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
|
|
|
-- Deploy numerus:payment to pg
|
|
|
|
-- requires: roles
|
|
|
|
-- requires: schema_numerus
|
|
|
|
-- requires: company
|
|
|
|
-- requires: payment_account
|
|
|
|
-- requires: currency
|
|
|
|
-- requires: tag_name
|
|
|
|
-- requires: payment_status
|
|
|
|
-- requires: extension_pgcrypto
|
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
|
|
set search_path to numerus, public;
|
|
|
|
|
|
|
|
create table payment (
|
|
|
|
payment_id integer generated by default as identity primary key,
|
|
|
|
company_id integer not null references company,
|
|
|
|
slug uuid not null unique default gen_random_uuid(),
|
|
|
|
description text not null,
|
|
|
|
payment_date date not null default current_date,
|
|
|
|
payment_account_id integer not null references payment_account,
|
2024-08-18 03:20:36 +00:00
|
|
|
amount integer not null constraint payment_amount_positive check (amount > 0),
|
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
|
|
|
currency_code text not null references currency,
|
|
|
|
tags tag_name[] not null default '{}',
|
|
|
|
payment_status text not null default 'complete' references payment_status,
|
|
|
|
created_at timestamptz not null default current_timestamp
|
|
|
|
);
|
|
|
|
|
|
|
|
create index on payment using gin (tags);
|
|
|
|
|
|
|
|
grant select, insert, update, delete on table payment to invoicer;
|
|
|
|
grant select, insert, update, delete on table payment to admin;
|
|
|
|
|
|
|
|
alter table payment enable row level security;
|
|
|
|
|
|
|
|
create policy company_policy
|
|
|
|
on payment
|
|
|
|
using (
|
|
|
|
exists(
|
|
|
|
select 1
|
|
|
|
from company_user
|
|
|
|
join user_profile using (user_id)
|
|
|
|
where company_user.company_id = payment.company_id
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
commit;
|