Payroll sumission API improved and test added
This commit is contained in:
parent
b224182e61
commit
616181def3
5 changed files with 342 additions and 16 deletions
|
@ -17,47 +17,47 @@ has error_messages => sub {
|
|||
required => { message => 'No gross payroll sent.', status => 400 },
|
||||
},
|
||||
payroll_income_tax => {
|
||||
required => { message => 'no payroll income tax sent.', status => 400 },
|
||||
required => { message => 'No total income tax sent.', status => 400 },
|
||||
},
|
||||
payroll_employee_ni => {
|
||||
required => { message => 'no payroll employee ni sent.', status => 400 },
|
||||
required => { message => 'No total employee NI sent.', status => 400 },
|
||||
},
|
||||
payroll_employer_ni => {
|
||||
required => { message => 'no payroll employer ni sent.', status => 400 },
|
||||
required => { message => 'No total employer NI sent.', status => 400 },
|
||||
},
|
||||
payroll_total_pension => {
|
||||
required => { message => 'no payroll total pension sent.', status => 400 },
|
||||
required => { message => 'No total total pension sent.', status => 400 },
|
||||
},
|
||||
payroll_other_benefit => {
|
||||
required => { message => 'no payroll other benefit sent.', status => 400 },
|
||||
required => { message => 'No total other benefits total sent.', status => 400 },
|
||||
},
|
||||
supplier_business_name => {
|
||||
required => { message => 'no supplier business name sent.', status => 400 },
|
||||
required => { message => 'No supplier business name sent.', status => 400 },
|
||||
},
|
||||
postcode => {
|
||||
required => { message => 'no postcode sent.', status => 400 },
|
||||
required => { message => 'No postcode sent.', status => 400 },
|
||||
postcode => { message => 'postcode must be valid', status => 400 },
|
||||
},
|
||||
monthly_spend => {
|
||||
required => { message => 'no monthly spend sent.', status => 400 },
|
||||
required => { message => 'No monthly spend sent.', status => 400 },
|
||||
},
|
||||
employee_no => {
|
||||
required => { message => 'no employee no sent.', status => 400 },
|
||||
required => { message => 'No employee no sent.', status => 400 },
|
||||
},
|
||||
employee_income_tax => {
|
||||
required => { message => 'no employee income tax sent.', status => 400 },
|
||||
required => { message => 'No employee income tax sent.', status => 400 },
|
||||
},
|
||||
employee_gross_wage => {
|
||||
required => { message => 'no employee gross wage sent.', status => 400 },
|
||||
required => { message => 'No employee gross wage sent.', status => 400 },
|
||||
},
|
||||
employee_ni => {
|
||||
required => { message => 'no employee ni sent.', status => 400 },
|
||||
required => { message => 'No employee ni sent.', status => 400 },
|
||||
},
|
||||
employee_pension => {
|
||||
required => { message => 'no employee pension sent.', status => 400 },
|
||||
required => { message => 'No employee pension sent.', status => 400 },
|
||||
},
|
||||
employee_other_benefit => {
|
||||
required => { message => 'no employee other benefits sent.', status => 400 },
|
||||
required => { message => 'No employee other benefits sent.', status => 400 },
|
||||
},
|
||||
};
|
||||
};
|
||||
|
@ -86,11 +86,26 @@ sub post_payroll {
|
|||
$validation->required('payroll_total_pension');
|
||||
$validation->required('payroll_other_benefit');
|
||||
|
||||
my $gross_payroll = $validation->param('gross_payroll');
|
||||
my $payroll_income_tax = $validation->param('payroll_income_tax');
|
||||
my $payroll_employee_ni = $validation->param('payroll_employee_ni');
|
||||
my $payroll_employer_ni = $validation->param('payroll_employer_ni');
|
||||
my $payroll_total_pension = $validation->param('payroll_total_pension');
|
||||
my $payroll_other_benefit = $validation->param('payroll_other_benefit');
|
||||
|
||||
return $c->api_validation_error if $validation->has_error;
|
||||
|
||||
$c->schema->txn_do( sub {
|
||||
$user->entity->organisation->update({
|
||||
$user->entity->organisation->payroll->create({
|
||||
entry_period => $validation->param('entry_period'),
|
||||
employee_amount => $validation->param('employee_amount'),
|
||||
local_employee_amount => $validation->param('local_employee_amount'),
|
||||
gross_payroll => $gross_payroll * 100000,
|
||||
payroll_income_tax => $payroll_income_tax * 100000,
|
||||
payroll_employee_ni => $payroll_employee_ni * 100000,
|
||||
payroll_employer_ni => $payroll_employer_ni * 100000,
|
||||
payroll_total_pension => $payroll_total_pension * 100000,
|
||||
payroll_other_benefit => $payroll_other_benefit * 100000,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -68,6 +68,13 @@ __PACKAGE__->belongs_to(
|
|||
"entity_id",
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
"payroll",
|
||||
"Pear::LocalLoop::Schema::Result::OrganisationPayroll",
|
||||
{ "foreign.org_id" => "self.id" },
|
||||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
__PACKAGE__->filter_column( pending => {
|
||||
filter_to_storage => 'to_bool',
|
||||
});
|
||||
|
|
83
lib/Pear/LocalLoop/Schema/Result/OrganisationPayroll.pm
Normal file
83
lib/Pear/LocalLoop/Schema/Result/OrganisationPayroll.pm
Normal file
|
@ -0,0 +1,83 @@
|
|||
package Pear::LocalLoop::Schema::Result::OrganisationPayroll;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use base 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->load_components(qw/
|
||||
InflateColumn::DateTime
|
||||
TimeStamp
|
||||
/);
|
||||
|
||||
__PACKAGE__->table("organisation_payroll");
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"id" => {
|
||||
data_type => "integer",
|
||||
is_auto_increment => 1,
|
||||
is_nullable => 0,
|
||||
},
|
||||
"org_id" => {
|
||||
data_type => 'integer',
|
||||
is_nullable => 0,
|
||||
is_foreign_key => 1,
|
||||
},
|
||||
"submitted_at" => {
|
||||
data_type => "datetime",
|
||||
is_nullable => 0,
|
||||
set_on_create => 1,
|
||||
},
|
||||
"entry_period" => {
|
||||
data_type => "datetime",
|
||||
is_nullable => 0,
|
||||
},
|
||||
"employee_amount" => {
|
||||
data_type => "integer",
|
||||
is_nullable => 0,
|
||||
},
|
||||
"local_employee_amount" => {
|
||||
data_type => "integer",
|
||||
is_nullable => 0,
|
||||
},
|
||||
"gross_payroll" => {
|
||||
data_type => "numeric",
|
||||
size => [ 100, 0 ],
|
||||
is_nullable => 0,
|
||||
},
|
||||
"payroll_income_tax" => {
|
||||
data_type => "numeric",
|
||||
size => [ 100, 0 ],
|
||||
is_nullable => 0,
|
||||
},
|
||||
"payroll_employee_ni" => {
|
||||
data_type => "numeric",
|
||||
size => [ 100, 0 ],
|
||||
is_nullable => 0,
|
||||
},
|
||||
"payroll_employer_ni" => {
|
||||
data_type => "numeric",
|
||||
size => [ 100, 0 ],
|
||||
is_nullable => 0,
|
||||
},
|
||||
"payroll_total_pension" => {
|
||||
data_type => "numeric",
|
||||
size => [ 100, 0 ],
|
||||
is_nullable => 0,
|
||||
},
|
||||
"payroll_other_benefit" => {
|
||||
data_type => "numeric",
|
||||
size => [ 100, 0 ],
|
||||
is_nullable => 0,
|
||||
},
|
||||
);
|
||||
|
||||
__PACKAGE__->set_primary_key("id");
|
||||
|
||||
__PACKAGE__->belongs_to(
|
||||
"organisation",
|
||||
"Pear::LocalLoop::Schema::Result::Organisation",
|
||||
"org_id",
|
||||
);
|
||||
|
||||
1;
|
Reference in a new issue