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};
|
my $user = $c->stash->{api_user};
|
||||||
|
|
||||||
# Temporary date lock for dev data
|
my $v = $c->validation;
|
||||||
my $last = DateTime->new(
|
$v->input($c->stash->{api_json});
|
||||||
year => 2019,
|
$v->required('from');
|
||||||
month => 4,
|
$v->required('to');
|
||||||
day => 1
|
|
||||||
);
|
return $c->api_validation_error if $v->has_error;
|
||||||
my $first = $last->clone->subtract(years => 1);
|
|
||||||
|
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 $dtf = $c->schema->storage->datetime_parser;
|
||||||
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||||
|
@ -185,13 +187,15 @@ sub post_supplier_count {
|
||||||
|
|
||||||
my $user = $c->stash->{api_user};
|
my $user = $c->stash->{api_user};
|
||||||
|
|
||||||
# Temporary date lock for dev data
|
my $v = $c->validation;
|
||||||
my $last = DateTime->new(
|
$v->input($c->stash->{api_json});
|
||||||
year => 2019,
|
$v->required('from');
|
||||||
month => 4,
|
$v->required('to');
|
||||||
day => 1
|
|
||||||
);
|
return $c->api_validation_error if $v->has_error;
|
||||||
my $first = $last->clone->subtract(years => 1);
|
|
||||||
|
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 $dtf = $c->schema->storage->datetime_parser;
|
||||||
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||||
|
@ -374,12 +378,31 @@ sub post_supplier_history {
|
||||||
sub post_lcc_table_summary {
|
sub post_lcc_table_summary {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
my $validation = $c->validation;
|
my $user = $c->stash->{api_user};
|
||||||
$validation->input($c->stash->{api_json});
|
|
||||||
|
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 $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' } } },
|
join => { seller => { postcode => { gb_postcode => 'ward' } } },
|
||||||
group_by => 'ward.id',
|
group_by => 'ward.id',
|
||||||
|
@ -415,6 +438,13 @@ sub post_lcc_table_summary {
|
||||||
/) {
|
/) {
|
||||||
my $transaction_type_rs = $transaction_rs->search(
|
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,
|
'meta.' . $meta => 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -428,7 +458,6 @@ sub post_lcc_table_summary {
|
||||||
}
|
}
|
||||||
)->first;
|
)->first;
|
||||||
|
|
||||||
|
|
||||||
$transaction_type_data->{$meta} = {
|
$transaction_type_data->{$meta} = {
|
||||||
($transaction_type_rs ? (
|
($transaction_type_rs ? (
|
||||||
count => $transaction_type_rs->get_column('count'),
|
count => $transaction_type_rs->get_column('count'),
|
||||||
|
|
Reference in a new issue