function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $upc_index = $this->get_column_index('upc');
     $desc_index = $this->get_column_index('desc');
     $price_index = $this->get_column_index('price');
     $type_index = $this->get_column_index('type');
     $tare_index = $this->get_column_index('tare');
     $shelf_index = $this->get_column_index('shelf');
     $net_index = $this->get_column_index('net');
     $text_index = $this->get_column_index('text');
     $model = new ScaleItemsModel($dbc);
     $ret = true;
     $this->stats = array('done' => 0, 'error' => array());
     foreach ($linedata as $line) {
         // get info from file and member-type default settings
         // if applicable
         $upc = $line[$upc_index];
         // upc cleanup
         $upc = str_replace(" ", "", $upc);
         $upc = str_replace("-", "", $upc);
         if (!is_numeric($upc)) {
             continue;
         }
         // skip header(s) or blank rows
         $upc = BarcodeLib::padUPC($upc);
         $model->reset();
         $model->plu($upc);
         $model->load();
         if ($type_index !== false && isset($line[$type_index])) {
             if (strtoupper($line[$type_index]) == 'FIXED' || strtoupper($line[$type_index]) == 'EA') {
                 $model->weight(1);
                 $model->bycount(1);
             } else {
                 if (strtoupper($line[$type_index]) == 'RANDOM' || strtoupper($line[$type_index]) == 'RAND') {
                     $model->weight(0);
                     $model->bycount(0);
                 }
             }
         }
         if ($desc_index !== false && isset($line[$desc_index]) && !empty($line[$desc_index])) {
             $desc = $line[$desc_index];
             $desc = str_replace("'", "", $desc);
             $desc = str_replace("\"", "", $desc);
             $model->itemdesc($desc);
         }
         if ($price_index !== false && isset($line[$price_index])) {
             $model->price($line[$price_index]);
         }
         if ($tare_index !== false && isset($line[$tare_index])) {
             $model->tare($line[$tare_index]);
         }
         if ($shelf_index !== false && isset($line[$shelf_index])) {
             $model->shelflife($line[$shelf_index]);
         }
         if ($net_index !== false && isset($line[$net_index])) {
             $model->netWeight($line[$net_index]);
         }
         if ($text_index !== false && isset($line[$text_index]) && !empty($line[$text_index])) {
             $text = $line[$text_index];
             $text = str_replace("'", "", $text);
             $text = str_replace("\"", "", $text);
             $model->text($line[$text_index]);
         }
         $try = $model->save();
         if ($try === false) {
             $ret = false;
             $this->stats['error'][] = 'There was an error importing UPC ' . $upc;
         } else {
             $this->stats['done']++;
         }
     }
     return $ret;
 }
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $barcode_index = $this->get_column_index('barcode');
     $desc_index = $this->get_column_index('desc');
     $price_index = $this->get_column_index('price');
     $type_index = $this->get_column_index('type');
     $graphics_index = $this->get_column_index('graphics');
     $label_index = $this->get_column_index('label');
     $tare_index = $this->get_column_index('tare');
     $shelf_index = $this->get_column_index('shelf');
     $net_index = $this->get_column_index('net');
     $model = new ScaleItemsModel($dbc);
     $ret = true;
     $this->stats = array('done' => 0, 'error' => array());
     foreach ($linedata as $line) {
         // get info from file and member-type default settings
         // if applicable
         if (!isset($line[$barcode_index])) {
             continue;
         }
         $barcode_segment = $line[$barcode_index];
         if (!is_numeric($barcode_segment)) {
             continue;
         }
         $upc = '002' . str_pad($barcode_segment, 5, '0', STR_PAD_LEFT) . '00000';
         $model->reset();
         $model->plu($upc);
         $model->load();
         $type = $line[$type_index];
         if ($type == 'Random Weight') {
             $model->weight(0);
             $model->bycount(0);
         } elseif ($type == 'Fixed Weight') {
             $model->weight(1);
             $model->bycount(1);
         } else {
             // bad record; no weight given
             continue;
         }
         if ($desc_index !== false && isset($line[$desc_index]) && !empty($line[$desc_index])) {
             $desc = $line[$desc_index];
             $desc = str_replace("'", "", $desc);
             $desc = str_replace("\"", "", $desc);
             $model->itemdesc($desc);
         }
         if ($price_index !== false && isset($line[$price_index])) {
             $model->price($line[$price_index]);
         }
         if ($tare_index !== false && isset($line[$tare_index])) {
             $model->tare($line[$tare_index]);
         }
         if ($shelf_index !== false && isset($line[$shelf_index])) {
             $model->shelflife($line[$shelf_index]);
         }
         if ($net_index !== false && isset($line[$net_index])) {
             $model->netWeight($line[$net_index]);
         }
         if ($label_index !== false && isset($line[$label_index])) {
             $model->label($line[$label_index]);
         }
         if ($graphics_index !== false && isset($line[$graphics_index])) {
             $model->graphics($line[$graphics_index]);
         }
         $try = $model->save();
         if ($try === false) {
             $ret = false;
             $this->stats['error'][] = 'There was an error importing UPC ' . $upc;
         } else {
             $this->stats['done']++;
         }
     }
     return $ret;
 }
Exemple #3
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);
         }
     }
 }
Exemple #4
0
 if ($s_graphics == "on") {
     $graphics = 121;
     $s_label = 53;
 }
 // for right now, check if the item is in the scaleItems
 // table and add it if it isn't
 // otherwise, update the row
 $scaleQuery = $sql->prepare("select plu from scaleItems where plu=?");
 $scaleRes = $sql->execute($scaleQuery, array($s_plu));
 $nr = $sql->num_rows($scaleRes);
 /* apostrophe filter */
 $s_itemdesc = str_replace("'", "", $s_itemdesc);
 $s_text = str_replace("'", "", $s_text);
 $s_itemdesc = str_replace("\"", "", $s_itemdesc);
 $s_text = str_replace("\"", "", $s_text);
 $scaleItem = new ScaleItemsModel($dbc);
 $scaleItem->plu($s_plu);
 $scaleItem->price($s_price);
 $scaleItem->itemdesc($s_itemdesc);
 $scaleItem->weight($wt);
 $scaleItem->bycount($bc);
 $scaleItem->tare($tare);
 $scaleItem->shelflife($shelflife);
 $scaleItem->text($s_text);
 $scaleItem->label($s_label);
 $scaleItem->graphics($graphics);
 $scaleItem->netWeight($netWeight);
 $scaleItem->save();
 $datetime = date("m/d/Y h:i:s a");
 $fp = fopen('hobartcsv/query.log', 'a');
 fwrite($fp, "{$datetime}\n{$scaleQuery}\n\n");
Exemple #5
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;
     }
 }
Exemple #6
0
 function post_u_view()
 {
     global $FANNIE_OP_DB, $FANNIE_URL;
     $this->add_script($FANNIE_URL . '/src/javascript/jquery.js');
     $this->add_css_file($FANNIE_URL . '/src/style.css');
     $ret = '';
     $ret .= '<form action="SyncFromSearch.php" method="post">';
     $scales = new ServiceScalesModel(FannieDB::get($FANNIE_OP_DB));
     $ret .= '<div class="panel panel-default">
         <div class="panel-heading">Scales</div>
         <div class="panel-body">';
     foreach ($scales->find('description') as $scale) {
         $ret .= sprintf('<input type="checkbox" class="scaleID" name="scaleID[]" 
                             id="scaleID%d" value="%d" />
                          <label for="scaleID%d">%s</label><br />', $scale->serviceScaleID(), $scale->serviceScaleID(), $scale->serviceScaleID(), $scale->description());
     }
     $ret .= '</div></div>';
     $ret .= '<p><button type="submit" name="sendall" value="1"
                 class="btn btn-default">Sync All Items</button></p>';
     $ret .= '<div id="alert-area"></div>';
     $ret .= '<table class="table">';
     $ret .= '<tr>
             <th>UPC</th>
             <th>Description</th>
             <th>Price</th>
             <th>Last Changed</th>
             <th>Send Now</th>
             </tr>';
     $model = new ScaleItemsModel(FannieDB::get($FANNIE_OP_DB));
     foreach ($this->upcs as $upc) {
         $model->plu($upc);
         if (!$model->load()) {
             continue;
         }
         $ret .= sprintf('<tr id="row%s">
                         <td>%s</td>
                         <td>%s</td>
                         <td>%.2f</td>
                         <td>%s</td>
                         <td><button type="button" class="btn btn-default"
                             onclick="sendOne(\'%s\'); return false;">Sync Item</button></td>
                         <input type="hidden" name="upcs[]" value="%s" />
                         </tr>', $model->plu(), $model->plu(), $model->mergeDescription(), $model->price(), $model->modified(), $model->plu(), $model->plu());
     }
     $ret .= '</table>';
     $ret .= '</form>';
     return $ret;
 }
Exemple #7
0
 /**
   Import Hobart Data into scaleItems table
   This one is for "item" data
   @param $filename [string] scale-exported data CSV
   @return [int] number of items imported
 */
 public static function readItemsFromFile($filename)
 {
     $dbc = \FannieDB::get(\FannieConfig::factory()->get('OP_DB'));
     $product = new \ProductsModel($dbc);
     $scaleItem = new \ScaleItemsModel($dbc);
     $fp = fopen($filename, 'r');
     // detect column indexes via header line
     $column_index = array('PLU Number' => -1, 'Price' => -1, 'Item Description' => -1, 'Item Type' => -1, 'By Count' => -1, 'Tare 01' => -1, 'Shelf Life' => -1, 'Net Weight' => -1, 'Label Type 01' => -1, 'Graphics Number' => -1);
     $headers = fgetcsv($fp);
     for ($i = 0; $i < count($headers); $i++) {
         $header = $headers[$i];
         if (isset($column_index[$header])) {
             $column_index[$header] = $i;
         }
     }
     $item_count = 0;
     while (!feof($fp)) {
         $line = fgetcsv($fp);
         if (!isset($line[$column_index['PLU Number']])) {
             // can't import item w/o PLU
             continue;
         }
         $plu = $line[$column_index['PLU Number']];
         $upc = self::scalePluToUpc($plu);
         $product->reset();
         $product->upc($upc);
         if (!$product->load()) {
             // no entry in products table
             // should one be created?
             continue;
         }
         $scaleItem->reset();
         $scaleItem->plu($upc);
         if ($column_index['Price'] != -1) {
             $scaleItem->price($line[$column_index['Price']]);
         }
         if ($column_index['Item Description'] != -1) {
             $scaleItem->itemdesc($line[$column_index['Item Description']]);
         }
         if ($column_index['Item Type'] != -1) {
             $scale_type = $line[$column_index['Item Description']];
             $scaleItem->weight($scale_type == 'Fixed Weight' ? 1 : 0);
         }
         if ($column_index['By Count'] != -1) {
             $scaleItem->bycount($line[$column_index['By Count']]);
         }
         if ($column_index['Tare 01'] != -1) {
             $scaleItem->tare($line[$column_index['Tare 01']]);
         }
         if ($column_index['Shelf Life'] != -1) {
             $scaleItem->shelflife($line[$column_index['Shelf Life']]);
         }
         if ($column_index['Net Weight'] != -1) {
             $scaleItem->netWeight($line[$column_index['Net Weight']]);
         }
         if ($column_index['Label Type 01'] != -1) {
             $scaleItem->weight($line[$column_index['Label Type 01']]);
         }
         if ($column_index['Graphics Number'] != -1) {
             $scaleItem->graphics($line[$column_index['Graphics Number']]);
         }
         $scaleItem->save();
         $item_count++;
     }
     fclose($fp);
     return $item_count;
 }