Commit 43e43e36 authored by Malcolm Blaney's avatar Malcolm Blaney

Changed Stock Increase and Decrease functions to only modify quantity

if the "stock-track-quantity" substitution is true. Also fixed a bug
that reset the form when a new product name and supplier was entered.
parent dcea66c2
......@@ -601,9 +601,10 @@ class Stock extends Base {
}
public function Decrease($product_list) {
if ($this->Substitute("stock-track-quantity") != "true") return;
$organiser = new Organiser($this->user, $this->owner);
$mysqli = connect_db();
foreach ($product_list as $user => $product) {
if (!$organiser->MatchUser($user)) {
$this->Log("Stock->Decrease 1: Supplier not found");
......@@ -621,9 +622,10 @@ class Stock extends Base {
}
public function Increase($product_list) {
if ($this->Substitute("stock-track-quantity") != "true") return;
$organiser = new Organiser($this->user, $this->owner);
$mysqli = connect_db();
foreach ($product_list as $user => $product) {
if (!$organiser->MatchUser($user)) {
$this->Log("Stock->Increase 1: Supplier not found");
......
......@@ -40,8 +40,7 @@ else{return sign* -1;}});adjustmentGrid.invalidate();});}}});});function checkPr
event.preventDefault();if(currentImport!==0){showProduct();}}
function showProduct(product){var productFound=false;var name=$("#stock-name-input").val();var supplier=$("#stock-user-input").val();if(product){exitImport("");name=product.name;supplier=product.user;}
if(currentImport!==0){$.each(stock.products,function(index,item){if(name===item.name&&importSupplier===item.user){checkExistingProduct();return false;}});}
else{$.each(stock.products,function(index,item){if(name===item.name){productFound=true;if(supplier===""||supplier===item.user){currentProduct=item;$("#stock-name-input").val(item.name);$("#stock-user-input").val(item.user);$("#stock-total-quantity-input").val(item.quantity);$("#stock-unit-select").val(item.unit);$("#stock-size-input").val(item.size);$("#stock-price-input").val(item.price);$("#stock-wholesale-input").val(item.wholesale);$("#stock-retail-input").val(item.retail);$("#stock-category-input").val(item.category);$("#stock-growing-input").val(item.grower);$("#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);$("#stock-composite-input").prop("checked",item.composite===1);return false;}}});if(!productFound){if(!currentProduct){resetForm();}
else if(confirm("Reset the form to add details for a new product?\n"+"(Press cancel to change product name and keep "+"existing details.\nWhen you click submit, all "+"previous purchases will also be updated.)")){resetForm();}}}}
else{$.each(stock.products,function(index,item){if(name===item.name){productFound=true;if(supplier===""||supplier===item.user){currentProduct=item;$("#stock-name-input").val(item.name);$("#stock-user-input").val(item.user);$("#stock-total-quantity-input").val(item.quantity);$("#stock-unit-select").val(item.unit);$("#stock-size-input").val(item.size);$("#stock-price-input").val(item.price);$("#stock-wholesale-input").val(item.wholesale);$("#stock-retail-input").val(item.retail);$("#stock-category-input").val(item.category);$("#stock-growing-input").val(item.grower);$("#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);$("#stock-composite-input").prop("checked",item.composite===1);return false;}}});if(!productFound&&currentProduct&&confirm("Reset the form to add details for a new product?\n"+"(Press cancel to change product name and keep "+"existing details.\nWhen you click submit, all "+"previous purchases will also be updated.)")){resetForm();}}}
function updateProducts(){function showProductFromMenu(event,ui){if(currentImport!==0){$.each(stock.products,function(index,item){if(ui.item.value===item.name&&importSupplier===item.user){checkExistingProduct(item.name);return false;}});}
else{$.each(stock.products,function(index,item){if(ui.item.value===item.name){showProduct(item);return false;}});}}
var products=[];$.each(stock.products,function(index,item){if($.inArray(item.name,products)===-1){products.push(item.name);}});$("#stock-name-input").autocomplete({source:products,select:showProductFromMenu});var categories=[];$.each(stock.products,function(index,item){if($.inArray(item.category,categories)===-1){categories.push(item.category);}});$("#stock-category-input").autocomplete({source:categories});}
......
......@@ -294,17 +294,15 @@ if (!this.dobrado.stock) {
}
}
});
if (!productFound) {
if (!currentProduct) {
resetForm();
}
// currentProduct is set when a row in the grid is selected.
else if (confirm("Reset the form to add details for a new product?\n" +
"(Press cancel to change product name and keep " +
"existing details.\nWhen you click submit, all " +
"previous purchases will also be updated.)")) {
resetForm();
}
// If a product is not found, user is either adding a new product or
// updating a current product, in which case currentProduct is set when
// a row in the grid is selected.
if (!productFound && currentProduct &&
confirm("Reset the form to add details for a new product?\n" +
"(Press cancel to change product name and keep " +
"existing details.\nWhen you click submit, all " +
"previous purchases will also be updated.)")) {
resetForm();
}
}
}
......
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