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,
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($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
184 //if($name=='curr_default') display_notification($opts['search_submit']);
185 if($result = db_query($sql)) {
186 while ($contact_row = db_fetch($result)) {
187 $value = $contact_row[0];
188 $descr = $opts['format']==null ? $contact_row[1] :
189 call_user_func($opts['format'], $contact_row);
191 if (get_post($search_button) && ($txt == $value)) {
192 $selected_id[] = $value;
195 if (in_array((string)$value, $selected_id, true)) {
198 $edit = $opts['editable'] && $contact_row['editable']
199 && (@$_POST[$search_box] == $value)
200 ? $contact_row[1] : false; // get non-formatted description
202 break; // selected field is editable - abandon list construction
204 // show selected option even if inactive
205 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
208 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
210 if ($first_id === false) {
214 $cat = $contact_row[$opts['category']];
215 if ($opts['category'] !== false && $cat != $lastcat){
217 $selector .= "</optgroup>";
218 $selector .= "<optgroup label='".$cat."'>\n";
221 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
224 $selector .= "</optgroup>";
225 db_free_result($result);
228 // Prepend special option.
229 if ($spec_option !== false) { // if special option used - add it
230 $first_id = $spec_id;
231 $first_opt = $spec_option;
233 // if($first_id !== false) {
234 $sel = $found===false ? 'selected' : '';
235 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
236 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
240 if ($found===false) {
241 $selected_id = array($first_id);
244 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
246 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
247 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
248 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
249 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
251 if ($by_id && ($search_box != false || $opts['editable']) ) {
252 // on first display show selector list
253 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
254 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
255 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
256 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
257 set_focus($name.'_text'); // prevent lost focus
258 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
259 set_focus($name); // prevent lost focus
260 if (!$opts['editable'])
262 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
265 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
267 // span for select list/input field update
268 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
270 // if selectable or editable list is used - add select button
271 if ($select_submit != false || $search_button) {
272 // button class selects form reload/ajax selector update
273 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
274 (fallback_mode() ? '' : 'display:none;'),
275 '_'.$name.'_update')."\n";
277 // ------ make combo ----------
279 if ($search_box != false) {
280 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
281 $opts['size']."' maxlength='".$opts['max'].
282 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
283 .$opts['box_hint']."'"
284 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
286 if ($search_submit != false || $opts['editable']) {
287 $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
288 (fallback_mode() ? '' : 'display:none;'),
289 $search_submit ? $search_submit : "_{$name}_button")."\n";
292 default_focus(($search_box && $by_id) ? $search_box : $name);
294 if ($opts['editlink'])
295 $selector .= ' '.$opts['editlink'];
297 if ($search_box && $opts['cells'])
298 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
300 $str = $edit_entry.$selector;
306 Returns true if selector $name is subject to update.
308 function list_updated($name)
310 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
312 //----------------------------------------------------------------------------------------------
313 // Universal array combo generator
314 // $items is array of options 'value' => 'description'
315 // Options is reduced set of combo_selector options and is merged with defaults.
317 function array_selector($name, $selected_id, $items, $options=null)
321 $opts = array( // default options
322 'spec_option'=>false, // option text or false
323 'spec_id' => 0, // option id
324 'select_submit' => false, //submit on select: true/false
325 'async' => true, // select update via ajax (true) vs _page_body reload
326 'default' => '', // default value when $_POST is not set
327 'multi'=>false, // multiple select
328 // search box parameters
329 'height' => false, // number of lines in select box
333 // ------ merge options with defaults ----------
335 $opts = array_merge($opts, $options);
336 $select_submit = $opts['select_submit'];
337 $spec_id = $opts['spec_id'];
338 $spec_option = $opts['spec_option'];
339 $disabled = $opts['disabled'] ? "disabled" : '';
340 $multi = $opts['multi'];
342 if ($selected_id == null) {
343 $selected_id = get_post($name, $opts['default']);
345 if(!is_array($selected_id))
346 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
348 if (isset($_POST[ '_'.$name.'_update'])) {
350 $Ajax->activate('_page_body');
352 $Ajax->activate($name);
355 // ------ make selector ----------
356 $selector = $first_opt = '';
359 //if($name=='SelectStockFromList') display_error($sql);
360 foreach($items as $value=>$descr) {
362 if (in_array((string)$value, $selected_id, true)) {
366 if ($first_id === false) {
370 $selector .= "<option $sel value='$value'>$descr</option>\n";
373 if ($first_id!==false) {
374 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
376 // Prepend special option.
377 if ($spec_option !== false) { // if special option used - add it
378 $first_id = $spec_id;
379 $first_opt = $spec_option;
380 $sel = $found===false ? 'selected' : '';
381 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
385 if ($found===false) {
386 $selected_id = array($first_id);
388 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
390 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
391 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
392 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
393 . $opts['sel_hint']."'>".$selector."</select>\n";
395 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
397 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
399 if ($select_submit != false) { // if submit on change is used - add select button
400 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
401 (fallback_mode() ? '' : 'display:none;'),
402 '_'.$name.'_update')."\n";
404 default_focus($name);
408 //----------------------------------------------------------------------------------------------
410 function _format_add_curr($row)
412 static $company_currency;
414 if ($company_currency == null)
416 $company_currency = get_company_currency();
418 return $row[1] . ($row[2] == $company_currency ?
419 '' : (" - " . $row[2]));
422 function add_edit_combo($type)
424 global $path_to_root, $popup_editors, $SysPrefs;
426 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
429 $theme_path = $path_to_root . '/themes/' . user_theme();
431 $key = $popup_editors[$type][1];
432 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
433 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
434 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
437 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
438 $all=false, $editkey = false)
441 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
443 $mode = get_company_pref('no_supplier_list');
446 set_editor('supplier', $name, $editkey);
448 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
450 'format' => '_format_add_curr',
451 'order' => array('supp_ref'),
452 'search_box' => $mode!=0,
454 'search' => array("supp_ref","supp_name","gst_no"),
455 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
456 'spec_id' => ALL_TEXT,
457 'select_submit'=> $submit_on_change,
459 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
460 _('Select supplier'),
461 'show_inactive'=>$all,
462 'editlink' => $editkey ? add_edit_combo('supplier') : false
467 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
468 $submit_on_change=false, $all=false, $editkey = false)
471 echo "<td>$label</td><td>\n";
472 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
477 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
478 $submit_on_change=false, $all=false, $editkey = false)
480 echo "<tr><td class='label'>$label</td><td>";
481 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
485 //----------------------------------------------------------------------------------------------
487 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
488 $show_inactive=false, $editkey = false)
491 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
493 $mode = get_company_pref('no_customer_list');
496 set_editor('customer', $name, $editkey);
498 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
500 'format' => '_format_add_curr',
501 'order' => array('debtor_ref'),
502 'search_box' => $mode!=0,
505 'search' => array("debtor_ref","name","tax_id"),
506 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
507 'spec_id' => ALL_TEXT,
508 'select_submit'=> $submit_on_change,
510 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
511 _('Select customer'),
512 'show_inactive' => $show_inactive,
513 'editlink' => $editkey ? add_edit_combo('customer') : false
518 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
519 $submit_on_change=false, $show_inactive=false, $editkey = false)
522 echo "<td>$label</td>\n";
524 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
525 $show_inactive, $editkey);
529 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
530 $submit_on_change=false, $show_inactive=false, $editkey = false)
533 echo "<tr><td class='label'>$label</td><td nowrap>";
534 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
535 $show_inactive, $editkey);
536 echo "</td>\n</tr>\n";
539 //------------------------------------------------------------------------------------------------
541 function customer_branches_list($customer_id, $name, $selected_id=null,
542 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
545 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
546 WHERE debtor_no=" . db_escape($customer_id)." ";
549 set_editor('branch', $name, $editkey);
551 $where = $enabled ? array("inactive = 0") : array();
552 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
555 'order' => array('branch_ref'),
556 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
557 'spec_id' => ALL_TEXT,
558 'select_submit'=> $submit_on_change,
559 'sel_hint' => _('Select customer branch'),
560 'editlink' => $editkey ? add_edit_combo('branch') : false
564 //------------------------------------------------------------------------------------------------
566 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
567 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
570 echo "<td>$label</td>\n";
572 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
573 $submit_on_change, $editkey);
577 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
578 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
580 echo "<tr><td class='label'>$label</td>";
581 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
582 $all_option, $enabled, $submit_on_change, $editkey);
586 //------------------------------------------------------------------------------------------------
588 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
591 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
593 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
595 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
596 'spec_id' => ALL_TEXT,
597 'select_submit'=> $submit_on_change
601 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
604 echo "<td>$label</td>\n";
606 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
610 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
612 echo "<tr><td class='label'>$label</td>";
613 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
617 //-----------------------------------------------------------------------------------------------
619 function currencies_list($name, $selected_id=null, $submit_on_change=false)
621 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
623 // default to the company currency
624 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
626 'select_submit'=> $submit_on_change,
627 'default' => get_company_currency(),
632 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
635 echo "<td>$label</td>\n";
637 echo currencies_list($name, $selected_id, $submit_on_change);
641 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
643 echo "<tr><td class='label'>$label</td>";
644 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
648 //---------------------------------------------------------------------------------------------------
650 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
653 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
655 // default to the company current fiscal year
657 return combo_input($name, $selected_id, $sql, 'id', '',
660 'default' => get_company_pref('f_year'),
661 'format' => '_format_fiscalyears',
662 'select_submit'=> $submit_on_change,
667 function _format_fiscalyears($row)
669 return sql2date($row[1]) . " - " . sql2date($row[2])
670 . " " . ($row[3] ? _('Closed') : _('Active'));
673 function fiscalyears_list_cells($label, $name, $selected_id=null)
676 echo "<td>$label</td>\n";
678 echo fiscalyears_list($name, $selected_id);
682 function fiscalyears_list_row($label, $name, $selected_id=null)
684 echo "<tr><td class='label'>$label</td>";
685 fiscalyears_list_cells(null, $name, $selected_id);
688 //------------------------------------------------------------------------------------
690 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
691 $submit_on_change=false, $showclosed=false, $showtype=1)
693 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
696 'order' => 'reference',
697 'spec_option'=>$no_option ? $showname : false,
699 'select_submit'=> $submit_on_change,
704 $options['where'][] = "closed=0";
706 $options['where'][] = "type_=".db_escape($showtype);
708 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
711 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
712 $showclosed=false, $showtype=0, $submit_on_change=false)
715 echo "<td>$label</td>\n";
717 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
721 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
722 $showclosed=false, $showtype=0, $submit_on_change=false)
724 echo "<tr><td class='label'>$label</td>";
725 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
726 $showclosed, $showtype, $submit_on_change);
730 //---------------------------------------------------------------------------------------------------
732 function stock_items_list($name, $selected_id=null, $all_option=false,
733 $submit_on_change=false, $opts=array(), $editkey = false)
736 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
737 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
740 set_editor('item', $name, $editkey);
742 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
745 'format' => '_format_stock_items',
746 'spec_option' => $all_option===true ? _("All Items") : $all_option,
747 'spec_id' => ALL_TEXT,
748 'search_box' => true,
749 'search' => array("stock_id", "c.description","s.description"),
750 'search_submit' => get_company_pref('no_item_list')!=0,
752 'select_submit'=> $submit_on_change,
754 'order' => array('c.description','stock_id'),
755 'editlink' => $editkey ? add_edit_combo('item') : false
760 function _format_stock_items($row)
762 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
765 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
766 $submit_on_change=false, $all=false, $editkey = false)
769 echo "<td>$label</td>\n";
770 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
771 array('cells'=>true, 'show_inactive'=>$all), $editkey);
774 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
777 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
781 //---------------------------------------------------------------------------------------------------
783 // Select item via foreign code.
785 function sales_items_list($name, $selected_id=null, $all_option=false,
786 $submit_on_change=false, $type='', $opts=array())
789 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
790 i.inactive, if(count(*)>1, '0', s.editable) as editable
792 ".TB_PREF."stock_master s,
793 ".TB_PREF."item_codes i
795 ".TB_PREF."stock_category c
796 ON i.category_id=c.category_id
797 WHERE i.stock_id=s.stock_id";
800 if ($type == 'local') { // exclude foreign codes
801 $sql .= " AND !i.is_foreign";
802 } elseif ($type == 'kits') { // sales kits
803 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
805 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
806 $sql .= " GROUP BY i.item_code";
808 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
811 'format' => '_format_stock_items',
812 'spec_option' => $all_option===true ? _("All Items") : $all_option,
813 'spec_id' => ALL_TEXT,
814 'search_box' => true,
815 'search' => array("i.item_code", "c.description", "i.description"),
816 'search_submit' => get_company_pref('no_item_list')!=0,
818 'select_submit'=> $submit_on_change,
820 'order' => array('c.description','i.item_code'),
826 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
829 set_editor('item', $name, $editkey);
832 echo "<td>$label</td>\n";
833 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
834 '', array('cells'=>true));
837 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
839 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
840 'kits', array('cells'=>false, 'editable' => false));
843 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
847 echo "<td class='label'>$label</td>\n";
849 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
850 'local', array('cells'=>false, 'editable' => false));
853 //------------------------------------------------------------------------------------
855 function stock_manufactured_items_list($name, $selected_id=null,
856 $all_option=false, $submit_on_change=false)
858 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
859 array('where'=>array("mb_flag= 'M'")));
862 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
863 $all_option=false, $submit_on_change=false)
866 echo "<td>$label</td>\n";
868 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
872 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
873 $all_option=false, $submit_on_change=false)
875 echo "<tr><td class='label'>$label</td>";
876 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
879 //------------------------------------------------------------------------------------
881 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
882 $all_option=false, $submit_on_change=false, $editkey = false)
884 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
885 array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
888 function stock_component_items_list_cells($label, $name, $parent_stock_id,
889 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
892 echo "<td>$label</td>\n";
893 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
894 array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
897 //------------------------------------------------------------------------------------
899 function stock_costable_items_list($name, $selected_id=null,
900 $all_option=false, $submit_on_change=false)
902 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
903 array('where'=>array("mb_flag!='D'")));
906 function stock_costable_items_list_cells($label, $name, $selected_id=null,
907 $all_option=false, $submit_on_change=false)
910 echo "<td>$label</td>\n";
911 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
912 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
915 //------------------------------------------------------------------------------------
916 function stock_purchasable_items_list($name, $selected_id=null,
917 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
919 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
920 array('where'=>array("NOT no_purchase"),
921 'show_inactive'=>$all), $editkey);
924 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
926 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
927 $all_option=false, $submit_on_change=false, $editkey=false)
930 echo "<td>$label</td>\n";
931 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
932 array('where'=>array("NOT no_purchase"),
934 'cells'=>true), $editkey);
937 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
938 $all_option=false, $submit_on_change=false, $editkey=false)
940 echo "<tr><td class='label'>$label</td>";
941 stock_purchasable_items_list_cells(null, $name, $selected_id=null,
942 $all_option, $submit_on_change, $editkey);
946 //------------------------------------------------------------------------------------
948 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
954 echo "<td class='label'>$label</td>\n";
957 echo array_selector($name, $selected_id, $stock_types,
959 'select_submit'=> true,
960 'disabled' => !$enabled) );
964 function stock_units_list_row($label, $name, $value=null, $enabled=true)
966 $result = get_all_item_units();
969 echo "<td class='label'>$label</td>\n";
972 while($unit = db_fetch($result))
973 $units[$unit['abbr']] = $unit['name'];
975 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
980 //------------------------------------------------------------------------------------
982 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
984 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
986 return combo_input($name, $selected_id, $sql, 'id', 'name',
988 'spec_option' => $none_option,
989 'spec_id' => ALL_NUMERIC,
990 'select_submit'=> $submit_on_change,
995 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
996 $submit_on_change=false)
999 echo "<td>$label</td>\n";
1001 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1005 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1006 $submit_on_change=false)
1008 echo "<tr><td class='label'>$label</td>";
1009 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1013 //------------------------------------------------------------------------------------
1015 function tax_groups_list($name, $selected_id=null,
1016 $none_option=false, $submit_on_change=false)
1018 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1020 return combo_input($name, $selected_id, $sql, 'id', 'name',
1023 'spec_option' => $none_option,
1024 'spec_id' => ALL_NUMERIC,
1025 'select_submit'=> $submit_on_change,
1030 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1033 echo "<td>$label</td>\n";
1035 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1039 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1041 echo "<tr><td class='label'>$label</td>";
1042 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1046 //------------------------------------------------------------------------------------
1048 function item_tax_types_list($name, $selected_id=null)
1050 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1051 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1054 function item_tax_types_list_cells($label, $name, $selected_id=null)
1057 echo "<td>$label</td>\n";
1059 echo item_tax_types_list($name, $selected_id);
1063 function item_tax_types_list_row($label, $name, $selected_id=null)
1065 echo "<tr><td class='label'>$label</td>";
1066 item_tax_types_list_cells(null, $name, $selected_id);
1070 //------------------------------------------------------------------------------------
1072 function shippers_list($name, $selected_id=null)
1074 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1075 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1076 array('order'=>array('shipper_name')));
1079 function shippers_list_cells($label, $name, $selected_id=null)
1082 echo "<td>$label</td>\n";
1084 echo shippers_list($name, $selected_id);
1088 function shippers_list_row($label, $name, $selected_id=null)
1090 echo "<tr><td class='label'>$label</td>";
1091 shippers_list_cells(null, $name, $selected_id);
1095 //-------------------------------------------------------------------------------------
1097 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1099 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1100 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1101 array('order'=>array('salesman_name'),
1102 'spec_option' => $spec_opt,
1103 'spec_id' => ALL_NUMERIC));
1106 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1109 echo "<td>$label</td>\n";
1111 echo sales_persons_list($name, $selected_id, $spec_opt);
1115 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1117 echo "<tr><td class='label'>$label</td>";
1118 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1122 //------------------------------------------------------------------------------------
1124 function sales_areas_list($name, $selected_id=null)
1126 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1127 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1130 function sales_areas_list_cells($label, $name, $selected_id=null)
1133 echo "<td>$label</td>\n";
1135 echo sales_areas_list($name, $selected_id);
1139 function sales_areas_list_row($label, $name, $selected_id=null)
1141 echo "<tr><td class='label'>$label</td>";
1142 sales_areas_list_cells(null, $name, $selected_id);
1146 //------------------------------------------------------------------------------------
1148 function sales_groups_list($name, $selected_id=null, $special_option=false)
1150 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1151 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1152 'spec_option' => $special_option===true ? ' ' : $special_option,
1153 'order' => 'description', 'spec_id' => 0,
1157 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1160 echo "<td>$label</td>\n";
1162 echo sales_groups_list($name, $selected_id, $special_option);
1166 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1168 echo "<tr><td class='label'>$label</td>";
1169 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1173 //------------------------------------------------------------------------------------
1175 function _format_template_items($row)
1177 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1180 function templates_list($name, $selected_id=null, $special_option=false)
1182 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1183 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1184 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1185 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1186 'format' => '_format_template_items',
1187 'spec_option' => $special_option===true ? ' ' : $special_option,
1188 'order' => 'order_no', 'spec_id' => 0,
1192 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1195 echo "<td>$label</td>\n";
1197 echo templates_list($name, $selected_id, $special_option);
1201 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1203 echo "<tr><td class='label'>$label</td>";
1204 templates_list_cells(null, $name, $selected_id, $special_option);
1208 //------------------------------------------------------------------------------------
1210 function workorders_list($name, $selected_id=null)
1212 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1213 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1216 function workorders_list_cells($label, $name, $selected_id=null)
1219 echo "<td>$label</td>\n";
1221 echo workorders_list($name, $selected_id);
1225 function workorders_list_row($label, $name, $selected_id=null)
1227 echo "<tr><td class='label'>$label</td>";
1228 workorders_list_cells(null, $name, $selected_id);
1232 //------------------------------------------------------------------------------------
1234 function payment_terms_list($name, $selected_id=null)
1236 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1237 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1240 function payment_terms_list_cells($label, $name, $selected_id=null)
1243 echo "<td>$label</td>\n";
1245 echo payment_terms_list($name, $selected_id);
1249 function payment_terms_list_row($label, $name, $selected_id=null)
1251 echo "<tr><td class='label'>$label</td>";
1252 payment_terms_list_cells(null, $name, $selected_id);
1256 //------------------------------------------------------------------------------------
1258 function credit_status_list($name, $selected_id=null)
1260 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1261 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1264 function credit_status_list_cells($label, $name, $selected_id=null)
1267 echo "<td>$label</td>\n";
1269 echo credit_status_list($name, $selected_id);
1273 function credit_status_list_row($label, $name, $selected_id=null)
1275 echo "<tr><td class='label'>$label</td>";
1276 credit_status_list_cells(null, $name, $selected_id);
1280 //-----------------------------------------------------------------------------------------------
1282 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1284 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1286 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1288 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1290 'select_submit'=> $submit_on_change,
1291 // 'async' => false,
1295 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1298 echo "<td>$label</td>\n";
1300 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1304 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1306 echo "<tr><td class='label'>$label</td>";
1307 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1311 //-----------------------------------------------------------------------------------------------
1313 function _format_date($row)
1315 return sql2date($row['reconciled']);
1318 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1320 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1321 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1322 GROUP BY reconciled";
1323 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1325 'spec_option' => $special_option,
1326 'format' => '_format_date',
1328 'select_submit'=> $submit_on_change
1332 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1335 echo "<td>$label</td>\n";
1337 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1341 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1344 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1348 //-----------------------------------------------------------------------------------------------
1350 function workcenter_list($name, $selected_id=null, $all_option=false)
1353 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1355 return combo_input($name, $selected_id, $sql, 'id', 'name',
1357 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1358 'spec_id' => ALL_TEXT,
1362 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1364 default_focus($name);
1366 echo "<td>$label</td>\n";
1368 echo workcenter_list($name, $selected_id, $all_option);
1372 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1374 echo "<tr><td class='label'>$label</td>";
1375 workcenter_list_cells(null, $name, $selected_id, $all_option);
1379 //-----------------------------------------------------------------------------------------------
1381 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1383 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1384 FROM ".TB_PREF."bank_accounts";
1386 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1388 'format' => '_format_add_curr',
1389 'select_submit'=> $submit_on_change,
1390 'spec_option' => $spec_option,
1396 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1399 echo "<td>$label</td>\n";
1401 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1405 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1407 echo "<tr><td class='label'>$label</td>";
1408 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1411 //-----------------------------------------------------------------------------------------------
1413 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1416 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1417 FROM ".TB_PREF."bank_accounts
1418 WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
1421 echo "<tr><td class='label'>$label</td>\n";
1423 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1425 'spec_option' => $all_option,
1426 'spec_id' => ALL_TEXT,
1427 'format' => '_format_add_curr',
1428 'select_submit'=> $submit_on_change,
1431 echo "</td></tr>\n";
1433 //-----------------------------------------------------------------------------------------------
1435 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1437 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1439 default_focus($name);
1442 echo "<td class='label'>$label</td>\n";
1445 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1447 'select_submit'=> $submit_on_change,
1449 'spec_option' =>$spec_option,
1451 'order'=> array('pos_name')
1453 echo "</td></tr>\n";
1456 //-----------------------------------------------------------------------------------------------
1457 // Payment type selector for current user.
1459 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1461 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1463 if ($category == PM_CASH) // only cash
1464 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1465 elseif ($category == PM_CREDIT) // only delayed payments
1466 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1467 elseif (!$prepayments)
1468 $sql .= " WHERE days_before_due>=0";
1470 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1472 'select_submit'=> $submit_on_change,
1478 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1481 echo "<td class='label'>$label</td>\n";
1484 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1488 //-----------------------------------------------------------------------------------------------
1490 function class_list($name, $selected_id=null, $submit_on_change=false)
1492 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1494 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1496 'select_submit'=> $submit_on_change,
1502 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1505 echo "<td>$label</td>\n";
1507 echo class_list($name, $selected_id, $submit_on_change);
1511 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1513 echo "<tr><td class='label'>$label</td>";
1514 class_list_cells(null, $name, $selected_id, $submit_on_change);
1518 //-----------------------------------------------------------------------------------------------
1519 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1521 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1522 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1523 array('order'=>'category_id',
1524 'spec_option' => $spec_opt,
1526 'select_submit'=> $submit_on_change,
1531 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1534 echo "<td>$label</td>\n";
1536 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1540 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1542 echo "<tr><td class='label'>$label</td>";
1543 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1547 //-----------------------------------------------------------------------------------------------
1549 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1552 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1554 return combo_input($name, $selected_id, $sql, 'id', 'name',
1556 'format' => '_format_account',
1557 'order' => array('class_id', 'id', 'parent'),
1558 'spec_option' =>$all_option,
1559 'spec_id' => ALL_TEXT
1563 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1566 echo "<td>$label</td>\n";
1568 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1572 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1574 echo "<tr><td class='label'>$label</td>";
1575 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1580 //-----------------------------------------------------------------------------------------------
1581 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1582 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1584 if ($skip_bank_accounts)
1585 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1586 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1587 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1588 ."ON chart.account_code=acc.account_code
1589 WHERE acc.account_code IS NULL
1590 AND chart.account_type=type.id";
1592 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1593 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1594 WHERE chart.account_type=type.id";
1596 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1598 'format' => '_format_account',
1599 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1602 'order' => array('type.class_id','type.id','account_code'),
1603 'search_box' => $cells,
1604 'search_submit' => false,
1608 'select_submit'=> $submit_on_change,
1611 'show_inactive' => $all
1616 function _format_account($row)
1618 return $row[0] . " " . $row[1];
1621 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1622 $skip_bank_accounts=false, $cells=false, $all_option=false,
1623 $submit_on_change=false, $all=false)
1626 echo "<td>$label</td>\n";
1628 echo gl_all_accounts_list($name, $selected_id,
1629 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1633 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1634 $skip_bank_accounts=false, $cells=false, $all_option=false)
1636 echo "<tr><td class='label'>$label</td>";
1637 gl_all_accounts_list_cells(null, $name, $selected_id,
1638 $skip_bank_accounts, $cells, $all_option);
1642 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1645 $items['0'] = strlen($name_no) ? $name_no : _("No");
1646 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1648 return array_selector($name, $selected_id, $items,
1650 'select_submit'=> $submit_on_change,
1651 'async' => false ) ); // FIX?
1654 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1657 echo "<td>$label</td>\n";
1659 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1663 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1665 echo "<tr><td class='label'>$label</td>";
1666 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1670 //------------------------------------------------------------------------------------------------
1672 function languages_list($name, $selected_id=null, $all_option=false)
1674 global $installed_languages;
1678 $items[''] = $all_option;
1679 foreach ($installed_languages as $lang)
1680 $items[$lang['code']] = $lang['name'];
1681 return array_selector($name, $selected_id, $items);
1684 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1687 echo "<td>$label</td>\n";
1689 echo languages_list($name, $selected_id, $all_option);
1693 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1695 echo "<tr><td class='label'>$label</td>";
1696 languages_list_cells(null, $name, $selected_id, $all_option);
1700 //------------------------------------------------------------------------------------------------
1702 function bank_account_types_list($name, $selected_id=null)
1704 global $bank_account_types;
1706 return array_selector($name, $selected_id, $bank_account_types);
1709 function bank_account_types_list_cells($label, $name, $selected_id=null)
1712 echo "<td>$label</td>\n";
1714 echo bank_account_types_list($name, $selected_id);
1718 function bank_account_types_list_row($label, $name, $selected_id=null)
1720 echo "<tr><td class='label'>$label</td>";
1721 bank_account_types_list_cells(null, $name, $selected_id);
1725 //------------------------------------------------------------------------------------------------
1726 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1728 global $payment_person_types;
1731 foreach ($payment_person_types as $key=>$type)
1733 if ($key != PT_WORKORDER)
1734 $items[$key] = $type;
1736 return array_selector($name, $selected_id, $items,
1737 array( 'select_submit'=> $submit_on_change ) );
1740 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1743 echo "<td>$label</td>\n";
1745 echo payment_person_types_list($name, $selected_id, $related);
1749 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1751 echo "<tr><td class='label'>$label</td>";
1752 payment_person_types_list_cells(null, $name, $selected_id, $related);
1756 //------------------------------------------------------------------------------------------------
1758 function wo_types_list($name, $selected_id=null)
1760 global $wo_types_array;
1762 return array_selector($name, $selected_id, $wo_types_array,
1763 array( 'select_submit'=> true, 'async' => true ) );
1766 function wo_types_list_row($label, $name, $selected_id=null)
1768 echo "<tr><td class='label'>$label</td><td>\n";
1769 echo wo_types_list($name, $selected_id);
1770 echo "</td></tr>\n";
1773 //------------------------------------------------------------------------------------------------
1775 function dateformats_list_row($label, $name, $value=null)
1779 echo "<tr><td class='label'>$label</td>\n<td>";
1780 echo array_selector( $name, $value, $SysPrefs->dateformats );
1781 echo "</td></tr>\n";
1784 function dateseps_list_row($label, $name, $value=null)
1788 echo "<tr><td class='label'>$label</td>\n<td>";
1789 echo array_selector( $name, $value, $SysPrefs->dateseps );
1790 echo "</td></tr>\n";
1793 function thoseps_list_row($label, $name, $value=null)
1797 echo "<tr><td class='label'>$label</td>\n<td>";
1798 echo array_selector( $name, $value, $SysPrefs->thoseps );
1799 echo "</td></tr>\n";
1802 function decseps_list_row($label, $name, $value=null)
1806 echo "<tr><td class='label'>$label</td>\n<td>";
1807 echo array_selector( $name, $value, $SysPrefs->decseps );
1808 echo "</td></tr>\n";
1811 function themes_list_row($label, $name, $value=null)
1813 global $path_to_root;
1815 $path = $path_to_root.'/themes/';
1817 $themedir = opendir($path);
1818 while(false !== ($fname = readdir($themedir)))
1820 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1822 $themes[$fname] = $fname;
1827 echo "<tr><td class='label'>$label</td>\n<td>";
1828 echo array_selector( $name, $value, $themes );
1829 echo "</td></tr>\n";
1832 function pagesizes_list_row($label, $name, $value=null)
1837 foreach ($SysPrefs->pagesizes as $pz)
1840 echo "<tr><td class='label'>$label</td>\n<td>";
1841 echo array_selector( $name, $value, $items );
1842 echo "</td></tr>\n";
1845 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1847 global $systypes_array;
1849 // emove non-voidable transactions if needed
1850 $systypes = array_diff_key($systypes_array, array_flip($exclude));
1851 return array_selector($name, $value, $systypes,
1853 'spec_option'=> $spec_opt,
1854 'spec_id' => ALL_NUMERIC,
1855 'select_submit'=> $submit_on_change,
1861 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1864 echo "<td>$label</td>\n";
1866 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
1870 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1872 echo "<tr><td class='label'>$label</td>";
1873 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
1877 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1879 global $systypes_array;
1882 echo "<td>$label</td>\n";
1885 $items = $systypes_array;
1887 // exclude quotes, orders and dimensions
1888 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
1889 unset($items[$excl]);
1891 echo array_selector($name, $value, $items,
1893 'spec_option'=> _("All"),
1895 'select_submit'=> $submit_on_change,
1902 function cust_allocations_list_cells($label, $name, $selected=null)
1909 ALL_TEXT=>_("All Types"),
1910 '1'=> _("Sales Invoices"),
1911 '2'=> _("Overdue Invoices"),
1912 '3' => _("Payments"),
1913 '4' => _("Credit Notes"),
1914 '5' => _("Delivery Notes")
1916 echo array_selector($name, $selected, $allocs);
1920 function supp_allocations_list_cell($name, $selected=null)
1925 ALL_TEXT=>_("All Types"),
1926 '1'=> _("Invoices"),
1927 '2'=> _("Overdue Invoices"),
1928 '3' => _("Payments"),
1929 '4' => _("Credit Notes"),
1930 '5' => _("Overdue Credit Notes")
1932 echo array_selector($name, $selected, $allocs);
1936 function supp_transactions_list_cell($name, $selected=null)
1941 ALL_TEXT=>_("All Types"),
1943 '1'=> _("Invoices"),
1944 '2'=> _("Overdue Invoices"),
1945 '3' => _("Payments"),
1946 '4' => _("Credit Notes"),
1947 '5' => _("Overdue Credit Notes")
1950 echo array_selector($name, $selected, $allocs);
1954 function policy_list_cells($label, $name, $selected=null)
1959 echo array_selector($name, $selected,
1960 array( '' => _("Automatically put balance on back order"),
1961 'CAN' => _("Cancel any quantites not delivered")) );
1965 function policy_list_row($label, $name, $selected=null)
1967 echo "<tr><td class='label'>$label</td>";
1968 policy_list_cells(null, $name, $selected);
1972 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1977 echo array_selector($name, $selected,
1978 array( 'Return' => _("Items Returned to Inventory Location"),
1979 'WriteOff' => _("Items Written Off")),
1980 array( 'select_submit'=> $submit_on_change ) );
1984 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1986 echo "<tr><td class='label'>$label</td>";
1987 credit_type_list_cells(null, $name, $selected, $submit_on_change);
1991 function number_list($name, $selected, $from, $to, $no_option=false)
1994 for ($i = $from; $i <= $to; $i++)
1997 return array_selector($name, $selected, $items,
1998 array( 'spec_option' => $no_option,
1999 'spec_id' => ALL_NUMERIC) );
2002 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2007 echo number_list($name, $selected, $from, $to, $no_option);
2011 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2013 echo "<tr><td class='label'>$label</td>";
2014 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2018 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2019 $submit_on_change=true)
2021 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2022 ." GROUP BY profile";
2023 $result = db_query($sql, 'cannot get all profile names');
2024 $profiles = array();
2025 while($myrow=db_fetch($result)) {
2026 $profiles[$myrow['profile']] = $myrow['profile'];
2031 echo "<td class='label'>$label</td>\n";
2034 echo array_selector($name, $selected_id, $profiles,
2035 array( 'select_submit'=> $submit_on_change,
2036 'spec_option'=>$spec_opt,
2040 echo "</td></tr>\n";
2043 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2045 static $printers; // query only once for page display
2048 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2049 $result = db_query($sql, 'cannot get all printers');
2050 $printers = array();
2051 while($myrow=db_fetch($result)) {
2052 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2055 return array_selector($name, $selected_id, $printers,
2056 array( 'select_submit'=> $submit_on_change,
2057 'spec_option'=>$spec_opt,
2062 //------------------------------------------------------------------------------------------------
2064 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2067 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2069 $sql .= " WHERE type=$type";
2071 return combo_input($name, $selected_id, $sql, 'id', 'description',
2074 'order' => 'description',
2075 'select_submit'=> $submit_on_change,
2081 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2084 echo "<td>$label</td>\n";
2086 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2090 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2092 echo "<tr><td class='label'>$label</td>";
2093 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2098 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2100 global $quick_actions;
2102 echo "<tr><td class='label'>$label</td><td>";
2103 echo array_selector($name, $selected_id, $quick_actions,
2105 'select_submit'=> $submit_on_change
2107 echo "</td></tr>\n";
2110 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2112 global $quick_entry_types;
2114 echo "<tr><td class='label'>$label</td><td>";
2115 echo array_selector($name, $selected_id, $quick_entry_types,
2117 'select_submit'=> $submit_on_change
2119 echo "</td></tr>\n";
2122 function record_status_list_row($label, $name) {
2123 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2126 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2128 global $class_types;
2130 echo "<tr><td class='label'>$label</td><td>";
2131 echo array_selector($name, $selected_id, $class_types,
2133 'select_submit'=> $submit_on_change
2135 echo "</td></tr>\n";
2138 //------------------------------------------------------------------------------------------------
2140 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2141 $show_inactive = false)
2144 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2146 return combo_input($name, $selected_id, $sql, 'id', 'description',
2148 'spec_option'=>$new_item ? _("New role") : false,
2150 'select_submit'=> $submit_on_change,
2151 'show_inactive' => $show_inactive
2155 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2156 $show_inactive = false)
2159 echo "<td>$label</td>\n";
2161 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2165 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2166 $show_inactive = false)
2168 echo "<tr><td class='label'>$label</td>";
2169 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2173 function tab_list_row($label, $name, $selected_id=null)
2175 global $installed_extensions;
2178 foreach ($_SESSION['App']->applications as $app) {
2179 $tabs[$app->id] = access_string($app->name, true);
2182 echo "<td class='label'>$label</td><td>\n";
2183 echo array_selector($name, $selected_id, $tabs);
2184 echo "</td></tr>\n";
2187 //-----------------------------------------------------------------------------------------------
2189 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2192 global $path_to_root;
2193 include_once($path_to_root . "/admin/db/tags_db.inc");
2194 $results = get_tags($type, $all);
2196 while ($tag = db_fetch($results))
2197 $tags[$tag['id']] = $tag['name'];
2199 if (!isset($tags)) {
2200 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2203 return array_selector($name, null, $tags,
2206 'height' => $height,
2207 'spec_option'=> $spec_opt,
2212 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2215 echo "<td>$label</td>\n";
2217 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2222 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2224 echo "<tr><td class='label'>$label</td>";
2225 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2229 //---------------------------------------------------------------------------------------------
2230 // List of sets of active extensions
2232 function extset_list($name, $value=null, $submit_on_change=false)
2234 global $db_connections;
2237 foreach ($db_connections as $comp)
2238 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2239 return array_selector( $name, $value, $items,
2241 'spec_option'=> _("Available and/or installed"),
2243 'select_submit'=> $submit_on_change,
2248 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2251 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2256 if (@$filter['class']) {
2257 $where[] = 'type='.db_escape($filter['class']);
2260 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2261 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2262 if (@$filter['multi']) { // contact category selector for person
2266 return combo_input($name, $selected_id, $sql, 'id', 'name',
2269 'height' => $multi ? 5:1,
2270 'category' => $groups,
2271 'select_submit'=> $submit_on_change,
2277 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2279 echo "<tr><td class='label'>$label</td><td>";
2280 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2281 echo "</td></tr>\n";
2284 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2286 global $pterm_types;
2288 echo "<tr><td class='label'>$label</td><td>";
2289 echo array_selector($name, $selected_id, $pterm_types,
2291 'select_submit'=> $submit_on_change
2293 echo "</td></tr>\n";
2296 function coa_list_row($label, $name, $value=null)
2298 global $path_to_root, $installed_extensions;
2300 $path = $path_to_root.'/sql/';
2302 $sqldir = opendir($path);
2303 while (false !== ($fname = readdir($sqldir)))
2305 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2307 $ext = array_search_value($fname, $installed_extensions, 'sql');
2309 $descr = $ext['name'];
2310 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2311 $descr = _("Standard new company American COA (4 digit)");
2312 } elseif ($fname == 'en_US-demo.sql') {
2313 $descr = _("Standard American COA (4 digit) with demo data");
2317 $coas[$fname] = $descr;
2322 echo "<tr><td class='label'>$label</td>\n<td>";
2323 echo array_selector( $name, $value, $coas );
2324 echo "</td></tr>\n";
2327 function payment_services($name)
2329 global $payment_services;
2331 $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2333 return array_selector($name, null, $services, array(
2334 'spec_option'=> _("No payment Link"),
2339 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2341 global $tax_algorithms;
2343 return array_selector($name, $value, $tax_algorithms,
2345 'select_submit'=> $submit_on_change,
2351 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2354 echo "<td>$label</td>\n";
2356 echo tax_algorithm_list($name, $value, $submit_on_change);
2360 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2362 echo "<tr><td class='label'>$label</td>";
2363 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2367 function refline_list($name, $type, $value=null, $spec_option=false)
2369 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2374 $where = array('`trans_type`='.db_escape($type));
2376 return combo_input($name, $value, $sql, 'id', 'prefix',
2378 'order'=>array('prefix'),
2379 'spec_option' => $spec_option,
2383 'select_submit' => true,
2388 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2392 echo "<td class='label'>$label</td>\n";
2395 echo refline_list($name, $type, $selected_id, $spec_option);
2396 echo "</td></tr>\n";
2400 //----------------------------------------------------------------------------------------------
2402 function subledger_list($name, $account, $selected_id=null)
2405 $type = is_subledger_account($account);
2410 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2412 .TB_PREF."debtors_master d,"
2413 .TB_PREF."cust_branch c
2414 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2416 $sql = "SELECT supplier_id as id, supp_ref as name
2418 .TB_PREF."suppliers s
2419 WHERE s.payable_account=".db_escape($account);
2421 $mode = get_company_pref('no_customer_list');
2423 return combo_input($name, $selected_id, $sql, 'id', 'name',
2431 function subledger_list_cells($label, $name, $account, $selected_id=null)
2434 echo "<td>$label</td>\n";
2436 echo subledger_list($name, $account, $selected_id);
2440 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2441 $submit_on_change=false, $show_inactive=false, $editkey = false)
2443 echo "<tr><td class='label'>$label</td><td nowrap>";
2444 echo subledger_list($name, $account, $selected_id);
2445 echo "</td>\n</tr>\n";
2448 function accounts_type_list_row($label, $name, $selected_id=null)
2452 echo "<td class='label'>$label</td>\n";
2454 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2455 echo array_selector($name, $selected_id, $sel);
2456 echo "</td></tr>\n";
2459 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2462 $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2465 echo "<td>$label</td>\n";
2468 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2470 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2472 'order' => 'real_name',
2473 'select_submit'=> $submit_on_change,
2480 function collations_list_row($label, $name, $selected_id=null)
2482 global $supported_collations;
2486 echo "<td class='label'>$label</td>\n";
2489 echo array_selector($name, $selected_id, $supported_collations,
2490 array('select_submit'=> false) );
2491 echo "</td></tr>\n";