app\controllers\DashboardController::actionPerformance PHP Method

actionPerformance() public method

public actionPerformance ( )
    public function actionPerformance()
    {
        $model = new Dashboard();
        $thisyear = date('Y');
        $thismonth = date('m');
        $lastmonth = date('m', strtotime('-1 months', strtotime(date('Y-m-d'))));
        $user = Yii::$app->user->identity->id;
        $command = Yii::$app->db->createCommand("SELECT \n            SUM(IF(cashbook.type_id=1, value, 0)) as v1,\n            SUM(IF(cashbook.type_id=2, value, 0)) as v2,\n            MONTHNAME(date) as m \n            FROM cashbook WHERE user_id = {$user} AND YEAR(date) = {$thisyear} GROUP BY m ORDER BY MONTH(date)");
        $performance = $command->queryAll();
        $m = array();
        $v1 = array();
        $v2 = array();
        for ($i = 0; $i < sizeof($performance); $i++) {
            $m[] = $performance[$i]["m"];
            $v1[] = (int) $performance[$i]["v1"];
            $v2[] = abs((int) $performance[$i]["v2"]);
        }
        return $this->render('performance', ['model' => $model, 'm' => $m, 'v1' => $v1, 'v2' => $v2]);
    }