Turns out I wrote three queries

This commit is contained in:
Tom Bloor 2019-07-15 04:54:55 +01:00
parent 86d52e7bbc
commit 7dc7acb1a1
No known key found for this signature in database
GPG Key ID: 4657C7EBE42CC5CC
1 changed files with 12 additions and 12 deletions

View File

@ -257,49 +257,49 @@ sub post_supplier_history {
my $dtf = $c->schema->storage->datetime_parser; my $dtf = $c->schema->storage->datetime_parser;
my $year_rs = $c->schema->resultset('Transaction')->search( my $year_rs = $c->schema->resultset('Transaction')->search(
{ {
'me.purchase_time' => { 'sales.purchase_time' => {
-between => [ -between => [
$dtf->format_datetime($first), $dtf->format_datetime($first),
$dtf->format_datetime($last), $dtf->format_datetime($last),
], ],
}, },
'me.buyer_id' => $user->entity->id, 'sales.buyer_id' => $user->entity->id,
}, },
{ {
join => { seller => 'organisation' }, join => [ 'sales', 'organisation' ],
columns => [ columns => [
{ {
id => 'me.seller_id', id => 'me.id',
name => 'organisation.name', name => 'organisation.name',
count => \"COUNT(*)", count => \"COUNT(*)",
total_spend => { sum => 'me.value' }, total_spend => { sum => 'sales.value' },
} }
], ],
group_by => 'me.seller_id', group_by => [ 'me.id', 'organisation.id' ],
order_by => { '-asc' => 'organisation.name' }, order_by => { '-asc' => 'organisation.name' },
} }
); );
my $half_year_rs = $c->schema->resultset('Transaction')->search( my $half_year_rs = $c->schema->resultset('Transaction')->search(
{ {
'me.purchase_time' => { 'sales.purchase_time' => {
-between => [ -between => [
$dtf->format_datetime($second), $dtf->format_datetime($second),
$dtf->format_datetime($last), $dtf->format_datetime($last),
], ],
}, },
'me.buyer_id' => $user->entity->id, 'sales.buyer_id' => $user->entity->id,
}, },
{ {
join => { seller => 'organisation' }, join => [ 'sales', 'organisation' ],
columns => [ columns => [
{ {
id => 'me.seller_id', id => 'me.id',
name => 'organisation.name', name => 'organisation.name',
count => \"COUNT(*)", count => \"COUNT(*)",
total_spend => { sum => 'me.value' }, total_spend => { sum => 'sales.value' },
} }
], ],
group_by => 'me.seller_id', group_by => [ 'me.id', 'organisation.id' ],
order_by => { '-asc' => 'organisation.name' }, order_by => { '-asc' => 'organisation.name' },
} }
); );