1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

database structure for payment schedule

This commit is contained in:
Sylvain 2020-10-27 11:32:20 +01:00
parent ef2e5aec20
commit 52f3bd956f
7 changed files with 259 additions and 3 deletions

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
# RepaymentSchedule is a way for members to pay something (especially a Subscription) with multiple payment,
# staged on a long period rather than with a single payment
class RepaymentSchedule < ApplicationRecord
belongs_to :scheduled, polymorphic: true
belongs_to :wallet_transaction
belongs_to :coupon
belongs_to :invoicing_profile
belongs_to :operator_profile, foreign_key: :operator_profile_id, class_name: 'InvoicingProfile'
end

View File

@ -0,0 +1,6 @@
# frozen_string_literal: true
# Represents a due date and the associated amount for a RepaymentSchedule
class RepaymentScheduleItem < ApplicationRecord
belongs_to :repayment_schedule
end

View File

@ -3,7 +3,7 @@
class CreateInvoices < ActiveRecord::Migration[4.2]
def change
create_table :invoices do |t|
t.references :invoiced, polymorphic: true
t.references :invoiced, polymorphic: true
t.string :stp_invoice_id
t.integer :total

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
# If a plan is marked as "monthly_payment", we can charge its subscriptions with a repayment schedule
# instead of a single invoice
class AddMonthlyPaymentToPlan < ActiveRecord::Migration[5.2]
def change
add_column :plans, :monthly_payment, :boolean
end
end

View File

@ -0,0 +1,24 @@
# frozen_string_literal: true
# Saves RepaymentSchedules in database.
# It allows to pay with multiple payments
class CreateRepaymentSchedules < ActiveRecord::Migration[5.2]
def change
create_table :repayment_schedules do |t|
t.references :scheduled, polymorphic: true
t.integer :total
t.string :stp_subscription_id
t.string :reference
t.string :payment_method
t.integer :wallet_amount
t.belongs_to :wallet_transaction, foreign_key: true
t.belongs_to :coupon, foreign_key: true
t.string :footprint
t.string :environment
t.belongs_to :invoicing_profile, foreign_key: true
t.references :operator_profile_id, foreign_key: { to_table: 'invoicing_profiles' }
t.timestamps
end
end
end

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
# Save each due dates for RepaymentSchedules
class CreateRepaymentScheduleItems < ActiveRecord::Migration[5.2]
def change
create_table :repayment_schedule_items do |t|
t.integer :amount
t.datetime :due_date
t.belongs_to :repayment_schedule, foreign_key: true
t.timestamps
end
end
end

View File

@ -1482,7 +1482,8 @@ CREATE TABLE public.plans (
ui_weight integer DEFAULT 0,
interval_count integer DEFAULT 1,
slug character varying,
disabled boolean
disabled boolean,
monthly_payment boolean
);
@ -1882,6 +1883,82 @@ CREATE SEQUENCE public.projects_themes_id_seq
ALTER SEQUENCE public.projects_themes_id_seq OWNED BY public.projects_themes.id;
--
-- Name: repayment_schedule_items; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.repayment_schedule_items (
id bigint NOT NULL,
amount integer,
due_date timestamp without time zone,
repayment_schedule_id bigint,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: repayment_schedule_items_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.repayment_schedule_items_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: repayment_schedule_items_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.repayment_schedule_items_id_seq OWNED BY public.repayment_schedule_items.id;
--
-- Name: repayment_schedules; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.repayment_schedules (
id bigint NOT NULL,
scheduled_type character varying,
scheduled_id bigint,
total integer,
stp_subscription_id character varying,
reference character varying,
payment_method character varying,
wallet_amount integer,
wallet_transaction_id bigint,
coupon_id bigint,
footprint character varying,
environment character varying,
invoicing_profile_id bigint,
operator_profile_id_id bigint,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: repayment_schedules_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.repayment_schedules_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: repayment_schedules_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.repayment_schedules_id_seq OWNED BY public.repayment_schedules.id;
--
-- Name: reservations; Type: TABLE; Schema: public; Owner: -
--
@ -3277,6 +3354,20 @@ ALTER TABLE ONLY public.projects_spaces ALTER COLUMN id SET DEFAULT nextval('pub
ALTER TABLE ONLY public.projects_themes ALTER COLUMN id SET DEFAULT nextval('public.projects_themes_id_seq'::regclass);
--
-- Name: repayment_schedule_items id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.repayment_schedule_items ALTER COLUMN id SET DEFAULT nextval('public.repayment_schedule_items_id_seq'::regclass);
--
-- Name: repayment_schedules id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.repayment_schedules ALTER COLUMN id SET DEFAULT nextval('public.repayment_schedules_id_seq'::regclass);
--
-- Name: reservations id; Type: DEFAULT; Schema: public; Owner: -
--
@ -3903,6 +3994,22 @@ ALTER TABLE ONLY public.projects_themes
ADD CONSTRAINT projects_themes_pkey PRIMARY KEY (id);
--
-- Name: repayment_schedule_items repayment_schedule_items_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.repayment_schedule_items
ADD CONSTRAINT repayment_schedule_items_pkey PRIMARY KEY (id);
--
-- Name: repayment_schedules repayment_schedules_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.repayment_schedules
ADD CONSTRAINT repayment_schedules_pkey PRIMARY KEY (id);
--
-- Name: reservations reservations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -4549,6 +4656,48 @@ CREATE INDEX index_projects_themes_on_project_id ON public.projects_themes USING
CREATE INDEX index_projects_themes_on_theme_id ON public.projects_themes USING btree (theme_id);
--
-- Name: index_repayment_schedule_items_on_repayment_schedule_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_repayment_schedule_items_on_repayment_schedule_id ON public.repayment_schedule_items USING btree (repayment_schedule_id);
--
-- Name: index_repayment_schedules_on_coupon_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_repayment_schedules_on_coupon_id ON public.repayment_schedules USING btree (coupon_id);
--
-- Name: index_repayment_schedules_on_invoicing_profile_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_repayment_schedules_on_invoicing_profile_id ON public.repayment_schedules USING btree (invoicing_profile_id);
--
-- Name: index_repayment_schedules_on_operator_profile_id_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_repayment_schedules_on_operator_profile_id_id ON public.repayment_schedules USING btree (operator_profile_id_id);
--
-- Name: index_repayment_schedules_on_scheduled_type_and_scheduled_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_repayment_schedules_on_scheduled_type_and_scheduled_id ON public.repayment_schedules USING btree (scheduled_type, scheduled_id);
--
-- Name: index_repayment_schedules_on_wallet_transaction_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_repayment_schedules_on_wallet_transaction_id ON public.repayment_schedules USING btree (wallet_transaction_id);
--
-- Name: index_reservations_on_reservable_type_and_reservable_id; Type: INDEX; Schema: public; Owner: -
--
@ -5252,6 +5401,14 @@ ALTER TABLE ONLY public.projects_themes
ADD CONSTRAINT fk_rails_9fd58ae797 FOREIGN KEY (project_id) REFERENCES public.projects(id);
--
-- Name: repayment_schedules fk_rails_a9e6b045af; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.repayment_schedules
ADD CONSTRAINT fk_rails_a9e6b045af FOREIGN KEY (operator_profile_id_id) REFERENCES public.invoicing_profiles(id);
--
-- Name: projects_themes fk_rails_b021a22658; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -5284,6 +5441,22 @@ ALTER TABLE ONLY public.projects_machines
ADD CONSTRAINT fk_rails_c1427daf48 FOREIGN KEY (project_id) REFERENCES public.projects(id);
--
-- Name: repayment_schedules fk_rails_c1530d5158; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.repayment_schedules
ADD CONSTRAINT fk_rails_c1530d5158 FOREIGN KEY (invoicing_profile_id) REFERENCES public.invoicing_profiles(id);
--
-- Name: repayment_schedules fk_rails_c313d6987a; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.repayment_schedules
ADD CONSTRAINT fk_rails_c313d6987a FOREIGN KEY (wallet_transaction_id) REFERENCES public.wallet_transactions(id);
--
-- Name: project_steps fk_rails_c6306005c3; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -5300,6 +5473,14 @@ ALTER TABLE ONLY public.projects_components
ADD CONSTRAINT fk_rails_c80c60ead3 FOREIGN KEY (project_id) REFERENCES public.projects(id);
--
-- Name: repayment_schedules fk_rails_c858c7637d; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.repayment_schedules
ADD CONSTRAINT fk_rails_c858c7637d FOREIGN KEY (coupon_id) REFERENCES public.coupons(id);
--
-- Name: statistic_profile_trainings fk_rails_cb689a8d3d; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -5308,6 +5489,14 @@ ALTER TABLE ONLY public.statistic_profile_trainings
ADD CONSTRAINT fk_rails_cb689a8d3d FOREIGN KEY (statistic_profile_id) REFERENCES public.statistic_profiles(id);
--
-- Name: repayment_schedule_items fk_rails_cc00414030; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.repayment_schedule_items
ADD CONSTRAINT fk_rails_cc00414030 FOREIGN KEY (repayment_schedule_id) REFERENCES public.repayment_schedules(id);
--
-- Name: accounting_periods fk_rails_cc9abff81f; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -5666,6 +5855,9 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200623134900'),
('20200623141305'),
('20200629123011'),
('20200721162939');
('20200721162939'),
('20201027092149'),
('20201027100746'),
('20201027101809');