diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-09-12 18:07:21 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-09-12 18:07:21 +0200 |
commit | 0822cfc993ff44605210b6b771cd4558c1a65aef (patch) | |
tree | f17b3ae7aceddb59ecb913c35c78ef1e9d2f03c5 | |
parent | 8c160f68540d4450db97c2dd6dcda05a67189d9f (diff) |
add auto-generated passenger rights forms1.9.0
-rw-r--r-- | cpanfile | 1 | ||||
-rwxr-xr-x | lib/Travelynx.pm | 2 | ||||
-rw-r--r-- | lib/Travelynx/Controller/Passengerrights.pm | 83 | ||||
-rw-r--r-- | public/static/pdf/fahrgastrechteformular.pdf | bin | 0 -> 111614 bytes | |||
-rw-r--r-- | templates/changelog.html.ep | 13 | ||||
-rw-r--r-- | templates/journey.html.ep | 12 |
6 files changed, 111 insertions, 0 deletions
@@ -1,4 +1,5 @@ requires 'Cache'; +requires 'CAM::PDF'; requires 'Crypt::Eksblowfish'; requires 'DateTime'; requires 'DateTime::Format::Strptime'; diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index b1febce..94a7c49 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -2906,6 +2906,8 @@ sub startup { $authed_r->post('/account/insight')->to('account#insight'); $authed_r->post('/journey/add')->to('traveling#add_journey_form'); $authed_r->post('/journey/edit')->to('traveling#edit_journey'); + $authed_r->post('/journey/passenger_rights') + ->to('passengerrights#generate'); $authed_r->post('/account/password')->to('account#change_password'); $authed_r->post('/account/mail')->to('account#change_mail'); $authed_r->post('/delete')->to('account#delete'); diff --git a/lib/Travelynx/Controller/Passengerrights.pm b/lib/Travelynx/Controller/Passengerrights.pm new file mode 100644 index 0000000..aab8d76 --- /dev/null +++ b/lib/Travelynx/Controller/Passengerrights.pm @@ -0,0 +1,83 @@ +package Travelynx::Controller::Passengerrights; +use Mojo::Base 'Mojolicious::Controller'; + +use DateTime; +use CAM::PDF; + +sub generate { + my ($self) = @_; + my $journey_id = $self->param('id'); + + my $uid = $self->current_user->{id}; + + if ( not($journey_id) ) { + $self->render( + 'journey', + error => 'notfound', + journey => {} + ); + return; + } + + my $journey = $self->get_journey( + uid => $uid, + journey_id => $journey_id, + verbose => 1, + ); + + if ( not $journey ) { + $self->render( + 'journey', + error => 'notfound', + journey => {} + ); + return; + } + + my $pdf = CAM::PDF->new('public/static/pdf/fahrgastrechteformular.pdf'); + + $pdf->fillFormFields( 'S1F4', $journey->{from_name} ); + $pdf->fillFormFields( 'S1F7', $journey->{to_name} ); + if ( not $journey->{cancelled} ) { + $pdf->fillFormFields( 'S1F13', $journey->{type} ); + $pdf->fillFormFields( 'S1F14', $journey->{no} ); + } + $pdf->fillFormFields( 'S1F17', $journey->{type} ); + $pdf->fillFormFields( 'S1F18', $journey->{no} ); + if ( $journey->{sched_departure}->epoch ) { + $pdf->fillFormFields( 'S1F1', + $journey->{sched_departure}->strftime('%d') ); + $pdf->fillFormFields( 'S1F2', + $journey->{sched_departure}->strftime('%m') ); + $pdf->fillFormFields( 'S1F3', + $journey->{sched_departure}->strftime('%y') ); + $pdf->fillFormFields( 'S1F5', + $journey->{sched_departure}->strftime('%H') ); + $pdf->fillFormFields( 'S1F6', + $journey->{sched_departure}->strftime('%M') ); + $pdf->fillFormFields( 'S1F19', + $journey->{sched_departure}->strftime('%H') ); + $pdf->fillFormFields( 'S1F20', + $journey->{sched_departure}->strftime('%M') ); + } + if ( $journey->{sched_arrival}->epoch ) { + $pdf->fillFormFields( 'S1F8', + $journey->{sched_arrival}->strftime('%H') ); + $pdf->fillFormFields( 'S1F9', + $journey->{sched_arrival}->strftime('%M') ); + } + if ( $journey->{rt_arrival}->epoch and not $journey->{cancelled} ) { + $pdf->fillFormFields( 'S1F10', $journey->{rt_arrival}->strftime('%d') ); + $pdf->fillFormFields( 'S1F11', $journey->{rt_arrival}->strftime('%m') ); + $pdf->fillFormFields( 'S1F12', $journey->{rt_arrival}->strftime('%y') ); + $pdf->fillFormFields( 'S1F15', $journey->{rt_arrival}->strftime('%H') ); + $pdf->fillFormFields( 'S1F16', $journey->{rt_arrival}->strftime('%M') ); + } + + $self->res->headers->content_type('application/pdf'); + $self->res->body( $pdf->toPDF() ); + $self->rendered(200); + +} + +1; diff --git a/public/static/pdf/fahrgastrechteformular.pdf b/public/static/pdf/fahrgastrechteformular.pdf Binary files differnew file mode 100644 index 0000000..f7f420c --- /dev/null +++ b/public/static/pdf/fahrgastrechteformular.pdf diff --git a/templates/changelog.html.ep b/templates/changelog.html.ep index e511100..aa7c6e6 100644 --- a/templates/changelog.html.ep +++ b/templates/changelog.html.ep @@ -2,6 +2,19 @@ <div class="row"> <div class="col s12 m1 l1"> + 1.9 + </div> + <div class="col s12 m11 l11"> + <p> + <i class="material-icons left">add</i> Generierung vorausgefüllter + Fahrgastrechteformulare bei Zugausfällen und Verspätungen ab 60 + Minuten. + </p> + </div> +</div> + +<div class="row"> + <div class="col s12 m1 l1"> 1.8 </div> <div class="col s12 m11 l11"> diff --git a/templates/journey.html.ep b/templates/journey.html.ep index 343c178..440eec6 100644 --- a/templates/journey.html.ep +++ b/templates/journey.html.ep @@ -31,6 +31,18 @@ ∗ Daten wurden manuell eingetragen </p> % } + % if ($journey->{cancelled} or ($journey->{rt_arrival} and ($journey->{rt_arrival}->epoch - $journey->{sched_arrival}->epoch) >= 3600)) { + <div style="text-align: center; margin-bottom: 1em;"> + %= form_for 'journeypassenger_rights' => begin + %= csrf_field + %= hidden_field id => $journey->{id} + <button class="btn waves-effect waves-light grey darken-3" type="submit" name="action" value="generate"> + <i class="material-icons left">file_download</i> + Fahrgastrechte + </button> + %= end + </div> + % } <table class="striped"> <tr> <th scope="row">Zug</th> |