<?php

namespace frontend\controllers;

use Yii;
use common\models\Log;
use frontend\models\LogSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Card;
use common\models\TicketInstallmentRequest;
use common\models\Ticket;
use common\models\Transfer;
use common\models\Account;
use common\components\Helper;
use common\models\Sale;
use common\models\Product;
use common\models\ShoppingCart;
use common\models\Customer;
use frontend\models\LogForm;

/**
 * LogController implements the CRUD actions for Log model.
 */
class LogController extends Controller {
	public function behaviors() {
		return [
			'access' => [
				'class' => \yii\filters\AccessControl::className(),
				'only' => ['towel'],
				'rules' => [
					// allow authenticated users
					[
						'allow' => true,
						'roles' => ['@'],
					],
					// everything else is denied
				],
			],
		];
	}

	/**
	 * Lists all Log models.
	 * @param $id_card
	 * @return mixed
	 * @throws \Yii\web\NotFoundHttpException
	 */
	public function actionTowel($id_card) {
		$card = Card::findOne ( $id_card );
		
		if (! isset ( $card ))
			throw new NotFoundHttpException ( 'A bérlet nem található' );
		
		$searchModel = new LogSearch ();
		$searchModel->card = $card;
		$searchModel->customer = $card->customer;
		$dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
		
		return $this->render ( 'index', [ 
				'searchModel' => $searchModel,
				'dataProvider' => $dataProvider 
		] );
	}
	
	 
	
	/**
	 * Finds the Log model based on its primary key value.
	 * If the model is not found, a 404 HTTP exception will be thrown.
	 *
	 * @param integer $id        	
	 * @return Log the loaded model
	 * @throws NotFoundHttpException if the model cannot be found
	 */
	protected function findModel($id) {
		if (($model = Log::findOne ( $id )) !== null) {
			return $model;
		} else {
			throw new NotFoundHttpException ( 'The requested page does not exist.' );
		}
	}
}
