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; 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 1585e16e3..bb052af7c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2240,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: - -- @@ -3315,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 ); @@ -4869,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: - -- @@ -5798,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: - -- @@ -6996,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: - -- @@ -7820,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: - -- @@ -9184,4 +9250,8 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230718134350'), ('20230720085857'), ('20230728072726'), -('20230728090257'); +('20230728090257'), +('20230825101952'), +('20230831103208'); + +