function preprocess() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $json = array('error' => ''); $model = new BatchTypeModel($dbc); if (FormLib::get_form_value('saveDesc') !== '') { $model->batchTypeID(FormLib::get('bid')); $model->typeDesc(FormLib::get('saveDesc')); if ($model->save() === false) { $json['error'] = 'Error saving description'; } echo json_encode($json); return false; // ajax call } if (FormLib::get_form_value('saveType') !== '') { $model->batchTypeID(FormLib::get('bid')); $model->discType(FormLib::get('saveType')); if ($model->save() === false) { $json['error'] = 'Error saving sale type'; } echo json_encode($json); return false; // ajax call } if (FormLib::get('saveDated') !== '') { $model->batchTypeID(FormLib::get('bid')); $model->datedSigns(FormLib::get('saveDated')); if ($model->save() === false) { $json['error'] = 'Error saving date setting'; } echo json_encode($json); return false; // ajax call } if (FormLib::get('saveSO') !== '') { $model->batchTypeID(FormLib::get('bid')); $model->specialOrderEligible(FormLib::get('saveSO')); if ($model->save() === false) { $json['error'] = 'Error saving SO eligibility'; } echo json_encode($json); return false; // ajax call } if (FormLib::get('saveUI') !== '') { $model->batchTypeID(FormLib::get('bid')); $model->editorUI(FormLib::get('saveUI')); if ($model->save() === false) { $json['error'] = 'Error saving UI setting'; } echo json_encode($json); return false; // ajax call } if (FormLib::get_form_value('addtype') !== '') { $prep = $dbc->prepare_statement("SELECT MAX(batchTypeID) FROM batchType"); $res = $dbc->exec_statement($prep); $tid = array_pop($dbc->fetch_row($res)); $tid = empty($tid) ? 1 : $tid + 1; $ins = $dbc->prepare_statement("INSERT INTO batchType (batchTypeID,typeDesc,discType)\n VALUES (?,'New Type',1)"); $dbc->exec_statement($ins, array($tid)); } elseif (FormLib::get_form_value('deltype') !== '') { $query = $dbc->prepare_statement("DELETE FROM batchType WHERE batchTypeID=?"); $dbc->exec_statement($query, array(FormLib::get_form_value('bid'))); } return true; }
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; }