Пример #1
0
        public void VoidedValidatorTest()
        {
            var voided = new VoidedHeader
            {
                TipoDocumentoIdentidadEmisor = TipoDocumentoIdentidad.RegistroUnicoContribuyentes,
                RucEmisor               = "20600995805",
                FechaEmision            = DateTime.Now.Subtract(TimeSpan.FromDays(2)),
                NombreRazonSocialEmisor = "ABLIMATEX EXPORT SAC",
                NombreComercialEmisor   = "C-ABLIMATEX EXPORT SAC",
                CorrelativoArchivo      = "01",
                DetallesDocumento       = new List <VoidedDetail>
                {
                    new VoidedDetail {
                        TipoDocumento        = TipoDocumentoElectronico.Factura,
                        SerieDocumento       = "F001",
                        CorrelativoDocumento = "1",
                        Motivo = "ERROR EN SISTEMA",
                    },
                    new VoidedDetail {
                        TipoDocumento        = TipoDocumentoElectronico.Factura,
                        SerieDocumento       = "F001",
                        CorrelativoDocumento = "15",
                        Motivo = "CANCELACION"
                    }
                }
            };
            var validator = new VoidedValidator();
            var result    = validator.Validate(voided);

            Assert.IsTrue(result.IsValid);
        }
Пример #2
0
        public void VoidedFailedValidatorTest()
        {
            var voided = new VoidedHeader
            {
                TipoDocumentoIdentidadEmisor = TipoDocumentoIdentidad.RegistroUnicoContribuyentes,
                RucEmisor               = "20600995805",
                FechaEmision            = DateTime.Now.Subtract(TimeSpan.FromDays(2)),
                NombreRazonSocialEmisor = "ABLIMATEX EXPORT SAC",
                NombreComercialEmisor   = "C-ABLIMATEX EXPORT SAC",
                CorrelativoArchivo      = "01",
                DetallesDocumento       = new List <VoidedDetail>
                {
                    new VoidedDetail {
                        TipoDocumento        = TipoDocumentoElectronico.Factura,
                        SerieDocumento       = "G001",
                        CorrelativoDocumento = "14567889",
                        Motivo = "ERROR EN SISTEMA",
                    },
                    new VoidedDetail {
                        TipoDocumento        = TipoDocumentoElectronico.Factura,
                        SerieDocumento       = "F001",
                        CorrelativoDocumento = "15",
                        Motivo = "CANCELACION"
                    }
                }
            };
            IValidator validator = new VoidedValidator();
            var        result    = validator.Validate(voided);

            Assert.IsFalse(result.IsValid);

            Trace.WriteLine(string.Join(Environment.NewLine, result.Errors.Select(r => r.ErrorMessage)));
        }
Пример #3
0
        public VoidedHeader Build()
        {
            var head = new VoidedHeader
            {
                TipoDocumentoIdentidadEmisor = TipoDocumentoIdentidad.RegistroUnicoContribuyentes,
                RucEmisor               = _company.Ruc,
                FechaEmision            = DateTime.Now.Date,
                NombreRazonSocialEmisor = _company.RazonSocial,
                NombreComercialEmisor   = _company.NombreComercial,
                CorrelativoArchivo      = new Random().Next(1, 999).ToString("D3"),
                DetallesDocumento       = new List <VoidedDetail>(_lines)
            };

            foreach (var item in Enumerable.Range(1, _lines))
            {
                head.DetallesDocumento.Add(new VoidedDetail
                {
                    TipoDocumento        = TipoDocumentoElectronico.Factura,
                    SerieDocumento       = "F001",
                    CorrelativoDocumento = item.ToString(),
                    Motivo = "ERROR EN SISTEMA"
                });
            }

            return(head);
        }
Пример #4
0
        /// <summary>
        /// Sends the specified baja.
        /// </summary>
        /// <param name="baja">The baja.</param>
        /// <returns>BillResult.</returns>
        public async Task <BillResult> Send(VoidedHeader baja)
        {
            var xmlRes = _xmlGenerator.ToXml(baja);

            if (!xmlRes.Success)
            {
                return(xmlRes);
            }
            return(await SendSumm(xmlRes.Path, xmlRes.Content));
        }
Пример #5
0
 /// <summary>
 /// XMLs for baja.
 /// </summary>
 /// <param name="baja">The baja.</param>
 /// <returns>XmlResult.</returns>
 public XmlResult ToXml(VoidedHeader baja)
 {
     try
     {
         return(XmlForBajaInternal(baja));
     }
     catch (Exception e)
     {
         return(ForException(e));
     }
 }
Пример #6
0
        private XmlResult XmlForBajaInternal(VoidedHeader baja)
        {
            var res = _xmlGenerator.GenerarDocumentoVoided(baja);

            return(new XmlResult
            {
                Success = res.Success,
                Description = res.Error,
                Path = res.FileName,
                Content = res.Content,
                Code = res.Success ? null : CodeStatus.ConErrores
            });
        }
Пример #7
0
        /// <summary>
        /// Genera un documento XML para Resumen de Reversion.
        /// </summary>
        /// <param name="voidedHeaderEntity">Entidad Voided</param>
        /// <returns>XML</returns>
        public XmlFileResult GenerarDocumentoVoided(VoidedHeader voidedHeaderEntity)
        {
            try
            {
                #region Filename
                var id          = $"RR-{DateTime.Today:yyyyMMdd}-{voidedHeaderEntity.CorrelativoArchivo}";
                var xmlFilename = voidedHeaderEntity.RucEmisor + "-" + id;
                #endregion

                #region Gen Voided
                var voidedDoc = new VoidedDocumentsType
                {
                    ID              = id,
                    ReferenceDate   = voidedHeaderEntity.FechaEmision,
                    CustomizationID = "1.0",
                    IssueDate       = DateTime.Today.Date,
                    UBLExtensions   = new[]
                    {
                        new UBLExtensionType
                        {
                            ExtensionContent = new AdditionalsInformationType()
                        },
                    },
                    Signature = UtilsXmlDoc.GetSignature(voidedHeaderEntity),
                    AccountingSupplierParty = UtilsXmlDoc.GetInfoEmisor(voidedHeaderEntity),
                    VoidedDocumentsLine     = UtilsXmlDoc.GetVoidedLines(voidedHeaderEntity.DetallesDocumento)
                };
                #endregion

                return(new XmlFileResult
                {
                    Success = true,
                    FileName = xmlFilename,
                    Content = UtilsXmlDoc.GenFile(ref _result, voidedDoc, _certificado)
                });
            }
            catch (Exception er)
            {
                _result.Success = false;
                _result.Error   = er.Message;
                _result.Target  = "XmlOtrosCeGenerator.GenerarDocumentoVoided()";
                return(null);
            }
        }
        public void GenerarDocumentoVoidedTest()
        {
            var voided = new VoidedHeader
            {
                TipoDocumentoIdentidadEmisor = TipoDocumentoIdentidad.RegistroUnicoContribuyentes,
                RucEmisor               = "20600995805",
                FechaEmision            = DateTime.Now.Subtract(TimeSpan.FromDays(2)),
                NombreRazonSocialEmisor = "ABLIMATEX EXPORT SAC",
                NombreComercialEmisor   = "C-ABLIMATEX EXPORT SAC",
                CorrelativoArchivo      = "01",
                DetallesDocumento       = new List <VoidedDetail>
                {
                    new VoidedDetail {
                        TipoDocumento        = TipoDocumentoElectronico.Factura,
                        SerieDocumento       = "F001",
                        CorrelativoDocumento = "1",
                        Motivo = "ERROR EN SISTEMA",
                    },
                    new VoidedDetail {
                        TipoDocumento        = TipoDocumentoElectronico.Factura,
                        SerieDocumento       = "F001",
                        CorrelativoDocumento = "15",
                        Motivo = "CANCELACION"
                    }
                }
            };

            var res = _generator.GenerarDocumentoVoided(voided);

            if (!res.Success)
            {
                Trace.WriteLine(res.Error);
            }

            Assert.IsTrue(res.Success);
            Assert.IsNotNull(res.Content);
            Assert.IsTrue(res.Content.Length > 0);
        }
Пример #9
0
        /// <summary>
        /// Genera un documento XML para Comunicacion de Baja.
        /// </summary>
        /// <param name="voidedHeaderEntity">Entidad Voided</param>
        /// <returns>Retorna el XML generado.</returns>
        public XmlFileResult GenerarDocumentoVoided(VoidedHeader voidedHeaderEntity)
        {
            try
            {
                #region Filename
                var id          = $"RA-{DateTime.Today:yyyyMMdd}-{voidedHeaderEntity.CorrelativoArchivo}";
                var xmlFilename = voidedHeaderEntity.RucEmisor + "-" + id;
                #endregion

                #region Gen Voided
                var voidedDoc = new VoidedDocumentsType
                {
                    ID              = id,
                    ReferenceDate   = voidedHeaderEntity.FechaEmision,
                    CustomizationID = "1.0",
                    IssueDate       = DateTime.Today.Date,
                    UBLExtensions   = new[]
                    {
                        new UBLExtensionType
                        {
                            ExtensionContent = new AdditionalsInformationType()
                        },
                    },
                    Signature = UtilsXmlDoc.GetSignature(voidedHeaderEntity),
                    AccountingSupplierParty = UtilsXmlDoc.GetInfoEmisor(voidedHeaderEntity),
                    VoidedDocumentsLine     = UtilsXmlDoc.GetVoidedLines(voidedHeaderEntity.DetallesDocumento)
                };
                #endregion

                return(FromDocument(voidedDoc, xmlFilename));
            }
            catch (Exception ex)
            {
                return(FromException(ex));
            }
        }