function post_id_handler() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $upc = BarcodeLib::padUPC($this->id); $model = new ProductsModel($dbc); $model->upc($upc); $model->store_id(1); $model->discounttype(0); $model->special_price(0); $model->modified(date('Y-m-d H:i:s')); $model->save(); $batchID = FormLib::get_form_value('batchID'); $batchUPC = FormLib::get_form_value('batchUPC'); if ($batchID !== '' && $batchUPC !== '') { if (substr($batchUPC, 0, 2) != 'LC') { $batchUPC = BarcodeLib::padUPC($batchUPC); } $batchP = $dbc->prepare_statement('DELETE FROM batchList WHERE upc=? AND batchID=?'); $batchR = $dbc->exec_statement($batchP, array($batchUPC, $batchID)); } require 'laneUpdates.php'; updateProductAllLanes($upc); header('Location: ItemEditorPage.php?searchupc=' . $upc); return False; }
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; } }
$dbc = new SQLManager($FANNIE_SERVER, $FANNIE_SERVER_DBMS, $FANNIE_OP_DB, $FANNIE_SERVER_USER, $FANNIE_SERVER_PW); /* 'i9el. Update likecodes */ /* update the item's likecode if specified also update other items in the likecode if the appropriate box isn't checked */ if (isset($_REQUEST['likeCode']) && $_REQUEST['likeCode'] != -1) { $dbc->query("DELETE FROM upcLike WHERE upc='{$upc}'"); $lcQ = "INSERT INTO upcLike (upc,likeCode) VALUES ('{$upc}',{$_REQUEST['likeCode']})"; $dbc->query($lcQ); if (!isset($_REQUEST['update'])) { $upcsQ = "SELECT upc FROM upcLike WHERE likeCode={$_REQUEST['likeCode']} AND upc <> '{$upc}'"; $upcsR = $dbc->query($upcsQ); unset($up_array['description']); while ($upcsW = $dbc->fetch_row($upcsR)) { $dbc->smart_update('products', $up_array, "upc='{$upcsW['0']}' AND store_id={$FANNIE_STORE_ID}"); updateProductAllLanes($upcsW[0]); } } } elseif (isset($_REQUEST['likeCode']) && $_REQUEST['likeCode'] == -1) { $dbc->query("DELETE FROM upcLike WHERE upc='{$upc}'"); } /* 11. Display the post-update values and an input for the next edit. */ /* Display some of the post-update values and an input for the next edit. * The page contains form elements but there is no submit for the them. * The record-select input is also displayed in a proper form with a submit. */ $deptQ = "SELECT dept_no, dept_name FROM departments ORDER BY dept_no"; $deptR = $dbc->query($deptQ); $row = $dbc->fetch_array($deptR); $firstDeptNo = $row['dept_no']; $firstDeptName = $row['dept_name'];
function save_item($isNew) { $FANNIE_PRODUCT_MODULES = $this->config->get('PRODUCT_MODULES'); $FANNIE_URL = $this->config->get('URL'); $upc = FormLib::get_form_value('upc', ''); if ($upc === '' || !is_numeric($upc)) { return '<span style="color:red;">Error: bad UPC:</span> ' . $upc; } $upc = BarcodeLib::padUPC($upc); $audited = false; if (FannieAuth::validateUserQuiet('pricechange')) { // validated; nothing to do } elseif (FannieAuth::validateUserQuiet('audited_pricechange')) { $audited = true; } elseif (($range = FannieAuth::validateUserLimited('pricechange')) !== false) { // validated for certain departments; nothing to do } else { // not authorized to make edits return '<span style="color:red;">Error: Log in to edit</span>'; } uasort($FANNIE_PRODUCT_MODULES, array('ItemEditorPage', 'sortModules')); $form = new \COREPOS\common\mvc\FormValueContainer(); foreach ($FANNIE_PRODUCT_MODULES as $class => $params) { $mod = new $class(); $mod->setConnection($this->connection); $mod->setConfig($this->config); $mod->setForm($form); $mod->SaveFormData($upc); } /* push updates to the lanes */ $dbc = $this->connection; $dbc->selectDB($this->config->get('OP_DB')); $FANNIE_COOP_ID = $this->config->get('COOP_ID'); if (isset($FANNIE_COOP_ID) && $FANNIE_COOP_ID == 'WEFC_Toronto') { updateAllLanes($upc, array('products', 'productUser')); } else { updateProductAllLanes($upc); } if ($audited) { $lc = FormLib::get('likeCode', -1); $no_update = FormLib::get('LikeCodeNoUpdate', false); if ($lc != -1 && !$no_update) { \COREPOS\Fannie\API\lib\AuditLib::itemUpdate($upc, $lc); } else { \COREPOS\Fannie\API\lib\AuditLib::itemUpdate($upc); } } $ret = "<table class=\"table\">"; foreach ($FANNIE_PRODUCT_MODULES as $class => $params) { $mod = new $class(); $rows = $mod->summaryRows($upc); foreach ($rows as $row) { $ret .= '<tr>' . $row . '</tr>'; } } $ret .= '</table>'; return $ret; }
function SaveFormData($upc) { $lc = FormLib::get_form_value('likeCode'); $dbc = $this->db(); $delP = $dbc->prepare_statement('DELETE FROM upcLike WHERE upc=?'); $delR = $dbc->exec_statement($delP, array($upc)); if ($lc == -1) { return $delR === False ? False : True; } $insP = 'INSERT INTO upcLike (upc,likeCode) VALUES (?,?)'; $insR = $dbc->exec_statement($insP, array($upc, $lc)); if (FormLib::get_form_value('LikeCodeNoUpdate') == 'noupdate') { return $insR === False ? False : True; } /* get values for current item */ $valuesP = $dbc->prepare_statement('SELECT normal_price,pricemethod,groupprice,quantity, department,scale,tax,foodstamp,discount,qttyEnforced,local,wicable FROM products WHERE upc=?'); $valuesR = $dbc->exec_statement($valuesP, array($upc)); if ($dbc->num_rows($valuesR) == 0) { return False; } $values = $dbc->fetch_row($valuesR); /* apply current values to other other items in the like code */ $upcP = $dbc->prepare_statement('SELECT upc FROM upcLike WHERE likeCode=? AND upc<>?'); $upcR = $dbc->exec_statement($upcP, array($lc, $upc)); $isHQ = FannieConfig::config('STORE_MODE') == 'HQ' ? true : false; $stores = new StoresModel($dbc); $stores = array_map(array_filter($stores->find(), function ($obj) { return $obj->hasOwnItems(); }), function ($obj) { return $obj->storeID(); }); $model = new ProductsModel($dbc); $model->upc($upc); $model->mixmatchcode($lc + 500); if ($isHQ) { foreach ($stores as $store_id) { $model->store_id($store_id); $model->save(); } } else { $model->save(); } while ($upcW = $dbc->fetch_row($upcR)) { $model->reset(); $model->upc($upcW['upc']); $model->normal_price($values['normal_price']); $model->pricemethod($values['pricemethod']); $model->groupprice($values['groupprice']); $model->quantity($values['quantity']); $model->department($values['department']); $model->scale($values['scale']); $model->tax($values['tax']); $model->foodstamp($values['foodstamp']); $model->discount($values['discount']); $model->qttyEnforced($values['qttyEnforced']); $model->local($values['local']); $model->wicable($values['wicable']); $model->mixmatchcode($lc + 500); if ($isHQ) { foreach ($stores as $store_id) { $model->store_id($store_id); $model->save(); } } else { $model->save(); } updateProductAllLanes($upcW['upc']); } return true; }
protected function delete_id_upc_handler() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $id = $this->id; $upc = $this->upc; $json = array('error' => 0, 'msg' => 'Item ' . $upc . ' removed from batch'); if (substr($upc, 0, 2) != 'LC') { // take the item off sale if this batch is currently on sale if ($this->unsaleUPC($this->upc) === false) { $json['error'] = 1; $json['msg'] = 'Error taking item ' . $upc . ' off sale'; } updateProductAllLanes($upc); } else { $likecode = substr($upc, 2); if ($this->unsaleLikeCode($likecode) === false) { $json['error'] = 1; $json['msg'] = 'Error taking like code ' . $likecode . ' off sale'; } } $delQ = $dbc->prepare_statement("delete from batchList where batchID=? and upc=?"); $delR = $dbc->exec_statement($delQ, array($id, $upc)); if ($delR === false) { if ($json['error']) { $json['msg'] .= '<br />Error deleting item ' . $upc . ' from batch'; } else { $json['error'] = 1; $json['msg'] = 'Error deleting item ' . $upc . ' from batch'; } } $delQ = $dbc->prepare_statement("delete from batchBarcodes where upc=? and batchID=?"); $delR = $dbc->exec_statement($delQ, array($upc, $id)); if (FormLib::get_form_value('audited') == '1') { \COREPOS\Fannie\API\lib\AuditLib::batchNotification($id, $upc, \COREPOS\Fannie\API\lib\AuditLib::BATCH_DELETE, substr($upc, 0, 2) == 'LC' ? true : false); } echo json_encode($json); return false; }