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 _format_date($row)
1317 return sql2date($row['reconciled']);
1320 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1322 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1323 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1324 GROUP BY reconciled";
1325 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1327 'spec_option' => $special_option,
1328 'format' => '_format_date',
1330 'select_submit'=> $submit_on_change
1334 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1337 echo "<td>$label</td>\n";
1339 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1343 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1346 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1350 //-----------------------------------------------------------------------------------------------
1352 function workcenter_list($name, $selected_id=null, $all_option=false)
1355 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1357 return combo_input($name, $selected_id, $sql, 'id', 'name',
1359 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1360 'spec_id' => ALL_TEXT,
1364 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1366 default_focus($name);
1368 echo "<td>$label</td>\n";
1370 echo workcenter_list($name, $selected_id, $all_option);
1374 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1376 echo "<tr><td class='label'>$label</td>";
1377 workcenter_list_cells(null, $name, $selected_id, $all_option);
1381 //-----------------------------------------------------------------------------------------------
1383 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1385 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1386 FROM ".TB_PREF."bank_accounts";
1388 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1390 'format' => '_format_add_curr',
1391 'select_submit'=> $submit_on_change,
1392 'spec_option' => $spec_option,
1398 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1401 echo "<td>$label</td>\n";
1403 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1407 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1409 echo "<tr><td class='label'>$label</td>";
1410 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1413 //-----------------------------------------------------------------------------------------------
1415 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1418 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1419 FROM ".TB_PREF."bank_accounts
1420 WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
1423 echo "<tr><td class='label'>$label</td>\n";
1425 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1427 'spec_option' => $all_option,
1428 'spec_id' => ALL_TEXT,
1429 'format' => '_format_add_curr',
1430 'select_submit'=> $submit_on_change,
1433 echo "</td></tr>\n";
1435 //-----------------------------------------------------------------------------------------------
1437 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1439 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1441 default_focus($name);
1444 echo "<td class='label'>$label</td>\n";
1447 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1449 'select_submit'=> $submit_on_change,
1451 'spec_option' =>$spec_option,
1453 'order'=> array('pos_name')
1455 echo "</td></tr>\n";
1458 //-----------------------------------------------------------------------------------------------
1459 // Payment type selector for current user.
1461 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1463 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1465 if ($category == PM_CASH) // only cash
1466 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1467 elseif ($category == PM_CREDIT) // only delayed payments
1468 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1469 elseif (!$prepayments)
1470 $sql .= " WHERE days_before_due>=0";
1472 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1474 'select_submit'=> $submit_on_change,
1480 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1483 echo "<td class='label'>$label</td>\n";
1486 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1490 //-----------------------------------------------------------------------------------------------
1492 function class_list($name, $selected_id=null, $submit_on_change=false)
1494 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1496 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1498 'select_submit'=> $submit_on_change,
1504 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1507 echo "<td>$label</td>\n";
1509 echo class_list($name, $selected_id, $submit_on_change);
1513 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1515 echo "<tr><td class='label'>$label</td>";
1516 class_list_cells(null, $name, $selected_id, $submit_on_change);
1520 //-----------------------------------------------------------------------------------------------
1521 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1523 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1524 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1525 array('order'=>'category_id',
1526 'spec_option' => $spec_opt,
1528 'select_submit'=> $submit_on_change,
1533 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1536 echo "<td>$label</td>\n";
1538 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1542 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1544 echo "<tr><td class='label'>$label</td>";
1545 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1549 //-----------------------------------------------------------------------------------------------
1551 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1554 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1556 return combo_input($name, $selected_id, $sql, 'id', 'name',
1558 'format' => '_format_account',
1559 'order' => array('class_id', 'id', 'parent'),
1560 'spec_option' =>$all_option,
1561 'spec_id' => ALL_TEXT
1565 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1568 echo "<td>$label</td>\n";
1570 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1574 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1576 echo "<tr><td class='label'>$label</td>";
1577 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1582 //-----------------------------------------------------------------------------------------------
1583 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1584 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1586 if ($skip_bank_accounts)
1587 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1588 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1589 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1590 ."ON chart.account_code=acc.account_code
1591 WHERE acc.account_code IS NULL
1592 AND chart.account_type=type.id";
1594 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1595 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1596 WHERE chart.account_type=type.id";
1598 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1600 'format' => '_format_account',
1601 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1604 'order' => array('type.class_id','type.id','account_code'),
1605 'search_box' => $cells,
1606 'search_submit' => false,
1610 'select_submit'=> $submit_on_change,
1613 'show_inactive' => $all
1618 function _format_account($row)
1620 return $row[0] . " " . $row[1];
1623 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1624 $skip_bank_accounts=false, $cells=false, $all_option=false,
1625 $submit_on_change=false, $all=false)
1628 echo "<td>$label</td>\n";
1630 echo gl_all_accounts_list($name, $selected_id,
1631 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1635 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1636 $skip_bank_accounts=false, $cells=false, $all_option=false)
1638 echo "<tr><td class='label'>$label</td>";
1639 gl_all_accounts_list_cells(null, $name, $selected_id,
1640 $skip_bank_accounts, $cells, $all_option);
1644 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1647 $items['0'] = strlen($name_no) ? $name_no : _("No");
1648 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1650 return array_selector($name, $selected_id, $items,
1652 'select_submit'=> $submit_on_change,
1653 'async' => false ) ); // FIX?
1656 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1659 echo "<td>$label</td>\n";
1661 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1665 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1667 echo "<tr><td class='label'>$label</td>";
1668 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1672 //------------------------------------------------------------------------------------------------
1674 function languages_list($name, $selected_id=null, $all_option=false)
1676 global $installed_languages;
1680 $items[''] = $all_option;
1681 foreach ($installed_languages as $lang)
1682 $items[$lang['code']] = $lang['name'];
1683 return array_selector($name, $selected_id, $items);
1686 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1689 echo "<td>$label</td>\n";
1691 echo languages_list($name, $selected_id, $all_option);
1695 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1697 echo "<tr><td class='label'>$label</td>";
1698 languages_list_cells(null, $name, $selected_id, $all_option);
1702 //------------------------------------------------------------------------------------------------
1704 function bank_account_types_list($name, $selected_id=null)
1706 global $bank_account_types;
1708 return array_selector($name, $selected_id, $bank_account_types);
1711 function bank_account_types_list_cells($label, $name, $selected_id=null)
1714 echo "<td>$label</td>\n";
1716 echo bank_account_types_list($name, $selected_id);
1720 function bank_account_types_list_row($label, $name, $selected_id=null)
1722 echo "<tr><td class='label'>$label</td>";
1723 bank_account_types_list_cells(null, $name, $selected_id);
1727 //------------------------------------------------------------------------------------------------
1728 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1730 global $payment_person_types;
1733 foreach ($payment_person_types as $key=>$type)
1735 if ($key != PT_WORKORDER)
1736 $items[$key] = $type;
1738 return array_selector($name, $selected_id, $items,
1739 array( 'select_submit'=> $submit_on_change ) );
1742 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1745 echo "<td>$label</td>\n";
1747 echo payment_person_types_list($name, $selected_id, $related);
1751 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1753 echo "<tr><td class='label'>$label</td>";
1754 payment_person_types_list_cells(null, $name, $selected_id, $related);
1758 //------------------------------------------------------------------------------------------------
1760 function wo_types_list($name, $selected_id=null)
1762 global $wo_types_array;
1764 return array_selector($name, $selected_id, $wo_types_array,
1765 array( 'select_submit'=> true, 'async' => true ) );
1768 function wo_types_list_row($label, $name, $selected_id=null)
1770 echo "<tr><td class='label'>$label</td><td>\n";
1771 echo wo_types_list($name, $selected_id);
1772 echo "</td></tr>\n";
1775 //------------------------------------------------------------------------------------------------
1777 function dateformats_list_row($label, $name, $value=null)
1781 echo "<tr><td class='label'>$label</td>\n<td>";
1782 echo array_selector( $name, $value, $SysPrefs->dateformats );
1783 echo "</td></tr>\n";
1786 function dateseps_list_row($label, $name, $value=null)
1790 echo "<tr><td class='label'>$label</td>\n<td>";
1791 echo array_selector( $name, $value, $SysPrefs->dateseps );
1792 echo "</td></tr>\n";
1795 function thoseps_list_row($label, $name, $value=null)
1799 echo "<tr><td class='label'>$label</td>\n<td>";
1800 echo array_selector( $name, $value, $SysPrefs->thoseps );
1801 echo "</td></tr>\n";
1804 function decseps_list_row($label, $name, $value=null)
1808 echo "<tr><td class='label'>$label</td>\n<td>";
1809 echo array_selector( $name, $value, $SysPrefs->decseps );
1810 echo "</td></tr>\n";
1813 function themes_list_row($label, $name, $value=null)
1815 global $path_to_root;
1817 $path = $path_to_root.'/themes/';
1819 $themedir = opendir($path);
1820 while(false !== ($fname = readdir($themedir)))
1822 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1824 $themes[$fname] = $fname;
1829 echo "<tr><td class='label'>$label</td>\n<td>";
1830 echo array_selector( $name, $value, $themes );
1831 echo "</td></tr>\n";
1834 function pagesizes_list_row($label, $name, $value=null)
1839 foreach ($SysPrefs->pagesizes as $pz)
1842 echo "<tr><td class='label'>$label</td>\n<td>";
1843 echo array_selector( $name, $value, $items );
1844 echo "</td></tr>\n";
1847 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1849 global $systypes_array;
1851 // emove non-voidable transactions if needed
1852 $systypes = array_diff_key($systypes_array, array_flip($exclude));
1853 return array_selector($name, $value, $systypes,
1855 'spec_option'=> $spec_opt,
1856 'spec_id' => ALL_NUMERIC,
1857 'select_submit'=> $submit_on_change,
1863 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1866 echo "<td>$label</td>\n";
1868 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
1872 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1874 echo "<tr><td class='label'>$label</td>";
1875 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
1879 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1881 global $systypes_array;
1884 echo "<td>$label</td>\n";
1887 $items = $systypes_array;
1889 // exclude quotes, orders and dimensions
1890 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
1891 unset($items[$excl]);
1893 echo array_selector($name, $value, $items,
1895 'spec_option'=> _("All"),
1897 'select_submit'=> $submit_on_change,
1904 function cust_allocations_list_cells($label, $name, $selected=null)
1911 ALL_TEXT=>_("All Types"),
1912 '1'=> _("Sales Invoices"),
1913 '2'=> _("Overdue Invoices"),
1914 '3' => _("Payments"),
1915 '4' => _("Credit Notes"),
1916 '5' => _("Delivery Notes")
1918 echo array_selector($name, $selected, $allocs);
1922 function supp_allocations_list_cell($name, $selected=null)
1927 ALL_TEXT=>_("All Types"),
1928 '1'=> _("Invoices"),
1929 '2'=> _("Overdue Invoices"),
1930 '3' => _("Payments"),
1931 '4' => _("Credit Notes"),
1932 '5' => _("Overdue Credit Notes")
1934 echo array_selector($name, $selected, $allocs);
1938 function supp_transactions_list_cell($name, $selected=null)
1943 ALL_TEXT=>_("All Types"),
1945 '1'=> _("Invoices"),
1946 '2'=> _("Overdue Invoices"),
1947 '3' => _("Payments"),
1948 '4' => _("Credit Notes"),
1949 '5' => _("Overdue Credit Notes")
1952 echo array_selector($name, $selected, $allocs);
1956 function policy_list_cells($label, $name, $selected=null)
1961 echo array_selector($name, $selected,
1962 array( '' => _("Automatically put balance on back order"),
1963 'CAN' => _("Cancel any quantites not delivered")) );
1967 function policy_list_row($label, $name, $selected=null)
1969 echo "<tr><td class='label'>$label</td>";
1970 policy_list_cells(null, $name, $selected);
1974 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1979 echo array_selector($name, $selected,
1980 array( 'Return' => _("Items Returned to Inventory Location"),
1981 'WriteOff' => _("Items Written Off")),
1982 array( 'select_submit'=> $submit_on_change ) );
1986 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
1988 echo "<tr><td class='label'>$label</td>";
1989 credit_type_list_cells(null, $name, $selected, $submit_on_change);
1993 function number_list($name, $selected, $from, $to, $no_option=false)
1996 for ($i = $from; $i <= $to; $i++)
1999 return array_selector($name, $selected, $items,
2000 array( 'spec_option' => $no_option,
2001 'spec_id' => ALL_NUMERIC) );
2004 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2009 echo number_list($name, $selected, $from, $to, $no_option);
2013 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2015 echo "<tr><td class='label'>$label</td>";
2016 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2020 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2021 $submit_on_change=true)
2023 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2024 ." GROUP BY profile";
2025 $result = db_query($sql, 'cannot get all profile names');
2026 $profiles = array();
2027 while($myrow=db_fetch($result)) {
2028 $profiles[$myrow['profile']] = $myrow['profile'];
2033 echo "<td class='label'>$label</td>\n";
2036 echo array_selector($name, $selected_id, $profiles,
2037 array( 'select_submit'=> $submit_on_change,
2038 'spec_option'=>$spec_opt,
2042 echo "</td></tr>\n";
2045 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2047 static $printers; // query only once for page display
2050 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2051 $result = db_query($sql, 'cannot get all printers');
2052 $printers = array();
2053 while($myrow=db_fetch($result)) {
2054 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2057 return array_selector($name, $selected_id, $printers,
2058 array( 'select_submit'=> $submit_on_change,
2059 'spec_option'=>$spec_opt,
2064 //------------------------------------------------------------------------------------------------
2066 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2069 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2071 $sql .= " WHERE type=$type";
2073 return combo_input($name, $selected_id, $sql, 'id', 'description',
2076 'order' => 'description',
2077 'select_submit'=> $submit_on_change,
2083 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2086 echo "<td>$label</td>\n";
2088 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2092 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2094 echo "<tr><td class='label'>$label</td>";
2095 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2100 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2102 global $quick_actions;
2104 echo "<tr><td class='label'>$label</td><td>";
2105 echo array_selector($name, $selected_id, $quick_actions,
2107 'select_submit'=> $submit_on_change
2109 echo "</td></tr>\n";
2112 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2114 global $quick_entry_types;
2116 echo "<tr><td class='label'>$label</td><td>";
2117 echo array_selector($name, $selected_id, $quick_entry_types,
2119 'select_submit'=> $submit_on_change
2121 echo "</td></tr>\n";
2124 function record_status_list_row($label, $name) {
2125 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2128 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2130 global $class_types;
2132 echo "<tr><td class='label'>$label</td><td>";
2133 echo array_selector($name, $selected_id, $class_types,
2135 'select_submit'=> $submit_on_change
2137 echo "</td></tr>\n";
2140 //------------------------------------------------------------------------------------------------
2142 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2143 $show_inactive = false)
2146 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2148 return combo_input($name, $selected_id, $sql, 'id', 'description',
2150 'spec_option'=>$new_item ? _("New role") : false,
2152 'select_submit'=> $submit_on_change,
2153 'show_inactive' => $show_inactive
2157 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2158 $show_inactive = false)
2161 echo "<td>$label</td>\n";
2163 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2167 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2168 $show_inactive = false)
2170 echo "<tr><td class='label'>$label</td>";
2171 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2175 function tab_list_row($label, $name, $selected_id=null)
2177 global $installed_extensions;
2180 foreach ($_SESSION['App']->applications as $app) {
2181 $tabs[$app->id] = access_string($app->name, true);
2184 echo "<td class='label'>$label</td><td>\n";
2185 echo array_selector($name, $selected_id, $tabs);
2186 echo "</td></tr>\n";
2189 //-----------------------------------------------------------------------------------------------
2191 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2194 global $path_to_root;
2195 include_once($path_to_root . "/admin/db/tags_db.inc");
2196 $results = get_tags($type, $all);
2198 while ($tag = db_fetch($results))
2199 $tags[$tag['id']] = $tag['name'];
2201 if (!isset($tags)) {
2202 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2205 return array_selector($name, null, $tags,
2208 'height' => $height,
2209 'spec_option'=> $spec_opt,
2214 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2217 echo "<td>$label</td>\n";
2219 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2224 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2226 echo "<tr><td class='label'>$label</td>";
2227 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2231 //---------------------------------------------------------------------------------------------
2232 // List of sets of active extensions
2234 function extset_list($name, $value=null, $submit_on_change=false)
2236 global $db_connections;
2239 foreach ($db_connections as $comp)
2240 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2241 return array_selector( $name, $value, $items,
2243 'spec_option'=> _("Available and/or installed"),
2245 'select_submit'=> $submit_on_change,
2250 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2253 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2258 if (@$filter['class']) {
2259 $where[] = 'type='.db_escape($filter['class']);
2262 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2263 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2264 if (@$filter['multi']) { // contact category selector for person
2268 return combo_input($name, $selected_id, $sql, 'id', 'name',
2271 'height' => $multi ? 5:1,
2272 'category' => $groups,
2273 'select_submit'=> $submit_on_change,
2279 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2281 echo "<tr><td class='label'>$label</td><td>";
2282 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2283 echo "</td></tr>\n";
2286 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2288 global $pterm_types;
2290 echo "<tr><td class='label'>$label</td><td>";
2291 echo array_selector($name, $selected_id, $pterm_types,
2293 'select_submit'=> $submit_on_change
2295 echo "</td></tr>\n";
2298 function coa_list_row($label, $name, $value=null)
2300 global $path_to_root, $installed_extensions;
2302 $path = $path_to_root.'/sql/';
2304 $sqldir = opendir($path);
2305 while (false !== ($fname = readdir($sqldir)))
2307 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2309 $ext = array_search_value($fname, $installed_extensions, 'sql');
2311 $descr = $ext['name'];
2312 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2313 $descr = _("Standard new company American COA (4 digit)");
2314 } elseif ($fname == 'en_US-demo.sql') {
2315 $descr = _("Standard American COA (4 digit) with demo data");
2319 $coas[$fname] = $descr;
2324 echo "<tr><td class='label'>$label</td>\n<td>";
2325 echo array_selector( $name, $value, $coas );
2326 echo "</td></tr>\n";
2329 function payment_services($name)
2331 global $payment_services;
2333 $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2335 return array_selector($name, null, $services, array(
2336 'spec_option'=> _("No payment Link"),
2341 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2343 global $tax_algorithms;
2345 return array_selector($name, $value, $tax_algorithms,
2347 'select_submit'=> $submit_on_change,
2353 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2356 echo "<td>$label</td>\n";
2358 echo tax_algorithm_list($name, $value, $submit_on_change);
2362 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2364 echo "<tr><td class='label'>$label</td>";
2365 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2368 //----------------------------------------------------------------------------------------------
2370 function subledger_list($name, $account, $selected_id=null)
2373 $type = is_subledger_account($account);
2378 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2380 .TB_PREF."debtors_master d,"
2381 .TB_PREF."cust_branch c
2382 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2384 $sql = "SELECT supplier_id as id, supp_ref as name
2386 .TB_PREF."suppliers s
2387 WHERE s.payable_account=".db_escape($account);
2389 $mode = get_company_pref('no_customer_list');
2391 return combo_input($name, $selected_id, $sql, 'id', 'name',
2399 function subledger_list_cells($label, $name, $account, $selected_id=null)
2402 echo "<td>$label</td>\n";
2404 echo subledger_list($name, $account, $selected_id);
2408 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2409 $submit_on_change=false, $show_inactive=false, $editkey = false)
2411 echo "<tr><td class='label'>$label</td><td nowrap>";
2412 echo subledger_list($name, $account, $selected_id);
2413 echo "</td>\n</tr>\n";
2416 function accounts_type_list_row($label, $name, $selected_id=null)
2420 echo "<td class='label'>$label</td>\n";
2422 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2423 echo array_selector($name, $selected_id, $sel);
2424 echo "</td></tr>\n";
2427 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2430 $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2433 echo "<td>$label</td>\n";
2436 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2438 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2440 'order' => 'real_name',
2441 'select_submit'=> $submit_on_change,