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 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; }
} $manufacturer = str_replace("'", "", $manufacturer); $distributor = str_replace("'", "", $distributor); // lookup vendorID by name $vendorID = 0; $vendor = new VendorsModel($sql); $vendor->vendorName($distributor); foreach ($vendor->find('vendorID') as $obj) { $vendorID = $obj->vendorID(); break; } $stamp = date("Y-m-d H:i:s"); $model = new ProductsModel($sql); $model->upc($upc); $model->description($descript); $model->brand($manufacturer); $model->normal_price($price); $model->tax($tax); $model->scale($Scale); $model->foodstamp($FS); $model->department($dept); $model->inUse($inUse); $model->modified($stamp); $model->qttyEnforced($QtyFrc); $model->discount($NoDisc); $model->pricemethod($price_method); $model->groupprice($vol_price); $model->quantity($vol_qtty); $model->local($local); $model->default_vendor_id($vendorID); $model->save();
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(); } }
public function preprocess() { global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB, $FANNIE_URL, $FANNIE_TRANS_DB; //$this->add_script($FANNIE_URL.'src/javascript/jquery.js'); //$this->add_script($FANNIE_URL.'src/javascript/jquery-ui.js'); if (FormLib::get('upc_in') !== '') { $upc = BarcodeLib::padUPC(FormLib::get('upc_in')); $this->current_item_data['upc'] = $upc; $dbc = FannieDB::get($FANNIE_OP_DB); $model = new ProductsModel($dbc); $model->upc($upc); $vendorID = 0; if ($model->load()) { $this->current_item_data['desc'] = $model->brand() . ' ' . $model->description(); $this->current_item_data['par'] = $model->auto_par(); $vendorID = $model->default_vendor_id(); } $model = new VendorsModel($dbc); $model->vendorID($vendorID); if ($model->load()) { $this->current_item_data['vendor'] = $model->vendorName(); $schedule = new VendorDeliveriesModel($dbc); $schedule->vendorID($vendorID); if ($schedule->load() && $schedule->regular() == 1) { $this->current_item_data['nextDelivery'] = date('D, M jS', strtotime($schedule->nextDelivery())) . ' & ' . date('D, M jS', strtotime($schedule->nextNextDelivery())); $nd = new DateTime(date('Y-m-d', strtotime($schedule->nextDelivery()))); $nnd = new DateTime(date('Y-m-d', strtotime($schedule->nextNextDelivery()))); $this->current_item_data['deliverySpan'] = $nnd->diff($nd)->format('%a'); } $items = new VendorItemsModel($dbc); $items->vendorID($vendorID); $items->upc($upc); $this->current_item_data['cases'] = array(); foreach ($items->find('units') as $item) { $this->current_item_data['cases'][] = $item->units(); } } $saleNow = 'SELECT b.batchName, b.startDate, b.endDate FROM batchList AS l INNER JOIN batches AS b ON b.batchID=l.batchID WHERE l.upc=? AND b.discounttype <> 0 AND b.startDate <= ' . $dbc->now() . ' AND b.endDate >= ' . $dbc->now(); $saleNow = $dbc->prepare($saleNow); $saleNow = $dbc->execute($saleNow, array($upc)); if ($dbc->num_rows($saleNow) > 0) { $row = $dbc->fetch_row($saleNow); $this->current_item_data['onSale'] = $row['batchName'] . ' thru ' . date('D, M jS', strtotime($row['endDate'])); } $saleNext = 'SELECT b.batchName, b.startDate, b.endDate FROM batchList AS l INNER JOIN batches AS b ON b.batchID=l.batchID WHERE l.upc=? AND b.discounttype <> 0 AND b.startDate >= ' . $dbc->now() . ' AND b.endDate >= ' . $dbc->now(); $saleNext = $dbc->prepare($saleNext); $saleNext = $dbc->execute($saleNext, array($upc)); if ($dbc->num_rows($saleNext) > 0) { $row = $dbc->fetch_row($saleNext); $this->current_item_data['soonSale'] = $row['batchName'] . ' on ' . date('D, M jS', strtotime($row['startDate'])); } $ordersQ = 'SELECT v.vendorName, o.placedDate, i.quantity, i.caseSize FROM PurchaseOrderItems AS i INNER JOIN PurchaseOrder AS o ON i.orderID=o.orderID INNER JOIN vendors AS v ON o.vendorID=v.vendorID WHERE i.internalUPC = ? ORDER BY o.placedDate DESC'; $ordersQ = $dbc->add_select_limit($ordersQ, 10); $ordersP = $dbc->prepare($ordersQ); $ordersR = $dbc->execute($ordersP, array($upc)); $orders = array(); while ($w = $dbc->fetch_row($ordersR)) { $orders[] = $w; } $this->current_item_data['orders'] = $orders; $salesQ = 'SELECT ' . DTrans::sumQuantity('d') . ' AS qty, MIN(tdate) as day FROM ' . $FANNIE_TRANS_DB . $dbc->sep() . 'dlog_15 AS d WHERE upc = ? GROUP BY YEAR(tdate), MONTH(tdate), DAY(tdate) ORDER BY YEAR(tdate) DESC, MONTH(tdate) DESC, DAY(tdate) DESC'; $salesP = $dbc->prepare($salesQ); $salesR = $dbc->execute($salesP, array($upc)); $sales = array(); while ($w = $dbc->fetch_row($salesR)) { $sales[] = $w; } $this->current_item_data['sales'] = $sales; } $this->linea_ios_mode = $this->linea_support_available(); if ($this->linea_ios_mode) { $this->add_script($FANNIE_URL . 'src/javascript/linea/cordova-2.2.0.js'); $this->add_script($FANNIE_URL . 'src/javascript/linea/ScannerLib-Linea-2.0.0.js'); } $this->add_script($FANNIE_URL . 'src/javascript/tablesorter/jquery.tablesorter.js'); $this->add_css_file($FANNIE_URL . 'src/javascript/tablesorter/themes/blue/style.css'); //$this->add_css_file($FANNIE_URL.'src/javascript/jquery-ui.css'); return true; }
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(); } } }
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; }