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($result = db_query($sql)) {
184 while ($contact_row = db_fetch($result)) {
185 $value = $contact_row[0];
186 $descr = $opts['format']==null ? $contact_row[1] :
187 call_user_func($opts['format'], $contact_row);
189 if (get_post($search_button) && ($txt == $value)) {
190 $selected_id[] = $value;
193 if (in_array((string)$value, $selected_id, true)) {
196 $edit = $opts['editable'] && $contact_row['editable']
197 && (@$_POST[$search_box] == $value)
198 ? $contact_row[1] : false; // get non-formatted description
200 break; // selected field is editable - abandon list construction
202 // show selected option even if inactive
203 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
206 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
208 if ($first_id === false) {
212 $cat = $contact_row[$opts['category']];
213 if ($opts['category'] !== false && $cat != $lastcat){
215 $selector .= "</optgroup>";
216 $selector .= "<optgroup label='".$cat."'>\n";
219 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
222 $selector .= "</optgroup>";
223 db_free_result($result);
226 // Prepend special option.
227 if ($spec_option !== false) { // if special option used - add it
228 $first_id = $spec_id;
229 $first_opt = $spec_option;
230 $sel = $found===false ? 'selected' : '';
231 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
232 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
236 if ($found===false) {
237 $selected_id = array($first_id);
240 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
242 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
243 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
244 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
245 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
247 if ($by_id && ($search_box != false || $opts['editable']) ) {
248 // on first display show selector list
249 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
250 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
251 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
252 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
253 set_focus($name.'_text'); // prevent lost focus
254 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
255 set_focus($name); // prevent lost focus
256 if (!$opts['editable'])
258 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
261 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
263 // span for select list/input field update
264 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
266 // if selectable or editable list is used - add select button
267 if ($select_submit != false || $search_button) {
268 // button class selects form reload/ajax selector update
269 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
270 (fallback_mode() ? '' : 'display:none;'),
271 '_'.$name.'_update')."\n";
273 // ------ make combo ----------
275 if ($search_box != false) {
276 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
277 $opts['size']."' maxlength='".$opts['max'].
278 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
279 .$opts['box_hint']."'"
280 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
282 if ($search_submit != false || $opts['editable']) {
283 $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
284 (fallback_mode() ? '' : 'display:none;'),
285 $search_submit ? $search_submit : "_{$name}_button")."\n";
288 default_focus(($search_box && $by_id) ? $search_box : $name);
290 if ($opts['editlink'])
291 $selector .= ' '.$opts['editlink'];
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 foreach($items as $value=>$descr) {
357 if (in_array((string)$value, $selected_id, true)) {
361 if ($first_id === false) {
365 $selector .= "<option $sel value='$value'>$descr</option>\n";
368 if ($first_id!==false) {
369 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
371 // Prepend special option.
372 if ($spec_option !== false) { // if special option used - add it
373 $first_id = $spec_id;
374 $first_opt = $spec_option;
375 $sel = $found===false ? 'selected' : '';
376 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
380 if ($found===false) {
381 $selected_id = array($first_id);
383 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
385 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
386 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
387 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
388 . $opts['sel_hint']."'>".$selector."</select>\n";
390 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
392 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
394 if ($select_submit != false) { // if submit on change is used - add select button
395 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
396 (fallback_mode() ? '' : 'display:none;'),
397 '_'.$name.'_update')."\n";
399 default_focus($name);
403 //----------------------------------------------------------------------------------------------
404 function array_selector_row($label, $name, $selected_id, $items, $options=null)
406 echo "<tr><td class='label'>$label</td>\n<td>";
407 echo array_selector($name, $selected_id, $items, $options);
411 //----------------------------------------------------------------------------------------------
412 function _format_add_curr($row)
414 static $company_currency;
416 if ($company_currency == null)
418 $company_currency = get_company_currency();
420 return $row[1] . ($row[2] == $company_currency ?
421 '' : (" - " . $row[2]));
424 function add_edit_combo($type)
426 global $path_to_root, $popup_editors, $SysPrefs;
428 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
431 $theme_path = $path_to_root . '/themes/' . user_theme();
433 $key = $popup_editors[$type][1];
434 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
435 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
436 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
439 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
440 $all=false, $editkey = false)
443 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
445 $mode = get_company_pref('no_supplier_list');
448 set_editor('supplier', $name, $editkey);
450 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
452 'format' => '_format_add_curr',
453 'order' => array('supp_ref'),
454 'search_box' => $mode!=0,
456 'search' => array("supp_ref","supp_name","gst_no"),
457 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
458 'spec_id' => ALL_TEXT,
459 'select_submit'=> $submit_on_change,
461 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
462 _('Select supplier'),
463 'show_inactive'=>$all,
464 'editlink' => $editkey ? add_edit_combo('supplier') : false
469 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
470 $submit_on_change=false, $all=false, $editkey = false)
473 echo "<td>$label</td><td>\n";
474 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
479 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
480 $submit_on_change=false, $all=false, $editkey = false)
482 echo "<tr><td class='label'>$label</td><td>";
483 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
487 //----------------------------------------------------------------------------------------------
489 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
490 $show_inactive=false, $editkey = false)
493 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
495 $mode = get_company_pref('no_customer_list');
498 set_editor('customer', $name, $editkey);
500 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
502 'format' => '_format_add_curr',
503 'order' => array('debtor_ref'),
504 'search_box' => $mode!=0,
507 'search' => array("debtor_ref","name","tax_id"),
508 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
509 'spec_id' => ALL_TEXT,
510 'select_submit'=> $submit_on_change,
512 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
513 _('Select customer'),
514 'show_inactive' => $show_inactive,
515 'editlink' => $editkey ? add_edit_combo('customer') : false
520 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
521 $submit_on_change=false, $show_inactive=false, $editkey = false)
524 echo "<td>$label</td>\n";
526 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
527 $show_inactive, $editkey);
531 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
532 $submit_on_change=false, $show_inactive=false, $editkey = false)
535 echo "<tr><td class='label'>$label</td><td nowrap>";
536 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
537 $show_inactive, $editkey);
538 echo "</td>\n</tr>\n";
541 //------------------------------------------------------------------------------------------------
543 function customer_branches_list($customer_id, $name, $selected_id=null,
544 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
547 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
548 WHERE debtor_no=" . db_escape($customer_id)." ";
551 set_editor('branch', $name, $editkey);
553 $where = $enabled ? array("inactive = 0") : array();
554 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
557 'order' => array('branch_ref'),
558 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
559 'spec_id' => ALL_TEXT,
560 'select_submit'=> $submit_on_change,
561 'sel_hint' => _('Select customer branch'),
562 'editlink' => $editkey ? add_edit_combo('branch') : false
566 //------------------------------------------------------------------------------------------------
568 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
569 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
572 echo "<td>$label</td>\n";
574 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
575 $submit_on_change, $editkey);
579 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
580 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
582 echo "<tr><td class='label'>$label</td>";
583 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
584 $all_option, $enabled, $submit_on_change, $editkey);
588 //------------------------------------------------------------------------------------------------
590 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
593 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations WHERE fixed_asset=".(int)$fixed_asset;
595 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
597 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
598 'spec_id' => ALL_TEXT,
599 'select_submit'=> $submit_on_change
603 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
606 echo "<td>$label</td>\n";
608 echo locations_list($name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
612 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
614 echo "<tr><td class='label'>$label</td>";
615 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
619 //-----------------------------------------------------------------------------------------------
621 function currencies_list($name, $selected_id=null, $submit_on_change=false)
623 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
625 // default to the company currency
626 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
628 'select_submit'=> $submit_on_change,
629 'default' => get_company_currency(),
634 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
637 echo "<td>$label</td>\n";
639 echo currencies_list($name, $selected_id, $submit_on_change);
643 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
645 echo "<tr><td class='label'>$label</td>";
646 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
650 //---------------------------------------------------------------------------------------------------
652 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
655 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
657 // default to the company current fiscal year
659 return combo_input($name, $selected_id, $sql, 'id', '',
662 'default' => get_company_pref('f_year'),
663 'format' => '_format_fiscalyears',
664 'select_submit'=> $submit_on_change,
669 function _format_fiscalyears($row)
671 return sql2date($row[1]) . " - " . sql2date($row[2])
672 . " " . ($row[3] ? _('Closed') : _('Active'));
675 function fiscalyears_list_cells($label, $name, $selected_id=null)
678 echo "<td>$label</td>\n";
680 echo fiscalyears_list($name, $selected_id);
684 function fiscalyears_list_row($label, $name, $selected_id=null)
686 echo "<tr><td class='label'>$label</td>";
687 fiscalyears_list_cells(null, $name, $selected_id);
690 //------------------------------------------------------------------------------------
692 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
693 $submit_on_change=false, $showclosed=false, $showtype=1)
695 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
698 'order' => 'reference',
699 'spec_option'=>$no_option ? $showname : false,
701 'select_submit'=> $submit_on_change,
706 $options['where'][] = "closed=0";
708 $options['where'][] = "type_=".db_escape($showtype);
710 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
713 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
714 $showclosed=false, $showtype=0, $submit_on_change=false)
717 echo "<td>$label</td>\n";
719 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
723 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
724 $showclosed=false, $showtype=0, $submit_on_change=false)
726 echo "<tr><td class='label'>$label</td>";
727 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
728 $showclosed, $showtype, $submit_on_change);
732 //---------------------------------------------------------------------------------------------------
734 function stock_items_list($name, $selected_id=null, $all_option=false,
735 $submit_on_change=false, $opts=array(), $editkey = false)
738 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
739 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
741 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
742 $sql .= " AND mb_flag='F'";
744 $sql .= " AND mb_flag!='F'";
747 set_editor('item', $name, $editkey);
749 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
752 'format' => '_format_stock_items',
753 'spec_option' => $all_option===true ? _("All Items") : $all_option,
754 'spec_id' => ALL_TEXT,
755 'search_box' => true,
756 'search' => array("stock_id", "c.description","s.description"),
757 'search_submit' => get_company_pref('no_item_list')!=0,
759 'select_submit'=> $submit_on_change,
761 'order' => array('c.description','stock_id'),
762 'editlink' => $editkey ? add_edit_combo('item') : false,
769 function _format_stock_items($row)
771 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
774 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
775 $submit_on_change=false, $all=false, $editkey = false, $opts= array())
777 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
778 $editor_item = 'fa_item';
780 $editor_item = 'item';
783 // set_editor($editor_item, $name, $editkey);
786 echo "<td>$label</td>\n";
789 // $opts = array_merge($options, array('cells'=>true, 'show_inactive'=>$all, 'new_icon' => $editkey ? 'item' : false));
791 // echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, $opts);
793 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
794 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey);
798 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
801 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
805 //---------------------------------------------------------------------------------------------------
807 // Select item via foreign code.
809 function sales_items_list($name, $selected_id=null, $all_option=false,
810 $submit_on_change=false, $type='', $opts=array())
813 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
814 i.inactive, if(count(*)>1, '0', s.editable) as editable
816 ".TB_PREF."stock_master s,
817 ".TB_PREF."item_codes i
819 ".TB_PREF."stock_category c
820 ON i.category_id=c.category_id
821 WHERE i.stock_id=s.stock_id
825 if ($type == 'local') { // exclude foreign codes
826 $sql .= " AND !i.is_foreign";
827 } elseif ($type == 'kits') { // sales kits
828 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
830 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
831 $sql .= " GROUP BY i.item_code";
833 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
836 'format' => '_format_stock_items',
837 'spec_option' => $all_option===true ? _("All Items") : $all_option,
838 'spec_id' => ALL_TEXT,
839 'search_box' => true,
840 'search' => array("i.item_code", "c.description", "i.description"),
841 'search_submit' => get_company_pref('no_item_list')!=0,
843 'select_submit'=> $submit_on_change,
845 'order' => array('c.description','i.item_code'),
851 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
854 set_editor('item', $name, $editkey);
857 echo "<td>$label</td>\n";
858 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
859 '', array('cells'=>true));
862 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
864 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
865 'kits', array('cells'=>false, 'editable' => false));
868 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
872 echo "<td class='label'>$label</td>\n";
874 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
875 'local', array('cells'=>false, 'editable' => false));
878 //------------------------------------------------------------------------------------
880 function stock_manufactured_items_list($name, $selected_id=null,
881 $all_option=false, $submit_on_change=false)
883 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
884 array('where'=>array("mb_flag= 'M'")));
887 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
888 $all_option=false, $submit_on_change=false)
891 echo "<td>$label</td>\n";
893 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
897 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
898 $all_option=false, $submit_on_change=false)
900 echo "<tr><td class='label'>$label</td>";
901 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
904 //------------------------------------------------------------------------------------
906 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
907 $all_option=false, $submit_on_change=false, $editkey = false)
909 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
910 array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
913 function stock_component_items_list_cells($label, $name, $parent_stock_id,
914 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
917 echo "<td>$label</td>\n";
918 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
919 array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
922 //------------------------------------------------------------------------------------
924 function stock_costable_items_list($name, $selected_id=null,
925 $all_option=false, $submit_on_change=false)
927 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
928 array('where'=>array("mb_flag!='D'")));
931 function stock_costable_items_list_cells($label, $name, $selected_id=null,
932 $all_option=false, $submit_on_change=false)
935 echo "<td>$label</td>\n";
936 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
937 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
940 //------------------------------------------------------------------------------------
941 function stock_purchasable_items_list($name, $selected_id=null,
942 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
944 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
945 array('where'=>array("NOT no_purchase"),
946 'show_inactive'=>$all), $editkey);
949 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
951 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
952 $all_option=false, $submit_on_change=false, $editkey=false)
955 echo "<td>$label</td>\n";
956 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
957 array('where'=>array("NOT no_purchase"),
959 'cells'=>true), $editkey);
962 //------------------------------------------------------------------------------------
964 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
970 echo "<td class='label'>$label</td>\n";
973 echo array_selector($name, $selected_id, $stock_types,
975 'select_submit'=> true,
976 'disabled' => !$enabled) );
980 function stock_units_list_row($label, $name, $value=null, $enabled=true)
982 $result = get_all_item_units();
985 echo "<td class='label'>$label</td>\n";
988 while($unit = db_fetch($result))
989 $units[$unit['abbr']] = $unit['name'];
991 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
996 //------------------------------------------------------------------------------------
998 function stock_purchasable_fa_list_cells($label, $name, $selected_id=null, $all_option=false,
999 $submit_on_change=false, $all=false, $editkey = false, $exclude_items = array())
1001 // Check if a fixed asset has been bought.
1002 $where_opts[] = "stock_id NOT IN
1003 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1005 // exclude items currently on the order.
1006 foreach($exclude_items as $item) {
1007 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1009 $where_opts[] = "mb_flag='F'";
1011 echo stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, $all, $editkey,
1012 array('fixed_asset' => true, 'where' => $where_opts));
1015 function stock_disposable_fa_list($name, $selected_id=null,
1016 $all_option=false, $submit_on_change=false)
1018 // Check if a fixed asset has been bought....
1019 $where_opts[] = "stock_id IN
1020 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1021 // ...but has not been disposed or sold already.
1022 $where_opts[] = "stock_id NOT IN
1023 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1025 $where_opts[] = "mb_flag='F'";
1027 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1028 array('fixed_asset' => true, 'where' => $where_opts));
1031 function stock_disposable_fa_list_cells($label, $name, $selected_id=null,
1032 $all_option=false, $submit_on_change=false, $exclude_items = array())
1034 // Check if a fixed asset has been bought....
1035 $where_opts[] = "stock_id IN
1036 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1037 // ...but has not been disposed or sold already.
1038 $where_opts[] = "stock_id NOT IN
1039 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1041 $where_opts[] = "mb_flag='F'";
1043 foreach($exclude_items as $item) {
1044 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1048 echo "<td>$label</td>\n";
1049 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1050 array('fixed_asset' => true, 'cells'=>true, 'where' => $where_opts));
1053 function stock_depreciable_fa_list_cells($label, $name, $selected_id=null,
1054 $all_option=false, $submit_on_change=false)
1057 // Check if a fixed asset has been bought....
1058 $where_opts[] = "stock_id IN
1059 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1060 // ...but has not been disposed or sold already.
1061 $where_opts[] = "stock_id NOT IN
1062 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1064 $year = get_current_fiscalyear();
1065 $y = date('Y', strtotime($year['end']));
1067 // check if current fiscal year
1068 $where_opts[] = "depreciation_date < '".$y."-12-01'";
1069 $where_opts[] = "depreciation_date >= '".($y-1)."-12-01'";
1071 $where_opts[] = "material_cost > 0";
1072 $where_opts[] = "mb_flag='F'";
1075 echo "<td>$label</td>\n";
1076 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1077 array('fixed_asset' => true, 'where' => $where_opts, 'cells'=>true));
1080 //------------------------------------------------------------------------------------
1082 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
1084 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
1086 return combo_input($name, $selected_id, $sql, 'id', 'name',
1088 'spec_option' => $none_option,
1089 'spec_id' => ALL_NUMERIC,
1090 'select_submit'=> $submit_on_change,
1095 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1096 $submit_on_change=false)
1099 echo "<td>$label</td>\n";
1101 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1105 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1106 $submit_on_change=false)
1108 echo "<tr><td class='label'>$label</td>";
1109 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1113 //------------------------------------------------------------------------------------
1115 function tax_groups_list($name, $selected_id=null,
1116 $none_option=false, $submit_on_change=false)
1118 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1120 return combo_input($name, $selected_id, $sql, 'id', 'name',
1123 'spec_option' => $none_option,
1124 'spec_id' => ALL_NUMERIC,
1125 'select_submit'=> $submit_on_change,
1130 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1133 echo "<td>$label</td>\n";
1135 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1139 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1141 echo "<tr><td class='label'>$label</td>";
1142 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1146 //------------------------------------------------------------------------------------
1148 function item_tax_types_list($name, $selected_id=null)
1150 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1151 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1154 function item_tax_types_list_cells($label, $name, $selected_id=null)
1157 echo "<td>$label</td>\n";
1159 echo item_tax_types_list($name, $selected_id);
1163 function item_tax_types_list_row($label, $name, $selected_id=null)
1165 echo "<tr><td class='label'>$label</td>";
1166 item_tax_types_list_cells(null, $name, $selected_id);
1170 //------------------------------------------------------------------------------------
1172 function shippers_list($name, $selected_id=null)
1174 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1175 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1176 array('order'=>array('shipper_name')));
1179 function shippers_list_cells($label, $name, $selected_id=null)
1182 echo "<td>$label</td>\n";
1184 echo shippers_list($name, $selected_id);
1188 function shippers_list_row($label, $name, $selected_id=null)
1190 echo "<tr><td class='label'>$label</td>";
1191 shippers_list_cells(null, $name, $selected_id);
1195 //-------------------------------------------------------------------------------------
1197 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1199 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1200 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1201 array('order'=>array('salesman_name'),
1202 'spec_option' => $spec_opt,
1203 'spec_id' => ALL_NUMERIC));
1206 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1209 echo "<td>$label</td>\n";
1211 echo sales_persons_list($name, $selected_id, $spec_opt);
1215 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1217 echo "<tr><td class='label'>$label</td>";
1218 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1222 //------------------------------------------------------------------------------------
1224 function sales_areas_list($name, $selected_id=null)
1226 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1227 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1230 function sales_areas_list_cells($label, $name, $selected_id=null)
1233 echo "<td>$label</td>\n";
1235 echo sales_areas_list($name, $selected_id);
1239 function sales_areas_list_row($label, $name, $selected_id=null)
1241 echo "<tr><td class='label'>$label</td>";
1242 sales_areas_list_cells(null, $name, $selected_id);
1246 //------------------------------------------------------------------------------------
1248 function sales_groups_list($name, $selected_id=null, $special_option=false)
1250 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1251 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1252 'spec_option' => $special_option===true ? ' ' : $special_option,
1253 'order' => 'description', 'spec_id' => 0,
1257 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1260 echo "<td>$label</td>\n";
1262 echo sales_groups_list($name, $selected_id, $special_option);
1266 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1268 echo "<tr><td class='label'>$label</td>";
1269 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1273 //------------------------------------------------------------------------------------
1275 function _format_template_items($row)
1277 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1280 function templates_list($name, $selected_id=null, $special_option=false)
1282 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1283 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1284 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1285 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1286 'format' => '_format_template_items',
1287 'spec_option' => $special_option===true ? ' ' : $special_option,
1288 'order' => 'order_no', 'spec_id' => 0,
1292 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1295 echo "<td>$label</td>\n";
1297 echo templates_list($name, $selected_id, $special_option);
1301 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1303 echo "<tr><td class='label'>$label</td>";
1304 templates_list_cells(null, $name, $selected_id, $special_option);
1308 //------------------------------------------------------------------------------------
1310 function workorders_list($name, $selected_id=null)
1312 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1313 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1316 function workorders_list_cells($label, $name, $selected_id=null)
1319 echo "<td>$label</td>\n";
1321 echo workorders_list($name, $selected_id);
1325 function workorders_list_row($label, $name, $selected_id=null)
1327 echo "<tr><td class='label'>$label</td>";
1328 workorders_list_cells(null, $name, $selected_id);
1332 //------------------------------------------------------------------------------------
1334 function payment_terms_list($name, $selected_id=null)
1336 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1337 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1340 function payment_terms_list_cells($label, $name, $selected_id=null)
1343 echo "<td>$label</td>\n";
1345 echo payment_terms_list($name, $selected_id);
1349 function payment_terms_list_row($label, $name, $selected_id=null)
1351 echo "<tr><td class='label'>$label</td>";
1352 payment_terms_list_cells(null, $name, $selected_id);
1356 //------------------------------------------------------------------------------------
1358 function credit_status_list($name, $selected_id=null)
1360 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1361 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1364 function credit_status_list_cells($label, $name, $selected_id=null)
1367 echo "<td>$label</td>\n";
1369 echo credit_status_list($name, $selected_id);
1373 function credit_status_list_row($label, $name, $selected_id=null)
1375 echo "<tr><td class='label'>$label</td>";
1376 credit_status_list_cells(null, $name, $selected_id);
1380 //-----------------------------------------------------------------------------------------------
1382 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1384 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1386 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1388 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1390 'select_submit'=> $submit_on_change,
1394 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1397 echo "<td>$label</td>\n";
1399 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1403 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1405 echo "<tr><td class='label'>$label</td>";
1406 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1410 //-----------------------------------------------------------------------------------------------
1412 function _format_date($row)
1414 return sql2date($row['reconciled']);
1417 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1419 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1420 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1421 GROUP BY reconciled";
1422 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1424 'spec_option' => $special_option,
1425 'format' => '_format_date',
1427 'select_submit'=> $submit_on_change
1431 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1434 echo "<td>$label</td>\n";
1436 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1440 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1443 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1447 //-----------------------------------------------------------------------------------------------
1449 function workcenter_list($name, $selected_id=null, $all_option=false)
1452 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1454 return combo_input($name, $selected_id, $sql, 'id', 'name',
1456 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1457 'spec_id' => ALL_TEXT,
1461 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1463 default_focus($name);
1465 echo "<td>$label</td>\n";
1467 echo workcenter_list($name, $selected_id, $all_option);
1471 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1473 echo "<tr><td class='label'>$label</td>";
1474 workcenter_list_cells(null, $name, $selected_id, $all_option);
1478 //-----------------------------------------------------------------------------------------------
1480 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1482 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1483 FROM ".TB_PREF."bank_accounts";
1485 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1487 'format' => '_format_add_curr',
1488 'select_submit'=> $submit_on_change,
1489 'spec_option' => $spec_option,
1495 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1498 echo "<td>$label</td>\n";
1500 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1504 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1506 echo "<tr><td class='label'>$label</td>";
1507 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1510 //-----------------------------------------------------------------------------------------------
1512 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1515 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1516 FROM ".TB_PREF."bank_accounts
1517 WHERE account_type=".BT_CASH;
1520 echo "<tr><td class='label'>$label</td>\n";
1522 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1524 'spec_option' => $all_option,
1525 'spec_id' => ALL_TEXT,
1526 'format' => '_format_add_curr',
1527 'select_submit'=> $submit_on_change,
1530 echo "</td></tr>\n";
1532 //-----------------------------------------------------------------------------------------------
1534 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1536 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1538 default_focus($name);
1541 echo "<td class='label'>$label</td>\n";
1544 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1546 'select_submit'=> $submit_on_change,
1548 'spec_option' =>$spec_option,
1550 'order'=> array('pos_name')
1552 echo "</td></tr>\n";
1555 //-----------------------------------------------------------------------------------------------
1556 // Payment type selector for current user.
1558 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1560 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1562 if ($category == PM_CASH) // only cash
1563 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1564 elseif ($category == PM_CREDIT) // only delayed payments
1565 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1566 elseif (!$prepayments)
1567 $sql .= " WHERE days_before_due>=0";
1569 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1571 'select_submit'=> $submit_on_change,
1577 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1580 echo "<td class='label'>$label</td>\n";
1583 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1587 //-----------------------------------------------------------------------------------------------
1589 function class_list($name, $selected_id=null, $submit_on_change=false)
1591 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1593 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1595 'select_submit'=> $submit_on_change,
1601 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1604 echo "<td>$label</td>\n";
1606 echo class_list($name, $selected_id, $submit_on_change);
1610 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1612 echo "<tr><td class='label'>$label</td>";
1613 class_list_cells(null, $name, $selected_id, $submit_on_change);
1617 //-----------------------------------------------------------------------------------------------
1618 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1620 $where_opts = array();
1622 $where_opts[0] = "dflt_mb_flag='F'";
1624 $where_opts[0] = "dflt_mb_flag!='F'";
1626 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1627 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1628 array('order'=>'category_id',
1629 'spec_option' => $spec_opt,
1631 'select_submit'=> $submit_on_change,
1633 'where' => $where_opts,
1637 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1640 echo "<td>$label</td>\n";
1642 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1646 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1648 echo "<tr><td class='label'>$label</td>";
1649 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1653 //-----------------------------------------------------------------------------------------------
1654 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1656 $sql = "SELECT c.fa_class_id, CONCAT(c.fa_class_id,' - ',c.description) `desc`, CONCAT(p.fa_class_id,' - ',p.description), c.inactive FROM ".TB_PREF."stock_fa_class c, ".TB_PREF."stock_fa_class p WHERE c.parent_id=p.fa_class_id";
1658 return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
1659 array('order'=>'c.fa_class_id',
1660 'spec_option' => $spec_opt,
1662 'select_submit'=> $submit_on_change,
1664 'search_box' => true,
1665 'search' => array("c.fa_class_id"),
1666 'search_submit' => false,
1667 'spec_option' => '',
1675 function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1677 echo "<tr><td class='label'>$label</td>";
1679 echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change);
1680 echo "</td></tr>\n";
1683 //-----------------------------------------------------------------------------------------------
1685 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1688 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1690 return combo_input($name, $selected_id, $sql, 'id', 'name',
1692 'format' => '_format_account',
1693 'order' => array('class_id', 'id', 'parent'),
1694 'spec_option' =>$all_option,
1695 'spec_id' => ALL_TEXT
1699 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1702 echo "<td>$label</td>\n";
1704 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1708 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1710 echo "<tr><td class='label'>$label</td>";
1711 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1716 //-----------------------------------------------------------------------------------------------
1717 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1718 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1720 if ($skip_bank_accounts)
1721 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1722 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1723 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1724 ."ON chart.account_code=acc.account_code
1725 WHERE acc.account_code IS NULL
1726 AND chart.account_type=type.id";
1728 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1729 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1730 WHERE chart.account_type=type.id";
1732 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1734 'format' => '_format_account',
1735 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1738 'order' => array('type.class_id','type.id','account_code'),
1739 'search_box' => $cells,
1740 'search_submit' => false,
1744 'select_submit'=> $submit_on_change,
1747 'show_inactive' => $all
1751 function _format_account($row)
1753 return $row[0] . " " . $row[1];
1756 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1757 $skip_bank_accounts=false, $cells=false, $all_option=false,
1758 $submit_on_change=false, $all=false)
1761 echo "<td>$label</td>\n";
1763 echo gl_all_accounts_list($name, $selected_id,
1764 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1768 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1769 $skip_bank_accounts=false, $cells=false, $all_option=false)
1771 echo "<tr><td class='label'>$label</td>";
1772 gl_all_accounts_list_cells(null, $name, $selected_id,
1773 $skip_bank_accounts, $cells, $all_option);
1777 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1780 $items['0'] = strlen($name_no) ? $name_no : _("No");
1781 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1783 return array_selector($name, $selected_id, $items,
1785 'select_submit'=> $submit_on_change,
1786 'async' => false ) ); // FIX?
1789 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1792 echo "<td>$label</td>\n";
1794 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1798 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1800 echo "<tr><td class='label'>$label</td>";
1801 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1805 //------------------------------------------------------------------------------------------------
1807 function languages_list($name, $selected_id=null, $all_option=false)
1809 global $installed_languages;
1813 $items[''] = $all_option;
1814 foreach ($installed_languages as $lang)
1815 $items[$lang['code']] = $lang['name'];
1816 return array_selector($name, $selected_id, $items);
1819 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1822 echo "<td>$label</td>\n";
1824 echo languages_list($name, $selected_id, $all_option);
1828 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1830 echo "<tr><td class='label'>$label</td>";
1831 languages_list_cells(null, $name, $selected_id, $all_option);
1835 //------------------------------------------------------------------------------------------------
1837 function bank_account_types_list($name, $selected_id=null)
1839 global $bank_account_types;
1841 return array_selector($name, $selected_id, $bank_account_types);
1844 function bank_account_types_list_cells($label, $name, $selected_id=null)
1847 echo "<td>$label</td>\n";
1849 echo bank_account_types_list($name, $selected_id);
1853 function bank_account_types_list_row($label, $name, $selected_id=null)
1855 echo "<tr><td class='label'>$label</td>";
1856 bank_account_types_list_cells(null, $name, $selected_id);
1860 //------------------------------------------------------------------------------------------------
1861 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1863 global $payment_person_types;
1866 foreach ($payment_person_types as $key=>$type)
1868 if ($key != PT_WORKORDER)
1869 $items[$key] = $type;
1871 return array_selector($name, $selected_id, $items,
1872 array( 'select_submit'=> $submit_on_change ) );
1875 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1878 echo "<td>$label</td>\n";
1880 echo payment_person_types_list($name, $selected_id, $related);
1884 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1886 echo "<tr><td class='label'>$label</td>";
1887 payment_person_types_list_cells(null, $name, $selected_id, $related);
1891 //------------------------------------------------------------------------------------------------
1893 function wo_types_list($name, $selected_id=null)
1895 global $wo_types_array;
1897 return array_selector($name, $selected_id, $wo_types_array,
1898 array( 'select_submit'=> true, 'async' => true ) );
1901 function wo_types_list_row($label, $name, $selected_id=null)
1903 echo "<tr><td class='label'>$label</td><td>\n";
1904 echo wo_types_list($name, $selected_id);
1905 echo "</td></tr>\n";
1908 //------------------------------------------------------------------------------------------------
1910 function dateformats_list_row($label, $name, $value=null)
1914 echo "<tr><td class='label'>$label</td>\n<td>";
1915 echo array_selector( $name, $value, $SysPrefs->dateformats );
1916 echo "</td></tr>\n";
1919 function dateseps_list_row($label, $name, $value=null)
1923 echo "<tr><td class='label'>$label</td>\n<td>";
1924 echo array_selector( $name, $value, $SysPrefs->dateseps );
1925 echo "</td></tr>\n";
1928 function thoseps_list_row($label, $name, $value=null)
1932 echo "<tr><td class='label'>$label</td>\n<td>";
1933 echo array_selector( $name, $value, $SysPrefs->thoseps );
1934 echo "</td></tr>\n";
1937 function decseps_list_row($label, $name, $value=null)
1941 echo "<tr><td class='label'>$label</td>\n<td>";
1942 echo array_selector( $name, $value, $SysPrefs->decseps );
1943 echo "</td></tr>\n";
1946 function themes_list_row($label, $name, $value=null)
1948 global $path_to_root;
1950 $path = $path_to_root.'/themes/';
1952 $themedir = opendir($path);
1953 while(false !== ($fname = readdir($themedir)))
1955 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1957 $themes[$fname] = $fname;
1962 echo "<tr><td class='label'>$label</td>\n<td>";
1963 echo array_selector( $name, $value, $themes );
1964 echo "</td></tr>\n";
1967 function pagesizes_list_row($label, $name, $value=null)
1972 foreach ($SysPrefs->pagesizes as $pz)
1975 echo "<tr><td class='label'>$label</td>\n<td>";
1976 echo array_selector( $name, $value, $items );
1977 echo "</td></tr>\n";
1980 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1982 global $systypes_array;
1984 // emove non-voidable transactions if needed
1985 $systypes = array_diff_key($systypes_array, array_flip($exclude));
1986 return array_selector($name, $value, $systypes,
1988 'spec_option'=> $spec_opt,
1989 'spec_id' => ALL_NUMERIC,
1990 'select_submit'=> $submit_on_change,
1996 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1999 echo "<td>$label</td>\n";
2001 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
2005 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2007 echo "<tr><td class='label'>$label</td>";
2008 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
2012 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
2014 global $systypes_array;
2017 echo "<td>$label</td>\n";
2020 $items = $systypes_array;
2022 // exclude quotes, orders and dimensions
2023 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
2024 unset($items[$excl]);
2026 echo array_selector($name, $value, $items,
2028 'spec_option'=> _("All"),
2030 'select_submit'=> $submit_on_change,
2037 function cust_allocations_list_cells($label, $name, $selected=null)
2044 ALL_TEXT=>_("All Types"),
2045 '1'=> _("Sales Invoices"),
2046 '2'=> _("Overdue Invoices"),
2047 '3' => _("Payments"),
2048 '4' => _("Credit Notes"),
2049 '5' => _("Delivery Notes")
2051 echo array_selector($name, $selected, $allocs);
2055 function supp_allocations_list_cell($name, $selected=null)
2060 ALL_TEXT=>_("All Types"),
2061 '1'=> _("Invoices"),
2062 '2'=> _("Overdue Invoices"),
2063 '3' => _("Payments"),
2064 '4' => _("Credit Notes"),
2065 '5' => _("Overdue Credit Notes")
2067 echo array_selector($name, $selected, $allocs);
2071 function supp_transactions_list_cell($name, $selected=null)
2076 ALL_TEXT=>_("All Types"),
2078 '1'=> _("Invoices"),
2079 '2'=> _("Overdue Invoices"),
2080 '3' => _("Payments"),
2081 '4' => _("Credit Notes"),
2082 '5' => _("Overdue Credit Notes")
2085 echo array_selector($name, $selected, $allocs);
2089 function policy_list_cells($label, $name, $selected=null)
2094 echo array_selector($name, $selected,
2095 array( '' => _("Automatically put balance on back order"),
2096 'CAN' => _("Cancel any quantites not delivered")) );
2100 function policy_list_row($label, $name, $selected=null)
2102 echo "<tr><td class='label'>$label</td>";
2103 policy_list_cells(null, $name, $selected);
2107 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2112 echo array_selector($name, $selected,
2113 array( 'Return' => _("Items Returned to Inventory Location"),
2114 'WriteOff' => _("Items Written Off")),
2115 array( 'select_submit'=> $submit_on_change ) );
2119 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2121 echo "<tr><td class='label'>$label</td>";
2122 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2126 function number_list($name, $selected, $from, $to, $no_option=false)
2129 for ($i = $from; $i <= $to; $i++)
2132 return array_selector($name, $selected, $items,
2133 array( 'spec_option' => $no_option,
2134 'spec_id' => ALL_NUMERIC) );
2137 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2142 echo number_list($name, $selected, $from, $to, $no_option);
2146 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2148 echo "<tr><td class='label'>$label</td>";
2149 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2153 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2154 $submit_on_change=true)
2156 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2157 ." GROUP BY profile";
2158 $result = db_query($sql, 'cannot get all profile names');
2159 $profiles = array();
2160 while($myrow=db_fetch($result)) {
2161 $profiles[$myrow['profile']] = $myrow['profile'];
2166 echo "<td class='label'>$label</td>\n";
2169 echo array_selector($name, $selected_id, $profiles,
2170 array( 'select_submit'=> $submit_on_change,
2171 'spec_option'=>$spec_opt,
2175 echo "</td></tr>\n";
2178 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2180 static $printers; // query only once for page display
2183 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2184 $result = db_query($sql, 'cannot get all printers');
2185 $printers = array();
2186 while($myrow=db_fetch($result)) {
2187 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2190 return array_selector($name, $selected_id, $printers,
2191 array( 'select_submit'=> $submit_on_change,
2192 'spec_option'=>$spec_opt,
2197 //------------------------------------------------------------------------------------------------
2199 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2202 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2204 $sql .= " WHERE type=$type";
2206 return combo_input($name, $selected_id, $sql, 'id', 'description',
2209 'order' => 'description',
2210 'select_submit'=> $submit_on_change,
2216 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2219 echo "<td>$label</td>\n";
2221 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2225 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2227 echo "<tr><td class='label'>$label</td>";
2228 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2233 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2235 global $quick_actions;
2237 echo "<tr><td class='label'>$label</td><td>";
2238 echo array_selector($name, $selected_id, $quick_actions,
2240 'select_submit'=> $submit_on_change
2242 echo "</td></tr>\n";
2245 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2247 global $quick_entry_types;
2249 echo "<tr><td class='label'>$label</td><td>";
2250 echo array_selector($name, $selected_id, $quick_entry_types,
2252 'select_submit'=> $submit_on_change
2254 echo "</td></tr>\n";
2257 function record_status_list_row($label, $name) {
2258 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2261 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2263 global $class_types;
2265 echo "<tr><td class='label'>$label</td><td>";
2266 echo array_selector($name, $selected_id, $class_types,
2268 'select_submit'=> $submit_on_change
2270 echo "</td></tr>\n";
2273 //------------------------------------------------------------------------------------------------
2275 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2276 $show_inactive = false)
2279 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2281 return combo_input($name, $selected_id, $sql, 'id', 'description',
2283 'spec_option'=>$new_item ? _("New role") : false,
2285 'select_submit'=> $submit_on_change,
2286 'show_inactive' => $show_inactive
2290 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2291 $show_inactive = false)
2294 echo "<td>$label</td>\n";
2296 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2300 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2301 $show_inactive = false)
2303 echo "<tr><td class='label'>$label</td>";
2304 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2308 function tab_list_row($label, $name, $selected_id=null)
2310 global $installed_extensions;
2313 foreach ($_SESSION['App']->applications as $app) {
2314 $tabs[$app->id] = access_string($app->name, true);
2317 echo "<td class='label'>$label</td><td>\n";
2318 echo array_selector($name, $selected_id, $tabs);
2319 echo "</td></tr>\n";
2322 //-----------------------------------------------------------------------------------------------
2324 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2327 global $path_to_root;
2328 include_once($path_to_root . "/admin/db/tags_db.inc");
2329 $results = get_tags($type, $all);
2331 while ($tag = db_fetch($results))
2332 $tags[$tag['id']] = $tag['name'];
2334 if (!isset($tags)) {
2335 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2338 return array_selector($name, null, $tags,
2341 'height' => $height,
2342 'spec_option'=> $spec_opt,
2347 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2350 echo "<td>$label</td>\n";
2352 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2357 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2359 echo "<tr><td class='label'>$label</td>";
2360 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2364 //---------------------------------------------------------------------------------------------
2365 // List of sets of active extensions
2367 function extset_list($name, $value=null, $submit_on_change=false)
2369 global $db_connections;
2372 foreach ($db_connections as $comp)
2373 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2374 return array_selector( $name, $value, $items,
2376 'spec_option'=> _("Available and/or installed"),
2378 'select_submit'=> $submit_on_change,
2383 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2386 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2391 if (@$filter['class']) {
2392 $where[] = 'type='.db_escape($filter['class']);
2395 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2396 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2397 if (@$filter['multi']) { // contact category selector for person
2401 return combo_input($name, $selected_id, $sql, 'id', 'name',
2404 'height' => $multi ? 5:1,
2405 'category' => $groups,
2406 'select_submit'=> $submit_on_change,
2412 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2414 echo "<tr><td class='label'>$label</td><td>";
2415 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2416 echo "</td></tr>\n";
2419 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2421 global $pterm_types;
2423 echo "<tr><td class='label'>$label</td><td>";
2424 echo array_selector($name, $selected_id, $pterm_types,
2426 'select_submit'=> $submit_on_change
2428 echo "</td></tr>\n";
2431 function coa_list_row($label, $name, $value=null)
2433 global $path_to_root, $installed_extensions;
2435 $path = $path_to_root.'/sql/';
2437 $sqldir = opendir($path);
2438 while (false !== ($fname = readdir($sqldir)))
2440 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2442 $ext = array_search_value($fname, $installed_extensions, 'sql');
2444 $descr = $ext['name'];
2445 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2446 $descr = _("Standard new company American COA (4 digit)");
2447 } elseif ($fname == 'en_US-demo.sql') {
2448 $descr = _("Standard American COA (4 digit) with demo data");
2452 $coas[$fname] = $descr;
2457 echo "<tr><td class='label'>$label</td>\n<td>";
2458 echo array_selector( $name, $value, $coas );
2459 echo "</td></tr>\n";
2462 function payment_services($name)
2464 global $payment_services;
2466 $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2468 return array_selector($name, null, $services, array(
2469 'spec_option'=> _("No payment Link"),
2474 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2476 global $tax_algorithms;
2478 return array_selector($name, $value, $tax_algorithms,
2480 'select_submit'=> $submit_on_change,
2486 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2489 echo "<td>$label</td>\n";
2491 echo tax_algorithm_list($name, $value, $submit_on_change);
2495 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2497 echo "<tr><td class='label'>$label</td>";
2498 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2502 function refline_list($name, $type, $value=null, $spec_option=false)
2504 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2509 $where = array('`trans_type`='.db_escape($type));
2511 return combo_input($name, $value, $sql, 'id', 'prefix',
2513 'order'=>array('prefix'),
2514 'spec_option' => $spec_option,
2518 'select_submit' => true,
2523 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2527 echo "<td class='label'>$label</td>\n";
2530 echo refline_list($name, $type, $selected_id, $spec_option);
2531 echo "</td></tr>\n";
2535 //----------------------------------------------------------------------------------------------
2537 function subledger_list($name, $account, $selected_id=null)
2540 $type = is_subledger_account($account);
2545 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2547 .TB_PREF."debtors_master d,"
2548 .TB_PREF."cust_branch c
2549 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2551 $sql = "SELECT supplier_id as id, supp_ref as name
2553 .TB_PREF."suppliers s
2554 WHERE s.payable_account=".db_escape($account);
2556 $mode = get_company_pref('no_customer_list');
2558 return combo_input($name, $selected_id, $sql, 'id', 'name',
2566 function subledger_list_cells($label, $name, $account, $selected_id=null)
2569 echo "<td>$label</td>\n";
2571 echo subledger_list($name, $account, $selected_id);
2575 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2576 $submit_on_change=false, $show_inactive=false, $editkey = false)
2578 echo "<tr><td class='label'>$label</td><td nowrap>";
2579 echo subledger_list($name, $account, $selected_id);
2580 echo "</td>\n</tr>\n";
2583 function accounts_type_list_row($label, $name, $selected_id=null)
2587 echo "<td class='label'>$label</td>\n";
2589 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2590 echo array_selector($name, $selected_id, $sel);
2591 echo "</td></tr>\n";
2594 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2597 $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2600 echo "<td>$label</td>\n";
2603 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2605 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2607 'order' => 'real_name',
2608 'select_submit'=> $submit_on_change,
2615 function collations_list_row($label, $name, $selected_id=null)
2617 global $supported_collations;
2621 echo "<td class='label'>$label</td>\n";
2624 echo array_selector($name, $selected_id, $supported_collations,
2625 array('select_submit'=> false) );
2626 echo "</td></tr>\n";