sub get_badge_data_from_program { my ($class, $c, $program, $only_unbadged) = @_; my ($mess, $title, $code) = $class->get_title_code($program); if ($mess) { # cannot proceed return $mess; } my @regs = model($c, 'Registration')->search( { program_id => $program->id, cancelled => '', $only_unbadged? (badge_printed => ''): (), }, { join => [qw/ person /], prefetch => [qw/ person /], } ); if (! @regs) { return "No badges to print."; } my @data; for my $reg (@regs) { my $dates = $reg->dates(); my $room = $reg->house_name(); my $pronouns = $reg->person->pronouns; push @data, map { +{ # href name => $_, pronouns => $pronouns, dates => $dates, room => $room, } } $reg->person->badge_name(), kid_badge_names($reg); # kids pronouns?? $reg->update({ badge_printed => 'yes', }); } @data = sort { $a->{name} cmp $b->{name} } @data; return ($mess, $title, $code, \@data); } sub get_badge_data_from_rental { my ($class, $c, $rental) = @_; my ($mess, $title, $code) = $class->get_title_code($rental); if ($mess) { # cannot proceed return $mess; } my $d = $rental->sdate_obj(); my @data; GRID: for my $g (model($c, 'Grid')->search({ rental_id => $rental->id, }) ) { my $cost = $g->cost; my $house_id = $g->house_id; if (!$cost || $g->occupancy !~ /1/) { # no one is in that room # shouldn't be a record... next GRID; } my $room = ($house_id == 1001)? 'Own Van' :($house_id == 1002)? 'Commuting' : $house_name_of{$house_id} ; my $name = $g->name; my @nights = $g->occupancy =~ m{(\d)}xmsg; # for 'child', '&', and 'and', see below # what nights? # there must be an easier way to do this... my ($this_d, $this_ed); for (my $i = 0; $i <= $#nights; ++$i) { if ($nights[$i] == 1) { $this_d = $d + $i; last; } } for (my $i = $#nights; $i >= 0; --$i) { if ($nights[$i] == 1) { $this_ed = $d + $i + 1; # +1 for the next day... last; } } if ((! $this_d) || (! $this_ed)) { # something is wrong next GRID; } my $dates = $this_d->format("%b %e") . ' - ' . $this_ed->format("%b %e") ; my @names = split m{ \s* (?: [&] | \band\b | [/]) # and / \s* }xmsi, $name; for my $n (@names) { $n =~ s{ \b child \s* \z}{}xmsi; if ($n =~ m{ [(] (.*) [)] }xms) { # a parenthesized name is the nickname # they want to be called by - perhaps # an adopted Sanskrit name or a shortened name # they prefer over their formal legal name. $n = $1; } push @data, { name => normalize($n), dates => $dates, room => $room, }; } } # could use Schwartzian transform below @data = sort { lc $a->{name} cmp lc $b->{name} } @data; return ($mess, $title, $code, \@data); }
<!-- the front of the badges --> <table cellpadding=1 cellspacing=1 class=front> <tr> [% FOREACH i IN [ 0,1,2,3,4,5,6,7] %] [% IF ! data.$i.name %] <td> </td> [% ELSE %] <td> <center> <img src=/static/images/mm-logo-mobile.png class=image> <div class='name first ${data.$i.name_class}'>${data.$i.first}</div> <div class='name last'>${data.$i.last}</div> <div class='pronouns'>${data.$i.pronouns}</div> <div class=program>[% IF data.$i.program %]${data.$i.program}[% ELSE %]$program[% END %]</div> <div class=dates>[% data.$i.dates %]</div> </center> </td> [% END %] [% IF i == 3 %] </tr><tr> [% END %] [% END %] </tr> </table> <div style='page-break-after:always'></div> <!-- the back of the badges --> <table cellpadding=1 cellspacing=1 class=back> <tr> [% FOREACH i IN [ 3,2,1,0,7,6,5,4 ] %] [% IF ! data.$i.name %] <td> </td> [% IF i == 0 %] </tr><tr> [% END %] [% NEXT %] [% END %] <td> <div class=center> <!-- <div class=emergency_lab> After Hours Contact </div> <div class=emergency_txt> 408-475-0095 </div> --> [% housing = (data.$i.room != 'No Housing') %] [% IF housing %] <div class=room_lab> Room #: <span class=room_txt> [% data.$i.room %] </span> </div> [% END %] <div class=main_lab> Main Gate Code: </div> <div class=main_txt> #[% IF data.$i.code %]${data.$i.code}[% ELSE %]$code[% END %] </div> <div class=oaks_lab> School Gate Code: </div> <div class=oaks_txt> 1[% IF data.$i.code %]${data.$i.code}[% ELSE %]$code[% END %] </div> <div class=return> <span class=lan>RETURN LANYARDS</span> and keys to the Guest Services Office[% IF housing %] or leave in your room[% END %]. </div> </div> </td> [% IF i == 0 %] </tr><tr> [% END %] [% END %] </tr> </table> <div style='page-break-after:always'></div>