Example #1
0
 public function testItemFlags()
 {
     $config = FannieConfig::factory();
     $connection = FannieDB::get($config->OP_DB);
     /**
       Setup preconditions for the test
     */
     $upc = BarcodeLib::padUPC('16');
     $product = new ProductsModel($connection);
     $product->upc($upc);
     $product->store_id(0);
     $product->load();
     if ($product->numflag() != 0) {
         $product->numflag(0);
     }
     $product->save();
     $module = new ItemFlagsModule();
     $module->setConnection($connection);
     $module->setConfig($config);
     $form = new \COREPOS\common\mvc\ValueContainer();
     $module->setForm($form);
     $saved = $module->saveFormData($upc);
     $this->assertEquals(true, $saved, 'Handled empty input');
     $product->reset();
     $product->upc($upc);
     $product->load();
     $this->assertEquals(0, $product->numflag(), 'Wrong numflag value ' . $product->numflag());
     /**
       Simulate real form input
     */
     $form = new \COREPOS\common\mvc\ValueContainer();
     $form->flags = array(1, 3);
     // 0b101 == 5
     $module->setForm($form);
     $saved = $module->saveFormData($upc);
     $this->assertEquals(true, $saved, 'Saving item flags failed');
     $product->reset();
     $product->upc($upc);
     $product->load();
     $this->assertEquals(5, $product->numflag(), 'Wrong numflag value ' . $product->numflag());
     /* put record back to normal */
     $product->numflag(0);
     $product->save();
     $form = new \COREPOS\common\mvc\ValueContainer();
     $form->flags = 'not_an_array';
     $module->setForm($form);
     $saved = $module->saveFormData($upc);
     $this->assertEquals(false, $saved, 'Accepted invalid input');
 }
Example #2
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 #3
0
 public function showEditForm($upc, $display_mode = 1, $expand_mode = 1)
 {
     $upc = BarcodeLib::padUPC($upc);
     $ret = '<div id="3for1FieldSet" class="panel panel-default">';
     $ret .= "<div class=\"panel-heading\">\n                <a href=\"\" onclick=\"\$('#VolumeFieldsetContent').toggle();return false;\">\n               \"Three for a dollar\"\n                </a></div>";
     $css = $expand_mode == 1 ? '' : ' collapse';
     $ret .= '<div id="VolumeFieldsetContent" class="panel-body' . $css . '">';
     $dbc = $this->db();
     $model = new ProductsModel($dbc);
     $model->upc($upc);
     $model->load();
     $methods = array(0 => 'Disabled', 2 => 'Use this price for full sets', 1 => 'Always use this price');
     $ret .= "<table class=\"table table-bordered\"><tr>";
     $ret .= '<tr><th>Enabled</td>
         <th># Items' . \COREPOS\Fannie\API\lib\FannieHelp::ToolTip('# of items in a set') . '</th>
         <th>Price' . \COREPOS\Fannie\API\lib\FannieHelp::ToolTip('Price for the whole set') . '</th>
         <th>Mix/Match' . \COREPOS\Fannie\API\lib\FannieHelp::ToolTip('Items with the same Mix/Match all count') . '</th></tr>';
     $ret .= '<tr><td><select name="vp_method" class="form-control">';
     foreach ($methods as $value => $label) {
         $ret .= sprintf('<option value="%d"%s>%s</option>', $value, $value == $model->pricemethod() ? ' selected' : '', $label);
     }
     $ret .= '</select></td>';
     $ret .= '<td><input type="text" name="vp_qty" class="form-control" value="' . $model->quantity() . '" /></td>';
     $ret .= '<td>
         <div class="input-group">
         <span class="input-group-addon">$</span>
         <input type="text" name="vp_price" class="form-control" value="' . sprintf('%.2f', $model->groupprice()) . '" />
         </div>
         </td>';
     $ret .= '<td><input type="text" name="vp_mm" class="form-control" value="' . $model->mixmatchcode() . '" /></td>';
     $ret .= '</table></div></div>';
     return $ret;
 }
Example #4
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 #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();
     return array('Weekly Sales For ' . $prod->upc() . ' ' . $prod->description());
 }
Example #6
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 #7
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 #8
0
function MarginFS($upc, $cost, $deptID)
{
    global $FANNIE_OP_DB;
    $dbc = FannieDB::get($FANNIE_OP_DB);
    $price = 'None';
    $prod = new ProductsModel($dbc);
    $prod->upc($upc);
    if ($prod->load()) {
        $price = $prod->normal_price();
    }
    $dm = 'Unknown';
    $dept = new DepartmentsModel($dbc);
    $dept->dept_no($deptID);
    if ($dept->load()) {
        $dm = $dept->margin();
    }
    if ((empty($dm) || $dm == 'Unknown') && $dbc->tableExists('deptMargin')) {
        $prep = $dbc->prepare_statement("SELECT margin FROM deptMargin WHERE dept_ID=?");
        $dm = $dbc->exec_statement($prep, array($deptID));
        if ($dbc->num_rows($dm) > 0) {
            $row = $dbc->fetch_row($dm);
            $dm = $dm['margin'];
        }
    }
    $ret = "Desired margin on this department is ";
    if ($dm == "Unknown") {
        $ret .= $dm;
    } else {
        $ret .= sprintf("%.2f%%", $dm * 100);
    }
    $ret .= "<br />";
    $actual = 0;
    if ($price != 0) {
        $actual = ($price - $cost) / $price;
    }
    if ($actual > $dm && is_numeric($dm) || !is_numeric($dm)) {
        $ret .= sprintf("<span style=\"color:green;\">Current margin on this item is %.2f%%<br />", $actual * 100);
    } else {
        if (!is_numeric($price)) {
            $ret .= "<span style=\"color:green;\">No price has been saved for this item<br />";
        } else {
            $ret .= sprintf("<span style=\"color:red;\">Current margin on this item is %.2f%%</span><br />", $actual * 100);
            $srp = getSRP($cost, $dm);
            $ret .= sprintf("Suggested price: \$%.2f ", $srp);
            $ret .= sprintf("(<a href=\"\" onclick=\"setPrice(%.2f); return false;\">Use this price</a>)", $srp);
        }
    }
    echo $ret;
}
Example #9
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 #10
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 #11
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 #12
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 #13
0
 public function SaveFormData($upc)
 {
     $local = $this->db();
     $upc = BarcodeLib::padUPC($upc);
     $pu = new ProductUserModel($local);
     $pu->upc($upc);
     $pu->enableOnline(FormLib::get('u_online') == 1 ? 1 : 0);
     $pu->soldOut(FormLib::get('u_soldout') == 1 ? 1 : 0);
     $pu->save();
     include dirname(__FILE__) . '/../../src/Credentials/OutsideDB.tunneled.php';
     $remote = $dbc;
     $pu->load();
     if ($pu->enableOnline() && $remote->isConnected()) {
         $pu->setConnection($remote);
         $pu->save();
         $prod = new ProductsModel($local);
         $prod->upc($upc);
         $prod->load();
         $prod->setConnection($remote);
         $prod->save();
     } elseif (FormLib::get('u_already_online') && $remote->isConnected()) {
         $prod = new ProductsModel($remote);
         $prod->upc($upc);
         $prod->delete();
     }
     if ($local->tableExists('productExpires')) {
         $e = new ProductExpiresModel($local);
         $e->upc($upc);
         $e->expires(FormLib::getDate('u_expires', date('Y-m-d')));
         $e->save();
         if ($e->expires() && $remote->isConnected()) {
             $e->setConnection($remote);
             $e->save();
         }
     }
 }
Example #14
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;
 }
Example #15
0
 public function showEditForm($upc, $display_mode = 1, $expand_mode = 1)
 {
     $db = $this->db();
     $product = new ProductsModel($db);
     $product->upc($upc);
     if (!$product->load()) {
         /**
           Lookup vendor cost on new items
         */
         $vendor = new VendorItemsModel($db);
         $vendor->upc($upc);
         foreach ($vendor->find('vendorID') as $v) {
             $product->cost($v->cost());
             break;
         }
     }
     $ret = '<div id="ItemMarginFieldset" class="panel panel-default">';
     $ret .= "<div class=\"panel-heading\">\n                <a href=\"\" onclick=\"\$('#ItemMarginContents').toggle();return false;\">\n                Margin\n                </a></div>";
     $css = $expand_mode == 1 ? '' : ' collapse';
     $ret .= '<div id="ItemMarginContents" class="panel-body' . $css . '">';
     $ret .= '<div class="col-sm-5">';
     $ret .= '<div id="ItemMarginMeter">';
     $ret .= $this->calculateMargin($product->normal_price(), $product->cost(), $product->department(), $upc);
     $ret .= '</div>';
     $ret .= '</div>';
     $ret .= '<div class="col-sm-6">';
     $ret .= '<div class="form-group form-inline">
                 <label>Pricing Rule</label>
                 <select name="price-rule-id" class="form-control input-sm"
                     onchange="if(this.value>=0)$(\'#custom-pricing-fields :input\').prop(\'disabled\', true);
                     else $(\'#custom-pricing-fields :input\').prop(\'disabled\', false);">
                     <option value="0" ' . ($product->price_rule_id() == 0 ? 'selected' : '') . '>Normal</option>
                     <option value="1" ' . ($product->price_rule_id() == 1 ? 'selected' : '') . '>Variable</option>
                     <option value="-1" ' . ($product->price_rule_id() > 1 ? 'selected' : '') . '>Custom</option>
                 </select>
                 <input type="hidden" name="current-price-rule-id" value="' . $product->price_rule_id() . '" />
                 &nbsp;
                 <label>Avg. Daily Movement</label> ' . sprintf('%.2f', $this->avgSales($upc)) . '
              </div>';
     $rule = new PriceRulesModel($db);
     if ($product->price_rule_id() > 1) {
         $rule->priceRuleID($product->price_rule_id());
         $rule->load();
     }
     $disabled = $product->price_rule_id() <= 1 ? 'disabled' : '';
     $ret .= '<div id="custom-pricing-fields" class="form-group form-inline">
                 <label>Custom</label>
                 <select ' . $disabled . ' name="price-rule-type" class="form-control input-sm">
                 {{RULE_TYPES}}
                 </select>
                 <input type="text" class="form-control date-field input-sm" name="rule-review-date"
                     ' . $disabled . ' placeholder="Review Date" title="Review Date" value="{{REVIEW_DATE}}" />
                 <input type="text" class="form-control input-sm" name="rule-details"
                     ' . $disabled . ' placeholder="Details" title="Details" value="{{RULE_DETAILS}}" />
              </div>';
     $types = new PriceRuleTypesModel($db);
     $ret = str_replace('{{RULE_TYPES}}', $types->toOptions($rule->priceRuleTypeID()), $ret);
     $ret = str_replace('{{REVIEW_DATE}}', $rule->reviewDate(), $ret);
     $ret = str_replace('{{RULE_DETAILS}}', $rule->details(), $ret);
     $ret .= '</div>';
     $ret .= '</div>';
     $ret .= '</div>';
     return $ret;
 }
Example #16
0
 /**
   Do whatever the service is supposed to do.
   Should override this.
   @param $args array of data
   @return an array of data
 */
 public function run($args = array())
 {
     $ret = array();
     if (!property_exists($args, 'upc')) {
         // missing required arguments
         $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters needs type');
         return $ret;
     }
     if (!is_array($args->upc)) {
         $args->upc = array($args->upc);
     }
     $dbc = \FannieDB::get(\FannieConfig::config('OP_DB'));
     $storeID = \FannieConfig::get('STORE_ID');
     /**
       In "fast" mode, look up the items and run UPDATE queries
       on each lane. This reduces overhead substantially but will
       overlook brand-new items since there's no check whether the
       item exists on the lane.
     
       If "fast" is not specified, each UPC record is copied to the
       lane exactly using models. This mode is preferrable unless
       performance becomes an issue.
     */
     if (property_exists($args, 'fast')) {
         $upc_data = array();
         $query = '
         SELECT normal_price,
             pricemethod,
             quantity,
             groupprice,
             special_price,
             specialpricemethod,
             specialquantity,
             specialgroupprice,
             discounttype,
             mixmatchcode,
             department,
             tax,
             foodstamp,
             discount,
             qttyEnforced,
             idEnforced,
             inUse,
             upc
         FROM products
         WHERE store_id=?
             AND upc IN (';
         $params = array($storeID);
         foreach ($args->upc as $upc) {
             $query .= '?,';
             $params[] = \BarcodeLib::padUPC($upc);
         }
         $query = substr($query, 0, strlen($query) - 1);
         $prep = $dbc->prepare($query);
         $result = $dbc->execute($prep, $params);
         while ($w = $dbc->fetchRow($result)) {
             $upc_data[$w['upc']] = $w;
         }
         $updateQ = '
         UPDATE products AS p SET
             p.normal_price = ?,
             p.pricemethod = ?,
             p.quantity = ?,
             p.groupprice = ?,
             p.special_price = ?,
             p.specialpricemethod = ?,
             p.specialquantity = ?,
             p.specialgroupprice = ?,
             p.discounttype = ?,
             p.mixmatchcode = ?,
             p.department = ?,
             p.tax = ?,
             p.foodstamp = ?,
             p.discount=?,
             p.qttyEnforced=?,
             p.idEnforced=?,
             p.inUse=?
         WHERE p.upc = ?';
         $FANNIE_LANES = \FannieConfig::config('LANES');
         for ($i = 0; $i < count($FANNIE_LANES); $i++) {
             $lane_sql = new \SQLManager($FANNIE_LANES[$i]['host'], $FANNIE_LANES[$i]['type'], $FANNIE_LANES[$i]['op'], $FANNIE_LANES[$i]['user'], $FANNIE_LANES[$i]['pw']);
             if (!isset($lane_sql->connections[$FANNIE_LANES[$i]['op']]) || $lane_sql->connections[$FANNIE_LANES[$i]['op']] === false) {
                 // connect failed
                 continue;
             }
             $updateP = $lane_sql->prepare($updateQ);
             foreach ($upc_data as $upc => $data) {
                 $lane_args = array($data['normal_price'], $data['pricemethod'], $data['quantity'], $data['groupprice'], $data['special_price'], $data['specialpricemethod'], $data['specialquantity'], $data['specialgroupprice'], $data['discounttype'], $data['mixmatchcode'], $data['department'], $data['tax'], $data['foodstamp'], $data['discount'], $data['qttyEnforced'], $data['idEnforced'], $data['inUse'], $upc);
                 $lane_sql->execute($updateP, $lane_args);
             }
         }
     } else {
         $product = new \ProductsModel($dbc);
         $ret['synced'] = array();
         foreach ($args->upc as $upc) {
             $upc = \BarcodeLib::padUPC($upc);
             $product->upc($upc);
             $product->store_id($storeID);
             if ($product->load()) {
                 $product->pushToLanes();
                 $ret['synced'][] = $upc;
             }
         }
     }
     return $ret;
 }
Example #17
0
 public function showEditForm($upc, $display_mode = 1, $expand_mode = 1)
 {
     $FANNIE_URL = FannieConfig::config('URL');
     $upc = BarcodeLib::padUPC($upc);
     $ret = '<div id="ProdUserFieldset" class="panel panel-default">';
     $ret .= "<div class=\"panel-heading\">\n                <a href=\"\" onclick=\"\$('#ProdUserFieldsetContent').toggle();return false;\">\n                Sign/Web Info</a>\n                </div>";
     $css = $expand_mode == 1 ? '' : ' collapse';
     $ret .= '<div id="ProdUserFieldsetContent" class="panel-body' . $css . '">';
     $dbc = $this->db();
     $model = new ProductUserModel($dbc);
     $model->upc($upc);
     $model->load();
     $loc = new ProdPhysicalLocationModel($dbc);
     $loc->upc($upc);
     $loc->load();
     $sections = new FloorSectionsModel($dbc);
     $prod = new ProductsModel($dbc);
     $prod->upc($upc);
     $prod->load();
     $ret .= '<div class="col-sm-6">';
     $ret .= '<div class="row form-group">' . '<label class="col-sm-1">Brand</label> ' . '<div class="col-sm-8">' . '<input type="text" class="form-control" id="lf_brand" name="lf_brand" value="' . $model->brand() . '" />' . '</div>' . '<div class="col-sm-3">' . ' <a href="" onclick="createSign(); return false;">Make Sign</a>' . '</div>' . '</div>';
     $ret .= '<div class="row form-group">' . '<label class="col-sm-1">Desc.</label> ' . '<div class="col-sm-8">' . '<textarea class="form-control" rows="2" id="lf_desc" name="lf_desc">' . $model->description() . '</textarea>' . '</div>' . '</div>';
     $ret .= '<div class="row form-group">' . '<label class="small col-sm-1">Sign Ct.</label> ' . '<div class="col-sm-8">' . '<input type="number" class="form-control price-field"
                 name="sign-count" value="' . $model->signCount() . '" />' . '</div>' . '</div>';
     $ret .= '<div class="row form-group">
                 <label tile="Location on the floor" class="col-sm-1">Loc.</label>
                 <div class="col-sm-8">
                     <select name="floor-id" class="form-control">
                         <option value="0">n/a</option>';
     foreach ($sections->find('name') as $section) {
         $ret .= sprintf('<option %s value="%d">%s</option>', $loc->floorSectionID() == $section->floorSectionID() ? 'selected' : '', $section->floorSectionID(), $section->name());
     }
     $ret .= '</select>
             </div>
             <div class="col-sm-3 text-left">
                 <a href="mapping/FloorSectionsPage.php" target="_blank">Add more</a>
             </div>
             </div>';
     $otherOriginBlock = '<div class=row>
             <div class=col-sm-1 />
             <div class=col-sm-8>
         <select name=otherOrigin[] class=form-control><option value=0>n/a</option>';
     $ret .= '<div class="row form-group">' . '<label class="col-sm-1"><a href="' . $FANNIE_URL . 'item/origins/OriginEditor.php">Origin</a></label>' . '<div class="col-sm-8">' . ' <select name="origin" class="form-control">' . '<option value="0">n/a</option>';
     $origins = new OriginsModel($dbc);
     $origins->local(0);
     foreach ($origins->find('name') as $o) {
         $ret .= sprintf('<option %s value="%d">%s</option>', $prod->current_origin_id() == $o->originID() ? 'selected' : '', $o->originID(), $o->name());
         $otherOriginBlock .= sprintf('<option value=%d>%s</option>', $o->originID(), $o->name());
     }
     $ret .= '</select></div>';
     $otherOriginBlock .= '</div></div>';
     $ret .= '<div class="col-sm-3 text-left">';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="" 
             onclick="$(\'#originsBeforeMe\').before(\'' . $otherOriginBlock . '\'); return false;">Add more</a>';
     $ret .= '</div></div>';
     $mapP = 'SELECT originID FROM ProductOriginsMap WHERE upc=? AND originID <> ?';
     $mapR = $dbc->execute($mapP, array($upc, $prod->current_origin_id()));
     while ($mapW = $dbc->fetch_row($mapR)) {
         $ret .= '<div class="form-group form-inline">
             <select name="otherOrigin[]" class="form-control"><option value="0">n/a</option>';
         foreach ($origins->find('name') as $o) {
             $ret .= sprintf('<option %s value="%d">%s</option>', $mapW['originID'] == $o->originID() ? 'selected' : '', $o->originID(), $o->name());
         }
         $ret .= '</select></div>';
     }
     $ret .= '<div id="originsBeforeMe"></div>';
     $ret .= '</div>';
     $ret .= '<div class="col-sm-6">';
     $ret .= '<div class="form-group"><label>Ad Text</label></div>';
     $ret .= '<div class="form-group">
             <textarea name="lf_text" class="form-control"
                 rows="8" cols="45">' . str_replace('<br />', "\n", $model->long_text()) . '</textarea></div>';
     $ret .= '</div>';
     $ret .= '</div>';
     $ret .= '</div>';
     return $ret;
 }
Example #18
0
 /**
   Import Hobart Data into scaleItems table
   This one is for "expanded text" data
   @param $filename [string] scale-exported data CSV
   @return [int] number of items imported
 */
 public static function readTextsFromFile($filename)
 {
     $dbc = \FannieDB::get(\FannieConfig::factory()->get('OP_DB'));
     $product = new \ProductsModel($dbc);
     $scaleItem = new \ScaleItems($dbc);
     $number_index = -1;
     $text_index = -1;
     $fp = fopen($filename, 'r');
     $headers = fgetcsv($fp);
     for ($i = 0; $i < count($headers); $i++) {
         $header = $headers[$i];
         if ($header == 'Expanded Text Number') {
             $number_index = $i;
         } else {
             if ($header == 'Expanded Text') {
                 $text_index = $i;
             }
         }
     }
     if ($text_index == -1 || $number_index == -1) {
         // no valid data
         return 0;
     }
     $item_count = 0;
     while (!feof($fp)) {
         $line = fgetcsv($fp);
         $plu = $line[$number_index];
         $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);
         $scaleItem->text($line[$text_index]);
         $scaleItem->save();
         $item_count++;
     }
     fclose($fp);
     return $item_count;
 }
Example #19
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 #20
0
 $upR = $sql->execute($upQ, array($val, $upc));
 if ($val == 1) {
     $prod = new ProductsModel($sql);
     $prod->upc($upc);
     $prod->store_id(1);
     $prod->load();
     // make sure another rule isn't overwritten with a generic one
     if ($prod->price_rule_id() == 0) {
         $prod->price_rule_id(1);
     }
     $prod->save();
 } else {
     $prod = new ProductsModel($sql);
     $prod->upc($upc);
     $prod->store_id(1);
     $prod->load();
     $ruleID = 0;
     // remove the rule but save its ID
     if ($prod->price_rule_id() != 0) {
         $ruleID = $prod->price_rule_id();
         $prod->price_rule_id(0);
     }
     $prod->save();
     // make sure no other item is using the same
     // rule before deleting it
     if ($ruleID > 1) {
         $prod->reset();
         $prod->price_rule_id($ruleID);
         if (count($prod->find()) == 0) {
             // no products are using this rule
             $rule = new PriceRulesModel($sql);
Example #21
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 #22
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 #23
0
 public function run()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $now = date('Y-m-d 00:00:00');
     $sale_upcs = array();
     // ensure likecode items are mixmatch-able
     if ($dbc->dbms_name() == 'mssql') {
         $dbc->query("UPDATE products\n                SET mixmatchcode=convert(varchar,u.likecode+500)\n                FROM \n                products AS p\n                INNER JOIN upcLike AS u\n                ON p.upc=u.upc");
     } else {
         $dbc->query("UPDATE products AS p\n                INNER JOIN upcLike AS u ON p.upc=u.upc\n                SET p.mixmatchcode=convert(u.likeCode+500,char)");
     }
     $likeP = $dbc->prepare('SELECT u.upc 
                             FROM upcLike AS u
                                 INNER JOIN products AS p ON u.upc=p.upc
                             WHERE likeCode=?');
     $product = new ProductsModel($dbc);
     $b_def = $dbc->tableDefinition('batches');
     // lookup current batches
     $query = 'SELECT l.upc, 
                 l.batchID, 
                 l.pricemethod, 
                 l.salePrice, 
                 l.groupSalePrice,
                 l.quantity,
                 b.startDate, 
                 b.endDate, 
                 b.discounttype
                 ' . (isset($b_def['transLimit']) ? ',b.transLimit' : ',0 AS transLimit') . '
               FROM batches AS b
                 INNER JOIN batchList AS l ON b.batchID = l.batchID
               WHERE b.discounttype <> 0
                 AND b.startDate <= ?
                 AND b.endDate >= ?
               ORDER BY l.upc,
                 l.salePrice DESC';
     $t_def = $dbc->tableDefinition('batchList');
     if (!isset($t_def['groupSalePrice'])) {
         $query = str_replace('l.groupSalePrice', 'NULL AS groupSalePrice', $query);
     }
     /**
       In HQ mode, join on junction table to get UPC+storeID rows
       when applying sale pricing
     */
     if ($this->config->get('STORE_MODE') === 'HQ') {
         $query = str_replace('WHERE', ' LEFT JOIN StoreBatchMap AS s ON b.batchID=s.batchID WHERE ', $query);
         $query = str_replace('SELECT', 'SELECT s.storeID,', $query);
     }
     $prep = $dbc->prepare($query);
     $result = $dbc->execute($prep, array($now, $now));
     while ($row = $dbc->fetch_row($result)) {
         // all items affected by this bathcList record
         // could be more than one in the case of likecodes
         $item_upcs = array();
         // use products column names for readability below
         $special_price = $row['salePrice'];
         $specialpricemethod = $row['pricemethod'];
         if ($row['groupSalePrice'] != null) {
             $specialgroupprice = $row['groupSalePrice'];
         } else {
             $specialgroupprice = abs($row['salePrice']);
         }
         $specialquantity = $row['quantity'];
         $special_limit = $row['transLimit'];
         $start_date = $row['startDate'];
         $end_date = $row['endDate'];
         $discounttype = $row['discounttype'];
         $batchID = $row['batchID'];
         // pricemethod 3 and 4 (AB pricing, typically)
         // has some overly complicated rules
         $mixmatch = false;
         if ($specialpricemethod == 3 || $specialpricemethod == 4) {
             if ($special_price >= 0) {
                 $mixmatch = $row['batchID'];
             } else {
                 $mixmatch = -1 * $row['batchID'];
             }
         }
         // unpack likecodes, if needed
         if (substr($row['upc'], 0, 2) == 'LC') {
             $likeCode = substr($row['upc'], 2);
             $likeR = $dbc->execute($likeP, array($likeCode));
             while ($likeW = $dbc->fetch_row($likeR)) {
                 $item_upcs[] = $likeW['upc'];
                 if ($mixmatch !== false) {
                     $mixmatch = $likeCode + 500;
                 }
             }
         } else {
             $item_upcs[] = $row['upc'];
         }
         // check each item to see if it is on
         // sale with the correct parameters
         foreach ($item_upcs as $upc) {
             $product->reset();
             $product->upc($upc);
             $this->cronMsg('Checking item ' . $upc, FannieLogger::INFO);
             /**
               Transistion mechanism. A batch that is set to apply to
               zero stores really should apply to zero stores. For now
               it fails over to using the local store's ID
             */
             if ($this->config->get('STORE_MODE') === 'HQ') {
                 $storeID = $row['storeID'];
                 if ($storeID == null) {
                     $storeID = $this->config->get('STORE_ID');
                 }
                 $product->store_id($storeID);
             }
             if (!$product->load()) {
                 $this->cronMsg("\tError: item does not exist in products", FannieLogger::NOTICE);
                 continue;
             }
             // list of UPCs that should be on sale
             $sale_upcs[] = $upc;
             $changed = false;
             if ($product->special_price() != $special_price) {
                 $changed = true;
                 $product->special_price($special_price);
             }
             if ($product->specialpricemethod() != $specialpricemethod) {
                 $changed = true;
                 $product->specialpricemethod($specialpricemethod);
             }
             if ($product->specialgroupprice() != $specialgroupprice) {
                 $changed = true;
                 $product->specialgroupprice($specialgroupprice);
             }
             if ($product->specialquantity() != $specialquantity) {
                 $changed = true;
                 $product->specialquantity($specialquantity);
             }
             if ($product->special_limit() != $special_limit) {
                 $changed = true;
                 $product->special_limit($special_limit);
             }
             if ($product->start_date() != $start_date) {
                 $changed = true;
                 $product->start_date($start_date);
             }
             if ($product->end_date() != $end_date) {
                 $changed = true;
                 $product->end_date($end_date);
             }
             if ($product->discounttype() != $discounttype) {
                 $changed = true;
                 $product->discounttype($discounttype);
             }
             if ($mixmatch !== false && $product->mixmatchcode() != $mixmatch) {
                 $changed = true;
                 $product->mixmatchcode($mixmatch);
             }
             if ($product->batchID() != $batchID) {
                 $changed = true;
                 $product->batchID($batchID);
             }
             if ($changed) {
                 $product->save();
                 $this->cronMsg("\tUpdated item", FannieLogger::INFO);
             }
         }
         // end loop on batchList record items
     }
     // end loop on batchList records
     // No sale items; need a filler value for
     // the query below
     if (count($sale_upcs) == 0) {
         $this->cronMsg('Notice: nothing is currently on sale', FannieLogger::WARNING);
         $sale_upcs[] = 'notValidUPC';
     }
     // now look for anything on sale that should not be
     // and take those items off sale
     $upc_in = '';
     foreach ($sale_upcs as $upc) {
         $upc_in .= '?,';
     }
     $upc_in = substr($upc_in, 0, strlen($upc_in) - 1);
     $lookupQ = 'SELECT p.upc
                 FROM products AS p
                 WHERE upc NOT IN (' . $upc_in . ')
                     AND (
                         p.discounttype <> 0
                         OR p.special_price <> 0
                         OR p.specialpricemethod <> 0
                         OR p.specialgroupprice <> 0
                         OR p.specialquantity <> 0
                     )';
     $lookupP = $dbc->prepare($lookupQ);
     $lookupR = $dbc->execute($lookupP, $sale_upcs);
     while ($lookupW = $dbc->fetch_row($lookupR)) {
         $this->cronMsg('Taking ' . $lookupW['upc'] . ' off sale', FannieLogger::INFO);
         $product->reset();
         if ($this->config->get('STORE_MODE') === 'HQ') {
             $product->store_id($this->config->get('STORE_ID'));
         }
         $product->upc($lookupW['upc']);
         $product->discounttype(0);
         $product->special_price(0);
         $product->specialgroupprice(0);
         $product->specialquantity(0);
         $product->start_date('');
         $product->end_date('');
         $product->batchID(0);
         $product->save();
     }
 }
Example #24
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 #25
0
    echo "<input type=hidden name=upc value={$upc}>";
    echo "<input type=hidden name=yes value=yes>";
    echo "<input type=submit value=Yes>  ";
    echo "</form>";
    echo "</td><td>";
    echo "<form action=productTest.php method=get>";
    echo "<input type=hidden name=upc value={$upc}>";
    echo "<input type=submit value=No>";
    echo "</form>";
    echo "</td></tr></table>";
} else {
    include '../db.php';
    // find the discount type for the selected upc
    $model = new ProductsModel($sql);
    $model->upc($upc);
    $model->load();
    $discounttype = $model->discounttype();
    // find the batchID(s) of active batches
    // containing the upc
    $batchIDQ = $sql->prepare("select b.batchID from batches as b, batchList as l where\n               b.batchID = l.batchID and l.upc = ? and b.discountType = ?\n           AND " . $sql->now() . " BETWEEN b.startDate and b.endDate");
    $batchIDR = $sql->execute($batchIDQ, array($upc, $discounttype));
    // if there isn't a batch putting that item on sale, then
    // i don't know what's going on.  SO DON'T CHANGE ANYTHING
    if ($sql->num_rows($batchIDR) != 0) {
        // now delete the upc from the batch list(s)
        while ($row = $sql->fetch_array($batchIDR)) {
            $batchID = $row['batchID'];
            $batchQ = $sql->prepare("delete from batchList where\n               upc = ? and batchID = ?");
            echo $batchQ . "<p />";
            $batchR = $sql->execute($batchQ, array($upc, $batchID));
        }
Example #26
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);
         }
     }
 }
Example #27
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;
 }