add ticket installment

This commit is contained in:
2016-01-22 14:45:56 +01:00
parent bb5978c1df
commit a2a6b1f240
51 changed files with 1498 additions and 113 deletions

View File

@@ -162,7 +162,7 @@ class AccountStateController extends Controller {
$total += $cassaOpen->money;
$openDate = $cassaOpen->created_at;
}
$total += Transfer::readPaid($openDate, date('Y-m-d h:i:s'), \Yii::$app->user->id);
$total += Transfer::readPaid($openDate, date('Y-m-d H:i:s'), \Yii::$app->user->id);
return $total;
}

View File

@@ -21,6 +21,7 @@ use common\models\UserSoldItem;
use frontend\components\FrontendController;
use frontend\components\DefaultAccountBehavior;
use frontend\components\CassaOpenBehavior;
use frontend\models\TicketUpdate;
/**
* TicketController implements the CRUD actions for Ticket model.
@@ -38,7 +39,7 @@ class TicketController extends FrontendController
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => ['create', 'index' ],
'only' => ['create', 'index','update' ],
'rules' => [
// allow authenticated users
[
@@ -135,6 +136,21 @@ class TicketController extends FrontendController
]);
}
public function actionUpdate($id){
$model = TicketUpdate::findOne($id);
if ( !isset($model)){
throw new NotFoundHttpException('The requested page does not exist.');
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index', 'number' => $model->card->number]);
}
return $this->render('update',['model' => $model]);
}
/**
* Deletes an existing Transfer model.
* If deletion is successful, the browser will be redirected to the 'index' page.
@@ -152,12 +168,21 @@ class TicketController extends FrontendController
try {
ShoppingCart::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
UserSoldItem::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
if ( $transfer->delete() ){
\Yii::$app->session->setFlash( 'success','Bérlet törölve' );
$transaction->commit();
}else{
throw new \Exception("Failed to save");
}
// $transfer->status = Transfer::STATUS_STORNO;
// $transfer->save(false);
// $ticket->status = Ticket::STATUS_DELETED;
// $ticket->save(false);
$transfer->storno();
$transaction->commit();
\Yii::$app->session->setFlash( 'success','Bérlet törölve' );
// $transaction->commit();
// if ( $transfer->delete() ){
// \Yii::$app->session->setFlash( 'success','Bérlet törölve' );
// $transaction->commit();
// }else{
// throw new \Exception("Failed to save");
// }
} catch(Exception $e) {
$transaction->rollback();

View File

@@ -222,12 +222,13 @@ class TransferController extends Controller
try {
ShoppingCart::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
UserSoldItem::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
if ( $transfer->delete() ){
\Yii::$app->session->setFlash( 'success','Tranzakció törölve' );
$transaction->commit();
}else{
throw new \Exception("Failed to save");
}
$transfer->storno();
// if ( $transfer->delete() ){
\Yii::$app->session->setFlash( 'success','Tranzakció törölve' );
$transaction->commit();
// }else{
// throw new \Exception("Failed to save");
// }
} catch(Exception $e) {
$transaction->rollback();

View File

@@ -83,6 +83,7 @@ class TicketCreate extends Ticket{
//cart
/////////////////////
[['cart'], 'string', 'max' => 10]
];
}
@@ -91,6 +92,18 @@ class TicketCreate extends Ticket{
$type = TicketType::findOne($this->id_ticket_type);
if ( !isset($type)) {
$this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid ticket type' ));
}else{
if ( $type->isInstallment()){
$bankAccount = trim($this->customer->bank_account);
if ( !isset($bankAccount) || empty($bankAccount)){
$this->addError($attribute,"Nincs bankszámlaszám vagy érvénytelen");
return;
}
if ( !( strlen($bankAccount) == 16 || strlen($bankAccount) == 24 ) ){
$this->addError($attribute,"Vendég bankszámlaszáma nem 16 vagy 24 hosszú");
return;
}
}
}
}
@@ -108,6 +121,23 @@ class TicketCreate extends Ticket{
}
}
public function beforeSave($insert){
$result = parent::beforeSave($insert);
if ( $result ){
if ($insert){
$ticketType = TicketType::findOne($this->id_ticket_type);
if ( isset($ticketType) && $ticketType->isInstallment() ){
$this->part = 0;
$this->part_paid = 0;
$this->part_count = $ticketType->installment_count;
}else{
$this->part_count = 0;
}
}
}
return $result;
}
public function afterSave($insert, $changedAttributes){
$this->addTransfer();
$this->appendToUserCart();

View File

@@ -0,0 +1,25 @@
<?php
namespace frontend\models;
use common\models\Ticket;
class TicketUpdate extends Ticket{
public function rules(){
return [
////////////////
//status
////////////////
[['status',], 'integer'],
[['status',], 'in', 'range' => [ static ::STATUS_ACTIVE, static ::STATUS_INACTIVE ]],
];
}
}
?>

View File

@@ -36,6 +36,11 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'comment',
'format' => 'html'
],
[
'attribute' => 'status',
'value' => 'statusName',
'label' => "Státusz"
],
['class' => 'yii\grid\ActionColumn',
'template' => '{view}'

View File

@@ -0,0 +1,84 @@
<?php
use yii\widgets\DetailView;
use common\models\Ticket;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
?>
<div class="ticket-form">
<?php if ( $model->status != Ticket::STATUS_DELETED){?>
<?php
$form = ActiveForm::begin ( [ ] )
// 'id' => 'ticket_form',
;
?>
<?php
$options = Ticket::statuses ();
unset ( $options [Ticket::STATUS_DELETED] );
echo $form->field ( $model, 'status' )->dropDownList ( $options );
?>
<div class="form-group">
<?= Html::submitButton( "Módosítás", ['class' => 'btn btn-success' ]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php } else{ echo "Törölt bérlet"; }?>
</div>
<?php
$attributes = [
'id_ticket',
[
'attribute' => 'id_user',
'value' => $model->user->username
]
,
[
'attribute' => 'id_ticket_type',
'value' => $model->ticketTypeName
]
,
[
'attribute' => 'id_account',
'value' => $model->accountName
]
,
[
'attribute' => 'id_discount',
'value' => $model->discountName
]
,
'start:datetime',
'end:datetime',
'max_usage_count',
'usage_count',
// [
// 'attribute' => 'status',
// 'value' => $model->statusName
// ],
'price_brutto',
'comment:raw',
'created_at',
'updated_at'
];
if ( $model->status == Ticket::STATUS_DELETED ){
$attributes[] = [
'attribute' => 'status',
'value' => $model->statusName
];
}
?>
<?=DetailView::widget ( [ 'model' => $model,'attributes' => $attributes ] )?>

View File

@@ -6,6 +6,7 @@ use frontend\components\ReceptionMenuWidget;
use frontend\components\ReceptionCardNumberWidget;
use frontend\components\ReceptionWidget;
use yii\base\Widget;
use common\models\Ticket;
/* @var $this yii\web\View */
/* @var $searchModel frontend\models\TicketSearch */
@@ -34,7 +35,11 @@ $this->params['breadcrumbs'][] = $this->title;
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'id_ticket',
'value' => 'id_ticket',
'label' => "B. Azonosító"
],
[
'attribute' => 'id_account',
'value' => 'accountName'
@@ -51,6 +56,10 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'id_user',
'value' => 'userName'
],
[
'attribute' => 'status',
'value' => 'statusName'
],
/*
[
'attribute' => 'id_discount',
@@ -58,9 +67,31 @@ $this->params['breadcrumbs'][] = $this->title;
],
*/
'price_brutto',
'created_at:datetime',
['class' => 'yii\grid\ActionColumn',
'template' =>'{delete}',
'template' =>'{delete} {update}',
'buttons' => [
'update' => function($url, $model, $key){
return $model->status == Ticket::STATUS_DELETED ? "" : Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url,
[ 'title' => "Bérlet törlése", 'class'=>'btn btn-primary btn-xs', ]) ;
},
'delete' => function($url, $model, $key){
return $model->status == Ticket::STATUS_DELETED ? "" : Html::a('<span class="glyphicon glyphicon-trash"></span>', $url,
[ 'title' => "Bérlet módosítása", 'class'=>'btn btn-primary btn-xs', 'data-method' =>'post']) ;
},
],
// 'buttons ' => [
// 'update' =>function ($url, $model, $key){
// return "update";
// },
// 'delete' =>function ($url, $model, $key){
// return "delete";
// }
// ]
// 'template' => function($model){ return $model->status == Ticket::STATUS_DELETED ? "" : "'{delete} {update}'" ;},
],
],
]); ?>

View File

@@ -5,9 +5,7 @@ use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Ticket */
$this->title = Yii::t('common/ticket', 'Update {modelClass}: ', [
'modelClass' => 'Ticket',
]) . ' ' . $model->id_ticket;
$this->title = "Bérlet módosítása:" . ' ' . $model->id_ticket;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket', 'Tickets'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id_ticket, 'url' => ['view', 'id' => $model->id_ticket]];
$this->params['breadcrumbs'][] = Yii::t('common/ticket', 'Update');
@@ -16,7 +14,7 @@ $this->params['breadcrumbs'][] = Yii::t('common/ticket', 'Update');
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
<?= $this->render('_form_update', [
'model' => $model,
]) ?>

View File

@@ -69,13 +69,15 @@ $formatter = Yii::$app->formatter;
</div>
<div class="row">
<div class="col-md-11 text-right">
<?php echo Html::a('<span class="glyphicon glyphicon-trash"></span>Törlés', Url::toRoute(['delete','id' =>$model->id_transfer]), [
<?php
if ( $model->status != Transfer::STATUS_STORNO){
echo Html::a('<span class="glyphicon glyphicon-trash"></span>Törlés', Url::toRoute(['delete','id' =>$model->id_transfer]), [
'title' => Yii::t('yii', 'Delete'),
'data-confirm' => Yii::t('yii', 'Are you sure to delete this item?'),
'data-method' => 'post',
'class' => 'btn btn-danger',
// 'style' =>'margin-right: 12px;'
]);?>
]);}?>
</div>
</div>
</div>