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

class Admin::PCommercialObjectMonthsController < ApplicationController
  layout "admin"
  before_action :auth_admin

  before_action :admin_space

  def admin_space
    @admin_space = "default"
  end

  def index
    @p_commercial_objective_months = PCommercialObjectMonth.all

    @p_commercial_objective_months = sort_by_sorting(@p_commercial_objective_months, "id DESC")
    respond_to do |format|
      format.html{

        params[:search][:per_page] = params[:search][:per_page] || 100
        per_page = params[:search][:per_page]
        page = (params[:page] and params[:page] != "") ? params[:page] : 1
        @p_commercial_objective_months = @p_commercial_objective_months.page(page).per(per_page)

      }
    end
  end

  def show
    @p_commercial_objective_month = PCommercialObjectMonth.find(params[:id])

  end

  def new
    @p_commercial_objective_month = PCommercialObjectMonth.new

  end

  def edit
    @p_commercial_objective_month = PCommercialObjectMonth.find(params[:id])



  end

  def create
    @p_commercial_objective_month = PCommercialObjectMonth.new(params.require(:p_commercial_objective_month).permit!)

    if @p_commercial_objective_month.save

    else
      render action: "new"

    end

  end


  def update
    @p_commercial_objective_month = PCommercialObjectMonth.find(params[:id])


    if @p_commercial_objective_month.update_attributes(params.require(:p_commercial_objective_month).permit!)

    else
     render action: "edit"

    end

  end


  def destroy
    @p_commercial_objective_month = PCommercialObjectMonth.find(params[:id])
    @p_commercial_objective_month.destroy

    # redirect_to :controller => 'p_commercial_objectives', :action => 'edit'

  end
end
