import { EmployeeMin } from './employeeMin'; import { Base } from './base'; import { Dictionary } from './dictionary'; import { Loan } from './loan'; import { Period } from './period'; export class Withdraw extends Base { withdrawID: string; uid: string; amountToWithdraw: number; financialReturnAmount: number; prepaymentInterest: number; type: string; typeID: number; date: Date; loan?: Loan; constructor(data: any | null = null) { super(); this.withdrawID = ''; this.amountToWithdraw = 0; this.financialReturnAmount = 0; this.prepaymentInterest = 0; this.type = ''; this.typeID = 0; this.date = new Date(); this.loan = new Loan(); this.load(data); } } export class ScheduleDateForDisplay { month: string; totalContribution: number; totalExtrasContribution: number; totalWithdrawals: number; total: number; } export class Beneficiary extends Base { index: number; names: string; firstLastName: string; secondLastName: string; relation: string; percentage: number; constructor(data: any | null = null) { super(); this.index = 0; this.names = ''; this.firstLastName = ''; this.secondLastName = ''; this.relation = ''; this.percentage = 0; this.load(data); } } export class ScheduleDate extends Base { comments: string; depositID: string; paid: boolean; depositDate: Date; voluntaryEmployeeContribution: number; salaryEmployeeContribution: number; annualPerformanceContribution: number; profitSharingContribution: number; targetBonusContribution: number; yearEndAndPerformanceBonusContribution: number; voluntaryCompanyContribution: number; salaryCompanyContribution: number; withdraw: number; skipped: boolean; constructor(data: any | null = null) { super(); this.comments = ''; this.depositID = ''; this.paid = false; this.depositDate = new Date(); this.voluntaryEmployeeContribution = 0; this.salaryEmployeeContribution = 0; this.annualPerformanceContribution = 0; this.profitSharingContribution = 0; this.targetBonusContribution = 0; this.yearEndAndPerformanceBonusContribution = 0; this.voluntaryCompanyContribution = 0; this.salaryCompanyContribution = 0; this.withdraw = 0; this.skipped = false; this.load(data); } get totalContribution(): number { if (!this.paid) { return 0; } return this.voluntaryEmployeeContribution + this.salaryEmployeeContribution; } get totalExtrasContribution(): number { if (!this.paid) { return 0; } return this.annualPerformanceContribution + this.profitSharingContribution + this.targetBonusContribution + this.yearEndAndPerformanceBonusContribution; } get totalWithdrawals(): number { if (!this.paid) { return 0; } return this.withdraw; } get scheduleDateTotals(): number { return (this.totalContribution + this.totalExtrasContribution) - this.totalWithdrawals; } } export class PermanentSaving extends Base { subscriptionDate: Date; employeeID: string; employeeRef: EmployeeMin; scheduleDates: Dictionary; beneficiaries: Dictionary; withdraws: Dictionary; annualPerformanceBonusPercentage: number; profitSharingPercentage: number; targetBonusPercentage: number; yearEndAndPerformanceBonusPercentage: number; contributionAmount: number; currentAmount: number; period: Period; active: boolean; status: string; constructor(data: any | null = null) { super(); this.subscriptionDate = new Date(); this.employeeID = ''; this.employeeRef = new EmployeeMin(); this.scheduleDates = new Dictionary(ScheduleDate); this.beneficiaries = new Dictionary(Beneficiary); this.withdraws = new Dictionary(Withdraw); this.period = new Period(); this.annualPerformanceBonusPercentage = 0; this.profitSharingPercentage = 0; this.targetBonusPercentage = 0; this.yearEndAndPerformanceBonusPercentage = 0; this.contributionAmount = 0; this.currentAmount = 0; this.active = false; this.status = ''; this.load(data); const paid = this.scheduleDates.Values().filter(element => element.paid); if (paid.length) { this.currentAmount = paid.map(element => element.totalContribution).reduce(((prev, next) => prev + next), 0); } } get groupScheduleDates(): any { const group: any = {}; this.scheduleDates.Values().forEach(element => { const year = element.depositDate.getFullYear().toString(); const month = String(element.depositDate.getMonth() + 1); if (group.hasOwnProperty(year)) { if (group[year].hasOwnProperty(month)) { group[year][month].push(element); } else { group[year][month] = [element]; } } else { group[year] = { [month]: [element] }; } }); return group; } get groupScheduleDatesForDisplay(): ScheduleDateForDisplay { const months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']; const group: any = {}; this.scheduleDates.Values().forEach(element => { const year = element.depositDate.getFullYear().toString(); const month = element.depositDate.getMonth(); if (group.hasOwnProperty(year)) { if (group[year].hasOwnProperty(month)) { const monthInfo = group[year][month]; monthInfo.month = months[month]; monthInfo.totalContribution = monthInfo.totalContribution + element.totalContribution; monthInfo.totalExtrasContribution = monthInfo.totalExtrasContribution + element.totalExtrasContribution; monthInfo.totalWithdrawals = monthInfo.totalWithdrawals + element.totalWithdrawals; monthInfo.total = (monthInfo.totalContribution + monthInfo.totalExtrasContribution) - monthInfo.totalWithdrawals; group[year][month] = monthInfo; } else { const monthInfo: ScheduleDateForDisplay = new ScheduleDateForDisplay(); monthInfo.month = months[month]; monthInfo.totalContribution = element.totalContribution; monthInfo.totalExtrasContribution = element.totalExtrasContribution; monthInfo.totalWithdrawals = element.totalWithdrawals; monthInfo.total = (monthInfo.totalContribution + monthInfo.totalExtrasContribution) - monthInfo.totalWithdrawals; group[year][month] = monthInfo; } } else { const monthInfo: ScheduleDateForDisplay = new ScheduleDateForDisplay(); monthInfo.month = months[month]; monthInfo.totalContribution = element.totalContribution; monthInfo.totalExtrasContribution = element.totalExtrasContribution; monthInfo.totalWithdrawals = element.totalWithdrawals; monthInfo.total = (monthInfo.totalContribution + monthInfo.totalExtrasContribution) - monthInfo.totalWithdrawals; group[year] = {}; group[year][month] = monthInfo; } }); const gbm: any = {}; Object.keys(group).forEach(key => { const year = group[key]; const array = []; Object.keys(year).forEach(month => { array.push(year[month]); }); gbm[key] = array; }); return gbm; } get total(): number { return this.scheduleDates.Values().filter(element => element.paid).map(element => element.totalContribution).reduce(((prev, next) => prev + next), 0); } get totalExtras(): number { return this.scheduleDates.Values().filter(element => element.paid).map(element => element.totalExtrasContribution).reduce(((prev, next) => prev + next), 0); } get totalWithdrawals(): number { return this.withdraws.Values().map(element => element.amountToWithdraw).reduce(((next, prev) => next + prev), 0); } get withdrawsInYear(): any { const group: any = {}; this.withdraws.Values().forEach(element => { const year = element.date.getFullYear().toString(); if (group.hasOwnProperty(year)) { group[year] = group[year] + 1; } else { group[year] = 1; } }); return group; } get rulesURL(): string | null { if (this.period && this.period.savingParameters.fileUploaded.downloadURL) { return this.period.savingParameters.fileUploaded.downloadURL; } return null; } }