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><td>\n";
555 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
560 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
561 $submit_on_change=false, $all=false, $editkey = false)
563 echo "<tr><td class='label'>$label</td><td>";
564 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
568 //----------------------------------------------------------------------------------------------
570 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
571 $show_inactive=false, $editkey = false)
574 if (!empty($SysPrefs->prefs['shortname_name_in_list']))
575 $sql = "SELECT debtor_no, debtor_ref, name, curr_code, inactive FROM ".TB_PREF."debtors_master ";
577 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
579 $mode = get_company_pref('no_customer_list');
582 set_editor('customer', $name, $editkey);
584 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
586 'format' => '_format_add_curr',
587 'order' => array('debtor_ref'),
588 'search_box' => $mode!=0,
591 'search' => array("debtor_ref","name","tax_id"),
592 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
593 'spec_id' => ALL_TEXT,
594 'select_submit'=> $submit_on_change,
596 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
597 _('Select customer'),
598 'show_inactive' => $show_inactive,
599 'editlink' => $editkey ? add_edit_combo('customer') : false
604 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
605 $submit_on_change=false, $show_inactive=false, $editkey = false)
608 echo "<td>$label</td>\n";
610 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
611 $show_inactive, $editkey);
615 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
616 $submit_on_change=false, $show_inactive=false, $editkey = false)
619 echo "<tr><td class='label'>$label</td><td nowrap>";
620 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
621 $show_inactive, $editkey);
622 echo "</td>\n</tr>\n";
625 //------------------------------------------------------------------------------------------------
627 function customer_branches_list($customer_id, $name, $selected_id=null,
628 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
631 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
632 WHERE debtor_no=" . db_escape($customer_id)." ";
635 set_editor('branch', $name, $editkey);
637 $where = $enabled ? array("inactive = 0") : array();
638 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
641 'order' => array('branch_ref'),
642 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
643 'spec_id' => ALL_TEXT,
644 'select_submit'=> $submit_on_change,
645 'sel_hint' => _('Select customer branch'),
646 'editlink' => $editkey ? add_edit_combo('branch') : false
650 //------------------------------------------------------------------------------------------------
652 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
653 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
656 echo "<td>$label</td>\n";
658 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
659 $submit_on_change, $editkey);
663 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
664 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
666 echo "<tr><td class='label'>$label</td>";
667 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
668 $all_option, $enabled, $submit_on_change, $editkey);
672 //------------------------------------------------------------------------------------------------
674 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
677 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations WHERE fixed_asset=".(int)$fixed_asset;
679 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
681 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
682 'spec_id' => ALL_TEXT,
683 'select_submit'=> $submit_on_change
687 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
690 echo "<td>$label</td>\n";
692 echo locations_list($name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
696 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
698 echo "<tr><td class='label'>$label</td>";
699 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
703 //-----------------------------------------------------------------------------------------------
705 function currencies_list($name, $selected_id=null, $submit_on_change=false, $exclude_home_curr=false)
707 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
708 if ($exclude_home_curr)
709 $sql .= " WHERE curr_abrev!='".get_company_currency()."'";
711 // default to the company currency
712 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
714 'select_submit'=> $submit_on_change,
715 'default' => get_company_currency(),
720 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
723 echo "<td>$label</td>\n";
725 echo currencies_list($name, $selected_id, $submit_on_change);
729 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
731 echo "<tr><td class='label'>$label</td>";
732 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
736 //---------------------------------------------------------------------------------------------------
738 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
741 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
743 // default to the company current fiscal year
745 return combo_input($name, $selected_id, $sql, 'id', '',
748 'default' => get_company_pref('f_year'),
749 'format' => '_format_fiscalyears',
750 'select_submit'=> $submit_on_change,
755 function _format_fiscalyears($row)
757 return sql2date($row[1]) . " - " . sql2date($row[2])
758 . " " . ($row[3] ? _('Closed') : _('Active'));
761 function fiscalyears_list_cells($label, $name, $selected_id=null)
764 echo "<td>$label</td>\n";
766 echo fiscalyears_list($name, $selected_id);
770 function fiscalyears_list_row($label, $name, $selected_id=null)
772 echo "<tr><td class='label'>$label</td>";
773 fiscalyears_list_cells(null, $name, $selected_id);
776 //------------------------------------------------------------------------------------
778 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
779 $submit_on_change=false, $showclosed=false, $showtype=1)
781 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
784 'order' => 'reference',
785 'spec_option'=>$no_option ? $showname : false,
787 'select_submit'=> $submit_on_change,
792 $options['where'][] = "closed=0";
794 $options['where'][] = "type_=".db_escape($showtype);
796 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
799 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
800 $showclosed=false, $showtype=0, $submit_on_change=false)
803 echo "<td>$label</td>\n";
805 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
809 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
810 $showclosed=false, $showtype=0, $submit_on_change=false)
812 echo "<tr><td class='label'>$label</td>";
813 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
814 $showclosed, $showtype, $submit_on_change);
818 //---------------------------------------------------------------------------------------------------
820 function stock_items_list($name, $selected_id=null, $all_option=false,
821 $submit_on_change=false, $opts=array(), $editkey = false, $type = "stock")
823 $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
824 FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
826 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
827 $sql .= " AND mb_flag='F'";
829 $sql .= " AND mb_flag!='F'";
832 set_editor('item', $name, $editkey);
834 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
837 'format' => '_format_stock_items',
838 'spec_option' => $all_option===true ? _("All Items") : $all_option,
839 'spec_id' => ALL_TEXT,
840 'search_box' => true,
841 'search' => array("stock_id", "c.description","s.description"),
842 'search_submit' => get_company_pref('no_item_list')!=0 && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']),
844 'select_submit'=> $submit_on_change,
846 'order' => array('c.description','stock_id'),
847 'editlink' => $editkey ? add_edit_combo('item') : false,
854 function _format_stock_items($row)
856 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
859 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
860 $submit_on_change=false, $all=false, $editkey = false, $opts= array())
862 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
863 $editor_item = 'fa_item';
865 $editor_item = 'item';
868 // set_editor($editor_item, $name, $editkey);
871 echo "<td>$label</td>\n";
874 // $opts = array_merge($options, array('cells'=>true, 'show_inactive'=>$all, 'new_icon' => $editkey ? 'item' : false));
876 // echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, $opts);
878 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
879 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey);
883 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
886 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
890 //---------------------------------------------------------------------------------------------------
892 // Select item via foreign code.
894 function sales_items_list($name, $selected_id=null, $all_option=false,
895 $submit_on_change=false, $type='', $opts=array())
898 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
899 i.inactive, if(count(*)>1, '0', s.editable) as editable
901 ".TB_PREF."stock_master s,
902 ".TB_PREF."item_codes i
904 ".TB_PREF."stock_category c
905 ON i.category_id=c.category_id
906 WHERE i.stock_id=s.stock_id
910 if ($type == 'local') { // exclude foreign codes
911 $sql .= " AND !i.is_foreign";
912 } elseif ($type == 'kits') { // sales kits
913 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
915 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
916 $sql .= " GROUP BY i.item_code";
918 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
921 'format' => '_format_stock_items',
922 'spec_option' => $all_option===true ? _("All Items") : $all_option,
923 'spec_id' => ALL_TEXT,
924 'search_box' => true,
925 'search' => array("i.item_code", "c.description", "i.description"),
926 'search_submit' => get_company_pref('no_item_list')!=0,
928 'select_submit'=> $submit_on_change,
930 'order' => array('c.description','i.item_code'),
933 ), $opts), $type == 'kits' ? $type : "stock_sales" );
936 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
939 set_editor('item', $name, $editkey);
942 echo "<td>$label</td>\n";
943 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
944 '', array('cells'=>true));
947 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
949 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
950 'kits', array('cells'=>false, 'editable' => false));
953 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
957 echo "<td class='label'>$label</td>\n";
959 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
960 'local', array('cells'=>false, 'editable' => false));
963 //------------------------------------------------------------------------------------
965 function stock_manufactured_items_list($name, $selected_id=null,
966 $all_option=false, $submit_on_change=false)
968 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
969 array('where'=>array("mb_flag= 'M'")), false, "stock_manufactured");
972 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
973 $all_option=false, $submit_on_change=false)
976 echo "<td>$label</td>\n";
978 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
982 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
983 $all_option=false, $submit_on_change=false)
985 echo "<tr><td class='label'>$label</td>";
986 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
989 //------------------------------------------------------------------------------------
991 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
992 $all_option=false, $submit_on_change=false, $editkey = false)
994 $parent = db_escape($parent_stock_id);
995 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
996 array('where'=>array("stock_id != $parent"), 'parent'=> $parent_stock_id), $editkey, "component");
1000 function stock_component_items_list_cells($label, $name, $parent_stock_id,
1001 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
1004 echo "<td>$label</td>\n";
1005 $parent = db_escape($parent_stock_id);
1006 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1007 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true, 'parent'=> $parent_stock_id), $editkey, "component");
1009 //------------------------------------------------------------------------------------
1011 function stock_costable_items_list($name, $selected_id=null,
1012 $all_option=false, $submit_on_change=false)
1014 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1015 array('where'=>array("mb_flag!='D'")), false, "stock_costable");
1018 function stock_costable_items_list_cells($label, $name, $selected_id=null,
1019 $all_option=false, $submit_on_change=false)
1022 echo "<td>$label</td>\n";
1023 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1024 array('where'=>array("mb_flag!='D'"), 'cells'=>true), false, "stock_costable");
1027 //------------------------------------------------------------------------------------
1028 function stock_purchasable_items_list($name, $selected_id=null,
1029 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
1031 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1032 array('where'=>array("NOT no_purchase"),
1033 'show_inactive'=>$all), $editkey, "stock_purchased");
1036 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
1038 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
1039 $all_option=false, $submit_on_change=false, $editkey=false)
1042 echo "<td>$label</td>\n";
1043 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1044 array('where'=>array("NOT no_purchase"),
1046 'cells'=>true), $editkey);
1049 //------------------------------------------------------------------------------------
1051 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
1053 global $stock_types;
1057 echo "<td class='label'>$label</td>\n";
1060 echo array_selector($name, $selected_id, $stock_types,
1062 'select_submit'=> true,
1063 'disabled' => !$enabled) );
1064 echo "</td></tr>\n";
1067 function stock_units_list_row($label, $name, $value=null, $enabled=true)
1069 $result = get_all_item_units();
1072 echo "<td class='label'>$label</td>\n";
1075 while($unit = db_fetch($result))
1076 $units[$unit['abbr']] = $unit['name'];
1078 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
1080 echo "</td></tr>\n";
1083 //------------------------------------------------------------------------------------
1085 function stock_purchasable_fa_list_cells($label, $name, $selected_id=null, $all_option=false,
1086 $submit_on_change=false, $all=false, $editkey = false, $exclude_items = array())
1088 // Check if a fixed asset has been bought.
1089 $where_opts[] = "stock_id NOT IN
1090 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1092 // exclude items currently on the order.
1093 foreach($exclude_items as $item) {
1094 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1096 $where_opts[] = "mb_flag='F'";
1098 echo stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, $all, $editkey,
1099 array('fixed_asset' => true, 'where' => $where_opts));
1102 function stock_disposable_fa_list($name, $selected_id=null,
1103 $all_option=false, $submit_on_change=false)
1105 // Check if a fixed asset has been bought....
1106 $where_opts[] = "stock_id IN
1107 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1108 // ...but has not been disposed or sold already.
1109 $where_opts[] = "stock_id NOT IN
1110 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1112 $where_opts[] = "mb_flag='F'";
1114 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1115 array('fixed_asset' => true, 'where' => $where_opts));
1118 function stock_disposable_fa_list_cells($label, $name, $selected_id=null,
1119 $all_option=false, $submit_on_change=false, $exclude_items = array())
1121 // Check if a fixed asset has been bought....
1122 $where_opts[] = "stock_id IN
1123 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1124 // ...but has not been disposed or sold already.
1125 $where_opts[] = "stock_id NOT IN
1126 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1128 $where_opts[] = "mb_flag='F'";
1130 foreach($exclude_items as $item) {
1131 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1135 echo "<td>$label</td>\n";
1136 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1137 array('fixed_asset' => true, 'cells'=>true, 'where' => $where_opts));
1140 function stock_depreciable_fa_list_cells($label, $name, $selected_id=null,
1141 $all_option=false, $submit_on_change=false)
1144 // Check if a fixed asset has been bought....
1145 $where_opts[] = "stock_id IN
1146 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1147 // ...but has not been disposed or sold already.
1148 $where_opts[] = "stock_id NOT IN
1149 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1151 $year = get_current_fiscalyear();
1152 $y = date('Y', strtotime($year['end']));
1154 // check if current fiscal year
1155 $where_opts[] = "depreciation_date < '".$y."-12-01'";
1156 $where_opts[] = "depreciation_date >= '".($y-1)."-12-01'";
1158 $where_opts[] = "material_cost > 0";
1159 $where_opts[] = "mb_flag='F'";
1162 echo "<td>$label</td>\n";
1163 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1164 array('fixed_asset' => true, 'where' => $where_opts, 'cells'=>true));
1167 //------------------------------------------------------------------------------------
1169 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
1171 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
1173 return combo_input($name, $selected_id, $sql, 'id', 'name',
1175 'spec_option' => $none_option,
1176 'spec_id' => ALL_NUMERIC,
1177 'select_submit'=> $submit_on_change,
1182 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1183 $submit_on_change=false)
1186 echo "<td>$label</td>\n";
1188 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1192 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1193 $submit_on_change=false)
1195 echo "<tr><td class='label'>$label</td>";
1196 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1200 //------------------------------------------------------------------------------------
1202 function tax_groups_list($name, $selected_id=null,
1203 $none_option=false, $submit_on_change=false)
1205 $sql = "SELECT id, name FROM ".TB_PREF."tax_groups";
1207 return combo_input($name, $selected_id, $sql, 'id', 'name',
1210 'spec_option' => $none_option,
1211 'spec_id' => ALL_NUMERIC,
1212 'select_submit'=> $submit_on_change,
1217 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1220 echo "<td>$label</td>\n";
1222 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1226 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1228 echo "<tr><td class='label'>$label</td>";
1229 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1233 //------------------------------------------------------------------------------------
1235 function item_tax_types_list($name, $selected_id=null, $show_inactive = false)
1237 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1238 if (!$show_inactive)
1239 $sql .= " WHERE !inactive";
1241 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1244 function item_tax_types_list_cells($label, $name, $selected_id=null, $show_inactive = false)
1247 echo "<td>$label</td>\n";
1249 echo item_tax_types_list($name, $selected_id, $show_inactive);
1253 function item_tax_types_list_row($label, $name, $selected_id=null, $show_inactive = false)
1255 echo "<tr><td class='label'>$label</td>";
1256 item_tax_types_list_cells(null, $name, $selected_id, $show_inactive);
1260 //------------------------------------------------------------------------------------
1262 function shippers_list($name, $selected_id=null)
1264 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1265 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1266 array('order'=>array('shipper_name')));
1269 function shippers_list_cells($label, $name, $selected_id=null)
1272 echo "<td>$label</td>\n";
1274 echo shippers_list($name, $selected_id);
1278 function shippers_list_row($label, $name, $selected_id=null)
1280 echo "<tr><td class='label'>$label</td>";
1281 shippers_list_cells(null, $name, $selected_id);
1285 //-------------------------------------------------------------------------------------
1287 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1289 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1290 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1291 array('order'=>array('salesman_name'),
1292 'spec_option' => $spec_opt,
1293 'spec_id' => ALL_NUMERIC));
1296 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1299 echo "<td>$label</td>\n";
1301 echo sales_persons_list($name, $selected_id, $spec_opt);
1305 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1307 echo "<tr><td class='label'>$label</td>";
1308 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1312 //------------------------------------------------------------------------------------
1314 function sales_areas_list($name, $selected_id=null)
1316 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1317 return combo_input($name, $selected_id, $sql, 'area_code', 'description', array());
1320 function sales_areas_list_cells($label, $name, $selected_id=null)
1323 echo "<td>$label</td>\n";
1325 echo sales_areas_list($name, $selected_id);
1329 function sales_areas_list_row($label, $name, $selected_id=null)
1331 echo "<tr><td class='label'>$label</td>";
1332 sales_areas_list_cells(null, $name, $selected_id);
1336 //------------------------------------------------------------------------------------
1338 function sales_groups_list($name, $selected_id=null, $special_option=false)
1340 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1341 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1342 'spec_option' => $special_option===true ? ' ' : $special_option,
1343 'order' => 'description', 'spec_id' => 0,
1347 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1350 echo "<td>$label</td>\n";
1352 echo sales_groups_list($name, $selected_id, $special_option);
1356 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1358 echo "<tr><td class='label'>$label</td>";
1359 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1363 //------------------------------------------------------------------------------------
1365 function _format_template_items($row)
1367 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1370 function templates_list($name, $selected_id=null, $special_option=false)
1372 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1373 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1374 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1375 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1376 'format' => '_format_template_items',
1377 'spec_option' => $special_option===true ? ' ' : $special_option,
1378 'order' => 'order_no', 'spec_id' => 0,
1382 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1385 echo "<td>$label</td>\n";
1387 echo templates_list($name, $selected_id, $special_option);
1391 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1393 echo "<tr><td class='label'>$label</td>";
1394 templates_list_cells(null, $name, $selected_id, $special_option);
1398 //------------------------------------------------------------------------------------
1400 function workorders_list($name, $selected_id=null)
1402 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1403 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1406 function workorders_list_cells($label, $name, $selected_id=null)
1409 echo "<td>$label</td>\n";
1411 echo workorders_list($name, $selected_id);
1415 function workorders_list_row($label, $name, $selected_id=null)
1417 echo "<tr><td class='label'>$label</td>";
1418 workorders_list_cells(null, $name, $selected_id);
1422 //------------------------------------------------------------------------------------
1424 function payment_terms_list($name, $selected_id=null)
1426 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1427 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1430 function payment_terms_list_cells($label, $name, $selected_id=null)
1433 echo "<td>$label</td>\n";
1435 echo payment_terms_list($name, $selected_id);
1439 function payment_terms_list_row($label, $name, $selected_id=null)
1441 echo "<tr><td class='label'>$label</td>";
1442 payment_terms_list_cells(null, $name, $selected_id);
1446 //------------------------------------------------------------------------------------
1448 function credit_status_list($name, $selected_id=null)
1450 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1451 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1454 function credit_status_list_cells($label, $name, $selected_id=null)
1457 echo "<td>$label</td>\n";
1459 echo credit_status_list($name, $selected_id);
1463 function credit_status_list_row($label, $name, $selected_id=null)
1465 echo "<tr><td class='label'>$label</td>";
1466 credit_status_list_cells(null, $name, $selected_id);
1470 //-----------------------------------------------------------------------------------------------
1472 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1474 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1476 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1478 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1480 'select_submit'=> $submit_on_change,
1484 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1487 echo "<td>$label</td>\n";
1489 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1493 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1495 echo "<tr><td class='label'>$label</td>";
1496 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1500 //-----------------------------------------------------------------------------------------------
1502 function _format_date($row)
1504 return sql2date($row['reconciled']);
1507 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1509 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1510 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1511 GROUP BY reconciled";
1512 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1514 'spec_option' => $special_option,
1515 'format' => '_format_date',
1517 'select_submit'=> $submit_on_change
1521 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1524 echo "<td>$label</td>\n";
1526 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1530 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1533 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1537 //-----------------------------------------------------------------------------------------------
1539 function workcenter_list($name, $selected_id=null, $all_option=false)
1542 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1544 return combo_input($name, $selected_id, $sql, 'id', 'name',
1546 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1547 'spec_id' => ALL_TEXT,
1551 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1553 default_focus($name);
1555 echo "<td>$label</td>\n";
1557 echo workcenter_list($name, $selected_id, $all_option);
1561 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1563 echo "<tr><td class='label'>$label</td>";
1564 workcenter_list_cells(null, $name, $selected_id, $all_option);
1568 //-----------------------------------------------------------------------------------------------
1570 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1572 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1573 FROM ".TB_PREF."bank_accounts";
1575 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1577 'format' => '_format_add_curr',
1578 'select_submit'=> $submit_on_change,
1579 'spec_option' => $spec_option,
1585 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1588 echo "<td>$label</td>\n";
1590 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1594 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1596 echo "<tr><td class='label'>$label</td>";
1597 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1600 //-----------------------------------------------------------------------------------------------
1602 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1605 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1606 FROM ".TB_PREF."bank_accounts
1607 WHERE account_type=".BT_CASH;
1610 echo "<tr><td class='label'>$label</td>\n";
1612 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1614 'spec_option' => $all_option,
1615 'spec_id' => ALL_TEXT,
1616 'format' => '_format_add_curr',
1617 'select_submit'=> $submit_on_change,
1620 echo "</td></tr>\n";
1622 //-----------------------------------------------------------------------------------------------
1624 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1626 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1628 default_focus($name);
1631 echo "<td class='label'>$label</td>\n";
1634 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1636 'select_submit'=> $submit_on_change,
1638 'spec_option' =>$spec_option,
1640 'order'=> array('pos_name')
1642 echo "</td></tr>\n";
1645 //-----------------------------------------------------------------------------------------------
1646 // Payment type selector for current user.
1648 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1650 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1652 if ($category == PM_CASH) // only cash
1653 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1654 elseif ($category == PM_CREDIT) // only delayed payments
1655 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1656 elseif (!$prepayments)
1657 $sql .= " WHERE days_before_due>=0";
1659 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1661 'select_submit'=> $submit_on_change,
1667 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1670 echo "<td class='label'>$label</td>\n";
1673 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1677 //-----------------------------------------------------------------------------------------------
1679 function class_list($name, $selected_id=null, $submit_on_change=false)
1681 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1683 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1685 'select_submit'=> $submit_on_change,
1691 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1694 echo "<td>$label</td>\n";
1696 echo class_list($name, $selected_id, $submit_on_change);
1700 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1702 echo "<tr><td class='label'>$label</td>";
1703 class_list_cells(null, $name, $selected_id, $submit_on_change);
1707 //-----------------------------------------------------------------------------------------------
1708 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1710 $where_opts = array();
1712 $where_opts[0] = "dflt_mb_flag='F'";
1714 $where_opts[0] = "dflt_mb_flag!='F'";
1716 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1717 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1718 array('order'=>'category_id',
1719 'spec_option' => $spec_opt,
1721 'select_submit'=> $submit_on_change,
1723 'where' => $where_opts,
1727 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1730 echo "<td>$label</td>\n";
1732 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1736 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
1738 echo "<tr><td class='label'>$label</td>";
1739 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
1743 //-----------------------------------------------------------------------------------------------
1744 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1746 $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 "
1747 .TB_PREF."stock_fa_class c LEFT JOIN ".TB_PREF."stock_fa_class p ON c.parent_id=p.fa_class_id";
1749 return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
1750 array('order'=>'c.fa_class_id',
1751 'spec_option' => $spec_opt,
1753 'select_submit'=> $submit_on_change,
1755 'search_box' => true,
1756 'search' => array("c.fa_class_id"),
1757 'search_submit' => false,
1761 'category' => 'class',
1765 function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1767 echo "<tr><td class='label'>$label</td>";
1769 echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change);
1770 echo "</td></tr>\n";
1773 //-----------------------------------------------------------------------------------------------
1775 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1778 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1780 return combo_input($name, $selected_id, $sql, 'id', 'name',
1782 'format' => '_format_account',
1783 'order' => array('class_id', 'id', 'parent'),
1784 'spec_option' =>$all_option,
1785 'spec_id' => ALL_TEXT
1789 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1792 echo "<td>$label</td>\n";
1794 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1798 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1800 echo "<tr><td class='label'>$label</td>";
1801 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1806 //-----------------------------------------------------------------------------------------------
1807 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1808 $cells=false, $all_option=false, $submit_on_change=false, $all=false, $type_id=false)
1810 if ($skip_bank_accounts)
1811 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1812 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1813 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1814 ."ON chart.account_code=acc.account_code
1815 WHERE acc.account_code IS NULL
1816 AND chart.account_type=type.id";
1818 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1819 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1820 WHERE chart.account_type=type.id";
1821 if ($type_id ) $sql .= " AND chart.account_type=".db_escape($type_id);
1823 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1825 'format' => '_format_account',
1826 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1829 'order' => array('type.class_id','type.id','account_code'),
1830 'search_box' => $cells,
1831 'search_submit' => false,
1835 'select_submit'=> $submit_on_change,
1838 'show_inactive' => $all
1842 function _format_account($row)
1844 return $row[0] . " " . $row[1];
1847 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1848 $skip_bank_accounts=false, $cells=false, $all_option=false,
1849 $submit_on_change=false, $all=false, $type_id=false)
1852 echo "<td>$label</td>\n";
1854 echo gl_all_accounts_list($name, $selected_id,
1855 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all, $type_id);
1859 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1860 $skip_bank_accounts=false, $cells=false, $all_option=false, $type_id=false)
1862 echo "<tr><td class='label'>$label</td>";
1863 gl_all_accounts_list_cells(null, $name, $selected_id,
1864 $skip_bank_accounts, $cells, $all_option, $type_id);
1868 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1871 $items['0'] = strlen($name_no) ? $name_no : _("No");
1872 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1874 return array_selector($name, $selected_id, $items,
1876 'select_submit'=> $submit_on_change,
1877 'async' => false ) ); // FIX?
1880 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1883 echo "<td>$label</td>\n";
1885 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1889 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1891 echo "<tr><td class='label'>$label</td>";
1892 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1896 //------------------------------------------------------------------------------------------------
1898 function languages_list($name, $selected_id=null, $all_option=false)
1900 global $installed_languages;
1904 $items[''] = $all_option;
1905 foreach ($installed_languages as $lang)
1906 $items[$lang['code']] = $lang['name'];
1907 return array_selector($name, $selected_id, $items);
1910 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1913 echo "<td>$label</td>\n";
1915 echo languages_list($name, $selected_id, $all_option);
1919 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1921 echo "<tr><td class='label'>$label</td>";
1922 languages_list_cells(null, $name, $selected_id, $all_option);
1926 //------------------------------------------------------------------------------------------------
1928 function bank_account_types_list($name, $selected_id=null)
1930 global $bank_account_types;
1932 return array_selector($name, $selected_id, $bank_account_types);
1935 function bank_account_types_list_cells($label, $name, $selected_id=null)
1938 echo "<td>$label</td>\n";
1940 echo bank_account_types_list($name, $selected_id);
1944 function bank_account_types_list_row($label, $name, $selected_id=null)
1946 echo "<tr><td class='label'>$label</td>";
1947 bank_account_types_list_cells(null, $name, $selected_id);
1951 //------------------------------------------------------------------------------------------------
1952 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
1954 global $payment_person_types;
1957 foreach ($payment_person_types as $key=>$type)
1959 if ($key != PT_WORKORDER)
1960 $items[$key] = $type;
1962 return array_selector($name, $selected_id, $items,
1963 array( 'select_submit'=> $submit_on_change ) );
1966 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
1969 echo "<td>$label</td>\n";
1971 echo payment_person_types_list($name, $selected_id, $related);
1975 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
1977 echo "<tr><td class='label'>$label</td>";
1978 payment_person_types_list_cells(null, $name, $selected_id, $related);
1982 //------------------------------------------------------------------------------------------------
1984 function wo_types_list($name, $selected_id=null)
1986 global $wo_types_array;
1988 return array_selector($name, $selected_id, $wo_types_array,
1989 array( 'select_submit'=> true, 'async' => true ) );
1992 function wo_types_list_row($label, $name, $selected_id=null)
1994 echo "<tr><td class='label'>$label</td><td>\n";
1995 echo wo_types_list($name, $selected_id);
1996 echo "</td></tr>\n";
1999 //------------------------------------------------------------------------------------------------
2001 function dateformats_list_row($label, $name, $value=null)
2005 echo "<tr><td class='label'>$label</td>\n<td>";
2006 echo array_selector( $name, $value, $SysPrefs->dateformats );
2007 echo "</td></tr>\n";
2010 function dateseps_list_row($label, $name, $value=null)
2014 echo "<tr><td class='label'>$label</td>\n<td>";
2015 echo array_selector( $name, $value, $SysPrefs->dateseps );
2016 echo "</td></tr>\n";
2019 function thoseps_list_row($label, $name, $value=null)
2023 echo "<tr><td class='label'>$label</td>\n<td>";
2024 echo array_selector( $name, $value, $SysPrefs->thoseps );
2025 echo "</td></tr>\n";
2028 function decseps_list_row($label, $name, $value=null)
2032 echo "<tr><td class='label'>$label</td>\n<td>";
2033 echo array_selector( $name, $value, $SysPrefs->decseps );
2034 echo "</td></tr>\n";
2037 function themes_list_row($label, $name, $value=null)
2039 global $path_to_root;
2041 $path = $path_to_root.'/themes/';
2043 $themedir = opendir($path);
2044 while(false !== ($fname = readdir($themedir)))
2046 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
2048 $themes[$fname] = $fname;
2053 echo "<tr><td class='label'>$label</td>\n<td>";
2054 echo array_selector( $name, $value, $themes );
2055 echo "</td></tr>\n";
2058 function pagesizes_list_row($label, $name, $value=null)
2063 foreach ($SysPrefs->pagesizes as $pz)
2066 echo "<tr><td class='label'>$label</td>\n<td>";
2067 echo array_selector( $name, $value, $items );
2068 echo "</td></tr>\n";
2071 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
2073 global $systypes_array;
2075 // emove non-voidable transactions if needed
2076 $systypes = array_diff_key($systypes_array, array_flip($exclude));
2077 return array_selector($name, $value, $systypes,
2079 'spec_option'=> $spec_opt,
2080 'spec_id' => ALL_NUMERIC,
2081 'select_submit'=> $submit_on_change,
2087 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2090 echo "<td>$label</td>\n";
2092 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
2096 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2098 echo "<tr><td class='label'>$label</td>";
2099 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
2103 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
2105 global $systypes_array;
2108 echo "<td>$label</td>\n";
2111 $items = $systypes_array;
2113 // exclude quotes, orders and dimensions
2114 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
2115 unset($items[$excl]);
2117 echo array_selector($name, $value, $items,
2119 'spec_option'=> _("All"),
2121 'select_submit'=> $submit_on_change,
2128 function cust_allocations_list_cells($label, $name, $selected=null, $submit_on_change=false)
2135 ALL_TEXT=>_("All Types"),
2136 '1'=> _("Sales Invoices"),
2137 '2'=> _("Unsettled transactions"),
2138 '3' => _("Payments"),
2139 '4' => _("Credit Notes"),
2140 '5' => _("Delivery Notes")
2142 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2146 function supp_allocations_list_cell($name, $selected=null)
2151 ALL_TEXT=>_("All Types"),
2152 '1'=> _("Invoices"),
2153 '2'=> _("Overdue Invoices"),
2154 '3' => _("Payments"),
2155 '4' => _("Credit Notes"),
2156 '5' => _("Overdue Credit Notes")
2158 echo array_selector($name, $selected, $allocs);
2162 function supp_transactions_list_cell($name, $selected=null, $submit_on_change=false)
2167 ALL_TEXT=>_("All Types"),
2169 '1'=> _("Invoices"),
2170 '2'=> _("Unsettled transactions"),
2171 '3' => _("Payments"),
2172 '4' => _("Credit Notes"),
2173 '5' => _("Overdue Credit Notes")
2176 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2180 function policy_list_cells($label, $name, $selected=null)
2185 echo array_selector($name, $selected,
2186 array( '' => _("Automatically put balance on back order"),
2187 'CAN' => _("Cancel any quantites not delivered")) );
2191 function policy_list_row($label, $name, $selected=null)
2193 echo "<tr><td class='label'>$label</td>";
2194 policy_list_cells(null, $name, $selected);
2198 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2203 echo array_selector($name, $selected,
2204 array( 'Return' => _("Items Returned to Inventory Location"),
2205 'WriteOff' => _("Items Written Off")),
2206 array( 'select_submit'=> $submit_on_change ) );
2210 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2212 echo "<tr><td class='label'>$label</td>";
2213 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2217 function number_list($name, $selected, $from, $to, $no_option=false)
2220 for ($i = $from; $i <= $to; $i++)
2223 return array_selector($name, $selected, $items,
2224 array( 'spec_option' => $no_option,
2225 'spec_id' => ALL_NUMERIC) );
2228 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2233 echo number_list($name, $selected, $from, $to, $no_option);
2237 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2239 echo "<tr><td class='label'>$label</td>";
2240 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2244 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2245 $submit_on_change=true)
2247 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2248 ." GROUP BY profile";
2249 $result = db_query($sql, 'cannot get all profile names');
2250 $profiles = array();
2251 while($myrow=db_fetch($result)) {
2252 $profiles[$myrow['profile']] = $myrow['profile'];
2257 echo "<td class='label'>$label</td>\n";
2260 echo array_selector($name, $selected_id, $profiles,
2261 array( 'select_submit'=> $submit_on_change,
2262 'spec_option'=>$spec_opt,
2266 echo "</td></tr>\n";
2269 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2271 static $printers; // query only once for page display
2274 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2275 $result = db_query($sql, 'cannot get all printers');
2276 $printers = array();
2277 while($myrow=db_fetch($result)) {
2278 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2281 return array_selector($name, $selected_id, $printers,
2282 array( 'select_submit'=> $submit_on_change,
2283 'spec_option'=>$spec_opt,
2288 //------------------------------------------------------------------------------------------------
2290 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2293 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2295 $sql .= " WHERE type=$type";
2297 return combo_input($name, $selected_id, $sql, 'id', 'description',
2300 'order' => 'description',
2301 'select_submit'=> $submit_on_change,
2307 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2310 echo "<td>$label</td>\n";
2312 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2316 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2318 echo "<tr><td class='label'>$label</td>";
2319 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2324 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2326 global $quick_actions;
2328 echo "<tr><td class='label'>$label</td><td>";
2329 echo array_selector($name, $selected_id, $quick_actions,
2331 'select_submit'=> $submit_on_change
2333 echo "</td></tr>\n";
2336 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2338 global $quick_entry_types;
2340 echo "<tr><td class='label'>$label</td><td>";
2341 echo array_selector($name, $selected_id, $quick_entry_types,
2343 'select_submit'=> $submit_on_change
2345 echo "</td></tr>\n";
2348 function record_status_list_row($label, $name) {
2349 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2352 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2354 global $class_types;
2356 echo "<tr><td class='label'>$label</td><td>";
2357 echo array_selector($name, $selected_id, $class_types,
2359 'select_submit'=> $submit_on_change
2361 echo "</td></tr>\n";
2364 //------------------------------------------------------------------------------------------------
2366 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2367 $show_inactive = false)
2370 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2372 return combo_input($name, $selected_id, $sql, 'id', 'description',
2374 'spec_option'=>$new_item ? _("New role") : false,
2376 'select_submit'=> $submit_on_change,
2377 'show_inactive' => $show_inactive
2381 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2382 $show_inactive = false)
2385 echo "<td>$label</td>\n";
2387 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2391 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2392 $show_inactive = false)
2394 echo "<tr><td class='label'>$label</td>";
2395 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2399 function tab_list_row($label, $name, $selected_id=null)
2401 global $installed_extensions;
2404 foreach ($_SESSION['App']->applications as $app) {
2405 $tabs[$app->id] = access_string($app->name, true);
2408 echo "<td class='label'>$label</td><td>\n";
2409 echo array_selector($name, $selected_id, $tabs);
2410 echo "</td></tr>\n";
2413 //-----------------------------------------------------------------------------------------------
2415 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2418 global $path_to_root;
2419 include_once($path_to_root . "/admin/db/tags_db.inc");
2420 $results = get_tags($type, $all);
2422 while ($tag = db_fetch($results))
2423 $tags[$tag['id']] = $tag['name'];
2425 if (!isset($tags)) {
2426 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2429 return array_selector($name, null, $tags,
2432 'height' => $height,
2433 'spec_option'=> $spec_opt,
2438 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2441 echo "<td>$label</td>\n";
2443 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2448 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2450 echo "<tr><td class='label'>$label</td>";
2451 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2455 //---------------------------------------------------------------------------------------------
2456 // List of sets of active extensions
2458 function extset_list($name, $value=null, $submit_on_change=false)
2460 global $db_connections;
2463 foreach ($db_connections as $comp)
2464 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2465 return array_selector( $name, $value, $items,
2467 'spec_option'=> _("Available and/or installed"),
2469 'select_submit'=> $submit_on_change,
2474 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2477 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2482 if (@$filter['class']) {
2483 $where[] = 'type='.db_escape($filter['class']);
2486 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2487 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2488 if (@$filter['multi']) { // contact category selector for person
2492 return combo_input($name, $selected_id, $sql, 'id', 'name',
2495 'height' => $multi ? 5:1,
2496 'category' => $groups,
2497 'select_submit'=> $submit_on_change,
2503 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2505 echo "<tr><td class='label'>$label</td><td>";
2506 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2507 echo "</td></tr>\n";
2510 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2512 global $pterm_types;
2514 echo "<tr><td class='label'>$label</td><td>";
2515 echo array_selector($name, $selected_id, $pterm_types,
2517 'select_submit'=> $submit_on_change
2519 echo "</td></tr>\n";
2522 function coa_list_row($label, $name, $value=null)
2524 global $path_to_root, $installed_extensions;
2526 $path = $path_to_root.'/sql/';
2528 $sqldir = opendir($path);
2529 while (false !== ($fname = readdir($sqldir)))
2531 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2533 $ext = array_search_value($fname, $installed_extensions, 'sql');
2535 $descr = $ext['name'];
2536 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2537 $descr = _("Standard new company American COA (4 digit)");
2538 } elseif ($fname == 'en_US-demo.sql') {
2539 $descr = _("Standard American COA (4 digit) with demo data");
2543 $coas[$fname] = $descr;
2548 echo "<tr><td class='label'>$label</td>\n<td>";
2549 echo array_selector( $name, $value, $coas );
2550 echo "</td></tr>\n";
2553 function payment_services($name)
2555 global $payment_services;
2557 $services = (object)array_combine(array_keys($payment_services), array_keys($payment_services));
2559 return array_selector($name, null, $services, array(
2560 'spec_option'=> _("No payment Link"),
2565 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2567 global $tax_algorithms;
2569 return array_selector($name, $value, $tax_algorithms,
2571 'select_submit'=> $submit_on_change,
2577 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2580 echo "<td>$label</td>\n";
2582 echo tax_algorithm_list($name, $value, $submit_on_change);
2586 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2588 echo "<tr><td class='label'>$label</td>";
2589 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2593 function refline_list($name, $type, $value=null, $spec_option=false)
2595 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2600 $where = array('`trans_type`='.db_escape($type));
2602 return combo_input($name, $value, $sql, 'id', 'prefix',
2604 'order'=>array('prefix'),
2605 'spec_option' => $spec_option,
2609 'select_submit' => true,
2614 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2618 echo "<td class='label'>$label</td>\n";
2621 echo refline_list($name, $type, $selected_id, $spec_option);
2622 echo "</td></tr>\n";
2626 //----------------------------------------------------------------------------------------------
2628 function subledger_list($name, $account, $selected_id=null)
2631 $type = is_subledger_account($account);
2636 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2638 .TB_PREF."debtors_master d,"
2639 .TB_PREF."cust_branch c
2640 WHERE d.debtor_no=c.debtor_no AND NOT d.inactive AND c.receivables_account=".db_escape($account);
2642 $sql = "SELECT supplier_id as id, supp_ref as name
2644 .TB_PREF."suppliers s
2645 WHERE NOT s.inactive AND s.payable_account=".db_escape($account);
2647 $mode = get_company_pref('no_customer_list');
2649 return combo_input($name, $selected_id, $sql, 'id', 'name',
2657 function subledger_list_cells($label, $name, $account, $selected_id=null)
2660 echo "<td>$label</td>\n";
2662 echo subledger_list($name, $account, $selected_id);
2666 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2667 $submit_on_change=false, $show_inactive=false, $editkey = false)
2669 echo "<tr><td class='label'>$label</td><td nowrap>";
2670 echo subledger_list($name, $account, $selected_id);
2671 echo "</td>\n</tr>\n";
2674 function accounts_type_list_row($label, $name, $selected_id=null)
2678 echo "<td class='label'>$label</td>\n";
2680 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2681 echo array_selector($name, $selected_id, $sel);
2682 echo "</td></tr>\n";
2685 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2688 $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
2691 echo "<td>$label</td>\n";
2694 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2696 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2698 'order' => 'real_name',
2699 'select_submit'=> $submit_on_change,
2706 function collations_list_row($label, $name, $selected_id=null)
2708 global $supported_collations;
2712 echo "<td class='label'>$label</td>\n";
2715 echo array_selector($name, $selected_id, $supported_collations,
2716 array('select_submit'=> false) );
2717 echo "</td></tr>\n";