function getItemInfo($vars, $responsetype)
{
global $db;
$ar = $vars;
if (empty($ar) || !isset($ar['VendorID']) || !isset($ar['ItemNumber'])) {
RestLog("16584 - Insufficient data provided for creating order \n" . print_r($vars, true) . "\n");
RestUtils::sendResponse(400, "16584 - Insufficient data provided");
//Internal Server Error
return false;
}
//now we grab inventory records for the requested item and build up our package to return
//to the dealer
//08.28.2015 ghh - added weight field
$query = "select Items.ItemID, Items.MSRP, NLA, CloseOut,\n\t\t\t\tPriceCode, Cost, MAP, Category, \n\t\t\t\tManufItemNumber, ManufName, SupersessionID, Weight\n\t\t\t\tfrom Items\n\t\t\t\twhere \n\t\t\t\tItemNumber='{$ar['ItemNumber']}' and\n\t\t\t\tVendorID={$ar['VendorID']}";
if (!($result = $db->sql_query($query))) {
RestLog("Error 16585 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16585 - There was a problem getting item information.");
//Internal Server Error
return false;
}
$row = $db->sql_fetchrow($result);
$item['OrigManufName'] = $row['ManufName'];
$item['OrigManufNumber'] = $row['ManufItemNumber'];
$item['NLA'] = $row['NLA'];
$item['CloseOut'] = $row['CloseOut'];
$item['MSRP'] = $row['MSRP'];
$item['Category'] = $row['Category'];
$item['MAP'] = $row['MAP'];
$item['Weight'] = $row['Weight'];
//08.28.2015 ghh -
if ($row['ItemID'] > 0) {
$item['Cost'] = getItemCost($row['ItemID'], $ar['DealerID'], $row['PriceCode'], $row['Cost'], $row['MSRP']);
}
//08.25.2015 ghh - if BSV asked for full detail then we're also going to send back
//images data and other items of interest
if ($row['SupersessionID'] > 0) {
$query = "select ItemNumber from Items where ItemID={$row['SupersessionID']}";
if (!($tmpresult = $db->sql_query($query))) {
RestLog("Error 16586 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16586 - There was a problem retrieving the supersession number");
//Internal Server Error
return false;
}
$tmprow = $db->sql_fetchrow($tmpresult);
$item['SupersessionNumber'] = $tmprow['ItemNumber'];
}
RestLog("Successful Request\n");
//08.10.2012 naj - return code 200 OK.
RestUtils::sendResponse(200, json_encode(stripHTML($item)));
return true;
}
//.........这里部分代码省略.........
$unitrow = $db->sql_fetchrow($unitresult);
if ($db->sql_numrows($unitresult) == 0) {
RestLog("Error 16561 The Unit Model you sent is not valid");
RestUtils::sendResponse(500, "16561 - The Model Number or VendorID passed are invalid");
return false;
}
//now lets see if we can calculate the cost for the current dealer
$cost = getUnitCost($unitrow['ModelID'], $vars['DealerID'], $unitrow['Cost']);
} else {
RestLog("Error 16563 {$row['PONumber']} is missing a vendor id\n");
RestUtils::sendResponse(409, "Error 16563 {$key['ModelNumber']} is missing a vendor id");
return false;
}
//08.25.2015 ghh - if we have less line items on the PO than the qty we need then
//we're going to insert a few more rows until they match.
if ($db->sql_numrows($result) < $key['Qty']) {
for ($i = 0; $i < $key['Qty'] - $db->sql_numrows($result); $i++) {
$query = "insert into PurchaseOrderUnits (POID,ModelNumber,\n\t\t\t\t\t ModelID,OrderCode,Year, Colors, VendorID, Cost) values \n\t\t\t\t\t ( '{$poid}','{$key['ModelNumber']}',{$unitrow['ModelID']},'{$unitrow['OrderCode']}',\n\t\t\t\t\t {$year},'{$key['Colors']}', {$key['VendorID']}, '{$cost}')";
if (!($tmpresult = $db->sql_query($query))) {
RestLog("Error 16564 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16564 - There was an error trying to add the unit to the order");
return false;
}
}
//08.25.2015 ghh - update the PO with the current time for last modified date
$query = "update PurchaseOrders set DateLastModified=now() where POID = {$poid}";
if (!($result = $db->sql_query($query))) {
RestLog("Error 16565 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16565 - There was a problem updating the last modified date");
//Internal Server Error
return false;
}
} else {
if ($db->sql_numrows($result) > $key['Qty']) {
$qtytoremove = $db->sql_numrows($result) - $key['Qty'];
$query = "select POUnitID from PurchaseOrderUnits where POID={$poid}\n\t\t\t\t\t\tand ModelID={$unitrow['ModelID']} limit {$qtytoremove}";
if (!($tmpresult = $db->sql_query($query))) {
RestLog("Error 16566 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16566 - There was a problem deleting changed models");
//Internal Server Error
return false;
}
while ($tmprow = $db->sql_fetchrow($tmpresult)) {
$query = "delete from PurchaseOrderUnits where POUnitID={$tmprow['POUnitID']}";
if (!($tmp2result = $db->sql_query($query))) {
RestLog("Error 16567 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16567 - There was a problem deleting changed models");
//Internal Server Error
return false;
}
}
//08.25.2015 ghh - update the PO with the current time for last modified date
$query = "update PurchaseOrders set DateLastModified=now() where POID = {$poid}";
if (!($result = $db->sql_query($query))) {
RestLog("Error 16568 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16568 - There was a problem updating the last modified date");
//Internal Server Error
return false;
}
}
}
//08.25.2015 ghh - first lets grab total qty for the current model
$query = "select sum(Qty) as Qty from UnitModelStock where ModelID={$unitrow['ModelID']}";
if (!($qtyresult = $db->sql_query($query))) {
RestLog("Error 16570 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16570 - There was an error getting total instock");
return false;
}
$tmprow = $db->sql_fetchrow($qtyresult);
$stockqty = $tmprow['Qty'];
$query = "select count(POUnitID) as Qty from PurchaseOrderUnits \n\t\t\t\twhere ModelID={$unitrow['ModelID']} and SerialVin is null";
if (!($qtyresult = $db->sql_query($query))) {
RestLog("Error 16571 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16571 - There was an error getting total instock");
return false;
}
$tmprow = $db->sql_fetchrow($qtyresult);
$orderqty = $tmprow['Qty'];
//08.21.2015 ghh - now we have all of our return information and have updated or
//inserted into the items list for the purchase order so we only need to build our
//response now.
$units[$i]['VendorID'] = $key['VendorID'];
$units[$i]['ModelNumber'] = $key['ModelNumber'];
$units[$i]['NLA'] = $unitrow['NLA'];
$units[$i]['Closeout'] = $unitrow['CloseOut'];
$units[$i]['MSRP'] = $unitrow['MSRP'];
$units[$i]['Cost'] = $cost;
if ($stockqty - $onorderqty < 0) {
$units[$i]['BackorderQty'] = abs($stockqty - $onorderqty);
} else {
$units[$i]['BackorderQty'] = 0;
}
$i++;
}
$rst['Units'] = $units;
RestLog("Successful Request\n");
//08.10.2012 naj - return code 200 OK.
RestUtils::sendResponse(200, json_encode(stripHTML($rst)));
return true;
}
function getInventory($vars, $responsetype)
{
global $db;
$ar = $vars;
if (empty($ar) || !isset($ar['VendorID']) || !isset($ar['ItemNumber'])) {
RestLog("16575 - Insufficient data provided for creating order \n" . print_r($vars, true) . "\n");
RestUtils::sendResponse(400, "16575 - Insufficient data provided");
//Internal Server Error
return false;
}
//now we grab inventory records for the requested item and build up our package to return
//to the dealer
//08.26.2015 rch - Moving ItemStock,Warehouses,DaysToFullfill to left outer joins
//to account for not stocking an item or not putting in warehouse
//08.28.2015 ghh - added Weight
$query = "select Items.ItemID, Items.MSRP, NLA, CloseOut,\n\t\t\t\tPriceCode, Cost, MAP, Category, WarehouseName, \n\t\t\t\tWarehouseState, Qty, DaysToArrive, Weight\n\t\t\t\tManufItemNumber, ManufName, SupersessionID\n\t\t\t\tfrom Items\n\t\t\t\tleft outer join ItemStock on ItemStock.ItemID = Items.ItemID \n\t\t\t\tleft outer join Warehouses on Warehouses.WarehouseID = ItemStock.WarehouseID\n\t\t\t\tleft outer join DaysToFullfill on DaysToFullfill.WarehouseID = ItemStock.WarehouseID\n\t\t\t\twhere Items.ItemNumber='{$ar['ItemNumber']}' and\n\t\t\t\tItems.VendorID={$ar['VendorID']} and\n\t\t\t\tDaysToFullfill.DealerID={$ar['DealerID']} order by DaysToArrive";
if (!($result = $db->sql_query($query))) {
RestLog("Error 16576 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16576 - There was a problem getting inventory information.");
//Internal Server Error
return false;
}
$i = 0;
$itemid = 0;
while ($row = $db->sql_fetchrow($result)) {
//grabbing our details on first run through as no sense in grabbing
//more than once.
if ($itemid == 0) {
$itemid = $row['ItemID'];
$OrigManufName = $row['ManufName'];
$OrigManufNumber = $row['ManufItemNumber'];
$NLA = $row['NLA'];
$CloseOut = $row['CloseOut'];
$MSRP = $row['MSRP'];
$Category = $row['Category'];
$MAP = $row['MAP'];
$Weight = $row['Weight'];
//08.28.2015 ghh -
}
$rst[$i]['WarehouseName'] = $row['WarehouseName'];
$rst[$i]['WarehouseState'] = $row['WarehouseState'];
$rst[$i]['Qty'] = $row['Qty'];
$rst[$i]['DaysToArrive'] = $row['DaysToArrive'];
$i++;
}
if ($itemid > 0) {
$item['Warehouses'] = $rst;
$item['MSRP'] = $MSRP;
if ($itemid > 0) {
$item['Cost'] = getItemCost($itemid, $ar['DealerID'], $row['PriceCode'], $row['Cost'], $row['MSRP']);
}
//08.25.2015 ghh - if BSV asked for full detail then we're also going to send back
//images data and other items of interest
if ($row['SupersessionID'] > 0) {
$query = "select ItemNumber from Items where ItemID={$row['SupersessionID']}";
if (!($tmpresult = $db->sql_query($query))) {
RestLog("Error 16578 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16578 - There was a problem retrieving the supersession number");
//Internal Server Error
return false;
}
$tmprow = $db->sql_fetchrow($tmpresult);
$item['SupersessionNumber'] = $tmprow['ItemNumber'];
}
$item['OrigManufName'] = $ManufName;
$item['OrigManufNumber'] = $ManufItemNumber;
$item['NLA'] = $NLA;
$item['Category'] = $Category;
$item['MAP'] = $MAP;
//08.25.2015 ghh - now we're getting a list of images that may exist for this
//item
$query = "select * from ItemImages where ItemID={$itemid}";
if (!($result = $db->sql_query($query))) {
RestLog("Error 16577 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16577 - There was a problem retrieving a list of images");
//Internal Server Error
return false;
}
$i = 0;
while ($row = $db->sql_fetchrow($result)) {
$img[$i]['ImageURL'] = $row['ImageURL'];
$img[$i]['ImageSize'] = $row['ImageSize'];
$i++;
}
$item['Images'] = $img;
} else {
RestLog("Error 16635 The item number being requested doesn't exist\n");
RestUtils::sendResponse(500, "16635 - The Item you requested was not found.");
//Internal Server Error
return false;
}
RestLog("Successful Request\n");
//08.10.2012 naj - return code 200 OK.
RestUtils::sendResponse(200, json_encode(stripHTML($item)));
return true;
}
function getModel($vars, $responsetype)
{
global $db;
$ar = $vars;
if (empty($ar) || !isset($ar['VendorID']) || !isset($ar['ModelNumber']) || !isset($ar['Year'])) {
RestLog("16579 - Insufficient data provided for creating order \n" . print_r($vars, true) . "\n");
RestUtils::sendResponse(400, "16579 - Insufficient data provided");
//Internal Server Error
return false;
}
$ar['ModelNumberNoFormat'] = preg_replace('/[^a-zA-Z0-9]/', '', $ar['ModelNumber']);
//strip formatting.
//now we grab inventory records for the requested item and build up our package to return
//to the dealer
$query = "select ModelID, OrderCode, Colors, ModelName, VehicleTypeID, NLA, CloseOut,\n\t\t\t\t\tCost, MSRP, MAP, Description from UnitModel where VendorID=\n\t\t\t\t\t{$ar['VendorID']} and ModelNumberNoFormat='{$ar['ModelNumberNoFormat']}' and\n\t\t\t\t\tYear={$ar['Year']}";
if (!($result = $db->sql_query($query))) {
RestLog("Error 16581 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16581 - There was a problem getting model information.");
//Internal Server Error
return false;
}
$row = $db->sql_fetchrow($result);
$unit['OrderCode'] = $row['OrderCode'];
$unit['Colors'] = $row['Colors'];
$unit['ModelName'] = $row['ModelName'];
$unit['NLA'] = $row['NLA'];
$unit['CloseOut'] = $row['CloseOut'];
$unit['Cost'] = getUnitCost($row['ModelID'], $ar['DealerID'], $row['Cost']);
$unit['MSRP'] = $row['MSRP'];
$unit['MAP'] = $row['MAP'];
$unit['Description'] = $row['Description'];
$modelid = $row['ModelID'];
if ($modelid > 0) {
//08.25.2015 ghh - now we grab unit inventory information
$query = "select Warehouses.WarehouseName, Warehouses.WarehouseState,\n\t\t\t\t\tQty, DaysToArrive \n\t\t\t\t\tfrom Warehouses, UnitModelStock, DaysToFullfill\n\t\t\t\t\twhere Warehouses.WarehouseID=UnitModelStock.WarehouseID and\n\t\t\t\t\tUnitModelStock.ModelID={$row['ModelID']} and\n\t\t\t\t\tUnitModelStock.WarehouseID=DaysToFullfill.WarehouseID and\n\t\t\t\t\tDaysToFullfill.DealerID={$ar['DealerID']} order by DaysToArrive";
if (!($result = $db->sql_query($query))) {
RestLog("Error 16582 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16582 - There was a problem getting model warehouse information.");
//Internal Server Error
return false;
}
$i = 0;
while ($row = $db->sql_fetchrow($result)) {
$rst[$i]['WarehouseName'] = $row['WarehouseName'];
$rst[$i]['WarehouseState'] = $row['WarehouseState'];
$rst[$i]['Qty'] = $row['Qty'];
$rst[$i]['DaysToArrive'] = $row['DaysToArrive'];
$i++;
}
$unit['Warehouses'] = $rst;
//08.25.2015 ghh - now we're getting a list of images that may exist for this
//item
$query = "select * from UnitModelImages where ModelID={$modelid}";
if (!($result = $db->sql_query($query))) {
RestLog("Error 16583 in query: {$query}\n" . $db->sql_error());
RestUtils::sendResponse(500, "16583 - There was a problem retrieving a list of images");
//Internal Server Error
return false;
}
$i = 0;
while ($row = $db->sql_fetchrow($result)) {
$img[$i]['ImageURL'] = $row['ImageURL'];
$img[$i]['ImageSize'] = $row['ImageSize'];
$i++;
}
$unit['Images'] = $img;
}
RestLog("Successful Request\n");
RestUtils::sendResponse(200, json_encode(stripHTML($unit)));
return true;
}
请发表评论