

.qi_row
  .qi_pannel.qi_plain.padding.p_customer_fin
    %p
      %strong Infos client
    .row
      .columns.span_6
        
            
            
        %table.table
          %tr
            %th CA HT :
            %td.tdr=number_to_currency p_customer.sheets_total_ht
          %tr
            %th Encours max assuré :
            %td.tdr=number_to_currency p_customer.encours_assure

          %tr
            %th Encours assuré restant :
            %td.tdr=number_to_currency p_customer.encours_assure_restant

          %tr  
            %th Encours :
            %td.tdr=number_to_currency p_customer.encours_ttc

          %tr  
            %th Encours prenant en compte les non-encaissés :
            %td.tdr=number_to_currency p_customer.th_r_encours_ttc
      
      .columns.span_6

        %table.table{:style => "margin-left:5%;width:95%"}
          %tr
            %th Commandes finalisées :
            %td.tdr
              =p_customer.nbr_orders.count
            
            %td.tdr
              ="(#{number_to_currency(p_customer.nbr_orders.sum(:a_ok_total))})"
          -if  p_customer.nbr_orders.order("created_at DESC").first
            %tr
              %th Dernière commande finalisée :
              %td.tdr
                =l p_customer.nbr_orders.order("created_at DESC").first.created_at, :format => :date
              %td.tdr
                ="(#{number_to_currency(p_customer.nbr_orders.order("created_at DESC").first.a_ok_total)})"
              
          %tr
            %th Commandes refusées :
            %td.tdr
              =p_customer.nbr_orders_refusees.count
     
            %td.tdr
              ="(#{number_to_currency(p_customer.nbr_orders_refusees.sum(:a_total))})"
          
          -if  p_customer.nbr_orders_refusees.order("created_at DESC").first
            %tr
              %th Dernière commande refusée :
              %td.tdr
                =l p_customer.nbr_orders_refusees.order("created_at DESC").first.created_at, :format => :date
              %td.tdr
                ="(#{number_to_currency(p_customer.nbr_orders_refusees.order("created_at DESC").first.a_total)})"
          
          
          %tr
            %th Produits déjà commandés :
            %td{:colspan => 2}
              -p_customer.p_products.where(:p_product_cat_id => 6).order(:code).uniq.each do |p_product|
                =p_product.code
                =p_product.name
                %br
              
              =link_to "Afficher les produits supplémentaires", "#", :onclick => "$(this).next('.more_products').toggle();return false;"
              -pp = p_customer.p_products.where("p_product_cat_id != 6").order(:code).uniq 
              -if pp.count > 0
                .more_products{:style => "display:none;"}
                  -pp.each do |p_product|
                    =p_product.code
                    =p_product.name
                    %br
              
              
          
  
      %table.table.table-hover.table-striped
        %tr
          %th ID
          %th Date
          %th Produit
          
          %th PU (HT)
          %th PU (TTC)
          %th Qté
          %th Prix (HT)
          %th Prix (TTC)
          %th Statut
          %th
          
          
          
          
        -p_customer.p_customer_sheets.order("created_at DESC").limit(5).each do |p_customer_sheet|
          -p_customer_sheet.p_sheet_lines.each do |p_sheet_line|
            %tr#p_customer_sheet{:id => p_customer_sheet.id}
              %td="##{p_customer_sheet.id}"
              %td=l p_customer_sheet.created_at, :format => :date
             
              %td
                = p_sheet_line.p_product.code
                = p_sheet_line.p_product.name
          
              -ok = p_sheet_line.shiped ? true : false
              -if ok
                
                
                %td
                  =number_to_currency p_sheet_line.ok_price, :precision => 5
                %td
                  =number_to_currency p_sheet_line.ok_price_ttc, :precision => 5
                
                %td
                  =p_sheet_line.ok_qte
                
                %td
                  =number_to_currency p_sheet_line.ok_price_tot
                %td
                  =number_to_currency p_sheet_line.ok_price_tot_ttc
              
              -else
                
                
                %td
                  =number_to_currency p_sheet_line.price, :precision => 5
                %td
                  =number_to_currency p_sheet_line.price_ttc, :precision => 5
                %td
                  =p_sheet_line.qte
                
                %td
                  =number_to_currency p_sheet_line.price_tot
                %td
                  =number_to_currency p_sheet_line.price_tot_ttc
                  
              
             
    
              %td{:style => "width:90px;"}=raw p_customer_sheet.state_html

  
              %td.actions
                -if p_customer_sheet.state == "brouillon"
                  = link_to i(:"trash-o"), [:admin, p_customer_sheet], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet auteur ? ' } , :remote => true
                = link_to i(:pencil), edit_admin_p_customer_sheet_path(p_customer_sheet), :remote => false
                = link_to i(:eye), admin_p_customer_sheet_path(p_customer_sheet), :remote => false

            
  