diff --git a/app/models/p_contact.rb b/app/models/p_contact.rb index 28706f5..6da354d 100644 --- a/app/models/p_contact.rb +++ b/app/models/p_contact.rb @@ -5,5 +5,5 @@ class PContact < ApplicationRecord has_many :p_contact_contact_types, :dependent => :destroy has_many :p_contact_types, :through => :p_contact_contact_types - + belongs_to :p_payment_type end diff --git a/app/models/p_fournisseur.rb b/app/models/p_fournisseur.rb index b24d696..e585732 100644 --- a/app/models/p_fournisseur.rb +++ b/app/models/p_fournisseur.rb @@ -1,2 +1,81 @@ class PFournisseur < ApplicationRecord + # has_many :particulars, :as => :owner, :dependent => :destroy + has_many :p_contacts, :as => :contactable, :dependent => :destroy + + acts_as_csv_import :fields => [ + :name, + :address1, + :cp, + :city, + :country, + :email, + :tel, + :p_contact_name, + :p_contact_comment, + :p_contact_tel, + :p_contact_skype, + :p_contact_email_1, + :p_contact_email_2, + :p_contact_email_3, + :bic, + :iban, + :payment_delais, + :tva_num, + :p_payment_type + ] + + def self.custom_csv_import(list, import_csv) + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap list + # ap list.class + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap import_csv + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + # ap "*********************************************************************************************************" + + list.each do |row| + + n = self.new + # particular = Particular.new(pro: true) + contact_1 = PContact.new + contact_2 = nil + contact_3 = nil + row.each do |key, value| + + if self.type_for_attribute(key) and self.type_for_attribute(key).type == :decimal + eval "n.#{key} = value.to_s.gsub(' ', '').gsub(',', '.')" + elsif key == "p_contact_name" + contact_1.name = value + elsif key == "p_contact_comment" + contact_1.p_contact_types << PContactType.find_or_create_by(name: value) + elsif key == "p_contact_tel" + contact_1.tel = value + elsif key == "p_contact_skype" + contact_1.skype = value + elsif key == "p_contact_email_1" + contact_1.email = value + elsif key == "p_contact_email_2" + contact_2 = PContact.new(email: value) + elsif key == "p_contact_email_3" + contact_3 = PContact.new(email: value) + elsif key == "p_payment_type" + n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id + else + eval "n.#{key} = value" + end + + end + # particular.organisation = self.name + n.save + n.p_contacts << contact_1 if (contact_1.name || contact_1.tel || contact_1.skype || contact_1.email) + n.p_contacts << contact_2 if contact_2 + n.p_contacts << contact_3 if contact_3 + # import_csv.import_csv_elements << ImportCsvElement.new(:element => n) + end + end end diff --git a/app/models/p_payment_type.rb b/app/models/p_payment_type.rb index a6cfaa8..fbd2f02 100644 --- a/app/models/p_payment_type.rb +++ b/app/models/p_payment_type.rb @@ -1,7 +1,8 @@ class PPaymentType < ApplicationRecord belongs_to :p_bank_account has_many :p_payments - + has_many :p_fournisseurs + after_save do if self.p_bank_account self.p_payments.where(:remise => false).update_all(:p_bank_account_id => self.p_bank_account_id) diff --git a/app/views/admin/import_csvs/_form.html.haml b/app/views/admin/import_csvs/_form.html.haml index f115a9c..ede671b 100644 --- a/app/views/admin/import_csvs/_form.html.haml +++ b/app/views/admin/import_csvs/_form.html.haml @@ -6,7 +6,7 @@ = f.input :name, :label => "Nom de l'import :" = f.input :file, :label => "file :" - = f.input :table_name, :label => "Table :" , :as => :select, :collection => ["order_hist_lines"] + = f.input :table_name, :label => "Type d'import :" , :as => :select, :collection => [["Base fournisseurs", "p_fournisseur"], ["Mise à jour catalogue prix","price_document"]] -if f.object.id %table.import_csv_champs_form @@ -23,4 +23,4 @@ .actions=f.submit "sauvegarder", :class => "btn btn-primary" - \ No newline at end of file + diff --git a/app/views/admin/import_csvs/index.html.haml b/app/views/admin/import_csvs/index.html.haml index 78aa6d9..54de32a 100644 --- a/app/views/admin/import_csvs/index.html.haml +++ b/app/views/admin/import_csvs/index.html.haml @@ -1,6 +1,6 @@ .qi_header .right= link_to ic(:plus)+' Ajouter', new_admin_import_csv_path(), :class => "btn btn-primary btn-ap-add", :remote => true - %h1 + %h1 Import xls @@ -12,4 +12,4 @@ =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @import_csvs} -=debug OrderHistLine.new.class.type_for_attribute("ff") \ No newline at end of file +=debug OrderHistLine.new.class.type_for_attribute("ff") diff --git a/db/migrate/20211004161651_add_skype_to_p_contacts.rb b/db/migrate/20211004161651_add_skype_to_p_contacts.rb new file mode 100644 index 0000000..2560a30 --- /dev/null +++ b/db/migrate/20211004161651_add_skype_to_p_contacts.rb @@ -0,0 +1,5 @@ +class AddSkypeToPContacts < ActiveRecord::Migration[6.0] + def change + add_column :p_contacts, :skype, :string + end +end diff --git a/db/migrate/20211004161753_add_details_to_p_fournisseurs.rb b/db/migrate/20211004161753_add_details_to_p_fournisseurs.rb new file mode 100644 index 0000000..345ce24 --- /dev/null +++ b/db/migrate/20211004161753_add_details_to_p_fournisseurs.rb @@ -0,0 +1,9 @@ +class AddDetailsToPFournisseurs < ActiveRecord::Migration[6.0] + def change + add_column :p_fournisseurs, :payment_delais, :integer + add_column :p_fournisseurs, :tva_num, :string + add_column :p_fournisseurs, :p_payment_type_id, :integer + add_column :p_fournisseurs, :iban, :string + add_column :p_fournisseurs, :bic, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 5baae52..dc64e8d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_09_17_124338) do +ActiveRecord::Schema.define(version: 2021_10_04_161753) do create_table "accounting_zones", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.string "name" @@ -1164,6 +1164,7 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do t.string "contactable_type" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "skype" t.index ["contactable_id"], name: "index_p_contacts_on_contactable_id" end @@ -1463,6 +1464,11 @@ ActiveRecord::Schema.define(version: 2021_09_17_124338) do t.string "compta_account" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.integer "payment_delais" + t.string "tva_num" + t.integer "p_payment_type_id" + t.string "iban" + t.string "bic" end create_table "p_grades", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| diff --git a/lib/acts_as_csv_import/hook.rb b/lib/acts_as_csv_import/hook.rb index ab6502b..e140daf 100644 --- a/lib/acts_as_csv_import/hook.rb +++ b/lib/acts_as_csv_import/hook.rb @@ -9,7 +9,7 @@ module ActsAsCsvImport::Hook end def self.import_csv(list, import_csv) - puts self.instance_methods + # puts self.instance_methods if self.methods.include?(:custom_csv_import) custom_csv_import(list, import_csv)