Example #1
0
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     if (!isset($_SESSION['vid'])) {
         $this->error_details = 'Missing vendor setting';
         return False;
     }
     $VENDOR_ID = $_SESSION['vid'];
     $p = $dbc->prepare_statement("SELECT vendorID,vendorName FROM vendors WHERE vendorID=?");
     $idR = $dbc->exec_statement($p, array($VENDOR_ID));
     if ($dbc->num_rows($idR) == 0) {
         $this->error_details = 'Cannot find vendor';
         return False;
     }
     $idW = $dbc->fetch_row($idR);
     $vendorName = $idW['vendorName'];
     $SKU = $this->get_column_index('sku');
     $BRAND = $this->get_column_index('brand');
     $DESCRIPTION = $this->get_column_index('desc');
     $QTY = $this->get_column_index('qty');
     $SIZE1 = $this->get_column_index('size');
     $UPC = $this->get_column_index('upc');
     $CATEGORY = $this->get_column_index('vDept');
     $REG_COST = $this->get_column_index('cost');
     $NET_COST = $this->get_column_index('saleCost');
     $REG_UNIT = $this->get_column_index('unitCost');
     $NET_UNIT = $this->get_column_index('unitSaleCost');
     $SRP = $this->get_column_index('srp');
     // PLU items have different internal UPCs
     // map vendor SKUs to the internal PLUs
     $SKU_TO_PLU_MAP = array();
     $skusP = $dbc->prepare('SELECT sku, upc FROM vendorSKUtoPLU WHERE vendorID=?');
     $skusR = $dbc->execute($skusP, array($VENDOR_ID));
     while ($skusW = $dbc->fetch_row($skusR)) {
         $SKU_TO_PLU_MAP[$skusW['sku']] = $skusW['upc'];
     }
     $itemP = $dbc->prepare("\n            INSERT INTO vendorItems (\n                brand, \n                sku,\n                size,\n                upc,\n                units,\n                cost,\n                description,\n                vendorDept,\n                vendorID,\n                saleCost,\n                modified,\n                srp\n            ) VALUES (\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?,\n                ?\n            )");
     $srpP = false;
     if ($dbc->tableExists('vendorSRPs')) {
         $srpP = $dbc->prepare_statement("INSERT INTO vendorSRPs (vendorID, upc, srp) VALUES (?,?,?)");
     }
     $pm = new ProductsModel($dbc);
     foreach ($linedata as $data) {
         if (!is_array($data)) {
             continue;
         }
         if (!isset($data[$UPC])) {
             continue;
         }
         // grab data from appropriate columns
         $sku = $data[$SKU];
         $brand = $BRAND === false ? $vendorName : substr($data[$BRAND], 0, 50);
         $description = substr($data[$DESCRIPTION], 0, 50);
         if ($QTY === false) {
             $qty = 1.0;
         } else {
             $qty = $data[$QTY];
             if (!is_numeric($qty)) {
                 $qty = 1.0;
             }
         }
         $size = $SIZE1 === false ? '' : substr($data[$SIZE1], 0, 25);
         $upc = $data[$UPC];
         $upc = str_replace(' ', '', $upc);
         $upc = str_replace('-', '', $upc);
         if (strlen($upc) > 13) {
             $upc = substr($upc, -13);
         } else {
             $upc = str_pad($upc, 13, '0', STR_PAD_LEFT);
         }
         // zeroes isn't a real item, skip it
         if ($upc == "0000000000000") {
             continue;
         }
         if ($_SESSION['vUploadCheckDigits']) {
             $upc = '0' . substr($upc, 0, 12);
         }
         if (isset($SKU_TO_PLU_MAP[$sku])) {
             $upc = $SKU_TO_PLU_MAP[$sku];
         }
         $category = $CATEGORY === false ? 0 : $data[$CATEGORY];
         $reg_unit = '';
         if ($REG_UNIT !== false) {
             $reg_unit = trim($data[$REG_UNIT]);
             $reg_unit = $this->priceFix($reg_unit);
         }
         if (!is_numeric($reg_unit) && $REG_COST !== false) {
             $reg = trim($data[$REG_COST]);
             $reg = $this->priceFix($reg);
             if (is_numeric($reg)) {
                 $reg_unit = $reg / $qty;
             }
         }
         // skip the item if prices aren't numeric
         // this will catch the 'label' line in the first CSV split
         // since the splits get returned in file system order,
         // we can't be certain *when* that chunk will come up
         // can't process items w/o price (usually promos/samples anyway)
         if (empty($reg_unit) || !is_numeric($reg_unit)) {
             continue;
         }
         $net_unit = '';
         if ($NET_UNIT !== false) {
             $net_unit = trim($data[$NET_UNIT]);
             $net_unit = $this->priceFix($net_unit);
         }
         if (!is_numeric($net_unit) && $NET_COST !== false) {
             $net = trim($data[$NET_COST]);
             $net = $this->priceFix($net);
             if (is_numeric($net)) {
                 $net_unit = $net / $qty;
             }
         }
         // blank spreadsheet cell
         if (empty($net_unit)) {
             $net_unit = 0.0;
         }
         $srp = $SRP === false ? 0.0 : trim($data[$SRP]);
         if ($net_unit == $reg_unit) {
             $net_unit = 0.0;
             // not really a sale
         }
         // syntax fixes. kill apostrophes in text fields,
         // trim $ off amounts as well as commas for the
         // occasional > $1,000 item
         $srp = $this->priceFix($srp);
         if (!is_numeric($srp)) {
             $srp = 0;
         }
         $brand = str_replace("'", "", $brand);
         $description = str_replace("'", "", $description);
         $args = array($brand, $sku, $size, $upc, $qty, $reg_unit, $description, $category, $VENDOR_ID, $net_unit, date('Y-m-d H:i:s'), $srp);
         $dbc->execute($itemP, $args);
         if ($srpP) {
             $dbc->exec_statement($srpP, array($VENDOR_ID, $upc, $srp));
         }
         if ($_SESSION['vUploadChangeCosts']) {
             $pm->reset();
             $pm->upc($upc);
             $pm->default_vendor_id($VENDOR_ID);
             foreach ($pm->find('store_id') as $obj) {
                 $obj->cost($reg_unit);
                 $obj->save();
             }
         }
     }
     return true;
 }
Example #2
0
$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();
$checkP = $sql->prepare("SELECT upc FROM prodExtra WHERE upc=?");
$checkR = $sql->execute($checkP, array($upc));
if ($sql->num_rows($checkR) == 0) {
    $extraQ = $sql->prepare("insert into prodExtra values (?,?,?,0,0,0,'','',0,'')");
    $extraR = $sql->execute($extraQ, array($upc, $distributor, $manufacturer));
} else {
    $extraQ = $sql->prepare("update prodExtra set manufacturer=?,distributor=? where upc=?");
    $extraR = $sql->execute($extraQ, array($manufacturer, $distributor, $upc));
}
$model->pushToLanes();
$query1 = $sql->prepare("SELECT * FROM products WHERE upc = ?");
$result1 = $sql->execute($query1, array($upc));
$row = $sql->fetch_array($result1);
$strMod = strtotime($row['modified']);
Example #3
0
 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;
 }
Example #4
0
 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;
     }
 }
Example #5
0
 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";
 }
Example #6
0
 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;
 }
Example #7
0
 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();
         }
     }
 }
Example #8
0
 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;
 }