Skip to content

Allow a tool's transaction type to be overridden #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: hms2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions procedures/sp_tool_charge.sql
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ BEGIN
declare full_rate int;
declare amount int;
declare tran_desc varchar(512);
declare tran_type varchar(255);
declare tool_name varchar(20);
declare tool_status varchar(20);
declare tran_id int;
@@ -53,15 +54,17 @@ BEGIN
tu.status,
ifnull(t.pph, 0),
t.name,
t.status
t.status,
ifnull(t.transaction_type_override, 'TOOL')
into
member_id,
tool_id,
usage_start,
usage_status,
tool_pph,
tool_name,
tool_status
tool_status,
tran_type
from tool_usages tu
inner join tools t on tu.tool_id = t.id
where tu.id = p_usage_id;
@@ -108,7 +111,7 @@ BEGIN
set amount = 0;
set tran_desc = concat('[', sec_to_time(new_usage_duration), '] of [', tool_name, '] use @ £0.00 p/h (maintenance)');

call sp_transaction_log(member_id, amount, 'TOOL', 'COMPLETE', tran_desc, null, tran_id, p_msg);
call sp_transaction_log(member_id, amount, tran_type, 'COMPLETE', tran_desc, null, tran_id, p_msg);
if (length(p_msg) > 0) then
set err = 1;
leave main;
@@ -123,7 +126,7 @@ BEGIN
where tu.user_id = member_id
and tu.tool_id = tool_id
and tu.status = 'COMPLETE';

-- calc zero-rate charges (i.e. take into account any unspent pledged time)
if (acc_usage_duration <= 0) then
set zero_rate = new_usage_duration; -- tool_usage still has a -ve usage time, so no charges apply yet
@@ -144,7 +147,7 @@ BEGIN
set amount = 0;
set tran_desc = concat('[', sec_to_time(zero_rate), '] of [', tool_name, '] use @ £', format((0)/100, 2), ' p/h');

call sp_transaction_log(member_id, amount, 'TOOL', 'COMPLETE', tran_desc, null, tran_id, p_msg);
call sp_transaction_log(member_id, amount, tran_type, 'COMPLETE', tran_desc, null, tran_id, p_msg);
if (length(p_msg) > 0) then
set err = 1;
leave main;
@@ -156,7 +159,7 @@ BEGIN
set amount = -1*(full_rate * (tool_pph/3600));
set tran_desc = concat('[', sec_to_time(full_rate), '] of [', tool_name, '] use @ £', format((tool_pph)/100, 2), ' p/h');

call sp_transaction_log(member_id, amount, 'TOOL', 'COMPLETE', tran_desc, null, tran_id, p_msg);
call sp_transaction_log(member_id, amount, tran_type, 'COMPLETE', tran_desc, null, tran_id, p_msg);
if (length(p_msg) > 0) then
set err = 1;
leave main;
8 changes: 7 additions & 1 deletion views/vw_payment.sql
Original file line number Diff line number Diff line change
@@ -28,7 +28,13 @@ SELECT
IFNULL(SUM(pp.amount), 0)
FROM (purchase_payment pp
JOIN transactions t2 ON (t2.id = pp.transaction_id_purchase))
WHERE ((pp.transaction_id_payment = t.id) AND (t2.transaction_type NOT IN ('TOOL', 'VEND', 'BOX')))
WHERE ((pp.transaction_id_payment = t.id) AND (t2.transaction_type = 'HEAT'))
) AS for_heat,
(SELECT
IFNULL(SUM(pp.amount), 0)
FROM (purchase_payment pp
JOIN transactions t2 ON (t2.id = pp.transaction_id_purchase))
WHERE ((pp.transaction_id_payment = t.id) AND (t2.transaction_type NOT IN ('TOOL', 'VEND', 'BOX', 'HEAT')))
) AS for_other
FROM (transactions t
JOIN user u ON (u.id = t.user_id))