diff --git a/App_Code/ClsMovimientos.vb b/App_Code/ClsMovimientos.vb index a7bd91c78..2f8a91298 100644 --- a/App_Code/ClsMovimientos.vb +++ b/App_Code/ClsMovimientos.vb @@ -609,7 +609,8 @@ Public Class ClsMovimientos 'CveAplicaNC Public Function GetCxPProveedor(CveProveedor As Integer, FechaI As String, FechaF As String, CveUsuarioProgramo As Integer, CveUsuarioRegistro As Integer, CveUsuarioResponsable As Integer, CveClasificacionProveedor As Integer, CveMoneda As Integer, CveEstatus As Integer, CveProveedorSucursal As Integer, CveAplicaNC As Integer, - Optional FechaVI As String = "-1", Optional FechaVF As String = "-1", Optional CodigoProgramacion As String = "-1", Optional CveSubProyecto As Integer = -1) As Boolean + Optional FechaVI As String = "-1", Optional FechaVF As String = "-1", Optional CodigoProgramacion As String = "-1", Optional CveSubProyecto As Integer = -1, Optional Opcion As Integer = 1, + Optional CveEmpresa As Integer = -1, Optional SaldoMayorA As Decimal = -999999999999, Optional SaldoMenorA As Decimal = 999999999999) As Boolean Dim Retorno As Boolean = False DataAdapter("PA_Comp_ProveedorCxP") With SqlAdapter.SelectCommand.Parameters @@ -628,7 +629,10 @@ Public Class ClsMovimientos .Add("@FechaVF", SqlDbType.VarChar).Value = FechaVF .Add("@CodigoProgramacion", SqlDbType.VarChar).Value = CodigoProgramacion .Add("@CveSubProyecto", SqlDbType.SmallInt).Value = CveSubProyecto - + .Add("@Opcion", SqlDbType.SmallInt).Value = Opcion + .Add("@CveEmpresaOp", SqlDbType.SmallInt).Value = CveEmpresa + .Add("@SaldoMayorA", SqlDbType.Money).Value = SaldoMayorA + .Add("@SaldoMenorA", SqlDbType.Money).Value = SaldoMenorA End With diff --git a/Contabilidad/RepIVA.aspx.cs b/Contabilidad/RepIVA.aspx.cs index ace02b2f8..1a90339d7 100644 --- a/Contabilidad/RepIVA.aspx.cs +++ b/Contabilidad/RepIVA.aspx.cs @@ -253,14 +253,33 @@ public partial class Contabilidad_RepIVA : ClsPaginas if (Archivo.Exists) { Ruta = string.Format("{0}Formatos\\{1}", UsuarioActual.Empresa.Ruta, Formato); - ImprimirbytesPDF(ImprimirPDFCrystal(Ruta, Dt, para, "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); + //ImprimirbytesPDF(ImprimirPDFCrystal(Ruta, Dt, para, "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); + + if (UsuarioActual.Empresa.Funcionalidad(713).ToEntero() == 1) + { + ImprimirbytesPDF(ImprimirSubRepPDFCrystal(Ruta, Dt, para, DtIEPSA, DtIVAA, "RepIEPSPorcentaje.rpt", "RepIVAPorcentaje.rpt", "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); + } + else + { + //ImprimirbytesPDF(ImprimirPDFCrystal(Ruta, Dt, para, "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); + ImprimirbytesPDF(ImprimirSubRepPDFCrystal(Ruta, Dt, para, new DataTable(), new DataTable(), "RepIEPSPorcentaje.rpt", "RepIVAPorcentaje.rpt", "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); + } + }else { Ruta = ModExtensiones.DirectorioBaseEmpresas + $@"Empresas\Grales\Formatos\{Formato}"; - - + //ImprimirbytesPDF(ImprimirSubRepPDFCrystal(Ruta, Dt, para, DtIEPSA, DtIVAA, "RepIEPSPorcentaje.rpt", "RepIVAPorcentaje.rpt", "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); + if (UsuarioActual.Empresa.Funcionalidad(713).ToEntero() == 1) + { ImprimirbytesPDF(ImprimirSubRepPDFCrystal(Ruta, Dt, para, DtIEPSA, DtIVAA, "RepIEPSPorcentaje.rpt", "RepIVAPorcentaje.rpt", "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); - //ImprimirbytesPDF(ImprimirPDFCrystal(Ruta, Dt, para, "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); + } + else + { + //ImprimirbytesPDF(ImprimirPDFCrystal(Ruta, Dt, para, "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); + ImprimirbytesPDF(ImprimirSubRepPDFCrystal(Ruta, Dt, para, new DataTable(), new DataTable(), "RepIEPSPorcentaje.rpt", "RepIVAPorcentaje.rpt", "Reporte de IVA", Opcion), "Reporte de IVA", Opcion); + } + + } diff --git a/Empresas/119/Formatos/RepIVA.rpt b/Empresas/119/Formatos/RepIVA.rpt index dac02e363..746765840 100644 Binary files a/Empresas/119/Formatos/RepIVA.rpt and b/Empresas/119/Formatos/RepIVA.rpt differ diff --git a/Empresas/Grales/Formatos/CatPS.rpt b/Empresas/Grales/Formatos/CatPS.rpt index b1c8440bf..d6860ee14 100644 Binary files a/Empresas/Grales/Formatos/CatPS.rpt and b/Empresas/Grales/Formatos/CatPS.rpt differ diff --git a/General/SaldosMenores.aspx b/General/SaldosMenores.aspx index 7ab09bad8..74d387dfa 100644 --- a/General/SaldosMenores.aspx +++ b/General/SaldosMenores.aspx @@ -146,18 +146,18 @@ - - + + - - -
-
+ + +
+
" style="display: inline-block; margin-right: -20px; width: 150px;" /> " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> -
+
-
+
@@ -195,17 +195,17 @@ - + - -
-
+ +
+
" style="display: inline-block; margin-right: -20px; width: 150px;" /> " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> -
+
-
+
@@ -245,116 +245,205 @@ - - + + -
-
- " style="display: inline-block; margin-right: -20px; width: 150px;" /> - " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> -
-
-
+
+
+ " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
+
+
-
- - - - - - - - - <%----%> - - - - - - - - Venta - - - - - - - - Tipo
- Docto -
- - - -
+
+ + + + + + + + + <%----%> + + + + + - - Cliente - - - - - - - - - Fecha
- Venta -
- - - -
- + Venta + + + + + - - Moneda - - - - - - - - - Monto + + Tipo
+ Docto +
+ + + +
+ + + + Cliente + + + + + + + + + Fecha
+ Venta +
+ + + +
+ + + + Moneda + + + + + + + + + Monto
- Venta -
- -   - -
- - - Saldo - -   - - + Venta + + +   + + -
-
+ + Saldo + +   + + -
-
+ + -
-
+ + + +
+
-
+
- + +
+
+ " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
+
+
+
+ + + + + + <%-- 0 --%> + + + + + + + + <%-- 1 --%> + + Factura + + + + + + + + Tipo
+ Docto +
+ + + +
+ + + + Proveedor + + + + + + <%-- 5 --%> + + Fecha Compra + + + + + + <%-- 5 --%> + + Moneda + + + + + + <%-- 8 --%> + + Monto Compra + +   + + + <%-- 10 --%> + + Saldo + +   + + + +
+ +
+ +
+
+ +
+
@@ -406,14 +495,20 @@
- + + + + + +
diff --git a/General/SaldosMenores.aspx.vb b/General/SaldosMenores.aspx.vb index 4863ff897..1859ef420 100644 --- a/General/SaldosMenores.aspx.vb +++ b/General/SaldosMenores.aspx.vb @@ -36,6 +36,15 @@ Partial Public Class General_SaldosMenores End Set End Property + Private Property DtDatosCompras As DataTable + Get + Return DirectCast(ViewState("DtDatosCompras"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtDatosCompras") = value + End Set + End Property + Private Property Tipo As Integer Get Return DirectCast(ViewState("Tipo"), Integer) @@ -45,32 +54,32 @@ Partial Public Class General_SaldosMenores End Set End Property - Private Property CveMoneda As Integer - Get - Return DirectCast(ViewState("CveMoneda"), Integer) - End Get - Set(value As Integer) - ViewState("CveMoneda") = value - End Set - End Property + 'Private Property CveMoneda As Integer + ' Get + ' Return DirectCast(ViewState("CveMoneda"), Integer) + ' End Get + ' Set(value As Integer) + ' ViewState("CveMoneda") = value + ' End Set + 'End Property - Private Property TCEspecifico As Double - Get - Return DirectCast(ViewState("TCEspecifico"), Double) - End Get - Set(value As Double) - ViewState("TCEspecifico") = value - End Set - End Property + 'Private Property TCEspecifico As Double + ' Get + ' Return DirectCast(ViewState("TCEspecifico"), Double) + ' End Get + ' Set(value As Double) + ' ViewState("TCEspecifico") = value + ' End Set + 'End Property - Private Property TipoCambio As Integer - Get - Return DirectCast(ViewState("TipoCambio"), Integer) - End Get - Set(value As Integer) - ViewState("TipoCambio") = value - End Set - End Property + 'Private Property TipoCambio As Integer + ' Get + ' Return DirectCast(ViewState("TipoCambio"), Integer) + ' End Get + ' Set(value As Integer) + ' ViewState("TipoCambio") = value + ' End Set + 'End Property #End Region Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load @@ -79,7 +88,23 @@ Partial Public Class General_SaldosMenores End If End Sub Protected Sub BtnonClickTabs_Click(sender As Object, e As EventArgs) - Consultar() + 'Consultar() + + GvDatosIXC.DataSource = Nothing + GvCxC.DataSource = Nothing + GvCxP.DataSource = Nothing + + GvDatosIXC.DataBind() + GvCxC.DataBind() + GvCxP.DataBind() + + DvSaldar.Visible = False + + Upsaldar.Update() + UpDatos.Update() + UpDatosNCEXC.Update() + UPVentas.Update() + UPCompras.Update() End Sub Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click Consultar() @@ -92,6 +117,7 @@ Partial Public Class General_SaldosMenores DtDatosIXC = New DataTable DtDatosNCEXC = New DataTable DtDatosVentas = New DataTable + DtDatosCompras = New DataTable DvSubProyectoSaldar1.Visible = False DvSubProyectoSaldar2.Visible = False @@ -117,289 +143,35 @@ Partial Public Class General_SaldosMenores End If End If + + If Tabs.ActiveTab Is TabCompras Then + CargaDatosCompras() + If DtDatosCompras.Rows.Count > 0 Then + DvSaldar.Visible = True + End If + End If + + + Upsaldar.Update() End Sub Protected Sub BtnSaldar_Click(sender As Object, e As EventArgs) If Tabs.ActiveTab Is TabIXC Then - Dim ObjConta As New ClsContabilidad() - ObjConta.IniciaTransacSQL() - Dim CvePrePoliza As Integer = 0, CveVenta As Integer = -1, CveIE As Integer = -1 - Dim Saldo As Decimal = 0 - Dim SaldoAdmin As Decimal = 0 - Dim ImporteTotalGasto As Decimal = 0 - Dim MsgError As String = "" - - CvePrePoliza = ObjConta.AddPrePolizas("Bancos/RepNCXAplicar", 6, 0, 0, 1, TxtFecha.Text.ToDate(), TxtConcepto.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 3) - Dim tMovto As Boolean = True - Dim tConceptoSaldar As Integer = 78 - - If CvePrePoliza > 0 Then - For Each Gv As GridViewRow In GvDatosIXC.Rows - Dim ConPreP As New ConceptosTipoSaldo() - - If Gv.FCCheckBox("Chk").Checked Then - - If Gv.DataKey("CveVenta").ToEntero > 0 Then - ConPreP = ClsPaginas.ObtenerCveConceptoPrePoliza(6, Gv.DataKey("CveMoneda").ToEntero(), False, 2) - ElseIf Gv.DataKey("CveIE").ToEntero > 0 Then - ConPreP.CveConcepto = 3 - End If - - 'If Tipo = 1 OrElse Tipo = 2 Then - If Gv.DataKey("CveVenta").ToEntero() > 0 Then - CveVenta = Gv.DataKey("CveVenta").ToEntero() - Saldo = -Gv.DataKey("Saldo").ToDecimal() - SaldoAdmin = Saldo - - ElseIf Gv.DataKey("CveIE").ToEntero() > 0 Then - 'ElseIf Tipo = 3 Then - ConPreP = ClsPaginas.ObtenerCveConceptoPrePoliza(18, Gv.DataKey("CveMoneda").ToEntero(), True, 2) - CveIE = Gv.DataKey("CveIE").ToEntero() - Saldo = Gv.DataKey("Saldo").ToDecimal() - SaldoAdmin = Saldo - End If - - Saldo = -Saldo ' invertimos el saldo para que se haga negativo para que sea Abono - - ImporteTotalGasto += Saldo - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, tMovto, SaldoAdmin, Saldo, ConPreP.CveConcepto, Gv.DataKey("SerieFolio").ToString(), TxtConcepto.Text, CveIE, CveVenta, CveCliente:=Gv.DataKey("CveCliente").ToEntero()) Then - MsgError = "Ocurrio un error al saldar el movimiento" - Exit For - End If - - If Gv.DataKey("CveMoneda").ToEntero() > 1 Then - Dim ImporteMN As Decimal = (Saldo * Gv.DataKey("TipoCambio").ToDecimal() - Saldo).RoundSQL() - ImporteTotalGasto += ImporteMN - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, tMovto, Saldo, ImporteMN, ConPreP.CveConceptoComplementario, Gv.DataKey("SerieFolio").ToString(), TxtConcepto.Text, CveIE, CveVenta, CveCliente:=Gv.DataKey("CveCliente").ToEntero(), ImporteME:=Saldo, TipoCambio:=Gv.DataKey("TipoCambio").ToDecimal()) Then - MsgError = "Ocurrio un error al saldar el movimiento" - Exit For - End If - End If - End If - Next - - If ImporteTotalGasto <> 0 Then - ImporteTotalGasto *= -1 ' se invierte el valor, para cuadre de prepoliza - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, tMovto, ImporteTotalGasto, ImporteTotalGasto, tConceptoSaldar, "", TxtConcepto.Text, CveIE, CveVenta, CveSubProyecto:=DdlSubProyectoSaldar.SelectedValue.ToEntero()) Then - MsgError = "Ocurrio un error al saldar el movimiento" - End If - Else - MsgError = "Poliza no insertada" - End If - End If - - If MsgError = "" Then - ObjConta.Commit() - ' DvSaldar.Visible = False - Dim Msg As String = "Los movimientos se saldaron correctamente." - Msg &= $"

Ver Póliza   " - Alert(Msg) - Else - ObjConta.RollBack() - Alert(MsgError, ModExtensiones.TipoMensaje.MsgError) - End If - - CargaDatosIXC() - ObjConta.Dispose() + SaldarIXC() End If - If Tabs.ActiveTab Is TabVentas Then + SaldarVentas() + End If - - Dim ObjConta As New ClsContabilidad - ObjConta.IniciaTransacSQL() - Dim CvePrePoliza As Integer = 0 - Dim MsgError As String = "" - - 'Dim ObjIE As New ClsBancos - Dim FechaUltimaFluctuacion As Date = MinFecha - Dim TipoCambioFluctuacion As Decimal = 1 - - Dim tFecha As Date = TxtFecha.Text.ToDate - Dim UltimaFluctuacion As MTipoCambioFluctuacion = GlobalTipoCambioUltimaFluctuacion(tFecha) - - If UsuarioActual.Empresa.Funcionalidad(703) = "1" AndAlso UltimaFluctuacion IsNot Nothing Then - If UltimaFluctuacion.FechaFluctuacion <= tFecha Then - FechaUltimaFluctuacion = UltimaFluctuacion.FechaFluctuacion - TipoCambioFluctuacion = UltimaFluctuacion.TCFluctuacion - End If - End If - - CvePrePoliza = ObjConta.AddPrePolizas("Bancos/ClientesAbonar/SaldarI", 47, 0, 0, 1, TxtFecha.Text.ToDate, TxtFecha.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - - For Each gr As GridViewRow In GvCxC.Rows - If gr.FCCheckBox("Chk").Checked Then - Dim PorcentajePago As Decimal = gr.DataKey("Saldo").ToDecimal / gr.DataKey("Original").ToDecimal - Dim Saldo As Decimal = gr.DataKey("Saldo").ToDecimal - Dim RETIVA As Decimal = gr.DataKey("RetIVA").ToDecimal - Dim SubTotal As Decimal = PorcentajePago * (gr.DataKey("SubTotal").ToDecimal.RoundSQL - gr.DataKey("Descuento").ToDecimal.RoundSQL).RoundSQL - Dim IVA As Decimal = PorcentajePago * gr.DataKey("IVA").ToDecimal.RoundSQL - Dim IEPS As Decimal = PorcentajePago * gr.DataKey("IEPS").ToDecimal.RoundSQL - Dim TCVenta As Decimal = gr.DataKey("TipoCambio").ToDecimal - Dim FechaVenta As Date = gr.DataKey("Fecha").ToDate - Dim tCveMoneda As Integer = gr.DataKey("CveMoneda").ToEntero - Dim TCPago As Decimal = GlobalTipoCambio(TxtFecha.Text.ToDate).FormatoNumero(4).ToDecimal - Dim CveConceptoDeduccion As Integer = DdlTipoDeduccion.SelectedValue.ToEntero - - Dim CveMoneda As Integer = gr.DataKey("CveMoneda").ToEntero - - 'si la fecha del documento es anterior a su ultima fluctuación. toma el Tc de la fluctuacion - If tCveMoneda = 2 Then - If FechaVenta < FechaUltimaFluctuacion Then - TCVenta = TipoCambioFluctuacion - End If - End If - 'condicionante - Dim ClienteMovto As Boolean = True - Dim SubtotalMovto As Boolean = False - Dim CveConceptoCliente As Integer = 2 - Dim ImpuestosMovto As Boolean = False - - Dim CveSubProyecto As Integer = gr.DataKey("CveSubProyecto").ToEntero - Dim ConceptoPartida As String = TxtConcepto.Text.Trim & " " & gr.DataKey("SerieFolio").ToString - 'TxtConcepto.Text - 'If CveConceptoDeduccion = 255 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(266).ToEntero - 'If CveConceptoDeduccion = 179 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(559).ToEntero - 'If CveConceptoDeduccion = 263 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(537).ToEntero - 'If CveConceptoDeduccion = 252 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(581).ToEntero - - If UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 122) Then - - ClienteMovto = False : Saldo = Saldo * -1 - ImpuestosMovto = True : IVA = IVA * -1 - RETIVA = ((SubTotal * RETIVA / gr.DataKey("SubTotal").ToDecimal.RoundSQL) * -1).RoundSQL(2) - CveConceptoCliente = 1 - End If - - Dim UsaComplementaria As Boolean = True - - 'If UsuarioActual.CveEmpresa = 119 Then - ' UsaComplementaria = True - 'End If - - If MsgError = "" Then - Dim ConPreP As ConceptosTipoSaldo = ClsPaginas.ObtenerCveConceptoPrePoliza(6, tCveMoneda, True, 1) - 'normal - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ClienteMovto, Saldo, Saldo, ConPreP.CveConcepto, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then - MsgError = "Ocurrio un error al saldar el movimiento" - End If - - If UsaComplementaria AndAlso tCveMoneda = 2 Then - 'complementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ClienteMovto, 0, If(CveMoneda = 1, Saldo, (Saldo * TCVenta) - Saldo).RoundSQL, ConPreP.CveConceptoComplementario, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteME:=Saldo, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then - MsgError = "Ocurrio un error al saldar el movimiento" - End If - End If - - 'fluctuación. - If tCveMoneda = 2 Then - Dim ImporteFluctuacion As Decimal = 0 - ImporteFluctuacion = Saldo * (TCPago - TCVenta) - - If CveSubProyecto <= 0 Then - MsgError = $"No se pudo obtener el sub proyecto de la venta {gr.DataKey("SerieFolio").ToString}" - End If - - If TCPago > TCVenta Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Math.Abs(ImporteFluctuacion), Math.Abs(ImporteFluctuacion), 64, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago, CveSubProyecto:=CveSubProyecto) Then - MsgError = "Ocurrio un error al saldar el movimiento" - End If - Else - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Math.Abs(ImporteFluctuacion), Math.Abs(ImporteFluctuacion), 65, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago, CveSubProyecto:=CveSubProyecto) Then - MsgError = "Ocurrio un error al saldar el movimiento" - End If - End If - - 'cuando hay pago en dólares, se ajusta el concepto de subtotal, - SubTotal = (Saldo * TCVenta) + ImporteFluctuacion - (IVA * TCVenta) - (IEPS * TCVenta) - - End If - - If (IVA > 0 Or UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 122) And IVA < 0) AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ImpuestosMovto, IVA, If(CveMoneda = 1, IVA, IVA * TCVenta), 13, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, PorcentajeImpuesto:=gr.DataKey("PorcentajeIVA").ToDecimal, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then - MsgError = "Ocurrio un error al saldar el movimiento" - End If - If (RETIVA > 0 Or UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 122) And RETIVA < 0) AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ClienteMovto, RETIVA, If(CveMoneda = 1, RETIVA, RETIVA * TCVenta), 8, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then - MsgError = "Ocurrio un error al saldar el movimiento" - End If - If IEPS > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ImpuestosMovto, IEPS, If(CveMoneda = 1, IEPS, IEPS * TCVenta), 38, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then - MsgError = "Ocurrio un error al saldar el movimiento" - End If - 'al gasto,Subtotal - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, SubtotalMovto, SubTotal, SubTotal, CveConceptoDeduccion, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyecto, CveCuenta:=-1, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then - MsgError = "Ocurrio un error al saldar el movimiento" - End If - - If ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual, Opcion:=5) Then - If ObjConta.ValorPolizaDescuadre > 0 Then - MsgError = ObjConta.MensajePolizaDescuadre + " " + ObjConta.ValorDiferencia - GuardaLogAD($"Ventas/ClientesAbonar | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") - Exit For - End If - End If - End If - End If - Next - - If MsgError = "" Then - 'ObjConta.RollBack() - ObjConta.Commit() - 'DvSaldar.Visible = False - CargaDatosVentas() - 'RegistraScript("$('#ModalSaldarCuentaIncobrable').modal('hide')") - Alert(String.Format("Los movimientos se saldaron correctamente.
Ver PrePóliza", CvePrePoliza), TipoMensaje.MsgInformacion) - 'BtnSaldarCuentasIncobrables.Visible = False - Else - ObjConta.RollBack() - Alert(MsgError, TipoMensaje.MsgError) - End If - - - ObjConta.Dispose() - - + If Tabs.ActiveTab Is TabCompras Then + SaldarCompras() End If - TxtFecha.Text = DateTime.Today.ToString() Upsaldar.Update() - End Sub - - - -#Region "I X C" - Protected Sub InicializaDatos() - txtFechaI.Text = $"01/01/{Now.Year}" - txtFechaF.Text = DateTime.Today.ToString() - TxtFecha.Text = DateTime.Today.ToString() - - TxtSaldoMayorA.Text = "0" - TxtSaldoMenorA.Text = "1000" - - CargaSucursales() - - Dim CveCliente As Integer = If(Request("CveCliente") Is Nothing, -1, Request("CveCliente").ToString().ToEntero()) - - - CveMoneda = If(Request("CveMoneda") Is Nothing, -1, Request("CveMoneda").ToString().ToEntero()) - txtFechaI.Text = If(Request("FechaI") Is Nothing, NowADS().ToString(), Request("FechaI").ToString()) - txtFechaF.Text = If(Request("FechaF") Is Nothing, NowADS().ToString(), Request("FechaF").ToString()) - TipoCambio = If(Request("TipoCambio") Is Nothing, 1, Request("TipoCambio").ToString().ToEntero()) - TCEspecifico = If(Request("TCEspecifico") Is Nothing, -1, Request("TCEspecifico").ToString().ToDouble()) - 'RblTipoCambio.SelectedValue = TipoCambio.ToString() - 'LiEspecifico.InnerText = TCEspecifico.FormatoNumero() - - Dim FechaICorte As DateTime - FechaICorte = If(Request("FechaICorte") Is Nothing, DateTime.MinValue, Request("FechaICorte").ToString().ToDate()) - - Tipo = -1 - End Sub @@ -409,6 +181,26 @@ Partial Public Class General_SaldosMenores DdlSubProyectoSaldar.DataBind() End Sub +#Region "I X C" + Protected Sub InicializaDatos() + + + txtFechaI.Text = $"01/01/{Now.Year}" + txtFechaF.Text = DateTime.Today.ToString() + TxtFecha.Text = DateTime.Today.ToString() + + TxtSaldoMayorA.Text = "0" + TxtSaldoMenorA.Text = "1000" + + CargaSucursales() + ' + Tipo = -1 + + + End Sub + + + Protected Sub CargaDatosIXC() @@ -421,7 +213,7 @@ Partial Public Class General_SaldosMenores - If ObjVenta.GetRepAnticiposNCIXCDetalle(CveCliente, -1, txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), UsuarioActual.CveEmpresa, 1, -1, CveMoneda, FechaICorte, FechaFCorte, TipoCambio, TCEspecifico, + If ObjVenta.GetRepAnticiposNCIXCDetalle(CveCliente, -1, txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), UsuarioActual.CveEmpresa, 1, -1, -1, FechaICorte, FechaFCorte, -1, -1, SaldoMayorA:=TxtSaldoMayorA.Text.ToDecimal, SaldoMenorA:=TxtSaldoMenorA.Text.ToDecimal) Then GvDatosIXC.DataSource = ObjVenta.DtResultados DtDatosIXC = ObjVenta.DtResultados @@ -497,7 +289,91 @@ Partial Public Class General_SaldosMenores End Sub + Protected Sub SaldarIXC() + Dim ObjConta As New ClsContabilidad() + ObjConta.IniciaTransacSQL() + Dim CvePrePoliza As Integer = 0, CveVenta As Integer = -1, CveIE As Integer = -1 + Dim Saldo As Decimal = 0 + Dim SaldoAdmin As Decimal = 0 + Dim ImporteTotalGasto As Decimal = 0 + Dim MsgError As String = "" + CvePrePoliza = ObjConta.AddPrePolizas("Bancos/RepNCXAplicar", 6, 0, 0, 1, TxtFecha.Text.ToDate(), TxtConcepto.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 3) + Dim tMovto As Boolean = True + Dim tConceptoSaldar As Integer = 78 + + If CvePrePoliza > 0 Then + For Each Gv As GridViewRow In GvDatosIXC.Rows + Dim ConPreP As New ConceptosTipoSaldo() + + If Gv.FCCheckBox("Chk").Checked Then + + If Gv.DataKey("CveVenta").ToEntero > 0 Then + ConPreP = ClsPaginas.ObtenerCveConceptoPrePoliza(6, Gv.DataKey("CveMoneda").ToEntero(), False, 2) + ElseIf Gv.DataKey("CveIE").ToEntero > 0 Then + ConPreP.CveConcepto = 3 + End If + + 'If Tipo = 1 OrElse Tipo = 2 Then + If Gv.DataKey("CveVenta").ToEntero() > 0 Then + CveVenta = Gv.DataKey("CveVenta").ToEntero() + Saldo = -Gv.DataKey("Saldo").ToDecimal() + SaldoAdmin = Saldo + + ElseIf Gv.DataKey("CveIE").ToEntero() > 0 Then + 'ElseIf Tipo = 3 Then + ConPreP = ClsPaginas.ObtenerCveConceptoPrePoliza(18, Gv.DataKey("CveMoneda").ToEntero(), True, 2) + CveIE = Gv.DataKey("CveIE").ToEntero() + Saldo = Gv.DataKey("Saldo").ToDecimal() + SaldoAdmin = Saldo + End If + + Saldo = -Saldo ' invertimos el saldo para que se haga negativo para que sea Abono + + ImporteTotalGasto += Saldo + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, tMovto, SaldoAdmin, Saldo, ConPreP.CveConcepto, Gv.DataKey("SerieFolio").ToString(), TxtConcepto.Text, CveIE, CveVenta, CveCliente:=Gv.DataKey("CveCliente").ToEntero()) Then + MsgError = "Ocurrio un error al saldar el movimiento" + Exit For + End If + + If Gv.DataKey("CveMoneda").ToEntero() > 1 Then + Dim ImporteMN As Decimal = (Saldo * Gv.DataKey("TipoCambio").ToDecimal() - Saldo).RoundSQL() + ImporteTotalGasto += ImporteMN + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, tMovto, Saldo, ImporteMN, ConPreP.CveConceptoComplementario, Gv.DataKey("SerieFolio").ToString(), TxtConcepto.Text, CveIE, CveVenta, CveCliente:=Gv.DataKey("CveCliente").ToEntero(), ImporteME:=Saldo, TipoCambio:=Gv.DataKey("TipoCambio").ToDecimal()) Then + MsgError = "Ocurrio un error al saldar el movimiento" + Exit For + End If + End If + End If + Next + + If ImporteTotalGasto <> 0 Then + ImporteTotalGasto *= -1 ' se invierte el valor, para cuadre de prepoliza + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, tMovto, ImporteTotalGasto, ImporteTotalGasto, tConceptoSaldar, "", TxtConcepto.Text, CveIE, CveVenta, CveSubProyecto:=DdlSubProyectoSaldar.SelectedValue.ToEntero()) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + Else + MsgError = "Poliza no insertada" + End If + End If + + If MsgError = "" Then + ObjConta.Commit() + ' DvSaldar.Visible = False + Dim Msg As String = "Los movimientos se saldaron correctamente." + Msg &= $"

Ver Póliza   " + Alert(Msg) + Else + ObjConta.RollBack() + Alert(MsgError, ModExtensiones.TipoMensaje.MsgError) + End If + + CargaDatosIXC() + ObjConta.Dispose() + End Sub #End Region @@ -514,7 +390,7 @@ Partial Public Class General_SaldosMenores Dim ObjVenta As New ClsVentas() Dim CveCliente As Integer = -1 - If ObjVenta.GetRepAnticiposNCIXCDetalle(CveCliente, -1, txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), UsuarioActual.CveEmpresa, 1, -1, CveMoneda, FechaICorte, FechaFCorte, TipoCambio, TCEspecifico, + If ObjVenta.GetRepAnticiposNCIXCDetalle(CveCliente, -1, txtFechaI.Text.ToDate(), txtFechaF.Text.ToDate(), UsuarioActual.CveEmpresa, 1, -1, -1, FechaICorte, FechaFCorte, -1, -1, SaldoMayorA:=TxtSaldoMayorA.Text.ToDecimal, SaldoMenorA:=TxtSaldoMenorA.Text.ToDecimal) Then GvDatosNCEXC.DataSource = ObjVenta.DtResultados DtDatosNCEXC = ObjVenta.DtResultados @@ -593,9 +469,6 @@ Partial Public Class General_SaldosMenores #Region "V E N T A S" - - '/Compras/RepAnt-NC-EXCDetalle.aspx - Protected Sub CargaDatosVentas() Dim Mov As New ClsMovimientos @@ -643,8 +516,341 @@ Partial Public Class General_SaldosMenores End Sub + Protected Sub SaldarVentas() + Dim ObjConta As New ClsContabilidad + ObjConta.IniciaTransacSQL() + Dim CvePrePoliza As Integer = 0 + Dim MsgError As String = "" + + 'Dim ObjIE As New ClsBancos + Dim FechaUltimaFluctuacion As Date = MinFecha + Dim TipoCambioFluctuacion As Decimal = 1 + + Dim tFecha As Date = TxtFecha.Text.ToDate + Dim UltimaFluctuacion As MTipoCambioFluctuacion = GlobalTipoCambioUltimaFluctuacion(tFecha) + + If UsuarioActual.Empresa.Funcionalidad(703) = "1" AndAlso UltimaFluctuacion IsNot Nothing Then + If UltimaFluctuacion.FechaFluctuacion <= tFecha Then + FechaUltimaFluctuacion = UltimaFluctuacion.FechaFluctuacion + TipoCambioFluctuacion = UltimaFluctuacion.TCFluctuacion + End If + End If + + CvePrePoliza = ObjConta.AddPrePolizas("Bancos/ClientesAbonar/SaldarI", 47, 0, 0, 1, TxtFecha.Text.ToDate, TxtConcepto.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + + For Each gr As GridViewRow In GvCxC.Rows + If gr.FCCheckBox("Chk").Checked Then + Dim PorcentajePago As Decimal = gr.DataKey("Saldo").ToDecimal / gr.DataKey("Original").ToDecimal + Dim Saldo As Decimal = gr.DataKey("Saldo").ToDecimal + Dim RETIVA As Decimal = gr.DataKey("RetIVA").ToDecimal + Dim SubTotal As Decimal = PorcentajePago * (gr.DataKey("SubTotal").ToDecimal.RoundSQL - gr.DataKey("Descuento").ToDecimal.RoundSQL).RoundSQL + Dim IVA As Decimal = PorcentajePago * gr.DataKey("IVA").ToDecimal.RoundSQL + Dim IEPS As Decimal = PorcentajePago * gr.DataKey("IEPS").ToDecimal.RoundSQL + Dim TCVenta As Decimal = gr.DataKey("TipoCambio").ToDecimal + Dim FechaVenta As Date = gr.DataKey("Fecha").ToDate + Dim tCveMoneda As Integer = gr.DataKey("CveMoneda").ToEntero + Dim TCPago As Decimal = GlobalTipoCambio(TxtFecha.Text.ToDate).FormatoNumero(4).ToDecimal + Dim CveConceptoDeduccion As Integer = DdlTipoDeduccion.SelectedValue.ToEntero + + Dim CveMoneda As Integer = gr.DataKey("CveMoneda").ToEntero + + 'si la fecha del documento es anterior a su ultima fluctuación. toma el Tc de la fluctuacion + If tCveMoneda = 2 Then + If FechaVenta < FechaUltimaFluctuacion Then + TCVenta = TipoCambioFluctuacion + End If + End If + 'condicionante + Dim ClienteMovto As Boolean = True + Dim SubtotalMovto As Boolean = False + Dim CveConceptoCliente As Integer = 2 + Dim ImpuestosMovto As Boolean = False + + Dim CveSubProyecto As Integer = gr.DataKey("CveSubProyecto").ToEntero + Dim ConceptoPartida As String = TxtConcepto.Text.Trim & " " & gr.DataKey("SerieFolio").ToString + 'TxtConcepto.Text + 'If CveConceptoDeduccion = 255 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(266).ToEntero + 'If CveConceptoDeduccion = 179 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(559).ToEntero + 'If CveConceptoDeduccion = 263 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(537).ToEntero + 'If CveConceptoDeduccion = 252 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(581).ToEntero + + If UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 122) Then + + ClienteMovto = False : Saldo = Saldo * -1 + ImpuestosMovto = True : IVA = IVA * -1 + RETIVA = ((SubTotal * RETIVA / gr.DataKey("SubTotal").ToDecimal.RoundSQL) * -1).RoundSQL(2) + CveConceptoCliente = 1 + End If + + Dim UsaComplementaria As Boolean = True + + 'If UsuarioActual.CveEmpresa = 119 Then + ' UsaComplementaria = True + 'End If + + If MsgError = "" Then + Dim ConPreP As ConceptosTipoSaldo = ClsPaginas.ObtenerCveConceptoPrePoliza(6, tCveMoneda, True, 1) + 'normal + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ClienteMovto, Saldo, Saldo, ConPreP.CveConcepto, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + + If UsaComplementaria AndAlso tCveMoneda = 2 Then + 'complementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ClienteMovto, 0, If(CveMoneda = 1, Saldo, (Saldo * TCVenta) - Saldo).RoundSQL, ConPreP.CveConceptoComplementario, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteME:=Saldo, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + End If + + 'fluctuación. + If tCveMoneda = 2 Then + Dim ImporteFluctuacion As Decimal = 0 + ImporteFluctuacion = Saldo * (TCPago - TCVenta) + + If CveSubProyecto <= 0 Then + MsgError = $"No se pudo obtener el sub proyecto de la venta {gr.DataKey("SerieFolio").ToString}" + End If + + If TCPago > TCVenta Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Math.Abs(ImporteFluctuacion), Math.Abs(ImporteFluctuacion), 64, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago, CveSubProyecto:=CveSubProyecto) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + Else + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Math.Abs(ImporteFluctuacion), Math.Abs(ImporteFluctuacion), 65, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago, CveSubProyecto:=CveSubProyecto) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + End If + + 'cuando hay pago en dólares, se ajusta el concepto de subtotal, + SubTotal = (Saldo * TCVenta) + ImporteFluctuacion - (IVA * TCVenta) - (IEPS * TCVenta) + + End If + + If (IVA > 0 Or UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 122) And IVA < 0) AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ImpuestosMovto, IVA, If(CveMoneda = 1, IVA, IVA * TCVenta), 13, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, PorcentajeImpuesto:=gr.DataKey("PorcentajeIVA").ToDecimal, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + If (RETIVA > 0 Or UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 122) And RETIVA < 0) AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ClienteMovto, RETIVA, If(CveMoneda = 1, RETIVA, RETIVA * TCVenta), 8, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + If IEPS > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ImpuestosMovto, IEPS, If(CveMoneda = 1, IEPS, IEPS * TCVenta), 38, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + 'al gasto,Subtotal + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, SubtotalMovto, SubTotal, SubTotal, CveConceptoDeduccion, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyecto, CveCuenta:=-1, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + + If ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual, Opcion:=5) Then + If ObjConta.ValorPolizaDescuadre > 0 Then + MsgError = ObjConta.MensajePolizaDescuadre + " " + ObjConta.ValorDiferencia + GuardaLogAD($"Ventas/ClientesAbonar | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") + Exit For + End If + End If + End If + End If + Next + + If MsgError = "" Then + 'ObjConta.RollBack() + ObjConta.Commit() + 'DvSaldar.Visible = False + CargaDatosVentas() + 'RegistraScript("$('#ModalSaldarCuentaIncobrable').modal('hide')") + Alert(String.Format("Los movimientos se saldaron correctamente.
Ver PrePóliza", CvePrePoliza), TipoMensaje.MsgInformacion) + 'BtnSaldarCuentasIncobrables.Visible = False + Else + ObjConta.RollBack() + Alert(MsgError, TipoMensaje.MsgError) + End If + + + ObjConta.Dispose() + End Sub + +#End Region + +#Region "C O M P R A S" + + + Protected Sub CargaDatosCompras() + + Dim Mov As New ClsMovimientos + Dim FechaI As String = txtFechaI.Text + Dim FechaF As String = txtFechaF.Text + + + + If Mov.GetCxPProveedor(-1, FechaI, FechaF, -1, -1, -1, -1, -1, -1, -1, -1, "-1", "-1", "-1", CveSubProyecto:=-1, Opcion:=2, CveEmpresa:=UsuarioActual.CveEmpresa, SaldoMayorA:=TxtSaldoMayorA.Text.ToDecimal, SaldoMenorA:=TxtSaldoMenorA.Text.ToDecimal) Then + DtDatosCompras = Mov.DtResultados + GvCxP.DataSource = DtDatosCompras + DtDatosCompras.Columns.Add("Movimiento") + If DtDatosCompras.Rows.Count > 0 Then + DtDatosCompras.Rows(0)("Movimiento") = "FACTURA DE ACREEDOR" + End If + + End If + + Mov.Dispose() + GvCxP.DataBind() + UPCompras.Update() + + End Sub + + + Protected Sub GvCxP_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvCxP.RowDataBound + + If e.Row.RowType = DataControlRowType.DataRow Then + + 'e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("FnSuma(this,{0},{1});", e.Row.FCTextBox("TxtAbonar").ClientID, e.Row.DBCampo("Saldo"))) + If e.Row.DataKey("CveCompra").ToEntero = 0 Then + e.Row.FCCheckBox("Chk").Visible = False + e.Row.BackColor = Drawing.Color.LightGray + End If + + End If + End Sub + + Protected Sub SaldarCompras() + + Dim ObjConta As New ClsContabilidad + ObjConta.IniciaTransacSQL() + Dim CvePrePoliza As Integer = 0 + Dim MsgError As String = "" + Dim FuncionalidadFluctuacionImpuestos As Boolean = If(UsuarioActual.Empresa.Funcionalidad(159) = "1", True, False) + + Dim EsContabilizable As Boolean = If(UsuarioActual.CveEmpresa.Contiene(13, 83), False, True) + + CvePrePoliza = ObjConta.AddPrePolizas("Bancos/ProveedoresAbonar/Saldar", 98, 0, 0, 1, TxtFecha.Text.ToDate, TxtConcepto.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + For Each gr As GridViewRow In GvCxP.Rows + If gr.FCCheckBox("Chk").Checked Then + Dim Saldo As Decimal = gr.DataKey("Saldo").ToDecimal 'gr.DataKey("Saldo").ToDecimal + Dim TCCompra As Decimal = gr.DataKey("TipoCambio").ToDecimal + Dim TCPago As Decimal = GlobalTipoCambio(TxtFecha.Text.ToDate).ToDecimal + Dim CveMoneda As Integer = gr.DataKey("CveMoneda").ToEntero + Dim FechaCompra As Date = gr.DataKey("Fecha").ToDate + Dim CveSubProyecto As Integer = gr.DataKey("CveSubProyecto").ToEntero + + Dim CveConceptoContablePago As Integer = 17 + If gr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoContablePago = 308 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case CveConceptoContablePago + Case 17 + CveConceptoContablePago = 312 + Case 308 + CveConceptoContablePago = 309 + Case Else + End Select + End If + + Dim CveConceptoContableComplementaria As Integer = 206 + If gr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoContableComplementaria = 310 'cuando es acreedor + + Dim ConceptoPartida As String = String.Format("Saldar compra {0}", gr.DataKey("SerieFolio").ToString) + + + If CveMoneda > 1 Then + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Saldo, Saldo, CveConceptoContablePago, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, TipoCambio:=TCCompra, ImporteME:=If(CveMoneda > 1, Saldo, 0), Contabilizable:=EsContabilizable) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, 0.00D, (Saldo * TCCompra - Saldo).RoundSQL, CveConceptoContableComplementaria, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteME:=Saldo, TipoCambio:=TCCompra, Contabilizable:=EsContabilizable) Then + MsgError = "No se pudo insertar la póliza" + End If + Else + TCPago = 1 + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Saldo, If(CveMoneda = 1, Saldo, Saldo * TCCompra), CveConceptoContablePago, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteME:=If(CveMoneda > 1, Saldo, 0), TipoCambio:=TCCompra, Contabilizable:=EsContabilizable) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + End If + Dim PorcentajePago As Decimal = Saldo / gr.DataKey("TotalOriginal").ToDecimal + + If MsgError = "" AndAlso gr.DataKey("IVA").ToDecimal > 0 Then + Dim PorcentajeImpuesto As Decimal = gr.DataKey("PorcentajeIVA").ToDecimal + Dim IVA As Decimal = PorcentajePago * gr.DataKey("IVA").ToDecimal + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, If(CveMoneda = 1, IVA, IVA * If(FuncionalidadFluctuacionImpuestos, TCPago, TCCompra)), 14, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, PorcentajeImpuesto:=PorcentajeImpuesto, Contabilizable:=EsContabilizable) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + Saldo = Saldo - IVA + End If + + If MsgError = "" AndAlso gr.DataKey("IEPS").ToDecimal > 0 Then + + Dim IEPS As Decimal = PorcentajePago * gr.DataKey("IEPS").ToDecimal + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, If(CveMoneda = 1, IEPS, IEPS * If(FuncionalidadFluctuacionImpuestos, TCPago, TCCompra)), 25, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, Contabilizable:=EsContabilizable) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + Saldo = Saldo - IEPS + End If + + ' se manda al ot ingresos, los impuestos por acreditar + If MsgError = "" Then + Dim tcvecon As Integer = 78 + Dim tTipoMovto As Boolean = True + If Saldo < 0 Then + tcvecon = 211 + tTipoMovto = False + End If + If MsgError = "" AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, tTipoMovto, Saldo, (Saldo * TCPago).RoundSQL, tcvecon, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, TipoCambio:=TCCompra, TipoCambioPago:=TCPago, CveSubProyecto:=CveSubProyecto, Contabilizable:=EsContabilizable) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + End If + + 'fluctuación. + If CveMoneda > 1 Then + Dim ImporteFluctuacion As Decimal = 0 + ImporteFluctuacion = Saldo * (TCPago - TCCompra) + + If CveSubProyecto <= 0 Then MsgError = "No se pudo obtener el sub proyecto o centro de costo" + + If TCCompra > TCPago Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Math.Abs(ImporteFluctuacion), Math.Abs(ImporteFluctuacion), 64, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveSubProyecto:=CveSubProyecto, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, TipoCambio:=TCCompra, TipoCambioPago:=TCPago, Contabilizable:=EsContabilizable) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + Else + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Math.Abs(ImporteFluctuacion), Math.Abs(ImporteFluctuacion), 65, gr.DataKey("SerieFolio").ToString, ConceptoPartida, CveSubProyecto:=CveSubProyecto, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, TipoCambio:=TCCompra, TipoCambioPago:=TCPago, Contabilizable:=EsContabilizable) Then + MsgError = "Ocurrio un error al saldar el movimiento" + End If + End If + End If + End If + Next + + If MsgError.Trim.Length = 0 AndAlso CvePrePoliza > 0 Then + If MsgError = "" AndAlso ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual, 5) Then + If ObjConta.ValorPolizaDescuadre > 0 Then + MsgError = ObjConta.MensajePolizaDescuadre + " " + ObjConta.ValorDiferencia + GuardaLogAD($"Bancos/ProveedoresAbonar | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") + End If + End If + End If + + If MsgError = "" Then + ObjConta.Commit() + CargaDatosCompras() + RegistraScript("$('#ModalSaldarCuentaSinPagar').modal('hide')") + Dim Msg As New StringBuilder + Msg.Append("Los movimientos se saldaron correctamente.
") + + If UsuarioActual.TienePermisoProceso(354) Then 'visualizar la póliza al registros + Msg.AppendFormat("Ver Póliza   ", CvePrePoliza) + End If + Alert(Msg.ToString) + + Else + ObjConta.RollBack() + Alert(MsgError, TipoMensaje.MsgError) + End If + + ObjConta.Dispose() + + End Sub + #End Region - End Class