Add database update for event billing
This commit is contained in:
parent
618c0229bd
commit
868e6aa645
|
@ -0,0 +1,66 @@
|
|||
-- Delete permissions
|
||||
DELETE
|
||||
FROM permissions
|
||||
WHERE permission LIKE 'modules.event#_billing.personnel.view' ESCAPE '#';
|
||||
|
||||
DELETE
|
||||
FROM permissions
|
||||
WHERE permission LIKE 'modules.event#_billing.start#_end#_times.edit' ESCAPE '#';
|
||||
|
||||
DELETE
|
||||
FROM permissions
|
||||
WHERE permission LIKE 'modules.event#_billing.view' ESCAPE '#';
|
||||
|
||||
DELETE
|
||||
FROM permissions
|
||||
WHERE permission LIKE 'modules.event#_billing.start#_end#_times.view' ESCAPE '#';
|
||||
|
||||
DELETE
|
||||
FROM permissions
|
||||
WHERE permission LIKE 'modules.event#_billing.approve' ESCAPE '#';
|
||||
|
||||
DELETE
|
||||
FROM permissions
|
||||
WHERE permission LIKE 'modules.event#_billing.personnel.edit' ESCAPE '#';
|
||||
|
||||
-- Drop Table personnel_billing
|
||||
DROP TABLE IF EXISTS personnel_billing;
|
||||
|
||||
-- Remove real_start_time and real_end_time from eu_position_instances
|
||||
|
||||
alter table eu_position_instances
|
||||
drop column real_start_time;
|
||||
|
||||
alter table eu_position_instances
|
||||
drop column real_end_time;
|
||||
|
||||
-- Remove fields planned_start_time, planned_end_time, real_start_time, real_end_time, billing_rate_id and billing_state_id from eu_instances
|
||||
alter table eu_instances
|
||||
drop constraint eu_instances_billing_states_state_id_fk;
|
||||
|
||||
alter table eu_instances
|
||||
drop constraint eu_instances_personnel_billing_rates_billing_rate_id_fk;
|
||||
|
||||
alter table eu_instances
|
||||
drop column planned_start_time;
|
||||
|
||||
alter table eu_instances
|
||||
drop column planned_end_time;
|
||||
|
||||
alter table eu_instances
|
||||
drop column real_start_time;
|
||||
|
||||
alter table eu_instances
|
||||
drop column real_end_time;
|
||||
|
||||
alter table eu_instances
|
||||
drop column billing_rate_id;
|
||||
|
||||
alter table eu_instances
|
||||
drop column billing_state_id;
|
||||
|
||||
-- Drop table personnel_billing_rates
|
||||
DROP TABLE IF EXISTS personnel_billing_rates;
|
||||
|
||||
-- Drop table billing_states
|
||||
DROP TABLE IF EXISTS billing_states;
|
|
@ -0,0 +1,101 @@
|
|||
-- Create new table billing states to define billing states for eu_instances
|
||||
create table billing_states
|
||||
(
|
||||
state_id text
|
||||
constraint billing_states_pk
|
||||
primary key,
|
||||
description text,
|
||||
final_approve boolean default false not null
|
||||
);
|
||||
|
||||
-- Create new table personnel_billing_rates to define billing rates for personnel billing
|
||||
create table personnel_billing_rates
|
||||
(
|
||||
billing_rate_id uuid default uuid_generate_v1() not null
|
||||
constraint billing_rates_pk
|
||||
primary key,
|
||||
name text not null,
|
||||
description text,
|
||||
active boolean default true not null,
|
||||
payment_per_hour numeric(18, 8) default 0 not null,
|
||||
lump_sum numeric(18, 8) default 0 not null
|
||||
);
|
||||
|
||||
-- Add fields planned_start_time, planned_end_time, real_start_time, real_end_time, billing_rate_id and billing_state_id to eu_instances
|
||||
alter table eu_instances
|
||||
add planned_start_time timestamptz;
|
||||
|
||||
alter table eu_instances
|
||||
add planned_end_time timestamptz;
|
||||
|
||||
alter table eu_instances
|
||||
add real_start_time timestamptz;
|
||||
|
||||
alter table eu_instances
|
||||
add real_end_time timestamptz;
|
||||
|
||||
alter table eu_instances
|
||||
add billing_rate_id uuid;
|
||||
|
||||
alter table eu_instances
|
||||
add billing_state_id text;
|
||||
|
||||
alter table eu_instances
|
||||
add constraint eu_instances_billing_states_state_id_fk
|
||||
foreign key (billing_state_id) references billing_states;
|
||||
|
||||
alter table eu_instances
|
||||
add constraint eu_instances_personnel_billing_rates_billing_rate_id_fk
|
||||
foreign key (billing_rate_id) references personnel_billing_rates;
|
||||
|
||||
-- Add real_start_time and real_end_time to eu_position_instances
|
||||
|
||||
alter table eu_position_instances
|
||||
add real_start_time timestamptz;
|
||||
|
||||
alter table eu_position_instances
|
||||
add real_end_time timestamptz;
|
||||
|
||||
-- Add table personnel_billing to store money calculated for each position_instance
|
||||
|
||||
create table personnel_billing
|
||||
(
|
||||
position_instance_id uuid
|
||||
constraint personnel_billing_pk
|
||||
primary key
|
||||
constraint personnel_billing_eu_position_instances_position_instance_id_fk
|
||||
references eu_position_instances,
|
||||
member_id uuid not null
|
||||
constraint personnel_billing_members_entity_id_fk
|
||||
references members,
|
||||
fulfilled_time int default 0 not null,
|
||||
money_for_time decimal(18, 8) default 0 not null,
|
||||
money_from_lump_sum decimal(18, 8) default 0 not null,
|
||||
total_money decimal(18, 8) default 0 not null
|
||||
);
|
||||
|
||||
-- Add permissions for billing module
|
||||
|
||||
INSERT INTO permissions (permission, description, context, context_type)
|
||||
VALUES ('modules.event_billing.view',
|
||||
'Permission to see event billing UI. Note: This and all other billing related permissions are overwritten if member is responsible for event and member_responsible_overwrites_permissions is set to true in config!',
|
||||
false, null);
|
||||
|
||||
INSERT INTO permissions (permission, description, context, context_type)
|
||||
VALUES ('modules.event_billing.start_end_times.view', 'Permission to see start/end times for event units in billing UI',
|
||||
false, null);
|
||||
|
||||
INSERT INTO permissions (permission, description, context, context_type)
|
||||
VALUES ('modules.event_billing.start_end_times.edit',
|
||||
'Permission to edit start/end times for event units in billing UI', false, null);
|
||||
|
||||
INSERT INTO permissions (permission, description, context, context_type)
|
||||
VALUES ('modules.event_billing.personnel.view', 'Permission to see personnel billing in billing UI', false, null);
|
||||
|
||||
INSERT INTO permissions (permission, description, context, context_type)
|
||||
VALUES ('modules.event_billing.personnel.edit', 'Permission to edit personnel billing in billing UI', false, null);
|
||||
|
||||
INSERT INTO permissions (permission, description, context, context_type)
|
||||
VALUES ('modules.event_billing.approve', 'Permission to approve billing for specified (context) billing_states', true,
|
||||
'billing_state');
|
||||
|
Loading…
Reference in New Issue