handle departure cancellation after checkin
This commit is contained in:
parent
a1865fa69e
commit
cc7439dd5e
4 changed files with 90 additions and 1 deletions
|
@ -2684,6 +2684,10 @@ sub startup {
|
|||
my $db = $opt{db} //= $self->pg->db;
|
||||
my $min_count = $opt{min_count} // 3;
|
||||
|
||||
if ( $opt{destination_name} ) {
|
||||
return ( $opt{destination_name} );
|
||||
}
|
||||
|
||||
my $dest_id = $opt{eva} // $self->get_latest_dest_id(%opt);
|
||||
|
||||
if ( not $dest_id ) {
|
||||
|
@ -2730,6 +2734,9 @@ sub startup {
|
|||
if ( $use_history & 0x01 ) {
|
||||
$eva = $opt{eva};
|
||||
}
|
||||
elsif ( $opt{destination_name} ) {
|
||||
$eva = $opt{eva};
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( $use_history & 0x02 ) {
|
||||
|
@ -3357,6 +3364,38 @@ sub startup {
|
|||
}
|
||||
)->expand->hash;
|
||||
|
||||
my $latest_cancellation = $db->select(
|
||||
'journeys_str',
|
||||
'*',
|
||||
{
|
||||
user_id => $uid,
|
||||
},
|
||||
{
|
||||
order_by => { -desc => 'journey_id' },
|
||||
limit => 1
|
||||
}
|
||||
)->expand->hash;
|
||||
|
||||
if ( $latest_cancellation and $latest_cancellation->{cancelled} ) {
|
||||
if ( my $station
|
||||
= $self->app->station_by_eva
|
||||
->{ $latest_cancellation->{dep_eva} } )
|
||||
{
|
||||
$latest_cancellation->{dep_ds100} = $station->[0];
|
||||
$latest_cancellation->{dep_name} = $station->[1];
|
||||
}
|
||||
if ( my $station
|
||||
= $self->app->station_by_eva
|
||||
->{ $latest_cancellation->{arr_eva} } )
|
||||
{
|
||||
$latest_cancellation->{arr_ds100} = $station->[0];
|
||||
$latest_cancellation->{arr_name} = $station->[1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$latest_cancellation = undef;
|
||||
}
|
||||
|
||||
if ($latest) {
|
||||
my $ts = $latest->{checkout_ts};
|
||||
my $action_time = epoch_to_dt($ts);
|
||||
|
@ -3375,6 +3414,7 @@ sub startup {
|
|||
return {
|
||||
checked_in => 0,
|
||||
cancelled => 0,
|
||||
cancellation => $latest_cancellation,
|
||||
journey_id => $latest->{journey_id},
|
||||
timestamp => $action_time,
|
||||
timestamp_delta => $now->epoch - $action_time->epoch,
|
||||
|
@ -3401,6 +3441,7 @@ sub startup {
|
|||
return {
|
||||
checked_in => 0,
|
||||
cancelled => 0,
|
||||
cancellation => $latest_cancellation,
|
||||
no_journeys_yet => 1,
|
||||
timestamp => epoch_to_dt(0),
|
||||
timestamp_delta => $now->epoch,
|
||||
|
|
|
@ -70,7 +70,44 @@ sub run {
|
|||
train_no => $train->train_no
|
||||
}
|
||||
);
|
||||
$self->app->add_route_timestamps( $uid, $train, 1 );
|
||||
if ( $train->departure_is_cancelled and $arr ) {
|
||||
|
||||
# depending on the amount of users in transit, some time may
|
||||
# have passed between fetching $entry from the database and
|
||||
# now. Ensure that the user is still checked into this train
|
||||
# before calling checkout to mark the cancellation.
|
||||
if (
|
||||
$db->select(
|
||||
'in_transit',
|
||||
'count(*) as count',
|
||||
{
|
||||
user_id => $uid,
|
||||
train_no => $train->train_no,
|
||||
checkin_station_id => $dep
|
||||
}
|
||||
)->hash->{count}
|
||||
)
|
||||
{
|
||||
$db->update(
|
||||
'in_transit',
|
||||
{
|
||||
cancelled => 1,
|
||||
},
|
||||
{
|
||||
user_id => $uid,
|
||||
train_no => $train->train_no,
|
||||
checkin_station_id => $dep
|
||||
}
|
||||
);
|
||||
|
||||
# check out (adds a cancelled journey and resets journey state
|
||||
# to checkin
|
||||
$self->app->checkout( $arr, 1, $uid );
|
||||
}
|
||||
}
|
||||
else {
|
||||
$self->app->add_route_timestamps( $uid, $train, 1 );
|
||||
}
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
|
|
|
@ -133,6 +133,10 @@ sub status_card {
|
|||
if ( $status->{checked_in} ) {
|
||||
$self->render( '_checked_in', journey => $status );
|
||||
}
|
||||
elsif ( $status->{cancellation} ) {
|
||||
$self->render( '_cancelled_departure',
|
||||
journey => $status->{cancellation} );
|
||||
}
|
||||
else {
|
||||
$self->render( '_checked_out', journey => $status );
|
||||
}
|
||||
|
|
|
@ -26,6 +26,13 @@
|
|||
</div>
|
||||
</div>
|
||||
% }
|
||||
% elsif ($status->{cancellation} and $station eq $status->{cancellation}{dep_name}) {
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
%= include '_cancelled_departure', journey => $status->{cancellation};
|
||||
</div>
|
||||
</div>
|
||||
% }
|
||||
% elsif ($status->{timestamp_delta} < 180) {
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
|
|
Loading…
Reference in a new issue