Example #1
0
 public function report_description_content()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $prod = new ProductsModel($dbc);
     $prod->upc(BarcodeLib::padUPC($this->form->upc));
     $prod->load();
     return array('Weekly Sales For ' . $prod->upc() . ' ' . $prod->description());
 }
Example #2
0
 public function mergeDescription()
 {
     if ($this->itemdesc() != '') {
         return $this->itemdesc();
     } else {
         $p = new ProductsModel($this->connection);
         $p->upc($this->plu());
         if ($p->load()) {
             return $p->description();
         }
     }
     return $this->itemdesc();
 }
Example #3
0
 public function report_description_content()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $prod = new ProductsModel($dbc);
     $prod->upc(BarcodeLib::padUPC(FormLib::get('upc')));
     $prod->load();
     $ret = array('Recent Sales For ' . $prod->upc() . ' ' . $prod->description() . '<br />');
     if ($this->report_format == 'html') {
         $ret[] = sprintf('<a href="../ItemLastQuarter/ItemLastQuarterReport.php?upc=%s">Weekly Sales Details</a> | ', $prod->upc());
         $ret[] = sprintf('<a href="../ItemOrderHistory/ItemOrderHistoryReport.php?upc=%s">Recent Order History</a>', $prod->upc());
     }
     return $ret;
 }
Example #4
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 #5
0
 public function report_description_content()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $prod = new ProductsModel($dbc);
     $prod->upc(BarcodeLib::padUPC($this->form->upc));
     $prod->load();
     $ret = array('Order History For ' . $prod->upc() . ' ' . $prod->description());
     if (FormLib::get('all')) {
         $ret[] = 'All [known] orders';
         if ($this->report_format = 'html') {
             $ret[] = sprintf('<a href="ItemOrderHistoryReport.php?upc=%s">Show Recent</a>', $prod->upc());
         }
     } else {
         $ret[] = 'Since ' . date('F d, Y', strtotime('92 days ago'));
         if ($this->report_format = 'html') {
             $ret[] = sprintf('<a href="ItemOrderHistoryReport.php?upc=%s&all=1">Show All</a>', $prod->upc());
         }
     }
     return $ret;
 }
Example #6
0
 public function logUpdate($type = 'UNKNOWN', $user = false)
 {
     if (!$user) {
         $user = FannieAuth::getUID(FannieAuth::checkLogin());
     }
     $product = new ProductsModel($this->connection);
     $product->upc($this->upc());
     $exists = $product->load();
     if (!$exists) {
         return false;
     }
     $this->storeID($product->store_id());
     $this->updateType($type);
     $this->description($product->description());
     $this->price($product->normal_price());
     $this->salePrice($product->special_price());
     $this->cost($product->cost());
     $this->dept($product->department());
     $this->tax($product->tax());
     $this->fs($product->foodstamp());
     $this->scale($product->scale());
     $this->modified($product->modified());
     $this->forceQty($product->qttyEnforced());
     $this->noDisc($product->discount());
     $this->inUse($product->inUse());
     $this->user($user);
     $likecode = 0;
     if ($this->connection->table_exists('upcLike')) {
         $upcQ = $this->connection->prepare('SELECT likeCode FROM upcLike WHERE upc=?');
         $upcR = $this->connection->execute($upcQ, array($this->upc()));
         if ($this->connection->num_rows($upcR) > 0) {
             $upcW = $this->connection->fetch_row($upcR);
             $this->likeCode($upcW['likeCode']);
         }
     }
     $this->save();
     return true;
 }
Example #7
0
 public function showEditForm($upc, $display_mode = 1, $expand_mode = 1)
 {
     $upc = BarcodeLib::padUPC($upc);
     $dbc = $this->db();
     $prod = new ProductsModel($dbc);
     $prod->upc($upc);
     if (FannieConfig::config('STORE_MODE') == 'HQ') {
         $prod->store_id(FannieConfig::config('STORE_ID'));
     }
     $prod->load();
     $ret = '<div id="FreshDealsFieldset" class="panel panel-default">';
     $ret .= "<div class=\"panel-heading\">\n                <a href=\"\" onclick=\"\$('#FreshDealsDiv').toggle();return false;\">\n                Fresh Deals</a>\n                </div>";
     $ret .= '<div id="FreshDealsDiv" class="panel-body">';
     $ret .= sprintf('<table class="table table-bordered"><tr>
         <td>%s</td>
         <td>%s</td>
         <td>%s</td>
         <td>$%.2f</td>
         <td>$%.2f</td>
         </tr></table>', $prod->brand(), $prod->description(), $prod->upc(), $prod->cost(), $prod->normal_price());
     $ret .= '</div></div>';
     return $ret;
 }
Example #8
0
 public function preprocess()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB, $FANNIE_URL, $FANNIE_TRANS_DB;
     //$this->add_script($FANNIE_URL.'src/javascript/jquery.js');
     //$this->add_script($FANNIE_URL.'src/javascript/jquery-ui.js');
     if (FormLib::get('upc_in') !== '') {
         $upc = BarcodeLib::padUPC(FormLib::get('upc_in'));
         $this->current_item_data['upc'] = $upc;
         $dbc = FannieDB::get($FANNIE_OP_DB);
         $model = new ProductsModel($dbc);
         $model->upc($upc);
         $vendorID = 0;
         if ($model->load()) {
             $this->current_item_data['desc'] = $model->brand() . ' ' . $model->description();
             $this->current_item_data['par'] = $model->auto_par();
             $vendorID = $model->default_vendor_id();
         }
         $model = new VendorsModel($dbc);
         $model->vendorID($vendorID);
         if ($model->load()) {
             $this->current_item_data['vendor'] = $model->vendorName();
             $schedule = new VendorDeliveriesModel($dbc);
             $schedule->vendorID($vendorID);
             if ($schedule->load() && $schedule->regular() == 1) {
                 $this->current_item_data['nextDelivery'] = date('D, M jS', strtotime($schedule->nextDelivery())) . ' & ' . date('D, M jS', strtotime($schedule->nextNextDelivery()));
                 $nd = new DateTime(date('Y-m-d', strtotime($schedule->nextDelivery())));
                 $nnd = new DateTime(date('Y-m-d', strtotime($schedule->nextNextDelivery())));
                 $this->current_item_data['deliverySpan'] = $nnd->diff($nd)->format('%a');
             }
             $items = new VendorItemsModel($dbc);
             $items->vendorID($vendorID);
             $items->upc($upc);
             $this->current_item_data['cases'] = array();
             foreach ($items->find('units') as $item) {
                 $this->current_item_data['cases'][] = $item->units();
             }
         }
         $saleNow = 'SELECT b.batchName, b.startDate, b.endDate
                     FROM batchList AS l
                         INNER JOIN batches AS b ON b.batchID=l.batchID
                     WHERE l.upc=?
                         AND b.discounttype <> 0
                         AND b.startDate <= ' . $dbc->now() . '
                         AND b.endDate >= ' . $dbc->now();
         $saleNow = $dbc->prepare($saleNow);
         $saleNow = $dbc->execute($saleNow, array($upc));
         if ($dbc->num_rows($saleNow) > 0) {
             $row = $dbc->fetch_row($saleNow);
             $this->current_item_data['onSale'] = $row['batchName'] . ' thru ' . date('D, M jS', strtotime($row['endDate']));
         }
         $saleNext = 'SELECT b.batchName, b.startDate, b.endDate
                     FROM batchList AS l
                         INNER JOIN batches AS b ON b.batchID=l.batchID
                     WHERE l.upc=?
                         AND b.discounttype <> 0
                         AND b.startDate >= ' . $dbc->now() . '
                         AND b.endDate >= ' . $dbc->now();
         $saleNext = $dbc->prepare($saleNext);
         $saleNext = $dbc->execute($saleNext, array($upc));
         if ($dbc->num_rows($saleNext) > 0) {
             $row = $dbc->fetch_row($saleNext);
             $this->current_item_data['soonSale'] = $row['batchName'] . ' on ' . date('D, M jS', strtotime($row['startDate']));
         }
         $ordersQ = 'SELECT v.vendorName,
                         o.placedDate,
                         i.quantity,
                         i.caseSize
                     FROM PurchaseOrderItems AS i
                         INNER JOIN PurchaseOrder AS o ON i.orderID=o.orderID
                         INNER JOIN vendors AS v ON o.vendorID=v.vendorID
                     WHERE i.internalUPC = ?
                     ORDER BY o.placedDate DESC';
         $ordersQ = $dbc->add_select_limit($ordersQ, 10);
         $ordersP = $dbc->prepare($ordersQ);
         $ordersR = $dbc->execute($ordersP, array($upc));
         $orders = array();
         while ($w = $dbc->fetch_row($ordersR)) {
             $orders[] = $w;
         }
         $this->current_item_data['orders'] = $orders;
         $salesQ = 'SELECT ' . DTrans::sumQuantity('d') . ' AS qty,
                     MIN(tdate) as day
                    FROM ' . $FANNIE_TRANS_DB . $dbc->sep() . 'dlog_15 AS d
                    WHERE upc = ?
                    GROUP BY YEAR(tdate), MONTH(tdate), DAY(tdate)
                    ORDER BY YEAR(tdate) DESC, MONTH(tdate) DESC, DAY(tdate) DESC';
         $salesP = $dbc->prepare($salesQ);
         $salesR = $dbc->execute($salesP, array($upc));
         $sales = array();
         while ($w = $dbc->fetch_row($salesR)) {
             $sales[] = $w;
         }
         $this->current_item_data['sales'] = $sales;
     }
     $this->linea_ios_mode = $this->linea_support_available();
     if ($this->linea_ios_mode) {
         $this->add_script($FANNIE_URL . 'src/javascript/linea/cordova-2.2.0.js');
         $this->add_script($FANNIE_URL . 'src/javascript/linea/ScannerLib-Linea-2.0.0.js');
     }
     $this->add_script($FANNIE_URL . 'src/javascript/tablesorter/jquery.tablesorter.js');
     $this->add_css_file($FANNIE_URL . 'src/javascript/tablesorter/themes/blue/style.css');
     //$this->add_css_file($FANNIE_URL.'src/javascript/jquery-ui.css');
     return true;
 }
Example #9
0
    $distributor = '';
}
$manufacturer = str_replace("'", "", $manufacturer);
$distributor = str_replace("'", "", $distributor);
// lookup vendorID by name
$vendorID = 0;
$vendor = new VendorsModel($sql);
$vendor->vendorName($distributor);
foreach ($vendor->find('vendorID') as $obj) {
    $vendorID = $obj->vendorID();
    break;
}
$stamp = date("Y-m-d H:i:s");
$model = new ProductsModel($sql);
$model->upc($upc);
$model->description($descript);
$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);
Example #10
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 #11
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 #12
0
 /**
   Helper: create a vendorItems record for an existing
   product if one does not exist
 */
 public function createIfMissing($upc, $vendorID)
 {
     // look for entry directly by UPC or via SKU mapping
     $findP = $this->connection->prepare('
         SELECT v.upc
         FROM vendorItems AS v
             LEFT JOIN vendorSKUtoPLU AS m ON v.vendorID=m.vendorID AND v.sku=m.sku
         WHERE v.vendorID=?
             AND (v.upc=? OR m.upc=?)');
     $findR = $this->connection->execute($findP, array($vendorID, $upc, $upc));
     if ($this->connection->num_rows($findR) == 0) {
         // create item from product
         $prod = new ProductsModel($this->connection);
         $prod->upc($upc);
         $prod->load();
         $vend = new VendorItemsModel($this->connection);
         $vend->vendorID($vendorID);
         $vend->upc($upc);
         $vend->sku($upc);
         $vend->brand($prod->brand());
         $vend->description($prod->description());
         $vend->cost($prod->cost());
         $vend->saleCost(0);
         $vend->vendorDept(0);
         $vend->units(1);
         $vend->size($prod->size() . $prod->unitofmeasure());
         $vend->save();
     }
 }
Example #13
0
 public static function batchNotification($batchID, $upc, $type, $is_likecode = false)
 {
     $conf = \FannieConfig::factory();
     $dbc = \FannieDB::getReadOnly($conf->get('OP_DB'));
     $likecode = '';
     $desc = '';
     $dept = 0;
     if ($is_likecode) {
         if (substr($upc, 0, 2) == 'LC') {
             $likecode = substr($upc, 2);
         } else {
             $likecode = $upc;
         }
         // upc is a like code. find the description
         // and a valid upc (hence inner join)
         $infoQ = 'SELECT p.department,
                 l.likeCodeDesc 
               FROM upcLike AS u
                 ' . DTrans::joinProducts('u', 'p', 'INNER') . '
                 LEFT JOIN likeCodes AS l ON u.likeCode=l.likeCode
               WHERE u.likeCode=?';
         $infoP = $dbc->prepare($infoQ);
         $infoR = $dbc->execute($infoP, array($likecode));
         if ($dbc->num_rows($infoR) == 0) {
             // invalid like code
             return false;
         }
         $infoW = $dbc->fetch_row($infoR);
         $desc = $infoW['likeCodeDesc'];
         $dept = $infoW['department'];
     } else {
         $product = new \ProductsModel($dbc);
         $product->upc($upc);
         $product->load();
         $desc = $product->description();
         $dept = $product->department();
     }
     $to_addr = self::getAddresses($dept);
     if ($to_addr === false) {
         // no one set to receive notices
         return false;
     }
     $batch = new \BatchesModel($dbc);
     $batch->batchID($batchID);
     $batch->load();
     $batchList = new \BatchListModel($dbc);
     $batchList->upc($upc);
     $batchList->batchID($batchID);
     $batchList->load();
     $subject = "Batch Update notification: " . $batch->batchName();
     $message = "Batch " . $batch->batchName() . " has been changed\n";
     if ($is_likecode) {
         $message .= 'Like code ' . $likecode . '(' . $desc . ') ';
     } else {
         $message .= 'Item ' . $upc . '(' . $desc . ') ';
     }
     switch ($type) {
         case self::BATCH_ADD:
             $message .= "has been added to the batch\n";
             $message .= 'Sale Price: $' . $batchList->salePrice() . "\n";
             break;
         case self::BATCH_EDIT:
             $message .= "has been re-priced\n";
             $message .= 'Sale Price: $' . $batchList->salePrice() . "\n";
             break;
         case self::BATCH_DELETE:
             $message .= "has been deleted from the batch\n";
             break;
         default:
             $message .= "may have experienced unknown changes\n";
             return false;
             // remove after testing; don't send lots of these in error
             break;
     }
     $message .= "\n";
     $message .= "View this batch:\n";
     $url = $conf->get('URL');
     $server_name = filter_input(INPUT_SERVER, 'SERVER_NAME');
     $message .= "http://{$server_name}{$url}batches/newbatch/EditBatchPage.php?id={$batchID}\n";
     $message .= "\n";
     $message .= "View this item:\n";
     $message .= "http://{$server_name}/{$url}item/ItemEditorPage.php?searchupc={$upc}\n";
     $message .= "\n";
     $username = \FannieAuth::checkLogin();
     if (!$username) {
         $username = '******';
     }
     $message .= "This change was made by user {$username}\n";
     $from = "From: automail\r\n";
     mail($to_addr, $subject, $message, $from);
     return true;
 }
Example #14
0
 protected function post_id_addUPC_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $id = $this->id;
     $upc = trim($this->addUPC);
     $upc = BarcodeLib::padUPC($upc);
     $json = array('error' => 0, 'msg' => '', 'content' => '', 'field' => '#addItemUPC');
     /**
       Nothing submitted; don't do anything
     */
     if ($this->addUPC === '') {
         echo json_encode($json);
         return false;
     }
     $overlap = $this->checkOverlap($id, $upc);
     if ($overlap !== false) {
         $error = 'Item already in concurrent batch: ' . '<a style="color:blue;" href="EditBatchPage.php?id=' . $overlap['batchID'] . '">' . $overlap['batchName'] . '</a> (' . date('Y-m-d', strtotime($overlap['startDate'])) . ' - ' . date('Y-m-d', strtotime($overlap['endDate'])) . ')' . '<br />' . 'Either remove item from conflicting batch or change
                dates so the batches do not overlap.';
         $json['error'] = 1;
         $json['msg'] = $error;
     } else {
         $product = new ProductsModel($dbc);
         $product->upc($upc);
         if (!$product->load()) {
             $json['error'] = 1;
             $json['msg'] = 'Item not found: ' . $upc;
         } else {
             $json['content'] = $this->addItemPriceInput($upc, false, $product->description(), $product->normal_price());
             $json['field'] = '#add-item-price';
         }
     }
     echo json_encode($json);
     return false;
 }
Example #15
0
 public function get_id_view()
 {
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $model = new ProductsModel($dbc);
     $model->upc(BarcodeLib::padUPC($this->id));
     if (!$model->load()) {
         return '<div class="alert alert-danger">Item ' . $this->id . ' does not exist</dv>';
     }
     $ret = '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
         <input type="hidden" name="id" value="' . $model->upc() . '" />
         <p>
             Create a copy of ' . $model->upc() . ' (' . $model->description() . ')
         </p>
         <div class="form-group">
             <label>New Item UPC</label>
             <input type="text" name="new-upc" class="form-control" id="new-upc" required />
         </div>
         <p>
             <button type="submit" class="btn btn-default">Clone Item</button>
         </p>
         </form>';
     $this->addOnloadCommand("enableLinea('#new-upc');\n");
     $this->addOnloadCommand("\$('#new-upc').focus();\n");
     return $ret;
 }
Example #16
0
 public function get_id_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $upc = BarcodeLib::padUPC($this->id);
     $product = new ProductsModel($dbc);
     $product->upc($upc);
     if (!$product->load()) {
         $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', 'Item not found');\n");
         $this->__route_stem = 'get';
     } else {
         $this->description = $product->description();
         $this->cost = $product->cost();
         $this->price = $product->normal_price();
         $this->department = $product->department();
         $this->upc = $upc;
     }
     return true;
 }
Example #17
0
 function summaryRows($upc)
 {
     $dbc = $this->db();
     $model = new ProductsModel($dbc);
     $model->upc($upc);
     if ($model->load()) {
         $row1 = '<th>UPC</th>
             <td><a href="ItemEditorPage.php?searchupc=' . $upc . '">' . $upc . '</td>
             <td>
                 <a class="iframe fancyboxLink" href="addShelfTag.php?upc=' . $upc . '" title="Create Shelf Tag">Shelf Tag</a>
             </td>';
         $row2 = '<th>Description</th><td>' . $model->description() . '</td>
                  <th>Price</th><td>$' . $model->normal_price() . '</td>';
         return array($row1, $row2);
     } else {
         return array('<td colspan="4">Error saving. <a href="ItemEditorPage.php?searchupc=' . $upc . '">Try Again</a>?</td>');
     }
 }
Example #18
0
 function SaveFormData($upc)
 {
     $upc = BarcodeLib::padUPC($upc);
     $ids = FormLib::get_form_value('v_id', array());
     $skus = FormLib::get_form_value('v_sku', array());
     $costs = FormLib::get_form_value('v_cost', array());
     $units = FormLib::get_form_value('v_units', array());
     $sizes = FormLib::get_form_value('v_size', array());
     $dbc = $this->db();
     $chkP = $dbc->prepare_statement('SELECT upc FROM vendorItems WHERE vendorID=? AND upc=?');
     $insP = $dbc->prepare_statement('INSERT INTO vendorItems (upc,vendorID,cost,units,sku,size)
                 VALUES (?,?,?,?,?,?)');
     $upP = $dbc->prepare_statement('UPDATE vendorItems SET cost=?,units=?,sku=?,size=? WHERE
                 upc=? AND vendorID=?');
     $initP = $dbc->prepare('
         UPDATE vendorItems
         SET brand=?,
             description=?,
             vendorDept=0
         WHERE upc=?
             AND vendorID=?');
     $prod = new ProductsModel($dbc);
     $prod->upc($upc);
     $prod->load();
     $ret = true;
     for ($i = 0; $i < count($ids); $i++) {
         if (!isset($skus[$i]) || !isset($costs[$i]) || !isset($units[$i])) {
             continue;
             // bad submit
         }
         // always create record for the default vendor
         // but only initialize an empty one if no
         // record exists.
         if ($ids[$i] == $prod->default_vendor_id()) {
             $defaultR = $dbc->execute($chkP, array($ids[$i], $prod->upc()));
             if ($dbc->numRows($defaultR) == 0) {
                 if (empty($skus[$i])) {
                     $skus[$i] = $prod->upc();
                 }
                 if (empty($costs[$i])) {
                     $costs[$i] = $prod->cost();
                 }
                 if (empty($units[$i])) {
                     $units[$i] = 1;
                 }
                 if (empty($sizes[$i])) {
                     $sizes[$i] = '';
                 }
             }
         }
         if (empty($skus[$i]) || empty($costs[$i])) {
             continue;
             // no submission. don't create a record
         }
         $chkR = $dbc->exec_statement($chkP, array($ids[$i], $upc));
         if ($dbc->num_rows($chkR) == 0) {
             $try = $dbc->exec_statement($insP, array($upc, $ids[$i], $costs[$i], $units[$i], $skus[$i], $sizes[$i]));
             if ($try === false) {
                 $ret = false;
             } else {
                 // initialize new record with product's brand
                 // and description so it isn't blank
                 $dbc->execute($initP, array($prod->brand(), $prod->description(), $upc, $ids[$i]));
             }
         } else {
             $try = $dbc->exec_statement($upP, array($costs[$i], $units[$i], $skus[$i], $sizes[$i], $upc, $ids[$i]));
             if ($try === false) {
                 $ret = false;
             }
         }
     }
     return $ret;
 }
Example #19
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;
 }