2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/banking.inc");
13 include_once($path_to_root . "/includes/types.inc");
14 include_once($path_to_root . "/includes/current_user.inc");
16 define('SEARCH_BUTTON', "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
17 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ");
19 define('SELECT_BUTTON', "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
20 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ");
22 //----------------------------------------------------------------------------
23 // Universal sql combo generator
24 // $sql must return selector values and selector texts in columns 0 & 1
25 // Options are merged with defaults.
27 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
32 $opts = array( // default options
33 'where'=> array(), // additional constraints
34 'order' => $namefield, // list sort order
35 // special option parameters
36 'spec_option'=>false, // option text or false
37 'spec_id' => 0, // option id
38 // submit on select parameters
39 'default' => '', // default value when $_POST is not set
40 'multi' => false, // multiple select
41 'select_submit' => false, //submit on select: true/false
42 'async' => true, // select update via ajax (true) vs _page_body reload
43 // search box parameters
45 'search_box' => false, // name or true/false
46 'type' => 0, // type of extended selector:
47 // 0 - with (optional) visible search box, search by fragment inside id
48 // 1 - with hidden search box, search by option text
49 // 2 - with (optional) visible search box, search by fragment at the start of id
50 // 3 - TODO reverse: box with hidden selector available via enter; this
51 // would be convenient for optional ad hoc adding of new item
52 'search_submit' => true, //search submit button: true/false
53 'size' => 8, // size and max of box tag
55 'height' => false, // number of lines in select box
56 'cells' => false, // combo displayed as 2 <td></td> cells
57 'search' => array(), // sql field names to search
58 'format' => null, // format functions for regular options
60 'box_hint' => null, // box/selectors hints; null = std see below
61 'category' => false, // category column name or false
62 'show_inactive' => false, // show inactive records.
63 'editable' => false // false, or length of editable entry field
65 // ------ merge options with defaults ----------
67 $opts = array_merge($opts, $options);
68 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
70 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
71 // select content filtered by search field:
72 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
73 // select set by select content field
74 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
76 $select_submit = $opts['select_submit'];
77 $spec_id = $opts['spec_id'];
78 $spec_option = $opts['spec_option'];
79 if ($opts['type'] == 0) {
82 } elseif($opts['type'] == 1) {
90 $disabled = $opts['disabled'] ? "disabled" : '';
91 $multi = $opts['multi'];
93 if(!count($opts['search'])) {
94 $opts['search'] = array($by_id ? $valfield : $namefield);
96 if ($opts['sel_hint'] === null)
97 $opts['sel_hint'] = $by_id || $search_box==false ?
98 '' : _('Press Space tab for search pattern entry');
100 if ($opts['box_hint'] === null)
101 $opts['box_hint'] = $search_box && $search_submit != false ?
102 ($by_id ? _('Enter code fragment to search or * for all')
103 : _('Enter description fragment to search or * for all')) :'';
105 if ($selected_id == null) {
106 $selected_id = get_post($name, (string)$opts['default']);
108 if(!is_array($selected_id))
109 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
111 $txt = get_post($search_box);
114 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
115 if ($by_id) $txt = $_POST[$name];
118 $Ajax->activate('_page_body');
120 $Ajax->activate($name);
122 if (isset($_POST[$search_button])) {
124 $Ajax->activate('_page_body');
126 $Ajax->activate($name);
129 // search related sql modifications
131 $rel = "rel='$search_box'"; // set relation to list
132 if ($opts['search_submit']) {
133 if (isset($_POST[$search_button])) {
134 $selected_id = array(); // ignore selected_id while search
136 $Ajax->activate('_page_body');
138 $Ajax->activate($name);
141 if ($spec_option === false && $selected_id == array())
144 $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id));
149 foreach($opts['search'] as $i=> $s)
150 $opts['search'][$i] = $s . " LIKE "
151 .db_escape(($class=='combo3' ? '' : '%').$txt.'%');
152 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
158 if (count($opts['where'])) {
159 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
160 $where .= '('. implode($opts['where'], ' AND ') . ')';
161 $group_pos = strpos($sql, 'GROUP BY');
163 $group = substr($sql, $group_pos);
164 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
169 if ($opts['order'] != false) {
170 if (!is_array($opts['order']))
171 $opts['order'] = array($opts['order']);
172 $sql .= ' ORDER BY '.implode(',',$opts['order']);
176 // ------ make selector ----------
177 $selector = $first_opt = '';
182 //if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
183 //if($name=='curr_default') display_notification($opts['search_submit']);
184 if($result = db_query($sql)) {
185 while ($contact_row = db_fetch($result)) {
186 $value = $contact_row[0];
187 $descr = $opts['format']==null ? $contact_row[1] :
188 call_user_func($opts['format'], $contact_row);
190 if (get_post($search_button) && ($txt == $value)) {
191 $selected_id[] = $value;
194 if (in_array((string)$value, $selected_id, true)) {
197 $edit = $opts['editable'] && $contact_row['editable']
198 && (@$_POST[$search_box] == $value)
199 ? $contact_row[1] : false; // get non-formatted description
201 break; // selected field is editable - abandon list construction
203 // show selected option even if inactive
204 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
207 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
209 if ($first_id === false) {
213 $cat = $contact_row[$opts['category']];
214 if ($opts['category'] !== false && $cat != $lastcat){
215 $selector .= "<optgroup label='".$cat."'>\n";
218 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
220 db_free_result($result);
223 // Prepend special option.
224 if ($spec_option !== false) { // if special option used - add it
225 $first_id = $spec_id;
226 $first_opt = $spec_option;
228 // if($first_id !== false) {
229 $sel = $found===false ? 'selected' : '';
230 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
231 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
235 if ($found===false) {
236 $selected_id = array($first_id);
239 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
241 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
242 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
243 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
244 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
246 if ($by_id && ($search_box != false || $opts['editable']) ) {
247 // on first display show selector list
248 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
249 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
250 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
251 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
252 set_focus($name.'_text'); // prevent lost focus
253 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
254 set_focus($name); // prevent lost focus
255 if (!$opts['editable'])
257 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
260 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
262 // span for select list/input field update
263 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
265 // if selectable or editable list is used - add select button
266 if ($select_submit != false || $search_button) {
267 // button class selects form reload/ajax selector update
268 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
269 (fallback_mode() ? '' : 'display:none;'),
270 '_'.$name.'_update')."\n";
272 // ------ make combo ----------
274 if ($search_box != false) {
275 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
276 $opts['size']."' maxlength='".$opts['max'].
277 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
278 .$opts['box_hint']."'"
279 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
281 if ($search_submit != false || $opts['editable']) {
282 $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
283 (fallback_mode() ? '' : 'display:none;'),
284 $search_submit ? $search_submit : "_{$name}_button")."\n";
287 default_focus(($search_box && $by_id) ? $search_box : $name);
289 if ($search_box && $opts['cells'])
290 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector</td>";
292 $str = $edit_entry.$selector;
298 Returns true if selector $name is subject to update.
300 function list_updated($name)
302 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
304 //----------------------------------------------------------------------------------------------
305 // Universal array combo generator
306 // $items is array of options 'value' => 'description'
307 // Options is reduced set of combo_selector options and is merged with defaults.
309 function array_selector($name, $selected_id, $items, $options=null)
313 $opts = array( // default options
314 'spec_option'=>false, // option text or false
315 'spec_id' => 0, // option id
316 'select_submit' => false, //submit on select: true/false
317 'async' => true, // select update via ajax (true) vs _page_body reload
318 'default' => '', // default value when $_POST is not set
319 'multi'=>false, // multiple select
320 // search box parameters
321 'height' => false, // number of lines in select box
325 // ------ merge options with defaults ----------
327 $opts = array_merge($opts, $options);
328 $select_submit = $opts['select_submit'];
329 $spec_id = $opts['spec_id'];
330 $spec_option = $opts['spec_option'];
331 $disabled = $opts['disabled'] ? "disabled" : '';
332 $multi = $opts['multi'];
334 if ($selected_id == null) {
335 $selected_id = get_post($name, $opts['default']);
337 if(!is_array($selected_id))
338 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
340 if (isset($_POST[ '_'.$name.'_update'])) {
342 $Ajax->activate('_page_body');
344 $Ajax->activate($name);
347 // ------ make selector ----------
348 $selector = $first_opt = '';
351 //if($name=='SelectStockFromList') display_error($sql);
352 foreach($items as $value=>$descr) {
354 if (in_array((string)$value, $selected_id, true)) {
358 if ($first_id === false) {
362 $selector .= "<option $sel value='$value'>$descr</option>\n";
365 if ($first_id!==false) {
366 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
367 $selector = sprintf($first_opt, $sel).$selector;
369 // Prepend special option.
370 if ($spec_option !== false) { // if special option used - add it
371 $first_id = $spec_id;
372 $first_opt = $spec_option;
373 $sel = $found===false ? 'selected' : '';
374 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
378 if ($found===false) {
379 $selected_id = array($first_id);
381 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
383 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
384 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
385 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
386 . $opts['sel_hint']."'>".$selector."</select>\n";
388 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
390 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
392 if ($select_submit != false) { // if submit on change is used - add select button
393 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
394 (fallback_mode() ? '' : 'display:none;'),
395 '_'.$name.'_update')."\n";
397 default_focus($name);
401 //----------------------------------------------------------------------------------------------
403 function _format_add_curr($row)
405 static $company_currency;
407 if ($company_currency == null)
409 $company_currency = get_company_currency();
411 return $row[1] . ($row[2] == $company_currency ?
412 '' : (" - " . $row[2]));
415 function add_edit_combo($type)
417 global $path_to_root, $popup_editors, $SysPrefs;
419 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
422 $theme_path = $path_to_root . '/themes/' . user_theme();
424 $key = $popup_editors[$type][1];
425 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
426 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
427 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
430 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
431 $all=false, $editkey = false)
434 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
436 $mode = get_company_pref('no_supplier_list');
439 set_editor('supplier', $name, $editkey);
441 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
443 'format' => '_format_add_curr',
444 'order' => array('supp_ref'),
445 'search_box' => $mode!=0,
447 'search' => array("supp_ref","supp_name","gst_no"),
448 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
449 'spec_id' => ALL_TEXT,
450 'select_submit'=> $submit_on_change,
452 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
453 _('Select supplier'),
454 'show_inactive'=>$all
457 $ret .= add_edit_combo('supplier');
461 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
462 $submit_on_change=false, $all=false, $editkey = false)
465 echo "<td>$label</td><td>\n";
466 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
471 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
472 $submit_on_change=false, $all=false, $editkey = false)
474 echo "<tr><td class='label'>$label</td><td>";
475 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
479 //----------------------------------------------------------------------------------------------
481 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
482 $show_inactive=false, $editkey = false)
485 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
487 $mode = get_company_pref('no_customer_list');
490 set_editor('customer', $name, $editkey);
492 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
494 'format' => '_format_add_curr',
495 'order' => array('debtor_ref'),
496 'search_box' => $mode!=0,
499 'search' => array("debtor_ref","name","tax_id"),
500 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
501 'spec_id' => ALL_TEXT,
502 'select_submit'=> $submit_on_change,
504 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
505 _('Select customer'),
506 'show_inactive' => $show_inactive
509 $ret .= add_edit_combo('customer');
513 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
514 $submit_on_change=false, $show_inactive=false, $editkey = false)
517 echo "<td>$label</td>\n";
519 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
520 $show_inactive, $editkey);
524 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
525 $submit_on_change=false, $show_inactive=false, $editkey = false)
528 echo "<tr><td class='label'>$label</td><td nowrap>";
529 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
530 $show_inactive, $editkey);
531 echo "</td>\n</tr>\n";
534 //------------------------------------------------------------------------------------------------
536 function customer_branches_list($customer_id, $name, $selected_id=null,
537 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
540 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
541 WHERE debtor_no=" . db_escape($customer_id)." ";
544 set_editor('branch', $name, $editkey);
546 $where = $enabled ? array("inactive = 0") : array();
547 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
550 'order' => array('branch_ref'),
551 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
552 'spec_id' => ALL_TEXT,
553 'select_submit'=> $submit_on_change,
554 'sel_hint' => _('Select customer branch')
558 $ret .= add_edit_combo('branch');
562 //------------------------------------------------------------------------------------------------
564 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
565 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
568 echo "<td>$label</td>\n";
570 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
571 $submit_on_change, $editkey);
575 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
576 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
578 echo "<tr><td class='label'>$label</td>";
579 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
580 $all_option, $enabled, $submit_on_change, $editkey);
584 //------------------------------------------------------------------------------------------------
586 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
589 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations";
591 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
593 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
594 'spec_id' => ALL_TEXT,
595 'select_submit'=> $submit_on_change
599 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
602 echo "<td>$label</td>\n";
604 echo locations_list($name, $selected_id, $all_option, $submit_on_change);
608 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
610 echo "<tr><td class='label'>$label</td>";
611 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
615 //-----------------------------------------------------------------------------------------------
617 function currencies_list($name, $selected_id=null, $submit_on_change=false)
619 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
621 // default to the company currency
622 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
624 'select_submit'=> $submit_on_change,
625 'default' => get_company_currency(),
630 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
633 echo "<td>$label</td>\n";
635 echo currencies_list($name, $selected_id, $submit_on_change);
639 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
641 echo "<tr><td class='label'>$label</td>";
642 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
646 //---------------------------------------------------------------------------------------------------
648 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
651 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
653 // default to the company current fiscal year
655 return combo_input($name, $selected_id, $sql, 'id', '',
658 'default' => get_company_pref('f_year'),
659 'format' => '_format_fiscalyears',
660 'select_submit'=> $submit_on_change,
665 function _format_fiscalyears($row)
667 return sql2date($row[1]) . " - " . sql2date($row[2])
668 . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
671 function fiscalyears_list_cells($label, $name, $selected_id=null)
674 echo "<td>$label</td>\n";
676 echo fiscalyears_list($name, $selected_id);
680 function fiscalyears_list_row($label, $name, $selected_id=null)
682 echo "<tr><td class='label'>$label</td>";
683 fiscalyears_list_cells(null, $name, $selected_id);
686 //------------------------------------------------------------------------------------
688 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
689 $submit_on_change=false, $showclosed=false, $showtype=1)
691 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
694 'order' => 'reference',
695 'spec_option'=>$no_option ? $showname : false,
697 'select_submit'=> $submit_on_change,
702 $options['where'][] = "closed=0";
704 $options['where'][] = "type_=".db_escape($showtype);
706 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
709 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
710 $showclosed=false, $showtype=0, $submit_on_change=false)
713 echo "<td>$label</td>\n";
715 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
719 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
720 $showclosed=false, $showtype=0, $submit_on_change=false)
722 echo "<tr><td class='label'>$label</td>";
723 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
724 $showclosed, $showtype, $submit_on_change);
728 //---------------------------------------------------------------------------------------------------
730 function stock_items_list($name, $selected_id=null, $all_option=false,
731 $submit_on_change=false, $opts=array(), $editkey = false)
734 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
735 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
738 set_editor('item', $name, $editkey);
740 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
743 'format' => '_format_stock_items',
744 'spec_option' => $all_option===true ? _("All Items") : $all_option,
745 'spec_id' => ALL_TEXT,
746 'search_box' => true,
747 'search' => array("stock_id", "c.description","s.description"),
748 'search_submit' => get_company_pref('no_item_list')!=0,
750 'select_submit'=> $submit_on_change,
752 'order' => array('c.description','stock_id')
755 $ret .= add_edit_combo('item');
759 function _format_stock_items($row)
761 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
764 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
765 $submit_on_change=false, $all=false, $editkey = false)
768 echo "<td>$label</td>\n";
769 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
770 array('cells'=>true, 'show_inactive'=>$all), $editkey);
773 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
776 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
780 //---------------------------------------------------------------------------------------------------
782 // Select item via foreign code.
784 function sales_items_list($name, $selected_id=null, $all_option=false,
785 $submit_on_change=false, $type='', $opts=array())
788 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
789 i.inactive, if(count(*)>1, '0', s.editable) as editable
791 ".TB_PREF."stock_master s,
792 ".TB_PREF."item_codes i
794 ".TB_PREF."stock_category c
795 ON i.category_id=c.category_id
796 WHERE i.stock_id=s.stock_id";
799 if ($type == 'local') { // exclude foreign codes
800 $sql .= " AND !i.is_foreign";
801 } elseif ($type == 'kits') { // sales kits
802 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
804 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
805 $sql .= " GROUP BY i.item_code";
807 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
810 'format' => '_format_stock_items',
811 'spec_option' => $all_option===true ? _("All Items") : $all_option,
812 'spec_id' => ALL_TEXT,
813 'search_box' => true,
814 'search' => array("i.item_code", "c.description", "i.description"),
815 'search_submit' => get_company_pref('no_item_list')!=0,
817 'select_submit'=> $submit_on_change,
819 'order' => array('c.description','i.item_code'),
825 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
828 set_editor('item', $name, $editkey);
831 echo "<td>$label</td>\n";
832 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
833 '', array('cells'=>true));
836 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
838 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
839 'kits', array('cells'=>false, 'editable' => false));
842 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
846 echo "<td class='label'>$label</td>\n";
848 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
849 'local', array('cells'=>false, 'editable' => false));
852 //------------------------------------------------------------------------------------
854 function stock_manufactured_items_list($name, $selected_id=null,
855 $all_option=false, $submit_on_change=false)
857 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
858 array('where'=>array("mb_flag= 'M'")));
861 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
862 $all_option=false, $submit_on_change=false)
865 echo "<td>$label</td>\n";
867 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
871 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
872 $all_option=false, $submit_on_change=false)
874 echo "<tr><td class='label'>$label</td>";
875 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
878 //------------------------------------------------------------------------------------
880 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
881 $all_option=false, $submit_on_change=false, $editkey = false)
883 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
884 array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey);
887 function stock_component_items_list_cells($label, $name, $parent_stock_id,
888 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
891 echo "<td>$label</td>\n";
892 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
893 array('where'=>array("stock_id != ".db_escape($parent_stock_id)), 'cells'=>true),
896 //------------------------------------------------------------------------------------
898 function stock_costable_items_list($name, $selected_id=null,
899 $all_option=false, $submit_on_change=false)
901 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
902 array('where'=>array("mb_flag!='D'")));
905 function stock_costable_items_list_cells($label, $name, $selected_id=null,
906 $all_option=false, $submit_on_change=false)
909 echo "<td>$label</td>\n";
910 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
911 array('where'=>array("mb_flag!='D'"), 'cells'=>true));
914 //------------------------------------------------------------------------------------
915 function stock_purchasable_items_list($name, $selected_id=null,
916 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
918 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
919 array('where'=>array("NOT no_purchase"),
920 'show_inactive'=>$all), $editkey);
923 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
925 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
926 $all_option=false, $submit_on_change=false, $editkey=false)
929 echo "<td>$label</td>\n";
930 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
931 array('where'=>array("NOT no_purchase"),
933 'cells'=>true), $editkey);
936 function stock_purchasable_items_list_row($label, $name, $selected_id=null,
937 $all_option=false, $submit_on_change=false, $editkey=false)
939 echo "<tr><td class='label'>$label</td>";
940 stock_purchasable_items_list_cells(null, $name, $selected_id=null,
941 $all_option, $submit_on_change, $editkey);
945 //------------------------------------------------------------------------------------
947 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
953 echo "<td class='label'>$label</td>\n";
956 echo array_selector($name, $selected_id, $stock_types,
958 'select_submit'=> true,
959 'disabled' => !$enabled) );
963 function stock_units_list_row($label, $name, $value=null, $enabled=true)
965 $result = get_all_item_units();
968 echo "<td class='label'>$label</td>\n";
971 while($unit = db_fetch($result))
972 $units[$unit['abbr']] = $unit['name'];
974 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
979 //------------------------------------------------------------------------------------
981 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
983 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
985 return combo_input($name, $selected_id, $sql, 'id', 'name',
987 'spec_option' => $none_option,
988 'spec_id' => ALL_NUMERIC,
989 'select_submit'=> $submit_on_change,
994 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
995 $submit_on_change=false)
998 echo "<td>$label</td>\n";
1000 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1004 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1005 $submit_on_change=false)
1007 echo "<tr><td class='label'>$label</td>";
1008 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1012 //------------------------------------------------------------------------------------
1014 function tax_groups_list($name, $selected_id=null,
1015 $none_option=false, $submit_on_change=false)
1017 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1019 return combo_input($name, $selected_id, $sql, 'id', 'name',
1022 'spec_option' => $none_option,
1023 'spec_id' => ALL_NUMERIC,
1024 'select_submit'=> $submit_on_change,
1029 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1032 echo "<td>$label</td>\n";
1034 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1038 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1040 echo "<tr><td class='label'>$label</td>";
1041 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1045 //------------------------------------------------------------------------------------
1047 function item_tax_types_list($name, $selected_id=null)
1049 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1050 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1053 function item_tax_types_list_cells($label, $name, $selected_id=null)
1056 echo "<td>$label</td>\n";
1058 echo item_tax_types_list($name, $selected_id);
1062 function item_tax_types_list_row($label, $name, $selected_id=null)
1064 echo "<tr><td class='label'>$label</td>";
1065 item_tax_types_list_cells(null, $name, $selected_id);
1069 //------------------------------------------------------------------------------------
1071 function shippers_list($name, $selected_id=null)
1073 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1074 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1075 array('order'=>array('shipper_name')));
1078 function shippers_list_cells($label, $name, $selected_id=null)
1081 echo "<td>$label</td>\n";
1083 echo shippers_list($name, $selected_id);
1087 function shippers_list_row($label, $name, $selected_id=null)
1089 echo "<tr><td class='label'>$label</td>";
1090 shippers_list_cells(null, $name, $selected_id);
1094 //-------------------------------------------------------------------------------------
1096 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1098 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1099 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1100 array('order'=>array('salesman_name'),
1101 'spec_option' => $spec_opt,
1102 'spec_id' => ALL_NUMERIC));
1105 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1108 echo "<td>$label</td>\n";
1110 echo sales_persons_list($name, $selected_id, $spec_opt);
1114 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1116 echo "<tr><td class='label'>$label</td>";
1117 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1121 //------------------------------------------------------------------------------------
1123 function sales_areas_list($name, $selected_id=null)
1125 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1126 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1129 function sales_areas_list_cells($label, $name, $selected_id=null)
1132 echo "<td>$label</td>\n";
1134 echo sales_areas_list($name, $selected_id);
1138 function sales_areas_list_row($label, $name, $selected_id=null)
1140 echo "<tr><td class='label'>$label</td>";
1141 sales_areas_list_cells(null, $name, $selected_id);
1145 //------------------------------------------------------------------------------------
1147 function sales_groups_list($name, $selected_id=null, $special_option=false)
1149 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1150 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1151 'spec_option' => $special_option===true ? ' ' : $special_option,
1152 'order' => 'description', 'spec_id' => 0,
1156 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1159 echo "<td>$label</td>\n";
1161 echo sales_groups_list($name, $selected_id, $special_option);
1165 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1167 echo "<tr><td class='label'>$label</td>";
1168 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1172 //------------------------------------------------------------------------------------
1174 function _format_template_items($row)
1176 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1179 function templates_list($name, $selected_id=null, $special_option=false)
1181 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1182 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1183 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1184 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1185 'format' => '_format_template_items',
1186 'spec_option' => $special_option===true ? ' ' : $special_option,
1187 'order' => 'order_no', 'spec_id' => 0,
1191 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1194 echo "<td>$label</td>\n";
1196 echo templates_list($name, $selected_id, $special_option);
1200 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1202 echo "<tr><td class='label'>$label</td>";
1203 templates_list_cells(null, $name, $selected_id, $special_option);
1207 //------------------------------------------------------------------------------------
1209 function workorders_list($name, $selected_id=null)
1211 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1212 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1215 function workorders_list_cells($label, $name, $selected_id=null)
1218 echo "<td>$label</td>\n";
1220 echo workorders_list($name, $selected_id);
1224 function workorders_list_row($label, $name, $selected_id=null)
1226 echo "<tr><td class='label'>$label</td>";
1227 workorders_list_cells(null, $name, $selected_id);
1231 //------------------------------------------------------------------------------------
1233 function payment_terms_list($name, $selected_id=null)
1235 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1236 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1239 function payment_terms_list_cells($label, $name, $selected_id=null)
1242 echo "<td>$label</td>\n";
1244 echo payment_terms_list($name, $selected_id);
1248 function payment_terms_list_row($label, $name, $selected_id=null)
1250 echo "<tr><td class='label'>$label</td>";
1251 payment_terms_list_cells(null, $name, $selected_id);
1255 //------------------------------------------------------------------------------------
1257 function credit_status_list($name, $selected_id=null)
1259 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1260 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1263 function credit_status_list_cells($label, $name, $selected_id=null)
1266 echo "<td>$label</td>\n";
1268 echo credit_status_list($name, $selected_id);
1272 function credit_status_list_row($label, $name, $selected_id=null)
1274 echo "<tr><td class='label'>$label</td>";
1275 credit_status_list_cells(null, $name, $selected_id);
1279 //-----------------------------------------------------------------------------------------------
1281 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1283 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1285 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1287 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1289 'select_submit'=> $submit_on_change,
1290 // 'async' => false,
1294 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1297 echo "<td>$label</td>\n";
1299 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1303 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1305 echo "<tr><td class='label'>$label</td>";
1306 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1310 //-----------------------------------------------------------------------------------------------
1312 function movement_types_list($name, $selected_id=null)
1314 $sql = "SELECT id, name FROM ".TB_PREF."movement_types";
1315 return combo_input($name, $selected_id, $sql, 'id', 'name', array());
1318 function movement_types_list_cells($label, $name, $selected_id=null)
1321 echo "<td>$label</td>\n";
1323 echo movement_types_list($name, $selected_id);
1327 function movement_types_list_row($label, $name, $selected_id=null)
1329 echo "<tr><td class='label'>$label</td>";
1330 movement_types_list_cells(null, $name, $selected_id);
1334 //-----------------------------------------------------------------------------------------------
1335 function _format_date($row)
1337 return sql2date($row['reconciled']);
1340 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1342 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1343 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1344 GROUP BY reconciled";
1345 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1347 'spec_option' => $special_option,
1348 'format' => '_format_date',
1350 'select_submit'=> $submit_on_change
1354 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1357 echo "<td>$label</td>\n";
1359 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1363 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1366 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1370 //-----------------------------------------------------------------------------------------------
1372 function workcenter_list($name, $selected_id=null, $all_option=false)
1375 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1377 return combo_input($name, $selected_id, $sql, 'id', 'name',
1379 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1380 'spec_id' => ALL_TEXT,
1384 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1386 default_focus($name);
1388 echo "<td>$label</td>\n";
1390 echo workcenter_list($name, $selected_id, $all_option);
1394 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1396 echo "<tr><td class='label'>$label</td>";
1397 workcenter_list_cells(null, $name, $selected_id, $all_option);
1401 //-----------------------------------------------------------------------------------------------
1403 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1405 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1406 FROM ".TB_PREF."bank_accounts";
1408 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1410 'format' => '_format_add_curr',
1411 'select_submit'=> $submit_on_change,
1412 'spec_option' => $spec_option,
1418 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1421 echo "<td>$label</td>\n";
1423 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1427 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1429 echo "<tr><td class='label'>$label</td>";
1430 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1433 //-----------------------------------------------------------------------------------------------
1435 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1438 $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
1439 FROM ".TB_PREF."bank_accounts
1440 WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
1443 echo "<tr><td class='label'>$label</td>\n";
1445 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1447 'spec_option' => $all_option,
1448 'spec_id' => ALL_TEXT,
1449 'format' => '_format_add_curr',
1450 'select_submit'=> $submit_on_change,
1453 echo "</td></tr>\n";
1455 //-----------------------------------------------------------------------------------------------
1457 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1459 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1461 default_focus($name);
1464 echo "<td class='label'>$label</td>\n";
1467 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1469 'select_submit'=> $submit_on_change,
1471 'spec_option' =>$spec_option,
1473 'order'=> array('pos_name')
1475 echo "</td></tr>\n";
1478 //-----------------------------------------------------------------------------------------------
1479 // Payment type selector for current user.
1481 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1483 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1485 if ($category == PM_CASH) // only cash
1486 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1487 elseif ($category == PM_CREDIT) // only delayed payments
1488 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1489 elseif (!$prepayments)
1490 $sql .= " WHERE days_before_due>=0";
1492 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1494 'select_submit'=> $submit_on_change,
1500 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1503 echo "<td class='label'>$label</td>\n";
1506 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1510 //-----------------------------------------------------------------------------------------------
1512 function class_list($name, $selected_id=null, $submit_on_change=false)
1514 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1516 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1518 'select_submit'=> $submit_on_change,
1524 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1527 echo "<td>$label</td>\n";
1529 echo class_list($name, $selected_id, $submit_on_change);
1533 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1535 echo "<tr><td class='label'>$label</td>";
1536 class_list_cells(null, $name, $selected_id, $submit_on_change);
1540 //-----------------------------------------------------------------------------------------------
1541 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1543 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1544 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1545 array('order'=>'category_id',
1546 'spec_option' => $spec_opt,
1548 'select_submit'=> $submit_on_change,
1553 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1556 echo "<td>$label</td>\n";
1558 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change);
1562 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1564 echo "<tr><td class='label'>$label</td>";
1565 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change);
1569 //-----------------------------------------------------------------------------------------------
1571 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1574 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1576 return combo_input($name, $selected_id, $sql, 'id', 'name',
1578 'format' => '_format_account',
1579 'order' => array('class_id', 'id', 'parent'),
1580 'spec_option' =>$all_option,
1581 'spec_id' => ALL_TEXT
1585 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1588 echo "<td>$label</td>\n";
1590 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1594 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1596 echo "<tr><td class='label'>$label</td>";
1597 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1602 //-----------------------------------------------------------------------------------------------
1603 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1604 $cells=false, $all_option=false, $submit_on_change=false, $all=false)
1606 if ($skip_bank_accounts)
1607 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1608 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1609 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1610 ."ON chart.account_code=acc.account_code
1611 WHERE acc.account_code IS NULL
1612 AND chart.account_type=type.id";
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 WHERE chart.account_type=type.id";
1618 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1620 'format' => '_format_account',
1621 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1624 'order' => array('type.class_id','type.id','account_code'),
1625 'search_box' => $cells,
1626 'search_submit' => false,
1630 'select_submit'=> $submit_on_change,
1633 'show_inactive' => $all
1638 function _format_account($row)
1640 return $row[0] . " " . $row[1];
1643 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1644 $skip_bank_accounts=false, $cells=false, $all_option=false,
1645 $submit_on_change=false, $all=false)
1648 echo "<td>$label</td>\n";
1650 echo gl_all_accounts_list($name, $selected_id,
1651 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all);
1655 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1656 $skip_bank_accounts=false, $cells=false, $all_option=false)
1658 echo "<tr><td class='label'>$label</td>";
1659 gl_all_accounts_list_cells(null, $name, $selected_id,
1660 $skip_bank_accounts, $cells, $all_option);
1664 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1667 $items['0'] = strlen($name_no) ? $name_no : _("No");
1668 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1670 return array_selector($name, $selected_id, $items,
1672 'select_submit'=> $submit_on_change,
1673 'async' => false ) ); // FIX?
1676 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1679 echo "<td>$label</td>\n";
1681 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1685 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1687 echo "<tr><td class='label'>$label</td>";
1688 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1692 //------------------------------------------------------------------------------------------------
1694 function languages_list($name, $selected_id=null, $all_option=false)
1696 global $installed_languages;
1700 $items[''] = $all_option;
1701 foreach ($installed_languages as $lang)
1702 $items[$lang['code']] = $lang['name'];
1703 return array_selector($name, $selected_id, $items);
1706 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1709 echo "<td>$label</td>\n";
1711 echo languages_list($name, $selected_id, $all_option);
1715 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1717 echo "<tr><td class='label'>$label</td>";
1718 languages_list_cells(null, $name, $selected_id, $all_option);
1722 //------------------------------------------------------------------------------------------------
1724 function bank_account_types_list($name, $selected_id=null)
1726 global $bank_account_types;
1728 return array_selector($name, $selected_id, $bank_account_types);
1731 function bank_account_types_list_cells($label, $name, $selected_id=null)
1734 echo "<td>$label</td>\n";
1736 echo bank_account_types_list($name, $selected_id);
1740 function bank_account_types_list_row($label, $name, $selected_id=null)
1742 echo "<tr><td class='label'>$label</td>";
1743 bank_account_types_list_cells(null, $name, $selected_id);
1747 //------------------------------------------------------------------------------------------------
1748 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1750 global $payment_person_types;
1753 foreach ($payment_person_types as $key=>$type)
1755 if ($key != PT_WORKORDER)
1756 $items[$key] = $type;
1758 return array_selector($name, $selected_id, $items,
1759 array( 'select_submit'=> $submit_on_change ) );
1762 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1765 echo "<td>$label</td>\n";
1767 echo payment_person_types_list($name, $selected_id, $related);
1771 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1773 echo "<tr><td class='label'>$label</td>";
1774 payment_person_types_list_cells(null, $name, $selected_id, $related);
1778 //------------------------------------------------------------------------------------------------
1780 function wo_types_list($name, $selected_id=null)
1782 global $wo_types_array;
1784 return array_selector($name, $selected_id, $wo_types_array,
1785 array( 'select_submit'=> true, 'async' => true ) );
1788 function wo_types_list_row($label, $name, $selected_id=null)
1790 echo "<tr><td class='label'>$label</td><td>\n";
1791 echo wo_types_list($name, $selected_id);
1792 echo "</td></tr>\n";
1795 //------------------------------------------------------------------------------------------------
1797 function dateformats_list_row($label, $name, $value=null)
1801 echo "<tr><td class='label'>$label</td>\n<td>";
1802 echo array_selector( $name, $value, $SysPrefs->dateformats );
1803 echo "</td></tr>\n";
1806 function dateseps_list_row($label, $name, $value=null)
1810 echo "<tr><td class='label'>$label</td>\n<td>";
1811 echo array_selector( $name, $value, $SysPrefs->dateseps );
1812 echo "</td></tr>\n";
1815 function thoseps_list_row($label, $name, $value=null)
1819 echo "<tr><td class='label'>$label</td>\n<td>";
1820 echo array_selector( $name, $value, $SysPrefs->thoseps );
1821 echo "</td></tr>\n";
1824 function decseps_list_row($label, $name, $value=null)
1828 echo "<tr><td class='label'>$label</td>\n<td>";
1829 echo array_selector( $name, $value, $SysPrefs->decseps );
1830 echo "</td></tr>\n";
1833 function themes_list_row($label, $name, $value=null)
1835 global $path_to_root;
1837 $path = $path_to_root.'/themes/';
1839 $themedir = opendir($path);
1840 while(false !== ($fname = readdir($themedir)))
1842 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
1844 $themes[$fname] = $fname;
1849 echo "<tr><td class='label'>$label</td>\n<td>";
1850 echo array_selector( $name, $value, $themes );
1851 echo "</td></tr>\n";
1854 function pagesizes_list_row($label, $name, $value=null)
1859 foreach ($SysPrefs->pagesizes as $pz)
1862 echo "<tr><td class='label'>$label</td>\n<td>";
1863 echo array_selector( $name, $value, $items );
1864 echo "</td></tr>\n";
1867 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
1869 global $systypes_array;
1871 // emove non-voidable transactions if needed
1872 $systypes = array_diff_key($systypes_array, array_flip($exclude));
1873 return array_selector($name, $value, $systypes,
1875 'spec_option'=> $spec_opt,
1876 'spec_id' => ALL_NUMERIC,
1877 'select_submit'=> $submit_on_change,
1883 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1886 echo "<td>$label</td>\n";
1888 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
1892 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
1894 echo "<tr><td class='label'>$label</td>";
1895 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
1899 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
1901 global $systypes_array;
1904 echo "<td>$label</td>\n";
1907 $items = $systypes_array;
1909 // exclude quotes, orders and dimensions
1910 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
1911 unset($items[$excl]);
1913 echo array_selector($name, $value, $items,
1915 'spec_option'=> _("All"),
1917 'select_submit'=> $submit_on_change,
1924 function cust_allocations_list_cells($label, $name, $selected=null)
1931 ALL_TEXT=>_("All Types"),
1932 '1'=> _("Sales Invoices"),
1933 '2'=> _("Overdue Invoices"),
1934 '3' => _("Payments"),
1935 '4' => _("Credit Notes"),
1936 '5' => _("Delivery Notes")
1938 echo array_selector($name, $selected, $allocs);
1942 function supp_allocations_list_cell($name, $selected=null)
1947 ALL_TEXT=>_("All Types"),
1948 '1'=> _("Invoices"),
1949 '2'=> _("Overdue Invoices"),
1950 '3' => _("Payments"),
1951 '4' => _("Credit Notes"),
1952 '5' => _("Overdue Credit Notes")
1954 echo array_selector($name, $selected, $allocs);
1958 function supp_transactions_list_cell($name, $selected=null)
1963 ALL_TEXT=>_("All Types"),
1965 '1'=> _("Invoices"),
1966 '2'=> _("Overdue Invoices"),
1967 '3' => _("Payments"),
1968 '4' => _("Credit Notes"),
1969 '5' => _("Overdue Credit Notes")
1972 echo array_selector($name, $selected, $allocs);
1976 function policy_list_cells($label, $name, $selected=null)
1981 echo array_selector($name, $selected,
1982 array( '' => _("Automatically put balance on back order"),
1983 'CAN' => _("Cancel any quantites not delivered")) );
1987 function policy_list_row($label, $name, $selected=null)
1989 echo "<tr><td class='label'>$label</td>";
1990 policy_list_cells(null, $name, $selected);
1994 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
1999 echo array_selector($name, $selected,
2000 array( 'Return' => _("Items Returned to Inventory Location"),
2001 'WriteOff' => _("Items Written Off")),
2002 array( 'select_submit'=> $submit_on_change ) );
2006 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2008 echo "<tr><td class='label'>$label</td>";
2009 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2013 function number_list($name, $selected, $from, $to, $no_option=false)
2016 for ($i = $from; $i <= $to; $i++)
2019 return array_selector($name, $selected, $items,
2020 array( 'spec_option' => $no_option,
2021 'spec_id' => ALL_NUMERIC) );
2024 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2029 echo number_list($name, $selected, $from, $to, $no_option);
2033 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2035 echo "<tr><td class='label'>$label</td>";
2036 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2040 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2041 $submit_on_change=true)
2043 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2044 ." GROUP BY profile";
2045 $result = db_query($sql, 'cannot get all profile names');
2046 $profiles = array();
2047 while($myrow=db_fetch($result)) {
2048 $profiles[$myrow['profile']] = $myrow['profile'];
2053 echo "<td class='label'>$label</td>\n";
2056 echo array_selector($name, $selected_id, $profiles,
2057 array( 'select_submit'=> $submit_on_change,
2058 'spec_option'=>$spec_opt,
2062 echo "</td></tr>\n";
2065 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2067 static $printers; // query only once for page display
2070 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2071 $result = db_query($sql, 'cannot get all printers');
2072 $printers = array();
2073 while($myrow=db_fetch($result)) {
2074 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2077 return array_selector($name, $selected_id, $printers,
2078 array( 'select_submit'=> $submit_on_change,
2079 'spec_option'=>$spec_opt,
2084 //------------------------------------------------------------------------------------------------
2086 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2089 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2091 $sql .= " WHERE type=$type";
2093 return combo_input($name, $selected_id, $sql, 'id', 'description',
2096 'order' => 'description',
2097 'select_submit'=> $submit_on_change,
2103 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2106 echo "<td>$label</td>\n";
2108 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2112 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2114 echo "<tr><td class='label'>$label</td>";
2115 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2120 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2122 global $quick_actions;
2124 echo "<tr><td class='label'>$label</td><td>";
2125 echo array_selector($name, $selected_id, $quick_actions,
2127 'select_submit'=> $submit_on_change
2129 echo "</td></tr>\n";
2132 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2134 global $quick_entry_types;
2136 echo "<tr><td class='label'>$label</td><td>";
2137 echo array_selector($name, $selected_id, $quick_entry_types,
2139 'select_submit'=> $submit_on_change
2141 echo "</td></tr>\n";
2144 function record_status_list_row($label, $name) {
2145 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2148 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2150 global $class_types;
2152 echo "<tr><td class='label'>$label</td><td>";
2153 echo array_selector($name, $selected_id, $class_types,
2155 'select_submit'=> $submit_on_change
2157 echo "</td></tr>\n";
2160 //------------------------------------------------------------------------------------------------
2162 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2163 $show_inactive = false)
2166 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2168 return combo_input($name, $selected_id, $sql, 'id', 'description',
2170 'spec_option'=>$new_item ? _("New role") : false,
2172 'select_submit'=> $submit_on_change,
2173 'show_inactive' => $show_inactive
2177 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2178 $show_inactive = false)
2181 echo "<td>$label</td>\n";
2183 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2187 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2188 $show_inactive = false)
2190 echo "<tr><td class='label'>$label</td>";
2191 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2195 function tab_list_row($label, $name, $selected_id=null)
2197 global $installed_extensions;
2200 foreach ($_SESSION['App']->applications as $app) {
2201 $tabs[$app->id] = access_string($app->name, true);
2204 echo "<td class='label'>$label</td><td>\n";
2205 echo array_selector($name, $selected_id, $tabs);
2206 echo "</td></tr>\n";
2209 //-----------------------------------------------------------------------------------------------
2211 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2214 global $path_to_root;
2215 include_once($path_to_root . "/admin/db/tags_db.inc");
2216 $results = get_tags($type, $all);
2218 while ($tag = db_fetch($results))
2219 $tags[$tag['id']] = $tag['name'];
2221 if (!isset($tags)) {
2222 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2225 return array_selector($name, null, $tags,
2228 'height' => $height,
2229 'spec_option'=> $spec_opt,
2234 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2237 echo "<td>$label</td>\n";
2239 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2244 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2246 echo "<tr><td class='label'>$label</td>";
2247 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2251 //---------------------------------------------------------------------------------------------
2252 // List of sets of active extensions
2254 function extset_list($name, $value=null, $submit_on_change=false)
2256 global $db_connections;
2259 foreach ($db_connections as $comp)
2260 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2261 return array_selector( $name, $value, $items,
2263 'spec_option'=> _("Available and/or installed"),
2265 'select_submit'=> $submit_on_change,
2270 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2273 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2278 if (@$filter['class']) {
2279 $where[] = 'type='.db_escape($filter['class']);
2282 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2283 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2284 if (@$filter['multi']) { // contact category selector for person
2288 return combo_input($name, $selected_id, $sql, 'id', 'name',
2291 'height' => $multi ? 5:1,
2292 'category' => $groups,
2293 'select_submit'=> $submit_on_change,
2299 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2301 echo "<tr><td class='label'>$label</td><td>";
2302 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2303 echo "</td></tr>\n";
2306 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2308 global $pterm_types;
2310 echo "<tr><td class='label'>$label</td><td>";
2311 echo array_selector($name, $selected_id, $pterm_types,
2313 'select_submit'=> $submit_on_change
2315 echo "</td></tr>\n";
2318 function coa_list_row($label, $name, $value=null)
2320 global $path_to_root, $installed_extensions;
2322 $path = $path_to_root.'/sql/';
2324 $sqldir = opendir($path);
2325 while (false !== ($fname = readdir($sqldir)))
2327 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2329 $ext = array_search_value($fname, $installed_extensions, 'sql');
2331 $descr = $ext['name'];
2332 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2333 $descr = _("Standard new company American COA (4 digit)");
2334 } elseif ($fname == 'en_US-demo.sql') {
2335 $descr = _("Standard American COA (4 digit) with demo data");
2339 $coas[$fname] = $descr;
2344 echo "<tr><td class='label'>$label</td>\n<td>";
2345 echo array_selector( $name, $value, $coas );
2346 echo "</td></tr>\n";
2349 function payment_services($name)
2351 global $payment_services;
2353 $services = array_combine(array_keys($payment_services), array_keys($payment_services));
2355 return array_selector($name, null, $services, array(
2356 'spec_option'=> _("No payment Link"),
2361 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2363 global $tax_algorithms;
2365 return array_selector($name, $value, $tax_algorithms,
2367 'select_submit'=> $submit_on_change,
2373 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2376 echo "<td>$label</td>\n";
2378 echo tax_algorithm_list($name, $value, $submit_on_change);
2382 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2384 echo "<tr><td class='label'>$label</td>";
2385 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2388 //----------------------------------------------------------------------------------------------
2390 function subledger_list($name, $account, $selected_id=null)
2393 $type = is_subledger_account($account);
2398 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2400 .TB_PREF."debtors_master d,"
2401 .TB_PREF."cust_branch c
2402 WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
2404 $sql = "SELECT supplier_id as id, supp_ref as name
2406 .TB_PREF."suppliers s
2407 WHERE s.payable_account=".db_escape($account);
2409 $mode = get_company_pref('no_customer_list');
2411 return combo_input($name, $selected_id, $sql, 'id', 'name',
2419 function subledger_list_cells($label, $name, $account, $selected_id=null)
2422 echo "<td>$label</td>\n";
2424 echo subledger_list($name, $account, $selected_id);
2428 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2429 $submit_on_change=false, $show_inactive=false, $editkey = false)
2431 echo "<tr><td class='label'>$label</td><td nowrap>";
2432 echo subledger_list($name, $account, $selected_id);
2433 echo "</td>\n</tr>\n";
2436 function accounts_type_list_row($label, $name, $selected_id=null)
2440 echo "<td class='label'>$label</td>\n";
2442 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2443 echo array_selector($name, $selected_id, $sel);
2444 echo "</td></tr>\n";