//[Security(ServiceID = PermissionContants.SuperMamalonPermission.ServiceID, // UseAuthorization = false, // UseSession = false, // Permissions = new[] { PermissionContants.SuperMamalonPermission.PermissionID }, // ResourceID = PermissionContants.SuperMamalonPermission.CotoRRA_Cloud_ID_String, // UserInstanceAsOwner = false)] public async Task <ActionResult <string> > GetByEmployeeId(Guid companyId, Guid instanceId, Guid employeeId) { List <OverdraftDTO> overdraftDTOs = new List <OverdraftDTO>(); JsonResult result = new JsonResult(overdraftDTOs); var _blobStorageUtil = new BlobStorageUtil(instanceId); await _blobStorageUtil.InitializeAsync(); try { var middlewareManager = new MiddlewareManager <Overdraft>(new BaseRecordManager <Overdraft>(), new OverdraftValidator()); //get historic overdraft last 3 months and stamped only var overdrafts = await middlewareManager.FindByExpressionAsync(p => p.company == companyId && p.InstanceID == instanceId && p.HistoricEmployee.EmployeeID == employeeId && p.Active && p.OverdraftStatus == OverdraftStatus.Stamped, companyId, new string[] { "HistoricEmployee", "PeriodDetail", "PeriodDetail.Period", "OverdraftDetails", "OverdraftDetails.ConceptPayment" }); if (overdrafts.Any()) { var overdraftManager = new OverdraftManager(); await overdrafts.ForEachAsync(async historicOverdraft => { var totals = overdraftManager.GetTotals(historicOverdraft, new Core.Utils.RoundUtil("MXN")); //Fill DTO var overdraftDTO = _mapper.Map <Overdraft, OverdraftDTO>(historicOverdraft); overdraftDTO.Total = totals.Total; overdraftDTO.TotalPerceptions = totals.TotalSalaryPayments; overdraftDTO.TotalDeductions = totals.TotalDeductionPayments; overdraftDTO.InitialDate = historicOverdraft.PeriodDetail.InitialDate; overdraftDTO.FinalDate = historicOverdraft.PeriodDetail.FinalDate; //Period Traduction overdraftDTO.PeriodTypeName = PaymentPeriodicityTraduction.GetTraduction(historicOverdraft.PeriodDetail.Period.PaymentPeriodicity); try { if (overdraftDTO.UUID != Guid.Empty) { overdraftDTO.XML = await _blobStorageUtil.DownloadDocumentAsync($"{overdraftDTO.UUID}.xml"); } } catch { //No se pudo obtener el xml asociado. overdraftDTO.XML = String.Empty; } //Perceptions and Deductions historicOverdraft.OverdraftDetails.OrderBy(p => p.ConceptPayment.Code).ToList().ForEach(detail => { if (detail.ConceptPayment.ConceptType == ConceptType.SalaryPayment) { overdraftDTO.Perceptions.Add(new PerceptionDTO() { Description = detail.ConceptPayment.Name, Amount = detail.Amount }); } else if (detail.ConceptPayment.ConceptType == ConceptType.DeductionPayment) { overdraftDTO.Deductions.Add(new DeductionDTO() { Description = detail.ConceptPayment.Name, Amount = detail.Amount }); } }); overdraftDTOs.Add(overdraftDTO); }, Environment.ProcessorCount); result = new JsonResult(overdraftDTOs); } } catch (Exception ex) { if (ex != null) { var exception = ex; while (exception.Message.Contains("Exception has been thrown by the target of an invocation")) { exception = exception.InnerException; } throw exception; } } return(result); }
public async Task <IReadOnlyList <Result <List <OverdraftDTO> > > > GetOverByEmployeeID(IReadOnlyList <IDEmployeeDataloaderParam> data) { var instanceID = data.FirstOrDefault().instanceID; var companyID = data.FirstOrDefault().companyID; var employeeIDs = data.Select(x => (Guid?)Guid.Parse(x.employeeID)).ToList(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <Overdraft, OverdraftDTO>(); }); var _blobStorageUtil = new BlobStorageUtil(Guid.Parse(instanceID)); await _blobStorageUtil.InitializeAsync(); var _mapper = config.CreateMapper(); List <Result <List <OverdraftDTO> > > result = new List <Result <List <OverdraftDTO> > >(); var middlewareManager = new MiddlewareManager <Overdraft>(new BaseRecordManager <Overdraft>(), new OverdraftValidator()); var historicOverdrafts = await middlewareManager.FindByExpressionAsync(p => p.company == Guid.Parse(companyID) && p.InstanceID == Guid.Parse(instanceID) && employeeIDs.Contains( p.HistoricEmployee.EmployeeID ) && p.PeriodDetail.FinalDate >= DateTime.UtcNow.AddMonths(-3) && p.Active && p.OverdraftStatus == OverdraftStatus.Stamped, Guid.Parse(companyID), new string[] { "HistoricEmployee", "PeriodDetail", "OverdraftDetails", "OverdraftDetails.ConceptPayment" }); await employeeIDs.ForEachAsync(async empID => { var overs = historicOverdrafts.Where(x => x.EmployeeID == empID); List <OverdraftDTO> overdraftDTOs = new List <OverdraftDTO>(); if (overs.Any()) { var overdraftManager = new OverdraftManager(); await overs.ForEachAsync(async historicOverdraft => { var totals = overdraftManager.GetTotals(historicOverdraft, new Core.Utils.RoundUtil("MXN")); //Fill DTO var overdraftDTO = _mapper.Map <Overdraft, OverdraftDTO>(historicOverdraft); overdraftDTO.Total = totals.Total; overdraftDTO.TotalPerceptions = totals.TotalSalaryPayments; overdraftDTO.TotalDeductions = totals.TotalDeductionPayments; overdraftDTO.InitialDate = historicOverdraft.PeriodDetail.InitialDate; overdraftDTO.FinalDate = historicOverdraft.PeriodDetail.FinalDate; try { if (overdraftDTO.UUID != Guid.Empty) { overdraftDTO.XML = await _blobStorageUtil.DownloadDocumentAsync($"{overdraftDTO.UUID}.xml"); } } catch { //No se pudo obtener el xml asociado. overdraftDTO.XML = String.Empty; } overdraftDTOs.Add(overdraftDTO); }, Environment.ProcessorCount); result.Add(overdraftDTOs); } }, Environment.ProcessorCount); return(result); }