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 ?
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])) {
88 if ($by_id) $txt = $_POST[$name];
91 $Ajax->activate('_page_body');
93 $Ajax->activate($name);
96 // search related sql modifications
98 $rel = "rel='$search_box'"; // set relation to list
99 if ($opts['search_submit']) {
100 if (isset($_POST[$search_submit])) {
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 ((string)($selected_id) === $value) {
146 if ($first_id === false) {
150 $selector .= "<option $sel value='$value'>$descr</option>\n";
152 db_free_result($result);
155 // Prepend special option.
156 if ($spec_option !== false) { // if special option used - add it
157 $first_id = $spec_id;
158 $first_opt = $spec_option;
159 $sel = $found===false ? 'selected' : '';
160 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
164 if ($found === false) {
165 $selected_id = $first_id;
167 $_POST[$name] = $selected_id;
169 if ($by_id && $search_box != false) {
170 $txt = $_POST[$name];
171 $Ajax->addUpdate($name, $search_box, $txt);
173 $selector = "<select $disabled name='$name' class='$class' title='"
174 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
176 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
178 // because of bug which M$ cannot fix since IE 5.0
179 // we must embed whole selector in span tags to enable proper ajax update
180 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
182 if ($select_submit != false) { // if submit on change is used - add select button
183 global $_select_button;
184 // button class selects form reload/ajax selector update
185 $selector .= sprintf($_select_button, $disabled, user_theme(),
186 (in_ajax() ? 'display:none;':''),
187 $select_submit)."\n";
189 // ------ make combo ----------
192 if ($search_box != false) {
193 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
194 $opts['size']."' maxlength='".$opts['max'].
195 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
196 .$opts['box_hint']."'"
197 .(in_ajax() && !$by_id ? " style=display:none;":'')
199 if ($search_submit != false) {
200 global $_search_button;
201 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
202 (in_ajax() ? 'display:none;':''),
203 $search_submit)."\n";
206 default_focus($name);
208 if ($search_box && $opts['cells'])
209 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
211 echo $edit_entry.$selector;
215 //----------------------------------------------------------------------------------------------
216 // Universal array combo generator
217 // $items is array of options 'value' => 'description'
218 // Options is reduced set of combo_selector options and is merged with defaults.
220 function array_selector($name, $selected_id, $items, $options=null)
224 $opts = array( // default options
225 'spec_option'=>false, // option text or false
226 'spec_id' => 0, // option id
227 'select_submit' => false, //submit on select: true/false
228 'async' => true, // select update via ajax (true) vs _page_body reload
229 'default' => '', // default value when $_POST is not set
230 // search box parameters
234 // ------ merge options with defaults ----------
236 $opts = array_merge($opts, $options);
237 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
238 $spec_id = $opts['spec_id'];
239 $spec_option = $opts['spec_option'];
240 $disabled = $opts['disabled'] ? "disabled" : '';
242 if ($selected_id == null) {
243 $selected_id = get_post($name, $opts['default']);
246 if (isset($_POST[$select_submit])) {
248 $Ajax->activate('_page_body');
250 $Ajax->activate($name);
253 // ------ make selector ----------
254 $selector = $first_opt = '';
257 //if($name=='SelectStockFromList') display_error($sql);
258 foreach($items as $value=>$descr) {
260 if ($selected_id == $value) {
264 if ($first_id === false) {
268 $selector .= "<option $sel value='$value'>$descr</option>\n";
271 // Prepend special option.
272 if ($spec_option !== false) { // if special option used - add it
273 $first_id = $spec_id;
274 $first_opt = $spec_option;
275 $sel = $found===false ? 'selected' : '';
276 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
280 if ($found === false) {
281 $_POST[$name] = $first_id;
284 $selector = "<select $disabled name='$name' class='combo' title='"
285 . $opts['sel_hint']."' >".$selector."</select>\n";
287 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
289 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
291 if ($select_submit != false) { // if submit on change is used - add select button
292 global $_select_button;
293 $selector .= sprintf($_select_button, $disabled, user_theme(),
294 (in_ajax() ? 'display:none;':''),
295 $select_submit)."\n";
297 default_focus($name);
302 //----------------------------------------------------------------------------------------------
304 function _format_add_curr($row)
306 static $company_currency;
308 if ($company_currency == null)
310 $company_currency = get_company_currency();
312 return $row[1] . ($row[2] == $company_currency ?
313 '' : (" - " . $row[2]));
316 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
320 $sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ";
322 $mode = get_company_pref('no_supplier_list');
324 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
326 'format' => '_format_add_curr',
327 'search_box' => $mode!=0,
329 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
330 'spec_id' => $all_items,
331 'select_submit'=> $submit_on_change,
333 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
338 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
341 echo "<td>$label</td><td>\n";
342 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change);
347 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
349 echo "<tr><td>$label</td><td>";
350 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
354 //----------------------------------------------------------------------------------------------
356 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
360 $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
362 $mode = get_company_pref('no_customer_list');
364 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
366 'format' => '_format_add_curr',
367 'search_box' => $mode!=0,
370 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
371 'spec_id' => $all_items,
372 'select_submit'=> $submit_on_change,
374 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
379 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
382 echo "<td>$label</td>\n";
384 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
389 function customer_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
391 echo "<tr><td>$label</td><td nowrap>";
392 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
393 echo "</td>\n</tr>\n";
397 //------------------------------------------------------------------------------------------------
399 function customer_branches_list($customer_id, $name, $selected_id=null,
400 $spec_option = true, $enabled=true, $submit_on_change=false)
404 $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
405 WHERE debtor_no='" . $customer_id . "' ";
407 $where = $enabled ? array("disable_trans = 0") : array();
408 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
411 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
412 'spec_id' => $all_items,
413 'select_submit'=> $submit_on_change,
414 'sel_hint' => _('Select customer branch')
417 //------------------------------------------------------------------------------------------------
419 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
422 echo "<td>$label</td>\n";
424 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
429 function customer_branches_list_row($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
432 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
437 //------------------------------------------------------------------------------------------------
439 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
443 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
445 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
447 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
448 'spec_id' => $all_items,
449 'select_submit'=> $submit_on_change
453 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
456 echo "<td>$label</td>\n";
458 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
463 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
466 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
471 //-----------------------------------------------------------------------------------------------
473 function currencies_list($name, $selected_id=null, $submit_on_change=false)
475 $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
477 // default to the company currency
479 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
481 'select_submit'=> $submit_on_change,
482 'default' => get_company_currency(),
487 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
490 echo "<td>$label</td>\n";
492 $str = currencies_list($name, $selected_id, $submit_on_change);
497 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
500 $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
505 //---------------------------------------------------------------------------------------------------
507 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
510 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
512 // default to the company current fiscal year
514 return combo_input($name, $selected_id, $sql, 'id', '',
517 'default' => get_company_pref('f_year'),
518 'format' => '_format_fiscalyears',
519 'select_submit'=> $submit_on_change,
524 function _format_fiscalyears($row)
526 return sql2date($row[1]) . " - " . sql2date($row[2])
527 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
530 function fiscalyears_list_cells($label, $name, $selected_id=null)
533 echo "<td>$label</td>\n";
535 $str = fiscalyears_list($name, $selected_id);
540 function fiscalyears_list_row($label, $name, $selected_id=null)
543 $str = fiscalyears_list_cells($label, $name, $selected_id);
547 //------------------------------------------------------------------------------------
549 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
550 $submit_on_change=false, $showclosed=false, $showtype=1)
552 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
555 'order' => 'reference',
556 'spec_option'=>$no_option ? $showname : false,
558 'select_submit'=> $submit_on_change,
563 $options['where'][] = "closed=0";
565 $options['where'][] = "type_=$showtype";
567 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
570 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
571 $showclosed=false, $showtype=0)
574 echo "<td>$label</td>\n";
576 $str = dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
581 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
582 $showclosed=false, $showtype=0)
585 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
586 $showclosed, $showtype);
591 //---------------------------------------------------------------------------------------------------
593 function stock_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $opts=array())
597 $sql = "SELECT stock_id, s.description, c.description
598 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
600 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
603 'format' => '_format_stock_items',
604 'spec_option' => $all_option===true ? _("All Items") : $all_option,
605 'spec_id' => $all_items,
606 'search_box' => true,
607 'search' => array("stock_id", "c.description","s.description"),
608 'search_submit' => get_company_pref('no_item_list')!=0,
610 'select_submit'=> $submit_on_change
614 function _format_stock_items($row)
616 return (user_show_codes() ? ($row[0] . " - ") : "")
617 . $row[2] . " - " . $row[1];
620 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
623 echo "<td>$label</td>\n";
624 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
625 array('cells'=>true));
629 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
632 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
637 //------------------------------------------------------------------------------------
639 function base_stock_items_list($where, $name, $selected_id=null,
640 $all_option=false, $submit_on_change=false)
644 $sql = "SELECT stock_id, s.description, c.description
645 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
646 s.category_id=c.category_id";
648 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
650 'format' => '_format_stock_items',
651 'spec_option' => $all_option==true ? _("All Items") : $all_option,
652 'spec_id' => $all_items,
653 'select_submit'=> $submit_on_change,
657 //------------------------------------------------------------------------------------
659 function stock_bom_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
662 return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
663 $name, $selected_id, $all_option, $submit_on_change);
666 function stock_bom_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
669 echo "<td>$label</td>\n";
671 $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
676 function stock_bom_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
679 $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
684 //------------------------------------------------------------------------------------
686 function stock_manufactured_items_list($name, $selected_id=null,
687 $all_option=false, $submit_on_change=false)
689 return base_stock_items_list("s.mb_flag='M'",
690 $name, $selected_id, $all_option, $submit_on_change);
693 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
694 $all_option=false, $submit_on_change=false)
697 echo "<td>$label</td>\n";
699 $str = stock_manufactured_items_list($name, $selected_id, $all_option,
705 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
706 $all_option=false, $submit_on_change=false)
709 $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
710 $all_option, $submit_on_change);
714 //------------------------------------------------------------------------------------
716 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
717 $all_option=false, $submit_on_change=false)
719 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
720 array('where'=>array("stock_id != '$parent_stock_id'")));
724 function stock_component_items_list_cells($label, $name, $parent_stock_id,
725 $selected_id=null, $all_option=false, $submit_on_change=false)
728 echo "<td>$label</td>\n";
729 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
730 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true));
733 //------------------------------------------------------------------------------------
735 function stock_costable_items_list($name, $selected_id=null,
736 $all_option=false, $submit_on_change=false)
738 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
739 array('where'=>array("mb_flag!='D'")));
743 function stock_costable_items_list_cells($label, $name, $selected_id=null,
744 $all_option=false, $submit_on_change=false)
747 echo "<td>$label</td>\n";
748 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
749 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
753 //------------------------------------------------------------------------------------
754 function stock_purchasable_items_list($name, $selected_id=null,
755 $all_option=false, $submit_on_change=false)
757 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
758 array('where'=>array("mb_flag!= 'M'")));
762 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
763 $all_option=false, $submit_on_change=false)
766 echo "<td>$label</td>\n";
767 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
768 array('where'=>array("mb_flag!= 'M'"), 'cells'=>true));
772 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
773 $all_option=false, $submit_on_change=false)
776 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
777 $all_option, $submit_on_change);
782 //------------------------------------------------------------------------------------
784 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
787 'M' => _("Manufactured"),
788 'B' => _("Purchased"),
794 echo "<td>$label</td>\n";
797 array_selector($name, $selected_id, $types,
799 'select_submit'=> true,
800 'disabled' => !$enabled) );
804 function stock_units_list_row($label, $name, $value=null, $enabled=true)
806 $result = get_all_item_units();
809 echo "<td>$label</td>\n";
812 while($unit = db_fetch($result))
813 $units[$unit['abbr']] = $unit['name'];
815 array_selector($name, $value, $units,
817 'select_submit'=> true,
818 'disabled' => !$enabled) );
823 //------------------------------------------------------------------------------------
825 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
827 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
829 return combo_input($name, $selected_id, $sql, 'id', 'name',
831 'spec_option' => $none_option,
832 'spec_id' => reserved_words::get_all_numeric(),
833 'select_submit'=> $submit_on_change,
838 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
839 $submit_on_change=false)
842 echo "<td>$label</td>\n";
844 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
849 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
850 $submit_on_change=false)
853 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
858 //------------------------------------------------------------------------------------
860 function tax_groups_list($name, $selected_id=null,
861 $none_option=false, $submit_on_change=false)
863 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
865 return combo_input($name, $selected_id, $sql, 'id', 'name',
868 'spec_option' => $none_option,
870 'select_submit'=> $submit_on_change,
875 function tax_groups_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
878 echo "<td>$label</td>\n";
880 $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
885 function tax_groups_list_row($label, $name, $selected_id=null, $submit_on_change=false)
888 $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
893 //------------------------------------------------------------------------------------
895 function item_tax_types_list($name, $selected_id=null)
897 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
898 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
901 function item_tax_types_list_cells($label, $name, $selected_id=null)
904 echo "<td>$label</td>\n";
906 item_tax_types_list($name, $selected_id);
910 function item_tax_types_list_row($label, $name, $selected_id=null)
913 item_tax_types_list_cells($label, $name, $selected_id);
917 //------------------------------------------------------------------------------------
919 function shippers_list($name, $selected_id=null)
921 $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
922 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
925 function shippers_list_cells($label, $name, $selected_id=null)
928 echo "<td>$label</td>\n";
930 shippers_list($name, $selected_id);
934 function shippers_list_row($label, $name, $selected_id=null)
937 shippers_list_cells($label, $name, $selected_id);
941 //-------------------------------------------------------------------------------------
943 function sales_persons_list($name, $selected_id=null)
945 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
946 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
949 function sales_persons_list_cells($label, $name, $selected_id=null)
952 echo "<td>$label</td>\n";
954 sales_persons_list($name, $selected_id);
958 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
961 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
965 //------------------------------------------------------------------------------------
967 function sales_areas_list($name, $selected_id=null)
969 $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
970 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
973 function sales_areas_list_cells($label, $name, $selected_id=null)
976 echo "<td>$label</td>\n";
978 sales_areas_list($name, $selected_id);
982 function sales_areas_list_row($label, $name, $selected_id=null)
985 sales_areas_list_cells($label, $name, $selected_id);
989 //------------------------------------------------------------------------------------
991 function workorders_list($name, $selected_id=null)
993 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
994 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
997 function workorders_list_cells($label, $name, $selected_id=null)
1000 echo "<td>$label</td>\n";
1002 workorders_list($name, $selected_id);
1006 function workorders_list_row($label, $name, $selected_id=null)
1009 workorders_list_cells($label, $name, $selected_id);
1013 //------------------------------------------------------------------------------------
1015 function payment_terms_list($name, $selected_id=null)
1017 $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
1018 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1021 function payment_terms_list_cells($label, $name, $selected_id=null)
1024 echo "<td>$label</td>\n";
1026 payment_terms_list($name, $selected_id);
1030 function payment_terms_list_row($label, $name, $selected_id=null)
1033 payment_terms_list_cells($label, $name, $selected_id);
1037 //------------------------------------------------------------------------------------
1039 function credit_status_list($name, $selected_id=null)
1041 $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
1042 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1045 function credit_status_list_cells($label, $name, $selected_id=null)
1048 echo "<td>$label</td>\n";
1050 credit_status_list($name, $selected_id);
1054 function credit_status_list_row($label, $name, $selected_id=null)
1057 credit_status_list_cells($label, $name, $selected_id);
1061 //-----------------------------------------------------------------------------------------------
1063 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1065 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
1067 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1069 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1071 'select_submit'=> $submit_on_change,
1072 // 'async' => false,
1076 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1079 echo "<td>$label</td>\n";
1081 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1086 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1089 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1094 //-----------------------------------------------------------------------------------------------
1096 function movement_types_list($name, $selected_id=null)
1098 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1099 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1102 function movement_types_list_cells($label, $name, $selected_id=null)
1105 echo "<td>$label</td>\n";
1107 movement_types_list($name, $selected_id);
1111 function movement_types_list_row($label, $name, $selected_id=null)
1114 movement_types_list_cells($label, $name, $selected_id);
1118 //-----------------------------------------------------------------------------------------------
1120 function bank_trans_types_list($name, $selected_id=null)
1122 $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1123 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1126 function bank_trans_types_list_cells($label, $name, $selected_id=null)
1129 echo "<td>$label</td>\n";
1131 bank_trans_types_list($name, $selected_id);
1135 function bank_trans_types_list_row($label, $name, $selected_id=null)
1138 bank_trans_types_list_cells($label, $name, $selected_id);
1142 //-----------------------------------------------------------------------------------------------
1144 function workcenter_list($name, $selected_id=null, $all_option=false)
1148 $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1150 return combo_input($name, $selected_id, $sql, 'id', 'name',
1152 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1153 'spec_id' => $all_items,
1157 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1159 default_focus($name);
1161 echo "<td>$label</td>\n";
1163 workcenter_list($name, $selected_id, $all_option);
1167 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1170 workcenter_list_cells($label, $name, $selected_id, $all_option);
1174 //-----------------------------------------------------------------------------------------------
1176 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1178 $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1179 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1180 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1182 return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1184 'format' => '_format_add_curr',
1185 'select_submit'=> $submit_on_change,
1190 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1193 echo "<td>$label</td>\n";
1195 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1200 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1203 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1208 //-----------------------------------------------------------------------------------------------
1210 function class_list($name, $selected_id=null, $submit_on_change=false)
1212 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1214 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1216 'select_submit'=> $submit_on_change,
1222 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1225 echo "<td>$label</td>\n";
1227 $str = class_list($name, $selected_id, $submit_on_change);
1232 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1235 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1240 //-----------------------------------------------------------------------------------------------
1242 function stock_categories_list($name, $selected_id=null)
1244 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1245 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1246 array('order'=>'category_id'));
1249 function stock_categories_list_cells($label, $name, $selected_id=null)
1252 echo "<td>$label</td>\n";
1254 stock_categories_list($name, $selected_id);
1258 function stock_categories_list_row($label, $name, $selected_id=null)
1261 stock_categories_list_cells($label, $name, $selected_id);
1265 //-----------------------------------------------------------------------------------------------
1267 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1271 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1273 combo_input($name, $selected_id, $sql, 'id', 'name',
1276 'spec_option' =>$all_option,
1277 'spec_id' => $all_option_numeric ? 0 : $all_items
1281 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1282 $all_option_numeric=false)
1285 echo "<td>$label</td>\n";
1287 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1291 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1292 $all_option_numeric=false)
1295 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1296 $all_option_numeric);
1300 //-----------------------------------------------------------------------------------------------
1301 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1302 $show_group=false, $cells=false, $all_option=false, $submit_on_change=false)
1304 if ($skip_bank_accounts)
1305 $sql = "SELECT chart.account_code, chart.account_name, type.name
1306 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1307 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1308 ."ON chart.account_code=acc.account_code
1309 WHERE acc.account_code IS NULL
1310 AND chart.account_type=type.id";
1312 $sql = "SELECT chart.account_code, chart.account_name, type.name
1313 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1314 WHERE chart.account_type=type.id";
1316 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1318 'format' => '_format_account' . ($show_group ? '2' : ''),
1319 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1321 'order' => 'account_code',
1322 'search_box' => $cells,
1323 'search_submit' => false,
1327 'select_submit'=> $submit_on_change,
1333 function _format_account($row)
1335 return $row[0] . " " . $row[1];
1338 function _format_account2($row)
1340 return $row[0] . " " . $row[2] . " " . $row[1];
1343 function gl_all_accounts_list_cells($label, $name, $selected_id=null, $skip_bank_accounts=false,
1344 $show_group=false, $cells=false, $all_option=false)
1347 echo "<td>$label</td>\n";
1349 gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1353 function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_accounts=false,
1354 $show_group=false, $cells=false, $all_option=false)
1357 gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1358 $show_group, $cells, $all_option);
1362 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1365 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1366 $items['0'] = strlen($name_no) ? $name_no : _("No");
1368 return array_selector($name, $selected_id, $items,
1370 'select_submit'=> $submit_on_change,
1371 'async' => false ) ); // FIX?
1374 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1377 echo "<td>$label</td>\n";
1379 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1384 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1387 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1392 //------------------------------------------------------------------------------------------------
1394 function languages_list($name, $selected_id=null)
1396 global $installed_languages;
1399 foreach ($installed_languages as $lang)
1400 $items[$lang['code']] = $lang['name'];
1402 return array_selector($name, $selected_id, $items );
1405 function languages_list_cells($label, $name, $selected_id=null)
1408 echo "<td>$label</td>\n";
1410 languages_list($name, $selected_id);
1414 function languages_list_row($label, $name, $selected_id=null)
1417 languages_list_cells($label, $name, $selected_id);
1421 //------------------------------------------------------------------------------------------------
1423 function bank_account_types_list($name, $selected_id=null)
1425 $types = bank_account_types::get_all();
1428 foreach ($types as $type)
1430 $items[$type['id']] = $type['name'];
1433 return array_selector($name, $selected_id, $items );
1436 function bank_account_types_list_cells($label, $name, $selected_id=null)
1439 echo "<td>$label</td>\n";
1441 bank_account_types_list($name, $selected_id);
1445 function bank_account_types_list_row($label, $name, $selected_id=null)
1448 bank_account_types_list_cells($label, $name, $selected_id);
1452 //------------------------------------------------------------------------------------------------
1453 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1455 $types = payment_person_types::get_all();
1458 foreach ($types as $type)
1460 if (payment_person_types::has_items($type['id']))
1462 $items[$type['id']] = $type['name'];
1466 return array_selector($name, $selected_id, $items,
1467 array( 'select_submit'=> $submit_on_change ) );
1470 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1473 echo "<td>$label</td>\n";
1475 $str = payment_person_types_list($name, $selected_id, $related);
1480 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1483 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1488 //------------------------------------------------------------------------------------------------
1490 function wo_types_list($name, $selected_id=null)
1492 $types = wo_types::get_all();
1495 foreach ($types as $type)
1496 $items[$type['id']] = $type['name'];
1498 return array_selector($name, $selected_id, $items,
1499 array( 'select_submit'=> true, 'async' => true ) );
1502 function wo_types_list_row($label, $name, $selected_id=null)
1504 echo "<tr><td>$label</td><td>\n";
1505 $str = wo_types_list($name, $selected_id);
1506 echo "</td></tr>\n";
1510 //------------------------------------------------------------------------------------------------
1512 function dateformats_list_row($label, $name, $value=null)
1514 global $dateformats;
1516 echo "<tr><td>$label</td>\n<td>";
1517 array_selector( $name, $value, $dateformats );
1518 echo "</td></tr>\n";
1521 function dateseps_list_row($label, $name, $value=null)
1525 echo "<tr><td>$label</td>\n<td>";
1526 array_selector( $name, $value, $dateseps );
1527 echo "</td></tr>\n";
1530 function thoseps_list_row($label, $name, $value=null)
1534 echo "<tr><td>$label</td>\n<td>";
1535 array_selector( $name, $value, $thoseps );
1536 echo "</td></tr>\n";
1539 function decseps_list_row($label, $name, $value=null)
1543 echo "<tr><td>$label</td>\n<td>";
1544 array_selector( $name, $value, $decseps );
1545 echo "</td></tr>\n";
1548 function themes_list_row($label, $name, $value=null)
1550 global $path_to_root;
1552 $path = $path_to_root.'/themes/';
1554 $themedir = opendir($path);
1555 while(false !== ($fname = readdir($themedir)))
1557 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1559 $themes[$fname] = $fname;
1564 echo "<tr><td>$label</td>\n<td>";
1565 array_selector( $name, $value, $themes );
1566 echo "</td></tr>\n";
1569 function pagesizes_list_row($label, $name, $value=null)
1574 foreach ($pagesizes as $pz)
1577 echo "<tr><td>$label</td>\n<td>";
1578 array_selector( $name, $value, $items );
1579 echo "</td></tr>\n";
1582 function security_headings_list_row($label, $name, $value=null)
1584 global $security_headings;
1586 echo "<tr><td>$label</td>\n<td>";
1587 array_selector( $name, $value, $security_headings );
1588 echo "</td></tr>\n";
1591 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1593 global $systypes_array;
1596 echo "<td>$label</td>\n";
1600 foreach ($systypes_array as $key=>$type)
1601 $items[$key] = $type['name'];
1603 $str = array_selector($name, $value, $items,
1605 'select_submit'=> $submit_on_change,
1613 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1616 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1621 function cust_allocations_list_cells($label, $name, $selected=null)
1629 $all_items=>_("All Types"),
1630 '1'=> _("Sales Invoices"),
1631 '2'=> _("Overdue Invoices"),
1632 '3' => _("Payments"),
1633 '4' => _("Credit Notes"),
1634 '5' => _("Delivery Notes")
1636 $str = array_selector($name, $selected, $allocs);
1641 function supp_allocations_list_cell($name, $selected=null)
1647 $all_items=>_("All Types"),
1648 '1'=> _("Invoices"),
1649 '2'=> _("Overdue Invoices"),
1650 '3' => _("Payments"),
1651 '4' => _("Credit Notes"),
1652 '5' => _("Overdue Credit Notes")
1654 $str = array_selector($name, $selected, $allocs);
1659 function policy_list_cells($label, $name, $selected=null)
1664 $str = array_selector($name, $selected,
1665 array( '' => _("Automatically put balance on back order"),
1666 'CAN' => _("Cancel any quantites not delivered")) );
1671 function policy_list_row($label, $name, $selected=null)
1674 policy_list_cells($label, $name, $selected);
1678 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1683 $str = array_selector($name, $selected,
1684 array( 'Return' => _("Items Returned to Inventory Location"),
1685 'WriteOff' => _("Items Written Off")),
1686 array( 'select_submit'=> $submit_on_change ) );
1691 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1694 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1699 function number_list($name, $selected, $from, $to, $no_option=false)
1702 for ($i = $from; $i <= $to; $i++)
1705 return array_selector($name, $selected, $items,
1706 array( 'spec_option' => $no_option,
1707 'spec_id' => reserved_words::get_all_numeric()) );
1710 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1715 number_list($name, $selected, $from, $to, $no_option);
1719 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1722 number_list_cells($label, $name, $selected, $from, $to, $no_option);