1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

(feat) add is_confirm to slots_reservations

This commit is contained in:
Du Peng 2023-08-31 16:10:43 +02:00
parent 9000c97aaf
commit 37aa4fb2ff
5 changed files with 206 additions and 9 deletions

View File

@ -69,13 +69,17 @@ class ReservationConfirmPaymentService
[@reservation], [@reservation],
@reservation.user @reservation.user
) )
return invoice if Setting.get('prevent_invoices_zero') && price[:total].zero? if Setting.get('prevent_invoices_zero') && price[:total].zero?
@reservation.slots_reservations.first.update(is_confirm: true)
return invoice
end
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
WalletService.debit_user_wallet(invoice, @reservation.user) WalletService.debit_user_wallet(invoice, @reservation.user)
invoice.save invoice.save
invoice.post_save invoice.post_save
@reservation.slots_reservations.first.update(is_confirm: true)
end end
invoice invoice
end end

View File

@ -88,7 +88,7 @@ json.events_reservations @member.reservations.where(reservable_type: 'Event').jo
json.event_title sr.reservation.reservable.title json.event_title sr.reservation.reservable.title
json.event_pre_registration sr.reservation.reservable.pre_registration json.event_pre_registration sr.reservation.reservable.pre_registration
json.is_valid sr.is_valid json.is_valid sr.is_valid
json.is_paid sr.reservation.invoice_items.count.positive? json.is_paid sr.is_confirm
json.amount sr.reservation.invoice_items.sum(:amount) json.amount sr.reservation.invoice_items.sum(:amount)
json.canceled_at sr.canceled_at json.canceled_at sr.canceled_at
json.booking_users_attributes sr.reservation.booking_users.order(booked_type: :desc) do |bu| json.booking_users_attributes sr.reservation.booking_users.order(booked_type: :desc) do |bu|

View File

@ -43,4 +43,4 @@ json.booking_users_attributes reservation.booking_users.order(booked_type: :desc
json.age ((Time.zone.now - bu.booked.birthday.to_time) / 1.year.seconds).floor if bu.booked_type == 'Child' json.age ((Time.zone.now - bu.booked.birthday.to_time) / 1.year.seconds).floor if bu.booked_type == 'Child'
end end
json.is_valid reservation.slots_reservations[0].is_valid json.is_valid reservation.slots_reservations[0].is_valid
json.is_paid reservation.invoice_items.count.positive? json.is_paid reservation.slots_reservations[0].is_confirm

View File

@ -0,0 +1,16 @@
# frozen_string_literal: true
# add is_confirm to slots_reservations
class AddIsConfirmToSlotsReservations < ActiveRecord::Migration[7.0]
def up
add_column :slots_reservations, :is_confirm, :boolean
SlotsReservation.reset_column_information
SlotsReservation.all.each do |sr|
sr.update_column(:is_confirm, true) if sr.is_valid && sr.reservation.invoice_items.count.positive?
end
end
def down
remove_column :slots_reservations, :is_confirm
end
end

View File

@ -839,7 +839,8 @@ CREATE TABLE public.cart_item_reservations (
operator_profile_id bigint, operator_profile_id bigint,
type character varying, type character varying,
created_at timestamp without time zone NOT NULL, created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL updated_at timestamp without time zone NOT NULL,
reservation_context_id bigint
); );
@ -1735,7 +1736,8 @@ CREATE TABLE public.machines (
disabled boolean, disabled boolean,
deleted_at timestamp without time zone, deleted_at timestamp without time zone,
machine_category_id bigint, machine_category_id bigint,
reservable boolean DEFAULT true reservable boolean DEFAULT true,
space_id bigint
); );
@ -2238,6 +2240,41 @@ CREATE SEQUENCE public.payment_gateway_objects_id_seq
ALTER SEQUENCE public.payment_gateway_objects_id_seq OWNED BY public.payment_gateway_objects.id; ALTER SEQUENCE public.payment_gateway_objects_id_seq OWNED BY public.payment_gateway_objects.id;
--
-- Name: payment_infos; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.payment_infos (
id bigint NOT NULL,
data jsonb,
state character varying,
payment_for character varying,
service character varying,
statistic_profile_id bigint,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
--
-- Name: payment_infos_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.payment_infos_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: payment_infos_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.payment_infos_id_seq OWNED BY public.payment_infos.id;
-- --
-- Name: payment_schedule_items; Type: TABLE; Schema: public; Owner: - -- Name: payment_schedule_items; Type: TABLE; Schema: public; Owner: -
-- --
@ -3126,6 +3163,38 @@ CREATE SEQUENCE public.projects_themes_id_seq
ALTER SEQUENCE public.projects_themes_id_seq OWNED BY public.projects_themes.id; ALTER SEQUENCE public.projects_themes_id_seq OWNED BY public.projects_themes.id;
--
-- Name: reservation_contexts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.reservation_contexts (
id bigint NOT NULL,
name character varying,
applicable_on character varying[] DEFAULT '{}'::character varying[],
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
--
-- Name: reservation_contexts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.reservation_contexts_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: reservation_contexts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.reservation_contexts_id_seq OWNED BY public.reservation_contexts.id;
-- --
-- Name: reservations; Type: TABLE; Schema: public; Owner: - -- Name: reservations; Type: TABLE; Schema: public; Owner: -
-- --
@ -3138,7 +3207,8 @@ CREATE TABLE public.reservations (
reservable_type character varying, reservable_type character varying,
reservable_id integer, reservable_id integer,
nb_reserve_places integer, nb_reserve_places integer,
statistic_profile_id integer statistic_profile_id integer,
reservation_context_id bigint
); );
@ -3280,7 +3350,8 @@ CREATE TABLE public.slots_reservations (
ex_end_at timestamp without time zone, ex_end_at timestamp without time zone,
canceled_at timestamp without time zone, canceled_at timestamp without time zone,
offered boolean DEFAULT false, offered boolean DEFAULT false,
is_valid boolean is_valid boolean,
is_confirm boolean
); );
@ -3317,7 +3388,9 @@ CREATE TABLE public.spaces (
updated_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL,
characteristics text, characteristics text,
disabled boolean, disabled boolean,
deleted_at timestamp without time zone deleted_at timestamp without time zone,
ancestry character varying NOT NULL COLLATE pg_catalog."C",
ancestry_depth integer DEFAULT 0
); );
@ -4832,6 +4905,13 @@ ALTER TABLE ONLY public.organizations ALTER COLUMN id SET DEFAULT nextval('publi
ALTER TABLE ONLY public.payment_gateway_objects ALTER COLUMN id SET DEFAULT nextval('public.payment_gateway_objects_id_seq'::regclass); ALTER TABLE ONLY public.payment_gateway_objects ALTER COLUMN id SET DEFAULT nextval('public.payment_gateway_objects_id_seq'::regclass);
--
-- Name: payment_infos id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.payment_infos ALTER COLUMN id SET DEFAULT nextval('public.payment_infos_id_seq'::regclass);
-- --
-- Name: payment_schedule_items id; Type: DEFAULT; Schema: public; Owner: - -- Name: payment_schedule_items id; Type: DEFAULT; Schema: public; Owner: -
-- --
@ -5007,6 +5087,13 @@ 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); ALTER TABLE ONLY public.projects_themes ALTER COLUMN id SET DEFAULT nextval('public.projects_themes_id_seq'::regclass);
--
-- Name: reservation_contexts id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.reservation_contexts ALTER COLUMN id SET DEFAULT nextval('public.reservation_contexts_id_seq'::regclass);
-- --
-- Name: reservations id; Type: DEFAULT; Schema: public; Owner: - -- Name: reservations id; Type: DEFAULT; Schema: public; Owner: -
-- --
@ -5754,6 +5841,14 @@ ALTER TABLE ONLY public.payment_gateway_objects
ADD CONSTRAINT payment_gateway_objects_pkey PRIMARY KEY (id); ADD CONSTRAINT payment_gateway_objects_pkey PRIMARY KEY (id);
--
-- Name: payment_infos payment_infos_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.payment_infos
ADD CONSTRAINT payment_infos_pkey PRIMARY KEY (id);
-- --
-- Name: payment_schedule_items payment_schedule_items_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- Name: payment_schedule_items payment_schedule_items_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- --
@ -5954,6 +6049,14 @@ ALTER TABLE ONLY public.projects_themes
ADD CONSTRAINT projects_themes_pkey PRIMARY KEY (id); ADD CONSTRAINT projects_themes_pkey PRIMARY KEY (id);
--
-- Name: reservation_contexts reservation_contexts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.reservation_contexts
ADD CONSTRAINT reservation_contexts_pkey PRIMARY KEY (id);
-- --
-- Name: reservations reservations_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- Name: reservations reservations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- --
@ -6503,6 +6606,13 @@ CREATE INDEX index_cart_item_reservations_on_plan_id ON public.cart_item_reserva
CREATE INDEX index_cart_item_reservations_on_reservable ON public.cart_item_reservations USING btree (reservable_type, reservable_id); CREATE INDEX index_cart_item_reservations_on_reservable ON public.cart_item_reservations USING btree (reservable_type, reservable_id);
--
-- Name: index_cart_item_reservations_on_reservation_context_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_cart_item_reservations_on_reservation_context_id ON public.cart_item_reservations USING btree (reservation_context_id);
-- --
-- Name: index_cart_item_slots_on_cart_item; Type: INDEX; Schema: public; Owner: - -- Name: index_cart_item_slots_on_cart_item; Type: INDEX; Schema: public; Owner: -
-- --
@ -6797,6 +6907,13 @@ CREATE INDEX index_machines_on_machine_category_id ON public.machines USING btre
CREATE UNIQUE INDEX index_machines_on_slug ON public.machines USING btree (slug); CREATE UNIQUE INDEX index_machines_on_slug ON public.machines USING btree (slug);
--
-- Name: index_machines_on_space_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_machines_on_space_id ON public.machines USING btree (space_id);
-- --
-- Name: index_notification_preferences_on_notification_type_id; Type: INDEX; Schema: public; Owner: - -- Name: index_notification_preferences_on_notification_type_id; Type: INDEX; Schema: public; Owner: -
-- --
@ -6930,6 +7047,13 @@ CREATE INDEX index_payment_gateway_objects_on_item_type_and_item_id ON public.pa
CREATE INDEX index_payment_gateway_objects_on_payment_gateway_object_id ON public.payment_gateway_objects USING btree (payment_gateway_object_id); CREATE INDEX index_payment_gateway_objects_on_payment_gateway_object_id ON public.payment_gateway_objects USING btree (payment_gateway_object_id);
--
-- Name: index_payment_infos_on_statistic_profile_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_payment_infos_on_statistic_profile_id ON public.payment_infos USING btree (statistic_profile_id);
-- --
-- Name: index_payment_schedule_items_on_invoice_id; Type: INDEX; Schema: public; Owner: - -- Name: index_payment_schedule_items_on_invoice_id; Type: INDEX; Schema: public; Owner: -
-- --
@ -7259,6 +7383,13 @@ CREATE INDEX index_projects_themes_on_theme_id ON public.projects_themes USING b
CREATE INDEX index_reservations_on_reservable_type_and_reservable_id ON public.reservations USING btree (reservable_type, reservable_id); CREATE INDEX index_reservations_on_reservable_type_and_reservable_id ON public.reservations USING btree (reservable_type, reservable_id);
--
-- Name: index_reservations_on_reservation_context_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_reservations_on_reservation_context_id ON public.reservations USING btree (reservation_context_id);
-- --
-- Name: index_reservations_on_statistic_profile_id; Type: INDEX; Schema: public; Owner: - -- Name: index_reservations_on_statistic_profile_id; Type: INDEX; Schema: public; Owner: -
-- --
@ -7329,6 +7460,13 @@ CREATE INDEX index_spaces_availabilities_on_availability_id ON public.spaces_ava
CREATE INDEX index_spaces_availabilities_on_space_id ON public.spaces_availabilities USING btree (space_id); CREATE INDEX index_spaces_availabilities_on_space_id ON public.spaces_availabilities USING btree (space_id);
--
-- Name: index_spaces_on_ancestry; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_spaces_on_ancestry ON public.spaces USING btree (ancestry);
-- --
-- Name: index_spaces_on_deleted_at; Type: INDEX; Schema: public; Owner: - -- Name: index_spaces_on_deleted_at; Type: INDEX; Schema: public; Owner: -
-- --
@ -7740,6 +7878,14 @@ ALTER TABLE ONLY public.payment_schedules
ADD CONSTRAINT fk_rails_00308dc223 FOREIGN KEY (wallet_transaction_id) REFERENCES public.wallet_transactions(id); ADD CONSTRAINT fk_rails_00308dc223 FOREIGN KEY (wallet_transaction_id) REFERENCES public.wallet_transactions(id);
--
-- Name: payment_infos fk_rails_0308366a58; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.payment_infos
ADD CONSTRAINT fk_rails_0308366a58 FOREIGN KEY (statistic_profile_id) REFERENCES public.statistic_profiles(id);
-- --
-- Name: cart_item_event_reservation_booking_users fk_rails_0964335a37; Type: FK CONSTRAINT; Schema: public; Owner: - -- Name: cart_item_event_reservation_booking_users fk_rails_0964335a37; Type: FK CONSTRAINT; Schema: public; Owner: -
-- --
@ -8388,6 +8534,14 @@ ALTER TABLE ONLY public.statistic_profile_prepaid_packs
ADD CONSTRAINT fk_rails_b0251cdfcf FOREIGN KEY (prepaid_pack_id) REFERENCES public.prepaid_packs(id); ADD CONSTRAINT fk_rails_b0251cdfcf FOREIGN KEY (prepaid_pack_id) REFERENCES public.prepaid_packs(id);
--
-- Name: machines fk_rails_b2e37688bb; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.machines
ADD CONSTRAINT fk_rails_b2e37688bb FOREIGN KEY (space_id) REFERENCES public.spaces(id);
-- --
-- Name: orders fk_rails_b33ed6c672; Type: FK CONSTRAINT; Schema: public; Owner: - -- Name: orders fk_rails_b33ed6c672; Type: FK CONSTRAINT; Schema: public; Owner: -
-- --
@ -8500,6 +8654,14 @@ ALTER TABLE ONLY public.accounting_periods
ADD CONSTRAINT fk_rails_cc9abff81f FOREIGN KEY (closed_by) REFERENCES public.users(id); ADD CONSTRAINT fk_rails_cc9abff81f FOREIGN KEY (closed_by) REFERENCES public.users(id);
--
-- Name: reservations fk_rails_cfaaf202e7; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.reservations
ADD CONSTRAINT fk_rails_cfaaf202e7 FOREIGN KEY (reservation_context_id) REFERENCES public.reservation_contexts(id);
-- --
-- Name: wallet_transactions fk_rails_d07bc24ce3; Type: FK CONSTRAINT; Schema: public; Owner: - -- Name: wallet_transactions fk_rails_d07bc24ce3; Type: FK CONSTRAINT; Schema: public; Owner: -
-- --
@ -8548,6 +8710,14 @@ ALTER TABLE ONLY public.payment_schedule_items
ADD CONSTRAINT fk_rails_d6030dd0e7 FOREIGN KEY (payment_schedule_id) REFERENCES public.payment_schedules(id); ADD CONSTRAINT fk_rails_d6030dd0e7 FOREIGN KEY (payment_schedule_id) REFERENCES public.payment_schedules(id);
--
-- Name: cart_item_reservations fk_rails_daa5b1b8b9; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.cart_item_reservations
ADD CONSTRAINT fk_rails_daa5b1b8b9 FOREIGN KEY (reservation_context_id) REFERENCES public.reservation_contexts(id);
-- --
-- Name: product_stock_movements fk_rails_dc802d5f48; Type: FK CONSTRAINT; Schema: public; Owner: - -- Name: product_stock_movements fk_rails_dc802d5f48; Type: FK CONSTRAINT; Schema: public; Owner: -
-- --
@ -9075,6 +9245,13 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230626103314'), ('20230626103314'),
('20230626122844'), ('20230626122844'),
('20230626122947'), ('20230626122947'),
('20230710072403'); ('20230710072403'),
('20230718133636'),
('20230718134350'),
('20230720085857'),
('20230728072726'),
('20230728090257'),
('20230825101952'),
('20230831103208');