
.qi_header
  %h2 Importation catégories client

-@import= true

-i = 0
-@csv.each do |csv|
  -i += 1
  -logger.error "ligne : "+i.to_s
  -logger.error "code client : "+csv["CODE CLIENT"].to_s
  -if csv["CODE CLIENT"].to_s != "" and p_customer = PCustomer.where(:code => csv["CODE CLIENT"], :i_cat => false).first
    -logger.error "IMPORT CLIENT "+csv["CODE CLIENT"].to_s
  
    -if csv["CATEGORIE"].to_s != "" and p_c_c = PCustomerCat.where(:name => csv["CATEGORIE"].to_s).first
    -else
      -p_c_c = PCustomerCat.create(:name => csv["CATEGORIE"].to_s)
    
    -p_customer.p_customer_cat = p_c_c
    
    -p_customer.i_cat = true
    
    -organisation = ""
    -name = ""
    -prenom = ""
    
    -if csv["CATEGORIE"] != "Particulier"
      -organisation = csv["NOM CLIENT"]
    -else
      -name = csv["NOM CLIENT"]
      
    -if csv["PRENOM CLIENT"].to_s != "" and csv["PRENOM CLIENT"].to_s != " "
      -prenom = csv["PRENOM CLIENT"]
    -p_customer.particulars.update_all(:name => name, :organisation => organisation, :firstname => prenom, :civilite => csv["CIVILITE"])
    

    -if csv["EMAIL"].to_s != "" and csv["EMAIL"].to_s != " " and p_customer.p_contacts.where(:email => csv["EMAIL"]).count == 0
      
      -p_customer.p_contacts << PContact.new(:email => csv["EMAIL"]) 
    
    
    -p_customer.save
      
      
      
    
  -else
    -logger.error "Déjà importé"+csv["CODE CLIENT"].to_s
  -if i == 100
    -#break


