2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/banking.inc");
13 include_once($path_to_root . "/includes/types.inc");
14 include_once($path_to_root . "/includes/current_user.inc");
16 $_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
17 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
19 $_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
20 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
22 $all_items = ALL_TEXT;
24 //----------------------------------------------------------------------------
25 // Universal sql combo generator
26 // $sql must return selector values and selector texts in columns 0 & 1
27 // Options are merged with defaults.
29 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
34 $opts = array( // default options
35 'where'=> array(), // additional constraints
36 'order' => $namefield, // list sort order
37 // special option parameters
38 'spec_option'=>false, // option text or false
39 'spec_id' => 0, // option id
40 // submit on select parameters
41 'default' => '', // default value when $_POST is not set
42 'multi' => false, // multiple select
43 'select_submit' => false, //submit on select: true/false
44 'async' => true, // select update via ajax (true) vs _page_body reload
45 // search box parameters
47 'search_box' => false, // name or true/false
48 'type' => 0, // type of extended selector:
49 // 0 - with (optional) visible search box, search by fragment inside id
50 // 1 - with hidden search box, search by option text
51 // 2 - with (optional) visible search box, search by fragment at the start of id
52 // 3 - TODO reverse: box with hidden selector available via enter; this
53 // would be convenient for optional ad hoc adding of new item
54 'search_submit' => true, //search submit button: true/false
55 'size' => 8, // size and max of box tag
57 'height' => false, // number of lines in select box
58 'cells' => false, // combo displayed as 2 <td></td> cells
59 'search' => array(), // sql field names to search
60 'format' => null, // format functions for regular options
62 'box_hint' => null, // box/selectors hints; null = std see below
63 'category' => false, // category column name or false
64 'show_inactive' => false, // show inactive records.
65 'editable' => false // false, or length of editable entry field
67 // ------ merge options with defaults ----------
69 $opts = array_merge($opts, $options);
70 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
72 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
73 // select content filtered by search field:
74 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
75 // select set by select content field
76 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
78 $select_submit = $opts['select_submit'];
79 $spec_id = $opts['spec_id'];
80 $spec_option = $opts['spec_option'];
81 if ($opts['type'] == 0) {
84 } elseif($opts['type'] == 1) {
92 $disabled = $opts['disabled'] ? "disabled" : '';
93 $multi = $opts['multi'];
95 if(!count($opts['search'])) {
96 $opts['search'] = array($by_id ? $valfield : $namefield);
98 if ($opts['sel_hint'] === null)
99 $opts['sel_hint'] = $by_id || $search_box==false ?
100 '' : _('Press Space tab for search pattern entry');
102 if ($opts['box_hint'] === null)
103 $opts['box_hint'] = $search_box && $search_submit != false ?
104 ($by_id ? _('Enter code fragment to search or * for all')
105 : _('Enter description fragment to search or * for all')) :'';
107 if ($selected_id == null) {
108 $selected_id = get_post($name, (string)$opts['default']);
110 if(!is_array($selected_id))
111 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
113 $txt = get_post($search_box);
116 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
117 if ($by_id) $txt = $_POST[$name];
120 $Ajax->activate('_page_body');
122 $Ajax->activate($name);
124 if (isset($_POST[$search_button])) {
126 $Ajax->activate('_page_body');
128 $Ajax->activate($name);
131 // search related sql modifications
133 $rel = "rel='$search_box'"; // set relation to list
134 if ($opts['search_submit']) {
135 if (isset($_POST[$search_button])) {
136 $selected_id = array(); // ignore selected_id while search
138 $Ajax->activate('_page_body');
140 $Ajax->activate($name);
143 if ($spec_option === false && $selected_id == array())
146 $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id));
151 foreach($opts['search'] as $i=> $s)
152 $opts['search'][$i] = $s . " LIKE "
153 .db_escape(($class=='combo3' ? '' : '%').$txt.'%');
154 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
160 if (count($opts['where'])) {
161 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
162 $where .= '('. implode($opts['where'], ' AND ') . ')';
163 $group_pos = strpos($sql, 'GROUP BY');
165 $group = substr($sql, $group_pos);
166 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
171 if ($opts['order'] != false) {
172 if (!is_array($opts['order']))
173 $opts['order'] = array($opts['order']);
174 $sql .= ' ORDER BY '.implode(',',$opts['order']);
178 // ------ make selector ----------
179 $selector = $first_opt = '';
184 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
185 //if($name=='curr_default') display_notification($opts['search_submit']);
186 if($result = db_query($sql)) {
187 while ($contact_row = db_fetch($result)) {
188 $value = $contact_row[0];
189 $descr = $opts['format']==null ? $contact_row[1] :
190 call_user_func($opts['format'], $contact_row);
192 if (get_post($search_button) && ($txt == $value)) {
193 $selected_id[] = $value;
196 if (in_array((string)$value, $selected_id, true)) {
199 $edit = $opts['editable'] && $contact_row['editable']
200 && (@$_POST[$search_box] == $value)
201 ? $contact_row[1] : false; // get non-formatted description
203 break; // selected field is editable - abandon list construction
205 // show selected option even if inactive
206 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
209 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
211 if ($first_id === false) {
215 $cat = $contact_row[$opts['category']];
216 if ($opts['category'] !== false && $cat != $lastcat){
217 $selector .= "<optgroup label='".$cat."'>\n";
220 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
222 db_free_result($result);
225 // Prepend special option.
226 if ($spec_option !== false) { // if special option used - add it
227 $first_id = $spec_id;
228 $first_opt = $spec_option;
230 // if($first_id !== false) {
231 $sel = $found===false ? 'selected' : '';
232 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
233 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
237 if ($found===false) {
238 $selected_id = array($first_id);
241 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
243 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
244 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
245 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
246 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
248 if ($by_id && ($search_box != false || $opts['editable']) ) {
249 // on first display show selector list
250 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
251 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
252 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
253 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
254 set_focus($name.'_text'); // prevent lost focus
255 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
256 set_focus($name); // prevent lost focus
257 if (!$opts['editable'])
259 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
262 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
264 // span for select list/input field update
265 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
267 // if selectable or editable list is used - add select button
268 if ($select_submit != false || $search_button) {
269 global $_select_button;
270 // button class selects form reload/ajax selector update
271 $selector .= sprintf($_select_button, $disabled, user_theme(),
272 (fallback_mode() ? '' : 'display:none;'),
273 '_'.$name.'_update')."\n";
275 // ------ make combo ----------
277 if ($search_box != false) {
278 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
279 $opts['size']."' maxlength='".$opts['max'].
280 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
281 .$opts['box_hint']."'"
282 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
284 if ($search_submit != false || $opts['editable']) {
285 global $_search_button;
286 $edit_entry .= sprintf($_search_button, $disabled, user_theme(),
287 (fallback_mode() ? '' : 'display:none;'),
288 $search_submit ? $search_submit : "_{$name}_button")."\n";
291 default_focus(($search_box && $by_id) ? $search_box : $name);
293 if ($search_box && $opts['cells'])
294 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
296 $str = $edit_entry.$selector;
302 Returns true if selector $name is subject to update.
304 function list_updated($name)
306 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
308 //----------------------------------------------------------------------------------------------
309 // Universal array combo generator
310 // $items is array of options 'value' => 'description'
311 // Options is reduced set of combo_selector options and is merged with defaults.
313 function array_selector($name, $selected_id, $items, $options=null)
317 $opts = array( // default options
318 'spec_option'=>false, // option text or false
319 'spec_id' => 0, // option id
320 'select_submit' => false, //submit on select: true/false
321 'async' => true, // select update via ajax (true) vs _page_body reload
322 'default' => '', // default value when $_POST is not set
323 'multi'=>false, // multiple select
324 // search box parameters
325 'height' => false, // number of lines in select box
329 // ------ merge options with defaults ----------
331 $opts = array_merge($opts, $options);
332 $select_submit = $opts['select_submit'];
333 $spec_id = $opts['spec_id'];
334 $spec_option = $opts['spec_option'];
335 $disabled = $opts['disabled'] ? "disabled" : '';
336 $multi = $opts['multi'];
338 if ($selected_id == null) {
339 $selected_id = get_post($name, $opts['default']);
341 if(!is_array($selected_id))
342 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
344 if (isset($_POST[ '_'.$name.'_update'])) {
346 $Ajax->activate('_page_body');
348 $Ajax->activate($name);
351 // ------ make selector ----------
352 $selector = $first_opt = '';
355 //if($name=='SelectStockFromList') display_error($sql);
356 foreach($items as $value=>$descr) {
358 if (in_array((string)$value, $selected_id, true)) {
362 if ($first_id === false) {
366 $selector .= "<option $sel value='$value'>$descr</option>\n";
369 if ($first_id!==false) {
370 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
371 $selector = sprintf($first_opt, $sel).$selector;
373 // Prepend special option.
374 if ($spec_option !== false) { // if special option used - add it
375 $first_id = $spec_id;
376 $first_opt = $spec_option;
377 $sel = $found===false ? 'selected' : '';
378 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
382 if ($found===false) {
383 $selected_id = array($first_id);
385 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
387 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
388 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
389 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
390 . $opts['sel_hint']."'>".$selector."</select>\n";
392 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
394 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
396 if ($select_submit != false) { // if submit on change is used - add select button
397 global $_select_button;
398 $selector .= sprintf($_select_button, $disabled, user_theme(),
399 (fallback_mode() ? '' : 'display:none;'),
400 '_'.$name.'_update')."\n";
402 default_focus($name);
406 //----------------------------------------------------------------------------------------------
408 function _format_add_curr($row)
410 static $company_currency;
412 if ($company_currency == null)
414 $company_currency = get_company_currency();
416 return $row[1] . ($row[2] == $company_currency ?
417 '' : (" - " . $row[2]));
420 function add_edit_combo($type)
422 global $path_to_root, $popup_editors, $use_icon_for_editkey;
424 if (!isset($use_icon_for_editkey) || $use_icon_for_editkey==0)
427 $theme_path = $path_to_root . '/themes/' . user_theme();
429 $key = $popup_editors[$type][1];
430 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
431 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
432 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
435 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
436 $all=false, $editkey = false)
440 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
442 $mode = get_company_pref('no_supplier_list');
445 set_editor('supplier', $name, $editkey);
447 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
449 'format' => '_format_add_curr',
450 'order' => array('supp_ref'),
451 'search_box' => $mode!=0,
453 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
454 'spec_id' => $all_items,
455 'select_submit'=> $submit_on_change,
457 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
458 _('Select supplier'),
459 'show_inactive'=>$all
462 $ret .= add_edit_combo('supplier');
466 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
467 $submit_on_change=false, $all=false, $editkey = false)
470 echo "<td>$label</td><td>\n";
471 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
476 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
477 $submit_on_change=false, $all=false, $editkey = false)
479 echo "<tr><td class='label'>$label</td><td>";
480 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
484 //----------------------------------------------------------------------------------------------
486 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
487 $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 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
506 'spec_id' => $all_items,
507 'select_submit'=> $submit_on_change,
509 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
510 _('Select customer'),
511 'show_inactive' => $show_inactive
514 $ret .= add_edit_combo('customer');
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)
546 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
547 WHERE debtor_no=" . db_escape($customer_id)." ";
550 set_editor('branch', $name, $editkey);
552 $where = $enabled ? array("disable_trans = 0") : array();
553 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
556 'order' => array('branch_ref'),
557 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
558 'spec_id' => $all_items,
559 'select_submit'=> $submit_on_change,
560 'sel_hint' => _('Select customer branch')
564 $ret .= add_edit_combo('branch');
568 //------------------------------------------------------------------------------------------------
570 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
571 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
574 echo "<td>$label</td>\n";
576 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
577 $submit_on_change, $editkey);
581 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
582 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
584 echo "<tr><td class='label'>$label</td>";
585 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
586 $all_option, $enabled, $submit_on_change, $editkey);
590 //------------------------------------------------------------------------------------------------
592 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
596 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
598 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
600 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
601 'spec_id' => $all_items,
602 'select_submit'=> $submit_on_change
606 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
609 echo "<td>$label</td>\n";
611 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
615 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
617 echo "<tr><td class='label'>$label</td>";
618 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
622 //-----------------------------------------------------------------------------------------------
624 function currencies_list($name, $selected_id=null, $submit_on_change=false)
626 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
628 // default to the company currency
629 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
631 'select_submit'=> $submit_on_change,
632 'default' => get_company_currency(),
637 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
640 echo "<td>$label</td>\n";
642 echo currencies_list($name, $selected_id, $submit_on_change);
646 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
648 echo "<tr><td class='label'>$label</td>";
649 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
653 //---------------------------------------------------------------------------------------------------
655 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
658 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
660 // default to the company current fiscal year
662 return combo_input($name, $selected_id, $sql, 'id', '',
665 'default' => get_company_pref('f_year'),
666 'format' => '_format_fiscalyears',
667 'select_submit'=> $submit_on_change,
672 function _format_fiscalyears($row)
674 return sql2date($row[1]) . " - " . sql2date($row[2])
675 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
678 function fiscalyears_list_cells($label, $name, $selected_id=null)
681 echo "<td>$label</td>\n";
683 echo fiscalyears_list($name, $selected_id);
687 function fiscalyears_list_row($label, $name, $selected_id=null)
689 echo "<tr><td class='label'>$label</td>";
690 fiscalyears_list_cells(null, $name, $selected_id);
693 //------------------------------------------------------------------------------------
695 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
696 $submit_on_change=false, $showclosed=false, $showtype=1)
698 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
701 'order' => 'reference',
702 'spec_option'=>$no_option ? $showname : false,
704 'select_submit'=> $submit_on_change,
709 $options['where'][] = "closed=0";
711 $options['where'][] = "type_=".db_escape($showtype);
713 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
716 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
717 $showclosed=false, $showtype=0, $submit_on_change=false)
720 echo "<td>$label</td>\n";
722 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
726 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
727 $showclosed=false, $showtype=0, $submit_on_change=false)
729 echo "<tr><td class='label'>$label</td>";
730 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
731 $showclosed, $showtype, $submit_on_change);
735 //---------------------------------------------------------------------------------------------------
737 function stock_items_list($name, $selected_id=null, $all_option=false,
738 $submit_on_change=false, $opts=array(), $editkey = false)
742 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
743 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
746 set_editor('item', $name, $editkey);
748 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
751 'format' => '_format_stock_items',
752 'spec_option' => $all_option===true ? _("All Items") : $all_option,
753 'spec_id' => $all_items,
754 'search_box' => true,
755 'search' => array("stock_id", "c.description","s.description"),
756 'search_submit' => get_company_pref('no_item_list')!=0,
758 'select_submit'=> $submit_on_change,
760 'order' => array('c.description','stock_id')
763 $ret .= add_edit_combo('item');
767 function _format_stock_items($row)
769 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
772 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
773 $submit_on_change=false, $all=false, $editkey = false)
776 echo "<td>$label</td>\n";
777 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
778 array('cells'=>true, 'show_inactive'=>$all), $editkey);
781 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
784 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
788 //---------------------------------------------------------------------------------------------------
790 // Select item via foreign code.
792 function sales_items_list($name, $selected_id=null, $all_option=false,
793 $submit_on_change=false, $type='', $opts=array())
797 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
798 i.inactive, if(count(*)>1, '0', s.editable) as editable
800 ".TB_PREF."stock_master s,
801 ".TB_PREF."item_codes i
803 ".TB_PREF."stock_category c
804 ON i.category_id=c.category_id
805 WHERE i.stock_id=s.stock_id";
808 if ($type == 'local') { // exclude foreign codes
809 $sql .= " AND !i.is_foreign";
810 } elseif ($type == 'kits') { // sales kits
811 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
813 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
814 $sql .= " GROUP BY i.item_code";
816 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
819 'format' => '_format_stock_items',
820 'spec_option' => $all_option===true ? _("All Items") : $all_option,
821 'spec_id' => $all_items,
822 'search_box' => true,
823 'search' => array("i.item_code", "c.description", "i.description"),
824 'search_submit' => get_company_pref('no_item_list')!=0,
826 'select_submit'=> $submit_on_change,
828 'order' => array('c.description','i.item_code'),
834 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
837 echo "<td>$label</td>\n";
838 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
839 '', array('cells'=>true));
842 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
844 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
845 'kits', array('cells'=>false, 'editable' => false));
848 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
852 echo "<td class='label'>$label</td>\n";
854 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
855 'local', array('cells'=>false, 'editable' => false));
858 //------------------------------------------------------------------------------------
860 function stock_manufactured_items_list($name, $selected_id=null,
861 $all_option=false, $submit_on_change=false)
863 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
864 array('where'=>array("mb_flag= 'M'")));
867 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
868 $all_option=false, $submit_on_change=false)
871 echo "<td>$label</td>\n";
873 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
877 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
878 $all_option=false, $submit_on_change=false)
880 echo "<tr><td class='label'>$label</td>";
881 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
884 //------------------------------------------------------------------------------------
886 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
887 $all_option=false, $submit_on_change=false, $editkey = false)
889 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
890 array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
893 function stock_component_items_list_cells($label, $name, $parent_stock_id,
894 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
897 echo "<td>$label</td>\n";
898 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
899 array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
902 //------------------------------------------------------------------------------------
904 function stock_costable_items_list($name, $selected_id=null,
905 $all_option=false, $submit_on_change=false)
907 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
908 array('where'=>array("mb_flag!='D'")));
911 function stock_costable_items_list_cells($label, $name, $selected_id=null,
912 $all_option=false, $submit_on_change=false)
915 echo "<td>$label</td>\n";
916 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
917 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
920 //------------------------------------------------------------------------------------
921 function stock_purchasable_items_list($name, $selected_id=null,
922 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
924 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
925 array('where'=>array("NOT no_purchase"),
926 'show_inactive'=>$all), $editkey);
929 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
931 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
932 $all_option=false, $submit_on_change=false, $editkey=false)
935 echo "<td>$label</td>\n";
936 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
937 array('where'=>array("NOT no_purchase"),
939 'cells'=>true), $editkey);
942 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
943 $all_option=false, $submit_on_change=false, $editkey=false)
945 echo "<tr><td class='label'>$label</td>";
946 stock_purchasable_items_list_cells(null, $name, $selected_id=null,
947 $all_option, $submit_on_change, $editkey);
951 //------------------------------------------------------------------------------------
953 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
959 echo "<td class='label'>$label</td>\n";
962 echo array_selector($name, $selected_id, $stock_types,
964 'select_submit'=> true,
965 'disabled' => !$enabled) );
969 function stock_units_list_row($label, $name, $value=null, $enabled=true)
971 $result = get_all_item_units();
974 echo "<td class='label'>$label</td>\n";
977 while($unit = db_fetch($result))
978 $units[$unit['abbr']] = $unit['name'];
980 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
985 //------------------------------------------------------------------------------------
987 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
989 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
991 return combo_input($name, $selected_id, $sql, 'id', 'name',
993 'spec_option' => $none_option,
994 'spec_id' => ALL_NUMERIC,
995 'select_submit'=> $submit_on_change,
1000 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1001 $submit_on_change=false)
1004 echo "<td>$label</td>\n";
1006 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1010 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1011 $submit_on_change=false)
1013 echo "<tr><td class='label'>$label</td>";
1014 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1018 //------------------------------------------------------------------------------------
1020 function tax_groups_list($name, $selected_id=null,
1021 $none_option=false, $submit_on_change=false)
1023 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1025 return combo_input($name, $selected_id, $sql, 'id', 'name',
1028 'spec_option' => $none_option,
1029 'spec_id' => ALL_NUMERIC,
1030 'select_submit'=> $submit_on_change,
1035 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1038 echo "<td>$label</td>\n";
1040 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1044 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1046 echo "<tr><td class='label'>$label</td>";
1047 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1051 //------------------------------------------------------------------------------------
1053 function item_tax_types_list($name, $selected_id=null)
1055 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1056 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1059 function item_tax_types_list_cells($label, $name, $selected_id=null)
1062 echo "<td>$label</td>\n";
1064 echo item_tax_types_list($name, $selected_id);
1068 function item_tax_types_list_row($label, $name, $selected_id=null)
1070 echo "<tr><td class='label'>$label</td>";
1071 item_tax_types_list_cells(null, $name, $selected_id);
1075 //------------------------------------------------------------------------------------
1077 function shippers_list($name, $selected_id=null)
1079 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1080 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1081 array('order'=>array('shipper_name')));
1084 function shippers_list_cells($label, $name, $selected_id=null)
1087 echo "<td>$label</td>\n";
1089 echo shippers_list($name, $selected_id);
1093 function shippers_list_row($label, $name, $selected_id=null)
1095 echo "<tr><td class='label'>$label</td>";
1096 shippers_list_cells(null, $name, $selected_id);
1100 //-------------------------------------------------------------------------------------
1102 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1104 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1105 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1106 array('order'=>array('salesman_name'),
1107 'spec_option' => $spec_opt,
1108 'spec_id' => ALL_NUMERIC));
1111 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1114 echo "<td>$label</td>\n";
1116 echo sales_persons_list($name, $selected_id, $spec_opt);
1120 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1122 echo "<tr><td class='label'>$label</td>";
1123 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1127 //------------------------------------------------------------------------------------
1129 function sales_areas_list($name, $selected_id=null)
1131 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1132 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1135 function sales_areas_list_cells($label, $name, $selected_id=null)
1138 echo "<td>$label</td>\n";
1140 echo sales_areas_list($name, $selected_id);
1144 function sales_areas_list_row($label, $name, $selected_id=null)
1146 echo "<tr><td class='label'>$label</td>";
1147 sales_areas_list_cells(null, $name, $selected_id);
1151 //------------------------------------------------------------------------------------
1153 function sales_groups_list($name, $selected_id=null, $special_option=false)
1155 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1156 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1157 'spec_option' => $special_option===true ? ' ' : $special_option,
1158 'order' => 'description', 'spec_id' => 0,
1162 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1165 echo "<td>$label</td>\n";
1167 echo sales_groups_list($name, $selected_id, $special_option);
1171 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1173 echo "<tr><td class='label'>$label</td>";
1174 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1178 //------------------------------------------------------------------------------------
1180 function _format_template_items($row)
1182 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1185 function templates_list($name, $selected_id=null, $special_option=false)
1187 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1188 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1189 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1190 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1191 'format' => '_format_template_items',
1192 'spec_option' => $special_option===true ? ' ' : $special_option,
1193 'order' => 'order_no', 'spec_id' => 0,
1197 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1200 echo "<td>$label</td>\n";
1202 echo templates_list($name, $selected_id, $special_option);
1206 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1208 echo "<tr><td class='label'>$label</td>";
1209 templates_list_cells(null, $name, $selected_id, $special_option);
1213 //------------------------------------------------------------------------------------
1215 function workorders_list($name, $selected_id=null)
1217 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1218 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1221 function workorders_list_cells($label, $name, $selected_id=null)
1224 echo "<td>$label</td>\n";
1226 echo workorders_list($name, $selected_id);
1230 function workorders_list_row($label, $name, $selected_id=null)
1232 echo "<tr><td class='label'>$label</td>";
1233 workorders_list_cells(null, $name, $selected_id);
1237 //------------------------------------------------------------------------------------
1239 function payment_terms_list($name, $selected_id=null)
1241 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1242 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1245 function payment_terms_list_cells($label, $name, $selected_id=null)
1248 echo "<td>$label</td>\n";
1250 echo payment_terms_list($name, $selected_id);
1254 function payment_terms_list_row($label, $name, $selected_id=null)
1256 echo "<tr><td class='label'>$label</td>";
1257 payment_terms_list_cells(null, $name, $selected_id);
1261 //------------------------------------------------------------------------------------
1263 function credit_status_list($name, $selected_id=null)
1265 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1266 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1269 function credit_status_list_cells($label, $name, $selected_id=null)
1272 echo "<td>$label</td>\n";
1274 echo credit_status_list($name, $selected_id);
1278 function credit_status_list_row($label, $name, $selected_id=null)
1280 echo "<tr><td class='label'>$label</td>";
1281 credit_status_list_cells(null, $name, $selected_id);
1285 //-----------------------------------------------------------------------------------------------
1287 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1289 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1291 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1293 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1295 'select_submit'=> $submit_on_change,
1296 // 'async' => false,
1300 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1303 echo "<td>$label</td>\n";
1305 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1309 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1311 echo "<tr><td class='label'>$label</td>";
1312 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1316 //-----------------------------------------------------------------------------------------------
1318 function movement_types_list($name, $selected_id=null)
1320 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1321 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1324 function movement_types_list_cells($label, $name, $selected_id=null)
1327 echo "<td>$label</td>\n";
1329 echo movement_types_list($name, $selected_id);
1333 function movement_types_list_row($label, $name, $selected_id=null)
1335 echo "<tr><td class='label'>$label</td>";
1336 movement_types_list_cells(null, $name, $selected_id);
1340 //-----------------------------------------------------------------------------------------------
1341 function _format_date($row)
1343 return sql2date($row['reconciled']);
1346 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1348 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1349 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1350 GROUP BY reconciled";
1351 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1353 'spec_option' => $special_option,
1354 'format' => '_format_date',
1356 'select_submit'=> $submit_on_change
1360 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1363 echo "<td>$label</td>\n";
1365 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1369 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1372 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1376 //-----------------------------------------------------------------------------------------------
1378 function workcenter_list($name, $selected_id=null, $all_option=false)
1382 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1384 return combo_input($name, $selected_id, $sql, 'id', 'name',
1386 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1387 'spec_id' => $all_items,
1391 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1393 default_focus($name);
1395 echo "<td>$label</td>\n";
1397 echo workcenter_list($name, $selected_id, $all_option);
1401 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1403 echo "<tr><td class='label'>$label</td>";
1404 workcenter_list_cells(null, $name, $selected_id, $all_option);
1408 //-----------------------------------------------------------------------------------------------
1410 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
1412 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1413 FROM ".TB_PREF."bank_accounts";
1415 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1417 'format' => '_format_add_curr',
1418 'select_submit'=> $submit_on_change,
1423 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1426 echo "<td>$label</td>\n";
1428 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1432 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1434 echo "<tr><td class='label'>$label</td>";
1435 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1438 //-----------------------------------------------------------------------------------------------
1440 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1444 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1445 FROM ".TB_PREF."bank_accounts
1446 WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
1449 echo "<tr><td class='label'>$label</td>\n";
1451 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1453 'spec_option' => $all_option,
1454 'spec_id' => $all_items,
1455 'format' => '_format_add_curr',
1456 'select_submit'=> $submit_on_change,
1459 echo "</td></tr>\n";
1461 //-----------------------------------------------------------------------------------------------
1463 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1465 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1467 default_focus($name);
1470 echo "<td class='label'>$label</td>\n";
1473 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1475 'select_submit'=> $submit_on_change,
1477 'spec_option' =>$spec_option,
1479 'order'=> array('pos_name')
1481 echo "</td></tr>\n";
1484 //-----------------------------------------------------------------------------------------------
1485 // Payment type selector for current user.
1487 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1489 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1491 if ($category == PM_CASH) // only cash
1492 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1493 elseif ($category == PM_CREDIT) // only delayed payments
1494 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1495 elseif (!$prepayments)
1496 $sql .= " WHERE days_before_due>=0";
1498 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1500 'select_submit'=> $submit_on_change,
1506 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1509 echo "<td class='label'>$label</td>\n";
1512 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1516 //-----------------------------------------------------------------------------------------------
1518 function class_list($name, $selected_id=null, $submit_on_change=false)
1520 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1522 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1524 'select_submit'=> $submit_on_change,
1530 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1533 echo "<td>$label</td>\n";
1535 echo class_list($name, $selected_id, $submit_on_change);
1539 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1541 echo "<tr><td class='label'>$label</td>";
1542 class_list_cells(null, $name, $selected_id, $submit_on_change);
1546 //-----------------------------------------------------------------------------------------------
1547 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1549 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1550 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1551 array('order'=>'category_id',
1552 'spec_option' => $spec_opt,
1554 'select_submit'=> $submit_on_change,
1559 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1562 echo "<td>$label</td>\n";
1564 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1568 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1570 echo "<tr><td class='label'>$label</td>";
1571 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1575 //-----------------------------------------------------------------------------------------------
1577 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1581 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1583 return combo_input($name, $selected_id, $sql, 'id', 'name',
1585 'format' => '_format_account',
1586 'order' => array('class_id', 'id', 'parent'),
1587 'spec_option' =>$all_option,
1588 'spec_id' => $all_items
1592 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1595 echo "<td>$label</td>\n";
1597 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1601 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1603 echo "<tr><td class='label'>$label</td>";
1604 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1609 //-----------------------------------------------------------------------------------------------
1610 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1611 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1613 if ($skip_bank_accounts)
1614 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1615 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1616 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1617 ."ON chart.account_code=acc.account_code
1618 WHERE acc.account_code IS NULL
1619 AND chart.account_type=type.id";
1621 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1622 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1623 WHERE chart.account_type=type.id";
1625 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1627 'format' => '_format_account',
1628 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1631 'order' => array('type.class_id','type.id','account_code'),
1632 'search_box' => $cells,
1633 'search_submit' => false,
1637 'select_submit'=> $submit_on_change,
1640 'show_inactive' => $all
1645 function _format_account($row)
1647 return $row[0] . " " . $row[1];
1650 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1651 $skip_bank_accounts=false, $cells=false, $all_option=false,
1652 $submit_on_change=false, $all=false)
1655 echo "<td>$label</td>\n";
1657 echo gl_all_accounts_list($name, $selected_id,
1658 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1662 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1663 $skip_bank_accounts=false, $cells=false, $all_option=false)
1665 echo "<tr><td class='label'>$label</td>";
1666 gl_all_accounts_list_cells(null, $name, $selected_id,
1667 $skip_bank_accounts, $cells, $all_option);
1671 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1674 $items['0'] = strlen($name_no) ? $name_no : _("No");
1675 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1677 return array_selector($name, $selected_id, $items,
1679 'select_submit'=> $submit_on_change,
1680 'async' => false ) ); // FIX?
1683 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1686 echo "<td>$label</td>\n";
1688 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1692 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1694 echo "<tr><td class='label'>$label</td>";
1695 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1699 //------------------------------------------------------------------------------------------------
1701 function languages_list($name, $selected_id=null, $all_option=false)
1703 global $installed_languages;
1707 $items[''] = $all_option;
1708 foreach ($installed_languages as $lang)
1709 $items[$lang['code']] = $lang['name'];
1710 return array_selector($name, $selected_id, $items);
1713 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1716 echo "<td>$label</td>\n";
1718 echo languages_list($name, $selected_id, $all_option);
1722 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1724 echo "<tr><td class='label'>$label</td>";
1725 languages_list_cells(null, $name, $selected_id, $all_option);
1729 //------------------------------------------------------------------------------------------------
1731 function bank_account_types_list($name, $selected_id=null)
1733 global $bank_account_types;
1735 return array_selector($name, $selected_id, $bank_account_types);
1738 function bank_account_types_list_cells($label, $name, $selected_id=null)
1741 echo "<td>$label</td>\n";
1743 echo bank_account_types_list($name, $selected_id);
1747 function bank_account_types_list_row($label, $name, $selected_id=null)
1749 echo "<tr><td class='label'>$label</td>";
1750 bank_account_types_list_cells(null, $name, $selected_id);
1754 //------------------------------------------------------------------------------------------------
1755 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1757 global $payment_person_types;
1760 foreach ($payment_person_types as $key=>$type)
1762 if ($key != PT_WORKORDER)
1763 $items[$key] = $type;
1765 return array_selector($name, $selected_id, $items,
1766 array( 'select_submit'=> $submit_on_change ) );
1769 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1772 echo "<td>$label</td>\n";
1774 echo payment_person_types_list($name, $selected_id, $related);
1778 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1780 echo "<tr><td class='label'>$label</td>";
1781 payment_person_types_list_cells(null, $name, $selected_id, $related);
1785 //------------------------------------------------------------------------------------------------
1787 function wo_types_list($name, $selected_id=null)
1789 global $wo_types_array;
1791 return array_selector($name, $selected_id, $wo_types_array,
1792 array( 'select_submit'=> true, 'async' => true ) );
1795 function wo_types_list_row($label, $name, $selected_id=null)
1797 echo "<tr><td class='label'>$label</td><td>\n";
1798 echo wo_types_list($name, $selected_id);
1799 echo "</td></tr>\n";
1802 //------------------------------------------------------------------------------------------------
1804 function dateformats_list_row($label, $name, $value=null)
1806 global $dateformats;
1808 echo "<tr><td class='label'>$label</td>\n<td>";
1809 echo array_selector( $name, $value, $dateformats );
1810 echo "</td></tr>\n";
1813 function dateseps_list_row($label, $name, $value=null)
1817 echo "<tr><td class='label'>$label</td>\n<td>";
1818 echo array_selector( $name, $value, $dateseps );
1819 echo "</td></tr>\n";
1822 function thoseps_list_row($label, $name, $value=null)
1826 echo "<tr><td class='label'>$label</td>\n<td>";
1827 echo array_selector( $name, $value, $thoseps );
1828 echo "</td></tr>\n";
1831 function decseps_list_row($label, $name, $value=null)
1835 echo "<tr><td class='label'>$label</td>\n<td>";
1836 echo array_selector( $name, $value, $decseps );
1837 echo "</td></tr>\n";
1840 function themes_list_row($label, $name, $value=null)
1842 global $path_to_root;
1844 $path = $path_to_root.'/themes/';
1846 $themedir = opendir($path);
1847 while(false !== ($fname = readdir($themedir)))
1849 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1851 $themes[$fname] = $fname;
1856 echo "<tr><td class='label'>$label</td>\n<td>";
1857 echo array_selector( $name, $value, $themes );
1858 echo "</td></tr>\n";
1861 function pagesizes_list_row($label, $name, $value=null)
1866 foreach ($pagesizes as $pz)
1869 echo "<tr><td class='label'>$label</td>\n<td>";
1870 echo array_selector( $name, $value, $items );
1871 echo "</td></tr>\n";
1874 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1876 global $systypes_array;
1878 // emove non-voidable transactions if needed
1879 $systypes = array_diff_key($systypes_array, array_flip($exclude));
1880 return array_selector($name, $value, $systypes,
1882 'spec_option'=> $spec_opt,
1883 'spec_id' => ALL_NUMERIC,
1884 'select_submit'=> $submit_on_change,
1890 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1893 echo "<td>$label</td>\n";
1895 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
1899 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1901 echo "<tr><td class='label'>$label</td>";
1902 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
1906 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1908 global $systypes_array;
1911 echo "<td>$label</td>\n";
1914 $items = $systypes_array;
1916 // exclude quotes, orders and dimensions
1917 foreach (array(ST_PURCHORDER, ST_WORKORDER, ST_SALESORDER, ST_DIMENSION,
1918 ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
1919 unset($items[$excl]);
1921 echo array_selector($name, $value, $items,
1923 'spec_option'=> _("All"),
1925 'select_submit'=> $submit_on_change,
1932 function cust_allocations_list_cells($label, $name, $selected=null)
1940 $all_items=>_("All Types"),
1941 '1'=> _("Sales Invoices"),
1942 '2'=> _("Overdue Invoices"),
1943 '3' => _("Payments"),
1944 '4' => _("Credit Notes"),
1945 '5' => _("Delivery Notes")
1947 echo array_selector($name, $selected, $allocs);
1951 function supp_allocations_list_cell($name, $selected=null)
1957 $all_items=>_("All Types"),
1958 '1'=> _("Invoices"),
1959 '2'=> _("Overdue Invoices"),
1960 '3' => _("Payments"),
1961 '4' => _("Credit Notes"),
1962 '5' => _("Overdue Credit Notes")
1964 echo array_selector($name, $selected, $allocs);
1968 function supp_transactions_list_cell($name, $selected=null)
1974 $all_items=>_("All Types"),
1976 '1'=> _("Invoices"),
1977 '2'=> _("Overdue Invoices"),
1978 '3' => _("Payments"),
1979 '4' => _("Credit Notes"),
1980 '5' => _("Overdue Credit Notes")
1983 echo array_selector($name, $selected, $allocs);
1987 function policy_list_cells($label, $name, $selected=null)
1992 echo array_selector($name, $selected,
1993 array( '' => _("Automatically put balance on back order"),
1994 'CAN' => _("Cancel any quantites not delivered")) );
1998 function policy_list_row($label, $name, $selected=null)
2000 echo "<tr><td class='label'>$label</td>";
2001 policy_list_cells(null, $name, $selected);
2005 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2010 echo array_selector($name, $selected,
2011 array( 'Return' => _("Items Returned to Inventory Location"),
2012 'WriteOff' => _("Items Written Off")),
2013 array( 'select_submit'=> $submit_on_change ) );
2017 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2019 echo "<tr><td class='label'>$label</td>";
2020 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2024 function number_list($name, $selected, $from, $to, $no_option=false)
2027 for ($i = $from; $i <= $to; $i++)
2030 return array_selector($name, $selected, $items,
2031 array( 'spec_option' => $no_option,
2032 'spec_id' => ALL_NUMERIC) );
2035 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2040 echo number_list($name, $selected, $from, $to, $no_option);
2044 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2046 echo "<tr><td class='label'>$label</td>";
2047 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2051 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2052 $submit_on_change=true)
2054 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2055 ." GROUP BY profile";
2056 $result = db_query($sql, 'cannot get all profile names');
2057 $profiles = array();
2058 while($myrow=db_fetch($result)) {
2059 $profiles[$myrow['profile']] = $myrow['profile'];
2064 echo "<td class='label'>$label</td>\n";
2067 echo array_selector($name, $selected_id, $profiles,
2068 array( 'select_submit'=> $submit_on_change,
2069 'spec_option'=>$spec_opt,
2073 echo "</td></tr>\n";
2076 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2078 static $printers; // query only once for page display
2081 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2082 $result = db_query($sql, 'cannot get all printers');
2083 $printers = array();
2084 while($myrow=db_fetch($result)) {
2085 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2088 return array_selector($name, $selected_id, $printers,
2089 array( 'select_submit'=> $submit_on_change,
2090 'spec_option'=>$spec_opt,
2095 //------------------------------------------------------------------------------------------------
2097 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2100 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2102 $sql .= " WHERE type=$type";
2104 return combo_input($name, $selected_id, $sql, 'id', 'description',
2107 'order' => 'description',
2108 'select_submit'=> $submit_on_change,
2114 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2117 echo "<td>$label</td>\n";
2119 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2123 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2125 echo "<tr><td class='label'>$label</td>";
2126 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2131 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2133 global $quick_actions;
2135 echo "<tr><td class='label'>$label</td><td>";
2136 echo array_selector($name, $selected_id, $quick_actions,
2138 'select_submit'=> $submit_on_change
2140 echo "</td></tr>\n";
2143 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2145 global $quick_entry_types;
2147 echo "<tr><td class='label'>$label</td><td>";
2148 echo array_selector($name, $selected_id, $quick_entry_types,
2150 'select_submit'=> $submit_on_change
2152 echo "</td></tr>\n";
2155 function record_status_list_row($label, $name) {
2156 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2159 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2161 global $class_types;
2163 echo "<tr><td class='label'>$label</td><td>";
2164 echo array_selector($name, $selected_id, $class_types,
2166 'select_submit'=> $submit_on_change
2168 echo "</td></tr>\n";
2171 //------------------------------------------------------------------------------------------------
2173 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2174 $show_inactive = false)
2178 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2180 return combo_input($name, $selected_id, $sql, 'id', 'description',
2182 'spec_option'=>$new_item ? _("New role") : false,
2184 'select_submit'=> $submit_on_change,
2185 'show_inactive' => $show_inactive
2189 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2190 $show_inactive = false)
2193 echo "<td>$label</td>\n";
2195 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2199 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2200 $show_inactive = false)
2202 echo "<tr><td class='label'>$label</td>";
2203 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2207 function tab_list_row($label, $name, $selected_id=null, $all = false)
2209 global $installed_extensions;
2212 foreach ($_SESSION['App']->applications as $app) {
2213 $tabs[$app->id] = access_string($app->name, true);
2215 if ($all) { // add also not active ext. modules
2216 foreach ($installed_extensions as $ext) {
2217 if ($ext['type'] == 'module' && !$ext['active'])
2218 $tabs[$ext['tab']] = access_string($ext['title'], true);
2222 echo "<td class='label'>$label</td><td>\n";
2223 echo array_selector($name, $selected_id, $tabs);
2224 echo "</td></tr>\n";
2227 //-----------------------------------------------------------------------------------------------
2229 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2232 global $path_to_root;
2233 include_once($path_to_root . "/admin/db/tags_db.inc");
2234 $results = get_tags($type, $all);
2236 while ($tag = db_fetch($results))
2237 $tags[$tag['id']] = $tag['name'];
2239 if (!isset($tags)) {
2240 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2243 return array_selector($name, null, $tags,
2246 'height' => $height,
2247 'spec_option'=> $spec_opt,
2252 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2255 echo "<td>$label</td>\n";
2257 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2262 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2264 echo "<tr><td class='label'>$label</td>";
2265 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2269 //---------------------------------------------------------------------------------------------
2270 // List of sets of active extensions
2272 function extset_list($name, $value=null, $submit_on_change=false)
2274 global $db_connections;
2277 foreach ($db_connections as $comp)
2278 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2279 return array_selector( $name, $value, $items,
2281 'spec_option'=> _("Available and/or installed"),
2283 'select_submit'=> $submit_on_change,
2288 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2291 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2296 if (@$filter['class']) {
2297 $where[] = 'type='.db_escape($filter['class']);
2300 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2301 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2302 if (@$filter['multi']) { // contact category selector for person
2306 return combo_input($name, $selected_id, $sql, 'id', 'name',
2309 'height' => $multi ? 5:1,
2310 'category' => $groups,
2311 'select_submit'=> $submit_on_change,
2317 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2319 echo "<tr><td class='label'>$label</td><td>";
2320 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2321 echo "</td></tr>\n";
2324 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2326 global $pterm_types;
2328 echo "<tr><td class='label'>$label</td><td>";
2329 echo array_selector($name, $selected_id, $pterm_types,
2331 'select_submit'=> $submit_on_change
2333 echo "</td></tr>\n";
2336 function coa_list_row($label, $name, $value=null)
2338 global $path_to_root, $installed_extensions;
2340 $path = $path_to_root.'/sql/';
2342 $sqldir = opendir($path);
2343 while (false !== ($fname = readdir($sqldir)))
2345 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2347 $ext = array_search_value($fname, $installed_extensions, 'sql');
2349 $descr = $ext['name'];
2350 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2351 $descr = _("Standard new company American COA (4 digit)");
2352 } elseif ($fname == 'en_US-demo.sql') {
2353 $descr = _("Standard American COA (4 digit) with demo data");
2357 $coas[$fname] = $descr;
2362 echo "<tr><td class='label'>$label</td>\n<td>";
2363 echo array_selector( $name, $value, $coas );
2364 echo "</td></tr>\n";
2367 function payment_services($name)
2369 global $payment_services;
2371 $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2373 return array_selector($name, null, $services, array(
2374 'spec_option'=> _("No payment Link"),
2379 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2381 global $tax_algorithms;
2383 return array_selector($name, $value, $tax_algorithms,
2385 'select_submit'=> $submit_on_change,
2391 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2394 echo "<td>$label</td>\n";
2396 echo tax_algorithm_list($name, $value, $submit_on_change);
2400 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2402 echo "<tr><td class='label'>$label</td>";
2403 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2406 //----------------------------------------------------------------------------------------------
2408 function subledger_list($name, $account, $selected_id=null)
2412 $type = is_subledger_account($account);
2417 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2419 .TB_PREF."debtors_master d,"
2420 .TB_PREF."cust_branch c
2421 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2423 $sql = "SELECT supplier_id as id, supp_ref as name
2425 .TB_PREF."suppliers s
2426 WHERE s.payable_account=".db_escape($account);
2428 $mode = get_company_pref('no_customer_list');
2430 return combo_input($name, $selected_id, $sql, 'id', 'name',
2438 function subledger_list_cells($label, $name, $account, $selected_id=null)
2441 echo "<td>$label</td>\n";
2443 echo subledger_list($name, $account, $selected_id);
2447 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2448 $submit_on_change=false, $show_inactive=false, $editkey = false)
2450 echo "<tr><td class='label'>$label</td><td nowrap>";
2451 echo subledger_list($name, $account, $selected_id);
2452 echo "</td>\n</tr>\n";