Commit 37d91521 authored by Malcolm Blaney's avatar Malcolm Blaney

Bug in Banking module if buyer group is null. Invoice module don't

send attendance email if not set. Purchase module improvements to
timestamp checking when two computers are used to purchase. Also
keep removed purchases by setting quantity to zero so that their
timestamps can still be used for resolving conflicts. Some js
bugs in Purchase and Stock modules fixed.
parent cc1c8de5
......@@ -280,7 +280,7 @@ class Banking extends Base {
$group = $banking["buyer_group"];
$user_list[] = $user;
// If the buyer_group for a user is empty, the default used is "price".
$buyer_groups[$user] = $group === "" ? "price" : $group;
$buyer_groups[$user] = $group == "" ? "price" : $group;
}
$result->close();
}
......@@ -332,7 +332,7 @@ class Banking extends Base {
$this->Log("Banking->BuyerGroup: ".$mysqli->error);
}
$mysqli->close();
return $buyer_group === "" ? "price" : $buyer_group;
return $buyer_group == "" ? "price" : $buyer_group;
}
public function UpdateUser($username, $reference, $name, $number,
......
......@@ -369,7 +369,6 @@ class Invoice extends Base {
'"invoice-intro-no-orders","","'.$no_orders.'"',
'"invoice-intro-orders","","'.$orders.'"',
'"invoice-attendance-hello","","Hello,"',
'"invoice-attendance-email","","(attendance email)"',
'"invoice-attendance-subject","","Attendance check"',
'"invoice-group-attach-files","","true"',
'"invoice-group-format","","user"',
......@@ -470,12 +469,12 @@ class Invoice extends Base {
if (!$mysqli->query($query)) {
$this->Log("Invoice->Update 12: ".$mysqli->error);
}
$query = 'UPDATE template SET label = "invoice-organisation-stock-cc" '.
$query = 'UPDATE template SET label = "invoice-organisation-cc" '.
'WHERE label = "organisation-stock-cc"';
if (!$mysqli->query($query)) {
$this->Log("Invoice->Update 13: ".$mysqli->error);
}
$query = 'UPDATE template SET label = "invoice-organisation-stock-bcc" '.
$query = 'UPDATE template SET label = "invoice-organisation-bcc" '.
'WHERE label = "organisation-stock-bcc"';
if (!$mysqli->query($query)) {
$this->Log("Invoice->Update 14: ".$mysqli->error);
......@@ -1369,6 +1368,12 @@ class Invoice extends Base {
}
private function LastAttended() {
// Don't do anything if an email address is not configured.
$email = $this->Substitute("invoice-attendance-email");
if ($email === "") {
return array("done" => true);
}
$detail = new Detail($this->user, $this->owner);
$user_details = $detail->AllUsers();
......@@ -1400,7 +1405,6 @@ class Invoice extends Base {
'</body></html>';
$message = wordwrap($message);
$email = $this->Substitute("invoice-attendance-email");
$sender = $this->Substitute("invoice-sender", "/!host/",
$this->user->config->ServerName());
$sender_name = $this->Substitute("invoice-sender-name");
......
This diff is collapsed.
......@@ -171,7 +171,11 @@ class Stock extends Base {
'<label for="stock-import-file">Import File:</label>'.
'<input id="stock-import-file" type="file" size="15">'.
'</div>'.
'<div class="info"></div>'.
'<div class="info"><b>Note</b> that when <i>show all imported</i> '.
'or <i>show existing only</i> filters are selected, all products '.
'for a supplier are <i>set to unavailable</i> before starting '.
'the import.'.
'</div>'.
'</div><hr>'.
'<div class="form-spacing">'.
'<label for="stock-name-input">Product:</label>'.
......
......@@ -184,15 +184,15 @@ currentProduct.grower);}
else{$("#purchase-all-available-grower-info").html("");}
$("#purchase-all-available-quota-info").html(showQuota(false));return false;}});}
function updateAvailablePurchaseData(e,args){var user=$("#purchase-name-input").val();if(user===""){return;}
var item=args.item;var price=parseFloat(item.price);var basePrice=parseFloat(item.basePrice);var updateProduct=null;if(item.quantity>0){$.each(purchase.products,function(index,product){if(product.name===item.name){updateProduct=product;if(product.unit==="variable"){item.quantity=1;}
else if(product.unit==="each"&&/\./.test(item.quantity)){alert("Please note!\n"+"This product is usually purchased in whole quantities.");}
return false;}});update(user,item.name,item.supplier,price,basePrice,item.quantity,item.date,false,true);}
var item=args.item;var price=parseFloat(item.price);var basePrice=parseFloat(item.basePrice);var updateProduct=null;$.each(purchase.products,function(index,product){if(product.name===item.name){updateProduct=product;return false;}});if(item.quantity>0){if(updateProduct.unit==="variable"){item.quantity=1;}
else if(updateProduct.unit==="each"&&/\./.test(item.quantity)){alert("Please note!\n"+"This product is usually purchased in whole quantities.");}
update(user,item.name,item.supplier,price,basePrice,item.quantity,item.date,false,true);}
else{removePurchase(user,item.name,item.date);}
var total=item.quantity*price;args.item.total=total.toFixed(2);if(allAvailableGrid){allAvailableGrid.invalidate();}
currentProduct=updateProduct;$("#purchase-all-available-quota-info").html(showQuota(false));}
function updateUserPurchaseData(e,args){var item=args.item;var price=parseFloat(item.price);var basePrice=parseFloat(item.basePrice);var updateProduct=null;if(item.quantity>0){$.each(purchase.products,function(index,product){if(product.name===item.name){updateProduct=product;if(product.unit==="variable"){item.quantity=1;}
else if(product.unit==="each"&&/\./.test(item.quantity)){alert("Please note!\n"+"This product is usually purchased in whole quantities.");}
return false;}});update(item.user,item.name,item.supplier,price,basePrice,item.quantity,item.date,false,false);}
function updateUserPurchaseData(e,args){var item=args.item;var price=parseFloat(item.price);var basePrice=parseFloat(item.basePrice);var updateProduct=null;$.each(purchase.products,function(index,product){if(product.name===item.name){updateProduct=product;return false;}});if(item.quantity>0){if(updateProduct.unit==="variable"){item.quantity=1;}
else if(updateProduct.unit==="each"&&/\./.test(item.quantity)){alert("Please note!\n"+"This product is usually purchased in whole quantities.");}
update(item.user,item.name,item.supplier,price,basePrice,item.quantity,item.date,false,false);}
else{removePurchase(item.user,item.name,item.date);}
var total=item.quantity*price;args.item.total=total.toFixed(2);if(allUserGrid){allUserChanges[args.row]={user:"grid-row-updated",date:"grid-row-updated",quantity:"grid-row-updated",price:"grid-row-updated",total:"grid-row-updated"};allUserGrid.setCellCssStyles("grid-row-updated",allUserChanges);allUserGrid.invalidate();}
currentProduct=updateProduct;$("#purchase-all-users-quota-info").html(showQuota(true));}})();
\ No newline at end of file
......@@ -1327,21 +1327,21 @@ if (!this.dobrado.purchase) {
var basePrice = parseFloat(item.basePrice);
var updateProduct = null;
$.each(purchase.products, function(index, product) {
if (product.name === item.name) {
updateProduct = product;
return false;
}
});
if (item.quantity > 0) {
// If this product has variable pricing, quantity must be 1.
$.each(purchase.products, function(index, product) {
if (product.name === item.name) {
updateProduct = product;
if (product.unit === "variable") {
item.quantity = 1;
}
else if (product.unit === "each" && /\./.test(item.quantity)) {
alert("Please note!\n" +
"This product is usually purchased in whole quantities.");
}
return false;
}
});
if (updateProduct.unit === "variable") {
item.quantity = 1;
}
else if (updateProduct.unit === "each" && /\./.test(item.quantity)) {
alert("Please note!\n" +
"This product is usually purchased in whole quantities.");
}
update(user, item.name, item.supplier, price, basePrice,
item.quantity, item.date, false, true);
}
......@@ -1365,21 +1365,21 @@ if (!this.dobrado.purchase) {
var basePrice = parseFloat(item.basePrice);
var updateProduct = null;
$.each(purchase.products, function(index, product) {
if (product.name === item.name) {
updateProduct = product;
return false;
}
});
if (item.quantity > 0) {
// If this product has variable pricing, quantity must be 1.
$.each(purchase.products, function(index, product) {
if (product.name === item.name) {
updateProduct = product;
if (product.unit === "variable") {
item.quantity = 1;
}
else if (product.unit === "each" && /\./.test(item.quantity)) {
alert("Please note!\n" +
"This product is usually purchased in whole quantities.");
}
return false;
}
});
if (updateProduct.unit === "variable") {
item.quantity = 1;
}
else if (updateProduct.unit === "each" && /\./.test(item.quantity)) {
alert("Please note!\n" +
"This product is usually purchased in whole quantities.");
}
update(item.user, item.name, item.supplier, price, basePrice,
item.quantity, item.date, false, false);
}
......
This diff is collapsed.
......@@ -396,8 +396,10 @@ if (!this.dobrado.stock) {
function updateSize() {
var size = $("#stock-size-input").val();
if (currentProduct && $.isNumeric(size) && size !== currentProduct.size) {
var newPrice = currentProduct.size / size * currentProduct.price;
var price = $("#stock-price-input").val();
if (currentProduct && $.isNumeric(size) &&
$.isNumeric(price) && size !== currentProduct.size) {
var newPrice = currentProduct.size / size * price;
$("#stock-price-input").val(newPrice.toFixed(2));
}
// Need to always update wholesale and retail prices because they don't
......@@ -409,7 +411,7 @@ if (!this.dobrado.stock) {
// Also use the remove button to skip the current transaction
// when an import is in progress.
if (currentImport !== 0) {
showImportData();
showImportData(false);
return false;
}
......@@ -735,7 +737,7 @@ if (!this.dobrado.stock) {
resetForm();
}
else {
showImportData();
showImportData(false);
}
});
return false;
......@@ -790,6 +792,30 @@ if (!this.dobrado.stock) {
}
function loadImportData() {
function setUnavailable() {
dobrado.log("Updating availability...", "info");
$.post("/php/request.php", { request: "stock",
action: "unavailable",
supplier: importSupplier,
showAvailable: showAvailable,
url: location.href,
token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, "stock availability")) {
return;
}
stock = JSON.parse(response);
if (stockGrid) {
stockGrid.setData(stock.products);
stockGrid.updateRowCount();
stockGrid.render();
stockGrid.setSelectedRows([]);
}
showImportData(false);
});
}
importSupplier = $("#stock-import-supplier").val();
if (importSupplier === "") {
alert("Please enter a supplier name before importing a file.");
......@@ -836,28 +862,14 @@ if (!this.dobrado.stock) {
$(".stock .remove").button("option", "label", "skip");
// Also show a navigation button to go back through import data.
$(".stock .back").show();
// Make all items unavailable for this supplier before showing imports.
dobrado.log("Updating availability...", "info");
$.post("/php/request.php",
{ request: "stock",
action: "unavailable",
supplier: importSupplier,
showAvailable: showAvailable,
url: location.href,
token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, "stock availability")) {
return;
}
stock = JSON.parse(response);
if (stockGrid) {
stockGrid.setData(stock.products);
stockGrid.updateRowCount();
stockGrid.render();
stockGrid.setSelectedRows([]);
}
showImportData();
});
// If the "show new only" filter is *not* being used, make all items
// unavailable for this supplier before showing imports.
if ($("#stock-import-filter").val() === "new") {
showImportData(false);
}
else {
setUnavailable();
}
}
};
reader.readAsText(file);
......@@ -1023,7 +1035,7 @@ if (!this.dobrado.stock) {
// showImportData always increments currentImport counter,
// so need to decrease by 2 to get back 1.
currentImport -= 2;
showImportData();
showImportData(true);
}
return false;
}
......@@ -1099,7 +1111,7 @@ if (!this.dobrado.stock) {
return changes;
}
function showImportData() {
function showImportData(showPrevious) {
if (currentImport === importData.length) {
$("#stock-name-input").val("");
exitImport("Data processing complete.");
......@@ -1114,7 +1126,12 @@ if (!this.dobrado.stock) {
if (changes.exists) {
if ($("#stock-import-filter").val() === "new") {
// Skip this existing product when showing new products only.
showImportData();
if (showPrevious) {
showPreviousImport();
}
else {
showImportData(false);
}
return;
}
productInfo = "<b>Existing product: " + row.product + "</b>";
......@@ -1128,7 +1145,12 @@ if (!this.dobrado.stock) {
else {
if ($("#stock-import-filter").val() === "existing") {
// Skip this new product when showing existing products only.
showImportData();
if (showPrevious) {
showPreviousImport();
}
else {
showImportData(false);
}
return;
}
productInfo = "<b>New product: " + row.product + "</b>";
......
......@@ -455,8 +455,8 @@ $us_description =
"invoice-order-rounding" => "A value between zero and one, used to ".
"decide if the number of packs should be rounded up or down. If ".
"empty the number of packs will be left as a fraction.",
"organisation-sender" => "The 'from' address of the orders email for ".
"the organisation.",
"invoice-organisation-sender" => "The 'from' address of the orders ".
"email for the organisation.",
"invoice-organisation-sender-name" => "A descriptive name for the ".
"from address.",
"invoice-organisation-email" => "The 'to' address of the orders ".
......
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