Example #1
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 #2
0
 /**
   Send email notification that item has been updated
   @param $upc [string] upc value or like code number
   @param $is_likecode [boolean] upc param is a like code
   @return [boolean] success/failure
 */
 public static function itemUpdate($upc, $likecode = false)
 {
     $conf = \FannieConfig::factory();
     $dbc = \FannieDB::getReadOnly($conf->get('OP_DB'));
     $product = new \ProductsModel($dbc);
     $product->upc($upc);
     $product->load();
     $desc = $product->description();
     $subject = "Item Update notification: " . $upc;
     $message = "Item {$upc} ({$desc}) has been changed\n";
     $message .= "Price: " . $product->normal_price() . "\n";
     $taxQ = $dbc->prepare_statement('SELECT description FROM taxrates WHERE id=?');
     $taxR = $dbc->execute($taxQ, array($product->tax()));
     $taxname = 'No Tax';
     if ($dbc->num_rows($taxR) > 0) {
         $taxW = $dbc->fetch_row($taxR);
         $taxname = $taxW['description'];
     }
     $message .= "Tax: " . $taxname . "\n";
     $message .= "Foodstampable: " . ($product->foodstamp() == 1 ? "Yes" : "No") . "\n";
     $message .= "Scale: " . ($product->scale() == 1 ? "Yes" : "No") . "\n";
     $message .= "Discountable: " . ($product->discount() == 1 ? "Yes" : "No") . "\n";
     if ($likecode) {
         $message .= "All items in this likecode ({$likecode}) were changed\n";
     }
     $message .= "\n";
     $message .= "Adjust this item?\n";
     $url = $conf->get('URL');
     $server_name = filter_input(INPUT_SERVER, 'SERVER_NAME');
     $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";
     $to_addr = self::getAddresses($product->department());
     if ($to_addr === false) {
         // no one set to receive notices
         return false;
     }
     mail($to_addr, $subject, $message, $from);
     return true;
 }
Example #3
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 #4
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 #5
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 #6
0
$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);
$model->save();
$checkP = $sql->prepare("SELECT upc FROM prodExtra WHERE upc=?");
Example #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
0
 function SaveFormData($upc)
 {
     $lc = FormLib::get_form_value('likeCode');
     $dbc = $this->db();
     $delP = $dbc->prepare_statement('DELETE FROM upcLike WHERE upc=?');
     $delR = $dbc->exec_statement($delP, array($upc));
     if ($lc == -1) {
         return $delR === False ? False : True;
     }
     $insP = 'INSERT INTO upcLike (upc,likeCode) VALUES (?,?)';
     $insR = $dbc->exec_statement($insP, array($upc, $lc));
     if (FormLib::get_form_value('LikeCodeNoUpdate') == 'noupdate') {
         return $insR === False ? False : True;
     }
     /* get values for current item */
     $valuesP = $dbc->prepare_statement('SELECT normal_price,pricemethod,groupprice,quantity,
         department,scale,tax,foodstamp,discount,qttyEnforced,local,wicable
         FROM products WHERE upc=?');
     $valuesR = $dbc->exec_statement($valuesP, array($upc));
     if ($dbc->num_rows($valuesR) == 0) {
         return False;
     }
     $values = $dbc->fetch_row($valuesR);
     /* apply current values to other other items
        in the like code */
     $upcP = $dbc->prepare_statement('SELECT upc FROM upcLike WHERE likeCode=? AND upc<>?');
     $upcR = $dbc->exec_statement($upcP, array($lc, $upc));
     $isHQ = FannieConfig::config('STORE_MODE') == 'HQ' ? true : false;
     $stores = new StoresModel($dbc);
     $stores = array_map(array_filter($stores->find(), function ($obj) {
         return $obj->hasOwnItems();
     }), function ($obj) {
         return $obj->storeID();
     });
     $model = new ProductsModel($dbc);
     $model->upc($upc);
     $model->mixmatchcode($lc + 500);
     if ($isHQ) {
         foreach ($stores as $store_id) {
             $model->store_id($store_id);
             $model->save();
         }
     } else {
         $model->save();
     }
     while ($upcW = $dbc->fetch_row($upcR)) {
         $model->reset();
         $model->upc($upcW['upc']);
         $model->normal_price($values['normal_price']);
         $model->pricemethod($values['pricemethod']);
         $model->groupprice($values['groupprice']);
         $model->quantity($values['quantity']);
         $model->department($values['department']);
         $model->scale($values['scale']);
         $model->tax($values['tax']);
         $model->foodstamp($values['foodstamp']);
         $model->discount($values['discount']);
         $model->qttyEnforced($values['qttyEnforced']);
         $model->local($values['local']);
         $model->wicable($values['wicable']);
         $model->mixmatchcode($lc + 500);
         if ($isHQ) {
             foreach ($stores as $store_id) {
                 $model->store_id($store_id);
                 $model->save();
             }
         } else {
             $model->save();
         }
         updateProductAllLanes($upcW['upc']);
     }
     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;
 }