예제 #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');
 }
예제 #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";
     }
 }
예제 #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";
     }
 }
예제 #4
0
 public function guessCode()
 {
     $dbc = $this->connection;
     // case 1: item exists in products
     $deptP = $dbc->prepare('
         SELECT d.salesCode
         FROM products AS p
             INNER JOIN departments AS d ON p.department=d.dept_no
         WHERE p.upc=?');
     $deptR = $dbc->execute($deptP, array($this->internalUPC()));
     if ($dbc->numRows($deptR)) {
         $w = $dbc->fetchRow($deptR);
         return $w['salesCode'];
     }
     $order = new PurchaseOrderModel($dbc);
     $order->orderID($this->orderID());
     $order->load();
     // case 2: item is SKU-mapped but the order record
     // does not reflect the internal PLU
     $deptP = $dbc->prepare('
         SELECT d.salesCode
         FROM vendorSKUtoPLU AS v
             ' . DTrans::joinProducts('v', 'p', 'INNER') . '
             INNER JOIN departments AS d ON p.department=d.dept_no
         WHERE v.sku=?
             AND v.vendorID=?');
     $deptR = $dbc->execute($deptP, array($this->sku(), $order->vendorID()));
     if ($dbc->numRows($deptR)) {
         $w = $dbc->fetchRow($deptR);
         return $w['salesCode'];
     }
     // case 3: item is not normally carried but is in a vendor catalog
     // that has vendor => POS department mapping
     $deptP = $dbc->prepare('
         SELECT d.salesCode
         FROM vendorItems AS v
             INNER JOIN vendorDepartments AS z ON v.vendorDept=z.deptID AND v.vendorID=z.vendorID
             INNER JOIN departments AS d ON z.posDeptID=d.dept_no
         WHERE v.sku=?
             AND v.vendorID=?');
     $deptR = $dbc->execute($deptP, array($this->sku(), $order->vendorID()));
     if ($dbc->numRows($deptR)) {
         $w = $dbc->fetchRow($deptR);
         return $w['salesCode'];
     }
     return false;
 }
예제 #5
0
 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();
 }
예제 #6
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;
 }