public function get_id_confirm_view() { $dbc = $this->connection; $dbc->selectDB($this->config->get('OP_DB')); $upc = BarcodeLib::padUPC($this->id); $model = new ProductsModel($dbc); $model->upc($upc); foreach ($model->find('store_id') as $obj) { $obj->delete(); } if (substr($upc, 0, 3) == '002') { $scaleQ = $dbc->prepare_statement("DELETE FROM scaleItems WHERE plu=?"); $dbc->exec_statement($scaleQ, array($upc)); $plu = substr($upc, 3, 4); \COREPOS\Fannie\API\item\HobartDgwLib::deleteItemsFromScales($plu); \COREPOS\Fannie\API\item\EpScaleLib::deleteItemsFromScales($plu); } $userP = $dbc->prepare("DELETE FROM productUser WHERE upc=?"); $dbc->execute($userP, array($upc)); if ($dbc->tableExists('prodExtra')) { $extraP = $dbc->prepare("DELETE FROM prodExtra WHERE upc=?"); $dbc->execute($extraP, array($upc)); } return '<div class="alert alert-success">Item deleted</div>'; }
/** For each store, examine all items. For all items in a given store, check whether it exists in all other stores. Copy the item to store(s) where it does not exist if needed. This may be better suited to a cron/CLI approach. Time required to check every item scales rapidly with both number of items and number of stores. */ public function post_view() { $dbc = $this->connection; $dbc->selectDB($this->config->get('OP_DB')); $model = new StoresModel(); $stores = array(); foreach ($model->find() as $s) { $stores[] = $s->storeID(); } $product = new ProductsModel(); $chkP = $dbc->prepare(' SELECT upc FROM products WHERE upc=? AND store_id=?'); for ($i = 0; $i < count($stores); $i++) { $store_id = $stores[$i]; $product->store_id($store_id); foreach ($product->find() as $p) { for ($j = 0; $j < count($stores); $j++) { if ($i == $j) { continue; } $chkR = $dbc->execute($chkP, array($p->upc(), $stores[$j])); if ($dbc->numRows($chkR) == 0) { $p->store_id($stores[$j]); $p->save(); } } } } header('Location: ' . $_SERVER['PHP_SELF']); return false; }
function process_file($linedata) { $dbc = $this->connection; $dbc->selectDB($this->config->get('OP_DB')); $upc_index = $this->get_column_index('upc'); $price_index = $this->get_column_index('price'); $cool_index = $this->get_column_index('cool'); $itemP = $dbc->prepare(' SELECT itemdesc, description, weight FROM scaleItems AS s LEFT JOIN products AS p ON s.plu=p.upc WHERE plu=?'); $saveP = $dbc->prepare(' UPDATE scaleItems SET price=?, itemdesc=?, modified=' . $dbc->now() . ' WHERE plu=?'); $product = new ProductsModel($dbc); $prodPricing = FormLib::get('prodPricing') === '' ? false : true; $scale_items = array(); foreach ($linedata as $line) { $upc = trim($line[$upc_index]); $upc = BarcodeLib::padUPC($upc); $price = str_replace('$', '', $line[$price_index]); $price = trim($price); $cool = $line[$cool_index]; if (!is_numeric($upc) || !is_numeric($price)) { continue; } $item = $dbc->getRow($itemP, array($upc)); if ($item === false) { continue; } $itemdesc = !empty($item['itemdesc']) ? $item['itemdesc'] : $item['description']; if (strstr($itemdesc, "\n")) { list($line1, $line2) = explode("\n", $itemdesc); $itemdesc = $line1 . "\n" . $cool; } else { $itemdesc .= "\n" . $cool; } $dbc->execute($itemP, array($price, $itemdesc, $upc)); if ($prodPricing) { $product->upc($upc); foreach ($product->find() as $obj) { $obj->normal_price($price); $obj->save(); } } $scale_info = array('RecordType' => 'ChangeOneItem', 'PLU' => substr($upc, 3, 4), 'Description' => $itemdesc, 'Price' => $price, 'Type' => $item['weight'] == 0 ? 'Random Weight' : 'Fixed Weight', 'ReportingClass' => 1); $scale_items[] = $scale_info; } $scales = $this->getScales(FormLib::get('scales')); HobartDgwLib::writeItemsToScales($scale_items, $scales); EpScaleLib::writeItemsToScales($scale_items, $scales); return true; }
public function get_id_break_handler() { $dbc = FannieDB::get($this->config->get('OP_DB')); $model = new VendorBreakdownsModel($dbc); $model->vendorID($this->id); $original = new VendorItemsModel($dbc); $product = new ProductsModel($dbc); foreach ($model->find() as $obj) { $original->vendorID($this->id); $original->sku($obj->sku()); if (!$original->load()) { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'Vendor SKU #" . $obj->sku() . " not found');\n"); continue; } $split_factor = false; $unit_size = ''; if (preg_match('/^\\d+$/', $original->size())) { $split_factor = $original->size(); } elseif (preg_match('/(\\d+)\\s*\\/\\s*(.+)/', $original->size(), $matches)) { $split_factor = $matches[1]; $unit_size = $matches[2]; } elseif (preg_match('/(\\d+)\\s*CT/', $original->size(), $matches)) { $split_factor = $matches[1]; } elseif (preg_match('/(\\d+)\\s*PKT/', $original->size(), $matches)) { $split_factor = $matches[1]; } if (!$split_factor) { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'Vendor SKU #" . $original->size() . " cannot be broken down');\n"); continue; } // add an entry using the store UPC/PLU in place of the vendor SKU // since two records from the same vendor with same SKU are not // permitted in the table $original->sku($obj->upc()); $original->upc($obj->upc()); $original->units(1); $original->size($unit_size); $original->cost($original->cost() / $split_factor); $original->saleCost($original->saleCost() / $split_factor); if ($original->save()) { // update cost in products table, too $product->reset(); $product->upc($obj->upc()); foreach ($product->find('store_id') as $p) { if ($p->load() && $p->default_vendor_id() == $this->id) { $p->cost($original->cost()); $p->save(); $original->description($p->description()); $original->save(); } } } else { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'success', 'Error saving vendor SKU #" . $obj->sku() . "');\n"); } } return true; }
function process_file($linedata) { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); if (!isset($_SESSION['vid'])) { $this->error_details = 'Missing vendor setting'; return False; } $VENDOR_ID = $_SESSION['vid']; $p = $dbc->prepare_statement("SELECT vendorID,vendorName FROM vendors WHERE vendorID=?"); $idR = $dbc->exec_statement($p, array($VENDOR_ID)); if ($dbc->num_rows($idR) == 0) { $this->error_details = 'Cannot find vendor'; return False; } $idW = $dbc->fetch_row($idR); $vendorName = $idW['vendorName']; $SKU = $this->get_column_index('sku'); $BRAND = $this->get_column_index('brand'); $DESCRIPTION = $this->get_column_index('desc'); $QTY = $this->get_column_index('qty'); $SIZE1 = $this->get_column_index('size'); $UPC = $this->get_column_index('upc'); $CATEGORY = $this->get_column_index('vDept'); $REG_COST = $this->get_column_index('cost'); $NET_COST = $this->get_column_index('saleCost'); $REG_UNIT = $this->get_column_index('unitCost'); $NET_UNIT = $this->get_column_index('unitSaleCost'); $SRP = $this->get_column_index('srp'); // PLU items have different internal UPCs // map vendor SKUs to the internal PLUs $SKU_TO_PLU_MAP = array(); $skusP = $dbc->prepare('SELECT sku, upc FROM vendorSKUtoPLU WHERE vendorID=?'); $skusR = $dbc->execute($skusP, array($VENDOR_ID)); while ($skusW = $dbc->fetch_row($skusR)) { $SKU_TO_PLU_MAP[$skusW['sku']] = $skusW['upc']; } $itemP = $dbc->prepare("\n INSERT INTO vendorItems (\n brand, \n sku,\n size,\n upc,\n units,\n cost,\n description,\n vendorDept,\n vendorID,\n saleCost,\n modified,\n srp\n ) VALUES (\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?,\n ?\n )"); $srpP = false; if ($dbc->tableExists('vendorSRPs')) { $srpP = $dbc->prepare_statement("INSERT INTO vendorSRPs (vendorID, upc, srp) VALUES (?,?,?)"); } $pm = new ProductsModel($dbc); foreach ($linedata as $data) { if (!is_array($data)) { continue; } if (!isset($data[$UPC])) { continue; } // grab data from appropriate columns $sku = $data[$SKU]; $brand = $BRAND === false ? $vendorName : substr($data[$BRAND], 0, 50); $description = substr($data[$DESCRIPTION], 0, 50); if ($QTY === false) { $qty = 1.0; } else { $qty = $data[$QTY]; if (!is_numeric($qty)) { $qty = 1.0; } } $size = $SIZE1 === false ? '' : substr($data[$SIZE1], 0, 25); $upc = $data[$UPC]; $upc = str_replace(' ', '', $upc); $upc = str_replace('-', '', $upc); if (strlen($upc) > 13) { $upc = substr($upc, -13); } else { $upc = str_pad($upc, 13, '0', STR_PAD_LEFT); } // zeroes isn't a real item, skip it if ($upc == "0000000000000") { continue; } if ($_SESSION['vUploadCheckDigits']) { $upc = '0' . substr($upc, 0, 12); } if (isset($SKU_TO_PLU_MAP[$sku])) { $upc = $SKU_TO_PLU_MAP[$sku]; } $category = $CATEGORY === false ? 0 : $data[$CATEGORY]; $reg_unit = ''; if ($REG_UNIT !== false) { $reg_unit = trim($data[$REG_UNIT]); $reg_unit = $this->priceFix($reg_unit); } if (!is_numeric($reg_unit) && $REG_COST !== false) { $reg = trim($data[$REG_COST]); $reg = $this->priceFix($reg); if (is_numeric($reg)) { $reg_unit = $reg / $qty; } } // skip the item if prices aren't numeric // this will catch the 'label' line in the first CSV split // since the splits get returned in file system order, // we can't be certain *when* that chunk will come up // can't process items w/o price (usually promos/samples anyway) if (empty($reg_unit) || !is_numeric($reg_unit)) { continue; } $net_unit = ''; if ($NET_UNIT !== false) { $net_unit = trim($data[$NET_UNIT]); $net_unit = $this->priceFix($net_unit); } if (!is_numeric($net_unit) && $NET_COST !== false) { $net = trim($data[$NET_COST]); $net = $this->priceFix($net); if (is_numeric($net)) { $net_unit = $net / $qty; } } // blank spreadsheet cell if (empty($net_unit)) { $net_unit = 0.0; } $srp = $SRP === false ? 0.0 : trim($data[$SRP]); if ($net_unit == $reg_unit) { $net_unit = 0.0; // not really a sale } // syntax fixes. kill apostrophes in text fields, // trim $ off amounts as well as commas for the // occasional > $1,000 item $srp = $this->priceFix($srp); if (!is_numeric($srp)) { $srp = 0; } $brand = str_replace("'", "", $brand); $description = str_replace("'", "", $description); $args = array($brand, $sku, $size, $upc, $qty, $reg_unit, $description, $category, $VENDOR_ID, $net_unit, date('Y-m-d H:i:s'), $srp); $dbc->execute($itemP, $args); if ($srpP) { $dbc->exec_statement($srpP, array($VENDOR_ID, $upc, $srp)); } if ($_SESSION['vUploadChangeCosts']) { $pm->reset(); $pm->upc($upc); $pm->default_vendor_id($VENDOR_ID); foreach ($pm->find('store_id') as $obj) { $obj->cost($reg_unit); $obj->save(); } } } return true; }
public function post_id_sku_field_value_handler() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $item = new VendorItemsModel($dbc); $item->vendorID($this->id); $item->sku($this->sku); $ret = array('error' => 0); if ($this->field === 'brand') { $item->brand($this->value); } elseif ($this->field === 'description') { $item->description($this->value); } elseif ($this->field === 'unitSize') { $item->size($this->value); } elseif ($this->field === 'caseQty') { $item->units($this->value); } elseif ($this->field === 'cost') { $item->cost($this->value); } else { $ret['error'] = 1; $ret['error_msg'] = 'Unknown field'; } if ($ret['error'] == 0) { $saved = $item->save(); if (!$saved) { $ret['error'] = 1; $ret['error_msg'] = 'Save failed'; } else { /** If cost was updated, update the corresponding product cost */ $prodP = $dbc->prepare(' SELECT p.upc FROM products AS p INNER JOIN vendorItems AS v ON p.upc=v.upc AND p.default_vendor_id=v.vendorID WHERE v.vendorID=? AND v.sku=?'); $prodR = $dbc->execute($prodP, array($this->id, $this->sku)); $model = new ProductsModel($dbc); while ($prodW = $dbc->fetch_row($prodR)) { $model->reset(); $model->upc($prodW['upc']); foreach ($model->find('store_id') as $obj) { $obj->cost($this->value); $obj->save(); } } } } echo json_encode($ret); return false; }
$prod->upc($upc); foreach ($prod->find('store_id') as $p) { // make sure another rule isn't overwritten with a generic one if ($p->price_rule_id() == 0) { $p->price_rule_id(1); } $p->save(); } break; case 'delVarPricing': $prep = $dbc->prepare_statement("UPDATE prodExtra SET variable_pricing=0 WHERE upc=?"); $dbc->exec_statement($prep, array($upc)); $ruleProd = new ProductsModel($dbc); $prod = new ProductsModel($dbc); $prod->upc($upc); foreach ($prod->find('store_id') as $p) { $ruleID = 0; // remove the rule but save its ID if ($p->price_rule_id() != 0) { $ruleID = $p->price_rule_id(); $p->price_rule_id(0); } $p->save(); // make sure no other item is using the same // rule before deleting it if ($ruleID > 1) { $ruleProd->reset(); $ruleProd->price_rule_id($ruleID); if (count($ruleProd->find()) == 0) { // no products are using this rule $rule = new PriceRulesModel($dbc);
protected function updateRealItem($upc, $brand, $description) { $dbc = $this->getDB(); $model = new \ProductUserModel($dbc); $model->upc(\BarcodeLib::padUPC($upc)); $model->brand($brand); $model->description($description); $model->save(); $model = new \ProductsModel($dbc); $model->upc(\BarcodeLib::padUPC($upc)); foreach ($model->find('store_id') as $obj) { $obj->brand($brand); $obj->save(); } }
$prod->upc($upc); $prod->store_id(1); $prod->load(); $ruleID = 0; // remove the rule but save its ID if ($prod->price_rule_id() != 0) { $ruleID = $prod->price_rule_id(); $prod->price_rule_id(0); } $prod->save(); // make sure no other item is using the same // rule before deleting it if ($ruleID > 1) { $prod->reset(); $prod->price_rule_id($ruleID); if (count($prod->find()) == 0) { // no products are using this rule $rule = new PriceRulesModel($sql); $rule->priceRuleID($ruleID); $rule->delete(); } } } break; } echo $out; return; } //Get buyID from index form. Set to 99 (all buyers) if not set. if (isset($_POST['buyer'])) { $buyID = $_POST['buyer'];
private function unsaleUPC($upc) { // take the item off sale if this batch is currently on sale $product = new ProductsModel($this->connection); $product->upc($upc); $ret = true; foreach ($product->find('store_id') as $obj) { $obj->discountType(0); $obj->special_price(0); $obj->start_date(0); $obj->end_date(0); $ret = $obj->save(); } return $ret ? true : false; }