diff --git a/common/models/Contract.php b/common/models/Contract.php index 2dfd0d0..3c65874 100644 --- a/common/models/Contract.php +++ b/common/models/Contract.php @@ -34,6 +34,7 @@ class Contract extends \yii\db\ActiveRecord public static $FLAG_CANCELED = 20; public static $FLAG_ACTIVE= 30; public static $FLAG_EXPIRED = 40; + public static $FLAG_CANCELED_2 = 50; public function behaviors() @@ -129,14 +130,7 @@ class Contract extends \yii\db\ActiveRecord return $this->hasOne(Discount::className(), ['id_discount' => 'id_discount']); } -// public static $STATUS_PAID = 10; -// public static $STATUS_NOT_PAID = 20; - -// public static $FLAG_DELETED = 10; -// public static $FLAG_CANCELED = 20; -// public static $FLAG_ACTIVE= 30; -// public static $FLAG_EXPIRED = 40; - + public static function statuses(){ return [ @@ -150,6 +144,7 @@ class Contract extends \yii\db\ActiveRecord return [ static::$FLAG_ACTIVE => "Aktív", static::$FLAG_CANCELED => "Felbontva", + static::$FLAG_CANCELED_2 => "Felbontva, újrakötés lehetőségével", static::$FLAG_DELETED => "Törölve", static::$FLAG_EXPIRED => "Lejárt", ]; @@ -163,6 +158,13 @@ class Contract extends \yii\db\ActiveRecord return Helper::getArrayValue(self::flags(), $flag, ""); } + public static function getFlagsDoesNotProhibitNewContract(){ + return [ + static::$FLAG_CANCELED_2, + static::$FLAG_DELETED + ]; + } + public function getStatusName() { return self::toStatusName($this->status); } @@ -190,6 +192,8 @@ class Contract extends \yii\db\ActiveRecord return $this->flag == static::$FLAG_ACTIVE; } + + public function getPriceMonthly(){ return $this->ticket->price_brutto; } diff --git a/frontend/controllers/ContractController.php b/frontend/controllers/ContractController.php index e6ca023..6dbec8d 100644 --- a/frontend/controllers/ContractController.php +++ b/frontend/controllers/ContractController.php @@ -199,8 +199,15 @@ class ContractController extends Controller { /** * EGY RÉSZLET KIFIZETÉSE */ - public function actionCancel($id) { + public function actionCancel($id,$flag) { $contract = $this->findModel ( $id ); + + if ( $flag != Contract::$FLAG_CANCELED && $flag != Contract::$FLAG_CANCELED_2){ + \Yii::error("A felmondási státusz nem található! ($flag)"); + throw new NotFoundHttpException("Az oldal nem található!"); + + } + $customer = $contract->customer; $card = $customer->card; @@ -209,7 +216,7 @@ class ContractController extends Controller { $transaction = $connection->beginTransaction (); try { - $contract->flag = Contract::$FLAG_CANCELED; + $contract->flag = $flag; $contract->save (); $requests = $contract->requests; $buntetes = 0; diff --git a/frontend/models/ContractForm.php b/frontend/models/ContractForm.php index 791ac06..9280054 100644 --- a/frontend/models/ContractForm.php +++ b/frontend/models/ContractForm.php @@ -157,7 +157,7 @@ class ContractForm extends Model { }else{ $contracts = Contract::find() ->andWhere( ['>' ,'contract.expired_at', date('Y-m-d')]) - ->andWhere(['not in' ,'contract.flag',[Contract::$FLAG_DELETED]]) + ->andWhere(['not in' ,'contract.flag', Contract::getFlagsDoesNotProhibitNewContract() ]) ->andWhere(['contract.id_customer' => $this->customer->id_customer])->all(); if ( count($contracts) > 0 ){ $this->addError( $attribute , "Már van érvényes vagy lemondott szerződés az adott időszakban"); diff --git a/frontend/views/contract/index.php b/frontend/views/contract/index.php index 991265f..df74f5b 100644 --- a/frontend/views/contract/index.php +++ b/frontend/views/contract/index.php @@ -36,6 +36,10 @@ echo Html::a( "Új szerződés",['contract/make' , 'id' => $searchModel->custom 'attribute' => 'id_user', 'value' => 'userName' ], + [ + 'attribute' => 'flag', + 'value' => "flagName" + ], // 'part_paid', // 'part_count', // 'part_required', diff --git a/frontend/views/contract/view.php b/frontend/views/contract/view.php index dc6b245..747fbec 100644 --- a/frontend/views/contract/view.php +++ b/frontend/views/contract/view.php @@ -4,6 +4,7 @@ use yii\helpers\Html; use yii\widgets\DetailView; use common\models\TicketInstallmentRequest; use frontend\components\CustomerTabWidget; +use common\models\Contract; /* @var $this yii\web\View */ /* @var $model common\models\Contract */ @@ -51,9 +52,17 @@ $this->params['breadcrumbs'][] = $this->title;
$model->id_contract], [ 'data-method' => 'post', 'class' => 'btn btn-danger']); - ?> - Szerződés felbontása esetén a már megkezdett hónapokra hónaponként 3000 Ft büntetést írunk fel a vásárló kosarába + echo Html::a("Szerződés felbontása ",['contract/cancel' , 'id' => $model->id_contract, 'flag' => Contract::$FLAG_CANCELED], [ 'data-method' => 'post', 'class' => 'btn btn-danger']); + ?>
+ Szerződés felbontása esetén a már megkezdett hónapokra hónaponként 3000 Ft büntetést írunk fel a vásárló kosarába.
+ A vendég nem köthet új szerződést a felbontott szerződés eredet lejáratáig. +
+
+ $model->id_contract , 'flag' => Contract::$FLAG_CANCELED_2], [ 'data-method' => 'post', 'class' => 'btn btn-danger']); + ?>
+ Szerződés felbontása esetén a már megkezdett hónapokra hónaponként 3000 Ft büntetést írunk fel a vásárló kosarába.
+ Ezen mód választásakor a vendégnek lehetősége lesz új szerződés kötésére a lemondott szerződés eredeti lejárati dátuma előtt!