예제 #1
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;
 }
예제 #2
0
 public function post_id_handler()
 {
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $ret = array('error' => false);
     $date = FormLib::get('order-date', date('Y-m-d'));
     $po_num = FormLib::get('po-number');
     $inv_num = FormLib::get('inv-number');
     $sku = FormLib::get('sku', array());
     $upc = FormLib::get('upc', array());
     $cases = FormLib::get('cases', array());
     $caseSize = FormLib::get('case-size', array());
     $total = FormLib::get('total', array());
     $brand = FormLib::get('brand', array());
     $description = FormLib::get('description', array());
     if (count($sku) == 0) {
         $ret['error'] = true;
         $ret['message'] = 'Order must have at least one item';
         echo json_encode($ret);
         return false;
     }
     /**
       Queries to check for vendorItems entries
     */
     $skuP = $dbc->prepare('
         SELECT size
         FROM vendorItems
         WHERE vendorID=?
             AND sku=?');
     $upcP = $dbc->prepare('
         SELECT size
         FROM vendorItems
         WHERE vendorID=?
             AND upc=?');
     $vitem = new VendorItemsModel($dbc);
     /**
       Create parent record for the order
     */
     $po = new PurchaseOrderModel($dbc);
     $po->vendorID($this->id);
     $po->creationDate($date);
     $po->placed(1);
     $po->placedDate($date);
     $po->userID(FannieAuth::getUID());
     $po->vendorOrderID($po_num);
     $po->vendorInvoiceID($inv_num);
     // if an orderID is supplied, update the existing order
     if (FormLib::get('order-id') !== '' && is_numeric(FormLib::get('order-id'))) {
         $orderID = FormLib::get('order-id');
         $po->orderID($orderID);
         $po->save();
     } else {
         $orderID = $po->save();
     }
     if (!$orderID) {
         $ret['error'] = true;
         $ret['message'] = 'Could not create new order';
         echo json_encode($ret);
         return false;
     }
     /**
       Create item records for the order
     */
     $pitem = new PurchaseOrderItemsModel($dbc);
     for ($i = 0; $i < count($sku); $i++) {
         $pitem->reset();
         $pitem->orderID($orderID);
         $pitem->sku($sku[$i]);
         $units = $caseSize[$i];
         $qty = $cases[$i];
         $unitCost = $total[$i] / $qty / $units;
         /**
           Multiple same-SKU records
           Sum the quantities and costs to merge
           into a single record
         */
         if ($pitem->load()) {
             $qty += $pitem->receivedQty();
             $total[$i] += $pitem->receivedTotalCost();
         }
         $pitem->quantity($qty);
         $pitem->caseSize($units);
         $pitem->unitSize('');
         $pitem->unitCost($unitCost);
         $pitem->receivedDate($date);
         $pitem->receivedQty($qty);
         $pitem->receivedTotalCost($total[$i]);
         $pitem->brand($brand[$i]);
         $pitem->description($description[$i]);
         $pitem->internalUPC($upc[$i]);
         /**
           Try to look up unit size using
           vendorID+sku or vendorID+upc.
           This avoids making unit size a required
           field *and* checks for an existing
           vendorItems record
         */
         $size = false;
         $skuR = $dbc->execute($skuP, array($this->id, $sku[$i]));
         if ($skuR && $dbc->numRows($skuR)) {
             $size = true;
             $w = $dbc->fetchRow($skuR);
             $pitem->unitSize($w['size']);
         }
         if ($size === false) {
             $upcR = $dbc->execute($upcP, array($this->id, $upc[$i]));
             if ($upcR && $dbc->numRows($upcR)) {
                 $size = true;
                 $w = $dbc->fetchRow($upcR);
                 $pitem->unitSize($w['size']);
             }
         }
         $pitem->save();
         /**
           If no vendorItems record exists for this
           SKU or UPC then create one
         */
         if ($size === false) {
             $vitem->reset();
             $vitem->vendorID($this->id);
             $vitem->sku($sku[$i]);
             $vitem->upc($upc[$i]);
             $vitem->brand($brand[$i]);
             $vitem->description($description[$i]);
             $vitem->size('');
             $vitem->units($qty);
             $vitem->cost($unitCost);
             $vitem->saleCost(0.0);
             $vitem->vendorDept(0);
             $vitem->save();
         }
     }
     $ret['order_id'] = $orderID;
     echo json_encode($ret);
     return false;
 }
예제 #3
0
 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;
 }
예제 #4
0
 function get_id_view()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $order = new PurchaseOrderModel($dbc);
     $order->orderID($this->id);
     $order->load();
     $vendor = new VendorsModel($dbc);
     $vendor->vendorID($order->vendorID());
     $vendor->load();
     $ret = '<p><div class="form-inline">';
     $ret .= '<b>Vendor</b>: ' . $vendor->vendorName();
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<b>Created</b>: ' . $order->creationDate();
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<b>Placed</b>: <span id="orderPlacedSpan">' . ($order->placed() ? $order->placedDate() : 'n/a') . '</span>';
     $ret .= '<input type="checkbox" ' . ($order->placed() ? 'checked' : '') . ' id="placedCheckbox"
             onclick="togglePlaced(' . $this->id . ');" />';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= 'Export as: <select id="exporterSelect" class="form-control">';
     $dh = opendir('exporters');
     while (($file = readdir($dh)) !== False) {
         if (substr($file, -4) != '.php') {
             continue;
         }
         include 'exporters/' . $file;
         $class = substr($file, 0, strlen($file) - 4);
         if (!class_exists($class)) {
             continue;
         }
         $obj = new $class();
         if (!isset($obj->nice_name)) {
             continue;
         }
         $ret .= '<option value="' . $class . '">' . $obj->nice_name . '</option>';
     }
     $ret .= '</select> ';
     $ret .= '<button type="submit" class="btn btn-default" onclick="doExport(' . $this->id . ');return false;">Export</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;';
     $init = $order->placed() ? 'init=placed' : 'init=pending';
     $ret .= '<button type="button" class="btn btn-default" 
         onclick="location=\'ViewPurchaseOrders.php?' . $init . '\'; return false;">All Orders</button>';
     $ret .= '</div></p>';
     $ret .= '<div class="row"><div class="col-sm-6">';
     $ret .= '<table class="table table-bordered"><tr><th colspan="2">Coding(s)</th>';
     $ret .= '<td><b>PO#</b>: ' . $order->vendorOrderID() . '</td>';
     $ret .= '<td><b>Invoice#</b>: ' . $order->vendorInvoiceID() . '</td>';
     $ret .= '</tr>';
     $ret .= '{{CODING}}';
     $ret .= '</table>';
     $ret .= '</div><div class="col-sm-6">';
     if (!$order->placed()) {
         $ret .= '<button class="btn btn-default"
             onclick="location=\'EditOnePurchaseOrder.php?id=' . $order->vendorID() . '\'; return false;">Add Items</button>';
         $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
         $ret .= '<button class="btn btn-default" onclick="deleteOrder(' . $this->id . '); return false;">Delete Order</button>';
     } else {
         $ret .= '<a class="btn btn-default"
             href="ManualPurchaseOrderPage.php?id=' . $order->vendorID() . '&adjust=' . $this->id . '">Edit Order</a>';
         $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
         $ret .= '<a class="btn btn-default"
             href="ViewPurchaseOrders.php?id=' . $this->id . '&receive=1">Receive Order</a>';
         $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
         $ret .= '<a class="btn btn-default"
             href="ViewPurchaseOrders.php?id=' . $this->id . '&recode=1">Alter Codings</a>';
     }
     $ret .= '</div></div>';
     $model = new PurchaseOrderItemsModel($dbc);
     $model->orderID($this->id);
     $codings = array();
     $accounting = $this->config->get('ACCOUNTING_MODULE');
     if (!class_exists($accounting)) {
         $accounting = '\\COREPOS\\Fannie\\API\\item\\Accounting';
     }
     $ret .= '<table class="table tablesorter"><thead>';
     $ret .= '<tr><th>Coding</th><th>SKU</th><th>UPC</th><th>Brand</th><th>Description</th>
         <th>Unit Size</th><th>Units/Case</th><th>Cases</th>
         <th>Est. Cost</th><th>&nbsp;</th><th>Received</th>
         <th>Rec. Qty</th><th>Rec. Cost</th></tr></thead><tbody>';
     foreach ($model->find() as $obj) {
         $css = '';
         if ($obj->receivedQty() == 0 && $obj->quantity() != 0) {
             $css = 'class="danger"';
         } elseif ($obj->receivedQty() < $obj->quantity()) {
             $css = 'class="warning"';
         }
         if ($obj->salesCode() == '') {
             $code = $obj->guessCode();
             $obj->salesCode($code);
             $obj->save();
         }
         $coding = (int) $obj->salesCode();
         $coding = $accounting::toPurchaseCode($coding);
         if (!isset($codings[$coding])) {
             $codings[$coding] = 0.0;
         }
         $codings[$coding] += $obj->receivedTotalCost();
         $ret .= sprintf('<tr %s><td>%d</td><td>%s</td>
                 <td><a href="../item/ItemEditorPage.php?searchupc=%s">%s</a></td><td>%s</td><td>%s</td>
                 <td>%s</td><td>%s</td><td>%d</td><td>%.2f</td>
                 <td>&nbsp;</td><td>%s</td><td>%d</td><td>%.2f</td>
                 </tr>', $css, $accounting::toPurchaseCode($obj->salesCode()), $obj->sku(), $obj->internalUPC(), $obj->internalUPC(), $obj->brand(), $obj->description(), $obj->unitSize(), $obj->caseSize(), $obj->quantity(), $obj->quantity() * $obj->caseSize() * $obj->unitCost(), date('Y-m-d', strtotime($obj->receivedDate())), $obj->receivedQty(), $obj->receivedTotalCost());
     }
     $ret .= '</tbody></table>';
     $coding_rows = '';
     foreach ($codings as $coding => $ttl) {
         $coding_rows .= sprintf('<tr><td>%d</td><td>%.2f</td></tr>', $coding, $ttl);
     }
     $ret = str_replace('{{CODING}}', $coding_rows, $ret);
     $this->add_script('js/view.js');
     $this->add_script('../src/javascript/tablesorter/jquery.tablesorter.min.js');
     $this->addOnloadCommand("\$('.tablesorter').tablesorter();\n");
     return $ret;
 }