This commit is contained in:
Nicolas Bally 2018-03-02 00:52:56 +01:00
parent 0b91dcd816
commit d6861c3c20
21 changed files with 452 additions and 124 deletions

View File

@ -191,6 +191,10 @@ class Admin::ProductOrdersController < ApplicationController
@product_order = ProductOrder.find(params[:id])
end
def subs
@product_order = ProductOrder.find(params[:id])
end
def bill
@ -200,8 +204,8 @@ class Admin::ProductOrdersController < ApplicationController
@temp_file = "#{Rails.root}/pdf/donator_transactions_recus/FACTURE_#{@product_order.id}_temp.pdf"
@final_file = "#{Rails.root}/pdf/donator_transactions_recus/FACTURE_#{@product_order.id}.pdf"
@temp_file = "#{Rails.root}/pdf/facture/FACTURE_#{@product_order.id}_temp.pdf"
@final_file = "#{Rails.root}/pdf/facture/FACTURE_#{@product_order.id}.pdf"
view = ActionView::Base.new(Rails.root.join('app/views'))

View File

@ -11,8 +11,14 @@ class Public::PaymentsController < ApplicationController
if params[:orderID]
if @payment.ogone_payid? and !@payment.element.paid
@abonnement = @payment.element
@payment = @abonnement.payments.create(:amount => @abonnement.total_price_ttc, :payment_type_id => 1, :customer_id => current_customer.id)
if @payment.element_type == "ProductOrder"
redirect_to select_payment_public_product_orders_path(:paid_fail => 1)
else
@abonnement = @payment.element
@payment = @abonnement.payments.create(:amount => @abonnement.total_price_ttc, :payment_type_id => 1, :customer_id => current_customer.id)
end
end
end
@ -75,6 +81,10 @@ class Public::PaymentsController < ApplicationController
#redirect_to paid_public_payment_path(@payment)
end
if @payment.element_type == "ProductOrder"
redirect_to paid_by_ogone_confirm_public_product_orders_path()
end
end

View File

@ -172,7 +172,13 @@ class Public::ProductOrdersController < ApplicationController
if @product_order.product_order_payment_type_ok_id == 3
redirect_to paid_by_ogone_public_product_orders_path()
#redirect_to paid_by_ogone_public_product_orders_path()
@payment = @product_order.payments.create(:amount => @product_order.archived_total_ttc, :payment_type_id => 1, :customer_id => current_customer.id)
session[:payment_id] = @payment.id
redirect_to paid_by_ogone_public_payment_path(@payment)
else
if [10, 1, 2, 4].include?(@product_order.product_order_payment_type_ok_id)
@ -189,7 +195,7 @@ class Public::ProductOrdersController < ApplicationController
@product_order.completed_finish = true
@product_order.save
@product_order.after_paid
@product_order.after_paid_old
#@product_order.generate_bl_number
@ -381,33 +387,10 @@ class Public::ProductOrdersController < ApplicationController
def paid_by_ogone_confirm
@check = OgoneRails::CheckAuth.new( request )
if @check.valid?
@product_order_payment = ProductOrderPayment.find_by_token(params[:orderID])
@product_order = @product_order_payment.product_order
end
if !@product_order.paid
update_ogone_infos()
end
@product_order = ProductOrder.find(session[:product_order_id])
session[:product_order_id] = nil if @product_order.paid
@past_product_order = @product_order
@product_order = ProductOrder.new
if !@past_product_order.paid
redirect_to select_payment_public_product_orders_path(:orderID => "fail")
end
end

View File

@ -0,0 +1,2 @@
class Fournisseur < ActiveRecord::Base
end

View File

@ -2,6 +2,8 @@ class Product < ActiveRecord::Base
belongs_to :reseaux
has_many :sub_products, :dependent => :destroy
accepts_nested_attributes_for :sub_products
has_many :product_product_sizes, :dependent => :destroy
has_many :product_sizes, :through => :product_product_sizes

View File

@ -1,7 +1,12 @@
class ProductOrder < ActiveRecord::Base
has_many :payments, :as => :element
has_many :product_order_products
has_many :sub_products, :through => :product_order_products
has_many :fournisseurs, :through => :sub_products
has_many :product_order_payments
belongs_to :product_order_payment_ok, :class_name => "ProductOrderPayment"
@ -185,8 +190,8 @@ class ProductOrder < ActiveRecord::Base
def generate_bill_number
if !self.bill_number and self.paid and self.product_order_payment_type_ok_id == 3
self.paid_at = self.product_order_payment_ok.paid_at
if !self.bill_number and self.paid and self.product_order_payment_type_ok_id == 3 and self.payments.where(:paid => true).first
self.paid_at = self.payments.where(:paid => true).first.paid_at
self.bill_year = self.paid_at.year
@ -196,13 +201,32 @@ class ProductOrder < ActiveRecord::Base
last_number = 0
last_number = ProductOrder.where("paid_at is not null").where(:bill_year => self.bill_year ).order("bill_index DESC").first.bill_index if ProductOrder.where("paid_at is not null").where(:bill_year => self.bill_year ).first
self.bill_index = last_number+1
self.bill_number = "WEB"+self.bill_year.to_s+('%04d' % self.bill_index)
self.bill_number = "NG"+self.bill_year.to_s+('%04d' % self.bill_index)
self.save(:validate => false)
end
end
def after_paid
self.product_order_products.each do |p|
p.update_stock_th
end
self.product_order_payment_type_ok_id = 3
self.completed_finish = true
self.paid_at = Time.now
self.paid = true
self.save
self.generate_bill_number
self.generate_bl_number
end
def after_paid_old
puts "TTTTTT"
self.product_order_products.each do |p|
@ -219,7 +243,7 @@ class ProductOrder < ActiveRecord::Base
def generate_bl_number
if !self.bl_number and ([1,2,4,10].include?(self.product_order_payment_type_ok_id))
if !self.bl_number and ([1,2,3,4,10].include?(self.product_order_payment_type_ok_id))
self.bl_year = self.updated_at.year
@ -293,7 +317,17 @@ class ProductOrder < ActiveRecord::Base
p.save
end
end
p.sub_products.destroy_all
p.product.sub_products.each do |sub_product|
dup_sub_product = sub_product.dup
dup_sub_product.product_order_product = p
dup_sub_product.product = nil
dup_sub_product.sub_product_reference_id = sub_product.id
dup_sub_product.archived = true
dup_sub_product.save
end
# save

View File

@ -11,6 +11,7 @@ class ProductOrderProduct < ActiveRecord::Base
belongs_to :archived_product_size, class_name: "ProductSize"
belongs_to :archived_product_option, class_name: "ProductOption"
has_many :sub_products
def sage_reference
if self.product

22
app/models/sub_product.rb Normal file
View File

@ -0,0 +1,22 @@
class SubProduct < ActiveRecord::Base
belongs_to :fournisseur
belongs_to :product
belongs_to :product_order_product
def price_ht_with_qte
self.price_ht * self.qte
end
def qte_tot
if self.product_order_product
self.qte * self.product_order_product.qty
else
0.0
end
end
def price_tot_with_qte
self.qte_tot * self.price_ht
end
end

View File

@ -4,14 +4,15 @@
%meta{:"http-equiv" => "Content-Type", :content=>"text/html; charset=UTF-8"}
%meta{:name=>"viewport", :content=>"width=device-width,initial-scale=1"}
:css
<link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,700i" rel="stylesheet">
:scss
body{
font-size:11pt;
padding :0px;
margin:0px;
background-color: transparent;
font-family:"Arial" ;
font-family:"Lato", Arial, Sans-serif;
padding:1cm;
}
#main{
@ -29,6 +30,15 @@
border-bottom:1px solid gray;
text-align:left;
}
td{
border-bottom:1px solid rgba(0,0,0,0.1);
p{
margin:5px 0;
}
}
table{
border-collapse:collapse;
@ -87,26 +97,27 @@
%body
#main
%div{:style => "position:absolute;top:1cm;right:1cm;text-align:right;"}
%div{:style => "position:absolute;top:4.4cm;right:1cm;text-align:right;"}
Facture n°
=@product_order.bill_number
%br
=l @product_order.paid_at, :format => :date
%div{:style => "height:300px;"}
%div{:style => "height:350px;"}
%table.table{:style => "position:absolute;right:1cm;top:220px"}
%tr
%td{:style => "min-width:6cm;"}
%td{:style => "width:5.5cm;border:0"}
%h3 Adresse de facturation
%strong
=@product_order.particular_bill.firstname
%strong=@product_order.particular_bill.organisation
%br
=@product_order.particular_bill.firstname
=@product_order.particular_bill.name
=@product_order.particular_bill.name
%br
=@product_order.particular_bill.address_2
@ -119,15 +130,19 @@
=@product_order.particular_bill.city
%br
=@product_order.particular_bill.country
%br
%br
=@product_order.particular_bill.tel
%td
%td{:style => "width:5.5cm;border:0"}
%h3 Adresse de livraison
%strong
=@product_order.particular_send.firstname
%strong=@product_order.particular_bill.organisation
%br
=@product_order.particular_send.firstname
=@product_order.particular_send.name
=@product_order.particular_send.name
%br
=@product_order.particular_send.address_2
@ -140,93 +155,81 @@
=@product_order.particular_send.city
%br
=@product_order.particular_send.country
%br
%br
=@product_order.particular_bill.tel
%table.table{:style => "width:100%;margin:1cm 0;"}
%tr
%th
%th
Description
%th
Taille
%th
Option
%th
%th{:style => "text-align:right;width:100px"}
Prix U. HT
%th{:style => "text-align:right;width:80px"}
Qté
%th
Unitaire
%th
Montant
%th{:style => "text-align:right;width:100px"}
Prix HT
-@product_order.product_order_products.order(:product_id).each do |product_order_product|
%tr
%td{:style => "width:135px;padding:0;vertical-align:middle"}
=image_tag "http://negos.pro"+product_order_product.product.default_image.image_file.file.large.medium.small.thumb.url, :style => "width:130px;" if product_order_product.product.default_image
%td
=simple_format product_order_product.archived_product.lang(:fr).bl_title
=# product_order_product.archived_product_size.name if product_order_product.archived_product_size
%td
= product_order_product.archived_product.lang(:fr).title
=# product_order_product.archived_product_option.lang(I18n.locale).name if product_order_product.archived_product_option
%td
= product_order_product.archived_product_size.name if product_order_product.archived_product_size
%td
= product_order_product.archived_product_option.lang(I18n.locale).name if product_order_product.archived_product_option
%td
= number_to_currency(product_order_product.archived_product.final_price_ttc.to_f, locale: :fr) if product_order_product.archived_product
%td
%td{:style => "text-align:right;"}
= number_to_currency(product_order_product.archived_product.final_price_ht.to_f, locale: :fr) if product_order_product.archived_product
%td{:style => "text-align:right;"}
=product_order_product.qty
%td
= number_to_currency(product_order_product.archived_final_price_ttc_with_qty, locale: :fr) if product_order_product.archived_product
%td{:style => "text-align:right;"}
= number_to_currency(product_order_product.archived_final_price_ht_with_qty, locale: :fr) if product_order_product.archived_product
%tr
%td{:colspan => 4, :style => "border:0;"}
%td Total :
%td= number_to_currency(@product_order.archived_total_articles, locale: :fr)
-if @product_order.vourcher_code_archived
%tr
%td{:colspan => 4, :style => "border:0;"}
%td
=qit "Code réduction tableau", "Code de réduction "
="("+@product_order.vourcher_code_archived.slug+") :"
%td
="-"
=number_to_currency @product_order.archived_vourcher_reduction, locale: :fr
%td{:colspan => 3, :rowspan => 3, :style => "border:0;text-align:left;"}
%p
%br
Mode de paiment :
-if @product_order.product_order_payment_type_ok_id == 3
CB
-elsif @product_order.product_order_payment_type_ok_id == 1
Chèque
-elsif @product_order.product_order_payment_type_ok_id == 2
Virement
-elsif @product_order.product_order_payment_type_ok_id == 4
Mandat administratif
%br
%br
Franco de port pour le Pays Voironnais
%td Total HT :
%td{:style => "text-align:right;"}= number_to_currency(@product_order.archived_total_ht, locale: :fr)
%tr
%td{:colspan => 4, :style => "border:0;"}
%td Frais de port :
%td= number_to_currency(@product_order.archived_total_fdp, locale: :fr)
%td TVA :
%td{:style => "text-align:right;"}= number_to_currency(@product_order.archived_total_tva, locale: :fr)
%tr
%td{:colspan => 4, :style => "border:0;"}
%td
%strong Total :
%td
%strong
= number_to_currency(@product_order.archived_total_ttc, locale: :fr)
%p
Mode de paiment :
-if @product_order.product_order_payment_type_ok_id == 3
CB
-elsif @product_order.product_order_payment_type_ok_id == 1
Chèque
%br
%p
Association à but non lucratif, non soumise à la TVA
%br
TVA non applicable, article 293B du code général des impots
<!---
.fdp
%table.table
%tr
%td
=@product_order.product_fdp_archived.fdp_description
%td
=number_to_currency @product_order.product_fdp_archived.price
="--->"
%td Total TTC :
%td{:style => "text-align:right;"}= number_to_currency(@product_order.archived_total_ttc, locale: :fr)
%br

View File

@ -11,7 +11,8 @@
.qi_row
.qi_pannel.qi_plain.padding
%p
=link_to "Voir le détail des sous produits", subs_admin_product_order_path(@product_order)
%p
Payée ?

View File

@ -0,0 +1,192 @@
.qi_header
.right=# link_to 'Ajouter une taille', new_admin_product_size_path, :class => "btn btn-primary", :remote => true
%h1
Boutique
%span
Détail des sous produits de la commande
="#"+@product_order.id.to_s
.qi_row
.qi_pannel.qi_plain.padding
%table.table
%tr
%td
%h3 Adresse de facturation
=render @product_order.particular_bill if @product_order.particular_bill
%td
%h3 Adresse de livraison
=render @product_order.particular_send if @product_order.particular_send
%table.table
-@product_order.product_order_products.order(:product_id).each do |product_order_product|
%tr
%td
%strong
-if product_order_product.product
=link_to admin_product_path(product_order_product.product) do
= product_order_product.archived_product.lang(:fr).title
-else
= product_order_product.archived_product.lang(:fr).title
%table.sub_products{:style => "width:100%;margin-bottom:20px;margin-top:5px;"}
%tr
%th Référence
%th Nom
%th Nbr / produits
%th Prix / produits
%th Nbr
%th Prix tot. HT
%th Prix tot. TTC
-product_order_product.sub_products.each do |sub_product|
%tr
%td
=sub_product.reference
%td
=sub_product.name
%td
=sub_product.qte
%td
=number_to_currency sub_product.price_ht_with_qte
%td
=sub_product.qte_tot
%td
=number_to_currency sub_product.price_tot_with_qte
%td
=number_to_currency sub_product.price_tot_with_qte*1.2
%td
= product_order_product.archived_product_size.name if product_order_product.archived_product_size
%td
= product_order_product.archived_product_option.lang(I18n.locale).name if product_order_product.archived_product_option
%td
= number_to_currency(product_order_product.archived_product.final_price_ttc.to_f, locale: :fr) if product_order_product.archived_product
%td
=product_order_product.qty
%td
= number_to_currency(product_order_product.archived_final_price_ttc_with_qty, locale: :fr) if product_order_product.archived_product
%tr
%td{:colspan => 4, :style => "border:0;"}
%td Total :
%td= number_to_currency(@product_order.archived_total_articles, locale: :fr)
-if @product_order.vourcher_code_archived
%tr
%td{:colspan => 4, :style => "border:0;"}
%td
=qit "Code réduction tableau", "Code de réduction "
="("+@product_order.vourcher_code_archived.slug+") :"
%td
="-"
=number_to_currency @product_order.archived_vourcher_reduction, locale: :fr
%tr
%td{:colspan => 4, :style => "border:0;"}
%td Frais de port :
%td= number_to_currency(@product_order.archived_total_fdp, locale: :fr)
%tr
%td{:colspan => 4, :style => "border:0;"}
%td
%strong Total :
%td
%strong
= number_to_currency(@product_order.archived_total_ttc, locale: :fr)
.fdp
%table.table
%tr
%td
=@product_order.product_fdp_archived.fdp_description
%td
=number_to_currency @product_order.product_fdp_archived.price
%br
%hr
%h3 Détail des sous produits
%table.table
%tr
%th Fournisseur
%th Référence
%th Nom
%th Nbr Prod.
%th Nbr
%th Prix tot. HT
%th Prix tot. TTC
-@product_order.sub_products.group(:reference).each do |sub_product_group|
%tr
%td
= sub_product_group.fournisseur.name if sub_product_group.fournisseur
%td= sub_product_group.reference
%td= sub_product_group.name
-sub_products = @product_order.sub_products.where(:reference => sub_product_group.reference)
%td
=sub_products.count
%td
-i = 0.0
-sub_products.each do |sub_product|
-i += sub_product.qte_tot
=i
%td
-i = 0.0
-sub_products.each do |sub_product|
-i += sub_product.price_tot_with_qte
=number_to_currency i
%td
=number_to_currency i*1.2
=#number_to_currency sub_product.price_tot_with_qte
%hr
%h3 Détail par fournisseurs
%table.table
%tr
%th Fournisseur
%th Prix HT
%th Prix TTC
-@product_order.fournisseurs.uniq.each do |fournisseur|
%tr
%td=fournisseur.name
%td
-i = 0.0
-@product_order.sub_products.where(:fournisseur_id => fournisseur.id).each do |sub_product|
-i += sub_product.price_tot_with_qte
=number_to_currency i
%td
=number_to_currency i*1.2
%hr
%br
%table.table
%thead
%tr
%th Identifiant paiement
%th Date de paiement
%th Type de paiement
%th ID Ogone
%th Status Ogone
%th Erreur Ogone
%th N°Carte
%th Montant
%th
%tbody#product_order_payments
=render @product_order.product_order_payments.order("created_at DESC")

View File

@ -38,6 +38,14 @@
=form.input :sage_reference, :label => "Référence sage :"
%hr
%h3
Sous produits
%p= link_to_add_fields "Ajouter un sous produit", form, :sub_products
.sub_products_form
=form.semantic_fields_for :sub_products do |form|
=render :partial => "admin/sub_products/form", :locals => {:form => form}
.actions
= form.submit "Sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,15 @@
.field
.product_option_form
%hr
.product_option
=form.input :name
=form.input :qte
=form.input :price_ht
=form.input :reference
=form.input :fournisseur_id, :collection => Fournisseur.all, :as => :select
= link_to_remove_fields i(:"trash-o"), form

View File

@ -1,4 +1,8 @@
.center
%h1 Merci pour votre paiement !
%p
Vous pouvez désormais profiter de votre abonnement.
-if @payement.element_type == "ProductOrder"
Votre commande est validée
-else
%p
Vous pouvez désormais profiter de votre abonnement.

View File

@ -55,7 +55,7 @@
=f.input :product_order_payment_type_ok_id, :label => false, :collection => [["Chèque",1], ["Virement",2],["Mandat administratif",4]], :as => :radio, :include_blank => false #["Pré-commande",10]
=f.input :product_order_payment_type_ok_id, :label => false, :collection => [["Chèque",1], ["Virement",2],["Carte bancaire",3],["Mandat administratif",4]], :as => :radio, :include_blank => false #["Pré-commande",10]
.cb_infos

View File

@ -329,12 +329,11 @@ Rails.application.routes.draw do
get :export
get :export2
end
member do
get :ship
get :bill
get :bl
member do
get :ship
get :bill
get :bl
get :subs
end
end

BIN
pdf_stamp/facture.pdf Normal file

Binary file not shown.

13
test/fixtures/fournisseurs.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
description: MyText
iban: MyString
bic: MyString
two:
name: MyString
description: MyText
iban: MyString
bic: MyString

21
test/fixtures/sub_products.yml vendored Normal file
View File

@ -0,0 +1,21 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
product_id: 1
name: MyString
description: MyText
price_ht: 9.99
price_ht_total: 9.99
qte: 9.99
product_order_product_id: 1
fournisseur_id: 1
two:
product_id: 1
name: MyString
description: MyText
price_ht: 9.99
price_ht_total: 9.99
qte: 9.99
product_order_product_id: 1
fournisseur_id: 1

View File

@ -0,0 +1,7 @@
require 'test_helper'
class FournisseurTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class SubProductTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end