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($opts['search'], ' OR ') . ')';
159 if (count($opts['where'])) {
160 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
161 $where .= '('. implode($opts['where'], ' AND ') . ')';
162 $group_pos = strpos($sql, 'GROUP BY');
164 $group = substr($sql, $group_pos);
165 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
170 if ($opts['order'] != false) {
171 if (!is_array($opts['order']))
172 $opts['order'] = array($opts['order']);
173 $sql .= ' ORDER BY '.implode(',',$opts['order']);
177 // ------ make selector ----------
178 $selector = $first_opt = '';
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) {
305 switch (strtolower($type)) {
307 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=all&client_id=" . $id;
308 $img_title = _("Search items");
310 case "stock_manufactured":
311 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=manufactured&client_id=" . $id;
312 $img_title = _("Search items");
314 case "stock_purchased":
315 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=purchasable&client_id=" . $id;
316 $img_title = _("Search items");
319 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=sales&client_id=" . $id;
320 $img_title = _("Search items");
322 case "stock_costable":
323 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=costable&client_id=" . $id;
324 $img_title = _("Search items");
327 $parent = $opts['parent'];
328 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=component&parent=".$parent."&client_id=" . $id;
329 $img_title = _("Search items");
332 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=kits&client_id=" . $id;
333 $img_title = _("Search items");
336 $link = $path_to_root . "/sales/inquiry/customers_list.php?popup=1&client_id=" . $id;
337 $img_title = _("Search customers");
340 $link = $path_to_root . "/sales/inquiry/customer_branches_list.php?popup=1&client_id=" . $id . "#customer_id";
341 $img_title = _("Search branches");
344 $link = $path_to_root . "/purchasing/inquiry/suppliers_list.php?popup=1&client_id=" . $id;
345 $img_title = _("Search suppliers");
349 $skip = strtolower($type) == "account" ? false : true;
350 $link = $path_to_root . "/gl/inquiry/accounts_list.php?popup=1&skip=".$skip."&client_id=" . $id;
351 $img_title = _("Search GL accounts");
357 $theme = user_theme();
358 $img = '<img src="'.$path_to_root.'/themes/'.$theme.'/images/'.ICON_VIEW.
359 '" style="vertical-align:middle;width:12px;height:12px;border:0;" onclick="javascript:lookupWindow("'.
360 $link.'", "");" title="' . $img_title . '" style="cursor:pointer;" />';
364 if ($opts['editlink'])
365 $selector .= ' '.$opts['editlink'];
367 if ($search_box && $opts['cells'])
368 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td nowrap>$selector$img</td>";
370 $str = $edit_entry.$selector.$img;
376 Returns true if selector $name is subject to update.
378 function list_updated($name)
380 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
382 //----------------------------------------------------------------------------------------------
383 // Universal array combo generator
384 // $items is array of options 'value' => 'description'
385 // Options is reduced set of combo_selector options and is merged with defaults.
387 function array_selector($name, $selected_id, $items, $options=null)
391 $opts = array( // default options
392 'spec_option'=>false, // option text or false
393 'spec_id' => 0, // option id
394 'select_submit' => false, //submit on select: true/false
395 'async' => true, // select update via ajax (true) vs _page_body reload
396 'default' => '', // default value when $_POST is not set
397 'multi'=>false, // multiple select
398 // search box parameters
399 'height' => false, // number of lines in select box
403 // ------ merge options with defaults ----------
405 $opts = array_merge($opts, $options);
406 $select_submit = $opts['select_submit'];
407 $spec_id = $opts['spec_id'];
408 $spec_option = $opts['spec_option'];
409 $disabled = $opts['disabled'] ? "disabled" : '';
410 $multi = $opts['multi'];
412 if ($selected_id == null) {
413 $selected_id = get_post($name, $opts['default']);
415 if(!is_array($selected_id))
416 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
418 if (isset($_POST[ '_'.$name.'_update'])) {
420 $Ajax->activate('_page_body');
422 $Ajax->activate($name);
425 // ------ make selector ----------
426 $selector = $first_opt = '';
429 foreach($items as $value=>$descr) {
431 if (in_array((string)$value, $selected_id, true)) {
435 if ($first_id === false) {
439 $selector .= "<option $sel value='$value'>$descr</option>\n";
442 if ($first_id!==false) {
443 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
445 // Prepend special option.
446 if ($spec_option !== false) { // if special option used - add it
447 $first_id = $spec_id;
448 $first_opt = $spec_option;
449 $sel = $found===false ? 'selected' : '';
450 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
454 if ($found===false) {
455 $selected_id = array($first_id);
457 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
459 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
460 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
461 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
462 . $opts['sel_hint']."'>".$selector."</select>\n";
464 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
466 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
468 if ($select_submit != false) { // if submit on change is used - add select button
469 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
470 (fallback_mode() ? '' : 'display:none;'),
471 '_'.$name.'_update')."\n";
473 default_focus($name);
477 //----------------------------------------------------------------------------------------------
478 function array_selector_row($label, $name, $selected_id, $items, $options=null)
480 echo "<tr><td class='label'>$label</td>\n<td>";
481 echo array_selector($name, $selected_id, $items, $options);
485 //----------------------------------------------------------------------------------------------
486 function _format_add_curr($row, $pname=false)
488 static $company_currency;
490 if ($company_currency == null)
492 $company_currency = get_company_currency();
496 return $row[1] . ($row[2] == $company_currency ? '' : (" - " . $row[2]));
500 return $row[1] . " - " . $row[2] . ($row[3] == $company_currency ? '' : (" - " . $row[3]));
504 function add_edit_combo($type)
506 global $path_to_root, $popup_editors, $SysPrefs;
508 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
511 $theme_path = $path_to_root . '/themes/' . user_theme();
513 $key = $popup_editors[$type][1];
514 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
515 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
516 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
519 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
520 $all=false, $editkey = false)
523 if (!empty($SysPrefs->prefs['shortname_name_in_list']))
524 $sql = "SELECT supplier_id, supp_ref, supp_name, curr_code, inactive FROM ".TB_PREF."suppliers ";
526 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
528 $mode = get_company_pref('no_supplier_list');
531 set_editor('supplier', $name, $editkey);
533 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
535 'format' => '_format_add_curr',
536 'order' => array('supp_ref'),
537 'search_box' => $mode!=0,
539 'search' => array("supp_ref","supp_name","gst_no"),
540 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
541 'spec_id' => ALL_TEXT,
542 'select_submit'=> $submit_on_change,
544 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
545 _('Select supplier'),
546 'show_inactive'=>$all,
547 'editlink' => $editkey ? add_edit_combo('supplier') : false
552 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
553 $submit_on_change=false, $all=false, $editkey = false)
556 echo "<td>$label</td>\n";
558 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
563 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
564 $submit_on_change=false, $all=false, $editkey = false)
566 echo "<tr><td class='label'>$label</td><td>";
567 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
571 //----------------------------------------------------------------------------------------------
573 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
574 $show_inactive=false, $editkey = false)
577 if (!empty($SysPrefs->prefs['shortname_name_in_list']))
578 $sql = "SELECT debtor_no, debtor_ref, name, curr_code, inactive FROM ".TB_PREF."debtors_master ";
580 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
582 $mode = get_company_pref('no_customer_list');
585 set_editor('customer', $name, $editkey);
587 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
589 'format' => '_format_add_curr',
590 'order' => array('debtor_ref'),
591 'search_box' => $mode!=0,
594 'search' => array("debtor_ref","name","tax_id"),
595 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
596 'spec_id' => ALL_TEXT,
597 'select_submit'=> $submit_on_change,
599 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
600 _('Select customer'),
601 'show_inactive' => $show_inactive,
602 'editlink' => $editkey ? add_edit_combo('customer') : false
607 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
608 $submit_on_change=false, $show_inactive=false, $editkey = false)
611 echo "<td>$label</td>\n";
613 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
614 $show_inactive, $editkey);
618 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
619 $submit_on_change=false, $show_inactive=false, $editkey = false)
622 echo "<tr><td class='label'>$label</td><td nowrap>";
623 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
624 $show_inactive, $editkey);
625 echo "</td>\n</tr>\n";
628 //------------------------------------------------------------------------------------------------
630 function customer_branches_list($customer_id, $name, $selected_id=null,
631 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
634 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
635 WHERE debtor_no=" . db_escape($customer_id)." ";
638 set_editor('branch', $name, $editkey);
640 $where = $enabled ? array("inactive = 0") : array();
641 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
644 'order' => array('branch_ref'),
645 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
646 'spec_id' => ALL_TEXT,
647 'select_submit'=> $submit_on_change,
648 'sel_hint' => _('Select customer branch'),
649 'editlink' => $editkey ? add_edit_combo('branch') : false
653 //------------------------------------------------------------------------------------------------
655 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
656 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
659 echo "<td>$label</td>\n";
661 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
662 $submit_on_change, $editkey);
666 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
667 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
669 echo "<tr><td class='label'>$label</td>";
670 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
671 $all_option, $enabled, $submit_on_change, $editkey);
675 //------------------------------------------------------------------------------------------------
677 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
680 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations WHERE fixed_asset=".(int)$fixed_asset;
682 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
684 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
685 'spec_id' => ALL_TEXT,
686 'select_submit'=> $submit_on_change
690 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
693 echo "<td>$label</td>\n";
695 echo locations_list($name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
699 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
701 echo "<tr><td class='label'>$label</td>";
702 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
706 //-----------------------------------------------------------------------------------------------
708 function currencies_list($name, $selected_id=null, $submit_on_change=false, $exclude_home_curr=false)
710 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
711 if ($exclude_home_curr)
712 $sql .= " WHERE curr_abrev!='".get_company_currency()."'";
714 // default to the company currency
715 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
717 'select_submit'=> $submit_on_change,
718 'default' => get_company_currency(),
723 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
726 echo "<td>$label</td>\n";
728 echo currencies_list($name, $selected_id, $submit_on_change);
732 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
734 echo "<tr><td class='label'>$label</td>";
735 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
739 //---------------------------------------------------------------------------------------------------
741 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
744 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
746 // default to the company current fiscal year
748 return combo_input($name, $selected_id, $sql, 'id', '',
751 'default' => get_company_pref('f_year'),
752 'format' => '_format_fiscalyears',
753 'select_submit'=> $submit_on_change,
758 function _format_fiscalyears($row)
760 return sql2date($row[1]) . " - " . sql2date($row[2])
761 . " " . ($row[3] ? _('Closed') : _('Active'));
764 function fiscalyears_list_cells($label, $name, $selected_id=null)
767 echo "<td>$label</td>\n";
769 echo fiscalyears_list($name, $selected_id);
773 function fiscalyears_list_row($label, $name, $selected_id=null)
775 echo "<tr><td class='label'>$label</td>";
776 fiscalyears_list_cells(null, $name, $selected_id);
779 //------------------------------------------------------------------------------------
781 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
782 $submit_on_change=false, $showclosed=false, $showtype=1)
784 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
787 'order' => 'reference',
788 'spec_option'=>$no_option ? $showname : false,
790 'select_submit'=> $submit_on_change,
795 $options['where'][] = "closed=0";
797 $options['where'][] = "type_=".db_escape($showtype);
799 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
802 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
803 $showclosed=false, $showtype=0, $submit_on_change=false)
806 echo "<td>$label</td>\n";
808 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
812 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
813 $showclosed=false, $showtype=0, $submit_on_change=false)
815 echo "<tr><td class='label'>$label</td>";
816 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
817 $showclosed, $showtype, $submit_on_change);
821 //---------------------------------------------------------------------------------------------------
823 function stock_items_list($name, $selected_id=null, $all_option=false,
824 $submit_on_change=false, $opts=array(), $editkey = false, $type = "stock")
826 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
827 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
829 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
830 $sql .= " AND mb_flag='F'";
832 $sql .= " AND mb_flag!='F'";
835 set_editor('item', $name, $editkey);
837 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
840 'format' => '_format_stock_items',
841 'spec_option' => $all_option===true ? _("All Items") : $all_option,
842 'spec_id' => ALL_TEXT,
843 'search_box' => true,
844 'search' => array("stock_id", "c.description","s.description"),
845 'search_submit' => get_company_pref('no_item_list')!=0 && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']),
847 'select_submit'=> $submit_on_change,
849 'order' => array('c.description','stock_id'),
850 'editlink' => $editkey ? add_edit_combo('item') : false,
857 function _format_stock_items($row)
859 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
862 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
863 $submit_on_change=false, $all=false, $editkey = false, $opts= array())
865 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
866 $editor_item = 'fa_item';
868 $editor_item = 'item';
871 // set_editor($editor_item, $name, $editkey);
874 echo "<td>$label</td>\n";
877 // $opts = array_merge($options, array('cells'=>true, 'show_inactive'=>$all, 'new_icon' => $editkey ? 'item' : false));
879 // echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, $opts);
881 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
882 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey);
886 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
889 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
893 //---------------------------------------------------------------------------------------------------
895 // Select item via foreign code.
897 function sales_items_list($name, $selected_id=null, $all_option=false,
898 $submit_on_change=false, $type='', $opts=array())
901 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
902 i.inactive, if(count(*)>1, '0', s.editable) as editable
904 ".TB_PREF."stock_master s,
905 ".TB_PREF."item_codes i
907 ".TB_PREF."stock_category c
908 ON i.category_id=c.category_id
909 WHERE i.stock_id=s.stock_id
913 if ($type == 'local') { // exclude foreign codes
914 $sql .= " AND !i.is_foreign";
915 } elseif ($type == 'kits') { // sales kits
916 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
918 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
919 $sql .= " GROUP BY i.item_code";
921 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
924 'format' => '_format_stock_items',
925 'spec_option' => $all_option===true ? _("All Items") : $all_option,
926 'spec_id' => ALL_TEXT,
927 'search_box' => true,
928 'search' => array("i.item_code", "c.description", "i.description"),
929 'search_submit' => get_company_pref('no_item_list')!=0,
931 'select_submit'=> $submit_on_change,
933 'order' => array('c.description','i.item_code'),
936 ), $opts), $type == 'kits' ? $type : "stock_sales" );
939 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
942 set_editor('item', $name, $editkey);
945 echo "<td>$label</td>\n";
946 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
947 '', array('cells'=>true, 'max'=>50)); // maximum is set to 50 and not default 255.
950 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
952 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
953 'kits', array('cells'=>false, 'editable' => false));
956 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
960 echo "<td class='label'>$label</td>\n";
962 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
963 'local', array('cells'=>false, 'editable' => false));
966 //------------------------------------------------------------------------------------
968 function stock_manufactured_items_list($name, $selected_id=null,
969 $all_option=false, $submit_on_change=false)
971 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
972 array('where'=>array("mb_flag= 'M'")), false, "stock_manufactured");
975 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
976 $all_option=false, $submit_on_change=false)
979 echo "<td>$label</td>\n";
981 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
985 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
986 $all_option=false, $submit_on_change=false)
988 echo "<tr><td class='label'>$label</td>";
989 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
992 //------------------------------------------------------------------------------------
994 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
995 $all_option=false, $submit_on_change=false, $editkey = false)
997 $parent = db_escape($parent_stock_id);
998 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
999 array('where'=>array("stock_id != $parent"), 'parent'=> $parent_stock_id), $editkey, "component");
1003 function stock_component_items_list_cells($label, $name, $parent_stock_id,
1004 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
1007 echo "<td>$label</td>\n";
1008 $parent = db_escape($parent_stock_id);
1009 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1010 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true, 'parent'=> $parent_stock_id), $editkey, "component");
1012 //------------------------------------------------------------------------------------
1014 function stock_costable_items_list($name, $selected_id=null,
1015 $all_option=false, $submit_on_change=false)
1017 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1018 array('where'=>array("mb_flag!='D'")), false, "stock_costable");
1021 function stock_costable_items_list_cells($label, $name, $selected_id=null,
1022 $all_option=false, $submit_on_change=false)
1025 echo "<td>$label</td>\n";
1026 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1027 array('where'=>array("mb_flag!='D'"), 'cells'=>true), false, "stock_costable");
1030 //------------------------------------------------------------------------------------
1031 function stock_purchasable_items_list($name, $selected_id=null,
1032 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
1034 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1035 array('where'=>array("NOT no_purchase"),
1036 'show_inactive'=>$all), $editkey, "stock_purchased");
1039 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
1041 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
1042 $all_option=false, $submit_on_change=false, $editkey=false)
1045 echo "<td>$label</td>\n";
1046 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1047 array('where'=>array("NOT no_purchase"),
1049 'cells'=>true), $editkey);
1052 //------------------------------------------------------------------------------------
1054 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
1056 global $stock_types;
1060 echo "<td class='label'>$label</td>\n";
1063 echo array_selector($name, $selected_id, $stock_types,
1065 'select_submit'=> true,
1066 'disabled' => !$enabled) );
1067 echo "</td></tr>\n";
1070 function stock_units_list_row($label, $name, $value=null, $enabled=true)
1072 $result = get_all_item_units();
1075 echo "<td class='label'>$label</td>\n";
1078 while($unit = db_fetch($result))
1079 $units[$unit['abbr']] = $unit['name'];
1081 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
1083 echo "</td></tr>\n";
1086 //------------------------------------------------------------------------------------
1088 function stock_purchasable_fa_list_cells($label, $name, $selected_id=null, $all_option=false,
1089 $submit_on_change=false, $all=false, $editkey = false, $exclude_items = array())
1091 // Check if a fixed asset has been bought.
1092 $where_opts[] = "stock_id NOT IN
1093 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1095 // exclude items currently on the order.
1096 foreach($exclude_items as $item) {
1097 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1099 $where_opts[] = "mb_flag='F'";
1101 echo stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, $all, $editkey,
1102 array('fixed_asset' => true, 'where' => $where_opts));
1105 function stock_disposable_fa_list($name, $selected_id=null,
1106 $all_option=false, $submit_on_change=false)
1108 // Check if a fixed asset has been bought....
1109 $where_opts[] = "stock_id IN
1110 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1111 // ...but has not been disposed or sold already.
1112 $where_opts[] = "stock_id NOT IN
1113 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1115 $where_opts[] = "mb_flag='F'";
1117 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1118 array('fixed_asset' => true, 'where' => $where_opts));
1121 function stock_disposable_fa_list_cells($label, $name, $selected_id=null,
1122 $all_option=false, $submit_on_change=false, $exclude_items = array())
1124 // Check if a fixed asset has been bought....
1125 $where_opts[] = "stock_id IN
1126 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1127 // ...but has not been disposed or sold already.
1128 $where_opts[] = "stock_id NOT IN
1129 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1131 $where_opts[] = "mb_flag='F'";
1133 foreach($exclude_items as $item) {
1134 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1138 echo "<td>$label</td>\n";
1139 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1140 array('fixed_asset' => true, 'cells'=>true, 'where' => $where_opts));
1143 function stock_depreciable_fa_list_cells($label, $name, $selected_id=null,
1144 $all_option=false, $submit_on_change=false)
1147 // Check if a fixed asset has been bought....
1148 $where_opts[] = "stock_id IN
1149 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1150 // ...but has not been disposed or sold already.
1151 $where_opts[] = "stock_id NOT IN
1152 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1154 $year = get_current_fiscalyear();
1155 $begin = date2sql(add_months(sql2date($year['begin']), -1));
1156 $end = date2sql(add_months(sql2date($year['end']), -1));
1158 // check if current fiscal year
1159 $where_opts[] = "depreciation_date <= '".$end."'";
1160 $where_opts[] = "depreciation_date >= '".$begin."'";
1162 $where_opts[] = "material_cost > 0";
1163 $where_opts[] = "mb_flag='F'";
1166 echo "<td>$label</td>\n";
1167 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1168 array('fixed_asset' => true, 'where' => $where_opts, 'cells'=>true));
1171 //------------------------------------------------------------------------------------
1173 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
1175 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
1177 return combo_input($name, $selected_id, $sql, 'id', 'name',
1179 'spec_option' => $none_option,
1180 'spec_id' => ALL_NUMERIC,
1181 'select_submit'=> $submit_on_change,
1186 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1187 $submit_on_change=false)
1190 echo "<td>$label</td>\n";
1192 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1196 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1197 $submit_on_change=false)
1199 echo "<tr><td class='label'>$label</td>";
1200 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1204 //------------------------------------------------------------------------------------
1206 function tax_groups_list($name, $selected_id=null,
1207 $none_option=false, $submit_on_change=false)
1209 $sql = "SELECT id, name, inactive FROM ".TB_PREF."tax_groups";
1211 return combo_input($name, $selected_id, $sql, 'id', 'name',
1214 'spec_option' => $none_option,
1215 'spec_id' => ALL_NUMERIC,
1216 'select_submit'=> $submit_on_change,
1221 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1224 echo "<td>$label</td>\n";
1226 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1230 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1232 echo "<tr><td class='label'>$label</td>";
1233 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1237 //------------------------------------------------------------------------------------
1239 function item_tax_types_list($name, $selected_id=null, $show_inactive = false)
1241 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1242 if (!$show_inactive)
1243 $sql .= " WHERE !inactive";
1245 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1248 function item_tax_types_list_cells($label, $name, $selected_id=null, $show_inactive = false)
1251 echo "<td>$label</td>\n";
1253 echo item_tax_types_list($name, $selected_id, $show_inactive);
1257 function item_tax_types_list_row($label, $name, $selected_id=null, $show_inactive = false)
1259 echo "<tr><td class='label'>$label</td>";
1260 item_tax_types_list_cells(null, $name, $selected_id, $show_inactive);
1264 //------------------------------------------------------------------------------------
1266 function shippers_list($name, $selected_id=null)
1268 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1269 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1270 array('order'=>array('shipper_name')));
1273 function shippers_list_cells($label, $name, $selected_id=null)
1276 echo "<td>$label</td>\n";
1278 echo shippers_list($name, $selected_id);
1282 function shippers_list_row($label, $name, $selected_id=null)
1284 echo "<tr><td class='label'>$label</td>";
1285 shippers_list_cells(null, $name, $selected_id);
1289 //-------------------------------------------------------------------------------------
1291 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1293 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1294 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1295 array('order'=>array('salesman_name'),
1296 'spec_option' => $spec_opt,
1297 'spec_id' => ALL_NUMERIC));
1300 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1303 echo "<td>$label</td>\n";
1305 echo sales_persons_list($name, $selected_id, $spec_opt);
1309 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1311 echo "<tr><td class='label'>$label</td>";
1312 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1316 //------------------------------------------------------------------------------------
1318 function sales_areas_list($name, $selected_id=null, $special_option=false)
1320 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1321 return combo_input($name, $selected_id, $sql, 'area_code', 'description',
1322 array('spec_option' => $special_option===true ? ' ' : $special_option,
1323 'order' => 'description', 'spec_id' => 0));
1326 function sales_areas_list_cells($label, $name, $selected_id=null, $special_option=false)
1329 echo "<td>$label</td>\n";
1331 echo sales_areas_list($name, $selected_id, $special_option);
1335 function sales_areas_list_row($label, $name, $selected_id=null, $special_option=false)
1337 echo "<tr><td class='label'>$label</td>";
1338 sales_areas_list_cells(null, $name, $selected_id, $special_option);
1342 //------------------------------------------------------------------------------------
1344 function sales_groups_list($name, $selected_id=null, $special_option=false)
1346 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1347 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1348 'spec_option' => $special_option===true ? ' ' : $special_option,
1349 'order' => 'description', 'spec_id' => 0,
1353 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1356 echo "<td>$label</td>\n";
1358 echo sales_groups_list($name, $selected_id, $special_option);
1362 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1364 echo "<tr><td class='label'>$label</td>";
1365 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1369 //------------------------------------------------------------------------------------
1371 function _format_template_items($row)
1373 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1376 function templates_list($name, $selected_id=null, $special_option=false)
1378 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1379 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1380 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1381 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1382 'format' => '_format_template_items',
1383 'spec_option' => $special_option===true ? ' ' : $special_option,
1384 'order' => 'order_no', 'spec_id' => 0,
1388 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1391 echo "<td>$label</td>\n";
1393 echo templates_list($name, $selected_id, $special_option);
1397 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1399 echo "<tr><td class='label'>$label</td>";
1400 templates_list_cells(null, $name, $selected_id, $special_option);
1404 //------------------------------------------------------------------------------------
1406 function workorders_list($name, $selected_id=null)
1408 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1409 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1412 function workorders_list_cells($label, $name, $selected_id=null)
1415 echo "<td>$label</td>\n";
1417 echo workorders_list($name, $selected_id);
1421 function workorders_list_row($label, $name, $selected_id=null)
1423 echo "<tr><td class='label'>$label</td>";
1424 workorders_list_cells(null, $name, $selected_id);
1428 //------------------------------------------------------------------------------------
1430 function payment_terms_list($name, $selected_id=null)
1432 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1433 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1436 function payment_terms_list_cells($label, $name, $selected_id=null)
1439 echo "<td>$label</td>\n";
1441 echo payment_terms_list($name, $selected_id);
1445 function payment_terms_list_row($label, $name, $selected_id=null)
1447 echo "<tr><td class='label'>$label</td>";
1448 payment_terms_list_cells(null, $name, $selected_id);
1452 //------------------------------------------------------------------------------------
1454 function credit_status_list($name, $selected_id=null)
1456 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1457 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1460 function credit_status_list_cells($label, $name, $selected_id=null)
1463 echo "<td>$label</td>\n";
1465 echo credit_status_list($name, $selected_id);
1469 function credit_status_list_row($label, $name, $selected_id=null)
1471 echo "<tr><td class='label'>$label</td>";
1472 credit_status_list_cells(null, $name, $selected_id);
1476 //-----------------------------------------------------------------------------------------------
1478 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1480 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1482 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1484 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1486 'select_submit'=> $submit_on_change,
1490 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1493 echo "<td>$label</td>\n";
1495 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1499 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1501 echo "<tr><td class='label'>$label</td>";
1502 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1506 //-----------------------------------------------------------------------------------------------
1508 function _format_date($row)
1510 return sql2date($row['reconciled']);
1513 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1515 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1516 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1517 GROUP BY reconciled";
1518 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1520 'spec_option' => $special_option,
1521 'format' => '_format_date',
1523 'select_submit'=> $submit_on_change
1527 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1530 echo "<td>$label</td>\n";
1532 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1536 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1539 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1543 //-----------------------------------------------------------------------------------------------
1545 function workcenter_list($name, $selected_id=null, $all_option=false)
1548 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1550 return combo_input($name, $selected_id, $sql, 'id', 'name',
1552 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1553 'spec_id' => ALL_TEXT,
1557 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1559 default_focus($name);
1561 echo "<td>$label</td>\n";
1563 echo workcenter_list($name, $selected_id, $all_option);
1567 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1569 echo "<tr><td class='label'>$label</td>";
1570 workcenter_list_cells(null, $name, $selected_id, $all_option);
1574 //-----------------------------------------------------------------------------------------------
1576 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1578 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1579 FROM ".TB_PREF."bank_accounts";
1581 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1583 'format' => '_format_add_curr',
1584 'select_submit'=> $submit_on_change,
1585 'spec_option' => $spec_option,
1591 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1594 echo "<td>$label</td>\n";
1596 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1600 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1602 echo "<tr><td class='label'>$label</td>";
1603 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1606 //-----------------------------------------------------------------------------------------------
1608 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1611 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1612 FROM ".TB_PREF."bank_accounts
1613 WHERE account_type=".BT_CASH;
1616 echo "<tr><td class='label'>$label</td>\n";
1618 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1620 'spec_option' => $all_option,
1621 'spec_id' => ALL_TEXT,
1622 'format' => '_format_add_curr',
1623 'select_submit'=> $submit_on_change,
1626 echo "</td></tr>\n";
1628 //-----------------------------------------------------------------------------------------------
1630 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1632 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1634 default_focus($name);
1637 echo "<td class='label'>$label</td>\n";
1640 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1642 'select_submit'=> $submit_on_change,
1644 'spec_option' =>$spec_option,
1646 'order'=> array('pos_name')
1648 echo "</td></tr>\n";
1651 //-----------------------------------------------------------------------------------------------
1652 // Payment type selector for current user.
1654 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1656 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1658 if ($category == PM_CASH) // only cash
1659 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1660 elseif ($category == PM_CREDIT) // only delayed payments
1661 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1662 elseif (!$prepayments)
1663 $sql .= " WHERE days_before_due>=0";
1665 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1667 'select_submit'=> $submit_on_change,
1673 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1676 echo "<td class='label'>$label</td>\n";
1679 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1683 //-----------------------------------------------------------------------------------------------
1685 function class_list($name, $selected_id=null, $submit_on_change=false)
1687 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1689 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1691 'select_submit'=> $submit_on_change,
1697 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1700 echo "<td>$label</td>\n";
1702 echo class_list($name, $selected_id, $submit_on_change);
1706 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1708 echo "<tr><td class='label'>$label</td>";
1709 class_list_cells(null, $name, $selected_id, $submit_on_change);
1713 //-----------------------------------------------------------------------------------------------
1714 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1716 $where_opts = array();
1718 $where_opts[0] = "dflt_mb_flag='F'";
1720 $where_opts[0] = "dflt_mb_flag!='F'";
1722 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1723 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1724 array('order'=>'category_id',
1725 'spec_option' => $spec_opt,
1727 'select_submit'=> $submit_on_change,
1729 'where' => $where_opts,
1733 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1736 echo "<td>$label</td>\n";
1738 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1742 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1744 echo "<tr><td class='label'>$label</td>";
1745 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1749 //-----------------------------------------------------------------------------------------------
1750 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1752 $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 "
1753 .TB_PREF."stock_fa_class c LEFT JOIN ".TB_PREF."stock_fa_class p ON c.parent_id=p.fa_class_id";
1755 return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
1756 array('order'=>'c.fa_class_id',
1757 'spec_option' => $spec_opt,
1759 'select_submit'=> $submit_on_change,
1761 'search_box' => true,
1762 'search' => array("c.fa_class_id"),
1763 'search_submit' => false,
1767 'category' => 'class',
1771 function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1773 echo "<tr><td class='label'>$label</td>";
1775 echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change);
1776 echo "</td></tr>\n";
1779 //-----------------------------------------------------------------------------------------------
1781 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1784 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1786 return combo_input($name, $selected_id, $sql, 'id', 'name',
1788 'format' => '_format_account',
1789 'order' => array('class_id', 'id', 'parent'),
1790 'spec_option' =>$all_option,
1791 'spec_id' => ALL_TEXT
1795 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1798 echo "<td>$label</td>\n";
1800 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1804 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1806 echo "<tr><td class='label'>$label</td>";
1807 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1812 //-----------------------------------------------------------------------------------------------
1813 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1814 $cells=false, $all_option=false, $submit_on_change=false, $all=false, $type_id=false)
1816 if ($skip_bank_accounts)
1817 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1818 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1819 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1820 ."ON chart.account_code=acc.account_code
1821 WHERE acc.account_code IS NULL
1822 AND chart.account_type=type.id";
1824 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1825 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1826 WHERE chart.account_type=type.id";
1827 if ($type_id ) $sql .= " AND chart.account_type=".db_escape($type_id);
1828 $account = ($skip_bank_accounts ? "account2" : "account");
1829 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1831 'format' => '_format_account',
1832 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1835 'order' => array('type.class_id','type.id','account_code'),
1836 'search_box' => $cells,
1837 'search_submit' => false,
1841 'select_submit'=> $submit_on_change,
1844 'show_inactive' => $all
1848 function _format_account($row)
1850 return $row[0] . " " . $row[1];
1853 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1854 $skip_bank_accounts=false, $cells=false, $all_option=false,
1855 $submit_on_change=false, $all=false, $type_id=false)
1858 echo "<td>$label</td>\n";
1860 echo gl_all_accounts_list($name, $selected_id,
1861 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all, $type_id);
1865 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1866 $skip_bank_accounts=false, $cells=false, $all_option=false, $type_id=false)
1868 echo "<tr><td class='label'>$label</td>";
1869 gl_all_accounts_list_cells(null, $name, $selected_id,
1870 $skip_bank_accounts, $cells, $all_option, $type_id);
1874 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1877 $items['0'] = strlen($name_no) ? $name_no : _("No");
1878 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1880 return array_selector($name, $selected_id, $items,
1882 'select_submit'=> $submit_on_change,
1883 'async' => false ) ); // FIX?
1886 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1889 echo "<td>$label</td>\n";
1891 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1895 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1897 echo "<tr><td class='label'>$label</td>";
1898 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1902 //------------------------------------------------------------------------------------------------
1904 function languages_list($name, $selected_id=null, $all_option=false)
1906 global $installed_languages;
1910 $items[''] = $all_option;
1911 foreach ($installed_languages as $lang)
1912 $items[$lang['code']] = $lang['name'];
1913 return array_selector($name, $selected_id, $items);
1916 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1919 echo "<td>$label</td>\n";
1921 echo languages_list($name, $selected_id, $all_option);
1925 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1927 echo "<tr><td class='label'>$label</td>";
1928 languages_list_cells(null, $name, $selected_id, $all_option);
1932 //------------------------------------------------------------------------------------------------
1934 function bank_account_types_list($name, $selected_id=null)
1936 global $bank_account_types;
1938 return array_selector($name, $selected_id, $bank_account_types);
1941 function bank_account_types_list_cells($label, $name, $selected_id=null)
1944 echo "<td>$label</td>\n";
1946 echo bank_account_types_list($name, $selected_id);
1950 function bank_account_types_list_row($label, $name, $selected_id=null)
1952 echo "<tr><td class='label'>$label</td>";
1953 bank_account_types_list_cells(null, $name, $selected_id);
1957 //------------------------------------------------------------------------------------------------
1958 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1960 global $payment_person_types;
1963 foreach ($payment_person_types as $key=>$type)
1965 if ($key != PT_WORKORDER)
1966 $items[$key] = $type;
1968 return array_selector($name, $selected_id, $items,
1969 array( 'select_submit'=> $submit_on_change ) );
1972 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1975 echo "<td>$label</td>\n";
1977 echo payment_person_types_list($name, $selected_id, $related);
1981 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1983 echo "<tr><td class='label'>$label</td>";
1984 payment_person_types_list_cells(null, $name, $selected_id, $related);
1988 //------------------------------------------------------------------------------------------------
1990 function wo_types_list($name, $selected_id=null)
1992 global $wo_types_array;
1994 return array_selector($name, $selected_id, $wo_types_array,
1995 array( 'select_submit'=> true, 'async' => true ) );
1998 function wo_types_list_row($label, $name, $selected_id=null)
2000 echo "<tr><td class='label'>$label</td><td>\n";
2001 echo wo_types_list($name, $selected_id);
2002 echo "</td></tr>\n";
2005 //------------------------------------------------------------------------------------------------
2007 function dateformats_list_row($label, $name, $value=null)
2011 echo "<tr><td class='label'>$label</td>\n<td>";
2012 echo array_selector( $name, $value, $SysPrefs->dateformats );
2013 echo "</td></tr>\n";
2016 function dateseps_list_row($label, $name, $value=null)
2020 echo "<tr><td class='label'>$label</td>\n<td>";
2021 echo array_selector( $name, $value, $SysPrefs->dateseps );
2022 echo "</td></tr>\n";
2025 function thoseps_list_row($label, $name, $value=null)
2029 echo "<tr><td class='label'>$label</td>\n<td>";
2030 echo array_selector( $name, $value, $SysPrefs->thoseps );
2031 echo "</td></tr>\n";
2034 function decseps_list_row($label, $name, $value=null)
2038 echo "<tr><td class='label'>$label</td>\n<td>";
2039 echo array_selector( $name, $value, $SysPrefs->decseps );
2040 echo "</td></tr>\n";
2043 function themes_list_row($label, $name, $value=null)
2045 global $path_to_root;
2047 $path = $path_to_root.'/themes/';
2049 $themedir = opendir($path);
2050 while(false !== ($fname = readdir($themedir)))
2052 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
2054 $themes[$fname] = $fname;
2059 echo "<tr><td class='label'>$label</td>\n<td>";
2060 echo array_selector( $name, $value, $themes );
2061 echo "</td></tr>\n";
2064 function pagesizes_list_row($label, $name, $value=null)
2069 foreach ($SysPrefs->pagesizes as $pz)
2072 echo "<tr><td class='label'>$label</td>\n<td>";
2073 echo array_selector( $name, $value, $items );
2074 echo "</td></tr>\n";
2077 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
2079 global $systypes_array;
2081 // emove non-voidable transactions if needed
2082 $systypes = array_diff_key($systypes_array, array_flip($exclude));
2083 return array_selector($name, $value, $systypes,
2085 'spec_option'=> $spec_opt,
2086 'spec_id' => ALL_NUMERIC,
2087 'select_submit'=> $submit_on_change,
2093 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2096 echo "<td>$label</td>\n";
2098 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
2102 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2104 echo "<tr><td class='label'>$label</td>";
2105 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
2109 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
2111 global $systypes_array;
2114 echo "<td>$label</td>\n";
2117 $items = $systypes_array;
2119 // exclude quotes, orders and dimensions
2120 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
2121 unset($items[$excl]);
2123 echo array_selector($name, $value, $items,
2125 'spec_option'=> _("All"),
2127 'select_submit'=> $submit_on_change,
2134 function cust_allocations_list_cells($label, $name, $selected=null, $submit_on_change=false)
2141 ALL_TEXT=>_("All Types"),
2142 '1'=> _("Sales Invoices"),
2143 '2'=> _("Unsettled transactions"),
2144 '3' => _("Payments"),
2145 '4' => _("Credit Notes"),
2146 '5' => _("Delivery Notes")
2148 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2152 function supp_allocations_list_cell($name, $selected=null)
2157 ALL_TEXT=>_("All Types"),
2158 '1'=> _("Invoices"),
2159 '2'=> _("Overdue Invoices"),
2160 '3' => _("Payments"),
2161 '4' => _("Credit Notes"),
2162 '5' => _("Overdue Credit Notes")
2164 echo array_selector($name, $selected, $allocs);
2168 function supp_transactions_list_cell($name, $selected=null, $submit_on_change=false)
2173 ALL_TEXT=>_("All Types"),
2175 '1'=> _("Invoices"),
2176 '2'=> _("Unsettled transactions"),
2177 '3' => _("Payments"),
2178 '4' => _("Credit Notes"),
2179 '5' => _("Overdue Credit Notes")
2182 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2186 function policy_list_cells($label, $name, $selected=null)
2191 echo array_selector($name, $selected,
2192 array( '' => _("Automatically put balance on back order"),
2193 'CAN' => _("Cancel any quantites not delivered")) );
2197 function policy_list_row($label, $name, $selected=null)
2199 echo "<tr><td class='label'>$label</td>";
2200 policy_list_cells(null, $name, $selected);
2204 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2209 echo array_selector($name, $selected,
2210 array( 'Return' => _("Items Returned to Inventory Location"),
2211 'WriteOff' => _("Items Written Off")),
2212 array( 'select_submit'=> $submit_on_change ) );
2216 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2218 echo "<tr><td class='label'>$label</td>";
2219 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2223 function number_list($name, $selected, $from, $to, $no_option=false)
2226 for ($i = $from; $i <= $to; $i++)
2229 return array_selector($name, $selected, $items,
2230 array( 'spec_option' => $no_option,
2231 'spec_id' => ALL_NUMERIC) );
2234 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2239 echo number_list($name, $selected, $from, $to, $no_option);
2243 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2245 echo "<tr><td class='label'>$label</td>";
2246 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2250 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2251 $submit_on_change=true)
2253 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2254 ." GROUP BY profile";
2255 $result = db_query($sql, 'cannot get all profile names');
2256 $profiles = array();
2257 while($myrow=db_fetch($result)) {
2258 $profiles[$myrow['profile']] = $myrow['profile'];
2263 echo "<td class='label'>$label</td>\n";
2266 echo array_selector($name, $selected_id, $profiles,
2267 array( 'select_submit'=> $submit_on_change,
2268 'spec_option'=>$spec_opt,
2272 echo "</td></tr>\n";
2275 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2277 static $printers; // query only once for page display
2280 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2281 $result = db_query($sql, 'cannot get all printers');
2282 $printers = array();
2283 while($myrow=db_fetch($result)) {
2284 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2287 return array_selector($name, $selected_id, $printers,
2288 array( 'select_submit'=> $submit_on_change,
2289 'spec_option'=>$spec_opt,
2294 //------------------------------------------------------------------------------------------------
2296 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2299 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2301 $sql .= " WHERE type=$type";
2303 return combo_input($name, $selected_id, $sql, 'id', 'description',
2306 'order' => 'description',
2307 'select_submit'=> $submit_on_change,
2313 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2316 echo "<td>$label</td>\n";
2318 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2322 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2324 echo "<tr><td class='label'>$label</td>";
2325 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2330 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2332 global $quick_actions;
2334 echo "<tr><td class='label'>$label</td><td>";
2335 echo array_selector($name, $selected_id, $quick_actions,
2337 'select_submit'=> $submit_on_change
2339 echo "</td></tr>\n";
2342 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2344 global $quick_entry_types;
2346 echo "<tr><td class='label'>$label</td><td>";
2347 echo array_selector($name, $selected_id, $quick_entry_types,
2349 'select_submit'=> $submit_on_change
2351 echo "</td></tr>\n";
2354 function record_status_list_row($label, $name) {
2355 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2358 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2360 global $class_types;
2362 echo "<tr><td class='label'>$label</td><td>";
2363 echo array_selector($name, $selected_id, $class_types,
2365 'select_submit'=> $submit_on_change
2367 echo "</td></tr>\n";
2370 //------------------------------------------------------------------------------------------------
2372 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2373 $show_inactive = false)
2376 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2378 return combo_input($name, $selected_id, $sql, 'id', 'description',
2380 'spec_option'=>$new_item ? _("New role") : false,
2382 'select_submit'=> $submit_on_change,
2383 'show_inactive' => $show_inactive
2387 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2388 $show_inactive = false)
2391 echo "<td>$label</td>\n";
2393 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2397 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2398 $show_inactive = false)
2400 echo "<tr><td class='label'>$label</td>";
2401 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2405 function tab_list_row($label, $name, $selected_id=null)
2407 global $installed_extensions;
2410 foreach ($_SESSION['App']->applications as $app) {
2411 $tabs[$app->id] = access_string($app->name, true);
2414 echo "<td class='label'>$label</td><td>\n";
2415 echo array_selector($name, $selected_id, $tabs);
2416 echo "</td></tr>\n";
2419 //-----------------------------------------------------------------------------------------------
2421 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2424 global $path_to_root;
2425 include_once($path_to_root . "/admin/db/tags_db.inc");
2426 $results = get_tags($type, $all);
2428 while ($tag = db_fetch($results))
2429 $tags[$tag['id']] = $tag['name'];
2431 if (!isset($tags)) {
2432 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2435 return array_selector($name, null, $tags,
2438 'height' => $height,
2439 'spec_option'=> $spec_opt,
2444 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2447 echo "<td>$label</td>\n";
2449 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2454 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2456 echo "<tr><td class='label'>$label</td>";
2457 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2461 //---------------------------------------------------------------------------------------------
2462 // List of sets of active extensions
2464 function extset_list($name, $value=null, $submit_on_change=false)
2466 global $db_connections;
2469 foreach ($db_connections as $comp)
2470 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2471 return array_selector( $name, $value, $items,
2473 'spec_option'=> _("Available and/or installed"),
2475 'select_submit'=> $submit_on_change,
2480 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2483 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2488 if (@$filter['class']) {
2489 $where[] = 'type='.db_escape($filter['class']);
2492 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2493 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2494 if (@$filter['multi']) { // contact category selector for person
2498 return combo_input($name, $selected_id, $sql, 'id', 'name',
2501 'height' => $multi ? 5:1,
2502 'category' => $groups,
2503 'select_submit'=> $submit_on_change,
2509 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2511 echo "<tr><td class='label'>$label</td><td>";
2512 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2513 echo "</td></tr>\n";
2516 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2518 global $pterm_types;
2520 echo "<tr><td class='label'>$label</td><td>";
2521 echo array_selector($name, $selected_id, $pterm_types,
2523 'select_submit'=> $submit_on_change
2525 echo "</td></tr>\n";
2528 function coa_list_row($label, $name, $value=null)
2530 global $path_to_root, $installed_extensions;
2532 $path = $path_to_root.'/sql/';
2534 $sqldir = opendir($path);
2535 while (false !== ($fname = readdir($sqldir)))
2537 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2539 $ext = array_search_value($fname, $installed_extensions, 'sql');
2541 $descr = $ext['name'];
2542 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2543 $descr = _("Standard new company American COA (4 digit)");
2544 } elseif ($fname == 'en_US-demo.sql') {
2545 $descr = _("Standard American COA (4 digit) with demo data");
2549 $coas[$fname] = $descr;
2554 echo "<tr><td class='label'>$label</td>\n<td>";
2555 echo array_selector( $name, $value, $coas );
2556 echo "</td></tr>\n";
2559 function payment_services($name)
2561 global $payment_services;
2563 $services = (object)array_combine(array_keys($payment_services), array_keys($payment_services));
2565 return array_selector($name, null, $services, array(
2566 'spec_option'=> _("No payment Link"),
2571 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2573 global $tax_algorithms;
2575 return array_selector($name, $value, $tax_algorithms,
2577 'select_submit'=> $submit_on_change,
2583 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2586 echo "<td>$label</td>\n";
2588 echo tax_algorithm_list($name, $value, $submit_on_change);
2592 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2594 echo "<tr><td class='label'>$label</td>";
2595 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2599 function refline_list($name, $type, $value=null, $spec_option=false)
2601 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2606 $where = array('`trans_type`='.db_escape($type));
2608 return combo_input($name, $value, $sql, 'id', 'prefix',
2610 'order'=>array('prefix'),
2611 'spec_option' => $spec_option,
2615 'select_submit' => true,
2620 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2624 echo "<td class='label'>$label</td>\n";
2627 echo refline_list($name, $type, $selected_id, $spec_option);
2628 echo "</td></tr>\n";
2632 //----------------------------------------------------------------------------------------------
2634 function subledger_list($name, $account, $selected_id=null)
2637 $type = is_subledger_account($account);
2642 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2644 .TB_PREF."debtors_master d,"
2645 .TB_PREF."cust_branch c
2646 WHERE d.debtor_no=c.debtor_no AND NOT d.inactive AND c.receivables_account=".db_escape($account);
2648 $sql = "SELECT supplier_id as id, supp_ref as name
2650 .TB_PREF."suppliers s
2651 WHERE NOT s.inactive AND s.payable_account=".db_escape($account);
2653 $mode = get_company_pref('no_customer_list');
2655 return combo_input($name, $selected_id, $sql, 'id', 'name',
2663 function subledger_list_cells($label, $name, $account, $selected_id=null)
2666 echo "<td>$label</td>\n";
2668 echo subledger_list($name, $account, $selected_id);
2672 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2673 $submit_on_change=false, $show_inactive=false, $editkey = false)
2675 echo "<tr><td class='label'>$label</td><td nowrap>";
2676 echo subledger_list($name, $account, $selected_id);
2677 echo "</td>\n</tr>\n";
2680 function accounts_type_list_row($label, $name, $selected_id=null)
2684 echo "<td class='label'>$label</td>\n";
2686 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2687 echo array_selector($name, $selected_id, $sel);
2688 echo "</td></tr>\n";
2691 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2694 $sql = " SELECT user_id, IF(real_name = '', user_id, real_name) FROM ".TB_PREF."users";
2697 echo "<td>$label</td>\n";
2700 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2702 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2704 'order' => 'real_name',
2705 'select_submit'=> $submit_on_change,
2712 function collations_list_row($label, $name, $selected_id=null)
2714 global $supported_collations;
2718 echo "<td class='label'>$label</td>\n";
2721 echo array_selector($name, $selected_id, $supported_collations,
2722 array('select_submit'=> false) );
2723 echo "</td></tr>\n";