-
Notifications
You must be signed in to change notification settings - Fork 1
/
DemandWorkOrders.php
executable file
·175 lines (165 loc) · 6 KB
/
DemandWorkOrders.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
<?php
// create work orders for all finished products with sales orders that exceed on hand and on work order quantities
$PageSecurity = 10;
include('includes/session.inc');
$title = _('Demand Work Orders');
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
$SQL = "SELECT stockmaster.stockid,
stockmaster.description,
SUM(locstock.quantity) AS qoh,
stockmaster.units,
stockmaster.eoq AS eoq
FROM stockmaster,
locstock
WHERE stockmaster.stockid=locstock.stockid
AND stockmaster.categoryid='F'
GROUP BY stockmaster.stockid,
stockmaster.description,
stockmaster.units
ORDER BY stockmaster.stockid";
$StockItemsResult = DB_query($SQL,$db,$ErrMsg,$DbgMsg);
echo '<CENTER><TABLE>';
echo '<tr><td class="label">Stock ID</td>';
echo '<td class="label">Work Order</td>';
echo '<td class="label">Description</td>';
echo '<td class="label">Quantity</td>';
echo '<td class="label">Picture</td>';
echo '<td class="label">Drawing</td></tr>';
while ($myrow=DB_fetch_array($StockItemsResult)) {
$StockId = $myrow['stockid'];
$StockQOH = $myrow['qoh'];
$StockEOQ = $myrow['eoq'];
$StockDescription = $myrow['description'];
$StockQOWO = 0;
$sql3 = "SELECT SUM(woitems.qtyreqd-woitems.qtyrecd) AS qtywo
FROM woitems INNER JOIN workorders
ON woitems.wo=workorders.wo
WHERE workorders.closed=0
AND woitems.stockid='" . $StockId . "'";
$ErrMsg = _('The quantity on work orders for this product cannot be retrieved because');
$QOOResult = DB_query($sql3,$db,$ErrMsg);
if (DB_num_rows($QOOResult)==1){
$QOORow = DB_fetch_row($QOOResult);
$StockQOWO += $QOORow[0];
}
$StockDemand =0;
$DemResult = DB_query("SELECT SUM(salesorderdetails.quantity-salesorderdetails.qtyinvoiced) AS demand,
salesorderdetails.itemdue,
salesorders.deliverydate
FROM salesorderdetails INNER JOIN salesorders
ON salesorders.orderno = salesorderdetails.orderno
WHERE salesorderdetails.completed=0
AND salesorders.quotation=0
AND salesorderdetails.stkcode='" . $StockId . "'
AND salesorderdetails.qtyinvoiced < salesorderdetails.quantity
GROUP BY salesorderdetails.stkcode",
$db);
$DemRow = DB_fetch_row($DemResult);
$StockDemand = $DemRow[0];
$DemandDate = $DemRow[1];
If(strlen(trim($DemandDate)) == 0)
{
$DemandDate = $DemRow[2];
}
If($StockQOH < 0)
{
$StockQOH = 0;
}
If($StockQOH + $StockQOWO - $StockDemand < 0)
{
$DemandQuantity = $StockDemand - ($StockQOH + $StockQOWO);
If($StockEOQ > 0)
{
If($StockEOQ > $DemandQuantity)
{
$DemandQuantity = $StockEOQ;
}
else
{
$EOQMultiple = Round(($DemandQuantity/$StockEOQ)+.49,0);
$DemandQuantity = $StockEOQ*$EOQMultiple;
}
}
$WO = GetNextTransNo(30,$db);
// echo $WO. "= WO<BR>";
$InsWOResult = DB_query("INSERT INTO workorders (wo,
loccode,
requiredby,
startdate)
VALUES (" . $WO . ",
'" . $_SESSION['UserStockLocation'] . "',
'" . $DemandDate . "',
'" . Date('Y-m-d'). "')",
$db);
$sql = "INSERT INTO woitems (wo,
stockid,
qtyreqd,
stdcost)
VALUES ( " . $WO . ",
'" . $StockId . "',
" . $DemandQuantity . ",
0)";
$result = DB_query($sql,$db,$ErrMsg);
$sql2 = "INSERT INTO worequirements (wo,
parentstockid,
stockid,
qtypu,
stdcost,
autoissue)
SELECT " . $WO . ",
bom.parent,
bom.component,
bom.quantity,
(materialcost+labourcost+overheadcost)*bom.quantity,
autoissue
FROM bom INNER JOIN stockmaster
ON bom.component=stockmaster.stockid
WHERE parent='" . $StockId . "'
AND loccode ='" . $_POST['StockLocation'] . "'";
$result = DB_query($sql2,$db,$ErrMsg);
echo '<tr><TD>' . $StockId . '</TD>';
echo '<td>' . $WO . '</td>';
echo '<TD>' .$StockDescription . '</td>';
echo '<td class="label">' . $DemandQuantity .'</td>';
$PictureToDisplay = '/srv/www/htdocs/batavg/webERP2/companies/' . $_SESSION['DatabaseName'] . '/part_pics/' . $StockId . '.jpg' ;
If(file_exists ( $PictureToDisplay))
{
echo '<td class="label">OK</td>';
}
else
{
echo '<td class="label">Need Picture</td>';
}
$DrawingPath = "/srv/www/htdocs/batavg/" . $rootpath . "/companies/" . $_SESSION['DatabaseName'] . '/Drawings';
$FileToDisplay = '';
If($handle = opendir($DrawingPath))
{
While(false !== ($file = readdir($handle)))
{
If(strpos($file,$StockId))
{
$FileToDisplay = Trim($file);
break;
}
If(strlen(trim($FileToDisplay)) > 0)
{
break;
}
}
}
If(file_exists ( $DrawingPath . "/" . $FileToDisplay) and strlen(trim($FileToDisplay)) > 0)
{
echo '<td class="label">OK</td>';
}
else
{
echo '<td class="label">Need Drawing</td>';
}
echo '</tr>';
}
}
echo '</table>';
echo '<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>';
include('includes/footer.inc');
?>