Exemple #1
3
 function export_order($id)
 {
     global $FANNIE_OP_DB, $FANNIE_ROOT;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $order = new PurchaseOrderModel($dbc);
     $order->orderID($id);
     $order->load();
     $items = new PurchaseOrderItemsModel($dbc);
     $items->orderID($id);
     $vendor = new VendorsModel($dbc);
     $vendor->vendorID($order->vendorID());
     $vendor->load();
     $contact = new VendorContactModel($dbc);
     $contact->vendorID($order->vendorID());
     $contact->load();
     if (!class_exists('FPDF')) {
         include_once $FANNIE_ROOT . 'src/fpdf/fpdf.php';
     }
     $pdf = new FPDF('P', 'mm', 'Letter');
     $pdf->AddPage();
     $pdf->SetFont('Arial', '', '12');
     $pdf->Cell(100, 5, 'Vendor: ' . $vendor->vendorName(), 0, 0);
     $pdf->Cell(100, 5, 'Date: ' . date('Y-m-d'), 0, 0);
     $pdf->Ln();
     $pdf->Cell(100, 5, 'Phone: ' . $contact->phone(), 0, 0);
     $pdf->Cell(100, 5, 'Fax: ' . $contact->fax(), 0, 0);
     $pdf->Ln();
     $pdf->Cell(100, 5, 'Email: ' . $contact->email(), 0, 0);
     $pdf->Cell(100, 5, 'Website: ' . $contact->website(), 0, 0);
     $pdf->Ln();
     $pdf->MultiCell(0, 5, "Ordering Info:\n" . $contact->notes(), 'B');
     $pdf->Ln();
     $cur_page = 0;
     $pdf->SetFontSize(10);
     foreach ($items->find() as $obj) {
         if ($cur_page != $pdf->PageNo()) {
             $cur_page = $pdf->PageNo();
             $pdf->Cell(25, 5, 'SKU', 0, 0);
             $pdf->Cell(20, 5, 'Order Qty', 0, 0);
             $pdf->Cell(30, 5, 'Brand', 0, 0);
             $pdf->Cell(65, 5, 'Description', 0, 0);
             $pdf->Cell(20, 5, 'Case Size', 0, 0);
             $pdf->Cell(20, 5, 'Est. Cost', 0, 0);
             $pdf->Ln();
         }
         $pdf->Cell(25, 5, $obj->sku(), 0, 0);
         $pdf->Cell(20, 5, $obj->quantity(), 0, 0, 'C');
         $pdf->Cell(30, 5, $obj->brand(), 0, 0);
         $pdf->Cell(65, 5, $obj->description(), 0, 0);
         $pdf->Cell(20, 5, $obj->caseSize(), 0, 0, 'C');
         $pdf->Cell(20, 5, sprintf('%.2f', $obj->caseSize() * $obj->unitCost() * $obj->quantity()), 0, 0);
         $pdf->Ln();
     }
     $pdf->Output('order_export.pdf', 'D');
 }
Exemple #2
0
 public function export_order($id)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $order = new PurchaseOrderModel($dbc);
     $order->orderID($id);
     $order->load();
     $items = new PurchaseOrderItemsModel($dbc);
     $items->orderID($id);
     $columns = array('Product Code', 'Inventory Item', 'Invoice Number', 'Date', 'Unit', 'Quantity', 'Cost', 'Description', 'Alt. Unit Indicator', 'Alternate Unit');
     foreach ($items->find() as $obj) {
         list($units, $unit_of_measure) = $this->getUnits($obj);
         echo $obj->sku() . ',';
         echo '"' . $obj->description() . '",';
         echo $order->vendorInvoiceID() . ',';
         echo date('Ymd', strtotime($obj->receivedDate())) . ',';
         printf('%f,', $units * $obj->caseSize() * $obj->quantity());
         echo $unit_of_measure . ',';
         printf('%.2f,', $obj->unitCost() * $obj->caseSize() * $obj->quantity());
         echo '"' . $obj->description() . '",';
         echo '"",';
         // alt. indicator
         echo '"",';
         // alt. unit
         echo "\r\n";
     }
 }
Exemple #3
0
 function export_order($id)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $order = new PurchaseOrderModel($dbc);
     $order->orderID($id);
     $order->load();
     $items = new PurchaseOrderItemsModel($dbc);
     $items->orderID($id);
     $vendor = new VendorsModel($dbc);
     $vendor->vendorID($order->vendorID());
     $vendor->load();
     echo 'Vendor,"' . $vendor->vendorName() . '",Order Date,' . date('Y-m-d') . "\r\n";
     echo "\r\n";
     echo "SKU,\"Order Qty\",Brand,Description,\"Case Size\",\"Est. Cost\"\r\n";
     foreach ($items->find() as $obj) {
         echo $obj->sku() . ',';
         echo $obj->quantity() . ',';
         echo '"' . $obj->brand() . '",';
         echo '"' . $obj->description() . '",';
         echo '"' . $obj->caseSize() . '",';
         printf('%.2f', $obj->unitCost() * $obj->caseSize() * $obj->quantity());
         echo "\r\n";
     }
 }
 public function export_order($id)
 {
     $config = FannieConfig::factory();
     $dbc = FannieDB::get($config->get('OP_DB'));
     $items = new PurchaseOrderItemsModel($dbc);
     $items->orderID($id);
     $NL = "\r\n";
     echo 'productCode,quantity' . $NL;
     foreach ($items->find() as $item) {
         echo str_pad($item->sku(), 7, '0', STR_PAD_LEFT);
         echo ',';
         echo $item->quantity();
         echo $NL;
     }
 }
Exemple #5
0
 public function post_vendorID_invoice_num_po_num_invoice_date_handler()
 {
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $skus = FormLib::get('sku', array());
     $upcs = FormLib::get('upc', array());
     $descriptions = FormLib::get('desc', array());
     $cases = FormLib::get('qty', array());
     $units = FormLib::get('units', array());
     $sizes = FormLib::get('size', array());
     $costs = FormLib::get('unitCost', array());
     $totals = FormLib::get('totalCost', array());
     $order = new PurchaseOrderModel($dbc);
     $order->vendorID($this->vendorID);
     $order->creationDate($this->invoice_date);
     $order->placed(1);
     $order->placedDate($this->invoice_date);
     $order->vendorOrderID($this->po_num);
     $order->vendorInvoiceID($this->invoice_num);
     $order->userID(0);
     $orderID = $order->save();
     $checkP = $dbc->prepare('
         SELECT v.sku
         FROM vendorItems AS v
         WHERE v.vendorID=?
             AND v.upc <> \'0000000000000\'
             AND v.upc <> \'\'
             AND v.upc IS NOT NULL
             AND v.sku=?');
     $vendorItem = new VendorItemsModel($dbc);
     $item = new PurchaseOrderItemsModel($dbc);
     for ($i = 0; $i < count($skus); $i++) {
         $sku = $skus[$i];
         $upc = BarcodeLib::padUPC(isset($upcs[$i]) ? $upcs[$i] : '');
         $qty = isset($cases[$i]) ? $cases[$i] : 1;
         $caseSize = isset($units[$i]) ? $units[$i] : 1;
         $unitSize = isset($sizes[$i]) ? $sizes[$i] : '';
         $unitCost = isset($costs[$i]) ? $costs[$i] : 0;
         $totalCost = isset($totals[$i]) ? $totals[$i] : 0;
         $desc = isset($descriptions[$i]) ? substr($descriptions[$i], 0, 50) : '';
         $item->reset();
         $item->orderID($orderID);
         $item->sku($sku);
         $item->quantity($qty);
         $item->unitCost($unitCost);
         $item->caseSize($caseSize);
         $item->receivedDate($this->invoice_date);
         $item->receivedQty($qty);
         $item->receivedTotalCost($totalCost);
         $item->unitSize($unitSize);
         $item->brand('');
         $item->description($desc);
         $item->internalUPC($upc);
         $item->save();
         /**
           Add entries to vendor catalog if they don't exist
         */
         $checkR = $dbc->execute($checkP, array($this->vendorID, $sku));
         if ($checkR && $dbc->numRows($checkR) == 0) {
             $vendorItem->vendorID($this->vendorID);
             $vendorItem->sku($sku);
             $vendorItem->upc($upc);
             $vendorItem->description($desc);
             $vendorItem->brand('');
             $vendorItem->units($caseSize);
             $vendorItem->size($unitSize);
             $vendorItem->cost($unitCost);
             $vendorItem->vendorDept(0);
             $vendorItem->save();
         }
     }
     header('Location: ' . filter_input(INPUT_SERVER, 'PHP_SELF') . '?complete=' . $orderID);
     return false;
 }
Exemple #6
0
 /**
   Lots of options on this report.
 */
 function fetch_report_data()
 {
     global $FANNIE_OP_DB;
     $date1 = FormLib::get_form_value('date1', date('Y-m-d'));
     $date2 = FormLib::get_form_value('date2', date('Y-m-d'));
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $mustCodeP = $dbc->prepare('
         SELECT i.orderID,
             i.sku
         FROM PurchaseOrderItems AS i
         WHERE i.receivedDate BETWEEN ? AND ?
             AND (i.salesCode IS NULL OR i.salesCode=0)
     ');
     $codeR = $dbc->execute($mustCodeP, array($date1 . ' 00:00:00', $date2 . ' 23:59:59'));
     $model = new PurchaseOrderItemsModel($dbc);
     while ($w = $dbc->fetchRow($codeR)) {
         $model->orderID($w['orderID']);
         $model->sku($w['sku']);
         if ($model->load()) {
             $code = $model->guessCode();
             $model->salesCode($code);
             $model->save();
         }
     }
     $accounting = $this->config->get('ACCOUNTING_MODULE');
     if (!class_exists($accounting)) {
         $accounting = '\\COREPOS\\Fannie\\API\\item\\Accounting';
     }
     $codingQ = 'SELECT o.orderID, 
                     o.salesCode, 
                     i.vendorInvoiceID, 
                     SUM(o.receivedTotalCost) as rtc,
                     MAX(o.receivedDate) AS rdate
                 FROM PurchaseOrderItems AS o
                     LEFT JOIN PurchaseOrder as i ON o.orderID=i.orderID 
                 WHERE i.vendorID=? 
                     AND i.userID=0
                     AND o.receivedDate BETWEEN ? AND ?
                 GROUP BY o.orderID, o.salesCode, i.vendorInvoiceID
                 ORDER BY rdate, i.vendorInvoiceID, o.salesCode';
     $codingP = $dbc->prepare($codingQ);
     $report = array();
     $invoice_sums = array();
     $vendorID = FormLib::get('vendorID');
     $codingR = $dbc->execute($codingP, array($vendorID, $date1 . ' 00:00:00', $date2 . ' 23:59:59'));
     $orders = array();
     while ($codingW = $dbc->fetch_row($codingR)) {
         if ($codingW['rtc'] == 0) {
             // skip zero lines (tote charges)
             continue;
         }
         $code = $accounting::toPurchaseCode($codingW['salesCode']);
         if (empty($code) && $this->report_format == 'html') {
             $code = 'n/a';
         }
         $record = array('UNFI', '<a href="../ViewPurchaseOrders.php?id=' . $codingW['orderID'] . '">' . $codingW['vendorInvoiceID'] . '</a>', $codingW['rdate'], 0.0, sprintf('%.2f', $codingW['rtc']), $code);
         if (!isset($invoice_sums[$codingW['vendorInvoiceID']])) {
             $invoice_sums[$codingW['vendorInvoiceID']] = 0;
         }
         $invoice_sums[$codingW['vendorInvoiceID']] += $codingW['rtc'];
         if (!isset($orders[$codingW['orderID']])) {
             $orders[$codingW['orderID']] = array();
         }
         $orders[$codingW['orderID']][] = $record;
     }
     $po = new PurchaseOrderModel($dbc);
     foreach ($orders as $id => $data) {
         $invTTL = 0;
         for ($i = 0; $i < count($data); $i++) {
             $row = $data[$i];
             $invTTL += $row[4];
         }
         foreach ($orders[$id] as $row) {
             $row[3] = $invTTL;
             $report[] = $row;
         }
     }
     /*
     for ($i=0; $i<count($report); $i++) {
         $inv = $report[$i][1];
         $report[$i][3] = sprintf('%.2f', $invoice_sums[$inv]);
     }
     */
     return $report;
 }
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $skuCol = $this->get_column_index('sku');
     $costCol = $this->get_column_index('cost');
     $uQtyCol = $this->get_column_index('unitQty');
     $cQtyCol = $this->get_column_index('caseQty');
     $uSizeCol = $this->get_column_index('unitSize');
     $cSizeCol = $this->get_column_index('caseSize');
     $brandCol = $this->get_column_index('brand');
     $descCol = $this->get_column_index('desc');
     $upcCol = $this->get_column_index('upc');
     $upccCol = $this->get_column_index('upcc');
     $vendorID = FormLib::get('vendorID');
     $inv = FormLib::get('identifier', '');
     $orderDate = FormLib::get('orderDate', date('Y-m-d H:i:s'));
     $recvDate = FormLib::get('recvDate', '');
     $order = new PurchaseOrderModel($dbc);
     $order->vendorID($vendorID);
     $order->creationDate($orderDate);
     $order->placedDate($orderDate);
     $order->placed(1);
     $order->userID(FannieAuth::getUID());
     $order->vendorOrderID($inv);
     $order->vendorInvoiceID($inv);
     $orderID = $order->save();
     $item = new PurchaseOrderItemsModel($dbc);
     $info = new VendorItemsModel($dbc);
     $ret = '';
     foreach ($linedata as $line) {
         if (!isset($line[$skuCol])) {
             continue;
         }
         if (!isset($line[$costCol])) {
             continue;
         }
         $sku = $line[$skuCol];
         $cost = $line[$costCol];
         $cost = trim($cost, ' ');
         $cost = trim($cost, '$');
         if (!is_numeric($cost)) {
             $ret .= "<i>Omitting item {$sku}. Cost {$cost} isn't a number</i><br />";
             continue;
         }
         $unitQty = $uQtyCol !== false && isset($line[$uQtyCol]) ? $line[$uQtyCol] : 0;
         $caseQty = $cQtyCol !== false && isset($line[$cQtyCol]) ? $line[$cQtyCol] : 0;
         if ($unitQty == 0 && $caseQty == 0) {
             // no qty specified.
             continue;
         }
         $unitSize = $uSizeCol !== false && isset($line[$uSizeCol]) ? $line[$uSizeCol] : 0;
         $caseSize = $cSizeCol !== false && isset($line[$cSizeCol]) ? $line[$cSizeCol] : 0;
         $brand = $brandCol !== '' && isset($line[$brandCol]) ? $line[$brandCol] : '';
         $desc = $descCol !== false && isset($line[$descCol]) ? $line[$descCol] : '';
         $upc = '';
         if ($upcCol !== false && isset($line[$upcCol])) {
             $upc = BarcodeLib::padUPC($line[$upcCol]);
         } elseif ($upccCol !== false && isset($line[$upccCol])) {
             $upc = BarcodeLib::padUPC($line[$upccCol]);
             $upc = '0' . substr($upc, 0, 12);
         }
         $info->reset();
         $info->vendorID($vendorID);
         $info->sku($sku);
         if ($info->load()) {
             if ($brand === '') {
                 $brand = $info->brand();
             }
             if ($desc === '') {
                 $desc = $info->description();
             }
             if ($unitSize === 0) {
                 $unitSize = $info->size();
             }
             if ($caseSize === 0) {
                 $caseSize = $info->units();
             }
             $upc = $info->upc();
         }
         if ($caseQty == 0 && $unitQty != 0) {
             if ($caseSize == 0) {
                 $caseQty = $unitQty;
                 $caseSize = 1;
             } else {
                 $caseQty = $unitQty / $caseSize;
             }
         } elseif ($caseQty != 0 && $unitQty == 0) {
             if ($caseSize == 0) {
                 $unitQty = $caseQty;
                 $caseSize = 1;
             } else {
                 $unitQty = $caseQty * $caseSize;
             }
         } elseif ($caseQty != 0 && $unitQty != 0) {
             if ($caseSize == 0) {
                 $caseSize = $caseQty / $unitQty;
             }
         }
         $unitCost = $cost / $unitQty;
         $item->orderID($orderID);
         $item->sku($sku);
         if ($item->load()) {
             // multiple records for same item
             $item->quantity($caseQty + $item->quantity());
             if ($recvDate !== '') {
                 $item->receivedTotalCost($cost + $item->receivedTotalCost());
                 $item->receivedQty($caseQty + $item->receivedQty());
                 $item->receivedDate($recvDate);
             }
         } else {
             $item->quantity($caseQty);
             if ($recvDate !== '') {
                 $item->receivedTotalCost($cost);
                 $item->receivedQty($caseQty);
                 $item->receivedDate($recvDate);
             }
         }
         $item->unitCost($unitCost);
         $item->caseSize($caseSize);
         $item->brand($brand);
         $item->description($desc);
         $item->internalUPC($upc);
         $item->save();
     }
     $ret .= "<p>Import Complete";
     $ret .= '<br />';
     $ret .= '<a href="' . $this->config->get('URL') . 'purchasing/ViewPurchaseOrders.php?id=' . $orderID . '">View Order</a></p>';
     $this->results = $ret;
     return true;
 }
 public function get_id_adjust_view()
 {
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $order = new PurchaseOrderModel($dbc);
     $order->orderID($this->adjust);
     $order->load();
     $orderJSON = $order->toJSON();
     $items = new PurchaseOrderItemsModel($dbc);
     $items->orderID($this->adjust);
     $itemsJSON = '[';
     foreach ($items->find() as $item) {
         $itemsJSON .= $item->toJSON() . ',';
     }
     if (strlen($itemsJSON) > 1) {
         $itemsJSON = substr($itemsJSON, 0, strlen($itemsJSON) - 1);
     }
     $itemsJSON .= ']';
     $orderJSON = str_replace('\\', '\\\\', $orderJSON);
     $itemsJSON = str_replace('\\', '\\\\', $itemsJSON);
     $this->addOnloadCommand("existingOrder('{$orderJSON}', '{$itemsJSON}');\n");
     return $this->get_id_view();
 }
Exemple #9
0
 /**
   Create purchase orders from zipfile
   @param $zipfile filename
   @param $vendorID integer vendor ID
   @param $repeat this date has been previously imported
 */
 public static function import($zipfile, $vendorID, $repeat = false)
 {
     global $FANNIE_OP_DB;
     $za = new ZipArchive();
     $try = $za->open($zipfile);
     if ($try !== true) {
         // invalid file
         return $try;
     }
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $create = $dbc->prepare('INSERT INTO PurchaseOrder (vendorID, creationDate, placed,
                         placedDate, userID, vendorOrderID, vendorInvoiceID) VALUES
                         (?, ?, 1, ?, 0, ?, ?)');
     $find = $dbc->prepare('SELECT orderID FROM PurchaseOrder WHERE vendorID=? AND userID=0
                         AND vendorInvoiceID=?');
     $plu = $dbc->prepare('SELECT upc FROM vendorSKUtoPLU WHERE vendorID=? AND sku LIKE ?');
     $clear = $dbc->prepare('DELETE FROM PurchaseOrderItems WHERE orderID=?');
     for ($i = 0; $i < $za->numFiles; $i++) {
         $info = $za->statIndex($i);
         if (substr(strtolower($info['name']), -4) != '.csv') {
             // skip non-csv file
             continue;
         }
         $fp = $za->getStream($info['name']);
         $header_info = array();
         $item_info = array();
         while (!feof($fp)) {
             $line = fgetcsv($fp);
             if (strtolower($line[0]) == 'header') {
                 $header_info = self::parseHeader($line);
             } else {
                 if (strtolower($line[0]) == 'detail') {
                     $item = self::parseItem($line, $vendorID);
                     $item_info[] = $item;
                 }
             }
         }
         if (count($item_info) > 0) {
             $id = false;
             // check whether order already exists
             $idR = $dbc->execute($find, array($vendorID, $header_info['vendorInvoiceID']));
             if ($dbc->num_rows($idR) > 0) {
                 $idW = $dbc->fetch_row($idR);
                 $id = $idW['orderID'];
                 $dbc->execute($clear, array($id));
             }
             if (!$id) {
                 // date has not been downloaded before OR
                 // date previously did not include this invoice
                 $dbc->execute($create, array($vendorID, $header_info['placedDate'], $header_info['placedDate'], $header_info['vendorOrderID'], $header_info['vendorInvoiceID']));
                 $id = $dbc->insert_id();
             }
             foreach ($item_info as $item) {
                 $model = new PurchaseOrderItemsModel($dbc);
                 $model->orderID($id);
                 $model->sku($item['sku']);
                 if ($model->load()) {
                     // sometimes an invoice contains multiple
                     // lines with the same product SKU
                     // sum those so the single record in
                     // PurchaseOrderItems is correct
                     $item['quantity'] += $model->quantity();
                     $item['receivedQty'] += $model->receivedQty();
                     $item['receivedTotalCost'] += $model->receivedTotalCost();
                 }
                 $model->quantity($item['quantity']);
                 $model->receivedQty($item['receivedQty']);
                 $model->receivedTotalCost($item['receivedTotalCost']);
                 $model->unitCost($item['unitCost']);
                 $model->caseSize($item['caseSize']);
                 $model->receivedDate($header_info['receivedDate']);
                 $model->unitSize($item['unitSize']);
                 $model->brand($item['brand']);
                 $model->description($item['description']);
                 $model->internalUPC($item['upc']);
                 $pluCheck = $dbc->execute($plu, array($vendorID, $item['sku']));
                 if ($dbc->num_rows($pluCheck) > 0) {
                     $pluInfo = $dbc->fetch_row($pluCheck);
                     $model->internalUPC($pluInfo['upc']);
                 }
                 if ($model->salesCode() == '') {
                     $code = $model->guessCode();
                     $model->salesCode($code);
                 }
                 $model->save();
             }
         }
     }
     return true;
 }
Exemple #10
0
 /**
   Receiving AJAX callback.
   Lookup item in the order and display form fields
   to enter required info 
 */
 public function get_id_sku_handler()
 {
     $dbc = $this->connection;
     $model = new PurchaseOrderItemsModel($dbc);
     $model->orderID($this->id);
     $model->sku($this->sku);
     // lookup by SKU but if nothing is found
     // try using the value as a UPC instead
     $found = false;
     if ($model->load()) {
         $found = true;
     } else {
         $model->reset();
         $model->orderID($this->id);
         $model->internalUPC(BarcodeLib::padUPC($this->sku));
         $matches = $model->find();
         if (count($matches) == 1) {
             $model = $matches[0];
             $found = true;
         }
     }
     // item not in order. need all fields to add it.
     if (!$found) {
         echo '<div class="alert alert-danger">SKU not found in order</div>';
         echo '<form onsubmit="saveReceive(); return false;">';
         echo '<table class="table table-bordered">';
         echo '<tr><th>SKU</th><th>UPC</th><th>Brand</th><th>Description</th>
             <th>Qty Ordered</th><th>Cost (est)</th><th>Qty Received</th><th>Cost Received</th></tr>';
         $order = new PurchaseOrderModel($dbc);
         $order->orderID($this->id);
         $order->load();
         $item = new VendorItemsModel($dbc);
         $item->vendorID($order->vendorID());
         $item->sku($this->sku);
         $item->load();
         printf('<tr>
             <td>%s<input type="hidden" name="sku" value="%s" /></td>
             <td><input type="text" class="form-control" name="upc" value="%s" /></td>
             <td><input type="text" class="form-control" name="brand" value="%s" /></td>
             <td><input type="text" class="form-control" name="description" value="%s" /></td>
             <td><input type="text" class="form-control" name="orderQty" value="%s" /></td>
             <td><input type="text" class="form-control" name="orderCost" value="%.2f" /></td>
             <td><input type="text" class="form-control" name="receiveQty" value="%s" /></td>
             <td><input type="text" class="form-control" name="receiveCost" value="%.2f" /></td>
             <td><button type="submit" class="btn btn-default">Add New Item</button><input type="hidden" name="id" value="%d" /></td>
             </tr>', $this->sku, $this->sku, $item->upc(), $item->brand(), $item->description(), 1, $item->cost() * $item->units(), 0, 0, $this->id);
         echo '</table>';
         echo '</form>';
     } else {
         // item in order. just need received qty and cost
         echo '<form onsubmit="saveReceive(); return false;">';
         echo '<table class="table table-bordered">';
         echo '<tr><th>SKU</th><th>UPC</th><th>Brand</th><th>Description</th>
             <th>Qty Ordered</th><th>Cost (est)</th><th>Qty Received</th><th>Cost Received</th></tr>';
         if ($model->receivedQty() === null) {
             $model->receivedQty($model->quantity());
         }
         if ($model->receivedTotalCost() === null) {
             $model->receivedTotalCost($model->quantity() * $model->unitCost() * $model->caseSize());
         }
         printf('<tr>
             <td>%s<input type="hidden" name="sku" value="%s" /></td>
             <td>%s</td>
             <td>%s</td>
             <td>%s</td>
             <td>%s</td>
             <td>%.2f</td>
             <td><input type="text" class="form-control" name="qty" value="%s" /></td>
             <td><input type="text" class="form-control" name="cost" value="%.2f" /></td>
             <td><button type="submit" class="btn btn-default">Save</button><input type="hidden" name="id" value="%d" /></td>
             </tr>', $this->sku, $this->sku, $model->internalUPC(), $model->brand(), $model->description(), $model->quantity(), $model->quantity() * $model->unitCost() * $model->caseSize(), $model->receivedQty(), $model->receivedTotalCost(), $this->id);
         echo '</table>';
         echo '</form>';
     }
     return false;
 }
 /**
   AJAX call: ?id=<vendor ID>&sku=<vendor SKU>&qty=<# of cases>
   Add the given SKU & qty to the order
 */
 function get_id_sku_qty_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $orderID = $this->getOrderID($this->id, FannieAuth::getUID($this->current_user));
     $vitem = new VendorItemsModel($dbc);
     $vitem->vendorID($this->id);
     $vitem->sku($this->sku);
     $vitem->load();
     $pitem = new PurchaseOrderItemsModel($dbc);
     $pitem->orderID($orderID);
     $pitem->sku($this->sku);
     $pitem->quantity($this->qty);
     $pitem->unitCost($vitem->cost());
     $pitem->caseSize($vitem->units());
     $pitem->unitSize($vitem->size());
     $pitem->brand($vitem->brand());
     $pitem->description($vitem->description());
     $pitem->internalUPC($vitem->upc());
     $pitem->save();
     $ret = array();
     $pitem->reset();
     $pitem->orderID($orderID);
     $pitem->sku($this->sku);
     if (count($pitem->find()) == 0) {
         $ret['error'] = 'Error saving entry';
     } else {
         $ret['sidebar'] = $this->calculate_sidebar();
     }
     echo json_encode($ret);
     return False;
 }
 function get_id_sku_index_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $orderID = $this->getOrderID($this->id, FannieAuth::getUID($this->current_user));
     $ret = array('qty' => 0, 'index' => $this->index);
     $item = new PurchaseOrderItemsModel($dbc);
     $item->orderID($orderID);
     $item->sku($this->sku);
     if ($item->load()) {
         $ret['qty'] = $item->quantity();
     }
     echo json_encode($ret);
     return false;
 }