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){
218 $selector .= "</optgroup>";
219 $selector .= "<optgroup label='".$cat."'>\n";
222 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
225 $selector .= "</optgroup>";
226 db_free_result($result);
229 // Prepend special option.
230 if ($spec_option !== false) { // if special option used - add it
231 $first_id = $spec_id;
232 $first_opt = $spec_option;
234 // if($first_id !== false) {
235 $sel = $found===false ? 'selected' : '';
236 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
237 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
241 if ($found===false) {
242 $selected_id = array($first_id);
245 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
247 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
248 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
249 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
250 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
252 if ($by_id && ($search_box != false || $opts['editable']) ) {
253 // on first display show selector list
254 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
255 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
256 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
257 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
258 set_focus($name.'_text'); // prevent lost focus
259 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
260 set_focus($name); // prevent lost focus
261 if (!$opts['editable'])
263 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
266 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
268 // span for select list/input field update
269 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
271 // if selectable or editable list is used - add select button
272 if ($select_submit != false || $search_button) {
273 global $_select_button;
274 // button class selects form reload/ajax selector update
275 $selector .= sprintf($_select_button, $disabled, user_theme(),
276 (fallback_mode() ? '' : 'display:none;'),
277 '_'.$name.'_update')."\n";
279 // ------ make combo ----------
281 if ($search_box != false) {
282 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
283 $opts['size']."' maxlength='".$opts['max'].
284 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
285 .$opts['box_hint']."'"
286 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
288 if ($search_submit != false || $opts['editable']) {
289 global $_search_button;
290 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
291 (fallback_mode() ? '' : 'display:none;'),
292 $search_submit ? $search_submit : "_{$name}_button")."\n";
295 default_focus(($search_box && $by_id) ? $search_box : $name);
297 if ($search_box && $opts['cells'])
298 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
300 $str = $edit_entry.$selector;
306 Returns true if selector $name is subject to update.
308 function list_updated($name)
310 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
312 //----------------------------------------------------------------------------------------------
313 // Universal array combo generator
314 // $items is array of options 'value' => 'description'
315 // Options is reduced set of combo_selector options and is merged with defaults.
317 function array_selector($name, $selected_id, $items, $options=null)
321 $opts = array( // default options
322 'spec_option'=>false, // option text or false
323 'spec_id' => 0, // option id
324 'select_submit' => false, //submit on select: true/false
325 'async' => true, // select update via ajax (true) vs _page_body reload
326 'default' => '', // default value when $_POST is not set
327 'multi'=>false, // multiple select
328 // search box parameters
329 'height' => false, // number of lines in select box
333 // ------ merge options with defaults ----------
335 $opts = array_merge($opts, $options);
336 $select_submit = $opts['select_submit'];
337 $spec_id = $opts['spec_id'];
338 $spec_option = $opts['spec_option'];
339 $disabled = $opts['disabled'] ? "disabled" : '';
340 $multi = $opts['multi'];
342 if ($selected_id == null) {
343 $selected_id = get_post($name, $opts['default']);
345 if(!is_array($selected_id))
346 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
348 if (isset($_POST[ '_'.$name.'_update'])) {
350 $Ajax->activate('_page_body');
352 $Ajax->activate($name);
355 // ------ make selector ----------
356 $selector = $first_opt = '';
359 //if($name=='SelectStockFromList') display_error($sql);
360 foreach($items as $value=>$descr) {
362 if (in_array((string)$value, $selected_id, true)) {
366 if ($first_id === false) {
370 $selector .= "<option $sel value='$value'>$descr</option>\n";
373 if ($first_id!==false) {
374 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
376 // Prepend special option.
377 if ($spec_option !== false) { // if special option used - add it
378 $first_id = $spec_id;
379 $first_opt = $spec_option;
380 $sel = $found===false ? 'selected' : '';
381 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
385 if ($found===false) {
386 $selected_id = array($first_id);
388 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
390 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
391 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
392 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
393 . $opts['sel_hint']."'>".$selector."</select>\n";
395 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
397 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
399 if ($select_submit != false) { // if submit on change is used - add select button
400 global $_select_button;
401 $selector .= sprintf($_select_button, $disabled, user_theme(),
402 (fallback_mode() ? '' : 'display:none;'),
403 '_'.$name.'_update')."\n";
405 default_focus($name);
409 //----------------------------------------------------------------------------------------------
411 function _format_add_curr($row)
413 static $company_currency;
415 if ($company_currency == null)
417 $company_currency = get_company_currency();
419 return $row[1] . ($row[2] == $company_currency ?
420 '' : (" - " . $row[2]));
423 function add_edit_combo($type)
425 global $path_to_root, $popup_editors, $use_icon_for_editkey;
427 if (!isset($use_icon_for_editkey) || $use_icon_for_editkey==0)
430 $theme_path = $path_to_root . '/themes/' . user_theme();
432 $key = $popup_editors[$type][1];
433 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
434 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
435 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
438 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
439 $all=false, $editkey = false)
443 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
445 $mode = get_company_pref('no_supplier_list');
448 set_editor('supplier', $name, $editkey);
450 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
452 'format' => '_format_add_curr',
453 'order' => array('supp_ref'),
454 'search_box' => $mode!=0,
456 'search' => array("supp_ref","supp_name","gst_no"),
457 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
458 'spec_id' => $all_items,
459 'select_submit'=> $submit_on_change,
461 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
462 _('Select supplier'),
463 'show_inactive'=>$all
466 $ret .= add_edit_combo('supplier');
470 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
471 $submit_on_change=false, $all=false, $editkey = false)
474 echo "<td>$label</td><td>\n";
475 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
480 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
481 $submit_on_change=false, $all=false, $editkey = false)
483 echo "<tr><td class='label'>$label</td><td>";
484 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
488 //----------------------------------------------------------------------------------------------
490 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
491 $show_inactive=false, $editkey = false)
495 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
497 $mode = get_company_pref('no_customer_list');
500 set_editor('customer', $name, $editkey);
502 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
504 'format' => '_format_add_curr',
505 'order' => array('debtor_ref'),
506 'search_box' => $mode!=0,
509 'search' => array("debtor_ref","name","tax_id"),
510 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
511 'spec_id' => $all_items,
512 'select_submit'=> $submit_on_change,
514 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
515 _('Select customer'),
516 'show_inactive' => $show_inactive
519 $ret .= add_edit_combo('customer');
523 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
524 $submit_on_change=false, $show_inactive=false, $editkey = false)
527 echo "<td>$label</td>\n";
529 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
530 $show_inactive, $editkey);
534 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
535 $submit_on_change=false, $show_inactive=false, $editkey = false)
537 global $path_to_root;
539 echo "<tr><td class='label'>$label</td><td nowrap>";
540 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
541 $show_inactive, $editkey);
542 echo "</td>\n</tr>\n";
545 //------------------------------------------------------------------------------------------------
547 function customer_branches_list($customer_id, $name, $selected_id=null,
548 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
552 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
553 WHERE debtor_no=" . db_escape($customer_id)." ";
556 set_editor('branch', $name, $editkey);
558 $where = $enabled ? array("disable_trans = 0") : array();
559 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
562 'order' => array('branch_ref'),
563 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
564 'spec_id' => $all_items,
565 'select_submit'=> $submit_on_change,
566 'sel_hint' => _('Select customer branch')
570 $ret .= add_edit_combo('branch');
574 //------------------------------------------------------------------------------------------------
576 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
577 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
580 echo "<td>$label</td>\n";
582 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
583 $submit_on_change, $editkey);
587 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
588 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
590 echo "<tr><td class='label'>$label</td>";
591 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
592 $all_option, $enabled, $submit_on_change, $editkey);
596 //------------------------------------------------------------------------------------------------
598 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
602 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
604 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
606 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
607 'spec_id' => $all_items,
608 'select_submit'=> $submit_on_change
612 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
615 echo "<td>$label</td>\n";
617 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
621 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
623 echo "<tr><td class='label'>$label</td>";
624 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
628 //-----------------------------------------------------------------------------------------------
630 function currencies_list($name, $selected_id=null, $submit_on_change=false)
632 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
634 // default to the company currency
635 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
637 'select_submit'=> $submit_on_change,
638 'default' => get_company_currency(),
643 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
646 echo "<td>$label</td>\n";
648 echo currencies_list($name, $selected_id, $submit_on_change);
652 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
654 echo "<tr><td class='label'>$label</td>";
655 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
659 //---------------------------------------------------------------------------------------------------
661 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
664 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
666 // default to the company current fiscal year
668 return combo_input($name, $selected_id, $sql, 'id', '',
671 'default' => get_company_pref('f_year'),
672 'format' => '_format_fiscalyears',
673 'select_submit'=> $submit_on_change,
678 function _format_fiscalyears($row)
680 return sql2date($row[1]) . " - " . sql2date($row[2])
681 . " " . ($row[3] ? _('Closed') : _('Active'));
684 function fiscalyears_list_cells($label, $name, $selected_id=null)
687 echo "<td>$label</td>\n";
689 echo fiscalyears_list($name, $selected_id);
693 function fiscalyears_list_row($label, $name, $selected_id=null)
695 echo "<tr><td class='label'>$label</td>";
696 fiscalyears_list_cells(null, $name, $selected_id);
699 //------------------------------------------------------------------------------------
701 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
702 $submit_on_change=false, $showclosed=false, $showtype=1)
704 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
707 'order' => 'reference',
708 'spec_option'=>$no_option ? $showname : false,
710 'select_submit'=> $submit_on_change,
715 $options['where'][] = "closed=0";
717 $options['where'][] = "type_=".db_escape($showtype);
719 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
722 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
723 $showclosed=false, $showtype=0, $submit_on_change=false)
726 echo "<td>$label</td>\n";
728 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
732 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
733 $showclosed=false, $showtype=0, $submit_on_change=false)
735 echo "<tr><td class='label'>$label</td>";
736 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
737 $showclosed, $showtype, $submit_on_change);
741 //---------------------------------------------------------------------------------------------------
743 function stock_items_list($name, $selected_id=null, $all_option=false,
744 $submit_on_change=false, $opts=array(), $editkey = false)
748 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
749 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
752 set_editor('item', $name, $editkey);
754 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
757 'format' => '_format_stock_items',
758 'spec_option' => $all_option===true ? _("All Items") : $all_option,
759 'spec_id' => $all_items,
760 'search_box' => true,
761 'search' => array("stock_id", "c.description","s.description"),
762 'search_submit' => get_company_pref('no_item_list')!=0,
764 'select_submit'=> $submit_on_change,
766 'order' => array('c.description','stock_id')
769 $ret .= add_edit_combo('item');
774 function _format_stock_items($row)
776 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
779 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
780 $submit_on_change=false, $all=false, $editkey = false)
783 echo "<td>$label</td>\n";
784 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
785 array('cells'=>true, 'show_inactive'=>$all), $editkey);
788 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
791 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
795 //---------------------------------------------------------------------------------------------------
797 // Select item via foreign code.
799 function sales_items_list($name, $selected_id=null, $all_option=false,
800 $submit_on_change=false, $type='', $opts=array())
804 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
805 i.inactive, if(count(*)>1, '0', s.editable) as editable
807 ".TB_PREF."stock_master s,
808 ".TB_PREF."item_codes i
810 ".TB_PREF."stock_category c
811 ON i.category_id=c.category_id
812 WHERE i.stock_id=s.stock_id";
815 if ($type == 'local') { // exclude foreign codes
816 $sql .= " AND !i.is_foreign";
817 } elseif ($type == 'kits') { // sales kits
818 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
820 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
821 $sql .= " GROUP BY i.item_code";
823 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
826 'format' => '_format_stock_items',
827 'spec_option' => $all_option===true ? _("All Items") : $all_option,
828 'spec_id' => $all_items,
829 'search_box' => true,
830 'search' => array("i.item_code", "c.description", "i.description"),
831 'search_submit' => get_company_pref('no_item_list')!=0,
833 'select_submit'=> $submit_on_change,
835 'order' => array('c.description','i.item_code'),
841 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
844 set_editor('item', $name, $editkey);
847 echo "<td>$label</td>\n";
848 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
849 '', array('cells'=>true));
852 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
854 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
855 'kits', array('cells'=>false, 'editable' => false));
858 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
862 echo "<td class='label'>$label</td>\n";
864 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
865 'local', array('cells'=>false, 'editable' => false));
868 //------------------------------------------------------------------------------------
870 function stock_manufactured_items_list($name, $selected_id=null,
871 $all_option=false, $submit_on_change=false)
873 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
874 array('where'=>array("mb_flag= 'M'")));
877 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
878 $all_option=false, $submit_on_change=false)
881 echo "<td>$label</td>\n";
883 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
887 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
888 $all_option=false, $submit_on_change=false)
890 echo "<tr><td class='label'>$label</td>";
891 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
894 //------------------------------------------------------------------------------------
896 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
897 $all_option=false, $submit_on_change=false, $editkey = false)
899 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
900 array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
903 function stock_component_items_list_cells($label, $name, $parent_stock_id,
904 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
907 echo "<td>$label</td>\n";
908 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
909 array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
912 //------------------------------------------------------------------------------------
914 function stock_costable_items_list($name, $selected_id=null,
915 $all_option=false, $submit_on_change=false)
917 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
918 array('where'=>array("mb_flag!='D'")));
921 function stock_costable_items_list_cells($label, $name, $selected_id=null,
922 $all_option=false, $submit_on_change=false)
925 echo "<td>$label</td>\n";
926 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
927 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
930 //------------------------------------------------------------------------------------
931 function stock_purchasable_items_list($name, $selected_id=null,
932 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
934 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
935 array('where'=>array("mb_flag!= 'M'"),
936 'show_inactive'=>$all), $editkey);
939 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
941 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
942 $all_option=false, $submit_on_change=false, $editkey=false)
945 echo "<td>$label</td>\n";
946 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
947 array('where'=>array("mb_flag!= 'M'"),
949 'cells'=>true), $editkey);
952 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
953 $all_option=false, $submit_on_change=false, $editkey=false)
955 echo "<tr><td class='label'>$label</td>";
956 stock_purchasable_items_list_cells(null, $name, $selected_id=null,
957 $all_option, $submit_on_change, $editkey);
961 //------------------------------------------------------------------------------------
963 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
969 echo "<td class='label'>$label</td>\n";
972 echo array_selector($name, $selected_id, $stock_types,
974 'select_submit'=> true,
975 'disabled' => !$enabled) );
979 function stock_units_list_row($label, $name, $value=null, $enabled=true)
981 $result = get_all_item_units();
984 echo "<td class='label'>$label</td>\n";
987 while($unit = db_fetch($result))
988 $units[$unit['abbr']] = $unit['name'];
990 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
995 //------------------------------------------------------------------------------------
997 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
999 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
1001 return combo_input($name, $selected_id, $sql, 'id', 'name',
1003 'spec_option' => $none_option,
1004 'spec_id' => ALL_NUMERIC,
1005 'select_submit'=> $submit_on_change,
1010 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1011 $submit_on_change=false)
1014 echo "<td>$label</td>\n";
1016 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1020 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1021 $submit_on_change=false)
1023 echo "<tr><td class='label'>$label</td>";
1024 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1028 //------------------------------------------------------------------------------------
1030 function tax_groups_list($name, $selected_id=null,
1031 $none_option=false, $submit_on_change=false)
1033 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1035 return combo_input($name, $selected_id, $sql, 'id', 'name',
1038 'spec_option' => $none_option,
1039 'spec_id' => ALL_NUMERIC,
1040 'select_submit'=> $submit_on_change,
1045 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1048 echo "<td>$label</td>\n";
1050 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1054 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1056 echo "<tr><td class='label'>$label</td>";
1057 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1061 //------------------------------------------------------------------------------------
1063 function item_tax_types_list($name, $selected_id=null)
1065 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1066 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1069 function item_tax_types_list_cells($label, $name, $selected_id=null)
1072 echo "<td>$label</td>\n";
1074 echo item_tax_types_list($name, $selected_id);
1078 function item_tax_types_list_row($label, $name, $selected_id=null)
1080 echo "<tr><td class='label'>$label</td>";
1081 item_tax_types_list_cells(null, $name, $selected_id);
1085 //------------------------------------------------------------------------------------
1087 function shippers_list($name, $selected_id=null)
1089 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1090 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1091 array('order'=>array('shipper_name')));
1094 function shippers_list_cells($label, $name, $selected_id=null)
1097 echo "<td>$label</td>\n";
1099 echo shippers_list($name, $selected_id);
1103 function shippers_list_row($label, $name, $selected_id=null)
1105 echo "<tr><td class='label'>$label</td>";
1106 shippers_list_cells(null, $name, $selected_id);
1110 //-------------------------------------------------------------------------------------
1112 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1114 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1115 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1116 array('order'=>array('salesman_name'),
1117 'spec_option' => $spec_opt,
1118 'spec_id' => ALL_NUMERIC));
1121 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1124 echo "<td>$label</td>\n";
1126 echo sales_persons_list($name, $selected_id, $spec_opt);
1130 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1132 echo "<tr><td class='label'>$label</td>";
1133 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1137 //------------------------------------------------------------------------------------
1139 function sales_areas_list($name, $selected_id=null)
1141 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1142 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1145 function sales_areas_list_cells($label, $name, $selected_id=null)
1148 echo "<td>$label</td>\n";
1150 echo sales_areas_list($name, $selected_id);
1154 function sales_areas_list_row($label, $name, $selected_id=null)
1156 echo "<tr><td class='label'>$label</td>";
1157 sales_areas_list_cells(null, $name, $selected_id);
1161 //------------------------------------------------------------------------------------
1163 function sales_groups_list($name, $selected_id=null, $special_option=false)
1165 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1166 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1167 'spec_option' => $special_option===true ? ' ' : $special_option,
1168 'order' => 'description', 'spec_id' => 0,
1172 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1175 echo "<td>$label</td>\n";
1177 echo sales_groups_list($name, $selected_id, $special_option);
1181 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1183 echo "<tr><td class='label'>$label</td>";
1184 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1188 //------------------------------------------------------------------------------------
1190 function _format_template_items($row)
1192 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1195 function templates_list($name, $selected_id=null, $special_option=false)
1197 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1198 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1199 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1200 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1201 'format' => '_format_template_items',
1202 'spec_option' => $special_option===true ? ' ' : $special_option,
1203 'order' => 'order_no', 'spec_id' => 0,
1207 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1210 echo "<td>$label</td>\n";
1212 echo templates_list($name, $selected_id, $special_option);
1216 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1218 echo "<tr><td class='label'>$label</td>";
1219 templates_list_cells(null, $name, $selected_id, $special_option);
1223 //------------------------------------------------------------------------------------
1225 function workorders_list($name, $selected_id=null)
1227 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1228 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1231 function workorders_list_cells($label, $name, $selected_id=null)
1234 echo "<td>$label</td>\n";
1236 echo workorders_list($name, $selected_id);
1240 function workorders_list_row($label, $name, $selected_id=null)
1242 echo "<tr><td class='label'>$label</td>";
1243 workorders_list_cells(null, $name, $selected_id);
1247 //------------------------------------------------------------------------------------
1249 function payment_terms_list($name, $selected_id=null)
1251 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1252 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1255 function payment_terms_list_cells($label, $name, $selected_id=null)
1258 echo "<td>$label</td>\n";
1260 echo payment_terms_list($name, $selected_id);
1264 function payment_terms_list_row($label, $name, $selected_id=null)
1266 echo "<tr><td class='label'>$label</td>";
1267 payment_terms_list_cells(null, $name, $selected_id);
1271 //------------------------------------------------------------------------------------
1273 function credit_status_list($name, $selected_id=null)
1275 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1276 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1279 function credit_status_list_cells($label, $name, $selected_id=null)
1282 echo "<td>$label</td>\n";
1284 echo credit_status_list($name, $selected_id);
1288 function credit_status_list_row($label, $name, $selected_id=null)
1290 echo "<tr><td class='label'>$label</td>";
1291 credit_status_list_cells(null, $name, $selected_id);
1295 //-----------------------------------------------------------------------------------------------
1297 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1299 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1301 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1303 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1305 'select_submit'=> $submit_on_change,
1306 // 'async' => false,
1310 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1313 echo "<td>$label</td>\n";
1315 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1319 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1321 echo "<tr><td class='label'>$label</td>";
1322 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1326 //-----------------------------------------------------------------------------------------------
1328 function movement_types_list($name, $selected_id=null)
1330 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1331 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1334 function movement_types_list_cells($label, $name, $selected_id=null)
1337 echo "<td>$label</td>\n";
1339 echo movement_types_list($name, $selected_id);
1343 function movement_types_list_row($label, $name, $selected_id=null)
1345 echo "<tr><td class='label'>$label</td>";
1346 movement_types_list_cells(null, $name, $selected_id);
1350 //-----------------------------------------------------------------------------------------------
1351 function _format_date($row)
1353 return sql2date($row['reconciled']);
1356 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1358 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1359 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1360 GROUP BY reconciled";
1361 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1363 'spec_option' => $special_option,
1364 'format' => '_format_date',
1366 'select_submit'=> $submit_on_change
1370 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1373 echo "<td>$label</td>\n";
1375 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1379 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1382 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1386 //-----------------------------------------------------------------------------------------------
1388 function workcenter_list($name, $selected_id=null, $all_option=false)
1392 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1394 return combo_input($name, $selected_id, $sql, 'id', 'name',
1396 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1397 'spec_id' => $all_items,
1401 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1403 default_focus($name);
1405 echo "<td>$label</td>\n";
1407 echo workcenter_list($name, $selected_id, $all_option);
1411 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1413 echo "<tr><td class='label'>$label</td>";
1414 workcenter_list_cells(null, $name, $selected_id, $all_option);
1418 //-----------------------------------------------------------------------------------------------
1420 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1422 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1423 FROM ".TB_PREF."bank_accounts";
1425 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1427 'format' => '_format_add_curr',
1428 'select_submit'=> $submit_on_change,
1429 'spec_option' => $spec_option,
1435 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1438 echo "<td>$label</td>\n";
1440 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1444 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1446 echo "<tr><td class='label'>$label</td>";
1447 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1450 //-----------------------------------------------------------------------------------------------
1452 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1454 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1455 FROM ".TB_PREF."bank_accounts
1456 WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
1459 echo "<tr><td class='label'>$label</td>\n";
1461 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1463 'format' => '_format_add_curr',
1464 'select_submit'=> $submit_on_change,
1467 echo "</td></tr>\n";
1469 //-----------------------------------------------------------------------------------------------
1471 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1473 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1475 default_focus($name);
1478 echo "<td class='label'>$label</td>\n";
1481 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1483 'select_submit'=> $submit_on_change,
1485 'spec_option' =>$spec_option,
1487 'order'=> array('pos_name')
1489 echo "</td></tr>\n";
1492 //-----------------------------------------------------------------------------------------------
1493 // Payment type selector for current user.
1495 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true)
1497 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1499 if ($category == PM_CASH) // only cash
1500 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1501 if ($category == PM_CREDIT) // only delayed payments
1502 $sql .= " WHERE days_before_due!=0 OR day_in_following_month!=0";
1504 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1506 'select_submit'=> $submit_on_change,
1512 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true)
1515 echo "<td class='label'>$label</td>\n";
1518 echo sale_payment_list($name, $category, $selected_id, $submit_on_change);
1522 //-----------------------------------------------------------------------------------------------
1524 function class_list($name, $selected_id=null, $submit_on_change=false)
1526 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1528 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1530 'select_submit'=> $submit_on_change,
1536 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1539 echo "<td>$label</td>\n";
1541 echo class_list($name, $selected_id, $submit_on_change);
1545 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1547 echo "<tr><td class='label'>$label</td>";
1548 class_list_cells(null, $name, $selected_id, $submit_on_change);
1552 //-----------------------------------------------------------------------------------------------
1553 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1555 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1556 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1557 array('order'=>'category_id',
1558 'spec_option' => $spec_opt,
1560 'select_submit'=> $submit_on_change,
1565 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1568 echo "<td>$label</td>\n";
1570 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1574 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1576 echo "<tr><td class='label'>$label</td>";
1577 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1581 //-----------------------------------------------------------------------------------------------
1583 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1587 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1589 return combo_input($name, $selected_id, $sql, 'id', 'name',
1591 'format' => '_format_account',
1592 'order' => array('class_id', 'id', 'parent'),
1593 'spec_option' =>$all_option,
1594 'spec_id' => $all_items
1598 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1601 echo "<td>$label</td>\n";
1603 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1607 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1609 echo "<tr><td class='label'>$label</td>";
1610 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1615 //-----------------------------------------------------------------------------------------------
1616 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1617 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1619 if ($skip_bank_accounts)
1620 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1621 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1622 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1623 ."ON chart.account_code=acc.account_code
1624 WHERE acc.account_code IS NULL
1625 AND chart.account_type=type.id";
1627 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1628 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1629 WHERE chart.account_type=type.id";
1631 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1633 'format' => '_format_account',
1634 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1637 'order' => array('type.class_id','type.id','account_code'),
1638 'search_box' => $cells,
1639 'search_submit' => false,
1643 'select_submit'=> $submit_on_change,
1646 'show_inactive' => $all
1651 function _format_account($row)
1653 return $row[0] . " " . $row[1];
1656 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1657 $skip_bank_accounts=false, $cells=false, $all_option=false,
1658 $submit_on_change=false, $all=false)
1661 echo "<td>$label</td>\n";
1663 echo gl_all_accounts_list($name, $selected_id,
1664 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1668 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1669 $skip_bank_accounts=false, $cells=false, $all_option=false)
1671 echo "<tr><td class='label'>$label</td>";
1672 gl_all_accounts_list_cells(null, $name, $selected_id,
1673 $skip_bank_accounts, $cells, $all_option);
1677 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1680 $items['0'] = strlen($name_no) ? $name_no : _("No");
1681 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1683 return array_selector($name, $selected_id, $items,
1685 'select_submit'=> $submit_on_change,
1686 'async' => false ) ); // FIX?
1689 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1692 echo "<td>$label</td>\n";
1694 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1698 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1700 echo "<tr><td class='label'>$label</td>";
1701 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1705 //------------------------------------------------------------------------------------------------
1707 function languages_list($name, $selected_id=null, $all_option=false)
1709 global $installed_languages;
1713 $items[''] = $all_option;
1714 foreach ($installed_languages as $lang)
1715 $items[$lang['code']] = $lang['name'];
1716 return array_selector($name, $selected_id, $items);
1719 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1722 echo "<td>$label</td>\n";
1724 echo languages_list($name, $selected_id, $all_option);
1728 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1730 echo "<tr><td class='label'>$label</td>";
1731 languages_list_cells(null, $name, $selected_id, $all_option);
1735 //------------------------------------------------------------------------------------------------
1737 function bank_account_types_list($name, $selected_id=null)
1739 global $bank_account_types;
1741 return array_selector($name, $selected_id, $bank_account_types);
1744 function bank_account_types_list_cells($label, $name, $selected_id=null)
1747 echo "<td>$label</td>\n";
1749 echo bank_account_types_list($name, $selected_id);
1753 function bank_account_types_list_row($label, $name, $selected_id=null)
1755 echo "<tr><td class='label'>$label</td>";
1756 bank_account_types_list_cells(null, $name, $selected_id);
1760 //------------------------------------------------------------------------------------------------
1761 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1763 global $payment_person_types;
1766 foreach ($payment_person_types as $key=>$type)
1768 if ($key != PT_WORKORDER)
1769 $items[$key] = $type;
1771 return array_selector($name, $selected_id, $items,
1772 array( 'select_submit'=> $submit_on_change ) );
1775 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1778 echo "<td>$label</td>\n";
1780 echo payment_person_types_list($name, $selected_id, $related);
1784 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1786 echo "<tr><td class='label'>$label</td>";
1787 payment_person_types_list_cells(null, $name, $selected_id, $related);
1791 //------------------------------------------------------------------------------------------------
1793 function wo_types_list($name, $selected_id=null)
1795 global $wo_types_array;
1797 return array_selector($name, $selected_id, $wo_types_array,
1798 array( 'select_submit'=> true, 'async' => true ) );
1801 function wo_types_list_row($label, $name, $selected_id=null)
1803 echo "<tr><td class='label'>$label</td><td>\n";
1804 echo wo_types_list($name, $selected_id);
1805 echo "</td></tr>\n";
1808 //------------------------------------------------------------------------------------------------
1810 function dateformats_list_row($label, $name, $value=null)
1812 global $dateformats;
1814 echo "<tr><td class='label'>$label</td>\n<td>";
1815 echo array_selector( $name, $value, $dateformats );
1816 echo "</td></tr>\n";
1819 function dateseps_list_row($label, $name, $value=null)
1823 echo "<tr><td class='label'>$label</td>\n<td>";
1824 echo array_selector( $name, $value, $dateseps );
1825 echo "</td></tr>\n";
1828 function thoseps_list_row($label, $name, $value=null)
1832 echo "<tr><td class='label'>$label</td>\n<td>";
1833 echo array_selector( $name, $value, $thoseps );
1834 echo "</td></tr>\n";
1837 function decseps_list_row($label, $name, $value=null)
1841 echo "<tr><td class='label'>$label</td>\n<td>";
1842 echo array_selector( $name, $value, $decseps );
1843 echo "</td></tr>\n";
1846 function themes_list_row($label, $name, $value=null)
1848 global $path_to_root;
1850 $path = $path_to_root.'/themes/';
1852 $themedir = opendir($path);
1853 while(false !== ($fname = readdir($themedir)))
1855 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1857 $themes[$fname] = $fname;
1862 echo "<tr><td class='label'>$label</td>\n<td>";
1863 echo array_selector( $name, $value, $themes );
1864 echo "</td></tr>\n";
1867 function pagesizes_list_row($label, $name, $value=null)
1872 foreach ($pagesizes as $pz)
1875 echo "<tr><td class='label'>$label</td>\n<td>";
1876 echo array_selector( $name, $value, $items );
1877 echo "</td></tr>\n";
1880 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1882 global $systypes_array;
1884 // emove non-voidable transactions if needed
1885 $systypes = array_diff_key($systypes_array, array_flip($exclude));
1886 return array_selector($name, $value, $systypes,
1888 'spec_option'=> $spec_opt,
1889 'spec_id' => ALL_NUMERIC,
1890 'select_submit'=> $submit_on_change,
1896 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1899 echo "<td>$label</td>\n";
1901 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
1905 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1907 echo "<tr><td class='label'>$label</td>";
1908 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
1912 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1914 global $systypes_array;
1917 echo "<td>$label</td>\n";
1920 $items = $systypes_array;
1922 // exclude quotes, orders and dimensions
1923 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
1924 unset($items[$excl]);
1926 echo array_selector($name, $value, $items,
1928 'spec_option'=> _("All"),
1930 'select_submit'=> $submit_on_change,
1937 function cust_allocations_list_cells($label, $name, $selected=null)
1945 $all_items=>_("All Types"),
1946 '1'=> _("Sales Invoices"),
1947 '2'=> _("Overdue Invoices"),
1948 '3' => _("Payments"),
1949 '4' => _("Credit Notes"),
1950 '5' => _("Delivery Notes")
1952 echo array_selector($name, $selected, $allocs);
1956 function supp_allocations_list_cell($name, $selected=null)
1962 $all_items=>_("All Types"),
1963 '1'=> _("Invoices"),
1964 '2'=> _("Overdue Invoices"),
1965 '3' => _("Payments"),
1966 '4' => _("Credit Notes"),
1967 '5' => _("Overdue Credit Notes")
1969 echo array_selector($name, $selected, $allocs);
1973 function supp_transactions_list_cell($name, $selected=null)
1979 $all_items=>_("All Types"),
1981 '1'=> _("Invoices"),
1982 '2'=> _("Overdue Invoices"),
1983 '3' => _("Payments"),
1984 '4' => _("Credit Notes"),
1985 '5' => _("Overdue Credit Notes")
1988 echo array_selector($name, $selected, $allocs);
1992 function policy_list_cells($label, $name, $selected=null)
1997 echo array_selector($name, $selected,
1998 array( '' => _("Automatically put balance on back order"),
1999 'CAN' => _("Cancel any quantites not delivered")) );
2003 function policy_list_row($label, $name, $selected=null)
2005 echo "<tr><td class='label'>$label</td>";
2006 policy_list_cells(null, $name, $selected);
2010 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2015 echo array_selector($name, $selected,
2016 array( 'Return' => _("Items Returned to Inventory Location"),
2017 'WriteOff' => _("Items Written Off")),
2018 array( 'select_submit'=> $submit_on_change ) );
2022 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2024 echo "<tr><td class='label'>$label</td>";
2025 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2029 function number_list($name, $selected, $from, $to, $no_option=false)
2032 for ($i = $from; $i <= $to; $i++)
2035 return array_selector($name, $selected, $items,
2036 array( 'spec_option' => $no_option,
2037 'spec_id' => ALL_NUMERIC) );
2040 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2045 echo number_list($name, $selected, $from, $to, $no_option);
2049 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2051 echo "<tr><td class='label'>$label</td>";
2052 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2056 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2057 $submit_on_change=true)
2059 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2060 ." GROUP BY profile";
2061 $result = db_query($sql, 'cannot get all profile names');
2062 $profiles = array();
2063 while($myrow=db_fetch($result)) {
2064 $profiles[$myrow['profile']] = $myrow['profile'];
2069 echo "<td class='label'>$label</td>\n";
2072 echo array_selector($name, $selected_id, $profiles,
2073 array( 'select_submit'=> $submit_on_change,
2074 'spec_option'=>$spec_opt,
2078 echo "</td></tr>\n";
2081 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2083 static $printers; // query only once for page display
2086 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2087 $result = db_query($sql, 'cannot get all printers');
2088 $printers = array();
2089 while($myrow=db_fetch($result)) {
2090 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2093 return array_selector($name, $selected_id, $printers,
2094 array( 'select_submit'=> $submit_on_change,
2095 'spec_option'=>$spec_opt,
2100 //------------------------------------------------------------------------------------------------
2102 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2105 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2107 $sql .= " WHERE type=$type";
2109 return combo_input($name, $selected_id, $sql, 'id', 'description',
2112 'order' => 'description',
2113 'select_submit'=> $submit_on_change,
2119 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2122 echo "<td>$label</td>\n";
2124 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2128 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2130 echo "<tr><td class='label'>$label</td>";
2131 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2136 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2138 global $quick_actions;
2140 echo "<tr><td class='label'>$label</td><td>";
2141 echo array_selector($name, $selected_id, $quick_actions,
2143 'select_submit'=> $submit_on_change
2145 echo "</td></tr>\n";
2148 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2150 global $quick_entry_types;
2152 echo "<tr><td class='label'>$label</td><td>";
2153 echo array_selector($name, $selected_id, $quick_entry_types,
2155 'select_submit'=> $submit_on_change
2157 echo "</td></tr>\n";
2160 function record_status_list_row($label, $name) {
2161 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2164 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2166 global $class_types;
2168 echo "<tr><td class='label'>$label</td><td>";
2169 echo array_selector($name, $selected_id, $class_types,
2171 'select_submit'=> $submit_on_change
2173 echo "</td></tr>\n";
2176 //------------------------------------------------------------------------------------------------
2178 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2179 $show_inactive = false)
2183 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2185 return combo_input($name, $selected_id, $sql, 'id', 'description',
2187 'spec_option'=>$new_item ? _("New role") : false,
2189 'select_submit'=> $submit_on_change,
2190 'show_inactive' => $show_inactive
2194 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2195 $show_inactive = false)
2198 echo "<td>$label</td>\n";
2200 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2204 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2205 $show_inactive = false)
2207 echo "<tr><td class='label'>$label</td>";
2208 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2212 function tab_list_row($label, $name, $selected_id=null)
2214 global $installed_extensions;
2217 foreach ($_SESSION['App']->applications as $app) {
2218 $tabs[$app->id] = access_string($app->name, true);
2221 echo "<td class='label'>$label</td><td>\n";
2222 echo array_selector($name, $selected_id, $tabs);
2223 echo "</td></tr>\n";
2226 //-----------------------------------------------------------------------------------------------
2228 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2231 global $path_to_root;
2232 include_once($path_to_root . "/admin/db/tags_db.inc");
2233 $results = get_tags($type, $all);
2235 while ($tag = db_fetch($results))
2236 $tags[$tag['id']] = $tag['name'];
2238 if (!isset($tags)) {
2239 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2242 return array_selector($name, null, $tags,
2245 'height' => $height,
2246 'spec_option'=> $spec_opt,
2251 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2254 echo "<td>$label</td>\n";
2256 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2261 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2263 echo "<tr><td class='label'>$label</td>";
2264 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2268 //---------------------------------------------------------------------------------------------
2269 // List of sets of active extensions
2271 function extset_list($name, $value=null, $submit_on_change=false)
2273 global $db_connections;
2276 foreach ($db_connections as $comp)
2277 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2278 return array_selector( $name, $value, $items,
2280 'spec_option'=> _("Available and/or installed"),
2282 'select_submit'=> $submit_on_change,
2287 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2290 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2295 if (@$filter['class']) {
2296 $where[] = 'type='.db_escape($filter['class']);
2299 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2300 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2301 if (@$filter['multi']) { // contact category selector for person
2305 return combo_input($name, $selected_id, $sql, 'id', 'name',
2308 'height' => $multi ? 5:1,
2309 'category' => $groups,
2310 'select_submit'=> $submit_on_change,
2316 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2318 echo "<tr><td class='label'>$label</td><td>";
2319 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2320 echo "</td></tr>\n";
2323 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2325 global $pterm_types;
2327 echo "<tr><td class='label'>$label</td><td>";
2328 echo array_selector($name, $selected_id, $pterm_types,
2330 'select_submit'=> $submit_on_change
2332 echo "</td></tr>\n";
2335 function coa_list_row($label, $name, $value=null)
2337 global $path_to_root, $installed_extensions;
2339 $path = $path_to_root.'/sql/';
2341 $sqldir = opendir($path);
2342 while (false !== ($fname = readdir($sqldir)))
2344 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2346 $ext = array_search_value($fname, $installed_extensions, 'sql');
2348 $descr = $ext['name'];
2349 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2350 $descr = _("Standard new company American COA (4 digit)");
2351 } elseif ($fname == 'en_US-demo.sql') {
2352 $descr = _("Standard American COA (4 digit) with demo data");
2356 $coas[$fname] = $descr;
2361 echo "<tr><td class='label'>$label</td>\n<td>";
2362 echo array_selector( $name, $value, $coas );
2363 echo "</td></tr>\n";
2366 function payment_services($name)
2368 global $payment_services;
2370 $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2372 return array_selector($name, null, $services, array(
2373 'spec_option'=> _("No payment Link"),