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 type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
9 ."%s/images/locate.png) no-repeat;%s' name='%s' value=' ' title='"._("Set filter")."'> ";
11 $_select_button = "<input type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
12 ."%s/images/button_ok.png) no-repeat;%s' name='%s' value=' ' title='"._("Select")."'> ";
14 $all_items = reserved_words::get_all();
16 //----------------------------------------------------------------------------
17 // Universal 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
49 'disabled' => false, // FIX todo
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';
64 if(!count($opts['search'])) {
65 $opts['search'] = array($by_id ? $valfield : $namefield);
67 if ($opts['sel_hint'] === null)
68 $opts['sel_hint'] = $by_id || $search_box==false ?
69 '' : _('Press Space tab for search pattern entry');
71 if ($opts['box_hint'] === null)
72 $opts['box_hint'] = $search_box ?
73 ($by_id ? _('Enter code fragment to search or * for all')
74 : _('Enter description fragment to search or * for all')) :'';
76 if ($selected_id == null) {
77 $selected_id = get_post($name, null);
79 $txt = get_post($search_box);
83 if (isset($_POST[$select_submit])) {
85 $Ajax->activate('_page_body');
87 $Ajax->activate($name);
90 // search related sql modifications
92 $rel = "rel='$search_box'"; // set relation to list
93 if ($opts['search_submit']) {
94 // if selected from list - set focus on next field
95 if (isset($_POST[$search_submit])) {
96 $Ajax->activate($name);
99 if ($spec_option === false)
102 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
107 foreach($opts['search'] as $i=> $s)
108 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
109 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
114 if (count($opts['where'])) {
115 $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
116 $sql .= '('. implode($opts['where'], ' AND ') . ')';
118 if ($opts['order'] != false) {
119 $sql .= ' ORDER BY '.$opts['order'];
123 // ------ make selector ----------
124 $selector = $first_opt = '';
127 //if($name=='code_id') display_error($sql);
128 if($result = db_query($sql)) {
129 while ($contact_row = db_fetch($result)) {
130 $value = $contact_row[0];
131 $descr = $opts['format']==null ? $contact_row[1] :
132 call_user_func($opts['format'], $contact_row);
134 if ($selected_id === $value) {
138 if ($first_id === false) {
142 $selector .= "<option $sel value='$value'>$descr</option>\n";
144 db_free_result($result);
146 // Prepend special option.
147 if ($spec_option !== false) { // if special option used - add it
148 $first_id = $spec_id;
149 $first_opt = $spec_option;
150 $sel = $found===false ? 'selected' : '';
151 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
155 if ($found === false) {
156 $_POST[$name] = $first_id;
160 $txt = $_POST[$name];
162 $Ajax->addUpdate($name, $search_box, $txt);
165 $selector = "<select name='$name' class='$class' title='"
166 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
168 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
170 // because of bug which M$ cannot fix since IE 5.0
171 // we must embed whole selector in span tags to enable proper ajax update
172 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
174 if ($select_submit != false) { // if submit on change is used - add select button
175 global $_select_button;
176 // button class selects form reload/ajax selector update
177 $selector .= sprintf($_select_button, user_theme(),
178 (in_ajax() ? 'display:none;':''),
179 $select_submit)."\n";
181 // ------ make combo ----------
184 if ($search_box != false) {
185 $edit_entry = "<input type='text' name='$search_box' id='$search_box' size='".
186 $opts['size']."' maxlength='".$opts['max'].
187 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
188 .$opts['box_hint']."'"
189 .(in_ajax() && !$by_id ? " style=display:none;":'')
191 if ($search_submit != false) {
192 global $_search_button;
193 $edit_entry .= sprintf($_search_button, user_theme(),
194 (in_ajax() ? 'display:none;':''),
195 $search_submit)."\n";
198 default_focus($name);
200 if ($search_box && $opts['cells'])
201 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
203 echo $edit_entry.$selector;
208 function supplier_list($name, $selected_id, $spec_option=false, $submit_on_change=false)
212 $sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ";
214 $mode = get_company_pref('no_supplier_list');
216 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
218 'format' => '_format_add_curr',
219 'search_box' => $mode!=0,
221 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
222 'spec_id' => $all_items,
223 'select_submit'=> $submit_on_change,
225 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
230 function _format_add_curr($row)
232 static $company_currency;
234 if ($company_currency == null)
236 $company_currency = get_company_currency();
238 return $row[1] . ($row[2] == $company_currency ?
239 '' : (" - " . $row[2]));
242 function supplier_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
245 echo "<td>$label</td><td>\n";
246 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change);
251 function supplier_list_row($label, $name, $selected_id, $all_option = false, $submit_on_change=false)
253 echo "<tr><td>$label</td><td>";
254 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
258 //----------------------------------------------------------------------------------------------
260 function customer_list($name, $selected_id, $spec_option=false, $submit_on_change=false)
264 $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
266 $mode = get_company_pref('no_customer_list');
268 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
270 'format' => '_format_add_curr',
271 'search_box' => $mode!=0,
274 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
275 'spec_id' => $all_items,
276 'select_submit'=> $submit_on_change,
278 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
283 function customer_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
286 echo "<td>$label</td>\n";
288 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
293 function customer_list_row($label, $name, $selected_id, $all_option = false, $submit_on_change=false)
295 echo "<tr><td>$label</td><td nowrap>";
296 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
297 echo "</td>\n</tr>\n";
301 //------------------------------------------------------------------------------------------------
303 function customer_branches_list($customer_id, $name, $selected_id,
304 $spec_option = true, $enabled=true, $submit_on_change=false)
308 $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
309 WHERE debtor_no='" . $customer_id . "' ";
311 $where = $enabled ? array("disable_trans = 0") : array();
312 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
315 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
316 'spec_id' => $all_items,
317 'select_submit'=> $submit_on_change,
318 'sel_hint' => _('Select customer branch')
322 //------------------------------------------------------------------------------------------------
324 function customer_branches_list_cells($label,$customer_id, $name, $selected_id, $all_option = true, $enabled=true, $submit_on_change=false)
327 echo "<td>$label</td>\n";
329 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
334 function customer_branches_list_row($label,$customer_id, $name, $selected_id, $all_option = true, $enabled=true, $submit_on_change=false)
337 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
342 //------------------------------------------------------------------------------------------------
344 function locations_list($name, $selected_id, $all_option=false, $submit_on_change=false)
348 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
350 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
352 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
353 'spec_id' => $all_items,
354 'select_submit'=> $submit_on_change,
359 function locations_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
362 echo "<td>$label</td>\n";
364 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
369 function locations_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
372 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
377 //-----------------------------------------------------------------------------------------------
379 function currencies_list($name, $selected_id, $submit_on_change=false)
381 $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
383 // default to the company currency
384 if ($selected_id == "")
386 $selected_id = get_company_currency();
387 $_POST[$name] = $selected_id;
390 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
392 'select_submit'=> $submit_on_change,
397 function currencies_list_cells($label, $name, $selected_id)
400 echo "<td>$label</td>\n";
402 $str = currencies_list($name, $selected_id);
407 function currencies_list_row($label, $name, $selected_id)
410 $str = currencies_list_cells($label, $name, $selected_id);
415 //---------------------------------------------------------------------------------------------------
417 function fiscalyears_list($name, $selected_id, $submit_on_change=false)
420 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
422 // default to the company current fiscal year
423 if ($selected_id == "")
425 $selected_id = get_company_pref('f_year');
426 $_POST[$name] = $selected_id;
429 return combo_input($name, $selected_id, $sql, 'id', '',
432 'format' => '_format_fiscalyears',
433 'select_submit'=> $submit_on_change,
438 function _format_fiscalyears($row)
440 return sql2date($row[1]) . " - " . sql2date($row[2])
441 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
444 function fiscalyears_list_cells($label, $name, $selected_id)
447 echo "<td>$label</td>\n";
449 $str = fiscalyears_list($name, $selected_id);
454 function fiscalyears_list_row($label, $name, $selected_id)
457 $str = fiscalyears_list_cells($label, $name, $selected_id);
461 //------------------------------------------------------------------------------------
463 function dimensions_list($name, $selected_id, $no_option=false, $showname=' ',
464 $submit_on_change=false, $showclosed=false, $showtype=1)
466 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
469 'order' => 'reference',
470 'spec_option'=>$no_option ? $showname : false,
472 'select_submit'=> $submit_on_change,
477 $options['where'][] = "closed=0";
479 $options['where'][] = "type_=$showtype";
481 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
484 function dimensions_list_cells($label, $name, $selected_id, $no_option=false, $showname=null,
485 $showclosed=false, $showtype=0)
488 echo "<td>$label</td>\n";
490 $str = dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
495 function dimensions_list_row($label, $name, $selected_id, $no_option=false, $showname=null,
496 $showclosed=false, $showtype=0)
499 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
500 $showclosed, $showtype);
505 //---------------------------------------------------------------------------------------------------
507 function stock_items_list($name, $selected_id, $all_option=false, $submit_on_change=false, $opts=array())
511 $sql = "SELECT stock_id, s.description, c.description
512 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
514 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
517 'format' => '_format_stock_items',
518 'spec_option' => $all_option===true ? _("All Items") : $all_option,
519 'spec_id' => $all_items,
520 'search_box' => true,
521 'search' => array("stock_id", "c.description","s.description"),
522 'search_submit' => get_company_pref('no_item_list')!=0,
524 'select_submit'=> $submit_on_change
528 function _format_stock_items($row)
530 return (user_show_codes() ? ($row[0] . " - ") : "")
531 . $row[2] . " - " . $row[1];
534 function stock_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
537 echo "<td>$label</td>\n";
538 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
539 array('cells'=>true));
543 function stock_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
546 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
551 //------------------------------------------------------------------------------------
553 function base_stock_items_list($where, $name, $selected_id,
554 $all_option=false, $submit_on_change=false)
558 $sql = "SELECT stock_id, s.description, c.description
559 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
560 s.category_id=c.category_id";
562 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
564 'format' => '_format_stock_items',
565 'spec_option' => $all_option==true ? _("All Items") : $all_option,
566 'spec_id' => $all_items,
567 'select_submit'=> $submit_on_change,
571 //------------------------------------------------------------------------------------
573 function stock_bom_items_list($name, $selected_id, $all_option=false, $submit_on_change=false)
576 return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
577 $name, $selected_id, $all_option, $submit_on_change);
580 function stock_bom_items_list_cells($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
583 echo "<td>$label</td>\n";
585 $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
590 function stock_bom_items_list_row($label, $name, $selected_id, $all_option=false, $submit_on_change=false)
593 $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
598 //------------------------------------------------------------------------------------
600 function stock_manufactured_items_list($name, $selected_id,
601 $all_option=false, $submit_on_change=false)
603 return base_stock_items_list("s.mb_flag='M'",
604 $name, $selected_id, $all_option, $submit_on_change);
607 function stock_manufactured_items_list_cells($label, $name, $selected_id,
608 $all_option=false, $submit_on_change=false)
611 echo "<td>$label</td>\n";
613 $str = stock_manufactured_items_list($name, $selected_id, $all_option,
619 function stock_manufactured_items_list_row($label, $name, $selected_id,
620 $all_option=false, $submit_on_change=false)
623 $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
624 $all_option, $submit_on_change);
628 //------------------------------------------------------------------------------------
630 function stock_component_items_list($name, $parent_stock_id, $selected_id,
631 $all_option=false, $submit_on_change=false)
633 return base_stock_items_list("stock_id != '$parent_stock_id'", $name, $selected_id,
634 $all_option, $submit_on_change);
636 //------------------------------------------------------------------------------------
638 function stock_costable_items_list($name, $selected_id,
639 $all_option=false, $submit_on_change=false)
641 return base_stock_items_list("mb_flag!='D'", $name, $selected_id,
642 $all_option, $submit_on_change);
645 //------------------------------------------------------------------------------------
647 function stock_purchasable_items_list($name, $selected_id, $all_option=false,
648 $submit_on_change=false, $opts=array())
651 $sql = "SELECT stock_id, s.description, c.description
652 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c
653 WHERE s.category_id=c.category_id
655 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
657 'format' => '_format_stock_items',
658 'spec_option' => $all_option===true ? _("All Items") : $all_option,
659 'spec_id' => $all_items,
660 'search_box' => true,
661 'search' => array("stock_id", "c.description","s.description"),
662 'search_submit' => get_company_pref('no_item_list')!=0,
664 'select_submit'=> $submit_on_change
669 function stock_purchasable_items_list_cells($label, $name, $selected_id,
670 $all_option=false, $submit_on_change=false)
673 echo "<td>$label</td>\n";
674 $ret = stock_purchasable_items_list($name, $selected_id, $all_option,
675 $submit_on_change, array('cells'=>true) );
679 function stock_purchasable_items_list_row($label, $name, $selected_id,
680 $all_option=false, $submit_on_change=false)
683 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id,
684 $all_option, $submit_on_change);
689 //------------------------------------------------------------------------------------
691 function stock_item_types_list_row($label, $name, $selected_id, $enabled=true)
693 default_focus($name);
696 echo "<td>$label</td>\n";
699 $sel = "<select name='$name' onchange='this.form.submit();'>\n";
701 $sel = "<select disabled name='$name'>\n";
702 if ($selected_id == null)
703 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
704 if ($selected_id == "")
705 $_POST[$name] = $selected_id = "B";
706 $sel .= "<option " . ($selected_id == 'M'?" selected ":"") . " value='M'>" . _("Manufactured"). "</option>\n";
707 $sel .= "<option " . ($selected_id == 'B'?" selected ":"") . " value='B'>" . _("Purchased"). "</option>\n";
708 $sel .= "<option " . ($selected_id == 'D'?" selected ":"") . " value='D'>" . _("Service"). "</option>\n";
715 function stock_units_list_row($label, $name, $value, $enabled=true)
719 default_focus($name);
720 $result = get_all_item_units();
721 echo "<tr><td>$label</td>\n";
723 echo "<td><select name='$name'>";
725 echo "<td><select disabled name='$name'>";
728 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
730 while($unit = db_fetch($result))
734 $_POST[$name] = $unit['abbr'];
736 $descr = $unit['name'];
737 if ($value==$unit['abbr'])
739 echo "<option selected value='".$unit['abbr']."'>$descr</option>\n";
743 echo "<option value='".$unit['abbr']."'>$descr</option>\n";
746 echo "</select></td></tr>\n";
749 //------------------------------------------------------------------------------------
751 function tax_types_list($name, $selected_id, $none_option=false, $submit_on_change=false)
755 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
757 return combo_input($name, $selected_id, $sql, 'id', 'name',
759 'spec_option' => $none_option,
760 'spec_id' => $all_items,
761 'select_submit'=> $submit_on_change,
766 function tax_types_list_cells($label, $name, $selected_id, $none_option=false,
767 $submit_on_change=false)
770 echo "<td>$label</td>\n";
772 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
777 function tax_types_list_row($label, $name, $selected_id, $none_option=false,
778 $submit_on_change=false)
781 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
786 //------------------------------------------------------------------------------------
788 function tax_groups_list($name, $selected_id,
789 $none_option=false, $submit_on_change=false)
793 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
795 return combo_input($name, $selected_id, $sql, 'id', 'name',
798 'spec_option' => $none_option,
799 'spec_id' => $all_items,
800 'select_submit'=> $submit_on_change,
805 function tax_groups_list_cells($label, $name, $selected_id, $submit_on_change=false)
808 echo "<td>$label</td>\n";
810 $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
815 function tax_groups_list_row($label, $name, $selected_id, $submit_on_change=false)
818 $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
823 //------------------------------------------------------------------------------------
825 function item_tax_types_list($name, $selected_id)
827 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
828 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
831 function item_tax_types_list_cells($label, $name, $selected_id)
834 echo "<td>$label</td>\n";
836 item_tax_types_list($name, $selected_id);
840 function item_tax_types_list_row($label, $name, $selected_id)
843 item_tax_types_list_cells($label, $name, $selected_id);
847 //------------------------------------------------------------------------------------
849 function shippers_list($name, $selected_id)
851 $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
852 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
855 function shippers_list_cells($label, $name, $selected_id)
858 echo "<td>$label</td>\n";
860 shippers_list($name, $selected_id);
864 function shippers_list_row($label, $name, $selected_id)
867 shippers_list_cells($label, $name, $selected_id);
871 //-------------------------------------------------------------------------------------
873 function sales_persons_list($name, $selected_id)
875 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
876 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
879 function sales_persons_list_cells($label, $name, $selected_id)
882 echo "<td>$label</td>\n";
884 sales_persons_list($name, $selected_id);
888 function sales_persons_list_row($label, $name, $selected_id, $submit_on_change=false)
891 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
895 //------------------------------------------------------------------------------------
897 function sales_areas_list($name, $selected_id)
899 $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
900 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
903 function sales_areas_list_cells($label, $name, $selected_id)
906 echo "<td>$label</td>\n";
908 sales_areas_list($name, $selected_id);
912 function sales_areas_list_row($label, $name, $selected_id)
915 sales_areas_list_cells($label, $name, $selected_id);
919 //------------------------------------------------------------------------------------
921 function workorders_list($name, $selected_id)
923 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
924 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
927 function workorders_list_cells($label, $name, $selected_id)
930 echo "<td>$label</td>\n";
932 workorders_list($name, $selected_id);
936 function workorders_list_row($label, $name, $selected_id)
939 workorders_list_cells($label, $name, $selected_id);
943 //------------------------------------------------------------------------------------
945 function payment_terms_list($name, $selected_id)
947 $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
948 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
951 function payment_terms_list_cells($label, $name, $selected_id)
954 echo "<td>$label</td>\n";
956 payment_terms_list($name, $selected_id);
960 function payment_terms_list_row($label, $name, $selected_id)
963 payment_terms_list_cells($label, $name, $selected_id);
967 //------------------------------------------------------------------------------------
969 function credit_status_list($name, $selected_id)
971 $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
972 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
975 function credit_status_list_cells($label, $name, $selected_id)
978 echo "<td>$label</td>\n";
980 credit_status_list($name, $selected_id);
984 function credit_status_list_row($label, $name, $selected_id)
987 credit_status_list_cells($label, $name, $selected_id);
991 //-----------------------------------------------------------------------------------------------
993 function sales_types_list($name, $selected_id, $submit_on_change=false, $special_option=false)
997 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
999 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1001 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1003 'select_submit'=> $submit_on_change,
1004 // 'async' => false,
1008 function sales_types_list_cells($label, $name, $selected_id, $submit_on_change=false, $special_option=false)
1011 echo "<td>$label</td>\n";
1013 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1018 function sales_types_list_row($label, $name, $selected_id, $submit_on_change=false, $special_option=false)
1021 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1026 //-----------------------------------------------------------------------------------------------
1028 function movement_types_list($name, $selected_id)
1030 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1031 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1034 function movement_types_list_cells($label, $name, $selected_id)
1037 echo "<td>$label</td>\n";
1039 movement_types_list($name, $selected_id);
1043 function movement_types_list_row($label, $name, $selected_id)
1046 movement_types_list_cells($label, $name, $selected_id);
1050 //-----------------------------------------------------------------------------------------------
1052 function bank_trans_types_list($name, $selected_id)
1054 $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1055 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1058 function bank_trans_types_list_cells($label, $name, $selected_id)
1061 echo "<td>$label</td>\n";
1063 bank_trans_types_list($name, $selected_id);
1067 function bank_trans_types_list_row($label, $name, $selected_id)
1070 bank_trans_types_list_cells($label, $name, $selected_id);
1074 //-----------------------------------------------------------------------------------------------
1076 function workcenter_list($name, $selected_id, $all_option=false)
1080 $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1082 return combo_input($name, $selected_id, $sql, 'id', 'name',
1084 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1085 'spec_id' => $all_items,
1089 function workcenter_list_cells($label, $name, $selected_id, $all_option=false)
1091 default_focus($name);
1093 echo "<td>$label</td>\n";
1095 workcenter_list($name, $selected_id, $all_option);
1099 function workcenter_list_row($label, $name, $selected_id, $all_option=false)
1102 workcenter_list_cells($label, $name, $selected_id, $all_option);
1106 //-----------------------------------------------------------------------------------------------
1108 function bank_accounts_list($name, $selected_id, $submit_on_change=false)
1110 $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1111 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1112 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1114 return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1116 'format' => '_format_add_curr',
1117 'select_submit'=> $submit_on_change,
1122 function bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change=false)
1125 echo "<td>$label</td>\n";
1127 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1132 function bank_accounts_list_row($label, $name, $selected_id, $submit_on_change=false)
1135 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1140 //-----------------------------------------------------------------------------------------------
1142 function class_list($name, $selected_id, $submit_on_change=false)
1144 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1146 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1148 'select_submit'=> $submit_on_change,
1154 function class_list_cells($label, $name, $selected_id, $submit_on_change=false)
1157 echo "<td>$label</td>\n";
1159 $str = class_list($name, $selected_id, $submit_on_change);
1164 function class_list_row($label, $name, $selected_id, $submit_on_change=false)
1167 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1172 //-----------------------------------------------------------------------------------------------
1174 function stock_categories_list($name, $selected_id)
1176 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1177 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1178 array('order'=>'category_id'));
1181 function stock_categories_list_cells($label, $name, $selected_id)
1184 echo "<td>$label</td>\n";
1186 stock_categories_list($name, $selected_id);
1190 function stock_categories_list_row($label, $name, $selected_id)
1193 stock_categories_list_cells($label, $name, $selected_id);
1197 //-----------------------------------------------------------------------------------------------
1199 function gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric)
1203 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1205 combo_input($name, $selected_id, $sql, 'id', 'name',
1208 'spec_option' =>$all_option,
1209 'spec_id' => $all_option_numeric ? 0 : $all_items
1213 function gl_account_types_list_cells($label, $name, $selected_id, $all_option=false,
1214 $all_option_numeric=false)
1217 echo "<td>$label</td>\n";
1219 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1223 function gl_account_types_list_row($label, $name, $selected_id, $all_option=false,
1224 $all_option_numeric=false)
1227 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1228 $all_option_numeric);
1232 //-----------------------------------------------------------------------------------------------
1233 function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false,
1234 $show_group=false, $cells=false)
1236 if ($skip_bank_accounts)
1237 $sql = "SELECT chart.account_code, chart.account_name, type.name
1238 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1239 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1240 ."ON chart.account_code=acc.account_code
1241 WHERE acc.account_code IS NULL
1242 AND chart.account_type=type.id";
1244 $sql = "SELECT chart.account_code, chart.account_name, type.name
1245 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1246 WHERE chart.account_type=type.id";
1248 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1250 'format' => '_format_account' . ($show_group ? '2' : ''),
1251 'order' => 'account_code',
1252 'search_box' => $cells,
1253 'search_submit' => false,
1261 function _format_account($row)
1263 return $row[0] . " " . $row[1];
1266 function _format_account2($row)
1268 return $row[0] . " " . $row[2] . " " . $row[1];
1271 function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false,
1272 $show_group=false, $cells=false)
1275 echo "<td>$label</td>\n";
1277 gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells);
1281 function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false,
1282 $show_group=false, $cells=false)
1285 gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1286 $show_group, $cells);
1290 function yesno_list($name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1292 default_focus($name);
1293 if ($submit_on_change == true)
1294 echo "<select name='$name' onchange='this.form.submit();'>"; // FIX ajax
1296 echo "<select name='$name'>";
1298 if (strlen($name_yes) == 0)
1302 if (strlen($name_no) == 0)
1307 if ($selected_id == null)
1308 $selected_id = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1309 if ($selected_id == 0)
1310 echo "<option value=1>";
1312 echo "<option selected value=1>";
1313 if (!isset($name_yes))
1314 echo _("Yes") . "</option>\n";
1316 echo $name_yes . "</option>\n";
1317 if ($selected_id == 0)
1318 echo "<option selected value=0>";
1320 echo "<option value=0>";
1321 if (!isset($name_no))
1322 echo _("No") . "</option>\n";
1324 echo $name_no . "</option>\n";
1328 function yesno_list_cells($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1331 echo "<td>$label</td>\n";
1333 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1338 function yesno_list_row($label, $name, $selected_id, $name_yes="", $name_no="", $submit_on_change=false)
1341 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1346 //------------------------------------------------------------------------------------------------
1348 function languages_list($name, $selected_id)
1350 global $installed_languages;
1352 default_focus($name);
1353 echo "<select name='$name'>";
1355 if ($selected_id == null)
1356 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1357 foreach ($installed_languages as $lang)
1360 if ($selected_id == $lang['code'])
1362 echo "value='" . $lang['code'] . "'>" . $lang['name'] . "</option>\n";
1366 function languages_list_cells($label, $name, $selected_id)
1369 echo "<td>$label</td>\n";
1371 languages_list($name, $selected_id);
1375 function languages_list_row($label, $name, $selected_id)
1378 languages_list_cells($label, $name, $selected_id);
1382 //------------------------------------------------------------------------------------------------
1384 function bank_account_types_list($name, $selected_id)
1386 $bank_account_types = bank_account_types::get_all();
1388 default_focus($name);
1389 echo "<select name='$name'>";
1391 if ($selected_id == null)
1392 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1393 foreach ($bank_account_types as $type)
1396 if ($selected_id == "" || $selected_id == $type['id'])
1398 echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1402 function bank_account_types_list_cells($label, $name, $selected_id)
1405 echo "<td>$label</td>\n";
1407 bank_account_types_list($name, $selected_id);
1411 function bank_account_types_list_row($label, $name, $selected_id)
1414 bank_account_types_list_cells($label, $name, $selected_id);
1418 //------------------------------------------------------------------------------------------------
1420 function payment_person_types_list($name, $selected_id, $related=null)
1422 $types = payment_person_types::get_all();
1424 default_focus($name);
1425 echo "<select name='$name'";
1426 if ($related) // FIX ajax
1427 echo " onchange='this.form.$related.value=\"\"; this.form.submit();' ";
1430 if ($selected_id == null)
1431 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1432 foreach ($types as $type)
1434 if (payment_person_types::has_items($type['id']))
1436 if ($selected_id == "")
1437 $_POST[$name] = $selected_id = $type['id'];
1439 if ($selected_id == $type['id'])
1441 echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1446 function payment_person_types_list_cells($label, $name, $selected_id, $related=null)
1449 echo "<td>$label</td>\n";
1451 $str = payment_person_types_list($name, $selected_id, $related);
1456 function payment_person_types_list_row($label, $name, $selected_id, $related=null)
1459 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1464 //------------------------------------------------------------------------------------------------
1466 function wo_types_list($name, $selected_id)
1468 $types = wo_types::get_all();
1470 default_focus($name); // FIX ajax
1471 echo "<select name='$name' onchange='this.form.submit();'>";
1473 if ($selected_id == null)
1474 $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1475 foreach ($types as $type)
1478 if ($selected_id == $type['id'])
1480 echo "value='" . $type['id'] . "'>" . $type['name'] . "</option>\n";
1485 function wo_types_list_row($label, $name, $selected_id)
1487 echo "<tr><td>$label</td><td>\n";
1488 $str = wo_types_list($name, $selected_id);
1489 echo "</td></tr>\n";
1493 //------------------------------------------------------------------------------------------------
1495 function dateformats_list_row($label, $name, $value)
1497 global $dateformats;
1499 default_focus($name);
1500 echo "<tr><td>$label</td>\n";
1501 echo "<td><select name='$name'>";
1504 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1506 foreach ($dateformats as $df)
1509 if ($value==$counter)
1511 echo "<option selected value='$counter'>$df</option>\n";
1515 echo "<option value='$counter'>$df</option>\n";
1519 echo "</select></td></tr>\n";
1522 function dateseps_list_row($label, $name, $value)
1526 default_focus($name);
1527 echo "<tr><td>$label</td>\n";
1528 echo "<td><select name='$name'>";
1531 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1533 foreach ($dateseps as $ds)
1536 if ($value==$counter)
1538 echo "<option selected value='$counter'>$ds</option>\n";
1542 echo "<option value='$counter'>$ds</option>\n";
1546 echo "</select></td></tr>\n";
1549 function thoseps_list_row($label, $name, $value)
1553 default_focus($name);
1554 echo "<tr><td>$label</td>\n";
1555 echo "<td><select name='$name'>";
1558 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1560 foreach ($thoseps as $ts)
1563 if ($value==$counter)
1565 echo "<option selected value='$counter'>$ts</option>\n";
1569 echo "<option value='$counter'>$ts</option>\n";
1573 echo "</select></td></tr>\n";
1576 function decseps_list_row($label, $name, $value)
1580 default_focus($name);
1581 echo "<tr><td>$label</td>\n";
1582 echo "<td><select name='$name'>";
1585 $value = (!isset($_POST[$name]) ? 0 : $_POST[$name]);
1587 foreach ($decseps as $ds)
1590 if ($value==$counter)
1592 echo "<option selected value='$counter'>$ds</option>\n";
1596 echo "<option value='$counter'>$ds</option>\n";
1600 echo "</select></td></tr>\n";
1603 function themes_list_row($label, $name, $value)
1605 global $path_to_root;
1607 default_focus($name);
1608 $path = $path_to_root.'/themes/';
1610 $themedir = opendir($path);
1611 while(false !== ($fname = readdir($themedir)))
1613 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1619 echo "<tr><td>$label</td>\n";
1620 echo "<td><select name='$name'>";
1623 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1624 foreach ($themes as $th)
1629 echo "<option selected value='$th'>$th</option>\n";
1633 echo "<option value='$th'>$th</option>\n";
1636 echo "</select></td></tr>\n";
1639 function pagesizes_list_row($label, $name, $value)
1643 default_focus($name);
1644 echo "<tr><td>$label</td>\n";
1645 echo "<td><select name='$name'>";
1648 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1649 foreach ($pagesizes as $pz)
1654 echo "<option selected value='$pz'>$pz</option>\n";
1658 echo "<option value='$pz'>$pz</option>\n";
1661 echo "</select></td></tr>\n";
1664 function security_headings_list_row($label, $name, $value)
1666 global $security_headings;
1668 default_focus($name);
1669 echo "<tr><td>$label</td>\n";
1670 echo "<td><select name='$name'>";
1673 $value = (!isset($_POST[$name]) ? 0 : (int)$_POST[$name]);
1675 foreach ($security_headings as $sh)
1678 if ($value==$counter)
1680 echo "<option selected value='$counter'>$sh</option>\n";
1684 echo "<option value='$counter'>$sh</option>\n";
1688 echo "</select></td></tr>\n";
1691 function systypes_list_cells($label, $name, $value, $submit_on_change=false)
1693 global $systypes_array;
1695 default_focus($name);
1697 echo "<td>$label</td>\n";
1698 echo "<td><select name='$name'";
1699 if ($submit_on_change)
1700 echo " onchange='this.form.submit();'>"; // FIX ajax
1704 $value = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1705 foreach ($systypes_array as $key=>$type)
1710 echo "<option selected value='$key'>".$type['name']."</option>\n";
1714 echo "<option value='$key'>".$type['name']."</option>\n";
1717 echo "</select></td>\n";
1720 function systypes_list_row($label, $name, $value, $submit_on_change=false)
1723 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1728 function cust_allocations_list_cells($label, $name, $selected)
1731 default_focus($name);
1734 if ($selected == null)
1735 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1736 echo "<td><select name='$name'>";
1737 echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
1738 echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Sales Invoices"). "</option>\n";
1739 echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1740 echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1741 echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1742 echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Delivery Notes"). "</option>\n";
1743 echo "</select></td>\n";
1746 function supp_allocations_list_cells($name, $selected)
1750 default_focus($name);
1751 if ($selected == null)
1752 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1753 echo "<td><select name='$name'>";
1754 echo "<option " . ($selected == $all_items ? " selected " : "") . " value='$all_items'>" . _("All Types"). "</option>\n";
1755 echo "<option " . ($selected == '1'?" selected ":"") . " value='1'>" . _("Invoices"). "</option>\n";
1756 echo "<option " . ($selected == '2'?" selected ":"") . " value='2'>" . _("Overdue Invoices"). "</option>\n";
1757 echo "<option " . ($selected == '3'?" selected ":"") . " value='3'>" . _("Payments"). "</option>\n";
1758 echo "<option " . ($selected == '4'?" selected ":"") . " value='4'>" . _("Credit Notes"). "</option>\n";
1759 echo "<option " . ($selected == '5'?" selected ":"") . " value='5'>" . _("Overdue Credit Notes"). "</option>\n";
1760 echo "</select></td>\n";
1763 function policy_list_cells($label, $name, $selected)
1765 default_focus($name);
1766 if ($selected == null)
1768 $selected = (!isset($_POST[$name]) ? "" : $_POST[$name]);
1769 if ($selected == "")
1770 $_POST[$name] = $selected;
1774 echo "<td><select name='$name'>";
1775 echo "<option " . ($selected == ''?" selected ":"") . " value=''>" . _("Automatically put balance on back order"). "</option>\n";
1776 echo "<option " . ($selected == 'CAN'?" selected ":"") . " value='CAN'>" . _("Cancel any quantites not delivered"). "</option>\n";
1777 echo "</select></td>\n";
1780 function policy_list_row($label, $name, $selected)
1783 policy_list_cells($label, $name, $selected);
1787 function credit_type_list_cells($label, $name, $selected, $submit_on_change=false)
1789 default_focus($name);
1790 if ($selected == null)
1792 $selected = (!isset($_POST[$name]) ? "Return" : $_POST[$name]);
1793 if ($selected == "Return")
1794 $_POST[$name] = $selected;
1798 echo "<td><select name='$name'";
1799 if ($submit_on_change)
1800 echo " onchange='this.form.submit();'>"; // FIX ajax
1803 echo "<option " . ($selected == 'Return'?" selected ":"") . " value='Return'>" . _("Items Returned to Inventory Location"). "</option>\n";
1804 echo "<option " . ($selected == 'WriteOff'?" selected ":"") . " value='WriteOff'>" . _("Items Written Off"). "</option>\n";
1805 echo "</select></td>\n";
1808 function credit_type_list_row($label, $name, $selected, $submit_on_change=false)
1811 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1816 function number_list($name, $selected, $from, $to, $firstlabel="")
1818 default_focus($name);
1819 if ($selected == null)
1821 $selected = (!isset($_POST[$name]) ? $from : $_POST[$name]);
1822 if ($selected == $from)
1823 $_POST[$name] = $selected;
1825 echo "<select name='$name'>";
1826 for ($i = $from; $i <= $to; $i++)
1828 if ($i == 0 && $firstlabel != "")
1829 $label = $firstlabel;
1832 if ($selected == $i)
1834 echo "<option selected value='$i'>$label</option>\n";
1838 echo "<option value='$i'>$label</option>\n";
1844 function number_list_cells($label, $name, $selected, $from, $to)
1849 number_list($name, $selected, $from, $to);
1853 function number_list_row($label, $name, $selected, $from, $to)
1856 number_list_cells($label, $name, $selected, $from, $to);