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

class Admin::PPaymentsController < ApplicationController
  layout "admin"
  before_filter :auth_admin

  before_filter :admin_space
  
  def admin_space
    @admin_space = "payments"
  end
  
  def index
    @p_payments = PPayment.order("created_at DESC").all

   
  end

  def show
    @p_payment = PPayment.find(params[:id])

  end

  def new
    
    
		@p_payment = PPayment.new(:p_payment_type_id => 1)
    

  end

 

  def edit
  
    
    @p_payment = PPayment.find(params[:id])
  end

  def create
    @p_payment = PPayment.new(params.require(:p_payment).permit!)


    if @p_payment.save
      @p_payment = PPayment.find(@p_payment.id)
      @p_customer = @p_payment.p_customer
    else
      render action: "new"
 
    end

  end


  def update
    @p_payment = PPayment.find(params[:id])


    if @p_payment.update_attributes(params.require(:p_payment).permit!)
      
       @p_payments = PPayment.order("created_at ASC").all
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @p_payment = PPayment.find(params[:id])
    @p_payment.destroy
    
    
  end
end
