From f414b3840d500bced4fc976c8f4c533dd10eef5d Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Mon, 4 Nov 2019 00:03:58 +0100 Subject: [PATCH] suite --- app/models/contact.rb | 77 +++++++++++++++++-- app/models/contact_product.rb | 4 + app/views/admin/contacts/show.html.haml | 4 +- app/views/admin/d_products/_form.html.haml | 2 + app/views/public/contacts/_form.html.haml | 6 +- .../question_mailer/send_contact.html.haml | 31 +++++++- ...103211505_add_stuff_to_contact_products.rb | 6 ++ .../20191103211533_add_stuff_to_d_products.rb | 5 ++ db/schema.rb | 17 ++-- 9 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20191103211505_add_stuff_to_contact_products.rb create mode 100644 db/migrate/20191103211533_add_stuff_to_d_products.rb diff --git a/app/models/contact.rb b/app/models/contact.rb index cce373d..b22fbe9 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -19,6 +19,56 @@ class Contact < ActiveRecord::Base accepts_nested_attributes_for :contact_products + + def devis_content + r = "" + if self.contact_products.count > 0 + r+= "" + r+= "" + r+= " + + + + + + + " + + r+= "" + + self.contact_products.all.each do |cp| + r+= "" + + r+= "" + r+= "" + r+= "" + r+= "" + r+= "" + r+= "" + + r+= "" + + end + + r+= "
CodeProduitConditionnementQuantitéUnité
" + r+= ActionController::Base.helpers.image_tag("https://payreenergies.fr/"+cp.d_product.icon.file.url, :style => "height:80px;").to_s + r+= "" + r+=cp.code.to_s + r+= "" + r+=cp.d_product.name.to_s + r+= "" + r+=cp.ship_type.to_s + r+= "" + r+=cp.qte.to_s + r+= "" + r+=cp.d_product.unit.to_s + r+= "
" + + end + + return r + end + def email_needed? true if self.email? end @@ -28,9 +78,9 @@ class Contact < ActiveRecord::Base end before_validation do - if (true or ((raison_id == 4 )) and !self.email? and !self.phone?) - errors.add(:email, "Vous devez indiquer votre numéro de téléphone et/ou votre email") - errors.add(:phone, "Vous devez indiquer votre numéro de téléphone et/ou votre email") + if (true or ((raison_id == 4 )) and !self.phone?) + #errors.add(:email, "Vous devez indiquer votre numéro de téléphone et/ou votre email") + errors.add(:phone, "Vous devez indiquer votre numéro de téléphone") end @@ -52,14 +102,24 @@ class Contact < ActiveRecord::Base :firstname => self.firstname, :corporate => self.corporate, - + + :address => self.address, + + :address2 => self.address2, + + :cp => self.cp, + + :city => self.city, + :email => self.email, :phone => self.phone, :message => self.message, - :provenance_id => self.provenance_id + :provenance_id => self.provenance_id, + + :devis_content => self.devis_content } @@ -78,10 +138,15 @@ class Contact < ActiveRecord::Base Curl::PostField.content(:name, @params[:name]), Curl::PostField.content(:firstname, @params[:firstname]), Curl::PostField.content(:corporate, @params[:corporate]), + Curl::PostField.content(:address, @params[:address]), + Curl::PostField.content(:address2, @params[:address2]), + Curl::PostField.content(:cp, @params[:cp]), + Curl::PostField.content(:city, @params[:city]), Curl::PostField.content(:email, @params[:email]), Curl::PostField.content(:phone, @params[:phone]), Curl::PostField.content(:message, @params[:message]), - Curl::PostField.content(:provenance_id, @params[:provenance_id]) + Curl::PostField.content(:provenance_id, @params[:provenance_id]), + Curl::PostField.content(:devis_content, @params[:devis_content]) ) diff --git a/app/models/contact_product.rb b/app/models/contact_product.rb index 99593bd..8ea4646 100644 --- a/app/models/contact_product.rb +++ b/app/models/contact_product.rb @@ -3,4 +3,8 @@ class ContactProduct < ActiveRecord::Base belongs_to :d_product validates :qte, :presence => true + + before_validation do + self.code = self.d_product.code if self.d_product and !self.code + end end diff --git a/app/views/admin/contacts/show.html.haml b/app/views/admin/contacts/show.html.haml index 4b31017..7519402 100644 --- a/app/views/admin/contacts/show.html.haml +++ b/app/views/admin/contacts/show.html.haml @@ -46,9 +46,11 @@ %br %br %br + + =raw @contact.devis_content %h2 Interactions - + #contact_actions =render @contact_actions diff --git a/app/views/admin/d_products/_form.html.haml b/app/views/admin/d_products/_form.html.haml index 091e51b..7d69713 100644 --- a/app/views/admin/d_products/_form.html.haml +++ b/app/views/admin/d_products/_form.html.haml @@ -6,6 +6,8 @@ = form.input :icon_id, :label => "Icone :" , :as => :qi_image_select + =form.input :code, :label => "Code :" + =form.input :name, :label => "Nom :" =form.input :description, :label => "Description :" diff --git a/app/views/public/contacts/_form.html.haml b/app/views/public/contacts/_form.html.haml index fb2b78b..80df487 100755 --- a/app/views/public/contacts/_form.html.haml +++ b/app/views/public/contacts/_form.html.haml @@ -18,11 +18,15 @@ %td =f.hidden_field :d_product_id =image_tag f.object.d_product.icon.file.url + %td =f.label :qte, "Quantité souhaitée (#{f.object.d_product.unit}) :" %td =f.input :qte, :label => false -p_ids << f.object.d_product_id + %td + -if f.object.d_product_id == 7 + =f.select :ship_type, ["En vrac","En sacs"] %td =link_to "supprimer ce produit", public_contact_product_path(:id => f.object.d_product_id), :method => :delete @@ -66,7 +70,7 @@ -if @contact.raison_id == 4 %tr %td{:colspan => 2} - =f.input :address, :label => false, :placeholder => "Adresse*" + =f.input :address, :label => false, :placeholder => "Adresse" %tr %td{:colspan => 2} =f.input :address2, :label => false, :placeholder => "Adresse (suite)" diff --git a/app/views/question_mailer/send_contact.html.haml b/app/views/question_mailer/send_contact.html.haml index 9b81002..69420a0 100755 --- a/app/views/question_mailer/send_contact.html.haml +++ b/app/views/question_mailer/send_contact.html.haml @@ -6,8 +6,8 @@ %table %tr - %td Civilité - %td=@contact.civilite + %td Organisation + %td=@contact.corporate %tr %td Nom %td=@contact.name @@ -17,6 +17,9 @@ %tr %td Adresse %td=@contact.address + %tr + %td Adresse + %td=@contact.address2 %tr %td Code postal %td=@contact.cp @@ -46,4 +49,26 @@ %hr =simple_format @contact.message %hr - +-if @contact.contact_products.count > 0 + %table + %tr + %td + %td Code + %td Produit + %td Conditionnement + %td Quantité + %td Unité + -@contact.contact_products.all.each do |cp| + %tr + %td + =image_tag "https://payreenergies.fr/"+cp.d_product.icon.file.url, :style => "height:80px;" + %td + =cp.code + %td + =cp.d_product.name + %td + =cp.ship_type + %td + =cp.qte + %td + =cp.d_product.unit diff --git a/db/migrate/20191103211505_add_stuff_to_contact_products.rb b/db/migrate/20191103211505_add_stuff_to_contact_products.rb new file mode 100644 index 0000000..234eae9 --- /dev/null +++ b/db/migrate/20191103211505_add_stuff_to_contact_products.rb @@ -0,0 +1,6 @@ +class AddStuffToContactProducts < ActiveRecord::Migration + def change + add_column :contact_products, :code, :string + add_column :contact_products, :ship_type, :string + end +end diff --git a/db/migrate/20191103211533_add_stuff_to_d_products.rb b/db/migrate/20191103211533_add_stuff_to_d_products.rb new file mode 100644 index 0000000..d3b724a --- /dev/null +++ b/db/migrate/20191103211533_add_stuff_to_d_products.rb @@ -0,0 +1,5 @@ +class AddStuffToDProducts < ActiveRecord::Migration + def change + add_column :d_products, :code, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index fda7fea..0d8d6ea 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: 20190325230219) do +ActiveRecord::Schema.define(version: 20191103211533) do create_table "admin_admin_roles", force: :cascade do |t| t.integer "admin_id", limit: 4 @@ -251,12 +251,14 @@ ActiveRecord::Schema.define(version: 20190325230219) do t.integer "contact_id", limit: 4 t.integer "d_product_id", limit: 4 t.integer "qte", limit: 4 - t.decimal "price_ht", precision: 10 - t.decimal "price_ttc", precision: 10 - t.decimal "price_tot_ht", precision: 10 - t.decimal "price_tot_ttc", precision: 10 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.decimal "price_ht", precision: 10 + t.decimal "price_ttc", precision: 10 + t.decimal "price_tot_ht", precision: 10 + t.decimal "price_tot_ttc", precision: 10 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "code", limit: 255 + t.string "ship_type", limit: 255 end add_index "contact_products", ["contact_id"], name: "index_contact_products_on_contact_id", using: :btree @@ -308,6 +310,7 @@ ActiveRecord::Schema.define(version: 20190325230219) do t.datetime "updated_at", null: false t.boolean "orderable", default: true t.string "unit", limit: 255, default: "L" + t.string "code", limit: 255 end create_table "data_file_categories", force: :cascade do |t|