Example #1
0
 public function testItemFlags()
 {
     $config = FannieConfig::factory();
     $connection = FannieDB::get($config->OP_DB);
     /**
       Setup preconditions for the test
     */
     $upc = BarcodeLib::padUPC('16');
     $product = new ProductsModel($connection);
     $product->upc($upc);
     $product->store_id(0);
     $product->load();
     if ($product->numflag() != 0) {
         $product->numflag(0);
     }
     $product->save();
     $module = new ItemFlagsModule();
     $module->setConnection($connection);
     $module->setConfig($config);
     $form = new \COREPOS\common\mvc\ValueContainer();
     $module->setForm($form);
     $saved = $module->saveFormData($upc);
     $this->assertEquals(true, $saved, 'Handled empty input');
     $product->reset();
     $product->upc($upc);
     $product->load();
     $this->assertEquals(0, $product->numflag(), 'Wrong numflag value ' . $product->numflag());
     /**
       Simulate real form input
     */
     $form = new \COREPOS\common\mvc\ValueContainer();
     $form->flags = array(1, 3);
     // 0b101 == 5
     $module->setForm($form);
     $saved = $module->saveFormData($upc);
     $this->assertEquals(true, $saved, 'Saving item flags failed');
     $product->reset();
     $product->upc($upc);
     $product->load();
     $this->assertEquals(5, $product->numflag(), 'Wrong numflag value ' . $product->numflag());
     /* put record back to normal */
     $product->numflag(0);
     $product->save();
     $form = new \COREPOS\common\mvc\ValueContainer();
     $form->flags = 'not_an_array';
     $module->setForm($form);
     $saved = $module->saveFormData($upc);
     $this->assertEquals(false, $saved, 'Accepted invalid input');
 }
Example #2
0
 function post_id_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $upc = BarcodeLib::padUPC($this->id);
     $model = new ProductsModel($dbc);
     $model->upc($upc);
     $model->store_id(1);
     $model->discounttype(0);
     $model->special_price(0);
     $model->modified(date('Y-m-d H:i:s'));
     $model->save();
     $batchID = FormLib::get_form_value('batchID');
     $batchUPC = FormLib::get_form_value('batchUPC');
     if ($batchID !== '' && $batchUPC !== '') {
         if (substr($batchUPC, 0, 2) != 'LC') {
             $batchUPC = BarcodeLib::padUPC($batchUPC);
         }
         $batchP = $dbc->prepare_statement('DELETE FROM batchList
                 WHERE upc=? AND batchID=?');
         $batchR = $dbc->exec_statement($batchP, array($batchUPC, $batchID));
     }
     require 'laneUpdates.php';
     updateProductAllLanes($upc);
     header('Location: ItemEditorPage.php?searchupc=' . $upc);
     return False;
 }
Example #3
0
 function preprocess()
 {
     global $FANNIE_OP_DB;
     // custom: can delete items from report results
     if (isset($_REQUEST['deleteItem'])) {
         $upc = FormLib::get_form_value('deleteItem', '');
         if (is_numeric($upc)) {
             $upc = BarcodeLib::padUPC($upc);
         }
         $dbc = FannieDB::get($FANNIE_OP_DB);
         $model = new ProductsModel($dbc);
         $model->upc($upc);
         $model->store_id(1);
         $model->delete();
         echo 'Deleted';
         return false;
     } elseif (FormLib::get('deactivate') !== '') {
         $upc = BarcodeLib::padUPC(FormLib::get('deactivate'));
         $dbc = FannieDB::get($FANNIE_OP_DB);
         $model = new ProductsModel($dbc);
         $model->upc($upc);
         $model->store_id(1);
         $model->inUse(0);
         $model->save();
         echo 'Deactivated';
     }
     $ret = parent::preprocess();
     // custom: needs extra JS for delete option
     if ($this->content_function == 'report_content' && $this->report_format == 'html') {
         $this->add_script("../../src/javascript/jquery.js");
         $this->add_script('delete.js');
     }
     return $ret;
 }
Example #4
0
 public function post_id_handler()
 {
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $new = FormLib::get('new-upc');
     if ($new == '') {
         $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'New UPC cannot be blank');\n");
         return true;
     }
     $new = BarcodeLib::padUPC($new);
     $model = new ProductsModel($dbc);
     $model->upc($new);
     if ($model->load()) {
         $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'New item {$new} already exists');\n");
         return true;
     }
     $model->reset();
     $model->upc(BarcodeLib::padUPC($this->id));
     if (!$model->load()) {
         $this->addOnloadCommand("showBootstrapAlert('#alert-area', 'danger', 'Source item " . $model->upc() . " not found');\n");
         return true;
     }
     $model->upc($new);
     $description = substr('CLONE ' . $model->description(), 0, 30);
     $model->description($description);
     $model->store_id(1);
     $model->save();
     if ($dbc->tableExists('prodExtra')) {
         $extra = new ProdExtraModel($dbc);
         $extra->upc(BarcodeLib::padUPC($this->id));
         $extra->load();
         $extra->upc($new);
         $extra->save();
     }
     if ($dbc->tableExists('productUser')) {
         $user = new ProductUserModel($dbc);
         $user->upc(BarcodeLib::padUPC($this->id));
         $user->load();
         $user->upc($new);
         $user->save();
     }
     header('Location: ItemEditorPage.php?searchupc=' . $new);
     return false;
 }
Example #5
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 #6
0
 public function SaveFormData($upc)
 {
     $upc = BarcodeLib::padUPC($upc);
     $dbc = $this->db();
     $model = new ProductsModel($dbc);
     $model->upc($upc);
     $model->store_id(1);
     $method = FormLib::get_form_value('vp_method', 0);
     $qty = FormLib::get_form_value('vp_qty', 0);
     $price = FormLib::get_form_value('vp_price', 0);
     $mixmatch = FormLib::get_form_value('vp_mm', 0);
     $model->pricemethod($method);
     $model->quantity($qty);
     $model->groupprice($price);
     $model->mixmatchcode($mixmatch);
     $r1 = $model->save();
     if ($r1 === false) {
         return false;
     } else {
         return true;
     }
 }
Example #7
0
 public function SaveFormData($upc)
 {
     $local = $this->db();
     $upc = BarcodeLib::padUPC($upc);
     $pu = new ProductUserModel($local);
     $pu->upc($upc);
     $pu->enableOnline(FormLib::get('u_online') == 1 ? 1 : 0);
     $pu->soldOut(FormLib::get('u_soldout') == 1 ? 1 : 0);
     $pu->save();
     include dirname(__FILE__) . '/../../src/Credentials/OutsideDB.tunneled.php';
     $remote = $dbc;
     $pu->load();
     if ($pu->enableOnline() && $remote->isConnected()) {
         $pu->setConnection($remote);
         $pu->save();
         $prod = new ProductsModel($local);
         $prod->upc($upc);
         $prod->load();
         $prod->setConnection($remote);
         $prod->save();
     } elseif (FormLib::get('u_already_online') && $remote->isConnected()) {
         $prod = new ProductsModel($remote);
         $prod->upc($upc);
         $prod->delete();
     }
     if ($local->tableExists('productExpires')) {
         $e = new ProductExpiresModel($local);
         $e->upc($upc);
         $e->expires(FormLib::getDate('u_expires', date('Y-m-d')));
         $e->save();
         if ($e->expires() && $remote->isConnected()) {
             $e->setConnection($remote);
             $e->save();
         }
     }
 }
Example #8
0
 function SaveFormData($upc)
 {
     $upc = BarcodeLib::padUPC($upc);
     $brand = FormLib::get('lf_brand');
     $desc = FormLib::get('lf_desc');
     $origin = FormLib::get('origin', 0);
     $floorID = FormLib::get('floor-id', 0);
     $text = FormLib::get('lf_text');
     $text = str_replace("\r", '', $text);
     $text = str_replace("\n", '<br />', $text);
     // strip non-ASCII (word copy/paste artifacts)
     $text = preg_replace("/[^-]/", "", $text);
     $signs = FormLib::get('sign-count', 1);
     if ($signs < 1) {
         $signs = 1;
     }
     $dbc = $this->db();
     $loc = new ProdPhysicalLocationModel($dbc);
     $loc->upc($upc);
     $loc->floorSectionID($floorID);
     $loc->save();
     $model = new ProductUserModel($dbc);
     $model->upc($upc);
     $model->brand($brand);
     $model->description($desc);
     $model->long_text($text);
     $model->signCount($signs);
     $multiOrigin = FormLib::get('otherOrigin', array());
     $originMap = array();
     if ($origin != 0) {
         $originMap[] = $origin;
     }
     foreach ($multiOrigin as $originID) {
         if ($originID != 0) {
             $originMap[] = $originID;
         }
     }
     $mapP = $dbc->prepare('DELETE FROM ProductOriginsMap WHERE upc=?');
     $addP = $dbc->prepare('INSERT INTO ProductOriginsMap
                             (originID, upc, active)
                             VALUES (?, ?, 1)');
     $lcP = $dbc->prepare('SELECT u.upc
                         FROM upcLike AS u
                             ' . DTrans::joinProducts('u', 'p', 'INNER') . '
                         WHERE u.likeCode IN (
                             SELECT l.likeCode
                             FROM upcLike AS l
                             WHERE l.upc = ?
                         )');
     $lcR = $dbc->execute($lcP, array($upc));
     $items = array($upc);
     while ($w = $dbc->fetch_row($lcR)) {
         if ($w['upc'] == $upc) {
             continue;
         }
         $items[] = $w['upc'];
     }
     $prod = new ProductsModel($dbc);
     $stores = new StoresModel($dbc);
     foreach ($items as $item) {
         $prod->upc($item);
         $prod->store_id(1);
         $prod->current_origin_id($origin);
         $prod->save();
         $dbc->execute($mapP, array($item));
         foreach ($originMap as $originID) {
             $dbc->execute($addP, array($originID, $item));
         }
     }
     return $model->save();
 }
Example #9
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 #10
0
 function SaveFormData($upc)
 {
     /* check if data was submitted */
     if (FormLib::get('s_plu') === '') {
         return False;
     }
     $desc = FormLib::get('descript', '');
     if (is_array($desc)) {
         $desc = array_pop($desc);
     }
     $longdesc = FormLib::get('s_longdesc', '');
     if (trim($longdesc) !== '') {
         $desc = $longdesc;
     }
     $price = FormLib::get('price', 0);
     if (is_array($price)) {
         $price = array_pop($price);
     }
     $tare = FormLib::get('s_tare', 0);
     $shelf = FormLib::get('s_shelflife', 0);
     $bycount = FormLib::get('s_bycount', 0);
     $graphics = FormLib::get('s_graphics', 0);
     $type = FormLib::get('s_type', 'Random Weight');
     $weight = $type == 'Random Weight' ? 0 : 1;
     $text = FormLib::get('s_text', '');
     $align = FormLib::get('s_label', 'horizontal');
     $netWeight = FormLib::get('s_netwt', 0);
     $label = \COREPOS\Fannie\API\item\ServiceScaleLib::attributesToLabel($align, $type == 'Fixed Weight' ? true : false, $graphics != 0 ? true : false);
     $dbc = $this->db();
     // apostrophes might make a mess
     // double quotes definitely will
     // DGW quotes text fields w/o any escaping
     $desc = str_replace("'", "", $desc);
     $text = str_replace("'", "", $text);
     $desc = str_replace("\"", "", $desc);
     $text = str_replace("\"", "", $text);
     /**
       Safety check:
       A fixed-weight item sticked by the each flagged
       as scalable will interact with the register's
       quantity * upc functionality incorrectly
     */
     if ($weight == 1 && $bycount == 1) {
         $p = new ProductsModel($dbc);
         $p->upc($upc);
         $p->store_id(1);
         if ($p->load()) {
             $p->Scale(0);
             $p->save();
         }
     }
     $scaleItem = new ScaleItemsModel($dbc);
     $scaleItem->plu($upc);
     $action = 'ChangeOneItem';
     if (!$scaleItem->load()) {
         // new record
         $action = "WriteOneItem";
     }
     $scaleItem->price($price);
     $scaleItem->itemdesc($desc);
     $scaleItem->weight($type == 'Fixed Weight' ? 1 : 0);
     $scaleItem->bycount($bycount);
     $scaleItem->tare($tare);
     $scaleItem->shelflife($shelf);
     $scaleItem->text($text);
     $scaleItem->label($label);
     $scaleItem->graphics($graphics ? 121 : 0);
     $scaleItem->netWeight($netWeight);
     $scaleItem->save();
     // extract scale PLU
     preg_match("/^002(\\d\\d\\d\\d)0/", $upc, $matches);
     $s_plu = $matches[1];
     if ($s_plu == '0000') {
         preg_match("/^0020(\\d\\d\\d\\d)/", $upc, $matches);
         $s_plu = $matches[1];
     }
     $item_info = array('RecordType' => $action, 'PLU' => $s_plu, 'Description' => $desc, 'Tare' => $tare, 'ShelfLife' => $shelf, 'Price' => $price, 'Label' => $label, 'ExpandedText' => $text, 'ByCount' => $bycount);
     if ($netWeight != 0) {
         $item_info['NetWeight'] = $netWeight;
     }
     if ($graphics) {
         $item_info['Graphics'] = 121;
     }
     // normalize type + bycount; they need to match
     if ($item_info['ByCount'] && $type == 'Random Weight') {
         $item_info['Type'] = 'By Count';
     } else {
         if ($type == 'Fixed Weight') {
             $item_info['Type'] = 'Fixed Weight';
             $item_info['ByCount'] = 1;
         } else {
             $item_info['Type'] = 'Random Weight';
             $item_info['ByCount'] = 0;
         }
     }
     $scales = array();
     $scaleIDs = FormLib::get('scaleID', array());
     $model = new ServiceScalesModel($dbc);
     /**
       Send item to requested scales
     */
     if (count($scaleIDs) > 0) {
         $chkMap = $dbc->prepare('SELECT upc
                                  FROM ServiceScaleItemMap
                                  WHERE serviceScaleID=?
                                     AND upc=?');
         $addMap = $dbc->prepare('INSERT INTO ServiceScaleItemMap
                                     (serviceScaleID, upc)
                                  VALUES
                                     (?, ?)');
         foreach ($scaleIDs as $scaleID) {
             $model->reset();
             $model->serviceScaleID($scaleID);
             if (!$model->load()) {
                 // scale doesn't exist
                 continue;
             }
             $repr = array('host' => $model->host(), 'dept' => $model->scaleDeptName(), 'type' => $model->scaleType(), 'new' => false);
             $exists = $dbc->execute($chkMap, array($scaleID, $upc));
             if ($dbc->num_rows($exists) == 0) {
                 $repr['new'] = true;
                 $dbc->execute($addMap, array($scaleID, $upc));
             }
             $scales[] = $repr;
         }
         HobartDgwLib::writeItemsToScales($item_info, $scales);
         EpScaleLib::writeItemsToScales($item_info, $scales);
     }
     /**
       Delete item from scales if that
       option was unchecked
     */
     $mapP = $dbc->prepare('
         SELECT serviceScaleID
         FROM ServiceScaleItemMap
         WHERE upc=?');
     $mapR = $dbc->execute($mapP, array($upc));
     $delP = $dbc->prepare('
         DELETE
         FROM ServiceScaleItemMap
         WHERE serviceScaleID=?
             AND upc=?');
     if ($mapR && $dbc->numRows($mapR)) {
         $scales = array();
         while ($mapW = $dbc->fetchRow($mapR)) {
             if (in_array($mapW['serviceScaleID'], $scaleIDs)) {
                 // item sent to that scale
                 continue;
             }
             $model->reset();
             $model->serviceScaleID($mapW['serviceScaleID']);
             if (!$model->load()) {
                 // scale doesn't exist
                 continue;
             }
             $repr = array('host' => $model->host(), 'dept' => $model->scaleDeptName(), 'type' => $model->scaleType(), 'new' => false);
             $scales[] = $repr;
             $dbc->execute($delP, array($mapW['serviceScaleID'], $upc));
         }
         if (count($scales) > 0) {
             HobartDgwLib::deleteItemsFromScales($item_info['PLU'], $scales);
         }
     }
 }
Example #11
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 #12
0
$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']);
//echo $strMod;
Example #13
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 #14
0
 public function saveFormData($upc)
 {
     try {
         $flags = $this->form->flags;
     } catch (Exception $ex) {
         $flags = array();
     }
     if (!is_array($flags)) {
         return false;
     }
     $numflag = 0;
     foreach ($flags as $f) {
         if ($f != (int) $f) {
             continue;
         }
         $numflag = $numflag | 1 << $f - 1;
     }
     $dbc = $this->connection;
     $model = new ProductsModel($dbc);
     $model->upc($upc);
     $model->store_id(1);
     $model->numflag($numflag);
     $saved = $model->save();
     return $saved ? true : false;
 }
Example #15
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 #16
0
 function SaveFormData($upc)
 {
     $upc = BarcodeLib::padUPC($upc);
     $deposit = FormLib::get_form_value('deposit', 0);
     $inUse = FormLib::get_form_value('inUse', 0);
     $local = FormLib::get_form_value('local', 0);
     $idReq = FormLib::get_form_value('idReq', 0);
     $dbc = $this->db();
     $pm = new ProductsModel($dbc);
     $pm->upc($upc);
     $pm->store_id(1);
     $pm->deposit($deposit);
     $pm->local($local);
     $pm->inUse($inUse);
     $pm->idEnforced($idReq);
     $r1 = $pm->save();
     if ($r1 === false) {
         return false;
     } else {
         return true;
     }
 }
Example #17
0
 function SaveFormData($upc)
 {
     $lc = FormLib::get_form_value('likeCode');
     $dbc = $this->db();
     $delP = $dbc->prepare_statement('DELETE FROM upcLike WHERE upc=?');
     $delR = $dbc->exec_statement($delP, array($upc));
     if ($lc == -1) {
         return $delR === False ? False : True;
     }
     $insP = 'INSERT INTO upcLike (upc,likeCode) VALUES (?,?)';
     $insR = $dbc->exec_statement($insP, array($upc, $lc));
     if (FormLib::get_form_value('LikeCodeNoUpdate') == 'noupdate') {
         return $insR === False ? False : True;
     }
     /* get values for current item */
     $valuesP = $dbc->prepare_statement('SELECT normal_price,pricemethod,groupprice,quantity,
         department,scale,tax,foodstamp,discount,qttyEnforced,local,wicable
         FROM products WHERE upc=?');
     $valuesR = $dbc->exec_statement($valuesP, array($upc));
     if ($dbc->num_rows($valuesR) == 0) {
         return False;
     }
     $values = $dbc->fetch_row($valuesR);
     /* apply current values to other other items
        in the like code */
     $upcP = $dbc->prepare_statement('SELECT upc FROM upcLike WHERE likeCode=? AND upc<>?');
     $upcR = $dbc->exec_statement($upcP, array($lc, $upc));
     $isHQ = FannieConfig::config('STORE_MODE') == 'HQ' ? true : false;
     $stores = new StoresModel($dbc);
     $stores = array_map(array_filter($stores->find(), function ($obj) {
         return $obj->hasOwnItems();
     }), function ($obj) {
         return $obj->storeID();
     });
     $model = new ProductsModel($dbc);
     $model->upc($upc);
     $model->mixmatchcode($lc + 500);
     if ($isHQ) {
         foreach ($stores as $store_id) {
             $model->store_id($store_id);
             $model->save();
         }
     } else {
         $model->save();
     }
     while ($upcW = $dbc->fetch_row($upcR)) {
         $model->reset();
         $model->upc($upcW['upc']);
         $model->normal_price($values['normal_price']);
         $model->pricemethod($values['pricemethod']);
         $model->groupprice($values['groupprice']);
         $model->quantity($values['quantity']);
         $model->department($values['department']);
         $model->scale($values['scale']);
         $model->tax($values['tax']);
         $model->foodstamp($values['foodstamp']);
         $model->discount($values['discount']);
         $model->qttyEnforced($values['qttyEnforced']);
         $model->local($values['local']);
         $model->wicable($values['wicable']);
         $model->mixmatchcode($lc + 500);
         if ($isHQ) {
             foreach ($stores as $store_id) {
                 $model->store_id($store_id);
                 $model->save();
             }
         } else {
             $model->save();
         }
         updateProductAllLanes($upcW['upc']);
     }
     return true;
 }
Example #18
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;
 }
Example #19
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 #20
0
             if ($prod->price_rule_id() == 0) {
                 $prod->price_rule_id(1);
             }
             $prod->save();
         } else {
             $prod = new ProductsModel($sql);
             $prod->upc($upc);
             $prod->store_id(1);
             $prod->load();
             $ruleID = 0;
             // remove the rule but save its ID
             if ($prod->price_rule_id() != 0) {
                 $ruleID = $prod->price_rule_id();
                 $prod->price_rule_id(0);
             }
             $prod->save();
             // make sure no other item is using the same
             // rule before deleting it
             if ($ruleID > 1) {
                 $prod->reset();
                 $prod->price_rule_id($ruleID);
                 if (count($prod->find()) == 0) {
                     // no products are using this rule
                     $rule = new PriceRulesModel($sql);
                     $rule->priceRuleID($ruleID);
                     $rule->delete();
                 }
             }
         }
         break;
 }
Example #21
0
 public function saveFormData($upc)
 {
     $db = $this->db();
     $new_rule = FormLib::get('price-rule-id', 0);
     $old_rule = FormLib::get('current-price-rule-id', 0);
     if ($new_rule != $old_rule) {
         $prod = new ProductsModel($db);
         $prod->upc(BarcodeLib::padUPC($upc));
         $prod->store_id(1);
         $rule = new PriceRulesModel($db);
         switch ($new_rule) {
             case 0:
                 // no custom rule
             // no custom rule
             case 1:
                 // generic variable pricing
                 /**
                   Update the product with the generic rule ID
                   If it was previously set to a custom rule,
                   that custom rule can be deleted
                 */
                 $prod->price_rule_id($new_rule);
                 if ($old_rule > 1) {
                     $rule->priceRuleID($old_rule);
                     $rule->delete();
                 }
                 break;
             default:
                 // custom rule
                 /**
                   If the product is already using a custom rule,
                   just update that rule record. Otherwise create
                   a new one.
                 */
                 $rule->reviewDate(FormLib::get('rule-review-date'));
                 $rule->details(FormLib::get('rule-details'));
                 $rule->priceRuleTypeID(FormLib::get('price-rule-type'));
                 if ($old_rule > 1) {
                     $rule->priceRuleID($old_rule);
                     $prod->price_rule_id($old_rule);
                     // just in case
                 } else {
                     $new_rule_id = $rule->save();
                     $prod->price_rule_id($new_rule_id);
                 }
         }
         $prod->save();
     }
     return true;
 }