From 278841ac50d88f9736b4167699d1e63f04e56066 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 22 Jul 2024 11:44:19 -0300 Subject: [PATCH] finished purchase display screen --- app/assets/images/cross.svg | 4 + app/assets/images/tic.svg | 3 + .../stylesheets/application.bootstrap.scss | 6 + app/controllers/purchases_controller.rb | 12 +- app/javascript/controllers/index.js | 3 + .../show_destinations_controller.js | 39 ++++++ app/models/purchase.rb | 4 + app/views/application/_header.html.erb | 4 +- app/views/purchases/confirmation.html.erb | 10 ++ app/views/purchases/index.html.erb | 36 ++++++ app/views/purchases/new.html.erb | 2 +- app/views/purchases/show.html.erb | 111 ++++++++++++++++++ config/routes.rb | 4 +- 13 files changed, 233 insertions(+), 5 deletions(-) create mode 100644 app/assets/images/cross.svg create mode 100644 app/assets/images/tic.svg create mode 100644 app/javascript/controllers/show_destinations_controller.js create mode 100644 app/views/purchases/confirmation.html.erb create mode 100644 app/views/purchases/index.html.erb create mode 100644 app/views/purchases/show.html.erb diff --git a/app/assets/images/cross.svg b/app/assets/images/cross.svg new file mode 100644 index 0000000..ca4e57c --- /dev/null +++ b/app/assets/images/cross.svg @@ -0,0 +1,4 @@ + + + + diff --git a/app/assets/images/tic.svg b/app/assets/images/tic.svg new file mode 100644 index 0000000..9346c14 --- /dev/null +++ b/app/assets/images/tic.svg @@ -0,0 +1,3 @@ + + + diff --git a/app/assets/stylesheets/application.bootstrap.scss b/app/assets/stylesheets/application.bootstrap.scss index 33233e1..09d7aa1 100644 --- a/app/assets/stylesheets/application.bootstrap.scss +++ b/app/assets/stylesheets/application.bootstrap.scss @@ -200,6 +200,7 @@ $utilities: map-merge( ) ); + .border-solid { border-style: solid; border-color: black; @@ -210,6 +211,11 @@ $utilities: map-merge( transform: translate(-50%, -50%); } +.finish-purchase-logo{ + width: 105px; + height: 129px; +} + .img-highlight{ width: 325px; height: 275px; diff --git a/app/controllers/purchases_controller.rb b/app/controllers/purchases_controller.rb index 530a9e6..2258afe 100644 --- a/app/controllers/purchases_controller.rb +++ b/app/controllers/purchases_controller.rb @@ -7,13 +7,23 @@ def new def create @purchase = Purchase.new(purchase_params) if @purchase.save - redirect_to root_path + redirect_to confirmation_purchases_path else flash.now[:alert] = 'No se pudo realizar la compra, revise el formulario.' render 'new', status: :unprocessable_entity end end + def index + @purchases = Purchase.joins(:payment_method).where(payment_methods: { user: current_user }) + .includes(:gift) + .page(params[:page]) + end + + def show + @purchase = Purchase.find(params[:id]) + end + private def selected_amount diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index a666cb5..ae81d80 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -28,5 +28,8 @@ application.register("notification", NotificationController) import PurchaseProcessController from "./purchase_process_controller" application.register("purchase-process", PurchaseProcessController) +import ShowDestinationsController from "./show_destinations_controller" +application.register("show-destinations", ShowDestinationsController) + import StyleLabelsController from "./style_labels_controller" application.register("style-labels", StyleLabelsController) diff --git a/app/javascript/controllers/show_destinations_controller.js b/app/javascript/controllers/show_destinations_controller.js new file mode 100644 index 0000000..4dbe01a --- /dev/null +++ b/app/javascript/controllers/show_destinations_controller.js @@ -0,0 +1,39 @@ +import { Controller } from "@hotwired/stimulus" + +// Connects to data-controller="show-destinations" +export default class extends Controller { + static classes = ['hide'] + static targets = ['destinationCount', 'rightButton', 'leftButton', 'destinations', 'index'] + + connect() { + if (this.destinationCountTarget.innerHTML == 1) { + this.rightButtonTarget.disabled = true + } + } + + left() { + let actualIndex = parseInt(this.indexTarget.innerHTML) + this.destinationsTarget.children[actualIndex].classList.add(this.hideClass) + this.destinationsTarget.children[actualIndex - 1].classList.remove(this.hideClass) + actualIndex-- + if (actualIndex == 0) { + this.leftButtonTarget.disabled = true + } + this.indexTarget.innerHTML = actualIndex + + this.rightButtonTarget.disabled = false + } + + right() { + let actualIndex = parseInt(this.indexTarget.innerHTML) + this.destinationsTarget.children[actualIndex].classList.add(this.hideClass) + this.destinationsTarget.children[actualIndex + 1].classList.remove(this.hideClass) + actualIndex++ + if (actualIndex + 1 == parseInt(this.destinationCountTarget.innerHTML)) { + this.rightButtonTarget.disabled = true + } + this.indexTarget.innerHTML = actualIndex + + this.leftButtonTarget.disabled = false + } +} diff --git a/app/models/purchase.rb b/app/models/purchase.rb index 0129b63..5ff887e 100644 --- a/app/models/purchase.rb +++ b/app/models/purchase.rb @@ -11,4 +11,8 @@ class Purchase < ApplicationRecord delegate :name, to: :payment_method, prefix: true validates :destinations, length: { minimum: 1 } validates :personalization, :social_reason, :RUT, :destinations, presence: true + + def logo_resized + company_logo.variant(resize_to_limit: [50, 25]).processed + end end diff --git a/app/views/application/_header.html.erb b/app/views/application/_header.html.erb index ff5ac8f..7ea85eb 100644 --- a/app/views/application/_header.html.erb +++ b/app/views/application/_header.html.erb @@ -65,7 +65,7 @@
  • <%= link_to 'Cuenta', users_show_path, class:'fw-light text-black text-decoration-none' %>
  • <%= link_to 'Favoritos', root_path, class:'fw-light text-reset text-decoration-none' %>
  • -
  • <%= link_to 'Pedidos y consultas', root_path, class:'fw-light text-reset text-decoration-none' %>
  • +
  • <%= link_to 'Pedidos y consultas', purchases_path, class:'fw-light text-reset text-decoration-none' %>
  • <%= link_to 'Campañas y metricas', root_path, class:' fw-light text-reset text-decoration-none' %>
  • <%= link_to 'Ayuda', root_path, class:'fw-light text-grey text-decoration-none' %>
  • <%= link_to 'Cerrar sesion', destroy_user_session_path, data:{ turbo_method: "delete" }, class:'fw-light text-grey text-decoration-none' %>
  • @@ -130,7 +130,7 @@
  • <%= link_to 'Cuenta', users_show_path, class:'fw-light text-black text-decoration-none' %>
  • <%= link_to 'Favoritos', root_path, class:'fw-light text-reset text-decoration-none' %>
  • -
  • <%= link_to 'Pedidos y consultas', root_path, class:'fw-light text-reset text-decoration-none' %>
  • +
  • <%= link_to 'Pedidos y consultas', purchases_path, class:'fw-light text-reset text-decoration-none' %>
  • <%= link_to 'Campañas y metricas', root_path, class:' fw-light text-reset text-decoration-none' %>
  • <%= link_to 'Ayuda', root_path, class:'fw-light text-grey text-decoration-none' %>
  • <%= link_to 'Cerrar sesion', destroy_user_session_path, data:{ turbo_method: "delete" }, class:'fw-light text-grey text-decoration-none' %>
  • diff --git a/app/views/purchases/confirmation.html.erb b/app/views/purchases/confirmation.html.erb new file mode 100644 index 0000000..bc22884 --- /dev/null +++ b/app/views/purchases/confirmation.html.erb @@ -0,0 +1,10 @@ +<% content_for :header do %> + <% render 'header', show_mobile: true, categories: @categories, filters: @filters, selected_tab: :gifts %> +<% end %> +
    + <%= image_tag("Logo.svg", class:"finish-purchase-logo mb-8") %> +

    Pedido realizado

    +

    Te enviaremos una notificación una vez que el servicio esté confirmado.

    + <%= link_to 'VOLVER AL INICIO', root_path, class: 'w-100 btn btn-outline-dark px-5 py-1 fs-sm-5 d-md-none'%> + <%= link_to 'VOLVER AL INICIO', root_path, class: 'd-none d-md-flex btn btn-outline-dark px-5 py-1 fs-5'%> +
    diff --git a/app/views/purchases/index.html.erb b/app/views/purchases/index.html.erb new file mode 100644 index 0000000..6660212 --- /dev/null +++ b/app/views/purchases/index.html.erb @@ -0,0 +1,36 @@ +<% content_for :header do %> + <% render 'header', show_mobile: true, categories: @categories, filters: @filters, selected_tab: :none %> +<% end %> +
    +
    +

    Mis Pedidos

    +
    +
    + <%= link_to 'Volver al inicio', root_path, class: 'fw-light text-blue-2 text-decoration-none mb-0' %> +
    +
    +
    +
    + <% @purchases.each do |purchase| %> + <%= link_to purchase_path(purchase), class:'text-decoration-none' do %> +
    +
    + <%= image_tag(purchase.gift.image_resized, class: 'rounded-top-2') %> +
    +
    +
    +

    <%= purchase.gift_name.truncate(12, separator: ' ') %>

    +
    +

    <%= I18n.l(purchase.created_at, format: "%B %d, %Y") %>

    +
    +
    +

    $<%= purchase.gift_price %>

    +
    +
    + <% end %> + <% end %> +
    +
    + <%= paginate @purchases %> +
    +
    diff --git a/app/views/purchases/new.html.erb b/app/views/purchases/new.html.erb index f34402a..bdbc883 100644 --- a/app/views/purchases/new.html.erb +++ b/app/views/purchases/new.html.erb @@ -115,7 +115,7 @@

    Subtotal

    - <%= form.text_field :subtotal, readonly:true, class: 'fs-2 fs-sm-4 fw-light mb-0 fs-lg-1 border-0 pointer-events-none text-end' %> + <%= form.text_field :subtotal, readonly:true, class: 'fs-2 fs-sm-4 fw-light mb-0 fs-lg-1 border-0 pointer-events-none text-end bg-transparent' %>

    Costo de envío

    diff --git a/app/views/purchases/show.html.erb b/app/views/purchases/show.html.erb new file mode 100644 index 0000000..298b0af --- /dev/null +++ b/app/views/purchases/show.html.erb @@ -0,0 +1,111 @@ +<% content_for :header do %> + <% render 'header', show_mobile: false, categories: @categories, filters: @filters, selected_tab: :none %> +<% end %> +
    +
    +
    + <%= link_to '< Volver', purchases_path, class: 'fw-light text-black text-decoration-none fs-2 fs-sm-6 mt-7 mb-md-3 mb-7 d-lg-none' %> +

    Detalles de la entrega

    +

    Detalles de la entrega

    +

    Destinatarios

    +
    + + +
    +
    +
    +
    <%= @purchase.destinations.count %>
    +
    0
    +
    + <% @purchase.destinations.each_with_index do |destination, index| %> +
    +
    +
    +
    Nombre
    +

    <%= destination.receiver %>

    +
    +
    +
    Fecha de entrega
    +

    <%= destination.day %>

    +
    +
    +
    Dirección
    +

    <%= destination.address %>

    +
    +
    +
    +
    +
    Número de contacto
    +

    <%= destination.number %>

    +
    +
    +
    Horarios de entrega
    +

    <%= destination.schedules %>

    +
    +
    +
    Costo de envío
    +

    <%= destination.cost %>

    +
    +
    +
    + <% end %> +
    +
    +
    +

    + <%= image_tag(@purchase.suprise_delivery ? 'tic.svg' : 'cross.svg', width: '24px', height: '24px', class:'vertical-align-middle') %> + Entrega Sopresa +

    +

    + <%= image_tag(@purchase.resend_delivery ? 'tic.svg' : 'cross.svg', width: '24px', height: '24px', class:'vertical-align-middle') %> + Intentar Reenvíos +

    +

    + Logo Adjuntado: <%= image_tag(@purchase.company_logo.present? ? @purchase.logo_resized : 'cross.svg', class:'vertical-align-middle') %> +

    +

    Personalización

    +

    <%= @purchase.personalization %>

    + +
    +
    +
    +
    + +

    Detalles de compra

    +

    Detalles de compra

    +
    + <%= image_tag(@purchase.gift.image_resized_for_purchase, class:'img-gift-purchase') %> +
    +

    <%= "#{@purchase.gift.supplier_name} | #{@purchase.gift_name}" %>

    +

    Pagado a través de <%= @purchase.payment_method_name %>

    +
    +
    +
    +
    +

    Personalizaciones Incluidas: <%= @purchase.customizations.empty? ? 'Ninguna' : '' %>

    +
      + <% @purchase.customizations.each do |customization| %> +
    • + <%= customization.name%> +
    • + <% end %> +
    +
    +
    +

    Información de facturación

    +
    +
    RUT
    +

    <%= @purchase.RUT %>

    +
    +
    +
    Razón Social
    +

    <%= @purchase.social_reason %>

    +
    +
    +
    +

    TOTAL

    +

    $ <%= @purchase.price %> +

    +
    +
    diff --git a/config/routes.rb b/config/routes.rb index d5b38c4..37c6aad 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,7 +17,9 @@ resources :merchandising, only: [:index] resources :events, path: 'eventos', only: [:index] - resources :purchases, path: 'compras', only: [:new, :create] + resources :purchases, path: 'compras', only: [:new, :create, :index, :show] do + get :confirmation, on: :collection + end devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions', passwords: 'users/passwords' }