Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View purchases #15

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/assets/images/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/images/tic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/application.bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ $utilities: map-merge(
)
);


.border-solid {
border-style: solid;
border-color: black;
Expand All @@ -210,6 +211,11 @@ $utilities: map-merge(
transform: translate(-50%, -50%);
}

.finish-purchase-logo{
width: 105px;
height: 129px;
}

.img-highlight{
width: 325px;
height: 275px;
Expand Down
12 changes: 11 additions & 1 deletion app/controllers/purchases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
39 changes: 39 additions & 0 deletions app/javascript/controllers/show_destinations_controller.js
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 4 additions & 0 deletions app/models/purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/views/application/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<li class="list-group-item-action py-3 border-top-solid border-top-1 border-dark">
<%= link_to 'Cuenta', users_show_path, class:'fw-light text-black text-decoration-none' %></li>
<li class="py-3 border-top-solid border-top-1 border-dark"> <%= link_to 'Favoritos', root_path, class:'fw-light text-reset text-decoration-none' %></li>
<li class="py-3 border-top-solid border-top-1 border-dark"> <%= link_to 'Pedidos y consultas', root_path, class:'fw-light text-reset text-decoration-none' %></li>
<li class="py-3 border-top-solid border-top-1 border-dark"> <%= link_to 'Pedidos y consultas', purchases_path, class:'fw-light text-reset text-decoration-none' %></li>
<li class="py-3 border-top-solid border-top-1 border-dark"> <%= link_to 'Campañas y metricas', root_path, class:' fw-light text-reset text-decoration-none' %></li>
<li class="py-3 border-top-solid border-top-1 border-dark"> <%= link_to 'Ayuda', root_path, class:'fw-light text-grey text-decoration-none' %></li>
<li class="py-3 border-top-solid border-top-1 border-grey"> <%= link_to 'Cerrar sesion', destroy_user_session_path, data:{ turbo_method: "delete" }, class:'fw-light text-grey text-decoration-none' %></li>
Expand Down Expand Up @@ -130,7 +130,7 @@
<li class="py-1 border-top-solid border-top-1 border-dark">
<%= link_to 'Cuenta', users_show_path, class:'fw-light text-black text-decoration-none' %></li>
<li class="py-1 border-top-solid border-top-1 border-dark"> <%= link_to 'Favoritos', root_path, class:'fw-light text-reset text-decoration-none' %></li>
<li class="py-1 border-top-solid border-top-1 border-dark"> <%= link_to 'Pedidos y consultas', root_path, class:'fw-light text-reset text-decoration-none' %></li>
<li class="py-1 border-top-solid border-top-1 border-dark"> <%= link_to 'Pedidos y consultas', purchases_path, class:'fw-light text-reset text-decoration-none' %></li>
<li class="py-1 border-top-solid border-top-1 border-dark"> <%= link_to 'Campañas y metricas', root_path, class:' fw-light text-reset text-decoration-none' %></li>
<li class="py-1 border-top-solid border-top-1 border-dark"> <%= link_to 'Ayuda', root_path, class:'fw-light text-grey text-decoration-none' %></li>
<li class="py-1 border-top-solid border-top-1 border-grey"> <%= link_to 'Cerrar sesion', destroy_user_session_path, data:{ turbo_method: "delete" }, class:'fw-light text-grey text-decoration-none' %></li>
Expand Down
10 changes: 10 additions & 0 deletions app/views/purchases/confirmation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% content_for :header do %>
<% render 'header', show_mobile: true, categories: @categories, filters: @filters, selected_tab: :gifts %>
<% end %>
<div class="d-flex flex-column align-items-center px-12 pt-lg-10">
<%= image_tag("Logo.svg", class:"finish-purchase-logo mb-8") %>
<h1 class= "bg-text-gradient-blue-20 text-fill-color-transparent fs-6 fw-medium mb-3 fs-sm-8"> Pedido realizado</h1>
<p class = "fs-1 text-center mb-8 fs-sm-3" >Te enviaremos una notificación una vez que el servicio esté confirmado.</p>
<%= 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'%>
</div>
36 changes: 36 additions & 0 deletions app/views/purchases/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<% content_for :header do %>
<% render 'header', show_mobile: true, categories: @categories, filters: @filters, selected_tab: :none %>
<% end %>
<div class="d-flex flex-column">
<div class="d-flex justify-content-center justify-content-md-between align-items-baseline border-bottom-solid">
<h1 class= "bg-text-gradient-blue-20 text-fill-color-transparent">Mis Pedidos</h1>
<div class="">
<div class="d-none d-md-flex flex-column align-items-end fs-md-5 fs-lg-3">
<%= link_to 'Volver al inicio', root_path, class: 'fw-light text-blue-2 text-decoration-none mb-0' %>
</div>
</div>
</div>
<div class="d-flex justify-content-sm-between justify-content-center pt-8 flex-wrap row-gap-5">
<% @purchases.each do |purchase| %>
<%= link_to purchase_path(purchase), class:'text-decoration-none' do %>
<div class="d-flex flex-column bg-white rounded-2 hover-border-grey border-style-solid border-color-transparent me-2">
<div>
<%= image_tag(purchase.gift.image_resized, class: 'rounded-top-2') %>
</div>
<div class="d-flex flex-column px-3 pt-4">
<div class="d-flex justify-content-between mb-3">
<p class= "fs-4 fw-medium mb-0 text-black"><%= purchase.gift_name.truncate(12, separator: ' ') %></p>
<div class="d-flex align-items-center">
<p class="mb-0 fs-4 text-black"> <%= I18n.l(purchase.created_at, format: "%B %d, %Y") %> </p>
</div>
</div>
<p class="fs-4 text-blue-2 mb-3 text-center">$<%= purchase.gift_price %></p>
</div>
</div>
<% end %>
<% end %>
</div>
<div class="d-flex my-3 justify-content-center mx-0">
<%= paginate @purchases %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/purchases/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
</div>
<div class="d-flex justify-content-between mb-2">
<p class="fs-2 fs-sm-4 fw-light text-role-grey mb-0 fs-lg-1">Subtotal</p>
<%= 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' %>
</div>
<div class="d-flex justify-content-between mb-2">
<p class="fs-2 fs-sm-4 fw-light text-role-grey mb-0 fs-lg-1">Costo de envío</p>
Expand Down
111 changes: 111 additions & 0 deletions app/views/purchases/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<% content_for :header do %>
<% render 'header', show_mobile: false, categories: @categories, filters: @filters, selected_tab: :none %>
<% end %>
<div data-controller="purchase-process" data-purchase-process-hide-class='d-none' class="d-lg-flex justify-content-around">
<div data-controller = "show-destinations" data-show-destinations-hide-class='d-none' data-purchase-process-target= "delivery">
<div class="d-flex flex-column top-0 position-lg-static position-absolute mt-md-16 mt-lg-0">
<%= 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' %>
<h3 class="fw-medium fs-4 fs-sm-6 bg-text-gradient-blue-20 text-fill-color-transparent mb-5 mb-md-1 d-lg-none">Detalles de la entrega </h3>
<h3 class="fw-medium fs-6 bg-text-gradient-blue-20 text-fill-color-transparent mb-lg-3 d-none d-lg-flex">Detalles de la entrega </h3>
<h4 class='fw-medium fs-3 fs-sm-5 mt-md-3 mt-lg-0'>Destinatarios</h4>
<div class="d-flex">
<button class="fs-6 border-0 bg-transparent ps-0" data-action="click->show-destinations#left" data-show-destinations-target="leftButton" disabled="true"><</button>
<button class="fs-6 border-0 bg-transparent ms-2" data-action="click->show-destinations#right" data-show-destinations-target="rightButton" >>
</button>
</div>
</div>
<div class="d-flex mt-2 mt-sm-20 mt-md-21 mt-lg-2">
<div class="d-none" data-show-destinations-target="destinationCount"><%= @purchase.destinations.count %> </div>
<div class="d-none " data-show-destinations-target="index"> 0 </div>
<div class="w-100" data-show-destinations-target="destinations" >
<% @purchase.destinations.each_with_index do |destination, index| %>
<div class="d-flex flex-column flex-lg-row column-gap-lg-6 <%= 'd-none' unless index.zero? %>">
<div class="d-flex flex-column">
<div class="d-flex flex-column">
<h5 class="fs-1 fw-light mb-0 fs-sm-3 fs-lg-1" >Nombre </h5>
<p class="text-role-grey border-0 border-bottom-solid outline-none w-100 ps-0 pb-1 fs-sm-5 fs-lg-3" ><%= destination.receiver %></p>
</div>
<div class="d-flex flex-column w-100">
<h5 class="fs-1 fw-light mb-0 fs-sm-3 fs-lg-1" >Fecha de entrega </h5>
<p class="text-role-grey border-0 border-bottom-solid outline-none w-100 ps-0 pb-1 fs-sm-5 fs-lg-3" ><%= destination.day %></p>
</div>
<div class="d-flex flex-column w-100">
<h5 class="fs-1 fw-light mb-0 fs-sm-3 fs-lg-1" >Dirección </h5>
<p class="text-role-grey border-0 border-bottom-solid outline-none w-100 ps-0 pb-1 fs-sm-5 fs-lg-3" ><%= destination.address %></p>
</div>
</div>
<div class="d-flex flex-column">
<div class="d-flex flex-column w-100">
<h5 class="fs-1 fw-light mb-0 fs-sm-3 fs-lg-1" >Número de contacto </h5>
<p class="text-role-grey border-0 border-bottom-solid outline-none w-100 ps-0 pb-1 fs-sm-5 fs-lg-3" ><%= destination.number %></p>
</div>
<div class="d-flex flex-column w-100">
<h5 class="fs-1 fw-light mb-0 fs-sm-3 fs-lg-1" >Horarios de entrega </h5>
<p class="text-role-grey border-0 border-bottom-solid outline-none w-100 ps-0 pb-1 fs-sm-5 fs-lg-3" ><%= destination.schedules %></p>
</div>
<div class="d-flex flex-column w-100">
<h5 class="fs-1 fw-light mb-0 fs-sm-3 fs-lg-1" >Costo de envío </h5>
<p class="text-role-grey border-0 border-bottom-solid outline-none w-100 ps-0 pb-1 fs-sm-5 fs-lg-3" ><%= destination.cost %></p>
</div>
</div>
</div>
<% end %>
</div>
</div>
<div class="d-flex flex-column mt-3">
<p class="fs-2 fw-light mb-2 fs-sm-4 fs-lg-2">
<%= image_tag(@purchase.suprise_delivery ? 'tic.svg' : 'cross.svg', width: '24px', height: '24px', class:'vertical-align-middle') %>
Entrega Sopresa
</p>
<p class="fs-2 fw-light fs-sm-4 fs-lg-2">
<%= image_tag(@purchase.resend_delivery ? 'tic.svg' : 'cross.svg', width: '24px', height: '24px', class:'vertical-align-middle') %>
Intentar Reenvíos
</p>
<p class="fs-2 fw-light fs-sm-4 fs-lg-2">
Logo Adjuntado: <%= image_tag(@purchase.company_logo.present? ? @purchase.logo_resized : 'cross.svg', class:'vertical-align-middle') %>
</p>
<h4 class="fs-3 fs-sm-5 fw-medium mb-0 mt-2">Personalización</h4>
<p class="border-0 text-role-grey fs-1 mt-1 bg-white rounded-1 w-100 fs-sm-3 fs-lg-1 bg-lg-strong-grey"> <%= @purchase.personalization %> </p>
<button type='button' class= 'd-lg-none color-white bg-Blue-lg-30deg border-1 rounded-2 hover-bg-white fs-3 fs-sm-6 hover-border-solid fs-xl-4 hover-border-color-mixBlue border-color-transparent w-100 mt-5' data-action= "click->purchase-process#showPurchase" > Detalles de la Compra</button>
</div>
</div>
<div class="d-none d-lg-flex flex-column bg-lg-white px-lg-10 py-lg-4 justify-content-between mb-lg-2" data-purchase-process-target= "purchase">
<div class="d-flex flex-column top-0 position-absolute mt-md-16 mt-lg-0 position-lg-static">
<button type='button' data-action= "click->purchase-process#showDelivery" class="fw-light text-start fs-2 fs-sm-6 mt-6 mb-7 border-0 bg-transparent d-lg-none mb-md-3"> < Volver </button>
<h3 class="fw-medium fs-4 fs-sm-6 bg-text-gradient-blue-20 text-fill-color-transparent mb-5 d-lg-none mb-md-1">Detalles de compra </h3>
<h3 class="fw-medium fs-5 mb-3 d-none d-lg-flex">Detalles de compra </h3>
<div class="d-flex column-gap-3">
<%= image_tag(@purchase.gift.image_resized_for_purchase, class:'img-gift-purchase') %>
<div class="d-flex flex-column mt-3 mt-lg-0">
<h4 class="fs-3 fs-sm-5 fs-lg-3 mb-0 fw-normal mb-1"><%= "#{@purchase.gift.supplier_name} | #{@purchase.gift_name}" %></h4>
<p class="fs-2 fs-sm-4 fw-light text-role-grey mb-0 fs-lg-1">Pagado a través de <%= @purchase.payment_method_name %> </p>
</div>
</div>
</div>
<div class="d-flex flex-column mt-6 mt-sm-21 mt-md-22 mt-lg-3">
<h4 class="fs-3 fs-sm-5 fw-medium mt-4 mt-sm-7 mt-lg-0 fs-lg-3">Personalizaciones Incluidas: <span class= "fs-3 fw-light mb-2 fs-sm-5 fs-lg-3"><%= @purchase.customizations.empty? ? 'Ninguna' : '' %></span></h4>
<ul>
<% @purchase.customizations.each do |customization| %>
<li class= "fs-2 fw-light mb-2 fs-sm-4 fs-lg-2">
<%= customization.name%>
</li>
<% end %>
</ul>
</div>
<div class="d-flex flex-column">
<h4 class='fw-medium fs-3 fs-sm-5 fs-lg-3 mb-3'>Información de facturación</h4>
<div class="d-flex flex-column">
<h5 class="fs-1 fw-light mb-0 fs-sm-3 fs-lg-1" >RUT </h5>
<p class="text-role-grey border-0 border-bottom-solid outline-none w-100 ps-0 pb-1 fs-sm-5 fs-lg-3 bg-transparent" ><%= @purchase.RUT %></p>
</div>
<div class="d-flex flex-column">
<h5 class="fs-1 fw-light mb-0 fs-sm-3 fs-lg-1" >Razón Social </h5>
<p class="text-role-grey border-0 border-bottom-solid outline-none w-100 ps-0 pb-1 fs-sm-5 fs-lg-3 bg-transparent" ><%= @purchase.social_reason %></p>
</div>
</div>
<div class="d-flex justify-content-between mb-6 mb-lg-0 mt-2">
<p class="fs-3 fs-sm-5 mb-0 fs-lg-2 fw-medium">TOTAL </p>
<p class= 'fs-3 fs-sm-5 fw-medium fs-lg-3 mb-0'>$ <%= @purchase.price %>
</div>
</div>
</div>
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
Loading