implement ticket expires-soon

This commit is contained in:
Roland Schneider 2019-01-07 07:48:28 +01:00
parent 4741cce196
commit 3fce2c70c2
5 changed files with 125 additions and 19 deletions

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

@ -61,5 +61,7 @@ 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,
]; ];

View File

@ -100,7 +100,6 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
$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]);
} }
$products = $query->all(); $products = $query->all();

View File

@ -425,4 +425,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

@ -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:";