Libro mayor SIG

This commit is contained in:
rakcsle
2024-08-28 22:53:45 -07:00
parent 473bdbced3
commit a49f1de1ca
12 changed files with 4309 additions and 4021 deletions

View File

@@ -5,6 +5,12 @@ Imports System
Imports System.Data
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Imports ClosedXML.Excel
Imports Profact.TimbraCFDI40
Imports System.IO
Imports System.Drawing
Partial Class Contabilidad2_RepBalanzaComprobacion
Inherits ClsPaginas
@@ -105,6 +111,10 @@ Partial Class Contabilidad2_RepBalanzaComprobacion
End If
CargarCentrosDeCosto(DdlProyecto, DdlSubproyecto, LblProyecto, LblSubProyecto)
If UsuarioActual.CveRol = 1 Then
BtnImprimirPoSubProyecto.Visible = True
End If
End If
End Sub
@@ -254,4 +264,238 @@ Partial Class Contabilidad2_RepBalanzaComprobacion
ImprimirPDF(reportpath, DtDatos, params, fileName, Formato)
End Sub
Protected Sub BtnImprimirPoSubProyecto_Click(sender As Object, e As EventArgs)
Dim WBAnexoBalanza = New ClosedXML.Excel.XLWorkbook
Dim TipoReporte = DdlTipoReporte.SelectedValue.ToEntero
FechaInicio = If(TxtFechaDel.Text = "" Or TxtFechaDel.Text = "__/__/____", NowADS(), TxtFechaDel.Text.ToDate)
FechaFin = If(TxtFechaAl.Text = "" Or TxtFechaAl.Text = "__/__/____", NowADS(), TxtFechaAl.Text.ToDate)
Dim SPCounter As Integer = 1
For Each drSP As DataRow In GlobalDTSubProyectos(UsuarioActual.CveEmpresa).Rows
Dim ObjConta As New ClsContabilidad
If ObjConta.GetBalanzaComprobacion(FechaInicio, FechaFin, 2, TipoReporte, -1, drSP("CveSubProyecto").ToString.ToEntero, UsuarioActual.CveEmpresa, DdlVista.SelectedValue.ToEntero, DdlNivel.SelectedValue.ToEntero) Then
DtDatos = ObjConta.DtResultados
Else
DtDatos = Nothing
Alert("Ocurrio un error al cargar los datos del Anexo del Catálogo", TipoMensaje.MsgError)
Exit For
End If
ObjConta.Dispose()
If DtDatos.Rows.Count > 0 Then
WBAnexoBalanza.AddWorksheet(WSDocumento(drSP("SubProyecto").ToString, DtDatos))
Dim spNombre As String = drSP("SubProyecto").ToString().Replace(":", "_").Replace("/", "_").Replace("\", "_").Replace("?", "_").Replace("*", "_").Replace("[", "_").Replace("]", "_")
WBAnexoBalanza.Worksheet(SPCounter).Name = $"{SPCounter}_{spNombre}"
SPCounter = SPCounter + 1
End If
Next
Dim msB = New MemoryStream()
WBAnexoBalanza.SaveAs(msB)
Dim BB As Byte() = msB.ToArray
msB.Dispose()
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment; filename=Balanza_" & Now.ToString("yyyyMMddhhmmss") & ".xlsx")
Response.ContentType = "application/vnd.ms-excel"
Response.BinaryWrite(BB)
Response.End()
End Sub
Function WSDocumento(SubProyecto As String, DtDatos As DataTable) As IXLWorksheet
Dim WBAnexoSalvar = New ClosedXML.Excel.XLWorkbook
Dim WBReporte = New ClosedXML.Excel.XLWorkbook()
WBReporte.Worksheets.Add("1")
Dim WSReporte = WBReporte.Worksheet(1)
Dim RutaLogo As String = String.Format("{0}Logo.png", UsuarioActual.Empresa.Ruta)
If File.Exists(RutaLogo) Then
Dim imagePath As String = RutaLogo
Dim img As Bitmap = New Bitmap(imagePath)
Dim picture = WSReporte.AddPicture(img).MoveTo(WSReporte.Cell("A1"))
picture.Scale(0.5)
End If
Dim Tamaniofuente As Integer = 13
Dim Range = WSReporte.Range("A1:D1")
WSReporte.Style.Font.FontSize = 10
WSReporte.Style.Font.FontName = "Arial Narrow"
WSReporte.Style.Alignment.WrapText = True
Range.Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente
WSReporte.Range("A1:F1").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente
WSReporte.Range("A2:F2").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente
WSReporte.Range("A3:F3").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente
WSReporte.Range("A4:F4").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente
WSReporte.Range("A5:F5").Merge().Style.Font.SetBold().Font.FontSize = Tamaniofuente
WSReporte.Range("A1:A5").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
WSReporte.Column(1).Width = 15
WSReporte.Column(2).Width = 35
WSReporte.Column(3).Width = 14
WSReporte.Column(4).Width = 14
WSReporte.Column(5).Width = 14
WSReporte.Column(6).Width = 14
WSReporte.Column(7).Width = 14
WSReporte.Cell(1, 1).Value = UsuarioActual.Empresa.Empresa
WSReporte.Cell(2, 1).Value = $"Balanza de Comprobación del {TxtFechaDel.Text} al {TxtFechaAl.Text}"
WSReporte.Cell(5, 1).Value = $"Sub Proyecto: {SubProyecto}"
WSReporte.Cell(5, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left
WSReporte.Cell(5, 1).Style.Font.Bold = True
WSReporte.Cell(6, 1).Value = "Cuenta"
WSReporte.Cell(6, 2).Value = "Nombre"
WSReporte.Cell(6, 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center
WSReporte.Cell(6, 2).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center
WSReporte.Cell(6, 3).Value = $"Saldos Iniciales{vbCrLf}Deudor Acreedor"
WSReporte.Cell(6, 4).Value = $"Cargos"
WSReporte.Cell(6, 5).Value = $"Abonos"
WSReporte.Cell(6, 6).Value = $"Saldo Actuales{vbCrLf} Deudor Acreedo"
WSReporte.Range("A6:F6").Style.Font.Bold = True
WSReporte.Range("A6:F6").Style.Font.FontSize = 10
WSReporte.Range("A6:F6").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
WSReporte.Range("A6:F6").Style.Border.TopBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Range("A6:F6").Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Range("A6:F6").Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
Dim CuerrentRow As Integer = 7
CuerrentRow = CuerrentRow + 1
For Each Drow As DataRow In DtDatos.Rows
WSReporte.Cell(CuerrentRow, 1).Value = Drow("Codigo").ToString
WSReporte.Cell(CuerrentRow, 2).Value = Drow("Nombre").ToString
WSReporte.Cell(CuerrentRow, 3).Value = Drow("SaldoInicial").ToString
WSReporte.Cell(CuerrentRow, 4).Value = Drow("Cargos").ToString
WSReporte.Cell(CuerrentRow, 5).Value = Drow("Abonos").ToString
WSReporte.Cell(CuerrentRow, 6).Value = Drow("SaldoActual").ToString
If Drow("CtaMayor").ToString.ToEntero.Contiene(1) Then
WSReporte.Cell(CuerrentRow, 1).Style.Font.Bold = True
WSReporte.Cell(CuerrentRow, 2).Style.Font.Bold = True
WSReporte.Cell(CuerrentRow, 3).Style.Font.Bold = True
WSReporte.Cell(CuerrentRow, 4).Style.Font.Bold = True
WSReporte.Cell(CuerrentRow, 5).Style.Font.Bold = True
WSReporte.Cell(CuerrentRow, 6).Style.Font.Bold = True
If Drow("CtaMayor").ToString.ToEntero.Contiene(1) Then
WSReporte.Cell(CuerrentRow, 1).Style.Alignment.Indent = 1
WSReporte.Cell(CuerrentRow, 1).Style.Font.Italic = True
End If
Else
WSReporte.Cell(CuerrentRow, 1).Style.Alignment.WrapText = True
WSReporte.Cell(CuerrentRow, 1).Style.Alignment.Indent = 2
End If
WSReporte.Cell(CuerrentRow, 2).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
WSReporte.Cell(CuerrentRow, 3).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
WSReporte.Cell(CuerrentRow, 4).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
WSReporte.Cell(CuerrentRow, 5).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
WSReporte.Cell(CuerrentRow, 6).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
CuerrentRow = CuerrentRow + 1
Next
For xy As Integer = 6 To CuerrentRow
WSReporte.Cell(xy, 6).Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Cell(xy, 1).Style.Border.LeftBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
Next
CuerrentRow = CuerrentRow + 1
WSReporte.Cell(CuerrentRow, 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center
WSReporte.Cell(CuerrentRow, 2).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center
WSReporte.Cell(CuerrentRow, 3).Value = $"Saldos Iniciales{vbCrLf}Deudor Acreedor"
WSReporte.Cell(CuerrentRow, 4).Value = $"Cargos"
WSReporte.Cell(CuerrentRow, 5).Value = $"Abonos"
WSReporte.Cell(CuerrentRow, 6).Value = $"Saldo Actuales{vbCrLf} Deudor Acreedo"
WSReporte.Cell(CuerrentRow, 1).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Cell(CuerrentRow, 2).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Cell(CuerrentRow, 3).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Cell(CuerrentRow, 4).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Cell(CuerrentRow, 5).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Cell(CuerrentRow, 6).Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Font.Bold = True
WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Font.FontSize = 10
WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Border.TopBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.Range($"A{CuerrentRow}:F{CuerrentRow}").Style.Border.RightBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
CuerrentRow = CuerrentRow + 1
Dim ultimaFila As DataRow = DtDatos.Rows(DtDatos.Rows.Count - 1)
Dim LastSaldoID As Decimal = ultimaFila("SaldoID").ToString.ToDecimal
Dim LastTotalAbonos As Decimal = ultimaFila("TotalAbonos").ToString.ToDecimal
Dim LastTotalCargos As Decimal = ultimaFila("TotalCargos").ToString.ToDecimal
Dim LastSaldoAD As Decimal = ultimaFila("SaldoAD").ToString.ToDecimal
Dim LastSaldoIA As Decimal = ultimaFila("SaldoIA").ToString.ToDecimal
Dim LastSaldoAA As Decimal = ultimaFila("SaldoAA").ToString.ToDecimal
WSReporte.Cell(CuerrentRow, 2).Value = "Sumas Iguales"
WSReporte.Cell(CuerrentRow, 3).Value = LastSaldoID
WSReporte.Cell(CuerrentRow, 4).Value = LastTotalCargos
WSReporte.Cell(CuerrentRow, 5).Value = LastTotalAbonos
WSReporte.Cell(CuerrentRow, 6).Value = LastSaldoAD
WSReporte.Cell(CuerrentRow, 3).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
WSReporte.Cell(CuerrentRow, 4).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
WSReporte.Cell(CuerrentRow, 5).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
WSReporte.Cell(CuerrentRow, 6).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
CuerrentRow = CuerrentRow + 1
WSReporte.Cell(CuerrentRow, 3).Value = LastSaldoIA
WSReporte.Cell(CuerrentRow, 6).Value = LastSaldoAA
WSReporte.Cell(CuerrentRow, 3).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
WSReporte.Cell(CuerrentRow, 6).Style.NumberFormat.Format = "#,##0.00; [Black] - #,##0.00 ;""-"""
WSReporte.Range($"B{CuerrentRow}:F{CuerrentRow}").Style.Border.BottomBorder = ClosedXML.Excel.XLBorderStyleValues.Medium
WSReporte.PageSetup.PrintAreas.Add($"A1:G{CuerrentRow + 0 + 1}")
WSReporte.PageSetup.Margins.Top = 0.3
WSReporte.PageSetup.Margins.Left = 0.8
WSReporte.PageSetup.Margins.Right = 0.8
WSReporte.PageSetup.FitToPages(1, 1)
WBReporte.Worksheet(1).CopyTo(WBAnexoSalvar, "SubProyecto")
Return WBReporte.Worksheet(1)
End Function
End Class