Example #1
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;
 }