campingmontagut/deploy/payment.sql
jordi fita mas f2143cd0e6 Add the admin page to see payments
Had to do a couple of changes to the database: add the currency_code to
the payment relation, to format the price according to the payment’s
currency instead of the company’s; and the reference SQL function, to
replace the equivalent golang function, so that i can use it to index
payments.

The rest is mostly the same as any other page, except that the
individual payment’s page is not a form, but a regular info dump.

I also moved the payment settings as a sub-route of payments, as i
believe this makes more sense than an additional user menu item.
2024-02-14 04:54:42 +01:00

48 lines
1.7 KiB
PL/PgSQL

-- Deploy camper:payment to pg
-- requires: roles
-- requires: schema_camper
-- requires: company
-- requires: campsite_type
-- requires: payment_status
-- requires: positive_integer
-- requires: nonnegative_integer
-- requires: percentage
-- requires: currency_code
-- requires: currency
begin;
set search_path to camper, 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(),
campsite_type_id integer not null references campsite_type,
arrival_date date not null,
departure_date date not null constraint departure_after_arrival check (departure_date > arrival_date),
subtotal_nights nonnegative_integer not null,
number_adults positive_integer not null,
subtotal_adults nonnegative_integer not null,
number_teenagers nonnegative_integer not null,
subtotal_teenagers nonnegative_integer not null,
number_children nonnegative_integer not null,
subtotal_children nonnegative_integer not null,
number_dogs nonnegative_integer not null,
subtotal_dogs nonnegative_integer not null,
subtotal_tourist_tax nonnegative_integer not null,
total nonnegative_integer not null,
currency_code currency_code not null references currency,
down_payment_percent percentage not null default 1.0,
zone_preferences text not null,
payment_status text not null default 'draft' references payment_status,
created_at timestamp with time zone not null default current_timestamp,
updated_at timestamp with time zone not null default current_timestamp
);
grant select, insert, update on table payment to guest;
grant select, insert, update on table payment to employee;
grant select, insert, update, delete on table payment to admin;
commit;