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");
348 $link = $path_to_root . "/gl/inquiry/accounts_list.php?popup=1&client_id=" . $id;
349 $img_title = _("Search GL accounts");
355 $theme = user_theme();
356 $img = '<img src="'.$path_to_root.'/themes/'.$theme.'/images/'.ICON_VIEW.
357 '" style="vertical-align:middle;width:12px;height:12px;border:0;" onclick="javascript:lookupWindow("'.
358 $link.'", "");" title="' . $img_title . '" style="cursor:pointer;" />';
362 if ($opts['editlink'])
363 $selector .= ' '.$opts['editlink'];
365 if ($search_box && $opts['cells'])
366 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector$img</td>";
368 $str = $edit_entry.$selector.$img;
374 Returns true if selector $name is subject to update.
376 function list_updated($name)
378 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
380 //----------------------------------------------------------------------------------------------
381 // Universal array combo generator
382 // $items is array of options 'value' => 'description'
383 // Options is reduced set of combo_selector options and is merged with defaults.
385 function array_selector($name, $selected_id, $items, $options=null)
389 $opts = array( // default options
390 'spec_option'=>false, // option text or false
391 'spec_id' => 0, // option id
392 'select_submit' => false, //submit on select: true/false
393 'async' => true, // select update via ajax (true) vs _page_body reload
394 'default' => '', // default value when $_POST is not set
395 'multi'=>false, // multiple select
396 // search box parameters
397 'height' => false, // number of lines in select box
401 // ------ merge options with defaults ----------
403 $opts = array_merge($opts, $options);
404 $select_submit = $opts['select_submit'];
405 $spec_id = $opts['spec_id'];
406 $spec_option = $opts['spec_option'];
407 $disabled = $opts['disabled'] ? "disabled" : '';
408 $multi = $opts['multi'];
410 if ($selected_id == null) {
411 $selected_id = get_post($name, $opts['default']);
413 if(!is_array($selected_id))
414 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
416 if (isset($_POST[ '_'.$name.'_update'])) {
418 $Ajax->activate('_page_body');
420 $Ajax->activate($name);
423 // ------ make selector ----------
424 $selector = $first_opt = '';
427 foreach($items as $value=>$descr) {
429 if (in_array((string)$value, $selected_id, true)) {
433 if ($first_id === false) {
437 $selector .= "<option $sel value='$value'>$descr</option>\n";
440 if ($first_id!==false) {
441 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
443 // Prepend special option.
444 if ($spec_option !== false) { // if special option used - add it
445 $first_id = $spec_id;
446 $first_opt = $spec_option;
447 $sel = $found===false ? 'selected' : '';
448 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
452 if ($found===false) {
453 $selected_id = array($first_id);
455 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
457 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
458 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
459 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
460 . $opts['sel_hint']."'>".$selector."</select>\n";
462 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
464 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
466 if ($select_submit != false) { // if submit on change is used - add select button
467 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
468 (fallback_mode() ? '' : 'display:none;'),
469 '_'.$name.'_update')."\n";
471 default_focus($name);
475 //----------------------------------------------------------------------------------------------
476 function array_selector_row($label, $name, $selected_id, $items, $options=null)
478 echo "<tr><td class='label'>$label</td>\n<td>";
479 echo array_selector($name, $selected_id, $items, $options);
483 //----------------------------------------------------------------------------------------------
484 function _format_add_curr($row, $pname=false)
486 static $company_currency;
488 if ($company_currency == null)
490 $company_currency = get_company_currency();
494 return $row[1] . ($row[2] == $company_currency ? '' : (" - " . $row[2]));
498 return $row[1] . " - " . $row[2] . ($row[3] == $company_currency ? '' : (" - " . $row[3]));
502 function add_edit_combo($type)
504 global $path_to_root, $popup_editors, $SysPrefs;
506 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
509 $theme_path = $path_to_root . '/themes/' . user_theme();
511 $key = $popup_editors[$type][1];
512 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
513 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
514 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
517 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
518 $all=false, $editkey = false)
521 if (!empty($SysPrefs->prefs['shortname_name_in_list']))
522 $sql = "SELECT supplier_id, supp_ref, supp_name, curr_code, inactive FROM ".TB_PREF."suppliers ";
524 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
526 $mode = get_company_pref('no_supplier_list');
529 set_editor('supplier', $name, $editkey);
531 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
533 'format' => '_format_add_curr',
534 'order' => array('supp_ref'),
535 'search_box' => $mode!=0,
537 'search' => array("supp_ref","supp_name","gst_no"),
538 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
539 'spec_id' => ALL_TEXT,
540 'select_submit'=> $submit_on_change,
542 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
543 _('Select supplier'),
544 'show_inactive'=>$all,
545 'editlink' => $editkey ? add_edit_combo('supplier') : false
550 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
551 $submit_on_change=false, $all=false, $editkey = false)
554 echo "<td>$label</td>\n";
556 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
561 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
562 $submit_on_change=false, $all=false, $editkey = false)
564 echo "<tr><td class='label'>$label</td><td>";
565 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
569 //----------------------------------------------------------------------------------------------
571 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
572 $show_inactive=false, $editkey = false)
575 if (!empty($SysPrefs->prefs['shortname_name_in_list']))
576 $sql = "SELECT debtor_no, debtor_ref, name, curr_code, inactive FROM ".TB_PREF."debtors_master ";
578 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
580 $mode = get_company_pref('no_customer_list');
583 set_editor('customer', $name, $editkey);
585 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
587 'format' => '_format_add_curr',
588 'order' => array('debtor_ref'),
589 'search_box' => $mode!=0,
592 'search' => array("debtor_ref","name","tax_id"),
593 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
594 'spec_id' => ALL_TEXT,
595 'select_submit'=> $submit_on_change,
597 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
598 _('Select customer'),
599 'show_inactive' => $show_inactive,
600 'editlink' => $editkey ? add_edit_combo('customer') : false
605 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
606 $submit_on_change=false, $show_inactive=false, $editkey = false)
609 echo "<td>$label</td>\n";
611 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
612 $show_inactive, $editkey);
616 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
617 $submit_on_change=false, $show_inactive=false, $editkey = false)
620 echo "<tr><td class='label'>$label</td><td nowrap>";
621 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
622 $show_inactive, $editkey);
623 echo "</td>\n</tr>\n";
626 //------------------------------------------------------------------------------------------------
628 function customer_branches_list($customer_id, $name, $selected_id=null,
629 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
632 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
633 WHERE debtor_no=" . db_escape($customer_id)." ";
636 set_editor('branch', $name, $editkey);
638 $where = $enabled ? array("inactive = 0") : array();
639 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
642 'order' => array('branch_ref'),
643 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
644 'spec_id' => ALL_TEXT,
645 'select_submit'=> $submit_on_change,
646 'sel_hint' => _('Select customer branch'),
647 'editlink' => $editkey ? add_edit_combo('branch') : false
651 //------------------------------------------------------------------------------------------------
653 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
654 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
657 echo "<td>$label</td>\n";
659 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
660 $submit_on_change, $editkey);
664 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
665 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
667 echo "<tr><td class='label'>$label</td>";
668 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
669 $all_option, $enabled, $submit_on_change, $editkey);
673 //------------------------------------------------------------------------------------------------
675 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
678 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations WHERE fixed_asset=".(int)$fixed_asset;
680 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
682 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
683 'spec_id' => ALL_TEXT,
684 'select_submit'=> $submit_on_change
688 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
691 echo "<td>$label</td>\n";
693 echo locations_list($name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
697 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
699 echo "<tr><td class='label'>$label</td>";
700 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
704 //-----------------------------------------------------------------------------------------------
706 function currencies_list($name, $selected_id=null, $submit_on_change=false, $exclude_home_curr=false)
708 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
709 if ($exclude_home_curr)
710 $sql .= " WHERE curr_abrev!='".get_company_currency()."'";
712 // default to the company currency
713 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
715 'select_submit'=> $submit_on_change,
716 'default' => get_company_currency(),
721 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
724 echo "<td>$label</td>\n";
726 echo currencies_list($name, $selected_id, $submit_on_change);
730 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
732 echo "<tr><td class='label'>$label</td>";
733 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
737 //---------------------------------------------------------------------------------------------------
739 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
742 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
744 // default to the company current fiscal year
746 return combo_input($name, $selected_id, $sql, 'id', '',
749 'default' => get_company_pref('f_year'),
750 'format' => '_format_fiscalyears',
751 'select_submit'=> $submit_on_change,
756 function _format_fiscalyears($row)
758 return sql2date($row[1]) . " - " . sql2date($row[2])
759 . " " . ($row[3] ? _('Closed') : _('Active'));
762 function fiscalyears_list_cells($label, $name, $selected_id=null)
765 echo "<td>$label</td>\n";
767 echo fiscalyears_list($name, $selected_id);
771 function fiscalyears_list_row($label, $name, $selected_id=null)
773 echo "<tr><td class='label'>$label</td>";
774 fiscalyears_list_cells(null, $name, $selected_id);
777 //------------------------------------------------------------------------------------
779 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
780 $submit_on_change=false, $showclosed=false, $showtype=1)
782 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
785 'order' => 'reference',
786 'spec_option'=>$no_option ? $showname : false,
788 'select_submit'=> $submit_on_change,
793 $options['where'][] = "closed=0";
795 $options['where'][] = "type_=".db_escape($showtype);
797 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
800 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
801 $showclosed=false, $showtype=0, $submit_on_change=false)
804 echo "<td>$label</td>\n";
806 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
810 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
811 $showclosed=false, $showtype=0, $submit_on_change=false)
813 echo "<tr><td class='label'>$label</td>";
814 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
815 $showclosed, $showtype, $submit_on_change);
819 //---------------------------------------------------------------------------------------------------
821 function stock_items_list($name, $selected_id=null, $all_option=false,
822 $submit_on_change=false, $opts=array(), $editkey = false, $type = "stock")
824 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
825 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
827 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
828 $sql .= " AND mb_flag='F'";
830 $sql .= " AND mb_flag!='F'";
833 set_editor('item', $name, $editkey);
835 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
838 'format' => '_format_stock_items',
839 'spec_option' => $all_option===true ? _("All Items") : $all_option,
840 'spec_id' => ALL_TEXT,
841 'search_box' => true,
842 'search' => array("stock_id", "c.description","s.description"),
843 'search_submit' => get_company_pref('no_item_list')!=0 && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']),
845 'select_submit'=> $submit_on_change,
847 'order' => array('c.description','stock_id'),
848 'editlink' => $editkey ? add_edit_combo('item') : false,
855 function _format_stock_items($row)
857 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
860 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
861 $submit_on_change=false, $all=false, $editkey = false, $opts= array())
863 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
864 $editor_item = 'fa_item';
866 $editor_item = 'item';
869 // set_editor($editor_item, $name, $editkey);
872 echo "<td>$label</td>\n";
875 // $opts = array_merge($options, array('cells'=>true, 'show_inactive'=>$all, 'new_icon' => $editkey ? 'item' : false));
877 // echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, $opts);
879 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
880 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey);
884 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
887 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
891 //---------------------------------------------------------------------------------------------------
893 // Select item via foreign code.
895 function sales_items_list($name, $selected_id=null, $all_option=false,
896 $submit_on_change=false, $type='', $opts=array())
899 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
900 i.inactive, if(count(*)>1, '0', s.editable) as editable
902 ".TB_PREF."stock_master s,
903 ".TB_PREF."item_codes i
905 ".TB_PREF."stock_category c
906 ON i.category_id=c.category_id
907 WHERE i.stock_id=s.stock_id
911 if ($type == 'local') { // exclude foreign codes
912 $sql .= " AND !i.is_foreign";
913 } elseif ($type == 'kits') { // sales kits
914 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
916 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
917 $sql .= " GROUP BY i.item_code";
919 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
922 'format' => '_format_stock_items',
923 'spec_option' => $all_option===true ? _("All Items") : $all_option,
924 'spec_id' => ALL_TEXT,
925 'search_box' => true,
926 'search' => array("i.item_code", "c.description", "i.description"),
927 'search_submit' => get_company_pref('no_item_list')!=0,
929 'select_submit'=> $submit_on_change,
931 'order' => array('c.description','i.item_code'),
934 ), $opts), $type == 'kits' ? $type : "stock_sales" );
937 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
940 set_editor('item', $name, $editkey);
943 echo "<td>$label</td>\n";
944 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
945 '', array('cells'=>true));
948 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
950 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
951 'kits', array('cells'=>false, 'editable' => false));
954 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
958 echo "<td class='label'>$label</td>\n";
960 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
961 'local', array('cells'=>false, 'editable' => false));
964 //------------------------------------------------------------------------------------
966 function stock_manufactured_items_list($name, $selected_id=null,
967 $all_option=false, $submit_on_change=false)
969 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
970 array('where'=>array("mb_flag= 'M'")), false, "stock_manufactured");
973 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
974 $all_option=false, $submit_on_change=false)
977 echo "<td>$label</td>\n";
979 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
983 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
984 $all_option=false, $submit_on_change=false)
986 echo "<tr><td class='label'>$label</td>";
987 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
990 //------------------------------------------------------------------------------------
992 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
993 $all_option=false, $submit_on_change=false, $editkey = false)
995 $parent = db_escape($parent_stock_id);
996 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
997 array('where'=>array("stock_id != $parent"), 'parent'=> $parent_stock_id), $editkey, "component");
1001 function stock_component_items_list_cells($label, $name, $parent_stock_id,
1002 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
1005 echo "<td>$label</td>\n";
1006 $parent = db_escape($parent_stock_id);
1007 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1008 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true, 'parent'=> $parent_stock_id), $editkey, "component");
1010 //------------------------------------------------------------------------------------
1012 function stock_costable_items_list($name, $selected_id=null,
1013 $all_option=false, $submit_on_change=false)
1015 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1016 array('where'=>array("mb_flag!='D'")), false, "stock_costable");
1019 function stock_costable_items_list_cells($label, $name, $selected_id=null,
1020 $all_option=false, $submit_on_change=false)
1023 echo "<td>$label</td>\n";
1024 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1025 array('where'=>array("mb_flag!='D'"), 'cells'=>true), false, "stock_costable");
1028 //------------------------------------------------------------------------------------
1029 function stock_purchasable_items_list($name, $selected_id=null,
1030 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
1032 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1033 array('where'=>array("NOT no_purchase"),
1034 'show_inactive'=>$all), $editkey, "stock_purchased");
1037 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
1039 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
1040 $all_option=false, $submit_on_change=false, $editkey=false)
1043 echo "<td>$label</td>\n";
1044 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1045 array('where'=>array("NOT no_purchase"),
1047 'cells'=>true), $editkey);
1050 //------------------------------------------------------------------------------------
1052 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
1054 global $stock_types;
1058 echo "<td class='label'>$label</td>\n";
1061 echo array_selector($name, $selected_id, $stock_types,
1063 'select_submit'=> true,
1064 'disabled' => !$enabled) );
1065 echo "</td></tr>\n";
1068 function stock_units_list_row($label, $name, $value=null, $enabled=true)
1070 $result = get_all_item_units();
1073 echo "<td class='label'>$label</td>\n";
1076 while($unit = db_fetch($result))
1077 $units[$unit['abbr']] = $unit['name'];
1079 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
1081 echo "</td></tr>\n";
1084 //------------------------------------------------------------------------------------
1086 function stock_purchasable_fa_list_cells($label, $name, $selected_id=null, $all_option=false,
1087 $submit_on_change=false, $all=false, $editkey = false, $exclude_items = array())
1089 // Check if a fixed asset has been bought.
1090 $where_opts[] = "stock_id NOT IN
1091 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1093 // exclude items currently on the order.
1094 foreach($exclude_items as $item) {
1095 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1097 $where_opts[] = "mb_flag='F'";
1099 echo stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, $all, $editkey,
1100 array('fixed_asset' => true, 'where' => $where_opts));
1103 function stock_disposable_fa_list($name, $selected_id=null,
1104 $all_option=false, $submit_on_change=false)
1106 // Check if a fixed asset has been bought....
1107 $where_opts[] = "stock_id IN
1108 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1109 // ...but has not been disposed or sold already.
1110 $where_opts[] = "stock_id NOT IN
1111 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1113 $where_opts[] = "mb_flag='F'";
1115 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1116 array('fixed_asset' => true, 'where' => $where_opts));
1119 function stock_disposable_fa_list_cells($label, $name, $selected_id=null,
1120 $all_option=false, $submit_on_change=false, $exclude_items = array())
1122 // Check if a fixed asset has been bought....
1123 $where_opts[] = "stock_id IN
1124 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1125 // ...but has not been disposed or sold already.
1126 $where_opts[] = "stock_id NOT IN
1127 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1129 $where_opts[] = "mb_flag='F'";
1131 foreach($exclude_items as $item) {
1132 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1136 echo "<td>$label</td>\n";
1137 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1138 array('fixed_asset' => true, 'cells'=>true, 'where' => $where_opts));
1141 function stock_depreciable_fa_list_cells($label, $name, $selected_id=null,
1142 $all_option=false, $submit_on_change=false)
1145 // Check if a fixed asset has been bought....
1146 $where_opts[] = "stock_id IN
1147 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1148 // ...but has not been disposed or sold already.
1149 $where_opts[] = "stock_id NOT IN
1150 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1152 $year = get_current_fiscalyear();
1153 $y = date('Y', strtotime($year['end']));
1155 // check if current fiscal year
1156 $where_opts[] = "depreciation_date < '".$y."-12-01'";
1157 $where_opts[] = "depreciation_date >= '".($y-1)."-12-01'";
1159 $where_opts[] = "material_cost > 0";
1160 $where_opts[] = "mb_flag='F'";
1163 echo "<td>$label</td>\n";
1164 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1165 array('fixed_asset' => true, 'where' => $where_opts, 'cells'=>true));
1168 //------------------------------------------------------------------------------------
1170 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
1172 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
1174 return combo_input($name, $selected_id, $sql, 'id', 'name',
1176 'spec_option' => $none_option,
1177 'spec_id' => ALL_NUMERIC,
1178 'select_submit'=> $submit_on_change,
1183 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1184 $submit_on_change=false)
1187 echo "<td>$label</td>\n";
1189 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1193 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1194 $submit_on_change=false)
1196 echo "<tr><td class='label'>$label</td>";
1197 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1201 //------------------------------------------------------------------------------------
1203 function tax_groups_list($name, $selected_id=null,
1204 $none_option=false, $submit_on_change=false)
1206 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1208 return combo_input($name, $selected_id, $sql, 'id', 'name',
1211 'spec_option' => $none_option,
1212 'spec_id' => ALL_NUMERIC,
1213 'select_submit'=> $submit_on_change,
1218 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1221 echo "<td>$label</td>\n";
1223 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1227 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1229 echo "<tr><td class='label'>$label</td>";
1230 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1234 //------------------------------------------------------------------------------------
1236 function item_tax_types_list($name, $selected_id=null, $show_inactive = false)
1238 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1239 if (!$show_inactive)
1240 $sql .= " WHERE !inactive";
1242 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1245 function item_tax_types_list_cells($label, $name, $selected_id=null, $show_inactive = false)
1248 echo "<td>$label</td>\n";
1250 echo item_tax_types_list($name, $selected_id, $show_inactive);
1254 function item_tax_types_list_row($label, $name, $selected_id=null, $show_inactive = false)
1256 echo "<tr><td class='label'>$label</td>";
1257 item_tax_types_list_cells(null, $name, $selected_id, $show_inactive);
1261 //------------------------------------------------------------------------------------
1263 function shippers_list($name, $selected_id=null)
1265 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1266 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1267 array('order'=>array('shipper_name')));
1270 function shippers_list_cells($label, $name, $selected_id=null)
1273 echo "<td>$label</td>\n";
1275 echo shippers_list($name, $selected_id);
1279 function shippers_list_row($label, $name, $selected_id=null)
1281 echo "<tr><td class='label'>$label</td>";
1282 shippers_list_cells(null, $name, $selected_id);
1286 //-------------------------------------------------------------------------------------
1288 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1290 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1291 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1292 array('order'=>array('salesman_name'),
1293 'spec_option' => $spec_opt,
1294 'spec_id' => ALL_NUMERIC));
1297 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1300 echo "<td>$label</td>\n";
1302 echo sales_persons_list($name, $selected_id, $spec_opt);
1306 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1308 echo "<tr><td class='label'>$label</td>";
1309 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1313 //------------------------------------------------------------------------------------
1315 function sales_areas_list($name, $selected_id=null, $special_option=false)
1317 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1318 return combo_input($name, $selected_id, $sql, 'area_code', 'description',
1319 array('spec_option' => $special_option===true ? ' ' : $special_option,
1320 'order' => 'description', 'spec_id' => 0));
1323 function sales_areas_list_cells($label, $name, $selected_id=null, $special_option=false)
1326 echo "<td>$label</td>\n";
1328 echo sales_areas_list($name, $selected_id, $special_option);
1332 function sales_areas_list_row($label, $name, $selected_id=null, $special_option=false)
1334 echo "<tr><td class='label'>$label</td>";
1335 sales_areas_list_cells(null, $name, $selected_id, $special_option);
1339 //------------------------------------------------------------------------------------
1341 function sales_groups_list($name, $selected_id=null, $special_option=false)
1343 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1344 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1345 'spec_option' => $special_option===true ? ' ' : $special_option,
1346 'order' => 'description', 'spec_id' => 0,
1350 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1353 echo "<td>$label</td>\n";
1355 echo sales_groups_list($name, $selected_id, $special_option);
1359 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1361 echo "<tr><td class='label'>$label</td>";
1362 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1366 //------------------------------------------------------------------------------------
1368 function _format_template_items($row)
1370 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1373 function templates_list($name, $selected_id=null, $special_option=false)
1375 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1376 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1377 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1378 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1379 'format' => '_format_template_items',
1380 'spec_option' => $special_option===true ? ' ' : $special_option,
1381 'order' => 'order_no', 'spec_id' => 0,
1385 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1388 echo "<td>$label</td>\n";
1390 echo templates_list($name, $selected_id, $special_option);
1394 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1396 echo "<tr><td class='label'>$label</td>";
1397 templates_list_cells(null, $name, $selected_id, $special_option);
1401 //------------------------------------------------------------------------------------
1403 function workorders_list($name, $selected_id=null)
1405 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1406 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1409 function workorders_list_cells($label, $name, $selected_id=null)
1412 echo "<td>$label</td>\n";
1414 echo workorders_list($name, $selected_id);
1418 function workorders_list_row($label, $name, $selected_id=null)
1420 echo "<tr><td class='label'>$label</td>";
1421 workorders_list_cells(null, $name, $selected_id);
1425 //------------------------------------------------------------------------------------
1427 function payment_terms_list($name, $selected_id=null)
1429 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1430 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1433 function payment_terms_list_cells($label, $name, $selected_id=null)
1436 echo "<td>$label</td>\n";
1438 echo payment_terms_list($name, $selected_id);
1442 function payment_terms_list_row($label, $name, $selected_id=null)
1444 echo "<tr><td class='label'>$label</td>";
1445 payment_terms_list_cells(null, $name, $selected_id);
1449 //------------------------------------------------------------------------------------
1451 function credit_status_list($name, $selected_id=null)
1453 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1454 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1457 function credit_status_list_cells($label, $name, $selected_id=null)
1460 echo "<td>$label</td>\n";
1462 echo credit_status_list($name, $selected_id);
1466 function credit_status_list_row($label, $name, $selected_id=null)
1468 echo "<tr><td class='label'>$label</td>";
1469 credit_status_list_cells(null, $name, $selected_id);
1473 //-----------------------------------------------------------------------------------------------
1475 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1477 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1479 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1481 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1483 'select_submit'=> $submit_on_change,
1487 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1490 echo "<td>$label</td>\n";
1492 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1496 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1498 echo "<tr><td class='label'>$label</td>";
1499 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1503 //-----------------------------------------------------------------------------------------------
1505 function _format_date($row)
1507 return sql2date($row['reconciled']);
1510 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1512 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1513 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1514 GROUP BY reconciled";
1515 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1517 'spec_option' => $special_option,
1518 'format' => '_format_date',
1520 'select_submit'=> $submit_on_change
1524 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1527 echo "<td>$label</td>\n";
1529 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1533 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1536 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1540 //-----------------------------------------------------------------------------------------------
1542 function workcenter_list($name, $selected_id=null, $all_option=false)
1545 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1547 return combo_input($name, $selected_id, $sql, 'id', 'name',
1549 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1550 'spec_id' => ALL_TEXT,
1554 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1556 default_focus($name);
1558 echo "<td>$label</td>\n";
1560 echo workcenter_list($name, $selected_id, $all_option);
1564 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1566 echo "<tr><td class='label'>$label</td>";
1567 workcenter_list_cells(null, $name, $selected_id, $all_option);
1571 //-----------------------------------------------------------------------------------------------
1573 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1575 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1576 FROM ".TB_PREF."bank_accounts";
1578 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1580 'format' => '_format_add_curr',
1581 'select_submit'=> $submit_on_change,
1582 'spec_option' => $spec_option,
1588 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1591 echo "<td>$label</td>\n";
1593 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1597 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1599 echo "<tr><td class='label'>$label</td>";
1600 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1603 //-----------------------------------------------------------------------------------------------
1605 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1608 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1609 FROM ".TB_PREF."bank_accounts
1610 WHERE account_type=".BT_CASH;
1613 echo "<tr><td class='label'>$label</td>\n";
1615 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1617 'spec_option' => $all_option,
1618 'spec_id' => ALL_TEXT,
1619 'format' => '_format_add_curr',
1620 'select_submit'=> $submit_on_change,
1623 echo "</td></tr>\n";
1625 //-----------------------------------------------------------------------------------------------
1627 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1629 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1631 default_focus($name);
1634 echo "<td class='label'>$label</td>\n";
1637 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1639 'select_submit'=> $submit_on_change,
1641 'spec_option' =>$spec_option,
1643 'order'=> array('pos_name')
1645 echo "</td></tr>\n";
1648 //-----------------------------------------------------------------------------------------------
1649 // Payment type selector for current user.
1651 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1653 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1655 if ($category == PM_CASH) // only cash
1656 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1657 elseif ($category == PM_CREDIT) // only delayed payments
1658 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1659 elseif (!$prepayments)
1660 $sql .= " WHERE days_before_due>=0";
1662 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1664 'select_submit'=> $submit_on_change,
1670 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1673 echo "<td class='label'>$label</td>\n";
1676 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1680 //-----------------------------------------------------------------------------------------------
1682 function class_list($name, $selected_id=null, $submit_on_change=false)
1684 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1686 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1688 'select_submit'=> $submit_on_change,
1694 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1697 echo "<td>$label</td>\n";
1699 echo class_list($name, $selected_id, $submit_on_change);
1703 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1705 echo "<tr><td class='label'>$label</td>";
1706 class_list_cells(null, $name, $selected_id, $submit_on_change);
1710 //-----------------------------------------------------------------------------------------------
1711 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1713 $where_opts = array();
1715 $where_opts[0] = "dflt_mb_flag='F'";
1717 $where_opts[0] = "dflt_mb_flag!='F'";
1719 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1720 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1721 array('order'=>'category_id',
1722 'spec_option' => $spec_opt,
1724 'select_submit'=> $submit_on_change,
1726 'where' => $where_opts,
1730 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1733 echo "<td>$label</td>\n";
1735 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1739 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1741 echo "<tr><td class='label'>$label</td>";
1742 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1746 //-----------------------------------------------------------------------------------------------
1747 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1749 $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 "
1750 .TB_PREF."stock_fa_class c LEFT JOIN ".TB_PREF."stock_fa_class p ON c.parent_id=p.fa_class_id";
1752 return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
1753 array('order'=>'c.fa_class_id',
1754 'spec_option' => $spec_opt,
1756 'select_submit'=> $submit_on_change,
1758 'search_box' => true,
1759 'search' => array("c.fa_class_id"),
1760 'search_submit' => false,
1764 'category' => 'class',
1768 function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1770 echo "<tr><td class='label'>$label</td>";
1772 echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change);
1773 echo "</td></tr>\n";
1776 //-----------------------------------------------------------------------------------------------
1778 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1781 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1783 return combo_input($name, $selected_id, $sql, 'id', 'name',
1785 'format' => '_format_account',
1786 'order' => array('class_id', 'id', 'parent'),
1787 'spec_option' =>$all_option,
1788 'spec_id' => ALL_TEXT
1792 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1795 echo "<td>$label</td>\n";
1797 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1801 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1803 echo "<tr><td class='label'>$label</td>";
1804 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1809 //-----------------------------------------------------------------------------------------------
1810 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1811 $cells=false, $all_option=false, $submit_on_change=false, $all=false, $type_id=false)
1813 if ($skip_bank_accounts)
1814 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1815 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1816 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1817 ."ON chart.account_code=acc.account_code
1818 WHERE acc.account_code IS NULL
1819 AND chart.account_type=type.id";
1821 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1822 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1823 WHERE chart.account_type=type.id";
1824 if ($type_id ) $sql .= " AND chart.account_type=".db_escape($type_id);
1826 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1828 'format' => '_format_account',
1829 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1832 'order' => array('type.class_id','type.id','account_code'),
1833 'search_box' => $cells,
1834 'search_submit' => false,
1838 'select_submit'=> $submit_on_change,
1841 'show_inactive' => $all
1845 function _format_account($row)
1847 return $row[0] . " " . $row[1];
1850 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1851 $skip_bank_accounts=false, $cells=false, $all_option=false,
1852 $submit_on_change=false, $all=false, $type_id=false)
1855 echo "<td>$label</td>\n";
1857 echo gl_all_accounts_list($name, $selected_id,
1858 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all, $type_id);
1862 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1863 $skip_bank_accounts=false, $cells=false, $all_option=false, $type_id=false)
1865 echo "<tr><td class='label'>$label</td>";
1866 gl_all_accounts_list_cells(null, $name, $selected_id,
1867 $skip_bank_accounts, $cells, $all_option, $type_id);
1871 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1874 $items['0'] = strlen($name_no) ? $name_no : _("No");
1875 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1877 return array_selector($name, $selected_id, $items,
1879 'select_submit'=> $submit_on_change,
1880 'async' => false ) ); // FIX?
1883 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1886 echo "<td>$label</td>\n";
1888 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1892 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1894 echo "<tr><td class='label'>$label</td>";
1895 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1899 //------------------------------------------------------------------------------------------------
1901 function languages_list($name, $selected_id=null, $all_option=false)
1903 global $installed_languages;
1907 $items[''] = $all_option;
1908 foreach ($installed_languages as $lang)
1909 $items[$lang['code']] = $lang['name'];
1910 return array_selector($name, $selected_id, $items);
1913 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1916 echo "<td>$label</td>\n";
1918 echo languages_list($name, $selected_id, $all_option);
1922 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1924 echo "<tr><td class='label'>$label</td>";
1925 languages_list_cells(null, $name, $selected_id, $all_option);
1929 //------------------------------------------------------------------------------------------------
1931 function bank_account_types_list($name, $selected_id=null)
1933 global $bank_account_types;
1935 return array_selector($name, $selected_id, $bank_account_types);
1938 function bank_account_types_list_cells($label, $name, $selected_id=null)
1941 echo "<td>$label</td>\n";
1943 echo bank_account_types_list($name, $selected_id);
1947 function bank_account_types_list_row($label, $name, $selected_id=null)
1949 echo "<tr><td class='label'>$label</td>";
1950 bank_account_types_list_cells(null, $name, $selected_id);
1954 //------------------------------------------------------------------------------------------------
1955 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1957 global $payment_person_types;
1960 foreach ($payment_person_types as $key=>$type)
1962 if ($key != PT_WORKORDER)
1963 $items[$key] = $type;
1965 return array_selector($name, $selected_id, $items,
1966 array( 'select_submit'=> $submit_on_change ) );
1969 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1972 echo "<td>$label</td>\n";
1974 echo payment_person_types_list($name, $selected_id, $related);
1978 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1980 echo "<tr><td class='label'>$label</td>";
1981 payment_person_types_list_cells(null, $name, $selected_id, $related);
1985 //------------------------------------------------------------------------------------------------
1987 function wo_types_list($name, $selected_id=null)
1989 global $wo_types_array;
1991 return array_selector($name, $selected_id, $wo_types_array,
1992 array( 'select_submit'=> true, 'async' => true ) );
1995 function wo_types_list_row($label, $name, $selected_id=null)
1997 echo "<tr><td class='label'>$label</td><td>\n";
1998 echo wo_types_list($name, $selected_id);
1999 echo "</td></tr>\n";
2002 //------------------------------------------------------------------------------------------------
2004 function dateformats_list_row($label, $name, $value=null)
2008 echo "<tr><td class='label'>$label</td>\n<td>";
2009 echo array_selector( $name, $value, $SysPrefs->dateformats );
2010 echo "</td></tr>\n";
2013 function dateseps_list_row($label, $name, $value=null)
2017 echo "<tr><td class='label'>$label</td>\n<td>";
2018 echo array_selector( $name, $value, $SysPrefs->dateseps );
2019 echo "</td></tr>\n";
2022 function thoseps_list_row($label, $name, $value=null)
2026 echo "<tr><td class='label'>$label</td>\n<td>";
2027 echo array_selector( $name, $value, $SysPrefs->thoseps );
2028 echo "</td></tr>\n";
2031 function decseps_list_row($label, $name, $value=null)
2035 echo "<tr><td class='label'>$label</td>\n<td>";
2036 echo array_selector( $name, $value, $SysPrefs->decseps );
2037 echo "</td></tr>\n";
2040 function themes_list_row($label, $name, $value=null)
2042 global $path_to_root;
2044 $path = $path_to_root.'/themes/';
2046 $themedir = opendir($path);
2047 while(false !== ($fname = readdir($themedir)))
2049 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
2051 $themes[$fname] = $fname;
2056 echo "<tr><td class='label'>$label</td>\n<td>";
2057 echo array_selector( $name, $value, $themes );
2058 echo "</td></tr>\n";
2061 function pagesizes_list_row($label, $name, $value=null)
2066 foreach ($SysPrefs->pagesizes as $pz)
2069 echo "<tr><td class='label'>$label</td>\n<td>";
2070 echo array_selector( $name, $value, $items );
2071 echo "</td></tr>\n";
2074 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
2076 global $systypes_array;
2078 // emove non-voidable transactions if needed
2079 $systypes = array_diff_key($systypes_array, array_flip($exclude));
2080 return array_selector($name, $value, $systypes,
2082 'spec_option'=> $spec_opt,
2083 'spec_id' => ALL_NUMERIC,
2084 'select_submit'=> $submit_on_change,
2090 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2093 echo "<td>$label</td>\n";
2095 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
2099 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2101 echo "<tr><td class='label'>$label</td>";
2102 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
2106 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
2108 global $systypes_array;
2111 echo "<td>$label</td>\n";
2114 $items = $systypes_array;
2116 // exclude quotes, orders and dimensions
2117 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
2118 unset($items[$excl]);
2120 echo array_selector($name, $value, $items,
2122 'spec_option'=> _("All"),
2124 'select_submit'=> $submit_on_change,
2131 function cust_allocations_list_cells($label, $name, $selected=null, $submit_on_change=false)
2138 ALL_TEXT=>_("All Types"),
2139 '1'=> _("Sales Invoices"),
2140 '2'=> _("Unsettled transactions"),
2141 '3' => _("Payments"),
2142 '4' => _("Credit Notes"),
2143 '5' => _("Delivery Notes")
2145 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2149 function supp_allocations_list_cell($name, $selected=null)
2154 ALL_TEXT=>_("All Types"),
2155 '1'=> _("Invoices"),
2156 '2'=> _("Overdue Invoices"),
2157 '3' => _("Payments"),
2158 '4' => _("Credit Notes"),
2159 '5' => _("Overdue Credit Notes")
2161 echo array_selector($name, $selected, $allocs);
2165 function supp_transactions_list_cell($name, $selected=null, $submit_on_change=false)
2170 ALL_TEXT=>_("All Types"),
2172 '1'=> _("Invoices"),
2173 '2'=> _("Unsettled transactions"),
2174 '3' => _("Payments"),
2175 '4' => _("Credit Notes"),
2176 '5' => _("Overdue Credit Notes")
2179 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2183 function policy_list_cells($label, $name, $selected=null)
2188 echo array_selector($name, $selected,
2189 array( '' => _("Automatically put balance on back order"),
2190 'CAN' => _("Cancel any quantites not delivered")) );
2194 function policy_list_row($label, $name, $selected=null)
2196 echo "<tr><td class='label'>$label</td>";
2197 policy_list_cells(null, $name, $selected);
2201 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2206 echo array_selector($name, $selected,
2207 array( 'Return' => _("Items Returned to Inventory Location"),
2208 'WriteOff' => _("Items Written Off")),
2209 array( 'select_submit'=> $submit_on_change ) );
2213 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2215 echo "<tr><td class='label'>$label</td>";
2216 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2220 function number_list($name, $selected, $from, $to, $no_option=false)
2223 for ($i = $from; $i <= $to; $i++)
2226 return array_selector($name, $selected, $items,
2227 array( 'spec_option' => $no_option,
2228 'spec_id' => ALL_NUMERIC) );
2231 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2236 echo number_list($name, $selected, $from, $to, $no_option);
2240 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2242 echo "<tr><td class='label'>$label</td>";
2243 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2247 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2248 $submit_on_change=true)
2250 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2251 ." GROUP BY profile";
2252 $result = db_query($sql, 'cannot get all profile names');
2253 $profiles = array();
2254 while($myrow=db_fetch($result)) {
2255 $profiles[$myrow['profile']] = $myrow['profile'];
2260 echo "<td class='label'>$label</td>\n";
2263 echo array_selector($name, $selected_id, $profiles,
2264 array( 'select_submit'=> $submit_on_change,
2265 'spec_option'=>$spec_opt,
2269 echo "</td></tr>\n";
2272 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2274 static $printers; // query only once for page display
2277 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2278 $result = db_query($sql, 'cannot get all printers');
2279 $printers = array();
2280 while($myrow=db_fetch($result)) {
2281 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2284 return array_selector($name, $selected_id, $printers,
2285 array( 'select_submit'=> $submit_on_change,
2286 'spec_option'=>$spec_opt,
2291 //------------------------------------------------------------------------------------------------
2293 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2296 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2298 $sql .= " WHERE type=$type";
2300 return combo_input($name, $selected_id, $sql, 'id', 'description',
2303 'order' => 'description',
2304 'select_submit'=> $submit_on_change,
2310 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2313 echo "<td>$label</td>\n";
2315 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2319 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2321 echo "<tr><td class='label'>$label</td>";
2322 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2327 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2329 global $quick_actions;
2331 echo "<tr><td class='label'>$label</td><td>";
2332 echo array_selector($name, $selected_id, $quick_actions,
2334 'select_submit'=> $submit_on_change
2336 echo "</td></tr>\n";
2339 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2341 global $quick_entry_types;
2343 echo "<tr><td class='label'>$label</td><td>";
2344 echo array_selector($name, $selected_id, $quick_entry_types,
2346 'select_submit'=> $submit_on_change
2348 echo "</td></tr>\n";
2351 function record_status_list_row($label, $name) {
2352 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2355 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2357 global $class_types;
2359 echo "<tr><td class='label'>$label</td><td>";
2360 echo array_selector($name, $selected_id, $class_types,
2362 'select_submit'=> $submit_on_change
2364 echo "</td></tr>\n";
2367 //------------------------------------------------------------------------------------------------
2369 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2370 $show_inactive = false)
2373 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2375 return combo_input($name, $selected_id, $sql, 'id', 'description',
2377 'spec_option'=>$new_item ? _("New role") : false,
2379 'select_submit'=> $submit_on_change,
2380 'show_inactive' => $show_inactive
2384 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2385 $show_inactive = false)
2388 echo "<td>$label</td>\n";
2390 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2394 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2395 $show_inactive = false)
2397 echo "<tr><td class='label'>$label</td>";
2398 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2402 function tab_list_row($label, $name, $selected_id=null)
2404 global $installed_extensions;
2407 foreach ($_SESSION['App']->applications as $app) {
2408 $tabs[$app->id] = access_string($app->name, true);
2411 echo "<td class='label'>$label</td><td>\n";
2412 echo array_selector($name, $selected_id, $tabs);
2413 echo "</td></tr>\n";
2416 //-----------------------------------------------------------------------------------------------
2418 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2421 global $path_to_root;
2422 include_once($path_to_root . "/admin/db/tags_db.inc");
2423 $results = get_tags($type, $all);
2425 while ($tag = db_fetch($results))
2426 $tags[$tag['id']] = $tag['name'];
2428 if (!isset($tags)) {
2429 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2432 return array_selector($name, null, $tags,
2435 'height' => $height,
2436 'spec_option'=> $spec_opt,
2441 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2444 echo "<td>$label</td>\n";
2446 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2451 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2453 echo "<tr><td class='label'>$label</td>";
2454 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2458 //---------------------------------------------------------------------------------------------
2459 // List of sets of active extensions
2461 function extset_list($name, $value=null, $submit_on_change=false)
2463 global $db_connections;
2466 foreach ($db_connections as $comp)
2467 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2468 return array_selector( $name, $value, $items,
2470 'spec_option'=> _("Available and/or installed"),
2472 'select_submit'=> $submit_on_change,
2477 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2480 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2485 if (@$filter['class']) {
2486 $where[] = 'type='.db_escape($filter['class']);
2489 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2490 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2491 if (@$filter['multi']) { // contact category selector for person
2495 return combo_input($name, $selected_id, $sql, 'id', 'name',
2498 'height' => $multi ? 5:1,
2499 'category' => $groups,
2500 'select_submit'=> $submit_on_change,
2506 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2508 echo "<tr><td class='label'>$label</td><td>";
2509 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2510 echo "</td></tr>\n";
2513 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2515 global $pterm_types;
2517 echo "<tr><td class='label'>$label</td><td>";
2518 echo array_selector($name, $selected_id, $pterm_types,
2520 'select_submit'=> $submit_on_change
2522 echo "</td></tr>\n";
2525 function coa_list_row($label, $name, $value=null)
2527 global $path_to_root, $installed_extensions;
2529 $path = $path_to_root.'/sql/';
2531 $sqldir = opendir($path);
2532 while (false !== ($fname = readdir($sqldir)))
2534 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2536 $ext = array_search_value($fname, $installed_extensions, 'sql');
2538 $descr = $ext['name'];
2539 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2540 $descr = _("Standard new company American COA (4 digit)");
2541 } elseif ($fname == 'en_US-demo.sql') {
2542 $descr = _("Standard American COA (4 digit) with demo data");
2546 $coas[$fname] = $descr;
2551 echo "<tr><td class='label'>$label</td>\n<td>";
2552 echo array_selector( $name, $value, $coas );
2553 echo "</td></tr>\n";
2556 function payment_services($name)
2558 global $payment_services;
2560 $services = (object)array_combine(array_keys($payment_services), array_keys($payment_services));
2562 return array_selector($name, null, $services, array(
2563 'spec_option'=> _("No payment Link"),
2568 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2570 global $tax_algorithms;
2572 return array_selector($name, $value, $tax_algorithms,
2574 'select_submit'=> $submit_on_change,
2580 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2583 echo "<td>$label</td>\n";
2585 echo tax_algorithm_list($name, $value, $submit_on_change);
2589 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2591 echo "<tr><td class='label'>$label</td>";
2592 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2596 function refline_list($name, $type, $value=null, $spec_option=false)
2598 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2603 $where = array('`trans_type`='.db_escape($type));
2605 return combo_input($name, $value, $sql, 'id', 'prefix',
2607 'order'=>array('prefix'),
2608 'spec_option' => $spec_option,
2612 'select_submit' => true,
2617 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2621 echo "<td class='label'>$label</td>\n";
2624 echo refline_list($name, $type, $selected_id, $spec_option);
2625 echo "</td></tr>\n";
2629 //----------------------------------------------------------------------------------------------
2631 function subledger_list($name, $account, $selected_id=null)
2634 $type = is_subledger_account($account);
2639 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2641 .TB_PREF."debtors_master d,"
2642 .TB_PREF."cust_branch c
2643 WHERE d.debtor_no=c.debtor_no AND NOT d.inactive AND c.receivables_account=".db_escape($account);
2645 $sql = "SELECT supplier_id as id, supp_ref as name
2647 .TB_PREF."suppliers s
2648 WHERE NOT s.inactive AND s.payable_account=".db_escape($account);
2650 $mode = get_company_pref('no_customer_list');
2652 return combo_input($name, $selected_id, $sql, 'id', 'name',
2660 function subledger_list_cells($label, $name, $account, $selected_id=null)
2663 echo "<td>$label</td>\n";
2665 echo subledger_list($name, $account, $selected_id);
2669 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2670 $submit_on_change=false, $show_inactive=false, $editkey = false)
2672 echo "<tr><td class='label'>$label</td><td nowrap>";
2673 echo subledger_list($name, $account, $selected_id);
2674 echo "</td>\n</tr>\n";
2677 function accounts_type_list_row($label, $name, $selected_id=null)
2681 echo "<td class='label'>$label</td>\n";
2683 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2684 echo array_selector($name, $selected_id, $sel);
2685 echo "</td></tr>\n";
2688 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2691 $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2694 echo "<td>$label</td>\n";
2697 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2699 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2701 'order' => 'real_name',
2702 'select_submit'=> $submit_on_change,
2709 function collations_list_row($label, $name, $selected_id=null)
2711 global $supported_collations;
2715 echo "<td class='label'>$label</td>\n";
2718 echo array_selector($name, $selected_id, $supported_collations,
2719 array('select_submit'=> false) );
2720 echo "</td></tr>\n";