Your IP : 216.73.216.124


Current Path : /var/www/html/crm/controllers/
Upload File :
Current File : /var/www/html/crm/controllers/RiderController.php

<?php

namespace app\controllers;

use Yii;
use app\models\Rider;
use app\models\RiderSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use app\models\StockDelivery;
use app\models\StockDeliverySearch;

/**
 * RiderController implements the CRUD actions for Rider model.
 */
class RiderController extends Controller {

    public $menu_id = 84;

    /**
     * {@inheritdoc}
     */
    public function behaviors() {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all Rider models.
     * @return mixed
     */
    public function actionIndex($year = '') {
        Url::remember();
        if (empty($year))
            $year = date('Y');
        $searchModel = new RiderSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        return $this->render('index', [
                    'searchModel' => $searchModel,
                    'dataProvider' => $dataProvider,
                    'menu_id' => $this->menu_id,
                    'year' => $year
        ]);
    }

    public function actionIndex2($year, $type = '', $rider_id = '') {
        Url::remember();
        $modelRider = $this->findModel($rider_id);
        $searchModel = new StockDeliverySearch();
        $searchModel->rider_id = $rider_id;
        $searchModel->search_year = $year;
        $dataProvider = $searchModel->searchforrider(Yii::$app->request->queryParams, $type);
        return $this->render('index2', [
                    'searchModel' => $searchModel,
                    'dataProvider' => $dataProvider,
                    'menu_id' => $this->menu_id,
                    'modelRider' => $modelRider,
                    'year' => $year
        ]);
    }

    /**
     * Displays a single Rider model.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($id) {
        return $this->render('view', [
                    'model' => $this->findModel($id),
        ]);
    }

    /**
     * Creates a new Rider model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate() {
        $model = new Rider();
        $model->scenario = 'managerider';
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $this->getView()->registerJs("swal.fire({position: 'center-center',type: 'success',title: 'Data has been saved',showConfirmButton: false,timer: 2000,}).then(function(result){window.location = '" . Url::toRoute('rider/index') . "';});");
        }
        return $this->render('create', ['model' => $model, 'menu_id' => $this->menu_id]);
    }

    /**
     * Updates an existing Rider model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($id) {
        $model = $this->findModel($id);
        $model->scenario = 'managerider';
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $this->getView()->registerJs("swal.fire({position: 'center-center',type: 'success',title: 'Data has been saved',showConfirmButton: false,timer: 2000,}).then(function(result){window.location = '" . Url::toRoute('rider/index') . "';});");
        }

        return $this->render('update', ['model' => $model, 'menu_id' => $this->menu_id]);
    }

    /**
     * Deletes an existing Rider model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionDelete() {
        if (($model = Rider::findOne($_POST['id'])) !== null) {
            if ($model->delete())
                return 'success';
        }
    }

    /**
     * Finds the Rider model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Rider the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id) {
        if (($model = Rider::findOne($id)) !== null) {
            return $model;
        }

        throw new NotFoundHttpException('The requested page does not exist.');
    }

}