Customer wants to require a down payment of 30 % for bookings made one week or more before the actual date, and to make the full payment otherwise. This would require yet another relation to keep these values. Fuck it; i added them to the function, as they are very unlikely to change. That forced me to change the test for draft_payment to use relative dates, otherwise there is no way i can have stable results in the future.
24 lines
555 B
PL/PgSQL
24 lines
555 B
PL/PgSQL
-- Deploy camper:down_payment to pg
|
|
-- requires: roles
|
|
-- requires: schema_camper
|
|
-- requires: payment
|
|
|
|
begin;
|
|
|
|
set search_path to camper, public;
|
|
|
|
create or replace function down_payment(p payment) returns integer as
|
|
$$
|
|
select round(p.total * p.down_payment_percent)::integer;
|
|
$$
|
|
language sql
|
|
stable
|
|
;
|
|
|
|
revoke execute on function down_payment(payment) from public;
|
|
grant execute on function down_payment(payment) to guest;
|
|
grant execute on function down_payment(payment) to employee;
|
|
grant execute on function down_payment(payment) to admin;
|
|
|
|
commit;
|