implement ticket expires-soon
This commit is contained in:
parent
4741cce196
commit
3fce2c70c2
@ -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;
|
||||
@ -94,6 +91,10 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function save(){
|
||||
|
||||
$this->loadLastInventory();
|
||||
@ -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{
|
||||
@ -254,6 +252,9 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function read(){
|
||||
|
||||
$this->loadInventory();
|
||||
@ -265,10 +266,13 @@ class InventoryItemForm extends Model{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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(){
|
||||
|
||||
@ -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,
|
||||
];
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -425,4 +425,46 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ use yii\helpers\Url;
|
||||
<style>
|
||||
</style>
|
||||
<?php
|
||||
/** @var \common\models\Ticket $ticket */
|
||||
$ticket = null;
|
||||
if ( count($model->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) {
|
||||
?>
|
||||
<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{
|
||||
echo Html::beginTag("div",['class'=>"alert alert-danger", "role"=>"alert"]);
|
||||
echo "Kártya korlátozás:";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user