diff --git a/app/controllers/admin/p_documents_controller.rb b/app/controllers/admin/p_documents_controller.rb
index 419d21e..9b4167f 100755
--- a/app/controllers/admin/p_documents_controller.rb
+++ b/app/controllers/admin/p_documents_controller.rb
@@ -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
diff --git a/app/models/p_contact.rb b/app/models/p_contact.rb
index 0b1dc7e..a58cdb1 100644
--- a/app/models/p_contact.rb
+++ b/app/models/p_contact.rb
@@ -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
diff --git a/app/models/p_contact_contact_type.rb b/app/models/p_contact_contact_type.rb
new file mode 100644
index 0000000..82da0a8
--- /dev/null
+++ b/app/models/p_contact_contact_type.rb
@@ -0,0 +1,4 @@
+class PContactContactType < ActiveRecord::Base
+ belongs_to :p_contact
+ belongs_to :p_contact_type
+end
diff --git a/app/models/p_contact_type.rb b/app/models/p_contact_type.rb
new file mode 100644
index 0000000..082f9c7
--- /dev/null
+++ b/app/models/p_contact_type.rb
@@ -0,0 +1,2 @@
+class PContactType < ActiveRecord::Base
+end
diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb
index dafa3bc..1a89349 100644
--- a/app/models/p_customer_sheet.rb
+++ b/app/models/p_customer_sheet.rb
@@ -223,6 +223,8 @@ class PCustomerSheet < ActiveRecord::Base
'Annulée'
elsif self.state == "refusée"
'Refusée'
+ elsif self.state == "remboursée"
+ 'Remboursée'
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"]
diff --git a/app/models/p_document.rb b/app/models/p_document.rb
index ff080de..f1e1918 100644
--- a/app/models/p_document.rb
+++ b/app/models/p_document.rb
@@ -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
diff --git a/app/models/p_sheet_line.rb b/app/models/p_sheet_line.rb
index 3122917..9d88f30 100644
--- a/app/models/p_sheet_line.rb
+++ b/app/models/p_sheet_line.rb
@@ -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
diff --git a/app/views/admin/p_contacts/_form.html.haml b/app/views/admin/p_contacts/_form.html.haml
index 2d28d4a..78a7abc 100755
--- a/app/views/admin/p_contacts/_form.html.haml
+++ b/app/views/admin/p_contacts/_form.html.haml
@@ -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
\ No newline at end of file
+ =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;
+ }
+ }
+
+ }
\ No newline at end of file
diff --git a/app/views/admin/p_customer_sheets/show.html.haml b/app/views/admin/p_customer_sheets/show.html.haml
index 8e894fc..599342d 100644
--- a/app/views/admin/p_customer_sheets/show.html.haml
+++ b/app/views/admin/p_customer_sheets/show.html.haml
@@ -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"
diff --git a/app/views/admin/p_documents/_p_document.html.haml b/app/views/admin/p_documents/_p_document.html.haml
index 6f59dd7..7ebb7bc 100644
--- a/app/views/admin/p_documents/_p_document.html.haml
+++ b/app/views/admin/p_documents/_p_document.html.haml
@@ -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 ?"}
+
\ No newline at end of file
diff --git a/app/views/admin/p_sheet_lines/_p_sheet_lines.html.haml b/app/views/admin/p_sheet_lines/_p_sheet_lines.html.haml
index 95192e3..6ef8feb 100644
--- a/app/views/admin/p_sheet_lines/_p_sheet_lines.html.haml
+++ b/app/views/admin/p_sheet_lines/_p_sheet_lines.html.haml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index ad883e9..19a21a2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/db/migrate/20190226102945_add_decr_to_p_sheet_lines.rb b/db/migrate/20190226102945_add_decr_to_p_sheet_lines.rb
new file mode 100644
index 0000000..5b83afa
--- /dev/null
+++ b/db/migrate/20190226102945_add_decr_to_p_sheet_lines.rb
@@ -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
diff --git a/db/migrate/20190226103405_add_doc_ref_to_p_documents.rb b/db/migrate/20190226103405_add_doc_ref_to_p_documents.rb
new file mode 100644
index 0000000..05ba644
--- /dev/null
+++ b/db/migrate/20190226103405_add_doc_ref_to_p_documents.rb
@@ -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
diff --git a/db/migrate/20190312134008_create_p_contact_types.rb b/db/migrate/20190312134008_create_p_contact_types.rb
new file mode 100644
index 0000000..37c03bc
--- /dev/null
+++ b/db/migrate/20190312134008_create_p_contact_types.rb
@@ -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
diff --git a/db/migrate/20190312134046_create_p_contact_contact_types.rb b/db/migrate/20190312134046_create_p_contact_contact_types.rb
new file mode 100644
index 0000000..8c49313
--- /dev/null
+++ b/db/migrate/20190312134046_create_p_contact_contact_types.rb
@@ -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
diff --git a/db/migrate/20190312134247_add_civil_to_p_contacts.rb b/db/migrate/20190312134247_add_civil_to_p_contacts.rb
new file mode 100644
index 0000000..52edffb
--- /dev/null
+++ b/db/migrate/20190312134247_add_civil_to_p_contacts.rb
@@ -0,0 +1,6 @@
+class AddCivilToPContacts < ActiveRecord::Migration
+ def change
+ add_column :p_contacts, :civilite, :string
+ add_column :p_contacts, :firstname, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c13c018..8d6d12b 100644
--- a/db/schema.rb
+++ b/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"
diff --git a/test/fixtures/p_contact_contact_types.yml b/test/fixtures/p_contact_contact_types.yml
new file mode 100644
index 0000000..5472ab8
--- /dev/null
+++ b/test/fixtures/p_contact_contact_types.yml
@@ -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:
diff --git a/test/fixtures/p_contact_types.yml b/test/fixtures/p_contact_types.yml
new file mode 100644
index 0000000..56066c6
--- /dev/null
+++ b/test/fixtures/p_contact_types.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ name: MyString
+
+two:
+ name: MyString
diff --git a/test/models/p_contact_contact_type_test.rb b/test/models/p_contact_contact_type_test.rb
new file mode 100644
index 0000000..0fec6e6
--- /dev/null
+++ b/test/models/p_contact_contact_type_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PContactContactTypeTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/models/p_contact_type_test.rb b/test/models/p_contact_type_test.rb
new file mode 100644
index 0000000..e75b69b
--- /dev/null
+++ b/test/models/p_contact_type_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PContactTypeTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end