From 37aa4fb2fffe85a9c477c4759295527c94d25341 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Thu, 31 Aug 2023 16:10:43 +0200 Subject: [PATCH 1/2] (feat) add is_confirm to slots_reservations --- .../reservation_confirm_payment_service.rb | 6 +- app/views/api/members/show.json.jbuilder | 2 +- .../reservations/_reservation.json.jbuilder | 2 +- ...08_add_is_confirm_to_slots_reservations.rb | 16 ++ db/structure.sql | 189 +++++++++++++++++- 5 files changed, 206 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20230831103208_add_is_confirm_to_slots_reservations.rb diff --git a/app/services/reservation_confirm_payment_service.rb b/app/services/reservation_confirm_payment_service.rb index c509a172f..86636263b 100644 --- a/app/services/reservation_confirm_payment_service.rb +++ b/app/services/reservation_confirm_payment_service.rb @@ -69,13 +69,17 @@ class ReservationConfirmPaymentService [@reservation], @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 WalletService.debit_user_wallet(invoice, @reservation.user) invoice.save invoice.post_save + @reservation.slots_reservations.first.update(is_confirm: true) end invoice end diff --git a/app/views/api/members/show.json.jbuilder b/app/views/api/members/show.json.jbuilder index 80d25ffae..0e7a44135 100644 --- a/app/views/api/members/show.json.jbuilder +++ b/app/views/api/members/show.json.jbuilder @@ -88,7 +88,7 @@ json.events_reservations @member.reservations.where(reservable_type: 'Event').jo json.event_title sr.reservation.reservable.title json.event_pre_registration sr.reservation.reservable.pre_registration 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.canceled_at sr.canceled_at json.booking_users_attributes sr.reservation.booking_users.order(booked_type: :desc) do |bu| diff --git a/app/views/api/reservations/_reservation.json.jbuilder b/app/views/api/reservations/_reservation.json.jbuilder index b8803ed8b..4370d7d5e 100644 --- a/app/views/api/reservations/_reservation.json.jbuilder +++ b/app/views/api/reservations/_reservation.json.jbuilder @@ -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' end 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 diff --git a/db/migrate/20230831103208_add_is_confirm_to_slots_reservations.rb b/db/migrate/20230831103208_add_is_confirm_to_slots_reservations.rb new file mode 100644 index 000000000..57c1fbba1 --- /dev/null +++ b/db/migrate/20230831103208_add_is_confirm_to_slots_reservations.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index 9d16cfde4..bb052af7c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -839,7 +839,8 @@ CREATE TABLE public.cart_item_reservations ( operator_profile_id bigint, type character varying, 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, deleted_at timestamp without time zone, 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; +-- +-- 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: - -- @@ -3126,6 +3163,38 @@ CREATE SEQUENCE public.projects_themes_id_seq 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: - -- @@ -3138,7 +3207,8 @@ CREATE TABLE public.reservations ( reservable_type character varying, reservable_id 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, canceled_at timestamp without time zone, 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, characteristics text, 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); +-- +-- 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: - -- @@ -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); +-- +-- 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: - -- @@ -5754,6 +5841,14 @@ ALTER TABLE ONLY public.payment_gateway_objects 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: - -- @@ -5954,6 +6049,14 @@ ALTER TABLE ONLY public.projects_themes 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: - -- @@ -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); +-- +-- 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: - -- @@ -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); +-- +-- 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: - -- @@ -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); +-- +-- 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: - -- @@ -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); +-- +-- 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: - -- @@ -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); +-- +-- 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: - -- @@ -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); +-- +-- 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: - -- @@ -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); +-- +-- 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: - -- @@ -8500,6 +8654,14 @@ ALTER TABLE ONLY public.accounting_periods 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: - -- @@ -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); +-- +-- 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: - -- @@ -9075,6 +9245,13 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230626103314'), ('20230626122844'), ('20230626122947'), -('20230710072403'); +('20230710072403'), +('20230718133636'), +('20230718134350'), +('20230720085857'), +('20230728072726'), +('20230728090257'), +('20230825101952'), +('20230831103208'); From ad89e4f278cba0a2320d52a2d8e518276ee485b8 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Thu, 31 Aug 2023 17:11:18 +0200 Subject: [PATCH 2/2] (bug) user cant book event after has reservation canceled --- .../src/javascript/controllers/events.js.erb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/frontend/src/javascript/controllers/events.js.erb b/app/frontend/src/javascript/controllers/events.js.erb index c55105338..f4e92afe9 100644 --- a/app/frontend/src/javascript/controllers/events.js.erb +++ b/app/frontend/src/javascript/controllers/events.js.erb @@ -238,7 +238,10 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', ' $scope.changeNbPlaces = function (priceType) { let reservedPlaces = 0; if ($scope.event.event_type === 'family') { - reservedPlaces = $scope.reservations.reduce((sum, reservation) => { + const reservations = $scope.reservations.filter((reservation) => { + return !reservation.slots_reservations_attributes[0].canceled_at; + }); + reservedPlaces = reservations.reduce((sum, reservation) => { return sum + reservation.booking_users_attributes.length; }, 0); } @@ -742,7 +745,10 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', ' } } } - for (const r of $scope.reservations) { + const reservations = $scope.reservations.filter((reservation) => { + return !reservation.slots_reservations_attributes[0].canceled_at; + }); + for (const r of reservations) { for (const user of r.booking_users_attributes) { const key = user.booked_type === 'User' ? `user_${user.booked_id}` : `child_${user.booked_id}`; if (key === userKey) { @@ -784,7 +790,10 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', ' */ const updateNbReservePlaces = function () { if ($scope.event.event_type === 'family' && $scope.ctrl.member.id) { - const reservedPlaces = $scope.reservations.reduce((sum, reservation) => { + const reservations = $scope.reservations.filter((reservation) => { + return !reservation.slots_reservations_attributes[0].canceled_at; + }); + const reservedPlaces = reservations.reduce((sum, reservation) => { return sum + reservation.booking_users_attributes.length; }, 0); const maxPlaces = $scope.children.length + 1 - reservedPlaces;