コード例 #1
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;
 }
コード例 #2
0
ファイル: BatchListPage.php プロジェクト: phpsmith/IS4C
 /**
   Create, update, and delete a batch
   Try each mode with and without an owner filter
 */
 public function unitTest($phpunit)
 {
     $get = $this->get_view();
     $phpunit->assertNotEquals(0, strlen($get));
     $this->connection->selectDB($this->config->get('OP_DB'));
     $model = new BatchesModel($this->connection);
     $this->newType = 1;
     $this->newName = 'Test BatchListPage';
     $this->newStart = date('Y-m-d 00:00:00');
     $this->newEnd = date('Y-m-d 00:00:00');
     $this->newOwner = 'IT';
     ob_start();
     $this->post_newType_newName_newStart_newEnd_newOwner_handler();
     ob_end_clean();
     $model->batchName($this->newName);
     $matches = $model->find();
     $phpunit->assertEquals(1, count($matches));
     $model->reset();
     $model->batchID($matches[0]->batchID());
     $phpunit->assertEquals(true, $model->load());
     $phpunit->assertEquals($this->newType, $model->batchType());
     $phpunit->assertEquals($this->newName, $model->batchName());
     $phpunit->assertEquals($this->newStart, $model->startDate());
     $phpunit->assertEquals($this->newEnd, $model->endDate());
     $phpunit->assertEquals($this->newOwner, $model->owner());
     $this->id = $model->batchID();
     $this->batchName = 'Change BatchListPage';
     $this->batchType = 2;
     $this->startDate = date('Y-m-d 00:00:00', strtotime('yesterday'));
     $this->endDate = $this->startDate;
     $this->owner = 'Admin';
     ob_start();
     $this->post_id_batchName_batchType_startDate_endDate_owner_handler();
     ob_end_clean();
     $model->reset();
     $model->batchID($this->id);
     $phpunit->assertEquals(true, $model->load());
     $phpunit->assertEquals($this->batchType, $model->batchType());
     $phpunit->assertEquals($this->batchName, $model->batchName());
     $phpunit->assertEquals($this->startDate, $model->startDate());
     $phpunit->assertEquals($this->endDate, $model->endDate());
     $phpunit->assertEquals($this->owner, $model->owner());
     $this->delete = 1;
     ob_start();
     $this->post_delete_id_handler();
     ob_end_clean();
     $model->reset();
     $model->batchID($this->id);
     $phpunit->assertEquals(false, $model->load());
     $modes = array('pending', 'current', 'historical', 'all');
     foreach ($modes as $m) {
         $get = $this->batchListDisplay('', $m, rand(0, 50));
         $phpunit->assertNotEquals(0, strlen($get));
         $get = $this->batchListDisplay('IT', $m, rand(0, 50));
         $phpunit->assertNotEquals(0, strlen($get));
     }
 }
コード例 #3
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;
 }
コード例 #4
0
ファイル: BatchesModel.php プロジェクト: phpsmith/IS4C
 protected function hookAddColumnowner()
 {
     // copy existing values from batchowner.owner to
     // new batches.owner column
     if ($this->connection->table_exists('batchowner')) {
         $dataR = $this->connection->query('SELECT batchID, owner FROM batchowner');
         $tempModel = new BatchesModel($this->connection);
         while ($dataW = $this->connection->fetch_row($dataR)) {
             $tempModel->reset();
             $tempModel->batchID($dataW['batchID']);
             if ($tempModel->load()) {
                 $tempModel->owner($dataW['owner']);
                 $tempModel->save();
             }
         }
     }
 }