1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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;
|