filter everything by date
This commit is contained in:
parent
653f495a70
commit
103cf61ec6
1 changed files with 80 additions and 51 deletions
|
@ -133,13 +133,15 @@ sub post_year_spend {
|
|||
|
||||
my $user = $c->stash->{api_user};
|
||||
|
||||
# Temporary date lock for dev data
|
||||
my $last = DateTime->new(
|
||||
year => 2019,
|
||||
month => 4,
|
||||
day => 1
|
||||
);
|
||||
my $first = $last->clone->subtract(years => 1);
|
||||
my $v = $c->validation;
|
||||
$v->input($c->stash->{api_json});
|
||||
$v->required('from');
|
||||
$v->required('to');
|
||||
|
||||
return $c->api_validation_error if $v->has_error;
|
||||
|
||||
my $last = $c->parse_iso_datetime($v->param('to'));
|
||||
my $first = $c->parse_iso_datetime($v->param('from'));
|
||||
|
||||
my $dtf = $c->schema->storage->datetime_parser;
|
||||
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||
|
@ -185,13 +187,15 @@ sub post_supplier_count {
|
|||
|
||||
my $user = $c->stash->{api_user};
|
||||
|
||||
# Temporary date lock for dev data
|
||||
my $last = DateTime->new(
|
||||
year => 2019,
|
||||
month => 4,
|
||||
day => 1
|
||||
);
|
||||
my $first = $last->clone->subtract(years => 1);
|
||||
my $v = $c->validation;
|
||||
$v->input($c->stash->{api_json});
|
||||
$v->required('from');
|
||||
$v->required('to');
|
||||
|
||||
return $c->api_validation_error if $v->has_error;
|
||||
|
||||
my $last = $c->parse_iso_datetime($v->param('to'));
|
||||
my $first = $c->parse_iso_datetime($v->param('from'));
|
||||
|
||||
my $dtf = $c->schema->storage->datetime_parser;
|
||||
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||
|
@ -374,12 +378,31 @@ sub post_supplier_history {
|
|||
sub post_lcc_table_summary {
|
||||
my $c = shift;
|
||||
|
||||
my $validation = $c->validation;
|
||||
$validation->input($c->stash->{api_json});
|
||||
my $user = $c->stash->{api_user};
|
||||
|
||||
my $v = $c->validation;
|
||||
$v->input($c->stash->{api_json});
|
||||
$v->required('from');
|
||||
$v->required('to');
|
||||
|
||||
return $c->api_validation_error if $v->has_error;
|
||||
|
||||
my $last = $c->parse_iso_datetime($v->param('to'));
|
||||
my $first = $c->parse_iso_datetime($v->param('from'));
|
||||
|
||||
my $transaction_rs = $c->schema->resultset('Transaction');
|
||||
|
||||
my $ward_transactions_rs = $transaction_rs->search({},
|
||||
my $dtf = $c->schema->storage->datetime_parser;
|
||||
my $ward_transactions_rs = $transaction_rs->search(
|
||||
{
|
||||
purchase_time => {
|
||||
-between => [
|
||||
$dtf->format_datetime($first),
|
||||
$dtf->format_datetime($last),
|
||||
],
|
||||
buyer_id => $user->entity->id,
|
||||
},
|
||||
},
|
||||
{
|
||||
join => { seller => { postcode => { gb_postcode => 'ward' } } },
|
||||
group_by => 'ward.id',
|
||||
|
@ -415,6 +438,13 @@ sub post_lcc_table_summary {
|
|||
/) {
|
||||
my $transaction_type_rs = $transaction_rs->search(
|
||||
{
|
||||
'me.purchase_time' => {
|
||||
-between => [
|
||||
$dtf->format_datetime($first),
|
||||
$dtf->format_datetime($last),
|
||||
],
|
||||
},
|
||||
'me.buyer_id' => $user->entity->id,
|
||||
'meta.' . $meta => 1,
|
||||
},
|
||||
{
|
||||
|
@ -428,7 +458,6 @@ sub post_lcc_table_summary {
|
|||
}
|
||||
)->first;
|
||||
|
||||
|
||||
$transaction_type_data->{$meta} = {
|
||||
($transaction_type_rs ? (
|
||||
count => $transaction_type_rs->get_column('count'),
|
||||
|
|
Reference in a new issue