

.qi_header
  .right
    =raw @p_ship_tour.state_html
  %h1
    Tournées
    %span
      Tournée du 
      =l @p_ship_tour.start_at, :format => :date




-@p_ship_tour.p_ship_tour_trucks.each do |p_ship_tour_truck|
  =render :partial => "p_ship_tour_truck_return", :locals => {:p_ship_tour_truck => p_ship_tour_truck} if !p_ship_tour_truck.tracteur_id
  
  -if p_ship_tour_truck.p_ship_tour_trucks.count > 0
    %p &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Remorques :
    -p_ship_tour_truck.p_ship_tour_trucks.each do |p_ship_tour_truck|
      =render :partial => "p_ship_tour_truck_return", :locals => {:p_ship_tour_truck => p_ship_tour_truck}

-if @p_ship_tour and @p_ship_tour.state != "livrée"
  %center
    %br
    %br

  
    =semantic_form_for [:admin, @p_ship_tour], :url => ship_return_save_admin_p_ship_tour_path(@p_ship_tour), :html => {:method => :post, :onkeyup => "update_tot();"} , :remote => false, :data => {:confirm => "Attention, une fois validée les données ne pourront plus être modifiées."} do |f|
      =f.submit "Valider le retour de tournée", :class => "btn btn-primary"
  %br
  %br
  %br


: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
    
      $(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()

: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
  
  $('.payment_type_id_select').change ->
    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()