Commit a1fb720b authored by Malcolm Blaney's avatar Malcolm Blaney

Banking module: Added "deposit" boolean to track whether members

have paid a deposit. Allow longer bank references. AllBuyers
method can return details for only members listed as "active".
Group Wizard module: New pre-order-open[-time] substitutions
have replaced pre-order-wait, which was hard to calculate.
Hidden some less useful options, now only visible with site
permission.
Invoice module: Bulk invoices are now only sent via cron.
This has cleaned up the UI, which now allows single invoices to be
sent on any date with better email options.
Purchase module now calls Stock->AllProducts when generating
invoices instead of AvailableProducts. AllProducts was updated to
return an associative array. Also fixed a stock bug that didn't
update order availability.
Payment module exits import if a duplicate payment is found.
parent a1aeb978
<?php
// Dobrado Content Management System
// Copyright (C) 2014 Malcolm Blaney
// Copyright (C) 2015 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -162,7 +162,7 @@ class Banking extends Base {
// This query does the insert without needing to check for an existing
// user. (The duplicate key update doesn't do anything).
$query = 'INSERT INTO banking VALUES ("'.$this->user->name.'", '.
'"'.$reference.'", "", "", "", 1, 1, 0, '.
'"'.$reference.'", "", "", "", 1, 1, 1, 0, '.
'"'.$this->Substitute("banking-default-group").'") '.
'ON DUPLICATE KEY UPDATE user = "'.$this->user->name.'"';
if (!$mysqli->query($query)) {
......@@ -197,12 +197,13 @@ class Banking extends Base {
$mysqli = connect_db();
$query = 'CREATE TABLE IF NOT EXISTS banking ('.
'user VARCHAR(50) NOT NULL,'.
'reference VARCHAR(6) NOT NULL,'.
'reference VARCHAR(20) NOT NULL,'.
'name VARCHAR(100),'.
'number VARCHAR(20),'.
'bsb VARCHAR(7),'.
'credit TINYINT(1),'.
'surcharge TINYINT(1),'.
'deposit TINYINT(1),'.
'next_week INT(10) UNSIGNED NOT NULL,'.
'buyer_group ENUM("", "wholesale", "retail"),'.
'PRIMARY KEY(user)'.
......@@ -249,6 +250,21 @@ class Banking extends Base {
public function Update() {
// This is called when the version of the module is updated,
// to provide a way to update or modify tables etc..
$mysqli = connect_db();
$query = 'ALTER TABLE banking MODIFY COLUMN reference VARCHAR(20)';
if (!$mysqli->query($query)) {
$this->Log("Banking->Update 1: ".$mysqli->error);
}
$query = 'ALTER TABLE banking ADD COLUMN deposit TINYINT(1) '.
'AFTER surcharge';
if (!$mysqli->query($query)) {
$this->Log("Banking->Update 2: ".$mysqli->error);
}
$query = 'UPDATE banking SET deposit = 1';
if (!$mysqli->query($query)) {
$this->Log("Banking->Update 3: ".$mysqli->error);
}
$mysqli->close();
}
public function UpdateScript($path) {
......@@ -258,20 +274,24 @@ class Banking extends Base {
// Public functions that aren't part of interface here /////////////////////
public function AllBuyers($organisation = false) {
public function AllBuyers($organisation = false, $active_only = true) {
$user_list = array();
$buyer_groups = array();
$mysqli = connect_db();
$query = "";
$active_query = "";
if ($active_only) {
$active_query = 'active = 1 AND ';
}
if ($organisation) {
$organiser = new Organiser($this->user, $this->owner);
$query = 'SELECT banking.user, buyer_group FROM banking LEFT JOIN '.
'users ON banking.user = users.user WHERE '.
'users ON banking.user = users.user WHERE '.$active_query.
$organiser->GroupQuery();
}
else {
$query = 'SELECT banking.user, buyer_group FROM banking LEFT JOIN '.
'users ON banking.user = users.user WHERE '.
'users ON banking.user = users.user WHERE '.$active_query.
'users.system_group = "'.$this->user->group.'"';
}
if ($result = $mysqli->query($query)) {
......@@ -296,13 +316,13 @@ class Banking extends Base {
if ($organisation) {
$organiser = new Organiser($this->user, $this->owner);
$query = 'SELECT banking.user, reference, name, number, bsb, credit, '.
'surcharge, next_week, buyer_group FROM banking LEFT JOIN users ON '.
'banking.user = users.user WHERE '.$organiser->GroupQuery();
'surcharge, deposit, next_week, buyer_group FROM banking LEFT JOIN '.
'users ON banking.user = users.user WHERE '.$organiser->GroupQuery();
}
else {
$query = 'SELECT banking.user, reference, name, number, bsb, credit, '.
'surcharge, next_week, buyer_group FROM banking LEFT JOIN users ON '.
'banking.user = users.user WHERE '.
'surcharge, deposit, next_week, buyer_group FROM banking LEFT JOIN '.
'users ON banking.user = users.user WHERE '.
'users.system_group = "'.$this->user->group.'"';
}
$mysqli = connect_db();
......@@ -315,6 +335,7 @@ class Banking extends Base {
"bsb" => $banking["bsb"],
"credit" => (int)$banking["credit"],
"surcharge" => (int)$banking["surcharge"],
"deposit" => (int)$banking["deposit"],
"nextWeek" => $banking["next_week"],
"buyerGroup" => $banking["buyer_group"]);
}
......@@ -344,8 +365,8 @@ class Banking extends Base {
return $buyer_group == "" ? "price" : $buyer_group;
}
public function UpdateUser($username, $reference, $name, $number,
$bsb, $credit, $surcharge, $buyer_group) {
public function UpdateUser($username, $reference, $name, $number, $bsb,
$credit, $surcharge, $deposit, $buyer_group) {
$count = -1;
$organiser = new Organiser($this->user, $this->owner);
......@@ -353,7 +374,7 @@ class Banking extends Base {
// The banking reference needs to be unique so check if it already exists.
$query = 'SELECT reference FROM banking LEFT JOIN users ON '.
'banking.user = users.user WHERE reference = "'.$reference.'" '.
'AND banking.user != "'.$username.'" AND ('.$organiser->GroupQuery().')';
'AND banking.user != "'.$username.'" AND '.$organiser->GroupQuery();
if ($result = $mysqli->query($query)) {
$count = $result->num_rows;
}
......@@ -367,8 +388,8 @@ class Banking extends Base {
$query = 'UPDATE banking SET reference = "'.$reference.'", '.
'name = "'.$name.'", number = "'.$number.'", bsb = "'.$bsb.'", '.
'credit = '.$credit.', surcharge = '.$surcharge.', '.
'buyer_group = "'.$buyer_group.'" WHERE user = "'.$username.'"';
'credit = '.$credit.', surcharge = '.$surcharge.', deposit = '.$deposit.
', buyer_group = "'.$buyer_group.'" WHERE user = "'.$username.'"';
if (!$mysqli->query($query)) {
$this->Log("Banking->UpdateUser 2: ".$mysqli->error);
}
......
<?php
// Dobrado Content Management System
// Copyright (C) 2014 Malcolm Blaney
// Copyright (C) 2015 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -241,7 +241,7 @@ class Detail extends Base {
$query = 'SELECT users.user, email, system_group, first, last, '.
'thumbnail, phone, description, display FROM users LEFT JOIN '.
'user_detail ON users.user = user_detail.user WHERE users.user '.
'NOT LIKE "buyer\_%" AND ('.$organiser->GroupQuery().')';
'NOT LIKE "buyer\_%" AND '.$organiser->GroupQuery();
}
else {
$query = 'SELECT users.user, email, system_group, first, last, '.
......
This diff is collapsed.
This diff is collapsed.
<?php
// Dobrado Content Management System
// Copyright (C) 2014 Malcolm Blaney
// Copyright (C) 2015 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -35,7 +35,8 @@ class Manager extends Base {
if ($action == "list") {
// Lists of users and products are made to autocomplete and verify input.
$banking = new Banking($this->user, $this->owner);
list($object["users"], $object["buyerGroup"]) = $banking->AllBuyers(true);
list($object["users"], $object["buyerGroup"]) =
$banking->AllBuyers(true, false);
$detail = new Detail($this->user, $this->owner);
$object["details"] = $detail->AllUsers(true);
......@@ -220,7 +221,7 @@ class Manager extends Base {
'</div><hr>'.
'<div class="form-spacing">'.
'<label for="manager-username-input">Username:</label>'.
'<input id="manager-username-input" size="15" maxlength="50">'.
'<input id="manager-username-input" size="30" maxlength="50">'.
'</div>'.
'<div class="details"><b>Contact details:</b> '.
'<button class="edit">edit</button><br>'.
......@@ -230,12 +231,12 @@ class Manager extends Base {
'<hr>'.
'<div class="form-spacing">'.
'<label for="manager-product-input">Product:</label>'.
'<input id="manager-product-input" size="15" maxlength="100">'.
'<input id="manager-product-input" size="30" maxlength="100">'.
'<a href="#" class="view-all">(View all)</a>'.
'</div>'.
'<div class="form-spacing">'.
'<label for="manager-supplier-input">Supplier:</label>'.
'<input id="manager-supplier-input" size="15" maxlength="50">'.
'<input id="manager-supplier-input" size="30" maxlength="50">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="manager-quantity-input">Quantity*:</label>'.
......
<?php
// Dobrado Content Management System
// Copyright (C) 2014 Malcolm Blaney
// Copyright (C) 2015 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -455,9 +455,9 @@ class Organiser extends Base {
}
// If there is no data return the user's current group.
if ($group_query == "") {
$group_query = 'users.system_group = "'.$this->user->group.'"';
return 'users.system_group = "'.$this->user->group.'"';
}
return $group_query;
return '('.$group_query.')';
}
public function MatchParents($groups) {
......@@ -489,7 +489,7 @@ class Organiser extends Base {
$match = false;
$mysqli = connect_db();
$query = 'SELECT user FROM users WHERE user = "'.$user.'" '.
'AND ('.$this->GroupQuery().')';
'AND '.$this->GroupQuery();
if ($result = $mysqli->query($query)) {
$match = $result->num_rows == 1;
$result->close();
......
<?php
// Dobrado Content Management System
// Copyright (C) 2014 Malcolm Blaney
// Copyright (C) 2015 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -173,7 +173,7 @@ class Payment extends Base {
'</div>'.
'<div class="form-spacing">'.
'<label for="payment-reference-input">Reference:</label>'.
'<input id="payment-reference-input" size="15" maxlength="100">'.
'<input id="payment-reference-input" size="15" maxlength="20">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="payment-comment">Comment:</label>'.
......@@ -237,6 +237,10 @@ class Payment extends Base {
'<label for="payment-details-surcharge-input">Add Surcharge:</label>'.
'<input id="payment-details-surcharge-input" type="checkbox">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="payment-details-deposit-input">Paid Deposit:</label>'.
'<input id="payment-details-deposit-input" type="checkbox">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="payment-details-buyer-group-select">'.
'Buyer Group:</label>'.
......@@ -417,7 +421,7 @@ class Payment extends Base {
$organiser = new Organiser($this->user, $this->owner);
$query = 'SELECT payment_totals.user, amount FROM payment_totals '.
'LEFT JOIN users ON payment_totals.user = users.user WHERE '.
'users.user NOT LIKE "buyer\_%" AND ('.$organiser->GroupQuery().')';
'users.user NOT LIKE "buyer\_%" AND '.$organiser->GroupQuery();
}
else {
$query = 'SELECT payment_totals.user, amount FROM payment_totals '.
......@@ -671,9 +675,8 @@ class Payment extends Base {
// Want the most recent payment that was manually entered, so ignore
// automatic deductions that get added when new accounts are created.
$query = 'SELECT MAX(timestamp) AS timestamp FROM payments LEFT JOIN '.
'users ON payments.user = users.user WHERE '.
'('.$organiser->GroupQuery().') AND '.
'comment != "Automatic deposit deduction for new user."';
'users ON payments.user = users.user WHERE '.$organiser->GroupQuery().
' AND comment != "Automatic deposit deduction for new user."';
if ($result = $mysqli->query($query)) {
while ($payments = $result->fetch_assoc()) {
$timestamp = (int)$payments["timestamp"];
......@@ -724,9 +727,9 @@ class Payment extends Base {
$username = $mysqli->escape_string($_POST["username"]);
if ($organiser->MatchUser($username)) {
$reference = $mysqli->escape_string($_POST["reference"]);
// The banking reference can't be empty, or longer than 6 characters.
if ($reference === "" || strlen($reference) > 6) {
$object["error"] = "Bank reference must be 6 characters or less.";
// The banking reference can't be empty, or longer than 20 characters.
if ($reference === "" || strlen($reference) > 20) {
$object["error"] = "Bank reference must be 20 characters or less.";
}
else {
$name = $mysqli->escape_string($_POST["name"]);
......@@ -734,10 +737,11 @@ class Payment extends Base {
$bsb = $mysqli->escape_string($_POST["bsb"]);
$credit = $mysqli->escape_string($_POST["credit"]);
$surcharge = $mysqli->escape_string($_POST["surcharge"]);
$deposit = $mysqli->escape_string($_POST["deposit"]);
$buyer_group = $mysqli->escape_string($_POST["buyerGroup"]);
$banking = new Banking($this->user, $this->owner);
$object = $banking->UpdateUser($username, $reference, $name, $number,
$bsb, $credit, $surcharge,
$bsb, $credit, $surcharge, $deposit,
$buyer_group);
}
}
......@@ -758,7 +762,8 @@ class Payment extends Base {
$reference = $mysqli->escape_string($_POST["reference"]);
$amount = $mysqli->escape_string($_POST["amount"]);
$comment = $mysqli->escape_string($_POST["comment"]);
$new_payment = $mysqli->escape_string($_POST["newPayment"]);
$new_payment = $_POST["newPayment"] == "true";
$import_mode = $_POST["importMode"] == "true";
// If the amount has a $ prefix remove it first.
if (substr($amount, 0, 1) === "$") {
$amount = substr($amount, 1);
......@@ -770,9 +775,6 @@ class Payment extends Base {
else if ($timestamp === 0) {
$object["error"] = "No date given";
}
else if ($reference === "") {
$object["error"] = "No reference given";
}
else if ((float)$amount < 0.001 && (float)$amount > -0.001) {
$object["error"] = "No amount given";
}
......@@ -781,20 +783,29 @@ class Payment extends Base {
$object["error"] = "User not found";
}
else {
if ($new_payment == "true") {
if ($new_payment) {
$exists = false;
// When entering a new payment make sure it gets a unique timestamp.
// (Unless in import mode, where a duplicate may have been imported).
do {
$exists = false;
$query = 'SELECT timestamp FROM payments WHERE '.
$query = 'SELECT timestamp, amount FROM payments WHERE '.
'user = "'.$username.'" AND timestamp = '.$timestamp;
if ($result = $mysqli->query($query)) {
if ($result->num_rows > 0) {
if ($payments = $result->fetch_assoc()) {
$exists = true;
$timestamp++;
if ($import_mode && $amount == $payments["amount"]) break;
}
else {
$exists = false;
}
$result->close();
}
} while ($exists);
if ($import_mode && $exists) {
$mysqli->close();
return array("exists" => true);
}
}
$query = 'INSERT INTO payments VALUES ("'.$username.'", '.
$timestamp.', "'.$reference.'", '.$amount.', "'.$comment.'", '.
......@@ -925,8 +936,7 @@ class Payment extends Base {
$organiser = new Organiser($this->user, $this->owner);
$query = 'SELECT payments.user, timestamp, reference, amount, comment '.
'FROM payments LEFT JOIN users ON payments.user = users.user WHERE '.
'('.$organiser->GroupQuery().') AND '.$search.
' ORDER BY timestamp DESC';
$organiser->GroupQuery().' AND '.$search.' ORDER BY timestamp DESC';
if ($result = $mysqli->query($query)) {
while ($payments = $result->fetch_assoc()) {
$amount = (float)$payments["amount"];
......
This diff is collapsed.
<?php
// Dobrado Content Management System
// Copyright (C) 2014 Malcolm Blaney
// Copyright (C) 2015 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -182,7 +182,7 @@ class Registration extends Base {
}
$user = new User($username, $group);
$status = new_user($user, $this->owner, $email, 0, $password);
$status = new_user($user, $this->owner, 1, $email, 0, $password);
if ($status === true) {
$detail = new Module($this->user, $this->owner, "detail");
if ($detail->IsInstalled()) {
......
......@@ -165,12 +165,12 @@ class Stock extends Base {
'</div>'.
'<div class="form-spacing">'.
'<label for="stock-user-input">Supplier:</label>'.
'<input id="stock-user-input" type="text" size="15" maxlength="50">'.
'<input id="stock-user-input" type="text" size="30" maxlength="50">'.
$add_supplier.
'</div>'.
'<div class="form-spacing">'.
'<label for="stock-name-input">Product:</label>'.
'<input id="stock-name-input" type="text" size="15" maxlength="100">'.
'<input id="stock-name-input" type="text" size="30" maxlength="100">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="stock-unit-select">Units:</label>'.
......@@ -198,7 +198,7 @@ class Stock extends Base {
$extra_pricing.
'<div class="form-spacing">'.
'<label for="stock-category-input">Category:</label>'.
'<input id="stock-category-input" type="text" size="15" '.
'<input id="stock-category-input" type="text" size="30" '.
'maxlength="100">'.
'</div>'.
'<div class="form-spacing">'.
......@@ -454,7 +454,7 @@ class Stock extends Base {
// Public functions that aren't part of interface here /////////////////////
public function AllProducts() {
public function AllProducts($array = true) {
$object = array();
$organiser = new Organiser($this->user, $this->owner);
......@@ -467,14 +467,30 @@ class Stock extends Base {
while ($stock = $result->fetch_assoc()) {
$available = $stock["order_available"] == "1" ||
$stock["purchase_available"] == "1";
$object[] = array("name" => $stock["name"],
"user" => $stock["user"],
"unit" => $stock["unit"],
"price" => (float)$stock["base_price"],
"wholesale" => (float)$stock["wholesale_price"],
"retail" => (float)$stock["retail_price"],
"available" => $available,
"composite" => (int)$stock["composite"]);
if ($array) {
$object[] = array("name" => $stock["name"],
"user" => $stock["user"],
"unit" => $stock["unit"],
"price" => (float)$stock["base_price"],
"wholesale" => (float)$stock["wholesale_price"],
"retail" => (float)$stock["retail_price"],
"available" => $available,
"composite" => (int)$stock["composite"]);
}
else {
$user = $stock["user"];
$name = $stock["name"];
if (!isset($object[$user])) {
$object[$user] = array();
}
$object[$user][$name] =
array("unit" => $stock["unit"],
"price" => (float)$stock["base_price"],
"wholesale" => (float)$stock["wholesale_price"],
"retail" => (float)$stock["retail_price"],
"available" => $available,
"composite" => (int)$stock["composite"]);
}
}
$result->close();
}
......@@ -532,7 +548,7 @@ class Stock extends Base {
'wholesale_price, retail_price, category, grower FROM stock LEFT JOIN '.
'users ON stock.user = users.user LEFT JOIN stock_supply_group ON '.
'stock_supply_group.user = stock.user WHERE composite = 0 AND '.
'('.$organiser->GroupQuery().') AND '.
$organiser->GroupQuery().' AND '.
'(stock_supply_group.system_group = "'.$this->user->group.'" OR '.
'stock_supply_group.system_group = "") '.$available_query.
' ORDER BY name, user';
......@@ -723,7 +739,7 @@ class Stock extends Base {
$mysqli = connect_db();
$query = 'SELECT stock.user FROM stock LEFT JOIN users ON '.
'stock.user = users.user WHERE name = "surcharge" AND '.
'('.$organiser->GroupQuery().')';
$organiser->GroupQuery();
if ($result = $mysqli->query($query)) {
if ($stock = $result->fetch_assoc()) {
$supplier = $stock["user"];
......@@ -941,7 +957,7 @@ class Stock extends Base {
$query = 'SELECT stock.user FROM stock LEFT JOIN users ON '.
'stock.user = users.user WHERE name = "'.$name.'" '.
'AND (order_available = 1 OR purchase_available = 1) '.
'AND stock.user != "'.$user.'" AND ('.$organiser->GroupQuery().')';
'AND stock.user != "'.$user.'" AND '.$organiser->GroupQuery();
if ($result = $mysqli->query($query)) {
if ($stock = $result->fetch_assoc()) {
$other = $stock["user"];
......@@ -1416,11 +1432,10 @@ class Stock extends Base {
$this->Log("Stock->ImportData 4: ".$mysqli->error);
}
}
$update_query = 'order_available = '.$order_available.
', purchase_available = '.$purchase_available.
', category = "'.$category.'", ';
// If a user is provided, don't update order_available,
// purchase_available or category as they're not imported.
$update_query = 'purchase_available = '.$purchase_available.
', category = "'.$category.'", ';
// If a user is provided, don't update purchase_available or
// category as they're not imported.
if ($user !== "") $update_query = "";
// On duplicate key allow the name to be updated too because it's case
// insensitive so this allows the case to be updated if required.
......@@ -1430,10 +1445,11 @@ class Stock extends Base {
', '.$purchase_available.', '.$supplier_available.', '.$taxable.', '.
$quantity.', 0) ON DUPLICATE KEY UPDATE name = "'.$name.'", '.
'unit = "'.$unit.'", pack_size = '.$size.', base_price = '.$base_price.
', wholesale_price = '.$wholesale_price.', '.
'retail_price = '.$retail_price.', '.$update_query.
'grower = "'.$grower.'", supplier_available = '.$supplier_available.
', taxable = '.$taxable.', quantity = quantity + '.$quantity;
', wholesale_price = '.$wholesale_price.', retail_price = '.
$retail_price.', order_available = '.$order_available.', '.
$update_query.'grower = "'.$grower.'", supplier_available = '.
$supplier_available.', taxable = '.$taxable.', '.
'quantity = quantity + '.$quantity;
if (!$mysqli->query($query)) {
$this->Log("Stock->ImportData 5: ".$mysqli->error);
}
......@@ -1533,7 +1549,7 @@ class Stock extends Base {
'wholesale_price, retail_price, category, grower, order_available, '.
'purchase_available, supplier_available, taxable, quantity FROM stock '.
'LEFT JOIN users ON stock.user = users.user WHERE '.
'('.$organiser->GroupQuery().')'.$available_query.' ORDER BY name, user';
$organiser->GroupQuery().$available_query.' ORDER BY name, user';
if ($result = $mysqli->query($query)) {
while ($stock = $result->fetch_assoc()) {
$user = $override_user !== "" ? $override_user : $stock["user"];
......
......@@ -3,7 +3,7 @@
// @licstart The following is the entire license notice
// for the JavaScript code in this page.
//
// Copyright (C) 2014 Malcolm Blaney
// Copyright (C) 2015 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -25,32 +25,33 @@
// for the JavaScript code in this page.
if(!this.dobrado.groupwizard){dobrado.groupwizard={};}
(function(){'use strict';var section=0;var total=0;$(function(){total=$(".groupwizard > div").length-1;$(".groupwizard").dialog({position:{my:"top",at:"top+50",of:"body"},title:"Group Settings Wizard",width:700,height:450,close:function(){$(".groupwizard").remove();}});$(".groupwizard .previous").button({disabled:true}).click(previous);$(".groupwizard .next").button().click(next);$(".groupwizard-purchase-other-order").click(dobrado.account.option);$(".groupwizard-purchase-volunteer").click(dobrado.account.option);$(".groupwizard-invoice-notifications").click(dobrado.account.option);$(".account").on("dialogopen",showGroup);$(".account").on("dialogfocus",showGroup);$("#groupwizard-pre-order-final-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$("#groupwizard-co-op-day-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$("#groupwizard-invoice-day-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$("#groupwizard-invoice-remove-orders-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$("#groupwizard-invoice-send-orders-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$(".groupwizard :input").change(save);if($("#groupwizard-pre-order").is(":checked")){$(".groupwizard-pre-order-settings").show();}
(function(){'use strict';var section=0;var total=0;$(function(){total=$(".groupwizard > div").length-1;$(".groupwizard").dialog({position:{my:"top",at:"top+50",of:"body"},title:"Group Settings Wizard",width:700,height:450,close:function(){$(".groupwizard").remove();}});$(".groupwizard .previous").button({disabled:true}).click(previous);$(".groupwizard .next").button().click(next);$(".groupwizard-purchase-other-order").click(dobrado.account.option);$(".groupwizard-purchase-volunteer").click(dobrado.account.option);$(".groupwizard-invoice-notifications").click(dobrado.account.option);$(".account").on("dialogopen",showGroup);$(".account").on("dialogfocus",showGroup);$("#groupwizard-pre-order-open-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$("#groupwizard-pre-order-final-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$("#groupwizard-co-op-day-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$("#groupwizard-invoice-day-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$("#groupwizard-invoice-remove-orders-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$("#groupwizard-invoice-send-orders-input").datepicker({dateFormat:dobrado.dateFormat,minDate:0});$(".groupwizard :input").change(save);if($("#groupwizard-pre-order").is(":checked")){$(".groupwizard-pre-order-settings").show();}
if($("#groupwizard-surcharge").is(":checked")){$(".groupwizard-payment-settings").show();}
if($("#groupwizard-stock-order-available").is(":checked")){$("#groupwizard-stock-order-update").parent().show();}
switchInput("pre-order-final");switchInput("co-op-day");switchInput("invoice-day");switchInput("invoice-remove-orders");switchInput("invoice-send-orders");});function previous(){$(".groupwizard-"+section).hide();section--;$(".groupwizard-"+section).show();if(section===0){$(".groupwizard .previous").button("option","disabled",true);}
switchInput("pre-order-open");switchInput("pre-order-final");switchInput("co-op-day");switchInput("invoice-day");switchInput("invoice-remove-orders");switchInput("invoice-send-orders");});function previous(){$(".groupwizard-"+section).hide();section--;$(".groupwizard-"+section).show();if(section===0){$(".groupwizard .previous").button("option","disabled",true);}
else{$(".groupwizard .previous").button("option","disabled",false);}
$(".groupwizard .next").button("option","disabled",false);}
function next(){$(".groupwizard-"+section).hide();section++;$(".groupwizard-"+section).show();if(section===total){$(".groupwizard .next").button("option","disabled",true);}
else{$(".groupwizard .next").button("option","disabled",false);}
$(".groupwizard .previous").button("option","disabled",false);}
function save(){var value="";var label=$(this).attr("id").substr(12);if(label==="pre-order-final-select"||label==="pre-order-final-input"){label="pre-order-final";}
function save(){var value="";var label=$(this).attr("id").substr(12);if(label==="pre-order-open-select"||label==="pre-order-open-input"){label="pre-order-open";}
else if(label==="pre-order-final-select"||label==="pre-order-final-input"){label="pre-order-final";}
else if(label==="co-op-day-select"||label==="co-op-day-input"){label="co-op-day";}
else if(label==="invoice-day-select"||label==="invoice-day-input"){label="invoice-day";}
else if(label==="invoice-send-orders-select"||label==="invoice-send-orders-input"){label="invoice-send-orders";}
else if(label==="invoice-remove-orders-select"||label==="invoice-remove-orders-input"){label="invoice-remove-orders";}
if(label==="pre-order-final-date"){$("#groupwizard-pre-order-final-input").parent().toggle();$("#groupwizard-pre-order-final-select").parent().toggle();return;}
if(label==="co-op-day-date"){$("#groupwizard-co-op-day-input").parent().toggle();$("#groupwizard-co-op-day-select").parent().toggle();return;}
if(label==="invoice-day-date"){$("#groupwizard-invoice-day-input").parent().toggle();$("#groupwizard-invoice-day-select").parent().toggle();return;}
if(label==="invoice-send-orders-date"){$("#groupwizard-invoice-send-orders-input").parent().toggle();$("#groupwizard-invoice-send-orders-select").parent().toggle();return;}
if(label==="invoice-remove-orders-date"){$("#groupwizard-invoice-remove-orders-input").parent().toggle();$("#groupwizard-invoice-remove-orders-select").parent().toggle();return;}
if(label==="pre-order-open-date"){$("#groupwizard-pre-order-open-input").val("").parent().toggle();$("#groupwizard-pre-order-open-select").val("").parent().toggle();return;}
if(label==="pre-order-final-date"){$("#groupwizard-pre-order-final-input").val("").parent().toggle();$("#groupwizard-pre-order-final-select").val("").parent().toggle();return;}
if(label==="co-op-day-date"){$("#groupwizard-co-op-day-input").val("").parent().toggle();$("#groupwizard-co-op-day-select").val("").parent().toggle();return;}
if(label==="invoice-day-date"){$("#groupwizard-invoice-day-input").val("").parent().toggle();$("#groupwizard-invoice-day-select").val("").parent().toggle();return;}
if(label==="invoice-send-orders-date"){$("#groupwizard-invoice-send-orders-input").val("").parent().toggle();$("#groupwizard-invoice-send-orders-select").val("").parent().toggle();return;}
if(label==="invoice-remove-orders-date"){$("#groupwizard-invoice-remove-orders-input").val("").parent().toggle();$("#groupwizard-invoice-remove-orders-select").val("").parent().toggle();return;}
if($(this).is(":checkbox")){value=$(this).is(":checked")?"true":"false";}
else{value=$(this).val();}
dobrado.log("Saving setting.","info");$.post("/php/request.php",{request:"groupwizard",label:label,value:value,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"save wizard setting")){return false;}
if(label==="pre-order"){$(".groupwizard-pre-order-settings").toggle();}
if(label==="surcharge"){$(".groupwizard-payment-settings").toggle();}
if(label==="stock-order-available"){$("#groupwizard-stock-order-update").parent().toggle();}
if(label==="pre-order-wait"||label=="pre-order-final"||label=="pre-order-final-time"){var wizard=JSON.parse(response);$(".groupwizard-pre-order-open").html(wizard.content);}});}
if(label==="stock-order-available"){$("#groupwizard-stock-order-update").parent().toggle();}});}
function switchInput(label){label="#groupwizard-"+label;if($(label+"-input").val()!==""){$(label+"-date").prop("checked",true);$(label+"-input").parent().show();$(label+"-select").parent().hide();}}
function showGroup(){$("#account-tabs").tabs("option","active",1);if(section===1){$("#group-input").val("admin/purchase-other-order");}
else if(section===2){$("#group-input").val("admin/purchase-volunteer");}
......
......@@ -57,6 +57,8 @@ if (!this.dobrado.groupwizard) {
// Need to also update on focus in case it's already open.
$(".account").on("dialogfocus", showGroup);
// Some fields switch between datepickers and selects.
$("#groupwizard-pre-order-open-input").datepicker({
dateFormat: dobrado.dateFormat, minDate: 0 });
$("#groupwizard-pre-order-final-input").datepicker({
dateFormat: dobrado.dateFormat, minDate: 0 });
$("#groupwizard-co-op-day-input").datepicker({
......@@ -81,6 +83,7 @@ if (!this.dobrado.groupwizard) {
$("#groupwizard-stock-order-update").parent().show();
}
// Some input methods need to be switched depending on their current value.
switchInput("pre-order-open");
switchInput("pre-order-final");
switchInput("co-op-day");
switchInput("invoice-day");
......@@ -119,48 +122,58 @@ if (!this.dobrado.groupwizard) {
// Remove the "groupwizard-" prefix from the label.
var label = $(this).attr("id").substr(12);
// Some labels have a suffix for different input modes.
if (label === "pre-order-final-select" ||
label === "pre-order-final-input") {
if (label === "pre-order-open-select" || label === "pre-order-open-input") {
label = "pre-order-open";
}
else if (label === "pre-order-final-select" ||
label === "pre-order-final-input") {
label = "pre-order-final";
}
else if (label === "co-op-day-select" || label === "co-op-day-input" ) {
else if (label === "co-op-day-select" || label === "co-op-day-input") {
label = "co-op-day";
}
else if (label === "invoice-day-select" || label === "invoice-day-input" ) {
else if (label === "invoice-day-select" || label === "invoice-day-input") {
label = "invoice-day";
}
else if (label === "invoice-send-orders-select" ||
label === "invoice-send-orders-input" ) {
label === "invoice-send-orders-input") {
label = "invoice-send-orders";
}
else if (label === "invoice-remove-orders-select" ||
label === "invoice-remove-orders-input" ) {
label === "invoice-remove-orders-input") {
label = "invoice-remove-orders";
}
// Some label don't need to be saved, they're just used to toggle content.
// Toggle input types when date input checkboxes are changed, and clear
// the current value to force a change event.
if (label === "pre-order-open-date") {
$("#groupwizard-pre-order-open-input").val("").parent().toggle();
$("#groupwizard-pre-order-open-select").val("").parent().toggle();
return;
}
if (label === "pre-order-final-date") {
$("#groupwizard-pre-order-final-input").parent().toggle();
$("#groupwizard-pre-order-final-select").parent().toggle();
$("#groupwizard-pre-order-final-input").val("").parent().toggle();
$("#groupwizard-pre-order-final-select").val("").parent().toggle();
return;
}
if (label === "co-op-day-date") {
$("#groupwizard-co-op-day-input").parent().toggle();
$("#groupwizard-co-op-day-select").parent().toggle();
$("#groupwizard-co-op-day-input").val("").parent().toggle();
$("#groupwizard-co-op-day-select").val("").parent().toggle();
return;
}
if (label === "invoice-day-date") {
$("#groupwizard-invoice-day-input").parent().toggle();
$("#groupwizard-invoice-day-select").parent().toggle();
$("#groupwizard-invoice-day-input").val("").parent().toggle();
$("#groupwizard-invoice-day-select").val("").parent().toggle();
return;
}
if (label === "invoice-send-orders-date") {
$("#groupwizard-invoice-send-orders-input").parent().toggle();
$("#groupwizard-invoice-send-orders-select").parent().toggle();
$("#groupwizard-invoice-send-orders-input").val("").parent().toggle();
$("#groupwizard-invoice-send-orders-select").val("").parent().toggle();
return;
}
if (label === "invoice-remove-orders-date") {
$("#groupwizard-invoice-remove-orders-input").parent().toggle();
$("#groupwizard-invoice-remove-orders-select").parent().toggle();
$("#groupwizard-invoice-remove-orders-input").val("").parent().toggle();
$("#groupwizard-invoice-remove-orders-select").val("").parent().toggle();
return;
}
......@@ -191,13 +204,6 @@ if (!this.dobrado.groupwizard) {
if (label === "stock-order-available") {
$("#groupwizard-stock-order-update").parent().toggle();
}
// Since pre-order-wait is set in hours, the opening date is updated
// and returned whenever the value changes, or pre-order-final[-time].
if (label === "pre-order-wait" ||
label == "pre-order-final" || label == "pre-order-final-time") {
var wizard = JSON.parse(response);
$(".groupwizard-pre-order-open").html(wizard.content);
}
});
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,7 @@
// @licstart The following is the entire license notice
// for the JavaScript code in this page.
//
// Copyright (C) 2014 Malcolm Blaney
// Copyright (C) 2015 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -112,7 +112,6 @@ if (!this.dobrado.manager) {
$("#manager-supplier-input").val("").change(function() {
setTimeout(function() { showSupplierFromMenu(); }, 10);