diff --git a/backend/models/InventoryItemForm.php b/backend/models/InventoryItemForm.php index 69f4651..ff7d9f1 100644 --- a/backend/models/InventoryItemForm.php +++ b/backend/models/InventoryItemForm.php @@ -3,15 +3,12 @@ namespace backend\models; use common\models\Waste; -use /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ - Yii; use yii\base\Model; use common\models\Inventory; use yii\base\Exception; use common\models\Product; use common\models\InventoryGroup; use common\models\InventoryItem; -use yii\db\Expression; use yii\db\Query; use common\models\Procurement; use common\models\Transfer; @@ -93,8 +90,12 @@ class InventoryItemForm extends Model{ } } } - - public function save(){ + + /** + * @return bool + * @throws \Exception + */ + public function save(){ $this->loadLastInventory(); $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->inventory->created_at]); - - if ( $this->type == 'product') { $query->andWhere(['product.id_product' => $this->product->id_product]); }else{ @@ -253,8 +251,11 @@ class InventoryItemForm extends Model{ $this->last_inventory_item = $query->one(); } } - - public function read(){ + + /** + * @throws Exception + */ + public function read(){ $this->loadInventory(); @@ -264,11 +265,14 @@ class InventoryItemForm extends Model{ $this->buildProductList(); } - - public function loadInventory(){ + + /** + * @throws Exception + */ + public function loadInventory(){ $this->inventory = Inventory::findOne($this->id_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(){ diff --git a/common/config/params.php b/common/config/params.php index df281ef..4f6683b 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -61,5 +61,7 @@ return [ 'key_toggle_door_log_enabled' => false, //if key required for entry trough the door '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, ]; diff --git a/common/models/Inventory.php b/common/models/Inventory.php index aea60ec..8fadb3e 100644 --- a/common/models/Inventory.php +++ b/common/models/Inventory.php @@ -100,7 +100,6 @@ class Inventory extends \common\models\BaseFitnessActiveRecord $query = Product::find(); if ( isset($this->id_account) && is_numeric($this->id_account)){ $query->andWhere(['id_account' => $this->id_account]); - } $products = $query->all(); diff --git a/common/models/Ticket.php b/common/models/Ticket.php index 9c65928..99ad375 100644 --- a/common/models/Ticket.php +++ b/common/models/Ticket.php @@ -424,5 +424,47 @@ class Ticket extends \common\models\BaseFitnessActiveRecord public function afterDelete(){ 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); + } + + } diff --git a/frontend/views/common/_reception_ticket.php b/frontend/views/common/_reception_ticket.php index 70fd006..4997a8c 100644 --- a/frontend/views/common/_reception_ticket.php +++ b/frontend/views/common/_reception_ticket.php @@ -9,7 +9,8 @@ use yii\helpers\Url; ?> -tickets) > 0 ){ $ticket = $model->tickets[0]; @@ -36,8 +37,6 @@ if ( isset($model->card)){ echo " - "; echo Yii::$app->formatter->asDate($ticket->end); echo Html::endTag("div"); - - }else{ echo Html::beginTag("div",['class'=>"alert alert-danger", "role"=>"alert"]); echo Html::beginTag("strong",[ ]); @@ -45,6 +44,66 @@ if ( isset($model->card)){ echo Html::endTag("strong"); 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) { + ?> +