camper/revert/set_campsite_type_option_cost.sql
jordi fita mas ea997a4154 Allow campsite type option to be just per unit, not per unit per night
Customer told us that there are some options, such as towels, that have
a fixed price for the whole stay, not a per night price.  Thus, had to
add a boolean to know whether to use sum or max when computing the
cart’s total for each option.
2024-02-11 21:45:00 +01:00

28 lines
974 B
PL/PgSQL

-- Deploy camper:set_campsite_type_option_cost to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite_type_option_cost
-- requires: parse_price
begin;
set search_path to camper, public;
drop function if exists set_campsite_type_option_cost(integer, integer, text, integer);
create or replace function set_campsite_type_option_cost(option_id integer, season_id integer, cost_per_night text, decimal_places integer default 2) returns void as
$$
insert into campsite_type_option_cost (campsite_type_option_id, season_id, cost_per_night)
values (option_id, season_id, parse_price(cost_per_night, decimal_places))
on conflict (campsite_type_option_id, season_id) do update
set cost_per_night = excluded.cost_per_night
;
$$
language sql
;
revoke execute on function set_campsite_type_option_cost(integer, integer, text, integer) from public;
grant execute on function set_campsite_type_option_cost(integer, integer, text, integer) to admin;
commit;