%head
  
  <script src="/jquery-3.4.1.min.js"></script>
  :scss
    body{
      font-size:12px;
      font-family:arial, sans-serif;
      
      .table{
        border-collapse:collapse;
        font-family:arial, 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:3.5cm;font-size:14px;margin-bottom:2cm;padding-right:2cm;width:250px;"}
    
    -if @price_document.label == "Bon de livraison"
      -@bl = true
      -particular_doc = price_line_block.particular_send
      
      
    -else
      -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;"}
      Vigneulles Les Hattonchatel, 
      
      %br
      le 
      
      =l @price_document.date, :format => :short_date
    
    
    
  =image_tag("/logo-jipe.png", :style => "width:5cm;")
  
  %div{:style => "margin:30px 0;margin-top:40px;"}
    %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:40px;"}
    %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 Référence
        %th Désignation
        %th Qté

        %th P.U. HT
        %th TVA
        %th
          Montant HT
    %tbody.lines_body#lines_body
      -price_line_block.price_lines.each do |price_line|
        %tr
          %td
            =price_line.ref
          %td
            =price_line.title
        
          %td.numeraire
            =price_line.qte if price_line.qte != 0.0
          
          %td.numeraire
        
            =number_to_currency price_line.price_u_ht if price_line.qte != 0.0
        

          %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_adjust
        %td
          %br
          %br
        %td
        %td
        %td
        %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

  %table.table{:style => "width:auto;"}
    %tr
      %th Conditions de paiement
      %th 
        Échéance
      %th Mode de paiement
      
    %tr
      %td
        =price_line_block.payment_delais.to_i
        jours
        -if price_line_block.ct_payment_month_end
          fin de mois
        
      %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