From a0f16725b2148359e6ca2a1b8d409125394baa07 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Mon, 15 Jul 2019 04:54:55 +0100 Subject: [PATCH] Turns out I wrote three queries --- lib/Pear/LocalLoop/Controller/Api/External.pm | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/External.pm b/lib/Pear/LocalLoop/Controller/Api/External.pm index 6f8b5c1..f28f7fa 100644 --- a/lib/Pear/LocalLoop/Controller/Api/External.pm +++ b/lib/Pear/LocalLoop/Controller/Api/External.pm @@ -257,49 +257,49 @@ sub post_supplier_history { my $dtf = $c->schema->storage->datetime_parser; my $year_rs = $c->schema->resultset('Transaction')->search( { - 'me.purchase_time' => { + 'sales.purchase_time' => { -between => [ $dtf->format_datetime($first), $dtf->format_datetime($last), ], }, - 'me.buyer_id' => $user->entity->id, + 'sales.buyer_id' => $user->entity->id, }, { - join => { seller => 'organisation' }, + join => [ 'sales', 'organisation' ], columns => [ { - id => 'me.seller_id', + id => 'me.id', name => 'organisation.name', 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' }, } ); my $half_year_rs = $c->schema->resultset('Transaction')->search( { - 'me.purchase_time' => { + 'sales.purchase_time' => { -between => [ $dtf->format_datetime($second), $dtf->format_datetime($last), ], }, - 'me.buyer_id' => $user->entity->id, + 'sales.buyer_id' => $user->entity->id, }, { - join => { seller => 'organisation' }, + join => [ 'sales', 'organisation' ], columns => [ { - id => 'me.seller_id', + id => 'me.id', name => 'organisation.name', 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' }, } );