diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 357f19b..67d11cb 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -9,7 +9,7 @@ class AdminMenuStructure{ public $menuItems; - public function AdminMenu(){ + public function __construct(){ $this->menuItems = []; } @@ -31,7 +31,6 @@ class AdminMenuStructure{ $items = []; if (!Yii::$app->user->isGuest) { - //$today = \Yii::$app->formatter->asDate( time() ); $today = \Yii::$app->formatter->asDate( strtotime('today UTC') ); $tomorrow = \Yii::$app->formatter->asDate( ( 60 *60 *24 + time())); @@ -40,39 +39,63 @@ class AdminMenuStructure{ $tomorrowDatetime = \Yii::$app->formatter->asDatetime( strtotime('tomorrow UTC') ); - // if ( $this->can('backend.user.index')){ - $items[] = ['label' => 'Felhasználók', 'url' =>['/user/index']]; - // } + ///////////////////////////// + // Beállítások + ///////////////////////////// + $items[] = ['label' => 'Felhasználók', 'url' =>['/user/index']]; + $this->menuItems[] = ['label' => 'Beállítások', 'url' => null, + 'items' => $items + ]; + ///////////////////////////// + // Törszadatok + ///////////////////////////// + $items = []; $items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']]; $items[] = ['label' => 'Kasszák', 'url' =>['/account/index']]; $items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ]; $items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ]; $items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ]; - $items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ]; - $items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ]; +// $items[] = ['label' => 'Pénznem', 'url' => ['/currency/index'] ]; + $this->menuItems[] = ['label' => 'Törszadatok', 'url' => null, + 'items' => $items + ]; + + ///////////////////////////// + // BÉRLETEK + ///////////////////////////// + $items = []; $items[] = ['label' => 'Vendégek', 'url' => ['/customer/index'] ]; $items[] = ['label' => 'Bérletkártyák', 'url' => ['/card/index'] ]; -// $items[] = ['label' => 'Pénznem', 'url' => ['/currency/index'] ]; + $items[] = ['label' => 'Bérletek', 'url' => ['/ticket/index' , 'TicketSearch[start]' =>$today,'TicketSearch[end]' => $tomorrow ] ]; + $this->menuItems[] = ['label' => 'Bérletek/Vendégek', 'url' => null, + 'items' => $items + ]; + ///////////////////////////// + // Termékek + ///////////////////////////// + $items = []; + $items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ]; + $items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ]; + $this->menuItems[] = ['label' => 'Termékek', 'url' => null, + 'items' => $items + ]; + ///////////////////////////// + // Pénzügy + ///////////////////////////// + $items = []; $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 ] ]; + $this->menuItems[] = ['label' => 'Pénzügy', 'url' => null, + 'items' => $items + ]; - if ( count($items) > 0 ){ - $userMainMenu = ['label' => 'Beállítások', 'url' => null, - 'items' => $items - ]; - } - - if ( isset($userMainMenu)){ - $this->menuItems[] = $userMainMenu; - } } } - protected function addLoginMainMenu(){ if (Yii::$app->user->isGuest) { $mainMenuItem= ['label' => 'Login', 'url' => ['/site/login']]; diff --git a/backend/controllers/TicketController.php b/backend/controllers/TicketController.php index 9c80307..68793a6 100644 --- a/backend/controllers/TicketController.php +++ b/backend/controllers/TicketController.php @@ -11,6 +11,9 @@ use yii\filters\VerbFilter; use common\models\Discount; use common\models\TicketType; use common\models\Account; +use common\models\User; +use common\models\Customer; +use common\models\Card; /** * TicketController implements the CRUD actions for Ticket model. @@ -18,6 +21,25 @@ use common\models\Account; class TicketController extends \backend\controllers\BackendController { + + public function behaviors() + { + return [ + 'access' => [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => ['create','index','view','update','index-customer'], + 'allow' => true, + 'roles' => ['admin','employee','reception'], + ], + // everything else is denied + ], + ], + ]; + } + /** * Lists all Ticket models. * @return mixed @@ -26,12 +48,55 @@ class TicketController extends \backend\controllers\BackendController { $searchModel = new TicketSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $searchModel->searchTotals(); + + $searchModel->users = User::read(); + $searchModel->accounts = Account::read(); + $searchModel->ticketTypes = TicketType::read(); + + return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } + + + /** + * Lists all Ticket models. + * @return mixed + */ + public function actionIndexCustomer($id) + { + + $customer = Customer::findOne($id); + $card = Card::findOne($id); + + + if ( $customer == null ){ + throw new NotFoundHttpException('The requested page does not exist.'); + } + + $searchModel = new TicketSearch(); + $searchModel->id_card = $customer->id_customer_card; + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $searchModel->searchTotals(); + + $searchModel->users = User::read(); + $searchModel->accounts = Account::read(); + $searchModel->ticketTypes = TicketType::read(); + + + + return $this->render('index_customer', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'customer' => $customer, + 'card' => $card + ]); + } + /** * Displays a single Ticket model. diff --git a/backend/models/TicketSearch.php b/backend/models/TicketSearch.php index 19d5813..c71bbf5 100644 --- a/backend/models/TicketSearch.php +++ b/backend/models/TicketSearch.php @@ -6,20 +6,42 @@ use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; use common\models\Ticket; +use common\components\Helper; +use yii\db\ActiveRecord; +use yii\helpers\ArrayHelper; /** * 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; + + public $statistics; + public $statisticsTotal; + + /** * @inheritdoc */ public function rules() { 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'], + [[ 'id_user', 'id_ticket_type', 'id_account'], 'integer'], + [[ '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'] , + ]; } @@ -31,7 +53,29 @@ class TicketSearch extends Ticket // bypass scenarios() implementation in the parent class return Model::scenarios(); } + + public function attributeLabels(){ + return ArrayHelper::merge(parent::attributeLabels(), [ + 'start' => Yii::t('backend/ticket','Start of interval'), + 'end' => Yii::t('backend/ticket','End of interval'), + 'valid_in_interval' => Yii::t('backend/ticket','Valid in interval'), + 'created_in_interval' => Yii::t('backend/ticket','Created in interval'), + 'expire_in_interval' => Yii::t('backend/ticket','Expire in interval'), + ]); + } + public function afterValidate(){ + + if ( !isset($this->timestampStart)) { + $this->timestampStart ='1900-01-01'; + } + + if ( !isset($this->timestampEnd)) { + $this->timestampEnd ='3000-01-01'; + } + + } + /** * Creates data provider instance with search query applied * @@ -43,36 +87,137 @@ class TicketSearch extends Ticket { $query = Ticket::find(); + Helper::queryAccountConstraint($query, 'ticket.id_account'); + + $query->with('ticketType' ); + $query->with('user'); + $query->with('customer'); + + + $dataProvider = new ActiveDataProvider([ 'query' => $query, + 'sort' =>[ + 'defaultOrder' => ['end' => SORT_DESC], + 'attributes' => ['end'] + ] ]); $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 $query; } + $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, + 'id_card' => $this->id_card, ]); - $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; + + 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; } + + + + public function searchTotals(){ + $query = Ticket::mkStatisticQuery($this->timestampStart, $this->timestampEnd,$this->id_card); + $this->statistics = $query->all(); + + $this->statisticsTotal =[ + 'valid' => 0, + 'created' => 0, + 'created_at_money' => 0, + 'expired' => 0, + ]; + + $this->statisticsTotal['valid'] = array_sum(array_column($this->statistics, 'valid')); + $this->statisticsTotal['created'] = array_sum(array_column($this->statistics, 'created')); + $this->statisticsTotal['created_money'] = array_sum(array_column($this->statistics, 'created_money')); + $this->statisticsTotal['expired'] = array_sum(array_column($this->statistics, 'expired')); + } + + + public static function mkSearchCondition( $timestampStart, $timestampEnd, $id_user,$id_ticket_tpye,$id_account,$valid_in_interval ,$expire_in_interval,$created_in_interval ){ + $query = Ticket::find(); + + Helper::queryAccountConstraint($query, 'ticket.id_account'); + + $query->with('ticketType' ); + $query->with('user'); + $query->with('customer'); + + $query->andFilterWhere([ + 'id_user' => $id_user, + 'id_ticket_type' => $id_ticket_type, + 'id_account' => $id_account, + ]); + + $all = (!($valid_in_interval) && !($expire_in_interval) && !($created_in_interval) ) + || + ($valid_in_interval == true && $expire_in_interval == true && $created_in_interval); + + $dateConditions = []; + $start = $timestampStart; + $end = $timestampEnd; + + if( $all || $created_in_interval ){ + $dateConditions[] = Helper::queryInIntervalRule('ticket.created_at', $start, $end); + } + + if ( $all || $valid_in_interval ){ + $dateConditions[] = Helper::queryValidRule('ticket.start', 'ticket.end', $start, $end); + } + + if ( $all || $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); + } + } + } diff --git a/backend/views/customer/index.php b/backend/views/customer/index.php index db4c9e4..a4c7a25 100644 --- a/backend/views/customer/index.php +++ b/backend/views/customer/index.php @@ -2,6 +2,7 @@ use yii\helpers\Html; use yii\grid\GridView; +use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $searchModel backend\models\CustomerSearch */ @@ -24,30 +25,31 @@ $this->params['breadcrumbs'][] = $this->title; 'columns' => [ [ 'attribute' => 'customerCardNumber' , -// 'value' => 'customerCardNumber' ], -// 'id_user', -// 'id_partner_card', -// 'id_proposer', 'name', 'email:email', - // 'password', 'phone', - // 'sex', - // 'date_stundent_card_expire', - // 'birthdate', - // 'image', - // 'description', - // 'tax_number', - // 'country', - // 'zip', - // 'city', - // 'address', 'created_at:datetime', - // 'updated_at', ['class' => 'yii\grid\ActionColumn', - 'template' =>'{view}{update}' + 'template' =>'{view} {update} {ticket/index-customer}', + 'buttons' => [ + 'ticket/index-customer' => function ($url) { return Html::a( ' ', $url, [ 'title' => 'Bérletek' ] ); } + ], + 'urlCreator' =>function ($action, $model, $key, $index){ + $params = is_array($key) ? $key : ['id' => (string) $key]; + if ( $action == 'ticket/index-customer' ){ + $today = \Yii::$app->formatter->asDate( strtotime('today UTC') ); + $tomorrow = \Yii::$app->formatter->asDate( strtotime( 'tomorrow UTC' )); + + $params['TicketSearch[start]'] = $today; + $params['TicketSearch[end]'] = $tomorrow; + + } + $params[0] = $action; + + return Url::toRoute($params); + } ], ], 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'); + +?> +