2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/banking.inc");
13 include_once($path_to_root . "/includes/types.inc");
14 include_once($path_to_root . "/includes/current_user.inc");
16 define('SEARCH_BUTTON', "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
17 ."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ");
19 define('SELECT_BUTTON', "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
20 ."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ");
22 //----------------------------------------------------------------------------
23 // Universal sql combo generator
24 // $sql must return selector values and selector texts in columns 0 & 1
25 // Options are merged with defaults.
27 function combo_input($name, $selected_id, $sql, $valfield, $namefield,
28 $options=null, $type=null)
30 global $Ajax, $path_to_root, $SysPrefs ;
32 $opts = array( // default options
33 'where'=> array(), // additional constraints
34 'order' => $namefield, // list sort order
35 // special option parameters
36 'spec_option'=>false, // option text or false
37 'spec_id' => 0, // option id
38 // submit on select parameters
39 'default' => '', // default value when $_POST is not set
40 'multi' => false, // multiple select
41 'select_submit' => false, //submit on select: true/false
42 'async' => true, // select update via ajax (true) vs _page_body reload
43 // search box parameters
45 'search_box' => false, // name or true/false
46 'type' => 0, // type of extended selector:
47 // 0 - with (optional) visible search box, search by fragment inside id
48 // 1 - with hidden search box, search by option text
49 // 2 - with (optional) visible search box, search by fragment at the start of id
50 // 3 - TODO reverse: box with hidden selector available via enter; this
51 // would be convenient for optional ad hoc adding of new item
52 'search_submit' => true, //search submit button: true/false
53 'size' => 8, // size and max of box tag
55 'height' => false, // number of lines in select box
56 'cells' => false, // combo displayed as 2 <td></td> cells
57 'search' => array(), // sql field names to search
58 'format' => null, // format functions for regular options
60 'box_hint' => null, // box/selectors hints; null = std see below
61 'category' => false, // category column name or false
62 'show_inactive' => false, // show inactive records.
63 'editable' => false, // false, or length of editable entry field
64 'editlink' => false // link to entity entry/edit page (optional)
66 // ------ merge options with defaults ----------
68 $opts = array_merge($opts, $options);
69 if (!is_array($opts['where'])) $opts['where'] = array($opts['where']);
71 $search_box = $opts['search_box']===true ? '_'.$name.'_edit' : $opts['search_box'];
72 // select content filtered by search field:
73 $search_submit = $opts['search_submit']===true ? '_'.$name.'_button' : $opts['search_submit'];
74 // select set by select content field
75 $search_button = $opts['editable'] ? '_'.$name.'_button' : ($search_box ? $search_submit : false);
77 $select_submit = $opts['select_submit'];
78 $spec_id = $opts['spec_id'];
79 $spec_option = $opts['spec_option'];
80 if ($opts['type'] == 0) {
83 } elseif($opts['type'] == 1) {
91 $disabled = $opts['disabled'] ? "disabled" : '';
92 $multi = $opts['multi'];
94 if(!count($opts['search'])) {
95 $opts['search'] = array($by_id ? $valfield : $namefield);
97 if ($opts['sel_hint'] === null)
98 $opts['sel_hint'] = $by_id || $search_box==false ?
99 '' : _('Press Space tab for search pattern entry');
101 if ($opts['box_hint'] === null)
102 $opts['box_hint'] = $search_box && $search_submit != false ?
103 ($by_id ? _('Enter code fragment to search or * for all')
104 : _('Enter description fragment to search or * for all')) :'';
106 if ($selected_id == null) {
107 $selected_id = get_post($name, (string)$opts['default']);
109 if(!is_array($selected_id))
110 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
112 $txt = get_post($search_box);
115 if (isset($_POST['_'.$name.'_update'])) { // select list or search box change
116 if ($by_id) $txt = $_POST[$name];
119 $Ajax->activate('_page_body');
121 $Ajax->activate($name);
123 if (isset($_POST[$search_button])) {
125 $Ajax->activate('_page_body');
127 $Ajax->activate($name);
130 // search related sql modifications
132 $rel = "rel='$search_box'"; // set relation to list
133 if ($opts['search_submit']) {
134 if (isset($_POST[$search_button])) {
135 $selected_id = array(); // ignore selected_id while search
137 $Ajax->activate('_page_body');
139 $Ajax->activate($name);
142 if ($spec_option === false && $selected_id == array())
145 $opts['where'][] = $valfield . "=". db_escape(get_post($name, $spec_id));
150 foreach($opts['search'] as $i=> $s)
151 $opts['search'][$i] = $s . " LIKE "
152 .db_escape(($class=='combo3' ? '' : '%').$txt.'%');
153 $opts['where'][] = '('. implode($opts['search'], ' OR ') . ')';
159 if (count($opts['where'])) {
160 $where = strpos($sql, 'WHERE')==false ? ' WHERE ':' AND ';
161 $where .= '('. implode($opts['where'], ' AND ') . ')';
162 $group_pos = strpos($sql, 'GROUP BY');
164 $group = substr($sql, $group_pos);
165 $sql = substr($sql, 0, $group_pos) . $where.' '.$group;
170 if ($opts['order'] != false) {
171 if (!is_array($opts['order']))
172 $opts['order'] = array($opts['order']);
173 $sql .= ' ORDER BY '.implode(',',$opts['order']);
177 // ------ make selector ----------
178 $selector = $first_opt = '';
184 if (($type === "customer" || $type === "supplier") && !empty($SysPrefs->prefs['shortname_name_in_list']))
186 if($result = db_query($sql)) {
187 while ($contact_row = db_fetch($result)) {
188 $value = $contact_row[0];
189 $descr = $opts['format']==null ? $contact_row[1] :
190 call_user_func($opts['format'], $contact_row, $pname);
192 if (get_post($search_button) && ($txt == $value)) {
193 $selected_id[] = $value;
196 if (in_array((string)$value, $selected_id, true)) {
199 $edit = $opts['editable'] && $contact_row['editable']
200 && (@$_POST[$search_box] == $value)
201 ? $contact_row[1] : false; // get non-formatted description
203 break; // selected field is editable - abandon list construction
205 // show selected option even if inactive
206 if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') {
209 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
211 if ($first_id === false) {
215 $cat = $contact_row[$opts['category']];
216 if ($opts['category'] !== false && $cat != $lastcat){
218 $selector .= "</optgroup>";
219 $selector .= "<optgroup label='".$cat."'>\n";
222 $selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
225 $selector .= "</optgroup>";
226 db_free_result($result);
229 // Prepend special option.
230 if ($spec_option !== false) { // if special option used - add it
231 $first_id = $spec_id;
232 $first_opt = $spec_option;
233 $sel = $found===false ? 'selected' : '';
234 $optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
235 $selector = "<option $sel value='$first_id'>$first_opt</option>\n"
239 if ($found===false) {
240 $selected_id = array($first_id);
243 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
245 if ($SysPrefs->use_popup_search)
246 $selector = "<select id='$name' autocomplete='off' ".($multi ? "multiple" : '')
247 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
248 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
249 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
251 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
252 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
253 . "$disabled name='$name".($multi ? '[]':'')."' class='$class' title='"
254 . $opts['sel_hint']."' $rel>".$selector."</select>\n";
255 if ($by_id && ($search_box != false || $opts['editable']) ) {
256 // on first display show selector list
257 if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
258 $selector = "<input type='hidden' name='$name' value='".$_POST[$name]."'>"
259 ."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
260 $opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
261 set_focus($name.'_text'); // prevent lost focus
262 } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
263 set_focus($name); // prevent lost focus
264 if (!$opts['editable'])
266 $Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
269 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
271 // span for select list/input field update
272 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
274 // if selectable or editable list is used - add select button
275 if ($select_submit != false || $search_button) {
276 // button class selects form reload/ajax selector update
277 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
278 (fallback_mode() ? '' : 'display:none;'),
279 '_'.$name.'_update')."\n";
281 // ------ make combo ----------
283 if ($search_box != false) {
284 $edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='".
285 $opts['size']."' maxlength='".$opts['max'].
286 "' value='$txt' class='$class' rel='$name' autocomplete='off' title='"
287 .$opts['box_hint']."'"
288 .(!fallback_mode() && !$by_id ? " style=display:none;":'')
290 if ($search_submit != false || $opts['editable']) {
291 $edit_entry .= sprintf(SEARCH_BUTTON, $disabled, user_theme(),
292 (fallback_mode() ? '' : 'display:none;'),
293 $search_submit ? $search_submit : "_{$name}_button")."\n";
296 default_focus(($search_box && $by_id) ? $search_box : $name);
299 if ($SysPrefs->use_popup_search && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']))
304 if ($SysPrefs->use_popup_windows) {
305 switch (strtolower($type)) {
307 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=all&client_id=" . $id;
308 $img_title = _("Search items");
310 case "stock_manufactured":
311 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=manufactured&client_id=" . $id;
312 $img_title = _("Search items");
314 case "stock_purchased":
315 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=purchasable&client_id=" . $id;
316 $img_title = _("Search items");
319 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=sales&client_id=" . $id;
320 $img_title = _("Search items");
322 case "stock_costable":
323 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=costable&client_id=" . $id;
324 $img_title = _("Search items");
327 $parent = $opts['parent'];
328 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=component&parent=".$parent."&client_id=" . $id;
329 $img_title = _("Search items");
332 $link = $path_to_root . "/inventory/inquiry/stock_list.php?popup=1&type=kits&client_id=" . $id;
333 $img_title = _("Search items");
336 $link = $path_to_root . "/sales/inquiry/customers_list.php?popup=1&client_id=" . $id;
337 $img_title = _("Search customers");
340 $link = $path_to_root . "/sales/inquiry/customer_branches_list.php?popup=1&client_id=" . $id . "#customer_id";
341 $img_title = _("Search branches");
344 $link = $path_to_root . "/purchasing/inquiry/suppliers_list.php?popup=1&client_id=" . $id;
345 $img_title = _("Search suppliers");
349 $skip = strtolower($type) == "account" ? false : true;
350 $link = $path_to_root . "/gl/inquiry/accounts_list.php?popup=1&skip=".$skip."&client_id=" . $id;
351 $img_title = _("Search GL accounts");
357 $theme = user_theme();
358 $img = '<img src="'.$path_to_root.'/themes/'.$theme.'/images/'.ICON_VIEW.
359 '" style="vertical-align:middle;width:12px;height:12px;border:0;" onclick="javascript:lookupWindow("'.
360 $link.'", "");" title="' . $img_title . '" style="cursor:pointer;" />';
364 if ($opts['editlink'])
365 $selector .= ' '.$opts['editlink'];
367 if ($search_box && $opts['cells'])
368 $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td nowrap>$selector$img</td>";
370 $str = $edit_entry.$selector.$img;
376 Returns true if selector $name is subject to update.
378 function list_updated($name)
380 return isset($_POST['_'.$name.'_update']) || isset($_POST['_'.$name.'_button']);
382 //----------------------------------------------------------------------------------------------
383 // Universal array combo generator
384 // $items is array of options 'value' => 'description'
385 // Options is reduced set of combo_selector options and is merged with defaults.
387 function array_selector($name, $selected_id, $items, $options=null)
391 $opts = array( // default options
392 'spec_option'=>false, // option text or false
393 'spec_id' => 0, // option id
394 'select_submit' => false, //submit on select: true/false
395 'async' => true, // select update via ajax (true) vs _page_body reload
396 'default' => '', // default value when $_POST is not set
397 'multi'=>false, // multiple select
398 // search box parameters
399 'height' => false, // number of lines in select box
403 // ------ merge options with defaults ----------
405 $opts = array_merge($opts, $options);
406 $select_submit = $opts['select_submit'];
407 $spec_id = $opts['spec_id'];
408 $spec_option = $opts['spec_option'];
409 $disabled = $opts['disabled'] ? "disabled" : '';
410 $multi = $opts['multi'];
412 if ($selected_id == null) {
413 $selected_id = get_post($name, $opts['default']);
415 if(!is_array($selected_id))
416 $selected_id = array((string)$selected_id); // code is generalized for multiple selection support
418 if (isset($_POST[ '_'.$name.'_update'])) {
420 $Ajax->activate('_page_body');
422 $Ajax->activate($name);
425 // ------ make selector ----------
426 $selector = $first_opt = '';
429 foreach($items as $value=>$descr) {
431 if (in_array((string)$value, $selected_id, true)) {
435 if ($first_id === false) {
439 $selector .= "<option $sel value='$value'>$descr</option>\n";
442 if ($first_id!==false) {
443 $sel = ($found===$first_id) || ($found===false && ($spec_option===false)) ? "selected='selected'" : '';
445 // Prepend special option.
446 if ($spec_option !== false) { // if special option used - add it
447 $first_id = $spec_id;
448 $first_opt = $spec_option;
449 $sel = $found===false ? 'selected' : '';
450 $selector = "<option $sel value='$spec_id'>$spec_option</option>\n"
454 if ($found===false) {
455 $selected_id = array($first_id);
457 $_POST[$name] = $multi ? $selected_id : $selected_id[0];
459 $selector = "<select autocomplete='off' ".($multi ? "multiple" : '')
460 . ($opts['height']!==false ? ' size="'.$opts['height'].'"' : '')
461 . "$disabled name='$name".($multi ? '[]' : '')."' class='combo' title='"
462 . $opts['sel_hint']."'>".$selector."</select>\n";
464 $Ajax->addUpdate($name, "_{$name}_sel", $selector);
466 $selector = "<span id='_{$name}_sel'>".$selector."</span>\n";
468 if ($select_submit != false) { // if submit on change is used - add select button
469 $selector .= sprintf(SELECT_BUTTON, $disabled, user_theme(),
470 (fallback_mode() ? '' : 'display:none;'),
471 '_'.$name.'_update')."\n";
473 default_focus($name);
477 //----------------------------------------------------------------------------------------------
478 function array_selector_row($label, $name, $selected_id, $items, $options=null)
480 echo "<tr><td class='label'>$label</td>\n<td>";
481 echo array_selector($name, $selected_id, $items, $options);
485 //----------------------------------------------------------------------------------------------
486 function _format_add_curr($row, $pname=false)
488 static $company_currency;
490 if ($company_currency == null)
492 $company_currency = get_company_currency();
496 return $row[1] . ($row[2] == $company_currency ? '' : (" - " . $row[2]));
500 return $row[1] . " - " . $row[2] . ($row[3] == $company_currency ? '' : (" - " . $row[3]));
504 function add_edit_combo($type)
506 global $path_to_root, $popup_editors, $SysPrefs;
508 if (!isset($SysPrefs->use_icon_for_editkey) || $SysPrefs->use_icon_for_editkey==0)
511 $theme_path = $path_to_root . '/themes/' . user_theme();
513 $key = $popup_editors[$type][1];
514 $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
515 $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
516 return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
519 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
520 $all=false, $editkey = false)
523 if (!empty($SysPrefs->prefs['shortname_name_in_list']))
524 $sql = "SELECT supplier_id, supp_ref, supp_name, curr_code, inactive FROM ".TB_PREF."suppliers ";
526 $sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM ".TB_PREF."suppliers ";
528 $mode = get_company_pref('no_supplier_list');
531 set_editor('supplier', $name, $editkey);
533 $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
535 'format' => '_format_add_curr',
536 'order' => array('supp_ref'),
537 'search_box' => $mode!=0,
539 'search' => array("supp_ref","supp_name","gst_no"),
540 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
541 'spec_id' => ALL_TEXT,
542 'select_submit'=> $submit_on_change,
544 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') :
545 _('Select supplier'),
546 'show_inactive'=>$all,
547 'editlink' => $editkey ? add_edit_combo('supplier') : false
552 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false,
553 $submit_on_change=false, $all=false, $editkey = false)
556 echo "<td>$label</td>\n";
558 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
563 function supplier_list_row($label, $name, $selected_id=null, $all_option = false,
564 $submit_on_change=false, $all=false, $editkey = false)
566 echo "<tr><td class='label'>$label</td><td>";
567 echo supplier_list($name, $selected_id, $all_option, $submit_on_change,
571 //----------------------------------------------------------------------------------------------
573 function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
574 $show_inactive=false, $editkey = false)
577 if (!empty($SysPrefs->prefs['shortname_name_in_list']))
578 $sql = "SELECT debtor_no, debtor_ref, name, curr_code, inactive FROM ".TB_PREF."debtors_master ";
580 $sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM ".TB_PREF."debtors_master ";
582 $mode = get_company_pref('no_customer_list');
585 set_editor('customer', $name, $editkey);
587 $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
589 'format' => '_format_add_curr',
590 'order' => array('debtor_ref'),
591 'search_box' => $mode!=0,
594 'search' => array("debtor_ref","name","tax_id"),
595 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
596 'spec_id' => ALL_TEXT,
597 'select_submit'=> $submit_on_change,
599 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') :
600 _('Select customer'),
601 'show_inactive' => $show_inactive,
602 'editlink' => $editkey ? add_edit_combo('customer') : false
607 function customer_list_cells($label, $name, $selected_id=null, $all_option=false,
608 $submit_on_change=false, $show_inactive=false, $editkey = false)
611 echo "<td>$label</td>\n";
613 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
614 $show_inactive, $editkey);
618 function customer_list_row($label, $name, $selected_id=null, $all_option = false,
619 $submit_on_change=false, $show_inactive=false, $editkey = false)
622 echo "<tr><td class='label'>$label</td><td nowrap>";
623 echo customer_list($name, $selected_id, $all_option, $submit_on_change,
624 $show_inactive, $editkey);
625 echo "</td>\n</tr>\n";
628 //------------------------------------------------------------------------------------------------
630 function customer_branches_list($customer_id, $name, $selected_id=null,
631 $spec_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
634 $sql = "SELECT branch_code, branch_ref FROM ".TB_PREF."cust_branch
635 WHERE debtor_no=" . db_escape($customer_id)." ";
638 set_editor('branch', $name, $editkey);
640 $where = $enabled ? array("inactive = 0") : array();
641 $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
644 'order' => array('branch_ref'),
645 'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
646 'spec_id' => ALL_TEXT,
647 'select_submit'=> $submit_on_change,
648 'sel_hint' => _('Select customer branch'),
649 'editlink' => $editkey ? add_edit_combo('branch') : false
653 //------------------------------------------------------------------------------------------------
655 function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null,
656 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
659 echo "<td>$label</td>\n";
661 echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled,
662 $submit_on_change, $editkey);
666 function customer_branches_list_row($label, $customer_id, $name, $selected_id=null,
667 $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false)
669 echo "<tr><td class='label'>$label</td>";
670 customer_branches_list_cells(null, $customer_id, $name, $selected_id,
671 $all_option, $enabled, $submit_on_change, $editkey);
675 //------------------------------------------------------------------------------------------------
677 function locations_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
680 $sql = "SELECT loc_code, location_name, inactive FROM ".TB_PREF."locations WHERE fixed_asset=".(int)$fixed_asset;
682 return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name',
684 'spec_option' => $all_option === true ? _("All Locations") : $all_option,
685 'spec_id' => ALL_TEXT,
686 'select_submit'=> $submit_on_change
690 function locations_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
693 echo "<td>$label</td>\n";
695 echo locations_list($name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
699 function locations_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $fixed_asset=false)
701 echo "<tr><td class='label'>$label</td>";
702 locations_list_cells(null, $name, $selected_id, $all_option, $submit_on_change, $fixed_asset);
706 //-----------------------------------------------------------------------------------------------
708 function currencies_list($name, $selected_id=null, $submit_on_change=false, $exclude_home_curr=false)
710 $sql = "SELECT curr_abrev, currency, inactive FROM ".TB_PREF."currencies";
711 if ($exclude_home_curr)
712 $sql .= " WHERE curr_abrev!='".get_company_currency()."'";
714 // default to the company currency
715 return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency',
717 'select_submit'=> $submit_on_change,
718 'default' => get_company_currency(),
723 function currencies_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
726 echo "<td>$label</td>\n";
728 echo currencies_list($name, $selected_id, $submit_on_change);
732 function currencies_list_row($label, $name, $selected_id=null, $submit_on_change=false)
734 echo "<tr><td class='label'>$label</td>";
735 currencies_list_cells(null, $name, $selected_id, $submit_on_change);
739 //---------------------------------------------------------------------------------------------------
741 function fiscalyears_list($name, $selected_id=null, $submit_on_change=false)
744 $sql = "SELECT * FROM ".TB_PREF."fiscal_year";
746 // default to the company current fiscal year
748 return combo_input($name, $selected_id, $sql, 'id', '',
751 'default' => get_company_pref('f_year'),
752 'format' => '_format_fiscalyears',
753 'select_submit'=> $submit_on_change,
758 function _format_fiscalyears($row)
760 return sql2date($row[1]) . " - " . sql2date($row[2])
761 . " " . ($row[3] ? _('Closed') : _('Active'));
764 function fiscalyears_list_cells($label, $name, $selected_id=null)
767 echo "<td>$label</td>\n";
769 echo fiscalyears_list($name, $selected_id);
773 function fiscalyears_list_row($label, $name, $selected_id=null)
775 echo "<tr><td class='label'>$label</td>";
776 fiscalyears_list_cells(null, $name, $selected_id);
779 //------------------------------------------------------------------------------------
781 function dimensions_list($name, $selected_id=null, $no_option=false, $showname=' ',
782 $submit_on_change=false, $showclosed=false, $showtype=1)
784 $sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM ".TB_PREF."dimensions";
787 'order' => 'reference',
788 'spec_option'=>$no_option ? $showname : false,
790 'select_submit'=> $submit_on_change,
795 $options['where'][] = "closed=0";
797 $options['where'][] = "type_=".db_escape($showtype);
799 return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
802 function dimensions_list_cells($label, $name, $selected_id=null, $no_option=false, $showname=null,
803 $showclosed=false, $showtype=0, $submit_on_change=false)
806 echo "<td>$label</td>\n";
808 echo dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
812 function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, $showname=null,
813 $showclosed=false, $showtype=0, $submit_on_change=false)
815 echo "<tr><td class='label'>$label</td>";
816 dimensions_list_cells(null, $name, $selected_id, $no_option, $showname,
817 $showclosed, $showtype, $submit_on_change);
821 //---------------------------------------------------------------------------------------------------
823 function stock_items_list($name, $selected_id=null, $all_option=false,
824 $submit_on_change=false, $opts=array(), $editkey = false, $type = "stock")
826 $sql = "SELECT stock_id, s.description, c.description, shipper.shipper_name, s.inactive, s.editable
827 FROM ".TB_PREF."stock_master s
828 LEFT JOIN ".TB_PREF."shippers shipper ON shipper.shipper_id=s.shipper_id
829 LEFT JOIN ".TB_PREF."stock_category c ON s.category_id=c.category_id";
831 if (isset($opts['shipping']) && $opts['shipping'])
832 $where[] = "mb_flag='T'";
833 elseif (isset($opts['fixed_asset']) && $opts['fixed_asset'])
834 $where[] = "mb_flag='F'";
836 $where[] = "NOT mb_flag IN('F','T')";
839 set_editor('item', $name, $editkey);
841 $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
844 'format' => '_format_stock_items',
845 'spec_option' => $all_option===true ? _("All Items") : $all_option,
846 'spec_id' => ALL_TEXT,
847 'search_box' => true,
848 'search' => array("stock_id", "c.description","s.description"),
849 'search_submit' => get_company_pref('no_item_list') != 0 && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']),
851 'select_submit'=> $submit_on_change,
853 'order' => (isset($opts['shipping']) && $opts['shipping']) ? array('shipper.shipper_name','stock_id'): array('c.description','stock_id'),
854 'editlink' => $editkey ? add_edit_combo('item') : false,
862 function _format_stock_items($row)
864 return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
867 function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false,
868 $submit_on_change=false, $all=false, $editkey = false, $opts= array())
870 if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
871 $editor_item = 'fa_item';
873 $editor_item = 'item';
876 // set_editor($editor_item, $name, $editkey);
879 echo "<td>$label</td>\n";
882 // $opts = array_merge($options, array('cells'=>true, 'show_inactive'=>$all, 'new_icon' => $editkey ? 'item' : false));
884 // echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, $opts);
886 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
887 array_merge(array('cells'=>true, 'show_inactive'=>$all), $opts), $editkey);
891 function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
894 stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
898 //---------------------------------------------------------------------------------------------------
900 // Select item via foreign code.
902 function sales_items_list($name, $selected_id=null, $all_option=false,
903 $submit_on_change=false, $type='', $opts=array())
906 $sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
907 i.inactive, if(count(*)>1, '0', s.editable) as editable
909 ".TB_PREF."stock_master s,
910 ".TB_PREF."item_codes i
912 ".TB_PREF."stock_category c
913 ON i.category_id=c.category_id
914 WHERE i.stock_id=s.stock_id
915 AND NOT mb_flag IN('F','T')";
918 if ($type == 'local') { // exclude foreign codes
919 $sql .= " AND !i.is_foreign";
920 } elseif ($type == 'kits') { // sales kits
921 $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
923 $sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
924 $sql .= " GROUP BY i.item_code";
926 return combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description',
929 'format' => '_format_stock_items',
930 'spec_option' => $all_option===true ? _("All Items") : $all_option,
931 'spec_id' => ALL_TEXT,
932 'search_box' => true,
933 'search' => array("i.item_code", "c.description", "i.description"),
934 'search_submit' => get_company_pref('no_item_list')!=0,
936 'select_submit'=> $submit_on_change,
938 'order' => array('c.description','i.item_code'),
941 ), $opts), $type == 'kits' ? $type : "stock_sales" );
944 function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false)
947 set_editor('item', $name, $editkey);
950 echo "<td>$label</td>\n";
951 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
952 '', array('cells'=>true, 'max'=>50)); // maximum is set to 50 and not default 255.
955 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
957 return sales_items_list($name, $selected_id, $all_option, $submit_on_change,
958 'kits', array('cells'=>false, 'editable' => false));
961 function sales_local_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false)
965 echo "<td class='label'>$label</td>\n";
967 echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
968 'local', array('cells'=>false, 'editable' => false));
971 //------------------------------------------------------------------------------------
973 function stock_manufactured_items_list($name, $selected_id=null,
974 $all_option=false, $submit_on_change=false)
976 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
977 array('where'=>array("mb_flag= 'M'")), false, "stock_manufactured");
980 function stock_manufactured_items_list_cells($label, $name, $selected_id=null,
981 $all_option=false, $submit_on_change=false)
984 echo "<td>$label</td>\n";
986 echo stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
990 function stock_manufactured_items_list_row($label, $name, $selected_id=null,
991 $all_option=false, $submit_on_change=false)
993 echo "<tr><td class='label'>$label</td>";
994 stock_manufactured_items_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
997 //------------------------------------------------------------------------------------
999 function stock_component_items_list($name, $parent_stock_id, $selected_id=null,
1000 $all_option=false, $submit_on_change=false, $editkey = false)
1002 $parent = db_escape($parent_stock_id);
1003 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1004 array('where'=>array("stock_id != $parent"), 'parent'=> $parent_stock_id), $editkey, "component");
1008 function stock_component_items_list_cells($label, $name, $parent_stock_id,
1009 $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false)
1012 echo "<td>$label</td>\n";
1013 $parent = db_escape($parent_stock_id);
1014 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1015 array('where'=>array("stock_id != '$parent_stock_id'"), 'cells'=>true, 'parent'=> $parent_stock_id), $editkey, "component");
1017 //------------------------------------------------------------------------------------
1019 function stock_costable_items_list($name, $selected_id=null,
1020 $all_option=false, $submit_on_change=false)
1022 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1023 array('where'=>array("mb_flag!='D'")), false, "stock_costable");
1026 function stock_costable_items_list_cells($label, $name, $selected_id=null,
1027 $all_option=false, $submit_on_change=false)
1030 echo "<td>$label</td>\n";
1031 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1032 array('where'=>array("mb_flag!='D'"), 'cells'=>true), false, "stock_costable");
1035 //------------------------------------------------------------------------------------
1036 function stock_purchasable_items_list($name, $selected_id=null,
1037 $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
1039 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1040 array('where'=>array("NOT no_purchase", "mb_flag!='F'"),
1041 'show_inactive'=>$all), $editkey, "stock_purchased");
1044 // This helper is used in PO/GRN/PI entry and supports editable descriptions.
1046 function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
1047 $all_option=false, $submit_on_change=false, $editkey=false)
1050 echo "<td>$label</td>\n";
1051 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1052 array('where'=>array("NOT no_purchase"),
1054 'cells'=>true), $editkey);
1057 //------------------------------------------------------------------------------------
1059 function shipping_methods_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
1061 return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1062 array('type'=>1, 'shipping'=>true, 'category' => false, 'search_box'=>false, 'search_sumbit' => false),
1063 false, false);//, "shipping_methods");
1066 function shipping_methods_list_cells($label, $name, $selected_id=null,
1067 $all_option=false, $submit_on_change=false)
1070 echo "<td>$label</td>\n";
1072 echo shipping_methods_list($name, $selected_id, $all_option, $submit_on_change);
1076 function shipping_methods_list_row($label, $name, $selected_id=null,
1077 $all_option=false, $submit_on_change=false)
1079 echo "<tr><td class='label'>$label</td>";
1080 shipping_methods_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
1084 //------------------------------------------------------------------------------------
1086 function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true, $all=true)
1088 global $stock_types;
1090 $options = $stock_types;
1093 unset($options['T']);
1094 unset($options['F']);
1098 echo "<td class='label'>$label</td>\n";
1101 echo array_selector($name, $selected_id, $options,
1103 'select_submit'=> true,
1104 'disabled' => !$enabled)
1106 echo "</td></tr>\n";
1109 function stock_units_list_row($label, $name, $value=null, $enabled=true)
1111 $result = get_all_item_units();
1114 echo "<td class='label'>$label</td>\n";
1117 while($unit = db_fetch($result))
1118 $units[$unit['abbr']] = $unit['name'];
1120 echo array_selector($name, $value, $units, array( 'disabled' => !$enabled) );
1122 echo "</td></tr>\n";
1125 //------------------------------------------------------------------------------------
1127 function stock_purchasable_fa_list_cells($label, $name, $selected_id=null, $all_option=false,
1128 $submit_on_change=false, $all=false, $editkey = false, $exclude_items = array())
1130 // Check if a fixed asset has been bought.
1131 $where_opts[] = "stock_id NOT IN
1132 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1134 // exclude items currently on the order.
1135 foreach($exclude_items as $item) {
1136 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1138 $where_opts[] = "mb_flag='F'";
1140 echo stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change, $all, $editkey,
1141 array('fixed_asset' => true, 'where' => $where_opts));
1144 function stock_disposable_fa_list($name, $selected_id=null,
1145 $all_option=false, $submit_on_change=false)
1147 // Check if a fixed asset has been bought....
1148 $where_opts[] = "stock_id IN
1149 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1150 // ...but has not been disposed or sold already.
1151 $where_opts[] = "stock_id NOT IN
1152 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1154 $where_opts[] = "mb_flag='F'";
1156 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1157 array('fixed_asset' => true, 'where' => $where_opts));
1160 function stock_disposable_fa_list_cells($label, $name, $selected_id=null,
1161 $all_option=false, $submit_on_change=false, $exclude_items = array())
1163 // Check if a fixed asset has been bought....
1164 $where_opts[] = "stock_id IN
1165 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1166 // ...but has not been disposed or sold already.
1167 $where_opts[] = "stock_id NOT IN
1168 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1170 $where_opts[] = "mb_flag='F'";
1172 foreach($exclude_items as $item) {
1173 $where_opts[] = "stock_id != ".db_escape($item->stock_id);
1177 echo "<td>$label</td>\n";
1178 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1179 array('fixed_asset' => true, 'cells'=>true, 'where' => $where_opts));
1182 function stock_depreciable_fa_list_cells($label, $name, $selected_id=null,
1183 $all_option=false, $submit_on_change=false)
1186 // Check if a fixed asset has been bought....
1187 $where_opts[] = "stock_id IN
1188 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE type=".ST_SUPPRECEIVE." AND qty!=0 )";
1189 // ...but has not been disposed or sold already.
1190 $where_opts[] = "stock_id NOT IN
1191 ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
1193 $year = get_current_fiscalyear();
1194 $begin = date2sql(add_months(sql2date($year['begin']), -1));
1195 $end = date2sql(add_months(sql2date($year['end']), -1));
1197 // check if current fiscal year
1198 $where_opts[] = "depreciation_date <= '".$end."'";
1199 $where_opts[] = "depreciation_date >= '".$begin."'";
1201 $where_opts[] = "material_cost > 0";
1202 $where_opts[] = "mb_flag='F'";
1205 echo "<td>$label</td>\n";
1206 echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
1207 array('fixed_asset' => true, 'where' => $where_opts, 'cells'=>true));
1210 //------------------------------------------------------------------------------------
1212 function tax_types_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
1214 $sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM ".TB_PREF."tax_types";
1216 return combo_input($name, $selected_id, $sql, 'id', 'name',
1218 'spec_option' => $none_option,
1219 'spec_id' => ALL_NUMERIC,
1220 'select_submit'=> $submit_on_change,
1225 function tax_types_list_cells($label, $name, $selected_id=null, $none_option=false,
1226 $submit_on_change=false)
1229 echo "<td>$label</td>\n";
1231 echo tax_types_list($name, $selected_id, $none_option, $submit_on_change);
1235 function tax_types_list_row($label, $name, $selected_id=null, $none_option=false,
1236 $submit_on_change=false)
1238 echo "<tr><td class='label'>$label</td>";
1239 tax_types_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1243 //------------------------------------------------------------------------------------
1245 function tax_groups_list($name, $selected_id=null,
1246 $none_option=false, $submit_on_change=false)
1248 $sql = "SELECT id, name, inactive FROM ".TB_PREF."tax_groups";
1250 return combo_input($name, $selected_id, $sql, 'id', 'name',
1253 'spec_option' => $none_option,
1254 'spec_id' => ALL_NUMERIC,
1255 'select_submit'=> $submit_on_change,
1260 function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1263 echo "<td>$label</td>\n";
1265 echo tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
1269 function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1271 echo "<tr><td class='label'>$label</td>";
1272 tax_groups_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1276 //------------------------------------------------------------------------------------
1278 function item_tax_types_list($name, $selected_id=null, $show_inactive = false)
1280 $sql ="SELECT id, name FROM ".TB_PREF."item_tax_types";
1281 if (!$show_inactive)
1282 $sql .= " WHERE !inactive";
1284 return combo_input($name, $selected_id, $sql, 'id', 'name', array('order' => 'id') );
1287 function item_tax_types_list_cells($label, $name, $selected_id=null, $show_inactive = false)
1290 echo "<td>$label</td>\n";
1292 echo item_tax_types_list($name, $selected_id, $show_inactive);
1296 function item_tax_types_list_row($label, $name, $selected_id=null, $show_inactive = false)
1298 echo "<tr><td class='label'>$label</td>";
1299 item_tax_types_list_cells(null, $name, $selected_id, $show_inactive);
1303 //------------------------------------------------------------------------------------
1305 function shippers_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
1307 $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
1308 return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name',
1309 array('order'=>array('shipper_name'),
1310 'spec_option' => $none_option,
1311 'spec_id' => ALL_NUMERIC,
1312 'select_submit'=> $submit_on_change,
1317 function shippers_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1320 echo "<td>$label</td>\n";
1322 echo shippers_list($name, $selected_id, $none_option, $submit_on_change);
1326 function shippers_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
1328 echo "<tr><td class='label'>$label</td>";
1329 shippers_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
1333 //-------------------------------------------------------------------------------------
1335 function sales_persons_list($name, $selected_id=null, $spec_opt=false)
1337 $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman";
1338 return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name',
1339 array('order'=>array('salesman_name'),
1340 'spec_option' => $spec_opt,
1341 'spec_id' => ALL_NUMERIC));
1344 function sales_persons_list_cells($label, $name, $selected_id=null, $spec_opt=false)
1347 echo "<td>$label</td>\n";
1349 echo sales_persons_list($name, $selected_id, $spec_opt);
1353 function sales_persons_list_row($label, $name, $selected_id=null, $spec_opt=false)
1355 echo "<tr><td class='label'>$label</td>";
1356 sales_persons_list_cells(null, $name, $selected_id, $spec_opt);
1360 //------------------------------------------------------------------------------------
1362 function sales_areas_list($name, $selected_id=null, $special_option=false)
1364 $sql = "SELECT area_code, description, inactive FROM ".TB_PREF."areas";
1365 return combo_input($name, $selected_id, $sql, 'area_code', 'description',
1366 array('spec_option' => $special_option===true ? ' ' : $special_option,
1367 'order' => 'description', 'spec_id' => 0));
1370 function sales_areas_list_cells($label, $name, $selected_id=null, $special_option=false)
1373 echo "<td>$label</td>\n";
1375 echo sales_areas_list($name, $selected_id, $special_option);
1379 function sales_areas_list_row($label, $name, $selected_id=null, $special_option=false)
1381 echo "<tr><td class='label'>$label</td>";
1382 sales_areas_list_cells(null, $name, $selected_id, $special_option);
1386 //------------------------------------------------------------------------------------
1388 function sales_groups_list($name, $selected_id=null, $special_option=false)
1390 $sql = "SELECT id, description, inactive FROM ".TB_PREF."groups";
1391 return combo_input($name, $selected_id, $sql, 'id', 'description', array(
1392 'spec_option' => $special_option===true ? ' ' : $special_option,
1393 'order' => 'description', 'spec_id' => 0,
1397 function sales_groups_list_cells($label, $name, $selected_id=null, $special_option=false)
1400 echo "<td>$label</td>\n";
1402 echo sales_groups_list($name, $selected_id, $special_option);
1406 function sales_groups_list_row($label, $name, $selected_id=null, $special_option=false)
1408 echo "<tr><td class='label'>$label</td>";
1409 sales_groups_list_cells(null, $name, $selected_id, $special_option);
1413 //------------------------------------------------------------------------------------
1415 function _format_template_items($row)
1417 return ($row[0] . " - " . _("Amount") . " ".$row[1]);
1420 function templates_list($name, $selected_id=null, $special_option=false)
1422 $sql = "SELECT sorder.order_no, Sum(line.unit_price*line.quantity*(1-line.discount_percent)) AS OrderValue
1423 FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."sales_order_details as line
1424 WHERE sorder.order_no = line.order_no AND sorder.type = 1 GROUP BY line.order_no";
1425 return combo_input($name, $selected_id, $sql, 'order_no', 'OrderValue', array(
1426 'format' => '_format_template_items',
1427 'spec_option' => $special_option===true ? ' ' : $special_option,
1428 'order' => 'order_no', 'spec_id' => 0,
1432 function templates_list_cells($label, $name, $selected_id=null, $special_option=false)
1435 echo "<td>$label</td>\n";
1437 echo templates_list($name, $selected_id, $special_option);
1441 function templates_list_row($label, $name, $selected_id=null, $special_option=false)
1443 echo "<tr><td class='label'>$label</td>";
1444 templates_list_cells(null, $name, $selected_id, $special_option);
1448 //------------------------------------------------------------------------------------
1450 function workorders_list($name, $selected_id=null)
1452 $sql = "SELECT id, wo_ref FROM ".TB_PREF."workorders WHERE closed=0";
1453 return combo_input($name, $selected_id, $sql, 'id', 'wo_ref', array());
1456 function workorders_list_cells($label, $name, $selected_id=null)
1459 echo "<td>$label</td>\n";
1461 echo workorders_list($name, $selected_id);
1465 function workorders_list_row($label, $name, $selected_id=null)
1467 echo "<tr><td class='label'>$label</td>";
1468 workorders_list_cells(null, $name, $selected_id);
1472 //------------------------------------------------------------------------------------
1474 function payment_terms_list($name, $selected_id=null)
1476 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1477 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms', array());
1480 function payment_terms_list_cells($label, $name, $selected_id=null)
1483 echo "<td>$label</td>\n";
1485 echo payment_terms_list($name, $selected_id);
1489 function payment_terms_list_row($label, $name, $selected_id=null)
1491 echo "<tr><td class='label'>$label</td>";
1492 payment_terms_list_cells(null, $name, $selected_id);
1496 //------------------------------------------------------------------------------------
1498 function credit_status_list($name, $selected_id=null)
1500 $sql ="SELECT id, reason_description, inactive FROM ".TB_PREF."credit_status";
1501 return combo_input($name, $selected_id, $sql, 'id', 'reason_description', array());
1504 function credit_status_list_cells($label, $name, $selected_id=null)
1507 echo "<td>$label</td>\n";
1509 echo credit_status_list($name, $selected_id);
1513 function credit_status_list_row($label, $name, $selected_id=null)
1515 echo "<tr><td class='label'>$label</td>";
1516 credit_status_list_cells(null, $name, $selected_id);
1520 //-----------------------------------------------------------------------------------------------
1522 function sales_types_list($name, $selected_id=null, $submit_on_change=false, $special_option=false)
1524 $sql = "SELECT id, sales_type, inactive FROM ".TB_PREF."sales_types";
1526 return combo_input($name, $selected_id, $sql, 'id', 'sales_type',
1528 'spec_option' => $special_option===true ? _("All Sales Types") : $special_option,
1530 'select_submit'=> $submit_on_change,
1534 function sales_types_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1537 echo "<td>$label</td>\n";
1539 echo sales_types_list($name, $selected_id, $submit_on_change, $special_option);
1543 function sales_types_list_row($label, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1545 echo "<tr><td class='label'>$label</td>";
1546 sales_types_list_cells(null, $name, $selected_id, $submit_on_change, $special_option);
1550 //-----------------------------------------------------------------------------------------------
1552 function _format_date($row)
1554 return sql2date($row['reconciled']);
1557 function bank_reconciliation_list($account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1559 $sql = "SELECT reconciled, reconciled FROM ".TB_PREF."bank_trans
1560 WHERE bank_act=".db_escape($account)." AND reconciled IS NOT NULL
1561 GROUP BY reconciled";
1562 return combo_input($name, $selected_id, $sql, 'id', 'reconciled',
1564 'spec_option' => $special_option,
1565 'format' => '_format_date',
1567 'select_submit'=> $submit_on_change
1571 function bank_reconciliation_list_cells($label,$account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1574 echo "<td>$label</td>\n";
1576 echo bank_reconciliation_list($account, $name, $selected_id, $submit_on_change, $special_option);
1580 function bank_reconciliation_list_row($label, $account, $name, $selected_id=null, $submit_on_change=false, $special_option=false)
1583 bank_reconciliation_list_cells($label, $account, $name, $selected_id, $submit_on_change, $special_option);
1587 //-----------------------------------------------------------------------------------------------
1589 function workcenter_list($name, $selected_id=null, $all_option=false)
1592 $sql = "SELECT id, name, inactive FROM ".TB_PREF."workcentres";
1594 return combo_input($name, $selected_id, $sql, 'id', 'name',
1596 'spec_option' =>$all_option===true ? _("All Suppliers") : $all_option,
1597 'spec_id' => ALL_TEXT,
1601 function workcenter_list_cells($label, $name, $selected_id=null, $all_option=false)
1603 default_focus($name);
1605 echo "<td>$label</td>\n";
1607 echo workcenter_list($name, $selected_id, $all_option);
1611 function workcenter_list_row($label, $name, $selected_id=null, $all_option=false)
1613 echo "<tr><td class='label'>$label</td>";
1614 workcenter_list_cells(null, $name, $selected_id, $all_option);
1618 //-----------------------------------------------------------------------------------------------
1620 function bank_accounts_list($name, $selected_id=null, $submit_on_change=false, $spec_option=false)
1622 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1623 FROM ".TB_PREF."bank_accounts";
1625 return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1627 'format' => '_format_add_curr',
1628 'select_submit'=> $submit_on_change,
1629 'spec_option' => $spec_option,
1635 function bank_accounts_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1638 echo "<td>$label</td>\n";
1640 echo bank_accounts_list($name, $selected_id, $submit_on_change);
1644 function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1646 echo "<tr><td class='label'>$label</td>";
1647 bank_accounts_list_cells(null, $name, $selected_id, $submit_on_change);
1650 //-----------------------------------------------------------------------------------------------
1652 function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
1655 $sql = "SELECT id, bank_account_name, bank_curr_code, inactive
1656 FROM ".TB_PREF."bank_accounts
1657 WHERE account_type=".BT_CASH;
1660 echo "<tr><td class='label'>$label</td>\n";
1662 echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
1664 'spec_option' => $all_option,
1665 'spec_id' => ALL_TEXT,
1666 'format' => '_format_add_curr',
1667 'select_submit'=> $submit_on_change,
1670 echo "</td></tr>\n";
1672 //-----------------------------------------------------------------------------------------------
1674 function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $submit_on_change=false)
1676 $sql = "SELECT id, pos_name, inactive FROM ".TB_PREF."sales_pos";
1678 default_focus($name);
1681 echo "<td class='label'>$label</td>\n";
1684 echo combo_input($name, $selected_id, $sql, 'id', 'pos_name',
1686 'select_submit'=> $submit_on_change,
1688 'spec_option' =>$spec_option,
1690 'order'=> array('pos_name')
1692 echo "</td></tr>\n";
1695 //-----------------------------------------------------------------------------------------------
1696 // Payment type selector for current user.
1698 function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1700 $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
1702 if ($category == PM_CASH) // only cash
1703 $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
1704 elseif ($category == PM_CREDIT) // only delayed payments
1705 $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
1706 elseif (!$prepayments)
1707 $sql .= " WHERE days_before_due>=0";
1709 return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
1711 'select_submit'=> $submit_on_change,
1717 function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
1720 echo "<td class='label'>$label</td>\n";
1723 echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
1727 //-----------------------------------------------------------------------------------------------
1729 function class_list($name, $selected_id=null, $submit_on_change=false)
1731 $sql = "SELECT cid, class_name FROM ".TB_PREF."chart_class";
1733 return combo_input($name, $selected_id, $sql, 'cid', 'class_name',
1735 'select_submit'=> $submit_on_change,
1741 function class_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
1744 echo "<td>$label</td>\n";
1746 echo class_list($name, $selected_id, $submit_on_change);
1750 function class_list_row($label, $name, $selected_id=null, $submit_on_change=false)
1752 echo "<tr><td class='label'>$label</td>";
1753 class_list_cells(null, $name, $selected_id, $submit_on_change);
1757 //-----------------------------------------------------------------------------------------------
1758 function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $type=false)
1760 $where_opts = array();
1761 if (in_array($type, array('F', 'T')))
1762 $where_opts[] = "dflt_mb_flag=".db_escape($type);
1764 $where_opts[] = "NOT dflt_mb_flag IN('F','T')";
1766 $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
1767 return combo_input($name, $selected_id, $sql, 'category_id', 'description',
1768 array('order'=>'category_id',
1769 'spec_option' => $spec_opt,
1771 'select_submit'=> $submit_on_change,
1773 'where' => $where_opts,
1777 function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $type=false)
1780 echo "<td>$label</td>\n";
1782 echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $type);
1786 function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $type=false)
1788 echo "<tr><td class='label'>$label</td>";
1789 stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $type);
1793 //-----------------------------------------------------------------------------------------------
1794 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1796 $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 "
1797 .TB_PREF."stock_fa_class c LEFT JOIN ".TB_PREF."stock_fa_class p ON c.parent_id=p.fa_class_id";
1799 return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
1800 array('order'=>'c.fa_class_id',
1801 'spec_option' => $spec_opt,
1803 'select_submit'=> $submit_on_change,
1805 'search_box' => true,
1806 'search' => array("c.fa_class_id"),
1807 'search_submit' => false,
1811 'category' => 'class',
1815 function fixed_asset_classes_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
1817 echo "<tr><td class='label'>$label</td>";
1819 echo fixed_asset_classes_list($name, $selected_id, $spec_opt, $submit_on_change);
1820 echo "</td></tr>\n";
1823 //-----------------------------------------------------------------------------------------------
1825 function gl_account_types_list($name, $selected_id=null, $all_option=false, $all=true)
1828 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
1830 return combo_input($name, $selected_id, $sql, 'id', 'name',
1832 'format' => '_format_account',
1833 'order' => array('class_id', 'id', 'parent'),
1834 'spec_option' =>$all_option,
1835 'spec_id' => ALL_TEXT
1839 function gl_account_types_list_cells($label, $name, $selected_id=null, $all_option=false, $all=false)
1842 echo "<td>$label</td>\n";
1844 echo gl_account_types_list($name, $selected_id, $all_option, $all);
1848 function gl_account_types_list_row($label, $name, $selected_id=null, $all_option=false, $all=false)
1850 echo "<tr><td class='label'>$label</td>";
1851 gl_account_types_list_cells(null, $name, $selected_id, $all_option,
1856 //-----------------------------------------------------------------------------------------------
1857 function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=false,
1858 $cells=false, $all_option=false, $submit_on_change=false, $all=false, $type_id=false)
1860 if ($skip_bank_accounts)
1861 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1862 FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
1863 ."LEFT JOIN ".TB_PREF."bank_accounts acc "
1864 ."ON chart.account_code=acc.account_code
1865 WHERE acc.account_code IS NULL
1866 AND chart.account_type=type.id";
1868 $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
1869 FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
1870 WHERE chart.account_type=type.id";
1871 if ($type_id ) $sql .= " AND chart.account_type=".db_escape($type_id);
1872 $account = ($skip_bank_accounts ? "account2" : "account");
1873 return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
1875 'format' => '_format_account',
1876 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option,
1879 'order' => array('type.class_id','type.id','account_code'),
1880 'search_box' => $cells,
1881 'search_submit' => false,
1885 'select_submit'=> $submit_on_change,
1888 'show_inactive' => $all
1892 function _format_account($row)
1894 return $row[0] . " " . $row[1];
1897 function gl_all_accounts_list_cells($label, $name, $selected_id=null,
1898 $skip_bank_accounts=false, $cells=false, $all_option=false,
1899 $submit_on_change=false, $all=false, $type_id=false)
1902 echo "<td>$label</td>\n";
1904 echo gl_all_accounts_list($name, $selected_id,
1905 $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all, $type_id);
1909 function gl_all_accounts_list_row($label, $name, $selected_id=null,
1910 $skip_bank_accounts=false, $cells=false, $all_option=false, $type_id=false)
1912 echo "<tr><td class='label'>$label</td>";
1913 gl_all_accounts_list_cells(null, $name, $selected_id,
1914 $skip_bank_accounts, $cells, $all_option, $type_id);
1918 function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1921 $items['0'] = strlen($name_no) ? $name_no : _("No");
1922 $items['1'] = strlen($name_yes) ? $name_yes : _("Yes");
1924 return array_selector($name, $selected_id, $items,
1926 'select_submit'=> $submit_on_change,
1927 'async' => false ) ); // FIX?
1930 function yesno_list_cells($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1933 echo "<td>$label</td>\n";
1935 echo yesno_list($name, $selected_id, $name_yes, $name_no, $submit_on_change);
1939 function yesno_list_row($label, $name, $selected_id=null, $name_yes="", $name_no="", $submit_on_change=false)
1941 echo "<tr><td class='label'>$label</td>";
1942 yesno_list_cells(null, $name, $selected_id, $name_yes, $name_no, $submit_on_change);
1946 //------------------------------------------------------------------------------------------------
1948 function languages_list($name, $selected_id=null, $all_option=false)
1950 global $installed_languages;
1954 $items[''] = $all_option;
1955 foreach ($installed_languages as $lang)
1956 $items[$lang['code']] = $lang['name'];
1957 return array_selector($name, $selected_id, $items);
1960 function languages_list_cells($label, $name, $selected_id=null, $all_option=false)
1963 echo "<td>$label</td>\n";
1965 echo languages_list($name, $selected_id, $all_option);
1969 function languages_list_row($label, $name, $selected_id=null, $all_option=false)
1971 echo "<tr><td class='label'>$label</td>";
1972 languages_list_cells(null, $name, $selected_id, $all_option);
1976 //------------------------------------------------------------------------------------------------
1978 function bank_account_types_list($name, $selected_id=null)
1980 global $bank_account_types;
1982 return array_selector($name, $selected_id, $bank_account_types);
1985 function bank_account_types_list_cells($label, $name, $selected_id=null)
1988 echo "<td>$label</td>\n";
1990 echo bank_account_types_list($name, $selected_id);
1994 function bank_account_types_list_row($label, $name, $selected_id=null)
1996 echo "<tr><td class='label'>$label</td>";
1997 bank_account_types_list_cells(null, $name, $selected_id);
2001 //------------------------------------------------------------------------------------------------
2002 function payment_person_types_list($name, $selected_id=null, $submit_on_change=false)
2004 global $payment_person_types;
2007 foreach ($payment_person_types as $key=>$type)
2009 if ($key != PT_WORKORDER)
2010 $items[$key] = $type;
2012 return array_selector($name, $selected_id, $items,
2013 array( 'select_submit'=> $submit_on_change ) );
2016 function payment_person_types_list_cells($label, $name, $selected_id=null, $related=null)
2019 echo "<td>$label</td>\n";
2021 echo payment_person_types_list($name, $selected_id, $related);
2025 function payment_person_types_list_row($label, $name, $selected_id=null, $related=null)
2027 echo "<tr><td class='label'>$label</td>";
2028 payment_person_types_list_cells(null, $name, $selected_id, $related);
2032 //------------------------------------------------------------------------------------------------
2034 function wo_types_list($name, $selected_id=null)
2036 global $wo_types_array;
2038 return array_selector($name, $selected_id, $wo_types_array,
2039 array( 'select_submit'=> true, 'async' => true ) );
2042 function wo_types_list_row($label, $name, $selected_id=null)
2044 echo "<tr><td class='label'>$label</td><td>\n";
2045 echo wo_types_list($name, $selected_id);
2046 echo "</td></tr>\n";
2049 //------------------------------------------------------------------------------------------------
2051 function dateformats_list_row($label, $name, $value=null)
2055 echo "<tr><td class='label'>$label</td>\n<td>";
2056 echo array_selector( $name, $value, $SysPrefs->dateformats );
2057 echo "</td></tr>\n";
2060 function dateseps_list_row($label, $name, $value=null)
2064 echo "<tr><td class='label'>$label</td>\n<td>";
2065 echo array_selector( $name, $value, $SysPrefs->dateseps );
2066 echo "</td></tr>\n";
2069 function thoseps_list_row($label, $name, $value=null)
2073 echo "<tr><td class='label'>$label</td>\n<td>";
2074 echo array_selector( $name, $value, $SysPrefs->thoseps );
2075 echo "</td></tr>\n";
2078 function decseps_list_row($label, $name, $value=null)
2082 echo "<tr><td class='label'>$label</td>\n<td>";
2083 echo array_selector( $name, $value, $SysPrefs->decseps );
2084 echo "</td></tr>\n";
2087 function themes_list_row($label, $name, $value=null)
2089 global $path_to_root;
2091 $path = $path_to_root.'/themes/';
2093 $themedir = opendir($path);
2094 while(false !== ($fname = readdir($themedir)))
2096 if($fname!='.' && $fname!='..' && $fname!='CVS' && is_dir($path.$fname))
2098 $themes[$fname] = $fname;
2103 echo "<tr><td class='label'>$label</td>\n<td>";
2104 echo array_selector( $name, $value, $themes );
2105 echo "</td></tr>\n";
2108 function pagesizes_list_row($label, $name, $value=null)
2113 foreach ($SysPrefs->pagesizes as $pz)
2116 echo "<tr><td class='label'>$label</td>\n<td>";
2117 echo array_selector( $name, $value, $items );
2118 echo "</td></tr>\n";
2121 function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=false, $exclude=array())
2123 global $systypes_array;
2125 // emove non-voidable transactions if needed
2126 $systypes = array_diff_key($systypes_array, array_flip($exclude));
2127 return array_selector($name, $value, $systypes,
2129 'spec_option'=> $spec_opt,
2130 'spec_id' => ALL_NUMERIC,
2131 'select_submit'=> $submit_on_change,
2137 function systypes_list_cells($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2140 echo "<td>$label</td>\n";
2142 echo systypes_list($name, $value, false, $submit_on_change, $exclude);
2146 function systypes_list_row($label, $name, $value=null, $submit_on_change=false, $exclude=array())
2148 echo "<tr><td class='label'>$label</td>";
2149 systypes_list_cells(null, $name, $value, $submit_on_change, $exclude);
2153 function journal_types_list_cells($label, $name, $value=null, $submit_on_change=false)
2155 global $systypes_array;
2158 echo "<td>$label</td>\n";
2161 $items = $systypes_array;
2163 // exclude quotes, orders and dimensions
2164 foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl)
2165 unset($items[$excl]);
2167 echo array_selector($name, $value, $items,
2169 'spec_option'=> _("All"),
2171 'select_submit'=> $submit_on_change,
2178 function cust_allocations_list_cells($label, $name, $selected=null, $submit_on_change=false)
2185 ALL_TEXT=>_("All Types"),
2186 '1'=> _("Sales Invoices"),
2187 '2'=> _("Unsettled transactions"),
2188 '3' => _("Payments"),
2189 '4' => _("Credit Notes"),
2190 '5' => _("Delivery Notes")
2192 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2196 function supp_allocations_list_cell($name, $selected=null)
2201 ALL_TEXT=>_("All Types"),
2202 '1'=> _("Invoices"),
2203 '2'=> _("Overdue Invoices"),
2204 '3' => _("Payments"),
2205 '4' => _("Credit Notes"),
2206 '5' => _("Overdue Credit Notes")
2208 echo array_selector($name, $selected, $allocs);
2212 function supp_transactions_list_cell($name, $selected=null, $submit_on_change=false)
2217 ALL_TEXT=>_("All Types"),
2219 '1'=> _("Invoices"),
2220 '2'=> _("Unsettled transactions"),
2221 '3' => _("Payments"),
2222 '4' => _("Credit Notes"),
2223 '5' => _("Overdue Credit Notes")
2226 echo array_selector($name, $selected, $allocs, array('select_submit'=> $submit_on_change));
2230 function policy_list_cells($label, $name, $selected=null)
2235 echo array_selector($name, $selected,
2236 array( '' => _("Automatically put balance on back order"),
2237 'CAN' => _("Cancel any quantites not delivered")) );
2241 function policy_list_row($label, $name, $selected=null)
2243 echo "<tr><td class='label'>$label</td>";
2244 policy_list_cells(null, $name, $selected);
2248 function credit_type_list_cells($label, $name, $selected=null, $submit_on_change=false)
2253 echo array_selector($name, $selected,
2254 array( 'Return' => _("Items Returned to Inventory Location"),
2255 'WriteOff' => _("Items Written Off")),
2256 array( 'select_submit'=> $submit_on_change ) );
2260 function credit_type_list_row($label, $name, $selected=null, $submit_on_change=false)
2262 echo "<tr><td class='label'>$label</td>";
2263 credit_type_list_cells(null, $name, $selected, $submit_on_change);
2267 function number_list($name, $selected, $from, $to, $no_option=false)
2270 for ($i = $from; $i <= $to; $i++)
2273 return array_selector($name, $selected, $items,
2274 array( 'spec_option' => $no_option,
2275 'spec_id' => ALL_NUMERIC) );
2278 function number_list_cells($label, $name, $selected, $from, $to, $no_option=false)
2283 echo number_list($name, $selected, $from, $to, $no_option);
2287 function number_list_row($label, $name, $selected, $from, $to, $no_option=false)
2289 echo "<tr><td class='label'>$label</td>";
2290 echo number_list_cells(null, $name, $selected, $from, $to, $no_option);
2294 function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
2295 $submit_on_change=true)
2297 $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
2298 ." GROUP BY profile";
2299 $result = db_query($sql, 'cannot get all profile names');
2300 $profiles = array();
2301 while($myrow=db_fetch($result)) {
2302 $profiles[$myrow['profile']] = $myrow['profile'];
2307 echo "<td class='label'>$label</td>\n";
2310 echo array_selector($name, $selected_id, $profiles,
2311 array( 'select_submit'=> $submit_on_change,
2312 'spec_option'=>$spec_opt,
2316 echo "</td></tr>\n";
2319 function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
2321 static $printers; // query only once for page display
2324 $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
2325 $result = db_query($sql, 'cannot get all printers');
2326 $printers = array();
2327 while($myrow=db_fetch($result)) {
2328 $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
2331 return array_selector($name, $selected_id, $printers,
2332 array( 'select_submit'=> $submit_on_change,
2333 'spec_option'=>$spec_opt,
2338 //------------------------------------------------------------------------------------------------
2340 function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
2343 $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
2345 $sql .= " WHERE type=$type";
2347 return combo_input($name, $selected_id, $sql, 'id', 'description',
2350 'order' => 'description',
2351 'select_submit'=> $submit_on_change,
2357 function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
2360 echo "<td>$label</td>\n";
2362 echo quick_entries_list($name, $selected_id, $type, $submit_on_change);
2366 function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
2368 echo "<tr><td class='label'>$label</td>";
2369 quick_entries_list_cells(null, $name, $selected_id, $type, $submit_on_change);
2374 function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2376 global $quick_actions;
2378 echo "<tr><td class='label'>$label</td><td>";
2379 echo array_selector($name, $selected_id, $quick_actions,
2381 'select_submit'=> $submit_on_change
2383 echo "</td></tr>\n";
2386 function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2388 global $quick_entry_types;
2390 echo "<tr><td class='label'>$label</td><td>";
2391 echo array_selector($name, $selected_id, $quick_entry_types,
2393 'select_submit'=> $submit_on_change
2395 echo "</td></tr>\n";
2398 function record_status_list_row($label, $name) {
2399 return yesno_list_row($label, $name, null, _('Inactive'), _('Active'));
2402 function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2404 global $class_types;
2406 echo "<tr><td class='label'>$label</td><td>";
2407 echo array_selector($name, $selected_id, $class_types,
2409 'select_submit'=> $submit_on_change
2411 echo "</td></tr>\n";
2414 //------------------------------------------------------------------------------------------------
2416 function security_roles_list($name, $selected_id=null, $new_item=false, $submit_on_change=false,
2417 $show_inactive = false)
2420 $sql = "SELECT id, role, inactive FROM ".TB_PREF."security_roles";
2422 return combo_input($name, $selected_id, $sql, 'id', 'description',
2424 'spec_option'=>$new_item ? _("New role") : false,
2426 'select_submit'=> $submit_on_change,
2427 'show_inactive' => $show_inactive
2431 function security_roles_list_cells($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2432 $show_inactive = false)
2435 echo "<td>$label</td>\n";
2437 echo security_roles_list($name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2441 function security_roles_list_row($label, $name, $selected_id=null, $new_item=false, $submit_on_change=false,
2442 $show_inactive = false)
2444 echo "<tr><td class='label'>$label</td>";
2445 security_roles_list_cells(null, $name, $selected_id, $new_item, $submit_on_change, $show_inactive);
2449 function tab_list_row($label, $name, $selected_id=null)
2451 global $installed_extensions;
2454 foreach ($_SESSION['App']->applications as $app) {
2455 $tabs[$app->id] = access_string($app->name, true);
2458 echo "<td class='label'>$label</td><td>\n";
2459 echo array_selector($name, $selected_id, $tabs);
2460 echo "</td></tr>\n";
2463 //-----------------------------------------------------------------------------------------------
2465 function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = false)
2468 global $path_to_root;
2469 include_once($path_to_root . "/admin/db/tags_db.inc");
2470 $results = get_tags($type, $all);
2472 while ($tag = db_fetch($results))
2473 $tags[$tag['id']] = $tag['name'];
2475 if (!isset($tags)) {
2476 $tags[''] = $all ? _("No tags defined.") : _("No active tags defined.");
2479 return array_selector($name, null, $tags,
2482 'height' => $height,
2483 'spec_option'=> $spec_opt,
2488 function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2491 echo "<td>$label</td>\n";
2493 echo tag_list($name, $height, $type, $mult, $all, $spec_opt);
2498 function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false)
2500 echo "<tr><td class='label'>$label</td>";
2501 tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt);
2505 //---------------------------------------------------------------------------------------------
2506 // List of sets of active extensions
2508 function extset_list($name, $value=null, $submit_on_change=false)
2510 global $db_connections;
2513 foreach ($db_connections as $comp)
2514 $items[] = sprintf(_("Activated for '%s'"), $comp['name']);
2515 return array_selector( $name, $value, $items,
2517 'spec_option'=> _("Available and/or installed"),
2519 'select_submit'=> $submit_on_change,
2524 function crm_category_types_list($name, $selected_id=null, $filter=array(), $submit_on_change=true)
2527 $sql = "SELECT id, name, type, inactive FROM ".TB_PREF."crm_categories";
2532 if (@$filter['class']) {
2533 $where[] = 'type='.db_escape($filter['class']);
2536 if (@$filter['subclass']) $where[] = 'action='.db_escape($filter['subclass']);
2537 if (@$filter['entity']) $where[] = 'entity_id='.db_escape($filter['entity']);
2538 if (@$filter['multi']) { // contact category selector for person
2542 return combo_input($name, $selected_id, $sql, 'id', 'name',
2545 'height' => $multi ? 5:1,
2546 'category' => $groups,
2547 'select_submit'=> $submit_on_change,
2553 function crm_category_types_list_row($label, $name, $selected_id=null, $filter=array(), $submit_on_change=true)
2555 echo "<tr><td class='label'>$label</td><td>";
2556 echo crm_category_types_list($name, $selected_id, $filter, $submit_on_change);
2557 echo "</td></tr>\n";
2560 function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false)
2562 global $pterm_types;
2564 echo "<tr><td class='label'>$label</td><td>";
2565 echo array_selector($name, $selected_id, $pterm_types,
2567 'select_submit'=> $submit_on_change
2569 echo "</td></tr>\n";
2572 function coa_list_row($label, $name, $value=null)
2574 global $path_to_root, $installed_extensions;
2576 $path = $path_to_root.'/sql/';
2578 $sqldir = opendir($path);
2579 while (false !== ($fname = readdir($sqldir)))
2581 if (is_file($path.$fname) && substr($fname,-4)=='.sql' && @($fname[2] == '_'))
2583 $ext = array_search_value($fname, $installed_extensions, 'sql');
2585 $descr = $ext['name'];
2586 } elseif ($fname == 'en_US-new.sql') { // two standard COAs
2587 $descr = _("Standard new company American COA (4 digit)");
2588 } elseif ($fname == 'en_US-demo.sql') {
2589 $descr = _("Standard American COA (4 digit) with demo data");
2593 $coas[$fname] = $descr;
2598 echo "<tr><td class='label'>$label</td>\n<td>";
2599 echo array_selector( $name, $value, $coas );
2600 echo "</td></tr>\n";
2603 function payment_services($name)
2605 global $payment_services;
2607 $services = (object)array_combine(array_keys($payment_services), array_keys($payment_services));
2609 return array_selector($name, null, $services, array(
2610 'spec_option'=> _("No payment Link"),
2615 function vat_category_list_row($label, $name, $selected_id=null, $enabled = true, $submit_on_change=false, $show_obsolete=false)
2617 global $vat_categories;
2621 echo "<td class='label'>$label</td>\n";
2624 $categories = $vat_categories;
2625 if (!$show_obsolete)
2626 unset($categories[VC_MEDIA]); // obsolete category removed to avoid mistake usage
2628 echo array_selector($name, $selected_id, $categories,
2629 array( 'select_submit'=> $submit_on_change,
2630 'disabled' => !$enabled));
2631 echo "</td></tr>\n";
2635 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
2637 global $tax_algorithms;
2639 return array_selector($name, $value, $tax_algorithms,
2641 'select_submit'=> $submit_on_change,
2647 function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
2650 echo "<td>$label</td>\n";
2652 echo tax_algorithm_list($name, $value, $submit_on_change);
2656 function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
2658 echo "<tr><td class='label'>$label</td>";
2659 tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
2663 function refline_list($name, $type, $value=null, $spec_option=false)
2665 $sql = "SELECT id, prefix, inactive FROM ".TB_PREF."reflines";
2670 $where = array('`trans_type`='.db_escape($type));
2672 return combo_input($name, $value, $sql, 'id', 'prefix',
2674 'order'=>array('prefix'),
2675 'spec_option' => $spec_option,
2679 'select_submit' => true,
2684 function refline_list_row($label, $name, $type, $selected_id=null, $spec_option=false)
2688 echo "<td class='label'>$label</td>\n";
2691 echo refline_list($name, $type, $selected_id, $spec_option);
2692 echo "</td></tr>\n";
2696 //----------------------------------------------------------------------------------------------
2698 function subledger_list($name, $account, $selected_id=null)
2701 $type = is_subledger_account($account);
2706 $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name
2708 .TB_PREF."debtors_master d,"
2709 .TB_PREF."cust_branch c
2710 WHERE d.debtor_no=c.debtor_no AND NOT d.inactive AND c.receivables_account=".db_escape($account);
2712 $sql = "SELECT supplier_id as id, supp_ref as name
2714 .TB_PREF."suppliers s
2715 WHERE NOT s.inactive AND s.payable_account=".db_escape($account);
2717 $mode = get_company_pref('no_customer_list');
2719 return combo_input($name, $selected_id, $sql, 'id', 'name',
2727 function subledger_list_cells($label, $name, $account, $selected_id=null)
2730 echo "<td>$label</td>\n";
2732 echo subledger_list($name, $account, $selected_id);
2736 function subledger_list_row($label, $name, $selected_id=null, $all_option = false,
2737 $submit_on_change=false, $show_inactive=false, $editkey = false)
2739 echo "<tr><td class='label'>$label</td><td nowrap>";
2740 echo subledger_list($name, $account, $selected_id);
2741 echo "</td>\n</tr>\n";
2744 function accounts_type_list_row($label, $name, $selected_id=null)
2748 echo "<td class='label'>$label</td>\n";
2750 $sel = array(_("Numeric"), _("Alpha Numeric"), _("ALPHA NUMERIC"));
2751 echo array_selector($name, $selected_id, $sel);
2752 echo "</td></tr>\n";
2755 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
2758 $sql = " SELECT user_id, IF(real_name = '', user_id, real_name) FROM ".TB_PREF."users";
2761 echo "<td>$label</td>\n";
2764 echo combo_input($name, $selected_id, $sql, 'user_id', 'real_name',
2766 'spec_option' => $spec_opt===true ?_("All users") : $spec_opt,
2768 'order' => 'real_name',
2769 'select_submit'=> $submit_on_change,
2776 function collations_list_row($label, $name, $selected_id=null)
2778 global $supported_collations;
2782 echo "<td class='label'>$label</td>\n";
2785 echo array_selector($name, $selected_id, $supported_collations,
2786 array('select_submit'=> false) );
2787 echo "</td></tr>\n";
2790 function vat_areas_list_row($label, $name, $selected_id=null, $enabled=true)
2792 global $tax_area_types;
2796 echo "<td class='label'>$label</td>\n";
2799 echo array_selector($name, $selected_id, $tax_area_types,
2801 'select_submit'=> true,
2802 'disabled' => !$enabled) );
2803 echo "</td></tr>\n";