From 6888f00036f82a018271fde8daa1a5f27bf8b95d Mon Sep 17 00:00:00 2001 From: Du Peng Date: Wed, 10 May 2023 18:47:13 +0200 Subject: [PATCH] (wip) save booking user for event nominatif --- .../src/javascript/controllers/events.js.erb | 11 ++- app/frontend/templates/events/show.html | 10 +-- app/models/cart_item.rb | 5 ++ app/models/cart_item/event_reservation.rb | 13 +++ .../event_reservation_booking_user.rb | 10 +++ app/services/cart_service.rb | 3 +- config/locales/app.public.en.yml | 1 + config/locales/app.public.fr.yml | 1 + ...rt_item_event_reservation_booking_users.rb | 15 ++++ db/structure.sql | 90 ++++++++++++++++++- 10 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 app/models/cart_item.rb create mode 100644 app/models/cart_item/event_reservation_booking_user.rb create mode 100644 db/migrate/20230510141305_create_cart_item_event_reservation_booking_users.rb diff --git a/app/frontend/src/javascript/controllers/events.js.erb b/app/frontend/src/javascript/controllers/events.js.erb index 63e2bd25d..335f97580 100644 --- a/app/frontend/src/javascript/controllers/events.js.erb +++ b/app/frontend/src/javascript/controllers/events.js.erb @@ -264,11 +264,14 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', ' const nbReservePlaces = priceType === 'normal' ? $scope.reserve.nbReservePlaces : $scope.reserve.tickets[priceType]; if (nbReservePlaces > nbBookingUsers) { _.times(nbReservePlaces - nbBookingUsers, () => { + /* if (!hasMemberInBookingUsers()) { $scope.reserve.bookingUsers[priceType].push({ event_price_category_id: priceType === 'normal' ? null : priceType, booked_id: $scope.ctrl.member.id, booked_type: 'User', name: $scope.ctrl.member.name }); } else { $scope.reserve.bookingUsers[priceType].push({ event_price_category_id: priceType === 'normal' ? null : priceType }); } + */ + $scope.reserve.bookingUsers[priceType].push({ event_price_category_id: priceType === 'normal' ? null : priceType }); }); } else { _.times(nbBookingUsers - nbReservePlaces, () => { @@ -689,10 +692,14 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', ' if (event.booking_nominative) { for (const key of Object.keys($scope.reserve.bookingUsers)) { for (const user of $scope.reserve.bookingUsers[key]) { - reservation.booking_users_attributes.push(user); + reservation.booking_users_attributes.push({ + event_price_category_id: user.event_price_category_id, + name: user.name, + booked_id: user.booked_id, + booked_type: user.booked_type + }); } } - console.log(reservation); } return { reservation }; diff --git a/app/frontend/templates/events/show.html b/app/frontend/templates/events/show.html index c8d86cd02..a75de228b 100644 --- a/app/frontend/templates/events/show.html +++ b/app/frontend/templates/events/show.html @@ -119,9 +119,9 @@ {{ 'app.public.events_show.ticket' | translate:{NUMBER:reserve.nbReservePlaces} }} -
+
- +
@@ -132,9 +132,9 @@ {{ 'app.public.events_show.ticket' | translate:{NUMBER:reserve.tickets[price.id]} }}
-
+
- +
@@ -169,7 +169,7 @@
{{ 'app.public.events_show.you_booked_DATE' | translate:{DATE:(reservation.created_at | amDateFormat:'L LT')} }}
{{ 'app.public.events_show.full_price_' | translate }} {{reservation.nb_reserve_places}} {{ 'app.public.events_show.ticket' | translate:{NUMBER:reservation.nb_reserve_places} }}
-
+
{{ticket.event_price_category.price_category.name}} : {{ticket.booked}} {{ 'app.public.events_show.ticket' | translate:{NUMBER:ticket.booked} }}
diff --git a/app/models/cart_item.rb b/app/models/cart_item.rb new file mode 100644 index 000000000..4397e866e --- /dev/null +++ b/app/models/cart_item.rb @@ -0,0 +1,5 @@ +module CartItem + def self.table_name_prefix + "cart_item_" + end +end diff --git a/app/models/cart_item/event_reservation.rb b/app/models/cart_item/event_reservation.rb index 9ae7be11a..cbb90a934 100644 --- a/app/models/cart_item/event_reservation.rb +++ b/app/models/cart_item/event_reservation.rb @@ -13,6 +13,11 @@ class CartItem::EventReservation < CartItem::Reservation foreign_type: 'cart_item_type', as: :cart_item accepts_nested_attributes_for :cart_item_reservation_slots + has_many :cart_item_event_reservation_booking_users, class_name: 'CartItem::EventReservationBookingUser', dependent: :destroy, + inverse_of: :cart_item_event_reservation, + foreign_key: 'cart_item_event_reservation_id' + accepts_nested_attributes_for :cart_item_event_reservation_booking_users + belongs_to :operator_profile, class_name: 'InvoicingProfile' belongs_to :customer_profile, class_name: 'InvoicingProfile' @@ -63,6 +68,14 @@ class CartItem::EventReservation < CartItem::Reservation booked: t.booked } end, + booking_users_attributes: cart_item_event_reservation_booking_users.map do |b| + { + event_price_category_id: b.event_price_category_id, + booked_type: b.booked_type, + booked_id: b.booked_id, + name: b.name + } + end, nb_reserve_places: normal_tickets, statistic_profile_id: StatisticProfile.find_by(user: customer).id ) diff --git a/app/models/cart_item/event_reservation_booking_user.rb b/app/models/cart_item/event_reservation_booking_user.rb new file mode 100644 index 000000000..82df9ac9c --- /dev/null +++ b/app/models/cart_item/event_reservation_booking_user.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# A relation table between a pending event reservation and reservation users for this event +class CartItem::EventReservationBookingUser < ApplicationRecord + self.table_name = 'cart_item_event_reservation_booking_users' + + belongs_to :cart_item_event_reservation, class_name: 'CartItem::EventReservation', inverse_of: :cart_item_event_reservation_booking_users + belongs_to :event_price_category, inverse_of: :cart_item_event_reservation_tickets + belongs_to :booked, polymorphic: true +end diff --git a/app/services/cart_service.rb b/app/services/cart_service.rb index 6c6588e4b..52210c40d 100644 --- a/app/services/cart_service.rb +++ b/app/services/cart_service.rb @@ -171,7 +171,8 @@ class CartService event: reservable, cart_item_reservation_slots_attributes: cart_item[:slots_reservations_attributes], normal_tickets: cart_item[:nb_reserve_places], - cart_item_event_reservation_tickets_attributes: cart_item[:tickets_attributes] || {}) + cart_item_event_reservation_tickets_attributes: cart_item[:tickets_attributes] || {}, + cart_item_event_reservation_booking_users_attributes: cart_item[:booking_users_attributes] || {}) when Space CartItem::SpaceReservation.new(customer_profile: @customer.invoicing_profile, operator_profile: @operator.invoicing_profile, diff --git a/config/locales/app.public.en.yml b/config/locales/app.public.en.yml index 12e8c9785..b8607b367 100644 --- a/config/locales/app.public.en.yml +++ b/config/locales/app.public.en.yml @@ -357,6 +357,7 @@ en: view_event_list: "View events to come" share_on_facebook: "Share on Facebook" share_on_twitter: "Share on Twitter" + last_name_and_first_name: "Last name and first name" #public calendar calendar: calendar: "Calendar" diff --git a/config/locales/app.public.fr.yml b/config/locales/app.public.fr.yml index 3ef09b458..0f0ca2103 100644 --- a/config/locales/app.public.fr.yml +++ b/config/locales/app.public.fr.yml @@ -357,6 +357,7 @@ fr: view_event_list: "Voir les événements à venir" share_on_facebook: "Partager sur Facebook" share_on_twitter: "Partager sur Twitter" + last_name_and_first_name: "Nom et prénom" #public calendar calendar: calendar: "Calendrier" diff --git a/db/migrate/20230510141305_create_cart_item_event_reservation_booking_users.rb b/db/migrate/20230510141305_create_cart_item_event_reservation_booking_users.rb new file mode 100644 index 000000000..bbaae5626 --- /dev/null +++ b/db/migrate/20230510141305_create_cart_item_event_reservation_booking_users.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# A relation table between a pending event reservation and reservation users for this event +class CreateCartItemEventReservationBookingUsers < ActiveRecord::Migration[7.0] + def change + create_table :cart_item_event_reservation_booking_users do |t| + t.string :name + t.belongs_to :cart_item_event_reservation, foreign_key: true, index: { name: 'index_cart_item_booking_users_on_cart_item_event_reservation' } + t.references :event_price_category, foreign_key: true, index: { name: 'index_cart_item_booking_users_on_event_price_category' } + t.references :booked, polymorphic: true + + t.timestamps + end + end +end diff --git a/db/structure.sql b/db/structure.sql index cc238df4c..c19642c69 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -588,6 +588,41 @@ CREATE SEQUENCE public.cart_item_coupons_id_seq ALTER SEQUENCE public.cart_item_coupons_id_seq OWNED BY public.cart_item_coupons.id; +-- +-- Name: cart_item_event_reservation_booking_users; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.cart_item_event_reservation_booking_users ( + id bigint NOT NULL, + name character varying, + cart_item_event_reservation_id bigint, + event_price_category_id bigint, + booked_type character varying, + booked_id bigint, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + +-- +-- Name: cart_item_event_reservation_booking_users_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.cart_item_event_reservation_booking_users_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: cart_item_event_reservation_booking_users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.cart_item_event_reservation_booking_users_id_seq OWNED BY public.cart_item_event_reservation_booking_users.id; + + -- -- Name: cart_item_event_reservation_tickets; Type: TABLE; Schema: public; Owner: - -- @@ -4398,6 +4433,13 @@ ALTER TABLE ONLY public.booking_users ALTER COLUMN id SET DEFAULT nextval('publi ALTER TABLE ONLY public.cart_item_coupons ALTER COLUMN id SET DEFAULT nextval('public.cart_item_coupons_id_seq'::regclass); +-- +-- Name: cart_item_event_reservation_booking_users id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cart_item_event_reservation_booking_users ALTER COLUMN id SET DEFAULT nextval('public.cart_item_event_reservation_booking_users_id_seq'::regclass); + + -- -- Name: cart_item_event_reservation_tickets id; Type: DEFAULT; Schema: public; Owner: - -- @@ -5252,6 +5294,14 @@ ALTER TABLE ONLY public.cart_item_coupons ADD CONSTRAINT cart_item_coupons_pkey PRIMARY KEY (id); +-- +-- Name: cart_item_event_reservation_booking_users cart_item_event_reservation_booking_users_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cart_item_event_reservation_booking_users + ADD CONSTRAINT cart_item_event_reservation_booking_users_pkey PRIMARY KEY (id); + + -- -- Name: cart_item_event_reservation_tickets cart_item_event_reservation_tickets_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -6192,6 +6242,20 @@ CREATE INDEX index_booking_users_on_event_price_category_id ON public.booking_us CREATE INDEX index_booking_users_on_reservation_id ON public.booking_users USING btree (reservation_id); +-- +-- Name: index_cart_item_booking_users_on_cart_item_event_reservation; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_cart_item_booking_users_on_cart_item_event_reservation ON public.cart_item_event_reservation_booking_users USING btree (cart_item_event_reservation_id); + + +-- +-- Name: index_cart_item_booking_users_on_event_price_category; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_cart_item_booking_users_on_event_price_category ON public.cart_item_event_reservation_booking_users USING btree (event_price_category_id); + + -- -- Name: index_cart_item_coupons_on_coupon_id; Type: INDEX; Schema: public; Owner: - -- @@ -6213,6 +6277,13 @@ CREATE INDEX index_cart_item_coupons_on_customer_profile_id ON public.cart_item_ CREATE INDEX index_cart_item_coupons_on_operator_profile_id ON public.cart_item_coupons USING btree (operator_profile_id); +-- +-- Name: index_cart_item_event_reservation_booking_users_on_booked; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_cart_item_event_reservation_booking_users_on_booked ON public.cart_item_event_reservation_booking_users USING btree (booked_type, booked_id); + + -- -- Name: index_cart_item_event_reservations_on_customer_profile_id; Type: INDEX; Schema: public; Owner: - -- @@ -7548,6 +7619,14 @@ ALTER TABLE ONLY public.payment_schedules ADD CONSTRAINT fk_rails_00308dc223 FOREIGN KEY (wallet_transaction_id) REFERENCES public.wallet_transactions(id); +-- +-- Name: cart_item_event_reservation_booking_users fk_rails_0964335a37; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cart_item_event_reservation_booking_users + ADD CONSTRAINT fk_rails_0964335a37 FOREIGN KEY (event_price_category_id) REFERENCES public.event_price_categories(id); + + -- -- Name: cart_item_free_extensions fk_rails_0d11862969; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -7820,6 +7899,14 @@ ALTER TABLE ONLY public.chained_elements ADD CONSTRAINT fk_rails_4fad806cca FOREIGN KEY (previous_id) REFERENCES public.chained_elements(id); +-- +-- Name: cart_item_event_reservation_booking_users fk_rails_5206c6ca4a; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.cart_item_event_reservation_booking_users + ADD CONSTRAINT fk_rails_5206c6ca4a FOREIGN KEY (cart_item_event_reservation_id) REFERENCES public.cart_item_event_reservations(id); + + -- -- Name: cart_item_event_reservation_tickets fk_rails_5307e8aab8; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -8839,6 +8926,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230328094809'), ('20230331132506'), ('20230509121907'), -('20230509161557'); +('20230509161557'), +('20230510141305');