:coffeescript
  @update_p_customer_form = () ->
    if $("#p_customer_enabled").is(':checked')
      $(".disabled_raison").hide()
    else
      $(".disabled_raison").show()
      
  


=semantic_form_for [:admin, @p_customer], :remote => false, :html => {:onchange => "update_p_customer_form();"} do |form|
  =#debug @p_customer.errors.messages
  .qi_row
    .qi_pannel.qi_plain.padding
      =form.inputs do
    
        .row.qi_cancel_margins
         
          .col-sm-4
            %br
            = form.input :enabled, :label => "Client actif ?", :as => :boolean, :input_html => {:id => "p_customer_enabled"}
            
          
          .col-sm-8
            .disabled_raison{:style => ("display:none;" if @p_customer.enabled)}
              = form.input :disabled_raison, :label => "Raison du blocage :", :as => :select, :collection => ["Impayé","Litige", "N'existe plus"], :include_blank => false
              
          
            
    
    
        .row.qi_cancel_margins
         
          .col-sm-4
    
            = form.input :p_commercial_id, :label => "Commercial :", :include_blank => false, :collection => PCommercial.order(:name).all, :as => :select, :member_label => :long_name
          .col-sm-4
            = form.input :accounting_zone_id, :label => "Zone :", :collection => AccountingZone.all, :as => :select, :include_blank => false
          .col-sm-4
            =# form.input :fav, :label => "Favoris ?" 
            = form.input :p_customer_cat_id, :label => "Catégorie client", :include_blank => false, :collection => PCustomerCat.order(:name).all, :as => :select
          
        -if @p_customer.id or (@p_customer.code? and @p_customer.errors[:code])
          = form.input :code, :label => "Code client :" 
     
   
  .qi_row
    .qi_pannel.qi_plain.padding
      Adresses :  
    
      -if false
        %p.right= link_to_add_fields "Ajouter une adresse", form, :particulars 
      
      .particulars_form
        =form.semantic_fields_for :particulars do |form|
          =render :partial => "admin/particulars/form", :locals => {:form => form}
    
      
    
      
  .qi_row
    .qi_pannel.qi_plain.padding
      Contacts du client :
      %hr
    
      .p_contacts_form
        =form.semantic_fields_for :p_contacts do |form|
          =render :partial => "admin/p_contacts/form", :locals => {:form => form}
  
      %p= link_to_add_fields ic(:plus)+" Ajouter un contact au client", form, :p_contacts
    
    
 
  .qi_row
    .qi_pannel.qi_plain.padding
      %h4 Remises
      
      .row.qi_cancel_margins
        .col-sm-4
          -if form.object.p_customer_cat_id
            -mds = MarketDiscount.where(:p_customer_cat_id => form.object.p_customer_cat_id).order("p_customer_cat_id ASC, min ASC").all
          -else
            -mds = MarketDiscount.order("p_customer_cat_id ASC, min ASC").all
          
          = form.input :market_discount_id, :label => "Remise annuelle de marché :", :include_blank => true, :collection => mds, :as => :select, :member_label => :member_label
        .col-sm-4
          %br
          = form.input :discount_enrobage, :label => "Remise enrobage ?", :as => :boolean
        .col-sm-4
          %br
          = form.input :discount_comptant, :label => "Remise paiement comptant ?", :as => :boolean
    
  
  .qi_row
    .qi_pannel.qi_plain.padding
      %h4 Paiements
      .row.qi_cancel_margins
        .col-sm-4
          = form.input :comptant, :label => "Paiement comptant nécessaire ?" 

          -if false
            = form.input :acompte, :label => "Acompte nécessaire ?" 
            = form.input :acompte_percent, :label => "Pourcentage d'acompte :" 
        .col-sm-4
          = form.input :payment_delais, :label => "Délais jour de paiement :"

          -if false
            = form.input :payment_fin_de_mois, :label => "Fin de mois ?"
    
        .col-sm-4
          = form.input :p_payment_type_id, :label => "Type de paiement :", :include_blank => false, :collection => PPaymentType.order(:name).all, :as => :select, :input_html => {:id => "payment_type_id_select"}
    
      
      
  .large_actions
    .actions
      =form.submit "sauvegarder", :class => "btn btn-primary btn-ap-add"
  