Commit e438ab95 authored by Malcolm Blaney's avatar Malcolm Blaney

Added new stock unit "adjusted", which displays as "each" while

ordering but shows a per quantity price when packing to allow it
to be adjusted. Organiser module no longer needs to be listed as
a dependency as it's now installed by default.
parent 573264f0
......@@ -220,7 +220,7 @@ class Banking extends Base {
'"","#banking-form label","width","8em"',
'"","#banking-form .submit","margin-left","8.4em"');
$this->AddSiteStyle($site_style);
return $this->Dependencies(array('invite', 'organiser'));
return $this->Dependencies(array('invite'));
}
public function Placement() {
......
......@@ -122,6 +122,8 @@ class Comment extends Base {
$site_style = array('"",".comment","width","500px"',
'"",".comment-name .thumb","width","20px"',
'"",".comment-name .thumb","border-radius","2px"',
'"","#comment-form .thumb","width","20px"',
'"","#comment-form .thumb","border-radius","2px"',
'"",".comment-wrapper","border","2px solid #222222"',
'"",".comment-wrapper","border-radius","3px"',
'"",".comment-wrapper","margin","5px"',
......
......@@ -677,8 +677,7 @@ class Groupwizard extends Base {
'"", "label[for=groupwizard-organiser-sender-name]", '.
'"width", "12em"');
$this->AddSiteStyle($site_style);
return $this->Dependencies(array('invite', 'organiser', 'purchase',
'stock'));
return $this->Dependencies(array('invite', 'purchase', 'stock'));
}
public function Placement() {
......
......@@ -328,8 +328,8 @@ class Invoice extends Base {
'"","#invoice-date","float","left"',
'"","#invoice-date","margin","5px"');
$this->AddSiteStyle($site_style);
$dependencies = array('banking', 'detail', 'invite', 'organiser', 'payment',
'purchase', 'roster', 'stock');
$dependencies = array('banking', 'detail', 'invite', 'payment', 'purchase',
'roster', 'stock');
return $this->Dependencies($dependencies);
}
......
......@@ -439,8 +439,8 @@ class Purchase extends Base {
$this->AddSiteStyle($site_style);
// Check module dependenices.
$dependencies = array('banking', 'detail', 'invite', 'organiser',
'payment', 'roster', 'stock');
$dependencies = array('banking', 'detail', 'invite', 'payment', 'roster',
'stock');
return $this->Dependencies($dependencies);
}
......
......@@ -221,9 +221,7 @@ class Report extends Base {
'"",".report-attendance-search","margin-bottom","20px"',
'"",".report-attendance-search","padding","5px"');
$this->AddSiteStyle($site_style);
// Need to call AppendScript here if module uses javascript.
return $this->Dependencies(array('invite', 'organiser', 'payment',
'purchase', 'stock'));
return $this->Dependencies(array('invite', 'payment', 'purchase', 'stock'));
}
public function Placement() {
......
This diff is collapsed.
......@@ -102,11 +102,11 @@ var total=(quantity*price).toFixed(2);var timestamp=parseInt($.datepicker.format
if(currentDate&&timestamp>currentDate-oneDay&&timestamp<currentDate+oneDay){timestamp=currentDate;}
else{currentDate=null;}
saving=true;$("#manager-form .submit").button("option","disabled",true);dobrado.log("Saving purchase...","info");$.post("/php/request.php",{request:"manager",username:user,timestamp:timestamp,product:product,supplier:supplier,quantity:quantity,price:price.toFixed(2),basePrice:basePrice.toFixed(2),action:"submit",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"manager submit")){saving=false;$("#manager-form .submit").button("option","disabled",false);return;}
var data=JSON.parse(response);var selectedRow=0;var newItem=true;if(currentDate){$.each(purchase,function(i,item){if(item.name===product&&item.date===currentDate&&item.user===user){purchase[i].supplier=supplier;purchase[i].quantity=quantity;purchase[i].price=price;purchase[i].total=total;if(managerGrid){selectedRow=i;}
var data=JSON.parse(response);var selectedRow=0;var newItem=true;if(currentDate){$.each(purchase,function(i,item){if(item.name===product&&item.date===currentDate&&item.user===user){purchase[i].supplier=supplier;purchase[i].quantity=quantity;purchase[i].price=price.toFixed(2);purchase[i].total=total;if(managerGrid){selectedRow=i;}
newItem=false;}
else if(!data.done&&item.user===user&&item.name==="surcharge"&&item.date===data.date){purchase[i]=data;}});}
if(newItem){if(data.composite){$.each(data.purchase,function(i,item){purchase.push({date:item.date,user:item.user,name:item.name,supplier:item.supplier,quantity:item.quantity,price:item.price,total:item.total});});}
else{purchase.push({date:timestamp,user:user,name:product,supplier:supplier,quantity:quantity,price:price,total:total});$.each(purchase,function(i,item){if(!data.done&&item.user===user&&item.name==="surcharge"&&item.date===data.date){purchase[i]=data;}});}
if(newItem){if(data.composite){$.each(data.purchase,function(i,item){purchase.push({date:item.date,user:item.user,name:item.name,supplier:item.supplier,quantity:item.quantity,price:item.price.toFixed(2),total:item.total});});}
else{purchase.push({date:timestamp,user:user,name:product,supplier:supplier,quantity:quantity,price:price.toFixed(2),total:total});$.each(purchase,function(i,item){if(!data.done&&item.user===user&&item.name==="surcharge"&&item.date===data.date){purchase[i]=data;}});}
selectedRow=purchase.length-1;}
if(managerGrid){managerGrid.setData(purchase);managerGrid.updateRowCount();managerGrid.render();$(managerGridId).show();managerGrid.setSelectedRows([selectedRow]);managerGrid.scrollRowIntoView(selectedRow);}
if(currentImport===0){resetForm();}
......@@ -158,7 +158,7 @@ if(item.quantity>0){if(item.unit==="variable"){item.quantity=1;}
if(composite){dobrado.log("Updating "+product+".","info");}
else{dobrado.log("Saving purchase.","info");}
$.post("/php/request.php",{request:"manager",username:user,timestamp:item.date,product:item.name,supplier:item.supplier,quantity:item.quantity,price:item.price,basePrice:item.basePrice,composite:product,action:"savePurchase",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"manager updatePurchase")){return;}
var data=JSON.parse(response);purchase.push({date:item.date,user:user,name:item.name,supplier:item.supplier,quantity:item.quantity,price:item.price,total:item.total});$.each(purchase,function(i,item){if(!data.done&&item.user===user&&item.name==="surcharge"&&item.date===data.date){purchase[i]=data;}});if(managerGrid){managerGrid.setData(purchase);managerGrid.updateRowCount();managerGrid.render();$(managerGridId).show();}});}
var data=JSON.parse(response);purchase.push({date:item.date,user:user,name:item.name,supplier:item.supplier,quantity:item.quantity,price:item.price.toFixed(2),total:item.total});$.each(purchase,function(i,item){if(!data.done&&item.user===user&&item.name==="surcharge"&&item.date===data.date){purchase[i]=data;}});if(managerGrid){managerGrid.setData(purchase);managerGrid.updateRowCount();managerGrid.render();$(managerGridId).show();}});}
else{if(composite){dobrado.log("Updating "+product+".","info");}
else{dobrado.log("Removing purchase.","info");}
$.post("/php/request.php",{request:"manager",username:user,timestamp:item.date,product:item.name,supplier:item.supplier,quantity:item.quantity,composite:product,action:"removePurchase",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"manager updatePurchase")){return;}});}}
......
......@@ -714,7 +714,7 @@ if (!this.dobrado.manager) {
item.date === currentDate && item.user === user) {
purchase[i].supplier = supplier;
purchase[i].quantity = quantity;
purchase[i].price = price;
purchase[i].price = price.toFixed(2);
purchase[i].total = total;
if (managerGrid) {
selectedRow = i;
......@@ -734,14 +734,15 @@ if (!this.dobrado.manager) {
$.each(data.purchase, function(i, item) {
purchase.push({ date: item.date, user: item.user,
name: item.name, supplier: item.supplier,
quantity: item.quantity, price: item.price,
quantity: item.quantity,
price: item.price.toFixed(2),
total: item.total });
});
}
else {
purchase.push({ date: timestamp, user: user, name: product,
supplier: supplier, quantity: quantity,
price: price, total: total });
price: price.toFixed(2), total: total });
// Update the surcharge value in the current purchase list.
$.each(purchase, function(i, item) {
if (!data.done && item.user === user &&
......@@ -1124,7 +1125,7 @@ if (!this.dobrado.manager) {
var data = JSON.parse(response);
purchase.push({ date: item.date, user: user, name: item.name,
supplier: item.supplier, quantity: item.quantity,
price: item.price, total: item.total });
price: item.price.toFixed(2), total: item.total });
// Update the surcharge value in the current purchase list.
$.each(purchase, function(i, item) {
if (!data.done && item.user === user &&
......
......@@ -98,12 +98,16 @@ function showAllAdjustments(){dobrado.log("Loading all adjustments...","info");$
adjustmentData=JSON.parse(response);allAdjustments=true;if(adjustmentGrid){adjustmentGrid.setData(adjustmentData);adjustmentGrid.updateRowCount();adjustmentGrid.render();adjustmentGrid.setSelectedRows([]);}});}
function exportAdjustments(){var name=$("#stock-name-input").val();var supplier=$("#stock-user-input").val();dobrado.log("Exporting adjustments...","info");$.post("/php/request.php",{request:"stock",action:"exportAdjustments",allAdjustments:allAdjustments,name:name,supplier:supplier,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"stock exportAdjustments")){return;}
var data=JSON.parse(response);location.href="/php/private.php?file="+data.filename;});return false;}
function submit(){if(saving){return false;}
function submit(){function checkFormat(name){return/\d+\s*(each|g|kg|kilo|l)/i.test(name);}
if(saving){return false;}
var quantity=parseFloat($("#stock-new-quantity-input").val());if(isNaN(quantity)){quantity=0;}
var total=parseFloat($("#stock-total-quantity-input").val());if(isNaN(total)){total=0;}
total+=quantity;var unit=$("#stock-unit-select > option:selected").val();var size=parseFloat($("#stock-size-input").val());var price=$("#stock-price-input").val();var wholesale=$("#stock-wholesale-input").val();var retail=$("#stock-retail-input").val();var category=$("#stock-category-input").val();var grower=$("#stock-growing-input").val();var available=$("#stock-order-available-input:checked").length;var purchaseAvailable=$("#stock-purchase-available-input:checked").length;var supplierAvailable=$("#stock-supplier-available-input:checked").length;var taxable=$("#stock-taxable-input:checked").length;var composite=$("#stock-composite-input:checked").length;var track=$("#stock-track-input:checked").length;var selectedRow=0;var selected=stockGrid.getSelectedRows();if(selected.length>1&&confirm("Update "+selected.length+" products?")){var data=[];$.each(selected,function(i,row){data.push({name:stock.products[row].name,supplier:stock.products[row].user});});$.post("/php/request.php",{request:"stock",action:"editMultiple",data:JSON.stringify(data),quantity:quantity,unit:unit,size:size,price:price,wholesale:wholesale,retail:retail,category:category,grower:grower,orderAvailable:available,purchaseAvailable:purchaseAvailable,supplierAvailable:supplierAvailable,taxable:taxable,composite:composite,track:track,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"stock submit")){return;}
total+=quantity;var unit=$("#stock-unit-select > option:selected").val();var size=parseFloat($("#stock-size-input").val());var price=$("#stock-price-input").val();var wholesale=$("#stock-wholesale-input").val();var retail=$("#stock-retail-input").val();var category=$("#stock-category-input").val();var grower=$("#stock-growing-input").val();var available=$("#stock-order-available-input:checked").length;var purchaseAvailable=$("#stock-purchase-available-input:checked").length;var supplierAvailable=$("#stock-supplier-available-input:checked").length;var taxable=$("#stock-taxable-input:checked").length;var composite=$("#stock-composite-input:checked").length;var track=$("#stock-track-input:checked").length;var selectedRow=0;var selected=stockGrid.getSelectedRows();if(selected.length>1&&confirm("Update "+selected.length+" products?")){var data=[];$.each(selected,function(i,row){var name=stock.products[row].name;if(unit==="adjusted"&&!checkFormat(name)){alert("Product name must include quantity and units to adjust by.");return false;}
data.push({name:name,supplier:stock.products[row].user});});if(data.length===0){return false;}
$.post("/php/request.php",{request:"stock",action:"editMultiple",data:JSON.stringify(data),quantity:quantity,unit:unit,size:size,price:price,wholesale:wholesale,retail:retail,category:category,grower:grower,orderAvailable:available,purchaseAvailable:purchaseAvailable,supplierAvailable:supplierAvailable,taxable:taxable,composite:composite,track:track,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"stock submit")){return;}
resetForm();showAll();});return false;}
var name=$("#stock-name-input").val();if(name===""){return false;}
if(unit==="adjusted"&&!checkFormat(name)){alert("Product name must include quantity and units to adjust by.");return false;}
var supplier=$("#stock-user-input").val();if($.inArray(supplier,stock.users)===-1){alert("Supplier account must be in the current buying group.");$("#stock-user-input").val("");return false;}
var oldName="";if(currentProduct){oldName=currentProduct.name;}
saving=true;$("#stock-form .submit").button("option","disabled",true);dobrado.log("Saving stock...","info");$.post("/php/request.php",{request:"stock",action:"edit",name:name,oldName:oldName,supplier:supplier,quantity:quantity,unit:unit,size:size,price:price,wholesale:wholesale,retail:retail,category:category,grower:grower,orderAvailable:available,purchaseAvailable:purchaseAvailable,supplierAvailable:supplierAvailable,taxable:taxable,composite:composite,track:track,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"stock submit")){saving=false;$("#stock-form .submit").button("option","disabled",false);return;}
......@@ -140,10 +144,10 @@ if(row.length>=9){if(!headerFound){if(row[0]==="Product"||row[1].substring(0,11)
return true;}
if(row[0]===""){emptyLineCount++;if(emptyLineCount===2){return false;}
return true;}
else{emptyLineCount=0;var quantity=row[2];var unit=row[4].toLowerCase();if(unit==="l"||unit.substring(0,5)==="litre"||unit.substring(0,6)==="litres"){unit="L";}
else if(unit.substring(0,1)==="g"||unit.substring(0,4)==="gram"||unit.substring(0,4)==="grams"){unit="g";}
else if(unit.substring(0,2)==="kg"||unit.substring(0,8)==="kilogram"||unit.substring(0,9)==="kilograms"){unit="kg";}
else if(unit!=="variable"){unit="each";}
else{emptyLineCount=0;var quantity=row[2];var unit=row[4].toLowerCase();if(unit==="l"||unit.substring(0,5)==="litre"){unit="L";}
else if(unit.substring(0,1)==="g"||unit.substring(0,4)==="gram"){unit="g";}
else if(unit.substring(0,2)==="kg"||unit.substring(0,4)==="kilo"){unit="kg";}
else if(unit!=="variable"&&unit!=="adjusted"){unit="each";}
var size=0;var matchSize=row[3].match(/^([0-9\.]+)/);if(matchSize&&matchSize.length===2){size=parseFloat(matchSize[1]);}
var price=row[5];if(price[0]==="$"){price=row[5].substring(1);}
price=parseFloat(price);if(size>0.001){price/=size;}
......
......@@ -756,6 +756,13 @@ if (!this.dobrado.stock) {
}
function submit() {
function checkFormat(name) {
// Allow for more options than the regex shows by not matching what comes
// after the start of the unit name.
return /\d+\s*(each|g|kg|kilo|l)/i.test(name);
}
// Don't allow submit to be called more than once before returning.
if (saving) {
return false;
......@@ -793,9 +800,16 @@ if (!this.dobrado.stock) {
confirm("Update " + selected.length + " products?")) {
var data = [];
$.each(selected, function(i, row) {
data.push({ name: stock.products[row].name,
supplier: stock.products[row].user });
var name = stock.products[row].name;
if (unit === "adjusted" && !checkFormat(name)) {
alert("Product name must include quantity and units to adjust by.");
return false;
}
data.push({ name: name, supplier: stock.products[row].user });
});
if (data.length === 0) {
return false;
}
$.post("/php/request.php",
{ request: "stock",
action: "editMultiple",
......@@ -830,6 +844,10 @@ if (!this.dobrado.stock) {
if (name === "") {
return false;
}
if (unit === "adjusted" && !checkFormat(name)) {
alert("Product name must include quantity and units to adjust by.");
return false;
}
var supplier = $("#stock-user-input").val();
if ($.inArray(supplier, stock.users) === -1) {
......@@ -1249,21 +1267,18 @@ if (!this.dobrado.stock) {
// The unit is free form text so try and condense to a limited set.
// substrings are used to avoid spaces.
var unit = row[4].toLowerCase();
if (unit === "l" || unit.substring(0, 5) === "litre" ||
unit.substring(0, 6) === "litres") {
if (unit === "l" || unit.substring(0, 5) === "litre") {
unit = "L";
}
else if (unit.substring(0, 1) === "g" ||
unit.substring(0, 4) === "gram" ||
unit.substring(0, 4) === "grams") {
unit.substring(0, 4) === "gram") {
unit = "g";
}
else if (unit.substring(0, 2) === "kg" ||
unit.substring(0, 8) === "kilogram" ||
unit.substring(0, 9) === "kilograms") {
unit.substring(0, 4) === "kilo") {
unit = "kg";
}
else if (unit !== "variable") {
else if (unit !== "variable" && unit !== "adjusted") {
unit = "each";
}
// Pack size is usually just a number, but can be min-max. In this
......
......@@ -121,8 +121,11 @@ function write_site_style() {
}
function write_page_style($user, $file) {
preg_match('/([^\/]+)\.css$/', $file, $matches);
$page = $matches[1];
$page = '';
$matches = array();
if (preg_match('/([^\/]+)\.css$/', $file, $matches)) {
$page = $matches[1];
}
if ($page === '') return;
$mysqli = connect_db();
......
......@@ -214,6 +214,7 @@ class Control extends Base {
'"",".control .wrapper","padding-top","8px"',
'"",".control-button","margin-left","7px"',
'"",".control-button","float","left"',
'"","label.control-button","margin-top","0"',
'"",".control-button.minimise","float","right"',
'"",".control-button.minimise","margin-right","7px"',
'"",".arrow","border-style","solid"',
......
......@@ -55,7 +55,7 @@ if ($user->loggedIn) {
}
}
if ($reader_installed && $reader->Factory('Following', $url)) {
if (is_array($status[$url])) {
if (isset($status[$url])) {
$status[$url]['follow'] = true;
}
else {
......
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