2017-05-16 20:30:38 +00:00
|
|
|
package Pear::LocalLoop::Schema::ResultSet::Transaction;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use base 'DBIx::Class::ResultSet';
|
|
|
|
|
|
|
|
use DateTime;
|
|
|
|
|
2017-05-16 21:45:49 +00:00
|
|
|
sub search_between {
|
2021-03-20 12:09:50 +00:00
|
|
|
my ( $self, $from, $to ) = @_;
|
|
|
|
|
|
|
|
my $dtf = $self->result_source->schema->storage->datetime_parser;
|
|
|
|
return $self->search(
|
|
|
|
{
|
|
|
|
purchase_time => {
|
|
|
|
-between =>
|
|
|
|
[ $dtf->format_datetime($from), $dtf->format_datetime($to), ],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2017-05-16 20:30:38 +00:00
|
|
|
}
|
|
|
|
|
2017-08-21 14:16:29 +00:00
|
|
|
sub search_before {
|
2021-03-20 12:09:50 +00:00
|
|
|
my ( $self, $date ) = @_;
|
|
|
|
|
|
|
|
my $dtf = $self->result_source->schema->storage->datetime_parser;
|
|
|
|
return $self->search(
|
|
|
|
{
|
|
|
|
purchase_time => { '<' => $dtf->format_datetime($date) },
|
|
|
|
}
|
|
|
|
);
|
2017-08-21 14:16:29 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 21:45:49 +00:00
|
|
|
sub today_rs {
|
2021-03-20 12:09:50 +00:00
|
|
|
my ($self) = @_;
|
2017-05-16 21:45:49 +00:00
|
|
|
|
2021-03-20 12:09:50 +00:00
|
|
|
my $today = DateTime->today();
|
|
|
|
return $self->search_between( $today, $today->clone->add( days => 1 ) );
|
2017-05-16 21:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub week_rs {
|
2021-03-20 12:09:50 +00:00
|
|
|
my ($self) = @_;
|
2017-05-16 21:45:49 +00:00
|
|
|
|
2021-03-20 12:09:50 +00:00
|
|
|
my $today = DateTime->today();
|
|
|
|
return $self->search_between( $today->clone->subtract( days => 7 ),
|
|
|
|
$today );
|
2017-05-16 21:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub month_rs {
|
2021-03-20 12:09:50 +00:00
|
|
|
my ($self) = @_;
|
2017-05-16 21:45:49 +00:00
|
|
|
|
2021-03-20 12:09:50 +00:00
|
|
|
my $today = DateTime->today();
|
|
|
|
return $self->search_between( $today->clone->subtract( days => 30 ),
|
|
|
|
$today );
|
2017-05-16 20:30:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|