public async Task <GetPreviewCancelationAckURLResult> GetPreviewCancelationAckURLAsync(Guid cancelationResponseXMLID, Guid instanceID)
        {
            var fiscalManager = FiscalPreviewFactory.CreateInstance(FiscalStampingVersion.CFDI33_Nom12);
            var result        = await fiscalManager.GetPreviewCancelationAckURLAsync(cancelationResponseXMLID, instanceID);

            return(result);
        }
        public async Task <GetPreviewUrlResult> GetPreviewUrlByUUIDAsync(Guid instanceId, Guid UUID)
        {
            var fiscalManager = FiscalPreviewFactory.CreateInstance(FiscalStampingVersion.CFDI33_Nom12);
            var result        = await fiscalManager.GetPreviewUrlByUUIDAsync(instanceId, UUID);

            return(result);
        }
예제 #3
0
        public async Task PreviewXMLToPDF_ShouldGenerate()
        {
            var fiscalStampingVersion = Schema.FiscalStampingVersion.CFDI33_Nom12;
            var globalPath            = Path.Combine(DirectoryUtil.AssemblyDirectory, "Fiscal", "cfdi33nom12", "preview");
            var xmlPath    = Path.Combine(globalPath, "6b181142-78bb-443a-927f-e7b969cb8a36.xml");
            var xmlContent = await File.ReadAllTextAsync(xmlPath);

            var previewInstance      = FiscalPreviewFactory.CreateInstance(fiscalStampingVersion);
            var transformationResult = await previewInstance.TransformAsync(new Schema.PreviewTransformParams()
            {
                FiscalStampingVersion         = fiscalStampingVersion,
                PreviewTransformParamsDetails = new List <Schema.PreviewTransformParamsDetail>()
                {
                    new Schema.PreviewTransformParamsDetail()
                    {
                        OverdraftID = Guid.Parse("A08D10B9-597F-4ECF-A2A4-5758D9AFDBF5"),
                        XML         = xmlContent
                    }
                },
                IdentityWorkID = Guid.Parse("0C08DAA6-F775-42A8-B75E-1B9B685B7977"),
                InstanceID     = Guid.Parse("D0FBA45F-3F09-463F-8FB6-1035D8302ABC"),
                user           = Guid.Parse("82CED4F6-A6CF-27E7-5683-95B6891B0B10")
            });

            var htmlPath = Path.Combine(DirectoryUtil.AssemblyDirectory, "6b181142-78bb-443a-927f-e7b969cb8a36.html");
            await File.WriteAllTextAsync(htmlPath, transformationResult.PreviewTransformResultDetails.FirstOrDefault().TransformHTMLResult);

            var pdfPath = Path.Combine(DirectoryUtil.AssemblyDirectory, "6b181142-78bb-443a-927f-e7b969cb8a36.pdf");
            await File.WriteAllBytesAsync(pdfPath, transformationResult.PreviewTransformResultDetails.FirstOrDefault().TransformPDFResult);
        }
예제 #4
0
        public async Task <ActionResult <string> > GetPreviewUrlByUUIDAsync(Guid instanceId, Guid uuid)
        {
            IFiscalPreview fiscalPreview = FiscalPreviewFactory.CreateInstance(FiscalStampingVersion.CFDI33_Nom12);
            var            resultPreview = await fiscalPreview.GetPreviewUrlByUUIDAsync(instanceId, uuid);

            return(new JsonResult(resultPreview));
        }
예제 #5
0
        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 <PreviewTransformResult> TransformAsync(PreviewTransformParams previewTransformParams)
        {
            IFiscalPreview fiscalPreview = FiscalPreviewFactory.CreateInstance(previewTransformParams.FiscalStampingVersion);

            return(await fiscalPreview.TransformAsync(previewTransformParams));
        }