-
Notifications
You must be signed in to change notification settings - Fork 3
/
workshop-view.php
executable file
·1144 lines (998 loc) · 30.6 KB
/
workshop-view.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
<?
#This program is copyright by Andre Coetzee email: ac@main.me
#and is licensed under the GPL v3
#
#
#
#
#Please add yourself to: http://www.accounting-123.com
#Developers, Software Vendors, Support, Accountants, Users
#
#
#The full software license can be found here:
#http://www.accounting-123.com/a.php?a=153/GPLv3
#
#
#
#
#
#
#
#
#
#
#
require ("settings.php");
// Merge get vars with post vars
foreach ($_GET as $key => $val) {
$_POST[$key] = $val;
}
// Decide which function to perform
if (isset($_POST["key"])) {
switch ($_POST["key"]) {
default:
case "display":
$OUTPUT = display();
break;
case "update":
$OUTPUT = update($_POST);
if ($_POST["update"] == "client_collect") {
// Extra quick links
$extra_qlinks = "
<tr class='datacell'>
<td><a href='cust-credit-stockinv.php'>New Invoice</a></td>
</tr>
<tr class='datacell'>
<td><a href='pos-invoice-new.php'>New POS Invoice</a></td>
</tr>
<tr class='datacell'>
<td><a href='nons-invoice-new.php'>New Non Stock Invoice</a></td>
</tr>";
}
break;
case "client_collect":
$OUTPUT = client_collect($_POST);
// Extra quick links
$extra_qlinks = "
<tr class='datacell'>
<td><a href='cust-credit-stockinv.php'>New Invoice</a></td>
</tr>
<tr class='datacell'>
<td><a href='pos-invoice-new.php'>New POS Invoice</a></td>
</tr>
<tr class='datacell'>
<td><a href='nons-invoice-new.php'>New Non Stock Invoice</a></td>
</tr>";
break;
case "status_history":
$OUTPUT = status_history($_POST);
break;
case "edit_notes":
$OUTPUT = edit_notes($_POST);
break;
case "check_in":
$OUTPUT = check_in($_POST);
break;
case "check_out":
$OUTPUT = check_out($_POST);
break;
case "receipt":
receipt($_POST);
break;
case "workshop_report":
$OUTPUT = workshop_report($_POST);
break;
}
} else {
$OUTPUT = display();
}
if (!isset($extra_qlinks)) $extra_qlinks = "";
// Append quick links to each page
$OUTPUT .= "
<p>
<table ".TMPL_tblDflts.">
<tr>
<th>Quick Links</th>
<tr>
<tr class='datacell'>
<td><a href='workshop-add.php'>Add to workshop</td>
</tr>
<tr class='datacell'>
<td><a href='supp-new.php'>Add Supplier<a></td>
</tr>
$extra_qlinks
<tr class='datacell'>
<td><a href='main.php'>Main Menu</a></td>
</tr>
</table>";
require ("template.php");
function display($errors="")
{
global $_POST;
extract($_POST);
// Validate and set variables
require_lib("validate");
$v = new validate;
if (isset($search)) {
$v->isOk($search, "string", 0, 255, "Invalid search string.");
} else {
$search = "";
}
if (isset($search_keysel)) {
$v->isOk($search_keysel, "string", 0, 255, "Invalid search selection.");
} else {
$search_keysel = "";
}
if (isset($offset)) {
$v->isOk($offset, "num", 1, 9, "Invalid offset defined");
} else {
$offset = 0;
}
// If any errors were found, clear the variables and display errors
if ($v->isError()) {
$errarr = $v->getErrors();
foreach ($errarr as $e) {
$errors .= "<li class='err'>$e[msg]</li>";
}
// Clear the variables
$search = "";
$search_keysel = "";
}
// Search query
if (!empty($search) && $search_keysel != "cusname" && $search_keysel != "age") {
$wsSql = "SELECT * FROM workshop WHERE $search_keysel LIKE '%$search%' ORDER BY status DESC";
} elseif (!empty($search) && $search_keysel == "cusname") {
// Retrieve the customer numbers
db_conn("cubit");
$cusSql = "SELECT cusnum FROM customers WHERE surname LIKE '%$search%'";
$cusRslt = db_exec($cusSql) or errDie("Unable to retrieve customer numbers from Cubit.");
$wsSqlarr = array();
while ($cusData = pg_fetch_array($cusRslt)) {
$wsSqlarr[] = "SELECT * FROM workshop WHERE cusnum='$cusData[cusnum] AND active='true''";
}
$wsSql = implode(" UNION ", $wsSqlarr);
if (!empty($wsSql)) {
$wsSql .= " ORDER BY status DESC";
} else {
// Do a select which would retrieve nothing instead of displaying an error
$wsSql = "SELECT * FROM workshop WHERE cusnum='0' AND active='true'";
}
} elseif (!empty($search) && $search_keysel == "age") {
if (is_numeric($search)) {
$wsSql = "SELECT * FROM workshop WHERE age(cdate)<='$search Days' AND active='true'";
} else {
return display("<li class='err'>Age searching requires a numeric input</li>");
}
} else {
$wsSql = "SELECT * FROM workshop WHERE active='true' ORDER BY status DESC";
}
// for use with the offset, offset needs to retrieve the full number of rows without the LIMIT
$osSql = $wsSql;
$wsSql .= " LIMIT 20 OFFSET $offset";
// Retrieve items in the workshop
db_conn("cubit");
$wsRslt = db_exec($wsSql) or errDie("Unable to retrieve workshop items from Cubit.");
// Previous and next offset values
db_conn("cubit");
$osRslt = db_exec($osSql) or errDie("Unable to retrieve offset data from Cubit.");
$offset_prev = ($offset - 20);
$offset_next = ($offset + 20);
if ($offset_prev < 0) {
$prev = "";
} else {
$prev = "<a href='?key=display&search=$search&search_keysel=$search_keysel&offset=$offset_prev'>« Previous</a>";
}
if ($offset_next > pg_num_rows($osRslt)) {
$next = "";
} else {
$next = "<a href='?key=display&search=$search&search_keysel=$search_keysel&offset=$offset_next'>Next »</a>";
}
$items = "";
$i = 0;
// See if we got any results from the query
if (pg_num_rows($wsRslt) == 0) {
$items = "<tr class='bg-odd'>
<td colspan=9>No items found.</td>";
}
while ($wsData = pg_fetch_array($wsRslt)) {
// Get the customer name
$sql = "SELECT surname, init FROM customers WHERE cusnum='$wsData[cusnum]'";
$cusRslt = db_exec($sql) or errDie("Unable to retrieve customer name from Cubit.");
$cusData = pg_fetch_array($cusRslt);
$i++;
$status = explode(",", $wsData["status"]);
$status = $status[count($status)-1];
// Which links should be enabled/disabled
if ($status == "Present") {
$client_collect = "<a href='?key=client_collect&refnum=$wsData[refnum]'>Client Collect</a>";
$checkinout = "<tr>
<td>
Check in
</td>
<td>
<a href='?key=check_out&refnum=$wsData[refnum]'>Check out to supplier</a>
</td>
</tr>";
} else {
$client_collect = "Client Collect";
$checkinout = "<tr>
<td>
<a href='?key=check_in&refnum=$wsData[refnum]'>Check In</a>
</td>
<td>
<a href='?key=check_out&refnum=$wsData[refnum]'>Check Out to supplier</a>
</td>
</tr>";
}
db_conn("cubit");
$sql = "SELECT * FROM serialrec WHERE serno='$wsData[serno]'";
$ser_rslt = db_exec($sql) or errDie("Unable to retrieve serial number information from Cubit.");
$ser_data = pg_fetch_array($ser_rslt);
if (pg_num_rows($ser_rslt)) {
db_conn("cubit");
$sql = "SELECT warranty FROM stock WHERE stkid='$ser_data[stkid]'";
$stk_rslt = db_exec($sql) or errDie("Unable to retrieve stock information from Cubit.");
$stk_data = pg_fetch_array($stk_data);
$warranty = $stk_data["warranty"];
} else {
$warranty = "";
}
// Items layout
$items .= "
<tr class='".bg_class()."' valign=top>
<td>$wsData[refnum]</td>
<td>$wsData[cdate]</td>
<td><a href='cust-det.php?cusnum=$wsData[cusnum]' target=_blank>$cusData[surname] $cusData[init]</a></td>
<td>$wsData[stkcod]</td>
<td>$wsData[serno]</td>
<td>$warranty</td>
<td>$wsData[description]</td>
<td style='width:180px'>
<center><b>$status</b></center>
<br>".nl2br(base64_decode($wsData["notes"]))."
</td>
<td nowrap align=center>
<table border=0 cellpadding='".TMPL_tblCellPadding."' cellspacing='".TMPL_tblCellSpacing."'>
<tr>
<td nowrap>$client_collect</td>
<td nowrap>
<a href='?key=status_history&refnum=$wsData[refnum]'>Status History</a>
<a href='?key=edit_notes&refnum=$wsData[refnum]'>Edit Notes</a>
</td>
</tr>
$checkinout
</table>
</td>
</tr>";
}
// Search dropdown
$search_keys = "<select name=search_keysel>";
$search_keyarr = array("refnum"=>"Reference Number",
"cusname"=>"Customer",
"serno"=>"Serial Number",
"stkcod"=>"Stock Code/Name",
"description"=>"Description",
"cdate"=>"Date (YYYY-MM-DD)",
"age"=>"Age (Days)"
);
foreach ($search_keyarr as $key => $val) {
if ($search_keysel == $key) {
$selected = "selected";
} else {
$selected = "";
}
$search_keys .= "<option value='$key' $selected>$val</option>";
}
$search_keys .= "</select>";
// Layout
$OUTPUT = "
<center>
<h3>View workshop</h3>
$errors
<form method='POST' action='".SELF."'>
<input type='hidden' name='key' value='display'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan='3'>Search</th>
</tr>
<tr class='".bg_class()."'>
<td><input type='text' name='search' value='$search'></td>
<td>$search_keys</td>
<td><input type='submit' value='Search'></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan='3>
<table ".TMPL_tblDflts." width='100%'>
<tr>
<th colspan='2'>Workshop reports</th>
</tr>
<tr class='".bg_class()."'>
<td align='center'><a href='?key=workshop_report&report=age'>Age report</a></td>
<td align='center'><a href='?key=workshop_report&report=date'>Date report</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<p>
<table ".TMPL_tblDflts." width='100%'>
<tr>
<th>Ref no.</th>
<th>Date</th>
<th>Customer</th>
<th>Stock/Asset Code/Name</th>
<th>Serial Number</th>
<th>Warranty</th>
<th>Description</th>
<th>Status/Notes</th>
<th>Options</th>
</tr>
<tr class='datacell'>
<td colspan='9' align='right'>
$prev
$next
</td>
</tr>
$items
<tr class='datacell'>
<td colspan='9' align='right'>
$prev
$next
</td>
</tr>
</table>
</center>";
return $OUTPUT;
}
function update($_POST)
{
extract ($_POST);
require_lib("validate");
$v = new validate;
$v->isOk($refnum, "num", 0, 9, "Invalid reference number");
$v->isOk($update, "string", 1, 255, "Nothing to update");
if (isset($status)) {
$v->isOk($status, "string", 1, 255, "Invalid status location.");
}
if (isset($supname)) {
$v->isOk($supname, "string", 1, 255, "Invalid supplier name.");
}
// Display Errors
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>$e[msg]</li>";
}
return display($confirm);
}
db_conn("cubit");
switch ($update) {
case "client_collect":
if (isset($printed)) {
$sql = "UPDATE workshop SET active='false', status='Completed' WHERE refnum='$refnum'";
$rslt = db_exec($sql) or errDie("Unable to update data to Cubit.");
} else {
// Print a receipt
$OUTPUT = "
<form method='POST' action='".SELF."'>
<input type='hidden' name='key' value='update'>
<input type='hidden' name='update' value='client_collect'>
<input type='hidden' name='refnum' value='$refnum'>
<input type='hidden' name='printed' value='true'>
<table ".TMPL_tblDflts." width='400'>
<tr>
<th>Info</th>
</tr>
<tr class='".bg_class()."'>
<td><li>After the receipt has been printed successfully, please click on \"<b>Write »</b>\" to commit the changes.</li></td>
</tr>
<tr>
<td align='right'>
<input type='submit' name='key' value='« View Workshop'>
<input type='submit' value='Write »'>
</td>
</tr>
</table>
<script>printer(\"".SELF."?key=receipt&type=delivery_note&refnum=$refnum\");</script>";
return $OUTPUT;
}
break;
case "edit_notes":
$sql = "UPDATE workshop SET notes='".base64_encode($notes)."' WHERE refnum='$refnum'";
$rslt = db_exec($sql) or errDie("Unable to update data to Cubit.");
break;
case "check_in":
db_conn("cubit");
$sql = "SELECT status FROM workshop WHERE refnum='$refnum'";
$statusRslt = db_exec($sql) or errDie("Unable to retrieve status from Cubit.");
$statusData = pg_fetch_result($statusRslt, 0) . ",Present";
$sql = "UPDATE workshop SET status='$statusData' WHERE refnum='$refnum'";
$rslt = db_exec($sql) or errDie("Unable to update data to Cubit.");
break;
case "check_out":
db_conn("cubit");
$sql = "SELECT status FROM workshop WHERE refnum='$refnum'";
$statusRslt = db_exec($sql) or errDie("Unable to retrieve status from Cubit.");
$statusData = pg_fetch_result($statusRslt, 0) . ",$supname";
$sql = "UPDATE workshop SET status='$statusData' WHERE refnum='$refnum'";
$rslt = db_exec($sql) or errDie("Unable to update data to Cubit.");
// Print a receipt
$OUTPUT = "
<form method='POST' action='".SELF."'>
<table ".TMPL_tblDflts.">
<tr>
<th>Info</th>
</tr>
<tr class='bg-odd'>
<td><li>Successfully checked out.</li></td>
</tr>
<tr>
<td align='right'><input type='submit' name='key' value='« View Workshop'></td>
</tr>
</table>
<script>printer(\"".SELF."?key=receipt&type=receipt&refnum=$refnum&supname=$supname&conditions=$conditions\");</script>";
return $OUTPUT;
break;
}
return display();
}
function client_collect($_POST)
{
extract ($_POST);
require_lib("validate");
$v = new validate;
$v->isOk($refnum, "num", 0, 9, "Invalid reference number");
// Display Errors
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>$e[msg]</li>";
}
return display($confirm);
}
db_conn("cubit");
$sql = "SELECT * FROM workshop WHERE refnum='$refnum'";
$wsRslt = db_exec($sql) or errDie("Unable to retrieve item from the workshop.");
$wsData = pg_fetch_array($wsRslt);
// retrieve customer name
db_conn("cubit");
$sql = "SELECT surname FROM customers WHERE cusnum='$wsData[cusnum]'";
$cusRslt = db_exec($sql) or errDie("Unable to retrieve customer name from Cubit.");
$surname = pg_fetch_result($cusRslt, 0);
$OUTPUT = "
<h3>View workshop</h3>
<form method='POST' action='".SELF."'>
<input type='hidden' name='key' value='update'>
<input type='hidden' name='update' value='client_collect'>
<input type='hidden' name='refnum' value='$refnum'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan=2>Client collect from workshop</th>
</tr>
<tr class='".bg_class()."'>
<td>Reference number</td>
<td>$wsData[refnum]</td>
</tr>
<tr class='".bg_class()."'>
<td>Customer</td>
<td>$surname</td>
</tr>
<tr class='".bg_class()."'>
<td>Stock Code/Name</td>
<td>$wsData[stkcod]</td>
</tr>
<tr class='".bg_class()."'>
<td>Serial Number</td>
<td>$wsData[serno]</td>
</tr>
<tr class='".bg_class()."'>
<td>Description</td>
<td>$wsData[description]</td>
</tr>
<tr class='".bg_class()."'>
<td>Notes</td>
<td>".nl2br(base64_decode($wsData["notes"]))."</td>
</tr>
<tr>
<td colspan='2' align='right'>
<input type='submit' name='key' value='« View Workshop'>
<input type='submit' value='Confirm »'>
</td>
</tr>
</table>";
return $OUTPUT;
}
function status_history($_POST)
{
extract ($_POST);
require_lib("validate");
$v = new validate;
$v->isOk($refnum, "num", 0, 9, "Invalid reference number");
// Display Errors
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>$e[msg]</li>";
}
return display($confirm);
}
db_conn("cubit");
$sql = "SELECT status FROM workshop WHERE refnum='$refnum'";
$wsRslt = db_exec($sql) or errDie("Unable to retrieve status history from Cubit.");
$status = pg_fetch_result($wsRslt, 0);
$hist = explode(",", $status);
$hist = array_reverse($hist);
$hist_out = "";
foreach ($hist as $val) {
$hist_out .= "$val<br>";
}
$OUTPUT = "
<h3>View workshop</h3>
<form method='POST' action='".SELF."'>
<table ".TMPL_tblDflts.">
<tr>
<th>Status history</th>
</tr>
<tr class='".bg_class()."'>
<td>$hist_out</td>
</tr>
<tr>
<td colspan='2' align='right'><input type='submit' name='key' value='« View Workshop'></td>
</tr>
</table>
</form>";
return $OUTPUT;
}
function edit_notes($_POST)
{
extract ($_POST);
require_lib("validate");
$v = new validate;
$v->isOk($refnum, "num", 0, 9, "Invalid reference number.");
// Display errors
if ($v->isError()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm = "<li class='err'>$e[msg]</li>";
}
return display($confirm);
}
// Retrieve the notes
db_conn("cubit");
$sql = "SELECT notes FROM workshop WHERE refnum='$refnum'";
$wsRslt = db_exec($sql) or errDie("Unable to retrieve notes from the workshop.");
$notes = base64_decode(pg_fetch_result($wsRslt, 0));
$OUTPUT = "
<h3>View workshop</h3>
<form method='POST' action='".SELF."'>
<input type='hidden' name='key' value='update'>
<input type='hidden' name='update' value='edit_notes'>
<input type='hidden' name='refnum' value='$refnum'>
<table ".TMPL_tblDflts.">
<tr>
<th>Edit Notes</th>
</tr>
<tr class='".bg_class()."'>
<td><textarea name='notes' rows='5' style='width: 180px'>$notes</textarea></td>
</tr>
<tr>
<td align='right'>
<input type='submit' name='key' value='« View Workshop'>
<input type='submit' value='Update »'>
</td>
</tr>
</table>
</form>";
return $OUTPUT;
}
function check_in($_POST)
{
extract ($_POST);
require_lib("validate");
$v = new validate;
$v->isOk($refnum, "num", 0, 9, "Invalid reference number.");
// Display Errors
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>$e[msg]</li>";
}
return display($confirm);
}
db_conn("cubit");
$sql = "SELECT * FROM workshop WHERE refnum='$refnum'";
$wsRslt = db_exec($sql) or errDie("Unable to retrieve item from the workshop.");
$wsData = pg_fetch_array($wsRslt);
// retrieve customer name
db_conn("cubit");
$sql = "SELECT surname FROM customers WHERE cusnum='$wsData[cusnum]'";
$cusRslt = db_exec($sql) or errDie("Unable to retrieve customer name from Cubit.");
$surname = pg_fetch_result($cusRslt, 0);
$status = explode(",", $wsData["status"]);
$status = $status[count($status)-1];
$OUTPUT = "
<h3>View workshop</h3>
<form method='POST' action='".SELF."'>
<input type='hidden' name='key' value='update'>
<input type='hidden' name='update' value='check_in'>
<input type='hidden' name='refnum' value='$refnum'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan='2'>Check in</th>
</tr>
<tr class='".bg_class()."'>
<td>Status</td>
<td>$status</td>
</tr>
<tr class='".bg_class()."'>
<td>Reference number</td>
<td>$wsData[refnum]</td>
</tr>
<tr class='".bg_class()."'>
<td>Customer</td>
<td>$surname</td>
</tr>
<tr class='".bg_class()."'>
<td>Stock Code/Name</td>
<td>$wsData[stkcod]</td>
</tr>
<tr class='".bg_class()."'>
<td>Serial Number</td>
<td>$wsData[serno]</td>
</tr>
<tr class='".bg_class()."'>
<td>Description</td>
<td>$wsData[description]</td>
</tr>
<tr class='".bg_class()."'>
<td>Notes</td>
<td>".nl2br(base64_decode($wsData["notes"]))."</td>
</tr>
<tr>
<td colspan='2' align='right'>
<input type='submit' name='key' value='« View Workshop'>
<input type='submit' value='Confirm »'>
</td>
</tr>
</table>";
return $OUTPUT;
}
function check_out($_POST)
{
extract ($_POST);
require_lib("validate");
$v = new validate;
$v->isOk($refnum, "num", 0, 9, "Invalid reference number");
// Display Errors
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>$e[msg]</li>";
}
return display($confirm);
}
db_conn("cubit");
$sql = "SELECT * FROM workshop WHERE refnum='$refnum'";
$wsRslt = db_exec($sql) or errDie("Unable to retrieve workshop item from Cubit.");
$wsData = pg_fetch_array($wsRslt);
// Supplier dropdown
db_conn("cubit");
$sql = "SELECT * FROM suppliers ORDER BY supname ASC";
$supRslt = db_exec($sql) or errDie("Unable to retrieve suppliers from Cubit.");
$supdn = "<select name=supname style='width: 180px'>";
while ($supData = pg_fetch_array($supRslt)) {
$supdn .= "<option value='$supData[supname]'>$supData[supname]</option>";
}
// retrieve customer name
db_conn("cubit");
$sql = "SELECT surname FROM customers WHERE cusnum='$wsData[cusnum]'";
$cusRslt = db_exec($sql) or errDie("Unable to retrieve customer name from Cubit.");
$surname = pg_fetch_result($cusRslt, 0);
// Retrieve the default workshop conditions
db_conn("cubit");
$sql = "SELECT value FROM workshop_settings WHERE setting='workshop_conditions' AND div='".USER_DIV."'";
$wsRslt = db_exec($sql) or errDie("Unable to retrieve default workshop conditions");
$conditions = pg_fetch_result($wsRslt, 0);
$OUTPUT = "
<h3>View workshop</h3>
<form method='POST' action='".SELF."'>
<input type='hidden' name='key' value='update'>
<input type='hidden' name='update' value='check_out'>
<input type='hidden' name='refnum' value='$refnum'>
<table ".TMPL_tblDflts.">
<tr>
<th colspan='2'>Check out</th>
</tr>
<tr class='".bg_class()."'>
<td>".REQ."Where</td>
<td>$supdn</td>
</tr>
<tr class='".bg_class()."'>
<td>".REQ."Workshop conditions</td>
<td><textarea name='conditions' rows='5' style='width: 180px'>$conditions</textarea></td>
</tr>
<tr class='".bg_class()."'>
<td>Reference number</td>
<td>$wsData[refnum]</td>
</tr>
<tr class='".bg_class()."'>
<td>Customer</td>
<td>$surname</td>
</tr>
<tr class='".bg_class()."'>
<td>Stock Code/Name</td>
<td>$wsData[stkcod]</td>
</tr>
<tr class='".bg_class()."'>
<td>Serial Number</td>
<td>$wsData[serno]</td>
</tr>
<tr class='".bg_class()."'>
<td>Description</td>
<td>$wsData[description]</td>
</tr>
<tr class='".bg_class()."'>
<td>Notes</td>
<td>".nl2br(base64_decode($wsData["notes"]))."</td>
</tr>
<tr>
<td colspan='2' align='right'>
<input type='submit' name='key' value='« View Workshop'>
<input type='submit' value='Confirm »'>
</td>
</tr>
</table>";
return $OUTPUT;
}
function receipt($_POST)
{
extract ($_POST);
require_lib("validate");
$v = new validate;
$v->isOk($refnum, "num", 1, 9, "Invalid reference number.");
$v->isOk($type, "string", 1, 255, "Invalid receipt type.");
if (isset($supname)) $v->isOk($supname, "string", 1, 255, "Invalid supplier name.");
if (isset($conditions)) $v->isOk($conditions, "string", 1, 255, "Invalid workshop conditions.");
// Display Errors
if ($v->isError ()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>$e[msg]</li>";
}
return display($confirm);
}
// Retrieve the workshop item information
db_conn("cubit");
$sql = "SELECT * FROM workshop WHERE refnum='$refnum'";
$wsRslt = db_exec($sql) or errDie("Unable to retrieve workshop information from Cubit.");
$wsData = pg_fetch_array($wsRslt);
switch ($type) {
case "receipt":
// Retrieve the supplier information
db_conn("cubit");
$sql = "SELECT * FROM suppliers WHERE supname='$supname'";
$supRslt = db_exec($sql) or errDie("Unable to retrieve suppliers from Cubit.");
$supData = pg_fetch_array($supRslt);
$OUTPUT = "
<center>
<table border='1' cellpadding='10' cellspacing='1' width='750'>
<tr>
<td valign='top' colspan='2' width='100%'><h1>".COMP_NAME."</h1></td>
</tr>
<tr>
<td valign='top' width='50%'>
<b>Workshop receipt for</b><br>
$supData[supname]<br>
".nl2br($supData["supaddr"])."<br><br>
Tel: $supData[tel]<br>
Fax: $supData[fax]
</td>
<td valign='top' width='50%'><b>Date:</b>".date("Y-m-d")."</td>
</tr>
<tr>
<td valign='top' colspan='2' width='100%'><b>Description:</b> $wsData[description]</td>
</tr>
<tr>
<td valign='top' colspan='2' width='100%'><b>Serial No:</b> $wsData[serno]</td>
</tr>
<tr>
<td valign='top' colspan='2' width='100%'><b>Workshop Conditions:</b><br>$conditions</td>
</tr>
<tr>
<td valign=top colspan=2 width=100%>
Received by: _____________________
</td>
</tr>
</table>
</center>";
break;
case "delivery_note":
db_conn("cubit");
$sql = "SELECT * FROM customers WHERE cusnum='$wsData[cusnum]'";
$cusRslt = db_exec($sql) or errDie("Unable to retrieve customer number from Cubit.");
$cusData = pg_fetch_array($cusRslt);
db_conn("cubit");
$sql = "SELECT value FROM workshop_settings WHERE setting='workshop_conditions'";
$wcRslt = db_exec($sql) or errDie("Unable to retrieve workshop settings from Cubit.");
$workshop_conditions = pg_fetch_result($wcRslt, 0);
$OUTPUT = "
<center>
<table border='1' cellpadding='10' cellspacing='1' width='750'>
<tr>
<td valign='top' colspan='2' width='100%'><h1>".COMP_NAME."</h1></td>
</tr>
<tr>
<td valign='top' width='50%'>
<b>Workshop receipt for:</b><br>
$cusData[title]. $cusData[init] $cusData[surname]<br>
".nl2br($cusData["addr1"])."<br><br>
Tel: $cusData[tel]<br>
Fax: $cusData[fax]<br>
Cell: $cusData[cellno]<br>
Bussiness Tel: $cusData[bustel]
</td>
<td valign='top' width='50%'>
<b>Date:</b> ".date("Y-m-d")."<br>
<b>Reference Number:</b> $refnum
</td>
</tr>
<tr>
<td valign='top' colspan='2' width='100%'><b>Description:</b> $wsData[description]</td>
</tr>
<tr>
<td valign='top' colspan='2' width='100%'><b>Serial No:</b> $wsData[serno]</td>
</tr>
<tr>
<td valign='top' colspan='2' width='100%'>
<b>Workshop Conditions:</b><br>
$workshop_conditions
</td>
</tr>
<tr>
<td valign=top colspan=2 width=100%>
Workshop Sign: _____________________
</td>
</tr>
</table>
</center>";
break;
}
require("tmpl-print.php");
}