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 '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 ----------
54 $opts = array_merge($opts, $options);
55 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
57 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
58 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
59 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
60 $spec_id = $opts['spec_id'];
61 $spec_option = $opts['spec_option'];
62 $by_id = ($opts['type'] == 0);
63 $class = $by_id ? 'combo':'combo2';
64 $disabled = $opts['disabled'] ? "disabled" : '';
66 if(!count($opts['search'])) {
67 $opts['search'] = array($by_id ? $valfield : $namefield);
69 if ($opts['sel_hint'] === null)
70 $opts['sel_hint'] = $by_id || $search_box==false ?
71 '' : _('Press Space tab for search pattern entry');
73 if ($opts['box_hint'] === null)
74 $opts['box_hint'] = $search_box ?
75 ($by_id ? _('Enter code fragment to search or * for all')
76 : _('Enter description fragment to search or * for all')) :'';
78 if ($selected_id == null) {
79 $selected_id = get_post($name, $opts['default']);
81 $txt = get_post($search_box);
85 if (isset($_POST[$select_submit])) {
87 if ($by_id) $txt = $_POST[$name];
90 $Ajax->activate('_page_body');
92 $Ajax->activate($name);
95 // search related sql modifications
97 $rel = "rel='$search_box'"; // set relation to list
98 if ($opts['search_submit']) {
99 if (isset($_POST[$search_submit])) {
101 $Ajax->activate('_page_body');
103 $Ajax->activate($name);
106 if ($spec_option === false && $selected_id==null)
109 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
114 foreach($opts['search'] as $i=> $s)
115 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
116 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
121 if (count($opts['where'])) {
122 $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
123 $sql .= '('. implode($opts['where'], ' AND ') . ')';
125 if ($opts['order'] != false) {
126 $sql .= ' ORDER BY '.$opts['order'];
130 // ------ make selector ----------
131 $selector = $first_opt = '';
134 //if($name=='SelectStockFromList') display_error($sql);
135 if($result = db_query($sql)) {
136 while ($contact_row = db_fetch($result)) {
137 $value = $contact_row[0];
138 $descr = $opts['format']==null ? $contact_row[1] :
139 call_user_func($opts['format'], $contact_row);
141 if ((string)($selected_id) === $value) {
145 if ($first_id === false) {
149 $selector .= "<option $sel value='$value'>$descr</option>\n";
151 db_free_result($result);
154 // Prepend special option.
155 if ($spec_option !== false) { // if special option used - add it
156 $first_id = $spec_id;
157 $first_opt = $spec_option;
158 $sel = $found===false ? 'selected' : '';
159 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
163 if ($found === false) {
164 $selected_id = $first_id;
166 $_POST[$name] = $selected_id;
168 if ($by_id && $search_box != false) {
169 $txt = $_POST[$name];
170 $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 'default' => '', // default value when $_POST is not set
229 // search box parameters
233 // ------ merge options with defaults ----------
234 $opts = array_merge($opts, $options);
235 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
236 $spec_id = $opts['spec_id'];
237 $spec_option = $opts['spec_option'];
238 $disabled = $opts['disabled'] ? "disabled" : '';
240 if ($selected_id == null) {
241 $selected_id = get_post($name, $opts['default']);
244 if (isset($_POST[$select_submit])) {
246 $Ajax->activate('_page_body');
248 $Ajax->activate($name);
251 // ------ make selector ----------
252 $selector = $first_opt = '';
255 //if($name=='SelectStockFromList') display_error($sql);
256 foreach($items as $value=>$descr) {
258 if ($selected_id == $value) {
262 if ($first_id === false) {
266 $selector .= "<option $sel value='$value'>$descr</option>\n";
269 // Prepend special option.
270 if ($spec_option !== false) { // if special option used - add it
271 $first_id = $spec_id;
272 $first_opt = $spec_option;
273 $sel = $found===false ? 'selected' : '';
274 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
278 if ($found === false) {
279 $_POST[$name] = $first_id;
282 $selector = "<select $disabled name='$name' class='combo' title='"
283 . $opts['sel_hint']."' >".$selector."</select>\n";
285 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
287 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
289 if ($select_submit != false) { // if submit on change is used - add select button
290 global $_select_button;
291 $selector .= sprintf($_select_button, $disabled, user_theme(),
292 (in_ajax() ? 'display:none;':''),
293 $select_submit)."\n";
295 default_focus($name);
300 //----------------------------------------------------------------------------------------------
302 function _format_add_curr($row)
304 static $company_currency;
306 if ($company_currency == null)
308 $company_currency = get_company_currency();
310 return $row[1] . ($row[2] == $company_currency ?
311 '' : (" - " . $row[2]));
314 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
318 $sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ";
320 $mode = get_company_pref('no_supplier_list');
322 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
324 'format' => '_format_add_curr',
325 'search_box' => $mode!=0,
327 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
328 'spec_id' => $all_items,
329 'select_submit'=> $submit_on_change,
331 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
336 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
339 echo "<td>$label</td><td>\n";
340 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change);
345 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
347 echo "<tr><td>$label</td><td>";
348 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
352 //----------------------------------------------------------------------------------------------
354 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
358 $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
360 $mode = get_company_pref('no_customer_list');
362 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
364 'format' => '_format_add_curr',
365 'search_box' => $mode!=0,
368 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
369 'spec_id' => $all_items,
370 'select_submit'=> $submit_on_change,
372 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
377 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
380 echo "<td>$label</td>\n";
382 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
387 function customer_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
389 echo "<tr><td>$label</td><td nowrap>";
390 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
391 echo "</td>\n</tr>\n";
395 //------------------------------------------------------------------------------------------------
397 function customer_branches_list($customer_id, $name, $selected_id=null,
398 $spec_option = true, $enabled=true, $submit_on_change=false)
402 $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
403 WHERE debtor_no='" . $customer_id . "' ";
405 $where = $enabled ? array("disable_trans = 0") : array();
406 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
409 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
410 'spec_id' => $all_items,
411 'select_submit'=> $submit_on_change,
412 'sel_hint' => _('Select customer branch')
415 //------------------------------------------------------------------------------------------------
417 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
420 echo "<td>$label</td>\n";
422 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
427 function customer_branches_list_row($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
430 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
435 //------------------------------------------------------------------------------------------------
437 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
441 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
443 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
445 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
446 'spec_id' => $all_items,
447 'select_submit'=> $submit_on_change
451 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
454 echo "<td>$label</td>\n";
456 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
461 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
464 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
469 //-----------------------------------------------------------------------------------------------
471 function currencies_list($name, $selected_id=null, $submit_on_change=false)
473 $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
475 // default to the company currency
477 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
479 'select_submit'=> $submit_on_change,
480 'default' => get_company_currency(),
485 function currencies_list_cells($label, $name, $selected_id=null)
488 echo "<td>$label</td>\n";
490 $str = currencies_list($name, $selected_id);
495 function currencies_list_row($label, $name, $selected_id=null)
498 $str = currencies_list_cells($label, $name, $selected_id);
503 //---------------------------------------------------------------------------------------------------
505 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
508 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
510 // default to the company current fiscal year
512 return combo_input($name, $selected_id, $sql, 'id', '',
515 'default' => get_company_pref('f_year'),
516 'format' => '_format_fiscalyears',
517 'select_submit'=> $submit_on_change,
522 function _format_fiscalyears($row)
524 return sql2date($row[1]) . " - " . sql2date($row[2])
525 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
528 function fiscalyears_list_cells($label, $name, $selected_id=null)
531 echo "<td>$label</td>\n";
533 $str = fiscalyears_list($name, $selected_id);
538 function fiscalyears_list_row($label, $name, $selected_id=null)
541 $str = fiscalyears_list_cells($label, $name, $selected_id);
545 //------------------------------------------------------------------------------------
547 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
548 $submit_on_change=false, $showclosed=false, $showtype=1)
550 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
553 'order' => 'reference',
554 'spec_option'=>$no_option ? $showname : false,
556 'select_submit'=> $submit_on_change,
561 $options['where'][] = "closed=0";
563 $options['where'][] = "type_=$showtype";
565 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
568 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
569 $showclosed=false, $showtype=0)
572 echo "<td>$label</td>\n";
574 $str = dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
579 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
580 $showclosed=false, $showtype=0)
583 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
584 $showclosed, $showtype);
589 //---------------------------------------------------------------------------------------------------
591 function stock_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $opts=array())
595 $sql = "SELECT stock_id, s.description, c.description
596 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
598 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
601 'format' => '_format_stock_items',
602 'spec_option' => $all_option===true ? _("All Items") : $all_option,
603 'spec_id' => $all_items,
604 'search_box' => true,
605 'search' => array("stock_id", "c.description","s.description"),
606 'search_submit' => get_company_pref('no_item_list')!=0,
608 'select_submit'=> $submit_on_change
612 function _format_stock_items($row)
614 return (user_show_codes() ? ($row[0] . " - ") : "")
615 . $row[2] . " - " . $row[1];
618 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
621 echo "<td>$label</td>\n";
622 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
623 array('cells'=>true));
627 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
630 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
635 //------------------------------------------------------------------------------------
637 function base_stock_items_list($where, $name, $selected_id=null,
638 $all_option=false, $submit_on_change=false)
642 $sql = "SELECT stock_id, s.description, c.description
643 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
644 s.category_id=c.category_id";
646 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
648 'format' => '_format_stock_items',
649 'spec_option' => $all_option==true ? _("All Items") : $all_option,
650 'spec_id' => $all_items,
651 'select_submit'=> $submit_on_change,
655 //------------------------------------------------------------------------------------
657 function stock_bom_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
660 return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
661 $name, $selected_id, $all_option, $submit_on_change);
664 function stock_bom_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
667 echo "<td>$label</td>\n";
669 $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
674 function stock_bom_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
677 $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
682 //------------------------------------------------------------------------------------
684 function stock_manufactured_items_list($name, $selected_id=null,
685 $all_option=false, $submit_on_change=false)
687 return base_stock_items_list("s.mb_flag='M'",
688 $name, $selected_id, $all_option, $submit_on_change);
691 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
692 $all_option=false, $submit_on_change=false)
695 echo "<td>$label</td>\n";
697 $str = stock_manufactured_items_list($name, $selected_id, $all_option,
703 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
704 $all_option=false, $submit_on_change=false)
707 $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
708 $all_option, $submit_on_change);
712 //------------------------------------------------------------------------------------
714 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
715 $all_option=false, $submit_on_change=false)
717 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
718 array('where'=>array("stock_id != '$parent_stock_id'")));
722 function stock_component_items_list_cells($label, $name, $parent_stock_id,
723 $selected_id=null, $all_option=false, $submit_on_change=false)
726 echo "<td>$label</td>\n";
727 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
728 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true));
731 //------------------------------------------------------------------------------------
733 function stock_costable_items_list($name, $selected_id=null,
734 $all_option=false, $submit_on_change=false)
736 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
737 array('where'=>array("mb_flag!='D'")));
741 function stock_costable_items_list_cells($label, $name, $selected_id=null,
742 $all_option=false, $submit_on_change=false)
745 echo "<td>$label</td>\n";
746 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
747 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
751 //------------------------------------------------------------------------------------
752 function stock_purchasable_items_list($name, $selected_id=null,
753 $all_option=false, $submit_on_change=false)
755 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
756 array('where'=>array("mb_flag!= 'M'")));
760 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
761 $all_option=false, $submit_on_change=false)
764 echo "<td>$label</td>\n";
765 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
766 array('where'=>array("mb_flag!= 'M'"), 'cells'=>true));
770 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
771 $all_option=false, $submit_on_change=false)
774 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
775 $all_option, $submit_on_change);
780 //------------------------------------------------------------------------------------
782 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
785 'M' => _("Manufactured"),
786 'B' => _("Purchased"),
792 echo "<td>$label</td>\n";
795 array_selector($name, $selected_id, $types,
797 'select_submit'=> true,
798 'disabled' => !$enabled) );
802 function stock_units_list_row($label, $name, $value=null, $enabled=true)
804 $result = get_all_item_units();
807 echo "<td>$label</td>\n";
810 while($unit = db_fetch($result))
811 $units[$unit['abbr']] = $unit['name'];
813 array_selector($name, $value, $units,
815 'select_submit'=> true,
816 'disabled' => !$enabled) );
821 //------------------------------------------------------------------------------------
823 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
825 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
827 return combo_input($name, $selected_id, $sql, 'id', 'name',
829 'spec_option' => $none_option,
830 'spec_id' => reserved_words::get_all_numeric(),
831 'select_submit'=> $submit_on_change,
836 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
837 $submit_on_change=false)
840 echo "<td>$label</td>\n";
842 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
847 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
848 $submit_on_change=false)
851 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
856 //------------------------------------------------------------------------------------
858 function tax_groups_list($name, $selected_id=null,
859 $none_option=false, $submit_on_change=false)
861 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
863 return combo_input($name, $selected_id, $sql, 'id', 'name',
866 'spec_option' => $none_option,
868 'select_submit'=> $submit_on_change,
873 function tax_groups_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
876 echo "<td>$label</td>\n";
878 $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
883 function tax_groups_list_row($label, $name, $selected_id=null, $submit_on_change=false)
886 $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
891 //------------------------------------------------------------------------------------
893 function item_tax_types_list($name, $selected_id=null)
895 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
896 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
899 function item_tax_types_list_cells($label, $name, $selected_id=null)
902 echo "<td>$label</td>\n";
904 item_tax_types_list($name, $selected_id);
908 function item_tax_types_list_row($label, $name, $selected_id=null)
911 item_tax_types_list_cells($label, $name, $selected_id);
915 //------------------------------------------------------------------------------------
917 function shippers_list($name, $selected_id=null)
919 $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
920 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
923 function shippers_list_cells($label, $name, $selected_id=null)
926 echo "<td>$label</td>\n";
928 shippers_list($name, $selected_id);
932 function shippers_list_row($label, $name, $selected_id=null)
935 shippers_list_cells($label, $name, $selected_id);
939 //-------------------------------------------------------------------------------------
941 function sales_persons_list($name, $selected_id=null)
943 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
944 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
947 function sales_persons_list_cells($label, $name, $selected_id=null)
950 echo "<td>$label</td>\n";
952 sales_persons_list($name, $selected_id);
956 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
959 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
963 //------------------------------------------------------------------------------------
965 function sales_areas_list($name, $selected_id=null)
967 $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
968 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
971 function sales_areas_list_cells($label, $name, $selected_id=null)
974 echo "<td>$label</td>\n";
976 sales_areas_list($name, $selected_id);
980 function sales_areas_list_row($label, $name, $selected_id=null)
983 sales_areas_list_cells($label, $name, $selected_id);
987 //------------------------------------------------------------------------------------
989 function workorders_list($name, $selected_id=null)
991 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
992 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
995 function workorders_list_cells($label, $name, $selected_id=null)
998 echo "<td>$label</td>\n";
1000 workorders_list($name, $selected_id);
1004 function workorders_list_row($label, $name, $selected_id=null)
1007 workorders_list_cells($label, $name, $selected_id);
1011 //------------------------------------------------------------------------------------
1013 function payment_terms_list($name, $selected_id=null)
1015 $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
1016 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1019 function payment_terms_list_cells($label, $name, $selected_id=null)
1022 echo "<td>$label</td>\n";
1024 payment_terms_list($name, $selected_id);
1028 function payment_terms_list_row($label, $name, $selected_id=null)
1031 payment_terms_list_cells($label, $name, $selected_id);
1035 //------------------------------------------------------------------------------------
1037 function credit_status_list($name, $selected_id=null)
1039 $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
1040 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1043 function credit_status_list_cells($label, $name, $selected_id=null)
1046 echo "<td>$label</td>\n";
1048 credit_status_list($name, $selected_id);
1052 function credit_status_list_row($label, $name, $selected_id=null)
1055 credit_status_list_cells($label, $name, $selected_id);
1059 //-----------------------------------------------------------------------------------------------
1061 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1063 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
1065 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1067 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1069 'select_submit'=> $submit_on_change,
1070 // 'async' => false,
1074 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1077 echo "<td>$label</td>\n";
1079 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1084 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1087 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1092 //-----------------------------------------------------------------------------------------------
1094 function movement_types_list($name, $selected_id=null)
1096 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1097 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1100 function movement_types_list_cells($label, $name, $selected_id=null)
1103 echo "<td>$label</td>\n";
1105 movement_types_list($name, $selected_id);
1109 function movement_types_list_row($label, $name, $selected_id=null)
1112 movement_types_list_cells($label, $name, $selected_id);
1116 //-----------------------------------------------------------------------------------------------
1118 function bank_trans_types_list($name, $selected_id=null)
1120 $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1121 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1124 function bank_trans_types_list_cells($label, $name, $selected_id=null)
1127 echo "<td>$label</td>\n";
1129 bank_trans_types_list($name, $selected_id);
1133 function bank_trans_types_list_row($label, $name, $selected_id=null)
1136 bank_trans_types_list_cells($label, $name, $selected_id);
1140 //-----------------------------------------------------------------------------------------------
1142 function workcenter_list($name, $selected_id=null, $all_option=false)
1146 $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1148 return combo_input($name, $selected_id, $sql, 'id', 'name',
1150 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1151 'spec_id' => $all_items,
1155 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1157 default_focus($name);
1159 echo "<td>$label</td>\n";
1161 workcenter_list($name, $selected_id, $all_option);
1165 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1168 workcenter_list_cells($label, $name, $selected_id, $all_option);
1172 //-----------------------------------------------------------------------------------------------
1174 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1176 $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1177 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1178 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1180 return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1182 'format' => '_format_add_curr',
1183 'select_submit'=> $submit_on_change,
1188 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1191 echo "<td>$label</td>\n";
1193 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1198 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1201 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1206 //-----------------------------------------------------------------------------------------------
1208 function class_list($name, $selected_id=null, $submit_on_change=false)
1210 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1212 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1214 'select_submit'=> $submit_on_change,
1220 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1223 echo "<td>$label</td>\n";
1225 $str = class_list($name, $selected_id, $submit_on_change);
1230 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1233 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1238 //-----------------------------------------------------------------------------------------------
1240 function stock_categories_list($name, $selected_id=null)
1242 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1243 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1244 array('order'=>'category_id'));
1247 function stock_categories_list_cells($label, $name, $selected_id=null)
1250 echo "<td>$label</td>\n";
1252 stock_categories_list($name, $selected_id);
1256 function stock_categories_list_row($label, $name, $selected_id=null)
1259 stock_categories_list_cells($label, $name, $selected_id);
1263 //-----------------------------------------------------------------------------------------------
1265 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1269 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1271 combo_input($name, $selected_id, $sql, 'id', 'name',
1274 'spec_option' =>$all_option,
1275 'spec_id' => $all_option_numeric ? 0 : $all_items
1279 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1280 $all_option_numeric=false)
1283 echo "<td>$label</td>\n";
1285 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1289 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1290 $all_option_numeric=false)
1293 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1294 $all_option_numeric);
1298 //-----------------------------------------------------------------------------------------------
1299 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1300 $show_group=false, $cells=false, $all_option=false)
1302 if ($skip_bank_accounts)
1303 $sql = "SELECT chart.account_code, chart.account_name, type.name
1304 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1305 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1306 ."ON chart.account_code=acc.account_code
1307 WHERE acc.account_code IS NULL
1308 AND chart.account_type=type.id";
1310 $sql = "SELECT chart.account_code, chart.account_name, type.name
1311 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1312 WHERE chart.account_type=type.id";
1314 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1316 'format' => '_format_account' . ($show_group ? '2' : ''),
1317 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1319 'order' => 'account_code',
1320 'search_box' => $cells,
1321 'search_submit' => false,
1329 function _format_account($row)
1331 return $row[0] . " " . $row[1];
1334 function _format_account2($row)
1336 return $row[0] . " " . $row[2] . " " . $row[1];
1339 function gl_all_accounts_list_cells($label, $name, $selected_id=null, $skip_bank_accounts=false,
1340 $show_group=false, $cells=false, $all_option=false)
1343 echo "<td>$label</td>\n";
1345 gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1349 function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_accounts=false,
1350 $show_group=false, $cells=false, $all_option=false)
1353 gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1354 $show_group, $cells, $all_option);
1358 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1361 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1362 $items['0'] = strlen($name_no) ? $name_no : _("No");
1364 return array_selector($name, $selected_id, $items,
1366 'select_submit'=> true,
1367 'async' => false ) ); // FIX?
1370 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1373 echo "<td>$label</td>\n";
1375 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1380 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1383 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1388 //------------------------------------------------------------------------------------------------
1390 function languages_list($name, $selected_id=null)
1392 global $installed_languages;
1395 foreach ($installed_languages as $lang)
1396 $items[$lang['code']] = $lang['name'];
1398 return array_selector($name, $selected_id, $items );
1401 function languages_list_cells($label, $name, $selected_id=null)
1404 echo "<td>$label</td>\n";
1406 languages_list($name, $selected_id);
1410 function languages_list_row($label, $name, $selected_id=null)
1413 languages_list_cells($label, $name, $selected_id);
1417 //------------------------------------------------------------------------------------------------
1419 function bank_account_types_list($name, $selected_id=null)
1421 $types = bank_account_types::get_all();
1424 foreach ($types as $type)
1426 if (payment_person_types::has_items($type['id']))
1428 $items[$type['id']] = $type['name'];
1432 return array_selector($name, $selected_id, $items );
1435 function bank_account_types_list_cells($label, $name, $selected_id=null)
1438 echo "<td>$label</td>\n";
1440 bank_account_types_list($name, $selected_id);
1444 function bank_account_types_list_row($label, $name, $selected_id=null)
1447 bank_account_types_list_cells($label, $name, $selected_id);
1451 //------------------------------------------------------------------------------------------------
1452 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1454 $types = payment_person_types::get_all();
1457 foreach ($types as $type)
1459 if (payment_person_types::has_items($type['id']))
1461 $items[$type['id']] = $type['name'];
1465 return array_selector($name, $selected_id, $items,
1466 array( 'select_submit'=> $submit_on_change ) );
1469 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1472 echo "<td>$label</td>\n";
1474 $str = payment_person_types_list($name, $selected_id, $related);
1479 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1482 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1487 //------------------------------------------------------------------------------------------------
1489 function wo_types_list($name, $selected_id=null)
1491 $types = wo_types::get_all();
1494 foreach ($types as $type)
1495 $items[$type['id']] = $type['name'];
1497 return array_selector($name, $selected_id, $items,
1498 array( 'select_submit'=> true, 'async' => true ) );
1501 function wo_types_list_row($label, $name, $selected_id=null)
1503 echo "<tr><td>$label</td><td>\n";
1504 $str = wo_types_list($name, $selected_id);
1505 echo "</td></tr>\n";
1509 //------------------------------------------------------------------------------------------------
1511 function dateformats_list_row($label, $name, $value=null)
1513 global $dateformats;
1515 echo "<tr><td>$label</td>\n<td>";
1516 array_selector( $name, $value, $dateformats );
1517 echo "</td></tr>\n";
1520 function dateseps_list_row($label, $name, $value=null)
1524 echo "<tr><td>$label</td>\n<td>";
1525 array_selector( $name, $value, $dateseps );
1526 echo "</td></tr>\n";
1529 function thoseps_list_row($label, $name, $value=null)
1533 echo "<tr><td>$label</td>\n<td>";
1534 array_selector( $name, $value, $thoseps );
1535 echo "</td></tr>\n";
1538 function decseps_list_row($label, $name, $value=null)
1542 echo "<tr><td>$label</td>\n<td>";
1543 array_selector( $name, $value, $decseps );
1544 echo "</td></tr>\n";
1547 function themes_list_row($label, $name, $value=null)
1549 global $path_to_root;
1551 $path = $path_to_root.'/themes/';
1553 $themedir = opendir($path);
1554 while(false !== ($fname = readdir($themedir)))
1556 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1558 $themes[$fname] = $fname;
1563 echo "<tr><td>$label</td>\n<td>";
1564 array_selector( $name, $value, $themes );
1565 echo "</td></tr>\n";
1568 function pagesizes_list_row($label, $name, $value=null)
1573 foreach ($pagesizes as $pz)
1576 echo "<tr><td>$label</td>\n<td>";
1577 array_selector( $name, $value, $items );
1578 echo "</td></tr>\n";
1581 function security_headings_list_row($label, $name, $value=null)
1583 global $security_headings;
1585 echo "<tr><td>$label</td>\n<td>";
1586 array_selector( $name, $value, $security_headings );
1587 echo "</td></tr>\n";
1590 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1592 global $systypes_array;
1595 echo "<td>$label</td>\n";
1599 foreach ($systypes_array as $key=>$type)
1600 $items[$key] = $type['name'];
1602 $str = array_selector($name, $value, $items,
1604 'select_submit'=> $submit_on_change,
1612 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1615 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1620 function cust_allocations_list_cells($label, $name, $selected=null)
1628 $all_items=>_("All Types"),
1629 '1'=> _("Sales Invoices"),
1630 '2'=> _("Overdue Invoices"),
1631 '3' => _("Payments"),
1632 '4' => _("Credit Notes"),
1633 '5' => _("Delivery Notes")
1635 $str = array_selector($name, $selected, $allocs);
1640 function supp_allocations_list_cell($name, $selected=null)
1646 $all_items=>_("All Types"),
1647 '1'=> _("Invoices"),
1648 '2'=> _("Overdue Invoices"),
1649 '3' => _("Payments"),
1650 '4' => _("Credit Notes"),
1651 '5' => _("Overdue Credit Notes")
1653 $str = array_selector($name, $selected, $allocs);
1658 function policy_list_cells($label, $name, $selected=null)
1663 $str = array_selector($name, $selected,
1664 array( '' => _("Automatically put balance on back order"),
1665 'CAN' => _("Cancel any quantites not delivered")) );
1670 function policy_list_row($label, $name, $selected=null)
1673 policy_list_cells($label, $name, $selected);
1677 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1682 $str = array_selector($name, $selected,
1683 array( 'Return' => _("Items Returned to Inventory Location"),
1684 'WriteOff' => _("Items Written Off")),
1685 array( 'select_submit'=> $submit_on_change ) );
1690 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1693 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1698 function number_list($name, $selected, $from, $to, $no_option=false)
1701 for ($i = $from; $i <= $to; $i++)
1704 return array_selector($name, $selected, $items,
1705 array( 'spec_option' => $no_option,
1706 'spec_id' => reserved_words::get_all_numeric()) );
1709 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1714 number_list($name, $selected, $from, $to, $no_option);
1718 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1721 number_list_cells($label, $name, $selected, $from, $to, $no_option);