Commit inicial Ventas Productivo
This commit is contained in:
238
Contabilidad/ContabilidadElectronica.aspx.vb
Normal file
238
Contabilidad/ContabilidadElectronica.aspx.vb
Normal file
@@ -0,0 +1,238 @@
|
||||
Option Explicit On
|
||||
Option Strict On
|
||||
|
||||
Imports System.Data
|
||||
Imports System.IO
|
||||
Imports Extensiones
|
||||
Partial Class Contabilidad_ContabilidadElectronica
|
||||
Inherits ClsPaginas
|
||||
|
||||
#Region " PROPIEDADES "
|
||||
Private Property ArchivoCuentas As String
|
||||
Get
|
||||
ArchivoCuentas = ViewState("ArchivoCuentas").ToString
|
||||
End Get
|
||||
Set(value As String)
|
||||
ViewState("ArchivoCuentas") = value
|
||||
End Set
|
||||
End Property
|
||||
Private Property ArchivoBalanza As String
|
||||
Get
|
||||
ArchivoBalanza = ViewState("ArchivoBalanza").ToString
|
||||
End Get
|
||||
Set(value As String)
|
||||
ViewState("ArchivoBalanza") = value
|
||||
End Set
|
||||
End Property
|
||||
#End Region
|
||||
|
||||
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
||||
If Not IsPostBack Then
|
||||
InicializaValores()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
#Region " INICIALIZA VALORES "
|
||||
Private Sub InicializaValores()
|
||||
'TxtFechaI.Text = String.Format("01/01/{0}", Now.Year)
|
||||
'TxtFechaI.Text = Now.ToShortDateString
|
||||
|
||||
If Not UsuarioActual.Empresa.UsaContabilidad Then
|
||||
BtnGenerar.Enabled = False
|
||||
Alert("Este módulo requiere el uso de contabilidad", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa)
|
||||
If ObjConta.GetEjercicios() Then
|
||||
DdlEjercicio.DataSource = ObjConta.DtResultados
|
||||
Else
|
||||
DdlEjercicio.DataSource = Nothing
|
||||
End If
|
||||
ObjConta.Dispose()
|
||||
|
||||
DdlEjercicio.DataBind()
|
||||
|
||||
DdlEjercicio.SelectedValue = Now.Year.ToString
|
||||
DdlPeriodo.SelectedValue = Now.Month.ToString
|
||||
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
#Region " GENERA XML "
|
||||
Protected Sub BtnGenerar_Click(sender As Object, e As EventArgs)
|
||||
|
||||
'CREA DIRECTORIO SI NO EXISTE
|
||||
DirectoryExistsCreate(String.Format("{0}ContabilidadElectronica", UsuarioActual.Empresa.Ruta))
|
||||
|
||||
'LIMPIA VALORES
|
||||
ArchivoCuentas = ""
|
||||
ArchivoBalanza = ""
|
||||
|
||||
If DdlTipoReporte.SelectedValue = "1" Then
|
||||
GeneraCatalogo()
|
||||
ElseIf DdlTipoReporte.SelectedValue = "2" Then
|
||||
GeneraBalanza()
|
||||
End If
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub GeneraCatalogo()
|
||||
Dim FechaF = String.Format("01/{0}/{1}", DdlPeriodo.SelectedValue.PadLeft(2, "0"c), DdlEjercicio.SelectedValue).ToDate.LastDayOfMonth
|
||||
Dim DtCuentas As New DataTable
|
||||
|
||||
Dim ObjConpaq As New ClsContPAQi(UsuarioActual.Empresa)
|
||||
If ObjConpaq.GetCuentasElectronica(MinFecha, FechaF) Then
|
||||
DtCuentas = ObjConpaq.DtResultados
|
||||
End If
|
||||
ObjConpaq.Dispose()
|
||||
|
||||
|
||||
If DtCuentas IsNot Nothing AndAlso DtCuentas.Rows.Count > 0 Then
|
||||
Dim Str As New StringBuilder
|
||||
|
||||
'CABECERA
|
||||
Str.Append("<?xml version=""1.0"" encoding=""UTF-8""?>")
|
||||
Str.Append("<catalogocuentas: Catalogo xsi:schemaLocation=""www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas CatalogoCuentas_1_1.xsd"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" Version=""1.1"" ")
|
||||
Str.AppendFormat("RFC=""{0}"" ", UsuarioActual.Empresa.RFC)
|
||||
Str.AppendFormat("Mes=""{0}"" ", DdlPeriodo.SelectedValue)
|
||||
Str.AppendFormat("Anio=""{0}"" ", DdlEjercicio.SelectedValue)
|
||||
Str.AppendFormat("Sello=""{0}"" ", "123")
|
||||
Str.AppendFormat("noCertificado=""{0}"" ", "123")
|
||||
Str.AppendFormat("Certificado=""{0}"" ", "1234567890")
|
||||
Str.Append("xmlns:catalogocuentas=""www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas"">")
|
||||
|
||||
'DETALLES
|
||||
For Each Dr As DataRow In DtCuentas.Rows
|
||||
Str.Append("<catalogocuentas:Ctas ")
|
||||
Str.AppendFormat("CodAgrup=""{0}"" ", Dr("CodAgrup"))
|
||||
Str.AppendFormat("NumCta=""{0}"" ", Dr("NumCta"))
|
||||
Str.AppendFormat("Desc=""{0}"" ", Dr("Desc"))
|
||||
Str.AppendFormat("SubCtaDe=""{0}"" ", Dr("SubCtaDe"))
|
||||
Str.AppendFormat("Nivel=""{0}"" ", Dr("Nivel"))
|
||||
Str.AppendFormat("Natur=""{0}"" ", Dr("Natur"))
|
||||
Str.Append("/>")
|
||||
Next
|
||||
DtCuentas.Dispose()
|
||||
|
||||
'FIN
|
||||
Str.Append("</catalogocuentas:Catalogo>")
|
||||
|
||||
|
||||
'GUARDA ARHIVO
|
||||
ArchivoCuentas = Server.MapPath(String.Format("~/Empresas/{0}/ContabilidadElectronica/{1}{2}{3}CT.xml", UsuarioActual.CveEmpresa, UsuarioActual.Empresa.RFC, DdlEjercicio.SelectedValue, DdlPeriodo.SelectedValue.PadLeft(2, "0"c)))
|
||||
|
||||
'SOBREESCRIBE
|
||||
If System.IO.File.Exists(ArchivoCuentas) Then
|
||||
System.IO.File.Delete(ArchivoCuentas)
|
||||
End If
|
||||
|
||||
Dim fs As FileStream = File.Create(ArchivoCuentas)
|
||||
Dim info As Byte() = New UTF8Encoding(True).GetBytes(Str.ToString)
|
||||
fs.Write(info, 0, info.Length)
|
||||
fs.Close()
|
||||
|
||||
|
||||
'DESCARGA XML
|
||||
Dim DescargaZIP As Ionic.Zip.ZipFile = New Ionic.Zip.ZipFile()
|
||||
|
||||
If IO.File.Exists(ArchivoCuentas) Then
|
||||
DescargaZIP.AddFile(ArchivoCuentas, "")
|
||||
End If
|
||||
|
||||
DescargaZIP.Save(Response.OutputStream)
|
||||
Response.AddHeader("content-Disposition", String.Format("attachment; filename={0}{1}{2}CT.zip", UsuarioActual.Empresa.RFC, DdlEjercicio.SelectedValue, DdlPeriodo.SelectedValue.PadLeft(2, "0"c)))
|
||||
Response.ContentType = "application/zip"
|
||||
Response.End()
|
||||
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub GeneraBalanza()
|
||||
Dim FechaI = String.Format("01/{0}/{1}", DdlPeriodo.SelectedValue.PadLeft(2, "0"c), DdlEjercicio.SelectedValue).ToDate
|
||||
Dim FechaF = FechaI.LastDayOfMonth
|
||||
Dim DtCuentas As New DataTable
|
||||
|
||||
Dim ObjConpaq As New ClsContPAQi(UsuarioActual.Empresa)
|
||||
If ObjConpaq.GetBalanzaElectronica(FechaI, FechaF) Then
|
||||
DtCuentas = ObjConpaq.DtResultados
|
||||
End If
|
||||
ObjConpaq.Dispose()
|
||||
|
||||
|
||||
If DtCuentas IsNot Nothing AndAlso DtCuentas.Rows.Count > 0 Then
|
||||
Dim Str As New StringBuilder
|
||||
|
||||
'CABECERA
|
||||
Str.Append("<?xml version=""1.0"" encoding=""UTF-8""?>")
|
||||
Str.Append("<BCE:Balanza xsi:schemaLocation=""www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion BalanzaComprobacion_1_1.xsd"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" Version=""1.1"" ")
|
||||
Str.AppendFormat("RFC=""{0}"" ", UsuarioActual.Empresa.RFC)
|
||||
Str.AppendFormat("Mes=""{0}"" ", DdlPeriodo.SelectedValue)
|
||||
Str.AppendFormat("Anio=""{0}"" ", DdlEjercicio.SelectedValue)
|
||||
|
||||
Str.AppendFormat("TipoEnvio=""{0}"" ", "C")
|
||||
Str.AppendFormat("FechaModBal=""{0}"" ", FechaF.ToString("yyyy-MM-dd"))
|
||||
|
||||
Str.AppendFormat("Sello=""{0}"" ", "123")
|
||||
Str.AppendFormat("noCertificado=""{0}"" ", "123")
|
||||
Str.AppendFormat("Certificado=""{0}"" ", "1234567890")
|
||||
Str.Append("xmlns:BCE=""www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion"">")
|
||||
|
||||
'DETALLES
|
||||
For Each Dr As DataRow In DtCuentas.Rows
|
||||
Str.Append("<BCE:Ctas ")
|
||||
Str.AppendFormat("NumCta=""{0}"" ", Dr("NumCta"))
|
||||
Str.AppendFormat("SaldoIni=""{0}"" ", Dr("SaldoIni"))
|
||||
Str.AppendFormat("Debe=""{0}"" ", Dr("Debe"))
|
||||
Str.AppendFormat("Haber=""{0}"" ", Dr("Haber"))
|
||||
Str.AppendFormat("SaldoFin=""{0}"" ", Dr("SaldoFin"))
|
||||
Str.Append("/>")
|
||||
Next
|
||||
|
||||
DtCuentas.Dispose()
|
||||
|
||||
'FIN
|
||||
Str.Append("</BCE:Balanza>")
|
||||
|
||||
|
||||
'GUARDA ARHIVO
|
||||
ArchivoBalanza = Server.MapPath(String.Format("~/Empresas/{0}/ContabilidadElectronica/{1}{2}{3}BN.xml", UsuarioActual.CveEmpresa, UsuarioActual.Empresa.RFC, DdlEjercicio.SelectedValue, DdlPeriodo.SelectedValue.PadLeft(2, "0"c)))
|
||||
|
||||
'SOBREESCRIBE
|
||||
If System.IO.File.Exists(ArchivoBalanza) Then
|
||||
System.IO.File.Delete(ArchivoBalanza)
|
||||
End If
|
||||
|
||||
Dim fs As FileStream = File.Create(ArchivoBalanza)
|
||||
Dim info As Byte() = New UTF8Encoding(True).GetBytes(Str.ToString)
|
||||
fs.Write(info, 0, info.Length)
|
||||
fs.Close()
|
||||
|
||||
|
||||
|
||||
'DESCARGA XML
|
||||
Dim DescargaZIP As Ionic.Zip.ZipFile = New Ionic.Zip.ZipFile()
|
||||
|
||||
If IO.File.Exists(ArchivoBalanza) Then
|
||||
DescargaZIP.AddFile(ArchivoBalanza, "")
|
||||
End If
|
||||
|
||||
DescargaZIP.Save(Response.OutputStream)
|
||||
Response.AddHeader("content-Disposition", String.Format("attachment; filename={0}{1}{2}BN.zip", UsuarioActual.Empresa.RFC, DdlEjercicio.SelectedValue, DdlPeriodo.SelectedValue.PadLeft(2, "0"c)))
|
||||
Response.ContentType = "application/zip"
|
||||
Response.End()
|
||||
|
||||
End If
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user