Saldos Menores

This commit is contained in:
rakcsle
2024-06-21 17:45:28 -07:00
parent c3a688fb9f
commit 838d3380a5
6 changed files with 740 additions and 416 deletions

View File

@@ -146,18 +146,18 @@
<ajax:TabContainer runat="server" ID="Tabs">
<ajax:TabPanel ID="TabIXC" runat="server" HeaderText="IXC" ClientIDMode="Static" OnClientClick="" >
<ajax:TabPanel ID="TabIXC" runat="server" HeaderText="IXC" ClientIDMode="Static" OnClientClick="onClickTabs">
<ContentTemplate>
<div class="row" style="margin-left: 0px; margin-top: 15px; margin-bottom: 5px; text-align: right; margin-right: 5px;" align="left">
<div class="col-md-6">
<div class="row" style="margin-left: 0px; margin-top: 15px; margin-bottom: 5px; text-align: right; margin-right: 5px;" align="left">
<div class="col-md-6">
<input type="text" id="TxtBusquedaIXC" class="form-control input-sm" onkeyup="<%= String.Format("FiltrarTabla('TxtBusquedaIXC','{0}')", GvDatosIXC.ClientID) %>" style="display: inline-block; margin-right: -20px; width: 150px;" />
<a href="javascript:;" onclick="<%= String.Format("FiltrarTabla('TxtBusquedaIXC','{0}')", GvDatosIXC.ClientID) %>" style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"><i class="icon-magnifier"></i></a>
</div>
</div>
</div>
<div class="row">
<div class="row">
<div class="col-md-6">
@@ -195,17 +195,17 @@
</ContentTemplate>
</ajax:TabPanel>
<ajax:TabPanel ID="TabNCEXC" runat="server" HeaderText="NC-EXC" ClientIDMode="Static">
<ajax:TabPanel ID="TabNCEXC" runat="server" HeaderText="NC-EXC" ClientIDMode="Static" OnClientClick="onClickTabs">
<ContentTemplate>
<div class="row" style="margin-left: 0px; margin-top: 15px; margin-bottom: 5px; text-align: right; margin-right: 5px;" align="left">
<div class="col-md-6">
<div class="row" style="margin-left: 0px; margin-top: 15px; margin-bottom: 5px; text-align: right; margin-right: 5px;" align="left">
<div class="col-md-6">
<input type="text" id="TxtBusquedaNCEXC" class="form-control input-sm" onkeyup="<%= String.Format("FiltrarTabla('TxtBusquedaNCEXC','{0}')", GvDatosNCEXC.ClientID) %>" style="display: inline-block; margin-right: -20px; width: 150px;" />
<a href="javascript:;" onclick="<%= String.Format("FiltrarTabla('TxtBusquedaNCEXC','{0}')", GvDatosNCEXC.ClientID) %>" style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"><i class="icon-magnifier"></i></a>
</div>
</div>
</div>
<div class="row">
<div class="row">
<div class="col-md-6">
@@ -245,116 +245,205 @@
</ajax:TabPanel>
<ajax:TabPanel ID="TabVentas" runat="server" HeaderText="Ventas" ClientIDMode="Static">
<ContentTemplate>
<ajax:TabPanel ID="TabVentas" runat="server" HeaderText="Ventas" ClientIDMode="Static" OnClientClick="onClickTabs">
<ContentTemplate>
<div class="row" style="margin-left: 0px; margin-top: 15px; margin-bottom: 5px; text-align: right; margin-right: 5px;" align="left">
<div class="col-md-6">
<input type="text" id="TxtBusquedaVentas" class="form-control input-sm" onkeyup="<%= String.Format("FiltrarTabla('TxtBusquedaVentas','{0}')", GvCxC.ClientID) %>" style="display: inline-block; margin-right: -20px; width: 150px;" />
<a href="javascript:;" onclick="<%= String.Format("FiltrarTabla('TxtBusquedaVentas','{0}')", GvCxC.ClientID) %>" style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"><i class="icon-magnifier"></i></a>
</div>
</div>
<div class="row">
<div class="row" style="margin-left: 0px; margin-top: 15px; margin-bottom: 5px; text-align: right; margin-right: 5px;" align="left">
<div class="col-md-6">
<input type="text" id="TxtBusquedaVentas" class="form-control input-sm" onkeyup="<%= String.Format("FiltrarTabla('TxtBusquedaVentas','{0}')", GvCxC.ClientID) %>" style="display: inline-block; margin-right: -20px; width: 150px;" />
<a href="javascript:;" onclick="<%= String.Format("FiltrarTabla('TxtBusquedaVentas','{0}')", GvCxC.ClientID) %>" style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"><i class="icon-magnifier"></i></a>
</div>
</div>
<div class="row">
<div class="col-md-6">
<asp:UpdatePanel ID="UPVentas" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GvCxC" runat="server" AutoGenerateColumns="False" EmptyDataText="No se encontraron Cuentas por Cobrar Pendientes"
DataKeyNames="TipoDocto,CveVenta,CveCliente,SerieFolio,Original,SubTotal,IVA,IEPS,RetIVA,RetISR,Num3,CveSubProyecto,CveMoneda,Saldo,TipoCambio, RFC,UUID,Fecha,PorcentajeIVA,DescuentoProntoPago,CveTipoRetencion,Descuento,ClaveMetodoPagoSAT"
CssClass="table table-striped table-advance table-hover Widthall" Style="text-align: center;" GridLines="None" HeaderStyle-CssClass="ADtr">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<%--<input type="checkbox" id="ChkAll" onclick="CheckAll();" />--%>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="Chk" CssClass="chkgv" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Left">
<HeaderTemplate>Venta</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="HplF" CssClass="Texto" NavigateUrl='<%# Eval("CveVenta", "/Ventas/Ventas.aspx?CveVenta={0}")%>' Text='<%# Eval("SerieFolio")%>' runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
Tipo<br>
Docto
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlTipoDocto" runat="server" Text='<%# Eval("TipoDocto") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<div class="col-md-6">
<asp:UpdatePanel ID="UPVentas" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GvCxC" runat="server" AutoGenerateColumns="False" EmptyDataText="No se encontraron Cuentas por Cobrar Pendientes"
DataKeyNames="TipoDocto,CveVenta,CveCliente,SerieFolio,Original,SubTotal,IVA,IEPS,RetIVA,RetISR,Num3,CveSubProyecto,CveMoneda,Saldo,TipoCambio, RFC,UUID,Fecha,PorcentajeIVA,DescuentoProntoPago,CveTipoRetencion,Descuento,ClaveMetodoPagoSAT"
CssClass="table table-striped table-advance table-hover Widthall" Style="text-align: center;" GridLines="None" HeaderStyle-CssClass="ADtr">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<%--<input type="checkbox" id="ChkAll" onclick="CheckAll();" />--%>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="Chk" CssClass="chkgv" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Left">
<HeaderTemplate>
Cliente
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="Ltl" runat="server" Text='<%# Eval("Nombre") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
Fecha<br>
Venta
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlFecha" runat="server" Text='<%# Eval("Fecha", "{0:d}") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<HeaderTemplate>Venta</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="HplF" CssClass="Texto" NavigateUrl='<%# Eval("CveVenta", "/Ventas/Ventas.aspx?CveVenta={0}")%>' Text='<%# Eval("SerieFolio")%>' runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
Moneda
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlMoneda" runat="server" Text='<%# Eval("Moneda" ) %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Right">
<HeaderTemplate>
Monto
<HeaderTemplate>
Tipo<br>
Docto
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlTipoDocto" runat="server" Text='<%# Eval("TipoDocto") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Left">
<HeaderTemplate>
Cliente
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="Ltl" runat="server" Text='<%# Eval("Nombre") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
Fecha<br>
Venta
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlFecha" runat="server" Text='<%# Eval("Fecha", "{0:d}") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
Moneda
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlMoneda" runat="server" Text='<%# Eval("Moneda") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Right">
<HeaderTemplate>
Monto
<br>
Venta
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlSaldoOriginal" runat="server" Text='<%# Eval("Original", "{0:N2}") %>'></asp:Literal>&nbsp;
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Right">
<HeaderTemplate>Saldo</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlSaldo" runat="server" Text='<%# Eval("Saldo", "{0:N2}") %>'></asp:Literal>&nbsp;
</ItemTemplate>
</asp:TemplateField>
Venta
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlSaldoOriginal" runat="server" Text='<%# Eval("Original", "{0:N2}") %>'></asp:Literal>&nbsp;
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:TemplateField ItemStyle-HorizontalAlign="Right">
<HeaderTemplate>Saldo</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlSaldo" runat="server" Text='<%# Eval("Saldo", "{0:N2}") %>'></asp:Literal>&nbsp;
</ItemTemplate>
</asp:TemplateField>
</ContentTemplate>
</asp:UpdatePanel>
</Columns>
</asp:GridView>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</ContentTemplate>
</ContentTemplate>
</ajax:TabPanel>
<ajax:TabPanel ID="TabCompras" runat="server" HeaderText="Compras" ClientIDMode="Static">
<ajax:TabPanel ID="TabCompras" runat="server" HeaderText="Compras" ClientIDMode="Static" OnClientClick="onClickTabs" >
<ContentTemplate>
<div class="row" style="margin-left: 0px; margin-top: 15px; margin-bottom: 5px; text-align: right; margin-right: 5px;" align="left">
<div class="col-md-6">
<input type="text" id="TxtBusquedaCompras" class="form-control input-sm" onkeyup="<%= String.Format("FiltrarTabla('TxtBusquedaCompras','{0}')", GvCxP.ClientID) %>" style="display: inline-block; margin-right: -20px; width: 150px;" />
<a href="javascript:;" onclick="<%= String.Format("FiltrarTabla('TxtBusquedaCompras','{0}')", GvCxP.ClientID) %>" style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"><i class="icon-magnifier"></i></a>
</div>
</div>
<div class="row">
<div class="col-md-6">
<asp:UpdatePanel ID="UPCompras" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GvCxP" runat="server" AutoGenerateColumns="False" EmptyDataText="No se encontraron Cuentas X Pagar Pendientes"
DataKeyNames="CveCompra,ImporteProgramo,Saldo,SubTotal,IVA,IVADeducible,IVANoDeducible,IEPS,RetIVA,RetISR,Total,UUID,RFC,CveFactura,SerieFolio,Descripcion,CvePrePoliza,Fecha,CveProveedor,TipoCambio,TipoCambioOriginal, CveMoneda,CveRetIVAConcepto,IVAPorPagar,IVAPorPagarDeducible,IVAPorPagarNoDeducible,IEPSPorPagar,CveRetISRConcepto,PorcentajeIVA,CveTipoConcepto,CveSubProyecto,TotalOriginal,EsImportacion,NoDeducible"
Width="100%" CssClass="table table-striped table-advance table-hover Widthall ScrollAD" Style="text-align: center;" GridLines="None">
<Columns>
<%-- 0 --%>
<asp:TemplateField>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="Chk" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<%-- 1 --%>
<asp:TemplateField ItemStyle-Width="115px" ItemStyle-HorizontalAlign="Left">
<HeaderTemplate>Factura</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="HplF" CssClass="Texto" NavigateUrl='<%# Eval("CveCompra", "/Compras/Compras.aspx?CveCompra={0}")%>' Text='<%# Eval("SerieFolio")%>' runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
Tipo<br>
Docto
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlTipoDocto" runat="server" Text='<%# Eval("TipoDocto") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Left">
<HeaderTemplate>Proveedor</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlRazonsocial" runat="server" Text='<%# Eval("RazonSocial") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<%-- 5 --%>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>Fecha Compra</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlFecha" runat="server" Text='<%# Eval("Fecha", "{0:d}") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<%-- 5 --%>
<asp:TemplateField ItemStyle-HorizontalAlign="Left">
<HeaderTemplate>Moneda</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlMoneda" runat="server" Text='<%# Eval("Moneda") %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<%-- 8 --%>
<asp:TemplateField ItemStyle-HorizontalAlign="Right">
<HeaderTemplate>Monto Compra</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlSaldoOriginal" runat="server" Text='<%# Eval("Original", "{0:N2}") %>'></asp:Literal>&nbsp;
</ItemTemplate>
</asp:TemplateField>
<%-- 10 --%>
<asp:TemplateField ItemStyle-HorizontalAlign="Right">
<HeaderTemplate>Saldo</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="LtlSaldo" runat="server" Text='<%# Eval("Saldo", "{0:N2}") %>'></asp:Literal>&nbsp;
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</ContentTemplate>
</ajax:TabPanel>
@@ -406,14 +495,20 @@
</asp:UpdatePanel>
<div style="display:none">
<asp:Button runat="server" ID="BtnonClickTabs" OnClick="BtnonClickTabs_Click" ClientIDMode="Static" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button runat="server" ID="BtnonClickTabs" OnClick="BtnonClickTabs_Click" ClientIDMode="Static" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
<asp:Content ID="Content8" ContentPlaceHolderID="JS" runat="Server">
<script>
function onClickTabs() {
$('#BtnonClickTabs').click();
function onClickTabs(sender, args) {
$('#BtnonClickTabs').click();
}
</script>
</asp:Content>

View File

@@ -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 &= $"<br/><br/><a Class='Texto' target='_blank' href='/Contabilidad/RegPrePolizaS.aspx?CvePrePoliza={CvePrePoliza}'>Ver Póliza</a>&nbsp;&nbsp; "
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. <br/> <a href='/Contabilidad/RegPrePoliza.aspx?CvePrePoliza={0}' class='Texto'>Ver PrePóliza</a>", 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 &= $"<br/><br/><a Class='Texto' target='_blank' href='/Contabilidad/RegPrePolizaS.aspx?CvePrePoliza={CvePrePoliza}'>Ver Póliza</a>&nbsp;&nbsp; "
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. <br/> <a href='/Contabilidad/RegPrePoliza.aspx?CvePrePoliza={0}' class='Texto'>Ver PrePóliza</a>", 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.</br>")
If UsuarioActual.TienePermisoProceso(354) Then 'visualizar la póliza al registros
Msg.AppendFormat("<a Class=""Texto"" target='_blank' href=""/Contabilidad/RegPrePolizaS.aspx?CvePrePoliza={0}"">Ver Póliza</a>&nbsp;&nbsp; ", CvePrePoliza)
End If
Alert(Msg.ToString)
Else
ObjConta.RollBack()
Alert(MsgError, TipoMensaje.MsgError)
End If
ObjConta.Dispose()
End Sub
#End Region
End Class