diff --git a/Planeacion/CatSubProyectos.aspx b/Planeacion/CatSubProyectos.aspx index b5c442439..77216b445 100644 --- a/Planeacion/CatSubProyectos.aspx +++ b/Planeacion/CatSubProyectos.aspx @@ -83,7 +83,7 @@
diff --git a/Planeacion/CatSubProyectos.aspx.vb b/Planeacion/CatSubProyectos.aspx.vb index 22121f394..0c13a7096 100644 --- a/Planeacion/CatSubProyectos.aspx.vb +++ b/Planeacion/CatSubProyectos.aspx.vb @@ -284,8 +284,8 @@ Partial Class CatSubProyectos DdlPrecioLista.SelectedValueExist(GvRow.DataKey("CvePrecioLista")) TxtCorreo.Text = (GvRow.DataKey("Correo")) TxtTelefono.Text = (GvRow.DataKey("Telefono")) - TxtHorarioVerano.Text = (GvRow.DataKey("HorarioVerano")) - TxtHorarioInvierno.Text = (GvRow.DataKey("HorarioInvierno")) + TxtHorarioVerano.Text = (GvRow.DataKey("UTCOffsetVerano")) + TxtHorarioInvierno.Text = (GvRow.DataKey("UTCOffsetInvierno")) 'COMERCIO EXTERIOR ChkAplicaComercioExterior.Checked = If(GvRow.DataKey("AplicaComercioExterior").ToString = "True", True, False) DdlPais.SelectedValueExist(GvRow.DataKey("CvePais")) diff --git a/Ventas/Ventas.aspx b/Ventas/Ventas.aspx index 564021c75..96819d0d4 100644 --- a/Ventas/Ventas.aspx +++ b/Ventas/Ventas.aspx @@ -1279,81 +1279,99 @@
- -
- - - - -
SubTotal: -   +
+
+ + + + + + + + + + + +
Descuentos. RNC.: +   +
Total NC.: +   +
+
+
+ + + + + - + + - - - - + + + - + <%----%> + - - - - - + + + + + - - - - - + + + + + - - - - - - + + + + + + - + - - - - - + + + + + - - - - - + + + + + - - <%-- + <%----%> - - - - + + + + - - - - + + + + - - - + + - - - + + + + + + + - - - - + + + + - - - - - - + + + + + + - - - - + + + + - - - - - + + + + + - + -
SubTotal: +   -
- -   +
+ +   - <%----%>
Amort. Ant.: -   -
Amort. Ant.: +   +
SubTotal 2: - -
SubTotal 2: + +
IVA: - - 8% - 16% - 0% - -
IVA: + + 8% + 16% + 0% + +
+
@@ -1374,99 +1392,101 @@ IEPS: -
IEPS: +
- - - - - - - - - - - - - - -
+ + + + + + + + + + + + + + +
Total: - - - - - +
Total: + + + + + - - + + - - - - Moneda: - -
Moneda: + +
- - Conv. Pesos: - T.C.: - - - - -
+ + Conv. Pesos: + T.C.: + + + + +
- - Conv. Dlls: - T.C.: - - - -
+ + Conv. Dlls: + T.C.: + + + +
+
+
+ @@ -3070,7 +3090,7 @@ -<%-- + <%-- --%>

@@ -6329,6 +6349,63 @@ + + + <%--APLICAR REMISIONES DE NC--%> + @@ -7463,24 +7540,24 @@ $('#divAgregarCliente').modal('hide'); } - function CompararNC() { - var TotalRem = ToDouble(document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').value); - var TotalNC = ToDouble(document.getElementById('<%= TxtNCImporte.ClientID %>').value); - - if (TotalRem == TotalNC) { - document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').style.border = "2px solid #04B431"; - document.getElementById('<%= TxtNCImporte.ClientID %>').style.border = "2px solid #04B431"; - document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').style.color = ""; - document.getElementById('<%= TxtNCImporte.ClientID %>').style.color = ""; - - } - else { - - document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').style.border = "2px solid #ff0000"; - document.getElementById('<%= TxtNCImporte.ClientID %>').style.border = "2px solid #ff0000"; - document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').style.color = "#ff0000"; - document.getElementById('<%= TxtNCImporte.ClientID %>').style.color = "#ff0000"; - } + function CompararNC() { + var TotalRem = ToDouble(document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').value); + var TotalNC = ToDouble(document.getElementById('<%= TxtNCImporte.ClientID %>').value); + + if (TotalRem == TotalNC) { + document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').style.border = "2px solid #04B431"; + document.getElementById('<%= TxtNCImporte.ClientID %>').style.border = "2px solid #04B431"; + document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').style.color = ""; + document.getElementById('<%= TxtNCImporte.ClientID %>').style.color = ""; + + } + else { + + document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').style.border = "2px solid #ff0000"; + document.getElementById('<%= TxtNCImporte.ClientID %>').style.border = "2px solid #ff0000"; + document.getElementById('<%= TxtImportesRemisionesNC.ClientID %>').style.color = "#ff0000"; + document.getElementById('<%= TxtNCImporte.ClientID %>').style.color = "#ff0000"; + } } function CerrarModalRemNC() { diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index bb8b675bf..48ec29b22 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -85,6 +85,14 @@ Partial Class Ventas End Property 'Local + Private Property DtPorcentajeMarcas As DataTable + Get + Return If(IsNothing(ViewState("DtPorcentajeMarcas")), Nothing, CType(ViewState("DtPorcentajeMarcas"), DataTable)) + End Get + Set(value As DataTable) + ViewState("DtPorcentajeMarcas") = value + End Set + End Property Private Property TmpDT As DataTable Get Return If(IsNothing(ViewState("TmpDT")), Nothing, CType(ViewState("TmpDT"), DataTable)) @@ -265,6 +273,14 @@ Partial Class Ventas ViewState("ListaRemisionesNC") = value End Set End Property + Private Property ListaNCDesc As List(Of Modelos.Factura) + Get + Return If(IsNothing(ViewState("ListaNCDesc")), Nothing, CType(ViewState("ListaNCDesc"), List(Of Modelos.Factura))) + End Get + Set(value As List(Of Modelos.Factura)) + ViewState("ListaNCDesc") = value + End Set + End Property Private Property Pedidos2Lista As List(Of Integer) Get Return If(IsNothing(ViewState("Pedidos2Lista")), Nothing, CType(ViewState("Pedidos2Lista"), List(Of Integer))) @@ -2463,7 +2479,7 @@ Partial Class Ventas InicializaAplicarNC() If CveCliente > 0 Then - CargaRestriccionesCreditoCliente() + CargaRestriccionesCreditoCliente(CveVenta:=Me.CveVenta) End If If Not CveVenta > 0 AndAlso UsuarioActual.Empresa.Funcionalidad(403).ToString = "1" Then @@ -2512,6 +2528,11 @@ Partial Class Ventas End If TxtFecha.Enabled = True + If UsuarioActual.Empresa.Funcionalidad(572) = "1" Then + TbDescuentosRNC.Visible = True + End If + + CargaPorcentajeMarcas() End Sub Private Sub ConfiguraEmpresa() @@ -4947,7 +4968,7 @@ Partial Class Ventas TrVistaPrevia.Visible = True If Not (ModalidadEdicion AndAlso DdlTipoComprobante.SelectedValue = "Rem") Then - CargaRestriccionesCreditoCliente(True) + CargaRestriccionesCreditoCliente(True, Me.CveVenta) End If @@ -5001,7 +5022,7 @@ Partial Class Ventas End Sub - Private Sub CargaRestriccionesCreditoCliente(Optional Alertas As Boolean = False) + Private Sub CargaRestriccionesCreditoCliente(Optional Alertas As Boolean = False, Optional CveVenta As Integer = -1) Dim ObjCliente As New ClsClientes() If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa) Then If ObjCliente.DtResultados.Rows.Count > 0 Then @@ -6120,7 +6141,11 @@ Partial Class Ventas #Region " EMITIR IMPRIMIR - GUARDAR " Protected Sub BtnEmitirImprimir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnEmitirImprimir.Click - EmitirImprimir() + Try + EmitirImprimir() + Catch ex As Exception + OnError(ex.ToString(), ex) + End Try End Sub Private Sub EmitirImprimir() @@ -6525,7 +6550,6 @@ Partial Class Ventas ' Exit Sub 'End If - If ObjFactura.CveCliente > 0 Or CveEmpresaCRM > 0 Then If TmpDT.Rows.Count > 0 Then @@ -6597,7 +6621,8 @@ Partial Class Ventas EsNCAmortizacion = True End If - GuardarVenta(ObjVentas, ObjConta, ObjInventario, ObjContr, ObjFactura, TmpDT, ObjFactura.CveNCaVincular, ObjContPaq, ObjBancos, ObjOS, ObjEventos, ObjCGame, ObjClientes, EsNCAmortizacion:=EsNCAmortizacion) + GuardarVenta(ObjVentas, ObjConta, ObjInventario, ObjContr, ObjFactura, TmpDT, ObjFactura.CveNCaVincular, ObjContPaq, ObjBancos, ObjOS, + ObjEventos, ObjCGame, ObjClientes, EsNCAmortizacion:=EsNCAmortizacion) 'SI ES REFACTURACION Dim ObjNC As List(Of Object) = Nothing @@ -6620,30 +6645,21 @@ Partial Class Ventas End If End If - - 'SI ES amortizacion 3.3 - Dim Obj2 As New List(Of Object) - + 'SI ES AMORTIZACION 3.3 + Dim Obj2 As New List(Of Object) + Dim NCDescuento As Boolean = (ListaNCDesc IsNot Nothing AndAlso ListaNCDesc.Count > 0) If ErrorList.Count = 0 Then ' cambiar la condicion para saber si hay seleccionado - If TieneAnticipo AndAlso DdlTipoAmortizacionAnticipo.SelectedValue = "2" Then - - If TieneAnticipo Then - CreaObjetosVentaAmortizacion(ObjVentas, FolioFiscalRelacionado, CveAnticipoPadre) - - Try - If RegistrarNCAmortizacion(ObjVentas, ObjConta, ObjInventario, ObjContr, ObjContPaq, ObjFacturaDevolucion, ObjBancos, Nothing, Nothing) Then - - Obj2.Add(ObjFacturaDevolucion) - - End If - Catch ex As Exception - ErrorList.Add("No se pudo generarse la nota de crédito de amortización") - End Try - - - End If - + If (TieneAnticipo AndAlso DdlTipoAmortizacionAnticipo.SelectedValue = "2") OrElse NCDescuento Then + Try + CreaObjetosVentaAmortizacion(ObjVentas, FolioFiscalRelacionado, CveAnticipoPadre, NCDescuento:=NCDescuento) + If RegistrarNCAmortizacion(ObjVentas, ObjConta, ObjInventario, ObjContr, ObjContPaq, ObjFacturaDevolucion, ObjBancos, Nothing, + Nothing, NCDescuento:=NCDescuento) Then + Obj2.Add(ObjFacturaDevolucion) + End If + Catch ex As Exception + ErrorList.Add("No se pudo generarse la nota de crédito de amortización") + End Try If Obj2 Is Nothing AndAlso Obj2.Count = 0 Then ErrorList.Add("No se pudo generarse la nota de crédito de amortización") End If @@ -6820,7 +6836,6 @@ Partial Class Ventas End Try - Dim SeTimbro As Boolean = False Dim SeTimbroNC As Boolean = False Dim EstatusSMS = 0 @@ -7084,7 +7099,8 @@ Partial Class Ventas End Sub - Private Sub CreaObjetosVentaAmortizacion(ObjVentas As ClsVentas, FolioFiscalRelacionado As String, CveAnticipoPadre As Integer, Optional CveVentasPadre As Integer = -1) + Private Sub CreaObjetosVentaAmortizacion(ObjVentas As ClsVentas, FolioFiscalRelacionado As String, CveAnticipoPadre As Integer, + Optional CveVentasPadre As Integer = -1, Optional NCDescuento As Boolean = False) ObjFacturaDevolucion = New Modelos.Factura ObjFacturaDevolucion.CveUsuario = UsuarioActual.CveUsuario @@ -7098,7 +7114,6 @@ Partial Class Ventas ObjFacturaDevolucion.CveVentaRelacion = ObjVentas.CveVenta End If - ObjFacturaDevolucion.CveEmpresa = UsuarioActual.CveEmpresa ObjFacturaDevolucion.TipoCambio = If(DdlMoneda.SelectedValue.ToEntero = 1, 1, TxtTipoCambio.Text.Trim.ToDecimal) ObjFacturaDevolucion.ConvertirPesos = ChkConvertirDoctoPesos.Checked @@ -7139,6 +7154,7 @@ Partial Class Ventas ObjFacturaDevolucion.CveTipoRelacion = DdlTipoRelacionAnticipo.SelectedValue.ToEntero ObjFacturaDevolucion.TipoRelacion = "07" + Dim Fol As New List(Of String) Fol.Add(FolioFiscalRelacionado) ObjFacturaDevolucion.UUIDRelacionados = Fol @@ -7199,15 +7215,33 @@ Partial Class Ventas ObjFacturaDevolucion.Det_FechaOrdenCompra = TxtDet_FechaOrdenCompra.Text.Trim ObjFacturaDevolucion.MonedaAbreviatura = "" + 'DETALLES + If NCDescuento Then + ObjFacturaDevolucion.DtDetalle = CreaDTDetalleNCDescuento() + + ObjFacturaDevolucion.SubTotal = ObjFacturaDevolucion.DtDetalle.SUM("Total").ToDecimal() + ObjFacturaDevolucion.Descuento = ObjFacturaDevolucion.DtDetalle.SUM("Descuento").ToDecimal() + ObjFacturaDevolucion.Amortizacion = 0 + ObjFacturaDevolucion.IVA = ObjFacturaDevolucion.DtDetalle.SUM("ImporteIVA").ToDecimal() + ObjFacturaDevolucion.RetIVA = ObjFacturaDevolucion.DtDetalle.SUM("ImporteRetIVA").ToDecimal() + ObjFacturaDevolucion.RetISR = ObjFacturaDevolucion.DtDetalle.SUM("ImporteRetISR").ToDecimal() + ObjFacturaDevolucion.IEPS = ObjFacturaDevolucion.DtDetalle.SUM("ImporteIEPS").ToDecimal() + + Dim Total As Decimal = (ObjFacturaDevolucion.SubTotal + ObjFacturaDevolucion.IVA + ObjFacturaDevolucion.IEPS) - (ObjFacturaDevolucion.Descuento + ObjFacturaDevolucion.RetIVA + ObjFacturaDevolucion.RetISR + ObjFacturaDevolucion.Amortizacion) + ObjFacturaDevolucion.Total = Total + Else + ObjFacturaDevolucion.DtDetalle = TmpDT + + ObjFacturaDevolucion.SubTotal = TxtSubTotal.Text.ToDecimal + ObjFacturaDevolucion.Descuento = LblDescuentos.Text.Trim.ToDecimal + ObjFacturaDevolucion.Amortizacion = LblAmortizacion.Text.Trim.ToDecimal + ObjFacturaDevolucion.IVA = TxtIVA.Text.ToDecimal + ObjFacturaDevolucion.RetIVA = TxtRetIVA.Text.ToDecimal + ObjFacturaDevolucion.RetISR = TxtRetISR.Text.ToDecimal + ObjFacturaDevolucion.IEPS = TxtIEPS.Text.ToDecimal + ObjFacturaDevolucion.Total = TxtTotal.Text.ToDecimal + End If 'Totales, Y se llena TmpDTImpuestos - ObjFacturaDevolucion.SubTotal = TxtSubTotal.Text.ToDecimal - ObjFacturaDevolucion.Descuento = LblDescuentos.Text.Trim.ToDecimal - ObjFacturaDevolucion.Amortizacion = LblAmortizacion.Text.Trim.ToDecimal - ObjFacturaDevolucion.IVA = TxtIVA.Text.ToDecimal - ObjFacturaDevolucion.RetIVA = TxtRetIVA.Text.ToDecimal - ObjFacturaDevolucion.RetISR = TxtRetISR.Text.ToDecimal - ObjFacturaDevolucion.IEPS = TxtIEPS.Text.ToDecimal - ObjFacturaDevolucion.Total = TxtTotal.Text.ToDecimal 'ObjFactura.BZDescripcion = TxtBZDescripcion.Text.Trim 'ObjFactura.BZNombreCorto = TxtBZNombreCorto.Text.Trim @@ -7255,12 +7289,10 @@ Partial Class Ventas End If Next - If TxtTotal.Text.ToDecimal <> 0 Then DR("ImpuestoLocal") = "Total" : DR("Importe") = TxtTotal.Text.ToDecimal : DR("Orden") = 100 : DR("TipoImpuesto") = "0" : TmpDTImpuestos.Rows.Add(DR) ObjFacturaDevolucion.DtDeduccion = TmpDTImpuestos.FiltraParametros("", Orderby:="Orden ASC") - 'otros ObjFacturaDevolucion.Det_FechaOrdenCompra = TxtDet_FechaOrdenCompra.Text.Trim ObjFacturaDevolucion.Det_OrdenCompra = TxtDet_OrdenCompra.Text.Trim @@ -7273,8 +7305,6 @@ Partial Class Ventas ObjFacturaDevolucion.CveMoneda = 1 End If - 'DETALLES - ObjFacturaDevolucion.DtDetalle = TmpDT ObjFacturaDevolucion.DtFirmas = DTmpF 'CLIENTE @@ -7331,10 +7361,11 @@ Partial Class Ventas End Sub - Private Function RegistrarNCAmortizacion(ObjVentas As ClsVentas, ObjConta As ClsContabilidad, ObjInventario As ClsInventarios, ObjContr As ClsContratos, ObjContPaq As ClsContPAQi, ByVal factura As Modelos.Factura, ObjBancos As ClsBancos, TmpDTconceptos As DataTable, ByRef ObjEventos As ClsOIEventos) As Boolean + Private Function RegistrarNCAmortizacion(ObjVentas As ClsVentas, ObjConta As ClsContabilidad, ObjInventario As ClsInventarios, ObjContr As ClsContratos, ObjContPaq As ClsContPAQi, + ByVal factura As Modelos.Factura, ObjBancos As ClsBancos, TmpDTconceptos As DataTable, ByRef ObjEventos As ClsOIEventos, Optional NCDescuento As Boolean = False) As Boolean Dim ProcesoCorrecto As Boolean = True - 'Generamos el nuevo folio + 'GENERAMOS EL NUEVO FOLIO Dim ObjFolios As New ClsGralFolios(ObjVentas.IniciaTransacSQL()) If ObjFolios.GetFolios(factura.TipoDocto, UsuarioActual.CveEmpresa) Then @@ -7347,91 +7378,10 @@ Partial Class Ventas DT.Dispose() End If - '** genero los datos de la NC - Dim tmpcon As DataTable = TmpDT.Clone - tmpcon.Clear() - - Dim drpss As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlNCPSAnt.SelectedValue.ToEntero).FiltroPrimero("") - - If drpss IsNot Nothing Then - Dim ii As Integer = 1 - Dim CveVentaP As Integer = 0 - For Each gvrt As GridViewRow In GVAnticipos.Rows - If gvrt.FCCheckBox(String.Format("Chk{0}", gvrt.RowIndex)).Checked Then - Dim CveSub As Integer = TmpDT.FiltroPrimeroValor("CveSubProyecto").ToEntero - Dim dr As DataRow = tmpcon.NewRow - Dim Cantidad As Decimal = 1 - Dim PU As Decimal = gvrt.FCTextBox(String.Format("TxtAnticipo{0}", gvrt.RowIndex)).Text.ToDecimal - Dim TotalCalculableImpuestos As Decimal = (Cantidad * (PU)) - dr("CvePS") = drpss("CvePS") - dr("PS") = drpss("PS") - dr("OBS") = drpss("PS") - dr("PU") = PU - dr("Cantidad") = Cantidad - dr("CveUM") = drpss("CveUnidadMedida") - dr("SATClaveProdServ") = "84111506" - dr("SATClaveUM") = "ACT" - dr("Consec") = ii - - If drpss("IVA").ToString = "-1" Then - dr("PorcentajeIVA") = PorcentajeIVA ' GlobalDTSubProyectos(-1,cves DrPS("IVA") - Else - dr("PorcentajeIVA") = drpss("IVA") - End If - - dr("IVA") = dr("PorcentajeIVA") - dr("ImporteIVA") = Math.Round(dr("PorcentajeIVA").ToString.ToDecimal * TotalCalculableImpuestos, NumeroDecimales) - dr("ImporteRetIVA") = Math.Round(ClienteRetIVA * TotalCalculableImpuestos, NumeroDecimales) - dr("ImporteRetISR") = Math.Round(ClienteRetISR * TotalCalculableImpuestos, NumeroDecimales) - dr("PorcentajeRetIVA") = ClienteRetIVA - dr("PorcentajeRetISR") = ClienteRetISR - If UsuarioActual.Empresa.Funcionalidad(343) = "1" Then - dr("PorcentajeIEPS") = drpss("IEPSPorcentaje") - dr("ImporteIEPS") = Math.Round(drpss("IEPSPorcentaje").ToString.ToDecimal * TotalCalculableImpuestos, NumeroDecimales) - Else - dr("PorcentajeIEPS") = 0 ' DrPS("IEPSPorcentaje") - dr("ImporteIEPS") = 0 'Math.Round(DrPS("IEPSPorcentaje").ToString.ToDecimal * TotalCalculableImpuestos, NumeroDecimales) - End If - - dr("IEPS") = dr("ImporteIEPS") - dr("Descuento") = Math.Round(0, NumeroDecimales) - dr("TipoDescuento") = HdnTipoDescuento.Value - dr("Total") = (Cantidad * PU) - dr("CveClasificacion") = drpss("CveClasificacion") - dr("CveSubProyecto") = CveSub - dr("TotalImporte") = Math.Round(Cantidad * PU, NumeroDecimales) - CveVentaP = gvrt.DataKey("CveVenta").ToEntero - tmpcon.Rows.Add(dr) - ii += 1 - End If - - Next - - '**** impuestos locales - - factura.DtDetalle = tmpcon - Dim TotalSubTotal As Decimal = tmpcon.SUM("TotalImporte").ToDecimal - Dim TotalDescuentos As Decimal = tmpcon.SUM("Descuento").ToDecimal - - Dim TotalIVA As Decimal = tmpcon.SUM("ImporteIVA").ToDecimal - Dim TotalIEPS As Decimal = tmpcon.SUM("ImporteIEPS").ToDecimal - Dim TotalRetIVA As Decimal = tmpcon.SUM("ImporteRetIVA").ToDecimal - Dim TotalRetISR As Decimal = tmpcon.SUM("ImporteRetISR").ToDecimal - Dim Total As Decimal = 0 - Dim TotalImpuestosLocales As Decimal = 0 - Total = (TotalSubTotal - TotalDescuentos + TotalIVA + TotalIEPS - TotalRetIVA - TotalRetISR - TotalImpuestosLocales) - - factura.SubTotal = TotalSubTotal - factura.Descuento = 0 - factura.IVA = TotalIVA - factura.IEPS = TotalIEPS - factura.RetIVA = TotalRetIVA - factura.RetISR = TotalRetISR - factura.Total = Total - factura.CveVentaPadre = CveVentaP + If NCDescuento Then If DtVentasNC IsNot Nothing AndAlso DtVentasNC.Rows.Count > 0 Then - DtVentasNC.Rows(0)("Importe") = Total + DtVentasNC.Rows(0)("Importe") = factura.Total DtVentasNC.Rows(0)("TC") = factura.TipoCambio DtVentasNC.Rows(0)("TCCambioValuacion") = factura.TipoCambio End If @@ -7439,36 +7389,107 @@ Partial Class Ventas ObjFacturaDevolucion.Timbre = PreParaTimbre(ObjFacturaDevolucion) 'Registramos la venta - GuardarVenta(ObjVentas, ObjConta, ObjInventario, ObjContr, factura, tmpcon, -1, ObjContPaq, ObjBancos, EsNCAmortizacion:=True) - - ''Timbramos - 'If factura.TipoDocto.Contiene("Ing", "Egs", "Ant") Then - ' If UsuarioActual.Empresa.TipoFacturacion = "CFDi" AndAlso UsuarioActual.Empresa.FacturaProduccion Then - - ' Dim sw As New Diagnostics.Stopwatch - ' sw.Start() - - ' ''factura INGRESO / EGRESO - ' Dim ObjTimbrado As New Modelos.Timbrado - ' Dim FM As New Modelos.FemsaFactura - ' Dim TmpDT7Eleven As New DataTable - ' Dim TmpDTComplementosTimbrado As New DataTable - - ' 'PrepararTimbrado(FM, TmpDT7Eleven, TmpDTComplementosTimbrado) - ' '** - ' ObjTimbrado.TimbrarFactura(UsuarioActual, factura, FM, TmpDT, TmpDTImpuestos, TmpDT7Eleven, TmpDTComplementosTimbrado, Ruta, LstFordASN, TxtFordGSDB.Text) - - ' sw.Stop() - ' 'GuardaLogTimbrado(sw.ElapsedMilliseconds.ToString, UsuarioActual.Empresa.CvePAC) - - - ' End If - 'End If + GuardarVenta(ObjVentas, ObjConta, ObjInventario, ObjContr, factura, factura.DtDetalle, -1, ObjContPaq, ObjBancos, EsNCAmortizacion:=True, NCDescuento:=True) Else - ErrorList.Add("No se encontró un producto para generar la nota de crédito") - End If + 'GENERO LOS DATOS DE LA NC + Dim tmpcon As DataTable = TmpDT.Clone + tmpcon.Clear() + Dim drpss As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlNCPSAnt.SelectedValue.ToEntero).FiltroPrimero("") + + If drpss IsNot Nothing Then + Dim ii As Integer = 1 + Dim CveVentaP As Integer = 0 + For Each gvrt As GridViewRow In GVAnticipos.Rows + If gvrt.FCCheckBox(String.Format("Chk{0}", gvrt.RowIndex)).Checked Then + Dim CveSub As Integer = TmpDT.FiltroPrimeroValor("CveSubProyecto").ToEntero + Dim dr As DataRow = tmpcon.NewRow + Dim Cantidad As Decimal = 1 + Dim PU As Decimal = gvrt.FCTextBox(String.Format("TxtAnticipo{0}", gvrt.RowIndex)).Text.ToDecimal + Dim TotalCalculableImpuestos As Decimal = (Cantidad * (PU)) + dr("CvePS") = drpss("CvePS") + dr("PS") = drpss("PS") + dr("OBS") = drpss("PS") + dr("PU") = PU + dr("Cantidad") = Cantidad + dr("CveUM") = drpss("CveUnidadMedida") + dr("SATClaveProdServ") = "84111506" + dr("SATClaveUM") = "ACT" + dr("Consec") = ii + + If drpss("IVA").ToString = "-1" Then + dr("PorcentajeIVA") = PorcentajeIVA ' GlobalDTSubProyectos(-1,cves DrPS("IVA") + Else + dr("PorcentajeIVA") = drpss("IVA") + End If + + dr("IVA") = dr("PorcentajeIVA") + dr("ImporteIVA") = Math.Round(dr("PorcentajeIVA").ToString.ToDecimal * TotalCalculableImpuestos, NumeroDecimales) + dr("ImporteRetIVA") = Math.Round(ClienteRetIVA * TotalCalculableImpuestos, NumeroDecimales) + dr("ImporteRetISR") = Math.Round(ClienteRetISR * TotalCalculableImpuestos, NumeroDecimales) + dr("PorcentajeRetIVA") = ClienteRetIVA + dr("PorcentajeRetISR") = ClienteRetISR + If UsuarioActual.Empresa.Funcionalidad(343) = "1" Then + dr("PorcentajeIEPS") = drpss("IEPSPorcentaje") + dr("ImporteIEPS") = Math.Round(drpss("IEPSPorcentaje").ToString.ToDecimal * TotalCalculableImpuestos, NumeroDecimales) + Else + dr("PorcentajeIEPS") = 0 ' DrPS("IEPSPorcentaje") + dr("ImporteIEPS") = 0 'Math.Round(DrPS("IEPSPorcentaje").ToString.ToDecimal * TotalCalculableImpuestos, NumeroDecimales) + End If + + dr("IEPS") = dr("ImporteIEPS") + dr("Descuento") = Math.Round(0, NumeroDecimales) + dr("TipoDescuento") = HdnTipoDescuento.Value + dr("Total") = (Cantidad * PU) + dr("CveClasificacion") = drpss("CveClasificacion") + dr("CveSubProyecto") = CveSub + dr("TotalImporte") = Math.Round(Cantidad * PU, NumeroDecimales) + CveVentaP = gvrt.DataKey("CveVenta").ToEntero + tmpcon.Rows.Add(dr) + ii += 1 + End If + + Next + + '**** IMPUESTOS LOCALES + + factura.DtDetalle = tmpcon + Dim TotalSubTotal As Decimal = tmpcon.SUM("TotalImporte").ToDecimal + Dim TotalDescuentos As Decimal = tmpcon.SUM("Descuento").ToDecimal + + Dim TotalIVA As Decimal = tmpcon.SUM("ImporteIVA").ToDecimal + Dim TotalIEPS As Decimal = tmpcon.SUM("ImporteIEPS").ToDecimal + Dim TotalRetIVA As Decimal = tmpcon.SUM("ImporteRetIVA").ToDecimal + Dim TotalRetISR As Decimal = tmpcon.SUM("ImporteRetISR").ToDecimal + Dim Total As Decimal = 0 + Dim TotalImpuestosLocales As Decimal = 0 + Total = (TotalSubTotal - TotalDescuentos + TotalIVA + TotalIEPS - TotalRetIVA - TotalRetISR - TotalImpuestosLocales) + + factura.SubTotal = TotalSubTotal + factura.Descuento = 0 + factura.IVA = TotalIVA + factura.IEPS = TotalIEPS + factura.RetIVA = TotalRetIVA + factura.RetISR = TotalRetISR + factura.Total = Total + factura.CveVentaPadre = CveVentaP + + If DtVentasNC IsNot Nothing AndAlso DtVentasNC.Rows.Count > 0 Then + DtVentasNC.Rows(0)("Importe") = Total + DtVentasNC.Rows(0)("TC") = factura.TipoCambio + DtVentasNC.Rows(0)("TCCambioValuacion") = factura.TipoCambio + End If + + ObjFacturaDevolucion.Timbre = PreParaTimbre(ObjFacturaDevolucion) + + 'Registramos la venta + GuardarVenta(ObjVentas, ObjConta, ObjInventario, ObjContr, factura, tmpcon, -1, ObjContPaq, ObjBancos, EsNCAmortizacion:=True) + + Else + ErrorList.Add("No se encontró un producto para generar la nota de crédito") + End If + End If Return ProcesoCorrecto End Function @@ -8934,7 +8955,7 @@ Partial Class Ventas #Region " GUARDAR - VENTA, PREPOLIZAS, INV, ESTIMACIONES, AC, NOTA DE CRÉDITO " Private Sub GuardarVenta(ByRef ObjVentas As ClsVentas, ByRef ObjConta As ClsContabilidad, ByRef ObjInventario As ClsInventarios, ByRef ObjContr As ClsContratos, factura As Modelos.Factura, TmpDTDetalle As DataTable, CveNCaVincular As Integer, ByRef objContPaqi As ClsContPAQi, Optional ByRef ObjBancos As ClsBancos = Nothing, Optional ByRef ObjOS As ClsOS = Nothing, ByRef Optional ObjEventos As ClsOIEventos = Nothing, ByRef Optional ObjCGame As ClsCGame = Nothing, - ByRef Optional ObjCliente As ClsClientes = Nothing, Optional EsNCAmortizacion As Boolean = False) + ByRef Optional ObjCliente As ClsClientes = Nothing, Optional EsNCAmortizacion As Boolean = False, Optional NCDescuento As Boolean = False) Dim Msgok As New StringBuilder Dim CveAlmacenTraspasoOrigen As Integer = -1 @@ -9255,10 +9276,10 @@ Partial Class Ventas If ErrorList.Count = 0 Then 'prepoliza - GuardarVentaPrePolizas(ObjConta, factura, TmpDTDetalle, CveNCaVincular, objContPaqi, ObjBancos, ObjVentas, ObjEventos:=ObjEventos, EsNCAmortizacion:=EsNCAmortizacion) + GuardarVentaPrePolizas(ObjConta, factura, TmpDTDetalle, CveNCaVincular, objContPaqi, ObjBancos, ObjVentas, ObjEventos:=ObjEventos, EsNCAmortizacion:=EsNCAmortizacion, NCDescuento:=NCDescuento) If ErrorList.Count = 0 Then 'inventarios - If Not EsNCAmortizacion Then + If Not EsNCAmortizacion AndAlso Not NCDescuento Then If GuardarVentaInventarios(ObjInventario, ObjConta, factura) Then ErrorList.Add("Ocurrio un error al Guardar Inventario") End If @@ -9284,7 +9305,7 @@ Partial Class Ventas End Sub Private Sub GuardarVentaPrePolizas(ByRef ObjConta As ClsContabilidad, factura As Modelos.Factura, TmpDTDetalleMovimientos As DataTable, CveNCaVincular As Integer, ByRef objContPaqi As ClsContPAQi, Optional ByRef ObjBancos As ClsBancos = Nothing, ByRef Optional ObjVentas As ClsVentas = Nothing, - ByRef Optional ObjEventos As ClsOIEventos = Nothing, Optional EsNCAmortizacion As Boolean = False) + ByRef Optional ObjEventos As ClsOIEventos = Nothing, Optional EsNCAmortizacion As Boolean = False, Optional NCDescuento As Boolean = False) Dim CveIE As Integer = -1 Dim DT As DataTable = Nothing @@ -9303,7 +9324,7 @@ Partial Class Ventas If DdlTipoComprobante.SelectedValue <> "Cot" Then If factura.CvePrePoliza > 0 Then - If ProcesoPrepolizas(ObjConta, factura, CveIE, TmpDTDetalleMovimientos, objContPaqi, 1, ObjBancos, ObjVentas, ObjEventos:=ObjEventos, EsNCAmortizacion:=EsNCAmortizacion) Then + If ProcesoPrepolizas(ObjConta, factura, CveIE, TmpDTDetalleMovimientos, objContPaqi, 1, ObjBancos, ObjVentas, ObjEventos:=ObjEventos, EsNCAmortizacion:=EsNCAmortizacion, NCDescuento:=NCDescuento) Then ErrorList.Add("Ocurrió un error al agregar los Movimientos de la prepoliza.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico") End If @@ -9314,7 +9335,7 @@ Partial Class Ventas End Sub Private Function ProcesoPrepolizas(ByRef ObjConta As ClsContabilidad, ObjFactura As Modelos.Factura, CveIE As Integer, TmpDTDetalle As DataTable, ByRef objContPaqi As ClsContPAQi, Optional ValorMultiplicador As Integer = 1, ByRef Optional ObjBancos As ClsBancos = Nothing, ByRef Optional ObjVentas As ClsVentas = Nothing, - ByRef Optional ObjEventos As ClsOIEventos = Nothing, Optional EsNCAmortizacion As Boolean = False) As Boolean + ByRef Optional ObjEventos As ClsOIEventos = Nothing, Optional EsNCAmortizacion As Boolean = False, Optional NCDescuento As Boolean = False) As Boolean Try Dim DT As DataTable Dim CvePlantilaPoliza As Integer @@ -9563,37 +9584,37 @@ Partial Class Ventas 'APLICA NC SALDOS DIRECTOS If DtVentasNC IsNot Nothing AndAlso DtVentasNC.Rows.Count > 0 Then - For Each Dr As DataRow In DtVentasNC.Rows + For Each Dr As DataRow In DtVentasNC.Rows - Dim Importe91 As Decimal = 0 - Dim ImporteMN91 As Decimal = 0 - Dim Importe251 As Decimal = 0 - Dim ImporteMN251 As Decimal = 0 + Dim Importe91 As Decimal = 0 + Dim ImporteMN91 As Decimal = 0 + Dim Importe251 As Decimal = 0 + Dim ImporteMN251 As Decimal = 0 - If DdlMoneda.SelectedValue.ToEntero = 1 AndAlso Not Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then - Importe251 = Dr("Importe").ToString.ToDecimal - Importe91 = Dr("Importe").ToString.ToDecimal - ImporteMN91 = Dr("Importe").ToString.ToDecimal - TipoCambioNC = 1 - ElseIf DdlMoneda.SelectedValue.ToEntero = 2 AndAlso Not Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then - Importe251 = Dr("Importe").ToString.ToDecimal - Importe91 = Dr("Importe").ToString.ToDecimal - ImporteMN91 = Dr("Importe").ToString.ToDecimal * TipoCambioNC - ElseIf DdlMoneda.SelectedValue.ToEntero = 2 AndAlso Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then - Importe251 = Dr("Importe").ToString.ToDecimal - Importe91 = Dr("Importe").ToString.ToDecimal - ImporteMN91 = Dr("Importe").ToString.ToDecimal * TipoCambioNC - ElseIf DdlMoneda.SelectedValue.ToEntero = 1 AndAlso Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then + If DdlMoneda.SelectedValue.ToEntero = 1 AndAlso Not Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then + Importe251 = Dr("Importe").ToString.ToDecimal + Importe91 = Dr("Importe").ToString.ToDecimal + ImporteMN91 = Dr("Importe").ToString.ToDecimal + TipoCambioNC = 1 + ElseIf DdlMoneda.SelectedValue.ToEntero = 2 AndAlso Not Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then + Importe251 = Dr("Importe").ToString.ToDecimal + Importe91 = Dr("Importe").ToString.ToDecimal + ImporteMN91 = Dr("Importe").ToString.ToDecimal * TipoCambioNC + ElseIf DdlMoneda.SelectedValue.ToEntero = 2 AndAlso Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then + Importe251 = Dr("Importe").ToString.ToDecimal + Importe91 = Dr("Importe").ToString.ToDecimal + ImporteMN91 = Dr("Importe").ToString.ToDecimal * TipoCambioNC + ElseIf DdlMoneda.SelectedValue.ToEntero = 1 AndAlso Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then - Importe91 = Dr("Importe").ToString.ToDecimal / TipoCambioNC - ImporteMN91 = Dr("Importe").ToString.ToDecimal - End If + Importe91 = Dr("Importe").ToString.ToDecimal / TipoCambioNC + ImporteMN91 = Dr("Importe").ToString.ToDecimal + End If - Dim TCFluctuacion As Decimal = Dr("TCCambioValuacion").ToString.ToDecimal - If TCFluctuacion = 1 AndAlso TipoCambioNC > 1 Then - TCFluctuacion = GlobalTipoCambio(TxtFecha.Text.ToDate).ToDecimal - End If + Dim TCFluctuacion As Decimal = Dr("TCCambioValuacion").ToString.ToDecimal + If TCFluctuacion = 1 AndAlso TipoCambioNC > 1 Then + TCFluctuacion = GlobalTipoCambio(TxtFecha.Text.ToDate).ToDecimal + End If If DdlMoneda.SelectedValue.ToEntero = 2 AndAlso Not Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then ImporteMN251 = Dr("Importe").ToString.ToDecimal * TCFluctuacion @@ -9614,93 +9635,93 @@ Partial Class Ventas CveUltimaVenta = Dr("CveVenta").ToString.ToEntero - Dim ImporteComplementarioIngreso As Decimal = 0 - If UsaComplementariaClientes = True AndAlso tipoCambio > 1 Then - ImporteMN91 = Importe91 - ImporteComplementarioIngreso = ((Importe91 * tipoCambio) - Importe91).RoundSQL - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, False, Importe91, Referencia, 203, Concepto, FechaMovimiento, IdCtaContableClienteComplementaria, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=Dr("CveVenta").ToString.ToEntero, ImporteMX:=ImporteComplementarioIngreso, ImporteME:=If(tipoCambio = 1, 0, Importe91), CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio, TipoCambioPago:=Dr("TCCambioValuacion").ToString.ToDecimal) Then - ErrorPrepoliza = True - Exit For - End If - End If - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, False, Importe91, Referencia, 91, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=Dr("CveVenta").ToString.ToEntero, ImporteMX:=ImporteMN91, ImporteME:=If(tipoCambio = 1, 0, Importe91), CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio) Then + Dim ImporteComplementarioIngreso As Decimal = 0 + If UsaComplementariaClientes = True AndAlso tipoCambio > 1 Then + ImporteMN91 = Importe91 + ImporteComplementarioIngreso = ((Importe91 * tipoCambio) - Importe91).RoundSQL + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, False, Importe91, Referencia, 203, Concepto, FechaMovimiento, IdCtaContableClienteComplementaria, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=Dr("CveVenta").ToString.ToEntero, ImporteMX:=ImporteComplementarioIngreso, ImporteME:=If(tipoCambio = 1, 0, Importe91), CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio, TipoCambioPago:=Dr("TCCambioValuacion").ToString.ToDecimal) Then ErrorPrepoliza = True Exit For End If - ImporteAcumulado91 += (ImporteMN91).RoundSQL - - If UsaComplementariaClientes = True AndAlso Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then - ImporteMN251 = Importe251 - Dim ImporteComplementarioNC As Decimal = ((Importe251 * Dr("TCCambioValuacion").ToString.ToDecimal) - Importe251).RoundSQL - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, True, Importe251, Referencia, 207, Concepto, FechaMovimiento, IdCtaContableClienteComplementaria, -1, CveVenta:=Dr("CveVenta").ToString.ToEntero, CveCliente:=ObjFactura.CveCliente, ImporteMX:=ImporteComplementarioNC, ImporteME:=If(Dr("TCCambioValuacion").ToString.ToDecimal = 1, 0, Importe251), CveSubProyecto:=CveSubProyectoContabilizar, CveVentaAmortizacion:=ObjFactura.CveVenta, TipoCambio:=Dr("TCCambioValuacion").ToString.ToDecimal) Then - ErrorPrepoliza = True - Exit For - End If - End If - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, True, Importe251, Referencia, 251, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=Dr("CveVenta").ToString.ToEntero, CveCliente:=ObjFactura.CveCliente, ImporteMX:=ImporteMN251, ImporteME:=If(Dr("TCCambioValuacion").ToString.ToDecimal = 1, 0, Importe251), CveSubProyecto:=CveSubProyectoContabilizar, CveVentaAmortizacion:=ObjFactura.CveVenta, TipoCambio:=Dr("TCCambioValuacion").ToString.ToDecimal, TipoCambioPago:=tipoCambio) Then - ErrorPrepoliza = True - Exit For - End If - - - 'considero fluctuación. - - - If TipoCambioNC <> TCFluctuacion AndAlso TCFluctuacion > 1 AndAlso TipoCambioNC > 1 Then - Dim difFluctuacion As Decimal = TipoCambioNC - TCFluctuacion - Dim CveConceptoFluctua As Integer = 64 '64.ganacia, 65.perdida - Dim TipoMovtoFluctua As Boolean = True - Dim IdCtaContableFluctua As Integer - If difFluctuacion < 0 Then - CveConceptoFluctua = 65 - TipoMovtoFluctua = False - IdCtaContableFluctua = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria - Else - CveConceptoFluctua = 64 - TipoMovtoFluctua = True - IdCtaContableFluctua = UsuarioActual.Empresa.IdCuentaGananciaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria - End If - Dim ImporteFluctuacion As Decimal = Math.Abs((Importe251 * difFluctuacion).RoundSQL) - - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovtoFluctua, ImporteFluctuacion, Referencia, CveConceptoFluctua, Concepto, FechaMovimiento, IdCtaContableFluctua, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=Dr("CveVenta").ToString.ToEntero, ImporteMX:=ImporteFluctuacion, ImporteME:=ImporteFluctuacion, CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=TipoCambioNC, TipoCambioPago:=Dr("TCCambioValuacion").ToString.ToDecimal, CveCuenta:=CveCuenta) Then - ErrorPrepoliza = True - Exit For - End If - End If - - Next - - If ImporteConcepto12 < ImporteAcumulado91 Then - Dim ImporteOtrosIngresos As Decimal = ImporteConcepto12 - ImporteAcumulado91 - If ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, False, ImporteOtrosIngresos, Referencia, 91, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=CveUltimaVenta, ImporteMX:=ImporteOtrosIngresos, ImporteME:=0, CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio) Then - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, True, ImporteOtrosIngresos, Referencia, 211, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, ImporteME:=0, ImporteMX:=ImporteOtrosIngresos, CveSubProyecto:=CveSubProyectoContabilizar) Then - ErrorPrepoliza = True - End If - Else - ErrorPrepoliza = True - End If End If - - If ObjConta.ValidacionPrePolizaCuadre(ObjFactura.CvePrePoliza, 5) Then - If ObjConta.ValorPolizaDescuadre > 0 Then - 'ErrorPrepoliza = True - GuardaLogAD($"Ventas/Ventas-ProcesoPrePolizas | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{ObjFactura.CvePrePoliza}", "LogPrePolizas") - - 'SIRVE PARA VER LA PREPOLIZA QUE SE VALIDA - 'If ObjConta.GetPrePolizasDetalle(ObjFactura.CvePrePoliza) Then - ' Dim DtTest = ObjConta.DtResultados - 'End If - End If - End If - - - If ErrorPrepoliza Then + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, False, Importe91, Referencia, 91, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=Dr("CveVenta").ToString.ToEntero, ImporteMX:=ImporteMN91, ImporteME:=If(tipoCambio = 1, 0, Importe91), CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio) Then + ErrorPrepoliza = True Exit For End If + ImporteAcumulado91 += (ImporteMN91).RoundSQL + + If UsaComplementariaClientes = True AndAlso Dr("TCCambioValuacion").ToString.ToDecimal > 1 Then + ImporteMN251 = Importe251 + Dim ImporteComplementarioNC As Decimal = ((Importe251 * Dr("TCCambioValuacion").ToString.ToDecimal) - Importe251).RoundSQL + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, True, Importe251, Referencia, 207, Concepto, FechaMovimiento, IdCtaContableClienteComplementaria, -1, CveVenta:=Dr("CveVenta").ToString.ToEntero, CveCliente:=ObjFactura.CveCliente, ImporteMX:=ImporteComplementarioNC, ImporteME:=If(Dr("TCCambioValuacion").ToString.ToDecimal = 1, 0, Importe251), CveSubProyecto:=CveSubProyectoContabilizar, CveVentaAmortizacion:=ObjFactura.CveVenta, TipoCambio:=Dr("TCCambioValuacion").ToString.ToDecimal) Then + ErrorPrepoliza = True + Exit For + End If + End If + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, True, Importe251, Referencia, 251, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=Dr("CveVenta").ToString.ToEntero, CveCliente:=ObjFactura.CveCliente, ImporteMX:=ImporteMN251, ImporteME:=If(Dr("TCCambioValuacion").ToString.ToDecimal = 1, 0, Importe251), CveSubProyecto:=CveSubProyectoContabilizar, CveVentaAmortizacion:=ObjFactura.CveVenta, TipoCambio:=Dr("TCCambioValuacion").ToString.ToDecimal, TipoCambioPago:=tipoCambio) Then + ErrorPrepoliza = True + Exit For + End If + + + 'considero fluctuación. + + + If TipoCambioNC <> TCFluctuacion AndAlso TCFluctuacion > 1 AndAlso TipoCambioNC > 1 Then + Dim difFluctuacion As Decimal = TipoCambioNC - TCFluctuacion + Dim CveConceptoFluctua As Integer = 64 '64.ganacia, 65.perdida + Dim TipoMovtoFluctua As Boolean = True + Dim IdCtaContableFluctua As Integer + If difFluctuacion < 0 Then + CveConceptoFluctua = 65 + TipoMovtoFluctua = False + IdCtaContableFluctua = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + Else + CveConceptoFluctua = 64 + TipoMovtoFluctua = True + IdCtaContableFluctua = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria + End If + Dim ImporteFluctuacion As Decimal = Math.Abs((Importe251 * difFluctuacion).RoundSQL) + + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovtoFluctua, ImporteFluctuacion, Referencia, CveConceptoFluctua, Concepto, FechaMovimiento, IdCtaContableFluctua, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=Dr("CveVenta").ToString.ToEntero, ImporteMX:=ImporteFluctuacion, ImporteME:=ImporteFluctuacion, CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=TipoCambioNC, TipoCambioPago:=Dr("TCCambioValuacion").ToString.ToDecimal, CveCuenta:=CveCuenta) Then + ErrorPrepoliza = True + Exit For + End If + End If + + Next + + If ImporteConcepto12 < ImporteAcumulado91 Then + Dim ImporteOtrosIngresos As Decimal = ImporteConcepto12 - ImporteAcumulado91 + If ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, False, ImporteOtrosIngresos, Referencia, 91, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=CveUltimaVenta, ImporteMX:=ImporteOtrosIngresos, ImporteME:=0, CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio) Then + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, True, ImporteOtrosIngresos, Referencia, 211, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, ImporteME:=0, ImporteMX:=ImporteOtrosIngresos, CveSubProyecto:=CveSubProyectoContabilizar) Then + ErrorPrepoliza = True + End If + Else + ErrorPrepoliza = True + End If End If + If ObjConta.ValidacionPrePolizaCuadre(ObjFactura.CvePrePoliza, 5) Then + If ObjConta.ValorPolizaDescuadre > 0 Then + 'ErrorPrepoliza = True + GuardaLogAD($"Ventas/Ventas-ProcesoPrePolizas | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{ObjFactura.CvePrePoliza}", "LogPrePolizas") + + 'SIRVE PARA VER LA PREPOLIZA QUE SE VALIDA + 'If ObjConta.GetPrePolizasDetalle(ObjFactura.CvePrePoliza) Then + ' Dim DtTest = ObjConta.DtResultados + 'End If + End If + End If + + + If ErrorPrepoliza Then + Exit For + End If + End If + 'APLICA DEVOLUCION SALDOS DIRECTOS If AplicaDevolucion Then Dim importeMovimientoDev = TxtTotal.Text.ToDecimal @@ -9960,8 +9981,16 @@ Partial Class Ventas Next If UsuarioActual.Empresa.Funcionalidad(344) = "1" Then - If ListaRemisionesNC IsNot Nothing Then - For Each ObjRNC As Modelos.Factura In ListaRemisionesNC + Dim ListaNC As List(Of Modelos.Factura) = Nothing + + If NCDescuento Then + ListaNC = ListaNCDesc + Else + ListaNC = ListaRemisionesNC + End If + + If ListaNC IsNot Nothing Then + For Each ObjRNC As Modelos.Factura In ListaNC If ObjRNC.TipoDocto = "RNC" Then importeMovimiento = ObjRNC.TotalRemNCAplicado * -1 importeMX = importeMovimiento * tipoCambio * Multiplicador @@ -10101,7 +10130,7 @@ Partial Class Ventas importeMovimiento = 0 Case 150 'Descuento sobre ventas - If ObjFactura.TipoDocto.Contiene("Egs", "Dev") AndAlso Not EsNCAmortizacion Then + If (ObjFactura.TipoDocto.Contiene("Egs", "Dev") AndAlso Not EsNCAmortizacion) OrElse NCDescuento Then Dim ConceptoContableAplicar = 150 Dim CveVentaAplicar = ObjFactura.CveVenta @@ -13815,6 +13844,13 @@ Partial Class Ventas UpINV.Update() UPPPS.Update() End Sub + Private Sub CargaPorcentajeMarcas() + Dim ObjPS As New ClsProductosServicios + If ObjPS.GetPorcentajeMarcas(CveCliente) Then + DtPorcentajeMarcas = ObjPS.DtResultados.Copy() + End If + ObjPS.Dispose() + End Sub Private Function AgregarProductoServicio(Cantidad As Decimal, CveUM As Integer, UM As String, CveClasificacion As Integer, Clasificacion As String, CvePS As Integer, PS As String, Obs As String, PU As Decimal, Descuento As Decimal, CveProyecto As Integer, Proyecto As String, CveSubProyecto As Integer, SubProyecto As String, @@ -13891,13 +13927,6 @@ Partial Class Ventas End If End If - If Not ClienteDesglosaIEPS Then - If Not RegeneraIEPS Then - PU = PU * (1 + DrPS("IEPSPorcentaje").ToString.ToDecimal) - End If - DrPS("IEPSPorcentaje") = 0 - End If - 'verifica si tiene ventaminima If Cantidad > 0 AndAlso DrPS("VentaMinima").ToString.ToDecimal > 0 Then 'verifico que la cantidad sea multiplo de venta minima, es decir ventaminima =5, solo puede vender 5,10,15... @@ -13907,6 +13936,56 @@ Partial Class Ventas End If End If + If Not ClienteDesglosaIEPS Then + If Not RegeneraIEPS Then + PU = PU * (1 + DrPS("IEPSPorcentaje").ToString.ToDecimal) + End If + DrPS("IEPSPorcentaje") = 0 + End If + + 'VERIFICA SI APLICAN CONDICIONES COMERCIALES + If DtPorcentajeMarcas IsNot Nothing AndAlso DtPorcentajeMarcas.Rows.Count > 0 Then + 'VERIFICA SI EL PRODUCTO TIENE ESPECIFICADA UNA MARCA + If Not String.IsNullOrEmpty(DrPS("CveMarca").ToString()) AndAlso DrPS("CveMarca").ToString().ToEntero() > 0 Then + Dim RowPorcentaje = DtPorcentajeMarcas.FiltroPrimero($"CveMarca={DrPS("CveMarca").ToString()}") + 'REALIZA LOS DESCUENTOS DE ACUERDO AL PORCENTAJE POR MARCA + If RowPorcentaje IsNot Nothing Then + Dim PorcentajeProducto = RowPorcentaje("PorcentajeProducto").ToString().ToDecimal() / 100D + Dim PorcentajeProducto2 = RowPorcentaje("PorcentajeProducto2").ToString().ToDecimal() / 100D + Dim PorcentajeProducto3 = RowPorcentaje("PorcentajeProducto3").ToString().ToDecimal() / 100D + + Dim TotalInicial = (Cantidad * (PU)) - Descuento + Dim TotalFinal = TotalInicial + 'SI APLICA EL PRIMER DESCUENTO + If PorcentajeProducto > 0 Then + Dim Descuento1 = TotalInicial * PorcentajeProducto + Dim Total2 = (TotalInicial - Descuento1) + + 'SI APLICA EL SEGUNDO DESCUENTO + If PorcentajeProducto2 > 0 Then + Dim Descuento2 = Total2 * PorcentajeProducto2 + Dim Total3 = (Total2 - Descuento2) + + 'SI APLICA EL TERCER DESCUENTO + If PorcentajeProducto3 > 0 Then + Dim Descuento3 = Total3 * PorcentajeProducto3 + TotalFinal = Total3 - Descuento3 + Else + TotalFinal = Total3 + End If + Else + TotalFinal = Total2 + End If + Else + TotalFinal = TotalInicial + End If + + Descuento += ((Cantidad * PU) - TotalFinal) + + End If + End If + + End If TotalCalculableImpuestos = (Cantidad * (PU)) - Descuento Row("PU") = PU @@ -13939,8 +14018,6 @@ Partial Class Ventas Row("IVA") = Row("PorcentajeIVA") Row("ImporteIVA") = Math.Round(Row("PorcentajeIVA").ToString.ToDecimal * TotalCalculableImpuestos, NumeroDecimales) - - Row("ImporteRetIVA") = Math.Round(ClienteRetIVA * TotalCalculableImpuestos, NumeroDecimales) Row("ImporteRetISR") = Math.Round(ClienteRetISR * TotalCalculableImpuestos, NumeroDecimales) Row("PorcentajeRetIVA") = ClienteRetIVA @@ -14253,784 +14330,784 @@ Partial Class Ventas #End Region #End Region -#Region "M E T O D O S" - Private Sub CargaOtrosConceptos() - Dim ObjVentas As New ClsVentas - If ObjVentas.GetVentaOtrosConceptos(UsuarioActual.CveEmpresa, CveVenta) Then - GVOtrosConceptos.DataSource = ObjVentas.DtResultados - GVOtrosConceptos.DataBind() - UpOtrosConceptos.Update() - End If - ObjVentas.Dispose() - End Sub - Private Function GenerarPolizaAC(ObjAC As ClsContPAQi, factura As Modelos.Factura, Optional CancelacionIngreso As Boolean = False) As Integer - Dim Retorno As Integer = 0 - Dim IDPoliza As Integer = 0 - - Dim ErrorAC As Boolean = False - 'Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa) : ObjAC.IniciaTransacSQL() - Dim Fecha As Date = factura.Fecha - Dim Concepto As String = String.Format("GD {0}", factura.Cliente.Nombre) - Dim Paridad As Integer = 1 - Dim TipoMovto As Boolean = False - - If CancelacionIngreso Then - Concepto = String.Format("Cancelación GD {0}", factura.Cliente.Nombre) - Paridad = -1 - TipoMovto = True - End If - - Dim TipoPoliza = If(factura.TipoDocto = "OP" Or factura.TipoDocto = "Com", 3, 1) - - IDPoliza = ObjAC.AddPoliza(TipoPoliza, Concepto, factura.Total * 2, factura.Total * 2, factura.CveUsuario, Fecha) - Dim dr As DataRow ' = DTPresupuestoIngresos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", DdlFuenteRecaudacion.SelectedValue)) - 'Dim Importe As Double = TxtTotal.Text.ToDouble - Dim CtaCliente As Integer = factura.Cliente.IdCtaContClientes - Dim CtaISSSTESON As Integer = 643 - Dim CtaISPT As Integer = 1745 - ' Dim NombreCliente As String = ViewState("NombreCliente").ToString - - If IDPoliza > 0 Then - - 'Orden de PAGO - If factura.TipoDocto = "OP" Then - - If DdlOrdenPago.SelectedValue.ToEntero = 1 Then - 'ISSSTESON - - If ObjAC.AddMovimiento(IDPoliza, factura.Cliente.IdCtaContClientes, False, Paridad * factura.Total, "", Concepto, 0, Fecha, "") Then - If Not ObjAC.AddMovimiento(IDPoliza, CtaISSSTESON, True, Paridad * factura.Total, "", Concepto, 0, Fecha, "") Then - ErrorAC = True - End If - Else - ErrorAC = True - End If - - Else - 'ISPT - - If ObjAC.AddMovimiento(IDPoliza, factura.Cliente.IdCtaContClientes, False, Paridad * factura.Total, "", Concepto, 0, Fecha, "") Then - If Not ObjAC.AddMovimiento(IDPoliza, CtaISPT, True, Paridad * factura.Total, "", Concepto, 0, Fecha, "") Then - ErrorAC = True - End If - Else - ErrorAC = True - End If - End If - - ' NORMAL - Else - Dim Detalles = From gvr As GridViewRow In GvPS.Rows.Cast(Of GridViewRow)() - Group gvr By Grp = New With { - Key .CvePresupuestoIngreso = gvr.FCDropDownList("DdlFR").SelectedValue.ToEntero - } Into Group - Select Grp.CvePresupuestoIngreso, - TotalImporte = Group.Sum(Function(r) r.FCLiteral("LtlTotal").Text.ToDouble) - - - 'Select Case TipoComprobante - ' Case "Ing", "Egs" - For Each grp In Detalles - dr = DTPresupuestoIngresos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", grp.CvePresupuestoIngreso)) - Concepto = String.Format("{0} - {1}: {2}", NombreCliente, DdlTipoComprobante.SelectedItem.Text.ToString, TxtFolio.Text) - - If ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaPorEjecutar").ToString.ToEntero, False, Paridad * grp.TotalImporte, "", Concepto, 0, Fecha, "") Then - If ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, Paridad * grp.TotalImporte, "", Concepto, 0, Fecha, "") Then - 'CARGO la deuda del cliente - If ObjAC.AddMovimiento(IDPoliza, CtaCliente, TipoMovto, grp.TotalImporte, "", Concepto, 0, Fecha, "") Then - 'abono, - If Not ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaMatriz").ToString.ToEntero, Not TipoMovto, grp.TotalImporte, "", Concepto, 0, Fecha, "") Then - ErrorAC = True - End If - Else - ErrorAC = True - End If - Else - ErrorAC = True - End If - Else - ErrorAC = True - End If - Next - - 'Case "OP", "Com" - ' Dim Importe As Decimal = 0 - ' If ObjAC.AddMovimiento(123456, IDPoliza, CtaCliente, False, Importe, "", Concepto, 0, Fecha, "") Then - ' If ObjAC.AddMovimiento(123456, IDPoliza, CtaCliente, True, Importe, "", Concepto, 0, Fecha, "") Then - - ' End If - ' End If - 'End Select - End If - - Else - ErrorAC = True - - End If - - If Not ErrorAC Then - ObjAC.AjustaPoliza(IDPoliza) - - Retorno = IDPoliza - Else - - Alert("Error al agregar la Póliza de AC.", TipoMensaje.MsgError) - End If - - ' ObjAC.Dispose() - - Return Retorno - - End Function - Private Function GenerarPolizaAC(ObjAC As ClsContPAQi, Optional CancelacionIngreso As Boolean = False) As Integer - Dim Retorno As Integer = 0 - Dim IDPoliza As Integer = 0 - - Dim ErrorAC As Boolean = False - 'Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa) : ObjAC.IniciaTransacSQL() - Dim Fecha As Date = TxtFecha.Text.ToDate - Dim Concepto As String = String.Format("GD {0}", NombreCliente) - Dim Paridad As Integer = 1 - Dim TipoMovto As Boolean = False - - If CancelacionIngreso Then - Concepto = String.Format("Cancelación GD {0}", NombreCliente) - Paridad = -1 - TipoMovto = True - End If - - Dim TipoPoliza = If(DdlTipoComprobante.SelectedValue.ToString = "OP" Or DdlTipoComprobante.SelectedValue.ToString = "Com", 3, 1) - - IDPoliza = ObjAC.AddPoliza(TipoPoliza, Concepto, TxtTotal.Text.ToDouble * 2, TxtTotal.Text.ToDouble * 2, UsuarioActual.CveUsuario, Fecha) - Dim dr As DataRow ' = DTPresupuestoIngresos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", DdlFuenteRecaudacion.SelectedValue)) - 'Dim Importe As Double = TxtTotal.Text.ToDouble - Dim CtaCliente As Integer = ViewState("IdCtaContClientes").ToString.ToEntero - Dim CtaISSSTESON As Integer = 643 - Dim CtaISPT As Integer = 1745 - ' Dim NombreCliente As String = ViewState("NombreCliente").ToString - - If IDPoliza > 0 Then - - 'Orden de PAGO - If DdlTipoComprobante.SelectedValue.ToString = "OP" Then - - If DdlOrdenPago.SelectedValue.ToEntero = 1 Then - 'ISSSTESON - - If ObjAC.AddMovimiento(IDPoliza, CtaCliente, False, Paridad * TxtTotal.Text.ToDecimal, "", Concepto, 0, Fecha, "") Then - If Not ObjAC.AddMovimiento(IDPoliza, CtaISSSTESON, True, Paridad * TxtTotal.Text.ToDecimal, "", Concepto, 0, Fecha, "") Then - ErrorAC = True - End If - Else - ErrorAC = True - End If - - Else - 'ISPT - - If ObjAC.AddMovimiento(IDPoliza, CtaCliente, False, Paridad * TxtTotal.Text.ToDecimal, "", Concepto, 0, Fecha, "") Then - If Not ObjAC.AddMovimiento(IDPoliza, CtaISPT, True, Paridad * TxtTotal.Text.ToDecimal, "", Concepto, 0, Fecha, "") Then - ErrorAC = True - End If - Else - ErrorAC = True - End If - End If - - ' NORMAL - Else - Dim Detalles = From gvr As GridViewRow In GvPS.Rows.Cast(Of GridViewRow)() - Group gvr By Grp = New With { - Key .CvePresupuestoIngreso = gvr.FCDropDownList("DdlFR").SelectedValue.ToEntero - } Into Group - Select Grp.CvePresupuestoIngreso, - TotalImporte = Group.Sum(Function(r) r.FCLiteral("LtlTotal").Text.ToDouble) - - - 'Select Case TipoComprobante - ' Case "Ing", "Egs" - For Each grp In Detalles - dr = DTPresupuestoIngresos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", grp.CvePresupuestoIngreso)) - Concepto = String.Format("{0} - {1}: {2}", NombreCliente, DdlTipoComprobante.SelectedItem.Text.ToString, TxtFolio.Text) - - If ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaPorEjecutar").ToString.ToEntero, False, Paridad * grp.TotalImporte, "", Concepto, 0, Fecha, "") Then - If ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, Paridad * grp.TotalImporte, "", Concepto, 0, Fecha, "") Then - 'CARGO la deuda del cliente - If ObjAC.AddMovimiento(IDPoliza, CtaCliente, TipoMovto, grp.TotalImporte, "", Concepto, 0, Fecha, "") Then - 'abono, - If Not ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaMatriz").ToString.ToEntero, Not TipoMovto, grp.TotalImporte, "", Concepto, 0, Fecha, "") Then - ErrorAC = True - End If - Else - ErrorAC = True - End If - Else - ErrorAC = True - End If - Else - ErrorAC = True - End If - Next - - 'Case "OP", "Com" - ' Dim Importe As Decimal = 0 - ' If ObjAC.AddMovimiento(123456, IDPoliza, CtaCliente, False, Importe, "", Concepto, 0, Fecha, "") Then - ' If ObjAC.AddMovimiento(123456, IDPoliza, CtaCliente, True, Importe, "", Concepto, 0, Fecha, "") Then - - ' End If - ' End If - 'End Select - End If - - Else - ErrorAC = True - - End If - - If Not ErrorAC Then - ObjAC.AjustaPoliza(IDPoliza) - - Retorno = IDPoliza - Else - - Alert("Error al Agregar la Póliza de AC.", TipoMensaje.MsgError) - End If - - ' ObjAC.Dispose() - - Return Retorno - - End Function - Private Sub SetValues() - ViewState("TipoCambio") = 1 - - If UsuarioActual.Empresa.MostrarRetIVA Then TrRetIVA.Style.Add("display", "") - If UsuarioActual.Empresa.MostrarRetISR Then TrRetISR.Style.Add("display", "") - - If UsuarioActual.CveEmpresa.Contiene(72, 80) Then ' agregar en el modal de PS. que forme el código del producto - TxtPS.Enabled = False - DivDdlTipo.Visible = True - DivTxtModelo.Visible = True - DivTxtAdicional.Visible = True - DdlTipo.Attributes.Add("onChange", "CreaDescripcionPS();") - DdlMarcaPSDes.Attributes.Add("onChange", "CreaDescripcionPS();") - TxtModelo.Attributes.Add("onKeyUp ", "CreaDescripcionPS();") - TxtAdicional.Attributes.Add("onKeyUp ", "CreaDescripcionPS();") - - CargaClasificacionesDetalles() - ClasificacionModal() - - End If - - If Not UsuarioActual.CveEmpresa.Contiene(1, 119) Then 'PAGO CON TERMINAL PARA JAM - RBLPago.Items.RemoveAt(2) - End If - - - End Sub - Private Sub SetPermisos() - If CveVenta < 1 Then - 'Puede cotizar - If Not UsuarioActual.TienePermisoProceso(59) Then - DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Cot")) - End If - - 'Puede Hacer NC - If Not UsuarioActual.TienePermisoProceso(175) Then - DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Egs")) - End If - - 'Puede Hacer Devolución - If Not UsuarioActual.TienePermisoProceso(264) Then - DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Dev")) - End If - - 'Puede facturar - If Not UsuarioActual.TienePermisoProceso(60) Then - DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ing")) - DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ant")) - DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Egs")) - DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Dev")) - End If - - 'Puede remisionar - If Not UsuarioActual.TienePermisoProceso(199) Then - DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Rem")) - LnkFacturarRemision.Visible = False - LnkRemisiones.Visible = False - End If - - '[IPP]: FALTA CONFIGURAR Y DAR PERMISO A TODOS LOS QUE TENGAN ACCESO A VENTAS - ''Puede remisionar - 'If Not UsuarioActual.TienePermisoProceso(199) Then - ' DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Rem")) - 'End If - - ''MODO SOLO LECTURA - 'If DdlTipoComprobante.Items.Count = 0 Then - ' DdlTipoComprobante.Items.Insert(0, New ListItem("Solo lectura", "-1")) - ' TrBotones.Visible = False - 'End If - - ConfiguraTipoDocto() - End If - End Sub - Private Sub CalculaTotalesVenta(Optional RecalculaImpuestosLocales As Boolean = True) - - Dim TotalSubTotal As Decimal = TmpDT.SUM("TotalImporte").ToDecimal - Dim TotalDescuentos As Decimal = TmpDT.SUM("Descuento").ToDecimal - Dim TotalAmortizacion As Decimal = LblAmortizacion.Text.ToDecimal - Dim TotalIVA As Decimal = TmpDT.SUM("ImporteIVA").ToDecimal - Dim TotalIEPS As Decimal = TmpDT.SUM("ImporteIEPS").ToDecimal - Dim TotalRetIVA As Decimal = TmpDT.SUM("ImporteRetIVA").ToDecimal - Dim TotalRetISR As Decimal = TmpDT.SUM("ImporteRetISR").ToDecimal - Dim Total As Decimal = 0 - Dim TotalImpuestosLocales As Decimal = 0 - - If TotalAmortizacion > 0 AndAlso TotalSubTotal = TotalAmortizacion Then ' si se amortizó completa la factura, debe de limpiar los impuestos - If DdlTipoAmortizacionAnticipo.SelectedValue.Contiene("3") Then - For Each dr As DataRow In TmpDT.Rows - dr("ImporteIVA") = 0 : dr("ImporteIEPS") = 0 : dr("ImporteRetIVA") = 0 : dr("ImporteRetISR") = 0 : dr("PorcentajeIVA") = 0 : dr("IVA") = 0 - Next - - If TmpDTImpuestos IsNot Nothing Then - For Each dr2 As DataRow In TmpDTImpuestos.Rows - dr2("Importe") = 0 - Next - TmpDTImpuestos.AcceptChanges() - End If - - TmpDT.AcceptChanges() - TotalIVA = TmpDT.SUM("ImporteIVA").ToDecimal - TotalIEPS = TmpDT.SUM("ImporteIEPS").ToDecimal - TotalRetIVA = TmpDT.SUM("ImporteRetIVA").ToDecimal - TotalRetISR = TmpDT.SUM("ImporteRetISR").ToDecimal - TotalImpuestosLocales = TmpDTImpuestos.SUM("Importe").ToDecimal - End If - End If - - If RecalculaImpuestosLocales AndAlso TmpDTImpuestos IsNot Nothing AndAlso TmpDTImpuestos.Rows.Count > 0 Then - If TotalSubTotal <> TotalAmortizacion Then - For Each drt As DataRow In TmpDTImpuestos.Rows - drt("Importe") = drt("Porcentaje").ToString.ToDecimal * TotalSubTotal / 100 - Next - End If - - GvImpuestosLocales2.DataSource = TmpDTImpuestos - GvImpuestosLocales2.DataBind() - End If - - For Each gvr As GridViewRow In GvImpuestosLocales2.Rows - If gvr.RowType = DataControlRowType.DataRow Then - - If gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDecimal > 0 Then - If gvr.DataKey("TipoImpuesto") = "5" Then ' traslado de imp local - TotalImpuestosLocales -= gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDecimal - Else - TotalImpuestosLocales += gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDecimal - End If - End If - End If - Next - - 'If TotalDescuentos > 0 Then GvPS.Columns(ColumnaDescuento).Visible = True : thEncDesc1.Visible = True : thEncDesc2.Visible = True Else GvPS.Columns(ColumnaDescuento).Visible = False : thEncDesc1.Visible = False : thEncDesc2.Visible = False - If TotalIEPS > 0 Then TrIEPS.Visible = True : GvPS.Columns(ColumnaIEPS).Visible = True : thEncIEPS1.Visible = True : thEncIEPS2.Visible = True Else TrIEPS.Visible = False : GvPS.Columns(ColumnaIEPS).Visible = False : thEncIEPS1.Visible = False : thEncIEPS2.Visible = False - If TotalRetIVA > 0 Then GvPS.Columns(ColumnaRetIVA).Visible = True Else GvPS.Columns(ColumnaRetIVA).Visible = False - If TotalRetISR > 0 Then GvPS.Columns(ColumnaRetISR).Visible = True Else GvPS.Columns(ColumnaRetISR).Visible = False - - If DdlTipoAmortizacionAnticipo.SelectedValue.ToEntero.Contiene(2, 1) Then - TotalAmortizacion = 0 - End If - - - Total = (TotalSubTotal - TotalDescuentos - TotalAmortizacion + TotalIVA + TotalIEPS - TotalRetIVA - TotalRetISR - TotalImpuestosLocales) - LblSubTotal1.Text = TotalSubTotal.FormatoNumero(2) - TxtSubTotal.Text = TotalSubTotal.FormatoNumero(2) - LblDescuentos.Text = TotalDescuentos.FormatoNumero - TxtSubTotal2.Text = (TotalSubTotal - TotalDescuentos - TotalAmortizacion).FormatoNumero(2) - TxtRetIVA.Text = TotalRetIVA.FormatoNumero(2) - TxtRetISR.Text = TotalRetISR.FormatoNumero(2) - TxtIVA.Text = TotalIVA.FormatoNumero - TxtIEPS.Text = TotalIEPS.FormatoNumero - TxtTotal.Text = Total.FormatoNumero - - LblAmort.Text = TxtSubTotal.Text - If CveVenta <= 0 OrElse (CveDevolucion > 0 And NuevaFactura = 1) Then - HdnVentaSaldo.Value = Total.ToString - Else - HdnVentaSaldo.Value = SaldoVenta.ToString - End If - HdnIVAOriginal.Value = TxtIVA.Text - - 'JJMQ 20160506: Se agrego para la validacion de pago de contado. - 'CVImporteContado.ValueToCompare = Total.ToString - - If MensajeCveSAT IsNot Nothing AndAlso MensajeCveSAT.ToString.Length > 0 Then - Alert($"Los siguientes conceptos hace falta especificar clave SAT

{MensajeCveSAT.ToString}", TipoMensaje.MsgAdvertencia) - MensajeCveSAT.Clear() - End If - - Dim view As DataView = New DataView(TmpDT) - view.Sort = "Consec" - GvPS.DataSource = view - GvPS.DataBind() - - 'RECARGA GV INVENTARIO - If Not CveVenta > 0 Or DdlTipoComprobante.SelectedValue = "Cot" Then - DtInv = TmpDT.Copy.FiltraParametros("CveTipoPS = 2") - CargaGVInv(DtInv) - End If - - UpContado.Update() - UpPS.Update() - RegistraScript("BorraDescuentos();", "BorraDescuentos") - End Sub - Private Function ValidaAdendaFEMSA() As Boolean - Dim Retorno As Boolean = False - - If Not AplicaFEMSA Then - Retorno = True - Else - If TxtFEMSA_Version.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtFEMSA_Version.Text.Trim) Then - Retorno = False - Alert("La versión de la Adenda es requerida y debe ser numérica. Por favor corrija.", TipoMensaje.MsgAdvertencia) - ElseIf TxtFEMSA_NumSociedad.Text.Trim.Length = 0 Then - Retorno = False - Alert("El número de Sociedad para la Adenda es requerido. Por favor capture uno.", TipoMensaje.MsgAdvertencia) - ElseIf TxtFEMSA_NumProveedor.Text.Trim.Length = 0 Then - Retorno = False - Alert("El número de Proveedor para la Adenda es requerido. Por favor capture uno.", TipoMensaje.MsgAdvertencia) - ElseIf DdlTipoComprobante.SelectedValue = "Ing" AndAlso (TxtFEMSA_NumPedido.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtFEMSA_NumPedido.Text.Trim)) Then - Retorno = False - Alert("El número de Pedido para la Adenda es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) - ElseIf DdlTipoComprobante.SelectedValue = "Ing" AndAlso (TxtFEMSA_NumEntrada.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtFEMSA_NumEntrada.Text.Trim)) Then - Retorno = False - Alert("El número de Entrada para la Adenda es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) - ElseIf DdlTipoComprobante.SelectedValue = "Ing" AndAlso TxtFEMSA_NumRemision.Text.Trim.Length = 0 Then - Retorno = False - Alert("El número de Remisión para la Adenda es requerido. Por favor capture uno.", TipoMensaje.MsgAdvertencia) - ElseIf TxtFEMSA_Mail.Text.Trim.Length = 0 Then - Retorno = False - Alert("El Mail para la Adenda es requerido. Por favor capture uno.", TipoMensaje.MsgAdvertencia) - Else - Retorno = True - End If - End If - - Return Retorno - End Function - Private Function ValidaComplementoDetallista() As Boolean - Dim Retorno As Boolean = False - - If Not AplicaDetallista Then - Retorno = True - Else - If TxtDet_OrdenCompra.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtDet_OrdenCompra.Text.Trim) Then - Retorno = False - Alert("El campo Orden de Compra es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia, "") - ElseIf TxtDet_FechaOrdenCompra.Text.Trim.Length = 0 OrElse Not IsDate(TxtDet_FechaOrdenCompra.Text.Trim) Then - Retorno = False - Alert("El campo Fecha de Orden de Compra es requerido y debe de contar con un formato válido de fecha. Por favor corrija.", TipoMensaje.MsgAdvertencia) - ElseIf TxtDet_GLNComprador.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtDet_GLNComprador.Text.Trim) Then - Retorno = False - Alert("El campo GLN-Comprador es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) - ElseIf TxtDet_Departamento.Text.Trim.Length = 0 Then - Retorno = False - Alert("El campo Departamento es requerido. Por favor ingrese uno.", TipoMensaje.MsgAdvertencia) - ElseIf TxtDet_GLNVendedor.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtDet_GLNVendedor.Text.Trim) Then - Retorno = False - Alert("El campo GLN-Vendedor es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) - ElseIf TxtDet_NumProv.Text.Trim.Length = 0 Then - Retorno = False - Alert("El campo Número de Proveedor es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) - Else - Retorno = True - End If - End If - - Return Retorno - End Function - Private Function ValidaComplementoFord() As Boolean - Dim Retorno As Boolean = False - - If Not AplicaFord Then - Retorno = True - Else - If TxtFordGSDB.Text.Trim.Length = 0 Then - Retorno = False - Alert("El campo GSDB es requerido. Por favor corrija.", TipoMensaje.MsgAdvertencia) - Else - If LstFordASN.Items.Count = 0 Then - Retorno = True - 'Alert("El campo ASN es requerido. Por favor corrija.", TipoMensaje.MsgAdvertencia) - Else - Retorno = True - End If - - End If - End If - - Return Retorno - End Function - Private Sub VinculaCotizacionVenta() - Dim ObjVentas As New ClsVentas() - ObjVentas.UpdateVentaCotizacion(CveVenta, Request("CveVenta").ToEntero) - ObjVentas.Dispose() - End Sub - Private Sub GeneraAddenda7Eleven(Archivo As String) - Dim cfdi As String = "" - Dim SB As New StringBuilder - Try - Using sr As New StreamReader(Archivo) - - cfdi = sr.ReadToEnd() - - End Using - Catch e As Exception - Alert("The file could not be read:", TipoMensaje.MsgError) - - End Try - - - cfdi = cfdi.Replace("", "") - - SB.Append(cfdi) - - SB.Append("") - SB.AppendFormat("", Txt7ElevenNumProveedor.Text.Trim) - SB.AppendFormat("", Txt7ElevenFolio.Text.Trim, Txt7ElevenTienda.Text.Trim, Txt7ElevenFecha.Text.Trim.ToDate.ToString("yyyy-MM-dd")) - - For Each Row As DataRow In TmpDT.Rows - - SB.AppendFormat("", Row("Codigo"), Row("PS"), Row("Cantidad").ToString.ToDouble.FormatoNumero(), Row("PU").ToString.ToDouble.FormatoNumero()) - - Next - - SB.Append("") - - - Using outfile As New StreamWriter(Archivo) - outfile.Write(SB.ToString()) - End Using - - 'Exit Sub - - - - 'Dim MyXmlDocument As New XmlDocument() - - 'MyXmlDocument.Load("C:/Temp/aaa.xml") - 'Dim nsmgr = New XmlNamespaceManager(MyXmlDocument.NameTable) - 'nsmgr.AddNamespace("cfdi", "http://www.sat.gob.mx/cfd/3") - 'Dim ParentElement As XmlElement = MyXmlDocument.CreateElement("cfdi:Addenda", "https://edixcfisecure.ekomercio.com/esquemas") - 'ParentElement.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") - 'ParentElement.SetAttribute("xsi:schemaLocation", "https://edixcfisecure.ekomercio.com/esquemas https:/edixcfdisecure.ekomercio.com/esquemas/7Eleven.xsd") - - 'Dim Prov As XmlElement = MyXmlDocument.CreateElement("cfdi:Proveedor", "") - 'Prov.SetAttribute("Clave", "3125") - - 'Dim ns As String = "cfdi" 'MyXmlDocument.DocumentElement.GetNamespaceOfPrefix("cfdi") - 'Dim Recepciones As XmlElement = MyXmlDocument.CreateElement("cfdi:Recepciones") - 'Recepciones.Prefix = "cfdi" - 'Dim Recepcion As XmlElement = MyXmlDocument.CreateElement("cfdi:Recepcion") - 'Recepcion.SetAttribute("folio", Txt7ElevenFolio.Text.Trim) - 'Recepcion.SetAttribute("tienda", Txt7ElevenTienda.Text.Trim) - 'Recepcion.SetAttribute("fecha", Txt7ElevenFecha.Text.Trim.ToDate.ToString("yyyy-dd-MM")) - - 'Dim Productos As XmlElement = MyXmlDocument.CreateElement("cfdi:Productos") - ''dentro de un ciclo - 'Dim Producto As XmlElement = MyXmlDocument.CreateElement("cfdi:Producto") - 'Producto.SetAttribute("codigo", "cod1") - 'Producto.SetAttribute("descripcion", "prod1") - 'Producto.SetAttribute("cantidad", "99") - 'Producto.SetAttribute("precio", "2000") - 'Productos.AppendChild(Producto) - ''fin de ciclo - - 'Recepcion.AppendChild(Productos) - - 'Recepciones.AppendChild(Recepcion) - - 'ParentElement.AppendChild(Prov) - - 'ParentElement.AppendChild(Recepciones) - - - 'MyXmlDocument.DocumentElement.AppendChild(ParentElement) - 'MyXmlDocument.Save("C:/Temp/aa.xml") - - End Sub - Protected Sub DdlFuenteRecaudacion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlFuenteRecaudacion.SelectedIndexChanged - For Each dr As DataRow In TmpDT.Rows - dr("CvePresupuestoIngreso") = DdlFuenteRecaudacion.SelectedValue - Next - - GvPS.DataSource = TmpDT - GvPS.DataBind() - - UpPS.Update() - End Sub - Protected Sub DdlFR_SelectedIndexChanged(sender As Object, e As EventArgs) - Dim DdlFR_Gv As DropDownList = CType(sender, DropDownList) - Dim index As Integer = CType(DdlFR_Gv.NamingContainer, GridViewRow).FCLiteral("LtlConsecutivo").Text.ToString.ToEntero - - If UsuarioActual.Empresa.UsaAC Then - TmpDT(index - 1)("CvePresupuestoIngreso") = DdlFR_Gv.SelectedValue - End If - TmpDT.AcceptChanges() - End Sub - Protected Sub LnkASN_Click(sender As Object, e As EventArgs) Handles LnkASN.Click - If TxtFordASN.Text.Trim.Length > 20 Then Alert("Maximo 20 Caracteres", TipoMensaje.MsgAdvertencia) : Exit Sub - LstFordASN.Items.Add(New ListItem(TxtFordASN.Text.Trim)) - TxtFordASN.Text = "" - TxtFordASN.Focus() - End Sub - Protected Sub LnkFordQuitar_Click(sender As Object, e As EventArgs) Handles LnkFordQuitar.Click - LstFordASN.Items.RemoveAt(LstFordASN.SelectedIndex) - - End Sub - Private Sub LnkImprimir_Click(sender As Object, e As EventArgs) Handles LnkImprimir.Click - GeneraPDFCot(TxtFecha.Text.Trim.ToDate, Nothing, VentaFolio, False, False) - End Sub - Protected Sub TxtCodigo_TextChanged(sender As Object, e As System.EventArgs) Handles TxtCodigo.TextChanged - - Dim ObjClientes As New ClsClientes() - - Dim Nombre As String = "-1" - Dim Codigo As String = "-1" - Dim NombreCorto As String = "-1" - Dim RFC As String = "-1" - Dim Telefono As String = "-1" - Dim Mail As String = "-1" - - If TxtCodigo.Text.Trim <> String.Empty Then Codigo = TxtCodigo.Text.Trim - - If Codigo <> "-1" Then - If ObjClientes.GetClientes(-1, Nombre, Codigo, NombreCorto, RFC, Telefono, Mail, -1, UsuarioActual.CveEmpresa, TipoCliente:=-1) Then - If ObjClientes.DtResultados.Rows.Count > 0 Then - If UsuarioActual.CveEmpresa = 2 AndAlso UsuarioActual.CveUsuario = 77 AndAlso Not ObjClientes.CveCliente.Contiene(10450, 10460, 10458) Then - TrEmitir.Visible = False : BtnCrearApartirDe.Enabled = False : LbAgregar.Enabled = False : LnkAgregarPyME.Enabled = False : BtnBuscarCliente.Enabled = False : BtnEmitirImprimir.Visible = False : TrVistaPrevia.Visible = False - UpFacturar.Update() - Exit Sub - ElseIf UsuarioActual.CveEmpresa = 2 AndAlso UsuarioActual.CveUsuario = 21 AndAlso Not ObjClientes.CveCliente.Contiene(27448) Then - TrEmitir.Visible = False : BtnCrearApartirDe.Enabled = False : LbAgregar.Enabled = False : LnkAgregarPyME.Enabled = False : BtnBuscarCliente.Enabled = False : BtnEmitirImprimir.Visible = False : TrVistaPrevia.Visible = False - UpFacturar.Update() - Exit Sub - Else - HdnCveCliente.Value = ObjClientes.CveCliente.ToString - End If - BtnBuscarCliente_Click(sender, e) - Else - Alert("No se encontró el cliente con el código: " & TxtCodigo.Text.Trim & ".", Extensiones.TipoMensaje.MsgAdvertencia) - TxtCodigo.Text = "" - LblCliente.Text = "Cliente" - LblDireccion.Text = "Dirección" - LblColonia.Text = "Colonia" - LblCiudad.Text = "Ciudad" - LblEstado.Text = "Estado" - LblCP.Text = "00000" - LblRFC.Text = "AAA010101AAA" - LblTelefono.Text = "9999999999" - trsucursalciente.Visible = False - End If - End If - ObjClientes.Dispose() - - End If - End Sub - Protected Sub TxtFolio_TextChanged(sender As Object, e As System.EventArgs) Handles TxtFolio.TextChanged - ViewState("EstablecioFolio") = True - End Sub - Private Sub ConfiguraTipoDocto() - - 'Esconde Todo - TdOrdenPago.Visible = False - Tr33.Visible = False - - 'si tiene la funcionalidad que se active independiente del tipo de documento RMF 15-10-2017 - Tr33.Visible = True - - If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant") Then - BtnEmitirImprimir.Text = "Emitir e Imprimir" - 'TdReferencia.Style.Add("display", "none") - ElseIf DdlTipoComprobante.SelectedValue.Contiene("Egs", "Dev") Then - BtnEmitirImprimir.Text = "Emitir e Imprimir" - 'TdReferencia.Style.Remove("display") - ElseIf DdlTipoComprobante.SelectedValue = "Rem" Then - BtnEmitirImprimir.Text = "Registrar" - 'TdReferencia.Style.Add("display", "none") - ElseIf DdlTipoComprobante.SelectedValue.Contiene("Ped", "PeC", "PA", "Pd2") Then - BtnEmitirImprimir.Text = "Registrar" - 'TdReferencia.Style.Add("display", "none") - ElseIf DdlTipoComprobante.SelectedValue = "Cot" Then - BtnEmitirImprimir.Text = "Cotizar" - 'TdReferencia.Style.Add("display", "none") - - 'FACTURACION 3.3 - Tr33.Visible = True - - ElseIf DdlTipoComprobante.SelectedValue = "Com" Then - BtnEmitirImprimir.Text = "Registrar" - 'TdReferencia.Style.Add("display", "none") - ElseIf DdlTipoComprobante.SelectedValue.ToString = "OP" Then - BtnEmitirImprimir.Text = "Registrar" - TdOrdenPago.Visible = True - End If - - UpFacturar.Update() - - End Sub - Private Sub EliminaPoliza() - Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa) - ObjAC.IniciaTransacSQL() - Dim ObjConta As New ClsContabilidad - ObjConta.IniciaTransacSQL() - - Dim ErrorMovimiento = False - - 'Elimina la poliza - If (UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.UsaContabilidad) AndAlso IdPoliza > 0 Then - If Not ObjAC.RemovePoliza(IdPoliza) Then - ErrorMovimiento = True - End If - End If - - 'Desasocia la poliza - If Not ErrorMovimiento Then - If Not ObjConta.DesasociarPoliza(IdPoliza, UsuarioActual.CveEmpresa) Then - ErrorMovimiento = True - End If - End If - +#Region "M E T O D O S" + Private Sub CargaOtrosConceptos() + Dim ObjVentas As New ClsVentas + If ObjVentas.GetVentaOtrosConceptos(UsuarioActual.CveEmpresa, CveVenta) Then + GVOtrosConceptos.DataSource = ObjVentas.DtResultados + GVOtrosConceptos.DataBind() + UpOtrosConceptos.Update() + End If + ObjVentas.Dispose() + End Sub + Private Function GenerarPolizaAC(ObjAC As ClsContPAQi, factura As Modelos.Factura, Optional CancelacionIngreso As Boolean = False) As Integer + Dim Retorno As Integer = 0 + Dim IDPoliza As Integer = 0 + + Dim ErrorAC As Boolean = False + 'Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa) : ObjAC.IniciaTransacSQL() + Dim Fecha As Date = factura.Fecha + Dim Concepto As String = String.Format("GD {0}", factura.Cliente.Nombre) + Dim Paridad As Integer = 1 + Dim TipoMovto As Boolean = False + + If CancelacionIngreso Then + Concepto = String.Format("Cancelación GD {0}", factura.Cliente.Nombre) + Paridad = -1 + TipoMovto = True + End If + + Dim TipoPoliza = If(factura.TipoDocto = "OP" Or factura.TipoDocto = "Com", 3, 1) + + IDPoliza = ObjAC.AddPoliza(TipoPoliza, Concepto, factura.Total * 2, factura.Total * 2, factura.CveUsuario, Fecha) + Dim dr As DataRow ' = DTPresupuestoIngresos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", DdlFuenteRecaudacion.SelectedValue)) + 'Dim Importe As Double = TxtTotal.Text.ToDouble + Dim CtaCliente As Integer = factura.Cliente.IdCtaContClientes + Dim CtaISSSTESON As Integer = 643 + Dim CtaISPT As Integer = 1745 + ' Dim NombreCliente As String = ViewState("NombreCliente").ToString + + If IDPoliza > 0 Then + + 'Orden de PAGO + If factura.TipoDocto = "OP" Then + + If DdlOrdenPago.SelectedValue.ToEntero = 1 Then + 'ISSSTESON + + If ObjAC.AddMovimiento(IDPoliza, factura.Cliente.IdCtaContClientes, False, Paridad * factura.Total, "", Concepto, 0, Fecha, "") Then + If Not ObjAC.AddMovimiento(IDPoliza, CtaISSSTESON, True, Paridad * factura.Total, "", Concepto, 0, Fecha, "") Then + ErrorAC = True + End If + Else + ErrorAC = True + End If + + Else + 'ISPT + + If ObjAC.AddMovimiento(IDPoliza, factura.Cliente.IdCtaContClientes, False, Paridad * factura.Total, "", Concepto, 0, Fecha, "") Then + If Not ObjAC.AddMovimiento(IDPoliza, CtaISPT, True, Paridad * factura.Total, "", Concepto, 0, Fecha, "") Then + ErrorAC = True + End If + Else + ErrorAC = True + End If + End If + + ' NORMAL + Else + Dim Detalles = From gvr As GridViewRow In GvPS.Rows.Cast(Of GridViewRow)() + Group gvr By Grp = New With { + Key .CvePresupuestoIngreso = gvr.FCDropDownList("DdlFR").SelectedValue.ToEntero + } Into Group + Select Grp.CvePresupuestoIngreso, + TotalImporte = Group.Sum(Function(r) r.FCLiteral("LtlTotal").Text.ToDouble) + + + 'Select Case TipoComprobante + ' Case "Ing", "Egs" + For Each grp In Detalles + dr = DTPresupuestoIngresos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", grp.CvePresupuestoIngreso)) + Concepto = String.Format("{0} - {1}: {2}", NombreCliente, DdlTipoComprobante.SelectedItem.Text.ToString, TxtFolio.Text) + + If ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaPorEjecutar").ToString.ToEntero, False, Paridad * grp.TotalImporte, "", Concepto, 0, Fecha, "") Then + If ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, Paridad * grp.TotalImporte, "", Concepto, 0, Fecha, "") Then + 'CARGO la deuda del cliente + If ObjAC.AddMovimiento(IDPoliza, CtaCliente, TipoMovto, grp.TotalImporte, "", Concepto, 0, Fecha, "") Then + 'abono, + If Not ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaMatriz").ToString.ToEntero, Not TipoMovto, grp.TotalImporte, "", Concepto, 0, Fecha, "") Then + ErrorAC = True + End If + Else + ErrorAC = True + End If + Else + ErrorAC = True + End If + Else + ErrorAC = True + End If + Next + + 'Case "OP", "Com" + ' Dim Importe As Decimal = 0 + ' If ObjAC.AddMovimiento(123456, IDPoliza, CtaCliente, False, Importe, "", Concepto, 0, Fecha, "") Then + ' If ObjAC.AddMovimiento(123456, IDPoliza, CtaCliente, True, Importe, "", Concepto, 0, Fecha, "") Then + + ' End If + ' End If + 'End Select + End If + + Else + ErrorAC = True + + End If + + If Not ErrorAC Then + ObjAC.AjustaPoliza(IDPoliza) + + Retorno = IDPoliza + Else + + Alert("Error al agregar la Póliza de AC.", TipoMensaje.MsgError) + End If + + ' ObjAC.Dispose() + + Return Retorno + + End Function + Private Function GenerarPolizaAC(ObjAC As ClsContPAQi, Optional CancelacionIngreso As Boolean = False) As Integer + Dim Retorno As Integer = 0 + Dim IDPoliza As Integer = 0 + + Dim ErrorAC As Boolean = False + 'Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa) : ObjAC.IniciaTransacSQL() + Dim Fecha As Date = TxtFecha.Text.ToDate + Dim Concepto As String = String.Format("GD {0}", NombreCliente) + Dim Paridad As Integer = 1 + Dim TipoMovto As Boolean = False + + If CancelacionIngreso Then + Concepto = String.Format("Cancelación GD {0}", NombreCliente) + Paridad = -1 + TipoMovto = True + End If + + Dim TipoPoliza = If(DdlTipoComprobante.SelectedValue.ToString = "OP" Or DdlTipoComprobante.SelectedValue.ToString = "Com", 3, 1) + + IDPoliza = ObjAC.AddPoliza(TipoPoliza, Concepto, TxtTotal.Text.ToDouble * 2, TxtTotal.Text.ToDouble * 2, UsuarioActual.CveUsuario, Fecha) + Dim dr As DataRow ' = DTPresupuestoIngresos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", DdlFuenteRecaudacion.SelectedValue)) + 'Dim Importe As Double = TxtTotal.Text.ToDouble + Dim CtaCliente As Integer = ViewState("IdCtaContClientes").ToString.ToEntero + Dim CtaISSSTESON As Integer = 643 + Dim CtaISPT As Integer = 1745 + ' Dim NombreCliente As String = ViewState("NombreCliente").ToString + + If IDPoliza > 0 Then + + 'Orden de PAGO + If DdlTipoComprobante.SelectedValue.ToString = "OP" Then + + If DdlOrdenPago.SelectedValue.ToEntero = 1 Then + 'ISSSTESON + + If ObjAC.AddMovimiento(IDPoliza, CtaCliente, False, Paridad * TxtTotal.Text.ToDecimal, "", Concepto, 0, Fecha, "") Then + If Not ObjAC.AddMovimiento(IDPoliza, CtaISSSTESON, True, Paridad * TxtTotal.Text.ToDecimal, "", Concepto, 0, Fecha, "") Then + ErrorAC = True + End If + Else + ErrorAC = True + End If + + Else + 'ISPT + + If ObjAC.AddMovimiento(IDPoliza, CtaCliente, False, Paridad * TxtTotal.Text.ToDecimal, "", Concepto, 0, Fecha, "") Then + If Not ObjAC.AddMovimiento(IDPoliza, CtaISPT, True, Paridad * TxtTotal.Text.ToDecimal, "", Concepto, 0, Fecha, "") Then + ErrorAC = True + End If + Else + ErrorAC = True + End If + End If + + ' NORMAL + Else + Dim Detalles = From gvr As GridViewRow In GvPS.Rows.Cast(Of GridViewRow)() + Group gvr By Grp = New With { + Key .CvePresupuestoIngreso = gvr.FCDropDownList("DdlFR").SelectedValue.ToEntero + } Into Group + Select Grp.CvePresupuestoIngreso, + TotalImporte = Group.Sum(Function(r) r.FCLiteral("LtlTotal").Text.ToDouble) + + + 'Select Case TipoComprobante + ' Case "Ing", "Egs" + For Each grp In Detalles + dr = DTPresupuestoIngresos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", grp.CvePresupuestoIngreso)) + Concepto = String.Format("{0} - {1}: {2}", NombreCliente, DdlTipoComprobante.SelectedItem.Text.ToString, TxtFolio.Text) + + If ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaPorEjecutar").ToString.ToEntero, False, Paridad * grp.TotalImporte, "", Concepto, 0, Fecha, "") Then + If ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, Paridad * grp.TotalImporte, "", Concepto, 0, Fecha, "") Then + 'CARGO la deuda del cliente + If ObjAC.AddMovimiento(IDPoliza, CtaCliente, TipoMovto, grp.TotalImporte, "", Concepto, 0, Fecha, "") Then + 'abono, + If Not ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaMatriz").ToString.ToEntero, Not TipoMovto, grp.TotalImporte, "", Concepto, 0, Fecha, "") Then + ErrorAC = True + End If + Else + ErrorAC = True + End If + Else + ErrorAC = True + End If + Else + ErrorAC = True + End If + Next + + 'Case "OP", "Com" + ' Dim Importe As Decimal = 0 + ' If ObjAC.AddMovimiento(123456, IDPoliza, CtaCliente, False, Importe, "", Concepto, 0, Fecha, "") Then + ' If ObjAC.AddMovimiento(123456, IDPoliza, CtaCliente, True, Importe, "", Concepto, 0, Fecha, "") Then + + ' End If + ' End If + 'End Select + End If + + Else + ErrorAC = True + + End If + + If Not ErrorAC Then + ObjAC.AjustaPoliza(IDPoliza) + + Retorno = IDPoliza + Else + + Alert("Error al Agregar la Póliza de AC.", TipoMensaje.MsgError) + End If + + ' ObjAC.Dispose() + + Return Retorno + + End Function + Private Sub SetValues() + ViewState("TipoCambio") = 1 + + If UsuarioActual.Empresa.MostrarRetIVA Then TrRetIVA.Style.Add("display", "") + If UsuarioActual.Empresa.MostrarRetISR Then TrRetISR.Style.Add("display", "") + + If UsuarioActual.CveEmpresa.Contiene(72, 80) Then ' agregar en el modal de PS. que forme el código del producto + TxtPS.Enabled = False + DivDdlTipo.Visible = True + DivTxtModelo.Visible = True + DivTxtAdicional.Visible = True + DdlTipo.Attributes.Add("onChange", "CreaDescripcionPS();") + DdlMarcaPSDes.Attributes.Add("onChange", "CreaDescripcionPS();") + TxtModelo.Attributes.Add("onKeyUp ", "CreaDescripcionPS();") + TxtAdicional.Attributes.Add("onKeyUp ", "CreaDescripcionPS();") + + CargaClasificacionesDetalles() + ClasificacionModal() + + End If + + If Not UsuarioActual.CveEmpresa.Contiene(1, 119) Then 'PAGO CON TERMINAL PARA JAM + RBLPago.Items.RemoveAt(2) + End If + + + End Sub + Private Sub SetPermisos() + If CveVenta < 1 Then + 'Puede cotizar + If Not UsuarioActual.TienePermisoProceso(59) Then + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Cot")) + End If + + 'Puede Hacer NC + If Not UsuarioActual.TienePermisoProceso(175) Then + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Egs")) + End If + + 'Puede Hacer Devolución + If Not UsuarioActual.TienePermisoProceso(264) Then + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Dev")) + End If + + 'Puede facturar + If Not UsuarioActual.TienePermisoProceso(60) Then + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ing")) + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Ant")) + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Egs")) + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Dev")) + End If + + 'Puede remisionar + If Not UsuarioActual.TienePermisoProceso(199) Then + DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Rem")) + LnkFacturarRemision.Visible = False + LnkRemisiones.Visible = False + End If + + '[IPP]: FALTA CONFIGURAR Y DAR PERMISO A TODOS LOS QUE TENGAN ACCESO A VENTAS + ''Puede remisionar + 'If Not UsuarioActual.TienePermisoProceso(199) Then + ' DdlTipoComprobante.Items.Remove(DdlTipoComprobante.Items.FindByValue("Rem")) + 'End If + + ''MODO SOLO LECTURA + 'If DdlTipoComprobante.Items.Count = 0 Then + ' DdlTipoComprobante.Items.Insert(0, New ListItem("Solo lectura", "-1")) + ' TrBotones.Visible = False + 'End If + + ConfiguraTipoDocto() + End If + End Sub + Private Sub CalculaTotalesVenta(Optional RecalculaImpuestosLocales As Boolean = True, Optional NCDescuento As Boolean = False) + + Dim TotalSubTotal As Decimal = TmpDT.SUM("TotalImporte").ToDecimal + Dim TotalDescuentos As Decimal = TmpDT.SUM("Descuento").ToDecimal + Dim TotalAmortizacion As Decimal = LblAmortizacion.Text.ToDecimal + Dim TotalIVA As Decimal = TmpDT.SUM("ImporteIVA").ToDecimal + Dim TotalIEPS As Decimal = TmpDT.SUM("ImporteIEPS").ToDecimal + Dim TotalRetIVA As Decimal = TmpDT.SUM("ImporteRetIVA").ToDecimal + Dim TotalRetISR As Decimal = TmpDT.SUM("ImporteRetISR").ToDecimal + Dim Total As Decimal = 0 + Dim TotalImpuestosLocales As Decimal = 0 + + If TotalAmortizacion > 0 AndAlso TotalSubTotal = TotalAmortizacion Then ' si se amortizó completa la factura, debe de limpiar los impuestos + If DdlTipoAmortizacionAnticipo.SelectedValue.Contiene("3") Then + For Each dr As DataRow In TmpDT.Rows + dr("ImporteIVA") = 0 : dr("ImporteIEPS") = 0 : dr("ImporteRetIVA") = 0 : dr("ImporteRetISR") = 0 : dr("PorcentajeIVA") = 0 : dr("IVA") = 0 + Next + + If TmpDTImpuestos IsNot Nothing Then + For Each dr2 As DataRow In TmpDTImpuestos.Rows + dr2("Importe") = 0 + Next + TmpDTImpuestos.AcceptChanges() + End If + + TmpDT.AcceptChanges() + TotalIVA = TmpDT.SUM("ImporteIVA").ToDecimal + TotalIEPS = TmpDT.SUM("ImporteIEPS").ToDecimal + TotalRetIVA = TmpDT.SUM("ImporteRetIVA").ToDecimal + TotalRetISR = TmpDT.SUM("ImporteRetISR").ToDecimal + TotalImpuestosLocales = TmpDTImpuestos.SUM("Importe").ToDecimal + End If + End If + + If RecalculaImpuestosLocales AndAlso TmpDTImpuestos IsNot Nothing AndAlso TmpDTImpuestos.Rows.Count > 0 Then + If TotalSubTotal <> TotalAmortizacion Then + For Each drt As DataRow In TmpDTImpuestos.Rows + drt("Importe") = drt("Porcentaje").ToString.ToDecimal * TotalSubTotal / 100 + Next + End If + + GvImpuestosLocales2.DataSource = TmpDTImpuestos + GvImpuestosLocales2.DataBind() + End If + + For Each gvr As GridViewRow In GvImpuestosLocales2.Rows + If gvr.RowType = DataControlRowType.DataRow Then + + If gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDecimal > 0 Then + If gvr.DataKey("TipoImpuesto") = "5" Then ' traslado de imp local + TotalImpuestosLocales -= gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDecimal + Else + TotalImpuestosLocales += gvr.FCTextBox("TxtImpuestoLocalPS").Text.ToDecimal + End If + End If + End If + Next + + 'If TotalDescuentos > 0 Then GvPS.Columns(ColumnaDescuento).Visible = True : thEncDesc1.Visible = True : thEncDesc2.Visible = True Else GvPS.Columns(ColumnaDescuento).Visible = False : thEncDesc1.Visible = False : thEncDesc2.Visible = False + If TotalIEPS > 0 Then TrIEPS.Visible = True : GvPS.Columns(ColumnaIEPS).Visible = True : thEncIEPS1.Visible = True : thEncIEPS2.Visible = True Else TrIEPS.Visible = False : GvPS.Columns(ColumnaIEPS).Visible = False : thEncIEPS1.Visible = False : thEncIEPS2.Visible = False + If TotalRetIVA > 0 Then GvPS.Columns(ColumnaRetIVA).Visible = True Else GvPS.Columns(ColumnaRetIVA).Visible = False + If TotalRetISR > 0 Then GvPS.Columns(ColumnaRetISR).Visible = True Else GvPS.Columns(ColumnaRetISR).Visible = False + + If DdlTipoAmortizacionAnticipo.SelectedValue.ToEntero.Contiene(2, 1) Then + TotalAmortizacion = 0 + End If + + + Total = (TotalSubTotal - TotalDescuentos - TotalAmortizacion + TotalIVA + TotalIEPS - TotalRetIVA - TotalRetISR - TotalImpuestosLocales) + LblSubTotal1.Text = TotalSubTotal.FormatoNumero(2) + TxtSubTotal.Text = TotalSubTotal.FormatoNumero(2) + LblDescuentos.Text = TotalDescuentos.FormatoNumero + TxtSubTotal2.Text = (TotalSubTotal - TotalDescuentos - TotalAmortizacion).FormatoNumero(2) + TxtRetIVA.Text = TotalRetIVA.FormatoNumero(2) + TxtRetISR.Text = TotalRetISR.FormatoNumero(2) + TxtIVA.Text = TotalIVA.FormatoNumero + TxtIEPS.Text = TotalIEPS.FormatoNumero + TxtTotal.Text = Total.FormatoNumero + + LblAmort.Text = TxtSubTotal.Text + If CveVenta <= 0 OrElse (CveDevolucion > 0 And NuevaFactura = 1) Then + HdnVentaSaldo.Value = Total.ToString + Else + HdnVentaSaldo.Value = SaldoVenta.ToString + End If + HdnIVAOriginal.Value = TxtIVA.Text + + 'JJMQ 20160506: Se agrego para la validacion de pago de contado. + 'CVImporteContado.ValueToCompare = Total.ToString + + If MensajeCveSAT IsNot Nothing AndAlso MensajeCveSAT.ToString.Length > 0 Then + Alert($"Los siguientes conceptos hace falta especificar clave SAT

{MensajeCveSAT.ToString}", TipoMensaje.MsgAdvertencia) + MensajeCveSAT.Clear() + End If + + Dim view As DataView = New DataView(TmpDT) + view.Sort = "Consec" + GvPS.DataSource = view + GvPS.DataBind() + + 'RECARGA GV INVENTARIO + If Not CveVenta > 0 Or DdlTipoComprobante.SelectedValue = "Cot" Then + DtInv = TmpDT.Copy.FiltraParametros("CveTipoPS = 2") + CargaGVInv(DtInv) + End If + + UpContado.Update() + UpPS.Update() + RegistraScript("BorraDescuentos();", "BorraDescuentos") + End Sub + Private Function ValidaAdendaFEMSA() As Boolean + Dim Retorno As Boolean = False + + If Not AplicaFEMSA Then + Retorno = True + Else + If TxtFEMSA_Version.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtFEMSA_Version.Text.Trim) Then + Retorno = False + Alert("La versión de la Adenda es requerida y debe ser numérica. Por favor corrija.", TipoMensaje.MsgAdvertencia) + ElseIf TxtFEMSA_NumSociedad.Text.Trim.Length = 0 Then + Retorno = False + Alert("El número de Sociedad para la Adenda es requerido. Por favor capture uno.", TipoMensaje.MsgAdvertencia) + ElseIf TxtFEMSA_NumProveedor.Text.Trim.Length = 0 Then + Retorno = False + Alert("El número de Proveedor para la Adenda es requerido. Por favor capture uno.", TipoMensaje.MsgAdvertencia) + ElseIf DdlTipoComprobante.SelectedValue = "Ing" AndAlso (TxtFEMSA_NumPedido.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtFEMSA_NumPedido.Text.Trim)) Then + Retorno = False + Alert("El número de Pedido para la Adenda es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) + ElseIf DdlTipoComprobante.SelectedValue = "Ing" AndAlso (TxtFEMSA_NumEntrada.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtFEMSA_NumEntrada.Text.Trim)) Then + Retorno = False + Alert("El número de Entrada para la Adenda es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) + ElseIf DdlTipoComprobante.SelectedValue = "Ing" AndAlso TxtFEMSA_NumRemision.Text.Trim.Length = 0 Then + Retorno = False + Alert("El número de Remisión para la Adenda es requerido. Por favor capture uno.", TipoMensaje.MsgAdvertencia) + ElseIf TxtFEMSA_Mail.Text.Trim.Length = 0 Then + Retorno = False + Alert("El Mail para la Adenda es requerido. Por favor capture uno.", TipoMensaje.MsgAdvertencia) + Else + Retorno = True + End If + End If + + Return Retorno + End Function + Private Function ValidaComplementoDetallista() As Boolean + Dim Retorno As Boolean = False + + If Not AplicaDetallista Then + Retorno = True + Else + If TxtDet_OrdenCompra.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtDet_OrdenCompra.Text.Trim) Then + Retorno = False + Alert("El campo Orden de Compra es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia, "") + ElseIf TxtDet_FechaOrdenCompra.Text.Trim.Length = 0 OrElse Not IsDate(TxtDet_FechaOrdenCompra.Text.Trim) Then + Retorno = False + Alert("El campo Fecha de Orden de Compra es requerido y debe de contar con un formato válido de fecha. Por favor corrija.", TipoMensaje.MsgAdvertencia) + ElseIf TxtDet_GLNComprador.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtDet_GLNComprador.Text.Trim) Then + Retorno = False + Alert("El campo GLN-Comprador es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) + ElseIf TxtDet_Departamento.Text.Trim.Length = 0 Then + Retorno = False + Alert("El campo Departamento es requerido. Por favor ingrese uno.", TipoMensaje.MsgAdvertencia) + ElseIf TxtDet_GLNVendedor.Text.Trim.Length = 0 OrElse Not IsNumeric(TxtDet_GLNVendedor.Text.Trim) Then + Retorno = False + Alert("El campo GLN-Vendedor es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) + ElseIf TxtDet_NumProv.Text.Trim.Length = 0 Then + Retorno = False + Alert("El campo Número de Proveedor es requerido y debe ser numérico. Por favor corrija.", TipoMensaje.MsgAdvertencia) + Else + Retorno = True + End If + End If + + Return Retorno + End Function + Private Function ValidaComplementoFord() As Boolean + Dim Retorno As Boolean = False + + If Not AplicaFord Then + Retorno = True + Else + If TxtFordGSDB.Text.Trim.Length = 0 Then + Retorno = False + Alert("El campo GSDB es requerido. Por favor corrija.", TipoMensaje.MsgAdvertencia) + Else + If LstFordASN.Items.Count = 0 Then + Retorno = True + 'Alert("El campo ASN es requerido. Por favor corrija.", TipoMensaje.MsgAdvertencia) + Else + Retorno = True + End If + + End If + End If + + Return Retorno + End Function + Private Sub VinculaCotizacionVenta() + Dim ObjVentas As New ClsVentas() + ObjVentas.UpdateVentaCotizacion(CveVenta, Request("CveVenta").ToEntero) + ObjVentas.Dispose() + End Sub + Private Sub GeneraAddenda7Eleven(Archivo As String) + Dim cfdi As String = "" + Dim SB As New StringBuilder + Try + Using sr As New StreamReader(Archivo) + + cfdi = sr.ReadToEnd() + + End Using + Catch e As Exception + Alert("The file could not be read:", TipoMensaje.MsgError) + + End Try + + + cfdi = cfdi.Replace("", "") + + SB.Append(cfdi) + + SB.Append("") + SB.AppendFormat("", Txt7ElevenNumProveedor.Text.Trim) + SB.AppendFormat("", Txt7ElevenFolio.Text.Trim, Txt7ElevenTienda.Text.Trim, Txt7ElevenFecha.Text.Trim.ToDate.ToString("yyyy-MM-dd")) + + For Each Row As DataRow In TmpDT.Rows + + SB.AppendFormat("", Row("Codigo"), Row("PS"), Row("Cantidad").ToString.ToDouble.FormatoNumero(), Row("PU").ToString.ToDouble.FormatoNumero()) + + Next + + SB.Append("") + + + Using outfile As New StreamWriter(Archivo) + outfile.Write(SB.ToString()) + End Using + + 'Exit Sub + + + + 'Dim MyXmlDocument As New XmlDocument() + + 'MyXmlDocument.Load("C:/Temp/aaa.xml") + 'Dim nsmgr = New XmlNamespaceManager(MyXmlDocument.NameTable) + 'nsmgr.AddNamespace("cfdi", "http://www.sat.gob.mx/cfd/3") + 'Dim ParentElement As XmlElement = MyXmlDocument.CreateElement("cfdi:Addenda", "https://edixcfisecure.ekomercio.com/esquemas") + 'ParentElement.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") + 'ParentElement.SetAttribute("xsi:schemaLocation", "https://edixcfisecure.ekomercio.com/esquemas https:/edixcfdisecure.ekomercio.com/esquemas/7Eleven.xsd") + + 'Dim Prov As XmlElement = MyXmlDocument.CreateElement("cfdi:Proveedor", "") + 'Prov.SetAttribute("Clave", "3125") + + 'Dim ns As String = "cfdi" 'MyXmlDocument.DocumentElement.GetNamespaceOfPrefix("cfdi") + 'Dim Recepciones As XmlElement = MyXmlDocument.CreateElement("cfdi:Recepciones") + 'Recepciones.Prefix = "cfdi" + 'Dim Recepcion As XmlElement = MyXmlDocument.CreateElement("cfdi:Recepcion") + 'Recepcion.SetAttribute("folio", Txt7ElevenFolio.Text.Trim) + 'Recepcion.SetAttribute("tienda", Txt7ElevenTienda.Text.Trim) + 'Recepcion.SetAttribute("fecha", Txt7ElevenFecha.Text.Trim.ToDate.ToString("yyyy-dd-MM")) + + 'Dim Productos As XmlElement = MyXmlDocument.CreateElement("cfdi:Productos") + ''dentro de un ciclo + 'Dim Producto As XmlElement = MyXmlDocument.CreateElement("cfdi:Producto") + 'Producto.SetAttribute("codigo", "cod1") + 'Producto.SetAttribute("descripcion", "prod1") + 'Producto.SetAttribute("cantidad", "99") + 'Producto.SetAttribute("precio", "2000") + 'Productos.AppendChild(Producto) + ''fin de ciclo + + 'Recepcion.AppendChild(Productos) + + 'Recepciones.AppendChild(Recepcion) + + 'ParentElement.AppendChild(Prov) + + 'ParentElement.AppendChild(Recepciones) + + + 'MyXmlDocument.DocumentElement.AppendChild(ParentElement) + 'MyXmlDocument.Save("C:/Temp/aa.xml") + + End Sub + Protected Sub DdlFuenteRecaudacion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlFuenteRecaudacion.SelectedIndexChanged + For Each dr As DataRow In TmpDT.Rows + dr("CvePresupuestoIngreso") = DdlFuenteRecaudacion.SelectedValue + Next + + GvPS.DataSource = TmpDT + GvPS.DataBind() + + UpPS.Update() + End Sub + Protected Sub DdlFR_SelectedIndexChanged(sender As Object, e As EventArgs) + Dim DdlFR_Gv As DropDownList = CType(sender, DropDownList) + Dim index As Integer = CType(DdlFR_Gv.NamingContainer, GridViewRow).FCLiteral("LtlConsecutivo").Text.ToString.ToEntero + + If UsuarioActual.Empresa.UsaAC Then + TmpDT(index - 1)("CvePresupuestoIngreso") = DdlFR_Gv.SelectedValue + End If + TmpDT.AcceptChanges() + End Sub + Protected Sub LnkASN_Click(sender As Object, e As EventArgs) Handles LnkASN.Click + If TxtFordASN.Text.Trim.Length > 20 Then Alert("Maximo 20 Caracteres", TipoMensaje.MsgAdvertencia) : Exit Sub + LstFordASN.Items.Add(New ListItem(TxtFordASN.Text.Trim)) + TxtFordASN.Text = "" + TxtFordASN.Focus() + End Sub + Protected Sub LnkFordQuitar_Click(sender As Object, e As EventArgs) Handles LnkFordQuitar.Click + LstFordASN.Items.RemoveAt(LstFordASN.SelectedIndex) + + End Sub + Private Sub LnkImprimir_Click(sender As Object, e As EventArgs) Handles LnkImprimir.Click + GeneraPDFCot(TxtFecha.Text.Trim.ToDate, Nothing, VentaFolio, False, False) + End Sub + Protected Sub TxtCodigo_TextChanged(sender As Object, e As System.EventArgs) Handles TxtCodigo.TextChanged + + Dim ObjClientes As New ClsClientes() + + Dim Nombre As String = "-1" + Dim Codigo As String = "-1" + Dim NombreCorto As String = "-1" + Dim RFC As String = "-1" + Dim Telefono As String = "-1" + Dim Mail As String = "-1" + + If TxtCodigo.Text.Trim <> String.Empty Then Codigo = TxtCodigo.Text.Trim + + If Codigo <> "-1" Then + If ObjClientes.GetClientes(-1, Nombre, Codigo, NombreCorto, RFC, Telefono, Mail, -1, UsuarioActual.CveEmpresa, TipoCliente:=-1) Then + If ObjClientes.DtResultados.Rows.Count > 0 Then + If UsuarioActual.CveEmpresa = 2 AndAlso UsuarioActual.CveUsuario = 77 AndAlso Not ObjClientes.CveCliente.Contiene(10450, 10460, 10458) Then + TrEmitir.Visible = False : BtnCrearApartirDe.Enabled = False : LbAgregar.Enabled = False : LnkAgregarPyME.Enabled = False : BtnBuscarCliente.Enabled = False : BtnEmitirImprimir.Visible = False : TrVistaPrevia.Visible = False + UpFacturar.Update() + Exit Sub + ElseIf UsuarioActual.CveEmpresa = 2 AndAlso UsuarioActual.CveUsuario = 21 AndAlso Not ObjClientes.CveCliente.Contiene(27448) Then + TrEmitir.Visible = False : BtnCrearApartirDe.Enabled = False : LbAgregar.Enabled = False : LnkAgregarPyME.Enabled = False : BtnBuscarCliente.Enabled = False : BtnEmitirImprimir.Visible = False : TrVistaPrevia.Visible = False + UpFacturar.Update() + Exit Sub + Else + HdnCveCliente.Value = ObjClientes.CveCliente.ToString + End If + BtnBuscarCliente_Click(sender, e) + Else + Alert("No se encontró el cliente con el código: " & TxtCodigo.Text.Trim & ".", Extensiones.TipoMensaje.MsgAdvertencia) + TxtCodigo.Text = "" + LblCliente.Text = "Cliente" + LblDireccion.Text = "Dirección" + LblColonia.Text = "Colonia" + LblCiudad.Text = "Ciudad" + LblEstado.Text = "Estado" + LblCP.Text = "00000" + LblRFC.Text = "AAA010101AAA" + LblTelefono.Text = "9999999999" + trsucursalciente.Visible = False + End If + End If + ObjClientes.Dispose() + + End If + End Sub + Protected Sub TxtFolio_TextChanged(sender As Object, e As System.EventArgs) Handles TxtFolio.TextChanged + ViewState("EstablecioFolio") = True + End Sub + Private Sub ConfiguraTipoDocto() + + 'Esconde Todo + TdOrdenPago.Visible = False + Tr33.Visible = False + + 'si tiene la funcionalidad que se active independiente del tipo de documento RMF 15-10-2017 + Tr33.Visible = True + + If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant") Then + BtnEmitirImprimir.Text = "Emitir e Imprimir" + 'TdReferencia.Style.Add("display", "none") + ElseIf DdlTipoComprobante.SelectedValue.Contiene("Egs", "Dev") Then + BtnEmitirImprimir.Text = "Emitir e Imprimir" + 'TdReferencia.Style.Remove("display") + ElseIf DdlTipoComprobante.SelectedValue = "Rem" Then + BtnEmitirImprimir.Text = "Registrar" + 'TdReferencia.Style.Add("display", "none") + ElseIf DdlTipoComprobante.SelectedValue.Contiene("Ped", "PeC", "PA", "Pd2") Then + BtnEmitirImprimir.Text = "Registrar" + 'TdReferencia.Style.Add("display", "none") + ElseIf DdlTipoComprobante.SelectedValue = "Cot" Then + BtnEmitirImprimir.Text = "Cotizar" + 'TdReferencia.Style.Add("display", "none") + + 'FACTURACION 3.3 + Tr33.Visible = True + + ElseIf DdlTipoComprobante.SelectedValue = "Com" Then + BtnEmitirImprimir.Text = "Registrar" + 'TdReferencia.Style.Add("display", "none") + ElseIf DdlTipoComprobante.SelectedValue.ToString = "OP" Then + BtnEmitirImprimir.Text = "Registrar" + TdOrdenPago.Visible = True + End If + + UpFacturar.Update() + + End Sub + Private Sub EliminaPoliza() + Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa) + ObjAC.IniciaTransacSQL() + Dim ObjConta As New ClsContabilidad + ObjConta.IniciaTransacSQL() + + Dim ErrorMovimiento = False + + 'Elimina la poliza + If (UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.UsaContabilidad) AndAlso IdPoliza > 0 Then + If Not ObjAC.RemovePoliza(IdPoliza) Then + ErrorMovimiento = True + End If + End If + + 'Desasocia la poliza + If Not ErrorMovimiento Then + If Not ObjConta.DesasociarPoliza(IdPoliza, UsuarioActual.CveEmpresa) Then + ErrorMovimiento = True + End If + End If + If Not ErrorMovimiento Then If Not ObjConta.UpdatePrePolizasDetalleBloquear(CvePrePoliza, False) Then ErrorMovimiento = True End If - End If - - If Not ErrorMovimiento Then - Alert("La póliza ha sido desvinculada y eliminada con éxito.", TipoMensaje.MsgInformacion) - ObjAC.Commit() - ObjConta.Commit() - BtnDescontabilizar.Visible = False - Else - Alert("Ocurrió un error al desvincular y/o eliminar la póliza. Por favor intente de nuevo ", TipoMensaje.MsgError) - ObjAC.RollBack() - ObjConta.RollBack() - End If - - ObjAC.Dispose() - ObjConta.Dispose() - - End Sub - Protected Sub DdlPS_SelectedIndexChanged1(sender As Object, e As EventArgs) - Dim Ddl As DropDownList = CType(sender, DropDownList) - Dim gvr As GridViewRow = CType(Ddl.BindingContainer, GridViewRow) - gvr.FCDropDownList("DdlUnidadMedida").DataSource = GlobalDTProductosServiciosEquivalencias(Ddl.SelectedValue.ToEntero, -1) - gvr.FCDropDownList("DdlUnidadMedida").DataBind() - - End Sub - Private Function TraspasoAlmacen(ByRef ObjInventario As ClsInventarios, CveRemision As Integer, ByRef ObjConta As ClsContabilidad, ConSalida As Boolean, ConceptoMovimiento As Integer) As Boolean + End If + + If Not ErrorMovimiento Then + Alert("La póliza ha sido desvinculada y eliminada con éxito.", TipoMensaje.MsgInformacion) + ObjAC.Commit() + ObjConta.Commit() + BtnDescontabilizar.Visible = False + Else + Alert("Ocurrió un error al desvincular y/o eliminar la póliza. Por favor intente de nuevo ", TipoMensaje.MsgError) + ObjAC.RollBack() + ObjConta.RollBack() + End If + + ObjAC.Dispose() + ObjConta.Dispose() + + End Sub + Protected Sub DdlPS_SelectedIndexChanged1(sender As Object, e As EventArgs) + Dim Ddl As DropDownList = CType(sender, DropDownList) + Dim gvr As GridViewRow = CType(Ddl.BindingContainer, GridViewRow) + gvr.FCDropDownList("DdlUnidadMedida").DataSource = GlobalDTProductosServiciosEquivalencias(Ddl.SelectedValue.ToEntero, -1) + gvr.FCDropDownList("DdlUnidadMedida").DataBind() + + End Sub + Private Function TraspasoAlmacen(ByRef ObjInventario As ClsInventarios, CveRemision As Integer, ByRef ObjConta As ClsContabilidad, ConSalida As Boolean, ConceptoMovimiento As Integer) As Boolean Dim OcurrioError As Boolean = False Try Dim DtMovimientos As DataTable @@ -16721,14 +16798,29 @@ Partial Class Ventas Private Function ValidaPagosContado() As Boolean Dim Retorno = False - If (UsuarioActual.CveEmpresa = 140) AndAlso (Not PermiteCredito) AndAlso (DtPagos Is Nothing OrElse DtPagos.Rows.Count = 0) And TxtTotal.Text.ToDecimal > 0 Then + If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem", "Ant") AndAlso (UsuarioActual.CveEmpresa = 140) AndAlso (Not PermiteCredito) AndAlso (DtPagos Is Nothing OrElse DtPagos.Rows.Count = 0) And TxtTotal.Text.ToDecimal > 0 Then Alert("Es necesario especificar un pago.", TipoMensaje.MsgAdvertencia) Retorno = True End If - If (DtPagos.SUM("Importe").ToString.ToDecimal + Total - TxtCambio.Text.ToDecimal) > TxtTotal.Text.ToDecimal Then - Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) - Retorno = True + If UsuarioActual.Empresa.Funcionalidad(572) = "1" Then + Dim TotalNC As Decimal = If(ListaNCDesc IsNot Nothing AndAlso ListaNCDesc.Count > 0, ListaNCDesc.Sum(Function(f) f.TotalRemNCAplicado), 0) + If TotalNC > 0 Then + If (DtPagos.SUM("Importe").ToString.ToDecimal + Total - TxtCambio.Text.ToDecimal) > TotalNC Then + Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) + Retorno = True + End If + Else + If (DtPagos.SUM("Importe").ToString.ToDecimal + Total - TxtCambio.Text.ToDecimal) > TxtTotal.Text.ToDecimal Then + Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) + Retorno = True + End If + End If + Else + If (DtPagos.SUM("Importe").ToString.ToDecimal + Total - TxtCambio.Text.ToDecimal) > TxtTotal.Text.ToDecimal Then + Alert("El importe de los pagos no puede exceder el importe de la factura. Por favor verifique.", TipoMensaje.MsgAdvertencia) + Retorno = True + End If End If Return Retorno @@ -16898,13 +16990,13 @@ Partial Class Ventas Private Sub BtnAgregarCliente_Click(sender As Object, e As EventArgs) Handles BtnAgregarCliente.Click Dim CvePreioLista As Integer = -1 - If DdlSubProyectoDatos.SelectedValue.ToEntero > 0 Then - Dim Dr As DataRow = GlobalDTSubProyectos(-1, DdlSubProyectoDatos.SelectedValue.ToEntero, UsuarioActual.CveEmpresa).Rows(0) - If Dr IsNot Nothing Then - If Dr("CvePrecioLista").ToString.ToEntero > 0 Then - CvePreioLista = Dr("CvePrecioLista").ToString.ToEntero - End If - End If + If DdlSubProyectoDatos.SelectedValue.ToEntero > 0 Then + Dim Dr As DataRow = GlobalDTSubProyectos(-1, DdlSubProyectoDatos.SelectedValue.ToEntero, UsuarioActual.CveEmpresa).Rows(0) + If Dr IsNot Nothing Then + If Dr("CvePrecioLista").ToString.ToEntero > 0 Then + CvePreioLista = Dr("CvePrecioLista").ToString.ToEntero + End If + End If End If Dim ObjCliente As New ClsClientes @@ -16925,16 +17017,16 @@ Partial Class Ventas End Sub - Private Sub RecargaGlobalCliente() - Dim Hilo As New System.Threading.Thread(AddressOf GeneraGlobalDTCliente) - Hilo.Start() - End Sub - Private Sub GeneraGlobalDTCliente() - Dim Objclientes As New ClsClientes - If Objclientes.GetClientes(-1, "-1", "-1", "-1", "-1", "-1", "-1", -1, -1, Estatus:=-1,TipoCliente:=-1) Then - Application("GlobalDTCliente") = Objclientes.DtResultados - End If - Objclientes.Dispose() + Private Sub RecargaGlobalCliente() + Dim Hilo As New System.Threading.Thread(AddressOf GeneraGlobalDTCliente) + Hilo.Start() + End Sub + Private Sub GeneraGlobalDTCliente() + Dim Objclientes As New ClsClientes + If Objclientes.GetClientes(-1, "-1", "-1", "-1", "-1", "-1", "-1", -1, -1, Estatus:=-1, TipoCliente:=-1) Then + Application("GlobalDTCliente") = Objclientes.DtResultados + End If + Objclientes.Dispose() End Sub #End Region @@ -20504,6 +20596,16 @@ Partial Class Ventas ObjMovtos.Dispose() GvRemisionesNC.DataBind() End Sub + Private Sub CargaDescRNC() + Dim ObjMovtos As New ClsMovimientos() + If ObjMovtos.GetCxCClienteDetalle(ViewState("CveCliente").ToString.ToEntero, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa, -1, TipoDocto:="RNC") Then + GvDescNC.DataSource = ObjMovtos.DtResultados.FiltraParametros("Tipo = 'Act' AND CveVenta > 0", "Moneda, OrdenVencimiento, FechaVencimiento") + End If + ObjMovtos.Dispose() + GvDescNC.DataBind() + + UpDescNC.Update() + End Sub Protected Sub GvCxC_RowDataBound(sender As Object, e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then @@ -20540,8 +20642,13 @@ Partial Class Ventas End If End If + AplicarNC(DdlNCPS.SelectedValue.ToEntero) - Dim DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlNCPS.SelectedValue.ToEntero).FiltroPrimero("") + RegistraScript("$('#ModalAplicarNC').modal('hide');", "EscondeModalNC") + End Sub + + Private Sub AplicarNC(CvePS As Integer, Optional NCDescuento As Boolean = False) + Dim DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimero("") If DrPS Is Nothing Then Alert("Ocurrió un error al cargar la información del producto. Por favor comuniquese con asistencia SIG", TipoMensaje.MsgError) Exit Sub @@ -20556,11 +20663,6 @@ Partial Class Ventas Exit Sub End If End If - - If DdlTipoComprobante.SelectedValue = "Ant" Then CveAnticipo = CveVenta - - DdlTipoComprobante.SelectedValueExist("Egs") - 'CREAMOS DT PARA UTILIZAR AL TIMBRAR InicializaDTVentasNC() @@ -20579,13 +20681,21 @@ Partial Class Ventas DtImpuestos.AcceptChanges() If AplicaNCMasiva Then - For Each Gvr As GridViewRow In GvCxC.Rows - If Gvr.FCCheckBox("ChkCxC").Checked Then - DtImpuestos.Merge(CargaDtImpuestosNC(Gvr.DataKey("CveVenta").ToString.ToEntero, Gvr.FCTextBox("TxtImporte").Text.ToString.ToDecimal), True, MissingSchemaAction.Ignore) - 'CARGA FACTURA A LA CUAL SE APLICA LA NC - CargaNCDT(Gvr.DataKey("CveVenta").ToString.ToEntero, Gvr.FCTextBox("TxtImporte").Text.ToString.ToDecimal) - End If - Next + If NCDescuento Then + For Each Gvr As GridViewRow In GvDescNC.Rows + If Gvr.FCCheckBox("ChkAplicar").Checked Then + DtImpuestos.Merge(CargaDtImpuestosNC(Gvr.DataKey("CveVenta").ToString.ToEntero, Gvr.FCTextBox("TxtImporte").Text.ToString.ToDecimal), True, MissingSchemaAction.Ignore) + End If + Next + Else + For Each Gvr As GridViewRow In GvCxC.Rows + If Gvr.FCCheckBox("ChkCxC").Checked Then + DtImpuestos.Merge(CargaDtImpuestosNC(Gvr.DataKey("CveVenta").ToString.ToEntero, Gvr.FCTextBox("TxtImporte").Text.ToString.ToDecimal), True, MissingSchemaAction.Ignore) + 'CARGA FACTURA A LA CUAL SE APLICA LA NC + CargaNCDT(Gvr.DataKey("CveVenta").ToString.ToEntero, Gvr.FCTextBox("TxtImporte").Text.ToString.ToDecimal) + End If + Next + End If Else DtImpuestos = CargaDtImpuestosNC(CveVenta, TxtNCImporte.Text.Trim.ToDecimal) End If @@ -20613,53 +20723,58 @@ Partial Class Ventas Exit Sub End If - DtImpuestos = query.QueryToDataTable(False) - LimpiaDocumentoNC() + If Not NCDescuento Then + LimpiaDocumentoNC() + End If Dim CveSubProyecto = DrSubProyecto("CveSubProyecto").ToString.ToEntero Dim SubProyecto = DrSubProyecto("SubProyecto").ToString Dim CveProyecto = DrSubProyecto("CveProyecto").ToString.ToEntero Dim Proyecto = DrSubProyecto("Proyecto").ToString - For Each Dr As DataRow In DtImpuestos.Rows - AgregaTempDT(DrPS("CvePS").ToString.ToEntero, DrPS("PS").ToString, DrPS("Codigo").ToString, DrPS("PSCodigo").ToString, DrPS("CveTipoPS").ToString.ToEntero, DrPS("Inv_CveMetodoInventario").ToString.ToEntero, - DrPS("CveUM").ToString.ToEntero, DrPS("UnidadMedida").ToString, DrPS("CveClasificacion").ToString.ToEntero, DrPS("Clasificacion").ToString, CveProyecto, Proyecto, CveSubProyecto, SubProyecto, - TxtNCObservaciones.Text.Trim, 1, Dr("ImportePU").ToString.ToDecimal, Dr("PorcentajeIVA").ToString.ToDecimal, Dr("ImporteIVA").ToString.ToDecimal, Dr("PorcentajeRetIVA").ToString.ToDecimal, Dr("ImporteRetIVA").ToString.ToDecimal, - Dr("PorcentajeRetISR").ToString.ToDecimal, Dr("ImporteRetISR").ToString.ToDecimal, Dr("PorcentajeIEPS").ToString.ToDecimal, Dr("ImporteIEPS").ToString.ToDecimal, -1, 0.0, Dr("ImporteTotal").ToString.ToDecimal, "", "", -1, -1, - DrPS("SATClavePS").ToString, DrPS("SATClaveUnidadMedida").ToString, -1, -1, -1, -1, -1, -1) - Next - - TrTipoRelacion.Visible = True - DdlTiposRelacion.SelectedValueExist("1") - - GvPS.DataSource = TmpDT - GvPS.DataBind() - - CalculaTotalesVenta(True) - - - - 'condicióon, en la que se verifica que el importe total de aplicación de la nota de crédito sea igual al del total de la nota de crédito, ej. saldo de la factura 1000.01 y la nota de crédito se generó po 1000.00 - If Not AplicaNCMasiva Then - Dim TT As Decimal = TxtNCImporte.Text.ToDecimal - If TT > TxtTotal.Text.ToDecimal Then TT = TxtTotal.Text.ToDecimal - CargaNCDT(CveVenta, TT) - - End If - 'verifica el tipo de cambio que se actualice - If DdlMoneda.SelectedValue <> "1" Then - TxtTipoCambio.Text = GlobalTipoCambio(Now).ToString - End If - LblTCValuacion.Visible = False - UpPS.Update() - - LBNotaCredito.Visible = False - RegistraScript("$('#ModalAplicarNC').modal('hide');", "EscondeModalNC") AplicaNC = True - CambiaTipoDocto() + If Not NCDescuento Then + + If DdlTipoComprobante.SelectedValue = "Ant" Then CveAnticipo = CveVenta + + DdlTipoComprobante.SelectedValueExist("Egs") + + For Each Dr As DataRow In DtImpuestos.Rows + AgregaTempDT(DrPS("CvePS").ToString.ToEntero, DrPS("PS").ToString, DrPS("Codigo").ToString, DrPS("PSCodigo").ToString, DrPS("CveTipoPS").ToString.ToEntero, DrPS("Inv_CveMetodoInventario").ToString.ToEntero, + DrPS("CveUM").ToString.ToEntero, DrPS("UnidadMedida").ToString, DrPS("CveClasificacion").ToString.ToEntero, DrPS("Clasificacion").ToString, CveProyecto, Proyecto, CveSubProyecto, SubProyecto, + TxtNCObservaciones.Text.Trim, 1, Dr("ImportePU").ToString.ToDecimal, Dr("PorcentajeIVA").ToString.ToDecimal, Dr("ImporteIVA").ToString.ToDecimal, Dr("PorcentajeRetIVA").ToString.ToDecimal, Dr("ImporteRetIVA").ToString.ToDecimal, + Dr("PorcentajeRetISR").ToString.ToDecimal, Dr("ImporteRetISR").ToString.ToDecimal, Dr("PorcentajeIEPS").ToString.ToDecimal, Dr("ImporteIEPS").ToString.ToDecimal, -1, 0.0, Dr("ImporteTotal").ToString.ToDecimal, "", "", -1, -1, + DrPS("SATClavePS").ToString, DrPS("SATClaveUnidadMedida").ToString, -1, -1, -1, -1, -1, -1) + Next + + GvPS.DataSource = TmpDT + GvPS.DataBind() + + CalculaTotalesVenta(True) + + TrTipoRelacion.Visible = True + DdlTiposRelacion.SelectedValueExist("1") + + 'condicióon, en la que se verifica que el importe total de aplicación de la nota de crédito sea igual al del total de la nota de crédito, ej. saldo de la factura 1000.01 y la nota de crédito se generó po 1000.00 + If Not AplicaNCMasiva Then + Dim TT As Decimal = TxtNCImporte.Text.ToDecimal + If TT > TxtTotal.Text.ToDecimal Then TT = TxtTotal.Text.ToDecimal + CargaNCDT(CveVenta, TT) + End If + 'verifica el tipo de cambio que se actualice + If DdlMoneda.SelectedValue <> "1" Then + TxtTipoCambio.Text = GlobalTipoCambio(Now).ToString + End If + LblTCValuacion.Visible = False + UpPS.Update() + + LBNotaCredito.Visible = False + CambiaTipoDocto() + + End If End Sub @@ -20684,8 +20799,6 @@ Partial Class Ventas Else Total = TxtTotal.Text.ToDecimal SubTotal = TxtSubTotal.Text.ToDecimal - - End If ObjVentas.Dispose() @@ -22061,7 +22174,10 @@ Partial Class Ventas Protected Sub BtnGuardarRemisiones_Click(sender As Object, e As EventArgs) Handles BtnGuardarRemisiones.Click If GvRem.Rows.Count > 0 Or GvRemPS.Rows.Count > 0 Then 'Checa las facturas selecionadas - VerificaRemisiones(DTRemisiones) + If Not VerificaRemisiones(DTRemisiones) Then + Alert("La cantidad/total debe ser mayor que 0", TipoMensaje.MsgAdvertencia) + Exit Sub + End If Dim dtSeleccionadas As DataTable = DTRemisiones.FiltraParametros("Aplicado = True") Dim CveContrato = DTRemisiones.FiltroPrimeroValor("CveContrato", "Aplicado = True").ToEntero @@ -22231,19 +22347,30 @@ Partial Class Ventas RegistraScript("$('#DivRemisiones').modal('hide');", "DivRemisionesHide") End Sub - Private Sub VerificaRemisiones(ByRef dt As DataTable) + Private Function VerificaRemisiones(ByRef dt As DataTable) As Boolean + Dim Valido As Boolean = True If ChkRemProductos.Checked Then - For Each Gvr As GridViewRow In GvRemPS.Rows - If Gvr.RowType = DataControlRowType.DataRow Then - Dim ChkAplicar As CheckBox = Gvr.FCCheckBox("Chk") - Dim CveVentaDetalle As Integer = Gvr.DataKey("CveVentaDetalle").ToEntero - Dim Drs As DataRow() = dt.Select($"CveVentaDetalle = {CveVentaDetalle}") - If Drs.Count > 0 Then - Drs(0)("Aplicado") = ChkAplicar.Checked + + Valido = Not (From GvRow In GvRemPS.Rows.Cast(Of GridViewRow) + Let Cantidad = GvRow.FCTextBox("TxtCantidadRem").Text.Trim().ToEntero(), Aplicar = GvRow.FCCheckBox("Chk").Checked + Where GvRow.RowType = DataControlRowType.DataRow AndAlso Cantidad <= 0 AndAlso Aplicar + Select GvRow + ).Any + + If Valido Then + For Each Gvr As GridViewRow In GvRemPS.Rows + If Gvr.RowType = DataControlRowType.DataRow Then + Dim ChkAplicar As CheckBox = Gvr.FCCheckBox("Chk") + Dim CveVentaDetalle As Integer = Gvr.DataKey("CveVentaDetalle").ToEntero + Dim Drs As DataRow() = dt.Select($"CveVentaDetalle = {CveVentaDetalle}") + If Drs.Count > 0 Then + Drs(0)("Aplicado") = ChkAplicar.Checked + End If + dt.AcceptChanges() End If - dt.AcceptChanges() - End If - Next + Next + End If + Else For Each Gvr As GridViewRow In GvRem.Rows If Gvr.RowType = DataControlRowType.DataRow Then @@ -22257,7 +22384,9 @@ Partial Class Ventas End If Next End If - End Sub + + Return Valido + End Function Private Sub CargaConceptosRemisionPorFacturar(CveRemisiones As String, TipoCargas As Integer) Dim ObjClientes As New ClsClientes If ObjClientes.GetVentasRemisionesTotales(CveCliente, CveRemisiones, TipoCargas) Then @@ -22877,7 +23006,7 @@ Partial Class Ventas CambiaTipoDocto() CambiaSucursalGeneral() CargaAnticipos(CveCliente) - CargaRestriccionesCreditoCliente() + CargaRestriccionesCreditoCliente(CveVenta:=-1) UpParametros.Update() End Sub @@ -23274,4 +23403,158 @@ Partial Class Ventas RegistraScript("CerrarModalRemNC();") End Sub + Protected Sub LnkDescuentosRNC_Click(sender As Object, e As EventArgs) + CargaDescRNC() + RegistraScript("$('#ModalAplicarDescuentoNC').modal('show'); ") + End Sub + Protected Sub BtnAplicarDesc_Click(sender As Object, e As EventArgs) + Dim CveSATNC = "84111506" + Dim DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, SATClavePS:=CveSATNC, AplicaParaVenta:=1).Rows(0) + + If DrPS Is Nothing Then + Alert("Ocurrió un error al cargar la información del Producto. Por favor vuelva a intentar.", TipoMensaje.MsgError) + Exit Sub + End If + + AplicaNCMasiva = True + + If ListaNCDesc Is Nothing Then + ListaNCDesc = New List(Of Modelos.Factura) + Else + ListaNCDesc.Clear() + End If + + Dim TotalRemNCAplicado As Decimal = 0 + For Each GvRow As GridViewRow In GvDescNC.Rows + If GvRow.RowType = DataControlRowType.DataRow Then + If GvRow.FCCheckBox("ChkAplicar").Checked Then + Dim RemNC As New Modelos.Factura(UsuarioActual, GvRow.DataKey("CveVenta").ToEntero(), UsuarioActual.CveEmpresa) + RemNC.TotalRemNCAplicado = GvRow.FCTextBox("TxtImporte").Text.ToDecimal() + TotalRemNCAplicado += RemNC.TotalRemNCAplicado + + If RemNC.TotalRemNCAplicado <= 0 Then + Alert($"Debe asignar un importe en la siguiente remisión: {RemNC.SerieFolio}", TipoMensaje.MsgAdvertencia) + ListaNCDesc.Clear() + Exit Sub + End If + + ListaNCDesc.Add(RemNC) + End If + End If + Next + + LblDescuentosRNC.Text = TotalRemNCAplicado.FormatoNumero + LblTotalNC.Text = (TxtTotal.Text.ToDecimal() - TotalRemNCAplicado).FormatoNumero + + Dim CvePS = DrPS("CvePS").ToString().ToEntero() + + AplicarNC(CvePS, True) + + UpPS.Update() + + RegistraScript("$('#ModalAplicarDescuentoNC').modal('hide'); ") + End Sub + + Protected Function CreaDTDetalleNCDescuento() As DataTable + Dim Dt As DataTable = TmpDT.Clone() + Dt.Rows.Clear() + + Dim CveSATNC = "84111506" + Dim DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, SATClavePS:=CveSATNC, AplicaParaVenta:=1).Rows(0) + + If DrPS Is Nothing Then + Alert("Ocurrió un error al cargar la información del Producto. Por favor vuelva a intentar.", TipoMensaje.MsgError) + Return Dt + End If + Dim CvePS = DrPS("CvePS").ToString().ToEntero() + + Dim TotalCalculableImpuestos As Decimal = 0 + Dim PU = Math.Round(ListaNCDesc.Sum(Function(RNC) RNC.TotalRemNCAplicado), 6) ' el precio unitario puede llevar hasta 6 decimales permitidos + Dim Cantidad As Decimal = 1 + Dim Descuento As Decimal = 0 + + Dim Row As DataRow = Dt.NewRow() + Row("CveProyecto") = DdlProyecto.SelectedValue.ToEntero() + Row("Proyecto") = DdlProyecto.SelectedItem.Text + Row("CveSubProyecto") = DdlSubProyecto.SelectedValue.ToEntero() + Row("SubProyecto") = DdlSubProyecto.SelectedItem.Text + Row("SerieLote") = "-1" + Row("TiempoEntrega") = "" + Row("Orden") = Dt.Rows.Count + 1 + Row("Cantidad") = Cantidad + Row("CveUM") = DrPS("CveUM").ToString().ToEntero() + Row("UM") = "" + Row("CveClasificacion") = DrPS("CveClasificacion").ToString().ToEntero() + Row("Clasificacion") = "" + Row("CvePS") = CvePS + Row("Obs") = "" + + TotalCalculableImpuestos = (Cantidad * (PU)) - Descuento + + Row("PU") = PU + Row("Codigo") = DrPS("Codigo") + Row("NoIdentificacion") = DrPS("Codigo") + Row("ClaveSATFraccionArancelaria") = DrPS("ClaveSATFraccionArancelaria") + Row("ClaveSATUnidadAduana") = DrPS("ClaveSATUnidadAduana") + Row("ClaveSATFraccionArancelariaDescripcion") = DrPS("ClaveSATFraccionArancelariaDescripcion") + Row("ClaveSATUnidadAduanaDescripcion") = DrPS("ClaveSATUnidadAduanaDescripcion") + + If Modalidad = "U" Then + Row("Consec") = Index + Else + Row("Consec") = TmpDT.Rows.Count + 1 + End If + + Row("PS") = DrPS("PS") + Row("CodigoPS") = DrPS("PSCodigo").ToString + Row("CveTipoPS") = DrPS("CveTipoPS") + Row("CveTipoInvPS") = DrPS("Inv_CveMetodoInventario") + Row("CveTamaño") = DrPS("CveTamaño") + Row("CveClasificacion") = DrPS("CveClasificacion") + Row("Clasificacion") = DrPS("Clasificacion") + + If DrPS("IVA").ToString.Contiene("-1", "") Then + Row("PorcentajeIVA") = PorcentajeIVA + Else + Row("PorcentajeIVA") = DrPS("IVA") + End If + + Row("IVA") = Row("PorcentajeIVA") + Row("ImporteIVA") = Math.Round(Row("PorcentajeIVA").ToString.ToDecimal * TotalCalculableImpuestos, NumeroDecimales) + Row("ImporteRetIVA") = Math.Round(ClienteRetIVA * TotalCalculableImpuestos, NumeroDecimales) + Row("ImporteRetISR") = Math.Round(ClienteRetISR * TotalCalculableImpuestos, NumeroDecimales) + Row("PorcentajeRetIVA") = ClienteRetIVA + Row("PorcentajeRetISR") = ClienteRetISR + Row("PorcentajeIEPS") = DrPS("IEPSPorcentaje") + Row("ImporteIEPS") = Math.Round(DrPS("IEPSPorcentaje").ToString.ToDecimal * TotalCalculableImpuestos, NumeroDecimales) + Row("IEPS") = Row("ImporteIEPS") + Row("Descuento") = Math.Round(Descuento, NumeroDecimales) + Row("TipoDescuento") = HdnTipoDescuento.Value + Row("Total") = (Cantidad * PU) + Row("TotalImporte") = Math.Round(Cantidad * PU, NumeroDecimales) + + Row("SATClaveProdServ") = DrPS("SATClavePS") + Row("SATClaveUM") = DrPS("SATClaveUnidadMedida") + + If UsuarioActual.Empresa.UsaAC Then + Row("CvePresupuestoIngreso") = Me.DdlFuenteRecaudacion.SelectedValue + End If + + Row("EntregaDirecta") = -1 + 'Contratos + Row("CveContratoDetalle") = -1 + Row("CveVentaDetalle") = -1 + Row("CveMovimientoDetallePedido") = -1 + Row("CveOrdenCompraDetalle") = -1 + Row("CveVentaDetalleRemision") = -1 + Row("CveVentaDetalleCotizacion") = -1 + Row("CveVentaDetallePedido2") = -1 + Row("CuentaPredial") = "-1" + Row("Consec") = 1 + + 'RECARGAR GV + Dt.Rows.Add(Row) + + Return Dt + End Function End Class \ No newline at end of file