/
InternalStockRequest.php
752 lines (698 loc) · 28.9 KB
/
InternalStockRequest.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
<?php
/* $Id: InternalStockRequest.php 4576 2011-05-27 10:59:20Z daintree $*/
include('includes/DefineStockRequestClass.php');
include('includes/session.inc');
$title = _('Create an Internal Materials Request');
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
if (isset($_GET['New'])) {
unset($_SESSION['Transfer']);
$_SESSION['Request'] = new StockRequest();
}
if (isset($_POST['Update'])) {
$InputError=0;
if ($_POST['Department']=='') {
prnMsg( _('You must select a Department for the request'), 'error');
$InputError=1;
}
if ($_POST['Location']=='') {
prnMsg( _('You must select a Location to request the items from'), 'error');
$InputError=1;
}
if ($InputError==0) {
$_SESSION['Request']->Department=$_POST['Department'];
$_SESSION['Request']->Location=$_POST['Location'];
$_SESSION['Request']->DispatchDate=$_POST['DispatchDate'];
$_SESSION['Request']->Narrative=$_POST['Narrative'];
}
}
if (isset($_POST['Edit'])) {
$_SESSION['Request']->LineItems[$_POST['LineNumber']]->Quantity=$_POST['Quantity'];
}
if (isset($_GET['Delete'])) {
unset($_SESSION['Request']->LineItems[$_GET['Delete']]);
echo '<br />';
prnMsg( _('The line was successfully deleted'), 'success');
echo '<br />';
}
foreach ($_POST as $key => $value) {
if (mb_strstr($key,'StockID')) {
$Index=mb_substr($key, 7);
if (filter_number_format($_POST['Quantity'.$Index])>0) {
$StockID=$value;
$ItemDescription=$_POST['ItemDescription'.$Index];
$DecimalPlaces=$_POST['DecimalPlaces'.$Index];
$NewItem_array[$StockID] = filter_number_format($_POST['Quantity'.$Index]);
$_POST['Units'.$StockID]=$_POST['Units'.$Index];
$_SESSION['Request']->AddLine($StockID, $ItemDescription, $NewItem_array[$StockID], $_POST['Units'.$StockID], $DecimalPlaces);
}
}
}
if (isset($_POST['Submit'])) {
DB_Txn_Begin($db);
$InputError=0;
if ($_SESSION['Request']->Department=='') {
prnMsg( _('You must select a Department for the request'), 'error');
$InputError=1;
}
if ($_SESSION['Request']->Location=='') {
prnMsg( _('You must select a Location to request the items from'), 'error');
$InputError=1;
}
if ($InputError==0) {
$RequestNo = GetNextTransNo(38, $db);
$HeaderSQL="INSERT INTO stockrequest (dispatchid,
loccode,
departmentid,
despatchdate,
narrative)
VALUES(
'" . $RequestNo . "',
'" . $_SESSION['Request']->Location . "',
'" . $_SESSION['Request']->Department . "',
'" . FormatDateForSQL($_SESSION['Request']->DispatchDate) . "',
'" . $_SESSION['Request']->Narrative . "')";
$ErrMsg =_('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The request header record could not be inserted because');
$DbgMsg = _('The following SQL to insert the request header record was used');
$Result = DB_query($HeaderSQL,$db,$ErrMsg,$DbgMsg,true);
foreach ($_SESSION['Request']->LineItems as $LineItems) {
$LineSQL="INSERT INTO stockrequestitems (dispatchitemsid,
dispatchid,
stockid,
quantity,
decimalplaces,
uom)
VALUES(
'".$LineItems->LineNumber."',
'".$RequestNo."',
'".$LineItems->StockID."',
'".$LineItems->Quantity."',
'".$LineItems->DecimalPlaces."',
'".$LineItems->UOM."')";
$ErrMsg =_('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The request line record could not be inserted because');
$DbgMsg = _('The following SQL to insert the request header record was used');
$Result = DB_query($LineSQL,$db,$ErrMsg,$DbgMsg,true);
}
$EmailSQL="SELECT email
FROM www_users, departments
WHERE departments.authoriser = www_users.userid
AND departments.departmentid = '" . $_SESSION['Request']->Department ."'";
$EmailResult = DB_query($EmailSQL,$db);
if ($myEmail=DB_fetch_array($EmailResult)){
$ConfirmationText = _('An internal stock request has been created and is waiting for your authoritation');
$EmailSubject = _('Internal Stock Request needs your authoritation');
mail($myEmail['email'],$EmailSubject,$ConfirmationText);
}
}
DB_Txn_Commit($db);
prnMsg( _('The internal stock request has been entered and now needs to be authorised'), 'success');
echo '<br /><div class="centre"><a href="'. htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?New=Yes">' . _('Create another request') . '</a></div>';
include('includes/footer.inc');
unset($_SESSION['Request']);
exit;
}
echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Dispatch') .
'" alt="" />' . ' ' . $title . '</p>';
if (isset($_GET['Edit'])) {
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="selection">';
echo '<tr>
<th colspan="2"><h4>' . _('Edit the Request Line') . '</h4></th>
</tr>';
echo '<tr>
<td>' . _('Line number') . '</td>
<td>' . $_SESSION['Request']->LineItems[$_GET['Edit']]->LineNumber . '</td>
</tr>
<tr>
<td>' . _('Stock Code') . '</td>
<td>' . $_SESSION['Request']->LineItems[$_GET['Edit']]->StockID . '</td>
</tr>
<tr>
<td>' . _('Item Description') . '</td>
<td>' . $_SESSION['Request']->LineItems[$_GET['Edit']]->ItemDescription . '</td>
</tr>
<tr>
<td>' . _('Unit of Measure') . '</td>
<td>' . $_SESSION['Request']->LineItems[$_GET['Edit']]->UOM . '</td>
</tr>
<tr>
<td>' . _('Quantity Requested') . '</td>
<td><input type="text" class="number" name="Quantity" value="' . locale_number_format($_SESSION['Request']->LineItems[$_GET['Edit']]->Quantity, $_SESSION['Request']->LineItems[$_GET['Edit']]->DecimalPlaces) . '" /></td>
</tr>';
echo '<input type="hidden" name="LineNumber" value="' . $_SESSION['Request']->LineItems[$_GET['Edit']]->LineNumber . '" />';
echo '</table>
<br />';
echo '<div class="centre">
<input type="submit" name="Edit" value="' . _('Update Line') . '" />
</div>
</div>
</form>';
include('includes/footer.inc');
exit;
}
echo '<form action="'. htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="selection">';
echo '<tr>
<th colspan="2"><h4>' . _('Internal Stock Request Details') . '</h4></th>
</tr>
<tr>
<td>' . _('Department') . ':</td>';
if($_SESSION['AllowedDepartment'] == 0){
// any internal department allowed
$sql="SELECT departmentid,
description
FROM departments
ORDER BY description";
}else{
// just 1 internal department allowed
$sql="SELECT departmentid,
description
FROM departments
WHERE departmentid = '". $_SESSION['AllowedDepartment'] ."'
ORDER BY description";
}
$result=DB_query($sql, $db);
echo '<td><select name="Department">';
while ($myrow=DB_fetch_array($result)){
if (isset($_SESSION['Request']->Department) AND $_SESSION['Request']->Department==$myrow['departmentid']){
echo '<option selected="True" value="' . $myrow['departmentid'] . '">' . htmlspecialchars($myrow['description'], ENT_QUOTES,'UTF-8') . '</option>';
} else {
echo '<option value="' . $myrow['departmentid'] . '">' . htmlspecialchars($myrow['description'], ENT_QUOTES,'UTF-8') . '</option>';
}
}
echo '</select></td>
</tr>
<tr>
<td>' . _('Location from which to request stock') . ':</td>';
$sql="SELECT loccode,
locationname
FROM locations
WHERE internalrequest = 1
ORDER BY locationname";
$result=DB_query($sql, $db);
echo '<td><select name="Location">
<option value="">' . _('Select a Location') . '</option>';
while ($myrow=DB_fetch_array($result)){
if (isset($_SESSION['Request']->Location) AND $_SESSION['Request']->Location==$myrow['loccode']){
echo '<option selected="True" value="' . $myrow['loccode'] . '">' . $myrow['loccode'].' - ' .htmlspecialchars($myrow['locationname'], ENT_QUOTES,'UTF-8') . '</option>';
} else {
echo '<option value="' . $myrow['loccode'] . '">' . $myrow['loccode'].' - ' .htmlspecialchars($myrow['locationname'], ENT_QUOTES,'UTF-8') . '</option>';
}
}
echo '</select></td>
</tr>
<tr>
<td>' . _('Date when required') . ':</td>';
echo '<td><input type="text" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" name="DispatchDate" maxlength="10" size="11" value="' . $_SESSION['Request']->DispatchDate . '" /></td>
</tr>';
echo '<tr>
<td>' . _('Narrative') . ':</td>
<td><textarea name="Narrative" cols="30" rows="5">'.$_SESSION['Request']->Narrative.'</textarea></td>
</tr>
</table>
<br />';
echo '<div class="centre">
<input type="submit" name="Update" value="' . _('Update') . '" />
</div>
</div>
</form>';
if (!isset($_SESSION['Request']->Location)) {
include('includes/footer.inc');
exit;
}
//****************MUESTRO LA TABLA CON LOS REGISTROS DE LA TRANSFERENCIA*************************************
$i = 0; //Line Item Array pointer
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<br />
<table class="selection">
<tr>
<th colspan="7"><h4>' . _('Details of Items Requested') . '</h4></th>
</tr>
<tr>
<th>'. _('Line Number') . '</th>
<th>'. _('Item Code') . '</th>
<th>'. _('Item Description'). '</th>
<th>'. _('Quantity Required'). '</th>
<th>'. _('UOM'). '</th>
</tr>';
$k=0;
foreach ($_SESSION['Request']->LineItems as $LineItems) {
if ($k==1){
echo '<tr class="EvenTableRows">';
$k=0;
} else {
echo '<tr class="OddTableRows">';
$k++;
}
echo '<td>' . $LineItems->LineNumber . '</td>
<td>' . $LineItems->StockID . '</td>
<td>' . $LineItems->ItemDescription . '</td>
<td class="number">' . locale_number_format($LineItems->Quantity, $LineItems->DecimalPlaces) . '</td>
<td>' . $LineItems->UOM . '</td>
<td><a href="'. htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?Edit='.$LineItems->LineNumber.'">' . _('Edit') . '</a></td>
<td><a href="'. htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?Delete='.$LineItems->LineNumber.'">' . _('Delete') . '</a></td>
</tr>';
}
echo '</table>
<br />
<div class="centre">
<input type="submit" name="Submit" value="' . _('Submit') . '" />
</div>
<br />
</div>
</form>';
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<p class="page_title_text"><img src="' . $rootpath . '/css/' . $theme . '/images/magnifier.png" title="' . _('Search') . '" alt="" />' . ' ' . _('Search for Inventory Items'). '</p>';
$SQL = "SELECT stockcategory.categoryid,
stockcategory.categorydescription
FROM stockcategory, internalstockcatrole
WHERE stockcategory.categoryid = internalstockcatrole.categoryid
AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . "
ORDER BY stockcategory.categorydescription";
$result1 = DB_query($SQL, $db);
if (DB_num_rows($result1) == 0) {
echo '<p class="bad">' . _('Problem Report') . ':<br />' . _('There are no stock categories currently defined please use the link below to set them up').'</p>';
echo '<br />
<a href="' . $rootpath . '/StockCategories.php">' . _('Define Stock Categories') . '</a>';
exit;
}
echo '<table class="selection">
<tr>
<td>' . _('In Stock Category') . ':<select name="StockCat">';
if (!isset($_POST['StockCat'])) {
$_POST['StockCat'] = '';
}
if ($_POST['StockCat'] == 'All') {
echo '<option selected="True" value="All">' . _('All Authorized').'</option>';
} else {
echo '<option value="All">' . _('All Authorized').'</option>';
}
while ($myrow1 = DB_fetch_array($result1)) {
if ($myrow1['categoryid'] == $_POST['StockCat']) {
echo '<option selected="True" value="' . $myrow1['categoryid'] . '">' . $myrow1['categorydescription'].'</option>';
} else {
echo '<option value="' . $myrow1['categoryid'] . '">' . $myrow1['categorydescription'].'</option>';
}
}
echo '</select></td>
<td>' . _('Enter partial') . '<b> ' . _('Description') . '</b>:</td>';
if (isset($_POST['Keywords'])) {
echo '<td><input type="text" name="Keywords" value="' . $_POST['Keywords'] . '" size="20" maxlength="25" /></td>';
} else {
echo '<td><input type="text" name="Keywords" size="20" maxlength="25" /></td>';
}
echo '</tr>
<tr>
<td></td>
<td><h3>' . _('OR') . ' ' . '</h3>' . _('Enter partial') . ' <b>' . _('Stock Code') . '</b>:</td>';
if (isset($_POST['StockCode'])) {
echo '<td><input type="text" name="StockCode" value="' . $_POST['StockCode'] . '" size="15" maxlength="18" /></td>';
} else {
echo '<td><input type="text" name="StockCode" size="15" maxlength="18" /></td>';
}
echo '</tr>
</table>
<br />
<div class="centre">
<input type="submit" name="Search" value="' . _('Search Now') . '" />
</div>
<br />';
echo '<script type="text/javascript">defaultControl(document.forms[0].StockCode);</script>';
echo '</div>';
echo '</form>';
if (isset($_POST['Search']) or isset($_POST['Next']) or isset($_POST['Prev'])){
if ($_POST['Keywords']!='' AND $_POST['StockCode']=='') {
prnMsg ( _('Order Item description has been used in search'), 'warn' );
} elseif ($_POST['StockCode']!='' AND $_POST['Keywords']=='') {
prnMsg ( _('Stock Code has been used in search'), 'warn' );
} elseif ($_POST['Keywords']=='' AND $_POST['StockCode']=='') {
prnMsg ( _('Stock Category has been used in search'), 'warn' );
}
if (isset($_POST['Keywords']) AND mb_strlen($_POST['Keywords'])>0) {
//insert wildcard characters in spaces
$_POST['Keywords'] = mb_strtoupper($_POST['Keywords']);
$SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%';
if ($_POST['StockCat']=='All'){
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units as stockunits,
stockmaster.decimalplaces
FROM stockmaster,
stockcategory,
internalstockcatrole
WHERE stockmaster.categoryid=stockcategory.categoryid
AND stockcategory.categoryid = internalstockcatrole.categoryid
AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . "
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.mbflag <>'G'
AND stockmaster.description " . LIKE . " '" . $SearchString . "'
AND stockmaster.discontinued=0
ORDER BY stockmaster.stockid";
} else {
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units as stockunits,
stockmaster.decimalplaces
FROM stockmaster,
stockcategory,
internalstockcatrole
WHERE stockmaster.categoryid=stockcategory.categoryid
AND stockcategory.categoryid = internalstockcatrole.categoryid
AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . "
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
AND stockmaster.description " . LIKE . " '" . $SearchString . "'
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid";
}
} elseif (mb_strlen($_POST['StockCode'])>0){
$_POST['StockCode'] = mb_strtoupper($_POST['StockCode']);
$SearchString = '%' . $_POST['StockCode'] . '%';
if ($_POST['StockCat']=='All'){
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units as stockunits,
stockmaster.decimalplaces
FROM stockmaster,
stockcategory,
internalstockcatrole
WHERE stockmaster.categoryid=stockcategory.categoryid
AND stockcategory.categoryid = internalstockcatrole.categoryid
AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . "
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.stockid " . LIKE . " '" . $SearchString . "'
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
ORDER BY stockmaster.stockid";
} else {
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units as stockunits,
stockmaster.decimalplaces
FROM stockmaster,
stockcategory,
internalstockcatrole
WHERE stockmaster.categoryid=stockcategory.categoryid
AND stockcategory.categoryid = internalstockcatrole.categoryid
AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . "
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.stockid " . LIKE . " '" . $SearchString . "'
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid";
}
} else {
if ($_POST['StockCat']=='All'){
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units as stockunits,
stockmaster.decimalplaces
FROM stockmaster,
stockcategory,
internalstockcatrole
WHERE stockmaster.categoryid=stockcategory.categoryid
AND stockcategory.categoryid = internalstockcatrole.categoryid
AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . "
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
ORDER BY stockmaster.stockid";
} else {
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
stockmaster.units as stockunits,
stockmaster.decimalplaces
FROM stockmaster,
stockcategory,
internalstockcatrole
WHERE stockmaster.categoryid=stockcategory.categoryid
AND stockcategory.categoryid = internalstockcatrole.categoryid
AND internalstockcatrole.secroleid= " . $_SESSION['AccessLevel'] . "
AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
AND stockmaster.mbflag <>'G'
AND stockmaster.discontinued=0
AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
ORDER BY stockmaster.stockid";
}
}
if (isset($_POST['Next'])) {
$Offset = $_POST['NextList'];
}
if (isset($_POST['Prev'])) {
$Offset = $_POST['Previous'];
}
if (!isset($Offset) or $Offset<0) {
$Offset=0;
}
$SQL = $SQL . ' LIMIT ' . $_SESSION['DefaultDisplayRecordsMax'] . ' OFFSET ' . ($_SESSION['DefaultDisplayRecordsMax']*$Offset);
$ErrMsg = _('There is a problem selecting the part records to display because');
$DbgMsg = _('The SQL used to get the part selection was');
$SearchResult = DB_query($SQL,$db,$ErrMsg, $DbgMsg);
if (DB_num_rows($SearchResult)==0 ){
prnMsg (_('There are no products available meeting the criteria specified'),'info');
}
if (DB_num_rows($SearchResult)<$_SESSION['DisplayRecordsMax']){
$Offset=0;
}
} //end of if search
/* display list if there is more than one record */
if (isset($searchresult) AND !isset($_POST['Select'])) {
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
$ListCount = DB_num_rows($searchresult);
if ($ListCount > 0) {
// If the user hit the search button and there is more than one item to show
$ListPageMax = ceil($ListCount / $_SESSION['DisplayRecordsMax']);
if (isset($_POST['Next'])) {
if ($_POST['PageOffset'] < $ListPageMax) {
$_POST['PageOffset'] = $_POST['PageOffset'] + 1;
}
}
if (isset($_POST['Previous'])) {
if ($_POST['PageOffset'] > 1) {
$_POST['PageOffset'] = $_POST['PageOffset'] - 1;
}
}
if ($_POST['PageOffset'] > $ListPageMax) {
$_POST['PageOffset'] = $ListPageMax;
}
if ($ListPageMax > 1) {
echo '<div class="centre"><br /> ' . $_POST['PageOffset'] . ' ' . _('of') . ' ' . $ListPageMax . ' ' . _('pages') . '. ' . _('Go to Page') . ': ';
echo '<select name="PageOffset">';
$ListPage = 1;
while ($ListPage <= $ListPageMax) {
if ($ListPage == $_POST['PageOffset']) {
echo '<option value=' . $ListPage . ' selected>' . $ListPage . '</option>';
} else {
echo '<option value=' . $ListPage . '>' . $ListPage . '</option>';
}
$ListPage++;
}
echo '</select>
<input type="submit" name="Go" value="' . _('Go') . '" />
<input type="submit" name="Previous" value="' . _('Previous') . '" />
<input type="submit" name="Next" value="' . _('Next') . '" />
<input type="hidden" name=Keywords value="'.$_POST['Keywords'].'" />
<input type="hidden" name=StockCat value="'.$_POST['StockCat'].'" />
<input type="hidden" name=StockCode value="'.$_POST['StockCode'].'" />
<br />
</div>';
}
echo '<table cellpadding="2">';
echo '<tr>
<th>' . _('Code') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('Total Qty On Hand') . '</th>
<th>' . _('Units') . '</th>
<th>' . _('Stock Status') . '</th>
</tr>';
$j = 1;
$k = 0; //row counter to determine background colour
$RowIndex = 0;
if (DB_num_rows($searchresult) <> 0) {
DB_data_seek($searchresult, ($_POST['PageOffset'] - 1) * $_SESSION['DisplayRecordsMax']);
}
while (($myrow = DB_fetch_array($searchresult)) AND ($RowIndex <> $_SESSION['DisplayRecordsMax'])) {
if ($k == 1) {
echo '<tr class="EvenTableRows">';
$k = 0;
} else {
echo '<tr class="OddTableRows">';
$k++;
}
if ($myrow['mbflag'] == 'D') {
$qoh = _('N/A');
} else {
$qoh = locale_number_format($myrow['qoh'], $myrow['decimalplaces']);
}
if ($myrow['discontinued']==1){
$ItemStatus = '<p class="bad">' . _('Obsolete') . '</p>';
} else {
$ItemStatus ='';
}
echo '<td><input type="submit" name="Select" value="' . $myrow['stockid'] . '" /></td>
<td>'.$myrow['description'].'</td>
<td class="number">' . $qoh . '</td>
<td>' . $myrow['units'] . '</td>
<td><a target="_blank" href="' . $rootpath . '/StockStatus.php?StockID=' . $myrow['stockid'].'">' . _('View') . '</a></td>
<td>' . $ItemStatus . '</td>
</tr>';
//end of page full new headings if
}
//end of while loop
echo '</table>
</div>
</form>
<br />';
}
}
/* end display list if there is more than one record */
if (isset($SearchResult)) {
echo '<br />';
echo '<div class="page_help_text">' . _('Select an item by entering the quantity required. Click Order when ready.') . '</div>';
echo '<br />';
$j = 1;
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post" id="orderform">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="table1">';
echo '<tr><td>
<input type="hidden" name="Previous" value="'.($Offset-1).'" />
<input tabindex="'.($j+8).'" type="submit" name="Prev" value="'._('Prev').'" /></td>';
echo '<td style="text-align:center" colspan="6">
<input type="hidden" name="order_items" value="1" />
<input tabindex="'.($j+9).'" type="submit" value="'._('Add to Requisition').'" /></td>';
echo '<td>
<input type="hidden" name="NextList" value="'.($Offset+1).'" />
<input tabindex="'.($j+10).'" type="submit" name="Next" value="'._('Next').'" /></td></tr>';
echo '<tr>
<th>' . _('Code') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('Units') . '</th>
<th>' . _('On Hand') . '</th>
<th>' . _('On Demand') . '</th>
<th>' . _('On Order') . '</th>
<th>' . _('Available') . '</th>
<th>' . _('Quantity') . '</th>
</tr>';
$ImageSource = _('No Image');
$k=0; //row colour counter
$i=0;
while ($myrow=DB_fetch_array($SearchResult)) {
if ($myrow['decimalplaces']=='') {
$DecimalPlacesSQL="SELECT decimalplaces
FROM stockmaster
WHERE stockid='" .$myrow['stockid'] . "'";
$DecimalPlacesResult = DB_query($DecimalPlacesSQL, $db);
$DecimalPlacesRow = DB_fetch_array($DecimalPlacesResult);
$DecimalPlaces = $DecimalPlacesRow['decimalplaces'];
} else {
$DecimalPlaces=$myrow['decimalplaces'];
}
$QOHSQL = "SELECT sum(locstock.quantity) AS qoh
FROM locstock
WHERE locstock.stockid='" .$myrow['stockid'] . "' AND
loccode = '" . $_SESSION['Request']->Location . "'";
$QOHResult = DB_query($QOHSQL,$db);
$QOHRow = DB_fetch_array($QOHResult);
$QOH = $QOHRow['qoh'];
// Find the quantity on outstanding sales orders
$sql = "SELECT SUM(salesorderdetails.quantity-salesorderdetails.qtyinvoiced) AS dem
FROM salesorderdetails INNER JOIN salesorders
ON salesorders.orderno = salesorderdetails.orderno
WHERE salesorders.fromstkloc='" . $_SESSION['Request']->Location . "'
AND salesorderdetails.completed=0
AND salesorders.quotation=0
AND salesorderdetails.stkcode='" . $myrow['stockid'] . "'";
$ErrMsg = _('The demand for this product from') . ' ' . $_SESSION['Request']->Location . ' ' . _('cannot be retrieved because');
$DemandResult = DB_query($sql,$db,$ErrMsg);
$DemandRow = DB_fetch_row($DemandResult);
if ($DemandRow[0] != null){
$DemandQty = $DemandRow[0];
} else {
$DemandQty = 0;
}
// Find the quantity on purchase orders
$sql = "SELECT SUM(purchorderdetails.quantityord-purchorderdetails.quantityrecd)*purchorderdetails.conversionfactor AS dem
FROM purchorderdetails LEFT JOIN purchorders
ON purchorderdetails.orderno=purchorders.orderno
WHERE purchorderdetails.completed=0
AND purchorders.status<>'Cancelled'
AND purchorders.status<>'Rejected'
AND purchorders.status<>'Completed'
AND purchorderdetails.itemcode='" . $myrow['stockid'] . "'";
$ErrMsg = _('The order details for this product cannot be retrieved because');
$PurchResult = DB_query($sql,$db,$ErrMsg);
$PurchRow = DB_fetch_row($PurchResult);
if ($PurchRow[0]!=null){
$PurchQty = $PurchRow[0];
} else {
$PurchQty = 0;
}
// Find the quantity on works orders
$sql = "SELECT SUM(woitems.qtyreqd - woitems.qtyrecd) AS dedm
FROM woitems
WHERE stockid='" . $myrow['stockid'] ."'";
$ErrMsg = _('The order details for this product cannot be retrieved because');
$WoResult = DB_query($sql,$db,$ErrMsg);
$WoRow = DB_fetch_row($WoResult);
if ($WoRow[0]!=null){
$WoQty = $WoRow[0];
} else {
$WoQty = 0;
}
if ($k==1){
echo '<tr class="EvenTableRows">';
$k=0;
} else {
echo '<tr class="OddTableRows">';
$k=1;
}
$OnOrder = $PurchQty + $WoQty;
$Available = $QOH - $DemandQty + $OnOrder;
echo '<td>'.$myrow['stockid'].'</td>
<td>'.$myrow['description'].'</td>
<td>'.$myrow['stockunits'].'</td>
<td class="number">'.locale_number_format($QOH,$DecimalPlaces).'</td>
<td class="number">'.locale_number_format($DemandQty,$DecimalPlaces).'</td>
<td class="number">'.locale_number_format($OnOrder, $DecimalPlaces).'</td>
<td class="number">'.locale_number_format($Available,$DecimalPlaces).'</td>
<td><input class="number" tabindex="'.($j+7).'" type="text" size="6" name="Quantity'.$i.'" value="0" />
<input type="hidden" name="StockID'.$i.'" value="'.$myrow['stockid'].'" />
</td>
</tr>';
echo '<input type="hidden" name="DecimalPlaces'.$i.'" value="' . $myrow['decimalplaces'] . '" />';
echo '<input type="hidden" name="ItemDescription'.$i.'" value="' . $myrow['description'] . '" />';
echo '<input type="hidden" name="Units'.$i.'" value="' . $myrow['stockunits'] . '" />';
if ($j==1) {
$jsCall = '<script type="text/javascript">if (document.SelectParts) {defaultControl(document.SelectParts.itm'.$myrow['stockid'].');}</script>';
}
$i++;
#end of page full new headings if
}
#end of while loop
echo '<tr><td><input type="hidden" name="Previous" value="'.($Offset-1).'" />
<input tabindex="'.($j+7).'" type="submit" name="Prev" value="'._('Prev').'" /></td>';
echo '<td style="text-align:center" colspan="6"><input type="hidden" name="order_items" value="1" />
<input tabindex="'.($j+8).'" type="submit" value="'._('Add to Requisition').'" /></td>';
echo '<td><input type="hidden" name="NextList" value="'.($Offset+1).'" />
<input tabindex="'.($j+9).'" type="submit" name="Next" value="'._('Next').'" /></td><tr/>';
echo '</table>
</div>
</form>';
echo $jsCall;
}#end if SearchResults to show
//*********************************************************************************************************
include('includes/footer.inc');
?>