forked from cambell-prince/frontaccounting-theme-bootstrap
/
ListRendererBootstrap.php
2093 lines (1820 loc) · 74.4 KB
/
ListRendererBootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace FA\Theme\Bootstrap;
class ListRendererBootstrap extends \ListRenderer
{
// ----------------------------------------------------------------------------
// Universal sql combo generator
// $sql must return selector values and selector texts in columns 0 & 1
// Options are merged with defaults.
function combo_input($name, $selected_id, $sql, $valfield, $namefield, $options = null)
{
global $Ajax;
$opts = array( // default options
'where' => array(), // additional constraints
'order' => $namefield, // list sort order
// special option parameters
'spec_option' => false, // option text or false
'spec_id' => 0, // option id
// submit on select parameters
'default' => '', // default value when $_POST is not set
'multi' => false, // multiple select
'select_submit' => false, // submit on select: true/false
'async' => true, // select update via ajax (true) vs _page_body reload
// search box parameters
'sel_hint' => null,
'search_box' => false, // name or true/false
'type' => 0, // type of extended selector:
// 0 - with (optional) visible search box, search by fragment inside id
// 1 - with hidden search box, search by option text
// 2 - with (optional) visible search box, search by fragment at the start of id
// 3 - TODO reverse: box with hidden selector available via enter; this
// would be convenient for optional ad hoc adding of new item
'search_submit' => true, // search submit button: true/false
'size' => 8, // size and max of box tag
'max' => 50,
'height' => false, // number of lines in select box
'cells' => false, // combo displayed as 2 <td></td> cells
'search' => array(), // sql field names to search
'format' => null, // format functions for regular options
'disabled' => false,
'box_hint' => null, // box/selectors hints; null = std see below
'category' => false, // category column name or false
'show_inactive' => false, // show inactive records.
'editable' => false // false, or length of editable entry field
);
// ------ merge options with defaults ----------
if ($options != null)
$opts = array_merge($opts, $options);
if (! is_array($opts['where']))
$opts['where'] = array(
$opts['where']
);
$search_box = $opts['search_box'] === true ? '_' . $name . '_edit' : $opts['search_box'];
// select content filtered by search field:
$search_submit = $opts['search_submit'] === true ? '_' . $name . '_button' : $opts['search_submit'];
// select set by select content field
$search_button = $opts['editable'] ? '_' . $name . '_button' : ($search_box ? $search_submit : false);
$select_submit = $opts['select_submit'];
$spec_id = $opts['spec_id'];
$spec_option = $opts['spec_option'];
if ($opts['type'] == 0) {
$by_id = true;
$class = 'combo';
} elseif ($opts['type'] == 1) {
$by_id = false;
$class = 'combo2';
} else {
$by_id = true;
$class = 'combo3';
}
$class .= ' form-control';
$disabled = $opts['disabled'] ? "disabled" : '';
$multi = $opts['multi'];
if (! count($opts['search'])) {
$opts['search'] = array(
$by_id ? $valfield : $namefield
);
}
if ($opts['sel_hint'] === null)
$opts['sel_hint'] = $by_id || $search_box == false ? '' : _('Press Space tab for search pattern entry');
if ($opts['box_hint'] === null)
$opts['box_hint'] = $search_box && $search_submit != false ? ($by_id ? _('Enter code fragment to search or * for all') : _('Enter description fragment to search or * for all')) : '';
if ($selected_id == null) {
$selected_id = get_post($name, (string) $opts['default']);
}
if (! is_array($selected_id))
$selected_id = array(
(string) $selected_id
); // code is generalized for multiple selection support
$txt = get_post($search_box);
$rel = '';
$limit = '';
if (isset($_POST['_' . $name . '_update'])) { // select list or search box change
if ($by_id)
$txt = $_POST[$name];
if (! $opts['async'])
$Ajax->activate('_page_body');
else
$Ajax->activate($name);
}
if (isset($_POST[$search_button])) {
if (! $opts['async'])
$Ajax->activate('_page_body');
else
$Ajax->activate($name);
}
if ($search_box) {
// search related sql modifications
$rel = "rel='$search_box'"; // set relation to list
if ($opts['search_submit']) {
if (isset($_POST[$search_button])) {
$selected_id = array(); // ignore selected_id while search
if (! $opts['async'])
$Ajax->activate('_page_body');
else
$Ajax->activate($name);
}
if ($txt == '') {
if ($spec_option === false && $selected_id == array())
$limit = ' LIMIT 1';
else
$opts['where'][] = $valfield . "=" . db_escape(get_post($name, $spec_id));
} else if ($txt != '*') {
foreach ($opts['search'] as $i => $s)
$opts['search'][$i] = $s . " LIKE " . db_escape(($class == 'combo3' ? '' : '%') . $txt . '%');
$opts['where'][] = '(' . implode($opts['search'], ' OR ') . ')';
}
}
}
// sql completion
if (count($opts['where'])) {
$where = strpos($sql, 'WHERE') == false ? ' WHERE ' : ' AND ';
$where .= '(' . implode($opts['where'], ' AND ') . ')';
$group_pos = strpos($sql, 'GROUP BY');
if ($group_pos) {
$group = substr($sql, $group_pos);
$sql = substr($sql, 0, $group_pos) . $where . ' ' . $group;
} else {
$sql .= $where;
}
}
if ($opts['order'] != false) {
if (! is_array($opts['order']))
$opts['order'] = array(
$opts['order']
);
$sql .= ' ORDER BY ' . implode(',', $opts['order']);
}
$sql .= $limit;
// ------ make selector ----------
$selector = $first_opt = '';
$first_id = false;
$found = false;
$lastcat = null;
$edit = false;
// if($name=='stock_id') display_notification('<pre>'.print_r($_POST, true).'</pre>');
// if($name=='curr_default') display_notification($opts['search_submit']);
if ($result = db_query($sql)) {
while ($contact_row = db_fetch($result)) {
$value = $contact_row[0];
$descr = $opts['format'] == null ? $contact_row[1] : call_user_func($opts['format'], $contact_row);
$sel = '';
if (get_post($search_button) && ($txt == $value)) {
$selected_id[] = $value;
}
if (in_array((string) $value, $selected_id, true)) {
$sel = 'selected';
$found = $value;
$edit = $opts['editable'] && $contact_row['editable'] && (@$_POST[$search_box] == $value) ? $contact_row[1] : false; // get non-formatted description
if ($edit)
break; // selected field is editable - abandon list construction
}
// show selected option even if inactive
if (! $opts['show_inactive'] && @$contact_row['inactive'] && $sel === '') {
continue;
} else
$optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
if ($first_id === false) {
$first_id = $value;
$first_opt = $descr;
}
$cat = $contact_row[$opts['category']];
if ($opts['category'] !== false && $cat != $lastcat) {
$selector .= "<optgroup label='" . $cat . "'>\n";
$lastcat = $cat;
}
$selector .= "<option $sel $optclass value='$value'>$descr</option>\n";
}
db_free_result($result);
}
// Prepend special option.
if ($spec_option !== false) { // if special option used - add it
$first_id = $spec_id;
$first_opt = $spec_option;
// }
// if($first_id !== false) {
$sel = $found === false ? 'selected' : '';
$optclass = @$contact_row['inactive'] ? "class='inactive'" : '';
$selector = "<option $sel value='$first_id'>$first_opt</option>\n" . $selector;
}
if ($found === false) {
$selected_id = array(
$first_id
);
}
$_POST[$name] = $multi ? $selected_id : $selected_id[0];
$selector = "<select autocomplete='off' " . ($multi ? "multiple" : '') . ($opts['height'] !== false ? ' size="' . $opts['height'] . '"' : '') . "$disabled name='$name" . ($multi ? '[]' : '') . "' class='$class' title='" . $opts['sel_hint'] . "' $rel>" . $selector . "</select>\n";
if ($by_id && ($search_box != false || $opts['editable'])) {
// on first display show selector list
if (isset($_POST[$search_box]) && $opts['editable'] && $edit) {
$selector = "<input type='hidden' name='$name' value='" . $_POST[$name] . "'>" . "<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='" . $opts['editable'] . "' maxlength='" . $opts['max'] . "' $rel value='$edit'>\n";
set_focus($name . '_text'); // prevent lost focus
} else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
set_focus($name); // prevent lost focus
if (! $opts['editable'])
$txt = $found;
$Ajax->addUpdate($name, $search_box, $txt ? $txt : '');
}
$Ajax->addUpdate($name, "_{$name}_sel", $selector);
// span for select list/input field update
$selector = "<span id='_{$name}_sel'>" . $selector . "</span>\n";
// if selectable or editable list is used - add select button
if ($select_submit != false || $search_button) {
global $_select_button;
// button class selects form reload/ajax selector update
$selector .= sprintf($_select_button, $disabled, user_theme(), (fallback_mode() ? '' : 'display:none;'), '_' . $name . '_update') . "\n";
}
// ------ make combo ----------
$edit_entry = '';
if ($search_box != false) {
$edit_entry = "<input $disabled type='text' name='$search_box' id='$search_box' size='" . $opts['size'] . "' maxlength='" . $opts['max'] . "' value='$txt' class='$class' rel='$name' autocomplete='off' title='" . $opts['box_hint'] . "'" . (! fallback_mode() && ! $by_id ? " style=display:none;" : '') . ">\n";
if ($search_submit != false || $opts['editable']) {
global $_search_button;
$edit_entry .= sprintf($_search_button, $disabled, user_theme(), (fallback_mode() ? '' : 'display:none;'), $search_submit ? $search_submit : "_{$name}_button") . "\n";
}
}
default_focus(($search_box && $by_id) ? $search_box : $name);
if ($opts['cells']) {
return array($edit_entry, $selector);
}
return $selector;
}
/*
* Helper function. Returns true if selector $name is subject to update.
*/
function list_updated($name)
{
return isset($_POST['_' . $name . '_update']) || isset($_POST['_' . $name . '_button']);
}
// ----------------------------------------------------------------------------------------------
// Universal array combo generator
// $items is array of options 'value' => 'description'
// Options is reduced set of combo_selector options and is merged with defaults.
function array_selector($name, $selected_id, $items, $options = null)
{
global $Ajax;
$opts = array( // default options
'spec_option' => false, // option text or false
'spec_id' => 0, // option id
'select_submit' => false, // submit on select: true/false
'async' => true, // select update via ajax (true) vs _page_body reload
'default' => '', // default value when $_POST is not set
'multi' => false, // multiple select
// search box parameters
'height' => false, // number of lines in select box
'sel_hint' => null,
'disabled' => false
);
// ------ merge options with defaults ----------
if ($options != null)
$opts = array_merge($opts, $options);
$select_submit = $opts['select_submit'];
$spec_id = $opts['spec_id'];
$spec_option = $opts['spec_option'];
$disabled = $opts['disabled'] ? "disabled" : '';
$multi = $opts['multi'];
if ($selected_id == null) {
$selected_id = get_post($name, $opts['default']);
}
if (! is_array($selected_id))
$selected_id = array(
(string) $selected_id
); // code is generalized for multiple selection support
if (isset($_POST['_' . $name . '_update'])) {
if (! $opts['async'])
$Ajax->activate('_page_body');
else
$Ajax->activate($name);
}
// ------ make selector ----------
$selector = $first_opt = '';
$first_id = false;
$found = false;
// if($name=='SelectStockFromList') display_error($sql);
foreach ($items as $value => $descr) {
$sel = '';
if (in_array((string) $value, $selected_id, true)) {
$sel = 'selected';
$found = $value;
}
if ($first_id === false) {
$first_id = $value;
$first_opt = $descr;
}
$selector .= "<option $sel value='$value'>$descr</option>\n";
}
if ($first_id !== false) {
$sel = ($found === $first_id) || ($found === false && ($spec_option === false)) ? "selected='selected'" : '';
$selector = sprintf($first_opt, $sel) . $selector;
}
// Prepend special option.
if ($spec_option !== false) { // if special option used - add it
$first_id = $spec_id;
$first_opt = $spec_option;
$sel = $found === false ? 'selected' : '';
$selector = "<option $sel value='$spec_id'>$spec_option</option>\n" . $selector;
}
if ($found === false) {
$selected_id = array(
$first_id
);
}
$_POST[$name] = $multi ? $selected_id : $selected_id[0];
$selector = "<select autocomplete='off' " . ($multi ? "multiple" : '') . ($opts['height'] !== false ? ' size="' . $opts['height'] . '"' : '') . "$disabled name='$name" . ($multi ? '[]' : '') . "' class='combo form-control' title='" . $opts['sel_hint'] . "'>" . $selector . "</select>\n";
$Ajax->addUpdate($name, "_{$name}_sel", $selector);
$selector = "<span id='_{$name}_sel'>" . $selector . "</span>\n";
if ($select_submit != false) { // if submit on change is used - add select button
global $_select_button;
$selector .= sprintf($_select_button, $disabled, user_theme(), (fallback_mode() ? '' : 'display:none;'), '_' . $name . '_update') . "\n";
}
default_focus($name);
return $selector;
}
// ----------------------------------------------------------------------------------------------
function _format_add_curr($row)
{
static $company_currency;
if ($company_currency == null) {
$company_currency = get_company_currency();
}
return $row[1] . ($row[2] == $company_currency ? '' : (" - " . $row[2]));
}
function add_edit_combo($type)
{
global $path_to_root, $popup_editors, $use_icon_for_editkey;
if (! isset($use_icon_for_editkey) || $use_icon_for_editkey == 0)
return "";
// Derive theme path
$theme_path = $path_to_root . '/themes/' . user_theme();
$key = $popup_editors[$type][1];
$onclick = "onclick=\"javascript:callEditor($key); return false;\"";
$img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/" . ICON_EDIT . "'>";
return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>";
}
function supplier_list($name, $selected_id = null, $spec_option = false, $submit_on_change = false, $all = false, $editkey = false)
{
global $all_items;
$sql = "SELECT supplier_id, supp_ref, curr_code, inactive FROM " . TB_PREF . "suppliers ";
$mode = get_company_pref('no_supplier_list');
if ($editkey)
set_editor('supplier', $name, $editkey);
$ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name', array(
'format' => '_format_add_curr',
'order' => array(
'supp_ref'
),
'search_box' => $mode != 0,
'type' => 1,
'search' => array(
"supp_ref",
"supp_name",
"gst_no"
),
'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option,
'spec_id' => $all_items,
'select_submit' => $submit_on_change,
'async' => false,
'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') : _('Select supplier'),
'show_inactive' => $all
));
if ($editkey)
$ret .= add_edit_combo('supplier');
return $ret;
}
function supplier_list_cells($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false, $all = false, $editkey = false)
{
$controlAsString = supplier_list($name, $selected_id, $all_option, $submit_on_change, $all, $editkey);
View::get()->addControl(View::controlFromRenderedString(View::CONTROL_COMBO, $label, $controlAsString));
}
function supplier_list_row($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false, $all = false, $editkey = false)
{
View::get()->layoutHintRow();
$controlAsString = supplier_list($name, $selected_id, $all_option, $submit_on_change, $all, $editkey);
View::get()->addControl(View::controlFromRenderedString(View::CONTROL_COMBO, $label, $controlAsString));
}
// ----------------------------------------------------------------------------------------------
function customer_list($name, $selected_id = null, $spec_option = false, $submit_on_change = false, $show_inactive = false, $editkey = false)
{
global $all_items;
$sql = "SELECT debtor_no, debtor_ref, curr_code, inactive FROM " . TB_PREF . "debtors_master ";
$mode = get_company_pref('no_customer_list');
if ($editkey)
set_editor('customer', $name, $editkey);
$ret = $this->combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref', array(
'format' => '_format_add_curr',
'order' => array(
'debtor_ref'
),
'search_box' => $mode != 0,
'type' => 1,
'size' => 20,
'search' => array(
"debtor_ref",
"name",
"tax_id"
),
'spec_option' => $spec_option === true ? _("All Customers") : $spec_option,
'spec_id' => $all_items,
'select_submit' => $submit_on_change,
'async' => false,
'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') : _('Select customer'),
'show_inactive' => $show_inactive
));
if ($editkey)
$ret .= $this->add_edit_combo('customer');
return $ret;
}
function customer_list_cells($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false, $show_inactive = false, $editkey = false)
{
$controlAsString = customer_list($name, $selected_id, $all_option, $submit_on_change, $show_inactive, $editkey);
View::get()->addControl(View::controlFromRenderedString(View::CONTROL_COMBO, $label, $controlAsString));
}
function customer_list_row($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false, $show_inactive = false, $editkey = false)
{
global $path_to_root;
View::get()->layoutHintRow();
$controlAsString = customer_list($name, $selected_id, $all_option, $submit_on_change, $show_inactive, $editkey);
View::get()->addControl(View::controlFromRenderedString(View::CONTROL_COMBO, $label, $controlAsString));
}
// ------------------------------------------------------------------------------------------------
function customer_branches_list($customer_id, $name, $selected_id = null, $spec_option = true, $enabled = true, $submit_on_change = false, $editkey = false)
{
global $all_items;
$sql = "SELECT branch_code, branch_ref FROM " . TB_PREF . "cust_branch
WHERE debtor_no=" . db_escape($customer_id) . " ";
if ($editkey)
set_editor('branch', $name, $editkey);
$where = $enabled ? array(
"disable_trans = 0"
) : array();
$ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref', array(
'where' => $where,
'order' => array(
'branch_ref'
),
'spec_option' => $spec_option === true ? _('All branches') : $spec_option,
'spec_id' => $all_items,
'select_submit' => $submit_on_change,
'sel_hint' => _('Select customer branch')
));
if ($editkey) {
$ret .= add_edit_combo('branch');
}
return $ret;
}
// ------------------------------------------------------------------------------------------------
function customer_branches_list_cells($label, $customer_id, $name, $selected_id = null, $all_option = true, $enabled = true, $submit_on_change = false, $editkey = false)
{
$controls = $this->customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change, $editkey);
View::get()->addComboControls($label, $controls);
}
function customer_branches_list_row($label, $customer_id, $name, $selected_id = null, $all_option = true, $enabled = true, $submit_on_change = false, $editkey = false)
{
View::get()->layoutHintRow();
$this->customer_branches_list_cells($label, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change, $editkey);
}
// ------------------------------------------------------------------------------------------------
function locations_list($name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
global $all_items;
$sql = "SELECT loc_code, location_name, inactive FROM " . TB_PREF . "locations";
return combo_input($name, $selected_id, $sql, 'loc_code', 'location_name', array(
'spec_option' => $all_option === true ? _("All Locations") : $all_option,
'spec_id' => $all_items,
'select_submit' => $submit_on_change
));
}
function locations_list_cells($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
$controlAsString = locations_list($name, $selected_id, $all_option, $submit_on_change);
View::get()->addControl(View::controlFromRenderedString(View::CONTROL_COMBO, $label, $controlAsString));
}
function locations_list_row($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
View::get()->layoutHintRow();
$this->locations_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
}
// -----------------------------------------------------------------------------------------------
function currencies_list($name, $selected_id = null, $submit_on_change = false)
{
$sql = "SELECT curr_abrev, currency, inactive FROM " . TB_PREF . "currencies";
// default to the company currency
return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency', array(
'select_submit' => $submit_on_change,
'default' => get_company_currency(),
'async' => false
));
}
function currencies_list_cells($label, $name, $selected_id = null, $submit_on_change = false)
{
$controls = currencies_list($name, $selected_id, $submit_on_change);
View::get()->addComboControls($label, $controls);
}
function currencies_list_row($label, $name, $selected_id = null, $submit_on_change = false)
{
View::get()->layoutHintRow();
$this->currencies_list_cells($label, $name, $selected_id, $submit_on_change);
}
// ---------------------------------------------------------------------------------------------------
function fiscalyears_list($name, $selected_id = null, $submit_on_change = false)
{
$sql = "SELECT * FROM " . TB_PREF . "fiscal_year";
// default to the company current fiscal year
return combo_input($name, $selected_id, $sql, 'id', '', array(
'order' => 'begin',
'default' => get_company_pref('f_year'),
'format' => '_format_fiscalyears',
'select_submit' => $submit_on_change,
'async' => false
));
}
function _format_fiscalyears($row)
{
return sql2date($row[1]) . " - " . sql2date($row[2]) . " " . ($row[3] ? _('Closed') : _('Active')) . "</option>\n";
}
function fiscalyears_list_cells($label, $name, $selected_id = null)
{
$controls = fiscalyears_list($name, $selected_id);
View::get()->addComboControls($label, $controls);
}
function fiscalyears_list_row($label, $name, $selected_id = null)
{
View::get()->layoutHintRow();
$this->fiscalyears_list_cells($label, $name, $selected_id);
}
// ------------------------------------------------------------------------------------
function dimensions_list($name, $selected_id = null, $no_option = false, $showname = ' ', $submit_on_change = false, $showclosed = false, $showtype = 1)
{
$sql = "SELECT id, CONCAT(reference,' ',name) as ref FROM " . TB_PREF . "dimensions";
$options = array(
'order' => 'reference',
'spec_option' => $no_option ? $showname : false,
'spec_id' => 0,
'select_submit' => $submit_on_change,
'async' => false
);
if (! $showclosed)
$options['where'][] = "closed=0";
if ($showtype)
$options['where'][] = "type_=" . db_escape($showtype);
return combo_input($name, $selected_id, $sql, 'id', 'ref', $options);
}
function dimensions_list_cells($label, $name, $selected_id = null, $no_option = false, $showname = null, $showclosed = false, $showtype = 0, $submit_on_change = false)
{
$controls = dimensions_list($name, $selected_id, $no_option, $showname, $submit_on_change, $showclosed, $showtype);
View::get()->addComboControls($label, $controls);
}
function dimensions_list_row($label, $name, $selected_id = null, $no_option = false, $showname = null, $showclosed = false, $showtype = 0, $submit_on_change = false)
{
View::get()->layoutHintRow();
$this->dimensions_list_cells($label, $name, $selected_id, $no_option, $showname, $showclosed, $showtype, $submit_on_change);
}
// ---------------------------------------------------------------------------------------------------
function stock_items_list($name, $selected_id = null, $all_option = false, $submit_on_change = false, $opts = array(), $editkey = false)
{
global $all_items;
$sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
FROM " . TB_PREF . "stock_master s," . TB_PREF . "stock_category c WHERE s.category_id=c.category_id";
if ($editkey)
set_editor('item', $name, $editkey);
$ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description', array_merge(array(
'format' => '_format_stock_items',
'spec_option' => $all_option === true ? _("All Items") : $all_option,
'spec_id' => $all_items,
'search_box' => true,
'search' => array(
"stock_id",
"c.description",
"s.description"
),
'search_submit' => get_company_pref('no_item_list') != 0,
'size' => 10,
'select_submit' => $submit_on_change,
'category' => 2,
'order' => array(
'c.description',
'stock_id'
)
), $opts));
if ($editkey) {
if ($opts['cells']) {
$ret[1] .= $this->add_edit_combo('item');
} else {
$ret .= $this->add_edit_combo('item');
}
}
return $ret;
}
function _format_stock_items($row)
{
return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1];
}
function stock_items_list_cells($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false, $all = false, $editkey = false)
{
$controls = stock_items_list($name, $selected_id, $all_option, $submit_on_change, array(
'cells' => true,
'show_inactive' => $all
), $editkey);
View::get()->addComboControls($label, $controls);
}
/*
* function stock_items_list_row($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false) {
* echo "<tr>\n"; stock_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change); echo
* "</tr>\n"; }
*/
// ---------------------------------------------------------------------------------------------------
//
// Select item via foreign code.
//
function sales_items_list($name, $selected_id = null, $all_option = false, $submit_on_change = false, $type = '', $opts = array())
{
global $all_items;
// all sales codes
$sql = "SELECT i.item_code, i.description, c.description, count(*)>1 as kit,
i.inactive, if(count(*)>1, '0', s.editable) as editable
FROM
" . TB_PREF . "stock_master s,
" . TB_PREF . "item_codes i
LEFT JOIN
" . TB_PREF . "stock_category c
ON i.category_id=c.category_id
WHERE i.stock_id=s.stock_id";
if ($type == 'local') { // exclude foreign codes
$sql .= " AND !i.is_foreign";
} elseif ($type == 'kits') { // sales kits
$sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id";
}
$sql .= " AND !i.inactive AND !s.inactive AND !s.no_sale";
$sql .= " GROUP BY i.item_code";
return $this->combo_input($name, $selected_id, $sql, 'i.item_code', 'c.description', array_merge(array(
'format' => '_format_stock_items',
'spec_option' => $all_option === true ? _("All Items") : $all_option,
'spec_id' => $all_items,
'search_box' => true,
'search' => array(
"i.item_code",
"c.description",
"i.description"
),
'search_submit' => get_company_pref('no_item_list') != 0,
'size' => 15,
'select_submit' => $submit_on_change,
'category' => 2,
'order' => array(
'c.description',
'i.item_code'
),
'editable' => 30,
'max' => 255
), $opts));
}
function sales_items_list_cells($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false, $editkey = false)
{
if ($editkey)
set_editor('item', $name, $editkey);
$controls = $this->sales_items_list($name, $selected_id, $all_option, $submit_on_change, '', array(
'cells' => true
));
View::get()->addComboControls($label, $controls);
}
function sales_kits_list($name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
return sales_items_list($name, $selected_id, $all_option, $submit_on_change, 'kits', array(
'cells' => false,
'editable' => false
));
}
function sales_local_items_list_row($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
View::get()->layoutHintRow();
$controls = sales_items_list($name, $selected_id, $all_option, $submit_on_change, 'local', array(
'cells' => false,
'editable' => false
));
View::get()->addComboControls($label, $controls);
}
// ------------------------------------------------------------------------------------
function stock_manufactured_items_list($name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
return stock_items_list($name, $selected_id, $all_option, $submit_on_change, array(
'where' => array(
"mb_flag= 'M'"
)
));
}
function stock_manufactured_items_list_cells($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
$controls = stock_manufactured_items_list($name, $selected_id, $all_option, $submit_on_change);
View::get()->addComboControls($label, $controls);
}
function stock_manufactured_items_list_row($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
View::get()->layoutHintRow();
$this->stock_manufactured_items_list_cells($label, $name, $selected_id, $all_option, $submit_on_change);
}
// ------------------------------------------------------------------------------------
function stock_component_items_list($name, $parent_stock_id, $selected_id = null, $all_option = false, $submit_on_change = false, $editkey = false)
{
return stock_items_list($name, $selected_id, $all_option, $submit_on_change, array(
'where' => array(
"stock_id != " . db_escape($parent_stock_id)
)
), $editkey);
}
function stock_component_items_list_cells($label, $name, $parent_stock_id, $selected_id = null, $all_option = false, $submit_on_change = false, $editkey = false)
{
$controls = stock_items_list($name, $selected_id, $all_option, $submit_on_change, array(
'where' => array(
"stock_id != " . db_escape($parent_stock_id)
),
'cells' => true
), $editkey);
View::get()->addComboControls($label, $controls);
}
// ------------------------------------------------------------------------------------
function stock_costable_items_list($name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
return stock_items_list($name, $selected_id, $all_option, $submit_on_change, array(
'where' => array(
"mb_flag!='D'"
)
));
}
function stock_costable_items_list_cells($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false)
{
$controls = stock_items_list($name, $selected_id, $all_option, $submit_on_change, array(
'where' => array(
"mb_flag!='D'"
),
'cells' => true
));
View::get()->addComboControls($label, $controls);
}
// ------------------------------------------------------------------------------------
function stock_purchasable_items_list($name, $selected_id = null, $all_option = false, $submit_on_change = false, $all = false, $editkey = false)
{
return stock_items_list($name, $selected_id, $all_option, $submit_on_change, array(
'where' => array(
"mb_flag!= 'M'"
),
'show_inactive' => $all
), $editkey);
}
//
// This helper is used in PO/GRN/PI entry and supports editable descriptions.
//
function stock_purchasable_items_list_cells($label, $name, $selected_id = null, $all_option = false, $submit_on_change = false, $editkey = false)
{
$controls = stock_items_list($name, $selected_id, $all_option, $submit_on_change, array(
'where' => array(
"mb_flag!= 'M'"
),
'editable' => 30,
'cells' => true
), $editkey);
View::get()->addComboControls($label, $controls);
}
/*
* function stock_purchasable_items_list_row($label, $name, $selected_id=null, $all_option=false,
* $submit_on_change=false, $editkey=false) { echo "<tr><td class='label'>$label</td>";
* stock_purchasable_items_list_cells(null, $name, $selected_id=null, $all_option, $submit_on_change, $editkey);
* echo "</tr>\n"; }
*/
// ------------------------------------------------------------------------------------
function stock_item_types_list_row($label, $name, $selected_id = null, $enabled = true)
{
global $stock_types;
View::get()->layoutHintRow();
$controlAsString = $this->array_selector($name, $selected_id, $stock_types, array(
'select_submit' => true,
'disabled' => ! $enabled
));
View::get()->addControl(View::controlFromRenderedString(View::CONTROL_ARRAY, $label, $controlAsString));
}
function stock_units_list_row($label, $name, $value = null, $enabled = true)
{
View::get()->layoutHintRow();
$result = get_all_item_units();
while ($unit = db_fetch($result))
$units[$unit['abbr']] = $unit['name'];
$controls = array_selector($name, $value, $units, array(
'disabled' => ! $enabled
));
View::get()->addComboControls($label, $controls);
}
// ------------------------------------------------------------------------------------
function tax_types_list($name, $selected_id = null, $none_option = false, $submit_on_change = false)
{
$sql = "SELECT id, CONCAT(name, ' (',rate,'%)') as name FROM " . TB_PREF . "tax_types";
return combo_input($name, $selected_id, $sql, 'id', 'name', array(
'spec_option' => $none_option,
'spec_id' => ALL_NUMERIC,
'select_submit' => $submit_on_change,
'async' => false
));
}
function tax_types_list_cells($label, $name, $selected_id = null, $none_option = false, $submit_on_change = false)
{
$controlAsString = tax_types_list($name, $selected_id, $none_option, $submit_on_change);
View::get()->addControl(View::controlFromRenderedString(View::CONTROL_ARRAY, $label, $controlAsString));
}
function tax_types_list_row($label, $name, $selected_id = null, $none_option = false, $submit_on_change = false)
{
View::get()->layoutHintRow();
$this->tax_types_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
}
// ------------------------------------------------------------------------------------
function tax_groups_list($name, $selected_id = null, $none_option = false, $submit_on_change = false)
{
$sql = "SELECT id, name FROM " . TB_PREF . "tax_groups";
return combo_input($name, $selected_id, $sql, 'id', 'name', array(
'order' => 'id',
'spec_option' => $none_option,
'spec_id' => ALL_NUMERIC,
'select_submit' => $submit_on_change,
'async' => false
));
}
function tax_groups_list_cells($label, $name, $selected_id = null, $none_option = false, $submit_on_change = false)
{
$controlAsString = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
View::get()->addControl(View::controlFromRenderedString(View::CONTROL_ARRAY, $label, $controlAsString));
}
function tax_groups_list_row($label, $name, $selected_id = null, $none_option = false, $submit_on_change = false)
{
View::get()->layoutHintRow();
$this->tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
}
// ------------------------------------------------------------------------------------
function item_tax_types_list($name, $selected_id = null)
{
$sql = "SELECT id, name FROM " . TB_PREF . "item_tax_types";
return combo_input($name, $selected_id, $sql, 'id', 'name', array(
'order' => 'id'
));
}
function item_tax_types_list_cells($label, $name, $selected_id = null)
{
$controls = item_tax_types_list($name, $selected_id);
View::get()->addComboControls($label, $controls);
}
function item_tax_types_list_row($label, $name, $selected_id = null)
{
View::get()->layoutHintRow();
$this->item_tax_types_list_cells($label, $name, $selected_id);
}
// ------------------------------------------------------------------------------------
function shippers_list($name, $selected_id = null)
{
$sql = "SELECT shipper_id, shipper_name, inactive FROM " . TB_PREF . "shippers";
return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array(
'order' => array(
'shipper_name'
)
));
}
function shippers_list_cells($label, $name, $selected_id = null)
{
$controls = shippers_list($name, $selected_id);
View::get()->addComboControls($label, $controls);
}
function shippers_list_row($label, $name, $selected_id = null)
{
View::get()->layoutHintRow();
$this->shippers_list_cells($label, $name, $selected_id);
}