Пример #1
0
        public async Task <JsonResult> Calculate(CalculateSettlementProcessParams data)
        {
            data.IdentityWorkID = SessionModel.CompanyID;
            data.InstanceID     = SessionModel.InstanceID;
            data.user           = SessionModel.IdentityID;
            var res = await settlementProcessClient.Calculate(data);

            return(Json(res));
        }
        private async Task <Overdraft> GenerateCompensationOverdraft(CalculateSettlementProcessParams parameters, List <ConceptPayment> allConcepts)
        {
            var satCodes = COMPENSATIONSATCODES;

            var compensationConcepts         = allConcepts.Where(x => x.Code == ISRFINIQUITOCONCEPTCODE || satCodes.Contains(x.SATGroupCode));
            var conceptsFromSettlementScreen = compensationConcepts.Where(x => parameters.ConceptsToApply.Select(x => x.Code).Contains(x.Code));
            var selectedCodesByUser          = parameters.ConceptsToApply.Where(x => x.Apply).Select(y => y.Code);

            var conceptsSelectedByUser = conceptsFromSettlementScreen.Where(x => selectedCodesByUser.Contains(x.Code));


            var overdraft = BuildOverdraft(parameters.IdentityWorkID, parameters.InstanceID, parameters.user, parameters.EmployeeID, parameters.PeriodDetailID, OverdraftType.CompensationSettlement);

            overdraft.Name        = "Sobrerecibo finiquito compensación";
            overdraft.Description = "Sobrerecibo finiquito compensación";
            var applyIndemnization = compensationConcepts.Any(x => selectedCodesByUser.Contains(x.Code));

            if (!applyIndemnization)
            {
                return(null);
            }

            List <OverdraftDetail> overdraftDetailsToADD = new List <OverdraftDetail>();

            compensationConcepts.ForEach(concept =>
            {
                //si esta en la lista de rubros
                if (conceptsFromSettlementScreen.Any(x => x.ID == concept.ID))
                {
                    //Si aplica
                    if (conceptsSelectedByUser.Any(y => y.ID == concept.ID))
                    {
                        var capturedData = parameters.ConceptsToApply.FirstOrDefault(p => p.Code == concept.Code);
                        var overDetail   = BuildEmptyOverdraftDetail(parameters.IdentityWorkID, concept.ID, parameters.InstanceID, overdraft.ID, parameters.user, capturedData.TotalDays);
                        overdraftDetailsToADD.Add(overDetail);
                    }
                    //Cuando no aplica no se agrega
                }
                else
                {
                    int value = 0;
                    //Si no tiene que ver con la lista se genera el detail
                    var overDetail = BuildEmptyOverdraftDetail(parameters.IdentityWorkID, concept.ID, parameters.InstanceID, concept.ID, parameters.user, value);//cero para automatico
                    overdraftDetailsToADD.Add(overDetail);
                }
            });

            overdraft.OverdraftDetails = overdraftDetailsToADD;

            var liabilitesDetails = GenerateLiabilities(parameters, allConcepts);

            overdraft.OverdraftDetails.AddRange(liabilitesDetails);

            await SaveOverdraft(overdraft, parameters.IdentityWorkID);

            return(await Calculate(overdraft, parameters.IdentityWorkID, parameters.InstanceID, parameters.user));
        }
Пример #3
0
        public async Task <List <Overdraft> > Calculate(CalculateSettlementProcessParams parameters)
        {
            var result = await ServiceHelperExtensions.CallRestServiceAsync(Format.JSON, RestMethod.POST, _authorizationHeader,
                                                                            new Uri($"{_cotorraUri}/Calculate"), new object[] { parameters }).ContinueWith((i) =>
            {
                if (i.Exception != null)
                {
                    throw i.Exception;
                }
                return(i.Result);
            });

            return(JsonConvert.DeserializeObject <List <Overdraft> >(result));
        }
        private List <OverdraftDetail> GenerateLiabilities(CalculateSettlementProcessParams parameters, List <ConceptPayment> allConcepts)
        {
            var liabilitiConcepts = allConcepts.Where(x => x.ConceptType == ConceptType.LiabilityPayment && x.AutomaticDismissal);

            var overdraftDetails = new List <OverdraftDetail>();


            liabilitiConcepts.ForEach(concept =>
            {
                var overDetail = BuildEmptyOverdraftDetail(parameters.IdentityWorkID, concept.ID, parameters.InstanceID, concept.ID, parameters.user, 0);
                overdraftDetails.Add(overDetail);
            });

            return(overdraftDetails);
        }
        public async Task <List <Overdraft> > Calculate(CalculateSettlementProcessParams parameters)
        {
            Guid identityWorkID = parameters.IdentityWorkID;
            Guid instanceId     = parameters.InstanceID;
            Guid periodDetailID = parameters.PeriodDetailID;
            Guid employeeID     = parameters.EmployeeID;
            var  oversGenerated = new List <Overdraft>();

            var codes = parameters.ConceptsToApply.Select(x => x.Code).ToList();

            codes.Add(ISRFINIQUITOCONCEPTCODE);

            var allConcepts = await GetAllConceptsSettlement(codes, COMPENSATIONSATCODES, identityWorkID,
                                                             instanceId);

            var employeeManager = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator());
            var employee        = employeeManager.FindByExpressionAsync(x => x.ID == employeeID && x.InstanceID == instanceId && x.Active == true, identityWorkID);

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var previousSettlementOverdrafts = await GetOverdrafts(parameters.EmployeeID,
                                                                       parameters.InstanceID, parameters.IdentityWorkID,
                                                                       new List <OverdraftType>() { OverdraftType.OrdinarySettlement,
                                                                                                    OverdraftType.CompensationSettlement });
                await UpdateEmployee(parameters, (await employee).FirstOrDefault());

                await DeleteOverdrafts(previousSettlementOverdrafts, parameters.IdentityWorkID);

                oversGenerated.Add(await GenerateOrdinaryOverdraft(parameters, allConcepts));
                var compensation = await GenerateCompensationOverdraft(parameters, allConcepts);

                if (compensation != null)
                {
                    oversGenerated.Add(compensation);
                }

                scope.Complete();
            }

            oversGenerated.ForEach(over => over.OverdraftDetails = over.OverdraftDetails.OrderBy(x => x.ConceptPayment.Code).ToList());
            return(oversGenerated);
        }
Пример #6
0
        public async Task <List <Overdraft> > Calculate(CalculateSettlementProcessParams parameters)
        {
            SettlementProcessManager mgr = new SettlementProcessManager();

            return(await mgr.Calculate(parameters));
        }
        /// <summary>
        /// Calculates the overdraft for settlement.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public async Task <Overdraft> GenerateOrdinaryOverdraft(CalculateSettlementProcessParams parameters, List <ConceptPayment> allConcepts)
        {
            var activeOverdraft = (await GetOverdrafts(parameters.EmployeeID, parameters.InstanceID,
                                                       parameters.IdentityWorkID, parameters.PeriodDetailID, new List <OverdraftType>()
            {
                OverdraftType.Ordinary
            })).FirstOrDefault();

            if (activeOverdraft == null)
            {
                throw new CotorraException(45001, "45001", "No es posible finiquitar a este empleado no tiene recibos activos.", null);
            }

            var reportedForUserConceptsOrdinarySettlementDetail = activeOverdraft.OverdraftDetails.Where(x => x.IsTotalAmountCapturedByUser || x.IsValueCapturedByUser || x.IsAmount1CapturedByUser || x.IsAmount2CapturedByUser || x.IsAmount3CapturedByUser || x.IsAmount4CapturedByUser);

            var settlementConcepts           = allConcepts;
            var conceptsFromSettlementScreen = settlementConcepts.Where(x => parameters.ConceptsToApply.Select(x => x.Code).Contains(x.Code));
            var automaticSettlementConcepts  = settlementConcepts.Where(x => x.AutomaticDismissal);

            var selectedCodesByUser    = parameters.ConceptsToApply.Where(x => x.Apply).Select(y => y.Code);
            var unSelectedCodesByUser  = parameters.ConceptsToApply.Where(x => !x.Apply).Select(y => y.Code);
            var conceptsSelectedByUser = conceptsFromSettlementScreen.Where(x => selectedCodesByUser.Contains(x.Code));


            List <ConceptPayment>  conceptsToADD         = new List <ConceptPayment>();
            List <OverdraftDetail> overdraftDetailsToADD = new List <OverdraftDetail>();


            //Get Overdraft

            var settlementOvedraft = BuildOverdraft(parameters.IdentityWorkID, parameters.InstanceID, parameters.user, parameters.EmployeeID, parameters.PeriodDetailID, OverdraftType.OrdinarySettlement);

            ///Revisamos los capturados por el usuario en el recibo ordinario
            reportedForUserConceptsOrdinarySettlementDetail.ForEach(overdraftDetail =>
            {
                //si esta en la lista de rubros
                if (conceptsFromSettlementScreen.Any(x => x.ID == overdraftDetail.ConceptPaymentID))
                {
                    //Si aplica
                    if (conceptsSelectedByUser.Any(y => y.ID == overdraftDetail.ConceptPaymentID))
                    {
                        var capturedData = parameters.ConceptsToApply.FirstOrDefault(p => p.Code == overdraftDetail.ConceptPayment.Code);
                        var overDetail   = BuildEmptyOverdraftDetail(parameters.IdentityWorkID, overdraftDetail.ConceptPaymentID, parameters.InstanceID, settlementOvedraft.ID, parameters.user, capturedData.TotalDays);
                        overdraftDetailsToADD.Add(overDetail);
                    }
                    //Cuando no aplica no se agrega
                }
                else
                {
                    //Si no tiene que ver con la lista se manda como va pero en un objeto nuevo
                    overdraftDetail.ID             = Guid.NewGuid();
                    overdraftDetail.OverdraftID    = settlementOvedraft.ID;
                    overdraftDetail.ConceptPayment = null;
                    overdraftDetailsToADD.Add(overdraftDetail);
                }
            });


            settlementConcepts.ForEach(automaticSettlementConcept =>
            {
                //si esta en la lista de rubros
                if (conceptsFromSettlementScreen.Any(x => x.ID == automaticSettlementConcept.ID))
                {
                    //Si aplica
                    if (conceptsSelectedByUser.Any(y => y.ID == automaticSettlementConcept.ID))
                    {
                        var capturedData = parameters.ConceptsToApply.FirstOrDefault(p => p.Code == automaticSettlementConcept.Code);
                        var overDetail   = BuildEmptyOverdraftDetail(parameters.IdentityWorkID, automaticSettlementConcept.ID, parameters.InstanceID, settlementOvedraft.ID, parameters.user, capturedData.TotalDays);
                        overdraftDetailsToADD.Add(overDetail);
                    }
                    //Cuando no aplica no se agrega
                }
                else
                {
                    int value = 0;
                    if (automaticSettlementConcept.Code == 29 && automaticSettlementConcept.ConceptType == ConceptType.SalaryPayment)
                    {
                        var conceptToOverride = parameters.ConceptsToApply.Where(x => x.Code == 29).FirstOrDefault();
                        if (conceptToOverride != null)
                        {
                            value = (int)conceptToOverride.TotalDays;
                        }
                    }
                    //Si no tiene que ver con la lista se genera el detail
                    var overDetail = BuildEmptyOverdraftDetail(parameters.IdentityWorkID, automaticSettlementConcept.ID, parameters.InstanceID, settlementOvedraft.ID, parameters.user, value);//cero para automatico??
                    overdraftDetailsToADD.Add(overDetail);
                }
            });


            settlementOvedraft.OverdraftDetails = overdraftDetailsToADD;
            await SaveOverdraft(settlementOvedraft, parameters.IdentityWorkID);

            return(await Calculate(settlementOvedraft, parameters.IdentityWorkID,
                                   parameters.InstanceID, parameters.user));
        }
 private async Task UpdateEmployee(CalculateSettlementProcessParams parameters, Employee employee)
 {
     employee.SettlementSalaryBase = parameters.SettlementBaseSalary;
     var employeeManager = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator());
     await employeeManager.UpdateAsync(new List <Employee>() { employee }, parameters.IdentityWorkID);
 }
 public Task <List <Overdraft> > Calculate(CalculateSettlementProcessParams parameters)
 {
     return(_client.Calculate(parameters));
 }