<?php



class SettlementreportController extends Controller
{



    public function accessRules()
    {



        return array(

            array(

                'allow', // allow all users to perform 'index' and 'view' actions

                'actions' => array('login', 'error', 'logout'),

                'users' => array('*'),

            ),

            array(

                'allow', // allow authenticated user to perform 'create' and 'update' actions

                'actions' => array(

                    'Index',
                    'PrintPurchaseOrderReport'
                ),

                'expression' => '$user->isMember()',

            ),

            array(

                'deny', // deny all users

                'users' => array('*'),

            ),

        );

    }



    public function filters()
    {



        return array(

            'accessControl', // perform access control for CRUD operations

        );

    }



    public function actionIndex()
    {  
        $user_id   = (int) Yii::app()->user->id; 
        $modeluser = User::model()->findByPk($user_id);

        if ($modeluser->user_group_id != 1) { 
            $this->redirect(Yii::app()->baseUrl . '/index.php');
            Yii::app()->end();
        }

            $this->render('index');
        
    }

    public function actionPrintPurchaseOrderReport()
    {
        $model = new Expense();

        $from_date = date('01/m/Y');
        $to_date   =  date('d/m/Y');

        Yii::app()->clientScript->scriptMap = array(
            '*.js' => false,
            '*.min.js' => false,
            '*.css' => false
        );

        $this->renderPartial(
            '//settlementreport/print_settlement_list',
            array(
                'model' => $model,
                'from_date' => $from_date,
                'to_date' => $to_date
            ),
            false, 
            true  
        );
    }

}
