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