class Admin::OrdersController < ApplicationController
  layout "admin"
  

  
  def index
    
    per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 50
    
    page = (params[:page] and params[:page] != "") ? params[:page] : 1 
    

    params[:y]= params[:y] || Time.now.year
    params[:m]= params[:m] || Time.now.month
    
    @start_date = Time.parse("#{params[:y]}-#{params[:m]}-01").beginning_of_day
    @end_date = @start_date.end_of_month.end_of_day
    
    @orders = Order.all
    
    @orders = @orders.between(@start_date, @end_date).page(page).per(per_page).order("created_at DESC").all
  end


  def show
    @order = Order.find(params[:id])
  end

  def cancel
    @order = Order.find(params[:id])
    @order.unpaid = true
    @order.unpaid_at = Time.now
    @order.save
    redirect_to :back
  end
  
  def force_pref
    @order = Order.find(params[:id])
  end
  
  def force
    @order = Order.find(params[:id])
    
    @order.paid = true
    @order.paid_at = Time.now
    @order.payment_type_id = params[:payment_type_id]

    @order.save
    if params[:coms]
      @order.after_paid(false)
    elsif
      
      @order.after_paid(true)
    end
    redirect_to [:admin, @order.annonce_account]
    
  end


  


end
