3 include_once($path_to_root . "/includes/banking.inc");
4 include_once($path_to_root . "/includes/reserved.inc");
5 include_once($path_to_root . "/includes/types.inc");
6 include_once($path_to_root . "/includes/current_user.inc");
8 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
9 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
11 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
12 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
14 $all_items = reserved_words::get_all();
16 //----------------------------------------------------------------------------
17 // Universal sql combo generator
18 // $sql must return selector values and selector texts in columns 0 & 1
19 // Options are merged with defaults.
21 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
26 $opts = array( // default options
27 'where'=> array(), // additional constraints
28 'order' => $namefield, // list sort order
29 // special option parameters
30 'spec_option'=>false, // option text or false
31 'spec_id' => 0, // option id
32 // submit on select parameters
33 'default' => '', // default value when $_POST is not set
34 'select_submit' => false, //submit on select: true/false
35 'async' => true, // select update via ajax (true) vs _page_body reload
36 // search box parameters
38 'search_box' => false, // name or true/false
39 'type' => 0, // type of extended selector:
40 // 0 - with (optional) visible search box, search by id
41 // 1 - with hidden search box, search by option text
42 // 2 - TODO reverse: box with hidden selector available via enter; this
43 // would be convenient for optional ad hoc adding of new item
44 'search_submit' => true, //search submit button: true/false
45 'size' => 8, // size and max of box tag
47 'cells' => false, // combo displayed as 2 <td></td> cells
48 'search' => array(), // sql field names to search
49 'format' => null, // format functions for regular options
51 'box_hint' => null // box/selectors hints; null = std see below
53 // ------ merge options with defaults ----------
55 $opts = array_merge($opts, $options);
56 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
58 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
59 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
60 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
61 $spec_id = $opts['spec_id'];
62 $spec_option = $opts['spec_option'];
63 $by_id = ($opts['type'] == 0);
64 $class = $by_id ? 'combo':'combo2';
65 $disabled = $opts['disabled'] ? "disabled" : '';
67 if(!count($opts['search'])) {
68 $opts['search'] = array($by_id ? $valfield : $namefield);
70 if ($opts['sel_hint'] === null)
71 $opts['sel_hint'] = $by_id || $search_box==false ?
72 '' : _('Press Space tab for search pattern entry');
74 if ($opts['box_hint'] === null)
75 $opts['box_hint'] = $search_box && $search_submit != false ?
76 ($by_id ? _('Enter code fragment to search or * for all')
77 : _('Enter description fragment to search or * for all')) :'';
79 if ($selected_id == null) {
80 $selected_id = get_post($name, $opts['default']);
82 $txt = get_post($search_box);
86 if (isset($_POST[$select_submit])) {
87 if ($by_id) $txt = $_POST[$name];
90 $Ajax->activate('_page_body');
92 $Ajax->activate($name);
95 // search related sql modifications
97 $rel = "rel='$search_box'"; // set relation to list
98 if ($opts['search_submit']) {
99 if (isset($_POST[$search_submit])) {
100 $selected_id = ''; // ignore selected_id while search
102 $Ajax->activate('_page_body');
104 $Ajax->activate($name);
107 if ($spec_option === false && $selected_id==null)
110 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
115 foreach($opts['search'] as $i=> $s)
116 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
117 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
122 if (count($opts['where'])) {
123 $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
124 $sql .= '('. implode($opts['where'], ' AND ') . ')';
126 if ($opts['order'] != false) {
127 $sql .= ' ORDER BY '.$opts['order'];
131 // ------ make selector ----------
132 $selector = $first_opt = '';
135 //if($name=='SelectStockFromList') display_error($sql);
136 if($result = db_query($sql)) {
137 while ($contact_row = db_fetch($result)) {
138 $value = $contact_row[0];
139 $descr = $opts['format']==null ? $contact_row[1] :
140 call_user_func($opts['format'], $contact_row);
142 if (get_post($search_submit) && ($txt === $value)) {
143 $selected_id = $value;
145 if ((string)($selected_id) === $value) {
149 if ($first_id === false) {
153 $selector .= "<option $sel value='$value'>$descr</option>\n";
155 db_free_result($result);
158 // Prepend special option.
159 if ($spec_option !== false) { // if special option used - add it
160 $first_id = $spec_id;
161 $first_opt = $spec_option;
162 $sel = $found===false ? 'selected' : '';
163 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
167 if ($found === false) {
168 $selected_id = $first_id;
170 $_POST[$name] = $selected_id;
172 if ($by_id && $search_box != false) {
174 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
176 $selector = "<select $disabled name='$name' class='$class' title='"
177 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
179 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
181 // because of bug which M$ cannot fix since IE 5.0
182 // we must embed whole selector in span tags to enable proper ajax update
183 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
185 if ($select_submit != false) { // if submit on change is used - add select button
186 global $_select_button;
187 // button class selects form reload/ajax selector update
188 $selector .= sprintf($_select_button, $disabled, user_theme(),
189 (in_ajax() ? 'display:none;':''),
190 $select_submit)."\n";
192 // ------ make combo ----------
195 if ($search_box != false) {
196 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
197 $opts['size']."' maxlength='".$opts['max'].
198 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
199 .$opts['box_hint']."'"
200 .(in_ajax() && !$by_id ? " style=display:none;":'')
202 if ($search_submit != false) {
203 global $_search_button;
204 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
205 (in_ajax() ? 'display:none;':''),
206 $search_submit)."\n";
209 default_focus($name);
211 if ($search_box && $opts['cells'])
212 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
214 echo $edit_entry.$selector;
221 Returns true if selector $name is subject to update.
223 function list_updated($name)
225 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
227 //----------------------------------------------------------------------------------------------
228 // Universal array combo generator
229 // $items is array of options 'value' => 'description'
230 // Options is reduced set of combo_selector options and is merged with defaults.
232 function array_selector($name, $selected_id, $items, $options=null)
236 $opts = array( // default options
237 'spec_option'=>false, // option text or false
238 'spec_id' => 0, // option id
239 'select_submit' => false, //submit on select: true/false
240 'async' => true, // select update via ajax (true) vs _page_body reload
241 'default' => '', // default value when $_POST is not set
242 // search box parameters
246 // ------ merge options with defaults ----------
248 $opts = array_merge($opts, $options);
249 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
250 $spec_id = $opts['spec_id'];
251 $spec_option = $opts['spec_option'];
252 $disabled = $opts['disabled'] ? "disabled" : '';
254 if ($selected_id == null) {
255 $selected_id = get_post($name, $opts['default']);
258 if (isset($_POST[$select_submit])) {
260 $Ajax->activate('_page_body');
262 $Ajax->activate($name);
265 // ------ make selector ----------
266 $selector = $first_opt = '';
269 //if($name=='SelectStockFromList') display_error($sql);
270 foreach($items as $value=>$descr) {
272 if ($selected_id == $value) {
276 if ($first_id === false) {
280 $selector .= "<option $sel value='$value'>$descr</option>\n";
283 // Prepend special option.
284 if ($spec_option !== false) { // if special option used - add it
285 $first_id = $spec_id;
286 $first_opt = $spec_option;
287 $sel = $found===false ? 'selected' : '';
288 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
292 if ($found === false) {
293 $_POST[$name] = $first_id;
296 $selector = "<select $disabled name='$name' class='combo' title='"
297 . $opts['sel_hint']."' >".$selector."</select>\n";
299 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
301 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
303 if ($select_submit != false) { // if submit on change is used - add select button
304 global $_select_button;
305 $selector .= sprintf($_select_button, $disabled, user_theme(),
306 (in_ajax() ? 'display:none;':''),
307 $select_submit)."\n";
309 default_focus($name);
314 //----------------------------------------------------------------------------------------------
316 function _format_add_curr($row)
318 static $company_currency;
320 if ($company_currency == null)
322 $company_currency = get_company_currency();
324 return $row[1] . ($row[2] == $company_currency ?
325 '' : (" - " . $row[2]));
328 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
332 $sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ";
334 $mode = get_company_pref('no_supplier_list');
336 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
338 'format' => '_format_add_curr',
339 'search_box' => $mode!=0,
341 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
342 'spec_id' => $all_items,
343 'select_submit'=> $submit_on_change,
345 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
350 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
353 echo "<td>$label</td><td>\n";
354 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change);
359 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
361 echo "<tr><td>$label</td><td>";
362 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
366 //----------------------------------------------------------------------------------------------
368 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
372 $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
374 $mode = get_company_pref('no_customer_list');
376 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
378 'format' => '_format_add_curr',
379 'search_box' => $mode!=0,
382 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
383 'spec_id' => $all_items,
384 'select_submit'=> $submit_on_change,
386 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
391 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
394 echo "<td>$label</td>\n";
396 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
401 function customer_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
403 echo "<tr><td>$label</td><td nowrap>";
404 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
405 echo "</td>\n</tr>\n";
409 //------------------------------------------------------------------------------------------------
411 function customer_branches_list($customer_id, $name, $selected_id=null,
412 $spec_option = true, $enabled=true, $submit_on_change=false)
416 $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
417 WHERE debtor_no='" . $customer_id . "' ";
419 $where = $enabled ? array("disable_trans = 0") : array();
420 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
423 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
424 'spec_id' => $all_items,
425 'select_submit'=> $submit_on_change,
426 'sel_hint' => _('Select customer branch')
429 //------------------------------------------------------------------------------------------------
431 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
434 echo "<td>$label</td>\n";
436 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
441 function customer_branches_list_row($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
444 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
449 //------------------------------------------------------------------------------------------------
451 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
455 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
457 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
459 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
460 'spec_id' => $all_items,
461 'select_submit'=> $submit_on_change
465 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
468 echo "<td>$label</td>\n";
470 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
475 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
478 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
483 //-----------------------------------------------------------------------------------------------
485 function currencies_list($name, $selected_id=null, $submit_on_change=false)
487 $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
489 // default to the company currency
491 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
493 'select_submit'=> $submit_on_change,
494 'default' => get_company_currency(),
499 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
502 echo "<td>$label</td>\n";
504 $str = currencies_list($name, $selected_id, $submit_on_change);
509 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
512 $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
517 //---------------------------------------------------------------------------------------------------
519 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
522 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
524 // default to the company current fiscal year
526 return combo_input($name, $selected_id, $sql, 'id', '',
529 'default' => get_company_pref('f_year'),
530 'format' => '_format_fiscalyears',
531 'select_submit'=> $submit_on_change,
536 function _format_fiscalyears($row)
538 return sql2date($row[1]) . " - " . sql2date($row[2])
539 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
542 function fiscalyears_list_cells($label, $name, $selected_id=null)
545 echo "<td>$label</td>\n";
547 $str = fiscalyears_list($name, $selected_id);
552 function fiscalyears_list_row($label, $name, $selected_id=null)
555 $str = fiscalyears_list_cells($label, $name, $selected_id);
559 //------------------------------------------------------------------------------------
561 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
562 $submit_on_change=false, $showclosed=false, $showtype=1)
564 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
567 'order' => 'reference',
568 'spec_option'=>$no_option ? $showname : false,
570 'select_submit'=> $submit_on_change,
575 $options['where'][] = "closed=0";
577 $options['where'][] = "type_=$showtype";
579 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
582 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
583 $showclosed=false, $showtype=0)
586 echo "<td>$label</td>\n";
588 $str = dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
593 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
594 $showclosed=false, $showtype=0)
597 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
598 $showclosed, $showtype);
603 //---------------------------------------------------------------------------------------------------
605 function stock_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $opts=array())
609 $sql = "SELECT stock_id, s.description, c.description
610 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
612 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
615 'format' => '_format_stock_items',
616 'spec_option' => $all_option===true ? _("All Items") : $all_option,
617 'spec_id' => $all_items,
618 'search_box' => true,
619 'search' => array("stock_id", "c.description","s.description"),
620 'search_submit' => get_company_pref('no_item_list')!=0,
622 'select_submit'=> $submit_on_change
626 function _format_stock_items($row)
628 return (user_show_codes() ? ($row[0] . " - ") : "")
629 . $row[2] . " - " . $row[1];
632 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
635 echo "<td>$label</td>\n";
636 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
637 array('cells'=>true));
641 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
644 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
649 //------------------------------------------------------------------------------------
651 function base_stock_items_list($where, $name, $selected_id=null,
652 $all_option=false, $submit_on_change=false)
656 $sql = "SELECT stock_id, s.description, c.description
657 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
658 s.category_id=c.category_id";
660 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
662 'format' => '_format_stock_items',
663 'spec_option' => $all_option==true ? _("All Items") : $all_option,
664 'spec_id' => $all_items,
665 'select_submit'=> $submit_on_change,
669 //------------------------------------------------------------------------------------
671 function stock_bom_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
674 return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
675 $name, $selected_id, $all_option, $submit_on_change);
678 function stock_bom_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
681 echo "<td>$label</td>\n";
683 $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
688 function stock_bom_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
691 $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
696 //------------------------------------------------------------------------------------
698 function stock_manufactured_items_list($name, $selected_id=null,
699 $all_option=false, $submit_on_change=false)
701 return base_stock_items_list("s.mb_flag='M'",
702 $name, $selected_id, $all_option, $submit_on_change);
705 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
706 $all_option=false, $submit_on_change=false)
709 echo "<td>$label</td>\n";
711 $str = stock_manufactured_items_list($name, $selected_id, $all_option,
717 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
718 $all_option=false, $submit_on_change=false)
721 $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
722 $all_option, $submit_on_change);
726 //------------------------------------------------------------------------------------
728 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
729 $all_option=false, $submit_on_change=false)
731 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
732 array('where'=>array("stock_id != '$parent_stock_id'")));
736 function stock_component_items_list_cells($label, $name, $parent_stock_id,
737 $selected_id=null, $all_option=false, $submit_on_change=false)
740 echo "<td>$label</td>\n";
741 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
742 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true));
745 //------------------------------------------------------------------------------------
747 function stock_costable_items_list($name, $selected_id=null,
748 $all_option=false, $submit_on_change=false)
750 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
751 array('where'=>array("mb_flag!='D'")));
755 function stock_costable_items_list_cells($label, $name, $selected_id=null,
756 $all_option=false, $submit_on_change=false)
759 echo "<td>$label</td>\n";
760 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
761 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
765 //------------------------------------------------------------------------------------
766 function stock_purchasable_items_list($name, $selected_id=null,
767 $all_option=false, $submit_on_change=false)
769 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
770 array('where'=>array("mb_flag!= 'M'")));
774 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
775 $all_option=false, $submit_on_change=false)
778 echo "<td>$label</td>\n";
779 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
780 array('where'=>array("mb_flag!= 'M'"), 'cells'=>true));
784 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
785 $all_option=false, $submit_on_change=false)
788 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
789 $all_option, $submit_on_change);
794 //------------------------------------------------------------------------------------
796 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
799 'M' => _("Manufactured"),
800 'B' => _("Purchased"),
806 echo "<td>$label</td>\n";
809 array_selector($name, $selected_id, $types,
811 'select_submit'=> true,
812 'disabled' => !$enabled) );
816 function stock_units_list_row($label, $name, $value=null, $enabled=true)
818 $result = get_all_item_units();
821 echo "<td>$label</td>\n";
824 while($unit = db_fetch($result))
825 $units[$unit['abbr']] = $unit['name'];
827 array_selector($name, $value, $units,
829 'select_submit'=> true,
830 'disabled' => !$enabled) );
835 //------------------------------------------------------------------------------------
837 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
839 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
841 return combo_input($name, $selected_id, $sql, 'id', 'name',
843 'spec_option' => $none_option,
844 'spec_id' => reserved_words::get_all_numeric(),
845 'select_submit'=> $submit_on_change,
850 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
851 $submit_on_change=false)
854 echo "<td>$label</td>\n";
856 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
861 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
862 $submit_on_change=false)
865 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
870 //------------------------------------------------------------------------------------
872 function tax_groups_list($name, $selected_id=null,
873 $none_option=false, $submit_on_change=false)
875 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
877 return combo_input($name, $selected_id, $sql, 'id', 'name',
880 'spec_option' => $none_option,
882 'select_submit'=> $submit_on_change,
887 function tax_groups_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
890 echo "<td>$label</td>\n";
892 $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
897 function tax_groups_list_row($label, $name, $selected_id=null, $submit_on_change=false)
900 $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
905 //------------------------------------------------------------------------------------
907 function item_tax_types_list($name, $selected_id=null)
909 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
910 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
913 function item_tax_types_list_cells($label, $name, $selected_id=null)
916 echo "<td>$label</td>\n";
918 item_tax_types_list($name, $selected_id);
922 function item_tax_types_list_row($label, $name, $selected_id=null)
925 item_tax_types_list_cells($label, $name, $selected_id);
929 //------------------------------------------------------------------------------------
931 function shippers_list($name, $selected_id=null)
933 $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
934 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
937 function shippers_list_cells($label, $name, $selected_id=null)
940 echo "<td>$label</td>\n";
942 shippers_list($name, $selected_id);
946 function shippers_list_row($label, $name, $selected_id=null)
949 shippers_list_cells($label, $name, $selected_id);
953 //-------------------------------------------------------------------------------------
955 function sales_persons_list($name, $selected_id=null)
957 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
958 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
961 function sales_persons_list_cells($label, $name, $selected_id=null)
964 echo "<td>$label</td>\n";
966 sales_persons_list($name, $selected_id);
970 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
973 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
977 //------------------------------------------------------------------------------------
979 function sales_areas_list($name, $selected_id=null)
981 $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
982 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
985 function sales_areas_list_cells($label, $name, $selected_id=null)
988 echo "<td>$label</td>\n";
990 sales_areas_list($name, $selected_id);
994 function sales_areas_list_row($label, $name, $selected_id=null)
997 sales_areas_list_cells($label, $name, $selected_id);
1001 //------------------------------------------------------------------------------------
1003 function workorders_list($name, $selected_id=null)
1005 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1006 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1009 function workorders_list_cells($label, $name, $selected_id=null)
1012 echo "<td>$label</td>\n";
1014 workorders_list($name, $selected_id);
1018 function workorders_list_row($label, $name, $selected_id=null)
1021 workorders_list_cells($label, $name, $selected_id);
1025 //------------------------------------------------------------------------------------
1027 function payment_terms_list($name, $selected_id=null)
1029 $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
1030 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1033 function payment_terms_list_cells($label, $name, $selected_id=null)
1036 echo "<td>$label</td>\n";
1038 payment_terms_list($name, $selected_id);
1042 function payment_terms_list_row($label, $name, $selected_id=null)
1045 payment_terms_list_cells($label, $name, $selected_id);
1049 //------------------------------------------------------------------------------------
1051 function credit_status_list($name, $selected_id=null)
1053 $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
1054 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1057 function credit_status_list_cells($label, $name, $selected_id=null)
1060 echo "<td>$label</td>\n";
1062 credit_status_list($name, $selected_id);
1066 function credit_status_list_row($label, $name, $selected_id=null)
1069 credit_status_list_cells($label, $name, $selected_id);
1073 //-----------------------------------------------------------------------------------------------
1075 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1077 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
1079 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1081 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1083 'select_submit'=> $submit_on_change,
1084 // 'async' => false,
1088 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1091 echo "<td>$label</td>\n";
1093 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1098 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1101 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1106 //-----------------------------------------------------------------------------------------------
1108 function movement_types_list($name, $selected_id=null)
1110 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1111 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1114 function movement_types_list_cells($label, $name, $selected_id=null)
1117 echo "<td>$label</td>\n";
1119 movement_types_list($name, $selected_id);
1123 function movement_types_list_row($label, $name, $selected_id=null)
1126 movement_types_list_cells($label, $name, $selected_id);
1130 //-----------------------------------------------------------------------------------------------
1132 function bank_trans_types_list($name, $selected_id=null)
1134 $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1135 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1138 function bank_trans_types_list_cells($label, $name, $selected_id=null)
1141 echo "<td>$label</td>\n";
1143 bank_trans_types_list($name, $selected_id);
1147 function bank_trans_types_list_row($label, $name, $selected_id=null)
1150 bank_trans_types_list_cells($label, $name, $selected_id);
1154 //-----------------------------------------------------------------------------------------------
1156 function workcenter_list($name, $selected_id=null, $all_option=false)
1160 $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1162 return combo_input($name, $selected_id, $sql, 'id', 'name',
1164 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1165 'spec_id' => $all_items,
1169 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1171 default_focus($name);
1173 echo "<td>$label</td>\n";
1175 workcenter_list($name, $selected_id, $all_option);
1179 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1182 workcenter_list_cells($label, $name, $selected_id, $all_option);
1186 //-----------------------------------------------------------------------------------------------
1188 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1190 $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1191 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1192 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1194 return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1196 'format' => '_format_add_curr',
1197 'select_submit'=> $submit_on_change,
1202 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1205 echo "<td>$label</td>\n";
1207 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1212 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1215 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1220 //-----------------------------------------------------------------------------------------------
1222 function class_list($name, $selected_id=null, $submit_on_change=false)
1224 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1226 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1228 'select_submit'=> $submit_on_change,
1234 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1237 echo "<td>$label</td>\n";
1239 $str = class_list($name, $selected_id, $submit_on_change);
1244 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1247 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1252 //-----------------------------------------------------------------------------------------------
1254 function stock_categories_list($name, $selected_id=null)
1256 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1257 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1258 array('order'=>'category_id'));
1261 function stock_categories_list_cells($label, $name, $selected_id=null)
1264 echo "<td>$label</td>\n";
1266 stock_categories_list($name, $selected_id);
1270 function stock_categories_list_row($label, $name, $selected_id=null)
1273 stock_categories_list_cells($label, $name, $selected_id);
1277 //-----------------------------------------------------------------------------------------------
1279 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1283 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1285 combo_input($name, $selected_id, $sql, 'id', 'name',
1288 'spec_option' =>$all_option,
1289 'spec_id' => $all_option_numeric ? 0 : $all_items
1293 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1294 $all_option_numeric=false)
1297 echo "<td>$label</td>\n";
1299 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1303 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1304 $all_option_numeric=false)
1307 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1308 $all_option_numeric);
1312 //-----------------------------------------------------------------------------------------------
1313 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1314 $show_group=false, $cells=false, $all_option=false, $submit_on_change=false)
1316 if ($skip_bank_accounts)
1317 $sql = "SELECT chart.account_code, chart.account_name, type.name
1318 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1319 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1320 ."ON chart.account_code=acc.account_code
1321 WHERE acc.account_code IS NULL
1322 AND chart.account_type=type.id";
1324 $sql = "SELECT chart.account_code, chart.account_name, type.name
1325 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1326 WHERE chart.account_type=type.id";
1328 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1330 'format' => '_format_account' . ($show_group ? '2' : ''),
1331 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1333 'order' => 'account_code',
1334 'search_box' => $cells,
1335 'search_submit' => false,
1339 'select_submit'=> $submit_on_change,
1345 function _format_account($row)
1347 return $row[0] . " " . $row[1];
1350 function _format_account2($row)
1352 return $row[0] . " " . $row[2] . " " . $row[1];
1355 function gl_all_accounts_list_cells($label, $name, $selected_id=null, $skip_bank_accounts=false,
1356 $show_group=false, $cells=false, $all_option=false)
1359 echo "<td>$label</td>\n";
1361 gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1365 function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_accounts=false,
1366 $show_group=false, $cells=false, $all_option=false)
1369 gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1370 $show_group, $cells, $all_option);
1374 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1377 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1378 $items['0'] = strlen($name_no) ? $name_no : _("No");
1380 return array_selector($name, $selected_id, $items,
1382 'select_submit'=> $submit_on_change,
1383 'async' => false ) ); // FIX?
1386 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1389 echo "<td>$label</td>\n";
1391 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1396 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1399 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1404 //------------------------------------------------------------------------------------------------
1406 function languages_list($name, $selected_id=null)
1408 global $installed_languages;
1411 foreach ($installed_languages as $lang)
1412 $items[$lang['code']] = $lang['name'];
1414 return array_selector($name, $selected_id, $items );
1417 function languages_list_cells($label, $name, $selected_id=null)
1420 echo "<td>$label</td>\n";
1422 languages_list($name, $selected_id);
1426 function languages_list_row($label, $name, $selected_id=null)
1429 languages_list_cells($label, $name, $selected_id);
1433 //------------------------------------------------------------------------------------------------
1435 function bank_account_types_list($name, $selected_id=null)
1437 $types = bank_account_types::get_all();
1440 foreach ($types as $type)
1442 $items[$type['id']] = $type['name'];
1445 return array_selector($name, $selected_id, $items );
1448 function bank_account_types_list_cells($label, $name, $selected_id=null)
1451 echo "<td>$label</td>\n";
1453 bank_account_types_list($name, $selected_id);
1457 function bank_account_types_list_row($label, $name, $selected_id=null)
1460 bank_account_types_list_cells($label, $name, $selected_id);
1464 //------------------------------------------------------------------------------------------------
1465 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1467 $types = payment_person_types::get_all();
1470 foreach ($types as $type)
1472 if (payment_person_types::has_items($type['id']))
1474 $items[$type['id']] = $type['name'];
1478 return array_selector($name, $selected_id, $items,
1479 array( 'select_submit'=> $submit_on_change ) );
1482 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1485 echo "<td>$label</td>\n";
1487 $str = payment_person_types_list($name, $selected_id, $related);
1492 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1495 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1500 //------------------------------------------------------------------------------------------------
1502 function wo_types_list($name, $selected_id=null)
1504 $types = wo_types::get_all();
1507 foreach ($types as $type)
1508 $items[$type['id']] = $type['name'];
1510 return array_selector($name, $selected_id, $items,
1511 array( 'select_submit'=> true, 'async' => true ) );
1514 function wo_types_list_row($label, $name, $selected_id=null)
1516 echo "<tr><td>$label</td><td>\n";
1517 $str = wo_types_list($name, $selected_id);
1518 echo "</td></tr>\n";
1522 //------------------------------------------------------------------------------------------------
1524 function dateformats_list_row($label, $name, $value=null)
1526 global $dateformats;
1528 echo "<tr><td>$label</td>\n<td>";
1529 array_selector( $name, $value, $dateformats );
1530 echo "</td></tr>\n";
1533 function dateseps_list_row($label, $name, $value=null)
1537 echo "<tr><td>$label</td>\n<td>";
1538 array_selector( $name, $value, $dateseps );
1539 echo "</td></tr>\n";
1542 function thoseps_list_row($label, $name, $value=null)
1546 echo "<tr><td>$label</td>\n<td>";
1547 array_selector( $name, $value, $thoseps );
1548 echo "</td></tr>\n";
1551 function decseps_list_row($label, $name, $value=null)
1555 echo "<tr><td>$label</td>\n<td>";
1556 array_selector( $name, $value, $decseps );
1557 echo "</td></tr>\n";
1560 function themes_list_row($label, $name, $value=null)
1562 global $path_to_root;
1564 $path = $path_to_root.'/themes/';
1566 $themedir = opendir($path);
1567 while(false !== ($fname = readdir($themedir)))
1569 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1571 $themes[$fname] = $fname;
1576 echo "<tr><td>$label</td>\n<td>";
1577 array_selector( $name, $value, $themes );
1578 echo "</td></tr>\n";
1581 function pagesizes_list_row($label, $name, $value=null)
1586 foreach ($pagesizes as $pz)
1589 echo "<tr><td>$label</td>\n<td>";
1590 array_selector( $name, $value, $items );
1591 echo "</td></tr>\n";
1594 function security_headings_list_row($label, $name, $value=null)
1596 global $security_headings;
1598 echo "<tr><td>$label</td>\n<td>";
1599 array_selector( $name, $value, $security_headings );
1600 echo "</td></tr>\n";
1603 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1605 global $systypes_array;
1608 echo "<td>$label</td>\n";
1612 foreach ($systypes_array as $key=>$type)
1613 $items[$key] = $type['name'];
1615 $str = array_selector($name, $value, $items,
1617 'select_submit'=> $submit_on_change,
1625 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1628 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1633 function cust_allocations_list_cells($label, $name, $selected=null)
1641 $all_items=>_("All Types"),
1642 '1'=> _("Sales Invoices"),
1643 '2'=> _("Overdue Invoices"),
1644 '3' => _("Payments"),
1645 '4' => _("Credit Notes"),
1646 '5' => _("Delivery Notes")
1648 $str = array_selector($name, $selected, $allocs);
1653 function supp_allocations_list_cell($name, $selected=null)
1659 $all_items=>_("All Types"),
1660 '1'=> _("Invoices"),
1661 '2'=> _("Overdue Invoices"),
1662 '3' => _("Payments"),
1663 '4' => _("Credit Notes"),
1664 '5' => _("Overdue Credit Notes")
1666 $str = array_selector($name, $selected, $allocs);
1671 function policy_list_cells($label, $name, $selected=null)
1676 $str = array_selector($name, $selected,
1677 array( '' => _("Automatically put balance on back order"),
1678 'CAN' => _("Cancel any quantites not delivered")) );
1683 function policy_list_row($label, $name, $selected=null)
1686 policy_list_cells($label, $name, $selected);
1690 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1695 $str = array_selector($name, $selected,
1696 array( 'Return' => _("Items Returned to Inventory Location"),
1697 'WriteOff' => _("Items Written Off")),
1698 array( 'select_submit'=> $submit_on_change ) );
1703 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1706 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1711 function number_list($name, $selected, $from, $to, $no_option=false)
1714 for ($i = $from; $i <= $to; $i++)
1717 return array_selector($name, $selected, $items,
1718 array( 'spec_option' => $no_option,
1719 'spec_id' => reserved_words::get_all_numeric()) );
1722 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1727 number_list($name, $selected, $from, $to, $no_option);
1731 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1734 number_list_cells($label, $name, $selected, $from, $to, $no_option);