Example #1
0
 public function post_start_number_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $dept_no = FormLib::get('department', 0);
     $desc = FormLib::get('description', 'NEW PLU');
     if (empty($desc)) {
         $desc = 'NEW PLU';
     }
     $dept = new DepartmentsModel($dbc);
     $dept->dept_no($dept_no);
     $dept->load();
     $model = new ProductsModel($dbc);
     $model->normal_price(0);
     $model->pricemethod(0);
     $model->quantity(0);
     $model->groupprice(0);
     $model->special_price(0);
     $model->specialpricemethod(0);
     $model->specialquantity(0);
     $model->specialgroupprice(0);
     $model->advertised(0);
     $model->tareweight(0);
     $model->start_date('');
     $model->end_date('');
     $model->discounttype(0);
     $model->wicable(0);
     $model->inUse(1);
     $model->tax($dept->dept_tax());
     $model->foodstamp($dept->dept_fs());
     $model->discount($dept->dept_discount());
     $model->department($dept_no);
     for ($i = 0; $i < $this->number; $i++) {
         $upc = BarcodeLib::padUPC($this->start + $i);
         $model->upc($upc);
         $model->store_id(1);
         $model->description($desc . ' ' . ($i + 1));
         $model->save();
     }
     header('Location: ItemEditorPage.php?searchupc=' . $this->start);
     return false;
 }
Example #2
0
 public function run()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $now = date('Y-m-d 00:00:00');
     $sale_upcs = array();
     // ensure likecode items are mixmatch-able
     if ($dbc->dbms_name() == 'mssql') {
         $dbc->query("UPDATE products\n                SET mixmatchcode=convert(varchar,u.likecode+500)\n                FROM \n                products AS p\n                INNER JOIN upcLike AS u\n                ON p.upc=u.upc");
     } else {
         $dbc->query("UPDATE products AS p\n                INNER JOIN upcLike AS u ON p.upc=u.upc\n                SET p.mixmatchcode=convert(u.likeCode+500,char)");
     }
     $likeP = $dbc->prepare('SELECT u.upc 
                             FROM upcLike AS u
                                 INNER JOIN products AS p ON u.upc=p.upc
                             WHERE likeCode=?');
     $product = new ProductsModel($dbc);
     $b_def = $dbc->tableDefinition('batches');
     // lookup current batches
     $query = 'SELECT l.upc, 
                 l.batchID, 
                 l.pricemethod, 
                 l.salePrice, 
                 l.groupSalePrice,
                 l.quantity,
                 b.startDate, 
                 b.endDate, 
                 b.discounttype
                 ' . (isset($b_def['transLimit']) ? ',b.transLimit' : ',0 AS transLimit') . '
               FROM batches AS b
                 INNER JOIN batchList AS l ON b.batchID = l.batchID
               WHERE b.discounttype <> 0
                 AND b.startDate <= ?
                 AND b.endDate >= ?
               ORDER BY l.upc,
                 l.salePrice DESC';
     $t_def = $dbc->tableDefinition('batchList');
     if (!isset($t_def['groupSalePrice'])) {
         $query = str_replace('l.groupSalePrice', 'NULL AS groupSalePrice', $query);
     }
     /**
       In HQ mode, join on junction table to get UPC+storeID rows
       when applying sale pricing
     */
     if ($this->config->get('STORE_MODE') === 'HQ') {
         $query = str_replace('WHERE', ' LEFT JOIN StoreBatchMap AS s ON b.batchID=s.batchID WHERE ', $query);
         $query = str_replace('SELECT', 'SELECT s.storeID,', $query);
     }
     $prep = $dbc->prepare($query);
     $result = $dbc->execute($prep, array($now, $now));
     while ($row = $dbc->fetch_row($result)) {
         // all items affected by this bathcList record
         // could be more than one in the case of likecodes
         $item_upcs = array();
         // use products column names for readability below
         $special_price = $row['salePrice'];
         $specialpricemethod = $row['pricemethod'];
         if ($row['groupSalePrice'] != null) {
             $specialgroupprice = $row['groupSalePrice'];
         } else {
             $specialgroupprice = abs($row['salePrice']);
         }
         $specialquantity = $row['quantity'];
         $special_limit = $row['transLimit'];
         $start_date = $row['startDate'];
         $end_date = $row['endDate'];
         $discounttype = $row['discounttype'];
         $batchID = $row['batchID'];
         // pricemethod 3 and 4 (AB pricing, typically)
         // has some overly complicated rules
         $mixmatch = false;
         if ($specialpricemethod == 3 || $specialpricemethod == 4) {
             if ($special_price >= 0) {
                 $mixmatch = $row['batchID'];
             } else {
                 $mixmatch = -1 * $row['batchID'];
             }
         }
         // unpack likecodes, if needed
         if (substr($row['upc'], 0, 2) == 'LC') {
             $likeCode = substr($row['upc'], 2);
             $likeR = $dbc->execute($likeP, array($likeCode));
             while ($likeW = $dbc->fetch_row($likeR)) {
                 $item_upcs[] = $likeW['upc'];
                 if ($mixmatch !== false) {
                     $mixmatch = $likeCode + 500;
                 }
             }
         } else {
             $item_upcs[] = $row['upc'];
         }
         // check each item to see if it is on
         // sale with the correct parameters
         foreach ($item_upcs as $upc) {
             $product->reset();
             $product->upc($upc);
             $this->cronMsg('Checking item ' . $upc, FannieLogger::INFO);
             /**
               Transistion mechanism. A batch that is set to apply to
               zero stores really should apply to zero stores. For now
               it fails over to using the local store's ID
             */
             if ($this->config->get('STORE_MODE') === 'HQ') {
                 $storeID = $row['storeID'];
                 if ($storeID == null) {
                     $storeID = $this->config->get('STORE_ID');
                 }
                 $product->store_id($storeID);
             }
             if (!$product->load()) {
                 $this->cronMsg("\tError: item does not exist in products", FannieLogger::NOTICE);
                 continue;
             }
             // list of UPCs that should be on sale
             $sale_upcs[] = $upc;
             $changed = false;
             if ($product->special_price() != $special_price) {
                 $changed = true;
                 $product->special_price($special_price);
             }
             if ($product->specialpricemethod() != $specialpricemethod) {
                 $changed = true;
                 $product->specialpricemethod($specialpricemethod);
             }
             if ($product->specialgroupprice() != $specialgroupprice) {
                 $changed = true;
                 $product->specialgroupprice($specialgroupprice);
             }
             if ($product->specialquantity() != $specialquantity) {
                 $changed = true;
                 $product->specialquantity($specialquantity);
             }
             if ($product->special_limit() != $special_limit) {
                 $changed = true;
                 $product->special_limit($special_limit);
             }
             if ($product->start_date() != $start_date) {
                 $changed = true;
                 $product->start_date($start_date);
             }
             if ($product->end_date() != $end_date) {
                 $changed = true;
                 $product->end_date($end_date);
             }
             if ($product->discounttype() != $discounttype) {
                 $changed = true;
                 $product->discounttype($discounttype);
             }
             if ($mixmatch !== false && $product->mixmatchcode() != $mixmatch) {
                 $changed = true;
                 $product->mixmatchcode($mixmatch);
             }
             if ($product->batchID() != $batchID) {
                 $changed = true;
                 $product->batchID($batchID);
             }
             if ($changed) {
                 $product->save();
                 $this->cronMsg("\tUpdated item", FannieLogger::INFO);
             }
         }
         // end loop on batchList record items
     }
     // end loop on batchList records
     // No sale items; need a filler value for
     // the query below
     if (count($sale_upcs) == 0) {
         $this->cronMsg('Notice: nothing is currently on sale', FannieLogger::WARNING);
         $sale_upcs[] = 'notValidUPC';
     }
     // now look for anything on sale that should not be
     // and take those items off sale
     $upc_in = '';
     foreach ($sale_upcs as $upc) {
         $upc_in .= '?,';
     }
     $upc_in = substr($upc_in, 0, strlen($upc_in) - 1);
     $lookupQ = 'SELECT p.upc
                 FROM products AS p
                 WHERE upc NOT IN (' . $upc_in . ')
                     AND (
                         p.discounttype <> 0
                         OR p.special_price <> 0
                         OR p.specialpricemethod <> 0
                         OR p.specialgroupprice <> 0
                         OR p.specialquantity <> 0
                     )';
     $lookupP = $dbc->prepare($lookupQ);
     $lookupR = $dbc->execute($lookupP, $sale_upcs);
     while ($lookupW = $dbc->fetch_row($lookupR)) {
         $this->cronMsg('Taking ' . $lookupW['upc'] . ' off sale', FannieLogger::INFO);
         $product->reset();
         if ($this->config->get('STORE_MODE') === 'HQ') {
             $product->store_id($this->config->get('STORE_ID'));
         }
         $product->upc($lookupW['upc']);
         $product->discounttype(0);
         $product->special_price(0);
         $product->specialgroupprice(0);
         $product->specialquantity(0);
         $product->start_date('');
         $product->end_date('');
         $product->batchID(0);
         $product->save();
     }
 }
Example #3
0
 // find the batchID(s) of active batches
 // containing the upc
 $batchIDQ = $sql->prepare("select b.batchID from batches as b, batchList as l where\n               b.batchID = l.batchID and l.upc = ? and b.discountType = ?\n           AND " . $sql->now() . " BETWEEN b.startDate and b.endDate");
 $batchIDR = $sql->execute($batchIDQ, array($upc, $discounttype));
 // if there isn't a batch putting that item on sale, then
 // i don't know what's going on.  SO DON'T CHANGE ANYTHING
 if ($sql->num_rows($batchIDR) != 0) {
     // now delete the upc from the batch list(s)
     while ($row = $sql->fetch_array($batchIDR)) {
         $batchID = $row['batchID'];
         $batchQ = $sql->prepare("delete from batchList where\n               upc = ? and batchID = ?");
         echo $batchQ . "<p />";
         $batchR = $sql->execute($batchQ, array($upc, $batchID));
     }
     // take the item off sale in products
     $model->start_date(0);
     $model->end_date(0);
     $model->special_price(0);
     $model->discounttype(0);
     $model->save();
     $model->pushToLanes();
     echo "Item <a href=productTest.php?upc={$upc}>{$upc}</a> is no longer on sale ";
 } else {
     if (isset($_GET['force'])) {
         // take the item off sale in products
         $model->start_date(0);
         $model->end_date(0);
         $model->special_price(0);
         $model->discounttype(0);
         $model->save();
         $model->pushToLanes();
Example #4
0
}
$stamp = date("Y-m-d H:i:s");
// use model instead of raw INSERT query
$model = new ProductsModel($sql);
$model->upc($upc);
$model->description($descript);
$model->brand($manufacturer);
$model->normal_price($price);
$model->pricemethod(0);
$model->groupprice(0.0);
$model->quantity(0);
$model->special_price(0.0);
$model->specialpricemethod(0);
$model->specialgroupprice(0.0);
$model->specialquantity(0);
$model->start_date('');
$model->end_date('');
$model->department($dept);
$model->size(0);
$model->tax($tax);
$model->foodstamp($FS);
$model->scale($Scale);
$model->scaleprice(0);
$model->mixmatchcode(0);
$model->modified($stamp);
$model->advertised(0);
$model->tareweight(0);
$model->discount($NoDisc);
$model->discounttype(0);
$model->unitofmeasure(0);
$model->wicable(0);
Example #5
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 #6
0
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $defaults_table = array();
     $defQ = $dbc->prepare_statement("SELECT dept_no,dept_tax,dept_fs,dept_discount FROM departments");
     $defR = $dbc->exec_statement($defQ);
     while ($defW = $dbc->fetch_row($defR)) {
         $defaults_table[$defW['dept_no']] = array('tax' => $defW['dept_tax'], 'fs' => $defW['dept_fs'], 'discount' => $defW['dept_discount']);
     }
     $upc_index = $this->get_column_index('upc');
     $desc_index = $this->get_column_index('desc');
     $price_index = $this->get_column_index('price');
     $dept_index = $this->get_column_index('dept');
     $ret = true;
     $linecount = 0;
     $checks = FormLib::get_form_value('checks') == 'yes' ? true : false;
     $skipExisting = FormLib::get('skipExisting', 0);
     $model = new ProductsModel($dbc);
     foreach ($linedata as $line) {
         // get info from file and member-type default settings
         // if applicable
         $upc = $line[$upc_index];
         $desc = $line[$desc_index];
         $price = $line[$price_index];
         $price = str_replace('$', '', $price);
         $price = trim($price);
         $dept = $dept_index !== false ? $line[$dept_index] : 0;
         $tax = 0;
         $fs = 0;
         $discount = 1;
         if ($dept_index !== false) {
             if (isset($defaults_table[$dept]['tax'])) {
                 $tax = $defaults_table[$dept]['tax'];
             }
             if (isset($defaults_table[$dept]['discount'])) {
                 $discount = $defaults_table[$dept]['discount'];
             }
             if (isset($defaults_table[$dept]['fs'])) {
                 $fs = $defaults_table[$dept]['fs'];
             }
         }
         // upc cleanup
         $upc = str_replace(" ", "", $upc);
         $upc = str_replace("-", "", $upc);
         if (!is_numeric($upc)) {
             continue;
         }
         // skip header(s) or blank rows
         if ($checks) {
             $upc = substr($upc, 0, strlen($upc) - 1);
         }
         $upc = BarcodeLib::padUPC($upc);
         if (strlen($desc) > 35) {
             $desc = substr($desc, 0, 35);
         }
         $model->reset();
         $model->upc($upc);
         $model->store_id(1);
         if ($model->load() && $skipExisting) {
             continue;
         }
         $model->description($desc);
         $model->normal_price($price);
         $model->department($dept);
         $model->tax($tax);
         $model->foodstamp($fs);
         $model->discount($discount);
         // fully init new record
         $model->pricemethod(0);
         $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->inUse(1);
         $try = $model->save();
         if ($try) {
             $this->stats['imported']++;
         } else {
             $this->stats['errors'][] = 'Error importing UPC ' . $upc;
         }
         if ($linecount++ % 100 == 0) {
             set_time_limit(30);
         }
     }
     return $ret;
 }