:scss
  body{
    font-family:Cousine, arial, sans-serif;
    font-size:8.8pt;
    padding:0;
    margin:0;
  }

  .page{
    page-break-after: always;
    position:relative;
    width:28.1cm;
    box-sizing:border-box;
   
    
  }
  
  .table{
    width:100%;
    font-size:8.8pt;
    border-collapse:collapse;
    td, th{
      border:1px solid black;
      padding:1px;
      page-break-inside: avoid !important;
      
    }
    td{
      vertical-align:top;
    }
    th{
      text-align:center;
      vertical-align:top;
    }
  }
  

  table tbody tr td:before,
  table tbody tr td:after {
      content : "" ;
      height : 4px ;
      display : block ;
  }

  



  


!!!
%html{:lang => "fr", "xml:lang" => "fr", :xmlns => "http://www.w3.org/1999/xhtml"}
  %head
    %meta{:name=>"viewport", :content=>"width=device-width,initial-scale=1"}
    %meta{ :"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8" }
    <link href="https://fonts.googleapis.com/css?family=Cousine:400,700" rel="stylesheet">
    
  %body
    -@p_ship_tour.p_ship_tour_trucks.each do |p_ship_tour_truck|
      - p_ship_tour_truck_remorque = p_ship_tour_truck.p_ship_tour_truck if p_ship_tour_truck_remorque
      - if !p_ship_tour_truck.p_truck.remorque
        .page
      
          %p{:style => "text-align:center;text-transform:uppercase"}
            Feuille de tournée
    
          %p{:style => "float:left;"}
            Chauffeur :
            =p_ship_tour_truck.p_driver.name
    
          %p{:style => "float:right;"}
            Camion :
            =p_ship_tour_truck.p_truck.immat
          %p{:style => "text-align:center;"}
            Date de livraison :
            =l p_ship_tour_truck.p_ship_tour.start_at, :format => :date
    
          %table.table
            %thead
              %tr
                %th{:style => "text-align:left;"}
                  Tour
      
                %th{:rowspan => 2}
                  Client
      
                %th{:rowspan => 2}
                  Produit
        
                %th{:rowspan => 2}
                  Quantité commandée
      
                %th{:rowspan => 2}
                  Prix unitaire
        
                %th{:rowspan => 2}
                  Quantité livrée
      
                %th{:colspan => 3}
                  Paiement
      
                %th{:rowspan => 2}
                  Divers
      
              %tr
                %th{:style => "text-align:right;"} Pièce
      
                %th
                  Espèce
                %th
                  Chèque
                %th 
                  Autre
            -qte_tot = 0.0
            -qte_products = {}
            -p_products_id = []
            -if p_ship_tour_truck_remorque
              -p_docs = p_ship_tour_truck.p_documents + p_ship_tour_truck_remorque.p_documents
            -else
              -p_docs = p_ship_tour_truck.p_documents 
              
            -(p_docs).each do |p_document|
              -element = p_document.element
              %tbody{ :style => "page-break-inside: avoid !important;"}
                %tr{ :style => "page-break-inside: avoid !important;"}
                  %td{:rowspan => 3, :style => "page-break-inside: avoid !important;"}
                    =p_document.d_number
            
                    %br
                    %br
            
                    %center=p_document.p_customer.code
          
                  %td{:rowspan => 2}
                    %div{:style => "text-transform:uppercase;"}
                      %strong
                        =element.particular_send.civilite
    
                        =element.particular_bill.organisation
    
    
                        =element.particular_send.name
                        =element.particular_send.firstname

    
                      -if element.particular_send.address_2?
                        %br
                        =element.particular_send.address_2

                      -if element.particular_send.address_3?
                        %br
                        =element.particular_send.address_3
                      -if element.particular_send.cp? and element.particular_send.city?
                        %br
                        =element.particular_send.cp

                        =element.particular_send.city
                
                    %div{:style => "text-transform:uppercase;"}
   
                      -p_document.element.p_customer.p_contacts.each do |p_contact|
  
                        .p_contact
                          =p_contact.name if p_contact.name?
                          =p_contact.tel if p_contact.tel?
            
                      -p_document.element.particular_send.p_contacts.each do |p_contact|
      
                        .p_contact
                          =p_contact.name if p_contact.name?
                          =p_contact.tel if p_contact.tel?
                  %td
                    -if p_document.p_sheet_line
                      =p_document.p_sheet_line.p_product.name
          
                  %td{:style => "text-align:right;"}
                    -if p_document.p_sheet_line
                      =p_document.p_sheet_line.qte
                      - qte_tot += p_document.p_sheet_line.qte
                      - qte_products[p_document.p_sheet_line.p_product_id] = qte_products[p_document.p_sheet_line.p_product_id].to_f + p_document.p_sheet_line.qte
                      - p_products_id << p_document.p_sheet_line.p_product_id
                      - p_products_id = p_products_id.uniq
                  %td{:rowspan => 2, :style => "text-align:right;"}
                    -if p_document.p_sheet_line
                      =p_document.p_sheet_line.price_tot 
                  %td{:rowspan => 2}
                  %td{:rowspan => 2}
                  %td{:rowspan => 2}
                  %td{:rowspan => 2}
                    %br
                    %br
                    %br
                    Date enc.
                  %td{:rowspan => 3}
                    Sécurité
                    %br
                    %br
                    KM
                    %br
                    Capactié
                    %br
                    %br
                    Reste
                    %br
                    %br
                    %br
            
                %tr{ :style => "page-break-inside: avoid !important;"}
                  %td{:colspan => 2}
                    Horaire prévu
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    Journée
            
                    %br
                    %br
                    Horaire livré
            
                %tr{ :style => "page-break-inside: avoid !important;"}
                  %td{:colspan => 8}
                    Journée
      
            %tr
              %td{:colspan => 3}
                Total cumulé
        
              %td{:style => "text-align:right;"}
                =qte_tot
              %td
              %td
              %td
              %td
              %td
              %td
   
          %br
          %br
          -p_products = PProduct.where(:id => p_products_id )
          %table.table{:style => "page-break-inside: avoid;"}
            %tr
              %th{:style => "width:2cm"}
              -p_products.each do |p_product|
                %th
                  =p_product.name
      
            %tr
              %th
                N° ONU
              -p_products.each do |p_product|
                %th
                  =p_product.un
            %tr
              %td A livrer
              -p_products.each do |p_product|
                %td
                  =qte_products[p_product.id]
      
            %tr
              %td
                Reste en cuve
        
              -p_products.each do |p_product|
                %td
      
            %tr
              %td
                Enlèvement
        
              -p_products.each do |p_product|
                %td   
            %tr
              %td
                ="-"
        
              -p_products.each do |p_product|
                %td
            %tr
              %td
                ="-"
        
              -p_products.each do |p_product|
                %td
            %tr
              %td
                ="-"
        
              -p_products.each do |p_product|
                %td
            %tr
              %td
                ="-"
        
              -p_products.each do |p_product|
                %td
            %tr
              %td
                Additivation
        
              -p_products.each do |p_product|
                %td
            %tr
              %td
                Dépotage
        
              -p_products.each do |p_product|
                %td
      
            %tr
              %td
                ="-"
        
              -p_products.each do |p_product|
                %td
      
            %tr
              %td
                Livraisons client
        
              -p_products.each do |p_product|
                %td
      
            %tr
              %td
                Reste en cuve
        
              -p_products.each do |p_product|
                %td
      
            %tr
              %td
                Purge
        
              -p_products.each do |p_product|
                %td
      
      
            %tr
              %td
                Consignes
        
        
              %td{:colspan => p_products.size}
                -PProductPNorme.joins(:p_product_spec).where(:p_product_id => p_products_id, :p_product_specs => {:un => true}).each do |p_product_p_norme|
                  %p{:style => "margin:0"}
                    =p_product_p_norme.p_product.name
                    =":"
                    =p_product_p_norme.p_product_spec.code
                    =p_product_p_norme.p_product_spec.description
      
      
      
      
      
      
        .page
          %table.table
            %tr
              %th Chauffeur-horaire
              %th{:style => "width:2.7cm;"} Matin
              %th{:style => "width:2.7cm;"} Après midi
              %th Total
              %th{:style => "width:2.7cm;"}
              %th{:rowspan => 7, :style => "width:5cm;"} Signature chauffeur
              %th{:rowspan => 2, :colspan => 2}
                Protocole Sécurité au
                %br
                départ du camion
            %tr
              %td Heure fin
              %td{:style => "width:2.7cm;"} h
              %td{:style => "width:2.7cm;"} h
              %td Temps chauffeur
              %td{:style => "width:2.7cm;"} h
      
            %tr
              %td Heure début
              %th{:style => "width:2.7cm;"} h
              %th{:style => "width:2.7cm;"} h
              %td Dont conduite + livraison
              %td{:style => "width:2.7cm;"} h
              %td Feux
              %td{:style => "width:2cm;"} 
      
            %tr
              %td =
              %td h
              %td h
              %td Autre
              %td h
              %td Domes
              %td
            %tr
              %th Véhicule-horaire
              %th Matin
              %th Après-midi
              %th Compteur kilométrique
              %td
              %td Vannes
              %td 
            %tr
              %td Heure fin
              %td h
              %td h
              %td Index fin
              %td
              %td Pneumatiques
              %td
            %tr
              %td Heure début
              %td h
              %td h
              %td Index début
              %td
      
            %tr
              %td =
              %td h
              %td h
              %td =
              %td
              %th{:rowspan => 7, :style => "width:5cm;"} signature contrôle
      
            %tr
              %th{:colspan => 5} Volucompteur
            %tr
              %td index fin
              %td{:colspan => 2}
              %td{:colspan => 2}
      
            %tr
              %td index début
              %td{:colspan => 2}
              %td{:colspan => 2}
      
            %tr
              %td =
              %td{:colspan => 2}
              %td{:colspan => 2}
      
            %tr
              %th Carburant déplacement (GO)
              %td{:colspan => 2}
              %th Carburant livraison (FOD)
              %td
      
            %tr
              %td{:style => "text-align:right;"}
                (dépot)
              %td{:colspan => 2}
              %td{:style => "text-align:right;"}
                (dépot)
              %td
        
        .page
          %table.table
            %tr
              %td{:style => "width:50%"}
                %strong
                  DOCUMENT DE TRANSPORT ADR N° 
          
                %br
                %strong CHAUFFEUR :
                =p_ship_tour_truck.p_driver.name
                %br
                %strong DATE :
                =l p_ship_tour_truck.p_ship_tour.start_at, :format => :date
                %br
                %strong N° PLAQUE :
                =p_ship_tour_truck.p_truck.immat
          
              %td
                PAYRE Produits Pétroliers
                SILO "Les Vernes"
                38430 Moirans
      
          %table.table
            %thead
              %tr
                %th{:colspan => 2} DENOMINATION + NUMERO ONU
                %th
                  UN1203
                  %br
                  ESSENCE
                %th{:colspan => 4}
                  UN1202
                  %br
                  CARBURANT DIESEL
                %th{:colspan => 4}
                  UN1202
                  %br
                  GASOIL
                %th
                  UN1223
                  %br
                  KEROSENE
              %tr
                %th{:colspan => 2} N° ETIQUETTE ET GROUPE EMBALLAGE
                %th 3, II
                %th{:colspan => 4} 3, III (disposition spéciale 640M)
                %th{:colspan => 4} 3, III (disposition spéciale 640M)
                %th 3, III
              %tr
                %th{:colspan => 2} 
                  NUMERO DE COMPARTIMENT
                  %span{:style => "font-size:7.8pt;"}
                    (en ordre croissant à partir de la cabine)
                %td
                %td 1
                %td 2
                %td 3
                %td 4
                %td 1
                %td 2
                %td 3
                %td 4
                %td
      
              %tr
                %th{:colspan => 2} NOMBRE DE LITRE AVANT LIVRAISON
                %td
                %td
                %td 
                %td 
                %td 
                %td 
                %td 
                %td 
                %td 
                %td
              %tr
                %th{:colspan => 2} LIVRAISON
                %th{:colspan => 10}
                  LITRES DANS LES COMPARTIMENTS APRES CHAQUE LIVRAISON
              %tr
                %th NOM ET ADRESSE DU DESTINATAIRE
                %th LITRE
                %th{:colspan => 10, :style => "background:black;"}
      
            %tbody
              -if p_ship_tour_truck_remorque
                -psl = (p_ship_tour_truck.p_sheet_lines + p_ship_tour_truck_remorque.p_sheet_lines)
              -else
                -psl = p_ship_tour_truck.p_sheet_lines
                
                
              -psl.each do |p_sheet_line|
                -element = p_sheet_line.p_customer_sheet
                %tr{:style => "page-break-inside: avoid;"}
                  %td{:style => "text-transform:uppercase;padding:5px 4px"}
          
                    =element.particular_send.civilite
  
                    =element.particular_bill.organisation
  
  
                    =element.particular_send.name
                    =element.particular_send.firstname

    
                    -if element.particular_send.address_2?
         
                      =element.particular_send.address_2

                    -if element.particular_send.address_3?
         
                      =element.particular_send.address_3
                    -if element.particular_send.cp? and element.particular_send.city?
           
                      =element.particular_send.cp

                      =element.particular_send.city
                  %td
                    =p_sheet_line.qte
                  %td
                  %td
                  %td 
                  %td 
                  %td 
                  %td 
                  %td 
                  %td 
                  %td 
                  %td
            %tbody{:style => "page-break-inside: avoid;"}
              %tr
                %th RESTANT
                %td
                %td
                %td
                %td 
                %td 
                %td 
                %td 
                %td 
                %td 
                %td 
                %td
        
              %tr
                %th{:colspan => 2}
                  VEHICULE CITERNE VIDE, 3,
                  cocher la case correspondante svp
          
                %td
                %td
                %td 
                %td 
                %td 
                %td 
                %td 
                %td 
                %td 
                %td
      
              %tr
                %th{:colspan => 2} DERNIERE MARCHANDISE CHARGEE :
                %th
                  UN1203
                  %br
                  ESSENCE
                %th{:colspan => 4}
                  UN1202
                  %br
                  CARBURANT DIESEL
                %th{:colspan => 4}
                  UN1202
                  %br
                  GASOIL
                %th
                  UN1223
                  %br
                  KEROSENE
        
        
        
        
