: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

        -if current_admin.has_permission?("customers-activer-desactiver")
          .row.qi_cancel_margins

            .col-sm-4

              = 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", "Pas encore vérifié"], :include_blank => false





        .row.qi_cancel_margins

          -if false
            -if !current_admin.p_commercial
              .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 :"


        .row.qi_cancel_margins
          .col-sm-6
            = form.input :siret, :label => "Siret :"
          .col-sm-6
            = form.input :siren, :label => "Siren :"


        .row.qi_cancel_margins
          .col-sm-6
            = form.input :particular_bill_id, :collection => form.object.particulars.all, :as => :select, :member_label => :address_line, :include_blank => true, :label => "Adresse de facturation :"
          .col-sm-6
            = form.input :particular_send_id, :collection => form.object.particulars.all, :as => :select, :member_label => :address_line, :include_blank => true, :label => "Adresse de livraison :"


        =form.input :code, :label => "Code client"
        
        
  -if !@p_customer.id
    .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



  -if current_admin.has_permission?("customers-payments") or (current_admin.p_commercial and @p_customer and !@p_customer.id)
    .qi_row
      .qi_pannel.qi_plain.padding
        %h4 Paiements
        .row.qi_cancel_margins
          .col-sm-4
            = form.input :comptant, :label => "Paiement comptant ?"

            -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"}

    .qi_row
      .qi_pannel.qi_plain.padding
        %h4 RIBs
        .p_customer_ribs_form
          =form.semantic_fields_for :p_customer_ribs, form.object.p_customer_ribs.where(:archived => false) do |form|
            =render :partial => "admin/p_customer_ribs/form", :locals => {:form => form}

        %p= link_to_add_fields "Ajouter un RIB", form, :p_customer_ribs



  .qi_row
    .qi_pannel.qi_plain.padding
      =form.input :p_customer_sheet_note, :label => "Notes s'affichant dans les demandes de commande :"




  .large_actions
    .actions
      =form.submit "sauvegarder", :class => "btn btn-primary btn-ap-add"
