Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
-- Test edit_payment
|
|
|
|
|
set client_min_messages to warning;
|
|
|
|
|
create extension if not exists pgtap;
|
|
|
|
|
reset client_min_messages;
|
|
|
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
2024-08-15 01:51:30 +00:00
|
|
|
|
select plan(17);
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
|
|
|
|
|
set search_path to numerus, public;
|
|
|
|
|
|
|
|
|
|
select has_function('numerus', 'edit_payment', array['uuid', 'date', 'integer', 'text', 'text', 'tag_name[]']);
|
|
|
|
|
select function_lang_is('numerus', 'edit_payment', array['uuid', 'date', 'integer', 'text', 'text', 'tag_name[]'], 'plpgsql');
|
|
|
|
|
select function_returns('numerus', 'edit_payment', array['uuid', 'date', 'integer', 'text', 'text', 'tag_name[]'], 'uuid');
|
|
|
|
|
select isnt_definer('numerus', 'edit_payment', array['uuid', 'date', 'integer', 'text', 'text', 'tag_name[]']);
|
|
|
|
|
select volatility_is('numerus', 'edit_payment', array['uuid', 'date', 'integer', 'text', 'text', 'tag_name[]'], 'volatile');
|
|
|
|
|
|
|
|
|
|
select function_privs_are('numerus', 'edit_payment', array ['uuid', 'date', 'integer', 'text', 'text', 'tag_name[]'], 'guest', array []::text[]);
|
|
|
|
|
select function_privs_are('numerus', 'edit_payment', array ['uuid', 'date', 'integer', 'text', 'text', 'tag_name[]'], 'invoicer', array ['EXECUTE']);
|
|
|
|
|
select function_privs_are('numerus', 'edit_payment', array ['uuid', 'date', 'integer', 'text', 'text', 'tag_name[]'], 'admin', array ['EXECUTE']);
|
|
|
|
|
select function_privs_are('numerus', 'edit_payment', array ['uuid', 'date', 'integer', 'text', 'text', 'tag_name[]'], 'authenticator', array []::text[]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set client_min_messages to warning;
|
|
|
|
|
truncate expense_payment cascade;
|
|
|
|
|
truncate payment cascade;
|
2024-08-15 01:51:30 +00:00
|
|
|
|
truncate expense_tax cascade;
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
truncate expense cascade;
|
|
|
|
|
truncate contact cascade;
|
2024-08-15 01:51:30 +00:00
|
|
|
|
truncate tax cascade;
|
|
|
|
|
truncate tax_class cascade;
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
truncate payment_account cascade;
|
|
|
|
|
truncate payment_method cascade;
|
|
|
|
|
truncate company cascade;
|
|
|
|
|
reset client_min_messages;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set constraints "company_default_payment_method_id_fkey" deferred;
|
|
|
|
|
|
|
|
|
|
insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, country_code, currency_code, default_payment_method_id)
|
|
|
|
|
values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', 'ES', 'EUR', 111)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
insert into payment_method (payment_method_id, company_id, name, instructions)
|
|
|
|
|
values (111, 1, 'cash', 'cash')
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
set constraints "company_default_payment_method_id_fkey" immediate;
|
|
|
|
|
|
2024-08-15 01:51:30 +00:00
|
|
|
|
insert into tax_class (tax_class_id, company_id, name)
|
|
|
|
|
values (11, 1, 'tax')
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
insert into tax (tax_id, company_id, tax_class_id, name, rate)
|
|
|
|
|
values (2, 1, 11, 'IRPF -15 %', -0.15)
|
|
|
|
|
, (3, 1, 11, 'IVA 4 %', 0.04)
|
|
|
|
|
, (4, 1, 11, 'IVA 10 %', 0.10)
|
|
|
|
|
;
|
|
|
|
|
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
insert into contact (contact_id, company_id, name)
|
|
|
|
|
values ( 9, 1, 'Customer 1')
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
insert into expense (expense_id, company_id, invoice_number, contact_id, invoice_date, amount, currency_code, expense_status)
|
|
|
|
|
values (13, 1, 'INV001', 9, '2011-01-11', 111, 'EUR', 'paid')
|
|
|
|
|
, (14, 1, 'INV002', 9, '2022-02-22', 222, 'EUR', 'paid')
|
|
|
|
|
, (15, 1, 'INV003', 9, '2022-02-22', 333, 'EUR', 'partial')
|
2024-08-15 01:51:30 +00:00
|
|
|
|
, (16, 1, 'REF001', 9, '2023-03-03', 10000, 'EUR', 'paid')
|
|
|
|
|
, (17, 1, 'REF002', 9, '2023-03-03', 10000, 'EUR', 'paid')
|
|
|
|
|
, (18, 1, 'REF003', 9, '2023-03-03', 10000, 'EUR', 'paid')
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
insert into expense_tax (expense_id, tax_id, tax_rate)
|
|
|
|
|
values (16, 3, 0.04)
|
|
|
|
|
, (17, 2, -0.15)
|
|
|
|
|
, (18, 2, -0.15)
|
|
|
|
|
, (18, 4, 0.10)
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
insert into payment_account (payment_account_id, company_id, payment_account_type, name)
|
|
|
|
|
values (11, 1, 'cash', 'Cash 1')
|
|
|
|
|
, (12, 1, 'cash', 'Cash 2')
|
|
|
|
|
, (13, 1, 'other', 'Other')
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
insert into payment (payment_id, company_id, slug, description, payment_date, payment_account_id, amount, currency_code, payment_status, tags)
|
|
|
|
|
values (16, 1, '7ac3ae0e-b0c1-4206-a19b-0be20835edd4', 'Payment INV001', '2023-05-04', 12, 111, 'EUR', 'complete', '{tag1}')
|
|
|
|
|
, (17, 1, 'b57b980b-247b-4be4-a0b7-03a7819c53ae', 'First INV002', '2023-05-05', 13, 100, 'EUR', 'partial', '{tag2}')
|
|
|
|
|
, (18, 1, '3bdad7a8-4a1e-4ae0-b5c6-015e51ee0502', 'Second INV002', '2023-05-06', 13, 122, 'EUR', 'partial', '{tag1,tag3}')
|
|
|
|
|
, (19, 1, '5a524bee-8311-4d13-9adf-ef6310b26990', 'Partial INV003', '2023-05-07', 11, 123, 'EUR', 'partial', '{}')
|
2024-08-15 01:51:30 +00:00
|
|
|
|
, (20, 1, '65222c3b-4faa-4be4-b39c-5bd170a943cf', 'Re: REF001', '2023-03-07', 11, 10400, 'EUR', 'complete', '{}')
|
|
|
|
|
, (21, 1, 'dbb699cf-d1f4-40ff-96cb-8f29e238d51d', 'Re: REF002', '2023-03-07', 11, 8500, 'EUR', 'complete', '{}')
|
|
|
|
|
, (22, 1, '0756a50f-2957-4661-abd2-e422a848af4e', 'Re: REF003', '2023-03-07', 11, 9500, 'EUR', 'complete', '{}')
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
insert into expense_payment (expense_id, payment_id)
|
|
|
|
|
values (13, 16)
|
|
|
|
|
, (14, 17)
|
|
|
|
|
, (14, 18)
|
|
|
|
|
, (15, 19)
|
2024-08-15 01:51:30 +00:00
|
|
|
|
, (16, 20)
|
|
|
|
|
, (17, 21)
|
|
|
|
|
, (18, 22)
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
select lives_ok(
|
|
|
|
|
$$ select edit_payment('7ac3ae0e-b0c1-4206-a19b-0be20835edd4', '2023-05-06', 13, 'Partial INV001', '1.00', array['tag1']) $$,
|
|
|
|
|
'Should be able to change a complete payment to partial'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
select lives_ok(
|
|
|
|
|
$$ select edit_payment('b57b980b-247b-4be4-a0b7-03a7819c53ae', '2023-05-07', 12, 'First INV002', '0.50', array['tag1', 'tag3']) $$,
|
|
|
|
|
'Should be able to adjust a partial payment, that is still partial, and the expense now becomes partial'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
select lives_ok(
|
|
|
|
|
$$ select edit_payment('5a524bee-8311-4d13-9adf-ef6310b26990', '2023-05-01', 11, 'Complete INV003', '3.33', array[]::tag_name[]) $$,
|
|
|
|
|
'Should be able to complete a previously partial payment'
|
|
|
|
|
);
|
|
|
|
|
|
2024-08-15 01:51:30 +00:00
|
|
|
|
select lives_ok(
|
|
|
|
|
$$ select edit_payment('65222c3b-4faa-4be4-b39c-5bd170a943cf', '2023-03-10', 11, 'Re: REF001', '103.99', array[]::tag_name[]) $$,
|
|
|
|
|
'Should be able to make partial a payment with tax.'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
select lives_ok(
|
|
|
|
|
$$ select edit_payment('dbb699cf-d1f4-40ff-96cb-8f29e238d51d', '2023-03-10', 11, 'Re: REF002', '84.99', array[]::tag_name[]) $$,
|
|
|
|
|
'Should be able to make partial a payment with negative tax.'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
select lives_ok(
|
|
|
|
|
$$ select edit_payment('0756a50f-2957-4661-abd2-e422a848af4e', '2023-03-10', 11, 'Re: REF003', '94.99', array[]::tag_name[]) $$,
|
|
|
|
|
'Should be able to make partial a payment with multiple taxe.'
|
|
|
|
|
);
|
|
|
|
|
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
select bag_eq(
|
|
|
|
|
$$ select description, payment_date::text, payment_account_id, amount, payment_status, tags::text from payment $$,
|
|
|
|
|
$$ values ('Partial INV001', '2023-05-06', 13, 100, 'partial', '{tag1}')
|
|
|
|
|
, ('First INV002', '2023-05-07', 12, 50, 'partial', '{tag1,tag3}')
|
|
|
|
|
, ('Second INV002', '2023-05-06', 13, 122, 'partial', '{tag1,tag3}')
|
|
|
|
|
, ('Complete INV003', '2023-05-01', 11, 333, 'complete', '{}')
|
2024-08-15 01:51:30 +00:00
|
|
|
|
, ('Re: REF001', '2023-03-10', 11, 10399, 'partial', '{}')
|
|
|
|
|
, ('Re: REF002', '2023-03-10', 11, 8499, 'partial', '{}')
|
|
|
|
|
, ('Re: REF003', '2023-03-10', 11, 9499, 'partial', '{}')
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
$$,
|
|
|
|
|
'Should have updated all payments'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
select bag_eq(
|
|
|
|
|
$$ select expense_id, expense_status from expense $$,
|
|
|
|
|
$$ values (13, 'partial')
|
|
|
|
|
, (14, 'partial')
|
|
|
|
|
, (15, 'paid')
|
2024-08-15 01:51:30 +00:00
|
|
|
|
, (16, 'partial')
|
|
|
|
|
, (17, 'partial')
|
|
|
|
|
, (18, 'partial')
|
Add the payments section
This actually should be the “payments and receivables” section, however
this is quite a mouthful; a “receivable” is a payment made **to** you,
therefore “payments” is ok.
In fact, there is still no receivables in there, as they should be in
a separate relation, to constraint them to invoices instead of expenses.
It will be done in a separate commit.
Since this section will be, in a sense, sort of simplified accounting,
i needed to introduce the “payment account” concept. There is no way,
yet, for users to add them, because i have to revamp the “tax details”
section, but this commit started to grow too big already.
The same reasoning for the attachment payment slips as PDF to payment:
something i have to add, but not yet in this commit.
2024-08-10 02:34:07 +00:00
|
|
|
|
$$,
|
|
|
|
|
'Should have updated expenses too'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select *
|
|
|
|
|
from finish();
|
|
|
|
|
|
|
|
|
|
rollback;
|