Fully added working import and API
This commit is contained in:
parent
aa2d429403
commit
efbf8cbad7
3 changed files with 34 additions and 22 deletions
|
@ -18,27 +18,29 @@ sub post_lcc_transactions {
|
|||
|
||||
return $c->api_validation_error if $validation->has_error;
|
||||
|
||||
my $lcc_import_ext_ref = $self->schema->resultset('ExternalReference')->find_or_create({ name => 'LCC CSV' });
|
||||
my $lcc_import_ext_ref = $c->schema->resultset('ExternalReference')->find({ name => 'LCC CSV' });
|
||||
|
||||
my $lcc_transactions = $lcc_import_ext_ref->search_related('transactions',
|
||||
undef,
|
||||
{
|
||||
page => $validation->param('page') || 1,
|
||||
rows => 10,
|
||||
order_by => { -desc => 'purchase_time' },
|
||||
},
|
||||
);
|
||||
return 0 unless $lcc_import_ext_ref;
|
||||
|
||||
my $lcc_transactions = $lcc_import_ext_ref->transactions->search(
|
||||
undef,
|
||||
{
|
||||
page => $validation->param('page') || 1,
|
||||
rows => 10,
|
||||
join => 'transaction',
|
||||
order_by => { -desc => 'transaction.purchase_time' },
|
||||
});
|
||||
|
||||
# purchase_time needs timezone attached to it
|
||||
my @transaction_list = (
|
||||
map {{
|
||||
transaction_external_id => $_->external_id,
|
||||
seller => $_->transaction->seller->name,
|
||||
net_value => $_->transaction->value,
|
||||
net_value => $_->transaction->meta->net_value,
|
||||
gross_value => $_->transaction->meta->gross_value,
|
||||
sales_tax_value => $_->transaction->meta->sales_tax_value,
|
||||
purchase_time => $c->transaction->format_iso_datetime($_->purchase_time),
|
||||
}} $transactions->all
|
||||
purchase_time => $c->format_iso_datetime($_->transaction->purchase_time),
|
||||
}} $lcc_transactions->all
|
||||
);
|
||||
|
||||
return $c->render( json => {
|
||||
|
@ -55,7 +57,7 @@ sub post_lcc_suppliers {
|
|||
|
||||
# TODO give an error if user is not of Lancashire County Council
|
||||
|
||||
my $is_lcc = $self->entity->organisation->count({ name => "Lancashire County Council" });
|
||||
my $is_lcc = $user->entity->organisation->count({ name => "Lancashire County Council" });
|
||||
|
||||
my $validation = $c->validation;
|
||||
$validation->input( $c->stash->{api_json} );
|
||||
|
@ -63,7 +65,7 @@ sub post_lcc_suppliers {
|
|||
|
||||
return $c->api_validation_error if $validation->has_error;
|
||||
|
||||
my $lcc_import_ext_ref = $self->schema->resultset('ExternalReference')->find_or_create({ name => 'LCC CSV' });
|
||||
my $lcc_import_ext_ref = $c->schema->resultset('ExternalReference')->find_or_create({ name => 'LCC CSV' });
|
||||
|
||||
my $lcc_suppliers = $lcc_import_ext_ref->search_related('organisations',
|
||||
undef,
|
||||
|
@ -74,7 +76,6 @@ sub post_lcc_suppliers {
|
|||
},
|
||||
);
|
||||
|
||||
# purchase_time needs timezone attached to it
|
||||
my @supplier_list = (
|
||||
map {{
|
||||
supplier_external_id => $_->external_id,
|
||||
|
|
Reference in a new issue