pie code made functional and relevant distance code updated
This commit is contained in:
parent
cb39b419d6
commit
7ffdfc5bd3
4 changed files with 60 additions and 11 deletions
|
@ -92,6 +92,11 @@ sub update {
|
|||
return $c->redirect_to( '/admin/users/' . $id );
|
||||
}
|
||||
|
||||
my $location = $c->get_location_from_postcode(
|
||||
$validation->param('postcode'),
|
||||
$user->type,
|
||||
);
|
||||
|
||||
if ( $user->type eq 'customer' ){
|
||||
|
||||
try {
|
||||
|
@ -100,6 +105,7 @@ sub update {
|
|||
full_name => $validation->param('full_name'),
|
||||
display_name => $validation->param('display_name'),
|
||||
postcode => $validation->param('postcode'),
|
||||
( defined $location ? ( %$location ) : ( latitude => undef, longitude => undef ) ),
|
||||
});
|
||||
$user->update({
|
||||
email => $validation->param('email'),
|
||||
|
@ -125,6 +131,7 @@ sub update {
|
|||
town => $validation->param('town'),
|
||||
sector => $validation->param('sector'),
|
||||
postcode => $validation->param('postcode'),
|
||||
( defined $location ? ( %$location ) : ( latitude => undef, longitude => undef ) ),
|
||||
});
|
||||
$user->update({
|
||||
email => $validation->param('email'),
|
||||
|
|
|
@ -21,7 +21,8 @@ sub post_index {
|
|||
my $end = DateTime->today;
|
||||
my $start = $end->clone->subtract_duration( $duration );
|
||||
|
||||
my $data = { purchases => [] };
|
||||
my $weeks = { purchases => [] };
|
||||
my $sectors = { sectors => [], purchases => [] };
|
||||
|
||||
my $dtf = $c->schema->storage->datetime_parser;
|
||||
my $driver = $c->schema->storage->dbh->{Driver}->{Name};
|
||||
|
@ -47,12 +48,13 @@ sub post_index {
|
|||
);
|
||||
|
||||
for ( $transaction_rs->all ) {
|
||||
push @{ $data->{ purchases } }, ($_->get_column('count') || 0);
|
||||
push @{ $weeks->{ purchases } }, ($_->get_column('count') || 0);
|
||||
}
|
||||
|
||||
return $c->render( json => {
|
||||
success => Mojo::JSON->true,
|
||||
data => $data,
|
||||
weeks => $weeks,
|
||||
sectors => $sectors,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -146,12 +146,18 @@ sub post_upload {
|
|||
|
||||
return $c->api_validation_error if $validation->has_error;
|
||||
|
||||
my $location = $c->get_location_from_postcode(
|
||||
$validation->param('postcode'),
|
||||
'organisation',
|
||||
);
|
||||
|
||||
my $entity = $c->schema->resultset('Entity')->create_org({
|
||||
submitted_by_id => $user->id,
|
||||
name => $validation->param('organisation_name'),
|
||||
street_name => $validation->param('street_name'),
|
||||
town => $validation->param('town'),
|
||||
postcode => $validation->param('postcode'),
|
||||
( defined $location ? ( %$location ) : ( latitude => undef, longitude => undef ) ),
|
||||
pending => 1,
|
||||
});
|
||||
$organisation = $entity->organisation;
|
||||
|
|
|
@ -5,17 +5,51 @@ sub index {
|
|||
my $c = shift;
|
||||
|
||||
my $entity = $c->stash->{api_user}->entity;
|
||||
my $data = { data => [] };
|
||||
|
||||
my $purchase_rs = $entity->purchases;
|
||||
my $local_org_local_purchase = $purchase_rs->search({
|
||||
"me.distance" => { '<', 20000 },
|
||||
'organisation.is_local' => 1,
|
||||
},
|
||||
{
|
||||
join => { 'seller' => 'organisation' },
|
||||
}
|
||||
);
|
||||
|
||||
my $local_org_non_local_purchase = $purchase_rs->search({
|
||||
"me.distance" => { '>=', 20000 },
|
||||
'organisation.is_local' => 1,
|
||||
},
|
||||
{
|
||||
join => { 'seller' => 'organisation' },
|
||||
}
|
||||
);
|
||||
|
||||
my $non_local_org_local_purchase = $purchase_rs->search({
|
||||
"me.distance" => { '<', 20000 },
|
||||
'organisation.is_local' => 0,
|
||||
},
|
||||
{
|
||||
join => { 'seller' => 'organisation' },
|
||||
}
|
||||
);
|
||||
|
||||
my $non_local_org_non_local_purchase = $purchase_rs->search({
|
||||
"me.distance" => { '>=', 20000 },
|
||||
'organisation.is_local' => 0,
|
||||
},
|
||||
{
|
||||
join => { 'seller' => 'organisation' },
|
||||
}
|
||||
);
|
||||
|
||||
my $data = {
|
||||
'Local shop local purchaser' => 20,
|
||||
'Local shop non-local purchaser' => 20,
|
||||
'Non-local shop local purchaser' => 20,
|
||||
'Non-local shop non-local purchaser' => 20,
|
||||
'Local shop local purchaser' => $local_org_local_purchase->count,
|
||||
'Local shop non-local purchaser' => $local_org_non_local_purchase->count,
|
||||
'Non-local shop local purchaser' => $non_local_org_local_purchase->count,
|
||||
'Non-local shop non-local purchaser' => $non_local_org_non_local_purchase->count,
|
||||
};
|
||||
|
||||
#TODO insert code fetching numbers here
|
||||
|
||||
return $c->render(
|
||||
json => {
|
||||
success => Mojo::JSON->true,
|
||||
|
|
Reference in a new issue