| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 2 |  |  | 2 |  | 3532 | use utf8; | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | package Interchange6::Schema::ResultSet::Tax; | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | Interchange6::Schema::ResultSet::Tax | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =cut | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Provides extra accessor methods for L<Interchange6::Schema::Result::Tax> | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =cut | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 2 |  |  | 2 |  | 88 | use strict; | 
|  | 2 |  |  |  |  | 10 |  | 
|  | 2 |  |  |  |  | 46 |  | 
| 18 | 2 |  |  | 2 |  | 17 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 52 |  | 
| 19 | 2 |  |  | 2 |  | 13 | use mro 'c3'; | 
|  | 2 |  |  |  |  | 7 |  | 
|  | 2 |  |  |  |  | 9 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 2 |  |  | 2 |  | 47 | use DateTime; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 41 |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 2 |  |  | 2 |  | 13 | use parent 'Interchange6::Schema::ResultSet'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =head1 METHODS | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head2 current_tax( $tax_name ) | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | Given a valid tax_name will return the Tax row for the current date | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | =cut | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub current_tax { | 
| 34 | 7 |  |  | 7 | 1 | 8096 | my ( $self, $tax_name ) = @_; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 7 |  |  |  |  | 40 | my $schema = $self->result_source->schema; | 
| 37 | 7 |  |  |  |  | 178 | my $dtf    = $schema->storage->datetime_parser; | 
| 38 | 7 |  |  |  |  | 168 | my $dt     = DateTime->today; | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 7 | 100 |  |  |  | 3965 | $schema->throw_exception("tax_name not supplied") unless defined $tax_name; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 6 |  |  |  |  | 29 | my $rset = $self->search( | 
| 43 |  |  |  |  |  |  | { | 
| 44 |  |  |  |  |  |  | tax_name   => $tax_name, | 
| 45 |  |  |  |  |  |  | valid_from => { '<=', $dtf->format_datetime($dt) }, | 
| 46 |  |  |  |  |  |  | valid_to   => [ undef, { '>=', $dtf->format_datetime($dt) } ], | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  | ); | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 6 | 100 |  |  |  | 1871 | if ( $rset->count == 1 ) { | 
| 51 | 4 |  |  |  |  | 21213 | return $rset->next; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  | else { | 
| 54 | 2 |  |  |  |  | 10890 | $schema->throw_exception( | 
| 55 |  |  |  |  |  |  | "current_tax not found for tax_name: " . $tax_name ); | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | 1; |