suite
This commit is contained in:
parent
484215164c
commit
e5d25ef2e9
@ -26,7 +26,7 @@ class Admin::PDocumentsController < ApplicationController
|
||||
params[:inline] = true
|
||||
|
||||
|
||||
if !params[:html]
|
||||
if false #!params[:html]
|
||||
|
||||
@temp_file = "#{Rails.root}/pdf/p_documents/#{@p_document.d_number}_temp.pdf"
|
||||
@final_file = "#{Rails.root}/pdf/p_documents/#{@p_document.d_number}.pdf"
|
||||
@ -63,5 +63,14 @@ class Admin::PDocumentsController < ApplicationController
|
||||
end
|
||||
|
||||
|
||||
|
||||
def create_avoir
|
||||
@p_document = PDocument.find(params[:id])
|
||||
if @p_document.create_avoir
|
||||
@p_document.element.restock if @p_document.element and @p_document.element_type == "PCustomerSheet"
|
||||
end
|
||||
redirect_to :back
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -2,4 +2,8 @@ class PContact < ActiveRecord::Base
|
||||
|
||||
belongs_to :contactable, :polymorphic => true
|
||||
|
||||
has_many :p_contact_contact_types
|
||||
|
||||
has_many :p_contact_types, :through => :p_contact_contact_types
|
||||
|
||||
end
|
||||
|
4
app/models/p_contact_contact_type.rb
Normal file
4
app/models/p_contact_contact_type.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class PContactContactType < ActiveRecord::Base
|
||||
belongs_to :p_contact
|
||||
belongs_to :p_contact_type
|
||||
end
|
2
app/models/p_contact_type.rb
Normal file
2
app/models/p_contact_type.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class PContactType < ActiveRecord::Base
|
||||
end
|
@ -223,6 +223,8 @@ class PCustomerSheet < ActiveRecord::Base
|
||||
'<span class="badge badge-dark">Annulée</span>'
|
||||
elsif self.state == "refusée"
|
||||
'<span class="badge badge-danger">Refusée</span>'
|
||||
elsif self.state == "remboursée"
|
||||
'<span class="badge badge-danger" style="background:#865F7C;">Remboursée</span>'
|
||||
end
|
||||
end
|
||||
|
||||
@ -283,14 +285,16 @@ class PCustomerSheet < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def generate_f
|
||||
|
||||
|
||||
|
||||
if self.p_documents.create(:p_document_type => PDocumentType.find_by_label("Facture"))
|
||||
self.state = "facturée"
|
||||
self.save
|
||||
if self.save
|
||||
|
||||
self.fige
|
||||
self.fige
|
||||
|
||||
self.unstock
|
||||
self.unstock
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -346,6 +350,20 @@ class PCustomerSheet < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def restock
|
||||
self.p_sheet_lines.each do |sheet_line|
|
||||
p_sheet_line_lines = sheet_line.p_sheet_line_lines.where("qte is not null")
|
||||
p_sheet_line_lines.each do |p_sheet_line_line|
|
||||
if p_sheet_line_line.p_product_stock
|
||||
p_sheet_line_line.p_product_stock.stock_ok = p_sheet_line_line.p_product_stock.stock_ok + p_sheet_line_line.qte
|
||||
p_sheet_line_line.p_product_stock.stock_th_ok = p_sheet_line_line.p_product_stock.stock_th_ok + p_sheet_line_line.qte
|
||||
p_sheet_line_line.p_product_stock.save
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
STATES = ["panier", "brouillon", "offre", "commande", "livrée","facturée", "annulée", "refusée"]
|
||||
|
||||
|
@ -10,6 +10,11 @@ class PDocument < ActiveRecord::Base
|
||||
belongs_to :particular_send, :class_name => "Particular"
|
||||
|
||||
|
||||
|
||||
has_many :relative_docs, :class_name => "PDocument", :foreign_key => :doc_ref_id
|
||||
|
||||
|
||||
|
||||
has_many :p_payment_documents, :dependent => :destroy
|
||||
|
||||
belongs_to :element, :polymorphic => true
|
||||
@ -39,7 +44,7 @@ class PDocument < ActiveRecord::Base
|
||||
|
||||
after_create do
|
||||
generate_number
|
||||
archive_sheet_line
|
||||
archive_sheet_line if self.p_document_type.label != "Avoir"
|
||||
end
|
||||
before_create do
|
||||
self.fdp_force_price = self.element.fdp_force_price
|
||||
@ -58,6 +63,15 @@ class PDocument < ActiveRecord::Base
|
||||
end
|
||||
before_validation do
|
||||
|
||||
|
||||
t = PDocument.where(:doc_ref_id => self.doc_ref_id)
|
||||
if self.id
|
||||
t= t.where("id != ?", self.id)
|
||||
end
|
||||
if self.label == "Avoir" and (!self.id and t.first)
|
||||
#errors.add(:acompte, "Avoir déjà créé")
|
||||
end
|
||||
|
||||
self.paid_completed?
|
||||
self.th_paid_completed?
|
||||
|
||||
@ -69,7 +83,7 @@ class PDocument < ActiveRecord::Base
|
||||
self.verify
|
||||
if !self.id
|
||||
|
||||
if self.p_document_type.label == "Facture" #or self.p_document_type.label == "Bon de livraison"
|
||||
if self.p_document_type.label == "Facture" and self.element.state == "facturée" #or self.p_document_type.label == "Bon de livraison"
|
||||
if PDocument.where(:element_id => self.element_id, :element_type => self.element_type,:p_document_type_id => self.p_document_type_id).count > 0
|
||||
|
||||
|
||||
@ -169,6 +183,9 @@ class PDocument < ActiveRecord::Base
|
||||
|
||||
|
||||
|
||||
self.save
|
||||
|
||||
self.cache_fdp = PSheetLine.frais_de_port(self.p_sheet_lines)
|
||||
self.save
|
||||
end
|
||||
|
||||
@ -292,5 +309,132 @@ class PDocument < ActiveRecord::Base
|
||||
end
|
||||
|
||||
|
||||
def create_avoir
|
||||
p_document = self
|
||||
|
||||
avoir = PDocument.create(:cache_fdp => ((self.cache_fdp * -1) if self.cache_fdp),:fdp_force_price => ((self.fdp_force_price * -1) if self.fdp_force_price),:label => "Avoir", :doc_ref_id => self.id, :doc_ref_number => self.d_number, :p_document_type => PDocumentType.find_by_label("Avoir"), :element_type => self.element_type, :element_id => self.element_id, :p_customer_id => self.p_customer_id, :particular_bill_id => self.particular_bill_id, :particular_send_id => self.particular_send_id)
|
||||
|
||||
|
||||
if false
|
||||
self.p_sheet_lines.each do |p_sheet_line|
|
||||
new_psl = p_sheet_line.dup
|
||||
new_psl.qte = (new_psl.qte*-1)
|
||||
|
||||
avoir.p_sheet_lines << new_psl
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
self.p_sheet_lines.joins(:p_product).each do |p_sheet_line|
|
||||
#fddsf = sfsf
|
||||
n_sheet_line = p_sheet_line.dup
|
||||
|
||||
if n_sheet_line.p_product
|
||||
n_sheet_line.archived_p_product = n_sheet_line.p_product.dup
|
||||
n_sheet_line.archived_p_product.archived = true
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
p_colors_archiveds = []
|
||||
|
||||
p_sizes_archiveds = []
|
||||
|
||||
p_sheet_line.p_sheet_line_lines.each do |psll|
|
||||
new_psll = psll.dup
|
||||
new_psll.qte = (new_psll.qte*-1) if new_psll.qte?
|
||||
|
||||
|
||||
#Attention avant fonction fige
|
||||
#new_psll.fige ########
|
||||
|
||||
|
||||
|
||||
if new_psll.p_product_stock.p_color
|
||||
|
||||
if p_color = p_colors_archiveds[new_psll.p_product_stock.p_color_id]
|
||||
|
||||
else
|
||||
|
||||
p_color = new_psll.p_product_stock.p_color.dup
|
||||
p_color.archived = true
|
||||
|
||||
p_colors_archiveds[new_psll.p_product_stock.p_color_id] = p_color
|
||||
|
||||
end
|
||||
|
||||
new_psll.p_color = p_color
|
||||
end
|
||||
|
||||
if new_psll.p_product_stock.p_size
|
||||
|
||||
if p_size = p_sizes_archiveds[new_psll.p_product_stock.p_size_id]
|
||||
|
||||
else
|
||||
p_size = new_psll.p_product_stock.p_size.dup
|
||||
p_size.archived = true
|
||||
|
||||
|
||||
p_sizes_archiveds[new_psll.p_product_stock.p_size_id] = p_size
|
||||
end
|
||||
|
||||
new_psll.p_size = p_size
|
||||
end
|
||||
|
||||
|
||||
new_psll.ok_code = new_psll.p_product_stock.code
|
||||
|
||||
|
||||
|
||||
|
||||
#end ################
|
||||
|
||||
|
||||
n_sheet_line.p_sheet_line_lines << new_psll
|
||||
|
||||
|
||||
end
|
||||
|
||||
n_sheet_line.p_customer_sheet = nil
|
||||
|
||||
if p_sheet_line.ok_price
|
||||
n_sheet_line.ok_price = p_sheet_line.ok_price
|
||||
else
|
||||
n_sheet_line.ok_price = p_sheet_line.price
|
||||
end
|
||||
|
||||
|
||||
avoir.p_sheet_lines << n_sheet_line
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
r = avoir.save
|
||||
|
||||
|
||||
if avoir.element and avoir.element_type == "PCustomerSheet"
|
||||
avoir.element.state = "remboursée"
|
||||
avoir.element.save
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
@ -398,7 +398,12 @@ class PSheetLine < ActiveRecord::Base
|
||||
|
||||
def self.frais_de_port(p_sheet_lines)
|
||||
|
||||
if p_sheet_lines[0] and ((p_sheet_lines[0].p_customer_sheet and p_sheet_lines[0].p_customer_sheet.fdp_force_price) or (p_sheet_lines[0].p_document and p_sheet_lines[0].p_document.fdp_force_price))
|
||||
if p_sheet_lines[0] and ((p_sheet_lines[0].p_document and p_sheet_lines[0].p_document.cache_fdp?))
|
||||
|
||||
p_sheet_lines[0].p_document.cache_fdp
|
||||
|
||||
|
||||
elsif p_sheet_lines[0] and ((p_sheet_lines[0].p_customer_sheet and p_sheet_lines[0].p_customer_sheet.fdp_force_price) or (p_sheet_lines[0].p_document and p_sheet_lines[0].p_document.fdp_force_price))
|
||||
if p_sheet_lines[0].p_document
|
||||
p_sheet_lines[0].p_document.fdp_force_price
|
||||
elsif p_sheet_lines[0].p_customer_sheet
|
||||
|
@ -8,13 +8,41 @@
|
||||
%strong BL
|
||||
|
||||
= form.input :bc, :label => ""
|
||||
|
||||
|
||||
%td
|
||||
= form.input :civilite, :label => "Civ. :", :collection => ["M", "Mme"], :as => :select
|
||||
|
||||
%td
|
||||
= form.input :firstname, :label => "Prénom :"
|
||||
|
||||
%td
|
||||
= form.input :name, :label => "Nom du contact :"
|
||||
%td
|
||||
= form.input :comment, :label => "Fonction, commentaire :", :as => :string
|
||||
= form.input :comment, :label => "Fonction :", :as => :string
|
||||
%td
|
||||
= form.input :tel, :label => "Tel :"
|
||||
%td
|
||||
= form.input :email, :label => "Email :"
|
||||
%td{:style => "width:30px;"}
|
||||
=link_to_remove_fields ic(:"trash-o"), form
|
||||
=link_to_remove_fields ic(:"trash-o"), form
|
||||
|
||||
.cats= form.input :p_contact_type_ids, :label => false, :collection => PContactType.all, :as => :check_boxes
|
||||
|
||||
:scss
|
||||
.cats{
|
||||
label, input, .checkbox{
|
||||
display:inline-block;
|
||||
}
|
||||
.checkbox{
|
||||
margin:0;
|
||||
}
|
||||
label{
|
||||
padding-right:5px;
|
||||
input{
|
||||
margin-left:0 !important;
|
||||
margin-right:2px;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -103,7 +103,7 @@
|
||||
-if @p_customer_sheet.acompte_percent?
|
||||
%p=link_to "Générer la facture d'acompte", generate_fa_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
|
||||
|
||||
-elsif @p_customer_sheet.state == "livraison"
|
||||
-elsif @p_customer_sheet.state == "livraison" or @p_customer_sheet.state == "remboursée"
|
||||
%p=link_to "Générer la facture", generate_f_admin_p_customer_sheet_path(@p_customer_sheet), :class => "btn btn-primary"
|
||||
|
||||
|
||||
|
@ -55,5 +55,9 @@
|
||||
|
||||
|
||||
|
||||
%td
|
||||
%td.actions
|
||||
-if p_document.label == "Facture" and !@relances
|
||||
-if p_document.relative_docs.where(:label => "Avoir").count == 0
|
||||
=link_to "Créer un avoir", create_avoir_admin_p_document_path(p_document), :data => {:confirm => "Voulez-vous vraiment créer un avoir ?"}
|
||||
|
||||
|
@ -30,7 +30,13 @@
|
||||
%td
|
||||
|
||||
- if sheet_line.shiped
|
||||
Livrée
|
||||
-if sheet_line.decr
|
||||
Stocks décrémentés
|
||||
-else
|
||||
Livrée
|
||||
=link_to "Décrémenter les stocks", decrement_admin_p_sheet_line_path(sheet_line), :data => {:confirm => "Attention : les stocks seront définitivement décrémenté, à ne faire que dans le cas d'un remboursement où la marchandise a été rachetée."}
|
||||
|
||||
|
||||
-elsif sheet_line.bl
|
||||
En cours de livraison
|
||||
%br
|
||||
|
@ -58,7 +58,13 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
resources :p_sheet_lines
|
||||
resources :p_sheet_lines do
|
||||
member do
|
||||
get :decrement
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
resources :specific_maps
|
||||
resources :specific_map_items
|
||||
|
||||
@ -138,7 +144,15 @@ Rails.application.routes.draw do
|
||||
resources :p_payments
|
||||
resources :p_drivers
|
||||
resources :p_document_type
|
||||
resources :p_documents
|
||||
resources :p_documents do
|
||||
member do
|
||||
get :create_avoir
|
||||
get :detail
|
||||
end
|
||||
collection do
|
||||
get :multiple
|
||||
end
|
||||
end
|
||||
resources :p_trucks
|
||||
resources :p_product_cats
|
||||
resources :p_fournisseur_orders
|
||||
|
6
db/migrate/20190226102945_add_decr_to_p_sheet_lines.rb
Normal file
6
db/migrate/20190226102945_add_decr_to_p_sheet_lines.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class AddDecrToPSheetLines < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :p_sheet_lines, :decr, :boolean, :default => false
|
||||
#add_column :p_sheet_line_stocks, :decr, :boolean, :default => false
|
||||
end
|
||||
end
|
17
db/migrate/20190226103405_add_doc_ref_to_p_documents.rb
Normal file
17
db/migrate/20190226103405_add_doc_ref_to_p_documents.rb
Normal file
@ -0,0 +1,17 @@
|
||||
class AddDocRefToPDocuments < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :p_documents, :doc_ref_id, :integer
|
||||
add_column :p_documents, :echeance_date, :date
|
||||
add_column :p_documents, :avoir_text, :text
|
||||
add_column :p_documents, :doc_ref_number, :string
|
||||
|
||||
add_column :p_documents, :cache_fdp, :decimal, :precision => 13, :scale => 2
|
||||
|
||||
|
||||
|
||||
PDocument.all.each do |pd|
|
||||
pd.cache_fdp = PSheetLine.frais_de_port(pd.p_sheet_lines)
|
||||
pd.save
|
||||
end
|
||||
end
|
||||
end
|
9
db/migrate/20190312134008_create_p_contact_types.rb
Normal file
9
db/migrate/20190312134008_create_p_contact_types.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class CreatePContactTypes < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :p_contact_types do |t|
|
||||
t.string :name
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
10
db/migrate/20190312134046_create_p_contact_contact_types.rb
Normal file
10
db/migrate/20190312134046_create_p_contact_contact_types.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class CreatePContactContactTypes < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :p_contact_contact_types do |t|
|
||||
t.references :p_contact, index: true, foreign_key: true
|
||||
t.references :p_contact_type, index: true, foreign_key: true
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
6
db/migrate/20190312134247_add_civil_to_p_contacts.rb
Normal file
6
db/migrate/20190312134247_add_civil_to_p_contacts.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class AddCivilToPContacts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :p_contacts, :civilite, :string
|
||||
add_column :p_contacts, :firstname, :string
|
||||
end
|
||||
end
|
28
db/schema.rb
28
db/schema.rb
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20190210113008) do
|
||||
ActiveRecord::Schema.define(version: 20190312134247) do
|
||||
|
||||
create_table "admin_admin_roles", force: :cascade do |t|
|
||||
t.integer "admin_id", limit: 4
|
||||
@ -748,6 +748,22 @@ ActiveRecord::Schema.define(version: 20190210113008) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "p_contact_contact_types", force: :cascade do |t|
|
||||
t.integer "p_contact_id", limit: 4
|
||||
t.integer "p_contact_type_id", limit: 4
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "p_contact_contact_types", ["p_contact_id"], name: "index_p_contact_contact_types_on_p_contact_id", using: :btree
|
||||
add_index "p_contact_contact_types", ["p_contact_type_id"], name: "index_p_contact_contact_types_on_p_contact_type_id", using: :btree
|
||||
|
||||
create_table "p_contact_types", force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "p_contacts", force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
t.text "comment", limit: 65535
|
||||
@ -759,6 +775,8 @@ ActiveRecord::Schema.define(version: 20190210113008) do
|
||||
t.string "contactable_type", limit: 255
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "civilite", limit: 255
|
||||
t.string "firstname", limit: 255
|
||||
end
|
||||
|
||||
create_table "p_customer_cats", force: :cascade do |t|
|
||||
@ -926,6 +944,11 @@ ActiveRecord::Schema.define(version: 20190210113008) do
|
||||
t.boolean "payment_fin_de_mois", default: false
|
||||
t.integer "p_payment_type_id", limit: 4
|
||||
t.string "cust_ref", limit: 255
|
||||
t.integer "doc_ref_id", limit: 4
|
||||
t.date "echeance_date"
|
||||
t.text "avoir_text", limit: 65535
|
||||
t.string "doc_ref_number", limit: 255
|
||||
t.decimal "cache_fdp", precision: 13, scale: 2
|
||||
end
|
||||
|
||||
create_table "p_eps", force: :cascade do |t|
|
||||
@ -1174,6 +1197,7 @@ ActiveRecord::Schema.define(version: 20190210113008) do
|
||||
t.string "archived_code", limit: 255
|
||||
t.integer "archived_p_product_id", limit: 4
|
||||
t.string "cust_ref", limit: 255
|
||||
t.boolean "decr", default: false
|
||||
end
|
||||
|
||||
add_index "p_sheet_lines", ["p_product_stock_id"], name: "index_p_sheet_lines_on_p_product_stock_id", using: :btree
|
||||
@ -1585,6 +1609,8 @@ ActiveRecord::Schema.define(version: 20190210113008) do
|
||||
add_foreign_key "menu_item_langs", "image_files"
|
||||
add_foreign_key "menu_item_langs", "lang_sites"
|
||||
add_foreign_key "p_box_fdps", "p_products"
|
||||
add_foreign_key "p_contact_contact_types", "p_contact_types"
|
||||
add_foreign_key "p_contact_contact_types", "p_contacts"
|
||||
add_foreign_key "p_customer_sheets", "p_payment_types"
|
||||
add_foreign_key "p_customer_sheets", "p_price_cats"
|
||||
add_foreign_key "p_customers", "p_price_cats"
|
||||
|
9
test/fixtures/p_contact_contact_types.yml
vendored
Normal file
9
test/fixtures/p_contact_contact_types.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
p_contact_id:
|
||||
p_contact_type_id:
|
||||
|
||||
two:
|
||||
p_contact_id:
|
||||
p_contact_type_id:
|
7
test/fixtures/p_contact_types.yml
vendored
Normal file
7
test/fixtures/p_contact_types.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
name: MyString
|
||||
|
||||
two:
|
||||
name: MyString
|
7
test/models/p_contact_contact_type_test.rb
Normal file
7
test/models/p_contact_contact_type_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PContactContactTypeTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
7
test/models/p_contact_type_test.rb
Normal file
7
test/models/p_contact_type_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PContactTypeTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user