%head
  <link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900&display=swap" rel="stylesheet">
  <script src="/jquery-3.4.1.min.js"></script>
  :scss
    body{
      font-size:12px;
      font-family:'Lato', sans-serif;
      -webkit-font-smoothin:antialiased;
      .table{
        border-collapse:collapse;
        font-family:'Lato', sans-serif;
        
        td,th{
          border:1px solid gray;
          padding:2px 7px;
        }
      }
      
      .table{
        td{
          padding:2px 5px;
        }
      }
    }
    
    
    .clear{
      clear:both;
    }
    
    .table{
      width:100%;
      
    }
    
    
    table{
      font-size:inherit;
      td{
        vertical-align:top;
        height:auto;
      }
      
    }
    td.numeraire{
      white-space: nowrap;
      text-align:right;
    }
    
    .lines_body{
      border-bottom:1px solid gray;
      td{
        border-top:0 !important;
        border-bottom:0 !important;
      }
    }
    
    


-price_line_block = @price_document.price_line_block
%body
  
  %div{:style => "float:right;margin-top:3cm;font-size:14px;margin-bottom:1cm;padding-right:2cm;width:400px;"}
    %table{:style => "width:100%;"}
      %tr
        %td{:style => "width:50%;"}
          %strong Adresse de livraison
          %br
          -particular_doc = price_line_block.particular_send
    
    
    
    
          -if particular_doc.organisation?
            %strong=particular_doc.organisation
          -if particular_doc.organisation?
            %br
            =particular_doc.com_name
      
    
          -if particular_doc.firstname? or particular_doc.name?
            =particular_doc.civilite
      
            =particular_doc.firstname

            =particular_doc.name
            %br

          =particular_doc.address_2

          -if particular_doc.address_3?
            %br
            =particular_doc.address_3
          %br
          =particular_doc.cp

          =particular_doc.city
          %br
          =particular_doc.country
          
        %td{:style => "width:50%;"}
          %strong Adresse de facturation
          %br
          -particular_doc = price_line_block.particular_bill
    
    
    
    
          -if particular_doc.organisation?
            %strong=particular_doc.organisation
          -if particular_doc.organisation?
            %br
            =particular_doc.com_name
      
    
          -if particular_doc.firstname? or particular_doc.name?
            =particular_doc.civilite
      
            =particular_doc.firstname

            =particular_doc.name
            %br

          =particular_doc.address_2

          -if particular_doc.address_3?
            %br
            =particular_doc.address_3
          %br
          =particular_doc.cp

          =particular_doc.city
          %br
          =particular_doc.country
          
        
    
    %br
    %br
    %span{:style => "font-size:12px;"}
      Réaumont, 
      
      %br
      le 
      
      =l @price_document.date, :format => :short_date
    
    
    
  =image_tag("/logo-lockaz.png", :style => "width:5.5cm;margin-top:30px;")
  
  %div{:style => "margin:30px 0;margin-top:0px;margin-bottom:0"}
    %div{:style => "padding:6px 13px;font-size:17px;text-transform:uppercase;border:2px solid black;font-weight:bold;display:inline-block;position:absolute;top:1cm;;right:0;"}
      =@price_document.label
      ="N°#{@price_document.d_number}"
  
  %table{:style => "margin-bottom:00px;"}
    %tr
      %td=# N° de client :
      %td=#@price_document.p_customer.code


    -if price_line_block.customer_ref?
      %tr
        %td Réf. interne client :
        %td=@price_document.price_line_block.customer_ref
    
    -if @price_document.s_project
      %tr
        %td Objet / projet :
        %td
          =@price_document.s_project.name
  
  
  .clear
  
  
  
  

      
  %table.table
    %thead
      %tr

        %th Désignation

        %th TVA
        %th
          Montant HT
    %tbody.lines_body#lines_body
      -price_line_block.price_lines.each do |price_line|
        %tr

          %td
            Forfait 
            ="#{price_line.qte}J location"
            =price_line.title
            
            
            -if price_line.ship_price_ht.to_f > 0.0
              ="+ livraison incluse"
            %br
            Livraison :
            
            =l price_line.ship_at, :format => :short_date if price_line.ship_at
            
            %br
            Récupération :
            
            =l price_line.return_at, :format => :short_date if price_line.return_at
            
            -if price_line.carburant
              %br
              Carburant : livrée réservoir plein, rendu plein, remise à niveau : 
              =price_line.carburant_type
              =number_to_currency price_line.carburant_price
              HT / litres
              ="(#{number_to_currency(price_line.carburant_price*(price_line.tva_account_value/100+1))} TTC)"
            
            %br
            %br
            
            Caution : chèque de 
            =number_to_currency price_line.caution
            non encaissé


          %td.numeraire
            =price_line.tva_account_value.to_s+"%" if price_line.qte != 0.0

          %td.numeraire
            =number_to_currency price_line.tot_amount_ht if price_line.qte != 0.0
      
      %tr
        %td
          %br
          %br
          %br
          -if @price_document.label == "Facture"
            %strong 
              Le réglement de cette facture vaut acceptation de nos conditions générales de vente et acceptation du contrat N°
              =@price_document.contrat_reference
            
          -else @price_document.label == "Contrat"
            %strong La signature de ce contrat avec "Bon pour accord" où le réglement de la facture associée vaut acceptation de nos conditions générales de vente et acceptation de ce contrat. 
          
          %br
          %br
          %strong
            COVID-19 : Nous vous demandons de respecter les gestes barrières avec le livreur, et laisser la machine au moins 5h sans utilisation à la livraison & avant la récupération.
        
        %td
        %td
      
      %tr#td_adjust
        %td
          %br
          %br
        %td
        %td

        
    
    :coffeescript
      if $("#lines_body").height() < 400
        $("#td_adjust").css("height", 400 - $("#lines_body").height())
        

    %table.table{:style => "width:auto;float:right;border-top:0;"}

      %tr
        %th{:style => "border-top:0;"}
          Total HT
        %td.numeraire{:style => "border-top:0;width:70px;"}
          =number_to_currency price_line_block.tot_lines_ht
  
      -if price_line_block.tot_discount_ht != 0.0
        %tr
          %th
            Remise commerciale exceptionnelle (HT
            ="(#{price_line_block.ct_tot_discount_percent}%)"
          %td.numeraire
            =number_to_currency price_line_block.tot_discount_ht
  

  
      %tr
        %th
          Total TVA
        %td.numeraire
          =number_to_currency price_line_block.tot_amount_tva
      
      %tr
        %th
          Total TTC
        %td.numeraire
          =number_to_currency price_line_block.tot_amount_ttc
      
      %tr
        %th{:style => "border-left:0;border-right:0;"}
          &nbsp;
        %th{:style => "border-left:0;border-right:0;"}
  
      %tr
        %th
          Net à payer
        %td.numeraire
          =number_to_currency price_line_block.tot_amount_ttc

      
      
    -if !@bl
      %br
      %br
      %table.table{:style => "width:auto;"}
        %tr
          %th 
            TVA
          %th Base TVA
          %th Total TVA
          
        -tva_rates = {}
    
        -price_line_block.price_lines.each do |pl|
    
          -tva_rates[pl.tva_account_value.to_s] = tva_rates[pl.tva_account_value.to_s] || {:montant => 0.0, :tva => 0.0}
      
          -tva_rates[pl.tva_account_value.to_s][:montant] += pl.tot_amount_ht.to_f - (pl.tot_amount_ht.to_f * ((price_line_block.ct_tot_discount_percent and price_line_block.ct_tot_discount_percent != 0.0) ? (price_line_block.ct_tot_discount_percent.to_f/100) : 0.0))
      
          -tva_rates[pl.tva_account_value.to_s][:tva] += pl.tot_amount_tva.to_f  - (pl.tot_amount_tva.to_f * ((price_line_block.ct_tot_discount_percent and price_line_block.ct_tot_discount_percent != 0.0) ? (price_line_block.ct_tot_discount_percent.to_f/100) : 0.0.to_f))
      
       
    
        -tva_rates[price_line_block.fdp_tva_rate.to_s] = tva_rates[price_line_block.fdp_tva_rate.to_s] || {:montant => 0.0, :tva => 0.0}
    
        -tva_rates[price_line_block.fdp_tva_rate.to_s][:montant] += price_line_block.tot_fdp_ht
    
        -tva_rates[price_line_block.fdp_tva_rate.to_s][:tva] += price_line_block.tot_fdp_tva
      
        -(tva_rates).each do |key, value|
          -if value[:montant] != 0.0
            %tr
              %td
                ="#{key}%"
              %td
                =number_to_currency value[:montant]
        
              %td
                =number_to_currency value[:tva]

  %br
  %br
  -if @price_document.label == "Facture"
    %table.table{:style => "width:auto;"}
      %tr
        %th Conditions de paiement
        %th 
          Échéance
        %th Mode de paiement
      
      %tr
        %td
          -if price_line_block.payment_delais.to_i > 0
            =price_line_block.payment_delais.to_i
            jours
            -if price_line_block.ct_payment_month_end
              fin de mois
          -else
            A réception de la facture
        
        %td
          =l price_line_block.payment_end_at, :format => :short_date
        %td
          =price_line_block.p_payment_type.name if price_line_block.p_payment_type
      

    %br
    %p

      Aucun escompte en cas de règlement anticipé. 
      ="-"
      En cas de retard de paiement, seront exigibles, conformément à l'article L 441-6 du code de commerce, une indemnité calculée sur la base de trois fois le taux de l'intérêt légal en vigueur ainsi qu'une indemnité forfaitaire pour frais de recouvrement de 40 euros.
  .clear