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,
28 $options=null, $type=null)
30 global $Ajax, $path_to_root, $SysPrefs ;
32 $opts = array( // default options
33 'where'=> array(), // additional constraints
34 'order' => $namefield, // list sort order
35 // special option parameters
36 'spec_option'=>false, // option text or false
37 'spec_id' => 0, // option id
38 // submit on select parameters
39 'default' => '', // default value when $_POST is not set
40 'multi' => false, // multiple select
41 'select_submit' => false, //submit on select: true/false
42 'async' => true, // select update via ajax (true) vs _page_body reload
43 // search box parameters
45 'search_box' => false, // name or true/false
46 'type' => 0, // type of extended selector:
47 // 0 - with (optional) visible search box, search by fragment inside id
48 // 1 - with hidden search box, search by option text
49 // 2 - with (optional) visible search box, search by fragment at the start of id
50 // 3 - TODO reverse: box with hidden selector available via enter; this
51 // would be convenient for optional ad hoc adding of new item
52 'search_submit' => true, //search submit button: true/false
53 'size' => 8, // size and max of box tag
55 'height' => false, // number of lines in select box
56 'cells' => false, // combo displayed as 2 <td></td> cells
57 'search' => array(), // sql field names to search
58 'format' => null, // format functions for regular options
60 'box_hint' => null, // box/selectors hints; null = std see below
61 'category' => false, // category column name or false
62 'show_inactive' => false, // show inactive records.
63 'editable' => false, // false, or length of editable entry field
64 'editlink' => false // link to entity entry/edit page (optional)
66 // ------ merge options with defaults ----------
68 $opts = array_merge($opts, $options);
69 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
71 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
72 // select content filtered by search field:
73 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
74 // select set by select content field
75 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
77 $select_submit = $opts['select_submit'];
78 $spec_id = $opts['spec_id'];
79 $spec_option = $opts['spec_option'];
80 if ($opts['type'] == 0) {
83 } elseif($opts['type'] == 1) {
91 $disabled = $opts['disabled'] ? "disabled" : '';
92 $multi = $opts['multi'];
94 if(!count($opts['search'])) {
95 $opts['search'] = array($by_id ? $valfield : $namefield);
97 if ($opts['sel_hint'] === null)
98 $opts['sel_hint'] = $by_id || $search_box==false ?
99 '' : _('Press Space tab for search pattern entry');
101 if ($opts['box_hint'] === null)
102 $opts['box_hint'] = $search_box && $search_submit != false ?
103 ($by_id ? _('Enter code fragment to search or * for all')
104 : _('Enter description fragment to search or * for all')) :'';
106 if ($selected_id == null) {
107 $selected_id = get_post($name, (string)$opts['default']);
109 if(!is_array($selected_id))
110 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
112 $txt = get_post($search_box);
115 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
116 if ($by_id) $txt = $_POST[$name];
119 $Ajax->activate('_page_body');
121 $Ajax->activate($name);
123 if (isset($_POST[$search_button])) {
125 $Ajax->activate('_page_body');
127 $Ajax->activate($name);
130 // search related sql modifications
132 $rel = "rel='$search_box'"; // set relation to list
133 if ($opts['search_submit']) {
134 if (isset($_POST[$search_button])) {
135 $selected_id = array(); // ignore selected_id while search
137 $Ajax->activate('_page_body');
139 $Ajax->activate($name);
142 if ($spec_option === false && $selected_id == array())
145 $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id));
150 foreach($opts['search'] as $i=> $s)
151 $opts['search'][$i] = $s . " LIKE "
152 .db_escape(($class=='combo3' ? '' : '%').$txt.'%');
153 $opts['where'][] = '('. implode(' OR ', $opts['search']) . ')';
159 if (count($opts['where'])) {
160 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
161 $where .= '('. implode(' AND ', $opts['where']) . ')';
162 $group_pos = strpos($sql, 'GROUP BY');
164 $group = substr($sql, $group_pos);
165 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
170 if ($opts['order'] != false) {
171 if (!is_array($opts['order']))
172 $opts['order'] = array($opts['order']);
173 $sql .= ' ORDER BY '.implode(',',$opts['order']);
177 // ------ make selector ----------
178 $selector = $first_opt = '';
184 if (($type === "customer" || $type === "supplier") && !empty($SysPrefs->prefs['shortname_name_in_list']))
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, $pname);
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){
218 $selector .= "</optgroup>";
219 $selector .= "<optgroup label='".$cat."'>\n";
222 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
225 $selector .= "</optgroup>";
226 db_free_result($result);
229 // Prepend special option.
230 if ($spec_option !== false) { // if special option used - add it
231 $first_id = $spec_id;
232 $first_opt = $spec_option;
233 $sel = $found===false ? 'selected' : '';
234 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
235 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
239 if ($found===false) {
240 $selected_id = array($first_id);
243 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
245 if ($SysPrefs->use_popup_search)
246 $selector = "<select id='$name' autocomplete='off' ".($multi ? "multiple" : '')
247 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
248 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
249 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
251 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
252 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
253 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
254 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
255 if ($by_id && ($search_box != false || $opts['editable']) ) {
256 // on first display show selector list
257 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
258 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
259 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
260 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
261 set_focus($name.'_text'); // prevent lost focus
262 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
263 set_focus($name); // prevent lost focus
264 if (!$opts['editable'])
266 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
269 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
271 // span for select list/input field update
272 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
274 // if selectable or editable list is used - add select button
275 if ($select_submit != false || $search_button) {
276 // button class selects form reload/ajax selector update
277 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
278 (fallback_mode() ? '' : 'display:none;'),
279 '_'.$name.'_update')."\n";
281 // ------ make combo ----------
283 if ($search_box != false) {
284 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
285 $opts['size']."' maxlength='".$opts['max'].
286 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
287 .$opts['box_hint']."'"
288 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
290 if ($search_submit != false || $opts['editable']) {
291 $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
292 (fallback_mode() ? '' : 'display:none;'),
293 $search_submit ? $search_submit : "_{$name}_button")."\n";
296 default_focus(($search_box && $by_id) ? $search_box : $name);
299 if ($SysPrefs->use_popup_search && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']))
304 if ($SysPrefs->use_popup_windows) {
306 switch (strtolower($type)) {
308 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=all&client_id=" . $id;
309 $img_title = _("Search items");
311 case "stock_manufactured":
312 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=manufactured&client_id=" . $id;
313 $img_title = _("Search items");
315 case "stock_purchased":
316 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=purchasable&client_id=" . $id;
317 $img_title = _("Search items");
320 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=sales&client_id=" . $id;
321 $img_title = _("Search items");
323 case "stock_costable":
324 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=costable&client_id=" . $id;
325 $img_title = _("Search items");
328 $parent = $opts['parent'];
329 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=component&parent=".$parent."&client_id=" . $id;
330 $img_title = _("Search items");
333 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=kits&client_id=" . $id;
334 $img_title = _("Search items");
337 $link = $path_to_root . "/sales/inquiry/customers_list.php?popup=1&client_id=" . $id;
338 $img_title = _("Search customers");
341 $link = $path_to_root . "/sales/inquiry/customer_branches_list.php?popup=1&client_id=" . $id . "#customer_id";
342 $img_title = _("Search branches");
345 $link = $path_to_root . "/purchasing/inquiry/suppliers_list.php?popup=1&client_id=" . $id;
346 $img_title = _("Search suppliers");
350 $skip = strtolower($type) == "account" ? false : true;
351 $link = $path_to_root . "/gl/inquiry/accounts_list.php?popup=1&skip=".$skip."&client_id=" . $id;
352 $img_title = _("Search GL accounts");
359 $theme = user_theme();
360 $img = '<img src="'.$path_to_root.'/themes/'.$theme.'/images/'.ICON_VIEW.
361 '" style="vertical-align:middle;width:12px;height:12px;border:0;" onclick="javascript:lookupWindow("'.
362 $link.'", "");" title="' . $img_title . '" style="cursor:pointer;" />';
366 if ($opts['editlink'])
367 $selector .= ' '.$opts['editlink'];
369 if ($search_box && $opts['cells'])
370 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td nowrap>$selector$img</td>";
372 $str = $edit_entry.$selector.$img;
378 Returns true if selector $name is subject to update.
380 function list_updated($name)
382 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
384 //----------------------------------------------------------------------------------------------
385 // Universal array combo generator
386 // $items is array of options 'value' => 'description'
387 // Options is reduced set of combo_selector options and is merged with defaults.
389 function array_selector($name, $selected_id, $items, $options=null)
393 $opts = array( // default options
394 'spec_option'=>false, // option text or false
395 'spec_id' => 0, // option id
396 'select_submit' => false, //submit on select: true/false
397 'async' => true, // select update via ajax (true) vs _page_body reload
398 'default' => '', // default value when $_POST is not set
399 'multi'=>false, // multiple select
400 // search box parameters
401 'height' => false, // number of lines in select box
405 // ------ merge options with defaults ----------
407 $opts = array_merge($opts, $options);
408 $select_submit = $opts['select_submit'];
409 $spec_id = $opts['spec_id'];
410 $spec_option = $opts['spec_option'];
411 $disabled = $opts['disabled'] ? "disabled" : '';
412 $multi = $opts['multi'];
414 if ($selected_id == null) {
415 $selected_id = get_post($name, $opts['default']);
417 if(!is_array($selected_id))
418 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
420 if (isset($_POST[ '_'.$name.'_update'])) {
422 $Ajax->activate('_page_body');
424 $Ajax->activate($name);
427 // ------ make selector ----------
428 $selector = $first_opt = '';
431 foreach($items as $value=>$descr) {
433 if (in_array((string)$value, $selected_id, true)) {
437 if ($first_id === false) {
441 $selector .= "<option $sel value='$value'>$descr</option>\n";
444 if ($first_id!==false) {
445 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
447 // Prepend special option.
448 if ($spec_option !== false) { // if special option used - add it
449 $first_id = $spec_id;
450 $first_opt = $spec_option;
451 $sel = $found===false ? 'selected' : '';
452 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
456 if ($found===false) {
457 $selected_id = array($first_id);
459 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
461 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
462 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
463 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
464 . $opts['sel_hint']."'>".$selector."</select>\n";
466 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
468 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
470 if ($select_submit != false) { // if submit on change is used - add select button
471 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
472 (fallback_mode() ? '' : 'display:none;'),
473 '_'.$name.'_update')."\n";
475 default_focus($name);
479 //----------------------------------------------------------------------------------------------
480 function array_selector_row($label, $name, $selected_id, $items, $options=null)
482 echo "<tr><td class='label'>$label</td>\n<td>";
483 echo array_selector($name, $selected_id, $items, $options);
487 //----------------------------------------------------------------------------------------------
488 function _format_add_curr($row, $pname=false)
490 static $company_currency;
492 if ($company_currency == null)
494 $company_currency = get_company_currency();
498 return $row[1] . ($row[2] == $company_currency ? '' : (" - " . $row[2]));
502 return $row[1] . " - " . $row[2] . ($row[3] == $company_currency ? '' : (" - " . $row[3]));
506 function add_edit_combo($type)
508 global $path_to_root, $popup_editors, $SysPrefs;
510 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
513 $theme_path = $path_to_root . '/themes/' . user_theme();
515 $key = $popup_editors[$type][1];
516 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
517 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
518 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
521 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
522 $all=false, $editkey = false)
525 if (!empty($SysPrefs->prefs['shortname_name_in_list']))
526 $sql = "SELECT supplier_id, supp_ref, supp_name, curr_code, inactive FROM ".TB_PREF."suppliers ";
528 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
530 $mode = get_company_pref('no_supplier_list');
533 set_editor('supplier', $name, $editkey);
535 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
537 'format' => '_format_add_curr',
538 'order' => array('supp_ref'),
539 'search_box' => $mode!=0,
541 'search' => array("supp_ref","supp_name","gst_no"),
542 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
543 'spec_id' => ALL_TEXT,
544 'select_submit'=> $submit_on_change,
546 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
547 _('Select supplier'),
548 'show_inactive'=>$all,
549 'editlink' => $editkey ? add_edit_combo('supplier') : false
554 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
555 $submit_on_change=false, $all=false, $editkey = false)
558 echo "<td>$label</td>\n";
560 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
565 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
566 $submit_on_change=false, $all=false, $editkey = false)
568 echo "<tr><td class='label'>$label</td><td>";
569 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
573 //----------------------------------------------------------------------------------------------
575 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
576 $show_inactive=false, $editkey = false)
579 if (!empty($SysPrefs->prefs['shortname_name_in_list']))
580 $sql = "SELECT debtor_no, debtor_ref, name, curr_code, inactive FROM ".TB_PREF."debtors_master ";
582 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
584 $mode = get_company_pref('no_customer_list');
587 set_editor('customer', $name, $editkey);
589 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
591 'format' => '_format_add_curr',
592 'order' => array('debtor_ref'),
593 'search_box' => $mode!=0,
596 'search' => array("debtor_ref","name","tax_id"),
597 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
598 'spec_id' => ALL_TEXT,
599 'select_submit'=> $submit_on_change,
601 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
602 _('Select customer'),
603 'show_inactive' => $show_inactive,
604 'editlink' => $editkey ? add_edit_combo('customer') : false
609 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
610 $submit_on_change=false, $show_inactive=false, $editkey = false)
613 echo "<td>$label</td>\n";
615 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
616 $show_inactive, $editkey);
620 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
621 $submit_on_change=false, $show_inactive=false, $editkey = false)
624 echo "<tr><td class='label'>$label</td><td nowrap>";
625 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
626 $show_inactive, $editkey);
627 echo "</td>\n</tr>\n";
630 //------------------------------------------------------------------------------------------------
632 function customer_branches_list($customer_id, $name, $selected_id=null,
633 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
636 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
637 WHERE debtor_no=" . db_escape($customer_id)." ";
640 set_editor('branch', $name, $editkey);
642 $where = $enabled ? array("inactive = 0") : array();
643 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
646 'order' => array('branch_ref'),
647 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
648 'spec_id' => ALL_TEXT,
649 'select_submit'=> $submit_on_change,
650 'sel_hint' => _('Select customer branch'),
651 'editlink' => $editkey ? add_edit_combo('branch') : false
655 //------------------------------------------------------------------------------------------------
657 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
658 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
661 echo "<td>$label</td>\n";
663 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
664 $submit_on_change, $editkey);
668 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
669 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
671 echo "<tr><td class='label'>$label</td>";
672 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
673 $all_option, $enabled, $submit_on_change, $editkey);
677 //------------------------------------------------------------------------------------------------
679 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
682 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations WHERE fixed_asset=".(int)$fixed_asset;
684 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
686 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
687 'spec_id' => ALL_TEXT,
688 'select_submit'=> $submit_on_change
692 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
695 echo "<td>$label</td>\n";
697 echo locations_list($name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
701 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
703 echo "<tr><td class='label'>$label</td>";
704 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
708 //-----------------------------------------------------------------------------------------------
710 function currencies_list($name, $selected_id=null, $submit_on_change=false, $exclude_home_curr=false)
712 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
713 if ($exclude_home_curr)
714 $sql .= " WHERE curr_abrev!='".get_company_currency()."'";
716 // default to the company currency
717 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
719 'select_submit'=> $submit_on_change,
720 'default' => get_company_currency(),
725 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
728 echo "<td>$label</td>\n";
730 echo currencies_list($name, $selected_id, $submit_on_change);
734 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
736 echo "<tr><td class='label'>$label</td>";
737 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
741 //---------------------------------------------------------------------------------------------------
743 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
746 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
748 // default to the company current fiscal year
750 return combo_input($name, $selected_id, $sql, 'id', '',
753 'default' => get_company_pref('f_year'),
754 'format' => '_format_fiscalyears',
755 'select_submit'=> $submit_on_change,
760 function _format_fiscalyears($row)
762 return sql2date($row[1]) . " - " . sql2date($row[2])
763 . " " . ($row[3] ? _('Closed') : _('Active'));
766 function fiscalyears_list_cells($label, $name, $selected_id=null)
769 echo "<td>$label</td>\n";
771 echo fiscalyears_list($name, $selected_id);
775 function fiscalyears_list_row($label, $name, $selected_id=null)
777 echo "<tr><td class='label'>$label</td>";
778 fiscalyears_list_cells(null, $name, $selected_id);
781 //------------------------------------------------------------------------------------
783 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
784 $submit_on_change=false, $showclosed=false, $showtype=1)
786 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
789 'order' => 'reference',
790 'spec_option'=>$no_option ? $showname : false,
792 'select_submit'=> $submit_on_change,
797 $options['where'][] = "closed=0";
799 $options['where'][] = "type_=".db_escape($showtype);
801 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
804 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
805 $showclosed=false, $showtype=0, $submit_on_change=false)
808 echo "<td>$label</td>\n";
810 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
814 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
815 $showclosed=false, $showtype=0, $submit_on_change=false)
817 echo "<tr><td class='label'>$label</td>";
818 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
819 $showclosed, $showtype, $submit_on_change);
823 //---------------------------------------------------------------------------------------------------
825 function stock_items_list($name, $selected_id=null, $all_option=false,
826 $submit_on_change=false, $opts=array(), $editkey = false, $type = "stock")
828 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
829 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
831 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
832 $sql .= " AND mb_flag='F'";
834 $sql .= " AND mb_flag!='F'";
837 set_editor('item', $name, $editkey);
839 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
842 'format' => '_format_stock_items',
843 'spec_option' => $all_option===true ? _("All Items") : $all_option,
844 'spec_id' => ALL_TEXT,
845 'search_box' => true,
846 'search' => array("stock_id", "c.description","s.description"),
847 'search_submit' => get_company_pref('no_item_list')!=0 && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']),
849 'select_submit'=> $submit_on_change,
851 'order' => array('c.description','stock_id'),
852 'editlink' => $editkey ? add_edit_combo('item') : false,
859 function _format_stock_items($row)
861 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
864 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
865 $submit_on_change=false, $all=false, $editkey = false, $opts= array())
867 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
868 $editor_item = 'fa_item';
870 $editor_item = 'item';
873 // set_editor($editor_item, $name, $editkey);
876 echo "<td>$label</td>\n";
879 // $opts = array_merge($options, array('cells'=>true, 'show_inactive'=>$all, 'new_icon' => $editkey ? 'item' : false));
881 // echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, $opts);
883 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
884 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey);
888 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
891 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
895 //---------------------------------------------------------------------------------------------------
897 // Select item via foreign code.
899 function sales_items_list($name, $selected_id=null, $all_option=false,
900 $submit_on_change=false, $type='', $opts=array())
903 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
904 i.inactive, if(count(*)>1, '0', s.editable) as editable
906 ".TB_PREF."stock_master s,
907 ".TB_PREF."item_codes i
909 ".TB_PREF."stock_category c
910 ON i.category_id=c.category_id
911 WHERE i.stock_id=s.stock_id
915 if ($type == 'local') { // exclude foreign codes
916 $sql .= " AND !i.is_foreign";
917 } elseif ($type == 'kits') { // sales kits
918 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
920 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
921 $sql .= " GROUP BY i.item_code";
923 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
926 'format' => '_format_stock_items',
927 'spec_option' => $all_option===true ? _("All Items") : $all_option,
928 'spec_id' => ALL_TEXT,
929 'search_box' => true,
930 'search' => array("i.item_code", "c.description", "i.description"),
931 'search_submit' => get_company_pref('no_item_list')!=0,
933 'select_submit'=> $submit_on_change,
935 'order' => array('c.description','i.item_code'),
938 ), $opts), $type == 'kits' ? $type : "stock_sales" );
941 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
944 set_editor('item', $name, $editkey);
947 echo "<td>$label</td>\n";
948 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
949 '', array('cells'=>true, 'max'=>50)); // maximum is set to 50 and not default 255.
952 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
954 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
955 'kits', array('cells'=>false, 'editable' => false));
958 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
962 echo "<td class='label'>$label</td>\n";
964 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
965 'local', array('cells'=>false, 'editable' => false));
968 //------------------------------------------------------------------------------------
970 function stock_manufactured_items_list($name, $selected_id=null,
971 $all_option=false, $submit_on_change=false)
973 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
974 array('where'=>array("mb_flag= 'M'")), false, "stock_manufactured");
977 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
978 $all_option=false, $submit_on_change=false)
981 echo "<td>$label</td>\n";
983 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
987 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
988 $all_option=false, $submit_on_change=false)
990 echo "<tr><td class='label'>$label</td>";
991 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
994 //------------------------------------------------------------------------------------
996 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
997 $all_option=false, $submit_on_change=false, $editkey = false)
999 $parent = db_escape($parent_stock_id);
1000 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1001 array('where'=>array("stock_id != $parent"), 'parent'=> $parent_stock_id), $editkey, "component");
1005 function stock_component_items_list_cells($label, $name, $parent_stock_id,
1006 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
1009 echo "<td>$label</td>\n";
1010 $parent = db_escape($parent_stock_id);
1011 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1012 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true, 'parent'=> $parent_stock_id), $editkey, "component");
1014 //------------------------------------------------------------------------------------
1016 function stock_costable_items_list($name, $selected_id=null,
1017 $all_option=false, $submit_on_change=false)
1019 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1020 array('where'=>array("mb_flag!='D'")), false, "stock_costable");
1023 function stock_costable_items_list_cells($label, $name, $selected_id=null,
1024 $all_option=false, $submit_on_change=false)
1027 echo "<td>$label</td>\n";
1028 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1029 array('where'=>array("mb_flag!='D'"), 'cells'=>true), false, "stock_costable");
1032 //------------------------------------------------------------------------------------
1033 function stock_purchasable_items_list($name, $selected_id=null,
1034 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
1036 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1037 array('where'=>array("NOT no_purchase"),
1038 'show_inactive'=>$all), $editkey, "stock_purchased");
1041 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
1043 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
1044 $all_option=false, $submit_on_change=false, $editkey=false)
1047 echo "<td>$label</td>\n";
1048 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1049 array('where'=>array("NOT no_purchase"),
1051 'cells'=>true), $editkey);
1054 //------------------------------------------------------------------------------------
1056 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
1058 global $stock_types;
1062 echo "<td class='label'>$label</td>\n";
1065 echo array_selector($name, $selected_id, $stock_types,
1067 'select_submit'=> true,
1068 'disabled' => !$enabled) );
1069 echo "</td></tr>\n";
1072 function stock_units_list_row($label, $name, $value=null, $enabled=true)
1074 $result = get_all_item_units();
1077 echo "<td class='label'>$label</td>\n";
1080 while($unit = db_fetch($result))
1081 $units[$unit['abbr']] = $unit['name'];
1083 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
1085 echo "</td></tr>\n";
1088 //------------------------------------------------------------------------------------
1090 function stock_purchasable_fa_list_cells($label, $name, $selected_id=null, $all_option=false,
1091 $submit_on_change=false, $all=false, $editkey = false, $exclude_items = array())
1093 // Check if a fixed asset has been bought.
1094 $where_opts[] = "stock_id NOT IN
1095 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1097 // exclude items currently on the order.
1098 foreach($exclude_items as $item) {
1099 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1101 $where_opts[] = "mb_flag='F'";
1103 echo stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, $all, $editkey,
1104 array('fixed_asset' => true, 'where' => $where_opts));
1107 function stock_disposable_fa_list($name, $selected_id=null,
1108 $all_option=false, $submit_on_change=false)
1110 // Check if a fixed asset has been bought....
1111 $where_opts[] = "stock_id IN
1112 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1113 // ...but has not been disposed or sold already.
1114 $where_opts[] = "stock_id NOT IN
1115 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1117 $where_opts[] = "mb_flag='F'";
1119 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1120 array('fixed_asset' => true, 'where' => $where_opts));
1123 function stock_disposable_fa_list_cells($label, $name, $selected_id=null,
1124 $all_option=false, $submit_on_change=false, $exclude_items = array())
1126 // Check if a fixed asset has been bought....
1127 $where_opts[] = "stock_id IN
1128 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1129 // ...but has not been disposed or sold already.
1130 $where_opts[] = "stock_id NOT IN
1131 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1133 $where_opts[] = "mb_flag='F'";
1135 foreach($exclude_items as $item) {
1136 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1140 echo "<td>$label</td>\n";
1141 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1142 array('fixed_asset' => true, 'cells'=>true, 'where' => $where_opts));
1145 function stock_depreciable_fa_list_cells($label, $name, $selected_id=null,
1146 $all_option=false, $submit_on_change=false)
1149 // Check if a fixed asset has been bought....
1150 $where_opts[] = "stock_id IN
1151 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1152 // ...but has not been disposed or sold already.
1153 $where_opts[] = "stock_id NOT IN
1154 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1156 $year = get_current_fiscalyear();
1157 $begin = date2sql(add_months(sql2date($year['begin']), -1));
1158 $end = date2sql(add_months(sql2date($year['end']), -1));
1160 // check if current fiscal year
1161 $where_opts[] = "depreciation_date <= '".$end."'";
1162 $where_opts[] = "depreciation_date >= '".$begin."'";
1164 $where_opts[] = "material_cost > 0";
1165 $where_opts[] = "mb_flag='F'";
1168 echo "<td>$label</td>\n";
1169 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1170 array('fixed_asset' => true, 'where' => $where_opts, 'cells'=>true));
1173 //------------------------------------------------------------------------------------
1175 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
1177 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
1179 return combo_input($name, $selected_id, $sql, 'id', 'name',
1181 'spec_option' => $none_option,
1182 'spec_id' => ALL_NUMERIC,
1183 'select_submit'=> $submit_on_change,
1188 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1189 $submit_on_change=false)
1192 echo "<td>$label</td>\n";
1194 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1198 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1199 $submit_on_change=false)
1201 echo "<tr><td class='label'>$label</td>";
1202 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1206 //------------------------------------------------------------------------------------
1208 function tax_groups_list($name, $selected_id=null,
1209 $none_option=false, $submit_on_change=false)
1211 $sql = "SELECT id, name, inactive FROM ".TB_PREF."tax_groups";
1213 return combo_input($name, $selected_id, $sql, 'id', 'name',
1216 'spec_option' => $none_option,
1217 'spec_id' => ALL_NUMERIC,
1218 'select_submit'=> $submit_on_change,
1223 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1226 echo "<td>$label</td>\n";
1228 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1232 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1234 echo "<tr><td class='label'>$label</td>";
1235 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1239 //------------------------------------------------------------------------------------
1241 function item_tax_types_list($name, $selected_id=null, $show_inactive = false)
1243 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1244 if (!$show_inactive)
1245 $sql .= " WHERE !inactive";
1247 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1250 function item_tax_types_list_cells($label, $name, $selected_id=null, $show_inactive = false)
1253 echo "<td>$label</td>\n";
1255 echo item_tax_types_list($name, $selected_id, $show_inactive);
1259 function item_tax_types_list_row($label, $name, $selected_id=null, $show_inactive = false)
1261 echo "<tr><td class='label'>$label</td>";
1262 item_tax_types_list_cells(null, $name, $selected_id, $show_inactive);
1266 //------------------------------------------------------------------------------------
1268 function shippers_list($name, $selected_id=null)
1270 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1271 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1272 array('order'=>array('shipper_name')));
1275 function shippers_list_cells($label, $name, $selected_id=null)
1278 echo "<td>$label</td>\n";
1280 echo shippers_list($name, $selected_id);
1284 function shippers_list_row($label, $name, $selected_id=null)
1286 echo "<tr><td class='label'>$label</td>";
1287 shippers_list_cells(null, $name, $selected_id);
1291 //-------------------------------------------------------------------------------------
1293 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1295 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1296 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1297 array('order'=>array('salesman_name'),
1298 'spec_option' => $spec_opt,
1299 'spec_id' => ALL_NUMERIC));
1302 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1305 echo "<td>$label</td>\n";
1307 echo sales_persons_list($name, $selected_id, $spec_opt);
1311 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1313 echo "<tr><td class='label'>$label</td>";
1314 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1318 //------------------------------------------------------------------------------------
1320 function sales_areas_list($name, $selected_id=null, $special_option=false)
1322 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1323 return combo_input($name, $selected_id, $sql, 'area_code', 'description',
1324 array('spec_option' => $special_option===true ? ' ' : $special_option,
1325 'order' => 'description', 'spec_id' => 0));
1328 function sales_areas_list_cells($label, $name, $selected_id=null, $special_option=false)
1331 echo "<td>$label</td>\n";
1333 echo sales_areas_list($name, $selected_id, $special_option);
1337 function sales_areas_list_row($label, $name, $selected_id=null, $special_option=false)
1339 echo "<tr><td class='label'>$label</td>";
1340 sales_areas_list_cells(null, $name, $selected_id, $special_option);
1344 //------------------------------------------------------------------------------------
1346 function sales_groups_list($name, $selected_id=null, $special_option=false)
1348 $sql = "SELECT id, description, inactive FROM `".TB_PREF."groups`";
1349 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1350 'spec_option' => $special_option===true ? ' ' : $special_option,
1351 'order' => 'description', 'spec_id' => 0,
1355 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1358 echo "<td>$label</td>\n";
1360 echo sales_groups_list($name, $selected_id, $special_option);
1364 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1366 echo "<tr><td class='label'>$label</td>";
1367 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1371 //------------------------------------------------------------------------------------
1373 function _format_template_items($row)
1375 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1378 function templates_list($name, $selected_id=null, $special_option=false)
1380 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1381 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1382 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1383 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1384 'format' => '_format_template_items',
1385 'spec_option' => $special_option===true ? ' ' : $special_option,
1386 'order' => 'order_no', 'spec_id' => 0,
1390 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1393 echo "<td>$label</td>\n";
1395 echo templates_list($name, $selected_id, $special_option);
1399 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1401 echo "<tr><td class='label'>$label</td>";
1402 templates_list_cells(null, $name, $selected_id, $special_option);
1406 //------------------------------------------------------------------------------------
1408 function workorders_list($name, $selected_id=null)
1410 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1411 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1414 function workorders_list_cells($label, $name, $selected_id=null)
1417 echo "<td>$label</td>\n";
1419 echo workorders_list($name, $selected_id);
1423 function workorders_list_row($label, $name, $selected_id=null)
1425 echo "<tr><td class='label'>$label</td>";
1426 workorders_list_cells(null, $name, $selected_id);
1430 //------------------------------------------------------------------------------------
1432 function payment_terms_list($name, $selected_id=null)
1434 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1435 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1438 function payment_terms_list_cells($label, $name, $selected_id=null)
1441 echo "<td>$label</td>\n";
1443 echo payment_terms_list($name, $selected_id);
1447 function payment_terms_list_row($label, $name, $selected_id=null)
1449 echo "<tr><td class='label'>$label</td>";
1450 payment_terms_list_cells(null, $name, $selected_id);
1454 //------------------------------------------------------------------------------------
1456 function credit_status_list($name, $selected_id=null)
1458 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1459 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1462 function credit_status_list_cells($label, $name, $selected_id=null)
1465 echo "<td>$label</td>\n";
1467 echo credit_status_list($name, $selected_id);
1471 function credit_status_list_row($label, $name, $selected_id=null)
1473 echo "<tr><td class='label'>$label</td>";
1474 credit_status_list_cells(null, $name, $selected_id);
1478 //-----------------------------------------------------------------------------------------------
1480 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1482 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1484 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1486 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1488 'select_submit'=> $submit_on_change,
1492 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1495 echo "<td>$label</td>\n";
1497 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1501 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1503 echo "<tr><td class='label'>$label</td>";
1504 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1508 //-----------------------------------------------------------------------------------------------
1510 function _format_date($row)
1512 return sql2date($row['reconciled']);
1515 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1517 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1518 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1519 GROUP BY reconciled";
1520 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1522 'spec_option' => $special_option,
1523 'format' => '_format_date',
1525 'select_submit'=> $submit_on_change
1529 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1532 echo "<td>$label</td>\n";
1534 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1538 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1541 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1545 //-----------------------------------------------------------------------------------------------
1547 function workcenter_list($name, $selected_id=null, $all_option=false)
1550 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1552 return combo_input($name, $selected_id, $sql, 'id', 'name',
1554 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1555 'spec_id' => ALL_TEXT,
1559 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1561 default_focus($name);
1563 echo "<td>$label</td>\n";
1565 echo workcenter_list($name, $selected_id, $all_option);
1569 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1571 echo "<tr><td class='label'>$label</td>";
1572 workcenter_list_cells(null, $name, $selected_id, $all_option);
1576 //-----------------------------------------------------------------------------------------------
1578 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1580 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1581 FROM ".TB_PREF."bank_accounts";
1583 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1585 'format' => '_format_add_curr',
1586 'select_submit'=> $submit_on_change,
1587 'spec_option' => $spec_option,
1593 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1596 echo "<td>$label</td>\n";
1598 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1602 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1604 echo "<tr><td class='label'>$label</td>";
1605 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1608 //-----------------------------------------------------------------------------------------------
1610 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1613 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1614 FROM ".TB_PREF."bank_accounts
1615 WHERE account_type=".BT_CASH;
1618 echo "<tr><td class='label'>$label</td>\n";
1620 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1622 'spec_option' => $all_option,
1623 'spec_id' => ALL_TEXT,
1624 'format' => '_format_add_curr',
1625 'select_submit'=> $submit_on_change,
1628 echo "</td></tr>\n";
1630 //-----------------------------------------------------------------------------------------------
1632 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1634 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1636 default_focus($name);
1639 echo "<td class='label'>$label</td>\n";
1642 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1644 'select_submit'=> $submit_on_change,
1646 'spec_option' =>$spec_option,
1648 'order'=> array('pos_name')
1650 echo "</td></tr>\n";
1653 //-----------------------------------------------------------------------------------------------
1654 // Payment type selector for current user.
1656 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1658 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1660 if ($category == PM_CASH) // only cash
1661 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1662 elseif ($category == PM_CREDIT) // only delayed payments
1663 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1664 elseif (!$prepayments)
1665 $sql .= " WHERE days_before_due>=0";
1667 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1669 'select_submit'=> $submit_on_change,
1675 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1678 echo "<td class='label'>$label</td>\n";
1681 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1685 //-----------------------------------------------------------------------------------------------
1687 function class_list($name, $selected_id=null, $submit_on_change=false)
1689 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1691 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1693 'select_submit'=> $submit_on_change,
1699 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1702 echo "<td>$label</td>\n";
1704 echo class_list($name, $selected_id, $submit_on_change);
1708 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1710 echo "<tr><td class='label'>$label</td>";
1711 class_list_cells(null, $name, $selected_id, $submit_on_change);
1715 //-----------------------------------------------------------------------------------------------
1716 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1718 $where_opts = array();
1720 $where_opts[0] = "dflt_mb_flag='F'";
1722 $where_opts[0] = "dflt_mb_flag!='F'";
1724 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1725 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1726 array('order'=>'category_id',
1727 'spec_option' => $spec_opt,
1729 'select_submit'=> $submit_on_change,
1731 'where' => $where_opts,
1735 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1738 echo "<td>$label</td>\n";
1740 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1744 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1746 echo "<tr><td class='label'>$label</td>";
1747 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1751 //-----------------------------------------------------------------------------------------------
1752 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1754 $sql = "SELECT c.fa_class_id, CONCAT(c.fa_class_id,' - ',c.description) `desc`, CONCAT(p.fa_class_id,' - ',p.description) `class`, c.inactive FROM "
1755 .TB_PREF."stock_fa_class c LEFT JOIN ".TB_PREF."stock_fa_class p ON c.parent_id=p.fa_class_id";
1757 return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
1758 array('order'=>'c.fa_class_id',
1759 'spec_option' => $spec_opt,
1761 'select_submit'=> $submit_on_change,
1763 'search_box' => true,
1764 'search' => array("c.fa_class_id"),
1765 'search_submit' => false,
1769 'category' => 'class',
1773 function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1775 echo "<tr><td class='label'>$label</td>";
1777 echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change);
1778 echo "</td></tr>\n";
1781 //-----------------------------------------------------------------------------------------------
1783 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1786 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1788 return combo_input($name, $selected_id, $sql, 'id', 'name',
1790 'format' => '_format_account',
1791 'order' => array('class_id', 'id', 'parent'),
1792 'spec_option' =>$all_option,
1793 'spec_id' => ALL_TEXT
1797 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1800 echo "<td>$label</td>\n";
1802 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1806 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1808 echo "<tr><td class='label'>$label</td>";
1809 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1814 //-----------------------------------------------------------------------------------------------
1815 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1816 $cells=false, $all_option=false, $submit_on_change=false, $all=false, $type_id=false)
1818 if ($skip_bank_accounts)
1819 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1820 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1821 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1822 ."ON chart.account_code=acc.account_code
1823 WHERE acc.account_code IS NULL
1824 AND chart.account_type=type.id";
1826 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1827 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1828 WHERE chart.account_type=type.id";
1829 if ($type_id ) $sql .= " AND chart.account_type=".db_escape($type_id);
1830 $account = ($skip_bank_accounts ? "account2" : "account");
1831 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1833 'format' => '_format_account',
1834 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1837 'order' => array('type.class_id','type.id','account_code'),
1838 'search_box' => $cells,
1839 'search_submit' => false,
1843 'select_submit'=> $submit_on_change,
1846 'show_inactive' => $all
1850 function _format_account($row)
1852 return $row[0] . " " . $row[1];
1855 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1856 $skip_bank_accounts=false, $cells=false, $all_option=false,
1857 $submit_on_change=false, $all=false, $type_id=false)
1860 echo "<td>$label</td>\n";
1862 echo gl_all_accounts_list($name, $selected_id,
1863 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all, $type_id);
1867 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1868 $skip_bank_accounts=false, $cells=false, $all_option=false, $submit_on_change=false, $all=false, $type_id=false)
1870 echo "<tr><td class='label'>$label</td>";
1871 gl_all_accounts_list_cells(null, $name, $selected_id,
1872 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all, $type_id);
1876 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1879 $items['0'] = strlen($name_no) ? $name_no : _("No");
1880 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1882 return array_selector($name, $selected_id, $items,
1884 'select_submit'=> $submit_on_change,
1885 'async' => false ) ); // FIX?
1888 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1891 echo "<td>$label</td>\n";
1893 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1897 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1899 echo "<tr><td class='label'>$label</td>";
1900 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1904 //------------------------------------------------------------------------------------------------
1906 function languages_list($name, $selected_id=null, $all_option=false)
1908 global $installed_languages;
1912 $items[''] = $all_option;
1913 foreach ($installed_languages as $lang)
1914 $items[$lang['code']] = $lang['name'];
1915 return array_selector($name, $selected_id, $items);
1918 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1921 echo "<td>$label</td>\n";
1923 echo languages_list($name, $selected_id, $all_option);
1927 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1929 echo "<tr><td class='label'>$label</td>";
1930 languages_list_cells(null, $name, $selected_id, $all_option);
1934 //------------------------------------------------------------------------------------------------
1936 function bank_account_types_list($name, $selected_id=null)
1938 global $bank_account_types;
1940 return array_selector($name, $selected_id, $bank_account_types);
1943 function bank_account_types_list_cells($label, $name, $selected_id=null)
1946 echo "<td>$label</td>\n";
1948 echo bank_account_types_list($name, $selected_id);
1952 function bank_account_types_list_row($label, $name, $selected_id=null)
1954 echo "<tr><td class='label'>$label</td>";
1955 bank_account_types_list_cells(null, $name, $selected_id);
1959 //------------------------------------------------------------------------------------------------
1960 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1962 global $payment_person_types;
1965 foreach ($payment_person_types as $key=>$type)
1967 if ($key != PT_WORKORDER)
1968 $items[$key] = $type;
1970 return array_selector($name, $selected_id, $items,
1971 array( 'select_submit'=> $submit_on_change ) );
1974 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1977 echo "<td>$label</td>\n";
1979 echo payment_person_types_list($name, $selected_id, $related);
1983 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1985 echo "<tr><td class='label'>$label</td>";
1986 payment_person_types_list_cells(null, $name, $selected_id, $related);
1990 //------------------------------------------------------------------------------------------------
1992 function wo_types_list($name, $selected_id=null)
1994 global $wo_types_array;
1996 return array_selector($name, $selected_id, $wo_types_array,
1997 array( 'select_submit'=> true, 'async' => true ) );
2000 function wo_types_list_row($label, $name, $selected_id=null)
2002 echo "<tr><td class='label'>$label</td><td>\n";
2003 echo wo_types_list($name, $selected_id);
2004 echo "</td></tr>\n";
2007 //------------------------------------------------------------------------------------------------
2009 function dateformats_list_row($label, $name, $value=null)
2013 echo "<tr><td class='label'>$label</td>\n<td>";
2014 echo array_selector( $name, $value, $SysPrefs->dateformats );
2015 echo "</td></tr>\n";
2018 function dateseps_list_row($label, $name, $value=null)
2022 echo "<tr><td class='label'>$label</td>\n<td>";
2023 echo array_selector( $name, $value, $SysPrefs->dateseps );
2024 echo "</td></tr>\n";
2027 function thoseps_list_row($label, $name, $value=null)
2031 echo "<tr><td class='label'>$label</td>\n<td>";
2032 echo array_selector( $name, $value, $SysPrefs->thoseps );
2033 echo "</td></tr>\n";
2036 function decseps_list_row($label, $name, $value=null)
2040 echo "<tr><td class='label'>$label</td>\n<td>";
2041 echo array_selector( $name, $value, $SysPrefs->decseps );
2042 echo "</td></tr>\n";
2045 function themes_list_row($label, $name, $value=null)
2047 global $path_to_root;
2049 $path = $path_to_root.'/themes/';
2051 $themedir = opendir($path);
2052 while(false !== ($fname = readdir($themedir)))
2054 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
2056 $themes[$fname] = $fname;
2061 echo "<tr><td class='label'>$label</td>\n<td>";
2062 echo array_selector( $name, $value, $themes );
2063 echo "</td></tr>\n";
2066 function pagesizes_list_row($label, $name, $value=null)
2071 foreach ($SysPrefs->pagesizes as $pz)
2074 echo "<tr><td class='label'>$label</td>\n<td>";
2075 echo array_selector( $name, $value, $items );
2076 echo "</td></tr>\n";
2079 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
2081 global $systypes_array;
2083 // emove non-voidable transactions if needed
2084 $systypes = array_diff_key($systypes_array, array_flip($exclude));
2085 return array_selector($name, $value, $systypes,
2087 'spec_option'=> $spec_opt,
2088 'spec_id' => ALL_NUMERIC,
2089 'select_submit'=> $submit_on_change,
2095 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2098 echo "<td>$label</td>\n";
2100 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
2104 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2106 echo "<tr><td class='label'>$label</td>";
2107 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
2111 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
2113 global $systypes_array;
2116 echo "<td>$label</td>\n";
2119 $items = $systypes_array;
2121 // exclude quotes, orders and dimensions
2122 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
2123 unset($items[$excl]);
2125 echo array_selector($name, $value, $items,
2127 'spec_option'=> _("All"),
2129 'select_submit'=> $submit_on_change,
2136 function cust_allocations_list_cells($label, $name, $selected=null, $submit_on_change=false)
2143 ALL_TEXT=>_("All Types"),
2144 '1'=> _("Sales Invoices"),
2145 '2'=> _("Unsettled transactions"),
2146 '3' => _("Payments"),
2147 '4' => _("Credit Notes"),
2148 '5' => _("Delivery Notes"),
2149 '6' => _("Journal Entries")
2151 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2155 function supp_allocations_list_cell($name, $selected=null)
2160 ALL_TEXT=>_("All Types"),
2161 '1'=> _("Invoices"),
2162 '2'=> _("Overdue Invoices"),
2163 '3' => _("Payments"),
2164 '4' => _("Credit Notes"),
2165 '5' => _("Overdue Credit Notes"),
2166 '6' => _("Journal Entries")
2168 echo array_selector($name, $selected, $allocs);
2172 function supp_transactions_list_cell($name, $selected=null, $submit_on_change=false)
2177 ALL_TEXT=>_("All Types"),
2179 '1'=> _("Invoices"),
2180 '2'=> _("Unsettled transactions"),
2181 '3' => _("Payments"),
2182 '4' => _("Credit Notes"),
2183 '5' => _("Overdue Credit Notes"),
2184 '7' => _("Journal Entries")
2187 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2191 function policy_list_cells($label, $name, $selected=null)
2196 echo array_selector($name, $selected,
2197 array( '' => _("Automatically put balance on back order"),
2198 'CAN' => _("Cancel any quantites not delivered")) );
2202 function policy_list_row($label, $name, $selected=null)
2204 echo "<tr><td class='label'>$label</td>";
2205 policy_list_cells(null, $name, $selected);
2209 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2214 echo array_selector($name, $selected,
2215 array( 'Return' => _("Items Returned to Inventory Location"),
2216 'WriteOff' => _("Items Written Off")),
2217 array( 'select_submit'=> $submit_on_change ) );
2221 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2223 echo "<tr><td class='label'>$label</td>";
2224 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2228 function number_list($name, $selected, $from, $to, $no_option=false)
2231 for ($i = $from; $i <= $to; $i++)
2234 return array_selector($name, $selected, $items,
2235 array( 'spec_option' => $no_option,
2236 'spec_id' => ALL_NUMERIC) );
2239 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2244 echo number_list($name, $selected, $from, $to, $no_option);
2248 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2250 echo "<tr><td class='label'>$label</td>";
2251 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2255 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2256 $submit_on_change=true)
2258 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2259 ." GROUP BY profile";
2260 $result = db_query($sql, 'cannot get all profile names');
2261 $profiles = array();
2262 while($myrow=db_fetch($result)) {
2263 $profiles[$myrow['profile']] = $myrow['profile'];
2268 echo "<td class='label'>$label</td>\n";
2271 echo array_selector($name, $selected_id, $profiles,
2272 array( 'select_submit'=> $submit_on_change,
2273 'spec_option'=>$spec_opt,
2277 echo "</td></tr>\n";
2280 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2282 static $printers; // query only once for page display
2285 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2286 $result = db_query($sql, 'cannot get all printers');
2287 $printers = array();
2288 while($myrow=db_fetch($result)) {
2289 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2292 return array_selector($name, $selected_id, $printers,
2293 array( 'select_submit'=> $submit_on_change,
2294 'spec_option'=>$spec_opt,
2299 //------------------------------------------------------------------------------------------------
2301 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2304 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2306 $sql .= " WHERE type=$type";
2308 return combo_input($name, $selected_id, $sql, 'id', 'description',
2311 'order' => 'description',
2312 'select_submit'=> $submit_on_change,
2318 function quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change=false)
2321 echo "<td>$label</td>\n";
2323 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2327 function quick_entries_list_row($label, $name, $selected_id, $type, $submit_on_change=false)
2329 echo "<tr><td class='label'>$label</td>";
2330 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2335 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2337 global $quick_actions;
2339 echo "<tr><td class='label'>$label</td><td>";
2340 echo array_selector($name, $selected_id, $quick_actions,
2342 'select_submit'=> $submit_on_change
2344 echo "</td></tr>\n";
2347 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2349 global $quick_entry_types;
2351 echo "<tr><td class='label'>$label</td><td>";
2352 echo array_selector($name, $selected_id, $quick_entry_types,
2354 'select_submit'=> $submit_on_change
2356 echo "</td></tr>\n";
2359 function record_status_list_row($label, $name) {
2360 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2363 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2365 global $class_types;
2367 echo "<tr><td class='label'>$label</td><td>";
2368 echo array_selector($name, $selected_id, $class_types,
2370 'select_submit'=> $submit_on_change
2372 echo "</td></tr>\n";
2375 //------------------------------------------------------------------------------------------------
2377 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2378 $show_inactive = false)
2381 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2383 return combo_input($name, $selected_id, $sql, 'id', 'description',
2385 'spec_option'=>$new_item ? _("New role") : false,
2387 'select_submit'=> $submit_on_change,
2388 'show_inactive' => $show_inactive
2392 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2393 $show_inactive = false)
2396 echo "<td>$label</td>\n";
2398 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2402 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2403 $show_inactive = false)
2405 echo "<tr><td class='label'>$label</td>";
2406 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2410 function tab_list_row($label, $name, $selected_id=null)
2412 global $installed_extensions;
2415 foreach ($_SESSION['App']->applications as $app) {
2416 $tabs[$app->id] = access_string($app->name, true);
2419 echo "<td class='label'>$label</td><td>\n";
2420 echo array_selector($name, $selected_id, $tabs);
2421 echo "</td></tr>\n";
2424 //-----------------------------------------------------------------------------------------------
2426 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2429 global $path_to_root;
2430 include_once($path_to_root . "/admin/db/tags_db.inc");
2431 $results = get_tags($type, $all);
2433 while ($tag = db_fetch($results))
2434 $tags[$tag['id']] = $tag['name'];
2436 if (!isset($tags)) {
2437 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2440 return array_selector($name, null, $tags,
2443 'height' => $height,
2444 'spec_option'=> $spec_opt,
2449 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2452 echo "<td>$label</td>\n";
2454 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2459 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2461 echo "<tr><td class='label'>$label</td>";
2462 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2466 //---------------------------------------------------------------------------------------------
2467 // List of sets of active extensions
2469 function extset_list($name, $value=null, $submit_on_change=false)
2471 global $db_connections;
2474 foreach ($db_connections as $comp)
2475 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2476 return array_selector( $name, $value, $items,
2478 'spec_option'=> _("Available and/or installed"),
2480 'select_submit'=> $submit_on_change,
2485 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2488 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2493 if (@$filter['class']) {
2494 $where[] = 'type='.db_escape($filter['class']);
2497 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2498 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2499 if (@$filter['multi']) { // contact category selector for person
2503 return combo_input($name, $selected_id, $sql, 'id', 'name',
2506 'height' => $multi ? 5:1,
2507 'category' => $groups,
2508 'select_submit'=> $submit_on_change,
2514 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2516 echo "<tr><td class='label'>$label</td><td>";
2517 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2518 echo "</td></tr>\n";
2521 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2523 global $pterm_types;
2525 echo "<tr><td class='label'>$label</td><td>";
2526 echo array_selector($name, $selected_id, $pterm_types,
2528 'select_submit'=> $submit_on_change
2530 echo "</td></tr>\n";
2533 function coa_list_row($label, $name, $value=null)
2535 global $path_to_root, $installed_extensions;
2537 $path = $path_to_root.'/sql/';
2539 $sqldir = opendir($path);
2540 while (false !== ($fname = readdir($sqldir)))
2542 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2544 $ext = array_search_value($fname, $installed_extensions, 'sql');
2546 $descr = $ext['name'];
2547 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2548 $descr = _("Standard new company American COA (4 digit)");
2549 } elseif ($fname == 'en_US-demo.sql') {
2550 $descr = _("Standard American COA (4 digit) with demo data");
2554 $coas[$fname] = $descr;
2559 echo "<tr><td class='label'>$label</td>\n<td>";
2560 echo array_selector( $name, $value, $coas );
2561 echo "</td></tr>\n";
2564 function payment_services($name)
2566 global $payment_services;
2568 $services = (object)array_combine(array_keys($payment_services), array_keys($payment_services));
2570 return array_selector($name, null, $services, array(
2571 'spec_option'=> _("No payment Link"),
2576 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2578 global $tax_algorithms;
2580 return array_selector($name, $value, $tax_algorithms,
2582 'select_submit'=> $submit_on_change,
2588 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2591 echo "<td>$label</td>\n";
2593 echo tax_algorithm_list($name, $value, $submit_on_change);
2597 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2599 echo "<tr><td class='label'>$label</td>";
2600 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2604 function refline_list($name, $type, $value=null, $spec_option=false)
2606 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2611 $where = array('`trans_type`='.db_escape($type));
2613 return combo_input($name, $value, $sql, 'id', 'prefix',
2615 'order'=>array('prefix'),
2616 'spec_option' => $spec_option,
2620 'select_submit' => true,
2625 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2629 echo "<td class='label'>$label</td>\n";
2632 echo refline_list($name, $type, $selected_id, $spec_option);
2633 echo "</td></tr>\n";
2637 //----------------------------------------------------------------------------------------------
2639 function subledger_list($name, $account, $selected_id=null)
2642 $type = is_subledger_account($account);
2647 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2649 .TB_PREF."debtors_master d,"
2650 .TB_PREF."cust_branch c
2651 WHERE d.debtor_no=c.debtor_no AND NOT d.inactive AND c.receivables_account=".db_escape($account);
2653 $sql = "SELECT supplier_id as id, supp_ref as name
2655 .TB_PREF."suppliers s
2656 WHERE NOT s.inactive AND s.payable_account=".db_escape($account);
2658 $mode = get_company_pref('no_customer_list');
2660 return combo_input($name, $selected_id, $sql, 'id', 'name',
2668 function subledger_list_cells($label, $name, $account, $selected_id=null)
2671 echo "<td>$label</td>\n";
2673 echo subledger_list($name, $account, $selected_id);
2677 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2678 $submit_on_change=false, $show_inactive=false, $editkey = false)
2680 echo "<tr><td class='label'>$label</td><td nowrap>";
2681 echo subledger_list($name, $account, $selected_id);
2682 echo "</td>\n</tr>\n";
2685 function accounts_type_list_row($label, $name, $selected_id=null)
2689 echo "<td class='label'>$label</td>\n";
2691 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2692 echo array_selector($name, $selected_id, $sel);
2693 echo "</td></tr>\n";
2696 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2699 $sql = " SELECT user_id, IF(real_name = '', user_id, real_name) FROM ".TB_PREF."users";
2702 echo "<td>$label</td>\n";
2705 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2707 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2709 'order' => 'real_name',
2710 'select_submit'=> $submit_on_change,
2717 function collations_list_row($label, $name, $selected_id=null)
2719 global $supported_collations;
2723 echo "<td class='label'>$label</td>\n";
2726 echo array_selector($name, $selected_id, $supported_collations,
2727 array('select_submit'=> false) );
2728 echo "</td></tr>\n";