diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 357f19b..8abde20 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -58,6 +58,7 @@ class AdminMenuStructure{ $items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$today,'TransferSearch[end]' => $tomorrow ] ]; $items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ]; $items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ]; + $items[] = ['label' => 'Bérletek', 'url' => ['/ticket/index' , 'TicketSearch[start]' =>$today,'TicketSearch[end]' => $tomorrow ] ]; if ( count($items) > 0 ){ $userMainMenu = ['label' => 'Beállítások', 'url' => null, diff --git a/backend/controllers/TicketController.php b/backend/controllers/TicketController.php index 9c80307..0a5a966 100644 --- a/backend/controllers/TicketController.php +++ b/backend/controllers/TicketController.php @@ -11,6 +11,7 @@ use yii\filters\VerbFilter; use common\models\Discount; use common\models\TicketType; use common\models\Account; +use common\models\User; /** * TicketController implements the CRUD actions for Ticket model. @@ -26,6 +27,12 @@ class TicketController extends \backend\controllers\BackendController { $searchModel = new TicketSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + $searchModel->users = User::read(); + $searchModel->accounts = Account::read(); + $searchModel->ticketTypes = TicketType::read(); + + return $this->render('index', [ 'searchModel' => $searchModel, diff --git a/backend/models/TicketSearch.php b/backend/models/TicketSearch.php index 19d5813..83e9662 100644 --- a/backend/models/TicketSearch.php +++ b/backend/models/TicketSearch.php @@ -6,12 +6,26 @@ use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; use common\models\Ticket; +use common\components\Helper; +use yii\db\ActiveRecord; /** * TicketSearch represents the model behind the search form about `common\models\Ticket`. */ class TicketSearch extends Ticket { + + public $timestampStart; + public $timestampEnd; + + public $users; + public $accounts; + public $ticketTypes; + + public $valid_in_interval; + public $created_in_interval; + public $expire_in_interval; + /** * @inheritdoc */ @@ -19,7 +33,10 @@ class TicketSearch extends Ticket { return [ [['id_ticket', 'id_user', 'id_ticket_type', 'id_account', 'id_discount', 'max_usage_count', 'usage_count', 'status', 'price_brutto'], 'integer'], - [['start', 'end', 'comment', 'created_at', 'updated_at'], 'safe'], + [[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + [[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + [['valid_in_interval','created_in_interval','expire_in_interval'],'boolean'] + ]; } @@ -43,35 +60,60 @@ class TicketSearch extends Ticket { $query = Ticket::find(); + Helper::queryAccountConstraint($query, 'ticket.id_account'); + + $query->with('ticketType' ); + $query->with('user'); + $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); + if (!$this->validate()) { - // uncomment the following line if you do not want to return any records when validation fails - // $query->where('0=1'); - return $dataProvider; + $query->where('0=1'); +// return $dataProvider; } $query->andFilterWhere([ - 'id_ticket' => $this->id_ticket, 'id_user' => $this->id_user, 'id_ticket_type' => $this->id_ticket_type, 'id_account' => $this->id_account, - 'id_discount' => $this->id_discount, - 'start' => $this->start, - 'end' => $this->end, - 'max_usage_count' => $this->max_usage_count, - 'usage_count' => $this->usage_count, - 'status' => $this->status, - 'price_brutto' => $this->price_brutto, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, ]); - $query->andFilterWhere(['like', 'comment', $this->comment]); + + $all = (!($this->valid_in_interval) && !($this->expire_in_interval) && !($this->created_in_interval) ) + || + ($this->valid_in_interval == true && $this->expire_in_interval == true && $this->created_in_interval); + + $dateConditions = []; + $start = $this->timestampStart; + $end = $this->timestampEnd; + Yii::info('valid all: ' .$all); + + if( $all || $this->created_in_interval ){ + $dateConditions[] = Helper::queryInIntervalRule('ticket.created_at', $start, $end); + } + + if ( $all || $this->valid_in_interval ){ + $dateConditions[] = Helper::queryValidRule('ticket.start', 'ticket.end', $start, $end); + } + + if ( $all || $this->expire_in_interval ){ + $dateConditions[] = Helper::queryExpireRule('ticket.start', 'ticket.end', $start, $end); + } + + if ( count($dateConditions) == 1 ){ + $query->andWhere($dateConditions[0]); + }else if ( count($dateConditions) > 1 ){ + $cond = ['or']; + foreach ($dateConditions as $c){ + $cond[] = $c; + } + $query->andWhere($cond); + } return $dataProvider; } diff --git a/backend/views/ticket/_search.php b/backend/views/ticket/_search.php index c89f75f..04e7bf5 100644 --- a/backend/views/ticket/_search.php +++ b/backend/views/ticket/_search.php @@ -2,12 +2,21 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; +use yii\helpers\ArrayHelper; +use kartik\widgets\DatePicker; /* @var $this yii\web\View */ /* @var $model backend\models\TicketSearch */ /* @var $form yii\widgets\ActiveForm */ ?> + 'Mind'] + ArrayHelper::map($model->ticketTypes, 'id_ticket_type', 'name'); +$accountOptions = ['' => 'Mind'] + ArrayHelper::map($model->accounts, 'id_account', 'name'); +$userOptions = ['' => 'Mind'] + ArrayHelper::map($model->users, 'id', 'username'); + +?> +