forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorkOrderCosting.php
598 lines (521 loc) · 22.4 KB
/
WorkOrderCosting.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
<?php
include('includes/session.php');
$Title = _('Work Order Costing');
include('includes/header.php');
include('includes/SQL_CommonFunctions.inc');
if (isset($_GET['WO'])) {
$SelectedWO = $_GET['WO'];
} elseif (isset($_POST['WO'])){
$SelectedWO = $_POST['WO'];
} else {
unset($SelectedWO);
}
echo '<a href="'. $RootPath . '/SelectWorkOrder.php">' . _('Back to Work Orders'). '</a>
<br />
<p class="page_title_text">
<img src="'.$RootPath.'/css/'.$Theme.'/images/maintenance.png" title="' .
_('Search') . '" 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'] . '" />';
if (!isset($SelectedWO)) {
/* This page can only be called with a work order number */
echo '<div class="centre><a href="' . $RootPath . '/SelectWorkOrder.php">' .
_('Select a work order') . '</a></div>';
prnMsg(_('This page can only be opened if a work order has been selected.'),'info');
include ('includes/footer.php');
exit;
} else {
echo '<input type="hidden" name="WO" value="' .$SelectedWO . '" />';
$_POST['WO']=$SelectedWO;
}
$ErrMsg = _('Could not retrieve the details of the selected work order');
$WOResult = DB_query("SELECT workorders.loccode,
locations.locationname,
workorders.requiredby,
workorders.startdate,
workorders.closed,
closecomments
FROM workorders INNER JOIN locations
ON workorders.loccode=locations.loccode
INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canupd=1
WHERE workorders.wo='" . $_POST['WO'] . "'",
$ErrMsg);
if (DB_num_rows($WOResult)==0){
prnMsg(_('The selected work order item cannot be retrieved from the database'),'info');
include('includes/footer.php');
exit;
}
$WorkOrderRow = DB_fetch_array($WOResult);
echo '<table class="selection">
<tr>
<td class="label">' . _('Work order') . ':</td>
<td>' . $_POST['WO'] . '</td>
<td class="label">' . _('Manufactured at') . ':</td>
<td>' . $WorkOrderRow['locationname'] . '</td>
<td class="label">' . _('Required By') . ':</td>
<td>' . ConvertSQLDate($WorkOrderRow['requiredby']) . '</td>
</tr>
</table>
<br />';
$WOItemsResult = DB_query("SELECT woitems.stockid,
stockmaster.description,
stockmaster.decimalplaces,
stockmaster.units,
stockmaster.materialcost+stockmaster.labourcost+stockmaster.overheadcost AS currcost,
woitems.qtyreqd,
woitems.qtyrecd,
woitems.stdcost,
stockcategory.materialuseagevarac,
stockcategory.purchpricevaract,
stockcategory.wipact,
stockcategory.stockact
FROM woitems INNER JOIN stockmaster
ON woitems.stockid=stockmaster.stockid
INNER JOIN stockcategory
ON stockmaster.categoryid=stockcategory.categoryid
WHERE woitems.wo='". $_POST['WO'] . "'",
$ErrMsg);
echo '<table class="selection">
<tr>
<th>' . _('Item') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('Quantity Required') . '</th>
<th>' . _('Units') . '</th>
<th>' . _('Quantity Received') . '</th>
<th>' . _('Status') . '</th>
<th>' . _('Receive') . '</th>
<th>' . _('Issue') . '</th>
</tr>';
$TotalStdValueRecd =0;
while ($WORow = DB_fetch_array($WOItemsResult)){
echo '<tr>
<td>' . $WORow['stockid'] . '</td>
<td>' . $WORow['description'] . '</td>
<td class="number">' . locale_number_format($WORow['qtyreqd'],$WORow['decimalplaces']) . '</td>
<td>' . $WORow['units'] . '</td>
<td class="number">' . locale_number_format($WORow['qtyrecd'],$WORow['decimalplaces']) . '</td>
<td class="number"><a href="'. $RootPath . '/WorkOrderStatus.php?WO=' . $_POST['WO'] . '&StockID=' . $WORow['stockid'] . '">' . _('Status') . '</a></td>
<td class="number"><a href="'. $RootPath . '/WorkOrderReceive.php?WO=' . $_POST['WO'] . '&StockID=' . $WORow['stockid'] . '">' . _('Receive') . '</a></td>
<td class="number"><a href="'. $RootPath . '/WorkOrderIssue.php?WO=' . $_POST['WO'] . '&StockID=' . $WORow['stockid'] . '">' . _('Issue') . '</a></td>
</tr>';
$TotalStdValueRecd +=($WORow['stdcost']*$WORow['qtyrecd']);
}
echo '</table>
<br />
<table class="selection">';
echo '<tr>
<th>' . _('Item') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('Qty Reqd') . '</th>
<th>' . _('Cost Reqd') . '</th>
<th>' . _('Date Issued') . '</th>
<th>' . _('Issued Qty') . '</th>
<th>' . _('Issued Cost') . '</th>
<th>' . _('Usage Variance') . '</th>
<th>' . _('Cost Variance') . '</th>
</tr>';
$RequirementsResult = DB_query("SELECT worequirements.stockid,
stockmaster.description,
stockmaster.decimalplaces,
worequirements.stdcost,
SUM(worequirements.qtypu*woitems.qtyrecd) AS requiredqty,
SUM(worequirements.stdcost*worequirements.qtypu*woitems.qtyrecd) AS expectedcost,
AVG(worequirements.qtypu) as qtypu
FROM worequirements INNER JOIN stockmaster
ON worequirements.stockid=stockmaster.stockid
INNER JOIN woitems ON woitems.stockid=worequirements.parentstockid AND woitems.wo=worequirements.wo
WHERE worequirements.wo='" . $_POST['WO'] . "'
GROUP BY worequirements.stockid,
stockmaster.description,
stockmaster.decimalplaces,
worequirements.stdcost
ORDER BY worequirements.stockid");
$TotalUsageVar =0;
$TotalCostVar =0;
$TotalIssuedCost=0;
$TotalReqdCost=0;
$RequiredItems =array();
$RequiredQty = array();
$RequiredStocks = array();
$CostVariedStocks = array();
$CurrStock = '';
$CurrQty = 0;
while ($RequirementsRow = DB_fetch_array($RequirementsResult)){
if ($CurrStock == '') {
$CurrStock = $RequirementsRow['stockid'];
}
if ($CurrStock == $RequirementsRow['stockid']) {
if (in_array($RequirementsRow['stockid'],$RequiredStocks)){
$CurrQty += $RequirementsRow['requiredqty'];
} else {
$CurrQty = $RequirementsRow['requiredqty'];
}
} else {//stock changed
$CostVariedStocks[] = array('stockid'=>$CurrStock,'totalreqqty'=>$CurrQty);
$CurrStock = $RequirementsRow['stockid'];
$CurrQty = $RequirementsRow['requiredqty'];
}
$RequiredStocks[] = $RequirementsRow['stockid'];
}
DB_data_seek($RequirementsResult,0);
while ($RequirementsRow = DB_fetch_array($RequirementsResult)){
$RequiredItems[] = $RequirementsRow['stockid'];
echo '<tr class="striped_row">
<td>' . $RequirementsRow['stockid'] . '</td>
<td>' . $RequirementsRow['description'] . '</td>
</tr>';
$IssuesResult = DB_query("SELECT stockmoves.trandate,
stockmoves.qty,
stockmoves.standardcost,
stockmaster.decimalplaces
FROM stockmoves INNER JOIN stockmaster
ON stockmoves.stockid = stockmaster.stockid
WHERE stockmoves.type=28
AND stockmoves.reference = '" . $_POST['WO'] . "'
AND stockmoves.stockid = '" . $RequirementsRow['stockid'] . "'",
_('Could not retrieve the issues of the item because:'));
$IssueQty =0;
$IssueCost=0;
if (DB_num_rows($IssuesResult)>0){
while ($IssuesRow = DB_fetch_array($IssuesResult)){
echo '<tr class="striped_row">
<td colspan="4"></td>
<td>' . ConvertSQLDate($IssuesRow['trandate']) . '</td>
<td class="number">' . locale_number_format(-$IssuesRow['qty'],$RequirementsRow['decimalplaces']) . '</td>
<td class="number">' . locale_number_format(-($IssuesRow['qty']*$IssuesRow['standardcost']),$IssuesRow['decimalplaces']) . '</td>
</tr>';
$IssueQty -= $IssuesRow['qty'];// because qty for the stock movement will be negative
$IssueCost -= ($IssuesRow['qty']*$IssuesRow['standardcost']);
}
echo '<tr class="striped_row">
<td colspan="9"><hr /></td>
</tr>';
}
if ($IssueQty != 0){
$MultiCost = false;
foreach ($CostVariedStocks as $key=>$value){
if ($value['stockid'] == $RequirementsRow['stockid']){
if ($value['totalreqqty']!=0){
$CostVar = $IssueQty * $RequirementsRow['requiredqty']/$value['totalreqqty']*(($RequirementsRow['stdcost']) -($IssueCost/$IssueQty));
} else {
$CostVar = 0;
}
$MultiCost = true;
break;
}
}
if (!$MultiCost){
$CostVar = $IssueQty *(($RequirementsRow['stdcost']) -($IssueCost/$IssueQty));
}
} else {
$CostVar = 0;
}
/*Required quantity is the quantity required of the component based on the quantity of the finished item received */
$UsageVar =($RequirementsRow['requiredqty']-$IssueQty)*($RequirementsRow['stdcost']);
echo '<tr class="striped_row">
<td colspan="2"></td>
<td class="number">' . locale_number_format($RequirementsRow['requiredqty'],$RequirementsRow['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($RequirementsRow['expectedcost'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td></td>
<td class="number">' . locale_number_format($IssueQty,$RequirementsRow['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($IssueCost,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($UsageVar,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($CostVar,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
</tr>';
$TotalReqdCost += $RequirementsRow['expectedcost'];
$TotalIssuedCost += $IssueCost;
$TotalCostVar += $CostVar;
$TotalUsageVar += $UsageVar;
echo '<tr>
<td colspan="9"><hr /></td>
</tr>';
}
//Now need to run through the issues to the work order that weren't in the requirements
$sql = "SELECT stockmoves.stockid,
stockmaster.description,
stockmaster.decimalplaces,
trandate,
qty,
stockmoves.standardcost
FROM stockmoves INNER JOIN stockmaster
ON stockmoves.stockid=stockmaster.stockid
WHERE stockmoves.type=28
AND reference = '" . $_POST['WO'] . "'
AND stockmoves.stockid NOT IN
(SELECT worequirements.stockid
FROM worequirements
WHERE worequirements.wo='" . $_POST['WO'] . "')";
$WOIssuesResult = DB_query($sql,_('Could not get issues that were not required by the BOM because'));
if (DB_num_rows($WOIssuesResult)>0){
while ($WOIssuesRow = DB_fetch_array($WOIssuesResult)){
echo '<tr class="striped_row">
<td>' . $WOIssuesRow['stockid'] . '</td>
<td>' . $WOIssuesRow['description'] . '</td>
<td class="number">0</td>
<td class="number">0</td>
<td>' . ConvertSQLDate($WOIssuesRow['trandate']) . '</td>
<td class="number">' . locale_number_format(-$WOIssuesRow['qty'],$WOIssuesRow['decimalplaces']) . '</td>
<td class="number">' . locale_number_format(-$WOIssuesRow['qty']*$WOIssuesRow['standardcost'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($WOIssuesRow['qty']*$WOIssuesRow['standardcost'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">0</td>
</tr>';
$TotalUsageVar += ($WOIssuesRow['qty']*$WOIssuesRow['standardcost']);
}
}
# <!-- <td colspan="5"></td> -->
echo '<tr>
<td colspan="3"></td>
<td><hr/></td>
<td colspan="2"></td>
<td colspan="3"><hr /></td>
</tr>';
echo '<tr>
<td colspan="2" class="number">' . _('Totals') . '</td>
<td></td>
<td class="number">' . locale_number_format($TotalReqdCost,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td></td><td></td>
<td class="number">' . locale_number_format($TotalIssuedCost,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($TotalUsageVar,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($TotalCostVar,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
</tr>';
echo '<tr>
<td colspan="3"></td>
<td><hr/></td>
<td colspan="2"></td>
<td colspan="3"><hr /></td>
</tr>';
If (isset($_POST['Close'])) {
DB_data_seek($WOItemsResult,0);
$NoItemsOnWO = DB_num_rows($WOItemsResult);
$TotalVariance = $TotalUsageVar + $TotalCostVar;
$PeriodNo = GetPeriod(Date($_SESSION['DefaultDateFormat']));
$WOCloseNo = GetNextTransNo(29);
$TransResult = DB_Txn_Begin();
while ($WORow = DB_fetch_array($WOItemsResult)){
if ($TotalStdValueRecd==0){
$ShareProportion = 1/$NoItemsOnWO;
} else {
$ShareProportion = ($WORow['stdcost']*$WORow['qtyrecd'])/$TotalStdValueRecd;
}
if ($_SESSION['WeightedAverageCosting']==1){
//we need to post the variances to stock and update the weighted average cost
/* need to get the current total quantity on hand
if the quantity on hand is less than the quantity received on the work order
then some of the variance needs to be written off to P & L and only the proportion
of the variance relating to the stock still on hand should be posted to the stock value
*/
$TotOnHandResult =DB_query("SELECT SUM(quantity)
FROM locstock
WHERE stockid='" . $WORow['stockid'] . "'");
$TotOnHandRow = DB_fetch_row($TotOnHandResult);
$TotalOnHand = $TotOnHandRow[0];
if ($TotalOnHand >= $WORow['qtyrecd']){
$ProportionOnHand = 1;
}else {
$ProportionOnHand = 1 - (($WORow['qtyrecd']- $TotalOnHand)/$WORow['qtyrecd']);
}
if ($_SESSION['CompanyRecord']['gllink_stock']==1 AND $TotalVariance!=0){
//need to get the current cost of the item
if ($ProportionOnHand < 1){
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (29,
'" . $WOCloseNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $WORow['materialuseagevarac'] . "',
'" . $_POST['WO'] . ' - ' . $WORow['stockid'] . ' ' . _('share of variance') . "',
'" .round((-$TotalCostVar*$ShareProportion*(1-$ProportionOnHand)),$_SESSION['CompanyRecord']['decimalplaces']) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL posting for the work order variance could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
}
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (29,
'" . $WOCloseNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $WORow['stockact'] . "',
'" . $_POST['WO'] . ' - ' . $WORow['stockid'] . ' ' . _('share of variance') . "',
'" . round((-$TotalCostVar*$ShareProportion*$ProportionOnHand),$_SESSION['CompanyRecord']['decimalplaces']) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL posting for the work order variance could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (29,
'" . $WOCloseNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $WORow['wipact'] . "',
'" . $_POST['WO'] . ' - ' . $WORow['stockid'] . ' ' . _('share of variance') . "',
'" . round(($TotalCostVar*$ShareProportion),$_SESSION['CompanyRecord']['decimalplaces']) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL posting for the WIP side of the work order variance posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
}
if ($TotalOnHand>0) {//to avoid negative quantity make cost data abnormal
$NewCost = $WORow['currcost'] +(-$TotalCostVar* $ShareProportion *$ProportionOnHand)/$TotalOnHand;
} else {
$NewCost = $WORow['currcost'];
}
$SQL = "UPDATE stockmaster SET
materialcost='" . $NewCost . "',
labourcost=0,
overheadcost=0,
lastcost='" . $WORow['currcost'] . "',
lastcostupdate = '" . Date('Y-m-d') . "'
WHERE stockid='" . $WORow['stockid'] . "'";
$ErrMsg = _('The cost details for the stock item could not be updated because');
$DbgMsg = _('The SQL that failed was');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
} else { //we are standard costing post the variances
if ($_SESSION['CompanyRecord']['gllink_stock']==1 AND $TotalUsageVar!=0){
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (29,
'" . $WOCloseNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $WORow['materialuseagevarac'] . "',
'" . $_POST['WO'] . ' - ' . $WORow['stockid'] . ' ' . _('share of usage variance') . "',
'" . round((-$TotalUsageVar*$ShareProportion),$_SESSION['CompanyRecord']['decimalplaces']) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL posting for the material usage variance could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (29,
'" . $WOCloseNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $WORow['wipact'] . "',
'" . $_POST['WO'] . ' - ' . $WORow['stockid'] . ' ' . _('share of usage variance') . "',
'" . round(($TotalUsageVar*$ShareProportion),$_SESSION['CompanyRecord']['decimalplaces']) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL posting for the WIP side of the usage variance posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
}//end if gl-stock linked and a usage variance exists
if ($_SESSION['CompanyRecord']['gllink_stock']==1 AND $TotalCostVar!=0){
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (29,
'" . $WOCloseNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $WORow['purchpricevaract'] . "',
'" . $_POST['WO'] . ' - ' . $WORow['stockid'] . ' ' . _('share of cost variance') . "',
'" . round((-$TotalCostVar*$ShareProportion),$_SESSION['CompanyRecord']['decimalplaces']) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL posting for the cost variance could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
$SQL = "INSERT INTO gltrans (type,
typeno,
trandate,
periodno,
account,
narrative,
amount)
VALUES (29,
'" . $WOCloseNo . "',
'" . Date('Y-m-d') . "',
'" . $PeriodNo . "',
'" . $WORow['wipact'] . "',
'" . $_POST['WO'] . ' - ' . $WORow['stockid'] . ' ' . _('share of cost variance') . "',
'" . round(($TotalCostVar*$ShareProportion),$_SESSION['CompanyRecord']['decimalplaces']) . "')";
$ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The GL posting for the WIP side of the cost variance posting could not be inserted because');
$DbgMsg = _('The following SQL to insert the GLTrans record was used');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
} //end of if gl-stock integrated and there's a cost variance
} //end of standard costing section
} // end loop around the items on the work order
$CloseWOResult =DB_query("UPDATE workorders SET closed=1, closecomments = '". $_POST['CloseComments'] ."' WHERE wo='" .$_POST['WO'] . "'",
_('Could not update the work order to closed because:'),
_('The SQL used to close the work order was:'),
true);
$DeleteAnyWOSerialNos = DB_query("DELETE FROM woserialnos WHERE wo='" . $_POST['WO'] . "'",
_('Could not delete the predefined work order serial numbers'),
_('The SQL used to delete the predefined serial numbers was:'),
true);
$TransResult = DB_Txn_Commit();
if ($_SESSION['CompanyRecord']['gllink_stock']==1){
if ($_SESSION['WeightedAverageCosting']==1){
prnMsg(_('The item cost as calculated from the work order has been applied against the weighted average cost and the necessary GL journals created to update stock as a result of closing this work order'),'success');
} else {
prnMsg(_('The work order has been closed and general ledger entries made for the variances on the work order'),'success');
}
} else {
if ($_SESSION['WeightedAverageCosting']==1){
prnMsg(_('The item costs resulting from the work order have been applied against the weighted average stock value of the items on the work order, and the work order has been closed'),'success');
} else {
prnMsg(_('The work order has been closed'),'success');
}
}
$WorkOrderRow['closed']=1;
}//end close button hit by user
if ($WorkOrderRow['closed']==0){
$ReadOnly='';
} else{
$ReadOnly='readonly';
if (!isset($_POST['CloseComments'])) {
$_POST['CloseComments'] = $WorkOrderRow['closecomments'];
}
}
echo '<tr>
<td colspan="9">
<div class="centre">
<textarea ' . $ReadOnly . ' style="width:100%" rows="5" cols="80" name="CloseComments" >' . $_POST['CloseComments'] . '</textarea>
</div>
</td>
</tr>';
if ($WorkOrderRow['closed']==0){
echo '<tr>
<td colspan="9">
<div class="centre">
<input type="submit" name="Close" value="' . _('Close This Work Order') . '" onclick="return confirm(\'' . _('Closing the work order takes the variances to the general ledger (if integrated). The work order will no longer be able to have manufactured goods received entered against it or materials issued to it.') . ' ' . _('Are You Sure?') . '\');" />
</div>
</td>
</tr>';
} else {
echo '<tr>
<td colspan="9">' . _('This work order is closed and cannot accept additional issues of materials or receipts of manufactured items') . '</td>
</tr>';
}
echo '</table>
</div>
</form>';
include('includes/footer.php');
?>