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 define('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 define('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 //----------------------------------------------------------------------------
23 // Universal sql combo generator
24 // $sql must return selector values and selector texts in columns 0 & 1
25 // Options are merged with defaults.
27 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
32 $opts = array( // default options
33 'where'=> array(), // additional constraints
34 'order' => $namefield, // list sort order
35 // special option parameters
36 'spec_option'=>false, // option text or false
37 'spec_id' => 0, // option id
38 // submit on select parameters
39 'default' => '', // default value when $_POST is not set
40 'multi' => false, // multiple select
41 'select_submit' => false, //submit on select: true/false
42 'async' => true, // select update via ajax (true) vs _page_body reload
43 // search box parameters
45 'search_box' => false, // name or true/false
46 'type' => 0, // type of extended selector:
47 // 0 - with (optional) visible search box, search by fragment inside id
48 // 1 - with hidden search box, search by option text
49 // 2 - with (optional) visible search box, search by fragment at the start of id
50 // 3 - TODO reverse: box with hidden selector available via enter; this
51 // would be convenient for optional ad hoc adding of new item
52 'search_submit' => true, //search submit button: true/false
53 'size' => 8, // size and max of box tag
55 'height' => false, // number of lines in select box
56 'cells' => false, // combo displayed as 2 <td></td> cells
57 'search' => array(), // sql field names to search
58 'format' => null, // format functions for regular options
60 'box_hint' => null, // box/selectors hints; null = std see below
61 'category' => false, // category column name or false
62 'show_inactive' => false, // show inactive records.
63 'editable' => false // false, or length of editable entry field
65 // ------ merge options with defaults ----------
67 $opts = array_merge($opts, $options);
68 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
70 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
71 // select content filtered by search field:
72 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
73 // select set by select content field
74 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
76 $select_submit = $opts['select_submit'];
77 $spec_id = $opts['spec_id'];
78 $spec_option = $opts['spec_option'];
79 if ($opts['type'] == 0) {
82 } elseif($opts['type'] == 1) {
90 $disabled = $opts['disabled'] ? "disabled" : '';
91 $multi = $opts['multi'];
93 if(!count($opts['search'])) {
94 $opts['search'] = array($by_id ? $valfield : $namefield);
96 if ($opts['sel_hint'] === null)
97 $opts['sel_hint'] = $by_id || $search_box==false ?
98 '' : _('Press Space tab for search pattern entry');
100 if ($opts['box_hint'] === null)
101 $opts['box_hint'] = $search_box && $search_submit != false ?
102 ($by_id ? _('Enter code fragment to search or * for all')
103 : _('Enter description fragment to search or * for all')) :'';
105 if ($selected_id == null) {
106 $selected_id = get_post($name, (string)$opts['default']);
108 if(!is_array($selected_id))
109 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
111 $txt = get_post($search_box);
114 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
115 if ($by_id) $txt = $_POST[$name];
118 $Ajax->activate('_page_body');
120 $Ajax->activate($name);
122 if (isset($_POST[$search_button])) {
124 $Ajax->activate('_page_body');
126 $Ajax->activate($name);
129 // search related sql modifications
131 $rel = "rel='$search_box'"; // set relation to list
132 if ($opts['search_submit']) {
133 if (isset($_POST[$search_button])) {
134 $selected_id = array(); // ignore selected_id while search
136 $Ajax->activate('_page_body');
138 $Ajax->activate($name);
141 if ($spec_option === false && $selected_id == array())
144 $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id));
149 foreach($opts['search'] as $i=> $s)
150 $opts['search'][$i] = $s . " LIKE "
151 .db_escape(($class=='combo3' ? '' : '%').$txt.'%');
152 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
158 if (count($opts['where'])) {
159 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
160 $where .= '('. implode($opts['where'], ' AND ') . ')';
161 $group_pos = strpos($sql, 'GROUP BY');
163 $group = substr($sql, $group_pos);
164 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
169 if ($opts['order'] != false) {
170 if (!is_array($opts['order']))
171 $opts['order'] = array($opts['order']);
172 $sql .= ' ORDER BY '.implode(',',$opts['order']);
176 // ------ make selector ----------
177 $selector = $first_opt = '';
182 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
183 //if($name=='curr_default') display_notification($opts['search_submit']);
184 if($result = db_query($sql)) {
185 while ($contact_row = db_fetch($result)) {
186 $value = $contact_row[0];
187 $descr = $opts['format']==null ? $contact_row[1] :
188 call_user_func($opts['format'], $contact_row);
190 if (get_post($search_button) && ($txt == $value)) {
191 $selected_id[] = $value;
194 if (in_array((string)$value, $selected_id, true)) {
197 $edit = $opts['editable'] && $contact_row['editable']
198 && (@$_POST[$search_box] == $value)
199 ? $contact_row[1] : false; // get non-formatted description
201 break; // selected field is editable - abandon list construction
203 // show selected option even if inactive
204 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
207 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
209 if ($first_id === false) {
213 $cat = $contact_row[$opts['category']];
214 if ($opts['category'] !== false && $cat != $lastcat){
216 $selector .= "</optgroup>";
217 $selector .= "<optgroup label='".$cat."'>\n";
220 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
223 $selector .= "</optgroup>";
224 db_free_result($result);
227 // Prepend special option.
228 if ($spec_option !== false) { // if special option used - add it
229 $first_id = $spec_id;
230 $first_opt = $spec_option;
232 // if($first_id !== false) {
233 $sel = $found===false ? 'selected' : '';
234 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
235 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
239 if ($found===false) {
240 $selected_id = array($first_id);
243 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
245 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
246 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
247 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
248 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
250 if ($by_id && ($search_box != false || $opts['editable']) ) {
251 // on first display show selector list
252 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
253 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
254 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
255 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
256 set_focus($name.'_text'); // prevent lost focus
257 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
258 set_focus($name); // prevent lost focus
259 if (!$opts['editable'])
261 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
264 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
266 // span for select list/input field update
267 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
269 // if selectable or editable list is used - add select button
270 if ($select_submit != false || $search_button) {
271 // button class selects form reload/ajax selector update
272 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
273 (fallback_mode() ? '' : 'display:none;'),
274 '_'.$name.'_update')."\n";
276 // ------ make combo ----------
278 if ($search_box != false) {
279 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
280 $opts['size']."' maxlength='".$opts['max'].
281 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
282 .$opts['box_hint']."'"
283 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
285 if ($search_submit != false || $opts['editable']) {
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'" : '';
372 // Prepend special option.
373 if ($spec_option !== false) { // if special option used - add it
374 $first_id = $spec_id;
375 $first_opt = $spec_option;
376 $sel = $found===false ? 'selected' : '';
377 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
381 if ($found===false) {
382 $selected_id = array($first_id);
384 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
386 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
387 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
388 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
389 . $opts['sel_hint']."'>".$selector."</select>\n";
391 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
393 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
395 if ($select_submit != false) { // if submit on change is used - add select button
396 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
397 (fallback_mode() ? '' : 'display:none;'),
398 '_'.$name.'_update')."\n";
400 default_focus($name);
404 //----------------------------------------------------------------------------------------------
406 function _format_add_curr($row)
408 static $company_currency;
410 if ($company_currency == null)
412 $company_currency = get_company_currency();
414 return $row[1] . ($row[2] == $company_currency ?
415 '' : (" - " . $row[2]));
418 function add_edit_combo($type)
420 global $path_to_root, $popup_editors, $SysPrefs;
422 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
425 $theme_path = $path_to_root . '/themes/' . user_theme();
427 $key = $popup_editors[$type][1];
428 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
429 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
430 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
433 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
434 $all=false, $editkey = false)
437 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
439 $mode = get_company_pref('no_supplier_list');
442 set_editor('supplier', $name, $editkey);
444 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
446 'format' => '_format_add_curr',
447 'order' => array('supp_ref'),
448 'search_box' => $mode!=0,
450 'search' => array("supp_ref","supp_name","gst_no"),
451 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
452 'spec_id' => ALL_TEXT,
453 'select_submit'=> $submit_on_change,
455 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
456 _('Select supplier'),
457 'show_inactive'=>$all
460 $ret .= add_edit_combo('supplier');
464 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
465 $submit_on_change=false, $all=false, $editkey = false)
468 echo "<td>$label</td><td>\n";
469 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
474 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
475 $submit_on_change=false, $all=false, $editkey = false)
477 echo "<tr><td class='label'>$label</td><td>";
478 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
482 //----------------------------------------------------------------------------------------------
484 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
485 $show_inactive=false, $editkey = false)
488 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
490 $mode = get_company_pref('no_customer_list');
493 set_editor('customer', $name, $editkey);
495 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
497 'format' => '_format_add_curr',
498 'order' => array('debtor_ref'),
499 'search_box' => $mode!=0,
502 'search' => array("debtor_ref","name","tax_id"),
503 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
504 'spec_id' => ALL_TEXT,
505 'select_submit'=> $submit_on_change,
507 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
508 _('Select customer'),
509 'show_inactive' => $show_inactive
512 $ret .= add_edit_combo('customer');
516 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
517 $submit_on_change=false, $show_inactive=false, $editkey = false)
520 echo "<td>$label</td>\n";
522 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
523 $show_inactive, $editkey);
527 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
528 $submit_on_change=false, $show_inactive=false, $editkey = false)
531 echo "<tr><td class='label'>$label</td><td nowrap>";
532 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
533 $show_inactive, $editkey);
534 echo "</td>\n</tr>\n";
537 //------------------------------------------------------------------------------------------------
539 function customer_branches_list($customer_id, $name, $selected_id=null,
540 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
543 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
544 WHERE debtor_no=" . db_escape($customer_id)." ";
547 set_editor('branch', $name, $editkey);
549 $where = $enabled ? array("inactive = 0") : array();
550 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
553 'order' => array('branch_ref'),
554 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
555 'spec_id' => ALL_TEXT,
556 'select_submit'=> $submit_on_change,
557 'sel_hint' => _('Select customer branch')
561 $ret .= add_edit_combo('branch');
565 //------------------------------------------------------------------------------------------------
567 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
568 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
571 echo "<td>$label</td>\n";
573 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
574 $submit_on_change, $editkey);
578 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
579 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
581 echo "<tr><td class='label'>$label</td>";
582 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
583 $all_option, $enabled, $submit_on_change, $editkey);
587 //------------------------------------------------------------------------------------------------
589 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
592 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
594 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
596 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
597 'spec_id' => ALL_TEXT,
598 'select_submit'=> $submit_on_change
602 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
605 echo "<td>$label</td>\n";
607 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
611 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
613 echo "<tr><td class='label'>$label</td>";
614 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
618 //-----------------------------------------------------------------------------------------------
620 function currencies_list($name, $selected_id=null, $submit_on_change=false)
622 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
624 // default to the company currency
625 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
627 'select_submit'=> $submit_on_change,
628 'default' => get_company_currency(),
633 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
636 echo "<td>$label</td>\n";
638 echo currencies_list($name, $selected_id, $submit_on_change);
642 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
644 echo "<tr><td class='label'>$label</td>";
645 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
649 //---------------------------------------------------------------------------------------------------
651 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
654 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
656 // default to the company current fiscal year
658 return combo_input($name, $selected_id, $sql, 'id', '',
661 'default' => get_company_pref('f_year'),
662 'format' => '_format_fiscalyears',
663 'select_submit'=> $submit_on_change,
668 function _format_fiscalyears($row)
670 return sql2date($row[1]) . " - " . sql2date($row[2])
671 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
674 function fiscalyears_list_cells($label, $name, $selected_id=null)
677 echo "<td>$label</td>\n";
679 echo fiscalyears_list($name, $selected_id);
683 function fiscalyears_list_row($label, $name, $selected_id=null)
685 echo "<tr><td class='label'>$label</td>";
686 fiscalyears_list_cells(null, $name, $selected_id);
689 //------------------------------------------------------------------------------------
691 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
692 $submit_on_change=false, $showclosed=false, $showtype=1)
694 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
697 'order' => 'reference',
698 'spec_option'=>$no_option ? $showname : false,
700 'select_submit'=> $submit_on_change,
705 $options['where'][] = "closed=0";
707 $options['where'][] = "type_=".db_escape($showtype);
709 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
712 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
713 $showclosed=false, $showtype=0, $submit_on_change=false)
716 echo "<td>$label</td>\n";
718 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
722 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
723 $showclosed=false, $showtype=0, $submit_on_change=false)
725 echo "<tr><td class='label'>$label</td>";
726 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
727 $showclosed, $showtype, $submit_on_change);
731 //---------------------------------------------------------------------------------------------------
733 function stock_items_list($name, $selected_id=null, $all_option=false,
734 $submit_on_change=false, $opts=array(), $editkey = false)
737 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
738 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
741 set_editor('item', $name, $editkey);
743 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
746 'format' => '_format_stock_items',
747 'spec_option' => $all_option===true ? _("All Items") : $all_option,
748 'spec_id' => ALL_TEXT,
749 'search_box' => true,
750 'search' => array("stock_id", "c.description","s.description"),
751 'search_submit' => get_company_pref('no_item_list')!=0,
753 'select_submit'=> $submit_on_change,
755 'order' => array('c.description','stock_id')
758 $ret .= add_edit_combo('item');
762 function _format_stock_items($row)
764 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
767 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
768 $submit_on_change=false, $all=false, $editkey = false)
771 echo "<td>$label</td>\n";
772 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
773 array('cells'=>true, 'show_inactive'=>$all), $editkey);
776 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
779 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
783 //---------------------------------------------------------------------------------------------------
785 // Select item via foreign code.
787 function sales_items_list($name, $selected_id=null, $all_option=false,
788 $submit_on_change=false, $type='', $opts=array())
791 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
792 i.inactive, if(count(*)>1, '0', s.editable) as editable
794 ".TB_PREF."stock_master s,
795 ".TB_PREF."item_codes i
797 ".TB_PREF."stock_category c
798 ON i.category_id=c.category_id
799 WHERE i.stock_id=s.stock_id";
802 if ($type == 'local') { // exclude foreign codes
803 $sql .= " AND !i.is_foreign";
804 } elseif ($type == 'kits') { // sales kits
805 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
807 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
808 $sql .= " GROUP BY i.item_code";
810 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
813 'format' => '_format_stock_items',
814 'spec_option' => $all_option===true ? _("All Items") : $all_option,
815 'spec_id' => ALL_TEXT,
816 'search_box' => true,
817 'search' => array("i.item_code", "c.description", "i.description"),
818 'search_submit' => get_company_pref('no_item_list')!=0,
820 'select_submit'=> $submit_on_change,
822 'order' => array('c.description','i.item_code'),
828 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
831 set_editor('item', $name, $editkey);
834 echo "<td>$label</td>\n";
835 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
836 '', array('cells'=>true));
839 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
841 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
842 'kits', array('cells'=>false, 'editable' => false));
845 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
849 echo "<td class='label'>$label</td>\n";
851 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
852 'local', array('cells'=>false, 'editable' => false));
855 //------------------------------------------------------------------------------------
857 function stock_manufactured_items_list($name, $selected_id=null,
858 $all_option=false, $submit_on_change=false)
860 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
861 array('where'=>array("mb_flag= 'M'")));
864 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
865 $all_option=false, $submit_on_change=false)
868 echo "<td>$label</td>\n";
870 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
874 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
875 $all_option=false, $submit_on_change=false)
877 echo "<tr><td class='label'>$label</td>";
878 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
881 //------------------------------------------------------------------------------------
883 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
884 $all_option=false, $submit_on_change=false, $editkey = false)
886 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
887 array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
890 function stock_component_items_list_cells($label, $name, $parent_stock_id,
891 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
894 echo "<td>$label</td>\n";
895 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
896 array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
899 //------------------------------------------------------------------------------------
901 function stock_costable_items_list($name, $selected_id=null,
902 $all_option=false, $submit_on_change=false)
904 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
905 array('where'=>array("mb_flag!='D'")));
908 function stock_costable_items_list_cells($label, $name, $selected_id=null,
909 $all_option=false, $submit_on_change=false)
912 echo "<td>$label</td>\n";
913 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
914 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
917 //------------------------------------------------------------------------------------
918 function stock_purchasable_items_list($name, $selected_id=null,
919 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
921 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
922 array('where'=>array("NOT no_purchase"),
923 'show_inactive'=>$all), $editkey);
926 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
928 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
929 $all_option=false, $submit_on_change=false, $editkey=false)
932 echo "<td>$label</td>\n";
933 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
934 array('where'=>array("NOT no_purchase"),
936 'cells'=>true), $editkey);
939 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
940 $all_option=false, $submit_on_change=false, $editkey=false)
942 echo "<tr><td class='label'>$label</td>";
943 stock_purchasable_items_list_cells(null, $name, $selected_id=null,
944 $all_option, $submit_on_change, $editkey);
948 //------------------------------------------------------------------------------------
950 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
956 echo "<td class='label'>$label</td>\n";
959 echo array_selector($name, $selected_id, $stock_types,
961 'select_submit'=> true,
962 'disabled' => !$enabled) );
966 function stock_units_list_row($label, $name, $value=null, $enabled=true)
968 $result = get_all_item_units();
971 echo "<td class='label'>$label</td>\n";
974 while($unit = db_fetch($result))
975 $units[$unit['abbr']] = $unit['name'];
977 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
982 //------------------------------------------------------------------------------------
984 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
986 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
988 return combo_input($name, $selected_id, $sql, 'id', 'name',
990 'spec_option' => $none_option,
991 'spec_id' => ALL_NUMERIC,
992 'select_submit'=> $submit_on_change,
997 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
998 $submit_on_change=false)
1001 echo "<td>$label</td>\n";
1003 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1007 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1008 $submit_on_change=false)
1010 echo "<tr><td class='label'>$label</td>";
1011 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1015 //------------------------------------------------------------------------------------
1017 function tax_groups_list($name, $selected_id=null,
1018 $none_option=false, $submit_on_change=false)
1020 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1022 return combo_input($name, $selected_id, $sql, 'id', 'name',
1025 'spec_option' => $none_option,
1026 'spec_id' => ALL_NUMERIC,
1027 'select_submit'=> $submit_on_change,
1032 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1035 echo "<td>$label</td>\n";
1037 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1041 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1043 echo "<tr><td class='label'>$label</td>";
1044 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1048 //------------------------------------------------------------------------------------
1050 function item_tax_types_list($name, $selected_id=null)
1052 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1053 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1056 function item_tax_types_list_cells($label, $name, $selected_id=null)
1059 echo "<td>$label</td>\n";
1061 echo item_tax_types_list($name, $selected_id);
1065 function item_tax_types_list_row($label, $name, $selected_id=null)
1067 echo "<tr><td class='label'>$label</td>";
1068 item_tax_types_list_cells(null, $name, $selected_id);
1072 //------------------------------------------------------------------------------------
1074 function shippers_list($name, $selected_id=null)
1076 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1077 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1078 array('order'=>array('shipper_name')));
1081 function shippers_list_cells($label, $name, $selected_id=null)
1084 echo "<td>$label</td>\n";
1086 echo shippers_list($name, $selected_id);
1090 function shippers_list_row($label, $name, $selected_id=null)
1092 echo "<tr><td class='label'>$label</td>";
1093 shippers_list_cells(null, $name, $selected_id);
1097 //-------------------------------------------------------------------------------------
1099 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1101 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1102 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1103 array('order'=>array('salesman_name'),
1104 'spec_option' => $spec_opt,
1105 'spec_id' => ALL_NUMERIC));
1108 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1111 echo "<td>$label</td>\n";
1113 echo sales_persons_list($name, $selected_id, $spec_opt);
1117 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1119 echo "<tr><td class='label'>$label</td>";
1120 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1124 //------------------------------------------------------------------------------------
1126 function sales_areas_list($name, $selected_id=null)
1128 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1129 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1132 function sales_areas_list_cells($label, $name, $selected_id=null)
1135 echo "<td>$label</td>\n";
1137 echo sales_areas_list($name, $selected_id);
1141 function sales_areas_list_row($label, $name, $selected_id=null)
1143 echo "<tr><td class='label'>$label</td>";
1144 sales_areas_list_cells(null, $name, $selected_id);
1148 //------------------------------------------------------------------------------------
1150 function sales_groups_list($name, $selected_id=null, $special_option=false)
1152 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1153 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1154 'spec_option' => $special_option===true ? ' ' : $special_option,
1155 'order' => 'description', 'spec_id' => 0,
1159 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1162 echo "<td>$label</td>\n";
1164 echo sales_groups_list($name, $selected_id, $special_option);
1168 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1170 echo "<tr><td class='label'>$label</td>";
1171 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1175 //------------------------------------------------------------------------------------
1177 function _format_template_items($row)
1179 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1182 function templates_list($name, $selected_id=null, $special_option=false)
1184 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1185 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1186 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1187 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1188 'format' => '_format_template_items',
1189 'spec_option' => $special_option===true ? ' ' : $special_option,
1190 'order' => 'order_no', 'spec_id' => 0,
1194 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1197 echo "<td>$label</td>\n";
1199 echo templates_list($name, $selected_id, $special_option);
1203 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1205 echo "<tr><td class='label'>$label</td>";
1206 templates_list_cells(null, $name, $selected_id, $special_option);
1210 //------------------------------------------------------------------------------------
1212 function workorders_list($name, $selected_id=null)
1214 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1215 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1218 function workorders_list_cells($label, $name, $selected_id=null)
1221 echo "<td>$label</td>\n";
1223 echo workorders_list($name, $selected_id);
1227 function workorders_list_row($label, $name, $selected_id=null)
1229 echo "<tr><td class='label'>$label</td>";
1230 workorders_list_cells(null, $name, $selected_id);
1234 //------------------------------------------------------------------------------------
1236 function payment_terms_list($name, $selected_id=null)
1238 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1239 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1242 function payment_terms_list_cells($label, $name, $selected_id=null)
1245 echo "<td>$label</td>\n";
1247 echo payment_terms_list($name, $selected_id);
1251 function payment_terms_list_row($label, $name, $selected_id=null)
1253 echo "<tr><td class='label'>$label</td>";
1254 payment_terms_list_cells(null, $name, $selected_id);
1258 //------------------------------------------------------------------------------------
1260 function credit_status_list($name, $selected_id=null)
1262 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1263 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1266 function credit_status_list_cells($label, $name, $selected_id=null)
1269 echo "<td>$label</td>\n";
1271 echo credit_status_list($name, $selected_id);
1275 function credit_status_list_row($label, $name, $selected_id=null)
1277 echo "<tr><td class='label'>$label</td>";
1278 credit_status_list_cells(null, $name, $selected_id);
1282 //-----------------------------------------------------------------------------------------------
1284 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1286 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1288 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1290 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1292 'select_submit'=> $submit_on_change,
1293 // 'async' => false,
1297 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1300 echo "<td>$label</td>\n";
1302 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1306 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1308 echo "<tr><td class='label'>$label</td>";
1309 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1313 //-----------------------------------------------------------------------------------------------
1315 function movement_types_list($name, $selected_id=null)
1317 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1318 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1321 function movement_types_list_cells($label, $name, $selected_id=null)
1324 echo "<td>$label</td>\n";
1326 echo movement_types_list($name, $selected_id);
1330 function movement_types_list_row($label, $name, $selected_id=null)
1332 echo "<tr><td class='label'>$label</td>";
1333 movement_types_list_cells(null, $name, $selected_id);
1337 //-----------------------------------------------------------------------------------------------
1338 function _format_date($row)
1340 return sql2date($row['reconciled']);
1343 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1345 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1346 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1347 GROUP BY reconciled";
1348 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1350 'spec_option' => $special_option,
1351 'format' => '_format_date',
1353 'select_submit'=> $submit_on_change
1357 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1360 echo "<td>$label</td>\n";
1362 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1366 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1369 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1373 //-----------------------------------------------------------------------------------------------
1375 function workcenter_list($name, $selected_id=null, $all_option=false)
1378 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1380 return combo_input($name, $selected_id, $sql, 'id', 'name',
1382 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1383 'spec_id' => ALL_TEXT,
1387 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1389 default_focus($name);
1391 echo "<td>$label</td>\n";
1393 echo workcenter_list($name, $selected_id, $all_option);
1397 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1399 echo "<tr><td class='label'>$label</td>";
1400 workcenter_list_cells(null, $name, $selected_id, $all_option);
1404 //-----------------------------------------------------------------------------------------------
1406 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1408 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1409 FROM ".TB_PREF."bank_accounts";
1411 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1413 'format' => '_format_add_curr',
1414 'select_submit'=> $submit_on_change,
1415 'spec_option' => $spec_option,
1421 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1424 echo "<td>$label</td>\n";
1426 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1430 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1432 echo "<tr><td class='label'>$label</td>";
1433 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1436 //-----------------------------------------------------------------------------------------------
1438 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1441 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1442 FROM ".TB_PREF."bank_accounts
1443 WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
1446 echo "<tr><td class='label'>$label</td>\n";
1448 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1450 'spec_option' => $all_option,
1451 'spec_id' => ALL_TEXT,
1452 'format' => '_format_add_curr',
1453 'select_submit'=> $submit_on_change,
1456 echo "</td></tr>\n";
1458 //-----------------------------------------------------------------------------------------------
1460 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1462 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1464 default_focus($name);
1467 echo "<td class='label'>$label</td>\n";
1470 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1472 'select_submit'=> $submit_on_change,
1474 'spec_option' =>$spec_option,
1476 'order'=> array('pos_name')
1478 echo "</td></tr>\n";
1481 //-----------------------------------------------------------------------------------------------
1482 // Payment type selector for current user.
1484 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1486 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1488 if ($category == PM_CASH) // only cash
1489 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1490 elseif ($category == PM_CREDIT) // only delayed payments
1491 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1492 elseif (!$prepayments)
1493 $sql .= " WHERE days_before_due>=0";
1495 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1497 'select_submit'=> $submit_on_change,
1503 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1506 echo "<td class='label'>$label</td>\n";
1509 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1513 //-----------------------------------------------------------------------------------------------
1515 function class_list($name, $selected_id=null, $submit_on_change=false)
1517 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1519 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1521 'select_submit'=> $submit_on_change,
1527 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1530 echo "<td>$label</td>\n";
1532 echo class_list($name, $selected_id, $submit_on_change);
1536 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1538 echo "<tr><td class='label'>$label</td>";
1539 class_list_cells(null, $name, $selected_id, $submit_on_change);
1543 //-----------------------------------------------------------------------------------------------
1544 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1546 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1547 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1548 array('order'=>'category_id',
1549 'spec_option' => $spec_opt,
1551 'select_submit'=> $submit_on_change,
1556 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1559 echo "<td>$label</td>\n";
1561 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1565 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1567 echo "<tr><td class='label'>$label</td>";
1568 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1572 //-----------------------------------------------------------------------------------------------
1574 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1577 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1579 return combo_input($name, $selected_id, $sql, 'id', 'name',
1581 'format' => '_format_account',
1582 'order' => array('class_id', 'id', 'parent'),
1583 'spec_option' =>$all_option,
1584 'spec_id' => ALL_TEXT
1588 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1591 echo "<td>$label</td>\n";
1593 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1597 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1599 echo "<tr><td class='label'>$label</td>";
1600 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1605 //-----------------------------------------------------------------------------------------------
1606 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1607 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1609 if ($skip_bank_accounts)
1610 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1611 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1612 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1613 ."ON chart.account_code=acc.account_code
1614 WHERE acc.account_code IS NULL
1615 AND chart.account_type=type.id";
1617 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1618 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1619 WHERE chart.account_type=type.id";
1621 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1623 'format' => '_format_account',
1624 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1627 'order' => array('type.class_id','type.id','account_code'),
1628 'search_box' => $cells,
1629 'search_submit' => false,
1633 'select_submit'=> $submit_on_change,
1636 'show_inactive' => $all
1641 function _format_account($row)
1643 return $row[0] . " " . $row[1];
1646 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1647 $skip_bank_accounts=false, $cells=false, $all_option=false,
1648 $submit_on_change=false, $all=false)
1651 echo "<td>$label</td>\n";
1653 echo gl_all_accounts_list($name, $selected_id,
1654 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1658 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1659 $skip_bank_accounts=false, $cells=false, $all_option=false)
1661 echo "<tr><td class='label'>$label</td>";
1662 gl_all_accounts_list_cells(null, $name, $selected_id,
1663 $skip_bank_accounts, $cells, $all_option);
1667 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1670 $items['0'] = strlen($name_no) ? $name_no : _("No");
1671 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1673 return array_selector($name, $selected_id, $items,
1675 'select_submit'=> $submit_on_change,
1676 'async' => false ) ); // FIX?
1679 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1682 echo "<td>$label</td>\n";
1684 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1688 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1690 echo "<tr><td class='label'>$label</td>";
1691 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1695 //------------------------------------------------------------------------------------------------
1697 function languages_list($name, $selected_id=null, $all_option=false)
1699 global $installed_languages;
1703 $items[''] = $all_option;
1704 foreach ($installed_languages as $lang)
1705 $items[$lang['code']] = $lang['name'];
1706 return array_selector($name, $selected_id, $items);
1709 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1712 echo "<td>$label</td>\n";
1714 echo languages_list($name, $selected_id, $all_option);
1718 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1720 echo "<tr><td class='label'>$label</td>";
1721 languages_list_cells(null, $name, $selected_id, $all_option);
1725 //------------------------------------------------------------------------------------------------
1727 function bank_account_types_list($name, $selected_id=null)
1729 global $bank_account_types;
1731 return array_selector($name, $selected_id, $bank_account_types);
1734 function bank_account_types_list_cells($label, $name, $selected_id=null)
1737 echo "<td>$label</td>\n";
1739 echo bank_account_types_list($name, $selected_id);
1743 function bank_account_types_list_row($label, $name, $selected_id=null)
1745 echo "<tr><td class='label'>$label</td>";
1746 bank_account_types_list_cells(null, $name, $selected_id);
1750 //------------------------------------------------------------------------------------------------
1751 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1753 global $payment_person_types;
1756 foreach ($payment_person_types as $key=>$type)
1758 if ($key != PT_WORKORDER)
1759 $items[$key] = $type;
1761 return array_selector($name, $selected_id, $items,
1762 array( 'select_submit'=> $submit_on_change ) );
1765 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1768 echo "<td>$label</td>\n";
1770 echo payment_person_types_list($name, $selected_id, $related);
1774 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1776 echo "<tr><td class='label'>$label</td>";
1777 payment_person_types_list_cells(null, $name, $selected_id, $related);
1781 //------------------------------------------------------------------------------------------------
1783 function wo_types_list($name, $selected_id=null)
1785 global $wo_types_array;
1787 return array_selector($name, $selected_id, $wo_types_array,
1788 array( 'select_submit'=> true, 'async' => true ) );
1791 function wo_types_list_row($label, $name, $selected_id=null)
1793 echo "<tr><td class='label'>$label</td><td>\n";
1794 echo wo_types_list($name, $selected_id);
1795 echo "</td></tr>\n";
1798 //------------------------------------------------------------------------------------------------
1800 function dateformats_list_row($label, $name, $value=null)
1804 echo "<tr><td class='label'>$label</td>\n<td>";
1805 echo array_selector( $name, $value, $SysPrefs->dateformats );
1806 echo "</td></tr>\n";
1809 function dateseps_list_row($label, $name, $value=null)
1813 echo "<tr><td class='label'>$label</td>\n<td>";
1814 echo array_selector( $name, $value, $SysPrefs->dateseps );
1815 echo "</td></tr>\n";
1818 function thoseps_list_row($label, $name, $value=null)
1822 echo "<tr><td class='label'>$label</td>\n<td>";
1823 echo array_selector( $name, $value, $SysPrefs->thoseps );
1824 echo "</td></tr>\n";
1827 function decseps_list_row($label, $name, $value=null)
1831 echo "<tr><td class='label'>$label</td>\n<td>";
1832 echo array_selector( $name, $value, $SysPrefs->decseps );
1833 echo "</td></tr>\n";
1836 function themes_list_row($label, $name, $value=null)
1838 global $path_to_root;
1840 $path = $path_to_root.'/themes/';
1842 $themedir = opendir($path);
1843 while(false !== ($fname = readdir($themedir)))
1845 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1847 $themes[$fname] = $fname;
1852 echo "<tr><td class='label'>$label</td>\n<td>";
1853 echo array_selector( $name, $value, $themes );
1854 echo "</td></tr>\n";
1857 function pagesizes_list_row($label, $name, $value=null)
1862 foreach ($SysPrefs->pagesizes as $pz)
1865 echo "<tr><td class='label'>$label</td>\n<td>";
1866 echo array_selector( $name, $value, $items );
1867 echo "</td></tr>\n";
1870 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1872 global $systypes_array;
1874 // emove non-voidable transactions if needed
1875 $systypes = array_diff_key($systypes_array, array_flip($exclude));
1876 return array_selector($name, $value, $systypes,
1878 'spec_option'=> $spec_opt,
1879 'spec_id' => ALL_NUMERIC,
1880 'select_submit'=> $submit_on_change,
1886 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1889 echo "<td>$label</td>\n";
1891 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
1895 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1897 echo "<tr><td class='label'>$label</td>";
1898 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
1902 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1904 global $systypes_array;
1907 echo "<td>$label</td>\n";
1910 $items = $systypes_array;
1912 // exclude quotes, orders and dimensions
1913 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
1914 unset($items[$excl]);
1916 echo array_selector($name, $value, $items,
1918 'spec_option'=> _("All"),
1920 'select_submit'=> $submit_on_change,
1927 function cust_allocations_list_cells($label, $name, $selected=null)
1934 ALL_TEXT=>_("All Types"),
1935 '1'=> _("Sales Invoices"),
1936 '2'=> _("Overdue Invoices"),
1937 '3' => _("Payments"),
1938 '4' => _("Credit Notes"),
1939 '5' => _("Delivery Notes")
1941 echo array_selector($name, $selected, $allocs);
1945 function supp_allocations_list_cell($name, $selected=null)
1950 ALL_TEXT=>_("All Types"),
1951 '1'=> _("Invoices"),
1952 '2'=> _("Overdue Invoices"),
1953 '3' => _("Payments"),
1954 '4' => _("Credit Notes"),
1955 '5' => _("Overdue Credit Notes")
1957 echo array_selector($name, $selected, $allocs);
1961 function supp_transactions_list_cell($name, $selected=null)
1966 ALL_TEXT=>_("All Types"),
1968 '1'=> _("Invoices"),
1969 '2'=> _("Overdue Invoices"),
1970 '3' => _("Payments"),
1971 '4' => _("Credit Notes"),
1972 '5' => _("Overdue Credit Notes")
1975 echo array_selector($name, $selected, $allocs);
1979 function policy_list_cells($label, $name, $selected=null)
1984 echo array_selector($name, $selected,
1985 array( '' => _("Automatically put balance on back order"),
1986 'CAN' => _("Cancel any quantites not delivered")) );
1990 function policy_list_row($label, $name, $selected=null)
1992 echo "<tr><td class='label'>$label</td>";
1993 policy_list_cells(null, $name, $selected);
1997 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2002 echo array_selector($name, $selected,
2003 array( 'Return' => _("Items Returned to Inventory Location"),
2004 'WriteOff' => _("Items Written Off")),
2005 array( 'select_submit'=> $submit_on_change ) );
2009 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2011 echo "<tr><td class='label'>$label</td>";
2012 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2016 function number_list($name, $selected, $from, $to, $no_option=false)
2019 for ($i = $from; $i <= $to; $i++)
2022 return array_selector($name, $selected, $items,
2023 array( 'spec_option' => $no_option,
2024 'spec_id' => ALL_NUMERIC) );
2027 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2032 echo number_list($name, $selected, $from, $to, $no_option);
2036 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2038 echo "<tr><td class='label'>$label</td>";
2039 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2043 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2044 $submit_on_change=true)
2046 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2047 ." GROUP BY profile";
2048 $result = db_query($sql, 'cannot get all profile names');
2049 $profiles = array();
2050 while($myrow=db_fetch($result)) {
2051 $profiles[$myrow['profile']] = $myrow['profile'];
2056 echo "<td class='label'>$label</td>\n";
2059 echo array_selector($name, $selected_id, $profiles,
2060 array( 'select_submit'=> $submit_on_change,
2061 'spec_option'=>$spec_opt,
2065 echo "</td></tr>\n";
2068 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2070 static $printers; // query only once for page display
2073 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2074 $result = db_query($sql, 'cannot get all printers');
2075 $printers = array();
2076 while($myrow=db_fetch($result)) {
2077 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2080 return array_selector($name, $selected_id, $printers,
2081 array( 'select_submit'=> $submit_on_change,
2082 'spec_option'=>$spec_opt,
2087 //------------------------------------------------------------------------------------------------
2089 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2092 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2094 $sql .= " WHERE type=$type";
2096 return combo_input($name, $selected_id, $sql, 'id', 'description',
2099 'order' => 'description',
2100 'select_submit'=> $submit_on_change,
2106 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2109 echo "<td>$label</td>\n";
2111 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2115 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2117 echo "<tr><td class='label'>$label</td>";
2118 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2123 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2125 global $quick_actions;
2127 echo "<tr><td class='label'>$label</td><td>";
2128 echo array_selector($name, $selected_id, $quick_actions,
2130 'select_submit'=> $submit_on_change
2132 echo "</td></tr>\n";
2135 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2137 global $quick_entry_types;
2139 echo "<tr><td class='label'>$label</td><td>";
2140 echo array_selector($name, $selected_id, $quick_entry_types,
2142 'select_submit'=> $submit_on_change
2144 echo "</td></tr>\n";
2147 function record_status_list_row($label, $name) {
2148 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2151 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2153 global $class_types;
2155 echo "<tr><td class='label'>$label</td><td>";
2156 echo array_selector($name, $selected_id, $class_types,
2158 'select_submit'=> $submit_on_change
2160 echo "</td></tr>\n";
2163 //------------------------------------------------------------------------------------------------
2165 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2166 $show_inactive = false)
2169 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2171 return combo_input($name, $selected_id, $sql, 'id', 'description',
2173 'spec_option'=>$new_item ? _("New role") : false,
2175 'select_submit'=> $submit_on_change,
2176 'show_inactive' => $show_inactive
2180 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2181 $show_inactive = false)
2184 echo "<td>$label</td>\n";
2186 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2190 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2191 $show_inactive = false)
2193 echo "<tr><td class='label'>$label</td>";
2194 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2198 function tab_list_row($label, $name, $selected_id=null)
2200 global $installed_extensions;
2203 foreach ($_SESSION['App']->applications as $app) {
2204 $tabs[$app->id] = access_string($app->name, true);
2207 echo "<td class='label'>$label</td><td>\n";
2208 echo array_selector($name, $selected_id, $tabs);
2209 echo "</td></tr>\n";
2212 //-----------------------------------------------------------------------------------------------
2214 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2217 global $path_to_root;
2218 include_once($path_to_root . "/admin/db/tags_db.inc");
2219 $results = get_tags($type, $all);
2221 while ($tag = db_fetch($results))
2222 $tags[$tag['id']] = $tag['name'];
2224 if (!isset($tags)) {
2225 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2228 return array_selector($name, null, $tags,
2231 'height' => $height,
2232 'spec_option'=> $spec_opt,
2237 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2240 echo "<td>$label</td>\n";
2242 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2247 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2249 echo "<tr><td class='label'>$label</td>";
2250 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2254 //---------------------------------------------------------------------------------------------
2255 // List of sets of active extensions
2257 function extset_list($name, $value=null, $submit_on_change=false)
2259 global $db_connections;
2262 foreach ($db_connections as $comp)
2263 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2264 return array_selector( $name, $value, $items,
2266 'spec_option'=> _("Available and/or installed"),
2268 'select_submit'=> $submit_on_change,
2273 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2276 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2281 if (@$filter['class']) {
2282 $where[] = 'type='.db_escape($filter['class']);
2285 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2286 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2287 if (@$filter['multi']) { // contact category selector for person
2291 return combo_input($name, $selected_id, $sql, 'id', 'name',
2294 'height' => $multi ? 5:1,
2295 'category' => $groups,
2296 'select_submit'=> $submit_on_change,
2302 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2304 echo "<tr><td class='label'>$label</td><td>";
2305 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2306 echo "</td></tr>\n";
2309 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2311 global $pterm_types;
2313 echo "<tr><td class='label'>$label</td><td>";
2314 echo array_selector($name, $selected_id, $pterm_types,
2316 'select_submit'=> $submit_on_change
2318 echo "</td></tr>\n";
2321 function coa_list_row($label, $name, $value=null)
2323 global $path_to_root, $installed_extensions;
2325 $path = $path_to_root.'/sql/';
2327 $sqldir = opendir($path);
2328 while (false !== ($fname = readdir($sqldir)))
2330 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2332 $ext = array_search_value($fname, $installed_extensions, 'sql');
2334 $descr = $ext['name'];
2335 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2336 $descr = _("Standard new company American COA (4 digit)");
2337 } elseif ($fname == 'en_US-demo.sql') {
2338 $descr = _("Standard American COA (4 digit) with demo data");
2342 $coas[$fname] = $descr;
2347 echo "<tr><td class='label'>$label</td>\n<td>";
2348 echo array_selector( $name, $value, $coas );
2349 echo "</td></tr>\n";
2352 function payment_services($name)
2354 global $payment_services;
2356 $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2358 return array_selector($name, null, $services, array(
2359 'spec_option'=> _("No payment Link"),
2364 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2366 global $tax_algorithms;
2368 return array_selector($name, $value, $tax_algorithms,
2370 'select_submit'=> $submit_on_change,
2376 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2379 echo "<td>$label</td>\n";
2381 echo tax_algorithm_list($name, $value, $submit_on_change);
2385 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2387 echo "<tr><td class='label'>$label</td>";
2388 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2391 //----------------------------------------------------------------------------------------------
2393 function subledger_list($name, $account, $selected_id=null)
2396 $type = is_subledger_account($account);
2401 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2403 .TB_PREF."debtors_master d,"
2404 .TB_PREF."cust_branch c
2405 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2407 $sql = "SELECT supplier_id as id, supp_ref as name
2409 .TB_PREF."suppliers s
2410 WHERE s.payable_account=".db_escape($account);
2412 $mode = get_company_pref('no_customer_list');
2414 return combo_input($name, $selected_id, $sql, 'id', 'name',
2422 function subledger_list_cells($label, $name, $account, $selected_id=null)
2425 echo "<td>$label</td>\n";
2427 echo subledger_list($name, $account, $selected_id);
2431 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2432 $submit_on_change=false, $show_inactive=false, $editkey = false)
2434 echo "<tr><td class='label'>$label</td><td nowrap>";
2435 echo subledger_list($name, $account, $selected_id);
2436 echo "</td>\n</tr>\n";
2439 function accounts_type_list_row($label, $name, $selected_id=null)
2443 echo "<td class='label'>$label</td>\n";
2445 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2446 echo array_selector($name, $selected_id, $sel);
2447 echo "</td></tr>\n";
2450 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2453 $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2456 echo "<td>$label</td>\n";
2459 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2461 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2463 'order' => 'real_name',
2464 'select_submit'=> $submit_on_change,