import { Injector } from './injector';
/**
* Creates a salary injector
* @class
*/
class InjectorSalary extends Injector {
/**
* @param {struct} skv_config Struct passed in when initializing the injector
* @param {array} arr_tax_years Array of tax years to add basic salary to
*/
constructor(skv_config = {}, arr_tax_years = []) {
super();
this.valid_keys = ['salary'];
if (!this.validate(this.valid_keys)) {
throw new Error('Invalid key passed in to InjectorSalary');
}
this.skv_config = skv_config;
this.arr_tax_years = InjectorSalary.setup(this.skv_config, arr_tax_years);
}
/**
* Do the setup
* @param {struct} skv_config Struct passed in when initializing the injector
* @param {array} arr_tax_years Array of tax years to add basic salary to
* @returns {array} Amended tax years
*/
static setup(skv_config, arr_tax_years) {
const arr_temp = arr_tax_years;
const cnt_arr_temp = arr_temp.length;
for (let i = 0; i < cnt_arr_temp; i += 1) {
// ratio for months in taxed year
const coverage_ratio = arr_temp[i].months_occupied / 12;
const skv_temp = {};
skv_temp.name = 'Salary';
skv_temp.value = skv_config.salary * coverage_ratio;
skv_temp.is_benefit = false;
skv_temp.is_employee_nic_taxable = true;
skv_temp.is_provided_by_employer = true;
skv_temp.is_taxed_at_source = false;
skv_temp.is_relief = false;
if (!Object.prototype.hasOwnProperty.call(arr_temp[i], 'arr_income')) {
arr_temp[i].arr_income = [];
}
arr_temp[i].arr_income.push(skv_temp);
}
return arr_temp;
}
}
export {
InjectorSalary,
};