Skip to content

Commit

Permalink
Moosify ResultSets
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Sep 17, 2016
1 parent 813ba8e commit 8194f28
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
14 changes: 13 additions & 1 deletion lib/Magnum/Schema/ResultSet/InvoiceLine.pm
Expand Up @@ -2,12 +2,24 @@ package Magnum::Schema::ResultSet::InvoiceLine;

use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
use Moose;
use MooseX::NonMoose;
extends 'DBIx::Class::ResultSet';

sub BUILDARGS { $_[2] }

has default_vat_type => (
is => 'ro',
isa => 'Str',
default => 'standard',
);

sub filter_by_vat_type {
my $self = shift;
my ($vat_type) = @_;

$vat_type //= $self->default_vat_type;

$self->search({
vat => $vat_type,
});
Expand Down
18 changes: 15 additions & 3 deletions lib/Magnum/Schema/ResultSet/VatRate.pm
Expand Up @@ -2,16 +2,28 @@ package Magnum::Schema::ResultSet::VatRate;

use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
use Moose;
use MooseX::NonMoose;
extends 'DBIx::Class::ResultSet';

sub BUILDARGS { $_[2] }

has datetime_formatter => (
is => 'ro',
lazy_build => 1,
);

sub _build_datetime_formatter {
return $_[0]->result_source->schema->storage->datetime_parser;
}

sub vat_rate_for_date {
my $self = shift;
my ($date, $type) = @_;

$type //= 'standard';

my $dtf = $self->result_source->schema->storage->datetime_parser;
my $search_date = $dtf->format_datetime($date);
my $search_date = $self->datetime_formatter->format_datetime($date);

my ($rate) = $self->search({
type => $type,
Expand Down

0 comments on commit 8194f28

Please sign in to comment.