public function fetch_report_data() { $dbc = $this->connection; $dbc->selectDB($this->config->get('OP_DB')); if (!is_array($this->form->ids)) { $this->form->ids = array($this->form->ids); } $data = array(); $model = new BatchesModel($dbc); foreach ($this->form->ids as $batchID) { $model->batchID($batchID); if ($model->load() === false) { continue; } list($start, $time) = explode(' ', $model->startDate(), 2); list($end, $time) = explode(' ', $model->endDate(), 2); $dlog = DTransactionsModel::selectDlog($start, $end); $q = "SELECT MIN(tdate) as weekStart, MAX(tdate) as weekEnd,\n batchName, sum(total) as sales, sum(d.quantity) as qty\n FROM {$dlog} AS d INNER JOIN\n batchList AS l ON l.upc=d.upc\n LEFT JOIN batches AS b ON l.batchID=b.batchID\n WHERE l.batchID = ?\n AND d.tdate BETWEEN ? AND ?\n GROUP BY " . $dbc->week('tdate') . ", batchName\n ORDER BY batchName, MIN(tdate)"; $p = $dbc->prepare_statement($q); $r = $dbc->exec_statement($p, array($batchID, $start . ' 00:00:00', $end . ' 23:59:59')); while ($w = $dbc->fetch_row($r)) { list($s, $time) = explode(' ', $w['weekStart'], 2); list($e, $time) = explode(' ', $w['weekEnd'], 2); $record = array($s, $e, $w['batchName'], sprintf('%.2f', $w['qty']), sprintf('%.2f', $w['sales'])); $data[] = $record; } } return $data; }
break; case 'addItemUPC': $id = $_GET['id']; $upc = str_pad($_GET['upc'], 13, '0', STR_PAD_LEFT); $newupc = fixBarcode($upc); $tag = false; if ($_GET['tag'] == 'true') { $tag = true; } $testQ = $sql->prepare("select * from products where upc=?"); $testR = $sql->execute($testQ, array($newupc)); if ($sql->num_rows($testR) > 0) { $upc = $newupc; } $batch = new BatchesModel($dbc); $batch->batchID($id); $batch->load(); $overlapP = $sql->prepare(' SELECT b.batchName, b.startDate, b.endDate FROM batchList AS l INNER JOIN batches AS b ON l.batchID=b.batchID WHERE l.batchID <> ? AND l.upc = ? AND ? <= b.endDate AND ? >= b.startDate AND b.discounttype <> 0 AND b.endDate >= ' . $sql->curdate()); $args = array($id, $upc, date('Y-m-d', strtotime($batch->startDate())), date('Y-m-d', strtotime($batch->endDate()))); $overlapR = $sql->execute($overlapP, $args);
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; }
/** 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)); } }
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(); } } } }
protected function showBatchDisplay($id, $order = 'natural') { global $FANNIE_SERVER_DBMS, $FANNIE_URL; $dbc = $this->connection; $uid = getUID($this->current_user); $uid = ltrim($uid, '0'); $orderby = ''; switch ($order) { case 'upc_a': $orderby = 'ORDER BY b.upc ASC'; break; case 'upc_d': $orderby = 'ORDER BY b.upc DESC'; break; case 'desc_a': $orderby = 'ORDER BY description ASC'; break; case 'desc_d': $orderby = 'ORDER BY description DESC'; break; case 'price_a': $orderby = 'ORDER BY p.normal_price ASC'; break; case 'price_d': $orderby = 'ORDER BY p.normal_price DESC'; break; case 'sale_a': $orderby = 'ORDER BY b.salePrice ASC'; break; case 'sale_d': $orderby = 'ORDER BY b.salePrice DESC'; break; case 'loc_a': $orderby = 'ORDER BY m.super_name,y.subsection,y.shelf_set,y.shelf'; break; case 'loc_d': $orderby = 'ORDER BY m.super_name DESC,y.subsection DESC,y.shelf_set DESC,y.shelf DESC'; break; case 'brand_a': $orderby = 'ORDER BY p.brand ASC'; break; case 'brand_d': $orderby = 'ORDER BY p.brand DESC'; break; case 'natural': default: $orderby = 'ORDER BY b.listID DESC'; break; } $model = new BatchesModel($dbc); $model->batchID($id); $model->load(); $name = $model->batchName(); $type = $model->batchType(); $dtype = $model->discountType(); $start = strtotime($model->startDate()); $end = strtotime($model->endDate()) + 60 * 60 * 24; $typeModel = new BatchTypeModel($dbc); $typeModel->batchTypeID($type); $typeModel->load(); if ($typeModel->editorUI() == 2) { return $this->showPairedBatchDisplay($id, $name); } $limit = $model->transLimit(); $hasLimit = $limit > 0 ? true : false; $saleHeader = "Sale Price"; if ($dtype == 3) { $saleHeader = "\$ Discount"; } elseif ($dtype == 4) { $saleHeader = "% Discount"; } elseif ($dtype == 0) { $saleHeader = "New price"; } $fetchArgs = array(); $fetchQ = "\n SELECT b.upc,\n CASE \n WHEN l.likeCode IS NULL THEN p.description\n ELSE l.likeCodeDesc \n END AS description,\n p.normal_price,\n b.salePrice,\n CASE WHEN c.upc IS NULL then 0 ELSE 1 END as isCut,\n b.quantity,\n b.pricemethod,\n m.super_name, \n y.subsection, \n y.shelf_set, \n y.shelf,\n p.brand\n FROM batchList AS b \n " . DTrans::joinProducts('b') . "\n LEFT JOIN likeCodes AS l ON b.upc = CONCAT('LC',CONVERT(l.likeCode,CHAR))\n LEFT JOIN batchCutPaste AS c ON b.upc=c.upc AND b.batchID=c.batchID\n LEFT JOIN prodPhysicalLocation AS y ON b.upc=y.upc\n LEFT JOIN superDeptNames AS m ON y.section=m.superID\n WHERE b.batchID = ? \n {$orderby}"; $fetchArgs[] = $id; if ($dbc->dbms_name() == "mssql") { $fetchQ = "select b.upc,\n case when l.likecode is null then p.description\n else l.likecodedesc end as description,\n p.normal_price,b.salePrice,\n CASE WHEN c.upc IS NULL then 0 ELSE 1 END as isCut,\n b.quantity,b.pricemethod\n from batchList as b \n " . DTrans::joinProducts('b') . "\n left join likeCodes as l on\n b.upc = 'LC'+convert(varchar,l.likecode)\n left join batchCutPaste as c ON\n b.upc=c.upc AND b.batchID=c.batchID\n where b.batchID = ? {$orderby}"; } $sections = array(); if ($dbc->tableExists('FloorSections')) { $floor = new FloorSectionsModel($dbc); foreach ($floor->find() as $f) { $sections[$f->floorSectionID()] = $f->name(); } $fetchQ = str_replace('y.subsection', 'y.floorSectionID', $fetchQ); } $fetchP = $dbc->prepare_statement($fetchQ); $fetchR = $dbc->exec_statement($fetchP, $fetchArgs); $overlapP = $dbc->prepare(' SELECT b.batchID, b.batchName FROM batchList as l INNER JOIN batches AS b ON b.batchID=l.batchID WHERE l.upc=? AND l.batchID <> ? AND b.discounttype <> 0 AND ( (b.startDate BETWEEN ? AND ?) OR (b.endDate BETWEEN ? AND ?) ) '); $overlap_args = array($model->startDate(), $model->endDate(), $model->startDate(), $model->endDate()); $cpCount = $dbc->prepare_statement("SELECT count(*) FROM batchCutPaste WHERE uid=?"); $res = $dbc->exec_statement($cpCount, array($uid)); $row = $dbc->fetch_row($res); $cpCount = $row[0]; $ret = "<span class=\"newBatchBlack\"><b>Batch name</b>: {$name}</span> | "; $ret .= '<b>Sale Dates</b>: ' . date('Y-m-d', strtotime($model->startDate())) . ' - ' . date('Y-m-d', strtotime($model->endDate())) . '<br />'; if ($this->config->get('STORE_MODE') === 'HQ') { $stores = new StoresModel($dbc); $mapP = $dbc->prepare('SELECT storeID FROM StoreBatchMap WHERE storeID=? AND batchID=?'); foreach ($stores->find('storeID') as $s) { $mapR = $dbc->execute($mapP, array($s->storeID(), $id)); $checked = $mapR && $dbc->numRows($mapR) ? 'checked' : ''; $ret .= sprintf('<label> <input type="checkbox" onchange="toggleStore(%d, %d);" %s /> %s </label> | ', $s->storeID(), $id, $checked, $s->description()); } $ret .= '<br />'; } $ret .= "<a href=\"BatchListPage.php\">Back to batch list</a> | "; $ret .= sprintf('<input type="hidden" id="batch-discount-type" value="%d" />', $model->discountType()); /** Price change batches probably want the upcoming retail rather than the current retail. Current sales will want the current sale price; future sales will want the future sale price. Past sales probably won't print signs under normal circumstances. */ $future_mode = false; if ($model->discountType() == 0) { $future_mode = true; } elseif (strtotime($model->startDate()) >= strtotime(mktime(0, 0, 0, date('n'), date('j'), date('Y')))) { $future_mode = true; } $ret .= sprintf('<input type="hidden" id="batch-future-mode" value="%d" />', $future_mode ? 1 : 0); $ret .= "<a href=\"../../admin/labels/SignFromSearch.php?batch={$id}\">Print Sale Signs</a> | "; $ret .= "<a href=\"BatchSignStylesPage.php?id={$id}\">Sign Pricing</a> | "; $ret .= "<a href=\"{$FANNIE_URL}admin/labels/BatchShelfTags.php?batchID%5B%5D={$id}\">Print Shelf Tags</a> | "; $ret .= "<a href=\"\" onclick=\"generateTags({$id}); return false;\">Auto-tag</a> | "; if ($cpCount > 0) { $ret .= "<a href=\"EditBatchPage.php?id={$id}&paste=1\">Paste Items ({$cpCount})</a> | "; } if ($dtype == 0 || time() >= $start && time() <= $end) { $ret .= "<a href=\"\" onclick=\"forceNow({$id}); return false;\">Force batch</a> | "; } if ($dtype != 0) { $ret .= "<a href=\"\" onclick=\"unsaleNow({$id}); return false;\">Stop Sale</a> "; } if ($dtype == 0) { $ret .= " <a href=\"\" onclick=\"trimPcBatch({$id}); return false;\">Trim Unchanged</a> "; } else { $ret .= " | <span id=\"edit-limit-link\"><a href=\"\" \n onclick=\"editTransLimit(); return false;\">" . ($hasLimit ? 'Edit' : 'Add') . " Limit</a></span>"; $ret .= "<span id=\"save-limit-link\" class=\"collapse\"><a href=\"\" onclick=\"saveTransLimit({$id}); return false;\">Save Limit</a></span>"; $ret .= " <span class=\"form-group form-inline\" id=\"currentLimit\" style=\"color:#000;\">{$limit}</span>"; } $ret .= "<br />"; $ret .= "<table id=yeoldetable class=\"table\">"; $ret .= "<tr>"; if ($orderby != "ORDER BY b.upc ASC") { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=upc_a\">UPC</a></th>"; } else { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=upc_d\">UPC</a></th>"; } if ($orderby != "ORDER BY p.brand ASC") { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=brand_a\">Brand</a></th>"; } else { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=brand_d\">Brand</a></th>"; } if ($orderby != "ORDER BY description ASC") { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=desc_a\">Description</a></th>"; } else { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=desc_d\">Description</a></th>"; } if ($orderby != "ORDER BY p.normal_price DESC") { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=price_d\">Normal Price</a></th>"; } else { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=price_a\">Normal Price</a></th>"; } if ($orderby != "ORDER BY b.salePrice DESC") { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=sale_d\">{$saleHeader}</a></th>"; } else { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=sale_a\">{$saleHeader}</a></th>"; } $ret .= "<th colspan=\"3\"> </th>"; if ($orderby != 'ORDER BY m.super_name,y.subsection,y.shelf_set,y.shelf') { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=loc_a\">Location</a></th>"; } else { $ret .= "<th><a href=\"EditBatchPage.php?id={$id}&sort=loc_d\">Location</a></th>"; } $ret .= "</tr>"; $colors = array('#ffffff', '#ffffcc'); $cur = 0; while ($fetchW = $dbc->fetch_array($fetchR)) { $cur = ($cur + 1) % 2; $ret .= "<tr>"; $fetchW['upc'] = rtrim($fetchW['upc']); if (substr($fetchW['upc'], 0, 2) == "LC") { $likecode = rtrim(substr($fetchW['upc'], 2)); $ret .= "<td bgcolor={$colors[$cur]}>" . $fetchW['upc']; $ret .= " <a href=\"\" onclick=\"\$('.lc-item-{$likecode}').toggle(); return false;\">[+]</a>"; $ret .= "</td>"; } else { $conflict = ''; if ($dtype != 0) { $overlapR = $dbc->execute($overlapP, array_merge(array($fetchW['upc'], $id), $overlap_args)); if ($overlapR && $dbc->numRows($overlapR)) { $overlap = $dbc->fetchRow($overlapR); $conflict = sprintf('<a href="EditBatchPage.php?id=%d" target="_batch%d" title="Conflicts with batch %s" class="btn btn-xs btn-danger"> <span class="glyphicon glyphicon-exclamation-sign"> </span></a>', $overlap['batchID'], $overlap['batchID'], $overlap['batchName']); } } $ret .= "<td bgcolor={$colors[$cur]}><a href=\"{$FANNIE_URL}item/ItemEditorPage.php?searchupc={$fetchW['upc']}\" \n target=\"_new{$fetchW['upc']}\">{$fetchW['upc']}</a>{$conflict}</td>"; } $ret .= "<td bgcolor={$colors[$cur]}>{$fetchW['brand']}</td>"; $ret .= "<td bgcolor={$colors[$cur]}>{$fetchW['description']}</td>"; $ret .= "<td bgcolor={$colors[$cur]}>{$fetchW['normal_price']}</td>"; $qtystr = $fetchW['pricemethod'] > 0 && is_numeric($fetchW['quantity']) && $fetchW['quantity'] > 0 ? $fetchW['quantity'] . " for " : ""; $qty = is_numeric($fetchW['quantity']) && $fetchW['quantity'] > 0 ? $fetchW['quantity'] : 1; $ret .= "<td bgcolor={$colors[$cur]} class=\"\">"; $ret .= '<span id="editable-text-' . $fetchW['upc'] . '">'; $ret .= '<span class="editable-' . $fetchW['upc'] . ($qty == 1 ? ' collapse ' : '') . '"' . ' id="item-qty-' . $fetchW['upc'] . '" data-name="qty">' . $qty . ' for </span>'; $ret .= "<span class=\"editable-{$fetchW['upc']}\" \n id=\"sale-price-{$fetchW['upc']}\" data-name=\"price\">" . sprintf("%.2f</span>", $fetchW['salePrice']); $ret .= '</span>'; $ret .= '<div class="form-group form-inline collapse" id="editable-fields-' . $fetchW['upc'] . '">'; $ret .= '<div class="input-group">'; $ret .= sprintf('<input type="text" class="form-control" name="qty" value="%d" />', $qty); $ret .= '<span class="input-group-addon">for</span>'; $ret .= '<span class="input-group-addon">$</span>'; $ret .= sprintf('<input text="text" class="form-control" name="price" value="%.2f" />', $fetchW['salePrice']); $ret .= '</div></div></td>'; $ret .= "<td bgcolor={$colors[$cur]} id=editLink{$fetchW['upc']}>\n <a href=\"\" class=\"edit\" onclick=\"editUpcPrice('{$fetchW['upc']}'); return false;\">\n " . \COREPOS\Fannie\API\lib\FannieUI::editIcon() . "</a>\n <a href=\"\" class=\"save collapse\" onclick=\"saveUpcPrice('{$fetchW['upc']}'); return false;\">\n " . \COREPOS\Fannie\API\lib\FannieUI::saveIcon() . "</a>\n </td>"; $ret .= "<td bgcolor={$colors[$cur]}><a href=\"\" \n onclick=\"deleteUPC.call(this, {$id}, '{$fetchW['upc']}'); return false;\">" . \COREPOS\Fannie\API\lib\FannieUI::deleteIcon() . "</a>\n </td>"; if ($fetchW['isCut'] == 1) { $ret .= "<td bgcolor={$colors[$cur]} id=cpLink{$fetchW['upc']}>\n <a href=\"\" id=\"unCut{$fetchW['upc']}\" onclick=\"cutItem('{$fetchW['upc']}',{$id},{$uid}, 0); return false;\">Undo</a>\n <a href=\"\" class=\"collapse\" id=\"doCut{$fetchW['upc']}\" onclick=\"cutItem('{$fetchW['upc']}',{$id},{$uid}, 1); return false;\">Cut</a>\n </td>"; } else { $ret .= "<td bgcolor={$colors[$cur]} id=cpLink{$fetchW['upc']}>\n <a href=\"\" class=\"collapse\" id=\"unCut{$fetchW['upc']}\" onclick=\"cutItem('{$fetchW['upc']}',{$id},{$uid},0); return false;\">Undo</a>\n <a href=\"\" id=\"doCut{$fetchW['upc']}\" onclick=\"cutItem('{$fetchW['upc']}',{$id},{$uid},1); return false;\">Cut</a>\n </td>"; } $loc = 'n/a'; if (!empty($fetchW['subsection'])) { $loc = substr($fetchW['super_name'], 0, 4); $loc .= $fetchW['subsection'] . ', '; $loc .= 'Unit ' . $fetchW['shelf_set'] . ', '; $loc .= 'Shelf ' . $fetchW['shelf']; } elseif (!empty($fetchW['floorSectionID'])) { $loc = $sections[$fetchW['floorSectionID']]; } $ret .= "<td bgcolor={$colors[$cur]}>" . $loc . '</td>'; $ret .= '<input type="hidden" class="batch-hidden-upc" value="' . $fetchW['upc'] . '" />'; $ret .= "</tr>"; if (substr($fetchW['upc'], 0, 2) == "LC") { $likecode = rtrim(substr($fetchW['upc'], 2)); $ret .= self::likeToTable($dbc, $likecode, $fetchW['salePrice']); } } $ret .= "</table>"; $ret .= "<input type=hidden id=currentBatchID value={$id} />"; return $ret; }