class Admin::VirementsController < ApplicationController
  layout "admin"
  

  
  def index
    @virement_remise = VirementRemise.new
    @virements = Virement.order("created_at DESC").all
  end


  def show

    @virement = Virement.find(params[:id])


    
  end
  
  def valid
    @virement = Virement.find(params[:id])
    
    if @virement.customer_rib.tva and @virement.customer_rib.country == "France"
      @virement.tva = 0.2 * @virement.amount_ht
      
    else
      @virement.tva = 0.0
    end
    
    @virement.amount_ttc = @virement.amount_ht + @virement.tva
    
    @virement.confirmed = true
   
    
    @virement.save(:validate => false)
    
    #redirect_to :back
    
  end

  def edit
    @virement = Virement.find(params[:id])
  end


  def update
    @virement = Virement.find(params[:id])
    
    if @virement.update_attributes(params.require(:virement).permit!)

          
    else
      render :action => "edit" 
    end
    
  end

end
