



-if price_line_block.p_customer
  %h3 Client
  -if price_line_block.p_customer and price_line_block.p_customer.particular
    =render :partial => "admin/p_customers/apercu", :locals => {:particular => price_line_block.p_customer.particular}


%table.table{:style => ""}
  %tr
    -if price_line_block.particular_bill
      %td{:style => "border:0"}
        %h3 Adresse de facturation

        =render(:partial => "admin/particulars/particular_detail", :locals => {:particular => price_line_block.particular_bill}) if price_line_block.particular_bill
    -if price_line_block.particular_send
      %td{:style => "border:0"}
        %h3 Adresse de livraison

        =render(:partial => "admin/particulars/particular_detail", :locals => {:particular => price_line_block.particular_send}) if price_line_block.particular_send


%p
  Date de commande :
  =l price_line_block.creation_date

-if price_line_block.wish_date
  %p
    Semaine de livraison souhaitée :
    =l price_line_block.wish_date, :format => "%V"
    (du
    =l price_line_block.wish_date.beginning_of_week
    au
    =l price_line_block.wish_date.end_of_week
    )
    %br
    Date saisie :
    =l price_line_block.wish_date

-if price_line_block.nbr_ship
  %p
    Nombre de colis :
    =price_line_block.nbr_ship

-if price_line_block.customer_ref?
  %p
    Référence commande personnalisée :
    =price_line_block.customer_ref

-if @p_customer_sheet and price_line_block.p_customer and price_line_block.p_customer.p_customer_sheet_note?

  %div
    %strong Notes pour les demandes de commandes pour ce client :
    =simple_format price_line_block.p_customer.p_customer_sheet_note
    %br

-if price_line_block.p_devise_id != 1
  %p
    Taux de change appliqué :
    1€ =
    =(1.0/ price_line_block.devise_rate).round(5)
    =price_line_block.devise_symbol
    ="(Provisoire)" if !price_line_block.local_amount_ttc?
%table.table
  %thead
    %tr
      %th Référence

      %th Désignation



      %th Qté
      -if @price_document and  @price_document.label != "Demande prix" and @price_document.label != "Réponse fournisseur"
        %th P.U. HT
        %th TVA
        %th
          Montant HT

        -if price_line_block.purchase?
          %th Montant équivalent
  %tbody
    -price_line_block.price_lines.each do |price_line|
      %tr
        %td
          =price_line.ref

        %td
          -if price_line.p_product_ref
            =price_line.p_product_ref.member_label
          -else
            =price_line.title

        
        %td.numeraire
          =price_line.qte
       
        -if @price_document and  @price_document.label != "Demande prix" and @price_document.label != "Réponse fournisseur"
          %td.numeraire
            =number_to_currency price_line.price_u_ht, :unit => price_line_block.devise_symbol

       
          %td.numeraire
            =price_line.tva_account_value.to_s+"%"

       


          %td.numeraire
            =number_to_currency price_line.tot_amount_ht, :unit => price_line_block.devise_symbol


          -if price_line_block.purchase?
            %td.numeraire
              =number_to_currency price_line.local_tot_amount_ht, :unit => price_line_block.devise_symbol


  -if @price_document and  @price_document.label != "Demande prix" and @price_document.label != "Réponse fournisseur"
    %table.table{:style => "width:auto;float:right;"}
      %tr
        %th
          Poids total :
        %td.numeraire
          ="#{price_line_block.weight_tot}Kg"

      -if !PriceLineBlock::PURCHASE_BLOCKS.include?(price_line_block.block_type)
        %tr
          %th Total remises U. HT :
          %td.numeraire
            =number_to_currency price_line_block.cumul_discount_ht, :unit => price_line_block.devise_symbol
        %tr
          %th
            Total HT
          %td.numeraire
            =number_to_currency price_line_block.tot_lines_ht, :unit => price_line_block.devise_symbol



        -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, :unit => price_line_block.devise_symbol

        %tr
          %th
            Frais de port HT
            ="(TVA #{price_line_block.fdp_tva_rate}%)"
          %td.numeraire
            =number_to_currency price_line_block.tot_fdp_ht, :unit => price_line_block.devise_symbol

      %tr
        %th
          Total HT Net
        %td.numeraire
          =number_to_currency price_line_block.tot_amount_ht, :unit => price_line_block.devise_symbol

      %tr
        %th
          Total TVA
        %td.numeraire
          =number_to_currency price_line_block.tot_amount_tva, :unit => price_line_block.devise_symbol

      %tr
        %th
          Total TTC
        %td.numeraire
          =number_to_currency price_line_block.tot_amount_ttc, :unit => price_line_block.devise_symbol

      -if !PriceLineBlock::PURCHASE_BLOCKS.include?(price_line_block.block_type)
        %tr
          %th
            &nbsp;
          %th

        %tr
          %th
            Net à payer
          %td.numeraire
            =number_to_currency price_line_block.tot_amount_ttc, :unit => price_line_block.devise_symbol

    %table.table{:style => "width:auto;"}
      %tr
        %th
          Taux
          %br
          TVA
        %th Montant HT Net
        %th Montant 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|
        %tr
          %td
            ="#{key}%"
          %td
            =number_to_currency value[:montant], :unit => price_line_block.devise_symbol

          %td
            =number_to_currency value[:tva], :unit => price_line_block.devise_symbol


    %table.table{:style => "width:auto;"}
      %tr
        %th
          Échéance
        %th Mode de paiement
        %th
          Montant net
      %tr
        %td
          =price_line_block.payment_delais.to_i
          jours
        %td
          =price_line_block.p_payment_type.name if price_line_block.p_payment_type
        %td
          =number_to_currency price_line_block.tot_amount_ttc

.clear
