2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/banking.inc");
13 include_once($path_to_root . "/includes/reserved.inc");
14 include_once($path_to_root . "/includes/types.inc");
15 include_once($path_to_root . "/includes/current_user.inc");
17 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
18 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
20 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
21 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
23 $all_items = reserved_words::get_all();
25 //----------------------------------------------------------------------------
26 // Universal sql combo generator
27 // $sql must return selector values and selector texts in columns 0 & 1
28 // Options are merged with defaults.
30 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
35 $opts = array( // default options
36 'where'=> array(), // additional constraints
37 'order' => $namefield, // list sort order
38 // special option parameters
39 'spec_option'=>false, // option text or false
40 'spec_id' => 0, // option id
41 // submit on select parameters
42 'default' => '', // default value when $_POST is not set
43 'select_submit' => false, //submit on select: true/false
44 'edit_submit' => false, // call editor on F4
45 'async' => true, // select update via ajax (true) vs _page_body reload
46 // search box parameters
48 'search_box' => false, // name or true/false
49 'type' => 0, // type of extended selector:
50 // 0 - with (optional) visible search box, search by id
51 // 1 - with hidden search box, search by option text
52 // 2 - TODO reverse: box with hidden selector available via enter; this
53 // would be convenient for optional ad hoc adding of new item
54 'search_submit' => true, //search submit button: true/false
55 'size' => 8, // size and max of box tag
57 'cells' => false, // combo displayed as 2 <td></td> cells
58 'search' => array(), // sql field names to search
59 'format' => null, // format functions for regular options
61 'box_hint' => null, // box/selectors hints; null = std see below
62 'category' => false, // category column name or false
63 'show_inactive' => false // show inactive records.
65 // ------ merge options with defaults ----------
67 $opts = array_merge($opts, $options);
68 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
70 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
71 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
72 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
73 $spec_id = $opts['spec_id'];
74 $spec_option = $opts['spec_option'];
75 $by_id = ($opts['type'] == 0);
76 $class = $by_id ? 'combo':'combo2';
77 $disabled = $opts['disabled'] ? "disabled" : '';
79 if(!count($opts['search'])) {
80 $opts['search'] = array($by_id ? $valfield : $namefield);
82 if ($opts['sel_hint'] === null)
83 $opts['sel_hint'] = $by_id || $search_box==false ?
84 '' : _('Press Space tab for search pattern entry');
86 if ($opts['box_hint'] === null)
87 $opts['box_hint'] = $search_box && $search_submit != false ?
88 ($by_id ? _('Enter code fragment to search or * for all')
89 : _('Enter description fragment to search or * for all')) :'';
91 if ($selected_id == null) {
92 $selected_id = get_post($name, $opts['default']);
94 $txt = get_post($search_box);
98 if (isset($_POST[$select_submit])) {
99 if ($by_id) $txt = $_POST[$name];
102 $Ajax->activate('_page_body');
104 $Ajax->activate($name);
107 // search related sql modifications
109 $rel = "rel='$search_box'"; // set relation to list
110 if ($opts['search_submit']) {
111 if (isset($_POST[$search_submit])) {
112 $selected_id = ''; // ignore selected_id while search
114 $Ajax->activate('_page_body');
116 $Ajax->activate($name);
119 if ($spec_option === false && $selected_id==null)
122 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
127 foreach($opts['search'] as $i=> $s)
128 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
129 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
134 if (count($opts['where'])) {
135 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
136 $where .= '('. implode($opts['where'], ' AND ') . ')';
137 $group_pos = strpos($sql, 'GROUP BY');
139 $group = substr($sql, $group_pos);
140 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
145 if ($opts['order'] != false) {
146 if (!is_array($opts['order']))
147 $opts['order'] = array($opts['order']);
148 $sql .= ' ORDER BY '.implode(',',$opts['order']);
152 // ------ make selector ----------
153 $selector = $first_opt = '';
157 //if($name=='stock_id') display_error($sql);
158 if($result = db_query($sql)) {
159 while ($contact_row = db_fetch($result)) {
160 $value = $contact_row[0];
161 $descr = $opts['format']==null ? $contact_row[1] :
162 call_user_func($opts['format'], $contact_row);
164 if (get_post($search_submit) && ($txt === $value)) {
165 $selected_id = $value;
167 if ((string)($selected_id) === $value) {
171 // show selected option even if inactive
172 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
175 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
177 if ($first_id === false) {
181 $cat = $contact_row[$opts['category']];
182 if ($opts['category'] !== false && $cat != $lastcat){
183 $selector .= "<optgroup label='".$cat."'>\n";
186 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
188 db_free_result($result);
191 // Prepend special option.
192 if ($spec_option !== false) { // if special option used - add it
193 $first_id = $spec_id;
194 $first_opt = $spec_option;
196 // if($first_id !== false) {
197 $sel = $found===false ? 'selected' : '';
198 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
199 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
203 if ($found === false) {
204 $selected_id = $first_id;
206 $_POST[$name] = $selected_id;
208 if ($by_id && $search_box != false) {
210 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
212 $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
213 $selector = "<select $disabled name='$name' class='$class' title='"
214 . $opts['sel_hint']."'$aspect $rel>".$selector."</select>\n";
216 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
218 // because of bug which M$ cannot fix since IE 5.0
219 // we must embed whole selector in span tags to enable proper ajax update
220 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
222 if ($select_submit != false) { // if submit on change is used - add select button
223 global $_select_button;
224 // button class selects form reload/ajax selector update
225 $selector .= sprintf($_select_button, $disabled, user_theme(),
226 (fallback_mode() ? '' : 'display:none;'),
227 $select_submit)."\n";
229 // ------ make combo ----------
232 if ($search_box != false) {
233 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
234 $opts['size']."' maxlength='".$opts['max'].
235 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
236 .$opts['box_hint']."'"
237 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
239 if ($search_submit != false) {
240 global $_search_button;
241 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
242 (fallback_mode() ? '' : 'display:none;'),
243 $search_submit)."\n";
246 default_focus(($search_box && $by_id) ? $search_box : $name);
248 if ($search_box && $opts['cells'])
249 echo ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
251 echo $edit_entry.$selector;
258 Returns true if selector $name is subject to update.
260 function list_updated($name)
262 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
264 //----------------------------------------------------------------------------------------------
265 // Universal array combo generator
266 // $items is array of options 'value' => 'description'
267 // Options is reduced set of combo_selector options and is merged with defaults.
269 function array_selector($name, $selected_id, $items, $options=null)
273 $opts = array( // default options
274 'spec_option'=>false, // option text or false
275 'spec_id' => 0, // option id
276 'select_submit' => false, //submit on select: true/false
277 'edit_submit' => false, // call editor on F4
278 'async' => true, // select update via ajax (true) vs _page_body reload
279 'default' => '', // default value when $_POST is not set
280 // search box parameters
284 // ------ merge options with defaults ----------
286 $opts = array_merge($opts, $options);
287 $select_submit = $opts['select_submit']===true ? '_'.$name.'_update' : $opts['select_submit'];
288 $spec_id = $opts['spec_id'];
289 $spec_option = $opts['spec_option'];
290 $disabled = $opts['disabled'] ? "disabled" : '';
292 if ($selected_id == null) {
293 $selected_id = get_post($name, $opts['default']);
296 if (isset($_POST[$select_submit])) {
298 $Ajax->activate('_page_body');
300 $Ajax->activate($name);
303 // ------ make selector ----------
304 $selector = $first_opt = '';
307 //if($name=='SelectStockFromList') display_error($sql);
308 foreach($items as $value=>$descr) {
310 if ($selected_id == $value) {
314 if ($first_id === false) {
318 $selector .= "<option $sel value='$value'>$descr</option>\n";
321 // Prepend special option.
322 if ($spec_option !== false) { // if special option used - add it
323 $first_id = $spec_id;
324 $first_opt = $spec_option;
325 $sel = $found===false ? 'selected' : '';
326 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
330 if ($found === false) {
331 $_POST[$name] = $first_id;
334 $aspect = $opts['edit_submit'] ? " aspect='editable'" : '';
335 $selector = "<select $disabled name='$name' class='combo' title='"
336 . $opts['sel_hint']."'$aspect >".$selector."</select>\n";
338 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
340 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
342 if ($select_submit != false) { // if submit on change is used - add select button
343 global $_select_button;
344 $selector .= sprintf($_select_button, $disabled, user_theme(),
345 (fallback_mode() ? '' : 'display:none;'),
346 $select_submit)."\n";
348 default_focus($name);
353 //----------------------------------------------------------------------------------------------
355 function _format_add_curr($row)
357 static $company_currency;
359 if ($company_currency == null)
361 $company_currency = get_company_currency();
363 return $row[1] . ($row[2] == $company_currency ?
364 '' : (" - " . $row[2]));
367 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
372 $sql = "SELECT supplier_id, supp_name, curr_code, inactive FROM ".TB_PREF."suppliers ";
374 $mode = get_company_pref('no_supplier_list');
376 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
378 'format' => '_format_add_curr',
379 'search_box' => $mode!=0,
380 'edit_submit' => true,
382 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
383 'spec_id' => $all_items,
384 'select_submit'=> $submit_on_change,
386 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
387 _('Select supplier'),
388 'show_inactive'=>$all
392 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
393 $submit_on_change=false, $all=false)
396 echo "<td>$label</td><td>\n";
397 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change, $all);
402 function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
404 echo "<tr><td>$label</td><td>";
405 $str = supplier_list($name, $selected_id, $all_option, $submit_on_change );
409 //----------------------------------------------------------------------------------------------
411 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false, $show_inactive=false)
415 $sql = "SELECT debtor_no, name, curr_code, inactive FROM ".TB_PREF."debtors_master ";
417 $mode = get_company_pref('no_customer_list');
419 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
421 'format' => '_format_add_curr',
422 'search_box' => $mode!=0,
425 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
426 'spec_id' => $all_items,
427 'select_submit'=> $submit_on_change,
428 'edit_submit' => true, // call editor on F4
430 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F4 - entry new customer') :
431 _('Select customer'),
432 'show_inactive' => $show_inactive
436 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
437 $submit_on_change=false, $show_inactive=false)
440 echo "<td>$label</td>\n";
442 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
448 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
449 $submit_on_change=false, $show_inactive=false)
451 echo "<tr><td>$label</td><td nowrap>";
452 $str = customer_list($name, $selected_id, $all_option, $submit_on_change,
454 echo "</td>\n</tr>\n";
458 //------------------------------------------------------------------------------------------------
460 function customer_branches_list($customer_id, $name, $selected_id=null,
461 $spec_option = true, $enabled=true, $submit_on_change=false)
465 $sql = "SELECT branch_code, br_name FROM ".TB_PREF."cust_branch
466 WHERE debtor_no='" . $customer_id . "' ";
468 $where = $enabled ? array("disable_trans = 0") : array();
469 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
472 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
473 'spec_id' => $all_items,
474 'select_submit'=> $submit_on_change,
475 'sel_hint' => _('Select customer branch')
478 //------------------------------------------------------------------------------------------------
480 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
483 echo "<td>$label</td>\n";
485 $ret = customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
490 function customer_branches_list_row($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false)
493 $ret = customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change);
498 //------------------------------------------------------------------------------------------------
500 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
504 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
506 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
508 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
509 'spec_id' => $all_items,
510 'select_submit'=> $submit_on_change
514 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
517 echo "<td>$label</td>\n";
519 $str = locations_list($name, $selected_id, $all_option, $submit_on_change);
524 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
527 $str = locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
532 //-----------------------------------------------------------------------------------------------
534 function currencies_list($name, $selected_id=null, $submit_on_change=false)
536 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
538 // default to the company currency
540 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
542 'select_submit'=> $submit_on_change,
543 'default' => get_company_currency(),
548 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
551 echo "<td>$label</td>\n";
553 $str = currencies_list($name, $selected_id, $submit_on_change);
558 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
561 $str = currencies_list_cells($label, $name, $selected_id, $submit_on_change);
566 //---------------------------------------------------------------------------------------------------
568 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
571 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
573 // default to the company current fiscal year
575 return combo_input($name, $selected_id, $sql, 'id', '',
578 'default' => get_company_pref('f_year'),
579 'format' => '_format_fiscalyears',
580 'select_submit'=> $submit_on_change,
585 function _format_fiscalyears($row)
587 return sql2date($row[1]) . " - " . sql2date($row[2])
588 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
591 function fiscalyears_list_cells($label, $name, $selected_id=null)
594 echo "<td>$label</td>\n";
596 $str = fiscalyears_list($name, $selected_id);
601 function fiscalyears_list_row($label, $name, $selected_id=null)
604 $str = fiscalyears_list_cells($label, $name, $selected_id);
608 //------------------------------------------------------------------------------------
610 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
611 $submit_on_change=false, $showclosed=false, $showtype=1)
613 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
616 'order' => 'reference',
617 'spec_option'=>$no_option ? $showname : false,
619 'select_submit'=> $submit_on_change,
624 $options['where'][] = "closed=0";
626 $options['where'][] = "type_=$showtype";
628 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
631 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
632 $showclosed=false, $showtype=0, $submit_on_change=false)
635 echo "<td>$label</td>\n";
637 $str = dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
642 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
643 $showclosed=false, $showtype=0, $submit_on_change=false)
646 $str = dimensions_list_cells($label, $name, $selected_id, $no_option, $showname,
647 $showclosed, $showtype, $submit_on_change);
652 //---------------------------------------------------------------------------------------------------
654 function stock_items_list($name, $selected_id=null, $all_option=false,
655 $submit_on_change=false, $opts=array())
659 $sql = "SELECT stock_id, s.description, c.description, s.inactive
660 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
662 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
665 'format' => '_format_stock_items',
666 'spec_option' => $all_option===true ? _("All Items") : $all_option,
667 'spec_id' => $all_items,
668 'search_box' => true,
669 'search' => array("stock_id", "c.description","s.description"),
670 'search_submit' => get_company_pref('no_item_list')!=0,
672 'select_submit'=> $submit_on_change,
674 'order' => array('c.description','stock_id')
678 function _format_stock_items($row)
680 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
683 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
684 $submit_on_change=false, $all=false)
687 echo "<td>$label</td>\n";
688 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
689 array('cells'=>true, 'show_inactive'=>$all));
693 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
696 $str = stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
701 //---------------------------------------------------------------------------------------------------
703 // Select item via foreign code.
705 function sales_items_list($name, $selected_id=null, $all_option=false,
706 $submit_on_change=false, $type='', $opts=array())
710 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
713 ".TB_PREF."stock_master s,
714 ".TB_PREF."item_codes i
716 ".TB_PREF."stock_category c
717 ON i.category_id=c.category_id
718 WHERE i.stock_id=s.stock_id";
721 if ($type == 'local') { // exclude foreign codes
722 $sql .= " AND !i.is_foreign";
723 } elseif ($type == 'kits') { // sales kits
724 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
726 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
727 $sql .= " GROUP BY i.item_code";
729 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
732 'format' => '_format_stock_items',
733 'spec_option' => $all_option===true ? _("All Items") : $all_option,
734 'spec_id' => $all_items,
735 'search_box' => true,
736 'search' => array("i.item_code", "i.description"),
737 'search_submit' => get_company_pref('no_item_list')!=0,
739 'select_submit'=> $submit_on_change,
741 'order' => array('c.description','i.item_code')
745 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
748 echo "<td>$label</td>\n";
749 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
750 '', array('cells'=>true));
754 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
756 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
757 'kits', array('cells'=>false));
761 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
765 echo "<td>$label</td>\n";
767 $str = sales_items_list($name, $selected_id, $all_option, $submit_on_change,
768 'local', array('cells'=>false));
772 //------------------------------------------------------------------------------------
774 function base_stock_items_list($where, $name, $selected_id=null,
775 $all_option=false, $submit_on_change=false)
779 $sql = "SELECT stock_id, s.description, c.description, s.inactive
780 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE
781 s.category_id=c.category_id";
783 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
785 'format' => '_format_stock_items',
786 'spec_option' => $all_option==true ? _("All Items") : $all_option,
787 'spec_id' => $all_items,
788 'select_submit'=> $submit_on_change,
792 //------------------------------------------------------------------------------------
794 function stock_bom_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
797 return base_stock_items_list("(s.mb_flag='M' OR s.mb_flag='K')",
798 $name, $selected_id, $all_option, $submit_on_change);
801 function stock_bom_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
804 echo "<td>$label</td>\n";
806 $str = stock_bom_items_list($name, $selected_id, $all_option, $submit_on_change);
811 function stock_bom_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
814 $str = stock_bom_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
819 //------------------------------------------------------------------------------------
821 function stock_manufactured_items_list($name, $selected_id=null,
822 $all_option=false, $submit_on_change=false)
824 return base_stock_items_list("s.mb_flag='M'",
825 $name, $selected_id, $all_option, $submit_on_change);
828 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
829 $all_option=false, $submit_on_change=false)
832 echo "<td>$label</td>\n";
834 $str = stock_manufactured_items_list($name, $selected_id, $all_option,
840 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
841 $all_option=false, $submit_on_change=false)
844 $str = stock_manufactured_items_list_cells($label, $name, $selected_id,
845 $all_option, $submit_on_change);
849 //------------------------------------------------------------------------------------
851 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
852 $all_option=false, $submit_on_change=false)
854 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
855 array('where'=>array("stock_id != '$parent_stock_id'")));
859 function stock_component_items_list_cells($label, $name, $parent_stock_id,
860 $selected_id=null, $all_option=false, $submit_on_change=false)
863 echo "<td>$label</td>\n";
864 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
865 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true));
868 //------------------------------------------------------------------------------------
870 function stock_costable_items_list($name, $selected_id=null,
871 $all_option=false, $submit_on_change=false)
873 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
874 array('where'=>array("mb_flag!='D'")));
878 function stock_costable_items_list_cells($label, $name, $selected_id=null,
879 $all_option=false, $submit_on_change=false)
882 echo "<td>$label</td>\n";
883 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
884 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
888 //------------------------------------------------------------------------------------
889 function stock_purchasable_items_list($name, $selected_id=null,
890 $all_option=false, $submit_on_change=false, $all=false)
892 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
893 array('where'=>array("mb_flag!= 'M'"),
894 'edit_submit' => true,
895 'show_inactive'=>$all));
899 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
900 $all_option=false, $submit_on_change=false, $all=false)
903 echo "<td>$label</td>\n";
904 $str = stock_items_list($name, $selected_id, $all_option, $submit_on_change,
905 array('where'=>array("mb_flag!= 'M'"),
906 'edit_submit' => true,
911 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
912 $all_option=false, $submit_on_change=false)
915 $ret = stock_purchasable_items_list_cells($label, $name, $selected_id=null,
916 $all_option, $submit_on_change);
921 //------------------------------------------------------------------------------------
923 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
929 echo "<td>$label</td>\n";
932 array_selector($name, $selected_id, $stock_types,
934 'select_submit'=> true,
935 'disabled' => !$enabled) );
939 function stock_units_list_row($label, $name, $value=null, $enabled=true)
941 $result = get_all_item_units();
944 echo "<td>$label</td>\n";
947 while($unit = db_fetch($result))
948 $units[$unit['abbr']] = $unit['name'];
950 array_selector($name, $value, $units,
952 'select_submit'=> true,
953 'disabled' => !$enabled) );
958 //------------------------------------------------------------------------------------
960 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
962 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
964 return combo_input($name, $selected_id, $sql, 'id', 'name',
966 'spec_option' => $none_option,
967 'spec_id' => reserved_words::get_all_numeric(),
968 'select_submit'=> $submit_on_change,
973 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
974 $submit_on_change=false)
977 echo "<td>$label</td>\n";
979 $str = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
984 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
985 $submit_on_change=false)
988 $str = tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
993 //------------------------------------------------------------------------------------
995 function tax_groups_list($name, $selected_id=null,
996 $none_option=false, $submit_on_change=false)
998 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1000 return combo_input($name, $selected_id, $sql, 'id', 'name',
1003 'spec_option' => $none_option,
1004 'spec_id' => reserved_words::get_all_numeric(),
1005 'select_submit'=> $submit_on_change,
1010 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1013 echo "<td>$label</td>\n";
1015 $str = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1020 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1023 $str = tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
1028 //------------------------------------------------------------------------------------
1030 function item_tax_types_list($name, $selected_id=null)
1032 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1033 combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1036 function item_tax_types_list_cells($label, $name, $selected_id=null)
1039 echo "<td>$label</td>\n";
1041 item_tax_types_list($name, $selected_id);
1045 function item_tax_types_list_row($label, $name, $selected_id=null)
1048 item_tax_types_list_cells($label, $name, $selected_id);
1052 //------------------------------------------------------------------------------------
1054 function shippers_list($name, $selected_id=null)
1056 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1057 combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array());
1060 function shippers_list_cells($label, $name, $selected_id=null)
1063 echo "<td>$label</td>\n";
1065 shippers_list($name, $selected_id);
1069 function shippers_list_row($label, $name, $selected_id=null)
1072 shippers_list_cells($label, $name, $selected_id);
1076 //-------------------------------------------------------------------------------------
1078 function sales_persons_list($name, $selected_id=null)
1080 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1081 combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array());
1084 function sales_persons_list_cells($label, $name, $selected_id=null)
1087 echo "<td>$label</td>\n";
1089 sales_persons_list($name, $selected_id);
1093 function sales_persons_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1096 sales_persons_list_cells($label, $name, $selected_id, $submit_on_change=false);
1100 //------------------------------------------------------------------------------------
1102 function sales_areas_list($name, $selected_id=null)
1104 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1105 combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1108 function sales_areas_list_cells($label, $name, $selected_id=null)
1111 echo "<td>$label</td>\n";
1113 sales_areas_list($name, $selected_id);
1117 function sales_areas_list_row($label, $name, $selected_id=null)
1120 sales_areas_list_cells($label, $name, $selected_id);
1124 //------------------------------------------------------------------------------------
1126 function sales_groups_list($name, $selected_id=null, $special_option=false)
1128 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1129 combo_input($name, $selected_id, $sql, 'id', 'description', array(
1130 'spec_option' => $special_option===true ? ' ' : $special_option,
1131 'order' => 'description', 'spec_id' => 0,
1135 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1138 echo "<td>$label</td>\n";
1140 sales_groups_list($name, $selected_id, $special_option);
1144 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1147 sales_groups_list_cells($label, $name, $selected_id, $special_option);
1151 //------------------------------------------------------------------------------------
1153 function _format_template_items($row)
1155 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1158 function templates_list($name, $selected_id=null, $special_option=false)
1160 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1161 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1162 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1163 combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1164 'format' => '_format_template_items',
1165 'spec_option' => $special_option===true ? ' ' : $special_option,
1166 'order' => 'order_no', 'spec_id' => 0,
1170 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1173 echo "<td>$label</td>\n";
1175 templates_list($name, $selected_id, $special_option);
1179 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1182 templates_list_cells($label, $name, $selected_id, $special_option);
1186 //------------------------------------------------------------------------------------
1188 function workorders_list($name, $selected_id=null)
1190 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1191 combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1194 function workorders_list_cells($label, $name, $selected_id=null)
1197 echo "<td>$label</td>\n";
1199 workorders_list($name, $selected_id);
1203 function workorders_list_row($label, $name, $selected_id=null)
1206 workorders_list_cells($label, $name, $selected_id);
1210 //------------------------------------------------------------------------------------
1212 function payment_terms_list($name, $selected_id=null)
1214 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1215 combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1218 function payment_terms_list_cells($label, $name, $selected_id=null)
1221 echo "<td>$label</td>\n";
1223 payment_terms_list($name, $selected_id);
1227 function payment_terms_list_row($label, $name, $selected_id=null)
1230 payment_terms_list_cells($label, $name, $selected_id);
1234 //------------------------------------------------------------------------------------
1236 function credit_status_list($name, $selected_id=null)
1238 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1239 combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1242 function credit_status_list_cells($label, $name, $selected_id=null)
1245 echo "<td>$label</td>\n";
1247 credit_status_list($name, $selected_id);
1251 function credit_status_list_row($label, $name, $selected_id=null)
1254 credit_status_list_cells($label, $name, $selected_id);
1258 //-----------------------------------------------------------------------------------------------
1260 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1262 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1264 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1266 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1268 'select_submit'=> $submit_on_change,
1269 // 'async' => false,
1273 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1276 echo "<td>$label</td>\n";
1278 $str = sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1283 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1286 $str = sales_types_list_cells($label, $name, $selected_id, $submit_on_change, $special_option);
1291 //-----------------------------------------------------------------------------------------------
1293 function movement_types_list($name, $selected_id=null)
1295 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1296 combo_input($name, $selected_id, $sql, 'id', 'name', array());
1299 function movement_types_list_cells($label, $name, $selected_id=null)
1302 echo "<td>$label</td>\n";
1304 movement_types_list($name, $selected_id);
1308 function movement_types_list_row($label, $name, $selected_id=null)
1311 movement_types_list_cells($label, $name, $selected_id);
1315 //-----------------------------------------------------------------------------------------------
1316 function _format_date($row)
1318 return sql2date($row['reconciled']);
1321 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1323 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1324 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1325 GROUP BY reconciled";
1326 combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1328 'spec_option' => $special_option,
1329 'format' => '_format_date',
1331 'select_submit'=> $submit_on_change
1335 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1338 echo "<td>$label</td>\n";
1340 bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1344 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1347 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1351 //-----------------------------------------------------------------------------------------------
1353 function workcenter_list($name, $selected_id=null, $all_option=false)
1357 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1359 return combo_input($name, $selected_id, $sql, 'id', 'name',
1361 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1362 'spec_id' => $all_items,
1366 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1368 default_focus($name);
1370 echo "<td>$label</td>\n";
1372 workcenter_list($name, $selected_id, $all_option);
1376 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1379 workcenter_list_cells($label, $name, $selected_id, $all_option);
1383 //-----------------------------------------------------------------------------------------------
1385 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1387 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1388 FROM ".TB_PREF."bank_accounts";
1389 // , ".TB_PREF."chart_master
1390 // WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
1392 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1394 'format' => '_format_add_curr',
1395 'select_submit'=> $submit_on_change,
1400 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1403 echo "<td>$label</td>\n";
1405 $str = bank_accounts_list($name, $selected_id, $submit_on_change);
1410 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1413 $str = bank_accounts_list_cells($label, $name, $selected_id, $submit_on_change);
1417 //-----------------------------------------------------------------------------------------------
1419 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1421 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1422 FROM ".TB_PREF."bank_accounts
1423 WHERE ".TB_PREF."bank_accounts.account_type=3";
1426 echo "<tr><td>$label</td>\n";
1428 $str = combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1430 'format' => '_format_add_curr',
1431 'select_submit'=> $submit_on_change,
1434 echo "</td></tr>\n";
1437 //-----------------------------------------------------------------------------------------------
1439 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1441 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1443 default_focus($name);
1446 echo "<td>$label</td>\n";
1449 $str = combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1451 'select_submit'=> $submit_on_change,
1453 'spec_option' =>$spec_option,
1456 echo "</td></tr>\n";
1460 //-----------------------------------------------------------------------------------------------
1462 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1465 echo "<td>$label</td>\n";
1467 $str = yesno_list($name, $selected_id, _('Cash'), _('Delayed'), $submit_on_change);
1471 //-----------------------------------------------------------------------------------------------
1473 function class_list($name, $selected_id=null, $submit_on_change=false)
1475 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1477 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1479 'select_submit'=> $submit_on_change,
1485 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1488 echo "<td>$label</td>\n";
1490 $str = class_list($name, $selected_id, $submit_on_change);
1495 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1498 $str = class_list_cells($label, $name, $selected_id, $submit_on_change);
1503 //-----------------------------------------------------------------------------------------------
1505 function stock_categories_list($name, $selected_id=null, $submit_on_change=false)
1507 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1508 combo_input($name, $selected_id, $sql, 'category_id', 'description',
1509 array('order'=>'category_id',
1510 'select_submit'=> $submit_on_change,
1515 function stock_categories_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1518 echo "<td>$label</td>\n";
1520 stock_categories_list($name, $selected_id, $submit_on_change);
1524 function stock_categories_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1527 stock_categories_list_cells($label, $name, $selected_id, $submit_on_change);
1531 //-----------------------------------------------------------------------------------------------
1533 function gl_account_types_list($name, $selected_id=null, $all_option, $all_option_numeric)
1537 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1539 combo_input($name, $selected_id, $sql, 'id', 'name',
1542 'spec_option' =>$all_option,
1543 'spec_id' => $all_option_numeric ? 0 : $all_items
1547 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false,
1548 $all_option_numeric=false)
1551 echo "<td>$label</td>\n";
1553 gl_account_types_list($name, $selected_id, $all_option, $all_option_numeric);
1557 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false,
1558 $all_option_numeric=false)
1561 gl_account_types_list_cells($label, $name, $selected_id, $all_option,
1562 $all_option_numeric);
1566 //-----------------------------------------------------------------------------------------------
1567 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1568 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1570 if ($skip_bank_accounts)
1571 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive
1572 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1573 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1574 ."ON chart.account_code=acc.account_code
1575 WHERE acc.account_code IS NULL
1576 AND chart.account_type=type.id";
1578 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive
1579 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1580 WHERE chart.account_type=type.id";
1582 combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1584 'format' => '_format_account',
1585 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1587 'order' => array('name','account_code'),
1588 'search_box' => $cells,
1589 'search_submit' => false,
1593 'select_submit'=> $submit_on_change,
1596 'show_inactive' => $all
1601 function _format_account($row)
1603 return $row[0] . " " . $row[1];
1606 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1607 $skip_bank_accounts=false, $cells=false, $all_option=false,
1608 $submit_on_change=false, $all=false)
1611 echo "<td>$label</td>\n";
1613 gl_all_accounts_list($name, $selected_id,
1614 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1618 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1619 $skip_bank_accounts=false, $cells=false, $all_option=false)
1622 gl_all_accounts_list_cells($label, $name, $selected_id,
1623 $skip_bank_accounts, $cells, $all_option);
1627 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1630 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1631 $items['0'] = strlen($name_no) ? $name_no : _("No");
1633 return array_selector($name, $selected_id, $items,
1635 'select_submit'=> $submit_on_change,
1636 'async' => false ) ); // FIX?
1639 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1642 echo "<td>$label</td>\n";
1644 $str = yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1649 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1652 $str = yesno_list_cells($label, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1657 //------------------------------------------------------------------------------------------------
1659 function languages_list($name, $selected_id=null)
1661 global $installed_languages;
1664 foreach ($installed_languages as $lang)
1665 $items[$lang['code']] = $lang['name'];
1667 return array_selector($name, $selected_id, $items );
1670 function languages_list_cells($label, $name, $selected_id=null)
1673 echo "<td>$label</td>\n";
1675 languages_list($name, $selected_id);
1679 function languages_list_row($label, $name, $selected_id=null)
1682 languages_list_cells($label, $name, $selected_id);
1686 //------------------------------------------------------------------------------------------------
1688 function bank_account_types_list($name, $selected_id=null)
1690 $types = bank_account_types::get_all();
1693 foreach ($types as $type)
1695 $items[$type['id']] = $type['name'];
1698 return array_selector($name, $selected_id, $items );
1701 function bank_account_types_list_cells($label, $name, $selected_id=null)
1704 echo "<td>$label</td>\n";
1706 bank_account_types_list($name, $selected_id);
1710 function bank_account_types_list_row($label, $name, $selected_id=null)
1713 bank_account_types_list_cells($label, $name, $selected_id);
1717 //------------------------------------------------------------------------------------------------
1718 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1720 $types = payment_person_types::get_all();
1723 foreach ($types as $type)
1725 if (payment_person_types::has_items($type['id']))
1727 $items[$type['id']] = $type['name'];
1731 return array_selector($name, $selected_id, $items,
1732 array( 'select_submit'=> $submit_on_change ) );
1735 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1738 echo "<td>$label</td>\n";
1740 $str = payment_person_types_list($name, $selected_id, $related);
1745 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1748 $str = payment_person_types_list_cells($label, $name, $selected_id, $related);
1753 //------------------------------------------------------------------------------------------------
1755 function wo_types_list($name, $selected_id=null)
1757 $types = wo_types::get_all();
1760 foreach ($types as $type)
1761 $items[$type['id']] = $type['name'];
1763 return array_selector($name, $selected_id, $items,
1764 array( 'select_submit'=> true, 'async' => true ) );
1767 function wo_types_list_row($label, $name, $selected_id=null)
1769 echo "<tr><td>$label</td><td>\n";
1770 $str = wo_types_list($name, $selected_id);
1771 echo "</td></tr>\n";
1775 //------------------------------------------------------------------------------------------------
1777 function dateformats_list_row($label, $name, $value=null)
1779 global $dateformats;
1781 echo "<tr><td>$label</td>\n<td>";
1782 array_selector( $name, $value, $dateformats );
1783 echo "</td></tr>\n";
1786 function dateseps_list_row($label, $name, $value=null)
1790 echo "<tr><td>$label</td>\n<td>";
1791 array_selector( $name, $value, $dateseps );
1792 echo "</td></tr>\n";
1795 function thoseps_list_row($label, $name, $value=null)
1799 echo "<tr><td>$label</td>\n<td>";
1800 array_selector( $name, $value, $thoseps );
1801 echo "</td></tr>\n";
1804 function decseps_list_row($label, $name, $value=null)
1808 echo "<tr><td>$label</td>\n<td>";
1809 array_selector( $name, $value, $decseps );
1810 echo "</td></tr>\n";
1813 function themes_list_row($label, $name, $value=null)
1815 global $path_to_root;
1817 $path = $path_to_root.'/themes/';
1819 $themedir = opendir($path);
1820 while(false !== ($fname = readdir($themedir)))
1822 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1824 $themes[$fname] = $fname;
1829 echo "<tr><td>$label</td>\n<td>";
1830 array_selector( $name, $value, $themes );
1831 echo "</td></tr>\n";
1834 function pagesizes_list_row($label, $name, $value=null)
1839 foreach ($pagesizes as $pz)
1842 echo "<tr><td>$label</td>\n<td>";
1843 array_selector( $name, $value, $items );
1844 echo "</td></tr>\n";
1847 function security_headings_list_row($label, $name, $value=null)
1849 global $security_headings;
1851 echo "<tr><td>$label</td>\n<td>";
1852 array_selector( $name, $value, $security_headings );
1853 echo "</td></tr>\n";
1856 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1858 global $systypes_array;
1861 echo "<td>$label</td>\n";
1865 foreach ($systypes_array as $key=>$type)
1866 $items[$key] = $type['name'];
1868 $str = array_selector($name, $value, $items,
1870 'select_submit'=> $submit_on_change,
1878 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1880 global $systypes_array;
1883 echo "<td>$label</td>\n";
1887 foreach ($systypes_array as $key=>$type)
1888 // exclude orders and dimensions
1889 if (!in_array($key, array(18,26,30,40)))
1890 $items[$key] = $type['name'];
1892 $str = array_selector($name, $value, $items,
1894 'spec_option'=> _("All"),
1896 'select_submit'=> $submit_on_change,
1904 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1907 $str = systypes_list_cells($label, $name, $value, $submit_on_change);
1912 function cust_allocations_list_cells($label, $name, $selected=null)
1920 $all_items=>_("All Types"),
1921 '1'=> _("Sales Invoices"),
1922 '2'=> _("Overdue Invoices"),
1923 '3' => _("Payments"),
1924 '4' => _("Credit Notes"),
1925 '5' => _("Delivery Notes")
1927 $str = array_selector($name, $selected, $allocs);
1932 function supp_allocations_list_cell($name, $selected=null)
1938 $all_items=>_("All Types"),
1939 '1'=> _("Invoices"),
1940 '2'=> _("Overdue Invoices"),
1941 '3' => _("Payments"),
1942 '4' => _("Credit Notes"),
1943 '5' => _("Overdue Credit Notes")
1945 $str = array_selector($name, $selected, $allocs);
1950 function policy_list_cells($label, $name, $selected=null)
1955 $str = array_selector($name, $selected,
1956 array( '' => _("Automatically put balance on back order"),
1957 'CAN' => _("Cancel any quantites not delivered")) );
1962 function policy_list_row($label, $name, $selected=null)
1965 policy_list_cells($label, $name, $selected);
1969 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1974 $str = array_selector($name, $selected,
1975 array( 'Return' => _("Items Returned to Inventory Location"),
1976 'WriteOff' => _("Items Written Off")),
1977 array( 'select_submit'=> $submit_on_change ) );
1982 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1985 $str = credit_type_list_cells($label, $name, $selected, $submit_on_change);
1990 function number_list($name, $selected, $from, $to, $no_option=false)
1993 for ($i = $from; $i <= $to; $i++)
1996 return array_selector($name, $selected, $items,
1997 array( 'spec_option' => $no_option,
1998 'spec_id' => reserved_words::get_all_numeric()) );
2001 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2006 number_list($name, $selected, $from, $to, $no_option);
2010 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2013 number_list_cells($label, $name, $selected, $from, $to, $no_option);
2017 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2018 $submit_on_change=true)
2020 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2021 ." GROUP BY profile";
2022 $result = db_query($sql, 'cannot get all profile names');
2023 $profiles = array();
2024 while($myrow=db_fetch($result)) {
2025 $profiles[$myrow['profile']] = $myrow['profile'];
2030 echo "<td>$label</td>\n";
2033 array_selector($name, $selected_id, $profiles,
2034 array( 'select_submit'=> $submit_on_change,
2035 'spec_option'=>$spec_opt,
2039 echo "</td></tr>\n";
2042 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2044 static $printers; // query only once for page display
2047 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2048 $result = db_query($sql, 'cannot get all printers');
2049 $printers = array();
2050 while($myrow=db_fetch($result)) {
2051 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2054 array_selector($name, $selected_id, $printers,
2055 array( 'select_submit'=> $submit_on_change,
2056 'spec_option'=>$spec_opt,
2061 //------------------------------------------------------------------------------------------------
2063 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2066 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2068 $sql .= " WHERE type=$type";
2070 combo_input($name, $selected_id, $sql, 'id', 'description',
2073 'order' => 'description',
2074 'select_submit'=> $submit_on_change,
2080 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2082 echo "<td>$label</td><td>\n";
2083 quick_entries_list($name, $selected_id, $type, $submit_on_change);
2087 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2090 quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
2095 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2097 global $quick_actions;
2099 echo "<tr><td>$label</td><td>";
2100 array_selector($name, $selected_id, $quick_actions,
2102 'select_submit'=> $submit_on_change
2104 echo "</td></tr>\n";
2107 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2109 global $quick_entry_types;
2111 echo "<tr><td>$label</td><td>";
2112 array_selector($name, $selected_id, $quick_entry_types,
2114 'select_submit'=> $submit_on_change
2116 echo "</td></tr>\n";
2119 function record_status_list_row($label, $name) {
2120 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));