=semantic_form_for [:admin, @p_ship_tour_truck_sheet_line], :remote => true, :html => {:onkeyup => "update_tot();"} do |p_ship_tour_truck_sheet_line|

  .content
    =p_ship_tour_truck_sheet_line.inputs do

      %table{:style => "width:100%"}
      
        %td{:style => "width:50%;padding-right:30px;"}
          =p_ship_tour_truck_sheet_line.input :p_ship_tour_truck_id, :collection => @p_ship_tour_truck_sheet_line.p_ship_tour_truck.p_ship_tour.p_ship_tour_trucks, :as => :select, :include_blank => false, :member_label => :member_label, :label => "Camion :"
          -p_sheet_line = p_ship_tour_truck_sheet_line.object.p_sheet_line
        
        
        %td
          -@p_customer_sheet = @p_ship_tour_truck_sheet_line.p_customer_sheet
          
          .right=link_to "Voir la commande", [:admin, @p_customer_sheet], :target => "_blank"
          
          %table.en-tete-table{:style => "width:auto;"}
            %tr
              %th Conditions de réglement
     
  
            %tr
    
  
              %td{:style => "width:150px;"}
                -if @p_customer_sheet.p_payment_type
                  =@p_customer_sheet.p_payment_type.name
                  %br
      
                -if @p_customer_sheet.comptant
                  Comptant
                -else
                  =@p_customer_sheet.payment_delais.to_i
                  j nets
            
          
          
      
      %br
      %br
      
      %table{:style => "width:100%;"}
        %tr
          %th
          %th{:style => "width:120px;"} Prix U HT
          %th{:style => "width:120px;"}  Quantité
          %th{:style => "width:120px;"} Prix HT
          %th{:style => "width:120px;"} Prix TTC
          %th
        %tbody.p_ship_tour_truck_sheet_line
          %tr{:style => "border-top:1px solid black"}
            %td{:colspan => 7}
              %br
              .address
                =link_to admin_p_customer_path(p_sheet_line.p_customer_sheet.p_customer) do
                  -if p_sheet_line.p_customer_sheet.particular_send.organisation?
                    =p_sheet_line.p_customer_sheet.particular_send.organisation

                  -if p_sheet_line.p_customer_sheet.particular_send.firstname? or p_sheet_line.p_customer_sheet.particular_send.name?
                    %strong
                      =p_sheet_line.p_customer_sheet.particular_send.firstname
                      =p_sheet_line.p_customer_sheet.particular_send.name

                -if false
                  %br
                  =p_sheet_line.p_customer_sheet.particular_send.cp
                  =p_sheet_line.p_customer_sheet.particular_send.city
          %tr
            %td
        
      
              =link_to admin_p_customer_sheet_path(p_sheet_line.p_customer_sheet) do
                ="#"+p_sheet_line.p_customer_sheet_id.to_s
          
              %strong=p_sheet_line.p_product.name
            %td.price_th{:data => {:price => p_sheet_line.price}}
              =number_to_currency p_sheet_line.price, :precision => 4
        
            %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=p_ship_tour_truck_sheet_line.input :ref, :label => false, :placeholder => "Référence bon"
      
      
        
          %tr
            %td
              Livré :

        

        
        
            %td{:style => "width:200px"}
              -p_ship_tour_truck_sheet_line.object.to_return = true
              =p_ship_tour_truck_sheet_line.hidden_field :to_return

              =p_ship_tour_truck_sheet_line.input :price_shiped, :placeholder => "Prix U Livré (HT) :", :label => false, :input_html => {:class => "price_shiped"}
        

        
            %td
              =p_ship_tour_truck_sheet_line.input :qte_shiped, :placeholder => "Quantitée livrée :", :label => false, :input_html => {:class => "qte_shiped", :id => "qte_focus"}
            %td.sheet_line_tot
            %td.sheet_line_tot_ttc
            %td{:style => "padding-left:10px;width:200px"}
        
              =p_ship_tour_truck_sheet_line.input :canceled, :label => "livraison annulée ?"

              =p_ship_tour_truck_sheet_line.input :raison, :placeholder => "Raison", :input_html => {:rows => 2}, :label => false
          %tr
            %td{:colspan => 6}
              .p_payments_form
                =p_ship_tour_truck_sheet_line.semantic_fields_for :p_payments do |form|
                  =render :partial => "admin/p_payments/essentials_form", :locals => {:form => form}

              %p= link_to_add_fields "Ajouter un paiement", p_ship_tour_truck_sheet_line, :p_payments
          
              .payment_info
      
      
      
      
      
      
      
      
  .actions=p_ship_tour_truck_sheet_line.submit "sauvegarder", :class => "btn btn-primary"
 
  

:coffeescript
  tva = 1.2
  @update_tot = ->
    tot_sheet = 0.0
    
    $(".p_ship_tour_truck_sheet_line").each ->
      
      
      
      tot = 0.0
      pht = parseFloat($(this).find(".price_shiped").val())
      tot = parseFloat($(this).find(".qte_shiped").val()) * pht
      if (!$(this).find(".price_shiped").is(":focus") and $(this).find(".price_shiped").val() == "")
        $(this).find(".price_shiped").val($(this).find(".price_th").data("price"))
      
      $(this).find(".sheet_line_tot").html(accounting.formatMoney(tot))
      $(this).find(".sheet_line_tot_ttc").html(accounting.formatMoney(tot*tva))
      #$(this).find(".sheet_line_price_ttc").val((Math.round( (pht*1.2) * 1000 )/ 1000 ))
      tot_paid = 0.0
      $(this).find(".p_payments_form").find(".field").each ->
        amount = parseFloat($(this).find(".payment_amount").val())
        tot_paid += amount
      
      dif = (tot * tva) - tot_paid
      
  
      
      if !isNaN(dif) and parseFloat(dif) != 0.0
        s = accounting.formatMoney(dif)
        html = '<div class="alert alert-danger fade in alert-dismissible"><strong>Attention :</strong> le paiement ne correspond pas, différence : <strong>'+s+'</strong>.</div>'
        
        $(this).find(".payment_info").html(html)
        
        
      else
        $(this).find(".payment_info").html("")
      
      
        
     
  update_tot()
  
  $("#qte_focus").focus()
  

:scss
  table{
    td{
      vertical-align:top;
    }
  }
  .p_payments_form{
    background:rgba(0,0,0,0.05);
    padding:5px 8px;
  }
  

-not_comptant_ids = PPaymentType.where(:comptant => false).ids

:javascript
  not_comptant_ids = #{not_comptant_ids};
  

:coffeescript
  $(document).on "change", ".payment_type_id_select", ->
    val = $(this).val()
    if $.inArray(parseInt(val), not_comptant_ids) isnt -1
      $(this).closest(".field").find(".not_comptant").show()
    else
      $(this).closest(".field").find(".not_comptant").hide() 