Merge branch 'release/v0.1.12'

This commit is contained in:
Roland Schneider 2019-03-30 19:58:35 +01:00
commit c7538af485
12 changed files with 575 additions and 224 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,7 +243,6 @@ 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 );
@ -250,6 +253,16 @@ class ContractController extends Controller {
] ); ] );
} }
/**
* @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.
* 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

@ -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,
@ -86,7 +88,12 @@ class TicketInstallmentRequestController extends Controller
} }
public function actionAccept( $id ) /**
* @param $id
* @return \yii\web\Response
* @throws NotFoundHttpException
*/
public function actionAccept($id )
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
@ -94,19 +101,16 @@ class TicketInstallmentRequestController extends Controller
$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

@ -3,15 +3,12 @@
namespace backend\models; namespace backend\models;
use common\models\Waste; use common\models\Waste;
use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */
Yii;
use yii\base\Model; use yii\base\Model;
use common\models\Inventory; use common\models\Inventory;
use yii\base\Exception; use yii\base\Exception;
use common\models\Product; use common\models\Product;
use common\models\InventoryGroup; use common\models\InventoryGroup;
use common\models\InventoryItem; use common\models\InventoryItem;
use yii\db\Expression;
use yii\db\Query; use yii\db\Query;
use common\models\Procurement; use common\models\Procurement;
use common\models\Transfer; use common\models\Transfer;
@ -94,7 +91,11 @@ class InventoryItemForm extends Model{
} }
} }
public function save(){ /**
* @return bool
* @throws \Exception
*/
public function save(){
$this->loadLastInventory(); $this->loadLastInventory();
$this->loadLastInventoryItem(); $this->loadLastInventoryItem();
@ -162,9 +163,6 @@ class InventoryItemForm extends Model{
$query->andWhere([ '>', 'procurement.created_at' ,$this->last_inventory_item->created_at]); $query->andWhere([ '>', 'procurement.created_at' ,$this->last_inventory_item->created_at]);
} }
//$query->andWhere([ '>', 'procurement.created_at' ,$this->inventory->created_at]);
if ( $this->type == 'product') { if ( $this->type == 'product') {
$query->andWhere(['product.id_product' => $this->product->id_product]); $query->andWhere(['product.id_product' => $this->product->id_product]);
}else{ }else{
@ -254,7 +252,10 @@ class InventoryItemForm extends Model{
} }
} }
public function read(){ /**
* @throws Exception
*/
public function read(){
$this->loadInventory(); $this->loadInventory();
@ -265,10 +266,13 @@ class InventoryItemForm extends Model{
} }
public function loadInventory(){ /**
* @throws Exception
*/
public function loadInventory(){
$this->inventory = Inventory::findOne($this->id_inventory); $this->inventory = Inventory::findOne($this->id_inventory);
if ( !isset( $this->inventory) ){ if ( !isset( $this->inventory) ){
throw new Exception("Nem található a leltár objektum"); throw new Exception("Nem található a leltár ");
} }
} }
public function loadLastInventory(){ public function loadLastInventory(){

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 <?php
$statusStyle = ""; $statusStyle = "";
if ( $model['request_status'] == TicketInstallmentRequest::$STATUS_ACCEPTED || $model['request_status'] == TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL ){ if ($model['request_status'] == TicketInstallmentRequest::$STATUS_ACCEPTED || $model['request_status'] == TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL) {
$statusStyle = "accepted"; $statusStyle = "accepted";
}else if ($model['request_status'] == TicketInstallmentRequest::$STATUS_REJECTED ){ } else if ($model['request_status'] == TicketInstallmentRequest::$STATUS_REJECTED) {
$statusStyle = "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'])) {
</div> echo Html::a("Kosárba helyez", ['ticket-installment-request/put-to-cart' , 'id' => $model['request_id_ticket_installment_request']],
</div> [
</div> 'class' => 'btn btn-danger',
'data-method' => 'POST'
]
);
}
?>
</div>
</div>
</div>
</div> </div>

View File

@ -1,3 +1,7 @@
-0.1.12
- add ticket installment request reopen
- inventory no inactive products
- warning for expires soon
-0.1.11 -0.1.11
- add rest application and ge - add rest application and ge
-0.1.10 -0.1.10

View File

@ -5,7 +5,7 @@ return [
'supportEmail' => 'rocho02@gmail.com', 'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu', 'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600, 'user.passwordResetTokenExpire' => 3600,
'version' => 'v0.1.11', 'version' => 'v0.1.12',
'company' => 'movar',//gyor 'company' => 'movar',//gyor
'company_name' => "Freimann Kft.", 'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global 'product_visiblity' => 'account',// on reception which products to display. account or global
@ -61,5 +61,8 @@ return [
'key_toggle_door_log_enabled' => false, 'key_toggle_door_log_enabled' => false,
//if key required for entry trough the door //if key required for entry trough the door
'key_required' => true, 'key_required' => true,
'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_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");
@ -94,20 +94,30 @@ 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 ){
$query = Product::find(); $query = Product::find();
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,
@ -119,7 +129,8 @@ 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
{ {
@ -425,4 +427,46 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
Card::updateCardFlagTicket($this->id_card);; Card::updateCardFlagTicket($this->id_card);;
} }
/**
* @throws \Exception
*/
public function getMinutesUntilExpire(){
$end = new \DateTime( $this->end );
$today = new \DateTime();
$today->setTime(0,0);
if ( $today > $end ){
return -1;
}
$seconds = $end->getTimestamp() - $today->getTimestamp();
$minutes = $seconds /60;
return $minutes;
}
/**
* @throws \Exception
*/
public function getDaysUntilExpire(){
$minutes = $this->getMinutesUntilExpire();
$days = $minutes / 60 /24;
return $days;
}
/**
* Get free usage count.
* @return bool|int
*/
public function getOpenUsageCount(){
if ( !isset($this->max_usage_count) || $this->max_usage_count <= 0){
return false;
}
$usageCount = $this->usage_count;
if ( !isset($usageCount) ){
$usageCount = 0;
}
return max($this->max_usage_count - $usageCount,0);
}
} }

View File

@ -343,4 +343,11 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord
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);

View File

@ -10,6 +10,7 @@ use yii\helpers\Url;
<style> <style>
</style> </style>
<?php <?php
/** @var \common\models\Ticket $ticket */
$ticket = null; $ticket = null;
if ( count($model->tickets) > 0 ){ if ( count($model->tickets) > 0 ){
$ticket = $model->tickets[0]; $ticket = $model->tickets[0];
@ -36,8 +37,6 @@ if ( isset($model->card)){
echo "&nbsp;-&nbsp;"; echo "&nbsp;-&nbsp;";
echo Yii::$app->formatter->asDate($ticket->end); echo Yii::$app->formatter->asDate($ticket->end);
echo Html::endTag("div"); echo Html::endTag("div");
}else{ }else{
echo Html::beginTag("div",['class'=>"alert alert-danger", "role"=>"alert"]); echo Html::beginTag("div",['class'=>"alert alert-danger", "role"=>"alert"]);
echo Html::beginTag("strong",[ ]); echo Html::beginTag("strong",[ ]);
@ -45,6 +44,66 @@ if ( isset($model->card)){
echo Html::endTag("strong"); echo Html::endTag("strong");
echo Html::endTag("div"); echo Html::endTag("div");
} }
//// //////////////////////////////////
/// Warn if expires soon
/// ///////////////////////////////////
$propertyWarnTicketExpireInDaysCount = \Yii::$app->params['warn_ticket_expire_in_days_count'];
$propertyWarnTicketExpireInUsageCount = \Yii::$app->params['warn_ticket_expire_in_usage_count'];
$showWarningExpires = false;
// expires in days
if ( $propertyWarnTicketExpireInDaysCount > 0 ){
$warnMessageTicketExpireInDaysCountTemplate = "A bérlet már csak {day} érvényes";
$expiresInDays = $ticket->getDaysUntilExpire();
$warnMessageTicketExpire = $expiresInDays;
if ( $expiresInDays <= $propertyWarnTicketExpireInDaysCount ){
$showWarningExpires = true;
$variables = array(
'{day}' => $expiresInDays > 0 ? " $expiresInDays napig" : "ma",
);
$warnMessageTicketExpire = strtr($warnMessageTicketExpireInDaysCountTemplate, $variables);
}
}
//// //////////////////////////////////
/// Warn if open usage count is low
/// ///////////////////////////////////
$showWaringUsageCount = false;
if ($propertyWarnTicketExpireInUsageCount > 0) {
$openUsageCount = $ticket->getOpenUsageCount();
if ($openUsageCount !== false && ($propertyWarnTicketExpireInUsageCount >= $openUsageCount)) {
$showWaringUsageCount = true;
$warnMessageTicketUsageCountTemplate = "A bérleten már csak {count} alkalom van";
$variables = array(
'{count}' => $openUsageCount,
);
$warnMessageTicketUsageCount = strtr($warnMessageTicketUsageCountTemplate, $variables);
}
}
//// //////////////////////////////////
/// if any warning is there, display
/// the warning box
/// ///////////////////////////////////
if ( $showWarningExpires || $showWaringUsageCount) {
?>
<div class="alert alert-warning">
<strong>A bérlet hamarosan lejár</strong>
<?php
if ($showWarningExpires) {
echo "<br>";
echo $warnMessageTicketExpire;
}
if ( $showWaringUsageCount){
echo "<br>";
echo $warnMessageTicketUsageCount;
}
?>
</div>
<?php
}
} else{ } else{
echo Html::beginTag("div",['class'=>"alert alert-danger", "role"=>"alert"]); echo Html::beginTag("div",['class'=>"alert alert-danger", "role"=>"alert"]);
echo "Kártya korlátozás:"; echo "Kártya korlátozás:";