<?php
class AwalletHistoriesController extends AdminAppController {
    public $helpers = array('Html', 'Form','Session','Paginator','Js'=> array('Jquery'));
    public $components = array('Session','Paginator','search-master.Prg');
    public $presetVars = true;
    var $paginate = array('page'=>1,'order'=>array('id'=>'desc'));
    public function beforeFilter()
    {
        parent::beforeFilter();
    }
    public function index($id=null)
    {
	$condition=$this->CustomFunction->userWisePermission($id,$this->luserId,$this->userType,$this->agencyId,'AwalletHistory.project_id','AwalletHistory.user_id');
        $conditionAwallet=$this->CustomFunction->userWisePermission($id,$this->luserId,$this->userType,$this->agencyId,'Awallet.project_id','Awallet.user_id');
        $this->Prg->commonProcess();
        $this->Paginator->settings = $this->paginate;
	
        $cond=array();
        if($id)
        $cond=array('user_id'=>$id);
        $this->Paginator->settings['conditions'] = array($this->AwalletHistory->parseCriteria($this->Prg->parsedParams()),$cond,$condition);
	$this->Paginator->settings['limit']=$this->pageLimit;
        $this->Paginator->settings['maxLimit']=$this->maxLimit;
        $this->loadModel('Awallet');
        if($cond)
        $this->set('aWallet',$this->Awallet->find('first',array('conditions'=>array($cond,$conditionAwallet))));
        else
        {
            $this->Awallet->virtualFields=array('credit'=>'SUM(credit)','debit'=>'SUM(debit)','balance'=>'SUM(balance)');
            $this->set('aWallet',$this->Awallet->find('first',array('conditions'=>array($cond,$conditionAwallet))));
        }
        $this->set('record', $this->Paginator->paginate());
	$this->set('id',$id);
	if ($this->request->is('ajax'))
        {
            $this->render('index','ajax'); // View, Layout
        }
    }
    
}
