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/types.inc");
14 include_once($path_to_root . "/includes/current_user.inc");
16 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
17 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
19 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
20 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
22 $all_items = ALL_TEXT;
24 //----------------------------------------------------------------------------
25 // Universal sql combo generator
26 // $sql must return selector values and selector texts in columns 0 & 1
27 // Options are merged with defaults.
29 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
34 $opts = array( // default options
35 'where'=> array(), // additional constraints
36 'order' => $namefield, // list sort order
37 // special option parameters
38 'spec_option'=>false, // option text or false
39 'spec_id' => 0, // option id
40 // submit on select parameters
41 'default' => '', // default value when $_POST is not set
42 'multi' => false, // multiple select
43 'select_submit' => false, //submit on select: true/false
44 'async' => true, // select update via ajax (true) vs _page_body reload
45 // search box parameters
47 'search_box' => false, // name or true/false
48 'type' => 0, // type of extended selector:
49 // 0 - with (optional) visible search box, search by id
50 // 1 - with hidden search box, search by option text
51 // 2 - TODO reverse: box with hidden selector available via enter; this
52 // would be convenient for optional ad hoc adding of new item
53 'search_submit' => true, //search submit button: true/false
54 'size' => 8, // size and max of box tag
56 'height' => false, // number of lines in select box
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.
64 'editable' => false // false, or length of editable entry field
66 // ------ merge options with defaults ----------
68 $opts = array_merge($opts, $options);
69 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
71 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
72 // select content filtered by search field:
73 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
74 // select set by select content field
75 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
77 $select_submit = $opts['select_submit'];
78 $spec_id = $opts['spec_id'];
79 $spec_option = $opts['spec_option'];
80 $by_id = ($opts['type'] == 0);
81 $class = $by_id ? 'combo':'combo2';
82 $disabled = $opts['disabled'] ? "disabled" : '';
83 $multi = $opts['multi'];
85 if(!count($opts['search'])) {
86 $opts['search'] = array($by_id ? $valfield : $namefield);
88 if ($opts['sel_hint'] === null)
89 $opts['sel_hint'] = $by_id || $search_box==false ?
90 '' : _('Press Space tab for search pattern entry');
92 if ($opts['box_hint'] === null) // dodaƦ hint dla pustego ****
93 $opts['box_hint'] = $search_box && $search_submit != false ?
94 ($by_id ? _('Enter code fragment to search or * for all')
95 : _('Enter description fragment to search or * for all')) :'';
97 if ($selected_id == null) {
98 $selected_id = get_post($name, $opts['default']);
100 if(!is_array($selected_id))
101 $selected_id = array($selected_id); // code is generalized for multiple selection support
103 $txt = get_post($search_box);
107 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
108 if ($by_id) $txt = $_POST[$name];
111 $Ajax->activate('_page_body');
113 $Ajax->activate($name);
115 if (isset($_POST[$search_button])) {
117 $Ajax->activate('_page_body');
119 $Ajax->activate($name);
122 // search related sql modifications
124 $rel = "rel='$search_box'"; // set relation to list
125 if ($opts['search_submit']) {
126 if (isset($_POST[$search_button])) {
127 $selected_id = array(); // ignore selected_id while search
129 $Ajax->activate('_page_body');
131 $Ajax->activate($name);
134 if ($spec_option === false && $selected_id == array())
137 $opts['where'][] = $valfield . "='". get_post($name, $spec_id)."'";
142 foreach($opts['search'] as $i=> $s)
143 $opts['search'][$i] = $s . " LIKE '%{$txt}%'";
144 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
149 if (count($opts['where'])) {
150 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
151 $where .= '('. implode($opts['where'], ' AND ') . ')';
152 $group_pos = strpos($sql, 'GROUP BY');
154 $group = substr($sql, $group_pos);
155 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
160 if ($opts['order'] != false) {
161 if (!is_array($opts['order']))
162 $opts['order'] = array($opts['order']);
163 $sql .= ' ORDER BY '.implode(',',$opts['order']);
167 // ------ make selector ----------
168 $selector = $first_opt = '';
173 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
174 //if($name=='curr_default') display_notification($opts['search_submit']);
175 if($result = db_query($sql)) {
176 while ($contact_row = db_fetch($result)) {
177 $value = $contact_row[0];
178 $descr = $opts['format']==null ? $contact_row[1] :
179 call_user_func($opts['format'], $contact_row);
181 if (get_post($search_button) && ($txt == $value)) {
182 $selected_id[] = $value;
185 if (in_array((string)$value, $selected_id, true)) {
188 $edit = $opts['editable'] && $contact_row['editable']
189 && (@$_POST[$search_box] == $value)
190 ? $contact_row[1] : false; // get non-formatted description
192 break; // selected field is editable - abandon list construction
194 // show selected option even if inactive
195 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
198 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
200 if ($first_id === false) {
204 $cat = $contact_row[$opts['category']];
205 if ($opts['category'] !== false && $cat != $lastcat){
206 $selector .= "<optgroup label='".$cat."'>\n";
209 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
211 db_free_result($result);
214 // Prepend special option.
215 if ($spec_option !== false) { // if special option used - add it
216 $first_id = $spec_id;
217 $first_opt = $spec_option;
219 // if($first_id !== false) {
220 $sel = $found===false ? 'selected' : '';
221 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
222 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
226 if ($found===false) {
227 $selected_id = array($first_id);
230 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
232 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
233 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
234 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
235 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
237 if ($by_id && ($search_box != false || $opts['editable']) ) {
238 // on first display show selector list
239 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
240 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
241 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
242 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
243 set_focus($name.'_text'); // prevent lost focus
244 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
245 set_focus($name); // prevent lost focus
246 if (!$opts['editable'])
248 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
251 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
253 // span for select list/input field update
254 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
256 // if selectable or editable list is used - add select button
257 if ($select_submit != false || $search_button) {
258 global $_select_button;
259 // button class selects form reload/ajax selector update
260 $selector .= sprintf($_select_button, $disabled, user_theme(),
261 (fallback_mode() ? '' : 'display:none;'),
262 '_'.$name.'_update')."\n";
264 // ------ make combo ----------
266 if ($search_box != false) {
267 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
268 $opts['size']."' maxlength='".$opts['max'].
269 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
270 .$opts['box_hint']."'"
271 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
273 if ($search_submit != false || $opts['editable']) {
274 global $_search_button;
275 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
276 (fallback_mode() ? '' : 'display:none;'),
277 $search_submit ? $search_submit : "_{$name}_button")."\n";
280 default_focus(($search_box && $by_id) ? $search_box : $name);
282 if ($search_box && $opts['cells'])
283 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
285 $str = $edit_entry.$selector;
291 Returns true if selector $name is subject to update.
293 function list_updated($name)
295 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
297 //----------------------------------------------------------------------------------------------
298 // Universal array combo generator
299 // $items is array of options 'value' => 'description'
300 // Options is reduced set of combo_selector options and is merged with defaults.
302 function array_selector($name, $selected_id, $items, $options=null)
306 $opts = array( // default options
307 'spec_option'=>false, // option text or false
308 'spec_id' => 0, // option id
309 'select_submit' => false, //submit on select: true/false
310 'async' => true, // select update via ajax (true) vs _page_body reload
311 'default' => '', // default value when $_POST is not set
312 'multi'=>false, // multiple select
313 // search box parameters
314 'height' => false, // number of lines in select box
318 // ------ merge options with defaults ----------
320 $opts = array_merge($opts, $options);
321 $select_submit = $opts['select_submit'];
322 $spec_id = $opts['spec_id'];
323 $spec_option = $opts['spec_option'];
324 $disabled = $opts['disabled'] ? "disabled" : '';
325 $multi = $opts['multi'];
327 if ($selected_id == null) {
328 $selected_id = get_post($name, $opts['default']);
330 if(!is_array($selected_id))
331 $selected_id = array($selected_id); // code is generalized for multiple selection support
333 if (isset($_POST[ '_'.$name.'_update'])) {
335 $Ajax->activate('_page_body');
337 $Ajax->activate($name);
340 // ------ make selector ----------
341 $selector = $first_opt = '';
344 //if($name=='SelectStockFromList') display_error($sql);
345 foreach($items as $value=>$descr) {
347 if (in_array((string)$value, $selected_id, true)) {
348 $sel = "selected='selected'";
351 if ($first_id === false) {
353 $first_opt = "<option %s value='$value'>$descr</option>\n";
356 $selector .= "<option $sel value='$value'>$descr</option>\n";
360 if ($first_id!==false) {
361 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
362 $selector = sprintf($first_opt, $sel).$selector;
364 // Prepend special option.
365 if ($spec_option !== false) { // if special option used - add it
366 $first_id = $spec_id;
367 $first_opt = $spec_option;
368 $sel = $found===false ? "selected='selected'" : '';
369 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
373 if ($found===false) {
374 $selected_id = array($first_id);
376 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
377 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
378 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
379 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
380 . $opts['sel_hint']."'>".$selector."</select>\n";
382 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
384 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
386 if ($select_submit != false) { // if submit on change is used - add select button
387 global $_select_button;
388 $selector .= sprintf($_select_button, $disabled, user_theme(),
389 (fallback_mode() ? '' : 'display:none;'),
390 '_'.$name.'_update')."\n";
392 default_focus($name);
396 //----------------------------------------------------------------------------------------------
398 function _format_add_curr($row)
400 static $company_currency;
402 if ($company_currency == null)
404 $company_currency = get_company_currency();
406 return $row[1] . ($row[2] == $company_currency ?
407 '' : (" - " . $row[2]));
410 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
411 $all=false, $editkey = false)
415 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
417 $mode = get_company_pref('no_supplier_list');
420 set_editor('supplier', $name, $editkey);
422 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
424 'format' => '_format_add_curr',
425 'order' => array('supp_ref'),
426 'search_box' => $mode!=0,
428 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
429 'spec_id' => $all_items,
430 'select_submit'=> $submit_on_change,
432 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
433 _('Select supplier'),
434 'show_inactive'=>$all
438 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
439 $submit_on_change=false, $all=false, $editkey = false)
442 echo "<td>$label</td><td>\n";
443 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
448 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
449 $submit_on_change=false, $all=false, $editkey = false)
451 echo "<tr><td class='label'>$label</td><td>";
452 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
456 //----------------------------------------------------------------------------------------------
458 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
459 $show_inactive=false, $editkey = false)
463 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
465 $mode = get_company_pref('no_customer_list');
468 set_editor('customer', $name, $editkey);
470 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
472 'format' => '_format_add_curr',
473 'order' => array('debtor_ref'),
474 'search_box' => $mode!=0,
477 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
478 'spec_id' => $all_items,
479 'select_submit'=> $submit_on_change,
481 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
482 _('Select customer'),
483 'show_inactive' => $show_inactive
487 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
488 $submit_on_change=false, $show_inactive=false, $editkey = false)
491 echo "<td>$label</td>\n";
493 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
494 $show_inactive, $editkey);
498 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
499 $submit_on_change=false, $show_inactive=false, $editkey = false)
501 echo "<tr><td class='label'>$label</td><td nowrap>";
502 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
503 $show_inactive, $editkey);
504 echo "</td>\n</tr>\n";
507 //------------------------------------------------------------------------------------------------
509 function customer_branches_list($customer_id, $name, $selected_id=null,
510 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
514 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
515 WHERE debtor_no='" . $customer_id . "' ";
518 set_editor('branch', $name, $editkey);
520 $where = $enabled ? array("disable_trans = 0") : array();
521 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
524 'order' => array('branch_ref'),
525 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
526 'spec_id' => $all_items,
527 'select_submit'=> $submit_on_change,
528 'sel_hint' => _('Select customer branch')
531 //------------------------------------------------------------------------------------------------
533 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
534 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
537 echo "<td>$label</td>\n";
539 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
540 $submit_on_change, $editkey);
544 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
545 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
547 echo "<tr><td class='label'>$label</td>";
548 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
549 $all_option, $enabled, $submit_on_change, $editkey);
553 //------------------------------------------------------------------------------------------------
555 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
559 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
561 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
563 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
564 'spec_id' => $all_items,
565 'select_submit'=> $submit_on_change
569 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
572 echo "<td>$label</td>\n";
574 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
578 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
580 echo "<tr><td class='label'>$label</td>";
581 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
585 //-----------------------------------------------------------------------------------------------
587 function currencies_list($name, $selected_id=null, $submit_on_change=false)
589 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
591 // default to the company currency
592 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
594 'select_submit'=> $submit_on_change,
595 'default' => get_company_currency(),
600 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
603 echo "<td>$label</td>\n";
605 echo currencies_list($name, $selected_id, $submit_on_change);
609 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
611 echo "<tr><td class='label'>$label</td>";
612 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
616 //---------------------------------------------------------------------------------------------------
618 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
621 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
623 // default to the company current fiscal year
625 return combo_input($name, $selected_id, $sql, 'id', '',
628 'default' => get_company_pref('f_year'),
629 'format' => '_format_fiscalyears',
630 'select_submit'=> $submit_on_change,
635 function _format_fiscalyears($row)
637 return sql2date($row[1]) . " - " . sql2date($row[2])
638 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
641 function fiscalyears_list_cells($label, $name, $selected_id=null)
644 echo "<td>$label</td>\n";
646 echo fiscalyears_list($name, $selected_id);
650 function fiscalyears_list_row($label, $name, $selected_id=null)
652 echo "<tr><td class='label'>$label</td>";
653 fiscalyears_list_cells(null, $name, $selected_id);
656 //------------------------------------------------------------------------------------
658 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
659 $submit_on_change=false, $showclosed=false, $showtype=1)
661 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
664 'order' => 'reference',
665 'spec_option'=>$no_option ? $showname : false,
667 'select_submit'=> $submit_on_change,
672 $options['where'][] = "closed=0";
674 $options['where'][] = "type_=$showtype";
676 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
679 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
680 $showclosed=false, $showtype=0, $submit_on_change=false)
683 echo "<td>$label</td>\n";
685 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
689 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
690 $showclosed=false, $showtype=0, $submit_on_change=false)
692 echo "<tr><td class='label'>$label</td>";
693 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
694 $showclosed, $showtype, $submit_on_change);
698 //---------------------------------------------------------------------------------------------------
700 function stock_items_list($name, $selected_id=null, $all_option=false,
701 $submit_on_change=false, $opts=array(), $editkey = false)
705 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
706 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
709 set_editor('item', $name, $editkey);
711 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
714 'format' => '_format_stock_items',
715 'spec_option' => $all_option===true ? _("All Items") : $all_option,
716 'spec_id' => $all_items,
717 'search_box' => true,
718 'search' => array("stock_id", "c.description","s.description"),
719 'search_submit' => get_company_pref('no_item_list')!=0,
721 'select_submit'=> $submit_on_change,
723 'order' => array('c.description','stock_id')
727 function _format_stock_items($row)
729 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
732 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
733 $submit_on_change=false, $all=false, $editkey = false)
736 echo "<td>$label</td>\n";
737 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
738 array('cells'=>true, 'show_inactive'=>$all), $editkey);
741 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
744 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
748 //---------------------------------------------------------------------------------------------------
750 // Select item via foreign code.
752 function sales_items_list($name, $selected_id=null, $all_option=false,
753 $submit_on_change=false, $type='', $opts=array())
757 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
758 i.inactive, if(count(*)>1, '0', s.editable) as editable
760 ".TB_PREF."stock_master s,
761 ".TB_PREF."item_codes i
763 ".TB_PREF."stock_category c
764 ON i.category_id=c.category_id
765 WHERE i.stock_id=s.stock_id";
768 if ($type == 'local') { // exclude foreign codes
769 $sql .= " AND !i.is_foreign";
770 } elseif ($type == 'kits') { // sales kits
771 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
773 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
774 $sql .= " GROUP BY i.item_code";
776 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
779 'format' => '_format_stock_items',
780 'spec_option' => $all_option===true ? _("All Items") : $all_option,
781 'spec_id' => $all_items,
782 'search_box' => true,
783 'search' => array("i.item_code", "c.description", "i.description"),
784 'search_submit' => get_company_pref('no_item_list')!=0,
786 'select_submit'=> $submit_on_change,
788 'order' => array('c.description','i.item_code'),
794 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
797 echo "<td>$label</td>\n";
798 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
799 '', array('cells'=>true));
802 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
804 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
805 'kits', array('cells'=>false, 'editable' => false));
808 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
812 echo "<td class='label'>$label</td>\n";
814 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
815 'local', array('cells'=>false, 'editable' => false));
818 //------------------------------------------------------------------------------------
820 function stock_manufactured_items_list($name, $selected_id=null,
821 $all_option=false, $submit_on_change=false)
823 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
824 array('where'=>array("mb_flag= 'M'")));
827 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
828 $all_option=false, $submit_on_change=false)
831 echo "<td>$label</td>\n";
833 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
837 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
838 $all_option=false, $submit_on_change=false)
840 echo "<tr><td class='label'>$label</td>";
841 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
844 //------------------------------------------------------------------------------------
846 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
847 $all_option=false, $submit_on_change=false, $editkey = false)
849 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
850 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
853 function stock_component_items_list_cells($label, $name, $parent_stock_id,
854 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
857 echo "<td>$label</td>\n";
858 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
859 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
862 //------------------------------------------------------------------------------------
864 function stock_costable_items_list($name, $selected_id=null,
865 $all_option=false, $submit_on_change=false)
867 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
868 array('where'=>array("mb_flag!='D'")));
871 function stock_costable_items_list_cells($label, $name, $selected_id=null,
872 $all_option=false, $submit_on_change=false)
875 echo "<td>$label</td>\n";
876 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
877 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
880 //------------------------------------------------------------------------------------
881 function stock_purchasable_items_list($name, $selected_id=null,
882 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
884 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
885 array('where'=>array("mb_flag!= 'M'"),
886 'show_inactive'=>$all), $editkey);
889 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
891 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
892 $all_option=false, $submit_on_change=false, $editkey=false)
895 echo "<td>$label</td>\n";
896 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
897 array('where'=>array("mb_flag!= 'M'"),
899 'cells'=>true), $editkey);
902 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
903 $all_option=false, $submit_on_change=false, $editkey=false)
905 echo "<tr><td class='label'>$label</td>";
906 stock_purchasable_items_list_cells(null, $name, $selected_id=null,
907 $all_option, $submit_on_change, $editkey);
911 //------------------------------------------------------------------------------------
913 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
919 echo "<td class='label'>$label</td>\n";
922 echo array_selector($name, $selected_id, $stock_types,
924 'select_submit'=> true,
925 'disabled' => !$enabled) );
929 function stock_units_list_row($label, $name, $value=null, $enabled=true)
931 $result = get_all_item_units();
934 echo "<td class='label'>$label</td>\n";
937 while($unit = db_fetch($result))
938 $units[$unit['abbr']] = $unit['name'];
940 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
945 //------------------------------------------------------------------------------------
947 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
949 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
951 return combo_input($name, $selected_id, $sql, 'id', 'name',
953 'spec_option' => $none_option,
954 'spec_id' => ALL_NUMERIC,
955 'select_submit'=> $submit_on_change,
960 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
961 $submit_on_change=false)
964 echo "<td>$label</td>\n";
966 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
970 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
971 $submit_on_change=false)
973 echo "<tr><td class='label'>$label</td>";
974 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
978 //------------------------------------------------------------------------------------
980 function tax_groups_list($name, $selected_id=null,
981 $none_option=false, $submit_on_change=false)
983 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
985 return combo_input($name, $selected_id, $sql, 'id', 'name',
988 'spec_option' => $none_option,
989 'spec_id' => ALL_NUMERIC,
990 'select_submit'=> $submit_on_change,
995 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
998 echo "<td>$label</td>\n";
1000 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1004 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1006 echo "<tr><td class='label'>$label</td>";
1007 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1011 //------------------------------------------------------------------------------------
1013 function item_tax_types_list($name, $selected_id=null)
1015 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1016 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1019 function item_tax_types_list_cells($label, $name, $selected_id=null)
1022 echo "<td>$label</td>\n";
1024 echo item_tax_types_list($name, $selected_id);
1028 function item_tax_types_list_row($label, $name, $selected_id=null)
1030 echo "<tr><td class='label'>$label</td>";
1031 item_tax_types_list_cells(null, $name, $selected_id);
1035 //------------------------------------------------------------------------------------
1037 function shippers_list($name, $selected_id=null)
1039 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1040 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1041 array('order'=>array('shipper_name')));
1044 function shippers_list_cells($label, $name, $selected_id=null)
1047 echo "<td>$label</td>\n";
1049 echo shippers_list($name, $selected_id);
1053 function shippers_list_row($label, $name, $selected_id=null)
1055 echo "<tr><td class='label'>$label</td>";
1056 shippers_list_cells(null, $name, $selected_id);
1060 //-------------------------------------------------------------------------------------
1062 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1064 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1065 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1066 array('order'=>array('salesman_name'),
1067 'spec_option' => $spec_opt,
1068 'spec_id' => ALL_NUMERIC));
1071 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1074 echo "<td>$label</td>\n";
1076 echo sales_persons_list($name, $selected_id, $spec_opt);
1080 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1082 echo "<tr><td class='label'>$label</td>";
1083 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1087 //------------------------------------------------------------------------------------
1089 function sales_areas_list($name, $selected_id=null)
1091 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1092 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1095 function sales_areas_list_cells($label, $name, $selected_id=null)
1098 echo "<td>$label</td>\n";
1100 echo sales_areas_list($name, $selected_id);
1104 function sales_areas_list_row($label, $name, $selected_id=null)
1106 echo "<tr><td class='label'>$label</td>";
1107 sales_areas_list_cells(null, $name, $selected_id);
1111 //------------------------------------------------------------------------------------
1113 function sales_groups_list($name, $selected_id=null, $special_option=false)
1115 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1116 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1117 'spec_option' => $special_option===true ? ' ' : $special_option,
1118 'order' => 'description', 'spec_id' => 0,
1122 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1125 echo "<td>$label</td>\n";
1127 echo sales_groups_list($name, $selected_id, $special_option);
1131 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1133 echo "<tr><td class='label'>$label</td>";
1134 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1138 //------------------------------------------------------------------------------------
1140 function _format_template_items($row)
1142 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1145 function templates_list($name, $selected_id=null, $special_option=false)
1147 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1148 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1149 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1150 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1151 'format' => '_format_template_items',
1152 'spec_option' => $special_option===true ? ' ' : $special_option,
1153 'order' => 'order_no', 'spec_id' => 0,
1157 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1160 echo "<td>$label</td>\n";
1162 echo templates_list($name, $selected_id, $special_option);
1166 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1168 echo "<tr><td class='label'>$label</td>";
1169 templates_list_cells(null, $name, $selected_id, $special_option);
1173 //------------------------------------------------------------------------------------
1175 function workorders_list($name, $selected_id=null)
1177 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1178 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1181 function workorders_list_cells($label, $name, $selected_id=null)
1184 echo "<td>$label</td>\n";
1186 echo workorders_list($name, $selected_id);
1190 function workorders_list_row($label, $name, $selected_id=null)
1192 echo "<tr><td class='label'>$label</td>";
1193 workorders_list_cells(null, $name, $selected_id);
1197 //------------------------------------------------------------------------------------
1199 function payment_terms_list($name, $selected_id=null)
1201 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1202 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1205 function payment_terms_list_cells($label, $name, $selected_id=null)
1208 echo "<td>$label</td>\n";
1210 echo payment_terms_list($name, $selected_id);
1214 function payment_terms_list_row($label, $name, $selected_id=null)
1216 echo "<tr><td class='label'>$label</td>";
1217 payment_terms_list_cells(null, $name, $selected_id);
1221 //------------------------------------------------------------------------------------
1223 function credit_status_list($name, $selected_id=null)
1225 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1226 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1229 function credit_status_list_cells($label, $name, $selected_id=null)
1232 echo "<td>$label</td>\n";
1234 echo credit_status_list($name, $selected_id);
1238 function credit_status_list_row($label, $name, $selected_id=null)
1240 echo "<tr><td class='label'>$label</td>";
1241 credit_status_list_cells(null, $name, $selected_id);
1245 //-----------------------------------------------------------------------------------------------
1247 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1249 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1251 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1253 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1255 'select_submit'=> $submit_on_change,
1256 // 'async' => false,
1260 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1263 echo "<td>$label</td>\n";
1265 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1269 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1271 echo "<tr><td class='label'>$label</td>";
1272 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1276 //-----------------------------------------------------------------------------------------------
1278 function movement_types_list($name, $selected_id=null)
1280 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1281 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1284 function movement_types_list_cells($label, $name, $selected_id=null)
1287 echo "<td>$label</td>\n";
1289 echo movement_types_list($name, $selected_id);
1293 function movement_types_list_row($label, $name, $selected_id=null)
1295 echo "<tr><td class='label'>$label</td>";
1296 movement_types_list_cells(null, $name, $selected_id);
1300 //-----------------------------------------------------------------------------------------------
1301 function _format_date($row)
1303 return sql2date($row['reconciled']);
1306 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1308 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1309 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1310 GROUP BY reconciled";
1311 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1313 'spec_option' => $special_option,
1314 'format' => '_format_date',
1316 'select_submit'=> $submit_on_change
1320 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1323 echo "<td>$label</td>\n";
1325 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1329 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1332 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1336 //-----------------------------------------------------------------------------------------------
1338 function workcenter_list($name, $selected_id=null, $all_option=false)
1342 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1344 return combo_input($name, $selected_id, $sql, 'id', 'name',
1346 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1347 'spec_id' => $all_items,
1351 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1353 default_focus($name);
1355 echo "<td>$label</td>\n";
1357 echo workcenter_list($name, $selected_id, $all_option);
1361 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1363 echo "<tr><td class='label'>$label</td>";
1364 workcenter_list_cells(null, $name, $selected_id, $all_option);
1368 //-----------------------------------------------------------------------------------------------
1370 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1372 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1373 FROM ".TB_PREF."bank_accounts";
1375 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1377 'format' => '_format_add_curr',
1378 'select_submit'=> $submit_on_change,
1383 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1386 echo "<td>$label</td>\n";
1388 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1392 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1394 echo "<tr><td class='label'>$label</td>";
1395 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1398 //-----------------------------------------------------------------------------------------------
1400 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1402 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1403 FROM ".TB_PREF."bank_accounts
1404 WHERE ".TB_PREF."bank_accounts.account_type=3";
1407 echo "<tr><td class='label'>$label</td>\n";
1409 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1411 'format' => '_format_add_curr',
1412 'select_submit'=> $submit_on_change,
1415 echo "</td></tr>\n";
1417 //-----------------------------------------------------------------------------------------------
1419 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1421 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1423 default_focus($name);
1426 echo "<td class='label'>$label</td>\n";
1429 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1431 'select_submit'=> $submit_on_change,
1433 'spec_option' =>$spec_option,
1435 'order'=> array('pos_name')
1437 echo "</td></tr>\n";
1440 //-----------------------------------------------------------------------------------------------
1441 // Payment type selector for current user.
1443 function sale_payment_list($name, $selected_id=null, $submit_on_change=true)
1445 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1446 $paym = get_sales_point(user_pos());
1448 if (!$paym['cash_sale'] || !$paym['credit_sale']) {
1449 if ($paym['cash_sale']) // only cash
1450 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1452 $sql .= " WHERE days_before_due!=0 OR day_in_following_month!=0";
1455 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1457 'select_submit'=> $submit_on_change,
1463 function sale_payment_list_cells($label, $name, $selected_id=null, $submit_on_change=true)
1466 echo "<td class='label'>$label</td>\n";
1469 echo sale_payment_list($name, $selected_id, $submit_on_change);
1473 //-----------------------------------------------------------------------------------------------
1475 function class_list($name, $selected_id=null, $submit_on_change=false)
1477 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1479 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1481 'select_submit'=> $submit_on_change,
1487 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1490 echo "<td>$label</td>\n";
1492 echo class_list($name, $selected_id, $submit_on_change);
1496 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1498 echo "<tr><td class='label'>$label</td>";
1499 class_list_cells(null, $name, $selected_id, $submit_on_change);
1503 //-----------------------------------------------------------------------------------------------
1504 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1506 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1507 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1508 array('order'=>'category_id',
1509 'spec_option' => $spec_opt,
1511 'select_submit'=> $submit_on_change,
1516 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1519 echo "<td>$label</td>\n";
1521 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1525 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1527 echo "<tr><td class='label'>$label</td>";
1528 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1532 //-----------------------------------------------------------------------------------------------
1534 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1538 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1540 return combo_input($name, $selected_id, $sql, 'id', 'name',
1542 'order' => array('class_id', 'id', 'parent'),
1543 'spec_option' =>$all_option,
1544 'spec_id' => $all_items
1548 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1551 echo "<td>$label</td>\n";
1553 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1557 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1559 echo "<tr><td class='label'>$label</td>";
1560 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1565 //-----------------------------------------------------------------------------------------------
1566 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1567 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1569 if ($skip_bank_accounts)
1570 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1571 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1572 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1573 ."ON chart.account_code=acc.account_code
1574 WHERE acc.account_code IS NULL
1575 AND chart.account_type=type.id";
1577 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1578 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1579 WHERE chart.account_type=type.id";
1581 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1583 'format' => '_format_account',
1584 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1586 'order' => array('type.class_id','type.id','account_code'),
1587 'search_box' => $cells,
1588 'search_submit' => false,
1592 'select_submit'=> $submit_on_change,
1595 'show_inactive' => $all
1600 function _format_account($row)
1602 return $row[0] . " " . $row[1];
1605 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1606 $skip_bank_accounts=false, $cells=false, $all_option=false,
1607 $submit_on_change=false, $all=false)
1610 echo "<td>$label</td>\n";
1612 echo gl_all_accounts_list($name, $selected_id,
1613 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1617 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1618 $skip_bank_accounts=false, $cells=false, $all_option=false)
1620 echo "<tr><td class='label'>$label</td>";
1621 gl_all_accounts_list_cells(null, $name, $selected_id,
1622 $skip_bank_accounts, $cells, $all_option);
1626 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1629 $items['0'] = strlen($name_no) ? $name_no : _("No");
1630 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1632 return array_selector($name, $selected_id, $items,
1634 'select_submit'=> $submit_on_change,
1635 'async' => false ) ); // FIX?
1638 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1641 echo "<td>$label</td>\n";
1643 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1647 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1649 echo "<tr><td class='label'>$label</td>";
1650 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1654 //------------------------------------------------------------------------------------------------
1656 function languages_list($name, $selected_id=null)
1658 global $installed_languages;
1661 foreach ($installed_languages as $lang)
1662 $items[$lang['code']] = $lang['name'];
1664 return array_selector($name, $selected_id, $items);
1667 function languages_list_cells($label, $name, $selected_id=null)
1670 echo "<td>$label</td>\n";
1672 echo languages_list($name, $selected_id);
1676 function languages_list_row($label, $name, $selected_id=null)
1678 echo "<tr><td class='label'>$label</td>";
1679 languages_list_cells(null, $name, $selected_id);
1683 //------------------------------------------------------------------------------------------------
1685 function bank_account_types_list($name, $selected_id=null)
1687 global $bank_account_types;
1689 return array_selector($name, $selected_id, $bank_account_types);
1692 function bank_account_types_list_cells($label, $name, $selected_id=null)
1695 echo "<td>$label</td>\n";
1697 echo bank_account_types_list($name, $selected_id);
1701 function bank_account_types_list_row($label, $name, $selected_id=null)
1703 echo "<tr><td class='label'>$label</td>";
1704 bank_account_types_list_cells(null, $name, $selected_id);
1708 //------------------------------------------------------------------------------------------------
1709 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1711 global $payment_person_types;
1714 foreach ($payment_person_types as $key=>$type)
1716 if ($key != PT_WORKORDER)
1717 $items[$key] = $type;
1719 return array_selector($name, $selected_id, $items,
1720 array( 'select_submit'=> $submit_on_change ) );
1723 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1726 echo "<td>$label</td>\n";
1728 echo payment_person_types_list($name, $selected_id, $related);
1732 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1734 echo "<tr><td class='label'>$label</td>";
1735 payment_person_types_list_cells(null, $name, $selected_id, $related);
1739 //------------------------------------------------------------------------------------------------
1741 function wo_types_list($name, $selected_id=null)
1743 global $wo_types_array;
1745 return array_selector($name, $selected_id, $wo_types_array,
1746 array( 'select_submit'=> true, 'async' => true ) );
1749 function wo_types_list_row($label, $name, $selected_id=null)
1751 echo "<tr><td class='label'>$label</td><td>\n";
1752 echo wo_types_list($name, $selected_id);
1753 echo "</td></tr>\n";
1756 //------------------------------------------------------------------------------------------------
1758 function dateformats_list_row($label, $name, $value=null)
1760 global $dateformats;
1762 echo "<tr><td class='label'>$label</td>\n<td>";
1763 echo array_selector( $name, $value, $dateformats );
1764 echo "</td></tr>\n";
1767 function dateseps_list_row($label, $name, $value=null)
1771 echo "<tr><td class='label'>$label</td>\n<td>";
1772 echo array_selector( $name, $value, $dateseps );
1773 echo "</td></tr>\n";
1776 function thoseps_list_row($label, $name, $value=null)
1780 echo "<tr><td class='label'>$label</td>\n<td>";
1781 echo array_selector( $name, $value, $thoseps );
1782 echo "</td></tr>\n";
1785 function decseps_list_row($label, $name, $value=null)
1789 echo "<tr><td class='label'>$label</td>\n<td>";
1790 echo array_selector( $name, $value, $decseps );
1791 echo "</td></tr>\n";
1794 function themes_list_row($label, $name, $value=null)
1796 global $path_to_root;
1798 $path = $path_to_root.'/themes/';
1800 $themedir = opendir($path);
1801 while(false !== ($fname = readdir($themedir)))
1803 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1805 $themes[$fname] = $fname;
1810 echo "<tr><td class='label'>$label</td>\n<td>";
1811 echo array_selector( $name, $value, $themes );
1812 echo "</td></tr>\n";
1815 function pagesizes_list_row($label, $name, $value=null)
1820 foreach ($pagesizes as $pz)
1823 echo "<tr><td class='label'>$label</td>\n<td>";
1824 echo array_selector( $name, $value, $items );
1825 echo "</td></tr>\n";
1828 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false)
1830 global $systypes_array;
1832 return array_selector($name, $value, $systypes_array,
1834 'spec_option'=> $spec_opt,
1835 'spec_id' => ALL_NUMERIC,
1836 'select_submit'=> $submit_on_change,
1842 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false)
1845 echo "<td>$label</td>\n";
1847 echo systypes_list($name, $value, false, $submit_on_change);
1851 function systypes_list_row($label, $name, $value=null, $submit_on_change=false)
1853 echo "<tr><td class='label'>$label</td>";
1854 systypes_list_cells(null, $name, $value, false, $submit_on_change);
1858 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1860 global $systypes_array;
1863 echo "<td>$label</td>\n";
1866 $items = $systypes_array;
1868 // exclude quotes, orders and dimensions
1869 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1870 ST_SALESQUOTE) as $excl)
1871 unset($items[$excl]);
1873 echo array_selector($name, $value, $items,
1875 'spec_option'=> _("All"),
1877 'select_submit'=> $submit_on_change,
1884 function cust_allocations_list_cells($label, $name, $selected=null)
1892 $all_items=>_("All Types"),
1893 '1'=> _("Sales Invoices"),
1894 '2'=> _("Overdue Invoices"),
1895 '3' => _("Payments"),
1896 '4' => _("Credit Notes"),
1897 '5' => _("Delivery Notes")
1899 echo array_selector($name, $selected, $allocs);
1903 function supp_allocations_list_cell($name, $selected=null)
1909 $all_items=>_("All Types"),
1910 '1'=> _("Invoices"),
1911 '2'=> _("Overdue Invoices"),
1912 '3' => _("Payments"),
1913 '4' => _("Credit Notes"),
1914 '5' => _("Overdue Credit Notes")
1916 echo array_selector($name, $selected, $allocs);
1920 function policy_list_cells($label, $name, $selected=null)
1925 echo array_selector($name, $selected,
1926 array( '' => _("Automatically put balance on back order"),
1927 'CAN' => _("Cancel any quantites not delivered")) );
1931 function policy_list_row($label, $name, $selected=null)
1933 echo "<tr><td class='label'>$label</td>";
1934 policy_list_cells(null, $name, $selected);
1938 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1943 echo array_selector($name, $selected,
1944 array( 'Return' => _("Items Returned to Inventory Location"),
1945 'WriteOff' => _("Items Written Off")),
1946 array( 'select_submit'=> $submit_on_change ) );
1950 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1952 echo "<tr><td class='label'>$label</td>";
1953 credit_type_list_cells(null, $name, $selected, $submit_on_change);
1957 function number_list($name, $selected, $from, $to, $no_option=false)
1960 for ($i = $from; $i <= $to; $i++)
1963 return array_selector($name, $selected, $items,
1964 array( 'spec_option' => $no_option,
1965 'spec_id' => ALL_NUMERIC) );
1968 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
1973 echo number_list($name, $selected, $from, $to, $no_option);
1977 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
1979 echo "<tr><td class='label'>$label</td>";
1980 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
1984 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
1985 $submit_on_change=true)
1987 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
1988 ." GROUP BY profile";
1989 $result = db_query($sql, 'cannot get all profile names');
1990 $profiles = array();
1991 while($myrow=db_fetch($result)) {
1992 $profiles[$myrow['profile']] = $myrow['profile'];
1997 echo "<td class='label'>$label</td>\n";
2000 echo array_selector($name, $selected_id, $profiles,
2001 array( 'select_submit'=> $submit_on_change,
2002 'spec_option'=>$spec_opt,
2006 echo "</td></tr>\n";
2009 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2011 static $printers; // query only once for page display
2014 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2015 $result = db_query($sql, 'cannot get all printers');
2016 $printers = array();
2017 while($myrow=db_fetch($result)) {
2018 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2021 return array_selector($name, $selected_id, $printers,
2022 array( 'select_submit'=> $submit_on_change,
2023 'spec_option'=>$spec_opt,
2028 //------------------------------------------------------------------------------------------------
2030 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2033 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2035 $sql .= " WHERE type=$type";
2037 return combo_input($name, $selected_id, $sql, 'id', 'description',
2040 'order' => 'description',
2041 'select_submit'=> $submit_on_change,
2047 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2050 echo "<td>$label</td>\n";
2052 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2056 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2058 echo "<tr><td class='label'>$label</td>";
2059 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2064 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2066 global $quick_actions;
2068 echo "<tr><td class='label'>$label</td><td>";
2069 echo array_selector($name, $selected_id, $quick_actions,
2071 'select_submit'=> $submit_on_change
2073 echo "</td></tr>\n";
2076 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2078 global $quick_entry_types;
2080 echo "<tr><td class='label'>$label</td><td>";
2081 echo array_selector($name, $selected_id, $quick_entry_types,
2083 'select_submit'=> $submit_on_change
2085 echo "</td></tr>\n";
2088 function record_status_list_row($label, $name) {
2089 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2092 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2094 global $class_types;
2096 echo "<tr><td class='label'>$label</td><td>";
2097 echo array_selector($name, $selected_id, $class_types,
2099 'select_submit'=> $submit_on_change
2101 echo "</td></tr>\n";
2104 //------------------------------------------------------------------------------------------------
2106 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2107 $show_inactive = false)
2111 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2113 return combo_input($name, $selected_id, $sql, 'id', 'description',
2115 'spec_option'=>$new_item ? _("New role") : false,
2117 'select_submit'=> $submit_on_change,
2118 'show_inactive' => $show_inactive
2122 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2123 $show_inactive = false)
2126 echo "<td>$label</td>\n";
2128 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2132 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2133 $show_inactive = false)
2135 echo "<tr><td class='label'>$label</td>";
2136 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2140 function tab_list_row($label, $name, $selected_id=null, $all = false)
2142 global $installed_extensions;
2145 foreach ($_SESSION['App']->applications as $app) {
2146 $tabs[$app->id] = access_string($app->name, true);
2148 if ($all) { // add also not active ext. modules
2149 foreach ($installed_extensions as $ext) {
2150 if ($ext['type'] == 'module' && !$ext['active'])
2151 $tabs[$ext['tab']] = access_string($ext['title'], true);
2155 echo "<td class='label'>$label</td><td>\n";
2156 echo array_selector($name, $selected_id, $tabs);
2157 echo "</td></tr>\n";
2160 //-----------------------------------------------------------------------------------------------
2162 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2165 global $path_to_root;
2166 include_once($path_to_root . "/admin/db/tags_db.inc");
2167 $results = get_tags($type, $all);
2169 while ($tag = db_fetch($results))
2170 $tags[$tag['id']] = $tag['name'];
2172 if (!isset($tags)) {
2173 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2176 return array_selector($name, null, $tags,
2179 'height' => $height,
2180 'spec_option'=> $spec_opt,
2185 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2188 echo "<td>$label</td>\n";
2190 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2195 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2197 echo "<tr><td class='label'>$label</td>";
2198 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2202 //---------------------------------------------------------------------------------------------
2203 // List of sets of active extensions
2205 function extset_list($name, $value=null, $submit_on_change=false)
2207 global $db_connections;
2210 foreach ($db_connections as $comp)
2211 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2212 return array_selector( $name, $value, $items,
2214 'spec_option'=> _("Available and/or installed"),
2216 'select_submit'=> $submit_on_change,