2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/banking.inc");
13 include_once($path_to_root . "/includes/types.inc");
14 include_once($path_to_root . "/includes/current_user.inc");
16 define('SEARCH_BUTTON', "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
17 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ");
19 define('SELECT_BUTTON', "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
20 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ");
22 //----------------------------------------------------------------------------
23 // Universal sql combo generator
24 // $sql must return selector values and selector texts in columns 0 & 1
25 // Options are merged with defaults.
27 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
28 $options=null, $type=null)
30 global $Ajax, $path_to_root, $SysPrefs ;
32 $opts = array( // default options
33 'where'=> array(), // additional constraints
34 'order' => $namefield, // list sort order
35 // special option parameters
36 'spec_option'=>false, // option text or false
37 'spec_id' => 0, // option id
38 // submit on select parameters
39 'default' => '', // default value when $_POST is not set
40 'multi' => false, // multiple select
41 'select_submit' => false, //submit on select: true/false
42 'async' => true, // select update via ajax (true) vs _page_body reload
43 // search box parameters
45 'search_box' => false, // name or true/false
46 'type' => 0, // type of extended selector:
47 // 0 - with (optional) visible search box, search by fragment inside id
48 // 1 - with hidden search box, search by option text
49 // 2 - with (optional) visible search box, search by fragment at the start of id
50 // 3 - TODO reverse: box with hidden selector available via enter; this
51 // would be convenient for optional ad hoc adding of new item
52 'search_submit' => true, //search submit button: true/false
53 'size' => 8, // size and max of box tag
55 'height' => false, // number of lines in select box
56 'cells' => false, // combo displayed as 2 <td></td> cells
57 'search' => array(), // sql field names to search
58 'format' => null, // format functions for regular options
60 'box_hint' => null, // box/selectors hints; null = std see below
61 'category' => false, // category column name or false
62 'show_inactive' => false, // show inactive records.
63 'editable' => false, // false, or length of editable entry field
64 'editlink' => false // link to entity entry/edit page (optional)
66 // ------ merge options with defaults ----------
68 $opts = array_merge($opts, $options);
69 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
71 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
72 // select content filtered by search field:
73 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
74 // select set by select content field
75 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
77 $select_submit = $opts['select_submit'];
78 $spec_id = $opts['spec_id'];
79 $spec_option = $opts['spec_option'];
80 if ($opts['type'] == 0) {
83 } elseif($opts['type'] == 1) {
91 $disabled = $opts['disabled'] ? "disabled" : '';
92 $multi = $opts['multi'];
94 if(!count($opts['search'])) {
95 $opts['search'] = array($by_id ? $valfield : $namefield);
97 if ($opts['sel_hint'] === null)
98 $opts['sel_hint'] = $by_id || $search_box==false ?
99 '' : _('Press Space tab for search pattern entry');
101 if ($opts['box_hint'] === null)
102 $opts['box_hint'] = $search_box && $search_submit != false ?
103 ($by_id ? _('Enter code fragment to search or * for all')
104 : _('Enter description fragment to search or * for all')) :'';
106 if ($selected_id == null) {
107 $selected_id = get_post($name, (string)$opts['default']);
109 if(!is_array($selected_id))
110 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
112 $txt = get_post($search_box);
115 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
116 if ($by_id) $txt = $_POST[$name];
119 $Ajax->activate('_page_body');
121 $Ajax->activate($name);
123 if (isset($_POST[$search_button])) {
125 $Ajax->activate('_page_body');
127 $Ajax->activate($name);
130 // search related sql modifications
132 $rel = "rel='$search_box'"; // set relation to list
133 if ($opts['search_submit']) {
134 if (isset($_POST[$search_button])) {
135 $selected_id = array(); // ignore selected_id while search
137 $Ajax->activate('_page_body');
139 $Ajax->activate($name);
142 if ($spec_option === false && $selected_id == array())
145 $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id));
150 foreach($opts['search'] as $i=> $s)
151 $opts['search'][$i] = $s . " LIKE "
152 .db_escape(($class=='combo3' ? '' : '%').$txt.'%');
153 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
159 if (count($opts['where'])) {
160 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
161 $where .= '('. implode($opts['where'], ' AND ') . ')';
162 $group_pos = strpos($sql, 'GROUP BY');
164 $group = substr($sql, $group_pos);
165 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
170 if ($opts['order'] != false) {
171 if (!is_array($opts['order']))
172 $opts['order'] = array($opts['order']);
173 $sql .= ' ORDER BY '.implode(',',$opts['order']);
177 // ------ make selector ----------
178 $selector = $first_opt = '';
183 if($result = db_query($sql)) {
184 while ($contact_row = db_fetch($result)) {
185 $value = $contact_row[0];
186 $descr = $opts['format']==null ? $contact_row[1] :
187 call_user_func($opts['format'], $contact_row);
189 if (get_post($search_button) && ($txt == $value)) {
190 $selected_id[] = $value;
193 if (in_array((string)$value, $selected_id, true)) {
196 $edit = $opts['editable'] && $contact_row['editable']
197 && (@$_POST[$search_box] == $value)
198 ? $contact_row[1] : false; // get non-formatted description
200 break; // selected field is editable - abandon list construction
202 // show selected option even if inactive
203 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
206 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
208 if ($first_id === false) {
212 $cat = $contact_row[$opts['category']];
213 if ($opts['category'] !== false && $cat != $lastcat){
215 $selector .= "</optgroup>";
216 $selector .= "<optgroup label='".$cat."'>\n";
219 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
222 $selector .= "</optgroup>";
223 db_free_result($result);
226 // Prepend special option.
227 if ($spec_option !== false) { // if special option used - add it
228 $first_id = $spec_id;
229 $first_opt = $spec_option;
230 $sel = $found===false ? 'selected' : '';
231 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
232 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
236 if ($found===false) {
237 $selected_id = array($first_id);
240 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
242 if ($SysPrefs->use_popup_search)
243 $selector = "<select id='$name' autocomplete='off' ".($multi ? "multiple" : '')
244 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
245 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
246 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
248 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
249 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
250 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
251 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
252 if ($by_id && ($search_box != false || $opts['editable']) ) {
253 // on first display show selector list
254 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
255 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
256 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
257 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
258 set_focus($name.'_text'); // prevent lost focus
259 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
260 set_focus($name); // prevent lost focus
261 if (!$opts['editable'])
263 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
266 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
268 // span for select list/input field update
269 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
271 // if selectable or editable list is used - add select button
272 if ($select_submit != false || $search_button) {
273 // button class selects form reload/ajax selector update
274 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
275 (fallback_mode() ? '' : 'display:none;'),
276 '_'.$name.'_update')."\n";
278 // ------ make combo ----------
280 if ($search_box != false) {
281 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
282 $opts['size']."' maxlength='".$opts['max'].
283 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
284 .$opts['box_hint']."'"
285 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
287 if ($search_submit != false || $opts['editable']) {
288 $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
289 (fallback_mode() ? '' : 'display:none;'),
290 $search_submit ? $search_submit : "_{$name}_button")."\n";
293 default_focus(($search_box && $by_id) ? $search_box : $name);
295 if ($SysPrefs->use_popup_search)
301 if ($SysPrefs->use_popup_windows) {
302 //_vd("type= $type");
303 switch (strtolower($type)) {
305 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=all&client_id=" . $id;
306 $img_title = _("Search items");
308 case "stock_manufactured":
309 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=manufactured&client_id=" . $id;
310 $img_title = _("Search items");
312 case "stock_purchased":
313 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=purchasable&client_id=" . $id;
314 $img_title = _("Search items");
317 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=sales&client_id=" . $id;
318 $img_title = _("Search items");
320 case "stock_costable":
321 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=costable&client_id=" . $id;
322 $img_title = _("Search items");
325 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=kits&client_id=" . $id;
326 $img_title = _("Search items");
329 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=assets&client_id=" . $id;
330 $img_title = _("Search items");
333 $link = $path_to_root . "/sales/inquiry/customers_list.php?popup=1&client_id=" . $id;
334 $img_title = _("Search customers");
337 $link = $path_to_root . "/sales/inquiry/customer_branches_list.php?popup=1&client_id=" . $id . "#customer_id";
338 $img_title = _("Search branches");
341 $link = $path_to_root . "/purchasing/inquiry/suppliers_list.php?popup=1&client_id=" . $id;
342 $img_title = _("Search suppliers");
345 $link = $path_to_root . "/gl/inquiry/accounts_list.php?popup=1&client_id=" . $id;
346 $img_title = _("Search GL accounts");
352 $theme = user_theme();
353 $img = '<img src="'.$path_to_root.'/themes/'.$theme.'/images/'.ICON_VIEW.
354 '" style="vertical-align:middle;width:12px;height:12px;border:0;" onclick="javascript:lookupWindow("'.
355 $link.'", "");" title="' . $img_title . '" style="cursor:pointer;" />';
359 if ($opts['editlink'])
360 $selector .= ' '.$opts['editlink'];
362 if ($SysPrefs->use_popup_search)
364 if ($search_box && $opts['cells'])
365 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector$img</td>";
367 $str = $edit_entry.$selector.$img;
371 if ($search_box && $opts['cells'])
372 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
374 $str = $edit_entry.$selector;
381 Returns true if selector $name is subject to update.
383 function list_updated($name)
385 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
387 //----------------------------------------------------------------------------------------------
388 // Universal array combo generator
389 // $items is array of options 'value' => 'description'
390 // Options is reduced set of combo_selector options and is merged with defaults.
392 function array_selector($name, $selected_id, $items, $options=null)
396 $opts = array( // default options
397 'spec_option'=>false, // option text or false
398 'spec_id' => 0, // option id
399 'select_submit' => false, //submit on select: true/false
400 'async' => true, // select update via ajax (true) vs _page_body reload
401 'default' => '', // default value when $_POST is not set
402 'multi'=>false, // multiple select
403 // search box parameters
404 'height' => false, // number of lines in select box
408 // ------ merge options with defaults ----------
410 $opts = array_merge($opts, $options);
411 $select_submit = $opts['select_submit'];
412 $spec_id = $opts['spec_id'];
413 $spec_option = $opts['spec_option'];
414 $disabled = $opts['disabled'] ? "disabled" : '';
415 $multi = $opts['multi'];
417 if ($selected_id == null) {
418 $selected_id = get_post($name, $opts['default']);
420 if(!is_array($selected_id))
421 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
423 if (isset($_POST[ '_'.$name.'_update'])) {
425 $Ajax->activate('_page_body');
427 $Ajax->activate($name);
430 // ------ make selector ----------
431 $selector = $first_opt = '';
434 foreach($items as $value=>$descr) {
436 if (in_array((string)$value, $selected_id, true)) {
440 if ($first_id === false) {
444 $selector .= "<option $sel value='$value'>$descr</option>\n";
447 if ($first_id!==false) {
448 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
450 // Prepend special option.
451 if ($spec_option !== false) { // if special option used - add it
452 $first_id = $spec_id;
453 $first_opt = $spec_option;
454 $sel = $found===false ? 'selected' : '';
455 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
459 if ($found===false) {
460 $selected_id = array($first_id);
462 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
464 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
465 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
466 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
467 . $opts['sel_hint']."'>".$selector."</select>\n";
469 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
471 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
473 if ($select_submit != false) { // if submit on change is used - add select button
474 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
475 (fallback_mode() ? '' : 'display:none;'),
476 '_'.$name.'_update')."\n";
478 default_focus($name);
482 //----------------------------------------------------------------------------------------------
483 function array_selector_row($label, $name, $selected_id, $items, $options=null)
485 echo "<tr><td class='label'>$label</td>\n<td>";
486 echo array_selector($name, $selected_id, $items, $options);
490 //----------------------------------------------------------------------------------------------
491 function _format_add_curr($row)
493 static $company_currency;
495 if ($company_currency == null)
497 $company_currency = get_company_currency();
499 return $row[1] . ($row[2] == $company_currency ?
500 '' : (" - " . $row[2]));
503 function add_edit_combo($type)
505 global $path_to_root, $popup_editors, $SysPrefs;
507 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
510 $theme_path = $path_to_root . '/themes/' . user_theme();
512 $key = $popup_editors[$type][1];
513 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
514 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
515 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
518 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
519 $all=false, $editkey = false)
522 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
524 $mode = get_company_pref('no_supplier_list');
527 set_editor('supplier', $name, $editkey);
529 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
531 'format' => '_format_add_curr',
532 'order' => array('supp_ref'),
533 'search_box' => $mode!=0,
535 'search' => array("supp_ref","supp_name","gst_no"),
536 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
537 'spec_id' => ALL_TEXT,
538 'select_submit'=> $submit_on_change,
540 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
541 _('Select supplier'),
542 'show_inactive'=>$all,
543 'editlink' => $editkey ? add_edit_combo('supplier') : false
548 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
549 $submit_on_change=false, $all=false, $editkey = false)
552 echo "<td>$label</td><td>\n";
553 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
558 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
559 $submit_on_change=false, $all=false, $editkey = false)
561 echo "<tr><td class='label'>$label</td><td>";
562 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
566 //----------------------------------------------------------------------------------------------
568 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
569 $show_inactive=false, $editkey = false)
572 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
574 $mode = get_company_pref('no_customer_list');
577 set_editor('customer', $name, $editkey);
579 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
581 'format' => '_format_add_curr',
582 'order' => array('debtor_ref'),
583 'search_box' => $mode!=0,
586 'search' => array("debtor_ref","name","tax_id"),
587 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
588 'spec_id' => ALL_TEXT,
589 'select_submit'=> $submit_on_change,
591 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
592 _('Select customer'),
593 'show_inactive' => $show_inactive,
594 'editlink' => $editkey ? add_edit_combo('customer') : false
599 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
600 $submit_on_change=false, $show_inactive=false, $editkey = false)
603 echo "<td>$label</td>\n";
605 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
606 $show_inactive, $editkey);
610 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
611 $submit_on_change=false, $show_inactive=false, $editkey = false)
614 echo "<tr><td class='label'>$label</td><td nowrap>";
615 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
616 $show_inactive, $editkey);
617 echo "</td>\n</tr>\n";
620 //------------------------------------------------------------------------------------------------
622 function customer_branches_list($customer_id, $name, $selected_id=null,
623 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
626 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
627 WHERE debtor_no=" . db_escape($customer_id)." ";
630 set_editor('branch', $name, $editkey);
632 $where = $enabled ? array("inactive = 0") : array();
633 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
636 'order' => array('branch_ref'),
637 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
638 'spec_id' => ALL_TEXT,
639 'select_submit'=> $submit_on_change,
640 'sel_hint' => _('Select customer branch'),
641 'editlink' => $editkey ? add_edit_combo('branch') : false
645 //------------------------------------------------------------------------------------------------
647 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
648 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
651 echo "<td>$label</td>\n";
653 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
654 $submit_on_change, $editkey);
658 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
659 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
661 echo "<tr><td class='label'>$label</td>";
662 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
663 $all_option, $enabled, $submit_on_change, $editkey);
667 //------------------------------------------------------------------------------------------------
669 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
672 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations WHERE fixed_asset=".(int)$fixed_asset;
674 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
676 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
677 'spec_id' => ALL_TEXT,
678 'select_submit'=> $submit_on_change
682 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
685 echo "<td>$label</td>\n";
687 echo locations_list($name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
691 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
693 echo "<tr><td class='label'>$label</td>";
694 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
698 //-----------------------------------------------------------------------------------------------
700 function currencies_list($name, $selected_id=null, $submit_on_change=false)
702 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
704 // default to the company currency
705 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
707 'select_submit'=> $submit_on_change,
708 'default' => get_company_currency(),
713 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
716 echo "<td>$label</td>\n";
718 echo currencies_list($name, $selected_id, $submit_on_change);
722 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
724 echo "<tr><td class='label'>$label</td>";
725 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
729 //---------------------------------------------------------------------------------------------------
731 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
734 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
736 // default to the company current fiscal year
738 return combo_input($name, $selected_id, $sql, 'id', '',
741 'default' => get_company_pref('f_year'),
742 'format' => '_format_fiscalyears',
743 'select_submit'=> $submit_on_change,
748 function _format_fiscalyears($row)
750 return sql2date($row[1]) . " - " . sql2date($row[2])
751 . " " . ($row[3] ? _('Closed') : _('Active'));
754 function fiscalyears_list_cells($label, $name, $selected_id=null)
757 echo "<td>$label</td>\n";
759 echo fiscalyears_list($name, $selected_id);
763 function fiscalyears_list_row($label, $name, $selected_id=null)
765 echo "<tr><td class='label'>$label</td>";
766 fiscalyears_list_cells(null, $name, $selected_id);
769 //------------------------------------------------------------------------------------
771 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
772 $submit_on_change=false, $showclosed=false, $showtype=1)
774 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
777 'order' => 'reference',
778 'spec_option'=>$no_option ? $showname : false,
780 'select_submit'=> $submit_on_change,
785 $options['where'][] = "closed=0";
787 $options['where'][] = "type_=".db_escape($showtype);
789 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
792 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
793 $showclosed=false, $showtype=0, $submit_on_change=false)
796 echo "<td>$label</td>\n";
798 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
802 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
803 $showclosed=false, $showtype=0, $submit_on_change=false)
805 echo "<tr><td class='label'>$label</td>";
806 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
807 $showclosed, $showtype, $submit_on_change);
811 //---------------------------------------------------------------------------------------------------
813 function stock_items_list($name, $selected_id=null, $all_option=false,
814 $submit_on_change=false, $opts=array(), $editkey = false, $type = "stock")
816 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
817 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
819 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
820 $sql .= " AND mb_flag='F'";
822 $sql .= " AND mb_flag!='F'";
825 set_editor('item', $name, $editkey);
827 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
829 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
832 'format' => '_format_stock_items',
833 'spec_option' => $all_option===true ? _("All Items") : $all_option,
834 'spec_id' => ALL_TEXT,
835 'search_box' => true,
836 'search' => array("stock_id", "c.description","s.description"),
837 'search_submit' => get_company_pref('no_item_list')!=0,
839 'select_submit'=> $submit_on_change,
841 'order' => array('c.description','stock_id'),
842 'editlink' => $editkey ? add_edit_combo('item') : false,
849 function _format_stock_items($row)
851 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
854 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
855 $submit_on_change=false, $all=false, $editkey = false, $opts= array())
857 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
858 $editor_item = 'fa_item';
860 $editor_item = 'item';
863 // set_editor($editor_item, $name, $editkey);
866 echo "<td>$label</td>\n";
869 // $opts = array_merge($options, array('cells'=>true, 'show_inactive'=>$all, 'new_icon' => $editkey ? 'item' : false));
871 // echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, $opts);
873 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
874 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey);
878 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
881 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
885 //---------------------------------------------------------------------------------------------------
887 // Select item via foreign code.
889 function sales_items_list($name, $selected_id=null, $all_option=false,
890 $submit_on_change=false, $type='', $opts=array())
893 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
894 i.inactive, if(count(*)>1, '0', s.editable) as editable
896 ".TB_PREF."stock_master s,
897 ".TB_PREF."item_codes i
899 ".TB_PREF."stock_category c
900 ON i.category_id=c.category_id
901 WHERE i.stock_id=s.stock_id
905 if ($type == 'local') { // exclude foreign codes
906 $sql .= " AND !i.is_foreign";
907 } elseif ($type == 'kits') { // sales kits
908 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
910 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
911 $sql .= " GROUP BY i.item_code";
913 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
916 'format' => '_format_stock_items',
917 'spec_option' => $all_option===true ? _("All Items") : $all_option,
918 'spec_id' => ALL_TEXT,
919 'search_box' => true,
920 'search' => array("i.item_code", "c.description", "i.description"),
921 'search_submit' => get_company_pref('no_item_list')!=0,
923 'select_submit'=> $submit_on_change,
925 'order' => array('c.description','i.item_code'),
928 ), $opts), $type == 'kits' ? $type : "stock_sales" );
931 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
934 set_editor('item', $name, $editkey);
937 echo "<td>$label</td>\n";
938 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
939 '', array('cells'=>true));
942 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
944 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
945 'kits', array('cells'=>false, 'editable' => false));
948 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
952 echo "<td class='label'>$label</td>\n";
954 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
955 'local', array('cells'=>false, 'editable' => false));
958 //------------------------------------------------------------------------------------
960 function stock_manufactured_items_list($name, $selected_id=null,
961 $all_option=false, $submit_on_change=false)
963 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
964 array('where'=>array("mb_flag= 'M'")), false, "stock_manufactured");
967 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
968 $all_option=false, $submit_on_change=false)
971 echo "<td>$label</td>\n";
973 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
977 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
978 $all_option=false, $submit_on_change=false)
980 echo "<tr><td class='label'>$label</td>";
981 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
984 //------------------------------------------------------------------------------------
986 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
987 $all_option=false, $submit_on_change=false, $editkey = false)
989 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
990 array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
993 function stock_component_items_list_cells($label, $name, $parent_stock_id,
994 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
997 echo "<td>$label</td>\n";
998 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
999 array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
1002 //------------------------------------------------------------------------------------
1004 function stock_costable_items_list($name, $selected_id=null,
1005 $all_option=false, $submit_on_change=false)
1007 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1008 array('where'=>array("mb_flag!='D'")), false, "stock_costable");
1011 function stock_costable_items_list_cells($label, $name, $selected_id=null,
1012 $all_option=false, $submit_on_change=false)
1015 echo "<td>$label</td>\n";
1016 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1017 array('where'=>array("mb_flag!='D'"), 'cells'=>true), false, "stock_costable");
1020 //------------------------------------------------------------------------------------
1021 function stock_purchasable_items_list($name, $selected_id=null,
1022 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
1024 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1025 array('where'=>array("NOT no_purchase"),
1026 'show_inactive'=>$all), $editkey, "stock_purchased");
1029 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
1031 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
1032 $all_option=false, $submit_on_change=false, $editkey=false)
1035 echo "<td>$label</td>\n";
1036 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1037 array('where'=>array("NOT no_purchase"),
1039 'cells'=>true), $editkey);
1042 //------------------------------------------------------------------------------------
1044 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
1046 global $stock_types;
1050 echo "<td class='label'>$label</td>\n";
1053 echo array_selector($name, $selected_id, $stock_types,
1055 'select_submit'=> true,
1056 'disabled' => !$enabled) );
1057 echo "</td></tr>\n";
1060 function stock_units_list_row($label, $name, $value=null, $enabled=true)
1062 $result = get_all_item_units();
1065 echo "<td class='label'>$label</td>\n";
1068 while($unit = db_fetch($result))
1069 $units[$unit['abbr']] = $unit['name'];
1071 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
1073 echo "</td></tr>\n";
1076 //------------------------------------------------------------------------------------
1078 function stock_purchasable_fa_list_cells($label, $name, $selected_id=null, $all_option=false,
1079 $submit_on_change=false, $all=false, $editkey = false, $exclude_items = array())
1081 // Check if a fixed asset has been bought.
1082 $where_opts[] = "stock_id NOT IN
1083 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1085 // exclude items currently on the order.
1086 foreach($exclude_items as $item) {
1087 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1089 $where_opts[] = "mb_flag='F'";
1091 echo stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, $all, $editkey,
1092 array('fixed_asset' => true, 'where' => $where_opts));
1095 function stock_disposable_fa_list($name, $selected_id=null,
1096 $all_option=false, $submit_on_change=false)
1098 // Check if a fixed asset has been bought....
1099 $where_opts[] = "stock_id IN
1100 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1101 // ...but has not been disposed or sold already.
1102 $where_opts[] = "stock_id NOT IN
1103 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1105 $where_opts[] = "mb_flag='F'";
1107 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1108 array('fixed_asset' => true, 'where' => $where_opts));
1111 function stock_disposable_fa_list_cells($label, $name, $selected_id=null,
1112 $all_option=false, $submit_on_change=false, $exclude_items = array())
1114 // Check if a fixed asset has been bought....
1115 $where_opts[] = "stock_id IN
1116 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1117 // ...but has not been disposed or sold already.
1118 $where_opts[] = "stock_id NOT IN
1119 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1121 $where_opts[] = "mb_flag='F'";
1123 foreach($exclude_items as $item) {
1124 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1128 echo "<td>$label</td>\n";
1129 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1130 array('fixed_asset' => true, 'cells'=>true, 'where' => $where_opts));
1133 function stock_depreciable_fa_list_cells($label, $name, $selected_id=null,
1134 $all_option=false, $submit_on_change=false)
1137 // Check if a fixed asset has been bought....
1138 $where_opts[] = "stock_id IN
1139 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1140 // ...but has not been disposed or sold already.
1141 $where_opts[] = "stock_id NOT IN
1142 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1144 $year = get_current_fiscalyear();
1145 $y = date('Y', strtotime($year['end']));
1147 // check if current fiscal year
1148 $where_opts[] = "depreciation_date < '".$y."-12-01'";
1149 $where_opts[] = "depreciation_date >= '".($y-1)."-12-01'";
1151 $where_opts[] = "material_cost > 0";
1152 $where_opts[] = "mb_flag='F'";
1155 echo "<td>$label</td>\n";
1156 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1157 array('fixed_asset' => true, 'where' => $where_opts, 'cells'=>true));
1160 //------------------------------------------------------------------------------------
1162 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
1164 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
1166 return combo_input($name, $selected_id, $sql, 'id', 'name',
1168 'spec_option' => $none_option,
1169 'spec_id' => ALL_NUMERIC,
1170 'select_submit'=> $submit_on_change,
1175 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1176 $submit_on_change=false)
1179 echo "<td>$label</td>\n";
1181 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1185 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1186 $submit_on_change=false)
1188 echo "<tr><td class='label'>$label</td>";
1189 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1193 //------------------------------------------------------------------------------------
1195 function tax_groups_list($name, $selected_id=null,
1196 $none_option=false, $submit_on_change=false)
1198 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1200 return combo_input($name, $selected_id, $sql, 'id', 'name',
1203 'spec_option' => $none_option,
1204 'spec_id' => ALL_NUMERIC,
1205 'select_submit'=> $submit_on_change,
1210 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1213 echo "<td>$label</td>\n";
1215 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1219 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1221 echo "<tr><td class='label'>$label</td>";
1222 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1226 //------------------------------------------------------------------------------------
1228 function item_tax_types_list($name, $selected_id=null)
1230 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1231 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1234 function item_tax_types_list_cells($label, $name, $selected_id=null)
1237 echo "<td>$label</td>\n";
1239 echo item_tax_types_list($name, $selected_id);
1243 function item_tax_types_list_row($label, $name, $selected_id=null)
1245 echo "<tr><td class='label'>$label</td>";
1246 item_tax_types_list_cells(null, $name, $selected_id);
1250 //------------------------------------------------------------------------------------
1252 function shippers_list($name, $selected_id=null)
1254 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1255 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1256 array('order'=>array('shipper_name')));
1259 function shippers_list_cells($label, $name, $selected_id=null)
1262 echo "<td>$label</td>\n";
1264 echo shippers_list($name, $selected_id);
1268 function shippers_list_row($label, $name, $selected_id=null)
1270 echo "<tr><td class='label'>$label</td>";
1271 shippers_list_cells(null, $name, $selected_id);
1275 //-------------------------------------------------------------------------------------
1277 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1279 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1280 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1281 array('order'=>array('salesman_name'),
1282 'spec_option' => $spec_opt,
1283 'spec_id' => ALL_NUMERIC));
1286 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1289 echo "<td>$label</td>\n";
1291 echo sales_persons_list($name, $selected_id, $spec_opt);
1295 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1297 echo "<tr><td class='label'>$label</td>";
1298 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1302 //------------------------------------------------------------------------------------
1304 function sales_areas_list($name, $selected_id=null)
1306 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1307 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1310 function sales_areas_list_cells($label, $name, $selected_id=null)
1313 echo "<td>$label</td>\n";
1315 echo sales_areas_list($name, $selected_id);
1319 function sales_areas_list_row($label, $name, $selected_id=null)
1321 echo "<tr><td class='label'>$label</td>";
1322 sales_areas_list_cells(null, $name, $selected_id);
1326 //------------------------------------------------------------------------------------
1328 function sales_groups_list($name, $selected_id=null, $special_option=false)
1330 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1331 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1332 'spec_option' => $special_option===true ? ' ' : $special_option,
1333 'order' => 'description', 'spec_id' => 0,
1337 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1340 echo "<td>$label</td>\n";
1342 echo sales_groups_list($name, $selected_id, $special_option);
1346 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1348 echo "<tr><td class='label'>$label</td>";
1349 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1353 //------------------------------------------------------------------------------------
1355 function _format_template_items($row)
1357 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1360 function templates_list($name, $selected_id=null, $special_option=false)
1362 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1363 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1364 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1365 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1366 'format' => '_format_template_items',
1367 'spec_option' => $special_option===true ? ' ' : $special_option,
1368 'order' => 'order_no', 'spec_id' => 0,
1372 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1375 echo "<td>$label</td>\n";
1377 echo templates_list($name, $selected_id, $special_option);
1381 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1383 echo "<tr><td class='label'>$label</td>";
1384 templates_list_cells(null, $name, $selected_id, $special_option);
1388 //------------------------------------------------------------------------------------
1390 function workorders_list($name, $selected_id=null)
1392 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1393 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1396 function workorders_list_cells($label, $name, $selected_id=null)
1399 echo "<td>$label</td>\n";
1401 echo workorders_list($name, $selected_id);
1405 function workorders_list_row($label, $name, $selected_id=null)
1407 echo "<tr><td class='label'>$label</td>";
1408 workorders_list_cells(null, $name, $selected_id);
1412 //------------------------------------------------------------------------------------
1414 function payment_terms_list($name, $selected_id=null)
1416 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1417 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1420 function payment_terms_list_cells($label, $name, $selected_id=null)
1423 echo "<td>$label</td>\n";
1425 echo payment_terms_list($name, $selected_id);
1429 function payment_terms_list_row($label, $name, $selected_id=null)
1431 echo "<tr><td class='label'>$label</td>";
1432 payment_terms_list_cells(null, $name, $selected_id);
1436 //------------------------------------------------------------------------------------
1438 function credit_status_list($name, $selected_id=null)
1440 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1441 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1444 function credit_status_list_cells($label, $name, $selected_id=null)
1447 echo "<td>$label</td>\n";
1449 echo credit_status_list($name, $selected_id);
1453 function credit_status_list_row($label, $name, $selected_id=null)
1455 echo "<tr><td class='label'>$label</td>";
1456 credit_status_list_cells(null, $name, $selected_id);
1460 //-----------------------------------------------------------------------------------------------
1462 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1464 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1466 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1468 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1470 'select_submit'=> $submit_on_change,
1474 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1477 echo "<td>$label</td>\n";
1479 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1483 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1485 echo "<tr><td class='label'>$label</td>";
1486 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1490 //-----------------------------------------------------------------------------------------------
1492 function _format_date($row)
1494 return sql2date($row['reconciled']);
1497 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1499 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1500 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1501 GROUP BY reconciled";
1502 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1504 'spec_option' => $special_option,
1505 'format' => '_format_date',
1507 'select_submit'=> $submit_on_change
1511 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1514 echo "<td>$label</td>\n";
1516 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1520 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1523 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1527 //-----------------------------------------------------------------------------------------------
1529 function workcenter_list($name, $selected_id=null, $all_option=false)
1532 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1534 return combo_input($name, $selected_id, $sql, 'id', 'name',
1536 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1537 'spec_id' => ALL_TEXT,
1541 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1543 default_focus($name);
1545 echo "<td>$label</td>\n";
1547 echo workcenter_list($name, $selected_id, $all_option);
1551 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1553 echo "<tr><td class='label'>$label</td>";
1554 workcenter_list_cells(null, $name, $selected_id, $all_option);
1558 //-----------------------------------------------------------------------------------------------
1560 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1562 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1563 FROM ".TB_PREF."bank_accounts";
1565 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1567 'format' => '_format_add_curr',
1568 'select_submit'=> $submit_on_change,
1569 'spec_option' => $spec_option,
1575 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1578 echo "<td>$label</td>\n";
1580 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1584 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1586 echo "<tr><td class='label'>$label</td>";
1587 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1590 //-----------------------------------------------------------------------------------------------
1592 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1595 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1596 FROM ".TB_PREF."bank_accounts
1597 WHERE account_type=".BT_CASH;
1600 echo "<tr><td class='label'>$label</td>\n";
1602 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1604 'spec_option' => $all_option,
1605 'spec_id' => ALL_TEXT,
1606 'format' => '_format_add_curr',
1607 'select_submit'=> $submit_on_change,
1610 echo "</td></tr>\n";
1612 //-----------------------------------------------------------------------------------------------
1614 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1616 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1618 default_focus($name);
1621 echo "<td class='label'>$label</td>\n";
1624 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1626 'select_submit'=> $submit_on_change,
1628 'spec_option' =>$spec_option,
1630 'order'=> array('pos_name')
1632 echo "</td></tr>\n";
1635 //-----------------------------------------------------------------------------------------------
1636 // Payment type selector for current user.
1638 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1640 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1642 if ($category == PM_CASH) // only cash
1643 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1644 elseif ($category == PM_CREDIT) // only delayed payments
1645 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1646 elseif (!$prepayments)
1647 $sql .= " WHERE days_before_due>=0";
1649 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1651 'select_submit'=> $submit_on_change,
1657 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1660 echo "<td class='label'>$label</td>\n";
1663 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1667 //-----------------------------------------------------------------------------------------------
1669 function class_list($name, $selected_id=null, $submit_on_change=false)
1671 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1673 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1675 'select_submit'=> $submit_on_change,
1681 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1684 echo "<td>$label</td>\n";
1686 echo class_list($name, $selected_id, $submit_on_change);
1690 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1692 echo "<tr><td class='label'>$label</td>";
1693 class_list_cells(null, $name, $selected_id, $submit_on_change);
1697 //-----------------------------------------------------------------------------------------------
1698 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1700 $where_opts = array();
1702 $where_opts[0] = "dflt_mb_flag='F'";
1704 $where_opts[0] = "dflt_mb_flag!='F'";
1706 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1707 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1708 array('order'=>'category_id',
1709 'spec_option' => $spec_opt,
1711 'select_submit'=> $submit_on_change,
1713 'where' => $where_opts,
1717 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1720 echo "<td>$label</td>\n";
1722 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1726 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1728 echo "<tr><td class='label'>$label</td>";
1729 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1733 //-----------------------------------------------------------------------------------------------
1734 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1736 $sql = "SELECT c.fa_class_id, CONCAT(c.fa_class_id,' - ',c.description) `desc`, CONCAT(p.fa_class_id,' - ',p.description) `class`, c.inactive FROM "
1737 .TB_PREF."stock_fa_class c LEFT JOIN ".TB_PREF."stock_fa_class p ON c.parent_id=p.fa_class_id";
1739 return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
1740 array('order'=>'c.fa_class_id',
1741 'spec_option' => $spec_opt,
1743 'select_submit'=> $submit_on_change,
1745 'search_box' => true,
1746 'search' => array("c.fa_class_id"),
1747 'search_submit' => false,
1751 'category' => 'class',
1755 function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1757 echo "<tr><td class='label'>$label</td>";
1759 echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change);
1760 echo "</td></tr>\n";
1763 //-----------------------------------------------------------------------------------------------
1765 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1768 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1770 return combo_input($name, $selected_id, $sql, 'id', 'name',
1772 'format' => '_format_account',
1773 'order' => array('class_id', 'id', 'parent'),
1774 'spec_option' =>$all_option,
1775 'spec_id' => ALL_TEXT
1779 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1782 echo "<td>$label</td>\n";
1784 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1788 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1790 echo "<tr><td class='label'>$label</td>";
1791 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1796 //-----------------------------------------------------------------------------------------------
1797 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1798 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1800 if ($skip_bank_accounts)
1801 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1802 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1803 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1804 ."ON chart.account_code=acc.account_code
1805 WHERE acc.account_code IS NULL
1806 AND chart.account_type=type.id";
1808 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1809 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1810 WHERE chart.account_type=type.id";
1812 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1814 'format' => '_format_account',
1815 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1818 'order' => array('type.class_id','type.id','account_code'),
1819 'search_box' => $cells,
1820 'search_submit' => false,
1824 'select_submit'=> $submit_on_change,
1827 'show_inactive' => $all
1831 function _format_account($row)
1833 return $row[0] . " " . $row[1];
1836 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1837 $skip_bank_accounts=false, $cells=false, $all_option=false,
1838 $submit_on_change=false, $all=false)
1841 echo "<td>$label</td>\n";
1843 echo gl_all_accounts_list($name, $selected_id,
1844 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1848 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1849 $skip_bank_accounts=false, $cells=false, $all_option=false)
1851 echo "<tr><td class='label'>$label</td>";
1852 gl_all_accounts_list_cells(null, $name, $selected_id,
1853 $skip_bank_accounts, $cells, $all_option);
1857 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1860 $items['0'] = strlen($name_no) ? $name_no : _("No");
1861 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1863 return array_selector($name, $selected_id, $items,
1865 'select_submit'=> $submit_on_change,
1866 'async' => false ) ); // FIX?
1869 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1872 echo "<td>$label</td>\n";
1874 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1878 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1880 echo "<tr><td class='label'>$label</td>";
1881 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1885 //------------------------------------------------------------------------------------------------
1887 function languages_list($name, $selected_id=null, $all_option=false)
1889 global $installed_languages;
1893 $items[''] = $all_option;
1894 foreach ($installed_languages as $lang)
1895 $items[$lang['code']] = $lang['name'];
1896 return array_selector($name, $selected_id, $items);
1899 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1902 echo "<td>$label</td>\n";
1904 echo languages_list($name, $selected_id, $all_option);
1908 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1910 echo "<tr><td class='label'>$label</td>";
1911 languages_list_cells(null, $name, $selected_id, $all_option);
1915 //------------------------------------------------------------------------------------------------
1917 function bank_account_types_list($name, $selected_id=null)
1919 global $bank_account_types;
1921 return array_selector($name, $selected_id, $bank_account_types);
1924 function bank_account_types_list_cells($label, $name, $selected_id=null)
1927 echo "<td>$label</td>\n";
1929 echo bank_account_types_list($name, $selected_id);
1933 function bank_account_types_list_row($label, $name, $selected_id=null)
1935 echo "<tr><td class='label'>$label</td>";
1936 bank_account_types_list_cells(null, $name, $selected_id);
1940 //------------------------------------------------------------------------------------------------
1941 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1943 global $payment_person_types;
1946 foreach ($payment_person_types as $key=>$type)
1948 if ($key != PT_WORKORDER)
1949 $items[$key] = $type;
1951 return array_selector($name, $selected_id, $items,
1952 array( 'select_submit'=> $submit_on_change ) );
1955 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1958 echo "<td>$label</td>\n";
1960 echo payment_person_types_list($name, $selected_id, $related);
1964 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1966 echo "<tr><td class='label'>$label</td>";
1967 payment_person_types_list_cells(null, $name, $selected_id, $related);
1971 //------------------------------------------------------------------------------------------------
1973 function wo_types_list($name, $selected_id=null)
1975 global $wo_types_array;
1977 return array_selector($name, $selected_id, $wo_types_array,
1978 array( 'select_submit'=> true, 'async' => true ) );
1981 function wo_types_list_row($label, $name, $selected_id=null)
1983 echo "<tr><td class='label'>$label</td><td>\n";
1984 echo wo_types_list($name, $selected_id);
1985 echo "</td></tr>\n";
1988 //------------------------------------------------------------------------------------------------
1990 function dateformats_list_row($label, $name, $value=null)
1994 echo "<tr><td class='label'>$label</td>\n<td>";
1995 echo array_selector( $name, $value, $SysPrefs->dateformats );
1996 echo "</td></tr>\n";
1999 function dateseps_list_row($label, $name, $value=null)
2003 echo "<tr><td class='label'>$label</td>\n<td>";
2004 echo array_selector( $name, $value, $SysPrefs->dateseps );
2005 echo "</td></tr>\n";
2008 function thoseps_list_row($label, $name, $value=null)
2012 echo "<tr><td class='label'>$label</td>\n<td>";
2013 echo array_selector( $name, $value, $SysPrefs->thoseps );
2014 echo "</td></tr>\n";
2017 function decseps_list_row($label, $name, $value=null)
2021 echo "<tr><td class='label'>$label</td>\n<td>";
2022 echo array_selector( $name, $value, $SysPrefs->decseps );
2023 echo "</td></tr>\n";
2026 function themes_list_row($label, $name, $value=null)
2028 global $path_to_root;
2030 $path = $path_to_root.'/themes/';
2032 $themedir = opendir($path);
2033 while(false !== ($fname = readdir($themedir)))
2035 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
2037 $themes[$fname] = $fname;
2042 echo "<tr><td class='label'>$label</td>\n<td>";
2043 echo array_selector( $name, $value, $themes );
2044 echo "</td></tr>\n";
2047 function pagesizes_list_row($label, $name, $value=null)
2052 foreach ($SysPrefs->pagesizes as $pz)
2055 echo "<tr><td class='label'>$label</td>\n<td>";
2056 echo array_selector( $name, $value, $items );
2057 echo "</td></tr>\n";
2060 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
2062 global $systypes_array;
2064 // emove non-voidable transactions if needed
2065 $systypes = array_diff_key($systypes_array, array_flip($exclude));
2066 return array_selector($name, $value, $systypes,
2068 'spec_option'=> $spec_opt,
2069 'spec_id' => ALL_NUMERIC,
2070 'select_submit'=> $submit_on_change,
2076 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2079 echo "<td>$label</td>\n";
2081 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
2085 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2087 echo "<tr><td class='label'>$label</td>";
2088 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
2092 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
2094 global $systypes_array;
2097 echo "<td>$label</td>\n";
2100 $items = $systypes_array;
2102 // exclude quotes, orders and dimensions
2103 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
2104 unset($items[$excl]);
2106 echo array_selector($name, $value, $items,
2108 'spec_option'=> _("All"),
2110 'select_submit'=> $submit_on_change,
2117 function cust_allocations_list_cells($label, $name, $selected=null)
2124 ALL_TEXT=>_("All Types"),
2125 '1'=> _("Sales Invoices"),
2126 '2'=> _("Overdue Invoices"),
2127 '3' => _("Payments"),
2128 '4' => _("Credit Notes"),
2129 '5' => _("Delivery Notes")
2131 echo array_selector($name, $selected, $allocs);
2135 function supp_allocations_list_cell($name, $selected=null)
2140 ALL_TEXT=>_("All Types"),
2141 '1'=> _("Invoices"),
2142 '2'=> _("Overdue Invoices"),
2143 '3' => _("Payments"),
2144 '4' => _("Credit Notes"),
2145 '5' => _("Overdue Credit Notes")
2147 echo array_selector($name, $selected, $allocs);
2151 function supp_transactions_list_cell($name, $selected=null)
2156 ALL_TEXT=>_("All Types"),
2158 '1'=> _("Invoices"),
2159 '2'=> _("Overdue Invoices"),
2160 '3' => _("Payments"),
2161 '4' => _("Credit Notes"),
2162 '5' => _("Overdue Credit Notes")
2165 echo array_selector($name, $selected, $allocs);
2169 function policy_list_cells($label, $name, $selected=null)
2174 echo array_selector($name, $selected,
2175 array( '' => _("Automatically put balance on back order"),
2176 'CAN' => _("Cancel any quantites not delivered")) );
2180 function policy_list_row($label, $name, $selected=null)
2182 echo "<tr><td class='label'>$label</td>";
2183 policy_list_cells(null, $name, $selected);
2187 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2192 echo array_selector($name, $selected,
2193 array( 'Return' => _("Items Returned to Inventory Location"),
2194 'WriteOff' => _("Items Written Off")),
2195 array( 'select_submit'=> $submit_on_change ) );
2199 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2201 echo "<tr><td class='label'>$label</td>";
2202 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2206 function number_list($name, $selected, $from, $to, $no_option=false)
2209 for ($i = $from; $i <= $to; $i++)
2212 return array_selector($name, $selected, $items,
2213 array( 'spec_option' => $no_option,
2214 'spec_id' => ALL_NUMERIC) );
2217 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2222 echo number_list($name, $selected, $from, $to, $no_option);
2226 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2228 echo "<tr><td class='label'>$label</td>";
2229 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2233 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2234 $submit_on_change=true)
2236 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2237 ." GROUP BY profile";
2238 $result = db_query($sql, 'cannot get all profile names');
2239 $profiles = array();
2240 while($myrow=db_fetch($result)) {
2241 $profiles[$myrow['profile']] = $myrow['profile'];
2246 echo "<td class='label'>$label</td>\n";
2249 echo array_selector($name, $selected_id, $profiles,
2250 array( 'select_submit'=> $submit_on_change,
2251 'spec_option'=>$spec_opt,
2255 echo "</td></tr>\n";
2258 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2260 static $printers; // query only once for page display
2263 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2264 $result = db_query($sql, 'cannot get all printers');
2265 $printers = array();
2266 while($myrow=db_fetch($result)) {
2267 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2270 return array_selector($name, $selected_id, $printers,
2271 array( 'select_submit'=> $submit_on_change,
2272 'spec_option'=>$spec_opt,
2277 //------------------------------------------------------------------------------------------------
2279 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2282 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2284 $sql .= " WHERE type=$type";
2286 return combo_input($name, $selected_id, $sql, 'id', 'description',
2289 'order' => 'description',
2290 'select_submit'=> $submit_on_change,
2296 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2299 echo "<td>$label</td>\n";
2301 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2305 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2307 echo "<tr><td class='label'>$label</td>";
2308 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2313 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2315 global $quick_actions;
2317 echo "<tr><td class='label'>$label</td><td>";
2318 echo array_selector($name, $selected_id, $quick_actions,
2320 'select_submit'=> $submit_on_change
2322 echo "</td></tr>\n";
2325 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2327 global $quick_entry_types;
2329 echo "<tr><td class='label'>$label</td><td>";
2330 echo array_selector($name, $selected_id, $quick_entry_types,
2332 'select_submit'=> $submit_on_change
2334 echo "</td></tr>\n";
2337 function record_status_list_row($label, $name) {
2338 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2341 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2343 global $class_types;
2345 echo "<tr><td class='label'>$label</td><td>";
2346 echo array_selector($name, $selected_id, $class_types,
2348 'select_submit'=> $submit_on_change
2350 echo "</td></tr>\n";
2353 //------------------------------------------------------------------------------------------------
2355 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2356 $show_inactive = false)
2359 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2361 return combo_input($name, $selected_id, $sql, 'id', 'description',
2363 'spec_option'=>$new_item ? _("New role") : false,
2365 'select_submit'=> $submit_on_change,
2366 'show_inactive' => $show_inactive
2370 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2371 $show_inactive = false)
2374 echo "<td>$label</td>\n";
2376 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2380 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2381 $show_inactive = false)
2383 echo "<tr><td class='label'>$label</td>";
2384 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2388 function tab_list_row($label, $name, $selected_id=null)
2390 global $installed_extensions;
2393 foreach ($_SESSION['App']->applications as $app) {
2394 $tabs[$app->id] = access_string($app->name, true);
2397 echo "<td class='label'>$label</td><td>\n";
2398 echo array_selector($name, $selected_id, $tabs);
2399 echo "</td></tr>\n";
2402 //-----------------------------------------------------------------------------------------------
2404 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2407 global $path_to_root;
2408 include_once($path_to_root . "/admin/db/tags_db.inc");
2409 $results = get_tags($type, $all);
2411 while ($tag = db_fetch($results))
2412 $tags[$tag['id']] = $tag['name'];
2414 if (!isset($tags)) {
2415 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2418 return array_selector($name, null, $tags,
2421 'height' => $height,
2422 'spec_option'=> $spec_opt,
2427 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2430 echo "<td>$label</td>\n";
2432 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2437 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2439 echo "<tr><td class='label'>$label</td>";
2440 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2444 //---------------------------------------------------------------------------------------------
2445 // List of sets of active extensions
2447 function extset_list($name, $value=null, $submit_on_change=false)
2449 global $db_connections;
2452 foreach ($db_connections as $comp)
2453 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2454 return array_selector( $name, $value, $items,
2456 'spec_option'=> _("Available and/or installed"),
2458 'select_submit'=> $submit_on_change,
2463 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2466 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2471 if (@$filter['class']) {
2472 $where[] = 'type='.db_escape($filter['class']);
2475 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2476 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2477 if (@$filter['multi']) { // contact category selector for person
2481 return combo_input($name, $selected_id, $sql, 'id', 'name',
2484 'height' => $multi ? 5:1,
2485 'category' => $groups,
2486 'select_submit'=> $submit_on_change,
2492 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2494 echo "<tr><td class='label'>$label</td><td>";
2495 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2496 echo "</td></tr>\n";
2499 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2501 global $pterm_types;
2503 echo "<tr><td class='label'>$label</td><td>";
2504 echo array_selector($name, $selected_id, $pterm_types,
2506 'select_submit'=> $submit_on_change
2508 echo "</td></tr>\n";
2511 function coa_list_row($label, $name, $value=null)
2513 global $path_to_root, $installed_extensions;
2515 $path = $path_to_root.'/sql/';
2517 $sqldir = opendir($path);
2518 while (false !== ($fname = readdir($sqldir)))
2520 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2522 $ext = array_search_value($fname, $installed_extensions, 'sql');
2524 $descr = $ext['name'];
2525 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2526 $descr = _("Standard new company American COA (4 digit)");
2527 } elseif ($fname == 'en_US-demo.sql') {
2528 $descr = _("Standard American COA (4 digit) with demo data");
2532 $coas[$fname] = $descr;
2537 echo "<tr><td class='label'>$label</td>\n<td>";
2538 echo array_selector( $name, $value, $coas );
2539 echo "</td></tr>\n";
2542 function payment_services($name)
2544 global $payment_services;
2546 $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2548 return array_selector($name, null, $services, array(
2549 'spec_option'=> _("No payment Link"),
2554 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2556 global $tax_algorithms;
2558 return array_selector($name, $value, $tax_algorithms,
2560 'select_submit'=> $submit_on_change,
2566 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2569 echo "<td>$label</td>\n";
2571 echo tax_algorithm_list($name, $value, $submit_on_change);
2575 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2577 echo "<tr><td class='label'>$label</td>";
2578 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2582 function refline_list($name, $type, $value=null, $spec_option=false)
2584 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2589 $where = array('`trans_type`='.db_escape($type));
2591 return combo_input($name, $value, $sql, 'id', 'prefix',
2593 'order'=>array('prefix'),
2594 'spec_option' => $spec_option,
2598 'select_submit' => true,
2603 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2607 echo "<td class='label'>$label</td>\n";
2610 echo refline_list($name, $type, $selected_id, $spec_option);
2611 echo "</td></tr>\n";
2615 //----------------------------------------------------------------------------------------------
2617 function subledger_list($name, $account, $selected_id=null)
2620 $type = is_subledger_account($account);
2625 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2627 .TB_PREF."debtors_master d,"
2628 .TB_PREF."cust_branch c
2629 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2631 $sql = "SELECT supplier_id as id, supp_ref as name
2633 .TB_PREF."suppliers s
2634 WHERE s.payable_account=".db_escape($account);
2636 $mode = get_company_pref('no_customer_list');
2638 return combo_input($name, $selected_id, $sql, 'id', 'name',
2646 function subledger_list_cells($label, $name, $account, $selected_id=null)
2649 echo "<td>$label</td>\n";
2651 echo subledger_list($name, $account, $selected_id);
2655 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2656 $submit_on_change=false, $show_inactive=false, $editkey = false)
2658 echo "<tr><td class='label'>$label</td><td nowrap>";
2659 echo subledger_list($name, $account, $selected_id);
2660 echo "</td>\n</tr>\n";
2663 function accounts_type_list_row($label, $name, $selected_id=null)
2667 echo "<td class='label'>$label</td>\n";
2669 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2670 echo array_selector($name, $selected_id, $sel);
2671 echo "</td></tr>\n";
2674 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2677 $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2680 echo "<td>$label</td>\n";
2683 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2685 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2687 'order' => 'real_name',
2688 'select_submit'=> $submit_on_change,
2695 function collations_list_row($label, $name, $selected_id=null)
2697 global $supported_collations;
2701 echo "<td class='label'>$label</td>\n";
2704 echo array_selector($name, $selected_id, $supported_collations,
2705 array('select_submit'=> false) );
2706 echo "</td></tr>\n";