コード例 #1
0
ファイル: AdvancedBatchEditor.php プロジェクト: phpsmith/IS4C
 /**
   Save batch and redirect to display
 */
 public function post_id_handler()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $list = new BatchListModel($dbc);
     $upcs = FormLib::get('upc', array());
     $prices = FormLib::get('price', array());
     $groups = FormLib::get('groupPrice', array());
     $methods = FormLib::get('priceMethod', array());
     $qtys = FormLib::get('quantity', array());
     for ($i = 0; $i < count($upcs); $i++) {
         $list->reset();
         $list->batchID($this->id);
         $list->upc($upcs[$i]);
         $changed = false;
         if (isset($prices[$i])) {
             $list->salePrice($prices[$i]);
             $changed = true;
         }
         if (isset($groups[$i])) {
             $list->groupSalePrice($groups[$i]);
             $changed = true;
         }
         if (isset($methods[$i])) {
             $list->pricemethod($methods[$i]);
             $changed = true;
         }
         if (isset($qtys[$i])) {
             $list->quantity($qtys[$i]);
             $changed = true;
         }
         if ($changed) {
             $list->save();
         }
     }
     header('Location: ?id=' . $this->id);
     return false;
 }
コード例 #2
0
ファイル: BatchFromSearch.php プロジェクト: phpsmith/IS4C
 function post_createBatch_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $type = $this->form->batchType;
     $name = $this->form->batchName;
     $startdate = $this->form->startDate;
     $enddate = $this->form->endDate;
     $owner = $this->form->batchOwner;
     $priority = 0;
     $upcs = $this->form->upc;
     $prices = $this->form->price;
     $btype = new BatchTypeModel($dbc);
     $btype->batchTypeID($type);
     if (!$btype->load()) {
         echo 'Invalid Batch Type ' . $type;
         return false;
     }
     $discounttype = $btype->discType();
     // make sure item data is present before creating batch
     if (!is_array($upcs) || !is_array($prices) || count($upcs) != count($prices) || count($upcs) == 0) {
         echo 'Invalid item data';
         return false;
     }
     $batch = new BatchesModel($dbc);
     $batch->startDate($startdate);
     $batch->endDate($enddate);
     $batch->batchName($name);
     $batch->batchType($type);
     $batch->discountType($discounttype);
     $batch->priority($priority);
     $batch->owner($owner);
     $batchID = $batch->save();
     if ($this->config->get('STORE_MODE') === 'HQ') {
         StoreBatchMapModel::initBatch($batchID);
     }
     if ($dbc->tableExists('batchowner')) {
         $insQ = $dbc->prepare_statement("insert batchowner values (?,?)");
         $insR = $dbc->exec_statement($insQ, array($batchID, $owner));
     }
     // add items to batch
     for ($i = 0; $i < count($upcs); $i++) {
         $upc = $upcs[$i];
         $price = isset($prices[$i]) ? $prices[$i] : 0.0;
         $list = new BatchListModel($dbc);
         $list->upc(BarcodeLib::padUPC($upc));
         $list->batchID($batchID);
         $list->salePrice($price);
         $list->groupSalePrice($price);
         $list->active(0);
         $list->pricemethod(0);
         $list->quantity(0);
         $list->save();
     }
     /**
       If tags were requested and it's price change batch, make them
       Lookup vendor info for each item then add a shelftag record
     */
     $tagset = $this->form->tagset;
     if ($discounttype == 0 && $tagset !== '') {
         $vendorID = $this->form->preferredVendor;
         $tag = new ShelftagsModel($dbc);
         $product = new ProductsModel($dbc);
         for ($i = 0; $i < count($upcs); $i++) {
             $upc = $upcs[$i];
             $price = isset($prices[$i]) ? $prices[$i] : 0.0;
             $product->upc($upc);
             $info = $product->getTagData($price);
             $tag->id($tagset);
             $tag->upc($upc);
             $tag->description($info['description']);
             $tag->normal_price($price);
             $tag->brand($info['brand']);
             $tag->sku($info['sku']);
             $tag->size($info['size']);
             $tag->units($info['units']);
             $tag->vendor($info['vendor']);
             $tag->pricePerUnit($info['pricePerUnit']);
             $tag->save();
         }
     }
     return 'Location: newbatch/BatchManagementTool.php?startAt=' . $batchID;
 }
コード例 #3
0
ファイル: CoopDealsReviewPage.php プロジェクト: phpsmith/IS4C
 public function results_content()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $start = date('Y-m-d', strtotime(FormLib::get_form_value('start', date('Y-m-d'))));
     $end = date('Y-m-d', strtotime(FormLib::get_form_value('end', date('Y-m-d'))));
     $b_start = date('Y-m-d', strtotime(FormLib::get_form_value('bstart', date('Y-m-d'))));
     $b_end = date('Y-m-d', strtotime(FormLib::get_form_value('bend', date('Y-m-d'))));
     $naming = FormLib::get_form_value('naming', '');
     $upcs = FormLib::get_form_value('upc', array());
     $prices = FormLib::get_form_value('price', array());
     $names = FormLib::get_form_value('batch', array());
     $set = FormLib::get('deal-set');
     $batchIDs = array();
     if (FormLib::get_form_value('group_by_superdepts', '') == 'on') {
         $superdept_grouping = "CASE WHEN s.super_name IS NULL THEN 'sale' ELSE s.super_name END";
     } else {
         $superdept_grouping = "";
     }
     $saleItemsP = $dbc->prepare_statement("\n            SELECT t.upc,\n                t.price,\n                t.multiplier," . $dbc->concat($superdept_grouping ? $superdept_grouping : "''", $superdept_grouping ? "' '" : "''", "'Co-op Deals '", "t.abtpr", '') . " AS batch\n            FROM CoopDealsItems as t\n                " . DTrans::joinProducts('t', 'p', 'INNER') . "\n                LEFT JOIN MasterSuperDepts AS s ON p.department=s.dept_ID\n            WHERE p.inUse=1\n                AND t.dealSet=?\n            ORDER BY s.super_name, t.upc\n        ");
     $saleItemsR = $dbc->exec_statement($saleItemsP, array($set));
     $batchP = $dbc->prepare_statement('
         INSERT INTO batches (
             batchName,
             batchType,
             discountType,
             priority,
             startDate,
             endDate
         )
         VALUES (?, ?, ?, 0, ?, ?)
     ');
     $list = new BatchListModel($dbc);
     $list->active(0);
     $list->pricemethod(0);
     $list->quantity(0);
     while ($row = $dbc->fetch_row($saleItemsR)) {
         if (!isset($batchIDs[$row['batch']])) {
             $args = array($row['batch'] . ' ' . $naming, 1, 1);
             if (substr($row['batch'], -2) == " A") {
                 $args[] = $start;
                 $args[] = $end;
             } else {
                 if (substr($row['batch'], -2) == " B") {
                     $args[] = $b_start;
                     $args[] = $b_end;
                 } else {
                     $args[] = $start;
                     $args[] = $b_end;
                 }
             }
             $dbc->exec_statement($batchP, $args);
             $bID = $dbc->insert_id();
             $batchIDs[$row['batch']] = $bID;
             if ($this->config->get('STORE_MODE') === 'HQ') {
                 StoreBatchMapModel::initBatch($bID);
             }
         }
         $id = $batchIDs[$row['batch']];
         $list->upc($row['upc']);
         $list->batchID($id);
         $list->salePrice(sprintf("%.2f", $row['price']));
         $list->signMultiplier($row['multiplier']);
         $list->save();
     }
     $ret = "<p>New sales batches have been created!</p>";
     $ret .= "<p><a href=\"../newbatch/\">View batches</a></p>";
     return $ret;
 }
コード例 #4
0
ファイル: batchAjax.php プロジェクト: phpsmith/IS4C
     echo "New Price Applied";
     break;
 case 'batchAdd':
     $vid = FormLib::get_form_value('vendorID');
     $bid = FormLib::get_form_value('batchID');
     $sid = FormLib::get_form_value('queueID', 0);
     if ($sid == 99) {
         $sid = 0;
     }
     $price = FormLib::get_form_value('price', 0);
     $model = new BatchListModel($dbc);
     $model->batchID($bid);
     $model->upc($upc);
     $model->salePrice($price);
     $model->pricemethod(0);
     $model->quantity(0);
     $model->save();
     $product = new ProductsModel($dbc);
     $product->upc($upc);
     $info = $product->getTagData($price);
     /* create a shelftag */
     $tag = new ShelftagsModel($dbc);
     $tag->id($sid);
     $tag->upc($upc);
     $tag->description($info['description']);
     $tag->normal_price($price);
     $tag->brand($info['brand']);
     $tag->sku($info['sku']);
     $tag->size($info['size']);
     $tag->units($info['units']);
     $tag->vendor($info['vendor']);
コード例 #5
0
 function post_newbatch_tags_upcs_newprices_handler()
 {
     global $FANNIE_OP_DB, $FANNIE_URL;
     $this->upcs = json_decode($this->upcs);
     $this->newprices = json_decode($this->newprices);
     $dbc = FannieDB::get($FANNIE_OP_DB);
     // try to lookup batch owner
     // failure is ok
     $owner = '';
     $ownerP = $dbc->prepare('SELECT super_name FROM superDeptNames WHERE superID=?');
     $ownerR = $dbc->execute($ownerP, array($this->tags));
     if ($dbc->num_rows($ownerR) > 0) {
         $ownerW = $dbc->fetch_row($ownerR);
         $owner = $ownerW['super_name'];
     }
     // try to lookup correct discount type
     // failure is ok
     $btype = 0;
     $btypeR = $dbc->query('SELECT batchTypeID FROM batchType WHERE discType=0 ORDER BY batchTypeID');
     if ($dbc->num_rows($btypeR) > 0) {
         $btypeW = $dbc->fetch_row($btypeR);
         $btype = $btypeW['batchTypeID'];
     }
     // create batch. date 'yesterday' ensures it doesn't
     // run automatically unless the user re-schedules it
     $b = new BatchesModel($dbc);
     $b->batchName($this->newbatch);
     $b->startDate(date('Y-m-d', strtotime('yesterday')));
     $b->endDate(date('Y-m-d', strtotime('yesterday')));
     $b->batchType($btype);
     $b->discountType(0);
     $b->priority(0);
     $b->owner($owner);
     $id = $b->save();
     // maintain @deprecated table if present
     if ($dbc->tableExists('batchowner')) {
         $insQ = $dbc->prepare_statement("insert batchowner values (?,?)");
         $insR = $dbc->exec_statement($insQ, array($id, $owner));
     }
     // add items to batch
     for ($i = 0; $i < count($this->upcs); $i++) {
         $upc = $this->upcs[$i];
         if (!isset($this->newprices[$i])) {
             continue;
             // should not happen
         }
         $price = $this->newprices[$i];
         $bl = new BatchListModel($dbc);
         $bl->upc(BarcodeLib::padUPC($upc));
         $bl->batchID($id);
         $bl->salePrice($price);
         $bl->active(0);
         $bl->pricemethod(0);
         $bl->quantity(0);
         $bl->save();
     }
     // did not select "none" for tags
     // so create some shelftags
     if ($this->tags != -1) {
         $lookup = $dbc->prepare('SELECT p.description, v.brand, v.sku, v.size, v.units, n.vendorName
                             FROM products AS p LEFT JOIN vendorItems AS v ON p.upc=v.upc
                             LEFT JOIN vendors AS n ON v.vendorID=n.vendorID
                             WHERE p.upc=? ORDER BY v.vendorID');
         $tag = new ShelfTagModel($dbc);
         for ($i = 0; $i < count($this->upcs); $i++) {
             $upc = $this->upcs[$i];
             if (!isset($this->newprices[$i])) {
                 continue;
                 // should not happen
             }
             $price = $this->newprices[$i];
             $info = array('description' => '', 'brand' => '', 'sku' => '', 'size' => '', 'units' => 1, 'vendorName' => '');
             $lookupR = $dbc->execute($lookup, array($upc));
             if ($dbc->num_rows($lookupR) > 0) {
                 $info = $dbc->fetch_row($lookupR);
             }
             $ppo = $info['size'] !== '' ? \COREPOS\Fannie\API\lib\PriceLib::pricePerUnit($price, $info['size']) : '';
             $tag->id($this->tags);
             $tag->upc($upc);
             $tag->description($info['description']);
             $tag->normal_price($price);
             $tag->brand($info['brand']);
             $tag->sku($info['sku']);
             $tag->size($info['size']);
             $tag->units($info['units']);
             $tag->vendor($info['vendorName']);
             $tag->pricePerUnit($ppo);
             $tag->save();
         }
     }
     echo $FANNIE_URL . 'newbatch/BatchManagementTool.php?startAt=' . $id;
     return false;
 }
コード例 #6
0
ファイル: XlsBatchPage.php プロジェクト: phpsmith/IS4C
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $upcCol = $this->get_column_index('upc_lc');
     $priceCol = $this->get_column_index('price');
     $btype = FormLib::get_form_value('btype', 0);
     $date1 = FormLib::get_form_value('date1', date('Y-m-d'));
     $date2 = FormLib::get_form_value('date2', date('Y-m-d'));
     $bname = FormLib::get_form_value('bname', '');
     $owner = FormLib::get_form_value('bowner', '');
     $ftype = FormLib::get_form_value('ftype', 'UPCs');
     $has_checks = FormLib::get_form_value('has_checks') !== '' ? True : False;
     $dtQ = $dbc->prepare_statement("SELECT discType FROM batchType WHERE batchTypeID=?");
     $dtR = $dbc->execute($dtQ, array($btype));
     $dtW = $dbc->fetchRow($dtR);
     $discountType = is_array($dtW) ? $dtW[0] : 0;
     $insQ = $dbc->prepare_statement("\n            INSERT INTO batches \n            (startDate,endDate,batchName,batchType,discounttype,priority,owner)\n            VALUES \n            (?,?,?,?,?,0,?)");
     $args = array($date1, $date2, $bname, $btype, $discountType, $owner);
     $insR = $dbc->exec_statement($insQ, $args);
     $batchID = $dbc->insert_id();
     if ($this->config->get('STORE_MODE') === 'HQ') {
         StoreBatchMapModel::initBatch($batchID);
     }
     $upcChk = $dbc->prepare_statement("SELECT upc FROM products WHERE upc=?");
     $model = new BatchListModel($dbc);
     $model->batchID($batchID);
     $model->pricemethod(0);
     $model->quantity(0);
     $model->active(0);
     $ret = '';
     foreach ($linedata as $line) {
         if (!isset($line[$upcCol])) {
             continue;
         }
         if (!isset($line[$priceCol])) {
             continue;
         }
         $upc = $line[$upcCol];
         $price = $line[$priceCol];
         $upc = str_replace(" ", "", $upc);
         $upc = str_replace("-", "", $upc);
         $price = trim($price, ' ');
         $price = trim($price, '$');
         if (!is_numeric($upc)) {
             $ret .= "<i>Omitting item. Identifier {$upc} isn't a number</i><br />";
             continue;
         } elseif (!is_numeric($price)) {
             $ret .= "<i>Omitting item. Price {$price} isn't a number</i><br />";
             continue;
         }
         $upc = $ftype == 'UPCs' ? BarcodeLib::padUPC($upc) : 'LC' . $upc;
         if ($has_checks && $ftype == 'UPCs') {
             $upc = '0' . substr($upc, 0, 12);
         }
         if ($ftype == 'UPCs') {
             $chkR = $dbc->exec_statement($upcChk, array($upc));
             if ($dbc->num_rows($chkR) == 0) {
                 continue;
             }
         }
         $model->upc($upc);
         $model->salePrice($price);
         $model->groupSalePrice($price);
         $model->save();
     }
     $ret .= '
     <p>
         Batch created
         <a href="' . $this->config->URL . 'batches/newbatch/EditBatchPage.php?id=' . $batchID . '" class="btn btn-default">View Batch</a>
     </p>';
     $this->results = $ret;
     return true;
 }
コード例 #7
0
ファイル: EditBatchPage.php プロジェクト: phpsmith/IS4C
 protected function post_id_upc_price_qty_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $json = array('error' => 0, 'msg' => '');
     if (!is_numeric($this->qty) || $this->qty < 1 || $this->qty != round($this->qty)) {
         $json['error'] = 1;
         $json['msg'] = 'Invalid quantity "' . $this->qty . '"; using quantity one';
         $this->qty = 1;
     }
     $pmethod = $this->qty >= 2 ? 2 : 0;
     $model = new BatchListModel($dbc);
     $model->upc($this->upc);
     $model->batchID($this->id);
     $model->salePrice($this->price);
     $model->groupSalePrice($this->price);
     $model->quantity($this->qty);
     // quantity functions as a per-transaction limit
     // when pricemethod=0
     if ($this->qty <= 1) {
         $this->qty = 1;
         $model->quantity(0);
     }
     $model->pricemethod($pmethod);
     $model->save();
     $json['price'] = sprintf('%.2f', $this->price);
     $json['qty'] = (int) $this->qty;
     $upQ = $dbc->prepare_statement("update batchBarcodes set normal_price=? where upc=? and batchID=?");
     $upR = $dbc->exec_statement($upQ, array($this->price, $this->upc, $this->id));
     if (FormLib::get_form_value('audited') == '1') {
         \COREPOS\Fannie\API\lib\AuditLib::batchNotification($this->id, $this->upc, \COREPOS\Fannie\API\lib\AuditLib::BATCH_EDIT, substr($this->upc, 0, 2) == 'LC' ? true : false);
     }
     echo json_encode($json);
     return false;
 }