Commit 33fe1b95 authored by Malcolm Blaney's avatar Malcolm Blaney

Fixed a few Cart module bugs, added Eftpos option to PaymentMethods.

Sell module now needs to send back the payment method to know if
it was cash or eftpos. Also buyers are now given retail price.
parent 9f37a2a8
......@@ -310,12 +310,12 @@ class Cart extends Base {
}
$mysqli->close();
$templates = array('"cart-price-text","","Price:"',
'"cart-quantity-text,"","Quantity:"',
'"cart-title","","Shopping Cart"',
'"cart-checkout","","Your order will be sent to:<br>'.
'!first !last<br>!address<br>!postcode<br>!city<br>'.
'!state<br>!country<br>"');
$template = array('"cart-price-text","","Price:"',
'"cart-quantity-text,"","Quantity:"',
'"cart-title","","Shopping Cart"',
'"cart-checkout","","Your order will be sent to:<br>'.
'!first !last<br>!address<br>!postcode<br>!city<br>'.
'!state<br>!country<br>"');
$this->AddTemplate($template);
$site_style = array('"","#cart-customer-details-form","background-color",'.
......@@ -823,17 +823,23 @@ class Cart extends Base {
$id = "customer-detail-method") {
$mysqli = connect_db();
$payment_method = "";
// When cash option needs to be displayed there only needs to be one
// other option to display the select.
$select_finished = false;
// When cash and eftpos options need to be displayed always show a select,
// otherwise the select is only shown if there's more than one option.
if ($display_cash) {
$payment_method .= '<label for="'.$id.'">Payment:</label>'.
'<select id="'.$id.'">'.
'<option value="cash">Cash</option>'.
'<option value="eftpos">Eftpos</option>';
}
$min = $display_cash ? 0 : 1;
$query = 'SELECT name FROM cart_method WHERE user = "'.$this->owner.'" '.
'AND available = 1';
if ($result = $mysqli->query($query)) {
if ($result->num_rows > $min) {
$payment_method = '<label for="'.$id.'">Payment:</label>'.
'<select id="'.$id.'">';
if ($display_cash) {
$payment_method .= '<option value="cash">Cash</option>';
if (!$display_cash) {
$payment_method = '<label for="'.$id.'">Payment:</label>'.
'<select id="'.$id.'">';
}
while ($cart_method = $result->fetch_assoc()) {
$method = $cart_method["name"];
......@@ -848,6 +854,7 @@ class Cart extends Base {
'</option>';
}
$payment_method .= '</select>';
$select_finished = true;
}
$result->close();
}
......@@ -855,6 +862,10 @@ class Cart extends Base {
$this->Log("Cart->PaymentMethods: ".$mysqli->error);
}
$mysqli->close();
// If displaying cash but there were no other options, finish the select.
if ($display_cash && !$select_finished) {
$payment_method .= '</select>';
}
return $payment_method;
}
......
......@@ -40,7 +40,17 @@ class Sell extends Base {
}
if ($action == "save") {
$purchase = new Purchase($this->user, $this->owner);
$purchase->SaveSales($_SESSION["sell-payment-method"]);
// The session variable is given precedence because the transaction has
// been checked. Otherwise method could end up as "check transaction".
if (isset($_SESSION["sell-payment-method"])) {
$purchase->SaveSales($_SESSION["sell-payment-method"]);
}
else {
$mysqli = connect_db();
$payment = $mysqli->escape_string($_POST["method"]);
$mysqli->close();
$purchase->SaveSales($payment);
}
$_SESSION["sell-payment-method"] = null;
return array("done" => true);
}
......@@ -238,9 +248,9 @@ class Sell extends Base {
public function Install($path) {
$this->AppendScript($path, "dobrado.sell.js", false);
$templates = array('"sell-items-description","","Purchases made on !date."',
'"sell-checkout","","Thanks for providing your '.
'details !first."');
$template = array('"sell-items-description","","Purchases made on !date."',
'"sell-checkout","","Thanks for providing your '.
'details !first."');
$this->AddTemplate($template);
$site_style = array('"","#sell-customer-details-form","background-color",'.
......@@ -251,8 +261,7 @@ class Sell extends Base {
'"2px"',
'"","#sell-customer-details-form","padding","5px"',
'"","#sell-customer-details-form","margin","5px"',
'"","#sell-customer-details-form label","width","7em"',
'"","#customer-detail-submit","margin-left","7.3em"');
'"","#sell-customer-details-form label","width","7em"');
$this->AddSiteStyle($site_style);
}
......
......@@ -54,8 +54,8 @@ cart[name].price=price;cart[name].quantity=quantity;}
else if(quantity!==0){cart[name]={selected:true,price:price,quantity:quantity,id:item.attr("id")};}
if(dobrado.localStorage()){localStorage.cart=JSON.stringify(cart);}
$("#cart-total").html(cartTotal());}
function cartMiniTotal(){var total=0;$.each(cart,function(name,item){if(item.selected&&item.price!==0){total+=item.price*item.quantity;}});$(".cart-total .number").html("$"+total.toFixed(2));}
function cartTotal(shipping){var total=0;var quantity=0;var table='<table class="cart-total-table">';$.each(cart,function(name,item){if(item.selected&&item.price!==0){total+=item.price*item.quantity;quantity+=item.quantity;table+='<tr><td>'+name+'</td><td>'+item.quantity+'</td><td>$'+(item.price*item.quantity).toFixed(2)+'</td></tr>';}});$(".cart-total .number").html("$"+total.toFixed(2));if(shipping){total+=shipping;table+='<tr><td>shipping</td><td></td><td>$'+
function cartMiniTotal(){var total=0;$.each(cart,function(name,item){if(item.selected&&item.price!==0){total+=item.price*item.quantity;}});$(".cart-total .number").html("$"+total.toFixed(0));}
function cartTotal(shipping){var total=0;var quantity=0;var table='<table class="cart-total-table">';$.each(cart,function(name,item){if(item.selected&&item.price!==0){total+=item.price*item.quantity;quantity+=item.quantity;table+='<tr><td>'+name+'</td><td>'+item.quantity+'</td><td>$'+(item.price*item.quantity).toFixed(2)+'</td></tr>';}});$(".cart-total .number").html("$"+total.toFixed(0));if(shipping){total+=shipping;table+='<tr><td>shipping</td><td></td><td>$'+
shipping.toFixed(2)+'</td></tr>';}
table+='<tr><td><b>Total</b></td><td>'+quantity+'</td><td>$'+
total.toFixed(2)+'</td></tr></table>';if(total===0){table="";$("#cart-checkout").button("option","disabled",true);}
......
......@@ -262,7 +262,7 @@ if (!this.dobrado.cart) {
total += item.price * item.quantity;
}
});
$(".cart-total .number").html("$" + total.toFixed(2));
$(".cart-total .number").html("$" + total.toFixed(0));
}
function cartTotal(shipping) {
......@@ -277,7 +277,7 @@ if (!this.dobrado.cart) {
'</td><td>$' + (item.price * item.quantity).toFixed(2) + '</td></tr>';
}
});
$(".cart-total .number").html("$" + total.toFixed(2));
$(".cart-total .number").html("$" + total.toFixed(0));
if (shipping) {
total += shipping;
......
This diff is collapsed.
......@@ -312,6 +312,7 @@ if (!this.dobrado.sell) {
country: $("#customer-detail-country").val(),
postcode: $("#customer-detail-postcode").val(),
total: $("#purchase-form .total").html(),
method: $("#purchase-payment-input").val(),
url: location.href,
token: dobrado.token },
function(response) {
......@@ -395,11 +396,11 @@ if (!this.dobrado.sell) {
// Clear the quantity input when the product changes.
if (currentProduct.unit === "variable") {
$("#purchase-quantity-input").val("1").spinner("disable");
$("#purchase-price-input").val(item.price.toFixed(2));
$("#purchase-price-input").val(item.retail.toFixed(2));
$("#purchase-price-input").attr("readonly", false);
}
else {
$("#purchase-price-input").val("($" + item.price.toFixed(2) + "/" +
$("#purchase-price-input").val("($" + item.retail.toFixed(2) + "/" +
item.unit + ")");
$("#purchase-price-input").attr("readonly", true);
$("#purchase-quantity-input").val("").spinner("enable");
......@@ -453,9 +454,9 @@ if (!this.dobrado.sell) {
}
if (currentProduct.unit !== "variable") {
var total = quantity * currentProduct.price;
var total = quantity * currentProduct.retail;
$("#purchase-price-input").val("$" + total.toFixed(2) + " @ ($" +
currentProduct.price.toFixed(2) +
currentProduct.retail.toFixed(2) +
"/" + currentProduct.unit + ")");
}
}
......@@ -529,7 +530,7 @@ if (!this.dobrado.sell) {
}
var accumulative = true;
var supplier = currentProduct.user;
var price = currentProduct.price;
var price = currentProduct.retail;
if (currentProduct.unit === "variable") {
price = parseFloat($("#purchase-price-input").val());
accumulative = false;
......@@ -615,9 +616,17 @@ if (!this.dobrado.sell) {
function saveBeforeLoad(reload) {
dobrado.log("Saving...", "info");
// When reload is true the page has returned after processing a transaction.
// In this case the method is set as "check transaction" and then overriden
// on the server when the transaction is checked.
var method = "cash";
if (reload) {
method = "check transaction";
}
$.post("/php/request.php", { request: "sell",
data: JSON.stringify(purchase.data),
action: "save",
method: method,
url: location.href,
token: dobrado.token },
function(response) {
......@@ -637,8 +646,8 @@ if (!this.dobrado.sell) {
function save() {
// Load the payment dialog for non cash payments.
var payment = $("#purchase-payment-input").val();
if (payment && payment !== "cash") {
var method = $("#purchase-payment-input").val();
if (method && method !== "cash" && method !== "eftpos") {
$("#sell-checkout-dialog").dialog("open");
}
else {
......@@ -646,6 +655,7 @@ if (!this.dobrado.sell) {
$.post("/php/request.php", { request: "sell",
data: JSON.stringify(purchase.data),
action: "save",
method: method,
url: location.href,
token: dobrado.token },
function(response) {
......@@ -675,8 +685,8 @@ if (!this.dobrado.sell) {
}
function newCashSale() {
var payment = $("#purchase-payment-input").val();
if (payment && payment !== "cash") {
var method = $("#purchase-payment-input").val();
if (method && method !== "cash") {
alert("Please save non-cash purchase first.");
return false;
}
......@@ -715,12 +725,12 @@ if (!this.dobrado.sell) {
$.each(purchase.products, function(productIndex, product) {
if (current[product.name]) {
$.each(current[product.name], function(currentIndex, currentItem) {
total = currentItem.quantity * product.price;
total = currentItem.quantity * product.retail;
allAvailableData.push({ name: product.name,
supplier: product.user,
quantity: currentItem.quantity,
unit: product.unit,
price: product.price.toFixed(2),
price: product.retail.toFixed(2),
basePrice: product.price.toFixed(2),
total: total.toFixed(2) });
......@@ -730,7 +740,7 @@ if (!this.dobrado.sell) {
allAvailableData.push({ name: product.name,
supplier: product.user, quantity: 0,
unit: product.unit,
price: product.price.toFixed(2),
price: product.retail.toFixed(2),
basePrice: product.price.toFixed(2),
total: "0.00" });
}
......
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