# -*- encoding : utf-8 -*-

class Admin::ProductOrderPaymentsController < ApplicationController
	before_filter :auth_admin

	layout "admin"


	
	def new
		@product_order_payment = ProductOrderPayment.new()
    
 
    @product_order_payment.product_order_payment_langs << ProductOrderPaymentLang.new(:lang => LangSite.first.slug)
    

	end

	def edit
		@product_order_payment = ProductOrderPayment.find(params[:id])
	end
  
	

	def create
		@product_order_payment = ProductOrderPayment.new(params.require(:product_order_payment).permit!)


		if @product_order_payment.save
      self.find_product_order_payments
			flash[:notice] = "Le paiement a été ajouté."
		

		else
			render :action => "new" 
		
		end
	
	end
	

	def update
		@product_order_payment = ProductOrderPayment.find(params[:id])

		
		

		
		
		respond_to do |format|
			if @product_order_payment.update_attributes(params.require(:product_order_payment).permit!)
				
			  @product_order_payment.product_order.verify_paid_status
        
				flash[:notice] = "Le paiement a été mis à jour"
				
				format.js { 
					render :action => "update" 
        }
			
			else
				
				flash[:error] = "Le paiement n'a pas pu être mis à jour"
				
					format.html { render :action => "edit" }
					format.js { render :action => "edit" }
          
				
				
			end
		end
    
    
    
    

	end



  
end
