-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetorderstatus.php
More file actions
232 lines (196 loc) · 7.96 KB
/
getorderstatus.php
File metadata and controls
232 lines (196 loc) · 7.96 KB
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
<?php
//08.25.2015 ghh - this function is responsible for returning a list of
//vendor names and ID's for this specific server
function getOrderStatus( $vars, $responsetype )
{
global $db;
$ar = safetycheck( $vars, $responsetype );
if ( !isset( $ar ) || !$ar['InternalID'] > 0 )
{
RestLog("16587 - Insufficient data provided for creating order \n".print_r($vars,true)."\n");
RestUtils::sendResponse(400, "16587 - Insufficient data provided" ); //Internal Server Error
return false;
}
//08.26.2015 ghh - to insure a dealer can't get a status on another dealers
//orders we need to make sure we include their internal id plus their dealerid
$query = "select * from PurchaseOrders where POID=$ar[InternalID] and
ClientID=$ar[ClientID]";
if (!$result = $db->sql_query($query))
{
RestLog("Error 16588 in query: $query\n".$db->sql_error());
RestUtils::sendResponse(500, "16588 - There was a problem locating the order"); //Internal Server Error
return false;
}
//08.26.2015 ghh - if no order was found then return
if ($db->sql_numrows($result) == 0 )
{
RestLog("Error 16589 in query: $query\n".$db->sql_error());
RestUtils::sendResponse(500, "16589 - There was a problem locating the order"); //Internal Server Error
return false;
}
//08.26.2015 ghh - now we grab what we need from the PO in order to return it
//to the caller
$row = $db->sql_fetchrow( $result );
$rst['InternalID'] = $row['POID'];
$rst['PONumber'] = $row['PONumber'];
$rst['Discount'] = $row['Discount'];
$rst['ExpectedDelivery'] = $row['ExpectedDeliveryDate'];
$rst['PayByDiscAmt'] = $row['PaybyDiscountAmount'];
$rst['PayByDiscPercent'] = $row['PaybyDiscountPercent'];
$rst['PayByDiscDate'] = $row['PaybyDiscountDate'];
$rst['Status'] = $row['Status'];
//08.26.2015 ghh - now we're going to start grabbing shipping information
$query = "select distinct( BoxID )
from PurchaseOrderItems a, PurchaseOrderShipped b
where b.POItemID=a.POItemID and a.POID=$ar[InternalID]";
if (!$result = $db->sql_query($query))
{
RestLog("Error 16590 in query: $query\n".$db->sql_error());
RestUtils::sendResponse(500, "16590 - There was a problem locating the order"); //Internal Server Error
return false;
}
//now we loop through our boxes and grab related items
$i = 0;
while( $row = $db->sql_fetchrow( $result ) )
{
//as we loop through each item, we need to gra
$query = "select a.POItemID, a.BoxID, a.QtyShipped, a.Cost, b.ItemNumber,
b.VendorID, b.Quantity, b.SupersessionID, b.CrossreferenceID,
c.WarehouseID, c.TrackingNumber, c.VendorInvoiceNumber,
c.DueDate, c.ShipVendorID, c.ShipDate, c.ShipCost, c.BoxNumber
from PurchaseOrderShipped a, PurchaseOrderItems b, ShippedBoxes c
where a.POItemID=b.POItemID and b.POID=$ar[InternalID] and
a.BoxID=$row[BoxID] order by BoxID, ItemNumber";
if (!$boxresult = $db->sql_query($query))
{
RestLog("Error 16591 in query: $query\n".$db->sql_error());
RestUtils::sendResponse(500, "16591 - There was a problem getting list of shipped boxes"); //Internal Server Error
return false;
}
//now loop through boxes and their items and lets build up our box
//array
$shipvendorid = 0;
$boxid = 0;
$j = 0;
$items = array();
while ( $boxrow = $db->sql_fetchrow( $boxresult ) )
{
//08.26.2015 ghh - we only enter the main box section when
//we actually change boxes since we don't want to repeat this
if ( $boxid != $boxrow['BoxID'] )
{
$boxid = $boxrow['BoxID'];
$box[$i]['BoxNumber'] = $boxrow['BoxNumber'];
$box[$i]['ShipVendor'] = getShipVendorName( $boxrow['ShipVendorID'] );
$box[$i]['ShipVendor'] = $shippingvendor;
$box[$i]['TrackingNumber'] = $boxrow['TrackingNumber'];
$box[$i]['VendorInvoice'] = $boxrow['VendorInvoice'];
$box[$i]['DueDate'] = $boxrow['DueDate'];
$box[$i]['ShipCost'] = $boxrow['ShipCost'];
$box[$i]['ShipDate'] = $boxrow['ShipDate'];
}
//now we build up our list of items
$items[$j]['VendorID'] = $boxrow['VendorID'];
$items[$j]['ItemNumber'] = $boxrow['ItemNumber'];
$items[$j]['QtyShipped'] = $boxrow['QtyShipped'];
$items[$j]['Cost'] = $boxrow['Cost'];
//this deals with supersession data and would only be supplied if the supplier
//elected to ship the super part instead of the original one ordered.
if ( $boxrow['SupersessionID'] > 0 )
{
$query = "select ItemNumber from Items where ItemID=$boxrow[SupersessionID]";
if (!$superresult = $db->sql_query($query))
{
RestLog("Error 16597 in query: $query\n".$db->sql_error());
RestUtils::sendResponse(500, "16597 - There was a problem getting supersession number"); //Internal Server Error
return false;
}
$superrow = $db->sql_fetchrow( $superresult );
$items[$j]['SuppersessionNumber'] = $superrow['ItemNumber'];
}
//this grabs crossreference information if it was entered and would only be
//entered if the supplier elected to ship a different vendors part than what
//was ordered
if ( $boxrow['CrossReferenceID'] > 0 )
{
$query = "select ItemNumber, VendorID from Items
where ItemID=$boxrow[CrossreferenceID]";
if (!$crossresult = $db->sql_query($query))
{
RestLog("Error 16598 in query: $query\n".$db->sql_error());
RestUtils::sendResponse(500, "16598 - There was a problem getting supersession number"); //Internal Server Error
return false;
}
$crossrow = $db->sql_fetchrow( $crossresult );
$items[$j]['CrossRefNumber'] = $crossrow['ItemNumber'];
$items[$j]['CrossRefVendorID'] = $crossrow['VendorID'];
}
$j++;
}
//08.26.2015 ghh - now we need to save our items into our box
$box[$i]['Items'] = $items;
$i++;
}
//now that we're done looping through boxes we need to save them as part of the return
//array
$rst['Boxes'] = $box;
##########################################UNITS###############################################################
//now we're going to grab a list of units that may have been shipped so we can send that
//information back as well.
$query = "select * from PurchaseOrderUnits where POID=$ar[InternalID] and
ShipDate is not null";
if (!$result = $db->sql_query($query))
{
RestLog("Error 16599 in query: $query\n".$db->sql_error());
RestUtils::sendResponse(500, "16599 - There was a problem getting supersession number"); //Internal Server Error
return false;
}
$i = 0;
while ( $row = $db->sql_fetchrow( $result ) )
{
$units[$i]['VendorID'] = $row['VendorID'];
$units[$i]['ModelNumber'] = $row['ModelNumber'];
//need to lookup up ship vendor name to send back
$units[$i]['ShipVendor'] = getShipVendorName( $row['ShipVendorID'] );
$units[$i]['TrackingNumber'] = $row['TrackingNumber'];
$units[$i]['OrderCode'] = $row['OrderCode'];
$units[$i]['Year'] = $row['Year'];
$units[$i]['Colors'] = $row['Colors'];
$units[$i]['Details'] = $row['Details'];
$units[$i]['Serial-VIN'] = $row['SerialVIN'];
$units[$i]['Cost'] = $row['Cost'];
$units[$i]['ShipCharge'] = $row['ShipCharge'];
$units[$i]['ShipDate'] = $row['ShipDate'];
$units[$i]['EstShipDate'] = $row['EstShipDate'];
$i++;
}
$rst['Units'] = $units;
###############################BACKORDERS##############################
//lastly we're going to go grab the list of backorders that might exist so that we
//can return them as well.
$query = "select b.*, a.ItemNumber, a.VendorID
from PurchaseOrderItems a, PurchaseOrderBackOrder b
where a.POID=$ar[InternalID] and
a.POItemID=b.POItemID";
if (!$result = $db->sql_query($query))
{
RestLog("Error 16602 in query: $query\n".$db->sql_error());
RestUtils::sendResponse(500, "16602 - There was a problem getting backorder information"); //Internal Server Error
return false;
}
$i = 0;
while ( $row = $db->sql_fetchrow( $result ) )
{
$back[$i]['ItemNumber'] = $row['ItemID'];
$back[$i]['VendorID'] = $row['VendorID'];
$back[$i]['QtyPending'] = $row['QtyPending'];
$back[$i]['EstShipDate'] = $row['EstShipDate'];
$back[$i]['ShipNote'] = $row['ShipNote'];
$i++;
}
$rst['Backorders'] = $back;
RestLog("Successful Request\n");
RestUtils::sendResponse(200,json_encode( stripHTML( $rst ) ));
return true;
}
?>