add frontend ticket changes
This commit is contained in:
@@ -9,9 +9,9 @@ use yii\helpers\ArrayHelper;
|
||||
class HtmlHelper{
|
||||
|
||||
|
||||
private static function mkOptions( $models, $key, $value = 'name', $options = [] ){
|
||||
public static function mkOptions( $models, $key, $value = 'name' ){
|
||||
$result = [];
|
||||
$result = ArrayHelper::map($models, $key, $value);
|
||||
$result = ArrayHelper::map( $models, $key, $value );
|
||||
return $result;
|
||||
|
||||
}
|
||||
@@ -20,23 +20,26 @@ class HtmlHelper{
|
||||
* @var $models common\models\Account[]
|
||||
* @return
|
||||
* */
|
||||
public static function mkAccountOptions( $models, $options = [] ){
|
||||
return $result = self::mkOptions($models, 'id_account');
|
||||
public static function mkAccountOptions( $models ){
|
||||
$result = HtmlHelper::mkOptions( $models, 'id_account' );
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* @var $models common\models\Discount[]
|
||||
* @return
|
||||
* */
|
||||
public static function mkDiscountOptions( $models, $options = [] ){
|
||||
return $result = self::mkOptions($models, 'id_discount');
|
||||
public static function mkDiscountOptions( $models ){
|
||||
$result = HtmlHelper::mkOptions( $models, 'id_discount' );
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var $models common\models\TicketType[]
|
||||
* @return
|
||||
* */
|
||||
public static function mkTicketTypeOptions( $models, $options = [] ){
|
||||
return $result = self::mkOptions($models, 'id_ticket_type');
|
||||
public static function mkTicketTypeOptions( $models ){
|
||||
$result = HtmlHelper::mkOptions( $models, 'id_ticket_type');
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,14 +38,24 @@ class TicketController extends Controller
|
||||
* Lists all Ticket models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
public function actionIndex($number = null)
|
||||
{
|
||||
$receptionForm = new ReceptionForm();
|
||||
$receptionForm->number = $number;
|
||||
$receptionForm->readCard();
|
||||
|
||||
|
||||
if ( !isset($receptionForm->card ) ){
|
||||
throw new NotFoundHttpException( Yii::t('frontend/ticket', 'The requested card does not exist.'));
|
||||
}
|
||||
|
||||
$searchModel = new TicketSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
$dataProvider = $searchModel->search( $receptionForm->card, Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
'receptionForm' => $receptionForm,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -75,6 +85,10 @@ class TicketController extends Controller
|
||||
|
||||
$receptionForm->readCard();
|
||||
|
||||
if ( !isset($receptionForm->card ) ){
|
||||
throw new NotFoundHttpException( Yii::t('frontend/ticket', 'The requested card does not exist.'));
|
||||
}
|
||||
|
||||
$model = new TicketCreate();
|
||||
|
||||
$discounts = Discount::read();
|
||||
@@ -89,9 +103,11 @@ class TicketController extends Controller
|
||||
$model->id_user = \Yii::$app->user->id;
|
||||
$model->status = Ticket::STATUS_ACTIVE;
|
||||
$model->usage_count = 0;
|
||||
$model->id_card = $receptionForm->card->id_card;
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_ticket]);
|
||||
Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Ticket added to customer') );
|
||||
return $this->redirect(['index', 'number' => $receptionForm->card->number]);
|
||||
} else {
|
||||
|
||||
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
|
||||
|
||||
@@ -5,10 +5,14 @@ use common\models\Ticket;
|
||||
use common\models\TicketType;
|
||||
use common\models\Account;
|
||||
use common\models\Discount;
|
||||
|
||||
use common\models\Transfer;
|
||||
|
||||
class TicketCreate extends Ticket{
|
||||
|
||||
|
||||
public $_currency;
|
||||
public $_account;
|
||||
public $_discount;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
@@ -47,7 +51,6 @@ class TicketCreate extends Ticket{
|
||||
/////////////////////
|
||||
//comment
|
||||
/////////////////////
|
||||
[['comment'], 'required'],
|
||||
[['comment'], 'string', 'max' => 255]
|
||||
];
|
||||
}
|
||||
@@ -59,18 +62,26 @@ class TicketCreate extends Ticket{
|
||||
$this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid ticket type' ));
|
||||
}
|
||||
}
|
||||
|
||||
public function validateAccount($attribute,$params){
|
||||
$acc = Account::findOne($this->id_account);
|
||||
if ( !isset($acc)) {
|
||||
$this->_account = Account::findOne($this->id_account);
|
||||
if ( !isset($this->_account )) {
|
||||
$this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid transfer' ));
|
||||
}
|
||||
}
|
||||
|
||||
public function validateDiscount($attribute,$params){
|
||||
$discount = Discount::findOne($this->id_discount);
|
||||
if ( !isset($discount)) {
|
||||
$this->_discount = Discount::findOne($this->id_discount);
|
||||
if ( !isset($this->_discount)) {
|
||||
$this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid discount' ));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
|
||||
$transfer = Transfer::createTicketTransfer($this->_account, $this->_discount, null, 1, $this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -39,14 +39,19 @@ class TicketSearch extends Ticket
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
public function search($card, $params)
|
||||
{
|
||||
$query = Ticket::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort'=> ['defaultOrder' => ['end'=>SORT_DESC]]
|
||||
]);
|
||||
|
||||
|
||||
|
||||
$query->innerJoinWith( 'card' );
|
||||
$query->andWhere( ['card.id_card' => $card->id_card ] );
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
@@ -56,7 +61,6 @@ class TicketSearch extends Ticket
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_ticket' => $this->id_ticket,
|
||||
'id_user' => $this->id_user,
|
||||
'id_ticket_type' => $this->id_ticket_type,
|
||||
'id_account' => $this->id_account,
|
||||
|
||||
@@ -66,12 +66,11 @@ function mkBtn($card, $label,$route = null ){
|
||||
<?php echo mkCustomerBtn( $card, Yii::t( 'frontend/customer' , 'Befizetések') , 'ticket/index'); ?>
|
||||
</div>
|
||||
<div class='col-md-4'>
|
||||
<?php echo Html::a(Html::tag("i","", [ 'class' => 'glyphicon glyphicon-plus' ] ) , Url::toRoute('ticket/create') , ['class' => 'btn btn-primary btn-reception'] ) ?>
|
||||
<?php echo mkCustomerBtn( $card, Html::tag("i","", [ 'class' => 'glyphicon glyphicon-plus' ] ) , 'ticket/create' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class='row'>
|
||||
<div class='col-md-12'>
|
||||
<?php //echo Html::a(Yii::t( 'frontend/customer', 'Termékeladás') , 'product/index' , ['class' => 'btn btn-primary btn-reception'] )?>
|
||||
<?php echo mkBtn($card, Yii::t( 'frontend/transfer', 'Termékeladás'), 'product/sale')?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -15,13 +15,14 @@ use kartik\widgets\DatePicker;
|
||||
|
||||
<?php
|
||||
|
||||
$accountOptions = [];
|
||||
$discountOptions= [];
|
||||
$ticketTypeOptions= [];
|
||||
|
||||
$accountOptions = HtmlHelper::mkAccountOptions($accounts);
|
||||
$discountOptions = HtmlHelper::mkDiscountOptions($discounts);
|
||||
$discountOptions = ['' => ''] + HtmlHelper::mkDiscountOptions($discounts, [ 'emptyOption' => true] );
|
||||
$ticketTypeOptions = HtmlHelper::mkTicketTypeOptions($ticketTypes);
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<div class="row" >
|
||||
@@ -36,8 +37,7 @@ use kartik\widgets\DatePicker;
|
||||
|
||||
<?= $form->field($model, 'id_discount')->dropDownList($discountOptions) ?>
|
||||
|
||||
|
||||
<?= $form->field($model, 'start')->widget(DatePicker::classname(), [
|
||||
<?= $form->field($model, 'start')->widget(DatePicker::classname(), [
|
||||
'pluginOptions' => [
|
||||
'autoclose'=>true,
|
||||
'format' => 'yyyy.mm.dd'
|
||||
|
||||
@@ -2,45 +2,71 @@
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use frontend\components\ReceptionMenuWidget;
|
||||
use frontend\components\ReceptionCardNumberWidget;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel frontend\models\TicketSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
/* @var $receptionForm frotned\models\ReceptionForm */
|
||||
|
||||
$card = $receptionForm->card;
|
||||
$customer = $receptionForm->customer;
|
||||
|
||||
$this->title = Yii::t('common/ticket', 'Tickets');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="ticket-index">
|
||||
|
||||
<div class='row'>
|
||||
<div class='col-md-3'>
|
||||
<?php echo ReceptionMenuWidget::widget( [ 'customer' => $customer, 'card' => $card] ) ?>
|
||||
</div>
|
||||
<div class='col-md-4'>
|
||||
<?php echo ReceptionCardNumberWidget::widget( [ 'customer' => $customer, 'card' =>$card, 'route' => ['customer/reception'] ] )?>
|
||||
</div>
|
||||
<div class='col-md-4'>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/ticket', 'Create Ticket'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||
<?= Html::a(Yii::t('common/ticket', 'Create Ticket'), ['create' ,'number' => $card->number ], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'id_ticket',
|
||||
'id_user',
|
||||
'id_ticket_type',
|
||||
'id_account',
|
||||
'id_discount',
|
||||
// 'start',
|
||||
// 'end',
|
||||
// 'max_usage_count',
|
||||
// 'usage_count',
|
||||
// 'status',
|
||||
// 'price_brutto',
|
||||
// 'comment',
|
||||
// 'created_at',
|
||||
// 'updated_at',
|
||||
[
|
||||
'attribute' => 'id_account',
|
||||
'value' => 'accountName'
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_ticket_type',
|
||||
'value' => 'ticketTypeName'
|
||||
],
|
||||
'start:date',
|
||||
'end:date',
|
||||
'max_usage_count',
|
||||
'usage_count',
|
||||
[
|
||||
'attribute' => 'id_user',
|
||||
'value' => 'userName'
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_discount',
|
||||
'value' => 'discountName'
|
||||
],
|
||||
'price_brutto',
|
||||
'created_at:datetime',
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' =>'{view} {update}',
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use yii\widgets\DetailView;
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Ticket */
|
||||
|
||||
$this->title = $model->id_ticket;
|
||||
$this->title = Yii::t('frontend/ticket', "Update ticket");
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket', 'Tickets'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
@@ -16,32 +16,34 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/ticket', 'Update'), ['update', 'id' => $model->id_ticket], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a(Yii::t('common/ticket', 'Delete'), ['delete', 'id' => $model->id_ticket], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => Yii::t('common/ticket', 'Are you sure you want to delete this item?'),
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ?>
|
||||
</p>
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id_ticket',
|
||||
'id_user',
|
||||
'id_ticket_type',
|
||||
'id_account',
|
||||
'id_discount',
|
||||
'start',
|
||||
'end',
|
||||
[
|
||||
'attribute' => 'id_ticket_type',
|
||||
'value' => $model->ticketTypeName,
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_account',
|
||||
'value' => $model->accountName,
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_discount',
|
||||
'value' => $model->discountName,
|
||||
],
|
||||
'start:date',
|
||||
'end:date',
|
||||
'max_usage_count',
|
||||
'usage_count',
|
||||
'status',
|
||||
'price_brutto',
|
||||
'comment',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
[
|
||||
'attribute' => 'comment',
|
||||
'type' => 'raw',
|
||||
],
|
||||
'created_at:datetime',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user