Commit ee8eabce authored by Malcolm Blaney's avatar Malcolm Blaney

Added a second availability option to the Stock module, so that

purchasing and ordering can have different availabilities.
parent a88af1f8
......@@ -736,7 +736,7 @@ class Invoice extends Base {
private function SendOrders() {
$stock = new Stock($this->user, $this->owner);
$products = $stock->AvailableProducts(false);
$products = $stock->AvailableProducts(false, false);
$roster = new Roster($this->user, $this->owner);
$purchase = new Purchase($this->user, $this->owner);
......@@ -828,7 +828,7 @@ class Invoice extends Base {
$object = array();
$files = array();
$stock = new Stock($this->user, $this->owner);
$products = $stock->AvailableProducts(false);
$products = $stock->AvailableProducts(false, false);
$purchase = new Purchase($this->user, $this->owner);
$next_week = $purchase->AllData(time(), strtotime("8 days"), false,
......@@ -1081,6 +1081,7 @@ class Invoice extends Base {
}
if ($format == "product") {
sort($message_data);
$message .= join($message_data);
}
......@@ -1315,33 +1316,6 @@ class Invoice extends Base {
$mysqli->close();
}
private function RunGroups($label, $time) {
$run_groups = array();
$mysqli = connect_db();
$query = 'SELECT DISTINCT system_group FROM users';
if ($result = $mysqli->query($query)) {
while ($users = $result->fetch_assoc()) {
$group = $users["system_group"];
$date = $this->Substitute($label, "", "", $group);
if ($date == "") continue;
$timestamp = strtotime("this ".$date." ".$time);
// Give Cron some time to run by checking that the current time
// is within an hour each way of the requested time.
if ($timestamp > strtotime("-1 hour") &&
$timestamp < strtotime("1 hour")) {
$run_groups[] = $group;
}
}
$result->close();
}
else {
$this->Log('Invoice->RunGroups: '.$mysqli->error);
}
$mysqli->close();
return $run_groups;
}
private function RoundPacks($packs) {
// Rounding is a value between zero and one, used to decide if the
// number of packs should be rounded up or down.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -189,7 +189,10 @@ if (!this.dobrado.stock) {
$("#stock-retail-input").val(item.retail);
$("#stock-category-input").val(item.category);
$("#stock-growing-input").val(item.grower);
$("#stock-available-input").prop("checked", item.available === 1);
$("#stock-order-available-input").
prop("checked", item.available === 1);
$("#stock-purchase-available-input").
prop("checked", item.purchaseAvailable === 1);
$("#stock-taxable-input").prop("checked", item.taxable === 1);
return false;
}
......@@ -362,7 +365,8 @@ if (!this.dobrado.stock) {
var retail = $("#stock-retail-input").val();
var category = $("#stock-category-input").val();
var grower = $("#stock-growing-input").val();
var available = $("#stock-available-input:checked").length;
var available = $("#stock-order-available-input:checked").length;
var purchaseAvailable = $("#stock-purchase-available-input:checked").length;
var taxable = $("#stock-taxable-input:checked").length;
var selectedRow = 0;
if ($.inArray(supplier, stock.users) === -1) {
......@@ -388,7 +392,8 @@ if (!this.dobrado.stock) {
retail: retail,
category: category,
grower: grower,
available: available,
orderAvailable: available,
purchaseAvailable: purchaseAvailable,
taxable: taxable,
url: location.href,
token: dobrado.token },
......@@ -406,7 +411,9 @@ if (!this.dobrado.stock) {
size: size, price: price,
wholesale: wholesale, retail: retail,
category: category, grower: grower,
available: available, taxable: taxable };
available: available,
purchaseAvailable: purchaseAvailable,
taxable: taxable };
selectedRow = i;
newItem = false;
// Also update autocomplete in this case.
......@@ -418,7 +425,9 @@ if (!this.dobrado.stock) {
size: size, price: price,
wholesale: wholesale, retail: retail,
category: category, grower: grower,
available: available, taxable: taxable };
available: available,
purchaseAvailable: purchaseAvailable,
taxable: taxable };
selectedRow = i;
newItem = false;
return false;
......@@ -430,6 +439,7 @@ if (!this.dobrado.stock) {
size: size, price: price, wholesale: wholesale,
retail: retail, category: category,
grower: grower, available: available,
purchaseAvailable: purchaseAvailable,
taxable: taxable });
// Can then update the product autocomplete list.
updateProducts();
......@@ -479,7 +489,8 @@ if (!this.dobrado.stock) {
$("#stock-retail-input").val("");
$("#stock-category-input").val("");
$("#stock-growing-input").val("");
$("#stock-available-input").prop("checked", true);
$("#stock-order-available-input").prop("checked", true);
$("#stock-purchase-available-input").prop("checked", true);
$("#stock-taxable-input").prop("checked", false);
currentProduct = null;
if (grid) {
......@@ -758,6 +769,13 @@ if (!this.dobrado.stock) {
$("#stock-available-info").html("<i>Changed from " +
availability + "</i>");
}
// Update availability for purchase here too, which isn't imported.
if (item.purchaseAvailable === 1) {
$("#stock-purchase-available-input").prop("checked", true);
}
else {
$("#stock-purchase-available-input").prop("checked", false);
}
if (item.taxable !== row.taxable) {
changes.product = true;
var tax = "not taxable";
......@@ -833,10 +851,10 @@ if (!this.dobrado.stock) {
}
$("#stock-growing-input").val(row.grower);
if (row.available === 1) {
$("#stock-available-input").prop("checked", true);
$("#stock-order-available-input").prop("checked", true);
}
else {
$("#stock-available-input").prop("checked", false);
$("#stock-order-available-input").prop("checked", false);
}
if (row.taxable === 1) {
$("#stock-taxable-input").prop("checked", true);
......@@ -860,7 +878,7 @@ if (!this.dobrado.stock) {
unit: $("#stock-unit-select").val(),
price: $("#stock-price-input").val(),
grower: $("#stock-growing-input").val(),
available: $("#stock-available-input:checked").length,
available: $("#stock-order-available-input:checked").length,
taxable: $("#stock-taxable-input:checked").length };
var changes = showChanges(data);
......
......@@ -474,6 +474,33 @@ abstract class Base {
return false;
}
protected function RunGroups($label, $time) {
$run_groups = array();
$mysqli = connect_db();
$query = 'SELECT DISTINCT system_group FROM users';
if ($result = $mysqli->query($query)) {
while ($users = $result->fetch_assoc()) {
$group = $users["system_group"];
$date = $this->Substitute($label, "", "", $group);
if ($date == "") continue;
$timestamp = strtotime("this ".$date." ".$time);
// Give Cron some time to run by checking that the current time
// is within an hour each way of the requested time.
if ($timestamp > strtotime("-1 hour") &&
$timestamp < strtotime("1 hour")) {
$run_groups[] = $group;
}
}
$result->close();
}
else {
$this->Log("Base->RunGroups: ".$mysqli->error);
}
$mysqli->close();
return $run_groups;
}
protected function Url($part = "", $page = "") {
$url = "";
if ($page === "") $page = $this->user->page;
......
......@@ -366,8 +366,6 @@ $us_description =
"or off.",
"pre-order-final" => "The day of the week the order is finalised and ".
"order emails are sent out for groups and organisations.",
"stock-taxable" => "The label used for the tax checkbox on the stock ".
"page.",
"pre-order-wait" => "The number of hours before pre-order-final that ".
"users must wait before they can order. Will show a dialog on the ".
"purchase page that can't be closed, showing pre-order-wait-text. ".
......@@ -449,6 +447,15 @@ $us_description =
"on the order.",
"banking-default-group" => "Either 'retail', 'wholesale' or empty to ".
"set which stock price should be used for new members.",
"stock-order-available" => "The string 'true' or 'false', when 'true' ".
"two availability checkboxes are shown on the stock page and the ".
"purchase page will show only items that are available depending on ".
"which mode it is in.",
"stock-order-update" => "When stock-order-available is true, this is ".
"the day when available to purchase is updated from available to ".
"order.",
"stock-taxable" => "The label used for the tax checkbox on the stock ".
"page.",
"stock-wholesale-percent" => "The default percent markup when ".
"automatically setting the wholesale price.",
"stock-retail-percent" => "The default percent markup when ".
......
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