Exemple #1
0
 function post_sendall_handler()
 {
     global $FANNIE_OP_DB;
     $model = new ScaleItemsModel(FannieDB::get($FANNIE_OP_DB));
     $upcs = FormLib::get('upcs', array());
     $all_items = array();
     $scales = $this->scalesFromIDs(FormLib::get('scaleID', array()));
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $chkMap = $dbc->prepare('
         SELECT upc
         FROM ServiceScaleItemMap
         WHERE serviceScaleID=?
             AND upc=?
     ');
     $addMap = $dbc->prepare('
         INSERT INTO ServiceScaleItemMap
             (serviceScaleID, upc)
         VALUES
             (?, ?)
     ');
     ob_start();
     echo '<ul>';
     // go through scales one at a time
     // check whether item is present on that
     // scale and do write or change as appropriate
     foreach ($scales as $scale) {
         foreach ($upcs as $upc) {
             $model->reset();
             $model->plu(BarcodeLib::padUPC($upc));
             if ($model->load()) {
                 $item_info = $this->getItemInfo($model);
                 $chk = $dbc->execute($chkMap, array($scale['id'], $upc));
                 if ($dbc->num_rows($chk) == 0) {
                     $dbc->execute($addMap, array($scale['id'], $upc));
                     $item_info['RecordType'] = 'WriteOneItem';
                 }
                 $all_items[] = $item_info;
                 echo '<li class="alert-success">Sending <strong>' . $model->plu() . '</strong></li>';
                 // batch out changes @ 10 items / file
                 if (count($all_items) >= 10) {
                     \COREPOS\Fannie\API\item\HobartDgwLib::writeItemsToScales($all_items, array($scale));
                     $all_items = array();
                 }
             } else {
                 echo '<li class="alert-danger">Error on <strong>' . $model->plu() . '</strong></li>';
             }
         }
         // end loop on items
         echo '</ul>';
         if (count($all_items) > 0) {
             \COREPOS\Fannie\API\item\HobartDgwLib::writeItemsToScales($all_items, array($scale));
         }
     }
     // end loop on scales
     $this->sent_status = ob_get_clean();
     return true;
 }
 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;
 }
 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;
 }
Exemple #4
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;
 }