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
64 'editlink' => false // link to entity entry/edit page (optional)
66 // ------ merge options with defaults ----------
68 $opts = array_merge($opts, $options);
69 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
71 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
72 // select content filtered by search field:
73 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
74 // select set by select content field
75 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
77 $select_submit = $opts['select_submit'];
78 $spec_id = $opts['spec_id'];
79 $spec_option = $opts['spec_option'];
80 if ($opts['type'] == 0) {
83 } elseif($opts['type'] == 1) {
91 $disabled = $opts['disabled'] ? "disabled" : '';
92 $multi = $opts['multi'];
94 if(!count($opts['search'])) {
95 $opts['search'] = array($by_id ? $valfield : $namefield);
97 if ($opts['sel_hint'] === null)
98 $opts['sel_hint'] = $by_id || $search_box==false ?
99 '' : _('Press Space tab for search pattern entry');
101 if ($opts['box_hint'] === null)
102 $opts['box_hint'] = $search_box && $search_submit != false ?
103 ($by_id ? _('Enter code fragment to search or * for all')
104 : _('Enter description fragment to search or * for all')) :'';
106 if ($selected_id == null) {
107 $selected_id = get_post($name, (string)$opts['default']);
109 if(!is_array($selected_id))
110 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
112 $txt = get_post($search_box);
115 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
116 if ($by_id) $txt = $_POST[$name];
119 $Ajax->activate('_page_body');
121 $Ajax->activate($name);
123 if (isset($_POST[$search_button])) {
125 $Ajax->activate('_page_body');
127 $Ajax->activate($name);
130 // search related sql modifications
132 $rel = "rel='$search_box'"; // set relation to list
133 if ($opts['search_submit']) {
134 if (isset($_POST[$search_button])) {
135 $selected_id = array(); // ignore selected_id while search
137 $Ajax->activate('_page_body');
139 $Ajax->activate($name);
142 if ($spec_option === false && $selected_id == array())
145 $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id));
150 foreach($opts['search'] as $i=> $s)
151 $opts['search'][$i] = $s . " LIKE "
152 .db_escape(($class=='combo3' ? '' : '%').$txt.'%');
153 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
159 if (count($opts['where'])) {
160 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
161 $where .= '('. implode($opts['where'], ' AND ') . ')';
162 $group_pos = strpos($sql, 'GROUP BY');
164 $group = substr($sql, $group_pos);
165 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
170 if ($opts['order'] != false) {
171 if (!is_array($opts['order']))
172 $opts['order'] = array($opts['order']);
173 $sql .= ' ORDER BY '.implode(',',$opts['order']);
177 // ------ make selector ----------
178 $selector = $first_opt = '';
183 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
184 //if($name=='curr_default') display_notification($opts['search_submit']);
185 if($result = db_query($sql)) {
186 while ($contact_row = db_fetch($result)) {
187 $value = $contact_row[0];
188 $descr = $opts['format']==null ? $contact_row[1] :
189 call_user_func($opts['format'], $contact_row);
191 if (get_post($search_button) && ($txt == $value)) {
192 $selected_id[] = $value;
195 if (in_array((string)$value, $selected_id, true)) {
198 $edit = $opts['editable'] && $contact_row['editable']
199 && (@$_POST[$search_box] == $value)
200 ? $contact_row[1] : false; // get non-formatted description
202 break; // selected field is editable - abandon list construction
204 // show selected option even if inactive
205 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
208 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
210 if ($first_id === false) {
214 $cat = $contact_row[$opts['category']];
215 if ($opts['category'] !== false && $cat != $lastcat){
217 $selector .= "</optgroup>";
218 $selector .= "<optgroup label='".$cat."'>\n";
221 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
224 $selector .= "</optgroup>";
225 db_free_result($result);
228 // Prepend special option.
229 if ($spec_option !== false) { // if special option used - add it
230 $first_id = $spec_id;
231 $first_opt = $spec_option;
233 // if($first_id !== false) {
234 $sel = $found===false ? 'selected' : '';
235 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
236 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
240 if ($found===false) {
241 $selected_id = array($first_id);
244 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
246 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
247 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
248 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
249 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
251 if ($by_id && ($search_box != false || $opts['editable']) ) {
252 // on first display show selector list
253 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
254 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
255 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
256 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
257 set_focus($name.'_text'); // prevent lost focus
258 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
259 set_focus($name); // prevent lost focus
260 if (!$opts['editable'])
262 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
265 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
267 // span for select list/input field update
268 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
270 // if selectable or editable list is used - add select button
271 if ($select_submit != false || $search_button) {
272 // button class selects form reload/ajax selector update
273 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
274 (fallback_mode() ? '' : 'display:none;'),
275 '_'.$name.'_update')."\n";
277 // ------ make combo ----------
279 if ($search_box != false) {
280 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
281 $opts['size']."' maxlength='".$opts['max'].
282 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
283 .$opts['box_hint']."'"
284 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
286 if ($search_submit != false || $opts['editable']) {
287 $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
288 (fallback_mode() ? '' : 'display:none;'),
289 $search_submit ? $search_submit : "_{$name}_button")."\n";
292 default_focus(($search_box && $by_id) ? $search_box : $name);
294 if ($opts['editlink'])
295 $selector .= ' '.$opts['editlink'];
297 if ($search_box && $opts['cells'])
298 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
300 $str = $edit_entry.$selector;
306 Returns true if selector $name is subject to update.
308 function list_updated($name)
310 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
312 //----------------------------------------------------------------------------------------------
313 // Universal array combo generator
314 // $items is array of options 'value' => 'description'
315 // Options is reduced set of combo_selector options and is merged with defaults.
317 function array_selector($name, $selected_id, $items, $options=null)
321 $opts = array( // default options
322 'spec_option'=>false, // option text or false
323 'spec_id' => 0, // option id
324 'select_submit' => false, //submit on select: true/false
325 'async' => true, // select update via ajax (true) vs _page_body reload
326 'default' => '', // default value when $_POST is not set
327 'multi'=>false, // multiple select
328 // search box parameters
329 'height' => false, // number of lines in select box
333 // ------ merge options with defaults ----------
335 $opts = array_merge($opts, $options);
336 $select_submit = $opts['select_submit'];
337 $spec_id = $opts['spec_id'];
338 $spec_option = $opts['spec_option'];
339 $disabled = $opts['disabled'] ? "disabled" : '';
340 $multi = $opts['multi'];
342 if ($selected_id == null) {
343 $selected_id = get_post($name, $opts['default']);
345 if(!is_array($selected_id))
346 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
348 if (isset($_POST[ '_'.$name.'_update'])) {
350 $Ajax->activate('_page_body');
352 $Ajax->activate($name);
355 // ------ make selector ----------
356 $selector = $first_opt = '';
359 //if($name=='SelectStockFromList') display_error($sql);
360 foreach($items as $value=>$descr) {
362 if (in_array((string)$value, $selected_id, true)) {
366 if ($first_id === false) {
370 $selector .= "<option $sel value='$value'>$descr</option>\n";
373 if ($first_id!==false) {
374 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
376 // Prepend special option.
377 if ($spec_option !== false) { // if special option used - add it
378 $first_id = $spec_id;
379 $first_opt = $spec_option;
380 $sel = $found===false ? 'selected' : '';
381 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
385 if ($found===false) {
386 $selected_id = array($first_id);
388 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
390 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
391 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
392 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
393 . $opts['sel_hint']."'>".$selector."</select>\n";
395 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
397 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
399 if ($select_submit != false) { // if submit on change is used - add select button
400 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
401 (fallback_mode() ? '' : 'display:none;'),
402 '_'.$name.'_update')."\n";
404 default_focus($name);
408 //----------------------------------------------------------------------------------------------
410 function _format_add_curr($row)
412 static $company_currency;
414 if ($company_currency == null)
416 $company_currency = get_company_currency();
418 return $row[1] . ($row[2] == $company_currency ?
419 '' : (" - " . $row[2]));
422 function add_edit_combo($type)
424 global $path_to_root, $popup_editors, $SysPrefs;
426 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
429 $theme_path = $path_to_root . '/themes/' . user_theme();
431 $key = $popup_editors[$type][1];
432 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
433 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
434 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
437 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
438 $all=false, $editkey = false)
441 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
443 $mode = get_company_pref('no_supplier_list');
446 set_editor('supplier', $name, $editkey);
448 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
450 'format' => '_format_add_curr',
451 'order' => array('supp_ref'),
452 'search_box' => $mode!=0,
454 'search' => array("supp_ref","supp_name","gst_no"),
455 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
456 'spec_id' => ALL_TEXT,
457 'select_submit'=> $submit_on_change,
459 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
460 _('Select supplier'),
461 'show_inactive'=>$all,
462 'editlink' => $editkey ? add_edit_combo('supplier') : false
467 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
468 $submit_on_change=false, $all=false, $editkey = false)
471 echo "<td>$label</td><td>\n";
472 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
477 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
478 $submit_on_change=false, $all=false, $editkey = false)
480 echo "<tr><td class='label'>$label</td><td>";
481 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
485 //----------------------------------------------------------------------------------------------
487 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
488 $show_inactive=false, $editkey = false)
491 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
493 $mode = get_company_pref('no_customer_list');
496 set_editor('customer', $name, $editkey);
498 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
500 'format' => '_format_add_curr',
501 'order' => array('debtor_ref'),
502 'search_box' => $mode!=0,
505 'search' => array("debtor_ref","name","tax_id"),
506 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
507 'spec_id' => ALL_TEXT,
508 'select_submit'=> $submit_on_change,
510 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
511 _('Select customer'),
512 'show_inactive' => $show_inactive,
513 'editlink' => $editkey ? add_edit_combo('customer') : false
518 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
519 $submit_on_change=false, $show_inactive=false, $editkey = false)
522 echo "<td>$label</td>\n";
524 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
525 $show_inactive, $editkey);
529 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
530 $submit_on_change=false, $show_inactive=false, $editkey = false)
533 echo "<tr><td class='label'>$label</td><td nowrap>";
534 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
535 $show_inactive, $editkey);
536 echo "</td>\n</tr>\n";
539 //------------------------------------------------------------------------------------------------
541 function customer_branches_list($customer_id, $name, $selected_id=null,
542 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
545 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
546 WHERE debtor_no=" . db_escape($customer_id)." ";
549 set_editor('branch', $name, $editkey);
551 $where = $enabled ? array("inactive = 0") : array();
552 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
555 'order' => array('branch_ref'),
556 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
557 'spec_id' => ALL_TEXT,
558 'select_submit'=> $submit_on_change,
559 'sel_hint' => _('Select customer branch'),
560 'editlink' => $editkey ? add_edit_combo('branch') : false
564 //------------------------------------------------------------------------------------------------
566 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
567 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
570 echo "<td>$label</td>\n";
572 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
573 $submit_on_change, $editkey);
577 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
578 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
580 echo "<tr><td class='label'>$label</td>";
581 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
582 $all_option, $enabled, $submit_on_change, $editkey);
586 //------------------------------------------------------------------------------------------------
588 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
591 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
593 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
595 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
596 'spec_id' => ALL_TEXT,
597 'select_submit'=> $submit_on_change
601 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
604 echo "<td>$label</td>\n";
606 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
610 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
612 echo "<tr><td class='label'>$label</td>";
613 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
617 //-----------------------------------------------------------------------------------------------
619 function currencies_list($name, $selected_id=null, $submit_on_change=false)
621 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
623 // default to the company currency
624 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
626 'select_submit'=> $submit_on_change,
627 'default' => get_company_currency(),
632 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
635 echo "<td>$label</td>\n";
637 echo currencies_list($name, $selected_id, $submit_on_change);
641 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
643 echo "<tr><td class='label'>$label</td>";
644 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
648 //---------------------------------------------------------------------------------------------------
650 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
653 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
655 // default to the company current fiscal year
657 return combo_input($name, $selected_id, $sql, 'id', '',
660 'default' => get_company_pref('f_year'),
661 'format' => '_format_fiscalyears',
662 'select_submit'=> $submit_on_change,
667 function _format_fiscalyears($row)
669 return sql2date($row[1]) . " - " . sql2date($row[2])
670 . " " . ($row[3] ? _('Closed') : _('Active'));
673 function fiscalyears_list_cells($label, $name, $selected_id=null)
676 echo "<td>$label</td>\n";
678 echo fiscalyears_list($name, $selected_id);
682 function fiscalyears_list_row($label, $name, $selected_id=null)
684 echo "<tr><td class='label'>$label</td>";
685 fiscalyears_list_cells(null, $name, $selected_id);
688 //------------------------------------------------------------------------------------
690 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
691 $submit_on_change=false, $showclosed=false, $showtype=1)
693 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
696 'order' => 'reference',
697 'spec_option'=>$no_option ? $showname : false,
699 'select_submit'=> $submit_on_change,
704 $options['where'][] = "closed=0";
706 $options['where'][] = "type_=".db_escape($showtype);
708 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
711 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
712 $showclosed=false, $showtype=0, $submit_on_change=false)
715 echo "<td>$label</td>\n";
717 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
721 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
722 $showclosed=false, $showtype=0, $submit_on_change=false)
724 echo "<tr><td class='label'>$label</td>";
725 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
726 $showclosed, $showtype, $submit_on_change);
730 //---------------------------------------------------------------------------------------------------
732 function stock_items_list($name, $selected_id=null, $all_option=false,
733 $submit_on_change=false, $opts=array(), $editkey = false)
736 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
737 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
740 set_editor('item', $name, $editkey);
742 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
745 'format' => '_format_stock_items',
746 'spec_option' => $all_option===true ? _("All Items") : $all_option,
747 'spec_id' => ALL_TEXT,
748 'search_box' => true,
749 'search' => array("stock_id", "c.description","s.description"),
750 'search_submit' => get_company_pref('no_item_list')!=0,
752 'select_submit'=> $submit_on_change,
754 'order' => array('c.description','stock_id'),
755 'editlink' => $editkey ? add_edit_combo('item') : false,
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, $opts= array())
771 echo "<td>$label</td>\n";
772 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
773 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $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);
2369 function refline_list($name, $type, $value=null, $spec_option=false)
2371 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2376 $where = array('`trans_type`='.db_escape($type));
2378 return combo_input($name, $value, $sql, 'id', 'prefix',
2380 'order'=>array('prefix'),
2381 'spec_option' => $spec_option,
2385 'select_submit' => true,
2390 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2394 echo "<td class='label'>$label</td>\n";
2397 echo refline_list($name, $type, $selected_id, $spec_option);
2398 echo "</td></tr>\n";
2402 //----------------------------------------------------------------------------------------------
2404 function subledger_list($name, $account, $selected_id=null)
2407 $type = is_subledger_account($account);
2412 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2414 .TB_PREF."debtors_master d,"
2415 .TB_PREF."cust_branch c
2416 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2418 $sql = "SELECT supplier_id as id, supp_ref as name
2420 .TB_PREF."suppliers s
2421 WHERE s.payable_account=".db_escape($account);
2423 $mode = get_company_pref('no_customer_list');
2425 return combo_input($name, $selected_id, $sql, 'id', 'name',
2433 function subledger_list_cells($label, $name, $account, $selected_id=null)
2436 echo "<td>$label</td>\n";
2438 echo subledger_list($name, $account, $selected_id);
2442 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2443 $submit_on_change=false, $show_inactive=false, $editkey = false)
2445 echo "<tr><td class='label'>$label</td><td nowrap>";
2446 echo subledger_list($name, $account, $selected_id);
2447 echo "</td>\n</tr>\n";
2450 function accounts_type_list_row($label, $name, $selected_id=null)
2454 echo "<td class='label'>$label</td>\n";
2456 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2457 echo array_selector($name, $selected_id, $sel);
2458 echo "</td></tr>\n";
2461 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2464 $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2467 echo "<td>$label</td>\n";
2470 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2472 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2474 'order' => 'real_name',
2475 'select_submit'=> $submit_on_change,
2482 function collations_list_row($label, $name, $selected_id=null)
2484 global $supported_collations;
2488 echo "<td class='label'>$label</td>\n";
2491 echo array_selector($name, $selected_id, $supported_collations,
2492 array('select_submit'=> false) );
2493 echo "</td></tr>\n";