3 include_once($path_to_root . "/includes/banking.inc");
4 include_once($path_to_root . "/includes/reserved.inc");
5 include_once($path_to_root . "/includes/types.inc");
6 include_once($path_to_root . "/includes/current_user.inc");
8 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
9 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
11 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
12 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
14 $all_items = reserved_words::get_all();
16 //----------------------------------------------------------------------------
17 // Universal sql combo generator
18 // $sql must return selector values and selector texts in columns 0 & 1
19 // Options are merged with defaults.
21 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
26 $opts = array( // default options
27 'where'=> array(), // additional constraints
28 'order' => $namefield, // list sort order
29 // special option parameters
30 'spec_option'=>false, // option text or false
31 'spec_id' => 0, // option id
32 // submit on select parameters
33 'default' => '', // default value when $_POST is not set
34 'select_submit' => false, //submit on select: true/false
35 'edit_submit' => false, // call editor on F4
36 'async' => true, // select update via ajax (true) vs _page_body reload
37 // search box parameters
39 'search_box' => false, // name or true/false
40 'type' => 0, // type of extended selector:
41 // 0 - with (optional) visible search box, search by id
42 // 1 - with hidden search box, search by option text
43 // 2 - TODO reverse: box with hidden selector available via enter; this
44 // would be convenient for optional ad hoc adding of new item
45 'search_submit' => true, //search submit button: true/false
46 'size' => 8, // size and max of box tag
48 'cells' => false, // combo displayed as 2 <td></td> cells
49 'search' => array(), // sql field names to search
50 'format' => null, // format functions for regular options
52 'box_hint' => null // box/selectors hints; null = std see below
54 // ------ merge options with defaults ----------
56 $opts = array_merge($opts, $options);
57 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
59 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
60 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
61 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
62 $spec_id = $opts['spec_id'];
63 $spec_option = $opts['spec_option'];
64 $by_id = ($opts['type'] == 0);
65 $class = $by_id ? 'combo':'combo2';
66 $disabled = $opts['disabled'] ? "disabled" : '';
68 if(!count($opts['search'])) {
69 $opts['search'] = array($by_id ? $valfield : $namefield);
71 if ($opts['sel_hint'] === null)
72 $opts['sel_hint'] = $by_id || $search_box==false ?
73 '' : _('Press Space tab for search pattern entry');
75 if ($opts['box_hint'] === null)
76 $opts['box_hint'] = $search_box && $search_submit != false ?
77 ($by_id ? _('Enter code fragment to search or * for all')
78 : _('Enter description fragment to search or * for all')) :'';
80 if ($selected_id == null) {
81 $selected_id = get_post($name, $opts['default']);
83 $txt = get_post($search_box);
87 if (isset($_POST[$select_submit])) {
88 if ($by_id) $txt = $_POST[$name];
91 $Ajax->activate('_page_body');
93 $Ajax->activate($name);
96 // search related sql modifications
98 $rel = "rel='$search_box'"; // set relation to list
99 if ($opts['search_submit']) {
100 if (isset($_POST[$search_submit])) {
101 $selected_id = ''; // ignore selected_id while search
103 $Ajax->activate('_page_body');
105 $Ajax->activate($name);
108 if ($spec_option === false && $selected_id==null)
111 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
116 foreach($opts['search'] as $i=> $s)
117 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
118 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
123 if (count($opts['where'])) {
124 $sql .= strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
125 $sql .= '('. implode($opts['where'], ' AND ') . ')';
127 if ($opts['order'] != false) {
128 $sql .= ' ORDER BY '.$opts['order'];
132 // ------ make selector ----------
133 $selector = $first_opt = '';
136 //if($name=='SelectStockFromList') display_error($sql);
137 if($result = db_query($sql)) {
138 while ($contact_row = db_fetch($result)) {
139 $value = $contact_row[0];
140 $descr = $opts['format']==null ? $contact_row[1] :
141 call_user_func($opts['format'], $contact_row);
143 if (get_post($search_submit) && ($txt === $value)) {
144 $selected_id = $value;
146 if (get_post($search_submit) && ($txt === $value)) {
147 $selected_id = $value;
149 if ((string)($selected_id) === $value) {
153 if ($first_id === false) {
157 $selector .= "<option $sel value='$value'>$descr</option>\n";
159 db_free_result($result);
162 // Prepend special option.
163 if ($spec_option !== false) { // if special option used - add it
164 $first_id = $spec_id;
165 $first_opt = $spec_option;
166 $sel = $found===false ? 'selected' : '';
167 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
171 if ($found === false) {
172 $selected_id = $first_id;
174 $_POST[$name] = $selected_id;
176 if ($by_id && $search_box != false) {
178 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
180 $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
181 $selector = "<select $disabled name='$name' class='$class' title='"
182 . $opts['sel_hint']."'$aspect $rel>".$selector."</select>\n";
184 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
186 // because of bug which M$ cannot fix since IE 5.0
187 // we must embed whole selector in span tags to enable proper ajax update
188 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
190 if ($select_submit != false) { // if submit on change is used - add select button
191 global $_select_button;
192 // button class selects form reload/ajax selector update
193 $selector .= sprintf($_select_button, $disabled, user_theme(),
194 (in_ajax() ? 'display:none;':''),
195 $select_submit)."\n";
197 // ------ make combo ----------
200 if ($search_box != false) {
201 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
202 $opts['size']."' maxlength='".$opts['max'].
203 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
204 .$opts['box_hint']."'"
205 .(in_ajax() && !$by_id ? " style=display:none;":'')
207 if ($search_submit != false) {
208 global $_search_button;
209 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
210 (in_ajax() ? 'display:none;':''),
211 $search_submit)."\n";
214 default_focus($name);
216 if ($search_box && $opts['cells'])
217 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
219 echo $edit_entry.$selector;
226 Returns true if selector $name is subject to update.
228 function list_updated($name)
230 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
232 //----------------------------------------------------------------------------------------------
233 // Universal array combo generator
234 // $items is array of options 'value' => 'description'
235 // Options is reduced set of combo_selector options and is merged with defaults.
237 function array_selector($name, $selected_id, $items, $options=null)
241 $opts = array( // default options
242 'spec_option'=>false, // option text or false
243 'spec_id' => 0, // option id
244 'select_submit' => false, //submit on select: true/false
245 'edit_submit' => false, // call editor on F4
246 'async' => true, // select update via ajax (true) vs _page_body reload
247 'default' => '', // default value when $_POST is not set
248 // search box parameters
252 // ------ merge options with defaults ----------
254 $opts = array_merge($opts, $options);
255 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
256 $spec_id = $opts['spec_id'];
257 $spec_option = $opts['spec_option'];
258 $disabled = $opts['disabled'] ? "disabled" : '';
260 if ($selected_id == null) {
261 $selected_id = get_post($name, $opts['default']);
264 if (isset($_POST[$select_submit])) {
266 $Ajax->activate('_page_body');
268 $Ajax->activate($name);
271 // ------ make selector ----------
272 $selector = $first_opt = '';
275 //if($name=='SelectStockFromList') display_error($sql);
276 foreach($items as $value=>$descr) {
278 if ($selected_id == $value) {
282 if ($first_id === false) {
286 $selector .= "<option $sel value='$value'>$descr</option>\n";
289 // Prepend special option.
290 if ($spec_option !== false) { // if special option used - add it
291 $first_id = $spec_id;
292 $first_opt = $spec_option;
293 $sel = $found===false ? 'selected' : '';
294 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
298 if ($found === false) {
299 $_POST[$name] = $first_id;
302 $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
303 $selector = "<select $disabled name='$name' class='combo' title='"
304 . $opts['sel_hint']."'$aspect >".$selector."</select>\n";
306 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
308 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
310 if ($select_submit != false) { // if submit on change is used - add select button
311 global $_select_button;
312 $selector .= sprintf($_select_button, $disabled, user_theme(),
313 (in_ajax() ? 'display:none;':''),
314 $select_submit)."\n";
316 default_focus($name);
321 //----------------------------------------------------------------------------------------------
323 function _format_add_curr($row)
325 static $company_currency;
327 if ($company_currency == null)
329 $company_currency = get_company_currency();
331 return $row[1] . ($row[2] == $company_currency ?
332 '' : (" - " . $row[2]));
335 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
339 $sql = "SELECT supplier_id, supp_name, curr_code FROM ".TB_PREF."suppliers ";
341 $mode = get_company_pref('no_supplier_list');
343 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
345 'format' => '_format_add_curr',
346 'search_box' => $mode!=0,
347 'edit_submit' => true,
349 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
350 'spec_id' => $all_items,
351 'select_submit'=> $submit_on_change,
353 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
358 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
361 echo "<td>$label</td><td>\n";
362 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change);
367 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
369 echo "<tr><td>$label</td><td>";
370 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
374 //----------------------------------------------------------------------------------------------
376 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false)
380 $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
382 $mode = get_company_pref('no_customer_list');
384 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
386 'format' => '_format_add_curr',
387 'search_box' => $mode!=0,
390 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
391 'spec_id' => $all_items,
392 'select_submit'=> $submit_on_change,
393 'edit_submit' => true, // call editor on F4
395 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F4 - entry new customer') :
400 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
403 echo "<td>$label</td>\n";
405 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
410 function customer_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
412 echo "<tr><td>$label</td><td nowrap>";
413 $str = customer_list($name, $selected_id, $all_option, $submit_on_change);
414 echo "</td>\n</tr>\n";
418 //------------------------------------------------------------------------------------------------
420 function customer_branches_list($customer_id, $name, $selected_id=null,
421 $spec_option = true, $enabled=true, $submit_on_change=false)
425 $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
426 WHERE debtor_no='" . $customer_id . "' ";
428 $where = $enabled ? array("disable_trans = 0") : array();
429 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
432 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
433 'spec_id' => $all_items,
434 'select_submit'=> $submit_on_change,
435 'sel_hint' => _('Select customer branch')
438 //------------------------------------------------------------------------------------------------
440 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
443 echo "<td>$label</td>\n";
445 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
450 function customer_branches_list_row($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
453 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
458 //------------------------------------------------------------------------------------------------
460 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
464 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
466 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
468 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
469 'spec_id' => $all_items,
470 'select_submit'=> $submit_on_change
474 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
477 echo "<td>$label</td>\n";
479 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
484 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
487 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
492 //-----------------------------------------------------------------------------------------------
494 function currencies_list($name, $selected_id=null, $submit_on_change=false)
496 $sql = "SELECT curr_abrev, currency FROM ".TB_PREF."currencies";
498 // default to the company currency
500 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
502 'select_submit'=> $submit_on_change,
503 'default' => get_company_currency(),
508 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
511 echo "<td>$label</td>\n";
513 $str = currencies_list($name, $selected_id, $submit_on_change);
518 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
521 $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
526 //---------------------------------------------------------------------------------------------------
528 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
531 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
533 // default to the company current fiscal year
535 return combo_input($name, $selected_id, $sql, 'id', '',
538 'default' => get_company_pref('f_year'),
539 'format' => '_format_fiscalyears',
540 'select_submit'=> $submit_on_change,
545 function _format_fiscalyears($row)
547 return sql2date($row[1]) . " - " . sql2date($row[2])
548 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
551 function fiscalyears_list_cells($label, $name, $selected_id=null)
554 echo "<td>$label</td>\n";
556 $str = fiscalyears_list($name, $selected_id);
561 function fiscalyears_list_row($label, $name, $selected_id=null)
564 $str = fiscalyears_list_cells($label, $name, $selected_id);
568 //------------------------------------------------------------------------------------
570 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
571 $submit_on_change=false, $showclosed=false, $showtype=1)
573 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
576 'order' => 'reference',
577 'spec_option'=>$no_option ? $showname : false,
579 'select_submit'=> $submit_on_change,
584 $options['where'][] = "closed=0";
586 $options['where'][] = "type_=$showtype";
588 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
591 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
592 $showclosed=false, $showtype=0)
595 echo "<td>$label</td>\n";
597 $str = dimensions_list($name, $selected_id, $no_option, $showname, false, $showclosed, $showtype);
602 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
603 $showclosed=false, $showtype=0)
606 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
607 $showclosed, $showtype);
612 //---------------------------------------------------------------------------------------------------
614 function stock_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $opts=array())
618 $sql = "SELECT stock_id, s.description, c.description
619 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
621 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
624 'format' => '_format_stock_items',
625 'spec_option' => $all_option===true ? _("All Items") : $all_option,
626 'spec_id' => $all_items,
627 'search_box' => true,
628 'search' => array("stock_id", "c.description","s.description"),
629 'search_submit' => get_company_pref('no_item_list')!=0,
631 'select_submit'=> $submit_on_change
635 function _format_stock_items($row)
637 return (user_show_codes() ? ($row[0] . " - ") : "")
638 . $row[2] . " - " . $row[1];
641 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
644 echo "<td>$label</td>\n";
645 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
646 array('cells'=>true));
650 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
653 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
658 //------------------------------------------------------------------------------------
660 function base_stock_items_list($where, $name, $selected_id=null,
661 $all_option=false, $submit_on_change=false)
665 $sql = "SELECT stock_id, s.description, c.description
666 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
667 s.category_id=c.category_id";
669 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
671 'format' => '_format_stock_items',
672 'spec_option' => $all_option==true ? _("All Items") : $all_option,
673 'spec_id' => $all_items,
674 'select_submit'=> $submit_on_change,
678 //------------------------------------------------------------------------------------
680 function stock_bom_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
683 return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
684 $name, $selected_id, $all_option, $submit_on_change);
687 function stock_bom_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
690 echo "<td>$label</td>\n";
692 $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
697 function stock_bom_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
700 $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
705 //------------------------------------------------------------------------------------
707 function stock_manufactured_items_list($name, $selected_id=null,
708 $all_option=false, $submit_on_change=false)
710 return base_stock_items_list("s.mb_flag='M'",
711 $name, $selected_id, $all_option, $submit_on_change);
714 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
715 $all_option=false, $submit_on_change=false)
718 echo "<td>$label</td>\n";
720 $str = stock_manufactured_items_list($name, $selected_id, $all_option,
726 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
727 $all_option=false, $submit_on_change=false)
730 $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
731 $all_option, $submit_on_change);
735 //------------------------------------------------------------------------------------
737 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
738 $all_option=false, $submit_on_change=false)
740 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
741 array('where'=>array("stock_id != '$parent_stock_id'")));
745 function stock_component_items_list_cells($label, $name, $parent_stock_id,
746 $selected_id=null, $all_option=false, $submit_on_change=false)
749 echo "<td>$label</td>\n";
750 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
751 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true));
754 //------------------------------------------------------------------------------------
756 function stock_costable_items_list($name, $selected_id=null,
757 $all_option=false, $submit_on_change=false)
759 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
760 array('where'=>array("mb_flag!='D'")));
764 function stock_costable_items_list_cells($label, $name, $selected_id=null,
765 $all_option=false, $submit_on_change=false)
768 echo "<td>$label</td>\n";
769 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
770 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
774 //------------------------------------------------------------------------------------
775 function stock_purchasable_items_list($name, $selected_id=null,
776 $all_option=false, $submit_on_change=false)
778 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
779 array('where'=>array("mb_flag!= 'M'"),
780 'edit_submit' => true));
784 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
785 $all_option=false, $submit_on_change=false)
788 echo "<td>$label</td>\n";
789 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
790 array('where'=>array("mb_flag!= 'M'"),
791 'edit_submit' => true,
796 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
797 $all_option=false, $submit_on_change=false)
800 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
801 $all_option, $submit_on_change);
806 //------------------------------------------------------------------------------------
808 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
811 'M' => _("Manufactured"),
812 'B' => _("Purchased"),
818 echo "<td>$label</td>\n";
821 array_selector($name, $selected_id, $types,
823 'select_submit'=> true,
824 'disabled' => !$enabled) );
828 function stock_units_list_row($label, $name, $value=null, $enabled=true)
830 $result = get_all_item_units();
833 echo "<td>$label</td>\n";
836 while($unit = db_fetch($result))
837 $units[$unit['abbr']] = $unit['name'];
839 array_selector($name, $value, $units,
841 'select_submit'=> true,
842 'disabled' => !$enabled) );
847 //------------------------------------------------------------------------------------
849 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
851 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
853 return combo_input($name, $selected_id, $sql, 'id', 'name',
855 'spec_option' => $none_option,
856 'spec_id' => reserved_words::get_all_numeric(),
857 'select_submit'=> $submit_on_change,
862 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
863 $submit_on_change=false)
866 echo "<td>$label</td>\n";
868 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
873 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
874 $submit_on_change=false)
877 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
882 //------------------------------------------------------------------------------------
884 function tax_groups_list($name, $selected_id=null,
885 $none_option=false, $submit_on_change=false)
887 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
889 return combo_input($name, $selected_id, $sql, 'id', 'name',
892 'spec_option' => $none_option,
894 'select_submit'=> $submit_on_change,
899 function tax_groups_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
902 echo "<td>$label</td>\n";
904 $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
909 function tax_groups_list_row($label, $name, $selected_id=null, $submit_on_change=false)
912 $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
917 //------------------------------------------------------------------------------------
919 function item_tax_types_list($name, $selected_id=null)
921 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
922 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
925 function item_tax_types_list_cells($label, $name, $selected_id=null)
928 echo "<td>$label</td>\n";
930 item_tax_types_list($name, $selected_id);
934 function item_tax_types_list_row($label, $name, $selected_id=null)
937 item_tax_types_list_cells($label, $name, $selected_id);
941 //------------------------------------------------------------------------------------
943 function shippers_list($name, $selected_id=null)
945 $sql = "SELECT shipper_id, shipper_name FROM ".TB_PREF."shippers";
946 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
949 function shippers_list_cells($label, $name, $selected_id=null)
952 echo "<td>$label</td>\n";
954 shippers_list($name, $selected_id);
958 function shippers_list_row($label, $name, $selected_id=null)
961 shippers_list_cells($label, $name, $selected_id);
965 //-------------------------------------------------------------------------------------
967 function sales_persons_list($name, $selected_id=null)
969 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
970 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
973 function sales_persons_list_cells($label, $name, $selected_id=null)
976 echo "<td>$label</td>\n";
978 sales_persons_list($name, $selected_id);
982 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
985 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
989 //------------------------------------------------------------------------------------
991 function sales_areas_list($name, $selected_id=null)
993 $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
994 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
997 function sales_areas_list_cells($label, $name, $selected_id=null)
1000 echo "<td>$label</td>\n";
1002 sales_areas_list($name, $selected_id);
1006 function sales_areas_list_row($label, $name, $selected_id=null)
1009 sales_areas_list_cells($label, $name, $selected_id);
1013 //------------------------------------------------------------------------------------
1015 function workorders_list($name, $selected_id=null)
1017 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1018 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1021 function workorders_list_cells($label, $name, $selected_id=null)
1024 echo "<td>$label</td>\n";
1026 workorders_list($name, $selected_id);
1030 function workorders_list_row($label, $name, $selected_id=null)
1033 workorders_list_cells($label, $name, $selected_id);
1037 //------------------------------------------------------------------------------------
1039 function payment_terms_list($name, $selected_id=null)
1041 $sql = "SELECT terms_indicator, terms FROM ".TB_PREF."payment_terms";
1042 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1045 function payment_terms_list_cells($label, $name, $selected_id=null)
1048 echo "<td>$label</td>\n";
1050 payment_terms_list($name, $selected_id);
1054 function payment_terms_list_row($label, $name, $selected_id=null)
1057 payment_terms_list_cells($label, $name, $selected_id);
1061 //------------------------------------------------------------------------------------
1063 function credit_status_list($name, $selected_id=null)
1065 $sql ="SELECT id, reason_description FROM ".TB_PREF."credit_status";
1066 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1069 function credit_status_list_cells($label, $name, $selected_id=null)
1072 echo "<td>$label</td>\n";
1074 credit_status_list($name, $selected_id);
1078 function credit_status_list_row($label, $name, $selected_id=null)
1081 credit_status_list_cells($label, $name, $selected_id);
1085 //-----------------------------------------------------------------------------------------------
1087 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1089 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
1091 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1093 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1095 'select_submit'=> $submit_on_change,
1096 // 'async' => false,
1100 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1103 echo "<td>$label</td>\n";
1105 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1110 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1113 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1118 //-----------------------------------------------------------------------------------------------
1120 function movement_types_list($name, $selected_id=null)
1122 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1123 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1126 function movement_types_list_cells($label, $name, $selected_id=null)
1129 echo "<td>$label</td>\n";
1131 movement_types_list($name, $selected_id);
1135 function movement_types_list_row($label, $name, $selected_id=null)
1138 movement_types_list_cells($label, $name, $selected_id);
1142 //-----------------------------------------------------------------------------------------------
1144 function bank_trans_types_list($name, $selected_id=null)
1146 $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
1147 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1150 function bank_trans_types_list_cells($label, $name, $selected_id=null)
1153 echo "<td>$label</td>\n";
1155 bank_trans_types_list($name, $selected_id);
1159 function bank_trans_types_list_row($label, $name, $selected_id=null)
1162 bank_trans_types_list_cells($label, $name, $selected_id);
1166 //-----------------------------------------------------------------------------------------------
1168 function workcenter_list($name, $selected_id=null, $all_option=false)
1172 $sql = "SELECT id, name FROM ".TB_PREF."workcentres";
1174 return combo_input($name, $selected_id, $sql, 'id', 'name',
1176 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1177 'spec_id' => $all_items,
1181 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1183 default_focus($name);
1185 echo "<td>$label</td>\n";
1187 workcenter_list($name, $selected_id, $all_option);
1191 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1194 workcenter_list_cells($label, $name, $selected_id, $all_option);
1198 //-----------------------------------------------------------------------------------------------
1200 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1202 $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
1203 FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
1204 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1206 return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
1208 'format' => '_format_add_curr',
1209 'select_submit'=> $submit_on_change,
1214 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1217 echo "<td>$label</td>\n";
1219 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1224 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1227 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1232 //-----------------------------------------------------------------------------------------------
1234 function class_list($name, $selected_id=null, $submit_on_change=false)
1236 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1238 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1240 'select_submit'=> $submit_on_change,
1246 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1249 echo "<td>$label</td>\n";
1251 $str = class_list($name, $selected_id, $submit_on_change);
1256 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1259 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1264 //-----------------------------------------------------------------------------------------------
1266 function stock_categories_list($name, $selected_id=null)
1268 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
1269 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1270 array('order'=>'category_id'));
1273 function stock_categories_list_cells($label, $name, $selected_id=null)
1276 echo "<td>$label</td>\n";
1278 stock_categories_list($name, $selected_id);
1282 function stock_categories_list_row($label, $name, $selected_id=null)
1285 stock_categories_list_cells($label, $name, $selected_id);
1289 //-----------------------------------------------------------------------------------------------
1291 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1295 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1297 combo_input($name, $selected_id, $sql, 'id', 'name',
1300 'spec_option' =>$all_option,
1301 'spec_id' => $all_option_numeric ? 0 : $all_items
1305 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1306 $all_option_numeric=false)
1309 echo "<td>$label</td>\n";
1311 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1315 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1316 $all_option_numeric=false)
1319 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1320 $all_option_numeric);
1324 //-----------------------------------------------------------------------------------------------
1325 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1326 $show_group=false, $cells=false, $all_option=false, $submit_on_change=false)
1328 if ($skip_bank_accounts)
1329 $sql = "SELECT chart.account_code, chart.account_name, type.name
1330 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1331 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1332 ."ON chart.account_code=acc.account_code
1333 WHERE acc.account_code IS NULL
1334 AND chart.account_type=type.id";
1336 $sql = "SELECT chart.account_code, chart.account_name, type.name
1337 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1338 WHERE chart.account_type=type.id";
1340 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1342 'format' => '_format_account' . ($show_group ? '2' : ''),
1343 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1345 'order' => 'account_code',
1346 'search_box' => $cells,
1347 'search_submit' => false,
1351 'select_submit'=> $submit_on_change,
1357 function _format_account($row)
1359 return $row[0] . " " . $row[1];
1362 function _format_account2($row)
1364 return $row[0] . " " . $row[2] . " " . $row[1];
1367 function gl_all_accounts_list_cells($label, $name, $selected_id=null, $skip_bank_accounts=false,
1368 $show_group=false, $cells=false, $all_option=false)
1371 echo "<td>$label</td>\n";
1373 gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option);
1377 function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_accounts=false,
1378 $show_group=false, $cells=false, $all_option=false)
1381 gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
1382 $show_group, $cells, $all_option);
1386 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1389 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1390 $items['0'] = strlen($name_no) ? $name_no : _("No");
1392 return array_selector($name, $selected_id, $items,
1394 'select_submit'=> $submit_on_change,
1395 'async' => false ) ); // FIX?
1398 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1401 echo "<td>$label</td>\n";
1403 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1408 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1411 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1416 //------------------------------------------------------------------------------------------------
1418 function languages_list($name, $selected_id=null)
1420 global $installed_languages;
1423 foreach ($installed_languages as $lang)
1424 $items[$lang['code']] = $lang['name'];
1426 return array_selector($name, $selected_id, $items );
1429 function languages_list_cells($label, $name, $selected_id=null)
1432 echo "<td>$label</td>\n";
1434 languages_list($name, $selected_id);
1438 function languages_list_row($label, $name, $selected_id=null)
1441 languages_list_cells($label, $name, $selected_id);
1445 //------------------------------------------------------------------------------------------------
1447 function bank_account_types_list($name, $selected_id=null)
1449 $types = bank_account_types::get_all();
1452 foreach ($types as $type)
1454 $items[$type['id']] = $type['name'];
1457 return array_selector($name, $selected_id, $items );
1460 function bank_account_types_list_cells($label, $name, $selected_id=null)
1463 echo "<td>$label</td>\n";
1465 bank_account_types_list($name, $selected_id);
1469 function bank_account_types_list_row($label, $name, $selected_id=null)
1472 bank_account_types_list_cells($label, $name, $selected_id);
1476 //------------------------------------------------------------------------------------------------
1477 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1479 $types = payment_person_types::get_all();
1482 foreach ($types as $type)
1484 if (payment_person_types::has_items($type['id']))
1486 $items[$type['id']] = $type['name'];
1490 return array_selector($name, $selected_id, $items,
1491 array( 'select_submit'=> $submit_on_change ) );
1494 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1497 echo "<td>$label</td>\n";
1499 $str = payment_person_types_list($name, $selected_id, $related);
1504 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1507 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1512 //------------------------------------------------------------------------------------------------
1514 function wo_types_list($name, $selected_id=null)
1516 $types = wo_types::get_all();
1519 foreach ($types as $type)
1520 $items[$type['id']] = $type['name'];
1522 return array_selector($name, $selected_id, $items,
1523 array( 'select_submit'=> true, 'async' => true ) );
1526 function wo_types_list_row($label, $name, $selected_id=null)
1528 echo "<tr><td>$label</td><td>\n";
1529 $str = wo_types_list($name, $selected_id);
1530 echo "</td></tr>\n";
1534 //------------------------------------------------------------------------------------------------
1536 function dateformats_list_row($label, $name, $value=null)
1538 global $dateformats;
1540 echo "<tr><td>$label</td>\n<td>";
1541 array_selector( $name, $value, $dateformats );
1542 echo "</td></tr>\n";
1545 function dateseps_list_row($label, $name, $value=null)
1549 echo "<tr><td>$label</td>\n<td>";
1550 array_selector( $name, $value, $dateseps );
1551 echo "</td></tr>\n";
1554 function thoseps_list_row($label, $name, $value=null)
1558 echo "<tr><td>$label</td>\n<td>";
1559 array_selector( $name, $value, $thoseps );
1560 echo "</td></tr>\n";
1563 function decseps_list_row($label, $name, $value=null)
1567 echo "<tr><td>$label</td>\n<td>";
1568 array_selector( $name, $value, $decseps );
1569 echo "</td></tr>\n";
1572 function themes_list_row($label, $name, $value=null)
1574 global $path_to_root;
1576 $path = $path_to_root.'/themes/';
1578 $themedir = opendir($path);
1579 while(false !== ($fname = readdir($themedir)))
1581 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1583 $themes[$fname] = $fname;
1588 echo "<tr><td>$label</td>\n<td>";
1589 array_selector( $name, $value, $themes );
1590 echo "</td></tr>\n";
1593 function pagesizes_list_row($label, $name, $value=null)
1598 foreach ($pagesizes as $pz)
1601 echo "<tr><td>$label</td>\n<td>";
1602 array_selector( $name, $value, $items );
1603 echo "</td></tr>\n";
1606 function security_headings_list_row($label, $name, $value=null)
1608 global $security_headings;
1610 echo "<tr><td>$label</td>\n<td>";
1611 array_selector( $name, $value, $security_headings );
1612 echo "</td></tr>\n";
1615 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1617 global $systypes_array;
1620 echo "<td>$label</td>\n";
1624 foreach ($systypes_array as $key=>$type)
1625 $items[$key] = $type['name'];
1627 $str = array_selector($name, $value, $items,
1629 'select_submit'=> $submit_on_change,
1637 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1640 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1645 function cust_allocations_list_cells($label, $name, $selected=null)
1653 $all_items=>_("All Types"),
1654 '1'=> _("Sales Invoices"),
1655 '2'=> _("Overdue Invoices"),
1656 '3' => _("Payments"),
1657 '4' => _("Credit Notes"),
1658 '5' => _("Delivery Notes")
1660 $str = array_selector($name, $selected, $allocs);
1665 function supp_allocations_list_cell($name, $selected=null)
1671 $all_items=>_("All Types"),
1672 '1'=> _("Invoices"),
1673 '2'=> _("Overdue Invoices"),
1674 '3' => _("Payments"),
1675 '4' => _("Credit Notes"),
1676 '5' => _("Overdue Credit Notes")
1678 $str = array_selector($name, $selected, $allocs);
1683 function policy_list_cells($label, $name, $selected=null)
1688 $str = array_selector($name, $selected,
1689 array( '' => _("Automatically put balance on back order"),
1690 'CAN' => _("Cancel any quantites not delivered")) );
1695 function policy_list_row($label, $name, $selected=null)
1698 policy_list_cells($label, $name, $selected);
1702 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1707 $str = array_selector($name, $selected,
1708 array( 'Return' => _("Items Returned to Inventory Location"),
1709 'WriteOff' => _("Items Written Off")),
1710 array( 'select_submit'=> $submit_on_change ) );
1715 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1718 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1723 function number_list($name, $selected, $from, $to, $no_option=false)
1726 for ($i = $from; $i <= $to; $i++)
1729 return array_selector($name, $selected, $items,
1730 array( 'spec_option' => $no_option,
1731 'spec_id' => reserved_words::get_all_numeric()) );
1734 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1739 number_list($name, $selected, $from, $to, $no_option);
1743 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1746 number_list_cells($label, $name, $selected, $from, $to, $no_option);