public function post_id_handler() { $dbc = FannieDB::get($this->config->get('OP_DB')); $new = FormLib::get('new-upc'); if ($new == '') { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'New UPC cannot be blank');\n"); return true; } $new = BarcodeLib::padUPC($new); $model = new ProductsModel($dbc); $model->upc($new); if ($model->load()) { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'New item {$new} already exists');\n"); return true; } $model->reset(); $model->upc(BarcodeLib::padUPC($this->id)); if (!$model->load()) { $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'Source item " . $model->upc() . " not found');\n"); return true; } $model->upc($new); $description = substr('CLONE ' . $model->description(), 0, 30); $model->description($description); $model->store_id(1); $model->save(); if ($dbc->tableExists('prodExtra')) { $extra = new ProdExtraModel($dbc); $extra->upc(BarcodeLib::padUPC($this->id)); $extra->load(); $extra->upc($new); $extra->save(); } if ($dbc->tableExists('productUser')) { $user = new ProductUserModel($dbc); $user->upc(BarcodeLib::padUPC($this->id)); $user->load(); $user->upc($new); $user->save(); } header('Location: ItemEditorPage.php?searchupc=' . $new); return false; }
function post_save_handler() { global $FANNIE_OP_DB; $upcs = FormLib::get('upc', array()); if (!is_array($upcs) || empty($upcs)) { echo 'Error: invalid data'; return false; } $dept = FormLib::get('dept'); $tax = FormLib::get('tax'); $local = FormLib::get('local'); $brand = FormLib::get('brand'); $vendor = FormLib::get('vendor'); $dbc = FannieDB::get($FANNIE_OP_DB); $vlookup = new VendorsModel($dbc); for ($i = 0; $i < count($upcs); $i++) { $model = new ProductsModel($dbc); $upc = BarcodeLib::padUPC($upcs[$i]); $model->upc($upc); $model->store_id(1); if (isset($dept[$i])) { $model->department($dept[$i]); } if (isset($tax[$i])) { $model->tax($tax[$i]); } if (isset($local[$i])) { $model->local($local[$i]); } if (isset($brand[$i])) { $model->brand($brand[$i]); } if (isset($vendor[$i])) { $vlookup->reset(); $vlookup->vendorName($vendor[$i]); foreach ($vlookup->find('vendorID') as $obj) { $model->default_vendor_id($obj->vendorID()); break; } } if (in_array($upc, FormLib::get('fs', array()))) { $model->foodstamp(1); } else { $model->foodstamp(0); } if (in_array($upc, FormLib::get('disc', array()))) { $model->discount(1); } else { $model->discount(0); } if (in_array($upc, FormLib::get('scale', array()))) { $model->scale(1); } else { $model->scale(0); } $model->modified(date('Y-m-d H:i:s')); $try = $model->save(); if ($try) { $model->pushToLanes(); } else { $this->save_results[] = 'Error saving item ' . $upc; } if (isset($vendor[$i]) && $vendor[$i] != '' || isset($brand[$i]) && $brand[$i] != '') { $extra = new ProdExtraModel($dbc); $extra->upc($upc); if (isset($vendor[$i]) && $vendor[$i] != '') { $extra->distributor($vendor[$i]); } if (isset($brand[$i]) && $brand[$i] != '') { $extra->manufacturer($brand[$i]); } $extra->save(); } $this->upcs[] = $upc; } return true; }
/** Log deletes to prodUpdate Delete corresponding records from other tables */ public function delete() { $update = new ProdUpdateModel($this->connection); $update->upc($this->upc()); $update->logUpdate(ProdUpdateModel::UPDATE_DELETE); $try = parent::delete(); if ($try) { if ($this->connection->tableExists('prodExtra')) { $extra = new ProdExtraModel($this->connection); $extra->upc($this->upc()); $extra->delete(); } $user = new ProductUserModel($this->connection); $user->upc($this->upc()); $user->delete(); } return $try; }
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(); } } }