/** Do whatever the service is supposed to do. Should override this. @param $args array of data @return an array of data */ public function run($args = array()) { $ret = array(); if (!property_exists($args, 'type')) { // missing required arguments $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters needs type'); return $ret; } // validate additional arguments switch (strtolower($args->type)) { case 'vendor': if (!property_exists($args, 'vendor_id')) { // vendor ID required $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters needs vendor_id'); return $ret; } elseif (!property_exists($args, 'sku') && !property_exists($args, 'upc')) { // either sku or upc is required $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters needs sku or upc'); return $ret; } break; default: // unknown type argument $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters'); return $ret; } // lookup results $dbc = \FannieDB::getReadOnly(\FannieConfig::factory()->get('OP_DB')); switch (strtolower($args->type)) { case 'vendor': $vendor = new \VendorItemsModel($dbc); $vendor->vendorID($args->vendor_id); if (property_exists($args, 'sku')) { $vendor->sku($args->sku); } elseif (property_exists($args, 'upc')) { $vendor->upc($args->upc); } foreach ($vendor->find() as $v) { $ret['sku'] = $v->sku(); $ret['upc'] = $v->upc(); $ret['size'] = $v->size(); $ret['units'] = $v->units(); $ret['brand'] = $v->brand(); $ret['description'] = $v->description(); $ret['cost'] = $v->cost(); break; } return $ret; } }
public function get_id_view() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $items = new VendorItemsModel($dbc); $items->vendorID($this->id); $ret = '<div id="alert-area"></div> <table class="table tablesorter">'; $ret .= '<thead><tr> <th>Vendor SKU</th> <th>Our UPC</th> <th>Brand</th> <th>Description</th> <th>Unit Size</th> <th>Case Qty</th> <th>Unit Cost</th> </tr></thead>'; $ret .= '<tbody>'; foreach ($items->find() as $item) { $ret .= sprintf('<tr> <input type="hidden" class="original-sku" name="originalSKU" value="%s" /> <td><span class="collapse">%s</span> <input type="text" class="form-control input-sm sku-field" name="editSKU" value="%s" size="13" /></td> <td><a href="../ItemEditorPage.php?searchupc=%s" target="_edit%s">%s</a></td> <td><span class="collapse">%s</span> <input type="text" class="form-control input-sm editable" name="brand" value="%s" /></td> <td><span class="collapse">%s</span> <input type="text" class="form-control input-sm editable" name="description" value="%s" /></td> <td><span class="collapse">%s</span> <input type="text" class="form-control input-sm editable" name="unitSize" value="%s" size="5" /></td> <td><span class="collapse">%s</span> <input type="text" class="form-control input-sm editable" name="caseQty" value="%.2f" size="5" /></td> <td><span class="collapse">%s</span> <input type="text" class="form-control input-sm costing" name="unitCost" value="%.2f" size="5" /></td> </tr>', $item->sku(), $item->sku(), $item->sku(), $item->upc(), $item->upc(), $item->upc(), $item->brand(), $item->brand(), $item->description(), $item->description(), $item->size(), $item->size(), $item->units(), $item->units(), $item->cost(), $item->cost()); } $ret .= '</tbody></table>'; $ret .= '<input type="hidden" id="vendor-id" value="' . $this->id . '" />'; $ret .= '<p><a href="VendorIndexPage.php?vid=' . $this->id . '" class="btn btn-default">Home</a></p>'; $this->add_onload_command('itemEditing();'); $this->add_script('../../src/javascript/tablesorter/jquery.tablesorter.js'); $this->addCssFile('../../src/javascript/tablesorter/themes/blue/style.css'); $this->add_onload_command("\$('.tablesorter').tablesorter({sortList:[[0,0]], widgets:['zebra']});"); return $ret; }
/** Helper: update vendor costs when updating a product cost if the product has a defined vendor */ public function updateCostByUPC($upc, $cost, $vendorID) { $updateP = $this->connection->prepare(' UPDATE vendorItems SET cost=?, modified=' . $this->connection->now() . ' WHERE vendorID=? AND sku=?'); $skuModel = new VendorSKUtoPLUModel($this->connection); $skuModel->vendorID($vendorID); $skuModel->upc($upc); foreach ($skuModel->find() as $obj) { $this->connection->execute($updateP, array($cost, $vendorID, $obj->sku())); } $vModel = new VendorItemsModel($this->connection); $vModel->vendorID($vendorID); $vModel->upc($upc); foreach ($vModel->find() as $obj) { $this->connection->execute($updateP, array($cost, $vendorID, $obj->sku())); } }
public function preprocess() { global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB, $FANNIE_URL, $FANNIE_TRANS_DB; //$this->add_script($FANNIE_URL.'src/javascript/jquery.js'); //$this->add_script($FANNIE_URL.'src/javascript/jquery-ui.js'); if (FormLib::get('upc_in') !== '') { $upc = BarcodeLib::padUPC(FormLib::get('upc_in')); $this->current_item_data['upc'] = $upc; $dbc = FannieDB::get($FANNIE_OP_DB); $model = new ProductsModel($dbc); $model->upc($upc); $vendorID = 0; if ($model->load()) { $this->current_item_data['desc'] = $model->brand() . ' ' . $model->description(); $this->current_item_data['par'] = $model->auto_par(); $vendorID = $model->default_vendor_id(); } $model = new VendorsModel($dbc); $model->vendorID($vendorID); if ($model->load()) { $this->current_item_data['vendor'] = $model->vendorName(); $schedule = new VendorDeliveriesModel($dbc); $schedule->vendorID($vendorID); if ($schedule->load() && $schedule->regular() == 1) { $this->current_item_data['nextDelivery'] = date('D, M jS', strtotime($schedule->nextDelivery())) . ' & ' . date('D, M jS', strtotime($schedule->nextNextDelivery())); $nd = new DateTime(date('Y-m-d', strtotime($schedule->nextDelivery()))); $nnd = new DateTime(date('Y-m-d', strtotime($schedule->nextNextDelivery()))); $this->current_item_data['deliverySpan'] = $nnd->diff($nd)->format('%a'); } $items = new VendorItemsModel($dbc); $items->vendorID($vendorID); $items->upc($upc); $this->current_item_data['cases'] = array(); foreach ($items->find('units') as $item) { $this->current_item_data['cases'][] = $item->units(); } } $saleNow = 'SELECT b.batchName, b.startDate, b.endDate FROM batchList AS l INNER JOIN batches AS b ON b.batchID=l.batchID WHERE l.upc=? AND b.discounttype <> 0 AND b.startDate <= ' . $dbc->now() . ' AND b.endDate >= ' . $dbc->now(); $saleNow = $dbc->prepare($saleNow); $saleNow = $dbc->execute($saleNow, array($upc)); if ($dbc->num_rows($saleNow) > 0) { $row = $dbc->fetch_row($saleNow); $this->current_item_data['onSale'] = $row['batchName'] . ' thru ' . date('D, M jS', strtotime($row['endDate'])); } $saleNext = 'SELECT b.batchName, b.startDate, b.endDate FROM batchList AS l INNER JOIN batches AS b ON b.batchID=l.batchID WHERE l.upc=? AND b.discounttype <> 0 AND b.startDate >= ' . $dbc->now() . ' AND b.endDate >= ' . $dbc->now(); $saleNext = $dbc->prepare($saleNext); $saleNext = $dbc->execute($saleNext, array($upc)); if ($dbc->num_rows($saleNext) > 0) { $row = $dbc->fetch_row($saleNext); $this->current_item_data['soonSale'] = $row['batchName'] . ' on ' . date('D, M jS', strtotime($row['startDate'])); } $ordersQ = 'SELECT v.vendorName, o.placedDate, i.quantity, i.caseSize FROM PurchaseOrderItems AS i INNER JOIN PurchaseOrder AS o ON i.orderID=o.orderID INNER JOIN vendors AS v ON o.vendorID=v.vendorID WHERE i.internalUPC = ? ORDER BY o.placedDate DESC'; $ordersQ = $dbc->add_select_limit($ordersQ, 10); $ordersP = $dbc->prepare($ordersQ); $ordersR = $dbc->execute($ordersP, array($upc)); $orders = array(); while ($w = $dbc->fetch_row($ordersR)) { $orders[] = $w; } $this->current_item_data['orders'] = $orders; $salesQ = 'SELECT ' . DTrans::sumQuantity('d') . ' AS qty, MIN(tdate) as day FROM ' . $FANNIE_TRANS_DB . $dbc->sep() . 'dlog_15 AS d WHERE upc = ? GROUP BY YEAR(tdate), MONTH(tdate), DAY(tdate) ORDER BY YEAR(tdate) DESC, MONTH(tdate) DESC, DAY(tdate) DESC'; $salesP = $dbc->prepare($salesQ); $salesR = $dbc->execute($salesP, array($upc)); $sales = array(); while ($w = $dbc->fetch_row($salesR)) { $sales[] = $w; } $this->current_item_data['sales'] = $sales; } $this->linea_ios_mode = $this->linea_support_available(); if ($this->linea_ios_mode) { $this->add_script($FANNIE_URL . 'src/javascript/linea/cordova-2.2.0.js'); $this->add_script($FANNIE_URL . 'src/javascript/linea/ScannerLib-Linea-2.0.0.js'); } $this->add_script($FANNIE_URL . 'src/javascript/tablesorter/jquery.tablesorter.js'); $this->add_css_file($FANNIE_URL . 'src/javascript/tablesorter/themes/blue/style.css'); //$this->add_css_file($FANNIE_URL.'src/javascript/jquery-ui.css'); return true; }
private static function parseItem($line, $vendorID) { global $FANNIE_OP_DB; $UPC = 3; $SKU = 4; $RECVQTY = 5; $CASESIZE = 6; $UNITSIZE = 7; $BRAND = 8; $DESCRIPTION = 9; $TOTALCOST = 13; $UNITCOST = 15; $ORDERQTY = 18; // remove non-digits and check digits // then pad to length $upc = str_replace('-', '', $line[$UPC]); $upc = str_replace(' ', '', $upc); $upc = substr($upc, 0, strlen($upc) - 1); $upc = BarcodeLib::padUPC($upc); $caseSize = $line[$CASESIZE]; // invoice does not include proper case size // try to find actual size in vendorItems table // via SKU or UPC if (strtoupper($caseSize) == 'CS') { $dbc = FannieDB::get($FANNIE_OP_DB); $vmodel = new VendorItemsModel($dbc); $vmodel->sku($line[$SKU]); $vmodel->vendorID($vendorID); $vmodel->load(); if ($vmodel->units() != '') { $caseSize = $vmodel->units(); } else { $vmodel->reset(); $vmodel->upc($upc); $vmodel->vendorID($vendorID); foreach ($vmodel->find() as $item) { if ($item->units() != '') { $caseSize = $item->units(); } } } } // never found a valid size if (!is_numeric($caseSize)) { $caseSize = 1; } return array('sku' => $line[$SKU], 'quantity' => $line[$ORDERQTY], 'unitCost' => $line[$UNITCOST], 'caseSize' => $caseSize, 'receivedQty' => $line[$RECVQTY], 'receivedTotalCost' => $line[$TOTALCOST], 'unitSize' => $line[$UNITSIZE], 'brand' => $line[$BRAND], 'description' => $line[$DESCRIPTION], 'upc' => $upc); }
public function showEditForm($upc, $display_mode = 1, $expand_mode = 1) { $db = $this->db(); $product = new ProductsModel($db); $product->upc($upc); if (!$product->load()) { /** Lookup vendor cost on new items */ $vendor = new VendorItemsModel($db); $vendor->upc($upc); foreach ($vendor->find('vendorID') as $v) { $product->cost($v->cost()); break; } } $ret = '<div id="ItemMarginFieldset" class="panel panel-default">'; $ret .= "<div class=\"panel-heading\">\n <a href=\"\" onclick=\"\$('#ItemMarginContents').toggle();return false;\">\n Margin\n </a></div>"; $css = $expand_mode == 1 ? '' : ' collapse'; $ret .= '<div id="ItemMarginContents" class="panel-body' . $css . '">'; $ret .= '<div class="col-sm-5">'; $ret .= '<div id="ItemMarginMeter">'; $ret .= $this->calculateMargin($product->normal_price(), $product->cost(), $product->department(), $upc); $ret .= '</div>'; $ret .= '</div>'; $ret .= '<div class="col-sm-6">'; $ret .= '<div class="form-group form-inline"> <label>Pricing Rule</label> <select name="price-rule-id" class="form-control input-sm" onchange="if(this.value>=0)$(\'#custom-pricing-fields :input\').prop(\'disabled\', true); else $(\'#custom-pricing-fields :input\').prop(\'disabled\', false);"> <option value="0" ' . ($product->price_rule_id() == 0 ? 'selected' : '') . '>Normal</option> <option value="1" ' . ($product->price_rule_id() == 1 ? 'selected' : '') . '>Variable</option> <option value="-1" ' . ($product->price_rule_id() > 1 ? 'selected' : '') . '>Custom</option> </select> <input type="hidden" name="current-price-rule-id" value="' . $product->price_rule_id() . '" /> <label>Avg. Daily Movement</label> ' . sprintf('%.2f', $this->avgSales($upc)) . ' </div>'; $rule = new PriceRulesModel($db); if ($product->price_rule_id() > 1) { $rule->priceRuleID($product->price_rule_id()); $rule->load(); } $disabled = $product->price_rule_id() <= 1 ? 'disabled' : ''; $ret .= '<div id="custom-pricing-fields" class="form-group form-inline"> <label>Custom</label> <select ' . $disabled . ' name="price-rule-type" class="form-control input-sm"> {{RULE_TYPES}} </select> <input type="text" class="form-control date-field input-sm" name="rule-review-date" ' . $disabled . ' placeholder="Review Date" title="Review Date" value="{{REVIEW_DATE}}" /> <input type="text" class="form-control input-sm" name="rule-details" ' . $disabled . ' placeholder="Details" title="Details" value="{{RULE_DETAILS}}" /> </div>'; $types = new PriceRuleTypesModel($db); $ret = str_replace('{{RULE_TYPES}}', $types->toOptions($rule->priceRuleTypeID()), $ret); $ret = str_replace('{{REVIEW_DATE}}', $rule->reviewDate(), $ret); $ret = str_replace('{{RULE_DETAILS}}', $rule->details(), $ret); $ret .= '</div>'; $ret .= '</div>'; $ret .= '</div>'; return $ret; }