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 fragment inside id
50 // 1 - with hidden search box, search by option text
51 // 2 - with (optional) visible search box, search by fragment at the start of id
52 // 3 - 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 'height' => false, // number of lines in select box
58 'cells' => false, // combo displayed as 2 <td></td> cells
59 'search' => array(), // sql field names to search
60 'format' => null, // format functions for regular options
62 'box_hint' => null, // box/selectors hints; null = std see below
63 'category' => false, // category column name or false
64 'show_inactive' => false, // show inactive records.
65 'editable' => false // false, or length of editable entry field
67 // ------ merge options with defaults ----------
69 $opts = array_merge($opts, $options);
70 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
72 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
73 // select content filtered by search field:
74 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
75 // select set by select content field
76 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
78 $select_submit = $opts['select_submit'];
79 $spec_id = $opts['spec_id'];
80 $spec_option = $opts['spec_option'];
81 if ($opts['type'] == 0) {
84 } elseif($opts['type'] == 1) {
92 $disabled = $opts['disabled'] ? "disabled" : '';
93 $multi = $opts['multi'];
95 if(!count($opts['search'])) {
96 $opts['search'] = array($by_id ? $valfield : $namefield);
98 if ($opts['sel_hint'] === null)
99 $opts['sel_hint'] = $by_id || $search_box==false ?
100 '' : _('Press Space tab for search pattern entry');
102 if ($opts['box_hint'] === null)
103 $opts['box_hint'] = $search_box && $search_submit != false ?
104 ($by_id ? _('Enter code fragment to search or * for all')
105 : _('Enter description fragment to search or * for all')) :'';
107 if ($selected_id == null) {
108 $selected_id = get_post($name, (string)$opts['default']);
110 if(!is_array($selected_id))
111 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
113 $txt = get_post($search_box);
116 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
117 if ($by_id) $txt = $_POST[$name];
120 $Ajax->activate('_page_body');
122 $Ajax->activate($name);
124 if (isset($_POST[$search_button])) {
126 $Ajax->activate('_page_body');
128 $Ajax->activate($name);
131 // search related sql modifications
133 $rel = "rel='$search_box'"; // set relation to list
134 if ($opts['search_submit']) {
135 if (isset($_POST[$search_button])) {
136 $selected_id = array(); // ignore selected_id while search
138 $Ajax->activate('_page_body');
140 $Ajax->activate($name);
143 if ($spec_option === false && $selected_id == array())
146 $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id));
151 foreach($opts['search'] as $i=> $s)
152 $opts['search'][$i] = $s . " LIKE "
153 .db_escape(($class=='combo3' ? '' : '%').$txt.'%');
154 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
160 if (count($opts['where'])) {
161 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
162 $where .= '('. implode($opts['where'], ' AND ') . ')';
163 $group_pos = strpos($sql, 'GROUP BY');
165 $group = substr($sql, $group_pos);
166 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
171 if ($opts['order'] != false) {
172 if (!is_array($opts['order']))
173 $opts['order'] = array($opts['order']);
174 $sql .= ' ORDER BY '.implode(',',$opts['order']);
178 // ------ make selector ----------
179 $selector = $first_opt = '';
184 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
185 //if($name=='curr_default') display_notification($opts['search_submit']);
186 if($result = db_query($sql)) {
187 while ($contact_row = db_fetch($result)) {
188 $value = $contact_row[0];
189 $descr = $opts['format']==null ? $contact_row[1] :
190 call_user_func($opts['format'], $contact_row);
192 if (get_post($search_button) && ($txt == $value)) {
193 $selected_id[] = $value;
196 if (in_array((string)$value, $selected_id, true)) {
199 $edit = $opts['editable'] && $contact_row['editable']
200 && (@$_POST[$search_box] == $value)
201 ? $contact_row[1] : false; // get non-formatted description
203 break; // selected field is editable - abandon list construction
205 // show selected option even if inactive
206 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
209 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
211 if ($first_id === false) {
215 $cat = $contact_row[$opts['category']];
216 if ($opts['category'] !== false && $cat != $lastcat){
217 $selector .= "<optgroup label='".$cat."'>\n";
220 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
222 db_free_result($result);
225 // Prepend special option.
226 if ($spec_option !== false) { // if special option used - add it
227 $first_id = $spec_id;
228 $first_opt = $spec_option;
230 // if($first_id !== false) {
231 $sel = $found===false ? 'selected' : '';
232 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
233 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
237 if ($found===false) {
238 $selected_id = array($first_id);
241 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
243 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
244 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
245 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
246 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
248 if ($by_id && ($search_box != false || $opts['editable']) ) {
249 // on first display show selector list
250 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
251 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
252 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
253 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
254 set_focus($name.'_text'); // prevent lost focus
255 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
256 set_focus($name); // prevent lost focus
257 if (!$opts['editable'])
259 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
262 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
264 // span for select list/input field update
265 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
267 // if selectable or editable list is used - add select button
268 if ($select_submit != false || $search_button) {
269 global $_select_button;
270 // button class selects form reload/ajax selector update
271 $selector .= sprintf($_select_button, $disabled, user_theme(),
272 (fallback_mode() ? '' : 'display:none;'),
273 '_'.$name.'_update')."\n";
275 // ------ make combo ----------
277 if ($search_box != false) {
278 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
279 $opts['size']."' maxlength='".$opts['max'].
280 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
281 .$opts['box_hint']."'"
282 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
284 if ($search_submit != false || $opts['editable']) {
285 global $_search_button;
286 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
287 (fallback_mode() ? '' : 'display:none;'),
288 $search_submit ? $search_submit : "_{$name}_button")."\n";
291 default_focus(($search_box && $by_id) ? $search_box : $name);
293 if ($search_box && $opts['cells'])
294 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
296 $str = $edit_entry.$selector;
302 Returns true if selector $name is subject to update.
304 function list_updated($name)
306 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
308 //----------------------------------------------------------------------------------------------
309 // Universal array combo generator
310 // $items is array of options 'value' => 'description'
311 // Options is reduced set of combo_selector options and is merged with defaults.
313 function array_selector($name, $selected_id, $items, $options=null)
317 $opts = array( // default options
318 'spec_option'=>false, // option text or false
319 'spec_id' => 0, // option id
320 'select_submit' => false, //submit on select: true/false
321 'async' => true, // select update via ajax (true) vs _page_body reload
322 'default' => '', // default value when $_POST is not set
323 'multi'=>false, // multiple select
324 // search box parameters
325 'height' => false, // number of lines in select box
329 // ------ merge options with defaults ----------
331 $opts = array_merge($opts, $options);
332 $select_submit = $opts['select_submit'];
333 $spec_id = $opts['spec_id'];
334 $spec_option = $opts['spec_option'];
335 $disabled = $opts['disabled'] ? "disabled" : '';
336 $multi = $opts['multi'];
338 if ($selected_id == null) {
339 $selected_id = get_post($name, $opts['default']);
341 if(!is_array($selected_id))
342 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
344 if (isset($_POST[ '_'.$name.'_update'])) {
346 $Ajax->activate('_page_body');
348 $Ajax->activate($name);
351 // ------ make selector ----------
352 $selector = $first_opt = '';
355 //if($name=='SelectStockFromList') display_error($sql);
356 foreach($items as $value=>$descr) {
358 if (in_array((string)$value, $selected_id, true)) {
362 if ($first_id === false) {
366 $selector .= "<option $sel value='$value'>$descr</option>\n";
369 if ($first_id!==false) {
370 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
371 $selector = sprintf($first_opt, $sel).$selector;
373 // Prepend special option.
374 if ($spec_option !== false) { // if special option used - add it
375 $first_id = $spec_id;
376 $first_opt = $spec_option;
377 $sel = $found===false ? 'selected' : '';
378 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
382 if ($found===false) {
383 $selected_id = array($first_id);
385 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
387 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
388 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
389 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
390 . $opts['sel_hint']."'>".$selector."</select>\n";
392 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
394 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
396 if ($select_submit != false) { // if submit on change is used - add select button
397 global $_select_button;
398 $selector .= sprintf($_select_button, $disabled, user_theme(),
399 (fallback_mode() ? '' : 'display:none;'),
400 '_'.$name.'_update')."\n";
402 default_focus($name);
406 //----------------------------------------------------------------------------------------------
408 function _format_add_curr($row)
410 static $company_currency;
412 if ($company_currency == null)
414 $company_currency = get_company_currency();
416 return $row[1] . ($row[2] == $company_currency ?
417 '' : (" - " . $row[2]));
420 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
421 $all=false, $editkey = false)
425 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
427 $mode = get_company_pref('no_supplier_list');
430 set_editor('supplier', $name, $editkey);
432 return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
434 'format' => '_format_add_curr',
435 'order' => array('supp_ref'),
436 'search_box' => $mode!=0,
438 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
439 'spec_id' => $all_items,
440 'select_submit'=> $submit_on_change,
442 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
443 _('Select supplier'),
444 'show_inactive'=>$all
448 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
449 $submit_on_change=false, $all=false, $editkey = false)
452 echo "<td>$label</td><td>\n";
453 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
458 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
459 $submit_on_change=false, $all=false, $editkey = false)
461 echo "<tr><td class='label'>$label</td><td>";
462 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
466 //----------------------------------------------------------------------------------------------
468 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
469 $show_inactive=false, $editkey = false)
473 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
475 $mode = get_company_pref('no_customer_list');
478 set_editor('customer', $name, $editkey);
480 return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
482 'format' => '_format_add_curr',
483 'order' => array('debtor_ref'),
484 'search_box' => $mode!=0,
487 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
488 'spec_id' => $all_items,
489 'select_submit'=> $submit_on_change,
491 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
492 _('Select customer'),
493 'show_inactive' => $show_inactive
497 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
498 $submit_on_change=false, $show_inactive=false, $editkey = false)
501 echo "<td>$label</td>\n";
503 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
504 $show_inactive, $editkey);
508 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
509 $submit_on_change=false, $show_inactive=false, $editkey = false)
511 echo "<tr><td class='label'>$label</td><td nowrap>";
512 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
513 $show_inactive, $editkey);
514 echo "</td>\n</tr>\n";
517 //------------------------------------------------------------------------------------------------
519 function customer_branches_list($customer_id, $name, $selected_id=null,
520 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
524 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
525 WHERE debtor_no=" . db_escape($customer_id)." ";
528 set_editor('branch', $name, $editkey);
530 $where = $enabled ? array("disable_trans = 0") : array();
531 return combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
534 'order' => array('branch_ref'),
535 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
536 'spec_id' => $all_items,
537 'select_submit'=> $submit_on_change,
538 'sel_hint' => _('Select customer branch')
541 //------------------------------------------------------------------------------------------------
543 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
544 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
547 echo "<td>$label</td>\n";
549 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
550 $submit_on_change, $editkey);
554 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
555 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
557 echo "<tr><td class='label'>$label</td>";
558 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
559 $all_option, $enabled, $submit_on_change, $editkey);
563 //------------------------------------------------------------------------------------------------
565 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
569 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
571 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
573 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
574 'spec_id' => $all_items,
575 'select_submit'=> $submit_on_change
579 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
582 echo "<td>$label</td>\n";
584 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
588 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
590 echo "<tr><td class='label'>$label</td>";
591 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
595 //-----------------------------------------------------------------------------------------------
597 function currencies_list($name, $selected_id=null, $submit_on_change=false)
599 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
601 // default to the company currency
602 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
604 'select_submit'=> $submit_on_change,
605 'default' => get_company_currency(),
610 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
613 echo "<td>$label</td>\n";
615 echo currencies_list($name, $selected_id, $submit_on_change);
619 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
621 echo "<tr><td class='label'>$label</td>";
622 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
626 //---------------------------------------------------------------------------------------------------
628 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
631 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
633 // default to the company current fiscal year
635 return combo_input($name, $selected_id, $sql, 'id', '',
638 'default' => get_company_pref('f_year'),
639 'format' => '_format_fiscalyears',
640 'select_submit'=> $submit_on_change,
645 function _format_fiscalyears($row)
647 return sql2date($row[1]) . " - " . sql2date($row[2])
648 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
651 function fiscalyears_list_cells($label, $name, $selected_id=null)
654 echo "<td>$label</td>\n";
656 echo fiscalyears_list($name, $selected_id);
660 function fiscalyears_list_row($label, $name, $selected_id=null)
662 echo "<tr><td class='label'>$label</td>";
663 fiscalyears_list_cells(null, $name, $selected_id);
666 //------------------------------------------------------------------------------------
668 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
669 $submit_on_change=false, $showclosed=false, $showtype=1)
671 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
674 'order' => 'reference',
675 'spec_option'=>$no_option ? $showname : false,
677 'select_submit'=> $submit_on_change,
682 $options['where'][] = "closed=0";
684 $options['where'][] = "type_=$showtype";
686 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
689 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
690 $showclosed=false, $showtype=0, $submit_on_change=false)
693 echo "<td>$label</td>\n";
695 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
699 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
700 $showclosed=false, $showtype=0, $submit_on_change=false)
702 echo "<tr><td class='label'>$label</td>";
703 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
704 $showclosed, $showtype, $submit_on_change);
708 //---------------------------------------------------------------------------------------------------
710 function stock_items_list($name, $selected_id=null, $all_option=false,
711 $submit_on_change=false, $opts=array(), $editkey = false)
715 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
716 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
719 set_editor('item', $name, $editkey);
721 return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
724 'format' => '_format_stock_items',
725 'spec_option' => $all_option===true ? _("All Items") : $all_option,
726 'spec_id' => $all_items,
727 'search_box' => true,
728 'search' => array("stock_id", "c.description","s.description"),
729 'search_submit' => get_company_pref('no_item_list')!=0,
731 'select_submit'=> $submit_on_change,
733 'order' => array('c.description','stock_id')
737 function _format_stock_items($row)
739 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
742 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
743 $submit_on_change=false, $all=false, $editkey = false)
746 echo "<td>$label</td>\n";
747 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
748 array('cells'=>true, 'show_inactive'=>$all), $editkey);
751 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
754 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
758 //---------------------------------------------------------------------------------------------------
760 // Select item via foreign code.
762 function sales_items_list($name, $selected_id=null, $all_option=false,
763 $submit_on_change=false, $type='', $opts=array())
767 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
768 i.inactive, if(count(*)>1, '0', s.editable) as editable
770 ".TB_PREF."stock_master s,
771 ".TB_PREF."item_codes i
773 ".TB_PREF."stock_category c
774 ON i.category_id=c.category_id
775 WHERE i.stock_id=s.stock_id";
778 if ($type == 'local') { // exclude foreign codes
779 $sql .= " AND !i.is_foreign";
780 } elseif ($type == 'kits') { // sales kits
781 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
783 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
784 $sql .= " GROUP BY i.item_code";
786 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
789 'format' => '_format_stock_items',
790 'spec_option' => $all_option===true ? _("All Items") : $all_option,
791 'spec_id' => $all_items,
792 'search_box' => true,
793 'search' => array("i.item_code", "c.description", "i.description"),
794 'search_submit' => get_company_pref('no_item_list')!=0,
796 'select_submit'=> $submit_on_change,
798 'order' => array('c.description','i.item_code'),
804 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
807 echo "<td>$label</td>\n";
808 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
809 '', array('cells'=>true));
812 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
814 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
815 'kits', array('cells'=>false, 'editable' => false));
818 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
822 echo "<td class='label'>$label</td>\n";
824 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
825 'local', array('cells'=>false, 'editable' => false));
828 //------------------------------------------------------------------------------------
830 function stock_manufactured_items_list($name, $selected_id=null,
831 $all_option=false, $submit_on_change=false)
833 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
834 array('where'=>array("mb_flag= 'M'")));
837 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
838 $all_option=false, $submit_on_change=false)
841 echo "<td>$label</td>\n";
843 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
847 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
848 $all_option=false, $submit_on_change=false)
850 echo "<tr><td class='label'>$label</td>";
851 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
854 //------------------------------------------------------------------------------------
856 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
857 $all_option=false, $submit_on_change=false, $editkey = false)
859 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
860 array('where'=>array("stock_id != '$parent_stock_id'")), $editkey);
863 function stock_component_items_list_cells($label, $name, $parent_stock_id,
864 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
867 echo "<td>$label</td>\n";
868 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
869 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true),
872 //------------------------------------------------------------------------------------
874 function stock_costable_items_list($name, $selected_id=null,
875 $all_option=false, $submit_on_change=false)
877 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
878 array('where'=>array("mb_flag!='D'")));
881 function stock_costable_items_list_cells($label, $name, $selected_id=null,
882 $all_option=false, $submit_on_change=false)
885 echo "<td>$label</td>\n";
886 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
887 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
890 //------------------------------------------------------------------------------------
891 function stock_purchasable_items_list($name, $selected_id=null,
892 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
894 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
895 array('where'=>array("mb_flag!= 'M'"),
896 'show_inactive'=>$all), $editkey);
899 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
901 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
902 $all_option=false, $submit_on_change=false, $editkey=false)
905 echo "<td>$label</td>\n";
906 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
907 array('where'=>array("mb_flag!= 'M'"),
909 'cells'=>true), $editkey);
912 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
913 $all_option=false, $submit_on_change=false, $editkey=false)
915 echo "<tr><td class='label'>$label</td>";
916 stock_purchasable_items_list_cells(null, $name, $selected_id=null,
917 $all_option, $submit_on_change, $editkey);
921 //------------------------------------------------------------------------------------
923 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
929 echo "<td class='label'>$label</td>\n";
932 echo 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 class='label'>$label</td>\n";
947 while($unit = db_fetch($result))
948 $units[$unit['abbr']] = $unit['name'];
950 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
955 //------------------------------------------------------------------------------------
957 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
959 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
961 return combo_input($name, $selected_id, $sql, 'id', 'name',
963 'spec_option' => $none_option,
964 'spec_id' => ALL_NUMERIC,
965 'select_submit'=> $submit_on_change,
970 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
971 $submit_on_change=false)
974 echo "<td>$label</td>\n";
976 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
980 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
981 $submit_on_change=false)
983 echo "<tr><td class='label'>$label</td>";
984 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
988 //------------------------------------------------------------------------------------
990 function tax_groups_list($name, $selected_id=null,
991 $none_option=false, $submit_on_change=false)
993 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
995 return combo_input($name, $selected_id, $sql, 'id', 'name',
998 'spec_option' => $none_option,
999 'spec_id' => ALL_NUMERIC,
1000 'select_submit'=> $submit_on_change,
1005 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1008 echo "<td>$label</td>\n";
1010 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1014 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1016 echo "<tr><td class='label'>$label</td>";
1017 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1021 //------------------------------------------------------------------------------------
1023 function item_tax_types_list($name, $selected_id=null)
1025 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1026 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1029 function item_tax_types_list_cells($label, $name, $selected_id=null)
1032 echo "<td>$label</td>\n";
1034 echo item_tax_types_list($name, $selected_id);
1038 function item_tax_types_list_row($label, $name, $selected_id=null)
1040 echo "<tr><td class='label'>$label</td>";
1041 item_tax_types_list_cells(null, $name, $selected_id);
1045 //------------------------------------------------------------------------------------
1047 function shippers_list($name, $selected_id=null)
1049 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1050 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1051 array('order'=>array('shipper_name')));
1054 function shippers_list_cells($label, $name, $selected_id=null)
1057 echo "<td>$label</td>\n";
1059 echo shippers_list($name, $selected_id);
1063 function shippers_list_row($label, $name, $selected_id=null)
1065 echo "<tr><td class='label'>$label</td>";
1066 shippers_list_cells(null, $name, $selected_id);
1070 //-------------------------------------------------------------------------------------
1072 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1074 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1075 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1076 array('order'=>array('salesman_name'),
1077 'spec_option' => $spec_opt,
1078 'spec_id' => ALL_NUMERIC));
1081 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1084 echo "<td>$label</td>\n";
1086 echo sales_persons_list($name, $selected_id, $spec_opt);
1090 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1092 echo "<tr><td class='label'>$label</td>";
1093 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1097 //------------------------------------------------------------------------------------
1099 function sales_areas_list($name, $selected_id=null)
1101 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1102 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1105 function sales_areas_list_cells($label, $name, $selected_id=null)
1108 echo "<td>$label</td>\n";
1110 echo sales_areas_list($name, $selected_id);
1114 function sales_areas_list_row($label, $name, $selected_id=null)
1116 echo "<tr><td class='label'>$label</td>";
1117 sales_areas_list_cells(null, $name, $selected_id);
1121 //------------------------------------------------------------------------------------
1123 function sales_groups_list($name, $selected_id=null, $special_option=false)
1125 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1126 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1127 'spec_option' => $special_option===true ? ' ' : $special_option,
1128 'order' => 'description', 'spec_id' => 0,
1132 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1135 echo "<td>$label</td>\n";
1137 echo sales_groups_list($name, $selected_id, $special_option);
1141 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1143 echo "<tr><td class='label'>$label</td>";
1144 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1148 //------------------------------------------------------------------------------------
1150 function _format_template_items($row)
1152 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1155 function templates_list($name, $selected_id=null, $special_option=false)
1157 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1158 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1159 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1160 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1161 'format' => '_format_template_items',
1162 'spec_option' => $special_option===true ? ' ' : $special_option,
1163 'order' => 'order_no', 'spec_id' => 0,
1167 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1170 echo "<td>$label</td>\n";
1172 echo templates_list($name, $selected_id, $special_option);
1176 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1178 echo "<tr><td class='label'>$label</td>";
1179 templates_list_cells(null, $name, $selected_id, $special_option);
1183 //------------------------------------------------------------------------------------
1185 function workorders_list($name, $selected_id=null)
1187 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1188 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1191 function workorders_list_cells($label, $name, $selected_id=null)
1194 echo "<td>$label</td>\n";
1196 echo workorders_list($name, $selected_id);
1200 function workorders_list_row($label, $name, $selected_id=null)
1202 echo "<tr><td class='label'>$label</td>";
1203 workorders_list_cells(null, $name, $selected_id);
1207 //------------------------------------------------------------------------------------
1209 function payment_terms_list($name, $selected_id=null)
1211 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1212 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1215 function payment_terms_list_cells($label, $name, $selected_id=null)
1218 echo "<td>$label</td>\n";
1220 echo payment_terms_list($name, $selected_id);
1224 function payment_terms_list_row($label, $name, $selected_id=null)
1226 echo "<tr><td class='label'>$label</td>";
1227 payment_terms_list_cells(null, $name, $selected_id);
1231 //------------------------------------------------------------------------------------
1233 function credit_status_list($name, $selected_id=null)
1235 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1236 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1239 function credit_status_list_cells($label, $name, $selected_id=null)
1242 echo "<td>$label</td>\n";
1244 echo credit_status_list($name, $selected_id);
1248 function credit_status_list_row($label, $name, $selected_id=null)
1250 echo "<tr><td class='label'>$label</td>";
1251 credit_status_list_cells(null, $name, $selected_id);
1255 //-----------------------------------------------------------------------------------------------
1257 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1259 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1261 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1263 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1265 'select_submit'=> $submit_on_change,
1266 // 'async' => false,
1270 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1273 echo "<td>$label</td>\n";
1275 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1279 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1281 echo "<tr><td class='label'>$label</td>";
1282 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1286 //-----------------------------------------------------------------------------------------------
1288 function movement_types_list($name, $selected_id=null)
1290 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1291 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1294 function movement_types_list_cells($label, $name, $selected_id=null)
1297 echo "<td>$label</td>\n";
1299 echo movement_types_list($name, $selected_id);
1303 function movement_types_list_row($label, $name, $selected_id=null)
1305 echo "<tr><td class='label'>$label</td>";
1306 movement_types_list_cells(null, $name, $selected_id);
1310 //-----------------------------------------------------------------------------------------------
1311 function _format_date($row)
1313 return sql2date($row['reconciled']);
1316 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1318 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1319 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1320 GROUP BY reconciled";
1321 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1323 'spec_option' => $special_option,
1324 'format' => '_format_date',
1326 'select_submit'=> $submit_on_change
1330 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1333 echo "<td>$label</td>\n";
1335 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1339 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1342 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1346 //-----------------------------------------------------------------------------------------------
1348 function workcenter_list($name, $selected_id=null, $all_option=false)
1352 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1354 return combo_input($name, $selected_id, $sql, 'id', 'name',
1356 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1357 'spec_id' => $all_items,
1361 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1363 default_focus($name);
1365 echo "<td>$label</td>\n";
1367 echo workcenter_list($name, $selected_id, $all_option);
1371 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1373 echo "<tr><td class='label'>$label</td>";
1374 workcenter_list_cells(null, $name, $selected_id, $all_option);
1378 //-----------------------------------------------------------------------------------------------
1380 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1382 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1383 FROM ".TB_PREF."bank_accounts";
1385 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1387 'format' => '_format_add_curr',
1388 'select_submit'=> $submit_on_change,
1393 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1396 echo "<td>$label</td>\n";
1398 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1402 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1404 echo "<tr><td class='label'>$label</td>";
1405 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1408 //-----------------------------------------------------------------------------------------------
1410 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1412 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1413 FROM ".TB_PREF."bank_accounts
1414 WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
1417 echo "<tr><td class='label'>$label</td>\n";
1419 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1421 'format' => '_format_add_curr',
1422 'select_submit'=> $submit_on_change,
1425 echo "</td></tr>\n";
1427 //-----------------------------------------------------------------------------------------------
1429 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1431 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1433 default_focus($name);
1436 echo "<td class='label'>$label</td>\n";
1439 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1441 'select_submit'=> $submit_on_change,
1443 'spec_option' =>$spec_option,
1445 'order'=> array('pos_name')
1447 echo "</td></tr>\n";
1450 //-----------------------------------------------------------------------------------------------
1451 // Payment type selector for current user.
1453 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true)
1455 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1457 if ($category == PM_CASH) // only cash
1458 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1459 if ($category == PM_CREDIT) // only delayed payments
1460 $sql .= " WHERE days_before_due!=0 OR day_in_following_month!=0";
1462 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1464 'select_submit'=> $submit_on_change,
1470 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true)
1473 echo "<td class='label'>$label</td>\n";
1476 echo sale_payment_list($name, $category, $selected_id, $submit_on_change);
1480 //-----------------------------------------------------------------------------------------------
1482 function class_list($name, $selected_id=null, $submit_on_change=false)
1484 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1486 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1488 'select_submit'=> $submit_on_change,
1494 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1497 echo "<td>$label</td>\n";
1499 echo class_list($name, $selected_id, $submit_on_change);
1503 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1505 echo "<tr><td class='label'>$label</td>";
1506 class_list_cells(null, $name, $selected_id, $submit_on_change);
1510 //-----------------------------------------------------------------------------------------------
1511 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1513 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1514 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1515 array('order'=>'category_id',
1516 'spec_option' => $spec_opt,
1518 'select_submit'=> $submit_on_change,
1523 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1526 echo "<td>$label</td>\n";
1528 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1532 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1534 echo "<tr><td class='label'>$label</td>";
1535 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1539 //-----------------------------------------------------------------------------------------------
1541 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1545 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1547 return combo_input($name, $selected_id, $sql, 'id', 'name',
1549 'format' => '_format_account',
1550 'order' => array('class_id', 'id', 'parent'),
1551 'spec_option' =>$all_option,
1552 'spec_id' => $all_items
1556 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1559 echo "<td>$label</td>\n";
1561 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1565 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1567 echo "<tr><td class='label'>$label</td>";
1568 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1573 //-----------------------------------------------------------------------------------------------
1574 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1575 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1577 if ($skip_bank_accounts)
1578 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1579 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1580 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1581 ."ON chart.account_code=acc.account_code
1582 WHERE acc.account_code IS NULL
1583 AND chart.account_type=type.id";
1585 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1586 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1587 WHERE chart.account_type=type.id";
1589 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1591 'format' => '_format_account',
1592 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1595 'order' => array('type.class_id','type.id','account_code'),
1596 'search_box' => $cells,
1597 'search_submit' => false,
1601 'select_submit'=> $submit_on_change,
1604 'show_inactive' => $all
1609 function _format_account($row)
1611 return $row[0] . " " . $row[1];
1614 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1615 $skip_bank_accounts=false, $cells=false, $all_option=false,
1616 $submit_on_change=false, $all=false)
1619 echo "<td>$label</td>\n";
1621 echo gl_all_accounts_list($name, $selected_id,
1622 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1626 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1627 $skip_bank_accounts=false, $cells=false, $all_option=false)
1629 echo "<tr><td class='label'>$label</td>";
1630 gl_all_accounts_list_cells(null, $name, $selected_id,
1631 $skip_bank_accounts, $cells, $all_option);
1635 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1638 $items['0'] = strlen($name_no) ? $name_no : _("No");
1639 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1641 return array_selector($name, $selected_id, $items,
1643 'select_submit'=> $submit_on_change,
1644 'async' => false ) ); // FIX?
1647 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1650 echo "<td>$label</td>\n";
1652 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1656 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1658 echo "<tr><td class='label'>$label</td>";
1659 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1663 //------------------------------------------------------------------------------------------------
1665 function languages_list($name, $selected_id=null, $all_option=false)
1667 global $installed_languages;
1671 $items[''] = $all_option;
1672 foreach ($installed_languages as $lang)
1673 $items[$lang['code']] = $lang['name'];
1674 return array_selector($name, $selected_id, $items);
1677 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1680 echo "<td>$label</td>\n";
1682 echo languages_list($name, $selected_id, $all_option);
1686 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1688 echo "<tr><td class='label'>$label</td>";
1689 languages_list_cells(null, $name, $selected_id, $all_option);
1693 //------------------------------------------------------------------------------------------------
1695 function bank_account_types_list($name, $selected_id=null)
1697 global $bank_account_types;
1699 return array_selector($name, $selected_id, $bank_account_types);
1702 function bank_account_types_list_cells($label, $name, $selected_id=null)
1705 echo "<td>$label</td>\n";
1707 echo bank_account_types_list($name, $selected_id);
1711 function bank_account_types_list_row($label, $name, $selected_id=null)
1713 echo "<tr><td class='label'>$label</td>";
1714 bank_account_types_list_cells(null, $name, $selected_id);
1718 //------------------------------------------------------------------------------------------------
1719 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1721 global $payment_person_types;
1724 foreach ($payment_person_types as $key=>$type)
1726 if ($key != PT_WORKORDER)
1727 $items[$key] = $type;
1729 return array_selector($name, $selected_id, $items,
1730 array( 'select_submit'=> $submit_on_change ) );
1733 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1736 echo "<td>$label</td>\n";
1738 echo payment_person_types_list($name, $selected_id, $related);
1742 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1744 echo "<tr><td class='label'>$label</td>";
1745 payment_person_types_list_cells(null, $name, $selected_id, $related);
1749 //------------------------------------------------------------------------------------------------
1751 function wo_types_list($name, $selected_id=null)
1753 global $wo_types_array;
1755 return array_selector($name, $selected_id, $wo_types_array,
1756 array( 'select_submit'=> true, 'async' => true ) );
1759 function wo_types_list_row($label, $name, $selected_id=null)
1761 echo "<tr><td class='label'>$label</td><td>\n";
1762 echo wo_types_list($name, $selected_id);
1763 echo "</td></tr>\n";
1766 //------------------------------------------------------------------------------------------------
1768 function dateformats_list_row($label, $name, $value=null)
1770 global $dateformats;
1772 echo "<tr><td class='label'>$label</td>\n<td>";
1773 echo array_selector( $name, $value, $dateformats );
1774 echo "</td></tr>\n";
1777 function dateseps_list_row($label, $name, $value=null)
1781 echo "<tr><td class='label'>$label</td>\n<td>";
1782 echo array_selector( $name, $value, $dateseps );
1783 echo "</td></tr>\n";
1786 function thoseps_list_row($label, $name, $value=null)
1790 echo "<tr><td class='label'>$label</td>\n<td>";
1791 echo array_selector( $name, $value, $thoseps );
1792 echo "</td></tr>\n";
1795 function decseps_list_row($label, $name, $value=null)
1799 echo "<tr><td class='label'>$label</td>\n<td>";
1800 echo array_selector( $name, $value, $decseps );
1801 echo "</td></tr>\n";
1804 function themes_list_row($label, $name, $value=null)
1806 global $path_to_root;
1808 $path = $path_to_root.'/themes/';
1810 $themedir = opendir($path);
1811 while(false !== ($fname = readdir($themedir)))
1813 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1815 $themes[$fname] = $fname;
1820 echo "<tr><td class='label'>$label</td>\n<td>";
1821 echo array_selector( $name, $value, $themes );
1822 echo "</td></tr>\n";
1825 function pagesizes_list_row($label, $name, $value=null)
1830 foreach ($pagesizes as $pz)
1833 echo "<tr><td class='label'>$label</td>\n<td>";
1834 echo array_selector( $name, $value, $items );
1835 echo "</td></tr>\n";
1838 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1840 global $systypes_array;
1842 // emove non-voidable transactions if needed
1843 $systypes = array_diff_key($systypes_array, array_flip($exclude));
1844 return array_selector($name, $value, $systypes,
1846 'spec_option'=> $spec_opt,
1847 'spec_id' => ALL_NUMERIC,
1848 'select_submit'=> $submit_on_change,
1854 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1857 echo "<td>$label</td>\n";
1859 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
1863 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1865 echo "<tr><td class='label'>$label</td>";
1866 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
1870 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1872 global $systypes_array;
1875 echo "<td>$label</td>\n";
1878 $items = $systypes_array;
1880 // exclude quotes, orders and dimensions
1881 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1882 ST_SALESQUOTE) as $excl)
1883 unset($items[$excl]);
1885 echo array_selector($name, $value, $items,
1887 'spec_option'=> _("All"),
1889 'select_submit'=> $submit_on_change,
1896 function cust_allocations_list_cells($label, $name, $selected=null)
1904 $all_items=>_("All Types"),
1905 '1'=> _("Sales Invoices"),
1906 '2'=> _("Overdue Invoices"),
1907 '3' => _("Payments"),
1908 '4' => _("Credit Notes"),
1909 '5' => _("Delivery Notes")
1911 echo array_selector($name, $selected, $allocs);
1915 function supp_allocations_list_cell($name, $selected=null)
1921 $all_items=>_("All Types"),
1922 '1'=> _("Invoices"),
1923 '2'=> _("Overdue Invoices"),
1924 '3' => _("Payments"),
1925 '4' => _("Credit Notes"),
1926 '5' => _("Overdue Credit Notes")
1928 echo array_selector($name, $selected, $allocs);
1932 function supp_transactions_list_cell($name, $selected=null)
1938 $all_items=>_("All Types"),
1940 '1'=> _("Invoices"),
1941 '2'=> _("Overdue Invoices"),
1942 '3' => _("Payments"),
1943 '4' => _("Credit Notes"),
1944 '5' => _("Overdue Credit Notes")
1947 echo array_selector($name, $selected, $allocs);
1951 function policy_list_cells($label, $name, $selected=null)
1956 echo array_selector($name, $selected,
1957 array( '' => _("Automatically put balance on back order"),
1958 'CAN' => _("Cancel any quantites not delivered")) );
1962 function policy_list_row($label, $name, $selected=null)
1964 echo "<tr><td class='label'>$label</td>";
1965 policy_list_cells(null, $name, $selected);
1969 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1974 echo array_selector($name, $selected,
1975 array( 'Return' => _("Items Returned to Inventory Location"),
1976 'WriteOff' => _("Items Written Off")),
1977 array( 'select_submit'=> $submit_on_change ) );
1981 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1983 echo "<tr><td class='label'>$label</td>";
1984 credit_type_list_cells(null, $name, $selected, $submit_on_change);
1988 function number_list($name, $selected, $from, $to, $no_option=false)
1991 for ($i = $from; $i <= $to; $i++)
1994 return array_selector($name, $selected, $items,
1995 array( 'spec_option' => $no_option,
1996 'spec_id' => ALL_NUMERIC) );
1999 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2004 echo number_list($name, $selected, $from, $to, $no_option);
2008 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2010 echo "<tr><td class='label'>$label</td>";
2011 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2015 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2016 $submit_on_change=true)
2018 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2019 ." GROUP BY profile";
2020 $result = db_query($sql, 'cannot get all profile names');
2021 $profiles = array();
2022 while($myrow=db_fetch($result)) {
2023 $profiles[$myrow['profile']] = $myrow['profile'];
2028 echo "<td class='label'>$label</td>\n";
2031 echo array_selector($name, $selected_id, $profiles,
2032 array( 'select_submit'=> $submit_on_change,
2033 'spec_option'=>$spec_opt,
2037 echo "</td></tr>\n";
2040 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2042 static $printers; // query only once for page display
2045 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2046 $result = db_query($sql, 'cannot get all printers');
2047 $printers = array();
2048 while($myrow=db_fetch($result)) {
2049 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2052 return array_selector($name, $selected_id, $printers,
2053 array( 'select_submit'=> $submit_on_change,
2054 'spec_option'=>$spec_opt,
2059 //------------------------------------------------------------------------------------------------
2061 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2064 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2066 $sql .= " WHERE type=$type";
2068 return combo_input($name, $selected_id, $sql, 'id', 'description',
2071 'order' => 'description',
2072 'select_submit'=> $submit_on_change,
2078 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2081 echo "<td>$label</td>\n";
2083 echo 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)
2089 echo "<tr><td class='label'>$label</td>";
2090 quick_entries_list_cells(null, $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 class='label'>$label</td><td>";
2100 echo 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 class='label'>$label</td><td>";
2112 echo 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'));
2123 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2125 global $class_types;
2127 echo "<tr><td class='label'>$label</td><td>";
2128 echo array_selector($name, $selected_id, $class_types,
2130 'select_submit'=> $submit_on_change
2132 echo "</td></tr>\n";
2135 //------------------------------------------------------------------------------------------------
2137 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2138 $show_inactive = false)
2142 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2144 return combo_input($name, $selected_id, $sql, 'id', 'description',
2146 'spec_option'=>$new_item ? _("New role") : false,
2148 'select_submit'=> $submit_on_change,
2149 'show_inactive' => $show_inactive
2153 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2154 $show_inactive = false)
2157 echo "<td>$label</td>\n";
2159 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2163 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2164 $show_inactive = false)
2166 echo "<tr><td class='label'>$label</td>";
2167 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2171 function tab_list_row($label, $name, $selected_id=null, $all = false)
2173 global $installed_extensions;
2176 foreach ($_SESSION['App']->applications as $app) {
2177 $tabs[$app->id] = access_string($app->name, true);
2179 if ($all) { // add also not active ext. modules
2180 foreach ($installed_extensions as $ext) {
2181 if ($ext['type'] == 'module' && !$ext['active'])
2182 $tabs[$ext['tab']] = access_string($ext['title'], true);
2186 echo "<td class='label'>$label</td><td>\n";
2187 echo array_selector($name, $selected_id, $tabs);
2188 echo "</td></tr>\n";
2191 //-----------------------------------------------------------------------------------------------
2193 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2196 global $path_to_root;
2197 include_once($path_to_root . "/admin/db/tags_db.inc");
2198 $results = get_tags($type, $all);
2200 while ($tag = db_fetch($results))
2201 $tags[$tag['id']] = $tag['name'];
2203 if (!isset($tags)) {
2204 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2207 return array_selector($name, null, $tags,
2210 'height' => $height,
2211 'spec_option'=> $spec_opt,
2216 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2219 echo "<td>$label</td>\n";
2221 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2226 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2228 echo "<tr><td class='label'>$label</td>";
2229 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2233 //---------------------------------------------------------------------------------------------
2234 // List of sets of active extensions
2236 function extset_list($name, $value=null, $submit_on_change=false)
2238 global $db_connections;
2241 foreach ($db_connections as $comp)
2242 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2243 return array_selector( $name, $value, $items,
2245 'spec_option'=> _("Available and/or installed"),
2247 'select_submit'=> $submit_on_change,
2252 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2255 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2260 if (@$filter['class']) {
2261 $where[] = 'type='.db_escape($filter['class']);
2264 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2265 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2266 if (@$filter['multi']) { // contact category selector for person
2270 return combo_input($name, $selected_id, $sql, 'id', 'name',
2273 'height' => $multi ? 5:1,
2274 'category' => $groups,
2275 'select_submit'=> $submit_on_change,
2281 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2283 echo "<tr><td class='label'>$label</td><td>";
2284 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2285 echo "</td></tr>\n";
2288 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2290 global $pterm_types;
2292 echo "<tr><td class='label'>$label</td><td>";
2293 echo array_selector($name, $selected_id, $pterm_types,
2295 'select_submit'=> $submit_on_change
2297 echo "</td></tr>\n";
2300 function coa_list_row($label, $name, $value=null)
2302 global $path_to_root, $installed_extensions;
2304 $path = $path_to_root.'/sql/';
2306 $sqldir = opendir($path);
2307 while (false !== ($fname = readdir($sqldir)))
2309 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2311 $ext = array_search_value($fname, $installed_extensions, 'sql');
2313 $descr = $ext['name'];
2314 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2315 $descr = _("Standard new company American COA (4 digit)");
2316 } elseif ($fname == 'en_US-demo.sql') {
2317 $descr = _("Standard American COA (4 digit) with demo data");
2321 $coas[$fname] = $descr;
2326 echo "<tr><td class='label'>$label</td>\n<td>";
2327 echo array_selector( $name, $value, $coas );
2328 echo "</td></tr>\n";