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' fallback='1' 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' fallback='1' 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 'select_submit' => false, //submit on select: true/false
34 'async' => true, // select update via ajax (true) vs _page_body reload
35 // search box parameters
37 'search_box' => false, // name or true/false
38 'type' => 0, // type of extended selector:
39 // 0 - with (optional) visible search box, search by id
40 // 1 - with hidden search box, search by option text
41 // 2 - TODO reverse: box with hidden selector available via enter; this
42 // would be convenient for optional ad hoc adding of new item
43 'search_submit' => true, //search submit button: true/false
44 'size' => 8, // size and max of box tag
46 'cells' => false, // combo displayed as 2 <td></td> cells
47 'search' => array(), // sql field names to search
48 'format' => null, // format functions for regular options
50 'box_hint' => null // box/selectors hints; null = std see below
52 // ------ merge options with defaults ----------
53 $opts = array_merge($opts, $options);
54 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
56 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
57 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
58 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
59 $spec_id = $opts['spec_id'];
60 $spec_option = $opts['spec_option'];
61 $by_id = ($opts['type'] == 0);
62 $class = $by_id ? 'combo':'combo2';
63 $disabled = $opts['disabled'] ? "disabled" : '';
65 if(!count($opts['search'])) {
66 $opts['search'] = array($by_id ? $valfield : $namefield);
68 if ($opts['sel_hint'] === null)
69 $opts['sel_hint'] = $by_id || $search_box==false ?
70 '' : _('Press Space tab for search pattern entry');
72 if ($opts['box_hint'] === null)
73 $opts['box_hint'] = $search_box ?
74 ($by_id ? _('Enter code fragment to search or * for all')
75 : _('Enter description fragment to search or * for all')) :'';
77 if ($selected_id == null) {
78 $selected_id = get_post($name, null);
80 $txt = get_post($search_box);
84 if (isset($_POST[$select_submit])) {
86 if ($by_id) $txt = $_POST[$name];
89 $Ajax->activate('_page_body');
91 $Ajax->activate($name);
94 // search related sql modifications
96 $rel = "rel='$search_box'"; // set relation to list
97 if ($opts['search_submit']) {
98 if (isset($_POST[$search_submit])) {
100 $Ajax->activate('_page_body');
102 $Ajax->activate($name);
105 if ($spec_option === false && $selected_id==null)
108 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
113 foreach($opts['search'] as $i=> $s)
114 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
115 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
120 if (count($opts['where'])) {
121 $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
122 $sql .= '('. implode($opts['where'], ' AND ') . ')';
124 if ($opts['order'] != false) {
125 $sql .= ' ORDER BY '.$opts['order'];
129 // ------ make selector ----------
130 $selector = $first_opt = '';
133 //if($name=='SelectStockFromList') display_error($sql);
134 if($result = db_query($sql)) {
135 while ($contact_row = db_fetch($result)) {
136 $value = $contact_row[0];
137 $descr = $opts['format']==null ? $contact_row[1] :
138 call_user_func($opts['format'], $contact_row);
140 if ((string)($selected_id) === $value) {
144 if ($first_id === false) {
148 $selector .= "<option $sel value='$value'>$descr</option>\n";
150 db_free_result($result);
153 // Prepend special option.
154 if ($spec_option !== false) { // if special option used - add it
155 $first_id = $spec_id;
156 $first_opt = $spec_option;
157 $sel = $found===false ? 'selected' : '';
158 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
162 if ($found === false) {
163 $_POST[$name] = $first_id;
167 $txt = $_POST[$name];
169 $Ajax->addUpdate($name, $search_box, $txt);
172 $selector = "<select $disabled name='$name' class='$class' title='"
173 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
175 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
177 // because of bug which M$ cannot fix since IE 5.0
178 // we must embed whole selector in span tags to enable proper ajax update
179 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
181 if ($select_submit != false) { // if submit on change is used - add select button
182 global $_select_button;
183 // button class selects form reload/ajax selector update
184 $selector .= sprintf($_select_button, $disabled, user_theme(),
185 (in_ajax() ? 'display:none;':''),
186 $select_submit)."\n";
188 // ------ make combo ----------
191 if ($search_box != false) {
192 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
193 $opts['size']."' maxlength='".$opts['max'].
194 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
195 .$opts['box_hint']."'"
196 .(in_ajax() && !$by_id ? " style=display:none;":'')
198 if ($search_submit != false) {
199 global $_search_button;
200 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
201 (in_ajax() ? 'display:none;':''),
202 $search_submit)."\n";
205 default_focus($name);
207 if ($search_box && $opts['cells'])
208 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
210 echo $edit_entry.$selector;
214 //----------------------------------------------------------------------------------------------
215 // Universal array combo generator
216 // $items is array of options 'value' => 'description'
217 // Options is reduced set of combo_selector options and is merged with defaults.
219 function array_selector($name, $selected_id, $items, $options=null)
223 $opts = array( // default options
224 'spec_option'=>false, // option text or false
225 'spec_id' => 0, // option id
226 'select_submit' => false, //submit on select: true/false
227 'async' => true, // select update via ajax (true) vs _page_body reload
228 // search box parameters
232 // ------ merge options with defaults ----------
233 $opts = array_merge($opts, $options);
234 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
235 $spec_id = $opts['spec_id'];
236 $spec_option = $opts['spec_option'];
237 $disabled = $opts['disabled'] ? "disabled" : '';
239 if ($selected_id == null) {
240 $selected_id = get_post($name, null);
243 if (isset($_POST[$select_submit])) {
245 $Ajax->activate('_page_body');
247 $Ajax->activate($name);
250 // ------ make selector ----------
251 $selector = $first_opt = '';
254 //if($name=='SelectStockFromList') display_error($sql);
255 foreach($items as $value=>$descr) {
257 if ($selected_id == $value) {
261 if ($first_id === false) {
265 $selector .= "<option $sel value='$value'>$descr</option>\n";
268 // Prepend special option.
269 if ($spec_option !== false) { // if special option used - add it
270 $first_id = $spec_id;
271 $first_opt = $spec_option;
272 $sel = $found===false ? 'selected' : '';
273 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
277 if ($found === false) {
278 $_POST[$name] = $first_id;
281 $selector = "<select $disabled name='$name' class='combo' title='"
282 . $opts['sel_hint']."' >".$selector."</select>\n";
284 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
286 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
288 if ($select_submit != false) { // if submit on change is used - add select button
289 global $_select_button;
290 $selector .= sprintf($_select_button, $disabled, user_theme(),
291 (in_ajax() ? 'display:none;':''),
292 $select_submit)."\n";
294 default_focus($name);
299 //----------------------------------------------------------------------------------------------
301 function _format_add_curr($row)
303 static $company_currency;
305 if ($company_currency == null)
307 $company_currency = get_company_currency();
309 return $row[1] . ($row[2] == $company_currency ?
310 '' : (" - " . $row[2]));
313 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
317 $sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ";
319 $mode = get_company_pref('no_supplier_list');
321 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
323 'format' => '_format_add_curr',
324 'search_box' => $mode!=0,
326 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
327 'spec_id' => $all_items,
328 'select_submit'=> $submit_on_change,
330 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
335 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
338 echo "<td>$label</td><td>\n";
339 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change);
344 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
346 echo "<tr><td>$label</td><td>";
347 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
351 //----------------------------------------------------------------------------------------------
353 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
357 $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
359 $mode = get_company_pref('no_customer_list');
361 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
363 'format' => '_format_add_curr',
364 'search_box' => $mode!=0,
367 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
368 'spec_id' => $all_items,
369 'select_submit'=> $submit_on_change,
371 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
376 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
379 echo "<td>$label</td>\n";
381 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
386 function customer_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
388 echo "<tr><td>$label</td><td nowrap>";
389 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
390 echo "</td>\n</tr>\n";
394 //------------------------------------------------------------------------------------------------
396 function customer_branches_list($customer_id, $name, $selected_id=null,
397 $spec_option = true, $enabled=true, $submit_on_change=false)
401 $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
402 WHERE debtor_no='" . $customer_id . "' ";
404 $where = $enabled ? array("disable_trans = 0") : array();
405 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
408 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
409 'spec_id' => $all_items,
410 'select_submit'=> $submit_on_change,
411 'sel_hint' => _('Select customer branch')
414 //------------------------------------------------------------------------------------------------
416 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
419 echo "<td>$label</td>\n";
421 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
426 function customer_branches_list_row($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
429 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
434 //------------------------------------------------------------------------------------------------
436 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
440 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
442 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
444 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
445 'spec_id' => $all_items,
446 'select_submit'=> $submit_on_change
450 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
453 echo "<td>$label</td>\n";
455 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
460 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
463 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
468 //-----------------------------------------------------------------------------------------------
470 function currencies_list($name, $selected_id=null, $submit_on_change=false)
472 $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
474 // default to the company currency
475 if ($selected_id == "")
477 $selected_id = get_company_currency();
478 $_POST[$name] = $selected_id;
481 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
483 'select_submit'=> $submit_on_change,
488 function currencies_list_cells($label, $name, $selected_id=null)
491 echo "<td>$label</td>\n";
493 $str = currencies_list($name, $selected_id);
498 function currencies_list_row($label, $name, $selected_id=null)
501 $str = currencies_list_cells($label, $name, $selected_id);
506 //---------------------------------------------------------------------------------------------------
508 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
511 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
513 // default to the company current fiscal year
514 if ($selected_id == "")
516 $selected_id = get_company_pref('f_year');
517 $_POST[$name] = $selected_id;
520 return combo_input($name, $selected_id, $sql, 'id', '',
523 'format' => '_format_fiscalyears',
524 'select_submit'=> $submit_on_change,
529 function _format_fiscalyears($row)
531 return sql2date($row[1]) . " - " . sql2date($row[2])
532 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
535 function fiscalyears_list_cells($label, $name, $selected_id=null)
538 echo "<td>$label</td>\n";
540 $str = fiscalyears_list($name, $selected_id);
545 function fiscalyears_list_row($label, $name, $selected_id=null)
548 $str = fiscalyears_list_cells($label, $name, $selected_id);
552 //------------------------------------------------------------------------------------
554 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
555 $submit_on_change=false, $showclosed=false, $showtype=1)
557 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
560 'order' => 'reference',
561 'spec_option'=>$no_option ? $showname : false,
563 'select_submit'=> $submit_on_change,
568 $options['where'][] = "closed=0";
570 $options['where'][] = "type_=$showtype";
572 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
575 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
576 $showclosed=false, $showtype=0)
579 echo "<td>$label</td>\n";
581 $str = dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
586 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
587 $showclosed=false, $showtype=0)
590 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
591 $showclosed, $showtype);
596 //---------------------------------------------------------------------------------------------------
598 function stock_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $opts=array())
602 $sql = "SELECT stock_id, s.description, c.description
603 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
605 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
608 'format' => '_format_stock_items',
609 'spec_option' => $all_option===true ? _("All Items") : $all_option,
610 'spec_id' => $all_items,
611 'search_box' => true,
612 'search' => array("stock_id", "c.description","s.description"),
613 'search_submit' => get_company_pref('no_item_list')!=0,
615 'select_submit'=> $submit_on_change
619 function _format_stock_items($row)
621 return (user_show_codes() ? ($row[0] . " - ") : "")
622 . $row[2] . " - " . $row[1];
625 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
628 echo "<td>$label</td>\n";
629 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
630 array('cells'=>true));
634 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
637 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
642 //------------------------------------------------------------------------------------
644 function base_stock_items_list($where, $name, $selected_id=null,
645 $all_option=false, $submit_on_change=false)
649 $sql = "SELECT stock_id, s.description, c.description
650 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
651 s.category_id=c.category_id";
653 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
655 'format' => '_format_stock_items',
656 'spec_option' => $all_option==true ? _("All Items") : $all_option,
657 'spec_id' => $all_items,
658 'select_submit'=> $submit_on_change,
662 //------------------------------------------------------------------------------------
664 function stock_bom_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
667 return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
668 $name, $selected_id, $all_option, $submit_on_change);
671 function stock_bom_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
674 echo "<td>$label</td>\n";
676 $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
681 function stock_bom_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
684 $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
689 //------------------------------------------------------------------------------------
691 function stock_manufactured_items_list($name, $selected_id=null,
692 $all_option=false, $submit_on_change=false)
694 return base_stock_items_list("s.mb_flag='M'",
695 $name, $selected_id, $all_option, $submit_on_change);
698 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
699 $all_option=false, $submit_on_change=false)
702 echo "<td>$label</td>\n";
704 $str = stock_manufactured_items_list($name, $selected_id, $all_option,
710 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
711 $all_option=false, $submit_on_change=false)
714 $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
715 $all_option, $submit_on_change);
719 //------------------------------------------------------------------------------------
721 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
722 $all_option=false, $submit_on_change=false)
724 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
725 array('where'=>array("stock_id != '$parent_stock_id'")));
729 function stock_component_items_list_cells($label, $name, $parent_stock_id,
730 $selected_id=null, $all_option=false, $submit_on_change=false)
733 echo "<td>$label</td>\n";
734 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
735 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true));
738 //------------------------------------------------------------------------------------
740 function stock_costable_items_list($name, $selected_id=null,
741 $all_option=false, $submit_on_change=false)
743 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
744 array('where'=>array("mb_flag!='D'")));
748 function stock_costable_items_list_cells($label, $name, $selected_id=null,
749 $all_option=false, $submit_on_change=false)
752 echo "<td>$label</td>\n";
753 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
754 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
758 //------------------------------------------------------------------------------------
759 function stock_purchasable_items_list($name, $selected_id=null,
760 $all_option=false, $submit_on_change=false)
762 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
763 array('where'=>array("mb_flag!= 'M'")));
767 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
768 $all_option=false, $submit_on_change=false)
771 echo "<td>$label</td>\n";
772 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
773 array('where'=>array("mb_flag!= 'M'"), 'cells'=>true));
777 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
778 $all_option=false, $submit_on_change=false)
781 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
782 $all_option, $submit_on_change);
787 //------------------------------------------------------------------------------------
789 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
792 'M' => _("Manufactured"),
793 'B' => _("Purchased"),
799 echo "<td>$label</td>\n";
802 array_selector($name, $selected_id, $types,
804 'select_submit'=> true,
805 'disabled' => !$enabled) );
809 function stock_units_list_row($label, $name, $value=null, $enabled=true)
811 $result = get_all_item_units();
814 echo "<td>$label</td>\n";
817 while($unit = db_fetch($result))
818 $units[$unit['abbr']] = $unit['name'];
820 array_selector($name, $value, $units,
822 'select_submit'=> true,
823 'disabled' => !$enabled) );
828 //------------------------------------------------------------------------------------
830 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
832 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
834 return combo_input($name, $selected_id, $sql, 'id', 'name',
836 'spec_option' => $none_option,
837 'spec_id' => reserved_words::get_all_numeric(),
838 'select_submit'=> $submit_on_change,
843 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
844 $submit_on_change=false)
847 echo "<td>$label</td>\n";
849 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
854 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
855 $submit_on_change=false)
858 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
863 //------------------------------------------------------------------------------------
865 function tax_groups_list($name, $selected_id=null,
866 $none_option=false, $submit_on_change=false)
868 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
870 return combo_input($name, $selected_id, $sql, 'id', 'name',
873 'spec_option' => $none_option,
875 'select_submit'=> $submit_on_change,
880 function tax_groups_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
883 echo "<td>$label</td>\n";
885 $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
890 function tax_groups_list_row($label, $name, $selected_id=null, $submit_on_change=false)
893 $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
898 //------------------------------------------------------------------------------------
900 function item_tax_types_list($name, $selected_id=null)
902 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
903 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
906 function item_tax_types_list_cells($label, $name, $selected_id=null)
909 echo "<td>$label</td>\n";
911 item_tax_types_list($name, $selected_id);
915 function item_tax_types_list_row($label, $name, $selected_id=null)
918 item_tax_types_list_cells($label, $name, $selected_id);
922 //------------------------------------------------------------------------------------
924 function shippers_list($name, $selected_id=null)
926 $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
927 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
930 function shippers_list_cells($label, $name, $selected_id=null)
933 echo "<td>$label</td>\n";
935 shippers_list($name, $selected_id);
939 function shippers_list_row($label, $name, $selected_id=null)
942 shippers_list_cells($label, $name, $selected_id);
946 //-------------------------------------------------------------------------------------
948 function sales_persons_list($name, $selected_id=null)
950 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
951 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
954 function sales_persons_list_cells($label, $name, $selected_id=null)
957 echo "<td>$label</td>\n";
959 sales_persons_list($name, $selected_id);
963 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
966 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
970 //------------------------------------------------------------------------------------
972 function sales_areas_list($name, $selected_id=null)
974 $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
975 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
978 function sales_areas_list_cells($label, $name, $selected_id=null)
981 echo "<td>$label</td>\n";
983 sales_areas_list($name, $selected_id);
987 function sales_areas_list_row($label, $name, $selected_id=null)
990 sales_areas_list_cells($label, $name, $selected_id);
994 //------------------------------------------------------------------------------------
996 function workorders_list($name, $selected_id=null)
998 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
999 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1002 function workorders_list_cells($label, $name, $selected_id=null)
1005 echo "<td>$label</td>\n";
1007 workorders_list($name, $selected_id);
1011 function workorders_list_row($label, $name, $selected_id=null)
1014 workorders_list_cells($label, $name, $selected_id);
1018 //------------------------------------------------------------------------------------
1020 function payment_terms_list($name, $selected_id=null)
1022 $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
1023 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1026 function payment_terms_list_cells($label, $name, $selected_id=null)
1029 echo "<td>$label</td>\n";
1031 payment_terms_list($name, $selected_id);
1035 function payment_terms_list_row($label, $name, $selected_id=null)
1038 payment_terms_list_cells($label, $name, $selected_id);
1042 //------------------------------------------------------------------------------------
1044 function credit_status_list($name, $selected_id=null)
1046 $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
1047 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1050 function credit_status_list_cells($label, $name, $selected_id=null)
1053 echo "<td>$label</td>\n";
1055 credit_status_list($name, $selected_id);
1059 function credit_status_list_row($label, $name, $selected_id=null)
1062 credit_status_list_cells($label, $name, $selected_id);
1066 //-----------------------------------------------------------------------------------------------
1068 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1070 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
1072 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1074 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1076 'select_submit'=> $submit_on_change,
1077 // 'async' => false,
1081 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1084 echo "<td>$label</td>\n";
1086 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1091 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1094 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1099 //-----------------------------------------------------------------------------------------------
1101 function movement_types_list($name, $selected_id=null)
1103 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1104 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1107 function movement_types_list_cells($label, $name, $selected_id=null)
1110 echo "<td>$label</td>\n";
1112 movement_types_list($name, $selected_id);
1116 function movement_types_list_row($label, $name, $selected_id=null)
1119 movement_types_list_cells($label, $name, $selected_id);
1123 //-----------------------------------------------------------------------------------------------
1125 function bank_trans_types_list($name, $selected_id=null)
1127 $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1128 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1131 function bank_trans_types_list_cells($label, $name, $selected_id=null)
1134 echo "<td>$label</td>\n";
1136 bank_trans_types_list($name, $selected_id);
1140 function bank_trans_types_list_row($label, $name, $selected_id=null)
1143 bank_trans_types_list_cells($label, $name, $selected_id);
1147 //-----------------------------------------------------------------------------------------------
1149 function workcenter_list($name, $selected_id=null, $all_option=false)
1153 $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1155 return combo_input($name, $selected_id, $sql, 'id', 'name',
1157 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1158 'spec_id' => $all_items,
1162 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1164 default_focus($name);
1166 echo "<td>$label</td>\n";
1168 workcenter_list($name, $selected_id, $all_option);
1172 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1175 workcenter_list_cells($label, $name, $selected_id, $all_option);
1179 //-----------------------------------------------------------------------------------------------
1181 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1183 $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1184 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1185 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1187 return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1189 'format' => '_format_add_curr',
1190 'select_submit'=> $submit_on_change,
1195 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1198 echo "<td>$label</td>\n";
1200 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1205 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1208 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1213 //-----------------------------------------------------------------------------------------------
1215 function class_list($name, $selected_id=null, $submit_on_change=false)
1217 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1219 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1221 'select_submit'=> $submit_on_change,
1227 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1230 echo "<td>$label</td>\n";
1232 $str = class_list($name, $selected_id, $submit_on_change);
1237 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1240 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1245 //-----------------------------------------------------------------------------------------------
1247 function stock_categories_list($name, $selected_id=null)
1249 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1250 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1251 array('order'=>'category_id'));
1254 function stock_categories_list_cells($label, $name, $selected_id=null)
1257 echo "<td>$label</td>\n";
1259 stock_categories_list($name, $selected_id);
1263 function stock_categories_list_row($label, $name, $selected_id=null)
1266 stock_categories_list_cells($label, $name, $selected_id);
1270 //-----------------------------------------------------------------------------------------------
1272 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1276 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1278 combo_input($name, $selected_id, $sql, 'id', 'name',
1281 'spec_option' =>$all_option,
1282 'spec_id' => $all_option_numeric ? 0 : $all_items
1286 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1287 $all_option_numeric=false)
1290 echo "<td>$label</td>\n";
1292 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1296 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1297 $all_option_numeric=false)
1300 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1301 $all_option_numeric);
1305 //-----------------------------------------------------------------------------------------------
1306 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1307 $show_group=false, $cells=false, $all_option=false)
1309 if ($skip_bank_accounts)
1310 $sql = "SELECT chart.account_code, chart.account_name, type.name
1311 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1312 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1313 ."ON chart.account_code=acc.account_code
1314 WHERE acc.account_code IS NULL
1315 AND chart.account_type=type.id";
1317 $sql = "SELECT chart.account_code, chart.account_name, type.name
1318 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1319 WHERE chart.account_type=type.id";
1321 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1323 'format' => '_format_account' . ($show_group ? '2' : ''),
1324 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1326 'order' => 'account_code',
1327 'search_box' => $cells,
1328 'search_submit' => false,
1336 function _format_account($row)
1338 return $row[0] . " " . $row[1];
1341 function _format_account2($row)
1343 return $row[0] . " " . $row[2] . " " . $row[1];
1346 function gl_all_accounts_list_cells($label, $name, $selected_id=null, $skip_bank_accounts=false,
1347 $show_group=false, $cells=false, $all_option=false)
1350 echo "<td>$label</td>\n";
1352 gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1356 function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_accounts=false,
1357 $show_group=false, $cells=false, $all_option=false)
1360 gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1361 $show_group, $cells, $all_option);
1365 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1368 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1369 $items['0'] = strlen($name_no) ? $name_no : _("No");
1371 return array_selector($name, $selected_id, $items,
1373 'select_submit'=> true,
1374 'async' => false ) ); // FIX?
1377 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1380 echo "<td>$label</td>\n";
1382 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1387 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1390 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1395 //------------------------------------------------------------------------------------------------
1397 function languages_list($name, $selected_id=null)
1399 global $installed_languages;
1402 foreach ($installed_languages as $lang)
1403 $items[$lang['code']] = $lang['name'];
1405 return array_selector($name, $selected_id, $items );
1408 function languages_list_cells($label, $name, $selected_id=null)
1411 echo "<td>$label</td>\n";
1413 languages_list($name, $selected_id);
1417 function languages_list_row($label, $name, $selected_id=null)
1420 languages_list_cells($label, $name, $selected_id);
1424 //------------------------------------------------------------------------------------------------
1426 function bank_account_types_list($name, $selected_id=null)
1428 $types = bank_account_types::get_all();
1431 foreach ($types as $type)
1433 if (payment_person_types::has_items($type['id']))
1435 $items[$type['id']] = $type['name'];
1439 return array_selector($name, $selected_id, $items );
1442 function bank_account_types_list_cells($label, $name, $selected_id=null)
1445 echo "<td>$label</td>\n";
1447 bank_account_types_list($name, $selected_id);
1451 function bank_account_types_list_row($label, $name, $selected_id=null)
1454 bank_account_types_list_cells($label, $name, $selected_id);
1458 //------------------------------------------------------------------------------------------------
1459 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1461 $types = payment_person_types::get_all();
1464 foreach ($types as $type)
1466 if (payment_person_types::has_items($type['id']))
1468 $items[$type['id']] = $type['name'];
1472 return array_selector($name, $selected_id, $items,
1473 array( 'select_submit'=> $submit_on_change ) );
1476 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1479 echo "<td>$label</td>\n";
1481 $str = payment_person_types_list($name, $selected_id, $related);
1486 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1489 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1494 //------------------------------------------------------------------------------------------------
1496 function wo_types_list($name, $selected_id=null)
1498 $types = wo_types::get_all();
1501 foreach ($types as $type)
1502 $items[$type['id']] = $type['name'];
1504 return array_selector($name, $selected_id, $items,
1505 array( 'select_submit'=> true, 'async' => true ) );
1508 function wo_types_list_row($label, $name, $selected_id=null)
1510 echo "<tr><td>$label</td><td>\n";
1511 $str = wo_types_list($name, $selected_id);
1512 echo "</td></tr>\n";
1516 //------------------------------------------------------------------------------------------------
1518 function dateformats_list_row($label, $name, $value=null)
1520 global $dateformats;
1522 echo "<tr><td>$label</td>\n<td>";
1523 array_selector( $name, $value, $dateformats );
1524 echo "</td></tr>\n";
1527 function dateseps_list_row($label, $name, $value=null)
1531 echo "<tr><td>$label</td>\n<td>";
1532 array_selector( $name, $value, $dateseps );
1533 echo "</td></tr>\n";
1536 function thoseps_list_row($label, $name, $value=null)
1540 echo "<tr><td>$label</td>\n<td>";
1541 array_selector( $name, $value, $thoseps );
1542 echo "</td></tr>\n";
1545 function decseps_list_row($label, $name, $value=null)
1549 echo "<tr><td>$label</td>\n<td>";
1550 array_selector( $name, $value, $decseps );
1551 echo "</td></tr>\n";
1554 function themes_list_row($label, $name, $value=null)
1556 global $path_to_root;
1558 $path = $path_to_root.'/themes/';
1560 $themedir = opendir($path);
1561 while(false !== ($fname = readdir($themedir)))
1563 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1565 $themes[$fname] = $fname;
1570 echo "<tr><td>$label</td>\n<td>";
1571 array_selector( $name, $value, $themes );
1572 echo "</td></tr>\n";
1575 function pagesizes_list_row($label, $name, $value=null)
1580 foreach ($pagesizes as $pz)
1583 echo "<tr><td>$label</td>\n<td>";
1584 array_selector( $name, $value, $items );
1585 echo "</td></tr>\n";
1588 function security_headings_list_row($label, $name, $value=null)
1590 global $security_headings;
1592 echo "<tr><td>$label</td>\n<td>";
1593 array_selector( $name, $value, $security_headings );
1594 echo "</td></tr>\n";
1597 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1599 global $systypes_array;
1602 echo "<td>$label</td>\n";
1606 foreach ($systypes_array as $key=>$type)
1607 $items[$key] = $type['name'];
1609 $str = array_selector($name, $value, $items,
1611 'select_submit'=> $submit_on_change,
1619 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1622 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1627 function cust_allocations_list_cells($label, $name, $selected=null)
1635 $all_items=>_("All Types"),
1636 '1'=> _("Sales Invoices"),
1637 '2'=> _("Overdue Invoices"),
1638 '3' => _("Payments"),
1639 '4' => _("Credit Notes"),
1640 '5' => _("Delivery Notes")
1642 $str = array_selector($name, $selected, $allocs);
1647 function supp_allocations_list_cell($name, $selected=null)
1653 $all_items=>_("All Types"),
1654 '1'=> _("Invoices"),
1655 '2'=> _("Overdue Invoices"),
1656 '3' => _("Payments"),
1657 '4' => _("Credit Notes"),
1658 '5' => _("Overdue Credit Notes")
1660 $str = array_selector($name, $selected, $allocs);
1665 function policy_list_cells($label, $name, $selected=null)
1670 $str = array_selector($name, $selected,
1671 array( '' => _("Automatically put balance on back order"),
1672 'CAN' => _("Cancel any quantites not delivered")) );
1677 function policy_list_row($label, $name, $selected=null)
1680 policy_list_cells($label, $name, $selected);
1684 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1689 $str = array_selector($name, $selected,
1690 array( 'Return' => _("Items Returned to Inventory Location"),
1691 'WriteOff' => _("Items Written Off")),
1692 array( 'select_submit'=> $submit_on_change ) );
1697 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1700 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1705 function number_list($name, $selected, $from, $to, $no_option=false)
1708 for ($i = $from; $i <= $to; $i++)
1711 return array_selector($name, $selected, $items,
1712 array( 'spec_option' => $no_option,
1713 'spec_id' => reserved_words::get_all_numeric()) );
1716 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1721 number_list($name, $selected, $from, $to, $no_option);
1725 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1728 number_list_cells($label, $name, $selected, $from, $to, $no_option);