public function logUpdate($type = 'UNKNOWN', $user = false) { if (!$user) { $user = FannieAuth::getUID(FannieAuth::checkLogin()); } $product = new ProductsModel($this->connection); $product->upc($this->upc()); $exists = $product->load(); if (!$exists) { return false; } $this->storeID($product->store_id()); $this->updateType($type); $this->description($product->description()); $this->price($product->normal_price()); $this->salePrice($product->special_price()); $this->cost($product->cost()); $this->dept($product->department()); $this->tax($product->tax()); $this->fs($product->foodstamp()); $this->scale($product->scale()); $this->modified($product->modified()); $this->forceQty($product->qttyEnforced()); $this->noDisc($product->discount()); $this->inUse($product->inUse()); $this->user($user); $likecode = 0; if ($this->connection->table_exists('upcLike')) { $upcQ = $this->connection->prepare('SELECT likeCode FROM upcLike WHERE upc=?'); $upcR = $this->connection->execute($upcQ, array($this->upc())); if ($this->connection->num_rows($upcR) > 0) { $upcW = $this->connection->fetch_row($upcR); $this->likeCode($upcW['likeCode']); } } $this->save(); return true; }
public function showEditForm($upc, $display_mode = 1, $expand_mode = 1) { $upc = BarcodeLib::padUPC($upc); $dbc = $this->db(); $prod = new ProductsModel($dbc); $prod->upc($upc); if (FannieConfig::config('STORE_MODE') == 'HQ') { $prod->store_id(FannieConfig::config('STORE_ID')); } $prod->load(); $ret = '<div id="FreshDealsFieldset" class="panel panel-default">'; $ret .= "<div class=\"panel-heading\">\n <a href=\"\" onclick=\"\$('#FreshDealsDiv').toggle();return false;\">\n Fresh Deals</a>\n </div>"; $ret .= '<div id="FreshDealsDiv" class="panel-body">'; $ret .= sprintf('<table class="table table-bordered"><tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>$%.2f</td> <td>$%.2f</td> </tr></table>', $prod->brand(), $prod->description(), $prod->upc(), $prod->cost(), $prod->normal_price()); $ret .= '</div></div>'; return $ret; }
function ajax_response() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); switch (FormLib::get_form_value('ajax')) { case 'save': $upc = FormLib::get_form_value('upc'); $store_id = FormLib::get('store_id'); $upc = BarcodeLib::padUPC($upc); $values = array(); $model = new ProductsModel($dbc); $model->upc($upc); $model->store_id($store_id); $brand = FormLib::get('brand'); if ($brand !== '') { $model->brand($brand); } $desc = FormLib::get_form_value('desc'); if ($desc !== '') { $model->description($desc); } $dept = FormLib::get_form_value('dept'); if ($dept !== '') { $model->department($dept); } $price = rtrim(FormLib::get_form_value('price'), ' '); if ($price !== '') { $model->normal_price($price); } $cost = rtrim(FormLib::get_form_value('cost'), ' '); if ($cost !== '') { $model->cost($cost); } $tax = FormLib::get_form_value('tax'); if ($tax !== '') { $model->tax($tax); } $fsx = FormLib::get_form_value('fs'); if ($fsx !== '') { $model->foodstamp($fsx); } $disc = FormLib::get_form_value('disc'); if ($disc !== '') { $model->discount($disc); } $wgt = FormLib::get_form_value('wgt'); if ($wgt !== '') { $model->scale($wgt); } $loc = FormLib::get_form_value('local'); if ($loc !== '') { $model->local($loc); } $supplier = FormLib::get_form_value('supplier'); /** Normalize free-form supplier text Look up corresponding vendor ID */ $vendorID = ''; $vendors = new VendorsModel($dbc); $vendors->vendorName($supplier); foreach ($vendors->find() as $obj) { $vendorID = $obj->vendorID(); break; } if ($vendorID !== '') { $model->default_vendor_id($vendorID); } $model->save(); $chkP = $dbc->prepare('SELECT upc FROM prodExtra WHERE upc=?'); $chkR = $dbc->execute($chkP, array($upc)); if ($dbc->num_rows($chkR) > 0) { $extraP = $dbc->prepare_statement('UPDATE prodExtra SET manufacturer=?, distributor=? WHERE upc=?'); $dbc->exec_statement($extraP, array($brand, $supplier, $upc)); } else { $extraP = $dbc->prepare('INSERT INTO prodExtra (upc, variable_pricing, margin, manufacturer, distributor) VALUES (?, 0, 0, ?, ?)'); $dbc->execute($extraP, array($upc, $brand, $supplier)); } if ($vendorID !== '') { $item = new VendorItemsModel($dbc); $item->createIfMissing($upc, $vendorID); $item->updateCostByUPC($upc, $cost, $vendorID); } updateProductAllLanes($upc); break; case 'deleteCheck': $upc = FormLib::get_form_value('upc'); $upc = BarcodeLib::padUPC($upc); $encoded_desc = FormLib::get_form_value('desc'); $desc = base64_decode($encoded_desc); $fetchP = $dbc->prepare_statement("select normal_price,\n special_price,t.description,\n case when foodstamp = 1 then 'Yes' else 'No' end as fs,\n case when scale = 1 then 'Yes' else 'No' end as s\n from products as p left join taxrates as t\n on p.tax = t.id\n where upc=? and p.description=?"); $fetchR = $dbc->exec_statement($fetchP, array($upc, $desc)); $fetchW = $dbc->fetch_array($fetchR); $ret = "Delete item {$upc} - {$desc}?\n"; $ret .= "Normal price: " . rtrim($fetchW[0]) . "\n"; $ret .= "Sale price: " . rtrim($fetchW[1]) . "\n"; $ret .= "Tax: " . rtrim($fetchW[2]) . "\n"; $ret .= "Foodstamp: " . rtrim($fetchW[3]) . "\n"; $ret .= "Scale: " . rtrim($fetchW[4]) . "\n"; $json = array('alertBox' => $ret, 'upc' => ltrim($upc, '0'), 'enc_desc' => $encoded_desc); echo json_encode($json); break; case 'doDelete': $upc = FormLib::get_form_value('upc'); $upc = BarcodeLib::padUPC($upc); $desc = base64_decode(FormLib::get_form_value('desc')); $update = new ProdUpdateModel($dbc); $update->upc($upc); $update->logUpdate(ProdUpdateModel::UPDATE_DELETE); $model = new ProductsModel($dbc); $model->upc($upc); $model->delete(); $model = new ProductUserModel($dbc); $model->upc($upc); $model->delete(); $model = new ScaleItemsModel($dbc); $model->plu($upc); $model->delete(); $delP = $dbc->prepare_statement("delete from prodExtra where upc=?"); $delXR = $dbc->exec_statement($delP, array($upc)); $delP = $dbc->prepare_statement("DELETE FROM upcLike WHERE upc=?"); $delR = $dbc->exec_statement($delP, array($upc)); deleteProductAllLanes($upc); break; default: echo 'Unknown Action'; break; } }
private function addToPos($upc, $vid, $price, $dept, $tags = -1) { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $p = $dbc->prepare_statement("SELECT i.*,v.vendorName FROM vendorItems AS i\n LEFT JOIN vendors AS v ON v.vendorID=i.vendorID\n WHERE i.vendorID=? AND upc=?"); $vinfo = $dbc->exec_statement($p, array($vid, $upc)); $vinfo = $dbc->fetch_row($vinfo); $p = $dbc->prepare_statement("SELECT * FROM departments WHERE dept_no=?"); $dinfo = $dbc->exec_statement($p, array($dept)); $dinfo = $dbc->fetch_row($dinfo); $model = new ProductsModel($dbc); $model->upc(BarcodeLib::padUPC($upc)); $model->description($vinfo['description']); $model->normal_price($price); $model->department($dept); $model->tax($dinfo['dept_tax']); $model->foodstamp($dinfo['dept_fs']); $model->cost($vinfo['cost']); $model->default_vendor_id($vid); $model->brand($vinfo['brand']); $model->store_id(1); $model->save(); $xInsQ = $dbc->prepare_statement("INSERT INTO prodExtra (upc,manufacturer,distributor,cost,margin,variable_pricing,location,\n case_quantity,case_cost,case_info) VALUES\n (?,?,?,?,0.00,0,'','',0.00,'')"); $args = array($upc, $vinfo['brand'], $vinfo['vendorName'], $vinfo['cost']); $dbc->exec_statement($xInsQ, $args); if ($tags !== -1) { $tag = new ShelftagsModel($dbc); $tag->id($tags); $tag->upc($upc); $info = $model->getTagData(); $tag->normal_price($info['normal_price']); $tag->description($info['description']); $tag->brand($info['brand']); $tag->vendor($info['vendor']); $tag->sku($info['sku']); $tag->size($info['size']); $tag->units($info['units']); $tag->pricePerUnit($info['pricePerUnit']); $tag->save(); } echo "Item added"; }
/** Helper: create a vendorItems record for an existing product if one does not exist */ public function createIfMissing($upc, $vendorID) { // look for entry directly by UPC or via SKU mapping $findP = $this->connection->prepare(' SELECT v.upc FROM vendorItems AS v LEFT JOIN vendorSKUtoPLU AS m ON v.vendorID=m.vendorID AND v.sku=m.sku WHERE v.vendorID=? AND (v.upc=? OR m.upc=?)'); $findR = $this->connection->execute($findP, array($vendorID, $upc, $upc)); if ($this->connection->num_rows($findR) == 0) { // create item from product $prod = new ProductsModel($this->connection); $prod->upc($upc); $prod->load(); $vend = new VendorItemsModel($this->connection); $vend->vendorID($vendorID); $vend->upc($upc); $vend->sku($upc); $vend->brand($prod->brand()); $vend->description($prod->description()); $vend->cost($prod->cost()); $vend->saleCost(0); $vend->vendorDept(0); $vend->units(1); $vend->size($prod->size() . $prod->unitofmeasure()); $vend->save(); } }
$model->size(0); $model->tax($tax); $model->foodstamp($FS); $model->scale($Scale); $model->scaleprice(0); $model->mixmatchcode(0); $model->modified($stamp); $model->advertised(0); $model->tareweight(0); $model->discount($NoDisc); $model->discounttype(0); $model->unitofmeasure(0); $model->wicable(0); $model->qttyEnforced(0); $model->idEnforced(0); $model->cost(0.0); $model->inUse(1); $model->numflag(0); $model->subdept(0); $model->deposit(0.0); $model->local($local); $model->default_vendor_id($vendorID); $model->save(); $model->upc($upc); $model->pushToLanes(); $checkQ = $sql->prepare("select * from prodExtra where upc=?"); $checkR = $sql->execute($checkQ, array($upc)); if ($sql->num_rows($checkR) == 0) { $extraQ = $sql->prepare("insert into prodExtra values (?,?,?,0,0,0,'','',0,'')"); $extraR = $sql->execute($extraQ, array($upc, $distributor, $manufacturer)); }
function SaveFormData($upc) { $FANNIE_PRODUCT_MODULES = FannieConfig::config('PRODUCT_MODULES', array()); $upc = BarcodeLib::padUPC($upc); $dbc = $this->db(); $model = new ProductsModel($dbc); $model->upc($upc); if (!$model->load()) { // fully init new record $model->special_price(0); $model->specialpricemethod(0); $model->specialquantity(0); $model->specialgroupprice(0); $model->advertised(0); $model->tareweight(0); $model->start_date('0000-00-00'); $model->end_date('0000-00-00'); $model->discounttype(0); $model->wicable(0); $model->scaleprice(0); $model->inUse(1); } $stores = FormLib::get('store_id', array()); for ($i = 0; $i < count($stores); $i++) { $model->store_id($stores[$i]); $taxes = FormLib::get('tax'); if (isset($taxes[$i])) { $model->tax($taxes[$i]); } $fs = FormLib::get('FS', array()); if (in_array($stores[$i], $fs)) { $model->foodstamp(1); } else { $model->foodstamp(0); } $scale = FormLib::get('Scale', array()); if (in_array($stores[$i], $scale)) { $model->scale(1); } else { $model->scale(0); } $qtyFrc = FormLib::get('QtyFrc', array()); if (in_array($stores[$i], $qtyFrc)) { $model->qttyEnforced(1); } else { $model->qttyEnforced(0); } $wic = FormLib::get('prod-wicable', array()); if (in_array($stores[$i], $wic)) { $model->wicable(1); } else { $model->wicable(0); } $discount_setting = FormLib::get('discount'); if (isset($discount_setting[$i])) { switch ($discount_setting[$i]) { case 0: $model->discount(0); $model->line_item_discountable(0); break; case 1: $model->discount(1); $model->line_item_discountable(1); break; case 2: $model->discount(1); $model->line_item_discountable(0); break; case 3: $model->discount(0); $model->line_item_discountable(1); break; } } $price = FormLib::get('price'); if (isset($price[$i])) { $model->normal_price($price[$i]); } $cost = FormLib::get('cost'); if (isset($cost[$i])) { $model->cost($cost[$i]); } $desc = FormLib::get('descript'); if (isset($desc[$i])) { $model->description(str_replace("'", '', $desc[$i])); } $brand = FormLib::get('manufacturer'); if (isset($brand[$i])) { $model->brand(str_replace("'", '', $brand[$i])); } $model->pricemethod(0); $model->groupprice(0.0); $model->quantity(0); $dept = FormLib::get('department'); if (isset($dept[$i])) { $model->department($dept[$i]); } $size = FormLib::get('size'); if (isset($size[$i])) { $model->size($size[$i]); } $model->modified(date('Y-m-d H:i:s')); $unit = FormLib::get('unitm'); if (isset($unit[$i])) { $model->unitofmeasure($unit[$i]); } $subdept = FormLib::get('subdept'); if (isset($subdept[$i])) { $model->subdept($subdept[$i]); } // lookup vendorID by name $vendorID = 0; $v_input = FormLib::get('distributor'); if (isset($v_input[$i])) { $vendor = new VendorsModel($dbc); $vendor->vendorName($v_input[$i]); foreach ($vendor->find('vendorID') as $obj) { $vendorID = $obj->vendorID(); break; } } $model->default_vendor_id($vendorID); $inUse = FormLib::get('prod-in-use', array()); if (in_array($stores[$i], $inUse)) { $model->inUse(1); } else { $model->inUse(0); } $idEnf = FormLib::get('id-enforced', array()); if (isset($idEnf[$i])) { $model->idEnforced($idEnf[$i]); } $local = FormLib::get('prod-local'); if (isset($local[$i])) { $model->local($local[$i]); } $deposit = FormLib::get('deposit-upc'); if (isset($deposit[$i])) { if ($deposit[$i] == '') { $deposit[$i] = 0; } $model->deposit($deposit[$i]); } /* products.formatted_name is intended to be maintained automatically. * Get all enabled plugins and standard modules of the base. * Run plugins first, then standard modules. */ $formatters = FannieAPI::ListModules('ProductNameFormatter'); $fmt_name = ""; $fn_params = array('index' => $i); foreach ($formatters as $formatter_name) { $formatter = new $formatter_name(); $fmt_name = $formatter->compose($fn_params); if (isset($formatter->this_mod_only) && $formatter->this_mod_only) { break; } } $model->formatted_name($fmt_name); $model->save(); } /** If a vendor is selected, intialize a vendorItems record */ if ($vendorID != 0) { $vitem = new VendorItemsModel($dbc); $vitem->vendorID($vendorID); $vitem->upc($upc); $sku = FormLib::get('vendorSKU'); if (empty($sku)) { $sku = $upc; } else { /** If a SKU is provided, update any old record that used the UPC as a placeholder SKU. */ $existsP = $dbc->prepare(' SELECT sku FROM vendorItems WHERE sku=? AND upc=? AND vendorID=?'); $existsR = $dbc->execute($existsP, array($sku, $upc, $vendorID)); if ($dbc->numRows($existsR) > 0 && $sku != $upc) { $delP = $dbc->prepare(' DELETE FROM vendorItems WHERE sku =? AND upc=? AND vendorID=?'); $dbc->execute($delP, array($upc, $upc, $vendorID)); } else { $fixSkuP = $dbc->prepare(' UPDATE vendorItems SET sku=? WHERE sku=? AND vendorID=?'); $dbc->execute($fixSkuP, array($sku, $upc, $vendorID)); } } $vitem->sku($sku); $vitem->size($model->size()); $vitem->description($model->description()); $vitem->brand($model->brand()); $vitem->units(FormLib::get('caseSize', 1)); $vitem->cost($model->cost()); $vitem->save(); } if ($dbc->table_exists('prodExtra')) { $extra = new ProdExtraModel($dbc); $extra->upc($upc); if (!$extra->load()) { $extra->variable_pricing(0); $extra->margin(0); $extra->case_quantity(''); $extra->case_cost(0.0); $extra->case_info(''); } $brand = FormLib::get('manufacturer'); if (isset($brand[0])) { $extra->manufacturer(str_replace("'", '', $brand[0])); } $dist = FormLib::get('distributor'); if (isset($dist[0])) { $extra->distributor(str_replace("'", '', $dist[0])); } $cost = FormLib::get('cost'); if (isset($cost[0])) { $extra->cost($cost[0]); } $extra->save(); } if (!isset($FANNIE_PRODUCT_MODULES['ProdUserModule'])) { if ($dbc->table_exists('productUser')) { $ldesc = FormLib::get_form_value('puser_description'); $model = new ProductUserModel($dbc); $model->upc($upc); $model->description($ldesc); $model->save(); } } }
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; }
function SaveFormData($upc) { $upc = BarcodeLib::padUPC($upc); $ids = FormLib::get_form_value('v_id', array()); $skus = FormLib::get_form_value('v_sku', array()); $costs = FormLib::get_form_value('v_cost', array()); $units = FormLib::get_form_value('v_units', array()); $sizes = FormLib::get_form_value('v_size', array()); $dbc = $this->db(); $chkP = $dbc->prepare_statement('SELECT upc FROM vendorItems WHERE vendorID=? AND upc=?'); $insP = $dbc->prepare_statement('INSERT INTO vendorItems (upc,vendorID,cost,units,sku,size) VALUES (?,?,?,?,?,?)'); $upP = $dbc->prepare_statement('UPDATE vendorItems SET cost=?,units=?,sku=?,size=? WHERE upc=? AND vendorID=?'); $initP = $dbc->prepare(' UPDATE vendorItems SET brand=?, description=?, vendorDept=0 WHERE upc=? AND vendorID=?'); $prod = new ProductsModel($dbc); $prod->upc($upc); $prod->load(); $ret = true; for ($i = 0; $i < count($ids); $i++) { if (!isset($skus[$i]) || !isset($costs[$i]) || !isset($units[$i])) { continue; // bad submit } // always create record for the default vendor // but only initialize an empty one if no // record exists. if ($ids[$i] == $prod->default_vendor_id()) { $defaultR = $dbc->execute($chkP, array($ids[$i], $prod->upc())); if ($dbc->numRows($defaultR) == 0) { if (empty($skus[$i])) { $skus[$i] = $prod->upc(); } if (empty($costs[$i])) { $costs[$i] = $prod->cost(); } if (empty($units[$i])) { $units[$i] = 1; } if (empty($sizes[$i])) { $sizes[$i] = ''; } } } if (empty($skus[$i]) || empty($costs[$i])) { continue; // no submission. don't create a record } $chkR = $dbc->exec_statement($chkP, array($ids[$i], $upc)); if ($dbc->num_rows($chkR) == 0) { $try = $dbc->exec_statement($insP, array($upc, $ids[$i], $costs[$i], $units[$i], $skus[$i], $sizes[$i])); if ($try === false) { $ret = false; } else { // initialize new record with product's brand // and description so it isn't blank $dbc->execute($initP, array($prod->brand(), $prod->description(), $upc, $ids[$i])); } } else { $try = $dbc->exec_statement($upP, array($costs[$i], $units[$i], $skus[$i], $sizes[$i], $upc, $ids[$i])); if ($try === false) { $ret = false; } } } return $ret; }
public function get_id_handler() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $upc = BarcodeLib::padUPC($this->id); $product = new ProductsModel($dbc); $product->upc($upc); if (!$product->load()) { $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', 'Item not found');\n"); $this->__route_stem = 'get'; } else { $this->description = $product->description(); $this->cost = $product->cost(); $this->price = $product->normal_price(); $this->department = $product->department(); $this->upc = $upc; } return true; }