UNPKG

hravemzdy.procezor

Version:

payroll-procezor Salary, Health, Social, Taxing Properties for years 2010-2022

198 lines 10.7 kB
"use strict"; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResultBuilder = void 0; var VersionCode_1 = require("../service_types/VersionCode"); var hravemzdy_legalios_1 = require("hravemzdy.legalios"); var TermCalcul_1 = require("./TermCalcul"); var TermResultError_1 = require("../service_errors/TermResultError"); var result_1 = require("@badrap/result"); var ArticleDafine_1 = require("../service_types/ArticleDafine"); var MonthCode_1 = require("../service_types/MonthCode"); var ContractCode_1 = require("../service_types/ContractCode"); var PositionCode_1 = require("../service_types/PositionCode"); var VariantCode_1 = require("../service_types/VariantCode"); var TermTarget_1 = require("../service_types/TermTarget"); var DependencyGraph_1 = require("./DependencyGraph"); var ResultBuilder = /** @class */ (function () { function ResultBuilder() { this.firstOrDefaultConcept = function (array, item) { return array.find(function (x) { return (x.code.value === item.value); }); }; this.firstOrDefaultTarget = function (array, item) { return array.find(function (x) { return (x.article.value === item.value); }); }; this.firstOrDefaultPath = function (array, item) { return array.find(function (x) { return (x[0].code.value === item.value); }); }; this.Version = VersionCode_1.VersionCode.new(); this.PeriodInit = hravemzdy_legalios_1.Period.new(); this.ArticleOrder = new Array(); this.ArticlePaths = new Map(); this.ArticleModel = new Array(); this.ConceptModel = new Array(); } ResultBuilder.prototype.TargetCompare = function (termOrder) { var codeOrder = termOrder.map(function (x) { return x.code; }); var compareTo = function (xIndex, yIndex) { if (xIndex === -1 && yIndex === -1) { return 0; } if (xIndex === -1 && yIndex !== -1) { return -1; } if (xIndex !== -1 && yIndex === -1) { return 1; } if (xIndex > yIndex) { return 1; } if (xIndex < yIndex) { return -1; } return 0; }; var finderFun = function (target) { return function (x) { return x.value === target.article.value; }; }; return function (x, y) { var xIndex = codeOrder.findIndex(finderFun(x)); var yIndex = codeOrder.findIndex(finderFun(y)); return compareTo(xIndex, yIndex); }; }; ResultBuilder.prototype.InitWithPeriod = function (version, period, articleFactory, conceptFactory) { var _a; this.Version = version; this.PeriodInit = period; this.ArticleModel = articleFactory.GetSpecList(period, version); this.ConceptModel = conceptFactory.GetSpecList(period, version); var dependencyGraph = new DependencyGraph_1.DependencyGraph(); _a = dependencyGraph.InitGraphModel(this.ArticleModel, this.ConceptModel), this.ArticleOrder = _a[0], this.ArticlePaths = _a[1]; return true; }; ResultBuilder.prototype.GetResults = function (ruleset, contractTerms, positionTerms, targets, calcArticles) { var calculTargets = this.BuildCalculsList(this.PeriodInit, ruleset, contractTerms, positionTerms, targets, calcArticles); var calculResults = this.BuildResultsList(this.PeriodInit, ruleset, calculTargets); return calculResults; }; ResultBuilder.prototype.BuildCalculsList = function (period, ruleset, contractTerms, positionTerms, targets, calcArticles) { var _this = this; var specDefines = Array.from(calcArticles) .map(function (a) { return Array.from(_this.ArticleModel).find(function (m) { return m.code.value === a.value; }); }); var calcDefines = Array.from(specDefines).filter(function (s) { return (s !== undefined); }) .map(function (x) { return ArticleDafine_1.ArticleDefine.get(x.code.value, x.seqs.value, x.role.value); }); var targetsSpec = this.AddFinDefToTargets(period, ruleset, contractTerms, positionTerms, Array.from(targets), calcDefines); var targetsStep = this.AddExternToTargets(period, ruleset, contractTerms, positionTerms, targetsSpec); var calculsList = this.AddTargetToCalculs(targetsStep); return calculsList; }; ResultBuilder.prototype.BuildResultsList = function (period, ruleset, calculs) { var _this = this; var reduceFunc = function (agr, x, idx, array) { return _this.MergeResults.apply(_this, __spreadArray([agr], Array.from(x.GetResults(period, ruleset, agr)), false)); }; var resultsInit = new Array(); return Array.from(calculs).reduce(reduceFunc, resultsInit); }; ResultBuilder.prototype.MergeResults = function (results) { var _a; var resultValues = []; for (var _i = 1; _i < arguments.length; _i++) { resultValues[_i - 1] = arguments[_i]; } return (_a = Array.from(results)).concat.apply(_a, resultValues); }; ResultBuilder.prototype.AddFinDefToTargets = function (period, ruleset, contractTerms, positionTerms, targets, calcDefines) { return this.MergeListPendings(period, ruleset, contractTerms, positionTerms, targets, calcDefines); }; ResultBuilder.prototype.AddExternToTargets = function (period, ruleset, contractTerms, positionTerms, targets) { var _this = this; var reduceFunc = function (agr, item, idx, array) { return _this.MergePendings(period, ruleset, contractTerms, positionTerms, agr, item); }; var targetsInit = Array.from(targets); var targetList = Array.from(targets).reduce(reduceFunc, targetsInit); var targetSort = Array.from(targetList).sort(this.TargetCompare(this.ArticleOrder)); return targetSort; }; ResultBuilder.prototype.AddDefinesToTargets = function (period, ruleset, contractTerms, positionTerms, targets, defines) { var _this = this; return Array.from(defines).flatMap(function (x) { return Array.from(_this.GetTargetList(period, ruleset, _this.ConceptModel, contractTerms, positionTerms, Array.from(targets).filter(function (t) { return t.article === x.code; }), x.code, x.role)); }); }; ResultBuilder.prototype.AddTargetToCalculs = function (targets) { var _this = this; var targetsRets = Array.from(targets).map(function (x) { var articleSpec = Array.from(_this.ArticleModel).find(function (a) { return a.code === x.article; }); return new TermCalcul_1.TermCalcul(x, articleSpec, _this.GetCalculFunc(_this.ConceptModel, x.concept)); }); return targetsRets; }; ResultBuilder.prototype.MergePendings = function (period, ruleset, contractTerms, positionTerms, targets, target) { var _this = this; var resultList = Array.from(targets); var pendingsSpec = this.firstOrDefaultPath(Array.from(this.ArticlePaths.entries()), target.article); if (pendingsSpec === undefined) { return resultList; } var pendingsPath = pendingsSpec[1]; var reduceFunc = function (agr, def, idx, array) { return _this.MergeItemPendings(period, ruleset, contractTerms, positionTerms, agr, def); }; if (pendingsPath !== undefined) { resultList = Array.from(Array.from(pendingsPath).reduce(reduceFunc, resultList)); } return resultList; }; ResultBuilder.prototype.MergeItemPendings = function (period, ruleset, contractTerms, positionTerms, targets, articleDefs) { var resultList = Array.from(targets); var initTargets = Array.from(targets).filter(function (x) { return x.article.value === articleDefs.code.value; }); var targetList = this.GetTargetList(period, ruleset, this.ConceptModel, contractTerms, positionTerms, initTargets, articleDefs.code, articleDefs.role); resultList = Array.from(resultList).concat(Array.from(targetList)); return resultList; }; ResultBuilder.prototype.MergeListPendings = function (period, ruleset, contractTerms, positionTerms, targets, calcDefines) { var resultList = Array.from(targets); var defineList = Array.from(calcDefines).filter(function (x) { return Array.from(targets).find(function (t) { return t.article === x.code; }) === undefined; }); var targetList = this.AddDefinesToTargets(period, ruleset, contractTerms, positionTerms, targets, defineList); resultList = Array.from(resultList).concat(Array.from(targetList)); return resultList; }; ResultBuilder.prototype.GetCalculFunc = function (conceptsModel, concept) { var conceptSpec = this.firstOrDefaultConcept(Array.from(conceptsModel), concept); if (conceptSpec === null) { return this.NotFoundCalculFunc; } return conceptSpec.resultDelegate; }; ResultBuilder.prototype.GetTargetList = function (period, ruleset, conceptsModel, contractTerms, positionTerms, targets, article, concept) { var monthCode = MonthCode_1.MonthCode.get(period.code); var variant = VariantCode_1.VariantCode.get(1); var conceptSpec = Array.from(conceptsModel).find(function (a) { return a.code.value === concept.value; }); if (conceptSpec === undefined) { var contract = ContractCode_1.ContractCode.new(); var position = PositionCode_1.PositionCode.new(); return [new TermTarget_1.TermTarget(monthCode, contract, position, variant, article, concept)]; } return conceptSpec.defaultTargetList(article, period, ruleset, monthCode, contractTerms, positionTerms, targets, variant); }; ResultBuilder.prototype.NotFoundCalculFunc = function (target, spec, period, ruleset, results) { var resultError = TermResultError_1.TermResultError.CreateNoResultFuncError(period, target); return new Array(result_1.Result.err(resultError)); }; return ResultBuilder; }()); exports.ResultBuilder = ResultBuilder; //# sourceMappingURL=ResultBuilder.js.map