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) // dodaƦ hint dla pustego ****
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);
107 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
108 if ($by_id) $txt = $_POST[$name];
111 $Ajax->activate('_page_body');
113 $Ajax->activate($name);
115 if (isset($_POST[$search_button])) {
117 $Ajax->activate('_page_body');
119 $Ajax->activate($name);
122 // search related sql modifications
124 $rel = "rel='$search_box'"; // set relation to list
125 if ($opts['search_submit']) {
126 if (isset($_POST[$search_button])) {
127 $selected_id = array(); // ignore selected_id while search
129 $Ajax->activate('_page_body');
131 $Ajax->activate($name);
134 if ($spec_option === false && $selected_id == array())
137 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
142 foreach($opts['search'] as $i=> $s)
143 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
144 $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;
184 if (in_array($value, $selected_id)) {
187 $edit = $opts['editable'] && $contact_row['editable']
188 && (@$_POST[$search_box] == $value)
191 break; // selected field is editable - abandon list construction
193 // show selected option even if inactive
194 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
197 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
199 if ($first_id === false) {
203 $cat = $contact_row[$opts['category']];
204 if ($opts['category'] !== false && $cat != $lastcat){
205 $selector .= "<optgroup label='".$cat."'>\n";
208 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
210 db_free_result($result);
213 // Prepend special option.
214 if ($spec_option !== false) { // if special option used - add it
215 $first_id = $spec_id;
216 $first_opt = $spec_option;
218 // if($first_id !== false) {
219 $sel = $found===false ? 'selected' : '';
220 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
221 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
225 if ($found===false) {
226 $selected_id = array($first_id);
229 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
231 $selector = "<select ".($multi ? "multiple" : '')
232 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
233 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
234 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
236 if ($by_id && ($search_box != false || $opts['editable']) ) {
237 // on first display show selector list
238 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
239 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
240 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
241 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
242 set_focus($name.'_text'); // prevent lost focus
243 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
244 set_focus($name); // prevent lost focus
245 if (!$opts['editable'])
247 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
250 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
252 // span for select list/input field update
253 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
255 // if selectable or editable list is used - add select button
256 if ($select_submit != false || $search_button) {
257 global $_select_button;
258 // button class selects form reload/ajax selector update
259 $selector .= sprintf($_select_button, $disabled, user_theme(),
260 (fallback_mode() ? '' : 'display:none;'),
261 '_'.$name.'_update')."\n";
263 // ------ make combo ----------
265 if ($search_box != false) {
266 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
267 $opts['size']."' maxlength='".$opts['max'].
268 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
269 .$opts['box_hint']."'"
270 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
272 if ($search_submit != false || $opts['editable']) {
273 global $_search_button;
274 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
275 (fallback_mode() ? '' : 'display:none;'),
276 $search_submit ? $search_submit : "_{$name}_button")."\n";
279 default_focus(($search_box && $by_id) ? $search_box : $name);
281 if ($search_box && $opts['cells'])
282 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
284 $str = $edit_entry.$selector;
290 Returns true if selector $name is subject to update.
292 function list_updated($name)
294 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
296 //----------------------------------------------------------------------------------------------
297 // Universal array combo generator
298 // $items is array of options 'value' => 'description'
299 // Options is reduced set of combo_selector options and is merged with defaults.
301 function array_selector($name, $selected_id, $items, $options=null)
305 $opts = array( // default options
306 'spec_option'=>false, // option text or false
307 'spec_id' => 0, // option id
308 'select_submit' => false, //submit on select: true/false
309 'async' => true, // select update via ajax (true) vs _page_body reload
310 'default' => '', // default value when $_POST is not set
311 'multi'=>false, // multiple select
312 // search box parameters
313 'height' => false, // number of lines in select box
317 // ------ merge options with defaults ----------
319 $opts = array_merge($opts, $options);
320 $select_submit = $opts['select_submit'];
321 $spec_id = $opts['spec_id'];
322 $spec_option = $opts['spec_option'];
323 $disabled = $opts['disabled'] ? "disabled" : '';
324 $multi = $opts['multi'];
326 if ($selected_id == null) {
327 $selected_id = get_post($name, $opts['default']);
329 if(!is_array($selected_id))
330 $selected_id = array($selected_id); // code is generalized for multiple selection support
332 if (isset($_POST[ '_'.$name.'_update'])) {
334 $Ajax->activate('_page_body');
336 $Ajax->activate($name);
339 // ------ make selector ----------
340 $selector = $first_opt = '';
343 //if($name=='SelectStockFromList') display_error($sql);
344 foreach($items as $value=>$descr) {
346 if (in_array((string)$value, $selected_id)) {
350 if ($first_id === false) {
354 $selector .= "<option $sel value='$value'>$descr</option>\n";
357 // Prepend special option.
358 if ($spec_option !== false) { // if special option used - add it
359 $first_id = $spec_id;
360 $first_opt = $spec_option;
361 $sel = $found===false ? 'selected' : '';
362 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
366 if ($found===false) {
367 $selected_id = array($first_id);
369 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
370 $selector = "<select ".($multi ? "multiple" : '')
371 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
372 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
373 . $opts['sel_hint']."'>".$selector."</select>\n";
375 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
377 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
379 if ($select_submit != false) { // if submit on change is used - add select button
380 global $_select_button;
381 $selector .= sprintf($_select_button, $disabled, user_theme(),
382 (fallback_mode() ? '' : 'display:none;'),
383 '_'.$name.'_update')."\n";
385 default_focus($name);
389 //----------------------------------------------------------------------------------------------
391 function _format_add_curr($row)
393 static $company_currency;
395 if ($company_currency == null)
397 $company_currency = get_company_currency();
399 return $row[1] . ($row[2] == $company_currency ?
400 '' : (" - " . $row[2]));
403 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
404 $all=false, $editkey = false)
408 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
410 $mode = get_company_pref('no_supplier_list');
413 set_editor('supplier', $name, $editkey);
415 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
417 'format' => '_format_add_curr',
418 'order' => array('supp_ref'),
419 'search_box' => $mode!=0,
421 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
422 'spec_id' => $all_items,
423 'select_submit'=> $submit_on_change,
425 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
426 _('Select supplier'),
427 'show_inactive'=>$all
431 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
432 $submit_on_change=false, $all=false, $editkey = false)
435 echo "<td>$label</td><td>\n";
436 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
441 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
442 $submit_on_change=false, $all=false, $editkey = false)
444 echo "<tr><td>$label</td><td>";
445 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
449 //----------------------------------------------------------------------------------------------
451 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
452 $show_inactive=false, $editkey = false)
456 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
458 $mode = get_company_pref('no_customer_list');
461 set_editor('customer', $name, $editkey);
463 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
465 'format' => '_format_add_curr',
466 'order' => array('debtor_ref'),
467 'search_box' => $mode!=0,
470 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
471 'spec_id' => $all_items,
472 'select_submit'=> $submit_on_change,
474 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
475 _('Select customer'),
476 'show_inactive' => $show_inactive
480 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
481 $submit_on_change=false, $show_inactive=false, $editkey = false)
484 echo "<td>$label</td>\n";
486 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
487 $show_inactive, $editkey);
491 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
492 $submit_on_change=false, $show_inactive=false, $editkey = false)
494 echo "<tr><td>$label</td><td nowrap>";
495 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
496 $show_inactive, $editkey);
497 echo "</td>\n</tr>\n";
500 //------------------------------------------------------------------------------------------------
502 function customer_branches_list($customer_id, $name, $selected_id=null,
503 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
507 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
508 WHERE debtor_no='" . $customer_id . "' ";
511 set_editor('branch', $name, $editkey);
513 $where = $enabled ? array("disable_trans = 0") : array();
514 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
517 'order' => array('branch_ref'),
518 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
519 'spec_id' => $all_items,
520 'select_submit'=> $submit_on_change,
521 'sel_hint' => _('Select customer branch')
524 //------------------------------------------------------------------------------------------------
526 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
527 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
530 echo "<td>$label</td>\n";
532 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
533 $submit_on_change, $editkey);
537 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
538 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
541 customer_branches_list_cells($label, $customer_id, $name, $selected_id,
542 $all_option, $enabled, $submit_on_change, $editkey);
546 //------------------------------------------------------------------------------------------------
548 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
552 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
554 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
556 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
557 'spec_id' => $all_items,
558 'select_submit'=> $submit_on_change
562 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
565 echo "<td>$label</td>\n";
567 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
571 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
574 locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
578 //-----------------------------------------------------------------------------------------------
580 function currencies_list($name, $selected_id=null, $submit_on_change=false)
582 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
584 // default to the company currency
585 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
587 'select_submit'=> $submit_on_change,
588 'default' => get_company_currency(),
593 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
596 echo "<td>$label</td>\n";
598 echo currencies_list($name, $selected_id, $submit_on_change);
602 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
605 currencies_list_cells($label, $name, $selected_id, $submit_on_change);
609 //---------------------------------------------------------------------------------------------------
611 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
614 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
616 // default to the company current fiscal year
618 return combo_input($name, $selected_id, $sql, 'id', '',
621 'default' => get_company_pref('f_year'),
622 'format' => '_format_fiscalyears',
623 'select_submit'=> $submit_on_change,
628 function _format_fiscalyears($row)
630 return sql2date($row[1]) . " - " . sql2date($row[2])
631 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
634 function fiscalyears_list_cells($label, $name, $selected_id=null)
637 echo "<td>$label</td>\n";
639 echo fiscalyears_list($name, $selected_id);
643 function fiscalyears_list_row($label, $name, $selected_id=null)
646 fiscalyears_list_cells($label, $name, $selected_id);
649 //------------------------------------------------------------------------------------
651 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
652 $submit_on_change=false, $showclosed=false, $showtype=1)
654 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
657 'order' => 'reference',
658 'spec_option'=>$no_option ? $showname : false,
660 'select_submit'=> $submit_on_change,
665 $options['where'][] = "closed=0";
667 $options['where'][] = "type_=$showtype";
669 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
672 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
673 $showclosed=false, $showtype=0, $submit_on_change=false)
676 echo "<td>$label</td>\n";
678 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
682 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
683 $showclosed=false, $showtype=0, $submit_on_change=false)
686 dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
687 $showclosed, $showtype, $submit_on_change);
691 //---------------------------------------------------------------------------------------------------
693 function stock_items_list($name, $selected_id=null, $all_option=false,
694 $submit_on_change=false, $opts=array(), $editkey = false)
698 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
699 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
702 set_editor('item', $name, $editkey);
704 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
707 'format' => '_format_stock_items',
708 'spec_option' => $all_option===true ? _("All Items") : $all_option,
709 'spec_id' => $all_items,
710 'search_box' => true,
711 'search' => array("stock_id", "c.description","s.description"),
712 'search_submit' => get_company_pref('no_item_list')!=0,
714 'select_submit'=> $submit_on_change,
716 'order' => array('c.description','stock_id')
720 function _format_stock_items($row)
722 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
725 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
726 $submit_on_change=false, $all=false, $editkey = false)
729 echo "<td>$label</td>\n";
730 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
731 array('cells'=>true, 'show_inactive'=>$all), $editkey);
734 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
737 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
741 //---------------------------------------------------------------------------------------------------
743 // Select item via foreign code.
745 function sales_items_list($name, $selected_id=null, $all_option=false,
746 $submit_on_change=false, $type='', $opts=array())
750 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
751 i.inactive, if(count(*)>1, '0', s.editable) as editable
753 ".TB_PREF."stock_master s,
754 ".TB_PREF."item_codes i
756 ".TB_PREF."stock_category c
757 ON i.category_id=c.category_id
758 WHERE i.stock_id=s.stock_id";
761 if ($type == 'local') { // exclude foreign codes
762 $sql .= " AND !i.is_foreign";
763 } elseif ($type == 'kits') { // sales kits
764 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
766 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
767 $sql .= " GROUP BY i.item_code";
769 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
772 'format' => '_format_stock_items',
773 'spec_option' => $all_option===true ? _("All Items") : $all_option,
774 'spec_id' => $all_items,
775 'search_box' => true,
776 'search' => array("i.item_code", "c.description", "i.description"),
777 'search_submit' => get_company_pref('no_item_list')!=0,
779 'select_submit'=> $submit_on_change,
781 'order' => array('c.description','i.item_code'),
787 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
790 echo "<td>$label</td>\n";
791 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
792 '', array('cells'=>true));
795 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
797 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
798 'kits', array('cells'=>false, 'editable' => false));
801 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
805 echo "<td>$label</td>\n";
807 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
808 'local', array('cells'=>false, 'editable' => false));
811 //------------------------------------------------------------------------------------
813 function stock_manufactured_items_list($name, $selected_id=null,
814 $all_option=false, $submit_on_change=false)
816 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
817 array('where'=>array("mb_flag= 'M'")));
820 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
821 $all_option=false, $submit_on_change=false)
824 echo "<td>$label</td>\n";
826 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
830 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
831 $all_option=false, $submit_on_change=false)
834 stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
837 //------------------------------------------------------------------------------------
839 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
840 $all_option=false, $submit_on_change=false, $editkey = false)
842 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
843 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
846 function stock_component_items_list_cells($label, $name, $parent_stock_id,
847 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
850 echo "<td>$label</td>\n";
851 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
852 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
855 //------------------------------------------------------------------------------------
857 function stock_costable_items_list($name, $selected_id=null,
858 $all_option=false, $submit_on_change=false)
860 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
861 array('where'=>array("mb_flag!='D'")));
864 function stock_costable_items_list_cells($label, $name, $selected_id=null,
865 $all_option=false, $submit_on_change=false)
868 echo "<td>$label</td>\n";
869 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
870 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
873 //------------------------------------------------------------------------------------
874 function stock_purchasable_items_list($name, $selected_id=null,
875 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
877 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
878 array('where'=>array("mb_flag!= 'M'"),
879 'show_inactive'=>$all), $editkey);
882 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
884 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
885 $all_option=false, $submit_on_change=false, $editkey=false)
888 echo "<td>$label</td>\n";
889 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
890 array('where'=>array("mb_flag!= 'M'"),
892 'cells'=>true), $editkey);
895 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
896 $all_option=false, $submit_on_change=false, $editkey=false)
899 stock_purchasable_items_list_cells($label, $name, $selected_id=null,
900 $all_option, $submit_on_change, $editkey);
904 //------------------------------------------------------------------------------------
906 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
912 echo "<td>$label</td>\n";
915 echo array_selector($name, $selected_id, $stock_types,
917 'select_submit'=> true,
918 'disabled' => !$enabled) );
922 function stock_units_list_row($label, $name, $value=null, $enabled=true)
924 $result = get_all_item_units();
927 echo "<td>$label</td>\n";
930 while($unit = db_fetch($result))
931 $units[$unit['abbr']] = $unit['name'];
933 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
938 //------------------------------------------------------------------------------------
940 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
942 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
944 return combo_input($name, $selected_id, $sql, 'id', 'name',
946 'spec_option' => $none_option,
947 'spec_id' => ALL_NUMERIC,
948 'select_submit'=> $submit_on_change,
953 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
954 $submit_on_change=false)
957 echo "<td>$label</td>\n";
959 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
963 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
964 $submit_on_change=false)
967 tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
971 //------------------------------------------------------------------------------------
973 function tax_groups_list($name, $selected_id=null,
974 $none_option=false, $submit_on_change=false)
976 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
978 return combo_input($name, $selected_id, $sql, 'id', 'name',
981 'spec_option' => $none_option,
982 'spec_id' => ALL_NUMERIC,
983 'select_submit'=> $submit_on_change,
988 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
991 echo "<td>$label</td>\n";
993 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
997 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1000 tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
1004 //------------------------------------------------------------------------------------
1006 function item_tax_types_list($name, $selected_id=null)
1008 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1009 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1012 function item_tax_types_list_cells($label, $name, $selected_id=null)
1015 echo "<td>$label</td>\n";
1017 echo item_tax_types_list($name, $selected_id);
1021 function item_tax_types_list_row($label, $name, $selected_id=null)
1024 item_tax_types_list_cells($label, $name, $selected_id);
1028 //------------------------------------------------------------------------------------
1030 function shippers_list($name, $selected_id=null)
1032 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1033 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1034 array('order'=>array('shipper_name')));
1037 function shippers_list_cells($label, $name, $selected_id=null)
1040 echo "<td>$label</td>\n";
1042 echo shippers_list($name, $selected_id);
1046 function shippers_list_row($label, $name, $selected_id=null)
1049 shippers_list_cells($label, $name, $selected_id);
1053 //-------------------------------------------------------------------------------------
1055 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1057 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1058 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1059 array('order'=>array('salesman_name'),
1060 'spec_option' => $spec_opt,
1061 'spec_id' => ALL_NUMERIC));
1064 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1067 echo "<td>$label</td>\n";
1069 echo sales_persons_list($name, $selected_id, $spec_opt);
1073 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1076 sales_persons_list_cells($label, $name, $selected_id, $spec_opt);
1080 //------------------------------------------------------------------------------------
1082 function sales_areas_list($name, $selected_id=null)
1084 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1085 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1088 function sales_areas_list_cells($label, $name, $selected_id=null)
1091 echo "<td>$label</td>\n";
1093 echo sales_areas_list($name, $selected_id);
1097 function sales_areas_list_row($label, $name, $selected_id=null)
1100 sales_areas_list_cells($label, $name, $selected_id);
1104 //------------------------------------------------------------------------------------
1106 function sales_groups_list($name, $selected_id=null, $special_option=false)
1108 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1109 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1110 'spec_option' => $special_option===true ? ' ' : $special_option,
1111 'order' => 'description', 'spec_id' => 0,
1115 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1118 echo "<td>$label</td>\n";
1120 echo sales_groups_list($name, $selected_id, $special_option);
1124 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1127 sales_groups_list_cells($label, $name, $selected_id, $special_option);
1131 //------------------------------------------------------------------------------------
1133 function _format_template_items($row)
1135 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1138 function templates_list($name, $selected_id=null, $special_option=false)
1140 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1141 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1142 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1143 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1144 'format' => '_format_template_items',
1145 'spec_option' => $special_option===true ? ' ' : $special_option,
1146 'order' => 'order_no', 'spec_id' => 0,
1150 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1153 echo "<td>$label</td>\n";
1155 echo templates_list($name, $selected_id, $special_option);
1159 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1162 templates_list_cells($label, $name, $selected_id, $special_option);
1166 //------------------------------------------------------------------------------------
1168 function workorders_list($name, $selected_id=null)
1170 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1171 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1174 function workorders_list_cells($label, $name, $selected_id=null)
1177 echo "<td>$label</td>\n";
1179 echo workorders_list($name, $selected_id);
1183 function workorders_list_row($label, $name, $selected_id=null)
1186 workorders_list_cells($label, $name, $selected_id);
1190 //------------------------------------------------------------------------------------
1192 function payment_terms_list($name, $selected_id=null)
1194 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1195 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1198 function payment_terms_list_cells($label, $name, $selected_id=null)
1201 echo "<td>$label</td>\n";
1203 echo payment_terms_list($name, $selected_id);
1207 function payment_terms_list_row($label, $name, $selected_id=null)
1210 payment_terms_list_cells($label, $name, $selected_id);
1214 //------------------------------------------------------------------------------------
1216 function credit_status_list($name, $selected_id=null)
1218 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1219 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1222 function credit_status_list_cells($label, $name, $selected_id=null)
1225 echo "<td>$label</td>\n";
1227 echo credit_status_list($name, $selected_id);
1231 function credit_status_list_row($label, $name, $selected_id=null)
1234 credit_status_list_cells($label, $name, $selected_id);
1238 //-----------------------------------------------------------------------------------------------
1240 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1242 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1244 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1246 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1248 'select_submit'=> $submit_on_change,
1249 // 'async' => false,
1253 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1256 echo "<td>$label</td>\n";
1258 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1262 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1265 sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1269 //-----------------------------------------------------------------------------------------------
1271 function movement_types_list($name, $selected_id=null)
1273 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1274 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1277 function movement_types_list_cells($label, $name, $selected_id=null)
1280 echo "<td>$label</td>\n";
1282 echo movement_types_list($name, $selected_id);
1286 function movement_types_list_row($label, $name, $selected_id=null)
1289 movement_types_list_cells($label, $name, $selected_id);
1293 //-----------------------------------------------------------------------------------------------
1294 function _format_date($row)
1296 return sql2date($row['reconciled']);
1299 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1301 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1302 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1303 GROUP BY reconciled";
1304 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1306 'spec_option' => $special_option,
1307 'format' => '_format_date',
1309 'select_submit'=> $submit_on_change
1313 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1316 echo "<td>$label</td>\n";
1318 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1322 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1325 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1329 //-----------------------------------------------------------------------------------------------
1331 function workcenter_list($name, $selected_id=null, $all_option=false)
1335 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1337 return combo_input($name, $selected_id, $sql, 'id', 'name',
1339 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1340 'spec_id' => $all_items,
1344 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1346 default_focus($name);
1348 echo "<td>$label</td>\n";
1350 echo workcenter_list($name, $selected_id, $all_option);
1354 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1357 workcenter_list_cells($label, $name, $selected_id, $all_option);
1361 //-----------------------------------------------------------------------------------------------
1363 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1365 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1366 FROM ".TB_PREF."bank_accounts";
1368 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1370 'format' => '_format_add_curr',
1371 'select_submit'=> $submit_on_change,
1376 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1379 echo "<td>$label</td>\n";
1381 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1385 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1388 bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1391 //-----------------------------------------------------------------------------------------------
1393 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1395 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1396 FROM ".TB_PREF."bank_accounts
1397 WHERE ".TB_PREF."bank_accounts.account_type=3";
1400 echo "<tr><td>$label</td>\n";
1402 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1404 'format' => '_format_add_curr',
1405 'select_submit'=> $submit_on_change,
1408 echo "</td></tr>\n";
1410 //-----------------------------------------------------------------------------------------------
1412 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1414 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1416 default_focus($name);
1419 echo "<td>$label</td>\n";
1422 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1424 'select_submit'=> $submit_on_change,
1426 'spec_option' =>$spec_option,
1428 'order'=> array('pos_name')
1430 echo "</td></tr>\n";
1433 //-----------------------------------------------------------------------------------------------
1434 // Payment type selector for current user.
1436 function sale_payment_list($name, $selected_id=null, $submit_on_change=true)
1438 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1439 $paym = get_sales_point(user_pos());
1441 if (!$paym['cash_sale'] || !$paym['credit_sale']) {
1442 if ($paym['cash_sale']) // only cash
1443 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1445 $sql .= " WHERE days_before_due!=0 OR day_in_following_month!=0";
1448 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1450 'select_submit'=> $submit_on_change,
1456 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=true)
1459 echo "<td>$label</td>\n";
1462 echo sale_payment_list($name, $selected_id, $submit_on_change);
1466 //-----------------------------------------------------------------------------------------------
1468 function class_list($name, $selected_id=null, $submit_on_change=false)
1470 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1472 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1474 'select_submit'=> $submit_on_change,
1480 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1483 echo "<td>$label</td>\n";
1485 echo class_list($name, $selected_id, $submit_on_change);
1489 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1492 class_list_cells($label, $name, $selected_id, $submit_on_change);
1496 //-----------------------------------------------------------------------------------------------
1497 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1499 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1500 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1501 array('order'=>'category_id',
1502 'spec_option' => $spec_opt,
1504 'select_submit'=> $submit_on_change,
1509 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1512 echo "<td>$label</td>\n";
1514 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1518 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1521 stock_categories_list_cells($label, $name, $selected_id, $spec_opt, $submit_on_change);
1525 //-----------------------------------------------------------------------------------------------
1527 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all_option_numeric=true)
1531 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1533 return combo_input($name, $selected_id, $sql, 'id', 'name',
1535 'order' => 'class_id', 'id',
1536 'spec_option' =>$all_option,
1537 'spec_id' => $all_option_numeric ? 0 : $all_items
1541 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1542 $all_option_numeric=false)
1545 echo "<td>$label</td>\n";
1547 echo gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1551 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1552 $all_option_numeric=false)
1555 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1556 $all_option_numeric);
1560 //-----------------------------------------------------------------------------------------------
1561 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1562 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1564 if ($skip_bank_accounts)
1565 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1566 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1567 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1568 ."ON chart.account_code=acc.account_code
1569 WHERE acc.account_code IS NULL
1570 AND chart.account_type=type.id";
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 WHERE chart.account_type=type.id";
1576 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1578 'format' => '_format_account',
1579 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1581 'order' => array('type.class_id','type.id','account_code'),
1582 'search_box' => $cells,
1583 'search_submit' => false,
1587 'select_submit'=> $submit_on_change,
1590 'show_inactive' => $all
1595 function _format_account($row)
1597 return $row[0] . " " . $row[1];
1600 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1601 $skip_bank_accounts=false, $cells=false, $all_option=false,
1602 $submit_on_change=false, $all=false)
1605 echo "<td>$label</td>\n";
1607 echo gl_all_accounts_list($name, $selected_id,
1608 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1612 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1613 $skip_bank_accounts=false, $cells=false, $all_option=false)
1616 gl_all_accounts_list_cells($label, $name, $selected_id,
1617 $skip_bank_accounts, $cells, $all_option);
1621 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1624 $items['0'] = strlen($name_no) ? $name_no : _("No");
1625 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1627 return array_selector($name, $selected_id, $items,
1629 'select_submit'=> $submit_on_change,
1630 'async' => false ) ); // FIX?
1633 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1636 echo "<td>$label</td>\n";
1638 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1642 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1645 yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1649 //------------------------------------------------------------------------------------------------
1651 function languages_list($name, $selected_id=null)
1653 global $installed_languages;
1656 foreach ($installed_languages as $lang)
1657 $items[$lang['code']] = $lang['name'];
1659 return array_selector($name, $selected_id, $items);
1662 function languages_list_cells($label, $name, $selected_id=null)
1665 echo "<td>$label</td>\n";
1667 echo languages_list($name, $selected_id);
1671 function languages_list_row($label, $name, $selected_id=null)
1674 languages_list_cells($label, $name, $selected_id);
1678 //------------------------------------------------------------------------------------------------
1680 function bank_account_types_list($name, $selected_id=null)
1682 global $bank_account_types;
1684 return array_selector($name, $selected_id, $bank_account_types);
1687 function bank_account_types_list_cells($label, $name, $selected_id=null)
1690 echo "<td>$label</td>\n";
1692 echo bank_account_types_list($name, $selected_id);
1696 function bank_account_types_list_row($label, $name, $selected_id=null)
1699 bank_account_types_list_cells($label, $name, $selected_id);
1703 //------------------------------------------------------------------------------------------------
1704 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1706 global $payment_person_types;
1709 foreach ($payment_person_types as $key=>$type)
1711 if ($key != PT_WORKORDER)
1712 $items[$key] = $type;
1714 return array_selector($name, $selected_id, $items,
1715 array( 'select_submit'=> $submit_on_change ) );
1718 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1721 echo "<td>$label</td>\n";
1723 echo payment_person_types_list($name, $selected_id, $related);
1727 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1730 payment_person_types_list_cells($label, $name, $selected_id, $related);
1734 //------------------------------------------------------------------------------------------------
1736 function wo_types_list($name, $selected_id=null)
1738 global $wo_types_array;
1740 return array_selector($name, $selected_id, $wo_types_array,
1741 array( 'select_submit'=> true, 'async' => true ) );
1744 function wo_types_list_row($label, $name, $selected_id=null)
1746 echo "<tr><td>$label</td><td>\n";
1747 echo wo_types_list($name, $selected_id);
1748 echo "</td></tr>\n";
1751 //------------------------------------------------------------------------------------------------
1753 function dateformats_list_row($label, $name, $value=null)
1755 global $dateformats;
1757 echo "<tr><td>$label</td>\n<td>";
1758 echo array_selector( $name, $value, $dateformats );
1759 echo "</td></tr>\n";
1762 function dateseps_list_row($label, $name, $value=null)
1766 echo "<tr><td>$label</td>\n<td>";
1767 echo array_selector( $name, $value, $dateseps );
1768 echo "</td></tr>\n";
1771 function thoseps_list_row($label, $name, $value=null)
1775 echo "<tr><td>$label</td>\n<td>";
1776 echo array_selector( $name, $value, $thoseps );
1777 echo "</td></tr>\n";
1780 function decseps_list_row($label, $name, $value=null)
1784 echo "<tr><td>$label</td>\n<td>";
1785 echo array_selector( $name, $value, $decseps );
1786 echo "</td></tr>\n";
1789 function themes_list_row($label, $name, $value=null)
1791 global $path_to_root;
1793 $path = $path_to_root.'/themes/';
1795 $themedir = opendir($path);
1796 while(false !== ($fname = readdir($themedir)))
1798 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1800 $themes[$fname] = $fname;
1805 echo "<tr><td>$label</td>\n<td>";
1806 echo array_selector( $name, $value, $themes );
1807 echo "</td></tr>\n";
1810 function pagesizes_list_row($label, $name, $value=null)
1815 foreach ($pagesizes as $pz)
1818 echo "<tr><td>$label</td>\n<td>";
1819 echo array_selector( $name, $value, $items );
1820 echo "</td></tr>\n";
1823 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false)
1825 global $systypes_array;
1827 return array_selector($name, $value, $systypes_array,
1829 'spec_option'=> $spec_opt,
1830 'spec_id' => ALL_NUMERIC,
1831 'select_submit'=> $submit_on_change,
1837 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1840 echo "<td>$label</td>\n";
1842 echo systypes_list($name, $value, false, $submit_on_change);
1846 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1849 systypes_list_cells($label, $name, $value, false, $submit_on_change);
1853 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1855 global $systypes_array;
1858 echo "<td>$label</td>\n";
1861 $items = $systypes_array;
1863 // exclude quotes, orders and dimensions
1864 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1865 ST_SALESQUOTE) as $excl)
1866 unset($items[$excl]);
1868 echo array_selector($name, $value, $items,
1870 'spec_option'=> _("All"),
1872 'select_submit'=> $submit_on_change,
1879 function cust_allocations_list_cells($label, $name, $selected=null)
1887 $all_items=>_("All Types"),
1888 '1'=> _("Sales Invoices"),
1889 '2'=> _("Overdue Invoices"),
1890 '3' => _("Payments"),
1891 '4' => _("Credit Notes"),
1892 '5' => _("Delivery Notes")
1894 echo array_selector($name, $selected, $allocs);
1898 function supp_allocations_list_cell($name, $selected=null)
1904 $all_items=>_("All Types"),
1905 '1'=> _("Invoices"),
1906 '2'=> _("Overdue Invoices"),
1907 '3' => _("Payments"),
1908 '4' => _("Credit Notes"),
1909 '5' => _("Overdue Credit Notes")
1911 echo array_selector($name, $selected, $allocs);
1915 function policy_list_cells($label, $name, $selected=null)
1920 echo array_selector($name, $selected,
1921 array( '' => _("Automatically put balance on back order"),
1922 'CAN' => _("Cancel any quantites not delivered")) );
1926 function policy_list_row($label, $name, $selected=null)
1929 policy_list_cells($label, $name, $selected);
1933 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1938 echo array_selector($name, $selected,
1939 array( 'Return' => _("Items Returned to Inventory Location"),
1940 'WriteOff' => _("Items Written Off")),
1941 array( 'select_submit'=> $submit_on_change ) );
1945 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1948 credit_type_list_cells($label, $name, $selected, $submit_on_change);
1952 function number_list($name, $selected, $from, $to, $no_option=false)
1955 for ($i = $from; $i <= $to; $i++)
1958 return array_selector($name, $selected, $items,
1959 array( 'spec_option' => $no_option,
1960 'spec_id' => ALL_NUMERIC) );
1963 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1968 echo number_list($name, $selected, $from, $to, $no_option);
1972 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1975 echo number_list_cells($label, $name, $selected, $from, $to, $no_option);
1979 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1980 $submit_on_change=true)
1982 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1983 ." GROUP BY profile";
1984 $result = db_query($sql, 'cannot get all profile names');
1985 $profiles = array();
1986 while($myrow=db_fetch($result)) {
1987 $profiles[$myrow['profile']] = $myrow['profile'];
1992 echo "<td>$label</td>\n";
1995 echo array_selector($name, $selected_id, $profiles,
1996 array( 'select_submit'=> $submit_on_change,
1997 'spec_option'=>$spec_opt,
2001 echo "</td></tr>\n";
2004 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2006 static $printers; // query only once for page display
2009 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2010 $result = db_query($sql, 'cannot get all printers');
2011 $printers = array();
2012 while($myrow=db_fetch($result)) {
2013 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2016 return array_selector($name, $selected_id, $printers,
2017 array( 'select_submit'=> $submit_on_change,
2018 'spec_option'=>$spec_opt,
2023 //------------------------------------------------------------------------------------------------
2025 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2028 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2030 $sql .= " WHERE type=$type";
2032 return combo_input($name, $selected_id, $sql, 'id', 'description',
2035 'order' => 'description',
2036 'select_submit'=> $submit_on_change,
2042 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2044 echo "<td>$label</td><td>\n";
2045 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2049 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2052 quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2057 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2059 global $quick_actions;
2061 echo "<tr><td>$label</td><td>";
2062 echo array_selector($name, $selected_id, $quick_actions,
2064 'select_submit'=> $submit_on_change
2066 echo "</td></tr>\n";
2069 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2071 global $quick_entry_types;
2073 echo "<tr><td>$label</td><td>";
2074 echo array_selector($name, $selected_id, $quick_entry_types,
2076 'select_submit'=> $submit_on_change
2078 echo "</td></tr>\n";
2081 function record_status_list_row($label, $name) {
2082 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2085 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2087 global $class_types;
2089 echo "<tr><td>$label</td><td>";
2090 echo array_selector($name, $selected_id, $class_types,
2092 'select_submit'=> $submit_on_change
2094 echo "</td></tr>\n";
2097 //------------------------------------------------------------------------------------------------
2099 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2100 $show_inactive = false)
2104 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2106 return combo_input($name, $selected_id, $sql, 'id', 'description',
2108 'spec_option'=>$new_item ? _("New role") : false,
2110 'select_submit'=> $submit_on_change,
2111 'show_inactive' => $show_inactive
2115 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2116 $show_inactive = false)
2119 echo "<td>$label</td>\n";
2121 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2125 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2126 $show_inactive = false)
2129 security_roles_list_cells($label, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2133 function tab_list_row($label, $name, $selected_id=null, $all = false)
2135 global $installed_extensions;
2138 foreach ($_SESSION['App']->applications as $app) {
2139 $tabs[$app->id] = access_string($app->name, true);
2141 if ($all) { // add also not active ext. modules
2142 foreach ($installed_extensions as $ext) {
2143 if ($ext['type'] == 'module' && !$ext['active'])
2144 $tabs[$ext['tab']] = access_string($ext['title'], true);
2148 echo "<td>$label</td><td>\n";
2149 echo array_selector($name, $selected_id, $tabs);
2150 echo "</td></tr>\n";
2153 //-----------------------------------------------------------------------------------------------
2155 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2158 global $path_to_root;
2159 include_once($path_to_root . "/admin/db/tags_db.inc");
2160 $results = get_tags($type, $all);
2162 while ($tag = db_fetch($results))
2163 $tags[$tag['id']] = $tag['name'];
2165 if (!isset($tags)) {
2166 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2169 return array_selector($name, null, $tags,
2172 'height' => $height,
2173 'spec_option'=> $spec_opt,
2178 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2181 echo "<td>$label</td>\n";
2183 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2188 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2191 tag_list_cells($label, $name, $height, $type, $mult, $all, $spec_opt);
2195 //---------------------------------------------------------------------------------------------
2196 // List of sets of active extensions
2198 function extset_list($name, $value=null, $submit_on_change=false)
2200 global $db_connections;
2203 foreach ($db_connections as $comp)
2204 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2205 return array_selector( $name, $value, $items,
2207 'spec_option'=> _("Available and/or installed"),
2209 'select_submit'=> $submit_on_change,