function unsale($batchID) { global $sql, $FANNIE_SERVER_DBMS; if ($FANNIE_SERVER_DBMS == "MSSQL") { $unsale1Q = $sql->prepare("update products set special_price=0,\n discounttype=0,start_date='',end_date='',\n specialpricemethod=0,specialquantity=0,\n specialgroupprice=0\n from\n products as p left join\n batchlist as b on p.upc=b.upc\n where b.batchID=?"); $unsale2Q = $sql->prepare("update products set special_price=0,\n discounttype=0,start_date='',end_date='',\n specialpricemethod=0,specialquantity=0,\n specialgroupprice=0\n from products as p left join\n upcLike as v on v.upc=p.upc left join\n batchlist as l on l.upc='LC'+convert(varchar,v.likecode)\n left join batches as b on b.batchID = l.batchID\n where b.batchID=?"); $sql->execute($unsale1Q, array($batchID)); $sql->execute($unsale2Q, array($batchID)); } else { $unsale1Q = $sql->prepare("update products as p\n left join batchList as b ON p.upc=b.upc\n set special_price=0,\n p.discounttype=0,start_date='',end_date='',\n specialpricemethod=0,specialquantity=0,\n specialgroupprice=0\n where b.batchID=?"); $unsale2Q = $sql->prepare("update products as p left join\n upcLike as v on v.upc=p.upc left join\n batchList as l on l.upc=concat('LC',convert(v.likeCode,char))\n left join batches as b on b.batchID = l.batchID\n set special_price=0,\n p.discounttype=0,start_date='',end_date='',\n specialpricemethod=0,specialquantity=0,\n specialgroupprice=0\n where b.batchID=?"); $sql->execute($unsale1Q, array($batchID)); $sql->execute($unsale2Q, array($batchID)); } $q = $sql->prepare("SELECT upc FROM batchList WHERE batchID=?"); $r = $sql->execute($q, array($batchID)); $q2 = $sql->prepare("SELECT upc FROM upcLike WHERE likeCode=?"); while ($w = $sql->fetch_row($r)) { $upcs = array($w['upc']); if (substr($w['upc'], 0, 2) == 'LC') { $upcs = array(); $lc = substr($w['upc'], 2); $r2 = $sql->execute($q2, array($lc)); while ($w2 = $sql->fetch_row($r2)) { $upcs[] = $w2['upc']; } } foreach ($upcs as $u) { $model = new ProductsModel(); $model->upc($u); $model->pushToLanes(); } } }
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; }
$update = new ProdUpdateModel($sql); $update->upc($upc); $update->logUpdate(ProdUpdateModel::UPDATE_BATCH); } else { $lc = substr($upc, 2); $unsaleQ = $sql->prepare("UPDATE products AS p LEFT JOIN upcLike as u on p.upc=u.upc\n LEFT JOIN batchList as b ON b.upc=concat('LC',convert(u.likeCode,char))\n set p.discounttype=0,special_price=0,start_date=0,end_date=0 \n WHERE u.likeCode=? and b.batchID=?"); if ($FANNIE_SERVER_DBMS == "MSSQL") { $unsaleQ = $sql->prepare("update products set discounttype=0,special_price=0,start_date=0,end_date=0\n from products as p, batches as b, upcLike as u\n where u.likeCode=? and u.upc=p.upc and b.startdate=p.start_date and b.enddate=p.end_date\n and b.batchID=?"); } $unsaleR = $sql->execute($unsaleQ, array($lc, $id)); $prep = $sql->prepare('SELECT upc FROM upcLike WHERE likeCode=?'); $all = $sql->execute($prep, array($lc)); while ($row = $sql->fetch_row($all)) { $model = new ProductsModel($sql); $model->upc($row['upc']); $model->pushToLanes(); $update = new ProdUpdateModel($sql); $update->upc($upc); $update->logUpdate(ProdUpdateModel::UPDATE_BATCH); } } $delQ = $sql->prepare("delete from batchList where batchID=? and upc=?"); $delR = $sql->execute($delQ, array($id, $upc)); $delQ = $sql->prepare("delete from batchBarcodes where upc=? and batchID=?"); $delR = $sql->execute($delQ, array($upc, $id)); $audited = $_GET['audited']; if ($audited == "1") { \COREPOS\Fannie\API\lib\AuditLib::batchNotification($id, $upc, \COREPOS\Fannie\API\lib\AuditLib::BATCH_DELETE, substr($upc, 0, 2) == 'LC' ? true : false); } $out .= showBatchDisplay($id); break;
/** 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, 'upc')) { // missing required arguments $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters needs type'); return $ret; } if (!is_array($args->upc)) { $args->upc = array($args->upc); } $dbc = \FannieDB::get(\FannieConfig::config('OP_DB')); $storeID = \FannieConfig::get('STORE_ID'); /** In "fast" mode, look up the items and run UPDATE queries on each lane. This reduces overhead substantially but will overlook brand-new items since there's no check whether the item exists on the lane. If "fast" is not specified, each UPC record is copied to the lane exactly using models. This mode is preferrable unless performance becomes an issue. */ if (property_exists($args, 'fast')) { $upc_data = array(); $query = ' SELECT normal_price, pricemethod, quantity, groupprice, special_price, specialpricemethod, specialquantity, specialgroupprice, discounttype, mixmatchcode, department, tax, foodstamp, discount, qttyEnforced, idEnforced, inUse, upc FROM products WHERE store_id=? AND upc IN ('; $params = array($storeID); foreach ($args->upc as $upc) { $query .= '?,'; $params[] = \BarcodeLib::padUPC($upc); } $query = substr($query, 0, strlen($query) - 1); $prep = $dbc->prepare($query); $result = $dbc->execute($prep, $params); while ($w = $dbc->fetchRow($result)) { $upc_data[$w['upc']] = $w; } $updateQ = ' UPDATE products AS p SET p.normal_price = ?, p.pricemethod = ?, p.quantity = ?, p.groupprice = ?, p.special_price = ?, p.specialpricemethod = ?, p.specialquantity = ?, p.specialgroupprice = ?, p.discounttype = ?, p.mixmatchcode = ?, p.department = ?, p.tax = ?, p.foodstamp = ?, p.discount=?, p.qttyEnforced=?, p.idEnforced=?, p.inUse=? WHERE p.upc = ?'; $FANNIE_LANES = \FannieConfig::config('LANES'); for ($i = 0; $i < count($FANNIE_LANES); $i++) { $lane_sql = new \SQLManager($FANNIE_LANES[$i]['host'], $FANNIE_LANES[$i]['type'], $FANNIE_LANES[$i]['op'], $FANNIE_LANES[$i]['user'], $FANNIE_LANES[$i]['pw']); if (!isset($lane_sql->connections[$FANNIE_LANES[$i]['op']]) || $lane_sql->connections[$FANNIE_LANES[$i]['op']] === false) { // connect failed continue; } $updateP = $lane_sql->prepare($updateQ); foreach ($upc_data as $upc => $data) { $lane_args = array($data['normal_price'], $data['pricemethod'], $data['quantity'], $data['groupprice'], $data['special_price'], $data['specialpricemethod'], $data['specialquantity'], $data['specialgroupprice'], $data['discounttype'], $data['mixmatchcode'], $data['department'], $data['tax'], $data['foodstamp'], $data['discount'], $data['qttyEnforced'], $data['idEnforced'], $data['inUse'], $upc); $lane_sql->execute($updateP, $lane_args); } } } else { $product = new \ProductsModel($dbc); $ret['synced'] = array(); foreach ($args->upc as $upc) { $upc = \BarcodeLib::padUPC($upc); $product->upc($upc); $product->store_id($storeID); if ($product->load()) { $product->pushToLanes(); $ret['synced'][] = $upc; } } } return $ret; }