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($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 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
243 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
244 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
245 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
247 if ($by_id && ($search_box != false || $opts['editable']) ) {
248 // on first display show selector list
249 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
250 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
251 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
252 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
253 set_focus($name.'_text'); // prevent lost focus
254 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
255 set_focus($name); // prevent lost focus
256 if (!$opts['editable'])
258 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
261 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
263 // span for select list/input field update
264 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
266 // if selectable or editable list is used - add select button
267 if ($select_submit != false || $search_button) {
268 // button class selects form reload/ajax selector update
269 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
270 (fallback_mode() ? '' : 'display:none;'),
271 '_'.$name.'_update')."\n";
273 // ------ make combo ----------
275 if ($search_box != false) {
276 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
277 $opts['size']."' maxlength='".$opts['max'].
278 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
279 .$opts['box_hint']."'"
280 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
282 if ($search_submit != false || $opts['editable']) {
283 $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
284 (fallback_mode() ? '' : 'display:none;'),
285 $search_submit ? $search_submit : "_{$name}_button")."\n";
288 default_focus(($search_box && $by_id) ? $search_box : $name);
290 if ($opts['editlink'])
291 $selector .= ' '.$opts['editlink'];
293 if ($search_box && $opts['cells'])
294 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
296 $str = $edit_entry.$selector;
302 Returns true if selector $name is subject to update.
304 function list_updated($name)
306 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
308 //----------------------------------------------------------------------------------------------
309 // Universal array combo generator
310 // $items is array of options 'value' => 'description'
311 // Options is reduced set of combo_selector options and is merged with defaults.
313 function array_selector($name, $selected_id, $items, $options=null)
317 $opts = array( // default options
318 'spec_option'=>false, // option text or false
319 'spec_id' => 0, // option id
320 'select_submit' => false, //submit on select: true/false
321 'async' => true, // select update via ajax (true) vs _page_body reload
322 'default' => '', // default value when $_POST is not set
323 'multi'=>false, // multiple select
324 // search box parameters
325 'height' => false, // number of lines in select box
329 // ------ merge options with defaults ----------
331 $opts = array_merge($opts, $options);
332 $select_submit = $opts['select_submit'];
333 $spec_id = $opts['spec_id'];
334 $spec_option = $opts['spec_option'];
335 $disabled = $opts['disabled'] ? "disabled" : '';
336 $multi = $opts['multi'];
338 if ($selected_id == null) {
339 $selected_id = get_post($name, $opts['default']);
341 if(!is_array($selected_id))
342 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
344 if (isset($_POST[ '_'.$name.'_update'])) {
346 $Ajax->activate('_page_body');
348 $Ajax->activate($name);
351 // ------ make selector ----------
352 $selector = $first_opt = '';
355 foreach($items as $value=>$descr) {
357 if (in_array((string)$value, $selected_id, true)) {
361 if ($first_id === false) {
365 $selector .= "<option $sel value='$value'>$descr</option>\n";
368 if ($first_id!==false) {
369 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
371 // Prepend special option.
372 if ($spec_option !== false) { // if special option used - add it
373 $first_id = $spec_id;
374 $first_opt = $spec_option;
375 $sel = $found===false ? 'selected' : '';
376 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
380 if ($found===false) {
381 $selected_id = array($first_id);
383 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
385 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
386 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
387 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
388 . $opts['sel_hint']."'>".$selector."</select>\n";
390 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
392 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
394 if ($select_submit != false) { // if submit on change is used - add select button
395 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
396 (fallback_mode() ? '' : 'display:none;'),
397 '_'.$name.'_update')."\n";
399 default_focus($name);
403 //----------------------------------------------------------------------------------------------
405 function _format_add_curr($row)
407 static $company_currency;
409 if ($company_currency == null)
411 $company_currency = get_company_currency();
413 return $row[1] . ($row[2] == $company_currency ?
414 '' : (" - " . $row[2]));
417 function add_edit_combo($type)
419 global $path_to_root, $popup_editors, $SysPrefs;
421 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
424 $theme_path = $path_to_root . '/themes/' . user_theme();
426 $key = $popup_editors[$type][1];
427 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
428 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
429 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
432 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
433 $all=false, $editkey = false)
436 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
438 $mode = get_company_pref('no_supplier_list');
441 set_editor('supplier', $name, $editkey);
443 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
445 'format' => '_format_add_curr',
446 'order' => array('supp_ref'),
447 'search_box' => $mode!=0,
449 'search' => array("supp_ref","supp_name","gst_no"),
450 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
451 'spec_id' => ALL_TEXT,
452 'select_submit'=> $submit_on_change,
454 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
455 _('Select supplier'),
456 'show_inactive'=>$all,
457 'editlink' => $editkey ? add_edit_combo('supplier') : false
462 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
463 $submit_on_change=false, $all=false, $editkey = false)
466 echo "<td>$label</td><td>\n";
467 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
472 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
473 $submit_on_change=false, $all=false, $editkey = false)
475 echo "<tr><td class='label'>$label</td><td>";
476 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
480 //----------------------------------------------------------------------------------------------
482 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
483 $show_inactive=false, $editkey = false)
486 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
488 $mode = get_company_pref('no_customer_list');
491 set_editor('customer', $name, $editkey);
493 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
495 'format' => '_format_add_curr',
496 'order' => array('debtor_ref'),
497 'search_box' => $mode!=0,
500 'search' => array("debtor_ref","name","tax_id"),
501 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
502 'spec_id' => ALL_TEXT,
503 'select_submit'=> $submit_on_change,
505 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
506 _('Select customer'),
507 'show_inactive' => $show_inactive,
508 'editlink' => $editkey ? add_edit_combo('customer') : false
513 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
514 $submit_on_change=false, $show_inactive=false, $editkey = false)
517 echo "<td>$label</td>\n";
519 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
520 $show_inactive, $editkey);
524 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
525 $submit_on_change=false, $show_inactive=false, $editkey = false)
528 echo "<tr><td class='label'>$label</td><td nowrap>";
529 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
530 $show_inactive, $editkey);
531 echo "</td>\n</tr>\n";
534 //------------------------------------------------------------------------------------------------
536 function customer_branches_list($customer_id, $name, $selected_id=null,
537 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
540 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
541 WHERE debtor_no=" . db_escape($customer_id)." ";
544 set_editor('branch', $name, $editkey);
546 $where = $enabled ? array("inactive = 0") : array();
547 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
550 'order' => array('branch_ref'),
551 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
552 'spec_id' => ALL_TEXT,
553 'select_submit'=> $submit_on_change,
554 'sel_hint' => _('Select customer branch'),
555 'editlink' => $editkey ? add_edit_combo('branch') : false
559 //------------------------------------------------------------------------------------------------
561 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
562 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
565 echo "<td>$label</td>\n";
567 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
568 $submit_on_change, $editkey);
572 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
573 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
575 echo "<tr><td class='label'>$label</td>";
576 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
577 $all_option, $enabled, $submit_on_change, $editkey);
581 //------------------------------------------------------------------------------------------------
583 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
586 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
588 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
590 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
591 'spec_id' => ALL_TEXT,
592 'select_submit'=> $submit_on_change
596 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
599 echo "<td>$label</td>\n";
601 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
605 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
607 echo "<tr><td class='label'>$label</td>";
608 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
612 //-----------------------------------------------------------------------------------------------
614 function currencies_list($name, $selected_id=null, $submit_on_change=false)
616 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
618 // default to the company currency
619 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
621 'select_submit'=> $submit_on_change,
622 'default' => get_company_currency(),
627 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
630 echo "<td>$label</td>\n";
632 echo currencies_list($name, $selected_id, $submit_on_change);
636 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
638 echo "<tr><td class='label'>$label</td>";
639 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
643 //---------------------------------------------------------------------------------------------------
645 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
648 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
650 // default to the company current fiscal year
652 return combo_input($name, $selected_id, $sql, 'id', '',
655 'default' => get_company_pref('f_year'),
656 'format' => '_format_fiscalyears',
657 'select_submit'=> $submit_on_change,
662 function _format_fiscalyears($row)
664 return sql2date($row[1]) . " - " . sql2date($row[2])
665 . " " . ($row[3] ? _('Closed') : _('Active'));
668 function fiscalyears_list_cells($label, $name, $selected_id=null)
671 echo "<td>$label</td>\n";
673 echo fiscalyears_list($name, $selected_id);
677 function fiscalyears_list_row($label, $name, $selected_id=null)
679 echo "<tr><td class='label'>$label</td>";
680 fiscalyears_list_cells(null, $name, $selected_id);
683 //------------------------------------------------------------------------------------
685 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
686 $submit_on_change=false, $showclosed=false, $showtype=1)
688 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
691 'order' => 'reference',
692 'spec_option'=>$no_option ? $showname : false,
694 'select_submit'=> $submit_on_change,
699 $options['where'][] = "closed=0";
701 $options['where'][] = "type_=".db_escape($showtype);
703 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
706 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
707 $showclosed=false, $showtype=0, $submit_on_change=false)
710 echo "<td>$label</td>\n";
712 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
716 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
717 $showclosed=false, $showtype=0, $submit_on_change=false)
719 echo "<tr><td class='label'>$label</td>";
720 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
721 $showclosed, $showtype, $submit_on_change);
725 //---------------------------------------------------------------------------------------------------
727 function stock_items_list($name, $selected_id=null, $all_option=false,
728 $submit_on_change=false, $opts=array(), $editkey = false)
731 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
732 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
735 set_editor('item', $name, $editkey);
737 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
740 'format' => '_format_stock_items',
741 'spec_option' => $all_option===true ? _("All Items") : $all_option,
742 'spec_id' => ALL_TEXT,
743 'search_box' => true,
744 'search' => array("stock_id", "c.description","s.description"),
745 'search_submit' => get_company_pref('no_item_list')!=0,
747 'select_submit'=> $submit_on_change,
749 'order' => array('c.description','stock_id'),
750 'editlink' => $editkey ? add_edit_combo('item') : false,
757 function _format_stock_items($row)
759 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
762 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
763 $submit_on_change=false, $all=false, $editkey = false, $opts= array())
766 echo "<td>$label</td>\n";
767 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
768 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey);
771 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
774 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
778 //---------------------------------------------------------------------------------------------------
780 // Select item via foreign code.
782 function sales_items_list($name, $selected_id=null, $all_option=false,
783 $submit_on_change=false, $type='', $opts=array())
786 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
787 i.inactive, if(count(*)>1, '0', s.editable) as editable
789 ".TB_PREF."stock_master s,
790 ".TB_PREF."item_codes i
792 ".TB_PREF."stock_category c
793 ON i.category_id=c.category_id
794 WHERE i.stock_id=s.stock_id";
797 if ($type == 'local') { // exclude foreign codes
798 $sql .= " AND !i.is_foreign";
799 } elseif ($type == 'kits') { // sales kits
800 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
802 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
803 $sql .= " GROUP BY i.item_code";
805 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
808 'format' => '_format_stock_items',
809 'spec_option' => $all_option===true ? _("All Items") : $all_option,
810 'spec_id' => ALL_TEXT,
811 'search_box' => true,
812 'search' => array("i.item_code", "c.description", "i.description"),
813 'search_submit' => get_company_pref('no_item_list')!=0,
815 'select_submit'=> $submit_on_change,
817 'order' => array('c.description','i.item_code'),
823 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
826 set_editor('item', $name, $editkey);
829 echo "<td>$label</td>\n";
830 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
831 '', array('cells'=>true));
834 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
836 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
837 'kits', array('cells'=>false, 'editable' => false));
840 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
844 echo "<td class='label'>$label</td>\n";
846 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
847 'local', array('cells'=>false, 'editable' => false));
850 //------------------------------------------------------------------------------------
852 function stock_manufactured_items_list($name, $selected_id=null,
853 $all_option=false, $submit_on_change=false)
855 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
856 array('where'=>array("mb_flag= 'M'")));
859 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
860 $all_option=false, $submit_on_change=false)
863 echo "<td>$label</td>\n";
865 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
869 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
870 $all_option=false, $submit_on_change=false)
872 echo "<tr><td class='label'>$label</td>";
873 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
876 //------------------------------------------------------------------------------------
878 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
879 $all_option=false, $submit_on_change=false, $editkey = false)
881 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
882 array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
885 function stock_component_items_list_cells($label, $name, $parent_stock_id,
886 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
889 echo "<td>$label</td>\n";
890 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
891 array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
894 //------------------------------------------------------------------------------------
896 function stock_costable_items_list($name, $selected_id=null,
897 $all_option=false, $submit_on_change=false)
899 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
900 array('where'=>array("mb_flag!='D'")));
903 function stock_costable_items_list_cells($label, $name, $selected_id=null,
904 $all_option=false, $submit_on_change=false)
907 echo "<td>$label</td>\n";
908 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
909 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
912 //------------------------------------------------------------------------------------
913 function stock_purchasable_items_list($name, $selected_id=null,
914 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
916 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
917 array('where'=>array("NOT no_purchase"),
918 'show_inactive'=>$all), $editkey);
921 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
923 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
924 $all_option=false, $submit_on_change=false, $editkey=false)
927 echo "<td>$label</td>\n";
928 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
929 array('where'=>array("NOT no_purchase"),
931 'cells'=>true), $editkey);
934 //------------------------------------------------------------------------------------
936 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
942 echo "<td class='label'>$label</td>\n";
945 echo array_selector($name, $selected_id, $stock_types,
947 'select_submit'=> true,
948 'disabled' => !$enabled) );
952 function stock_units_list_row($label, $name, $value=null, $enabled=true)
954 $result = get_all_item_units();
957 echo "<td class='label'>$label</td>\n";
960 while($unit = db_fetch($result))
961 $units[$unit['abbr']] = $unit['name'];
963 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
968 //------------------------------------------------------------------------------------
970 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
972 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
974 return combo_input($name, $selected_id, $sql, 'id', 'name',
976 'spec_option' => $none_option,
977 'spec_id' => ALL_NUMERIC,
978 'select_submit'=> $submit_on_change,
983 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
984 $submit_on_change=false)
987 echo "<td>$label</td>\n";
989 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
993 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
994 $submit_on_change=false)
996 echo "<tr><td class='label'>$label</td>";
997 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1001 //------------------------------------------------------------------------------------
1003 function tax_groups_list($name, $selected_id=null,
1004 $none_option=false, $submit_on_change=false)
1006 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1008 return combo_input($name, $selected_id, $sql, 'id', 'name',
1011 'spec_option' => $none_option,
1012 'spec_id' => ALL_NUMERIC,
1013 'select_submit'=> $submit_on_change,
1018 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1021 echo "<td>$label</td>\n";
1023 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1027 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1029 echo "<tr><td class='label'>$label</td>";
1030 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1034 //------------------------------------------------------------------------------------
1036 function item_tax_types_list($name, $selected_id=null)
1038 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1039 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1042 function item_tax_types_list_cells($label, $name, $selected_id=null)
1045 echo "<td>$label</td>\n";
1047 echo item_tax_types_list($name, $selected_id);
1051 function item_tax_types_list_row($label, $name, $selected_id=null)
1053 echo "<tr><td class='label'>$label</td>";
1054 item_tax_types_list_cells(null, $name, $selected_id);
1058 //------------------------------------------------------------------------------------
1060 function shippers_list($name, $selected_id=null)
1062 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1063 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1064 array('order'=>array('shipper_name')));
1067 function shippers_list_cells($label, $name, $selected_id=null)
1070 echo "<td>$label</td>\n";
1072 echo shippers_list($name, $selected_id);
1076 function shippers_list_row($label, $name, $selected_id=null)
1078 echo "<tr><td class='label'>$label</td>";
1079 shippers_list_cells(null, $name, $selected_id);
1083 //-------------------------------------------------------------------------------------
1085 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1087 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1088 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1089 array('order'=>array('salesman_name'),
1090 'spec_option' => $spec_opt,
1091 'spec_id' => ALL_NUMERIC));
1094 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1097 echo "<td>$label</td>\n";
1099 echo sales_persons_list($name, $selected_id, $spec_opt);
1103 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1105 echo "<tr><td class='label'>$label</td>";
1106 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1110 //------------------------------------------------------------------------------------
1112 function sales_areas_list($name, $selected_id=null)
1114 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1115 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1118 function sales_areas_list_cells($label, $name, $selected_id=null)
1121 echo "<td>$label</td>\n";
1123 echo sales_areas_list($name, $selected_id);
1127 function sales_areas_list_row($label, $name, $selected_id=null)
1129 echo "<tr><td class='label'>$label</td>";
1130 sales_areas_list_cells(null, $name, $selected_id);
1134 //------------------------------------------------------------------------------------
1136 function sales_groups_list($name, $selected_id=null, $special_option=false)
1138 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1139 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1140 'spec_option' => $special_option===true ? ' ' : $special_option,
1141 'order' => 'description', 'spec_id' => 0,
1145 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1148 echo "<td>$label</td>\n";
1150 echo sales_groups_list($name, $selected_id, $special_option);
1154 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1156 echo "<tr><td class='label'>$label</td>";
1157 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1161 //------------------------------------------------------------------------------------
1163 function _format_template_items($row)
1165 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1168 function templates_list($name, $selected_id=null, $special_option=false)
1170 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1171 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1172 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1173 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1174 'format' => '_format_template_items',
1175 'spec_option' => $special_option===true ? ' ' : $special_option,
1176 'order' => 'order_no', 'spec_id' => 0,
1180 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1183 echo "<td>$label</td>\n";
1185 echo templates_list($name, $selected_id, $special_option);
1189 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1191 echo "<tr><td class='label'>$label</td>";
1192 templates_list_cells(null, $name, $selected_id, $special_option);
1196 //------------------------------------------------------------------------------------
1198 function workorders_list($name, $selected_id=null)
1200 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1201 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1204 function workorders_list_cells($label, $name, $selected_id=null)
1207 echo "<td>$label</td>\n";
1209 echo workorders_list($name, $selected_id);
1213 function workorders_list_row($label, $name, $selected_id=null)
1215 echo "<tr><td class='label'>$label</td>";
1216 workorders_list_cells(null, $name, $selected_id);
1220 //------------------------------------------------------------------------------------
1222 function payment_terms_list($name, $selected_id=null)
1224 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1225 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1228 function payment_terms_list_cells($label, $name, $selected_id=null)
1231 echo "<td>$label</td>\n";
1233 echo payment_terms_list($name, $selected_id);
1237 function payment_terms_list_row($label, $name, $selected_id=null)
1239 echo "<tr><td class='label'>$label</td>";
1240 payment_terms_list_cells(null, $name, $selected_id);
1244 //------------------------------------------------------------------------------------
1246 function credit_status_list($name, $selected_id=null)
1248 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1249 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1252 function credit_status_list_cells($label, $name, $selected_id=null)
1255 echo "<td>$label</td>\n";
1257 echo credit_status_list($name, $selected_id);
1261 function credit_status_list_row($label, $name, $selected_id=null)
1263 echo "<tr><td class='label'>$label</td>";
1264 credit_status_list_cells(null, $name, $selected_id);
1268 //-----------------------------------------------------------------------------------------------
1270 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1272 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1274 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1276 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1278 'select_submit'=> $submit_on_change,
1282 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1285 echo "<td>$label</td>\n";
1287 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1291 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1293 echo "<tr><td class='label'>$label</td>";
1294 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1298 //-----------------------------------------------------------------------------------------------
1300 function _format_date($row)
1302 return sql2date($row['reconciled']);
1305 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1307 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1308 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1309 GROUP BY reconciled";
1310 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1312 'spec_option' => $special_option,
1313 'format' => '_format_date',
1315 'select_submit'=> $submit_on_change
1319 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1322 echo "<td>$label</td>\n";
1324 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1328 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1331 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1335 //-----------------------------------------------------------------------------------------------
1337 function workcenter_list($name, $selected_id=null, $all_option=false)
1340 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1342 return combo_input($name, $selected_id, $sql, 'id', 'name',
1344 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1345 'spec_id' => ALL_TEXT,
1349 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1351 default_focus($name);
1353 echo "<td>$label</td>\n";
1355 echo workcenter_list($name, $selected_id, $all_option);
1359 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1361 echo "<tr><td class='label'>$label</td>";
1362 workcenter_list_cells(null, $name, $selected_id, $all_option);
1366 //-----------------------------------------------------------------------------------------------
1368 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1370 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1371 FROM ".TB_PREF."bank_accounts";
1373 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1375 'format' => '_format_add_curr',
1376 'select_submit'=> $submit_on_change,
1377 'spec_option' => $spec_option,
1383 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1386 echo "<td>$label</td>\n";
1388 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1392 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1394 echo "<tr><td class='label'>$label</td>";
1395 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1398 //-----------------------------------------------------------------------------------------------
1400 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1403 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1404 FROM ".TB_PREF."bank_accounts
1405 WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
1408 echo "<tr><td class='label'>$label</td>\n";
1410 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1412 'spec_option' => $all_option,
1413 'spec_id' => ALL_TEXT,
1414 'format' => '_format_add_curr',
1415 'select_submit'=> $submit_on_change,
1418 echo "</td></tr>\n";
1420 //-----------------------------------------------------------------------------------------------
1422 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1424 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1426 default_focus($name);
1429 echo "<td class='label'>$label</td>\n";
1432 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1434 'select_submit'=> $submit_on_change,
1436 'spec_option' =>$spec_option,
1438 'order'=> array('pos_name')
1440 echo "</td></tr>\n";
1443 //-----------------------------------------------------------------------------------------------
1444 // Payment type selector for current user.
1446 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1448 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1450 if ($category == PM_CASH) // only cash
1451 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1452 elseif ($category == PM_CREDIT) // only delayed payments
1453 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1454 elseif (!$prepayments)
1455 $sql .= " WHERE days_before_due>=0";
1457 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1459 'select_submit'=> $submit_on_change,
1465 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1468 echo "<td class='label'>$label</td>\n";
1471 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1475 //-----------------------------------------------------------------------------------------------
1477 function class_list($name, $selected_id=null, $submit_on_change=false)
1479 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1481 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1483 'select_submit'=> $submit_on_change,
1489 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1492 echo "<td>$label</td>\n";
1494 echo class_list($name, $selected_id, $submit_on_change);
1498 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1500 echo "<tr><td class='label'>$label</td>";
1501 class_list_cells(null, $name, $selected_id, $submit_on_change);
1505 //-----------------------------------------------------------------------------------------------
1506 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1508 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1509 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1510 array('order'=>'category_id',
1511 'spec_option' => $spec_opt,
1513 'select_submit'=> $submit_on_change,
1518 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1521 echo "<td>$label</td>\n";
1523 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1527 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1529 echo "<tr><td class='label'>$label</td>";
1530 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1534 //-----------------------------------------------------------------------------------------------
1536 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1539 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1541 return combo_input($name, $selected_id, $sql, 'id', 'name',
1543 'format' => '_format_account',
1544 'order' => array('class_id', 'id', 'parent'),
1545 'spec_option' =>$all_option,
1546 'spec_id' => ALL_TEXT
1550 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1553 echo "<td>$label</td>\n";
1555 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1559 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1561 echo "<tr><td class='label'>$label</td>";
1562 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1567 //-----------------------------------------------------------------------------------------------
1568 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1569 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1571 if ($skip_bank_accounts)
1572 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1573 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1574 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1575 ."ON chart.account_code=acc.account_code
1576 WHERE acc.account_code IS NULL
1577 AND chart.account_type=type.id";
1579 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1580 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1581 WHERE chart.account_type=type.id";
1583 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1585 'format' => '_format_account',
1586 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1589 'order' => array('type.class_id','type.id','account_code'),
1590 'search_box' => $cells,
1591 'search_submit' => false,
1595 'select_submit'=> $submit_on_change,
1598 'show_inactive' => $all
1602 function _format_account($row)
1604 return $row[0] . " " . $row[1];
1607 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1608 $skip_bank_accounts=false, $cells=false, $all_option=false,
1609 $submit_on_change=false, $all=false)
1612 echo "<td>$label</td>\n";
1614 echo gl_all_accounts_list($name, $selected_id,
1615 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1619 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1620 $skip_bank_accounts=false, $cells=false, $all_option=false)
1622 echo "<tr><td class='label'>$label</td>";
1623 gl_all_accounts_list_cells(null, $name, $selected_id,
1624 $skip_bank_accounts, $cells, $all_option);
1628 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1631 $items['0'] = strlen($name_no) ? $name_no : _("No");
1632 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1634 return array_selector($name, $selected_id, $items,
1636 'select_submit'=> $submit_on_change,
1637 'async' => false ) ); // FIX?
1640 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1643 echo "<td>$label</td>\n";
1645 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1649 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1651 echo "<tr><td class='label'>$label</td>";
1652 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1656 //------------------------------------------------------------------------------------------------
1658 function languages_list($name, $selected_id=null, $all_option=false)
1660 global $installed_languages;
1664 $items[''] = $all_option;
1665 foreach ($installed_languages as $lang)
1666 $items[$lang['code']] = $lang['name'];
1667 return array_selector($name, $selected_id, $items);
1670 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1673 echo "<td>$label</td>\n";
1675 echo languages_list($name, $selected_id, $all_option);
1679 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1681 echo "<tr><td class='label'>$label</td>";
1682 languages_list_cells(null, $name, $selected_id, $all_option);
1686 //------------------------------------------------------------------------------------------------
1688 function bank_account_types_list($name, $selected_id=null)
1690 global $bank_account_types;
1692 return array_selector($name, $selected_id, $bank_account_types);
1695 function bank_account_types_list_cells($label, $name, $selected_id=null)
1698 echo "<td>$label</td>\n";
1700 echo bank_account_types_list($name, $selected_id);
1704 function bank_account_types_list_row($label, $name, $selected_id=null)
1706 echo "<tr><td class='label'>$label</td>";
1707 bank_account_types_list_cells(null, $name, $selected_id);
1711 //------------------------------------------------------------------------------------------------
1712 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1714 global $payment_person_types;
1717 foreach ($payment_person_types as $key=>$type)
1719 if ($key != PT_WORKORDER)
1720 $items[$key] = $type;
1722 return array_selector($name, $selected_id, $items,
1723 array( 'select_submit'=> $submit_on_change ) );
1726 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1729 echo "<td>$label</td>\n";
1731 echo payment_person_types_list($name, $selected_id, $related);
1735 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1737 echo "<tr><td class='label'>$label</td>";
1738 payment_person_types_list_cells(null, $name, $selected_id, $related);
1742 //------------------------------------------------------------------------------------------------
1744 function wo_types_list($name, $selected_id=null)
1746 global $wo_types_array;
1748 return array_selector($name, $selected_id, $wo_types_array,
1749 array( 'select_submit'=> true, 'async' => true ) );
1752 function wo_types_list_row($label, $name, $selected_id=null)
1754 echo "<tr><td class='label'>$label</td><td>\n";
1755 echo wo_types_list($name, $selected_id);
1756 echo "</td></tr>\n";
1759 //------------------------------------------------------------------------------------------------
1761 function dateformats_list_row($label, $name, $value=null)
1765 echo "<tr><td class='label'>$label</td>\n<td>";
1766 echo array_selector( $name, $value, $SysPrefs->dateformats );
1767 echo "</td></tr>\n";
1770 function dateseps_list_row($label, $name, $value=null)
1774 echo "<tr><td class='label'>$label</td>\n<td>";
1775 echo array_selector( $name, $value, $SysPrefs->dateseps );
1776 echo "</td></tr>\n";
1779 function thoseps_list_row($label, $name, $value=null)
1783 echo "<tr><td class='label'>$label</td>\n<td>";
1784 echo array_selector( $name, $value, $SysPrefs->thoseps );
1785 echo "</td></tr>\n";
1788 function decseps_list_row($label, $name, $value=null)
1792 echo "<tr><td class='label'>$label</td>\n<td>";
1793 echo array_selector( $name, $value, $SysPrefs->decseps );
1794 echo "</td></tr>\n";
1797 function themes_list_row($label, $name, $value=null)
1799 global $path_to_root;
1801 $path = $path_to_root.'/themes/';
1803 $themedir = opendir($path);
1804 while(false !== ($fname = readdir($themedir)))
1806 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1808 $themes[$fname] = $fname;
1813 echo "<tr><td class='label'>$label</td>\n<td>";
1814 echo array_selector( $name, $value, $themes );
1815 echo "</td></tr>\n";
1818 function pagesizes_list_row($label, $name, $value=null)
1823 foreach ($SysPrefs->pagesizes as $pz)
1826 echo "<tr><td class='label'>$label</td>\n<td>";
1827 echo array_selector( $name, $value, $items );
1828 echo "</td></tr>\n";
1831 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1833 global $systypes_array;
1835 // emove non-voidable transactions if needed
1836 $systypes = array_diff_key($systypes_array, array_flip($exclude));
1837 return array_selector($name, $value, $systypes,
1839 'spec_option'=> $spec_opt,
1840 'spec_id' => ALL_NUMERIC,
1841 'select_submit'=> $submit_on_change,
1847 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1850 echo "<td>$label</td>\n";
1852 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
1856 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1858 echo "<tr><td class='label'>$label</td>";
1859 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
1863 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1865 global $systypes_array;
1868 echo "<td>$label</td>\n";
1871 $items = $systypes_array;
1873 // exclude quotes, orders and dimensions
1874 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
1875 unset($items[$excl]);
1877 echo array_selector($name, $value, $items,
1879 'spec_option'=> _("All"),
1881 'select_submit'=> $submit_on_change,
1888 function cust_allocations_list_cells($label, $name, $selected=null)
1895 ALL_TEXT=>_("All Types"),
1896 '1'=> _("Sales Invoices"),
1897 '2'=> _("Overdue Invoices"),
1898 '3' => _("Payments"),
1899 '4' => _("Credit Notes"),
1900 '5' => _("Delivery Notes")
1902 echo array_selector($name, $selected, $allocs);
1906 function supp_allocations_list_cell($name, $selected=null)
1911 ALL_TEXT=>_("All Types"),
1912 '1'=> _("Invoices"),
1913 '2'=> _("Overdue Invoices"),
1914 '3' => _("Payments"),
1915 '4' => _("Credit Notes"),
1916 '5' => _("Overdue Credit Notes")
1918 echo array_selector($name, $selected, $allocs);
1922 function supp_transactions_list_cell($name, $selected=null)
1927 ALL_TEXT=>_("All Types"),
1929 '1'=> _("Invoices"),
1930 '2'=> _("Overdue Invoices"),
1931 '3' => _("Payments"),
1932 '4' => _("Credit Notes"),
1933 '5' => _("Overdue Credit Notes")
1936 echo array_selector($name, $selected, $allocs);
1940 function policy_list_cells($label, $name, $selected=null)
1945 echo array_selector($name, $selected,
1946 array( '' => _("Automatically put balance on back order"),
1947 'CAN' => _("Cancel any quantites not delivered")) );
1951 function policy_list_row($label, $name, $selected=null)
1953 echo "<tr><td class='label'>$label</td>";
1954 policy_list_cells(null, $name, $selected);
1958 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1963 echo array_selector($name, $selected,
1964 array( 'Return' => _("Items Returned to Inventory Location"),
1965 'WriteOff' => _("Items Written Off")),
1966 array( 'select_submit'=> $submit_on_change ) );
1970 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1972 echo "<tr><td class='label'>$label</td>";
1973 credit_type_list_cells(null, $name, $selected, $submit_on_change);
1977 function number_list($name, $selected, $from, $to, $no_option=false)
1980 for ($i = $from; $i <= $to; $i++)
1983 return array_selector($name, $selected, $items,
1984 array( 'spec_option' => $no_option,
1985 'spec_id' => ALL_NUMERIC) );
1988 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1993 echo number_list($name, $selected, $from, $to, $no_option);
1997 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1999 echo "<tr><td class='label'>$label</td>";
2000 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2004 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2005 $submit_on_change=true)
2007 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2008 ." GROUP BY profile";
2009 $result = db_query($sql, 'cannot get all profile names');
2010 $profiles = array();
2011 while($myrow=db_fetch($result)) {
2012 $profiles[$myrow['profile']] = $myrow['profile'];
2017 echo "<td class='label'>$label</td>\n";
2020 echo array_selector($name, $selected_id, $profiles,
2021 array( 'select_submit'=> $submit_on_change,
2022 'spec_option'=>$spec_opt,
2026 echo "</td></tr>\n";
2029 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2031 static $printers; // query only once for page display
2034 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2035 $result = db_query($sql, 'cannot get all printers');
2036 $printers = array();
2037 while($myrow=db_fetch($result)) {
2038 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2041 return array_selector($name, $selected_id, $printers,
2042 array( 'select_submit'=> $submit_on_change,
2043 'spec_option'=>$spec_opt,
2048 //------------------------------------------------------------------------------------------------
2050 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2053 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2055 $sql .= " WHERE type=$type";
2057 return combo_input($name, $selected_id, $sql, 'id', 'description',
2060 'order' => 'description',
2061 'select_submit'=> $submit_on_change,
2067 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2070 echo "<td>$label</td>\n";
2072 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2076 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2078 echo "<tr><td class='label'>$label</td>";
2079 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2084 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2086 global $quick_actions;
2088 echo "<tr><td class='label'>$label</td><td>";
2089 echo array_selector($name, $selected_id, $quick_actions,
2091 'select_submit'=> $submit_on_change
2093 echo "</td></tr>\n";
2096 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2098 global $quick_entry_types;
2100 echo "<tr><td class='label'>$label</td><td>";
2101 echo array_selector($name, $selected_id, $quick_entry_types,
2103 'select_submit'=> $submit_on_change
2105 echo "</td></tr>\n";
2108 function record_status_list_row($label, $name) {
2109 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2112 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2114 global $class_types;
2116 echo "<tr><td class='label'>$label</td><td>";
2117 echo array_selector($name, $selected_id, $class_types,
2119 'select_submit'=> $submit_on_change
2121 echo "</td></tr>\n";
2124 //------------------------------------------------------------------------------------------------
2126 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2127 $show_inactive = false)
2130 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2132 return combo_input($name, $selected_id, $sql, 'id', 'description',
2134 'spec_option'=>$new_item ? _("New role") : false,
2136 'select_submit'=> $submit_on_change,
2137 'show_inactive' => $show_inactive
2141 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2142 $show_inactive = false)
2145 echo "<td>$label</td>\n";
2147 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2151 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2152 $show_inactive = false)
2154 echo "<tr><td class='label'>$label</td>";
2155 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2159 function tab_list_row($label, $name, $selected_id=null)
2161 global $installed_extensions;
2164 foreach ($_SESSION['App']->applications as $app) {
2165 $tabs[$app->id] = access_string($app->name, true);
2168 echo "<td class='label'>$label</td><td>\n";
2169 echo array_selector($name, $selected_id, $tabs);
2170 echo "</td></tr>\n";
2173 //-----------------------------------------------------------------------------------------------
2175 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2178 global $path_to_root;
2179 include_once($path_to_root . "/admin/db/tags_db.inc");
2180 $results = get_tags($type, $all);
2182 while ($tag = db_fetch($results))
2183 $tags[$tag['id']] = $tag['name'];
2185 if (!isset($tags)) {
2186 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2189 return array_selector($name, null, $tags,
2192 'height' => $height,
2193 'spec_option'=> $spec_opt,
2198 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2201 echo "<td>$label</td>\n";
2203 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2208 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2210 echo "<tr><td class='label'>$label</td>";
2211 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2215 //---------------------------------------------------------------------------------------------
2216 // List of sets of active extensions
2218 function extset_list($name, $value=null, $submit_on_change=false)
2220 global $db_connections;
2223 foreach ($db_connections as $comp)
2224 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2225 return array_selector( $name, $value, $items,
2227 'spec_option'=> _("Available and/or installed"),
2229 'select_submit'=> $submit_on_change,
2234 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2237 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2242 if (@$filter['class']) {
2243 $where[] = 'type='.db_escape($filter['class']);
2246 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2247 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2248 if (@$filter['multi']) { // contact category selector for person
2252 return combo_input($name, $selected_id, $sql, 'id', 'name',
2255 'height' => $multi ? 5:1,
2256 'category' => $groups,
2257 'select_submit'=> $submit_on_change,
2263 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2265 echo "<tr><td class='label'>$label</td><td>";
2266 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2267 echo "</td></tr>\n";
2270 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2272 global $pterm_types;
2274 echo "<tr><td class='label'>$label</td><td>";
2275 echo array_selector($name, $selected_id, $pterm_types,
2277 'select_submit'=> $submit_on_change
2279 echo "</td></tr>\n";
2282 function coa_list_row($label, $name, $value=null)
2284 global $path_to_root, $installed_extensions;
2286 $path = $path_to_root.'/sql/';
2288 $sqldir = opendir($path);
2289 while (false !== ($fname = readdir($sqldir)))
2291 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2293 $ext = array_search_value($fname, $installed_extensions, 'sql');
2295 $descr = $ext['name'];
2296 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2297 $descr = _("Standard new company American COA (4 digit)");
2298 } elseif ($fname == 'en_US-demo.sql') {
2299 $descr = _("Standard American COA (4 digit) with demo data");
2303 $coas[$fname] = $descr;
2308 echo "<tr><td class='label'>$label</td>\n<td>";
2309 echo array_selector( $name, $value, $coas );
2310 echo "</td></tr>\n";
2313 function payment_services($name)
2315 global $payment_services;
2317 $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2319 return array_selector($name, null, $services, array(
2320 'spec_option'=> _("No payment Link"),
2325 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2327 global $tax_algorithms;
2329 return array_selector($name, $value, $tax_algorithms,
2331 'select_submit'=> $submit_on_change,
2337 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2340 echo "<td>$label</td>\n";
2342 echo tax_algorithm_list($name, $value, $submit_on_change);
2346 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2348 echo "<tr><td class='label'>$label</td>";
2349 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2353 function refline_list($name, $type, $value=null, $spec_option=false)
2355 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2360 $where = array('`trans_type`='.db_escape($type));
2362 return combo_input($name, $value, $sql, 'id', 'prefix',
2364 'order'=>array('prefix'),
2365 'spec_option' => $spec_option,
2369 'select_submit' => true,
2374 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2378 echo "<td class='label'>$label</td>\n";
2381 echo refline_list($name, $type, $selected_id, $spec_option);
2382 echo "</td></tr>\n";
2386 //----------------------------------------------------------------------------------------------
2388 function subledger_list($name, $account, $selected_id=null)
2391 $type = is_subledger_account($account);
2396 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2398 .TB_PREF."debtors_master d,"
2399 .TB_PREF."cust_branch c
2400 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2402 $sql = "SELECT supplier_id as id, supp_ref as name
2404 .TB_PREF."suppliers s
2405 WHERE s.payable_account=".db_escape($account);
2407 $mode = get_company_pref('no_customer_list');
2409 return combo_input($name, $selected_id, $sql, 'id', 'name',
2417 function subledger_list_cells($label, $name, $account, $selected_id=null)
2420 echo "<td>$label</td>\n";
2422 echo subledger_list($name, $account, $selected_id);
2426 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2427 $submit_on_change=false, $show_inactive=false, $editkey = false)
2429 echo "<tr><td class='label'>$label</td><td nowrap>";
2430 echo subledger_list($name, $account, $selected_id);
2431 echo "</td>\n</tr>\n";
2434 function accounts_type_list_row($label, $name, $selected_id=null)
2438 echo "<td class='label'>$label</td>\n";
2440 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2441 echo array_selector($name, $selected_id, $sel);
2442 echo "</td></tr>\n";
2445 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2448 $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2451 echo "<td>$label</td>\n";
2454 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2456 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2458 'order' => 'real_name',
2459 'select_submit'=> $submit_on_change,
2466 function collations_list_row($label, $name, $selected_id=null)
2468 global $supported_collations;
2472 echo "<td class='label'>$label</td>\n";
2475 echo array_selector($name, $selected_id, $supported_collations,
2476 array('select_submit'=> false) );
2477 echo "</td></tr>\n";