Esempio n. 1
0
 function post_newbatch_tags_upcs_newprices_handler()
 {
     global $FANNIE_OP_DB, $FANNIE_URL;
     $this->upcs = json_decode($this->upcs);
     $this->newprices = json_decode($this->newprices);
     $dbc = FannieDB::get($FANNIE_OP_DB);
     // try to lookup batch owner
     // failure is ok
     $owner = '';
     $ownerP = $dbc->prepare('SELECT super_name FROM superDeptNames WHERE superID=?');
     $ownerR = $dbc->execute($ownerP, array($this->tags));
     if ($dbc->num_rows($ownerR) > 0) {
         $ownerW = $dbc->fetch_row($ownerR);
         $owner = $ownerW['super_name'];
     }
     // try to lookup correct discount type
     // failure is ok
     $btype = 0;
     $btypeR = $dbc->query('SELECT batchTypeID FROM batchType WHERE discType=0 ORDER BY batchTypeID');
     if ($dbc->num_rows($btypeR) > 0) {
         $btypeW = $dbc->fetch_row($btypeR);
         $btype = $btypeW['batchTypeID'];
     }
     // create batch. date 'yesterday' ensures it doesn't
     // run automatically unless the user re-schedules it
     $b = new BatchesModel($dbc);
     $b->batchName($this->newbatch);
     $b->startDate(date('Y-m-d', strtotime('yesterday')));
     $b->endDate(date('Y-m-d', strtotime('yesterday')));
     $b->batchType($btype);
     $b->discountType(0);
     $b->priority(0);
     $b->owner($owner);
     $id = $b->save();
     // maintain @deprecated table if present
     if ($dbc->tableExists('batchowner')) {
         $insQ = $dbc->prepare_statement("insert batchowner values (?,?)");
         $insR = $dbc->exec_statement($insQ, array($id, $owner));
     }
     // add items to batch
     for ($i = 0; $i < count($this->upcs); $i++) {
         $upc = $this->upcs[$i];
         if (!isset($this->newprices[$i])) {
             continue;
             // should not happen
         }
         $price = $this->newprices[$i];
         $bl = new BatchListModel($dbc);
         $bl->upc(BarcodeLib::padUPC($upc));
         $bl->batchID($id);
         $bl->salePrice($price);
         $bl->active(0);
         $bl->pricemethod(0);
         $bl->quantity(0);
         $bl->save();
     }
     // did not select "none" for tags
     // so create some shelftags
     if ($this->tags != -1) {
         $lookup = $dbc->prepare('SELECT p.description, v.brand, v.sku, v.size, v.units, n.vendorName
                             FROM products AS p LEFT JOIN vendorItems AS v ON p.upc=v.upc
                             LEFT JOIN vendors AS n ON v.vendorID=n.vendorID
                             WHERE p.upc=? ORDER BY v.vendorID');
         $tag = new ShelfTagModel($dbc);
         for ($i = 0; $i < count($this->upcs); $i++) {
             $upc = $this->upcs[$i];
             if (!isset($this->newprices[$i])) {
                 continue;
                 // should not happen
             }
             $price = $this->newprices[$i];
             $info = array('description' => '', 'brand' => '', 'sku' => '', 'size' => '', 'units' => 1, 'vendorName' => '');
             $lookupR = $dbc->execute($lookup, array($upc));
             if ($dbc->num_rows($lookupR) > 0) {
                 $info = $dbc->fetch_row($lookupR);
             }
             $ppo = $info['size'] !== '' ? \COREPOS\Fannie\API\lib\PriceLib::pricePerUnit($price, $info['size']) : '';
             $tag->id($this->tags);
             $tag->upc($upc);
             $tag->description($info['description']);
             $tag->normal_price($price);
             $tag->brand($info['brand']);
             $tag->sku($info['sku']);
             $tag->size($info['size']);
             $tag->units($info['units']);
             $tag->vendor($info['vendorName']);
             $tag->pricePerUnit($ppo);
             $tag->save();
         }
     }
     echo $FANNIE_URL . 'newbatch/BatchManagementTool.php?startAt=' . $id;
     return false;
 }
Esempio n. 2
0
 /**
   Standardization method to ensure shelf tag
   fields are calculated consistently for a given 
   item.
   @param $price [optional, default false] use a specified price
     rather than the product's current price
   @return [keyed array] of tag data with the following keys:
     - upc
     - description
     - brand
     - normal_price
     - sku
     - size
     - units
     - vendor
     - pricePerUnit
 */
 public function getTagData($price = false)
 {
     /**
       If a custom data source has been specified, let
       that handle the calculations
     */
     if (FannieConfig::config('TAG_DATA_SOURCE') !== '' && class_exists(FannieConfig::config('TAG_DATA_SOURCE'))) {
         $source = FannieConfig::config('TAG_DATA_SOURCE');
         $obj = new $source();
         return $obj->getTagData($this->connection, $this->upc(), $price);
     }
     $query = '
         SELECT p.upc,
             p.description,
             p.normal_price,
             COALESCE(p.brand, x.manufacturer) AS brand,
             COALESCE(v.vendorName, x.distributor) AS vendor,
             p.size AS p_size,
             p.unitofmeasure,
             i.sku,
             i.units,  
             i.size AS vi_size
         FROM products AS p
             LEFT JOIN prodExtra AS x ON p.upc=x.upc
             LEFT JOIN vendors AS v ON p.default_vendor_id=v.vendorID
             LEFT JOIN vendorItems AS i ON p.upc=i.upc AND v.vendorID=i.vendorID
         WHERE p.upc=?';
     $prep = $this->connection->prepare($query);
     $res = $this->connection->execute($prep, array($this->upc()));
     $ret = array('upc' => $this->upc(), 'description' => $this->description(), 'brand' => $this->brand(), 'normal_price' => $this->normal_price(), 'sku' => '', 'size' => '', 'units' => '', 'vendor' => '', 'pricePerUnit' => '');
     if (!$res || $this->connection->numRows($res) == 0) {
         return $ret;
     }
     $row = $this->connection->fetchRow($res);
     $ret['description'] = $row['description'];
     $ret['brand'] = $row['brand'];
     $ret['vendor'] = $row['vendor'];
     $ret['sku'] = $row['sku'];
     $ret['units'] = $row['units'];
     if ($price !== false) {
         $ret['normal_price'] = $price;
     } else {
         $ret['normal_price'] = $row['normal_price'];
     }
     if (is_numeric($row['p_size']) && !empty($row['p_size']) && !empty($row['unitofmeasure'])) {
         $ret['size'] = $row['p_size'] . ' ' . $row['unitofmeasure'];
     } elseif (!empty($row['p_size'])) {
         $ret['size'] = $row['p_size'];
     } elseif (!empty($row['vi_size'])) {
         $ret['size'] = $row['vi_size'];
     }
     $ret['pricePerUnit'] = \COREPOS\Fannie\API\lib\PriceLib::pricePerUnit($ret['normal_price'], $ret['size']);
     return $ret;
 }
Esempio n. 3
0
 public function loadItems()
 {
     if ($this->source == 'provided') {
         return $this->items;
     }
     $dbc = $this->getDB();
     if ($this->source == 'shelftags') {
         $sql = $this->listFromShelftags();
     } elseif ($this->source == 'batchbarcodes') {
         $sql = $this->listFromBatchBarcodes();
     } else {
         if ($this->source == 'batch') {
             $sql = $this->listFromBatches($dbc);
         } else {
             $sql = $this->listFromCurrentRetail($dbc);
             if ($this->source_id == 1) {
                 // upcoming retail
                 $sql = $this->listFromUpcomingRetail($dbc);
             } elseif ($this->source_id == 2) {
                 // current sale
                 $sql = $this->listFromCurrentSale($dbc);
             } elseif ($this->source_id == 3) {
                 // current sale
                 $sql = $this->listFromUpcomingSale($dbc);
             }
             $u_def = $dbc->tableDefinition('productUser');
             if (isset($u_def['signCount'])) {
                 $sql['query'] = str_replace('p.upc,', 'p.upc, u.signCount,', $sql['query']);
             } else {
                 $sql['query'] = str_replace('p.upc,', 'p.upc, 1 AS signCount,', $sql['query']);
             }
         }
     }
     $data = array();
     $prep = $dbc->prepare($sql['query']);
     $result = $dbc->execute($prep, $sql['args']);
     $mapP = $dbc->prepare('SELECT o.name, o.shortName
                        FROM ProductOriginsMap AS m
                         INNER JOIN origins AS o ON m.originID=o.originID
                        WHERE
                         m.upc = ?
                         AND o.name <> ?
                         AND o.shortName <> ?');
     while ($row = $dbc->fetch_row($result)) {
         if (substr($row['upc'], 0, 2) == 'LC') {
             $row = $this->unrollLikeCode($dbc, substr($row['upc'], 2), $row);
         }
         if (in_array($row['upc'], $this->excludes)) {
             continue;
         }
         if ($row['pricePerUnit'] == '') {
             $row['pricePerUnit'] = \COREPOS\Fannie\API\lib\PriceLib::pricePerUnit($row['normal_price'], $row['size']);
         }
         if (!isset($row['signMultiplier'])) {
             $row['signMultiplier'] = 1;
         }
         if ($row['originName'] != '') {
             // check for additional origins
             $mapR = $dbc->execute($mapP, array($row['upc'], $row['originName'], $row['originShortName']));
             while ($mapW = $dbc->fetch_row($mapR)) {
                 $row['originName'] .= _(' or ') . $mapW['name'];
                 $row['originShortName'] .= _(' or ') . $mapW['shortName'];
             }
         }
         if (isset($this->overrides[$row['upc']])) {
             foreach ($this->overrides[$row['upc']] as $key => $val) {
                 if ($key == 'originName' && $val != $row['originName']) {
                     $row['originShortName'] = $val;
                 }
                 $row[$key] = $val;
             }
         }
         if (!isset($row['signCount']) || $row['signCount'] < 0) {
             $row['signCount'] = 1;
         }
         for ($i = 0; $i < $row['signCount']; $i++) {
             $data[] = $row;
         }
     }
     return $data;
 }