.sub_header
  .inner
    %h2
      =qit('my-account-orders', 'Mon compte / Détail de ma commande')



.main_wrapper.general_padding


  .main_center.white_background

    .right
      =state_helper @p_customer_sheet.state

    .back_link
      -price_line_block = @p_customer_sheet.price_line_block
      =link_to public_my_account_path do
        =ic :"arrow-alt-circle-left"
        =qit "return-account", "Retour à mes commandes"


    / %p
    /   Type de livraison :
    /   =price_line_block.shipper_name_with_date


    / -if price_line_block.p_shipper and price_line_block.p_shipper.with_colissimo_point
    /   %p Point retrait :
    /   %p
    /     =price_line_block.cl_nom
    /     %br
    /     =price_line_block.cl_adresse1
    /     %br
    /     -if price_line_block.cl_adresse2?
    /       =price_line_block.cl_adresse2
    /       %br
    /     -if price_line_block.cl_adresse3?
    /       =price_line_block.cl_adresse3
    /       %br
    /     =price_line_block.cl_codepostal

    /     =price_line_block.cl_localite
    /     %br
    /     =price_line_block.cl_identifiant
    /     %br
    /     =price_line_block.cl_distributionsort



    / -if price_line_block.p_shipper and price_line_block.p_shipper.with_dates
    /   %p
    /     Détail livraison :
    /     =price_line_block.ship_point_date.to_s


    / -if price_line_block.p_shipper and price_line_block.p_shipper.with_custom_date
    /   %p
    /     Date retrait :
    /     =l price_line_block.ship_custom_date

    %table.table{:style => ""}
      %tr
        %td{:style => "border:0"}
          %h3
            =qit('billing-address', 'Adresse de facturation')

          -if @p_customer_sheet.particular_bill
            %strong=@p_customer_sheet.particular_bill.organisation
            %br
            =@p_customer_sheet.particular_bill.firstname

            =@p_customer_sheet.particular_bill.name
            %br
            =@p_customer_sheet.particular_bill.address_2

            -if @p_customer_sheet.particular_bill.address_3?
              %br
              =@p_customer_sheet.particular_bill.address_3
            %br
            =@p_customer_sheet.particular_bill.cp

            =@p_customer_sheet.particular_bill.city
            %br
            =@p_customer_sheet.particular_bill.country
            %br
            %br
            =@p_customer_sheet.particular_bill.tel


        %td{:style => "border:0"}
          %h3 Adresse de livraison

          -if @p_customer_sheet.particular_bill
            %strong=@p_customer_sheet.particular_bill.organisation
            %br
            =@p_customer_sheet.particular_send.firstname

            =@p_customer_sheet.particular_send.name
            %br
            =@p_customer_sheet.particular_send.address_2

            -if @p_customer_sheet.particular_send.address_3?
              %br
              =@p_customer_sheet.particular_send.address_3
            %br
            =@p_customer_sheet.particular_send.cp

            =@p_customer_sheet.particular_send.city
            =@p_customer_sheet.particular_send.country
            %br
            %br
            =@p_customer_sheet.particular_bill.tel




    .price_line_block_recap
      %table.table
        %thead
          %tr
            / %th
            %th
              =qit('designate', 'Désignation')
            %th
              =qit('quantity', 'Quantité')
            %th
              =qit('vat', 'TVA')
            %th
              =qit('amount-excl-tax', 'Montant HT')
            %th
              =qit('amount-incl-tax', 'Montant TTC')
        %tbody
          -price_line_block.price_lines.each do |price_line|
            %tr
              / %td.td_img
              /   -if price_line.img
              /     =link_to [:public, price_line.p_product_ref.p_product] do
              /       =image_tag(price_line.img.file.square.url)
              %td
                =link_to [:public, price_line.p_product_ref.p_product] do
                  =price_line.title

              %td.numeraire
                =price_line.qte



              %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

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


        %table.table{:style => "width:auto;float:right;"}


          -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
              =qit('shipping-costs', 'Frais de port TTC')

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


          %tr
            %th
              =qit('total-incl-tax')
            %td.numeraire
              =number_to_currency price_line_block.tot_amount_ttc, :unit => price_line_block.devise_symbol


      %table.table{:style => "width:auto;"}
        %tr
          %th
            =qit('rate', 'Taux')
            %br
            =qit('vat', 'TVA')
          %th
            =qit('amount-exclu-vat-bis', 'Montant HT Net')
          %th
            =qit('amount-vat', '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



