From e8346243aebd285160b21b359a40cb5dee72bd9d Mon Sep 17 00:00:00 2001 From: Aaron Jackson Date: Fri, 13 Dec 2024 18:53:44 +0000 Subject: [PATCH] Allow a tool to override tran_type --- procedures/sp_tool_charge.sql | 15 +++++++++------ views/vw_payment.sql | 8 +++++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/procedures/sp_tool_charge.sql b/procedures/sp_tool_charge.sql index 1a90dd3..dfba278 100644 --- a/procedures/sp_tool_charge.sql +++ b/procedures/sp_tool_charge.sql @@ -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,7 +54,8 @@ BEGIN tu.status, ifnull(t.pph, 0), t.name, - t.status + t.status, + ifnull(t.transaction_type_override, 'TOOL') into member_id, tool_id, @@ -61,7 +63,8 @@ BEGIN 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; diff --git a/views/vw_payment.sql b/views/vw_payment.sql index 358d49a..1dd36c4 100644 --- a/views/vw_payment.sql +++ b/views/vw_payment.sql @@ -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))