import p_customer

This commit is contained in:
Barnabé 2021-10-13 18:14:54 +02:00
parent cbb5d65098
commit 8cefeec6b3
2 changed files with 424 additions and 0 deletions

View File

@ -1,2 +1,3 @@
class PBank < ApplicationRecord class PBank < ApplicationRecord
has_many :particulars, :as => :owner, :dependent => :destroy
end end

View File

@ -256,6 +256,7 @@ class PCustomer < ApplicationRecord
end end
def solde_avoir_and_bills(date = Date.today) def solde_avoir_and_bills(date = Date.today)
raise # p_document_id à remplacer
self.p_documents.where(:p_document_type_id => [4,7]).where("created_at < ?", date.to_time.end_of_day).sum(:cache_total_ttc) self.p_documents.where(:p_document_type_id => [4,7]).where("created_at < ?", date.to_time.end_of_day).sum(:cache_total_ttc)
end end
@ -480,5 +481,427 @@ class PCustomer < ApplicationRecord
end while PCustomer.exists?(column => self[column]) end while PCustomer.exists?(column => self[column])
end end
acts_as_csv_import :fields => [
:code,
:societe_raison_sociale,
:nom_enseigne,
:adresse_facturation_1,
:adresse_livraison_2,
:adresse_3,
:cp,
:cp2,
:ville_1,
:ville_2,
:pays,
:societe_livraison,
:forme_juridique,
:famille_client,
:facturer_ttc,
:mode_reglement,
:libelle_mode_reglement,
:telephone_1,
:telephone_2,
:fax,
:risque,
:bloque,
:credit_accorde,
:mode_tva,
:nii,
:nom_banque,
:adresse_banque_1,
:adresse_banque_2,
:adresse_banque_3,
:code_banque,
:ville_banque,
:pays_banque,
:code_banque,
:code_guichet,
:numero_compte,
:cle_rib,
:compte_comptable,
:analytique,
:taux_remise,
:observation,
:export_compta,
:releve_compte,
:email,
:url,
:siret,
:representant,
:nom_representant,
:encour_initial,
:credit_disponible,
:code_tarif,
:telephone_livraison,
:portable_livraison,
:fax_livraison,
:encours_courant,
:encours,
:client_divers,
:contacts_client,
:date_creation,
:code_iban,
:code_bic,
:nom_contact,
:societe_contact,
:titre_contact,
:fonction_contact,
:telephone_contact,
:portable_contact,
:email_contact
]
def self.custom_csv_import(list, import_csv)
#OK Code AUTO :code OK :code
#OK Société - Raison Sociale :particular.organisation OK :societe_raison_sociale
#OK Nom enseigne :particular.com_name OK :nom_enseigne
#OK Adresse facturation 1 :particular.address_1 OK :adresse_facturation_1
#OK Adresse Livraison 2 :particular.address_2 OK :adresse_livraison_2
#OK Adresse 3 :particular.address_3 OK :adresse_3
#OK Code Postal 1 :particular.cp OK :cp
#OK Code Postal 2 VIDE OK :cp2
#OK Ville 1 :particular_city OK :ville_1
#OK Ville 2 VIDE OK :ville_2
#OK Pays :particular.country OK :pays
#OK Société Livraison :particular.address_4 OK :societe_livraison
#OK Forme juridique livraison :particular.address_5 OK :forme_juridique
#OK Famille Client VIDE OK :famille_client
#OK Facturer en TTC VIDE OK :facturer_ttc
#OK Mode Règlement :p_payment_type OK :mode_reglement
#OK Libellé Mode Règlement :payment_delais OK :libelle_mode_reglement
#OK Téléphone 1 :particular.tel OK :telephone_1
#OK Téléphone 2 :particular.tel2 OK :telephone_2
#OK Fax :particular.fax OK :fax
#OK Risque VIDE OK :risque
#OK Bloqué VIDE OK :bloque
#OK Crédit accordé VIDE OK :credit_accorde
#OK Mode TVA VIDE OK :mode_tva
#OK N.I.I. VIDE OK :nii
#OK Nom Banque :p_bank.name OK :nom_banque
#OK Adresse 1 Banque :p_bank.particular.address_1 OK :adresse_banque_1
#OK Adresse 2 Banque :p_bank.particular.address_2 OK :adresse_banque_2
#OK Adresse 3 Banque VIDE OK :adresse_banque_3
#OK Code Postal Banque :p_bank.particular.cp OK :code_banque
#OK Ville Banque :p_bank.particular.ville OK :ville_banque
#OK Pays Banque :p_bank.particular.pays OK :pays_banque
#OK Code Banque INUTILE OK :code_banque
#OK Code Guichet INUTILE OK :code_guichet
#OK Numéro Compte INUTILE OK :numero_compte
#OK Clé RIB INUTILE OK :cle_rib
# Compte Comptable ??? ?? :compte_comptable
#OK Analytique VIDE OK :analytique
#OK Taux Remise VIDE OK :taux_remise
#OK Observations AUTO :p_customer_sheet_note OK :observation
#OK Export Compta VIDE OK :export_compta
# Relevé Compte Bboolean à ajouter dans la base ?? :releve_compte
#OK E-mail AUTO :email OK :email
#OK URL VIDE OK :url
#OK SIRET AUTO :siret OK :siret
#OK Représentant :p_commercial_code OK :representant
#OK Nom Représentant :p_commercial_firstname OK :nom_representant
# Encours initial ??? ?? :encour_initial
# Crédit Disponible ??? ?? :credit_disponible
#OK Code Tarif VIDE OK :code_tarif
#OK Téléphone Livraison :particular.send_tel OK :telephone_livraison
#OK Portable Livraison :particular.send_tel2 OK :portable_livraison
#OK Fax Livraison :particular.send_fax OK :fax_livraison
# Encours courant ??? ?? :encours_courant
# encours_courant ??? ?? :encours
# Client divers ??? ?? :client_divers
#OK Contacts client INUTILE OK :contacts_client
#OK Date de création INUTILE OK :date_creation
#OK Code IBAN :p_customer_ribs.iban OK :code_iban
#OK Code BIC :p_customer_ribs.bic OK :code_bic
#OK Nom du contact :p_contact_name OK :nom_contact
#OK Société du contact VIDE OK :societe_contact
#OK Titre du contact :p_contact.civilite OK :titre_contact
#OK Fonction du contact :p_contact.comment OK :fonction_contact
#OK Téléphone du contact :p_contact.tel OK :telephone_contact
#OK Portable du contact :p_contact.tel2 OK :portable_contact
#OK E-mail du contact :p_contact.email OK :email_contact
# ap "*********************************************************************************************************"
# ap "*********************************************************************************************************"
# ap "*********************************************************************************************************"
# ap list
# ap list.class
# ap "*********************************************************************************************************"
# ap "*********************************************************************************************************"
# ap "*********************************************************************************************************"
# ap import_csv
# ap "*********************************************************************************************************"
# ap "*********************************************************************************************************"
# ap "*********************************************************************************************************"
list.each do |row|
n = self.new(imported: true, p_customer_cat: PCustomerCat.find_by_name("Professionnel"))
# particular = Particular.new(pro: true)
particular_bill = Particular.new
bank = bic = iban = p_commercial = particular_send = send_tel = send_tel2 = send_fax = send_address_2 = p_commercial_code = p_commercial_firstname = contact_2 = nil
bank_particular = Particular.new
contact = PContact.new
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(',', '.')"
else
case key
when "societe_raison_sociale"
particular_bill.organisation = value
when "nom_enseigne"
particular_bill.com_name = value
when "adresse_facturation_1"
particular_bill.address_1 = value
when "adresse_livraison_2"
send_address_2 = value
when "adresse_3"
particular_bill.address_3 = value
when "cp"
particular_bill.cp = value
when "ville_1"
particular_bill.city = value
when "pays"
particular_bill.country = value
when "societe_livraison"
particular_bill.address_4 = value
when "forme_juridique"
particular_bill.address_5 = value
when "telephone_1"
particular_bill.tel = value
when "telephone_2"
particular_bill.tel2 = value
when "fax"
particular_bill.fax = value
when "mode_reglement"
next if value.nil?
if value == "VIR" || "VIR COM" || "VIR 60 J NET" || "VIR 30 J NET"
n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Virement").id
elsif value == "TRAITE"
n.p_payment_type_id = PPaymentType.find_or_create_by(name: "Traite").id
else
n.p_payment_type_id = PPaymentType.find_or_create_by(name: value).id
end
when "libelle_mode_reglement"
case value
when "Virement à la commande"
n.payment_delais = 0
when "Chèque à la commande"
n.payment_delais = 0
when "Chèque à réception"
n.payment_delais = 0
when "30 JOURS FIN DE MOIS"
n.payment_delais = 30
when "VIR 60J NET DATE RELEVE"
n.payment_delais = 60
when "TRAITE A 60 JOURS FIN DE MOIS"
n.payment_delais = 60
when "Mensuel - 30j fin de mois du dépôt"
n.payment_delais = 30
else
n.payment_delais = value
end
when "nom_banque"
next if value.nil?
bank = PBank.find_or_create_by(name: value)
when "adresse_banque_1"
bank_particular.address_1 = value
when "adresse_banque_2"
bank_particular.address_2 = value
when "code_banque"
bank_particular.cp = value
when "ville_banque"
bank_particular.city = value
when "pays_banque"
bank_particular.country = value
when "telephone_livraison"
send_tel = value
when "portable_livraison"
send_tel2 = value
when "fax_livraison"
send_fax = value
when "representant"
p_commercial_code = value
when "nom_representant"
p_commercial_firstname = value
when "code_iban"
iban = value
when "code_bic"
bic = value
when "nom_contact"
contact.name = value
when "titre_contact"
particular_bill.civilite = value
when "fonction_contact"
next if value.nil?
contact.p_contact_types << PContactType.find_or_create_by(name: value)
when "telephone_contact"
contact.tel = value
when "portable_contact"
next if value.nil?
if contact.tel.nil?
contact.tel = value
else
contact_2 = PContact.new(tel: value)
end
when "email_contact"
contact.email = value
when "observation"
n.p_customer_sheet_note = value
# champs vides ou inutiles :
when "cp2"
when "ville_2"
when "famille_client"
when "facturer_ttc"
when "risque"
when "bloque"
when "credit_accorde"
when "mode_tva"
when "nii"
when "adresse_banque_3"
when "code_banque"
when "code_guichet"
when "numero_compte"
when "cle_rib"
when "analytique"
when "taux_remise"
when "export_compta"
when "url"
when "code_tarif"
when "contacts_client"
when "date_creation"
when "societe_contact"
# Champs ???
when "compte_comptable"
when "encour_initial"
when "credit_disponible"
when "releve_compte"
when "encours_courant"
when "releve_compte"
when "encours"
when "client_divers"
else
eval "n.#{key} = value"
end
end
end
n.particulars << particular_bill
n.save
if bank
bank.bic = bic
bank.particulars << bank_particular if bank_particular.address_1
bank.save
import_csv.import_csv_elements << ImportCsvElement.new(:element => bank)
end
if bic || iban
rib = PCustomerRib.create(bic: bic, iban: iban)
rib.bank = bank.name if bank
account = PBankAccount.create(bic: bic, iban: iban, p_bank: bank, p_customer: n)
n.p_customer_ribs << rib
import_csv.import_csv_elements << ImportCsvElement.new(:element => rib)
import_csv.import_csv_elements << ImportCsvElement.new(:element => account)
end
if p_commercial_code || p_commercial_firstname
p_commercial = PCommercial.find_or_create_by(code: p_commercial_code, firstname: p_commercial_firstname)
n.p_commercial = p_commercial
end
if send_tel || send_tel2 || send_fax || send_address_2
particular_send = Particular.new
particular_send.tel = send_tel if send_tel
particular_send.tel2 = send_tel2 if send_tel2
particular_send.fax = send_fax if send_fax
n.particulars << particular_send
n.particular_send_id = particular_send.id
end
n.p_contacts << contact if (contact.name || contact.tel || contact.email)
n.p_contacts << contact_2 if contact_2
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap n
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ contact §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap contact
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.contacts §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap n.p_contacts
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.particulars §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap n.particulars
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.p_customer_ribs §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap n.p_customer_ribs
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ n.p_commercial §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap n.p_commercial
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
# ap "§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§"
import_csv.import_csv_elements << ImportCsvElement.new(:element => n)
end
end
end end