-#PDocument.update_arrondi

-if !params[:html] and @p_customer
  .qi_header
    .right
      = link_to "Retour à la fiche client",[:admin, @p_customer], :class => "btn btn-primary"
    %h1
      Clients
      %span
        Détail d'un client
      %span
        =link_to [:admin, @p_customer] do
          =@p_customer.code
          =@p_customer.show_name

  .qi_row
    .qi_pannel.qi_plain.padding
      =render :partial => "search_etat_form" 

.qi_row
  .qi_pannel.qi_plain.padding
    -if !params[:html]
      .right
        =link_to "Télécharger en PDF", request.query_parameters.merge({pdf: true}), :class => "btn btn-primary"
        
    -if params[:html] and @p_customer
    


      %div{:style => "height:0cm;"}
  
      =#;top:5cm;
      %div{:style => "position:relative;width:6.4cm;margin-right:1.5cm;float:right;"}
        %div{:style => "padding:4px 8px;min-height:80px;"}
          %h3{:style => "position:absolute;top:-40px;"} Adresse de facturation
    
          %strong=@p_customer.particular.organisation
          %br
          =@p_customer.particular.name
          =@p_customer.particular.firstname

      
          -if @p_customer.particular.address_2?
            %br
            =@p_customer.particular.address_2

          -if @p_customer.particular.address_3?
            %br
            =@p_customer.particular.address_3
          -if @p_customer.particular.cp? or @p_customer.particular.city?
            %br
            =@p_customer.particular.cp

            =@p_customer.particular.city
          %br
          =@p_customer.particular.country
          
          %p
            A Moirans, le 
            =l Date.today
    
      %div{:style => "height:2.6cm;"}
      
    
      %p Bonjour
      
 
      %p Veuillez trouver votre relevé de compte ci-dessous et de nous faire parvenir un règlement si des échéances sont dépassées.
 
      %p Merci de vérifier si vous avez en votre possession toutes les factures référencées, si cela n’était pas le cas merci de nous le signaler.
 
 
      %p Cordialement
      
      %hr
      
      
        
    %h1 Etat de compte
    
    -if !@p_customer
      %p
        =@p_compta_elements.count
        résultats
          
    

    -if params[:ok].to_s != ""
      Opérations 
      -if params[:ok] == "1"
        soldées
      -else
        non soldées
        
      -if @start and @stop
        du 
        =l (@start), :format => :date
        au
        =l (@stop), :format => :date
    
      -elsif @start
        à partir du 
        =l (@start), :format => :date
      -elsif @stop
        jusqu'au
        =l (@stop), :format => :date
    
    
    %table.table.table-hover.table-striped#p_customer_etat{:id => (@p_customer.id if @p_customer)}
      %thead
        %tr
          -if !@p_customer
            %th Client
          %th Date
          %th Echéance
          %th Type
          %th Réf
          %th Débit
          %th Crédit
          %th{:style => "width:20px"} Soldé ?
          -if !@p_customer
            %th Solde
          -if !params[:html]
            %th.action
    
      -if @stop and params[:ok].to_s == "" and @p_customer
        %tbody
          %tr
            %th{:colspan => (@p_customer ? 4 : 5)}
              Solde au
              =l (@stop), :format => :date
        
        
            - a = (@p_customer.encours_at(@stop) * -1)
            - a = 0.0 if a == -0.0
            %th
              -if a < 0
                =number_to_currency a
            %th
              -if a >= 0
                =number_to_currency a
            %th
            -if !@p_customer
              %th
            -if !params[:html]
              %th
      
  
  
    
      %tbody=render @p_compta_elements
  
      %tbody
        %tr
          %th{:colspan => (@p_customer ? 4 : 5)}
            Total
          %th.right_text
            -a = @p_compta_elements.where("amount < 0.0").sum(:amount)
            =number_to_currency (a * -1)
          %th.right_text
            -b = @p_compta_elements.where("amount > 0.0").sum(:amount)
            =number_to_currency b
          %th
          -if !@p_customer
            %th
          -if !params[:html]
            %th
    
    
      -if @start and params[:ok].to_s == "" and @p_customer
        %tbody
          %tr
            %th{:colspan => (@p_customer ? 4 : 5)}
              Solde au
              =l (@start - 1.second), :format => :date
      
            - a = (@p_customer.encours_at(@start - 1.second) * -1)
            - a = 0.0 if a == -0.0
            %th.right_text
              -if a < 0
                =number_to_currency a
            %th.right_text
              -if a >= 0
                =number_to_currency a
            %th
            -if !@p_customer
              %th
            -if !params[:html]
              %th
       
    -if !@stop and @p_customer
      %p 
        Encours du compte :
        %strong
          =number_to_currency @p_customer.encours_ttc 
     
        

-if params[:html]
  :scss
    body{
      font-family: arial, sans-serif;
      font-size:10pt;
      padding:0;
      margin:0;
    }
    .page{
      page-break-after: always;
      position:relative;
      width:28.1cm;
      box-sizing:border-box;
   
    
    }
  
    .table{
      width:100%;
      font-size:10pt;
      border-collapse:collapse;
      td, th{
        border:1px solid black;
        padding:2px 5px;
        page-break-inside: avoid !important;
      
      }
      td{
        vertical-align:top;
      }
      th{
        text-align:left;
        vertical-align:top;
      }
      .right_text{
        text-align:right;
      }
    }
  
  

  


