fix move out , if usage count reached max usage count

fix gui: card number will be loaded only if form is empty
This commit is contained in:
Schneider Roland
2023-05-24 16:36:41 +02:00
parent 3d8516c50f
commit cb1b2e2d13
5 changed files with 53 additions and 24 deletions

View File

@@ -363,25 +363,8 @@ class KeyDoorManager extends BaseObject
Yii::info("$ctx->requestId: active ticket count:" . count($activeTickets));
/** @var Ticket $ticket */
$ticket = null;
if (isset($activeTickets) && count($activeTickets) > 0) {
for ( $i = 0; ($i < count($activeTickets)) && !isset($ticket); $i++){
/**@var $currentTicket Ticket **/
$currentTicket = $activeTickets[$i];
if ( $currentTicket->usage_count < $currentTicket->max_usage_count){
$ticket = $currentTicket;
}
}
}
if (!isset($ticket)) {
throw new FitnessException(
"$ctx->requestId: No active ticket found for:" . $ctx->card->number,
FitnessException::TYPE_BAD_REQUEST,
"NOT_FOUND_ACTIVE_TICKET",
$ctx
);
}
$ctx->ticket = $ticket;
Yii::info("$ctx->requestId: ticket {$ticket->id_ticket} loaded in sec " . $stopWatch->split());
// load customer
$customer = $ctx->card->customer;
@@ -400,6 +383,27 @@ class KeyDoorManager extends BaseObject
// if direction is in, check if usage count must be increased
if ($ctx->direction == DoorLog::$DIRECTION_IN) {
if (isset($activeTickets) && count($activeTickets) > 0) {
for ( $i = 0; ($i < count($activeTickets)) && !isset($ticket); $i++){
/**@var $currentTicket Ticket **/
$currentTicket = $activeTickets[$i];
if ( $currentTicket->usage_count < $currentTicket->max_usage_count){
$ticket = $currentTicket;
}
}
}
if (!isset($ticket)) {
throw new FitnessException(
"$ctx->requestId: No active ticket found for:" . $ctx->card->number,
FitnessException::TYPE_BAD_REQUEST,
"NOT_FOUND_ACTIVE_TICKET",
$ctx
);
}
$ctx->ticket = $ticket;
Yii::info("$ctx->requestId: ticket {$ticket->id_ticket} loaded in sec " . $stopWatch->split());
// Key required
if (!isset($ctx->key)) {
throw new FitnessException(
@@ -544,7 +548,26 @@ class KeyDoorManager extends BaseObject
$ctx->virtualKey->save(false);
}
// set ticket move out counter
if (isset($activeTickets) && count($activeTickets) > 0) {
for ( $i = 0; ($i < count($activeTickets)) && !isset($ticket); $i++){
/**@var $currentTicket Ticket **/
$currentTicket = $activeTickets[$i];
if ( $currentTicket->count_move_out < $currentTicket->max_usage_count && $currentTicket->count_move_out != $currentTicket->usage_count){
$ticket = $currentTicket;
}
}
}
if (!isset($ticket)) {
throw new FitnessException(
"$ctx->requestId: No active ticket found for:" . $ctx->card->number,
FitnessException::TYPE_BAD_REQUEST,
"NOT_FOUND_ACTIVE_TICKET",
$ctx
);
}
$ctx->ticket = $ticket;
$ticket->count_move_out = $ticket->usage_count;
if (!$ctx->verifyOnly) {
$ticket->save(false);

View File

@@ -24,6 +24,7 @@ use yii\web\HttpException;
* @property string $end
* @property integer $max_usage_count
* @property integer $usage_count
* @property integer $count_move_out
* @property integer $status
* @property integer $price_brutto
* @property integer $part eddig a részletig kell kifizetve lenni