Initial API for submission added
This commit is contained in:
parent
c6679e1261
commit
662219fc6e
2 changed files with 123 additions and 0 deletions
|
@ -155,6 +155,9 @@ sub startup {
|
||||||
$api->post('/stats')->to('api-stats#post_index');
|
$api->post('/stats')->to('api-stats#post_index');
|
||||||
$api->post('/stats/leaderboard')->to('api-stats#post_leaderboards');
|
$api->post('/stats/leaderboard')->to('api-stats#post_leaderboards');
|
||||||
$api->post('/outgoing-transactions')->to('api-transactions#post_transaction_list_purchases');
|
$api->post('/outgoing-transactions')->to('api-transactions#post_transaction_list_purchases');
|
||||||
|
$api->post('/org/payroll')->to('api-organisation#post_payroll');
|
||||||
|
$api->post('/org/supplier')->to('api-organisation#post_supplier');
|
||||||
|
$api->post('/org/employee')->to('api-organisation#post_employee');
|
||||||
|
|
||||||
my $api_v1 = $api->under('/v1');
|
my $api_v1 = $api->under('/v1');
|
||||||
|
|
||||||
|
|
120
lib/Pear/LocalLoop/Controller/Api/Organisation.pm
Normal file
120
lib/Pear/LocalLoop/Controller/Api/Organisation.pm
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
package Pear::LocalLoop::Controller::Api::Organisation;
|
||||||
|
use Mojo::Base 'Mojolicious::Controller';
|
||||||
|
use Mojo::JSON;
|
||||||
|
|
||||||
|
has error_messages => sub {
|
||||||
|
return {
|
||||||
|
sector => {
|
||||||
|
required => { message => 'No sector sent.', status => 400 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
sub post_payroll {
|
||||||
|
my $c = shift;
|
||||||
|
|
||||||
|
my $user = $c->stash->{api_user};
|
||||||
|
|
||||||
|
my $validation = $c->validation;
|
||||||
|
$validation->input( $c->stash->{api_json} );
|
||||||
|
|
||||||
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
|
||||||
|
my $user_rs = $c->schema->resultset('User')->search({
|
||||||
|
id => { "!=" => $user->id },
|
||||||
|
});
|
||||||
|
|
||||||
|
$validation->required('entryperiod');
|
||||||
|
$validation->required('employeeamount');
|
||||||
|
$validation->required('localemployeeamount');
|
||||||
|
$validation->required('grosspayroll');
|
||||||
|
$validation->optional('payrollincometax');
|
||||||
|
$validation->optional('payrollemployeeni');
|
||||||
|
$validation->optional('payrollemployerni');
|
||||||
|
$validation->optional('payrolltotalpension');
|
||||||
|
$validation->optional('payrollotherbenefit');
|
||||||
|
|
||||||
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
|
||||||
|
$c->schema->txn_do( sub {
|
||||||
|
$user->entity->organisation->update({
|
||||||
|
entry_period => $validation->param('entryperiod'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return $c->render( json => {
|
||||||
|
success => Mojo::JSON->true,
|
||||||
|
message => 'Submitted Payroll Info Successfully',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
sub post_supplier {
|
||||||
|
my $c = shift;
|
||||||
|
|
||||||
|
my $user = $c->stash->{api_user};
|
||||||
|
|
||||||
|
my $validation = $c->validation;
|
||||||
|
$validation->input( $c->stash->{api_json} );
|
||||||
|
|
||||||
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
|
||||||
|
my $user_rs = $c->schema->resultset('User')->search({
|
||||||
|
id => { "!=" => $user->id },
|
||||||
|
});
|
||||||
|
|
||||||
|
$validation->required('entryperiod');
|
||||||
|
$validation->optional('postcode')->postcode;
|
||||||
|
$validation->optional('supplierbusinessname');
|
||||||
|
$validation->optional('monthlyspend');
|
||||||
|
|
||||||
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
|
||||||
|
$c->schema->txn_do( sub {
|
||||||
|
$user->entity->organisation->update({
|
||||||
|
entry_period => $validation->param('entryperiod'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return $c->render( json => {
|
||||||
|
success => Mojo::JSON->true,
|
||||||
|
message => 'Submitted Payroll Info Successfully',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
sub post_employee {
|
||||||
|
my $c = shift;
|
||||||
|
|
||||||
|
my $user = $c->stash->{api_user};
|
||||||
|
|
||||||
|
my $validation = $c->validation;
|
||||||
|
$validation->input( $c->stash->{api_json} );
|
||||||
|
|
||||||
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
|
||||||
|
my $user_rs = $c->schema->resultset('User')->search({
|
||||||
|
id => { "!=" => $user->id },
|
||||||
|
});
|
||||||
|
|
||||||
|
$validation->required('entryperiod');
|
||||||
|
$validation->optional('employeeno');
|
||||||
|
$validation->optional('employeeincometax');
|
||||||
|
$validation->optional('employeegrosswage');
|
||||||
|
$validation->optional('employeeni');
|
||||||
|
$validation->optional('employeepension');
|
||||||
|
$validation->optional('employeeotherbenefit');
|
||||||
|
|
||||||
|
return $c->api_validation_error if $validation->has_error;
|
||||||
|
|
||||||
|
$c->schema->txn_do( sub {
|
||||||
|
$user->entity->organisation->update({
|
||||||
|
entry_period => $validation->param('entryperiod'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return $c->render( json => {
|
||||||
|
success => Mojo::JSON->true,
|
||||||
|
message => 'Submitted Payroll Info Successfully',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
Reference in a new issue