/// <summary> /// Calculation generic /// </summary> /// <param name="calculateParams"></param> /// <returns></returns> public async Task <ICalculateResult> CalculateAsync(ICalculateParams calculateParams) { //result instance var calculateGenericResult = new CalculateGenericResult(); var genericParams = calculateParams as CalculateGenericParams; var calculateOverdraftParams = new CalculateOverdraftParams() { DeleteAccumulates = true, SaveOverdraft = false, IdentityWorkID = genericParams.IdentityWorkID, InstanceID = genericParams.InstanceID, OverdraftID = genericParams.OverdraftID.Value, ResetCalculation = false, }; var overdraftCalculationManager = new OverdraftCalculationManager(); await overdraftCalculationManager.CalculateAsync(calculateOverdraftParams); var calculateResult = overdraftCalculationManager.CalculateFormula(genericParams.Formula); calculateGenericResult.Result = calculateResult.Result; calculateGenericResult.ResultText = calculateResult.ResultText; calculateGenericResult.CalculateArguments = calculateResult.CalculateArguments; return(calculateGenericResult); }
public async Task <CalculateOverdraftResult> CalculateOverdraftAsync(CalculateOverdraftParams calculateOverdraftParams) { ICalculationManager calculationManager = new OverdraftCalculationManager(); var calculationResult = await calculationManager.CalculateAsync(calculateOverdraftParams) as CalculateOverdraftResult; return(calculationResult); }
private async Task Calculate(Guid overdraftID, bool restore) { var calculateOverdraftParams = new CalculateOverdraftParams() { IdentityWorkID = SessionModel.CompanyID, InstanceID = SessionModel.InstanceID, OverdraftID = overdraftID, UserID = SessionModel.IdentityID, ResetCalculation = restore, SaveOverdraft = true }; await calculationClient.CalculateOverdraftAsync(calculateOverdraftParams); }
public async Task <CalculateOverdraftResult> CalculateOverdraftAsync(CalculateOverdraftParams calculateOverdraftParams) { //call service async var result = await ServiceHelperExtensions.CallRestServiceAsync(Format.JSON, RestMethod.POST, _authorizationHeader, new Uri($"{_cotorraUri}/CalculateOverdraft"), new object[] { calculateOverdraftParams }).ContinueWith((i) => { if (i.Exception != null) { throw i.Exception; } return(i.Result); }); var calculateGenericResult = JsonConvert.DeserializeObject <CalculateOverdraftResult>(result); return(calculateGenericResult); }
public async Task <CalculateResult> CalculateFormula(ICalculateParams calculateParams, string formula) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //result instance var calculateOverdraftDIParams = calculateParams as CalculateOverdraftDIParams; //Functions params // Para inyectarle a las formulas los datos necesarios para el calculo (1 sola llamada a BD) var dataResponse = await GetDataAsync( calculateOverdraftDIParams.InstanceID, calculateOverdraftDIParams.IdentityWorkID, calculateOverdraftDIParams.UserID); //Fill necesary data to calculate dataResponse = await FillDataAsync(calculateOverdraftDIParams, dataResponse); //Poner en 0 todos los amounts / previous calculation dataResponse.Overdraft.OverdraftDetails.ForEach(p => { p.Taxed = 0M; p.Exempt = 0M; p.IMSSTaxed = 0M; p.IMSSExempt = 0M; if (calculateOverdraftDIParams.ResetCalculation) { p.IsAmount1CapturedByUser = false; p.IsAmount2CapturedByUser = false; p.IsAmount3CapturedByUser = false; p.IsAmount4CapturedByUser = false; p.IsTotalAmountCapturedByUser = false; p.IsValueCapturedByUser = false; p.Value = 0M; p.Amount = 0M; } }); var calculateOverdraftParams = new CalculateOverdraftParams(); calculateOverdraftParams.DeleteAccumulates = false; calculateOverdraftParams.IdentityWorkID = calculateOverdraftDIParams.IdentityWorkID; calculateOverdraftParams.InstanceID = calculateOverdraftDIParams.InstanceID; calculateOverdraftParams.OverdraftID = dataResponse.Overdraft.ID; calculateOverdraftParams.ResetCalculation = true; calculateOverdraftParams.SaveOverdraft = false; calculateOverdraftParams.UserID = calculateOverdraftDIParams.UserID; FunctionParams functionParams = new FunctionParams(); functionParams.CalculationBaseResult = dataResponse; functionParams.IdentityWorkID = calculateOverdraftParams.IdentityWorkID; functionParams.InstanceID = calculateOverdraftParams.InstanceID; //overdraftDetails - All Perceptions, Deductions and Obligations List <AccumulatedEmployee> accumulatedEmployees = dataResponse.AccumulatedEmployees; var overdraftCalculationManager = new OverdraftCalculationManager(); //Initializate data, arguments, and functions overdraftCalculationManager.Initializate(functionParams); //Perceptions (Overdraft overdraft, List <AccumulatedEmployee> employeeAccumulates) = await overdraftCalculationManager.CalculateByConceptAsync(dataResponse, ConceptType.SalaryPayment, calculateOverdraftParams, null); accumulatedEmployees = employeeAccumulates; dataResponse.Overdraft = overdraft; //Deductions (overdraft, employeeAccumulates) = await overdraftCalculationManager.CalculateByConceptAsync(dataResponse, ConceptType.DeductionPayment, calculateOverdraftParams, new ConcurrentBag <AccumulatedEmployee>(accumulatedEmployees)); accumulatedEmployees = employeeAccumulates; dataResponse.Overdraft = overdraft; //Liabilities //Liability dataResponse.IsLiability = true; (overdraft, employeeAccumulates) = await overdraftCalculationManager.CalculateByConceptAsync(dataResponse, ConceptType.LiabilityPayment, calculateOverdraftParams, new ConcurrentBag <AccumulatedEmployee>(accumulatedEmployees)); dataResponse.Overdraft = overdraft; dataResponse.IsLiability = false; //Ajuste al neto await overdraftCalculationManager.amountAdjustmentAsync(dataResponse.Overdraft, calculateOverdraftParams, dataResponse); var calculareResult = overdraftCalculationManager.CalculateFormula(formula); stopwatch.Stop(); Trace.WriteLine($"Time elapsed in the overdraft di calculation {stopwatch.Elapsed}"); return(calculareResult); }
public async Task Should_Stamp_Payroll_CFDI_Valid() { var xmlCancelacion = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Acuse xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Fecha=\"2020-07-02T16:02:07.2838838\" RfcEmisor=\"KAHO641101B39\"> <Folios xmlns=\"http://cancelacfd.sat.gob.mx\"> <UUID>3377E0AA-C54B-4E9E-BFF2-1D8BA96D5DD4</UUID> <EstatusUUID>201</EstatusUUID> </Folios> <Signature Id=\"SelloSAT\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\"> <SignedInfo> <CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /> <SignatureMethod Algorithm=\"http://www.w3.org/2001/04/xmldsig-more#hmac-sha512\" /> <Reference URI=\"\"> <Transforms> <Transform Algorithm=\"http://www.w3.org/TR/1999/REC-xpath-19991116\"> <XPath>not(ancestor-or-self::*[local-name()='Signature'])</XPath> </Transform> </Transforms> <DigestMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#sha512\" /> <DigestValue>BThmOyTf26Ax25v8Li0oqcP3wyrhW3kjjxOcO1zamRYasNIPcHSnBiRyxmJ449a3gdgAWaz/UKVil3pqcper+g==</DigestValue> </Reference> </SignedInfo> <SignatureValue>6qDGoWoHW5tK2MGNiXU7fI6hfpkbrYTMHafVvIsGRkl9xq2H2YQRvId4CO7B9GGJFbuVMku2IBkpKU/Tscqo9Q==</SignatureValue> <KeyInfo> <KeyName>BF66E582888CC845</KeyName> <KeyValue> <RSAKeyValue> <Modulus>n5YsGT0w5Z70ONPbqszhExfJU+KY3Bscftc2jxUn4wxpSjEUhnCuTd88OK5QbDW3Mupoc61jr83lRhUCjchFAmCigpC10rEntTfEU+7qtX8ud/jJJDB1a9lTIB6bhBN//X8IQDjhmHrfKvfen3p7RxLrFoxzWgpwKriuGI5wUlU=</Modulus> <Exponent>AQAB</Exponent> </RSAKeyValue> </KeyValue> </KeyInfo> </Signature></Acuse>"; var acuse = SerializerXml.DeserializeObject <Schema.CFDI33Nom12.Acuse>(xmlCancelacion); using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); try { var identityWorkId = Guid.NewGuid(); var instanceID = Guid.NewGuid(); var overdraft = await new PayrollStampingManagerUT().CreateRealOverdraftAsync(identityWorkId, instanceID); var periodDetailID = overdraft.PeriodDetailID; //Recalculate var calculateParams = new CalculateOverdraftParams() { DeleteAccumulates = true, IdentityWorkID = identityWorkId, InstanceID = instanceID, OverdraftID = overdraft.ID, ResetCalculation = true, SaveOverdraft = true, UserID = Guid.Empty }; var calculationResult = await new OverdraftCalculationManager().CalculateAsync(calculateParams); overdraft = (calculationResult as CalculateOverdraftResult).OverdraftResult; Assert.True(overdraft.OverdraftDetails.Sum(p => p.Amount) > 0); //Autorización de la nómina var authorizationManager = new AuthorizationManager(); var authorizationParams = new AuthorizationParams() { IdentityWorkID = identityWorkId, InstanceID = instanceID, PeriodDetailIDToAuthorize = periodDetailID, ResourceID = Guid.Empty, user = Guid.Empty }; //autorizacion de la nómina var historicOverdrafts = await authorizationManager.AuthorizationAsync(authorizationParams); //Timbrado var overdraftManager = new MiddlewareManager <Overdraft>(new BaseRecordManager <Overdraft>(), new OverdraftValidator()); var overdraftsPrevious = await overdraftManager.FindByExpressionAsync(p => p.PeriodDetailID == periodDetailID, identityWorkId); var manager = new PayrollStampingManager(); var dateTime = DateTime.Now; var stampingParms = new PayrollStampingParams() { FiscalStampingVersion = FiscalStampingVersion.CFDI33_Nom12, IdentityWorkID = identityWorkId, InstanceID = instanceID, PeriodDetailID = periodDetailID, Detail = new List <PayrollStampingDetail>() { new PayrollStampingDetail() { Folio = "2020", Series = "S1", PaymentDate = dateTime.AddDays(-2), RFCOriginEmployer = null, SNCFEntity = null, OverdraftID = overdraftsPrevious.FirstOrDefault().ID, } }, Currency = Currency.MXN }; var payrollStampingResult = await manager.PayrollStampingAsync(stampingParms); Assert.Contains(payrollStampingResult.PayrollStampingResultDetails, p => p.PayrollStampingResultStatus == PayrollStampingResultStatus.Success); //cancel payroll var cancelStampingManager = new CancelStampingManager(); var cancelParams = new CancelPayrollStampingParams() { FiscalStampingVersion = FiscalStampingVersion.CFDI33_Nom12, IdentityWorkID = identityWorkId, InstanceID = instanceID, OverdraftIDs = overdraftsPrevious.Select(p => p.ID).ToList(), user = Guid.Empty }; await Task.Delay(10000); var cancelationResult = await cancelStampingManager.CancelPayrollStampingAsync(cancelParams); Assert.False(cancelationResult.WithErrors); var cancelManager = new MiddlewareManager <CancelationFiscalDocument>(new BaseRecordManager <CancelationFiscalDocument>(), new CancelationFiscalDocumentValidator()); var cancelations = await cancelManager.FindByExpressionAsync(p => p.InstanceID == instanceID, identityWorkId, new string[] { "CancelationFiscalDocumentDetails" }); Assert.True(cancelations.Any()); var overIds = overdraftsPrevious.Select(p => p.ID).ToList(); var olderOverdrafts = await overdraftManager.FindByExpressionAsync(p => overIds.Contains(p.ID), identityWorkId); Assert.False(olderOverdrafts.Any(p => p.OverdraftStatus != OverdraftStatus.Canceled)); var newOverdrafts = await overdraftManager.FindByExpressionAsync(p => overIds.Contains(p.OverdraftPreviousCancelRelationshipID.Value), identityWorkId); Assert.False(newOverdrafts.Any(p => p.OverdraftPreviousCancelRelationshipID == null)); } catch (Exception ex) { var t = ex.ToString(); Assert.True(false, ex.ToString()); } }
public async Task Should_Stamp_Payroll_CFDI_Valid() { using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); try { var identityWorkId = Guid.NewGuid(); var instanceID = Guid.NewGuid(); var overdraft = await CreateRealOverdraftAsync(identityWorkId, instanceID); var periodDetailID = overdraft.PeriodDetailID; //Recalculate var calculateParams = new CalculateOverdraftParams() { DeleteAccumulates = true, IdentityWorkID = identityWorkId, InstanceID = instanceID, OverdraftID = overdraft.ID, ResetCalculation = true, SaveOverdraft = true, UserID = Guid.Empty }; var calculationResult = await new OverdraftCalculationManager().CalculateAsync(calculateParams); overdraft = (calculationResult as CalculateOverdraftResult).OverdraftResult; Assert.True(overdraft.OverdraftDetails.Sum(p => p.Amount) > 0); //Autorización de la nómina var authorizationManager = new AuthorizationManager(); var authorizationParams = new AuthorizationParams() { IdentityWorkID = identityWorkId, InstanceID = instanceID, PeriodDetailIDToAuthorize = periodDetailID, ResourceID = Guid.Empty, user = Guid.Empty }; //autorizacion de la nómina var historicOverdrafts = await authorizationManager.AuthorizationAsync(authorizationParams); //Timbrado var overdraftManager = new MiddlewareManager <Overdraft>(new BaseRecordManager <Overdraft>(), new OverdraftValidator()); var overdraftsPrevious = await overdraftManager.FindByExpressionAsync(p => p.PeriodDetailID == periodDetailID, identityWorkId); var manager = new PayrollStampingManager(); var dateTime = DateTime.Now; var stampingParms = new PayrollStampingParams() { FiscalStampingVersion = FiscalStampingVersion.CFDI33_Nom12, IdentityWorkID = identityWorkId, InstanceID = instanceID, PeriodDetailID = periodDetailID, Detail = new List <PayrollStampingDetail>() { new PayrollStampingDetail() { Folio = "2020", Series = "S1", PaymentDate = dateTime.AddDays(-2), RFCOriginEmployer = null, SNCFEntity = null, OverdraftID = overdraftsPrevious.FirstOrDefault().ID, } }, Currency = Currency.MXN }; var payrollStampingResult = await manager.PayrollStampingAsync(stampingParms); Assert.Contains(payrollStampingResult.PayrollStampingResultDetails, p => p.PayrollStampingResultStatus == PayrollStampingResultStatus.Success); var uuid = payrollStampingResult.PayrollStampingResultDetails.FirstOrDefault().Overdraft.UUID; var fiscalManager = FiscalPreviewFactory.CreateInstance(FiscalStampingVersion.CFDI33_Nom12); var resultUrls = await fiscalManager.GetPreviewUrlByUUIDAsync(instanceID, uuid); HttpClient client = new HttpClient(); var pdfBytes = await client.GetByteArrayAsync(resultUrls.PDFUri); //Save XML to FileSystem var xmlFilePath = Path.Combine(DirectoryUtil.AssemblyDirectory, "example.xml"); await File.WriteAllTextAsync(xmlFilePath, payrollStampingResult.PayrollStampingResultDetails.FirstOrDefault().XML); Assert.True(File.Exists(xmlFilePath)); //Save PDF to FileSystem var outPDFFilePath = Path.Combine(DirectoryUtil.AssemblyDirectory, "example.pdf"); await File.WriteAllBytesAsync(outPDFFilePath, pdfBytes); Assert.True(File.Exists(outPDFFilePath)); } catch (Exception ex) { var t = ex.ToString(); Assert.True(false, ex.ToString()); } }
public async Task <CalculateOverdraftResult> CalculateOverdraftAsync(CalculateOverdraftParams calculateOverdraftParams) { return(await _client.CalculateOverdraftAsync(calculateOverdraftParams)); }