Commit 57dde7f6 authored by Malcolm Blaney's avatar Malcolm Blaney

Allow stock items to be hidden from the stock list by giving them

a category of "hidden". Added a help dialog for using import.
parent 3b746cfb
......@@ -23,6 +23,7 @@ php/modules/Registration.php
php/modules/Roster.php
php/modules/Sell.php
php/modules/Slider.php
php/modules/Spark.php
php/modules/Stock.php
php/modules/Summary.php
php/modules/Turner.php
......@@ -52,6 +53,7 @@ js/dobrado.registration.js
js/dobrado.roster.js
js/dobrado.sell.js
js/dobrado.slider.js
js/dobrado.spark.js
js/dobrado.stock.js
js/dobrado.summary.js
js/dobrado.turner.js
......@@ -80,6 +82,7 @@ js/source/dobrado.registration.js
js/source/dobrado.roster.js
js/source/dobrado.sell.js
js/source/dobrado.slider.js
js/source/dobrado.spark.js
js/source/dobrado.stock.js
js/source/dobrado.summary.js
js/source/dobrado.turner.js
......
......@@ -66,6 +66,9 @@ class Stock extends Base {
if ($action == "exportAdjustments") {
return $this->ExportAdjustments();
}
if ($action == "showHidden") {
return $this->AllData(array(), false, true);
}
return array("error" => "Unknown action");
}
......@@ -111,6 +114,21 @@ class Stock extends Base {
'<input id="stock-purchase-available-input" type="checkbox">'.
'</div>';
}
$taxable = $this->Substitute("stock-taxable");
if ($taxable !== "") {
$taxable = '<div class="form-spacing">'.
'<label for="stock-taxable-input">'.
$taxable.':</label>'.
'<input id="stock-taxable-input" type="checkbox">'.
'</div>';
}
$composite = "";
if ($this->Substitute("stock-show-composite") == "true") {
$composite = '<div class="form-spacing">'.
'<label for="stock-composite-input">Composite item:</label>'.
'<input id="stock-composite-input" type="checkbox">'.
'</div>';
}
$quantity = "";
$quantity_dialog = "";
if ($this->Substitute("stock-track-quantity") == "true") {
......@@ -162,6 +180,7 @@ class Stock extends Base {
'<div class="form-spacing">'.
'<label for="stock-import-file">Import:</label>'.
'<input id="stock-import-file" type="file" size="15">'.
'<div class="stock-import-help" title="help"></div>'.
'</div>'.
'<div class="form-spacing">'.
'<label for="stock-user-input">Supplier:</label>'.
......@@ -217,15 +236,7 @@ class Stock extends Base {
'Available from suppliers:</label>'.
'<input id="stock-supplier-available-input" type="checkbox">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="stock-taxable-input">'.
$this->Substitute("stock-taxable").':</label>'.
'<input id="stock-taxable-input" type="checkbox">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="stock-composite-input">Composite item:</label>'.
'<input id="stock-composite-input" type="checkbox">'.
'</div>'.
$taxable.$composite.
'<button class="submit">submit</button>'.
'<button class="remove">remove</button>'.
'</form>'.
......@@ -236,6 +247,10 @@ class Stock extends Base {
'show products with alternative</button>'.
'<button class="stock-export-available">export available</button>'.
'<button class="stock-export-all">export all</button>'.
'<button class="stock-show-hidden">show hidden</button>'.
'</div>'.
'<div class="stock-import-info">'.
$this->Substitute("stock-import-info").
'</div>'.
$quantity_dialog;
}
......@@ -373,9 +388,55 @@ class Stock extends Base {
if (!$mysqli->query($query)) {
$this->Log("Stock->Install 5: ".$mysqli->error);
}
$us_info = '<p><b>Using Import</b><br><br>To use the import function you '.
'first need to have created accounts for each of your suppliers. If you '.
'haven\'t done that, you can create them using the <b>add supplier</b> '.
'button in the form. Then, browse for the file you want to import. Once '.
'you\'ve successfully imported your file, the grid will show you '.
'products that have become available. This will be the full list the '.
'first time you import a file for a supplier, but usually only a few '.
'products change their availability week to week. You can return to the '.
'full list of products by clicking the <b>show all</b> button.</p>'.
'<p><b>Availability</b><br><br>Next you can update if any products '.
'should be made available to your members. You can hold down '.
'<b>shift</b> or <b>ctrl</b> to select multiple items, then use the '.
'availability check boxes in the form to update their status. When '.
'changing multiple items at once, only the fields in the form that you '.
'enter values for will be updated. The rest will keep the existing '.
'values for each item.</p>'.
'<p><b>Hidden Products</b><br><br>Sometimes the availability lists from '.
'suppliers contain more products than you\'re interested in. You can '.
'hide these products by giving them a category of <b>hidden</b>. You '.
'can always access them again later by clicking the '.
'<b>show hidden</b> button.</p>'.
'<p><b>Alternatives</b><br><br>Products with alternative pack sizes and '.
'prices can be listed in the import file (they must be on consecutive '.
'lines). These products can be listed separately by clicking the '.
'<b>show products with alternative</b> button. You can then switch '.
'between the two options by clicking the <b>alternative</b> button '.
'in the form, next to Pack Size. Your preferred values will be saved, '.
'along with any other changes you\'ve made to the product, when you '.
'click submit.</p>'.
'<p><b>File Types</b><br><br>For those wanting to know more about the '.
'file types used when importing, there are two different formats '.
'available. One is for products from a single supplier, the other '.
'contains products from multiple suppliers. The format for the first '.
'file is <i>comma separated values</i> with the first entry being the '.
'header row:<br>Product,Description,Quantity,Pack Size,Unit,Unit Price,'.
'Total,GST,Grower</p>'.
'<p>Note that the supplier is not listed here. When using this format '.
'you pick the username for the supplier <i>before importing</i>.</p>'.
'<p>The second import format is also <i>csv</i>, however since it '.
'contains the usernames of your suppliers, you don\'t need to select a '.
'username in the form when importing. To see the format required, you '.
'can use the export button on the page.</p>'.
$template = array('"stock-taxable","","Attracts GST"',
'"stock-import-info","",'.
'"'.$mysqli->escape_string($us_info).'"');
$mysqli->close();
$template = array('"stock-taxable","","Attracts GST"');
$this->AddTemplate($template);
$site_style = array('"","#stock-form","background-color","#eeeeee"',
......@@ -769,7 +830,7 @@ class Stock extends Base {
// Private functions below here ////////////////////////////////////////////
private function AllData($new_available = array(),
$alternatives_only = false) {
$alternatives_only = false, $show_hidden = false) {
$object = array();
$object["wholesalePercent"] =
(float)$this->Substitute("stock-wholesale-percent");
......@@ -783,6 +844,7 @@ class Stock extends Base {
$object["alternative"] = array();
$organiser = new Organiser($this->user, $this->owner);
$group_query = $organiser->GroupQuery();
$hidden_query = $show_hidden ? '' : ' AND category != "hidden"';
$new_count = 0;
foreach ($new_available as $user => $products) {
......@@ -829,7 +891,7 @@ class Stock extends Base {
'wholesale_price, retail_price, category, grower, order_available, '.
'purchase_available, supplier_available, taxable, quantity, composite '.
'FROM stock LEFT JOIN users ON stock.user = users.user WHERE '.
$group_query.' ORDER BY name, user';
$group_query.$hidden_query.' ORDER BY name, user';
if ($result = $mysqli->query($query)) {
while ($stock = $result->fetch_assoc()) {
$name = $stock["name"];
......@@ -1403,14 +1465,15 @@ class Stock extends Base {
$previous_name = $name;
$previous_size = $size;
$previous_price = $base_price;
// Check if this product is newly available.
// Check if this product is newly available and not currently hidden.
if ($supplier_available == "1") {
$query = 'SELECT supplier_available FROM stock_history WHERE '.
'name = "'.$name.'" AND user = "'.$supplier.'" '.
$query = 'SELECT category, supplier_available FROM stock_history '.
'WHERE name = "'.$name.'" AND user = "'.$supplier.'" '.
'ORDER BY timestamp DESC LIMIT 1';
if ($result = $mysqli->query($query)) {
if ($stock = $result->fetch_assoc()) {
if ($stock["supplier_available"] === "0") {
if (strtolower(trim($stock["category"])) !== "hidden" &&
$stock["supplier_available"] === "0") {
if (!isset($new_available[$supplier])) {
$new_available[$supplier] = array();
}
......
This diff is collapsed.
......@@ -87,10 +87,15 @@ if (!this.dobrado.stock) {
$(".stock-list-alternative").button().click(listAlternatives);
$(".stock-export-available").button().click(exportAvailable);
$(".stock-export-all").button().click(exportAll);
$(".stock-show-hidden").button().click(showHidden);
$(".stock-move-link").click(function() {
$(".stock-move").toggle();
$(".stock-adjust").toggle();
});
$(".stock-import-help").button({ icons:
{ primary: "ui-icon-help" }, text: false }).click(function() {
$(".stock-import-info").dialog("open");
});
resetForm();
$(".stock-quantity-dialog").dialog({
......@@ -101,6 +106,14 @@ if (!this.dobrado.stock) {
height: 400
});
$(".stock-import-info").dialog({
autoOpen: false,
position: { my: "top", at: "top+50", of: "body" },
title: "Stock Import Help",
width: 700,
height: 400
});
dobrado.log("Loading stock...", "info");
$.post("/php/request.php", { request: "stock",
action: "list",
......@@ -950,6 +963,7 @@ if (!this.dobrado.stock) {
$(".stock-list-alternative").show();
$(".stock-export-available").show();
$(".stock-export-all").show();
$(".stock-show-hidden").show();
showAll();
}
......@@ -1061,6 +1075,29 @@ if (!this.dobrado.stock) {
});
}
function showHidden() {
dobrado.log("Updating grid...", "info");
$.post("/php/request.php",
{ request: "stock",
action: "showHidden",
url: location.href,
token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, "stock showHidden")) {
return;
}
stock = JSON.parse(response);
updateProducts();
updateNames();
if (stockGrid) {
stockGrid.setData(stock.products);
stockGrid.updateRowCount();
stockGrid.render();
stockGrid.setSelectedRows([]);
}
});
}
function loadImportData() {
importSupplier = "";
importData = [];
......@@ -1123,6 +1160,7 @@ if (!this.dobrado.stock) {
$(".stock-list-alternative").hide();
$(".stock-export-available").hide();
$(".stock-export-all").hide();
$(".stock-show-hidden").hide();
}
if (stockGrid) {
stockGrid.setData(stock.products);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment