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 $_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 $_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 $all_items = ALL_TEXT;
24 //----------------------------------------------------------------------------
25 // Universal sql combo generator
26 // $sql must return selector values and selector texts in columns 0 & 1
27 // Options are merged with defaults.
29 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
34 $opts = array( // default options
35 'where'=> array(), // additional constraints
36 'order' => $namefield, // list sort order
37 // special option parameters
38 'spec_option'=>false, // option text or false
39 'spec_id' => 0, // option id
40 // submit on select parameters
41 'default' => '', // default value when $_POST is not set
42 'multi' => false, // multiple select
43 'select_submit' => false, //submit on select: true/false
44 'async' => true, // select update via ajax (true) vs _page_body reload
45 // search box parameters
47 'search_box' => false, // name or true/false
48 'type' => 0, // type of extended selector:
49 // 0 - with (optional) visible search box, search by id
50 // 1 - with hidden search box, search by option text
51 // 2 - TODO reverse: box with hidden selector available via enter; this
52 // would be convenient for optional ad hoc adding of new item
53 'search_submit' => true, //search submit button: true/false
54 'size' => 8, // size and max of box tag
56 'height' => false, // number of lines in select box
57 'cells' => false, // combo displayed as 2 <td></td> cells
58 'search' => array(), // sql field names to search
59 'format' => null, // format functions for regular options
61 'box_hint' => null, // box/selectors hints; null = std see below
62 'category' => false, // category column name or false
63 'show_inactive' => false, // show inactive records.
64 'editable' => false // false, or length of editable entry field
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 $by_id = ($opts['type'] == 0);
81 $class = $by_id ? 'combo':'combo2';
82 $disabled = $opts['disabled'] ? "disabled" : '';
83 $multi = $opts['multi'];
85 if(!count($opts['search'])) {
86 $opts['search'] = array($by_id ? $valfield : $namefield);
88 if ($opts['sel_hint'] === null)
89 $opts['sel_hint'] = $by_id || $search_box==false ?
90 '' : _('Press Space tab for search pattern entry');
92 if ($opts['box_hint'] === null)
93 $opts['box_hint'] = $search_box && $search_submit != false ?
94 ($by_id ? _('Enter code fragment to search or * for all')
95 : _('Enter description fragment to search or * for all')) :'';
97 if ($selected_id == null) {
98 $selected_id = get_post($name, $opts['default']);
100 if(!is_array($selected_id))
101 $selected_id = array($selected_id); // code is generalized for multiple selection support
103 $txt = get_post($search_box);
106 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
107 if ($by_id) $txt = $_POST[$name];
110 $Ajax->activate('_page_body');
112 $Ajax->activate($name);
114 if (isset($_POST[$search_button])) {
116 $Ajax->activate('_page_body');
118 $Ajax->activate($name);
121 // search related sql modifications
123 $rel = "rel='$search_box'"; // set relation to list
124 if ($opts['search_submit']) {
125 if (isset($_POST[$search_button])) {
126 $selected_id = array(); // ignore selected_id while search
128 $Ajax->activate('_page_body');
130 $Ajax->activate($name);
133 if ($spec_option === false && $selected_id == array())
136 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
141 foreach($opts['search'] as $i=> $s)
142 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
143 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
149 if (count($opts['where'])) {
150 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
151 $where .= '('. implode($opts['where'], ' AND ') . ')';
152 $group_pos = strpos($sql, 'GROUP BY');
154 $group = substr($sql, $group_pos);
155 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
160 if ($opts['order'] != false) {
161 if (!is_array($opts['order']))
162 $opts['order'] = array($opts['order']);
163 $sql .= ' ORDER BY '.implode(',',$opts['order']);
167 // ------ make selector ----------
168 $selector = $first_opt = '';
173 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
174 //if($name=='curr_default') display_notification($opts['search_submit']);
175 if($result = db_query($sql)) {
176 while ($contact_row = db_fetch($result)) {
177 $value = $contact_row[0];
178 $descr = $opts['format']==null ? $contact_row[1] :
179 call_user_func($opts['format'], $contact_row);
181 if (get_post($search_button) && ($txt == $value)) {
182 $selected_id[] = $value;
185 if (in_array((string)$value, $selected_id, true)) {
188 $edit = $opts['editable'] && $contact_row['editable']
189 && (@$_POST[$search_box] == $value)
190 ? $contact_row[1] : false; // get non-formatted description
192 break; // selected field is editable - abandon list construction
194 // show selected option even if inactive
195 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
198 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
200 if ($first_id === false) {
204 $cat = $contact_row[$opts['category']];
205 if ($opts['category'] !== false && $cat != $lastcat){
206 $selector .= "<optgroup label='".$cat."'>\n";
209 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
211 db_free_result($result);
214 // Prepend special option.
215 if ($spec_option !== false) { // if special option used - add it
216 $first_id = $spec_id;
217 $first_opt = $spec_option;
219 // if($first_id !== false) {
220 $sel = $found===false ? 'selected' : '';
221 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
222 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
226 if ($found===false) {
227 $selected_id = array($first_id);
230 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
232 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
233 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
234 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
235 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
237 if ($by_id && ($search_box != false || $opts['editable']) ) {
238 // on first display show selector list
239 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
240 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
241 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
242 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
243 set_focus($name.'_text'); // prevent lost focus
244 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
245 set_focus($name); // prevent lost focus
246 if (!$opts['editable'])
248 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
251 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
253 // span for select list/input field update
254 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
256 // if selectable or editable list is used - add select button
257 if ($select_submit != false || $search_button) {
258 global $_select_button;
259 // button class selects form reload/ajax selector update
260 $selector .= sprintf($_select_button, $disabled, user_theme(),
261 (fallback_mode() ? '' : 'display:none;'),
262 '_'.$name.'_update')."\n";
264 // ------ make combo ----------
266 if ($search_box != false) {
267 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
268 $opts['size']."' maxlength='".$opts['max'].
269 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
270 .$opts['box_hint']."'"
271 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
273 if ($search_submit != false || $opts['editable']) {
274 global $_search_button;
275 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
276 (fallback_mode() ? '' : 'display:none;'),
277 $search_submit ? $search_submit : "_{$name}_button")."\n";
280 default_focus(($search_box && $by_id) ? $search_box : $name);
282 if ($search_box && $opts['cells'])
283 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
285 $str = $edit_entry.$selector;
291 Returns true if selector $name is subject to update.
293 function list_updated($name)
295 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
297 //----------------------------------------------------------------------------------------------
298 // Universal array combo generator
299 // $items is array of options 'value' => 'description'
300 // Options is reduced set of combo_selector options and is merged with defaults.
302 function array_selector($name, $selected_id, $items, $options=null)
306 $opts = array( // default options
307 'spec_option'=>false, // option text or false
308 'spec_id' => 0, // option id
309 'select_submit' => false, //submit on select: true/false
310 'async' => true, // select update via ajax (true) vs _page_body reload
311 'default' => '', // default value when $_POST is not set
312 'multi'=>false, // multiple select
313 // search box parameters
314 'height' => false, // number of lines in select box
318 // ------ merge options with defaults ----------
320 $opts = array_merge($opts, $options);
321 $select_submit = $opts['select_submit'];
322 $spec_id = $opts['spec_id'];
323 $spec_option = $opts['spec_option'];
324 $disabled = $opts['disabled'] ? "disabled" : '';
325 $multi = $opts['multi'];
327 if ($selected_id == null) {
328 $selected_id = get_post($name, $opts['default']);
330 if(!is_array($selected_id))
331 $selected_id = array($selected_id); // code is generalized for multiple selection support
333 if (isset($_POST[ '_'.$name.'_update'])) {
335 $Ajax->activate('_page_body');
337 $Ajax->activate($name);
340 // ------ make selector ----------
341 $selector = $first_opt = '';
344 //if($name=='SelectStockFromList') display_error($sql);
345 foreach($items as $value=>$descr) {
347 if (in_array((string)$value, $selected_id, true)) {
351 if ($first_id === false) {
355 $selector .= "<option $sel value='$value'>$descr</option>\n";
358 if ($first_id!==false) {
359 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
360 $selector = sprintf($first_opt, $sel).$selector;
362 // Prepend special option.
363 if ($spec_option !== false) { // if special option used - add it
364 $first_id = $spec_id;
365 $first_opt = $spec_option;
366 $sel = $found===false ? 'selected' : '';
367 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
371 if ($found===false) {
372 $selected_id = array($first_id);
374 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
376 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
377 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
378 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
379 . $opts['sel_hint']."'>".$selector."</select>\n";
381 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
383 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
385 if ($select_submit != false) { // if submit on change is used - add select button
386 global $_select_button;
387 $selector .= sprintf($_select_button, $disabled, user_theme(),
388 (fallback_mode() ? '' : 'display:none;'),
389 '_'.$name.'_update')."\n";
391 default_focus($name);
395 //----------------------------------------------------------------------------------------------
397 function _format_add_curr($row)
399 static $company_currency;
401 if ($company_currency == null)
403 $company_currency = get_company_currency();
405 return $row[1] . ($row[2] == $company_currency ?
406 '' : (" - " . $row[2]));
409 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
410 $all=false, $editkey = false)
414 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
416 $mode = get_company_pref('no_supplier_list');
419 set_editor('supplier', $name, $editkey);
421 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
423 'format' => '_format_add_curr',
424 'order' => array('supp_ref'),
425 'search_box' => $mode!=0,
427 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
428 'spec_id' => $all_items,
429 'select_submit'=> $submit_on_change,
431 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
432 _('Select supplier'),
433 'show_inactive'=>$all
437 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
438 $submit_on_change=false, $all=false, $editkey = false)
441 echo "<td>$label</td><td>\n";
442 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
447 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
448 $submit_on_change=false, $all=false, $editkey = false)
450 echo "<tr><td class='label'>$label</td><td>";
451 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
455 //----------------------------------------------------------------------------------------------
457 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
458 $show_inactive=false, $editkey = false)
462 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
464 $mode = get_company_pref('no_customer_list');
467 set_editor('customer', $name, $editkey);
469 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
471 'format' => '_format_add_curr',
472 'order' => array('debtor_ref'),
473 'search_box' => $mode!=0,
476 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
477 'spec_id' => $all_items,
478 'select_submit'=> $submit_on_change,
480 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
481 _('Select customer'),
482 'show_inactive' => $show_inactive
486 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
487 $submit_on_change=false, $show_inactive=false, $editkey = false)
490 echo "<td>$label</td>\n";
492 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
493 $show_inactive, $editkey);
497 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
498 $submit_on_change=false, $show_inactive=false, $editkey = false)
500 echo "<tr><td class='label'>$label</td><td nowrap>";
501 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
502 $show_inactive, $editkey);
503 echo "</td>\n</tr>\n";
506 //------------------------------------------------------------------------------------------------
508 function customer_branches_list($customer_id, $name, $selected_id=null,
509 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
513 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
514 WHERE debtor_no='" . $customer_id . "' ";
517 set_editor('branch', $name, $editkey);
519 $where = $enabled ? array("disable_trans = 0") : array();
520 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
523 'order' => array('branch_ref'),
524 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
525 'spec_id' => $all_items,
526 'select_submit'=> $submit_on_change,
527 'sel_hint' => _('Select customer branch')
530 //------------------------------------------------------------------------------------------------
532 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
533 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
536 echo "<td>$label</td>\n";
538 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
539 $submit_on_change, $editkey);
543 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
544 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
546 echo "<tr><td class='label'>$label</td>";
547 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
548 $all_option, $enabled, $submit_on_change, $editkey);
552 //------------------------------------------------------------------------------------------------
554 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
558 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
560 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
562 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
563 'spec_id' => $all_items,
564 'select_submit'=> $submit_on_change
568 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
571 echo "<td>$label</td>\n";
573 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
577 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
579 echo "<tr><td class='label'>$label</td>";
580 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
584 //-----------------------------------------------------------------------------------------------
586 function currencies_list($name, $selected_id=null, $submit_on_change=false)
588 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
590 // default to the company currency
591 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
593 'select_submit'=> $submit_on_change,
594 'default' => get_company_currency(),
599 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
602 echo "<td>$label</td>\n";
604 echo currencies_list($name, $selected_id, $submit_on_change);
608 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
610 echo "<tr><td class='label'>$label</td>";
611 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
615 //---------------------------------------------------------------------------------------------------
617 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
620 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
622 // default to the company current fiscal year
624 return combo_input($name, $selected_id, $sql, 'id', '',
627 'default' => get_company_pref('f_year'),
628 'format' => '_format_fiscalyears',
629 'select_submit'=> $submit_on_change,
634 function _format_fiscalyears($row)
636 return sql2date($row[1]) . " - " . sql2date($row[2])
637 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
640 function fiscalyears_list_cells($label, $name, $selected_id=null)
643 echo "<td>$label</td>\n";
645 echo fiscalyears_list($name, $selected_id);
649 function fiscalyears_list_row($label, $name, $selected_id=null)
651 echo "<tr><td class='label'>$label</td>";
652 fiscalyears_list_cells(null, $name, $selected_id);
655 //------------------------------------------------------------------------------------
657 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
658 $submit_on_change=false, $showclosed=false, $showtype=1)
660 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
663 'order' => 'reference',
664 'spec_option'=>$no_option ? $showname : false,
666 'select_submit'=> $submit_on_change,
671 $options['where'][] = "closed=0";
673 $options['where'][] = "type_=$showtype";
675 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
678 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
679 $showclosed=false, $showtype=0, $submit_on_change=false)
682 echo "<td>$label</td>\n";
684 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
688 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
689 $showclosed=false, $showtype=0, $submit_on_change=false)
691 echo "<tr><td class='label'>$label</td>";
692 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
693 $showclosed, $showtype, $submit_on_change);
697 //---------------------------------------------------------------------------------------------------
699 function stock_items_list($name, $selected_id=null, $all_option=false,
700 $submit_on_change=false, $opts=array(), $editkey = false)
704 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
705 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
708 set_editor('item', $name, $editkey);
710 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
713 'format' => '_format_stock_items',
714 'spec_option' => $all_option===true ? _("All Items") : $all_option,
715 'spec_id' => $all_items,
716 'search_box' => true,
717 'search' => array("stock_id", "c.description","s.description"),
718 'search_submit' => get_company_pref('no_item_list')!=0,
720 'select_submit'=> $submit_on_change,
722 'order' => array('c.description','stock_id')
726 function _format_stock_items($row)
728 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
731 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
732 $submit_on_change=false, $all=false, $editkey = false)
735 echo "<td>$label</td>\n";
736 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
737 array('cells'=>true, 'show_inactive'=>$all), $editkey);
740 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
743 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
747 //---------------------------------------------------------------------------------------------------
749 // Select item via foreign code.
751 function sales_items_list($name, $selected_id=null, $all_option=false,
752 $submit_on_change=false, $type='', $opts=array())
756 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
757 i.inactive, if(count(*)>1, '0', s.editable) as editable
759 ".TB_PREF."stock_master s,
760 ".TB_PREF."item_codes i
762 ".TB_PREF."stock_category c
763 ON i.category_id=c.category_id
764 WHERE i.stock_id=s.stock_id";
767 if ($type == 'local') { // exclude foreign codes
768 $sql .= " AND !i.is_foreign";
769 } elseif ($type == 'kits') { // sales kits
770 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
772 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
773 $sql .= " GROUP BY i.item_code";
775 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
778 'format' => '_format_stock_items',
779 'spec_option' => $all_option===true ? _("All Items") : $all_option,
780 'spec_id' => $all_items,
781 'search_box' => true,
782 'search' => array("i.item_code", "c.description", "i.description"),
783 'search_submit' => get_company_pref('no_item_list')!=0,
785 'select_submit'=> $submit_on_change,
787 'order' => array('c.description','i.item_code'),
793 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
796 echo "<td>$label</td>\n";
797 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
798 '', array('cells'=>true));
801 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
803 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
804 'kits', array('cells'=>false, 'editable' => false));
807 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
811 echo "<td class='label'>$label</td>\n";
813 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
814 'local', array('cells'=>false, 'editable' => false));
817 //------------------------------------------------------------------------------------
819 function stock_manufactured_items_list($name, $selected_id=null,
820 $all_option=false, $submit_on_change=false)
822 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
823 array('where'=>array("mb_flag= 'M'")));
826 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
827 $all_option=false, $submit_on_change=false)
830 echo "<td>$label</td>\n";
832 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
836 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
837 $all_option=false, $submit_on_change=false)
839 echo "<tr><td class='label'>$label</td>";
840 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
843 //------------------------------------------------------------------------------------
845 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
846 $all_option=false, $submit_on_change=false, $editkey = false)
848 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
849 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
852 function stock_component_items_list_cells($label, $name, $parent_stock_id,
853 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
856 echo "<td>$label</td>\n";
857 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
858 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
861 //------------------------------------------------------------------------------------
863 function stock_costable_items_list($name, $selected_id=null,
864 $all_option=false, $submit_on_change=false)
866 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
867 array('where'=>array("mb_flag!='D'")));
870 function stock_costable_items_list_cells($label, $name, $selected_id=null,
871 $all_option=false, $submit_on_change=false)
874 echo "<td>$label</td>\n";
875 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
876 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
879 //------------------------------------------------------------------------------------
880 function stock_purchasable_items_list($name, $selected_id=null,
881 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
883 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
884 array('where'=>array("mb_flag!= 'M'"),
885 'show_inactive'=>$all), $editkey);
888 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
890 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
891 $all_option=false, $submit_on_change=false, $editkey=false)
894 echo "<td>$label</td>\n";
895 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
896 array('where'=>array("mb_flag!= 'M'"),
898 'cells'=>true), $editkey);
901 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
902 $all_option=false, $submit_on_change=false, $editkey=false)
904 echo "<tr><td class='label'>$label</td>";
905 stock_purchasable_items_list_cells(null, $name, $selected_id=null,
906 $all_option, $submit_on_change, $editkey);
910 //------------------------------------------------------------------------------------
912 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
918 echo "<td class='label'>$label</td>\n";
921 echo array_selector($name, $selected_id, $stock_types,
923 'select_submit'=> true,
924 'disabled' => !$enabled) );
928 function stock_units_list_row($label, $name, $value=null, $enabled=true)
930 $result = get_all_item_units();
933 echo "<td class='label'>$label</td>\n";
936 while($unit = db_fetch($result))
937 $units[$unit['abbr']] = $unit['name'];
939 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
944 //------------------------------------------------------------------------------------
946 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
948 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
950 return combo_input($name, $selected_id, $sql, 'id', 'name',
952 'spec_option' => $none_option,
953 'spec_id' => ALL_NUMERIC,
954 'select_submit'=> $submit_on_change,
959 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
960 $submit_on_change=false)
963 echo "<td>$label</td>\n";
965 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
969 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
970 $submit_on_change=false)
972 echo "<tr><td class='label'>$label</td>";
973 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
977 //------------------------------------------------------------------------------------
979 function tax_groups_list($name, $selected_id=null,
980 $none_option=false, $submit_on_change=false)
982 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
984 return combo_input($name, $selected_id, $sql, 'id', 'name',
987 'spec_option' => $none_option,
988 'spec_id' => ALL_NUMERIC,
989 'select_submit'=> $submit_on_change,
994 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
997 echo "<td>$label</td>\n";
999 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1003 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1005 echo "<tr><td class='label'>$label</td>";
1006 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1010 //------------------------------------------------------------------------------------
1012 function item_tax_types_list($name, $selected_id=null)
1014 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1015 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1018 function item_tax_types_list_cells($label, $name, $selected_id=null)
1021 echo "<td>$label</td>\n";
1023 echo item_tax_types_list($name, $selected_id);
1027 function item_tax_types_list_row($label, $name, $selected_id=null)
1029 echo "<tr><td class='label'>$label</td>";
1030 item_tax_types_list_cells(null, $name, $selected_id);
1034 //------------------------------------------------------------------------------------
1036 function shippers_list($name, $selected_id=null)
1038 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1039 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1040 array('order'=>array('shipper_name')));
1043 function shippers_list_cells($label, $name, $selected_id=null)
1046 echo "<td>$label</td>\n";
1048 echo shippers_list($name, $selected_id);
1052 function shippers_list_row($label, $name, $selected_id=null)
1054 echo "<tr><td class='label'>$label</td>";
1055 shippers_list_cells(null, $name, $selected_id);
1059 //-------------------------------------------------------------------------------------
1061 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1063 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1064 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1065 array('order'=>array('salesman_name'),
1066 'spec_option' => $spec_opt,
1067 'spec_id' => ALL_NUMERIC));
1070 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1073 echo "<td>$label</td>\n";
1075 echo sales_persons_list($name, $selected_id, $spec_opt);
1079 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1081 echo "<tr><td class='label'>$label</td>";
1082 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1086 //------------------------------------------------------------------------------------
1088 function sales_areas_list($name, $selected_id=null)
1090 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1091 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1094 function sales_areas_list_cells($label, $name, $selected_id=null)
1097 echo "<td>$label</td>\n";
1099 echo sales_areas_list($name, $selected_id);
1103 function sales_areas_list_row($label, $name, $selected_id=null)
1105 echo "<tr><td class='label'>$label</td>";
1106 sales_areas_list_cells(null, $name, $selected_id);
1110 //------------------------------------------------------------------------------------
1112 function sales_groups_list($name, $selected_id=null, $special_option=false)
1114 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1115 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1116 'spec_option' => $special_option===true ? ' ' : $special_option,
1117 'order' => 'description', 'spec_id' => 0,
1121 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1124 echo "<td>$label</td>\n";
1126 echo sales_groups_list($name, $selected_id, $special_option);
1130 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1132 echo "<tr><td class='label'>$label</td>";
1133 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1137 //------------------------------------------------------------------------------------
1139 function _format_template_items($row)
1141 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1144 function templates_list($name, $selected_id=null, $special_option=false)
1146 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1147 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1148 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1149 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1150 'format' => '_format_template_items',
1151 'spec_option' => $special_option===true ? ' ' : $special_option,
1152 'order' => 'order_no', 'spec_id' => 0,
1156 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1159 echo "<td>$label</td>\n";
1161 echo templates_list($name, $selected_id, $special_option);
1165 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1167 echo "<tr><td class='label'>$label</td>";
1168 templates_list_cells(null, $name, $selected_id, $special_option);
1172 //------------------------------------------------------------------------------------
1174 function workorders_list($name, $selected_id=null)
1176 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1177 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1180 function workorders_list_cells($label, $name, $selected_id=null)
1183 echo "<td>$label</td>\n";
1185 echo workorders_list($name, $selected_id);
1189 function workorders_list_row($label, $name, $selected_id=null)
1191 echo "<tr><td class='label'>$label</td>";
1192 workorders_list_cells(null, $name, $selected_id);
1196 //------------------------------------------------------------------------------------
1198 function payment_terms_list($name, $selected_id=null)
1200 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1201 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1204 function payment_terms_list_cells($label, $name, $selected_id=null)
1207 echo "<td>$label</td>\n";
1209 echo payment_terms_list($name, $selected_id);
1213 function payment_terms_list_row($label, $name, $selected_id=null)
1215 echo "<tr><td class='label'>$label</td>";
1216 payment_terms_list_cells(null, $name, $selected_id);
1220 //------------------------------------------------------------------------------------
1222 function credit_status_list($name, $selected_id=null)
1224 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1225 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1228 function credit_status_list_cells($label, $name, $selected_id=null)
1231 echo "<td>$label</td>\n";
1233 echo credit_status_list($name, $selected_id);
1237 function credit_status_list_row($label, $name, $selected_id=null)
1239 echo "<tr><td class='label'>$label</td>";
1240 credit_status_list_cells(null, $name, $selected_id);
1244 //-----------------------------------------------------------------------------------------------
1246 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1248 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1250 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1252 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1254 'select_submit'=> $submit_on_change,
1255 // 'async' => false,
1259 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1262 echo "<td>$label</td>\n";
1264 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1268 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1270 echo "<tr><td class='label'>$label</td>";
1271 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1275 //-----------------------------------------------------------------------------------------------
1277 function movement_types_list($name, $selected_id=null)
1279 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1280 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1283 function movement_types_list_cells($label, $name, $selected_id=null)
1286 echo "<td>$label</td>\n";
1288 echo movement_types_list($name, $selected_id);
1292 function movement_types_list_row($label, $name, $selected_id=null)
1294 echo "<tr><td class='label'>$label</td>";
1295 movement_types_list_cells(null, $name, $selected_id);
1299 //-----------------------------------------------------------------------------------------------
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)
1341 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1343 return combo_input($name, $selected_id, $sql, 'id', 'name',
1345 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1346 'spec_id' => $all_items,
1350 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1352 default_focus($name);
1354 echo "<td>$label</td>\n";
1356 echo workcenter_list($name, $selected_id, $all_option);
1360 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1362 echo "<tr><td class='label'>$label</td>";
1363 workcenter_list_cells(null, $name, $selected_id, $all_option);
1367 //-----------------------------------------------------------------------------------------------
1369 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1371 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1372 FROM ".TB_PREF."bank_accounts";
1374 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1376 'format' => '_format_add_curr',
1377 'select_submit'=> $submit_on_change,
1382 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1385 echo "<td>$label</td>\n";
1387 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1391 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1393 echo "<tr><td class='label'>$label</td>";
1394 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1397 //-----------------------------------------------------------------------------------------------
1399 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1401 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1402 FROM ".TB_PREF."bank_accounts
1403 WHERE ".TB_PREF."bank_accounts.account_type=3";
1406 echo "<tr><td class='label'>$label</td>\n";
1408 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1410 'format' => '_format_add_curr',
1411 'select_submit'=> $submit_on_change,
1414 echo "</td></tr>\n";
1416 //-----------------------------------------------------------------------------------------------
1418 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1420 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1422 default_focus($name);
1425 echo "<td class='label'>$label</td>\n";
1428 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1430 'select_submit'=> $submit_on_change,
1432 'spec_option' =>$spec_option,
1434 'order'=> array('pos_name')
1436 echo "</td></tr>\n";
1439 //-----------------------------------------------------------------------------------------------
1440 // Payment type selector for current user.
1442 function sale_payment_list($name, $selected_id=null, $submit_on_change=true)
1444 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1445 $paym = get_sales_point(user_pos());
1447 if (!$paym['cash_sale'] || !$paym['credit_sale']) {
1448 if ($paym['cash_sale']) // only cash
1449 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1451 $sql .= " WHERE days_before_due!=0 OR day_in_following_month!=0";
1454 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1456 'select_submit'=> $submit_on_change,
1462 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=true)
1465 echo "<td class='label'>$label</td>\n";
1468 echo sale_payment_list($name, $selected_id, $submit_on_change);
1472 //-----------------------------------------------------------------------------------------------
1474 function class_list($name, $selected_id=null, $submit_on_change=false)
1476 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1478 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1480 'select_submit'=> $submit_on_change,
1486 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1489 echo "<td>$label</td>\n";
1491 echo class_list($name, $selected_id, $submit_on_change);
1495 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1497 echo "<tr><td class='label'>$label</td>";
1498 class_list_cells(null, $name, $selected_id, $submit_on_change);
1502 //-----------------------------------------------------------------------------------------------
1503 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1505 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1506 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1507 array('order'=>'category_id',
1508 'spec_option' => $spec_opt,
1510 'select_submit'=> $submit_on_change,
1515 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1518 echo "<td>$label</td>\n";
1520 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1524 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1526 echo "<tr><td class='label'>$label</td>";
1527 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1531 //-----------------------------------------------------------------------------------------------
1533 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1537 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1539 return combo_input($name, $selected_id, $sql, 'id', 'name',
1541 'order' => array('class_id', 'id', 'parent'),
1542 'spec_option' =>$all_option,
1543 'spec_id' => $all_items
1547 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1550 echo "<td>$label</td>\n";
1552 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1556 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1558 echo "<tr><td class='label'>$label</td>";
1559 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1564 //-----------------------------------------------------------------------------------------------
1565 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1566 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1568 if ($skip_bank_accounts)
1569 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1570 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1571 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1572 ."ON chart.account_code=acc.account_code
1573 WHERE acc.account_code IS NULL
1574 AND chart.account_type=type.id";
1576 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1577 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1578 WHERE chart.account_type=type.id";
1580 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1582 'format' => '_format_account',
1583 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1585 'order' => array('type.class_id','type.id','account_code'),
1586 'search_box' => $cells,
1587 'search_submit' => false,
1591 'select_submit'=> $submit_on_change,
1594 'show_inactive' => $all
1599 function _format_account($row)
1601 return $row[0] . " " . $row[1];
1604 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1605 $skip_bank_accounts=false, $cells=false, $all_option=false,
1606 $submit_on_change=false, $all=false)
1609 echo "<td>$label</td>\n";
1611 echo gl_all_accounts_list($name, $selected_id,
1612 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1616 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1617 $skip_bank_accounts=false, $cells=false, $all_option=false)
1619 echo "<tr><td class='label'>$label</td>";
1620 gl_all_accounts_list_cells(null, $name, $selected_id,
1621 $skip_bank_accounts, $cells, $all_option);
1625 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1628 $items['0'] = strlen($name_no) ? $name_no : _("No");
1629 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1631 return array_selector($name, $selected_id, $items,
1633 'select_submit'=> $submit_on_change,
1634 'async' => false ) ); // FIX?
1637 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1640 echo "<td>$label</td>\n";
1642 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1646 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1648 echo "<tr><td class='label'>$label</td>";
1649 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1653 //------------------------------------------------------------------------------------------------
1655 function languages_list($name, $selected_id=null, $all_option=false)
1657 global $installed_languages;
1661 $items[''] = $all_option;
1662 foreach ($installed_languages as $lang)
1663 $items[$lang['code']] = $lang['name'];
1664 return array_selector($name, $selected_id, $items);
1667 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1670 echo "<td>$label</td>\n";
1672 echo languages_list($name, $selected_id, $all_option);
1676 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1678 echo "<tr><td class='label'>$label</td>";
1679 languages_list_cells(null, $name, $selected_id, $all_option);
1683 //------------------------------------------------------------------------------------------------
1685 function bank_account_types_list($name, $selected_id=null)
1687 global $bank_account_types;
1689 return array_selector($name, $selected_id, $bank_account_types);
1692 function bank_account_types_list_cells($label, $name, $selected_id=null)
1695 echo "<td>$label</td>\n";
1697 echo bank_account_types_list($name, $selected_id);
1701 function bank_account_types_list_row($label, $name, $selected_id=null)
1703 echo "<tr><td class='label'>$label</td>";
1704 bank_account_types_list_cells(null, $name, $selected_id);
1708 //------------------------------------------------------------------------------------------------
1709 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1711 global $payment_person_types;
1714 foreach ($payment_person_types as $key=>$type)
1716 if ($key != PT_WORKORDER)
1717 $items[$key] = $type;
1719 return array_selector($name, $selected_id, $items,
1720 array( 'select_submit'=> $submit_on_change ) );
1723 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1726 echo "<td>$label</td>\n";
1728 echo payment_person_types_list($name, $selected_id, $related);
1732 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1734 echo "<tr><td class='label'>$label</td>";
1735 payment_person_types_list_cells(null, $name, $selected_id, $related);
1739 //------------------------------------------------------------------------------------------------
1741 function wo_types_list($name, $selected_id=null)
1743 global $wo_types_array;
1745 return array_selector($name, $selected_id, $wo_types_array,
1746 array( 'select_submit'=> true, 'async' => true ) );
1749 function wo_types_list_row($label, $name, $selected_id=null)
1751 echo "<tr><td class='label'>$label</td><td>\n";
1752 echo wo_types_list($name, $selected_id);
1753 echo "</td></tr>\n";
1756 //------------------------------------------------------------------------------------------------
1758 function dateformats_list_row($label, $name, $value=null)
1760 global $dateformats;
1762 echo "<tr><td class='label'>$label</td>\n<td>";
1763 echo array_selector( $name, $value, $dateformats );
1764 echo "</td></tr>\n";
1767 function dateseps_list_row($label, $name, $value=null)
1771 echo "<tr><td class='label'>$label</td>\n<td>";
1772 echo array_selector( $name, $value, $dateseps );
1773 echo "</td></tr>\n";
1776 function thoseps_list_row($label, $name, $value=null)
1780 echo "<tr><td class='label'>$label</td>\n<td>";
1781 echo array_selector( $name, $value, $thoseps );
1782 echo "</td></tr>\n";
1785 function decseps_list_row($label, $name, $value=null)
1789 echo "<tr><td class='label'>$label</td>\n<td>";
1790 echo array_selector( $name, $value, $decseps );
1791 echo "</td></tr>\n";
1794 function themes_list_row($label, $name, $value=null)
1796 global $path_to_root;
1798 $path = $path_to_root.'/themes/';
1800 $themedir = opendir($path);
1801 while(false !== ($fname = readdir($themedir)))
1803 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1805 $themes[$fname] = $fname;
1810 echo "<tr><td class='label'>$label</td>\n<td>";
1811 echo array_selector( $name, $value, $themes );
1812 echo "</td></tr>\n";
1815 function pagesizes_list_row($label, $name, $value=null)
1820 foreach ($pagesizes as $pz)
1823 echo "<tr><td class='label'>$label</td>\n<td>";
1824 echo array_selector( $name, $value, $items );
1825 echo "</td></tr>\n";
1828 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false)
1830 global $systypes_array;
1832 return array_selector($name, $value, $systypes_array,
1834 'spec_option'=> $spec_opt,
1835 'spec_id' => ALL_NUMERIC,
1836 'select_submit'=> $submit_on_change,
1842 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1845 echo "<td>$label</td>\n";
1847 echo systypes_list($name, $value, false, $submit_on_change);
1851 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1853 echo "<tr><td class='label'>$label</td>";
1854 systypes_list_cells(null, $name, $value, false, $submit_on_change);
1858 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1860 global $systypes_array;
1863 echo "<td>$label</td>\n";
1866 $items = $systypes_array;
1868 // exclude quotes, orders and dimensions
1869 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1870 ST_SALESQUOTE) as $excl)
1871 unset($items[$excl]);
1873 echo array_selector($name, $value, $items,
1875 'spec_option'=> _("All"),
1877 'select_submit'=> $submit_on_change,
1884 function cust_allocations_list_cells($label, $name, $selected=null)
1892 $all_items=>_("All Types"),
1893 '1'=> _("Sales Invoices"),
1894 '2'=> _("Overdue Invoices"),
1895 '3' => _("Payments"),
1896 '4' => _("Credit Notes"),
1897 '5' => _("Delivery Notes")
1899 echo array_selector($name, $selected, $allocs);
1903 function supp_allocations_list_cell($name, $selected=null)
1909 $all_items=>_("All Types"),
1910 '1'=> _("Invoices"),
1911 '2'=> _("Overdue Invoices"),
1912 '3' => _("Payments"),
1913 '4' => _("Credit Notes"),
1914 '5' => _("Overdue Credit Notes")
1916 echo array_selector($name, $selected, $allocs);
1920 function policy_list_cells($label, $name, $selected=null)
1925 echo array_selector($name, $selected,
1926 array( '' => _("Automatically put balance on back order"),
1927 'CAN' => _("Cancel any quantites not delivered")) );
1931 function policy_list_row($label, $name, $selected=null)
1933 echo "<tr><td class='label'>$label</td>";
1934 policy_list_cells(null, $name, $selected);
1938 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1943 echo array_selector($name, $selected,
1944 array( 'Return' => _("Items Returned to Inventory Location"),
1945 'WriteOff' => _("Items Written Off")),
1946 array( 'select_submit'=> $submit_on_change ) );
1950 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1952 echo "<tr><td class='label'>$label</td>";
1953 credit_type_list_cells(null, $name, $selected, $submit_on_change);
1957 function number_list($name, $selected, $from, $to, $no_option=false)
1960 for ($i = $from; $i <= $to; $i++)
1963 return array_selector($name, $selected, $items,
1964 array( 'spec_option' => $no_option,
1965 'spec_id' => ALL_NUMERIC) );
1968 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1973 echo number_list($name, $selected, $from, $to, $no_option);
1977 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1979 echo "<tr><td class='label'>$label</td>";
1980 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
1984 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1985 $submit_on_change=true)
1987 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1988 ." GROUP BY profile";
1989 $result = db_query($sql, 'cannot get all profile names');
1990 $profiles = array();
1991 while($myrow=db_fetch($result)) {
1992 $profiles[$myrow['profile']] = $myrow['profile'];
1997 echo "<td class='label'>$label</td>\n";
2000 echo array_selector($name, $selected_id, $profiles,
2001 array( 'select_submit'=> $submit_on_change,
2002 'spec_option'=>$spec_opt,
2006 echo "</td></tr>\n";
2009 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2011 static $printers; // query only once for page display
2014 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2015 $result = db_query($sql, 'cannot get all printers');
2016 $printers = array();
2017 while($myrow=db_fetch($result)) {
2018 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2021 return array_selector($name, $selected_id, $printers,
2022 array( 'select_submit'=> $submit_on_change,
2023 'spec_option'=>$spec_opt,
2028 //------------------------------------------------------------------------------------------------
2030 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2033 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2035 $sql .= " WHERE type=$type";
2037 return combo_input($name, $selected_id, $sql, 'id', 'description',
2040 'order' => 'description',
2041 'select_submit'=> $submit_on_change,
2047 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2050 echo "<td>$label</td>\n";
2052 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2056 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2058 echo "<tr><td class='label'>$label</td>";
2059 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2064 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2066 global $quick_actions;
2068 echo "<tr><td class='label'>$label</td><td>";
2069 echo array_selector($name, $selected_id, $quick_actions,
2071 'select_submit'=> $submit_on_change
2073 echo "</td></tr>\n";
2076 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2078 global $quick_entry_types;
2080 echo "<tr><td class='label'>$label</td><td>";
2081 echo array_selector($name, $selected_id, $quick_entry_types,
2083 'select_submit'=> $submit_on_change
2085 echo "</td></tr>\n";
2088 function record_status_list_row($label, $name) {
2089 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2092 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2094 global $class_types;
2096 echo "<tr><td class='label'>$label</td><td>";
2097 echo array_selector($name, $selected_id, $class_types,
2099 'select_submit'=> $submit_on_change
2101 echo "</td></tr>\n";
2104 //------------------------------------------------------------------------------------------------
2106 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2107 $show_inactive = false)
2111 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2113 return combo_input($name, $selected_id, $sql, 'id', 'description',
2115 'spec_option'=>$new_item ? _("New role") : false,
2117 'select_submit'=> $submit_on_change,
2118 'show_inactive' => $show_inactive
2122 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2123 $show_inactive = false)
2126 echo "<td>$label</td>\n";
2128 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2132 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2133 $show_inactive = false)
2135 echo "<tr><td class='label'>$label</td>";
2136 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2140 function tab_list_row($label, $name, $selected_id=null, $all = false)
2142 global $installed_extensions;
2145 foreach ($_SESSION['App']->applications as $app) {
2146 $tabs[$app->id] = access_string($app->name, true);
2148 if ($all) { // add also not active ext. modules
2149 foreach ($installed_extensions as $ext) {
2150 if ($ext['type'] == 'module' && !$ext['active'])
2151 $tabs[$ext['tab']] = access_string($ext['title'], true);
2155 echo "<td class='label'>$label</td><td>\n";
2156 echo array_selector($name, $selected_id, $tabs);
2157 echo "</td></tr>\n";
2160 //-----------------------------------------------------------------------------------------------
2162 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2165 global $path_to_root;
2166 include_once($path_to_root . "/admin/db/tags_db.inc");
2167 $results = get_tags($type, $all);
2169 while ($tag = db_fetch($results))
2170 $tags[$tag['id']] = $tag['name'];
2172 if (!isset($tags)) {
2173 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2176 return array_selector($name, null, $tags,
2179 'height' => $height,
2180 'spec_option'=> $spec_opt,
2185 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2188 echo "<td>$label</td>\n";
2190 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2195 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2197 echo "<tr><td class='label'>$label</td>";
2198 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2202 //---------------------------------------------------------------------------------------------
2203 // List of sets of active extensions
2205 function extset_list($name, $value=null, $submit_on_change=false)
2207 global $db_connections;
2210 foreach ($db_connections as $comp)
2211 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2212 return array_selector( $name, $value, $items,
2214 'spec_option'=> _("Available and/or installed"),
2216 'select_submit'=> $submit_on_change,