implement feature 'put to cart ticket installment request'

This commit is contained in:
Roland Schneider 2019-03-26 07:29:47 +01:00
parent 3fce2c70c2
commit 8de73c0585
9 changed files with 444 additions and 203 deletions

View File

@ -0,0 +1,162 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: rocho
* Date: 2019.03.19.
* Time: 18:04
*/
namespace backend\components;
use common\models\Contract;
use common\models\ShoppingCart;
use common\models\Ticket;
use common\models\TicketInstallmentRequest;
use common\models\Transfer;
use yii\web\NotFoundHttpException;
class ContractManager
{
/**
* $STATUS_PENDING nothing to do
* $STATUS_MARKED_TO_SEND nothing to do, automatic purchase in progress
* $STATUS_SENT nothing to do , automatic purchase in progress
* $STATUS_CANCELED we can mark it as accepted_manual, and put it back to cart. TODO: put it to pending state
* $STATUS_REJECTED automatic purchase was rejected, accept manual
* $STATUS_ACCEPTED nothing to do, automatic purchase was ok
* $STATUS_ACCEPTED_MANUAL this we can put back to cart
* @param $id_ticket_installment_request
* @throws NotFoundHttpException
* @throws \Throwable
*/
public function openRequestAndPutItItoCart($id_ticket_installment_request)
{
$request = TicketInstallmentRequest::findOne(['id_ticket_installment_request' => $id_ticket_installment_request]);
if (!isset($request)) {
throw new NotFoundHttpException("ticket_installment_request not found #" . $id_ticket_installment_request);
}
// if status does not support open, return
if (!(
$request->status == TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL
|| $request->status == TicketInstallmentRequest::$STATUS_CANCELED
|| $request->status == TicketInstallmentRequest::$STATUS_REJECTED
)
) {
$this->info("request can't be opened with status " . TicketInstallmentRequest::toStatusName($request->status));
return;
}
$contract = Contract::findOne($request->id_contract);
if (!isset($contract)) {
throw new NotFoundHttpException("contract not found #" . $id_ticket_installment_request);
}
$this->openTicketInstallmentRequest($contract, $request);
$this->putToCart($contract, $request);
}
/**
* If status is
* TicketInstallmentRequest::$STATUS_ACCEPTED: nothing to do, automatic purchase was successful
* TicketInstallmentRequest::$STATUS_PENDING: nothing to do, automatic purchase was successful
* TicketInstallmentRequest::$STATUS_MARKED_TO_SEND: nothing to do, automatic purchase was successful
* TicketInstallmentRequest::$STATUS_SENT: nothing to do, automatic purchase was successful
* TicketInstallmentRequest::$STATUS_SENT: nothing to do, automatic purchase was successful
*
* @param $contract \common\models\Contract
* @param $part \common\models\TicketInstallmentRequest
* @throws \Exception
* @throws \Throwable
*/
public function openTicketInstallmentRequest($contract, $part)
{
$statusChanged = false;
if ($part->status == TicketInstallmentRequest::$STATUS_CANCELED) {
$part->status = TicketInstallmentRequest::$STATUS_PENDING;
$part->request_processed_at = null;
$statusChanged = true;
}
if ($part->status == TicketInstallmentRequest::$STATUS_REJECTED) {
$part->status = TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL;
$statusChanged = true;
}
if ($statusChanged) {
$part->save(false);
if (!$contract->isFlagActive()) {
$contract->flag = Contract::$FLAG_ACTIVE;
$contract->save(false);
}
}
}
/**
* @param $contract
* @param $part
* @throws \Exception
*/
private function putToCart($contract, $part)
{
/** @var \common\models\Ticket $ticket */
$ticket = Ticket::findOne(['id_ticket' => $part->id_ticket]);
if (isset($ticket)) {
$this->info("Ticket found: " . $ticket->id_ticket . "/" . $ticket->ticketType->name);
// inactivate ticket
if ($ticket->status != Ticket::STATUS_INACTIVE) {
$ticket->status = Ticket::STATUS_INACTIVE;
$ticket->save(false);
}
// set transfer status to not paid
/** @var \common\models\Transfer $transfer */
$transfer = $ticket->transfer;
if ($transfer->status != Transfer::STATUS_NOT_PAID) {
// clean up transfer paid status
$statusOriginal = $transfer->status;
$transfer->status = Transfer::STATUS_NOT_PAID;
$transfer->paid_at = null;
$transfer->paid_by = null;
$transfer->payment_method = null;
$transfer->save(false);
$this->info("Restore transfer: ");
$this->info($transfer->id_transfer);
$this->info(Transfer::toStatusName($statusOriginal) . "->" . Ticket::toStatusName($transfer->status));
}
// check shopping cart
$cart = ShoppingCart::findOne(['id_transfer' => $transfer->id_transfer]);
// put transfer into cart if it is not there
if (!isset($cart)) {
$cart = new ShoppingCart();
$cart->id_customer = $contract->customer->id_customer;
$cart->id_transfer = $transfer->id_transfer;
if (!$cart->save(false)) {
/** @noinspection SpellCheckingInspection */
$E_FAILED_TO_SAVE = "Vendég kosár hozzárendelés sikertelen!";
\Yii::error($E_FAILED_TO_SAVE);
throw new \Exception($E_FAILED_TO_SAVE);
}
}
}
}
private function info($message)
{
\Yii::info($message);
}
}

View File

@ -2,15 +2,14 @@
namespace backend\controllers; namespace backend\controllers;
use backend\components\ContractManager;
use Yii; use Yii;
use common\models\Contract; use common\models\Contract;
use backend\models\ContractSearch; use backend\models\ContractSearch;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use backend\models\ContractCustomerSearch; use backend\models\ContractCustomerSearch;
use common\models\Customer; use common\models\Customer;
use yii\db\Query;
use backend\models\ContractRequestSearch; use backend\models\ContractRequestSearch;
use common\models\TicketInstallmentRequest; use common\models\TicketInstallmentRequest;
use common\models\Ticket; use common\models\Ticket;
@ -64,6 +63,7 @@ class ContractController extends Controller {
/** /**
* Lists all Contract models. * Lists all Contract models.
* *
* @param $id
* @return mixed * @return mixed
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
@ -197,17 +197,21 @@ class ContractController extends Controller {
], [ ], [
'id_contract' => $model->id_contract 'id_contract' => $model->id_contract
] ); ] );
$ticket = Ticket::find ()->andWhere ( [
/** @var \common\models\Ticket $ticket */
$ticket = Ticket::find ()->andWhere ( [
'id_contract' => $model->id_contract 'id_contract' => $model->id_contract
] )->one (); ] )->one ();
$transfer = Transfer::find ()->andWhere ( [
/** @var \common\models\Transfer $transfer */
$transfer = Transfer::find ()->andWhere ( [
'type' => Transfer::TYPE_TICKET 'type' => Transfer::TYPE_TICKET
] )->andWhere ( [ ] )->andWhere ( [
'id_object' => $ticket->id_ticket 'id_object' => $ticket->id_ticket
] )->one (); ] )->one ();
$transfer->storno (); $transfer->storno();
$tx->commit (); $tx->commit ();
// $tx->rollBack(); // $tx->rollBack();
@ -239,8 +243,7 @@ class ContractController extends Controller {
'contract' => $contract 'contract' => $contract
] ); ] );
// $searchModel->contract = $contract;
$dataProvider = $searchModel->search ( Yii::$app->request->queryParams ); $dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
return $this->render ( 'details', [ return $this->render ( 'details', [
@ -249,6 +252,16 @@ class ContractController extends Controller {
'dataProvider' => $dataProvider 'dataProvider' => $dataProvider
] ); ] );
} }
/**
* @param $id
* @throws NotFoundHttpException
* @throws \Throwable
*/
public function actionRequestToCart($id){
$contractManager = new ContractManager();
$contractManager->openRequestAndPutItItoCart($id);
}
/** /**
* Finds the Contract model based on its primary key value. * Finds the Contract model based on its primary key value.

View File

@ -2,9 +2,11 @@
namespace backend\controllers; namespace backend\controllers;
use backend\components\ContractManager;
use Yii; use Yii;
use common\models\TicketInstallmentRequest; use common\models\TicketInstallmentRequest;
use backend\models\TicketInstallmentRequestSearch; use backend\models\TicketInstallmentRequestSearch;
use yii\helpers\Url;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
@ -58,7 +60,7 @@ class TicketInstallmentRequestController extends Controller
{ {
$searchModel = new TicketInstallmentRequestSearch(); $searchModel = new TicketInstallmentRequestSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
Url::remember('',"ticket-installment-request/index");
return $this->render('index', [ return $this->render('index', [
'searchModel' => $searchModel, 'searchModel' => $searchModel,
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
@ -84,29 +86,31 @@ class TicketInstallmentRequestController extends Controller
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
]); ]);
} }
public function actionAccept( $id ) /**
* @param $id
* @return \yii\web\Response
* @throws NotFoundHttpException
*/
public function actionAccept($id )
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
if ( !$model->isStatusAccepted() ){ if ( !$model->isStatusAccepted() ){
$model->applyStatus(TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL,true); $model->applyStatus(TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL,true);
\Yii::$app->session->setFlash('success',"Megbízás teljesítve"); \Yii::$app->session->setFlash('success',"Megbízás teljesítve");
} }
// else{
// }
// echo "asdff";
return $this->redirect(['ticket-installment-request/view', return $this->redirect(['ticket-installment-request/view',
'id' => $model->id_ticket_installment_request, 'id' => $model->id_ticket_installment_request,
]); ]);
} }
/** /**
* Lists pending TicketInstallmentRequest models. * Lists pending TicketInstallmentRequest models.
* @return mixed * @return mixed
* @throws \Exception
*/ */
public function actionDownloadGiro() public function actionDownloadGiro()
{ {
@ -132,6 +136,7 @@ class TicketInstallmentRequestController extends Controller
* Displays a single TicketInstallmentRequest model. * Displays a single TicketInstallmentRequest model.
* @param integer $id * @param integer $id
* @return mixed * @return mixed
* @throws NotFoundHttpException
*/ */
public function actionView($id) public function actionView($id)
{ {
@ -163,6 +168,7 @@ class TicketInstallmentRequestController extends Controller
* If update is successful, the browser will be redirected to the 'view' page. * If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id * @param integer $id
* @return mixed * @return mixed
* @throws NotFoundHttpException
*/ */
public function actionUpdate($id) public function actionUpdate($id)
{ {
@ -182,6 +188,8 @@ class TicketInstallmentRequestController extends Controller
* If deletion is successful, the browser will be redirected to the 'index' page. * If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id * @param integer $id
* @return mixed * @return mixed
* @throws NotFoundHttpException
* @throws \yii\db\StaleObjectException
*/ */
public function actionDelete($id) public function actionDelete($id)
{ {
@ -192,10 +200,23 @@ class TicketInstallmentRequestController extends Controller
public function actionTest( ) public function actionTest( )
{ {
return $this->render('test'); return $this->render('test');
} }
/**
* @param $id
* @return string
* @throws NotFoundHttpException
* @throws \Throwable
*/
public function actionPutToCart($id )
{
$contractManager = new ContractManager();
$contractManager->openRequestAndPutItItoCart($id);
return $this->redirect( Url::previous("ticket-installment-request/index"));
}
/** /**
* Finds the TicketInstallmentRequest model based on its primary key value. * Finds the TicketInstallmentRequest model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.

View File

@ -1,181 +1,192 @@
<?php <?php /** @noinspection PhpUnhandledExceptionInspection */
use common\models\TicketInstallmentRequest; use common\models\TicketInstallmentRequest;
use common\models\Ticket; use common\models\Ticket;
use yii\helpers\Html; use yii\helpers\Html;
?>
<?php
$statusStyle = "";
if ( $model['request_status'] == TicketInstallmentRequest::$STATUS_ACCEPTED || $model['request_status'] == TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL ){
$statusStyle = "accepted";
}else if ($model['request_status'] == TicketInstallmentRequest::$STATUS_REJECTED ){
$statusStyle = "rejected";
}
?> ?>
<?php
$statusStyle = "";
if ($model['request_status'] == TicketInstallmentRequest::$STATUS_ACCEPTED || $model['request_status'] == TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL) {
$statusStyle = "accepted";
} else if ($model['request_status'] == TicketInstallmentRequest::$STATUS_REJECTED) {
$statusStyle = "rejected";
}
?>
<!--suppress CssUnusedSymbol -->
<style> <style>
.accepted table td.status { .accepted table td.status {
background-color: green; background-color: green;
} }
.rejected table td.status {
background-color: #dd4b39; .rejected table td.status {
} background-color: #dd4b39;
}
</style> </style>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<div class="request-view <?= $statusStyle ?>"> <div class="request-view <?= $statusStyle ?>">
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th> <th>
Megbízás azonosító Megbízás azonosító
</th> </th>
<td> <td>
<?php echo "".$model['request_id_ticket_installment_request'];?> <?php echo "" . $model['request_id_ticket_installment_request']; ?>
</td> </td>
<th> <th>
Megbízás státusza Megbízás státusza
</th> </th>
<td class="status"> <td class="status">
<?php echo TicketInstallmentRequest::toStatusName( $model['request_status'] );?> <?php echo TicketInstallmentRequest::toStatusName($model['request_status']); ?>
</td> </td>
<th> <th>
Megbízás összege Megbízás összege
</th> </th>
<td> <td>
<?php echo $model['request_money'] ." Ft";?> <?php echo $model['request_money'] . " Ft"; ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<th> <th>
Megbízás esedékességének dátuma Megbízás esedékességének dátuma
</th> </th>
<td> <td>
<?php echo \Yii::$app->formatter->asDatetime( $model['request_request_target_time_at'] );?> <?php echo \Yii::$app->formatter->asDatetime($model['request_request_target_time_at']); ?>
</td> </td>
<th> <th>
Megbízás elindításának ideje Megbízás elindításának ideje
</th> </th>
<td> <td>
<?php echo \Yii::$app->formatter->asDatetime( $model['request_sent_at'] );?> <?php echo \Yii::$app->formatter->asDatetime($model['request_sent_at']); ?>
</td> </td>
<th> <th>
Megbízás feldoglozásának ideje Megbízás feldoglozásának ideje
</th> </th>
<td> <td>
<?php echo \Yii::$app->formatter->asDatetime( $model['request_processed_at'] );?> <?php echo \Yii::$app->formatter->asDatetime($model['request_processed_at']); ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<th> <th>
Megbízás prioritása Megbízás prioritása
</th> </th>
<td> <td>
<?php echo $model['request_priority'] ;?> <?php echo $model['request_priority']; ?>
</td> </td>
<th> <th>
Köteg azonosító Köteg azonosító
</th> </th>
<td> <td>
<?php echo $model['ugiro_id_ugiro'] ;?> <?php echo $model['ugiro_id_ugiro']; ?>
</td> </td>
<th> <th>
Szerződés azonosító Szerződés azonosító
</th> </th>
<td> <td>
<?php echo $model['request_id_contract'] ;?> <?php echo $model['request_id_contract']; ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<th> <th>
Vendég azonosító Vendég azonosító
</th> </th>
<td> <td>
<?php echo "". $model['customer_id_customer'];?> <?php echo "" . $model['customer_id_customer']; ?>
</td> </td>
<th> <th>
Vendég neve Vendég neve
</th> </th>
<td> <td>
<?php echo $model['customer_name'];?> <?php echo $model['customer_name']; ?>
</td> </td>
<th> <th>
Kártyaszám Kártyaszám
</th> </th>
<td> <td>
<?php echo $model['card_number'];?> <?php echo $model['card_number']; ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<th> <th>
Bérlet azonosító Bérlet azonosító
</th> </th>
<td> <td>
<?php echo "". $model['ticket_id_ticket'];?> <?php echo "" . $model['ticket_id_ticket']; ?>
</td> </td>
<th> <th>
Bérlet típus Bérlet típus
</th> </th>
<td> <td>
<?php echo $model['ticket_type_name'];?> <?php echo $model['ticket_type_name']; ?>
</td> </td>
<th> <th>
Bérlet státusza Bérlet státusza
</th> </th>
<td> <td>
<?php echo Ticket::toStatusName( $model['ticket_status'] );?> <?php echo Ticket::toStatusName($model['ticket_status']); ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<th> <th>
Bérlet érvényességének kezdete Bérlet érvényességének kezdete
</th> </th>
<td> <td>
<?php echo \Yii::$app->formatter->asDate( $model['ticket_start'] ) ;?> <?php echo \Yii::$app->formatter->asDate($model['ticket_start']); ?>
</td> </td>
<th> <th>
Bérlet érvényességének vége Bérlet érvényességének vége
</th> </th>
<td> <td>
<?php echo \Yii::$app->formatter->asDate( $model['ticket_end'] ) ;?> <?php echo \Yii::$app->formatter->asDate($model['ticket_end']); ?>
</td> </td>
<th> <th>
</th> </th>
<td> <td>
</td> </td>
</tr> </tr>
<tr> <tr>
<th> <th>
Tétel sorszám Tétel sorszám
</th> </th>
<td> <td>
<?php echo ( $model['request_number'] ) ;?> <?php echo($model['request_number']); ?>
</td> </td>
<th> <th>
</th> </th>
<td> <td>
</td> </td>
<th> <th>
</th> </th>
<td> <td>
</td> </td>
</tr> </tr>
</table> </table>
<div > <div>
<?php <?php
if ( !empty( $model['ugiro_id_ugiro'] )){ if (!empty($model['ugiro_id_ugiro'])) {
echo Html::a("Köteg",['ugiro/view', 'id' => $model['ugiro_id_ugiro']] ,[ 'class' => 'btn btn-primary']); echo Html::a("Köteg", ['ugiro/view', 'id' => $model['ugiro_id_ugiro']], ['class' => 'btn btn-primary']);
} }
echo Html::a("Megbízás részletek",['ticket-installment-request/view', 'id' => $model['request_id_ticket_installment_request']] ,[ 'class' => 'btn btn-primary']); echo Html::a("Megbízás részletek", ['ticket-installment-request/view', 'id' => $model['request_id_ticket_installment_request']], ['class' => 'btn btn-primary']);
if ( !empty( $model['ticket_id_ticket'] )){ if (!empty($model['ticket_id_ticket'])) {
echo Html::a("Szerződés megbízásai",['ticket-installment-request/index', 'TicketInstallmentRequestSearch[id_contract]' => $model['request_id_contract']] ,[ 'class' => 'btn btn-primary']); echo Html::a("Szerződés megbízásai", ['ticket-installment-request/index', 'TicketInstallmentRequestSearch[id_contract]' => $model['request_id_contract']], ['class' => 'btn btn-primary']);
} }
?> if (TicketInstallmentRequest::canBePutToCustomerCart($model['request_status'])) {
echo Html::a("Kosárba helyez", ['ticket-installment-request/put-to-cart' , 'id' => $model['request_id_ticket_installment_request']],
[
'class' => 'btn btn-danger',
'data-method' => 'POST'
]
);
}
?>
</div>
</div>
</div>
</div> </div>
</div>
</div>
</div>

View File

@ -64,4 +64,5 @@ return [
'ticket_type_door_allowed_check_on' => false, 'ticket_type_door_allowed_check_on' => false,
'warn_ticket_expire_in_days_count' => 3, 'warn_ticket_expire_in_days_count' => 3,
'warn_ticket_expire_in_usage_count' => 3, 'warn_ticket_expire_in_usage_count' => 3,
'inventory.products.only.active' => true
]; ];

View File

@ -71,7 +71,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
} }
public function validateOnlyClosed($attribute,$params){ public function validateOnlyClosed( ){
$opened = Inventory::find()->andWhere(['status' => Inventory::$STATUS_OPEN])->all(); $opened = Inventory::find()->andWhere(['status' => Inventory::$STATUS_OPEN])->all();
if ( count($opened) > 0 ){ if ( count($opened) > 0 ){
$this->addError("name","Kérem előbb zárjon le minden másik leltárt"); $this->addError("name","Kérem előbb zárjon le minden másik leltárt");
@ -93,7 +93,12 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
] ]
], parent::behaviors()); ], parent::behaviors());
} }
/**
* @param $insert
* @param $changedAttributes
* @throws \Exception
*/
public function afterSave($insert, $changedAttributes){ public function afterSave($insert, $changedAttributes){
if ( $insert ){ if ( $insert ){
@ -101,12 +106,18 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
if ( isset($this->id_account) && is_numeric($this->id_account)){ if ( isset($this->id_account) && is_numeric($this->id_account)){
$query->andWhere(['id_account' => $this->id_account]); $query->andWhere(['id_account' => $this->id_account]);
} }
if ( \Yii::$app->params['inventory.products.only.active']) {
$query->andWhere( ['status' => Product::STATUS_ACTIVE] );
}
$products = $query->all(); $products = $query->all();
$inventoryGroups = InventoryGroup::find()->all(); $inventoryGroups = InventoryGroup::find()->all();
foreach ($products as $product){ /** @var \common\models\Product $product */
foreach ($products as $product){
$form = new InventoryItemForm( $form = new InventoryItemForm(
[ [
'inventory' => $this, 'inventory' => $this,
@ -117,8 +128,9 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
); );
$form->save(); $form->save();
} }
foreach ($inventoryGroups as $group){ /** @var \common\models\InventoryGroup $group */
foreach ($inventoryGroups as $group){
$form = new InventoryItemForm( $form = new InventoryItemForm(
[ [
'inventory' => $this, 'inventory' => $this,

View File

@ -36,6 +36,8 @@ use common\components\Helper;
* *
* @property \common\models\Card card * @property \common\models\Card card
* @property \common\models\Ticket transfer * @property \common\models\Ticket transfer
* @property \common\models\TicketType ticketType
* @property \common\models\Discount discount
*/ */
class Ticket extends \common\models\BaseFitnessActiveRecord class Ticket extends \common\models\BaseFitnessActiveRecord
{ {

View File

@ -342,5 +342,12 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord
public function getStatusName(){ public function getStatusName(){
return static::toStatusName($this->status); return static::toStatusName($this->status);
} }
public static function canBePutToCustomerCart($status){
return $status == TicketInstallmentRequest::$STATUS_CANCELED
||
$status == TicketInstallmentRequest::$STATUS_REJECTED
||
$status == TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL;
}
} }

View File

@ -2,6 +2,7 @@
namespace console\controllers; namespace console\controllers;
use backend\components\ContractManager;
use common\models\Card; use common\models\Card;
use common\models\Contract; use common\models\Contract;
use common\models\Customer; use common\models\Customer;
@ -15,6 +16,17 @@ use yii\console\Exception;
class ContractController extends Controller class ContractController extends Controller
{ {
/**
* @param $requestId
* @throws \Throwable
* @throws \yii\web\NotFoundHttpException
*/
public function actionRequestToCart($requestId){
$contractManager = new ContractManager();
$contractManager->openRequestAndPutItItoCart($requestId);
}
/** /**
* @param $cardNumber * @param $cardNumber
* @throws Exception * @throws Exception
@ -84,15 +96,15 @@ class ContractController extends Controller
); );
} else if ($part->isStatusAccepted()) { } else if ($part->isStatusAccepted()) {
$this->info("loading ticket: #" .$part->id_ticket); $this->info("loading ticket: #" .$part->id_ticket);
/** @var \common\models\Ticket $ticket */
$ticket = null; $ticket = null;
try{ try {
/** @var \common\models\Ticket $ticket */ $ticket = Ticket::findOne(['id_ticket' => $part->id_ticket]);
// $ticket = Ticket::findOne(['id_ticket' => $part->id_ticket]);
}catch (\Throwable $e){ }catch (\Throwable $e){
\Yii::info("Failed to load ticket: " . $e->getMessage()); \Yii::info("Failed to load ticket: " . $e->getMessage());
} }
if (isset($ticket)) { if (isset($ticket)) {
$this->info("Ticket found: " . $ticket->id_ticket . "/" . $ticket->ticetType->name); $this->info("Ticket found: " . $ticket->id_ticket . "/" . $ticket->ticketType->name);
if ($ticket->status == Ticket::STATUS_DELETED) { if ($ticket->status == Ticket::STATUS_DELETED) {
$ticket->status = Ticket::STATUS_ACTIVE; $ticket->status = Ticket::STATUS_ACTIVE;
$ticket->save(false); $ticket->save(false);
@ -148,4 +160,4 @@ class ContractController extends Controller
echo $msg . "\n"; echo $msg . "\n";
} }
} }