forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StockLocTransferReceive.php
698 lines (598 loc) · 29.8 KB
/
StockLocTransferReceive.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
<?php
/* Inventory Transfer - Receive */
include('includes/DefineSerialItems.php');
include('includes/DefineStockTransfers.php');
include('includes/session.php');
$Title = _('Inventory Transfer') . ' - ' . _('Receiving');// Screen identification.
$ViewTopic = 'Inventory';// Filename's id in ManualContents.php's TOC.
$BookMark = 'LocationTransfers';// Anchor's id in the manual's html document.
include('includes/header.php');
include('includes/SQL_CommonFunctions.inc');
if(isset($_GET['NewTransfer'])) {
unset($_SESSION['Transfer']);
}
if(isset($_SESSION['Transfer']) and $_SESSION['Transfer']->TrfID == '') {
unset($_SESSION['Transfer']);
}
if(isset($_POST['ProcessTransfer'])) {
/*Ok Time To Post transactions to Inventory Transfers, and Update Posted variable & received Qty's to LocTransfers */
$PeriodNo = GetPeriod ($_SESSION['Transfer']->TranDate);
$SQLTransferDate = FormatDateForSQL($_SESSION['Transfer']->TranDate);
$InputError = False; /*Start off hoping for the best */
$i=0;
$TotalQuantity = 0;
foreach ($_SESSION['Transfer']->TransferItem AS $TrfLine) {
if(is_numeric(filter_number_format($_POST['Qty' . $i]))) {
/*Update the quantity received from the inputs */
$_SESSION['Transfer']->TransferItem[$i]->Quantity= round(filter_number_format($_POST['Qty' . $i]),$_SESSION['Transfer']->TransferItem[$i]->DecimalPlaces);
} elseif($_POST['Qty' . $i]=='') {
$_SESSION['Transfer']->TransferItem[$i]->Quantity= 0;
} else {
prnMsg(_('The quantity entered for'). ' ' . $TrfLine->StockID . ' '. _('is not numeric') . '. ' . _('All quantities must be numeric'),'error');
$InputError = True;
}
if(filter_number_format($_POST['Qty' . $i])<0) {
prnMsg(_('The quantity entered for'). ' ' . $TrfLine->StockID . ' '. _('is negative') . '. ' . _('All quantities must be for positive numbers greater than zero'),'error');
$InputError = True;
}
if($TrfLine->PrevRecvQty + $TrfLine->Quantity > $TrfLine->ShipQty) {
prnMsg( _('The Quantity entered plus the Quantity Previously Received can not be greater than the Total Quantity shipped for').' '. $TrfLine->StockID , 'error');
$InputError = True;
}
if(isset($_POST['CancelBalance' . $i]) and $_POST['CancelBalance' . $i]==1) {
$_SESSION['Transfer']->TransferItem[$i]->CancelBalance=1;
} else {
$_SESSION['Transfer']->TransferItem[$i]->CancelBalance=0;
}
$TotalQuantity += $TrfLine->Quantity;
$i++;
} /*end loop to validate and update the SESSION['Transfer'] data */
if($TotalQuantity < 0) {
prnMsg( _('All quantities entered are less than zero') . '. ' . _('Please correct that and try again'), 'error' );
$InputError = True;
}
//exit;
if(!$InputError) {
/*All inputs must be sensible so make the stock movement records and update the locations stocks */
$Result = DB_Txn_Begin(); // The Txn should affect the full transfer
foreach ($_SESSION['Transfer']->TransferItem AS $TrfLine) {
if($TrfLine->Quantity >= 0) {
/* Need to get the current location quantity will need it later for the stock movement */
$SQL="SELECT locstock.quantity
FROM locstock
WHERE locstock.stockid='" . $TrfLine->StockID . "'
AND loccode= '" . $_SESSION['Transfer']->StockLocationFrom . "'";
$Result = DB_query($SQL, _('Could not retrieve the stock quantity at the dispatch stock location prior to this transfer being processed') );
if(DB_num_rows($Result)==1) {
$LocQtyRow = DB_fetch_row($Result);
$QtyOnHandPrior = $LocQtyRow[0];
} else {
/* There must actually be some error this should never happen */
$QtyOnHandPrior = 0;
}
/* Insert the stock movement for the stock going out of the from location */
$SQL = "INSERT INTO stockmoves (stockid,
type,
transno,
loccode,
trandate,
userid,
prd,
reference,
qty,
newqoh)
VALUES (
'" . $TrfLine->StockID . "',
16,
'" . $_SESSION['Transfer']->TrfID . "',
'" . $_SESSION['Transfer']->StockLocationFrom . "',
'" . $SQLTransferDate . "',
'" . $_SESSION['UserID'] . "',
'" . $PeriodNo . "',
'" . _('To') . ' ' . DB_escape_string($_SESSION['Transfer']->StockLocationToName) . "',
'" . round(-$TrfLine->Quantity, $TrfLine->DecimalPlaces) . "',
'" . round($QtyOnHandPrior - $TrfLine->Quantity, $TrfLine->DecimalPlaces) . "'
)";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The stock movement record cannot be inserted because');
$DbgMsg = _('The following SQL to insert the stock movement record was used');
$Result = DB_query($SQL,$ErrMsg, $DbgMsg, true);
/*Get the ID of the StockMove... */
$StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno');
/*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/
if($TrfLine->Controlled ==1) {
foreach($TrfLine->SerialItems as $Item) {
/*We need to add or update the StockSerialItem record and
The StockSerialMoves as well */
/*First need to check if the serial items already exists or not in the location from */
$SQL = "SELECT COUNT(*)
FROM stockserialitems
WHERE
stockid='" . $TrfLine->StockID . "'
AND loccode='" . $_SESSION['Transfer']->StockLocationFrom . "'
AND serialno='" . $Item->BundleRef . "'";
$Result = DB_query($SQL,'<br />' . _('Could not determine if the serial item exists') );
$SerialItemExistsRow = DB_fetch_row($Result);
if($SerialItemExistsRow[0]==1) {
$SQL = "UPDATE stockserialitems SET
quantity= quantity - " . $Item->BundleQty . "
WHERE
stockid='" . $TrfLine->StockID . "'
AND loccode='" . $_SESSION['Transfer']->StockLocationFrom . "'
AND serialno='" . $Item->BundleRef . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be updated because');
$DbgMsg = _('The following SQL to update the serial stock item record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
} else {
/*Need to insert a new serial item record */
$SQL = "INSERT INTO stockserialitems (stockid,
loccode,
serialno,
quantity)
VALUES ('" . $TrfLine->StockID . "',
'" . $_SESSION['Transfer']->StockLocationFrom . "',
'" . $Item->BundleRef . "',
'" . -$Item->BundleQty . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item for the stock being transferred out of the existing location could not be inserted because');
$DbgMsg = _('The following SQL to update the serial stock item record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
/* now insert the serial stock movement */
$SQL = "INSERT INTO stockserialmoves (
stockmoveno,
stockid,
serialno,
moveqty
) VALUES (
'" . $StkMoveNo . "',
'" . $TrfLine->StockID . "',
'" . $Item->BundleRef . "',
'" . -$Item->BundleQty . "'
)";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock movement record could not be inserted because');
$DbgMsg = _('The following SQL to insert the serial stock movement records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}/* foreach controlled item in the serialitems array */
} /*end if the transferred item is a controlled item */
/* Need to get the current location quantity will need it later for the stock movement */
$SQL="SELECT locstock.quantity
FROM locstock
WHERE locstock.stockid='" . $TrfLine->StockID . "'
AND loccode= '" . $_SESSION['Transfer']->StockLocationTo . "'";
$Result = DB_query($SQL, _('Could not retrieve the quantity on hand at the location being transferred to') );
if(DB_num_rows($Result)==1) {
$LocQtyRow = DB_fetch_row($Result);
$QtyOnHandPrior = $LocQtyRow[0];
} else {
// There must actually be some error this should never happen
$QtyOnHandPrior = 0;
}
// Insert outgoing inventory GL transaction if any of the locations has a GL account code:
if(($_SESSION['Transfer']->StockLocationFromAccount !='' or $_SESSION['Transfer']->StockLocationToAccount !='')) {
// Get the account code:
if($_SESSION['Transfer']->StockLocationFromAccount !='') {
$AccountCode = $_SESSION['Transfer']->StockLocationFromAccount;
} else {
$StockGLCode = GetStockGLCode($TrfLine->StockID);// Get Category's account codes.
$AccountCode = $StockGLCode['stockact'];// Select account code for stock.
}
// Get the item cost:
$SQLstandardcost = "SELECT stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost AS standardcost
FROM stockmaster
WHERE stockmaster.stockid ='" . $TrfLine->StockID . "'";
$ErrMsg = _('The standard cost of the item cannot be retrieved because');
$DbgMsg = _('The SQL that failed was');
$myrow = DB_fetch_array(DB_query($SQLstandardcost,$ErrMsg,$DbgMsg));
$StandardCost = $myrow['standardcost'];// QUESTION: Standard cost for: Assembly (value="A") and Manufactured (value="M") items ?
// Insert record:
$SQL = "INSERT INTO gltrans (
periodno,
trandate,
type,
typeno,
account,
narrative,
amount)
VALUES ('" .
$PeriodNo . "','" .
$SQLTransferDate .
"',16,'" .
$_SESSION['Transfer']->TrfID . "','" .
$AccountCode . "','" .
$_SESSION['Transfer']->StockLocationFrom.' - '.$TrfLine->StockID.' x '.$TrfLine->Quantity.' @ '. $StandardCost . "','" .
-$TrfLine->Quantity * $StandardCost . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The outgoing inventory GL transacction record could not be inserted because');
$DbgMsg = _('The following SQL to insert records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
// Insert the stock movement for the stock coming into the to location
$SQL = "INSERT INTO stockmoves (stockid,
type,
transno,
loccode,
trandate,
userid,
prd,
reference,
qty,
newqoh)
VALUES (
'" . $TrfLine->StockID . "',
16,
'" . $_SESSION['Transfer']->TrfID . "',
'" . $_SESSION['Transfer']->StockLocationTo . "',
'" . $SQLTransferDate . "',
'" . $_SESSION['UserID'] . "',
'" . $PeriodNo . "',
'" . _('From') . ' ' . DB_escape_string($_SESSION['Transfer']->StockLocationFromName) ."',
'" . round($TrfLine->Quantity, $TrfLine->DecimalPlaces) . "',
'" . round($QtyOnHandPrior + $TrfLine->Quantity, $TrfLine->DecimalPlaces) . "'
)";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The stock movement record for the incoming stock cannot be added because');
$DbgMsg = _('The following SQL to insert the stock movement record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
/*Get the ID of the StockMove... */
$StkMoveNo = DB_Last_Insert_ID('stockmoves','stkmoveno');
/*Insert the StockSerialMovements and update the StockSerialItems for controlled items*/
if($TrfLine->Controlled ==1) {
foreach($TrfLine->SerialItems as $Item) {
/*We need to add or update the StockSerialItem record and the StockSerialMoves as well */
/*First need to check if the serial items already exists or not in the location to */
$SQL = "SELECT COUNT(*)
FROM stockserialitems
WHERE
stockid='" . $TrfLine->StockID . "'
AND loccode='" . $_SESSION['Transfer']->StockLocationTo . "'
AND serialno='" . $Item->BundleRef . "'";
$Result = DB_query($SQL,'<br />' . _('Could not determine if the serial item exists') );
$SerialItemExistsRow = DB_fetch_row($Result);
if($SerialItemExistsRow[0]==1) {
$SQL = "UPDATE stockserialitems SET
quantity= quantity + '" . $Item->BundleQty . "'
WHERE
stockid='" . $TrfLine->StockID . "'
AND loccode='" . $_SESSION['Transfer']->StockLocationTo . "'
AND serialno='" . $Item->BundleRef . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record could not be updated for the quantity coming in because');
$DbgMsg = _('The following SQL to update the serial stock item record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
} else {
/*Need to insert a new serial item record */
$SQL = "INSERT INTO stockserialitems (stockid,
loccode,
serialno,
quantity)
VALUES ('" . $TrfLine->StockID . "',
'" . $_SESSION['Transfer']->StockLocationTo . "',
'" . $Item->BundleRef . "',
'" . $Item->BundleQty . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock item record for the stock coming in could not be added because');
$DbgMsg = _('The following SQL to update the serial stock item record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
/* now insert the serial stock movement */
$SQL = "INSERT INTO stockserialmoves (
stockmoveno,
stockid,
serialno,
moveqty)
VALUES (" . $StkMoveNo . ",
'" . $TrfLine->StockID . "',
'" . $Item->BundleRef . "',
'" . $Item->BundleQty . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The serial stock movement record could not be inserted because');
$DbgMsg = _('The following SQL to insert the serial stock movement records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}/* foreach controlled item in the serialitems array */
} /*end if the transfer item is a controlled item */
$SQL = "UPDATE locstock
SET quantity = quantity - '" . round($TrfLine->Quantity, $TrfLine->DecimalPlaces) . "'
WHERE stockid='" . $TrfLine->StockID . "'
AND loccode='" . $_SESSION['Transfer']->StockLocationFrom . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The location stock record could not be updated because');
$DbgMsg = _('The following SQL to update the stock record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
$SQL = "UPDATE locstock
SET quantity = quantity + '" . round($TrfLine->Quantity, $TrfLine->DecimalPlaces) . "'
WHERE stockid='" . $TrfLine->StockID . "'
AND loccode='" . $_SESSION['Transfer']->StockLocationTo . "'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The location stock record could not be updated because');
$DbgMsg = _('The following SQL to update the stock record was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
// Insert incoming inventory GL transaction if any of the locations has a GL account code:
if(($_SESSION['Transfer']->StockLocationFromAccount !='' or $_SESSION['Transfer']->StockLocationToAccount !='')) {
// Get the account code:
if($_SESSION['Transfer']->StockLocationToAccount !='') {
$AccountCode = $_SESSION['Transfer']->StockLocationToAccount;
} else {
$StockGLCode = GetStockGLCode($TrfLine->StockID);// Get Category's account codes.
$AccountCode = $StockGLCode['stockact'];// Select account code for stock.
}
// Get the item cost:
$SQLstandardcost = "SELECT stockmaster.materialcost + stockmaster.labourcost + stockmaster.overheadcost AS standardcost
FROM stockmaster
WHERE stockmaster.stockid ='" . $TrfLine->StockID . "'";
$ErrMsg = _('The standard cost of the item cannot be retrieved because');
$DbgMsg = _('The SQL that failed was');
$myrow = DB_fetch_array(DB_query($SQLstandardcost,$ErrMsg,$DbgMsg));
$StandardCost = $myrow['standardcost'];// QUESTION: Standard cost for: Assembly (value="A") and Manufactured (value="M") items ?
// Insert record:
$SQL = "INSERT INTO gltrans (
periodno,
trandate,
type,
typeno,
account,
narrative,
amount)
VALUES ('" .
$PeriodNo . "','" .
$SQLTransferDate . "',
16,'" .
$_SESSION['Transfer']->TrfID . "','" .
$AccountCode . "','" .
$_SESSION['Transfer']->StockLocationTo.' - '.$TrfLine->StockID.' x '.$TrfLine->Quantity.' @ '. $StandardCost . "','" .
$TrfLine->Quantity * $StandardCost . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The incoming inventory GL transacction record could not be inserted because');
$DbgMsg = _('The following SQL to insert records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
prnMsg(_('A stock transfer for item code'). ' - ' . $TrfLine->StockID . ' ' . $TrfLine->ItemDescription . ' '. _('has been created from').' ' . $_SESSION['Transfer']->StockLocationFromName . ' '. _('to'). ' ' . $_SESSION['Transfer']->StockLocationToName . ' ' . _('for a quantity of'). ' '. $TrfLine->Quantity,'success');
if($TrfLine->CancelBalance==1) {
RecordItemCancelledInTransfer($_SESSION['Transfer']->TrfID, $TrfLine->StockID, $TrfLine->Quantity);
$sql = "UPDATE loctransfers SET recqty = recqty + '". round($TrfLine->Quantity, $TrfLine->DecimalPlaces) . "',
shipqty = recqty + '". round($TrfLine->Quantity, $TrfLine->DecimalPlaces) . "',
recdate = '".Date('Y-m-d H:i:s'). "'
WHERE reference = '". $_SESSION['Transfer']->TrfID . "'
AND stockid = '". $TrfLine->StockID."'";
} else {
$sql = "UPDATE loctransfers SET recqty = recqty + '". round($TrfLine->Quantity, $TrfLine->DecimalPlaces) . "',
recdate = '".Date('Y-m-d H:i:s'). "'
WHERE reference = '". $_SESSION['Transfer']->TrfID . "'
AND stockid = '". $TrfLine->StockID."'";
}
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('Unable to update the Location Transfer Record');
$Result = DB_query($sql, $ErrMsg, $DbgMsg, true);
unset ($_SESSION['Transfer']->LineItem[$i]);
unset ($_POST['Qty' . $i]);
} /*end if Quantity >= 0 */
if($TrfLine->CancelBalance==1) {
$sql = "UPDATE loctransfers SET shipqty = recqty
WHERE reference = '". $_SESSION['Transfer']->TrfID . "'
AND stockid = '". $TrfLine->StockID."'";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('Unable to set the quantity received to the quantity shipped to cancel the balance on this transfer line');
$Result = DB_query($sql, $ErrMsg, $DbgMsg, true);
// send an email to the inventory manager about this cancellation (as can lead to employee fraud)
if($_SESSION['InventoryManagerEmail']!='') {
$ConfirmationText = _('Cancelled balance of transfer'). ': ' . $_SESSION['Transfer']->TrfID .
"\r\n" . _('From Location') . ': ' . $_SESSION['Transfer']->StockLocationFrom .
"\r\n" . _('To Location') . ': ' . $_SESSION['Transfer']->StockLocationTo .
"\r\n" . _('Stock code') . ': ' . $TrfLine->StockID .
"\r\n" . _('Qty received') . ': ' . round($TrfLine->Quantity, $TrfLine->DecimalPlaces) .
"\r\n" . _('By user') . ': ' . $_SESSION['UserID'] .
"\r\n" . _('At') . ': ' . Date('Y-m-d H:i:s');
$EmailSubject = _('Cancelled balance of transfer'). ' ' . $_SESSION['Transfer']->TrfID;
if($_SESSION['SmtpSetting']==0) {
mail($_SESSION['InventoryManagerEmail'],$EmailSubject,$ConfirmationText);
} else{
include('includes/htmlMimeMail.php');
$mail = new htmlMimeMail();
$mail->setSubject($EmailSubject);
$mail->setText($ConfirmationText);
$result = SendmailBySmtp($mail,array($_SESSION['InventoryManagerEmail']));
}
}
}
$i++;
} /*end of foreach TransferItem */
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('Unable to COMMIT the Stock Transfer transaction');
DB_Txn_Commit();
unset($_SESSION['Transfer']->LineItem);
unset($_SESSION['Transfer']);
} /* end of if no input errors */
} /*end of PRocess Transfer */
if(isset($_GET['Trf_ID'])) {
unset($_SESSION['Transfer']);
$sql = "SELECT loctransfers.stockid,
stockmaster.description,
stockmaster.units,
stockmaster.controlled,
stockmaster.serialised,
stockmaster.perishable,
stockmaster.decimalplaces,
loctransfers.shipqty,
loctransfers.recqty,
locations.locationname as shiplocationname,
locations.glaccountcode as shipaccountcode,
reclocations.locationname as reclocationname,
reclocations.glaccountcode as recaccountcode,
loctransfers.shiploc,
loctransfers.recloc
FROM loctransfers INNER JOIN locations
ON loctransfers.shiploc=locations.loccode
INNER JOIN locations as reclocations
ON loctransfers.recloc = reclocations.loccode
INNER JOIN locationusers ON locationusers.loccode=reclocations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1
INNER JOIN stockmaster
ON loctransfers.stockid=stockmaster.stockid
WHERE reference ='" . $_GET['Trf_ID'] . "' ORDER BY loctransfers.stockid";
$ErrMsg = _('The details of transfer number') . ' ' . $_GET['Trf_ID'] . ' ' . _('could not be retrieved because') .' ';
$DbgMsg = _('The SQL to retrieve the transfer was');
$result = DB_query($sql,$ErrMsg,$DbgMsg);
if(DB_num_rows($result) == 0) {
echo '<h3>' . _('Transfer') . ' #' . $_GET['Trf_ID'] . ' '. _('Does Not Exist') . '</h3><br />';
include('includes/footer.php');
exit;
}
$myrow=DB_fetch_array($result);
$_SESSION['Transfer']= new StockTransfer($_GET['Trf_ID'],
$myrow['shiploc'],
$myrow['shiplocationname'],
$myrow['shipaccountcode'],
$myrow['recloc'],
$myrow['reclocationname'],
$myrow['recaccountcode'],
Date($_SESSION['DefaultDateFormat']) );
/*Populate the StockTransfer TransferItem s array with the lines to be transferred */
$i = 0;
do {
$_SESSION['Transfer']->TransferItem[$i]= new LineItem ($myrow['stockid'],
$myrow['description'],
$myrow['shipqty'],
$myrow['units'],
$myrow['controlled'],
$myrow['serialised'],
$myrow['perishable'],
$myrow['decimalplaces'] );
$_SESSION['Transfer']->TransferItem[$i]->PrevRecvQty = $myrow['recqty'];
$_SESSION['Transfer']->TransferItem[$i]->Quantity = $myrow['shipqty']-$myrow['recqty'];
$i++; /*numerical index for the TransferItem[] array of LineItem s */
} while ($myrow=DB_fetch_array($result));
} /* $_GET['Trf_ID'] is set */
if(isset($_SESSION['Transfer'])) {
//Begin Form for receiving shipment
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/supplier.png" title="' . _('Dispatch') .
'" alt="" />' . ' ' . $Title . '</p>';
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
prnMsg(_('Please Verify Shipment Quantities Received'),'info');
$i = 0;//Line Item Array pointer
echo '<br />
<table class="selection">';
echo '<tr>
<th colspan="7"><h3>' . _('Location Transfer Reference'). ' #' . $_SESSION['Transfer']->TrfID . ' '. _('from').' ' . $_SESSION['Transfer']->StockLocationFromName . ' '. _('to'). ' ' . $_SESSION['Transfer']->StockLocationToName . '</h3></th>
</tr>';
$tableheader = '<tr>
<th>' . _('Item Code') . '</th>
<th>' . _('Item Description'). '</th>
<th>' . _('Quantity Dispatched'). '</th>
<th>' . _('Quantity Received'). '</th>
<th>' . _('Quantity To Receive'). '</th>
<th>' . _('Units'). '</th>
<th>' . _('Cancel Balance') . '</th>
</tr>';
echo $tableheader;
foreach ($_SESSION['Transfer']->TransferItem AS $TrfLine) {
echo '<tr class="striped_row">
<td>' . $TrfLine->StockID . '</td>
<td>' . $TrfLine->ItemDescription . '</td>';
echo '<td class="number">' . locale_number_format($TrfLine->ShipQty, $TrfLine->DecimalPlaces) . '</td>';
if(isset($_POST['Qty' . $i]) AND is_numeric(filter_number_format($_POST['Qty' . $i]))) {
$_SESSION['Transfer']->TransferItem[$i]->Quantity= round(filter_number_format($_POST['Qty' . $i]),$TrfLine->DecimalPlaces);
$Qty = round(filter_number_format($_POST['Qty' . $i]),$TrfLine->DecimalPlaces);
} else if($TrfLine->Controlled==1) {
if(sizeOf($TrfLine->SerialItems)==0) {
$Qty = 0;
} else {
$Qty = $TrfLine->Quantity;
}
} else {
$Qty = $TrfLine->Quantity;
}
echo '<td class="number">' . locale_number_format($TrfLine->PrevRecvQty, $TrfLine->DecimalPlaces) . '</td>';
if($TrfLine->Controlled==1) {
echo '<td class="number"><input type="hidden" name="Qty' . $i . '" value="' . locale_number_format($Qty,$TrfLine->DecimalPlaces) . '" /><a href="' . $RootPath .'/StockTransferControlled.php?TransferItem=' . $i . '" />' . $Qty . '</a></td>';
} else {
echo '<td><input type="text" class="number" name="Qty' . $i . '" maxlength="10" size="auto" value="' . locale_number_format($Qty,$TrfLine->DecimalPlaces) . '" /></td>';
}
echo '<td>' . $TrfLine->PartUnit . '</td>';
echo '<td><input type="checkbox" name="CancelBalance' . $i . '" value="1" /></td>';
if($TrfLine->Controlled==1) {
if($TrfLine->Serialised==1) {
echo '<td><a href="' . $RootPath .'/StockTransferControlled.php?TransferItem=' . $i . '">' . _('Enter Serial Numbers') . '</a></td>';
} else {
echo '<td><a href="' . $RootPath .'/StockTransferControlled.php?TransferItem=' . $i . '">' . _('Enter Batch Refs') . '</a></td>';
}
}
echo '</tr>';
$i++; /* the array of TransferItem s is indexed numerically and i matches the index no */
} /*end of foreach TransferItem */
echo '</table>
<br />
<div class="centre">
<input type="submit" name="ProcessTransfer" value="'. _('Process Inventory Transfer'). '" />
<br />
</div>
</div>
</form>';
echo '<a href="'.htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8'). '?NewTransfer=true">' . _('Select A Different Transfer') . '</a>';
} else { /*Not $_SESSION['Transfer'] set */
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/supplier.png" title="' . _('Dispatch') . '" alt="" />' . ' ' . $Title . '</p>';
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post" id="form1">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
$LocResult = DB_query("SELECT locationname, locations.loccode FROM locations INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1 ORDER BY locationname");
echo '<table class="selection">';
echo '<tr>
<td>' . _('Select Location Receiving Into'). ':</td>
<td>';
echo '<select name="RecLocation" onchange="ReloadForm(form1.RefreshTransferList)">';
if(!isset($_POST['RecLocation'])) {
$_POST['RecLocation'] = $_SESSION['UserStockLocation'];
}
while ($myrow=DB_fetch_array($LocResult)) {
if($myrow['loccode'] == $_POST['RecLocation']) {
echo '<option selected="selected" value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
} else {
echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
}
}
echo '</select>
<input type="submit" name="RefreshTransferList" value="' . _('Refresh Transfer List') . '" /></td>
</tr>
</table>
<br />';
$sql = "SELECT DISTINCT reference,
locations.locationname as trffromloc,
shipdate
FROM loctransfers INNER JOIN locations
ON loctransfers.shiploc=locations.loccode
WHERE recloc='" . $_POST['RecLocation'] . "'
AND recqty < shipqty";
$TrfResult = DB_query($sql);
if(DB_num_rows($TrfResult)>0) {
$LocSql = "SELECT locationname FROM locations WHERE loccode='" . $_POST['RecLocation'] . "'";
$LocResult = DB_query($LocSql);
$LocRow = DB_fetch_array($LocResult);
echo '<table class="selection">';
echo '<tr><th colspan="4"><h3>' . _('Pending Transfers Into').' '.$LocRow['locationname'] . '</h3></th></tr>';
echo '<tr>
<th>' . _('Transfer Ref'). '</th>
<th>' . _('Transfer From'). '</th>
<th>' . _('Dispatch Date'). '</th></tr>';
while ($myrow=DB_fetch_array($TrfResult)) {
echo '<tr class="striped_row">
<td class="number">' . $myrow['reference'] . '</td>
<td>' . $myrow['trffromloc'] . '</td>
<td>' . ConvertSQLDateTime($myrow['shipdate']) . '</td>
<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?Trf_ID=' . $myrow['reference'] . '">' . _('Receive'). '</a></td>
</tr>';
}
echo '</table>';
} else if(!isset($_POST['ProcessTransfer'])) {
prnMsg(_('There are no incoming transfers to this location'), 'info');
}
echo '</div>
</form>';
}
include('includes/footer.php');
function RecordItemCancelledInTransfer($TransferReference, $StockID, $CancelQty){
$SQL = "INSERT INTO loctransfercancellations (
reference,
stockid,
cancelqty,
canceldate,
canceluserid)
VALUES ('" . $TransferReference . "',
'" . $StockID . "',
(SELECT (l2.shipqty-l2.recqty)
FROM loctransfers AS l2
WHERE l2.reference = '" . $TransferReference . "'
AND l2.stockid ='" . $StockID . "') - " . $CancelQty . ",
'" . Date('Y-m-d H:i:s') . "',
'" . $_SESSION['UserID'] . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The transfer cancellation record could not be inserted because');
$DbgMsg = _('The following SQL to insert records was used');
$Result = DB_query($SQL, $ErrMsg, $DbgMsg, true);
}
?>