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; } }