Пример #1
0
 protected function post_id_handler()
 {
     $batchList = new BatchListModel($this->connection);
     $batchList->batchID($this->id);
     try {
         $upc = $this->form->upc;
         $style = $this->form->style;
         for ($i = 0; $i < count($upc); $i++) {
             $batchList->upc($upc[$i]);
             $batchList->signMultiplier($style[$i]);
             $batchList->save();
         }
     } catch (Exception $ex) {
     }
     return filter_input(INPUT_SERVER, 'PHP_SELF') . '?id=' . $this->id;
 }
Пример #2
0
 /**
   Display batch as form
 */
 public function get_id_view()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $list = new BatchListModel($dbc);
     $list->batchID($this->id);
     $ret = '<form method="post">
         <input type="hidden" name="id" value="' . $this->id . '" />
         <table class="table table-bordered table-striped tablesorter tablesorter-core">
         <thead>
         <tr>
             <th>UPC</th>
             <th>Brand</th>
             <th>Description</th>
             <th>Sale Price</th>
             <th>Group Price</th>
             <th>Price Method</th>
             <th>Quantity</th>
         </tr>
         </thead>
         <tbody>';
     $t_def = $dbc->tableDefinition('batchList');
     $prodP = $dbc->prepare('
         SELECT brand,
             description
         FROM products
         WHERE upc=?');
     foreach ($list->find('listID', true) as $item) {
         if (!isset($t_def['groupSalePrice']) || $item->groupSalePrice() == null) {
             $item->groupSalePrice($item->salePrice());
         }
         $prod = $dbc->getRow($prodP, array($item->upc()));
         $ret .= $this->printRow($item);
     }
     $ret .= '</tbody></table>
         <p>
             <button type="submit" class="btn btn-default">Save</button>
         </p>
         </form>';
     $this->addScript('../../src/javascript/tablesorter/jquery.tablesorter.min.js');
     $this->addOnloadCommand("\$('.tablesorter').tablesorter();");
     $this->addOnloadCommand("\$('.table input.form-control:first').focus();\n");
     return $ret;
 }
Пример #3
0
 public function get_id_view()
 {
     $dbc = $this->connection;
     $date = FormLib::get('date', false);
     $args = array($this->id);
     if ($date) {
         $this->itemQ .= ' AND r.reviewDate BETWEEN ? AND ?';
         $args[] = $date . ' 00:00:00';
         $args[] = $date . ' 23:59:59';
     }
     $itemP = $dbc->prepare($this->itemQ);
     $itemR = $dbc->execute($itemP, $args);
     if ($dbc->numRows($itemR) == 0) {
         return '<div class="alert alert-warning">No applicable items</div>' . $this->get_view();
     }
     $typeID = $this->getBatchType();
     if ($typeID === false) {
         return '<div class="alert alert-danger">Cannot create a price change batch</div>' . $this->get_view();
     }
     $batch = new BatchesModel($dbc);
     $batch->batchName('EDLP Price Change');
     $yesterday = date('Y-m-d', strtotime('yesterday'));
     $batch->startDate($yesterday);
     $batch->endDate($yesterday);
     $batch->batchType($typeID);
     $batch->discountType(0);
     $batchID = $batch->save();
     $list = new BatchListModel($dbc);
     $list->batchID($batchID);
     while ($itemW = $dbc->fetchRow($itemR)) {
         $list->upc($itemW['upc']);
         $list->salePrice($itemW['maxPrice']);
         $list->save();
     }
     return sprintf('<div class="alert alert-success">Created Batch. 
         <a href="../newbatch/EditBatchPage.php?id=%d">View it</a>.</div>', $batchID) . $this->get_view();
 }
Пример #4
0
 public function post_upc_price_batchID_mult_handler()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $added = 0;
     $batchList = new BatchListModel($dbc);
     for ($i = 0; $i < count($this->batchID); $i++) {
         if ($this->batchID[$i] == '') {
             continue;
         }
         if (!isset($this->upc[$i]) || !isset($this->price[$i])) {
             continue;
         }
         $batchList->salePrice($this->price[$i]);
         $batchList->batchID($this->batchID[$i]);
         $batchList->upc(BarcodeLib::padUPC($this->upc[$i]));
         $batchList->signMultiplier($this->mult[$i]);
         if ($batchList->save()) {
             $added++;
         }
     }
     header('Location: ?added=' . $added);
     return false;
 }
Пример #5
0
 /**
   Create a one-item sale. Requires sample data
   for item, batch types
 */
 public function unitTest($phpunit)
 {
     $this->u = array('0001878777132');
     //14.99
     $this->post_u_handler();
     $phpunit->assertEquals(1, count($this->upcs));
     $post = $this->post_u_view();
     $phpunit->assertNotEquals(0, strlen($post));
     $form = new \COREPOS\common\mvc\ValueContainer();
     $form->upc = $this->u;
     $form->preferredVendor = 0;
     $this->setForm($form);
     ob_start();
     $this->post_redoSRPs_handler();
     $json = ob_get_clean();
     $arr = json_decode($json, true);
     $phpunit->assertInternalType('array', $arr);
     $phpunit->assertEquals(1, count($arr));
     $phpunit->assertEquals($this->u[0], $arr[0]['upc']);
     $phpunit->assertEquals(0, $arr[0]['srp']);
     $form->startDate = date('Y-m-d');
     $form->endDate = date('Y-m-d');
     $form->batchName = 'Test BatchFromSearch';
     $form->batchType = 3;
     // price change batch means tags get created
     $form->batchOwner = 'IT';
     $form->price = array(1.99);
     $form->tagset = 1;
     $this->setForm($form);
     $this->post_createBatch_handler();
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $batch = new BatchesModel($dbc);
     $batch->batchName('Test BatchFromSearch');
     $phpunit->assertEquals(1, count($batch->find()));
     $sale = new BatchListModel($dbc);
     $sale->upc($this->u[0]);
     $sale->salePrice(1.99);
     $phpunit->assertEquals(1, count($sale->find()));
     $tag = new ShelftagsModel($dbc);
     $tag->id(1);
     $tag->upc($this->u[0]);
     $phpunit->assertEquals(true, $tag->load());
 }
Пример #6
0
 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;
 }
Пример #7
0
        /* 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']);
        $tag->pricePerUnit($info['pricePerUnit']);
        $tag->save();
        break;
    case 'batchDel':
        $vid = FormLib::get_form_value('vendorID');
        $bid = FormLib::get_form_value('batchID');
        $sid = FormLib::get_form_value('queueID', 0);
        if ($sid == 99) {
            $sid = 0;
        }
        $model = new BatchListModel($dbc);
        $model->batchID($bid);
        $model->upc($upc);
        $model->delete();
        $tag = new ShelftagsModel($dbc);
        $tag->id($sid);
        $tag->upc($upc);
        $tag->delete();
        break;
}
Пример #8
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;
 }
Пример #9
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;
 }
Пример #10
0
 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;
 }
Пример #11
0
 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;
 }
Пример #12
0
 public function get_id_view()
 {
     $this->addScript('pricing-batch.js');
     $dbc = $this->connection;
     $dbc->selectDB($this->config->OP_DB);
     $superID = FormLib::get_form_value('super', 99);
     $queueID = FormLib::get('queueID');
     $vendorID = $this->id;
     $filter = FormLib::get_form_value('filter') == 'Yes' ? True : False;
     /* lookup vendor and superdept names to build a batch name */
     $sname = "All";
     if ($superID != 99) {
         $smodel = new SuperDeptNamesModel($dbc);
         $smodel->superID($superID);
         $smodel->load();
         $sname = $smodel->super_name();
     }
     $vendor = new VendorsModel($dbc);
     $vendor->vendorID($vendorID);
     $vendor->load();
     $batchName = $sname . " " . $vendor->vendorName() . " PC " . date('m/d/y');
     /* find a price change batch type */
     $types = new BatchTypeModel($dbc);
     $types->discType(0);
     $bType = 0;
     foreach ($types->find() as $obj) {
         $bType = $obj->batchTypeID();
         break;
     }
     /* get the ID of the current batch. Create it if needed. */
     $bidQ = $dbc->prepare("\n            SELECT batchID \n            FROM batches \n            WHERE batchName=? \n                AND batchType=? \n                AND discounttype=0\n            ORDER BY batchID DESC");
     $bidR = $dbc->execute($bidQ, array($batchName, $bType));
     $batchID = 0;
     if ($dbc->numRows($bidR) == 0) {
         $b = new BatchesModel($dbc);
         $b->batchName($batchName);
         $b->startDate('1900-01-01');
         $b->endDate('1900-01-01');
         $b->batchType($bType);
         $b->discountType(0);
         $b->priority(0);
         $batchID = $b->save();
     } else {
         $bidW = $dbc->fetchRow($bidR);
         $batchID = $bidW['batchID'];
     }
     $ret = sprintf('<b>Batch</b>: 
                 <a href="%sbatches/newbatch/BatchManagementTool.php?startAt=%d">%s</a>', $this->config->URL, $batchID, $batchName);
     $ret .= sprintf("<input type=hidden id=vendorID value=%d />\n            <input type=hidden id=batchID value=%d />\n            <input type=hidden id=queueID value=%d />\n            <input type=hidden id=superID value=%d />", $vendorID, $batchID, $queueID, $superID);
     $batchUPCs = array();
     $batchList = new BatchListModel($dbc);
     $batchList->batchID($batchID);
     foreach ($batchList->find() as $obj) {
         $batchUPCs[$obj->upc()] = true;
     }
     $costSQL = Margin::adjustedCostSQL('v.cost', 'b.discountRate', 'b.shippingMarkup');
     $marginSQL = Margin::toMarginSQL($costSQL, 'p.normal_price');
     $p_def = $dbc->tableDefinition('products');
     $marginCase = '
         CASE 
             WHEN g.margin IS NOT NULL AND g.margin <> 0 THEN g.margin
             WHEN s.margin IS NOT NULL AND s.margin <> 0 THEN s.margin
             ELSE d.margin
         END';
     $srpSQL = Margin::toPriceSQL($costSQL, $marginCase);
     $query = "SELECT p.upc,\n            p.description,\n            v.cost,\n            b.shippingMarkup,\n            b.discountRate,\n            p.normal_price,\n            " . Margin::toMarginSQL($costSQL, 'p.normal_price') . " AS current_margin,\n            " . Margin::toMarginSQL($costSQL, 'v.srp') . " AS desired_margin,\n            " . $costSQL . " AS adjusted_cost,\n            v.srp,\n            " . $srpSQL . " AS rawSRP,\n            v.vendorDept,\n            x.variable_pricing,\n            " . $marginCase . " AS margin\n            FROM products AS p \n                INNER JOIN vendorItems AS v ON p.upc=v.upc AND p.default_vendor_id=v.vendorID\n                INNER JOIN vendors as b ON v.vendorID=b.vendorID\n                LEFT JOIN departments AS d ON p.department=d.dept_no\n                LEFT JOIN vendorDepartments AS s ON v.vendorDept=s.deptID AND v.vendorID=s.vendorID\n                LEFT JOIN VendorSpecificMargins AS g ON p.department=g.deptID AND v.vendorID=g.vendorID\n                LEFT JOIN prodExtra AS x on p.upc=x.upc ";
     $args = array($vendorID);
     if ($superID != 99) {
         $query .= " LEFT JOIN MasterSuperDepts AS m\n                ON p.department=m.dept_ID ";
     }
     $query .= "WHERE v.cost > 0 \n                    AND v.vendorID=?\n                    AND p.inUse=1 ";
     if ($superID != 99) {
         $query .= " AND m.superID=? ";
         $args[] = $superID;
     }
     if ($filter === false) {
         $query .= " AND p.normal_price <> v.srp ";
     }
     if ($this->config->get('STORE_MODE') == 'HQ') {
         $query .= ' AND p.store_id=? ';
         $args[] = $this->config->get('STORE_ID');
     }
     $query .= " ORDER BY p.upc";
     if (isset($p_def['price_rule_id'])) {
         $query = str_replace('x.variable_pricing', 'p.price_rule_id AS variable_pricing', $query);
     }
     $prep = $dbc->prepare_statement($query);
     $result = $dbc->exec_statement($prep, $args);
     $ret .= "<table class=\"table table-bordered small\">";
     $ret .= "<tr><td colspan=6>&nbsp;</td><th colspan=2>Current</th>\n            <th colspan=3>Vendor</th></tr>";
     $ret .= "<tr><th>UPC</th><th>Our Description</th>\n            <th>Base Cost</th>\n            <th>Shipping</th>\n            <th>Discount%</th>\n            <th>Adj. Cost</th>\n            <th>Price</th><th>Margin</th><th>Raw</th><th>SRP</th>\n            <th>Margin</th><th>Cat</th><th>Var</th>\n            <th>Batch</th></tr>";
     while ($row = $dbc->fetch_row($result)) {
         $background = "white";
         if (isset($batchUPCs[$row['upc']])) {
             $background = 'selection';
         } elseif ($row['variable_pricing'] == 0) {
             $background = $row['normal_price'] + 0.1 < $row['rawSRP'] ? 'red' : 'green';
             if ($row['normal_price'] - 0.1 > $row['rawSRP']) {
                 $background = $row['normal_price'] - 0.1 > $row['rawSRP'] ? 'yellow' : 'green';
             }
         }
         if (isset($batchUPCs[$row['upc']])) {
             $icon = '<span class="glyphicon glyphicon-minus-sign"
                 title="Remove from batch">
                 </span>';
         } else {
             $icon = '<span class="glyphicon glyphicon-plus-sign"
                 title="Add to batch">
                 </span>';
         }
         $ret .= sprintf("<tr id=row%s class=%s>\n                <td class=\"sub\"><a href=\"%sitem/ItemEditorPage.php?searchupc=%s\">%s</a></td>\n                <td class=\"sub\">%s</td>\n                <td class=\"sub cost\">%.2f</td>\n                <td class=\"sub shipping\">%.2f%%</td>\n                <td class=\"sub discount\">%.2f%%</td>\n                <td class=\"sub adj-cost\">%.2f</td>\n                <td class=\"sub price\">%.2f</td>\n                <td class=\"sub cmargin\">%.2f%%</td>\n                <td class=\"sub raw-srp\">%.2f</td>\n                <td onclick=\"reprice('%s');\" class=\"sub srp\">%.2f</td>\n                <td class=\"sub dmargin\">%.2f%%</td>\n                <td class=\"sub\">%d</td>\n                <td><input class=varp type=checkbox onclick=\"toggleV('%s');\" %s /></td>\n                <td class=white>\n                    <a class=\"add-button %s\" href=\"\" \n                        onclick=\"addToBatch('%s'); return false;\">\n                        <span class=\"glyphicon glyphicon-plus-sign\"\n                            title=\"Add item to batch\"></span>\n                    </a>\n                    <a class=\"remove-button %s\" href=\"\" \n                        onclick=\"removeFromBatch('%s'); return false;\">\n                        <span class=\"glyphicon glyphicon-minus-sign\"\n                            title=\"Remove item from batch\"></span>\n                    </a>\n                </td>\n                </tr>", $row['upc'], $background, $this->config->URL, $row['upc'], $row['upc'], $row['description'], $row['cost'], $row['shippingMarkup'] * 100, $row['discountRate'] * 100, $row['adjusted_cost'], $row['normal_price'], 100 * $row['current_margin'], $row['rawSRP'], $row['upc'], $row['srp'], 100 * $row['desired_margin'], $row['vendorDept'], $row['upc'], $row['variable_pricing'] >= 1 ? 'checked' : '', isset($batchUPCs[$row['upc']]) ? 'collapse' : '', $row['upc'], !isset($batchUPCs[$row['upc']]) ? 'collapse' : '', $row['upc']);
     }
     $ret .= "</table>";
     return $ret;
 }