sub
current_tax {
my
(
$self
,
$tax_name
) =
@_
;
my
$schema
=
$self
->result_source->schema;
my
$dtf
=
$schema
->storage->datetime_parser;
my
$dt
= DateTime->today;
$schema
->throw_exception(
"tax_name not supplied"
)
unless
defined
$tax_name
;
my
$rset
=
$self
->search(
{
tax_name
=>
$tax_name
,
valid_from
=> {
'<='
,
$dtf
->format_datetime(
$dt
) },
valid_to
=> [
undef
, {
'>='
,
$dtf
->format_datetime(
$dt
) } ],
}
);
if
(
$rset
->count == 1 ) {
return
$rset
->
next
;
}
else
{
$schema
->throw_exception(
"current_tax not found for tax_name: "
.
$tax_name
);
}
}
1;