2024-08-21 01:36:12 +00:00
|
|
|
-- Deploy numerus:remove_collection to pg
|
|
|
|
-- requires: roles
|
|
|
|
-- requires: schema_numerus
|
2025-01-30 22:24:16 +00:00
|
|
|
-- requires: invoice_payment
|
|
|
|
-- requires: payment
|
|
|
|
-- requires: payment_attachment
|
2024-08-21 01:36:12 +00:00
|
|
|
-- requires: update_invoice_collection_status
|
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
|
|
set search_path to numerus, public;
|
|
|
|
|
|
|
|
create or replace function remove_collection(collection_slug uuid) returns void as
|
|
|
|
$$
|
|
|
|
declare
|
|
|
|
cid integer;
|
|
|
|
iid integer;
|
|
|
|
begin
|
2025-01-30 22:24:16 +00:00
|
|
|
select payment_id into cid from payment where slug = collection_slug;
|
2024-08-21 01:36:12 +00:00
|
|
|
if not found then
|
|
|
|
return;
|
|
|
|
end if;
|
|
|
|
|
2025-01-30 22:24:16 +00:00
|
|
|
delete from invoice_payment where payment_id = cid returning invoice_id into iid;
|
2024-08-21 01:36:12 +00:00
|
|
|
if iid is not null then
|
|
|
|
perform update_invoice_collection_status(null, iid, 0);
|
|
|
|
end if;
|
|
|
|
|
2025-01-30 22:24:16 +00:00
|
|
|
delete from payment_attachment where payment_id = cid;
|
|
|
|
delete from payment where payment_id = cid;
|
2024-08-21 01:36:12 +00:00
|
|
|
end
|
|
|
|
$$
|
|
|
|
language plpgsql
|
|
|
|
;
|
|
|
|
|
|
|
|
revoke execute on function remove_collection(uuid) from public;
|
|
|
|
grant execute on function remove_collection(uuid) to invoicer;
|
|
|
|
grant execute on function remove_collection(uuid) to admin;
|
|
|
|
|
|
|
|
commit;
|