Skip to content

Commit

Permalink
Re-process USF invoices safely
Browse files Browse the repository at this point in the history
  • Loading branch information
gohanman committed Oct 31, 2019
1 parent a953605 commit 904acc2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions fannie/modules/plugins2.0/USFoodsInvoiceGrabber/USFTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function run()
}

$this->connection->startTransaction();
$first = true;
while (!feof($fp)) {
$data = fgetcsv($fp);

Expand Down Expand Up @@ -88,11 +89,11 @@ public function run()
$unitPrice = round($unitPrice, 3);

$upc = $this->updateCatalog($vendorID, $sku, $item, $brand, $size, $units, $unitPrice, $doUpdates);
$orderID = $this->findPO($store, $invoice, $vendorID, $orderDate);
$orderID = $this->findPO($store, $invoice, $vendorID, $orderDate, $first);
if (!$orderID) continue;
$this->updatePO($orderID, $shipDate, $ordered, $shipped, $sku, $upc, $item, $brand, $size, $units, $unitPrice, $fullPrice);
$orders[$orderID] = $invoice;
$count++;
$first = false;
}
$this->connection->commitTransaction();
}
Expand Down Expand Up @@ -159,7 +160,7 @@ private function updatePO($orderID, $shipDate, $ordered, $shipped, $sku, $upc, $
}

private $poP = false;
private function findPO($store, $invoice, $vendor, $date)
private function findPO($store, $invoice, $vendor, $date, $first)
{
if (!$this->poP) {
$this->poP = $this->connection->prepare("SELECT orderID FROM PurchaseOrder WHERE storeID=? AND vendorID=? AND vendorInvoiceID=?");
Expand All @@ -176,6 +177,11 @@ private function findPO($store, $invoice, $vendor, $date)
$model->vendorInvoiceID($invoice);
$orderID = $model->save();

} elseif ($first) {
// zero out old amounts to avoid doubling them on re-import
$prep = $this->connection->prepare("UPDATE PurchaseOrderItems SET quantity=0, receivedQty=0, receivedTotalCost=0
WHERE orderID=?");
$this->connection->execute($prep, array($orderID));
}

return $orderID;
Expand Down

0 comments on commit 904acc2

Please sign in to comment.