From 64bc05602cf1be2fd2310185bd03e6cc6c349b68 Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Wed, 11 Mar 2020 17:26:01 -0700 Subject: [PATCH 01/14] Impuestos locales al aplicar NC --- Ventas/Ventas.aspx.vb | 57 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index 52b6db6e6..ce903284a 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -9344,7 +9344,7 @@ Partial Class Ventas Dim CveTipoRetencion As Integer = 0 If UsuarioActual.Empresa.Funcionalidad(579) = "1" Then - CveTipoRetencion = DdlTipoRetencion.SelectedValue.ToEntero() + CveTipoRetencion = factura.CveTipoRetencion End If factura.CvePrePoliza = ObjConta.AddPrePolizas("Ventas/GuardarVenta", factura.CvePlantillaPoliza, factura.Total, factura.Total, factura.CveMoneda, factura.Fecha, If(CveEmpresaCRM > 0, LblEmpresaCRM.Text, factura.Cliente.Nombre), factura.CveUsuario, factura.CveEmpresa) @@ -21486,13 +21486,22 @@ Partial Class Ventas End If End If DdlTipoComprobante.SelectedValue = "Egs" + Dim AplicaImpuestosLocales As Boolean = False - AplicarNC(DdlNCPS.SelectedValue.ToEntero, EsNCAmortizacion:=ChkAplicaNCAnticipo.Checked) + Dim ObjCliente As New ClsClientes + If ObjCliente.GetClienteImpuestosLocales(CveCliente) Then + 'se cargan impuestos locales + Dim DtClienteImpuesto As DataTable = ObjCliente.DtResultados.FiltraParametros("Seleccionado = 1", "Orden") + AplicaImpuestosLocales = (DtClienteImpuesto IsNot Nothing AndAlso DtClienteImpuesto.Rows.Count > 0) + End If + ObjCliente.Dispose() + + AplicarNC(DdlNCPS.SelectedValue.ToEntero, EsNCAmortizacion:=ChkAplicaNCAnticipo.Checked, AplicaImpuestosLocales:=AplicaImpuestosLocales) RegistraScript("$('#ModalAplicarNC').modal('hide');", "EscondeModalNC") End Sub - Private Sub AplicarNC(CvePS As Integer, Optional NCDescuento As Boolean = False, Optional EsNCAmortizacion As Boolean = False) + Private Sub AplicarNC(CvePS As Integer, Optional NCDescuento As Boolean = False, Optional EsNCAmortizacion As Boolean = False, Optional AplicaImpuestosLocales As Boolean = True) 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) @@ -21509,6 +21518,12 @@ Partial Class Ventas End If End If + If Not AplicaImpuestosLocales Then + TmpDTImpuestos.Rows.Clear() + GvImpuestosLocales2.DataSource = TmpDTImpuestos + GvImpuestosLocales2.DataBind() + End If + 'CREAMOS DT PARA UTILIZAR AL TIMBRAR InicializaDTVentasNC() @@ -21530,13 +21545,13 @@ Partial Class Ventas If AplicaNCMasiva Then If NCDescuento Then For Each RNC In ListaNCDesc - DtImpuestos.Merge(CargaDtImpuestosNC(RNC.CveVenta, RNC.TotalRemNCAplicado, NCDescuento:=True), True, MissingSchemaAction.Ignore) + DtImpuestos.Merge(CargaDtImpuestosNC(RNC.CveVenta, RNC.TotalRemNCAplicado, NCDescuento:=True, AplicaImpuestosLocales:=AplicaImpuestosLocales), True, MissingSchemaAction.Ignore) 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) + DtImpuestos.Merge(CargaDtImpuestosNC(Gvr.DataKey("CveVenta").ToString.ToEntero, Gvr.FCTextBox("TxtImporte").Text.ToString.ToDecimal, AplicaImpuestosLocales:=AplicaImpuestosLocales), True, MissingSchemaAction.Ignore) 'CARGA FACTURA A LA CUAL SE APLICA LA NC AcumuladoNC += Gvr.FCTextBox("TxtImporte").Text.ToString.ToDecimal CargaNCDT(Gvr.DataKey("CveVenta").ToString.ToEntero, Gvr.FCTextBox("TxtImporte").Text.ToString.ToDecimal) @@ -21544,7 +21559,7 @@ Partial Class Ventas Next End If Else - DtImpuestos = CargaDtImpuestosNC(CveVenta, TxtNCImporte.Text.Trim.ToDecimal) + DtImpuestos = CargaDtImpuestosNC(CveVenta, TxtNCImporte.Text.Trim.ToDecimal, AplicaImpuestosLocales:=AplicaImpuestosLocales) If EsNCAmortizacion Then If DtAnticipoAmortizacion Is Nothing Then @@ -21646,7 +21661,7 @@ Partial Class Ventas GvPS.DataSource = TmpDT GvPS.DataBind() - CalculaTotalesVenta(True) + CalculaTotalesVenta(RecalculaImpuestosLocales:=AplicaImpuestosLocales) TrTipoRelacion.Visible = True DdlTiposRelacion.SelectedValueExist("1") @@ -21671,14 +21686,21 @@ Partial Class Ventas End Sub - Private Function CargaDtImpuestosNC(CveVentaNC As Integer, Importe As Decimal, Optional NCDescuento As Boolean = False) As DataTable + Private Function CargaDtImpuestosNC(CveVentaNC As Integer, Importe As Decimal, Optional NCDescuento As Boolean = False, Optional AplicaImpuestosLocales As Boolean = True) As DataTable Dim Total As Decimal = 0, SubTotal As Decimal = 0, Saldo As Decimal = 0 Dim TmpDT As DataTable = Nothing + Dim TmpDTImpuestos As DataTable = Nothing Dim ObjVentas As New ClsVentas + If ObjVentas.GetVentaImpuestosLocales(CveVentaNC) Then + If ObjVentas.DtResultados.Rows.Count > 0 Then + TmpDTImpuestos = ObjVentas.DtResultados.Copy() + End If + End If + If ObjVentas.GetVentaDetalle(CveVentaNC) Then - TmpDT = ObjVentas.DtResultados + TmpDT = ObjVentas.DtResultados.Copy() TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer)) End If @@ -21708,10 +21730,19 @@ Partial Class Ventas Dim Porcentaje As Decimal = ((Importe * 100) / ImporteReferencia) / 100 Dim FiltroStr As String = "" Dim importePuTemp As Decimal = 0 + Dim TotalImpuestosLocales As Decimal = 0 + If TmpDTImpuestos IsNot Nothing AndAlso TmpDTImpuestos.Rows.Count > 0 Then + TotalImpuestosLocales = TmpDTImpuestos.SUM("Importe").ToDecimal() + End If For Each Dr As DataRow In DtImpuestosLocal.Rows FiltroStr = String.Format("ISNULL(PorcentajeIVA,0) = {0} AND ISNULL(PorcentajeRetIVA,0) = {1} AND ISNULL(PorcentajeRetISR,0) = {2} AND ISNULL(PorcentajeIEPS,0) = {3} AND ISNULL(CveSubProyecto,0) = {4} ", Dr("PorcentajeIVA").ToString.ToDecimal, Dr("PorcentajeRetIVA").ToString.ToDecimal, Dr("PorcentajeRetISR").ToString.ToDecimal, Dr("PorcentajeIEPS").ToString.ToDecimal, Dr("CveSubProyecto")) importePuTemp = (Porcentaje * (TmpDT.SUM("TotalImporte", FiltroStr).ToDecimal() - TmpDT.SUM("Descuento", FiltroStr).ToDecimal())) + + If Not AplicaImpuestosLocales Then + importePuTemp = importePuTemp - TotalImpuestosLocales + End If + Dr("ImporteTotal") = importePuTemp.RoundSQL(2) @@ -21728,9 +21759,13 @@ Partial Class Ventas Dr("ImportePU") = importePuTemp.RoundSQL(6) 'Dr("ImporteTotal").ToString.ToDecimal.RoundSQL(2) '(Dr("ImporteTotal").ToString.ToDecimal - Dr("ImporteIVA").ToString.ToDecimal - Dr("ImporteRetIVA").ToString.ToDecimal - Dr("ImporteRetISR").ToString.ToDecimal - Dr("ImporteIEPS").ToString.ToDecimal) Next - + Dim importeNC = (DtImpuestosLocal.SUMD("ImporteTotal") + DtImpuestosLocal.SUMD("ImporteIVA") + DtImpuestosLocal.SUMD("ImporteIEPS") - DtImpuestosLocal.SUMD("ImporteRetIVA") - DtImpuestosLocal.SUMD("ImporteRetISR")) + If AplicaImpuestosLocales Then + Importe = Importe + TotalImpuestosLocales + End If 'codigo para ajuste de centavo, si el importe total no cuadra con los totales - Dim difTmp As Decimal = Importe - (DtImpuestosLocal.SUMD("ImporteTotal") + DtImpuestosLocal.SUMD("ImporteIVA") + DtImpuestosLocal.SUMD("ImporteIEPS") - DtImpuestosLocal.SUMD("ImporteRetIVA") - DtImpuestosLocal.SUMD("ImporteRetISR")) + Dim difTmp As Decimal = Importe - importeNC + If Math.Abs(difTmp) >= 0.01 Then 'asusto la diferencia en el último concepto Dim ImporteAjustado As Decimal = DtImpuestosLocal.Rows(DtImpuestosLocal.Rows.Count - 1)("ImporteTotal").ToString.ToDecimal + difTmp From ab34ae1d4987b001f8e3947d0309763ed8932f4a Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Thu, 12 Mar 2020 10:22:59 -0700 Subject: [PATCH 02/14] Registrar compras automaticamente --- .gitignore | 2 +- Compras/Compras.aspx.vb | 46 ++++++++++++++++++++++++++++++++++++-- Ventas/RepIngresos.aspx | 4 ++-- Ventas/RepIngresos.aspx.vb | 28 +++++++++++------------ vwd.webinfo | 2 ++ 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index a7b361013..9b5134ac3 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ LogTimbrado.txt *.user *.userosscache *.sln.docstates - +vwd.webinfo # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/Compras/Compras.aspx.vb b/Compras/Compras.aspx.vb index c8104569b..12fc56201 100644 --- a/Compras/Compras.aspx.vb +++ b/Compras/Compras.aspx.vb @@ -1621,11 +1621,21 @@ Partial Class Compras_Compras ' 'End If 'End If - 'RegistraScript("ScrollVentanaAddProducto();") End Sub #Region "C A R G A S" + Private Sub CargaRegistarEntradaAlmacenAutomatico() + 'REGISTRA ENTRADA DE ALMACÉN EN AUTOMÁTICO + If UsuarioActual.Empresa.Funcionalidad(585) = "1" Then + GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True + For Each GvRow As GridViewRow In GvInv.Rows + If GvRow.RowType = DataControlRowType.DataRow Then + GvRow.FCCheckBox("cbInv").Checked = True + End If + Next + End If + End Sub Private Sub CargaOrdenCorte() Dim ObjCGame As New ClsCGame() If ObjCGame.GetOrdenCorte(UsuarioActual.CveEmpresa) Then @@ -3847,6 +3857,34 @@ Partial Class Compras_Compras Protected Sub BtnGuardar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGuardar.Click '------------------INICIA VALIDACIONES------------------ + 'REGISTRA ENTRADA DE ALMACÉN EN AUTOMÁTICO + If UsuarioActual.Empresa.Funcionalidad(585) = "1" Then + + If Not GvInv.HeaderRow.FCCheckBox("cbAll").Checked Then + Alert("Debe seleccionar aplicar el inventario", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToEntero() <= 0 Then + Alert("Debe seleccionar un almacen para el inventario", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + For Each GvRow As GridViewRow In GvInv.Rows + If GvRow.RowType = DataControlRowType.DataRow Then + If Not GvRow.FCCheckBox("cbInv").Checked Then + Alert("Debe seleccionar todos los productos para el inventario", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If GvRow.FCDropDownList("ddlEAlmacen").SelectedValue.ToEntero() <= 0 Then + Alert("Debe seleccionar un almacen para todos los productos para el inventario", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + Next + End If + Dim EstatusCredito As Integer = 0 'Credito Multiple If RBLPago.SelectedValue.ToEntero = 4 Then @@ -11170,6 +11208,8 @@ Partial Class Compras_Compras If ChkConsignacion.Checked Then End If + CargaRegistarEntradaAlmacenAutomatico() + UpINV.Update() End Sub @@ -11222,7 +11262,9 @@ Partial Class Compras_Compras If e.Row.DBCampo("AlmacenRegistrado").ToString = "1" Then e.Row.FCCheckBox("cbInv").Checked = True End If - e.Row.FCCheckBox("cbInv").Enabled = False + e.Row.FCCheckBox("cbInv").Enabled = False + Else + End If 'CONSIGNACIONES diff --git a/Ventas/RepIngresos.aspx b/Ventas/RepIngresos.aspx index 460a9e479..59b888063 100644 --- a/Ventas/RepIngresos.aspx +++ b/Ventas/RepIngresos.aspx @@ -225,8 +225,8 @@ - - + + <%----%>
diff --git a/Ventas/RepIngresos.aspx.vb b/Ventas/RepIngresos.aspx.vb index 9bb39a6f6..467609afe 100644 --- a/Ventas/RepIngresos.aspx.vb +++ b/Ventas/RepIngresos.aspx.vb @@ -94,7 +94,7 @@ Partial Class Ventas_RepIngresos Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then TCEspecifico = -1 - TipoCambio = 1 + TipoCambio = 2 CveSubProyecto = -1 TxtFechaInicio.Text = String.Format("01/01/{0}", Now.Year) DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1) @@ -107,11 +107,11 @@ Partial Class Ventas_RepIngresos Dim Cves_Subprotectos As String = If(DdlSubProyecto.GetSelectedValuesM = "", "-1", DdlSubProyecto.GetSelectedValuesM) Dim TiposDoc As String = If(DdlTipoDocto.GetSelectedValuesM = "", "-1", DdlTipoDocto.GetSelectedValuesM) - If RblTipoCambio.SelectedValue.ToEntero = 3 And TxtEspecifico.Text <> "" Then - TCEspecifico = TxtEspecifico.Text.ToDecimal - Else - TCEspecifico = -1 - End If + 'If RblTipoCambio.SelectedValue.ToEntero = 3 And TxtEspecifico.Text <> "" Then + ' TCEspecifico = TxtEspecifico.Text.ToDecimal + 'Else + ' TCEspecifico = -1 + 'End If Dim ObjRepI As New ClsVentas() If ObjRepI.RepIngresos(UsuarioActual.CveEmpresa, If(RsFechaI = "-1", MinFecha, RsFechaI.ToDate), If(RsFechaF = "-1", MaxFecha, RsFechaF.ToDate), TiposDoc, Cves_Subprotectos, TipoCambio:=TipoCambio, TCEspecifico:=TCEspecifico) Then @@ -174,20 +174,20 @@ Partial Class Ventas_RepIngresos If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("TipoAmortizacion") = "" Then e.Row.CssClass = "Totales" - ElseIf e.Row.DBCampo("TipoAmortizacion") <> "" AndAlso e.Row.DBCampo("CveConceptoContable") = "-1" Then + ElseIf e.Row.DBCampo("TipoAmortizacion") <> "" AndAlso e.Row.DBCampo("CveConceptoContable") = "" Then e.Row.CssClass = "SubTotales" End If End If End Sub Private Sub RblTipoCambio_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RblTipoCambio.SelectedIndexChanged TipoCambio = RblTipoCambio.SelectedValue.ToEntero - If TipoCambio = 3 Then - LiEspecifico.Visible = True - TCEspecifico = GlobalTipoCambio(Now).ToDecimal - TxtEspecifico.Text = TCEspecifico.ToString - Else - LiEspecifico.Visible = False - End If + 'If TipoCambio = 3 Then + ' LiEspecifico.Visible = True + ' TCEspecifico = GlobalTipoCambio(Now).ToDecimal + ' TxtEspecifico.Text = TCEspecifico.ToString + 'Else + ' LiEspecifico.Visible = False + 'End If UpBodyTipoCambio.Update() End Sub Private Sub BtnTipoCambio_Click(sender As Object, e As EventArgs) Handles BtnTipoCambio.Click diff --git a/vwd.webinfo b/vwd.webinfo index bfda47f43..a280964b8 100644 --- a/vwd.webinfo +++ b/vwd.webinfo @@ -23,6 +23,8 @@ + + \ No newline at end of file From 28a8f707411cc6d737d66f9aa7e6cd2756baf143 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Thu, 12 Mar 2020 12:04:46 -0700 Subject: [PATCH 03/14] =?UTF-8?q?imprimiendo=20excel=20en=20compras=20deta?= =?UTF-8?q?lle=20y=20se=20avanz=C3=B3=20en=20el=20reporte=20de=20metas=20v?= =?UTF-8?q?endedores=20NOTA:=20Aun=20faltan=20columnas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Compras/RepComprasDetalle.aspx.vb | 4 ++-- Ventas/MetasVendedores.aspx | 15 +++++++++++++++ Ventas/MetasVendedores.aspx.vb | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Compras/RepComprasDetalle.aspx.vb b/Compras/RepComprasDetalle.aspx.vb index 060289af1..d1c57402a 100644 --- a/Compras/RepComprasDetalle.aspx.vb +++ b/Compras/RepComprasDetalle.aspx.vb @@ -397,8 +397,8 @@ Partial Class Compras_RepComprasDetalle ImprimirPDF(String.Format("{0}Formatos\Remesa.rdlc", UsuarioActual.Empresa.Ruta), DtDatos.FiltraParametros("CveCompra > 0"), params, "Remesa", RDSName:="DsCompras") End Sub Protected Sub LnkExportar_Click(sender As Object, e As EventArgs) Handles LnkExportar.Click - GvDatos.ExportToExcel("ReporteComprasDetalles" & Now.ToShortDateString) - 'GenerarPDF("EXCEL") + 'GvDatos.ExportToExcel("ReporteComprasDetalles" & Now.ToShortDateString) + GenerarPDF("EXCEL") End Sub Protected Sub LnkPdf_Click(sender As Object, e As EventArgs) diff --git a/Ventas/MetasVendedores.aspx b/Ventas/MetasVendedores.aspx index 46c64406e..b22cc2c93 100644 --- a/Ventas/MetasVendedores.aspx +++ b/Ventas/MetasVendedores.aspx @@ -183,6 +183,21 @@ + + + + + + + + + + + + + + + diff --git a/Ventas/MetasVendedores.aspx.vb b/Ventas/MetasVendedores.aspx.vb index e362df89f..fdb6b508a 100644 --- a/Ventas/MetasVendedores.aspx.vb +++ b/Ventas/MetasVendedores.aspx.vb @@ -75,9 +75,21 @@ Partial Class MetasVendedores Protected Sub GV_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GV.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then + e.Row.FCLabel("lblRealMesPorcentaje").Text = String.Format("{0}{1}", e.Row.FCLabel("lblRealMesPorcentaje").Text, "%") + e.Row.FCLabel("lblVarVSAAPerc").Text = String.Format("{0}{1}", e.Row.FCLabel("lblVarVSAAPerc").Text, "%") Select Case e.Row.DataKey("Etiqueta") Case "Vendedor" e.Row.CssClass = "Vendedor" + e.Row.FCLabel("lblRealMes").Text = "" + e.Row.FCLabel("lblVtaMesAA").Text = "" + e.Row.FCLabel("lblObjMes").Text = "" + e.Row.FCLabel("lblRealAcumulado").Text = "" + e.Row.FCLabel("lblRealMesPorcentaje").Text = "" + e.Row.FCLabel("lblAAntAcumulado").Text = "" + e.Row.FCLabel("lblObjAcumulado").Text = "" + e.Row.FCLabel("lblVarVSAAPerc").Text = "" + e.Row.FCLabel("lblVarVSAA").Text = "" + e.Row.FCLabel("lblVarVSObjAcum").Text = "" Case "Categoria" e.Row.CssClass = "Totales" Case "Clasificacion" From f1e240086c30160e4257b3541f21c45be20de600 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Thu, 12 Mar 2020 18:19:26 -0700 Subject: [PATCH 04/14] agregando agrupadores vendedor, sucursal y total --- App_Code/ClsVentas.vb | 4 +++- Ventas/MetasVendedores.aspx | 12 ++++++++++-- Ventas/MetasVendedores.aspx.vb | 6 +++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/App_Code/ClsVentas.vb b/App_Code/ClsVentas.vb index 3a91601be..5c98d9754 100644 --- a/App_Code/ClsVentas.vb +++ b/App_Code/ClsVentas.vb @@ -4359,7 +4359,8 @@ Public Class ClsVentas Return retorno End Function Public Function GetRepMetasVendedores(FechaMesActual As String, CveEmpresa As Integer, CveVendedor As Integer, CveCategoria As Integer, CveClasificacion As Integer, - CveClasificacion2 As Integer, CveMarca As Integer, CveSubProyecto As Integer, CveCliente As Integer) As Boolean + CveClasificacion2 As Integer, CveMarca As Integer, CveSubProyecto As Integer, CveCliente As Integer, + Optional GrupoSuperior As Integer = 0) As Boolean Dim retorno As Boolean = False DataAdapter("PA_Vta_MetasVendedores", CommandType.StoredProcedure) With SqlAdapter.SelectCommand.Parameters @@ -4372,6 +4373,7 @@ Public Class ClsVentas .Add("@CveMarca", SqlDbType.Int).Value = CveMarca .Add("@CveSubProyecto", SqlDbType.Int).Value = CveSubProyecto .Add("@CveCliente", SqlDbType.Int).Value = CveCliente + .Add("@GrupoSuperior", SqlDbType.Int).Value = GrupoSuperior End With Try SqlAdapter.Fill(Data) diff --git a/Ventas/MetasVendedores.aspx b/Ventas/MetasVendedores.aspx index b22cc2c93..b8b459039 100644 --- a/Ventas/MetasVendedores.aspx +++ b/Ventas/MetasVendedores.aspx @@ -37,12 +37,12 @@ padding-right: 4px !important; padding-left: 4px !important; } - .Vendedor{ + .GrupoSuperior{ background-color:#000077; color:white; font-weight:bold; } - .Vendedor:hover{ + .GrupoSuperior:hover{ background-color:#000077; } @@ -121,6 +121,14 @@
+ +
+ + + + + +
diff --git a/Ventas/MetasVendedores.aspx.vb b/Ventas/MetasVendedores.aspx.vb index fdb6b508a..a00223aec 100644 --- a/Ventas/MetasVendedores.aspx.vb +++ b/Ventas/MetasVendedores.aspx.vb @@ -60,7 +60,7 @@ Partial Class MetasVendedores Dim ObjVentas As New ClsVentas If ObjVentas.GetRepMetasVendedores(TxtFechaMes.Text, UsuarioActual.CveEmpresa, DdlVendedorFiltro.SelectedValue.ToEntero, DdlCategoria.SelectedValue.ToEntero, DdlClasificaciones.SelectedValue.ToEntero, DdlClasificacion2.SelectedValue.ToEntero, DdlMarcaFiltro.SelectedValue.ToEntero, - DdlSubProyectoFiltro.SelectedValue.ToEntero, DdlCliente.SelectedValue.ToEntero) Then + DdlSubProyectoFiltro.SelectedValue.ToEntero, DdlCliente.SelectedValue.ToEntero, DdlGrupo.SelectedValue.ToEntero) Then GV.DataSource = ObjVentas.DtResultados DtDatos = ObjVentas.DtResultados End If @@ -78,8 +78,8 @@ Partial Class MetasVendedores e.Row.FCLabel("lblRealMesPorcentaje").Text = String.Format("{0}{1}", e.Row.FCLabel("lblRealMesPorcentaje").Text, "%") e.Row.FCLabel("lblVarVSAAPerc").Text = String.Format("{0}{1}", e.Row.FCLabel("lblVarVSAAPerc").Text, "%") Select Case e.Row.DataKey("Etiqueta") - Case "Vendedor" - e.Row.CssClass = "Vendedor" + Case "GrupoSuperior" + e.Row.CssClass = "GrupoSuperior" e.Row.FCLabel("lblRealMes").Text = "" e.Row.FCLabel("lblVtaMesAA").Text = "" e.Row.FCLabel("lblObjMes").Text = "" From 1b44fd8361adbaf17a60a43134c35ca0fec16735 Mon Sep 17 00:00:00 2001 From: Raul Pimienta Date: Fri, 13 Mar 2020 00:12:37 -0700 Subject: [PATCH 05/14] Se agregaron conceptos contables de acreedores en Compras, ProveedoresAbonar, ReembolsosComprobaciones y PopIECompras --- Bancos/PopIECompras.aspx | 2 +- Bancos/PopIECompras.aspx.vb | 38 +- Bancos/ProveedoresAbonar.aspx | 2 +- Bancos/ProveedoresAbonar.aspx.vb | 52 +- Compras/Compras.aspx | 2 +- Compras/Compras.aspx.vb | 36962 +++++++++++---------- Compras/ReembolsosComprobaciones.aspx | 2 +- Compras/ReembolsosComprobaciones.aspx.vb | 20 +- vwd.webinfo | 2 + 9 files changed, 18651 insertions(+), 18431 deletions(-) diff --git a/Bancos/PopIECompras.aspx b/Bancos/PopIECompras.aspx index 9d8a06644..f2f318896 100644 --- a/Bancos/PopIECompras.aspx +++ b/Bancos/PopIECompras.aspx @@ -210,7 +210,7 @@
- diff --git a/Bancos/PopIECompras.aspx.vb b/Bancos/PopIECompras.aspx.vb index 4a5e80e2b..c27586b07 100644 --- a/Bancos/PopIECompras.aspx.vb +++ b/Bancos/PopIECompras.aspx.vb @@ -48,6 +48,17 @@ Partial Class Bancos_PopIECompras ViewState("CveCompra") = value End Set End Property + + Private Property CveTipoConcepto As Integer + Get + Return ViewState("CveTipoConcepto").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveTipoConcepto") = value + End Set + End Property + + Private Property IdPoliza As Integer Get Return ViewState("IdPoliza").ToString.ToEntero @@ -426,6 +437,7 @@ Partial Class Bancos_PopIECompras CveProveedor = -1 CveCompra = -1 + CveTipoConcepto = 1 IdPoliza = -1 CveMoneda = 0 TipoTransaccion = "Egs" @@ -600,6 +612,7 @@ Partial Class Bancos_PopIECompras HdnCveProveedor.Value = CveProveedor.ToString CargaProveedor(CveProveedor, "-1") CveMoneda = dr("CveMoneda").ToString.ToEntero + CveTipoConcepto = dr("CveTipoConcepto").ToString.ToEntero CveMonedaCompra = dr("CveMoneda").ToString.ToEntero CveMonedaFiltros = dr("CveMoneda").ToString.ToEntero SerieFolio = dr("SerieFolio").ToString @@ -1442,6 +1455,21 @@ Partial Class Bancos_PopIECompras Select Case ConceptoContable Case 17 'Pago Proveedores + + If CveTipoConcepto = 2 Then ConceptoContable = 308 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case ConceptoContable + Case 17 + ConceptoContable = 312 + Case 308 + ConceptoContable = 309 + Case Else + End Select + End If + + Dim CveConceptoContableComplementaria As Integer = 206 + If CveTipoConcepto = 2 Then CveConceptoContableComplementaria = 310 'cuando es acreedor + If RBLContado.SelectedValue.Contiene("3", "4", "5", "6") Then For Each rw As GridViewRow In GvIngresos.Rows If rw.FCCheckBox("Chk").Checked Then @@ -1483,7 +1511,7 @@ Partial Class Bancos_PopIECompras IdCtaContable = IdCtaContComplementaria CveCuenta = CveCuentaComplementaria If ImporteMovimiento <> 0 AndAlso (IdCtaContable > 0 Or UsuarioActual.CveEmpresa = 119) Then - If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, 206, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, CveConceptoContableComplementaria, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then MsgError = "No se pudo insertar la póliza" End If End If @@ -1534,7 +1562,7 @@ Partial Class Bancos_PopIECompras IdCtaContable = IdCtaContComplementaria CveCuenta = CveCuentaComplementaria If ImporteMovimiento <> 0 AndAlso (IdCtaContable > 0 Or UsuarioActual.CveEmpresa = 119) Then - If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, 206, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, CveConceptoContableComplementaria, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then MsgError = "No se pudo insertar la póliza" End If End If @@ -1584,7 +1612,7 @@ Partial Class Bancos_PopIECompras IdCtaContable = IdCtaContComplementaria CveCuenta = CveCuentaComplementaria If ImporteMovimiento <> 0 AndAlso (IdCtaContable > 0 Or UsuarioActual.CveEmpresa = 119) Then - If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, 206, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, CveConceptoContableComplementaria, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then MsgError = "No se pudo insertar la póliza" End If End If @@ -1633,7 +1661,7 @@ Partial Class Bancos_PopIECompras IdCtaContable = IdCtaContComplementaria CveCuenta = CveCuentaComplementaria If ImporteMovimiento <> 0 AndAlso (IdCtaContable > 0 Or UsuarioActual.CveEmpresa = 119) Then - If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, 206, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, rw.DataKey("CveVenta").ToEntero, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, CveConceptoContableComplementaria, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, rw.DataKey("CveVenta").ToEntero, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then MsgError = "No se pudo insertar la póliza" End If End If @@ -1671,7 +1699,7 @@ Partial Class Bancos_PopIECompras IdCtaContable = IdCtaContComplementaria CveCuenta = CveCuentaComplementaria If ImporteMovimiento <> 0 AndAlso (IdCtaContable > 0 Or UsuarioActual.CveEmpresa = 119) Then - If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, 206, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, CveConceptoContableComplementaria, ConceptoMovimiento, Fecha, IdCtaContable, -1, CveIE, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor2, CvePersonal:=CvePersonal, ImporteMX:=ImporteMovimiento * tipoCambioCompra - ImporteMovimiento, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompra, CveCuenta:=CveCuenta) Then MsgError = "No se pudo insertar la póliza" End If ImporteMX = ImporteMovimiento diff --git a/Bancos/ProveedoresAbonar.aspx b/Bancos/ProveedoresAbonar.aspx index 23de03c5a..3ddb46e81 100644 --- a/Bancos/ProveedoresAbonar.aspx +++ b/Bancos/ProveedoresAbonar.aspx @@ -358,7 +358,7 @@ diff --git a/Bancos/ProveedoresAbonar.aspx.vb b/Bancos/ProveedoresAbonar.aspx.vb index bf0ac93bf..de9e37d1e 100644 --- a/Bancos/ProveedoresAbonar.aspx.vb +++ b/Bancos/ProveedoresAbonar.aspx.vb @@ -939,6 +939,18 @@ Partial Class Bancos_ProveedoresAbonar Select Case ConceptoContable Case 17 'Pago Proveedores + + If gvr.DataKey("CveTipoConcepto").ToEntero = 2 Then ConceptoContable = 308 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case ConceptoContable + Case 17 + ConceptoContable = 312 + Case 308 + ConceptoContable = 309 + Case Else + End Select + End If + If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal importeMX = ImporteMovimiento @@ -961,12 +973,15 @@ Partial Class Bancos_ProveedoresAbonar IdCtaContable = CtaProveedor CveCuenta = CveCuentaProveedor Else + Dim CveConceptoComplementaria As Integer = 206 + If gvr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoComplementaria = 310 + ConceptoMovimiento += $" TC:{tipoCambioCompra} ${ImporteMovimiento.FormatoNumero(2)}" IdCtaContable = IdCtaContComplementaria CveCuenta = CveCuentaProveedorExtranjera If ImporteMovimiento <> 0 AndAlso (UsuarioActual.CveEmpresa = 119 Or IdCtaContable > 0) Then 'Cuando tiene complementaria lo dividimos en dos importeMX = ImporteMovimiento - If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0.00D, Referencia, 206, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=Math.Round(ImporteMovimiento * tipoCambioCompraValuacion - ImporteMovimiento, 2, MidpointRounding.AwayFromZero), ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompraValuacion, CveCuenta:=CveCuentaComplementaria) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0.00D, Referencia, CveConceptoComplementaria, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=Math.Round(ImporteMovimiento * tipoCambioCompraValuacion - ImporteMovimiento, 2, MidpointRounding.AwayFromZero), ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompraValuacion, CveCuenta:=CveCuentaComplementaria) Then MsgError = "No se pudo insertar la póliza" End If End If @@ -2072,7 +2087,18 @@ Partial Class Bancos_ProveedoresAbonar 'Saco el porcentaje de pago If gvr.DataKey("Original").ToDouble > 0 Then PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal / gvr.DataKey("Original").ToDecimal Else PorcentajePago = 1 - If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, gvr.FCTextBox("TxtAbonar").Text.ToDecimal, TxtObservaciones.Text, 17, "", Now, 0, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=gvr.FCTextBox("TxtAbonar").Text.ToDecimal) Then + Dim CveConceptoContablePago As Integer = 17 + If gvr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoContablePago = 308 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case CveConceptoContablePago + Case 17 + CveConceptoContablePago = 312 + Case 308 + CveConceptoContablePago = 309 + Case Else + End Select + End If + If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, gvr.FCTextBox("TxtAbonar").Text.ToDecimal, TxtObservaciones.Text, CveConceptoContablePago, "", Now, 0, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=gvr.FCTextBox("TxtAbonar").Text.ToDecimal) Then MsgError = "Detalle" Exit For Else @@ -2879,8 +2905,22 @@ Partial Class Bancos_ProveedoresAbonar Dim TCCompra As Decimal = gr.DataKey("TipoCambio").ToDecimal Dim TCPago As Decimal = GlobalTipoCambio(TxtFechaIncobrable.Text.ToDate).ToDecimal Dim CveMoneda As Integer = gr.DataKey("CveMoneda").ToEntero - Dim FechaCompra As Date = gr.DataKey("Fecha").ToDate + Dim FechaCompra As Date = gr.DataKey("Fecha").ToDate + + Dim CveConceptoContablePago As Integer = 17 + If gr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoContablePago = 308 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case CveConceptoContablePago + Case 17 + CveConceptoContablePago = 312 + Case 308 + CveConceptoContablePago = 309 + Case Else + End Select + End If + Dim CveConceptoContableComplementaria As Integer = 206 + If gr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoContableComplementaria = 310 'cuando es acreedor Dim ConceptoPartida As String = String.Format("Saldar compra {0}", gr.DataKey("SerieFolio").ToString) CvePrePoliza = ObjConta.AddPrePolizas("Bancos/ProveedoresAbonar/Saldar", 98, gr.DataKey("Saldo").ToDecimal, gr.DataKey("Saldo").ToDecimal, gr.DataKey("CveMoneda").ToEntero, TxtFechaIncobrable.Text.ToDate, ConceptoPartida, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) @@ -2888,13 +2928,13 @@ Partial Class Bancos_ProveedoresAbonar If CveMoneda > 1 AndAlso (IdCtaContComplementaria > 0 Or UsuarioActual.CveEmpresa = 119) Then IdCtaContable = IdCtaContComplementaria CveCuenta = CveCuentaProveedorExtranjera - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, 0.00D, gr.DataKey("SerieFolio").ToString, 206, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=Math.Round(Saldo * TCCompra - Saldo, 2, MidpointRounding.AwayFromZero), ImporteME:=Saldo, TipoCambio:=TCCompra, CveCuenta:=CveCuentaComplementaria) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, 0.00D, gr.DataKey("SerieFolio").ToString, CveConceptoContableComplementaria, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=Math.Round(Saldo * TCCompra - Saldo, 2, MidpointRounding.AwayFromZero), ImporteME:=Saldo, TipoCambio:=TCCompra, CveCuenta:=CveCuentaComplementaria) Then MsgError = "No se pudo insertar la póliza" End If IdCtaContable = IdCtaProveedorExtranjera CveCuenta = CveCuentaProveedorExtranjera - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Saldo, gr.DataKey("SerieFolio").ToString, 17, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=Saldo, ImporteME:=If(CveMoneda > 1, Saldo, 0), TipoCambio:=TCCompra, CveCuenta:=CveCuenta) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Saldo, gr.DataKey("SerieFolio").ToString, CveConceptoContablePago, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=Saldo, ImporteME:=If(CveMoneda > 1, Saldo, 0), TipoCambio:=TCCompra, CveCuenta:=CveCuenta) Then MsgError = "Ocurrio un error al saldar el movimiento" End If Else @@ -2902,7 +2942,7 @@ Partial Class Bancos_ProveedoresAbonar IdCtaContable = IdCtaProveedorExtranjera CveCuenta = CveCuentaProveedorExtranjera End If - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Saldo, gr.DataKey("SerieFolio").ToString, 17, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=If(CveMoneda = 1, Saldo, Saldo * TCCompra), ImporteME:=If(CveMoneda > 1, Saldo, 0), TipoCambio:=TCCompra, CveCuenta:=CveCuenta) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Saldo, gr.DataKey("SerieFolio").ToString, CveConceptoContablePago, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=If(CveMoneda = 1, Saldo, Saldo * TCCompra), ImporteME:=If(CveMoneda > 1, Saldo, 0), TipoCambio:=TCCompra, CveCuenta:=CveCuenta) Then MsgError = "Ocurrio un error al saldar el movimiento" End If End If diff --git a/Compras/Compras.aspx b/Compras/Compras.aspx index 6e0b5e8f0..0ea14cbaa 100644 --- a/Compras/Compras.aspx +++ b/Compras/Compras.aspx @@ -4692,7 +4692,7 @@
- + diff --git a/Compras/Compras.aspx.vb b/Compras/Compras.aspx.vb index c8104569b..e4e1045a8 100644 --- a/Compras/Compras.aspx.vb +++ b/Compras/Compras.aspx.vb @@ -1,1614 +1,1614 @@ -Option Explicit On -Option Strict On - -Imports Extensiones -Imports System.Data -Imports System.Xml -Imports System.Globalization -Imports System.Linq -Imports System -Imports System.IO -Imports ADServerControl -Imports System.Threading.Tasks +Option Explicit On +Option Strict On + +Imports Extensiones +Imports System.Data +Imports System.Xml +Imports System.Globalization +Imports System.Linq +Imports System +Imports System.IO +Imports ADServerControl +Imports System.Threading.Tasks Imports System.Diagnostics -Partial Class Compras_Compras +Partial Class Compras_Compras Inherits ClsPaginas -#Region "Propiedades" +#Region "Propiedades" 'Local - Private Property RequiereEvaluacion() As Boolean - Get - Return If(IsNothing(ViewState("RequiereEvaluacion")), False, CBool(ViewState("RequiereEvaluacion"))) - End Get - Set - ViewState("RequiereEvaluacion") = Value - End Set - End Property - - Private Property CveUsuarioEvaluador() As Integer - Get - Return If(IsNothing(ViewState("CveUsuarioEvaluador")), -1, CInt(ViewState("CveUsuarioEvaluador"))) - End Get - Set - ViewState("CveUsuarioEvaluador") = Value - End Set - End Property - Private Property TmpDT As DataTable - Get - Return CType(ViewState("TmpDT"), DataTable) - End Get - Set(value As DataTable) - ViewState("TmpDT") = value - End Set - End Property - Private Property TmpDTOriginal As DataTable - Get - Return CType(ViewState("TmpDTOriginal"), DataTable) - End Get - Set(value As DataTable) - ViewState("TmpDTOriginal") = value - End Set - End Property - Private Property TmpCXP As DataTable - Get - Return CType(ViewState("TmpCXP"), DataTable) - End Get - Set(value As DataTable) - ViewState("TmpCXP") = value - End Set - End Property - - 'Private Property PSDTRemplazo As DataTable - ' Get - ' Return CType(ViewState("PSDTRemplazo"), DataTable) - ' End Get - ' Set(value As DataTable) - ' ViewState("PSDTRemplazo") = value - ' End Set - 'End Property - Private Property DtCheques As DataTable - Get - Return CType(ViewState("DtCheques"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtCheques") = value - End Set - End Property - - Private Property Modalidad As String - Get - Return ViewState("Modalidad").ToString - End Get - Set(value As String) - ViewState("Modalidad") = value - End Set - End Property - - Public Property IdVale As List(Of Integer) - Get - IdVale = DirectCast(ViewState("IdVale"), List(Of Integer)) - End Get - - Set(ByVal value As List(Of Integer)) - ViewState("IdVale") = value - End Set - End Property - Public Property ListaDocumentos As List(Of String) - Get - ListaDocumentos = DirectCast(ViewState("ListaDocumentos"), List(Of String)) - End Get - Set(ByVal value As List(Of String)) - ViewState("ListaDocumentos") = value - End Set + Private Property RequiereEvaluacion() As Boolean + Get + Return If(IsNothing(ViewState("RequiereEvaluacion")), False, CBool(ViewState("RequiereEvaluacion"))) + End Get + Set + ViewState("RequiereEvaluacion") = Value + End Set End Property - Public Property TieneAnticiposXML As Boolean - Get - TieneAnticiposXML = DirectCast(ViewState("TieneAnticiposXML"), Boolean) - End Get - Set(ByVal value As Boolean) - ViewState("TieneAnticiposXML") = value - End Set - End Property - - Private Property DTOCTemp As DataTable - Get - Return CType(ViewState("DTOCTemp"), DataTable) - End Get - Set(value As DataTable) - ViewState("DTOCTemp") = value - End Set - End Property - Private Property DTOCGV As DataTable - Get - Return CType(ViewState("DTOCGV"), DataTable) - End Get - Set(value As DataTable) - ViewState("DTOCGV") = value - End Set - End Property - Private Property DtConsignaciones As DataTable - Get - Return CType(ViewState("DtConsignaciones"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtConsignaciones") = value - End Set - End Property - - 'Private Property DtCuentas As DataTable - ' Get - ' Return CType(ViewState("DtCuentas"), DataTable) - ' End Get - ' Set(value As DataTable) - ' ViewState("DtCuentas") = value - ' End Set - 'End Property - 'Private Property CargoFactura As Boolean - ' Get - ' Return CType(ViewState("CargoFactura"), Boolean) - ' End Get - ' Set(value As Boolean) - ' ViewState("CargoFactura") = value - ' End Set - 'End Property - Private Property tDTAcarreos As DataTable - Get - Return If(IsNothing(ViewState("tDTAcarreos")), Nothing, CType(ViewState("tDTAcarreos"), DataTable)) - End Get - Set(value As DataTable) - ViewState("tDTAcarreos") = value - End Set - End Property - Private Property DtDeudores As DataTable - Get - Return CType(ViewState("DtDeudores"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtDeudores") = value - End Set - End Property - Private Property DtDeudoresDetalle As DataTable - Get - Return CType(ViewState("DtDeudoresDetalle"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtDeudoresDetalle") = value - End Set - End Property - Private Property DtAcreedores As DataTable - Get - Return CType(ViewState("DtAcreedores"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtAcreedores") = value - End Set - End Property - Private Property DTUM As DataTable - Get - Return CType(ViewState("DTUM"), DataTable) - End Get - Set(value As DataTable) - ViewState("DTUM") = value - End Set - End Property - Private Property TmpDTTiposAF As DataTable - Get - Return CType(ViewState("TmpDTTiposAF"), DataTable) - End Get - Set(value As DataTable) - ViewState("TmpDTTiposAF") = value - End Set - End Property - Private Property DtFacturas As DataTable - Get - Return CType(ViewState("DtFacturas"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtFacturas") = value - End Set - End Property - - Private Property DtServicios As DataTable - Get - Return CType(ViewState("DtServicios"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtServicios") = value - End Set - End Property - Private ReadOnly Property CveProveedor As Integer - Get - Return ViewState("CveProveedor").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveTipoProveedor As Integer - Get - Return ViewState("CveTipoProveedor").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CtaProveedor As Integer - Get - Return ViewState("CtaProveedor").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedor As Integer - Get - Return ViewState("CveCuentaProveedor").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CtaProveedorDeudores As Integer - Get - Return ViewState("CtaProveedorDeudores").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedorDeudores As Integer - Get - Return ViewState("CveCuentaProveedorDeudores").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedorAcreedores As Integer - Get - Return ViewState("CveCuentaProveedorAcreedores").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CtaProveedorAcreedores As Integer - Get - Return ViewState("CtaProveedorAcreedores").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CtaProveedorAnticipos As Integer - Get - Return ViewState("CtaProveedorAnticipos").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedorAnticipos As Integer - Get - Return ViewState("CveCuentaProveedorAnticipos").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CtaProveedorAnticiposExtranjera As Integer - Get - Return ViewState("CtaProveedorAnticiposExtranjera").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedorAnticiposExtranjera As Integer - Get - Return ViewState("CveCuentaProveedorAnticiposExtranjera").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CtaProveedorAnticiposComplementaria As Integer - Get - Return ViewState("CtaProveedorAnticiposComplementaria").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedorAnticiposComplementaria As Integer - Get - Return ViewState("CveCuentaProveedorAnticiposComplementaria").ToString.ToEntero - End Get - End Property - - Private ReadOnly Property CtaProveedorRetIVA As Integer - Get - Return ViewState("CtaProveedorRetIVA").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedorRetIVA As Integer - Get - Return ViewState("CveCuentaProveedorRetIVA").ToString.ToEntero - End Get - End Property - - Private ReadOnly Property CtaProveedorRetISR As Integer - Get - Return ViewState("CtaProveedorRetISR").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedorRetISR As Integer - Get - Return ViewState("CveCuentaProveedorRetISR").ToString.ToEntero - End Get - End Property - - Private ReadOnly Property CveCuentaIEPS As Integer - Get - Return ViewState("CveCuentaIEPS").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CtaProveedorExtranjera As Integer - Get - Return ViewState("CtaProveedorExtranjera").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedorExtranjera As Integer - Get - Return ViewState("CveCuentaProveedorExtranjera").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CtaProveedorComplementaria As Integer - Get - Return ViewState("CtaProveedorComplementaria").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveCuentaProveedorComplementaria As Integer - Get - Return ViewState("CveCuentaProveedorComplementaria").ToString.ToEntero - End Get - End Property - Private ReadOnly Property NombreProveedor As String - Get - Return ViewState("NombreProveedor").ToString - End Get - End Property - Private Property IdPoliza As Integer - Get - Return ViewState("IdPoliza").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("IdPoliza") = value - End Set - End Property - Private Property CveOrdenCorte As Integer - Get - Return ViewState("CveOrdenCorte").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveOrdenCorte") = value - End Set - End Property - Private Property CvePrePoliza As Integer - Get - Return ViewState("CvePrePoliza").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CvePrePoliza") = value - End Set - End Property - Private ReadOnly Property CveCompra As Integer - Get - Return ViewState("CveCompra").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CveFactura As Integer - Get - Return ViewState("CveFactura").ToString.ToEntero - End Get - End Property - Private Property CveMovimientoAlmacen As Integer - Get - Return ViewState("CveMovimientoAlmacen").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveMovimientoAlmacen") = value - End Set - End Property - Private Property CveConsignacion As Integer - Get - Return ViewState("CveConsignacion").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveConsignacion") = value - End Set - End Property - Private Property PermisoEdicionManual As Boolean - Get - Return CType(ViewState("PermisoEdicionManual"), Boolean) - End Get - Set(value As Boolean) - ViewState("PermisoEdicionManual") = value - End Set - End Property - - Private Property NuevaValidacionXML As Integer - Get - Return ViewState("NuevaValidacionXML").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("NuevaValidacionXML") = value - End Set - End Property - Private Property IdCuentaBancaria As Integer - Get - Return ViewState("IdCuentaBancaria").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("IdCuentaBancaria") = value - End Set - End Property - Private Property CveCuentaBancaria As Integer - Get - Return ViewState("CveCuentaBancaria").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveCuentaBancaria") = value - End Set - End Property - Private Property IdCuentaBancariaComplementaria As Integer - Get - Return ViewState("IdCuentaBancariaComplementaria").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("IdCuentaBancariaComplementaria") = value - End Set - End Property - Private Property CveCuentaBancariaComplementaria As Integer - Get - Return ViewState("CveCuentaBancariaComplementaria").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveCuentaBancariaComplementaria") = value - End Set - End Property - Private Property IvaAcumulado As Double - Get - Return ViewState("IvaAcumulado").ToString.ToDouble - End Get - Set(value As Double) - ViewState("IvaAcumulado") = value - End Set - End Property - - Private Property EsContado As Boolean - Get - Return CType(ViewState("EsContado"), Boolean) - End Get - Set(value As Boolean) - ViewState("EsContado") = value - End Set - End Property - - 'Private ReadOnly Property CompraFolio As String - ' Get - ' Return ViewState("CompraFolio").ToString - ' End Get - 'End Property - 'Private ReadOnly Property FolioFiscal As String - ' Get - ' Return ViewState("FolioFiscal").ToString - ' End Get - 'End Property - - 'Private ReadOnly Property IdCtaContProveedores As Integer - ' Get - ' Return ViewState("IdCtaContProveedores").ToString.ToEntero - ' End Get - 'End Property - 'Private ReadOnly Property IdCtaContAnticipos As Integer - ' Get - ' Return ViewState("IdCtaContAnticipos").ToString.ToEntero - ' End Get - 'End Property - 'Private ReadOnly Property IdCtaContRetIVA As Integer - ' Get - ' Return ViewState("IdCtaContRetIVA").ToString.ToEntero - ' End Get - 'End Property - 'Private ReadOnly Property IdCtaContRetISR As Integer - ' Get - ' Return ViewState("IdCtaContRetISR").ToString.ToEntero - ' End Get - 'End Property - - 'Private ReadOnly Property IVAPS As Double - ' Get - ' Return ViewState("IVAPS").ToString.ToDouble - ' End Get - 'End Property - 'Private ReadOnly Property RetIVA As Double - ' Get - ' Return ViewState("RetIVA").ToString.ToDouble - ' End Get - 'End Property - 'Private ReadOnly Property RetISR As Double - ' Get - ' Return ViewState("RetISR").ToString.ToDouble - ' End Get - 'End Property - 'Private ReadOnly Property IEPSPS As Double - ' Get - ' Return ViewState("IEPSPS").ToString.ToDouble - ' End Get - 'End Property - 'Private ReadOnly Property IEPSPSIVA As Double - ' Get - ' Return ViewState("IEPSPSIVA").ToString.ToDouble - ' End Get - 'End Property - Private Property TotalGeneral As Double - Get - Return ViewState("TotalGeneral").ToString.ToDouble - End Get - Set(value As Double) - ViewState("TotalGeneral") = value - End Set - End Property - - Private Property CompraSaldo As Double - Get - Return ViewState("CompraSaldo").ToString.ToDouble - End Get - Set(value As Double) - ViewState("CompraSaldo") = value - End Set - End Property - Private Property Saldo As Double - Get - Return ViewState("Saldo").ToString.ToDouble - End Get - Set(value As Double) - ViewState("Saldo") = value - End Set - End Property - - Private Property CveMoneda As Integer - Get - Return ViewState("CveMoneda").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveMoneda") = value - End Set - End Property - Private Property CveAlmacenConsignacion As Integer - Get - Return ViewState("CveAlmacenConsignacion").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveAlmacenConsignacion") = value - End Set - End Property - - Private Property DtFuncionarios As DataTable - Get - Return CType(ViewState("DtFuncionarios"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtFuncionarios") = value - End Set - End Property - - Private Property DtDatosDetalle As DataTable - Get - Return CType(ViewState("DtDatosDetalle"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtDatosDetalle") = value - End Set - End Property - Private Property CvePSSerieLote As Integer - Get - Return CType(ViewState("CvePSSerieLote"), Integer) - End Get - Set(value As Integer) - ViewState("CvePSSerieLote") = value - End Set - End Property - Private Property CveUMSerieLote As Integer - Get - Return CType(ViewState("CveUMSerieLote"), Integer) - End Get - Set(value As Integer) - ViewState("CveUMSerieLote") = value - End Set - End Property - Private Property PUSerieLote As Decimal - Get - Return CType(ViewState("PUSerieLote"), Decimal) - End Get - Set(value As Decimal) - ViewState("PUSerieLote") = value - End Set - End Property - Private Property TotAcarreos As Double - Get - Return CType(ViewState("TotAcarreos"), Double) - End Get - Set(value As Double) - ViewState("TotAcarreos") = value - End Set - End Property - - 'Private ReadOnly Property Ruta As String - ' Get - ' Return AppDomain.CurrentDomain.BaseDirectory & "Empresas\" & UsuarioActual.CveEmpresa & "\" - ' End Get - 'End Property - - - Public Class Anticipos - Public Property TipoMovto As String - Public Property CveIE As Integer - Public Property Importe As Decimal - Public Property TCCompra As Decimal - - Public Property CvePersonal As Integer - Public Property CveCompra As Integer - Public Property CvePrePoliza As Integer - End Class - Private Property ArrAnticipos As ArrayList - Get - Return CType(ViewState("ArrAnticipos"), ArrayList) - End Get - Set(value As ArrayList) - ViewState("ArrAnticipos") = value - End Set - End Property - Private Property ArrIE As ArrayList - Get - Return CType(ViewState("ArrIE"), ArrayList) - End Get - Set(value As ArrayList) - ViewState("ArrIE") = value - End Set - End Property - Private Property ArrIEFuncionariosEmpleados As ArrayList - Get - Return CType(ViewState("ArrIEFuncionariosEmpleados"), ArrayList) - End Get - Set(value As ArrayList) - ViewState("ArrIEFuncionariosEmpleados") = value - End Set - End Property - 'Inventarios - Private Property DtInv As DataTable - Get - Return CType(ViewState("DtInv"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtInv") = value - End Set - End Property - - Private Property DtAC As DataTable - Get - DtAC = DirectCast(ViewState("DtAC"), DataTable) - End Get - - Set(ByVal value As DataTable) - ViewState("DtAC") = value - End Set - End Property - - 'Caja Chica, Funcionario/Empleado - Private ReadOnly Property CveCajaChica As Integer - Get - Return ViewState("CveCajaChica").ToString.ToEntero - End Get - End Property - Private ReadOnly Property CvePersonal As Integer - Get - Return ViewState("CvePersonal").ToString.ToEntero - End Get - End Property - Private Property OCsVinculadas As String - Get - Return ViewState("OCsVinculadas").ToString - End Get - Set(value As String) - ViewState("OCsVinculadas") = value - End Set - End Property - - Private Property DdlOC As DropDownList - Get - Return CType(ViewState("OCsVinculadas"), DropDownList) - End Get - Set(value As DropDownList) - ViewState("OCsVinculadas") = value - End Set - End Property - - Private Property TieneOC As Boolean - Get - Return CType(ViewState("TieneOC"), Boolean) - End Get - Set(value As Boolean) - ViewState("TieneOC") = value - End Set - End Property - Private Property OCVinculada As Boolean - Get - Return CType(ViewState("OCVinculada"), Boolean) - End Get - Set(value As Boolean) - ViewState("OCVinculada") = value - End Set - End Property - Private Property CierrePeriodo As Boolean - Get - Return CType(ViewState("CierrePeriodo"), Boolean) - End Get - Set(value As Boolean) - ViewState("CierrePeriodo") = value - End Set - End Property - Private Property NCDevolucion As Boolean - Get - Return CType(ViewState("NCDevolucion"), Boolean) - End Get - Set(value As Boolean) - ViewState("NCDevolucion") = value - End Set - End Property - Private Property CompraCargada As Boolean - Get - Return CType(ViewState("CompraCargada"), Boolean) - End Get - Set(value As Boolean) - ViewState("CompraCargada") = value - End Set - End Property - Private Property ModalidadUMAlias As Integer - Get - Return ViewState("EjercicioAC").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("EjercicioAC") = value - End Set - End Property - - Private Property CveConceptoContableAlmacen As Integer - Get - Return ViewState("CveConceptoContableAlmacen").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveConceptoContableAlmacen") = value - End Set - End Property - Private Property EsNoDeducible As Boolean - Get - Return CType(ViewState("EsNoDeducible"), Boolean) - End Get - Set(value As Boolean) - ViewState("EsNoDeducible") = value - End Set + Private Property CveUsuarioEvaluador() As Integer + Get + Return If(IsNothing(ViewState("CveUsuarioEvaluador")), -1, CInt(ViewState("CveUsuarioEvaluador"))) + End Get + Set + ViewState("CveUsuarioEvaluador") = Value + End Set End Property -#End Region - -#Region "PROPIEDADES - AC NEW" - Private Property DtPresupuestos As DataTable - Get - Return CType(ViewState("DtPresupuestos"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtPresupuestos") = value - End Set - End Property - Private Property EjercicioAC As Integer - Get - Return ViewState("EjercicioAC").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("EjercicioAC") = value - End Set + Private Property TmpDT As DataTable + Get + Return CType(ViewState("TmpDT"), DataTable) + End Get + Set(value As DataTable) + ViewState("TmpDT") = value + End Set End Property -#End Region - -#Region " PROPIEDADES REFACTURACION " - Private Property DtRefacturacion As DataTable - Get - Return CType(ViewState("DtRefacturacion"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtRefacturacion") = value - End Set - End Property - Private Property CveCompraRefacturacion As Integer - Get - Return ViewState("CveCompraRefacturacion").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveCompraRefacturacion") = value - End Set - End Property - Private Property EmpresaPrueba As Boolean - Get - Return CBool(ViewState("EmpresaPrueba")) - End Get - Set(value As Boolean) - ViewState("EmpresaPrueba") = value - End Set - End Property - Private Property StringProrrateo As String - Get - Return ViewState("StringProrrateo").ToString - End Get - Set(value As String) - ViewState("StringProrrateo") = value - End Set - End Property - Private Property ClavesBorradas As ArrayList - Get - Return CType(ViewState("ClavesBorradas"), ArrayList) - End Get - Set(value As ArrayList) - ViewState("ClavesBorradas") = value - End Set + Private Property TmpDTOriginal As DataTable + Get + Return CType(ViewState("TmpDTOriginal"), DataTable) + End Get + Set(value As DataTable) + ViewState("TmpDTOriginal") = value + End Set + End Property + Private Property TmpCXP As DataTable + Get + Return CType(ViewState("TmpCXP"), DataTable) + End Get + Set(value As DataTable) + ViewState("TmpCXP") = value + End Set End Property -#End Region - -#Region " PROPIEDADES OC " - Private Property TipoCambioOC As Decimal - Get - Return ViewState("TipoCambioOC").ToString.ToDecimal - End Get - Set(value As Decimal) - ViewState("TipoCambioOC") = value - End Set - End Property - Private Property PopUpOC As Boolean - Get - Return CBool(ViewState("PopUpOC")) - End Get - Set(value As Boolean) - ViewState("PopUpOC") = value - End Set + 'Private Property PSDTRemplazo As DataTable + ' Get + ' Return CType(ViewState("PSDTRemplazo"), DataTable) + ' End Get + ' Set(value As DataTable) + ' ViewState("PSDTRemplazo") = value + ' End Set + 'End Property + Private Property DtCheques As DataTable + Get + Return CType(ViewState("DtCheques"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtCheques") = value + End Set End Property -#End Region -#Region "PROPIEDADES ALMACEN" 'Charlie - Private Property TotalAlmacen As Decimal - Get - Return ViewState("TotalAlmacen").ToString.ToDecimal - End Get - Set(value As Decimal) - ViewState("TotalAlmacen") = value - End Set - End Property - - Private Property TotalFlete As Decimal - Get - Return ViewState("TotalFlete").ToString.ToDecimal - End Get - Set(value As Decimal) - ViewState("TotalFlete") = value - End Set + Private Property Modalidad As String + Get + Return ViewState("Modalidad").ToString + End Get + Set(value As String) + ViewState("Modalidad") = value + End Set End Property -#End Region -#Region "Propiedades" + Public Property IdVale As List(Of Integer) + Get + IdVale = DirectCast(ViewState("IdVale"), List(Of Integer)) + End Get + + Set(ByVal value As List(Of Integer)) + ViewState("IdVale") = value + End Set + End Property + Public Property ListaDocumentos As List(Of String) + Get + ListaDocumentos = DirectCast(ViewState("ListaDocumentos"), List(Of String)) + End Get + Set(ByVal value As List(Of String)) + ViewState("ListaDocumentos") = value + End Set + End Property + + Public Property TieneAnticiposXML As Boolean + Get + TieneAnticiposXML = DirectCast(ViewState("TieneAnticiposXML"), Boolean) + End Get + Set(ByVal value As Boolean) + ViewState("TieneAnticiposXML") = value + End Set + End Property + + Private Property DTOCTemp As DataTable + Get + Return CType(ViewState("DTOCTemp"), DataTable) + End Get + Set(value As DataTable) + ViewState("DTOCTemp") = value + End Set + End Property + Private Property DTOCGV As DataTable + Get + Return CType(ViewState("DTOCGV"), DataTable) + End Get + Set(value As DataTable) + ViewState("DTOCGV") = value + End Set + End Property + Private Property DtConsignaciones As DataTable + Get + Return CType(ViewState("DtConsignaciones"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtConsignaciones") = value + End Set + End Property + + 'Private Property DtCuentas As DataTable + ' Get + ' Return CType(ViewState("DtCuentas"), DataTable) + ' End Get + ' Set(value As DataTable) + ' ViewState("DtCuentas") = value + ' End Set + 'End Property + 'Private Property CargoFactura As Boolean + ' Get + ' Return CType(ViewState("CargoFactura"), Boolean) + ' End Get + ' Set(value As Boolean) + ' ViewState("CargoFactura") = value + ' End Set + 'End Property + Private Property tDTAcarreos As DataTable + Get + Return If(IsNothing(ViewState("tDTAcarreos")), Nothing, CType(ViewState("tDTAcarreos"), DataTable)) + End Get + Set(value As DataTable) + ViewState("tDTAcarreos") = value + End Set + End Property + Private Property DtDeudores As DataTable + Get + Return CType(ViewState("DtDeudores"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtDeudores") = value + End Set + End Property + Private Property DtDeudoresDetalle As DataTable + Get + Return CType(ViewState("DtDeudoresDetalle"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtDeudoresDetalle") = value + End Set + End Property + Private Property DtAcreedores As DataTable + Get + Return CType(ViewState("DtAcreedores"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtAcreedores") = value + End Set + End Property + Private Property DTUM As DataTable + Get + Return CType(ViewState("DTUM"), DataTable) + End Get + Set(value As DataTable) + ViewState("DTUM") = value + End Set + End Property + Private Property TmpDTTiposAF As DataTable + Get + Return CType(ViewState("TmpDTTiposAF"), DataTable) + End Get + Set(value As DataTable) + ViewState("TmpDTTiposAF") = value + End Set + End Property + Private Property DtFacturas As DataTable + Get + Return CType(ViewState("DtFacturas"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtFacturas") = value + End Set + End Property + + Private Property DtServicios As DataTable + Get + Return CType(ViewState("DtServicios"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtServicios") = value + End Set + End Property + Private ReadOnly Property CveProveedor As Integer + Get + Return ViewState("CveProveedor").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveTipoProveedor As Integer + Get + Return ViewState("CveTipoProveedor").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CtaProveedor As Integer + Get + Return ViewState("CtaProveedor").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedor As Integer + Get + Return ViewState("CveCuentaProveedor").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CtaProveedorDeudores As Integer + Get + Return ViewState("CtaProveedorDeudores").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedorDeudores As Integer + Get + Return ViewState("CveCuentaProveedorDeudores").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedorAcreedores As Integer + Get + Return ViewState("CveCuentaProveedorAcreedores").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CtaProveedorAcreedores As Integer + Get + Return ViewState("CtaProveedorAcreedores").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CtaProveedorAnticipos As Integer + Get + Return ViewState("CtaProveedorAnticipos").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedorAnticipos As Integer + Get + Return ViewState("CveCuentaProveedorAnticipos").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CtaProveedorAnticiposExtranjera As Integer + Get + Return ViewState("CtaProveedorAnticiposExtranjera").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedorAnticiposExtranjera As Integer + Get + Return ViewState("CveCuentaProveedorAnticiposExtranjera").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CtaProveedorAnticiposComplementaria As Integer + Get + Return ViewState("CtaProveedorAnticiposComplementaria").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedorAnticiposComplementaria As Integer + Get + Return ViewState("CveCuentaProveedorAnticiposComplementaria").ToString.ToEntero + End Get + End Property + + Private ReadOnly Property CtaProveedorRetIVA As Integer + Get + Return ViewState("CtaProveedorRetIVA").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedorRetIVA As Integer + Get + Return ViewState("CveCuentaProveedorRetIVA").ToString.ToEntero + End Get + End Property + + Private ReadOnly Property CtaProveedorRetISR As Integer + Get + Return ViewState("CtaProveedorRetISR").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedorRetISR As Integer + Get + Return ViewState("CveCuentaProveedorRetISR").ToString.ToEntero + End Get + End Property + + Private ReadOnly Property CveCuentaIEPS As Integer + Get + Return ViewState("CveCuentaIEPS").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CtaProveedorExtranjera As Integer + Get + Return ViewState("CtaProveedorExtranjera").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedorExtranjera As Integer + Get + Return ViewState("CveCuentaProveedorExtranjera").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CtaProveedorComplementaria As Integer + Get + Return ViewState("CtaProveedorComplementaria").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveCuentaProveedorComplementaria As Integer + Get + Return ViewState("CveCuentaProveedorComplementaria").ToString.ToEntero + End Get + End Property + Private ReadOnly Property NombreProveedor As String + Get + Return ViewState("NombreProveedor").ToString + End Get + End Property + Private Property IdPoliza As Integer + Get + Return ViewState("IdPoliza").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("IdPoliza") = value + End Set + End Property + Private Property CveOrdenCorte As Integer + Get + Return ViewState("CveOrdenCorte").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveOrdenCorte") = value + End Set + End Property + Private Property CvePrePoliza As Integer + Get + Return ViewState("CvePrePoliza").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CvePrePoliza") = value + End Set + End Property + Private ReadOnly Property CveCompra As Integer + Get + Return ViewState("CveCompra").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CveFactura As Integer + Get + Return ViewState("CveFactura").ToString.ToEntero + End Get + End Property + Private Property CveMovimientoAlmacen As Integer + Get + Return ViewState("CveMovimientoAlmacen").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveMovimientoAlmacen") = value + End Set + End Property + Private Property CveConsignacion As Integer + Get + Return ViewState("CveConsignacion").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveConsignacion") = value + End Set + End Property + Private Property PermisoEdicionManual As Boolean + Get + Return CType(ViewState("PermisoEdicionManual"), Boolean) + End Get + Set(value As Boolean) + ViewState("PermisoEdicionManual") = value + End Set + End Property + + Private Property NuevaValidacionXML As Integer + Get + Return ViewState("NuevaValidacionXML").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("NuevaValidacionXML") = value + End Set + End Property + Private Property IdCuentaBancaria As Integer + Get + Return ViewState("IdCuentaBancaria").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("IdCuentaBancaria") = value + End Set + End Property + Private Property CveCuentaBancaria As Integer + Get + Return ViewState("CveCuentaBancaria").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveCuentaBancaria") = value + End Set + End Property + Private Property IdCuentaBancariaComplementaria As Integer + Get + Return ViewState("IdCuentaBancariaComplementaria").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("IdCuentaBancariaComplementaria") = value + End Set + End Property + Private Property CveCuentaBancariaComplementaria As Integer + Get + Return ViewState("CveCuentaBancariaComplementaria").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveCuentaBancariaComplementaria") = value + End Set + End Property + Private Property IvaAcumulado As Double + Get + Return ViewState("IvaAcumulado").ToString.ToDouble + End Get + Set(value As Double) + ViewState("IvaAcumulado") = value + End Set + End Property + + Private Property EsContado As Boolean + Get + Return CType(ViewState("EsContado"), Boolean) + End Get + Set(value As Boolean) + ViewState("EsContado") = value + End Set + End Property + + 'Private ReadOnly Property CompraFolio As String + ' Get + ' Return ViewState("CompraFolio").ToString + ' End Get + 'End Property + 'Private ReadOnly Property FolioFiscal As String + ' Get + ' Return ViewState("FolioFiscal").ToString + ' End Get + 'End Property + + 'Private ReadOnly Property IdCtaContProveedores As Integer + ' Get + ' Return ViewState("IdCtaContProveedores").ToString.ToEntero + ' End Get + 'End Property + 'Private ReadOnly Property IdCtaContAnticipos As Integer + ' Get + ' Return ViewState("IdCtaContAnticipos").ToString.ToEntero + ' End Get + 'End Property + 'Private ReadOnly Property IdCtaContRetIVA As Integer + ' Get + ' Return ViewState("IdCtaContRetIVA").ToString.ToEntero + ' End Get + 'End Property + 'Private ReadOnly Property IdCtaContRetISR As Integer + ' Get + ' Return ViewState("IdCtaContRetISR").ToString.ToEntero + ' End Get + 'End Property + + 'Private ReadOnly Property IVAPS As Double + ' Get + ' Return ViewState("IVAPS").ToString.ToDouble + ' End Get + 'End Property + 'Private ReadOnly Property RetIVA As Double + ' Get + ' Return ViewState("RetIVA").ToString.ToDouble + ' End Get + 'End Property + 'Private ReadOnly Property RetISR As Double + ' Get + ' Return ViewState("RetISR").ToString.ToDouble + ' End Get + 'End Property + 'Private ReadOnly Property IEPSPS As Double + ' Get + ' Return ViewState("IEPSPS").ToString.ToDouble + ' End Get + 'End Property + 'Private ReadOnly Property IEPSPSIVA As Double + ' Get + ' Return ViewState("IEPSPSIVA").ToString.ToDouble + ' End Get + 'End Property + Private Property TotalGeneral As Double + Get + Return ViewState("TotalGeneral").ToString.ToDouble + End Get + Set(value As Double) + ViewState("TotalGeneral") = value + End Set + End Property + + Private Property CompraSaldo As Double + Get + Return ViewState("CompraSaldo").ToString.ToDouble + End Get + Set(value As Double) + ViewState("CompraSaldo") = value + End Set + End Property + Private Property Saldo As Double + Get + Return ViewState("Saldo").ToString.ToDouble + End Get + Set(value As Double) + ViewState("Saldo") = value + End Set + End Property + + Private Property CveMoneda As Integer + Get + Return ViewState("CveMoneda").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveMoneda") = value + End Set + End Property + Private Property CveAlmacenConsignacion As Integer + Get + Return ViewState("CveAlmacenConsignacion").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveAlmacenConsignacion") = value + End Set + End Property + + Private Property DtFuncionarios As DataTable + Get + Return CType(ViewState("DtFuncionarios"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtFuncionarios") = value + End Set + End Property + + Private Property DtDatosDetalle As DataTable + Get + Return CType(ViewState("DtDatosDetalle"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtDatosDetalle") = value + End Set + End Property + Private Property CvePSSerieLote As Integer + Get + Return CType(ViewState("CvePSSerieLote"), Integer) + End Get + Set(value As Integer) + ViewState("CvePSSerieLote") = value + End Set + End Property + Private Property CveUMSerieLote As Integer + Get + Return CType(ViewState("CveUMSerieLote"), Integer) + End Get + Set(value As Integer) + ViewState("CveUMSerieLote") = value + End Set + End Property + Private Property PUSerieLote As Decimal + Get + Return CType(ViewState("PUSerieLote"), Decimal) + End Get + Set(value As Decimal) + ViewState("PUSerieLote") = value + End Set + End Property + Private Property TotAcarreos As Double + Get + Return CType(ViewState("TotAcarreos"), Double) + End Get + Set(value As Double) + ViewState("TotAcarreos") = value + End Set + End Property + + 'Private ReadOnly Property Ruta As String + ' Get + ' Return AppDomain.CurrentDomain.BaseDirectory & "Empresas\" & UsuarioActual.CveEmpresa & "\" + ' End Get + 'End Property + + + Public Class Anticipos + Public Property TipoMovto As String + Public Property CveIE As Integer + Public Property Importe As Decimal + Public Property TCCompra As Decimal + + Public Property CvePersonal As Integer + Public Property CveCompra As Integer + Public Property CvePrePoliza As Integer + End Class + Private Property ArrAnticipos As ArrayList + Get + Return CType(ViewState("ArrAnticipos"), ArrayList) + End Get + Set(value As ArrayList) + ViewState("ArrAnticipos") = value + End Set + End Property + Private Property ArrIE As ArrayList + Get + Return CType(ViewState("ArrIE"), ArrayList) + End Get + Set(value As ArrayList) + ViewState("ArrIE") = value + End Set + End Property + Private Property ArrIEFuncionariosEmpleados As ArrayList + Get + Return CType(ViewState("ArrIEFuncionariosEmpleados"), ArrayList) + End Get + Set(value As ArrayList) + ViewState("ArrIEFuncionariosEmpleados") = value + End Set + End Property + 'Inventarios + Private Property DtInv As DataTable + Get + Return CType(ViewState("DtInv"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtInv") = value + End Set + End Property + + Private Property DtAC As DataTable + Get + DtAC = DirectCast(ViewState("DtAC"), DataTable) + End Get + + Set(ByVal value As DataTable) + ViewState("DtAC") = value + End Set + End Property + + 'Caja Chica, Funcionario/Empleado + Private ReadOnly Property CveCajaChica As Integer + Get + Return ViewState("CveCajaChica").ToString.ToEntero + End Get + End Property + Private ReadOnly Property CvePersonal As Integer + Get + Return ViewState("CvePersonal").ToString.ToEntero + End Get + End Property + Private Property OCsVinculadas As String + Get + Return ViewState("OCsVinculadas").ToString + End Get + Set(value As String) + ViewState("OCsVinculadas") = value + End Set + End Property + + Private Property DdlOC As DropDownList + Get + Return CType(ViewState("OCsVinculadas"), DropDownList) + End Get + Set(value As DropDownList) + ViewState("OCsVinculadas") = value + End Set + End Property + + Private Property TieneOC As Boolean + Get + Return CType(ViewState("TieneOC"), Boolean) + End Get + Set(value As Boolean) + ViewState("TieneOC") = value + End Set + End Property + Private Property OCVinculada As Boolean + Get + Return CType(ViewState("OCVinculada"), Boolean) + End Get + Set(value As Boolean) + ViewState("OCVinculada") = value + End Set + End Property + Private Property CierrePeriodo As Boolean + Get + Return CType(ViewState("CierrePeriodo"), Boolean) + End Get + Set(value As Boolean) + ViewState("CierrePeriodo") = value + End Set + End Property + Private Property NCDevolucion As Boolean + Get + Return CType(ViewState("NCDevolucion"), Boolean) + End Get + Set(value As Boolean) + ViewState("NCDevolucion") = value + End Set + End Property + Private Property CompraCargada As Boolean + Get + Return CType(ViewState("CompraCargada"), Boolean) + End Get + Set(value As Boolean) + ViewState("CompraCargada") = value + End Set + End Property + Private Property ModalidadUMAlias As Integer + Get + Return ViewState("EjercicioAC").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("EjercicioAC") = value + End Set + End Property + + Private Property CveConceptoContableAlmacen As Integer + Get + Return ViewState("CveConceptoContableAlmacen").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveConceptoContableAlmacen") = value + End Set + End Property + Private Property EsNoDeducible As Boolean + Get + Return CType(ViewState("EsNoDeducible"), Boolean) + End Get + Set(value As Boolean) + ViewState("EsNoDeducible") = value + End Set + End Property +#End Region + +#Region "PROPIEDADES - AC NEW" + Private Property DtPresupuestos As DataTable + Get + Return CType(ViewState("DtPresupuestos"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtPresupuestos") = value + End Set + End Property + Private Property EjercicioAC As Integer + Get + Return ViewState("EjercicioAC").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("EjercicioAC") = value + End Set + End Property +#End Region + +#Region " PROPIEDADES REFACTURACION " + Private Property DtRefacturacion As DataTable + Get + Return CType(ViewState("DtRefacturacion"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtRefacturacion") = value + End Set + End Property + Private Property CveCompraRefacturacion As Integer + Get + Return ViewState("CveCompraRefacturacion").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveCompraRefacturacion") = value + End Set + End Property + Private Property EmpresaPrueba As Boolean + Get + Return CBool(ViewState("EmpresaPrueba")) + End Get + Set(value As Boolean) + ViewState("EmpresaPrueba") = value + End Set + End Property + Private Property StringProrrateo As String + Get + Return ViewState("StringProrrateo").ToString + End Get + Set(value As String) + ViewState("StringProrrateo") = value + End Set + End Property + Private Property ClavesBorradas As ArrayList + Get + Return CType(ViewState("ClavesBorradas"), ArrayList) + End Get + Set(value As ArrayList) + ViewState("ClavesBorradas") = value + End Set + End Property + +#End Region + +#Region " PROPIEDADES OC " + Private Property TipoCambioOC As Decimal + Get + Return ViewState("TipoCambioOC").ToString.ToDecimal + End Get + Set(value As Decimal) + ViewState("TipoCambioOC") = value + End Set + End Property + Private Property PopUpOC As Boolean + Get + Return CBool(ViewState("PopUpOC")) + End Get + Set(value As Boolean) + ViewState("PopUpOC") = value + End Set + End Property +#End Region + +#Region "PROPIEDADES ALMACEN" 'Charlie + Private Property TotalAlmacen As Decimal + Get + Return ViewState("TotalAlmacen").ToString.ToDecimal + End Get + Set(value As Decimal) + ViewState("TotalAlmacen") = value + End Set + End Property + + Private Property TotalFlete As Decimal + Get + Return ViewState("TotalFlete").ToString.ToDecimal + End Get + Set(value As Decimal) + ViewState("TotalFlete") = value + End Set + End Property +#End Region + +#Region "Propiedades" 'CFDi - Private Property Serie As String - Private Property Folio As String - Private Property Fecha As String - Private Property SubTotal As Decimal + Private Property Serie As String + Private Property Folio As String + Private Property Fecha As String + Private Property SubTotal As Decimal Private Property Total As Decimal = 0 - Private Property Descuentos As Decimal = 0 - Private Property Amortizaciones As Decimal = 0 - Private Property EmisorRFC As String - Private Property ReceptorRFC As String - Private Property TrasladoIVA As Decimal = 0 - Private Property RetencionIVA As Decimal = 0 - Private Property RetencionISR As Decimal = 0 - Private Property TrasladoIEPS As Decimal = 0 - Private Property TFDUUID As String = "" - Private Property Moneda As String = "" - Private Property TipoComprobante As String = "" - Private Property MetodoPago As String = "" - Private Property CveMetodoPago As Integer - Get - Return ViewState("CveMetodoPago").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveMetodoPago") = value - End Set - End Property - Private Property TipoCambio As Double - Get - Return ViewState("TipoCambio").ToString.ToDouble - End Get - Set(value As Double) - ViewState("TipoCambio") = value - End Set - End Property - 'Private Property TipoCambio As Double = 0 - Private Property OtrosImpuestos As Decimal = 0 - Private Property OtrosImpuestosRetenciones As Decimal = 0 - Private Property TotalRetenciones As Decimal = 0 - Private Property SumaTotalRetenciones As Decimal = 0 - Private Property TotalTraslados As Decimal = 0 - Private Property SumaTotalTraslados As Decimal = 0 - Private Property SubTotalConceptos As Decimal = 0 - Private Property Redondeo As Decimal = 0 - Private Property IEPSGasto As Boolean = False - Private Property OtrosImpuestosGasto As Boolean = False - - Private Property Version As String - Get - Return ViewState("Version").ToString - End Get - Set(value As String) - ViewState("Version") = value - End Set - End Property - Private Property Index As Integer - Get - Return ViewState("Index").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("Index") = value - End Set - End Property - - Private Property Con As Integer - Get - Return ViewState("Con").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("Con") = value - End Set - End Property - - Private Property IvaTotalGv As Double - Get - Return DirectCast(ViewState("IvaTotalGv"), Double) - End Get - Set(value As Double) - ViewState("IvaTotalGv") = value - End Set - End Property - - Private Property SerieVieja As String - Get - Return DirectCast(ViewState("SerieVieja"), String) - End Get - Set(value As String) - ViewState("SerieVieja") = value - End Set - End Property - - Private Property EstatusAlmacen As Integer - Get - Return ViewState("EstatusAlmacen").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("EstatusAlmacen") = value - End Set - End Property - - Private Property DtTemporalGuardados As DataTable - Get - Return CType(ViewState("DtTemporalGuardados"), DataTable) - End Get - Set(value As DataTable) - ViewState("DtTemporalGuardados") = value - End Set - End Property - - Private Property RFCProv As String - Get - Return IfNull(ViewState("RFCProv"), "").ToString - End Get - Set(value As String) - ViewState("RFCProv") = value - End Set - End Property - - Private Property CveImportacion As Integer - Get - Return IfNull(ViewState("CveImportacion"), -1).ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveImportacion") = value - End Set - End Property - Private Property CveFlete As Integer - Get - Return IfNull(ViewState("CveFlete"), -1).ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveFlete") = value - End Set - End Property - Private Property FleteImportacionOpcion As Integer - Get - Return IfNull(ViewState("FleteImportacionOpcion"), -1).ToString.ToEntero - End Get - Set(value As Integer) - ViewState("FleteImportacionOpcion") = value - End Set + Private Property Descuentos As Decimal = 0 + Private Property Amortizaciones As Decimal = 0 + Private Property EmisorRFC As String + Private Property ReceptorRFC As String + Private Property TrasladoIVA As Decimal = 0 + Private Property RetencionIVA As Decimal = 0 + Private Property RetencionISR As Decimal = 0 + Private Property TrasladoIEPS As Decimal = 0 + Private Property TFDUUID As String = "" + Private Property Moneda As String = "" + Private Property TipoComprobante As String = "" + Private Property MetodoPago As String = "" + Private Property CveMetodoPago As Integer + Get + Return ViewState("CveMetodoPago").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveMetodoPago") = value + End Set + End Property + Private Property TipoCambio As Double + Get + Return ViewState("TipoCambio").ToString.ToDouble + End Get + Set(value As Double) + ViewState("TipoCambio") = value + End Set + End Property + 'Private Property TipoCambio As Double = 0 + Private Property OtrosImpuestos As Decimal = 0 + Private Property OtrosImpuestosRetenciones As Decimal = 0 + Private Property TotalRetenciones As Decimal = 0 + Private Property SumaTotalRetenciones As Decimal = 0 + Private Property TotalTraslados As Decimal = 0 + Private Property SumaTotalTraslados As Decimal = 0 + Private Property SubTotalConceptos As Decimal = 0 + Private Property Redondeo As Decimal = 0 + Private Property IEPSGasto As Boolean = False + Private Property OtrosImpuestosGasto As Boolean = False + + Private Property Version As String + Get + Return ViewState("Version").ToString + End Get + Set(value As String) + ViewState("Version") = value + End Set + End Property + Private Property Index As Integer + Get + Return ViewState("Index").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("Index") = value + End Set End Property -#End Region - -#Region " PROPIEDADES DE TOTALES " - Private Property SubTotalOriginal As Double - Get - Return ViewState("SubTotalOriginal").ToString.ToDouble - End Get - Set(value As Double) - ViewState("SubTotalOriginal") = value - End Set - End Property - Private Property SubTotal2Original As Double - Get - Return ViewState("SubTotal2Original").ToString.ToDouble - End Get - Set(value As Double) - ViewState("SubTotal2Original") = value - End Set + Private Property Con As Integer + Get + Return ViewState("Con").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("Con") = value + End Set End Property - Private Property IVAOriginal As Double + Private Property IvaTotalGv As Double + Get + Return DirectCast(ViewState("IvaTotalGv"), Double) + End Get + Set(value As Double) + ViewState("IvaTotalGv") = value + End Set + End Property + + Private Property SerieVieja As String + Get + Return DirectCast(ViewState("SerieVieja"), String) + End Get + Set(value As String) + ViewState("SerieVieja") = value + End Set + End Property + + Private Property EstatusAlmacen As Integer + Get + Return ViewState("EstatusAlmacen").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("EstatusAlmacen") = value + End Set + End Property + + Private Property DtTemporalGuardados As DataTable + Get + Return CType(ViewState("DtTemporalGuardados"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtTemporalGuardados") = value + End Set + End Property + + Private Property RFCProv As String + Get + Return IfNull(ViewState("RFCProv"), "").ToString + End Get + Set(value As String) + ViewState("RFCProv") = value + End Set + End Property + + Private Property CveImportacion As Integer + Get + Return IfNull(ViewState("CveImportacion"), -1).ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveImportacion") = value + End Set + End Property + Private Property CveFlete As Integer + Get + Return IfNull(ViewState("CveFlete"), -1).ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveFlete") = value + End Set + End Property + Private Property FleteImportacionOpcion As Integer + Get + Return IfNull(ViewState("FleteImportacionOpcion"), -1).ToString.ToEntero + End Get + Set(value As Integer) + ViewState("FleteImportacionOpcion") = value + End Set + End Property + +#End Region + +#Region " PROPIEDADES DE TOTALES " + Private Property SubTotalOriginal As Double + Get + Return ViewState("SubTotalOriginal").ToString.ToDouble + End Get + Set(value As Double) + ViewState("SubTotalOriginal") = value + End Set + End Property + Private Property SubTotal2Original As Double + Get + Return ViewState("SubTotal2Original").ToString.ToDouble + End Get + Set(value As Double) + ViewState("SubTotal2Original") = value + End Set + End Property + + Private Property IVAOriginal As Double Get - If ViewState("IVAOriginal") Is Nothing Then - Return 0 - Else - Return ViewState("IVAOriginal").ToString.ToDouble + If ViewState("IVAOriginal") Is Nothing Then + Return 0 + Else + Return ViewState("IVAOriginal").ToString.ToDouble End If - End Get - Set(value As Double) - ViewState("IVAOriginal") = value - End Set - End Property - Private Property RetIVAOriginal As Double - Get - Return ViewState("RetIVAOriginal").ToString.ToDouble - End Get - Set(value As Double) - ViewState("RetIVAOriginal") = value - End Set - End Property - Private Property RetISROriginal As Double - Get - Return ViewState("RetISROriginal").ToString.ToDouble - End Get - Set(value As Double) - ViewState("RetISROriginal") = value - End Set + End Get + Set(value As Double) + ViewState("IVAOriginal") = value + End Set + End Property + Private Property RetIVAOriginal As Double + Get + Return ViewState("RetIVAOriginal").ToString.ToDouble + End Get + Set(value As Double) + ViewState("RetIVAOriginal") = value + End Set + End Property + Private Property RetISROriginal As Double + Get + Return ViewState("RetISROriginal").ToString.ToDouble + End Get + Set(value As Double) + ViewState("RetISROriginal") = value + End Set End Property - Private Property TotalOriginal As Double - Get + Private Property TotalOriginal As Double + Get If ViewState("TotalOriginal") Is Nothing Then Return 0 Else Return ViewState("TotalOriginal").ToString.ToDouble End If - End Get - Set(value As Double) - ViewState("TotalOriginal") = value - End Set - End Property - - Private Property ActualizaTotales As Boolean - Get - Return CBool(ViewState("ActualizaTotales")) - End Get - Set(value As Boolean) - ViewState("ActualizaTotales") = value - End Set + End Get + Set(value As Double) + ViewState("TotalOriginal") = value + End Set End Property -#End Region + Private Property ActualizaTotales As Boolean + Get + Return CBool(ViewState("ActualizaTotales")) + End Get + Set(value As Boolean) + ViewState("ActualizaTotales") = value + End Set + End Property - Dim DTConceptos As DataTable - Private Property EmpresasOC As List(Of Integer) - Get - EmpresasOC = DirectCast(ViewState("EmpresasOC"), List(Of Integer)) - End Get - Set(ByVal value As List(Of Integer)) - ViewState("EmpresasOC") = value - End Set - End Property - - Private Property DtPendientesAlmacen As DataTable - Get - DtPendientesAlmacen = DirectCast(ViewState("DtPendientesAlmacen"), DataTable) - End Get - - Set(ByVal value As DataTable) - ViewState("DtPendientesAlmacen") = value - End Set - End Property - - Private Property CveTipoConcepto As Integer - Get - Return ViewState("CveTipoConcepto").ToString.ToEntero - End Get - Set(value As Integer) - ViewState("CveTipoConcepto") = value - End Set - End Property - - Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load - If Not IsPostBack Then - 'ImgBtnBuscarOC.Attributes.Add("data-toggle", "tooltip") - 'ImgBtnBuscarOC.Attributes.Add("data-placement", "top") - CargaDatosAgregarPS() +#End Region + + Dim DTConceptos As DataTable + Private Property EmpresasOC As List(Of Integer) + Get + EmpresasOC = DirectCast(ViewState("EmpresasOC"), List(Of Integer)) + End Get + Set(ByVal value As List(Of Integer)) + ViewState("EmpresasOC") = value + End Set + End Property + + Private Property DtPendientesAlmacen As DataTable + Get + DtPendientesAlmacen = DirectCast(ViewState("DtPendientesAlmacen"), DataTable) + End Get + + Set(ByVal value As DataTable) + ViewState("DtPendientesAlmacen") = value + End Set + End Property + + Private Property CveTipoConcepto As Integer + Get + Return ViewState("CveTipoConcepto").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveTipoConcepto") = value + End Set + End Property + + Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load + If Not IsPostBack Then + 'ImgBtnBuscarOC.Attributes.Add("data-toggle", "tooltip") + 'ImgBtnBuscarOC.Attributes.Add("data-placement", "top") + CargaDatosAgregarPS() TieneAnticiposXML = False - Modalidad = "" - Version = "" - CveMetodoPago = -1 - RFCProv = "" - CargaDdlTipoGasto() - CreaTmpAcarreos() - EsContado = False - CierrePeriodo = False - NCDevolucion = False - CompraCargada = False - Saldo = 0 - SubTotalOriginal = 0 - CveConceptoContableAlmacen = 0 - EsNoDeducible = False - CveTipoConcepto = 1 - '******** Prorrateo ******************************************** - If UsuarioActual.Empresa.Funcionalidad(117) <> "" Then - btnProrateo.Visible = True - End If - - If UsuarioActual.Empresa.Funcionalidad(303) <> "" Then - btnProrateo2.Visible = True - End If - '**************************************************************** - 'If UsuarioActual.CveEmpresa = 72 Then - ' LiRecepcion.Visible = True - ' DdlRecepcion.SelectedValue = "2" - 'End If - - TipoCambio = 1 - IvaAcumulado = 0 - TotalAlmacen = 0 - TotalFlete = 0 - CveOrdenCorte = -1 - - 'VALIDACION DE XML - NuevaValidacionXML = IfNull(Request("NuevaValidacionXML"), 0).ToString.ToEntero - - - IdVale = New List(Of Integer) - - ListaDocumentos = New List(Of String) - - 'If UsuarioActual.Empresa.Funcionalidad(207) = "1" Then 'Esquema nuevo PrePolizas - If Not UsuarioActual.Empresa.UsaAC Then - EmpresaPrueba = True - TotalGeneral = 0 - CompraSaldo = 0 - ViewState("CvePersonal") = -1 - IdCuentaBancaria = 0 - CveCuentaBancaria = 0 - End If - - IdCuentaBancariaComplementaria = 0 - CveCuentaBancariaComplementaria = 0 - - 'If UsuarioActual.TienePermisoProceso(259) Then - DivEsNoDeducible.Visible = True - 'End If - - If UsuarioActual.Empresa.Funcionalidad(125) = "1" Then 'Seleccionar a quien se abona la Prepoliza - 'ddlCargoPrePoliza.Visible = True - 'lblProveedor.Visible = False - End If - - If isAlmacenistaGluyas() Then - GvInv.Columns(10).Visible = True - 'Dim productos As New ClsProductosServicios - 'If productos.GetPS(-1, -1, UsuarioActual.CveEmpresa) Then - ' PSDTRemplazo = productos.DtResultados.FiltraParametros("PendienteEnOC=1", "PS") - 'End If - 'productos.Dispose() - End If - - PermisoEdicionManual = False - CveMovimientoAlmacen = 0 - SetValues() - ArrAnticipos = New ArrayList() - ArrIE = New ArrayList() - ArrIEFuncionariosEmpleados = New ArrayList() - ClavesBorradas = New ArrayList() - TxtFecha.Text = Now.ToShortDateString - TxtFechaEjecucion.Text = Now.ToShortDateString - ViewState("CveCompra") = "0" - ViewState("CveFactura") = "0" - ViewState("IdPoliza") = "0" - ViewState("CveCompra") = -1 - ViewState("EjercicioAC") = -1 - ViewState("CveTipoProveedor") = -1 - CveCompraRefacturacion = -1 - ModalidadUMAlias = -1 - CvePrePoliza = -1 - TabActivosFijos.Enabled = UsuarioActual.Empresa.UsaAF - - TieneOC = False - CveMoneda = -1 - - '[IPP] Eliminar 22Junio2018 - 'If UsuarioActual.Empresa.UsaInventarios Then - ' TabAlmacen.Enabled = Not UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 - 'End If - - ImgAnticiposPendientes.Attributes.Add("OnClick", "MuestraAnticipos();") - 'ImgCerrar.Attributes.Add("OnClick", "$('#DivAnticipos').hide(200);") - 'BtnCancelar.Attributes.Add("OnClick", "$('#DivAddEq').hide();") - ' ImageButton1.Attributes.Add("OnClick", "$('#DivAlmacen').hide();") - ImgClose.Attributes.Add("OnClick", "$('#DivAlmacen').hide();") - ImgAdd.Attributes.Add("OnClick", "$('#DivAlmacen').hide();") - 'LbTotalPorDevengar.Attributes.Add("OnInnerTextChanged", "TotalDevendar();") - 'Mensaje temporalca - - RBLPago.Visible = True - If UsuarioActual.Empresa.UsaAC Then RBLPago.Items.RemoveAt(2) 'Elimina Reembolso cuando es AC - - - If UsuarioActual.Empresa.UsaAC Then - TrReembolso.Visible = True - GvPS.Columns(1).Visible = True - TxtFecha.Attributes.Add("onblur", "CambiaFecha();") - End If - - TxtOC.Attributes.Add("onkeypress", "fncBuscaOC(event);") - - 'If UsuarioActual.Empresa.GralSoloProyecto Then - - ' LitHProyecto.Text = "Sucursal" - ' DdlSubProyecto.Items.Clear() - ' DdlSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) - ' DdlSubProyecto.DataBind() - ' DdlSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) - - ' DdlAsignaSubProyecto.Items.Clear() - ' DdlAsignaSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) - ' DdlAsignaSubProyecto.DataBind() - ' DdlAsignaSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) - - ' divproyecto.Visible = False - ' divasignaproyecto.Visible = False - ' DdlProyecto.Visible = False - ' DdlProyecto.Items(0).Text = "" - - 'End If - - If UsuarioActual.CveEmpresa = 66 And UsuarioActual.TienePermisoProceso(96) Then - ChkProgramarPago.Visible = True - End If - - - 'CARGA PERSONAL - Dim ObjPersonal As New ClsRH - ObjPersonal.GetPersonal(-1, UsuarioActual.CveEmpresa) - DdlPersonal.DataSource = ObjPersonal.DtResultados - DdlPersonalReembolso.DataSource = ObjPersonal.DtResultados - ObjPersonal.Dispose() - DdlPersonal.DataBind() - DdlPersonalReembolso.DataBind() - - - 'Carga Proveedor - If Request("CveProveedor") IsNot Nothing AndAlso IsNumeric(Request("CveProveedor")) AndAlso Request("CveProveedor").ToEntero > 0 Then - ViewState("CveProveedor") = Request("CveProveedor") - HdnCveProveedor.Value = Request("CveProveedor") - CargaProveedor(CveProveedor, "-1") - GvInv.Visible = True - ElseIf Request("CveFactura") IsNot Nothing AndAlso IsNumeric(Request("CveFactura")) AndAlso Request("CveFactura").ToEntero > 0 Then - ViewState("CveFactura") = Request("CveFactura").ToEntero - - Dim RFC As String = CargaFactura(CveFactura) - DdlProveedor.Visible = False - HplProveedor.Visible = True - GvInv.Visible = True - CargaProveedor(-1, RFC) - - If Not DdlTipoComprobante.SelectedValue = "NC" Then - If UsuarioActual.Empresa.Funcionalidad(128) = "1" And Not UsuarioActual.TienePermisoProceso(213) Then - If TmpDT.MAX("CvePS").ToEntero > 0 Then - BtnGuardar.Enabled = False - RegistraScript("$('#ImgBtnBuscarOC').click()") - End If - End If - End If - - If DdlTipoComprobante.SelectedValue = "NC" Then - paneldevolucion.Visible = True - Pnlalmaceninventarios.Visible = False - cargaddldevoluciones(CveProveedor, TxtSubTotal.Text.ToDouble) - InicializaAplicaNCFact() - DivReembolso.Visible = False - RBLPago.Items(2).Enabled = False - - End If - - - - If UsuarioActual.Empresa.UsaAC Then - CambiaEjercicioAC() - End If - - ' ''Fecha limite para ingreso de facturas - ''Dim DtEmpresa As DataTable = GlobalDTEmpresas(UsuarioActual.CveEmpresa) - ''If DtEmpresa.Rows.Count > 0 Then - '' Dim FechaLimite = DateSerial(DtEmpresa.Rows(0)("EjercicioActual").ToString.ToEntero, DtEmpresa.Rows(0)("PeriodoActual").ToString.ToEntero, DtEmpresa.Rows(0)("DiasPermitidos").ToString.ToEntero) - '' If Month(TxtFecha.Text.ToDate) < (Month(FechaLimite) - 1) Or (Month(TxtFecha.Text.ToDate) = (Month(FechaLimite) - 1) And Day(Date.Now) > Day(FechaLimite)) Then - '' Alert("La factura actual ya no aplica para ingresarse al sístema.", TipoMensaje.MsgAdvertencia) - '' BtnGuardar.Enabled = False - '' Else - '' Alert("En tiempo") - '' End If - ''Else - '' Alert("No se pudieron cargar los datos de la empresa", TipoMensaje.MsgAdvertencia) - ''End If - 'Carga Compra - - If UsuarioActual.Empresa.Funcionalidad(123).ToEntero > 0 And Not UsuarioActual.TienePermisoProceso(156) Then - If Not ValidaCierrePeriodo() Then - Alert("El periodo de la compra actual ya se encuentra cerrado. No podra registrar la compra.", TipoMensaje.MsgAdvertencia) - BtnGuardar.Visible = False - TxtOC.Enabled = False - ImgBtnBuscarOC.Enabled = False - CierrePeriodo = True - DivRestriccionAdvertencia.Visible = True - LtRestriccionAdvertencia.Text = "El periodo de la compra actual ya se encuentra cerrado." - End If - End If - - Dim HayDifIEPS As Boolean = False - For Each Gvr As GridViewRow In GvPS.Rows - If Gvr.DataKey("CvePS").ToEntero > 0 AndAlso Gvr.DataKey("IEPSPSPorcentaje").ToDouble > 0 Then - If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=Gvr.DataKey("CvePS").ToEntero).Rows.Count > 0 Then - Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=Gvr.DataKey("CvePS").ToEntero).Rows(0) - If DrPS IsNot Nothing Then - If DrPS("IEPSPorcentaje").ToString.ToDouble <> Gvr.DataKey("IEPSPSPorcentaje").ToDouble Then - HayDifIEPS = True - End If - End If - End If - End If - Next - - If HayDifIEPS Then Alert("El porcentaje de IEPS del producto no coincide con el especificado.", TipoMensaje.MsgAdvertencia) - - If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then CargaGastosServicios(UsuarioActual.Empresa.Funcionalidad(562).ToEntero) - - ElseIf Request("CveCompra") IsNot Nothing AndAlso IsNumeric(Request("CveCompra")) AndAlso Request("CveCompra").ToEntero > 0 Then - - ViewState("CveCompra") = Request("CveCompra") - CargaCompra() - BtnGuardar.Enabled = False - 'TdIVA.Visible = True - 'DdlIVA.Enabled = False - CargaGvBitacora() - InventarioMov() - HabilitaNCInv() - DivConsignaciones.Visible = False - - ' 2018/05/25 - Muestra Boton Agregar Guia - LnkAgregarGuia.Visible = True - UpLnkPaqueteriaGuias.Update() - DivEsNoDeducible.Visible = True - DivActualizarVincular.Visible = True - - Else - - ViewState("CveProveedor") = -1 - HdnCveProveedor.Value = "-1" - DdlProveedor.Items.Insert(0, New ListItem("Seleccione el Proveedor", "-1")) - GvInv.Visible = True - 'TdIVA.Visible = True - 'cuando es nuevo - TxtSubTotal2.Attributes.Add("onkeyup", "ActIVA();") - TxtIVA.Attributes.Add("onkeyup", "ActTotal();") - If UsuarioActual.Empresa.UsaAC Then ChkACGeneral.Checked = False ' codigo que se usa para que al agregar una compra manual, al cambiar el filtro del presupuestos afecte a lo capturado - - If UsuarioActual.Empresa.UsaAC Then - CambiaEjercicioAC() - End If - UpConsignaciones.Update() - UpINV.Update() - 'DdlIVA.Visible = True ' cuando es compra manual - If UsuarioActual.CveEmpresa = 126 Then - CargaOrdenCorte() - LnkAddOtrosGastos.Visible = True - UpnTools.Update() - End If - LnkAgregarGuia.Visible = False - UpLnkPaqueteriaGuias.Update() - End If - - 'SI ES UNA COMPRA NUEVA SE PONE EL TOTAL, SI NO EL SALDO + Modalidad = "" + Version = "" + CveMetodoPago = -1 + RFCProv = "" + CargaDdlTipoGasto() + CreaTmpAcarreos() + EsContado = False + CierrePeriodo = False + NCDevolucion = False + CompraCargada = False + Saldo = 0 + SubTotalOriginal = 0 + CveConceptoContableAlmacen = 0 + EsNoDeducible = False + CveTipoConcepto = 1 + '******** Prorrateo ******************************************** + If UsuarioActual.Empresa.Funcionalidad(117) <> "" Then + btnProrateo.Visible = True + End If + + If UsuarioActual.Empresa.Funcionalidad(303) <> "" Then + btnProrateo2.Visible = True + End If + '**************************************************************** + 'If UsuarioActual.CveEmpresa = 72 Then + ' LiRecepcion.Visible = True + ' DdlRecepcion.SelectedValue = "2" + 'End If + + TipoCambio = 1 + IvaAcumulado = 0 + TotalAlmacen = 0 + TotalFlete = 0 + CveOrdenCorte = -1 + + 'VALIDACION DE XML + NuevaValidacionXML = IfNull(Request("NuevaValidacionXML"), 0).ToString.ToEntero + + + IdVale = New List(Of Integer) + + ListaDocumentos = New List(Of String) + + 'If UsuarioActual.Empresa.Funcionalidad(207) = "1" Then 'Esquema nuevo PrePolizas + If Not UsuarioActual.Empresa.UsaAC Then + EmpresaPrueba = True + TotalGeneral = 0 + CompraSaldo = 0 + ViewState("CvePersonal") = -1 + IdCuentaBancaria = 0 + CveCuentaBancaria = 0 + End If + + IdCuentaBancariaComplementaria = 0 + CveCuentaBancariaComplementaria = 0 + + 'If UsuarioActual.TienePermisoProceso(259) Then + DivEsNoDeducible.Visible = True + 'End If + + If UsuarioActual.Empresa.Funcionalidad(125) = "1" Then 'Seleccionar a quien se abona la Prepoliza + 'ddlCargoPrePoliza.Visible = True + 'lblProveedor.Visible = False + End If + + If isAlmacenistaGluyas() Then + GvInv.Columns(10).Visible = True + 'Dim productos As New ClsProductosServicios + 'If productos.GetPS(-1, -1, UsuarioActual.CveEmpresa) Then + ' PSDTRemplazo = productos.DtResultados.FiltraParametros("PendienteEnOC=1", "PS") + 'End If + 'productos.Dispose() + End If + + PermisoEdicionManual = False + CveMovimientoAlmacen = 0 + SetValues() + ArrAnticipos = New ArrayList() + ArrIE = New ArrayList() + ArrIEFuncionariosEmpleados = New ArrayList() + ClavesBorradas = New ArrayList() + TxtFecha.Text = Now.ToShortDateString + TxtFechaEjecucion.Text = Now.ToShortDateString + ViewState("CveCompra") = "0" + ViewState("CveFactura") = "0" + ViewState("IdPoliza") = "0" + ViewState("CveCompra") = -1 + ViewState("EjercicioAC") = -1 + ViewState("CveTipoProveedor") = -1 + CveCompraRefacturacion = -1 + ModalidadUMAlias = -1 + CvePrePoliza = -1 + TabActivosFijos.Enabled = UsuarioActual.Empresa.UsaAF + + TieneOC = False + CveMoneda = -1 + + '[IPP] Eliminar 22Junio2018 + 'If UsuarioActual.Empresa.UsaInventarios Then + ' TabAlmacen.Enabled = Not UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 + 'End If + + ImgAnticiposPendientes.Attributes.Add("OnClick", "MuestraAnticipos();") + 'ImgCerrar.Attributes.Add("OnClick", "$('#DivAnticipos').hide(200);") + 'BtnCancelar.Attributes.Add("OnClick", "$('#DivAddEq').hide();") + ' ImageButton1.Attributes.Add("OnClick", "$('#DivAlmacen').hide();") + ImgClose.Attributes.Add("OnClick", "$('#DivAlmacen').hide();") + ImgAdd.Attributes.Add("OnClick", "$('#DivAlmacen').hide();") + 'LbTotalPorDevengar.Attributes.Add("OnInnerTextChanged", "TotalDevendar();") + 'Mensaje temporalca + + RBLPago.Visible = True + If UsuarioActual.Empresa.UsaAC Then RBLPago.Items.RemoveAt(2) 'Elimina Reembolso cuando es AC + + + If UsuarioActual.Empresa.UsaAC Then + TrReembolso.Visible = True + GvPS.Columns(1).Visible = True + TxtFecha.Attributes.Add("onblur", "CambiaFecha();") + End If + + TxtOC.Attributes.Add("onkeypress", "fncBuscaOC(event);") + + 'If UsuarioActual.Empresa.GralSoloProyecto Then + + ' LitHProyecto.Text = "Sucursal" + ' DdlSubProyecto.Items.Clear() + ' DdlSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) + ' DdlSubProyecto.DataBind() + ' DdlSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) + + ' DdlAsignaSubProyecto.Items.Clear() + ' DdlAsignaSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) + ' DdlAsignaSubProyecto.DataBind() + ' DdlAsignaSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) + + ' divproyecto.Visible = False + ' divasignaproyecto.Visible = False + ' DdlProyecto.Visible = False + ' DdlProyecto.Items(0).Text = "" + + 'End If + + If UsuarioActual.CveEmpresa = 66 And UsuarioActual.TienePermisoProceso(96) Then + ChkProgramarPago.Visible = True + End If + + + 'CARGA PERSONAL + Dim ObjPersonal As New ClsRH + ObjPersonal.GetPersonal(-1, UsuarioActual.CveEmpresa) + DdlPersonal.DataSource = ObjPersonal.DtResultados + DdlPersonalReembolso.DataSource = ObjPersonal.DtResultados + ObjPersonal.Dispose() + DdlPersonal.DataBind() + DdlPersonalReembolso.DataBind() + + + 'Carga Proveedor + If Request("CveProveedor") IsNot Nothing AndAlso IsNumeric(Request("CveProveedor")) AndAlso Request("CveProveedor").ToEntero > 0 Then + ViewState("CveProveedor") = Request("CveProveedor") + HdnCveProveedor.Value = Request("CveProveedor") + CargaProveedor(CveProveedor, "-1") + GvInv.Visible = True + ElseIf Request("CveFactura") IsNot Nothing AndAlso IsNumeric(Request("CveFactura")) AndAlso Request("CveFactura").ToEntero > 0 Then + ViewState("CveFactura") = Request("CveFactura").ToEntero + + Dim RFC As String = CargaFactura(CveFactura) + DdlProveedor.Visible = False + HplProveedor.Visible = True + GvInv.Visible = True + CargaProveedor(-1, RFC) + + If Not DdlTipoComprobante.SelectedValue = "NC" Then + If UsuarioActual.Empresa.Funcionalidad(128) = "1" And Not UsuarioActual.TienePermisoProceso(213) Then + If TmpDT.MAX("CvePS").ToEntero > 0 Then + BtnGuardar.Enabled = False + RegistraScript("$('#ImgBtnBuscarOC').click()") + End If + End If + End If + + If DdlTipoComprobante.SelectedValue = "NC" Then + paneldevolucion.Visible = True + Pnlalmaceninventarios.Visible = False + cargaddldevoluciones(CveProveedor, TxtSubTotal.Text.ToDouble) + InicializaAplicaNCFact() + DivReembolso.Visible = False + RBLPago.Items(2).Enabled = False + + End If + + + + If UsuarioActual.Empresa.UsaAC Then + CambiaEjercicioAC() + End If + + ' ''Fecha limite para ingreso de facturas + ''Dim DtEmpresa As DataTable = GlobalDTEmpresas(UsuarioActual.CveEmpresa) + ''If DtEmpresa.Rows.Count > 0 Then + '' Dim FechaLimite = DateSerial(DtEmpresa.Rows(0)("EjercicioActual").ToString.ToEntero, DtEmpresa.Rows(0)("PeriodoActual").ToString.ToEntero, DtEmpresa.Rows(0)("DiasPermitidos").ToString.ToEntero) + '' If Month(TxtFecha.Text.ToDate) < (Month(FechaLimite) - 1) Or (Month(TxtFecha.Text.ToDate) = (Month(FechaLimite) - 1) And Day(Date.Now) > Day(FechaLimite)) Then + '' Alert("La factura actual ya no aplica para ingresarse al sístema.", TipoMensaje.MsgAdvertencia) + '' BtnGuardar.Enabled = False + '' Else + '' Alert("En tiempo") + '' End If + ''Else + '' Alert("No se pudieron cargar los datos de la empresa", TipoMensaje.MsgAdvertencia) + ''End If + 'Carga Compra + + If UsuarioActual.Empresa.Funcionalidad(123).ToEntero > 0 And Not UsuarioActual.TienePermisoProceso(156) Then + If Not ValidaCierrePeriodo() Then + Alert("El periodo de la compra actual ya se encuentra cerrado. No podra registrar la compra.", TipoMensaje.MsgAdvertencia) + BtnGuardar.Visible = False + TxtOC.Enabled = False + ImgBtnBuscarOC.Enabled = False + CierrePeriodo = True + DivRestriccionAdvertencia.Visible = True + LtRestriccionAdvertencia.Text = "El periodo de la compra actual ya se encuentra cerrado." + End If + End If + + Dim HayDifIEPS As Boolean = False + For Each Gvr As GridViewRow In GvPS.Rows + If Gvr.DataKey("CvePS").ToEntero > 0 AndAlso Gvr.DataKey("IEPSPSPorcentaje").ToDouble > 0 Then + If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=Gvr.DataKey("CvePS").ToEntero).Rows.Count > 0 Then + Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=Gvr.DataKey("CvePS").ToEntero).Rows(0) + If DrPS IsNot Nothing Then + If DrPS("IEPSPorcentaje").ToString.ToDouble <> Gvr.DataKey("IEPSPSPorcentaje").ToDouble Then + HayDifIEPS = True + End If + End If + End If + End If + Next + + If HayDifIEPS Then Alert("El porcentaje de IEPS del producto no coincide con el especificado.", TipoMensaje.MsgAdvertencia) + + If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then CargaGastosServicios(UsuarioActual.Empresa.Funcionalidad(562).ToEntero) + + ElseIf Request("CveCompra") IsNot Nothing AndAlso IsNumeric(Request("CveCompra")) AndAlso Request("CveCompra").ToEntero > 0 Then + + ViewState("CveCompra") = Request("CveCompra") + CargaCompra() + BtnGuardar.Enabled = False + 'TdIVA.Visible = True + 'DdlIVA.Enabled = False + CargaGvBitacora() + InventarioMov() + HabilitaNCInv() + DivConsignaciones.Visible = False + + ' 2018/05/25 - Muestra Boton Agregar Guia + LnkAgregarGuia.Visible = True + UpLnkPaqueteriaGuias.Update() + DivEsNoDeducible.Visible = True + DivActualizarVincular.Visible = True + + Else + + ViewState("CveProveedor") = -1 + HdnCveProveedor.Value = "-1" + DdlProveedor.Items.Insert(0, New ListItem("Seleccione el Proveedor", "-1")) + GvInv.Visible = True + 'TdIVA.Visible = True + 'cuando es nuevo + TxtSubTotal2.Attributes.Add("onkeyup", "ActIVA();") + TxtIVA.Attributes.Add("onkeyup", "ActTotal();") + If UsuarioActual.Empresa.UsaAC Then ChkACGeneral.Checked = False ' codigo que se usa para que al agregar una compra manual, al cambiar el filtro del presupuestos afecte a lo capturado + + If UsuarioActual.Empresa.UsaAC Then + CambiaEjercicioAC() + End If + UpConsignaciones.Update() + UpINV.Update() + 'DdlIVA.Visible = True ' cuando es compra manual + If UsuarioActual.CveEmpresa = 126 Then + CargaOrdenCorte() + LnkAddOtrosGastos.Visible = True + UpnTools.Update() + End If + LnkAgregarGuia.Visible = False + UpLnkPaqueteriaGuias.Update() + End If + + 'SI ES UNA COMPRA NUEVA SE PONE EL TOTAL, SI NO EL SALDO LblSaldoFactura.Text = If(CveCompra > 0, Saldo.FormatoNumero, TxtTotal.Text.FormatoNumero) 'cuando es factura con amortizacion, el importe a descontar es el saldo que se debe de aplicar para la amortizacion - If ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 Then - LblSaldoFactura.Text = TmpDT.SUMD("Descuento").ToString - End If - - If UsuarioActual.CveEmpresa = 126 And CveCompra > 0 Then - LnkExportaGv.Visible = True - End If - - 'Condiciones de la Compra - Dim dt As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario) - dt = dt.FiltraParametros(String.Format("CveTipoCuenta = 1")) - - DdlCajaChica.DataSource = dt - DdlCajaChica.DataBind() - DdlCuentaCajaChicaReembolso.DataSource = dt - DdlCuentaCajaChicaReembolso.DataBind() - - ViewState("CveCajaChica") = -1 - ViewState("CvePersonal") = -1 - - CargaTipoTransaccion() - CargaCuentas() - - 'If CveFactura > 0 AndAlso UsuarioActual.Empresa.UsaAC Then - ' CompruebaAgregar() - 'End If - - - 'VALIDA REQUIERE CENTRO COSTOS - If UsuarioActual.Empresa.RequiereCentroCostos Then - 'RFVSubProyecto.Enabled = True - End If - - - 'VALIDA Usuario TIPO REMESA - If UsuarioActual.TienePermisoProceso(108) Then - RBLPago.Enabled = False - - 'VALIDA FECHAPAGO PARA USUARIO TIPO REMESA - If UsuarioActual.TienePermisoProceso(109) Then - TxtFechaPago.Enabled = False - End If - - End If - - 'Valida Proceso 115 para ALMACENISTA - If UsuarioActual.TienePermisoProceso(115) Then - TxtFechaPago.Enabled = False - ChkAplicaNotaCredito.Enabled = False - RBLPago.Enabled = False - BtnGuardar.Enabled = False - BtnGuardar.ToolTip = "Obliga a seleccionar una Orden de compra para su registro." - End If - - - - 'Valida Proceso 119 para ROL Administrador de obra - Bloquea Contado - If UsuarioActual.TienePermisoProceso(119) Then - RBLPago.Items(1).Enabled = False - End If - - 'VALIDA REFACTURACION - ValidaRefacturacion() - If UsuarioActual.TienePermisoProceso(118) Then - RBLPago.Enabled = True - RBLPago.Items(1).Enabled = False - End If - - 'Cargamos los Fletes - ValidaFletesServicios() - If CveCompra > 0 Then - CargaFletesAgregados() - End If - - InicializaOC() - - 'Valida si el IVA del XML es está bien calculado - ValidaIVA() - - If UsuarioActual.TienePermisoProceso(196) Then - BtnRegenerarPrePolizaAlmacen.Visible = True - UpFacturar.Update() - End If - - If CompraCargada AndAlso Request("ADRegenerarPPD") IsNot Nothing AndAlso IsNumeric(Request("ADRegenerarPPD")) AndAlso Request("ADRegenerarPPD").ToEntero = 15062017 Then - RegeneraPrePoliza() - End If - - CargaFletes() - - - If UsuarioActual.Empresa.CvePlataforma = 2 Then - TabActivosFijos.Visible = False - VerRefacturacion.Visible = False - liServicios.Visible = False - DivConsignaciones.Visible = False - End If - - If UsuarioActual.Empresa.Tipo_CentroCosto = 2 Then - LitHProyecto.Text = "Proyecto" - LthProyectoP.Text = "Proyecto" - - LblSubProyectoHeader.Text = "" - LblSubProyectoPHeader.Text = "" - - LblSubProyecto.InnerText = "Proyecto" - 'LblSubProyectoDivAplica.InnerText = "Proyecto" - - DdlSubProyecto.Items.Clear() - 'DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1) - DdlSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) - DdlSubProyecto.DataBind() - DdlSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) - - 'DdlAsignaSubProyecto.Items.Clear() - 'DdlAsignaSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) - 'DdlAsignaSubProyecto.DataBind() - 'DdlAsignaSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) - - divproyecto.Visible = False - 'divasignaproyecto.Visible = False - DdlProyecto.Visible = False - DdlProyecto.Items(0).Text = "" - - ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 1 Then - LitHProyecto.Text = "Sucursal" - LthProyectoP.Text = "Sucursal" - - LblSubProyectoHeader.Text = "" - LblSubProyectoPHeader.Text = "" - - LblSubProyecto.InnerText = "Sucursal" - 'LblSubProyectoDivAplica.InnerText = "Sucursal" - - DdlSubProyecto.Items.Clear() - 'DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1) - DdlSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) - DdlSubProyecto.DataBind() - DdlSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) - - 'DdlAsignaSubProyecto.Items.Clear() - 'DdlAsignaSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) - 'DdlAsignaSubProyecto.DataBind() - 'DdlAsignaSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) - - divproyecto.Visible = False - 'divasignaproyecto.Visible = False - DdlProyecto.Visible = False - DdlProyecto.Items(0).Text = "" - - ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 4 Then - LitHProyecto.Text = "Sucursal" - LthProyectoP.Text = "Sucursal" - - LblSubProyectoHeader.Text = "Proyecto" - LblSubProyectoPHeader.Text = "Proyecto" - - 'LblSubProyectoDivAplica.InnerText = "Sucursal" - 'LblProyectoDivAplica.InnerText = "Proyecto" - LblSubProyecto.InnerText = "Sucursal" - LblProyecto.InnerText = "Proyecto" - - ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 5 Then - LitHProyecto.Text = "Proyecto" - LthProyectoP.Text = "Proyecto" - - LblSubProyectoHeader.Text = "Sucursal" - LblSubProyectoPHeader.Text = "Sucursal" - - 'LblSubProyectoDivAplica.InnerText = "Proyecto" - 'LblProyectoDivAplica.InnerText = "Sucursal" - LblSubProyecto.InnerText = "Proyecto" - LblProyecto.InnerText = "Sucursal" - End If - - CargaGvPersonal() - CargaDdlPersonal() - - - InicializaDevolucionAlmacen() - HabilitaEdicionManualAgregar() - InicializaActualizarTC() - End If - - - 'SE OCUPAN AFUERA DEL POSTBACK ?? - cargaddlVinculacionServcios() - If UsuarioActual.TienePermisoProceso(117) Then - - HplAddClasificacion.Visible = False - ImgClasificacion.Visible = False + If ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 Then + LblSaldoFactura.Text = TmpDT.SUMD("Descuento").ToString + End If + + If UsuarioActual.CveEmpresa = 126 And CveCompra > 0 Then + LnkExportaGv.Visible = True + End If + + 'Condiciones de la Compra + Dim dt As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario) + dt = dt.FiltraParametros(String.Format("CveTipoCuenta = 1")) + + DdlCajaChica.DataSource = dt + DdlCajaChica.DataBind() + DdlCuentaCajaChicaReembolso.DataSource = dt + DdlCuentaCajaChicaReembolso.DataBind() + + ViewState("CveCajaChica") = -1 + ViewState("CvePersonal") = -1 + + CargaTipoTransaccion() + CargaCuentas() + + 'If CveFactura > 0 AndAlso UsuarioActual.Empresa.UsaAC Then + ' CompruebaAgregar() + 'End If + + + 'VALIDA REQUIERE CENTRO COSTOS + If UsuarioActual.Empresa.RequiereCentroCostos Then + 'RFVSubProyecto.Enabled = True + End If + + + 'VALIDA Usuario TIPO REMESA + If UsuarioActual.TienePermisoProceso(108) Then + RBLPago.Enabled = False + + 'VALIDA FECHAPAGO PARA USUARIO TIPO REMESA + If UsuarioActual.TienePermisoProceso(109) Then + TxtFechaPago.Enabled = False + End If + + End If + + 'Valida Proceso 115 para ALMACENISTA + If UsuarioActual.TienePermisoProceso(115) Then + TxtFechaPago.Enabled = False + ChkAplicaNotaCredito.Enabled = False + RBLPago.Enabled = False + BtnGuardar.Enabled = False + BtnGuardar.ToolTip = "Obliga a seleccionar una Orden de compra para su registro." + End If + + + + 'Valida Proceso 119 para ROL Administrador de obra - Bloquea Contado + If UsuarioActual.TienePermisoProceso(119) Then + RBLPago.Items(1).Enabled = False + End If + + 'VALIDA REFACTURACION + ValidaRefacturacion() + If UsuarioActual.TienePermisoProceso(118) Then + RBLPago.Enabled = True + RBLPago.Items(1).Enabled = False + End If + + 'Cargamos los Fletes + ValidaFletesServicios() + If CveCompra > 0 Then + CargaFletesAgregados() + End If + + InicializaOC() + + 'Valida si el IVA del XML es está bien calculado + ValidaIVA() + + If UsuarioActual.TienePermisoProceso(196) Then + BtnRegenerarPrePolizaAlmacen.Visible = True + UpFacturar.Update() + End If + + If CompraCargada AndAlso Request("ADRegenerarPPD") IsNot Nothing AndAlso IsNumeric(Request("ADRegenerarPPD")) AndAlso Request("ADRegenerarPPD").ToEntero = 15062017 Then + RegeneraPrePoliza() + End If + + CargaFletes() + + + If UsuarioActual.Empresa.CvePlataforma = 2 Then + TabActivosFijos.Visible = False + VerRefacturacion.Visible = False + liServicios.Visible = False + DivConsignaciones.Visible = False + End If + + If UsuarioActual.Empresa.Tipo_CentroCosto = 2 Then + LitHProyecto.Text = "Proyecto" + LthProyectoP.Text = "Proyecto" + + LblSubProyectoHeader.Text = "" + LblSubProyectoPHeader.Text = "" + + LblSubProyecto.InnerText = "Proyecto" + 'LblSubProyectoDivAplica.InnerText = "Proyecto" + + DdlSubProyecto.Items.Clear() + 'DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1) + DdlSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) + DdlSubProyecto.DataBind() + DdlSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) + + 'DdlAsignaSubProyecto.Items.Clear() + 'DdlAsignaSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) + 'DdlAsignaSubProyecto.DataBind() + 'DdlAsignaSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) + + divproyecto.Visible = False + 'divasignaproyecto.Visible = False + DdlProyecto.Visible = False + DdlProyecto.Items(0).Text = "" + + ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 1 Then + LitHProyecto.Text = "Sucursal" + LthProyectoP.Text = "Sucursal" + + LblSubProyectoHeader.Text = "" + LblSubProyectoPHeader.Text = "" + + LblSubProyecto.InnerText = "Sucursal" + 'LblSubProyectoDivAplica.InnerText = "Sucursal" + + DdlSubProyecto.Items.Clear() + 'DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1) + DdlSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) + DdlSubProyecto.DataBind() + DdlSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) + + 'DdlAsignaSubProyecto.Items.Clear() + 'DdlAsignaSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) + 'DdlAsignaSubProyecto.DataBind() + 'DdlAsignaSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) + + divproyecto.Visible = False + 'divasignaproyecto.Visible = False + DdlProyecto.Visible = False + DdlProyecto.Items(0).Text = "" + + ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 4 Then + LitHProyecto.Text = "Sucursal" + LthProyectoP.Text = "Sucursal" + + LblSubProyectoHeader.Text = "Proyecto" + LblSubProyectoPHeader.Text = "Proyecto" + + 'LblSubProyectoDivAplica.InnerText = "Sucursal" + 'LblProyectoDivAplica.InnerText = "Proyecto" + LblSubProyecto.InnerText = "Sucursal" + LblProyecto.InnerText = "Proyecto" + + ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 5 Then + LitHProyecto.Text = "Proyecto" + LthProyectoP.Text = "Proyecto" + + LblSubProyectoHeader.Text = "Sucursal" + LblSubProyectoPHeader.Text = "Sucursal" + + 'LblSubProyectoDivAplica.InnerText = "Proyecto" + 'LblProyectoDivAplica.InnerText = "Sucursal" + LblSubProyecto.InnerText = "Proyecto" + LblProyecto.InnerText = "Sucursal" + End If + + CargaGvPersonal() + CargaDdlPersonal() + + + InicializaDevolucionAlmacen() + HabilitaEdicionManualAgregar() + InicializaActualizarTC() + End If + + + 'SE OCUPAN AFUERA DEL POSTBACK ?? + cargaddlVinculacionServcios() + If UsuarioActual.TienePermisoProceso(117) Then + + HplAddClasificacion.Visible = False + ImgClasificacion.Visible = False End If 'If CargoFactura Then @@ -1625,64 +1625,64 @@ Partial Class Compras_Compras 'RegistraScript("ScrollVentanaAddProducto();") End Sub -#Region "C A R G A S" - Private Sub CargaOrdenCorte() - Dim ObjCGame As New ClsCGame() - If ObjCGame.GetOrdenCorte(UsuarioActual.CveEmpresa) Then - DdlOrdenCorte.DataSource = ObjCGame.DtResultados.FiltraParametros("Disponible = 1") - DdlOrdenCorte.Items.Insert(0, New ListItem("No vincular", "-1")) - End If - ObjCGame.Dispose() - DdlOrdenCorte.DataBind() - UpOtrosGastos.Update() - End Sub - - Private Sub CargaDdlTipoGasto() - DdlTipoGasto.DataSource = GlobalDTTiposGastos(UsuarioActual.CveEmpresa) - DdlTipoGasto.DataBind() - DdlTipoGastoAsignar.DataSource = GlobalDTTiposGastos(UsuarioActual.CveEmpresa) - DdlTipoGastoAsignar.DataBind() - UpParametros.Update() - End Sub - - Private Sub CargaGvAcarreos(tCveProveedor As Integer) - Dim ObjAcar As New ClsAcarreos - If ObjAcar.GetPreEstimacion(tCveProveedor, UsuarioActual.CveEmpresa, -1) Then - GvAcarreo.DataSource = ObjAcar.DtResultados - If ObjAcar.DtResultados.Rows.Count > 0 Then - LnkAcarreo.Visible = True - End If - End If - ObjAcar.Dispose() - UpAddAcarreo.Update() - GvAcarreo.DataBind() - End Sub - - Private Sub ValidaIVA() - If Version <> "3.3" And CveCompra <= 0 Then - Dim ImporteIVAXML As Double = (TxtSubTotal.Text.Trim.ToDouble - TxtDescuento.Text.Trim.ToDouble - TxtIEPS.Text.Trim.ToDouble) * 0.16 - If Math.Abs(TxtIVA.Text.Trim.ToDouble - ImporteIVAXML) >= 1 Then - Alert("El IVA del CFDi no tiene un comportamiento normal, por favor verifique que sea correcto.

NOTA: Esta advertencia no aplica en casos de conceptos(alimentos, combustibles o servicios de comunicación) exentos de IVA o causantes de IEPS.", TipoMensaje.MsgAdvertencia) - End If - End If - End Sub - - Private Function isAlmacenistaGluyas() As Boolean - 'Return (UsuarioActual.CveRol = 1052 And UsuarioActual.CveEmpresa = 66) - Return False - End Function - - Private Function CargaFactura(CveFactura As Integer) As String - Dim ObjeFacturas As New ClsCompras - Dim RFC As String = "" - If ObjeFacturas.GetFacturas(CveFactura, "-1", Now.AddYears(-3), Now, "-1", "-1", -1, -1, -1, -1, "-1", UsuarioActual.CveEmpresa) AndAlso ObjeFacturas.DtResultados.Rows.Count > 0 Then - Dim dr As DataRow = ObjeFacturas.DtResultados.Rows(0) ' no toma la cero, porque es el totalizador - - Dim XMLDoc As New XmlDocument - Dim Archivo As String = String.Format("{0}Empresas\{1}\Compras\{2}\{3}", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa, dr("RFCDe"), dr("XML")) - If IO.File.Exists(Archivo) Then - - Dim Validada As Boolean = True +#Region "C A R G A S" + Private Sub CargaOrdenCorte() + Dim ObjCGame As New ClsCGame() + If ObjCGame.GetOrdenCorte(UsuarioActual.CveEmpresa) Then + DdlOrdenCorte.DataSource = ObjCGame.DtResultados.FiltraParametros("Disponible = 1") + DdlOrdenCorte.Items.Insert(0, New ListItem("No vincular", "-1")) + End If + ObjCGame.Dispose() + DdlOrdenCorte.DataBind() + UpOtrosGastos.Update() + End Sub + + Private Sub CargaDdlTipoGasto() + DdlTipoGasto.DataSource = GlobalDTTiposGastos(UsuarioActual.CveEmpresa) + DdlTipoGasto.DataBind() + DdlTipoGastoAsignar.DataSource = GlobalDTTiposGastos(UsuarioActual.CveEmpresa) + DdlTipoGastoAsignar.DataBind() + UpParametros.Update() + End Sub + + Private Sub CargaGvAcarreos(tCveProveedor As Integer) + Dim ObjAcar As New ClsAcarreos + If ObjAcar.GetPreEstimacion(tCveProveedor, UsuarioActual.CveEmpresa, -1) Then + GvAcarreo.DataSource = ObjAcar.DtResultados + If ObjAcar.DtResultados.Rows.Count > 0 Then + LnkAcarreo.Visible = True + End If + End If + ObjAcar.Dispose() + UpAddAcarreo.Update() + GvAcarreo.DataBind() + End Sub + + Private Sub ValidaIVA() + If Version <> "3.3" And CveCompra <= 0 Then + Dim ImporteIVAXML As Double = (TxtSubTotal.Text.Trim.ToDouble - TxtDescuento.Text.Trim.ToDouble - TxtIEPS.Text.Trim.ToDouble) * 0.16 + If Math.Abs(TxtIVA.Text.Trim.ToDouble - ImporteIVAXML) >= 1 Then + Alert("El IVA del CFDi no tiene un comportamiento normal, por favor verifique que sea correcto.

NOTA: Esta advertencia no aplica en casos de conceptos(alimentos, combustibles o servicios de comunicación) exentos de IVA o causantes de IEPS.", TipoMensaje.MsgAdvertencia) + End If + End If + End Sub + + Private Function isAlmacenistaGluyas() As Boolean + 'Return (UsuarioActual.CveRol = 1052 And UsuarioActual.CveEmpresa = 66) + Return False + End Function + + Private Function CargaFactura(CveFactura As Integer) As String + Dim ObjeFacturas As New ClsCompras + Dim RFC As String = "" + If ObjeFacturas.GetFacturas(CveFactura, "-1", Now.AddYears(-3), Now, "-1", "-1", -1, -1, -1, -1, "-1", UsuarioActual.CveEmpresa) AndAlso ObjeFacturas.DtResultados.Rows.Count > 0 Then + Dim dr As DataRow = ObjeFacturas.DtResultados.Rows(0) ' no toma la cero, porque es el totalizador + + Dim XMLDoc As New XmlDocument + Dim Archivo As String = String.Format("{0}Empresas\{1}\Compras\{2}\{3}", AppDomain.CurrentDomain.BaseDirectory, UsuarioActual.CveEmpresa, dr("RFCDe"), dr("XML")) + If IO.File.Exists(Archivo) Then + + Dim Validada As Boolean = True If Not UsuarioActual.Empresa.Funcionalidad(529) = "1" Then 'verificacion doble, si no la han cancelado, ya tiene una validaci[on para que llegue aqui @@ -1705,145 +1705,145 @@ Partial Class Compras_Compras Alert($"Los servicios de validacion del SAT presentan lentitud en la respuesta [{ SegundosRespuesta } s].", TipoMensaje.ToastError, "", 0) End If - If UsuarioActual.CveEmpresa < 2 Then - Valida.EsValida = 1 - End If - - If Valida.EsValida > 0 Then - If Valida.EsValida = 2 Then - Validada = False - - If ObjeFacturas.UpdateEstatus(Valida.EsValida, CveFactura) Then - - End If - - Alert("La factura está cancelada ante el SAT.", TipoMensaje.MsgError) - Else ' cuando es valor =1, es vigente - Validada = True - 'solicitud de activacion de facturas - 'If UsuarioActual.CveEmpresa = 66 Then Alert("Se deshabilitado la validación ante el SAT.
Pero el Sistema validación del SAT esta funcionando. ") - End If - - Else - 'no se pudo validar, pero ya tuvo la primera vuelta de validacion - Validada = True - End If - 'Valida.Dispose() - End If - - UpPSS.Update() - - - If Validada Then - - - - Try - - XMLDoc.Load(Archivo) - Catch ex As Exception - - Dim oReader = New StreamReader(Archivo, Encoding.GetEncoding("ISO-8859-1")) - XMLDoc.Load(oReader) - oReader.Dispose() - - End Try - - - CreaDTConceptos() - - CargaComprobanteXML(XMLDoc) - - If NuevaValidacionXML = 1 Or Version = "3.3" Then - Dim Xml As New StringBuilder - Dim nodo As XmlNode = XMLDoc.DocumentElement - Dim Version = ValorXML(nodo, "version") - Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix) - Dim cfdVer As String = "http://www.sat.gob.mx/cfd/3" - Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable) - - If Prefijo.ToLower <> "cfdi" Then cfdVer = "http://www.sat.gob.mx/cfd/2" - namespaces.AddNamespace(Prefijo, cfdVer) - namespaces.AddNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital") - namespaces.AddNamespace("implocal", "http://www.sat.gob.mx/implocal") - namespaces.AddNamespace("registrofiscal", "http://www.sat.gob.mx/registrofiscal") - - Dim nodeconceptos As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Conceptos", Prefijo), namespaces) - - Xml.Append(Replace(Replace(Replace(nodeconceptos.OuterXml, " 0 Then + If Valida.EsValida = 2 Then + Validada = False + + If ObjeFacturas.UpdateEstatus(Valida.EsValida, CveFactura) Then + + End If + + Alert("La factura está cancelada ante el SAT.", TipoMensaje.MsgError) + Else ' cuando es valor =1, es vigente + Validada = True + 'solicitud de activacion de facturas + 'If UsuarioActual.CveEmpresa = 66 Then Alert("Se deshabilitado la validación ante el SAT.
Pero el Sistema validación del SAT esta funcionando. ") + End If + + Else + 'no se pudo validar, pero ya tuvo la primera vuelta de validacion + Validada = True + End If + 'Valida.Dispose() + End If + + UpPSS.Update() + + + If Validada Then + + + + Try + + XMLDoc.Load(Archivo) + Catch ex As Exception + + Dim oReader = New StreamReader(Archivo, Encoding.GetEncoding("ISO-8859-1")) + XMLDoc.Load(oReader) + oReader.Dispose() + + End Try + + + CreaDTConceptos() + + CargaComprobanteXML(XMLDoc) + + If NuevaValidacionXML = 1 Or Version = "3.3" Then + Dim Xml As New StringBuilder + Dim nodo As XmlNode = XMLDoc.DocumentElement + Dim Version = ValorXML(nodo, "version") + Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix) + Dim cfdVer As String = "http://www.sat.gob.mx/cfd/3" + Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable) + + If Prefijo.ToLower <> "cfdi" Then cfdVer = "http://www.sat.gob.mx/cfd/2" + namespaces.AddNamespace(Prefijo, cfdVer) + namespaces.AddNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital") + namespaces.AddNamespace("implocal", "http://www.sat.gob.mx/implocal") + namespaces.AddNamespace("registrofiscal", "http://www.sat.gob.mx/registrofiscal") + + Dim nodeconceptos As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Conceptos", Prefijo), namespaces) + + Xml.Append(Replace(Replace(Replace(nodeconceptos.OuterXml, " 0 And UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero > 0 Then - AgregarConceptoIEPS(TrasladoIEPS, UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero) - ' TrasladoIEPS = 0 - End If - - 'AGREGA IEPS COMO IMPORTE GENERAL - 'If TrasladoIEPS > 0 And Not UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero > 0 Then - ' IEPS = TrasladoIEPS - 'End If - - 'en otro impuesto lo esta registrando en ajuste en automatico - If OtrosImpuestos > 0 Then - AjustaUltimoConcepto = True - End If - - If RFC = "CFE370814QI0" Then ' RFC de CFE, se hace un ajuste por diferencia para sacar el DAP - 'OtrosImpuestos = Total - (SubTotal2 + IVA) - 'este importe lo vamos a meter al gasto - 'AjustaImporteUltimoConcepto(OtrosImpuestos) - OtrosImpuestos = 1 - AjustaUltimoConcepto = True - 'SubTotal2 = SubTotal - End If - - Dim SubTotalReal As Decimal = 0 - - - SubTotalReal = Math.Round(Total + RetencionISR + RetencionIVA - IVA + Descuentos - TrasladoIEPS, 2) ' NO se incluye otros impuestos para ajustar esa cifra - - Dim DiferenciaTotales As Decimal = SubTotalReal - Math.Round(SubTotalConceptos, 2) - - - If DiferenciaTotales <> 0 Then - 'Verificamos IEPS y Otros Impuestos - 'restricccion general, que si el subtotal de los conceptos no cuadra con Total + RetISR + RetIVA - IVA <> SubTotalConeptos, ajuste al final - If TrasladoIEPS > 0 OrElse OtrosImpuestos > 0 OrElse Math.Abs(DiferenciaTotales) < 1 Then - - 'Condicion necesaria cuando hay IVA pero no hay diferencia - If DiferenciaTotales <> 0 Then - - If DiferenciaTotales < 50 OrElse AjustaUltimoConcepto = True Then - Dim IA As Decimal = Total + RetencionISR + RetencionIVA - IVA - SubTotalConceptos - TrasladoIEPS + Descuentos - AjustaImporteUltimoConcepto(IA, True) - - ElseIf DiferenciaTotales > 50 Then - PnlAjusteProductos.Visible = True - Dim Porcentaje As Double = Math.Round((SubTotalConceptos - SubTotalReal) / SubTotalConceptos * 100, 2) - TxtAjustePorcentaje.Text = Porcentaje.FormatoNumero - Msg &= String.Format("La Factura presenta anomalias en los importes mostrados, estas anomalias impiden que se editen las partidas. Por favor realice el ajuste correspondiente
") - ImgBtnBuscarOC.Visible = False : TxtOC.Enabled = False - - 'Ocultamos la opcion de Editar y Eliminar hasta que se arreglen las anomalias - For Each Row As GridViewRow In GvPS.Rows - Row.FCLinkButton("imgE").Visible = False - Row.FCLinkButton("imgD").Visible = False - Next - - End If - - End If - TrasladoIEPS = 0 : OtrosImpuestos = 0 : SubTotal2 = SubTotal - - Else - PnlAjusteProductos.Visible = True - Dim Porcentaje As Double = If(SubTotalConceptos > 0, Math.Round((SubTotalConceptos - SubTotalReal) / SubTotalConceptos * 100, 2), 0) - TxtAjustePorcentaje.Text = Porcentaje.FormatoNumero - Msg &= String.Format("La Factura presenta anomalias en los importes mostrados, estas anomalias impiden que se editen las partidas. Por favor realice el ajuste correspondiente
") - ImgBtnBuscarOC.Visible = False : TxtOC.Enabled = False - - 'Ocultamos la opcion de Editar y Eliminar hasta que se arreglen las anomalias - For Each Row As GridViewRow In GvPS.Rows - Row.FCLinkButton("imgE").Visible = False - Row.FCLinkButton("imgD").Visible = False - Next - End If - End If - - - 'Si no hay diferencias pero tenemos descuento, se ofrece la opcion para ajustar el gasto - If Descuentos > 0 Then - - '[IPP] PARCHE: Factura TELMEX para APH 12/ENERO/2018 - If CveFactura = 286290 Then - - Else - PnlAjusteProductos.Visible = True - Dim Porcentaje As Double = Math.Round((Descuentos) / (SubTotalConceptos) * 100, 4) - TxtAjustePorcentaje.Text = Porcentaje.FormatoNumero(4) - Msg &= String.Format("La Factura presenta anomalias en los importes mostrados, estas anomalias impiden que se editen las partidas. Por favor realice el ajuste correspondiente
") - ImgBtnBuscarOC.Visible = False : TxtOC.Enabled = False - - 'Ocultamos la opcion de Editar y Eliminar hasta que se arreglen las anomalias - For Each Row As GridViewRow In GvPS.Rows - Row.FCLinkButton("imgE").Visible = False - Row.FCLinkButton("imgD").Visible = False - Next - End If - - End If - - - SubTotal2 = SubTotalReal - Descuentos - - If Descuentos > 0 Then - TrDescuento.Visible = True - End If - - If Msg <> "" Then - Alert(Msg, TipoMensaje.MsgAdvertencia) - BtnGuardar.Enabled = False - End If - - 'AJUSTAMOS SUBTOTAL EN CASO DE SER DIFERENTE AL SUBTOTAL2 DEL XML (TOTAL - IVA) - If SubTotal2 <> SubTotal Then - SubTotal = SubTotalConceptos - End If - - TxtSubTotal.Text = SubTotal.FormatoNumero - TxtDescuento.Text = Descuentos.FormatoNumero - TxtSubTotal2.Text = SubTotal2.FormatoNumero - TxtIVA.Text = IVA.FormatoNumero - TxtTotal.Text = Total.ToString.FormatoNumero - - HfTotalCompra.Value = Total.ToString - CompraSaldo = Total - - CalculaTotalPorDevengar() - TxtDocumentoImporteFE.Text = Total.ToString - RVDocumentoImporte.MaximumValue = Math.Round(Total, 2).ToString - RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue - RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue - TxtDocumentoImporte.Text = Total.FormatoNumero - TxtDocumentoImporteCaja.Text = Total.FormatoNumero - TxtRetIVA.Text = RetencionIVA.FormatoNumero - TxtRetISR.Text = RetencionISR.FormatoNumero - TxtIEPS.Text = IEPS.FormatoNumero - If IEPS > 0 Then TrIEPS.Visible = True - If RetencionIVA > 0 Then TrRetIVA.Visible = True - If RetencionISR > 0 Then TrRetISR.Visible = True - TxtOtrosImpuestos.Text = OtrosImpuestos.FormatoNumero - If OtrosImpuestos > 0 Then TrOtrosImpuestos.Visible = True - - HFDiferenciaCompra.Value = TxtTotal.Text - - - LblRetIVA.Text = (If(SubTotal2 > 0, (RetencionIVA / SubTotal2), 0) * 100).FormatoNumero(3) + "%" - LblRetISR.Text = (If(SubTotal2 > 0, (RetencionISR / SubTotal2), 0) * 100).FormatoNumero(3) - - - 'ASIGNA VALORES ORIGINALES PARA GUARDAR - AsignaValoresOriginales(SubTotal, SubTotal2, IVA, RetencionIVA, RetencionISR, Total) - - End If - - - TxtFechaPago.Text = (TxtFecha.Text.ToDate.AddDays(LblDiasCredito.Text.ToEntero)).ToShortDateString - - Dim drMon As DataRow = GlobalDTMonedas.FiltroPrimero(String.Format(" (Abreviatura LIKE '%{0}%' OR Moneda LIKE '%{0}%' )", Moneda)) - If drMon IsNot Nothing Then - DdlMoneda.SelectedValue = drMon("CveMoneda").ToString - Else - 'sino busco en la tabla de alias - drMon = GlobalDTMonedasAlias.FiltroPrimero(String.Format("MonedaAlias LIKE '%{0}%' ", Moneda)) - - If drMon IsNot Nothing Then - DdlMoneda.SelectedValue = drMon("CveMoneda").ToString - Else - LblMoneda.Text = Moneda - LblMoneda.ForeColor = Drawing.Color.Red - End If - - End If - - If DdlMoneda.SelectedValue.ToEntero > 1 Then - If TipoCambio <= 10 Then - TipoCambio = GlobalTipoCambio(TxtFecha.Text.ToDate) - End If - - TxtFecha.Attributes.Remove("onblur") - If UsuarioActual.Empresa.UsaAC Then - TxtFecha.Attributes.Add("onblur", "CambiaFecha();CambiaFechaTC();") - Else - TxtFecha.Attributes.Add("onblur", "CambiaFechaTC();") - End If - - End If - - If TipoCambio > 0 And DdlMoneda.SelectedValue.ToEntero > 1 Then LblTC.Text = String.Format("TC: {0}", TipoCambio.ToString("N4")) - - 'DF - 10-04-17 - If UsuarioActual.TienePermisoProceso(187) Then - TxtSerie.Enabled = True - End If - - - End If - - Else - Alert("No se Encontró la Factura", TipoMensaje.MsgAdvertencia) - BtnGuardar.Visible = False - End If - - 'GvPS.DataSource = 'DTConceptos - 'GvPS.DataBind() - End If - - ObjeFacturas.Dispose() - - Dim ObjSAT As New ClsSAT - Dim RFCRequest As String = Request("RFC").ToString - If ObjSAT.GetListado69B(2, UsuarioActual.CveEmpresa, RFCRequest) Then - If ObjSAT.DtResultados.Rows.Count > 0 Then - Dim Estatus As String = ObjSAT.DtResultados.Rows(0)("Situacion").ToString - BtnGuardar.Enabled = False - UpParametros.Update() - - Alert($"El RFC del proveedor se encuentra en estado {Estatus} en el Listado EFOS (69B) del SAT", TipoMensaje.MsgAdvertencia) - System.Threading.Thread.Sleep(5) - End If - End If - ObjSAT.Dispose() - - - Return RFC - End Function - + End If + + Dim Msg As String = "" + + + If Version = "3.3" Then + + ValidacionesTotalesXml() + + Else + + 'PRUEBA + 'http://rm/Compras/Compras.aspx?CveFactura=122518 Emp: 48 + + 'tTotal = Math.Round(SubTotal2 + IVA - RetencionIVA - RetencionISR + IEPS + OtrosImpuestos, 2) + HdnCompraSaldo.Value = Total.ToString + CompraSaldo = Total + Dim AjustaUltimoConcepto = False + + 'AGREGA IEPS COMO CONCEPTO + If TrasladoIEPS > 0 And UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero > 0 Then + AgregarConceptoIEPS(TrasladoIEPS, UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero) + ' TrasladoIEPS = 0 + End If + + 'AGREGA IEPS COMO IMPORTE GENERAL + 'If TrasladoIEPS > 0 And Not UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero > 0 Then + ' IEPS = TrasladoIEPS + 'End If + + 'en otro impuesto lo esta registrando en ajuste en automatico + If OtrosImpuestos > 0 Then + AjustaUltimoConcepto = True + End If + + If RFC = "CFE370814QI0" Then ' RFC de CFE, se hace un ajuste por diferencia para sacar el DAP + 'OtrosImpuestos = Total - (SubTotal2 + IVA) + 'este importe lo vamos a meter al gasto + 'AjustaImporteUltimoConcepto(OtrosImpuestos) + OtrosImpuestos = 1 + AjustaUltimoConcepto = True + 'SubTotal2 = SubTotal + End If + + Dim SubTotalReal As Decimal = 0 + + + SubTotalReal = Math.Round(Total + RetencionISR + RetencionIVA - IVA + Descuentos - TrasladoIEPS, 2) ' NO se incluye otros impuestos para ajustar esa cifra + + Dim DiferenciaTotales As Decimal = SubTotalReal - Math.Round(SubTotalConceptos, 2) + + + If DiferenciaTotales <> 0 Then + 'Verificamos IEPS y Otros Impuestos + 'restricccion general, que si el subtotal de los conceptos no cuadra con Total + RetISR + RetIVA - IVA <> SubTotalConeptos, ajuste al final + If TrasladoIEPS > 0 OrElse OtrosImpuestos > 0 OrElse Math.Abs(DiferenciaTotales) < 1 Then + + 'Condicion necesaria cuando hay IVA pero no hay diferencia + If DiferenciaTotales <> 0 Then + + If DiferenciaTotales < 50 OrElse AjustaUltimoConcepto = True Then + Dim IA As Decimal = Total + RetencionISR + RetencionIVA - IVA - SubTotalConceptos - TrasladoIEPS + Descuentos + AjustaImporteUltimoConcepto(IA, True) + + ElseIf DiferenciaTotales > 50 Then + PnlAjusteProductos.Visible = True + Dim Porcentaje As Double = Math.Round((SubTotalConceptos - SubTotalReal) / SubTotalConceptos * 100, 2) + TxtAjustePorcentaje.Text = Porcentaje.FormatoNumero + Msg &= String.Format("La Factura presenta anomalias en los importes mostrados, estas anomalias impiden que se editen las partidas. Por favor realice el ajuste correspondiente
") + ImgBtnBuscarOC.Visible = False : TxtOC.Enabled = False + + 'Ocultamos la opcion de Editar y Eliminar hasta que se arreglen las anomalias + For Each Row As GridViewRow In GvPS.Rows + Row.FCLinkButton("imgE").Visible = False + Row.FCLinkButton("imgD").Visible = False + Next + + End If + + End If + TrasladoIEPS = 0 : OtrosImpuestos = 0 : SubTotal2 = SubTotal + + Else + PnlAjusteProductos.Visible = True + Dim Porcentaje As Double = If(SubTotalConceptos > 0, Math.Round((SubTotalConceptos - SubTotalReal) / SubTotalConceptos * 100, 2), 0) + TxtAjustePorcentaje.Text = Porcentaje.FormatoNumero + Msg &= String.Format("La Factura presenta anomalias en los importes mostrados, estas anomalias impiden que se editen las partidas. Por favor realice el ajuste correspondiente
") + ImgBtnBuscarOC.Visible = False : TxtOC.Enabled = False + + 'Ocultamos la opcion de Editar y Eliminar hasta que se arreglen las anomalias + For Each Row As GridViewRow In GvPS.Rows + Row.FCLinkButton("imgE").Visible = False + Row.FCLinkButton("imgD").Visible = False + Next + End If + End If + + + 'Si no hay diferencias pero tenemos descuento, se ofrece la opcion para ajustar el gasto + If Descuentos > 0 Then + + '[IPP] PARCHE: Factura TELMEX para APH 12/ENERO/2018 + If CveFactura = 286290 Then + + Else + PnlAjusteProductos.Visible = True + Dim Porcentaje As Double = Math.Round((Descuentos) / (SubTotalConceptos) * 100, 4) + TxtAjustePorcentaje.Text = Porcentaje.FormatoNumero(4) + Msg &= String.Format("La Factura presenta anomalias en los importes mostrados, estas anomalias impiden que se editen las partidas. Por favor realice el ajuste correspondiente
") + ImgBtnBuscarOC.Visible = False : TxtOC.Enabled = False + + 'Ocultamos la opcion de Editar y Eliminar hasta que se arreglen las anomalias + For Each Row As GridViewRow In GvPS.Rows + Row.FCLinkButton("imgE").Visible = False + Row.FCLinkButton("imgD").Visible = False + Next + End If + + End If + + + SubTotal2 = SubTotalReal - Descuentos + + If Descuentos > 0 Then + TrDescuento.Visible = True + End If + + If Msg <> "" Then + Alert(Msg, TipoMensaje.MsgAdvertencia) + BtnGuardar.Enabled = False + End If + + 'AJUSTAMOS SUBTOTAL EN CASO DE SER DIFERENTE AL SUBTOTAL2 DEL XML (TOTAL - IVA) + If SubTotal2 <> SubTotal Then + SubTotal = SubTotalConceptos + End If + + TxtSubTotal.Text = SubTotal.FormatoNumero + TxtDescuento.Text = Descuentos.FormatoNumero + TxtSubTotal2.Text = SubTotal2.FormatoNumero + TxtIVA.Text = IVA.FormatoNumero + TxtTotal.Text = Total.ToString.FormatoNumero + + HfTotalCompra.Value = Total.ToString + CompraSaldo = Total + + CalculaTotalPorDevengar() + TxtDocumentoImporteFE.Text = Total.ToString + RVDocumentoImporte.MaximumValue = Math.Round(Total, 2).ToString + RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue + RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue + TxtDocumentoImporte.Text = Total.FormatoNumero + TxtDocumentoImporteCaja.Text = Total.FormatoNumero + TxtRetIVA.Text = RetencionIVA.FormatoNumero + TxtRetISR.Text = RetencionISR.FormatoNumero + TxtIEPS.Text = IEPS.FormatoNumero + If IEPS > 0 Then TrIEPS.Visible = True + If RetencionIVA > 0 Then TrRetIVA.Visible = True + If RetencionISR > 0 Then TrRetISR.Visible = True + TxtOtrosImpuestos.Text = OtrosImpuestos.FormatoNumero + If OtrosImpuestos > 0 Then TrOtrosImpuestos.Visible = True + + HFDiferenciaCompra.Value = TxtTotal.Text + + + LblRetIVA.Text = (If(SubTotal2 > 0, (RetencionIVA / SubTotal2), 0) * 100).FormatoNumero(3) + "%" + LblRetISR.Text = (If(SubTotal2 > 0, (RetencionISR / SubTotal2), 0) * 100).FormatoNumero(3) + + + 'ASIGNA VALORES ORIGINALES PARA GUARDAR + AsignaValoresOriginales(SubTotal, SubTotal2, IVA, RetencionIVA, RetencionISR, Total) + + End If + + + TxtFechaPago.Text = (TxtFecha.Text.ToDate.AddDays(LblDiasCredito.Text.ToEntero)).ToShortDateString + + Dim drMon As DataRow = GlobalDTMonedas.FiltroPrimero(String.Format(" (Abreviatura LIKE '%{0}%' OR Moneda LIKE '%{0}%' )", Moneda)) + If drMon IsNot Nothing Then + DdlMoneda.SelectedValue = drMon("CveMoneda").ToString + Else + 'sino busco en la tabla de alias + drMon = GlobalDTMonedasAlias.FiltroPrimero(String.Format("MonedaAlias LIKE '%{0}%' ", Moneda)) + + If drMon IsNot Nothing Then + DdlMoneda.SelectedValue = drMon("CveMoneda").ToString + Else + LblMoneda.Text = Moneda + LblMoneda.ForeColor = Drawing.Color.Red + End If + + End If + + If DdlMoneda.SelectedValue.ToEntero > 1 Then + If TipoCambio <= 10 Then + TipoCambio = GlobalTipoCambio(TxtFecha.Text.ToDate) + End If + + TxtFecha.Attributes.Remove("onblur") + If UsuarioActual.Empresa.UsaAC Then + TxtFecha.Attributes.Add("onblur", "CambiaFecha();CambiaFechaTC();") + Else + TxtFecha.Attributes.Add("onblur", "CambiaFechaTC();") + End If + + End If + + If TipoCambio > 0 And DdlMoneda.SelectedValue.ToEntero > 1 Then LblTC.Text = String.Format("TC: {0}", TipoCambio.ToString("N4")) + + 'DF - 10-04-17 + If UsuarioActual.TienePermisoProceso(187) Then + TxtSerie.Enabled = True + End If + + + End If + + Else + Alert("No se Encontró la Factura", TipoMensaje.MsgAdvertencia) + BtnGuardar.Visible = False + End If + + 'GvPS.DataSource = 'DTConceptos + 'GvPS.DataBind() + End If + + ObjeFacturas.Dispose() + + Dim ObjSAT As New ClsSAT + Dim RFCRequest As String = Request("RFC").ToString + If ObjSAT.GetListado69B(2, UsuarioActual.CveEmpresa, RFCRequest) Then + If ObjSAT.DtResultados.Rows.Count > 0 Then + Dim Estatus As String = ObjSAT.DtResultados.Rows(0)("Situacion").ToString + BtnGuardar.Enabled = False + UpParametros.Update() + + Alert($"El RFC del proveedor se encuentra en estado {Estatus} en el Listado EFOS (69B) del SAT", TipoMensaje.MsgAdvertencia) + System.Threading.Thread.Sleep(5) + End If + End If + ObjSAT.Dispose() + + + Return RFC + End Function + Private Sub CargaRetIVAConcepto(Optional Cambio As Boolean = False) - If TrRetIVA.Visible Then + If TrRetIVA.Visible Then TdRetIVAConcepto.Visible = True @@ -2116,18 +2116,18 @@ Partial Class Compras_Compras - End If - - If Cambio Then - DdlRetIVAConcepto.Items.Clear() - - If RFCProv.Length = 13 Then - DdlRetIVAConcepto.Items.Insert(0, New ListItem("Honorarios/Serv. Prof.", "1")) - DdlRetIVAConcepto.Items.Insert(1, New ListItem("Fletes P.F.", "2")) - ElseIf RFCProv.Length = 12 Then - DdlRetIVAConcepto.Items.Insert(0, New ListItem("Fletes P.M.", "3")) - End If - + End If + + If Cambio Then + DdlRetIVAConcepto.Items.Clear() + + If RFCProv.Length = 13 Then + DdlRetIVAConcepto.Items.Insert(0, New ListItem("Honorarios/Serv. Prof.", "1")) + DdlRetIVAConcepto.Items.Insert(1, New ListItem("Fletes P.F.", "2")) + ElseIf RFCProv.Length = 12 Then + DdlRetIVAConcepto.Items.Insert(0, New ListItem("Fletes P.M.", "3")) + End If + DdlRetIVAConcepto.Items.Add(New ListItem("Arrendamiento", "4")) If UsuarioActual.Empresa.Funcionalidad(577).ToEntero = 1 Then @@ -2138,96 +2138,96 @@ Partial Class Compras_Compras End If - UpPS.Update() - - End Sub - Private Sub CargaRetISRConcepto(Optional Cambio As Boolean = False) - If TrRetISR.Visible Then - TdRetISRConcepto.Visible = True - End If - If Cambio Then - DdlRetISRConcepto.Items.Clear() - DdlRetISRConcepto.Items.Insert(0, New ListItem("Honorarios", "1")) - DdlRetISRConcepto.Items.Insert(1, New ListItem("Arrendamiento", "2")) - End If - UpPS.Update() - End Sub - - Private Sub ValidacionesTotalesXml() - - Dim Msg As String = "" - Dim SubtotalTemp = TmpDT.SUM("Total") + Math.Round(TmpDT.SUM("Descuento") + Math.Round(TmpDT.SUM("Amortizacion")), 2) - Dim DescuentosTemp = TmpDT.SUM("Descuento") - Dim Subtotal2Temp = TmpDT.SUM("Total") - Dim IVATemp = TmpDT.SUM("IVA") - Dim IEPSTemp = TmpDT.SUM("IEPSPS") - Dim RetIVATemp = TmpDT.SUM("RetIVA") - Dim RetISRTemp = TmpDT.SUM("RetISR") - Dim TotalTemp As Decimal = (Subtotal2Temp - RetIVATemp - RetISRTemp + Math.Round(IVATemp, 6) + IEPSTemp + OtrosImpuestos - OtrosImpuestosRetenciones).ToDecimal - - - If Math.Abs(Math.Round(DescuentosTemp, 6) - Math.Round(Descuentos, 6)) > 0.01 Then - Msg &= String.Format("- Los descuentos del detalle no coinciden con el descuento general
") - End If - - If Math.Abs(Math.Round(IVATemp, 6) - Math.Round(TrasladoIVA, 6)) > 0.01 Then - Msg &= String.Format("- Los IVAS del detalle no coinciden con el IVA general
") - End If - - If Math.Abs(Math.Round(IEPSTemp, 6) - Math.Round(TrasladoIEPS, 6)) > 0.01 Then - Msg &= String.Format("- Los IEPS del detalle no coinciden con el IEPS general
") - End If - - If Math.Abs(Math.Round(RetIVATemp, 6) - Math.Round(RetencionIVA, 6)) > 0.01 Then - Msg &= String.Format("- Los RetIVA del detalle no coinciden con el RetIVA general
") - End If - - If Math.Abs(Math.Round(RetISRTemp, 6) - Math.Round(RetencionISR, 6)) > 0.01 Then - Msg &= String.Format("- Las RetISR del detalle no coinciden con el RetIVA general
") - End If - - If Math.Abs(Math.Round(TotalTemp, 2) - Math.Round(Total, 2)) > 0.01 Then - Msg &= String.Format("- El total generado por los detalles no coincide con el total general
({0}-{1})", Math.Round(TotalTemp, 2), Math.Round(Total, 2)) - End If - - If Msg <> "" Then - Alert($"El comprobante XML presenta las siguientes inconsistencias:

{Msg}", TipoMensaje.MsgAdvertencia) - - TAB.ActiveTabIndex = 0 - - ''''BLOQUEA ACCIONES'''' - BtnGuardar.Enabled = False - - 'BLOQUEA OC - TxtOC.Enabled = False - ImgBtnBuscarOC.Visible = False - Else - '[IPP] IGUALAMOS VALORES PARA RESPETAR LOS DEL XML EN CASO DE DIF DE 0.01 - DescuentosTemp = Descuentos - IVATemp = TrasladoIVA - TotalTemp = Total - RetIVATemp = RetencionIVA - RetISRTemp = RetencionISR + UpPS.Update() + + End Sub + Private Sub CargaRetISRConcepto(Optional Cambio As Boolean = False) + If TrRetISR.Visible Then + TdRetISRConcepto.Visible = True + End If + If Cambio Then + DdlRetISRConcepto.Items.Clear() + DdlRetISRConcepto.Items.Insert(0, New ListItem("Honorarios", "1")) + DdlRetISRConcepto.Items.Insert(1, New ListItem("Arrendamiento", "2")) + End If + UpPS.Update() + End Sub + + Private Sub ValidacionesTotalesXml() + + Dim Msg As String = "" + Dim SubtotalTemp = TmpDT.SUM("Total") + Math.Round(TmpDT.SUM("Descuento") + Math.Round(TmpDT.SUM("Amortizacion")), 2) + Dim DescuentosTemp = TmpDT.SUM("Descuento") + Dim Subtotal2Temp = TmpDT.SUM("Total") + Dim IVATemp = TmpDT.SUM("IVA") + Dim IEPSTemp = TmpDT.SUM("IEPSPS") + Dim RetIVATemp = TmpDT.SUM("RetIVA") + Dim RetISRTemp = TmpDT.SUM("RetISR") + Dim TotalTemp As Decimal = (Subtotal2Temp - RetIVATemp - RetISRTemp + Math.Round(IVATemp, 6) + IEPSTemp + OtrosImpuestos - OtrosImpuestosRetenciones).ToDecimal + + + If Math.Abs(Math.Round(DescuentosTemp, 6) - Math.Round(Descuentos, 6)) > 0.01 Then + Msg &= String.Format("- Los descuentos del detalle no coinciden con el descuento general
") + End If + + If Math.Abs(Math.Round(IVATemp, 6) - Math.Round(TrasladoIVA, 6)) > 0.01 Then + Msg &= String.Format("- Los IVAS del detalle no coinciden con el IVA general
") + End If + + If Math.Abs(Math.Round(IEPSTemp, 6) - Math.Round(TrasladoIEPS, 6)) > 0.01 Then + Msg &= String.Format("- Los IEPS del detalle no coinciden con el IEPS general
") + End If + + If Math.Abs(Math.Round(RetIVATemp, 6) - Math.Round(RetencionIVA, 6)) > 0.01 Then + Msg &= String.Format("- Los RetIVA del detalle no coinciden con el RetIVA general
") + End If + + If Math.Abs(Math.Round(RetISRTemp, 6) - Math.Round(RetencionISR, 6)) > 0.01 Then + Msg &= String.Format("- Las RetISR del detalle no coinciden con el RetIVA general
") + End If + + If Math.Abs(Math.Round(TotalTemp, 2) - Math.Round(Total, 2)) > 0.01 Then + Msg &= String.Format("- El total generado por los detalles no coincide con el total general
({0}-{1})", Math.Round(TotalTemp, 2), Math.Round(Total, 2)) + End If + + If Msg <> "" Then + Alert($"El comprobante XML presenta las siguientes inconsistencias:

{Msg}", TipoMensaje.MsgAdvertencia) + + Tab.ActiveTabIndex = 0 + + ''''BLOQUEA ACCIONES'''' + BtnGuardar.Enabled = False + + 'BLOQUEA OC + TxtOC.Enabled = False + ImgBtnBuscarOC.Visible = False + Else + '[IPP] IGUALAMOS VALORES PARA RESPETAR LOS DEL XML EN CASO DE DIF DE 0.01 + DescuentosTemp = Descuentos + IVATemp = TrasladoIVA + TotalTemp = Total + RetIVATemp = RetencionIVA + RetISRTemp = RetencionISR IEPSTemp = TrasladoIEPS - End If - + End If + If TrasladoIEPS > 0 Or OtrosImpuestos > 0 Then - RegistraScript("$('#ModalIEPS').modal('show');") - - If TrasladoIEPS > 0 Then - ChkIEPS.Visible = True - ChkIEPS.Checked = True - DdlConceptoIEPS.Visible = True - CargaProductos(DdlConceptoIEPS, If(UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero > 0, UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero, -1)) - LbImporte.Text = "$" + TrasladoIEPS.ToString - End If - If OtrosImpuestos > 0 Then - ChkOtrosI.Visible = True - ChkOtrosI.Checked = True - DdlConceptoOI.Visible = True - CargaProductos(DdlConceptoOI, If(UsuarioActual.Empresa.Funcionalidad(305).ToString.ToEntero > 0, UsuarioActual.Empresa.Funcionalidad(305).ToString.ToEntero, -1)) - LbImporte2.Text = "$" + OtrosImpuestos.ToString - End If + RegistraScript("$('#ModalIEPS').modal('show');") + + If TrasladoIEPS > 0 Then + ChkIEPS.Visible = True + ChkIEPS.Checked = True + DdlConceptoIEPS.Visible = True + CargaProductos(DdlConceptoIEPS, If(UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero > 0, UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero, -1)) + LbImporte.Text = "$" + TrasladoIEPS.ToString + End If + If OtrosImpuestos > 0 Then + ChkOtrosI.Visible = True + ChkOtrosI.Checked = True + DdlConceptoOI.Visible = True + CargaProductos(DdlConceptoOI, If(UsuarioActual.Empresa.Funcionalidad(305).ToString.ToEntero > 0, UsuarioActual.Empresa.Funcionalidad(305).ToString.ToEntero, -1)) + LbImporte2.Text = "$" + OtrosImpuestos.ToString + End If End If Dim MostrarRetIva6 As Boolean = False @@ -2236,49 +2236,49 @@ Partial Class Compras_Compras - TxtSubTotal.Text = SubtotalTemp.FormatoNumero - TxtDescuento.Text = DescuentosTemp.FormatoNumero - TxtSubTotal2.Text = Subtotal2Temp.FormatoNumero - TxtIVA.Text = IVATemp.FormatoNumero - TxtTotal.Text = TotalTemp.FormatoNumero - TxtRetIVA.Text = RetIVATemp.FormatoNumero - TxtRetISR.Text = RetISRTemp.FormatoNumero + TxtSubTotal.Text = SubtotalTemp.FormatoNumero + TxtDescuento.Text = DescuentosTemp.FormatoNumero + TxtSubTotal2.Text = Subtotal2Temp.FormatoNumero + TxtIVA.Text = IVATemp.FormatoNumero + TxtTotal.Text = TotalTemp.FormatoNumero + TxtRetIVA.Text = RetIVATemp.FormatoNumero + TxtRetISR.Text = RetISRTemp.FormatoNumero TxtIEPS.Text = IEPSTemp.FormatoNumero - TrDescuento.Visible = DescuentosTemp > 0 - TrIEPS.Visible = IEPSTemp > 0 - TrRetIVA.Visible = RetIVATemp > 0 - TrRetISR.Visible = RetISRTemp > 0 - - TxtSubTotal.Enabled = False - TxtDescuento.Enabled = False - TxtSubTotal2.Enabled = False - TxtIVA.Enabled = False - TxtTotal.Enabled = False - TxtRetIVA.Enabled = False - TxtRetISR.Enabled = False - TxtIEPS.Enabled = False - - HfTotalCompra.Value = TotalTemp.ToString - CompraSaldo = TotalTemp - CalculaTotalPorDevengar() - TxtDocumentoImporteFE.Text = TotalTemp.ToString - RVDocumentoImporte.MaximumValue = Math.Round(TotalTemp, 2).ToString - RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue - RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue - TxtDocumentoImporte.Text = TotalTemp.FormatoNumero - TxtDocumentoImporteCaja.Text = TotalTemp.FormatoNumero - TxtOtrosImpuestos.Text = OtrosImpuestos.FormatoNumero - If OtrosImpuestos > 0 Then TrOtrosImpuestos.Visible = True - If OtrosImpuestosRetenciones > 0 Then TrOtrosImpuestos.Visible = True : TxtOtrosImpuestos.Text = (-OtrosImpuestosRetenciones).FormatoNumero - HFDiferenciaCompra.Value = TxtTotal.Text - HdnCompraSaldo.Value = TotalTemp.ToString - CompraSaldo = TotalTemp - - LblRetIVA.Text = (If(Subtotal2Temp > 0, (RetIVATemp / Subtotal2Temp), 0) * 100).FormatoNumero(3) + "%" - LblRetISR.Text = (If(Subtotal2Temp > 0, (RetISRTemp / Subtotal2Temp), 0) * 100).FormatoNumero(3) - - 'ASIGNA VALORES ORIGINALES PARA GUARDAR + TrDescuento.Visible = DescuentosTemp > 0 + TrIEPS.Visible = IEPSTemp > 0 + TrRetIVA.Visible = RetIVATemp > 0 + TrRetISR.Visible = RetISRTemp > 0 + + TxtSubTotal.Enabled = False + TxtDescuento.Enabled = False + TxtSubTotal2.Enabled = False + TxtIVA.Enabled = False + TxtTotal.Enabled = False + TxtRetIVA.Enabled = False + TxtRetISR.Enabled = False + TxtIEPS.Enabled = False + + HfTotalCompra.Value = TotalTemp.ToString + CompraSaldo = TotalTemp + CalculaTotalPorDevengar() + TxtDocumentoImporteFE.Text = TotalTemp.ToString + RVDocumentoImporte.MaximumValue = Math.Round(TotalTemp, 2).ToString + RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue + RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue + TxtDocumentoImporte.Text = TotalTemp.FormatoNumero + TxtDocumentoImporteCaja.Text = TotalTemp.FormatoNumero + TxtOtrosImpuestos.Text = OtrosImpuestos.FormatoNumero + If OtrosImpuestos > 0 Then TrOtrosImpuestos.Visible = True + If OtrosImpuestosRetenciones > 0 Then TrOtrosImpuestos.Visible = True : TxtOtrosImpuestos.Text = (-OtrosImpuestosRetenciones).FormatoNumero + HFDiferenciaCompra.Value = TxtTotal.Text + HdnCompraSaldo.Value = TotalTemp.ToString + CompraSaldo = TotalTemp + + LblRetIVA.Text = (If(Subtotal2Temp > 0, (RetIVATemp / Subtotal2Temp), 0) * 100).FormatoNumero(3) + "%" + LblRetISR.Text = (If(Subtotal2Temp > 0, (RetISRTemp / Subtotal2Temp), 0) * 100).FormatoNumero(3) + + 'ASIGNA VALORES ORIGINALES PARA GUARDAR AsignaValoresOriginales(SubtotalTemp, Subtotal2Temp, IVATemp, RetIVATemp, RetISRTemp, Total) If UsuarioActual.Empresa.Funcionalidad(577).ToString = "1" Then @@ -2299,711 +2299,712 @@ Partial Class Compras_Compras End If - End Sub - - ''' - ''' Método que convierte el IEPS en un concepto para no ajustar totales - ''' - Private Sub AgregarConceptoIEPS(IEPS As Decimal, CvePS1 As Integer) - Dim SubTotalR As Decimal = TmpDT.SUM("Total").ToString.ToDecimal - - Dim PSS As DataTable = GlobalDTPS(UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CvePS = {0} ", CvePS1), "PS") - Dim PSS2 As DataTable = TmpDT.FiltraParametros(String.Format("CvePS = {0} ", CvePS1), "PS") - - If PSS.Rows.Count > 0 Or PSS2.Rows.Count > 0 Then - Dim CveUM As Integer = 0 - Dim UM As String = "" - Dim CveClasificacion As Integer = 0 - Dim Clasificacion As String = "" - Dim CvePS As Integer = 0 - Dim PS As String = "" - Dim CveTipoPS As Integer = 0 - - If PSS.Rows.Count > 0 Then - CveUM = PSS.Rows(0)("CveUM").ToString.ToEntero - UM = PSS.Rows(0)("UnidadMedida").ToString - CveClasificacion = PSS.Rows(0)("CveClasificacion").ToString.ToEntero - Clasificacion = PSS.Rows(0)("Clasificacion").ToString - CvePS = PSS.Rows(0)("CvePS").ToString.ToEntero - PS = PSS.Rows(0)("PS").ToString - CveTipoPS = PSS.Rows(0)("CveTipoPS").ToString.ToEntero - End If - - Dim Cantidad As Double = 1 - Dim CveSubProyectoContrato As String = "-1" - Dim CveProyecto As String = "-1" - Dim SubProyecto As String = "SE" - Dim Proyecto As String = "SE" - Dim Obs As String = "" - Dim PU As Double = IEPS - Dim Total As Double = Cantidad * PU - Dim IVA As Double = 0 - Dim Descuento As Double = 0 - - If PSS2.Rows.Count > 0 Then - CveUM = PSS2.Rows(0)("CveUM").ToString.ToEntero - UM = PSS2.Rows(0)("UM").ToString - CveClasificacion = PSS2.Rows(0)("CveClasificacion").ToString.ToEntero - Clasificacion = PSS2.Rows(0)("Clasificacion").ToString - CvePS = PSS2.Rows(0)("CvePS").ToString.ToEntero - PS = PSS2.Rows(0)("PS").ToString - CveTipoPS = PSS2.Rows(0)("CveTipoPS").ToString.ToEntero - - CveSubProyectoContrato = PSS2.Rows(0)("CveSubProyecto").ToString - CveProyecto = PSS2.Rows(0)("CveProyecto").ToString - SubProyecto = PSS2.Rows(0)("SubProyecto").ToString - Proyecto = PSS2.Rows(0)("Proyecto").ToString - Obs = PSS2.Rows(0)("Obs").ToString - - Dim CveTipoGasto As Integer = PSS2.Rows(0)("CveTipoGasto").ToString.ToEntero - Dim TipoGasto As String = PSS2.Rows(0)("TipoGasto").ToString - - AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, 0, 0, 0, 0, Descuento, TCalculaTotales:=False, CveTipoGasto:=CveTipoGasto, TipoGasto:=TipoGasto) - AddPS2() - Else - AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, 0, 0, 0, 0, Descuento, TCalculaTotales:=False) - AddPS2() - End If - End If - - Dim SubTotalIEPS = TmpDT.SUM("Total").ToString.ToDecimal - - SubTotal = Math.Round(SubTotalIEPS, 2) - SubTotalConceptos = Math.Round(SubTotalIEPS, 2) - - 'If SubTotalR <> SubTotalIEPS Then - ' Dim IA As Decimal = SubTotalR - SubTotalIEPS - ' AjustaImporteUltimoConcepto(IA) - 'End If - - PSS.Dispose() - End Sub - - Private Sub CargaCompra() - Dim ObjCompra As New ClsCompras() - Dim ObjOC As New ClsOC() - - If ObjCompra.GetCompras(CveCompra, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then - If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then - - CompraCargada = True - - 'data-toggle="tooltip" data-placement="left" title="Agregar Escolaridad ." - If ObjCompra.DtResultados.Rows(0)("FolioREQ").ToString <> "" Then - lblOCLabel.Attributes.Add("data-toggle", "tooltip") - lblOCLabel.Attributes.Add("data-placement", "top") - lblOCLabel.Attributes.Add("title", "REQ: " & ObjCompra.DtResultados.Rows(0)("FolioREQ").ToString) - End If - - 'CargaProveedor - Dim dr As DataRow = ObjCompra.DtResultados.Rows(0) - Saldo = dr("Saldo").ToString.ToDecimal - RBLPago.Visible = False - Dim CveProveedor As Integer = dr("CveProveedor").ToString.ToEntero - - HdnCveProveedor.Value = CveProveedor.ToString - ViewState("CveProveedor") = CveProveedor - - ImgBtnBuscarOC.OnClientClick = String.Format("AbrirVentana('/OC/PopUpBuscarReq.aspx?V=VOCCOMP&P={0}&T={1}&Masterimpoup=true',1000,600,'S'); return false;", CveProveedor, DdlTipoComprobante.SelectedValue) - - - Dim ObjBancos As New ClsBancos() - - If ObjBancos.GetCreditosCompra(CveCompra) And ObjBancos.DtResultados.Rows.Count > 0 Then - GvCreditosRelacionados.DataSource = ObjBancos.DtResultados - GvCreditosRelacionados.Visible = True - GvCreditosRelacionados.DataBind() - romCreditosTabla.Visible = True - GvCreditos.Visible = False - GvCreditosRelacionados.Visible = True - - PnlContadoCreditos.Visible = True - Else - GvCreditosRelacionados.DataSource = Nothing - GvCreditosRelacionados.Visible = False - GvCreditosRelacionados.DataBind() - - End If - UpGvCreditos.Update() - LblImporteCreditos.Visible = True - ObjBancos.Dispose() - - 'RegistraScript("CargaProveedor(""" & CveProveedor & """);") - - 'CargaEncabezado - 'ViewState("FolioFiscal") = ObjCompra.DtResultados.Rows(0)("FolioFiscal").ToString - TxtSerie.Text = dr("Serie").ToString - TxtFolio.Text = dr("Folio").ToString - TxtFolioSecundario.Text = dr("FolioSecundario").ToString - TxtFecha.Text = dr("Fecha").ToString.ToDate.ToShortDateString - TxtDescripcion.Text = dr("Descripcion").ToString - CvePrePoliza = dr("CvePrePoliza").ToString.ToEntero - EstatusAlmacen = dr("EstatusAlmacen").ToString.ToEntero - DdlTipoCompra.SelectedValueExist(dr("CveTipoCompra")) - 'Select Case dr("PorcentajeIVA").ToString.ToDouble - ' Case 0 - ' DdlIVA.SelectedValue = "1" - ' Case 0.16 - ' DdlIVA.SelectedValue = "1.16" - ' Case 0.08 - ' DdlIVA.SelectedValue = "1.08" - 'End Select - 'If dr("PorcentajeIVA").ToString.ToDouble = 0 Then DdlIVA.SelectedValue = "1" Else DdlIVA.SelectedValue = "1.16" - - LblMetodoPago.Text = dr("MetodoPagoSAT").ToString - - If UsuarioActual.Empresa.UsaAC Then - CambiaEjercicioAC(False) - End If - - If GlobalDTProveedorSucursales(CveProveedor, UsuarioActual.CveEmpresa).Rows.Count > 0 Then - RowProveedorSucursal.Visible = True - DdlProveedorSucursal.Items.Clear() - DdlProveedorSucursal.DataSource = GlobalDTProveedorSucursales(CveProveedor, UsuarioActual.CveEmpresa) - DdlProveedorSucursal.DataBind() - DdlProveedorSucursal.Items.Insert(0, New ListItem("Matriz", "0")) - DdlProveedorSucursal.SelectedValueExist(dr("CveProveedorSucursal").ToString.ToEntero) - End If - - ''SE AJUSTO EL SUBTOTAL POR LA COMPRA # 52433 DE LA EMPRESA 48 PARA QUE CUADREN LOS TOTALES CUANDO VIENE CON DESCUENTOS - 'TxtSubTotal.Text = (dr("SubTotal").ToString.ToDouble + dr("Descuentos").ToString.ToDouble).FormatoNumero(2) - TxtSubTotal.Text = (dr("SubTotal").ToString.ToDouble).FormatoNumero - 'TxtSubTotal2.Text = (dr("SubTotal").ToString.ToDouble).FormatoNumero - TxtSubTotal2.Text = (dr("SubTotal").ToString.ToDouble - dr("Descuentos").ToString.ToDouble).FormatoNumero(2) - - TxtDescuento.Text = dr("Descuentos").ToString.FormatoNumero(2) - LblAmortizacion.Text = dr("Amortizacion").ToString.FormatoNumero(2) - TxtIVA.Text = dr("IVA").ToString.FormatoNumero(2) - TxtRetIVA.Text = dr("RetIVA").ToString.FormatoNumero(2) - TxtRetISR.Text = dr("RetISR").ToString.FormatoNumero(2) - TxtIEPS.Text = dr("IEPS").ToString.FormatoNumero(2) - If dr("IEPS").ToString.ToDouble > 0 Then TrIEPS.Visible = True - If dr("RetIVA").ToString.ToDouble > 0 Then TrRetIVA.Visible = True - If dr("RetISR").ToString.ToDouble > 0 Then TrRetISR.Visible = True - If Math.Abs(dr("Redondeo").ToString.ToDouble) > 0 Then TrRedondeo.Visible = True - TxtRedondeo.Text = dr("Redondeo").ToString.FormatoNumero(2) - - TxtOtrosImpuestos.Text = dr("OtrosImpuestos").ToString.FormatoNumero(2) - If dr("OtrosImpuestos").ToString.ToDouble > 0 Then TrOtrosImpuestos.Visible = True - TxtTotal.Text = dr("Total").ToString.FormatoNumero(2) - - HfTotalCompra.Value = TxtTotal.Text - CompraSaldo = TxtTotal.Text.ToDouble - - TipoCambio = dr("TipoCambio").ToString.ToDouble - Dim TipoCambioOriginal = dr("TipoCambioOriginal").ToString.ToDouble - If TipoCambio > 1 Then LblTC.Text = String.Format("TC: {0}", TipoCambio.ToString("N4")) - If TipoCambio <> TipoCambioOriginal Then LblTCO.Text = String.Format("
TC Original: {0}", TipoCambioOriginal.ToString("N4")) - - - AsignaValoresOriginales(TxtSubTotal.Text.ToDouble, TxtSubTotal2.Text.ToDouble, TxtIVA.Text.ToDouble, TxtRetIVA.Text.ToDouble, TxtRetISR.Text.ToDouble, TxtTotal.Text.ToDouble) - CalculaTotalPorDevengar() - TxtDocumentoImporteFE.Text = dr("Total").ToString - RVDocumentoImporte.MaximumValue = dr("Total").ToString.FormatoNumero(2) - RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue - RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue - - HFDiferenciaCompra.Value = TxtTotal.Text - - - - TotalGeneral = dr("Total").ToString.ToDouble - CveMoneda = dr("CveMoneda").ToString.ToEntero - DdlValidadaSAT.SelectedValue = "Si" - TxtObsFact.Text = dr("Observaciones").ToString - LblUsuarioCaptura.Text = dr("Usuario").ToString - LitFechCaptura.Text = dr("FechaIng").ToString.ToDate.ToShortDateString - LblRetIVA.Text = Math.Round((dr("RetIVA").ToString.ToDouble / TxtSubTotal2.Text.ToDouble) * 100, 4).FormatoNumero(3) + "%" - LblRetISR.Text = Math.Round((dr("RetISR").ToString.ToDouble / TxtSubTotal2.Text.ToDouble) * 100, 4).FormatoNumero(3) - If dr("TipoFactura").ToString <> "CFDi" Then LblTipoFact.Text = dr("TipoFactura").ToString : divTipoFactura.Visible = True - ViewState("CveFactura") = dr("CveFactura").ToString.ToEntero - ViewState("IdPoliza") = dr("IdPoliza").ToString.ToEntero - - DdlMoneda.SelectedValue = dr("CveMoneda").ToString - 'primero se asigna la moneda, para que dentro del proveedor carge los anticipos solo de esa moneda - DdlProveedor.Visible = False - HplProveedor.Visible = True - CargaProveedor(CveProveedor, "-1") - - - DdlRetIVAConcepto.SelectedValueExist(dr("CveRetIVAConcepto").ToString) + End Sub + + ''' + ''' Método que convierte el IEPS en un concepto para no ajustar totales + ''' + Private Sub AgregarConceptoIEPS(IEPS As Decimal, CvePS1 As Integer) + Dim SubTotalR As Decimal = TmpDT.SUM("Total").ToString.ToDecimal + + Dim PSS As DataTable = GlobalDTPS(UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CvePS = {0} ", CvePS1), "PS") + Dim PSS2 As DataTable = TmpDT.FiltraParametros(String.Format("CvePS = {0} ", CvePS1), "PS") + + If PSS.Rows.Count > 0 Or PSS2.Rows.Count > 0 Then + Dim CveUM As Integer = 0 + Dim UM As String = "" + Dim CveClasificacion As Integer = 0 + Dim Clasificacion As String = "" + Dim CvePS As Integer = 0 + Dim PS As String = "" + Dim CveTipoPS As Integer = 0 + + If PSS.Rows.Count > 0 Then + CveUM = PSS.Rows(0)("CveUM").ToString.ToEntero + UM = PSS.Rows(0)("UnidadMedida").ToString + CveClasificacion = PSS.Rows(0)("CveClasificacion").ToString.ToEntero + Clasificacion = PSS.Rows(0)("Clasificacion").ToString + CvePS = PSS.Rows(0)("CvePS").ToString.ToEntero + PS = PSS.Rows(0)("PS").ToString + CveTipoPS = PSS.Rows(0)("CveTipoPS").ToString.ToEntero + End If + + Dim Cantidad As Double = 1 + Dim CveSubProyectoContrato As String = "-1" + Dim CveProyecto As String = "-1" + Dim SubProyecto As String = "SE" + Dim Proyecto As String = "SE" + Dim Obs As String = "" + Dim PU As Double = IEPS + Dim Total As Double = Cantidad * PU + Dim IVA As Double = 0 + Dim Descuento As Double = 0 + + If PSS2.Rows.Count > 0 Then + CveUM = PSS2.Rows(0)("CveUM").ToString.ToEntero + UM = PSS2.Rows(0)("UM").ToString + CveClasificacion = PSS2.Rows(0)("CveClasificacion").ToString.ToEntero + Clasificacion = PSS2.Rows(0)("Clasificacion").ToString + CvePS = PSS2.Rows(0)("CvePS").ToString.ToEntero + PS = PSS2.Rows(0)("PS").ToString + CveTipoPS = PSS2.Rows(0)("CveTipoPS").ToString.ToEntero + + CveSubProyectoContrato = PSS2.Rows(0)("CveSubProyecto").ToString + CveProyecto = PSS2.Rows(0)("CveProyecto").ToString + SubProyecto = PSS2.Rows(0)("SubProyecto").ToString + Proyecto = PSS2.Rows(0)("Proyecto").ToString + Obs = PSS2.Rows(0)("Obs").ToString + + Dim CveTipoGasto As Integer = PSS2.Rows(0)("CveTipoGasto").ToString.ToEntero + Dim TipoGasto As String = PSS2.Rows(0)("TipoGasto").ToString + + AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, 0, 0, 0, 0, Descuento, TCalculaTotales:=False, CveTipoGasto:=CveTipoGasto, TipoGasto:=TipoGasto) + AddPS2() + Else + AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, 0, 0, 0, 0, Descuento, TCalculaTotales:=False) + AddPS2() + End If + End If + + Dim SubTotalIEPS = TmpDT.SUM("Total").ToString.ToDecimal + + SubTotal = Math.Round(SubTotalIEPS, 2) + SubTotalConceptos = Math.Round(SubTotalIEPS, 2) + + 'If SubTotalR <> SubTotalIEPS Then + ' Dim IA As Decimal = SubTotalR - SubTotalIEPS + ' AjustaImporteUltimoConcepto(IA) + 'End If + + PSS.Dispose() + End Sub + + Private Sub CargaCompra() + Dim ObjCompra As New ClsCompras() + Dim ObjOC As New ClsOC() + + If ObjCompra.GetCompras(CveCompra, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then + If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then + + CompraCargada = True + + 'data-toggle="tooltip" data-placement="left" title="Agregar Escolaridad ." + If ObjCompra.DtResultados.Rows(0)("FolioREQ").ToString <> "" Then + lblOCLabel.Attributes.Add("data-toggle", "tooltip") + lblOCLabel.Attributes.Add("data-placement", "top") + lblOCLabel.Attributes.Add("title", "REQ: " & ObjCompra.DtResultados.Rows(0)("FolioREQ").ToString) + End If + + 'CargaProveedor + Dim dr As DataRow = ObjCompra.DtResultados.Rows(0) + Saldo = dr("Saldo").ToString.ToDecimal + RBLPago.Visible = False + Dim CveProveedor As Integer = dr("CveProveedor").ToString.ToEntero + + HdnCveProveedor.Value = CveProveedor.ToString + ViewState("CveProveedor") = CveProveedor + + ImgBtnBuscarOC.OnClientClick = String.Format("AbrirVentana('/OC/PopUpBuscarReq.aspx?V=VOCCOMP&P={0}&T={1}&Masterimpoup=true',1000,600,'S'); return false;", CveProveedor, DdlTipoComprobante.SelectedValue) + + + Dim ObjBancos As New ClsBancos() + + If ObjBancos.GetCreditosCompra(CveCompra) And ObjBancos.DtResultados.Rows.Count > 0 Then + GvCreditosRelacionados.DataSource = ObjBancos.DtResultados + GvCreditosRelacionados.Visible = True + GvCreditosRelacionados.DataBind() + romCreditosTabla.Visible = True + GvCreditos.Visible = False + GvCreditosRelacionados.Visible = True + + PnlContadoCreditos.Visible = True + Else + GvCreditosRelacionados.DataSource = Nothing + GvCreditosRelacionados.Visible = False + GvCreditosRelacionados.DataBind() + + End If + UpGvCreditos.Update() + LblImporteCreditos.Visible = True + ObjBancos.Dispose() + + 'RegistraScript("CargaProveedor(""" & CveProveedor & """);") + + 'CargaEncabezado + 'ViewState("FolioFiscal") = ObjCompra.DtResultados.Rows(0)("FolioFiscal").ToString + TxtSerie.Text = dr("Serie").ToString + TxtFolio.Text = dr("Folio").ToString + TxtFolioSecundario.Text = dr("FolioSecundario").ToString + TxtFecha.Text = dr("Fecha").ToString.ToDate.ToShortDateString + TxtDescripcion.Text = dr("Descripcion").ToString + CvePrePoliza = dr("CvePrePoliza").ToString.ToEntero + EstatusAlmacen = dr("EstatusAlmacen").ToString.ToEntero + DdlTipoCompra.SelectedValueExist(dr("CveTipoCompra")) + CveTipoConcepto = dr("CveTipoConcepto").ToString.ToEntero + 'Select Case dr("PorcentajeIVA").ToString.ToDouble + ' Case 0 + ' DdlIVA.SelectedValue = "1" + ' Case 0.16 + ' DdlIVA.SelectedValue = "1.16" + ' Case 0.08 + ' DdlIVA.SelectedValue = "1.08" + 'End Select + 'If dr("PorcentajeIVA").ToString.ToDouble = 0 Then DdlIVA.SelectedValue = "1" Else DdlIVA.SelectedValue = "1.16" + + LblMetodoPago.Text = dr("MetodoPagoSAT").ToString + + If UsuarioActual.Empresa.UsaAC Then + CambiaEjercicioAC(False) + End If + + If GlobalDTProveedorSucursales(CveProveedor, UsuarioActual.CveEmpresa).Rows.Count > 0 Then + RowProveedorSucursal.Visible = True + DdlProveedorSucursal.Items.Clear() + DdlProveedorSucursal.DataSource = GlobalDTProveedorSucursales(CveProveedor, UsuarioActual.CveEmpresa) + DdlProveedorSucursal.DataBind() + DdlProveedorSucursal.Items.Insert(0, New ListItem("Matriz", "0")) + DdlProveedorSucursal.SelectedValueExist(dr("CveProveedorSucursal").ToString.ToEntero) + End If + + ''SE AJUSTO EL SUBTOTAL POR LA COMPRA # 52433 DE LA EMPRESA 48 PARA QUE CUADREN LOS TOTALES CUANDO VIENE CON DESCUENTOS + 'TxtSubTotal.Text = (dr("SubTotal").ToString.ToDouble + dr("Descuentos").ToString.ToDouble).FormatoNumero(2) + TxtSubTotal.Text = (dr("SubTotal").ToString.ToDouble).FormatoNumero + 'TxtSubTotal2.Text = (dr("SubTotal").ToString.ToDouble).FormatoNumero + TxtSubTotal2.Text = (dr("SubTotal").ToString.ToDouble - dr("Descuentos").ToString.ToDouble).FormatoNumero(2) + + TxtDescuento.Text = dr("Descuentos").ToString.FormatoNumero(2) + LblAmortizacion.Text = dr("Amortizacion").ToString.FormatoNumero(2) + TxtIVA.Text = dr("IVA").ToString.FormatoNumero(2) + TxtRetIVA.Text = dr("RetIVA").ToString.FormatoNumero(2) + TxtRetISR.Text = dr("RetISR").ToString.FormatoNumero(2) + TxtIEPS.Text = dr("IEPS").ToString.FormatoNumero(2) + If dr("IEPS").ToString.ToDouble > 0 Then TrIEPS.Visible = True + If dr("RetIVA").ToString.ToDouble > 0 Then TrRetIVA.Visible = True + If dr("RetISR").ToString.ToDouble > 0 Then TrRetISR.Visible = True + If Math.Abs(dr("Redondeo").ToString.ToDouble) > 0 Then TrRedondeo.Visible = True + TxtRedondeo.Text = dr("Redondeo").ToString.FormatoNumero(2) + + TxtOtrosImpuestos.Text = dr("OtrosImpuestos").ToString.FormatoNumero(2) + If dr("OtrosImpuestos").ToString.ToDouble > 0 Then TrOtrosImpuestos.Visible = True + TxtTotal.Text = dr("Total").ToString.FormatoNumero(2) + + HfTotalCompra.Value = TxtTotal.Text + CompraSaldo = TxtTotal.Text.ToDouble + + TipoCambio = dr("TipoCambio").ToString.ToDouble + Dim TipoCambioOriginal = dr("TipoCambioOriginal").ToString.ToDouble + If TipoCambio > 1 Then LblTC.Text = String.Format("TC: {0}", TipoCambio.ToString("N4")) + If TipoCambio <> TipoCambioOriginal Then LblTCO.Text = String.Format("
TC Original: {0}", TipoCambioOriginal.ToString("N4")) + + + AsignaValoresOriginales(TxtSubTotal.Text.ToDouble, TxtSubTotal2.Text.ToDouble, TxtIVA.Text.ToDouble, TxtRetIVA.Text.ToDouble, TxtRetISR.Text.ToDouble, TxtTotal.Text.ToDouble) + CalculaTotalPorDevengar() + TxtDocumentoImporteFE.Text = dr("Total").ToString + RVDocumentoImporte.MaximumValue = dr("Total").ToString.FormatoNumero(2) + RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue + RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue + + HFDiferenciaCompra.Value = TxtTotal.Text + + + + TotalGeneral = dr("Total").ToString.ToDouble + CveMoneda = dr("CveMoneda").ToString.ToEntero + DdlValidadaSAT.SelectedValue = "Si" + TxtObsFact.Text = dr("Observaciones").ToString + LblUsuarioCaptura.Text = dr("Usuario").ToString + LitFechCaptura.Text = dr("FechaIng").ToString.ToDate.ToShortDateString + LblRetIVA.Text = Math.Round((dr("RetIVA").ToString.ToDouble / TxtSubTotal2.Text.ToDouble) * 100, 4).FormatoNumero(3) + "%" + LblRetISR.Text = Math.Round((dr("RetISR").ToString.ToDouble / TxtSubTotal2.Text.ToDouble) * 100, 4).FormatoNumero(3) + If dr("TipoFactura").ToString <> "CFDi" Then LblTipoFact.Text = dr("TipoFactura").ToString : divTipoFactura.Visible = True + ViewState("CveFactura") = dr("CveFactura").ToString.ToEntero + ViewState("IdPoliza") = dr("IdPoliza").ToString.ToEntero + + DdlMoneda.SelectedValue = dr("CveMoneda").ToString + 'primero se asigna la moneda, para que dentro del proveedor carge los anticipos solo de esa moneda + DdlProveedor.Visible = False + HplProveedor.Visible = True + CargaProveedor(CveProveedor, "-1") + + + DdlRetIVAConcepto.SelectedValueExist(dr("CveRetIVAConcepto").ToString) DdlRetISRConcepto.SelectedValueExist(dr("CveRetISRConcepto").ToString) - If dr("CveTipoConcepto").ToString.ToEntero = 1 Then LblProveedor.Text = "Proveedor:" Else LblProveedor.Text = "Acreedor:" - - HdnCveEstatusFactura.Value = dr("CveEstatusFactura").ToString - LblCompraEstatus.Text = dr("EstatusFactura").ToString - If dr("CveEstatusFactura").ToString = "2" Then ChkProgramarPago.Checked = True - - TrRembolsoUpdate.Visible = True - TrRembolsoNumero.Visible = True - - Dim DtPersonal = GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltraParametros("", "NombreCompleto") - DdlRembolsoPersonal.DataSource = DtPersonal - DdlRembolsoPersonal.Items.Insert(0, New ListItem("Sin Seleccionar", "-1")) - DdlRembolsoPersonal.DataBind() - If dr("CvePersonal").ToString.ToEntero > 0 Then - DdlRembolsoPersonal.SelectedValueExist(dr("CvePersonal").ToString) - TxtRembolsoNumero.Text = dr("NumeroReembolso").ToString - RblRembolso.SelectedValuesIfExist("1") - TrRembolsoPersonal.Visible = True - End If - - Dim DtCajaChica As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario) - DtCajaChica = DtCajaChica.FiltraParametros(String.Format("CveTipoCuenta = 1")) - DdlRembolsoCajaChica.DataSource = DtCajaChica - DdlRembolsoCajaChica.Items.Insert(0, New ListItem("Sin Seleccionar", "-1")) - DdlRembolsoCajaChica.DataBind() - If dr("CveCajaChica").ToString.ToEntero > 0 Then - DdlRembolsoCajaChica.SelectedValueExist(dr("CveCajaChica").ToString) - TxtRembolsoNumero.Text = dr("NumeroReembolso").ToString - RblRembolso.SelectedValuesIfExist("2") - TrRembolsoCajaChica.Visible = True - End If - - VisualizaEstatusCompraSaldo(dr("TipoDocto").ToString, dr("Saldo").ToString.ToDecimal, dr("Total").ToString.ToDecimal) - If dr("IdPoliza").ToString.ToEntero > 0 Then - HplCompraContabilizada.Text = "Si" - HplCompraContabilizada.NavigateUrl = String.Format("/Contabilidad/RegPoliza.aspx?IdPoliza={0}", dr("IdPoliza")) - LblCompraEstatus.ForeColor = Drawing.Color.Navy - trContabilizada.Visible = True - If UsuarioActual.TienePermisoProceso(107) Then BtnDescontabilizar.Visible = True - Else - BtnDescontabilizar.Visible = False - HplCompraContabilizada.Text = "No" - trContabilizada.Visible = True - If UsuarioActual.Empresa.UsaAC Then - LBContabilizarAC.Visible = True - End If - End If - UPPDescontablizar.Update() - - TxtFechaPago.Text = dr("FechaVencimiento").ToString.ToDate.ToShortDateString - RowBitacora.Visible = True - CargaEventoBitacora() - 'ImgAddObs.Attributes.Add("onclick", "javascript: PosicionaObjeto(this.id,'DivEventoBitacora',null,-250,-250); $('#DivEventoBitacora').show(1000); ") - ImgAddObs.Visible = True - ChkAplicaNotaCredito.Checked = CBool(dr("AplicaNotaCredito").ToString) - 'RBLPago.Enabled = False - 'If dr("CveIE").ToString.ToEntero > 0 Then - ' RBLPago.SelectedValue = "2" - ' 'cargo los datos del pago - ' 'PnlPago.Visible = True - ' 'PnlChkFuncionariosEmpleados.Visible = True - - ' Dim ObjIE As New ClsBancos() - - ' If ObjIE.GetBancosIE(dr("CveIE").ToString.ToEntero, UsuarioActual.CveEmpresa) Then - ' If ObjIE.DtResultados.Rows.Count > 0 Then - - ' DdlTipoTransaccion.SelectedValue = ObjIE.CveTipoTransaccion.ToString - ' DdlCuenta.SelectedValue = ObjIE.CveCuenta.ToString - ' TxtDocumentoFolio.Text = ObjIE.Folio - ' TxtDocumentoImporte.Text = ObjIE.Importe.FormatoNumero - ' TxtDocumentoObservaciones.Text = ObjIE.Observaciones - - ' End If - ' End If - - ' ObjIE.Dispose() - 'End If - CompraSaldo = TotalGeneral - LblAmortizacion.Text.ToDouble - If EmpresaPrueba Then - CompraSaldo = dr("Saldo").ToString.ToDouble - End If - - If CompraSaldo > dr("Saldo").ToString.ToDouble Then - CompraSaldo = dr("Saldo").ToString.ToDouble - End If - HdnCompraSaldo.Value = CompraSaldo.ToString - - If CompraSaldo > 0 And UsuarioActual.TienePermisoProceso(100) Then - HLPagar.Visible = True - HLPagar.NavigateUrl = $"/Bancos/PopIECompras.aspx?CveCompra={CveCompra}&TB_iframe=true&height=520&width=700" - End If - - If dr("CveFactura").ToString.ToEntero > 0 Then - ImgDownXML.Visible = True : ImgDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=Fact&EXT=xml&CveFactura={0}&RFC={1}", dr("CveFactura"), dr("RFC").ToString.Replace("&", "%26%")))) - ImgDownPDF.Visible = True : ImgDownPDF.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=Fact&EXT=pdf&CveFactura={0}&RFC={1}", dr("CveFactura"), dr("RFC").ToString.Replace("&", "%26%")))) - End If - - 'CargaDetalle - If ObjCompra.GetCompraDetalle(CveCompra) Then - TmpDT = ObjCompra.DtResultados - TmpDTOriginal = ObjCompra.DtResultados.Copy - - TmpDT.Columns.Add("CveClasificacionActualizar", GetType(Integer)) - 'TmpDT.Columns.Add("CveEq", GetType(Integer)) - TmpDT.Columns.Add("CveAlmacen", GetType(Integer)) - 'TmpDT.Columns.Add("CvePersonal", GetType(Integer)) - - TmpDT.Columns.Add("IdCuentaComprometido", GetType(Integer)) - TmpDT.Columns.Add("IdCuentaPorEjercer", GetType(Integer)) - TmpDT.Columns.Add("IdCuentaDevengado", GetType(Integer)) - TmpDT.Columns.Add("IdCuentaMatriz", GetType(Integer)) - - TmpDT.Columns.Add("PSDescripcion", GetType(String)) - TmpDT.Columns.Add("ProductoOC", GetType(String)) - TmpDT.Columns.Add("CantidadF", GetType(Double)) - - 'Consignaciones - TmpDT.Columns.Add("CveAlmacenConsignacion", GetType(Integer)) - TmpDT.Columns.Add("NoConsignacion", GetType(Integer)) - TmpDT.Columns.Add("CveConsignacion", GetType(Integer)) - TmpDT.Columns.Add("HdnPS", GetType(String)) - TmpDT.Columns.Add("HdnCvePS", GetType(String)) - TmpDT.Columns.Add("HdnClasificacion", GetType(String)) - TmpDT.Columns.Add("HdnCveClasificacion", GetType(String)) - TmpDT.Columns.Add("HdnCveAlmacen", GetType(String)) - - 'INVENTARIO SERIE/LOTE - TmpDT.Columns.Add("CveMetodoInventario", GetType(Integer)) - - 'Fletes y Servicios - 'TmpDT.Columns.Add("AplicaCostoIndirecto", GetType(Integer)) 'Ya traemos el estatus flete - TmpDT.Columns.Add("CostoIndirectoAlmacen", GetType(Decimal)) - TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) - - TmpDT.Columns.Add("CveContrato", GetType(Integer)) - - - - GvPS.DataSource = TmpDT - GvPS.DataBind() - - If UsuarioActual.Empresa.UsaAC Then - CargaHidendsAC() - End If - - CalculaTotales(True) - - If UsuarioActual.Empresa.UsaInventarios Then - DtInv = TmpDT.FiltraParametros(String.Format("CveTipoPS = 2")).Copy - - If dr("Inventario").ToString = "1" Then - - CveMovimientoAlmacen = dr("CveMovimiento").ToString.ToEntero - - Dim Inv As New ClsInventarios - If Inv.GetMovimientosDetalle(dr("CveMovimiento").ToString.ToEntero, UsuarioActual.CveEmpresa) Then - 'Dim TempParametros = Encripta(String.Format("OP=Alm&CveMovimiento={0}", dr("CveMovimiento"))) - 'ImgImprimirAlmacen.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", TempParametros) - - ImgImprimirAlmacen.Visible = True - ImgImprimirAlmacen.NavigateUrl = String.Format("/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}", dr("CveMovimiento")) - - Dim drt As DataRow - 'actualizo el almacen - For Each dri As DataRow In DtInv.Rows - - drt = Inv.DtResultados.FiltroPrimero(String.Format("CvePS = {0} AND Cantidad = {1}", dri("CvePS"), dri("Cantidad"))) - If drt IsNot Nothing Then - Dim TmpDr As DataRow = TmpDT.Select($"Consec = {dri("Consec").ToString.ToEntero}")(0) 'Charlie - TmpDr("CveAlmacen") = drt("CveAlmacen") 'Charlie - - dri("CveAlmacen") = drt("CveAlmacen") - - End If - - Next - - End If - - 'Proceso Super Tramposo de Charlie - If Inv.GetMovimientosDetalle(dr("CveMovimiento").ToString.ToEntero, UsuarioActual.CveEmpresa, CveCompra:=-123) Then - Dim drt As DataRow - For Each dri As DataRow In DtInv.Rows - drt = Inv.DtResultados.FiltroPrimero(String.Format("CvePS = {0} AND Cantidad = {1}", dri("CvePS"), dri("Cantidad"))) - If drt IsNot Nothing Then - Dim TmpDr As DataRow = TmpDT.Select($"Consec = {dri("Consec").ToString.ToEntero}")(0) - TmpDr("CveAlmacen") = drt("CveAlmacen") - End If - Next - End If - - Inv.Dispose() - - End If - - CargaGvInv() - - 'Ocultamos "Recibir Aqui" - GvInv.Columns(6).Visible = False - GvInv.Columns(7).Visible = False - - End If - End If - - DdlTipoComprobante.Enabled = False - DdlTipoComprobante.SelectedValue = dr("TipoDocto").ToString - If dr("TipoDocto").ToString = "Fac" Then - ChkAplicaNotaCredito.Enabled = True - ImgAnticiposPendientes.Visible = True - Else - ImgAnticiposPendientes.Visible = False - ChkAplicaNotaCredito.Enabled = False - End If - HlProveedor.HRef = "" - TxtCodigo.ReadOnly = True - 'IPP Usuario Sistema No Bloquea, se cambió al proceso - If UsuarioActual.TienePermisoProceso(79) Then - TxtCantidad.Enabled = True - TxtPrecio.Enabled = True - Else - TxtCantidad.Enabled = False - TxtPrecio.Enabled = False - End If - - DdlPS.Enabled = False - TxtObsPS.Enabled = False - 'ImgAmort.Attributes.Clear() - LbAgregar.Enabled = False - TxtSerie.Enabled = False + If dr("CveTipoConcepto").ToString.ToEntero = 1 Then LblProveedor.Text = "Proveedor:" Else LblProveedor.Text = "Acreedor:" + + HdnCveEstatusFactura.Value = dr("CveEstatusFactura").ToString + LblCompraEstatus.Text = dr("EstatusFactura").ToString + If dr("CveEstatusFactura").ToString = "2" Then ChkProgramarPago.Checked = True + + TrRembolsoUpdate.Visible = True + TrRembolsoNumero.Visible = True + + Dim DtPersonal = GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltraParametros("", "NombreCompleto") + DdlRembolsoPersonal.DataSource = DtPersonal + DdlRembolsoPersonal.Items.Insert(0, New ListItem("Sin Seleccionar", "-1")) + DdlRembolsoPersonal.DataBind() + If dr("CvePersonal").ToString.ToEntero > 0 Then + DdlRembolsoPersonal.SelectedValueExist(dr("CvePersonal").ToString) + TxtRembolsoNumero.Text = dr("NumeroReembolso").ToString + RblRembolso.SelectedValuesIfExist("1") + TrRembolsoPersonal.Visible = True + End If + + Dim DtCajaChica As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario) + DtCajaChica = DtCajaChica.FiltraParametros(String.Format("CveTipoCuenta = 1")) + DdlRembolsoCajaChica.DataSource = DtCajaChica + DdlRembolsoCajaChica.Items.Insert(0, New ListItem("Sin Seleccionar", "-1")) + DdlRembolsoCajaChica.DataBind() + If dr("CveCajaChica").ToString.ToEntero > 0 Then + DdlRembolsoCajaChica.SelectedValueExist(dr("CveCajaChica").ToString) + TxtRembolsoNumero.Text = dr("NumeroReembolso").ToString + RblRembolso.SelectedValuesIfExist("2") + TrRembolsoCajaChica.Visible = True + End If + + VisualizaEstatusCompraSaldo(dr("TipoDocto").ToString, dr("Saldo").ToString.ToDecimal, dr("Total").ToString.ToDecimal) + If dr("IdPoliza").ToString.ToEntero > 0 Then + HplCompraContabilizada.Text = "Si" + HplCompraContabilizada.NavigateUrl = String.Format("/Contabilidad/RegPoliza.aspx?IdPoliza={0}", dr("IdPoliza")) + LblCompraEstatus.ForeColor = Drawing.Color.Navy + trContabilizada.Visible = True + If UsuarioActual.TienePermisoProceso(107) Then BtnDescontabilizar.Visible = True + Else + BtnDescontabilizar.Visible = False + HplCompraContabilizada.Text = "No" + trContabilizada.Visible = True + If UsuarioActual.Empresa.UsaAC Then + LBContabilizarAC.Visible = True + End If + End If + UPPDescontablizar.Update() + + TxtFechaPago.Text = dr("FechaVencimiento").ToString.ToDate.ToShortDateString + RowBitacora.Visible = True + CargaEventoBitacora() + 'ImgAddObs.Attributes.Add("onclick", "javascript: PosicionaObjeto(this.id,'DivEventoBitacora',null,-250,-250); $('#DivEventoBitacora').show(1000); ") + ImgAddObs.Visible = True + ChkAplicaNotaCredito.Checked = CBool(dr("AplicaNotaCredito").ToString) + 'RBLPago.Enabled = False + 'If dr("CveIE").ToString.ToEntero > 0 Then + ' RBLPago.SelectedValue = "2" + ' 'cargo los datos del pago + ' 'PnlPago.Visible = True + ' 'PnlChkFuncionariosEmpleados.Visible = True + + ' Dim ObjIE As New ClsBancos() + + ' If ObjIE.GetBancosIE(dr("CveIE").ToString.ToEntero, UsuarioActual.CveEmpresa) Then + ' If ObjIE.DtResultados.Rows.Count > 0 Then + + ' DdlTipoTransaccion.SelectedValue = ObjIE.CveTipoTransaccion.ToString + ' DdlCuenta.SelectedValue = ObjIE.CveCuenta.ToString + ' TxtDocumentoFolio.Text = ObjIE.Folio + ' TxtDocumentoImporte.Text = ObjIE.Importe.FormatoNumero + ' TxtDocumentoObservaciones.Text = ObjIE.Observaciones + + ' End If + ' End If + + ' ObjIE.Dispose() + 'End If + CompraSaldo = TotalGeneral - LblAmortizacion.Text.ToDouble + If EmpresaPrueba Then + CompraSaldo = dr("Saldo").ToString.ToDouble + End If + + If CompraSaldo > dr("Saldo").ToString.ToDouble Then + CompraSaldo = dr("Saldo").ToString.ToDouble + End If + HdnCompraSaldo.Value = CompraSaldo.ToString + + If CompraSaldo > 0 And UsuarioActual.TienePermisoProceso(100) Then + HLPagar.Visible = True + HLPagar.NavigateUrl = $"/Bancos/PopIECompras.aspx?CveCompra={CveCompra}&TB_iframe=true&height=520&width=700" + End If + + If dr("CveFactura").ToString.ToEntero > 0 Then + ImgDownXML.Visible = True : ImgDownXML.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=Fact&EXT=xml&CveFactura={0}&RFC={1}", dr("CveFactura"), dr("RFC").ToString.Replace("&", "%26%")))) + ImgDownPDF.Visible = True : ImgDownPDF.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=Fact&EXT=pdf&CveFactura={0}&RFC={1}", dr("CveFactura"), dr("RFC").ToString.Replace("&", "%26%")))) + End If + + 'CargaDetalle + If ObjCompra.GetCompraDetalle(CveCompra) Then + TmpDT = ObjCompra.DtResultados + TmpDTOriginal = ObjCompra.DtResultados.Copy + + TmpDT.Columns.Add("CveClasificacionActualizar", GetType(Integer)) + 'TmpDT.Columns.Add("CveEq", GetType(Integer)) + TmpDT.Columns.Add("CveAlmacen", GetType(Integer)) + 'TmpDT.Columns.Add("CvePersonal", GetType(Integer)) + + TmpDT.Columns.Add("IdCuentaComprometido", GetType(Integer)) + TmpDT.Columns.Add("IdCuentaPorEjercer", GetType(Integer)) + TmpDT.Columns.Add("IdCuentaDevengado", GetType(Integer)) + TmpDT.Columns.Add("IdCuentaMatriz", GetType(Integer)) + + TmpDT.Columns.Add("PSDescripcion", GetType(String)) + TmpDT.Columns.Add("ProductoOC", GetType(String)) + TmpDT.Columns.Add("CantidadF", GetType(Double)) + + 'Consignaciones + TmpDT.Columns.Add("CveAlmacenConsignacion", GetType(Integer)) + TmpDT.Columns.Add("NoConsignacion", GetType(Integer)) + TmpDT.Columns.Add("CveConsignacion", GetType(Integer)) + TmpDT.Columns.Add("HdnPS", GetType(String)) + TmpDT.Columns.Add("HdnCvePS", GetType(String)) + TmpDT.Columns.Add("HdnClasificacion", GetType(String)) + TmpDT.Columns.Add("HdnCveClasificacion", GetType(String)) + TmpDT.Columns.Add("HdnCveAlmacen", GetType(String)) + + 'INVENTARIO SERIE/LOTE + TmpDT.Columns.Add("CveMetodoInventario", GetType(Integer)) + + 'Fletes y Servicios + 'TmpDT.Columns.Add("AplicaCostoIndirecto", GetType(Integer)) 'Ya traemos el estatus flete + TmpDT.Columns.Add("CostoIndirectoAlmacen", GetType(Decimal)) + TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) + + TmpDT.Columns.Add("CveContrato", GetType(Integer)) + + + + GvPS.DataSource = TmpDT + GvPS.DataBind() + + If UsuarioActual.Empresa.UsaAC Then + CargaHidendsAC() + End If + + CalculaTotales(True) + + If UsuarioActual.Empresa.UsaInventarios Then + DtInv = TmpDT.FiltraParametros(String.Format("CveTipoPS = 2")).Copy + + If dr("Inventario").ToString = "1" Then + + CveMovimientoAlmacen = dr("CveMovimiento").ToString.ToEntero + + Dim Inv As New ClsInventarios + If Inv.GetMovimientosDetalle(dr("CveMovimiento").ToString.ToEntero, UsuarioActual.CveEmpresa) Then + 'Dim TempParametros = Encripta(String.Format("OP=Alm&CveMovimiento={0}", dr("CveMovimiento"))) + 'ImgImprimirAlmacen.NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", TempParametros) + + ImgImprimirAlmacen.Visible = True + ImgImprimirAlmacen.NavigateUrl = String.Format("/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}", dr("CveMovimiento")) + + Dim drt As DataRow + 'actualizo el almacen + For Each dri As DataRow In DtInv.Rows + + drt = Inv.DtResultados.FiltroPrimero(String.Format("CvePS = {0} AND Cantidad = {1}", dri("CvePS"), dri("Cantidad"))) + If drt IsNot Nothing Then + Dim TmpDr As DataRow = TmpDT.Select($"Consec = {dri("Consec").ToString.ToEntero}")(0) 'Charlie + TmpDr("CveAlmacen") = drt("CveAlmacen") 'Charlie + + dri("CveAlmacen") = drt("CveAlmacen") + + End If + + Next + + End If + + 'Proceso Super Tramposo de Charlie + If Inv.GetMovimientosDetalle(dr("CveMovimiento").ToString.ToEntero, UsuarioActual.CveEmpresa, CveCompra:=-123) Then + Dim drt As DataRow + For Each dri As DataRow In DtInv.Rows + drt = Inv.DtResultados.FiltroPrimero(String.Format("CvePS = {0} AND Cantidad = {1}", dri("CvePS"), dri("Cantidad"))) + If drt IsNot Nothing Then + Dim TmpDr As DataRow = TmpDT.Select($"Consec = {dri("Consec").ToString.ToEntero}")(0) + TmpDr("CveAlmacen") = drt("CveAlmacen") + End If + Next + End If + + Inv.Dispose() + + End If + + CargaGvInv() + + 'Ocultamos "Recibir Aqui" + GvInv.Columns(6).Visible = False + GvInv.Columns(7).Visible = False + + End If + End If + + DdlTipoComprobante.Enabled = False + DdlTipoComprobante.SelectedValue = dr("TipoDocto").ToString + If dr("TipoDocto").ToString = "Fac" Then + ChkAplicaNotaCredito.Enabled = True + ImgAnticiposPendientes.Visible = True + Else + ImgAnticiposPendientes.Visible = False + ChkAplicaNotaCredito.Enabled = False + End If + HlProveedor.HRef = "" + TxtCodigo.ReadOnly = True + 'IPP Usuario Sistema No Bloquea, se cambió al proceso + If UsuarioActual.TienePermisoProceso(79) Then + TxtCantidad.Enabled = True + TxtPrecio.Enabled = True + Else + TxtCantidad.Enabled = False + TxtPrecio.Enabled = False + End If + + DdlPS.Enabled = False + TxtObsPS.Enabled = False + 'ImgAmort.Attributes.Clear() + LbAgregar.Enabled = False + TxtSerie.Enabled = False TxtFolio.Enabled = False - TxtFecha.Enabled = UsuarioActual.TienePermisoProceso(216) - ImgFecha.Enabled = UsuarioActual.TienePermisoProceso(216) - CEFecha.Enabled = UsuarioActual.TienePermisoProceso(216) - - DdlProveedor.Enabled = False - DdlProveedorSucursal.Enabled = False - DdlEstatus.Enabled = False - DdlMoneda.Enabled = False - DdlRetIVAConcepto.Enabled = False - DdlRetISRConcepto.Enabled = False - If UsuarioActual.TienePermisoProceso(79) Then - BtnActualizar.Visible = True - DdlProveedorSucursal.Enabled = True - DdlPS.Enabled = True - TxtObsPS.Enabled = True - LbAgregar.Enabled = True - LnkUpdateFechaPago.Visible = True - End If - - BtnGuardar.Visible = False - BtnGuardar.Enabled = False - UpPSS.Update() - - 'GvLeyendasFiscales.Enabled = False - TxtSubTotal.ReadOnly = True - TxtIVA.ReadOnly = True - TxtRetIVA.ReadOnly = True - TxtRetISR.ReadOnly = True - TxtIEPS.ReadOnly = True - TxtOtrosImpuestos.ReadOnly = True - TxtTotal.ReadOnly = True - - - 'CargaLeyendasFiscales - ViewState("CompraFolio") = TxtFolio.Text.Trim - - Dim dtnc As DataTable = Nothing - If dr("TipoDocto").ToString = "Fac" Then - 'carga as notas de credito vinculadas - If ObjCompra.GetComprasNotasCredito(CveCompra, -1) Then - dtnc = ObjCompra.DtResultados - End If - ElseIf dr("TipoDocto").ToString.Contiene("NC", "DEV", "Ant") Then - If dr("TipoDocto").ToString = "NC" Then - DivReembolso.Visible = False - RBLPago.Items(2).Enabled = False - End If - If ObjCompra.GetComprasNotasCredito(-1, CveCompra) Then - dtnc = ObjCompra.DtResultados - GvAnticiposSel.Caption = "
Compras Aplicadas
" - End If - End If - - - 'VINCULACIÓN OC - NUEVA DICIEMBRE 2015 - If dr("OCVinculada").ToString() <> "" Then - Dim DtOCs As New DataTable - Dim OCS = "", CveOCS = "" - - DtOCs.Columns.Add("FolioOC", GetType(Integer)) - DtOCs.Columns.Add("CveOrdenCompra", GetType(Integer)) - - - For Each drt As DataRow In TmpDT.Rows - If drt("FolioOC").ToString <> "" Then - Dim DrOC = DtOCs.NewRow - DrOC("FolioOC") = drt("FolioOC").ToString - DrOC("CveOrdenCompra") = drt("CveOrdenCompra").ToString - DtOCs.Rows.Add(DrOC) - End If - Next - - DtOCs = DtOCs.FiltraParametros("", "", {"FolioOC", "CveOrdenCompra"}) - DtOCs.Columns.Add("Fecha", GetType(Date)) - DtOCs.Columns.Add("Descripcion", GetType(String)) - - If DtOCs.Rows.Count > 0 Then - For Each drt As DataRow In DtOCs.Rows - If ObjOC.GetOrdenesCompraRep("OC", -1, -1, -1, -1, MinFecha, MaxFecha, drt("CveOrdenCompra").ToString.ToEntero, CveProveedor, -1, -1, -1, UsuarioActual.CveEmpresa, -1) Then - If ObjOC.DtResultados.Rows.Count = 1 Then - OCS += If(OCS <> "", String.Format(",{0}", drt("FolioOC").ToString), drt("FolioOC").ToString) - CveOCS += If(CveOCS <> "", String.Format(",{0}", drt("CveOrdenCompra").ToString), drt("CveOrdenCompra").ToString) - drt("Fecha") = ObjOC.DtResultados.FiltroPrimeroValor("FechaIng") - drt("Descripcion") = ObjOC.DtResultados.FiltroPrimeroValor("Descripcion") - End If - End If - Next - End If - - TxtOC.Text = OCS - TieneOC = True - - If DtOCs.Rows.Count > 1 Then - HLOCsVinculadas.Visible = True - GvOCsVinculadas.DataSource = DtOCs - GvOCsVinculadas.DataBind() - UpOCsVinculadas.Update() - ElseIf DtOCs.Rows.Count = 1 Then - HLOCsVinculadas.Visible = True - HLOCsVinculadas.Attributes.Remove("data-toggle") - HLOCsVinculadas.Attributes.Remove("data-target") - HLOCsVinculadas.Attributes.Add("data-toggle", "tooltip") - HLOCsVinculadas.NavigateUrl = $"/OC/OC.aspx?OC={DtOCs.FiltroPrimeroValor("CveOrdenCompra")}" - HLOCsVinculadas.Target = "_blank" - End If - - - End If - - 'BLOQUEA OC - TxtOC.Enabled = False - ImgBtnBuscarOC.Visible = False - TAB.ActiveTabIndex = 0 - - GvAnticiposSel.DataSource = dtnc - GvAnticiposSel.DataBind() - - - '' VALIDA ELIMINAR COMPRA - If UsuarioActual.TienePermisoProceso(77) OrElse UsuarioActual.TienePermisoProceso(135) Then ' Eliminar compra - - 'SIN VINCULACIÓN - If UsuarioActual.TienePermisoProceso(135) Then - If TxtOC.Text = "" AndAlso IdPoliza < 1 AndAlso CveMovimientoAlmacen < 1 AndAlso LblUsuarioCaptura.Text = UsuarioActual.Usuario AndAlso TmpDT.MAX("CveActivoFijo").ToEntero < 1 AndAlso Not ChkProgramarPago.Checked AndAlso CompraSaldo = TxtTotal.Text.ToDouble Then - BtnEliminarCompra.Visible = True - End If - End If - - 'ELIMINAR A FUERZAS - If UsuarioActual.TienePermisoProceso(77) Then - If Not (IdPoliza > 0) Then - BtnEliminarCompra.Visible = True - End If - End If - - - Dim StrInventario As String = "" - If dr("Inventario").ToString = "1" Then - StrInventario = "los Movimientos de Inventario relacionados" - End If - - If UsuarioActual.Empresa.UsaAC Then - BtnEliminarCompra.Attributes.Add("data-original-title", String.Format("¿Está seguro que desea eliminar la Compra, {0} y la Poliza Asociada?", StrInventario)) - Else - BtnEliminarCompra.Attributes.Add("data-original-title", String.Format("¿Está seguro que desea eliminar la Compra y {0}?", StrInventario)) - End If - End If - - 'VALIDA CANCELAR COMPRA - AC - ValidaCancelarCompra() - - 'CUANDO ESTA CANCELADA - If dr("CveEstatusFactura").ToString = "-2" Then - BtnEliminarCompra.Visible = False - BtnActualizar.Visible = False - BtnGuardar.Visible = False - BtnCancelarCompra.Visible = False - - LblCompraEstatus.Text = "CANCELADA" - LblCompraEstatus.Font.Bold = True - LblCompraEstatus.Font.Size = 12 - LblCompraEstatus.ForeColor = Drawing.Color.DarkRed - 'HplIr.Visible = False - - BtnDescontabilizar.Visible = False - BtnEliminarPolizaMultiple.Visible = False - - 'LIGA POLIZA CANCELACIÓN - 'HplPolizaCancelación.NavigateUrl = String.Format("/Contabilidad/RegPoliza.aspx?IdPoliza={0}", dr("IdPoliza")) - - End If - - 'CUANDO FUE REFACTURADA - If dr("CompraRefacturada").ToString.ToEntero > 0 Then - BtnEliminarCompra.Visible = False - BtnActualizar.Visible = False - BtnGuardar.Visible = False - BtnCancelarCompra.Visible = False - End If - - 'TIENE AMORTIZACIÓN - If GvAnticiposSel.Rows.Count > 0 Then - BtnEliminarCompra.Visible = False - If Not DdlTipoComprobante.SelectedValue.Contiene("NC") Then - BtnCancelarCompra.Visible = False - End If - End If - - CargaComplementosPago() - - Else - Alert("La compra solicitada no se encontró. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - End If - Else - Alert("Ocurrió un error al cargar la compra. Por favor vuelta a intentar o comuniquese con Sistemas.", TipoMensaje.MsgError) - End If - - ObjCompra.Dispose() - ObjOC.Dispose() - End Sub - - Private Sub VisualizaEstatusCompraSaldo(TipoDocto As String, Saldo As Decimal, Total As Decimal) - - If TipoDocto.Contiene("Fac", "Ant") Then - - If HdnCveEstatusFactura.Value.ToEntero = 6 Then - LblCompraEstatus.Text = "Vinculada a Crédito" - LblCompraEstatus.Font.Bold = True - LblCompraEstatus.Font.Size = 12 - LblCompraEstatus.ForeColor = Drawing.Color.Navy - BtnAceptarAnticipos.Visible = False - trImporte.Visible = False - HplImporte.Visible = False - HplImporte.Text = "" - HplImporte.NavigateUrl = "" - - Else - If Saldo <= 0 Then - LblCompraEstatus.Text = "PAGADA" - LblCompraEstatus.Font.Bold = True - LblCompraEstatus.Font.Size = 12 - LblCompraEstatus.ForeColor = Drawing.Color.Navy - BtnAceptarAnticipos.Visible = False - trImporte.Visible = True - HplImporte.Visible = True - HplImporte.Text = String.Format("$ {0}", Total.FormatoNumero()) - HplImporte.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxPProveedor&CveProveedor={0}&CveCompra={1}&TB_iframe=true&height=700&width=920", CveProveedor, CveCompra) - - - Else - If Saldo < Total Then - LblCompraEstatus.Text = "ABONADA" + TxtFecha.Enabled = False + ImgFecha.Enabled = False + CEFecha.Enabled = False + + DdlProveedor.Enabled = False + DdlProveedorSucursal.Enabled = False + DdlEstatus.Enabled = False + DdlMoneda.Enabled = False + DdlRetIVAConcepto.Enabled = False + DdlRetISRConcepto.Enabled = False + If UsuarioActual.TienePermisoProceso(79) Then + BtnActualizar.Visible = True + DdlProveedorSucursal.Enabled = True + DdlPS.Enabled = True + TxtObsPS.Enabled = True + LbAgregar.Enabled = True + LnkUpdateFechaPago.Visible = True + End If + + BtnGuardar.Visible = False + BtnGuardar.Enabled = False + UpPSS.Update() + + 'GvLeyendasFiscales.Enabled = False + TxtSubTotal.ReadOnly = True + TxtIVA.ReadOnly = True + TxtRetIVA.ReadOnly = True + TxtRetISR.ReadOnly = True + TxtIEPS.ReadOnly = True + TxtOtrosImpuestos.ReadOnly = True + TxtTotal.ReadOnly = True + + + 'CargaLeyendasFiscales + ViewState("CompraFolio") = TxtFolio.Text.Trim + + Dim dtnc As DataTable = Nothing + If dr("TipoDocto").ToString = "Fac" Then + 'carga as notas de credito vinculadas + If ObjCompra.GetComprasNotasCredito(CveCompra, -1) Then + dtnc = ObjCompra.DtResultados + End If + ElseIf dr("TipoDocto").ToString.Contiene("NC", "DEV", "Ant") Then + If dr("TipoDocto").ToString = "NC" Then + DivReembolso.Visible = False + RBLPago.Items(2).Enabled = False + End If + If ObjCompra.GetComprasNotasCredito(-1, CveCompra) Then + dtnc = ObjCompra.DtResultados + GvAnticiposSel.Caption = "
Compras Aplicadas
" + End If + End If + + + 'VINCULACIÓN OC - NUEVA DICIEMBRE 2015 + If dr("OCVinculada").ToString() <> "" Then + Dim DtOCs As New DataTable + Dim OCS = "", CveOCS = "" + + DtOCs.Columns.Add("FolioOC", GetType(Integer)) + DtOCs.Columns.Add("CveOrdenCompra", GetType(Integer)) + + + For Each drt As DataRow In TmpDT.Rows + If drt("FolioOC").ToString <> "" Then + Dim DrOC = DtOCs.NewRow + DrOC("FolioOC") = drt("FolioOC").ToString + DrOC("CveOrdenCompra") = drt("CveOrdenCompra").ToString + DtOCs.Rows.Add(DrOC) + End If + Next + + DtOCs = DtOCs.FiltraParametros("", "", {"FolioOC", "CveOrdenCompra"}) + DtOCs.Columns.Add("Fecha", GetType(Date)) + DtOCs.Columns.Add("Descripcion", GetType(String)) + + If DtOCs.Rows.Count > 0 Then + For Each drt As DataRow In DtOCs.Rows + If ObjOC.GetOrdenesCompraRep("OC", -1, -1, -1, -1, MinFecha, MaxFecha, drt("CveOrdenCompra").ToString.ToEntero, CveProveedor, -1, -1, -1, UsuarioActual.CveEmpresa, -1) Then + If ObjOC.DtResultados.Rows.Count = 1 Then + OCS += If(OCS <> "", String.Format(",{0}", drt("FolioOC").ToString), drt("FolioOC").ToString) + CveOCS += If(CveOCS <> "", String.Format(",{0}", drt("CveOrdenCompra").ToString), drt("CveOrdenCompra").ToString) + drt("Fecha") = ObjOC.DtResultados.FiltroPrimeroValor("FechaIng") + drt("Descripcion") = ObjOC.DtResultados.FiltroPrimeroValor("Descripcion") + End If + End If + Next + End If + + TxtOC.Text = OCS + TieneOC = True + + If DtOCs.Rows.Count > 1 Then + HLOCsVinculadas.Visible = True + GvOCsVinculadas.DataSource = DtOCs + GvOCsVinculadas.DataBind() + UpOCsVinculadas.Update() + ElseIf DtOCs.Rows.Count = 1 Then + HLOCsVinculadas.Visible = True + HLOCsVinculadas.Attributes.Remove("data-toggle") + HLOCsVinculadas.Attributes.Remove("data-target") + HLOCsVinculadas.Attributes.Add("data-toggle", "tooltip") + HLOCsVinculadas.NavigateUrl = $"/OC/OC.aspx?OC={DtOCs.FiltroPrimeroValor("CveOrdenCompra")}" + HLOCsVinculadas.Target = "_blank" + End If + + + End If + + 'BLOQUEA OC + TxtOC.Enabled = False + ImgBtnBuscarOC.Visible = False + Tab.ActiveTabIndex = 0 + + GvAnticiposSel.DataSource = dtnc + GvAnticiposSel.DataBind() + + + '' VALIDA ELIMINAR COMPRA + If UsuarioActual.TienePermisoProceso(77) OrElse UsuarioActual.TienePermisoProceso(135) Then ' Eliminar compra + + 'SIN VINCULACIÓN + If UsuarioActual.TienePermisoProceso(135) Then + If TxtOC.Text = "" AndAlso IdPoliza < 1 AndAlso CveMovimientoAlmacen < 1 AndAlso LblUsuarioCaptura.Text = UsuarioActual.Usuario AndAlso TmpDT.MAX("CveActivoFijo").ToEntero < 1 AndAlso Not ChkProgramarPago.Checked AndAlso CompraSaldo = TxtTotal.Text.ToDouble Then + BtnEliminarCompra.Visible = True + End If + End If + + 'ELIMINAR A FUERZAS + If UsuarioActual.TienePermisoProceso(77) Then + If Not (IdPoliza > 0) Then + BtnEliminarCompra.Visible = True + End If + End If + + + Dim StrInventario As String = "" + If dr("Inventario").ToString = "1" Then + StrInventario = "los Movimientos de Inventario relacionados" + End If + + If UsuarioActual.Empresa.UsaAC Then + BtnEliminarCompra.Attributes.Add("data-original-title", String.Format("¿Está seguro que desea eliminar la Compra, {0} y la Poliza Asociada?", StrInventario)) + Else + BtnEliminarCompra.Attributes.Add("data-original-title", String.Format("¿Está seguro que desea eliminar la Compra y {0}?", StrInventario)) + End If + End If + + 'VALIDA CANCELAR COMPRA - AC + ValidaCancelarCompra() + + 'CUANDO ESTA CANCELADA + If dr("CveEstatusFactura").ToString = "-2" Then + BtnEliminarCompra.Visible = False + BtnActualizar.Visible = False + BtnGuardar.Visible = False + BtnCancelarCompra.Visible = False + + LblCompraEstatus.Text = "CANCELADA" + LblCompraEstatus.Font.Bold = True + LblCompraEstatus.Font.Size = 12 + LblCompraEstatus.ForeColor = Drawing.Color.DarkRed + 'HplIr.Visible = False + + BtnDescontabilizar.Visible = False + BtnEliminarPolizaMultiple.Visible = False + + 'LIGA POLIZA CANCELACIÓN + 'HplPolizaCancelación.NavigateUrl = String.Format("/Contabilidad/RegPoliza.aspx?IdPoliza={0}", dr("IdPoliza")) + + End If + + 'CUANDO FUE REFACTURADA + If dr("CompraRefacturada").ToString.ToEntero > 0 Then + BtnEliminarCompra.Visible = False + BtnActualizar.Visible = False + BtnGuardar.Visible = False + BtnCancelarCompra.Visible = False + End If + + 'TIENE AMORTIZACIÓN + If GvAnticiposSel.Rows.Count > 0 Then + BtnEliminarCompra.Visible = False + If Not DdlTipoComprobante.SelectedValue.Contiene("NC") Then + BtnCancelarCompra.Visible = False + End If + End If + + CargaComplementosPago() + + Else + Alert("La compra solicitada no se encontró. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + End If + Else + Alert("Ocurrió un error al cargar la compra. Por favor vuelta a intentar o comuniquese con Sistemas.", TipoMensaje.MsgError) + End If + + ObjCompra.Dispose() + ObjOC.Dispose() + End Sub + + Private Sub VisualizaEstatusCompraSaldo(TipoDocto As String, Saldo As Decimal, Total As Decimal) + + If TipoDocto.Contiene("Fac", "Ant") Then + + If HdnCveEstatusFactura.Value.ToEntero = 6 Then + LblCompraEstatus.Text = "Vinculada a Crédito" + LblCompraEstatus.Font.Bold = True + LblCompraEstatus.Font.Size = 12 + LblCompraEstatus.ForeColor = Drawing.Color.Navy + BtnAceptarAnticipos.Visible = False + trImporte.Visible = False + HplImporte.Visible = False + HplImporte.Text = "" + HplImporte.NavigateUrl = "" + + Else + If Saldo <= 0 Then + LblCompraEstatus.Text = "PAGADA" + LblCompraEstatus.Font.Bold = True + LblCompraEstatus.Font.Size = 12 + LblCompraEstatus.ForeColor = Drawing.Color.Navy + BtnAceptarAnticipos.Visible = False + trImporte.Visible = True + HplImporte.Visible = True + HplImporte.Text = String.Format("$ {0}", Total.FormatoNumero()) + HplImporte.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxPProveedor&CveProveedor={0}&CveCompra={1}&TB_iframe=true&height=700&width=920", CveProveedor, CveCompra) + + + Else + If Saldo < Total Then + LblCompraEstatus.Text = "ABONADA" LblCompraEstatus.Font.Bold = True - End If + End If LblCompraEstatus.ForeColor = Drawing.Color.Navy trSaldo.Visible = True HplSaldoAuxiliar.Text = String.Format("$ {0}", Saldo.FormatoNumero()) HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxPProveedor&CveProveedor={0}&CveCompra={1}&TB_iframe=true&height=700&width=920", CveProveedor, CveCompra) - End If - End If - + End If + End If + UpEstatus.Update() Else @@ -3015,1424 +3016,1424 @@ Partial Class Compras_Compras HplSaldoAuxiliar.NavigateUrl = String.Format("/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxPProveedor&CveProveedor={0}&CveCompra={1}&TB_iframe=true&height=700&width=920", CveProveedor, CveCompra) End If - End If - - End Sub - - Private Sub CargaMonedas() - DdlMoneda.DataSource = GlobalDTMonedas - DdlMoneda.DataBind() - End Sub - - Private Sub CargarAlmacen() - 'ddlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen IN (1,2)") 'solo muestra tipo material y herramientas - 'ddlAlmacen.DataBind() - - ddlAlmacenAdd.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen IN (1,2,7,14,19)") 'solo muestra tipo material y herramientas - ddlAlmacenAdd.DataBind() - End Sub - - Protected Sub CargaFuncionariosEmpleados() - 'Cargar los FUncionarios Empleados que tengan saldo - Dim objGastosXComprobar As New ClsMovimientos - Dim dtFE As New DataTable - - If objGastosXComprobar.GetEgresosSinComprobarPersonal(UsuarioActual.CveEmpresa) Then - 'TRATAR DE HACERLO CON c - - dtFE.Columns.Add("CvePersonal", GetType(Integer)) - dtFE.Columns.Add("NombreCompleto", GetType(String)) - dtFE.Columns.Add("Saldo", GetType(Double)) - 'dtFE.Columns.Add("CveIE", GetType(Integer)) - DtFuncionarios = objGastosXComprobar.DtResultados.FiltraParametros("CvePersonal > 0 ") 'objGastosXComprobar.DtResultados.FiltraParametros("CvePersonal > 0 AND Saldo > 0 ") ' saco los egresos sin comprobar de funcionarios y empleados - - For Each Row As DataRow In objGastosXComprobar.DtResultados.FiltraParametros("CvePersonal > 0 ", "NombreCompleto").Rows ' saco los totalizadores - Dim RowFE As DataRow = Nothing - RowFE = dtFE.NewRow() - - RowFE("CvePersonal") = Row("CvePersonal").ToString.ToEntero - RowFE("NombreCompleto") = String.Format("{0} - ${1}", Row("NombreCompleto").ToString.Trim, Row("Saldo").ToString.FormatoNumero(2)) - RowFE("Saldo") = Row("Saldo").ToString.ToDouble - - dtFE.Rows.Add(RowFE) - Next - ' DtFuncionarios = dtFE - 'For Each Row As DataRow In objGastosXComprobar.DtResultados.FiltraParametros("CvePersonal > 0 AND FechaDocumento IS NOT NULL").Rows - ' ArrIE.Add(New Anticipos With {.CveIE = Row("CveIE").ToString.ToEntero, .Importe = Row("Saldo").ToString.ToDouble, .CvePersonal = Row("CvePersonal").ToString.ToEntero}) - 'Next - - - End If - - objGastosXComprobar.Dispose() - - DdlFuncionarioEmpleado.DataSource = dtFE.FiltraParametros("", "NombreCompleto") - DdlFuncionarioEmpleado.DataBind() - - DdlFuncionarioEmpleado.Items.Insert(0, New ListItem("Seleccione Funcionario Empleado", "-1")) - - 'UPCondicionesPago.Update() - UpContado.Update() - End Sub - - Protected Sub CargaDeudores() - 'Cargar los FUncionarios Empleados que tengan saldo - Dim Deudores As New ClsMovimientos - - If RBLTipoDeudor.SelectedValue.ToEntero = 1 Then - If Deudores.GetDeudoresSaldos(-1, UsuarioActual.CveEmpresa) Then - DtDeudores = Deudores.DtResultados.FiltraParametros("CveProveedor > 0") - DdlDeudor.DataSource = DtDeudores - DdlDeudor.DataBind() - - DdlDeudor.Items.Insert(0, New ListItem("Seleccione Deudor", "-1")) - UpContado.Update() - End If - Else - If Deudores.GetDeudoresComisionesSaldos(UsuarioActual.CveEmpresa) Then - DtDeudores = Deudores.DtResultados.FiltraParametros("CveProveedor > 0") - DdlDeudor.DataSource = DtDeudores - DdlDeudor.DataBind() - - DdlDeudor.Items.Insert(0, New ListItem("Seleccione Deudor", "-1")) - UpContado.Update() - End If - End If - - Deudores.Dispose() - End Sub - - Private Sub CreaTmpAcarreos() - tDTAcarreos = New DataTable - tDTAcarreos.Columns.Add("CvePreEstimacion", GetType(Integer)) - tDTAcarreos.Columns.Add("Importe", GetType(Double)) - End Sub - - Protected Sub CargaAcreedores() - Dim ObjMov As New ClsMovimientos - - If ObjMov.GetAcreedoresSaldos(-1, UsuarioActual.CveEmpresa) Then - DtAcreedores = ObjMov.DtResultados.FiltraParametros("CveProveedor > 0") - DdlAcreedor.DataSource = DtAcreedores - DdlAcreedor.DataBind() - - - - DdlAcreedor.Items.Insert(0, New ListItem("Seleccione Acreedor", "-1")) - UpContado.Update() - End If - - ObjMov.Dispose() - End Sub - - Private Sub CargaCreditos() - - Dim Cred As New ClsBancos - Dim Dt As DataTable = Nothing - Dim DtD As DataTable = Nothing - If Cred.GetCreditos(-1, -1, -1, -1, -1, UsuarioActual.CveEmpresa) Then - Dt = Cred.DtResultados.FiltraParametros("CveCredito > 0 AND CveTipoCredito IN (4,5)") - If Dt.Rows.Count > 0 AndAlso Cred.GetCreditosDetalle(Dt.Rows(0)("CveCredito").ToString.ToEntero, -1) Then - DtD = Cred.DtResultados.FiltraParametros("Estatus = 2 AND CveIE IS NOT NULL") - End If - End If - Cred.Dispose() - - If DdlTipoCredito.SelectedValue.ToEntero = 1 Then - Dt = Dt.FiltraParametros("CveCompraFactura IS NULL") - End If - - DdlCredito.DataSource = Dt.FiltraParametros("", DistinctColumns:={"CveCredito", "ReferenciaImporte"}) - DdlCredito.DataBind() - DdlCredito.Items.Insert(0, New ListItem("Seleccione", "-1")) - - - DdlCreditoDetalle.DataSource = DtD - DdlCreditoDetalle.DataBind() - DdlCreditoDetalle.Items.Insert(0, New ListItem("Seleccione", "-1")) - - End Sub - - Private Sub CargaCreditosDetalle(CveCredito As Integer) - Dim Cred As New ClsBancos - - Dim DtD As DataTable = Nothing - - If Cred.GetCreditosDetalle(CveCredito, -1) Then - DtD = Cred.DtResultados.FiltraParametros("Estatus = 2") - End If - Cred.Dispose() - - DdlCreditoDetalle.DataSource = DtD - DdlCreditoDetalle.DataBind() - DdlCreditoDetalle.Items.Insert(0, New ListItem("Seleccione", "-1")) - - End Sub - - Private Sub CargaProveedor(CveProveedor As Integer, RFC As String, Optional RecargaCombo As Boolean = True) - - Dim ObjProveedor As New ClsCompProveedores() - - If ObjProveedor.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, CveProveedor, "-1", "-1", "-1", "-1", RFC, "-1", "-1", -1, UsuarioActual.CveEmpresa) Then - If ObjProveedor.DtResultados.Rows.Count > 0 Then - - If RecargaCombo Then DdlProveedor.DataSource = ObjProveedor.DtResultados : DdlProveedor.DataBind() - - ChkConsignacion.Enabled = True - - ViewState("CveProveedor") = ObjProveedor.CveProveedor - ViewState("CveTipoProveedor") = ObjProveedor.CveTipoProveedor - - 'Conta ContPAQ - ViewState("CtaProveedor") = ObjProveedor.IdCtaContProveedores - ViewState("CtaProveedorAnticipos") = ObjProveedor.IdCtaContAnticipos - ViewState("CtaProveedorAnticiposExtranjera") = ObjProveedor.IdCtaContAnticiposExtranjera - ViewState("CtaProveedorAnticiposComplementaria") = ObjProveedor.IdCtaContAnticiposComplementaria - ViewState("CtaProveedorDeudores") = ObjProveedor.IdCtaContDeudor - ViewState("CtaProveedorAcreedores") = ObjProveedor.IdCtaContAcreedor - ViewState("CtaProveedorRetISR") = ObjProveedor.IdCtaContRetISR - ViewState("CtaProveedorRetIVA") = ObjProveedor.IdCtaContRetIVA - ViewState("CtaProveedorExtranjera") = ObjProveedor.IdCtaContProveedoresExtranjera - ViewState("CtaProveedorComplementaria") = ObjProveedor.IdCtaContProveedoresComplementaria - ViewState("IdCtaContDocsXPagar") = ObjProveedor.IdCtaContDocsXPagar - - 'Conta SIG - ViewState("CveCuentaProveedor") = ObjProveedor.CveCuentaProveedores - ViewState("CveCuentaProveedorAnticipos") = ObjProveedor.CveCuentaAnticipos - ViewState("CveCuentaProveedorAnticiposExtranjera") = ObjProveedor.CveCuentaAnticiposExtranjera - ViewState("CveCuentaProveedorAnticiposComplementaria") = ObjProveedor.CveCuentaAnticiposComplementaria - ViewState("CveCuentaProveedorDeudores") = ObjProveedor.CveCuentaDeudor - ViewState("CveCuentaProveedorAcreedores") = ObjProveedor.CveCuentaAcreedor - ViewState("CveCuentaProveedorRetISR") = ObjProveedor.CveCuentaRetISR - ViewState("CveCuentaProveedorRetIVA") = ObjProveedor.CveCuentaRetIVA - ViewState("CveCuentaProveedorExtranjera") = ObjProveedor.CveCuentaProveedoresExtranjera - ViewState("CveCuentaProveedorComplementaria") = ObjProveedor.CveCuentaProveedoresComplementaria - - - ViewState("NombreProveedor") = ObjProveedor.RazonSocial - - HdnCveProveedor.Value = ObjProveedor.CveProveedor.ToString - - If ObjProveedor.EditarFolioDuplicado Then - TxtFolio.Enabled = True - TxtSerie.Enabled = True - End If - - TxtCodigo.Text = ObjProveedor.Codigo - LblRFC.Text = String.Format("{1}", Me.CveProveedor, ObjProveedor.RFC) - HplProveedor.Text = ObjProveedor.NombreComercial : HplProveedor.NavigateUrl = String.Format("/Compras/Proveedores.aspx?CveProveedor={0}", Me.CveProveedor) - DdlProveedor.SelectedValue = ObjProveedor.CveProveedor.ToString - LblDiasCredito.Text = ObjProveedor.PlazoPago.ToString - LblLimiteCredito.Text = ObjProveedor.LimiteCredito.FormatoNumero - LblCreditoDisponible.Text = ObjProveedor.LimiteCredito.FormatoNumero - - If Not CveCompra > 0 Then '[IPP] SI YA ESTA REGISTRADA LOS VALORES SE CARGAN EN EL CARGACOMPRA() - 'DF 11-04-17 - Dim dtprovsuc As DataTable = GlobalDTProveedorSucursales(ObjProveedor.CveProveedor, UsuarioActual.CveEmpresa) - If dtprovsuc IsNot Nothing AndAlso dtprovsuc.Rows.Count > 0 Then - RowProveedorSucursal.Visible = True - DdlProveedorSucursal.Items.Clear() - DdlProveedorSucursal.DataSource = dtprovsuc - DdlProveedorSucursal.DataBind() - DdlProveedorSucursal.Items.Insert(0, New ListItem("Seleccione", "-1")) - DdlProveedorSucursal.Items.Insert(0, New ListItem("Matriz", "0")) - 'si tiene una serie cargada, sugiere la sucursal - If TxtSerie.Text.Trim <> "" Then - DdlProveedorSucursal.SelectedValueExist(dtprovsuc.FiltroPrimeroValor("CveProveedorSucursal", $"Serie LIKE '%{TxtSerie.Text.Trim}%'").ToString()) - End If - Else - RowProveedorSucursal.Visible = False - DdlProveedorSucursal.Items.Clear() - DdlProveedorSucursal.Items.Insert(0, New ListItem("N/A", "-1")) - DdlProveedorSucursal.DataBind() - End If - End If - - If CveCompra <= 0 AndAlso CveFactura <= 0 Then 'si se está cargando una factura o compra no se carga - 'LblRetIVA.Text = ObjProveedor.RetIVA.ToString.FormatoNumero(5) - 'LblRetISR.Text = ObjProveedor.RetISR.ToString.FormatoNumero(5) - - If ObjProveedor.RFC = "XAXX010101000" Then ' RFC Generico - 'cuando se esta dando de alta de nueva la compra, se obtiene el folio siguiente de no deducibles - Dim ObjComp As New ClsCompras - TxtFolio.Text = ObjComp.GetSiguienteFolio(ObjProveedor.CveProveedor, TxtSerie.Text).ToString - ObjComp.Dispose() - End If - End If - ViewState("IVA") = ObjProveedor.IVA - HdnProveedorIVA.Value = ObjProveedor.IVA.ToString - - ViewState("IdCtaContProveedores") = ObjProveedor.IdCtaContProveedores - ViewState("IdCtaContAnticipos") = ObjProveedor.IdCtaContAnticipos - ViewState("IdCtaProveedorDeudores") = ObjProveedor.IdCtaContDeudor - ViewState("IdCtaProveedorAcreedores") = ObjProveedor.IdCtaContAcreedor - ViewState("IdCtaContRetIVA") = ObjProveedor.IdCtaContRetIVA - ViewState("IdCtaContRetISR") = ObjProveedor.IdCtaContRetISR - - If UsuarioActual.Empresa.Funcionalidad(200) = "1" AndAlso ObjProveedor.IdCtaContProveedores < 1 Then - Alert("El Proveedor seleccionado no tiene cuenta contable asignada.", TipoMensaje.MsgAdvertencia) - End If - - ViewState("CveProveedor") = ObjProveedor.CveProveedor - HdnCveProveedor.Value = ObjProveedor.CveProveedor.ToString - TxtFechaPago.Text = (TxtFecha.Text.ToDate.AddDays(LblDiasCredito.Text.ToEntero)).ToShortDateString - RFCProv = ObjProveedor.RFC - CargaRetIVAConcepto(True) - CargaRetISRConcepto(True) - - If ObjProveedor.DIOTCveTipoOperacion = 1 Then '03 - Prestación de Servicios Profesionales - DdlRetIVAConcepto.SelectedValueExist("1") - DdlRetISRConcepto.SelectedValueExist("1") ' honorarios - ElseIf ObjProveedor.DIOTCveTipoOperacion = 2 Then ' 06 - Arrendamiento de inmuebles - DdlRetIVAConcepto.SelectedValueExist("4") - DdlRetISRConcepto.SelectedValueExist("2") ' arrendamiento - ElseIf ObjProveedor.DIOTCveTipoOperacion = 3 Then ' 85 - Otros - DdlRetIVAConcepto.SelectedValueExist("2") ' flete pf - DdlRetIVAConcepto.SelectedValueExist("3") ' fletes pm - DdlRetISRConcepto.SelectedValueExist("1") ' honorarios - End If - - LbAgregar.Enabled = True - UpPSS.Update() - UpPS.Update() - UpParametros.Update() - UPCondicionesPago.Update() - 'si tiene el habiltiado el módulo de Contratos - 'checo si tiene estimaciones - - 'CargaDatosEstimaciones(ObjProveedor.CveProveedor) - ImgBtnBuscarOC.OnClientClick = String.Format("AbrirVentana('/OC/PopUpBuscarReq.aspx?V=VOCCOMP&P={0}&T={1}&Masterimpoup=true',1000,600,'S'); return false;", ObjProveedor.CveProveedor, DdlTipoComprobante.SelectedValue) - CargaAnticipos(ObjProveedor.CveProveedor) : UpAnticipos.Update() - - If UsuarioActual.Empresa.UsaAC Then - If (TxtRetIVA.Text.ToDouble > 0 And Not ObjProveedor.IdCtaContRetIVA > 0) Or (TxtRetISR.Text.ToDouble > 0 And Not ObjProveedor.IdCtaContRetISR > 0) Then ' - ImgBtnBuscarOC.Visible = False - TxtOC.Enabled = False - BtnGuardar.Visible = False - Alert("El proveedor no tiene registrada cuentas contables de retenciones. Debe asignar las cuentas en el registro del proveedor.", TipoMensaje.MsgAdvertencia) - DivRestriccionAdvertencia.Visible = True - LtRestriccionAdvertencia.Text = "El proveedor no tiene registrada cuentas contables de retenciones." - End If - End If - - CargaGvAcarreos(ViewState("CveProveedor").ToString.ToEntero) - - - 'MONEDA PREFERENTE - If CveCompra <= 0 Then - If CveFactura <= 0 Then - DdlMoneda.SelectedValueExist(ObjProveedor.CveMonedaPreferente) - End If - CambiaMoneda(False) - End If - - - If CveProveedor > 0 Then - - Dim ObjSAT As New ClsSAT - Dim RFCRequest As String = ObjProveedor.RFC - If ObjSAT.GetListado69B(2, UsuarioActual.CveEmpresa, RFCRequest) Then - If ObjSAT.DtResultados.Rows.Count > 0 Then - Dim Estatus As String = ObjSAT.DtResultados.Rows(0)("Situacion").ToString - BtnGuardar.Enabled = False - UpParametros.Update() - - Alert($"El RFC del proveedor se encuentra en estado {Estatus} en el Listado EFOS (69B) del SAT", TipoMensaje.MsgAdvertencia) - System.Threading.Thread.Sleep(5) - End If - End If - ObjSAT.Dispose() - - End If - - - - Else - Alert("El Proveedor solicitado no existe, por favor intente de nuevo.", TipoMensaje.MsgAdvertencia) - End If - Else - Alert("Ocurrió un error al consultar el proveedor.", TipoMensaje.MsgError) - End If - - If UsuarioActual.Empresa.Funcionalidad(560) = "1" Then - If ObjProveedor.GetProveedoresEvaluacionPediente(Me.CveProveedor, UsuarioActual.CveEmpresa) Then - If ObjProveedor.DtResultados.Rows.Count > 0 Then - Me.RequiereEvaluacion = ObjProveedor.DtResultados.Rows(0)("RequiereEvaluacion").ToString() = "1" - Me.CveUsuarioEvaluador = ObjProveedor.DtResultados.Rows(0)("CveUsuarioEvaluador").ToString().ToEntero() - End If - End If - End If - - ObjProveedor.Dispose() - End Sub - - Private Sub CargaAnticipos(CveProveedor As Integer, Optional FiltroTipo As String = "-1") - Dim ObjMovtos As New ClsMovimientos() - If ObjMovtos.GetAnticiposProveedor(CveProveedor, -1, CveMoneda:=-1, SelectTop:=-1, TipoDocto:=FiltroTipo) AndAlso ObjMovtos.DtResultados.Rows.Count > 0 Then - Dim CveMoneda As Integer = If(ChkPagarConPesos.Checked, 1, If(ChkPagarConDolares.Checked, 2, DdlMoneda.SelectedValue.ToEntero)) - If DdlMoneda.SelectedValue.ToEntero = 1 AndAlso CveCompra > 0 Then DivPagarConDolares.Visible = True Else If CveCompra > 0 Then DivPagarConPesos.Visible = True - GVAnticipos.DataSource = ObjMovtos.DtResultados.FiltraParametros($"Tipo = 'Act' AND CveMoneda = {CveMoneda}") - If ObjMovtos.DtResultados.FiltraParametros("Saldo > 0").Rows.Count > 0 Then - BtnAceptarAnticipos.Enabled = True - If DdlTipoComprobante.SelectedValue = "Fac" Then ImgAnticiposPendientes.Visible = True - End If - Else - GVAnticipos.DataSource = Nothing - End If - ObjMovtos.Dispose() - GVAnticipos.DataBind() - End Sub - - Private Sub CargaTiposAF() - ViewState("TmpDTTiposAF") = GlobalDTTipoActivoFijo(UsuarioActual.CveEmpresa) - Dim Row As DataRow = DirectCast(ViewState("TmpDTTiposAF"), DataTable).NewRow() - Row("CveTipoActivoFijo") = -1 : Row("TipoActivoFijo") = "Seleccione" - DirectCast(ViewState("TmpDTTiposAF"), DataTable).Rows.InsertAt(Row, 0) - End Sub - - Public Function isWhitFamily() As Boolean - Return UsuarioActual.CveEmpresa = 66 - End Function - - Private Sub CargaPSAlias() - DdlPSAlias2.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1") - - If UsuarioActual.CveEmpresa = 66 Then - DdlPSAlias2.ddlWS.Attributes.Add("data-subfamilia", "-1") - DdlPSAlias2.ddlWS.Attributes.Add("data-fueporxml", "0") - 'SOLO CUANDO SEA FACTURA DE INGRESOS - If DdlTipoComprobante.SelectedValue = "Fac" Then - DdlPSAlias2.ddlWS.Attributes.Add("data-pagina", "Compras") - Else - DdlPSAlias2.ddlWS.Attributes.Add("data-pagina", "Compras2") - End If - End If - If Not DdlPSAlias2.UsaWebService AndAlso CType(DdlPSAlias2.DataSource, DataTable) Is Nothing Then - DdlPSAlias2.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa) - DdlPSAlias2.DataBind() - End If - - End Sub - - Private Sub CargarUM(CvePS As Integer, ob As DropDownList) - Dim ObjUM As New ClsProductosServicios() - If ObjUM.GetPSEquivalencias(CvePS, UsuarioActual.CveEmpresa) Then - ViewState("DTUM") = ObjUM.DtResultados - ob.Items.Clear() - ob.DataSource = DTUM - ob.DataBind() - - End If - ObjUM.Dispose() - - End Sub - - Private Sub CargaGridTarjetas() - Dim ObjCreditos As New ClsBancos - ObjCreditos.GetTarjetasCreditos(DdlCuenta.SelectedValue.ToEntero) - - DdlTarjeta.Items.Clear() - DdlTarjeta.DataSource = ObjCreditos.DtResultados - DdlTarjeta.DataBind() - DdlTarjeta.Items.Insert(0, New ListItem("Seleccione", "-1")) - - ObjCreditos.Dispose() - DivTarjeta.Visible = True - End Sub - - Private Sub CargaConceptosXML(XMLDoc As XmlDocument) - Dim i As Integer = 0 - - Dim Total As Decimal = 0 - Dim PU As Decimal = 0 - Dim Descuento As Double = 0 - Dim CveUM As Integer = 0 - Dim UMM As String = "No Aplica" - Dim tCvePS As Integer = 0 - Dim TipoPS As Integer = 0 - Dim tCveClasif As Integer = -1 - Dim Clasif As String = "Sin Clasificación" - Dim tPSCodigo As String = "-" - Dim tPSDescripcion As String = "-" - Dim PSS As String = "" - Dim Obs As String = "" - Dim SubTotalTemp = 0.0D - Dim IVA As Double = 0 - Dim IEPS As Double = 0 - Dim RetISR As Double = 0 - Dim RetIVA As Double = 0 - Dim PorcentajeIVA As Double = 0 - Dim PorcentajeIEPS As Double = 0 - Dim PorcentajeRetISR As Double = 0 - Dim PorcentajeRetIVA As Double = 0 - Dim DtTemporalGuardados = New DataTable - DtTemporalGuardados.Columns.Add("Contador", GetType(Integer)) - DtTemporalGuardados.Columns.Add("Tipo", GetType(Integer)) - - 'GLOBALS - Dim DtUM = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa).AsEnumerable - Dim DtUMAlias = GlobalDTUnidadesMedidaAlias(UsuarioActual.CveEmpresa).AsEnumerable - Dim DtPS = GlobalDTPS(UsuarioActual.CveEmpresa).AsEnumerable - Dim DtPSAlias = GlobalDTProductosServiciosAlias(UsuarioActual.CveEmpresa).AsEnumerable - - ''AGREGA EN TABLA TEMPORAL - 'Dim DtPSTemp = TmpDT.Clone - 'Dim Row As DataRow = Nothing - - Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix) - Dim cfdVer As String = "http://www.sat.gob.mx/cfd/3" - Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable) - - If Prefijo.ToLower <> "cfdi" Then cfdVer = "http://www.sat.gob.mx/cfd/2" - namespaces.AddNamespace(Prefijo, cfdVer) - namespaces.AddNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital") - namespaces.AddNamespace("implocal", "http://www.sat.gob.mx/implocal") - namespaces.AddNamespace("registrofiscal", "http://www.sat.gob.mx/registrofiscal") - - Dim nodeconcepto As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Conceptos", Prefijo), namespaces) - If nodeconcepto IsNot Nothing AndAlso nodeconcepto.ChildNodes.Count > 0 Then - Dim nodosConceptos As XmlNodeList = nodeconcepto.SelectNodes(String.Format("//{0}:Concepto", Prefijo), namespaces) - For Each node As XmlNode In nodosConceptos - - ' INICIALIZA VALORES - PU = 0 - Descuento = 0 - CveUM = 0 - UMM = "No Aplica" - tCvePS = 0 - TipoPS = 0 - tCveClasif = -1 - Clasif = "Sin Clasificación" - tPSCodigo = "-" - tPSDescripcion = "-" - PSS = "" - Obs = "" - Total = 0 - IVA = 0 - IEPS = 0 - RetISR = 0 - RetIVA = 0 - PorcentajeIVA = 0 - PorcentajeIEPS = 0 - PorcentajeRetISR = 0 - PorcentajeRetIVA = 0 - - - 'CARGA NODO ACTUAL - ' node = XMLDoc.DocumentElement.ChildNodes(2).ChildNodes(i) - - 'CARGA PU - PU = ValorXML(node, "valorUnitario").ToDecimal - - 'SI PU >= TOTAL AND CANTIDAD > 0 : PU / CANTIDAD, por si tiene descuento en el importe y el valor unitario es mayor, lo ajusta - If ValorXML(node, "cantidad").ToDecimal > 0 AndAlso ValorXML(node, "valorUnitario").ToDecimal >= (ValorXML(node, "importe").ToDecimal / ValorXML(node, "cantidad").ToDecimal) Then - PU = ValorXML(node, "importe").ToDecimal / ValorXML(node, "cantidad").ToDecimal - End If - If ValorXML(node, "cantidad").ToDecimal > 0 AndAlso ValorXML(node, "valorUnitario").ToDouble <= 0 And ValorXML(node, "importe").ToDouble > 0 Then - PU = ValorXML(node, "importe").ToDecimal / ValorXML(node, "cantidad").ToDecimal - End If - - - - - 'OBTIENE DESCUENTO - If ValorXML(node, "descuento") IsNot Nothing Then Descuento = ValorXML(node, "descuento").Trim.ToDouble - - 'OBTIENE TOTAL - If ValorXML(node, "importe") IsNot Nothing Then Total = ValorXML(node, "importe").Trim.ToDecimal - - 'OBTIENE SUBTOTAL - SubTotalTemp += If(Total > 0, Total, PU * ValorXML(node, "cantidad").ToDecimal) - - - 'OBTIENE UM - If ValorXML(node, "unidad") IsNot Nothing Then UMM = ValorXML(node, "unidad").Trim - 'BUSCA UM EN CATALOGO - UMM = UMM.ToUpper.Replace(".", "").Replace(",", "") - Dim fUM = (From u In DtUM - Where String.Compare(u!UnidadMedida.ToString.ToUpper.Trim, UMM, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 OrElse - String.Compare(u!Abreviatura.ToString.ToUpper.Trim, UMM, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 - Select CveUnidadMedida = u!CveUnidadMedida, UnidadMedida = u!UnidadMedida).FirstOrDefault() - If fUM IsNot Nothing AndAlso fUM.CveUnidadMedida.ToString.ToEntero > 0 Then - CveUM = fUM.CveUnidadMedida.ToString.ToEntero - UMM = fUM.UnidadMedida.ToString - Else - - 'BUSCA UM EN ALIAS - Dim fUMAlias = (From u In DtUMAlias - Where String.Compare(u!UnidadMedidaAlias.ToString.ToUpper.Trim, UMM, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 - Select u!CveUnidadMedida, u!UnidadMedida).FirstOrDefault() - - If fUMAlias IsNot Nothing Then - CveUM = fUMAlias.CveUnidadMedida.ToString.ToEntero - UMM = fUMAlias.UnidadMedida.ToString - End If - End If - - - - 'se le puso una condicion de que ignorara los acentos, porque en la bd, marcaria error porque no distingue acentos - 'CONCEPTO PRUEBA "TRABAJOS DE CONSTRUCCION", RM/Compras/Compras.aspx?CveFactura=13402&RFC=ECO061206QW7 - '' u!PS.ToString.ToUpper.Trim = PSS - - - 'BUSCA PS - - PSS = ValorXML(node, "descripcion").ToUpper.Trim.Replace(vbCrLf, " ").Replace(vbLf, " ").Replace("'", "''").Replace(" ", " ").Replace("�", "") - If PSS.Length > 844 Then - PSS = PSS.Substring(0, 844) '844,por ser el numero de caracteres aceptados en la columna de la BD - End If - tPSCodigo = PSS - - 'BUSCA PS EN CATALOGO - Dim fPS = (From u In DtPS - Where String.Compare(u!PS.ToString.ToUpper.Trim, PSS, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 - Select u!CvePS, u!CveClasificacion, u!Clasificacion, u!CveTipoPS, u!PSCodigo).FirstOrDefault() - - If fPS IsNot Nothing Then - PSS = fPS.PSCodigo.ToString - tCvePS = fPS.CvePS.ToString.ToEntero - TipoPS = fPS.CveTipoPS.ToString.ToEntero - tCveClasif = fPS.CveClasificacion.ToString.ToEntero - Clasif = fPS.Clasificacion.ToString - tPSCodigo = fPS.PSCodigo.ToString - Else - 'BUSCA PS EN ALIAS - Dim fPSAlias = (From u In DtPSAlias - Where String.Compare(u!PSAlias.ToString.ToUpper.Trim, PSS, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 - Select u!CvePS, u!PS, u!CveClasificacion, u!Clasificacion, u!CveTipoPS, u!PSCodigo).FirstOrDefault() - If fPSAlias IsNot Nothing Then - Obs = PSS - PSS = fPSAlias.PS.ToString - tCvePS = fPSAlias.CvePS.ToString.ToEntero - TipoPS = fPSAlias.CveTipoPS.ToString.ToEntero - tCveClasif = fPSAlias.CveClasificacion.ToString.ToEntero - Clasif = fPSAlias.Clasificacion.ToString - tPSCodigo = fPSAlias.PSCodigo.ToString - End If - End If - - - 'PARA GLUYAS - If UsuarioActual.CveEmpresa = 66 Then - tPSCodigo = String.Format("{1} - {0}", ValorXML(node, "descripcion").ToUpper.Trim.Replace(vbCrLf, " ").Replace(vbLf, " ").Replace("'", "''"), ValorXML(node, "noIdentificacion").Trim) - End If - - - If Version = "3.3" Then - If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then - 'OBTENER TRASLADOS POR DETALLES - Dim ContadorTraslado = 0 - Dim nodosConceptosTraslado As XmlNodeList = node.SelectNodes(String.Format("//{0}:Impuestos/{0}:Traslados/{0}:Traslado", Prefijo), namespaces) - For Each nodeTraslado As XmlNode In nodosConceptosTraslado - - If Not DtTemporalGuardados.FiltraParametros($"Contador = {ContadorTraslado} AND Tipo = 1").Rows.Count > 0 Then - If ValorXML(nodeTraslado, "TasaOCuota").Trim.ToDecimal > 0 And ValorXML(nodeTraslado, "Base").Trim.ToDecimal = Total Then - If ValorXML(nodeTraslado, "Impuesto") = "002" Then - IVA = ValorXML(nodeTraslado, "Importe").Trim.ToDecimal - PorcentajeIVA = ValorXML(nodeTraslado, "TasaOCuota").Trim.ToDecimal - Dim Dr As DataRow - Dr = DtTemporalGuardados.NewRow() - Dr("Contador") = ContadorTraslado - Dr("Tipo") = 1 - DtTemporalGuardados.Rows.Add(Dr) - DtTemporalGuardados.AcceptChanges() - Exit For - ElseIf ValorXML(nodeTraslado, "Impuesto") = "003" Then - IEPS = ValorXML(nodeTraslado, "Importe").Trim.ToDecimal - PorcentajeIEPS = ValorXML(nodeTraslado, "TasaOCuota").Trim.ToDecimal - Dim Dr As DataRow - Dr = DtTemporalGuardados.NewRow() - Dr("Contador") = ContadorTraslado - Dr("Tipo") = 1 - DtTemporalGuardados.Rows.Add(Dr) - DtTemporalGuardados.AcceptChanges() - Exit For - End If - - End If - End If - ContadorTraslado += 1 - Next - - 'OBTENER RETENCIONES POR DETALLES - Dim ContadorRetenciones = 0 - Dim nodosConceptosRetenciones As XmlNodeList = node.SelectNodes(String.Format("//{0}:Impuestos/{0}:Retenciones/{0}:Retencion", Prefijo), namespaces) - For Each nodeRetencion As XmlNode In nodosConceptosRetenciones - - If Not DtTemporalGuardados.FiltraParametros($"Contador = {ContadorRetenciones} AND Tipo = 2").Rows.Count > 0 Then - If ValorXML(nodeRetencion, "TasaOCuota").Trim.ToDecimal > 0 And ValorXML(nodeRetencion, "Base").Trim.ToDecimal = Total Then - If ValorXML(nodeRetencion, "Impuesto".Trim) = "001" Then - RetISR = ValorXML(nodeRetencion, "Importe").Trim.ToDecimal - PorcentajeRetISR = ValorXML(nodeRetencion, "TasaOCuota").Trim.ToDecimal - Dim Dr As DataRow - Dr = DtTemporalGuardados.NewRow() - Dr("Contador") = ContadorRetenciones - Dr("Tipo") = 2 - DtTemporalGuardados.Rows.Add(Dr) - DtTemporalGuardados.AcceptChanges() - Exit For - ElseIf ValorXML(nodeRetencion, "Impuesto") = "002" Then - RetIVA = ValorXML(nodeRetencion, "Importe").Trim.ToDecimal - PorcentajeRetIVA = ValorXML(nodeRetencion, "TasaOCuota").Trim.ToDecimal - Dim Dr As DataRow - Dr = DtTemporalGuardados.NewRow() - Dr("Contador") = ContadorRetenciones - Dr("Tipo") = 2 - DtTemporalGuardados.Rows.Add(Dr) - DtTemporalGuardados.AcceptChanges() - Exit For - End If - - End If - End If - ContadorRetenciones += 1 - Next - End If - - End If - - If Version = "3.2" Then - - - - - Try - If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then - Dim ContadorTraslado = 0 - Dim nodosConceptosTraslado As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Impuestos/{0}:Traslados/{0}:Traslado", Prefijo), namespaces) - - For Each nodeTraslado As XmlNode In nodosConceptosTraslado - If ValorXML(nodeTraslado, "tasa").Trim.ToDecimal > 0 And ValorXML(nodeTraslado, "impuesto").Trim = "IVA" Then - PorcentajeIVA = ValorXML(nodeTraslado, "tasa").Trim.ToDecimal - Alert($"{PorcentajeIVA}") - End If - Next - End If - Catch ex As Exception - - End Try - - End If - - - - '' AGREGA PS - 'AGREGA A TMPDT - AddPS(ValorXML(node, "cantidad").ToDouble, CveUM, UMM, tCveClasif, Clasif, tCvePS, PSS, TipoPS, "-1", "SE", "SE", "-1", Obs, PU, Total, IVA, RetIVA, RetISR, IEPS, 0, Descuento, PSCodigo:=tPSCodigo, TCalculaTotales:=False, CveSATPS:=ValorXML(node, "ClaveProdServ").ToEntero(), CargaXml:=True, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, PorcentajeRetISR:=PorcentajeRetISR, PorcentajeIEPS:=PorcentajeIEPS) - - Next - End If - - AddPS2(False) - - If UsuarioActual.Empresa.UsaAC Then - CompruebaAgregar() - End If - - If isAlmacenistaGluyas() Then - BtnGuardar.Visible = False - AlmacenCambiaPS.Visible = True - End If - - SubTotalConceptos = Math.Round(SubTotalTemp, 2) - 'TmpDT = DtPSTemp.Copy - 'DtPSTemp.Dispose() - - End Sub -#End Region + End If -#Region "Vinculacion De Servcios" - Private Function isAdminObraGluyas() As Boolean - Return (UsuarioActual.CveRol = 1047 And UsuarioActual.CveEmpresa = 66) - End Function - Private Sub cargaddlVinculacionServcios() - If isAdminObraGluyas() Then - TabVinculacionServicios.Visible = True - 'Dim productos As New ClsProductosServicios - 'If productos.GetPS(-1, -1, UsuarioActual.CveEmpresa) Then - ' PSDTRemplazo = productos.DtResultados.FiltraParametros("CveTipoPS=2", "PS") - 'End If - 'productos.Dispose() - GVVinculacionServicios.DataSource = TmpDT - GVVinculacionServicios.DataBind() - End If - End Sub - Protected Sub GVVinculacionServicios_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVVinculacionServicios.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - Dim dt As DataTable = Nothing - dt = GlobalDTPS(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoPS=2", "PS") - e.Row.FCDropDownList("Ddlnewps").DataSource = dt 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) - e.Row.FCDropDownList("Ddlnewps").DataBind() - e.Row.FCDropDownList("Ddlnewps").Items.Insert(0, New ListItem("Seleccione", "-1")) - dt.Dispose() - - End If End Sub -#End Region + Private Sub CargaMonedas() + DdlMoneda.DataSource = GlobalDTMonedas + DdlMoneda.DataBind() + End Sub -#Region "BTN'S" - Protected Sub BtnVincularServicios_Click(sender As Object, e As EventArgs) Handles BtnVincularServicios.Click - Dim correcto As Boolean = True - Dim x As Integer = 0 - 'Dim buid As New StringBuilder - For Each Dr As DataRow In TmpDT.Rows - Dim newps As Integer = GVVinculacionServicios.Rows(x).FCDropDownList("Ddlnewps").SelectedValue.ToEntero - If newps > 0 Then - 'buid.Append(String.Format("{0} ---> {1},", Dr("CvePS").ToString, newps)) - Dr("CvePS") = newps - 'buid.Append(String.Format("{0} ---> {1},
", Dr("CvePS").ToString, newps)) - Else 'limpio el valor para que no truene en linq mas abajo - correcto = False - Alert("Favor de vincular todos los servicios", TipoMensaje.MsgAdvertencia) - Exit For - End If - x = x + 1 - Next - x = 0 - For Each Dr As DataRow In GVVinculacionServicios.Rows - Dim newps As Integer = GVVinculacionServicios.Rows(x).FCDropDownList("Ddlnewps").SelectedValue.ToEntero - If newps > 0 Then - 'buid.Append(String.Format("{0} ---> {1},", Dr("CvePS").ToString, newps)) - Dr("CvePS") = newps - 'buid.Append(String.Format("{0} ---> {1},
", Dr("CvePS").ToString, newps)) - Else 'limpio el valor para que no truene en linq mas abajo - correcto = False - Alert("Favor de vincular todos los servicios", TipoMensaje.MsgAdvertencia) - Exit For - End If - x = x + 1 - Next - - TmpDT.AcceptChanges() - 'Alert(buid.ToString) - If correcto Then - If Not CierrePeriodo Then - BtnGuardar.Visible = True - End If - UpFacturar.Update() - End If - End Sub - - Protected Sub BtnCargarProveedores_Click(sender As Object, e As System.EventArgs) Handles BtnCargarProveedores.Click - DdlProveedor.CssClass += " select2me" - DdlProveedor.AutoPostBack = True - DdlProveedor.Items.Clear() - DdlProveedor.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa) - 'Dim ObjProveedor As New ClsCompProveedores - 'If ObjProveedor.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, -1, "-1", "-1", "-1", "-1", "-1", "-1", "-1", UsuarioActual.CveEmpresa) Then - 'DdlProveedor.DataSource = ObjProveedor.DtResultados - 'End If - DdlProveedor.DataBind() - DdlProveedor.Items.Insert(0, New ListItem("Seleccione el Proveedor", "-1")) - DdlProveedor.Attributes.Remove("onclick") - - 'RegistraScript("$('#C_DdlProveedor').select2('open');") - End Sub - - Protected Sub BtnBuscarProveedor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnBuscarProveedor.Click - ViewState("CveProveedor") = HdnCveProveedor.Value.ToEntero - CargaProveedor(HdnCveProveedor.Value.ToEntero, "-1") - - If DdlPS.SelectedValue IsNot Nothing AndAlso DdlPS.SelectedValue.ToEntero > 0 Then - DdlPS_SelectedIndexChanged(sender, e) - DdlPS.Focus() - Else - TxtCantidad.Focus() - End If - - End Sub - - Protected Sub BtnGuardar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGuardar.Click - - '------------------INICIA VALIDACIONES------------------ - Dim EstatusCredito As Integer = 0 - 'Credito Multiple - If RBLPago.SelectedValue.ToEntero = 4 Then - - Dim DifCreCompra As Decimal = 0 - Dim TotalCreditos As Decimal = 0 - Dim MensualidadMultipleTotal As Decimal = 0 - Dim CveUltimoCreditoDetalleInterno As Integer - - For Each GvRow As GridViewRow In GvCreditos.Rows - - Dim CapitalMiltiple As Decimal = GvRow.FCTextBox("TxtCapital").Text.ToDecimal - Dim InteresMiltiple As Decimal = GvRow.FCTextBox("TxtInteres").Text.ToDecimal - - Dim AmbosMiltiple As Decimal = GvRow.FCTextBox("TxtAmbos").Text.ToDecimal - Dim MensualidadMultiple As Decimal = GvRow.DataKey("Mensualidad").ToDecimal - - If CapitalMiltiple > 0 Or InteresMiltiple > 0 Then - - TotalCreditos = TotalCreditos + CapitalMiltiple + InteresMiltiple - MensualidadMultipleTotal = MensualidadMultipleTotal + MensualidadMultiple - CveUltimoCreditoDetalleInterno = GvRow.DataKey("CveCreditoDetalle").ToEntero - - ElseIf AmbosMiltiple > 0 Then - - TotalCreditos = TotalCreditos + AmbosMiltiple - MensualidadMultipleTotal = MensualidadMultipleTotal + MensualidadMultiple - CveUltimoCreditoDetalleInterno = GvRow.DataKey("CveCreditoDetalle").ToEntero - EstatusCredito = GvRow.DataKey("Estatus").ToEntero - End If - Next - - If TotalCreditos <> TxtTotal.Text.ToDecimal Then - Alert($"El importe de La factura no concide con el total de los creditos, diferencia: { (TotalCreditos - TxtTotal.Text.ToDecimal).FormatoNumero(2)}", TipoMensaje.MsgAdvertencia) - Exit Sub - - End If - End If - - 'Si se marcó No Deducible en el encabezado mínimo se debe registrar un No Deducible en el Detalle - Dim GuardaNoDeducibles As Boolean = False - If ChkEsNoDeducible.Checked Then - For Each Row As DataRow In TmpDT.Rows - If Row("NoDeducible").ToString().ToUpper().Contiene("TRUE", "1") Then - GuardaNoDeducibles = True - End If - Next - If GuardaNoDeducibles = False Then - Alert("Si la compra es No Deducible, mínimo se debe registrar un producto No Deducible", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - - - If CierrePeriodo Then - Alert("El periodo de la compra actual ya se encuentra cerrado. No podra registrar la compra.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - 'DF - 10/04/2017 - If UsuarioActual.TienePermisoProceso(187) Then - If TxtSerie.Text <> SerieVieja Then - Dim SerieNueva As String = GlobalDTProveedorSucursales(CveProveedor, UsuarioActual.CveEmpresa).FiltroPrimeroValor("Serie", $"Serie = '{TxtSerie.Text}'").ToString - If SerieNueva = "" Then - Alert("La Serie no es válida, por favor revise que se encuentre dentro de la lista de las sucursales del proveedor.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - End If - - 'Excede el limite de credito - If RBLPago.SelectedValue = "1" AndAlso DdlTipoComprobante.SelectedValue.Contiene("Fac") AndAlso UsuarioActual.Empresa.Funcionalidad(518) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(185) Then - Dim ObjCompras As New ClsCompras - If ObjCompras.ObtenerCreditoRestante(CveProveedor) Then - If ObjCompras.DtResultados.Rows.Count > 0 Then - Dim Saldo As Decimal = ObjCompras.DtResultados(0)("Saldo").ToString.ToDecimal + TxtTotal.Text.ToDecimal - Dim LimiteCredito As Decimal = ObjCompras.DtResultados(0)("LimiteCredito").ToString.ToDecimal - - If LimiteCredito > 0 Then - If Saldo / LimiteCredito * 100 > 90 Then - Alert($"Nuestro Limite de Credito con este proveedor supera el 90%
Porcentaje Actual: {(Saldo / LimiteCredito * 100).FormatoNumero(2)}%", TipoMensaje.MsgAdvertencia) - End If - End If - Else - ObjCompras.Dispose() - Alert("El proveedor no tiene límite de crédito", TipoMensaje.MsgError) - Exit Sub - End If - Else - ObjCompras.Dispose() - Alert("Ocurrio un error al obtener el limite de credito del Proveedor", TipoMensaje.MsgError) - Exit Sub - End If - ObjCompras.Dispose() - End If - - If Not (HFDiferenciaCompra.Value = TxtTotal.Text Or CveFactura < 1 Or CveCompra < 1) Then - Alert("La compra no se puede registrar debido a que los totales no son iguales, verifique sus cambios", TipoMensaje.MsgError) - Exit Sub - End If - - 'UM EQUIVALENCIAS - For Each gvr As GridViewRow In GvPS.Rows - If gvr.DataKey("CvePS").ToString.ToEntero > 0 Then - If gvr.DataKey("CveUM").ToString.ToEntero = 0 Then - Alert("Existe un error, Unidad de Medida no registrada", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - Next - - If ChkConsignacion.Checked Then - For Each gvr As GridViewRow In GvInv.Rows - If gvr.FCDropDownList("DdlVinculaConsignacion").SelectedValue.ToEntero < 0 Then - Alert("Si la compra aplica consignación debe vincular todos los conceptos en Almacén.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - Next - End If - - If RowProveedorSucursal.Visible And DdlProveedorSucursal.SelectedValue.ToEntero = -1 Then - Alert("Favor de seleccionar una sucursal del proveedor", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If UsuarioActual.TienePermisoProceso(121) Then - If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - If Not NCDevolucion Then - Alert("Favor de seleccionar un producto en la pestaña de almacen", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - Else - Dim x As Integer = 0 - For Each Dr As GridViewRow In GvInv.Rows - If Dr.FCCheckBox("cbInv").Checked Then - x = x + 1 - End If - Next - If x = 0 AndAlso GvInv.Rows.Count > 0 Then - Alert("Favor de seleccionar un producto en la pestaña de almacen", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - End If - - If UsuarioActual.Empresa.Funcionalidad(538).ToEntero = 1 Then - If TmpDT.MIN("CvePS").ToEntero <= 0 Then - Alert("Todos los Productos/Servicios deben estar registrados o aliados a un productos ya registrado.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - - If UsuarioActual.Empresa.Funcionalidad(123).ToEntero > 0 And Not UsuarioActual.TienePermisoProceso(156) Then - If Not ValidaCierrePeriodo() Then - Alert("No se puede registar la compra. Se ha cerrado el periodo de la compra actual", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - - Dim TotalPorDevengar = Math.Round(TxtTotal.Text.ToDouble, 2) - Dim TotalDetalle = 0.0 - Dim RequiereCentroCosto As Boolean = False - - 'If Not (UsuarioActual.Empresa.Funcionalidad(102) = "") Then - ' Dim NotHas117 As Boolean = Not UsuarioActual.TienePermisoProceso(117) - ' 'verifica que tenga proyecto y clasificacion - For Each Row As DataRow In TmpDT.Rows - If Row("CveSubProyecto").ToString.ToEntero <= 0 Then - Alert("No se ha completado la asignacion de proyectos en la compra. ", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If Row("CveClasificacionActualizar").ToString.ToEntero <= 0 Then 'If NotHas117 AndAlso Row("CveClasificacionActualizar").ToString.ToEntero <= 0 Then - Alert("Hay productos que no tienen clasificación asignada.
Favor de asignarle una y darle guardar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If UsuarioActual.Empresa.Funcionalidad(527) = "1" Then - If Row("CveTipoGasto").ToString.ToEntero <= 0 Then - Alert("No se ha completado la asignacion de tipos de gasto en la compra.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - Next - 'End If - - 'SI LA CANTIDAD EN SERIE/LOTE NO ES IGUAL A CANTIDAD EN GVPS - 'Dim DtDetalles As DataTable - Dim Cantidad As Integer - - If GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True Then - For Each Dr As DataRow In DtInv.Rows - If Dr("CveMetodoInventario").ToString.ToEntero = 5 Then - Cantidad = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", Dr("CvePS").ToString)).Rows.Count - If Cantidad < Dr("Cantidad").ToString.ToEntero Then - Alert("No hay productos a los que no se le ha asociado Serie-Lote", TipoMensaje.MsgError) - Exit Sub - End If - End If - Next - End If - - If Not HdnCveProveedor.Value <> "-1" Then - Alert("En necesario seleccionar un proveedor, al cual se le va a facturar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If Not TmpDT.Rows.Count > 0 Then - Alert("Es necesario agregar al menos un Producto o Servicio a la factura.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - 'VALIDA SI LA CLASIFICACIÓN REQUIERE PERSONAL, AF COMPRA O AF INSUMO - Dim ErrorValidacion As Boolean = False - Dim DtTemporal As New DataTable - DtTemporal.Columns.Add("CveClasificacion", GetType(Integer)) - For Each Gvr As GridViewRow In GvPS.Rows - Dim Dr As DataRow = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros($"CveClasificacion = {Gvr.DataKey("CveClasificacion").ToEntero}")(0) - If Dr IsNot Nothing Then - Dim SeValido As Boolean = False - For Each Drt As DataRow In DtTemporal.Rows - If Drt("CveClasificacion").ToString.ToEntero = Dr("CveClasificacion").ToString.ToEntero Then - SeValido = True - Exit For - End If - Next - If Not SeValido Then - If CBool(Dr("RequierePersonal")) Then - For Each GvP As GridViewRow In GvPersonal.Rows - If GvP.DataKey("CveClasificacion").ToEntero = Dr("CveClasificacion").ToString.ToEntero Then - If Not GvP.FCDropDownList("DdlPersonalGv").SelectedValue.ToEntero > 0 Then - ErrorValidacion = True - Alert($"Tiene que seleccionar un personal para esta clasificación: {Dr("Clasificacion").ToString}.", TipoMensaje.MsgAdvertencia) - Exit For - End If - End If - Next - End If - If CBool(Dr("RequiereAFCompra")) Then - For Each GvAFC As GridViewRow In GvAFCompras.Rows - If GvAFC.DataKey("CveClasificacion").ToEntero = Dr("CveClasificacion").ToString.ToEntero Then - If Not GvAFC.FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then - ErrorValidacion = True - Alert($"Tiene que seleccionar un AF compra para esta clasificación: {Dr("Clasificacion").ToString}.", TipoMensaje.MsgAdvertencia) - Exit For - End If - End If - Next - End If - If CBool(Dr("RequiereAFInsumo")) Then - For Each GvAFI As GridViewRow In GvAFInsumos.Rows - If GvAFI.DataKey("CveClasificacion").ToEntero = Dr("CveClasificacion").ToString.ToEntero Then - If Not GvAFI.FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then - ErrorValidacion = True - If Not SeValido Then - Alert($"Tiene que seleccionar un AF insumo para esta clasificación: {Dr("Clasificacion").ToString}.", TipoMensaje.MsgAdvertencia) - End If - Exit For - End If - End If - Next - End If - Dim Drr As DataRow = DtTemporal.NewRow - Drr("CveClasificacion") = Dr("CveClasificacion").ToString.ToEntero - DtTemporal.Rows.Add(Drr) - End If - End If - Next - If ErrorValidacion Then Exit Sub - - '------------------TERMINA VALIDACIONES------------------ - - 'RECORRO LOS PRODUCTOS O SERVICIOS PARA REGISTRARLOS LOS QUE NO EXISTEN EN EL CATÁLOGO - Dim tCve As Integer - Dim RegeneraPS As Boolean = False - 'OBJETOS PROVISIONALES - Dim UM As New ClsUnidadesMedida - Dim PSS As New ClsProductosServicios - Dim Correcto = True - - For Each Row As DataRow In TmpDT.Rows - - 'VALIDACION DE CENTRO DE COSTO - If UsuarioActual.Empresa.RequiereCentroCostos AndAlso Row("CveSubProyecto").ToString.ToEntero <= 0 Then - RequiereCentroCosto = True - UM.Dispose() - PSS.Dispose() - Alert("Falta asignar Proyecto a la compra", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - 'REGISTRO LAS UNIDADES DE MEDIDA - If Row("CveUM").ToString.ToEntero = 0 Then - tCve = UM.AddUnidadMedida(Row("UM").ToString, Row("UM").ToString, "", "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1) - If tCve > 0 Then - Row("CveUM") = tCve - Dim rowsToUpdate = TmpDT.AsEnumerable().Where(Function(r) r.Field(Of String)("UM").ToString.ToUpper = Row("UM").ToString.ToUpper AndAlso r!CveUM.ToString.ToEntero = 0) - For Each roww As DataRow In rowsToUpdate - roww.SetField("CveUM", tCve) - Next - Else - Correcto = False - End If - End If - - 'REGISTRO LOS PRODUCTOS - If Row("CvePS").ToString.ToEntero = 0 Then - tCve = PSS.AddPS(Row("CveClasificacionActualizar").ToString.ToEntero, -1, Row("CveUM").ToString.ToEntero, "", "", "", Row("PS").ToString, Row("PU").ToString.ToDouble, If(TxtIVA.Text.ToDouble > 0, -1, 0), 0, False, 0, True, False, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, 0) - If tCve > 0 Then - RegeneraPS = True - Row("CvePS") = tCve - Row("CveClasificacion") = Row("CveClasificacionActualizar").ToString.ToEntero - 'Row("CveEq") = 1 - TmpDT.AcceptChanges() - - 'busco el mismo PS dentro de la tabla por si está más de una vez y lo actualizo - Dim rowsToUpdate = TmpDT.AsEnumerable().Where(Function(r) r.Field(Of String)("PS") = Row("PS").ToString AndAlso r!CvePS.ToString.ToEntero = 0) - For Each roww As DataRow In rowsToUpdate - roww.SetField("CvePS", tCve) - roww.SetField("CveClasificacion", Row("CveClasificacionActualizar").ToString.ToEntero) - 'roww.SetField("CveEq", 1) - Next - TmpDT.AcceptChanges() - Else - Correcto = False - End If - Else - 'UPDATE CLASIFICACION DE PRODUCTO YA REGISTRADO - If Row("CveClasificacionActualizar").ToString.ToEntero > 0 AndAlso Row("CveClasificacion").ToString.ToEntero <= 0 Then - If PSS.UpdateClasificacionPS(Row("CveClasificacionActualizar").ToString.ToEntero, UsuarioActual.CveUsuario, Row("CvePS").ToString.ToEntero) Then - Row("CveClasificacion") = Row("CveClasificacionActualizar").ToString.ToEntero - RegeneraPS = True - Else - Correcto = False - End If - End If - End If - Next - UM.Dispose() - PSS.Dispose() - - 'si hay necesidad de actualizar el globaldtps - If RegeneraPS Then - 'Dim Hilo As New System.Threading.Thread(AddressOf GeneraGlobalDT) - 'Hilo.Start() - GeneraGlobalDT(Nothing) - End If - - Dim CvePlantillaPrePoliza As Integer - If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - CvePlantillaPrePoliza = 60 - Else - CvePlantillaPrePoliza = 1 - End If - Dim tIdContaProveedor As Integer = CtaProveedor - Dim ImporteAnticipo As Decimal = 0 - - If (ArrAnticipos.Count > 0 And CveCompra > 0) Or (ArrAnticipos.Count > 0 And UsuarioActual.Empresa.UsaAC) Then '-- ESTO SE QUITO - IPP - 04 NOVIMEBRE 2016 - CvePlantillaPrePoliza = 52 - 'cuenta de anticipos - tIdContaProveedor = CtaProveedorAnticipos - For Each Ant As Compras_Compras.Anticipos In ArrAnticipos - ImporteAnticipo += Ant.Importe - Next - If Math.Round(ImporteAnticipo, 2) > TxtTotal.Text.ToDouble Then - Alert("El Importe seleccionado es mayor a la compra", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - End If - - If RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then - If EmpresaPrueba Then - If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - CvePlantillaPrePoliza = 60 - Else - CvePlantillaPrePoliza = 1 - End If - Else - CvePlantillaPrePoliza = 9 - End If - End If - - 'If RBLPago.SelectedValue.ToEntero = 4 And UsuarioActual.CveEmpresa.Contiene(1, 7) Then - ' CvePlantillaPrePoliza = 69 - 'End If - - TmpDT.AcceptChanges() - If Correcto Then - - 'VALIDA IMPORTES - If Not ValidaTotalesGuardar() Then - Exit Sub - End If - - - Dim ObjCompras As New ClsCompras() - Dim ObjConta As New ClsContabilidad(ObjCompras.IniciaTransacSQL()) - Dim ObjIE As New ClsBancos(ObjCompras.IniciaTransacSQL) - Dim ObjInventario As New ClsInventarios(ObjCompras.IniciaTransacSQL) - Dim ObjAF As New ClsAF(ObjCompras.IniciaTransacSQL) - Dim ObjOC As New ClsOC(ObjCompras.IniciaTransacSQL) - Dim ObjContratos As New ClsContratos(ObjCompras.IniciaTransacSQL()) - Dim ObjProveedores As New ClsCompProveedores(ObjCompras.IniciaTransacSQL()) - Dim ObjEventos As New ClsOIEventos(ObjCompras.IniciaTransacSQL()) - Dim ObjAcar As New ClsAcarreos(ObjCompras.IniciaTransacSQL()) - Dim ObjCGame As New ClsCGame(ObjCompras.IniciaTransacSQL()) - Dim ObjProductosServicios As New ClsProductosServicios(ObjCompras.IniciaTransacSQL()) - - - Dim ObjContaAC As ClsContPAQi = Nothing - - Dim ErrorMovtosCxP As Boolean = False - Dim ErrorPrepoliza As Boolean = False - Dim ErrorPrepolizaDescuadre As Boolean = False - Dim ErrorMovtosRetIVA As Boolean = False - Dim ErrorMovtosRetISR As Boolean = False - Dim ErrorMovtosEstimaciones As Boolean = False - Dim ErrorMovtosIVA As Boolean = False - Dim ErrorMovtosIE As Boolean = False - Dim ErrorMovInv As Boolean - Dim ErrorMovDev As Boolean = False - Dim ErrorOC = False - Dim TieneError As Boolean = False - Dim ErrorAC As Boolean = False - Dim ErrorAF As Boolean = False - Dim ErrorReembolso As Boolean = False - Dim ErrorBitacora = False - Dim ErrorAddAcarreos As Boolean = False - Dim ErrorCreditosCompra As Boolean = False - Dim ErrorOtrosGastos As Boolean = False - Dim ErrorSATPS As Boolean = False - Dim ErrorACMEnsaje As New StringBuilder - Dim ErrorSaldosInvComp As Boolean = False - - Dim CveIE As Integer = -1 - Dim CveEstatusFactura As Integer = 1 - Dim PolizaFolio As Integer = 0 - Dim CvePrePoliza As Integer - Dim ImporteCompra As Decimal = TxtTotal.Text.ToDecimal - Dim MultiplicadorNC = If(DdlTipoComprobante.SelectedValue = "NC", -1, 1) - Dim CveMovimientoInventario As Integer = -1 - Dim IVA = 1.16 - Dim ListaMovimientosAlmacen As New List(Of Integer) - - Dim ErrorCreditoCapitalIntres As Boolean = False - Dim ErrorCredito As Boolean = False - - If ChkProgramarPago.Checked Then - CveEstatusFactura = 2 - End If - Dim EntregaDirecta = False - - Dim ConceptoPoliza As String = String.Format("{0} - {1}{2} - {3}", NombreProveedor, TxtSerie.Text, TxtFolio.Text, TxtDescripcion.Text.Trim) - - 'TIPO CAMBIO MANUAL CON COMPRA NUEVA - Dim TipoCambioGuardar = 1.0 - If DdlMoneda.SelectedValue.ToEntero > 1 Then - TipoCambioGuardar = If(DivTC.Visible, TxtTC.Text.ToDouble, LblTC.Text.Substring(3).ToDouble) - End If - TipoCambio = If(DivTC.Visible, TipoCambioGuardar, TipoCambio) - - Try - Dim FolioFijo As Integer = 0 - 'cheque - If DdlTipoTransaccion.SelectedValue = "1" Then FolioFijo = TxtFolio.Text.ToEntero - - CvePrePoliza = ObjConta.AddPrePolizas("Compras/Registrar", If(EsContado And CvePlantillaPrePoliza = 1, 2, CvePlantillaPrePoliza), ImporteCompra, TxtTotal.Text.ToDouble, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, FolioFijo:=FolioFijo, ReglaFolioPoliza:=ObjCompras.ObtenerReglaFolio(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa), CveTipoPoliza:=ObjConta.ObtenerTipoPoliza(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa)) - - If CvePrePoliza > 0 Then - - 'seria de contado, solo cuando no tenga vinculado ningun anticipo - Dim ImportePago As Decimal = 0 - Dim TCPago As Decimal = GlobalTipoCambio(TxtFechaPago.Text.ToDate).ToString.ToDecimal - Dim CveMonedaPago As Integer = DdlMoneda.SelectedValue.ToEntero - - If RBLPago.SelectedValue.ToEntero = 2 Then 'Contado - - If RBLContado.SelectedValue = "1" Then - ImportePago = TxtDocumentoImporte.Text.Trim.ToDecimal - Dim Dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros($"CveCuenta = {DdlCuenta.SelectedValue}").Rows(0) - - If Dr IsNot Nothing Then - CveMonedaPago = Dr("CveMoneda").ToString.ToEntero - End If - - If CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 2 Then - ImportePago = (ImportePago * TCPago).RoundSQL - ElseIf CveMonedaPago = 2 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then - ImportePago = (ImportePago / TCPago).RoundSQL - ElseIf CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then - TCPago = 1 - End If - - 'se registra primero el movimiento en bancos para luego vincularlo en la compra - CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero, TxtFechaPago.Text.Trim.ToDate, TxtDocumentoFolio.Text.Trim, DdlProveedor.SelectedItem.Text.Trim, ImportePago, CveMonedaPago, TCPago, TxtDocumentoObservaciones.Text.Trim, "", True, True, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCuentaTarjeta:=If(DivTarjeta.Visible, DdlTarjeta.SelectedValue.ToEntero, -1)) - ElseIf RBLContado.SelectedValue = "6" Then - ImportePago = TxtDocumentoImporteCaja.Text.Trim.ToDecimal - Dim Dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros($"CveCuenta = {DdlCuentaCaja.SelectedValue}").Rows(0) - If Dr IsNot Nothing Then - CveMonedaPago = Dr("CveMoneda").ToString.ToEntero - End If - - If CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 2 Then - ImportePago = (ImportePago * TCPago).RoundSQL - ElseIf CveMonedaPago = 2 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then - ImportePago = (ImportePago / TCPago).RoundSQL - ElseIf CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then - TCPago = 1 - End If - - 'se registra primero el movimiento en bancos para luego vincularlo en la compra - CveIE = ObjIE.AddBancos_IE(DdlCuentaCaja.SelectedValue.ToEntero, DdlTipoTransaccionCaja.SelectedValue.ToEntero, TxtFechaPago.Text.Trim.ToDate, TxtDocumentoFolioCaja.Text.Trim, DdlProveedor.SelectedItem.Text.Trim, ImportePago, CveMonedaPago, TCPago, TxtDocumentoObservacionesCaja.Text.Trim, "", True, True, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - End If - - If (RBLContado.SelectedValue = "1" OrElse RBLContado.SelectedValue = "6") AndAlso Not CveIE > 0 Then - ErrorMovtosIE = True - End If - End If - - If Not ErrorMovtosIE Then - - 'REEMBOLSOS NO USA AC - Dim NumeroReembolso = "-1" - If TxtNumeroReembolso IsNot Nothing And RBLPago.SelectedValue = "3" Then - NumeroReembolso = TxtNumeroReembolso.Text - - ''GUARDA VALORES PARA SESSION - UsuarioActual.Sesion("Comp-NumeroReembolso") = TxtNumeroReembolso.Text - UsuarioActual.Sesion("Comp-CveFYE") = DdlPersonalReembolso.SelectedValue - UsuarioActual.Sesion("Comp-Descripcion") = TxtDescripcion.Text - - If NumeroReembolso <> "-1" Then - If CvePersonal <= 0 And CveCajaChica <= 0 Then - ErrorReembolso = True - End If - End If - Else - UsuarioActual.Sesion("Comp-NumeroReembolso") = "" - End If - - - If Not ErrorReembolso Then - - 'PORCENTAJE IVA - Dim PorcentajeIVA As Decimal = TmpDT.MAX("IVAPorcentaje").ToDecimal - - 'If DdlIVA.SelectedValue.ToDouble = 1.16 Then - ' PorcentajeIVA = 0.16 - 'ElseIf DdlIVA.SelectedValue.ToDouble = 1.08 Then - ' PorcentajeIVA = 0.08 - 'End If - - 'METODO DE PREPOLIZA DE ALMACEN - If UsuarioActual.CveEmpresa.Contiene(1, 119, 72, 80, 140, 141) And UsuarioActual.Empresa.UsaInventarios And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - Dim ImporteAlmacen = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0, "ImporteSinImpuestos", "Total"), $"ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveTipoPS = 2").ToString.ToDecimal - If ImporteAlmacen > 0 Then - If Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then - If (CveImportacion > 0 Or CveFlete > 0) Then - CveConceptoContableAlmacen = CveConceptoContableAlmacen - Else - CveConceptoContableAlmacen = 205 - End If - If OCVinculada And Not (CveImportacion > 0 Or CveFlete > 0) Then - CveConceptoContableAlmacen = DdlOCVinculaInv.SelectedValue.ToEntero - End If - If UsuarioActual.CveEmpresa.Contiene(72, 80, 140, 141) Then - CveConceptoContableAlmacen = 205 - End If + Private Sub CargarAlmacen() + 'ddlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen IN (1,2)") 'solo muestra tipo material y herramientas + 'ddlAlmacen.DataBind() + + ddlAlmacenAdd.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen IN (1,2,7,14,19)") 'solo muestra tipo material y herramientas + ddlAlmacenAdd.DataBind() + End Sub + + Protected Sub CargaFuncionariosEmpleados() + 'Cargar los FUncionarios Empleados que tengan saldo + Dim objGastosXComprobar As New ClsMovimientos + Dim dtFE As New DataTable + + If objGastosXComprobar.GetEgresosSinComprobarPersonal(UsuarioActual.CveEmpresa) Then + 'TRATAR DE HACERLO CON c + + dtFE.Columns.Add("CvePersonal", GetType(Integer)) + dtFE.Columns.Add("NombreCompleto", GetType(String)) + dtFE.Columns.Add("Saldo", GetType(Double)) + 'dtFE.Columns.Add("CveIE", GetType(Integer)) + DtFuncionarios = objGastosXComprobar.DtResultados.FiltraParametros("CvePersonal > 0 ") 'objGastosXComprobar.DtResultados.FiltraParametros("CvePersonal > 0 AND Saldo > 0 ") ' saco los egresos sin comprobar de funcionarios y empleados + + For Each Row As DataRow In objGastosXComprobar.DtResultados.FiltraParametros("CvePersonal > 0 ", "NombreCompleto").Rows ' saco los totalizadores + Dim RowFE As DataRow = Nothing + RowFE = dtFE.NewRow() + + RowFE("CvePersonal") = Row("CvePersonal").ToString.ToEntero + RowFE("NombreCompleto") = String.Format("{0} - ${1}", Row("NombreCompleto").ToString.Trim, Row("Saldo").ToString.FormatoNumero(2)) + RowFE("Saldo") = Row("Saldo").ToString.ToDouble + + dtFE.Rows.Add(RowFE) + Next + ' DtFuncionarios = dtFE + 'For Each Row As DataRow In objGastosXComprobar.DtResultados.FiltraParametros("CvePersonal > 0 AND FechaDocumento IS NOT NULL").Rows + ' ArrIE.Add(New Anticipos With {.CveIE = Row("CveIE").ToString.ToEntero, .Importe = Row("Saldo").ToString.ToDouble, .CvePersonal = Row("CvePersonal").ToString.ToEntero}) + 'Next + + + End If + + objGastosXComprobar.Dispose() + + DdlFuncionarioEmpleado.DataSource = dtFE.FiltraParametros("", "NombreCompleto") + DdlFuncionarioEmpleado.DataBind() + + DdlFuncionarioEmpleado.Items.Insert(0, New ListItem("Seleccione Funcionario Empleado", "-1")) + + 'UPCondicionesPago.Update() + UpContado.Update() + End Sub + + Protected Sub CargaDeudores() + 'Cargar los FUncionarios Empleados que tengan saldo + Dim Deudores As New ClsMovimientos + + If RBLTipoDeudor.SelectedValue.ToEntero = 1 Then + If Deudores.GetDeudoresSaldos(-1, UsuarioActual.CveEmpresa) Then + DtDeudores = Deudores.DtResultados.FiltraParametros("CveProveedor > 0") + DdlDeudor.DataSource = DtDeudores + DdlDeudor.DataBind() + + DdlDeudor.Items.Insert(0, New ListItem("Seleccione Deudor", "-1")) + UpContado.Update() + End If + Else + If Deudores.GetDeudoresComisionesSaldos(UsuarioActual.CveEmpresa) Then + DtDeudores = Deudores.DtResultados.FiltraParametros("CveProveedor > 0") + DdlDeudor.DataSource = DtDeudores + DdlDeudor.DataBind() + + DdlDeudor.Items.Insert(0, New ListItem("Seleccione Deudor", "-1")) + UpContado.Update() + End If + End If + + Deudores.Dispose() + End Sub + + Private Sub CreaTmpAcarreos() + tDTAcarreos = New DataTable + tDTAcarreos.Columns.Add("CvePreEstimacion", GetType(Integer)) + tDTAcarreos.Columns.Add("Importe", GetType(Double)) + End Sub + + Protected Sub CargaAcreedores() + Dim ObjMov As New ClsMovimientos + + If ObjMov.GetAcreedoresSaldos(-1, UsuarioActual.CveEmpresa) Then + DtAcreedores = ObjMov.DtResultados.FiltraParametros("CveProveedor > 0") + DdlAcreedor.DataSource = DtAcreedores + DdlAcreedor.DataBind() + + + + DdlAcreedor.Items.Insert(0, New ListItem("Seleccione Acreedor", "-1")) + UpContado.Update() + End If + + ObjMov.Dispose() + End Sub + + Private Sub CargaCreditos() + + Dim Cred As New ClsBancos + Dim Dt As DataTable = Nothing + Dim DtD As DataTable = Nothing + If Cred.GetCreditos(-1, -1, -1, -1, -1, UsuarioActual.CveEmpresa) Then + Dt = Cred.DtResultados.FiltraParametros("CveCredito > 0 AND CveTipoCredito IN (4,5)") + If Dt.Rows.Count > 0 AndAlso Cred.GetCreditosDetalle(Dt.Rows(0)("CveCredito").ToString.ToEntero, -1) Then + DtD = Cred.DtResultados.FiltraParametros("Estatus = 2 AND CveIE IS NOT NULL") + End If + End If + Cred.Dispose() + + If DdlTipoCredito.SelectedValue.ToEntero = 1 Then + Dt = Dt.FiltraParametros("CveCompraFactura IS NULL") + End If + + DdlCredito.DataSource = Dt.FiltraParametros("", DistinctColumns:={"CveCredito", "ReferenciaImporte"}) + DdlCredito.DataBind() + DdlCredito.Items.Insert(0, New ListItem("Seleccione", "-1")) + + + DdlCreditoDetalle.DataSource = DtD + DdlCreditoDetalle.DataBind() + DdlCreditoDetalle.Items.Insert(0, New ListItem("Seleccione", "-1")) + + End Sub + + Private Sub CargaCreditosDetalle(CveCredito As Integer) + Dim Cred As New ClsBancos + + Dim DtD As DataTable = Nothing + + If Cred.GetCreditosDetalle(CveCredito, -1) Then + DtD = Cred.DtResultados.FiltraParametros("Estatus = 2") + End If + Cred.Dispose() + + DdlCreditoDetalle.DataSource = DtD + DdlCreditoDetalle.DataBind() + DdlCreditoDetalle.Items.Insert(0, New ListItem("Seleccione", "-1")) + + End Sub + + Private Sub CargaProveedor(CveProveedor As Integer, RFC As String, Optional RecargaCombo As Boolean = True) + + Dim ObjProveedor As New ClsCompProveedores() + + If ObjProveedor.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, CveProveedor, "-1", "-1", "-1", "-1", RFC, "-1", "-1", -1, UsuarioActual.CveEmpresa) Then + If ObjProveedor.DtResultados.Rows.Count > 0 Then + + If RecargaCombo Then DdlProveedor.DataSource = ObjProveedor.DtResultados : DdlProveedor.DataBind() + + ChkConsignacion.Enabled = True + + ViewState("CveProveedor") = ObjProveedor.CveProveedor + ViewState("CveTipoProveedor") = ObjProveedor.CveTipoProveedor + + 'Conta ContPAQ + ViewState("CtaProveedor") = ObjProveedor.IdCtaContProveedores + ViewState("CtaProveedorAnticipos") = ObjProveedor.IdCtaContAnticipos + ViewState("CtaProveedorAnticiposExtranjera") = ObjProveedor.IdCtaContAnticiposExtranjera + ViewState("CtaProveedorAnticiposComplementaria") = ObjProveedor.IdCtaContAnticiposComplementaria + ViewState("CtaProveedorDeudores") = ObjProveedor.IdCtaContDeudor + ViewState("CtaProveedorAcreedores") = ObjProveedor.IdCtaContAcreedor + ViewState("CtaProveedorRetISR") = ObjProveedor.IdCtaContRetISR + ViewState("CtaProveedorRetIVA") = ObjProveedor.IdCtaContRetIVA + ViewState("CtaProveedorExtranjera") = ObjProveedor.IdCtaContProveedoresExtranjera + ViewState("CtaProveedorComplementaria") = ObjProveedor.IdCtaContProveedoresComplementaria + ViewState("IdCtaContDocsXPagar") = ObjProveedor.IdCtaContDocsXPagar + + 'Conta SIG + ViewState("CveCuentaProveedor") = ObjProveedor.CveCuentaProveedores + ViewState("CveCuentaProveedorAnticipos") = ObjProveedor.CveCuentaAnticipos + ViewState("CveCuentaProveedorAnticiposExtranjera") = ObjProveedor.CveCuentaAnticiposExtranjera + ViewState("CveCuentaProveedorAnticiposComplementaria") = ObjProveedor.CveCuentaAnticiposComplementaria + ViewState("CveCuentaProveedorDeudores") = ObjProveedor.CveCuentaDeudor + ViewState("CveCuentaProveedorAcreedores") = ObjProveedor.CveCuentaAcreedor + ViewState("CveCuentaProveedorRetISR") = ObjProveedor.CveCuentaRetISR + ViewState("CveCuentaProveedorRetIVA") = ObjProveedor.CveCuentaRetIVA + ViewState("CveCuentaProveedorExtranjera") = ObjProveedor.CveCuentaProveedoresExtranjera + ViewState("CveCuentaProveedorComplementaria") = ObjProveedor.CveCuentaProveedoresComplementaria + + + ViewState("NombreProveedor") = ObjProveedor.RazonSocial + + HdnCveProveedor.Value = ObjProveedor.CveProveedor.ToString + + If ObjProveedor.EditarFolioDuplicado Then + TxtFolio.Enabled = True + TxtSerie.Enabled = True + End If + + TxtCodigo.Text = ObjProveedor.Codigo + LblRFC.Text = String.Format("{1}", Me.CveProveedor, ObjProveedor.RFC) + HplProveedor.Text = ObjProveedor.NombreComercial : HplProveedor.NavigateUrl = String.Format("/Compras/Proveedores.aspx?CveProveedor={0}", Me.CveProveedor) + DdlProveedor.SelectedValue = ObjProveedor.CveProveedor.ToString + LblDiasCredito.Text = ObjProveedor.PlazoPago.ToString + LblLimiteCredito.Text = ObjProveedor.LimiteCredito.FormatoNumero + LblCreditoDisponible.Text = ObjProveedor.LimiteCredito.FormatoNumero + + If Not CveCompra > 0 Then '[IPP] SI YA ESTA REGISTRADA LOS VALORES SE CARGAN EN EL CARGACOMPRA() + 'DF 11-04-17 + Dim dtprovsuc As DataTable = GlobalDTProveedorSucursales(ObjProveedor.CveProveedor, UsuarioActual.CveEmpresa) + If dtprovsuc IsNot Nothing AndAlso dtprovsuc.Rows.Count > 0 Then + RowProveedorSucursal.Visible = True + DdlProveedorSucursal.Items.Clear() + DdlProveedorSucursal.DataSource = dtprovsuc + DdlProveedorSucursal.DataBind() + DdlProveedorSucursal.Items.Insert(0, New ListItem("Seleccione", "-1")) + DdlProveedorSucursal.Items.Insert(0, New ListItem("Matriz", "0")) + 'si tiene una serie cargada, sugiere la sucursal + If TxtSerie.Text.Trim <> "" Then + DdlProveedorSucursal.SelectedValueExist(dtprovsuc.FiltroPrimeroValor("CveProveedorSucursal", $"Serie LIKE '%{TxtSerie.Text.Trim}%'").ToString()) + End If + Else + RowProveedorSucursal.Visible = False + DdlProveedorSucursal.Items.Clear() + DdlProveedorSucursal.Items.Insert(0, New ListItem("N/A", "-1")) + DdlProveedorSucursal.DataBind() + End If + End If + + If CveCompra <= 0 AndAlso CveFactura <= 0 Then 'si se está cargando una factura o compra no se carga + 'LblRetIVA.Text = ObjProveedor.RetIVA.ToString.FormatoNumero(5) + 'LblRetISR.Text = ObjProveedor.RetISR.ToString.FormatoNumero(5) + + If ObjProveedor.RFC = "XAXX010101000" Then ' RFC Generico + 'cuando se esta dando de alta de nueva la compra, se obtiene el folio siguiente de no deducibles + Dim ObjComp As New ClsCompras + TxtFolio.Text = ObjComp.GetSiguienteFolio(ObjProveedor.CveProveedor, TxtSerie.Text).ToString + ObjComp.Dispose() + End If + End If + ViewState("IVA") = ObjProveedor.IVA + HdnProveedorIVA.Value = ObjProveedor.IVA.ToString + + ViewState("IdCtaContProveedores") = ObjProveedor.IdCtaContProveedores + ViewState("IdCtaContAnticipos") = ObjProveedor.IdCtaContAnticipos + ViewState("IdCtaProveedorDeudores") = ObjProveedor.IdCtaContDeudor + ViewState("IdCtaProveedorAcreedores") = ObjProveedor.IdCtaContAcreedor + ViewState("IdCtaContRetIVA") = ObjProveedor.IdCtaContRetIVA + ViewState("IdCtaContRetISR") = ObjProveedor.IdCtaContRetISR + + If UsuarioActual.Empresa.Funcionalidad(200) = "1" AndAlso ObjProveedor.IdCtaContProveedores < 1 Then + Alert("El Proveedor seleccionado no tiene cuenta contable asignada.", TipoMensaje.MsgAdvertencia) + End If + + ViewState("CveProveedor") = ObjProveedor.CveProveedor + HdnCveProveedor.Value = ObjProveedor.CveProveedor.ToString + TxtFechaPago.Text = (TxtFecha.Text.ToDate.AddDays(LblDiasCredito.Text.ToEntero)).ToShortDateString + RFCProv = ObjProveedor.RFC + CargaRetIVAConcepto(True) + CargaRetISRConcepto(True) + + If ObjProveedor.DIOTCveTipoOperacion = 1 Then '03 - Prestación de Servicios Profesionales + DdlRetIVAConcepto.SelectedValueExist("1") + DdlRetISRConcepto.SelectedValueExist("1") ' honorarios + ElseIf ObjProveedor.DIOTCveTipoOperacion = 2 Then ' 06 - Arrendamiento de inmuebles + DdlRetIVAConcepto.SelectedValueExist("4") + DdlRetISRConcepto.SelectedValueExist("2") ' arrendamiento + ElseIf ObjProveedor.DIOTCveTipoOperacion = 3 Then ' 85 - Otros + DdlRetIVAConcepto.SelectedValueExist("2") ' flete pf + DdlRetIVAConcepto.SelectedValueExist("3") ' fletes pm + DdlRetISRConcepto.SelectedValueExist("1") ' honorarios + End If + + LbAgregar.Enabled = True + UpPSS.Update() + UpPS.Update() + UpParametros.Update() + UPCondicionesPago.Update() + 'si tiene el habiltiado el módulo de Contratos + 'checo si tiene estimaciones + + 'CargaDatosEstimaciones(ObjProveedor.CveProveedor) + ImgBtnBuscarOC.OnClientClick = String.Format("AbrirVentana('/OC/PopUpBuscarReq.aspx?V=VOCCOMP&P={0}&T={1}&Masterimpoup=true',1000,600,'S'); return false;", ObjProveedor.CveProveedor, DdlTipoComprobante.SelectedValue) + CargaAnticipos(ObjProveedor.CveProveedor) : UpAnticipos.Update() + + If UsuarioActual.Empresa.UsaAC Then + If (TxtRetIVA.Text.ToDouble > 0 And Not ObjProveedor.IdCtaContRetIVA > 0) Or (TxtRetISR.Text.ToDouble > 0 And Not ObjProveedor.IdCtaContRetISR > 0) Then ' + ImgBtnBuscarOC.Visible = False + TxtOC.Enabled = False + BtnGuardar.Visible = False + Alert("El proveedor no tiene registrada cuentas contables de retenciones. Debe asignar las cuentas en el registro del proveedor.", TipoMensaje.MsgAdvertencia) + DivRestriccionAdvertencia.Visible = True + LtRestriccionAdvertencia.Text = "El proveedor no tiene registrada cuentas contables de retenciones." + End If + End If + + CargaGvAcarreos(ViewState("CveProveedor").ToString.ToEntero) + + + 'MONEDA PREFERENTE + If CveCompra <= 0 Then + If CveFactura <= 0 Then + DdlMoneda.SelectedValueExist(ObjProveedor.CveMonedaPreferente) + End If + CambiaMoneda(False) + End If + + + If CveProveedor > 0 Then + + Dim ObjSAT As New ClsSAT + Dim RFCRequest As String = ObjProveedor.RFC + If ObjSAT.GetListado69B(2, UsuarioActual.CveEmpresa, RFCRequest) Then + If ObjSAT.DtResultados.Rows.Count > 0 Then + Dim Estatus As String = ObjSAT.DtResultados.Rows(0)("Situacion").ToString + BtnGuardar.Enabled = False + UpParametros.Update() + + Alert($"El RFC del proveedor se encuentra en estado {Estatus} en el Listado EFOS (69B) del SAT", TipoMensaje.MsgAdvertencia) + System.Threading.Thread.Sleep(5) + End If + End If + ObjSAT.Dispose() + + End If + + + + Else + Alert("El Proveedor solicitado no existe, por favor intente de nuevo.", TipoMensaje.MsgAdvertencia) + End If + Else + Alert("Ocurrió un error al consultar el proveedor.", TipoMensaje.MsgError) + End If + + If UsuarioActual.Empresa.Funcionalidad(560) = "1" Then + If ObjProveedor.GetProveedoresEvaluacionPediente(Me.CveProveedor, UsuarioActual.CveEmpresa) Then + If ObjProveedor.DtResultados.Rows.Count > 0 Then + Me.RequiereEvaluacion = ObjProveedor.DtResultados.Rows(0)("RequiereEvaluacion").ToString() = "1" + Me.CveUsuarioEvaluador = ObjProveedor.DtResultados.Rows(0)("CveUsuarioEvaluador").ToString().ToEntero() + End If + End If + End If + + ObjProveedor.Dispose() + End Sub + + Private Sub CargaAnticipos(CveProveedor As Integer, Optional FiltroTipo As String = "-1") + Dim ObjMovtos As New ClsMovimientos() + If ObjMovtos.GetAnticiposProveedor(CveProveedor, -1, CveMoneda:=-1, SelectTop:=-1, TipoDocto:=FiltroTipo) AndAlso ObjMovtos.DtResultados.Rows.Count > 0 Then + Dim CveMoneda As Integer = If(ChkPagarConPesos.Checked, 1, If(ChkPagarConDolares.Checked, 2, DdlMoneda.SelectedValue.ToEntero)) + If DdlMoneda.SelectedValue.ToEntero = 1 AndAlso CveCompra > 0 Then DivPagarConDolares.Visible = True Else If CveCompra > 0 Then DivPagarConPesos.Visible = True + GVAnticipos.DataSource = ObjMovtos.DtResultados.FiltraParametros($"Tipo = 'Act' AND CveMoneda = {CveMoneda}") + If ObjMovtos.DtResultados.FiltraParametros("Saldo > 0").Rows.Count > 0 Then + BtnAceptarAnticipos.Enabled = True + If DdlTipoComprobante.SelectedValue = "Fac" Then ImgAnticiposPendientes.Visible = True + End If + Else + GVAnticipos.DataSource = Nothing + End If + ObjMovtos.Dispose() + GVAnticipos.DataBind() + End Sub + + Private Sub CargaTiposAF() + ViewState("TmpDTTiposAF") = GlobalDTTipoActivoFijo(UsuarioActual.CveEmpresa) + Dim Row As DataRow = DirectCast(ViewState("TmpDTTiposAF"), DataTable).NewRow() + Row("CveTipoActivoFijo") = -1 : Row("TipoActivoFijo") = "Seleccione" + DirectCast(ViewState("TmpDTTiposAF"), DataTable).Rows.InsertAt(Row, 0) + End Sub + + Public Function isWhitFamily() As Boolean + Return UsuarioActual.CveEmpresa = 66 + End Function + + Private Sub CargaPSAlias() + DdlPSAlias2.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1") + + If UsuarioActual.CveEmpresa = 66 Then + DdlPSAlias2.ddlWS.Attributes.Add("data-subfamilia", "-1") + DdlPSAlias2.ddlWS.Attributes.Add("data-fueporxml", "0") + 'SOLO CUANDO SEA FACTURA DE INGRESOS + If DdlTipoComprobante.SelectedValue = "Fac" Then + DdlPSAlias2.ddlWS.Attributes.Add("data-pagina", "Compras") + Else + DdlPSAlias2.ddlWS.Attributes.Add("data-pagina", "Compras2") + End If + End If + If Not DdlPSAlias2.UsaWebService AndAlso CType(DdlPSAlias2.DataSource, DataTable) Is Nothing Then + DdlPSAlias2.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa) + DdlPSAlias2.DataBind() + End If + + End Sub + + Private Sub CargarUM(CvePS As Integer, ob As DropDownList) + Dim ObjUM As New ClsProductosServicios() + If ObjUM.GetPSEquivalencias(CvePS, UsuarioActual.CveEmpresa) Then + ViewState("DTUM") = ObjUM.DtResultados + ob.Items.Clear() + ob.DataSource = DTUM + ob.DataBind() + + End If + ObjUM.Dispose() + + End Sub + + Private Sub CargaGridTarjetas() + Dim ObjCreditos As New ClsBancos + ObjCreditos.GetTarjetasCreditos(DdlCuenta.SelectedValue.ToEntero) + + DdlTarjeta.Items.Clear() + DdlTarjeta.DataSource = ObjCreditos.DtResultados + DdlTarjeta.DataBind() + DdlTarjeta.Items.Insert(0, New ListItem("Seleccione", "-1")) + + ObjCreditos.Dispose() + DivTarjeta.Visible = True + End Sub + + Private Sub CargaConceptosXML(XMLDoc As XmlDocument) + Dim i As Integer = 0 + + Dim Total As Decimal = 0 + Dim PU As Decimal = 0 + Dim Descuento As Double = 0 + Dim CveUM As Integer = 0 + Dim UMM As String = "No Aplica" + Dim tCvePS As Integer = 0 + Dim TipoPS As Integer = 0 + Dim tCveClasif As Integer = -1 + Dim Clasif As String = "Sin Clasificación" + Dim tPSCodigo As String = "-" + Dim tPSDescripcion As String = "-" + Dim PSS As String = "" + Dim Obs As String = "" + Dim SubTotalTemp = 0.0D + Dim IVA As Double = 0 + Dim IEPS As Double = 0 + Dim RetISR As Double = 0 + Dim RetIVA As Double = 0 + Dim PorcentajeIVA As Double = 0 + Dim PorcentajeIEPS As Double = 0 + Dim PorcentajeRetISR As Double = 0 + Dim PorcentajeRetIVA As Double = 0 + Dim DtTemporalGuardados = New DataTable + DtTemporalGuardados.Columns.Add("Contador", GetType(Integer)) + DtTemporalGuardados.Columns.Add("Tipo", GetType(Integer)) + + 'GLOBALS + Dim DtUM = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa).AsEnumerable + Dim DtUMAlias = GlobalDTUnidadesMedidaAlias(UsuarioActual.CveEmpresa).AsEnumerable + Dim DtPS = GlobalDTPS(UsuarioActual.CveEmpresa).AsEnumerable + Dim DtPSAlias = GlobalDTProductosServiciosAlias(UsuarioActual.CveEmpresa).AsEnumerable + + ''AGREGA EN TABLA TEMPORAL + 'Dim DtPSTemp = TmpDT.Clone + 'Dim Row As DataRow = Nothing + + Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix) + Dim cfdVer As String = "http://www.sat.gob.mx/cfd/3" + Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable) + + If Prefijo.ToLower <> "cfdi" Then cfdVer = "http://www.sat.gob.mx/cfd/2" + namespaces.AddNamespace(Prefijo, cfdVer) + namespaces.AddNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital") + namespaces.AddNamespace("implocal", "http://www.sat.gob.mx/implocal") + namespaces.AddNamespace("registrofiscal", "http://www.sat.gob.mx/registrofiscal") + + Dim nodeconcepto As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Conceptos", Prefijo), namespaces) + If nodeconcepto IsNot Nothing AndAlso nodeconcepto.ChildNodes.Count > 0 Then + Dim nodosConceptos As XmlNodeList = nodeconcepto.SelectNodes(String.Format("//{0}:Concepto", Prefijo), namespaces) + For Each node As XmlNode In nodosConceptos + + ' INICIALIZA VALORES + PU = 0 + Descuento = 0 + CveUM = 0 + UMM = "No Aplica" + tCvePS = 0 + TipoPS = 0 + tCveClasif = -1 + Clasif = "Sin Clasificación" + tPSCodigo = "-" + tPSDescripcion = "-" + PSS = "" + Obs = "" + Total = 0 + IVA = 0 + IEPS = 0 + RetISR = 0 + RetIVA = 0 + PorcentajeIVA = 0 + PorcentajeIEPS = 0 + PorcentajeRetISR = 0 + PorcentajeRetIVA = 0 + + + 'CARGA NODO ACTUAL + ' node = XMLDoc.DocumentElement.ChildNodes(2).ChildNodes(i) + + 'CARGA PU + PU = ValorXML(node, "valorUnitario").ToDecimal + + 'SI PU >= TOTAL AND CANTIDAD > 0 : PU / CANTIDAD, por si tiene descuento en el importe y el valor unitario es mayor, lo ajusta + If ValorXML(node, "cantidad").ToDecimal > 0 AndAlso ValorXML(node, "valorUnitario").ToDecimal >= (ValorXML(node, "importe").ToDecimal / ValorXML(node, "cantidad").ToDecimal) Then + PU = ValorXML(node, "importe").ToDecimal / ValorXML(node, "cantidad").ToDecimal + End If + If ValorXML(node, "cantidad").ToDecimal > 0 AndAlso ValorXML(node, "valorUnitario").ToDouble <= 0 And ValorXML(node, "importe").ToDouble > 0 Then + PU = ValorXML(node, "importe").ToDecimal / ValorXML(node, "cantidad").ToDecimal + End If + + + + + 'OBTIENE DESCUENTO + If ValorXML(node, "descuento") IsNot Nothing Then Descuento = ValorXML(node, "descuento").Trim.ToDouble + + 'OBTIENE TOTAL + If ValorXML(node, "importe") IsNot Nothing Then Total = ValorXML(node, "importe").Trim.ToDecimal + + 'OBTIENE SUBTOTAL + SubTotalTemp += If(Total > 0, Total, PU * ValorXML(node, "cantidad").ToDecimal) + + + 'OBTIENE UM + If ValorXML(node, "unidad") IsNot Nothing Then UMM = ValorXML(node, "unidad").Trim + 'BUSCA UM EN CATALOGO + UMM = UMM.ToUpper.Replace(".", "").Replace(",", "") + Dim fUM = (From u In DtUM + Where String.Compare(u!UnidadMedida.ToString.ToUpper.Trim, UMM, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 OrElse + String.Compare(u!Abreviatura.ToString.ToUpper.Trim, UMM, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 + Select CveUnidadMedida = u!CveUnidadMedida, UnidadMedida = u!UnidadMedida).FirstOrDefault() + If fUM IsNot Nothing AndAlso fUM.CveUnidadMedida.ToString.ToEntero > 0 Then + CveUM = fUM.CveUnidadMedida.ToString.ToEntero + UMM = fUM.UnidadMedida.ToString + Else + + 'BUSCA UM EN ALIAS + Dim fUMAlias = (From u In DtUMAlias + Where String.Compare(u!UnidadMedidaAlias.ToString.ToUpper.Trim, UMM, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 + Select u!CveUnidadMedida, u!UnidadMedida).FirstOrDefault() + + If fUMAlias IsNot Nothing Then + CveUM = fUMAlias.CveUnidadMedida.ToString.ToEntero + UMM = fUMAlias.UnidadMedida.ToString + End If + End If + + + + 'se le puso una condicion de que ignorara los acentos, porque en la bd, marcaria error porque no distingue acentos + 'CONCEPTO PRUEBA "TRABAJOS DE CONSTRUCCION", RM/Compras/Compras.aspx?CveFactura=13402&RFC=ECO061206QW7 + '' u!PS.ToString.ToUpper.Trim = PSS + + + 'BUSCA PS + + PSS = ValorXML(node, "descripcion").ToUpper.Trim.Replace(vbCrLf, " ").Replace(vbLf, " ").Replace("'", "''").Replace(" ", " ").Replace("�", "") + If PSS.Length > 844 Then + PSS = PSS.Substring(0, 844) '844,por ser el numero de caracteres aceptados en la columna de la BD + End If + tPSCodigo = PSS + + 'BUSCA PS EN CATALOGO + Dim fPS = (From u In DtPS + Where String.Compare(u!PS.ToString.ToUpper.Trim, PSS, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 + Select u!CvePS, u!CveClasificacion, u!Clasificacion, u!CveTipoPS, u!PSCodigo).FirstOrDefault() + + If fPS IsNot Nothing Then + PSS = fPS.PSCodigo.ToString + tCvePS = fPS.CvePS.ToString.ToEntero + TipoPS = fPS.CveTipoPS.ToString.ToEntero + tCveClasif = fPS.CveClasificacion.ToString.ToEntero + Clasif = fPS.Clasificacion.ToString + tPSCodigo = fPS.PSCodigo.ToString + Else + 'BUSCA PS EN ALIAS + Dim fPSAlias = (From u In DtPSAlias + Where String.Compare(u!PSAlias.ToString.ToUpper.Trim, PSS, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace) = 0 + Select u!CvePS, u!PS, u!CveClasificacion, u!Clasificacion, u!CveTipoPS, u!PSCodigo).FirstOrDefault() + If fPSAlias IsNot Nothing Then + Obs = PSS + PSS = fPSAlias.PS.ToString + tCvePS = fPSAlias.CvePS.ToString.ToEntero + TipoPS = fPSAlias.CveTipoPS.ToString.ToEntero + tCveClasif = fPSAlias.CveClasificacion.ToString.ToEntero + Clasif = fPSAlias.Clasificacion.ToString + tPSCodigo = fPSAlias.PSCodigo.ToString + End If + End If + + + 'PARA GLUYAS + If UsuarioActual.CveEmpresa = 66 Then + tPSCodigo = String.Format("{1} - {0}", ValorXML(node, "descripcion").ToUpper.Trim.Replace(vbCrLf, " ").Replace(vbLf, " ").Replace("'", "''"), ValorXML(node, "noIdentificacion").Trim) + End If + + + If Version = "3.3" Then + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + 'OBTENER TRASLADOS POR DETALLES + Dim ContadorTraslado = 0 + Dim nodosConceptosTraslado As XmlNodeList = node.SelectNodes(String.Format("//{0}:Impuestos/{0}:Traslados/{0}:Traslado", Prefijo), namespaces) + For Each nodeTraslado As XmlNode In nodosConceptosTraslado + + If Not DtTemporalGuardados.FiltraParametros($"Contador = {ContadorTraslado} AND Tipo = 1").Rows.Count > 0 Then + If ValorXML(nodeTraslado, "TasaOCuota").Trim.ToDecimal > 0 And ValorXML(nodeTraslado, "Base").Trim.ToDecimal = Total Then + If ValorXML(nodeTraslado, "Impuesto") = "002" Then + IVA = ValorXML(nodeTraslado, "Importe").Trim.ToDecimal + PorcentajeIVA = ValorXML(nodeTraslado, "TasaOCuota").Trim.ToDecimal + Dim Dr As DataRow + Dr = DtTemporalGuardados.NewRow() + Dr("Contador") = ContadorTraslado + Dr("Tipo") = 1 + DtTemporalGuardados.Rows.Add(Dr) + DtTemporalGuardados.AcceptChanges() + Exit For + ElseIf ValorXML(nodeTraslado, "Impuesto") = "003" Then + IEPS = ValorXML(nodeTraslado, "Importe").Trim.ToDecimal + PorcentajeIEPS = ValorXML(nodeTraslado, "TasaOCuota").Trim.ToDecimal + Dim Dr As DataRow + Dr = DtTemporalGuardados.NewRow() + Dr("Contador") = ContadorTraslado + Dr("Tipo") = 1 + DtTemporalGuardados.Rows.Add(Dr) + DtTemporalGuardados.AcceptChanges() + Exit For + End If + + End If + End If + ContadorTraslado += 1 + Next + + 'OBTENER RETENCIONES POR DETALLES + Dim ContadorRetenciones = 0 + Dim nodosConceptosRetenciones As XmlNodeList = node.SelectNodes(String.Format("//{0}:Impuestos/{0}:Retenciones/{0}:Retencion", Prefijo), namespaces) + For Each nodeRetencion As XmlNode In nodosConceptosRetenciones + + If Not DtTemporalGuardados.FiltraParametros($"Contador = {ContadorRetenciones} AND Tipo = 2").Rows.Count > 0 Then + If ValorXML(nodeRetencion, "TasaOCuota").Trim.ToDecimal > 0 And ValorXML(nodeRetencion, "Base").Trim.ToDecimal = Total Then + If ValorXML(nodeRetencion, "Impuesto".Trim) = "001" Then + RetISR = ValorXML(nodeRetencion, "Importe").Trim.ToDecimal + PorcentajeRetISR = ValorXML(nodeRetencion, "TasaOCuota").Trim.ToDecimal + Dim Dr As DataRow + Dr = DtTemporalGuardados.NewRow() + Dr("Contador") = ContadorRetenciones + Dr("Tipo") = 2 + DtTemporalGuardados.Rows.Add(Dr) + DtTemporalGuardados.AcceptChanges() + Exit For + ElseIf ValorXML(nodeRetencion, "Impuesto") = "002" Then + RetIVA = ValorXML(nodeRetencion, "Importe").Trim.ToDecimal + PorcentajeRetIVA = ValorXML(nodeRetencion, "TasaOCuota").Trim.ToDecimal + Dim Dr As DataRow + Dr = DtTemporalGuardados.NewRow() + Dr("Contador") = ContadorRetenciones + Dr("Tipo") = 2 + DtTemporalGuardados.Rows.Add(Dr) + DtTemporalGuardados.AcceptChanges() + Exit For + End If + + End If + End If + ContadorRetenciones += 1 + Next + End If + + End If + + If Version = "3.2" Then + + + + + Try + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + Dim ContadorTraslado = 0 + Dim nodosConceptosTraslado As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Impuestos/{0}:Traslados/{0}:Traslado", Prefijo), namespaces) + + For Each nodeTraslado As XmlNode In nodosConceptosTraslado + If ValorXML(nodeTraslado, "tasa").Trim.ToDecimal > 0 And ValorXML(nodeTraslado, "impuesto").Trim = "IVA" Then + PorcentajeIVA = ValorXML(nodeTraslado, "tasa").Trim.ToDecimal + Alert($"{PorcentajeIVA}") + End If + Next + End If + Catch ex As Exception + + End Try + + End If + + + + '' AGREGA PS + 'AGREGA A TMPDT + AddPS(ValorXML(node, "cantidad").ToDouble, CveUM, UMM, tCveClasif, Clasif, tCvePS, PSS, TipoPS, "-1", "SE", "SE", "-1", Obs, PU, Total, IVA, RetIVA, RetISR, IEPS, 0, Descuento, PSCodigo:=tPSCodigo, TCalculaTotales:=False, CveSATPS:=ValorXML(node, "ClaveProdServ").ToEntero(), CargaXml:=True, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, PorcentajeRetISR:=PorcentajeRetISR, PorcentajeIEPS:=PorcentajeIEPS) + + Next + End If + + AddPS2(False) + + If UsuarioActual.Empresa.UsaAC Then + CompruebaAgregar() + End If + + If isAlmacenistaGluyas() Then + BtnGuardar.Visible = False + AlmacenCambiaPS.Visible = True + End If + + SubTotalConceptos = Math.Round(SubTotalTemp, 2) + 'TmpDT = DtPSTemp.Copy + 'DtPSTemp.Dispose() + + End Sub +#End Region + +#Region "Vinculacion De Servcios" + Private Function isAdminObraGluyas() As Boolean + Return (UsuarioActual.CveRol = 1047 And UsuarioActual.CveEmpresa = 66) + End Function + Private Sub cargaddlVinculacionServcios() + If isAdminObraGluyas() Then + TabVinculacionServicios.Visible = True + 'Dim productos As New ClsProductosServicios + 'If productos.GetPS(-1, -1, UsuarioActual.CveEmpresa) Then + ' PSDTRemplazo = productos.DtResultados.FiltraParametros("CveTipoPS=2", "PS") + 'End If + 'productos.Dispose() + GVVinculacionServicios.DataSource = TmpDT + GVVinculacionServicios.DataBind() + End If + End Sub + Protected Sub GVVinculacionServicios_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVVinculacionServicios.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + Dim dt As DataTable = Nothing + dt = GlobalDTPS(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoPS=2", "PS") + e.Row.FCDropDownList("Ddlnewps").DataSource = dt 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) + e.Row.FCDropDownList("Ddlnewps").DataBind() + e.Row.FCDropDownList("Ddlnewps").Items.Insert(0, New ListItem("Seleccione", "-1")) + dt.Dispose() + + End If + End Sub + +#End Region + +#Region "BTN'S" + Protected Sub BtnVincularServicios_Click(sender As Object, e As EventArgs) Handles BtnVincularServicios.Click + Dim correcto As Boolean = True + Dim x As Integer = 0 + 'Dim buid As New StringBuilder + For Each Dr As DataRow In TmpDT.Rows + Dim newps As Integer = GVVinculacionServicios.Rows(x).FCDropDownList("Ddlnewps").SelectedValue.ToEntero + If newps > 0 Then + 'buid.Append(String.Format("{0} ---> {1},", Dr("CvePS").ToString, newps)) + Dr("CvePS") = newps + 'buid.Append(String.Format("{0} ---> {1},
", Dr("CvePS").ToString, newps)) + Else 'limpio el valor para que no truene en linq mas abajo + correcto = False + Alert("Favor de vincular todos los servicios", TipoMensaje.MsgAdvertencia) + Exit For + End If + x = x + 1 + Next + x = 0 + For Each Dr As DataRow In GVVinculacionServicios.Rows + Dim newps As Integer = GVVinculacionServicios.Rows(x).FCDropDownList("Ddlnewps").SelectedValue.ToEntero + If newps > 0 Then + 'buid.Append(String.Format("{0} ---> {1},", Dr("CvePS").ToString, newps)) + Dr("CvePS") = newps + 'buid.Append(String.Format("{0} ---> {1},
", Dr("CvePS").ToString, newps)) + Else 'limpio el valor para que no truene en linq mas abajo + correcto = False + Alert("Favor de vincular todos los servicios", TipoMensaje.MsgAdvertencia) + Exit For + End If + x = x + 1 + Next + + TmpDT.AcceptChanges() + 'Alert(buid.ToString) + If correcto Then + If Not CierrePeriodo Then + BtnGuardar.Visible = True + End If + UpFacturar.Update() + End If + End Sub + + Protected Sub BtnCargarProveedores_Click(sender As Object, e As System.EventArgs) Handles BtnCargarProveedores.Click + DdlProveedor.CssClass += " select2me" + DdlProveedor.AutoPostBack = True + DdlProveedor.Items.Clear() + DdlProveedor.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa) + 'Dim ObjProveedor As New ClsCompProveedores + 'If ObjProveedor.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, -1, "-1", "-1", "-1", "-1", "-1", "-1", "-1", UsuarioActual.CveEmpresa) Then + 'DdlProveedor.DataSource = ObjProveedor.DtResultados + 'End If + DdlProveedor.DataBind() + DdlProveedor.Items.Insert(0, New ListItem("Seleccione el Proveedor", "-1")) + DdlProveedor.Attributes.Remove("onclick") + + 'RegistraScript("$('#C_DdlProveedor').select2('open');") + End Sub + + Protected Sub BtnBuscarProveedor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnBuscarProveedor.Click + ViewState("CveProveedor") = HdnCveProveedor.Value.ToEntero + CargaProveedor(HdnCveProveedor.Value.ToEntero, "-1") + + If DdlPS.SelectedValue IsNot Nothing AndAlso DdlPS.SelectedValue.ToEntero > 0 Then + DdlPS_SelectedIndexChanged(sender, e) + DdlPS.Focus() + Else + TxtCantidad.Focus() + End If + + End Sub + + Protected Sub BtnGuardar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGuardar.Click + + '------------------INICIA VALIDACIONES------------------ + Dim EstatusCredito As Integer = 0 + 'Credito Multiple + If RBLPago.SelectedValue.ToEntero = 4 Then + + Dim DifCreCompra As Decimal = 0 + Dim TotalCreditos As Decimal = 0 + Dim MensualidadMultipleTotal As Decimal = 0 + Dim CveUltimoCreditoDetalleInterno As Integer + + For Each GvRow As GridViewRow In GvCreditos.Rows + + Dim CapitalMiltiple As Decimal = GvRow.FCTextBox("TxtCapital").Text.ToDecimal + Dim InteresMiltiple As Decimal = GvRow.FCTextBox("TxtInteres").Text.ToDecimal + + Dim AmbosMiltiple As Decimal = GvRow.FCTextBox("TxtAmbos").Text.ToDecimal + Dim MensualidadMultiple As Decimal = GvRow.DataKey("Mensualidad").ToDecimal + + If CapitalMiltiple > 0 Or InteresMiltiple > 0 Then + + TotalCreditos = TotalCreditos + CapitalMiltiple + InteresMiltiple + MensualidadMultipleTotal = MensualidadMultipleTotal + MensualidadMultiple + CveUltimoCreditoDetalleInterno = GvRow.DataKey("CveCreditoDetalle").ToEntero + + ElseIf AmbosMiltiple > 0 Then + + TotalCreditos = TotalCreditos + AmbosMiltiple + MensualidadMultipleTotal = MensualidadMultipleTotal + MensualidadMultiple + CveUltimoCreditoDetalleInterno = GvRow.DataKey("CveCreditoDetalle").ToEntero + EstatusCredito = GvRow.DataKey("Estatus").ToEntero + End If + Next + + If TotalCreditos <> TxtTotal.Text.ToDecimal Then + Alert($"El importe de La factura no concide con el total de los creditos, diferencia: { (TotalCreditos - TxtTotal.Text.ToDecimal).FormatoNumero(2)}", TipoMensaje.MsgAdvertencia) + Exit Sub + + End If + End If + + 'Si se marcó No Deducible en el encabezado mínimo se debe registrar un No Deducible en el Detalle + Dim GuardaNoDeducibles As Boolean = False + If ChkEsNoDeducible.Checked Then + For Each Row As DataRow In TmpDT.Rows + If Row("NoDeducible").ToString().ToUpper().Contiene("TRUE", "1") Then + GuardaNoDeducibles = True + End If + Next + If GuardaNoDeducibles = False Then + Alert("Si la compra es No Deducible, mínimo se debe registrar un producto No Deducible", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + + + If CierrePeriodo Then + Alert("El periodo de la compra actual ya se encuentra cerrado. No podra registrar la compra.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'DF - 10/04/2017 + If UsuarioActual.TienePermisoProceso(187) Then + If TxtSerie.Text <> SerieVieja Then + Dim SerieNueva As String = GlobalDTProveedorSucursales(CveProveedor, UsuarioActual.CveEmpresa).FiltroPrimeroValor("Serie", $"Serie = '{TxtSerie.Text}'").ToString + If SerieNueva = "" Then + Alert("La Serie no es válida, por favor revise que se encuentre dentro de la lista de las sucursales del proveedor.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + End If + + 'Excede el limite de credito + If RBLPago.SelectedValue = "1" AndAlso DdlTipoComprobante.SelectedValue.Contiene("Fac") AndAlso UsuarioActual.Empresa.Funcionalidad(518) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(185) Then + Dim ObjCompras As New ClsCompras + If ObjCompras.ObtenerCreditoRestante(CveProveedor) Then + If ObjCompras.DtResultados.Rows.Count > 0 Then + Dim Saldo As Decimal = ObjCompras.DtResultados(0)("Saldo").ToString.ToDecimal + TxtTotal.Text.ToDecimal + Dim LimiteCredito As Decimal = ObjCompras.DtResultados(0)("LimiteCredito").ToString.ToDecimal + + If LimiteCredito > 0 Then + If Saldo / LimiteCredito * 100 > 90 Then + Alert($"Nuestro Limite de Credito con este proveedor supera el 90%
Porcentaje Actual: {(Saldo / LimiteCredito * 100).FormatoNumero(2)}%", TipoMensaje.MsgAdvertencia) + End If + End If + Else + ObjCompras.Dispose() + Alert("El proveedor no tiene límite de crédito", TipoMensaje.MsgError) + Exit Sub + End If + Else + ObjCompras.Dispose() + Alert("Ocurrio un error al obtener el limite de credito del Proveedor", TipoMensaje.MsgError) + Exit Sub + End If + ObjCompras.Dispose() + End If + + If Not (HFDiferenciaCompra.Value = TxtTotal.Text Or CveFactura < 1 Or CveCompra < 1) Then + Alert("La compra no se puede registrar debido a que los totales no son iguales, verifique sus cambios", TipoMensaje.MsgError) + Exit Sub + End If + + 'UM EQUIVALENCIAS + For Each gvr As GridViewRow In GvPS.Rows + If gvr.DataKey("CvePS").ToString.ToEntero > 0 Then + If gvr.DataKey("CveUM").ToString.ToEntero = 0 Then + Alert("Existe un error, Unidad de Medida no registrada", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + Next + + If ChkConsignacion.Checked Then + For Each gvr As GridViewRow In GvInv.Rows + If gvr.FCDropDownList("DdlVinculaConsignacion").SelectedValue.ToEntero < 0 Then + Alert("Si la compra aplica consignación debe vincular todos los conceptos en Almacén.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + Next + End If + + If RowProveedorSucursal.Visible And DdlProveedorSucursal.SelectedValue.ToEntero = -1 Then + Alert("Favor de seleccionar una sucursal del proveedor", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If UsuarioActual.TienePermisoProceso(121) Then + If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + If Not NCDevolucion Then + Alert("Favor de seleccionar un producto en la pestaña de almacen", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + Else + Dim x As Integer = 0 + For Each Dr As GridViewRow In GvInv.Rows + If Dr.FCCheckBox("cbInv").Checked Then + x = x + 1 + End If + Next + If x = 0 AndAlso GvInv.Rows.Count > 0 Then + Alert("Favor de seleccionar un producto en la pestaña de almacen", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + End If + + If UsuarioActual.Empresa.Funcionalidad(538).ToEntero = 1 Then + If TmpDT.MIN("CvePS").ToEntero <= 0 Then + Alert("Todos los Productos/Servicios deben estar registrados o aliados a un productos ya registrado.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + + If UsuarioActual.Empresa.Funcionalidad(123).ToEntero > 0 And Not UsuarioActual.TienePermisoProceso(156) Then + If Not ValidaCierrePeriodo() Then + Alert("No se puede registar la compra. Se ha cerrado el periodo de la compra actual", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + + Dim TotalPorDevengar = Math.Round(TxtTotal.Text.ToDouble, 2) + Dim TotalDetalle = 0.0 + Dim RequiereCentroCosto As Boolean = False + + 'If Not (UsuarioActual.Empresa.Funcionalidad(102) = "") Then + ' Dim NotHas117 As Boolean = Not UsuarioActual.TienePermisoProceso(117) + ' 'verifica que tenga proyecto y clasificacion + For Each Row As DataRow In TmpDT.Rows + If Row("CveSubProyecto").ToString.ToEntero <= 0 Then + Alert("No se ha completado la asignacion de proyectos en la compra. ", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If Row("CveClasificacionActualizar").ToString.ToEntero <= 0 Then 'If NotHas117 AndAlso Row("CveClasificacionActualizar").ToString.ToEntero <= 0 Then + Alert("Hay productos que no tienen clasificación asignada.
Favor de asignarle una y darle guardar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If UsuarioActual.Empresa.Funcionalidad(527) = "1" Then + If Row("CveTipoGasto").ToString.ToEntero <= 0 Then + Alert("No se ha completado la asignacion de tipos de gasto en la compra.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + Next + 'End If + + 'SI LA CANTIDAD EN SERIE/LOTE NO ES IGUAL A CANTIDAD EN GVPS + 'Dim DtDetalles As DataTable + Dim Cantidad As Integer + + If GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True Then + For Each Dr As DataRow In DtInv.Rows + If Dr("CveMetodoInventario").ToString.ToEntero = 5 Then + Cantidad = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", Dr("CvePS").ToString)).Rows.Count + If Cantidad < Dr("Cantidad").ToString.ToEntero Then + Alert("No hay productos a los que no se le ha asociado Serie-Lote", TipoMensaje.MsgError) + Exit Sub + End If + End If + Next + End If + + If Not HdnCveProveedor.Value <> "-1" Then + Alert("En necesario seleccionar un proveedor, al cual se le va a facturar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If Not TmpDT.Rows.Count > 0 Then + Alert("Es necesario agregar al menos un Producto o Servicio a la factura.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'VALIDA SI LA CLASIFICACIÓN REQUIERE PERSONAL, AF COMPRA O AF INSUMO + Dim ErrorValidacion As Boolean = False + Dim DtTemporal As New DataTable + DtTemporal.Columns.Add("CveClasificacion", GetType(Integer)) + For Each Gvr As GridViewRow In GvPS.Rows + Dim Dr As DataRow = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros($"CveClasificacion = {Gvr.DataKey("CveClasificacion").ToEntero}")(0) + If Dr IsNot Nothing Then + Dim SeValido As Boolean = False + For Each Drt As DataRow In DtTemporal.Rows + If Drt("CveClasificacion").ToString.ToEntero = Dr("CveClasificacion").ToString.ToEntero Then + SeValido = True + Exit For + End If + Next + If Not SeValido Then + If CBool(Dr("RequierePersonal")) Then + For Each GvP As GridViewRow In GvPersonal.Rows + If GvP.DataKey("CveClasificacion").ToEntero = Dr("CveClasificacion").ToString.ToEntero Then + If Not GvP.FCDropDownList("DdlPersonalGv").SelectedValue.ToEntero > 0 Then + ErrorValidacion = True + Alert($"Tiene que seleccionar un personal para esta clasificación: {Dr("Clasificacion").ToString}.", TipoMensaje.MsgAdvertencia) + Exit For + End If + End If + Next + End If + If CBool(Dr("RequiereAFCompra")) Then + For Each GvAFC As GridViewRow In GvAFCompras.Rows + If GvAFC.DataKey("CveClasificacion").ToEntero = Dr("CveClasificacion").ToString.ToEntero Then + If Not GvAFC.FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then + ErrorValidacion = True + Alert($"Tiene que seleccionar un AF compra para esta clasificación: {Dr("Clasificacion").ToString}.", TipoMensaje.MsgAdvertencia) + Exit For + End If + End If + Next + End If + If CBool(Dr("RequiereAFInsumo")) Then + For Each GvAFI As GridViewRow In GvAFInsumos.Rows + If GvAFI.DataKey("CveClasificacion").ToEntero = Dr("CveClasificacion").ToString.ToEntero Then + If Not GvAFI.FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then + ErrorValidacion = True + If Not SeValido Then + Alert($"Tiene que seleccionar un AF insumo para esta clasificación: {Dr("Clasificacion").ToString}.", TipoMensaje.MsgAdvertencia) + End If + Exit For + End If + End If + Next + End If + Dim Drr As DataRow = DtTemporal.NewRow + Drr("CveClasificacion") = Dr("CveClasificacion").ToString.ToEntero + DtTemporal.Rows.Add(Drr) + End If + End If + Next + If ErrorValidacion Then Exit Sub + + '------------------TERMINA VALIDACIONES------------------ + + 'RECORRO LOS PRODUCTOS O SERVICIOS PARA REGISTRARLOS LOS QUE NO EXISTEN EN EL CATÁLOGO + Dim tCve As Integer + Dim RegeneraPS As Boolean = False + 'OBJETOS PROVISIONALES + Dim UM As New ClsUnidadesMedida + Dim PSS As New ClsProductosServicios + Dim Correcto = True + + For Each Row As DataRow In TmpDT.Rows + + 'VALIDACION DE CENTRO DE COSTO + If UsuarioActual.Empresa.RequiereCentroCostos AndAlso Row("CveSubProyecto").ToString.ToEntero <= 0 Then + RequiereCentroCosto = True + UM.Dispose() + PSS.Dispose() + Alert("Falta asignar Proyecto a la compra", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'REGISTRO LAS UNIDADES DE MEDIDA + If Row("CveUM").ToString.ToEntero = 0 Then + tCve = UM.AddUnidadMedida(Row("UM").ToString, Row("UM").ToString, "", "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1) + If tCve > 0 Then + Row("CveUM") = tCve + Dim rowsToUpdate = TmpDT.AsEnumerable().Where(Function(r) r.Field(Of String)("UM").ToString.ToUpper = Row("UM").ToString.ToUpper AndAlso r!CveUM.ToString.ToEntero = 0) + For Each roww As DataRow In rowsToUpdate + roww.SetField("CveUM", tCve) + Next + Else + Correcto = False + End If + End If + + 'REGISTRO LOS PRODUCTOS + If Row("CvePS").ToString.ToEntero = 0 Then + tCve = PSS.AddPS(Row("CveClasificacionActualizar").ToString.ToEntero, -1, Row("CveUM").ToString.ToEntero, "", "", "", Row("PS").ToString, Row("PU").ToString.ToDouble, If(TxtIVA.Text.ToDouble > 0, -1, 0), 0, False, 0, True, False, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, 0) + If tCve > 0 Then + RegeneraPS = True + Row("CvePS") = tCve + Row("CveClasificacion") = Row("CveClasificacionActualizar").ToString.ToEntero + 'Row("CveEq") = 1 + TmpDT.AcceptChanges() + + 'busco el mismo PS dentro de la tabla por si está más de una vez y lo actualizo + Dim rowsToUpdate = TmpDT.AsEnumerable().Where(Function(r) r.Field(Of String)("PS") = Row("PS").ToString AndAlso r!CvePS.ToString.ToEntero = 0) + For Each roww As DataRow In rowsToUpdate + roww.SetField("CvePS", tCve) + roww.SetField("CveClasificacion", Row("CveClasificacionActualizar").ToString.ToEntero) + 'roww.SetField("CveEq", 1) + Next + TmpDT.AcceptChanges() + Else + Correcto = False + End If + Else + 'UPDATE CLASIFICACION DE PRODUCTO YA REGISTRADO + If Row("CveClasificacionActualizar").ToString.ToEntero > 0 AndAlso Row("CveClasificacion").ToString.ToEntero <= 0 Then + If PSS.UpdateClasificacionPS(Row("CveClasificacionActualizar").ToString.ToEntero, UsuarioActual.CveUsuario, Row("CvePS").ToString.ToEntero) Then + Row("CveClasificacion") = Row("CveClasificacionActualizar").ToString.ToEntero + RegeneraPS = True + Else + Correcto = False + End If + End If + End If + Next + UM.Dispose() + PSS.Dispose() + + 'si hay necesidad de actualizar el globaldtps + If RegeneraPS Then + 'Dim Hilo As New System.Threading.Thread(AddressOf GeneraGlobalDT) + 'Hilo.Start() + GeneraGlobalDT(Nothing) + End If + + Dim CvePlantillaPrePoliza As Integer + If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + CvePlantillaPrePoliza = 60 + Else + CvePlantillaPrePoliza = 1 + End If + Dim tIdContaProveedor As Integer = CtaProveedor + Dim ImporteAnticipo As Decimal = 0 + + If (ArrAnticipos.Count > 0 And CveCompra > 0) Or (ArrAnticipos.Count > 0 And UsuarioActual.Empresa.UsaAC) Then '-- ESTO SE QUITO - IPP - 04 NOVIMEBRE 2016 + CvePlantillaPrePoliza = 52 + 'cuenta de anticipos + tIdContaProveedor = CtaProveedorAnticipos + For Each Ant As Compras_Compras.Anticipos In ArrAnticipos + ImporteAnticipo += Ant.Importe + Next + If Math.Round(ImporteAnticipo, 2) > TxtTotal.Text.ToDouble Then + Alert("El Importe seleccionado es mayor a la compra", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + End If + + If RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then + If EmpresaPrueba Then + If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + CvePlantillaPrePoliza = 60 + Else + CvePlantillaPrePoliza = 1 + End If + Else + CvePlantillaPrePoliza = 9 + End If + End If + + 'If RBLPago.SelectedValue.ToEntero = 4 And UsuarioActual.CveEmpresa.Contiene(1, 7) Then + ' CvePlantillaPrePoliza = 69 + 'End If + + TmpDT.AcceptChanges() + If Correcto Then + + 'VALIDA IMPORTES + If Not ValidaTotalesGuardar() Then + Exit Sub + End If + + + Dim ObjCompras As New ClsCompras() + Dim ObjConta As New ClsContabilidad(ObjCompras.IniciaTransacSQL()) + Dim ObjIE As New ClsBancos(ObjCompras.IniciaTransacSQL) + Dim ObjInventario As New ClsInventarios(ObjCompras.IniciaTransacSQL) + Dim ObjAF As New ClsAF(ObjCompras.IniciaTransacSQL) + Dim ObjOC As New ClsOC(ObjCompras.IniciaTransacSQL) + Dim ObjContratos As New ClsContratos(ObjCompras.IniciaTransacSQL()) + Dim ObjProveedores As New ClsCompProveedores(ObjCompras.IniciaTransacSQL()) + Dim ObjEventos As New ClsOIEventos(ObjCompras.IniciaTransacSQL()) + Dim ObjAcar As New ClsAcarreos(ObjCompras.IniciaTransacSQL()) + Dim ObjCGame As New ClsCGame(ObjCompras.IniciaTransacSQL()) + Dim ObjProductosServicios As New ClsProductosServicios(ObjCompras.IniciaTransacSQL()) + + + Dim ObjContaAC As ClsContPAQi = Nothing + + Dim ErrorMovtosCxP As Boolean = False + Dim ErrorPrepoliza As Boolean = False + Dim ErrorPrepolizaDescuadre As Boolean = False + Dim ErrorMovtosRetIVA As Boolean = False + Dim ErrorMovtosRetISR As Boolean = False + Dim ErrorMovtosEstimaciones As Boolean = False + Dim ErrorMovtosIVA As Boolean = False + Dim ErrorMovtosIE As Boolean = False + Dim ErrorMovInv As Boolean + Dim ErrorMovDev As Boolean = False + Dim ErrorOC = False + Dim TieneError As Boolean = False + Dim ErrorAC As Boolean = False + Dim ErrorAF As Boolean = False + Dim ErrorReembolso As Boolean = False + Dim ErrorBitacora = False + Dim ErrorAddAcarreos As Boolean = False + Dim ErrorCreditosCompra As Boolean = False + Dim ErrorOtrosGastos As Boolean = False + Dim ErrorSATPS As Boolean = False + Dim ErrorACMEnsaje As New StringBuilder + Dim ErrorSaldosInvComp As Boolean = False + + Dim CveIE As Integer = -1 + Dim CveEstatusFactura As Integer = 1 + Dim PolizaFolio As Integer = 0 + Dim CvePrePoliza As Integer + Dim ImporteCompra As Decimal = TxtTotal.Text.ToDecimal + Dim MultiplicadorNC = If(DdlTipoComprobante.SelectedValue = "NC", -1, 1) + Dim CveMovimientoInventario As Integer = -1 + Dim IVA = 1.16 + Dim ListaMovimientosAlmacen As New List(Of Integer) + + Dim ErrorCreditoCapitalIntres As Boolean = False + Dim ErrorCredito As Boolean = False + + If ChkProgramarPago.Checked Then + CveEstatusFactura = 2 + End If + Dim EntregaDirecta = False + + Dim ConceptoPoliza As String = String.Format("{0} - {1}{2} - {3}", NombreProveedor, TxtSerie.Text, TxtFolio.Text, TxtDescripcion.Text.Trim) + + 'TIPO CAMBIO MANUAL CON COMPRA NUEVA + Dim TipoCambioGuardar = 1.0 + If DdlMoneda.SelectedValue.ToEntero > 1 Then + TipoCambioGuardar = If(DivTC.Visible, TxtTC.Text.ToDouble, LblTC.Text.Substring(3).ToDouble) + End If + TipoCambio = If(DivTC.Visible, TipoCambioGuardar, TipoCambio) + + Try + Dim FolioFijo As Integer = 0 + 'cheque + If DdlTipoTransaccion.SelectedValue = "1" Then FolioFijo = TxtFolio.Text.ToEntero + + CvePrePoliza = ObjConta.AddPrePolizas("Compras/Registrar", If(EsContado And CvePlantillaPrePoliza = 1, 2, CvePlantillaPrePoliza), ImporteCompra, TxtTotal.Text.ToDouble, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, FolioFijo:=FolioFijo, ReglaFolioPoliza:=ObjCompras.ObtenerReglaFolio(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa), CveTipoPoliza:=ObjConta.ObtenerTipoPoliza(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa)) + + If CvePrePoliza > 0 Then + + 'seria de contado, solo cuando no tenga vinculado ningun anticipo + Dim ImportePago As Decimal = 0 + Dim TCPago As Decimal = GlobalTipoCambio(TxtFechaPago.Text.ToDate).ToString.ToDecimal + Dim CveMonedaPago As Integer = DdlMoneda.SelectedValue.ToEntero + + If RBLPago.SelectedValue.ToEntero = 2 Then 'Contado + + If RBLContado.SelectedValue = "1" Then + ImportePago = TxtDocumentoImporte.Text.Trim.ToDecimal + Dim Dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros($"CveCuenta = {DdlCuenta.SelectedValue}").Rows(0) + + If Dr IsNot Nothing Then + CveMonedaPago = Dr("CveMoneda").ToString.ToEntero + End If + + If CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 2 Then + ImportePago = (ImportePago * TCPago).RoundSQL + ElseIf CveMonedaPago = 2 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then + ImportePago = (ImportePago / TCPago).RoundSQL + ElseIf CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then + TCPago = 1 + End If + + 'se registra primero el movimiento en bancos para luego vincularlo en la compra + CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero, TxtFechaPago.Text.Trim.ToDate, TxtDocumentoFolio.Text.Trim, DdlProveedor.SelectedItem.Text.Trim, ImportePago, CveMonedaPago, TCPago, TxtDocumentoObservaciones.Text.Trim, "", True, True, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCuentaTarjeta:=If(DivTarjeta.Visible, DdlTarjeta.SelectedValue.ToEntero, -1)) + ElseIf RBLContado.SelectedValue = "6" Then + ImportePago = TxtDocumentoImporteCaja.Text.Trim.ToDecimal + Dim Dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros($"CveCuenta = {DdlCuentaCaja.SelectedValue}").Rows(0) + If Dr IsNot Nothing Then + CveMonedaPago = Dr("CveMoneda").ToString.ToEntero + End If + + If CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 2 Then + ImportePago = (ImportePago * TCPago).RoundSQL + ElseIf CveMonedaPago = 2 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then + ImportePago = (ImportePago / TCPago).RoundSQL + ElseIf CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then + TCPago = 1 + End If + + 'se registra primero el movimiento en bancos para luego vincularlo en la compra + CveIE = ObjIE.AddBancos_IE(DdlCuentaCaja.SelectedValue.ToEntero, DdlTipoTransaccionCaja.SelectedValue.ToEntero, TxtFechaPago.Text.Trim.ToDate, TxtDocumentoFolioCaja.Text.Trim, DdlProveedor.SelectedItem.Text.Trim, ImportePago, CveMonedaPago, TCPago, TxtDocumentoObservacionesCaja.Text.Trim, "", True, True, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + End If + + If (RBLContado.SelectedValue = "1" OrElse RBLContado.SelectedValue = "6") AndAlso Not CveIE > 0 Then + ErrorMovtosIE = True + End If + End If + + If Not ErrorMovtosIE Then + + 'REEMBOLSOS NO USA AC + Dim NumeroReembolso = "-1" + If TxtNumeroReembolso IsNot Nothing And RBLPago.SelectedValue = "3" Then + NumeroReembolso = TxtNumeroReembolso.Text + + ''GUARDA VALORES PARA SESSION + UsuarioActual.Sesion("Comp-NumeroReembolso") = TxtNumeroReembolso.Text + UsuarioActual.Sesion("Comp-CveFYE") = DdlPersonalReembolso.SelectedValue + UsuarioActual.Sesion("Comp-Descripcion") = TxtDescripcion.Text + + If NumeroReembolso <> "-1" Then + If CvePersonal <= 0 And CveCajaChica <= 0 Then + ErrorReembolso = True + End If + End If + Else + UsuarioActual.Sesion("Comp-NumeroReembolso") = "" + End If + + + If Not ErrorReembolso Then + + 'PORCENTAJE IVA + Dim PorcentajeIVA As Decimal = TmpDT.MAX("IVAPorcentaje").ToDecimal + + 'If DdlIVA.SelectedValue.ToDouble = 1.16 Then + ' PorcentajeIVA = 0.16 + 'ElseIf DdlIVA.SelectedValue.ToDouble = 1.08 Then + ' PorcentajeIVA = 0.08 + 'End If + + 'METODO DE PREPOLIZA DE ALMACEN + If UsuarioActual.CveEmpresa.Contiene(1, 119, 72, 80, 140, 141) And UsuarioActual.Empresa.UsaInventarios And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + Dim ImporteAlmacen = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0, "ImporteSinImpuestos", "Total"), $"ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveTipoPS = 2").ToString.ToDecimal + If ImporteAlmacen > 0 Then + If Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then + If (CveImportacion > 0 Or CveFlete > 0) Then + CveConceptoContableAlmacen = CveConceptoContableAlmacen + Else + CveConceptoContableAlmacen = 205 + End If + If OCVinculada And Not (CveImportacion > 0 Or CveFlete > 0) Then + CveConceptoContableAlmacen = DdlOCVinculaInv.SelectedValue.ToEntero + End If + If UsuarioActual.CveEmpresa.Contiene(72, 80, 140, 141) Then + CveConceptoContableAlmacen = 205 + End If Else - CveConceptoContableAlmacen = 225 - End If - - 'Condiciones para los casos de facturas que son en 0 pero que se utiliza el almacen - ElseIf OCVinculada AndAlso Not (CveImportacion > 0 Or CveFlete > 0) AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then - CveConceptoContableAlmacen = DdlOCVinculaInv.SelectedValue.ToEntero - ElseIf (CveImportacion > 0 Or CveFlete > 0) AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then - CveConceptoContableAlmacen = CveConceptoContableAlmacen - End If - End If - - - If RBLPago.SelectedValue.ToEntero = 4 And EstatusCredito.Contiene(1, 101) Then - CveEstatusFactura = 6 - End If - 'hay amortización directa como descuento. RMF Temporal + CveConceptoContableAlmacen = 225 + End If + + 'Condiciones para los casos de facturas que son en 0 pero que se utiliza el almacen + ElseIf OCVinculada AndAlso Not (CveImportacion > 0 Or CveFlete > 0) AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then + CveConceptoContableAlmacen = DdlOCVinculaInv.SelectedValue.ToEntero + ElseIf (CveImportacion > 0 Or CveFlete > 0) AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then + CveConceptoContableAlmacen = CveConceptoContableAlmacen + End If + End If + + + If RBLPago.SelectedValue.ToEntero = 4 And EstatusCredito.Contiene(1, 101) Then + CveEstatusFactura = 6 + End If + 'hay amortización directa como descuento. RMF Temporal If UsuarioActual.CveEmpresa = 119 Then 'If LblAmortizacion.Text.ToDouble > 0 AndAlso TxtDescuento.Text.ToDouble = 0 Then ' TxtDescuento.Text = LblAmortizacion.Text @@ -4445,1450 +4446,1487 @@ Partial Class Compras_Compras ' LblAmortizacion.Text = "0.00" 'End If - End If - - 'Compra - If ObjCompras.AddCompra(DdlTipoComprobante.SelectedValue, TxtDescripcion.Text.Trim, TxtSerie.Text.Trim, TxtFolio.Text.Trim, TxtFolioSecundario.Text.Trim, CveProveedor, TxtSubTotal.Text.ToDouble, TxtDescuento.Text.ToDouble, - LblAmortizacion.Text.ToDouble, TxtIVA.Text.ToDouble, TxtRetIVA.Text.ToDouble, TxtRetISR.Text.ToDouble, TxtIEPS.Text.ToDouble, TxtOtrosImpuestos.Text.ToDouble, - TxtRedondeo.Text.ToDouble, TxtTotal.Text.ToDouble, TxtFecha.Text.Trim.ToDate, DdlMoneda.SelectedValue.ToEntero, TipoCambio, TxtFechaPago.Text.Trim.ToDate, ChkAplicaNotaCredito.Checked, TxtObsFact.Text.Trim, CveEstatusFactura, - CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, IdPoliza, CveCajaChica:=CveCajaChica, CvePersonal:=CvePersonal, NumeroReembolso:=NumeroReembolso, CveProveedorSucursal:=DdlProveedorSucursal.SelectedValue.ToEntero, - AplicoPromocion:=ChkOCPromocion.Checked, PorcentajeIVA:=PorcentajeIVA, CveMetodoPago:=CveMetodoPago, CveRetIVAConcepto:=If(DdlRetIVAConcepto.Items.Count > 0, DdlRetIVAConcepto.SelectedValue.ToEntero, -1), CveConceptoContableAlmacen:=CveConceptoContableAlmacen, - CveRetISRConcepto:=If(DdlRetISRConcepto.Items.Count > 0, DdlRetISRConcepto.SelectedValue.ToEntero, -1), NoDeducible:=EsNoDeducible, CveTipoCompra:=DdlTipoCompra.SelectedValue.ToEntero, TotalOriginal:=TotalOriginal, CveTipoConcepto:=CveTipoConcepto) Then - - ViewState("CveCompra") = ObjCompras.CveCompra - If ObjCompras.DtResultados.Rows.Count > 0 Then ViewState("CompraFolio") = ObjCompras.DtResultados.Rows(0)("vFolio").ToString - If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - ErrorMovDev = guardardevolucion(ObjInventario, ObjCompras.CveCompra, TxtSubTotal.Text.ToDouble, TxtFecha.Text.Trim.ToDate) - End If - Dim ErrorDetalles As Boolean = False - ' Dim IDPoliza As Integer - Dim IDPolizaComprometido = 0 - Dim ErrorComprometido = False - - If CveImportacion > 0 Or CveFlete > 0 Then - - - Select Case CveConceptoContableAlmacen - Case 237 - Select Case FleteImportacionOpcion - Case 1 - Dim Dr As DataRow = Nothing - If ObjInventario.GetFletes(UsuarioActual.CveEmpresa, CveFlete) Then - If ObjInventario.DtResultados.Rows.Count > 0 Then - Dr = ObjInventario.DtResultados.Rows(0) - End If - End If - If Dr IsNot Nothing Then - If Not ObjInventario.UpdateFlete(CveFlete, Dr("Descripcion").ToString, Dr("Fecha").ToString.ToDate, -1, CveCompra, UsuarioActual.CveUsuario) Then - ErrorOC = True - End If - Else - ErrorOC = True - End If - Case 2 - If Not ObjInventario.AddFleteDetalle(CveFlete, CveCompra) Then - ErrorOC = True - End If - 'actualiza la compra para que no se surta en almacen. sino por el flete o importación - If Not ObjCompras.UpdateEstatusAlmacen(CveCompra, 2) Then - ErrorOC = True - End If - End Select - Case 240 - Select Case FleteImportacionOpcion - Case 1 - If Not ObjCompras.AddImportacionCompra(CveImportacion, CveCompra) Then - ErrorOC = True - End If - Case 2 - If Not ObjCompras.AddImportacionDetalle(CveImportacion, CveCompra) Then - ErrorOC = True - End If - 'actualiza la compra para que no se surta en almacen. sino por el flete o importación - If Not ObjCompras.UpdateEstatusAlmacen(CveCompra, 2) Then - ErrorOC = True - End If - End Select - End Select - End If - - - If UsuarioActual.Empresa.UsaAC Then - - If TotalPorDevengar <= TxtTotal.Text.ToDouble And TotalPorDevengar > 0 Then - ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) - ObjContaAC.IniciaTransacSQL() - - ''POLIZA COMPROMETIDO SOLO SI NO SE VINCULA OC - If HdnVCveOC.Value.ToEntero > 0 Then - ' IDPolizaComprometido = ObjContaAC.AddPoliza( 4, "Comprometido", Total, Total, UsuarioActual.CveUsuario, Now) - ' If IDPolizaComprometido <= 0 Then - ' ErrorComprometido = True - ' End If - IDPolizaComprometido = 1 - TotalPorDevengar = TotalPorDevengar * 2 - Else - TotalPorDevengar = TotalPorDevengar * 3 - End If - - IdPoliza = ObjContaAC.AddPoliza(3, TxtDescripcion.Text.Trim, TotalPorDevengar, TotalPorDevengar, UsuarioActual.CveUsuario, TxtFecha.Text.ToDate) - - 'Dim filtro As New StringBuilder - If IdPoliza > 0 Then - PolizaFolio = ObjContaAC.Folio - 'Dim RegistroMatriz As DataRow - 'Dim CuentaCargo As Integer - Dim CuentaAbono As Integer - Dim Importe As Decimal - - 'CUENTA PROVEEDOR - If tIdContaProveedor <= 0 Then - 'normalmente debe de ser la cuenta 021120000000000000, para el caso de APH, se el cmabio al 2119 - If ObjContaAC.GetCuentas(-1, "021190000000000000", -1) Then - Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") - If drCuenta IsNot Nothing Then - - CuentaAbono = drCuenta("Id").ToString.ToEntero - Dim FolioProveedor = ObjContaAC.GetFolioProveedores("021190000000000000").ToString - ViewState("CtaProveedor") = ObjContaAC.AddCuenta(String.Format("02119{0}000000000", FolioProveedor.PadLeft(4, "0"c)), NombreProveedor, "D", 2, 0, 1, 0, "", 1, CuentaAbono) - ObjProveedores.UpdateProveedorIdCuentaAC(CveProveedor, CtaProveedor) - tIdContaProveedor = CtaProveedor - - Else - ErrorAC = True - ErrorACMEnsaje.Append(" - DrCuenta Nula") - End If - Else - ErrorACMEnsaje.Append(" - Error al consultar cuenta 021190000000000000 ") - ErrorAC = True - End If - End If - - Dim ConceptoRenglon As String = "" - If Not ErrorAC Then - - - 'INVENTARIOS EN AC - Dim ContadorInventario As Integer = GvInv.Rows.Cast(Of GridViewRow)().Count(Function(gvr) gvr.FCCheckBox("cbInv").Checked) - Dim CtaAlmacen As Integer - If ContadorInventario > 0 Then - Dim drr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero)) - If drr IsNot Nothing Then - CtaAlmacen = drr("IdCtaContable").ToString.ToEntero - End If - End If - - Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA, tRetIVA, tRetISR As Decimal - Dim ipresup As Integer = 0 - 'COMIENZA: PRUEBA AGRUPACION CONCEPTOS - Dim Presup = From gvr As DataRow In TmpDT.Rows.Cast(Of DataRow)() - Group gvr By Grp = New With { - Key .CvePresupuestoEgreso = gvr("CvePresupuestoEgreso").ToString.ToEntero, - Key .CveOrdencompraDetalle = If(gvr("CveOrdencompraDetalle").ToString.ToEntero > 0, 1, -1), - Key .CveActivoFijo = If(gvr("TipoAF").ToString.ToEntero = 2, gvr("CveActivoFijo").ToString.ToEntero, -1) - } Into Group - Select Grp.CvePresupuestoEgreso, Grp.CveActivoFijo, Grp.CveOrdencompraDetalle, - TotalImporte = Group.Sum(Function(r) r("Total").ToString.ToDecimal) - Dim Fecha As Date = TxtFecha.Text.ToDate - - 'Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA As Double - tTotalIVA = TxtIVA.Text.ToDecimal - tRetIVA = TxtRetIVA.Text.ToDecimal - tRetISR = TxtRetISR.Text.ToDecimal - - 'tTotalIVA = tTotalIVA - tRetIVA - tRetISR - - tTotalGral = TxtTotal.Text.ToDecimal + tRetIVA + tRetISR ' EL TOTAL GENERAL DEBE DE SER EL SUBTOTAL + IVA, NO SE DEBEN DE INCLUIR LAS RETENCIONES, POR ESO SE RESTA - tDiferenciaIVA = tTotalIVA - - ipresup = 0 - - Dim CuentaMatrizAlmacen As Integer - - 'PresupuestoEgresos - Dim DtPresupuestosTemp As DataTable - Dim IdCuentaComprometido, IdCuentaPorEjercer, IdCuentaDevengado, IdCuentaMatriz As Integer - ' Dim DescuentoConIVA As Decimal - Dim tPorIVA As Decimal = tTotalIVA / (tTotalGral - tTotalIVA) - Dim tAjusteTotal As Decimal - - For Each grp In Presup - Importe = grp.TotalImporte - TotalDetalle += Importe - ipresup += 1 - If Importe > 0 Then - 'saco la proporcion de iva que le corresponde - tIVA = Math.Round(Importe * tPorIVA, 2) - tDiferenciaIVA -= tIVA - 'identifico si es el ultimo registro, para ver si es necesario un ajuste - If ipresup = Presup.Count Then - If Math.Round(TotalDetalle - tTotalGral, 2) <= 0.01 AndAlso tDiferenciaIVA > 0 Then - tIVA += tDiferenciaIVA - End If - End If - - 'le sumo el iva al concepto - Importe += tIVA - - 'codigo Provisional, para cuand tenga descuento, solo tome el subtotal * el iva,RMF - If TxtDescuento.Text.ToDouble > 0 Then - Importe = grp.TotalImporte * 1.16D - End If - - tAjusteTotal += Importe - 'valido que la sumas de lo detalles no exceda al totalgeneral - If Math.Round(tAjusteTotal, 2) > tTotalGral Then - 'le resto la diferencia - Importe -= (tAjusteTotal - tTotalGral) - End If - - 'Presupuesto Egresos - DtPresupuestosTemp = DtPresupuestos.FiltraParametros(String.Format("CvePresupuestoEgreso = {0}", grp.CvePresupuestoEgreso)) - If DtPresupuestosTemp.Rows.Count <> 1 Then - ErrorAC = True - ErrorACMEnsaje.Append(" - DtPresupuestosTemp.Rows.Count <> 1 ") - Exit For - End If - IdCuentaComprometido = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString.ToEntero - IdCuentaPorEjercer = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero - IdCuentaDevengado = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString.ToEntero - IdCuentaMatriz = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString.ToEntero - - 'COMPROMETIDO DEPENDIENTE SI EXISTE SU POLIZA - If grp.CveOrdencompraDetalle = -1 Then - ConceptoRenglon = String.Format("GC Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaPorEjercer, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - ErrorACMEnsaje.Append(" - Error al agregar movimiento contabilidad 1") - Exit For - End If - Else - ErrorACMEnsaje.Append(" - Error al agregar movimiento contabilidad 2") - ErrorAC = True - Exit For - End If - End If - - ConceptoRenglon = String.Format("GD Fact:{0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - 'DEVENGADO - If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaDevengado, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorACMEnsaje.Append(" - Error al agregar movimiento contabilidad 3") - ErrorAC = True - Exit For - End If - Else - ErrorACMEnsaje.Append(" - Error al agregar movimiento contabilidad 4") - ErrorAC = True - Exit For - End If - - If ContadorInventario > 0 Then - CuentaMatrizAlmacen = CtaAlmacen - ElseIf grp.CveActivoFijo > 0 Then - - Dim CtaAF = -1 - Dim AF = "" - Dim CuentaInicial = -1 - - If ObjAF.GetActivosFijos(grp.CveActivoFijo, UsuarioActual.CveEmpresa, "-1", "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "", -1, UsuarioActual.CveEmpresa) Then - CtaAF = ObjAF.Cuenta - AF = ObjAF.Descripcion - CuentaInicial = ObjAF.CuentaInicial - Else - ErrorAC = True - ErrorACMEnsaje.Append(" - Error al obtener activos fijos ") - Exit For - End If - - If Not CuentaInicial > 0 Then - CuentaInicial = 1241 - End If - - 'CUENTA AF - If CtaAF <= 0 Then - If ObjContaAC.GetCuentas(-1, String.Format("0{0}0000000000000", CuentaInicial), -1) Then - Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") - If drCuenta IsNot Nothing Then - ErrorACMEnsaje.Append(" - Error al obtener cuentas 0{0}0000000000000 drCuenta nula") - CuentaAbono = drCuenta("Id").ToString.ToEntero - Dim FolioAF = ObjContaAC.GetFolioProveedores(String.Format("0{0}0000000000000", CuentaInicial)).ToString - CtaAF = ObjContaAC.AddCuenta(String.Format("0{0}{1}000000000", CuentaInicial, FolioAF.PadLeft(4, "0"c)), AF, "A", 2, 0, 1, 0, "", 1, CuentaAbono) - - ObjAF.UpdateActivosFijosCuentaAC(grp.CveActivoFijo, CtaAF, UsuarioActual.CveUsuario) - Else - ErrorACMEnsaje.Append(" - Error al obtener cuentas 0{0}0000000000000 drCuenta nulo") - ErrorAC = True - End If - Else - ErrorACMEnsaje.Append(" - Error al obtener cuentas 0{0}0000000000000") - ErrorAC = True - End If - End If - - CuentaMatrizAlmacen = CtaAF - Else - CuentaMatrizAlmacen = IdCuentaMatriz - End If - - - ''AFECTAR MATRIZ EGRESOS - If ObjContaAC.AddMovimiento(IdPoliza, CuentaMatrizAlmacen, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - - - ''VERIFICA SI TIENE DESCUENTO (AMORTIZACION) - 'If TxtDescuento.Text.ToDouble > 0 Then - ' DescuentoConIVA = TxtDescuento.Text.ToDouble * 1.16 - - ' 'Valida que el descuento con iva cuadre en los totales - ' If Math.Abs(DescuentoConIVA - (Importe - TxtTotal.Text.ToDouble)) < 0.02 Then - ' DescuentoConIVA = Importe - TxtTotal.Text.ToDouble - ' ElseIf DescuentoConIVA <> (Importe - TxtTotal.Text.ToDouble) Then - ' ErrorAC = True - ' Exit For - ' End If - - ' 'actualizo el idcuenta del presupuesto - ' If ObjContaAC.AddMovimiento(123456, IdPoliza, tIdContaProveedor, True, Importe - DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then - ' 'agrego a la cuenta contable anticipos - ' If Not ObjContaAC.AddMovimiento(123456, IdPoliza, CtaProveedorAnticipos, True, DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then - ' ErrorAC = True - ' Exit For - ' End If - ' Else - ' ErrorAC = True - ' Exit For - ' End If - - 'Else - ' 'actualizo el idcuenta del presupuesto - ' Importe = TxtTotal.Text.ToDouble - ' If Not ObjContaAC.AddMovimiento(123456, IdPoliza, tIdContaProveedor, True, If(ArrAnticipos.Count > 0, ImporteAnticipo, Importe), "", ConceptoRenglon, 0, Fecha, "") Then - ' ErrorAC = True - ' Exit For - ' End If - - 'End If - - - Else - ErrorACMEnsaje.Append(" - Error AFECTAR MATRIZ EGRESOS ObjContaAC.AddMovimiento") - ErrorAC = True - Exit For - End If - ''TERMINA AFECTAR MATRIZ EGRESOS - - Else - ErrorACMEnsaje.Append(" - For Each grp In Presup Importe > 0 ") - ErrorAC = True - Exit For - End If - - Next - - ''[IPP] COMENTADO A MIRAS DE ELIMINAR 21-FEBRERO-2018 - ''VERIFICA SI TIENE DESCUENTO (AMORTIZACION) - 'If TxtDescuento.Text.ToDouble > 0 Then - ' DescuentoConIVA = TxtDescuento.Text.ToDecimal * 1.16D - - ' 'Valida que el descuento con iva cuadre en los totales - ' If Math.Abs(DescuentoConIVA - (Importe - TxtTotal.Text.ToDecimal)) < 0.02 Then - ' DescuentoConIVA = Importe - TxtTotal.Text.ToDecimal - ' ElseIf DescuentoConIVA <> (Importe - TxtTotal.Text.ToDecimal) Then - ' ErrorACMEnsaje.Append(" - Valida que el descuento con iva cuadre en los totales ") - ' ErrorAC = True - ' End If - - ' 'actualizo el idcuenta del presupuesto - ' If ObjContaAC.AddMovimiento(IdPoliza, tIdContaProveedor, True, MultiplicadorNC * (Importe - DescuentoConIVA), "", ConceptoRenglon, 0, Fecha, "") Then - ' 'agrego a la cuenta contable anticipos - ' If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorAnticipos, True, MultiplicadorNC * DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then - ' ErrorACMEnsaje.Append(" - actualizo el idcuenta del presupuesto ObjContaAC.AddMovimiento 1") - ' ErrorAC = True - ' End If - ' Else - ' ErrorACMEnsaje.Append(" - actualizo el idcuenta del presupuesto ObjContaAC.AddMovimiento 2") - ' ErrorAC = True - ' End If - 'Else - 'actualizo el idcuenta del presupuesto - Importe = TxtTotal.Text.ToDecimal - If Not ObjContaAC.AddMovimiento(IdPoliza, tIdContaProveedor, True, MultiplicadorNC * (If(ArrAnticipos.Count > 0, ImporteAnticipo, Importe)), "", ConceptoRenglon, 0, Fecha, "") Then - ErrorACMEnsaje.Append(" - actualizo el idcuenta del presupuesto ObjContaAC.AddMovimiento 3") - ErrorAC = True - End If - 'End If - - - If tRetISR > 0 Then - ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorRetISR, True, MultiplicadorNC * tRetISR, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorACMEnsaje.Append(" RetISR > 0 ObjContaAC.AddMovimiento") - ErrorAC = True - End If - End If - - 'TERMINA: PRUEBA AGRUPACION CONCEPTOS - - 'registrar amortizar anticipos - End If - - Else - ErrorACMEnsaje.Append(" - Id Poliza = 0 ") - ErrorAC = True - End If - Else - TieneError = True - ErrorACMEnsaje.Append("- TotalPorDevengar <= TxtTotal.Text.ToDouble And TotalPorDevengar > 0") - ErrorAC = True - End If - End If - - If Not ErrorAC Then - - - Dim AutoConta As Boolean = UsuarioActual.Empresa.Funcionalidad(200) = "1" - - If UsuarioActual.CveEmpresa = 119 AndAlso (DdlPersonalReembolso.SelectedValue.ToEntero > 0 Or DdlCuentaCajaChicaReembolso.SelectedValue.ToEntero > 0) Then - AutoConta = False - End If - - If (AutoConta Or UsuarioActual.Empresa.UsaAC) And ObjContaAC Is Nothing Then - ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) - ObjContaAC.IniciaTransacSQL() - End If - - ''EMPIEZA: INSERTA DETALLES DE LA COMPRA - Dim indiceTR = 0 - Dim Cont As Integer = 0 - For Each Row As DataRow In TmpDT.Rows - Dim TipoRecepcion As Integer = -1 - - - ''INVENTARIOS - If GvInv.Rows.Count > indiceTR Then - If GvInv.Rows(indiceTR).FCCheckBox("cbInv").Checked = True And GvInv.Rows(indiceTR).FCDropDownList("DdlRecibirInv").SelectedValue = "1" Then - TipoRecepcion = 1 - ElseIf GvInv.Rows(indiceTR).FCCheckBox("cbInv").Checked = True And GvInv.Rows(indiceTR).FCDropDownList("DdlRecibirInv").SelectedValue = "0" Then - TipoRecepcion = 2 - End If - End If - - Dim CvePersonal = -1 - Dim Referencia = "" - - If GvPersonal.Rows.Count > Cont Then - CvePersonal = GvPersonal.Rows(Cont).FCDropDownList("DdlPersonalGv").SelectedValue.ToEntero - Referencia = GvPersonal.Rows(Cont).FCTextBox("TxtReferencia").Text - End If - Cont = Cont + 1 - - 'Si es AF-INSUMO se guarda CveAF en CompraDetalle - Dim CveAF = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 1, Row("CveActivoFijo").ToString.ToEntero, -1) - - 'Si es AF-COMPRA se guarda CveAF en la Columna CveAFCompra - Dim CveAFC = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 2, Row("CveActivoFijo").ToString.ToEntero, -1) - - 'AGREGA COMPRA DETALLE - If Not ObjCompras.AddCompraDetalle(CveCompra, Row("CveUM").ToString.ToEntero, Row("CvePS").ToString.ToEntero, Row("CveSubProyecto").ToString.ToEntero, -1, CveAF, - Row("Cantidad").ToString.ToDouble, Row("PU").ToString.ToDouble, Row("IVA").ToString.ToDouble, Row("Total").ToString.ToDouble, Row("Descuento").ToString.ToDouble, - Row("Obs").ToString, Row("CveOrdenCompraDetalle").ToString.ToEntero, TipoRecepcion, Row("CveContrato").ToString.ToEntero, Row("CvePresupuestoEgreso").ToString.ToEntero, - AplicaCostoIndirecto:=Row("AplicaCostoIndirecto").ToString.ToEntero, EstatusAlmacen:=Row("EntregaDirecta").ToString.ToEntero, CvePersonal:=CvePersonal, - CveTipoGasto:=Row("CveTipoGasto").ToString.ToEntero, AF_Medida:=Row("AFMedida").ToString.ToEntero, AF_TipoMantenimiento:=Row("AFTipoMantenimiento").ToString.ToEntero, Referencia:=Referencia, OtrosGastos:=Row("OtrosGastos").ToString.ToDecimal, - RetIVA:=Row("RetIVA").ToString.ToDouble, RetISR:=Row("RetISR").ToString.ToDouble, IEPSPS:=Row("IEPSPS").ToString.ToDouble, IEPSPSIVA:=Row("IEPSPSIVA").ToString.ToDouble, - IVAPorcentaje:=Row("IVAPorcentaje").ToString.ToDouble, RetIVAPorcentaje:=Row("RetIVAPorcentaje").ToString.ToDouble, RetISRPorcentaje:=Row("RetISRPorcentaje").ToString.ToDouble, - IEPSPSPorcentaje:=Row("IEPSPSPorcentaje").ToString.ToDouble, IEPSPSIVAPorcentaje:=Row("IEPSPSIVAPorcentaje").ToString.ToDouble, NoDeducible:=If((Row("NoDeducible").ToString().ToUpper().Contiene("TRUE", "1")) AndAlso EsNoDeducible, True, False)) Then - - ErrorDetalles = True - Exit For - Else - - If Row("EntregaDirecta").ToString.ToEntero > 0 Then - EntregaDirecta = True - End If - - Dim TmpDr As DataRow = TmpDT.Select($"Consec = {Row("Consec").ToString}")(0) - TmpDr("CveCompraDetalle") = ObjCompras.CveCompraDetalle - - ' Si no es un movimiento de almacen va a tronar - Try - Dim InvDr As DataRow = DtInv.Select($"Consec = {Row("Consec").ToString}")(0) - InvDr("CveCompraDetalle") = ObjCompras.CveCompraDetalle - Catch ex As Exception - End Try - - End If - - 'Vincula Vales - If IdVale.Count > 0 Then - For Each cve In IdVale - If Not ObjAF.UpdateValeCombustible(cve, CveCompra, -1, "", -1, -1, -1, UsuarioActual.CveEmpresa) Then - ErrorAF = True - Exit For - End If - Next - Else - - End If - - - - 'AGREGA AF COMPRA - Cuando es Compra se guarda CveCompraDetalle en AF - If Row("TipoAF").ToString.ToEntero = 2 Then - If Not ObjAF.UpdateActivosFijosCompra(Row("CveActivoFijo").ToString.ToEntero, ObjCompras.CveCompraDetalle, Row("TipoAF").ToString.ToEntero, Row("Total").ToString.ToDouble, TxtFecha.Text.Trim.ToDate) Then - ErrorDetalles = True - Exit For - End If - End If - - 'ACTUALIZAR PRODUCTO/SERVICIO SAT - If Version = "3.3" Then - If Not ObjProductosServicios.UpdateProductosServiciosSAT(Row("CvePS").ToString().ToEntero(), Row("CveSATPS").ToString().ToEntero(), UsuarioActual.CveUsuario) Then - ErrorSATPS = True - End If - End If - - indiceTR += 1 - Next - ''TERMINA: INSERTA DETALLES DE LA COMPRA - - 'QUEMA SALDOS DE INV-COMPRA | MERCANCIA RECIBIDA POR ADELANTADO (OC) | PP 176 - If OCVinculada And Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - For Each Row As DataRow In TmpDT.FiltraParametros("CveTipoPS = 2").Rows - If Not ObjOC.OrdenesCompraDetalleSaldosInvCompraAdd(Row("CveOrdenCompraDetalle").ToString.ToEntero, -1, -1, Row("CveCompraDetalle").ToString.ToEntero, Row("Cantidad").ToString.ToDouble) Then - ErrorSaldosInvComp = True - Exit For - End If - Next - - 'verifica si fue vinculada con una OC, y si fue la opción de entrega por adelantado, que si hubo cambios de precios - If DdlOCVinculaInv.SelectedValue.ToEntero.Contiene(176, 205) Then - If Not AjustarPrePolizaVinculacionOC(ObjOC, ObjEventos, ObjInventario, ObjConta, ObjContaAC) Then - ErrorPrepoliza = True - End If - End If - - End If - - If CvePrePoliza > 0 Then - - 'INVENTARIOS - ALMACEN - If UsuarioActual.Empresa.UsaInventarios Then 'And UsuarioActual.Empresa.UsaAC = False - - ''SI ES CON DOLARES VALIDA QUE SE TENGA EL TIPO DE CAMBIO DEL DIA DE LA FACTURA - SI NO, NO HACE NADA, la validación del TC, ya está chk constrains - ' If DdlMoneda.SelectedValue.ToEntero = 1 Or (DdlMoneda.SelectedValue.ToEntero > 1 AndAlso GlobalTipoCambio(TxtFecha.Text.ToDate) > 0) Then - - ''ALMACEN CONSIGNACION - If CveConsignacion > 0 Then - - 'actualizamos cvecompraconsignacion - For Each gvr As GridViewRow In GvInv.Rows - If gvr.FCCheckBox("cbinv").Checked AndAlso gvr.FCHiddenField("HdnCveConsignacion").Value.ToEntero > 0 Then - If Not ObjInventario.UpdateConsignacionesCompra(CveCompra, gvr.FCHiddenField("HdnCveConsignacion").Value.ToEntero, gvr.FCHiddenField("HdnCveAlmacen").Value.ToEntero, gvr.FCHiddenField("HdnCvePS").Value.ToEntero, gvr.DataKey("Cantidad").ToDouble, UsuarioActual.CveEmpresa) Then - ErrorMovInv = True - Exit For - End If - End If - Next - - If Not ErrorMovInv Then - - Dim x As Integer = 0 - For Each dr As DataRow In DtInv.Rows - If GvInv.Rows(x).FCCheckBox("cbInv").Checked And GvInv.Rows(x).FCTextBox("TbCantidad").Text.ToDouble > 0 Then - - Dim TmpDr As DataRow = TmpDT.Select($"Consec = {dr("Consec").ToString.ToEntero}")(0) 'Charlie - TmpDr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlEAlmacen").SelectedValue.ToEntero 'Charlie - - dr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlealmacen").SelectedValue.ToEntero - dr("Cantidad") = GvInv.Rows(x).FCTextBox("TbCantidad").Text.ToDouble - Else - Dim TmpDr As DataRow = TmpDT.Select($"Consec = {dr("Consec").ToString.ToEntero}")(0) 'Charlie - TmpDr("CveAlmacen") = 0 'Charlie - - dr("CveAlmacen") = 0 - End If - x = x + 1 - Next - - Dim cvemovimientosalida = 0 - Dim cvemovimientoentrada = 0 - Dim cvemovimientosalidagasto = 0 - Dim folio = 0 - Dim fecha As Date = TxtFecha.Text.ToDate - Dim indice = 0 - Dim importeconcepto = 0.0 - - Dim listalmacenes = (From cvealmacen In DtInv.AsEnumerable() Where cvealmacen.Field(Of Integer)("cvealmacen") > 0 Select cvealmacen.Field(Of Integer)("cvealmacen")).Distinct().ToList - - For Each tcvealmacen As Integer In listalmacenes - If GvInv.Rows(indice).FCDropDownList("ddlrecibirinv").SelectedValue = "1" Then - Continue For - End If - indice += 1 - - - ''agregamos la salida de consignacion - 'folio = objinventario.getfoliosiguiente(3, usuarioactual.cveempresa) - 'cvemovimientosalida = objinventario.addmovimiento(cvealmacenconsignacion, 3, ddlmoneda.selectedvalue.toentero, fecha, folio, usuarioactual.cveusuario, usuarioactual.cveempresa, cvecompra, -1, -1, -1) - 'if cvemovimientosalida <= 0 then - ' errormovinv = true - ' exit for - 'else - ' for each dr as datarow in dtinv.rows - ' if dr("cvealmacen").tostring.toentero = tcvealmacen then - ' if not objinventario.addmovimientodetalle(cvemovimientosalida, dr("cantidad").tostring.todouble, ddlum.selectedvalue.toentero, dr("cveps").tostring.toentero, 0, -1) then - ' errormovinv = true - ' exit for - - ' end if - ' end if - ' next - 'end if - - - 'agregamos la entrada - If Not UsuarioActual.Empresa.UsaAC Then fecha = Now - - folio = ObjInventario.GetFolioSiguiente(2, UsuarioActual.CveEmpresa) - cvemovimientoentrada = ObjInventario.AddMovimiento(tcvealmacen, 2, 1, fecha, folio, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, TipoCambio:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, TipoCambioGuardar), Modulo:="Comp/G") - If cvemovimientoentrada <= 0 Then - ErrorMovInv = True - Exit For - Else - CveMovimientoInventario = cvemovimientoentrada - ListaMovimientosAlmacen.Add(CveMovimientoInventario) - - For Each dr As DataRow In DtInv.Rows - If dr("cvealmacen").ToString.ToEntero = tcvealmacen Then - - importeconcepto = If(DdlMoneda.SelectedValue.ToEntero = 1, dr("pu").ToString.ToDouble, dr("pu").ToString.ToDouble * TipoCambioGuardar) - If Not ObjInventario.AddMovimientoDetalle(cvemovimientoentrada, dr("cantidad").ToString.ToDouble, dr("cveum").ToString.ToEntero, dr("cveps").ToString.ToEntero, importeconcepto, -1, PUTC:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, dr("pu").ToString.ToDouble), CveCompraDetalle:=dr("CveCompraDetalle").ToString.ToEntero) Then - - ErrorMovInv = True - Exit For - End If - End If - Next - - End If - - 'agregamos la salida gasto - folio = ObjInventario.GetFolioSiguiente(3, UsuarioActual.CveEmpresa) - cvemovimientosalidagasto = ObjInventario.AddMovimiento(tcvealmacen, 3, DdlMoneda.SelectedValue.ToEntero, fecha.AddSeconds(1), folio, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, Modulo:="Comp/G") - If cvemovimientosalidagasto <= 0 Then - ErrorMovInv = True - Exit For - Else - If ObjInventario.GetMovimientosDetalle(cvemovimientoentrada, UsuarioActual.CveEmpresa) Then - For Each dr As DataRow In ObjInventario.DtResultados.Rows - If Not ObjInventario.AddMovimientoDetalle(cvemovimientosalidagasto, dr("cantidad").ToString.ToDouble, dr("cveum").ToString.ToEntero, dr("cveps").ToString.ToEntero, 0, dr("cveaf").ToString.ToEntero, CveCompraDetalle:=dr("CveCompraDetalle").ToString.ToEntero) Then - ErrorMovInv = True - Exit For - End If - Next - End If - End If - - Next - - End If - - ''ALMACEN NORMAL - Else - - 'OBTIENE ALMACENES - Dim x As Integer = 0 - For Each Dr As DataRow In DtInv.Rows - If GvInv.Rows(x).FCCheckBox("cbInv").Checked And GvInv.Rows(x).FCTextBox("TbCantidad").Text.ToDecimal > 0 Then - - Dim TmpDr As DataRow = TmpDT.Select($"Consec = {Dr("Consec").ToString.ToEntero}")(0) - TmpDr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlEAlmacen").SelectedValue.ToEntero - - Dr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlEAlmacen").SelectedValue.ToEntero - Dr("Cantidad") = GvInv.Rows(x).FCTextBox("TbCantidad").Text.ToDouble - - Else 'limpio el valor para que no truene en linq mas abajo - - Dim TmpDr As DataRow = TmpDT.Select($"Consec = {Dr("Consec").ToString.ToEntero}")(0) - TmpDr("CveAlmacen") = 0 - - Dr("CveAlmacen") = 0 - End If - x = x + 1 - Next - - Dim i As Integer = 0 - Dim ListAlmacenes = (From CveAlmacen In DtInv.AsEnumerable() Where CveAlmacen.Field(Of Integer)("CveAlmacen") > 0 Select CveAlmacen.Field(Of Integer)("CveAlmacen")).Distinct().ToList - Dim indice = 0 - Dim ImporteConcepto = 0.0 - - For Each tCveAlmacen As Integer In ListAlmacenes - If GvInv.Rows(indice).FCDropDownList("DdlRecibirInv").SelectedValue = "1" Then - Continue For - End If - indice += 1 - - Dim fecha As Date = TxtFecha.Text.ToDate - If Not UsuarioActual.Empresa.UsaAC Then fecha = Now - - CveMovimientoInventario = ObjInventario.AddMovimiento(tCveAlmacen, 2, 1, fecha, 0, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, TipoCambio:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, TipoCambioGuardar), Modulo:="Comp/G") - - If CveMovimientoInventario <= 0 Then - ErrorMovInv = True - Else - - Dim DtDetalle As New DataTable - Dim DtEquivalencias As DataTable - Dim CveProducto As Integer - Dim CantidadInv As Double - Dim PUInv As Double - Dim CveUnidad As Integer - Dim CostoIndirecto As Double - - ListaMovimientosAlmacen.Add(CveMovimientoInventario) - - - For Each Dr As DataRow In DtInv.Rows - - CveProducto = Dr("CvePS").ToString.ToEntero - CveUnidad = Dr("CveUM").ToString.ToEntero - CantidadInv = Dr("Cantidad").ToString.ToDouble - PUInv = Dr("PU").ToString.ToDouble - CostoIndirecto = Dr("CostoIndirectoAlmacen").ToString.ToDouble - - If Dr("CveMetodoInventario").ToString.ToEntero = 5 Then - 'SI FUE POR SERIE LOTE - DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", Dr("CvePS"))) - If DtDetalle.Rows.Count > 0 Then - For Each drr As DataRow In DtDetalle.Rows - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoInventario, 1, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDouble, -1, SerieLote:=drr("Serie").ToString, FechaCaducidad:=drr("FechaCaducidad").ToString.ToDate, CostoIndirecto:=Dr("CostoIndirectoAlmacen").ToString.ToDouble, CveCompraDetalle:=Dr("CveCompraDetalle").ToString.ToEntero, CveOrdenCompraDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero) Then - ErrorMovInv = True - Exit For - End If - - Next - End If - Else - - 'UNIDAD BASE - EQUIVALENCIAS - INVENTARIO - If UsuarioActual.CveEmpresa = 1 Then - DtEquivalencias = New DataTable - DtEquivalencias = GlobalDTProductosServiciosEquivalencias(CveProducto, -1, UsuarioActual.CveEmpresa) - Dim CveUnidadBase As Integer = DtEquivalencias.FiltroPrimeroValor("CveUM", "UnidadBase = 'True'").ToEntero - Dim drUMBase As DataRow = DtEquivalencias.FiltroPrimero("UnidadBase = 'True'") - - 'SI LA UNIDAD ACTUAL NO ES LA BASE SACA PROPORCION (EQUIVALENTE) - If CveUnidadBase <> CveUnidad Then - ' LO QUE PUSE LO QUE VALE UNIDAD BASE LO QUE VALE UNIDAD SELECCIONADA - CantidadInv = Dr("Cantidad").ToString.ToDouble * drUMBase("Cantidad").ToString.ToDouble / DtEquivalencias.FiltraParametros(String.Format("CveUM = {0}", CveUnidad)).Rows(0)("Cantidad").ToString.ToDouble - PUInv = PUInv * Dr("Cantidad").ToString.ToDouble / CantidadInv - CostoIndirecto = CostoIndirecto * Dr("Cantidad").ToString.ToDouble / CantidadInv - CveUnidad = CveUnidadBase - End If - End If - - 'si no es por serie lote - ImporteConcepto = If(DdlMoneda.SelectedValue.ToEntero = 1, PUInv, PUInv * TipoCambioGuardar) - ImporteConcepto = If(UsuarioActual.Empresa.UsaAC, ImporteConcepto * IVA, ImporteConcepto) - If Dr("CveAlmacen").ToString.ToEntero = tCveAlmacen Then - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoInventario, CantidadInv, CveUnidad, Dr("CvePS").ToString.ToEntero, ImporteConcepto, -1, PUTC:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, Dr("PU").ToString.ToDouble), CostoIndirecto:=CostoIndirecto, CveCompraDetalle:=Dr("CveCompraDetalle").ToString.ToEntero, CveOrdenCompraDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero) Then - ErrorMovInv = True - Exit For - End If - End If - - End If - - - i = i + 1 - Next - End If - Next - - End If - - - - If AplicarCostoIndirecto(ObjInventario, ObjCompras) Then - ErrorMovInv = True - End If - - 'Else - ' Alert("El tipo de cambio no esta actualizado. Por favor comuniquese con un asistente SIG.", TipoMensaje.MsgError) - ' ErrorMovInv = True - 'End If - - End If - - '*************************************************** P R I M E R A P A R T E C O M P R A S ************************************************************************************************************************************************************************************************************************************************************************************************** - 'P R E P O L I Z A S - - Dim CveConceptoAfectacion As Integer = 5 'Proveedores - Dim CveConceptoAfectacionContado As Integer = 17 'Pago Proveedores - Dim CveConceptoCompra As Integer = 6 'Compra - Dim CveConceptoIVA As Integer = 14 'IVA Trasladado - Dim CveConceptoRetIVA As Integer = 15 'Ret IVA - Dim CveConceptoRetISR As Integer = 16 'Ret ISR - Dim CveConceptoDescuento As Integer = 24 'DSC - Dim CveConceptoRetIEPS As Integer = 25 'IEPS - Dim CveConceptoRetOtrosImpuestos As Integer = 27 'Otros Impuestos - Dim CveCreditoDetalle As Integer = -1 - - 'Afectable con el tabpanel Contable - Dim CveProveedorLocal As Integer - Dim CveProveedorConcepto As Integer - Dim CveAcreedor As Integer - Dim CveColectiva As Integer = -1 - - Dim TipoCreditoInteres As Boolean = False - Dim ImporteIECredito As Decimal = 0 - Dim SeContabiliza As Boolean = If(UsuarioActual.CveEmpresa.Contiene(119) AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ant"), False, True) - - If RBLPago.SelectedValue = "1" Or RBLPago.SelectedValue = "3" Then - 'Credito Proveedor - CveProveedorLocal = CveProveedor - CveProveedorConcepto = CveProveedor - CveAcreedor = -1 - - Else - 'cuando es contado - - Select Case RBLContado.SelectedValue - Case "1", "6" 'Proveedores - CveProveedorLocal = CveProveedor - CveProveedorConcepto = CveProveedor - CveAcreedor = -1 - Case "2" ' F y E - CveProveedorLocal = CveProveedor - CveProveedorConcepto = CveProveedor - CveAcreedor = -1 - CveIE = DDlCheques.SelectedValue.ToEntero - Case "3" ' Doctos - - CveProveedorConcepto = CveProveedor - - If DdlTipoCredito.SelectedValue.ToEntero = 2 Then - CveProveedorLocal = CveProveedor - CveProveedorConcepto = CveProveedor - CveAcreedor = -1 - CveColectiva = -1 - ' CveConceptoAfectacionContado = 55 - CveConceptoAfectacion = 59 - CveCreditoDetalle = DdlCreditoDetalle.SelectedValue.ToEntero - ObjIE.UpdateCreditosDetalle(3, CveCreditoDetalle) - End If - Case "4" ' Deudores - CveProveedorLocal = CveProveedor - CveProveedorConcepto = DdlDeudor.SelectedValue.ToEntero - For Each row As GridViewRow In GvDeudores.Rows - If row.FCCheckBox("Chk").Checked Then - CveIE = row.DataKey("CveIE").ToString.ToEntero - Exit For - End If - Next - CveAcreedor = -1 - CveColectiva = -1 - ' CveConceptoAfectacionContado = 55 - CveConceptoAfectacion = 37 - Case "5" ' Acreedores - CveProveedorLocal = CveProveedor - CveProveedorConcepto = DdlAcreedor.SelectedValue.ToEntero - CveAcreedor = -1 - CveColectiva = -1 - CveConceptoAfectacion = 41 - - If EmpresaPrueba Then - CveIE = If(DdlAcreedorDetalle.SelectedValue.ToEntero = -2, -1, DdlAcreedorDetalle.SelectedValue.ToEntero) - End If - End Select - End If - - If RBLPago.SelectedValue.ToEntero = 4 Then - Dim TmpTotal As Decimal = TxtTotal.Text.ToDecimal - Dim TmpTotalCreditos As Decimal = 0 - - For Each GvRow As GridViewRow In GvCreditos.Rows - TmpTotalCreditos = TmpTotalCreditos + GvRow.FCTextBox("TxtCapital").Text.ToDecimal - TmpTotalCreditos = TmpTotalCreditos + GvRow.FCTextBox("TxtInteres").Text.ToDecimal - TmpTotalCreditos = TmpTotalCreditos + GvRow.FCTextBox("TxtAmbos").Text.ToDecimal - Next - - If TmpTotalCreditos > TmpTotal Then - ErrorCredito = True - End If - - For Each GvRow As GridViewRow In GvCreditos.Rows - - Dim Capital As Decimal = GvRow.FCTextBox("TxtCapital").Text.Replace(",", "").ToDecimal - Dim Interes As Decimal = GvRow.FCTextBox("TxtInteres").Text.Replace(",", "").ToDecimal - Dim Ambos As Decimal = GvRow.FCTextBox("TxtAmbos").Text.Replace(",", "").ToDecimal - - Dim CveCreditoDetalleTemp As Integer = GvRow.DataKey("CveCreditoDetalle").ToEntero - Dim CveCreditoTemp As Integer = GvRow.DataKey("CveCredito").ToEntero - Dim EstusTemp = GvRow.DataKey("Estatus").ToEntero - ' Dim ImporteOpcionCompra As Decimal = GvRow.DataKey("ImporteOpcionCompra").ToDecimal - Dim Marcador As Decimal = GvRow.DataKey("Marcador").ToEntero - Dim CreditoEstatus As Integer = -1 - - If Capital > 0 Or Interes > 0 Or Ambos > 0 Then - - If ObjIE.GetCreditosDetalle(CveCreditoTemp, -1) Then - - Dim CveCompraCapital As Integer = -1 - Dim CveCompraInteres As Integer = -1 - - 'Dim ImporteCapital As Decimal = 0 - ' Dim ImporteCapitalIVA As Decimal = 0 - - 'Dim ImporteInteres As Decimal = 0 - ' Dim ImporteInteresIVA As Decimal = 0 - - ' Dim ImporteIEMensualidad As Decimal = ObjIE.DtResultados.FiltroPrimeroValor("ImporteIE", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToDecimal - CreditoEstatus = ObjIE.DtResultados.FiltroPrimeroValor("Estatus", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToEntero - - CveCompraCapital = ObjIE.DtResultados.FiltroPrimeroValor("CveCompra", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToEntero - CveCompraInteres = ObjIE.DtResultados.FiltroPrimeroValor("CveCompraInteres", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToEntero - - CveCompraCapital = If(CveCompraCapital < 1, -1, CveCompraCapital) - CveCompraInteres = If(CveCompraInteres < 1, -1, CveCompraInteres) - - TipoCreditoInteres = Boolean.Parse(ObjIE.DtResultados.FiltroPrimeroValor("TipoInteres", $"CveCreditoDetalle = {CveCreditoDetalleTemp}")) - ImporteIECredito = ObjIE.DtResultados.FiltroPrimeroValor("ImportePago", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToDecimal - - If Ambos > 0 Then - CveCompraCapital = CveCompra - CveCompraInteres = CveCompra - - Capital = Ambos - Interes = Ambos - - End If - - If Capital > 0 Then - CveCompraCapital = CveCompra - End If - If Interes > 0 Then - CveCompraInteres = CveCompra - End If - - - - If (CveCompraCapital > 0 And CveCompraInteres > 0) And EstusTemp = 2 Then - If EstusTemp = 2 Then - EstusTemp = 3 - ElseIf EstusTemp = 1 Or EstusTemp = 4 Then - EstusTemp = 4 - End If - ElseIf CveCompraCapital > 0 Or CveCompraInteres > 0 Then - If EstusTemp = 2 Then - EstusTemp = 2 - ElseIf EstusTemp = 1 Or EstusTemp = 4 Then - EstusTemp = 4 - End If - End If - - If Not ObjIE.UpdateCreditosDetalle(CveCreditoDetalleTemp, "01/01/2000".ToDate, -1, -1, -1, -1, -1, -1, EstusTemp, CveCompra:=CveCompraCapital, CveCompraInteres:=CveCompraInteres, importeCapital:=Capital, - ImporteInteres:=Interes) Then - ErrorCredito = True - End If - 'ObjIE.UpdateCreditosDetalle(CveCreditoDetalle, "01/01/2000".ToDate, -1, -1, -1, -1, -1, -1, Estatus) - - - - Else - ErrorCredito = True - End If - End If - Next - End If - - Dim TipoMovimientoCompra As Boolean = False - Dim TipoMovimientoImpuestos As Boolean = True - If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - CveConceptoAfectacion = 18 'Devolución del Proveedor (NC) - TipoMovimientoCompra = Not TipoMovimientoCompra - TipoMovimientoImpuestos = Not TipoMovimientoImpuestos - End If - - If EmpresaPrueba Then 'Empresa Prueba - - Dim PorcentajePagos As Decimal = 0 - Dim sumaPagos As Decimal = 0 - Dim tipoCambioActual As Decimal - Dim alertaContabilizacion As String = "Se enviaron correctamente las siguientes pólizas:

" - Dim idCuentaContabilizacion As Long = 1 - Dim CveCuentaContabilizacion As Long = 1 - Dim FechaMovimiento As Date = TxtFecha.Text.ToDate - Dim DT As DataTable = Nothing - Dim CuentasContablesInvalidas As New StringBuilder - Dim CuentasContablesInvalidasSIG As New StringBuilder - Dim ConceptoPersonal As String = "" - Dim IdCtaIVAXAcreditar As Integer = 0 - Dim IdCtaIVAAcreditable As Integer = 0 - Dim GuardoConcepto18 As Boolean = False - - If GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeIVA).Rows.Count > 0 Then - IdCtaIVAXAcreditar = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeIVA).Rows(0)("IdCtaIVAXAcreditar").ToString.ToEntero - IdCtaIVAAcreditable = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeIVA).Rows(0)("IdCtaIVAAcreditable").ToString.ToEntero - End If - - - - '********************** Variables '********************** - - '****** Pagos - - 'Bancos (30) - Dim importeBanco As Decimal = 0 - If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "1" AndAlso (Not DivTarjeta.Visible Or DdlTarjeta.SelectedValue.ToEntero = -1) Then - importeBanco = TxtDocumentoImporte.Text.ToDecimal - sumaPagos += importeBanco - End If - - 'Caja Chica (30) - Dim importeCajaChica As Decimal = 0 - If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "6" Then - importeCajaChica = TxtDocumentoImporteCaja.Text.ToDecimal - sumaPagos += importeCajaChica - End If - - 'Funcionarios y Empleados (29) - Dim importeFE As Decimal = 0 - If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "2" Then - ViewState("CvePersonal") = DdlFuncionarioEmpleado.SelectedValue.ToEntero - ConceptoPersonal = DdlFuncionarioEmpleado.SelectedItem.ToString - importeFE = TxtDocumentoImporteFE.Text.ToDecimal - sumaPagos += importeFE - End If - - 'Deudores (37) - Dim importeDD As Decimal = 0 - If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "4" Then - ConceptoPersonal = DdlDeudor.SelectedItem.ToString - importeDD = TxtContadoDeudor.Text.ToDecimal - sumaPagos += importeDD - End If - - 'Acreedores (41) SinTarjeta - Dim importeAcreedores As Decimal = 0 - If (CveIE > 0 Or DdlAcreedorDetalle.SelectedValue.ToEntero = -2) AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "5" Then - ConceptoPersonal = DdlAcreedor.SelectedItem.ToString - importeAcreedores = TxtContadoAcreedor.Text.ToDecimal - sumaPagos += importeAcreedores - End If - - 'Acreedores (42) ConTarjeta - Dim importeAcreedoresTarjeta As Decimal = 0 - If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "1" AndAlso DivTarjeta.Visible AndAlso DdlTarjeta.SelectedValue.ToEntero > 0 Then - ConceptoPersonal = DdlTarjeta.SelectedItem.ToString - importeAcreedoresTarjeta = TxtDocumentoImporte.Text.ToDecimal - sumaPagos += importeAcreedoresTarjeta - End If - - 'Creditos/Documentos (59) - Dim importeCreditos As Decimal = 0 - Dim CveIECreditos = -1 - If RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "3" AndAlso DdlTipoCredito.SelectedValue.ToEntero = 2 Then - If ObjIE.GetCreditosDetalle(DdlCredito.SelectedValue.ToEntero, -1) Then - CveIECreditos = ObjIE.DtResultados.FiltroPrimero($"CveCreditoDetalle = {DdlCreditoDetalle.SelectedValue.ToEntero}")("CveIE").ToString.ToEntero - End If - ConceptoPersonal = DdlCredito.SelectedItem.ToString - importeCreditos = TxtTotal.Text.ToDecimal - sumaPagos += importeCreditos - End If - - PorcentajePagos = If(TxtTotal.Text.ToDecimal > 0, sumaPagos / TxtTotal.Text.ToDecimal, 0) - - '****** Acreditables - - 'IVA Acreditable (19) - Dim importeIVAAcreditable As Decimal = 0 - importeIVAAcreditable = TxtIVA.Text.ToDecimal * PorcentajePagos - - 'IEPS Acreditable (26) - Dim ImporteIEPSAcreditable As Decimal = 0 - ImporteIEPSAcreditable = TxtIEPS.Text.ToDecimal * PorcentajePagos - - 'RetIVA Acrediable (22) - Dim importeRetIVAAcreditable As Decimal = 0 - importeRetIVAAcreditable = TxtRetIVA.Text.ToDecimal * PorcentajePagos - - 'RetISR Acreditable (23) - Dim importeRetISRAcreditable As Decimal = 0 - importeRetISRAcreditable = TxtRetISR.Text.ToDecimal * PorcentajePagos - - - - '****** X Acreditar - 'IVA X Acreditar (14) - Dim importeIVAxAcreditar As Decimal = 0 - importeIVAxAcreditar = TxtIVA.Text.ToDecimal - - 'IEPS X Acreditar (25) - Dim ImporteIEPSxAcreditar As Decimal = 0 - ImporteIEPSxAcreditar = TxtIEPS.Text.ToDecimal - - 'Otros Impuestos (224) - Dim OtrosImpuestos As Decimal = 0 - OtrosImpuestos = TxtOtrosImpuestos.Text.ToDecimal - - 'RetIVA X Acreditar (15) - Dim importeRetIVAxAcreditar As Decimal = 0 - importeRetIVAxAcreditar = TxtRetIVA.Text.ToDecimal - - 'RetISR X Acreditar (16) - Dim importeRetISRxAcreditar As Decimal = 0 - importeRetISRxAcreditar = TxtRetISR.Text.ToDecimal - - - - '****** Movimientos Independientes - - 'Pago Proveedores (17) - Dim importePagoProv As Decimal = 0 - importePagoProv = sumaPagos - - 'If CveIE > 0 AndAlso ((RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0) Or (RBLContado.SelectedValue = "4" AndAlso DdlDeudor.SelectedValue.ToEntero > 0)) Then - ' importePagoProv = TxtDocumentoImporteFE.Text.ToDecimal - 'End If - - 'Compra (6) - 'Ya que es un foreach todo su proceso esta en el Case 6 - - 'Proveedores (5) - Dim importeProv As Decimal = 0 - importeProv = TxtTotal.Text.ToDecimal - - 'Nota de Credito (18) - Dim importeNC As Decimal = 0 - If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - importeNC = TxtTotal.Text.ToDecimal - End If - - '************************************************************************************************************************** - - Dim TipoCambioCompra As Decimal = 1 - TipoCambioCompra = GlobalTipoCambio(FechaMovimiento).ToString.ToDecimal - TipoCambioCompra = If(DivTC.Visible, TipoCambio.ToDecimal, TipoCambioCompra) - - If CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then - TipoCambioCompra = 1 - End If - - If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then - tipoCambioActual = GlobalTipoCambio(FechaMovimiento).ToString.ToDecimal - tipoCambioActual = If(DivTC.Visible, TipoCambio.ToDecimal, tipoCambioActual) - Else - tipoCambioActual = 1 - End If - - 'CASO ESPECIAL CREDITOS - If CveIECreditos > 0 Then - CveIE = CveIECreditos - 'Dim CveIEProvisional = CveIE - End If - - - - If ObjConta.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPrePoliza) Then - - Dim DTPlatilla As New DataTable - DTPlatilla = ObjConta.DtResultados - - For Each Row As DataRow In DTPlatilla.Rows - - Dim ConceptoContable = Row("CveConcepto").ToString.ToEntero - Dim TipoMovimiento As Boolean = If(Row("TipoMovto").ToString = "True", True, False) - Dim importeMovimiento As Decimal = 0 - Dim IdCtaContable As Integer = 0 - Dim CveCuenta As Integer = 0 - Dim Concepto As String = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, ConceptoContable, NombreProveedor, $"{TxtSerie.Text}-{TxtFolio.Text}", If(TxtDocumentoFolio.Visible, TxtDocumentoFolio.Text, If(TxtDocumentoFolioCaja.Visible, TxtDocumentoFolioCaja.Text, ConceptoPersonal))) - Dim importeMN As Decimal = 0 - Dim Multiplicador As Integer = If(Row("Multiplicador").ToString.ToEntero = 1, 1, -1) - Dim Referencia As String = $"{TxtSerie.Text}-{TxtFolio.Text}" ' concatenation interpolation - Dim PorcentajeImpuesto As Decimal = 0 - - - Select Case ConceptoContable - - - - - Case 17 'Pago Proveedores - - importeMovimiento = importePagoProv - If CveMonedaPago = 2 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then - importeMovimiento = importeMovimiento / TipoCambioCompra - End If - importeMN = importeMovimiento * TipoCambioCompra * Multiplicador - IdCtaContable = CtaProveedor - CveCuenta = CveCuentaProveedor - - - If RBLPago.SelectedValue.ToEntero = 4 And EstatusCredito.Contiene(2, 102) Then 'SI ES CRÉDITO Y ESTA PAGADO - - Dim IdSegmentoNegocio As Integer = -1 - For Each Row2 As DataRow In TmpDT.Rows - - importeMovimiento = TxtTotal.Text.ToDecimal 'TmpDT.SUM("Total", String.Format("ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) = 0 And ISNULL(AplicaCostoIndirecto,0) <> 1 And CveClasificacion = {0} And CveSubProyecto = {1} And ISNULL(CveTipoGasto,0) = {2}", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - 'CLASIFICACION - If Row2("CveClasificacion").ToString.ToEntero > 0 Then - If ObjConta.GetRetCuenta(6, Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero) Then - If ObjConta.DtResultados.Rows.Count > 0 AndAlso ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero - Else - IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGasto", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero - CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero - End If - End If - End If - - - - - 'SEGMENTO DE NEGOCIO - - Dim drT As DataRow = GlobalDTSubProyectos(-1, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero).FiltroPrimero(String.Format("CveSubProyecto = {0} ", Row2("CveSubProyecto").ToString.ToEntero)) - If drT IsNot Nothing Then - IdSegmentoNegocio = drT("IdSegNeg").ToString.ToEntero - End If - - 'AGREGA MOVIMIENTO - If importeMovimiento <> 0 Then - 'Conta ContPAQ - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - 'Conta SIG - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) - CveCuentaContabilizacion = 0 - End If - End If - Next - - - - Dim CveClasificacionDT As Integer = -1 - Dim CveSubProyectoDT As Integer = -1 - Dim CveTipoGastoDT As Integer = -1 - - If TmpDT.Rows.Count > 0 Then - CveClasificacionDT = TmpDT(0)("CveClasificacion").ToString.ToEntero - CveSubProyectoDT = TmpDT(0)("CveSubProyecto").ToString.ToEntero - CveTipoGastoDT = TmpDT(0)("CveTipoGasto").ToString.ToEntero - End If - - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - - Dim ImporteSubCre As Decimal = TxtSubTotal.Text.ToDecimal - Dim ImporteSubCreMN As Decimal = TxtSubTotal.Text.ToDecimal * tipoCambioActual - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteSubCre, Referencia, 6, Concepto, FechaMovimiento, IdCtaContable, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=CveClasificacionDT, CveSubProyecto:=CveSubProyectoDT, ImporteMX:=ImporteSubCreMN, ImporteME:=If(tipoCambioActual = 1, 0, ImporteSubCre), CveCuenta:=CveCuenta, CveTipoGasto:=CveTipoGastoDT, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, Referencia, 41, Concepto, FechaMovimiento, CtaProveedorAcreedores, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=CveClasificacionDT, CveSubProyecto:=CveSubProyectoDT, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, CveTipoGasto:=CveTipoGastoDT, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - - If TipoCreditoInteres Then - - - Dim importeMovimientoIn As Decimal = ImporteIECredito - importeMovimiento - Dim importeMNIn As Decimal = importeMovimientoIn * tipoCambioActual * Multiplicador - - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimientoIn, Referencia, 41, Concepto, FechaMovimiento, CtaProveedorAcreedores, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=CveClasificacionDT, CveSubProyecto:=CveSubProyectoDT, ImporteMX:=importeMNIn, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimientoIn), CveCuenta:=CveCuenta, CveTipoGasto:=CveTipoGastoDT, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimientoIn, Referencia, 50, Concepto, FechaMovimiento, ViewState("IdCtaContDocsXPagar").ToString.ToEntero(), IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=CveClasificacionDT, CveSubProyecto:=CveSubProyectoDT, ImporteMX:=importeMNIn, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimientoIn), CveCuenta:=CveCuenta, CveTipoGasto:=CveTipoGastoDT, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - - End If - End If - - - - - End If - - If TipoCambioCompra > 1 AndAlso DdlMoneda.SelectedValue.ToEntero <> 1 Then Concepto += $" TC:{TipoCambioCompra} ${importeMovimiento.FormatoNumero(2)}" - - If TipoCambioCompra = 1 Or DdlMoneda.SelectedValue.ToEntero = 1 Then - IdCtaContable = CtaProveedor - CveCuenta = CveCuentaProveedor - importeMovimiento = importeMN - Else - IdCtaContable = CtaProveedorComplementaria - CveCuenta = CveCuentaProveedorComplementaria - If importeMovimiento <> 0 AndAlso (IdCtaContable > 0 Or CveCuenta > 0) Then 'Cuando tiene complementaria lo dividimos en dos - importeMN = importeMovimiento - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento * TipoCambioCompra - importeMovimiento, Referencia, 206, Concepto, FechaMovimiento, IdCtaContable, -1, CveIE, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMovimiento * TipoCambioCompra - importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=TipoCambioCompra) Then - ErrorPrepoliza = True - End If - End If - - IdCtaContable = CtaProveedorExtranjera - CveCuenta = CveCuentaProveedorExtranjera - End If - - Case 30 'Bancos - importeMovimiento = importeBanco + importeCajaChica 'Uno de los dos debe ser 0 - If CveMonedaPago = 2 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then - importeMovimiento = importeMovimiento / TCPago - End If - importeMN = importeMovimiento * TCPago * Multiplicador - - If TCPago > 1 AndAlso CveMonedaPago <> 1 Then Concepto += $" TC:{TCPago} ${importeMovimiento.FormatoNumero(2)}" - - If TCPago = 1 Or CveMonedaPago = 1 Then - IdCtaContable = IdCuentaBancaria - CveCuenta = CveCuentaBancaria - Else - IdCtaContable = IdCuentaBancariaComplementaria - CveCuenta = CveCuentaBancariaComplementaria - If importeMovimiento <> 0 AndAlso (IdCtaContable > 0 Or CveCuenta > 0) Then 'Cuando tiene complementaria lo dividimos en dos - importeMN = importeMovimiento - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento * TCPago - importeMovimiento, Referencia, 204, Concepto, FechaMovimiento, IdCtaContable, -1, CveIE, CveProveedor:=CveProveedor, ImporteMX:=importeMovimiento * TCPago - importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=TCPago) Then - ErrorPrepoliza = True - End If - End If - - IdCtaContable = IdCuentaBancaria - CveCuenta = CveCuentaBancaria - End If - - - Case 19 'IVA Acreditable - If UsuarioActual.Empresa.Funcionalidad(521) = "1" Then - If importePagoProv = importeProv Then - importeMovimiento = TxtIVA.Text.ToDecimal - Else - importeMovimiento = 0 - End If - Else - importeMovimiento = importeIVAAcreditable - End If - - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - - PorcentajeImpuesto = PorcentajeIVA - IdCtaContable = If(IdCtaIVAAcreditable > 0, IdCtaIVAAcreditable, 0) - - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditable").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditableSIG").ToString.ToEntero - End If - End If - - 'Agregamos el Opuesto del 19 -> 14 - If importeMovimiento <> 0 Then - Dim IdCtaIva As Integer = 0 - Dim CveCuentaIVA As Integer = 0 - IdCtaIva = If(IdCtaIVAXAcreditar > 0, IdCtaIVAXAcreditar, 0) - - If ObjConta.GetRetCuenta(14, UsuarioActual.CveEmpresa) And Not IdCtaIva > 0 Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaIva = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditar").ToString.ToEntero - CveCuentaIVA = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditarSIG").ToString.ToEntero - End If - End If - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 14, Concepto + If(tipoCambioActual > 1, $" TC: {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaIva, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuentaIVA, PorcentajeImpuesto:=PorcentajeImpuesto, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then - ErrorPrepoliza = True - End If - End If - - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - Case 14 'IVA X Acreditar - importeMovimiento = importeIVAxAcreditar - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - PorcentajeImpuesto = PorcentajeIVA - IdCtaContable = If(IdCtaIVAXAcreditar > 0, IdCtaIVAXAcreditar, 0) - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditar").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditarSIG").ToString.ToEntero - End If - End If - Case 25 'IEPS X Acreditar - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - importeMovimiento = ImporteIEPSxAcreditar - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxAcreditar").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxAcreditarSIG").ToString.ToEntero - End If - End If - End If - - Case 224 'Otros impuestos - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - importeMovimiento = OtrosImpuestos - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - IdCtaContable = If(UsuarioActual.CveEmpresa = 119, 1171, -1) - CveCuenta = -1 - End If - Case 26 'IEPS Acreditable - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - importeMovimiento = ImporteIEPSAcreditable - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSAcreditable").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSAcreditableSIG").ToString.ToEntero - End If - End If - - 'Agregamos el Opuesto del 26 -> 25 - If importeMovimiento <> 0 Then - Dim IdCtaIEPS As Integer = 0 - Dim CveCuentaIEPS As Integer = 0 - If ObjConta.GetRetCuenta(25, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaIEPS = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxAcreditar").ToString.ToEntero - CveCuentaIEPS = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxAcreditarSIG").ToString.ToEntero - End If - End If - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 25, Concepto + If(tipoCambioActual > 1, $" TC: {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaIEPS, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuentaIEPS, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then - ErrorPrepoliza = True - End If - End If - - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - - End If - Case 22 'RetIVA Acreditable Honorarios/Serv. Prof. - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 1 Then - importeMovimiento = importeRetIVAAcreditable - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(308).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(308).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If + End If + + 'Compra + If ObjCompras.AddCompra(DdlTipoComprobante.SelectedValue, TxtDescripcion.Text.Trim, TxtSerie.Text.Trim, TxtFolio.Text.Trim, TxtFolioSecundario.Text.Trim, CveProveedor, TxtSubTotal.Text.ToDouble, TxtDescuento.Text.ToDouble, + LblAmortizacion.Text.ToDouble, TxtIVA.Text.ToDouble, TxtRetIVA.Text.ToDouble, TxtRetISR.Text.ToDouble, TxtIEPS.Text.ToDouble, TxtOtrosImpuestos.Text.ToDouble, + TxtRedondeo.Text.ToDouble, TxtTotal.Text.ToDouble, TxtFecha.Text.Trim.ToDate, DdlMoneda.SelectedValue.ToEntero, TipoCambio, TxtFechaPago.Text.Trim.ToDate, ChkAplicaNotaCredito.Checked, TxtObsFact.Text.Trim, CveEstatusFactura, + CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, IdPoliza, CveCajaChica:=CveCajaChica, CvePersonal:=CvePersonal, NumeroReembolso:=NumeroReembolso, CveProveedorSucursal:=DdlProveedorSucursal.SelectedValue.ToEntero, + AplicoPromocion:=ChkOCPromocion.Checked, PorcentajeIVA:=PorcentajeIVA, CveMetodoPago:=CveMetodoPago, CveRetIVAConcepto:=If(DdlRetIVAConcepto.Items.Count > 0, DdlRetIVAConcepto.SelectedValue.ToEntero, -1), CveConceptoContableAlmacen:=CveConceptoContableAlmacen, + CveRetISRConcepto:=If(DdlRetISRConcepto.Items.Count > 0, DdlRetISRConcepto.SelectedValue.ToEntero, -1), NoDeducible:=EsNoDeducible, CveTipoCompra:=DdlTipoCompra.SelectedValue.ToEntero, TotalOriginal:=TotalOriginal, CveTipoConcepto:=CveTipoConcepto) Then + + ViewState("CveCompra") = ObjCompras.CveCompra + If ObjCompras.DtResultados.Rows.Count > 0 Then ViewState("CompraFolio") = ObjCompras.DtResultados.Rows(0)("vFolio").ToString + If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + ErrorMovDev = guardardevolucion(ObjInventario, ObjCompras.CveCompra, TxtSubTotal.Text.ToDouble, TxtFecha.Text.Trim.ToDate) + End If + Dim ErrorDetalles As Boolean = False + ' Dim IDPoliza As Integer + Dim IDPolizaComprometido = 0 + Dim ErrorComprometido = False + + If CveImportacion > 0 Or CveFlete > 0 Then + + + Select Case CveConceptoContableAlmacen + Case 237 + Select Case FleteImportacionOpcion + Case 1 + Dim Dr As DataRow = Nothing + If ObjInventario.GetFletes(UsuarioActual.CveEmpresa, CveFlete) Then + If ObjInventario.DtResultados.Rows.Count > 0 Then + Dr = ObjInventario.DtResultados.Rows(0) + End If + End If + If Dr IsNot Nothing Then + If Not ObjInventario.UpdateFlete(CveFlete, Dr("Descripcion").ToString, Dr("Fecha").ToString.ToDate, -1, CveCompra, UsuarioActual.CveUsuario) Then + ErrorOC = True + End If + Else + ErrorOC = True + End If + Case 2 + If Not ObjInventario.AddFleteDetalle(CveFlete, CveCompra) Then + ErrorOC = True + End If + 'actualiza la compra para que no se surta en almacen. sino por el flete o importación + If Not ObjCompras.UpdateEstatusAlmacen(CveCompra, 2) Then + ErrorOC = True + End If + End Select + Case 240 + Select Case FleteImportacionOpcion + Case 1 + If Not ObjCompras.AddImportacionCompra(CveImportacion, CveCompra) Then + ErrorOC = True + End If + Case 2 + If Not ObjCompras.AddImportacionDetalle(CveImportacion, CveCompra) Then + ErrorOC = True + End If + 'actualiza la compra para que no se surta en almacen. sino por el flete o importación + If Not ObjCompras.UpdateEstatusAlmacen(CveCompra, 2) Then + ErrorOC = True + End If + End Select + End Select + End If + + + If UsuarioActual.Empresa.UsaAC Then + + If TotalPorDevengar <= TxtTotal.Text.ToDouble And TotalPorDevengar > 0 Then + ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) + ObjContaAC.IniciaTransacSQL() + + ''POLIZA COMPROMETIDO SOLO SI NO SE VINCULA OC + If HdnVCveOC.Value.ToEntero > 0 Then + ' IDPolizaComprometido = ObjContaAC.AddPoliza( 4, "Comprometido", Total, Total, UsuarioActual.CveUsuario, Now) + ' If IDPolizaComprometido <= 0 Then + ' ErrorComprometido = True + ' End If + IDPolizaComprometido = 1 + TotalPorDevengar = TotalPorDevengar * 2 + Else + TotalPorDevengar = TotalPorDevengar * 3 + End If + + IdPoliza = ObjContaAC.AddPoliza(3, TxtDescripcion.Text.Trim, TotalPorDevengar, TotalPorDevengar, UsuarioActual.CveUsuario, TxtFecha.Text.ToDate) + + 'Dim filtro As New StringBuilder + If IdPoliza > 0 Then + PolizaFolio = ObjContaAC.Folio + 'Dim RegistroMatriz As DataRow + 'Dim CuentaCargo As Integer + Dim CuentaAbono As Integer + Dim Importe As Decimal + + 'CUENTA PROVEEDOR + If tIdContaProveedor <= 0 Then + 'normalmente debe de ser la cuenta 021120000000000000, para el caso de APH, se el cmabio al 2119 + If ObjContaAC.GetCuentas(-1, "021190000000000000", -1) Then + Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") + If drCuenta IsNot Nothing Then + + CuentaAbono = drCuenta("Id").ToString.ToEntero + Dim FolioProveedor = ObjContaAC.GetFolioProveedores("021190000000000000").ToString + ViewState("CtaProveedor") = ObjContaAC.AddCuenta(String.Format("02119{0}000000000", FolioProveedor.PadLeft(4, "0"c)), NombreProveedor, "D", 2, 0, 1, 0, "", 1, CuentaAbono) + ObjProveedores.UpdateProveedorIdCuentaAC(CveProveedor, CtaProveedor) + tIdContaProveedor = CtaProveedor + + Else + ErrorAC = True + ErrorACMEnsaje.Append(" - DrCuenta Nula") + End If + Else + ErrorACMEnsaje.Append(" - Error al consultar cuenta 021190000000000000 ") + ErrorAC = True + End If + End If + + Dim ConceptoRenglon As String = "" + If Not ErrorAC Then + + + 'INVENTARIOS EN AC + Dim ContadorInventario As Integer = GvInv.Rows.Cast(Of GridViewRow)().Count(Function(gvr) gvr.FCCheckBox("cbInv").Checked) + Dim CtaAlmacen As Integer + If ContadorInventario > 0 Then + Dim drr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero)) + If drr IsNot Nothing Then + CtaAlmacen = drr("IdCtaContable").ToString.ToEntero + End If + End If + + Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA, tRetIVA, tRetISR As Decimal + Dim ipresup As Integer = 0 + 'COMIENZA: PRUEBA AGRUPACION CONCEPTOS + Dim Presup = From gvr As DataRow In TmpDT.Rows.Cast(Of DataRow)() + Group gvr By Grp = New With { + Key .CvePresupuestoEgreso = gvr("CvePresupuestoEgreso").ToString.ToEntero, + Key .CveOrdencompraDetalle = If(gvr("CveOrdencompraDetalle").ToString.ToEntero > 0, 1, -1), + Key .CveActivoFijo = If(gvr("TipoAF").ToString.ToEntero = 2, gvr("CveActivoFijo").ToString.ToEntero, -1) + } Into Group + Select Grp.CvePresupuestoEgreso, Grp.CveActivoFijo, Grp.CveOrdencompraDetalle, + TotalImporte = Group.Sum(Function(r) r("Total").ToString.ToDecimal) + Dim Fecha As Date = TxtFecha.Text.ToDate + + 'Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA As Double + tTotalIVA = TxtIVA.Text.ToDecimal + tRetIVA = TxtRetIVA.Text.ToDecimal + tRetISR = TxtRetISR.Text.ToDecimal + + 'tTotalIVA = tTotalIVA - tRetIVA - tRetISR + + tTotalGral = TxtTotal.Text.ToDecimal + tRetIVA + tRetISR ' EL TOTAL GENERAL DEBE DE SER EL SUBTOTAL + IVA, NO SE DEBEN DE INCLUIR LAS RETENCIONES, POR ESO SE RESTA + tDiferenciaIVA = tTotalIVA + + ipresup = 0 + + Dim CuentaMatrizAlmacen As Integer + + 'PresupuestoEgresos + Dim DtPresupuestosTemp As DataTable + Dim IdCuentaComprometido, IdCuentaPorEjercer, IdCuentaDevengado, IdCuentaMatriz As Integer + ' Dim DescuentoConIVA As Decimal + Dim tPorIVA As Decimal = tTotalIVA / (tTotalGral - tTotalIVA) + Dim tAjusteTotal As Decimal + + For Each grp In Presup + Importe = grp.TotalImporte + TotalDetalle += Importe + ipresup += 1 + If Importe > 0 Then + 'saco la proporcion de iva que le corresponde + tIVA = Math.Round(Importe * tPorIVA, 2) + tDiferenciaIVA -= tIVA + 'identifico si es el ultimo registro, para ver si es necesario un ajuste + If ipresup = Presup.Count Then + If Math.Round(TotalDetalle - tTotalGral, 2) <= 0.01 AndAlso tDiferenciaIVA > 0 Then + tIVA += tDiferenciaIVA + End If + End If + + 'le sumo el iva al concepto + Importe += tIVA + + 'codigo Provisional, para cuand tenga descuento, solo tome el subtotal * el iva,RMF + If TxtDescuento.Text.ToDouble > 0 Then + Importe = grp.TotalImporte * 1.16D + End If + + tAjusteTotal += Importe + 'valido que la sumas de lo detalles no exceda al totalgeneral + If Math.Round(tAjusteTotal, 2) > tTotalGral Then + 'le resto la diferencia + Importe -= (tAjusteTotal - tTotalGral) + End If + + 'Presupuesto Egresos + DtPresupuestosTemp = DtPresupuestos.FiltraParametros(String.Format("CvePresupuestoEgreso = {0}", grp.CvePresupuestoEgreso)) + If DtPresupuestosTemp.Rows.Count <> 1 Then + ErrorAC = True + ErrorACMEnsaje.Append(" - DtPresupuestosTemp.Rows.Count <> 1 ") + Exit For + End If + IdCuentaComprometido = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString.ToEntero + IdCuentaPorEjercer = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero + IdCuentaDevengado = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString.ToEntero + IdCuentaMatriz = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString.ToEntero + + 'COMPROMETIDO DEPENDIENTE SI EXISTE SU POLIZA + If grp.CveOrdencompraDetalle = -1 Then + ConceptoRenglon = String.Format("GC Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaPorEjercer, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + ErrorACMEnsaje.Append(" - Error al agregar movimiento contabilidad 1") + Exit For + End If + Else + ErrorACMEnsaje.Append(" - Error al agregar movimiento contabilidad 2") + ErrorAC = True + Exit For + End If + End If + + ConceptoRenglon = String.Format("GD Fact:{0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + 'DEVENGADO + If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaDevengado, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorACMEnsaje.Append(" - Error al agregar movimiento contabilidad 3") + ErrorAC = True + Exit For + End If + Else + ErrorACMEnsaje.Append(" - Error al agregar movimiento contabilidad 4") + ErrorAC = True + Exit For + End If + + If ContadorInventario > 0 Then + CuentaMatrizAlmacen = CtaAlmacen + ElseIf grp.CveActivoFijo > 0 Then + + Dim CtaAF = -1 + Dim AF = "" + Dim CuentaInicial = -1 + + If ObjAF.GetActivosFijos(grp.CveActivoFijo, UsuarioActual.CveEmpresa, "-1", "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "", -1, UsuarioActual.CveEmpresa) Then + CtaAF = ObjAF.Cuenta + AF = ObjAF.Descripcion + CuentaInicial = ObjAF.CuentaInicial + Else + ErrorAC = True + ErrorACMEnsaje.Append(" - Error al obtener activos fijos ") + Exit For + End If + + If Not CuentaInicial > 0 Then + CuentaInicial = 1241 + End If + + 'CUENTA AF + If CtaAF <= 0 Then + If ObjContaAC.GetCuentas(-1, String.Format("0{0}0000000000000", CuentaInicial), -1) Then + Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") + If drCuenta IsNot Nothing Then + ErrorACMEnsaje.Append(" - Error al obtener cuentas 0{0}0000000000000 drCuenta nula") + CuentaAbono = drCuenta("Id").ToString.ToEntero + Dim FolioAF = ObjContaAC.GetFolioProveedores(String.Format("0{0}0000000000000", CuentaInicial)).ToString + CtaAF = ObjContaAC.AddCuenta(String.Format("0{0}{1}000000000", CuentaInicial, FolioAF.PadLeft(4, "0"c)), AF, "A", 2, 0, 1, 0, "", 1, CuentaAbono) + + ObjAF.UpdateActivosFijosCuentaAC(grp.CveActivoFijo, CtaAF, UsuarioActual.CveUsuario) + Else + ErrorACMEnsaje.Append(" - Error al obtener cuentas 0{0}0000000000000 drCuenta nulo") + ErrorAC = True + End If + Else + ErrorACMEnsaje.Append(" - Error al obtener cuentas 0{0}0000000000000") + ErrorAC = True + End If + End If + + CuentaMatrizAlmacen = CtaAF + Else + CuentaMatrizAlmacen = IdCuentaMatriz + End If + + + ''AFECTAR MATRIZ EGRESOS + If ObjContaAC.AddMovimiento(IdPoliza, CuentaMatrizAlmacen, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + + + ''VERIFICA SI TIENE DESCUENTO (AMORTIZACION) + 'If TxtDescuento.Text.ToDouble > 0 Then + ' DescuentoConIVA = TxtDescuento.Text.ToDouble * 1.16 + + ' 'Valida que el descuento con iva cuadre en los totales + ' If Math.Abs(DescuentoConIVA - (Importe - TxtTotal.Text.ToDouble)) < 0.02 Then + ' DescuentoConIVA = Importe - TxtTotal.Text.ToDouble + ' ElseIf DescuentoConIVA <> (Importe - TxtTotal.Text.ToDouble) Then + ' ErrorAC = True + ' Exit For + ' End If + + ' 'actualizo el idcuenta del presupuesto + ' If ObjContaAC.AddMovimiento(123456, IdPoliza, tIdContaProveedor, True, Importe - DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then + ' 'agrego a la cuenta contable anticipos + ' If Not ObjContaAC.AddMovimiento(123456, IdPoliza, CtaProveedorAnticipos, True, DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then + ' ErrorAC = True + ' Exit For + ' End If + ' Else + ' ErrorAC = True + ' Exit For + ' End If + + 'Else + ' 'actualizo el idcuenta del presupuesto + ' Importe = TxtTotal.Text.ToDouble + ' If Not ObjContaAC.AddMovimiento(123456, IdPoliza, tIdContaProveedor, True, If(ArrAnticipos.Count > 0, ImporteAnticipo, Importe), "", ConceptoRenglon, 0, Fecha, "") Then + ' ErrorAC = True + ' Exit For + ' End If + + 'End If + + + Else + ErrorACMEnsaje.Append(" - Error AFECTAR MATRIZ EGRESOS ObjContaAC.AddMovimiento") + ErrorAC = True + Exit For + End If + ''TERMINA AFECTAR MATRIZ EGRESOS + + Else + ErrorACMEnsaje.Append(" - For Each grp In Presup Importe > 0 ") + ErrorAC = True + Exit For + End If + + Next + + ''[IPP] COMENTADO A MIRAS DE ELIMINAR 21-FEBRERO-2018 + ''VERIFICA SI TIENE DESCUENTO (AMORTIZACION) + 'If TxtDescuento.Text.ToDouble > 0 Then + ' DescuentoConIVA = TxtDescuento.Text.ToDecimal * 1.16D + + ' 'Valida que el descuento con iva cuadre en los totales + ' If Math.Abs(DescuentoConIVA - (Importe - TxtTotal.Text.ToDecimal)) < 0.02 Then + ' DescuentoConIVA = Importe - TxtTotal.Text.ToDecimal + ' ElseIf DescuentoConIVA <> (Importe - TxtTotal.Text.ToDecimal) Then + ' ErrorACMEnsaje.Append(" - Valida que el descuento con iva cuadre en los totales ") + ' ErrorAC = True + ' End If + + ' 'actualizo el idcuenta del presupuesto + ' If ObjContaAC.AddMovimiento(IdPoliza, tIdContaProveedor, True, MultiplicadorNC * (Importe - DescuentoConIVA), "", ConceptoRenglon, 0, Fecha, "") Then + ' 'agrego a la cuenta contable anticipos + ' If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorAnticipos, True, MultiplicadorNC * DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then + ' ErrorACMEnsaje.Append(" - actualizo el idcuenta del presupuesto ObjContaAC.AddMovimiento 1") + ' ErrorAC = True + ' End If + ' Else + ' ErrorACMEnsaje.Append(" - actualizo el idcuenta del presupuesto ObjContaAC.AddMovimiento 2") + ' ErrorAC = True + ' End If + 'Else + 'actualizo el idcuenta del presupuesto + Importe = TxtTotal.Text.ToDecimal + If Not ObjContaAC.AddMovimiento(IdPoliza, tIdContaProveedor, True, MultiplicadorNC * (If(ArrAnticipos.Count > 0, ImporteAnticipo, Importe)), "", ConceptoRenglon, 0, Fecha, "") Then + ErrorACMEnsaje.Append(" - actualizo el idcuenta del presupuesto ObjContaAC.AddMovimiento 3") + ErrorAC = True + End If + 'End If + + + If tRetISR > 0 Then + ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorRetISR, True, MultiplicadorNC * tRetISR, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorACMEnsaje.Append(" RetISR > 0 ObjContaAC.AddMovimiento") + ErrorAC = True + End If + End If + + 'TERMINA: PRUEBA AGRUPACION CONCEPTOS + + 'registrar amortizar anticipos + End If + + Else + ErrorACMEnsaje.Append(" - Id Poliza = 0 ") + ErrorAC = True + End If + Else + TieneError = True + ErrorACMEnsaje.Append("- TotalPorDevengar <= TxtTotal.Text.ToDouble And TotalPorDevengar > 0") + ErrorAC = True + End If + End If + + If Not ErrorAC Then + + + Dim AutoConta As Boolean = UsuarioActual.Empresa.Funcionalidad(200) = "1" + + If UsuarioActual.CveEmpresa = 119 AndAlso (DdlPersonalReembolso.SelectedValue.ToEntero > 0 Or DdlCuentaCajaChicaReembolso.SelectedValue.ToEntero > 0 Or DdlTipoComprobante.SelectedValue = "Ant") Then + AutoConta = False + End If + + If (AutoConta Or UsuarioActual.Empresa.UsaAC) And ObjContaAC Is Nothing Then + ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) + ObjContaAC.IniciaTransacSQL() + End If + + ''EMPIEZA: INSERTA DETALLES DE LA COMPRA + Dim indiceTR = 0 + Dim Cont As Integer = 0 + For Each Row As DataRow In TmpDT.Rows + Dim TipoRecepcion As Integer = -1 + + + ''INVENTARIOS + If GvInv.Rows.Count > indiceTR Then + If GvInv.Rows(indiceTR).FCCheckBox("cbInv").Checked = True And GvInv.Rows(indiceTR).FCDropDownList("DdlRecibirInv").SelectedValue = "1" Then + TipoRecepcion = 1 + ElseIf GvInv.Rows(indiceTR).FCCheckBox("cbInv").Checked = True And GvInv.Rows(indiceTR).FCDropDownList("DdlRecibirInv").SelectedValue = "0" Then + TipoRecepcion = 2 + End If + End If + + Dim CvePersonal = -1 + Dim Referencia = "" + + If GvPersonal.Rows.Count > Cont Then + CvePersonal = GvPersonal.Rows(Cont).FCDropDownList("DdlPersonalGv").SelectedValue.ToEntero + Referencia = GvPersonal.Rows(Cont).FCTextBox("TxtReferencia").Text + End If + Cont = Cont + 1 + + 'Si es AF-INSUMO se guarda CveAF en CompraDetalle + Dim CveAF = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 1, Row("CveActivoFijo").ToString.ToEntero, -1) + + 'Si es AF-COMPRA se guarda CveAF en la Columna CveAFCompra + Dim CveAFC = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 2, Row("CveActivoFijo").ToString.ToEntero, -1) + + 'AGREGA COMPRA DETALLE + If Not ObjCompras.AddCompraDetalle(CveCompra, Row("CveUM").ToString.ToEntero, Row("CvePS").ToString.ToEntero, Row("CveSubProyecto").ToString.ToEntero, -1, CveAF, + Row("Cantidad").ToString.ToDouble, Row("PU").ToString.ToDouble, Row("IVA").ToString.ToDouble, Row("Total").ToString.ToDouble, Row("Descuento").ToString.ToDouble, + Row("Obs").ToString, Row("CveOrdenCompraDetalle").ToString.ToEntero, TipoRecepcion, Row("CveContrato").ToString.ToEntero, Row("CvePresupuestoEgreso").ToString.ToEntero, + AplicaCostoIndirecto:=Row("AplicaCostoIndirecto").ToString.ToEntero, EstatusAlmacen:=Row("EntregaDirecta").ToString.ToEntero, CvePersonal:=CvePersonal, + CveTipoGasto:=Row("CveTipoGasto").ToString.ToEntero, AF_Medida:=Row("AFMedida").ToString.ToEntero, AF_TipoMantenimiento:=Row("AFTipoMantenimiento").ToString.ToEntero, Referencia:=Referencia, OtrosGastos:=Row("OtrosGastos").ToString.ToDecimal, + RetIVA:=Row("RetIVA").ToString.ToDouble, RetISR:=Row("RetISR").ToString.ToDouble, IEPSPS:=Row("IEPSPS").ToString.ToDouble, IEPSPSIVA:=Row("IEPSPSIVA").ToString.ToDouble, + IVAPorcentaje:=Row("IVAPorcentaje").ToString.ToDouble, RetIVAPorcentaje:=Row("RetIVAPorcentaje").ToString.ToDouble, RetISRPorcentaje:=Row("RetISRPorcentaje").ToString.ToDouble, + IEPSPSPorcentaje:=Row("IEPSPSPorcentaje").ToString.ToDouble, IEPSPSIVAPorcentaje:=Row("IEPSPSIVAPorcentaje").ToString.ToDouble, NoDeducible:=If((Row("NoDeducible").ToString().ToUpper().Contiene("TRUE", "1")) AndAlso EsNoDeducible, True, False)) Then + + ErrorDetalles = True + Exit For + Else + + If Row("EntregaDirecta").ToString.ToEntero > 0 Then + EntregaDirecta = True + End If + + Dim TmpDr As DataRow = TmpDT.Select($"Consec = {Row("Consec").ToString}")(0) + TmpDr("CveCompraDetalle") = ObjCompras.CveCompraDetalle + + ' Si no es un movimiento de almacen va a tronar + Try + Dim InvDr As DataRow = DtInv.Select($"Consec = {Row("Consec").ToString}")(0) + InvDr("CveCompraDetalle") = ObjCompras.CveCompraDetalle + Catch ex As Exception + End Try + + End If + + 'Vincula Vales + If IdVale.Count > 0 Then + For Each cve In IdVale + If Not ObjAF.UpdateValeCombustible(cve, CveCompra, -1, "", -1, -1, -1, UsuarioActual.CveEmpresa) Then + ErrorAF = True + Exit For + End If + Next + Else + + End If + + + + 'AGREGA AF COMPRA - Cuando es Compra se guarda CveCompraDetalle en AF + If Row("TipoAF").ToString.ToEntero = 2 Then + If Not ObjAF.UpdateActivosFijosCompra(Row("CveActivoFijo").ToString.ToEntero, ObjCompras.CveCompraDetalle, Row("TipoAF").ToString.ToEntero, Row("Total").ToString.ToDouble, TxtFecha.Text.Trim.ToDate) Then + ErrorDetalles = True + Exit For + End If + End If + + 'ACTUALIZAR PRODUCTO/SERVICIO SAT + If Version = "3.3" Then + If Not ObjProductosServicios.UpdateProductosServiciosSAT(Row("CvePS").ToString().ToEntero(), Row("CveSATPS").ToString().ToEntero(), UsuarioActual.CveUsuario) Then + ErrorSATPS = True + End If + End If + + indiceTR += 1 + Next + ''TERMINA: INSERTA DETALLES DE LA COMPRA + + 'QUEMA SALDOS DE INV-COMPRA | MERCANCIA RECIBIDA POR ADELANTADO (OC) | PP 176 + If OCVinculada And Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + For Each Row As DataRow In TmpDT.FiltraParametros("CveTipoPS = 2").Rows + If Not ObjOC.OrdenesCompraDetalleSaldosInvCompraAdd(Row("CveOrdenCompraDetalle").ToString.ToEntero, -1, -1, Row("CveCompraDetalle").ToString.ToEntero, Row("Cantidad").ToString.ToDouble) Then + ErrorSaldosInvComp = True + Exit For + End If + Next + + 'verifica si fue vinculada con una OC, y si fue la opción de entrega por adelantado, que si hubo cambios de precios + If DdlOCVinculaInv.SelectedValue.ToEntero.Contiene(176, 205) Then + If Not AjustarPrePolizaVinculacionOC(ObjOC, ObjEventos, ObjInventario, ObjConta, ObjContaAC) Then + ErrorPrepoliza = True + End If + End If + + End If + + If CvePrePoliza > 0 Then + + 'INVENTARIOS - ALMACEN + If UsuarioActual.Empresa.UsaInventarios Then 'And UsuarioActual.Empresa.UsaAC = False + + ''SI ES CON DOLARES VALIDA QUE SE TENGA EL TIPO DE CAMBIO DEL DIA DE LA FACTURA - SI NO, NO HACE NADA, la validación del TC, ya está chk constrains + ' If DdlMoneda.SelectedValue.ToEntero = 1 Or (DdlMoneda.SelectedValue.ToEntero > 1 AndAlso GlobalTipoCambio(TxtFecha.Text.ToDate) > 0) Then + + ''ALMACEN CONSIGNACION + If CveConsignacion > 0 Then + + 'actualizamos cvecompraconsignacion + For Each gvr As GridViewRow In GvInv.Rows + If gvr.FCCheckBox("cbinv").Checked AndAlso gvr.FCHiddenField("HdnCveConsignacion").Value.ToEntero > 0 Then + If Not ObjInventario.UpdateConsignacionesCompra(CveCompra, gvr.FCHiddenField("HdnCveConsignacion").Value.ToEntero, gvr.FCHiddenField("HdnCveAlmacen").Value.ToEntero, gvr.FCHiddenField("HdnCvePS").Value.ToEntero, gvr.DataKey("Cantidad").ToDouble, UsuarioActual.CveEmpresa) Then + ErrorMovInv = True + Exit For + End If + End If + Next + + If Not ErrorMovInv Then + + Dim x As Integer = 0 + For Each dr As DataRow In DtInv.Rows + If GvInv.Rows(x).FCCheckBox("cbInv").Checked And GvInv.Rows(x).FCTextBox("TbCantidad").Text.ToDouble > 0 Then + + Dim TmpDr As DataRow = TmpDT.Select($"Consec = {dr("Consec").ToString.ToEntero}")(0) 'Charlie + TmpDr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlEAlmacen").SelectedValue.ToEntero 'Charlie + + dr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlealmacen").SelectedValue.ToEntero + dr("Cantidad") = GvInv.Rows(x).FCTextBox("TbCantidad").Text.ToDouble + Else + Dim TmpDr As DataRow = TmpDT.Select($"Consec = {dr("Consec").ToString.ToEntero}")(0) 'Charlie + TmpDr("CveAlmacen") = 0 'Charlie + + dr("CveAlmacen") = 0 + End If + x = x + 1 + Next + + Dim cvemovimientosalida = 0 + Dim cvemovimientoentrada = 0 + Dim cvemovimientosalidagasto = 0 + Dim folio = 0 + Dim fecha As Date = TxtFecha.Text.ToDate + Dim indice = 0 + Dim importeconcepto = 0.0 + + Dim listalmacenes = (From cvealmacen In DtInv.AsEnumerable() Where cvealmacen.Field(Of Integer)("cvealmacen") > 0 Select cvealmacen.Field(Of Integer)("cvealmacen")).Distinct().ToList + + For Each tcvealmacen As Integer In listalmacenes + If GvInv.Rows(indice).FCDropDownList("ddlrecibirinv").SelectedValue = "1" Then + Continue For + End If + indice += 1 + + + ''agregamos la salida de consignacion + 'folio = objinventario.getfoliosiguiente(3, usuarioactual.cveempresa) + 'cvemovimientosalida = objinventario.addmovimiento(cvealmacenconsignacion, 3, ddlmoneda.selectedvalue.toentero, fecha, folio, usuarioactual.cveusuario, usuarioactual.cveempresa, cvecompra, -1, -1, -1) + 'if cvemovimientosalida <= 0 then + ' errormovinv = true + ' exit for + 'else + ' for each dr as datarow in dtinv.rows + ' if dr("cvealmacen").tostring.toentero = tcvealmacen then + ' if not objinventario.addmovimientodetalle(cvemovimientosalida, dr("cantidad").tostring.todouble, ddlum.selectedvalue.toentero, dr("cveps").tostring.toentero, 0, -1) then + ' errormovinv = true + ' exit for + + ' end if + ' end if + ' next + 'end if + + + 'agregamos la entrada + If Not UsuarioActual.Empresa.UsaAC Then fecha = Now + + folio = ObjInventario.GetFolioSiguiente(2, UsuarioActual.CveEmpresa) + cvemovimientoentrada = ObjInventario.AddMovimiento(tcvealmacen, 2, 1, fecha, folio, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, TipoCambio:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, TipoCambioGuardar), Modulo:="Comp/G") + If cvemovimientoentrada <= 0 Then + ErrorMovInv = True + Exit For + Else + CveMovimientoInventario = cvemovimientoentrada + ListaMovimientosAlmacen.Add(CveMovimientoInventario) + + For Each dr As DataRow In DtInv.Rows + If dr("cvealmacen").ToString.ToEntero = tcvealmacen Then + + importeconcepto = If(DdlMoneda.SelectedValue.ToEntero = 1, dr("pu").ToString.ToDouble, dr("pu").ToString.ToDouble * TipoCambioGuardar) + If Not ObjInventario.AddMovimientoDetalle(cvemovimientoentrada, dr("cantidad").ToString.ToDouble, dr("cveum").ToString.ToEntero, dr("cveps").ToString.ToEntero, importeconcepto, -1, PUTC:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, dr("pu").ToString.ToDouble), CveCompraDetalle:=dr("CveCompraDetalle").ToString.ToEntero) Then + + ErrorMovInv = True + Exit For + End If + End If + Next + + End If + + 'agregamos la salida gasto + folio = ObjInventario.GetFolioSiguiente(3, UsuarioActual.CveEmpresa) + cvemovimientosalidagasto = ObjInventario.AddMovimiento(tcvealmacen, 3, DdlMoneda.SelectedValue.ToEntero, fecha.AddSeconds(1), folio, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, Modulo:="Comp/G") + If cvemovimientosalidagasto <= 0 Then + ErrorMovInv = True + Exit For + Else + If ObjInventario.GetMovimientosDetalle(cvemovimientoentrada, UsuarioActual.CveEmpresa) Then + For Each dr As DataRow In ObjInventario.DtResultados.Rows + If Not ObjInventario.AddMovimientoDetalle(cvemovimientosalidagasto, dr("cantidad").ToString.ToDouble, dr("cveum").ToString.ToEntero, dr("cveps").ToString.ToEntero, 0, dr("cveaf").ToString.ToEntero, CveCompraDetalle:=dr("CveCompraDetalle").ToString.ToEntero) Then + ErrorMovInv = True + Exit For + End If + Next + End If + End If + + Next + + End If + + ''ALMACEN NORMAL + Else + + 'OBTIENE ALMACENES + Dim x As Integer = 0 + For Each Dr As DataRow In DtInv.Rows + If GvInv.Rows(x).FCCheckBox("cbInv").Checked And GvInv.Rows(x).FCTextBox("TbCantidad").Text.ToDecimal > 0 Then + + Dim TmpDr As DataRow = TmpDT.Select($"Consec = {Dr("Consec").ToString.ToEntero}")(0) + TmpDr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlEAlmacen").SelectedValue.ToEntero + + Dr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlEAlmacen").SelectedValue.ToEntero + Dr("Cantidad") = GvInv.Rows(x).FCTextBox("TbCantidad").Text.ToDouble + + Else 'limpio el valor para que no truene en linq mas abajo + + Dim TmpDr As DataRow = TmpDT.Select($"Consec = {Dr("Consec").ToString.ToEntero}")(0) + TmpDr("CveAlmacen") = 0 + + Dr("CveAlmacen") = 0 + End If + x = x + 1 + Next + + Dim i As Integer = 0 + Dim ListAlmacenes = (From CveAlmacen In DtInv.AsEnumerable() Where CveAlmacen.Field(Of Integer)("CveAlmacen") > 0 Select CveAlmacen.Field(Of Integer)("CveAlmacen")).Distinct().ToList + Dim indice = 0 + Dim ImporteConcepto = 0.0 + + For Each tCveAlmacen As Integer In ListAlmacenes + If GvInv.Rows(indice).FCDropDownList("DdlRecibirInv").SelectedValue = "1" Then + Continue For + End If + indice += 1 + + Dim fecha As Date = TxtFecha.Text.ToDate + If Not UsuarioActual.Empresa.UsaAC Then fecha = Now + + CveMovimientoInventario = ObjInventario.AddMovimiento(tCveAlmacen, 2, 1, fecha, 0, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, TipoCambio:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, TipoCambioGuardar), Modulo:="Comp/G") + + If CveMovimientoInventario <= 0 Then + ErrorMovInv = True + Else + + Dim DtDetalle As New DataTable + Dim DtEquivalencias As DataTable + Dim CveProducto As Integer + Dim CantidadInv As Double + Dim PUInv As Double + Dim CveUnidad As Integer + Dim CostoIndirecto As Double + + ListaMovimientosAlmacen.Add(CveMovimientoInventario) + + + For Each Dr As DataRow In DtInv.Rows + + CveProducto = Dr("CvePS").ToString.ToEntero + CveUnidad = Dr("CveUM").ToString.ToEntero + CantidadInv = Dr("Cantidad").ToString.ToDouble + PUInv = Dr("PU").ToString.ToDouble + CostoIndirecto = Dr("CostoIndirectoAlmacen").ToString.ToDouble + + If Dr("CveMetodoInventario").ToString.ToEntero = 5 Then + 'SI FUE POR SERIE LOTE + DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", Dr("CvePS"))) + If DtDetalle.Rows.Count > 0 Then + For Each drr As DataRow In DtDetalle.Rows + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoInventario, 1, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDouble, -1, SerieLote:=drr("Serie").ToString, FechaCaducidad:=drr("FechaCaducidad").ToString.ToDate, CostoIndirecto:=Dr("CostoIndirectoAlmacen").ToString.ToDouble, CveCompraDetalle:=Dr("CveCompraDetalle").ToString.ToEntero, CveOrdenCompraDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero) Then + ErrorMovInv = True + Exit For + End If + + Next + End If + Else + + 'UNIDAD BASE - EQUIVALENCIAS - INVENTARIO + If UsuarioActual.CveEmpresa = 1 Then + DtEquivalencias = New DataTable + DtEquivalencias = GlobalDTProductosServiciosEquivalencias(CveProducto, -1, UsuarioActual.CveEmpresa) + Dim CveUnidadBase As Integer = DtEquivalencias.FiltroPrimeroValor("CveUM", "UnidadBase = 'True'").ToEntero + Dim drUMBase As DataRow = DtEquivalencias.FiltroPrimero("UnidadBase = 'True'") + + 'SI LA UNIDAD ACTUAL NO ES LA BASE SACA PROPORCION (EQUIVALENTE) + If CveUnidadBase <> CveUnidad Then + ' LO QUE PUSE LO QUE VALE UNIDAD BASE LO QUE VALE UNIDAD SELECCIONADA + CantidadInv = Dr("Cantidad").ToString.ToDouble * drUMBase("Cantidad").ToString.ToDouble / DtEquivalencias.FiltraParametros(String.Format("CveUM = {0}", CveUnidad)).Rows(0)("Cantidad").ToString.ToDouble + PUInv = PUInv * Dr("Cantidad").ToString.ToDouble / CantidadInv + CostoIndirecto = CostoIndirecto * Dr("Cantidad").ToString.ToDouble / CantidadInv + CveUnidad = CveUnidadBase + End If + End If + + 'si no es por serie lote + ImporteConcepto = If(DdlMoneda.SelectedValue.ToEntero = 1, PUInv, PUInv * TipoCambioGuardar) + ImporteConcepto = If(UsuarioActual.Empresa.UsaAC, ImporteConcepto * IVA, ImporteConcepto) + If Dr("CveAlmacen").ToString.ToEntero = tCveAlmacen Then + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoInventario, CantidadInv, CveUnidad, Dr("CvePS").ToString.ToEntero, ImporteConcepto, -1, PUTC:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, Dr("PU").ToString.ToDouble), CostoIndirecto:=CostoIndirecto, CveCompraDetalle:=Dr("CveCompraDetalle").ToString.ToEntero, CveOrdenCompraDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero) Then + ErrorMovInv = True + Exit For + End If + End If + + End If + + + i = i + 1 + Next + End If + Next + + End If + + + + If AplicarCostoIndirecto(ObjInventario, ObjCompras) Then + ErrorMovInv = True + End If + + 'Else + ' Alert("El tipo de cambio no esta actualizado. Por favor comuniquese con un asistente SIG.", TipoMensaje.MsgError) + ' ErrorMovInv = True + 'End If + + End If + + '*************************************************** P R I M E R A P A R T E C O M P R A S ************************************************************************************************************************************************************************************************************************************************************************************************** + 'P R E P O L I Z A S + + Dim CveConceptoAfectacion As Integer = 5 'Proveedores + If CveTipoConcepto = 2 Then CveConceptoAfectacion = 305 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case CveConceptoAfectacion + Case 5 + CveConceptoAfectacion = 311 + Case 305 + CveConceptoAfectacion = 306 + Case Else + End Select + End If + + Dim CveConceptoAfectacionContado As Integer = 17 'Pago Proveedores + If CveTipoConcepto = 2 Then CveConceptoAfectacionContado = 308 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case CveConceptoAfectacionContado + Case 17 + CveConceptoAfectacionContado = 312 + Case 308 + CveConceptoAfectacionContado = 309 + Case Else + End Select + End If + + Dim CveConceptoCompra As Integer = 6 'Compra + Dim CveConceptoIVA As Integer = 14 'IVA Trasladado + Dim CveConceptoRetIVA As Integer = 15 'Ret IVA + Dim CveConceptoRetISR As Integer = 16 'Ret ISR + Dim CveConceptoDescuento As Integer = 24 'DSC + Dim CveConceptoRetIEPS As Integer = 25 'IEPS + Dim CveConceptoRetOtrosImpuestos As Integer = 27 'Otros Impuestos + Dim CveCreditoDetalle As Integer = -1 + + 'Afectable con el tabpanel Contable + Dim CveProveedorLocal As Integer + Dim CveProveedorConcepto As Integer + Dim CveAcreedor As Integer + Dim CveColectiva As Integer = -1 + + Dim TipoCreditoInteres As Boolean = False + Dim ImporteIECredito As Decimal = 0 + Dim SeContabiliza As Boolean = If(UsuarioActual.CveEmpresa.Contiene(119) AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ant"), False, True) + + If RBLPago.SelectedValue = "1" Or RBLPago.SelectedValue = "3" Then + 'Credito Proveedor + CveProveedorLocal = CveProveedor + CveProveedorConcepto = CveProveedor + CveAcreedor = -1 + + Else + 'cuando es contado + + Select Case RBLContado.SelectedValue + Case "1", "6" 'Proveedores + CveProveedorLocal = CveProveedor + CveProveedorConcepto = CveProveedor + CveAcreedor = -1 + Case "2" ' F y E + CveProveedorLocal = CveProveedor + CveProveedorConcepto = CveProveedor + CveAcreedor = -1 + CveIE = DDlCheques.SelectedValue.ToEntero + Case "3" ' Doctos + + CveProveedorConcepto = CveProveedor + + If DdlTipoCredito.SelectedValue.ToEntero = 2 Then + CveProveedorLocal = CveProveedor + CveProveedorConcepto = CveProveedor + CveAcreedor = -1 + CveColectiva = -1 + ' CveConceptoAfectacionContado = 55 + CveConceptoAfectacion = 59 + CveCreditoDetalle = DdlCreditoDetalle.SelectedValue.ToEntero + ObjIE.UpdateCreditosDetalle(3, CveCreditoDetalle) + End If + Case "4" ' Deudores + CveProveedorLocal = CveProveedor + CveProveedorConcepto = DdlDeudor.SelectedValue.ToEntero + For Each row As GridViewRow In GvDeudores.Rows + If row.FCCheckBox("Chk").Checked Then + CveIE = row.DataKey("CveIE").ToString.ToEntero + Exit For + End If + Next + CveAcreedor = -1 + CveColectiva = -1 + ' CveConceptoAfectacionContado = 55 + CveConceptoAfectacion = 37 + Case "5" ' Acreedores + CveProveedorLocal = CveProveedor + CveProveedorConcepto = DdlAcreedor.SelectedValue.ToEntero + CveAcreedor = -1 + CveColectiva = -1 + CveConceptoAfectacion = 41 + + If EmpresaPrueba Then + CveIE = If(DdlAcreedorDetalle.SelectedValue.ToEntero = -2, -1, DdlAcreedorDetalle.SelectedValue.ToEntero) + End If + End Select + End If + + If RBLPago.SelectedValue.ToEntero = 4 Then + Dim TmpTotal As Decimal = TxtTotal.Text.ToDecimal + Dim TmpTotalCreditos As Decimal = 0 + + For Each GvRow As GridViewRow In GvCreditos.Rows + TmpTotalCreditos = TmpTotalCreditos + GvRow.FCTextBox("TxtCapital").Text.ToDecimal + TmpTotalCreditos = TmpTotalCreditos + GvRow.FCTextBox("TxtInteres").Text.ToDecimal + TmpTotalCreditos = TmpTotalCreditos + GvRow.FCTextBox("TxtAmbos").Text.ToDecimal + Next + + If TmpTotalCreditos > TmpTotal Then + ErrorCredito = True + End If + + For Each GvRow As GridViewRow In GvCreditos.Rows + + Dim Capital As Decimal = GvRow.FCTextBox("TxtCapital").Text.Replace(",", "").ToDecimal + Dim Interes As Decimal = GvRow.FCTextBox("TxtInteres").Text.Replace(",", "").ToDecimal + Dim Ambos As Decimal = GvRow.FCTextBox("TxtAmbos").Text.Replace(",", "").ToDecimal + + Dim CveCreditoDetalleTemp As Integer = GvRow.DataKey("CveCreditoDetalle").ToEntero + Dim CveCreditoTemp As Integer = GvRow.DataKey("CveCredito").ToEntero + Dim EstusTemp = GvRow.DataKey("Estatus").ToEntero + ' Dim ImporteOpcionCompra As Decimal = GvRow.DataKey("ImporteOpcionCompra").ToDecimal + Dim Marcador As Decimal = GvRow.DataKey("Marcador").ToEntero + Dim CreditoEstatus As Integer = -1 + + If Capital > 0 Or Interes > 0 Or Ambos > 0 Then + + If ObjIE.GetCreditosDetalle(CveCreditoTemp, -1) Then + + Dim CveCompraCapital As Integer = -1 + Dim CveCompraInteres As Integer = -1 + + 'Dim ImporteCapital As Decimal = 0 + ' Dim ImporteCapitalIVA As Decimal = 0 + + 'Dim ImporteInteres As Decimal = 0 + ' Dim ImporteInteresIVA As Decimal = 0 + + ' Dim ImporteIEMensualidad As Decimal = ObjIE.DtResultados.FiltroPrimeroValor("ImporteIE", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToDecimal + CreditoEstatus = ObjIE.DtResultados.FiltroPrimeroValor("Estatus", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToEntero + + CveCompraCapital = ObjIE.DtResultados.FiltroPrimeroValor("CveCompra", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToEntero + CveCompraInteres = ObjIE.DtResultados.FiltroPrimeroValor("CveCompraInteres", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToEntero + + CveCompraCapital = If(CveCompraCapital < 1, -1, CveCompraCapital) + CveCompraInteres = If(CveCompraInteres < 1, -1, CveCompraInteres) + + TipoCreditoInteres = Boolean.Parse(ObjIE.DtResultados.FiltroPrimeroValor("TipoInteres", $"CveCreditoDetalle = {CveCreditoDetalleTemp}")) + ImporteIECredito = ObjIE.DtResultados.FiltroPrimeroValor("ImportePago", $"CveCreditoDetalle = {CveCreditoDetalleTemp}").ToDecimal + + If Ambos > 0 Then + CveCompraCapital = CveCompra + CveCompraInteres = CveCompra + + Capital = Ambos + Interes = Ambos + + End If + + If Capital > 0 Then + CveCompraCapital = CveCompra + End If + If Interes > 0 Then + CveCompraInteres = CveCompra + End If + + + + If (CveCompraCapital > 0 And CveCompraInteres > 0) And EstusTemp = 2 Then + If EstusTemp = 2 Then + EstusTemp = 3 + ElseIf EstusTemp = 1 Or EstusTemp = 4 Then + EstusTemp = 4 + End If + ElseIf CveCompraCapital > 0 Or CveCompraInteres > 0 Then + If EstusTemp = 2 Then + EstusTemp = 2 + ElseIf EstusTemp = 1 Or EstusTemp = 4 Then + EstusTemp = 4 + End If + End If + + If Not ObjIE.UpdateCreditosDetalle(CveCreditoDetalleTemp, "01/01/2000".ToDate, -1, -1, -1, -1, -1, -1, EstusTemp, CveCompra:=CveCompraCapital, CveCompraInteres:=CveCompraInteres, importeCapital:=Capital, + ImporteInteres:=Interes) Then + ErrorCredito = True + End If + 'ObjIE.UpdateCreditosDetalle(CveCreditoDetalle, "01/01/2000".ToDate, -1, -1, -1, -1, -1, -1, Estatus) + + + + Else + ErrorCredito = True + End If + End If + Next + End If + + Dim TipoMovimientoCompra As Boolean = False + Dim TipoMovimientoImpuestos As Boolean = True + If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + CveConceptoAfectacion = 18 'Devolución del Proveedor (NC) + TipoMovimientoCompra = Not TipoMovimientoCompra + TipoMovimientoImpuestos = Not TipoMovimientoImpuestos + End If + + If EmpresaPrueba Then 'Empresa Prueba + + Dim PorcentajePagos As Decimal = 0 + Dim sumaPagos As Decimal = 0 + Dim tipoCambioActual As Decimal + Dim alertaContabilizacion As String = "Se enviaron correctamente las siguientes pólizas:

" + Dim idCuentaContabilizacion As Long = 1 + Dim CveCuentaContabilizacion As Long = 1 + Dim FechaMovimiento As Date = TxtFecha.Text.ToDate + Dim DT As DataTable = Nothing + Dim CuentasContablesInvalidas As New StringBuilder + Dim CuentasContablesInvalidasSIG As New StringBuilder + Dim ConceptoPersonal As String = "" + Dim IdCtaIVAXAcreditar As Integer = 0 + Dim IdCtaIVAAcreditable As Integer = 0 + Dim GuardoConcepto18 As Boolean = False + + If GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeIVA).Rows.Count > 0 Then + IdCtaIVAXAcreditar = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeIVA).Rows(0)("IdCtaIVAXAcreditar").ToString.ToEntero + IdCtaIVAAcreditable = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeIVA).Rows(0)("IdCtaIVAAcreditable").ToString.ToEntero + End If + + + + '********************** Variables '********************** + + '****** Pagos + + 'Bancos (30) + Dim importeBanco As Decimal = 0 + If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "1" AndAlso (Not DivTarjeta.Visible Or DdlTarjeta.SelectedValue.ToEntero = -1) Then + importeBanco = TxtDocumentoImporte.Text.ToDecimal + sumaPagos += importeBanco + End If + + 'Caja Chica (30) + Dim importeCajaChica As Decimal = 0 + If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "6" Then + importeCajaChica = TxtDocumentoImporteCaja.Text.ToDecimal + sumaPagos += importeCajaChica + End If + + 'Funcionarios y Empleados (29) + Dim importeFE As Decimal = 0 + If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "2" Then + ViewState("CvePersonal") = DdlFuncionarioEmpleado.SelectedValue.ToEntero + ConceptoPersonal = DdlFuncionarioEmpleado.SelectedItem.ToString + importeFE = TxtDocumentoImporteFE.Text.ToDecimal + sumaPagos += importeFE + End If + + 'Deudores (37) + Dim importeDD As Decimal = 0 + If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "4" Then + ConceptoPersonal = DdlDeudor.SelectedItem.ToString + importeDD = TxtContadoDeudor.Text.ToDecimal + sumaPagos += importeDD + End If + + 'Acreedores (41) SinTarjeta + Dim importeAcreedores As Decimal = 0 + If (CveIE > 0 Or DdlAcreedorDetalle.SelectedValue.ToEntero = -2) AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "5" Then + ConceptoPersonal = DdlAcreedor.SelectedItem.ToString + importeAcreedores = TxtContadoAcreedor.Text.ToDecimal + sumaPagos += importeAcreedores + End If + + 'Acreedores (42) ConTarjeta + Dim importeAcreedoresTarjeta As Decimal = 0 + If CveIE > 0 AndAlso RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "1" AndAlso DivTarjeta.Visible AndAlso DdlTarjeta.SelectedValue.ToEntero > 0 Then + ConceptoPersonal = DdlTarjeta.SelectedItem.ToString + importeAcreedoresTarjeta = TxtDocumentoImporte.Text.ToDecimal + sumaPagos += importeAcreedoresTarjeta + End If + + 'Creditos/Documentos (59) + Dim importeCreditos As Decimal = 0 + Dim CveIECreditos = -1 + If RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue = "3" AndAlso DdlTipoCredito.SelectedValue.ToEntero = 2 Then + If ObjIE.GetCreditosDetalle(DdlCredito.SelectedValue.ToEntero, -1) Then + CveIECreditos = ObjIE.DtResultados.FiltroPrimero($"CveCreditoDetalle = {DdlCreditoDetalle.SelectedValue.ToEntero}")("CveIE").ToString.ToEntero + End If + ConceptoPersonal = DdlCredito.SelectedItem.ToString + importeCreditos = TxtTotal.Text.ToDecimal + sumaPagos += importeCreditos + End If + + PorcentajePagos = If(TxtTotal.Text.ToDecimal > 0, sumaPagos / TxtTotal.Text.ToDecimal, 0) + + '****** Acreditables + + 'IVA Acreditable (19) + Dim importeIVAAcreditable As Decimal = 0 + importeIVAAcreditable = TxtIVA.Text.ToDecimal * PorcentajePagos + + 'IEPS Acreditable (26) + Dim ImporteIEPSAcreditable As Decimal = 0 + ImporteIEPSAcreditable = TxtIEPS.Text.ToDecimal * PorcentajePagos + + 'RetIVA Acrediable (22) + Dim importeRetIVAAcreditable As Decimal = 0 + importeRetIVAAcreditable = TxtRetIVA.Text.ToDecimal * PorcentajePagos + + 'RetISR Acreditable (23) + Dim importeRetISRAcreditable As Decimal = 0 + importeRetISRAcreditable = TxtRetISR.Text.ToDecimal * PorcentajePagos + + + + '****** X Acreditar + 'IVA X Acreditar (14) + Dim importeIVAxAcreditar As Decimal = 0 + importeIVAxAcreditar = TxtIVA.Text.ToDecimal + + 'IEPS X Acreditar (25) + Dim ImporteIEPSxAcreditar As Decimal = 0 + ImporteIEPSxAcreditar = TxtIEPS.Text.ToDecimal + + 'Otros Impuestos (224) + Dim OtrosImpuestos As Decimal = 0 + OtrosImpuestos = TxtOtrosImpuestos.Text.ToDecimal + + 'RetIVA X Acreditar (15) + Dim importeRetIVAxAcreditar As Decimal = 0 + importeRetIVAxAcreditar = TxtRetIVA.Text.ToDecimal + + 'RetISR X Acreditar (16) + Dim importeRetISRxAcreditar As Decimal = 0 + importeRetISRxAcreditar = TxtRetISR.Text.ToDecimal + + + + '****** Movimientos Independientes + + 'Pago Proveedores (17) + Dim importePagoProv As Decimal = 0 + importePagoProv = sumaPagos + + 'If CveIE > 0 AndAlso ((RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0) Or (RBLContado.SelectedValue = "4" AndAlso DdlDeudor.SelectedValue.ToEntero > 0)) Then + ' importePagoProv = TxtDocumentoImporteFE.Text.ToDecimal + 'End If + + 'Compra (6) + 'Ya que es un foreach todo su proceso esta en el Case 6 + + 'Proveedores (5) + Dim importeProv As Decimal = 0 + importeProv = TxtTotal.Text.ToDecimal + + 'Nota de Credito (18) + Dim importeNC As Decimal = 0 + If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + importeNC = TxtTotal.Text.ToDecimal + End If + + '************************************************************************************************************************** + + Dim TipoCambioCompra As Decimal = 1 + TipoCambioCompra = GlobalTipoCambio(FechaMovimiento).ToString.ToDecimal + TipoCambioCompra = If(DivTC.Visible, TipoCambio.ToDecimal, TipoCambioCompra) + + If CveMonedaPago = 1 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then + TipoCambioCompra = 1 + End If + + If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then + tipoCambioActual = GlobalTipoCambio(FechaMovimiento).ToString.ToDecimal + tipoCambioActual = If(DivTC.Visible, TipoCambio.ToDecimal, tipoCambioActual) + Else + tipoCambioActual = 1 + End If + + 'CASO ESPECIAL CREDITOS + If CveIECreditos > 0 Then + CveIE = CveIECreditos + 'Dim CveIEProvisional = CveIE + End If + + + + If ObjConta.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPrePoliza) Then + + Dim DTPlatilla As New DataTable + DTPlatilla = ObjConta.DtResultados + + For Each Row As DataRow In DTPlatilla.Rows + + Dim ConceptoContable = Row("CveConcepto").ToString.ToEntero + Dim TipoMovimiento As Boolean = If(Row("TipoMovto").ToString = "True", True, False) + Dim importeMovimiento As Decimal = 0 + Dim IdCtaContable As Integer = 0 + Dim CveCuenta As Integer = 0 + Dim Concepto As String = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, ConceptoContable, NombreProveedor, $"{TxtSerie.Text}-{TxtFolio.Text}", If(TxtDocumentoFolio.Visible, TxtDocumentoFolio.Text, If(TxtDocumentoFolioCaja.Visible, TxtDocumentoFolioCaja.Text, ConceptoPersonal))) + Dim importeMN As Decimal = 0 + Dim Multiplicador As Integer = If(Row("Multiplicador").ToString.ToEntero = 1, 1, -1) + Dim Referencia As String = $"{TxtSerie.Text}-{TxtFolio.Text}" ' concatenation interpolation + Dim PorcentajeImpuesto As Decimal = 0 + + + Select Case ConceptoContable + + + + + Case 17 'Pago Proveedores + + If CveTipoConcepto = 2 Then ConceptoContable = 308 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case ConceptoContable + Case 17 + ConceptoContable = 312 + Case 308 + ConceptoContable = 309 + Case Else + End Select + End If + + importeMovimiento = importePagoProv + If CveMonedaPago = 2 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then + importeMovimiento = importeMovimiento / TipoCambioCompra + End If + importeMN = importeMovimiento * TipoCambioCompra * Multiplicador + IdCtaContable = CtaProveedor + CveCuenta = CveCuentaProveedor + + + If RBLPago.SelectedValue.ToEntero = 4 And EstatusCredito.Contiene(2, 102) Then 'SI ES CRÉDITO Y ESTA PAGADO + + Dim IdSegmentoNegocio As Integer = -1 + For Each Row2 As DataRow In TmpDT.Rows + + importeMovimiento = TxtTotal.Text.ToDecimal 'TmpDT.SUM("Total", String.Format("ISNULL(TipoAF, 0) <> 2 And ISNULL(CveAlmacen, 0) = 0 And ISNULL(AplicaCostoIndirecto, 0) <> 1 And CveClasificacion = {0} And CveSubProyecto = {1} And ISNULL(CveTipoGasto, 0) = {2} Then", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + 'CLASIFICACION + If Row2("CveClasificacion").ToString.ToEntero > 0 Then + If ObjConta.GetRetCuenta(6, Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero) Then + If ObjConta.DtResultados.Rows.Count > 0 AndAlso ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero + Else + IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGasto", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero + CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero + End If + End If + End If + + + + + 'SEGMENTO DE NEGOCIO + + Dim drT As DataRow = GlobalDTSubProyectos(-1, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero).FiltroPrimero(String.Format("CveSubProyecto = {0} ", Row2("CveSubProyecto").ToString.ToEntero)) + If drT IsNot Nothing Then + IdSegmentoNegocio = drT("IdSegNeg").ToString.ToEntero + End If + + 'AGREGA MOVIMIENTO + If importeMovimiento <> 0 Then + 'Conta ContPAQ + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + 'Conta SIG + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) + CveCuentaContabilizacion = 0 + End If + End If + Next + + + + Dim CveClasificacionDT As Integer = -1 + Dim CveSubProyectoDT As Integer = -1 + Dim CveTipoGastoDT As Integer = -1 + + If TmpDT.Rows.Count > 0 Then + CveClasificacionDT = TmpDT(0)("CveClasificacion").ToString.ToEntero + CveSubProyectoDT = TmpDT(0)("CveSubProyecto").ToString.ToEntero + CveTipoGastoDT = TmpDT(0)("CveTipoGasto").ToString.ToEntero + End If + + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + + Dim ImporteSubCre As Decimal = TxtSubTotal.Text.ToDecimal + Dim ImporteSubCreMN As Decimal = TxtSubTotal.Text.ToDecimal * tipoCambioActual + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteSubCre, Referencia, 6, Concepto, FechaMovimiento, IdCtaContable, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=CveClasificacionDT, CveSubProyecto:=CveSubProyectoDT, ImporteMX:=ImporteSubCreMN, ImporteME:=If(tipoCambioActual = 1, 0, ImporteSubCre), CveCuenta:=CveCuenta, CveTipoGasto:=CveTipoGastoDT, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, Referencia, 41, Concepto, FechaMovimiento, CtaProveedorAcreedores, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=CveClasificacionDT, CveSubProyecto:=CveSubProyectoDT, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, CveTipoGasto:=CveTipoGastoDT, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + + If TipoCreditoInteres Then + + + Dim importeMovimientoIn As Decimal = ImporteIECredito - importeMovimiento + Dim importeMNIn As Decimal = importeMovimientoIn * tipoCambioActual * Multiplicador + + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimientoIn, Referencia, 41, Concepto, FechaMovimiento, CtaProveedorAcreedores, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=CveClasificacionDT, CveSubProyecto:=CveSubProyectoDT, ImporteMX:=importeMNIn, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimientoIn), CveCuenta:=CveCuenta, CveTipoGasto:=CveTipoGastoDT, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimientoIn, Referencia, 50, Concepto, FechaMovimiento, ViewState("IdCtaContDocsXPagar").ToString.ToEntero(), IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=CveClasificacionDT, CveSubProyecto:=CveSubProyectoDT, ImporteMX:=importeMNIn, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimientoIn), CveCuenta:=CveCuenta, CveTipoGasto:=CveTipoGastoDT, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + + End If + End If + + + + + End If + + If TipoCambioCompra > 1 AndAlso DdlMoneda.SelectedValue.ToEntero <> 1 Then Concepto += $" TC{TipoCambioCompra} ${importeMovimiento.FormatoNumero(2)}" + + If TipoCambioCompra = 1 Or DdlMoneda.SelectedValue.ToEntero = 1 Then + IdCtaContable = CtaProveedor + CveCuenta = CveCuentaProveedor + importeMovimiento = importeMN + Else + IdCtaContable = CtaProveedorComplementaria + CveCuenta = CveCuentaProveedorComplementaria + If importeMovimiento <> 0 AndAlso (IdCtaContable > 0 Or CveCuenta > 0) Then 'Cuando tiene complementaria lo dividimos en dos + + Dim CveConceptoContableComplementaria As Integer = 206 + If CveTipoConcepto = 2 Then CveConceptoContableComplementaria = 310 'cuando es acreedor + + importeMN = importeMovimiento + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento * TipoCambioCompra - importeMovimiento, Referencia, CveConceptoContableComplementaria, Concepto, FechaMovimiento, IdCtaContable, -1, CveIE, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMovimiento * TipoCambioCompra - importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=TipoCambioCompra) Then + ErrorPrepoliza = True + End If + End If + + IdCtaContable = CtaProveedorExtranjera + CveCuenta = CveCuentaProveedorExtranjera + End If + + Case 30 'Bancos + importeMovimiento = importeBanco + importeCajaChica 'Uno de los dos debe ser 0 + If CveMonedaPago = 2 AndAlso DdlMoneda.SelectedValue.ToEntero = 1 Then + importeMovimiento = importeMovimiento / TCPago + End If + importeMN = importeMovimiento * TCPago * Multiplicador + + If TCPago > 1 AndAlso CveMonedaPago <> 1 Then Concepto += $" TC{TCPago} ${importeMovimiento.FormatoNumero(2)}" + + If TCPago = 1 Or CveMonedaPago = 1 Then + IdCtaContable = IdCuentaBancaria + CveCuenta = CveCuentaBancaria + Else + IdCtaContable = IdCuentaBancariaComplementaria + CveCuenta = CveCuentaBancariaComplementaria + If importeMovimiento <> 0 AndAlso (IdCtaContable > 0 Or CveCuenta > 0) Then 'Cuando tiene complementaria lo dividimos en dos + importeMN = importeMovimiento + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento * TCPago - importeMovimiento, Referencia, 204, Concepto, FechaMovimiento, IdCtaContable, -1, CveIE, CveProveedor:=CveProveedor, ImporteMX:=importeMovimiento * TCPago - importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=TCPago) Then + ErrorPrepoliza = True + End If + End If + + IdCtaContable = IdCuentaBancaria + CveCuenta = CveCuentaBancaria + End If + + + Case 19 'IVA Acreditable + If UsuarioActual.Empresa.Funcionalidad(521) = "1" Then + If importePagoProv = importeProv Then + importeMovimiento = TxtIVA.Text.ToDecimal + Else + importeMovimiento = 0 + End If + Else + importeMovimiento = importeIVAAcreditable + End If + + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + + PorcentajeImpuesto = PorcentajeIVA + IdCtaContable = If(IdCtaIVAAcreditable > 0, IdCtaIVAAcreditable, 0) + + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditable").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditableSIG").ToString.ToEntero + End If + End If + + 'Agregamos el Opuesto del 19 -> 14 + If importeMovimiento <> 0 Then + Dim IdCtaIva As Integer = 0 + Dim CveCuentaIVA As Integer = 0 + IdCtaIva = If(IdCtaIVAXAcreditar > 0, IdCtaIVAXAcreditar, 0) + + If ObjConta.GetRetCuenta(14, UsuarioActual.CveEmpresa) And Not IdCtaIva > 0 Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaIva = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditar").ToString.ToEntero + CveCuentaIVA = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditarSIG").ToString.ToEntero + End If + End If + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 14, Concepto + If(tipoCambioActual > 1, $" TC {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaIva, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuentaIVA, PorcentajeImpuesto:=PorcentajeImpuesto, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then + ErrorPrepoliza = True + End If + End If + + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + Case 14 'IVA X Acreditar + importeMovimiento = importeIVAxAcreditar + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + PorcentajeImpuesto = PorcentajeIVA + IdCtaContable = If(IdCtaIVAXAcreditar > 0, IdCtaIVAXAcreditar, 0) + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditar").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditarSIG").ToString.ToEntero + End If + End If + Case 25 'IEPS X Acreditar + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + importeMovimiento = ImporteIEPSxAcreditar + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxAcreditar").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxAcreditarSIG").ToString.ToEntero + End If + End If + End If + + Case 224 'Otros impuestos + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + importeMovimiento = OtrosImpuestos + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + IdCtaContable = If(UsuarioActual.CveEmpresa = 119, 1171, -1) + CveCuenta = -1 + End If + Case 26 'IEPS Acreditable + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + importeMovimiento = ImporteIEPSAcreditable + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSAcreditable").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSAcreditableSIG").ToString.ToEntero + End If + End If + + 'Agregamos el Opuesto del 26 -> 25 + If importeMovimiento <> 0 Then + Dim IdCtaIEPS As Integer = 0 + Dim CveCuentaIEPS As Integer = 0 + If ObjConta.GetRetCuenta(25, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaIEPS = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxAcreditar").ToString.ToEntero + CveCuentaIEPS = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxAcreditarSIG").ToString.ToEntero + End If + End If + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 25, Concepto + If(tipoCambioActual > 1, $" TC {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaIEPS, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuentaIEPS, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then + ErrorPrepoliza = True + End If + End If + + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + + End If + Case 22 'RetIVA Acreditable Honorarios/Serv. Prof. + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 1 Then + importeMovimiento = importeRetIVAAcreditable + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(308).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(308).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If End If @@ -5898,191 +5936,191 @@ Partial Class Compras_Compras 'Agregamos el Opuesto del 22 -> 15 - If importeMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 15, Concepto + If(tipoCambioActual > 1, $" TC: {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then - ErrorPrepoliza = True - End If - End If - - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - End If - End If - End If - Case 15 'RetIVA X Acreditar Honorarios/Serv. Prof. - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 1 Then - importeMovimiento = importeRetIVAxAcreditar - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(307).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(307).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - Case 184 'RetIVA Acreditable Fletes P.F - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 2 Then - importeMovimiento = importeRetIVAAcreditable - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(310).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(310).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - - 'Agregamos el Opuesto del 184 -> 183 - If importeMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 183, Concepto + If(tipoCambioActual > 1, $" TC: {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then - ErrorPrepoliza = True - End If - End If - - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - End If - End If - End If - Case 183 'RetIVA X Acreditar Fletes P.F - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 2 Then - importeMovimiento = importeRetIVAxAcreditar - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(309).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(309).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - Case 248 'RetIVA X Acreditar Arrendamiento - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 AndAlso DdlRetIVAConcepto.SelectedValue.ToEntero = 4 Then - importeMovimiento = importeRetIVAxAcreditar - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(313).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(313).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - - End If - End If - Case 186 'RetIVA Acreditable Fletes P.M. - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 3 Then - importeMovimiento = importeRetIVAAcreditable - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(312).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(312).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - - 'Agregamos el Opuesto del 186 -> 185 - If importeMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 185, Concepto + If(tipoCambioActual > 1, $" TC: {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then - ErrorPrepoliza = True - End If - End If - - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - End If - End If - End If - Case 185 'RetIVA X Acreditar Fletes P.M. - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 3 Then - importeMovimiento = importeRetIVAxAcreditar - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(311).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(311).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - Case 249 'RetIVA Acreditable Arrendamiento - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 AndAlso DdlRetIVAConcepto.SelectedValue.ToEntero = 4 Then - importeMovimiento = importeRetIVAAcreditable - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(314).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(314).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - End If - + If importeMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 15, Concepto + If(tipoCambioActual > 1, $" TC {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then + ErrorPrepoliza = True + End If + End If + + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + End If + End If + End If + Case 15 'RetIVA X Acreditar Honorarios/Serv. Prof. + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 1 Then + importeMovimiento = importeRetIVAxAcreditar + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(307).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(307).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + Case 184 'RetIVA Acreditable Fletes P.F + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 2 Then + importeMovimiento = importeRetIVAAcreditable + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(310).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(310).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + + 'Agregamos el Opuesto del 184 -> 183 + If importeMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 183, Concepto + If(tipoCambioActual > 1, $" TC {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then + ErrorPrepoliza = True + End If + End If + + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + End If + End If + End If + Case 183 'RetIVA X Acreditar Fletes P.F + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 2 Then + importeMovimiento = importeRetIVAxAcreditar + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(309).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(309).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + Case 248 'RetIVA X Acreditar Arrendamiento + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 AndAlso DdlRetIVAConcepto.SelectedValue.ToEntero = 4 Then + importeMovimiento = importeRetIVAxAcreditar + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(313).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(313).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + + End If + End If + Case 186 'RetIVA Acreditable Fletes P.M. + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 3 Then + importeMovimiento = importeRetIVAAcreditable + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(312).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(312).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + + 'Agregamos el Opuesto del 186 -> 185 + If importeMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 185, Concepto + If(tipoCambioActual > 1, $" TC {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then + ErrorPrepoliza = True + End If + End If + + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + End If + End If + End If + Case 185 'RetIVA X Acreditar Fletes P.M. + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 3 Then + importeMovimiento = importeRetIVAxAcreditar + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(311).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(311).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + Case 249 'RetIVA Acreditable Arrendamiento + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 AndAlso DdlRetIVAConcepto.SelectedValue.ToEntero = 4 Then + importeMovimiento = importeRetIVAAcreditable + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(314).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(314).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + End If + End If 'Case 23 'RetISR Acreditable ' If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then @@ -6105,56 +6143,56 @@ Partial Class Compras_Compras ' 'Agregamos el Opuesto del 23 -> 16 ' If importeMovimiento <> 0 Then - ' If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 15, Concepto + If(tipoCambioActual > 1, $" TC: {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ' If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 15, Concepto + If(tipoCambioActual > 1, $" TC {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then ' ErrorPrepoliza = True ' End If ' End If - ' If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + ' If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" ' End If ' End If - Case 16 'Ret ISR X Acreditar - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 1 Then - importeMovimiento = importeRetISRxAcreditar - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - If CtaProveedorRetISR > 0 Then - IdCtaContable = CtaProveedorRetISR - CveCuenta = CveCuentaProveedorRetISR - ElseIf UsuarioActual.Empresa.Funcionalidad(315).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(315).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - Case 243 'RetISR X Acreditar Terceros y Arrendamiento - If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then - If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 2 Then - importeMovimiento = importeRetISRxAcreditar - importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador - If CtaProveedorRetISR > 0 Then - IdCtaContable = CtaProveedorRetISR - CveCuenta = CveCuentaProveedorRetISR - ElseIf UsuarioActual.Empresa.Funcionalidad(317).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(317).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero - End If - End If - End If - - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - End If + Case 16 'Ret ISR X Acreditar + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 1 Then + importeMovimiento = importeRetISRxAcreditar + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + If CtaProveedorRetISR > 0 Then + IdCtaContable = CtaProveedorRetISR + CveCuenta = CveCuentaProveedorRetISR + ElseIf UsuarioActual.Empresa.Funcionalidad(315).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(315).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + Case 243 'RetISR X Acreditar Terceros y Arrendamiento + If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then + If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 2 Then + importeMovimiento = importeRetISRxAcreditar + importeMN = Math.Round(importeMovimiento, 2) * tipoCambioActual * Multiplicador + If CtaProveedorRetISR > 0 Then + IdCtaContable = CtaProveedorRetISR + CveCuenta = CveCuentaProveedorRetISR + ElseIf UsuarioActual.Empresa.Funcionalidad(317).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(317).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero + End If + End If + End If + + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + End If End If 'Case 244 'RetISR Acreditable Terceros y Arrendamiento ' If Not DdlTipoComprobante.SelectedValue.Contiene("Ant") Then @@ -6176,495 +6214,505 @@ Partial Class Compras_Compras ' End If ' 'Agregamos el Opuesto del 244 -> 243 ' If importeMovimiento <> 0 Then - ' If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 243, Concepto + If(tipoCambioActual > 1, $" TC: {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ' If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 243, Concepto + If(tipoCambioActual > 1, $" TC {tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}", ""), FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento * tipoCambioActual, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then ' ErrorPrepoliza = True ' End If ' End If - ' If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + ' If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" ' End If ' End If - Case 64 'Ganancia - If TCPago <> 1 AndAlso TxtFechaPago.Text <> TxtFecha.Text Then - IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria - If TCPago < TipoCambioCompra Then - importeMovimiento = Math.Abs(TCPago - TipoCambioCompra) * importePagoProv - importeMovimiento -= Math.Abs(TCPago - TipoCambioCompra) * importeIVAAcreditable - importeMovimiento += Math.Abs(TCPago - TipoCambioCompra) * importeRetIVAAcreditable - importeMovimiento += Math.Abs(TCPago - TipoCambioCompra) * importeRetISRAcreditable - importeMN = importeMovimiento - End If - Else - importeMovimiento = 0 - End If - + Case 64 'Ganancia + If TCPago <> 1 AndAlso TxtFechaPago.Text <> TxtFecha.Text Then + IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria + If TCPago < TipoCambioCompra Then + importeMovimiento = Math.Abs(TCPago - TipoCambioCompra) * importePagoProv + importeMovimiento -= Math.Abs(TCPago - TipoCambioCompra) * importeIVAAcreditable + importeMovimiento += Math.Abs(TCPago - TipoCambioCompra) * importeRetIVAAcreditable + importeMovimiento += Math.Abs(TCPago - TipoCambioCompra) * importeRetISRAcreditable + importeMN = importeMovimiento + End If + Else + importeMovimiento = 0 + End If + Case 65 'Perdida - If TCPago <> 1 AndAlso TxtFechaPago.Text <> TxtFecha.Text Then - IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria - If TCPago < TipoCambioCompra Then - importeMovimiento = Math.Abs(TCPago - TipoCambioCompra) * importePagoProv - importeMovimiento -= Math.Abs(TCPago - TipoCambioCompra) * importeIVAAcreditable - importeMovimiento += Math.Abs(TCPago - TipoCambioCompra) * importeRetIVAAcreditable - importeMovimiento += Math.Abs(TCPago - TipoCambioCompra) * importeRetISRAcreditable - importeMN = importeMovimiento - End If - Else - importeMovimiento = 0 + If TCPago <> 1 AndAlso TxtFechaPago.Text <> TxtFecha.Text Then + IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + If TCPago < TipoCambioCompra Then + importeMovimiento = Math.Abs(TCPago - TipoCambioCompra) * importePagoProv + importeMovimiento -= Math.Abs(TCPago - TipoCambioCompra) * importeIVAAcreditable + importeMovimiento += Math.Abs(TCPago - TipoCambioCompra) * importeRetIVAAcreditable + importeMovimiento += Math.Abs(TCPago - TipoCambioCompra) * importeRetISRAcreditable + importeMN = importeMovimiento + End If + Else + importeMovimiento = 0 End If - Case 285 'Ret IVA 6% Servicios - - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(578).ToEntero - - 'If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then - ' If ObjConta.DtResultados.Rows.Count > 0 Then - ' IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - ' CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - ' End If - 'End If - - - If DdlRetIVAConcepto.SelectedValue.ToEntero = 5 Then - - If CveMoneda = 2 Then - importeMN = TmpDT.SUMD("RetIVA") * TxtTC.Text.ToDecimal - Else - importeMN = TmpDT.SUMD("RetIVA") - importeMovimiento = TmpDT.SUMD("RetIVA") - - End If - - Else - importeMovimiento = 0 + Case 285 'Ret IVA 6% Servicios + + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(578).ToEntero + + 'If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then + ' If ObjConta.DtResultados.Rows.Count > 0 Then + ' IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + ' CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + ' End If + 'End If + + + If DdlRetIVAConcepto.SelectedValue.ToEntero = 5 Then + + If CveMoneda = 2 Then + importeMN = TmpDT.SUMD("RetIVA") * TxtTC.Text.ToDecimal + Else + importeMN = TmpDT.SUMD("RetIVA") + importeMovimiento = TmpDT.SUMD("RetIVA") + + End If + + Else + importeMovimiento = 0 End If - Case 6 'Compra - + Case 6 'Compra + Dim AgregaMercanciaInventario As Boolean = UsuarioActual.CveEmpresa.Contiene(1, 72, 80, 119, 140, 141) AndAlso UsuarioActual.Empresa.UsaInventarios AndAlso Not UsuarioActual.Empresa.Funcionalidad(126) = "1" Dim RegistraConcepto225 As Boolean = UsuarioActual.Empresa.UsaInventarios AndAlso DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") AndAlso Not UsuarioActual.Empresa.Funcionalidad(126) = "1" - If RBLPago.SelectedValue.ToEntero = 4 Then - Exit Select 'Es credito el concepto 6 se agrega en CASE 17 - End If - - If Not CveCompraRefacturacion > 0 OrElse ChkRefacNC.Checked Then - 'AF TipoAF 2 Es para las compras - DT = TmpDT.FiltraParametros("ISNULL(TipoAF,0) = 2 AND ISNULL(AplicaCostoIndirecto,0) <> 1") - If DT.Rows.Count > 0 AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then - For Each Row2 As DataRow In DT.Rows - importeMovimiento = If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, Row2("ImporteSinImpuestos").ToString.ToDecimal, Row2("Total").ToString.ToDecimal) - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - If ObjConta.GetRetCuenta(49, Row2("CveActivoFijo").ToString.ToEntero) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijo").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijoSIG").ToString.ToEntero - End If - End If - - If importeMovimiento <> 0 Then - 'Conta ContPAQ - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 49))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - 'Conta SIG - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 49))("ConceptoContable").ToString) - CveCuentaContabilizacion = 0 - End If - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Row2("CodAF").ToString, 49, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveActivoFijo:=Row2("CveActivoFijo").ToString.ToEntero, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - End If - Next - End If - - 'LIMPIA - importeMovimiento = 0 - IdCtaContable = 0 - CveCuenta = 0 - - 'COSTO ALMACEN - Dim DtAlmacenes = GlobalDTAlmacen(UsuarioActual.CveEmpresa) - If UsuarioActual.Empresa.UsaInventarios AndAlso Not UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - DT = TmpDT.FiltraParametros("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) > 0", "", {"CveAlmacen"}) - 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN - For Each Dr As DataRow In DT.Rows - If DtAlmacenes.FiltroPrimeroValor("Modalidad", $"CveAlmacen = {Dr("CveAlmacen").ToString.ToEntero}").ToString = "Solo Existencia" Then - Dr("CveAlmacen") = 0 - End If - Dr.AcceptChanges() - Next - DT.AcceptChanges() - DT = DT.FiltraParametros("ISNULL(CveAlmacen,0) > 0") - If DT.Rows.Count > 0 AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then - For Each Row2 As DataRow In DT.Rows - - importeMovimiento = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), $"CveAlmacen = {Row2("CveAlmacen")}").ToString.ToDecimal + TmpDT.SUM("CostoIndirectoAlmacen", $"CveAlmacen = {Row2("CveAlmacen")}").ToString.ToDecimal 'Row2("Total").ToString.ToDecimal + Row2("CostoIndirectoAlmacen").ToString.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - If ObjConta.GetRetCuenta(68, GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContableSIG").ToString.ToEntero - End If - End If - If importeMovimiento <> 0 Then - 'Conta ContPAQ - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - 'Conta SIG - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) - CveCuentaContabilizacion = 0 - End If - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 68, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveMovimientoAlmacen:=CveMovimientoInventario, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - End If - Next - End If - End If - - 'LIMPIA - importeMovimiento = 0 - IdCtaContable = 0 - CveCuenta = 0 - - ''FLETES - 'If UsuarioActual.CveEmpresa.Contiene(119) And UsuarioActual.Empresa.UsaInventarios And DdlTipoComprobante.SelectedValue <> "NC" And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And CveConceptoContableAlmacen.Contiene(237, 240) Then - - 'End If - Dim CostoIndirectoAcum176 As Decimal = 0 - 'INV [MERCANCIA RECIBIDA POR ADELANTADO (OC) | MERCANCIA PENDIENTE POR RECIBIR (COMPRA) ] - If AgregaMercanciaInventario AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") AndAlso CveConceptoContableAlmacen.Contiene(205, 176, 237, 240) Then - - importeMovimiento = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), $"ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND (ISNULL(CveTipoPS,0) = 2 OR (ISNULL(CveTipoPS,0) = 1 AND ISNULL(AplicaCostoIndirecto,0) = 1))").ToString.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - - Dim ConceptoContabilizacion = 205 - Dim ConceptoContabilizacionME = -1 - Dim IdCtaContableME = -1 - Dim ConceptoContabilizacionMEComp = -1 - Dim IdCtaContableMEComp = -1 - - If OCVinculada Or CveConceptoContableAlmacen.Contiene(237, 240) Then - ConceptoContabilizacion = CveConceptoContableAlmacen - End If - Dim UsaComplementariaFleteImportaciones As Boolean = False - - Select Case ConceptoContabilizacion - Case 176 - ConceptoContabilizacionME = 228 - ConceptoContabilizacionMEComp = 229 - Case 205 - ConceptoContabilizacionME = 230 - ConceptoContabilizacionMEComp = 231 - Case 237 - ConceptoContabilizacionME = 238 - ConceptoContabilizacionMEComp = 239 - importeMovimiento = TmpDT.SUMD(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")) - importeMN = importeMovimiento * tipoCambioActual * Multiplicador 'TIENE QUE TENER EL IMPORTEMN IGUAL AL IMPORTEMOVIMIENTO PORQUE NO TOMA EN CUENTA SI UN PRODUCTO ES TIPO SERVICIO - Case 240 - ConceptoContabilizacionME = 241 - ConceptoContabilizacionMEComp = 242 - importeMovimiento = TmpDT.SUMD(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")) - importeMN = importeMovimiento * tipoCambioActual * Multiplicador 'TIENE QUE TENER EL IMPORTEMN IGUAL AL IMPORTEMOVIMIENTO PORQUE NO TOMA EN CUENTA SI UN PRODUCTO ES TIPO SERVICIO - End Select - - If ObjConta.GetRetCuenta(ConceptoContabilizacion, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - End If - - If ObjConta.GetRetCuenta(ConceptoContabilizacionME, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableME = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - End If - - If ObjConta.GetRetCuenta(ConceptoContabilizacionMEComp, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableMEComp = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - End If - Dim CveMovimientoAlmacen As Integer = -1 - - 'If importeMovimiento <> 0 Then - Select Case ConceptoContabilizacion - Case 176 - Dim SumatoriaOCINV = 0.0D, Importe176 = 0.0D, ImporteME176 = 0.0D, ImporteMN176 = 0.0D, Importe228 = 0.0D, ImporteME228 = 0.0D, ImporteMN228 = 0.0D, Importe229 = 0.0D, ImporteME229 = 0.0D, ImporteMN229 = 0.0D, ImporteCI176 = 0.0D - For Each Dr As DataRow In TmpDT.FiltraParametros("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND ISNULL(CveTipoPS,0) = 2").Rows - If ObjOC.OrdenesCompraDetalleCostoPP(Dr("CveOrdenCompraDetalle").ToString.ToEntero) AndAlso ObjOC.DtResultados.Rows.Count >= 1 Then - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text} OC: {ObjOC.DtResultados.FiltroPrimeroValor("Folio").ToString} Inv:{ObjOC.DtResultados.FiltroPrimeroValor("FolioAlmacen").ToString}" - Importe176 = ObjOC.DtResultados.FiltroPrimeroValor("Importe176").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteME176 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteME176").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteMN176 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteMN176").ToDecimal * Dr("Cantidad").ToString.ToDecimal - Importe228 = ObjOC.DtResultados.FiltroPrimeroValor("Importe228").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteME228 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteME228").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteMN228 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteMN228").ToDecimal * Dr("Cantidad").ToString.ToDecimal - Importe229 = ObjOC.DtResultados.FiltroPrimeroValor("Importe229").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteME229 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteME229").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteMN229 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteMN229").ToDecimal * Dr("Cantidad").ToString.ToDecimal - ImporteCI176 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteCI176").ToDecimal - CveMovimientoAlmacen = ObjOC.DtResultados.FiltroPrimeroValor("CveMovimientoAlmacen").ToEntero - Dim TCAjuste As Decimal = ObjOC.DtResultados.FiltroPrimeroValor("TipoCambioAjuste").ToDecimal - 'RMF. falta verificar el costo indirecto de la OC - If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then - ImporteCI176 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteCI228").ToDecimal - CostoIndirectoAcum176 += ImporteCI176 - 'se considera costoindirecto, para que la factura tiene en un concepto tipo servicio - SumatoriaOCINV += (Dr(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")).ToString.ToDecimal * tipoCambioActual) - (ImporteMN228 + ImporteMN229 - ImporteCI176) - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, Importe228, Referencia, ConceptoContabilizacionME, Concepto, FechaMovimiento, IdCtaContableME, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=ImporteMN228, ImporteME:=ImporteME228, CveCuenta:=CveCuenta, CveOCDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero, TipoCambio:=TCAjuste, CveMovimientoAlmacen:=CveMovimientoAlmacen, Contabilizable:=SeContabiliza) Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, Importe229, Referencia, ConceptoContabilizacionMEComp, Concepto, FechaMovimiento, IdCtaContableMEComp, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=ImporteMN229, ImporteME:=ImporteME229, CveCuenta:=CveCuenta, CveOCDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero, TipoCambio:=TCAjuste, CveMovimientoAlmacen:=CveMovimientoAlmacen, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - Else - ErrorPrepoliza = True - Exit For - End If - Else - CostoIndirectoAcum176 += ImporteCI176 - 'se considera costoindirecto, para que la factura tiene en un concepto tipo servicio - SumatoriaOCINV += (Dr(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")).ToString.ToDecimal * tipoCambioActual) - (ImporteMN176 - ImporteCI176) - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, Importe176, Referencia, ConceptoContabilizacion, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=ImporteMN176, ImporteME:=ImporteME176, CveCuenta:=CveCuenta, CveOCDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero, CveMovimientoAlmacen:=CveMovimientoAlmacen, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - End If - Else - Alert("Ocurrió un error al procesar la mercancia recibida por adelantado. Por favor comuniquese con asistencia SIG", TipoMensaje.MsgError) - ErrorPrepoliza = True - Exit For - End If - Next - If SumatoriaOCINV.RoundSQL <> 0 Then - ' se abona el costo, cambiamos su naturaleza - SumatoriaOCINV = -SumatoriaOCINV - Dim CveClasificacionCostoOC = TmpDT.FiltroPrimeroValor("CveClasificacion", "ISNULL(TipoAF, 0) <> 2 And ISNULL(CveAlmacen, 0) = 0 And ISNULL(AplicaCostoIndirecto, 0) <> 1 And ISNULL(CveTipoPS, 0) = 2").ToEntero - IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {CveClasificacionCostoOC}").ToString.ToEntero - CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", $"CveClasificacion = {CveClasificacionCostoOC}").ToString.ToEntero - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SumatoriaOCINV, Referencia, 69, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveClasificacion:=CveClasificacionCostoOC, ImporteMX:=SumatoriaOCINV, CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - End If - Case 205, 237, 240 - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - If DdlMoneda.SelectedValue.ToEntero <> 1 AndAlso UsaComplementariaFleteImportaciones Then - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContabilizacionME, Concepto, FechaMovimiento, IdCtaContableME, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMovimiento, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMN - importeMovimiento, Referencia, ConceptoContabilizacionMEComp, Concepto, FechaMovimiento, IdCtaContableMEComp, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN - importeMovimiento, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - Else - ErrorPrepoliza = True - End If - Else - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMN, Referencia, ConceptoContabilizacion, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - End If - End Select - 'End If - - End If - - 'falta el registro de la NC cuando es - Dim RegistroCuentaPuente As Boolean = False - 'NC CON PRODUCTOS - CUENTA PUENTE - If RegistraConcepto225 Then - - importeMovimiento = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), $"ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND ISNULL(CveTipoPS,0) = 2").ToString.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - - Dim ConceptoContabilizacionNC = 225 - - If ObjConta.GetRetCuenta(ConceptoContabilizacionNC, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - End If - End If - - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - - If importeMovimiento > 0 Or TxtTotal.Text.ToDecimal = 0 Then - RegistroCuentaPuente = True - 'Conta ContPAQ - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - 'Conta SIG - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) - CveCuentaContabilizacion = 0 - End If - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContabilizacionNC, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - - End If - - - If UsuarioActual.CveEmpresa.Contiene(119) Then - Dim ContienePSNeteoBonif As Boolean = False - For Each Dr As DataRow In TmpDT.Rows - If Dr("CveClasificacion").ToString.ToEntero.Contiene(20319) Then 'clasificación de Bonificación, no se incluirá en el neteo - ContienePSNeteoBonif = True - Exit For - End If - Next - - If ContienePSNeteoBonif Then - importeMovimiento = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), $"ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1 ").ToString.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - Dim IdCtaContableDescCompra As Integer = UsuarioActual.Empresa.Funcionalidad(405).ToEntero - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, Referencia, 259, Concepto, FechaMovimiento, IdCtaContableDescCompra, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, -importeMovimiento, Referencia, 259, Concepto, FechaMovimiento, IdCtaContableDescCompra, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=-importeMN, ImporteME:=If(tipoCambioActual = 1, 0, -importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - Else - ErrorPrepoliza = True - End If - End If - End If - - + If RBLPago.SelectedValue.ToEntero = 4 Then + Exit Select 'Es credito el concepto 6 se agrega en CASE 17 + End If + + If Not CveCompraRefacturacion > 0 OrElse ChkRefacNC.Checked Then + 'AF TipoAF 2 Es para las compras + DT = TmpDT.FiltraParametros("ISNULL(TipoAF,0) = 2 And ISNULL(AplicaCostoIndirecto,0) <> 1") + If DT.Rows.Count > 0 AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then + For Each Row2 As DataRow In DT.Rows + importeMovimiento = If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, Row2("ImporteSinImpuestos").ToString.ToDecimal, Row2("Total").ToString.ToDecimal) + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + If ObjConta.GetRetCuenta(49, Row2("CveActivoFijo").ToString.ToEntero) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijo").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijoSIG").ToString.ToEntero + End If + End If + + If importeMovimiento <> 0 Then + 'Conta ContPAQ + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 49))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + 'Conta SIG + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 49))("ConceptoContable").ToString) + CveCuentaContabilizacion = 0 + End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Row2("CodAF").ToString, 49, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveActivoFijo:=Row2("CveActivoFijo").ToString.ToEntero, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + End If + Next + End If + + 'LIMPIA + importeMovimiento = 0 + IdCtaContable = 0 + CveCuenta = 0 + + 'COSTO ALMACEN + Dim DtAlmacenes = GlobalDTAlmacen(UsuarioActual.CveEmpresa) + If UsuarioActual.Empresa.UsaInventarios AndAlso Not UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + DT = TmpDT.FiltraParametros("ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) > 0", "", {"CveAlmacen"}) + 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN + For Each Dr As DataRow In DT.Rows + If DtAlmacenes.FiltroPrimeroValor("Modalidad", $"CveAlmacen = {Dr("CveAlmacen").ToString.ToEntero}").ToString = "Solo Existencia" Then + Dr("CveAlmacen") = 0 + End If + Dr.AcceptChanges() + Next + DT.AcceptChanges() + DT = DT.FiltraParametros("ISNULL(CveAlmacen,0) > 0") + If DT.Rows.Count > 0 AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then + For Each Row2 As DataRow In DT.Rows + + importeMovimiento = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), $"CveAlmacen = {Row2("CveAlmacen")}").ToString.ToDecimal + TmpDT.SUM("CostoIndirectoAlmacen", $"CveAlmacen = {Row2("CveAlmacen")}").ToString.ToDecimal 'Row2("Total").ToString.ToDecimal + Row2("CostoIndirectoAlmacen").ToString.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + If ObjConta.GetRetCuenta(68, GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContableSIG").ToString.ToEntero + End If + End If + If importeMovimiento <> 0 Then + 'Conta ContPAQ + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + 'Conta SIG + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) + CveCuentaContabilizacion = 0 + End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 68, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveMovimientoAlmacen:=CveMovimientoInventario, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + End If + Next + End If + End If + + 'LIMPIA + importeMovimiento = 0 + IdCtaContable = 0 + CveCuenta = 0 + + ''FLETES + 'If UsuarioActual.CveEmpresa.Contiene(119) And UsuarioActual.Empresa.UsaInventarios And DdlTipoComprobante.SelectedValue <> "NC" And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And CveConceptoContableAlmacen.Contiene(237, 240) Then + + 'End If + Dim CostoIndirectoAcum176 As Decimal = 0 + 'INV [MERCANCIA RECIBIDA POR ADELANTADO (OC) | MERCANCIA PENDIENTE POR RECIBIR (COMPRA) ] + If AgregaMercanciaInventario AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") AndAlso CveConceptoContableAlmacen.Contiene(205, 176, 237, 240) Then + + importeMovimiento = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), $"ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) = 0 And (ISNULL(CveTipoPS,0) = 2 Or (ISNULL(CveTipoPS,0) = 1 And ISNULL(AplicaCostoIndirecto,0) = 1))").ToString.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + + Dim ConceptoContabilizacion = 205 + Dim ConceptoContabilizacionME = -1 + Dim IdCtaContableME = -1 + Dim ConceptoContabilizacionMEComp = -1 + Dim IdCtaContableMEComp = -1 + + If OCVinculada Or CveConceptoContableAlmacen.Contiene(237, 240) Then + ConceptoContabilizacion = CveConceptoContableAlmacen + End If + Dim UsaComplementariaFleteImportaciones As Boolean = False + + Select Case ConceptoContabilizacion + Case 176 + ConceptoContabilizacionME = 228 + ConceptoContabilizacionMEComp = 229 + Case 205 + ConceptoContabilizacionME = 230 + ConceptoContabilizacionMEComp = 231 + Case 237 + ConceptoContabilizacionME = 238 + ConceptoContabilizacionMEComp = 239 + importeMovimiento = TmpDT.SUMD(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")) + importeMN = importeMovimiento * tipoCambioActual * Multiplicador 'TIENE QUE TENER EL IMPORTEMN IGUAL AL IMPORTEMOVIMIENTO PORQUE NO TOMA EN CUENTA SI UN PRODUCTO ES TIPO SERVICIO + Case 240 + ConceptoContabilizacionME = 241 + ConceptoContabilizacionMEComp = 242 + importeMovimiento = TmpDT.SUMD(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")) + importeMN = importeMovimiento * tipoCambioActual * Multiplicador 'TIENE QUE TENER EL IMPORTEMN IGUAL AL IMPORTEMOVIMIENTO PORQUE NO TOMA EN CUENTA SI UN PRODUCTO ES TIPO SERVICIO + End Select + + If ObjConta.GetRetCuenta(ConceptoContabilizacion, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + End If + + If ObjConta.GetRetCuenta(ConceptoContabilizacionME, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableME = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + End If + + If ObjConta.GetRetCuenta(ConceptoContabilizacionMEComp, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableMEComp = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + End If + Dim CveMovimientoAlmacen As Integer = -1 + + 'If importeMovimiento <> 0 Then + Select Case ConceptoContabilizacion + Case 176 + Dim SumatoriaOCINV = 0.0D, Importe176 = 0.0D, ImporteME176 = 0.0D, ImporteMN176 = 0.0D, Importe228 = 0.0D, ImporteME228 = 0.0D, ImporteMN228 = 0.0D, Importe229 = 0.0D, ImporteME229 = 0.0D, ImporteMN229 = 0.0D, ImporteCI176 = 0.0D + For Each Dr As DataRow In TmpDT.FiltraParametros("ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) = 0 And ISNULL(AplicaCostoIndirecto,0) <> 1 And ISNULL(CveTipoPS,0) = 2").Rows + If ObjOC.OrdenesCompraDetalleCostoPP(Dr("CveOrdenCompraDetalle").ToString.ToEntero) AndAlso ObjOC.DtResultados.Rows.Count >= 1 Then + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text} OC {ObjOC.DtResultados.FiltroPrimeroValor("Folio").ToString} Inv{ObjOC.DtResultados.FiltroPrimeroValor("FolioAlmacen").ToString}" + Importe176 = ObjOC.DtResultados.FiltroPrimeroValor("Importe176").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteME176 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteME176").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteMN176 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteMN176").ToDecimal * Dr("Cantidad").ToString.ToDecimal + Importe228 = ObjOC.DtResultados.FiltroPrimeroValor("Importe228").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteME228 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteME228").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteMN228 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteMN228").ToDecimal * Dr("Cantidad").ToString.ToDecimal + Importe229 = ObjOC.DtResultados.FiltroPrimeroValor("Importe229").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteME229 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteME229").ToDecimal * Dr("Cantidad").ToString.ToDecimal : ImporteMN229 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteMN229").ToDecimal * Dr("Cantidad").ToString.ToDecimal + ImporteCI176 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteCI176").ToDecimal + CveMovimientoAlmacen = ObjOC.DtResultados.FiltroPrimeroValor("CveMovimientoAlmacen").ToEntero + Dim TCAjuste As Decimal = ObjOC.DtResultados.FiltroPrimeroValor("TipoCambioAjuste").ToDecimal + 'RMF. falta verificar el costo indirecto de la OC + If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then + ImporteCI176 = ObjOC.DtResultados.FiltroPrimeroValor("ImporteCI228").ToDecimal + CostoIndirectoAcum176 += ImporteCI176 + 'se considera costoindirecto, para que la factura tiene en un concepto tipo servicio + SumatoriaOCINV += (Dr(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")).ToString.ToDecimal * tipoCambioActual) - (ImporteMN228 + ImporteMN229 - ImporteCI176) + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, Importe228, Referencia, ConceptoContabilizacionME, Concepto, FechaMovimiento, IdCtaContableME, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=ImporteMN228, ImporteME:=ImporteME228, CveCuenta:=CveCuenta, CveOCDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero, TipoCambio:=TCAjuste, CveMovimientoAlmacen:=CveMovimientoAlmacen, Contabilizable:=SeContabiliza) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, Importe229, Referencia, ConceptoContabilizacionMEComp, Concepto, FechaMovimiento, IdCtaContableMEComp, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=ImporteMN229, ImporteME:=ImporteME229, CveCuenta:=CveCuenta, CveOCDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero, TipoCambio:=TCAjuste, CveMovimientoAlmacen:=CveMovimientoAlmacen, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + Else + ErrorPrepoliza = True + Exit For + End If + Else + CostoIndirectoAcum176 += ImporteCI176 + 'se considera costoindirecto, para que la factura tiene en un concepto tipo servicio + SumatoriaOCINV += (Dr(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")).ToString.ToDecimal * tipoCambioActual) - (ImporteMN176 - ImporteCI176) + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, Importe176, Referencia, ConceptoContabilizacion, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=ImporteMN176, ImporteME:=ImporteME176, CveCuenta:=CveCuenta, CveOCDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero, CveMovimientoAlmacen:=CveMovimientoAlmacen, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + End If + Else + Alert("Ocurrió un error al procesar la mercancia recibida por adelantado. Por favor comuniquese con asistencia SIG", TipoMensaje.MsgError) + ErrorPrepoliza = True + Exit For + End If + Next + If SumatoriaOCINV.RoundSQL <> 0 Then + ' se abona el costo, cambiamos su naturaleza + SumatoriaOCINV = -SumatoriaOCINV + Dim CveClasificacionCostoOC = TmpDT.FiltroPrimeroValor("CveClasificacion", "ISNULL(TipoAF, 0) <> 2 And ISNULL(CveAlmacen, 0) = 0 And ISNULL(AplicaCostoIndirecto, 0) <> 1 And ISNULL(CveTipoPS, 0) = 2").ToEntero + IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {CveClasificacionCostoOC}").ToString.ToEntero + CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", $"CveClasificacion = {CveClasificacionCostoOC}").ToString.ToEntero + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SumatoriaOCINV, Referencia, 69, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveClasificacion:=CveClasificacionCostoOC, ImporteMX:=SumatoriaOCINV, CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + End If + Case 205, 237, 240 + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + If DdlMoneda.SelectedValue.ToEntero <> 1 AndAlso UsaComplementariaFleteImportaciones Then + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContabilizacionME, Concepto, FechaMovimiento, IdCtaContableME, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMovimiento, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMN - importeMovimiento, Referencia, ConceptoContabilizacionMEComp, Concepto, FechaMovimiento, IdCtaContableMEComp, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN - importeMovimiento, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + Else + ErrorPrepoliza = True + End If + Else + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMN, Referencia, ConceptoContabilizacion, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + End If + End Select + 'End If + + End If + + 'falta el registro de la NC cuando es + Dim RegistroCuentaPuente As Boolean = False + 'NC CON PRODUCTOS - CUENTA PUENTE + If RegistraConcepto225 Then + + importeMovimiento = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), $"ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) = 0 And ISNULL(AplicaCostoIndirecto,0) <> 1 And ISNULL(CveTipoPS,0) = 2").ToString.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + + Dim ConceptoContabilizacionNC = 225 + + If ObjConta.GetRetCuenta(ConceptoContabilizacionNC, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + End If + End If + + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + + If importeMovimiento > 0 Or TxtTotal.Text.ToDecimal = 0 Then + RegistroCuentaPuente = True + 'Conta ContPAQ + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + 'Conta SIG + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) + CveCuentaContabilizacion = 0 + End If + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContabilizacionNC, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + + End If + + + If UsuarioActual.CveEmpresa.Contiene(119) Then + Dim ContienePSNeteoBonif As Boolean = False + For Each Dr As DataRow In TmpDT.Rows + If Dr("CveClasificacion").ToString.ToEntero.Contiene(20319) Then 'clasificación de Bonificación, no se incluirá en el neteo + ContienePSNeteoBonif = True + Exit For + End If + Next + + If ContienePSNeteoBonif Then + importeMovimiento = TmpDT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), $"ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) = 0 And ISNULL(AplicaCostoIndirecto,0) <> 1 ").ToString.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + Dim IdCtaContableDescCompra As Integer = UsuarioActual.Empresa.Funcionalidad(405).ToEntero + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, Referencia, 259, Concepto, FechaMovimiento, IdCtaContableDescCompra, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, -importeMovimiento, Referencia, 259, Concepto, FechaMovimiento, IdCtaContableDescCompra, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=-importeMN, ImporteME:=If(tipoCambioActual = 1, 0, -importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + Else + ErrorPrepoliza = True + End If + End If + End If + + End If ' adfasdasd 'ChkNCInvNC - If Not RegistroCuentaPuente AndAlso Not ChkNCInvNC.Checked Then - 'GASTO - If UsuarioActual.CveEmpresa = 119 Then - DT = TmpDT - Else - DT = TmpDT.FiltraParametros("ISNULL(AplicaCostoIndirecto,0) <> 1") - End If - 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN - For Each Dr As DataRow In DT.Rows - If DtAlmacenes.FiltroPrimeroValor("Modalidad", $"CveAlmacen = {Dr("CveAlmacen").ToString.ToEntero}").ToString = "Solo Existencia" Then - Dr("CveAlmacen") = 0 - End If - Dr.AcceptChanges() - Next - DT.AcceptChanges() - DtAlmacenes.Dispose() - - 'QUITA 1-[MERCANCIA RECIBIDA POR ADELANTADO (OC) | MERCANCIA PENDIENTE POR RECIBIR (COMPRA)] 2-[NC CON PRODUCTOS] - If AgregaMercanciaInventario Then - DT = DT.FiltraParametros("ISNULL(CveTipoPS,0) <> 2") - End If - - Dim DTDistinct = DT.Copy - If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - DTDistinct = DTDistinct.FiltraParametros("ISNULL(TipoAF, 0) <> 2", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveSubProyecto", "CveTipoGasto", "TipoGasto"}) - Else - DTDistinct = DTDistinct.FiltraParametros("ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) = 0 And ISNULL(AplicaCostoIndirecto,0) <> 1", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveSubProyecto", "CveTipoGasto", "TipoGasto"}) - End If - 'RMF, si es concepto relacionado a flete o importacion, no debe de afectar al gasto - If CveFlete > 0 OrElse CveImportacion > 0 Then - DTDistinct.Clear() - End If - - If DTDistinct.Rows.Count > 0 Then - For Each Row2 As DataRow In DTDistinct.Rows - - 'DETERMINA IMPORTE - If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - importeMovimiento = DT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), String.Format("ISNULL(TipoAF,0) <> 2 And CveClasificacion = {0} And CveSubProyecto = {1} And ISNULL(CveTipoGasto,0) = {2}", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal - Else - importeMovimiento = DT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), String.Format("ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) = 0 And ISNULL(AplicaCostoIndirecto,0) <> 1 And CveClasificacion = {0} And CveSubProyecto = {1} And ISNULL(CveTipoGasto,0) = {2}", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal - End If - 'se debe de restar el costo indirecto, si se recibió por OC sobre el importe del gasto, por si ya está incuido - importeMovimiento = importeMovimiento - CostoIndirectoAcum176 - - importeMN = importeMovimiento * tipoCambioActual * Multiplicador '[IPP] EL 6 DEBE SER POSITIVO 27/AGOSTO/2018 - - 'CLASIFICACION - If Row2("CveClasificacion").ToString.ToEntero > 0 Then - If ObjConta.GetRetCuenta(6, Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero) Then - If ObjConta.DtResultados.Rows.Count > 0 AndAlso ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero - Else - IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGasto", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero - CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero - End If - End If - End If - - 'SEGMENTO DE NEGOCIO - Dim IdSegmentoNegocio As Integer = -1 - Dim drT As DataRow = GlobalDTSubProyectos(-1, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero).FiltroPrimero(String.Format("CveSubProyecto = {0} ", Row2("CveSubProyecto").ToString.ToEntero)) - If drT IsNot Nothing Then - IdSegmentoNegocio = drT("IdSegNeg").ToString.ToEntero - End If - - 'AGREGA MOVIMIENTO - If importeMovimiento.RoundSQL <> 0 Then - 'Conta ContPAQ - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - 'Conta SIG - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) - CveCuentaContabilizacion = 0 - End If - - Dim tcvecon As Integer = 6 - Dim tidctacon As Integer = 6 - tidctacon = IdCtaContable - If DdlTipoComprobante.SelectedValue = "Ant" Then - tcvecon = 264 - tidctacon = ViewState("CtaProveedorAnticipos").ToString.ToEntero - If DdlMoneda.SelectedValue = "2" Then - tidctacon = ViewState("CtaProveedorAnticiposExtranjera").ToString.ToEntero - End If - End If - - Dim usacomplementariaProveedor As Boolean = False - usacomplementariaProveedor = If(tipoCambioActual > 1 AndAlso UsuarioActual.CveEmpresa.Contiene(1, 119), True, False) - - If usacomplementariaProveedor AndAlso DdlTipoComprobante.SelectedValue = "Ant" Then - 'importeMovimiento - - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - importeMN = tipoCambioActual * importeMovimiento - importeMovimiento - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 266, Concepto, FechaMovimiento, tidctacon, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, CveTipoGasto:=Row2("CveTipoGasto").ToString.ToEntero, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - importeMN = importeMovimiento - End If - - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, tcvecon, Concepto, FechaMovimiento, tidctacon, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, CveTipoGasto:=Row2("CveTipoGasto").ToString.ToEntero, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - - - - - - End If - - Next - End If - End If - - - 'LIMPIA - importeMovimiento = 0 - IdCtaContable = 0 - CveCuenta = 0 - End If + If Not RegistroCuentaPuente AndAlso Not ChkNCInvNC.Checked Then + 'GASTO + If UsuarioActual.CveEmpresa = 119 Then + DT = TmpDT + Else + DT = TmpDT.FiltraParametros("ISNULL(AplicaCostoIndirecto,0) <> 1") + End If + 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN + For Each Dr As DataRow In DT.Rows + If DtAlmacenes.FiltroPrimeroValor("Modalidad", $"CveAlmacen = {Dr("CveAlmacen").ToString.ToEntero}").ToString = "Solo Existencia" Then + Dr("CveAlmacen") = 0 + End If + Dr.AcceptChanges() + Next + DT.AcceptChanges() + DtAlmacenes.Dispose() + + 'QUITA 1-[MERCANCIA RECIBIDA POR ADELANTADO (OC) | MERCANCIA PENDIENTE POR RECIBIR (COMPRA)] 2-[NC CON PRODUCTOS] + If AgregaMercanciaInventario Then + DT = DT.FiltraParametros("ISNULL(CveTipoPS,0) <> 2") + End If + + Dim DTDistinct = DT.Copy + If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + DTDistinct = DTDistinct.FiltraParametros("ISNULL(TipoAF, 0) <> 2", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveSubProyecto", "CveTipoGasto", "TipoGasto"}) + Else + DTDistinct = DTDistinct.FiltraParametros("ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) = 0 And ISNULL(AplicaCostoIndirecto,0) <> 1", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveSubProyecto", "CveTipoGasto", "TipoGasto"}) + End If + 'RMF, si es concepto relacionado a flete o importacion, no debe de afectar al gasto + If CveFlete > 0 OrElse CveImportacion > 0 Then + DTDistinct.Clear() + End If + + If DTDistinct.Rows.Count > 0 Then + For Each Row2 As DataRow In DTDistinct.Rows + + 'DETERMINA IMPORTE + If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + importeMovimiento = DT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), String.Format("ISNULL(TipoAF,0) <> 2 And CveClasificacion = {0} And CveSubProyecto = {1} And ISNULL(CveTipoGasto,0) = {2}", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal + Else + importeMovimiento = DT.SUM(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total"), String.Format("ISNULL(TipoAF,0) <> 2 And ISNULL(CveAlmacen,0) = 0 And ISNULL(AplicaCostoIndirecto,0) <> 1 And CveClasificacion = {0} And CveSubProyecto = {1} And ISNULL(CveTipoGasto,0) = {2}", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal + End If + 'se debe de restar el costo indirecto, si se recibió por OC sobre el importe del gasto, por si ya está incuido + importeMovimiento = importeMovimiento - CostoIndirectoAcum176 + + importeMN = importeMovimiento * tipoCambioActual * Multiplicador '[IPP] EL 6 DEBE SER POSITIVO 27/AGOSTO/2018 + + 'CLASIFICACION + If Row2("CveClasificacion").ToString.ToEntero > 0 Then + If ObjConta.GetRetCuenta(6, Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero) Then + If ObjConta.DtResultados.Rows.Count > 0 AndAlso ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero + Else + IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGasto", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero + CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero + End If + End If + End If + + 'SEGMENTO DE NEGOCIO + Dim IdSegmentoNegocio As Integer = -1 + Dim drT As DataRow = GlobalDTSubProyectos(-1, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero).FiltroPrimero(String.Format("CveSubProyecto = {0} ", Row2("CveSubProyecto").ToString.ToEntero)) + If drT IsNot Nothing Then + IdSegmentoNegocio = drT("IdSegNeg").ToString.ToEntero + End If + + 'AGREGA MOVIMIENTO + If importeMovimiento.RoundSQL <> 0 Then + 'Conta ContPAQ + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + 'Conta SIG + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) + CveCuentaContabilizacion = 0 + End If + + Dim tcvecon As Integer = 6 + Dim tidctacon As Integer = 6 + tidctacon = IdCtaContable + If DdlTipoComprobante.SelectedValue = "Ant" Then + tcvecon = 264 + tidctacon = ViewState("CtaProveedorAnticipos").ToString.ToEntero + If DdlMoneda.SelectedValue = "2" Then + tidctacon = ViewState("CtaProveedorAnticiposExtranjera").ToString.ToEntero + End If + End If + + Dim usacomplementariaProveedor As Boolean = False + usacomplementariaProveedor = If(tipoCambioActual > 1 AndAlso UsuarioActual.CveEmpresa.Contiene(1, 119), True, False) + + If usacomplementariaProveedor AndAlso DdlTipoComprobante.SelectedValue = "Ant" Then + 'importeMovimiento + + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + importeMN = tipoCambioActual * importeMovimiento - importeMovimiento + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 266, Concepto, FechaMovimiento, tidctacon, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, CveTipoGasto:=Row2("CveTipoGasto").ToString.ToEntero, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + importeMN = importeMovimiento + End If + + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, tcvecon, Concepto, FechaMovimiento, tidctacon, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, CveTipoGasto:=Row2("CveTipoGasto").ToString.ToEntero, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + + + + + + End If + + Next + End If + End If + + + 'LIMPIA + importeMovimiento = 0 + IdCtaContable = 0 + CveCuenta = 0 + End If Case 5 'Proveedores - If CveTipoConcepto = 2 Then ConceptoContable = 305 'cuando es acreedor - If Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - - importeMovimiento = importeProv - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - Dim CveConceptoComplementario As Integer = 201 - If CveTipoConcepto = 2 Then CveConceptoComplementario = 310 + If CveTipoConcepto = 2 Then ConceptoContable = 305 'cuando es acreedor + If tipoCambioActual <> 1 Then + Select Case ConceptoContable + Case 5 + ConceptoContable = 311 + Case 305 + ConceptoContable = 306 + Case Else + End Select + End If + + If Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + + importeMovimiento = importeProv + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + Dim CveConceptoContableComplementaria As Integer = 201 + If CveTipoConcepto = 2 Then CveConceptoContableComplementaria = 307 If tipoCambioActual = 1 Then IdCtaContable = CtaProveedor @@ -6674,7 +6722,7 @@ Partial Class Compras_Compras CveCuenta = CveCuentaProveedorComplementaria If importeMovimiento <> 0 AndAlso (IdCtaContable > 0 Or CveCuenta > 0 Or UsuarioActual.CveEmpresa = 119) Then 'Cuando tiene complementaria lo dividimos en dos Then importeMN = importeMovimiento - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, Referencia, CveConceptoComplementario, Concepto, FechaMovimiento, IdCtaContable, -1, CveIE, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMovimiento * tipoCambioActual - importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, Referencia, CveConceptoContableComplementaria, Concepto, FechaMovimiento, IdCtaContable, -1, CveIE, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMovimiento * tipoCambioActual - importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then ErrorPrepoliza = True End If End If @@ -6684,534 +6732,560 @@ Partial Class Compras_Compras End If - Case 59 'Documentos - importeMovimiento = importeCreditos - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - If ObjConta.GetRetCuenta(ConceptoContable, CveProveedor) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContableSIG").ToString.ToEntero - End If - End If - End If - - Case 37 'Deudores - If RBLTipoDeudor.SelectedValue.ToEntero = 1 Then - For Each rw As GridViewRow In GvDeudores.Rows - If rw.FCCheckBox("Chk").Checked Then - importeMovimiento = rw.FCTextBox("TxtSaldoDeudor").Text.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - IdCtaContable = CtaProveedorDeudores - CveCuenta = CveCuentaProveedorDeudores - - 'Conta ContPAQ - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - 'Conta SIG - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) - CveCuentaContabilizacion = 0 - End If - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=rw.DataKey("CveIE").ToString.ToEntero, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - End If - Next - Else - For Each rw As GridViewRow In GvDeudores.Rows - If rw.FCCheckBox("Chk").Checked Then - importeMovimiento = rw.FCTextBox("TxtSaldoDeudor").Text.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - IdCtaContable = CtaProveedorDeudores - CveCuenta = CveCuentaProveedorDeudores - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 254, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveIE:=rw.DataKey("CveIE").ToString.ToEntero, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - End If - Next - End If - - importeMovimiento = 0 - - Case 41 'Acreedores - importeMovimiento = importeAcreedores - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - - IdCtaContable = CtaProveedorAcreedores - CveCuenta = CveCuentaProveedorAcreedores - - Case 42 'Acreedores - importeMovimiento = importeAcreedoresTarjeta - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - IdCtaContable = CtaProveedorAcreedores - CveCuenta = CveCuentaProveedorAcreedores - - Case 18 'NC - Notas de Credito - importeMovimiento = importeNC - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - If tipoCambioActual > 1 Then Concepto += $" TC:{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" - IdCtaContable = CtaProveedor - CveCuenta = CveCuentaProveedor - If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then - IdCtaContable = CtaProveedorExtranjera - CveCuenta = CveCuentaProveedorExtranjera - End If - - If importeMovimiento <> 0 Then - GuardoConcepto18 = True - If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then - - 'PROVISION - IdCtaContable = CtaProveedorExtranjera - CveCuenta = CveCuentaProveedorExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - IdCtaContable = CtaProveedorComplementaria - CveCuenta = CveCuentaProveedorComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMN - importeMovimiento, Referencia, 234, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN - importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then - ErrorPrepoliza = True - Exit Select - End If - Else - ErrorPrepoliza = True - Exit Select - End If - - 'AMORTIZACIÓN EN EL REGISTRO - For Each Gvr As GridViewRow In GvFacturaNC.Rows - If Gvr.FCCheckBox("ChkFacturaNC").Checked Then - Dim CvePrePolizaTemp = ObjConta.AddPrePolizas("Compras/Registrar-NC", If(EsContado And CvePlantillaPrePoliza = 1, 2, CvePlantillaPrePoliza), ImporteCompra, TxtTotal.Text.ToDouble, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, FolioFijo:=FolioFijo, ReglaFolioPoliza:=ObjCompras.ObtenerReglaFolio(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa), CveTipoPoliza:=ObjConta.ObtenerTipoPoliza(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa)) - Dim importeMovimientoNC = Gvr.FCTextBox("TxtImporte").Text.ToDecimal - Dim TipoCambioFactura = Gvr.DataKey("TipoCambio").ToDecimal - Dim importeMNNC = importeMovimientoNC * TipoCambioFactura * Multiplicador - - IdCtaContable = CtaProveedorExtranjera - CveCuenta = CveCuentaProveedorExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, False, importeMovimientoNC, Referencia, 272, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioFactura, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, CveCompraAmortizacion:=CveCompra) Then - IdCtaContable = CtaProveedorComplementaria - CveCuenta = CveCuentaProveedorComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, False, importeMNNC - importeMovimientoNC, Referencia, 206, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioFactura, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, CveCompraAmortizacion:=CveCompra) Then - ErrorPrepoliza = True - Exit For - End If - Else - ErrorPrepoliza = True - Exit For - End If - - - importeMNNC = importeMovimientoNC * tipoCambioActual * Multiplicador - IdCtaContable = CtaProveedorExtranjera - CveCuenta = CveCuentaProveedorExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, True, importeMovimientoNC, Referencia, 60, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - IdCtaContable = CtaProveedorComplementaria - CveCuenta = CveCuentaProveedorComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, True, importeMNNC - importeMovimientoNC, Referencia, 235, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - Else - ErrorPrepoliza = True - Exit For - Exit For - End If - - ' FLUCTUACION CAMBIARIA - If tipoCambioActual <> TipoCambioFactura Then - importeMovimiento = (importeMovimientoNC * TipoCambioFactura) - (importeMovimientoNC * tipoCambioActual) - - If importeMovimiento > 0 Then - ConceptoContable = 64 - TipoMovimiento = True - IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria - ElseIf importeMovimiento < 0 Then - ConceptoContable = 65 - TipoMovimiento = False - IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria - End If - - importeMovimiento = importeMovimiento.Abs.RoundSQL() - importeMN = importeMovimiento - If importeMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, TipoMovimiento, importeMovimiento, Concepto, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - End If - End If - - - ObjConta.PrePolizaUnificacion(CvePrePoliza, CvePrePolizaTemp) - End If - Next - - If ErrorPrepoliza Then - Exit Select - End If - - Else - IdCtaContable = CtaProveedor - CveCuenta = CveCuentaProveedor - - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - For Each Gvr As GridViewRow In GvFacturaNC.Rows - If Gvr.FCCheckBox("ChkFacturaNC").Checked Then - Dim CvePrePolizaTemp = ObjConta.AddPrePolizas("Compras/Registrar", If(EsContado And CvePlantillaPrePoliza = 1, 2, CvePlantillaPrePoliza), ImporteCompra, TxtTotal.Text.ToDouble, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, FolioFijo:=FolioFijo, ReglaFolioPoliza:=ObjCompras.ObtenerReglaFolio(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa), CveTipoPoliza:=ObjConta.ObtenerTipoPoliza(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa)) - Dim importeMovimientoNC = Gvr.FCTextBox("TxtImporte").Text.ToDecimal - Dim importeMNNC = importeMovimientoNC * tipoCambioActual * Multiplicador - If ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, False, importeMovimientoNC, Referencia, 272, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimientoNC), CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, True, importeMovimientoNC, Referencia, 60, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimientoNC), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - Else - ErrorPrepoliza = True - End If - ObjConta.PrePolizaUnificacion(CvePrePoliza, CvePrePolizaTemp) - End If - Next - End If - End If - End If - - importeMovimiento = 0 - - Case 29 'Funcionarios y Empleados - importeMovimiento = importeFE - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - If ObjConta.GetRetCuenta(ConceptoContable, CvePersonal) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContPersonal").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContPersonalSIG").ToString.ToEntero - End If - End If - - Case 21 'Anticipo - - If ArrAnticipos.Count > 0 Then - - - Dim CtaIvaxAcreditar As Integer = 0 - Dim CtaIvaAcreditable As Integer = 0 - Dim CveCuentaIvaxAcreditar As Integer = 0 - Dim PorcentajeImpuestoAnticipo = PorcentajeIVA - CtaIvaxAcreditar = If(IdCtaIVAXAcreditar > 0, IdCtaIVAXAcreditar, 0) - CtaIvaAcreditable = If(IdCtaIVAAcreditable > 0, IdCtaIVAAcreditable, 0) - If ObjConta.GetRetCuenta(14, UsuarioActual.CveEmpresa) And Not CtaIvaxAcreditar > 0 Then - If ObjConta.DtResultados.Rows.Count > 0 Then - CtaIvaxAcreditar = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditar").ToString.ToEntero - CveCuentaIvaxAcreditar = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditarSIG").ToString.ToEntero - End If - End If - If ObjConta.GetRetCuenta(19, UsuarioActual.CveEmpresa) And Not CtaIvaAcreditable > 0 Then - If ObjConta.DtResultados.Rows.Count > 0 Then - CtaIvaAcreditable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditable").ToString.ToEntero - End If - End If - - '** PRUEBA CUANDO SE AMORTIZA NC ANTES DE QUE SE REGISTRE NO DEBE TENER CONCEPTO 19 ** JMURUAM 01/06/2017 SE HIZO ESTO PARA LA FACTURA HRFA-8012831 DE VIGILANCIA - 'Dim CtaIvaAcreditable As Integer = 0 - 'If ObjConta.GetRetCuenta(19, UsuarioActual.CveEmpresa) Then - ' If ObjConta.DtResultados.Rows.Count > 0 Then - ' CtaIvaAcreditable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditable").ToString.ToEntero - ' End If - 'End If - - For Each Ant As Compras_Compras.Anticipos In ArrAnticipos - - Dim ConceptoContableAnticipo, ConceptoContableAnticipoComplementaria As Integer - Dim CveCompraNC As Integer = CveCompra - - Select Case Ant.TipoMovto - Case "NC", "DEV" - ConceptoContableAnticipo = 60 - ConceptoContableAnticipoComplementaria = 235 - CveCompraNC = Ant.CveCompra 'cuando es NC, se utiliza la clave de compra de la nota de credito - IdCtaContable = CtaProveedor - CveCuenta = CveCuentaProveedor - Case "Egsc" - ConceptoContableAnticipo = 21 - IdCtaContable = CtaProveedorAnticipos - CveCuenta = CveCuentaProveedorAnticipos - - Case "DD" - ConceptoContableAnticipo = 37 - IdCtaContable = CtaProveedorDeudores - CveCuenta = CveCuentaProveedorDeudores - Case "Ant" - ConceptoContableAnticipo = 265 - ConceptoContableAnticipoComplementaria = 266 - CveCompraNC = Ant.CveCompra - IdCtaContable = CtaProveedorAnticipos - CveCuenta = CveCuentaProveedorAnticipos - End Select - - importeMovimiento = Ant.Importe - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - - If importeMovimiento <> 0 Then - 'Conta ContPAQ - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - 'Conta SIG - If CveCuenta = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - - 'AMORTIZACIÓN NC ESPECIAL COMPLEMENTARIA - If ConceptoContableAnticipo.Contiene(60) And DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then - Dim importeMovimientoNC = Ant.Importe - Dim importeMNNC = 0.0D - Dim TipoCambioNC = Ant.TCCompra - - importeMNNC = importeMovimientoNC * TipoCambioNC * Multiplicador - IdCtaContable = CtaProveedorExtranjera - CveCuenta = CveCuentaProveedorExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimientoNC, Referencia, 60, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Ant.CveCompra, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioNC, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - IdCtaContable = CtaProveedorComplementaria - CveCuenta = CveCuentaProveedorComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMNNC - importeMovimientoNC, Referencia, 235, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Ant.CveCompra, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioNC, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - Else - ErrorPrepoliza = True - Exit For - End If - - importeMNNC = importeMovimientoNC * tipoCambioActual * Multiplicador - IdCtaContable = CtaProveedorExtranjera - CveCuenta = CveCuentaProveedorExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimientoNC, Referencia, 272, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - IdCtaContable = CtaProveedorComplementaria - CveCuenta = CveCuentaProveedorComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMNNC - importeMovimientoNC, Referencia, 206, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - Else - ErrorPrepoliza = True - Exit For - End If - - ' FLUCTUACION CAMBIARIA - If tipoCambioActual <> TipoCambioNC Then - importeMovimiento = (importeMovimientoNC * tipoCambioActual) - (importeMovimientoNC * TipoCambioNC) - - If importeMovimiento > 0 Then - ConceptoContable = 64 - TipoMovimiento = True - IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria - ElseIf importeMovimiento < 0 Then - ConceptoContable = 65 - TipoMovimiento = False - IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria - End If - - importeMovimiento = importeMovimiento.Abs.RoundSQL() - importeMN = importeMovimiento - If importeMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Concepto, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - End If - End If - - ElseIf ConceptoContableAnticipo.Contiene(265) And DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then - Dim importeMovimientoNC = Ant.Importe - Dim importeMNNC = 0.0D - Dim TipoCambioNC = Ant.TCCompra - - importeMNNC = importeMovimientoNC * TipoCambioNC * Multiplicador - IdCtaContable = CtaProveedorAnticiposExtranjera - CveCuenta = CveCuentaProveedorAnticiposExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimientoNC, Referencia, 265, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Ant.CveCompra, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioNC, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - IdCtaContable = CtaProveedorAnticiposComplementaria - CveCuenta = CveCuentaProveedorAnticiposComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMNNC - importeMovimientoNC, Referencia, 266, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Ant.CveCompra, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioNC, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - Else - ErrorPrepoliza = True - Exit For - End If - - If TxtTotal.Text.ToDouble > 0 AndAlso TieneAnticiposXML = False Then - importeMNNC = importeMovimientoNC * tipoCambioActual * Multiplicador - IdCtaContable = CtaProveedorExtranjera ' CtaProveedorAnticiposExtranjera - CveCuenta = CveCuentaProveedorExtranjera 'CveCuentaProveedorAnticiposExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimientoNC, Referencia, 272, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, CveCompraAmortizacion:=CveCompraNC, Contabilizable:=SeContabiliza) Then - IdCtaContable = CtaProveedorExtranjera 'CtaProveedorAnticiposComplementaria - CveCuenta = CveCuentaProveedorExtranjera 'CveCuentaProveedorAnticiposComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMNNC - importeMovimientoNC, Referencia, 206, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - Else - ErrorPrepoliza = True - Exit For - End If - - If Ant.TipoMovto.Contiene("Ant") Then - Dim PorcentajePagoAnt As Decimal = importeMovimientoNC / If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, TmpDT.SUMD("ImporteConImpuestos"), TxtTotal.Text.ToDecimal) - Dim ImporteIVA As Decimal = Math.Round(PorcentajePagoAnt * TxtIVA.Text.ToDecimal, 2) - - 'Agregamos el 14 - If ImporteIVA > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteIVA, Referencia, 14, Concepto, FechaMovimiento, CtaIvaxAcreditar, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteIVA * tipoCambioActual * Multiplicador, ImporteME:=If(tipoCambioActual = 1, 0, ImporteIVA), CveCuenta:=CveCuentaIvaxAcreditar, PorcentajeImpuesto:=PorcentajeImpuestoAnticipo, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - - 'Agregamos el 19 - If ImporteIVA > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, ImporteIVA, Referencia, 19, Concepto, FechaMovimiento, CtaIvaAcreditable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteIVA * tipoCambioActual * Multiplicador, ImporteME:=If(tipoCambioActual = 1, 0, ImporteIVA), PorcentajeImpuesto:=PorcentajeImpuestoAnticipo, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - - Dim ImporteIEPS As Decimal = Math.Round(PorcentajePagoAnt * TxtIEPS.Text.ToDecimal, 2) - - 'Agregamos el 25 - If ImporteIEPS > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteIEPS, Referencia, 25, Concepto, FechaMovimiento, CtaIvaxAcreditar, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteIVA * tipoCambioActual * Multiplicador, ImporteME:=If(tipoCambioActual = 1, 0, ImporteIVA), CveCuenta:=CveCuentaIvaxAcreditar, PorcentajeImpuesto:=PorcentajeImpuestoAnticipo, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - - 'Agregamos el 26 - If ImporteIEPS > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, ImporteIEPS, Referencia, 26, Concepto, FechaMovimiento, CtaIvaAcreditable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteIVA * tipoCambioActual * Multiplicador, ImporteME:=If(tipoCambioActual = 1, 0, ImporteIVA), PorcentajeImpuesto:=PorcentajeImpuestoAnticipo, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - End If - - - ' FLUCTUACION CAMBIARIA - If tipoCambioActual <> TipoCambioNC Then - importeMovimiento = (importeMovimientoNC * tipoCambioActual) - (importeMovimientoNC * TipoCambioNC) - - If importeMovimiento > 0 Then - ConceptoContable = 64 - TipoMovimiento = True - IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria - ElseIf importeMovimiento < 0 Then - ConceptoContable = 65 - TipoMovimiento = False - IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria - End If - - importeMovimiento = importeMovimiento.Abs.RoundSQL() - importeMN = importeMovimiento - If importeMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Concepto, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - End If - End If - End If - - Else - - - Dim usacomplementariaAnticipo As Boolean = False - usacomplementariaAnticipo = If(Ant.TCCompra > 1 AndAlso UsuarioActual.CveEmpresa.Contiene(1, 119), True, False) - Dim TipoCambioAnt = Ant.TCCompra - - - Dim ImporteAnt As Decimal = importeMovimiento - Dim ImporteAntMN As Decimal = ImporteAnt * TipoCambioAnt - If usacomplementariaAnticipo Then - IdCtaContable = CtaProveedorAnticiposComplementaria - CveCuenta = CveCuentaProveedorAnticiposComplementaria - ImporteAntMN = TipoCambioAnt * ImporteAnt - ImporteAnt - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteAnt, Referencia, 266, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompraNC, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=ImporteAntMN, ImporteME:=ImporteAnt, TipoCambio:=TipoCambioAnt, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - ImporteAntMN = ImporteAnt - End If - - If TipoCambioAnt > 1 Then - IdCtaContable = CtaProveedorAnticiposExtranjera - CveCuenta = CveCuentaProveedorAnticiposExtranjera - End If - - 'Agregamos el 21/37/60 - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteAnt, Referencia, ConceptoContableAnticipo, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompraNC, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteAntMN, ImporteME:=If(tipoCambioActual = 1, 0, ImporteAnt), TipoCambio:=TipoCambioAnt, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - - If TxtTotal.Text.ToDouble > 0 AndAlso TieneAnticiposXML = False Then - Dim IdCtaContablePago As Integer = CtaProveedor - Dim CveCuentaPago As Integer = CveCuentaProveedor - Dim usacomplementariaProveedor As Boolean = False - usacomplementariaProveedor = If(tipoCambioActual > 1 AndAlso UsuarioActual.CveEmpresa.Contiene(1, 119), True, False) - If usacomplementariaProveedor Then - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - importeMN = tipoCambioActual * importeMovimiento - importeMovimiento - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 201, Concepto, FechaMovimiento, CtaProveedorComplementaria, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuentaProveedorComplementaria, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - importeMN = importeMovimiento - End If - - If tipoCambioActual > 1 Then - IdCtaContablePago = CtaProveedorExtranjera - CveCuentaPago = CveCuentaProveedorExtranjera - End If - - 'Agregamos el 17 - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 17, Concepto, FechaMovimiento, IdCtaContablePago, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuentaPago, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - End If - - End If - ' FLUCTUACION CAMBIARIA - If tipoCambioActual <> TipoCambioAnt Then - Dim importeFluctuacion = (ImporteAnt * tipoCambioActual) - (ImporteAnt * TipoCambioAnt) - - If importeFluctuacion > 0 Then - ConceptoContable = 64 - TipoMovimiento = True - IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria - ElseIf importeFluctuacion < 0 Then - ConceptoContable = 65 - TipoMovimiento = False - IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria - End If - - importeFluctuacion = importeFluctuacion.Abs.RoundSQL() - If importeFluctuacion <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeFluctuacion, Concepto, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeFluctuacion, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - End If - End If - - - End If - - - - '** PRUEBA CUANDO SE AMORTIZA NC ANTES DE QUE SE REGISTRE NO DEBE TENER CONCEPTO 19 ** JM 01/06/2017 SE HIZO ESTO PARA LA FACTURA HRFA-8012831 DE VIGILANCIA - '[IPP] NC NO DEBE REGISTRAR IMPUESTOS EN AMORTIZACIÓN 27/Agosto/2018 - If Not Ant.TipoMovto.Contiene("NC", "DEV") Then - Dim PorcentajePagoAnt As Decimal = importeMovimiento / If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, TmpDT.SUMD("ImporteConImpuestos"), TxtTotal.Text.ToDecimal) - Dim ImporteIVA As Decimal = Math.Round(PorcentajePagoAnt * TxtIVA.Text.ToDecimal, 2) - - + Case 59 'Documentos + importeMovimiento = importeCreditos + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + If ObjConta.GetRetCuenta(ConceptoContable, CveProveedor) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContableSIG").ToString.ToEntero + End If + End If + End If + + Case 37 'Deudores + If RBLTipoDeudor.SelectedValue.ToEntero = 1 Then + For Each rw As GridViewRow In GvDeudores.Rows + If rw.FCCheckBox("Chk").Checked Then + importeMovimiento = rw.FCTextBox("TxtSaldoDeudor").Text.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + IdCtaContable = CtaProveedorDeudores + CveCuenta = CveCuentaProveedorDeudores + + 'Conta ContPAQ + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + 'Conta SIG + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) + CveCuentaContabilizacion = 0 + End If + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=rw.DataKey("CveIE").ToString.ToEntero, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + End If + Next + Else + For Each rw As GridViewRow In GvDeudores.Rows + If rw.FCCheckBox("Chk").Checked Then + importeMovimiento = rw.FCTextBox("TxtSaldoDeudor").Text.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + IdCtaContable = CtaProveedorDeudores + CveCuenta = CveCuentaProveedorDeudores + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 254, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveIE:=rw.DataKey("CveIE").ToString.ToEntero, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + End If + Next + End If + + importeMovimiento = 0 + + Case 41 'Acreedores + importeMovimiento = importeAcreedores + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + + IdCtaContable = CtaProveedorAcreedores + CveCuenta = CveCuentaProveedorAcreedores + + Case 42 'Acreedores + importeMovimiento = importeAcreedoresTarjeta + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + IdCtaContable = CtaProveedorAcreedores + CveCuenta = CveCuentaProveedorAcreedores + + Case 18 'NC - Notas de Credito + importeMovimiento = importeNC + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + If tipoCambioActual > 1 Then Concepto += $" TC{tipoCambioActual} ${importeMovimiento.FormatoNumero(2)}" + IdCtaContable = CtaProveedor + CveCuenta = CveCuentaProveedor + If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then + IdCtaContable = CtaProveedorExtranjera + CveCuenta = CveCuentaProveedorExtranjera + End If + + If importeMovimiento <> 0 Then + GuardoConcepto18 = True + If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then + + 'PROVISION + IdCtaContable = CtaProveedorExtranjera + CveCuenta = CveCuentaProveedorExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + IdCtaContable = CtaProveedorComplementaria + CveCuenta = CveCuentaProveedorComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMN - importeMovimiento, Referencia, 234, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN - importeMovimiento, ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, TipoCambio:=tipoCambioActual) Then + ErrorPrepoliza = True + Exit Select + End If + Else + ErrorPrepoliza = True + Exit Select + End If + + 'AMORTIZACIÓN EN EL REGISTRO + For Each Gvr As GridViewRow In GvFacturaNC.Rows + If Gvr.FCCheckBox("ChkFacturaNC").Checked Then + Dim CvePrePolizaTemp = ObjConta.AddPrePolizas("Compras/Registrar-NC", If(EsContado And CvePlantillaPrePoliza = 1, 2, CvePlantillaPrePoliza), ImporteCompra, TxtTotal.Text.ToDouble, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, FolioFijo:=FolioFijo, ReglaFolioPoliza:=ObjCompras.ObtenerReglaFolio(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa), CveTipoPoliza:=ObjConta.ObtenerTipoPoliza(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa)) + Dim importeMovimientoNC = Gvr.FCTextBox("TxtImporte").Text.ToDecimal + Dim TipoCambioFactura = Gvr.DataKey("TipoCambio").ToDecimal + Dim importeMNNC = importeMovimientoNC * TipoCambioFactura * Multiplicador + + IdCtaContable = CtaProveedorExtranjera + CveCuenta = CveCuentaProveedorExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, False, importeMovimientoNC, Referencia, 272, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioFactura, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, CveCompraAmortizacion:=CveCompra) Then + + Dim CveConceptoContableComplementaria As Integer = 206 + If Gvr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoContableComplementaria = 310 'cuando es acreedor + + IdCtaContable = CtaProveedorComplementaria + CveCuenta = CveCuentaProveedorComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, False, importeMNNC - importeMovimientoNC, Referencia, CveConceptoContableComplementaria, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioFactura, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza, CveCompraAmortizacion:=CveCompra) Then + ErrorPrepoliza = True + Exit For + End If + Else + ErrorPrepoliza = True + Exit For + End If + + + importeMNNC = importeMovimientoNC * tipoCambioActual * Multiplicador + IdCtaContable = CtaProveedorExtranjera + CveCuenta = CveCuentaProveedorExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, True, importeMovimientoNC, Referencia, 60, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + IdCtaContable = CtaProveedorComplementaria + CveCuenta = CveCuentaProveedorComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, True, importeMNNC - importeMovimientoNC, Referencia, 235, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + Else + ErrorPrepoliza = True + Exit For + Exit For + End If + + ' FLUCTUACION CAMBIARIA + If tipoCambioActual <> TipoCambioFactura Then + importeMovimiento = (importeMovimientoNC * TipoCambioFactura) - (importeMovimientoNC * tipoCambioActual) + + If importeMovimiento > 0 Then + ConceptoContable = 64 + TipoMovimiento = True + IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria + ElseIf importeMovimiento < 0 Then + ConceptoContable = 65 + TipoMovimiento = False + IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + End If + + importeMovimiento = importeMovimiento.Abs.RoundSQL() + importeMN = importeMovimiento + If importeMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, TipoMovimiento, importeMovimiento, Concepto, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + End If + End If + + + ObjConta.PrePolizaUnificacion(CvePrePoliza, CvePrePolizaTemp) + End If + Next + + If ErrorPrepoliza Then + Exit Select + End If + + Else + IdCtaContable = CtaProveedor + CveCuenta = CveCuentaProveedor + + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + For Each Gvr As GridViewRow In GvFacturaNC.Rows + If Gvr.FCCheckBox("ChkFacturaNC").Checked Then + Dim CvePrePolizaTemp = ObjConta.AddPrePolizas("Compras/Registrar", If(EsContado And CvePlantillaPrePoliza = 1, 2, CvePlantillaPrePoliza), ImporteCompra, TxtTotal.Text.ToDouble, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, FolioFijo:=FolioFijo, ReglaFolioPoliza:=ObjCompras.ObtenerReglaFolio(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa), CveTipoPoliza:=ObjConta.ObtenerTipoPoliza(DdlTipoTransaccion.SelectedValue, DdlTipoTransaccionCaja.SelectedValue, UsuarioActual.CveEmpresa)) + Dim importeMovimientoNC = Gvr.FCTextBox("TxtImporte").Text.ToDecimal + Dim importeMNNC = importeMovimientoNC * tipoCambioActual * Multiplicador + If ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, False, importeMovimientoNC, Referencia, 272, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimientoNC), CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTemp, True, importeMovimientoNC, Referencia, 60, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=Gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimientoNC), CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + Else + ErrorPrepoliza = True + End If + ObjConta.PrePolizaUnificacion(CvePrePoliza, CvePrePolizaTemp) + End If + Next + End If + End If + End If + + importeMovimiento = 0 + + Case 29 'Funcionarios y Empleados + importeMovimiento = importeFE + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + If ObjConta.GetRetCuenta(ConceptoContable, CvePersonal) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContPersonal").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContPersonalSIG").ToString.ToEntero + End If + End If + + Case 21 'Anticipo + + If ArrAnticipos.Count > 0 Then + + + Dim CtaIvaxAcreditar As Integer = 0 + Dim CtaIvaAcreditable As Integer = 0 + Dim CveCuentaIvaxAcreditar As Integer = 0 + Dim PorcentajeImpuestoAnticipo = PorcentajeIVA + CtaIvaxAcreditar = If(IdCtaIVAXAcreditar > 0, IdCtaIVAXAcreditar, 0) + CtaIvaAcreditable = If(IdCtaIVAAcreditable > 0, IdCtaIVAAcreditable, 0) + If ObjConta.GetRetCuenta(14, UsuarioActual.CveEmpresa) And Not CtaIvaxAcreditar > 0 Then + If ObjConta.DtResultados.Rows.Count > 0 Then + CtaIvaxAcreditar = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditar").ToString.ToEntero + CveCuentaIvaxAcreditar = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditarSIG").ToString.ToEntero + End If + End If + If ObjConta.GetRetCuenta(19, UsuarioActual.CveEmpresa) And Not CtaIvaAcreditable > 0 Then + If ObjConta.DtResultados.Rows.Count > 0 Then + CtaIvaAcreditable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditable").ToString.ToEntero + End If + End If + + '** PRUEBA CUANDO SE AMORTIZA NC ANTES DE QUE SE REGISTRE NO DEBE TENER CONCEPTO 19 ** JMURUAM 01/06/2017 SE HIZO ESTO PARA LA FACTURA HRFA-8012831 DE VIGILANCIA + 'Dim CtaIvaAcreditable As Integer = 0 + 'If ObjConta.GetRetCuenta(19, UsuarioActual.CveEmpresa) Then + ' If ObjConta.DtResultados.Rows.Count > 0 Then + ' CtaIvaAcreditable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditable").ToString.ToEntero + ' End If + 'End If + + For Each Ant As Compras_Compras.Anticipos In ArrAnticipos + + Dim ConceptoContableAnticipo, ConceptoContableAnticipoComplementaria As Integer + Dim CveCompraNC As Integer = CveCompra + + Select Case Ant.TipoMovto + Case "NC", "DEV" + ConceptoContableAnticipo = 60 + ConceptoContableAnticipoComplementaria = 235 + CveCompraNC = Ant.CveCompra 'cuando es NC, se utiliza la clave de compra de la nota de credito + IdCtaContable = CtaProveedor + CveCuenta = CveCuentaProveedor + Case "Egsc" + ConceptoContableAnticipo = 21 + IdCtaContable = CtaProveedorAnticipos + CveCuenta = CveCuentaProveedorAnticipos + + Case "DD" + ConceptoContableAnticipo = 37 + IdCtaContable = CtaProveedorDeudores + CveCuenta = CveCuentaProveedorDeudores + Case "Ant" + ConceptoContableAnticipo = 265 + ConceptoContableAnticipoComplementaria = 266 + CveCompraNC = Ant.CveCompra + IdCtaContable = CtaProveedorAnticipos + CveCuenta = CveCuentaProveedorAnticipos + End Select + + importeMovimiento = Ant.Importe + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + + If importeMovimiento <> 0 Then + 'Conta ContPAQ + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + 'Conta SIG + If CveCuenta = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + + 'AMORTIZACIÓN NC ESPECIAL COMPLEMENTARIA + If ConceptoContableAnticipo.Contiene(60) And DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then + Dim importeMovimientoNC = Ant.Importe + Dim importeMNNC = 0.0D + Dim TipoCambioNC = Ant.TCCompra + + importeMNNC = importeMovimientoNC * TipoCambioNC * Multiplicador + IdCtaContable = CtaProveedorExtranjera + CveCuenta = CveCuentaProveedorExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimientoNC, Referencia, 60, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Ant.CveCompra, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioNC, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + IdCtaContable = CtaProveedorComplementaria + CveCuenta = CveCuentaProveedorComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMNNC - importeMovimientoNC, Referencia, 235, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Ant.CveCompra, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioNC, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + Else + ErrorPrepoliza = True + Exit For + End If + + importeMNNC = importeMovimientoNC * tipoCambioActual * Multiplicador + IdCtaContable = CtaProveedorExtranjera + CveCuenta = CveCuentaProveedorExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimientoNC, Referencia, 272, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + + Dim CveConceptoContableComplementaria As Integer = 206 + If CveTipoConcepto = 2 Then CveConceptoContableComplementaria = 310 'cuando es acreedor + + IdCtaContable = CtaProveedorComplementaria + CveCuenta = CveCuentaProveedorComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMNNC - importeMovimientoNC, Referencia, CveConceptoContableComplementaria, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + Else + ErrorPrepoliza = True + Exit For + End If + + ' FLUCTUACION CAMBIARIA + If tipoCambioActual <> TipoCambioNC Then + importeMovimiento = (importeMovimientoNC * tipoCambioActual) - (importeMovimientoNC * TipoCambioNC) + + If importeMovimiento > 0 Then + ConceptoContable = 64 + TipoMovimiento = True + IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria + ElseIf importeMovimiento < 0 Then + ConceptoContable = 65 + TipoMovimiento = False + IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + End If + + importeMovimiento = importeMovimiento.Abs.RoundSQL() + importeMN = importeMovimiento + If importeMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Concepto, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + End If + End If + + ElseIf ConceptoContableAnticipo.Contiene(265) And DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then + Dim importeMovimientoNC = Ant.Importe + Dim importeMNNC = 0.0D + Dim TipoCambioNC = Ant.TCCompra + + importeMNNC = importeMovimientoNC * TipoCambioNC * Multiplicador + IdCtaContable = CtaProveedorAnticiposExtranjera + CveCuenta = CveCuentaProveedorAnticiposExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimientoNC, Referencia, 265, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Ant.CveCompra, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioNC, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + IdCtaContable = CtaProveedorAnticiposComplementaria + CveCuenta = CveCuentaProveedorAnticiposComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMNNC - importeMovimientoNC, Referencia, 266, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=Ant.CveCompra, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=TipoCambioNC, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + Else + ErrorPrepoliza = True + Exit For + End If + + If TxtTotal.Text.ToDouble > 0 AndAlso TieneAnticiposXML = False Then + importeMNNC = importeMovimientoNC * tipoCambioActual * Multiplicador + IdCtaContable = CtaProveedorExtranjera ' CtaProveedorAnticiposExtranjera + CveCuenta = CveCuentaProveedorExtranjera 'CveCuentaProveedorAnticiposExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimientoNC, Referencia, 272, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, CveCompraAmortizacion:=CveCompraNC, Contabilizable:=SeContabiliza) Then + + Dim CveConceptoContableComplementaria As Integer = 206 + If CveTipoConcepto = 2 Then CveConceptoContableComplementaria = 310 'cuando es acreedor + + IdCtaContable = CtaProveedorExtranjera 'CtaProveedorAnticiposComplementaria + CveCuenta = CveCuentaProveedorExtranjera 'CveCuentaProveedorAnticiposComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMNNC - importeMovimientoNC, Referencia, CveConceptoContableComplementaria, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMNNC - importeMovimientoNC, ImporteME:=importeMovimientoNC, TipoCambio:=tipoCambioActual, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + Else + ErrorPrepoliza = True + Exit For + End If + + If Ant.TipoMovto.Contiene("Ant") Then + Dim PorcentajePagoAnt As Decimal = importeMovimientoNC / If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, TmpDT.SUMD("ImporteConImpuestos"), TxtTotal.Text.ToDecimal) + Dim ImporteIVA As Decimal = Math.Round(PorcentajePagoAnt * TxtIVA.Text.ToDecimal, 2) + + 'Agregamos el 14 + If ImporteIVA > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteIVA, Referencia, 14, Concepto, FechaMovimiento, CtaIvaxAcreditar, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteIVA * tipoCambioActual * Multiplicador, ImporteME:=If(tipoCambioActual = 1, 0, ImporteIVA), CveCuenta:=CveCuentaIvaxAcreditar, PorcentajeImpuesto:=PorcentajeImpuestoAnticipo, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + + 'Agregamos el 19 + If ImporteIVA > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, ImporteIVA, Referencia, 19, Concepto, FechaMovimiento, CtaIvaAcreditable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteIVA * tipoCambioActual * Multiplicador, ImporteME:=If(tipoCambioActual = 1, 0, ImporteIVA), PorcentajeImpuesto:=PorcentajeImpuestoAnticipo, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + + Dim ImporteIEPS As Decimal = Math.Round(PorcentajePagoAnt * TxtIEPS.Text.ToDecimal, 2) + + 'Agregamos el 25 + If ImporteIEPS > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteIEPS, Referencia, 25, Concepto, FechaMovimiento, CtaIvaxAcreditar, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteIVA * tipoCambioActual * Multiplicador, ImporteME:=If(tipoCambioActual = 1, 0, ImporteIVA), CveCuenta:=CveCuentaIvaxAcreditar, PorcentajeImpuesto:=PorcentajeImpuestoAnticipo, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + + 'Agregamos el 26 + If ImporteIEPS > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, ImporteIEPS, Referencia, 26, Concepto, FechaMovimiento, CtaIvaAcreditable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteIVA * tipoCambioActual * Multiplicador, ImporteME:=If(tipoCambioActual = 1, 0, ImporteIVA), PorcentajeImpuesto:=PorcentajeImpuestoAnticipo, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + End If + + + ' FLUCTUACION CAMBIARIA + If tipoCambioActual <> TipoCambioNC Then + importeMovimiento = (importeMovimientoNC * tipoCambioActual) - (importeMovimientoNC * TipoCambioNC) + + If importeMovimiento > 0 Then + ConceptoContable = 64 + TipoMovimiento = True + IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria + ElseIf importeMovimiento < 0 Then + ConceptoContable = 65 + TipoMovimiento = False + IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + End If + + importeMovimiento = importeMovimiento.Abs.RoundSQL() + importeMN = importeMovimiento + If importeMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Concepto, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + End If + End If + End If + + Else + + + Dim usacomplementariaAnticipo As Boolean = False + usacomplementariaAnticipo = If(Ant.TCCompra > 1 AndAlso UsuarioActual.CveEmpresa.Contiene(1, 119), True, False) + Dim TipoCambioAnt = Ant.TCCompra + + + Dim ImporteAnt As Decimal = importeMovimiento + Dim ImporteAntMN As Decimal = ImporteAnt * TipoCambioAnt + If usacomplementariaAnticipo Then + IdCtaContable = CtaProveedorAnticiposComplementaria + CveCuenta = CveCuentaProveedorAnticiposComplementaria + ImporteAntMN = TipoCambioAnt * ImporteAnt - ImporteAnt + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteAnt, Referencia, 266, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompraNC, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=ImporteAntMN, ImporteME:=ImporteAnt, TipoCambio:=TipoCambioAnt, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + ImporteAntMN = ImporteAnt + End If + + If TipoCambioAnt > 1 Then + IdCtaContable = CtaProveedorAnticiposExtranjera + CveCuenta = CveCuentaProveedorAnticiposExtranjera + End If + + 'Agregamos el 21/37/60 + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteAnt, Referencia, ConceptoContableAnticipo, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompraNC, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteAntMN, ImporteME:=If(tipoCambioActual = 1, 0, ImporteAnt), TipoCambio:=TipoCambioAnt, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + + If TxtTotal.Text.ToDouble > 0 AndAlso TieneAnticiposXML = False Then + Dim CveConceptoContableComplementaria As Integer = 201 + If CveTipoConcepto = 2 Then CveConceptoContableComplementaria = 307 + Dim IdCtaContablePago As Integer = CtaProveedor + Dim CveCuentaPago As Integer = CveCuentaProveedor + Dim usacomplementariaProveedor As Boolean = False + usacomplementariaProveedor = If(tipoCambioActual > 1 AndAlso UsuarioActual.CveEmpresa.Contiene(1, 119), True, False) + If usacomplementariaProveedor Then + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + importeMN = tipoCambioActual * importeMovimiento - importeMovimiento + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, CveConceptoContableComplementaria, Concepto, FechaMovimiento, CtaProveedorComplementaria, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuentaProveedorComplementaria, TipoCambio:=tipoCambioActual, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + importeMN = importeMovimiento + End If + + If tipoCambioActual > 1 Then + IdCtaContablePago = CtaProveedorExtranjera + CveCuentaPago = CveCuentaProveedorExtranjera + End If + + Dim CveConceptoContablePago As Integer = 17 + If CveTipoConcepto = 2 Then CveConceptoContablePago = 308 'cuando es acreedor + If tipoCambioActual > 1 Then + Select Case CveConceptoContablePago + Case 17 + CveConceptoContablePago = 312 + Case 308 + CveConceptoContablePago = 309 + Case Else + End Select + End If + + 'Agregamos el 17 + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, CveConceptoContablePago, Concepto, FechaMovimiento, IdCtaContablePago, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuentaPago, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + + End If + ' FLUCTUACION CAMBIARIA + If tipoCambioActual <> TipoCambioAnt Then + Dim importeFluctuacion = (ImporteAnt * tipoCambioActual) - (ImporteAnt * TipoCambioAnt) + + If importeFluctuacion > 0 Then + ConceptoContable = 64 + TipoMovimiento = True + IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria + ElseIf importeFluctuacion < 0 Then + ConceptoContable = 65 + TipoMovimiento = False + IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + End If + + importeFluctuacion = importeFluctuacion.Abs.RoundSQL() + If importeFluctuacion <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeFluctuacion, Concepto, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeFluctuacion, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + End If + End If + + + End If + + + + '** PRUEBA CUANDO SE AMORTIZA NC ANTES DE QUE SE REGISTRE NO DEBE TENER CONCEPTO 19 ** JM 01/06/2017 SE HIZO ESTO PARA LA FACTURA HRFA-8012831 DE VIGILANCIA + '[IPP] NC NO DEBE REGISTRAR IMPUESTOS EN AMORTIZACIÓN 27/Agosto/2018 + If Not Ant.TipoMovto.Contiene("NC", "DEV") Then + Dim PorcentajePagoAnt As Decimal = importeMovimiento / If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, TmpDT.SUMD("ImporteConImpuestos"), TxtTotal.Text.ToDecimal) + Dim ImporteIVA As Decimal = Math.Round(PorcentajePagoAnt * TxtIVA.Text.ToDecimal, 2) + + If ImporteIVA <> 0 Then 'Agregamos el 14 If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteIVA, Referencia, 14, Concepto, FechaMovimiento, CtaIvaxAcreditar, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=ImporteIVA * tipoCambioActual * Multiplicador, ImporteME:=If(tipoCambioActual = 1, 0, ImporteIVA), CveCuenta:=CveCuentaIvaxAcreditar, PorcentajeImpuesto:=PorcentajeImpuestoAnticipo, Contabilizable:=SeContabiliza) Then @@ -7224,30 +7298,30 @@ Partial Class Compras_Compras End If End If - End If - - - End If - - ''Unificacion de PrePolizas - 'If UsuarioActual.Empresa.Funcionalidad(219) = "1" Then - ' If Not ObjConta.PrePolizaUnificacion(Ant.CvePrePoliza, CvePrePoliza) Then - ' ErrorPrepoliza = True - ' Alert("No se pudo unificar la prepoliza", TipoMensaje.MsgError) - ' End If - 'End If - - ''Simplificacion de PrePolizas - 'If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then - ' If Not ObjConta.PrePolizaSimplificacion(Ant.CvePrePoliza, UsuarioActual.CveEmpresa) Then - ' ErrorPrepoliza = True - ' Alert("No se pudo simplificar los movimientos", TipoMensaje.MsgError) - ' End If - 'End If - - Next - importeMovimiento = 0 - + End If + + + End If + + ''Unificacion de PrePolizas + 'If UsuarioActual.Empresa.Funcionalidad(219) = "1" Then + ' If Not ObjConta.PrePolizaUnificacion(Ant.CvePrePoliza, CvePrePoliza) Then + ' ErrorPrepoliza = True + ' Alert("No se pudo unificar la prepoliza", TipoMensaje.MsgError) + ' End If + 'End If + + ''Simplificacion de PrePolizas + 'If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then + ' If Not ObjConta.PrePolizaSimplificacion(Ant.CvePrePoliza, UsuarioActual.CveEmpresa) Then + ' ErrorPrepoliza = True + ' Alert("No se pudo simplificar los movimientos", TipoMensaje.MsgError) + ' End If + 'End If + + Next + importeMovimiento = 0 + End If @@ -7261,719 +7335,755 @@ Partial Class Compras_Compras ' End If - End Select - - If ErrorPrepoliza Then - Exit For - End If - - If importeMovimiento <> 0 Or (ConceptoContable.Contiene(5) AndAlso DdlTipoComprobante.SelectedValue.Contiene("Fac", "Ant")) Or (ConceptoContable.Contiene(18) AndAlso DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") AndAlso Not GuardoConcepto18) Then - 'Conta ContPAQ - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - 'COnta SIG - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) - CveCuentaContabilizacion = 0 - End If - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=Math.Round(importeMN, 2, MidpointRounding.AwayFromZero), ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, PorcentajeImpuesto:=PorcentajeImpuesto, Contabilizable:=SeContabiliza) Then - ErrorPrepoliza = True - Exit For - End If - - End If - - Next - - 'EMPIEZA REFACTURACION - If CveCompraRefacturacion > 0 Then - ErrorBitacora = GuardaRefacturacion(ObjCompras, ObjEventos, CvePrePoliza) - If ErrorBitacora Then - Alert("Ocurrió un error al hacer la Refacturación", TipoMensaje.MsgError) - End If - End If - - 'Simplificacion de PrePolizas - If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then - If Not ObjConta.PrePolizaSimplificacion(CvePrePoliza, UsuarioActual.CveEmpresa) Then - ErrorPrepolizaDescuadre = True - End If - End If - - If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, 4) Then - If ObjConta.ValorPolizaDescuadre > 0 Then - GuardaLogAD($"Compras/Compras-Guardar | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") - ErrorPrepolizaDescuadre = True - End If - End If - - 'Conta ContPAQ - If ObjContaAC IsNot Nothing AndAlso Not ErrorPrepoliza AndAlso Not ErrorPrepolizaDescuadre AndAlso UsuarioActual.Empresa.Funcionalidad(200).ToString = "1" Then - If idCuentaContabilizacion > 0 Then - If ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContaAC) Then - ' Alert(alertaContabilizacion, ModExtensiones.TipoMensaje.MsgInformacion) - IdPoliza = ObjConta.ContaIdPoliza - Else - ErrorPrepoliza = True - Alert($"Ocurrio un error al contabilizar {ObjConta.AlertaMensaje}", TipoMensaje.MsgAdvertencia) - End If - Else - Alert(String.Format("No se puede contabilizar la Prepoliza debido a que las siguientes cuentas son inválidas:
{0}", CuentasContablesInvalidas), TipoMensaje.MsgAdvertencia) - ErrorPrepoliza = True - End If - End If - End If - - - - - '' A N T I C I P O S - If UsuarioActual.Empresa.UsaAC Then - If ArrAnticipos.Count > 0 Then - - Dim PorcentajePago As Decimal - Dim ConceptoRenglon As String - - - 'si hay una diferencia entre lo amortizado y el total, se registra la diferencia a proveedores y los ivas por acreditar - If TxtTotal.Text.ToDouble - ImporteAnticipo > 0 Then - PorcentajePago = (TxtTotal.Text.ToDecimal - ImporteAnticipo) / TxtTotal.Text.ToDecimal - ConceptoRenglon = String.Format("GE Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, TxtTotal.Text.ToDouble - ImporteAnticipo, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - ErrorACMEnsaje.Append(" - si hay una diferencia entre lo amortizado y el total, se registra la diferencia a proveedores y los ivas por acreditar ObjContaAC.AddMovimiento") - ErrorAC = True - End If - End If - - 'una vez amortizado, se generan los movimientos presupuestales - If ImporteAnticipo > 0 Then - PorcentajePago = ImporteAnticipo / TxtTotal.Text.ToDecimal - If ObjCompras.GetPresupuestosCompras(CveCompra) AndAlso ObjCompras.DtResultados.Rows.Count > 0 Then - 'DtAC.Merge(ObjConta.DtResultados) - For Each dr As DataRow In ObjCompras.DtResultados.Rows - Total = dr("TotalPresupuesto").ToString.ToDecimal * PorcentajePago - If Total > 0 Then - - 'EJERCIDO - If True Then - ConceptoRenglon = String.Format("GE {0} F:{1}-{2}", DdlProveedor.SelectedItem.Text, TxtSerie.Text, TxtFolio.Text) - If ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaEjercido").ToString.ToEntero, False, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - 'actualizo el idcuenta del presupuesto - If Not ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - TieneError = True - Exit For - End If - Else - TieneError = True - Exit For - End If - End If - - 'PAGADO - ConceptoRenglon = String.Format("GP {0} F:{1}-{2}", DdlProveedor.SelectedItem.Text, TxtSerie.Text, TxtFolio.Text) - If ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaPagado").ToString.ToEntero, False, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - 'actualizo el idcuenta del presupuesto - If Not ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaEjercido").ToString.ToEntero, True, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - TieneError = True - Exit For - End If - Else - TieneError = True - Exit For - End If - - End If - Next - - Else - ErrorACMEnsaje.Append(" - error al obtener presupuestos ObjCompras.GetPresupuestosCompras") - ErrorAC = True - End If - - End If - End If - End If - - - '' F U N C I O N A R I O S Y E M P L E A D O S - If RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then - TxtDocumentoImporte.Text = TxtDocumentoImporteFE.Text - TxtDocumentoImporteCaja.Text = TxtDocumentoImporteFE.Text - - End If - - Else 'Empresa Prueba - - If RBLPago.SelectedValue.ToEntero = 2 AndAlso (RBLContado.SelectedValue = "1" Or RBLContado.SelectedValue = "6") Then 'Contado - Bancos y Caja Chica - 'se agrego un movimiento de pago - ' CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero, TxtFecha.Text.Trim.ToDate, TxtDocumentoFolio.Text.Trim, DdlProveedor.SelectedItem.Text.Trim, TxtDocumentoImporte.Text.Trim.ToDouble, 1, 0.0, TxtDocumentoObservaciones.Text.Trim, True, True, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CveIE > 0 Then - - 'inserto los movimientos de la conta para abonar al saldo - - 'Se agregamovimiento de pago de proveedor - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteCompra, " ", CveConceptoAfectacionContado, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then - ErrorMovtosCxP = True - End If - - 'Compra - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtSubTotal2.Text.ToDecimal, " ", 30, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then - ErrorMovtosCxP = True - End If - - 'IVA por Acreditar . siempre se registra aunque sea cero - If Not ErrorMovtosCxP Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal, " ", 19, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then - ErrorMovtosCxP = True - End If - End If - - If Not ErrorMovtosCxP AndAlso TxtRetIVA.Text.ToDouble > 0 Then - 'Agrego el RetIVA - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal, " ", 22, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then - ErrorMovtosCxP = True - End If - End If - - If Not ErrorMovtosCxP AndAlso TxtRetISR.Text.ToDouble > 0 Then - 'Agrego el RetIVA - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal, " ", 23, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva) Then - ErrorMovtosCxP = True - End If - End If - - - Else - ErrorMovtosIE = True - End If - - End If - - - 'movimiento de compra - '[IPP] PARCHE PROVISIONAL DE CLASIFICACION Y SUBPROYECTO [CveClasificacion:=TmpDT.FiltroPrimeroValor("CveClasificacion").ToString.ToEntero] [CveSubProyecto:=TmpDT.FiltroPrimeroValor("CveSubProyecto").ToString.ToEntero] - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoCompra, TxtSubTotal2.Text.ToDecimal, " ", CveConceptoCompra, " ", TxtFechaPago.Text.ToDate, 0, -1, CveClasificacion:=TmpDT.FiltroPrimeroValor("CveClasificacion").ToString.ToEntero, CveSubProyecto:=TmpDT.FiltroPrimeroValor("CveSubProyecto").ToString.ToEntero, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtSubTotal2.Text.ToDecimal) Then - ErrorMovtosCxP = True - End If - - 'Se agregan las CxP - If CveConceptoAfectacion = 37 Then - For Each rw As GridViewRow In GvDeudores.Rows - If rw.FCCheckBox("Chk").Checked Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimientoCompra, rw.FCTextBox("TxtSaldoDeudor").Text.ToDecimal, " ", CveConceptoAfectacion, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=rw.DataKey("CveIE").ToString.ToEntero, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=rw.FCTextBox("TxtSaldoDeudor").Text.ToDecimal) Then - ErrorMovtosCxP = True - End If - End If - Next - Else - If ImporteCompra > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimientoCompra, ImporteCompra, " ", CveConceptoAfectacion, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=ImporteCompra) Then - ErrorMovtosCxP = True - End If - End If - - - If CvePlantillaPrePoliza = 1 Or CvePlantillaPrePoliza = 60 Then - - 'Siempre: Se agrega IVA aunque sea cero - ' If TxtIVA.Text.Replace(", ", "").Trim.ToDouble <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimientoImpuestos, TxtIVA.Text.ToDecimal, " ", CveConceptoIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal) Then - ErrorMovtosIVA = True - End If - 'End If - - 'Se agregan las Ret IVA - If TxtRetIVA.Text.ToDouble <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoImpuestos, TxtRetIVA.Text.ToDecimal, " ", CveConceptoRetIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal) Then - ErrorMovtosRetIVA = True - End If - End If - - 'Se agregan las Ret ISR - If TxtRetISR.Text.ToDouble > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoImpuestos, TxtRetISR.Text.ToDecimal, " ", CveConceptoRetISR, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetISR.Text.ToDecimal) Then - ErrorMovtosRetISR = True - End If - End If - - If TxtIEPS.Text.ToDouble > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoImpuestos, TxtIEPS.Text.ToDecimal, " ", CveConceptoRetIEPS, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIEPS.Text.ToDecimal) Then - ErrorMovtosRetISR = True - End If - End If - - If TxtOtrosImpuestos.Text.ToDouble <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoImpuestos, TxtOtrosImpuestos.Text.ToDecimal, " ", CveConceptoRetOtrosImpuestos, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtOtrosImpuestos.Text.ToDecimal) Then - ErrorMovtosRetISR = True - End If - End If - - End If - - - '' A N T I C I P O S - If ArrAnticipos.Count > 0 Then - - Dim TotalIVA As Double = TxtIVA.Text.ToDouble - - 'Inserto otra poliza del mo - 'Dim CvePrePolizaAnticipo As Integer = ObjConta.AddPrePolizas("Banc", 10, ImporteAnticipo, ImporteAnticipo, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - ' CveConceptoAfectacion = 21 'Cancelacion Anticipo Proveedores - Dim PorcentajePago As Decimal - Dim CveConceptoAnt As Integer = 21 - Dim CveCompraNC As Integer - For Each Ant As Compras_Compras.Anticipos In ArrAnticipos - CveCompraNC = CveCompra - Dim CveConceptoPago As Integer = 17 - Select Case Ant.TipoMovto - Case "NC", "DEV" - CveConceptoAnt = 60 - CveCompraNC = Ant.CveCompra ' cuando es NC, se utiliza la clave de compra de la nota de credito - CveConceptoPago = 272 - Case "Egsc" - CveConceptoAnt = 21 - Case "DD" - CveConceptoAnt = 37 - - End Select - + End Select + + If ErrorPrepoliza Then + Exit For + End If + + If importeMovimiento <> 0 Or (ConceptoContable.Contiene(5, 305, 306, 311) AndAlso DdlTipoComprobante.SelectedValue.Contiene("Fac", "Ant")) Or (ConceptoContable.Contiene(18) AndAlso DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") AndAlso Not GuardoConcepto18) Then + 'Conta ContPAQ + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + 'COnta SIG + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) + CveCuentaContabilizacion = 0 + End If + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=Math.Round(importeMN, 2, MidpointRounding.AwayFromZero), ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, TipoCambio:=tipoCambioActual, PorcentajeImpuesto:=PorcentajeImpuesto, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + + End If + + Next + + 'EMPIEZA REFACTURACION + If CveCompraRefacturacion > 0 Then + ErrorBitacora = GuardaRefacturacion(ObjCompras, ObjEventos, CvePrePoliza) + If ErrorBitacora Then + Alert("Ocurrió un error al hacer la Refacturación", TipoMensaje.MsgError) + End If + End If + + 'Simplificacion de PrePolizas + If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then + If Not ObjConta.PrePolizaSimplificacion(CvePrePoliza, UsuarioActual.CveEmpresa) Then + ErrorPrepolizaDescuadre = True + End If + End If + + If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, 4) Then + If ObjConta.ValorPolizaDescuadre > 0 Then + GuardaLogAD($"Compras/Compras-Guardar | Error{ObjConta.MensajePolizaDescuadre} Diferencia{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") + ErrorPrepolizaDescuadre = True + End If + End If + + 'Conta ContPAQ + If ObjContaAC IsNot Nothing AndAlso Not ErrorPrepoliza AndAlso Not ErrorPrepolizaDescuadre AndAlso UsuarioActual.Empresa.Funcionalidad(200).ToString = "1" Then + If idCuentaContabilizacion > 0 Then + If ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContaAC) Then + ' Alert(alertaContabilizacion, ModExtensiones.TipoMensaje.MsgInformacion) + IdPoliza = ObjConta.ContaIdPoliza + Else + ErrorPrepoliza = True + Alert($"Ocurrio un error al contabilizar {ObjConta.AlertaMensaje}", TipoMensaje.MsgAdvertencia) + End If + Else + Alert(String.Format("No se puede contabilizar la Prepoliza debido a que las siguientes cuentas son inválidas:
{0}", CuentasContablesInvalidas), TipoMensaje.MsgAdvertencia) + ErrorPrepoliza = True + End If + End If + End If + + + + + '' A N T I C I P O S + If UsuarioActual.Empresa.UsaAC Then + If ArrAnticipos.Count > 0 Then + + Dim PorcentajePago As Decimal + Dim ConceptoRenglon As String + + + 'si hay una diferencia entre lo amortizado y el total, se registra la diferencia a proveedores y los ivas por acreditar + If TxtTotal.Text.ToDouble - ImporteAnticipo > 0 Then + PorcentajePago = (TxtTotal.Text.ToDecimal - ImporteAnticipo) / TxtTotal.Text.ToDecimal + ConceptoRenglon = String.Format("GE Fact {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, TxtTotal.Text.ToDouble - ImporteAnticipo, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + ErrorACMEnsaje.Append(" - si hay una diferencia entre lo amortizado y el total, se registra la diferencia a proveedores y los ivas por acreditar ObjContaAC.AddMovimiento") + ErrorAC = True + End If + End If + + 'una vez amortizado, se generan los movimientos presupuestales + If ImporteAnticipo > 0 Then + PorcentajePago = ImporteAnticipo / TxtTotal.Text.ToDecimal + If ObjCompras.GetPresupuestosCompras(CveCompra) AndAlso ObjCompras.DtResultados.Rows.Count > 0 Then + 'DtAC.Merge(ObjConta.DtResultados) + For Each dr As DataRow In ObjCompras.DtResultados.Rows + Total = dr("TotalPresupuesto").ToString.ToDecimal * PorcentajePago + If Total > 0 Then + + 'EJERCIDO + If True Then + ConceptoRenglon = String.Format("GE {0} F{1}-{2}", DdlProveedor.SelectedItem.Text, TxtSerie.Text, TxtFolio.Text) + If ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaEjercido").ToString.ToEntero, False, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + 'actualizo el idcuenta del presupuesto + If Not ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + TieneError = True + Exit For + End If + Else + TieneError = True + Exit For + End If + End If + + 'PAGADO + ConceptoRenglon = String.Format("GP {0} F{1}-{2}", DdlProveedor.SelectedItem.Text, TxtSerie.Text, TxtFolio.Text) + If ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaPagado").ToString.ToEntero, False, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + 'actualizo el idcuenta del presupuesto + If Not ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaEjercido").ToString.ToEntero, True, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + TieneError = True + Exit For + End If + Else + TieneError = True + Exit For + End If + + End If + Next + + Else + ErrorACMEnsaje.Append(" - Error al obtener presupuestos ObjCompras.GetPresupuestosCompras") + ErrorAC = True + End If + + End If + End If + End If + + + '' F U N C I O N A R I O S Y E M P L E A D O S + If RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then + TxtDocumentoImporte.Text = TxtDocumentoImporteFE.Text + TxtDocumentoImporteCaja.Text = TxtDocumentoImporteFE.Text + + End If + + Else 'Empresa Prueba + + If RBLPago.SelectedValue.ToEntero = 2 AndAlso (RBLContado.SelectedValue = "1" Or RBLContado.SelectedValue = "6") Then 'Contado - Bancos y Caja Chica + 'se agrego un movimiento de pago + ' CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero, TxtFecha.Text.Trim.ToDate, TxtDocumentoFolio.Text.Trim, DdlProveedor.SelectedItem.Text.Trim, TxtDocumentoImporte.Text.Trim.ToDouble, 1, 0.0, TxtDocumentoObservaciones.Text.Trim, True, True, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CveIE > 0 Then + + 'inserto los movimientos de la conta para abonar al saldo + + 'Se agregamovimiento de pago de proveedor + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteCompra, " ", CveConceptoAfectacionContado, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then + ErrorMovtosCxP = True + End If + + 'Compra + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtSubTotal2.Text.ToDecimal, " ", 30, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then + ErrorMovtosCxP = True + End If + + 'IVA por Acreditar . siempre se registra aunque sea cero + If Not ErrorMovtosCxP Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal, " ", 19, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then + ErrorMovtosCxP = True + End If + End If + + If Not ErrorMovtosCxP AndAlso TxtRetIVA.Text.ToDouble > 0 Then + 'Agrego el RetIVA + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal, " ", 22, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then + ErrorMovtosCxP = True + End If + End If + + If Not ErrorMovtosCxP AndAlso TxtRetISR.Text.ToDouble > 0 Then + 'Agrego el RetIVA + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal, " ", 23, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva) Then + ErrorMovtosCxP = True + End If + End If + + + Else + ErrorMovtosIE = True + End If + + End If + + + 'movimiento de compra + '[IPP] PARCHE PROVISIONAL DE CLASIFICACION Y SUBPROYECTO [CveClasificacion:=TmpDT.FiltroPrimeroValor("CveClasificacion").ToString.ToEntero] [CveSubProyecto:=TmpDT.FiltroPrimeroValor("CveSubProyecto").ToString.ToEntero] + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoCompra, TxtSubTotal2.Text.ToDecimal, " ", CveConceptoCompra, " ", TxtFechaPago.Text.ToDate, 0, -1, CveClasificacion:=TmpDT.FiltroPrimeroValor("CveClasificacion").ToString.ToEntero, CveSubProyecto:=TmpDT.FiltroPrimeroValor("CveSubProyecto").ToString.ToEntero, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtSubTotal2.Text.ToDecimal) Then + ErrorMovtosCxP = True + End If + + 'Se agregan las CxP + If CveConceptoAfectacion = 37 Then + For Each rw As GridViewRow In GvDeudores.Rows + If rw.FCCheckBox("Chk").Checked Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimientoCompra, rw.FCTextBox("TxtSaldoDeudor").Text.ToDecimal, " ", CveConceptoAfectacion, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=rw.DataKey("CveIE").ToString.ToEntero, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=rw.FCTextBox("TxtSaldoDeudor").Text.ToDecimal) Then + ErrorMovtosCxP = True + End If + End If + Next + Else + If ImporteCompra > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimientoCompra, ImporteCompra, " ", CveConceptoAfectacion, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=ImporteCompra) Then + ErrorMovtosCxP = True + End If + End If + + + If CvePlantillaPrePoliza = 1 Or CvePlantillaPrePoliza = 60 Then + + 'Siempre: Se agrega IVA aunque sea cero + ' If TxtIVA.Text.Replace(", ", "").Trim.ToDouble <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimientoImpuestos, TxtIVA.Text.ToDecimal, " ", CveConceptoIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal) Then + ErrorMovtosIVA = True + End If + 'End If + + 'Se agregan las Ret IVA + If TxtRetIVA.Text.ToDouble <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoImpuestos, TxtRetIVA.Text.ToDecimal, " ", CveConceptoRetIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal) Then + ErrorMovtosRetIVA = True + End If + End If + + 'Se agregan las Ret ISR + If TxtRetISR.Text.ToDouble > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoImpuestos, TxtRetISR.Text.ToDecimal, " ", CveConceptoRetISR, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetISR.Text.ToDecimal) Then + ErrorMovtosRetISR = True + End If + End If + + If TxtIEPS.Text.ToDouble > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoImpuestos, TxtIEPS.Text.ToDecimal, " ", CveConceptoRetIEPS, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIEPS.Text.ToDecimal) Then + ErrorMovtosRetISR = True + End If + End If + + If TxtOtrosImpuestos.Text.ToDouble <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoImpuestos, TxtOtrosImpuestos.Text.ToDecimal, " ", CveConceptoRetOtrosImpuestos, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtOtrosImpuestos.Text.ToDecimal) Then + ErrorMovtosRetISR = True + End If + End If + + End If + + + '' A N T I C I P O S + If ArrAnticipos.Count > 0 Then + + Dim TotalIVA As Double = TxtIVA.Text.ToDouble + + 'Inserto otra poliza del mo + 'Dim CvePrePolizaAnticipo As Integer = ObjConta.AddPrePolizas("Banc", 10, ImporteAnticipo, ImporteAnticipo, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + ' CveConceptoAfectacion = 21 'Cancelacion Anticipo Proveedores + Dim PorcentajePago As Decimal + Dim CveConceptoAnt As Integer = 21 + Dim CveCompraNC As Integer + For Each Ant As Compras_Compras.Anticipos In ArrAnticipos + CveCompraNC = CveCompra + + Dim CveConceptoPago As Integer = 17 + If CveTipoConcepto = 2 Then CveConceptoPago = 308 'cuando es acreedor + If CveMoneda > 1 Then + Select Case CveConceptoPago + Case 17 + CveConceptoPago = 312 + Case 308 + CveConceptoPago = 309 + Case Else + End Select + End If + + Select Case Ant.TipoMovto + Case "NC", "DEV" + CveConceptoAnt = 60 + CveCompraNC = Ant.CveCompra ' cuando es NC, se utiliza la clave de compra de la nota de credito + CveConceptoPago = 272 + Case "Egsc" + CveConceptoAnt = 21 + Case "DD" + CveConceptoAnt = 37 + + End Select + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Ant.Importe, " ", CveConceptoAnt, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompraNC, CveCompraAmortizacion:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=Ant.Importe) Then ' ImporteAnticipo += Ant.Importe ' RESTO DEL IMPORTE POR SI QUEDA DIFERENCIA DE LA SUMA DE LOS ANTICIPOS Y EL PROVEEDOR TIENE QUE PAGAR 'movimiento de pago proveedor, --no se regisra porque no se registra el total de la compra como deuda del proveedor, solo lo que queda a deber 'si es l moviemiento es de amortizacion con descuento, no registra el pago, ya esta descontado - If TieneAnticiposXML = False AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoCompra, Ant.Importe, " ", CveConceptoPago, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=Ant.Importe) Then - ErrorMovtosCxP = True - End If - PorcentajePago = (Ant.Importe) / TxtTotal.Text.ToDecimal - - 'IVA por Acreditar . siempre se registra aunque sea cero - If Not ErrorMovtosCxP Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal * PorcentajePago, " ", 19, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True - End If - - 'Agrego el RetIVA - If Not ErrorMovtosCxP AndAlso TxtRetIVA.Text.ToDouble > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal * PorcentajePago, " ", 22, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True - End If - - 'Agrego el RetISR - If Not ErrorMovtosCxP AndAlso TxtRetISR.Text.ToDouble > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal * PorcentajePago, " ", 23, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, ImporteMX:=TxtRetISR.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True - End If - Else - ErrorMovtosCxP = True - End If - Next - - Dim ConceptoRenglon As String - - - 'si hay una diferencia entre lo amortizado y el total, se registra la diferencia a proveedores y los ivas por acreditar - If TxtTotal.Text.ToDouble - ImporteAnticipo > 0 Then - PorcentajePago = (TxtTotal.Text.ToDecimal - ImporteAnticipo) / TxtTotal.Text.ToDecimal - 'Siempre: Se agrega IVA aunque sea cero - If TxtIVA.Text.ToDouble <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal * PorcentajePago, " ", CveConceptoIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal * PorcentajePago) Then - ErrorMovtosIVA = True - End If - End If - - 'Se agregan las Ret IVA - If TxtRetIVA.Text.ToDouble <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal * PorcentajePago, " ", CveConceptoRetIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal * PorcentajePago) Then - ErrorMovtosRetIVA = True - End If - End If - - 'Se agregan las Ret ISR - If TxtRetISR.Text.ToDouble > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal * PorcentajePago, " ", CveConceptoRetISR, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetISR.Text.ToDecimal * PorcentajePago) Then - ErrorMovtosRetISR = True - End If - End If - - If UsuarioActual.Empresa.UsaAC Then - If CtaProveedor > 0 Then - ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, TxtTotal.Text.ToDouble - ImporteAnticipo, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - ErrorAC = True - ErrorACMEnsaje.Append("- CtaProveedor > 0 ObjContaAC.AddMovimiento") - End If - Else - Alert(" - El proveedor no tiene cuenta contable.", TipoMensaje.MsgAdvertencia) - - ErrorAC = True - End If - End If - End If - - 'una vez amortizado, se generan los movimientos presupuestales - - If UsuarioActual.Empresa.UsaAC AndAlso ImporteAnticipo > 0 Then - - - PorcentajePago = ImporteAnticipo / TxtTotal.Text.ToDecimal - - If ObjCompras.GetPresupuestosCompras(CveCompra) AndAlso ObjCompras.DtResultados.Rows.Count > 0 Then - 'DtAC.Merge(ObjConta.DtResultados) - - For Each dr As DataRow In ObjCompras.DtResultados.Rows - Total = dr("TotalPresupuesto").ToString.ToDecimal * PorcentajePago - - If Total > 0 Then - - 'EJERCIDO - If True Then - - ConceptoRenglon = String.Format("GE {0} F:{1}-{2}", DdlProveedor.SelectedItem.Text, TxtSerie.Text, TxtFolio.Text) - If ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaEjercido").ToString.ToEntero, False, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - 'actualizo el idcuenta del presupuesto - If Not ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - TieneError = True - Exit For - End If - - Else - TieneError = True - Exit For - End If - End If - - 'PAGADO - ConceptoRenglon = String.Format("GP {0} F:{1}-{2}", DdlProveedor.SelectedItem.Text, TxtSerie.Text, TxtFolio.Text) - If ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaPagado").ToString.ToEntero, False, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - 'actualizo el idcuenta del presupuesto - If Not ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaEjercido").ToString.ToEntero, True, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then - TieneError = True - Exit For - End If - Else - TieneError = True - Exit For - End If - - End If - Next - - Else - ErrorACMEnsaje.Append("- error al obtener presupuestos 2") - ErrorAC = True - End If - End If - - End If - - - '' F U N C I O N A R I O S Y E M P L E A D O S - If RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then - 'Si es con funcionarios empleados Ya existe un registro en Bancos de Ingresos Egresos - TxtDocumentoImporte.Text = TxtDocumentoImporteFE.Text - TxtDocumentoImporteCaja.Text = TxtDocumentoImporteFE.Text - - Dim ImportePagadoFE As Decimal = 0 - Dim ImporteAPagarFE As Decimal = TxtDocumentoImporteFE.Text.ToDecimal - Dim ImportePagar As Decimal = ImporteAPagarFE - - 'CvePrePoliza = ObjConta.AddPrePolizas("Banc", 2, ImporteAPagarFE, ImporteAPagarFE, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CvePrePoliza > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImportePagar, " ", 29, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CvePersonal:=DdlFuncionarioEmpleado.SelectedValue.ToEntero, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveColectiva:=CveColectiva, CveIE:=CveIE, ImporteMX:=ImportePagar) Then - ErrorMovtosCxP = True - End If - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImportePagar, " ", 17, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CvePersonal:=DdlFuncionarioEmpleado.SelectedValue.ToEntero, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveColectiva:=CveColectiva, CveIE:=CveIE, ImporteMX:=ImportePagar) Then - ErrorMovtosCxP = True - End If - - - Dim PorcentajePago As Decimal = (ImportePagar) / TxtTotal.Text.ToDecimal - - 'IVA por Acreditar . siempre se registra aunque sea cero - If Not ErrorMovtosCxP Then - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal * PorcentajePago, " ", 19, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True - - End If - - If Not ErrorMovtosCxP AndAlso TxtRetIVA.Text.ToDouble > 0 Then - 'Agrego el RetIVA - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal * PorcentajePago, " ", 22, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True - - End If - - If Not ErrorMovtosCxP AndAlso TxtRetISR.Text.ToDouble > 0 Then - 'Agrego el RetISR - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal * PorcentajePago, " ", 23, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, ImporteMX:=TxtRetISR.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True - - End If - - - 'sino alcanzo a cubrir se regitran los ivas por acreditar - If TxtTotal.Text.ToDouble - ImportePagar > 0 Then - PorcentajePago = (TxtTotal.Text.ToDecimal - ImportePagar) / TxtTotal.Text.ToDecimal - 'Movimiento, se omite, porque se esta registrando la totalidad de la deuda - 'If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtTotal.Text.ToDouble - ImporteAnticipo, " ", 5, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then - ' ErrorMovtosCxP = True - 'End If - 'Siempre: Se agrega IVA aunque sea cero - If TxtIVA.Text.ToDouble <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal * PorcentajePago, " ", CveConceptoIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal * PorcentajePago) Then - ErrorMovtosIVA = True - End If - End If - - 'Se agregan las Ret IVA - If TxtRetIVA.Text.ToDouble <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal * PorcentajePago, " ", CveConceptoRetIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal * PorcentajePago) Then - ErrorMovtosRetIVA = True - End If - End If - - 'Se agregan las Ret ISR - If TxtRetISR.Text.ToDouble > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal * PorcentajePago, " ", CveConceptoRetISR, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetISR.Text.ToDecimal * PorcentajePago) Then - ErrorMovtosRetISR = True - End If - End If - - End If - - Else - ErrorMovtosCxP = True - End If - - - End If - - End If 'Empresa Prueba - - '************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************ - - 'End If - Else - ErrorMovtosCxP = True - End If - - - End If - - If HdnVCveOC.Value <> "-1" AndAlso HdnCveEstatusOC.Value <> "-1" Then - Dim ArrayCveOC As String() = HdnVCveOC.Value.Split(New Char() {","c}) - Dim ArrayCveEstatusOC As String() = HdnCveEstatusOC.Value.Split(New Char() {","c}) - - If ArrayCveEstatusOC.Count = ArrayCveOC.Count Then - For i = 0 To ArrayCveEstatusOC.Count - 1 - If Not ObjOC.UpdateOrdenCompraCompletada(ArrayCveEstatusOC(i).ToEntero, ArrayCveOC(i).ToEntero, UsuarioActual.CveUsuario, "Se vinculó Compra", CveCompra) Then - ErrorOC = True - Exit For - End If - Next - Else - ErrorOC = True - End If - - End If - - If ChkNCInvNC.Checked Then - For Each Gvr As GridViewRow In GVNCInv.Rows - If Gvr.FCTextBox("TxtCantidadNCInv").Text.ToDouble > 0 Then - If Not ObjCompras.ComprasDetalleDevolucionesAdd(Gvr.DataKey("CveCompraDetalle").ToEntero, CveCompra, Gvr.FCTextBox("TxtCantidadNCInv").Text.ToDouble, UsuarioActual.CveEmpresa) Then - ErrorMovInv = True - Exit For - End If - End If - Next - End If - - - 'GUARDA BITACORA TIPO CAMBIO OC - If Not ErrorOC And TipoCambioOC > 0 Then - If Not ObjEventos.AddEventoBitacora(String.Format("La vinculación con la orden de compra fue con un tipo de cambio de: ${0}", TipoCambioOC.ToString), "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then - ErrorOC = True - End If - End If - - - If tDTAcarreos.Rows.Count > 0 Then - If TotAcarreos = TxtSubTotal.Text.ToDouble Then - 'ACARREOS - For Each tDTAcar As DataRow In tDTAcarreos.Rows - If Not ObjAcar.UpdatePreEstimacion(CInt(tDTAcar("CvePreEstimacion")), CveCompra) Then - ErrorAddAcarreos = True - Exit For - End If - Next - Else - ErrorAddAcarreos = True - End If - End If - - 'AGREGAR OTROS GASTOS A ORDEN DE CORTE - If CveOrdenCorte > 0 And UsuarioActual.CveEmpresa = 126 Then - If ObjCGame.AddCorteGasto(CveOrdenCorte, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Now, 0, CveCompra) Then - If Not ObjCGame.AddCorteGastoDetalle(ObjCGame.CveCorteGasto, 32, 1, TxtSubTotal.Text.ToDouble()) Then - ErrorOtrosGastos = True - End If - Else - ErrorOtrosGastos = True - End If - End If - - 'CREDITO COMPRA - Dim CvePrePolizaCredito = 0 - If RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue.ToEntero = 3 AndAlso DdlTipoCredito.SelectedValue.ToEntero = 1 AndAlso DdlCredito.SelectedValue.ToEntero > 0 Then - - If Not ObjIE.UpdateCreditosCompra(DdlCredito.SelectedValue.ToEntero, CveCompra, UsuarioActual.CveEmpresa) Then - ErrorCreditosCompra = True - End If - - If Not ErrorCreditosCompra Then - - If ObjIE.GetCreditos(DdlCredito.SelectedValue.ToEntero, -1, -1, -1, -1, UsuarioActual.CveEmpresa) Then - CvePrePolizaCredito = ObjConta.AddPrePolizas("Compras/RegistrarCredito", -1, ObjIE.TotalFinanciado, ObjIE.TotalFinanciado, 1, TxtFecha.Text.ToDate, "Vinculación crédito con factura", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If ObjConta.AddPrePolizasDetalle(CvePrePolizaCredito, False, ObjIE.TotalFinanciado.ToDecimal, "", 17, "Vinculación crédito con factura", TxtFecha.Text.ToDate, CtaProveedor, -1, CveProveedor:=CveProveedor, CveCompra:=CveCompra, ImporteMX:=ObjIE.TotalFinanciado.ToDecimal, CvePrePolizaOriginal:=CvePrePolizaCredito) Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaCredito, True, ObjIE.TotalFinanciado.ToDecimal, "", 50, "Vinculación crédito con factura", TxtFecha.Text.ToDate, CtaProveedor, -1, CveProveedor:=CveProveedor, CveCompra:=CveCompra, ImporteMX:=ObjIE.TotalFinanciado.ToDecimal, CvePrePolizaOriginal:=CvePrePolizaCredito) Then - ErrorCreditosCompra = True - End If - Else - ErrorCreditosCompra = True - End If - - If Not ErrorCreditosCompra Then - ObjConta.PrePolizaUnificacion(CvePrePoliza, CvePrePolizaCredito) - End If - - End If - End If - - End If - - - - - 'VALIDAR ERRORES - If ErrorAC OrElse ErrorPrepoliza OrElse ErrorPrepolizaDescuadre OrElse ErrorDetalles OrElse ErrorMovDev OrElse ErrorMovtosCxP OrElse ErrorMovtosRetIVA OrElse ErrorMovtosRetISR OrElse ErrorMovtosEstimaciones OrElse ErrorMovtosIE OrElse ErrorMovtosIVA OrElse ErrorMovInv OrElse TieneError OrElse ErrorAF OrElse ErrorOC OrElse ErrorBitacora OrElse ErrorAddAcarreos OrElse ErrorCreditosCompra Then - If ErrorDetalles Then - Alert("Ocurrió un Error al agregar un Producto o Servicio a la Factura.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ElseIf ErrorMovtosCxP Then - Alert("Ocurrió un Error al agregar las CxP.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ElseIf ErrorMovtosRetIVA Then - Alert("Ocurrió un Error al agregar las Retenciones de IVA.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ElseIf ErrorMovtosRetISR Then - Alert("Ocurrió un Error al agregar las Retenciones de ISR.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ElseIf ErrorMovtosEstimaciones Then - Alert("Ocurrió un Error al agregar las Estimaciones.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ElseIf ErrorMovtosIE Then - Alert("Ocurrió un Error al agregar el movimiento bancario.
Revise sus datos y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ElseIf ErrorMovtosIVA Then - Alert("Ocurrió un Error al agregar el IVA.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ElseIf ErrorMovInv Then - Alert("Ocurrió un Error al agregar el Producto o Servicio al Inventario.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ElseIf TieneError Then - Alert("El total de los IMPORTES del FINANCIAMIENTO debe ser mayor que 0 y menor o igual al total de la compra", TipoMensaje.MsgAdvertencia) - ElseIf ErrorAF Then - Alert("Error al actualizar la vinculacion del Activo Fijo", TipoMensaje.MsgAdvertencia) - ElseIf ErrorAC Then - Alert("Ocurrió un Error al insertar los movimientos contables.", TipoMensaje.MsgError) - GuardaLog($" Error Compras DESCRIPCIÓN DETALLADA: {ErrorACMEnsaje.ToString} {vbCrLf} Usuario={UsuarioActual.CveUsuario}, Empresa={UsuarioActual.CveEmpresa}, CveFactura={CveFactura}, CveProveedor={CveProveedor}") - ElseIf ErrorPrepolizaDescuadre Then - Alert(ObjConta.MensajePolizaDescuadre, TipoMensaje.MsgError) - ElseIf ErrorPrepoliza Then - Alert("Ocurrió un error al verificar los movimientos contables", TipoMensaje.MsgError) - ElseIf ErrorOC Then - Alert("Ocurrió un Error al vincular la Orden(es) de Compra. Por favor vuelva intentar.", TipoMensaje.MsgError) - ElseIf ErrorBitacora Then - Alert("Ocurrió un Error al guardar la refacturación.", TipoMensaje.MsgError) - ElseIf ErrorAddAcarreos Then - Alert("Ocurrio un Error al momento de agregar los acarreos.", TipoMensaje.MsgError) - ElseIf ErrorCreditosCompra Then - Alert("Ocurrió un Error al vincular la compra con el crédito.", TipoMensaje.MsgError) - ElseIf ErrorOtrosGastos Then - Alert("Ocurrió un Error al vincular la compra con la orden de corte.", TipoMensaje.MsgError) - ElseIf ErrorSATPS Then - Alert("Ocurrió un Error al actualizar el producto/servicio SAT.", TipoMensaje.MsgError) - ElseIf ErrorSaldosInvComp Then - Alert("Ocurrió un error al validar la mercancía recibida por adelantado.", TipoMensaje.MsgError) - End If - - ViewState("CveCompra") = -1 - ObjCompras.RollBack() - If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() - CargaProveedor(CveProveedor, "-1") - Else - Dim MsgAccionAceptar As String = "" - Dim Msg As New StringBuilder - Msg.Append("La compra se registró correctamente") - - - 'ACTUALIZA CVEFACTURA - If Request("CveFactura") IsNot Nothing Then - + If TieneAnticiposXML = False AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoCompra, Ant.Importe, " ", CveConceptoPago, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=Ant.CveIE, CveColectiva:=CveColectiva, ImporteMX:=Ant.Importe) Then + ErrorMovtosCxP = True + End If + PorcentajePago = (Ant.Importe) / TxtTotal.Text.ToDecimal + + 'IVA por Acreditar . siempre se registra aunque sea cero + If Not ErrorMovtosCxP Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal * PorcentajePago, " ", 19, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True + End If + + 'Agrego el RetIVA + If Not ErrorMovtosCxP AndAlso TxtRetIVA.Text.ToDouble > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal * PorcentajePago, " ", 22, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True + End If + + 'Agrego el RetISR + If Not ErrorMovtosCxP AndAlso TxtRetISR.Text.ToDouble > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal * PorcentajePago, " ", 23, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, ImporteMX:=TxtRetISR.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True + End If + Else + ErrorMovtosCxP = True + End If + Next + + Dim ConceptoRenglon As String + + + 'si hay una diferencia entre lo amortizado y el total, se registra la diferencia a proveedores y los ivas por acreditar + If TxtTotal.Text.ToDouble - ImporteAnticipo > 0 Then + PorcentajePago = (TxtTotal.Text.ToDecimal - ImporteAnticipo) / TxtTotal.Text.ToDecimal + 'Siempre: Se agrega IVA aunque sea cero + If TxtIVA.Text.ToDouble <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal * PorcentajePago, " ", CveConceptoIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal * PorcentajePago) Then + ErrorMovtosIVA = True + End If + End If + + 'Se agregan las Ret IVA + If TxtRetIVA.Text.ToDouble <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal * PorcentajePago, " ", CveConceptoRetIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal * PorcentajePago) Then + ErrorMovtosRetIVA = True + End If + End If + + 'Se agregan las Ret ISR + If TxtRetISR.Text.ToDouble > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal * PorcentajePago, " ", CveConceptoRetISR, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetISR.Text.ToDecimal * PorcentajePago) Then + ErrorMovtosRetISR = True + End If + End If + + If UsuarioActual.Empresa.UsaAC Then + If CtaProveedor > 0 Then + ConceptoRenglon = String.Format("GD Fact {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, TxtTotal.Text.ToDouble - ImporteAnticipo, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + ErrorAC = True + ErrorACMEnsaje.Append("- CtaProveedor > 0 ObjContaAC.AddMovimiento") + End If + Else + Alert(" - El proveedor no tiene cuenta contable.", TipoMensaje.MsgAdvertencia) + + ErrorAC = True + End If + End If + End If + + 'una vez amortizado, se generan los movimientos presupuestales + + If UsuarioActual.Empresa.UsaAC AndAlso ImporteAnticipo > 0 Then + + + PorcentajePago = ImporteAnticipo / TxtTotal.Text.ToDecimal + + If ObjCompras.GetPresupuestosCompras(CveCompra) AndAlso ObjCompras.DtResultados.Rows.Count > 0 Then + 'DtAC.Merge(ObjConta.DtResultados) + + For Each dr As DataRow In ObjCompras.DtResultados.Rows + Total = dr("TotalPresupuesto").ToString.ToDecimal * PorcentajePago + + If Total > 0 Then + + 'EJERCIDO + If True Then + + ConceptoRenglon = String.Format("GE {0} F{1}-{2}", DdlProveedor.SelectedItem.Text, TxtSerie.Text, TxtFolio.Text) + If ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaEjercido").ToString.ToEntero, False, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + 'actualizo el idcuenta del presupuesto + If Not ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + TieneError = True + Exit For + End If + + Else + TieneError = True + Exit For + End If + End If + + 'PAGADO + ConceptoRenglon = String.Format("GP {0} F{1}-{2}", DdlProveedor.SelectedItem.Text, TxtSerie.Text, TxtFolio.Text) + If ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaPagado").ToString.ToEntero, False, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + 'actualizo el idcuenta del presupuesto + If Not ObjContaAC.AddMovimiento(IdPoliza, dr("IdCuentaEjercido").ToString.ToEntero, True, MultiplicadorNC * Total, "", ConceptoRenglon, 0, TxtFechaPago.Text.ToDate, "") Then + TieneError = True + Exit For + End If + Else + TieneError = True + Exit For + End If + + End If + Next + + Else + ErrorACMEnsaje.Append("- Error al obtener presupuestos 2") + ErrorAC = True + End If + End If + + End If + + + '' F U N C I O N A R I O S Y E M P L E A D O S + If RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then + 'Si es con funcionarios empleados Ya existe un registro en Bancos de Ingresos Egresos + TxtDocumentoImporte.Text = TxtDocumentoImporteFE.Text + TxtDocumentoImporteCaja.Text = TxtDocumentoImporteFE.Text + + Dim ImportePagadoFE As Decimal = 0 + Dim ImporteAPagarFE As Decimal = TxtDocumentoImporteFE.Text.ToDecimal + Dim ImportePagar As Decimal = ImporteAPagarFE + + 'CvePrePoliza = ObjConta.AddPrePolizas("Banc", 2, ImporteAPagarFE, ImporteAPagarFE, DdlMoneda.SelectedValue.ToEntero, TxtFecha.Text.ToDate, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CvePrePoliza > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImportePagar, " ", 29, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CvePersonal:=DdlFuncionarioEmpleado.SelectedValue.ToEntero, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveColectiva:=CveColectiva, CveIE:=CveIE, ImporteMX:=ImportePagar) Then + ErrorMovtosCxP = True + End If + + Dim CveConceptoPago As Integer = 17 + If CveTipoConcepto = 2 Then CveConceptoPago = 308 'cuando es acreedor + If CveMoneda > 1 Then + Select Case CveConceptoPago + Case 17 + CveConceptoPago = 312 + Case 308 + CveConceptoPago = 309 + Case Else + End Select + End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImportePagar, " ", CveConceptoPago, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CvePersonal:=DdlFuncionarioEmpleado.SelectedValue.ToEntero, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveColectiva:=CveColectiva, CveIE:=CveIE, ImporteMX:=ImportePagar) Then + ErrorMovtosCxP = True + End If + + + Dim PorcentajePago As Decimal = (ImportePagar) / TxtTotal.Text.ToDecimal + + 'IVA por Acreditar . siempre se registra aunque sea cero + If Not ErrorMovtosCxP Then + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal * PorcentajePago, " ", 19, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True + + End If + + If Not ErrorMovtosCxP AndAlso TxtRetIVA.Text.ToDouble > 0 Then + 'Agrego el RetIVA + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal * PorcentajePago, " ", 22, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True + + End If + + If Not ErrorMovtosCxP AndAlso TxtRetISR.Text.ToDouble > 0 Then + 'Agrego el RetISR + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal * PorcentajePago, " ", 23, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, ImporteMX:=TxtRetISR.Text.ToDecimal * PorcentajePago) Then ErrorMovtosCxP = True + + End If + + + 'sino alcanzo a cubrir se regitran los ivas por acreditar + If TxtTotal.Text.ToDouble - ImportePagar > 0 Then + PorcentajePago = (TxtTotal.Text.ToDecimal - ImportePagar) / TxtTotal.Text.ToDecimal + 'Movimiento, se omite, porque se esta registrando la totalidad de la deuda + 'If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtTotal.Text.ToDouble - ImporteAnticipo, " ", 5, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle) Then + ' ErrorMovtosCxP = True + 'End If + 'Siempre: Se agrega IVA aunque sea cero + If TxtIVA.Text.ToDouble <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TxtIVA.Text.ToDecimal * PorcentajePago, " ", CveConceptoIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtIVA.Text.ToDecimal * PorcentajePago) Then + ErrorMovtosIVA = True + End If + End If + + 'Se agregan las Ret IVA + If TxtRetIVA.Text.ToDouble <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetIVA.Text.ToDecimal * PorcentajePago, " ", CveConceptoRetIVA, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetIVA.Text.ToDecimal * PorcentajePago) Then + ErrorMovtosRetIVA = True + End If + End If + + 'Se agregan las Ret ISR + If TxtRetISR.Text.ToDouble > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TxtRetISR.Text.ToDecimal * PorcentajePago, " ", CveConceptoRetISR, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorLocal, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=TxtRetISR.Text.ToDecimal * PorcentajePago) Then + ErrorMovtosRetISR = True + End If + End If + + End If + + Else + ErrorMovtosCxP = True + End If + + + End If + + End If 'Empresa Prueba + + '************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************ + + 'End If + Else + ErrorMovtosCxP = True + End If + + + End If + + If HdnVCveOC.Value <> "-1" AndAlso HdnCveEstatusOC.Value <> "-1" Then + Dim ArrayCveOC As String() = HdnVCveOC.Value.Split(New Char() {","c}) + Dim ArrayCveEstatusOC As String() = HdnCveEstatusOC.Value.Split(New Char() {","c}) + + If ArrayCveEstatusOC.Count = ArrayCveOC.Count Then + For i = 0 To ArrayCveEstatusOC.Count - 1 + If Not ObjOC.UpdateOrdenCompraCompletada(ArrayCveEstatusOC(i).ToEntero, ArrayCveOC(i).ToEntero, UsuarioActual.CveUsuario, "Se vinculó Compra", CveCompra) Then + ErrorOC = True + Exit For + End If + Next + Else + ErrorOC = True + End If + + End If + + If ChkNCInvNC.Checked Then + For Each Gvr As GridViewRow In GVNCInv.Rows + If Gvr.FCTextBox("TxtCantidadNCInv").Text.ToDouble > 0 Then + If Not ObjCompras.ComprasDetalleDevolucionesAdd(Gvr.DataKey("CveCompraDetalle").ToEntero, CveCompra, Gvr.FCTextBox("TxtCantidadNCInv").Text.ToDouble, UsuarioActual.CveEmpresa) Then + ErrorMovInv = True + Exit For + End If + End If + Next + End If + + + 'GUARDA BITACORA TIPO CAMBIO OC + If Not ErrorOC And TipoCambioOC > 0 Then + If Not ObjEventos.AddEventoBitacora(String.Format("La vinculación con la orden de compra fue con un tipo de cambio de ${0}", TipoCambioOC.ToString), "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then + ErrorOC = True + End If + End If + + + If tDTAcarreos.Rows.Count > 0 Then + If TotAcarreos = TxtSubTotal.Text.ToDouble Then + 'ACARREOS + For Each tDTAcar As DataRow In tDTAcarreos.Rows + If Not ObjAcar.UpdatePreEstimacion(CInt(tDTAcar("CvePreEstimacion")), CveCompra) Then + ErrorAddAcarreos = True + Exit For + End If + Next + Else + ErrorAddAcarreos = True + End If + End If + + 'AGREGAR OTROS GASTOS A ORDEN DE CORTE + If CveOrdenCorte > 0 And UsuarioActual.CveEmpresa = 126 Then + If ObjCGame.AddCorteGasto(CveOrdenCorte, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Now, 0, CveCompra) Then + If Not ObjCGame.AddCorteGastoDetalle(ObjCGame.CveCorteGasto, 32, 1, TxtSubTotal.Text.ToDouble()) Then + ErrorOtrosGastos = True + End If + Else + ErrorOtrosGastos = True + End If + End If + + 'CREDITO COMPRA + Dim CvePrePolizaCredito = 0 + If RBLPago.SelectedValue.ToEntero = 2 AndAlso RBLContado.SelectedValue.ToEntero = 3 AndAlso DdlTipoCredito.SelectedValue.ToEntero = 1 AndAlso DdlCredito.SelectedValue.ToEntero > 0 Then + + If Not ObjIE.UpdateCreditosCompra(DdlCredito.SelectedValue.ToEntero, CveCompra, UsuarioActual.CveEmpresa) Then + ErrorCreditosCompra = True + End If + + If Not ErrorCreditosCompra Then + + Dim CveConceptoPago As Integer = 17 + If CveTipoConcepto = 2 Then CveConceptoPago = 308 'cuando es acreedor + If CveMoneda > 1 Then + Select Case CveConceptoPago + Case 17 + CveConceptoPago = 312 + Case 308 + CveConceptoPago = 309 + Case Else + End Select + End If + + If ObjIE.GetCreditos(DdlCredito.SelectedValue.ToEntero, -1, -1, -1, -1, UsuarioActual.CveEmpresa) Then + CvePrePolizaCredito = ObjConta.AddPrePolizas("Compras/RegistrarCredito", -1, ObjIE.TotalFinanciado, ObjIE.TotalFinanciado, 1, TxtFecha.Text.ToDate, "Vinculación crédito con factura", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If ObjConta.AddPrePolizasDetalle(CvePrePolizaCredito, False, ObjIE.TotalFinanciado.ToDecimal, "", CveConceptoPago, "Vinculación crédito con factura", TxtFecha.Text.ToDate, CtaProveedor, -1, CveProveedor:=CveProveedor, CveCompra:=CveCompra, ImporteMX:=ObjIE.TotalFinanciado.ToDecimal, CvePrePolizaOriginal:=CvePrePolizaCredito) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaCredito, True, ObjIE.TotalFinanciado.ToDecimal, "", 50, "Vinculación crédito con factura", TxtFecha.Text.ToDate, CtaProveedor, -1, CveProveedor:=CveProveedor, CveCompra:=CveCompra, ImporteMX:=ObjIE.TotalFinanciado.ToDecimal, CvePrePolizaOriginal:=CvePrePolizaCredito) Then + ErrorCreditosCompra = True + End If + Else + ErrorCreditosCompra = True + End If + + If Not ErrorCreditosCompra Then + ObjConta.PrePolizaUnificacion(CvePrePoliza, CvePrePolizaCredito) + End If + + End If + End If + + End If + + + + + 'VALIDAR ERRORES + If ErrorAC OrElse ErrorPrepoliza OrElse ErrorPrepolizaDescuadre OrElse ErrorDetalles OrElse ErrorMovDev OrElse ErrorMovtosCxP OrElse ErrorMovtosRetIVA OrElse ErrorMovtosRetISR OrElse ErrorMovtosEstimaciones OrElse ErrorMovtosIE OrElse ErrorMovtosIVA OrElse ErrorMovInv OrElse TieneError OrElse ErrorAF OrElse ErrorOC OrElse ErrorBitacora OrElse ErrorAddAcarreos OrElse ErrorCreditosCompra Then + If ErrorDetalles Then + Alert("Ocurrió un Error al agregar un Producto o Servicio a la Factura.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ElseIf ErrorMovtosCxP Then + Alert("Ocurrió un Error al agregar las CxP.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ElseIf ErrorMovtosRetIVA Then + Alert("Ocurrió un Error al agregar las Retenciones de IVA.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ElseIf ErrorMovtosRetISR Then + Alert("Ocurrió un Error al agregar las Retenciones de ISR.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ElseIf ErrorMovtosEstimaciones Then + Alert("Ocurrió un Error al agregar las Estimaciones.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ElseIf ErrorMovtosIE Then + Alert("Ocurrió un Error al agregar el movimiento bancario.
Revise sus datos y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ElseIf ErrorMovtosIVA Then + Alert("Ocurrió un Error al agregar el IVA.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ElseIf ErrorMovInv Then + Alert("Ocurrió un Error al agregar el Producto o Servicio al Inventario.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ElseIf TieneError Then + Alert("El total de los IMPORTES del FINANCIAMIENTO debe ser mayor que 0 y menor o igual al total de la compra", TipoMensaje.MsgAdvertencia) + ElseIf ErrorAF Then + Alert("Error al actualizar la vinculacion del Activo Fijo", TipoMensaje.MsgAdvertencia) + ElseIf ErrorAC Then + Alert("Ocurrió un Error al insertar los movimientos contables.", TipoMensaje.MsgError) + GuardaLog($" Error Compras DESCRIPCIÓN DETALLADA {ErrorACMEnsaje.ToString} {vbCrLf} Usuario={UsuarioActual.CveUsuario}, Empresa={UsuarioActual.CveEmpresa}, CveFactura={CveFactura}, CveProveedor={CveProveedor}") + ElseIf ErrorPrepolizaDescuadre Then + Alert(ObjConta.MensajePolizaDescuadre, TipoMensaje.MsgError) + ElseIf ErrorPrepoliza Then + Alert("Ocurrió un Error al verificar los movimientos contables", TipoMensaje.MsgError) + ElseIf ErrorOC Then + Alert("Ocurrió un Error al vincular la Orden(es) de Compra. Por favor vuelva intentar.", TipoMensaje.MsgError) + ElseIf ErrorBitacora Then + Alert("Ocurrió un Error al guardar la refacturación.", TipoMensaje.MsgError) + ElseIf ErrorAddAcarreos Then + Alert("Ocurrio un Error al momento de agregar los acarreos.", TipoMensaje.MsgError) + ElseIf ErrorCreditosCompra Then + Alert("Ocurrió un Error al vincular la compra con el crédito.", TipoMensaje.MsgError) + ElseIf ErrorOtrosGastos Then + Alert("Ocurrió un Error al vincular la compra con la orden de corte.", TipoMensaje.MsgError) + ElseIf ErrorSATPS Then + Alert("Ocurrió un Error al actualizar el producto/servicio SAT.", TipoMensaje.MsgError) + ElseIf ErrorSaldosInvComp Then + Alert("Ocurrió un Error al validar la mercancía recibida por adelantado.", TipoMensaje.MsgError) + End If + + ViewState("CveCompra") = -1 + ObjCompras.RollBack() + If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() + CargaProveedor(CveProveedor, "-1") + Else + Dim MsgAccionAceptar As String = "" + Dim Msg As New StringBuilder + Msg.Append("La compra se registró correctamente") + + + 'ACTUALIZA CVEFACTURA + If Request("CveFactura") IsNot Nothing Then + If Not ObjCompras.UpdateCompraFactura(CveCompra, Request("CveFactura").ToEntero, TxtSerie.Text.Trim, TxtFolio.Text.Trim) Then - TieneError = True - End If - - If UsuarioActual.Empresa.UsaAC Then - MsgAccionAceptar = String.Format("window.opener.location.href = window.opener.location.href; window.open(""/Contabilidad/RegPoliza.aspx?IdPoliza={0}""); window.close();", IdPoliza) - Else - MsgAccionAceptar = "if (window.opener){window.opener.location.href = window.opener.location.href; window.close();}" - End If - Else - MsgAccionAceptar = "location.href =""Compras.aspx""" - End If - - - - 'CUANDO ES REEMBOLSO COMPROBACION Y CAJA CHICA - If UsuarioActual.CveEmpresa.Contiene(1, 119) AndAlso TxtNumeroReembolso.Text.Trim <> "" AndAlso (DdlPersonalReembolso.SelectedValue.ToEntero > 0 Or DdlCuentaCajaChicaReembolso.SelectedValue.ToEntero > 0) Then - If ObjCompras.GetComprobacion(DdlPersonalReembolso.SelectedValue.ToEntero, DdlCuentaCajaChicaReembolso.SelectedValue.ToEntero, TxtNumeroReembolso.Text.Trim, UsuarioActual.CveEmpresa) Then - Dim CvePreComprobacion As Integer - If ObjCompras.DtResultados.Rows.Count = 0 Then - 'sino existe, creamos la comprobacion - Dim tConcepto As String = If(DdlPersonalReembolso.SelectedValue.ToEntero > 0, DdlPersonalReembolso.SelectedItem.Text, DdlCuentaCajaChicaReembolso.SelectedItem.Text) - tConcepto = String.Format("{0}-{1}", tConcepto, TxtNumeroReembolso.Text.Trim) - - CvePreComprobacion = ObjConta.AddPrePolizas("Compras Comproba", 1, 0, 0, 1, TxtFecha.Text.ToDate, tConcepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - If ObjCompras.AddComprobacion(DdlPersonalReembolso.SelectedValue.ToEntero, DdlCuentaCajaChicaReembolso.SelectedValue.ToEntero, TxtNumeroReembolso.Text.Trim, CvePreComprobacion, UsuarioActual.CveEmpresa) > 0 Then - - End If - Else - 'si ya existe, obtenemos la prepóliza - CvePreComprobacion = ObjCompras.DtResultados.FiltroPrimeroValor("CvePrePoliza").ToEntero - End If - - ObjConta.PrePolizaUnificacion(CvePreComprobacion, CvePrePoliza) - End If - - End If - - - - 'AJUSTA POLIZA - If IdPoliza > 0 Then - PolizaFolio = ObjContaAC.Folio - ObjContaAC.AjustaPoliza(IdPoliza) - Msg.AppendFormat("

Ver Póliza", IdPoliza) - End If - - If CveMovimientoInventario > 0 Then - Dim TempParametros = Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoInventario)) - Msg.AppendFormat("
Ver Movimiento de Almacen", CveMovimientoInventario) - Msg.AppendFormat("
Imprimir Entrada Almacen", TempParametros) - End If - + TieneError = True + End If + + If UsuarioActual.Empresa.UsaAC Then + MsgAccionAceptar = String.Format("window.opener.location.href = window.opener.location.href; window.open(""/Contabilidad/RegPoliza.aspx?IdPoliza={0}""); window.close();", IdPoliza) + Else + MsgAccionAceptar = "If (window.opener){window.opener.location.href = window.opener.location.href; window.close();}" + End If + Else + MsgAccionAceptar = "location.href =""Compras.aspx""" + End If + + + + 'CUANDO ES REEMBOLSO COMPROBACION Y CAJA CHICA + If UsuarioActual.CveEmpresa.Contiene(1, 119) AndAlso TxtNumeroReembolso.Text.Trim <> "" AndAlso (DdlPersonalReembolso.SelectedValue.ToEntero > 0 Or DdlCuentaCajaChicaReembolso.SelectedValue.ToEntero > 0) Then + If ObjCompras.GetComprobacion(DdlPersonalReembolso.SelectedValue.ToEntero, DdlCuentaCajaChicaReembolso.SelectedValue.ToEntero, TxtNumeroReembolso.Text.Trim, UsuarioActual.CveEmpresa) Then + Dim CvePreComprobacion As Integer + If ObjCompras.DtResultados.Rows.Count = 0 Then + 'sino existe, creamos la comprobacion + Dim tConcepto As String = If(DdlPersonalReembolso.SelectedValue.ToEntero > 0, DdlPersonalReembolso.SelectedItem.Text, DdlCuentaCajaChicaReembolso.SelectedItem.Text) + tConcepto = String.Format("{0}-{1}", tConcepto, TxtNumeroReembolso.Text.Trim) + + CvePreComprobacion = ObjConta.AddPrePolizas("Compras Comproba", 1, 0, 0, 1, TxtFecha.Text.ToDate, tConcepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + If ObjCompras.AddComprobacion(DdlPersonalReembolso.SelectedValue.ToEntero, DdlCuentaCajaChicaReembolso.SelectedValue.ToEntero, TxtNumeroReembolso.Text.Trim, CvePreComprobacion, UsuarioActual.CveEmpresa) > 0 Then + + End If + Else + 'si ya existe, obtenemos la prepóliza + CvePreComprobacion = ObjCompras.DtResultados.FiltroPrimeroValor("CvePrePoliza").ToEntero + End If + + ObjConta.PrePolizaUnificacion(CvePreComprobacion, CvePrePoliza) + End If + + End If + + + + 'AJUSTA POLIZA + If IdPoliza > 0 Then + PolizaFolio = ObjContaAC.Folio + ObjContaAC.AjustaPoliza(IdPoliza) + Msg.AppendFormat("

Ver Póliza", IdPoliza) + End If + + If CveMovimientoInventario > 0 Then + Dim TempParametros = Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoInventario)) + Msg.AppendFormat("
Ver Movimiento de Almacen", CveMovimientoInventario) + Msg.AppendFormat("
Imprimir Entrada Almacen", TempParametros) + End If + If Not ObjCompras.UpdateCompraPrePoliza(TxtFecha.Text.ToDate, PolizaFolio.ToString, IdPoliza, CvePrePoliza, CveCompra, 0) Then TieneError = True End If - If EntregaDirecta Then - Msg.AppendFormat($"
Recibir mercancía de entrega directa.") - End If - + If EntregaDirecta Then + Msg.AppendFormat($"
Recibir mercancía de entrega directa.") + End If + If Not TieneError Then ObjCompras.Commit() If ObjContaAC IsNot Nothing Then ObjContaAC.Commit() @@ -8003,363 +8113,363 @@ Partial Class Compras_Compras ObjCompras.RollBack() If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() Alert("Ocurrio un error al guardar la compra. Por favor intente nuevamente.", TipoMensaje.MsgError) - End If - - Alert(Msg.ToString, TipoMensaje.MsgInformacion, MsgAccionAceptar) - - End If - - Else - ObjCompras.RollBack() - If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() - Alert("Ocurrio un error al guardar la compra. Por favor intente nuevamente.", TipoMensaje.MsgError) - End If - - - Else - Alert("Debe seleccionar un Funcionario/Empleado o Caja Chica para Reembolsos. Por favor vuelva a intentar.", TipoMensaje.MsgError) - ObjCompras.RollBack() - If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() - End If - - Else - Alert("Ocurrió un error al agregar el movimiento bancario.
Revise sus datos de pago y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ObjCompras.RollBack() - End If - - End If - - Catch ex As Exception - ObjCompras.RollBack() - If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() - Alert("Ocurrió un error al registrar la compra y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgError) - GuardaLog($"Ocurrió un error al registrar la compra y cualquier detalle comuníquese a Soporte Técnico : {ex}") - ViewState("CveCompra") = -1 - End Try - ObjAcar.Dispose() - ObjCompras.Dispose() - ObjConta.Dispose() - ObjIE.Dispose() - ObjInventario.Dispose() - ObjAF.Dispose() - ObjOC.Dispose() - ObjProveedores.Dispose() - ObjCGame.Dispose() - ObjProductosServicios.Dispose() - End If - End Sub - - Protected Sub TxtCodigo_TextChanged(sender As Object, e As System.EventArgs) Handles TxtCodigo.TextChanged - Dim ObjProveedores As New ClsCompProveedores() - - Dim Codigo As String = "-1" - If TxtCodigo.Text.Trim <> String.Empty Then Codigo = TxtCodigo.Text.Trim - - If Codigo <> "-1" Then - If ObjProveedores.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, -1, Codigo, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa) Then - If ObjProveedores.DtResultados.Rows.Count > 0 Then - HdnCveProveedor.Value = ObjProveedores.CveProveedor.ToString - Else - Alert("No se encontró el Proveedor con el código: " & TxtCodigo.Text.Trim & ".", Extensiones.TipoMensaje.MsgAdvertencia) - End If - End If - ObjProveedores.Dispose() - BtnBuscarProveedor_Click(sender, e) - End If - End Sub - - Protected Sub ImgSubProyecto_Click(sender As Object, e As EventArgs) Handles ImgSubProyecto.Click - DdlAsignarProyecto.SelectedValue = "-1" - CargaSubProyectoAsignado() - RegistraScript(String.Format("$('#{0}').modal('show');", "DivAplicaSubProyecto")) - End Sub - - Protected Sub BtnEliminarCompra_Click(sender As Object, e As EventArgs) Handles BtnEliminarCompra.Click - - Dim ObjAC As ClsContPAQi = Nothing - Dim Comp As New ClsCompras() - Dim ObjEventos As New ClsOIEventos(Comp.IniciaTransacSQL()) - Dim ObjConta As New ClsContabilidad(Comp.IniciaTransacSQL()) - - - Dim ErrorCompra = False - - If (UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.UsaContabilidad) AndAlso IdPoliza > 0 Then - ObjAC = New ClsContPAQi(UsuarioActual.Empresa) - ObjAC.IniciaTransacSQL() - If Not ObjAC.RemovePoliza(IdPoliza) Then - ErrorCompra = True - End If - End If - - If Not ErrorCompra Then - For Each gvr As GridViewRow In GvEB.Rows - If Not ObjEventos.RemoveEvento(gvr.DataKey("CveEvento").ToString.ToEntero, UsuarioActual.CveEmpresa) Then - ErrorCompra = True - Exit For - End If - Next - End If - - If Not ErrorCompra Then - If Not ObjConta.UpdatePrePolizasDetalleBloquear(CvePrePoliza, False) Then - ErrorCompra = True - End If - End If - - If Not ErrorCompra Then - If Not Comp.DeleteCompra(CveCompra, False) Then - ErrorCompra = True - End If - End If - - If Not ErrorCompra Then - Alert("La Compra ha sido eliminada.", TipoMensaje.MsgInformacion, "document.location.href=""/Compras/Compras.aspx""") - If ObjAC IsNot Nothing Then ObjAC.Commit() - Comp.Commit() - Else - Alert("La Compra no ha sido eliminada.", TipoMensaje.MsgAdvertencia) - If ObjAC IsNot Nothing Then ObjAC.RollBack() - Comp.RollBack() - End If - - If ObjAC IsNot Nothing Then ObjAC.Dispose() - Comp.Dispose() - ObjConta.Dispose() - End Sub - - Protected Sub BtnAceptarAnticipos_Click(sender As Object, e As System.EventArgs) Handles BtnAceptarAnticipos.Click - - If EstatusAlmacen = 1 Then - Alert("La compra encuentra pendiente de devolución de almacén, por lo cual no se puede amortizar el documento.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - 'SI TIENE PENDIENTES POR RECIBIR EN ALMACEN, ESTOS PENDIENTES SE PUEDEN QUEMAR CON LAS NC APLICADAS - If CveCompra > 0 And GvInvMov.Rows.Count > 0 And ChkNCInv.Checked Then - CargaNCINV() - Else - GuardaAnticipos(Nothing, Nothing) - End If - - End Sub - - Private Sub GuardaAnticipos(ByRef ObjComprasParametro As ClsCompras, ByRef ObjContaParametro As ClsContabilidad) - - 'SI YA VIENE LOS OBJETOS DE CLASE TOMA LOS DE PARAMETROS - Dim ObjCompra As ClsCompras - Dim ObjConta As ClsContabilidad - - If ObjComprasParametro IsNot Nothing And ObjContaParametro IsNot Nothing Then - ObjCompra = ObjComprasParametro - ObjConta = ObjContaParametro - Else - ObjCompra = New ClsCompras - ObjConta = New ClsContabilidad(ObjCompra.IniciaTransacSQL) - End If - - - Dim Contador As Integer = 0 - Dim Importe As Double = 0 - Dim ErrorMovtosCxP As Integer = 0 - Dim Fecha As Date - - If ListaDocumentos Is Nothing And Not ListaDocumentos.Count > 0 Then - For Each gvr As GridViewRow In GVAnticipos.Rows - If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then - Contador += 1 - 'If gvr.DataKey("Fecha").ToDate > Fecha Then Fecha = gvr.DataKey("Fecha").ToDate 'guardo la fecha mayor - Importe += gvr.FCTextBox("TxtAnticipo").Text.ToDouble + End If + + Alert(Msg.ToString, TipoMensaje.MsgInformacion, MsgAccionAceptar) + + End If + + Else + ObjCompras.RollBack() + If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() + Alert("Ocurrio un error al guardar la compra. Por favor intente nuevamente.", TipoMensaje.MsgError) + End If + + + Else + Alert("Debe seleccionar un Funcionario/Empleado o Caja Chica para Reembolsos. Por favor vuelva a intentar.", TipoMensaje.MsgError) + ObjCompras.RollBack() + If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() + End If + + Else + Alert("Ocurrió un error al agregar el movimiento bancario.
Revise sus datos de pago y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ObjCompras.RollBack() + End If + + End If + + Catch ex As Exception + ObjCompras.RollBack() + If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() + Alert("Ocurrió un error al registrar la compra y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgError) + GuardaLog($"Ocurrió un error al registrar la compra y cualquier detalle comuníquese a Soporte Técnico : {ex}") + ViewState("CveCompra") = -1 + End Try + ObjAcar.Dispose() + ObjCompras.Dispose() + ObjConta.Dispose() + ObjIE.Dispose() + ObjInventario.Dispose() + ObjAF.Dispose() + ObjOC.Dispose() + ObjProveedores.Dispose() + ObjCGame.Dispose() + ObjProductosServicios.Dispose() + End If + End Sub + + Protected Sub TxtCodigo_TextChanged(sender As Object, e As System.EventArgs) Handles TxtCodigo.TextChanged + Dim ObjProveedores As New ClsCompProveedores() + + Dim Codigo As String = "-1" + If TxtCodigo.Text.Trim <> String.Empty Then Codigo = TxtCodigo.Text.Trim + + If Codigo <> "-1" Then + If ObjProveedores.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, -1, Codigo, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa) Then + If ObjProveedores.DtResultados.Rows.Count > 0 Then + HdnCveProveedor.Value = ObjProveedores.CveProveedor.ToString + Else + Alert("No se encontró el Proveedor con el código: " & TxtCodigo.Text.Trim & ".", Extensiones.TipoMensaje.MsgAdvertencia) + End If + End If + ObjProveedores.Dispose() + BtnBuscarProveedor_Click(sender, e) + End If + End Sub + + Protected Sub ImgSubProyecto_Click(sender As Object, e As EventArgs) Handles ImgSubProyecto.Click + DdlAsignarProyecto.SelectedValue = "-1" + CargaSubProyectoAsignado() + RegistraScript(String.Format("$('#{0}').modal('show');", "DivAplicaSubProyecto")) + End Sub + + Protected Sub BtnEliminarCompra_Click(sender As Object, e As EventArgs) Handles BtnEliminarCompra.Click + + Dim ObjAC As ClsContPAQi = Nothing + Dim Comp As New ClsCompras() + Dim ObjEventos As New ClsOIEventos(Comp.IniciaTransacSQL()) + Dim ObjConta As New ClsContabilidad(Comp.IniciaTransacSQL()) + + + Dim ErrorCompra = False + + If (UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.UsaContabilidad) AndAlso IdPoliza > 0 Then + ObjAC = New ClsContPAQi(UsuarioActual.Empresa) + ObjAC.IniciaTransacSQL() + If Not ObjAC.RemovePoliza(IdPoliza) Then + ErrorCompra = True + End If + End If + + If Not ErrorCompra Then + For Each gvr As GridViewRow In GvEB.Rows + If Not ObjEventos.RemoveEvento(gvr.DataKey("CveEvento").ToString.ToEntero, UsuarioActual.CveEmpresa) Then + ErrorCompra = True + Exit For + End If + Next + End If + + If Not ErrorCompra Then + If Not ObjConta.UpdatePrePolizasDetalleBloquear(CvePrePoliza, False) Then + ErrorCompra = True + End If + End If + + If Not ErrorCompra Then + If Not Comp.DeleteCompra(CveCompra, False) Then + ErrorCompra = True + End If + End If + + If Not ErrorCompra Then + Alert("La Compra ha sido eliminada.", TipoMensaje.MsgInformacion, "document.location.href=""/Compras/Compras.aspx""") + If ObjAC IsNot Nothing Then ObjAC.Commit() + Comp.Commit() + Else + Alert("La Compra no ha sido eliminada.", TipoMensaje.MsgAdvertencia) + If ObjAC IsNot Nothing Then ObjAC.RollBack() + Comp.RollBack() + End If + + If ObjAC IsNot Nothing Then ObjAC.Dispose() + Comp.Dispose() + ObjConta.Dispose() + End Sub + + Protected Sub BtnAceptarAnticipos_Click(sender As Object, e As System.EventArgs) Handles BtnAceptarAnticipos.Click + + If EstatusAlmacen = 1 Then + Alert("La compra encuentra pendiente de devolución de almacén, por lo cual no se puede amortizar el documento.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'SI TIENE PENDIENTES POR RECIBIR EN ALMACEN, ESTOS PENDIENTES SE PUEDEN QUEMAR CON LAS NC APLICADAS + If CveCompra > 0 And GvInvMov.Rows.Count > 0 And ChkNCInv.Checked Then + CargaNCINV() + Else + GuardaAnticipos(Nothing, Nothing) + End If + + End Sub + + Private Sub GuardaAnticipos(ByRef ObjComprasParametro As ClsCompras, ByRef ObjContaParametro As ClsContabilidad) + + 'SI YA VIENE LOS OBJETOS DE CLASE TOMA LOS DE PARAMETROS + Dim ObjCompra As ClsCompras + Dim ObjConta As ClsContabilidad + + If ObjComprasParametro IsNot Nothing And ObjContaParametro IsNot Nothing Then + ObjCompra = ObjComprasParametro + ObjConta = ObjContaParametro + Else + ObjCompra = New ClsCompras + ObjConta = New ClsContabilidad(ObjCompra.IniciaTransacSQL) + End If + + + Dim Contador As Integer = 0 + Dim Importe As Double = 0 + Dim ErrorMovtosCxP As Integer = 0 + Dim Fecha As Date + + If ListaDocumentos Is Nothing And Not ListaDocumentos.Count > 0 Then + For Each gvr As GridViewRow In GVAnticipos.Rows + If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then + Contador += 1 + 'If gvr.DataKey("Fecha").ToDate > Fecha Then Fecha = gvr.DataKey("Fecha").ToDate 'guardo la fecha mayor + Importe += gvr.FCTextBox("TxtAnticipo").Text.ToDouble If Math.Round(Importe, 2) - Math.Round(CompraSaldo, 2) > 0.01 Then gvr.FCTextBox("TxtAnticipo").Text = "" : gvr.FCCheckBox("Chk").Checked = False - End If + End If Next - Else - Contador = 1 - End If - - - - - 'If TxtFecha.Text.ToDate > Fecha Then Fecha = TxtFecha.Text.ToDate - Fecha = TxtFechaEjecucion.Text.ToDate - - 'Contador = 0 - If Contador > 0 Then - If ListaDocumentos Is Nothing And Not ListaDocumentos.Count > 0 Then - If Math.Round(Importe, 2) - Math.Round(CompraSaldo, 2) > 0.01 Then - Alert("El Importe seleccionado excede al importe de la compra", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - - ArrAnticipos.Clear() - - If CveCompra > 0 Then - - 'INICIALIZA OBJETOS - If Not (ObjComprasParametro IsNot Nothing And ObjContaParametro IsNot Nothing) Then - ObjCompra = New ClsCompras - ObjConta = New ClsContabilidad(ObjCompra.IniciaTransacSQL) - End If - - Dim CveCompraNC, IdCtaContable, CveCuenta As Integer - - Dim PorcentajePago, ImporteMovimiento, sumaAmortizacion, sumaAmortizacionCompleto As Decimal - Dim ConceptoPoliza As String = $"Amortización {NombreProveedor} - {TxtSerie.Text}-{TxtFolio.Text}" - Dim CompraUnificada As Boolean = False - Dim IVACompleto As Boolean = False - Dim IdCtaIVAXAcreditar As Integer = 0 - Dim IdCtaIVAAcreditable As Integer = 0 - 'PorcentajeIVA - If GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=TmpDT.MAX("IVAPorcentaje").ToDouble).Rows.Count > 0 Then - IdCtaIVAXAcreditar = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=TmpDT.MAX("IVAPorcentaje").ToDouble).Rows(0)("IdCtaIVAXAcreditar").ToString.ToEntero - IdCtaIVAAcreditable = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=TmpDT.MAX("IVAPorcentaje").ToDouble).Rows(0)("IdCtaIVAAcreditable").ToString.ToEntero - End If - - Try - Dim CveIE As Integer = -1 - - If EmpresaPrueba Then - Dim CvePlantillaPoliza = 52 - Dim tipoCambio As Decimal - Dim tipoCambioNC As Decimal - Dim alertaContabilizacion As New StringBuilder - Dim idCuentaContabilizacion As Long = 1 - Dim CveCuentaContabilizacion As Long = 1 - Dim CvePrepolizaPadre As Integer = CvePrePoliza - Dim CuentasContablesInvalidas As New StringBuilder - Dim CuentasContablesInvalidasSIG As New StringBuilder - - If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then - tipoCambio = GlobalTipoCambio(Fecha).ToString.ToDecimal - Else - tipoCambio = 1 - End If - - '[IPP] PARCHE PARA AMORTIZACIÓN NC - Dim TipoCambioCompra = Me.TipoCambio.ToDecimal - - Dim CvePrePolizaNueva As Integer = ObjConta.AddPrePolizas("Compras/Anticipos", 52, Importe, Importe, DdlMoneda.SelectedValue.ToEntero, Fecha, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - For Each gvr As GridViewRow In GVAnticipos.Rows - If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then - - CveCompraNC = gvr.DataKey("CveCompra").ToEntero - tipoCambioNC = If(ChkPagarConPesos.Checked, GlobalTipoCambio(gvr.DataKey("Fecha").ToDate).ToDecimal, gvr.DataKey("TCCompra").ToDecimal) - sumaAmortizacion = 0 - - If CvePrePolizaNueva > 0 Then - If ObjConta.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPoliza) Then - - For Each Row As DataRow In ObjConta.DtResultados.Rows - - Dim ConceptoContable = Row("CveConcepto").ToString.ToEntero - Dim TipoMovimiento As Boolean = If(Row("TipoMovto").ToString = "True", True, False) - ImporteMovimiento = 0 - IdCtaContable = 0 - CveCuenta = 0 - Dim Concepto As String = String.Format("{0}-{1}", TxtSerie.Text, TxtFolio.Text) - Dim importeMN As Decimal = 0 - Dim Multiplicador As Integer = If(Row("Multiplicador").ToString.ToEntero = 1, 1, -1) - Dim PorcentajeImpuesto As Decimal = 0 - Dim ConceptoPartida As String = String.Format("{0}-{1}", TxtSerie.Text, TxtFolio.Text) - - - Select Case ConceptoContable - Case 265 'Amortización Anticipos Compras - If gvr.DataKey("TipoDocto").Contiene("Ant") Then - CveIE = -1 - ImporteMovimiento = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal - importeMN = ImporteMovimiento * tipoCambioNC - sumaAmortizacion += ImporteMovimiento + Else + Contador = 1 + End If + + + + + 'If TxtFecha.Text.ToDate > Fecha Then Fecha = TxtFecha.Text.ToDate + Fecha = TxtFechaEjecucion.Text.ToDate + + 'Contador = 0 + If Contador > 0 Then + If ListaDocumentos Is Nothing And Not ListaDocumentos.Count > 0 Then + If Math.Round(Importe, 2) - Math.Round(CompraSaldo, 2) > 0.01 Then + Alert("El Importe seleccionado excede al importe de la compra", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + + ArrAnticipos.Clear() + + If CveCompra > 0 Then + + 'INICIALIZA OBJETOS + If Not (ObjComprasParametro IsNot Nothing And ObjContaParametro IsNot Nothing) Then + ObjCompra = New ClsCompras + ObjConta = New ClsContabilidad(ObjCompra.IniciaTransacSQL) + End If + + Dim CveCompraNC, IdCtaContable, CveCuenta As Integer + + Dim PorcentajePago, ImporteMovimiento, sumaAmortizacion, sumaAmortizacionCompleto As Decimal + Dim ConceptoPoliza As String = $"Amortización {NombreProveedor} - {TxtSerie.Text}-{TxtFolio.Text}" + Dim CompraUnificada As Boolean = False + Dim IVACompleto As Boolean = False + Dim IdCtaIVAXAcreditar As Integer = 0 + Dim IdCtaIVAAcreditable As Integer = 0 + 'PorcentajeIVA + If GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=TmpDT.MAX("IVAPorcentaje").ToDouble).Rows.Count > 0 Then + IdCtaIVAXAcreditar = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=TmpDT.MAX("IVAPorcentaje").ToDouble).Rows(0)("IdCtaIVAXAcreditar").ToString.ToEntero + IdCtaIVAAcreditable = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=TmpDT.MAX("IVAPorcentaje").ToDouble).Rows(0)("IdCtaIVAAcreditable").ToString.ToEntero + End If + + Try + Dim CveIE As Integer = -1 + + If EmpresaPrueba Then + Dim CvePlantillaPoliza = 52 + Dim tipoCambio As Decimal + Dim tipoCambioNC As Decimal + Dim alertaContabilizacion As New StringBuilder + Dim idCuentaContabilizacion As Long = 1 + Dim CveCuentaContabilizacion As Long = 1 + Dim CvePrepolizaPadre As Integer = CvePrePoliza + Dim CuentasContablesInvalidas As New StringBuilder + Dim CuentasContablesInvalidasSIG As New StringBuilder + + If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then + tipoCambio = GlobalTipoCambio(Fecha).ToString.ToDecimal + Else + tipoCambio = 1 + End If + + '[IPP] PARCHE PARA AMORTIZACIÓN NC + Dim TipoCambioCompra = Me.TipoCambio.ToDecimal + + Dim CvePrePolizaNueva As Integer = ObjConta.AddPrePolizas("Compras/Anticipos", 52, Importe, Importe, DdlMoneda.SelectedValue.ToEntero, Fecha, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + For Each gvr As GridViewRow In GVAnticipos.Rows + If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then + + CveCompraNC = gvr.DataKey("CveCompra").ToEntero + tipoCambioNC = If(ChkPagarConPesos.Checked, GlobalTipoCambio(gvr.DataKey("Fecha").ToDate).ToDecimal, gvr.DataKey("TCCompra").ToDecimal) + sumaAmortizacion = 0 + + If CvePrePolizaNueva > 0 Then + If ObjConta.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPoliza) Then + + For Each Row As DataRow In ObjConta.DtResultados.Rows + + Dim ConceptoContable = Row("CveConcepto").ToString.ToEntero + Dim TipoMovimiento As Boolean = If(Row("TipoMovto").ToString = "True", True, False) + ImporteMovimiento = 0 + IdCtaContable = 0 + CveCuenta = 0 + Dim Concepto As String = String.Format("{0}-{1}", TxtSerie.Text, TxtFolio.Text) + Dim importeMN As Decimal = 0 + Dim Multiplicador As Integer = If(Row("Multiplicador").ToString.ToEntero = 1, 1, -1) + Dim PorcentajeImpuesto As Decimal = 0 + Dim ConceptoPartida As String = String.Format("{0}-{1}", TxtSerie.Text, TxtFolio.Text) + + + Select Case ConceptoContable + Case 265 'Amortización Anticipos Compras + If gvr.DataKey("TipoDocto").Contiene("Ant") Then + CveIE = -1 + ImporteMovimiento = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal + importeMN = ImporteMovimiento * tipoCambioNC + sumaAmortizacion += ImporteMovimiento sumaAmortizacionCompleto += ImporteMovimiento If ChkPagarConPesos.Checked Then ImporteMovimiento = ImporteMovimiento * GlobalTipoCambio(gvr.DataKey("Fecha").ToDate).ToDecimal ElseIf ChkPagarConDolares.Checked Then ImporteMovimiento = ImporteMovimiento / gvr.DataKey("TCCompra").ToDecimal - End If - - If DdlMoneda.SelectedValue.ToEntero <> 1 Then - IdCtaContable = CtaProveedorAnticiposExtranjera - CveCuenta = CveCuentaProveedorAnticiposExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, "", ConceptoContable, "", Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioNC, CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then - If UsuarioActual.CveEmpresa.Contiene(119) Then - IdCtaContable = CtaProveedorAnticiposComplementaria - CveCuenta = CveCuentaProveedorAnticiposComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, importeMN - ImporteMovimiento, "", 266, "", Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN - ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioNC, CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - Exit Select - End If - End If - Else - ErrorMovtosCxP = 1 - Exit Select - End If - Else - IdCtaContable = CtaProveedorAnticipos - CveCuenta = CveCuentaProveedorAnticipos - If ImporteMovimiento <> 0 Then - PorcentajePago = ImporteMovimiento / TxtTotal.Text.ToDecimal - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, "", ConceptoContable, "", Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(tipoCambio = 1, 0, ImporteMovimiento), CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - End If - End If - End If - End If - - ImporteMovimiento = 0 - Case 60 'Nota de Credito - If gvr.DataKey("TipoDocto").Contiene("NC", "DEV") Then - CveIE = -1 - ImporteMovimiento = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal - importeMN = ImporteMovimiento * tipoCambioNC - sumaAmortizacion += ImporteMovimiento + End If + + If DdlMoneda.SelectedValue.ToEntero <> 1 Then + IdCtaContable = CtaProveedorAnticiposExtranjera + CveCuenta = CveCuentaProveedorAnticiposExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, "", ConceptoContable, "", Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioNC, CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then + If UsuarioActual.CveEmpresa.Contiene(119) Then + IdCtaContable = CtaProveedorAnticiposComplementaria + CveCuenta = CveCuentaProveedorAnticiposComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, importeMN - ImporteMovimiento, "", 266, "", Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN - ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioNC, CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + Exit Select + End If + End If + Else + ErrorMovtosCxP = 1 + Exit Select + End If + Else + IdCtaContable = CtaProveedorAnticipos + CveCuenta = CveCuentaProveedorAnticipos + If ImporteMovimiento <> 0 Then + PorcentajePago = ImporteMovimiento / TxtTotal.Text.ToDecimal + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, "", ConceptoContable, "", Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(tipoCambio = 1, 0, ImporteMovimiento), CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + End If + End If + End If + End If + + ImporteMovimiento = 0 + Case 60 'Nota de Credito + If gvr.DataKey("TipoDocto").Contiene("NC", "DEV") Then + CveIE = -1 + ImporteMovimiento = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal + importeMN = ImporteMovimiento * tipoCambioNC + sumaAmortizacion += ImporteMovimiento sumaAmortizacionCompleto += ImporteMovimiento If ChkPagarConPesos.Checked Then ImporteMovimiento = ImporteMovimiento * GlobalTipoCambio(gvr.DataKey("Fecha").ToDate).ToDecimal ElseIf ChkPagarConDolares.Checked Then ImporteMovimiento = ImporteMovimiento / gvr.DataKey("TCCompra").ToDecimal - End If - - If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then - IdCtaContable = CtaProveedorExtranjera - CveCuenta = CveCuentaProveedorExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, ConceptoPartida, ConceptoContable, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioNC, CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then - IdCtaContable = CtaProveedorComplementaria - CveCuenta = CveCuentaProveedorComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, importeMN - ImporteMovimiento, ConceptoPartida, 235, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN - ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioNC, CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - Exit Select - End If - Else - ErrorMovtosCxP = 1 - Exit Select - End If - Else - IdCtaContable = CtaProveedor - CveCuenta = CveCuentaProveedor - If ImporteMovimiento <> 0 Then - PorcentajePago = ImporteMovimiento / TxtTotal.Text.ToDecimal - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, ConceptoPartida, ConceptoContable, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(tipoCambio = 1, 0, ImporteMovimiento), CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - End If - End If - End If - End If - - ImporteMovimiento = 0 - Case 21 'Anticipo - If gvr.DataKey("TipoDocto") = "Egsc" Then - CveCompraNC = -1 - CveIE = gvr.DataKey("CveIE").ToEntero - ImporteMovimiento = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal - sumaAmortizacion += ImporteMovimiento - sumaAmortizacionCompleto += ImporteMovimiento - IdCtaContable = CtaProveedorAnticipos + End If + + If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then + IdCtaContable = CtaProveedorExtranjera + CveCuenta = CveCuentaProveedorExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, ConceptoPartida, ConceptoContable, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioNC, CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then + IdCtaContable = CtaProveedorComplementaria + CveCuenta = CveCuentaProveedorComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, importeMN - ImporteMovimiento, ConceptoPartida, 235, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN - ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioNC, CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + Exit Select + End If + Else + ErrorMovtosCxP = 1 + Exit Select + End If + Else + IdCtaContable = CtaProveedor + CveCuenta = CveCuentaProveedor + If ImporteMovimiento <> 0 Then + PorcentajePago = ImporteMovimiento / TxtTotal.Text.ToDecimal + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, ConceptoPartida, ConceptoContable, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(tipoCambio = 1, 0, ImporteMovimiento), CveCompraAmortizacion:=CveCompra, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + End If + End If + End If + End If + + ImporteMovimiento = 0 + Case 21 'Anticipo + If gvr.DataKey("TipoDocto") = "Egsc" Then + CveCompraNC = -1 + CveIE = gvr.DataKey("CveIE").ToEntero + ImporteMovimiento = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal + sumaAmortizacion += ImporteMovimiento + sumaAmortizacionCompleto += ImporteMovimiento + IdCtaContable = CtaProveedorAnticipos CveCuenta = CveCuentaProveedorAnticipos PorcentajePago = ImporteMovimiento / TxtTotal.Text.ToDecimal @@ -8373,533 +8483,549 @@ Partial Class Compras_Compras If ImporteMovimiento <> 0 Then Dim TipoCambioAnt = gvr.DataKey("TCCompra").ToDecimal - - Dim usacomplementariaAnticipo As Boolean = False + + Dim usacomplementariaAnticipo As Boolean = False usacomplementariaAnticipo = If(TipoCambioAnt > 1 AndAlso UsuarioActual.CveEmpresa.Contiene(1, 119), True, False) - Dim ImporteAnt As Decimal = ImporteMovimiento - Dim ImporteAntMN As Decimal = ImporteAnt * TipoCambioAnt - If usacomplementariaAnticipo Then - IdCtaContable = CtaProveedorAnticiposComplementaria - CveCuenta = CveCuentaProveedorAnticiposComplementaria - ImporteAntMN = TipoCambioAnt * ImporteAnt - ImporteAnt - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteAnt, "", 266, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=CveCompraNC, CveProveedor:=CveProveedor, CvePersonal:=CvePersonal, ImporteMX:=ImporteAntMN, ImporteME:=ImporteAnt, TipoCambio:=TipoCambioAnt, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - End If - ImporteAntMN = ImporteAnt - End If - - If TipoCambioAnt > 1 Then - IdCtaContable = CtaProveedorAnticiposExtranjera - CveCuenta = CveCuentaProveedorAnticiposExtranjera - End If - - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteAnt, "", ConceptoContable, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteAntMN, CvePrePolizaOriginal:=CvePrePolizaNueva, ImporteME:=If(tipoCambio = 1, 0, ImporteAnt), CveCompraAmortizacion:=CveCompraNC, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 + Dim ImporteAnt As Decimal = ImporteMovimiento + Dim ImporteAntMN As Decimal = ImporteAnt * TipoCambioAnt + If usacomplementariaAnticipo Then + IdCtaContable = CtaProveedorAnticiposComplementaria + CveCuenta = CveCuentaProveedorAnticiposComplementaria + ImporteAntMN = TipoCambioAnt * ImporteAnt - ImporteAnt + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteAnt, "", 266, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=CveCompraNC, CveProveedor:=CveProveedor, CvePersonal:=CvePersonal, ImporteMX:=ImporteAntMN, ImporteME:=ImporteAnt, TipoCambio:=TipoCambioAnt, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + End If + ImporteAntMN = ImporteAnt + End If + + If TipoCambioAnt > 1 Then + IdCtaContable = CtaProveedorAnticiposExtranjera + CveCuenta = CveCuentaProveedorAnticiposExtranjera + End If + + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteAnt, "", ConceptoContable, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteAntMN, CvePrePolizaOriginal:=CvePrePolizaNueva, ImporteME:=If(tipoCambio = 1, 0, ImporteAnt), CveCompraAmortizacion:=CveCompraNC, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 End If If ChkPagarConPesos.Checked Or ChkPagarConDolares.Checked Then ImporteAnt = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal - TipoCambioAnt = If(ChkPagarConPesos.Checked, GlobalTipoCambio(gvr.DataKey("Fecha").ToDate).ToDecimal, gvr.DataKey("TCCompra").ToDecimal) - End If - + TipoCambioAnt = If(ChkPagarConPesos.Checked, GlobalTipoCambio(gvr.DataKey("Fecha").ToDate).ToDecimal, gvr.DataKey("TCCompra").ToDecimal) + End If + Dim TipoCambioDiferencia = If(ChkPagarConDolares.Checked, GlobalTipoCambio(TxtFecha.Text.ToDate), TipoCambioCompra).ToDecimal - If TipoCambioDiferencia <> TipoCambioAnt Then - Dim importeFluctuacion = (ImporteAnt * TipoCambioDiferencia) - (ImporteAnt * TipoCambioAnt) - - If importeFluctuacion > 0 Then - ConceptoContable = 64 - TipoMovimiento = True - IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria - ElseIf importeFluctuacion < 0 Then - ConceptoContable = 65 - TipoMovimiento = False - IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria - End If - - importeFluctuacion = importeFluctuacion.Abs.RoundSQL() - If importeFluctuacion <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, importeFluctuacion, "", ConceptoContable, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeFluctuacion, CvePrePolizaOriginal:=CvePrePolizaNueva, ImporteME:=0, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - End If - End If - End If - - End If - End If - - ImporteMovimiento = 0 - - Case 37 'Deudores Diversos - If gvr.DataKey("TipoDocto") = "DD" Then - CveCompraNC = -1 - CveIE = gvr.DataKey("CveIE").ToEntero - ImporteMovimiento = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal - sumaAmortizacion += ImporteMovimiento - sumaAmortizacionCompleto += ImporteMovimiento - IdCtaContable = CtaProveedorDeudores - CveCuenta = CveCuentaProveedorDeudores - - If ImporteMovimiento <> 0 Then - PorcentajePago = ImporteMovimiento / TxtTotal.Text.ToDecimal - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, "", ConceptoContable, "", Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento * tipoCambio, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(tipoCambio = 1, 0, ImporteMovimiento), CveCompraAmortizacion:=CveCompraNC, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - End If - End If - End If - - ImporteMovimiento = 0 - - Case 17 'Pago Proveedores - Dim TipoCambio17 = tipoCambio - If gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant", "Egsc") Then - TipoCambio17 = TipoCambioCompra - End If - If gvr.DataKey("TipoDocto").Contiene("NC", "DEV") Then - ConceptoContable = 272 - End If - - ImporteMovimiento = sumaAmortizacion - importeMN = ImporteMovimiento * TipoCambio17 - - If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then - IdCtaContable = CtaProveedorExtranjera - CveCuenta = CveCuentaProveedorExtranjera - If ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=TipoCambio17, CveCuenta:=CveCuenta) Then - IdCtaContable = CtaProveedorComplementaria - CveCuenta = CveCuentaProveedorComplementaria - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, importeMN - ImporteMovimiento, Concepto, 206, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN - ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=TipoCambio17, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - Exit Select - End If - Else - ErrorMovtosCxP = 1 - Exit Select - End If - Else - IdCtaContable = CtaProveedor - CveCuenta = CveCuentaProveedor - If ImporteMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(TipoCambio17 = 1, 0, ImporteMovimiento), CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - Exit For - End If - End If - End If - - ImporteMovimiento = 0 - Case 14 'Iva X Acreditar - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If UsuarioActual.Empresa.Funcionalidad(521) = "1" Then - If sumaAmortizacion = CompraSaldo Then + If TipoCambioDiferencia <> TipoCambioAnt Then + Dim importeFluctuacion = (ImporteAnt * TipoCambioDiferencia) - (ImporteAnt * TipoCambioAnt) + + If importeFluctuacion > 0 Then + ConceptoContable = 64 + TipoMovimiento = True + IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria + ElseIf importeFluctuacion < 0 Then + ConceptoContable = 65 + TipoMovimiento = False + IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + End If + + importeFluctuacion = importeFluctuacion.Abs.RoundSQL() + If importeFluctuacion <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, importeFluctuacion, "", ConceptoContable, ConceptoPartida, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeFluctuacion, CvePrePolizaOriginal:=CvePrePolizaNueva, ImporteME:=0, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + End If + End If + End If + + End If + End If + + ImporteMovimiento = 0 + + Case 37 'Deudores Diversos + If gvr.DataKey("TipoDocto") = "DD" Then + CveCompraNC = -1 + CveIE = gvr.DataKey("CveIE").ToEntero + ImporteMovimiento = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal + sumaAmortizacion += ImporteMovimiento + sumaAmortizacionCompleto += ImporteMovimiento + IdCtaContable = CtaProveedorDeudores + CveCuenta = CveCuentaProveedorDeudores + + If ImporteMovimiento <> 0 Then + PorcentajePago = ImporteMovimiento / TxtTotal.Text.ToDecimal + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, "", ConceptoContable, "", Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento * tipoCambio, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(tipoCambio = 1, 0, ImporteMovimiento), CveCompraAmortizacion:=CveCompraNC, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + End If + End If + End If + + ImporteMovimiento = 0 + + Case 17 'Pago Proveedores + + If CveTipoConcepto = 2 Then ConceptoContable = 308 'cuando es acreedor + If CveMoneda > 1 Then + Select Case ConceptoContable + Case 17 + ConceptoContable = 312 + Case 308 + ConceptoContable = 309 + Case Else + End Select + End If + + Dim TipoCambio17 = tipoCambio + If gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant", "Egsc") Then + TipoCambio17 = TipoCambioCompra + End If + If gvr.DataKey("TipoDocto").Contiene("NC", "DEV") Then + ConceptoContable = 272 + End If + + ImporteMovimiento = sumaAmortizacion + importeMN = ImporteMovimiento * TipoCambio17 + + If DdlMoneda.SelectedValue.ToEntero <> 1 And UsuarioActual.CveEmpresa.Contiene(119) Then + IdCtaContable = CtaProveedorExtranjera + CveCuenta = CveCuentaProveedorExtranjera + If ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=TipoCambio17, CveCuenta:=CveCuenta) Then + + Dim CveConceptoContableComplementaria As Integer = 206 + If CveTipoConcepto = 2 Then CveConceptoContableComplementaria = 310 'cuando es acreedor + + IdCtaContable = CtaProveedorComplementaria + CveCuenta = CveCuentaProveedorComplementaria + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, importeMN - ImporteMovimiento, Concepto, CveConceptoContableComplementaria, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN - ImporteMovimiento, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=ImporteMovimiento, TipoCambio:=TipoCambio17, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + Exit Select + End If + Else + ErrorMovtosCxP = 1 + Exit Select + End If + Else + IdCtaContable = CtaProveedor + CveCuenta = CveCuentaProveedor + If ImporteMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveCompraAmortizacion:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(TipoCambio17 = 1, 0, ImporteMovimiento), CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + Exit For + End If + End If + End If + + ImporteMovimiento = 0 + Case 14 'Iva X Acreditar + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If UsuarioActual.Empresa.Funcionalidad(521) = "1" Then + If sumaAmortizacion = CompraSaldo Then ImporteMovimiento = TxtIVA.Text.ToDecimal If ImporteMovimiento > 0 Then IVACompleto = True End If - Else - ImporteMovimiento = 0 - End If - Else - ImporteMovimiento = Math.Round(PorcentajePago * TxtIVA.Text.ToDecimal, 2) - End If - importeMN = ImporteMovimiento * tipoCambio - PorcentajeImpuesto = TmpDT.MAX("IVAPorcentaje").ToDecimal - IdCtaContable = If(IdCtaIVAXAcreditar > 0, IdCtaIVAXAcreditar, 0) - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditar").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditarSIG").ToString.ToEntero - End If - End If - End If - Case 19 'Iva Acreditado - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If UsuarioActual.Empresa.Funcionalidad(521) = "1" Then - If sumaAmortizacion = CompraSaldo Then - ImporteMovimiento = TxtIVA.Text.ToDecimal - IVACompleto = True - Else - ImporteMovimiento = 0 - End If - Else - ImporteMovimiento = Math.Round(PorcentajePago * TxtIVA.Text.ToDecimal, 2) - End If - importeMN = ImporteMovimiento * tipoCambio - PorcentajeImpuesto = TmpDT.MAX("IVAPorcentaje").ToDecimal - IdCtaContable = If(IdCtaIVAAcreditable > 0, IdCtaIVAAcreditable, 0) - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditable").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditableSIG").ToString.ToEntero - End If - End If - End If - Case 15 'RetIVA x Acreditar Honorarios/Serv. Prof. - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 1 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(307).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(307).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - Case 22 'RetIVA Acreditable Honorarios/Serv. Prof. - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 1 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) + Else + ImporteMovimiento = 0 + End If + Else + ImporteMovimiento = Math.Round(PorcentajePago * TxtIVA.Text.ToDecimal, 2) + End If + importeMN = ImporteMovimiento * tipoCambio + PorcentajeImpuesto = TmpDT.MAX("IVAPorcentaje").ToDecimal + IdCtaContable = If(IdCtaIVAXAcreditar > 0, IdCtaIVAXAcreditar, 0) + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditar").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIVAxAcreditarSIG").ToString.ToEntero + End If + End If + End If + Case 19 'Iva Acreditado + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If UsuarioActual.Empresa.Funcionalidad(521) = "1" Then + If sumaAmortizacion = CompraSaldo Then + ImporteMovimiento = TxtIVA.Text.ToDecimal + IVACompleto = True + Else + ImporteMovimiento = 0 + End If + Else + ImporteMovimiento = Math.Round(PorcentajePago * TxtIVA.Text.ToDecimal, 2) + End If + importeMN = ImporteMovimiento * tipoCambio + PorcentajeImpuesto = TmpDT.MAX("IVAPorcentaje").ToDecimal + IdCtaContable = If(IdCtaIVAAcreditable > 0, IdCtaIVAAcreditable, 0) + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditable").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaIVAAcreditableSIG").ToString.ToEntero + End If + End If + End If + Case 15 'RetIVA x Acreditar Honorarios/Serv. Prof. + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 1 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(307).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(307).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + Case 22 'RetIVA Acreditable Honorarios/Serv. Prof. + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 1 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(308).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(308).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - - + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(308).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(308).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + + If UsuarioActual.Empresa.Funcionalidad(577).ToEntero = 1 Then IdCtaContable = UsuarioActual.Empresa.Funcionalidad(578).ToEntero End If End If - End If - - End If - - - Case 183 'RetIVA x Acreditar Fletes P.F. - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 2 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(309).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(309).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - - Case 184 'RetIVA Acreditable Fletes P.F. - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 2 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(310).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(310).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - - Case 185 'RetIVA x Acreditar Fletes P.M. - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 3 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(311).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(311).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - - Case 186 'RetIVA Acreditable Fletes P.M. - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 3 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(312).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(312).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - Case 248 'RetIVA x Acreditar Arrendamiento - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 4 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(313).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(313).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - - Case 249 'RetIVA Acreditable Arrendamiento - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetIVAConcepto.Items.Count > 0 Then - If DdlRetIVAConcepto.SelectedValue.ToEntero = 4 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetIVA > 0 Then - IdCtaContable = CtaProveedorRetIVA - CveCuenta = CveCuentaProveedorRetIVA - ElseIf UsuarioActual.Empresa.Funcionalidad(314).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(314).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - End If - Case 16 'RetISR x Acreditar - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 1 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetISR > 0 Then - IdCtaContable = CtaProveedorRetISR - CveCuenta = CveCuentaProveedorRetISR - ElseIf UsuarioActual.Empresa.Funcionalidad(315).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(315).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - - Case 23 'RetISR Acreditable - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 1 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetISR > 0 Then - IdCtaContable = CtaProveedorRetISR - CveCuenta = CveCuentaProveedorRetISR - ElseIf UsuarioActual.Empresa.Funcionalidad(316).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(316).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - Case 243 'RetISR X Acreditar Terceros y Arrendamiento - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 2 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetISR > 0 Then - IdCtaContable = CtaProveedorRetISR - CveCuenta = CveCuentaProveedorRetISR - ElseIf UsuarioActual.Empresa.Funcionalidad(317).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(317).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - Case 244 'RetISR Acreditable Terceros y Arrendamiento - If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then - If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 2 Then - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) - importeMN = ImporteMovimiento * tipoCambio - If CtaProveedorRetISR > 0 Then - IdCtaContable = CtaProveedorRetISR - CveCuenta = CveCuentaProveedorRetISR - ElseIf UsuarioActual.Empresa.Funcionalidad(318).ToEntero > 0 Then - IdCtaContable = UsuarioActual.Empresa.Funcionalidad(318).ToEntero - Else - If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero - End If - End If - End If - End If - End If - Case 64 'GANANCIA - If gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then 'SOLO SE IMPLEMENTÓ PARA NC - If DdlMoneda.SelectedValue.ToEntero <> 1 Or gvr.DataKey("CveMoneda").ToEntero <> 1 Then - IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria - Dim TipoCambioDiferenciaCambiaria = If(ChkPagarConPesos.Checked, GlobalTipoCambio(gvr.DataKey("Fecha").ToDate).ToDecimal, tipoCambioNC) - Dim TipoCambioDiferenciaCompra = If(ChkPagarConDolares.Checked, GlobalTipoCambio(TxtFecha.Text.ToDate), TipoCambioCompra).ToDecimal - If TipoCambioDiferenciaCompra > TipoCambioDiferenciaCambiaria Then - ImporteMovimiento = (sumaAmortizacion * TipoCambioDiferenciaCompra) - (sumaAmortizacion * TipoCambioDiferenciaCambiaria) - ImporteMovimiento = ImporteMovimiento.RoundSQL() - importeMN = ImporteMovimiento - End If - - If ImporteMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - Exit For - End If - End If - - End If - End If - ImporteMovimiento = 0 - Case 65 'PERDIDA - If gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then 'SOLO SE IMPLEMENTÓ PARA NC - If DdlMoneda.SelectedValue.ToEntero <> 1 Or gvr.DataKey("CveMoneda").ToEntero <> 1 Then - IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria - CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + End If + + End If + + + Case 183 'RetIVA x Acreditar Fletes P.F. + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 2 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(309).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(309).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + + Case 184 'RetIVA Acreditable Fletes P.F. + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 2 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(310).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(310).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + + Case 185 'RetIVA x Acreditar Fletes P.M. + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 3 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(311).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(311).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + + Case 186 'RetIVA Acreditable Fletes P.M. + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 3 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(312).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(312).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + Case 248 'RetIVA x Acreditar Arrendamiento + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 4 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(313).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(313).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + + Case 249 'RetIVA Acreditable Arrendamiento + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetIVAConcepto.Items.Count > 0 Then + If DdlRetIVAConcepto.SelectedValue.ToEntero = 4 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetIVA > 0 Then + IdCtaContable = CtaProveedorRetIVA + CveCuenta = CveCuentaProveedorRetIVA + ElseIf UsuarioActual.Empresa.Funcionalidad(314).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(314).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + End If + Case 16 'RetISR x Acreditar + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 1 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetISR > 0 Then + IdCtaContable = CtaProveedorRetISR + CveCuenta = CveCuentaProveedorRetISR + ElseIf UsuarioActual.Empresa.Funcionalidad(315).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(315).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + + Case 23 'RetISR Acreditable + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 1 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetISR > 0 Then + IdCtaContable = CtaProveedorRetISR + CveCuenta = CveCuentaProveedorRetISR + ElseIf UsuarioActual.Empresa.Funcionalidad(316).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(316).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + Case 243 'RetISR X Acreditar Terceros y Arrendamiento + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 2 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetISR > 0 Then + IdCtaContable = CtaProveedorRetISR + CveCuenta = CveCuentaProveedorRetISR + ElseIf UsuarioActual.Empresa.Funcionalidad(317).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(317).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + Case 244 'RetISR Acreditable Terceros y Arrendamiento + If Not gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then + If DdlRetISRConcepto.Items.Count > 0 AndAlso DdlRetISRConcepto.SelectedValue.ToEntero = 2 Then + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) + importeMN = ImporteMovimiento * tipoCambio + If CtaProveedorRetISR > 0 Then + IdCtaContable = CtaProveedorRetISR + CveCuenta = CveCuentaProveedorRetISR + ElseIf UsuarioActual.Empresa.Funcionalidad(318).ToEntero > 0 Then + IdCtaContable = UsuarioActual.Empresa.Funcionalidad(318).ToEntero + Else + If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero + End If + End If + End If + End If + End If + Case 64 'GANANCIA + If gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then 'SOLO SE IMPLEMENTÓ PARA NC + If DdlMoneda.SelectedValue.ToEntero <> 1 Or gvr.DataKey("CveMoneda").ToEntero <> 1 Then + IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria Dim TipoCambioDiferenciaCambiaria = If(ChkPagarConPesos.Checked, GlobalTipoCambio(gvr.DataKey("Fecha").ToDate).ToDecimal, tipoCambioNC) - Dim TipoCambioDiferenciaCompra = If(ChkPagarConDolares.Checked, GlobalTipoCambio(TxtFecha.Text.ToDate), TipoCambioCompra).ToDecimal - If TipoCambioDiferenciaCambiaria > TipoCambioDiferenciaCompra Then - ImporteMovimiento = (sumaAmortizacion * TipoCambioDiferenciaCambiaria) - (sumaAmortizacion * TipoCambioDiferenciaCompra) - ImporteMovimiento = ImporteMovimiento.RoundSQL() - importeMN = ImporteMovimiento - End If - - If ImporteMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta) Then - ErrorMovtosCxP = 1 - Exit For - End If - End If - - End If - End If - ImporteMovimiento = 0 - End Select - - If ImporteMovimiento <> 0 Then - 'Conta ContPAQ - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) - idCuentaContabilizacion = 0 - End If - 'Conta SIG - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) - CveCuentaContabilizacion = 0 - End If - - If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(tipoCambio = 1, 0, ImporteMovimiento), CveCuenta:=CveCuenta, PorcentajeImpuesto:=PorcentajeImpuesto) Then - ErrorMovtosCxP = 1 - Exit For - End If - - End If - Next - - End If - - End If - - '[IPP] COMENTADO PORQUE REUNIFICABA AMORTIZACIÓN NC 27/Agosto/2018 - 'If Not CompraUnificada Then - ' 'Unificacion de PrePolizas - ' If UsuarioActual.Empresa.Funcionalidad(219) = "1" Then - ' If Not ObjConta.PrePolizaUnificacion(gvr.DataKey("CvePrePoliza").ToEntero, CvePrepolizaPadre) Then - ' ErrorMovtosCxP = 1 - ' Alert("No se pudo unificar la prepoliza", TipoMensaje.MsgError) - ' End If - ' End If - 'End If - End If - Next - - 'Si el importe total de la amortizacion es igual al saldo de la compra se registra IVA - If IVACompleto = False AndAlso UsuarioActual.Empresa.Funcionalidad(521) = "1" Then - If sumaAmortizacionCompleto = CompraSaldo Then + Dim TipoCambioDiferenciaCompra = If(ChkPagarConDolares.Checked, GlobalTipoCambio(TxtFecha.Text.ToDate), TipoCambioCompra).ToDecimal + If TipoCambioDiferenciaCompra > TipoCambioDiferenciaCambiaria Then + ImporteMovimiento = (sumaAmortizacion * TipoCambioDiferenciaCompra) - (sumaAmortizacion * TipoCambioDiferenciaCambiaria) + ImporteMovimiento = ImporteMovimiento.RoundSQL() + importeMN = ImporteMovimiento + End If + + If ImporteMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + Exit For + End If + End If + + End If + End If + ImporteMovimiento = 0 + Case 65 'PERDIDA + If gvr.DataKey("TipoDocto").Contiene("NC", "DEV", "Ant") Then 'SOLO SE IMPLEMENTÓ PARA NC + If DdlMoneda.SelectedValue.ToEntero <> 1 Or gvr.DataKey("CveMoneda").ToEntero <> 1 Then + IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + Dim TipoCambioDiferenciaCambiaria = If(ChkPagarConPesos.Checked, GlobalTipoCambio(gvr.DataKey("Fecha").ToDate).ToDecimal, tipoCambioNC) + Dim TipoCambioDiferenciaCompra = If(ChkPagarConDolares.Checked, GlobalTipoCambio(TxtFecha.Text.ToDate), TipoCambioCompra).ToDecimal + If TipoCambioDiferenciaCambiaria > TipoCambioDiferenciaCompra Then + ImporteMovimiento = (sumaAmortizacion * TipoCambioDiferenciaCambiaria) - (sumaAmortizacion * TipoCambioDiferenciaCompra) + ImporteMovimiento = ImporteMovimiento.RoundSQL() + importeMN = ImporteMovimiento + End If + + If ImporteMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=0, CveCuenta:=CveCuenta) Then + ErrorMovtosCxP = 1 + Exit For + End If + End If + + End If + End If + ImporteMovimiento = 0 + End Select + + If ImporteMovimiento <> 0 Then + 'Conta ContPAQ + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + 'Conta SIG + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) + CveCuentaContabilizacion = 0 + End If + + If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaNueva, TipoMovimiento, ImporteMovimiento, Concepto, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=importeMN, CvePrePolizaOriginal:=CvePrePoliza, ImporteME:=If(tipoCambio = 1, 0, ImporteMovimiento), CveCuenta:=CveCuenta, PorcentajeImpuesto:=PorcentajeImpuesto) Then + ErrorMovtosCxP = 1 + Exit For + End If + + End If + Next + + End If + + End If + + '[IPP] COMENTADO PORQUE REUNIFICABA AMORTIZACIÓN NC 27/Agosto/2018 + 'If Not CompraUnificada Then + ' 'Unificacion de PrePolizas + ' If UsuarioActual.Empresa.Funcionalidad(219) = "1" Then + ' If Not ObjConta.PrePolizaUnificacion(gvr.DataKey("CvePrePoliza").ToEntero, CvePrepolizaPadre) Then + ' ErrorMovtosCxP = 1 + ' Alert("No se pudo unificar la prepoliza", TipoMensaje.MsgError) + ' End If + ' End If + 'End If + End If + Next + + 'Si el importe total de la amortizacion es igual al saldo de la compra se registra IVA + If IVACompleto = False AndAlso UsuarioActual.Empresa.Funcionalidad(521) = "1" Then + If sumaAmortizacionCompleto = CompraSaldo Then Dim PorcentajeImpuesto As Decimal = TmpDT.MAX("IVAPorcentaje").ToDecimal @@ -8914,1670 +9040,1682 @@ Partial Class Compras_Compras End If - End If - End If - - 'Unificacion de PrePolizas - If UsuarioActual.Empresa.Funcionalidad(219) = "1" Then - If Not ObjConta.PrePolizaUnificacion(CvePrepolizaPadre, CvePrePolizaNueva) Then - ErrorMovtosCxP = 1 - Alert("No se pudo unificar la prepoliza", TipoMensaje.MsgError) + End If + End If + + 'Unificacion de PrePolizas + If UsuarioActual.Empresa.Funcionalidad(219) = "1" Then + If Not ObjConta.PrePolizaUnificacion(CvePrepolizaPadre, CvePrePolizaNueva) Then + ErrorMovtosCxP = 1 + Alert("No se pudo unificar la prepoliza", TipoMensaje.MsgError) End If CvePrePolizaNueva = CvePrepolizaPadre 'para que se unifique siempre la prepolizanueva - End If - - 'Simplificacion de PrePolizas - If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then - If Not ObjConta.PrePolizaSimplificacion(CvePrePolizaNueva, UsuarioActual.CveEmpresa) Then - ErrorMovtosCxP = 1 - Alert("No se pudo simplificar los movimientos", TipoMensaje.MsgError) - End If - End If - - 'Validacion de prepolizas - If ObjConta.ValidacionPrePolizaCuadre(CvePrePolizaNueva, 4) Then - If ObjConta.ValorPolizaDescuadre > 0 Then - GuardaLogAD($"Compras/Compras-Anticipos | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") - 'ErrorMovtosCxP = 1 - End If - End If - - 'Conta ContPAQ - If UsuarioActual.Empresa.Funcionalidad(200) = "1" AndAlso ErrorMovtosCxP = 0 Then - If idCuentaContabilizacion > 0 Then - If ObjConta.ContabilizarPrePoliza(CvePrePolizaNueva, UsuarioActual.CveUsuario, UsuarioActual.Empresa) Then - alertaContabilizacion.AppendFormat("{1}<\a>
", ObjConta.ContaIdPoliza, ObjConta.ContaFolio) - Else - ErrorMovtosCxP = 1 - End If - If ErrorMovtosCxP = 0 Then - Alert("Se enviaron correctamente las siguientes pólizas:

" & alertaContabilizacion.ToString, ModExtensiones.TipoMensaje.MsgInformacion) - Else - Alert($"Ocurrio un error al contabilizar {ObjConta.AlertaMensaje}", TipoMensaje.MsgAdvertencia) - End If - Else - Alert(String.Format("No se puede contabilizar la Prepoliza debido a que las siguientes cuentas son inválidas:
{0}", CuentasContablesInvalidas), TipoMensaje.MsgAdvertencia) - End If - End If - - - Else 'Empresa Prueba - - For Each gvr As GridViewRow In GVAnticipos.Rows - If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then - - CveCompraNC = gvr.DataKey("CveCompra").ToEntero - If CvePrePoliza > 0 Then - - Dim CveConceptoCompra As Integer = 60 - Dim CveConceptoPago As Integer = 17 - Dim TipoMovimientoCompra As Boolean = True - Select Case gvr.DataKey("TipoDocto") - Case "NC", "DEV" - CveConceptoCompra = 60 - CveIE = -1 - CveConceptoPago = 272 - Case "Egsc" - CveConceptoCompra = 21 - 'vinculo la compra actual, y no la compra como si fuera nota de credito - CveCompraNC = -1 - CveIE = gvr.DataKey("CveIE").ToEntero - Case "DD" - CveConceptoCompra = 37 - 'vinculo la compra actual, y no la compra como si fuera nota de credito - CveCompraNC = -1 - CveIE = gvr.DataKey("CveIE").ToEntero - End Select - - PorcentajePago = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal / TxtTotal.Text.ToDecimal - - 'Se agrega la nota de credito - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimientoCompra, gvr.FCTextBox("TxtAnticipo").Text.ToDecimal, " ", CveConceptoCompra, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, CveCompraAmortizacion:=CveCompraNC, ImporteMX:=gvr.FCTextBox("TxtAnticipo").Text.ToDecimal) Then - ErrorMovtosCxP = 1 - Exit For - End If - - 'movimiento de pago proveedor - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoCompra, gvr.FCTextBox("TxtAnticipo").Text.ToDecimal, " ", CveConceptoPago, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, CveCompraAmortizacion:=CveCompraNC, ImporteMX:=gvr.FCTextBox("TxtAnticipo").Text.ToDecimal) Then - ErrorMovtosCxP = 1 - Exit For - End If - - 'si tiene iva y su proporcion - ImporteMovimiento = Math.Round(PorcentajePago * TxtIVA.Text.ToDecimal, 2) - If ImporteMovimiento > 0 Then - Dim PorcentajeImpuesto As Decimal = TmpDT.MAX("IVAPorcentaje").ToDecimal - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteMovimiento, " ", 14, " ", TxtFechaPago.Text.ToDate, IdCtaIVAXAcreditar, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, PorcentajeImpuesto:=PorcentajeImpuesto) Then ErrorMovtosCxP = 1 : Exit For - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, " ", 19, " ", TxtFechaPago.Text.ToDate, IdCtaIVAAcreditable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, PorcentajeImpuesto:=PorcentajeImpuesto) Then ErrorMovtosCxP = 1 : Exit For - - End If - - 'si tiene Ret iva y su proporcion - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) - If ImporteMovimiento > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteMovimiento, " ", 15, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento) Then ErrorMovtosCxP = 1 : Exit For - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, " ", 22, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento) Then ErrorMovtosCxP = 1 : Exit For - - End If - - 'si tiene Ret ISR y su proporcion - ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) - If ImporteMovimiento > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteMovimiento, " ", 16, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento) Then ErrorMovtosCxP = 1 : Exit For - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, " ", 23, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento) Then ErrorMovtosCxP = 1 : Exit For - - End If - - - 'actualizo una tabla de vinculaciones - - 'actualizo la cantidad en amortizaciones - - If gvr.DataKey("TipoDocto").Contiene("NC", "DEV") Then - If Not ObjCompra.AmortizarCompra(CveCompra, CveCompraNC, gvr.FCTextBox("TxtAnticipo").Text.ToDouble, UsuarioActual.CveUsuario) Then - ErrorMovtosCxP = 2 - Exit For - - End If - - End If - - - End If - - End If - - Next - - End If 'Empresa Prueba - - - - Select Case ErrorMovtosCxP - Case 0 - Alert("El movimiento se aplicó correctamente.", TipoMensaje.MsgInformacion) - ObjCompra.Commit() - - - Dim dtnc As DataTable = Nothing - If ObjCompra.GetComprasNotasCredito(CveCompra, -1) Then - dtnc = ObjCompra.DtResultados - End If - - GvAnticiposSel.DataSource = dtnc - GvAnticiposSel.DataBind() - - LblAmortizacion.Text = (LblAmortizacion.Text.ToDouble + Importe).FormatoNumero - CompraSaldo = CompraSaldo - Importe - HdnCompraSaldo.Value = CompraSaldo.ToString - - If CompraSaldo > 0 Then CargaAnticipos(CveProveedor) - If CveCompra > 0 Then VisualizaEstatusCompraSaldo(DdlTipoComprobante.SelectedValue, CompraSaldo.ToDecimal, TxtTotal.Text.ToDecimal) - - UpAnticipos.Update() - UpPS.Update() - dtnc.Dispose() - Case 1 - Alert("Ocurrió un error al amortizar la nota de crédito
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ObjCompra.RollBack() - Case 2 - Alert("Ocurrió un error al amortizar la nota de crédito
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) - ObjCompra.RollBack() - End Select - - Catch ex As Exception - ObjCompra.RollBack() - End Try - ObjCompra.Dispose() - Else - 'sino se ha guardado la compra, se registra temporal que anticpos van a cargarle - - For Each gvr As GridViewRow In GVAnticipos.Rows - If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then - ArrAnticipos.Add(New Anticipos With {.CvePrePoliza = gvr.DataKey("CvePrePoliza").ToEntero, .CveIE = gvr.DataKey("CveIE").ToString.ToEntero, .CveCompra = gvr.DataKey("CveCompra").ToEntero, .Importe = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal, .TCCompra = gvr.DataKey("TCCompra").ToDecimal, .TipoMovto = gvr.DataKey("TipoDocto")}) - End If - Next - - Dim ImporteAnticipo As Decimal = 0 - If ArrAnticipos.Count > 0 Then - For Each Ant As Compras_Compras.Anticipos In ArrAnticipos - ImporteAnticipo += Ant.Importe - Next - End If - + End If + + 'Simplificacion de PrePolizas + If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then + If Not ObjConta.PrePolizaSimplificacion(CvePrePolizaNueva, UsuarioActual.CveEmpresa) Then + ErrorMovtosCxP = 1 + Alert("No se pudo simplificar los movimientos", TipoMensaje.MsgError) + End If + End If + + 'Validacion de prepolizas + If ObjConta.ValidacionPrePolizaCuadre(CvePrePolizaNueva, 4) Then + If ObjConta.ValorPolizaDescuadre > 0 Then + GuardaLogAD($"Compras/Compras-Anticipos | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") + 'ErrorMovtosCxP = 1 + End If + End If + + 'Conta ContPAQ + If UsuarioActual.Empresa.Funcionalidad(200) = "1" AndAlso ErrorMovtosCxP = 0 Then + If idCuentaContabilizacion > 0 Then + If ObjConta.ContabilizarPrePoliza(CvePrePolizaNueva, UsuarioActual.CveUsuario, UsuarioActual.Empresa) Then + alertaContabilizacion.AppendFormat("
{1}<\a>
", ObjConta.ContaIdPoliza, ObjConta.ContaFolio) + Else + ErrorMovtosCxP = 1 + End If + If ErrorMovtosCxP = 0 Then + Alert("Se enviaron correctamente las siguientes pólizas:

" & alertaContabilizacion.ToString, ModExtensiones.TipoMensaje.MsgInformacion) + Else + Alert($"Ocurrio un error al contabilizar {ObjConta.AlertaMensaje}", TipoMensaje.MsgAdvertencia) + End If + Else + Alert(String.Format("No se puede contabilizar la Prepoliza debido a que las siguientes cuentas son inválidas:
{0}", CuentasContablesInvalidas), TipoMensaje.MsgAdvertencia) + End If + End If + + + Else 'Empresa Prueba + + For Each gvr As GridViewRow In GVAnticipos.Rows + If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then + + CveCompraNC = gvr.DataKey("CveCompra").ToEntero + If CvePrePoliza > 0 Then + + Dim CveConceptoCompra As Integer = 60 + + Dim CveConceptoPago As Integer = 17 + If CveTipoConcepto = 2 Then CveConceptoPago = 308 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case CveConceptoPago + Case 17 + CveConceptoPago = 312 + Case 308 + CveConceptoPago = 309 + Case Else + End Select + End If + + Dim TipoMovimientoCompra As Boolean = True + Select Case gvr.DataKey("TipoDocto") + Case "NC", "DEV" + CveConceptoCompra = 60 + CveIE = -1 + CveConceptoPago = 272 + Case "Egsc" + CveConceptoCompra = 21 + 'vinculo la compra actual, y no la compra como si fuera nota de credito + CveCompraNC = -1 + CveIE = gvr.DataKey("CveIE").ToEntero + Case "DD" + CveConceptoCompra = 37 + 'vinculo la compra actual, y no la compra como si fuera nota de credito + CveCompraNC = -1 + CveIE = gvr.DataKey("CveIE").ToEntero + End Select + + PorcentajePago = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal / TxtTotal.Text.ToDecimal + + 'Se agrega la nota de credito + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovimientoCompra, gvr.FCTextBox("TxtAnticipo").Text.ToDecimal, " ", CveConceptoCompra, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompraNC, CveProveedor:=CveProveedor, CveIE:=CveIE, CveCompraAmortizacion:=CveCompraNC, ImporteMX:=gvr.FCTextBox("TxtAnticipo").Text.ToDecimal) Then + ErrorMovtosCxP = 1 + Exit For + End If + + 'movimiento de pago proveedor + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimientoCompra, gvr.FCTextBox("TxtAnticipo").Text.ToDecimal, " ", CveConceptoPago, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, CveCompraAmortizacion:=CveCompraNC, ImporteMX:=gvr.FCTextBox("TxtAnticipo").Text.ToDecimal) Then + ErrorMovtosCxP = 1 + Exit For + End If + + 'si tiene iva y su proporcion + ImporteMovimiento = Math.Round(PorcentajePago * TxtIVA.Text.ToDecimal, 2) + If ImporteMovimiento > 0 Then + Dim PorcentajeImpuesto As Decimal = TmpDT.MAX("IVAPorcentaje").ToDecimal + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteMovimiento, " ", 14, " ", TxtFechaPago.Text.ToDate, IdCtaIVAXAcreditar, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, PorcentajeImpuesto:=PorcentajeImpuesto) Then ErrorMovtosCxP = 1 : Exit For + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, " ", 19, " ", TxtFechaPago.Text.ToDate, IdCtaIVAAcreditable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento, PorcentajeImpuesto:=PorcentajeImpuesto) Then ErrorMovtosCxP = 1 : Exit For + + End If + + 'si tiene Ret iva y su proporcion + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetIVA.Text.ToDecimal, 2) + If ImporteMovimiento > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteMovimiento, " ", 15, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento) Then ErrorMovtosCxP = 1 : Exit For + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, " ", 22, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento) Then ErrorMovtosCxP = 1 : Exit For + + End If + + 'si tiene Ret ISR y su proporcion + ImporteMovimiento = Math.Round(PorcentajePago * TxtRetISR.Text.ToDecimal, 2) + If ImporteMovimiento > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteMovimiento, " ", 16, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento) Then ErrorMovtosCxP = 1 : Exit For + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, " ", 23, " ", TxtFechaPago.Text.ToDate, 0, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveIE:=CveIE, ImporteMX:=ImporteMovimiento) Then ErrorMovtosCxP = 1 : Exit For + + End If + + + 'actualizo una tabla de vinculaciones + + 'actualizo la cantidad en amortizaciones + + If gvr.DataKey("TipoDocto").Contiene("NC", "DEV") Then + If Not ObjCompra.AmortizarCompra(CveCompra, CveCompraNC, gvr.FCTextBox("TxtAnticipo").Text.ToDouble, UsuarioActual.CveUsuario) Then + ErrorMovtosCxP = 2 + Exit For + + End If + + End If + + + End If + + End If + + Next + + End If 'Empresa Prueba + + + + Select Case ErrorMovtosCxP + Case 0 + Alert("El movimiento se aplicó correctamente.", TipoMensaje.MsgInformacion) + ObjCompra.Commit() + + + Dim dtnc As DataTable = Nothing + If ObjCompra.GetComprasNotasCredito(CveCompra, -1) Then + dtnc = ObjCompra.DtResultados + End If + + GvAnticiposSel.DataSource = dtnc + GvAnticiposSel.DataBind() + + LblAmortizacion.Text = (LblAmortizacion.Text.ToDouble + Importe).FormatoNumero + CompraSaldo = CompraSaldo - Importe + HdnCompraSaldo.Value = CompraSaldo.ToString + + If CompraSaldo > 0 Then CargaAnticipos(CveProveedor) + If CveCompra > 0 Then VisualizaEstatusCompraSaldo(DdlTipoComprobante.SelectedValue, CompraSaldo.ToDecimal, TxtTotal.Text.ToDecimal) + + UpAnticipos.Update() + UpPS.Update() + dtnc.Dispose() + Case 1 + Alert("Ocurrió un error al amortizar la nota de crédito
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ObjCompra.RollBack() + Case 2 + Alert("Ocurrió un error al amortizar la nota de crédito
Revise su factura y cualquier detalle comuníquese a Soporte Técnico", TipoMensaje.MsgAdvertencia) + ObjCompra.RollBack() + End Select + + Catch ex As Exception + ObjCompra.RollBack() + End Try + ObjCompra.Dispose() + Else + 'sino se ha guardado la compra, se registra temporal que anticpos van a cargarle + + For Each gvr As GridViewRow In GVAnticipos.Rows + If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then + ArrAnticipos.Add(New Anticipos With {.CvePrePoliza = gvr.DataKey("CvePrePoliza").ToEntero, .CveIE = gvr.DataKey("CveIE").ToString.ToEntero, .CveCompra = gvr.DataKey("CveCompra").ToEntero, .Importe = gvr.FCTextBox("TxtAnticipo").Text.ToDecimal, .TCCompra = gvr.DataKey("TCCompra").ToDecimal, .TipoMovto = gvr.DataKey("TipoDocto")}) + End If + Next + + Dim ImporteAnticipo As Decimal = 0 + If ArrAnticipos.Count > 0 Then + For Each Ant As Compras_Compras.Anticipos In ArrAnticipos + ImporteAnticipo += Ant.Importe + Next + End If + LblAmortizacion.Text = ImporteAnticipo.FormatoNumero - UpPS.Update() - End If - RegistraScript(String.Format("$('#{0}').modal('hide');", "DivAnticipos")) - Else - Alert("No hay movimientos seleccionados para aplicar", TipoMensaje.MsgAdvertencia) - End If - UPPAnticiposSel.Update() - End Sub - - Protected Sub ImgClasificacion_Click(sender As Object, e As EventArgs) Handles ImgClasificacion.Click - - If CveCompra > 0 Then - - Dim SiSelecciono As Boolean = False - For Each gvr As GridViewRow In GvPS.Rows - If gvr.FCCheckBox("CheckClasificacion").Checked = True Then - SiSelecciono = True - Exit For - End If - Next - If SiSelecciono = False Then - Alert("Tiene que seleccionar algun Producto o Servicio", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - DdlAplicaClasificacion.SelectedValue = "-1" - RegistraScript(String.Format("$('#{0}').modal('show');", "DivClasificacion")) - Else - RegistraScript(String.Format("$('#{0}').modal('show');", "DivClasificacion")) - End If - - End Sub - - Protected Sub BtnActualizar_Click(sender As Object, e As EventArgs) Handles BtnActualizar.Click - - 'VALIDA IMPORTES - If CveFactura > 0 Then 'SI NO VIENE DE FACTURA/XML NO VALIDA TOTALES - If Not ValidaTotalesGuardar() Then - Exit Sub - End If - End If - - For Each Row As DataRow In TmpDT.Rows - If Row("CveSubProyecto").ToString.ToEntero <= 0 Then - Alert("No se ha completado la asignacion de proyectos en la compra. ", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If Row("CveClasificacionActualizar").ToString.ToEntero <= 0 Then 'If NotHas117 AndAlso Row("CveClasificacionActualizar").ToString.ToEntero <= 0 Then - Alert("Hay productos que no tienen clasificación asignada.
Favor de asignarle una y darle guardar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If UsuarioActual.Empresa.Funcionalidad(527) = "1" Then - If Row("CveTipoGasto").ToString.ToEntero <= 0 Then - Alert("No se ha completado la asignacion de tipos de gasto en la compra.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - Next - - - Dim ObjCompra As New ClsCompras - Dim ObjProveedores As New ClsCompProveedores(ObjCompra.IniciaTransacSQL()) - Dim ObjInventario As New ClsInventarios(ObjCompra.IniciaTransacSQL) - Dim ObjContabilidad As New ClsContabilidad(ObjCompra.IniciaTransacSQL) - Dim ObjAF As New ClsAF(ObjCompra.IniciaTransacSQL) - Dim ObjContaAC As ClsContPAQi = New ClsContPAQi(UsuarioActual.Empresa) - - Dim Retorno As Boolean = True - Dim CveEstatusFactura As Integer = HdnCveEstatusFactura.Value.ToEntero - Dim MultiplicadorNC = If(DdlTipoComprobante.SelectedValue = "NC", -1, 1) - - Dim ErrorAC = False - Dim IDPolizaComprometido = 0 - - If ChkProgramarPago.Checked AndAlso CveEstatusFactura = 1 Then - CveEstatusFactura = 2 - End If - If Not ChkProgramarPago.Checked AndAlso CveEstatusFactura = 2 Then - CveEstatusFactura = 1 - End If - Try - 'Revisamos que los cambios hechos mantengan la interidad de los numeros - If HFDiferenciaCompra.Value = TxtTotal.Text Or CveFactura < 1 Or CveCompra < 1 Then - - If IdPoliza > 0 Then - If Not ObjContabilidad.UpdatePrePolizasDetalleBloquear(CvePrePoliza, False) Then - Retorno = False - End If - - If Not ObjContabilidad.UpdatePrePoliza(MinFecha, -1, -1, Nothing, CvePrePoliza, UsuarioActual.CveEmpresa) Then - Retorno = False - End If - End If - - 'PORCENTAJE IVA - Dim PorcentajeIVA As Decimal = TmpDT.MAX("IVAPorcentaje").ToDecimal - - If ObjCompra.UpdateCompra(TxtDescripcion.Text.Trim, TxtFolioSecundario.Text.Trim, TxtFechaPago.Text.ToDate, ChkAplicaNotaCredito.Checked, TxtObsFact.Text.Trim, CveEstatusFactura, - TxtDescuento.Text.ToDouble, TxtSubTotal.Text.ToDouble, TxtIVA.Text.ToDouble, TxtTotal.Text.ToDouble, - UsuarioActual.CveUsuario, CveCompra, CveCajaChica:=DdlRembolsoCajaChica.SelectedValue.ToEntero, CvePersonal:=DdlRembolsoPersonal.SelectedValue.ToEntero, CveProveedorSucursal:=If(DdlProveedorSucursal.SelectedValue.ToEntero > 0, DdlProveedorSucursal.SelectedValue.ToEntero, -1), PorcentajeIVA:=PorcentajeIVA, NumeroReembolso:=TxtRembolsoNumero.Text, - CveTipoCompra:=DdlTipoCompra.SelectedValue.ToEntero, NoDeducible:=EsNoDeducible) Then - - If Not ComparaDatatables() Then - - 'Regeneramos el concepto 6 de PrePolizas - 'If UsuarioActual.Empresa.Funcionalidad(207) = "1" Then - ' If Not RegenerarPrePoliza(ObjContabilidad, ObjContaAC, 6, False, MultiplicadorNC) Then - ' Retorno = False - ' End If - 'End If - - - - 'If UsuarioActual.Empresa.Funcionalidad(207) = "1" Then - If Not ActualizarPrePoliza(ObjContabilidad, ObjCompra) Then - Retorno = False - End If - 'End If - - ''EMPIEZA: SI USA AC - If UsuarioActual.Empresa.UsaAC AndAlso IdPoliza > 0 Then - ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) - ObjContaAC.IniciaTransacSQL() - - - 'ELIMINA TODOS LOS MOVIMIENTOS DE LA POLIZA - ObjContaAC.RemoveAllMovimientos(IdPoliza) - - - 'INSERTA LOS NUEVOS MOVIMIENTOS DE LA POLIZA - If IdPoliza > 0 Then - Dim CuentaAbono As Integer - Dim Importe As Decimal = 0 - Dim TotalDetalle As Decimal = 0 - - 'CUENTA PROVEEDOR - If CtaProveedor <= 0 Then - If ObjContaAC.GetCuentas(-1, "021120000000000000", -1) Then - Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") - If drCuenta IsNot Nothing Then - CuentaAbono = drCuenta("Id").ToString.ToEntero - Dim FolioProveedor = ObjContaAC.GetFolioProveedores("021120000000000000").ToString - ViewState("CtaProveedor") = ObjContaAC.AddCuenta(String.Format("02112{0}000000000", FolioProveedor.PadLeft(4, "0"c)), NombreProveedor, "D", 2, 0, 1, 0, "", 1, CuentaAbono) - ObjProveedores.UpdateProveedorIdCuentaAC(CveProveedor, CtaProveedor) - Else - ErrorAC = True - End If - Else - ErrorAC = True - End If - End If - - Dim ConceptoRenglon As String = "" - If Not ErrorAC Then - - Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA, tRetIVA, tRetISR As Decimal - - Dim ipresup As Integer = 0 - - 'COMIENZA: PRUEBA AGRUPACION CONCEPTOS - Dim Presup = From gvr As DataRow In TmpDT.Rows.Cast(Of DataRow)() - Group gvr By Grp = New With { - Key .CvePresupuestoEgreso = gvr("CvePresupuestoEgreso").ToString.ToEntero, - Key .CveActivoFijo = If(gvr("TipoAF").ToString.ToEntero = 2, gvr("CveActivoFijo").ToString.ToEntero, -1) - } Into Group - Select Grp.CvePresupuestoEgreso, Grp.CveActivoFijo, - TotalImporte = Group.Sum(Function(r) r("Total").ToString.ToDecimal) - Dim Fecha As Date = TxtFecha.Text.ToDate - - 'PresupuestoEgresos - Dim DtPresupuestosTemp As DataTable - Dim IdCuentaComprometido, IdCuentaPorEjercer, IdCuentaDevengado, IdCuentaMatriz As Integer - - 'Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA As Double - tTotalIVA = TxtIVA.Text.ToDecimal - tRetIVA = TxtRetIVA.Text.ToDecimal - tRetISR = TxtRetISR.Text.ToDecimal - - 'tTotalIVA = tTotalIVA - tRetIVA - tRetISR - - tTotalGral = TxtTotal.Text.ToDecimal + tRetIVA + tRetISR ' EL TOTAL GENERAL DEBE DE SER EL SUBTOTAL + IVA, NO SE DEBEN DE INCLUIR LAS RETENCIONES, POR ESO SE RESTA - tDiferenciaIVA = tTotalIVA - tIVA = 0 - ipresup = 0 - - 'INVENTARIOS EN AC - Dim CuentaMatrizAlmacen As Integer - Dim ContadorInventario As Integer = GvInv.Rows.Cast(Of GridViewRow)().Count(Function(gvr) gvr.FCCheckBox("cbInv").Checked) - - 'COMENTADO 15/3/2016 - 'cuando hay algo que ingresar a inventarios - 'Dim x As Integer = 0 - 'For Each Dr As DataRow In TmpDT.Rows - ' If GvInv.Rows.Count > 0 Then - ' If GvInv.Rows(x).FCCheckBox("cbInv").Checked Then - ' Dr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlEAlmacen").SelectedValue.ToEntero - ' Else 'limpio el valor para que no truene en linq mas abajo - ' Dr("CveAlmacen") = 0 - ' End If - ' x = x + 1 - ' Else - ' Exit For - ' End If - 'Next - - ''previamente si hay un ingreso a inventarios - 'Dim CtaAlmacen As Integer - 'If ContadorInventario > 0 Then - ' Dim drr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", TmpDT.Rows(0)("CveAlmacen").ToString)) - ' If drr IsNot Nothing Then - ' CtaAlmacen = drr("IdCtaContable").ToString.ToEntero - ' End If - 'End If - - Dim CtaAlmacen As Integer - If ContadorInventario > 0 Then - Dim drr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero)) - If drr IsNot Nothing Then - CtaAlmacen = drr("IdCtaContable").ToString.ToEntero - End If - End If - Dim DescuentoConIVA As Double - Dim tPorIVA As Decimal = tTotalIVA / (tTotalGral - tTotalIVA) - Dim tAjusteTotal As Decimal = 0 - - For Each grp In Presup - Importe = grp.TotalImporte - TotalDetalle += Importe - ipresup += 1 - If Importe > 0 Then - 'saco la proporcion de iva que le corresponde - tIVA = Math.Round(Importe * tPorIVA, 2) - tDiferenciaIVA -= tIVA - 'identifico si es el ultimo registro, para ver si es necesario un ajuste - If ipresup = Presup.Count Then - If Math.Round(TotalDetalle - tTotalGral, 2) <= 0.01 AndAlso tDiferenciaIVA > 0 Then - tIVA += tDiferenciaIVA - End If - End If - - 'le sumo el iva al concepto - Importe += tIVA - 'codigo Provisional, para cuand tenga descuento, solo tome el subtotal * el iva,RMF - If TxtDescuento.Text.ToDouble > 0 Then - Importe = grp.TotalImporte * (1 + tPorIVA) - End If - - tAjusteTotal += Importe - - 'valido que la sumas de lo detalles no exceda al totalgeneral - If Math.Round(tAjusteTotal, 2) > tTotalGral Then - 'le resto la diferencia - Importe -= (tAjusteTotal - tTotalGral) - End If - - 'Presupuesto Egresos - DtPresupuestosTemp = DtPresupuestos.FiltraParametros(String.Format("CvePresupuestoEgreso = {0}", grp.CvePresupuestoEgreso)) - If DtPresupuestosTemp.Rows.Count <> 1 Then - ErrorAC = True - Exit For - End If - IdCuentaComprometido = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString.ToEntero - IdCuentaPorEjercer = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero - IdCuentaDevengado = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString.ToEntero - IdCuentaMatriz = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString.ToEntero - - 'COMPROMETIDO DEPENDIENTE SI EXISTE SU POLIZA - If IDPolizaComprometido = 0 Then - ConceptoRenglon = String.Format("GC Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaPorEjercer, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - Exit For - End If - Else - ErrorAC = True - Exit For - End If - End If - - ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - 'DEVENGADO - If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaDevengado, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - Exit For - End If - Else - ErrorAC = True - Exit For - End If - - - If ContadorInventario > 0 Then - Dim tImporte, ttIVA As Double - - For Each gvr As GridViewRow In GvPS.Rows - 'registra los movimientos del presupuesto asignado, para que no se duplique si hay varios presupeusto dentro de la compra - If gvr.DataKey("CvePresupuestoEgreso").ToEntero = grp.CvePresupuestoEgreso Then - 'saco la proporcion de iva que le corresponde - - tImporte = gvr.FCLiteral("LtlTotal").Text.ToDouble - - ttIVA = Math.Round(tImporte * tTotalIVA / tTotalGral, 2) - ' tDiferenciaIVA -= tIVA - ' 'identifico si es el ultimo registro, para ver si es necesario un ajuste - ' If ipresup = GvPS.Rows.Count Then - ' If Math.Round(TotalDetalle - tTotalGral, 2) <= 0.01 AndAlso tDiferenciaIVA > 0 Then - ' tIVA += tDiferenciaIVA - ' End If - ' End If - - ' ' 'le sumo el iva al concepto - tImporte += ttIVA - - 'PU = tImporte / gvr.DataKey("Cantidad").ToDouble - 'If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, gvr.DataKey("Cantidad").ToDouble, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1) Then - ' ErrorAC = True - ' Exit For - 'End If - End If - - Next - - CuentaMatrizAlmacen = CtaAlmacen - - ElseIf grp.CveActivoFijo > 0 Then - - Dim CtaAF = -1 - Dim AF = "" - Dim CuentaInicial = -1 - - If ObjAF.GetActivosFijos(grp.CveActivoFijo, UsuarioActual.CveEmpresa, "-1", "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "", -1, UsuarioActual.CveEmpresa) Then - CtaAF = ObjAF.Cuenta - AF = ObjAF.Descripcion - CuentaInicial = ObjAF.CuentaInicial - Else - ErrorAC = True - Exit For - End If - - If Not CuentaInicial > 0 Then - CuentaInicial = 1241 - End If - - 'CUENTA AF - If CtaAF <= 0 Then - If ObjContaAC.GetCuentas(-1, String.Format("0{0}0000000000000", CuentaInicial), -1) Then - Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") - If drCuenta IsNot Nothing Then - - CuentaAbono = drCuenta("Id").ToString.ToEntero - Dim FolioAF = ObjContaAC.GetFolioProveedores(String.Format("0{0}0000000000000", CuentaInicial)).ToString - CtaAF = ObjContaAC.AddCuenta(String.Format("0{0}{1}000000000", CuentaInicial, FolioAF.PadLeft(4, "0"c)), AF, "A", 2, 0, 1, 0, "", 1, CuentaAbono) - - ObjAF.UpdateActivosFijosCuentaAC(grp.CveActivoFijo, CtaAF, UsuarioActual.CveUsuario) - Else - ErrorAC = True - End If - Else - ErrorAC = True - End If - End If - - CuentaMatrizAlmacen = CtaAF - Else - CuentaMatrizAlmacen = IdCuentaMatriz - End If - - - ''AFECTAR MATRIZ EGRESOS - If ObjContaAC.AddMovimiento(IdPoliza, CuentaMatrizAlmacen, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - - ''VERIFICA SI TIENE DESCUENTO (AMORTIZACION) - If TxtDescuento.Text.ToDouble > 0 AndAlso CtaProveedorAnticipos > 0 Then - DescuentoConIVA = TxtDescuento.Text.ToDecimal * 1.16 - - 'Valida que el descuento con iva cuadre en los totales - If Math.Abs(DescuentoConIVA - (Importe - TxtTotal.Text.ToDouble)) < 0.02 Then - DescuentoConIVA = Importe - TxtTotal.Text.ToDouble - ElseIf DescuentoConIVA <> (Importe - TxtTotal.Text.ToDecimal) Then - ErrorAC = True - Exit For - End If - - 'actualizo el idcuenta del presupuesto - If ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, MultiplicadorNC * (Importe - DescuentoConIVA), "", ConceptoRenglon, 0, Fecha, "") Then - 'agrego a la cuenta contable anticipos - If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorAnticipos, True, MultiplicadorNC * DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - Exit For - End If - Else - ErrorAC = True - Exit For - End If - Else - 'actualizo el idcuenta del - - End If - - Else - ErrorAC = True - Exit For - End If - ''TERMINA AFECTAR MATRIZ EGRESOS - - Else - ErrorAC = True - Exit For - End If - - Next - - If Not ErrorAC Then - 'registro un solo movimiento a proveedores - Importe = TxtTotal.Text.ToDecimal - If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - End If - End If - - If tRetISR > 0 Then - ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorRetISR, True, MultiplicadorNC * tRetISR, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - End If - End If - - End If - - Else - ErrorAC = True - End If - - 'CUADRA LA POLIZA - ObjContaAC.AjustaPoliza(IdPoliza) - - End If - ''TERMINA: SI USA AC - - - - If Not ErrorAC Then - Dim Cont As Integer = 0 - For Each Row As DataRow In TmpDT.Rows - - 'actualizar las clasificaciones, que se hallan hecho - If Row("CveClasificacionActualizar").ToString.ToEntero > 0 Then - 'REGISTRO EL PRODUCTO - Dim PSS As New ClsProductosServicios - If Not PSS.UpdateClasificacionPS(Row("CveClasificacionActualizar").ToString.ToEntero, UsuarioActual.CveUsuario, Row("CvePS").ToString.ToEntero) Then - Retorno = False - Exit For - End If - 'Row("CvePS") = 20184 'PSS.DtResultados.FiltraParametros("PS = '" & Row("PS").ToString & "' AND CveEmpresa = " & UsuarioActual.CveEmpresa).Rows(0)("CvePS").ToString - PSS.Dispose() - End If - - Dim CvePersonal = GvPersonal.Rows(Cont).FCDropDownList("DdlPersonalGv").SelectedValue.ToEntero - Dim Referencia = GvPersonal.Rows(Cont).FCTextBox("TxtReferencia").Text - - Cont = Cont + 1 - 'Si es AF-INSUMO se guarda en CveActivoFIjo - Dim CveAF = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 1, Row("CveActivoFijo").ToString.ToEntero, -1) - - 'Si es AF-COMPRA se guarda en CveActivoFijoCompra - Dim CveAFCompra = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 2, Row("CveActivoFijo").ToString.ToEntero, -1) - - If Not ObjCompra.UpdateCompraDetalle(Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDouble, Row("PU").ToString.ToDouble, Row("IVA").ToString.ToDouble, Row("Total").ToString.ToDouble, - Row("Descuento").ToString.ToDouble, Row("Obs").ToString, Row("CveSubProyecto").ToString.ToEntero, Row("CvePresupuestoEgreso").ToString.ToEntero, CveAF, Row("CveCompraDetalle").ToString.ToEntero, CvePersonal:=CvePersonal, CveTipoGasto:=Row("CveTipoGasto").ToString.ToEntero, AF_Medida:=Row("AFMedida").ToString.ToEntero, AF_TipoMantenimiento:=Row("AFTipoMantenimiento").ToString.ToEntero, Referencia:=Referencia, - RetIVA:=Row("RetIVA").ToString.ToDouble, RetISR:=Row("RetISR").ToString.ToDouble, IEPSPS:=Row("IEPSPS").ToString.ToDouble, IEPSPSIVA:=Row("IEPSPSIVA").ToString.ToDouble, - IVAPorcentaje:=Row("IVAPorcentaje").ToString.ToDouble, RetIVAPorcentaje:=Row("RetIVAPorcentaje").ToString.ToDouble, RetISRPorcentaje:=Row("RetISRPorcentaje").ToString.ToDouble, IEPSPSPorcentaje:=Row("IEPSPSPorcentaje").ToString.ToDouble, IEPSPSIVAPorcentaje:=Row("IEPSPSIVAPorcentaje").ToString.ToDouble, NoDeducible:=If((Row("NoDeducible").ToString().ToUpper().Contiene("TRUE", "1")) AndAlso EsNoDeducible, True, False)) Then - - Retorno = False - Exit For - End If - - 'If Not ObjCompra.VerificaPrepolizas(UsuarioActual.CveEmpresa, CveCompra) Then - ' Retorno = False - 'End If - - If Retorno Then - 'AGREGA AF COMPRA - Cuando es Compra se guarda CveCompraDetalle en AF - If Row("TipoAF").ToString.ToEntero = 2 Then - If Not ObjAF.UpdateActivosFijosCompra(Row("CveActivoFijo").ToString.ToEntero, Row("CveCompraDetalle").ToString.ToEntero, Row("TipoAF").ToString.ToEntero, Row("Total").ToString.ToDouble, TxtFecha.Text.Trim.ToDate) Then - Retorno = False - Exit For - End If - End If - End If - - - Next - - For Each item As String In ClavesBorradas - Dim ObjCompras As New ClsCompras - If Not ObjCompras.DeleteCompraDetalle(item.ToEntero) Then - Retorno = False - End If - Next - - If Retorno Then - If (UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.Funcionalidad(200).ToString = "1") AndAlso IdPoliza > 0 Then - If ObjContaAC Is Nothing Then - ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) - ObjContaAC.IniciaTransacSQL() - End If - - If Not ObjContabilidad.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveEmpresa, UsuarioActual.Empresa, MinFecha, String.Format("{0}-{1}", Serie, Folio), ObjContaAC, pIDPoliza:=ViewState("IdPoliza").ToString.ToEntero) Then - Retorno = False - End If - - End If - End If - - - - Else - Retorno = False - End If - - 'Retorno = True - 'Alert("La Compra se actualizó correctamente.") - Else - - If IdPoliza > 0 Then - If Not ObjContabilidad.UpdatePrePolizasDetalleBloquear(CvePrePoliza, True) Then - Retorno = False - End If - - If Not ObjContabilidad.UpdatePrePoliza(MinFecha, -1, -1, IdPoliza, CvePrePoliza, UsuarioActual.CveEmpresa) Then - Retorno = False - End If - End If - - End If - - Else - Retorno = False - End If - - Else - - Alert("La compra no se puede actualizar debido a que los totales no son iguales, verifique sus cambios", TipoMensaje.MsgError) - - End If - Catch ex As Exception - Alert("Ocurrió un error al actualizar la compra", TipoMensaje.MsgError) - ObjCompra.RollBack() - If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() - - Finally - If Retorno Then - If ObjContabilidad.MensajePolizaDescuadre IsNot Nothing AndAlso ObjContabilidad.MensajePolizaDescuadre.ToString <> "" Then - Alert(ObjContabilidad.MensajePolizaDescuadre.ToString) - End If - ObjCompra.Commit() - If ObjContaAC IsNot Nothing Then ObjContaAC.Commit() - Dim Msg As New StringBuilder() - - Msg.Append("La Compra se actualizó correctamente") - - Alert(Msg.ToString()) - Else - ObjCompra.RollBack() - If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() - Alert("Ocurrió un error al actualizar la compra, por favor vuelva a intentar.", TipoMensaje.MsgAdvertencia) - End If - - If ObjContaAC IsNot Nothing Then ObjContaAC.Dispose() - - End Try - - ObjCompra.Dispose() - ObjProveedores.Dispose() - ObjInventario.Dispose() - ObjContabilidad.Dispose() - ObjAF.Dispose() - If ObjContaAC IsNot Nothing Then ObjContaAC.Dispose() - - CargaGvBitacora() - UpBitacora.Update() - End Sub - - Private Function ComparaDatatables() As Boolean - Dim NumRow As Integer = 0 - For Each row1 As DataRow In TmpDT.Rows - Dim NumRow2 As Integer = 0 - For Each row2 As DataRow In TmpDTOriginal.Rows - If NumRow2 = NumRow Then - If (row1("CveSubProyecto").ToString.ToEntero <> row2("CveSubProyecto").ToString.ToEntero) Or - (row1("CveClasificacion").ToString.ToEntero <> row2("CveClasificacion").ToString.ToEntero) Or - (row1("CveTipoGasto").ToString.ToEntero <> row2("CveTipoGasto").ToString.ToEntero) Or - (row1("Total").ToString.ToDouble <> row2("Total").ToString.ToDouble) Or - (row1("NoDeducible").ToString <> row2("NoDeducible").ToString) Or - (row1("CvePS").ToString.ToEntero <> row2("CvePS").ToString.ToEntero) Then - Return False - End If - End If - NumRow2 += 1 - Next - NumRow += 1 - Next - Return True - End Function - - Private Function ActualizarPrePoliza(ObjConta As ClsContabilidad, ObjCompra As ClsCompras) As Boolean - - Dim Retorno = True, ErrorPrepoliza = False - Dim CvePlantillaPrePoliza As Integer - If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - CvePlantillaPrePoliza = 60 - Else - CvePlantillaPrePoliza = 1 - End If - Dim tIdContaProveedor As Integer = CtaProveedor - Dim ImporteAnticipo As Decimal = 0 - - - If (ArrAnticipos.Count > 0 And CveCompra > 0) Or (ArrAnticipos.Count > 0 And UsuarioActual.Empresa.UsaAC) Then '-- ESTO SE QUITO - IPP - 04 NOVIMEBRE 2016 - CvePlantillaPrePoliza = 52 - 'cuenta de anticipos - tIdContaProveedor = CtaProveedorAnticipos - For Each Ant As Compras_Compras.Anticipos In ArrAnticipos - ImporteAnticipo += Ant.Importe - Next - If Math.Round(ImporteAnticipo, 2) > TxtTotal.Text.ToDouble Then - Alert("El Importe seleccionado es mayor a la compra", TipoMensaje.MsgAdvertencia) - Return False - End If - - End If - - If RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then - If EmpresaPrueba Then - If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - CvePlantillaPrePoliza = 60 - Else - CvePlantillaPrePoliza = 1 - End If - Else - CvePlantillaPrePoliza = 9 - End If - End If - - - - Dim CveMovimientoInventario As Integer = CveMovimientoAlmacen - - - Dim DT As DataTable - Dim tipoCambioActual, tipoCambioPago As Decimal - Dim FechaMovimiento As Date = TxtFecha.Text.ToDate - - - If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then - tipoCambioActual = GlobalTipoCambio(FechaMovimiento).ToString.ToDecimal - tipoCambioActual = If(DivTC.Visible Or TipoCambio.ToDecimal > 0, TipoCambio.ToDecimal, tipoCambioActual) - tipoCambioPago = GlobalTipoCambio(TxtFechaPago.Text.ToDate).ToString.ToDecimal - Else - tipoCambioActual = 1 - tipoCambioPago = 1 - End If - - If ObjConta.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPrePoliza) Then - For Each Row As DataRow In ObjConta.DtResultados.Rows - - Dim ConceptoContable = Row("CveConcepto").ToString.ToEntero - Dim TipoMovimiento As Boolean = If(Row("TipoMovto").ToString = "True", True, False) - Dim importeMovimiento As Decimal = 0 - Dim IdCtaContable As Integer = 0 - Dim CveCuenta As Integer = 0 - Dim importeMN As Decimal = 0 - Dim Multiplicador As Integer = If(Row("Multiplicador").ToString.ToEntero = 1, 1, -1) - Dim Referencia As String = $"{TxtSerie.Text}-{TxtFolio.Text}" ' concatenation interpolation - - Select Case ConceptoContable - 'Case 5 - ' IdCtaContable = 1244 - ' If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, Referencia, 5, Referencia, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=DdlProveedor.SelectedValue.ToEntero, CvePersonal:=CvePersonal, CveMovimientoAlmacen:=CveMovimientoInventario, ImporteMX:=TxtTotal.Text.ToDecimal, ImporteME:=If(tipoCambioActual = 1, 0, TxtTotal.Text.ToDecimal), CveCuenta:=CveCuenta) Then - ' ErrorPrepoliza = True - ' End If - ' IdCtaContable = 1243 - ' If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, Referencia, 205, Referencia, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=DdlProveedor.SelectedValue.ToEntero, CvePersonal:=CvePersonal, CveMovimientoAlmacen:=CveMovimientoInventario, ImporteMX:=TxtTotal.Text.ToDecimal, ImporteME:=If(tipoCambioActual = 1, 0, TxtTotal.Text.ToDecimal), CveCuenta:=CveCuenta) Then - ' ErrorPrepoliza = True - ' End If - Case 6 - Dim CveProveedorConcepto As Integer = 0, CveAcreedor As Integer = 0, CveIE As Integer = 0, CveColectiva As Integer = 0, CveCreditoDetalle As Integer = 0 - Dim ConceptoPersonal As String = "", Concepto As String = "" - - If Not ObjConta.GetPrePolizasDetalle(CvePrePoliza) Then - ErrorPrepoliza = True - Else - If ObjConta.DtResultados.FiltraParametros("CveConceptoContable IN (6,68,49,205,176)").Rows.Count > 0 Then - CveProveedorConcepto = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveProveedor").ToString.ToEntero - CveAcreedor = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveAcreedor").ToString.ToEntero - CveIE = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveIE").ToString.ToEntero - CveColectiva = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveColectiva").ToString.ToEntero - CveCreditoDetalle = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveCreditoDetalle").ToString.ToEntero - Concepto = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("Concepto").ToString - End If - End If - - If CveProveedorConcepto <= 0 Then - CveProveedorConcepto = DdlProveedor.SelectedValue.ToEntero - End If - - 'Removemos los conceptos de la prepoliza - ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 6, CveCompra, 1) 'GASTO - ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 68, CveCompra, 1) 'ALMACEN - ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 49, CveCompra, 1) 'AF - ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 205, CveCompra, 1) 'PS YA RECIBIDO - ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 230, CveCompra, 1) 'PS YA RECIBIDO - ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 231, CveCompra, 1) 'PS YA RECIBIDO - ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 176, CveCompra, 1) 'PS NO RECIBIDO - ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 228, CveCompra, 1) 'PS NO RECIBIDO - ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 229, CveCompra, 1) 'PS NO RECIBIDO - - 'OBTIENE METODO DE CONTABILIZACIÓN AL GUARDAR - Dim ConceptoContabilizacionAlmacen = 0 - If ObjCompra.GetCompras(CveCompra, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then - ConceptoContabilizacionAlmacen = ObjCompra.DtResultados.FiltroPrimeroValor("CveConceptoContableAlmacen").ToEntero - End If - - 'AF - DT = TmpDT.FiltraParametros("ISNULL(TipoAF,0) = 2") - If DT.Rows.Count > 0 AndAlso DdlTipoComprobante.SelectedValue <> "NC" And ConceptoContabilizacionAlmacen = 0 Then - For Each Row2 As DataRow In DT.Rows - importeMovimiento = Row2("Total").ToString.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - If ObjConta.GetRetCuenta(49, Row2("CveActivoFijo").ToString.ToEntero) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijo").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijoSIG").ToString.ToEntero - End If - End If - - If importeMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Row2("CodAF").ToString, 49, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveActivoFijo:=Row2("CveActivoFijo").ToString.ToEntero, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta) Then - ErrorPrepoliza = True - End If - End If - Next - End If - - 'LIMPIA - importeMovimiento = 0 - IdCtaContable = 0 - CveCuenta = 0 - - 'COSTO ALMACEN - Dim DtAlmacenes = GlobalDTAlmacen(UsuarioActual.CveEmpresa) - If UsuarioActual.Empresa.UsaInventarios AndAlso Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And ConceptoContabilizacionAlmacen = 0 Then - DT = TmpDT.FiltraParametros("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) > 0", "", {"CveAlmacen"}) - 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN - For Each Dr As DataRow In DT.Rows - If DtAlmacenes.FiltroPrimeroValor("Modalidad", $"CveAlmacen = {Dr("CveAlmacen").ToString.ToEntero}").ToString = "Solo Existencia" Then - Dr("CveAlmacen") = 0 - End If - Dr.AcceptChanges() - Next - DT.AcceptChanges() - DT = DT.FiltraParametros("ISNULL(CveAlmacen,0) > 0") - If DT.Rows.Count > 0 AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then - For Each Row2 As DataRow In DT.Rows - - importeMovimiento = TmpDT.SUM("Total", $"CveAlmacen = {Row2("CveAlmacen")}").ToString.ToDecimal + TmpDT.SUM("CostoIndirectoAlmacen", $"CveAlmacen = {Row2("CveAlmacen")}").ToString.ToDecimal 'Row2("Total").ToString.ToDecimal + Row2("CostoIndirectoAlmacen").ToString.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - If ObjConta.GetRetCuenta(68, GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContableSIG").ToString.ToEntero - End If - End If - If importeMovimiento <> 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 68, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveMovimientoAlmacen:=CveMovimientoInventario, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta) Then - ErrorPrepoliza = True - End If - End If - Next - End If - End If - - 'LIMPIA - importeMovimiento = 0 - IdCtaContable = 0 - CveCuenta = 0 - - 'INV [MERCANCIA RECIBIDA POR ADELANTADO (OC) | MERCANCIA PENDIENTE POR RECIBIR (COMPRA) ] - If UsuarioActual.Empresa.UsaInventarios And Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And ConceptoContabilizacionAlmacen.Contiene(176, 205) Then - importeMovimiento = TmpDT.SUM("Total", $"ISNULL(TipoAF,0) <> 2 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveTipoPS = 2").ToString.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - - If ObjConta.GetRetCuenta(ConceptoContabilizacionAlmacen, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - End If - End If - - If importeMovimiento <> 0 Then - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContabilizacionAlmacen, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta) Then - ErrorPrepoliza = True - End If - End If - - End If - - 'NC CON PRODUCTOS - CUENTA PUENTE - - If UsuarioActual.Empresa.UsaInventarios And Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And ConceptoContabilizacionAlmacen.Contiene(225) Then - importeMovimiento = TmpDT.SUM("Total", $"ISNULL(TipoAF,0) <> 2 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveTipoPS = 2").ToString.ToDecimal - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - - If ObjConta.GetRetCuenta(ConceptoContabilizacionAlmacen, UsuarioActual.CveEmpresa) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - End If - End If - - If importeMovimiento <> 0 Then - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContabilizacionAlmacen, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta) Then - ErrorPrepoliza = True - End If - End If - End If - - - 'GASTO - DT = TmpDT.Copy - 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN - For Each Dr As DataRow In DT.Rows - If DtAlmacenes.FiltroPrimeroValor("Modalidad", $"CveAlmacen = {Dr("CveAlmacen").ToString.ToEntero}").ToString = "Solo Existencia" Then - Dr("CveAlmacen") = 0 - End If - Dr.AcceptChanges() - Next - DT.AcceptChanges() - DtAlmacenes.Dispose() - - 'QUITA 1-[MERCANCIA RECIBIDA POR ADELANTADO (OC) | MERCANCIA PENDIENTE POR RECIBIR (COMPRA)] 2-[NC CON PRODUCTOS] - If UsuarioActual.CveEmpresa.Contiene(119) And UsuarioActual.Empresa.UsaInventarios And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And ConceptoContabilizacionAlmacen > 0 Then - DT = DT.FiltraParametros("CveTipoPS <> 2") - End If - - Dim DTDistinct = DT.Copy - If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - DTDistinct = DTDistinct.FiltraParametros("ISNULL(TipoAF,0) <> 2", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveProyecto", "CveSubProyecto", "CveTipoGasto", "TipoGasto"}) - Else - DTDistinct = DTDistinct.FiltraParametros("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveProyecto", "CveSubProyecto", "CveTipoGasto", "TipoGasto"}) - End If - - If DTDistinct.Rows.Count > 0 Then - For Each Row2 As DataRow In DTDistinct.Rows - - 'DETERMINA IMPORTE - If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - importeMovimiento = DT.SUM("Total", String.Format("ISNULL(TipoAF,0) <> 2 AND CveClasificacion = {0} AND CveSubProyecto = {1} AND ISNULL(CveTipoGasto,0) = {2}", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal - Else - importeMovimiento = DT.SUM("Total", String.Format("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveClasificacion = {0} AND CveSubProyecto = {1} AND ISNULL(CveTipoGasto,0) = {2}", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal - End If - importeMN = importeMovimiento * tipoCambioActual * Multiplicador - - 'CLASIFICACION - If Row2("CveClasificacion").ToString.ToEntero > 0 Then - If ObjConta.GetRetCuenta(6, Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero) Then - If ObjConta.DtResultados.Rows.Count > 0 AndAlso ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero - Else - IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGasto", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero - CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero - End If - End If - End If - - 'SEGMENTO DE NEGOCIO - Dim IdSegmentoNegocio As Integer = -1 - Dim drT As DataRow = GlobalDTSubProyectos(-1, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero).FiltroPrimero(String.Format("CveSubProyecto = {0} ", Row2("CveSubProyecto").ToString.ToEntero)) - If drT IsNot Nothing Then - IdSegmentoNegocio = drT("IdSegNeg").ToString.ToEntero - End If - - 'AGREGA MOVIMIENTO - If importeMovimiento <> 0 Then - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 6, Concepto, FechaMovimiento, IdCtaContable, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, CveTipoGasto:=Row2("CveTipoGasto").ToString.ToEntero) Then - ErrorPrepoliza = True - End If - End If - - Next - End If - - 'LIMPIA - importeMovimiento = 0 - IdCtaContable = 0 - CveCuenta = 0 - - End Select - - Next - End If - - If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, 4) Then - If ObjConta.ValorPolizaDescuadre > 0 Then - ErrorPrepoliza = True - GuardaLogAD($"Compras/Compras-Actualizar | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") - End If - End If - - If Not ErrorPrepoliza Then - Retorno = True - Else - Retorno = False - End If - - Return Retorno - End Function - - Protected Sub ImgActualizarProyecto_Click(sender As Object, e As EventArgs) Handles ImgActualizarProyecto.Click - 'actualizo los proyectos - Dim Compra As New ClsCompras - Dim Retorno As Boolean = True - Compra.IniciaTransacSQL() - - For Each Row As DataRow In TmpDT.Rows - - If Not Compra.UpdateCompraDetalle(Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDouble, Row("PU").ToString.ToDouble, Row("IVA").ToString.ToDouble, Row("Total").ToString.ToDouble, - Row("Descuento").ToString.ToDouble, Row("Observaciones").ToString, Row("CveSubProyecto").ToString.ToEntero, Row("CvePresupuestoEgreso").ToString.ToEntero, -2, Row("CveCompraDetalle").ToString.ToEntero, CveTipoGasto:=Row("CveTipoGasto").ToString.ToEntero) Then - - Retorno = False - Exit For - End If - Next - - If Retorno Then - Compra.Commit() - Alert("La Compra se actualizó correctamente.") - Else - Compra.RollBack() - End If - - - Compra.Dispose() - - - End Sub - - Protected Sub BtnVerAmortizacion_Click(sender As Object, e As EventArgs) Handles BtnVerAmortizacion.Click - BtnVerAmortizacion.Visible = False - 'BtnAmortizar.Visible = True - 'activo el cuadro para amortizar - - RBLPago.SelectedValue = "2" ' selecciono contado - PnlContado.Visible = True - PnlContadoBancos.Visible = False - RBLContado.Items.Clear() - RBLContado.Items.Add(New ListItem("Deudores", "4")) - - RBLContado.SelectedValue = "4" 'selecciono deudores - PnlContadoDeudores.Visible = True - CargaDeudores() - End Sub - - Protected Sub ImgAjusteSobreTotal_Click(sender As Object, e As ImageClickEventArgs) Handles ImgAjustaSobreTotal.Click - 'realizo el ajuste de los productos - 'total - iva - Dim Diferencia As Decimal = TxtTotal.Text.ToDecimal() - TxtIVA.Text.ToDecimal + TxtRetIVA.Text.ToDecimal + TxtRetISR.Text.ToDecimal - (TxtSubTotal2.Text.ToDecimal) - - AjustaImporteUltimoConcepto(Diferencia) - BtnGuardar.Enabled = True - UpFacturar.Update() - + UpPS.Update() + End If + RegistraScript(String.Format("$('#{0}').modal('hide');", "DivAnticipos")) + Else + Alert("No hay movimientos seleccionados para aplicar", TipoMensaje.MsgAdvertencia) + End If + UPPAnticiposSel.Update() End Sub -#End Region -#Region "CargaXML" + Protected Sub ImgClasificacion_Click(sender As Object, e As EventArgs) Handles ImgClasificacion.Click - Private Function ValorXML(n As XmlNode, Campo As String, Optional Retorno As String = "") As String - Dim o As XmlNode = n.Attributes.Cast(Of XmlAttribute)().SingleOrDefault(Function(a) String.Compare(a.Name, Campo, True) = 0) - If o Is Nothing Then - Return Retorno - Else - Return o.Value - End If - End Function - - Private Sub CargaComprobanteXML(XMLDoc As XmlDocument) - Dim nodo As XmlNode = XMLDoc.DocumentElement - - _Serie = ValorXML(nodo, "serie") - If _Serie <> "" Then _Serie = _Serie - - Version = ValorXML(nodo, "version") - _Folio = ValorXML(nodo, "folio") - _Fecha = ValorXML(nodo, "fecha") - SubTotal = ValorXML(nodo, "subTotal").ToDecimal - Total = ValorXML(nodo, "total").ToDecimal - Descuentos = ValorXML(nodo, "descuento").ToDecimal - _Moneda = ValorXML(nodo, "Moneda") - _TipoComprobante = ValorXML(nodo, "tipoDeComprobante") - TipoCambio = ValorXML(nodo, "TipoCambio", "1").ToDouble - - If Version = "3.3" Then - Dim drm As DataRow = GlobalDTVtaMetodoPago.FiltroPrimero(String.Format("ClaveMetodoPagoSAT = '{0}'", ValorXML(nodo, "MetodoPago"))) - If drm IsNot Nothing Then - CveMetodoPago = drm("CveMetodoPago").ToString.ToEntero - MetodoPago = drm("MetodoPagoSAT").ToString - End If - End If - - - Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix) - Dim cfdVer As String = "http://www.sat.gob.mx/cfd/3" - Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable) - - If Prefijo.ToLower <> "cfdi" Then cfdVer = "http://www.sat.gob.mx/cfd/2" - namespaces.AddNamespace(Prefijo, cfdVer) - namespaces.AddNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital") - namespaces.AddNamespace("implocal", "http://www.sat.gob.mx/implocal") - namespaces.AddNamespace("registrofiscal", "http://www.sat.gob.mx/registrofiscal") - - Dim node As XmlNode - node = XMLDoc.SelectSingleNode(String.Format("//{0}:Emisor", Prefijo), namespaces) - - If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then - EmisorRFC = ValorXML(node, "RFC") - 'EmisorNombre = ValorXML(node, "nombre") - End If - - node = XMLDoc.SelectSingleNode(String.Format("//{0}:CfdiRelacionados", Prefijo), namespaces) + If CveCompra > 0 Then + + Dim SiSelecciono As Boolean = False + For Each gvr As GridViewRow In GvPS.Rows + If gvr.FCCheckBox("CheckClasificacion").Checked = True Then + SiSelecciono = True + Exit For + End If + Next + If SiSelecciono = False Then + Alert("Tiene que seleccionar algun Producto o Servicio", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + DdlAplicaClasificacion.SelectedValue = "-1" + RegistraScript(String.Format("$('#{0}').modal('show');", "DivClasificacion")) + Else + RegistraScript(String.Format("$('#{0}').modal('show');", "DivClasificacion")) + End If + + End Sub + + Protected Sub BtnActualizar_Click(sender As Object, e As EventArgs) Handles BtnActualizar.Click + + 'VALIDA IMPORTES + If CveFactura > 0 Then 'SI NO VIENE DE FACTURA/XML NO VALIDA TOTALES + If Not ValidaTotalesGuardar() Then + Exit Sub + End If + End If + + For Each Row As DataRow In TmpDT.Rows + If Row("CveSubProyecto").ToString.ToEntero <= 0 Then + Alert("No se ha completado la asignacion de proyectos en la compra. ", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If Row("CveClasificacionActualizar").ToString.ToEntero <= 0 Then 'If NotHas117 AndAlso Row("CveClasificacionActualizar").ToString.ToEntero <= 0 Then + Alert("Hay productos que no tienen clasificación asignada.
Favor de asignarle una y darle guardar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If UsuarioActual.Empresa.Funcionalidad(527) = "1" Then + If Row("CveTipoGasto").ToString.ToEntero <= 0 Then + Alert("No se ha completado la asignacion de tipos de gasto en la compra.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + Next + + + Dim ObjCompra As New ClsCompras + Dim ObjProveedores As New ClsCompProveedores(ObjCompra.IniciaTransacSQL()) + Dim ObjInventario As New ClsInventarios(ObjCompra.IniciaTransacSQL) + Dim ObjContabilidad As New ClsContabilidad(ObjCompra.IniciaTransacSQL) + Dim ObjAF As New ClsAF(ObjCompra.IniciaTransacSQL) + Dim ObjContaAC As ClsContPAQi = New ClsContPAQi(UsuarioActual.Empresa) + + Dim Retorno As Boolean = True + Dim CveEstatusFactura As Integer = HdnCveEstatusFactura.Value.ToEntero + Dim MultiplicadorNC = If(DdlTipoComprobante.SelectedValue = "NC", -1, 1) + + Dim ErrorAC = False + Dim IDPolizaComprometido = 0 + + If ChkProgramarPago.Checked AndAlso CveEstatusFactura = 1 Then + CveEstatusFactura = 2 + End If + If Not ChkProgramarPago.Checked AndAlso CveEstatusFactura = 2 Then + CveEstatusFactura = 1 + End If + Try + 'Revisamos que los cambios hechos mantengan la interidad de los numeros + If HFDiferenciaCompra.Value = TxtTotal.Text Or CveFactura < 1 Or CveCompra < 1 Then + + If IdPoliza > 0 Then + If Not ObjContabilidad.UpdatePrePolizasDetalleBloquear(CvePrePoliza, False) Then + Retorno = False + End If + + If Not ObjContabilidad.UpdatePrePoliza(MinFecha, -1, -1, Nothing, CvePrePoliza, UsuarioActual.CveEmpresa) Then + Retorno = False + End If + End If + + 'PORCENTAJE IVA + Dim PorcentajeIVA As Decimal = TmpDT.MAX("IVAPorcentaje").ToDecimal + + If ObjCompra.UpdateCompra(TxtDescripcion.Text.Trim, TxtFolioSecundario.Text.Trim, TxtFechaPago.Text.ToDate, ChkAplicaNotaCredito.Checked, TxtObsFact.Text.Trim, CveEstatusFactura, + TxtDescuento.Text.ToDouble, TxtSubTotal.Text.ToDouble, TxtIVA.Text.ToDouble, TxtTotal.Text.ToDouble, + UsuarioActual.CveUsuario, CveCompra, CveCajaChica:=DdlRembolsoCajaChica.SelectedValue.ToEntero, CvePersonal:=DdlRembolsoPersonal.SelectedValue.ToEntero, CveProveedorSucursal:=If(DdlProveedorSucursal.SelectedValue.ToEntero > 0, DdlProveedorSucursal.SelectedValue.ToEntero, -1), PorcentajeIVA:=PorcentajeIVA, NumeroReembolso:=TxtRembolsoNumero.Text, + CveTipoCompra:=DdlTipoCompra.SelectedValue.ToEntero, NoDeducible:=EsNoDeducible) Then + + If Not ComparaDatatables() Then + + 'Regeneramos el concepto 6 de PrePolizas + 'If UsuarioActual.Empresa.Funcionalidad(207) = "1" Then + ' If Not RegenerarPrePoliza(ObjContabilidad, ObjContaAC, 6, False, MultiplicadorNC) Then + ' Retorno = False + ' End If + 'End If + + + + 'If UsuarioActual.Empresa.Funcionalidad(207) = "1" Then + If Not ActualizarPrePoliza(ObjContabilidad, ObjCompra) Then + Retorno = False + End If + 'End If + + ''EMPIEZA: SI USA AC + If UsuarioActual.Empresa.UsaAC AndAlso IdPoliza > 0 Then + ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) + ObjContaAC.IniciaTransacSQL() + + + 'ELIMINA TODOS LOS MOVIMIENTOS DE LA POLIZA + ObjContaAC.RemoveAllMovimientos(IdPoliza) + + + 'INSERTA LOS NUEVOS MOVIMIENTOS DE LA POLIZA + If IdPoliza > 0 Then + Dim CuentaAbono As Integer + Dim Importe As Decimal = 0 + Dim TotalDetalle As Decimal = 0 + + 'CUENTA PROVEEDOR + If CtaProveedor <= 0 Then + If ObjContaAC.GetCuentas(-1, "021120000000000000", -1) Then + Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") + If drCuenta IsNot Nothing Then + CuentaAbono = drCuenta("Id").ToString.ToEntero + Dim FolioProveedor = ObjContaAC.GetFolioProveedores("021120000000000000").ToString + ViewState("CtaProveedor") = ObjContaAC.AddCuenta(String.Format("02112{0}000000000", FolioProveedor.PadLeft(4, "0"c)), NombreProveedor, "D", 2, 0, 1, 0, "", 1, CuentaAbono) + ObjProveedores.UpdateProveedorIdCuentaAC(CveProveedor, CtaProveedor) + Else + ErrorAC = True + End If + Else + ErrorAC = True + End If + End If + + Dim ConceptoRenglon As String = "" + If Not ErrorAC Then + + Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA, tRetIVA, tRetISR As Decimal + + Dim ipresup As Integer = 0 + + 'COMIENZA: PRUEBA AGRUPACION CONCEPTOS + Dim Presup = From gvr As DataRow In TmpDT.Rows.Cast(Of DataRow)() + Group gvr By Grp = New With { + Key .CvePresupuestoEgreso = gvr("CvePresupuestoEgreso").ToString.ToEntero, + Key .CveActivoFijo = If(gvr("TipoAF").ToString.ToEntero = 2, gvr("CveActivoFijo").ToString.ToEntero, -1) + } Into Group + Select Grp.CvePresupuestoEgreso, Grp.CveActivoFijo, + TotalImporte = Group.Sum(Function(r) r("Total").ToString.ToDecimal) + Dim Fecha As Date = TxtFecha.Text.ToDate + + 'PresupuestoEgresos + Dim DtPresupuestosTemp As DataTable + Dim IdCuentaComprometido, IdCuentaPorEjercer, IdCuentaDevengado, IdCuentaMatriz As Integer + + 'Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA As Double + tTotalIVA = TxtIVA.Text.ToDecimal + tRetIVA = TxtRetIVA.Text.ToDecimal + tRetISR = TxtRetISR.Text.ToDecimal + + 'tTotalIVA = tTotalIVA - tRetIVA - tRetISR + + tTotalGral = TxtTotal.Text.ToDecimal + tRetIVA + tRetISR ' EL TOTAL GENERAL DEBE DE SER EL SUBTOTAL + IVA, NO SE DEBEN DE INCLUIR LAS RETENCIONES, POR ESO SE RESTA + tDiferenciaIVA = tTotalIVA + tIVA = 0 + ipresup = 0 + + 'INVENTARIOS EN AC + Dim CuentaMatrizAlmacen As Integer + Dim ContadorInventario As Integer = GvInv.Rows.Cast(Of GridViewRow)().Count(Function(gvr) gvr.FCCheckBox("cbInv").Checked) + + 'COMENTADO 15/3/2016 + 'cuando hay algo que ingresar a inventarios + 'Dim x As Integer = 0 + 'For Each Dr As DataRow In TmpDT.Rows + ' If GvInv.Rows.Count > 0 Then + ' If GvInv.Rows(x).FCCheckBox("cbInv").Checked Then + ' Dr("CveAlmacen") = GvInv.Rows(x).FCDropDownList("ddlEAlmacen").SelectedValue.ToEntero + ' Else 'limpio el valor para que no truene en linq mas abajo + ' Dr("CveAlmacen") = 0 + ' End If + ' x = x + 1 + ' Else + ' Exit For + ' End If + 'Next + + ''previamente si hay un ingreso a inventarios + 'Dim CtaAlmacen As Integer + 'If ContadorInventario > 0 Then + ' Dim drr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", TmpDT.Rows(0)("CveAlmacen").ToString)) + ' If drr IsNot Nothing Then + ' CtaAlmacen = drr("IdCtaContable").ToString.ToEntero + ' End If + 'End If + + Dim CtaAlmacen As Integer + If ContadorInventario > 0 Then + Dim drr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero)) + If drr IsNot Nothing Then + CtaAlmacen = drr("IdCtaContable").ToString.ToEntero + End If + End If + Dim DescuentoConIVA As Double + Dim tPorIVA As Decimal = tTotalIVA / (tTotalGral - tTotalIVA) + Dim tAjusteTotal As Decimal = 0 + + For Each grp In Presup + Importe = grp.TotalImporte + TotalDetalle += Importe + ipresup += 1 + If Importe > 0 Then + 'saco la proporcion de iva que le corresponde + tIVA = Math.Round(Importe * tPorIVA, 2) + tDiferenciaIVA -= tIVA + 'identifico si es el ultimo registro, para ver si es necesario un ajuste + If ipresup = Presup.Count Then + If Math.Round(TotalDetalle - tTotalGral, 2) <= 0.01 AndAlso tDiferenciaIVA > 0 Then + tIVA += tDiferenciaIVA + End If + End If + + 'le sumo el iva al concepto + Importe += tIVA + 'codigo Provisional, para cuand tenga descuento, solo tome el subtotal * el iva,RMF + If TxtDescuento.Text.ToDouble > 0 Then + Importe = grp.TotalImporte * (1 + tPorIVA) + End If + + tAjusteTotal += Importe + + 'valido que la sumas de lo detalles no exceda al totalgeneral + If Math.Round(tAjusteTotal, 2) > tTotalGral Then + 'le resto la diferencia + Importe -= (tAjusteTotal - tTotalGral) + End If + + 'Presupuesto Egresos + DtPresupuestosTemp = DtPresupuestos.FiltraParametros(String.Format("CvePresupuestoEgreso = {0}", grp.CvePresupuestoEgreso)) + If DtPresupuestosTemp.Rows.Count <> 1 Then + ErrorAC = True + Exit For + End If + IdCuentaComprometido = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString.ToEntero + IdCuentaPorEjercer = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero + IdCuentaDevengado = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString.ToEntero + IdCuentaMatriz = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString.ToEntero + + 'COMPROMETIDO DEPENDIENTE SI EXISTE SU POLIZA + If IDPolizaComprometido = 0 Then + ConceptoRenglon = String.Format("GC Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaPorEjercer, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + Exit For + End If + Else + ErrorAC = True + Exit For + End If + End If + + ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + 'DEVENGADO + If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaDevengado, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + Exit For + End If + Else + ErrorAC = True + Exit For + End If + + + If ContadorInventario > 0 Then + Dim tImporte, ttIVA As Double + + For Each gvr As GridViewRow In GvPS.Rows + 'registra los movimientos del presupuesto asignado, para que no se duplique si hay varios presupeusto dentro de la compra + If gvr.DataKey("CvePresupuestoEgreso").ToEntero = grp.CvePresupuestoEgreso Then + 'saco la proporcion de iva que le corresponde + + tImporte = gvr.FCLiteral("LtlTotal").Text.ToDouble + + ttIVA = Math.Round(tImporte * tTotalIVA / tTotalGral, 2) + ' tDiferenciaIVA -= tIVA + ' 'identifico si es el ultimo registro, para ver si es necesario un ajuste + ' If ipresup = GvPS.Rows.Count Then + ' If Math.Round(TotalDetalle - tTotalGral, 2) <= 0.01 AndAlso tDiferenciaIVA > 0 Then + ' tIVA += tDiferenciaIVA + ' End If + ' End If + + ' ' 'le sumo el iva al concepto + tImporte += ttIVA + + 'PU = tImporte / gvr.DataKey("Cantidad").ToDouble + 'If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, gvr.DataKey("Cantidad").ToDouble, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1) Then + ' ErrorAC = True + ' Exit For + 'End If + End If + + Next + + CuentaMatrizAlmacen = CtaAlmacen + + ElseIf grp.CveActivoFijo > 0 Then + + Dim CtaAF = -1 + Dim AF = "" + Dim CuentaInicial = -1 + + If ObjAF.GetActivosFijos(grp.CveActivoFijo, UsuarioActual.CveEmpresa, "-1", "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "", -1, UsuarioActual.CveEmpresa) Then + CtaAF = ObjAF.Cuenta + AF = ObjAF.Descripcion + CuentaInicial = ObjAF.CuentaInicial + Else + ErrorAC = True + Exit For + End If + + If Not CuentaInicial > 0 Then + CuentaInicial = 1241 + End If + + 'CUENTA AF + If CtaAF <= 0 Then + If ObjContaAC.GetCuentas(-1, String.Format("0{0}0000000000000", CuentaInicial), -1) Then + Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") + If drCuenta IsNot Nothing Then + + CuentaAbono = drCuenta("Id").ToString.ToEntero + Dim FolioAF = ObjContaAC.GetFolioProveedores(String.Format("0{0}0000000000000", CuentaInicial)).ToString + CtaAF = ObjContaAC.AddCuenta(String.Format("0{0}{1}000000000", CuentaInicial, FolioAF.PadLeft(4, "0"c)), AF, "A", 2, 0, 1, 0, "", 1, CuentaAbono) + + ObjAF.UpdateActivosFijosCuentaAC(grp.CveActivoFijo, CtaAF, UsuarioActual.CveUsuario) + Else + ErrorAC = True + End If + Else + ErrorAC = True + End If + End If + + CuentaMatrizAlmacen = CtaAF + Else + CuentaMatrizAlmacen = IdCuentaMatriz + End If + + + ''AFECTAR MATRIZ EGRESOS + If ObjContaAC.AddMovimiento(IdPoliza, CuentaMatrizAlmacen, False, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + + ''VERIFICA SI TIENE DESCUENTO (AMORTIZACION) + If TxtDescuento.Text.ToDouble > 0 AndAlso CtaProveedorAnticipos > 0 Then + DescuentoConIVA = TxtDescuento.Text.ToDecimal * 1.16 + + 'Valida que el descuento con iva cuadre en los totales + If Math.Abs(DescuentoConIVA - (Importe - TxtTotal.Text.ToDouble)) < 0.02 Then + DescuentoConIVA = Importe - TxtTotal.Text.ToDouble + ElseIf DescuentoConIVA <> (Importe - TxtTotal.Text.ToDecimal) Then + ErrorAC = True + Exit For + End If + + 'actualizo el idcuenta del presupuesto + If ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, MultiplicadorNC * (Importe - DescuentoConIVA), "", ConceptoRenglon, 0, Fecha, "") Then + 'agrego a la cuenta contable anticipos + If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorAnticipos, True, MultiplicadorNC * DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + Exit For + End If + Else + ErrorAC = True + Exit For + End If + Else + 'actualizo el idcuenta del + + End If + + Else + ErrorAC = True + Exit For + End If + ''TERMINA AFECTAR MATRIZ EGRESOS + + Else + ErrorAC = True + Exit For + End If + + Next + + If Not ErrorAC Then + 'registro un solo movimiento a proveedores + Importe = TxtTotal.Text.ToDecimal + If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, MultiplicadorNC * Importe, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + End If + End If + + If tRetISR > 0 Then + ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorRetISR, True, MultiplicadorNC * tRetISR, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + End If + End If + + End If + + Else + ErrorAC = True + End If + + 'CUADRA LA POLIZA + ObjContaAC.AjustaPoliza(IdPoliza) + + End If + ''TERMINA: SI USA AC + + + + If Not ErrorAC Then + Dim Cont As Integer = 0 + For Each Row As DataRow In TmpDT.Rows + + 'actualizar las clasificaciones, que se hallan hecho + If Row("CveClasificacionActualizar").ToString.ToEntero > 0 Then + 'REGISTRO EL PRODUCTO + Dim PSS As New ClsProductosServicios + If Not PSS.UpdateClasificacionPS(Row("CveClasificacionActualizar").ToString.ToEntero, UsuarioActual.CveUsuario, Row("CvePS").ToString.ToEntero) Then + Retorno = False + Exit For + End If + 'Row("CvePS") = 20184 'PSS.DtResultados.FiltraParametros("PS = '" & Row("PS").ToString & "' AND CveEmpresa = " & UsuarioActual.CveEmpresa).Rows(0)("CvePS").ToString + PSS.Dispose() + End If + + Dim CvePersonal = GvPersonal.Rows(Cont).FCDropDownList("DdlPersonalGv").SelectedValue.ToEntero + Dim Referencia = GvPersonal.Rows(Cont).FCTextBox("TxtReferencia").Text + + Cont = Cont + 1 + 'Si es AF-INSUMO se guarda en CveActivoFIjo + Dim CveAF = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 1, Row("CveActivoFijo").ToString.ToEntero, -1) + + 'Si es AF-COMPRA se guarda en CveActivoFijoCompra + Dim CveAFCompra = If(Row("CveActivoFijo").ToString.ToEntero > 0 AndAlso Row("TipoAF").ToString.ToEntero = 2, Row("CveActivoFijo").ToString.ToEntero, -1) + + If Not ObjCompra.UpdateCompraDetalle(Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDouble, Row("PU").ToString.ToDouble, Row("IVA").ToString.ToDouble, Row("Total").ToString.ToDouble, + Row("Descuento").ToString.ToDouble, Row("Obs").ToString, Row("CveSubProyecto").ToString.ToEntero, Row("CvePresupuestoEgreso").ToString.ToEntero, CveAF, Row("CveCompraDetalle").ToString.ToEntero, CvePersonal:=CvePersonal, CveTipoGasto:=Row("CveTipoGasto").ToString.ToEntero, AF_Medida:=Row("AFMedida").ToString.ToEntero, AF_TipoMantenimiento:=Row("AFTipoMantenimiento").ToString.ToEntero, Referencia:=Referencia, + RetIVA:=Row("RetIVA").ToString.ToDouble, RetISR:=Row("RetISR").ToString.ToDouble, IEPSPS:=Row("IEPSPS").ToString.ToDouble, IEPSPSIVA:=Row("IEPSPSIVA").ToString.ToDouble, + IVAPorcentaje:=Row("IVAPorcentaje").ToString.ToDouble, RetIVAPorcentaje:=Row("RetIVAPorcentaje").ToString.ToDouble, RetISRPorcentaje:=Row("RetISRPorcentaje").ToString.ToDouble, IEPSPSPorcentaje:=Row("IEPSPSPorcentaje").ToString.ToDouble, IEPSPSIVAPorcentaje:=Row("IEPSPSIVAPorcentaje").ToString.ToDouble, NoDeducible:=If((Row("NoDeducible").ToString().ToUpper().Contiene("TRUE", "1")) AndAlso EsNoDeducible, True, False)) Then + + Retorno = False + Exit For + End If + + 'If Not ObjCompra.VerificaPrepolizas(UsuarioActual.CveEmpresa, CveCompra) Then + ' Retorno = False + 'End If + + If Retorno Then + 'AGREGA AF COMPRA - Cuando es Compra se guarda CveCompraDetalle en AF + If Row("TipoAF").ToString.ToEntero = 2 Then + If Not ObjAF.UpdateActivosFijosCompra(Row("CveActivoFijo").ToString.ToEntero, Row("CveCompraDetalle").ToString.ToEntero, Row("TipoAF").ToString.ToEntero, Row("Total").ToString.ToDouble, TxtFecha.Text.Trim.ToDate) Then + Retorno = False + Exit For + End If + End If + End If + + + Next + + For Each item As String In ClavesBorradas + Dim ObjCompras As New ClsCompras + If Not ObjCompras.DeleteCompraDetalle(item.ToEntero) Then + Retorno = False + End If + Next + + If Retorno Then + If (UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.Funcionalidad(200).ToString = "1") AndAlso IdPoliza > 0 Then + If ObjContaAC Is Nothing Then + ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) + ObjContaAC.IniciaTransacSQL() + End If + + If Not ObjContabilidad.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveEmpresa, UsuarioActual.Empresa, MinFecha, String.Format("{0}-{1}", Serie, Folio), ObjContaAC, pIDPoliza:=ViewState("IdPoliza").ToString.ToEntero) Then + Retorno = False + End If + + End If + End If + + + + Else + Retorno = False + End If + + 'Retorno = True + 'Alert("La Compra se actualizó correctamente.") + Else + + If IdPoliza > 0 Then + If Not ObjContabilidad.UpdatePrePolizasDetalleBloquear(CvePrePoliza, True) Then + Retorno = False + End If + + If Not ObjContabilidad.UpdatePrePoliza(MinFecha, -1, -1, IdPoliza, CvePrePoliza, UsuarioActual.CveEmpresa) Then + Retorno = False + End If + End If + + End If + + Else + Retorno = False + End If + + Else + + Alert("La compra no se puede actualizar debido a que los totales no son iguales, verifique sus cambios", TipoMensaje.MsgError) + + End If + Catch ex As Exception + Alert("Ocurrió un error al actualizar la compra", TipoMensaje.MsgError) + ObjCompra.RollBack() + If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() + + Finally + If Retorno Then + If ObjContabilidad.MensajePolizaDescuadre IsNot Nothing AndAlso ObjContabilidad.MensajePolizaDescuadre.ToString <> "" Then + Alert(ObjContabilidad.MensajePolizaDescuadre.ToString) + End If + ObjCompra.Commit() + If ObjContaAC IsNot Nothing Then ObjContaAC.Commit() + Dim Msg As New StringBuilder() + + Msg.Append("La Compra se actualizó correctamente") + + Alert(Msg.ToString()) + Else + ObjCompra.RollBack() + If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() + Alert("Ocurrió un error al actualizar la compra, por favor vuelva a intentar.", TipoMensaje.MsgAdvertencia) + End If + + If ObjContaAC IsNot Nothing Then ObjContaAC.Dispose() + + End Try + + ObjCompra.Dispose() + ObjProveedores.Dispose() + ObjInventario.Dispose() + ObjContabilidad.Dispose() + ObjAF.Dispose() + If ObjContaAC IsNot Nothing Then ObjContaAC.Dispose() + + CargaGvBitacora() + UpBitacora.Update() + End Sub + + Private Function ComparaDatatables() As Boolean + Dim NumRow As Integer = 0 + For Each row1 As DataRow In TmpDT.Rows + Dim NumRow2 As Integer = 0 + For Each row2 As DataRow In TmpDTOriginal.Rows + If NumRow2 = NumRow Then + If (row1("CveSubProyecto").ToString.ToEntero <> row2("CveSubProyecto").ToString.ToEntero) Or + (row1("CveClasificacion").ToString.ToEntero <> row2("CveClasificacion").ToString.ToEntero) Or + (row1("CveTipoGasto").ToString.ToEntero <> row2("CveTipoGasto").ToString.ToEntero) Or + (row1("Total").ToString.ToDouble <> row2("Total").ToString.ToDouble) Or + (row1("NoDeducible").ToString <> row2("NoDeducible").ToString) Or + (row1("CvePS").ToString.ToEntero <> row2("CvePS").ToString.ToEntero) Then + Return False + End If + End If + NumRow2 += 1 + Next + NumRow += 1 + Next + Return True + End Function + + Private Function ActualizarPrePoliza(ObjConta As ClsContabilidad, ObjCompra As ClsCompras) As Boolean + + Dim Retorno = True, ErrorPrepoliza = False + Dim CvePlantillaPrePoliza As Integer + If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + CvePlantillaPrePoliza = 60 + Else + CvePlantillaPrePoliza = 1 + End If + Dim tIdContaProveedor As Integer = CtaProveedor + Dim ImporteAnticipo As Decimal = 0 + + + If (ArrAnticipos.Count > 0 And CveCompra > 0) Or (ArrAnticipos.Count > 0 And UsuarioActual.Empresa.UsaAC) Then '-- ESTO SE QUITO - IPP - 04 NOVIMEBRE 2016 + CvePlantillaPrePoliza = 52 + 'cuenta de anticipos + tIdContaProveedor = CtaProveedorAnticipos + For Each Ant As Compras_Compras.Anticipos In ArrAnticipos + ImporteAnticipo += Ant.Importe + Next + If Math.Round(ImporteAnticipo, 2) > TxtTotal.Text.ToDouble Then + Alert("El Importe seleccionado es mayor a la compra", TipoMensaje.MsgAdvertencia) + Return False + End If + + End If + + If RBLContado.SelectedValue = "2" AndAlso DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then + If EmpresaPrueba Then + If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + CvePlantillaPrePoliza = 60 + Else + CvePlantillaPrePoliza = 1 + End If + Else + CvePlantillaPrePoliza = 9 + End If + End If + + + + Dim CveMovimientoInventario As Integer = CveMovimientoAlmacen + + + Dim DT As DataTable + Dim tipoCambioActual, tipoCambioPago As Decimal + Dim FechaMovimiento As Date = TxtFecha.Text.ToDate + + + If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then + tipoCambioActual = GlobalTipoCambio(FechaMovimiento).ToString.ToDecimal + tipoCambioActual = If(DivTC.Visible Or TipoCambio.ToDecimal > 0, TipoCambio.ToDecimal, tipoCambioActual) + tipoCambioPago = GlobalTipoCambio(TxtFechaPago.Text.ToDate).ToString.ToDecimal + Else + tipoCambioActual = 1 + tipoCambioPago = 1 + End If + + If ObjConta.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPrePoliza) Then + For Each Row As DataRow In ObjConta.DtResultados.Rows + + Dim ConceptoContable = Row("CveConcepto").ToString.ToEntero + Dim TipoMovimiento As Boolean = If(Row("TipoMovto").ToString = "True", True, False) + Dim importeMovimiento As Decimal = 0 + Dim IdCtaContable As Integer = 0 + Dim CveCuenta As Integer = 0 + Dim importeMN As Decimal = 0 + Dim Multiplicador As Integer = If(Row("Multiplicador").ToString.ToEntero = 1, 1, -1) + Dim Referencia As String = $"{TxtSerie.Text}-{TxtFolio.Text}" ' concatenation interpolation + + Select Case ConceptoContable + 'Case 5 + ' IdCtaContable = 1244 + ' If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importeMovimiento, Referencia, 5, Referencia, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=DdlProveedor.SelectedValue.ToEntero, CvePersonal:=CvePersonal, CveMovimientoAlmacen:=CveMovimientoInventario, ImporteMX:=TxtTotal.Text.ToDecimal, ImporteME:=If(tipoCambioActual = 1, 0, TxtTotal.Text.ToDecimal), CveCuenta:=CveCuenta) Then + ' ErrorPrepoliza = True + ' End If + ' IdCtaContable = 1243 + ' If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, Referencia, 205, Referencia, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=DdlProveedor.SelectedValue.ToEntero, CvePersonal:=CvePersonal, CveMovimientoAlmacen:=CveMovimientoInventario, ImporteMX:=TxtTotal.Text.ToDecimal, ImporteME:=If(tipoCambioActual = 1, 0, TxtTotal.Text.ToDecimal), CveCuenta:=CveCuenta) Then + ' ErrorPrepoliza = True + ' End If + Case 6 + Dim CveProveedorConcepto As Integer = 0, CveAcreedor As Integer = 0, CveIE As Integer = 0, CveColectiva As Integer = 0, CveCreditoDetalle As Integer = 0 + Dim ConceptoPersonal As String = "", Concepto As String = "" + + If Not ObjConta.GetPrePolizasDetalle(CvePrePoliza) Then + ErrorPrepoliza = True + Else + If ObjConta.DtResultados.FiltraParametros("CveConceptoContable IN (6,68,49,205,176)").Rows.Count > 0 Then + CveProveedorConcepto = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveProveedor").ToString.ToEntero + CveAcreedor = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveAcreedor").ToString.ToEntero + CveIE = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveIE").ToString.ToEntero + CveColectiva = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveColectiva").ToString.ToEntero + CveCreditoDetalle = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("CveCreditoDetalle").ToString.ToEntero + Concepto = ObjConta.DtResultados.FiltraParametros("CveConceptoContable = 6 OR CveConceptoContable = 68 OR CveConceptoContable = 49 OR CveConceptoContable = 205 OR CveConceptoContable = 176").Rows(0)("Concepto").ToString + End If + End If + + If CveProveedorConcepto <= 0 Then + CveProveedorConcepto = DdlProveedor.SelectedValue.ToEntero + End If + + 'Removemos los conceptos de la prepoliza + ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 6, CveCompra, 1) 'GASTO + ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 68, CveCompra, 1) 'ALMACEN + ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 49, CveCompra, 1) 'AF + ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 205, CveCompra, 1) 'PS YA RECIBIDO + ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 230, CveCompra, 1) 'PS YA RECIBIDO + ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 231, CveCompra, 1) 'PS YA RECIBIDO + ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 176, CveCompra, 1) 'PS NO RECIBIDO + ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 228, CveCompra, 1) 'PS NO RECIBIDO + ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 229, CveCompra, 1) 'PS NO RECIBIDO + + 'OBTIENE METODO DE CONTABILIZACIÓN AL GUARDAR + Dim ConceptoContabilizacionAlmacen = 0 + If ObjCompra.GetCompras(CveCompra, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then + ConceptoContabilizacionAlmacen = ObjCompra.DtResultados.FiltroPrimeroValor("CveConceptoContableAlmacen").ToEntero + End If + + 'AF + DT = TmpDT.FiltraParametros("ISNULL(TipoAF,0) = 2") + If DT.Rows.Count > 0 AndAlso DdlTipoComprobante.SelectedValue <> "NC" And ConceptoContabilizacionAlmacen = 0 Then + For Each Row2 As DataRow In DT.Rows + importeMovimiento = Row2("Total").ToString.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + If ObjConta.GetRetCuenta(49, Row2("CveActivoFijo").ToString.ToEntero) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijo").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijoSIG").ToString.ToEntero + End If + End If + + If importeMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Row2("CodAF").ToString, 49, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveActivoFijo:=Row2("CveActivoFijo").ToString.ToEntero, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta) Then + ErrorPrepoliza = True + End If + End If + Next + End If + + 'LIMPIA + importeMovimiento = 0 + IdCtaContable = 0 + CveCuenta = 0 + + 'COSTO ALMACEN + Dim DtAlmacenes = GlobalDTAlmacen(UsuarioActual.CveEmpresa) + If UsuarioActual.Empresa.UsaInventarios AndAlso Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And ConceptoContabilizacionAlmacen = 0 Then + DT = TmpDT.FiltraParametros("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) > 0", "", {"CveAlmacen"}) + 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN + For Each Dr As DataRow In DT.Rows + If DtAlmacenes.FiltroPrimeroValor("Modalidad", $"CveAlmacen = {Dr("CveAlmacen").ToString.ToEntero}").ToString = "Solo Existencia" Then + Dr("CveAlmacen") = 0 + End If + Dr.AcceptChanges() + Next + DT.AcceptChanges() + DT = DT.FiltraParametros("ISNULL(CveAlmacen,0) > 0") + If DT.Rows.Count > 0 AndAlso Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then + For Each Row2 As DataRow In DT.Rows + + importeMovimiento = TmpDT.SUM("Total", $"CveAlmacen = {Row2("CveAlmacen")}").ToString.ToDecimal + TmpDT.SUM("CostoIndirectoAlmacen", $"CveAlmacen = {Row2("CveAlmacen")}").ToString.ToDecimal 'Row2("Total").ToString.ToDecimal + Row2("CostoIndirectoAlmacen").ToString.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + If ObjConta.GetRetCuenta(68, GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContableSIG").ToString.ToEntero + End If + End If + If importeMovimiento <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 68, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CvePersonal:=CvePersonal, CveMovimientoAlmacen:=CveMovimientoInventario, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta) Then + ErrorPrepoliza = True + End If + End If + Next + End If + End If + + 'LIMPIA + importeMovimiento = 0 + IdCtaContable = 0 + CveCuenta = 0 + + 'INV [MERCANCIA RECIBIDA POR ADELANTADO (OC) | MERCANCIA PENDIENTE POR RECIBIR (COMPRA) ] + If UsuarioActual.Empresa.UsaInventarios And Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And ConceptoContabilizacionAlmacen.Contiene(176, 205) Then + importeMovimiento = TmpDT.SUM("Total", $"ISNULL(TipoAF,0) <> 2 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveTipoPS = 2").ToString.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + + If ObjConta.GetRetCuenta(ConceptoContabilizacionAlmacen, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + End If + End If + + If importeMovimiento <> 0 Then + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContabilizacionAlmacen, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta) Then + ErrorPrepoliza = True + End If + End If + + End If + + 'NC CON PRODUCTOS - CUENTA PUENTE + + If UsuarioActual.Empresa.UsaInventarios And Not DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And ConceptoContabilizacionAlmacen.Contiene(225) Then + importeMovimiento = TmpDT.SUM("Total", $"ISNULL(TipoAF,0) <> 2 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveTipoPS = 2").ToString.ToDecimal + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + + If ObjConta.GetRetCuenta(ConceptoContabilizacionAlmacen, UsuarioActual.CveEmpresa) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + End If + End If + + If importeMovimiento <> 0 Then + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContabilizacionAlmacen, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta) Then + ErrorPrepoliza = True + End If + End If + End If + + + 'GASTO + DT = TmpDT.Copy + 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN + For Each Dr As DataRow In DT.Rows + If DtAlmacenes.FiltroPrimeroValor("Modalidad", $"CveAlmacen = {Dr("CveAlmacen").ToString.ToEntero}").ToString = "Solo Existencia" Then + Dr("CveAlmacen") = 0 + End If + Dr.AcceptChanges() + Next + DT.AcceptChanges() + DtAlmacenes.Dispose() + + 'QUITA 1-[MERCANCIA RECIBIDA POR ADELANTADO (OC) | MERCANCIA PENDIENTE POR RECIBIR (COMPRA)] 2-[NC CON PRODUCTOS] + If UsuarioActual.CveEmpresa.Contiene(119) And UsuarioActual.Empresa.UsaInventarios And Not UsuarioActual.Empresa.Funcionalidad(126) = "1" And ConceptoContabilizacionAlmacen > 0 Then + DT = DT.FiltraParametros("CveTipoPS <> 2") + End If + + Dim DTDistinct = DT.Copy + If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + DTDistinct = DTDistinct.FiltraParametros("ISNULL(TipoAF,0) <> 2", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveProyecto", "CveSubProyecto", "CveTipoGasto", "TipoGasto"}) + Else + DTDistinct = DTDistinct.FiltraParametros("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveProyecto", "CveSubProyecto", "CveTipoGasto", "TipoGasto"}) + End If + + If DTDistinct.Rows.Count > 0 Then + For Each Row2 As DataRow In DTDistinct.Rows + + 'DETERMINA IMPORTE + If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + importeMovimiento = DT.SUM("Total", String.Format("ISNULL(TipoAF,0) <> 2 AND CveClasificacion = {0} AND CveSubProyecto = {1} AND ISNULL(CveTipoGasto,0) = {2}", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal + Else + importeMovimiento = DT.SUM("Total", String.Format("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveClasificacion = {0} AND CveSubProyecto = {1} AND ISNULL(CveTipoGasto,0) = {2}", Row2("CveClasificacion").ToString.ToEntero, Row2("CveSubProyecto").ToString.ToEntero, Row2("CveTipoGasto").ToString.ToEntero)).ToString.ToDecimal + End If + importeMN = importeMovimiento * tipoCambioActual * Multiplicador + + 'CLASIFICACION + If Row2("CveClasificacion").ToString.ToEntero > 0 Then + If ObjConta.GetRetCuenta(6, Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero) Then + If ObjConta.DtResultados.Rows.Count > 0 AndAlso ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero + Else + IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGasto", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero + CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero + End If + End If + End If + + 'SEGMENTO DE NEGOCIO + Dim IdSegmentoNegocio As Integer = -1 + Dim drT As DataRow = GlobalDTSubProyectos(-1, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero).FiltroPrimero(String.Format("CveSubProyecto = {0} ", Row2("CveSubProyecto").ToString.ToEntero)) + If drT IsNot Nothing Then + IdSegmentoNegocio = drT("IdSegNeg").ToString.ToEntero + End If + + 'AGREGA MOVIMIENTO + If importeMovimiento <> 0 Then + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 6, Concepto, FechaMovimiento, IdCtaContable, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveAcreedor:=CveAcreedor, CveIE:=CveIE, CveColectiva:=CveColectiva, CveCreditoDetalle:=CveCreditoDetalle, CveClasificacion:=Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, CveTipoGasto:=Row2("CveTipoGasto").ToString.ToEntero) Then + ErrorPrepoliza = True + End If + End If + + Next + End If + + 'LIMPIA + importeMovimiento = 0 + IdCtaContable = 0 + CveCuenta = 0 + + End Select + + Next + End If + + If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, 4) Then + If ObjConta.ValorPolizaDescuadre > 0 Then + ErrorPrepoliza = True + GuardaLogAD($"Compras/Compras-Actualizar | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") + End If + End If + + If Not ErrorPrepoliza Then + Retorno = True + Else + Retorno = False + End If + + Return Retorno + End Function + + Protected Sub ImgActualizarProyecto_Click(sender As Object, e As EventArgs) Handles ImgActualizarProyecto.Click + 'actualizo los proyectos + Dim Compra As New ClsCompras + Dim Retorno As Boolean = True + Compra.IniciaTransacSQL() + + For Each Row As DataRow In TmpDT.Rows + + If Not Compra.UpdateCompraDetalle(Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDouble, Row("PU").ToString.ToDouble, Row("IVA").ToString.ToDouble, Row("Total").ToString.ToDouble, + Row("Descuento").ToString.ToDouble, Row("Observaciones").ToString, Row("CveSubProyecto").ToString.ToEntero, Row("CvePresupuestoEgreso").ToString.ToEntero, -2, Row("CveCompraDetalle").ToString.ToEntero, CveTipoGasto:=Row("CveTipoGasto").ToString.ToEntero) Then + + Retorno = False + Exit For + End If + Next + + If Retorno Then + Compra.Commit() + Alert("La Compra se actualizó correctamente.") + Else + Compra.RollBack() + End If + + + Compra.Dispose() + + + End Sub + + Protected Sub BtnVerAmortizacion_Click(sender As Object, e As EventArgs) Handles BtnVerAmortizacion.Click + BtnVerAmortizacion.Visible = False + 'BtnAmortizar.Visible = True + 'activo el cuadro para amortizar + + RBLPago.SelectedValue = "2" ' selecciono contado + PnlContado.Visible = True + PnlContadoBancos.Visible = False + RBLContado.Items.Clear() + RBLContado.Items.Add(New ListItem("Deudores", "4")) + + RBLContado.SelectedValue = "4" 'selecciono deudores + PnlContadoDeudores.Visible = True + CargaDeudores() + End Sub + + Protected Sub ImgAjusteSobreTotal_Click(sender As Object, e As ImageClickEventArgs) Handles ImgAjustaSobreTotal.Click + 'realizo el ajuste de los productos + 'total - iva + Dim Diferencia As Decimal = TxtTotal.Text.ToDecimal() - TxtIVA.Text.ToDecimal + TxtRetIVA.Text.ToDecimal + TxtRetISR.Text.ToDecimal - (TxtSubTotal2.Text.ToDecimal) + + AjustaImporteUltimoConcepto(Diferencia) + BtnGuardar.Enabled = True + UpFacturar.Update() + + End Sub +#End Region + +#Region "CargaXML" + + Private Function ValorXML(n As XmlNode, Campo As String, Optional Retorno As String = "") As String + Dim o As XmlNode = n.Attributes.Cast(Of XmlAttribute)().SingleOrDefault(Function(a) String.Compare(a.Name, Campo, True) = 0) + If o Is Nothing Then + Return Retorno + Else + Return o.Value + End If + End Function + + Private Sub CargaComprobanteXML(XMLDoc As XmlDocument) + Dim nodo As XmlNode = XMLDoc.DocumentElement + + _Serie = ValorXML(nodo, "serie") + If _Serie <> "" Then _Serie = _Serie + + Version = ValorXML(nodo, "version") + _Folio = ValorXML(nodo, "folio") + _Fecha = ValorXML(nodo, "fecha") + SubTotal = ValorXML(nodo, "subTotal").ToDecimal + Total = ValorXML(nodo, "total").ToDecimal + Descuentos = ValorXML(nodo, "descuento").ToDecimal + _Moneda = ValorXML(nodo, "Moneda") + _TipoComprobante = ValorXML(nodo, "tipoDeComprobante") + TipoCambio = ValorXML(nodo, "TipoCambio", "1").ToDouble + + If Version = "3.3" Then + Dim drm As DataRow = GlobalDTVtaMetodoPago.FiltroPrimero(String.Format("ClaveMetodoPagoSAT = '{0}'", ValorXML(nodo, "MetodoPago"))) + If drm IsNot Nothing Then + CveMetodoPago = drm("CveMetodoPago").ToString.ToEntero + MetodoPago = drm("MetodoPagoSAT").ToString + End If + End If + + + Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix) + Dim cfdVer As String = "http://www.sat.gob.mx/cfd/3" + Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable) + + If Prefijo.ToLower <> "cfdi" Then cfdVer = "http://www.sat.gob.mx/cfd/2" + namespaces.AddNamespace(Prefijo, cfdVer) + namespaces.AddNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital") + namespaces.AddNamespace("implocal", "http://www.sat.gob.mx/implocal") + namespaces.AddNamespace("registrofiscal", "http://www.sat.gob.mx/registrofiscal") + + Dim node As XmlNode + node = XMLDoc.SelectSingleNode(String.Format("//{0}:Emisor", Prefijo), namespaces) + + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + EmisorRFC = ValorXML(node, "RFC") + 'EmisorNombre = ValorXML(node, "nombre") + End If + + node = XMLDoc.SelectSingleNode(String.Format("//{0}:CfdiRelacionados", Prefijo), namespaces) node = XMLDoc.SelectSingleNode(String.Format("//{0}:Receptor", Prefijo), namespaces) - If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then - ReceptorRFC = ValorXML(node, "RFC") - End If - - If UsuarioActual.CveEmpresa.Contiene(119, 7) Then - node = XMLDoc.SelectSingleNode(String.Format("//{0}:CfdiRelacionados", Prefijo), namespaces) - If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then - If ValorXML(node, "TipoRelacion").ToString.Contiene("04", "07") Then - Dim nodeDocumentosRelacionados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:CfdiRelacionado", Prefijo), namespaces) - For Each documento As XmlNode In nodeDocumentosRelacionados - If documento.Attributes("UUID").Value <> "" Then - ListaDocumentos.Add(documento.Attributes("UUID").Value) - End If + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + ReceptorRFC = ValorXML(node, "RFC") + End If + + If UsuarioActual.CveEmpresa.Contiene(119, 7) Then + node = XMLDoc.SelectSingleNode(String.Format("//{0}:CfdiRelacionados", Prefijo), namespaces) + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + If ValorXML(node, "TipoRelacion").ToString.Contiene("04", "07") Then + Dim nodeDocumentosRelacionados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:CfdiRelacionado", Prefijo), namespaces) + For Each documento As XmlNode In nodeDocumentosRelacionados + If documento.Attributes("UUID").Value <> "" Then + ListaDocumentos.Add(documento.Attributes("UUID").Value) + End If TieneAnticiposXML = True - Next - End If - End If - End If - - - node = XMLDoc.SelectSingleNode(String.Format("//{0}:Impuestos", Prefijo), namespaces) - If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then - Dim nodeRetenciones As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Comprobante/{0}:Impuestos/{0}:Retenciones/{0}:Retencion", Prefijo), namespaces) - - TotalRetenciones = ValorXML(node, "totalImpuestosRetenidos", "0").ToDecimal - - If Version = "3.3" Then - - For Each retencion As XmlNode In nodeRetenciones - If retencion.Attributes("Impuesto").Value = "002" Then - RetencionIVA += retencion.Attributes("Importe").Value.ToDecimal - End If - If retencion.Attributes("Impuesto").Value = "001" Then - RetencionISR += retencion.Attributes("Importe").Value.ToDecimal - End If - ' Do something. - Next - GvOC1.Columns(6).Visible = True - GvOC2.Columns(4).Visible = True - Else - - For Each retencion As XmlNode In nodeRetenciones - If retencion.Attributes("impuesto").Value = "IVA" Then - RetencionIVA += retencion.Attributes("importe").Value.ToDecimal - End If - If retencion.Attributes("impuesto").Value = "ISR" Then - RetencionISR += retencion.Attributes("importe").Value.ToDecimal - End If - ' Do something. - Next - End If - SumaTotalRetenciones += RetencionIVA - SumaTotalRetenciones += RetencionISR - - TotalTraslados = ValorXML(node, "totalImpuestosTrasladados", "0").ToDecimal - Dim nodeTraslados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Comprobante/{0}:Impuestos/{0}:Traslados/{0}:Traslado", Prefijo), namespaces) - - If Version = "3.3" Then - - For Each traslado As XmlNode In nodeTraslados - If traslado.Attributes("Impuesto").Value = "002" Then - TrasladoIVA += traslado.Attributes("Importe").Value.ToDecimal - End If - If traslado.Attributes("Impuesto").Value = "003" Then - TrasladoIEPS += traslado.Attributes("Importe").Value.ToDecimal - End If - If traslado.Attributes("Impuesto").Value = "001" Then - 'TrasladoISR = traslado.Attributes("importe").Value - End If - ' Do something. - Next - - Else - - For Each traslado As XmlNode In nodeTraslados - If traslado.Attributes("impuesto").Value = "IVA" Then - TrasladoIVA += traslado.Attributes("importe").Value.ToDecimal - End If - If traslado.Attributes("impuesto").Value = "IEPS" Then - TrasladoIEPS += traslado.Attributes("importe").Value.ToDecimal - End If - 'If traslado.Attributes("impuesto").Value = "ISR" Then - ' TrasladoISR = traslado.Attributes("importe").Value - 'End If - ' Do something. - Next - End If - - SumaTotalTraslados += TrasladoIVA - SumaTotalTraslados += TrasladoIEPS - End If - - Dim nodeComp As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Complemento", Prefijo), namespaces) - If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then - - Dim nodeTFD As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:TimbreFiscalDigital", "tfd"), namespaces) - - _TFDUUID = ValorXML(nodeTFD, "UUID", "") - - Dim nodeRF As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:CFDIRegistroFiscal ", "registrofiscal"), namespaces) - If nodeRF IsNot Nothing Then - _Folio = ValorXML(nodeRF, "folio").TrimStart("0"c) - End If - - node = node.SelectSingleNode(String.Format("//{0}:ImpuestosLocales", "implocal"), namespaces) - - - If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then - OtrosImpuestos = ValorXML(node, "TotaldeTraslados", "0").ToDecimal - OtrosImpuestosRetenciones = ValorXML(node, "TotaldeRetenciones", "0").ToDecimal - - 'If RetencionIVA <= 0 AndAlso ValorXML(node, "TotaldeRetenciones", "0").ToDouble > 0 Then RetencionIVA = ValorXML(node, "TotaldeRetenciones", "0").ToDecimal - - 'For Each retencion As XmlNode In nodeImpLocales - ' If retencion.Attributes("impuesto").Value = "IVA" Then - ' RetencionIVA += retencion.Attributes("importe").Value.ToDouble - ' End If - ' If retencion.Attributes("impuesto").Value = "ISR" Then - ' RetencionISR += retencion.Attributes("importe").Value.ToDouble - ' End If - ' ' Do something. - 'Next - ' SumaTotalRetenciones += RetencionIVA - ' SumaTotalRetenciones += RetencionISR - - 'TotalTraslados = ValorXML(node, "totalImpuestosTrasladados", "0").ToDouble - - 'Dim nodeTraslados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Traslado", Prefijo), namespaces) - 'For Each traslado As XmlNode In nodeTraslados - ' If traslado.Attributes("impuesto").Value = "IVA" Then - ' TrasladoIVA += traslado.Attributes("importe").Value.ToDouble - ' End If - ' If traslado.Attributes("impuesto").Value = "IEPS" Then - ' TrasladoIEPS += traslado.Attributes("importe").Value.ToDouble - ' End If - ' 'If traslado.Attributes("impuesto").Value = "ISR" Then - ' ' TrasladoISR = traslado.Attributes("importe").Value - ' 'End If - ' ' Do something. - 'Next - 'SumaTotalTraslados += TrasladoIVA - 'SumaTotalTraslados += TrasladoIEPS - End If - - End If - - 'Try - ' _TFDUUID = XMLDoc.SelectSingleNode(String.Format("//{0}:Complemento", Prefijo), namespaces).LastChild.Attributes("UUID").InnerText - 'Catch ex As Exception - ' _TFDUUID = "" - 'End Try - - + Next + End If + End If + End If + + + node = XMLDoc.SelectSingleNode(String.Format("//{0}:Impuestos", Prefijo), namespaces) + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + Dim nodeRetenciones As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Comprobante/{0}:Impuestos/{0}:Retenciones/{0}:Retencion", Prefijo), namespaces) + + TotalRetenciones = ValorXML(node, "totalImpuestosRetenidos", "0").ToDecimal + + If Version = "3.3" Then + + For Each retencion As XmlNode In nodeRetenciones + If retencion.Attributes("Impuesto").Value = "002" Then + RetencionIVA += retencion.Attributes("Importe").Value.ToDecimal + End If + If retencion.Attributes("Impuesto").Value = "001" Then + RetencionISR += retencion.Attributes("Importe").Value.ToDecimal + End If + ' Do something. + Next + GvOC1.Columns(6).Visible = True + GvOC2.Columns(4).Visible = True + Else + + For Each retencion As XmlNode In nodeRetenciones + If retencion.Attributes("impuesto").Value = "IVA" Then + RetencionIVA += retencion.Attributes("importe").Value.ToDecimal + End If + If retencion.Attributes("impuesto").Value = "ISR" Then + RetencionISR += retencion.Attributes("importe").Value.ToDecimal + End If + ' Do something. + Next + End If + SumaTotalRetenciones += RetencionIVA + SumaTotalRetenciones += RetencionISR + + TotalTraslados = ValorXML(node, "totalImpuestosTrasladados", "0").ToDecimal + Dim nodeTraslados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Comprobante/{0}:Impuestos/{0}:Traslados/{0}:Traslado", Prefijo), namespaces) + + If Version = "3.3" Then + + For Each traslado As XmlNode In nodeTraslados + If traslado.Attributes("Impuesto").Value = "002" Then + TrasladoIVA += traslado.Attributes("Importe").Value.ToDecimal + End If + If traslado.Attributes("Impuesto").Value = "003" Then + TrasladoIEPS += traslado.Attributes("Importe").Value.ToDecimal + End If + If traslado.Attributes("Impuesto").Value = "001" Then + 'TrasladoISR = traslado.Attributes("importe").Value + End If + ' Do something. + Next + + Else + + For Each traslado As XmlNode In nodeTraslados + If traslado.Attributes("impuesto").Value = "IVA" Then + TrasladoIVA += traslado.Attributes("importe").Value.ToDecimal + End If + If traslado.Attributes("impuesto").Value = "IEPS" Then + TrasladoIEPS += traslado.Attributes("importe").Value.ToDecimal + End If + 'If traslado.Attributes("impuesto").Value = "ISR" Then + ' TrasladoISR = traslado.Attributes("importe").Value + 'End If + ' Do something. + Next + End If + + SumaTotalTraslados += TrasladoIVA + SumaTotalTraslados += TrasladoIEPS + End If + + Dim nodeComp As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Complemento", Prefijo), namespaces) + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + + Dim nodeTFD As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:TimbreFiscalDigital", "tfd"), namespaces) + + _TFDUUID = ValorXML(nodeTFD, "UUID", "") + + Dim nodeRF As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:CFDIRegistroFiscal ", "registrofiscal"), namespaces) + If nodeRF IsNot Nothing Then + _Folio = ValorXML(nodeRF, "folio").TrimStart("0"c) + End If + + node = node.SelectSingleNode(String.Format("//{0}:ImpuestosLocales", "implocal"), namespaces) + + + If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then + OtrosImpuestos = ValorXML(node, "TotaldeTraslados", "0").ToDecimal + OtrosImpuestosRetenciones = ValorXML(node, "TotaldeRetenciones", "0").ToDecimal + + 'If RetencionIVA <= 0 AndAlso ValorXML(node, "TotaldeRetenciones", "0").ToDouble > 0 Then RetencionIVA = ValorXML(node, "TotaldeRetenciones", "0").ToDecimal + + 'For Each retencion As XmlNode In nodeImpLocales + ' If retencion.Attributes("impuesto").Value = "IVA" Then + ' RetencionIVA += retencion.Attributes("importe").Value.ToDouble + ' End If + ' If retencion.Attributes("impuesto").Value = "ISR" Then + ' RetencionISR += retencion.Attributes("importe").Value.ToDouble + ' End If + ' ' Do something. + 'Next + ' SumaTotalRetenciones += RetencionIVA + ' SumaTotalRetenciones += RetencionISR + + 'TotalTraslados = ValorXML(node, "totalImpuestosTrasladados", "0").ToDouble + + 'Dim nodeTraslados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Traslado", Prefijo), namespaces) + 'For Each traslado As XmlNode In nodeTraslados + ' If traslado.Attributes("impuesto").Value = "IVA" Then + ' TrasladoIVA += traslado.Attributes("importe").Value.ToDouble + ' End If + ' If traslado.Attributes("impuesto").Value = "IEPS" Then + ' TrasladoIEPS += traslado.Attributes("importe").Value.ToDouble + ' End If + ' 'If traslado.Attributes("impuesto").Value = "ISR" Then + ' ' TrasladoISR = traslado.Attributes("importe").Value + ' 'End If + ' ' Do something. + 'Next + 'SumaTotalTraslados += TrasladoIVA + 'SumaTotalTraslados += TrasladoIEPS + End If + + End If + + 'Try + ' _TFDUUID = XMLDoc.SelectSingleNode(String.Format("//{0}:Complemento", Prefijo), namespaces).LastChild.Attributes("UUID").InnerText + 'Catch ex As Exception + ' _TFDUUID = "" + 'End Try + + End Sub -#End Region +#End Region -#Region "GV'S" - Protected Sub GVAnticipos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVAnticipos.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - If e.Row.DBCampo("SerieFolio") = "" Then - e.Row.Cells(0).Text = "" - e.Row.Cells(5).Text = "" - e.Row.Cells(0).Width = Unit.Pixel(150) - e.Row.CssClass = "Totales TextCenter" - Select Case e.Row.DBCampo("TipoDocto") - Case "Egsc" - e.Row.Cells(0).Text = "Egreso Por Comprobar" - Case "Ant" - e.Row.Cells(0).Text = "Anticipos" - Case "NC" - e.Row.Cells(0).Text = "Notas de crédito" - Case "DEV" - e.Row.Cells(0).Text = "Devolución" - End Select - - ElseIf e.Row.DBCampo("CveProveedor") = "" Then - e.Row.Cells(0).Text = "" - e.Row.Cells(5).Text = "" - e.Row.BackColor = Drawing.Color.LightGray - Else - If e.Row.DBCampo("Saldo").ToDouble < 0 Then e.Row.Cells(3).ForeColor = Drawing.Color.Red +#Region "GV'S" + Protected Sub GVAnticipos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVAnticipos.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + If e.Row.DBCampo("SerieFolio") = "" Then + e.Row.Cells(0).Text = "" + e.Row.Cells(5).Text = "" + e.Row.Cells(0).Width = Unit.Pixel(150) + e.Row.CssClass = "Totales TextCenter" + Select Case e.Row.DBCampo("TipoDocto") + Case "Egsc" + e.Row.Cells(0).Text = "Egreso Por Comprobar" + Case "Ant" + e.Row.Cells(0).Text = "Anticipos" + Case "NC" + e.Row.Cells(0).Text = "Notas de crédito" + Case "DEV" + e.Row.Cells(0).Text = "Devolución" + End Select + + ElseIf e.Row.DBCampo("CveProveedor") = "" Then + e.Row.Cells(0).Text = "" + e.Row.Cells(5).Text = "" + e.Row.BackColor = Drawing.Color.LightGray + Else + If e.Row.DBCampo("Saldo").ToDouble < 0 Then e.Row.Cells(3).ForeColor = Drawing.Color.Red If e.Row.DBCampo("Saldo").ToDouble = 0 Then e.Row.FCLiteral("LtlAnticipos").Text = "" - Dim ImporteAmortizacion As Decimal = If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0, TmpDT.SUMD("ImporteConImpuestos"), TxtTotal.Text.ToDecimal) - - e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("chkAnt(this,{0},{1},{2});", e.Row.FCTextBox("TxtAnticipo").ClientID, e.Row.DBCampo("Saldo"), If(CveCompra > 0, Saldo, ImporteAmortizacion), e.Row.DBCampo("CveMoneda").ToEntero, If(Not e.Row.DBCampo("TCCompra").ToDouble > 1, GlobalTipoCambio(e.Row.DBCampo("Fecha").ToDate), e.Row.DBCampo("TCCompra").ToDouble), DdlMoneda.SelectedValue.ToEntero)) 'SI ES UNA COMPRA NUEVA SE PONE EL TOTAL, SI NO EL SALDO - e.Row.FCTextBox("TxtAnticipo").Attributes.Add("onKeyUp", String.Format("FnCambiaAnt({0},this,{1},{2});", e.Row.FCCheckBox("Chk").ClientID, e.Row.DBCampo("Saldo"), If(CveCompra > 0, Saldo, ImporteAmortizacion), e.Row.DBCampo("CveMoneda").ToEntero, If(Not e.Row.DBCampo("TCCompra").ToDouble > 1, GlobalTipoCambio(e.Row.DBCampo("Fecha").ToDate), e.Row.DBCampo("TCCompra").ToDouble), DdlMoneda.SelectedValue.ToEntero)) 'SI ES UNA COMPRA NUEVA SE PONE EL TOTAL, SI NO EL SALDO - - If ChkNCInv.Checked Then - e.Row.FCCheckBox("Chk").CssClass = "ChkAntNC" - End If - - If ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 Then - Dim Entro As Boolean = False - For Each Documento In ListaDocumentos - If e.Row.DBCampo("UUID").ToString = Documento Then - Entro = True - End If - Next - 'permite vincular otro folio fiscal. - Entro = True - If Not Entro Then e.Row.FCCheckBox("Chk").Enabled = False - End If - End If - End If - End Sub - Protected Sub GvPS_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GvPS.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - If Not (e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5) Then - - If e.Row.RowIndex = 0 Then - 'e.Row.Cells(0).Width = Unit.Pixel(15) - 'e.Row.Cells(1).Width = Unit.Pixel(45) - 'e.Row.Cells(2).Width = Unit.Pixel(70) - 'e.Row.Cells(3).Width = Unit.Pixel(230) - 'e.Row.Cells(4).Width = Unit.Pixel(202) - 'e.Row.Cells(5).Width = Unit.Pixel(155) - 'e.Row.Cells(6).Width = Unit.Pixel(155) - 'e.Row.Cells(7).Width = Unit.Pixel(50) - 'e.Row.Cells(8).Width = Unit.Pixel(80) - 'e.Row.Cells(9).Width = Unit.Pixel(80) - 'e.Row.Cells(10).Width = Unit.Pixel(43) - 'e.Row.Cells(11).Width = Unit.Pixel(43) - - If UsuarioActual.Empresa.UsaAC Then 'AndAlso (CveFactura > 0 Or CveCompra > 0) - e.Row.Cells(12).Width = Unit.Pixel(150) - e.Row.Cells(13).Width = Unit.Pixel(150) - e.Row.Cells(14).Width = Unit.Pixel(150) - e.Row.Cells(15).Width = Unit.Pixel(150) - e.Row.Cells(16).Width = Unit.Pixel(100) - End If - End If - - 'Permite la Regeneracion de las prepolizas - If e.Row.DBCampo("CveClasificacion") <> "" AndAlso e.Row.DBCampo("CveClasificacion").ToEntero > 0 Then - TmpDT.Rows(e.Row.RowIndex)("CveClasificacionActualizar") = e.Row.DBCampo("CveClasificacion") - End If - - If CveCompra > 0 AndAlso UsuarioActual.TienePermisoProceso(104) AndAlso e.Row.FCCheckBox("CheckClasificacion") IsNot Nothing Then - e.Row.FCCheckBox("CheckClasificacion").Visible = True - End If - - If UsuarioActual.TienePermisoProceso(117) Then - e.Row.FCLinkButton("imgE").Visible = False - End If - - 'El Eliminar solo debera aparecer cuando se registre manual la compra, cuando viene de una factura se desactiva, o cuando esta registrada la compra - If CveFactura = 0 Then 'CveCompra <= 0 And - e.Row.FCLinkButton("imgD").Visible = True - 'If e.Row.FCImageButton("imgE") IsNot Nothing Then e.Row.FCImageButton("imgE").Visible = True - If e.Row.FCTextBox("TxtCantidadEdit") IsNot Nothing Then e.Row.FCTextBox("TxtCantidadEdit").Enabled = True - If e.Row.FCTextBox("TxtPrecioEdit") IsNot Nothing Then e.Row.FCTextBox("TxtPrecioEdit").Enabled = True - End If - - 'Dejar un PS para ver que hace esto y documentar. - If e.Row.DBCampo("CvePS") = "0" Then - e.Row.Cells(0).ToolTip = "Producto/Servicio NO Registrado" - e.Row.Cells(0).ID = String.Format("tr{0}", e.Row.RowIndex) - e.Row.Cells(0).ClientIDMode = ClientIDMode.Static - e.Row.Cells(0).Attributes.Add("onclick", String.Format("fnAltaPS('{0}','{1}',{2})", String.Format("tr{0}", e.Row.RowIndex), e.Row.DBCampo("PS").Replace("'", "").Replace(Chr(13), "").Replace(Chr(10), ""), e.Row.RowIndex)) - If e.Row.FCTextBox("TxtPrecioEdit") IsNot Nothing Then e.Row.FCTextBox("TxtPrecioEdit").Enabled = False - If e.Row.FCTextBox("TxtCantidadEdit") IsNot Nothing Then e.Row.FCTextBox("TxtCantidadEdit").Enabled = False - End If - - 'VALIDA UNIDAD DE MEDIDA - If e.Row.DBCampo("CvePS").ToString.ToEntero > 0 Then - Dim DtEquivalencias = GlobalDTProductosServiciosEquivalencias(e.Row.DBCampo("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) - - 'SI UM NO ESTA REGISTRADA - If e.Row.DBCampo("CveUM").ToString.ToEntero <= 0 Then - e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("onclick", $"FncUMEquivalencias(1,'{e.Row.DBCampo("UM").Replace("'", "")}',{e.Row.RowIndex},'{DtEquivalencias.FiltroPrimeroValor("UnidadMedida", "UnidadBase = 1")}','{e.Row.DBCampo("CveSATUnidadMedida")}','{e.Row.DBCampo("SATClaveUnidadMedida")}')") - e.Row.FCLabel("LtlUnidadMedida").CssClass = "label label-danger manita centrarUM" - e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("data-toggle", "tooltip") - e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("title", "Unidad de medida SIN registrar") - End If - - 'EQUIVALENCIA - If e.Row.DBCampo("CveUM").ToString.ToEntero > 0 And e.Row.DBCampo("CveTipoPS").ToString.ToEntero = 2 Then - If DtEquivalencias.FiltraParametros($"CveUM = {e.Row.DBCampo("CveUM").ToString.ToEntero}").Rows.Count > 0 Then - If Not DtEquivalencias.FiltraParametros($"CveUM = {e.Row.DBCampo("CveUM").ToString.ToEntero} AND UnidadBase = 1").Rows.Count > 0 Then - 'UM NO BASE - e.Row.FCLinkButton("LBAplicarEquivalencia").Visible = True - - 'e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("onclick", $"FncUMEquivalencias(2,'{e.Row.DBCampo("UM").Replace("'", "")}',{e.Row.RowIndex},'{DtEquivalencias.FiltroPrimeroValor("UnidadMedida", "UnidadBase = 1")}')") - e.Row.FCLabel("LtlUnidadMedida").CssClass = "label label-danger centrarUM" - e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("data-toggle", "tooltip") - e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("title", "Unidad de medida NO medida base") - End If - Else - 'SIN EQUIVALENCIA - e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("onclick", $"FncUMEquivalencias(3,'{e.Row.DBCampo("UM").Replace("'", "")}',{e.Row.RowIndex},'{DtEquivalencias.FiltroPrimeroValor("UnidadMedida", "UnidadBase = 1")}','{e.Row.DBCampo("CveSATUnidadMedida")}','{e.Row.DBCampo("SATClaveUnidadMedida")}')") - e.Row.FCLabel("LtlUnidadMedida").CssClass = "label label-danger manita centrarUM" - e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("data-toggle", "tooltip") - e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("title", "Unidad de medida SIN equivalencia") - End If - End If - End If - - - If PermisoEdicionManual Then - If e.Row.FCTextBox("TxtPrecioEdit") IsNot Nothing Then e.Row.FCTextBox("TxtPrecioEdit").Enabled = True - End If - - 'Esconde Editar y Eliminar cuando tiene una OC Vinculada - If OCVinculada Then - e.Row.FCLinkButton("ImgE").Visible = False - e.Row.FCLinkButton("ImgD").Visible = False - End If - - If e.Row.DBCampo("CvePS").ToEntero > 0 AndAlso e.Row.DBCampo("IEPSPSPorcentaje").ToDouble > 0 Then - If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=e.Row.DBCampo("CvePS").ToEntero).Rows.Count > 0 Then - Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=e.Row.DBCampo("CvePS").ToEntero).Rows(0) - If DrPS IsNot Nothing Then - If DrPS("IEPSPorcentaje").ToString.ToDouble <> e.Row.DBCampo("IEPSPSPorcentaje").ToDouble Then - e.Row.CssClass = "danger" - e.Row.ToolTip = "El porcentaje de IEPS del producto no coincide con el especificado." - End If - End If - End If - End If - - 'CargaPresupuestosEgresos - If UsuarioActual.Empresa.UsaAC Then - e.Row.Cells(13).Visible = True - e.Row.Cells(14).Visible = True - e.Row.Cells(15).Visible = True - e.Row.Cells(16).Visible = True - e.Row.Cells(17).Visible = True - - e.Row.FCDropDownList("DdlAC1").Items.Clear() - e.Row.FCDropDownList("DdlAC1").DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveProgramaOperativo", "ProgramaOperativo"}) - e.Row.FCDropDownList("DdlAC1").DataBind() - e.Row.FCDropDownList("DdlAC1").SelectedValueExist(e.Row.DBCampo("CveProgramaOperativo")) - - e.Row.FCDropDownList("DdlAC2").Items.Clear() - e.Row.FCDropDownList("DdlAC2").DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveUnidadAdministrativa", "UnidadAdministrativa"}, Orderby:="UnidadAdministrativa") - e.Row.FCDropDownList("DdlAC2").DataBind() - e.Row.FCDropDownList("DdlAC2").SelectedValueExist(e.Row.DBCampo("CveUnidadAdministrativa")) - - e.Row.FCDropDownList("DdlAC3").Items.Clear() - e.Row.FCDropDownList("DdlAC3").DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveFuenteFinanciamiento", "FuenteFinanciamiento"}, Orderby:="FuenteFinanciamiento") - e.Row.FCDropDownList("DdlAC3").DataBind() - e.Row.FCDropDownList("DdlAC3").SelectedValueExist(e.Row.DBCampo("CveFuenteFinanciamiento")) - - e.Row.FCDropDownList("DdlAC4").Items.Clear() - e.Row.FCDropDownList("DdlAC4").DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveTipoGasto", "TipoGasto"}) - e.Row.FCDropDownList("DdlAC4").DataBind() - e.Row.FCDropDownList("DdlAC4").SelectedValueExist(e.Row.DBCampo("CveTipoGasto")) - - e.Row.FCDropDownList("DdlAC5").Items.Clear() - e.Row.FCDropDownList("DdlAC5").Visible = True - e.Row.FCDropDownList("DdlAC5").DataSource = DtPresupuestos.FiltraParametros("NOT CodigoCOG like '1%'", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros("Afectable = 1 ") 'DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") - e.Row.FCDropDownList("DdlAC5").DataBind() - e.Row.FCDropDownList("DdlAC5").SelectedValueExist(e.Row.DBCampo("CveClasificacionOG")) - - 'SI EL PRESUPUESTO DE EGRESOS VIENE DESDE LA OC, SE BLOQUEA PE - If e.Row.DBCampo("CveOrdenCompraDetalle").ToEntero > 0 AndAlso e.Row.DBCampo("CvePresupuestoEgreso").ToEntero > 0 Then - - e.Row.Cells(13).Enabled = False - e.Row.Cells(14).Enabled = False - e.Row.Cells(15).Enabled = False - e.Row.Cells(16).Enabled = False - e.Row.Cells(17).Enabled = False - End If - Else - - e.Row.Cells(13).Visible = False - e.Row.Cells(14).Visible = False - e.Row.Cells(15).Visible = False - e.Row.Cells(16).Visible = False - e.Row.Cells(17).Visible = False - End If - - End If - - End If - End Sub - Protected Sub GvPS_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvPS.RowDeleting - Dim DbRow As DataRow = Nothing - DbRow = TmpDT.Rows(e.RowIndex) - 'Dim TipoDescuento As Integer = -1 - Dim Cantidad, PU, IVA, Descuento As Double - - Cantidad = DbRow("Cantidad").ToString.ToDouble - PU = DbRow("PU").ToString.ToDouble - IVA = DbRow("IVA").ToString.ToDouble - 'IVA = Math.Round((((TxtSubTotal.Text.ToDouble - (Cantidad * PU - Descuento)) * TxtIVA.Text.ToDouble) / TxtSubTotal.Text.ToDouble), 2) - Descuento = DbRow("Descuento").ToString.ToDouble - - If CveCompra > 0 Then - ClavesBorradas.Add(DbRow("CveCompraDetalle").ToString.ToEntero) - End If - TmpDT.Rows.RemoveAt(e.RowIndex) - GvPS.DataSource = TmpDT - GvPS.DataBind() - - 'GVAF.DataSource = TmpDT - 'GVAF.DataBind() - ''UpnAF.Update() - - CalculaTotales(True) - CargaGvInv() - CargaGVsAF() - CargaGvPersonal() - Alert("El Concepto ha sido eliminado correctamente", TipoMensaje.MsgInformacion) - End Sub - Private Sub GvDeudores_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDeudores.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - Dim total As Double = TxtTotal.Text.ToString.ToDouble - Dim saldo As Double = e.Row.DataKey("Saldo").ToDouble - - e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("ClickDeudorChk(this, ""{0}"", ""{1}"", ""{2}"")", e.Row.FCTextBox("TxtSaldoDeudor").ClientID, total, saldo)) - e.Row.FCTextBox("TxtSaldoDeudor").Attributes.Add("onKeyUp", String.Format("AjustaTextboxDeudores(this);")) - - Dim rv As RangeValidator = CType(e.Row.FindControl("RVSaldoDeudor"), RangeValidator) - - If saldo > total Then - rv.MaximumValue = total.ToString - Else - rv.MaximumValue = saldo.ToString - End If - - End If - - End Sub -#End Region + Dim ImporteAmortizacion As Decimal = If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0, TmpDT.SUMD("ImporteConImpuestos"), TxtTotal.Text.ToDecimal) -#Region "METODOS" - Private Sub GeneraGlobalDT(data As Object) - GlobalDTPSSimplificado(UsuarioActual.CveEmpresa) = Nothing + e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("chkAnt(this,{0},{1},{2});", e.Row.FCTextBox("TxtAnticipo").ClientID, e.Row.DBCampo("Saldo"), If(CveCompra > 0, Saldo, ImporteAmortizacion), e.Row.DBCampo("CveMoneda").ToEntero, If(Not e.Row.DBCampo("TCCompra").ToDouble > 1, GlobalTipoCambio(e.Row.DBCampo("Fecha").ToDate), e.Row.DBCampo("TCCompra").ToDouble), DdlMoneda.SelectedValue.ToEntero)) 'SI ES UNA COMPRA NUEVA SE PONE EL TOTAL, SI NO EL SALDO + e.Row.FCTextBox("TxtAnticipo").Attributes.Add("onKeyUp", String.Format("FnCambiaAnt({0},this,{1},{2});", e.Row.FCCheckBox("Chk").ClientID, e.Row.DBCampo("Saldo"), If(CveCompra > 0, Saldo, ImporteAmortizacion), e.Row.DBCampo("CveMoneda").ToEntero, If(Not e.Row.DBCampo("TCCompra").ToDouble > 1, GlobalTipoCambio(e.Row.DBCampo("Fecha").ToDate), e.Row.DBCampo("TCCompra").ToDouble), DdlMoneda.SelectedValue.ToEntero)) 'SI ES UNA COMPRA NUEVA SE PONE EL TOTAL, SI NO EL SALDO + + If ChkNCInv.Checked Then + e.Row.FCCheckBox("Chk").CssClass = "ChkAntNC" + End If + + If ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 Then + Dim Entro As Boolean = False + For Each Documento In ListaDocumentos + If e.Row.DBCampo("UUID").ToString = Documento Then + Entro = True + End If + Next + 'permite vincular otro folio fiscal. + Entro = True + If Not Entro Then e.Row.FCCheckBox("Chk").Enabled = False + End If + End If + End If + End Sub + Protected Sub GvPS_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GvPS.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + If Not (e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5) Then + + If e.Row.RowIndex = 0 Then + 'e.Row.Cells(0).Width = Unit.Pixel(15) + 'e.Row.Cells(1).Width = Unit.Pixel(45) + 'e.Row.Cells(2).Width = Unit.Pixel(70) + 'e.Row.Cells(3).Width = Unit.Pixel(230) + 'e.Row.Cells(4).Width = Unit.Pixel(202) + 'e.Row.Cells(5).Width = Unit.Pixel(155) + 'e.Row.Cells(6).Width = Unit.Pixel(155) + 'e.Row.Cells(7).Width = Unit.Pixel(50) + 'e.Row.Cells(8).Width = Unit.Pixel(80) + 'e.Row.Cells(9).Width = Unit.Pixel(80) + 'e.Row.Cells(10).Width = Unit.Pixel(43) + 'e.Row.Cells(11).Width = Unit.Pixel(43) + + If UsuarioActual.Empresa.UsaAC Then 'AndAlso (CveFactura > 0 Or CveCompra > 0) + e.Row.Cells(12).Width = Unit.Pixel(150) + e.Row.Cells(13).Width = Unit.Pixel(150) + e.Row.Cells(14).Width = Unit.Pixel(150) + e.Row.Cells(15).Width = Unit.Pixel(150) + e.Row.Cells(16).Width = Unit.Pixel(100) + End If + End If + + 'Permite la Regeneracion de las prepolizas + If e.Row.DBCampo("CveClasificacion") <> "" AndAlso e.Row.DBCampo("CveClasificacion").ToEntero > 0 Then + TmpDT.Rows(e.Row.RowIndex)("CveClasificacionActualizar") = e.Row.DBCampo("CveClasificacion") + End If + + If CveCompra > 0 AndAlso UsuarioActual.TienePermisoProceso(104) AndAlso e.Row.FCCheckBox("CheckClasificacion") IsNot Nothing Then + e.Row.FCCheckBox("CheckClasificacion").Visible = True + End If + + If UsuarioActual.TienePermisoProceso(117) Then + e.Row.FCLinkButton("imgE").Visible = False + End If + + 'El Eliminar solo debera aparecer cuando se registre manual la compra, cuando viene de una factura se desactiva, o cuando esta registrada la compra + If CveFactura = 0 Then 'CveCompra <= 0 And + e.Row.FCLinkButton("imgD").Visible = True + 'If e.Row.FCImageButton("imgE") IsNot Nothing Then e.Row.FCImageButton("imgE").Visible = True + If e.Row.FCTextBox("TxtCantidadEdit") IsNot Nothing Then e.Row.FCTextBox("TxtCantidadEdit").Enabled = True + If e.Row.FCTextBox("TxtPrecioEdit") IsNot Nothing Then e.Row.FCTextBox("TxtPrecioEdit").Enabled = True + End If + + 'Dejar un PS para ver que hace esto y documentar. + If e.Row.DBCampo("CvePS") = "0" Then + e.Row.Cells(0).ToolTip = "Producto/Servicio NO Registrado" + e.Row.Cells(0).ID = String.Format("tr{0}", e.Row.RowIndex) + e.Row.Cells(0).ClientIDMode = ClientIDMode.Static + e.Row.Cells(0).Attributes.Add("onclick", String.Format("fnAltaPS('{0}','{1}',{2})", String.Format("tr{0}", e.Row.RowIndex), e.Row.DBCampo("PS").Replace("'", "").Replace(Chr(13), "").Replace(Chr(10), ""), e.Row.RowIndex)) + If e.Row.FCTextBox("TxtPrecioEdit") IsNot Nothing Then e.Row.FCTextBox("TxtPrecioEdit").Enabled = False + If e.Row.FCTextBox("TxtCantidadEdit") IsNot Nothing Then e.Row.FCTextBox("TxtCantidadEdit").Enabled = False + End If + + 'VALIDA UNIDAD DE MEDIDA + If e.Row.DBCampo("CvePS").ToString.ToEntero > 0 Then + Dim DtEquivalencias = GlobalDTProductosServiciosEquivalencias(e.Row.DBCampo("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) + + 'SI UM NO ESTA REGISTRADA + If e.Row.DBCampo("CveUM").ToString.ToEntero <= 0 Then + e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("onclick", $"FncUMEquivalencias(1,'{e.Row.DBCampo("UM").Replace("'", "")}',{e.Row.RowIndex},'{DtEquivalencias.FiltroPrimeroValor("UnidadMedida", "UnidadBase = 1")}','{e.Row.DBCampo("CveSATUnidadMedida")}','{e.Row.DBCampo("SATClaveUnidadMedida")}')") + e.Row.FCLabel("LtlUnidadMedida").CssClass = "label label-danger manita centrarUM" + e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("data-toggle", "tooltip") + e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("title", "Unidad de medida SIN registrar") + End If + + 'EQUIVALENCIA + If e.Row.DBCampo("CveUM").ToString.ToEntero > 0 And e.Row.DBCampo("CveTipoPS").ToString.ToEntero = 2 Then + If DtEquivalencias.FiltraParametros($"CveUM = {e.Row.DBCampo("CveUM").ToString.ToEntero}").Rows.Count > 0 Then + If Not DtEquivalencias.FiltraParametros($"CveUM = {e.Row.DBCampo("CveUM").ToString.ToEntero} AND UnidadBase = 1").Rows.Count > 0 Then + 'UM NO BASE + e.Row.FCLinkButton("LBAplicarEquivalencia").Visible = True + + 'e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("onclick", $"FncUMEquivalencias(2,'{e.Row.DBCampo("UM").Replace("'", "")}',{e.Row.RowIndex},'{DtEquivalencias.FiltroPrimeroValor("UnidadMedida", "UnidadBase = 1")}')") + e.Row.FCLabel("LtlUnidadMedida").CssClass = "label label-danger centrarUM" + e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("data-toggle", "tooltip") + e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("title", "Unidad de medida NO medida base") + End If + Else + 'SIN EQUIVALENCIA + e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("onclick", $"FncUMEquivalencias(3,'{e.Row.DBCampo("UM").Replace("'", "")}',{e.Row.RowIndex},'{DtEquivalencias.FiltroPrimeroValor("UnidadMedida", "UnidadBase = 1")}','{e.Row.DBCampo("CveSATUnidadMedida")}','{e.Row.DBCampo("SATClaveUnidadMedida")}')") + e.Row.FCLabel("LtlUnidadMedida").CssClass = "label label-danger manita centrarUM" + e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("data-toggle", "tooltip") + e.Row.FCLabel("LtlUnidadMedida").Attributes.Add("title", "Unidad de medida SIN equivalencia") + End If + End If + End If + + + If PermisoEdicionManual Then + If e.Row.FCTextBox("TxtPrecioEdit") IsNot Nothing Then e.Row.FCTextBox("TxtPrecioEdit").Enabled = True + End If + + 'Esconde Editar y Eliminar cuando tiene una OC Vinculada + If OCVinculada Then + e.Row.FCLinkButton("ImgE").Visible = False + e.Row.FCLinkButton("ImgD").Visible = False + End If + + If e.Row.DBCampo("CvePS").ToEntero > 0 AndAlso e.Row.DBCampo("IEPSPSPorcentaje").ToDouble > 0 Then + If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=e.Row.DBCampo("CvePS").ToEntero).Rows.Count > 0 Then + Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=e.Row.DBCampo("CvePS").ToEntero).Rows(0) + If DrPS IsNot Nothing Then + If DrPS("IEPSPorcentaje").ToString.ToDouble <> e.Row.DBCampo("IEPSPSPorcentaje").ToDouble Then + e.Row.CssClass = "danger" + e.Row.ToolTip = "El porcentaje de IEPS del producto no coincide con el especificado." + End If + End If + End If + End If + + 'CargaPresupuestosEgresos + If UsuarioActual.Empresa.UsaAC Then + e.Row.Cells(13).Visible = True + e.Row.Cells(14).Visible = True + e.Row.Cells(15).Visible = True + e.Row.Cells(16).Visible = True + e.Row.Cells(17).Visible = True + + e.Row.FCDropDownList("DdlAC1").Items.Clear() + e.Row.FCDropDownList("DdlAC1").DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveProgramaOperativo", "ProgramaOperativo"}) + e.Row.FCDropDownList("DdlAC1").DataBind() + e.Row.FCDropDownList("DdlAC1").SelectedValueExist(e.Row.DBCampo("CveProgramaOperativo")) + + e.Row.FCDropDownList("DdlAC2").Items.Clear() + e.Row.FCDropDownList("DdlAC2").DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveUnidadAdministrativa", "UnidadAdministrativa"}, Orderby:="UnidadAdministrativa") + e.Row.FCDropDownList("DdlAC2").DataBind() + e.Row.FCDropDownList("DdlAC2").SelectedValueExist(e.Row.DBCampo("CveUnidadAdministrativa")) + + e.Row.FCDropDownList("DdlAC3").Items.Clear() + e.Row.FCDropDownList("DdlAC3").DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveFuenteFinanciamiento", "FuenteFinanciamiento"}, Orderby:="FuenteFinanciamiento") + e.Row.FCDropDownList("DdlAC3").DataBind() + e.Row.FCDropDownList("DdlAC3").SelectedValueExist(e.Row.DBCampo("CveFuenteFinanciamiento")) + + e.Row.FCDropDownList("DdlAC4").Items.Clear() + e.Row.FCDropDownList("DdlAC4").DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveTipoGasto", "TipoGasto"}) + e.Row.FCDropDownList("DdlAC4").DataBind() + e.Row.FCDropDownList("DdlAC4").SelectedValueExist(e.Row.DBCampo("CveTipoGasto")) + + e.Row.FCDropDownList("DdlAC5").Items.Clear() + e.Row.FCDropDownList("DdlAC5").Visible = True + e.Row.FCDropDownList("DdlAC5").DataSource = DtPresupuestos.FiltraParametros("NOT CodigoCOG like '1%'", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros("Afectable = 1 ") 'DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") + e.Row.FCDropDownList("DdlAC5").DataBind() + e.Row.FCDropDownList("DdlAC5").SelectedValueExist(e.Row.DBCampo("CveClasificacionOG")) + + 'SI EL PRESUPUESTO DE EGRESOS VIENE DESDE LA OC, SE BLOQUEA PE + If e.Row.DBCampo("CveOrdenCompraDetalle").ToEntero > 0 AndAlso e.Row.DBCampo("CvePresupuestoEgreso").ToEntero > 0 Then + + e.Row.Cells(13).Enabled = False + e.Row.Cells(14).Enabled = False + e.Row.Cells(15).Enabled = False + e.Row.Cells(16).Enabled = False + e.Row.Cells(17).Enabled = False + End If + Else + + e.Row.Cells(13).Visible = False + e.Row.Cells(14).Visible = False + e.Row.Cells(15).Visible = False + e.Row.Cells(16).Visible = False + e.Row.Cells(17).Visible = False + End If + + End If + + End If + End Sub + Protected Sub GvPS_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvPS.RowDeleting + Dim DbRow As DataRow = Nothing + DbRow = TmpDT.Rows(e.RowIndex) + 'Dim TipoDescuento As Integer = -1 + Dim Cantidad, PU, IVA, Descuento As Double + + Cantidad = DbRow("Cantidad").ToString.ToDouble + PU = DbRow("PU").ToString.ToDouble + IVA = DbRow("IVA").ToString.ToDouble + 'IVA = Math.Round((((TxtSubTotal.Text.ToDouble - (Cantidad * PU - Descuento)) * TxtIVA.Text.ToDouble) / TxtSubTotal.Text.ToDouble), 2) + Descuento = DbRow("Descuento").ToString.ToDouble + + If CveCompra > 0 Then + ClavesBorradas.Add(DbRow("CveCompraDetalle").ToString.ToEntero) + End If + TmpDT.Rows.RemoveAt(e.RowIndex) + GvPS.DataSource = TmpDT + GvPS.DataBind() + + 'GVAF.DataSource = TmpDT + 'GVAF.DataBind() + ''UpnAF.Update() + + CalculaTotales(True) + CargaGvInv() + CargaGVsAF() + CargaGvPersonal() + Alert("El Concepto ha sido eliminado correctamente", TipoMensaje.MsgInformacion) + End Sub + Private Sub GvDeudores_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDeudores.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + Dim total As Double = TxtTotal.Text.ToString.ToDouble + Dim saldo As Double = e.Row.DataKey("Saldo").ToDouble + + e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("ClickDeudorChk(this, ""{0}"", ""{1}"", ""{2}"")", e.Row.FCTextBox("TxtSaldoDeudor").ClientID, total, saldo)) + e.Row.FCTextBox("TxtSaldoDeudor").Attributes.Add("onKeyUp", String.Format("AjustaTextboxDeudores(this);")) + + Dim rv As RangeValidator = CType(e.Row.FindControl("RVSaldoDeudor"), RangeValidator) + + If saldo > total Then + rv.MaximumValue = total.ToString + Else + rv.MaximumValue = saldo.ToString + End If + + End If + + End Sub +#End Region + +#Region "METODOS" + Private Sub GeneraGlobalDT(data As Object) + GlobalDTPSSimplificado(UsuarioActual.CveEmpresa) = Nothing GlobalDTProductosServiciosEquivalencias(-1, -1, UsuarioActual.CveEmpresa) = Nothing 'Dim ObjPS As New ClsProductosServicios @@ -10590,430 +10728,430 @@ Partial Class Compras_Compras 'End If 'ObjPS.Dispose() - End Sub - Private Function notienepresupuesto() As Boolean - Dim notienerecursos = False - Dim SinRecursos As New StringBuilder - SinRecursos.AppendFormat("No se cuenta con los Recursos Suficientes en los siguientes subproyectos ") - Dim subproyectosSr As New List(Of Integer) - Dim filtro As New StringBuilder - 'me traigo los proyectos y subproyectos para traer presupuesots de la bd - Dim subproyectos As New List(Of Integer) - - For Each Row As DataRow In TmpDT.FiltraParametros("", "", {"CveSubProyecto", "SubProyecto"}).Rows - Dim RowCon As DataRow = GlobalDTContratos.FiltroPrimero(String.Format("CveSubProyecto={0}", Row("CveSubProyecto"))) - If Not IsNothing(RowCon) Then - filtro.AppendFormat(",{0}", Row("CveSubProyecto")) - subproyectos.Add(Row("CveSubProyecto").ToString.ToEntero) - End If - Next - 'me traigo los presupuestos de la base de datos - Dim dtpresupuestos As New DataTable - Dim objContratos As New ClsContratos - If objContratos.GetContratosPresupuesto(filtro.ToString) Then - dtpresupuestos = objContratos.DtResultados - End If - objContratos.Dispose() - - 'resto los importes actuales a los presupuestos obtenidos de la bd - For Each dr As DataRow In TmpDT.Rows - Dim psclasificacion As String = String.Format("CveSubFamilia='{0}' AND CveSubProyecto={1}", GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CvePS={0}", dr("CvePS").ToString.ToEntero))("CveSubFamilia").ToString, dr("CveSubProyecto").ToString) - - If dtpresupuestos.Rows.Count > 0 AndAlso dtpresupuestos.Select(psclasificacion).Count > 0 Then - Dim rowpresupuesto As DataRow = dtpresupuestos.Select(psclasificacion)(0) - rowpresupuesto("Importe") = rowpresupuesto("Importe").ToString.ToDouble - dr("Total").ToString.ToDouble() - Else - If subproyectos.Contains(dr("CveSubProyecto").ToString.ToEntero) Then - notienerecursos = True - If Not subproyectosSr.Contains(dr("CveSubProyecto").ToString.ToEntero) Then - subproyectosSr.Add(dr("CveSubProyecto").ToString.ToEntero) - SinRecursos.AppendFormat(",{0}", dr("SubProyecto").ToString) - End If - End If - End If - Next - dtpresupuestos.AcceptChanges() - ' - For Each rowpresupuesto As DataRow In dtpresupuestos.Rows - If (rowpresupuesto("Importe").ToString.ToDouble() < 0) Then - If Not subproyectosSr.Contains(rowpresupuesto("CveSubProyecto").ToString.ToEntero) Then - subproyectosSr.Add(rowpresupuesto("CveSubProyecto").ToString.ToEntero) - SinRecursos.AppendFormat(",{0}", rowpresupuesto("SubProyecto").ToString) - End If - notienerecursos = True - End If - Next - If (notienerecursos) Then - Alert(SinRecursos.ToString, TipoMensaje.MsgAdvertencia) - End If - dtpresupuestos.Dispose() - Return notienerecursos - End Function - Private Sub CreaDTConceptos() - DTConceptos = New DataTable - DTConceptos.Columns.Add("Consec", GetType(Integer)) - DTConceptos.Columns.Add("Cantidad", GetType(Double)) - DTConceptos.Columns.Add("UM", GetType(String)) - DTConceptos.Columns.Add("CveClasificacion", GetType(Integer)) - DTConceptos.Columns.Add("PS", GetType(String)) - DTConceptos.Columns.Add("PU", GetType(Double)) - DTConceptos.Columns.Add("Descuento", GetType(Double)) - DTConceptos.Columns.Add("IVA", GetType(Double)) - DTConceptos.Columns.Add("Total", GetType(Double)) - DTConceptos.Columns.Add("Amortizacion", GetType(Double)) - End Sub - 'Private Sub AddPS(Cantidad As Double, UM As String, PS As String, PU As Double, IVA As Double, Descuento As Double, Optional Total As Double = 0) - ' Dim Row As DataRow = Nothing - ' Row = DTConceptos.NewRow() - ' Row("Consec") = DTConceptos.Rows.Count + 1 - ' Row("Cantidad") = Cantidad - ' Row("UM") = UM - ' Row("CveClasificacion") = -1 - ' Row("PS") = PS - ' Row("PU") = PU - ' Row("IVA") = IVA - ' Row("Total") = If(Total > 0, Total, Cantidad * PU) - ' Row("Descuento") = Descuento - - ' DTConceptos.Rows.Add(Row) - 'End Sub - Private Sub CreaDTCompras() - - TmpDT = New DataTable - TmpDT.Columns.Add("Consec", GetType(Integer)) - TmpDT.Columns.Add("Cantidad", GetType(Decimal)) - TmpDT.Columns.Add("Codigo", GetType(String)) - TmpDT.Columns.Add("CveUM", GetType(Integer)) - TmpDT.Columns.Add("UM", GetType(String)) - TmpDT.Columns.Add("CveClasificacion", GetType(Integer)) - TmpDT.Columns.Add("Clasificacion", GetType(String)) - TmpDT.Columns.Add("CveClasificacionActualizar", GetType(Integer)) - TmpDT.Columns.Add("CvePS", GetType(Integer)) - TmpDT.Columns.Add("PS", GetType(String)) - TmpDT.Columns.Add("Obs", GetType(String)) - TmpDT.Columns.Add("PU", GetType(Decimal)) - TmpDT.Columns.Add("IVA", GetType(Decimal)) - TmpDT.Columns.Add("IVAPorcentaje", GetType(Decimal)) - TmpDT.Columns.Add("RetIVA", GetType(Decimal)) - TmpDT.Columns.Add("RetIVAPorcentaje", GetType(Decimal)) - TmpDT.Columns.Add("RetISR", GetType(Decimal)) - TmpDT.Columns.Add("RetISRPorcentaje", GetType(Decimal)) - TmpDT.Columns.Add("IEPSPS", GetType(Double)) - TmpDT.Columns.Add("IEPSPSPorcentaje", GetType(Double)) - TmpDT.Columns.Add("IEPSPSIVA", GetType(Double)) - TmpDT.Columns.Add("IEPSPSIVAPorcentaje", GetType(Double)) - TmpDT.Columns.Add("Descuento", GetType(Decimal)) - TmpDT.Columns.Add("OtrosGastos", GetType(Decimal)) - TmpDT.Columns.Add("Total", GetType(Decimal)) - TmpDT.Columns.Add("AsientoContableCompras", GetType(Integer)) - TmpDT.Columns.Add("IdCtaContCompras", GetType(Integer)) - TmpDT.Columns.Add("Proyecto", GetType(String)) - TmpDT.Columns.Add("CveProyecto", GetType(Integer)) - TmpDT.Columns.Add("CveSubProyecto", GetType(Integer)) - TmpDT.Columns.Add("CveContrato", GetType(Integer)) - TmpDT.Columns.Add("SubProyecto", GetType(String)) - 'TmpDT.Columns.Add("CveEq", GetType(Integer)) - TmpDT.Columns.Add("CveAlmacen", GetType(Integer)) - TmpDT.Columns.Add("CvePersonal", GetType(String)) - TmpDT.Columns.Add("Referencia", GetType(String)) - - 'AC - TmpDT.Columns.Add("CveTipoGastoAC", GetType(Integer)) - TmpDT.Columns.Add("CvePresupuestoEgreso", GetType(Integer)) - TmpDT.Columns.Add("CveProgramaOperativo", GetType(Integer)) - TmpDT.Columns.Add("CveUnidadAdministrativa", GetType(Integer)) - TmpDT.Columns.Add("CveFuenteFinanciamiento", GetType(Integer)) - TmpDT.Columns.Add("CveClasificacionOG", GetType(Integer)) - - TmpDT.Columns.Add("IdCuentaComprometido", GetType(Integer)) - TmpDT.Columns.Add("IdCuentaPorEjercer", GetType(Integer)) - TmpDT.Columns.Add("IdCuentaDevengado", GetType(Integer)) - TmpDT.Columns.Add("IdCuentaMatriz", GetType(Integer)) - - 'INVENTARIO SERIE/LOTE - TmpDT.Columns.Add("CveMetodoInventario", GetType(Integer)) - - TmpDT.Columns.Add("CveConcepto", GetType(Integer)) - - 'AF - TmpDT.Columns.Add("CveActivoFijo", GetType(Integer)) - TmpDT.Columns.Add("CodAF", GetType(String)) - TmpDT.Columns.Add("TipoAF", GetType(Integer)) - TmpDT.Columns.Add("AFMedida", GetType(Integer)) - TmpDT.Columns.Add("AFTipoMantenimiento", GetType(Integer)) - - 'PS - TmpDT.Columns.Add("CveTipoPS", GetType(Integer)) - TmpDT.Columns.Add("CodigoPS", GetType(String)) - TmpDT.Columns.Add("PSDescripcion", GetType(String)) - 'CAMPO ESPECIAL PARA GLUYAS - LEE EL DEL XML - A GLUYAS LE INTERESA EL CODIGO DEL PROVEEDOR - TmpDT.Columns.Add("PSCodigo", GetType(String)) - - - 'OC - TmpDT.Columns.Add("CveOrdenCompraDetalle", GetType(Integer)) - TmpDT.Columns.Add("ProductoOC", GetType(String)) - TmpDT.Columns.Add("CantidadF", GetType(Double)) - - 'Consignaciones - TmpDT.Columns.Add("CveAlmacenConsignacion", GetType(Integer)) - TmpDT.Columns.Add("NoConsignacion", GetType(Integer)) - TmpDT.Columns.Add("CveConsignacion", GetType(Integer)) - TmpDT.Columns.Add("HdnPS", GetType(String)) - TmpDT.Columns.Add("HdnCvePS", GetType(String)) - TmpDT.Columns.Add("HdnClasificacion", GetType(String)) - TmpDT.Columns.Add("HdnCveClasificacion", GetType(String)) - TmpDT.Columns.Add("HdnCveAlmacen", GetType(String)) - - 'Fletes y Servicios - TmpDT.Columns.Add("AplicaCostoIndirecto", GetType(Integer)) - TmpDT.Columns.Add("CostoIndirectoAlmacen", GetType(Decimal)) - TmpDT.Columns.Add("CveCompraDetalle", GetType(Integer)) - - TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) - - 'SAT - TmpDT.Columns.Add("CveSATPS", GetType(Integer)) - TmpDT.Columns.Add("SATClaveProductoServicio", GetType(String)) - TmpDT.Columns.Add("CveSATUnidadMedida", GetType(Integer)) - TmpDT.Columns.Add("SATClaveUnidadMedida", GetType(String)) - - 'Tipo de Gasto - TmpDT.Columns.Add("CveTipoGasto", GetType(Integer)) - TmpDT.Columns.Add("TipoGasto", GetType(String)) - - TmpDT.Columns.Add("ImporteSinImpuestos", GetType(Double)) - TmpDT.Columns.Add("ImporteConImpuestos", GetType(Double)) - TmpDT.Columns.Add("NoDeducible", GetType(Boolean)) - - TmpDTOriginal = New DataTable - TmpDTOriginal.Columns.Add("Consec", GetType(Integer)) - TmpDTOriginal.Columns.Add("Cantidad", GetType(Decimal)) - TmpDTOriginal.Columns.Add("Codigo", GetType(String)) - TmpDTOriginal.Columns.Add("CveUM", GetType(Integer)) - TmpDTOriginal.Columns.Add("UM", GetType(String)) - TmpDTOriginal.Columns.Add("CveClasificacion", GetType(Integer)) - TmpDTOriginal.Columns.Add("Clasificacion", GetType(String)) - TmpDTOriginal.Columns.Add("CveClasificacionActualizar", GetType(Integer)) - TmpDTOriginal.Columns.Add("CvePS", GetType(Integer)) - TmpDTOriginal.Columns.Add("PS", GetType(String)) - TmpDTOriginal.Columns.Add("Obs", GetType(String)) - TmpDTOriginal.Columns.Add("PU", GetType(Decimal)) - TmpDTOriginal.Columns.Add("IVA", GetType(Decimal)) - TmpDTOriginal.Columns.Add("IVAPorcentaje", GetType(Decimal)) - TmpDTOriginal.Columns.Add("RetIVA", GetType(Decimal)) - TmpDTOriginal.Columns.Add("RetIVAPorcentaje", GetType(Decimal)) - TmpDTOriginal.Columns.Add("RetISR", GetType(Decimal)) - TmpDTOriginal.Columns.Add("RetISRPorcentaje", GetType(Decimal)) - TmpDTOriginal.Columns.Add("IEPSPS", GetType(Double)) - TmpDTOriginal.Columns.Add("IEPSPSPorcentaje", GetType(Double)) - TmpDTOriginal.Columns.Add("IEPSPSIVA", GetType(Double)) - TmpDTOriginal.Columns.Add("IEPSPSIVAPorcentaje", GetType(Double)) - TmpDTOriginal.Columns.Add("Descuento", GetType(Decimal)) - TmpDTOriginal.Columns.Add("OtrosGastos", GetType(Decimal)) - TmpDTOriginal.Columns.Add("Total", GetType(Decimal)) - TmpDTOriginal.Columns.Add("AsientoContableCompras", GetType(Integer)) - TmpDTOriginal.Columns.Add("IdCtaContCompras", GetType(Integer)) - TmpDTOriginal.Columns.Add("Proyecto", GetType(String)) - TmpDTOriginal.Columns.Add("CveProyecto", GetType(Integer)) - TmpDTOriginal.Columns.Add("CveSubProyecto", GetType(Integer)) - TmpDTOriginal.Columns.Add("CveContrato", GetType(Integer)) - TmpDTOriginal.Columns.Add("SubProyecto", GetType(String)) - 'TmpDTOriginal.Columns.Add("CveEq", GetType(Integer)) - TmpDTOriginal.Columns.Add("CveAlmacen", GetType(Integer)) - TmpDTOriginal.Columns.Add("CvePersonal", GetType(String)) - TmpDTOriginal.Columns.Add("Referencia", GetType(String)) - - 'AC - TmpDTOriginal.Columns.Add("CveTipoGastoAC", GetType(Integer)) - TmpDTOriginal.Columns.Add("CvePresupuestoEgreso", GetType(Integer)) - TmpDTOriginal.Columns.Add("CveProgramaOperativo", GetType(Integer)) - TmpDTOriginal.Columns.Add("CveUnidadAdministrativa", GetType(Integer)) - TmpDTOriginal.Columns.Add("CveFuenteFinanciamiento", GetType(Integer)) - TmpDTOriginal.Columns.Add("CveClasificacionOG", GetType(Integer)) - - TmpDTOriginal.Columns.Add("IdCuentaComprometido", GetType(Integer)) - TmpDTOriginal.Columns.Add("IdCuentaPorEjercer", GetType(Integer)) - TmpDTOriginal.Columns.Add("IdCuentaDevengado", GetType(Integer)) - TmpDTOriginal.Columns.Add("IdCuentaMatriz", GetType(Integer)) - - 'INVENTARIO SERIE/LOTE - TmpDTOriginal.Columns.Add("CveMetodoInventario", GetType(Integer)) - - TmpDTOriginal.Columns.Add("CveConcepto", GetType(Integer)) - - 'AF - TmpDTOriginal.Columns.Add("CveActivoFijo", GetType(Integer)) - TmpDTOriginal.Columns.Add("CodAF", GetType(String)) - TmpDTOriginal.Columns.Add("TipoAF", GetType(Integer)) - TmpDTOriginal.Columns.Add("AFMedida", GetType(Integer)) - TmpDTOriginal.Columns.Add("AFTipoMantenimiento", GetType(Integer)) - - 'PS - TmpDTOriginal.Columns.Add("CveTipoPS", GetType(Integer)) - TmpDTOriginal.Columns.Add("CodigoPS", GetType(String)) - TmpDTOriginal.Columns.Add("PSDescripcion", GetType(String)) - 'CAMPO ESPECIAL PARA GLUYAS - LEE EL DEL XML - A GLUYAS LE INTERESA EL CODIGO DEL PROVEEDOR - TmpDTOriginal.Columns.Add("PSCodigo", GetType(String)) - - - 'OC - TmpDTOriginal.Columns.Add("CveOrdenCompraDetalle", GetType(Integer)) - TmpDTOriginal.Columns.Add("ProductoOC", GetType(String)) - TmpDTOriginal.Columns.Add("CantidadF", GetType(Double)) - - 'Consignaciones - TmpDTOriginal.Columns.Add("CveAlmacenConsignacion", GetType(Integer)) - TmpDTOriginal.Columns.Add("NoConsignacion", GetType(Integer)) - TmpDTOriginal.Columns.Add("CveConsignacion", GetType(Integer)) - TmpDTOriginal.Columns.Add("HdnPS", GetType(String)) - TmpDTOriginal.Columns.Add("HdnCvePS", GetType(String)) - TmpDTOriginal.Columns.Add("HdnClasificacion", GetType(String)) - TmpDTOriginal.Columns.Add("HdnCveClasificacion", GetType(String)) - TmpDTOriginal.Columns.Add("HdnCveAlmacen", GetType(String)) - - 'Fletes y Servicios - TmpDTOriginal.Columns.Add("AplicaCostoIndirecto", GetType(Integer)) - TmpDTOriginal.Columns.Add("CostoIndirectoAlmacen", GetType(Decimal)) - TmpDTOriginal.Columns.Add("CveCompraDetalle", GetType(Integer)) - - TmpDTOriginal.Columns.Add("EntregaDirecta", GetType(Integer)) - - 'SAT - TmpDTOriginal.Columns.Add("CveSATPS", GetType(Integer)) - TmpDTOriginal.Columns.Add("SATClaveProductoServicio", GetType(String)) - TmpDTOriginal.Columns.Add("CveSATUnidadMedida", GetType(Integer)) - TmpDTOriginal.Columns.Add("SATClaveUnidadMedida", GetType(String)) - - 'Tipo de Gasto - TmpDTOriginal.Columns.Add("CveTipoGasto", GetType(Integer)) - TmpDTOriginal.Columns.Add("TipoGasto", GetType(String)) - TmpDTOriginal.Columns.Add("NoDeducible", GetType(Boolean)) - - TmpDTOriginal.Columns.Add("Importe", GetType(Double)) - - - End Sub - 'Private Sub AddDTEnvio(Cantidad As Double, UM As String, CveUM As Integer, CvePS As Integer, PS As String, PU As Double, CveAlmacen As Integer, CveEq As Integer) - - ' Dim dr As DataRow = DtInv.NewRow - - ' dr("Cantidad") = Cantidad - ' dr("UM") = UM - ' dr("CveUM") = CveUM - ' dr("CvePS") = CvePS - ' dr("PS") = PS - ' dr("PU") = PU - ' dr("CveAlmacen") = CveAlmacen - ' dr("CveEq") = CveEq - - ' DtInv.Rows.InsertAt(dr, hdnIndexInv.Value.ToEntero + 1) - - ' GvInv.DataSource = DtInv - ' GvInv.DataBind() - - - 'End Sub - - Protected Sub RecargaMaximum_Click(sender As Object, e As System.EventArgs) - - CalculaTotales(True) - - 'RVDocumentoImporte.MaximumValue = (TxtSubTotal.Text.ToDouble - TxtDescuento.Text.ToDouble - LblAmortizacion.Text.Trim.ToDouble + TxtIVA.Text.ToDouble - TxtRetIVA.Text.ToDouble - TxtRetISR.Text.ToDouble).FormatoNumero(2) - 'RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue - 'RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue - End Sub - Protected Sub AlmacenCambiaPS_Click(sender As Object, e As EventArgs) Handles AlmacenCambiaPS.Click - Dim correcto As Boolean = True - Dim x As Integer = 0 - - 'Dim buid As New StringBuilder - For Each Dr As DataRow In TmpDT.Rows - Dim newps As Integer = GvInv.Rows(x).FCDropDownList("Ddlnewps").SelectedValue.ToEntero - If newps > 0 Then - 'buid.Append(String.Format("{0} ---> {1},", Dr("CvePS").ToString, newps)) - Dr("CvePS") = newps - 'buid.Append(String.Format("{0} ---> {1},
", Dr("CvePS").ToString, newps)) - Else 'limpio el valor para que no truene en linq mas abajo - correcto = False - Alert("Favor de asociar todos los productos o servicios", TipoMensaje.MsgAdvertencia) - Exit For - End If - x = x + 1 - Next - - x = 0 - - For Each Dr As DataRow In DtInv.Rows - Dim newps As Integer = GvInv.Rows(x).FCDropDownList("Ddlnewps").SelectedValue.ToEntero - If newps > 0 Then - 'buid.Append(String.Format("{0} ---> {1},", Dr("CvePS").ToString, newps)) - Dr("CvePS") = newps - 'buid.Append(String.Format("{0} ---> {1},
", Dr("CvePS").ToString, newps)) - Else 'limpio el valor para que no truene en linq mas abajo - correcto = False - Alert("Favor de asociar todos los productos o servicios", TipoMensaje.MsgAdvertencia) - Exit For - End If - x = x + 1 - Next - - TmpDT.AcceptChanges() - 'Alert(buid.ToString) - If correcto Then - If Not CierrePeriodo Then - BtnGuardar.Visible = True - End If - UpFacturar.Update() - End If - - End Sub - Private Sub SetValues() - 'Dim um As New ClsUnidadesMedida - TxtFecha.Text = Now.ToShortDateString() - LblUsuarioCaptura.Text = UsuarioActual.Usuario - DdlProveedor.Attributes.Add("onclick", "CargaProveedores();") - 'DdlFuncionarioEmpleado.Attributes.Add("onclick", "CargaFuncionariosEmpleados();") - TxtPrecio.Attributes.Add("onKeyUp ", "Recalcula();") - TxtCantidad.Attributes.Add("onKeyUp ", "Recalcula();") - TxtDescuentoModal.Attributes.Add("onKeyUp ", "Recalcula();") - TxtOtrosGastos.Attributes.Add("onKeyUp ", "Recalcula();") - 'ImgAmort.Attributes.Add("onclick", "javascript:$('#DivDescP').show(1000); PosicionaObjeto(this.id,'DivDescP');") ' $get('LblTitulo1').style.display = 'none'; $get('LblTituloTipo1').style.display = 'none'; $get('LblTituloTipo2').style.display = ''; $get('LblPrecio1').style.display = 'none'; $get('LblTotalPS1').style.display = 'none'; $get('LblSubTotal1').style.display = 'none'; $get('LblAmort').style.display = ''; $get('BtnAplicarDescP').style.display = 'none'; $get('BtnAplicarDescG').style.display = ''; $get('TrMotivoDescuento').style.display = 'none';") - - 'If um.GetUnidadesMedida() Then - ' GlobalDTUnidadesMedida = um.DtResultados - 'End If - 'um.Dispose() - - 'CargaEstatus() - CargaTiposAF() - CargaProyectoAsignado() - CargaClasificaciones() - CargaPS(-1) - CargaProyecto() - CreaDTCompras() - CargaMonedas() - CargarAlmacen() - 'CreaDtAF() - 'TabOC.Visible = False - - 'BORRAR OC - 'Valores para Vinculacion OC - 'If UsuarioActual.Empresa.MetodoOC = 1 Then GvOC2.Columns(2).Visible = False : tdSurtirOC.Visible = False Else GvOC2.Columns(0).Visible = False : tdFolioOC.Visible = False - - CveAlmacenConsignacion = -1 - CveConsignacion = -1 - OCVinculada = False - TipoCambioOC = -1 - EstatusAlmacen = -1 - CreaDtDetalle() - - CargarUMAlias() - End Sub -#End Region + Private Function notienepresupuesto() As Boolean + Dim notienerecursos = False + Dim SinRecursos As New StringBuilder + SinRecursos.AppendFormat("No se cuenta con los Recursos Suficientes en los siguientes subproyectos ") + Dim subproyectosSr As New List(Of Integer) + Dim filtro As New StringBuilder + 'me traigo los proyectos y subproyectos para traer presupuesots de la bd + Dim subproyectos As New List(Of Integer) -#Region " ALGO DE AF QUE NUNCA SE USABA " + For Each Row As DataRow In TmpDT.FiltraParametros("", "", {"CveSubProyecto", "SubProyecto"}).Rows + Dim RowCon As DataRow = GlobalDTContratos.FiltroPrimero(String.Format("CveSubProyecto={0}", Row("CveSubProyecto"))) + If Not IsNothing(RowCon) Then + filtro.AppendFormat(",{0}", Row("CveSubProyecto")) + subproyectos.Add(Row("CveSubProyecto").ToString.ToEntero) + End If + Next + 'me traigo los presupuestos de la base de datos + Dim dtpresupuestos As New DataTable + Dim objContratos As New ClsContratos + If objContratos.GetContratosPresupuesto(filtro.ToString) Then + dtpresupuestos = objContratos.DtResultados + End If + objContratos.Dispose() + + 'resto los importes actuales a los presupuestos obtenidos de la bd + For Each dr As DataRow In TmpDT.Rows + Dim psclasificacion As String = String.Format("CveSubFamilia='{0}' AND CveSubProyecto={1}", GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CvePS={0}", dr("CvePS").ToString.ToEntero))("CveSubFamilia").ToString, dr("CveSubProyecto").ToString) + + If dtpresupuestos.Rows.Count > 0 AndAlso dtpresupuestos.Select(psclasificacion).Count > 0 Then + Dim rowpresupuesto As DataRow = dtpresupuestos.Select(psclasificacion)(0) + rowpresupuesto("Importe") = rowpresupuesto("Importe").ToString.ToDouble - dr("Total").ToString.ToDouble() + Else + If subproyectos.Contains(dr("CveSubProyecto").ToString.ToEntero) Then + notienerecursos = True + If Not subproyectosSr.Contains(dr("CveSubProyecto").ToString.ToEntero) Then + subproyectosSr.Add(dr("CveSubProyecto").ToString.ToEntero) + SinRecursos.AppendFormat(",{0}", dr("SubProyecto").ToString) + End If + End If + End If + Next + dtpresupuestos.AcceptChanges() + ' + For Each rowpresupuesto As DataRow In dtpresupuestos.Rows + If (rowpresupuesto("Importe").ToString.ToDouble() < 0) Then + If Not subproyectosSr.Contains(rowpresupuesto("CveSubProyecto").ToString.ToEntero) Then + subproyectosSr.Add(rowpresupuesto("CveSubProyecto").ToString.ToEntero) + SinRecursos.AppendFormat(",{0}", rowpresupuesto("SubProyecto").ToString) + End If + notienerecursos = True + End If + Next + If (notienerecursos) Then + Alert(SinRecursos.ToString, TipoMensaje.MsgAdvertencia) + End If + dtpresupuestos.Dispose() + Return notienerecursos + End Function + Private Sub CreaDTConceptos() + DTConceptos = New DataTable + DTConceptos.Columns.Add("Consec", GetType(Integer)) + DTConceptos.Columns.Add("Cantidad", GetType(Double)) + DTConceptos.Columns.Add("UM", GetType(String)) + DTConceptos.Columns.Add("CveClasificacion", GetType(Integer)) + DTConceptos.Columns.Add("PS", GetType(String)) + DTConceptos.Columns.Add("PU", GetType(Double)) + DTConceptos.Columns.Add("Descuento", GetType(Double)) + DTConceptos.Columns.Add("IVA", GetType(Double)) + DTConceptos.Columns.Add("Total", GetType(Double)) + DTConceptos.Columns.Add("Amortizacion", GetType(Double)) + End Sub + 'Private Sub AddPS(Cantidad As Double, UM As String, PS As String, PU As Double, IVA As Double, Descuento As Double, Optional Total As Double = 0) + ' Dim Row As DataRow = Nothing + ' Row = DTConceptos.NewRow() + ' Row("Consec") = DTConceptos.Rows.Count + 1 + ' Row("Cantidad") = Cantidad + ' Row("UM") = UM + ' Row("CveClasificacion") = -1 + ' Row("PS") = PS + ' Row("PU") = PU + ' Row("IVA") = IVA + ' Row("Total") = If(Total > 0, Total, Cantidad * PU) + ' Row("Descuento") = Descuento + + ' DTConceptos.Rows.Add(Row) + 'End Sub + Private Sub CreaDTCompras() + + TmpDT = New DataTable + TmpDT.Columns.Add("Consec", GetType(Integer)) + TmpDT.Columns.Add("Cantidad", GetType(Decimal)) + TmpDT.Columns.Add("Codigo", GetType(String)) + TmpDT.Columns.Add("CveUM", GetType(Integer)) + TmpDT.Columns.Add("UM", GetType(String)) + TmpDT.Columns.Add("CveClasificacion", GetType(Integer)) + TmpDT.Columns.Add("Clasificacion", GetType(String)) + TmpDT.Columns.Add("CveClasificacionActualizar", GetType(Integer)) + TmpDT.Columns.Add("CvePS", GetType(Integer)) + TmpDT.Columns.Add("PS", GetType(String)) + TmpDT.Columns.Add("Obs", GetType(String)) + TmpDT.Columns.Add("PU", GetType(Decimal)) + TmpDT.Columns.Add("IVA", GetType(Decimal)) + TmpDT.Columns.Add("IVAPorcentaje", GetType(Decimal)) + TmpDT.Columns.Add("RetIVA", GetType(Decimal)) + TmpDT.Columns.Add("RetIVAPorcentaje", GetType(Decimal)) + TmpDT.Columns.Add("RetISR", GetType(Decimal)) + TmpDT.Columns.Add("RetISRPorcentaje", GetType(Decimal)) + TmpDT.Columns.Add("IEPSPS", GetType(Double)) + TmpDT.Columns.Add("IEPSPSPorcentaje", GetType(Double)) + TmpDT.Columns.Add("IEPSPSIVA", GetType(Double)) + TmpDT.Columns.Add("IEPSPSIVAPorcentaje", GetType(Double)) + TmpDT.Columns.Add("Descuento", GetType(Decimal)) + TmpDT.Columns.Add("OtrosGastos", GetType(Decimal)) + TmpDT.Columns.Add("Total", GetType(Decimal)) + TmpDT.Columns.Add("AsientoContableCompras", GetType(Integer)) + TmpDT.Columns.Add("IdCtaContCompras", GetType(Integer)) + TmpDT.Columns.Add("Proyecto", GetType(String)) + TmpDT.Columns.Add("CveProyecto", GetType(Integer)) + TmpDT.Columns.Add("CveSubProyecto", GetType(Integer)) + TmpDT.Columns.Add("CveContrato", GetType(Integer)) + TmpDT.Columns.Add("SubProyecto", GetType(String)) + 'TmpDT.Columns.Add("CveEq", GetType(Integer)) + TmpDT.Columns.Add("CveAlmacen", GetType(Integer)) + TmpDT.Columns.Add("CvePersonal", GetType(String)) + TmpDT.Columns.Add("Referencia", GetType(String)) + + 'AC + TmpDT.Columns.Add("CveTipoGastoAC", GetType(Integer)) + TmpDT.Columns.Add("CvePresupuestoEgreso", GetType(Integer)) + TmpDT.Columns.Add("CveProgramaOperativo", GetType(Integer)) + TmpDT.Columns.Add("CveUnidadAdministrativa", GetType(Integer)) + TmpDT.Columns.Add("CveFuenteFinanciamiento", GetType(Integer)) + TmpDT.Columns.Add("CveClasificacionOG", GetType(Integer)) + + TmpDT.Columns.Add("IdCuentaComprometido", GetType(Integer)) + TmpDT.Columns.Add("IdCuentaPorEjercer", GetType(Integer)) + TmpDT.Columns.Add("IdCuentaDevengado", GetType(Integer)) + TmpDT.Columns.Add("IdCuentaMatriz", GetType(Integer)) + + 'INVENTARIO SERIE/LOTE + TmpDT.Columns.Add("CveMetodoInventario", GetType(Integer)) + + TmpDT.Columns.Add("CveConcepto", GetType(Integer)) + + 'AF + TmpDT.Columns.Add("CveActivoFijo", GetType(Integer)) + TmpDT.Columns.Add("CodAF", GetType(String)) + TmpDT.Columns.Add("TipoAF", GetType(Integer)) + TmpDT.Columns.Add("AFMedida", GetType(Integer)) + TmpDT.Columns.Add("AFTipoMantenimiento", GetType(Integer)) + + 'PS + TmpDT.Columns.Add("CveTipoPS", GetType(Integer)) + TmpDT.Columns.Add("CodigoPS", GetType(String)) + TmpDT.Columns.Add("PSDescripcion", GetType(String)) + 'CAMPO ESPECIAL PARA GLUYAS - LEE EL DEL XML - A GLUYAS LE INTERESA EL CODIGO DEL PROVEEDOR + TmpDT.Columns.Add("PSCodigo", GetType(String)) + + + 'OC + TmpDT.Columns.Add("CveOrdenCompraDetalle", GetType(Integer)) + TmpDT.Columns.Add("ProductoOC", GetType(String)) + TmpDT.Columns.Add("CantidadF", GetType(Double)) + + 'Consignaciones + TmpDT.Columns.Add("CveAlmacenConsignacion", GetType(Integer)) + TmpDT.Columns.Add("NoConsignacion", GetType(Integer)) + TmpDT.Columns.Add("CveConsignacion", GetType(Integer)) + TmpDT.Columns.Add("HdnPS", GetType(String)) + TmpDT.Columns.Add("HdnCvePS", GetType(String)) + TmpDT.Columns.Add("HdnClasificacion", GetType(String)) + TmpDT.Columns.Add("HdnCveClasificacion", GetType(String)) + TmpDT.Columns.Add("HdnCveAlmacen", GetType(String)) + + 'Fletes y Servicios + TmpDT.Columns.Add("AplicaCostoIndirecto", GetType(Integer)) + TmpDT.Columns.Add("CostoIndirectoAlmacen", GetType(Decimal)) + TmpDT.Columns.Add("CveCompraDetalle", GetType(Integer)) + + TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) + + 'SAT + TmpDT.Columns.Add("CveSATPS", GetType(Integer)) + TmpDT.Columns.Add("SATClaveProductoServicio", GetType(String)) + TmpDT.Columns.Add("CveSATUnidadMedida", GetType(Integer)) + TmpDT.Columns.Add("SATClaveUnidadMedida", GetType(String)) + + 'Tipo de Gasto + TmpDT.Columns.Add("CveTipoGasto", GetType(Integer)) + TmpDT.Columns.Add("TipoGasto", GetType(String)) + + TmpDT.Columns.Add("ImporteSinImpuestos", GetType(Double)) + TmpDT.Columns.Add("ImporteConImpuestos", GetType(Double)) + TmpDT.Columns.Add("NoDeducible", GetType(Boolean)) + + TmpDTOriginal = New DataTable + TmpDTOriginal.Columns.Add("Consec", GetType(Integer)) + TmpDTOriginal.Columns.Add("Cantidad", GetType(Decimal)) + TmpDTOriginal.Columns.Add("Codigo", GetType(String)) + TmpDTOriginal.Columns.Add("CveUM", GetType(Integer)) + TmpDTOriginal.Columns.Add("UM", GetType(String)) + TmpDTOriginal.Columns.Add("CveClasificacion", GetType(Integer)) + TmpDTOriginal.Columns.Add("Clasificacion", GetType(String)) + TmpDTOriginal.Columns.Add("CveClasificacionActualizar", GetType(Integer)) + TmpDTOriginal.Columns.Add("CvePS", GetType(Integer)) + TmpDTOriginal.Columns.Add("PS", GetType(String)) + TmpDTOriginal.Columns.Add("Obs", GetType(String)) + TmpDTOriginal.Columns.Add("PU", GetType(Decimal)) + TmpDTOriginal.Columns.Add("IVA", GetType(Decimal)) + TmpDTOriginal.Columns.Add("IVAPorcentaje", GetType(Decimal)) + TmpDTOriginal.Columns.Add("RetIVA", GetType(Decimal)) + TmpDTOriginal.Columns.Add("RetIVAPorcentaje", GetType(Decimal)) + TmpDTOriginal.Columns.Add("RetISR", GetType(Decimal)) + TmpDTOriginal.Columns.Add("RetISRPorcentaje", GetType(Decimal)) + TmpDTOriginal.Columns.Add("IEPSPS", GetType(Double)) + TmpDTOriginal.Columns.Add("IEPSPSPorcentaje", GetType(Double)) + TmpDTOriginal.Columns.Add("IEPSPSIVA", GetType(Double)) + TmpDTOriginal.Columns.Add("IEPSPSIVAPorcentaje", GetType(Double)) + TmpDTOriginal.Columns.Add("Descuento", GetType(Decimal)) + TmpDTOriginal.Columns.Add("OtrosGastos", GetType(Decimal)) + TmpDTOriginal.Columns.Add("Total", GetType(Decimal)) + TmpDTOriginal.Columns.Add("AsientoContableCompras", GetType(Integer)) + TmpDTOriginal.Columns.Add("IdCtaContCompras", GetType(Integer)) + TmpDTOriginal.Columns.Add("Proyecto", GetType(String)) + TmpDTOriginal.Columns.Add("CveProyecto", GetType(Integer)) + TmpDTOriginal.Columns.Add("CveSubProyecto", GetType(Integer)) + TmpDTOriginal.Columns.Add("CveContrato", GetType(Integer)) + TmpDTOriginal.Columns.Add("SubProyecto", GetType(String)) + 'TmpDTOriginal.Columns.Add("CveEq", GetType(Integer)) + TmpDTOriginal.Columns.Add("CveAlmacen", GetType(Integer)) + TmpDTOriginal.Columns.Add("CvePersonal", GetType(String)) + TmpDTOriginal.Columns.Add("Referencia", GetType(String)) + + 'AC + TmpDTOriginal.Columns.Add("CveTipoGastoAC", GetType(Integer)) + TmpDTOriginal.Columns.Add("CvePresupuestoEgreso", GetType(Integer)) + TmpDTOriginal.Columns.Add("CveProgramaOperativo", GetType(Integer)) + TmpDTOriginal.Columns.Add("CveUnidadAdministrativa", GetType(Integer)) + TmpDTOriginal.Columns.Add("CveFuenteFinanciamiento", GetType(Integer)) + TmpDTOriginal.Columns.Add("CveClasificacionOG", GetType(Integer)) + + TmpDTOriginal.Columns.Add("IdCuentaComprometido", GetType(Integer)) + TmpDTOriginal.Columns.Add("IdCuentaPorEjercer", GetType(Integer)) + TmpDTOriginal.Columns.Add("IdCuentaDevengado", GetType(Integer)) + TmpDTOriginal.Columns.Add("IdCuentaMatriz", GetType(Integer)) + + 'INVENTARIO SERIE/LOTE + TmpDTOriginal.Columns.Add("CveMetodoInventario", GetType(Integer)) + + TmpDTOriginal.Columns.Add("CveConcepto", GetType(Integer)) + + 'AF + TmpDTOriginal.Columns.Add("CveActivoFijo", GetType(Integer)) + TmpDTOriginal.Columns.Add("CodAF", GetType(String)) + TmpDTOriginal.Columns.Add("TipoAF", GetType(Integer)) + TmpDTOriginal.Columns.Add("AFMedida", GetType(Integer)) + TmpDTOriginal.Columns.Add("AFTipoMantenimiento", GetType(Integer)) + + 'PS + TmpDTOriginal.Columns.Add("CveTipoPS", GetType(Integer)) + TmpDTOriginal.Columns.Add("CodigoPS", GetType(String)) + TmpDTOriginal.Columns.Add("PSDescripcion", GetType(String)) + 'CAMPO ESPECIAL PARA GLUYAS - LEE EL DEL XML - A GLUYAS LE INTERESA EL CODIGO DEL PROVEEDOR + TmpDTOriginal.Columns.Add("PSCodigo", GetType(String)) + + + 'OC + TmpDTOriginal.Columns.Add("CveOrdenCompraDetalle", GetType(Integer)) + TmpDTOriginal.Columns.Add("ProductoOC", GetType(String)) + TmpDTOriginal.Columns.Add("CantidadF", GetType(Double)) + + 'Consignaciones + TmpDTOriginal.Columns.Add("CveAlmacenConsignacion", GetType(Integer)) + TmpDTOriginal.Columns.Add("NoConsignacion", GetType(Integer)) + TmpDTOriginal.Columns.Add("CveConsignacion", GetType(Integer)) + TmpDTOriginal.Columns.Add("HdnPS", GetType(String)) + TmpDTOriginal.Columns.Add("HdnCvePS", GetType(String)) + TmpDTOriginal.Columns.Add("HdnClasificacion", GetType(String)) + TmpDTOriginal.Columns.Add("HdnCveClasificacion", GetType(String)) + TmpDTOriginal.Columns.Add("HdnCveAlmacen", GetType(String)) + + 'Fletes y Servicios + TmpDTOriginal.Columns.Add("AplicaCostoIndirecto", GetType(Integer)) + TmpDTOriginal.Columns.Add("CostoIndirectoAlmacen", GetType(Decimal)) + TmpDTOriginal.Columns.Add("CveCompraDetalle", GetType(Integer)) + + TmpDTOriginal.Columns.Add("EntregaDirecta", GetType(Integer)) + + 'SAT + TmpDTOriginal.Columns.Add("CveSATPS", GetType(Integer)) + TmpDTOriginal.Columns.Add("SATClaveProductoServicio", GetType(String)) + TmpDTOriginal.Columns.Add("CveSATUnidadMedida", GetType(Integer)) + TmpDTOriginal.Columns.Add("SATClaveUnidadMedida", GetType(String)) + + 'Tipo de Gasto + TmpDTOriginal.Columns.Add("CveTipoGasto", GetType(Integer)) + TmpDTOriginal.Columns.Add("TipoGasto", GetType(String)) + TmpDTOriginal.Columns.Add("NoDeducible", GetType(Boolean)) + + TmpDTOriginal.Columns.Add("Importe", GetType(Double)) + + + End Sub + 'Private Sub AddDTEnvio(Cantidad As Double, UM As String, CveUM As Integer, CvePS As Integer, PS As String, PU As Double, CveAlmacen As Integer, CveEq As Integer) + + ' Dim dr As DataRow = DtInv.NewRow + + ' dr("Cantidad") = Cantidad + ' dr("UM") = UM + ' dr("CveUM") = CveUM + ' dr("CvePS") = CvePS + ' dr("PS") = PS + ' dr("PU") = PU + ' dr("CveAlmacen") = CveAlmacen + ' dr("CveEq") = CveEq + + ' DtInv.Rows.InsertAt(dr, hdnIndexInv.Value.ToEntero + 1) + + ' GvInv.DataSource = DtInv + ' GvInv.DataBind() + + + 'End Sub + + Protected Sub RecargaMaximum_Click(sender As Object, e As System.EventArgs) + + CalculaTotales(True) + + 'RVDocumentoImporte.MaximumValue = (TxtSubTotal.Text.ToDouble - TxtDescuento.Text.ToDouble - LblAmortizacion.Text.Trim.ToDouble + TxtIVA.Text.ToDouble - TxtRetIVA.Text.ToDouble - TxtRetISR.Text.ToDouble).FormatoNumero(2) + 'RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue + 'RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue + End Sub + Protected Sub AlmacenCambiaPS_Click(sender As Object, e As EventArgs) Handles AlmacenCambiaPS.Click + Dim correcto As Boolean = True + Dim x As Integer = 0 + + 'Dim buid As New StringBuilder + For Each Dr As DataRow In TmpDT.Rows + Dim newps As Integer = GvInv.Rows(x).FCDropDownList("Ddlnewps").SelectedValue.ToEntero + If newps > 0 Then + 'buid.Append(String.Format("{0} ---> {1},", Dr("CvePS").ToString, newps)) + Dr("CvePS") = newps + 'buid.Append(String.Format("{0} ---> {1},
", Dr("CvePS").ToString, newps)) + Else 'limpio el valor para que no truene en linq mas abajo + correcto = False + Alert("Favor de asociar todos los productos o servicios", TipoMensaje.MsgAdvertencia) + Exit For + End If + x = x + 1 + Next + + x = 0 + + For Each Dr As DataRow In DtInv.Rows + Dim newps As Integer = GvInv.Rows(x).FCDropDownList("Ddlnewps").SelectedValue.ToEntero + If newps > 0 Then + 'buid.Append(String.Format("{0} ---> {1},", Dr("CvePS").ToString, newps)) + Dr("CvePS") = newps + 'buid.Append(String.Format("{0} ---> {1},
", Dr("CvePS").ToString, newps)) + Else 'limpio el valor para que no truene en linq mas abajo + correcto = False + Alert("Favor de asociar todos los productos o servicios", TipoMensaje.MsgAdvertencia) + Exit For + End If + x = x + 1 + Next + + TmpDT.AcceptChanges() + 'Alert(buid.ToString) + If correcto Then + If Not CierrePeriodo Then + BtnGuardar.Visible = True + End If + UpFacturar.Update() + End If + + End Sub + Private Sub SetValues() + 'Dim um As New ClsUnidadesMedida + TxtFecha.Text = Now.ToShortDateString() + LblUsuarioCaptura.Text = UsuarioActual.Usuario + DdlProveedor.Attributes.Add("onclick", "CargaProveedores();") + 'DdlFuncionarioEmpleado.Attributes.Add("onclick", "CargaFuncionariosEmpleados();") + TxtPrecio.Attributes.Add("onKeyUp ", "Recalcula();") + TxtCantidad.Attributes.Add("onKeyUp ", "Recalcula();") + TxtDescuentoModal.Attributes.Add("onKeyUp ", "Recalcula();") + TxtOtrosGastos.Attributes.Add("onKeyUp ", "Recalcula();") + 'ImgAmort.Attributes.Add("onclick", "javascript:$('#DivDescP').show(1000); PosicionaObjeto(this.id,'DivDescP');") ' $get('LblTitulo1').style.display = 'none'; $get('LblTituloTipo1').style.display = 'none'; $get('LblTituloTipo2').style.display = ''; $get('LblPrecio1').style.display = 'none'; $get('LblTotalPS1').style.display = 'none'; $get('LblSubTotal1').style.display = 'none'; $get('LblAmort').style.display = ''; $get('BtnAplicarDescP').style.display = 'none'; $get('BtnAplicarDescG').style.display = ''; $get('TrMotivoDescuento').style.display = 'none';") + + 'If um.GetUnidadesMedida() Then + ' GlobalDTUnidadesMedida = um.DtResultados + 'End If + 'um.Dispose() + + 'CargaEstatus() + CargaTiposAF() + CargaProyectoAsignado() + CargaClasificaciones() + CargaPS(-1) + CargaProyecto() + CreaDTCompras() + CargaMonedas() + CargarAlmacen() + 'CreaDtAF() + 'TabOC.Visible = False + + 'BORRAR OC + 'Valores para Vinculacion OC + 'If UsuarioActual.Empresa.MetodoOC = 1 Then GvOC2.Columns(2).Visible = False : tdSurtirOC.Visible = False Else GvOC2.Columns(0).Visible = False : tdFolioOC.Visible = False + + CveAlmacenConsignacion = -1 + CveConsignacion = -1 + OCVinculada = False + TipoCambioOC = -1 + EstatusAlmacen = -1 + CreaDtDetalle() + + CargarUMAlias() + + End Sub +#End Region + +#Region " ALGO DE AF QUE NUNCA SE USABA " 'Protected Sub GVAF_RowCreated(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GVAF.RowCreated ' If e.Row.RowType = DataControlRowType.DataRow AndAlso (e.Row.RowState = DataControlRowState.Alternate OrElse e.Row.RowState = DataControlRowState.Normal) Then ' e.Row.FCDropDownList("DdlTipoActivoFijo").DataSource = TmpDTTiposAF @@ -11070,46 +11208,46 @@ Partial Class Compras_Compras ' PnlFuncionarioEmpleado.Visible = chkFuncionariosEmpleados.Checked ' UPCondicionesPago.Update() 'End Sub - Protected Sub BtnOCAceptar_Click(sender As Object, e As EventArgs) Handles BtnOCAceptar.Click - 'carga la OC - Dim CveOC As Integer = -1 - For Each gvr As GridViewRow In GvOC.Rows - If gvr.FCCheckBox("Chk").Checked Then - CveOC = gvr.DataKey("CveOrdenCompra").ToEntero - Exit For - End If - Next - - Dim dt As DataTable = Nothing - If CveOC > 0 Then - - Dim OC As New ClsOC - - If OC.GetOC(CveOC, UsuarioActual.CveEmpresa) Then - - TxtOC.Text = OC.Folio.ToString - 'RegistraScript(String.Format("$get('TxtOC').value = '{0}';tb_remove;", OC.Folio)) - RegistraScript("tb_remove();") - - If OC.GetOrdenesDetalle(CveOC) Then - dt = OC.DtResultados - End If - End If - - OC.Dispose() - End If - - 'GvOCC.DataSource = TmpDT - 'GvOCC.DataBind() - 'GvOCC2.DataSource = dt - 'GvOCC2.DataBind() - - 'UpnAF.Update() - - End Sub -#End Region + Protected Sub BtnOCAceptar_Click(sender As Object, e As EventArgs) Handles BtnOCAceptar.Click + 'carga la OC + Dim CveOC As Integer = -1 + For Each gvr As GridViewRow In GvOC.Rows + If gvr.FCCheckBox("Chk").Checked Then + CveOC = gvr.DataKey("CveOrdenCompra").ToEntero + Exit For + End If + Next -#Region "Estimaciones" + Dim dt As DataTable = Nothing + If CveOC > 0 Then + + Dim OC As New ClsOC + + If OC.GetOC(CveOC, UsuarioActual.CveEmpresa) Then + + TxtOC.Text = OC.Folio.ToString + 'RegistraScript(String.Format("$get('TxtOC').value = '{0}';tb_remove;", OC.Folio)) + RegistraScript("tb_remove();") + + If OC.GetOrdenesDetalle(CveOC) Then + dt = OC.DtResultados + End If + End If + + OC.Dispose() + End If + + 'GvOCC.DataSource = TmpDT + 'GvOCC.DataBind() + 'GvOCC2.DataSource = dt + 'GvOCC2.DataBind() + + 'UpnAF.Update() + + End Sub +#End Region + +#Region "Estimaciones" 'Private Sub CargaDatosEstimaciones(pCveProveedor As Integer) ' Dim Con As New ClsContratos @@ -11143,354 +11281,354 @@ Partial Class Compras_Compras ' End If 'End Sub -#End Region +#End Region -#Region " ALMACEN " - Private Sub CargaGvInv() - - 'SI ES CONSIGNACION NO LIMITA POR TIPO PS - PARA GLUYAS - If ChkConsignacion.Checked Then - DtInv = TmpDT.Copy - Else - DtInv = TmpDT.FiltraParametros(String.Format("CveTipoPS = 2")).Copy - End If - - GvInv.DataSource = DtInv - GvInv.DataBind() - - 'If (GvInv.Rows.Count > 0) Then - ' GvInv.UseAccessibleHeader = True - ' GvInv.HeaderRow.TableSection = TableRowSection.TableHeader - ' RegistraScript("OrdenarGVInv();") - 'End If - - InicializaCargaEvidenciaAlmacen() - - 'CARGA VALORES YA SELECCIONADOS DE CONSIGNACION - If ChkConsignacion.Checked Then - End If - - UpINV.Update() - - End Sub - - Private Sub CargaFletesAgregados() - CreaDTServicios() - BtnFiltrar_Click(Nothing, Nothing) - End Sub - - Protected Sub GVINV_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvInv.RowEditing - CargaGvInv() - End Sub - - Protected Sub GVINV_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvInv.RowCancelingEdit - CargaGvInv() - End Sub - - Protected Sub GVINV_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvInv.RowUpdating - Dim Cantidad As Double = DirectCast(GvInv.Rows(e.RowIndex).FindControl("txtECantidad"), TextBox).Text.ToDouble - Dim CveUnidadMedida As Integer = DirectCast(GvInv.Rows(e.RowIndex).FindControl("ddlEUnidad"), DropDownList).SelectedValue.ToString.ToEntero - DtInv.Rows.Item(e.RowIndex)("Cantidad") = Cantidad - DtInv.Rows.Item(e.RowIndex)("CveUM") = CveUnidadMedida - - CargaGvInv() - End Sub - - Protected Sub GVINV_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvInv.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - - 'SI USA SERIE-LOTE INVENTARIO - If e.Row.DBCampo("CveMetodoInventario").ToString = "5" Then - e.Row.FCButton("BtnSerieLote").Visible = True - e.Row.FCButton("BtnSerieLote").CommandArgument = String.Format("{0}°{1}°{2}°{3}°{4}", e.Row.DBCampo("CvePS"), e.Row.DBCampo("CveUM"), e.Row.DBCampo("PU"), e.Row.DBCampo("PS"), e.Row.DBCampo("Cantidad")) - e.Row.FCTextBox("TbCantidad").Enabled = False - e.Row.FCCheckBox("cbInv").Enabled = False - Dim Contador = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", e.Row.DataKey("CvePS"))).Rows.Count - e.Row.FCTextBox("TbCantidad").Text = Contador.ToString - 'e.Row.FCTextBox("TbCantidadF").Text = "0" - Else - e.Row.FCButton("BtnSerieLote").Visible = False - e.Row.FCTextBox("TbCantidad").Enabled = True - e.Row.FCTextBox("TbCantidad").Attributes.Add("onblur", String.Format("ValidarCantidad(this,{0})", e.Row.DBCampo("Cantidad"))) - End If - - 'SIEMPRE ENABLED FALSE - e.Row.FCCheckBox("cbInv").Enabled = False - - 'si ya hay cargada una compra - If CveCompra > 0 AndAlso CveMovimientoAlmacen > 0 Then - If e.Row.DBCampo("AlmacenRegistrado").ToString = "1" Then - e.Row.FCCheckBox("cbInv").Checked = True - End If - e.Row.FCCheckBox("cbInv").Enabled = False - End If - - 'CONSIGNACIONES - If ChkConsignacion.Checked Then - e.Row.FCTextBox("TbCantidad").Enabled = False - e.Row.FCCheckBox("cbInv").Enabled = False - - If Not OCVinculada Then - e.Row.Cells(3).Text = e.Row.DBCampo("PSCodigo").ToString - End If - - Else - If e.Row.DBCampo("CveMetodoInventario").ToString = "5" Then - e.Row.FCTextBox("TbCantidad").Enabled = False - Else - e.Row.FCTextBox("TbCantidad").Enabled = True - End If - - e.Row.FCCheckBox("cbInv").Enabled = False - End If - - If UsuarioActual.Empresa.UsaAC Then - e.Row.FCCheckBox("cbInv").Enabled = False - End If - - e.Row.FCDropDownList("ddlEAlmacen").DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen IN (1,2,7,14,19)") 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) - e.Row.FCDropDownList("ddlEAlmacen").Items.Insert(0, New ListItem("Seleccione", "-1")) - e.Row.FCDropDownList("ddlEAlmacen").DataBind() - 'e.Row.FCDropDownList("ddlEAlmacen").SelectedValue = If(e.Row.DBCampo("CveAlmacen").ToEntero <= 0, "-1", e.Row.DBCampo("CveAlmacen")) - If UsuarioActual.Empresa.UsaAC Then e.Row.FCDropDownList("ddlEAlmacen").Enabled = False - - If Not e.Row.DBCampo("CveMetodoInventario").ToString = "5" Then - e.Row.FCTextBox("TbCantidad").Attributes.Add("onblur", String.Format("ValidarCantidad(this,{0})", If(e.Row.DBCampo("CantidadF").ToString.ToDecimal > e.Row.DBCampo("Cantidad").ToString.ToDecimal, e.Row.DBCampo("Cantidad"), e.Row.DBCampo("CantidadF")))) - e.Row.FCTextBox("TbCantidad").Text = If(e.Row.DBCampo("CantidadF").ToString.ToDecimal > e.Row.DBCampo("Cantidad").ToString.ToDecimal, e.Row.DBCampo("Cantidad"), e.Row.DBCampo("CantidadF")) - End If - - 'e.Row.FCImageButton("btnImgDestino").Attributes.Add("onclick", "javascript:$('#DivAlmacen').show(500); PosicionaObjeto(this.id,'DivAlmacen'); CargarValores('" & e.Row.RowIndex & "','" & e.Row.DBCampo("Cantidad") & "','" & e.Row.DBCampo("PS").Replace("'", "\'") & "'); ") - ' e.Row.FCImageButton("btnImgDestino").ID = e.Row.FCImageButton("btnImgDestino").ID.ToString + e.Row.RowIndex.ToString - 'e.Row.Cells(6).ToolTip = "Enviar a otro Almacén." - - If e.Row.DBCampo("Consec").ToEntero = 0 Then - e.Row.BackColor = Drawing.Color.PaleGreen - End If - - If UsuarioActual.CveEmpresa = 66 Then - e.Row.FCDropDownList("DdlRecibirInv").Items.RemoveAt(1) - End If - - 'If isAlmacenistaGluyas() Then - ' Dim dt As DataTable = Nothing - ' dt = GlobalDTProductosServicios(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoPS=2", "PS") - ' e.Row.FCDropDownList("Ddlnewps").DataSource = dt 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) - ' e.Row.FCDropDownList("Ddlnewps").DataBind() - ' e.Row.FCDropDownList("Ddlnewps").Items.Insert(0, New ListItem("Seleccione", "-1")) - ' dt.Dispose() - 'End If - - 'Consignaciones - If CveConsignacion > 0 Then - ''CARGA ALMACEN CONSIGNACION - e.Row.FCDropDownList("ddlAlmacenConsignacion").DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 4) - e.Row.FCDropDownList("ddlAlmacenConsignacion").DataBind() - - If e.Row.DBCampo("CveAlmacenConsignacion").ToEntero > 0 Then - e.Row.FCDropDownList("ddlAlmacenConsignacion").SelectedValueExist(e.Row.DBCampo("CveAlmacenConsignacion")) - End If - - ''CARGA CONSIGNACIONES - e.Row.FCDropDownList("DdlVinculaConsignacion").DataSource = DtConsignaciones.FiltraParametros(String.Format("CveAlmacenSalida = {0} OR {0} = '-1'", e.Row.FCDropDownList("ddlAlmacenConsignacion").SelectedValue)) - e.Row.FCDropDownList("DdlVinculaConsignacion").DataBind() - e.Row.FCDropDownList("DdlVinculaConsignacion").Items.Insert(0, New ListItem("Seleccione", "-1")) - - If e.Row.DBCampo("NoConsignacion").ToEntero > 0 Then - e.Row.FCDropDownList("DdlVinculaConsignacion").SelectedValueExist(e.Row.DBCampo("NoConsignacion")) - e.Row.FCHiddenField("HdnNoConsignacion").Value = e.Row.DBCampo("NoConsignacion") - End If - - If e.Row.DBCampo("CveConsignacion").ToEntero > 0 Then - e.Row.FCHiddenField("HdnCveConsignacion").Value = e.Row.DBCampo("CveConsignacion") - e.Row.FCHiddenField("HdnPS").Value = e.Row.DBCampo("HdnPS") - e.Row.FCHiddenField("HdnCvePS").Value = e.Row.DBCampo("HdnCvePS") - e.Row.FCHiddenField("HdnClasificacion").Value = e.Row.DBCampo("HdnClasificacion") - e.Row.FCHiddenField("HdnCveClasificacion").Value = e.Row.DBCampo("HdnCveClasificacion") - e.Row.FCHiddenField("HdnCveAlmacen").Value = e.Row.DBCampo("HdnCveAlmacen") - End If - - e.Row.FCTextBox("TxtDividir").Visible = True - Else - e.Row.FCTextBox("TxtDividir").Visible = False - End If - - If Not UsuarioActual.Empresa.UsaAC Then - - - e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("FormatoMoneda(this);LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCButton("BtnDividirCompra").ClientID)) - - e.Row.FCTextBox("TxtDividir").Text = "" - If e.Row.DBCampo("Cantidad").ToDouble > 0.02 Then - e.Row.FCButton("BtnDividirCompra").CommandArgument = e.Row.RowIndex.ToString - Else - e.Row.FCButton("BtnDividirCompra").Visible = False - e.Row.FCTextBox("TxtDividir").Visible = False - End If - End If - - End If - - 'HEADER GvInv - If e.Row.RowType = DataControlRowType.Header Then - Dim StrAlmacenes As String = "CveTipoAlmacen IN (1,2,7,14,19)" - - If UsuarioActual.CveUsuario.Contiene(1397, 1517, 1565) Then ' iliana, horacio, marco, RMF. 2017.03.13 - StrAlmacenes = "CveTipoAlmacen IN (1,2,7,14,12,19)" - End If - e.Row.FCDropDownList("ddlAlmacen").DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros(StrAlmacenes) 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) - e.Row.FCDropDownList("ddlAlmacen").Items.Insert(0, New ListItem("Seleccione", "-1")) - e.Row.FCDropDownList("ddlAlmacen").DataBind() - - 'si ya hay cargada una compra - If CveCompra > 0 AndAlso CveMovimientoAlmacen > 0 Then - e.Row.FCCheckBox("cbAll").Enabled = False - End If - - ''CARGA ALMACEN CONSIGNACION - e.Row.FCDropDownList("ddlAlmacenConsignacionGeneral").DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 4) - e.Row.FCDropDownList("ddlAlmacenConsignacionGeneral").DataBind() - End If - - End Sub - - Protected Sub ddlAlmacen_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) - Dim Ddl As DropDownList = CType(sender, DropDownList) - - For i As Integer = 0 To GvInv.Rows.Count - 1 - GvInv.Rows(i).FCDropDownList("ddlEAlmacen").SelectedValue = Ddl.SelectedValue - Next - - InicializaCargaEvidenciaAlmacen() - - End Sub - 'Protected Sub btnAgregarEq_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click - - - ' Dim eq As New ClsProductosServicios - ' Dim Unidad As String = TmpDT.Rows.Item(HdnEq.Value.ToEntero)("UM").ToString - ' Dim CvePS As Integer = TmpDT.Rows.Item(HdnEq.Value.ToEntero)("CvePS").ToString.ToEntero - ' Dim CveUM As Integer = TmpDT.Rows.Item(HdnEq.Value.ToEntero)("CveUM").ToString.ToEntero - ' Dim PU As Double = TmpDT.Rows.Item(HdnEq.Value.ToEntero)("PU").ToString.ToDouble - - ' Dim tCve As Integer = 0 - ' Dim ErrorUM As Boolean = False - - ' If UsuarioActual.Empresa.UsaInventarios And CveUM = 0 Then - ' Dim UM As New ClsUnidadesMedida - ' tCve = UM.AddUnidadMedida(TmpDT.Rows.Item(HdnEq.Value.ToEntero)("UM").ToString, TmpDT.Rows.Item(HdnEq.Value.ToEntero)("UM").ToString, "", "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1) - - ' If tCve > 0 Then - ' TmpDT.Rows.Item(HdnEq.Value.ToEntero)("CveUM") = tCve - ' Else - ' ErrorUM = True - ' End If - - - ' End If - - ' If Not ErrorUM Then - - ' If eq.AddPSEquivalencias(CvePS, CveUM, txtCantidadEq.Text.ToDecimal, False, PU, UsuarioActual.CveUsuario) Then - ' TmpDT.Rows.Item(HdnEq.Value.ToEntero)("CveEq") = 1 - - ' End If - - - ' End If - - - ' GvPS.DataSource = TmpDT - ' GvPS.DataBind() - - ' eq.Dispose() - - ' txtCantidadEq.Text = "" - 'End Sub - - - 'Protected Sub Enviar_Click(sender As Object, e As ImageClickEventArgs) Handles ImgAdd.Click - - ' If TbCantidadAlm.Text.ToDouble < DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("Cantidad").ToString.ToDouble And TbCantidadAlm.Text.ToDouble > 0 Then - - ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("Cantidad") = DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("Cantidad").ToString.ToDouble - TbCantidadAlm.Text.ToDouble - ' AddDTEnvio(TbCantidadAlm.Text.ToDouble, - ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("UM").ToString, - ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CveUM").ToString.ToEntero, - ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CvePS").ToString().ToEntero, - ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("PS").ToString, - ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("PU").ToString.ToDouble, - ' ddlAlmacenAdd.SelectedValue.ToEntero, DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CveEq").ToString.ToEntero) - - - ' Else - ' Alert("El campo cantidad es necesario que sea mayor que 0 y menor al registro seleccionado.") - - - ' End If - - ' TbCantidadAlm.Text = "" - ' ddlAlmacenAdd.SelectedIndex = 0 - ' UpINV.Update() - - ' ' Alert(TmpDT.Rows.Count.ToString) - - - - 'End Sub - - - Protected Sub cbAll_CheckedChanged(sender As Object, e As EventArgs) - For i As Integer = 0 To GvInv.Rows.Count - 1 - GvInv.Rows(i).FCCheckBox("cbInv").Checked = GvInv.HeaderRow.FCCheckBox("cbAll").Checked - Next - CalculaTotalPorDevengar() - End Sub - - Private Sub InicializaCargaEvidenciaAlmacen() - - TableAlmacenEvidencia.Visible = False - - If UsuarioActual.CveEmpresa = 13 Then - If GvInv.Rows.Count > 0 AndAlso GvInv.HeaderRow().FCDropDownList("ddlAlmacen").SelectedValue.ToEntero > 0 Then - Dim DrAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", GvInv.HeaderRow().FCDropDownList("ddlAlmacen").SelectedValue.ToEntero)) - If DrAlmacen("CveTipoAlmacen").ToString = "7" Then - TableAlmacenEvidencia.Visible = True - End If - End If - End If - - UpAlmacenEvidencia.Update() - - End Sub -#End Region +#Region " ALMACEN " + Private Sub CargaGvInv() -#Region "PESTAÑA INFORMACION GENERAL DE BANCO IE" + 'SI ES CONSIGNACION NO LIMITA POR TIPO PS - PARA GLUYAS + If ChkConsignacion.Checked Then + DtInv = TmpDT.Copy + Else + DtInv = TmpDT.FiltraParametros(String.Format("CveTipoPS = 2")).Copy + End If + + GvInv.DataSource = DtInv + GvInv.DataBind() + + 'If (GvInv.Rows.Count > 0) Then + ' GvInv.UseAccessibleHeader = True + ' GvInv.HeaderRow.TableSection = TableRowSection.TableHeader + ' RegistraScript("OrdenarGVInv();") + 'End If + + InicializaCargaEvidenciaAlmacen() + + 'CARGA VALORES YA SELECCIONADOS DE CONSIGNACION + If ChkConsignacion.Checked Then + End If + + UpINV.Update() - Private Sub CargaTipoTransaccion() - DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs'") - DdlTipoTransaccion.DataBind() - DdlTipoTransaccion.Items.Insert(0, New ListItem("Seleccione Tipo Movimiento", "-1")) - - DdlTipoTransaccionCaja.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs'") - DdlTipoTransaccionCaja.DataBind() - DdlTipoTransaccionCaja.Items.Insert(0, New ListItem("Seleccione Tipo Movimiento", "-1")) - End Sub - - Private Sub CargaCuentas() - DdlCuenta.Items.Clear() - DdlCuenta.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros(String.Format("CveTipoCuenta <> 1")) - DdlCuenta.DataBind() - DdlCuenta.Items.Insert(0, New ListItem("Seleccione", "-1")) - - DdlCuentaCaja.Items.Clear() - DdlCuentaCaja.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros(String.Format("CveTipoCuenta = 1")) - DdlCuentaCaja.DataBind() - DdlCuentaCaja.Items.Insert(0, New ListItem("Seleccione", "-1")) End Sub -#End Region + Private Sub CargaFletesAgregados() + CreaDTServicios() + BtnFiltrar_Click(Nothing, Nothing) + End Sub -#Region "FINANCIAMIENTO - AC" + Protected Sub GVINV_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvInv.RowEditing + CargaGvInv() + End Sub + + Protected Sub GVINV_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvInv.RowCancelingEdit + CargaGvInv() + End Sub + + Protected Sub GVINV_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvInv.RowUpdating + Dim Cantidad As Double = DirectCast(GvInv.Rows(e.RowIndex).FindControl("txtECantidad"), TextBox).Text.ToDouble + Dim CveUnidadMedida As Integer = DirectCast(GvInv.Rows(e.RowIndex).FindControl("ddlEUnidad"), DropDownList).SelectedValue.ToString.ToEntero + DtInv.Rows.Item(e.RowIndex)("Cantidad") = Cantidad + DtInv.Rows.Item(e.RowIndex)("CveUM") = CveUnidadMedida + + CargaGvInv() + End Sub + + Protected Sub GVINV_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvInv.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + + 'SI USA SERIE-LOTE INVENTARIO + If e.Row.DBCampo("CveMetodoInventario").ToString = "5" Then + e.Row.FCButton("BtnSerieLote").Visible = True + e.Row.FCButton("BtnSerieLote").CommandArgument = String.Format("{0}°{1}°{2}°{3}°{4}", e.Row.DBCampo("CvePS"), e.Row.DBCampo("CveUM"), e.Row.DBCampo("PU"), e.Row.DBCampo("PS"), e.Row.DBCampo("Cantidad")) + e.Row.FCTextBox("TbCantidad").Enabled = False + e.Row.FCCheckBox("cbInv").Enabled = False + Dim Contador = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", e.Row.DataKey("CvePS"))).Rows.Count + e.Row.FCTextBox("TbCantidad").Text = Contador.ToString + 'e.Row.FCTextBox("TbCantidadF").Text = "0" + Else + e.Row.FCButton("BtnSerieLote").Visible = False + e.Row.FCTextBox("TbCantidad").Enabled = True + e.Row.FCTextBox("TbCantidad").Attributes.Add("onblur", String.Format("ValidarCantidad(this,{0})", e.Row.DBCampo("Cantidad"))) + End If + + 'SIEMPRE ENABLED FALSE + e.Row.FCCheckBox("cbInv").Enabled = False + + 'si ya hay cargada una compra + If CveCompra > 0 AndAlso CveMovimientoAlmacen > 0 Then + If e.Row.DBCampo("AlmacenRegistrado").ToString = "1" Then + e.Row.FCCheckBox("cbInv").Checked = True + End If + e.Row.FCCheckBox("cbInv").Enabled = False + End If + + 'CONSIGNACIONES + If ChkConsignacion.Checked Then + e.Row.FCTextBox("TbCantidad").Enabled = False + e.Row.FCCheckBox("cbInv").Enabled = False + + If Not OCVinculada Then + e.Row.Cells(3).Text = e.Row.DBCampo("PSCodigo").ToString + End If + + Else + If e.Row.DBCampo("CveMetodoInventario").ToString = "5" Then + e.Row.FCTextBox("TbCantidad").Enabled = False + Else + e.Row.FCTextBox("TbCantidad").Enabled = True + End If + + e.Row.FCCheckBox("cbInv").Enabled = False + End If + + If UsuarioActual.Empresa.UsaAC Then + e.Row.FCCheckBox("cbInv").Enabled = False + End If + + e.Row.FCDropDownList("ddlEAlmacen").DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen IN (1,2,7,14,19)") 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) + e.Row.FCDropDownList("ddlEAlmacen").Items.Insert(0, New ListItem("Seleccione", "-1")) + e.Row.FCDropDownList("ddlEAlmacen").DataBind() + 'e.Row.FCDropDownList("ddlEAlmacen").SelectedValue = If(e.Row.DBCampo("CveAlmacen").ToEntero <= 0, "-1", e.Row.DBCampo("CveAlmacen")) + If UsuarioActual.Empresa.UsaAC Then e.Row.FCDropDownList("ddlEAlmacen").Enabled = False + + If Not e.Row.DBCampo("CveMetodoInventario").ToString = "5" Then + e.Row.FCTextBox("TbCantidad").Attributes.Add("onblur", String.Format("ValidarCantidad(this,{0})", If(e.Row.DBCampo("CantidadF").ToString.ToDecimal > e.Row.DBCampo("Cantidad").ToString.ToDecimal, e.Row.DBCampo("Cantidad"), e.Row.DBCampo("CantidadF")))) + e.Row.FCTextBox("TbCantidad").Text = If(e.Row.DBCampo("CantidadF").ToString.ToDecimal > e.Row.DBCampo("Cantidad").ToString.ToDecimal, e.Row.DBCampo("Cantidad"), e.Row.DBCampo("CantidadF")) + End If + + 'e.Row.FCImageButton("btnImgDestino").Attributes.Add("onclick", "javascript:$('#DivAlmacen').show(500); PosicionaObjeto(this.id,'DivAlmacen'); CargarValores('" & e.Row.RowIndex & "','" & e.Row.DBCampo("Cantidad") & "','" & e.Row.DBCampo("PS").Replace("'", "\'") & "'); ") + ' e.Row.FCImageButton("btnImgDestino").ID = e.Row.FCImageButton("btnImgDestino").ID.ToString + e.Row.RowIndex.ToString + 'e.Row.Cells(6).ToolTip = "Enviar a otro Almacén." + + If e.Row.DBCampo("Consec").ToEntero = 0 Then + e.Row.BackColor = Drawing.Color.PaleGreen + End If + + If UsuarioActual.CveEmpresa = 66 Then + e.Row.FCDropDownList("DdlRecibirInv").Items.RemoveAt(1) + End If + + 'If isAlmacenistaGluyas() Then + ' Dim dt As DataTable = Nothing + ' dt = GlobalDTProductosServicios(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoPS=2", "PS") + ' e.Row.FCDropDownList("Ddlnewps").DataSource = dt 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) + ' e.Row.FCDropDownList("Ddlnewps").DataBind() + ' e.Row.FCDropDownList("Ddlnewps").Items.Insert(0, New ListItem("Seleccione", "-1")) + ' dt.Dispose() + 'End If + + 'Consignaciones + If CveConsignacion > 0 Then + ''CARGA ALMACEN CONSIGNACION + e.Row.FCDropDownList("ddlAlmacenConsignacion").DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 4) + e.Row.FCDropDownList("ddlAlmacenConsignacion").DataBind() + + If e.Row.DBCampo("CveAlmacenConsignacion").ToEntero > 0 Then + e.Row.FCDropDownList("ddlAlmacenConsignacion").SelectedValueExist(e.Row.DBCampo("CveAlmacenConsignacion")) + End If + + ''CARGA CONSIGNACIONES + e.Row.FCDropDownList("DdlVinculaConsignacion").DataSource = DtConsignaciones.FiltraParametros(String.Format("CveAlmacenSalida = {0} OR {0} = '-1'", e.Row.FCDropDownList("ddlAlmacenConsignacion").SelectedValue)) + e.Row.FCDropDownList("DdlVinculaConsignacion").DataBind() + e.Row.FCDropDownList("DdlVinculaConsignacion").Items.Insert(0, New ListItem("Seleccione", "-1")) + + If e.Row.DBCampo("NoConsignacion").ToEntero > 0 Then + e.Row.FCDropDownList("DdlVinculaConsignacion").SelectedValueExist(e.Row.DBCampo("NoConsignacion")) + e.Row.FCHiddenField("HdnNoConsignacion").Value = e.Row.DBCampo("NoConsignacion") + End If + + If e.Row.DBCampo("CveConsignacion").ToEntero > 0 Then + e.Row.FCHiddenField("HdnCveConsignacion").Value = e.Row.DBCampo("CveConsignacion") + e.Row.FCHiddenField("HdnPS").Value = e.Row.DBCampo("HdnPS") + e.Row.FCHiddenField("HdnCvePS").Value = e.Row.DBCampo("HdnCvePS") + e.Row.FCHiddenField("HdnClasificacion").Value = e.Row.DBCampo("HdnClasificacion") + e.Row.FCHiddenField("HdnCveClasificacion").Value = e.Row.DBCampo("HdnCveClasificacion") + e.Row.FCHiddenField("HdnCveAlmacen").Value = e.Row.DBCampo("HdnCveAlmacen") + End If + + e.Row.FCTextBox("TxtDividir").Visible = True + Else + e.Row.FCTextBox("TxtDividir").Visible = False + End If + + If Not UsuarioActual.Empresa.UsaAC Then + + + e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("FormatoMoneda(this);LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCButton("BtnDividirCompra").ClientID)) + + e.Row.FCTextBox("TxtDividir").Text = "" + If e.Row.DBCampo("Cantidad").ToDouble > 0.02 Then + e.Row.FCButton("BtnDividirCompra").CommandArgument = e.Row.RowIndex.ToString + Else + e.Row.FCButton("BtnDividirCompra").Visible = False + e.Row.FCTextBox("TxtDividir").Visible = False + End If + End If + + End If + + 'HEADER GvInv + If e.Row.RowType = DataControlRowType.Header Then + Dim StrAlmacenes As String = "CveTipoAlmacen IN (1,2,7,14,19)" + + If UsuarioActual.CveUsuario.Contiene(1397, 1517, 1565) Then ' iliana, horacio, marco, RMF. 2017.03.13 + StrAlmacenes = "CveTipoAlmacen IN (1,2,7,14,12,19)" + End If + e.Row.FCDropDownList("ddlAlmacen").DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros(StrAlmacenes) 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) + e.Row.FCDropDownList("ddlAlmacen").Items.Insert(0, New ListItem("Seleccione", "-1")) + e.Row.FCDropDownList("ddlAlmacen").DataBind() + + 'si ya hay cargada una compra + If CveCompra > 0 AndAlso CveMovimientoAlmacen > 0 Then + e.Row.FCCheckBox("cbAll").Enabled = False + End If + + ''CARGA ALMACEN CONSIGNACION + e.Row.FCDropDownList("ddlAlmacenConsignacionGeneral").DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 4) + e.Row.FCDropDownList("ddlAlmacenConsignacionGeneral").DataBind() + End If + + End Sub + + Protected Sub ddlAlmacen_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) + Dim Ddl As DropDownList = CType(sender, DropDownList) + + For i As Integer = 0 To GvInv.Rows.Count - 1 + GvInv.Rows(i).FCDropDownList("ddlEAlmacen").SelectedValue = Ddl.SelectedValue + Next + + InicializaCargaEvidenciaAlmacen() + + End Sub + 'Protected Sub btnAgregarEq_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click + + + ' Dim eq As New ClsProductosServicios + ' Dim Unidad As String = TmpDT.Rows.Item(HdnEq.Value.ToEntero)("UM").ToString + ' Dim CvePS As Integer = TmpDT.Rows.Item(HdnEq.Value.ToEntero)("CvePS").ToString.ToEntero + ' Dim CveUM As Integer = TmpDT.Rows.Item(HdnEq.Value.ToEntero)("CveUM").ToString.ToEntero + ' Dim PU As Double = TmpDT.Rows.Item(HdnEq.Value.ToEntero)("PU").ToString.ToDouble + + ' Dim tCve As Integer = 0 + ' Dim ErrorUM As Boolean = False + + ' If UsuarioActual.Empresa.UsaInventarios And CveUM = 0 Then + ' Dim UM As New ClsUnidadesMedida + ' tCve = UM.AddUnidadMedida(TmpDT.Rows.Item(HdnEq.Value.ToEntero)("UM").ToString, TmpDT.Rows.Item(HdnEq.Value.ToEntero)("UM").ToString, "", "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1) + + ' If tCve > 0 Then + ' TmpDT.Rows.Item(HdnEq.Value.ToEntero)("CveUM") = tCve + ' Else + ' ErrorUM = True + ' End If + + + ' End If + + ' If Not ErrorUM Then + + ' If eq.AddPSEquivalencias(CvePS, CveUM, txtCantidadEq.Text.ToDecimal, False, PU, UsuarioActual.CveUsuario) Then + ' TmpDT.Rows.Item(HdnEq.Value.ToEntero)("CveEq") = 1 + + ' End If + + + ' End If + + + ' GvPS.DataSource = TmpDT + ' GvPS.DataBind() + + ' eq.Dispose() + + ' txtCantidadEq.Text = "" + 'End Sub + + + 'Protected Sub Enviar_Click(sender As Object, e As ImageClickEventArgs) Handles ImgAdd.Click + + ' If TbCantidadAlm.Text.ToDouble < DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("Cantidad").ToString.ToDouble And TbCantidadAlm.Text.ToDouble > 0 Then + + ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("Cantidad") = DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("Cantidad").ToString.ToDouble - TbCantidadAlm.Text.ToDouble + ' AddDTEnvio(TbCantidadAlm.Text.ToDouble, + ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("UM").ToString, + ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CveUM").ToString.ToEntero, + ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CvePS").ToString().ToEntero, + ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("PS").ToString, + ' DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("PU").ToString.ToDouble, + ' ddlAlmacenAdd.SelectedValue.ToEntero, DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CveEq").ToString.ToEntero) + + + ' Else + ' Alert("El campo cantidad es necesario que sea mayor que 0 y menor al registro seleccionado.") + + + ' End If + + ' TbCantidadAlm.Text = "" + ' ddlAlmacenAdd.SelectedIndex = 0 + ' UpINV.Update() + + ' ' Alert(TmpDT.Rows.Count.ToString) + + + + 'End Sub + + + Protected Sub cbAll_CheckedChanged(sender As Object, e As EventArgs) + For i As Integer = 0 To GvInv.Rows.Count - 1 + GvInv.Rows(i).FCCheckBox("cbInv").Checked = GvInv.HeaderRow.FCCheckBox("cbAll").Checked + Next + CalculaTotalPorDevengar() + End Sub + + Private Sub InicializaCargaEvidenciaAlmacen() + + TableAlmacenEvidencia.Visible = False + + If UsuarioActual.CveEmpresa = 13 Then + If GvInv.Rows.Count > 0 AndAlso GvInv.HeaderRow().FCDropDownList("ddlAlmacen").SelectedValue.ToEntero > 0 Then + Dim DrAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", GvInv.HeaderRow().FCDropDownList("ddlAlmacen").SelectedValue.ToEntero)) + If DrAlmacen("CveTipoAlmacen").ToString = "7" Then + TableAlmacenEvidencia.Visible = True + End If + End If + End If + + UpAlmacenEvidencia.Update() + + End Sub +#End Region + +#Region "PESTAÑA INFORMACION GENERAL DE BANCO IE" + + Private Sub CargaTipoTransaccion() + DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs'") + DdlTipoTransaccion.DataBind() + DdlTipoTransaccion.Items.Insert(0, New ListItem("Seleccione Tipo Movimiento", "-1")) + + DdlTipoTransaccionCaja.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs'") + DdlTipoTransaccionCaja.DataBind() + DdlTipoTransaccionCaja.Items.Insert(0, New ListItem("Seleccione Tipo Movimiento", "-1")) + End Sub + + Private Sub CargaCuentas() + DdlCuenta.Items.Clear() + DdlCuenta.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros(String.Format("CveTipoCuenta <> 1")) + DdlCuenta.DataBind() + DdlCuenta.Items.Insert(0, New ListItem("Seleccione", "-1")) + + DdlCuentaCaja.Items.Clear() + DdlCuentaCaja.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros(String.Format("CveTipoCuenta = 1")) + DdlCuentaCaja.DataBind() + DdlCuentaCaja.Items.Insert(0, New ListItem("Seleccione", "-1")) + End Sub + +#End Region + +#Region "FINANCIAMIENTO - AC" 'Private Sub CreaDtAC() ' DtAC = New DataTable ' DtAC.Columns.Add("IdCuenta", GetType(String)) @@ -11530,418 +11668,418 @@ Partial Class Compras_Compras ' End If 'End Sub -#End Region +#End Region + +#Region "TAB - PERSONAL" + Private Sub CargaGvPersonal() + GvPersonal.DataSource = TmpDT + GvPersonal.DataBind() + UpGvPersonal.Update() + + End Sub + + Protected Sub DdlProyectoPersonal_SelectedIndexChanged(sender As Object, e As EventArgs) + Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, DropDownList)).NamingContainer, GridViewRow) + Dim CveProyecto = If(gvRow.FCDropDownList("DdlProyectoPersonal").SelectedValue.ToEntero > 0, gvRow.FCDropDownList("DdlProyectoPersonal").SelectedValue.ToEntero, -1) + gvRow.FCDropDownList("DdlSubProyectoPersonal").Items.Clear() + If CveProyecto > 0 Or UsuarioActual.Empresa.Tipo_CentroCosto.Contiene(1, 2) Then + gvRow.FCDropDownList("DdlSubProyectoPersonal").DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, CveProyecto, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(CveProyecto, -1, UsuarioActual.CveEmpresa, 1)) + End If + gvRow.FCDropDownList("DdlSubProyectoPersonal").DataBind() + gvRow.FCDropDownList("DdlSubProyectoPersonal").Items.Insert(0, New ListItem("Seleccione", "-1")) + End Sub + + Protected Sub DdlSubProyectoPersonal_SelectedIndexChanged(sender As Object, e As EventArgs) + Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, DropDownList)).NamingContainer, GridViewRow) + Dim CveProyecto = If(gvRow.FCDropDownList("DdlProyectoPersonal").SelectedValue.ToEntero > 0, gvRow.FCDropDownList("DdlProyectoPersonal").SelectedValue.ToEntero, -1) + Dim CveSubProyecto = If(gvRow.FCDropDownList("DdlSubProyectoPersonal").SelectedValue.ToEntero > 0, gvRow.FCDropDownList("DdlSubProyectoPersonal").SelectedValue.ToEntero, -1) + Dim dr1 As DataRow = TmpDT.Rows(gvRow.RowIndex) + dr1("CveProyecto") = CveProyecto + dr1("CveSubProyecto") = CveSubProyecto + dr1("Proyecto") = If(CveProyecto > 0, gvRow.FCDropDownList("DdlProyectoPersonal").SelectedItem.Text, "") + dr1("SubProyecto") = If(CveSubProyecto > 0, gvRow.FCDropDownList("DdlSubProyectoPersonal").SelectedItem.Text, "") + TmpDT.AcceptChanges() + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + End Sub + + Private Sub DdlPersonalHeader_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPersonalHeader.SelectedIndexChanged + For Each Gvr As GridViewRow In GvPersonal.Rows + Gvr.FCDropDownList("DdlPersonalGv").SelectedValue = DdlPersonalHeader.SelectedValue + Next + UpGvPersonal.Update() + End Sub + + Private Sub CargaDdlPersonal() + 'DdlPersonalGv.DataSource = GlobalDTRHPersonal(UsuarioActual.CveEmpresa) + 'DdlPersonalGv.DataBind() + + DdlPersonalHeader.DataSource = GlobalDTRHPersonal(UsuarioActual.CveEmpresa) + DdlPersonalHeader.DataBind() + UpGvPersonal.Update() + End Sub + + Private Sub GvPersonal_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvPersonal.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + e.Row.FCDropDownList("DdlPersonalGv").DataSource = GlobalDTRHPersonal(UsuarioActual.CveEmpresa) + e.Row.FCDropDownList("DdlPersonalGv").DataBind() + + If UsuarioActual.Empresa.Tipo_CentroCosto = 1 Or UsuarioActual.Empresa.Tipo_CentroCosto = 2 Then + e.Row.FCDropDownList("DdlSubProyectoPersonal").DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) + e.Row.FCDropDownList("DdlSubProyectoPersonal").Items.Insert(0, New ListItem("Seleccione", "-1")) + e.Row.FCDropDownList("DdlSubProyectoPersonal").DataBind() + e.Row.FCDropDownList("DdlProyectoPersonal").Visible = False + Else + e.Row.FCDropDownList("DdlProyectoPersonal").DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"}), GlobalDTProyectos(UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"})) + e.Row.FCDropDownList("DdlProyectoPersonal").Items.Insert(0, New ListItem("Seleccione", "-1")) + e.Row.FCDropDownList("DdlProyectoPersonal").DataBind() + e.Row.FCDropDownList("DdlProyectoPersonal").SelectedValueExist(e.Row.DBCampo("CveProyecto")) + If e.Row.DBCampo("CveProyecto").ToEntero > 0 Then + e.Row.FCDropDownList("DdlSubProyectoPersonal").DataSource = + If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), + GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, e.Row.DBCampo("CveProyecto").ToEntero, UsuarioActual.CveEmpresa, -1, 1), + GlobalDTSubProyectos(e.Row.DBCampo("CveProyecto").ToEntero, -1, UsuarioActual.CveEmpresa, 1)) + End If + e.Row.FCDropDownList("DdlSubProyectoPersonal").Items.Insert(0, New ListItem("Seleccione", "-1")) + e.Row.FCDropDownList("DdlSubProyectoPersonal").DataBind() + End If + e.Row.FCDropDownList("DdlSubProyectoPersonal").SelectedValueExist(e.Row.DBCampo("CveSubProyecto")) + + If CveCompra > 0 Then + If e.Row.DBCampo("CvePersonal").ToEntero <> -1 And e.Row.DBCampo("CvePersonal") <> Nothing Then + e.Row.FCDropDownList("DdlPersonalGv").SelectedValue = e.Row.DBCampo("CvePersonal") + End If + If e.Row.DBCampo("Referencia").ToString <> "" And e.Row.DBCampo("Referencia") <> Nothing Then + e.Row.FCTextBox("TxtReferencia").Text = e.Row.DBCampo("Referencia") + End If + e.Row.FCTextBox("TxtDividir").Enabled = False + End If + e.Row.FCLinkButton("BtnDividirPersonal").Attributes.Add("onclick", String.Format("DividirPersonal('{0}');", e.Row.FCTextBox("TxtDividir").ClientID)) + e.Row.FCLinkButton("BtnDividirPersonal").CommandArgument = e.Row.RowIndex.ToString + e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCLinkButton("BtnDividirPersonal").ClientID)) + + + End If + End Sub + + Protected Sub DividirPersonal(sender As Object, e As EventArgs) + Dim index2 As Integer = 0 + + For Each Row As DataRow In TmpDT.Rows + If GvPersonal.Rows(index2).FCTextBox("TxtReferencia").Text <> "" Then + Row("Referencia") = GvPersonal.Rows(index2).FCTextBox("TxtReferencia").Text + End If + If GvPersonal.Rows(index2).FCDropDownList("DdlPersonalGv").SelectedValue <> "-1" Then + Row("CvePersonal") = GvPersonal.Rows(index2).FCDropDownList("DdlPersonalGv").SelectedValue + End If + index2 += 1 + Next + + 'index2 = 0 + 'For Each Row As DataRow In TmpDT.Rows + ' If GvAFCompras.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then + ' Row("CveActivoFijo") = GvAFCompras.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero + ' Row("CodAF") = GvAFCompras.Rows(index2).FCHiddenField("HdnCodAF").Value.ToString + ' Row("TipoAF") = 1 + ' End If + ' index2 += 1 + 'Next + + 'Dim Index As Integer = CType(sender, LinkButton).CommandArgument.ToString.ToEntero + Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) + Dim Index As Integer = gvRow.RowIndex + Dim Cantidad As String = HdnCantidadPersonal.Value + Dim dr1 As DataRow = TmpDT.Rows(Index) + Dim dr As DataRow = TmpDT.NewRow + dr.ItemArray = dr1.ItemArray + dr1("Cantidad") = (dr1("Cantidad").ToString.ToDouble - Cantidad.ToDouble) + dr1("Total") = dr1("PU").ToString.ToDouble * dr1("Cantidad").ToString.ToDouble + dr1("IVA") = Math.Round(dr1("IVAPorcentaje").ToString.ToDouble * dr1("Total").ToString.ToDouble, 6) + + TmpDT.AcceptChanges() + + dr("CvePersonal") = 0 + dr("Referencia") = "" + dr("CveActivoFijo") = 0 + dr("CodAF") = 0 + dr("Cantidad") = Cantidad.ToDouble + dr("Total") = dr("PU").ToString.ToDouble * Cantidad.ToDouble + dr("IVA") = Math.Round(dr("IVAPorcentaje").ToString.ToDouble * dr("Total").ToString.ToDouble, 6) + TmpDT.Rows.InsertAt(dr, Index) + TmpDT.AcceptChanges() + + index2 = 0 + For Each Row As DataRow In TmpDT.Rows + Row("Consec") = index2 + index2 += 1 + Next + TmpDT.AcceptChanges() + + CargaGvPersonal() + + 'TmpDT = DtAFInsumos.Copy + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + 'Afecta GVINV y GvAF + CargaGvInv() + CargaGVsAF() + CalculaTotales(True) + + index2 = 0 + For Each Row As DataRow In TmpDT.Rows + If Row("Referencia").ToString <> "" Then + GvPersonal.Rows(index2).FCTextBox("TxtReferencia").Text = Row("Referencia").ToString + End If + If Row("CvePersonal").ToString <> "" Then + GvPersonal.Rows(index2).FCDropDownList("DdlPersonalGv").SelectedValue = Row("CvePersonal").ToString + End If + index2 += 1 + Next + -#Region "TAB - PERSONAL" - Private Sub CargaGvPersonal() - GvPersonal.DataSource = TmpDT - GvPersonal.DataBind() - UpGvPersonal.Update() - - End Sub - - Protected Sub DdlProyectoPersonal_SelectedIndexChanged(sender As Object, e As EventArgs) - Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, DropDownList)).NamingContainer, GridViewRow) - Dim CveProyecto = If(gvRow.FCDropDownList("DdlProyectoPersonal").SelectedValue.ToEntero > 0, gvRow.FCDropDownList("DdlProyectoPersonal").SelectedValue.ToEntero, -1) - gvRow.FCDropDownList("DdlSubProyectoPersonal").Items.Clear() - If CveProyecto > 0 Or UsuarioActual.Empresa.Tipo_CentroCosto.Contiene(1, 2) Then - gvRow.FCDropDownList("DdlSubProyectoPersonal").DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, CveProyecto, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(CveProyecto, -1, UsuarioActual.CveEmpresa, 1)) - End If - gvRow.FCDropDownList("DdlSubProyectoPersonal").DataBind() - gvRow.FCDropDownList("DdlSubProyectoPersonal").Items.Insert(0, New ListItem("Seleccione", "-1")) - End Sub - - Protected Sub DdlSubProyectoPersonal_SelectedIndexChanged(sender As Object, e As EventArgs) - Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, DropDownList)).NamingContainer, GridViewRow) - Dim CveProyecto = If(gvRow.FCDropDownList("DdlProyectoPersonal").SelectedValue.ToEntero > 0, gvRow.FCDropDownList("DdlProyectoPersonal").SelectedValue.ToEntero, -1) - Dim CveSubProyecto = If(gvRow.FCDropDownList("DdlSubProyectoPersonal").SelectedValue.ToEntero > 0, gvRow.FCDropDownList("DdlSubProyectoPersonal").SelectedValue.ToEntero, -1) - Dim dr1 As DataRow = TmpDT.Rows(gvRow.RowIndex) - dr1("CveProyecto") = CveProyecto - dr1("CveSubProyecto") = CveSubProyecto - dr1("Proyecto") = If(CveProyecto > 0, gvRow.FCDropDownList("DdlProyectoPersonal").SelectedItem.Text, "") - dr1("SubProyecto") = If(CveSubProyecto > 0, gvRow.FCDropDownList("DdlSubProyectoPersonal").SelectedItem.Text, "") - TmpDT.AcceptChanges() - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - End Sub - - Private Sub DdlPersonalHeader_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPersonalHeader.SelectedIndexChanged - For Each Gvr As GridViewRow In GvPersonal.Rows - Gvr.FCDropDownList("DdlPersonalGv").SelectedValue = DdlPersonalHeader.SelectedValue - Next - UpGvPersonal.Update() - End Sub - - Private Sub CargaDdlPersonal() - 'DdlPersonalGv.DataSource = GlobalDTRHPersonal(UsuarioActual.CveEmpresa) - 'DdlPersonalGv.DataBind() - - DdlPersonalHeader.DataSource = GlobalDTRHPersonal(UsuarioActual.CveEmpresa) - DdlPersonalHeader.DataBind() - UpGvPersonal.Update() - End Sub - - Private Sub GvPersonal_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvPersonal.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - e.Row.FCDropDownList("DdlPersonalGv").DataSource = GlobalDTRHPersonal(UsuarioActual.CveEmpresa) - e.Row.FCDropDownList("DdlPersonalGv").DataBind() - - If UsuarioActual.Empresa.Tipo_CentroCosto = 1 Or UsuarioActual.Empresa.Tipo_CentroCosto = 2 Then - e.Row.FCDropDownList("DdlSubProyectoPersonal").DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1)) - e.Row.FCDropDownList("DdlSubProyectoPersonal").Items.Insert(0, New ListItem("Seleccione", "-1")) - e.Row.FCDropDownList("DdlSubProyectoPersonal").DataBind() - e.Row.FCDropDownList("DdlProyectoPersonal").Visible = False - Else - e.Row.FCDropDownList("DdlProyectoPersonal").DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"}), GlobalDTProyectos(UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"})) - e.Row.FCDropDownList("DdlProyectoPersonal").Items.Insert(0, New ListItem("Seleccione", "-1")) - e.Row.FCDropDownList("DdlProyectoPersonal").DataBind() - e.Row.FCDropDownList("DdlProyectoPersonal").SelectedValueExist(e.Row.DBCampo("CveProyecto")) - If e.Row.DBCampo("CveProyecto").ToEntero > 0 Then - e.Row.FCDropDownList("DdlSubProyectoPersonal").DataSource = - If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), - GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, e.Row.DBCampo("CveProyecto").ToEntero, UsuarioActual.CveEmpresa, -1, 1), - GlobalDTSubProyectos(e.Row.DBCampo("CveProyecto").ToEntero, -1, UsuarioActual.CveEmpresa, 1)) - End If - e.Row.FCDropDownList("DdlSubProyectoPersonal").Items.Insert(0, New ListItem("Seleccione", "-1")) - e.Row.FCDropDownList("DdlSubProyectoPersonal").DataBind() - End If - e.Row.FCDropDownList("DdlSubProyectoPersonal").SelectedValueExist(e.Row.DBCampo("CveSubProyecto")) - - If CveCompra > 0 Then - If e.Row.DBCampo("CvePersonal").ToEntero <> -1 And e.Row.DBCampo("CvePersonal") <> Nothing Then - e.Row.FCDropDownList("DdlPersonalGv").SelectedValue = e.Row.DBCampo("CvePersonal") - End If - If e.Row.DBCampo("Referencia").ToString <> "" And e.Row.DBCampo("Referencia") <> Nothing Then - e.Row.FCTextBox("TxtReferencia").Text = e.Row.DBCampo("Referencia") - End If - e.Row.FCTextBox("TxtDividir").Enabled = False - End If - e.Row.FCLinkButton("BtnDividirPersonal").Attributes.Add("onclick", String.Format("DividirPersonal('{0}');", e.Row.FCTextBox("TxtDividir").ClientID)) - e.Row.FCLinkButton("BtnDividirPersonal").CommandArgument = e.Row.RowIndex.ToString - e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCLinkButton("BtnDividirPersonal").ClientID)) - - - End If - End Sub - - Protected Sub DividirPersonal(sender As Object, e As EventArgs) - Dim index2 As Integer = 0 - - For Each Row As DataRow In TmpDT.Rows - If GvPersonal.Rows(index2).FCTextBox("TxtReferencia").Text <> "" Then - Row("Referencia") = GvPersonal.Rows(index2).FCTextBox("TxtReferencia").Text - End If - If GvPersonal.Rows(index2).FCDropDownList("DdlPersonalGv").SelectedValue <> "-1" Then - Row("CvePersonal") = GvPersonal.Rows(index2).FCDropDownList("DdlPersonalGv").SelectedValue - End If - index2 += 1 - Next - - 'index2 = 0 - 'For Each Row As DataRow In TmpDT.Rows - ' If GvAFCompras.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then - ' Row("CveActivoFijo") = GvAFCompras.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero - ' Row("CodAF") = GvAFCompras.Rows(index2).FCHiddenField("HdnCodAF").Value.ToString - ' Row("TipoAF") = 1 - ' End If - ' index2 += 1 - 'Next - - 'Dim Index As Integer = CType(sender, LinkButton).CommandArgument.ToString.ToEntero - Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) - Dim Index As Integer = gvRow.RowIndex - Dim Cantidad As String = HdnCantidadPersonal.Value - Dim dr1 As DataRow = TmpDT.Rows(Index) - Dim dr As DataRow = TmpDT.NewRow - dr.ItemArray = dr1.ItemArray - dr1("Cantidad") = (dr1("Cantidad").ToString.ToDouble - Cantidad.ToDouble) - dr1("Total") = dr1("PU").ToString.ToDouble * dr1("Cantidad").ToString.ToDouble - dr1("IVA") = Math.Round(dr1("IVAPorcentaje").ToString.ToDouble * dr1("Total").ToString.ToDouble, 6) - - TmpDT.AcceptChanges() - - dr("CvePersonal") = 0 - dr("Referencia") = "" - dr("CveActivoFijo") = 0 - dr("CodAF") = 0 - dr("Cantidad") = Cantidad.ToDouble - dr("Total") = dr("PU").ToString.ToDouble * Cantidad.ToDouble - dr("IVA") = Math.Round(dr("IVAPorcentaje").ToString.ToDouble * dr("Total").ToString.ToDouble, 6) - TmpDT.Rows.InsertAt(dr, Index) - TmpDT.AcceptChanges() - - index2 = 0 - For Each Row As DataRow In TmpDT.Rows - Row("Consec") = index2 - index2 += 1 - Next - TmpDT.AcceptChanges() - - CargaGvPersonal() - - 'TmpDT = DtAFInsumos.Copy - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - 'Afecta GVINV y GvAF - CargaGvInv() - CargaGVsAF() - CalculaTotales(True) - - index2 = 0 - For Each Row As DataRow In TmpDT.Rows - If Row("Referencia").ToString <> "" Then - GvPersonal.Rows(index2).FCTextBox("TxtReferencia").Text = Row("Referencia").ToString - End If - If Row("CvePersonal").ToString <> "" Then - GvPersonal.Rows(index2).FCDropDownList("DdlPersonalGv").SelectedValue = Row("CvePersonal").ToString - End If - index2 += 1 - Next - - End Sub -#End Region +#End Region -#Region "TAB - ACTIVOS FIJOS -AF" - Protected Sub CargarGvActivosFijos(sender As Object, e As EventArgs) - TAB.ActiveTabIndex = 3 - - If GvAFInsumos.Rows.Count > 0 Then - llenaDtsAF() - End If - - CargaGVsAF() - End Sub - Protected Sub llenaDtsAF() - Dim index As Integer = 0 - For Each Row As DataRow In TmpDT.Rows - If Row("TipoAF").ToString.ToEntero = 1 AndAlso GvAFInsumos.Rows(index).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then - Row("CveActivoFijo") = GvAFInsumos.Rows(index).FCHiddenField("HdnCveAF").Value.ToEntero - Row("CodAF") = If(GvAFInsumos.Rows(index).FCHiddenField("HdnCodAF").Value.ToString = "", "SN", GvAFInsumos.Rows(index).FCHiddenField("HdnCodAF").Value.ToString) - 'Row("TipoAF") = 1 - End If - index += 1 - Next - index = 0 - For Each Row As DataRow In TmpDT.Rows - If Row("TipoAF").ToString.ToEntero = 2 AndAlso GvAFCompras.Rows(index).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then - Row("CveActivoFijo") = GvAFCompras.Rows(index).FCHiddenField("HdnCveAF").Value.ToEntero - Row("CodAF") = If(GvAFCompras.Rows(index).FCHiddenField("HdnCodAF").Value.ToString = "", "SN", GvAFCompras.Rows(index).FCHiddenField("HdnCodAF").Value.ToString) - 'Row("TipoAF") = 2 - End If - index += 1 - Next - End Sub - Private Sub CargaGVsAF() - GvAFInsumos.DataSource = TmpDT - GvAFInsumos.DataBind() - UPDatosAFInsumos.Update() - - GvAFCompras.DataSource = TmpDT - GvAFCompras.DataBind() - UPDatosAFCompras.Update() - End Sub - Protected Sub GvAFCompras_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvAFCompras.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - Dim SinValor = True - - If e.Row.DBCampo("TipoAF").ToEntero = 2 Then - If e.Row.DBCampo("CveActivoFijo").ToEntero > 0 Then - e.Row.FCTextBox("LblCodigo").Text = e.Row.DBCampo("CodAF").ToString - e.Row.FCHiddenField("HdnCveAF").Value = e.Row.DBCampo("CveActivoFijo").ToString - e.Row.FCHiddenField("HdnCodAF").Value = e.Row.DBCampo("CodAF").ToString - SinValor = False - End If - End If - - If SinValor Then - e.Row.FCTextBox("LblCodigo").Text = "" - e.Row.FCHiddenField("HdnCveAF").Value = "0" - e.Row.FCHiddenField("HdnCodAF").Value = "0" - End If - - 'e.Row.FCButton("BtnDividirInsumo").Attributes.Add("onclick", String.Format("DividirInsumo('{0}');", e.Row.FCTextBox("TxtDividir").ClientID)) - 'e.Row.FCButton("BtnDividirInsumo").CommandArgument = e.Row.RowIndex.ToString - - e.Row.FCHiddenField("HdnIndex").Value = e.Row.RowIndex.ToString - e.Row.FCHyperLink("HLBuscarAF").Attributes.Add("onclick", String.Format("LimpiaAF(2, '{0}');", e.Row.FCHiddenField("HdnCveConcepto").Value)) - e.Row.FCHyperLink("HLBuscarAF").NavigateUrl = String.Format("javascript:AbrirVentana('/AF/PopUpBuscarAF.aspx?L={0}&H1={1}&H2={2}',730,450,'N');", e.Row.FCTextBox("LblCodigo").ClientID, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID) - 'e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCButton("BtnDividirInsumo").ClientID)) - - e.Row.FCTextBox("LblCodigo").Attributes.Add("onkeyup", String.Format("LimpiaAF(2, '{0}'); EnterAFEdit(event,this,{1},{2},{3});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID, e.Row.RowIndex.ToString)) - e.Row.FCTextBox("LblCodigo").Attributes.Add("onblur", String.Format("LimpiaAF(2, '{0}'); AFBlurEdit(this,{1},{2},{3});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID, e.Row.RowIndex.ToString)) - End If - End Sub - Protected Sub GvAFInsumos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvAFInsumos.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - Dim SinValor = True - - If e.Row.DBCampo("TipoAF").ToEntero = 1 Then - If e.Row.DBCampo("CveActivoFijo").ToEntero > 0 Then - e.Row.FCTextBox("LblCodigo").Text = e.Row.DBCampo("CodAF").ToString - e.Row.FCLabel("LblValido").Attributes("display") = "" - e.Row.FCHiddenField("HdnCveAF").Value = e.Row.DBCampo("CveActivoFijo").ToString - e.Row.FCHiddenField("HdnCodAF").Value = e.Row.DBCampo("CodAF").ToString - SinValor = False - End If - End If - - If SinValor Then - e.Row.FCTextBox("LblCodigo").Text = "" - e.Row.FCHiddenField("HdnCveAF").Value = "0" - e.Row.FCHiddenField("HdnCodAF").Value = "0" - e.Row.FCLabel("LblValido").Attributes("display") = "none" - End If - - If e.Row.DBCampo("AFTipoMantenimiento").ToEntero > 0 Then - e.Row.FCDropDownList("DdlTipoMantemiento").SelectedValueExist(e.Row.DBCampo("AFTipoMantenimiento")) - - End If - e.Row.FCButton("BtnDividirInsumo").Attributes.Add("onclick", String.Format("DividirInsumo('{0}');", e.Row.FCTextBox("TxtDividir").ClientID)) - e.Row.FCButton("BtnDividirInsumo").CommandArgument = e.Row.RowIndex.ToString - - e.Row.FCHiddenField("HdnIndex").Value = e.Row.RowIndex.ToString - e.Row.FCHyperLink("HLBuscarAF").Attributes.Add("onclick", String.Format("LimpiaAF(1, '{0}');", e.Row.FCHiddenField("HdnCveConcepto").Value)) - e.Row.FCHyperLink("HLBuscarAF").NavigateUrl = String.Format("javascript:AbrirVentana('/AF/PopUpBuscarAF.aspx?L={0}&H1={1}&H2={2}',730,450,'N');", e.Row.FCTextBox("LblCodigo").ClientID, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID) - e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCButton("BtnDividirInsumo").ClientID)) - - e.Row.FCTextBox("LblCodigo").Attributes.Add("onkeyup", String.Format("LimpiaAF(1, '{0}'); EnterAFEdit(event,this,{1},{2},{3});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID, e.Row.RowIndex.ToString)) - e.Row.FCTextBox("LblCodigo").Attributes.Add("onblur", String.Format("LimpiaAF(1, '{0}'); AFBlurEdit(this,{1},{2},{3});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID, e.Row.RowIndex.ToString)) - - e.Row.FCTextBox("TxtAFMedida").Attributes.Add("onblur", String.Format("AFInsumosMedida(this,{0});", e.Row.RowIndex)) - - - End If - End Sub - Protected Sub BtnLimpiaAF_Click(sender As Object, e As EventArgs) - LimpiaAF(HdnTipoAF.Value.ToEntero, HdnCveConceptoAF.Value) - End Sub - Protected Sub LimpiaAF(TipoCompra As Integer, CveConcepto As String) - llenaDtsAF() - - For Each Row As DataRow In TmpDT.Rows - If Row("CveConcepto").ToString = CveConcepto Then - Row("TipoAF") = TipoCompra - End If - Next - TmpDT.AcceptChanges() - - llenaDtsAF() - CargaGVsAF() - End Sub - Protected Sub DivirInsumo(sender As Object, e As EventArgs) - Dim index2 As Integer = 0 - - 'LLena el AF vinculado para no perderlo - For Each Row As DataRow In TmpDT.Rows - If GvAFInsumos.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then - Row("CveActivoFijo") = GvAFInsumos.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero - Row("CodAF") = GvAFInsumos.Rows(index2).FCHiddenField("HdnCodAF").Value.ToString - Row("TipoAF") = 1 - End If - index2 += 1 - Next - - index2 = 0 - For Each Row As DataRow In TmpDT.Rows - If GvAFCompras.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then - Row("CveActivoFijo") = GvAFCompras.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero - Row("CodAF") = GvAFCompras.Rows(index2).FCHiddenField("HdnCodAF").Value.ToString - Row("TipoAF") = 1 - End If - index2 += 1 - Next - - Dim Index As Integer = CType(sender, Button).CommandArgument.ToString.ToEntero - Dim Cantidad As String = HdnCantidadInsumo.Value - Dim dr1 As DataRow = TmpDT.Rows(Index) - Dim dr As DataRow = TmpDT.NewRow - dr.ItemArray = dr1.ItemArray - - dr1("Cantidad") = (dr1("Cantidad").ToString.ToDouble - Cantidad.ToDouble) - dr1("Total") = dr1("PU").ToString.ToDouble * dr1("Cantidad").ToString.ToDouble - dr1("IVA") = Math.Round(dr1("IVAPorcentaje").ToString.ToDouble * dr1("Total").ToString.ToDouble, 6) - TmpDT.AcceptChanges() - - - dr("CveActivoFijo") = 0 - dr("CodAF") = "" - dr("Cantidad") = Cantidad.ToDouble - dr("Total") = dr("PU").ToString.ToDouble * Cantidad.ToDouble - dr("IVA") = Math.Round(dr("IVAPorcentaje").ToString.ToDouble * dr("Total").ToString.ToDouble, 6) - - TmpDT.Rows.InsertAt(dr, Index + 1) - - For Index = 0 To TmpDT.Rows.Count - 1 - TmpDT.Rows(Index)("Consec") = Index + 1 - Next - - CargaGVsAF() - - 'TmpDT = DtAFInsumos.Copy - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - 'Afecta GVINV - CargaGvInv() - - CargaGvPersonal() - End Sub - Protected Sub BtnVinculaAFEdit_Click(sender As Object, e As EventArgs) - Dim ObjAF As New ClsAF - Dim Index As Integer = HdnIndexTmpDT.Value.ToEntero() - If ObjAF.GetActivosFijos(-1, UsuarioActual.CveEmpresa, HdnCodAFEdit.Value, "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "", -1, UsuarioActual.CveEmpresa) Then - If ObjAF.DtResultados.Rows.Count = 1 Then - 'VERIFICAR QUE EL ACTIVO FIJO ESTE ACTIVO. que no este en baja, inactivo. - If HdnTipoAF.Value.ToEntero = 1 Then - GvAFInsumos.Rows(Index).FCHiddenField("HdnCveAF").Value = ObjAF.DtResultados.Rows(0)("CveActivoFijo").ToString - GvAFInsumos.Rows(Index).FCHiddenField("HdnCodAF").Value = ObjAF.DtResultados.Rows(0)("Codigo").ToString - RegistraScript(String.Format("MuestraCheckAF('{0}','');", GvAFInsumos.Rows(Index).FCLabel("LblValido").ClientID), "A2") - ElseIf HdnTipoAF.Value.ToEntero = 2 Then - GvAFCompras.Rows(Index).FCHiddenField("HdnCveAF").Value = ObjAF.DtResultados.Rows(0)("CveActivoFijo").ToString - GvAFCompras.Rows(Index).FCHiddenField("HdnCodAF").Value = ObjAF.DtResultados.Rows(0)("Codigo").ToString - RegistraScript(String.Format("MuestraCheckAF('{0}','');", GvAFCompras.Rows(Index).FCLabel("LblValido").ClientID), "A2") - End If - 'COMENTADO IPP 15 JUNIO 2017 - 'RegistraScript(String.Format("EnterAFEditOK('{0}','{1}');", ObjAF.DtResultados.Rows(0)("CveActivoFijo").ToString, ObjAF.DtResultados.Rows(0)("Codigo").ToString)) - LimpiaAF(HdnTipoAF.Value.ToEntero, HdnCveConceptoAF.Value) - Else - If HdnTipoAF.Value.ToEntero = 1 Then - GvAFInsumos.Rows(Index).FCHiddenField("HdnCveAF").Value = "-1" - GvAFInsumos.Rows(Index).FCHiddenField("HdnCodAF").Value = "-1" - RegistraScript(String.Format("MuestraCheckAF('{0}','none');", GvAFInsumos.Rows(Index).FCLabel("LblValido").ClientID), "A2") - ElseIf HdnTipoAF.Value.ToEntero = 2 Then - GvAFCompras.Rows(Index).FCHiddenField("HdnCveAF").Value = "-1" - GvAFCompras.Rows(Index).FCHiddenField("HdnCodAF").Value = "-1" - RegistraScript(String.Format("MuestraCheckAF('{0}','none');", GvAFCompras.Rows(Index).FCLabel("LblValido").ClientID), "A2") - End If - - Alert("No se encontró un Activo Fijo con el código proporcionado.", TipoMensaje.MsgAdvertencia) - End If - End If - - ObjAF.Dispose() - End Sub - Protected Sub DdlTipoMantemiento_SelectedIndexChanged(sender As Object, e As EventArgs) - Dim dr = TmpDT.Rows(CType(CType(sender, DropDownList).NamingContainer, GridViewRow).RowIndex) - - dr("AFTipoMantenimiento") = CType(CType(sender, DropDownList).NamingContainer, GridViewRow).FCDropDownList("DdlTipoMantemiento").SelectedValue.ToEntero - - End Sub - Protected Sub BtnAFMedida_Click(sender As Object, e As EventArgs) - TmpDT(HdnIndexTmpDT.Value.ToEntero)("AFMedida") = HdnTxtAFMedida.Value +#Region "TAB - ACTIVOS FIJOS -AF" + Protected Sub CargarGvActivosFijos(sender As Object, e As EventArgs) + Tab.ActiveTabIndex = 3 + + If GvAFInsumos.Rows.Count > 0 Then + llenaDtsAF() + End If + + CargaGVsAF() End Sub -#End Region + Protected Sub llenaDtsAF() + Dim index As Integer = 0 + For Each Row As DataRow In TmpDT.Rows + If Row("TipoAF").ToString.ToEntero = 1 AndAlso GvAFInsumos.Rows(index).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then + Row("CveActivoFijo") = GvAFInsumos.Rows(index).FCHiddenField("HdnCveAF").Value.ToEntero + Row("CodAF") = If(GvAFInsumos.Rows(index).FCHiddenField("HdnCodAF").Value.ToString = "", "SN", GvAFInsumos.Rows(index).FCHiddenField("HdnCodAF").Value.ToString) + 'Row("TipoAF") = 1 + End If + index += 1 + Next + index = 0 + For Each Row As DataRow In TmpDT.Rows + If Row("TipoAF").ToString.ToEntero = 2 AndAlso GvAFCompras.Rows(index).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then + Row("CveActivoFijo") = GvAFCompras.Rows(index).FCHiddenField("HdnCveAF").Value.ToEntero + Row("CodAF") = If(GvAFCompras.Rows(index).FCHiddenField("HdnCodAF").Value.ToString = "", "SN", GvAFCompras.Rows(index).FCHiddenField("HdnCodAF").Value.ToString) + 'Row("TipoAF") = 2 + End If + index += 1 + Next + End Sub + Private Sub CargaGVsAF() + GvAFInsumos.DataSource = TmpDT + GvAFInsumos.DataBind() + UPDatosAFInsumos.Update() -#Region "C O N T R A T O S" + GvAFCompras.DataSource = TmpDT + GvAFCompras.DataBind() + UPDatosAFCompras.Update() + End Sub + Protected Sub GvAFCompras_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvAFCompras.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + Dim SinValor = True + + If e.Row.DBCampo("TipoAF").ToEntero = 2 Then + If e.Row.DBCampo("CveActivoFijo").ToEntero > 0 Then + e.Row.FCTextBox("LblCodigo").Text = e.Row.DBCampo("CodAF").ToString + e.Row.FCHiddenField("HdnCveAF").Value = e.Row.DBCampo("CveActivoFijo").ToString + e.Row.FCHiddenField("HdnCodAF").Value = e.Row.DBCampo("CodAF").ToString + SinValor = False + End If + End If + + If SinValor Then + e.Row.FCTextBox("LblCodigo").Text = "" + e.Row.FCHiddenField("HdnCveAF").Value = "0" + e.Row.FCHiddenField("HdnCodAF").Value = "0" + End If + + 'e.Row.FCButton("BtnDividirInsumo").Attributes.Add("onclick", String.Format("DividirInsumo('{0}');", e.Row.FCTextBox("TxtDividir").ClientID)) + 'e.Row.FCButton("BtnDividirInsumo").CommandArgument = e.Row.RowIndex.ToString + + e.Row.FCHiddenField("HdnIndex").Value = e.Row.RowIndex.ToString + e.Row.FCHyperLink("HLBuscarAF").Attributes.Add("onclick", String.Format("LimpiaAF(2, '{0}');", e.Row.FCHiddenField("HdnCveConcepto").Value)) + e.Row.FCHyperLink("HLBuscarAF").NavigateUrl = String.Format("javascript:AbrirVentana('/AF/PopUpBuscarAF.aspx?L={0}&H1={1}&H2={2}',730,450,'N');", e.Row.FCTextBox("LblCodigo").ClientID, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID) + 'e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCButton("BtnDividirInsumo").ClientID)) + + e.Row.FCTextBox("LblCodigo").Attributes.Add("onkeyup", String.Format("LimpiaAF(2, '{0}'); EnterAFEdit(event,this,{1},{2},{3});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID, e.Row.RowIndex.ToString)) + e.Row.FCTextBox("LblCodigo").Attributes.Add("onblur", String.Format("LimpiaAF(2, '{0}'); AFBlurEdit(this,{1},{2},{3});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID, e.Row.RowIndex.ToString)) + End If + End Sub + Protected Sub GvAFInsumos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvAFInsumos.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + Dim SinValor = True + + If e.Row.DBCampo("TipoAF").ToEntero = 1 Then + If e.Row.DBCampo("CveActivoFijo").ToEntero > 0 Then + e.Row.FCTextBox("LblCodigo").Text = e.Row.DBCampo("CodAF").ToString + e.Row.FCLabel("LblValido").Attributes("display") = "" + e.Row.FCHiddenField("HdnCveAF").Value = e.Row.DBCampo("CveActivoFijo").ToString + e.Row.FCHiddenField("HdnCodAF").Value = e.Row.DBCampo("CodAF").ToString + SinValor = False + End If + End If + + If SinValor Then + e.Row.FCTextBox("LblCodigo").Text = "" + e.Row.FCHiddenField("HdnCveAF").Value = "0" + e.Row.FCHiddenField("HdnCodAF").Value = "0" + e.Row.FCLabel("LblValido").Attributes("display") = "none" + End If + + If e.Row.DBCampo("AFTipoMantenimiento").ToEntero > 0 Then + e.Row.FCDropDownList("DdlTipoMantemiento").SelectedValueExist(e.Row.DBCampo("AFTipoMantenimiento")) + + End If + e.Row.FCButton("BtnDividirInsumo").Attributes.Add("onclick", String.Format("DividirInsumo('{0}');", e.Row.FCTextBox("TxtDividir").ClientID)) + e.Row.FCButton("BtnDividirInsumo").CommandArgument = e.Row.RowIndex.ToString + + e.Row.FCHiddenField("HdnIndex").Value = e.Row.RowIndex.ToString + e.Row.FCHyperLink("HLBuscarAF").Attributes.Add("onclick", String.Format("LimpiaAF(1, '{0}');", e.Row.FCHiddenField("HdnCveConcepto").Value)) + e.Row.FCHyperLink("HLBuscarAF").NavigateUrl = String.Format("javascript:AbrirVentana('/AF/PopUpBuscarAF.aspx?L={0}&H1={1}&H2={2}',730,450,'N');", e.Row.FCTextBox("LblCodigo").ClientID, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID) + e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("Cantidad"), e.Row.FCButton("BtnDividirInsumo").ClientID)) + + e.Row.FCTextBox("LblCodigo").Attributes.Add("onkeyup", String.Format("LimpiaAF(1, '{0}'); EnterAFEdit(event,this,{1},{2},{3});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID, e.Row.RowIndex.ToString)) + e.Row.FCTextBox("LblCodigo").Attributes.Add("onblur", String.Format("LimpiaAF(1, '{0}'); AFBlurEdit(this,{1},{2},{3});", e.Row.FCHiddenField("HdnCveConcepto").Value, e.Row.FCHiddenField("HdnCveAF").ClientID, e.Row.FCHiddenField("HdnCodAF").ClientID, e.Row.RowIndex.ToString)) + + e.Row.FCTextBox("TxtAFMedida").Attributes.Add("onblur", String.Format("AFInsumosMedida(this,{0});", e.Row.RowIndex)) + + + End If + End Sub + Protected Sub BtnLimpiaAF_Click(sender As Object, e As EventArgs) + LimpiaAF(HdnTipoAF.Value.ToEntero, HdnCveConceptoAF.Value) + End Sub + Protected Sub LimpiaAF(TipoCompra As Integer, CveConcepto As String) + llenaDtsAF() + + For Each Row As DataRow In TmpDT.Rows + If Row("CveConcepto").ToString = CveConcepto Then + Row("TipoAF") = TipoCompra + End If + Next + TmpDT.AcceptChanges() + + llenaDtsAF() + CargaGVsAF() + End Sub + Protected Sub DivirInsumo(sender As Object, e As EventArgs) + Dim index2 As Integer = 0 + + 'LLena el AF vinculado para no perderlo + For Each Row As DataRow In TmpDT.Rows + If GvAFInsumos.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then + Row("CveActivoFijo") = GvAFInsumos.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero + Row("CodAF") = GvAFInsumos.Rows(index2).FCHiddenField("HdnCodAF").Value.ToString + Row("TipoAF") = 1 + End If + index2 += 1 + Next + + index2 = 0 + For Each Row As DataRow In TmpDT.Rows + If GvAFCompras.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero > 0 Then + Row("CveActivoFijo") = GvAFCompras.Rows(index2).FCHiddenField("HdnCveAF").Value.ToEntero + Row("CodAF") = GvAFCompras.Rows(index2).FCHiddenField("HdnCodAF").Value.ToString + Row("TipoAF") = 1 + End If + index2 += 1 + Next + + Dim Index As Integer = CType(sender, Button).CommandArgument.ToString.ToEntero + Dim Cantidad As String = HdnCantidadInsumo.Value + Dim dr1 As DataRow = TmpDT.Rows(Index) + Dim dr As DataRow = TmpDT.NewRow + dr.ItemArray = dr1.ItemArray + + dr1("Cantidad") = (dr1("Cantidad").ToString.ToDouble - Cantidad.ToDouble) + dr1("Total") = dr1("PU").ToString.ToDouble * dr1("Cantidad").ToString.ToDouble + dr1("IVA") = Math.Round(dr1("IVAPorcentaje").ToString.ToDouble * dr1("Total").ToString.ToDouble, 6) + TmpDT.AcceptChanges() + + + dr("CveActivoFijo") = 0 + dr("CodAF") = "" + dr("Cantidad") = Cantidad.ToDouble + dr("Total") = dr("PU").ToString.ToDouble * Cantidad.ToDouble + dr("IVA") = Math.Round(dr("IVAPorcentaje").ToString.ToDouble * dr("Total").ToString.ToDouble, 6) + + TmpDT.Rows.InsertAt(dr, Index + 1) + + For Index = 0 To TmpDT.Rows.Count - 1 + TmpDT.Rows(Index)("Consec") = Index + 1 + Next + + CargaGVsAF() + + 'TmpDT = DtAFInsumos.Copy + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + 'Afecta GVINV + CargaGvInv() + + CargaGvPersonal() + End Sub + Protected Sub BtnVinculaAFEdit_Click(sender As Object, e As EventArgs) + Dim ObjAF As New ClsAF + Dim Index As Integer = HdnIndexTmpDT.Value.ToEntero() + If ObjAF.GetActivosFijos(-1, UsuarioActual.CveEmpresa, HdnCodAFEdit.Value, "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "", -1, UsuarioActual.CveEmpresa) Then + If ObjAF.DtResultados.Rows.Count = 1 Then + 'VERIFICAR QUE EL ACTIVO FIJO ESTE ACTIVO. que no este en baja, inactivo. + If HdnTipoAF.Value.ToEntero = 1 Then + GvAFInsumos.Rows(Index).FCHiddenField("HdnCveAF").Value = ObjAF.DtResultados.Rows(0)("CveActivoFijo").ToString + GvAFInsumos.Rows(Index).FCHiddenField("HdnCodAF").Value = ObjAF.DtResultados.Rows(0)("Codigo").ToString + RegistraScript(String.Format("MuestraCheckAF('{0}','');", GvAFInsumos.Rows(Index).FCLabel("LblValido").ClientID), "A2") + ElseIf HdnTipoAF.Value.ToEntero = 2 Then + GvAFCompras.Rows(Index).FCHiddenField("HdnCveAF").Value = ObjAF.DtResultados.Rows(0)("CveActivoFijo").ToString + GvAFCompras.Rows(Index).FCHiddenField("HdnCodAF").Value = ObjAF.DtResultados.Rows(0)("Codigo").ToString + RegistraScript(String.Format("MuestraCheckAF('{0}','');", GvAFCompras.Rows(Index).FCLabel("LblValido").ClientID), "A2") + End If + 'COMENTADO IPP 15 JUNIO 2017 + 'RegistraScript(String.Format("EnterAFEditOK('{0}','{1}');", ObjAF.DtResultados.Rows(0)("CveActivoFijo").ToString, ObjAF.DtResultados.Rows(0)("Codigo").ToString)) + LimpiaAF(HdnTipoAF.Value.ToEntero, HdnCveConceptoAF.Value) + Else + If HdnTipoAF.Value.ToEntero = 1 Then + GvAFInsumos.Rows(Index).FCHiddenField("HdnCveAF").Value = "-1" + GvAFInsumos.Rows(Index).FCHiddenField("HdnCodAF").Value = "-1" + RegistraScript(String.Format("MuestraCheckAF('{0}','none');", GvAFInsumos.Rows(Index).FCLabel("LblValido").ClientID), "A2") + ElseIf HdnTipoAF.Value.ToEntero = 2 Then + GvAFCompras.Rows(Index).FCHiddenField("HdnCveAF").Value = "-1" + GvAFCompras.Rows(Index).FCHiddenField("HdnCodAF").Value = "-1" + RegistraScript(String.Format("MuestraCheckAF('{0}','none');", GvAFCompras.Rows(Index).FCLabel("LblValido").ClientID), "A2") + End If + + Alert("No se encontró un Activo Fijo con el código proporcionado.", TipoMensaje.MsgAdvertencia) + End If + End If + + ObjAF.Dispose() + End Sub + Protected Sub DdlTipoMantemiento_SelectedIndexChanged(sender As Object, e As EventArgs) + Dim dr = TmpDT.Rows(CType(CType(sender, DropDownList).NamingContainer, GridViewRow).RowIndex) + + dr("AFTipoMantenimiento") = CType(CType(sender, DropDownList).NamingContainer, GridViewRow).FCDropDownList("DdlTipoMantemiento").SelectedValue.ToEntero + + End Sub + Protected Sub BtnAFMedida_Click(sender As Object, e As EventArgs) + TmpDT(HdnIndexTmpDT.Value.ToEntero)("AFMedida") = HdnTxtAFMedida.Value + End Sub +#End Region + +#Region "C O N T R A T O S" 'Protected Sub ImgBtnBuscarContrato_Click(sender As Object, e As ImageClickEventArgs) Handles ImgBtnBuscarContrato.Click ' If CveProveedor <= 0 Then ' Alert("Debe de Seleccionar un proveedor") @@ -11986,1718 +12124,1718 @@ Partial Class Compras_Compras ' ObjContratos.Dispose() ' End If 'End Sub -#End Region +#End Region -#Region "TAB ALMACEN - INVENTARIOS ISRAEL PIÑA - 5 FEBRERO 2015" +#Region "TAB ALMACEN - INVENTARIOS ISRAEL PIÑA - 5 FEBRERO 2015" - Protected Sub CalculaTotalPorDevengar() - Dim total = TxtTotal.Text.ToDouble - For Each Gvr As GridViewRow In GvInv.Rows - If Gvr.FCCheckBox("cbInv").Checked = True And Gvr.FCDropDownList("DdlRecibirInv").SelectedValue = "1" Then - total -= Math.Round(Gvr.FCTextBox("TbCantidad").Text.ToDouble * Gvr.DataKey("PU").ToDouble, 4) - End If - Next - 'LbTotalPorDevengar.Text = total.ToString.FormatoNumero - 'UPPM.Update() - End Sub - - Protected Sub CambiaTotalDevengar(sender As Object, e As EventArgs) - CalculaTotalPorDevengar() + Protected Sub CalculaTotalPorDevengar() + Dim total = TxtTotal.Text.ToDouble + For Each Gvr As GridViewRow In GvInv.Rows + If Gvr.FCCheckBox("cbInv").Checked = True And Gvr.FCDropDownList("DdlRecibirInv").SelectedValue = "1" Then + total -= Math.Round(Gvr.FCTextBox("TbCantidad").Text.ToDouble * Gvr.DataKey("PU").ToDouble, 4) + End If + Next + 'LbTotalPorDevengar.Text = total.ToString.FormatoNumero + 'UPPM.Update() End Sub -#End Region + Protected Sub CambiaTotalDevengar(sender As Object, e As EventArgs) + CalculaTotalPorDevengar() + End Sub -#Region " AJUSTA IMPORTES " +#End Region + +#Region " AJUSTA IMPORTES " Private Sub AjustaImporteUltimoConcepto(ImporteAjuste As Decimal, Optional EsCarga As Boolean = False) 'Dim TempSubTotal = TxtSubTotal.Text.ToDouble Dim Amortizacion As Decimal = 0 If ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 Then Amortizacion = LblAmortizacion.Text.ToDecimal - End If - - If TmpDT.Rows.Count > 0 Then ' si hay movimientos y si esta afectando al total, que se haga el ajuste - 'Dim ImporteAjuste As Decimal = Total - (SubTotal2 + IVA - RetencionIVA - RetencionIVA - RetencionISR + IEPS + OtrosImpuestos) - Dim Indice As Integer = If(TmpDT.Rows(TmpDT.Rows.Count - 1)("CvePS").ToString = UsuarioActual.Empresa.Funcionalidad(112).ToString, TmpDT.Rows.Count - 2, TmpDT.Rows.Count - 1) + End If + + If TmpDT.Rows.Count > 0 Then ' si hay movimientos y si esta afectando al total, que se haga el ajuste + 'Dim ImporteAjuste As Decimal = Total - (SubTotal2 + IVA - RetencionIVA - RetencionIVA - RetencionISR + IEPS + OtrosImpuestos) + Dim Indice As Integer = If(TmpDT.Rows(TmpDT.Rows.Count - 1)("CvePS").ToString = UsuarioActual.Empresa.Funcionalidad(112).ToString, TmpDT.Rows.Count - 2, TmpDT.Rows.Count - 1) Dim tPU As Decimal - If TmpDT.Rows(Indice)("Cantidad").ToString.ToDecimal > 0 Then - tPU = ImporteAjuste / TmpDT.Rows(Indice)("Cantidad").ToString.ToDecimal - Else - tPU = 0 - End If - - TmpDT.Rows(Indice)("PU") = TmpDT.Rows(Indice)("PU").ToString.ToDouble + tPU - TmpDT.Rows(Indice)("Total") = TmpDT.Rows(Indice)("Total").ToString.ToDouble + ImporteAjuste - TmpDT.AcceptChanges() - End If - - SubTotal = TmpDT.SUM("Total").ToString.ToDecimal - If Not EsCarga Then - Descuentos = TmpDT.SUM("Descuento").ToString.ToDecimal - End If - TxtSubTotal.Text = (SubTotal + Descuentos).FormatoNumero() - TxtSubTotal2.Text = (SubTotal - Amortizacion).FormatoNumero - TxtDescuento.Text = Descuentos.FormatoNumero() - SubTotalConceptos = SubTotal - GvPS.DataSource = TmpDT : GvPS.DataBind() - - 'If TxtOtrosImpuestos.Text.ToDouble > 0 Then TxtOtrosImpuestos.Text = "" : TrOtrosImpuestos.Visible = False - - 'EN ESPERA DE ALGUN CASO QUE LO NECESITE - IPP 5 DICIEMBRE 2016 - 'TempSubTotal = TempSubTotal - SubTotal - 'If TempSubTotal > 0 Then - ' TxtTotal.Text = TempSubTotal.ToString.FormatoNumero - 'End If - - 'GVAF.DataSource = TmpDT : GVAF.DataBind() - End Sub - - Protected Sub ImgAjustePorcentaje_Click(sender As Object, e As ImageClickEventArgs) Handles ImgAjustePorcentaje.Click - 'realizo el ajuste de los productos - AjustaConceptos() - For Each Row As GridViewRow In GvPS.Rows - If UsuarioActual.TienePermisoProceso(143) Then - Row.FCLinkButton("ImgE").Visible = True - Row.FCLinkButton("ImgD").Visible = True - End If - Next - End Sub - - Private Sub AjustaConceptos(Optional AjusteForzoso As Boolean = False) - 'SE COMENTO POR PORCENTAJE DE DESCUENTO 0.00 - IPP 3 ENERO 2017 - 'If TxtAjustePorcentaje.Text.ToDecimal <> 0 Or AjusteForzoso Then - 'End If - - If TxtAjustePorcentaje.Text.ToDecimal <> 0 Then - For Each Dr As DataRow In TmpDT.Rows - 'Dr("PU") = Dr("PU").ToString.ToDecimal * ((100 - TxtAjustePorcentaje.Text.ToDecimal) / 100) - Dim TotalAnterior = Dr("Total").ToString.ToDecimal - Dr("Total") = Dr("Total").ToString.ToDecimal * ((100 - TxtAjustePorcentaje.Text.ToDecimal) / 100) - Dr("Descuento") = TotalAnterior - Dr("Total").ToString.ToDecimal - Next - - 'TxtDescuento.Text = Descuentos.ToString - End If - - 'verifico las sumas - If TxtSubTotal2.Text.ToDecimal <> TmpDT.SUM("Total") Then - Dim i As Integer = TmpDT.Rows.Count - 1 - 'verifico si el ultimo dato, es diferente de cero, sino tomo el anterior - If TmpDT.Rows(i)("Total").ToString.ToDecimal <= 0 AndAlso i - 1 >= 0 Then i = i - 1 - - 'sino se hizo el ajuste, lo aplico al ultimo registro la diferencia - 'para ajustar el PU, de la diferencia la divido entre la cantidad - TmpDT.Rows(i)("PU") = TmpDT.Rows(i)("PU").ToString.ToDecimal + ((TxtSubTotal2.Text.ToDecimal - TmpDT.SUM("Total")) / TmpDT.Rows(i)("Cantidad").ToString.ToDecimal) - TmpDT.Rows(i)("Total") = TmpDT.Rows(i)("Total").ToString.ToDecimal + TxtSubTotal2.Text.ToDecimal - TmpDT.SUM("Total") - End If - - - TxtSubTotal.Text = (TmpDT.SUM("Total") + TmpDT.SUM("Descuento")).FormatoNumero - TxtSubTotal2.Text = TmpDT.SUM("Total").FormatoNumero - SubTotalOriginal = TmpDT.SUM("Total") + TmpDT.SUM("Descuento") - SubTotal2Original = TmpDT.SUM("Total") - - BtnGuardar.Enabled = True - UpFacturar.Update() - PnlAjusteProductos.Visible = False - 'habilito la busqueda de oc - ImgBtnBuscarOC.Visible = True - TxtOC.Enabled = True - UpParametros.Update() - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - End Sub -#End Region + If TmpDT.Rows(Indice)("Cantidad").ToString.ToDecimal > 0 Then + tPU = ImporteAjuste / TmpDT.Rows(Indice)("Cantidad").ToString.ToDecimal + Else + tPU = 0 + End If -#Region "DDL'S" - Protected Sub DdlCredito_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCredito.SelectedIndexChanged - CargaCreditosDetalle(DdlCredito.SelectedValue.ToEntero) - CargaCreditosDisponibles() - End Sub - Protected Sub DdlDeudor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlDeudor.SelectedIndexChanged - TxtContadoDeudor.Text = "0" - - If DdlDeudor.SelectedValue.ToEntero > 0 Then - Dim Deudores As New ClsMovimientos - - If RBLTipoDeudor.SelectedValue.ToEntero = 1 Then - If Deudores.GetDeudoresSaldosDetalle(DdlDeudor.SelectedValue.ToEntero, DdlMoneda.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then - DtDeudoresDetalle = Deudores.DtResultados.FiltraParametros("CveProveedor > 0 AND Saldo > 0") - GvDeudores.DataSource = DtDeudoresDetalle - GvDeudores.DataBind() - End If - Else - If Deudores.GetDeudoresComisionesSaldosDetalle(DdlDeudor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then - DtDeudoresDetalle = Deudores.DtResultados.FiltraParametros("CveProveedor > 0 AND Saldo > 0") - GvDeudores.DataSource = DtDeudoresDetalle - GvDeudores.DataBind() - End If - End If - - - If CompraSaldo < TxtTotal.Text.ToDouble Then - RVContadoDeudor.MaximumValue = CompraSaldo.ToString - Else - RVContadoDeudor.MaximumValue = TxtTotal.Text - End If - - UPDeudores.Update() - Deudores.Dispose() - TxtContadoDeudor.Attributes.Add("readonly", "readonly") - End If - End Sub - Protected Sub DdlAcreedor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlAcreedor.SelectedIndexChanged - If DdlAcreedor.SelectedValue.ToEntero > 0 Then - Dim dr As DataRow - - dr = DtAcreedores.FiltroPrimero(String.Format("CveProveedor = {0}", DdlAcreedor.SelectedValue)) - 'If EmpresaPrueba Then - ' dr = DtAcreedores.FiltroPrimero(String.Format("CveProveedor = {0}", DdlAcreedor.SelectedValue)) - 'Else - ' dr = DtAcreedores.FiltroPrimero(String.Format("CveProveedor = {0}", DdlDeudor.SelectedValue)) - 'End If - - - If dr IsNot Nothing Then - Dim tSaldo As Double = dr("Saldo").ToString.ToDouble - RVContadoAcreedor.MaximumValue = tSaldo.ToString - 'si el saldo es mayor de la compra poner el valor de la compra sino el valor del saldo - TxtContadoAcreedor.Text = If(tSaldo > TxtTotal.Text.ToDouble, TxtTotal.Text, tSaldo.ToString).FormatoNumero - - LblDetalle.Visible = True - DdlAcreedorDetalle.Visible = True - - Dim ObjMov As New ClsMovimientos - Dim ObjProveedor As New ClsCompProveedores() - - If ObjMov.GetAcreedoresSaldosDetalles(-1, CveMoneda, UsuarioActual.CveEmpresa) Then - DdlAcreedorDetalle.DataSource = ObjMov.DtResultados.FiltraParametros(String.Format("CveProveedor = {0}", DdlAcreedor.SelectedValue)) - DdlAcreedorDetalle.DataBind() - DdlAcreedorDetalle.Items.Insert(0, New ListItem("Seleccione Acreedor", "-1")) - UpContado.Update() - End If - - If ObjProveedor.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, DdlAcreedor.SelectedValue.ToEntero, "-1", "-1", "-1", "-1", "-1", "-1", "-1", 1, UsuarioActual.CveEmpresa) Then - ViewState("CtaProveedorAcreedores") = ObjProveedor.IdCtaContAcreedor - ViewState("CveCuentaProveedorAcreedores") = ObjProveedor.CveCuentaAcreedor - End If - - - ObjProveedor.Dispose() - ObjMov.Dispose() - - End If - - Else - TxtContadoAcreedor.Text = "0" - End If - End Sub - Protected Sub DdlPersonal_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPersonal.SelectedIndexChanged - ViewState("CvePersonal") = DdlPersonal.SelectedValue - End Sub - Protected Sub DdlCajaChica_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCajaChica.SelectedIndexChanged - ViewState("CveCajaChica") = DdlCajaChica.SelectedValue - End Sub - Protected Sub DdlTipoCredito_SelectedIndexChanged(sender As Object, e As EventArgs) - CargaCreditos() - - Select Case DdlTipoCredito.SelectedValue.ToEntero - Case 1 - DivCreditoMensualidad.Visible = False - Case 2 - DivCreditoMensualidad.Visible = True - End Select - End Sub - Protected Sub DdlProveedor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlProveedor.SelectedIndexChanged - ViewState("CveProveedor") = DdlProveedor.SelectedValue.ToEntero - HdnCveProveedor.Value = CveProveedor.ToString - CargaProveedor(HdnCveProveedor.Value.ToEntero, "-1", False) - - - - - If DdlPS.ddl.SelectedIndex > 0 Then - DdlPS_SelectedIndexChanged(sender, e) - DdlPS.Focus() - Else - TxtCantidad.Focus() - End If - - If DdlProveedor.SelectedValue.ToEntero > 0 Then - ChkConsignacion.Enabled = True - Else - ChkConsignacion.Enabled = False - End If - - If GlobalDTProveedorSucursales(DdlProveedor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa).Rows.Count > 0 Then - RowProveedorSucursal.Visible = True - DdlProveedorSucursal.Items.Clear() - DdlProveedorSucursal.DataSource = GlobalDTProveedorSucursales(DdlProveedor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) - DdlProveedorSucursal.DataBind() - DdlProveedorSucursal.Items.Insert(0, New ListItem("Selecciona una Sucursal", "-1")) - DdlProveedorSucursal.Items.Insert(0, New ListItem("Matriz", "0")) - Else - DdlProveedorSucursal.Items.Clear() - DdlProveedorSucursal.Items.Insert(0, New ListItem("N/O", "-1")) - DdlProveedorSucursal.DataBind() - RowProveedorSucursal.Visible = False - End If - - UpEstatus.Update() - UpTabs.Update() - - - - - - - - 'DdlProveedor.Attributes.Add("onclick", "CargaProveedores();") - End Sub - Protected Sub DdlCuenta_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuenta.SelectedIndexChanged - Dim Folio As Long - - Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltroPrimero("CveCuenta = " & DdlCuenta.SelectedValue) - - If dr IsNot Nothing Then - CveMoneda = dr("CveMoneda").ToString.ToEntero - IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero - CveCuentaBancaria = dr("IdCtaContableSIG").ToString.ToEntero - IdCuentaBancariaComplementaria = dr("IdCtaContableComplementaria").ToString.ToEntero - CveCuentaBancariaComplementaria = dr("IdCtaContableComplementariaSIG").ToString.ToEntero - If dr("UsaTarjeta").ToString = "True" Then - CargaGridTarjetas() - Else - DivTarjeta.Visible = False - End If - End If - - If UsuarioActual.Empresa.Funcionalidad(505) <> "1" Then - Dim Banco As New ClsBancos - Folio = Banco.GetNextFolio(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero) - Banco.Dispose() - - TxtDocumentoFolio.Text = Folio.ToString - End If - - End Sub - Protected Sub DdlCuentaCaja_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuentaCaja.SelectedIndexChanged - Dim Folio As Long - - Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltroPrimero("CveCuenta = " & DdlCuentaCaja.SelectedValue) - - If dr IsNot Nothing Then - CveMoneda = dr("CveMoneda").ToString.ToEntero - IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero - CveCuentaBancaria = dr("IdCtaContableSIG").ToString.ToEntero - End If - - If UsuarioActual.Empresa.Funcionalidad(505) <> "1" Then - Dim Banco As New ClsBancos - Folio = Banco.GetNextFolio(DdlCuentaCaja.SelectedValue.ToEntero, DdlTipoTransaccionCaja.SelectedValue.ToEntero) - Banco.Dispose() - - TxtDocumentoFolioCaja.Text = Folio.ToString - End If - - End Sub - Protected Sub DdlFuncionarioEmpleado_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlFuncionarioEmpleado.SelectedIndexChanged - If DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then - Dim ObjMovtos As New ClsMovimientos - RowCheque.Visible = True - - ObjMovtos.GetEgresosSinComprobarPersonalDetalle(DdlFuncionarioEmpleado.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) - DtCheques = ObjMovtos.DtResultados.FiltraParametros("CveIE > 0", "FechaDocumento, FolioFecha") - - 'Limpia Ddl Cheques - DDlCheques.Items.Clear() - - If DtCheques.Rows.Count > 0 Then - DDlCheques.DataSource = DtCheques - End If - - ObjMovtos.Dispose() - DDlCheques.DataBind() - - - DDlCheques_SelectedIndexChanged(DDlCheques, EventArgs.Empty) - Else - RowCheque.Visible = False - - lblSaldoFE.Text = "0.00" - End If - - End Sub - Protected Sub DDlCheques_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDlCheques.SelectedIndexChanged - Dim saldo As Double = DtCheques.Rows(DDlCheques.SelectedIndex)("Saldo").ToString.ToDecimal - - TxtDocumentoImporteFE.Text = If(saldo < TxtTotal.Text.ToDouble, saldo.FormatoNumero, TxtTotal.Text) - lblSaldoFE.Text = saldo.FormatoNumero - - RVDocumentoImporteFE.MaximumValue = saldo.ToString - UPCondicionesPago.Update() - - End Sub -#End Region + TmpDT.Rows(Indice)("PU") = TmpDT.Rows(Indice)("PU").ToString.ToDouble + tPU + TmpDT.Rows(Indice)("Total") = TmpDT.Rows(Indice)("Total").ToString.ToDouble + ImporteAjuste + TmpDT.AcceptChanges() + End If -#Region "CHK'S" - Protected Sub RBLCajaChica_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLCajaChica.SelectedIndexChanged - Select Case RBLCajaChica.SelectedValue - Case "1" : DdlCajaChica.Visible = False : DdlPersonal.Visible = True - Case "2" : DdlCajaChica.Visible = True : DdlPersonal.Visible = False - End Select - - - End Sub - Protected Sub ChkReembolso_CheckedChanged(sender As Object, e As EventArgs) Handles ChkReembolso.CheckedChanged - PnlReemb.Visible = ChkReembolso.Checked - End Sub - Protected Sub RBLPago_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLPago.SelectedIndexChanged - CambiaTipoPago(True) - End Sub - Private Sub CambiaTipoPago(MostrarModal As Boolean) - DdlPersonalReembolso.Visible = False - DdlCuentaCajaChicaReembolso.Visible = False - - - Select Case RBLPago.SelectedValue - Case "1" 'Credito - PnlContado.Visible = False - - If Not UsuarioActual.Empresa.UsaAC Then - TxtNumeroReembolso.Text = "" - tdNumeroReembolso.Visible = False - End If - EsContado = False - romCreditosTabla.Visible = False - Case "2" 'Contado - PnlContado.Visible = True - - TxtNumeroReembolso.Text = "" - tdNumeroReembolso.Visible = False - - - - RBLContado.Items(0).Enabled = True - RBLContado.Items(3).Enabled = True - RBLContado.Items(4).Enabled = True - RBLContado.Items(5).Enabled = True - - - If UsuarioActual.Empresa.CvePlataforma = 2 Then - RBLContado.Items.Clear() - RBLContado.Items.Insert(0, New ListItem("Bancos", "1")) - RBLContado.Items.Insert(1, New ListItem("Caja Chica", "6")) - RBLContado.Items.Insert(2, New ListItem("Deudores", "4")) - RBLContado.SelectedIndex = 0 - - - 'RBLContado.Items.Item(2).Enabled = False - 'RBLContado.Items.Item(4).Enabled = False - 'RBLContado.Items.Item(5).Enabled = False - End If - - 'If EmpresaPrueba Then - ' RBLContado.Items(5).Enabled = False - 'End If - - EsContado = True - romCreditosTabla.Visible = False - Case "3" 'Reembolso/Comprobacion - PnlContado.Visible = True - - - ''AGARRA VALORES DE SESSION PARA REEMBOLSO -- SI YA ESTA REGISTRADA LA COMPRA IGNORA DATOS DE REEMBOLSO - If Not CveCompra > 0 Then - If UsuarioActual.Sesion("Comp-NumeroReembolso") <> Nothing AndAlso UsuarioActual.Sesion("Comp-NumeroReembolso").ToString <> "" Then - 'RBLPago.SelectedValue = "3" ' [IPP] SE COMENTO POR NO PODER MOSTRAR LO SELECCIONADO - 'RBLPago_SelectedIndexChanged(RBLPago, EventArgs.Empty) - 'CambiaTipoPago(False) - - tdNumeroReembolso.Visible = True - TxtNumeroReembolso.Text = UsuarioActual.Sesion("Comp-NumeroReembolso").ToString - TxtDescripcion.Text = UsuarioActual.Sesion("Comp-Descripcion").ToString - - If UsuarioActual.Sesion("Comp-CveFYE") <> Nothing AndAlso UsuarioActual.Sesion("Comp-CveFYE").ToString.ToEntero > 0 Then - RBLContado.SelectedValue = "2" - RBLContado_SelectedIndexChanged(RBLContado, EventArgs.Empty) - DdlPersonalReembolso.SelectedValueExist(UsuarioActual.Sesion("Comp-CveFYE").ToString) - ViewState("CvePersonal") = UsuarioActual.Sesion("Comp-CveFYE").ToString - Else - RBLContado.SelectedValue = "6" - End If - - Else - UsuarioActual.Sesion("Comp-NumeroReembolso") = "" - UsuarioActual.Sesion("Comp-CveFYE") = "" - UsuarioActual.Sesion("Comp-Descripcion") = "" - - TxtNumeroReembolso.Text = "" - tdNumeroReembolso.Visible = True - RBLContado.SelectedValue = "6" - End If - End If - - - RBLContado.Items(0).Enabled = False - RBLContado.Items(3).Enabled = True - RBLContado.Items(4).Enabled = False - RBLContado.Items(5).Enabled = False - - - EsContado = False - - 'Valida Proceso 118 para ROL Administrador - Si es REEMBOLSO: Selecciona FyE y Relacionado con UsuarioActual cuando tiene CvePersonal - If UsuarioActual.TienePermisoProceso(118) Then - RBLContado.SelectedValue = "2" - RBLContado.Items(1).Enabled = False - End If - - Select Case RBLContado.SelectedValue - Case "2" - DdlPersonalReembolso.Visible = True - Case "6" - DdlCuentaCajaChicaReembolso.Visible = True - End Select - romCreditosTabla.Visible = False - Case "4" - CargaCreditosDisponibles() - Exit Select - End Select - UpGvCreditos.Update() - - If Not RBLPago.SelectedValue = "1" And MostrarModal And RBLPago.SelectedValue <> "4" Then - RegistraScript(String.Format("$('#{0}').modal('show');", "DivContadoModal")) - End If - - LtlTituloPago.Text = If(EsContado, "Contado", "Reembolso") - - DivContado.Visible = EsContado - DivReembolso.Visible = Not EsContado - - CargaContado() - - End Sub - Protected Sub RBLContado_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLContado.SelectedIndexChanged - CargaContado() - End Sub - Private Sub RBLTipoDeudor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLTipoDeudor.SelectedIndexChanged - GvDeudores.DataSource = Nothing - GvDeudores.DataBind() - UpContado.Update() - - CargaDeudores() - End Sub - Private Sub CargaContado() - 'ESCONDE TODO - PnlContadoBancos.Visible = False - PnlContadoFyE.Visible = False - PnlContadoCreditos.Visible = False - PnlContadoDeudores.Visible = False - PnlContadoAcreedores.Visible = False - PnlContadoCajaChica.Visible = False - DdlPersonalReembolso.Visible = False - DdlCuentaCajaChicaReembolso.Visible = False - - If GvDeudores IsNot Nothing Then - GvDeudores.DataSource = Nothing - GvDeudores.DataBind() - UPDeudores.Update() - End If - - 'Reembolsos - If RBLPago.SelectedValue = "3" Then - - Select Case RBLContado.SelectedValue - Case "2" - DdlPersonalReembolso.Visible = True - Case "6" - DdlCuentaCajaChicaReembolso.Visible = True - End Select - - 'Valida Proceso 118 para ROL Administrador - Si es REEMBOLSO: Selecciona FyE y Relacionado con UsuarioActual cuando tiene CvePersonal - If UsuarioActual.TienePermisoProceso(118) Then - If UsuarioActual.CvePersonal > 0 Then - DdlPersonalReembolso.SelectedValueExist(UsuarioActual.CvePersonal.ToString) - ViewState("CvePersonal") = DdlPersonalReembolso.SelectedValue - End If - DdlPersonalReembolso.Enabled = False - End If - - End If - - 'CONTADO - Select Case RBLContado.SelectedValue - Case "1" ' Bancos - PnlContadoBancos.Visible = True + SubTotal = TmpDT.SUM("Total").ToString.ToDecimal + If Not EsCarga Then + Descuentos = TmpDT.SUM("Descuento").ToString.ToDecimal + End If + TxtSubTotal.Text = (SubTotal + Descuentos).FormatoNumero() + TxtSubTotal2.Text = (SubTotal - Amortizacion).FormatoNumero + TxtDescuento.Text = Descuentos.FormatoNumero() + SubTotalConceptos = SubTotal + GvPS.DataSource = TmpDT : GvPS.DataBind() + + 'If TxtOtrosImpuestos.Text.ToDouble > 0 Then TxtOtrosImpuestos.Text = "" : TrOtrosImpuestos.Visible = False + + 'EN ESPERA DE ALGUN CASO QUE LO NECESITE - IPP 5 DICIEMBRE 2016 + 'TempSubTotal = TempSubTotal - SubTotal + 'If TempSubTotal > 0 Then + ' TxtTotal.Text = TempSubTotal.ToString.FormatoNumero + 'End If + + 'GVAF.DataSource = TmpDT : GVAF.DataBind() + End Sub + + Protected Sub ImgAjustePorcentaje_Click(sender As Object, e As ImageClickEventArgs) Handles ImgAjustePorcentaje.Click + 'realizo el ajuste de los productos + AjustaConceptos() + For Each Row As GridViewRow In GvPS.Rows + If UsuarioActual.TienePermisoProceso(143) Then + Row.FCLinkButton("ImgE").Visible = True + Row.FCLinkButton("ImgD").Visible = True + End If + Next + End Sub + + Private Sub AjustaConceptos(Optional AjusteForzoso As Boolean = False) + 'SE COMENTO POR PORCENTAJE DE DESCUENTO 0.00 - IPP 3 ENERO 2017 + 'If TxtAjustePorcentaje.Text.ToDecimal <> 0 Or AjusteForzoso Then + 'End If + + If TxtAjustePorcentaje.Text.ToDecimal <> 0 Then + For Each Dr As DataRow In TmpDT.Rows + 'Dr("PU") = Dr("PU").ToString.ToDecimal * ((100 - TxtAjustePorcentaje.Text.ToDecimal) / 100) + Dim TotalAnterior = Dr("Total").ToString.ToDecimal + Dr("Total") = Dr("Total").ToString.ToDecimal * ((100 - TxtAjustePorcentaje.Text.ToDecimal) / 100) + Dr("Descuento") = TotalAnterior - Dr("Total").ToString.ToDecimal + Next + + 'TxtDescuento.Text = Descuentos.ToString + End If + + 'verifico las sumas + If TxtSubTotal2.Text.ToDecimal <> TmpDT.SUM("Total") Then + Dim i As Integer = TmpDT.Rows.Count - 1 + 'verifico si el ultimo dato, es diferente de cero, sino tomo el anterior + If TmpDT.Rows(i)("Total").ToString.ToDecimal <= 0 AndAlso i - 1 >= 0 Then i = i - 1 + + 'sino se hizo el ajuste, lo aplico al ultimo registro la diferencia + 'para ajustar el PU, de la diferencia la divido entre la cantidad + TmpDT.Rows(i)("PU") = TmpDT.Rows(i)("PU").ToString.ToDecimal + ((TxtSubTotal2.Text.ToDecimal - TmpDT.SUM("Total")) / TmpDT.Rows(i)("Cantidad").ToString.ToDecimal) + TmpDT.Rows(i)("Total") = TmpDT.Rows(i)("Total").ToString.ToDecimal + TxtSubTotal2.Text.ToDecimal - TmpDT.SUM("Total") + End If + + + TxtSubTotal.Text = (TmpDT.SUM("Total") + TmpDT.SUM("Descuento")).FormatoNumero + TxtSubTotal2.Text = TmpDT.SUM("Total").FormatoNumero + SubTotalOriginal = TmpDT.SUM("Total") + TmpDT.SUM("Descuento") + SubTotal2Original = TmpDT.SUM("Total") + + BtnGuardar.Enabled = True + UpFacturar.Update() + PnlAjusteProductos.Visible = False + 'habilito la busqueda de oc + ImgBtnBuscarOC.Visible = True + TxtOC.Enabled = True + UpParametros.Update() + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + End Sub +#End Region + +#Region "DDL'S" + Protected Sub DdlCredito_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCredito.SelectedIndexChanged + CargaCreditosDetalle(DdlCredito.SelectedValue.ToEntero) + CargaCreditosDisponibles() + End Sub + Protected Sub DdlDeudor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlDeudor.SelectedIndexChanged + TxtContadoDeudor.Text = "0" + + If DdlDeudor.SelectedValue.ToEntero > 0 Then + Dim Deudores As New ClsMovimientos + + If RBLTipoDeudor.SelectedValue.ToEntero = 1 Then + If Deudores.GetDeudoresSaldosDetalle(DdlDeudor.SelectedValue.ToEntero, DdlMoneda.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then + DtDeudoresDetalle = Deudores.DtResultados.FiltraParametros("CveProveedor > 0 AND Saldo > 0") + GvDeudores.DataSource = DtDeudoresDetalle + GvDeudores.DataBind() + End If + Else + If Deudores.GetDeudoresComisionesSaldosDetalle(DdlDeudor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then + DtDeudoresDetalle = Deudores.DtResultados.FiltraParametros("CveProveedor > 0 AND Saldo > 0") + GvDeudores.DataSource = DtDeudoresDetalle + GvDeudores.DataBind() + End If + End If + + + If CompraSaldo < TxtTotal.Text.ToDouble Then + RVContadoDeudor.MaximumValue = CompraSaldo.ToString + Else + RVContadoDeudor.MaximumValue = TxtTotal.Text + End If + + UPDeudores.Update() + Deudores.Dispose() + TxtContadoDeudor.Attributes.Add("readonly", "readonly") + End If + End Sub + Protected Sub DdlAcreedor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlAcreedor.SelectedIndexChanged + If DdlAcreedor.SelectedValue.ToEntero > 0 Then + Dim dr As DataRow + + dr = DtAcreedores.FiltroPrimero(String.Format("CveProveedor = {0}", DdlAcreedor.SelectedValue)) + 'If EmpresaPrueba Then + ' dr = DtAcreedores.FiltroPrimero(String.Format("CveProveedor = {0}", DdlAcreedor.SelectedValue)) + 'Else + ' dr = DtAcreedores.FiltroPrimero(String.Format("CveProveedor = {0}", DdlDeudor.SelectedValue)) + 'End If + + + If dr IsNot Nothing Then + Dim tSaldo As Double = dr("Saldo").ToString.ToDouble + RVContadoAcreedor.MaximumValue = tSaldo.ToString + 'si el saldo es mayor de la compra poner el valor de la compra sino el valor del saldo + TxtContadoAcreedor.Text = If(tSaldo > TxtTotal.Text.ToDouble, TxtTotal.Text, tSaldo.ToString).FormatoNumero + + LblDetalle.Visible = True + DdlAcreedorDetalle.Visible = True + + Dim ObjMov As New ClsMovimientos + Dim ObjProveedor As New ClsCompProveedores() + + If ObjMov.GetAcreedoresSaldosDetalles(-1, CveMoneda, UsuarioActual.CveEmpresa) Then + DdlAcreedorDetalle.DataSource = ObjMov.DtResultados.FiltraParametros(String.Format("CveProveedor = {0}", DdlAcreedor.SelectedValue)) + DdlAcreedorDetalle.DataBind() + DdlAcreedorDetalle.Items.Insert(0, New ListItem("Seleccione Acreedor", "-1")) + UpContado.Update() + End If + + If ObjProveedor.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, DdlAcreedor.SelectedValue.ToEntero, "-1", "-1", "-1", "-1", "-1", "-1", "-1", 1, UsuarioActual.CveEmpresa) Then + ViewState("CtaProveedorAcreedores") = ObjProveedor.IdCtaContAcreedor + ViewState("CveCuentaProveedorAcreedores") = ObjProveedor.CveCuentaAcreedor + End If + + + ObjProveedor.Dispose() + ObjMov.Dispose() + + End If + + Else + TxtContadoAcreedor.Text = "0" + End If + End Sub + Protected Sub DdlPersonal_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPersonal.SelectedIndexChanged + ViewState("CvePersonal") = DdlPersonal.SelectedValue + End Sub + Protected Sub DdlCajaChica_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCajaChica.SelectedIndexChanged + ViewState("CveCajaChica") = DdlCajaChica.SelectedValue + End Sub + Protected Sub DdlTipoCredito_SelectedIndexChanged(sender As Object, e As EventArgs) + CargaCreditos() + + Select Case DdlTipoCredito.SelectedValue.ToEntero + Case 1 + DivCreditoMensualidad.Visible = False + Case 2 + DivCreditoMensualidad.Visible = True + End Select + End Sub + Protected Sub DdlProveedor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlProveedor.SelectedIndexChanged + ViewState("CveProveedor") = DdlProveedor.SelectedValue.ToEntero + HdnCveProveedor.Value = CveProveedor.ToString + CargaProveedor(HdnCveProveedor.Value.ToEntero, "-1", False) + + + + + If DdlPS.ddl.SelectedIndex > 0 Then + DdlPS_SelectedIndexChanged(sender, e) + DdlPS.Focus() + Else + TxtCantidad.Focus() + End If + + If DdlProveedor.SelectedValue.ToEntero > 0 Then + ChkConsignacion.Enabled = True + Else + ChkConsignacion.Enabled = False + End If + + If GlobalDTProveedorSucursales(DdlProveedor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa).Rows.Count > 0 Then + RowProveedorSucursal.Visible = True + DdlProveedorSucursal.Items.Clear() + DdlProveedorSucursal.DataSource = GlobalDTProveedorSucursales(DdlProveedor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) + DdlProveedorSucursal.DataBind() + DdlProveedorSucursal.Items.Insert(0, New ListItem("Selecciona una Sucursal", "-1")) + DdlProveedorSucursal.Items.Insert(0, New ListItem("Matriz", "0")) + Else + DdlProveedorSucursal.Items.Clear() + DdlProveedorSucursal.Items.Insert(0, New ListItem("N/O", "-1")) + DdlProveedorSucursal.DataBind() + RowProveedorSucursal.Visible = False + End If + + UpEstatus.Update() + UpTabs.Update() + + + + + + + + 'DdlProveedor.Attributes.Add("onclick", "CargaProveedores();") + End Sub + Protected Sub DdlCuenta_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuenta.SelectedIndexChanged + Dim Folio As Long + + Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltroPrimero("CveCuenta = " & DdlCuenta.SelectedValue) + + If dr IsNot Nothing Then + CveMoneda = dr("CveMoneda").ToString.ToEntero + IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero + CveCuentaBancaria = dr("IdCtaContableSIG").ToString.ToEntero + IdCuentaBancariaComplementaria = dr("IdCtaContableComplementaria").ToString.ToEntero + CveCuentaBancariaComplementaria = dr("IdCtaContableComplementariaSIG").ToString.ToEntero + If dr("UsaTarjeta").ToString = "True" Then + CargaGridTarjetas() + Else + DivTarjeta.Visible = False + End If + End If + + If UsuarioActual.Empresa.Funcionalidad(505) <> "1" Then + Dim Banco As New ClsBancos + Folio = Banco.GetNextFolio(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero) + Banco.Dispose() + + TxtDocumentoFolio.Text = Folio.ToString + End If + + End Sub + Protected Sub DdlCuentaCaja_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuentaCaja.SelectedIndexChanged + Dim Folio As Long + + Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltroPrimero("CveCuenta = " & DdlCuentaCaja.SelectedValue) + + If dr IsNot Nothing Then + CveMoneda = dr("CveMoneda").ToString.ToEntero + IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero + CveCuentaBancaria = dr("IdCtaContableSIG").ToString.ToEntero + End If + + If UsuarioActual.Empresa.Funcionalidad(505) <> "1" Then + Dim Banco As New ClsBancos + Folio = Banco.GetNextFolio(DdlCuentaCaja.SelectedValue.ToEntero, DdlTipoTransaccionCaja.SelectedValue.ToEntero) + Banco.Dispose() + + TxtDocumentoFolioCaja.Text = Folio.ToString + End If + + End Sub + Protected Sub DdlFuncionarioEmpleado_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlFuncionarioEmpleado.SelectedIndexChanged + If DdlFuncionarioEmpleado.SelectedValue.ToEntero > 0 Then + Dim ObjMovtos As New ClsMovimientos + RowCheque.Visible = True + + ObjMovtos.GetEgresosSinComprobarPersonalDetalle(DdlFuncionarioEmpleado.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) + DtCheques = ObjMovtos.DtResultados.FiltraParametros("CveIE > 0", "FechaDocumento, FolioFecha") + + 'Limpia Ddl Cheques + DDlCheques.Items.Clear() + + If DtCheques.Rows.Count > 0 Then + DDlCheques.DataSource = DtCheques + End If + + ObjMovtos.Dispose() + DDlCheques.DataBind() + + + DDlCheques_SelectedIndexChanged(DDlCheques, EventArgs.Empty) + Else + RowCheque.Visible = False + + lblSaldoFE.Text = "0.00" + End If + + End Sub + Protected Sub DDlCheques_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDlCheques.SelectedIndexChanged + Dim saldo As Double = DtCheques.Rows(DDlCheques.SelectedIndex)("Saldo").ToString.ToDecimal + + TxtDocumentoImporteFE.Text = If(saldo < TxtTotal.Text.ToDouble, saldo.FormatoNumero, TxtTotal.Text) + lblSaldoFE.Text = saldo.FormatoNumero + + RVDocumentoImporteFE.MaximumValue = saldo.ToString + UPCondicionesPago.Update() + + End Sub +#End Region + +#Region "CHK'S" + Protected Sub RBLCajaChica_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLCajaChica.SelectedIndexChanged + Select Case RBLCajaChica.SelectedValue + Case "1" : DdlCajaChica.Visible = False : DdlPersonal.Visible = True + Case "2" : DdlCajaChica.Visible = True : DdlPersonal.Visible = False + End Select + + + End Sub + Protected Sub ChkReembolso_CheckedChanged(sender As Object, e As EventArgs) Handles ChkReembolso.CheckedChanged + PnlReemb.Visible = ChkReembolso.Checked + End Sub + Protected Sub RBLPago_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLPago.SelectedIndexChanged + CambiaTipoPago(True) + End Sub + Private Sub CambiaTipoPago(MostrarModal As Boolean) + DdlPersonalReembolso.Visible = False + DdlCuentaCajaChicaReembolso.Visible = False + + + Select Case RBLPago.SelectedValue + Case "1" 'Credito + PnlContado.Visible = False + + If Not UsuarioActual.Empresa.UsaAC Then + TxtNumeroReembolso.Text = "" + tdNumeroReembolso.Visible = False + End If + EsContado = False + romCreditosTabla.Visible = False + Case "2" 'Contado + PnlContado.Visible = True + + TxtNumeroReembolso.Text = "" + tdNumeroReembolso.Visible = False + + + + RBLContado.Items(0).Enabled = True + RBLContado.Items(3).Enabled = True + RBLContado.Items(4).Enabled = True + RBLContado.Items(5).Enabled = True + + + If UsuarioActual.Empresa.CvePlataforma = 2 Then + RBLContado.Items.Clear() + RBLContado.Items.Insert(0, New ListItem("Bancos", "1")) + RBLContado.Items.Insert(1, New ListItem("Caja Chica", "6")) + RBLContado.Items.Insert(2, New ListItem("Deudores", "4")) + RBLContado.SelectedIndex = 0 + + + 'RBLContado.Items.Item(2).Enabled = False + 'RBLContado.Items.Item(4).Enabled = False + 'RBLContado.Items.Item(5).Enabled = False + End If + + 'If EmpresaPrueba Then + ' RBLContado.Items(5).Enabled = False + 'End If + + EsContado = True + romCreditosTabla.Visible = False + Case "3" 'Reembolso/Comprobacion + PnlContado.Visible = True + + + ''AGARRA VALORES DE SESSION PARA REEMBOLSO -- SI YA ESTA REGISTRADA LA COMPRA IGNORA DATOS DE REEMBOLSO + If Not CveCompra > 0 Then + If UsuarioActual.Sesion("Comp-NumeroReembolso") <> Nothing AndAlso UsuarioActual.Sesion("Comp-NumeroReembolso").ToString <> "" Then + 'RBLPago.SelectedValue = "3" ' [IPP] SE COMENTO POR NO PODER MOSTRAR LO SELECCIONADO + 'RBLPago_SelectedIndexChanged(RBLPago, EventArgs.Empty) + 'CambiaTipoPago(False) + + tdNumeroReembolso.Visible = True + TxtNumeroReembolso.Text = UsuarioActual.Sesion("Comp-NumeroReembolso").ToString + TxtDescripcion.Text = UsuarioActual.Sesion("Comp-Descripcion").ToString + + If UsuarioActual.Sesion("Comp-CveFYE") <> Nothing AndAlso UsuarioActual.Sesion("Comp-CveFYE").ToString.ToEntero > 0 Then + RBLContado.SelectedValue = "2" + RBLContado_SelectedIndexChanged(RBLContado, EventArgs.Empty) + DdlPersonalReembolso.SelectedValueExist(UsuarioActual.Sesion("Comp-CveFYE").ToString) + ViewState("CvePersonal") = UsuarioActual.Sesion("Comp-CveFYE").ToString + Else + RBLContado.SelectedValue = "6" + End If + + Else + UsuarioActual.Sesion("Comp-NumeroReembolso") = "" + UsuarioActual.Sesion("Comp-CveFYE") = "" + UsuarioActual.Sesion("Comp-Descripcion") = "" + + TxtNumeroReembolso.Text = "" + tdNumeroReembolso.Visible = True + RBLContado.SelectedValue = "6" + End If + End If + + + RBLContado.Items(0).Enabled = False + RBLContado.Items(3).Enabled = True + RBLContado.Items(4).Enabled = False + RBLContado.Items(5).Enabled = False + + + EsContado = False + + 'Valida Proceso 118 para ROL Administrador - Si es REEMBOLSO: Selecciona FyE y Relacionado con UsuarioActual cuando tiene CvePersonal + If UsuarioActual.TienePermisoProceso(118) Then + RBLContado.SelectedValue = "2" + RBLContado.Items(1).Enabled = False + End If + + Select Case RBLContado.SelectedValue + Case "2" + DdlPersonalReembolso.Visible = True + Case "6" + DdlCuentaCajaChicaReembolso.Visible = True + End Select + romCreditosTabla.Visible = False + Case "4" + CargaCreditosDisponibles() + Exit Select + End Select + UpGvCreditos.Update() + + If Not RBLPago.SelectedValue = "1" And MostrarModal And RBLPago.SelectedValue <> "4" Then + RegistraScript(String.Format("$('#{0}').modal('show');", "DivContadoModal")) + End If + + LtlTituloPago.Text = If(EsContado, "Contado", "Reembolso") + + DivContado.Visible = EsContado + DivReembolso.Visible = Not EsContado + + CargaContado() + + End Sub + Protected Sub RBLContado_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLContado.SelectedIndexChanged + CargaContado() + End Sub + Private Sub RBLTipoDeudor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLTipoDeudor.SelectedIndexChanged + GvDeudores.DataSource = Nothing + GvDeudores.DataBind() + UpContado.Update() + + CargaDeudores() + End Sub + Private Sub CargaContado() + 'ESCONDE TODO + PnlContadoBancos.Visible = False + PnlContadoFyE.Visible = False + PnlContadoCreditos.Visible = False + PnlContadoDeudores.Visible = False + PnlContadoAcreedores.Visible = False + PnlContadoCajaChica.Visible = False + DdlPersonalReembolso.Visible = False + DdlCuentaCajaChicaReembolso.Visible = False + + If GvDeudores IsNot Nothing Then + GvDeudores.DataSource = Nothing + GvDeudores.DataBind() + UPDeudores.Update() + End If + + 'Reembolsos + If RBLPago.SelectedValue = "3" Then + + Select Case RBLContado.SelectedValue + Case "2" + DdlPersonalReembolso.Visible = True + Case "6" + DdlCuentaCajaChicaReembolso.Visible = True + End Select + + 'Valida Proceso 118 para ROL Administrador - Si es REEMBOLSO: Selecciona FyE y Relacionado con UsuarioActual cuando tiene CvePersonal + If UsuarioActual.TienePermisoProceso(118) Then + If UsuarioActual.CvePersonal > 0 Then + DdlPersonalReembolso.SelectedValueExist(UsuarioActual.CvePersonal.ToString) + ViewState("CvePersonal") = DdlPersonalReembolso.SelectedValue + End If + DdlPersonalReembolso.Enabled = False + End If + + End If + + 'CONTADO + Select Case RBLContado.SelectedValue + Case "1" ' Bancos + PnlContadoBancos.Visible = True TxtDocumentoImporte.Text = (TxtTotal.Text.ToDecimal - LblAmortizacion.Text.ToDecimal).FormatoNumero - Case "2" ' F y E - PnlContadoFyE.Visible = True - CargaFuncionariosEmpleados() - Case "3" ' Creditos - PnlContadoCreditos.Visible = True - CargaCreditos() - Case "4" ' Deudores - PnlContadoDeudores.Visible = True - CargaDeudores() - Case "5" ' ACREEDORES - PnlContadoAcreedores.Visible = True - CargaAcreedores() - Case "6" ' Caja Chica - PnlContadoCajaChica.Visible = True - TxtDocumentoImporteCaja.Text = (TxtTotal.Text.ToDecimal - LblAmortizacion.Text.ToDecimal).FormatoNumero - End Select - - UpContado.Update() - End Sub - - Protected Sub RblRembolso_SelectedIndexChanged(sender As Object, e As EventArgs) - TrRembolsoCajaChica.Visible = False - TrRembolsoPersonal.Visible = False - DdlRembolsoCajaChica.SelectedValueExist("-1") - DdlRembolsoPersonal.SelectedValueExist("-1") - If RblRembolso.SelectedValue.ToEntero = 1 Then - TrRembolsoPersonal.Visible = True - ElseIf RblRembolso.SelectedValue.ToEntero = 2 Then - TrRembolsoCajaChica.Visible = True - End If - End Sub -#End Region + Case "2" ' F y E + PnlContadoFyE.Visible = True + CargaFuncionariosEmpleados() + Case "3" ' Creditos + PnlContadoCreditos.Visible = True + CargaCreditos() + Case "4" ' Deudores + PnlContadoDeudores.Visible = True + CargaDeudores() + Case "5" ' ACREEDORES + PnlContadoAcreedores.Visible = True + CargaAcreedores() + Case "6" ' Caja Chica + PnlContadoCajaChica.Visible = True + TxtDocumentoImporteCaja.Text = (TxtTotal.Text.ToDecimal - LblAmortizacion.Text.ToDecimal).FormatoNumero + End Select -#Region "ARMONIZACION CONTABLE - AC - SIMPLIFICADO" - Private Sub CargaPresupuestosEgresos(Optional CargaTodo As Boolean = True) - - 'Seccion Grid - GvPS.Width = 1760 - GvPS.Columns(12).Visible = True - GvPS.Columns(13).Visible = True - GvPS.Columns(14).Visible = True - GvPS.Columns(15).Visible = True - GvPS.Columns(16).Visible = True - - 'Panel General - UpPresupuestosAC.Visible = True - - DdlACGeneral1.Items.Clear() - DdlACGeneral1.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveProgramaOperativo", "ProgramaOperativo"}) - DdlACGeneral1.DataBind() - - DdlACGeneral2.Items.Clear() - DdlACGeneral2.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveUnidadAdministrativa", "UnidadAdministrativa"}, Orderby:="UnidadAdministrativa") - DdlACGeneral2.DataBind() - - DdlACGeneral3.Items.Clear() - DdlACGeneral3.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveFuenteFinanciamiento", "FuenteFinanciamiento"}, Orderby:="FuenteFinanciamiento") - DdlACGeneral3.DataBind() - - DdlACGeneral4.Items.Clear() - DdlACGeneral4.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveTipoGasto", "TipoGasto"}) - DdlACGeneral4.DataBind() - - DdlACGeneral5.Items.Clear() - DdlACGeneral5.DataSource = DtPresupuestos.FiltraParametros("NOT CodigoCOG like '1%'", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") - If UsuarioActual.CveEmpresa.Contiene(120) Then - DdlACGeneral5.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") - Else - DdlACGeneral5.DataSource = DtPresupuestos.FiltraParametros("NOT CodigoCOG like '1%'", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") - End If - DdlACGeneral5.DataBind() - - If CveCompra > 0 Then - RegistraScript("$get('DivPresupuestoEgresosGeneral').style.display = 'none';") - BtnVerPE.Visible = True - End If - - If CargaTodo Then - CalculaSaldoACGeneral() - UpPresupuestosAC.Update() - End If - - End Sub - - Private Sub ConservaAC() - 'Guarda valores AC en TmpDT - Dim Index = 0 - For Each gvr As GridViewRow In GvPS.Rows - TmpDT.Rows(Index)("CveProgramaOperativo") = gvr.FCDropDownList("DdlAC1").SelectedValue.ToEntero - TmpDT.Rows(Index)("CveUnidadAdministrativa") = gvr.FCDropDownList("DdlAC2").SelectedValue.ToEntero - TmpDT.Rows(Index)("CveFuenteFinanciamiento") = gvr.FCDropDownList("DdlAC3").SelectedValue.ToEntero - TmpDT.Rows(Index)("CveTipoGastoAC") = gvr.FCDropDownList("DdlAC4").SelectedValue.ToEntero - TmpDT.Rows(Index)("CveClasificacionOG") = gvr.FCDropDownList("DdlAC5").SelectedValue.ToEntero - Index += 1 - Next - End Sub - - Protected Sub CompruebaSaldoAC(sender As Object, e As EventArgs) - ConservaAC() - - CompruebaAgregar() - End Sub - - Protected Sub CambiaACGeneral(sender As Object, e As EventArgs) - - If ChkACGeneral.Checked Then - - 'CAMBIA LOS COMBOS DE TODOS LOS DETALLES DEL GRID - For Each gvr As GridViewRow In GvPS.Rows - - 'SI VIENE DESDE OC EL PE NO SE MUEVE - If Not gvr.DataKey("CveOrdenCompraDetalle").ToEntero > 0 Then - gvr.FCDropDownList("DdlAC1").SelectedValue = DdlACGeneral1.SelectedValue - gvr.FCDropDownList("DdlAC2").SelectedValue = DdlACGeneral2.SelectedValue - gvr.FCDropDownList("DdlAC3").SelectedValue = DdlACGeneral3.SelectedValue - gvr.FCDropDownList("DdlAC4").SelectedValue = DdlACGeneral4.SelectedValue - gvr.FCDropDownList("DdlAC5").SelectedValue = DdlACGeneral5.SelectedValue - End If - Next - - ConservaAC() - CompruebaAgregar() - UpPS.Update() - - End If - - CalculaSaldoACGeneral() - UpPresupuestosAC.Update() - - End Sub - - Private Sub CalculaSaldoACGeneral() - Dim ContPaq As New ClsContPAQi(UsuarioActual.Empresa) - Dim DtPresupuestosTemp = DtPresupuestos.FiltraParametros(String.Format("CveProgramaOperativo = {0} and CveUnidadAdministrativa = {1} and CveFuenteFinanciamiento = {2} and CveTipoGasto= {3} and CveClasificacion = {4}", DdlACGeneral1.SelectedValue.ToString, DdlACGeneral2.SelectedValue.ToString, DdlACGeneral3.SelectedValue.ToString, DdlACGeneral4.SelectedValue.ToString, DdlACGeneral5.SelectedValue.ToString)) - If DtPresupuestosTemp.Rows.Count > 0 Then - Dim IdCuenta = If(HdnVCveOC.Value <> "-1", DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString.ToEntero, DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero) - - LbACGeneralSaldo.Text = ContPaq.GetSaldoCuenta(IdCuenta, 0, TxtFecha.Text.ToDate.Year).ToString.FormatoNumero(2) - Else - LbACGeneralSaldo.Text = "0.00" - End If - ContPaq.Dispose() - End Sub - - Private Sub CargaHidendsAC() - Dim DtPresupuestosTemp As DataTable - Dim Filtro As New StringBuilder - - For Each grid As GridViewRow In GvPS.Rows - Filtro.AppendFormat("CveProgramaOperativo = {0} and CveUnidadAdministrativa = {1} and CveFuenteFinanciamiento = {2} and CveTipoGasto= {3} and CveClasificacion = {4}", grid.FCDropDownList("DdlAC1").SelectedValue.ToString, grid.FCDropDownList("DdlAC2").SelectedValue.ToString, grid.FCDropDownList("DdlAC3").SelectedValue.ToString, grid.FCDropDownList("DdlAC4").SelectedValue.ToString, grid.FCDropDownList("DdlAC5").SelectedValue.ToString) - DtPresupuestosTemp = DtPresupuestos.FiltraParametros(Filtro.ToString) - Filtro.Clear() - - If DtPresupuestosTemp.Rows.Count > 0 Then - TmpDT.Rows(grid.RowIndex)("CvePresupuestoEgreso") = DtPresupuestosTemp.Rows(0)("CvePresupuestoEgreso").ToString - TmpDT.Rows(grid.RowIndex)("IdCuentaComprometido") = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString - TmpDT.Rows(grid.RowIndex)("IdCuentaPorEjercer") = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString - TmpDT.Rows(grid.RowIndex)("IdCuentaDevengado") = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString - TmpDT.Rows(grid.RowIndex)("IdCuentaMatriz") = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString - Else - Alert("Ocurrió un error al vincular el Presupuesto de Egreso. Por favor intente de nuevo.", TipoMensaje.MsgAdvertencia) - End If - Next - - End Sub - - Private Sub CompruebaAgregar() - Dim ContPaq As New ClsContPAQi(UsuarioActual.Empresa) - Dim disponible As Double - Dim ErrorPresupuesto = False - Dim Conceptos As New StringBuilder - - Dim Ddl1 As DropDownList - Dim Ddl2 As DropDownList - Dim Ddl3 As DropDownList - Dim Ddl4 As DropDownList - Dim Ddl5 As DropDownList - Dim Total As Double - - Dim DtPresupuestosTemp As DataTable - Dim Filtro As New StringBuilder - - For Each grid As GridViewRow In GvPS.Rows - Ddl1 = grid.FCDropDownList("DdlAC1") - Ddl2 = grid.FCDropDownList("DdlAC2") - Ddl3 = grid.FCDropDownList("DdlAC3") - Ddl4 = grid.FCDropDownList("DdlAC4") - Ddl5 = grid.FCDropDownList("DdlAC5") - Total = grid.Cells(8).ToString.ToDouble - - Filtro.AppendFormat("CveProgramaOperativo = {0} and CveUnidadAdministrativa = {1} and CveFuenteFinanciamiento = {2} and CveTipoGasto= {3} and CveClasificacion = {4}", Ddl1.SelectedValue.ToString, Ddl2.SelectedValue.ToString, Ddl3.SelectedValue.ToString, Ddl4.SelectedValue.ToString, Ddl5.SelectedValue.ToString) - DtPresupuestosTemp = DtPresupuestos.FiltraParametros(Filtro.ToString) - Filtro.Clear() - - If DtPresupuestosTemp IsNot Nothing AndAlso DtPresupuestosTemp.Rows.Count > 0 Then - disponible = ContPaq.GetSaldoCuenta(If(OCVinculada, DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString.ToEntero, DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero), 0, TxtFecha.Text.ToDate.Year) - - If (disponible > 0 AndAlso disponible >= Total) Or DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - 'Alert("Si hay dinero: ") - - TmpDT.Rows(grid.RowIndex)("CvePresupuestoEgreso") = DtPresupuestosTemp.Rows(0)("CvePresupuestoEgreso").ToString - TmpDT.Rows(grid.RowIndex)("IdCuentaComprometido") = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString - TmpDT.Rows(grid.RowIndex)("IdCuentaPorEjercer") = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString - TmpDT.Rows(grid.RowIndex)("IdCuentaDevengado") = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString - TmpDT.Rows(grid.RowIndex)("IdCuentaMatriz") = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString - - grid.Cells(7).BackColor = Drawing.Color.Green - Else - 'Alert("No hay presupuesto asignado", TipoMensaje.MsgAdvertencia) - Conceptos.AppendFormat("
#{0} - {1} - {2}", grid.RowIndex + 1, grid.DataKey("Clasificacion"), grid.DataKey("PS")) - grid.Cells(7).BackColor = Drawing.Color.Red - ErrorPresupuesto = True - End If - - TmpDT.Rows(grid.RowIndex)("CvePresupuestoEgreso") = DtPresupuestosTemp.Rows(0)("CvePresupuestoEgreso").ToString - - Else - TmpDT.Rows(grid.RowIndex)("CvePresupuestoEgreso") = "-1" - 'Alert("No hay presupuesto asignado", TipoMensaje.MsgAdvertencia) - Conceptos.AppendFormat("
#{0} - {1} - {2}", grid.RowIndex + 1, grid.DataKey("Clasificacion"), grid.DataKey("PS")) - grid.Cells(7).BackColor = Drawing.Color.Red - ErrorPresupuesto = True - End If - - Next - - If ErrorPresupuesto Then - Alert(String.Format("No hay presupuesto asignado para los siguientes conceptos: {0}", Conceptos), TipoMensaje.MsgAdvertencia) - BtnGuardar.Enabled = False - Else - BtnGuardar.Enabled = True - End If - UpFacturar.Update() - ContPaq.Dispose() - End Sub - - Private Sub GuardaAC() - Dim dr As DataRow - For Each gvr As GridViewRow In GvPS.Rows - dr = TmpDT.Rows(gvr.RowIndex) - - 'DtDetalle.Rows(gvr.RowIndex)("CveClasificacionOG") = gvr.FCDropDownList("DdlAC5").SelectedValue.ToEntero - 'DtDetalle.Rows(gvr.RowIndex)("CveProgramaOperativo") = gvr.FCDropDownList("DdlAC1").SelectedValue.ToEntero - 'DtDetalle.Rows(gvr.RowIndex)("CveUnidadAdministrativa") = gvr.FCDropDownList("DdlAC2").SelectedValue.ToEntero - 'DtDetalle.Rows(gvr.RowIndex)("CveFuenteFinanciamiento") = gvr.FCDropDownList("DdlAC3").SelectedValue.ToEntero - 'DtDetalle.Rows(gvr.RowIndex)("CveTipoGasto") = gvr.FCDropDownList("DdlAC4").SelectedValue.ToEntero - - dr("CveProgramaOperativo") = gvr.FCDropDownList("DdlAC1").SelectedValue.ToEntero - dr("CveUnidadAdministrativa") = gvr.FCDropDownList("DdlAC2").SelectedValue.ToEntero - dr("CveFuenteFinanciamiento") = gvr.FCDropDownList("DdlAC3").SelectedValue.ToEntero - dr("CveTipoGastoAC") = gvr.FCDropDownList("DdlAC4").SelectedValue.ToEntero - dr("CveClasificacionOG") = gvr.FCDropDownList("DdlAC5").SelectedValue.ToEntero - 'dr("CvePresupuestoEgreso") = gvr.FCHiddenField("HdnCvePresupuestoEgreso").Value.ToString.ToEntero - Next - - TmpDT.AcceptChanges() - End Sub - - Protected Sub BtnCambiaFecha_Click(sender As Object, e As EventArgs) - CambiaEjercicioAC() - End Sub - - Private Sub CambiaEjercicioAC(Optional CargaTodo As Boolean = True) - Dim Ejercicio = If(IsDate(TxtFecha.Text), Year(TxtFecha.Text.ToDate), UsuarioActual.Empresa.EjercicioActual) - - If Ejercicio <> EjercicioAC Then - Dim AC As New ClsAC - If AC.GetPresupuestoEgresos(-1, True, Ejercicio, UsuarioActual.CveEmpresa, True) Then - DtPresupuestos = AC.DtResultados.Copy - CargaPresupuestosEgresos(CargaTodo) - - ConservaAC() - - GvPS.DataSource = TmpDT - GvPS.DataBind() - 'CAMBIA LOS COMBOS DE TODOS LOS DETALLES DEL GRID - For Each gvr As GridViewRow In GvPS.Rows - gvr.FCDropDownList("DdlAC1").SelectedValue = DdlACGeneral1.SelectedValue - gvr.FCDropDownList("DdlAC2").SelectedValue = DdlACGeneral2.SelectedValue - gvr.FCDropDownList("DdlAC3").SelectedValue = DdlACGeneral3.SelectedValue - gvr.FCDropDownList("DdlAC4").SelectedValue = DdlACGeneral4.SelectedValue - gvr.FCDropDownList("DdlAC5").SelectedValue = DdlACGeneral5.SelectedValue - Next - - If CargaTodo Then CompruebaAgregar() - - UpPS.Update() - UpPresupuestosAC.Update() - Else - Alert("Ocurrio un error al cargar los Presupuestos. Por favor vuelva a cargar la página") - End If - AC.Dispose() - - EjercicioAC = Ejercicio - End If - + UpContado.Update() End Sub -#End Region - -#Region "E V E N T O - B I T A C O R A" - Protected Sub GVEventoBitacora_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvEB.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - If e.Row.RowIndex = 0 Then - e.Row.Cells(0).Width = Unit.Pixel(200) - e.Row.Cells(1).Width = Unit.Pixel(200) - e.Row.Cells(2).Width = Unit.Pixel(100) - e.Row.Cells(3).Width = Unit.Pixel(500) - End If - - If e.Row.DBCampo("Archivo").ToString <> "" Then - e.Row.FCLinkButton("LinkArchivo").Visible = True - e.Row.FCLinkButton("LinkArchivo").CommandArgument = String.Format("OI\{0}", e.Row.DBCampo("Archivo").ToString) - ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FCLinkButton("LinkArchivo")) 'Registro un evento Postbacktrigger, que recargue toda la pagina para que funcione - End If - - e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Left - - End If - End Sub - - Protected Sub BtnGuardarEventoBitacora_Click(sender As Object, e As EventArgs) Handles BtnGuardarEventoBitacora.Click - Dim ObjEventoBitacora As New ClsOIEventos - - Dim FileExtension As String = "-1" - Dim Filesgral As List(Of Archivo) = Anexo.getfiles().Archivos - Dim Filename As String = "" - For Each fileItem As Archivo In Filesgral - FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") - Filename = fileItem.filename - Next - - - - If ObjEventoBitacora.AddEventoBitacora(TxtEventoDescripcion.Text.Trim, String.Format(".{0}", FileExtension), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then - If Filename <> "" Then - Filename.FilesMove(String.Format("OI{0}", ObjEventoBitacora.CveEvento.ToString), String.Format("Empresas\{0}\OI", UsuarioActual.CveEmpresa)) - End If - - GvEB.DataSource = ObjEventoBitacora.DtResultados - TxtEventoDescripcion.Text = "" - Anexo.Text = "[]" - Alert("La bitácora/observación se guardó correctamente", TipoMensaje.MsgInformacion) - RegistraScript("$('#ModalBitacora').modal('hide')", "hidemodal") - - End If - ObjEventoBitacora.Dispose() - GvEB.DataBind() - - UPEventoBitacora.Update() - CargaEventoBitacora() - UPAddEventoBitacora.Update() - End Sub - - 'Protected Sub CargarArchivo(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AFU.UploadedComplete - ' If AFU.HasFile Then - - - ' Dim UploadFolder As String = String.Format("{0}\Temp\", UsuarioActual.Empresa.Ruta) - ' UploadFolder.DirectoryExistsCreate() - ' Dim Extension As String = System.IO.Path.GetExtension(AFU.PostedFile.FileName) - - ' If File.Exists(String.Format("{0}{1}{2}", UploadFolder, UsuarioActual.CveUsuario.ToString, Extension)) Then File.Delete(String.Format("{0}{1}{2}", UploadFolder, UsuarioActual.CveUsuario.ToString, Extension)) - - ' AFU.SaveAs(UploadFolder & UsuarioActual.CveUsuario.ToString & Extension) - ' Session("FileUpload") = UploadFolder & UsuarioActual.CveUsuario.ToString & Extension - ' Session("FileExtension") = Extension - ' Session("FileFolder") = UploadFolder - ' End If - 'End Sub - Protected Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs) - Dim filePath As String = String.Format("{0}{1}", UsuarioActual.Empresa.Ruta, CType(sender, LinkButton).CommandArgument) - Dim Archivo As New System.IO.FileInfo(filePath) - - HttpContext.Current.Response.Clear() - HttpContext.Current.Response.ClearContent() - HttpContext.Current.Response.ContentType = "application/octet-stream" - HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(filePath)) - HttpContext.Current.Response.AddHeader("Content-Length", Archivo.Length.ToString()) - HttpContext.Current.Response.TransmitFile(filePath) - HttpContext.Current.Response.Flush() - HttpContext.Current.Response.End() - - Archivo = Nothing - End Sub - - Private Sub CargaEventoBitacora() - - Dim ObjEventoBitacora As New ClsOIEventos() - If ObjEventoBitacora.GetAgendaBitacora(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then - GvEB.DataSource = ObjEventoBitacora.DtResultados.FiltraParametros("CveTipoEvento = 6 OR CveTipoEvento = 2") - Else - GvEB.DataSource = Nothing - End If - ObjEventoBitacora.Dispose() - GvEB.DataBind() + Protected Sub RblRembolso_SelectedIndexChanged(sender As Object, e As EventArgs) + TrRembolsoCajaChica.Visible = False + TrRembolsoPersonal.Visible = False + DdlRembolsoCajaChica.SelectedValueExist("-1") + DdlRembolsoPersonal.SelectedValueExist("-1") + If RblRembolso.SelectedValue.ToEntero = 1 Then + TrRembolsoPersonal.Visible = True + ElseIf RblRembolso.SelectedValue.ToEntero = 2 Then + TrRembolsoCajaChica.Visible = True + End If End Sub -#End Region +#End Region + +#Region "ARMONIZACION CONTABLE - AC - SIMPLIFICADO" + Private Sub CargaPresupuestosEgresos(Optional CargaTodo As Boolean = True) + + 'Seccion Grid + GvPS.Width = 1760 + GvPS.Columns(12).Visible = True + GvPS.Columns(13).Visible = True + GvPS.Columns(14).Visible = True + GvPS.Columns(15).Visible = True + GvPS.Columns(16).Visible = True + + 'Panel General + UpPresupuestosAC.Visible = True + + DdlACGeneral1.Items.Clear() + DdlACGeneral1.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveProgramaOperativo", "ProgramaOperativo"}) + DdlACGeneral1.DataBind() + + DdlACGeneral2.Items.Clear() + DdlACGeneral2.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveUnidadAdministrativa", "UnidadAdministrativa"}, Orderby:="UnidadAdministrativa") + DdlACGeneral2.DataBind() + + DdlACGeneral3.Items.Clear() + DdlACGeneral3.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveFuenteFinanciamiento", "FuenteFinanciamiento"}, Orderby:="FuenteFinanciamiento") + DdlACGeneral3.DataBind() + + DdlACGeneral4.Items.Clear() + DdlACGeneral4.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveTipoGasto", "TipoGasto"}) + DdlACGeneral4.DataBind() + + DdlACGeneral5.Items.Clear() + DdlACGeneral5.DataSource = DtPresupuestos.FiltraParametros("NOT CodigoCOG like '1%'", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") + If UsuarioActual.CveEmpresa.Contiene(120) Then + DdlACGeneral5.DataSource = DtPresupuestos.FiltraParametros("", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") + Else + DdlACGeneral5.DataSource = DtPresupuestos.FiltraParametros("NOT CodigoCOG like '1%'", DistinctColumns:={"CveClasificacion", "CodigoClasificacion"}, Orderby:="CodigoClasificacion") + End If + DdlACGeneral5.DataBind() + + If CveCompra > 0 Then + RegistraScript("$get('DivPresupuestoEgresosGeneral').style.display = 'none';") + BtnVerPE.Visible = True + End If + + If CargaTodo Then + CalculaSaldoACGeneral() + UpPresupuestosAC.Update() + End If -#Region " C O N T A B I L I D A D " - Protected Sub BtnDescontabilizar_Click(sender As Object, e As EventArgs) - 'Alert("Hola entre", TipoMensaje.MsgError) - 'Exit Sub - - Dim ObjConta As New ClsContabilidad - Dim Movimientos = ObjConta.GetMovimientosPoliza(IdPoliza, UsuarioActual.CveEmpresa) - - 'Verifica que solo exista 1 compra asociada - If Movimientos = 1 Then - EliminaPoliza() - Else - RegistraScript("ConfirmEliminarPolizaMultiple();") - End If - - ObjConta.Dispose() - End Sub - Protected Sub LBContabilizarAC_Click(sender As Object, e As EventArgs) - Dim ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) - ObjContaAC.IniciaTransacSQL() - Dim ObjCompras As New ClsCompras - Dim ObjProveedores As New ClsCompProveedores(ObjCompras.IniciaTransacSQL()) - Dim ObjAF As New ClsAF(ObjCompras.IniciaTransacSQL()) - Dim ErrorAC = False - Dim IDPolizaComprometido = If(TxtOC.Text.Length > 0, 1, 0) - - ''EMPIEZA: SI USA AC - If UsuarioActual.Empresa.UsaAC Then - ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) - ObjContaAC.IniciaTransacSQL() - - - 'ELIMINA TODOS LOS MOVIMIENTOS DE LA POLIZA - If IdPoliza > 0 Then - ObjContaAC.RemoveAllMovimientos(IdPoliza) - Else - Dim TotalPorDevengar = Math.Round(TxtTotal.Text.ToDouble, 2) - IdPoliza = ObjContaAC.AddPoliza(3, TxtDescripcion.Text.Trim, TotalPorDevengar, TotalPorDevengar, UsuarioActual.CveUsuario, TxtFecha.Text.ToDate) - End If - - 'INSERTA LOS NUEVOS MOVIMIENTOS DE LA POLIZA - If IdPoliza > 0 Then - Dim CuentaAbono As Integer - Dim Importe As Decimal = 0 - Dim TotalDetalle As Decimal = 0 - - 'CUENTA PROVEEDOR - If CtaProveedor <= 0 Then - If ObjContaAC.GetCuentas(-1, "021120000000000000", -1) Then - Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") - If drCuenta IsNot Nothing Then - CuentaAbono = drCuenta("Id").ToString.ToEntero - Dim FolioProveedor = ObjContaAC.GetFolioProveedores("021120000000000000").ToString - ViewState("CtaProveedor") = ObjContaAC.AddCuenta(String.Format("02112{0}000000000", FolioProveedor.PadLeft(4, "0"c)), NombreProveedor, "D", 2, 0, 1, 0, "", 1, CuentaAbono) - ObjProveedores.UpdateProveedorIdCuentaAC(CveProveedor, CtaProveedor) - Else - ErrorAC = True - End If - Else - ErrorAC = True - End If - End If - - Dim ConceptoRenglon As String = "" - If Not ErrorAC Then - - Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA, tRetIVA, tRetISR As Decimal - - Dim ipresup As Integer = 0 - - 'COMIENZA: PRUEBA AGRUPACION CONCEPTOS - Dim Presup = From gvr As DataRow In TmpDT.Rows.Cast(Of DataRow)() - Group gvr By Grp = New With { - Key .CvePresupuestoEgreso = gvr("CvePresupuestoEgreso").ToString.ToEntero, - Key .CveActivoFijo = If(gvr("TipoAF").ToString.ToEntero = 2, gvr("CveActivoFijo").ToString.ToEntero, -1) - } Into Group - Select Grp.CvePresupuestoEgreso, Grp.CveActivoFijo, - TotalImporte = Group.Sum(Function(r) r("Total").ToString.ToDecimal) - Dim Fecha As Date = TxtFecha.Text.ToDate - - 'PresupuestoEgresos - Dim DtPresupuestosTemp As DataTable - Dim IdCuentaComprometido, IdCuentaPorEjercer, IdCuentaDevengado, IdCuentaMatriz As Integer - - 'Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA As Double - tTotalIVA = TxtIVA.Text.ToDecimal - tRetIVA = TxtRetIVA.Text.ToDecimal - tRetISR = TxtRetISR.Text.ToDecimal - - 'tTotalIVA = tTotalIVA - tRetIVA - tRetISR - - tTotalGral = TxtTotal.Text.ToDecimal + tRetIVA + tRetISR ' EL TOTAL GENERAL DEBE DE SER EL SUBTOTAL + IVA, NO SE DEBEN DE INCLUIR LAS RETENCIONES, POR ESO SE RESTA - tDiferenciaIVA = tTotalIVA - tIVA = 0 - ipresup = 0 - - 'INVENTARIOS EN AC - Dim CuentaMatrizAlmacen As Integer - Dim ContadorInventario As Integer = GvInv.Rows.Cast(Of GridViewRow)().Count(Function(gvr) gvr.FCCheckBox("cbInv").Checked) - - Dim CtaAlmacen As Integer - If ContadorInventario > 0 Then - Dim drr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero)) - If drr IsNot Nothing Then - CtaAlmacen = drr("IdCtaContable").ToString.ToEntero - End If - End If - Dim DescuentoConIVA As Double - Dim tPorIVA As Decimal = tTotalIVA / (tTotalGral - tTotalIVA) - Dim tAjusteTotal As Decimal = 0 - - For Each grp In Presup - Importe = grp.TotalImporte - TotalDetalle += Importe - ipresup += 1 - If Importe > 0 Then - 'saco la proporcion de iva que le corresponde - tIVA = Math.Round(Importe * tPorIVA, 2) - tDiferenciaIVA -= tIVA - 'identifico si es el ultimo registro, para ver si es necesario un ajuste - If ipresup = Presup.Count Then - If Math.Round(TotalDetalle - tTotalGral, 2) <= 0.01 AndAlso tDiferenciaIVA > 0 Then - tIVA += tDiferenciaIVA - End If - End If - - 'le sumo el iva al concepto - Importe += tIVA - 'codigo Provisional, para cuand tenga descuento, solo tome el subtotal * el iva,RMF - If TxtDescuento.Text.ToDouble > 0 Then - Importe = grp.TotalImporte * (1 + tPorIVA) - End If - - tAjusteTotal += Importe - - 'valido que la sumas de lo detalles no exceda al totalgeneral - If Math.Round(tAjusteTotal, 2) > tTotalGral Then - 'le resto la diferencia - Importe -= (tAjusteTotal - tTotalGral) - End If - - 'Presupuesto Egresos - DtPresupuestosTemp = DtPresupuestos.FiltraParametros(String.Format("CvePresupuestoEgreso = {0}", grp.CvePresupuestoEgreso)) - If DtPresupuestosTemp.Rows.Count <> 1 Then - ErrorAC = True - Exit For - End If - IdCuentaComprometido = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString.ToEntero - IdCuentaPorEjercer = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero - IdCuentaDevengado = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString.ToEntero - IdCuentaMatriz = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString.ToEntero - - 'COMPROMETIDO DEPENDIENTE SI EXISTE SU POLIZA - If IDPolizaComprometido = 0 Then - ConceptoRenglon = String.Format("GC Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, False, Importe, "", ConceptoRenglon, 0, Fecha, "") Then - If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaPorEjercer, True, Importe, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - Exit For - End If - Else - ErrorAC = True - Exit For - End If - End If - - ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - 'DEVENGADO - If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaDevengado, False, Importe, "", ConceptoRenglon, 0, Fecha, "") Then - If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, True, Importe, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - Exit For - End If - Else - ErrorAC = True - Exit For - End If - - - If ContadorInventario > 0 Then - Dim tImporte, ttIVA As Double - - For Each gvr As GridViewRow In GvPS.Rows - 'registra los movimientos del presupuesto asignado, para que no se duplique si hay varios presupeusto dentro de la compra - If gvr.DataKey("CvePresupuestoEgreso").ToEntero = grp.CvePresupuestoEgreso Then - 'saco la proporcion de iva que le corresponde - tImporte = gvr.FCLiteral("LtlTotal").Text.ToDouble - ttIVA = Math.Round(tImporte * tTotalIVA / tTotalGral, 2) - tImporte += ttIVA - End If - - Next - - CuentaMatrizAlmacen = CtaAlmacen - - ElseIf grp.CveActivoFijo > 0 Then - - Dim CtaAF = -1 - Dim AF = "" - Dim CuentaInicial = -1 - - If ObjAF.GetActivosFijos(grp.CveActivoFijo, UsuarioActual.CveEmpresa, "-1", "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "", -1, UsuarioActual.CveEmpresa) Then - CtaAF = ObjAF.Cuenta - AF = ObjAF.Descripcion - CuentaInicial = ObjAF.CuentaInicial - Else - ErrorAC = True - Exit For - End If - - If Not CuentaInicial > 0 Then - CuentaInicial = 1241 - End If - - 'CUENTA AF - If CtaAF <= 0 Then - If ObjContaAC.GetCuentas(-1, String.Format("0{0}0000000000000", CuentaInicial), -1) Then - Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") - If drCuenta IsNot Nothing Then - - CuentaAbono = drCuenta("Id").ToString.ToEntero - Dim FolioAF = ObjContaAC.GetFolioProveedores(String.Format("0{0}0000000000000", CuentaInicial)).ToString - CtaAF = ObjContaAC.AddCuenta(String.Format("0{0}{1}000000000", CuentaInicial, FolioAF.PadLeft(4, "0"c)), AF, "A", 2, 0, 1, 0, "", 1, CuentaAbono) - - ObjAF.UpdateActivosFijosCuentaAC(grp.CveActivoFijo, CtaAF, UsuarioActual.CveUsuario) - Else - ErrorAC = True - End If - Else - ErrorAC = True - End If - End If - - CuentaMatrizAlmacen = CtaAF - Else - CuentaMatrizAlmacen = IdCuentaMatriz - End If - - - ''AFECTAR MATRIZ EGRESOS - If ObjContaAC.AddMovimiento(IdPoliza, CuentaMatrizAlmacen, False, Importe, "", ConceptoRenglon, 0, Fecha, "") Then - - ''VERIFICA SI TIENE DESCUENTO (AMORTIZACION) - If TxtDescuento.Text.ToDouble > 0 AndAlso CtaProveedorAnticipos > 0 Then - DescuentoConIVA = TxtDescuento.Text.ToDecimal * 1.16 - - 'Valida que el descuento con iva cuadre en los totales - If Math.Abs(DescuentoConIVA - (Importe - TxtTotal.Text.ToDouble)) < 0.02 Then - DescuentoConIVA = Importe - TxtTotal.Text.ToDouble - ElseIf DescuentoConIVA <> (Importe - TxtTotal.Text.ToDecimal) Then - ErrorAC = True - Exit For - End If - - 'actualizo el idcuenta del presupuesto - If ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, (Importe - DescuentoConIVA), "", ConceptoRenglon, 0, Fecha, "") Then - 'agrego a la cuenta contable anticipos - If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorAnticipos, True, DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - Exit For - End If - Else - ErrorAC = True - Exit For - End If - Else - 'actualizo el idcuenta del - - End If - - Else - ErrorAC = True - Exit For - End If - ''TERMINA AFECTAR MATRIZ EGRESOS - - Else - ErrorAC = True - Exit For - End If - - Next - - If Not ErrorAC Then - 'registro un solo movimiento a proveedores - Importe = TxtTotal.Text.ToDecimal - If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, Importe, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - End If - End If - - If tRetISR > 0 Then - ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) - If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorRetISR, True, tRetISR, "", ConceptoRenglon, 0, Fecha, "") Then - ErrorAC = True - End If - End If - - End If - - Else - ErrorAC = True - End If - - 'CUADRA LA POLIZA - ObjContaAC.AjustaPoliza(IdPoliza) - - End If - ''TERMINA: SI USA AC - - If Not ErrorAC Then - If Not ObjCompras.UpdateCompraPoliza(IdPoliza, CveCompra) Then - ErrorAC = True - End If - End If - - - If ErrorAC Then - - - - Alert("Ocurrió un error al contabilizar la compra. Comuniquese con soporte.", TipoMensaje.MsgError) - ObjContaAC.RollBack() - ObjCompras.RollBack() - Else - ObjContaAC.Commit() - ObjCompras.Commit() - Alert("La Compra se contabilizó correctamente.", TipoMensaje.MsgInformacion) - - HplCompraContabilizada.Text = "Si" - HplCompraContabilizada.NavigateUrl = String.Format("/Contabilidad/RegPoliza.aspx?IdPoliza={0}", IdPoliza) - LblCompraEstatus.ForeColor = Drawing.Color.Navy - trContabilizada.Visible = True - UpEstatus.Update() - End If - ObjContaAC.Dispose() - - End Sub - - Protected Sub BtnEliminarPoliza_Click(sender As Object, e As EventArgs) - EliminaPoliza() - End Sub - - Private Sub EliminaPoliza() - Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa) - ObjAC.IniciaTransacSQL() - Dim ObjConta As New ClsContabilidad - ObjConta.IniciaTransacSQL() - - Dim ErrorCompra = False - - 'Elimina la poliza - If (UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.UsaContabilidad) AndAlso IdPoliza > 0 Then - If Not ObjAC.RemovePoliza(IdPoliza) Then - ErrorCompra = True - End If - End If - - 'Desasocia la poliza - If Not ErrorCompra Then - If Not ObjConta.DesasociarPoliza(IdPoliza, UsuarioActual.CveEmpresa) Then - ErrorCompra = True - End If - End If - - If Not ErrorCompra Then - If Not ObjConta.UpdatePrePolizasDetalleBloquear(CvePrePoliza, False) Then - ErrorCompra = True - End If - End If - - If Not ErrorCompra Then - Alert("La poliza ha sido desvinculada y eliminada con exito.", TipoMensaje.MsgInformacion) - ObjAC.Commit() - ObjConta.Commit() - - Else - Alert("Ocurrió un error al desvincular y/o eliminar la poliza. Por favor intente de nuevo ", TipoMensaje.MsgError) - ObjAC.RollBack() - ObjConta.RollBack() - End If - - ObjAC.Dispose() - ObjConta.Dispose() - - If Not ErrorCompra Then - CargaCompra() - End If End Sub -#End Region - -#Region " REEMBOLSOS NO USA AC " - Protected Sub DdlPersonal2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPersonalReembolso.SelectedIndexChanged - ViewState("CvePersonal") = DdlPersonalReembolso.SelectedValue - End Sub - Protected Sub DdlCajaChica2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuentaCajaChicaReembolso.SelectedIndexChanged - Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltroPrimero("CveCuenta = " & DdlCuentaCajaChicaReembolso.SelectedValue) - - If dr IsNot Nothing Then - CveMoneda = dr("CveMoneda").ToString.ToEntero - IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero - CveCuentaBancaria = dr("IdCtaContableSIG").ToString.ToEntero - End If - ViewState("CveCajaChica") = DdlCuentaCajaChicaReembolso.SelectedValue + Private Sub ConservaAC() + 'Guarda valores AC en TmpDT + Dim Index = 0 + For Each gvr As GridViewRow In GvPS.Rows + TmpDT.Rows(Index)("CveProgramaOperativo") = gvr.FCDropDownList("DdlAC1").SelectedValue.ToEntero + TmpDT.Rows(Index)("CveUnidadAdministrativa") = gvr.FCDropDownList("DdlAC2").SelectedValue.ToEntero + TmpDT.Rows(Index)("CveFuenteFinanciamiento") = gvr.FCDropDownList("DdlAC3").SelectedValue.ToEntero + TmpDT.Rows(Index)("CveTipoGastoAC") = gvr.FCDropDownList("DdlAC4").SelectedValue.ToEntero + TmpDT.Rows(Index)("CveClasificacionOG") = gvr.FCDropDownList("DdlAC5").SelectedValue.ToEntero + Index += 1 + Next End Sub -#End Region -#Region " ALMACEN " + Protected Sub CompruebaSaldoAC(sender As Object, e As EventArgs) + ConservaAC() -#End Region - -#Region " CONSIGNACIONES " - Protected Sub ChkConsignacion_CheckedChanged(sender As Object, e As EventArgs) - - If ChkConsignacion.Checked Then - 'LiConsignacion.Visible = True - GvInv.Columns(7).Visible = True - GvInv.Columns(8).Visible = True - CargaConsignaciones2() - - CargaGvInv() - - GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True - GvInv.HeaderRow.FCCheckBox("cbAll").Enabled = False - - BtnVinculaConsignacion.Visible = True - - BtnGuardar.Enabled = False - UpFacturar.Update() - Else - GvInv.Columns(7).Visible = False - GvInv.Columns(8).Visible = False - 'LiConsignacion.Visible = False - CveConsignacion = -1 - - GvInv.HeaderRow.FCCheckBox("cbAll").Checked = False - GvInv.HeaderRow.FCCheckBox("cbAll").Enabled = True - - BtnVinculaConsignacion.Visible = False - - CargaGvInv() - - BtnGuardar.Enabled = True - UpFacturar.Update() - End If - - cbAll_CheckedChanged(GvInv.HeaderRow.FCCheckBox("cbAll"), EventArgs.Empty) - UpConsignaciones.Update() - End Sub - Private Sub CargaConsignaciones() - If DdlProveedor.SelectedValue.ToEntero > 0 Then - 'Dim ObjInventarios As New ClsInventarios - - 'If ObjInventarios.GetConsignaciones2(-1, UsuarioActual.CveEmpresa) Then - ' DdlConsignacion.DataSource = ObjInventarios.DtResultados.FiltraParametros(String.Format("CveProveedor = {0}", DdlProveedor.SelectedValue.ToEntero)) - 'Else - ' DdlConsignacion.DataSource = Nothing - 'End If - - 'ObjInventarios.Dispose() - - 'DdlConsignacion.DataBind() - 'DdlConsignacion.Items.Insert(0, New ListItem("Seleccione", "-1")) - End If - End Sub - Private Sub CargaConsignaciones2() - Dim ObjInventarios As New ClsInventarios - Dim TieneError = False - - CveConsignacion = -1 - - If ObjInventarios.GetConsignacionesDetalleProveedor(DdlProveedor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then - DtConsignaciones = ObjInventarios.DtResultados - Else - TieneError = True - End If - - If DtConsignaciones IsNot Nothing AndAlso DtConsignaciones.Rows.Count > 0 Then - 'CveConsignacion = DdlConsignacion.SelectedValue.ToEntero - CveConsignacion = 1 - 'CveAlmacenConsignacion = ObjInventarios.DtResultados.Rows(0)("CveAlmacen").ToString.ToEntero - End If - - If TieneError Then - Alert("Ocurrió un error al cargar la consignación. Por favor vuelva a intentar.", TipoMensaje.MsgError) - DtConsignaciones = Nothing - End If - - ObjInventarios.Dispose() - - CargaGvInv() - End Sub - Protected Sub BtnVinculaConsignacion_Click(sender As Object, e As EventArgs) - Dim ObjInventarios As New ClsInventarios - Dim TieneError = False - - CveConsignacion = -1 - - If ObjInventarios.GetConsignacionesDetalleProveedor(DdlProveedor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then - DtConsignaciones = ObjInventarios.DtResultados - Else - TieneError = True - End If - - If DtConsignaciones.Rows.Count > 0 Then - 'CveConsignacion = DdlConsignacion.SelectedValue.ToEntero - CveConsignacion = 1 - CveAlmacenConsignacion = ObjInventarios.DtResultados.Rows(0)("CveAlmacen").ToString.ToEntero - End If - - If TieneError Then - Alert("Ocurrió un error al cargar la consignación. Por favor vuelva a intentar.", TipoMensaje.MsgError) - DtConsignaciones = Nothing - End If - - ObjInventarios.Dispose() - - CargaGvInv() - 'If DtConsignaciones IsNot Nothing Then - ' GvConsignaciones.DataSource = DtConsignaciones - ' GvConsignaciones.DataBind() - 'End If - - 'UpConsignaciones.Update() - End Sub - Protected Sub GvConsignaciones_RowDataBound(sender As Object, e As GridViewRowEventArgs) 'Handles GvConsignaciones.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - - e.Row.FCDropDownList("DdlVinculaConsignacion").DataSource = TmpDT - e.Row.FCDropDownList("DdlVinculaConsignacion").DataBind() - e.Row.FCDropDownList("DdlVinculaConsignacion").Items.Insert(0, New ListItem("Seleccione", "-1")) - - End If - End Sub - Protected Sub DdlVinculaConsignacion_SelectedIndexChanged(sender As Object, e As EventArgs) - Dim Ddl As DropDownList = DirectCast(sender, DropDownList) - Dim gvr As GridViewRow = DirectCast(Ddl.BindingContainer, GridViewRow) - - If Ddl.SelectedValue = "-1" Then - - gvr.FCHiddenField("HdnPS").Value = "-1" - gvr.FCHiddenField("HdnCvePS").Value = "-1" - gvr.FCHiddenField("HdnClasificacion").Value = "-1" - gvr.FCHiddenField("HdnCveClasificacion").Value = "-1" - gvr.FCHiddenField("HdnCveAlmacen").Value = "-1" - - gvr.FCHiddenField("HdnNoConsignacion").Value = "-1" - gvr.FCHiddenField("HdnCveConsignacion").Value = "-1" - - 'GUARDA VALORES POR UNA RECARGA (DIVISION DE CONCEPTO) - TmpDT.Rows(gvr.RowIndex)("CveAlmacenConsignacion") = "-1" - TmpDT.Rows(gvr.RowIndex)("NoConsignacion") = "-1" - TmpDT.Rows(gvr.RowIndex)("CveConsignacion") = "-1" - - TmpDT.Rows(gvr.RowIndex)("HdnPS") = "-1" - TmpDT.Rows(gvr.RowIndex)("HdnCvePS") = "-1" - TmpDT.Rows(gvr.RowIndex)("HdnClasificacion") = "-1" - TmpDT.Rows(gvr.RowIndex)("HdnCveClasificacion") = "-1" - TmpDT.Rows(gvr.RowIndex)("HdnCveAlmacen") = "-1" - Exit Sub - End If - - Dim Row = DtConsignaciones.Rows(Ddl.SelectedValue.ToEntero - 1) - - 'VALIDAMOS CANTIDAD - Dim Cantidad = Row("Cantidad").ToString.ToDecimal - For Each gvr1 As GridViewRow In GvInv.Rows - If gvr1.FCHiddenField("HdnNoConsignacion").Value.ToString = Ddl.SelectedValue Then - Cantidad = Cantidad - gvr1.DataKey("Cantidad").ToString.ToDecimal - End If - Next - - If Cantidad - gvr.DataKey("Cantidad").ToString.ToDecimal < 0 Then - Ddl.SelectedValue = "-1" - - gvr.FCHiddenField("HdnPS").Value = "-1" - gvr.FCHiddenField("HdnCvePS").Value = "-1" - gvr.FCHiddenField("HdnClasificacion").Value = "-1" - gvr.FCHiddenField("HdnCveClasificacion").Value = "-1" - gvr.FCHiddenField("HdnCveAlmacen").Value = "-1" - - gvr.FCHiddenField("HdnNoConsignacion").Value = "-1" - gvr.FCHiddenField("HdnCveConsignacion").Value = "-1" - - 'GUARDA VALORES POR UNA RECARGA (DIVISION DE CONCEPTO) - TmpDT.Rows(gvr.RowIndex)("CveAlmacenConsignacion") = "-1" - TmpDT.Rows(gvr.RowIndex)("NoConsignacion") = "-1" - TmpDT.Rows(gvr.RowIndex)("CveConsignacion") = "-1" - - TmpDT.Rows(gvr.RowIndex)("HdnPS") = "-1" - TmpDT.Rows(gvr.RowIndex)("HdnCvePS") = "-1" - TmpDT.Rows(gvr.RowIndex)("HdnClasificacion") = "-1" - TmpDT.Rows(gvr.RowIndex)("HdnCveClasificacion") = "-1" - TmpDT.Rows(gvr.RowIndex)("HdnCveAlmacen") = "-1" - - Alert("El concepto que desea vincular excede la cantidad del inventario de consignación.", TipoMensaje.MsgAdvertencia) - Else - gvr.FCHiddenField("HdnPS").Value = Row("PS").ToString - gvr.FCHiddenField("HdnCvePS").Value = Row("CvePS").ToString - gvr.FCHiddenField("HdnClasificacion").Value = Row("Clasificacion").ToString - gvr.FCHiddenField("HdnCveClasificacion").Value = Row("CveClasificacion").ToString - gvr.FCHiddenField("HdnCveAlmacen").Value = Row("CveAlmacenSalida").ToString - - gvr.FCHiddenField("HdnNoConsignacion").Value = Ddl.SelectedValue.ToEntero.ToString - gvr.FCHiddenField("HdnCveConsignacion").Value = Row("CveConsignacion").ToString - - 'GUARDA VALORES POR UNA RECARGA (DIVISION DE CONCEPTO) - TmpDT.Rows(gvr.RowIndex)("CveAlmacenConsignacion") = gvr.FCDropDownList("ddlAlmacenConsignacion").SelectedValue.ToEntero - TmpDT.Rows(gvr.RowIndex)("NoConsignacion") = Ddl.SelectedValue.ToEntero - TmpDT.Rows(gvr.RowIndex)("CveConsignacion") = Row("CveConsignacion").ToString - - TmpDT.Rows(gvr.RowIndex)("HdnPS") = Row("PS").ToString - TmpDT.Rows(gvr.RowIndex)("HdnCvePS") = Row("CvePS").ToString - TmpDT.Rows(gvr.RowIndex)("HdnClasificacion") = Row("Clasificacion").ToString - TmpDT.Rows(gvr.RowIndex)("HdnCveClasificacion") = Row("CveClasificacion").ToString - TmpDT.Rows(gvr.RowIndex)("HdnCveAlmacen") = Row("CveAlmacenSalida").ToString - End If - - - End Sub - Protected Sub ddlAlmacenConsignacionGeneral_SelectedIndexChanged(sender As Object, e As EventArgs) - Dim DdlAlmacenConsignacionGeneral = CType(sender, DropDownList) - - For Each gvr As GridViewRow In GvInv.Rows - gvr.FCDropDownList("ddlAlmacenConsignacion").SelectedValue = DdlAlmacenConsignacionGeneral.SelectedValue - - gvr.FCDropDownList("ddlVinculaConsignacion").DataSource = DtConsignaciones.FiltraParametros(String.Format("CveAlmacenSalida = {0} OR {0} = '-1'", gvr.FCDropDownList("ddlAlmacenConsignacion").SelectedValue)) - gvr.FCDropDownList("ddlVinculaConsignacion").DataBind() - gvr.FCDropDownList("ddlVinculaConsignacion").Items.Insert(0, New ListItem("Seleccione", "-1")) - Next - - UpINV.Update() - End Sub - Protected Sub ddlAlmacenConsignacion_SelectedIndexChanged(sender As Object, e As EventArgs) - Dim DdlAlmacenConsignacion = CType(sender, DropDownList) - Dim DdlVinculaConsignacion = CType(CType(sender, DropDownList).NamingContainer, GridViewRow).FCDropDownList("DdlVinculaConsignacion") - - ''CARGA CONSIGNACIONES - DdlVinculaConsignacion.DataSource = DtConsignaciones.FiltraParametros(String.Format("CveAlmacenSalida = {0} OR {0} = '-1'", DdlAlmacenConsignacion.SelectedValue)) - DdlVinculaConsignacion.DataBind() - DdlVinculaConsignacion.Items.Insert(0, New ListItem("Seleccione", "-1")) - - UpINV.Update() - End Sub - Protected Sub BtnVinculaConsignacion_Click1(sender As Object, e As EventArgs) - - 'VALIDACIONES - For Each gvr As GridViewRow In GvInv.Rows - If gvr.FCDropDownList("DdlVinculaConsignacion").SelectedValue = "-1" Then - Alert("Debe vincular todos los conceptos para realizar la vinculación de consignación.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - Next - - 'CambiaPS - For Each gvr As GridViewRow In GvInv.Rows - TmpDT.Rows(gvr.RowIndex)("PS") = gvr.FCHiddenField("HdnPS").Value - TmpDT.Rows(gvr.RowIndex)("CvePS") = gvr.FCHiddenField("HdnCvePS").Value - TmpDT.Rows(gvr.RowIndex)("Clasificacion") = gvr.FCHiddenField("HdnClasificacion").Value - TmpDT.Rows(gvr.RowIndex)("CveClasificacion") = gvr.FCHiddenField("HdnCveClasificacion").Value - Next - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - 'Bloqueamos todo para respetar cambios realizados - DtInv = TmpDT - ChkConsignacion.Enabled = False - BtnVinculaConsignacion.Enabled = False - UpConsignaciones.Update() - - GvInv.Enabled = False - UpINV.Update() - GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True - cbAll_CheckedChanged(GvInv.HeaderRow.FCCheckBox("cbAll"), EventArgs.Empty) - - BtnGuardar.Enabled = True - UpFacturar.Update() - + CompruebaAgregar() End Sub -#End Region -#Region " ***** Devoluciones INV ***** " + Protected Sub CambiaACGeneral(sender As Object, e As EventArgs) + + If ChkACGeneral.Checked Then + + 'CAMBIA LOS COMBOS DE TODOS LOS DETALLES DEL GRID + For Each gvr As GridViewRow In GvPS.Rows + + 'SI VIENE DESDE OC EL PE NO SE MUEVE + If Not gvr.DataKey("CveOrdenCompraDetalle").ToEntero > 0 Then + gvr.FCDropDownList("DdlAC1").SelectedValue = DdlACGeneral1.SelectedValue + gvr.FCDropDownList("DdlAC2").SelectedValue = DdlACGeneral2.SelectedValue + gvr.FCDropDownList("DdlAC3").SelectedValue = DdlACGeneral3.SelectedValue + gvr.FCDropDownList("DdlAC4").SelectedValue = DdlACGeneral4.SelectedValue + gvr.FCDropDownList("DdlAC5").SelectedValue = DdlACGeneral5.SelectedValue + End If + Next + + ConservaAC() + CompruebaAgregar() + UpPS.Update() + + End If + + CalculaSaldoACGeneral() + UpPresupuestosAC.Update() + + End Sub + + Private Sub CalculaSaldoACGeneral() + Dim ContPaq As New ClsContPAQi(UsuarioActual.Empresa) + Dim DtPresupuestosTemp = DtPresupuestos.FiltraParametros(String.Format("CveProgramaOperativo = {0} and CveUnidadAdministrativa = {1} and CveFuenteFinanciamiento = {2} and CveTipoGasto= {3} and CveClasificacion = {4}", DdlACGeneral1.SelectedValue.ToString, DdlACGeneral2.SelectedValue.ToString, DdlACGeneral3.SelectedValue.ToString, DdlACGeneral4.SelectedValue.ToString, DdlACGeneral5.SelectedValue.ToString)) + If DtPresupuestosTemp.Rows.Count > 0 Then + Dim IdCuenta = If(HdnVCveOC.Value <> "-1", DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString.ToEntero, DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero) + + LbACGeneralSaldo.Text = ContPaq.GetSaldoCuenta(IdCuenta, 0, TxtFecha.Text.ToDate.Year).ToString.FormatoNumero(2) + Else + LbACGeneralSaldo.Text = "0.00" + End If + ContPaq.Dispose() + End Sub + + Private Sub CargaHidendsAC() + Dim DtPresupuestosTemp As DataTable + Dim Filtro As New StringBuilder + + For Each grid As GridViewRow In GvPS.Rows + Filtro.AppendFormat("CveProgramaOperativo = {0} and CveUnidadAdministrativa = {1} and CveFuenteFinanciamiento = {2} and CveTipoGasto= {3} and CveClasificacion = {4}", grid.FCDropDownList("DdlAC1").SelectedValue.ToString, grid.FCDropDownList("DdlAC2").SelectedValue.ToString, grid.FCDropDownList("DdlAC3").SelectedValue.ToString, grid.FCDropDownList("DdlAC4").SelectedValue.ToString, grid.FCDropDownList("DdlAC5").SelectedValue.ToString) + DtPresupuestosTemp = DtPresupuestos.FiltraParametros(Filtro.ToString) + Filtro.Clear() + + If DtPresupuestosTemp.Rows.Count > 0 Then + TmpDT.Rows(grid.RowIndex)("CvePresupuestoEgreso") = DtPresupuestosTemp.Rows(0)("CvePresupuestoEgreso").ToString + TmpDT.Rows(grid.RowIndex)("IdCuentaComprometido") = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString + TmpDT.Rows(grid.RowIndex)("IdCuentaPorEjercer") = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString + TmpDT.Rows(grid.RowIndex)("IdCuentaDevengado") = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString + TmpDT.Rows(grid.RowIndex)("IdCuentaMatriz") = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString + Else + Alert("Ocurrió un error al vincular el Presupuesto de Egreso. Por favor intente de nuevo.", TipoMensaje.MsgAdvertencia) + End If + Next + + End Sub + + Private Sub CompruebaAgregar() + Dim ContPaq As New ClsContPAQi(UsuarioActual.Empresa) + Dim disponible As Double + Dim ErrorPresupuesto = False + Dim Conceptos As New StringBuilder + + Dim Ddl1 As DropDownList + Dim Ddl2 As DropDownList + Dim Ddl3 As DropDownList + Dim Ddl4 As DropDownList + Dim Ddl5 As DropDownList + Dim Total As Double + + Dim DtPresupuestosTemp As DataTable + Dim Filtro As New StringBuilder + + For Each grid As GridViewRow In GvPS.Rows + Ddl1 = grid.FCDropDownList("DdlAC1") + Ddl2 = grid.FCDropDownList("DdlAC2") + Ddl3 = grid.FCDropDownList("DdlAC3") + Ddl4 = grid.FCDropDownList("DdlAC4") + Ddl5 = grid.FCDropDownList("DdlAC5") + Total = grid.Cells(8).ToString.ToDouble + + Filtro.AppendFormat("CveProgramaOperativo = {0} and CveUnidadAdministrativa = {1} and CveFuenteFinanciamiento = {2} and CveTipoGasto= {3} and CveClasificacion = {4}", Ddl1.SelectedValue.ToString, Ddl2.SelectedValue.ToString, Ddl3.SelectedValue.ToString, Ddl4.SelectedValue.ToString, Ddl5.SelectedValue.ToString) + DtPresupuestosTemp = DtPresupuestos.FiltraParametros(Filtro.ToString) + Filtro.Clear() + + If DtPresupuestosTemp IsNot Nothing AndAlso DtPresupuestosTemp.Rows.Count > 0 Then + disponible = ContPaq.GetSaldoCuenta(If(OCVinculada, DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString.ToEntero, DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero), 0, TxtFecha.Text.ToDate.Year) + + If (disponible > 0 AndAlso disponible >= Total) Or DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + 'Alert("Si hay dinero: ") + + TmpDT.Rows(grid.RowIndex)("CvePresupuestoEgreso") = DtPresupuestosTemp.Rows(0)("CvePresupuestoEgreso").ToString + TmpDT.Rows(grid.RowIndex)("IdCuentaComprometido") = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString + TmpDT.Rows(grid.RowIndex)("IdCuentaPorEjercer") = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString + TmpDT.Rows(grid.RowIndex)("IdCuentaDevengado") = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString + TmpDT.Rows(grid.RowIndex)("IdCuentaMatriz") = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString + + grid.Cells(7).BackColor = Drawing.Color.Green + Else + 'Alert("No hay presupuesto asignado", TipoMensaje.MsgAdvertencia) + Conceptos.AppendFormat("
#{0} - {1} - {2}", grid.RowIndex + 1, grid.DataKey("Clasificacion"), grid.DataKey("PS")) + grid.Cells(7).BackColor = Drawing.Color.Red + ErrorPresupuesto = True + End If + + TmpDT.Rows(grid.RowIndex)("CvePresupuestoEgreso") = DtPresupuestosTemp.Rows(0)("CvePresupuestoEgreso").ToString + + Else + TmpDT.Rows(grid.RowIndex)("CvePresupuestoEgreso") = "-1" + 'Alert("No hay presupuesto asignado", TipoMensaje.MsgAdvertencia) + Conceptos.AppendFormat("
#{0} - {1} - {2}", grid.RowIndex + 1, grid.DataKey("Clasificacion"), grid.DataKey("PS")) + grid.Cells(7).BackColor = Drawing.Color.Red + ErrorPresupuesto = True + End If + + Next + + If ErrorPresupuesto Then + Alert(String.Format("No hay presupuesto asignado para los siguientes conceptos: {0}", Conceptos), TipoMensaje.MsgAdvertencia) + BtnGuardar.Enabled = False + Else + BtnGuardar.Enabled = True + End If + UpFacturar.Update() + ContPaq.Dispose() + End Sub + + Private Sub GuardaAC() + Dim dr As DataRow + For Each gvr As GridViewRow In GvPS.Rows + dr = TmpDT.Rows(gvr.RowIndex) + + 'DtDetalle.Rows(gvr.RowIndex)("CveClasificacionOG") = gvr.FCDropDownList("DdlAC5").SelectedValue.ToEntero + 'DtDetalle.Rows(gvr.RowIndex)("CveProgramaOperativo") = gvr.FCDropDownList("DdlAC1").SelectedValue.ToEntero + 'DtDetalle.Rows(gvr.RowIndex)("CveUnidadAdministrativa") = gvr.FCDropDownList("DdlAC2").SelectedValue.ToEntero + 'DtDetalle.Rows(gvr.RowIndex)("CveFuenteFinanciamiento") = gvr.FCDropDownList("DdlAC3").SelectedValue.ToEntero + 'DtDetalle.Rows(gvr.RowIndex)("CveTipoGasto") = gvr.FCDropDownList("DdlAC4").SelectedValue.ToEntero + + dr("CveProgramaOperativo") = gvr.FCDropDownList("DdlAC1").SelectedValue.ToEntero + dr("CveUnidadAdministrativa") = gvr.FCDropDownList("DdlAC2").SelectedValue.ToEntero + dr("CveFuenteFinanciamiento") = gvr.FCDropDownList("DdlAC3").SelectedValue.ToEntero + dr("CveTipoGastoAC") = gvr.FCDropDownList("DdlAC4").SelectedValue.ToEntero + dr("CveClasificacionOG") = gvr.FCDropDownList("DdlAC5").SelectedValue.ToEntero + 'dr("CvePresupuestoEgreso") = gvr.FCHiddenField("HdnCvePresupuestoEgreso").Value.ToString.ToEntero + Next + + TmpDT.AcceptChanges() + End Sub + + Protected Sub BtnCambiaFecha_Click(sender As Object, e As EventArgs) + CambiaEjercicioAC() + End Sub + + Private Sub CambiaEjercicioAC(Optional CargaTodo As Boolean = True) + Dim Ejercicio = If(IsDate(TxtFecha.Text), Year(TxtFecha.Text.ToDate), UsuarioActual.Empresa.EjercicioActual) + + If Ejercicio <> EjercicioAC Then + Dim AC As New ClsAC + If AC.GetPresupuestoEgresos(-1, True, Ejercicio, UsuarioActual.CveEmpresa, True) Then + DtPresupuestos = AC.DtResultados.Copy + CargaPresupuestosEgresos(CargaTodo) + + ConservaAC() + + GvPS.DataSource = TmpDT + GvPS.DataBind() + 'CAMBIA LOS COMBOS DE TODOS LOS DETALLES DEL GRID + For Each gvr As GridViewRow In GvPS.Rows + gvr.FCDropDownList("DdlAC1").SelectedValue = DdlACGeneral1.SelectedValue + gvr.FCDropDownList("DdlAC2").SelectedValue = DdlACGeneral2.SelectedValue + gvr.FCDropDownList("DdlAC3").SelectedValue = DdlACGeneral3.SelectedValue + gvr.FCDropDownList("DdlAC4").SelectedValue = DdlACGeneral4.SelectedValue + gvr.FCDropDownList("DdlAC5").SelectedValue = DdlACGeneral5.SelectedValue + Next + + If CargaTodo Then CompruebaAgregar() + + UpPS.Update() + UpPresupuestosAC.Update() + Else + Alert("Ocurrio un error al cargar los Presupuestos. Por favor vuelva a cargar la página") + End If + AC.Dispose() + + EjercicioAC = Ejercicio + End If + + End Sub + +#End Region + +#Region "E V E N T O - B I T A C O R A" + Protected Sub GVEventoBitacora_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvEB.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + If e.Row.RowIndex = 0 Then + e.Row.Cells(0).Width = Unit.Pixel(200) + e.Row.Cells(1).Width = Unit.Pixel(200) + e.Row.Cells(2).Width = Unit.Pixel(100) + e.Row.Cells(3).Width = Unit.Pixel(500) + End If + + If e.Row.DBCampo("Archivo").ToString <> "" Then + e.Row.FCLinkButton("LinkArchivo").Visible = True + e.Row.FCLinkButton("LinkArchivo").CommandArgument = String.Format("OI\{0}", e.Row.DBCampo("Archivo").ToString) + ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FCLinkButton("LinkArchivo")) 'Registro un evento Postbacktrigger, que recargue toda la pagina para que funcione + End If + + e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Left + + End If + End Sub + + Protected Sub BtnGuardarEventoBitacora_Click(sender As Object, e As EventArgs) Handles BtnGuardarEventoBitacora.Click + Dim ObjEventoBitacora As New ClsOIEventos + + Dim FileExtension As String = "-1" + Dim Filesgral As List(Of Archivo) = Anexo.getfiles().Archivos + Dim Filename As String = "" + For Each fileItem As Archivo In Filesgral + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") + Filename = fileItem.filename + Next + + + + If ObjEventoBitacora.AddEventoBitacora(TxtEventoDescripcion.Text.Trim, String.Format(".{0}", FileExtension), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then + If Filename <> "" Then + Filename.FilesMove(String.Format("OI{0}", ObjEventoBitacora.CveEvento.ToString), String.Format("Empresas\{0}\OI", UsuarioActual.CveEmpresa)) + End If + + GvEB.DataSource = ObjEventoBitacora.DtResultados + TxtEventoDescripcion.Text = "" + Anexo.Text = "[]" + Alert("La bitácora/observación se guardó correctamente", TipoMensaje.MsgInformacion) + RegistraScript("$('#ModalBitacora').modal('hide')", "hidemodal") + + End If + ObjEventoBitacora.Dispose() + GvEB.DataBind() + + UPEventoBitacora.Update() + CargaEventoBitacora() + UPAddEventoBitacora.Update() + End Sub + + 'Protected Sub CargarArchivo(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AFU.UploadedComplete + ' If AFU.HasFile Then + + + ' Dim UploadFolder As String = String.Format("{0}\Temp\", UsuarioActual.Empresa.Ruta) + ' UploadFolder.DirectoryExistsCreate() + ' Dim Extension As String = System.IO.Path.GetExtension(AFU.PostedFile.FileName) + + ' If File.Exists(String.Format("{0}{1}{2}", UploadFolder, UsuarioActual.CveUsuario.ToString, Extension)) Then File.Delete(String.Format("{0}{1}{2}", UploadFolder, UsuarioActual.CveUsuario.ToString, Extension)) + + ' AFU.SaveAs(UploadFolder & UsuarioActual.CveUsuario.ToString & Extension) + ' Session("FileUpload") = UploadFolder & UsuarioActual.CveUsuario.ToString & Extension + ' Session("FileExtension") = Extension + ' Session("FileFolder") = UploadFolder + ' End If + 'End Sub + Protected Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs) + Dim filePath As String = String.Format("{0}{1}", UsuarioActual.Empresa.Ruta, CType(sender, LinkButton).CommandArgument) + Dim Archivo As New System.IO.FileInfo(filePath) + + HttpContext.Current.Response.Clear() + HttpContext.Current.Response.ClearContent() + HttpContext.Current.Response.ContentType = "application/octet-stream" + HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(filePath)) + HttpContext.Current.Response.AddHeader("Content-Length", Archivo.Length.ToString()) + HttpContext.Current.Response.TransmitFile(filePath) + HttpContext.Current.Response.Flush() + HttpContext.Current.Response.End() + + Archivo = Nothing + End Sub + + Private Sub CargaEventoBitacora() + + Dim ObjEventoBitacora As New ClsOIEventos() + If ObjEventoBitacora.GetAgendaBitacora(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then + GvEB.DataSource = ObjEventoBitacora.DtResultados.FiltraParametros("CveTipoEvento = 6 OR CveTipoEvento = 2") + Else + GvEB.DataSource = Nothing + End If + ObjEventoBitacora.Dispose() + GvEB.DataBind() + End Sub +#End Region + +#Region " C O N T A B I L I D A D " + Protected Sub BtnDescontabilizar_Click(sender As Object, e As EventArgs) + 'Alert("Hola entre", TipoMensaje.MsgError) + 'Exit Sub + + Dim ObjConta As New ClsContabilidad + Dim Movimientos = ObjConta.GetMovimientosPoliza(IdPoliza, UsuarioActual.CveEmpresa) + + 'Verifica que solo exista 1 compra asociada + If Movimientos = 1 Then + EliminaPoliza() + Else + RegistraScript("ConfirmEliminarPolizaMultiple();") + End If + + ObjConta.Dispose() + End Sub + Protected Sub LBContabilizarAC_Click(sender As Object, e As EventArgs) + Dim ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) + ObjContaAC.IniciaTransacSQL() + Dim ObjCompras As New ClsCompras + Dim ObjProveedores As New ClsCompProveedores(ObjCompras.IniciaTransacSQL()) + Dim ObjAF As New ClsAF(ObjCompras.IniciaTransacSQL()) + Dim ErrorAC = False + Dim IDPolizaComprometido = If(TxtOC.Text.Length > 0, 1, 0) + + ''EMPIEZA: SI USA AC + If UsuarioActual.Empresa.UsaAC Then + ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) + ObjContaAC.IniciaTransacSQL() + + + 'ELIMINA TODOS LOS MOVIMIENTOS DE LA POLIZA + If IdPoliza > 0 Then + ObjContaAC.RemoveAllMovimientos(IdPoliza) + Else + Dim TotalPorDevengar = Math.Round(TxtTotal.Text.ToDouble, 2) + IdPoliza = ObjContaAC.AddPoliza(3, TxtDescripcion.Text.Trim, TotalPorDevengar, TotalPorDevengar, UsuarioActual.CveUsuario, TxtFecha.Text.ToDate) + End If + + 'INSERTA LOS NUEVOS MOVIMIENTOS DE LA POLIZA + If IdPoliza > 0 Then + Dim CuentaAbono As Integer + Dim Importe As Decimal = 0 + Dim TotalDetalle As Decimal = 0 + + 'CUENTA PROVEEDOR + If CtaProveedor <= 0 Then + If ObjContaAC.GetCuentas(-1, "021120000000000000", -1) Then + Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") + If drCuenta IsNot Nothing Then + CuentaAbono = drCuenta("Id").ToString.ToEntero + Dim FolioProveedor = ObjContaAC.GetFolioProveedores("021120000000000000").ToString + ViewState("CtaProveedor") = ObjContaAC.AddCuenta(String.Format("02112{0}000000000", FolioProveedor.PadLeft(4, "0"c)), NombreProveedor, "D", 2, 0, 1, 0, "", 1, CuentaAbono) + ObjProveedores.UpdateProveedorIdCuentaAC(CveProveedor, CtaProveedor) + Else + ErrorAC = True + End If + Else + ErrorAC = True + End If + End If + + Dim ConceptoRenglon As String = "" + If Not ErrorAC Then + + Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA, tRetIVA, tRetISR As Decimal + + Dim ipresup As Integer = 0 + + 'COMIENZA: PRUEBA AGRUPACION CONCEPTOS + Dim Presup = From gvr As DataRow In TmpDT.Rows.Cast(Of DataRow)() + Group gvr By Grp = New With { + Key .CvePresupuestoEgreso = gvr("CvePresupuestoEgreso").ToString.ToEntero, + Key .CveActivoFijo = If(gvr("TipoAF").ToString.ToEntero = 2, gvr("CveActivoFijo").ToString.ToEntero, -1) + } Into Group + Select Grp.CvePresupuestoEgreso, Grp.CveActivoFijo, + TotalImporte = Group.Sum(Function(r) r("Total").ToString.ToDecimal) + Dim Fecha As Date = TxtFecha.Text.ToDate + + 'PresupuestoEgresos + Dim DtPresupuestosTemp As DataTable + Dim IdCuentaComprometido, IdCuentaPorEjercer, IdCuentaDevengado, IdCuentaMatriz As Integer + + 'Dim tTotalIVA, tTotalGral, tDiferenciaIVA, tIVA As Double + tTotalIVA = TxtIVA.Text.ToDecimal + tRetIVA = TxtRetIVA.Text.ToDecimal + tRetISR = TxtRetISR.Text.ToDecimal + + 'tTotalIVA = tTotalIVA - tRetIVA - tRetISR + + tTotalGral = TxtTotal.Text.ToDecimal + tRetIVA + tRetISR ' EL TOTAL GENERAL DEBE DE SER EL SUBTOTAL + IVA, NO SE DEBEN DE INCLUIR LAS RETENCIONES, POR ESO SE RESTA + tDiferenciaIVA = tTotalIVA + tIVA = 0 + ipresup = 0 + + 'INVENTARIOS EN AC + Dim CuentaMatrizAlmacen As Integer + Dim ContadorInventario As Integer = GvInv.Rows.Cast(Of GridViewRow)().Count(Function(gvr) gvr.FCCheckBox("cbInv").Checked) + + Dim CtaAlmacen As Integer + If ContadorInventario > 0 Then + Dim drr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToString.ToEntero)) + If drr IsNot Nothing Then + CtaAlmacen = drr("IdCtaContable").ToString.ToEntero + End If + End If + Dim DescuentoConIVA As Double + Dim tPorIVA As Decimal = tTotalIVA / (tTotalGral - tTotalIVA) + Dim tAjusteTotal As Decimal = 0 + + For Each grp In Presup + Importe = grp.TotalImporte + TotalDetalle += Importe + ipresup += 1 + If Importe > 0 Then + 'saco la proporcion de iva que le corresponde + tIVA = Math.Round(Importe * tPorIVA, 2) + tDiferenciaIVA -= tIVA + 'identifico si es el ultimo registro, para ver si es necesario un ajuste + If ipresup = Presup.Count Then + If Math.Round(TotalDetalle - tTotalGral, 2) <= 0.01 AndAlso tDiferenciaIVA > 0 Then + tIVA += tDiferenciaIVA + End If + End If + + 'le sumo el iva al concepto + Importe += tIVA + 'codigo Provisional, para cuand tenga descuento, solo tome el subtotal * el iva,RMF + If TxtDescuento.Text.ToDouble > 0 Then + Importe = grp.TotalImporte * (1 + tPorIVA) + End If + + tAjusteTotal += Importe + + 'valido que la sumas de lo detalles no exceda al totalgeneral + If Math.Round(tAjusteTotal, 2) > tTotalGral Then + 'le resto la diferencia + Importe -= (tAjusteTotal - tTotalGral) + End If + + 'Presupuesto Egresos + DtPresupuestosTemp = DtPresupuestos.FiltraParametros(String.Format("CvePresupuestoEgreso = {0}", grp.CvePresupuestoEgreso)) + If DtPresupuestosTemp.Rows.Count <> 1 Then + ErrorAC = True + Exit For + End If + IdCuentaComprometido = DtPresupuestosTemp.Rows(0)("IdCuentaComprometido").ToString.ToEntero + IdCuentaPorEjercer = DtPresupuestosTemp.Rows(0)("IdCuentaPorEjercer").ToString.ToEntero + IdCuentaDevengado = DtPresupuestosTemp.Rows(0)("IdCuentaDevengado").ToString.ToEntero + IdCuentaMatriz = DtPresupuestosTemp.Rows(0)("IdCuentaMatriz").ToString.ToEntero + + 'COMPROMETIDO DEPENDIENTE SI EXISTE SU POLIZA + If IDPolizaComprometido = 0 Then + ConceptoRenglon = String.Format("GC Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, False, Importe, "", ConceptoRenglon, 0, Fecha, "") Then + If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaPorEjercer, True, Importe, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + Exit For + End If + Else + ErrorAC = True + Exit For + End If + End If + + ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + 'DEVENGADO + If ObjContaAC.AddMovimiento(IdPoliza, IdCuentaDevengado, False, Importe, "", ConceptoRenglon, 0, Fecha, "") Then + If Not ObjContaAC.AddMovimiento(IdPoliza, IdCuentaComprometido, True, Importe, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + Exit For + End If + Else + ErrorAC = True + Exit For + End If + + + If ContadorInventario > 0 Then + Dim tImporte, ttIVA As Double + + For Each gvr As GridViewRow In GvPS.Rows + 'registra los movimientos del presupuesto asignado, para que no se duplique si hay varios presupeusto dentro de la compra + If gvr.DataKey("CvePresupuestoEgreso").ToEntero = grp.CvePresupuestoEgreso Then + 'saco la proporcion de iva que le corresponde + tImporte = gvr.FCLiteral("LtlTotal").Text.ToDouble + ttIVA = Math.Round(tImporte * tTotalIVA / tTotalGral, 2) + tImporte += ttIVA + End If + + Next + + CuentaMatrizAlmacen = CtaAlmacen + + ElseIf grp.CveActivoFijo > 0 Then + + Dim CtaAF = -1 + Dim AF = "" + Dim CuentaInicial = -1 + + If ObjAF.GetActivosFijos(grp.CveActivoFijo, UsuarioActual.CveEmpresa, "-1", "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "", -1, UsuarioActual.CveEmpresa) Then + CtaAF = ObjAF.Cuenta + AF = ObjAF.Descripcion + CuentaInicial = ObjAF.CuentaInicial + Else + ErrorAC = True + Exit For + End If + + If Not CuentaInicial > 0 Then + CuentaInicial = 1241 + End If + + 'CUENTA AF + If CtaAF <= 0 Then + If ObjContaAC.GetCuentas(-1, String.Format("0{0}0000000000000", CuentaInicial), -1) Then + Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("") + If drCuenta IsNot Nothing Then + + CuentaAbono = drCuenta("Id").ToString.ToEntero + Dim FolioAF = ObjContaAC.GetFolioProveedores(String.Format("0{0}0000000000000", CuentaInicial)).ToString + CtaAF = ObjContaAC.AddCuenta(String.Format("0{0}{1}000000000", CuentaInicial, FolioAF.PadLeft(4, "0"c)), AF, "A", 2, 0, 1, 0, "", 1, CuentaAbono) + + ObjAF.UpdateActivosFijosCuentaAC(grp.CveActivoFijo, CtaAF, UsuarioActual.CveUsuario) + Else + ErrorAC = True + End If + Else + ErrorAC = True + End If + End If + + CuentaMatrizAlmacen = CtaAF + Else + CuentaMatrizAlmacen = IdCuentaMatriz + End If + + + ''AFECTAR MATRIZ EGRESOS + If ObjContaAC.AddMovimiento(IdPoliza, CuentaMatrizAlmacen, False, Importe, "", ConceptoRenglon, 0, Fecha, "") Then + + ''VERIFICA SI TIENE DESCUENTO (AMORTIZACION) + If TxtDescuento.Text.ToDouble > 0 AndAlso CtaProveedorAnticipos > 0 Then + DescuentoConIVA = TxtDescuento.Text.ToDecimal * 1.16 + + 'Valida que el descuento con iva cuadre en los totales + If Math.Abs(DescuentoConIVA - (Importe - TxtTotal.Text.ToDouble)) < 0.02 Then + DescuentoConIVA = Importe - TxtTotal.Text.ToDouble + ElseIf DescuentoConIVA <> (Importe - TxtTotal.Text.ToDecimal) Then + ErrorAC = True + Exit For + End If + + 'actualizo el idcuenta del presupuesto + If ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, (Importe - DescuentoConIVA), "", ConceptoRenglon, 0, Fecha, "") Then + 'agrego a la cuenta contable anticipos + If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorAnticipos, True, DescuentoConIVA, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + Exit For + End If + Else + ErrorAC = True + Exit For + End If + Else + 'actualizo el idcuenta del + + End If + + Else + ErrorAC = True + Exit For + End If + ''TERMINA AFECTAR MATRIZ EGRESOS + + Else + ErrorAC = True + Exit For + End If + + Next + + If Not ErrorAC Then + 'registro un solo movimiento a proveedores + Importe = TxtTotal.Text.ToDecimal + If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedor, True, Importe, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + End If + End If + + If tRetISR > 0 Then + ConceptoRenglon = String.Format("GD Fact: {0}-{1} {2}", TxtSerie.Text.Trim, TxtFolio.Text.Trim, DdlProveedor.SelectedItem.Text) + If Not ObjContaAC.AddMovimiento(IdPoliza, CtaProveedorRetISR, True, tRetISR, "", ConceptoRenglon, 0, Fecha, "") Then + ErrorAC = True + End If + End If + + End If + + Else + ErrorAC = True + End If + + 'CUADRA LA POLIZA + ObjContaAC.AjustaPoliza(IdPoliza) + + End If + ''TERMINA: SI USA AC + + If Not ErrorAC Then + If Not ObjCompras.UpdateCompraPoliza(IdPoliza, CveCompra) Then + ErrorAC = True + End If + End If + + + If ErrorAC Then + + + + Alert("Ocurrió un error al contabilizar la compra. Comuniquese con soporte.", TipoMensaje.MsgError) + ObjContaAC.RollBack() + ObjCompras.RollBack() + Else + ObjContaAC.Commit() + ObjCompras.Commit() + Alert("La Compra se contabilizó correctamente.", TipoMensaje.MsgInformacion) + + HplCompraContabilizada.Text = "Si" + HplCompraContabilizada.NavigateUrl = String.Format("/Contabilidad/RegPoliza.aspx?IdPoliza={0}", IdPoliza) + LblCompraEstatus.ForeColor = Drawing.Color.Navy + trContabilizada.Visible = True + UpEstatus.Update() + End If + ObjContaAC.Dispose() + + End Sub + + Protected Sub BtnEliminarPoliza_Click(sender As Object, e As EventArgs) + EliminaPoliza() + End Sub + + Private Sub EliminaPoliza() + Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa) + ObjAC.IniciaTransacSQL() + Dim ObjConta As New ClsContabilidad + ObjConta.IniciaTransacSQL() + + Dim ErrorCompra = False + + 'Elimina la poliza + If (UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.UsaContabilidad) AndAlso IdPoliza > 0 Then + If Not ObjAC.RemovePoliza(IdPoliza) Then + ErrorCompra = True + End If + End If + + 'Desasocia la poliza + If Not ErrorCompra Then + If Not ObjConta.DesasociarPoliza(IdPoliza, UsuarioActual.CveEmpresa) Then + ErrorCompra = True + End If + End If + + If Not ErrorCompra Then + If Not ObjConta.UpdatePrePolizasDetalleBloquear(CvePrePoliza, False) Then + ErrorCompra = True + End If + End If + + If Not ErrorCompra Then + Alert("La poliza ha sido desvinculada y eliminada con exito.", TipoMensaje.MsgInformacion) + ObjAC.Commit() + ObjConta.Commit() + + Else + Alert("Ocurrió un error al desvincular y/o eliminar la poliza. Por favor intente de nuevo ", TipoMensaje.MsgError) + ObjAC.RollBack() + ObjConta.RollBack() + End If + + ObjAC.Dispose() + ObjConta.Dispose() + + If Not ErrorCompra Then + CargaCompra() + End If + End Sub + +#End Region + +#Region " REEMBOLSOS NO USA AC " + Protected Sub DdlPersonal2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPersonalReembolso.SelectedIndexChanged + ViewState("CvePersonal") = DdlPersonalReembolso.SelectedValue + End Sub + Protected Sub DdlCajaChica2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuentaCajaChicaReembolso.SelectedIndexChanged + Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltroPrimero("CveCuenta = " & DdlCuentaCajaChicaReembolso.SelectedValue) + + If dr IsNot Nothing Then + CveMoneda = dr("CveMoneda").ToString.ToEntero + IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero + CveCuentaBancaria = dr("IdCtaContableSIG").ToString.ToEntero + End If + ViewState("CveCajaChica") = DdlCuentaCajaChicaReembolso.SelectedValue + End Sub +#End Region + +#Region " ALMACEN " + +#End Region + +#Region " CONSIGNACIONES " + Protected Sub ChkConsignacion_CheckedChanged(sender As Object, e As EventArgs) + + If ChkConsignacion.Checked Then + 'LiConsignacion.Visible = True + GvInv.Columns(7).Visible = True + GvInv.Columns(8).Visible = True + CargaConsignaciones2() + + CargaGvInv() + + GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True + GvInv.HeaderRow.FCCheckBox("cbAll").Enabled = False + + BtnVinculaConsignacion.Visible = True + + BtnGuardar.Enabled = False + UpFacturar.Update() + Else + GvInv.Columns(7).Visible = False + GvInv.Columns(8).Visible = False + 'LiConsignacion.Visible = False + CveConsignacion = -1 + + GvInv.HeaderRow.FCCheckBox("cbAll").Checked = False + GvInv.HeaderRow.FCCheckBox("cbAll").Enabled = True + + BtnVinculaConsignacion.Visible = False + + CargaGvInv() + + BtnGuardar.Enabled = True + UpFacturar.Update() + End If + + cbAll_CheckedChanged(GvInv.HeaderRow.FCCheckBox("cbAll"), EventArgs.Empty) + UpConsignaciones.Update() + End Sub + Private Sub CargaConsignaciones() + If DdlProveedor.SelectedValue.ToEntero > 0 Then + 'Dim ObjInventarios As New ClsInventarios + + 'If ObjInventarios.GetConsignaciones2(-1, UsuarioActual.CveEmpresa) Then + ' DdlConsignacion.DataSource = ObjInventarios.DtResultados.FiltraParametros(String.Format("CveProveedor = {0}", DdlProveedor.SelectedValue.ToEntero)) + 'Else + ' DdlConsignacion.DataSource = Nothing + 'End If + + 'ObjInventarios.Dispose() + + 'DdlConsignacion.DataBind() + 'DdlConsignacion.Items.Insert(0, New ListItem("Seleccione", "-1")) + End If + End Sub + Private Sub CargaConsignaciones2() + Dim ObjInventarios As New ClsInventarios + Dim TieneError = False + + CveConsignacion = -1 + + If ObjInventarios.GetConsignacionesDetalleProveedor(DdlProveedor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then + DtConsignaciones = ObjInventarios.DtResultados + Else + TieneError = True + End If + + If DtConsignaciones IsNot Nothing AndAlso DtConsignaciones.Rows.Count > 0 Then + 'CveConsignacion = DdlConsignacion.SelectedValue.ToEntero + CveConsignacion = 1 + 'CveAlmacenConsignacion = ObjInventarios.DtResultados.Rows(0)("CveAlmacen").ToString.ToEntero + End If + + If TieneError Then + Alert("Ocurrió un error al cargar la consignación. Por favor vuelva a intentar.", TipoMensaje.MsgError) + DtConsignaciones = Nothing + End If + + ObjInventarios.Dispose() + + CargaGvInv() + End Sub + Protected Sub BtnVinculaConsignacion_Click(sender As Object, e As EventArgs) + Dim ObjInventarios As New ClsInventarios + Dim TieneError = False + + CveConsignacion = -1 + + If ObjInventarios.GetConsignacionesDetalleProveedor(DdlProveedor.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then + DtConsignaciones = ObjInventarios.DtResultados + Else + TieneError = True + End If + + If DtConsignaciones.Rows.Count > 0 Then + 'CveConsignacion = DdlConsignacion.SelectedValue.ToEntero + CveConsignacion = 1 + CveAlmacenConsignacion = ObjInventarios.DtResultados.Rows(0)("CveAlmacen").ToString.ToEntero + End If + + If TieneError Then + Alert("Ocurrió un error al cargar la consignación. Por favor vuelva a intentar.", TipoMensaje.MsgError) + DtConsignaciones = Nothing + End If + + ObjInventarios.Dispose() + + CargaGvInv() + 'If DtConsignaciones IsNot Nothing Then + ' GvConsignaciones.DataSource = DtConsignaciones + ' GvConsignaciones.DataBind() + 'End If + + 'UpConsignaciones.Update() + End Sub + Protected Sub GvConsignaciones_RowDataBound(sender As Object, e As GridViewRowEventArgs) 'Handles GvConsignaciones.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + + e.Row.FCDropDownList("DdlVinculaConsignacion").DataSource = TmpDT + e.Row.FCDropDownList("DdlVinculaConsignacion").DataBind() + e.Row.FCDropDownList("DdlVinculaConsignacion").Items.Insert(0, New ListItem("Seleccione", "-1")) + + End If + End Sub + Protected Sub DdlVinculaConsignacion_SelectedIndexChanged(sender As Object, e As EventArgs) + Dim Ddl As DropDownList = DirectCast(sender, DropDownList) + Dim gvr As GridViewRow = DirectCast(Ddl.BindingContainer, GridViewRow) + + If Ddl.SelectedValue = "-1" Then + + gvr.FCHiddenField("HdnPS").Value = "-1" + gvr.FCHiddenField("HdnCvePS").Value = "-1" + gvr.FCHiddenField("HdnClasificacion").Value = "-1" + gvr.FCHiddenField("HdnCveClasificacion").Value = "-1" + gvr.FCHiddenField("HdnCveAlmacen").Value = "-1" + + gvr.FCHiddenField("HdnNoConsignacion").Value = "-1" + gvr.FCHiddenField("HdnCveConsignacion").Value = "-1" + + 'GUARDA VALORES POR UNA RECARGA (DIVISION DE CONCEPTO) + TmpDT.Rows(gvr.RowIndex)("CveAlmacenConsignacion") = "-1" + TmpDT.Rows(gvr.RowIndex)("NoConsignacion") = "-1" + TmpDT.Rows(gvr.RowIndex)("CveConsignacion") = "-1" + + TmpDT.Rows(gvr.RowIndex)("HdnPS") = "-1" + TmpDT.Rows(gvr.RowIndex)("HdnCvePS") = "-1" + TmpDT.Rows(gvr.RowIndex)("HdnClasificacion") = "-1" + TmpDT.Rows(gvr.RowIndex)("HdnCveClasificacion") = "-1" + TmpDT.Rows(gvr.RowIndex)("HdnCveAlmacen") = "-1" + Exit Sub + End If + + Dim Row = DtConsignaciones.Rows(Ddl.SelectedValue.ToEntero - 1) + + 'VALIDAMOS CANTIDAD + Dim Cantidad = Row("Cantidad").ToString.ToDecimal + For Each gvr1 As GridViewRow In GvInv.Rows + If gvr1.FCHiddenField("HdnNoConsignacion").Value.ToString = Ddl.SelectedValue Then + Cantidad = Cantidad - gvr1.DataKey("Cantidad").ToString.ToDecimal + End If + Next + + If Cantidad - gvr.DataKey("Cantidad").ToString.ToDecimal < 0 Then + Ddl.SelectedValue = "-1" + + gvr.FCHiddenField("HdnPS").Value = "-1" + gvr.FCHiddenField("HdnCvePS").Value = "-1" + gvr.FCHiddenField("HdnClasificacion").Value = "-1" + gvr.FCHiddenField("HdnCveClasificacion").Value = "-1" + gvr.FCHiddenField("HdnCveAlmacen").Value = "-1" + + gvr.FCHiddenField("HdnNoConsignacion").Value = "-1" + gvr.FCHiddenField("HdnCveConsignacion").Value = "-1" + + 'GUARDA VALORES POR UNA RECARGA (DIVISION DE CONCEPTO) + TmpDT.Rows(gvr.RowIndex)("CveAlmacenConsignacion") = "-1" + TmpDT.Rows(gvr.RowIndex)("NoConsignacion") = "-1" + TmpDT.Rows(gvr.RowIndex)("CveConsignacion") = "-1" + + TmpDT.Rows(gvr.RowIndex)("HdnPS") = "-1" + TmpDT.Rows(gvr.RowIndex)("HdnCvePS") = "-1" + TmpDT.Rows(gvr.RowIndex)("HdnClasificacion") = "-1" + TmpDT.Rows(gvr.RowIndex)("HdnCveClasificacion") = "-1" + TmpDT.Rows(gvr.RowIndex)("HdnCveAlmacen") = "-1" + + Alert("El concepto que desea vincular excede la cantidad del inventario de consignación.", TipoMensaje.MsgAdvertencia) + Else + gvr.FCHiddenField("HdnPS").Value = Row("PS").ToString + gvr.FCHiddenField("HdnCvePS").Value = Row("CvePS").ToString + gvr.FCHiddenField("HdnClasificacion").Value = Row("Clasificacion").ToString + gvr.FCHiddenField("HdnCveClasificacion").Value = Row("CveClasificacion").ToString + gvr.FCHiddenField("HdnCveAlmacen").Value = Row("CveAlmacenSalida").ToString + + gvr.FCHiddenField("HdnNoConsignacion").Value = Ddl.SelectedValue.ToEntero.ToString + gvr.FCHiddenField("HdnCveConsignacion").Value = Row("CveConsignacion").ToString + + 'GUARDA VALORES POR UNA RECARGA (DIVISION DE CONCEPTO) + TmpDT.Rows(gvr.RowIndex)("CveAlmacenConsignacion") = gvr.FCDropDownList("ddlAlmacenConsignacion").SelectedValue.ToEntero + TmpDT.Rows(gvr.RowIndex)("NoConsignacion") = Ddl.SelectedValue.ToEntero + TmpDT.Rows(gvr.RowIndex)("CveConsignacion") = Row("CveConsignacion").ToString + + TmpDT.Rows(gvr.RowIndex)("HdnPS") = Row("PS").ToString + TmpDT.Rows(gvr.RowIndex)("HdnCvePS") = Row("CvePS").ToString + TmpDT.Rows(gvr.RowIndex)("HdnClasificacion") = Row("Clasificacion").ToString + TmpDT.Rows(gvr.RowIndex)("HdnCveClasificacion") = Row("CveClasificacion").ToString + TmpDT.Rows(gvr.RowIndex)("HdnCveAlmacen") = Row("CveAlmacenSalida").ToString + End If + + + End Sub + Protected Sub ddlAlmacenConsignacionGeneral_SelectedIndexChanged(sender As Object, e As EventArgs) + Dim DdlAlmacenConsignacionGeneral = CType(sender, DropDownList) + + For Each gvr As GridViewRow In GvInv.Rows + gvr.FCDropDownList("ddlAlmacenConsignacion").SelectedValue = DdlAlmacenConsignacionGeneral.SelectedValue + + gvr.FCDropDownList("ddlVinculaConsignacion").DataSource = DtConsignaciones.FiltraParametros(String.Format("CveAlmacenSalida = {0} OR {0} = '-1'", gvr.FCDropDownList("ddlAlmacenConsignacion").SelectedValue)) + gvr.FCDropDownList("ddlVinculaConsignacion").DataBind() + gvr.FCDropDownList("ddlVinculaConsignacion").Items.Insert(0, New ListItem("Seleccione", "-1")) + Next + + UpINV.Update() + End Sub + Protected Sub ddlAlmacenConsignacion_SelectedIndexChanged(sender As Object, e As EventArgs) + Dim DdlAlmacenConsignacion = CType(sender, DropDownList) + Dim DdlVinculaConsignacion = CType(CType(sender, DropDownList).NamingContainer, GridViewRow).FCDropDownList("DdlVinculaConsignacion") + + ''CARGA CONSIGNACIONES + DdlVinculaConsignacion.DataSource = DtConsignaciones.FiltraParametros(String.Format("CveAlmacenSalida = {0} OR {0} = '-1'", DdlAlmacenConsignacion.SelectedValue)) + DdlVinculaConsignacion.DataBind() + DdlVinculaConsignacion.Items.Insert(0, New ListItem("Seleccione", "-1")) + + UpINV.Update() + End Sub + Protected Sub BtnVinculaConsignacion_Click1(sender As Object, e As EventArgs) + + 'VALIDACIONES + For Each gvr As GridViewRow In GvInv.Rows + If gvr.FCDropDownList("DdlVinculaConsignacion").SelectedValue = "-1" Then + Alert("Debe vincular todos los conceptos para realizar la vinculación de consignación.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + Next + + 'CambiaPS + For Each gvr As GridViewRow In GvInv.Rows + TmpDT.Rows(gvr.RowIndex)("PS") = gvr.FCHiddenField("HdnPS").Value + TmpDT.Rows(gvr.RowIndex)("CvePS") = gvr.FCHiddenField("HdnCvePS").Value + TmpDT.Rows(gvr.RowIndex)("Clasificacion") = gvr.FCHiddenField("HdnClasificacion").Value + TmpDT.Rows(gvr.RowIndex)("CveClasificacion") = gvr.FCHiddenField("HdnCveClasificacion").Value + Next + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + 'Bloqueamos todo para respetar cambios realizados + DtInv = TmpDT + ChkConsignacion.Enabled = False + BtnVinculaConsignacion.Enabled = False + UpConsignaciones.Update() + + GvInv.Enabled = False + UpINV.Update() + GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True + cbAll_CheckedChanged(GvInv.HeaderRow.FCCheckBox("cbAll"), EventArgs.Empty) + + BtnGuardar.Enabled = True + UpFacturar.Update() + + End Sub +#End Region + +#Region " ***** Devoluciones INV ***** " '*se envia true si hubo un error*' - Private Function guardardevolucion(ObjInventario As ClsInventarios, CveCompra As Integer, subtotal As Double, Fecha As Date) As Boolean - Dim ErrorMovInv As Boolean = False - Dim CveAlmacen As Integer - Dim subtotaldevolucion As Double = 0 - Dim realizadevolucion As Boolean = False - 'Calculo los subtotales para comparar con la NC - Dim cantidad As Double = 0.0 - For Each Dr As GridViewRow In GVDevolucion.Rows - CveAlmacen = Dr.DataKey("CveAlmacen").ToString.ToEntero - cantidad = Dr.FCTextBox("TxtCantidad").Text.ToDouble - If cantidad > 0 Then - realizadevolucion = True - subtotaldevolucion += Dr.DataKey("PU").ToString.ToDouble * cantidad - End If - Next - 'si no esta vinculado a nc simplemente me lo brinco - If realizadevolucion Then - - 'si el subtotal es iwal a la nc lo guardo si no marco error - If subtotal > subtotaldevolucion - 1 AndAlso subtotal < subtotaldevolucion + 1 Then - - Dim CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacen, 13, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, Modulo:="Comp/G") - If CveMovimientoEntrada <= 0 Then - ErrorMovInv = True - Else - For Each Dr As GridViewRow In GVDevolucion.Rows - If Dr.FCTextBox("TxtCantidad").Text.ToDouble > 0 Then - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr.FCTextBox("TxtCantidad").Text.ToDouble, Dr.DataKey("CveUM").ToString.ToEntero, Dr.DataKey("CvePS").ToString.ToEntero, Dr.DataKey("PU").ToString.ToDouble, -1, CveMovimientoDetalleEntrada:=Dr.DataKey("CveMovimientoDetalle").ToString.ToEntero) Then - ErrorMovInv = True - Exit For - End If - End If - Next - End If - Else - ErrorMovInv = True - Alert("El Total de la NC debe ser igual al total de la devolucion", TipoMensaje.MsgAdvertencia) - End If - End If - Return ErrorMovInv - End Function - - - Private Sub cargaddldevoluciones(CveProveedor As Integer, SubTotal As Double) - Dim objcompras As New ClsCompras() - If objcompras.GetCompraParaDevolucion(CveProveedor, UsuarioActual.CveEmpresa, SubTotal) Then - DDLDevolucion.Items.Clear() - DDLDevolucion.DataSource = objcompras.DtResultados - DDLDevolucion.DataBind() - DDLDevolucion.Items.Insert(0, New ListItem("Seleccione", "-1")) - End If - objcompras.Dispose() - UPDevolucion.Update() - - End Sub - - - Protected Sub DDLDevolucion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDLDevolucion.SelectedIndexChanged - Dim objcompras As New ClsCompras() - If objcompras.GetCompraDetallealmacen(DDLDevolucion.SelectedValue.ToEntero) Then - GVDevolucion.DataSource = objcompras.DtResultados - GVDevolucion.DataBind() - End If - objcompras.Dispose() - UPDevolucion.Update() - End Sub - 'Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click - ' cargaddldevoluciones(CveProveedor, TextBox1.Text.ToDouble) - 'End Sub - 'Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click - ' Dim ObjInventario As New ClsInventarios() - ' Dim cvecompra As Integer = 5221 - ' Dim subtotal As Double = TextBox1.Text.ToDouble - ' guardardevolucion(ObjInventario, cvecompra, subtotal, Now.ToDate) - 'End Sub - Protected Sub BtnVinculaDevolucion_Click(sender As Object, e As EventArgs) + Private Function guardardevolucion(ObjInventario As ClsInventarios, CveCompra As Integer, subtotal As Double, Fecha As Date) As Boolean + Dim ErrorMovInv As Boolean = False + Dim CveAlmacen As Integer + Dim subtotaldevolucion As Double = 0 + Dim realizadevolucion As Boolean = False + 'Calculo los subtotales para comparar con la NC + Dim cantidad As Double = 0.0 + For Each Dr As GridViewRow In GVDevolucion.Rows + CveAlmacen = Dr.DataKey("CveAlmacen").ToString.ToEntero + cantidad = Dr.FCTextBox("TxtCantidad").Text.ToDouble + If cantidad > 0 Then + realizadevolucion = True + subtotaldevolucion += Dr.DataKey("PU").ToString.ToDouble * cantidad + End If + Next + 'si no esta vinculado a nc simplemente me lo brinco + If realizadevolucion Then + + 'si el subtotal es iwal a la nc lo guardo si no marco error + If subtotal > subtotaldevolucion - 1 AndAlso subtotal < subtotaldevolucion + 1 Then + + Dim CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacen, 13, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, Modulo:="Comp/G") + If CveMovimientoEntrada <= 0 Then + ErrorMovInv = True + Else + For Each Dr As GridViewRow In GVDevolucion.Rows + If Dr.FCTextBox("TxtCantidad").Text.ToDouble > 0 Then + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr.FCTextBox("TxtCantidad").Text.ToDouble, Dr.DataKey("CveUM").ToString.ToEntero, Dr.DataKey("CvePS").ToString.ToEntero, Dr.DataKey("PU").ToString.ToDouble, -1, CveMovimientoDetalleEntrada:=Dr.DataKey("CveMovimientoDetalle").ToString.ToEntero) Then + ErrorMovInv = True + Exit For + End If + End If + Next + End If + Else + ErrorMovInv = True + Alert("El Total de la NC debe ser igual al total de la devolucion", TipoMensaje.MsgAdvertencia) + End If + End If + Return ErrorMovInv + End Function + + + Private Sub cargaddldevoluciones(CveProveedor As Integer, SubTotal As Double) + Dim objcompras As New ClsCompras() + If objcompras.GetCompraParaDevolucion(CveProveedor, UsuarioActual.CveEmpresa, SubTotal) Then + DDLDevolucion.Items.Clear() + DDLDevolucion.DataSource = objcompras.DtResultados + DDLDevolucion.DataBind() + DDLDevolucion.Items.Insert(0, New ListItem("Seleccione", "-1")) + End If + objcompras.Dispose() + UPDevolucion.Update() + + End Sub + + + Protected Sub DDLDevolucion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDLDevolucion.SelectedIndexChanged + Dim objcompras As New ClsCompras() + If objcompras.GetCompraDetallealmacen(DDLDevolucion.SelectedValue.ToEntero) Then + GVDevolucion.DataSource = objcompras.DtResultados + GVDevolucion.DataBind() + End If + objcompras.Dispose() + UPDevolucion.Update() + End Sub + 'Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click + ' cargaddldevoluciones(CveProveedor, TextBox1.Text.ToDouble) + 'End Sub + 'Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click + ' Dim ObjInventario As New ClsInventarios() + ' Dim cvecompra As Integer = 5221 + ' Dim subtotal As Double = TextBox1.Text.ToDouble + ' guardardevolucion(ObjInventario, cvecompra, subtotal, Now.ToDate) + 'End Sub + Protected Sub BtnVinculaDevolucion_Click(sender As Object, e As EventArgs) Try Dim subtotaldevolucion As Double = 0 Dim realizadevolucion As Boolean = False @@ -13729,13 +13867,13 @@ Partial Class Compras_Compras End If Catch ex As Exception OnError("Ocurrió un error al realizar la vinculación", ex) - End Try - - - End Sub - - Private Sub VinculaDevolucion() - 'LIMPIAR PARTIDAS DE LA COMPRA PARA AGREGAR NUEVAS + End Try + + + End Sub + + Private Sub VinculaDevolucion() + 'LIMPIAR PARTIDAS DE LA COMPRA PARA AGREGAR NUEVAS TmpDT.Clear() Dim SubTotalCompra As Decimal = TxtSubTotal.Text.ToDecimal() @@ -13747,1246 +13885,1246 @@ Partial Class Compras_Compras 'Dim TotalCalculable As Decimal = TotalCompra - IEPSCompra + RetIVACompra + RetISRCompra - Dim IVAPorcentajeCompra As Decimal = Math.Round((IVACompra / SubTotalCompra), 2) - - 'Iteramos el GridView de la OC - For Each gvr As GridViewRow In GVDevolucion.Rows + Dim IVAPorcentajeCompra As Decimal = Math.Round((IVACompra / SubTotalCompra), 2) + + 'Iteramos el GridView de la OC + For Each gvr As GridViewRow In GVDevolucion.Rows If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Then Dim CvePS As Integer = gvr.DataKey("CvePS").ToString.ToEntero Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).Rows(0) - Dim Cantidad As Decimal = gvr.FCTextBox("TxtCantidad").Text.ToDecimal - Dim CveUM As Integer = gvr.DataKey("CveUM").ToString.ToEntero - Dim UM As String = gvr.DataKey("UM").ToString - Dim CveClasificacion As Integer = gvr.DataKey("CveClasificacion").ToString.ToEntero - Dim Clasificacion As String = gvr.DataKey("Clasificacion").ToString - Dim PS As String = gvr.DataKey("PS").ToString - Dim CveTipoPS As Integer = gvr.DataKey("CveTipoPS").ToString.ToEntero - Dim CveSubProyectoContrato As String = "-1" - Dim CveProyecto As String = "-1" - Dim SubProyecto As String = "Seleccione" - Dim Proyecto As String = "Seleccione" - Dim Obs As String = "" - Dim PU As Decimal = gvr.DataKey("PU").ToString.ToDecimal - Dim Total As Decimal = gvr.FCTextBox("TxtTotalDevolucion").Text.ToDecimal - Dim IVA As Decimal = IVAPorcentajeCompra 'Math.Round(Total * IVAPorcentajeCompra, 2) - Dim Descuento As Decimal = 0 - - AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, 0, 0, 0, 0, Descuento, -1, False) - - End If - Next - - AddPS2() - - BtnGuardar.Enabled = True - If Not CierrePeriodo Then - BtnGuardar.Visible = True - End If - AlmacenCambiaPS.Visible = False - UpFacturar.Update() - - TabGenerales.Enabled = True - TAB.ActiveTabIndex = 0 - UpTabs.Update() - - ImgClasificacion.Visible = False - LbAgregar.Visible = False - UpPSS.Update() - - CargaGvInv() - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - CargaGVsAF() - - CargaTipoCentroCostoOC() - GvOC1.DataSource = DTOCTemp - - Dim DTCVEOCS As DataTable = DTOCTemp.FiltraParametros("", "", {"CveOrdenCompra"}) - If DTCVEOCS IsNot Nothing AndAlso DTCVEOCS.Rows.Count > 1 Then - GvOC1.Columns(0).Visible = True - Else - GvOC1.Columns(0).Visible = False - End If - - - - - GvOC1.DataBind() - - ' TmpDT = OrdenarTablas("CvePS", DTOCTemp, TmpDT) - GvOC2.DataSource = TmpDT - GvOC2.DataBind() - - - UpGvOC1.Update() - NCDevolucion = True - - ''Bloquea cambio de proyecto - 'DdlProyecto.Enabled = False - 'DdlSubProyecto.Enabled = False - 'UPPProyecto.Update() - - 'Bloquea cambio de OC ya que se concluyo alguna vinculacion - TxtOC.Enabled = False - ImgBtnBuscarOC.Visible = False - UpParametros.Update() - UpPSS.Update() - End Sub -#End Region + Dim Cantidad As Decimal = gvr.FCTextBox("TxtCantidad").Text.ToDecimal + Dim CveUM As Integer = gvr.DataKey("CveUM").ToString.ToEntero + Dim UM As String = gvr.DataKey("UM").ToString + Dim CveClasificacion As Integer = gvr.DataKey("CveClasificacion").ToString.ToEntero + Dim Clasificacion As String = gvr.DataKey("Clasificacion").ToString + Dim PS As String = gvr.DataKey("PS").ToString + Dim CveTipoPS As Integer = gvr.DataKey("CveTipoPS").ToString.ToEntero + Dim CveSubProyectoContrato As String = "-1" + Dim CveProyecto As String = "-1" + Dim SubProyecto As String = "Seleccione" + Dim Proyecto As String = "Seleccione" + Dim Obs As String = "" + Dim PU As Decimal = gvr.DataKey("PU").ToString.ToDecimal + Dim Total As Decimal = gvr.FCTextBox("TxtTotalDevolucion").Text.ToDecimal + Dim IVA As Decimal = IVAPorcentajeCompra 'Math.Round(Total * IVAPorcentajeCompra, 2) + Dim Descuento As Decimal = 0 -#Region " REFACTURACION " - Private Sub ValidaRefacturacion() - If Not CveCompra > 0 AndAlso DdlTipoComprobante.SelectedValue = "Fac" And UsuarioActual.Empresa.CvePlataforma <> 2 Then - VerRefacturacion.Visible = True - End If - End Sub - Protected Sub BtnRefacturacionVer_Click(sender As Object, e As EventArgs) Handles BtnRefacturacionVer.Click - Dim Opcion As Integer = 1 - - If UsuarioActual.CveEmpresa.Contiene(119, 72) Then Opcion = 2 - - Dim ObjCompras As New ClsCompras - - DdlRefacturacionFacturas.Items.Clear() - If ObjCompras.GetRefacturacion(CveProveedor, TxtSubTotal.Text.ToDecimal, TxtIVA.Text.ToDecimal, TxtTotal.Text.ToDecimal, Opcion, UsuarioActual.CveEmpresa) Then - DtRefacturacion = ObjCompras.DtResultados - DdlRefacturacionFacturas.DataSource = DtRefacturacion - Else - Alert("Ocurrió un error al obtener las facturas para refacturación. Por favor vuelva a intentar.", TipoMensaje.MsgError) - End If - ObjCompras.Dispose() - DivRefacturacion.Visible = True - - DdlRefacturacionFacturas.DataBind() - DdlRefacturacionFacturas.SelectedValueExist(CveCompraRefacturacion) - DdlRefacturacionFacturas.Items.Insert(0, New ListItem("Seleccione", "-1")) - RegistraScript(String.Format("$('#{0}').modal('show')", DivRefacturacion.ClientID)) - UpRefacturacion.Update() - - End Sub - Protected Sub BtnRefacturacionAplicaFactura_Click(sender As Object, e As EventArgs) Handles BtnRefacturacionAplicaFactura.Click - TxtDescripcion.Text = String.Format("Refacturacion: {0}", DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("Descripcion")) - TxtFechaPago.Text = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("FechaVencimiento").ToString.ToDate.ToShortDateString - - For Each Dr As DataRow In TmpDT.Rows - Dr("CveSubProyecto") = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("CveSubProyecto").ToString.ToEntero - Dr("SubProyecto") = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("SubProyecto").ToString - Dr("CveProyecto") = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("CveProyecto").ToString.ToEntero - Dr("Proyecto") = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("Proyecto").ToString - Next - - TrFacturaRefacturar.Visible = True - LtFacturaRefacturar.Text = DdlRefacturacionFacturas.SelectedItem.Text - - CveCompraRefacturacion = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("CveCompra").ToString.ToEntero - - GvPS.DataSource = TmpDT - GvPS.DataBind() - - 'LIMPIA ALMACEN - For Each gvr As GridViewRow In GvInv.Rows - gvr.FCCheckBox("cbInv").Checked = False - Next - TabAlmacen.Enabled = False - - UpRefacturacion.Update() - UpParametros.Update() - UpPS.Update() - UPCondicionesPago.Update() - UpTabs.Update() - RegistraScript(String.Format("$('#{0}').modal('hide')", DivRefacturacion.ClientID)) - End Sub - - Private Function GuardaRefacturacion(ByRef ObjCompra As ClsCompras, ByRef ObjEventos As ClsOIEventos, CvePrePoliza As Integer) As Boolean - Dim dr As DataRow = Nothing - Dim ErrorBitacora = False - Dim IdPolizaAnterior = -1 - Dim TotalRefact As Decimal = 0 - - 'SI NO TIENE POLIZA NI PAGOS NO HACE NADA - 'If ObjCompra.GetCompras(CveCompraRefacturacion, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then - ' If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count = 1 Then - ' Dim drc As DataRow = ObjCompra.DtResultados.Rows(0) - ' TotalRefact = drc("Total").ToString.ToDecimal - ' If drc("IdPoliza").ToString.ToEntero <= 0 AndAlso drc("Saldo").ToString.ToDecimal = drc("Total").ToString.ToDecimal AndAlso drc("CveMovimiento").ToString.ToEntero <= 0 Then - ' Alert("La factura a refacturar no esta contabilizada ni tiene pagos ni movimientos de almacen. No se puede refacturar, debera eliminar la factura anterior y agregar esta factura de forma normal.", TipoMensaje.MsgAdvertencia) - ' Return True - ' End If - ' End If - 'End If - - 'GUARDA ADJUNTOS Y LIGA EN BITACORA (RELACION DE FACTURA NUEVA Y VIEJA) - ErrorBitacora = GuardaRefacturacionBitacora(ObjCompra, ObjEventos) - - If ObjCompra.GetCompras(CveCompraRefacturacion, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then - If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then - dr = ObjCompra.DtResultados.Rows(0) - IdPolizaAnterior = dr("IdPoliza").ToString.ToEntero - End If - End If - - Dim Tipo As Integer = 1 - If ChkRefacNC.Checked Then Tipo = 2 - - 'CONTABILIZA REFACTURACION - If Not ObjCompra.Refacturacion(CveCompraRefacturacion, CveCompra, UsuarioActual.CveEmpresa, Tipo) Then - ErrorBitacora = True - End If - - - - 'Return True - Return ErrorBitacora - End Function - - Private Function GuardaRefacturacionBitacora(ObjCompra As ClsCompras, ObjEventos As ClsOIEventos) As Boolean - Dim dr As DataRow = Nothing - Dim ErrorBitacora = False - Dim Archivo = "" - Dim Folio = "" - Dim Extension = "" - Dim Ruta = "" - - 'CARGA COMPRA REFACTURADA - If CveCompra > 0 AndAlso ObjCompra.GetCompras(CveCompraRefacturacion, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then - If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then - dr = ObjCompra.DtResultados.Rows(0) - - 'ADJUNTAMOS ARCHIVO XML - If Not ErrorBitacora Then - Archivo = String.Format("/Empresas/{0}/Compras/{1}/{2}", dr("CveEmpresa"), dr("RFC"), dr("XML")) - If File.Exists(Archivo) Then - Extension = Path.GetExtension(Archivo) - If Extension <> "" Then - If ObjEventos.AddEventoBitacora("XML de Refacturación:", Extension, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then - - 'OBTENEMOS RUTA DONDE GUARDAR | OPCIONAL: CREAMOS CARPETA - Ruta = String.Format("{0}OI", UsuarioActual.Empresa.Ruta) - Ruta.DirectoryExistsCreate() - - 'COPIAMOS EL ARCHIVO A OI - System.IO.File.Copy(Archivo, String.Format("{0}\OI{1}{2}", Ruta, ObjEventos.CveEvento.ToString, Extension)) - Else - ErrorBitacora = True - End If - End If - End If - End If - - - 'ADJUNTAMOS ARCHIVO PDF - If Not ErrorBitacora Then - Archivo = String.Format("/Empresas/{0}/Compras/{1}/{2}", dr("CveEmpresa"), dr("RFC"), dr("PDF")) - If File.Exists(Archivo) Then - Extension = Path.GetExtension(Archivo) - If Extension <> "" Then - If ObjEventos.AddEventoBitacora("PDF de Refacturación:", Extension, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then - - 'OBTENEMOS RUTA DONDE GUARDAR | OPCIONAL: CREAMOS CARPETA - Ruta = String.Format("{0}OI", UsuarioActual.Empresa.Ruta) - Ruta.DirectoryExistsCreate() - - 'COPIAMOS EL ARCHIVO A OI - System.IO.File.Copy(Archivo, String.Format("{0}\OI{1}{2}", Ruta, ObjEventos.CveEvento.ToString, Extension)) - - Else - ErrorBitacora = True - End If - End If - End If - End If - - 'LIGA AL FOLIO/COMPRA DE REFACTURACION - If Not ErrorBitacora Then - If Not ObjEventos.AddEventoBitacora(String.Format("Refacturación de:
{1}", CveCompraRefacturacion, dr("Folio").ToString), "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then - ErrorBitacora = True - End If - End If - - End If - End If - - 'CARGA COMPRA ACTUAL - If Not ErrorBitacora Then - If ObjCompra.GetCompras(CveCompra, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then - If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then - dr = ObjCompra.DtResultados.Rows(0) - - 'ADJUNTAMOS ARCHIVO XML - If Not ErrorBitacora Then - Archivo = String.Format("/Empresas/{0}/Compras/{1}/{2}", dr("CveEmpresa"), dr("RFC"), dr("XML")) - If File.Exists(Archivo) Then - Extension = Path.GetExtension(Archivo) - If Extension <> "" Then - If ObjEventos.AddEventoBitacora("XML de Refacturación:", Extension, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then - - 'OBTENEMOS RUTA DONDE GUARDAR | OPCIONAL: CREAMOS CARPETA - Ruta = String.Format("{0}OI", UsuarioActual.Empresa.Ruta) - Ruta.DirectoryExistsCreate() - - 'COPIAMOS EL ARCHIVO A OI - System.IO.File.Copy(Archivo, String.Format("{0}\OI{1}{2}", Ruta, ObjEventos.CveEvento.ToString, Extension)) - Else - ErrorBitacora = True - End If - End If - End If - End If - - 'ADJUNTAMOS ARCHIVO PDF - If Not ErrorBitacora Then - Archivo = String.Format("/Empresas/{0}/Compras/{1}/{2}", dr("CveEmpresa"), dr("RFC"), dr("PDF")) - If File.Exists(Archivo) Then - Extension = Path.GetExtension(Archivo) - If Extension <> "" Then - If ObjEventos.AddEventoBitacora("PDF de Refacturación:", Extension, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then - - 'OBTENEMOS RUTA DONDE GUARDAR | OPCIONAL: CREAMOS CARPETA - Ruta = String.Format("{0}OI", UsuarioActual.Empresa.Ruta) - Ruta.DirectoryExistsCreate() - - 'COPIAMOS EL ARCHIVO A OI - System.IO.File.Copy(Archivo, String.Format("{0}\OI{1}{2}", Ruta, ObjEventos.CveEvento.ToString, Extension)) - - Else - ErrorBitacora = True - End If - End If - End If - End If - - 'LIGA AL FOLIO/COMPRA EN REFACTURACION - If Not ErrorBitacora Then - If Not ObjEventos.AddEventoBitacora(String.Format("Refacturación en: {1}", CveCompra, dr("Folio").ToString), "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompraRefacturacion) Then - ErrorBitacora = True - End If - End If - - End If - End If - End If - - Return ErrorBitacora + AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, 0, 0, 0, 0, Descuento, -1, False) + + End If + Next + + AddPS2() + + BtnGuardar.Enabled = True + If Not CierrePeriodo Then + BtnGuardar.Visible = True + End If + AlmacenCambiaPS.Visible = False + UpFacturar.Update() + + TabGenerales.Enabled = True + Tab.ActiveTabIndex = 0 + UpTabs.Update() + + ImgClasificacion.Visible = False + LbAgregar.Visible = False + UpPSS.Update() + + CargaGvInv() + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + CargaGVsAF() + + CargaTipoCentroCostoOC() + GvOC1.DataSource = DTOCTemp + + Dim DTCVEOCS As DataTable = DTOCTemp.FiltraParametros("", "", {"CveOrdenCompra"}) + If DTCVEOCS IsNot Nothing AndAlso DTCVEOCS.Rows.Count > 1 Then + GvOC1.Columns(0).Visible = True + Else + GvOC1.Columns(0).Visible = False + End If + + + + + GvOC1.DataBind() + + ' TmpDT = OrdenarTablas("CvePS", DTOCTemp, TmpDT) + GvOC2.DataSource = TmpDT + GvOC2.DataBind() + + + UpGvOC1.Update() + NCDevolucion = True + + ''Bloquea cambio de proyecto + 'DdlProyecto.Enabled = False + 'DdlSubProyecto.Enabled = False + 'UPPProyecto.Update() + + 'Bloquea cambio de OC ya que se concluyo alguna vinculacion + TxtOC.Enabled = False + ImgBtnBuscarOC.Visible = False + UpParametros.Update() + UpPSS.Update() + End Sub +#End Region + +#Region " REFACTURACION " + Private Sub ValidaRefacturacion() + If Not CveCompra > 0 AndAlso DdlTipoComprobante.SelectedValue = "Fac" And UsuarioActual.Empresa.CvePlataforma <> 2 Then + VerRefacturacion.Visible = True + End If + End Sub + Protected Sub BtnRefacturacionVer_Click(sender As Object, e As EventArgs) Handles BtnRefacturacionVer.Click + Dim Opcion As Integer = 1 + + If UsuarioActual.CveEmpresa.Contiene(119, 72) Then Opcion = 2 + + Dim ObjCompras As New ClsCompras + + DdlRefacturacionFacturas.Items.Clear() + If ObjCompras.GetRefacturacion(CveProveedor, TxtSubTotal.Text.ToDecimal, TxtIVA.Text.ToDecimal, TxtTotal.Text.ToDecimal, Opcion, UsuarioActual.CveEmpresa) Then + DtRefacturacion = ObjCompras.DtResultados + DdlRefacturacionFacturas.DataSource = DtRefacturacion + Else + Alert("Ocurrió un error al obtener las facturas para refacturación. Por favor vuelva a intentar.", TipoMensaje.MsgError) + End If + ObjCompras.Dispose() + DivRefacturacion.Visible = True + + DdlRefacturacionFacturas.DataBind() + DdlRefacturacionFacturas.SelectedValueExist(CveCompraRefacturacion) + DdlRefacturacionFacturas.Items.Insert(0, New ListItem("Seleccione", "-1")) + RegistraScript(String.Format("$('#{0}').modal('show')", DivRefacturacion.ClientID)) + UpRefacturacion.Update() + + End Sub + Protected Sub BtnRefacturacionAplicaFactura_Click(sender As Object, e As EventArgs) Handles BtnRefacturacionAplicaFactura.Click + TxtDescripcion.Text = String.Format("Refacturacion: {0}", DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("Descripcion")) + TxtFechaPago.Text = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("FechaVencimiento").ToString.ToDate.ToShortDateString + + For Each Dr As DataRow In TmpDT.Rows + Dr("CveSubProyecto") = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("CveSubProyecto").ToString.ToEntero + Dr("SubProyecto") = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("SubProyecto").ToString + Dr("CveProyecto") = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("CveProyecto").ToString.ToEntero + Dr("Proyecto") = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("Proyecto").ToString + Next + + TrFacturaRefacturar.Visible = True + LtFacturaRefacturar.Text = DdlRefacturacionFacturas.SelectedItem.Text + + CveCompraRefacturacion = DtRefacturacion.Rows(DdlRefacturacionFacturas.SelectedIndex - 1)("CveCompra").ToString.ToEntero + + GvPS.DataSource = TmpDT + GvPS.DataBind() + + 'LIMPIA ALMACEN + For Each gvr As GridViewRow In GvInv.Rows + gvr.FCCheckBox("cbInv").Checked = False + Next + TabAlmacen.Enabled = False + + UpRefacturacion.Update() + UpParametros.Update() + UpPS.Update() + UPCondicionesPago.Update() + UpTabs.Update() + RegistraScript(String.Format("$('#{0}').modal('hide')", DivRefacturacion.ClientID)) + End Sub + + Private Function GuardaRefacturacion(ByRef ObjCompra As ClsCompras, ByRef ObjEventos As ClsOIEventos, CvePrePoliza As Integer) As Boolean + Dim dr As DataRow = Nothing + Dim ErrorBitacora = False + Dim IdPolizaAnterior = -1 + Dim TotalRefact As Decimal = 0 + + 'SI NO TIENE POLIZA NI PAGOS NO HACE NADA + 'If ObjCompra.GetCompras(CveCompraRefacturacion, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then + ' If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count = 1 Then + ' Dim drc As DataRow = ObjCompra.DtResultados.Rows(0) + ' TotalRefact = drc("Total").ToString.ToDecimal + ' If drc("IdPoliza").ToString.ToEntero <= 0 AndAlso drc("Saldo").ToString.ToDecimal = drc("Total").ToString.ToDecimal AndAlso drc("CveMovimiento").ToString.ToEntero <= 0 Then + ' Alert("La factura a refacturar no esta contabilizada ni tiene pagos ni movimientos de almacen. No se puede refacturar, debera eliminar la factura anterior y agregar esta factura de forma normal.", TipoMensaje.MsgAdvertencia) + ' Return True + ' End If + ' End If + 'End If + + 'GUARDA ADJUNTOS Y LIGA EN BITACORA (RELACION DE FACTURA NUEVA Y VIEJA) + ErrorBitacora = GuardaRefacturacionBitacora(ObjCompra, ObjEventos) + + If ObjCompra.GetCompras(CveCompraRefacturacion, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then + If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then + dr = ObjCompra.DtResultados.Rows(0) + IdPolizaAnterior = dr("IdPoliza").ToString.ToEntero + End If + End If + + Dim Tipo As Integer = 1 + If ChkRefacNC.Checked Then Tipo = 2 + + 'CONTABILIZA REFACTURACION + If Not ObjCompra.Refacturacion(CveCompraRefacturacion, CveCompra, UsuarioActual.CveEmpresa, Tipo) Then + ErrorBitacora = True + End If + + + + 'Return True + Return ErrorBitacora End Function -#End Region + Private Function GuardaRefacturacionBitacora(ObjCompra As ClsCompras, ObjEventos As ClsOIEventos) As Boolean + Dim dr As DataRow = Nothing + Dim ErrorBitacora = False + Dim Archivo = "" + Dim Folio = "" + Dim Extension = "" + Dim Ruta = "" + + 'CARGA COMPRA REFACTURADA + If CveCompra > 0 AndAlso ObjCompra.GetCompras(CveCompraRefacturacion, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then + If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then + dr = ObjCompra.DtResultados.Rows(0) + + 'ADJUNTAMOS ARCHIVO XML + If Not ErrorBitacora Then + Archivo = String.Format("/Empresas/{0}/Compras/{1}/{2}", dr("CveEmpresa"), dr("RFC"), dr("XML")) + If File.Exists(Archivo) Then + Extension = Path.GetExtension(Archivo) + If Extension <> "" Then + If ObjEventos.AddEventoBitacora("XML de Refacturación:", Extension, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then + + 'OBTENEMOS RUTA DONDE GUARDAR | OPCIONAL: CREAMOS CARPETA + Ruta = String.Format("{0}OI", UsuarioActual.Empresa.Ruta) + Ruta.DirectoryExistsCreate() + + 'COPIAMOS EL ARCHIVO A OI + System.IO.File.Copy(Archivo, String.Format("{0}\OI{1}{2}", Ruta, ObjEventos.CveEvento.ToString, Extension)) + Else + ErrorBitacora = True + End If + End If + End If + End If + + + 'ADJUNTAMOS ARCHIVO PDF + If Not ErrorBitacora Then + Archivo = String.Format("/Empresas/{0}/Compras/{1}/{2}", dr("CveEmpresa"), dr("RFC"), dr("PDF")) + If File.Exists(Archivo) Then + Extension = Path.GetExtension(Archivo) + If Extension <> "" Then + If ObjEventos.AddEventoBitacora("PDF de Refacturación:", Extension, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then + + 'OBTENEMOS RUTA DONDE GUARDAR | OPCIONAL: CREAMOS CARPETA + Ruta = String.Format("{0}OI", UsuarioActual.Empresa.Ruta) + Ruta.DirectoryExistsCreate() + + 'COPIAMOS EL ARCHIVO A OI + System.IO.File.Copy(Archivo, String.Format("{0}\OI{1}{2}", Ruta, ObjEventos.CveEvento.ToString, Extension)) + + Else + ErrorBitacora = True + End If + End If + End If + End If + + 'LIGA AL FOLIO/COMPRA DE REFACTURACION + If Not ErrorBitacora Then + If Not ObjEventos.AddEventoBitacora(String.Format("Refacturación de: {1}", CveCompraRefacturacion, dr("Folio").ToString), "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then + ErrorBitacora = True + End If + End If + + End If + End If + + 'CARGA COMPRA ACTUAL + If Not ErrorBitacora Then + If ObjCompra.GetCompras(CveCompra, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then + If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then + dr = ObjCompra.DtResultados.Rows(0) + + 'ADJUNTAMOS ARCHIVO XML + If Not ErrorBitacora Then + Archivo = String.Format("/Empresas/{0}/Compras/{1}/{2}", dr("CveEmpresa"), dr("RFC"), dr("XML")) + If File.Exists(Archivo) Then + Extension = Path.GetExtension(Archivo) + If Extension <> "" Then + If ObjEventos.AddEventoBitacora("XML de Refacturación:", Extension, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then + + 'OBTENEMOS RUTA DONDE GUARDAR | OPCIONAL: CREAMOS CARPETA + Ruta = String.Format("{0}OI", UsuarioActual.Empresa.Ruta) + Ruta.DirectoryExistsCreate() + + 'COPIAMOS EL ARCHIVO A OI + System.IO.File.Copy(Archivo, String.Format("{0}\OI{1}{2}", Ruta, ObjEventos.CveEvento.ToString, Extension)) + Else + ErrorBitacora = True + End If + End If + End If + End If + + 'ADJUNTAMOS ARCHIVO PDF + If Not ErrorBitacora Then + Archivo = String.Format("/Empresas/{0}/Compras/{1}/{2}", dr("CveEmpresa"), dr("RFC"), dr("PDF")) + If File.Exists(Archivo) Then + Extension = Path.GetExtension(Archivo) + If Extension <> "" Then + If ObjEventos.AddEventoBitacora("PDF de Refacturación:", Extension, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then + + 'OBTENEMOS RUTA DONDE GUARDAR | OPCIONAL: CREAMOS CARPETA + Ruta = String.Format("{0}OI", UsuarioActual.Empresa.Ruta) + Ruta.DirectoryExistsCreate() + + 'COPIAMOS EL ARCHIVO A OI + System.IO.File.Copy(Archivo, String.Format("{0}\OI{1}{2}", Ruta, ObjEventos.CveEvento.ToString, Extension)) + + Else + ErrorBitacora = True + End If + End If + End If + End If + + 'LIGA AL FOLIO/COMPRA EN REFACTURACION + If Not ErrorBitacora Then + If Not ObjEventos.AddEventoBitacora(String.Format("Refacturación en: {1}", CveCompra, dr("Folio").ToString), "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompraRefacturacion) Then + ErrorBitacora = True + End If + End If + + End If + End If + End If + + Return ErrorBitacora + End Function + +#End Region + +#Region " CANCELAR COMPRA " + Private Sub ValidaCancelarCompra() + If UsuarioActual.TienePermisoProceso(140) Then + If CveMovimientoAlmacen > 0 And EstatusAlmacen = 2 Then + BtnCancelarCompra.Visible = True + ElseIf CveMovimientoAlmacen = 0 Then + BtnCancelarCompra.Visible = True + End If + End If + End Sub + Protected Sub BtnCancelarCompra2_Click(sender As Object, e As EventArgs) + RegistraScript("$('#DivCancelarCompra').modal('hide');") + + Dim ObjAC As ClsContPAQi = Nothing + If UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.Funcionalidad(200).ToString = "1" Then + ObjAC = New ClsContPAQi(UsuarioActual.Empresa) + ObjAC.IniciaTransacSQL() + End If + + Dim ObjCompras As New ClsCompras + Dim ObjContabilidad As New ClsContabilidad(ObjCompras.IniciaTransacSQL()) + + Dim ErrorCancelar = False + Dim IdPolizaNueva = -1 + Dim FolioPolizaNueva = -1 + Dim CvePrePolizaNueva = -1 + Dim dt As DataTable + + + ' MES ANTERIOR, MOVIMIENTOS CONTRARIOS (NEGATIVOS) + If TxtFecha.Text.ToDate.Month < TxtFechaCancelacion.Text.ToDate.Month Or TxtFecha.Text.ToDate.Year < TxtFechaCancelacion.Text.ToDate.Year Or DdlTipoComprobante.SelectedValue.Contiene("NC") Then + + 'CREA POLIZA NEGATIVA + If IdPoliza > 0 AndAlso ObjAC IsNot Nothing Then + If ObjAC.GetPoliza(IdPoliza, -1, -1, -1, -1) AndAlso ObjAC.DtResultados.Rows.Count > 0 Then + dt = ObjAC.DtResultados + + IdPolizaNueva = ObjAC.AddPoliza(dt.Rows(0)("CodigoTipoPoliza").ToString.ToEntero, String.Format("Cancelacion: {0}", dt.Rows(0)("Concepto").ToString), 0, 0, UsuarioActual.CveUsuario, TxtFechaCancelacion.Text.ToDate) + If IdPolizaNueva > 0 Then + FolioPolizaNueva = ObjAC.Folio + For Each dr As DataRow In dt.Rows + If Not ObjAC.AddMovimiento(IdPolizaNueva, dr("IdCuenta").ToString.ToEntero, dr("TipoMovto").ToString = "True", dr("Importe").ToString.ToDecimal * -1, dr("Referencia").ToString, String.Format("Cancelacion: {0}", dt.Rows(0)("Concepto").ToString), dr("IdSegNeg").ToString.ToEntero, TxtFechaCancelacion.Text.ToDate, "") Then + ErrorCancelar = True : Exit For + End If + Next + + 'AJUSTA POLIZA + If Not ErrorCancelar Then + If Not ObjAC.AjustaPoliza(IdPolizaNueva) Then + ErrorCancelar = True + End If + End If + Else + ErrorCancelar = True + End If + Else + ErrorCancelar = True + End If + End If + + 'CREA PRE-POLIZA NEGATIVA + If DdlTipoComprobante.SelectedValue.Contiene("NC") Then + If ObjCompras.GetCancelarNC(CveCompra, UsuarioActual.CveEmpresa) Then + dt = ObjCompras.DtResultados + + CvePrePolizaNueva = ObjContabilidad.AddPrePolizas("Compras/Cancelar", dt.Rows(0)("CvePlantillaPoliza").ToString.ToEntero, dt.Rows(0)("Cargos").ToString.ToDouble * -1, dt.Rows(0)("Abonos").ToString.ToDouble * -1, dt.Rows(0)("CveMoneda").ToString.ToEntero, TxtFechaCancelacion.Text.ToDate, String.Format("Cancelación: {0}", dt.Rows(0)("Concepto").ToString), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CvePrePolizaNueva > 0 Then + For Each dr As DataRow In dt.Rows + If Not ObjContabilidad.AddPrePolizasDetalle(CvePrePolizaNueva, CBool(dr("TipoMovto").ToString), dr("Importe").ToString.ToDecimal * -1, dr("Referencia").ToString, dr("CveConceptoContable").ToString.ToEntero, + dr("Concepto").ToString, TxtFechaCancelacion.Text.ToDate, dr("IdCtaContable").ToString.ToEntero, dr("IdSegmentoNegocio").ToString.ToEntero, dr("CveIE").ToString.ToEntero, + dr("CveVenta").ToString.ToEntero, dr("CveCompra").ToString.ToEntero, dr("CveSubProyecto").ToString.ToEntero, dr("CveCliente").ToString.ToEntero, dr("CveProveedor").ToString.ToEntero, dr("CvePersonal").ToString.ToEntero, + dr("CveMovimientoAlmacen").ToString.ToEntero, dr("CveActivoFijo").ToString.ToEntero, dr("CveAcreedor").ToString.ToEntero, dr("CveColectiva").ToString.ToEntero, dr("CveCreditoDetalle").ToString.ToEntero, CveCuenta:=dr("CveCuenta").ToString.ToEntero, + ImporteMX:=dr("Importe").ToString.ToDecimal * -1, ImporteME:=dr("Importe").ToString.ToDecimal * -1, CveTipoGasto:=dr("CveTipoGasto").ToString.ToEntero, CveClasificacion:=dr("CveClasificacion").ToString.ToEntero, CveOCDetalle:=dr("CveOCDetalle").ToString.ToEntero, + CveCompraAmortizacion:=dr("CveCompraAmortizacion").ToString.ToEntero) Then + ErrorCancelar = True + Exit For + End If + Next + Else + ErrorCancelar = True + End If + Else + ErrorCancelar = True + End If + Else + If CvePrePoliza > 0 Then + If ObjContabilidad.GetPrePolizasDetalle(CvePrePoliza) Then + dt = ObjContabilidad.DtResultados + + CvePrePolizaNueva = ObjContabilidad.AddPrePolizas("Compras/Cancelar", dt.Rows(0)("CvePlantillaPoliza").ToString.ToEntero, dt.Rows(0)("Cargos").ToString.ToDouble * -1, dt.Rows(0)("Abonos").ToString.ToDouble * -1, dt.Rows(0)("CveMoneda").ToString.ToEntero, TxtFechaCancelacion.Text.ToDate, String.Format("Cancelación: {0}", dt.Rows(0)("Concepto").ToString), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CvePrePolizaNueva > 0 Then + For Each dr As DataRow In dt.Rows + If Not ObjContabilidad.AddPrePolizasDetalle(CvePrePolizaNueva, CBool(dr("TipoMovto").ToString), dr("Importe").ToString.ToDecimal * -1, dr("Referencia").ToString, dr("CveConceptoContable").ToString.ToEntero, + dr("Concepto").ToString, TxtFechaCancelacion.Text.ToDate, dr("IdCtaContable").ToString.ToEntero, dr("IdSegmentoNegocio").ToString.ToEntero, dr("CveIE").ToString.ToEntero, + dr("CveVenta").ToString.ToEntero, dr("CveCompra").ToString.ToEntero, dr("CveSubProyecto").ToString.ToEntero, dr("CveCliente").ToString.ToEntero, dr("CveProveedor").ToString.ToEntero, dr("CvePersonal").ToString.ToEntero, + dr("CveMovimientoAlmacen").ToString.ToEntero, dr("CveActivoFijo").ToString.ToEntero, dr("CveAcreedor").ToString.ToEntero, dr("CveColectiva").ToString.ToEntero, dr("CveCreditoDetalle").ToString.ToEntero, CveCuenta:=dr("CveCuenta").ToString.ToEntero, + ImporteMX:=dr("Importe").ToString.ToDecimal * -1, ImporteME:=dr("Importe").ToString.ToDecimal * -1, CveTipoGasto:=dr("CveTipoGasto").ToString.ToEntero, CveClasificacion:=dr("CveClasificacion").ToString.ToEntero, CveOCDetalle:=dr("CveOCDetalle").ToString.ToEntero) Then + ErrorCancelar = True + Exit For + End If + Next + Else + ErrorCancelar = True + End If + Else + ErrorCancelar = True + End If + End If + End If + + 'MES ACTUAL + Else + + 'LIMPIA POLIZA PONIENDO IMPORTE EN CEROS + If IdPoliza > 0 AndAlso ObjAC IsNot Nothing Then + If ObjAC.GetPoliza(IdPoliza, -1, -1, -1, -1) AndAlso ObjAC.DtResultados.Rows.Count > 0 Then + dt = ObjAC.DtResultados + + For Each dr As DataRow In dt.Rows + If Not ObjAC.UpdateMovimiento(dr("Id").ToString.ToEntero, dr("IdCuenta").ToString.ToEntero, dr("TipoMovto").ToString = "1", 0, dr("Referencia").ToString, dr("Concepto").ToString, dr("IdSegNeg").ToString.ToEntero, dr("Fecha").ToString.ToDate) Then + ErrorCancelar = True : Exit For + End If + Next + + 'AJUSTA POLIZA + If Not ErrorCancelar Then + If Not ObjAC.AjustaPoliza(IdPoliza) Then + ErrorCancelar = True + End If + End If + + Else + ErrorCancelar = True + End If + End If + + 'LIMPIA PRE-POLIZA PONIENDO IMPORTE EN CEROS + If CvePrePoliza > 0 Then + If ObjContabilidad.GetPrePolizasDetalle(CvePrePoliza) Then + dt = ObjContabilidad.DtResultados + + For Each dr As DataRow In dt.Rows + If Not ObjContabilidad.UpdatePrepolizasDetalle(dr("CvePrePolizaDetalle").ToString.ToEntero, dr("Concepto").ToString, dr("CveSubProyecto").ToString.ToEntero, dr("IdCtaContable").ToString.ToEntero, CBool(dr("TipoMovto").ToString), 0) Then + ErrorCancelar = True : Exit For + End If + Next + Else + ErrorCancelar = True + End If + End If + + End If + + + 'CANCELA COMPRA + If Not ErrorCancelar Then + If Not ObjCompras.UpdateEstatusCompra(CveCompra, -2) Then + ErrorCancelar = True + End If + End If + + + If Not ErrorCancelar Then + If ObjAC IsNot Nothing Then + ObjAC.Commit() + End If + ObjCompras.Commit() + Dim Msg As New StringBuilder + Msg.Append("La compra se cancelo correctamente.") + + If IdPolizaNueva > 0 Then Msg.AppendFormat("

Ver Póliza de cancelación", IdPolizaNueva) + Alert(Msg.ToString, TipoMensaje.MsgInformacion) + Else + If ObjAC IsNot Nothing Then + ObjAC.RollBack() + End If + ObjCompras.RollBack() + Alert("La compra no se pudo cancelar. Por favor vuelva a intentar.", TipoMensaje.MsgError) + End If + + ObjCompras.Dispose() + If ObjAC IsNot Nothing Then + ObjAC.Dispose() + End If -#Region " CANCELAR COMPRA " - Private Sub ValidaCancelarCompra() - If UsuarioActual.TienePermisoProceso(140) Then - If CveMovimientoAlmacen > 0 And EstatusAlmacen = 2 Then - BtnCancelarCompra.Visible = True - ElseIf CveMovimientoAlmacen = 0 Then - BtnCancelarCompra.Visible = True - End If - End If - End Sub - Protected Sub BtnCancelarCompra2_Click(sender As Object, e As EventArgs) - RegistraScript("$('#DivCancelarCompra').modal('hide');") - - Dim ObjAC As ClsContPAQi = Nothing - If UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.Funcionalidad(200).ToString = "1" Then - ObjAC = New ClsContPAQi(UsuarioActual.Empresa) - ObjAC.IniciaTransacSQL() - End If - - Dim ObjCompras As New ClsCompras - Dim ObjContabilidad As New ClsContabilidad(ObjCompras.IniciaTransacSQL()) - - Dim ErrorCancelar = False - Dim IdPolizaNueva = -1 - Dim FolioPolizaNueva = -1 - Dim CvePrePolizaNueva = -1 - Dim dt As DataTable - - - ' MES ANTERIOR, MOVIMIENTOS CONTRARIOS (NEGATIVOS) - If TxtFecha.Text.ToDate.Month < TxtFechaCancelacion.Text.ToDate.Month Or TxtFecha.Text.ToDate.Year < TxtFechaCancelacion.Text.ToDate.Year Or DdlTipoComprobante.SelectedValue.Contiene("NC") Then - - 'CREA POLIZA NEGATIVA - If IdPoliza > 0 AndAlso ObjAC IsNot Nothing Then - If ObjAC.GetPoliza(IdPoliza, -1, -1, -1, -1) AndAlso ObjAC.DtResultados.Rows.Count > 0 Then - dt = ObjAC.DtResultados - - IdPolizaNueva = ObjAC.AddPoliza(dt.Rows(0)("CodigoTipoPoliza").ToString.ToEntero, String.Format("Cancelacion: {0}", dt.Rows(0)("Concepto").ToString), 0, 0, UsuarioActual.CveUsuario, TxtFechaCancelacion.Text.ToDate) - If IdPolizaNueva > 0 Then - FolioPolizaNueva = ObjAC.Folio - For Each dr As DataRow In dt.Rows - If Not ObjAC.AddMovimiento(IdPolizaNueva, dr("IdCuenta").ToString.ToEntero, dr("TipoMovto").ToString = "True", dr("Importe").ToString.ToDecimal * -1, dr("Referencia").ToString, String.Format("Cancelacion: {0}", dt.Rows(0)("Concepto").ToString), dr("IdSegNeg").ToString.ToEntero, TxtFechaCancelacion.Text.ToDate, "") Then - ErrorCancelar = True : Exit For - End If - Next - - 'AJUSTA POLIZA - If Not ErrorCancelar Then - If Not ObjAC.AjustaPoliza(IdPolizaNueva) Then - ErrorCancelar = True - End If - End If - Else - ErrorCancelar = True - End If - Else - ErrorCancelar = True - End If - End If - - 'CREA PRE-POLIZA NEGATIVA - If DdlTipoComprobante.SelectedValue.Contiene("NC") Then - If ObjCompras.GetCancelarNC(CveCompra, UsuarioActual.CveEmpresa) Then - dt = ObjCompras.DtResultados - - CvePrePolizaNueva = ObjContabilidad.AddPrePolizas("Compras/Cancelar", dt.Rows(0)("CvePlantillaPoliza").ToString.ToEntero, dt.Rows(0)("Cargos").ToString.ToDouble * -1, dt.Rows(0)("Abonos").ToString.ToDouble * -1, dt.Rows(0)("CveMoneda").ToString.ToEntero, TxtFechaCancelacion.Text.ToDate, String.Format("Cancelación: {0}", dt.Rows(0)("Concepto").ToString), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CvePrePolizaNueva > 0 Then - For Each dr As DataRow In dt.Rows - If Not ObjContabilidad.AddPrePolizasDetalle(CvePrePolizaNueva, CBool(dr("TipoMovto").ToString), dr("Importe").ToString.ToDecimal * -1, dr("Referencia").ToString, dr("CveConceptoContable").ToString.ToEntero, - dr("Concepto").ToString, TxtFechaCancelacion.Text.ToDate, dr("IdCtaContable").ToString.ToEntero, dr("IdSegmentoNegocio").ToString.ToEntero, dr("CveIE").ToString.ToEntero, - dr("CveVenta").ToString.ToEntero, dr("CveCompra").ToString.ToEntero, dr("CveSubProyecto").ToString.ToEntero, dr("CveCliente").ToString.ToEntero, dr("CveProveedor").ToString.ToEntero, dr("CvePersonal").ToString.ToEntero, - dr("CveMovimientoAlmacen").ToString.ToEntero, dr("CveActivoFijo").ToString.ToEntero, dr("CveAcreedor").ToString.ToEntero, dr("CveColectiva").ToString.ToEntero, dr("CveCreditoDetalle").ToString.ToEntero, CveCuenta:=dr("CveCuenta").ToString.ToEntero, - ImporteMX:=dr("Importe").ToString.ToDecimal * -1, ImporteME:=dr("Importe").ToString.ToDecimal * -1, CveTipoGasto:=dr("CveTipoGasto").ToString.ToEntero, CveClasificacion:=dr("CveClasificacion").ToString.ToEntero, CveOCDetalle:=dr("CveOCDetalle").ToString.ToEntero, - CveCompraAmortizacion:=dr("CveCompraAmortizacion").ToString.ToEntero) Then - ErrorCancelar = True - Exit For - End If - Next - Else - ErrorCancelar = True - End If - Else - ErrorCancelar = True - End If - Else - If CvePrePoliza > 0 Then - If ObjContabilidad.GetPrePolizasDetalle(CvePrePoliza) Then - dt = ObjContabilidad.DtResultados - - CvePrePolizaNueva = ObjContabilidad.AddPrePolizas("Compras/Cancelar", dt.Rows(0)("CvePlantillaPoliza").ToString.ToEntero, dt.Rows(0)("Cargos").ToString.ToDouble * -1, dt.Rows(0)("Abonos").ToString.ToDouble * -1, dt.Rows(0)("CveMoneda").ToString.ToEntero, TxtFechaCancelacion.Text.ToDate, String.Format("Cancelación: {0}", dt.Rows(0)("Concepto").ToString), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CvePrePolizaNueva > 0 Then - For Each dr As DataRow In dt.Rows - If Not ObjContabilidad.AddPrePolizasDetalle(CvePrePolizaNueva, CBool(dr("TipoMovto").ToString), dr("Importe").ToString.ToDecimal * -1, dr("Referencia").ToString, dr("CveConceptoContable").ToString.ToEntero, - dr("Concepto").ToString, TxtFechaCancelacion.Text.ToDate, dr("IdCtaContable").ToString.ToEntero, dr("IdSegmentoNegocio").ToString.ToEntero, dr("CveIE").ToString.ToEntero, - dr("CveVenta").ToString.ToEntero, dr("CveCompra").ToString.ToEntero, dr("CveSubProyecto").ToString.ToEntero, dr("CveCliente").ToString.ToEntero, dr("CveProveedor").ToString.ToEntero, dr("CvePersonal").ToString.ToEntero, - dr("CveMovimientoAlmacen").ToString.ToEntero, dr("CveActivoFijo").ToString.ToEntero, dr("CveAcreedor").ToString.ToEntero, dr("CveColectiva").ToString.ToEntero, dr("CveCreditoDetalle").ToString.ToEntero, CveCuenta:=dr("CveCuenta").ToString.ToEntero, - ImporteMX:=dr("Importe").ToString.ToDecimal * -1, ImporteME:=dr("Importe").ToString.ToDecimal * -1, CveTipoGasto:=dr("CveTipoGasto").ToString.ToEntero, CveClasificacion:=dr("CveClasificacion").ToString.ToEntero, CveOCDetalle:=dr("CveOCDetalle").ToString.ToEntero) Then - ErrorCancelar = True - Exit For - End If - Next - Else - ErrorCancelar = True - End If - Else - ErrorCancelar = True - End If - End If - End If - - 'MES ACTUAL - Else - - 'LIMPIA POLIZA PONIENDO IMPORTE EN CEROS - If IdPoliza > 0 AndAlso ObjAC IsNot Nothing Then - If ObjAC.GetPoliza(IdPoliza, -1, -1, -1, -1) AndAlso ObjAC.DtResultados.Rows.Count > 0 Then - dt = ObjAC.DtResultados - - For Each dr As DataRow In dt.Rows - If Not ObjAC.UpdateMovimiento(dr("Id").ToString.ToEntero, dr("IdCuenta").ToString.ToEntero, dr("TipoMovto").ToString = "1", 0, dr("Referencia").ToString, dr("Concepto").ToString, dr("IdSegNeg").ToString.ToEntero, dr("Fecha").ToString.ToDate) Then - ErrorCancelar = True : Exit For - End If - Next - - 'AJUSTA POLIZA - If Not ErrorCancelar Then - If Not ObjAC.AjustaPoliza(IdPoliza) Then - ErrorCancelar = True - End If - End If - - Else - ErrorCancelar = True - End If - End If - - 'LIMPIA PRE-POLIZA PONIENDO IMPORTE EN CEROS - If CvePrePoliza > 0 Then - If ObjContabilidad.GetPrePolizasDetalle(CvePrePoliza) Then - dt = ObjContabilidad.DtResultados - - For Each dr As DataRow In dt.Rows - If Not ObjContabilidad.UpdatePrepolizasDetalle(dr("CvePrePolizaDetalle").ToString.ToEntero, dr("Concepto").ToString, dr("CveSubProyecto").ToString.ToEntero, dr("IdCtaContable").ToString.ToEntero, CBool(dr("TipoMovto").ToString), 0) Then - ErrorCancelar = True : Exit For - End If - Next - Else - ErrorCancelar = True - End If - End If - - End If - - - 'CANCELA COMPRA - If Not ErrorCancelar Then - If Not ObjCompras.UpdateEstatusCompra(CveCompra, -2) Then - ErrorCancelar = True - End If - End If - - - If Not ErrorCancelar Then - If ObjAC IsNot Nothing Then - ObjAC.Commit() - End If - ObjCompras.Commit() - Dim Msg As New StringBuilder - Msg.Append("La compra se cancelo correctamente.") - - If IdPolizaNueva > 0 Then Msg.AppendFormat("

Ver Póliza de cancelación", IdPolizaNueva) - Alert(Msg.ToString, TipoMensaje.MsgInformacion) - Else - If ObjAC IsNot Nothing Then - ObjAC.RollBack() - End If - ObjCompras.RollBack() - Alert("La compra no se pudo cancelar. Por favor vuelva a intentar.", TipoMensaje.MsgError) - End If - - ObjCompras.Dispose() - If ObjAC IsNot Nothing Then - ObjAC.Dispose() - End If - - End Sub - - Private Sub btnProrateo_Click(sender As Object, e As EventArgs) Handles btnProrateo.Click, btnProrateo2.Click - Dim IvaOriginal As Double = TxtIVA.Text.ToDouble - - Dim CuentaContable = DirectCast(sender, Button).CommandArgument.ToString - Select Case CuentaContable - Case "Compras" - StringProrrateo = UsuarioActual.Empresa.Funcionalidad(117) - Case "Nomina" - StringProrrateo = UsuarioActual.Empresa.Funcionalidad(303) - End Select - - Dim porcentajes As String() = StringProrrateo.Split(New Char() {";"c}) - - Dim prtDT As DataTable = TmpDT.Copy - Dim GBSP As DataTable = GlobalDTSubProyectos(DdlProyecto.SelectedValue.ToString.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa) - - TmpDT.Clear() - Dim subtotal As Decimal = TxtSubTotal.Text.ToDecimal - Dim subtotal2 As Decimal = TxtSubTotal2.Text.ToDecimal - Dim des As Decimal = TxtDescuento.Text.ToDecimal - Dim ivaa As Decimal = TxtIVA.Text.ToDecimal - - TxtSubTotal.Text = "0.00" - TxtSubTotal2.Text = "0.00" - If CveFactura = 0 Then - TxtDescuento.Text = "0.00" - TxtIVA.Text = "0.00" - End If - - For Each dr As DataRow In prtDT.Rows - Dim CveUM As Integer = dr("CveUM").ToString.ToEntero - Dim UM As String = dr("UM").ToString - Dim CveClasificacion As Integer = dr("CveClasificacion").ToString.ToEntero - Dim Clasificacion As String = dr("Clasificacion").ToString - Dim CvePS As Integer = dr("CvePS").ToString.ToEntero - Dim PS As String = dr("PS").ToString - Dim CveTipoPS As Integer = dr("CveTipoPS").ToString.ToEntero - Dim Proyecto As String = dr("Proyecto").ToString - Dim Obs As String = dr("Obs").ToString - Dim PU As Double = dr("PU").ToString.ToDouble - Dim IVA As Double = dr("IVA").ToString.ToDouble - Dim RetIVA As Double = dr("RetIVA").ToString.ToDouble - Dim RetISR As Double = dr("RetISR").ToString.ToDouble - Dim IEPSPS As Double = dr("IEPSPSPorcentaje").ToString.ToDouble - Dim IEPSPSIVA As Double = If(dr("IEPSGrabaIVA").ToString = "True", dr("IEPSPorcentaje").ToString.ToDouble, 0) - Dim Descuento As Double = dr("Descuento").ToString.ToDouble - Dim CveOrdenCompraDetalle As Integer = dr("CveOrdenCompraDetalle").ToString.ToEntero - - For Each cadena As String In porcentajes - - Dim valores As String() = cadena.Split(New Char() {","c}) - Dim Cantidad As Double = dr("Cantidad").ToString.ToDouble * (valores(1).ToDouble / 100) - Dim CveSubProyectoContrato As String = valores(0) - Dim CveProyecto As String = valores(0) - Dim Total As Double = Cantidad * PU - Dim drT As DataRow = GBSP.FiltroPrimero(String.Format("CveSubProyecto = {0} ", CveSubProyectoContrato)) - Dim drq As DataRow = GBSP.FiltroPrimero(String.Format("CveProyecto = {0} ", CveProyecto)) - Dim SubProyecto As String = drT("SubProyecto").ToString - - AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, RetIVA, RetISR, IEPSPS, IEPSPSIVA, Descuento, CveOrdenCompraDetalle:=CveOrdenCompraDetalle) - Next - Next - - AddPS2() - - AjustaImporteUltimoConcepto(subtotal2 - TmpDT.SUM("Total").ToString.ToDecimal) - TxtIVA.Text = IvaOriginal.ToString - CalculaTotales(True) - - LbAgregar.Visible = False - UpPSS.Update() - prtDT = TmpDT.Copy - prtDT.Clear() - - End Sub - - - - Private Sub BtnValesCombustibleVer_Click(sender As Object, e As EventArgs) Handles BtnValesCombustibleVer.Click - - Dim AF As New ClsAF - - If AF.GetValesCombustible(-1, -1, -1, CveProveedor, -1, -1, -1, -1, -1, -1, -1, UsuarioActual.CveEmpresa, -1, -1) Then - GvVales.DataSource = AF.DtResultados - End If - - AF.Dispose() - GvVales.DataBind() - DivValesCombustible.Visible = True - RegistraScript(String.Format("$('#{0}').modal('show')", DivValesCombustible.ClientID)) - UPPValesCombustible.Update() End Sub -#End Region + Private Sub btnProrateo_Click(sender As Object, e As EventArgs) Handles btnProrateo.Click, btnProrateo2.Click + Dim IvaOriginal As Double = TxtIVA.Text.ToDouble + + Dim CuentaContable = DirectCast(sender, Button).CommandArgument.ToString + Select Case CuentaContable + Case "Compras" + StringProrrateo = UsuarioActual.Empresa.Funcionalidad(117) + Case "Nomina" + StringProrrateo = UsuarioActual.Empresa.Funcionalidad(303) + End Select + + Dim porcentajes As String() = StringProrrateo.Split(New Char() {";"c}) + + Dim prtDT As DataTable = TmpDT.Copy + Dim GBSP As DataTable = GlobalDTSubProyectos(DdlProyecto.SelectedValue.ToString.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa) + + TmpDT.Clear() + Dim subtotal As Decimal = TxtSubTotal.Text.ToDecimal + Dim subtotal2 As Decimal = TxtSubTotal2.Text.ToDecimal + Dim des As Decimal = TxtDescuento.Text.ToDecimal + Dim ivaa As Decimal = TxtIVA.Text.ToDecimal + + TxtSubTotal.Text = "0.00" + TxtSubTotal2.Text = "0.00" + If CveFactura = 0 Then + TxtDescuento.Text = "0.00" + TxtIVA.Text = "0.00" + End If + + For Each dr As DataRow In prtDT.Rows + Dim CveUM As Integer = dr("CveUM").ToString.ToEntero + Dim UM As String = dr("UM").ToString + Dim CveClasificacion As Integer = dr("CveClasificacion").ToString.ToEntero + Dim Clasificacion As String = dr("Clasificacion").ToString + Dim CvePS As Integer = dr("CvePS").ToString.ToEntero + Dim PS As String = dr("PS").ToString + Dim CveTipoPS As Integer = dr("CveTipoPS").ToString.ToEntero + Dim Proyecto As String = dr("Proyecto").ToString + Dim Obs As String = dr("Obs").ToString + Dim PU As Double = dr("PU").ToString.ToDouble + Dim IVA As Double = dr("IVA").ToString.ToDouble + Dim RetIVA As Double = dr("RetIVA").ToString.ToDouble + Dim RetISR As Double = dr("RetISR").ToString.ToDouble + Dim IEPSPS As Double = dr("IEPSPSPorcentaje").ToString.ToDouble + Dim IEPSPSIVA As Double = If(dr("IEPSGrabaIVA").ToString = "True", dr("IEPSPorcentaje").ToString.ToDouble, 0) + Dim Descuento As Double = dr("Descuento").ToString.ToDouble + Dim CveOrdenCompraDetalle As Integer = dr("CveOrdenCompraDetalle").ToString.ToEntero + + For Each cadena As String In porcentajes + + Dim valores As String() = cadena.Split(New Char() {","c}) + Dim Cantidad As Double = dr("Cantidad").ToString.ToDouble * (valores(1).ToDouble / 100) + Dim CveSubProyectoContrato As String = valores(0) + Dim CveProyecto As String = valores(0) + Dim Total As Double = Cantidad * PU + Dim drT As DataRow = GBSP.FiltroPrimero(String.Format("CveSubProyecto = {0} ", CveSubProyectoContrato)) + Dim drq As DataRow = GBSP.FiltroPrimero(String.Format("CveProyecto = {0} ", CveProyecto)) + Dim SubProyecto As String = drT("SubProyecto").ToString + + AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, RetIVA, RetISR, IEPSPS, IEPSPSIVA, Descuento, CveOrdenCompraDetalle:=CveOrdenCompraDetalle) + Next + Next + + AddPS2() + + AjustaImporteUltimoConcepto(subtotal2 - TmpDT.SUM("Total").ToString.ToDecimal) + TxtIVA.Text = IvaOriginal.ToString + CalculaTotales(True) + + LbAgregar.Visible = False + UpPSS.Update() + prtDT = TmpDT.Copy + prtDT.Clear() -#Region " VALES COMBUSTIBLES " - Protected Sub BtnValesVincular_Click(sender As Object, e As EventArgs) - IdVale = New List(Of Integer) - - For Each row As GridViewRow In GvVales.Rows - If row.FCCheckBox("ChkVale").Checked Then - IdVale.Add(row.DataKey("CveVale").ToEntero) - End If - Next - - If IdVale.Count <= 0 Then - Alert("Debe elegir por lo menos un vale de combustible. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - Else - Alert("Los vales selecciondos están listos para vincular") - RegistraScript(String.Format("$('#{0}').modal('hide')", DivValesCombustible.ClientID)) - 'For Each cve In IdVale - ' Alert(cve.ToString) - 'Next - End If End Sub -#End Region -#Region " VINCULAR OC " - Private Sub InicializaOC() - 'BORRAR OC - 'TabOC.Visible = False - - TabOC.Visible = False - - EmpresasOC = New List(Of Integer) - - ''TODAS LAS EMPRESAS LO TIENEN Y LA 66 SOLO LOS USUARIOS DE ABAJO - EMPRESA QUE ESTE EN LA LISTA NO TENDRA NUEVO ESQUEMA - 'If UsuarioActual.CveEmpresa = 66 AndAlso Not UsuarioActual.CveUsuario.Contiene(1434, 1436, 1337, 1440) Then - ' EmpresasOC.Add(UsuarioActual.CveEmpresa) - 'End If - - 'If Not EmpresasOC.Contains(UsuarioActual.CveEmpresa) Then - TabOC.Visible = True - 'Else - 'TabOC.Visible = True - 'End If - - If Not UsuarioActual.TienePermisoProceso(242) Then - DdlOCVinculaInv.Items.RemoveAt(2) - DdlOCVinculaInv.Items.RemoveAt(3) - End If - - End Sub - Protected Sub BtnBuscarOC_Click(sender As Object, e As EventArgs) Handles BtnBuscarOC.Click - PopUpOC = False - CargaOC() - End Sub - Protected Sub CargaVOC(sender As Object, e As EventArgs) - PopUpOC = True - CargaOC() - End Sub - Private Sub CargaOC() - Dim EntregaDirecta = 0 - DivOCSolicitudAnticipo.Visible = False - DivOCSolicitudAnticipoModal.Visible = False - - If CveProveedor <= 0 Then - Alert("Debe de Seleccionar un proveedor") - Exit Sub - End If - - 'BANDERA DE SURTIDO - If UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 Then - GvOC1.Columns(1).Visible = True - End If - - Dim CvesOC = "" - - - If PopUpOC Then - CvesOC = HdnVCveOC.Value - End If - - HdnVCveOC.Value = "" - HdnCveEstatusOC.Value = "" - - Dim OC As New ClsOC - If PopUpOC Then - Dim ArrayCveOC As String() = CvesOC.Split(New Char() {","c}) - For i As Integer = 0 To ArrayCveOC.Count - 1 - If OC.GetOrdenesCompraRep("OC", -1, -1, -1, -1, MinFecha, MaxFecha, ArrayCveOC(i).ToEntero, CveProveedor, -1, -1, -1, UsuarioActual.CveEmpresa, -1) Then - If OC.DtResultados.FiltraParametros("TipoTermino = 3").Rows.Count = 1 Or DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - HdnVCveOC.Value += String.Format("{0}{1}", If(HdnVCveOC.Value <> "", ",", ""), OC.DtResultados.Rows(0)("CveOrdenCompra").ToString) - HdnCveEstatusOC.Value += String.Format("{0}{1}", If(HdnCveEstatusOC.Value <> "", ",", ""), OC.DtResultados.Rows(0)("CveEstatusSiguiente").ToString) - EntregaDirecta += If(OC.DtResultados.Rows(0)("EntregaDirecta").ToString = "True", 1, 0) - End If - End If - Next - Else - Dim TextoErrorOC = "" - Dim ArrayCveOC As String() = TxtOC.Text.Split(New Char() {","c}) - For i As Integer = 0 To ArrayCveOC.Count - 1 - If OC.GetOrdenesCompraRep("OC", -1, -1, -1, -1, MinFecha, MaxFecha, -1, CveProveedor, ArrayCveOC(i).ToEntero, -1, -1, UsuarioActual.CveEmpresa, -1) Then - If OC.DtResultados.Rows.Count > 1 Then - TextoErrorOC += $"
El folio {ArrayCveOC(i).ToEntero} no se pudo identificar." - End If - If OC.DtResultados.FiltraParametros("TipoTermino = 3").Rows.Count = 1 Or DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then - HdnVCveOC.Value += String.Format("{0}{1}", If(HdnVCveOC.Value <> "", ",", ""), OC.DtResultados.Rows(0)("CveOrdenCompra").ToString) - HdnCveEstatusOC.Value += String.Format("{0}{1}", If(HdnCveEstatusOC.Value <> "", ",", ""), OC.DtResultados.Rows(0)("CveEstatusSiguiente").ToString) - EntregaDirecta += If(OC.DtResultados.Rows(0)("EntregaDirecta").ToString = "True", 1, 0) - End If - End If - Next - If TextoErrorOC <> "" Then - Alert($"Las siguientes Ordenes de Compra no se pudieron vincular automaticamente:
{TextoErrorOC}

Sera necesario vincular de manera manual mediante busqueda (lupia).", TipoMensaje.MsgAdvertencia) - TxtOC.Text = "" - Exit Sub - End If - End If - OC.Dispose() - PopUpOC = False - - - If HdnVCveOC.Value <> "" Then - If HdnCveEstatusOC.Value = "" Then - Alert("No se tiene especificado el siguiente estatus de la Orden(es) de Compra. Por favor verifique los estatus y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - VinculaOC() - - If EntregaDirecta > 0 Then - Alert("Se identificó una Orden de Compra con entrega directa, por lo cual no se podra recibir en almacén desde este modulo, para esto es necesario recibir la mercancía desde la Orden de Compra.", TipoMensaje.MsgAdvertencia) - TabAlmacen.Visible = False - DivOCEntregaDirecta.Visible = True - End If - - BtnGuardar.Enabled = False - TxtOC.Enabled = False - ImgBtnBuscarOC.Enabled = False - UpFacturar.Update() - - Else - Alert("No se encontro ninguna Orden de Compra con el folio especificado.", TipoMensaje.MsgAdvertencia) - End If - - UPPOC.Update() - UpPS.Update() - End Sub - Protected Sub BtnVOC_Click(sender As Object, e As EventArgs) - VinculaOC() - End Sub - Private Sub VinculaOC() - If TxtOC.Text <> "" Then - - 'VARIABLES - Dim TextoObservaciones = "" - LtOCPromocion.Text = "" - IvaAcumulado = 0 - DTOCTemp = New DataTable - - 'SI NO ES UNA COMPRA REGISTRADA = ENABLE FALSE TAB GENERALES, ACTIVE TAB OC - If Not CveCompra > 0 Then - TabGenerales.Enabled = False - TAB.ActiveTabIndex = 2 - UpTabs.Update() - End If - - 'CARGAMOS LOS DATOS DE LAS OC - Dim ObjOC As New ClsOC - Dim ArrayCveOC As String() = HdnVCveOC.Value.Split(New Char() {","c}) - Dim FoliosOCAnticipo = "", FoliosOCAnticipoIE = "" - Dim StrPromos As New StringBuilder - - For Each CveOCItem As String In ArrayCveOC.Distinct - If ObjOC.GetOrdenesDetalle(CveOCItem.ToEntero) AndAlso ObjOC.DtResultados.Rows.Count > 0 Then - If IsNothing(DTOCTemp) Then - DTOCTemp = ObjOC.DtResultados.Copy - Else - DTOCTemp.Merge(ObjOC.DtResultados) - End If - - IvaAcumulado += ObjOC.DtResultados.Rows(0)("IVA").ToString.ToDouble - TextoObservaciones += ObjOC.DtResultados.Rows(0)("Descripcion").ToString - - If ObjOC.DtResultados.Rows.Count > 0 Then - - ''MONEDA DIFERENTE - If ObjOC.DtResultados.Rows(0)("CveMoneda").ToString.ToEntero <> DdlMoneda.SelectedValue.ToEntero Then - DivTipoCambioOC.Visible = True - TxtTipoCambioOC.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString - BtnVincularOCCompleta.Visible = False - BtnVincularOC.Visible = False - End If - - ''SOLICITUD DE ANTICIPO - If ObjOC.DtResultados.Rows(0)("CveIEAnticipo").ToString.ToEntero > 0 Then - FoliosOCAnticipo += $"{ObjOC.DtResultados.Rows(0)("FolioOC").ToString}," - FoliosOCAnticipoIE += $"{ObjOC.DtResultados.Rows(0)("FolioIEAnticipo").ToString}," - DivOCSolicitudAnticipo.Visible = True - DivOCSolicitudAnticipoModal.Visible = True - End If - - 'PROMOCIONES - Dim Promocion = ObjOC.DtResultados.Rows(0)("Promocion").ToString - If Not String.IsNullOrEmpty(Promocion) Then - Dim FolioOC = ObjOC.DtResultados.Rows(0)("FolioOC").ToString - StrPromos.Append($"OC #{FolioOC} {Promocion}
") - StrPromos.AppendLine() - End If - End If - - Else - Alert("Ocurrio un Error al cargar la(s) Orden(es) de Compra", TipoMensaje.MsgError) - If DTOCTemp IsNot Nothing Then DTOCTemp.Rows.Clear() - TextoObservaciones = "" - Exit Sub - End If - Next - ObjOC.Dispose() - - 'MOVIMIENTOS DE ALMACÉN - Dim ObjInventarios As New ClsInventarios - Dim FoliosOCAlmacen = "" - For Each CveOCItem As String In ArrayCveOC.Distinct - If ObjInventarios.GetMovimientosOC(CveOCItem.ToEntero, UsuarioActual.CveEmpresa) Then - If ObjInventarios.DtResultados.Rows.Count > 0 Then - FoliosOCAlmacen = $"{ObjInventarios.DtResultados.FiltroPrimeroValor("FolioOC")}," - End If - Else - Alert("Ocurrió un error al cargar los movimientos de almacén de la orden de compra", TipoMensaje.MsgError) - ObjInventarios.Dispose() - Exit Sub - End If - Next - ObjInventarios.Dispose() - If FoliosOCAlmacen.Length > 0 Then - DivOCAlmacen.Visible = True - LtOCAlmacen.Text = FoliosOCAlmacen.Substring(0, FoliosOCAlmacen.Length - 1) - End If - - 'SI PUEDE RECIBIR POR OC Y COMPRA - If UsuarioActual.CveEmpresa.Contiene(119) Then - If UsuarioActual.Empresa.UsaInventarios And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 And Not UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 Then - DivOCVinculaInv.Visible = True - End If - End If - - - 'TIPO CAMBIO - If CveCompra > 0 Then - DivTipoCambioOC.Visible = False - End If - - DTOCTemp.Columns.Add("PUTC", GetType(Double)) - DTOCTemp.Columns.Add("TotalTC", GetType(Double)) - DTOCTemp.Columns.Add("DescuentoTC", GetType(Double)) - DTOCTemp.Columns.Add("IVATC", GetType(Double)) - DTOCTemp.Columns.Add("IEPSPSTC", GetType(Double)) - DTOCTemp.Columns.Add("IEPSPSIVATC", GetType(Double)) - DTOCTemp.Columns.Add("RetIVATC", GetType(Double)) - DTOCTemp.Columns.Add("RetISRTC", GetType(Double)) - DTOCTemp.Columns.Add("FolioAlmacen", GetType(String)) - For Each Dr As DataRow In DTOCTemp.Rows - Dr("PUTC") = Dr("Importe") - Dr("DescuentoTC") = Dr("Descuento") - Dr("IVATC") = Dr("IVA") - Dr("IEPSPSTC") = Dr("IEPSPS") - Dr("IEPSPSIVATC") = Dr("IEPSPSIVA") - Dr("RetIVATC") = Dr("RetIVA") - Dr("RetISRTC") = Dr("RetISR") - Dr("TotalTC") = Dr("ImporteAjustadoDescuento") - - '[IPP] - JAMEntregaAdelantado | AJUSTE DE CANITDAD POR RECIBIR EN BASE A SALDOS DE INV-COMPRAS - 'If UsuarioActual.CveUsuario = 100 Then - 'If Dr("CveTipoPS").ToString.ToEntero = 2 And UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 Then - ' Dr("CantidadDisponible") = If(Dr("CantidadDisponible").ToString.ToDouble > Dr("CantidadPendienteVincular").ToString.ToDouble, Dr("CantidadPendienteVincular"), Dr("CantidadDisponible")) - 'End If - 'End If - Next - - 'DESCRIPCION DE OC CUANDO NO ES COMPRA REGISTRADA - If Not CveCompra > 0 Then TxtDescripcion.Text = TextoObservaciones - - 'SOLICITUD DE ANTICIPO - If DivOCSolicitudAnticipo.Visible And FoliosOCAnticipo.Length > 0 Then - LtSolicitudAnticipoFoliosOC.Text = $"La(s) siguiente(s) OC: {FoliosOCAnticipo.Substring(0, FoliosOCAnticipo.Length - 1)}. tienen vinculado un anticipo" - LtSolicitudAnticipoFoliosIE.Text = $" {FoliosOCAnticipoIE.Substring(0, FoliosOCAnticipoIE.Length - 1)}" - End If - - 'PROMOCIONES - LtOCPromocion.Text = StrPromos.ToString - If LtOCPromocion.Text.Length > 0 And UsuarioActual.CveEmpresa = 119 Then - DivOCPromocion.Visible = True - End If - - 'CARGA DATOS DE OC - CargaVinculacionOC(True) - - End If - End Sub - Protected Sub DdlOCVinculaInv_SelectedIndexChanged(sender As Object, e As EventArgs) - CargaVinculacionOC() - End Sub - Private Sub CargaVinculacionOC(Optional CargaInicial As Boolean = False) - 'FILTRAMOS SOLO PENDIENTES POR SURTIR - DTOCGV = DTOCTemp.FiltraParametros("CantidadDisponible > 0", "CveOrdenCompra").Copy - - 'SI PUEDE RECIBIR POR OC Y COMPRA - If UsuarioActual.CveEmpresa.Contiene(119) Then - If UsuarioActual.Empresa.UsaInventarios And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 And Not UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 Then - Select Case DdlOCVinculaInv.SelectedValue.ToEntero - Case 176 - DTOCGV = DTOCGV.FiltraParametros("((EstatusInventario IN (3,5) AND CveTipoPS = 2) OR CveTipoPS = 1) AND CantidadPorAdelantado > 0") - Case 205 - DTOCGV = DTOCGV.FiltraParametros("(EstatusInventario IN (1,2) AND CveTipoPS = 2) OR CveTipoPS = 1") - End Select - End If - End If - - If DTOCGV.Rows.Count = 0 Then - Alert("La orden de compra no tiene nada pendiente por vincular. En caso de ser Entrega Directa por favor verifique el estatus de facturación.", TipoMensaje.MsgAdvertencia) - End If - - CargaGvsOC() - - CargaTotalesOC() - - 'Diferencia permitida $ entre OC y Compra - Dim DiferenciaPermitida = 1 - - 'VINCULACION TOTAL - If CargaInicial And DivTipoCambioOC.Visible = False Then - If LbTotalOC1.Text = LbTotalOC2.Text AndAlso (UsuarioActual.CveEmpresa.Contiene(1, 4, 7, 11, 12, 48, 13, 66, 72, 80, 145)) AndAlso CveCompra <= 0 Then - BtnVincularOCCompleta.Visible = Not DivTipoCambioOC.Visible - Else - BtnVincularOCCompleta.Visible = False - End If - Else - If LbTotalOC1.Text = LbTotalOC2.Text AndAlso (UsuarioActual.CveEmpresa.Contiene(1, 4, 7, 11, 12, 48, 13, 66, 72, 80, 145)) AndAlso CveCompra <= 0 Then - BtnVincularOCCompleta.Visible = Not DivTipoCambioOC.Visible - Else - BtnVincularOCCompleta.Visible = False - End If - End If - - UpOC.Update() - - ' If DdlOCVinculaInv.SelectedValue.ToEntero.Contiene(237, 240) Then CargaModalFletesImportaciones() - - End Sub - - Private Sub CargaTipoCentroCostoOC() - If UsuarioActual.Empresa.Tipo_CentroCosto = 1 Then - GvOC1.Columns(5).HeaderText = "Sucursal" - ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 2 Then - GvOC1.Columns(5).HeaderText = "Proyecto" - ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 4 Then - GvOC1.Columns(5).HeaderText = "Sucursal
Proyecto" - ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 5 Then - GvOC1.Columns(5).HeaderText = "Proyecto
Sucursal" - End If - End Sub - Private Sub CargaGvsOC() - - 'SI ES MAS DE UNA OC ORDENA POR PRODUCTO - Dim ArrayCveOC As String() = HdnVCveOC.Value.Split(New Char() {","c}) - DTOCGV = If(ArrayCveOC.Length > 1, DTOCGV.FiltraParametros("", "Producto"), DTOCGV) - - CargaTipoCentroCostoOC() - GvOC1.DataSource = DTOCGV - GvOC1.DataBind() - - Dim DTCVEOGV As DataTable = DTOCGV.FiltraParametros("", "", {"CveOrdenCompra"}) - If DTCVEOGV.Rows.Count > 1 Then - GvOC1.Columns(0).Visible = True - Else - GvOC1.Columns(0).Visible = False - End If - - Dim Cont As Integer = 0 - For Each gvr As GridViewRow In GvOC1.Rows - RegistraScript($"CalculaTotalOCEdit('{gvr.DataKey("PS").Replace("'", "")}', {gvr.DataKey("CantidadDisponible").ToString.ToDouble}, {gvr.FCTextBox("TxtCantidad").ClientID}, {gvr.FCTextBox("TxtPU").ClientID}, {gvr.FCTextBox("TxtTotalOC1").ClientID}, {gvr.DataKey("IEPSPS").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1IEPSImporte").ClientID}, {gvr.DataKey("IVA").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1IVA").ClientID},{gvr.DataKey("RetIVA").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1RetIVA").ClientID},{gvr.DataKey("RetISR").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1RetISR").ClientID},{gvr.DataKey("IEPSPS").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1IEPSIVA").ClientID},{gvr.DataKey("Descuento")},{gvr.FCHiddenField("HdnOC1Descuento").ClientID},{gvr.DataKey("IVAPorcentaje").ToString.ToDouble},{gvr.DataKey("RetIVAPorcentaje").ToString.ToDouble},{gvr.DataKey("RetISRPorcentaje").ToString.ToDouble},{gvr.DataKey("IEPSPSPorcentaje").ToString.ToDouble},{gvr.DataKey("IEPSPSIVAPorcentaje").ToString.ToDouble});", $"Gv{Cont}") - Cont += 1 - Next - - UpGvOC1.Update() - - TmpDT = TmpDT.FiltraParametros("", "PU") - - - GvOC2.DataSource = TmpDT - GvOC2.DataBind() - UpGvOC2.Update() - End Sub - Protected Sub GvOC1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvOC1.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - - Dim JSCambiaScript = $"CalculaTotalOCEdit('{e.Row.DBCampo("PS").Replace("'", "")}', {e.Row.DBCampo("CantidadDisponible").ToString.ToDouble}, {e.Row.FCTextBox("TxtCantidad").ClientID}, {e.Row.FCTextBox("TxtPU").ClientID}, {e.Row.FCTextBox("TxtTotalOC1").ClientID}, {e.Row.DBCampo("IEPSPS").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1IEPSImporte").ClientID}, {e.Row.DBCampo("IVA").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1IVA").ClientID},{e.Row.DBCampo("RetIVA").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1RetIVA").ClientID},{e.Row.DBCampo("RetISR").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1RetISR").ClientID},{e.Row.DBCampo("IEPSPS").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1IEPSIVA").ClientID},{e.Row.DBCampo("Descuento")},{e.Row.FCHiddenField("HdnOC1Descuento").ClientID},{e.Row.DBCampo("IVAPorcentaje").ToString.ToDouble},{e.Row.DBCampo("RetIVAPorcentaje").ToString.ToDouble},{e.Row.DBCampo("RetISRPorcentaje").ToString.ToDouble},{e.Row.DBCampo("IEPSPSPorcentaje").ToString.ToDouble},{e.Row.DBCampo("IEPSPSIVAPorcentaje").ToString.ToDouble});" - e.Row.FCTextBox("TxtCantidad").Attributes.Add("onkeyup", $"LimitaCantidadOC({e.Row.DBCampo("CantidadDisponible")}, this);{JSCambiaScript}") - e.Row.FCTextBox("TxtPU").Attributes.Add("onkeyup", JSCambiaScript) - - e.Row.FCTextBox("TxtCantidad").Attributes.Add("onblur", $"ValidaImporteCero('{e.Row.DBCampo("PS").Replace("'", "")}',{e.Row.FCTextBox("TxtCantidad").ClientID}, {e.Row.FCTextBox("TxtPU").ClientID});") - e.Row.FCTextBox("TxtPU").Attributes.Add("onblur", $"ValidaImporteCero('{e.Row.DBCampo("PS").Replace("'", "")}',{e.Row.FCTextBox("TxtCantidad").ClientID}, {e.Row.FCTextBox("TxtPU").ClientID});") - - - RegistraScript(JSCambiaScript) - - - If e.Row.DataKey("FolioREQ").ToString.Trim.Length > 0 Then - Dim LblOC As Label = e.Row.FCLabel("LblOC") - LblOC.Attributes.Add("data-toggle", "tooltip") - LblOC.Attributes.Add("data-placement", "top") - LblOC.Attributes.Add("title", "REQ: " & e.Row.DataKey("FolioREQ").ToString) - End If - - - - If e.Row.DBCampo("CveTipoPS").ToEntero = 2 And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 Then - Select Case e.Row.DBCampo("EstatusInventario").ToEntero - Case 1 - e.Row.FCLabel("LbEstatusInv").Text = "" - e.Row.FCLabel("LbEstatusInv").ForeColor = Drawing.Color.Red - Case 2 - e.Row.FCLabel("LbEstatusInv").Text = "" - e.Row.FCLabel("LbEstatusInv").ForeColor = Drawing.Color.DarkOrange - Case 3 - e.Row.FCLabel("LbEstatusInv").Text = "" - e.Row.FCLabel("LbEstatusInv").ForeColor = Drawing.Color.Green - Case Else - e.Row.FCLabel("LbEstatusInv").Text = "ERR" - End Select - ElseIf e.Row.DBCampo("CveTipoPS").ToEntero = 1 And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 Then - e.Row.FCLabel("LbEstatusInv").Text = "NA" - End If - - If Version = "3.3" Then - CargaPSSAT(e.Row.FCDropDownLost("DdlSATPS")) - If e.Row.DBCampo("CveSATPS").ToEntero > 0 Then - e.Row.FCDropDownLost("DdlSATPS").SelectedValue = e.Row.DBCampo("CveSATPS") - e.Row.FCDropDownLost("DdlSATPS").SelectedText = $"{e.Row.DBCampo("SATClaveProductoServicio")}" - End If - End If - - End If - End Sub - - Private Sub CargaPSSAT(Objeto As ADServerControl.Dropdownlost) - Objeto.setEsWebService(True) - Objeto.ddlWS.Attributes.Add("data-metodo", "getpssat") - End Sub - - Private Sub CargaTotalesOC() - - Dim TotalOC = 0.0D - For Each gvr As GridViewRow In GvOC1.Rows - TotalOC += gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal - Next - - 'SUBTOTAL OC - LbSubTotalOC1Mod.Text = (TotalOC + DTOCGV.SUM("Descuento")).FormatoNumero - LbSubTotalOC1.Text = (TotalOC + DTOCGV.SUM("Descuento")).FormatoNumero - - 'SUBTOTAL2 OC - LbSubTotal2OC1Mod.Text = TotalOC.FormatoNumero - LbSubTotal2OC1.Text = TotalOC.FormatoNumero - - 'IVA OC - LbIVAOC1Mod.Text = (DTOCGV.SUM("IVA").ToString.ToDouble + DTOCGV.SUM("IEPSPSIVA").ToString.ToDouble).FormatoNumero - LbIVAOC1.Text = (DTOCGV.SUM("IVA").ToString.ToDouble + DTOCGV.SUM("IEPSPSIVA").ToString.ToDouble).FormatoNumero - - 'DESCUENTO OC - LbDescuentoOC1Mod.Text = DTOCGV.SUM("Descuento").FormatoNumero - LbDescuentoOC1.Text = DTOCGV.SUM("Descuento").FormatoNumero - If LbDescuentoOC1.Text.ToDecimal > 0 Then - TrDescuentosOC1.Visible = True - End If - - 'IEPS OC - LbIEPSOCMod1.Text = DTOCGV.SUM("IEPSPS").FormatoNumero - LbIEPSOC1.Text = DTOCGV.SUM("IEPSPS").FormatoNumero - If LbIEPSOC1.Text.ToDecimal > 0 Then - TrIEPSOC1.Visible = True - End If - - 'RET IVA OC - LblRetIVAOC1Mod.Text = DTOCGV.SUM("RetIVA").ToString.FormatoNumero - LblRetIVAOC1.Text = DTOCGV.SUM("RetIVA").ToString.FormatoNumero - If LblRetIVAOC1.Text.ToDecimal > 0 Then - TrRetIVAOC1.Visible = True - End If - - 'RET ISR OC - LblRetISROC1Mod.Text = DTOCGV.SUM("RetISR").ToString.FormatoNumero - LblRetISROC1.Text = DTOCGV.SUM("RetISR").ToString.FormatoNumero - If LblRetISROC1.Text.ToDecimal > 0 Then - TrRetISROC1.Visible = True - End If - - 'TOTAL OC - TotalOC = TotalOC + LbIVAOC1.Text.ToDecimal + LbIEPSOC1.Text.ToDecimal - LblRetIVAOC1.Text.ToDecimal - LblRetISROC1.Text.ToDecimal - LbTotalOC1.Text = TotalOC.FormatoNumero - LbTotalOC1Mod.Text = TotalOC.FormatoNumero - - 'SUBTOTAL COMPRA - LbSubTotalOC2.Text = TxtSubTotal.Text - - 'SUBTOTAL2 COMPRA - LblSubTotal2OC2.Text = TxtSubTotal2.Text - - 'IVA COMPRA - LbIVAOC2.Text = TxtIVA.Text - - 'IEPS COMPRA - LbIEPSOC2.Text = TxtIEPS.Text - If LbIEPSOC2.Text.ToDecimal > 0 Then - TrIEPSOC2.Visible = True - End If - - 'DESCUENTO COMPRA - LblDescuentoOC2.Text = TxtDescuento.Text - If LblDescuentoOC2.Text.ToDecimal > 0 Then - TrDescuentosOC2.Visible = True - End If - - 'RET IVA COMPRA - LblRetIVAOC2.Text = TxtRetIVA.Text - If LblRetIVAOC2.Text.ToDecimal > 0 Then - TrRetIVAOC2.Visible = True - End If - - 'RET ISR COMPRA - LblRetISROC2.Text = TxtRetISR.Text - If LblRetISROC2.Text.ToDecimal > 0 Then - TrRetISROC2.Visible = True - End If - - 'ANTICIPOS COMPRA - Dim ImporteAnticipo As Decimal = 0 - If ArrAnticipos.Count > 0 Then - For Each Ant As Compras_Compras.Anticipos In ArrAnticipos - ImporteAnticipo += Ant.Importe - Next - End If - - If ImporteAnticipo > 0 Then - TrAnticiposOC.Visible = True - LbAnticiposOC2.Text = ImporteAnticipo.ToString.FormatoNumero - End If - - 'TOTAL COMPRA - LbTotalOC2.Text = (TxtTotal.Text.ToDouble - ImporteAnticipo).FormatoNumero - 'LbTotalOC2.Text = TxtTotal.Text - - - RegistraScript("CalculaTotalesOC();") - - End Sub - Protected Sub BtnVincularOC_Click(sender As Object, e As EventArgs) - 'If DdlOCVinculaInv.SelectedValue.ToEntero = 237 And Not CveFlete > 0 Then Alert("Necesita vincular un flete si selecciona Factura de Flete", TipoMensaje.MsgAdvertencia) : Exit Sub - 'If DdlOCVinculaInv.SelectedValue.ToEntero = 240 And Not CveImportacion > 0 Then Alert("Necesita vincular una Importación si selecciona Factura de Importación", TipoMensaje.MsgAdvertencia) : Exit Sub - + + + Private Sub BtnValesCombustibleVer_Click(sender As Object, e As EventArgs) Handles BtnValesCombustibleVer.Click + + Dim AF As New ClsAF + + If AF.GetValesCombustible(-1, -1, -1, CveProveedor, -1, -1, -1, -1, -1, -1, -1, UsuarioActual.CveEmpresa, -1, -1) Then + GvVales.DataSource = AF.DtResultados + End If + + AF.Dispose() + GvVales.DataBind() + DivValesCombustible.Visible = True + RegistraScript(String.Format("$('#{0}').modal('show')", DivValesCombustible.ClientID)) + UPPValesCombustible.Update() + End Sub + +#End Region + +#Region " VALES COMBUSTIBLES " + Protected Sub BtnValesVincular_Click(sender As Object, e As EventArgs) + IdVale = New List(Of Integer) + + For Each row As GridViewRow In GvVales.Rows + If row.FCCheckBox("ChkVale").Checked Then + IdVale.Add(row.DataKey("CveVale").ToEntero) + End If + Next + + If IdVale.Count <= 0 Then + Alert("Debe elegir por lo menos un vale de combustible. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Else + Alert("Los vales selecciondos están listos para vincular") + RegistraScript(String.Format("$('#{0}').modal('hide')", DivValesCombustible.ClientID)) + 'For Each cve In IdVale + ' Alert(cve.ToString) + 'Next + End If + End Sub +#End Region + +#Region " VINCULAR OC " + Private Sub InicializaOC() + 'BORRAR OC + 'TabOC.Visible = False + + TabOC.Visible = False + + EmpresasOC = New List(Of Integer) + + ''TODAS LAS EMPRESAS LO TIENEN Y LA 66 SOLO LOS USUARIOS DE ABAJO - EMPRESA QUE ESTE EN LA LISTA NO TENDRA NUEVO ESQUEMA + 'If UsuarioActual.CveEmpresa = 66 AndAlso Not UsuarioActual.CveUsuario.Contiene(1434, 1436, 1337, 1440) Then + ' EmpresasOC.Add(UsuarioActual.CveEmpresa) + 'End If + + 'If Not EmpresasOC.Contains(UsuarioActual.CveEmpresa) Then + TabOC.Visible = True + 'Else + 'TabOC.Visible = True + 'End If + + If Not UsuarioActual.TienePermisoProceso(242) Then + DdlOCVinculaInv.Items.RemoveAt(2) + DdlOCVinculaInv.Items.RemoveAt(3) + End If + + End Sub + Protected Sub BtnBuscarOC_Click(sender As Object, e As EventArgs) Handles BtnBuscarOC.Click + PopUpOC = False + CargaOC() + End Sub + Protected Sub CargaVOC(sender As Object, e As EventArgs) + PopUpOC = True + CargaOC() + End Sub + Private Sub CargaOC() + Dim EntregaDirecta = 0 + DivOCSolicitudAnticipo.Visible = False + DivOCSolicitudAnticipoModal.Visible = False + + If CveProveedor <= 0 Then + Alert("Debe de Seleccionar un proveedor") + Exit Sub + End If + + 'BANDERA DE SURTIDO + If UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 Then + GvOC1.Columns(1).Visible = True + End If + + Dim CvesOC = "" + + + If PopUpOC Then + CvesOC = HdnVCveOC.Value + End If + + HdnVCveOC.Value = "" + HdnCveEstatusOC.Value = "" + + Dim OC As New ClsOC + If PopUpOC Then + Dim ArrayCveOC As String() = CvesOC.Split(New Char() {","c}) + For i As Integer = 0 To ArrayCveOC.Count - 1 + If OC.GetOrdenesCompraRep("OC", -1, -1, -1, -1, MinFecha, MaxFecha, ArrayCveOC(i).ToEntero, CveProveedor, -1, -1, -1, UsuarioActual.CveEmpresa, -1) Then + If OC.DtResultados.FiltraParametros("TipoTermino = 3").Rows.Count = 1 Or DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + HdnVCveOC.Value += String.Format("{0}{1}", If(HdnVCveOC.Value <> "", ",", ""), OC.DtResultados.Rows(0)("CveOrdenCompra").ToString) + HdnCveEstatusOC.Value += String.Format("{0}{1}", If(HdnCveEstatusOC.Value <> "", ",", ""), OC.DtResultados.Rows(0)("CveEstatusSiguiente").ToString) + EntregaDirecta += If(OC.DtResultados.Rows(0)("EntregaDirecta").ToString = "True", 1, 0) + End If + End If + Next + Else + Dim TextoErrorOC = "" + Dim ArrayCveOC As String() = TxtOC.Text.Split(New Char() {","c}) + For i As Integer = 0 To ArrayCveOC.Count - 1 + If OC.GetOrdenesCompraRep("OC", -1, -1, -1, -1, MinFecha, MaxFecha, -1, CveProveedor, ArrayCveOC(i).ToEntero, -1, -1, UsuarioActual.CveEmpresa, -1) Then + If OC.DtResultados.Rows.Count > 1 Then + TextoErrorOC += $"
El folio {ArrayCveOC(i).ToEntero} no se pudo identificar." + End If + If OC.DtResultados.FiltraParametros("TipoTermino = 3").Rows.Count = 1 Or DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then + HdnVCveOC.Value += String.Format("{0}{1}", If(HdnVCveOC.Value <> "", ",", ""), OC.DtResultados.Rows(0)("CveOrdenCompra").ToString) + HdnCveEstatusOC.Value += String.Format("{0}{1}", If(HdnCveEstatusOC.Value <> "", ",", ""), OC.DtResultados.Rows(0)("CveEstatusSiguiente").ToString) + EntregaDirecta += If(OC.DtResultados.Rows(0)("EntregaDirecta").ToString = "True", 1, 0) + End If + End If + Next + If TextoErrorOC <> "" Then + Alert($"Las siguientes Ordenes de Compra no se pudieron vincular automaticamente:
{TextoErrorOC}

Sera necesario vincular de manera manual mediante busqueda (lupia).", TipoMensaje.MsgAdvertencia) + TxtOC.Text = "" + Exit Sub + End If + End If + OC.Dispose() + PopUpOC = False + + + If HdnVCveOC.Value <> "" Then + If HdnCveEstatusOC.Value = "" Then + Alert("No se tiene especificado el siguiente estatus de la Orden(es) de Compra. Por favor verifique los estatus y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + VinculaOC() + + If EntregaDirecta > 0 Then + Alert("Se identificó una Orden de Compra con entrega directa, por lo cual no se podra recibir en almacén desde este modulo, para esto es necesario recibir la mercancía desde la Orden de Compra.", TipoMensaje.MsgAdvertencia) + TabAlmacen.Visible = False + DivOCEntregaDirecta.Visible = True + End If + + BtnGuardar.Enabled = False + TxtOC.Enabled = False + ImgBtnBuscarOC.Enabled = False + UpFacturar.Update() + + Else + Alert("No se encontro ninguna Orden de Compra con el folio especificado.", TipoMensaje.MsgAdvertencia) + End If + + UPPOC.Update() + UpPS.Update() + End Sub + Protected Sub BtnVOC_Click(sender As Object, e As EventArgs) + VinculaOC() + End Sub + Private Sub VinculaOC() + If TxtOC.Text <> "" Then + + 'VARIABLES + Dim TextoObservaciones = "" + LtOCPromocion.Text = "" + IvaAcumulado = 0 + DTOCTemp = New DataTable + + 'SI NO ES UNA COMPRA REGISTRADA = ENABLE FALSE TAB GENERALES, ACTIVE TAB OC + If Not CveCompra > 0 Then + TabGenerales.Enabled = False + Tab.ActiveTabIndex = 2 + UpTabs.Update() + End If + + 'CARGAMOS LOS DATOS DE LAS OC + Dim ObjOC As New ClsOC + Dim ArrayCveOC As String() = HdnVCveOC.Value.Split(New Char() {","c}) + Dim FoliosOCAnticipo = "", FoliosOCAnticipoIE = "" + Dim StrPromos As New StringBuilder + + For Each CveOCItem As String In ArrayCveOC.Distinct + If ObjOC.GetOrdenesDetalle(CveOCItem.ToEntero) AndAlso ObjOC.DtResultados.Rows.Count > 0 Then + If IsNothing(DTOCTemp) Then + DTOCTemp = ObjOC.DtResultados.Copy + Else + DTOCTemp.Merge(ObjOC.DtResultados) + End If + + IvaAcumulado += ObjOC.DtResultados.Rows(0)("IVA").ToString.ToDouble + TextoObservaciones += ObjOC.DtResultados.Rows(0)("Descripcion").ToString + + If ObjOC.DtResultados.Rows.Count > 0 Then + + ''MONEDA DIFERENTE + If ObjOC.DtResultados.Rows(0)("CveMoneda").ToString.ToEntero <> DdlMoneda.SelectedValue.ToEntero Then + DivTipoCambioOC.Visible = True + TxtTipoCambioOC.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString + BtnVincularOCCompleta.Visible = False + BtnVincularOC.Visible = False + End If + + ''SOLICITUD DE ANTICIPO + If ObjOC.DtResultados.Rows(0)("CveIEAnticipo").ToString.ToEntero > 0 Then + FoliosOCAnticipo += $"{ObjOC.DtResultados.Rows(0)("FolioOC").ToString}," + FoliosOCAnticipoIE += $"{ObjOC.DtResultados.Rows(0)("FolioIEAnticipo").ToString}," + DivOCSolicitudAnticipo.Visible = True + DivOCSolicitudAnticipoModal.Visible = True + End If + + 'PROMOCIONES + Dim Promocion = ObjOC.DtResultados.Rows(0)("Promocion").ToString + If Not String.IsNullOrEmpty(Promocion) Then + Dim FolioOC = ObjOC.DtResultados.Rows(0)("FolioOC").ToString + StrPromos.Append($"OC #{FolioOC} {Promocion}
") + StrPromos.AppendLine() + End If + End If + + Else + Alert("Ocurrio un Error al cargar la(s) Orden(es) de Compra", TipoMensaje.MsgError) + If DTOCTemp IsNot Nothing Then DTOCTemp.Rows.Clear() + TextoObservaciones = "" + Exit Sub + End If + Next + ObjOC.Dispose() + + 'MOVIMIENTOS DE ALMACÉN + Dim ObjInventarios As New ClsInventarios + Dim FoliosOCAlmacen = "" + For Each CveOCItem As String In ArrayCveOC.Distinct + If ObjInventarios.GetMovimientosOC(CveOCItem.ToEntero, UsuarioActual.CveEmpresa) Then + If ObjInventarios.DtResultados.Rows.Count > 0 Then + FoliosOCAlmacen = $"{ObjInventarios.DtResultados.FiltroPrimeroValor("FolioOC")}," + End If + Else + Alert("Ocurrió un error al cargar los movimientos de almacén de la orden de compra", TipoMensaje.MsgError) + ObjInventarios.Dispose() + Exit Sub + End If + Next + ObjInventarios.Dispose() + If FoliosOCAlmacen.Length > 0 Then + DivOCAlmacen.Visible = True + LtOCAlmacen.Text = FoliosOCAlmacen.Substring(0, FoliosOCAlmacen.Length - 1) + End If + + 'SI PUEDE RECIBIR POR OC Y COMPRA + If UsuarioActual.CveEmpresa.Contiene(119) Then + If UsuarioActual.Empresa.UsaInventarios And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 And Not UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 Then + DivOCVinculaInv.Visible = True + End If + End If + + + 'TIPO CAMBIO + If CveCompra > 0 Then + DivTipoCambioOC.Visible = False + End If + + DTOCTemp.Columns.Add("PUTC", GetType(Double)) + DTOCTemp.Columns.Add("TotalTC", GetType(Double)) + DTOCTemp.Columns.Add("DescuentoTC", GetType(Double)) + DTOCTemp.Columns.Add("IVATC", GetType(Double)) + DTOCTemp.Columns.Add("IEPSPSTC", GetType(Double)) + DTOCTemp.Columns.Add("IEPSPSIVATC", GetType(Double)) + DTOCTemp.Columns.Add("RetIVATC", GetType(Double)) + DTOCTemp.Columns.Add("RetISRTC", GetType(Double)) + DTOCTemp.Columns.Add("FolioAlmacen", GetType(String)) + For Each Dr As DataRow In DTOCTemp.Rows + Dr("PUTC") = Dr("Importe") + Dr("DescuentoTC") = Dr("Descuento") + Dr("IVATC") = Dr("IVA") + Dr("IEPSPSTC") = Dr("IEPSPS") + Dr("IEPSPSIVATC") = Dr("IEPSPSIVA") + Dr("RetIVATC") = Dr("RetIVA") + Dr("RetISRTC") = Dr("RetISR") + Dr("TotalTC") = Dr("ImporteAjustadoDescuento") + + '[IPP] - JAMEntregaAdelantado | AJUSTE DE CANITDAD POR RECIBIR EN BASE A SALDOS DE INV-COMPRAS + 'If UsuarioActual.CveUsuario = 100 Then + 'If Dr("CveTipoPS").ToString.ToEntero = 2 And UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 Then + ' Dr("CantidadDisponible") = If(Dr("CantidadDisponible").ToString.ToDouble > Dr("CantidadPendienteVincular").ToString.ToDouble, Dr("CantidadPendienteVincular"), Dr("CantidadDisponible")) + 'End If + 'End If + Next + + 'DESCRIPCION DE OC CUANDO NO ES COMPRA REGISTRADA + If Not CveCompra > 0 Then TxtDescripcion.Text = TextoObservaciones + + 'SOLICITUD DE ANTICIPO + If DivOCSolicitudAnticipo.Visible And FoliosOCAnticipo.Length > 0 Then + LtSolicitudAnticipoFoliosOC.Text = $"La(s) siguiente(s) OC: {FoliosOCAnticipo.Substring(0, FoliosOCAnticipo.Length - 1)}. tienen vinculado un anticipo" + LtSolicitudAnticipoFoliosIE.Text = $" {FoliosOCAnticipoIE.Substring(0, FoliosOCAnticipoIE.Length - 1)}" + End If + + 'PROMOCIONES + LtOCPromocion.Text = StrPromos.ToString + If LtOCPromocion.Text.Length > 0 And UsuarioActual.CveEmpresa = 119 Then + DivOCPromocion.Visible = True + End If + + 'CARGA DATOS DE OC + CargaVinculacionOC(True) + + End If + End Sub + Protected Sub DdlOCVinculaInv_SelectedIndexChanged(sender As Object, e As EventArgs) + CargaVinculacionOC() + End Sub + Private Sub CargaVinculacionOC(Optional CargaInicial As Boolean = False) + 'FILTRAMOS SOLO PENDIENTES POR SURTIR + DTOCGV = DTOCTemp.FiltraParametros("CantidadDisponible > 0", "CveOrdenCompra").Copy + + 'SI PUEDE RECIBIR POR OC Y COMPRA + If UsuarioActual.CveEmpresa.Contiene(119) Then + If UsuarioActual.Empresa.UsaInventarios And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 And Not UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 Then + Select Case DdlOCVinculaInv.SelectedValue.ToEntero + Case 176 + DTOCGV = DTOCGV.FiltraParametros("((EstatusInventario IN (3,5) AND CveTipoPS = 2) OR CveTipoPS = 1) AND CantidadPorAdelantado > 0") + Case 205 + DTOCGV = DTOCGV.FiltraParametros("(EstatusInventario IN (1,2) AND CveTipoPS = 2) OR CveTipoPS = 1") + End Select + End If + End If + + If DTOCGV.Rows.Count = 0 Then + Alert("La orden de compra no tiene nada pendiente por vincular. En caso de ser Entrega Directa por favor verifique el estatus de facturación.", TipoMensaje.MsgAdvertencia) + End If + + CargaGvsOC() + + CargaTotalesOC() + + 'Diferencia permitida $ entre OC y Compra + Dim DiferenciaPermitida = 1 + + 'VINCULACION TOTAL + If CargaInicial And DivTipoCambioOC.Visible = False Then + If LbTotalOC1.Text = LbTotalOC2.Text AndAlso (UsuarioActual.CveEmpresa.Contiene(1, 4, 7, 11, 12, 48, 13, 66, 72, 80, 145)) AndAlso CveCompra <= 0 Then + BtnVincularOCCompleta.Visible = Not DivTipoCambioOC.Visible + Else + BtnVincularOCCompleta.Visible = False + End If + Else + If LbTotalOC1.Text = LbTotalOC2.Text AndAlso (UsuarioActual.CveEmpresa.Contiene(1, 4, 7, 11, 12, 48, 13, 66, 72, 80, 145)) AndAlso CveCompra <= 0 Then + BtnVincularOCCompleta.Visible = Not DivTipoCambioOC.Visible + Else + BtnVincularOCCompleta.Visible = False + End If + End If + + UpOC.Update() + + ' If DdlOCVinculaInv.SelectedValue.ToEntero.Contiene(237, 240) Then CargaModalFletesImportaciones() + + End Sub + + Private Sub CargaTipoCentroCostoOC() + If UsuarioActual.Empresa.Tipo_CentroCosto = 1 Then + GvOC1.Columns(5).HeaderText = "Sucursal" + ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 2 Then + GvOC1.Columns(5).HeaderText = "Proyecto" + ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 4 Then + GvOC1.Columns(5).HeaderText = "Sucursal
Proyecto" + ElseIf UsuarioActual.Empresa.Tipo_CentroCosto = 5 Then + GvOC1.Columns(5).HeaderText = "Proyecto
Sucursal" + End If + End Sub + Private Sub CargaGvsOC() + + 'SI ES MAS DE UNA OC ORDENA POR PRODUCTO + Dim ArrayCveOC As String() = HdnVCveOC.Value.Split(New Char() {","c}) + DTOCGV = If(ArrayCveOC.Length > 1, DTOCGV.FiltraParametros("", "Producto"), DTOCGV) + + CargaTipoCentroCostoOC() + GvOC1.DataSource = DTOCGV + GvOC1.DataBind() + + Dim DTCVEOGV As DataTable = DTOCGV.FiltraParametros("", "", {"CveOrdenCompra"}) + If DTCVEOGV.Rows.Count > 1 Then + GvOC1.Columns(0).Visible = True + Else + GvOC1.Columns(0).Visible = False + End If + + Dim Cont As Integer = 0 + For Each gvr As GridViewRow In GvOC1.Rows + RegistraScript($"CalculaTotalOCEdit('{gvr.DataKey("PS").Replace("'", "")}', {gvr.DataKey("CantidadDisponible").ToString.ToDouble}, {gvr.FCTextBox("TxtCantidad").ClientID}, {gvr.FCTextBox("TxtPU").ClientID}, {gvr.FCTextBox("TxtTotalOC1").ClientID}, {gvr.DataKey("IEPSPS").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1IEPSImporte").ClientID}, {gvr.DataKey("IVA").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1IVA").ClientID},{gvr.DataKey("RetIVA").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1RetIVA").ClientID},{gvr.DataKey("RetISR").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1RetISR").ClientID},{gvr.DataKey("IEPSPS").ToString.ToDouble},{gvr.FCHiddenField("HdnOC1IEPSIVA").ClientID},{gvr.DataKey("Descuento")},{gvr.FCHiddenField("HdnOC1Descuento").ClientID},{gvr.DataKey("IVAPorcentaje").ToString.ToDouble},{gvr.DataKey("RetIVAPorcentaje").ToString.ToDouble},{gvr.DataKey("RetISRPorcentaje").ToString.ToDouble},{gvr.DataKey("IEPSPSPorcentaje").ToString.ToDouble},{gvr.DataKey("IEPSPSIVAPorcentaje").ToString.ToDouble});", $"Gv{Cont}") + Cont += 1 + Next + + UpGvOC1.Update() + + TmpDT = TmpDT.FiltraParametros("", "PU") + + + GvOC2.DataSource = TmpDT + GvOC2.DataBind() + UpGvOC2.Update() + End Sub + Protected Sub GvOC1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvOC1.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + + Dim JSCambiaScript = $"CalculaTotalOCEdit('{e.Row.DBCampo("PS").Replace("'", "")}', {e.Row.DBCampo("CantidadDisponible").ToString.ToDouble}, {e.Row.FCTextBox("TxtCantidad").ClientID}, {e.Row.FCTextBox("TxtPU").ClientID}, {e.Row.FCTextBox("TxtTotalOC1").ClientID}, {e.Row.DBCampo("IEPSPS").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1IEPSImporte").ClientID}, {e.Row.DBCampo("IVA").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1IVA").ClientID},{e.Row.DBCampo("RetIVA").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1RetIVA").ClientID},{e.Row.DBCampo("RetISR").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1RetISR").ClientID},{e.Row.DBCampo("IEPSPS").ToString.ToDouble},{e.Row.FCHiddenField("HdnOC1IEPSIVA").ClientID},{e.Row.DBCampo("Descuento")},{e.Row.FCHiddenField("HdnOC1Descuento").ClientID},{e.Row.DBCampo("IVAPorcentaje").ToString.ToDouble},{e.Row.DBCampo("RetIVAPorcentaje").ToString.ToDouble},{e.Row.DBCampo("RetISRPorcentaje").ToString.ToDouble},{e.Row.DBCampo("IEPSPSPorcentaje").ToString.ToDouble},{e.Row.DBCampo("IEPSPSIVAPorcentaje").ToString.ToDouble});" + e.Row.FCTextBox("TxtCantidad").Attributes.Add("onkeyup", $"LimitaCantidadOC({e.Row.DBCampo("CantidadDisponible")}, this);{JSCambiaScript}") + e.Row.FCTextBox("TxtPU").Attributes.Add("onkeyup", JSCambiaScript) + + e.Row.FCTextBox("TxtCantidad").Attributes.Add("onblur", $"ValidaImporteCero('{e.Row.DBCampo("PS").Replace("'", "")}',{e.Row.FCTextBox("TxtCantidad").ClientID}, {e.Row.FCTextBox("TxtPU").ClientID});") + e.Row.FCTextBox("TxtPU").Attributes.Add("onblur", $"ValidaImporteCero('{e.Row.DBCampo("PS").Replace("'", "")}',{e.Row.FCTextBox("TxtCantidad").ClientID}, {e.Row.FCTextBox("TxtPU").ClientID});") + + + RegistraScript(JSCambiaScript) + + + If e.Row.DataKey("FolioREQ").ToString.Trim.Length > 0 Then + Dim LblOC As Label = e.Row.FCLabel("LblOC") + LblOC.Attributes.Add("data-toggle", "tooltip") + LblOC.Attributes.Add("data-placement", "top") + LblOC.Attributes.Add("title", "REQ: " & e.Row.DataKey("FolioREQ").ToString) + End If + + + + If e.Row.DBCampo("CveTipoPS").ToEntero = 2 And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 Then + Select Case e.Row.DBCampo("EstatusInventario").ToEntero + Case 1 + e.Row.FCLabel("LbEstatusInv").Text = "" + e.Row.FCLabel("LbEstatusInv").ForeColor = Drawing.Color.Red + Case 2 + e.Row.FCLabel("LbEstatusInv").Text = "" + e.Row.FCLabel("LbEstatusInv").ForeColor = Drawing.Color.DarkOrange + Case 3 + e.Row.FCLabel("LbEstatusInv").Text = "" + e.Row.FCLabel("LbEstatusInv").ForeColor = Drawing.Color.Green + Case Else + e.Row.FCLabel("LbEstatusInv").Text = "ERR" + End Select + ElseIf e.Row.DBCampo("CveTipoPS").ToEntero = 1 And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 Then + e.Row.FCLabel("LbEstatusInv").Text = "NA" + End If + + If Version = "3.3" Then + CargaPSSAT(e.Row.FCDropDownLost("DdlSATPS")) + If e.Row.DBCampo("CveSATPS").ToEntero > 0 Then + e.Row.FCDropDownLost("DdlSATPS").SelectedValue = e.Row.DBCampo("CveSATPS") + e.Row.FCDropDownLost("DdlSATPS").SelectedText = $"{e.Row.DBCampo("SATClaveProductoServicio")}" + End If + End If + + End If + End Sub + + Private Sub CargaPSSAT(Objeto As ADServerControl.Dropdownlost) + Objeto.setEsWebService(True) + Objeto.ddlWS.Attributes.Add("data-metodo", "getpssat") + End Sub + + Private Sub CargaTotalesOC() + + Dim TotalOC = 0.0D + For Each gvr As GridViewRow In GvOC1.Rows + TotalOC += gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal + Next + + 'SUBTOTAL OC + LbSubTotalOC1Mod.Text = (TotalOC + DTOCGV.SUM("Descuento")).FormatoNumero + LbSubTotalOC1.Text = (TotalOC + DTOCGV.SUM("Descuento")).FormatoNumero + + 'SUBTOTAL2 OC + LbSubTotal2OC1Mod.Text = TotalOC.FormatoNumero + LbSubTotal2OC1.Text = TotalOC.FormatoNumero + + 'IVA OC + LbIVAOC1Mod.Text = (DTOCGV.SUM("IVA").ToString.ToDouble + DTOCGV.SUM("IEPSPSIVA").ToString.ToDouble).FormatoNumero + LbIVAOC1.Text = (DTOCGV.SUM("IVA").ToString.ToDouble + DTOCGV.SUM("IEPSPSIVA").ToString.ToDouble).FormatoNumero + + 'DESCUENTO OC + LbDescuentoOC1Mod.Text = DTOCGV.SUM("Descuento").FormatoNumero + LbDescuentoOC1.Text = DTOCGV.SUM("Descuento").FormatoNumero + If LbDescuentoOC1.Text.ToDecimal > 0 Then + TrDescuentosOC1.Visible = True + End If + + 'IEPS OC + LbIEPSOCMod1.Text = DTOCGV.SUM("IEPSPS").FormatoNumero + LbIEPSOC1.Text = DTOCGV.SUM("IEPSPS").FormatoNumero + If LbIEPSOC1.Text.ToDecimal > 0 Then + TrIEPSOC1.Visible = True + End If + + 'RET IVA OC + LblRetIVAOC1Mod.Text = DTOCGV.SUM("RetIVA").ToString.FormatoNumero + LblRetIVAOC1.Text = DTOCGV.SUM("RetIVA").ToString.FormatoNumero + If LblRetIVAOC1.Text.ToDecimal > 0 Then + TrRetIVAOC1.Visible = True + End If + + 'RET ISR OC + LblRetISROC1Mod.Text = DTOCGV.SUM("RetISR").ToString.FormatoNumero + LblRetISROC1.Text = DTOCGV.SUM("RetISR").ToString.FormatoNumero + If LblRetISROC1.Text.ToDecimal > 0 Then + TrRetISROC1.Visible = True + End If + + 'TOTAL OC + TotalOC = TotalOC + LbIVAOC1.Text.ToDecimal + LbIEPSOC1.Text.ToDecimal - LblRetIVAOC1.Text.ToDecimal - LblRetISROC1.Text.ToDecimal + LbTotalOC1.Text = TotalOC.FormatoNumero + LbTotalOC1Mod.Text = TotalOC.FormatoNumero + + 'SUBTOTAL COMPRA + LbSubTotalOC2.Text = TxtSubTotal.Text + + 'SUBTOTAL2 COMPRA + LblSubTotal2OC2.Text = TxtSubTotal2.Text + + 'IVA COMPRA + LbIVAOC2.Text = TxtIVA.Text + + 'IEPS COMPRA + LbIEPSOC2.Text = TxtIEPS.Text + If LbIEPSOC2.Text.ToDecimal > 0 Then + TrIEPSOC2.Visible = True + End If + + 'DESCUENTO COMPRA + LblDescuentoOC2.Text = TxtDescuento.Text + If LblDescuentoOC2.Text.ToDecimal > 0 Then + TrDescuentosOC2.Visible = True + End If + + 'RET IVA COMPRA + LblRetIVAOC2.Text = TxtRetIVA.Text + If LblRetIVAOC2.Text.ToDecimal > 0 Then + TrRetIVAOC2.Visible = True + End If + + 'RET ISR COMPRA + LblRetISROC2.Text = TxtRetISR.Text + If LblRetISROC2.Text.ToDecimal > 0 Then + TrRetISROC2.Visible = True + End If + + 'ANTICIPOS COMPRA + Dim ImporteAnticipo As Decimal = 0 + If ArrAnticipos.Count > 0 Then + For Each Ant As Compras_Compras.Anticipos In ArrAnticipos + ImporteAnticipo += Ant.Importe + Next + End If + + If ImporteAnticipo > 0 Then + TrAnticiposOC.Visible = True + LbAnticiposOC2.Text = ImporteAnticipo.ToString.FormatoNumero + End If + + 'TOTAL COMPRA + LbTotalOC2.Text = (TxtTotal.Text.ToDouble - ImporteAnticipo).FormatoNumero + 'LbTotalOC2.Text = TxtTotal.Text + + + RegistraScript("CalculaTotalesOC();") + + End Sub + Protected Sub BtnVincularOC_Click(sender As Object, e As EventArgs) + 'If DdlOCVinculaInv.SelectedValue.ToEntero = 237 And Not CveFlete > 0 Then Alert("Necesita vincular un flete si selecciona Factura de Flete", TipoMensaje.MsgAdvertencia) : Exit Sub + 'If DdlOCVinculaInv.SelectedValue.ToEntero = 240 And Not CveImportacion > 0 Then Alert("Necesita vincular una Importación si selecciona Factura de Importación", TipoMensaje.MsgAdvertencia) : Exit Sub + Dim SubTotalGV = 0.0D - Dim Amortizacion As Decimal = TmpDT.SUMD("Total") - If ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 Then - Amortizacion = TmpDT.SUMD("ImporteSinImpuestos") - End If - Dim SubTotalCompra As Decimal = Amortizacion - Dim DiferenciaPermitida = 1 - Dim Cont = 0 - For Each gvr As GridViewRow In GvOC1.Rows - SubTotalGV += gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal - If Cont = 0 Then DdlProveedorSucursal.SelectedValueExist(gvr.DataKey("CveProveedorSucursal").ToEntero()) - Cont = 1 - Next - - If Math.Abs(SubTotalGV - SubTotalCompra) < DiferenciaPermitida Then - LbSubTotalDif.Visible = False - Vinculacion() - ElseIf Math.Abs(SubTotalGV - (SubTotalCompra - LbAnticiposOC2.Text.ToDecimal)) < DiferenciaPermitida Then - LbSubTotalDif.Visible = False - Vinculacion() - ElseIf Math.Abs(LbTotalOC1.Text.ToDecimal - (LbTotalOC2.Text.ToDecimal)) < DiferenciaPermitida Then - LbSubTotalDif.Visible = False - Vinculacion() - ElseIf Math.Abs(LbSubTotalOC2.Text.ToDecimal - (LbSubTotalOC1.Text.ToDecimal - LbAnticiposOC2.Text.ToDecimal)) < DiferenciaPermitida Then - LbSubTotalDif.Visible = False - Vinculacion() - Else - LbSubTotalDif.Visible = True - LbSubTotalDif.Text = (SubTotalCompra - SubTotalGV).FormatoNumero - Alert("Los SubTotales de la vinculación no coinciden. Rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia,,) - RegistraScript("CalculaTotalesOC();") - End If - - UpEstatus.Update() - End Sub - Protected Sub BtnVincularOCCompleta_Click(sender As Object, e As EventArgs) - Vinculacion(True) - End Sub - Private Sub Vinculacion(Optional VinculacionCompleta As Boolean = False) - - - 'SI PUEDE RECIBIR POR OC Y COMPRA - If UsuarioActual.CveEmpresa.Contiene(119) Then - If UsuarioActual.Empresa.UsaInventarios And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 And Not UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 Then - If DdlOCVinculaInv.SelectedValue.ToEntero <= 0 Then - Alert("El campo Tipo de recepción almacén es necesario. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - End If - - If Math.Abs(HdnIEPSModificadoOC.Value.ToDecimal - LbIEPSOC2.Text.ToDecimal) > 0.05 AndAlso UsuarioActual.CveEmpresa.Contiene(119) Then - Alert($"Hay una diferencia de IEPS entre la factura y la OC. Dif: {HdnIEPSModificadoOC.Value.ToDecimal - LbIEPSOC2.Text.ToDecimal}", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - 'PSCodigo DE XML IP - Dim DtTemporalXML = TmpDT.Copy - Dim IndexTmpOriginal = 0 - - 'Borramos el TmpDT - CreaDTCompras() - - 'Iteramos el GridView de la OC - Dim dr As DataRow - Dim Index = 0 - Dim MensajeCostoCero As New StringBuilder - Dim TotalRows As Integer = 0 - For Each gvr As GridViewRow In GvOC1.Rows - If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Or VinculacionCompleta Then - TotalRows += 1 - End If + Dim Amortizacion As Decimal = TmpDT.SUMD("Total") + If ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 Then + Amortizacion = TmpDT.SUMD("ImporteSinImpuestos") + End If + Dim SubTotalCompra As Decimal = Amortizacion + Dim DiferenciaPermitida = 1 + Dim Cont = 0 + For Each gvr As GridViewRow In GvOC1.Rows + SubTotalGV += gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal + If Cont = 0 Then DdlProveedorSucursal.SelectedValueExist(gvr.DataKey("CveProveedorSucursal").ToEntero()) + Cont = 1 + Next + + If Math.Abs(SubTotalGV - SubTotalCompra) < DiferenciaPermitida Then + LbSubTotalDif.Visible = False + Vinculacion() + ElseIf Math.Abs(SubTotalGV - (SubTotalCompra - LbAnticiposOC2.Text.ToDecimal)) < DiferenciaPermitida Then + LbSubTotalDif.Visible = False + Vinculacion() + ElseIf Math.Abs(LbTotalOC1.Text.ToDecimal - (LbTotalOC2.Text.ToDecimal)) < DiferenciaPermitida Then + LbSubTotalDif.Visible = False + Vinculacion() + ElseIf Math.Abs(LbSubTotalOC2.Text.ToDecimal - (LbSubTotalOC1.Text.ToDecimal - LbAnticiposOC2.Text.ToDecimal)) < DiferenciaPermitida Then + LbSubTotalDif.Visible = False + Vinculacion() + Else + LbSubTotalDif.Visible = True + LbSubTotalDif.Text = (SubTotalCompra - SubTotalGV).FormatoNumero + Alert("Los SubTotales de la vinculación no coinciden. Rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia,,) + RegistraScript("CalculaTotalesOC();") + End If + + UpEstatus.Update() + End Sub + Protected Sub BtnVincularOCCompleta_Click(sender As Object, e As EventArgs) + Vinculacion(True) + End Sub + Private Sub Vinculacion(Optional VinculacionCompleta As Boolean = False) + + + 'SI PUEDE RECIBIR POR OC Y COMPRA + If UsuarioActual.CveEmpresa.Contiene(119) Then + If UsuarioActual.Empresa.UsaInventarios And UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 And Not UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 Then + If DdlOCVinculaInv.SelectedValue.ToEntero <= 0 Then + Alert("El campo Tipo de recepción almacén es necesario. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + End If + + If Math.Abs(HdnIEPSModificadoOC.Value.ToDecimal - LbIEPSOC2.Text.ToDecimal) > 0.05 AndAlso UsuarioActual.CveEmpresa.Contiene(119) Then + Alert($"Hay una diferencia de IEPS entre la factura y la OC. Dif: {HdnIEPSModificadoOC.Value.ToDecimal - LbIEPSOC2.Text.ToDecimal}", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'PSCodigo DE XML IP + Dim DtTemporalXML = TmpDT.Copy + Dim IndexTmpOriginal = 0 + + 'Borramos el TmpDT + CreaDTCompras() + + 'Iteramos el GridView de la OC + Dim dr As DataRow + Dim Index = 0 + Dim MensajeCostoCero As New StringBuilder + Dim TotalRows As Integer = 0 + For Each gvr As GridViewRow In GvOC1.Rows + If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Or VinculacionCompleta Then + TotalRows += 1 + End If Next Dim TieneAmortizacion As Boolean = False @@ -14995,921 +15133,921 @@ Partial Class Compras_Compras TieneAmortizacion = True End If - For Each gvr As GridViewRow In GvOC1.Rows - If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Or VinculacionCompleta Then - dr = DTOCGV.Rows(gvr.RowIndex) - - Dim Cantidad As Decimal = gvr.FCTextBox("TxtCantidad").Text.ToDecimal 'dr("Cantidad").ToString.ToDouble - Dim CantidadF As Decimal = gvr.DataKey("CantidadF").ToString.ToDecimal 'dr("Cantidad").ToString.ToDouble - Dim CveUM As Integer = dr("CveUM").ToString.ToEntero - Dim UM As String = dr("UM").ToString - Dim CveClasificacion As Integer = dr("CveClasificacion").ToString.ToEntero - Dim Clasificacion As String = dr("Clasificacion").ToString - Dim CvePS As Integer = dr("CvePS").ToString.ToEntero - Dim PS As String = dr("PS").ToString - Dim CveTipoPS As Integer = dr("CveTipoPS").ToString.ToEntero - Dim CveSubProyectoContrato As String = dr("CveSubProyecto").ToString - Dim CveProyecto As String = dr("CveProyecto").ToString - Dim SubProyecto As String = dr("SubProyecto").ToString - Dim Proyecto As String = dr("Proyecto").ToString - Dim Obs As String = dr("Obs").ToString - Dim PU As Decimal = gvr.FCTextBox("TxtPU").Text.ToDecimal - Dim Total As Decimal = If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, Math.Round((gvr.FCTextBox("TxtCantidad").Text.ToDecimal * gvr.FCTextBox("TxtPU").Text.ToDecimal) - (TxtDescuento.Text.ToDouble / TotalRows).ToDecimal, 2), gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal) - 'Dim Total As Decimal = gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal - 'Dim IVA As Decimal = gvr.FCHiddenField("HdnOC1IVA").Value.ToDecimal - 'Dim RetIVA As Double = gvr.FCHiddenField("HdnOC1RetIVA").Value.ToDecimal - 'Dim RetISR As Double = gvr.FCHiddenField("HdnOC1RetISR").Value.ToDecimal - 'Dim IEPSPS As Double = gvr.FCHiddenField("HdnOC1IEPSImporte").Value.ToDecimal - 'Dim IEPSPSIVA As Double = gvr.FCHiddenField("HdnOC1IEPSIVA").Value.ToDecimal - Dim IVA As Decimal = dr("IVAPorcentaje").ToString.ToDecimal - Dim RetIVA As Double = dr("RetIVAPorcentaje").ToString.ToDecimal - Dim RetISR As Double = dr("RetISRPorcentaje").ToString.ToDecimal - Dim IEPSPS As Double = dr("IEPSPSPorcentaje").ToString.ToDecimal - Dim IEPSPSIVA As Double = dr("IEPSPSIVAPorcentaje").ToString.ToDecimal - Dim Descuento As Double = If(TieneAmortizacion, TxtDescuento.Text.ToDouble / TotalRows, gvr.FCHiddenField("HdnOC1Descuento").Value.ToDecimal) - 'Dim Descuento As Double = gvr.FCHiddenField("HdnOC1Descuento").Value.ToDecimal - Dim CveOrdenCompraDetalle As Integer = dr("CveOrdenCompraDetalle").ToString.ToEntero - Dim EntregaDirecta As Integer = dr("EntregaDirecta").ToString.ToEntero - Dim CveSATPS As Integer = gvr.FCDropDownLost("DdlSATPS").SelectedValue.ToEntero - Dim CveTipoGasto As Integer = -1 - Dim TipoGasto As String = "" - - '[IPP] PROVISIONAL PARA TIPO GASTO - If GlobalDTTiposGastos(UsuarioActual.CveEmpresa) IsNot Nothing AndAlso GlobalDTTiposGastos(UsuarioActual.CveEmpresa).Rows.Count = 1 Then - Dim DrTipoGasto = GlobalDTTiposGastos(UsuarioActual.CveEmpresa).FiltroPrimero("") - If DrTipoGasto IsNot Nothing Then - CveTipoGasto = DrTipoGasto("CveTipoGasto").ToString.ToEntero - TipoGasto = DrTipoGasto("TipoGasto").ToString - End If - End If - - AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, RetIVA, RetISR, IEPSPS, IEPSPSIVA, Descuento, CveOrdenCompraDetalle, False, CantidadF:=CantidadF, EntregaDirecta:=EntregaDirecta, CveSATPS:=CveSATPS, CveTipoGasto:=CveTipoGasto, TipoGasto:=TipoGasto) - - 'CARGA PE - Index = TmpDT.Rows.Count - 1 - TmpDT.Rows(Index)("CvePresupuestoEgreso") = dr("CvePresupuestoEgreso").ToString.ToEntero - TmpDT.Rows(Index)("CveProgramaOperativo") = dr("CveProgramaOperativo").ToString.ToEntero - TmpDT.Rows(Index)("CveUnidadAdministrativa") = dr("CveUnidadAdministrativa").ToString.ToEntero - TmpDT.Rows(Index)("CveFuenteFinanciamiento") = dr("CveFuenteFinanciamiento").ToString.ToEntero - TmpDT.Rows(Index)("CveTipoGastoAC") = dr("CveTipoGasto").ToString.ToEntero - TmpDT.Rows(Index)("CveClasificacionOG") = dr("CveClasificacionOG").ToString.ToEntero - - 'TmpDT.Rows(Index)("PSCodigo") = DtTemporalXML.Rows(IndexTmpOriginal)("PSCodigo") - TmpDT.Rows(Index)("PSCodigo") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimeroValor("PSCodigo", "").ToString - - Dim CveAF As String = dr("CveActivoFijo").ToString - If CveAF <> "" AndAlso CveAF <> "-1" Then - TmpDT.Rows(Index)("CveActivoFijo") = CveAF.ToEntero - TmpDT.Rows(Index)("CodAF") = dr("CodigoAF").ToString - TmpDT.Rows(Index)("TipoAF") = 1 - End If - 'actualizo los movimientos registrados - DTOCGV.Rows(gvr.RowIndex)("CantidadDisponible") = Cantidad - DTOCGV.Rows(gvr.RowIndex)("Importe") = PU - DTOCGV.Rows(gvr.RowIndex)("Total") = Total - - End If - IndexTmpOriginal += 1 - Next - - AddPS2(False) - - 'AJUSTE DE REDONDEO O DIFERENCIA PERMITIDA DE IMPORTE + For Each gvr As GridViewRow In GvOC1.Rows + If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Or VinculacionCompleta Then + dr = DTOCGV.Rows(gvr.RowIndex) + + Dim Cantidad As Decimal = gvr.FCTextBox("TxtCantidad").Text.ToDecimal 'dr("Cantidad").ToString.ToDouble + Dim CantidadF As Decimal = gvr.DataKey("CantidadF").ToString.ToDecimal 'dr("Cantidad").ToString.ToDouble + Dim CveUM As Integer = dr("CveUM").ToString.ToEntero + Dim UM As String = dr("UM").ToString + Dim CveClasificacion As Integer = dr("CveClasificacion").ToString.ToEntero + Dim Clasificacion As String = dr("Clasificacion").ToString + Dim CvePS As Integer = dr("CvePS").ToString.ToEntero + Dim PS As String = dr("PS").ToString + Dim CveTipoPS As Integer = dr("CveTipoPS").ToString.ToEntero + Dim CveSubProyectoContrato As String = dr("CveSubProyecto").ToString + Dim CveProyecto As String = dr("CveProyecto").ToString + Dim SubProyecto As String = dr("SubProyecto").ToString + Dim Proyecto As String = dr("Proyecto").ToString + Dim Obs As String = dr("Obs").ToString + Dim PU As Decimal = gvr.FCTextBox("TxtPU").Text.ToDecimal + Dim Total As Decimal = If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, Math.Round((gvr.FCTextBox("TxtCantidad").Text.ToDecimal * gvr.FCTextBox("TxtPU").Text.ToDecimal) - (TxtDescuento.Text.ToDouble / TotalRows).ToDecimal, 2), gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal) + 'Dim Total As Decimal = gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal + 'Dim IVA As Decimal = gvr.FCHiddenField("HdnOC1IVA").Value.ToDecimal + 'Dim RetIVA As Double = gvr.FCHiddenField("HdnOC1RetIVA").Value.ToDecimal + 'Dim RetISR As Double = gvr.FCHiddenField("HdnOC1RetISR").Value.ToDecimal + 'Dim IEPSPS As Double = gvr.FCHiddenField("HdnOC1IEPSImporte").Value.ToDecimal + 'Dim IEPSPSIVA As Double = gvr.FCHiddenField("HdnOC1IEPSIVA").Value.ToDecimal + Dim IVA As Decimal = dr("IVAPorcentaje").ToString.ToDecimal + Dim RetIVA As Double = dr("RetIVAPorcentaje").ToString.ToDecimal + Dim RetISR As Double = dr("RetISRPorcentaje").ToString.ToDecimal + Dim IEPSPS As Double = dr("IEPSPSPorcentaje").ToString.ToDecimal + Dim IEPSPSIVA As Double = dr("IEPSPSIVAPorcentaje").ToString.ToDecimal + Dim Descuento As Double = If(TieneAmortizacion, TxtDescuento.Text.ToDouble / TotalRows, gvr.FCHiddenField("HdnOC1Descuento").Value.ToDecimal) + 'Dim Descuento As Double = gvr.FCHiddenField("HdnOC1Descuento").Value.ToDecimal + Dim CveOrdenCompraDetalle As Integer = dr("CveOrdenCompraDetalle").ToString.ToEntero + Dim EntregaDirecta As Integer = dr("EntregaDirecta").ToString.ToEntero + Dim CveSATPS As Integer = gvr.FCDropDownLost("DdlSATPS").SelectedValue.ToEntero + Dim CveTipoGasto As Integer = -1 + Dim TipoGasto As String = "" + + '[IPP] PROVISIONAL PARA TIPO GASTO + If GlobalDTTiposGastos(UsuarioActual.CveEmpresa) IsNot Nothing AndAlso GlobalDTTiposGastos(UsuarioActual.CveEmpresa).Rows.Count = 1 Then + Dim DrTipoGasto = GlobalDTTiposGastos(UsuarioActual.CveEmpresa).FiltroPrimero("") + If DrTipoGasto IsNot Nothing Then + CveTipoGasto = DrTipoGasto("CveTipoGasto").ToString.ToEntero + TipoGasto = DrTipoGasto("TipoGasto").ToString + End If + End If + + AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, RetIVA, RetISR, IEPSPS, IEPSPSIVA, Descuento, CveOrdenCompraDetalle, False, CantidadF:=CantidadF, EntregaDirecta:=EntregaDirecta, CveSATPS:=CveSATPS, CveTipoGasto:=CveTipoGasto, TipoGasto:=TipoGasto) + + 'CARGA PE + Index = TmpDT.Rows.Count - 1 + TmpDT.Rows(Index)("CvePresupuestoEgreso") = dr("CvePresupuestoEgreso").ToString.ToEntero + TmpDT.Rows(Index)("CveProgramaOperativo") = dr("CveProgramaOperativo").ToString.ToEntero + TmpDT.Rows(Index)("CveUnidadAdministrativa") = dr("CveUnidadAdministrativa").ToString.ToEntero + TmpDT.Rows(Index)("CveFuenteFinanciamiento") = dr("CveFuenteFinanciamiento").ToString.ToEntero + TmpDT.Rows(Index)("CveTipoGastoAC") = dr("CveTipoGasto").ToString.ToEntero + TmpDT.Rows(Index)("CveClasificacionOG") = dr("CveClasificacionOG").ToString.ToEntero + + 'TmpDT.Rows(Index)("PSCodigo") = DtTemporalXML.Rows(IndexTmpOriginal)("PSCodigo") + TmpDT.Rows(Index)("PSCodigo") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimeroValor("PSCodigo", "").ToString + + Dim CveAF As String = dr("CveActivoFijo").ToString + If CveAF <> "" AndAlso CveAF <> "-1" Then + TmpDT.Rows(Index)("CveActivoFijo") = CveAF.ToEntero + TmpDT.Rows(Index)("CodAF") = dr("CodigoAF").ToString + TmpDT.Rows(Index)("TipoAF") = 1 + End If + 'actualizo los movimientos registrados + DTOCGV.Rows(gvr.RowIndex)("CantidadDisponible") = Cantidad + DTOCGV.Rows(gvr.RowIndex)("Importe") = PU + DTOCGV.Rows(gvr.RowIndex)("Total") = Total + + End If + IndexTmpOriginal += 1 + Next + + AddPS2(False) + + 'AJUSTE DE REDONDEO O DIFERENCIA PERMITIDA DE IMPORTE AjustaImporteUltimoConcepto((If(TieneAmortizacion, TmpDT.SUMD("ImporteSinImpuestos"), TxtSubTotal2.Text.ToDouble) + TxtOtrosImpuestos.Text.ToDouble).ToDecimal - If(TieneAmortizacion, TmpDT.SUM("ImporteSinImpuestos").ToString.ToDecimal, TmpDT.SUM("Total").ToString.ToDecimal)) 'AjustaImporteUltimoConcepto(TxtSubTotal2.Text.ToDecimal + TxtOtrosImpuestos.Text.ToDecimal - (TmpDT.SUM("Total").ToString.ToDecimal)) - BtnGuardar.Enabled = True - If Not CierrePeriodo Then - BtnGuardar.Visible = True - End If - AlmacenCambiaPS.Visible = False - UpFacturar.Update() - - TabGenerales.Enabled = True - TAB.ActiveTabIndex = 0 - UpTabs.Update() - - - ImgClasificacion.Visible = False - ImgSubProyecto.Visible = False - LbAgregar.Visible = False - OCVinculada = True - UpPSS.Update() - - AsignaValoresOriginales(TxtSubTotal.Text.ToDouble, TxtSubTotal2.Text.ToDouble, TxtIVA.Text.ToDouble, TxtRetIVA.Text.ToDouble, TxtRetISR.Text.ToDouble, TxtTotal.Text.ToDouble) - - If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then CargaGastosServicios(UsuarioActual.Empresa.Funcionalidad(562).ToEntero) - - CargaGvInv() - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - CargaGVsAF() - - CargaTipoCentroCostoOC() - GvOC1.DataSource = DTOCGV - GvOC1.DataBind() - - Dim DTCVEOCS As DataTable = DTOCGV.FiltraParametros("", "", {"CveOrdenCompra"}) - If DTCVEOCS.Rows.Count > 1 Then - GvOC1.Columns(0).Visible = True - Else - GvOC1.Columns(0).Visible = False - End If - - - GvOC2.DataSource = TmpDT - GvOC2.DataBind() - - LbSubTotalOC1.Text = LbSubTotalOC2.Text - LbSubTotal2OC1.Text = LblSubTotal2OC2.Text - LbIVAOC1.Text = LbIVAOC2.Text - LbIEPSOC1.Text = LbIEPSOC2.Text - LblRetIVAOC1.Text = LblRetIVAOC2.Text - LblRetISROC1.Text = LblRetISROC2.Text - LbDescuentoOC1.Text = LblDescuentoOC2.Text - LbTotalOC1.Text = LbTotalOC2.Text - - UpGvOC1.Update() - - 'Bloquea cambio de proyecto - DdlProyecto.Enabled = False - DdlSubProyecto.Enabled = False - DdlAsignarProyecto.Enabled = False - DdlAsignaSubProyecto.Enabled = False - UPPProyecto.Update() - - 'Bloquea cambio de OC ya que se concluyo alguna vinculacion - TxtOC.Enabled = False - UpParametros.Update() - - 'VERIFICA PE - If UsuarioActual.Empresa.UsaAC Then - CompruebaAgregar() - End If - - CargaGvPersonal() - - - 'ANTICIPO OC - If DivOCSolicitudAnticipo.Visible Then - RegistraScript("MuestraAnticipos();", "MuestaAnticiposOC") - UpAnticipos.Update() - End If - - CalculaTotales() - - End Sub - - Private Sub VinculacionAsync(Optional VinculacionCompleta As Boolean = False) - - 'LIMPIAMOS TMPDT - CreaDTCompras() - - Dim tasks As New List(Of Task)() - For Each gvr As GridViewRow In GvOC1.Rows - If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Or VinculacionCompleta Then - tasks.Add(AgregaConceptoOC(DTOCGV.Rows(gvr.RowIndex), gvr)) - End If - Next - Task.WaitAll(tasks.ToArray()) - - AddPS2(False) - - 'AJUSTE DE REDONDEO O DIFERENCIA PERMITIDA DE IMPORTE - AjustaImporteUltimoConcepto((TxtSubTotal2.Text.ToDouble - TmpDT.SUM("Total")).ToString.ToDecimal) - - BtnGuardar.Enabled = True - If Not CierrePeriodo Then - BtnGuardar.Visible = True - End If - AlmacenCambiaPS.Visible = False - UpFacturar.Update() - - TabGenerales.Enabled = True - TAB.ActiveTabIndex = 0 - UpTabs.Update() - - ImgClasificacion.Visible = False - ImgSubProyecto.Visible = False - LbAgregar.Visible = False - OCVinculada = True - UpPSS.Update() - - AsignaValoresOriginales(TxtSubTotal.Text.ToDouble, TxtSubTotal2.Text.ToDouble, TxtIVA.Text.ToDouble, TxtRetIVA.Text.ToDouble, TxtRetISR.Text.ToDouble, TxtTotal.Text.ToDouble) - - CargaGvInv() - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - CargaGVsAF() - - CargaTipoCentroCostoOC() - GvOC1.DataSource = DTOCGV - GvOC1.DataBind() - - Dim DTCVEOCS As DataTable = DTOCGV.FiltraParametros("", "", {"CveOrdenCompra"}) - If DTCVEOCS.Rows.Count > 1 Then - GvOC1.Columns(0).Visible = True - Else - GvOC1.Columns(0).Visible = False - End If - - GvOC2.DataSource = TmpDT - GvOC2.DataBind() - - LbSubTotalOC1.Text = LbSubTotalOC2.Text - LbSubTotal2OC1.Text = LblSubTotal2OC2.Text - LbIVAOC1.Text = LbIVAOC2.Text - LbIEPSOC1.Text = LbIEPSOC2.Text - LblRetIVAOC1.Text = LblRetIVAOC2.Text - LblRetISROC1.Text = LblRetISROC2.Text - LbDescuentoOC1.Text = LblDescuentoOC2.Text - LbTotalOC1.Text = LbTotalOC2.Text - - UpGvOC1.Update() - - 'Bloquea cambio de proyecto - DdlProyecto.Enabled = False - DdlSubProyecto.Enabled = False - DdlAsignarProyecto.Enabled = False - DdlAsignaSubProyecto.Enabled = False - UPPProyecto.Update() - - 'Bloquea cambio de OC ya que se concluyo alguna vinculacion - TxtOC.Enabled = False - UpParametros.Update() - - 'VERIFICA PE - If UsuarioActual.Empresa.UsaAC Then - CompruebaAgregar() - End If - - CargaGvPersonal() - - 'ANTICIPO OC - If DivOCSolicitudAnticipo.Visible Then - RegistraScript("MuestraAnticipos();", "MuestaAnticiposOC") - UpAnticipos.Update() - End If - - CalculaTotales() - - End Sub - - Private Function AgregaConceptoOC(dr As DataRow, gvr As GridViewRow) As Task - Return Task.Factory.StartNew(Sub() AgregaConceptoOCHilo(dr, gvr)) - End Function - Private Sub AgregaConceptoOCHilo(dr As DataRow, gvr As GridViewRow) - Dim Cantidad As Decimal = gvr.FCTextBox("TxtCantidad").Text.ToDecimal - Dim CantidadF As Decimal = gvr.DataKey("CantidadF").ToString.ToDecimal - Dim CveUM As Integer = dr("CveUM").ToString.ToEntero - Dim UM As String = dr("UM").ToString - Dim CveClasificacion As Integer = dr("CveClasificacion").ToString.ToEntero - Dim Clasificacion As String = dr("Clasificacion").ToString - Dim CvePS As Integer = dr("CvePS").ToString.ToEntero - Dim PS As String = dr("PS").ToString - Dim CveTipoPS As Integer = dr("CveTipoPS").ToString.ToEntero - Dim CveSubProyectoContrato As String = dr("CveSubProyecto").ToString - Dim CveProyecto As String = dr("CveProyecto").ToString - Dim SubProyecto As String = dr("SubProyecto").ToString - Dim Proyecto As String = dr("Proyecto").ToString - Dim Obs As String = dr("Obs").ToString - Dim PU As Decimal = gvr.FCTextBox("TxtPU").Text.ToDecimal - Dim Total As Decimal = gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal - - Dim IVA As Decimal = dr("IVAPorcentaje").ToString.ToDecimal - Dim RetIVA As Double = dr("RetIVAPorcentaje").ToString.ToDecimal - Dim RetISR As Double = dr("RetISRPorcentaje").ToString.ToDecimal - Dim IEPSPS As Double = dr("IEPSPSPorcentaje").ToString.ToDecimal - Dim IEPSPSIVA As Double = dr("IEPSPSIVAPorcentaje").ToString.ToDecimal - Dim Descuento As Double = gvr.FCHiddenField("HdnOC1Descuento").Value.ToDecimal - Dim CveOrdenCompraDetalle As Integer = dr("CveOrdenCompraDetalle").ToString.ToEntero - Dim EntregaDirecta As Integer = dr("EntregaDirecta").ToString.ToEntero - Dim CveSATPS As Integer = gvr.FCDropDownLost("DdlSATPS").SelectedValue.ToEntero - Dim CveTipoGasto As Integer = -1 - Dim TipoGasto As String = "" - - '[IPP] PROVISIONAL PARA TIPO GASTO - If GlobalDTTiposGastos(UsuarioActual.CveEmpresa) IsNot Nothing AndAlso GlobalDTTiposGastos(UsuarioActual.CveEmpresa).Rows.Count = 1 Then - Dim DrTipoGasto = GlobalDTTiposGastos(UsuarioActual.CveEmpresa).FiltroPrimero("") - If DrTipoGasto IsNot Nothing Then - CveTipoGasto = DrTipoGasto("CveTipoGasto").ToString.ToEntero - TipoGasto = DrTipoGasto("TipoGasto").ToString - End If - End If - - 'AGREGA PS - Dim IndexVinculacionOC = AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, RetIVA, RetISR, IEPSPS, IEPSPSIVA, Descuento, CveOrdenCompraDetalle, False, CantidadF:=CantidadF, EntregaDirecta:=EntregaDirecta, CveSATPS:=CveSATPS, CveTipoGasto:=CveTipoGasto, TipoGasto:=TipoGasto) - - 'CARGA PE - TmpDT.Rows(IndexVinculacionOC)("CvePresupuestoEgreso") = dr("CvePresupuestoEgreso").ToString.ToEntero - TmpDT.Rows(IndexVinculacionOC)("CveProgramaOperativo") = dr("CveProgramaOperativo").ToString.ToEntero - TmpDT.Rows(IndexVinculacionOC)("CveUnidadAdministrativa") = dr("CveUnidadAdministrativa").ToString.ToEntero - TmpDT.Rows(IndexVinculacionOC)("CveFuenteFinanciamiento") = dr("CveFuenteFinanciamiento").ToString.ToEntero - TmpDT.Rows(IndexVinculacionOC)("CveTipoGastoAC") = dr("CveTipoGasto").ToString.ToEntero - TmpDT.Rows(IndexVinculacionOC)("CveClasificacionOG") = dr("CveClasificacionOG").ToString.ToEntero - - TmpDT.Rows(IndexVinculacionOC)("PSCodigo") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimeroValor("PSCodigo", "").ToString - - Dim CveAF As String = dr("CveActivoFijo").ToString - If CveAF <> "" AndAlso CveAF <> "-1" Then - TmpDT.Rows(IndexVinculacionOC)("CveActivoFijo") = CveAF.ToEntero - TmpDT.Rows(IndexVinculacionOC)("CodAF") = dr("CodigoAF").ToString - TmpDT.Rows(IndexVinculacionOC)("TipoAF") = 1 - End If - 'actualizo los movimientos registrados - DTOCGV.Rows(gvr.RowIndex)("CantidadDisponible") = Cantidad - DTOCGV.Rows(gvr.RowIndex)("Importe") = PU - DTOCGV.Rows(gvr.RowIndex)("Total") = Total - End Sub - - - Protected Sub BtnTipoCambioOC_Click(sender As Object, e As EventArgs) - - If TxtTipoCambioOC.Text.ToDecimal = 0 Then - Alert("El tipo de cambio debe ser mayor a cero. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - For Each Dr As DataRow In DTOCTemp.Rows - - 'OC - COMPRA - 'DOLARES A PESOS - If DdlMoneda.SelectedValue.ToEntero = 1 Then - Dr("Importe") = Dr("PUTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal - Dr("Descuento") = Dr("DescuentoTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal - Dr("IVA") = Dr("IVATC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal - Dr("IEPSPS") = Dr("IEPSPSTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal - Dr("IEPSPSIVA") = Dr("IEPSPSIVATC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal - Dr("RetIVA") = Dr("RetIVATC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal - Dr("RetISR") = Dr("RetISRTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal - Dr("ImporteAjustadoDescuento") = Dr("TotalTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal - End If - - 'OC - COMPRA - 'PESOS A DOLARES - If DdlMoneda.SelectedValue.ToEntero = 2 Then - Dr("Importe") = Dr("PUTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal - Dr("Descuento") = Dr("DescuentoTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal - Dr("IVA") = Dr("IVATC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal - Dr("IEPSPS") = Dr("IEPSPSTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal - Dr("IEPSPSIVA") = Dr("IEPSPSIVATC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal - Dr("RetIVA") = Dr("RetIVATC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal - Dr("RetISR") = Dr("RetISRTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal - Dr("ImporteAjustadoDescuento") = Dr("TotalTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal - End If - - Dr.AcceptChanges() - Next - - TipoCambioOC = TxtTipoCambioOC.Text.ToDecimal - BtnVincularOC.Visible = True - CargaVinculacionOC() - End Sub - Protected Sub BtnDividirCompra_Click(sender As Object, e As EventArgs) - Dim Cantidad = CType(CType(sender, Button).NamingContainer, GridViewRow).FCTextBox("TxtDividir").Text.ToDouble - - If Cantidad < 0.1 Then - Exit Sub - End If - - Dim dr = TmpDT.Rows(CType(CType(sender, Button).NamingContainer, GridViewRow).RowIndex) - Dim drNuevo = TmpDT.NewRow - - drNuevo.ItemArray = dr.ItemArray - drNuevo("Cantidad") = Cantidad - drNuevo("Total") = drNuevo("Cantidad").ToString.ToEntero * drNuevo("PU").ToString.ToDouble - - dr("Cantidad") = dr("Cantidad").ToString.ToEntero - Cantidad - dr("Total") = dr("Cantidad").ToString.ToEntero * dr("PU").ToString.ToDouble - - TmpDT.Rows.InsertAt(drNuevo, CType(CType(sender, Button).NamingContainer, GridViewRow).RowIndex) - - If TxtOC.Text.Trim <> "" Then - 'If EmpresasOC.Contains(UsuarioActual.CveEmpresa) Then - ' GvOC1.DataSource = TmpDT - ' GvOC1.DataBind() - ' UpGvOC1.Update() - 'Else - GvOC2.DataSource = TmpDT - GvOC2.DataBind() - UpGvOC2.Update() - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - 'End If - Else - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - End If - - CargaGvInv() - - End Sub - Protected Sub BtnAlertaPUCero_Click(sender As Object, e As EventArgs) - Dim Argumentos = HdnAlertaPUCero.Value.Split("|"c) - Dim PS = Argumentos(0) - Dim Cantidad = Argumentos(1) - 'Alert($"El concepto tiene especificada una cantidad pero con costo de cero ($0).
br /<> b > En caso de vincular la OC de esta manera la cantidad especificada sera considerada como recibida.

De ser correcto Continue o de lo contrario rectifique.", TipoMensaje.MsgAdvertencia) - - - Alert($"El concepto {PS} tiene especificada la cantidad {Cantidad} pero un costo de cero ($0).

En caso de vincular la OC de esta manera la cantidad especificada sera considerada como recibida.

De ser correcto Continue o de lo contrario rectifique.", TipoMensaje.MsgAdvertencia) + BtnGuardar.Enabled = True + If Not CierrePeriodo Then + BtnGuardar.Visible = True + End If + AlmacenCambiaPS.Visible = False + UpFacturar.Update() + + TabGenerales.Enabled = True + Tab.ActiveTabIndex = 0 + UpTabs.Update() + + + ImgClasificacion.Visible = False + ImgSubProyecto.Visible = False + LbAgregar.Visible = False + OCVinculada = True + UpPSS.Update() + + AsignaValoresOriginales(TxtSubTotal.Text.ToDouble, TxtSubTotal2.Text.ToDouble, TxtIVA.Text.ToDouble, TxtRetIVA.Text.ToDouble, TxtRetISR.Text.ToDouble, TxtTotal.Text.ToDouble) + + If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then CargaGastosServicios(UsuarioActual.Empresa.Funcionalidad(562).ToEntero) + + CargaGvInv() + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + CargaGVsAF() + + CargaTipoCentroCostoOC() + GvOC1.DataSource = DTOCGV + GvOC1.DataBind() + + Dim DTCVEOCS As DataTable = DTOCGV.FiltraParametros("", "", {"CveOrdenCompra"}) + If DTCVEOCS.Rows.Count > 1 Then + GvOC1.Columns(0).Visible = True + Else + GvOC1.Columns(0).Visible = False + End If + + + GvOC2.DataSource = TmpDT + GvOC2.DataBind() + + LbSubTotalOC1.Text = LbSubTotalOC2.Text + LbSubTotal2OC1.Text = LblSubTotal2OC2.Text + LbIVAOC1.Text = LbIVAOC2.Text + LbIEPSOC1.Text = LbIEPSOC2.Text + LblRetIVAOC1.Text = LblRetIVAOC2.Text + LblRetISROC1.Text = LblRetISROC2.Text + LbDescuentoOC1.Text = LblDescuentoOC2.Text + LbTotalOC1.Text = LbTotalOC2.Text + + UpGvOC1.Update() + + 'Bloquea cambio de proyecto + DdlProyecto.Enabled = False + DdlSubProyecto.Enabled = False + DdlAsignarProyecto.Enabled = False + DdlAsignaSubProyecto.Enabled = False + UPPProyecto.Update() + + 'Bloquea cambio de OC ya que se concluyo alguna vinculacion + TxtOC.Enabled = False + UpParametros.Update() + + 'VERIFICA PE + If UsuarioActual.Empresa.UsaAC Then + CompruebaAgregar() + End If + + CargaGvPersonal() + + + 'ANTICIPO OC + If DivOCSolicitudAnticipo.Visible Then + RegistraScript("MuestraAnticipos();", "MuestaAnticiposOC") + UpAnticipos.Update() + End If + + CalculaTotales() + End Sub -#End Region -#Region "F L E T E S Y S E R V I C I O S" + Private Sub VinculacionAsync(Optional VinculacionCompleta As Boolean = False) - Public Sub CreaDTFacturas() - - Dim dt As New DataTable - - dt.Columns.Add("CveCompra", Type.GetType("System.Int32")) - dt.Columns.Add("Folio", Type.GetType("System.String")) - dt.Columns.Add("Fecha", Type.GetType("System.String")) - - DtFacturas = dt - End Sub - - Public Sub CreaDTServicios() - - Dim dt As New DataTable - - dt.Columns.Add("Total", Type.GetType("System.Double")) - dt.Columns.Add("PS", Type.GetType("System.String")) - dt.Columns.Add("Consec", Type.GetType("System.Int32")) - dt.Columns.Add("CvePS", Type.GetType("System.Int32")) - - DtServicios = dt - End Sub - - - - Protected Sub LbServicios_Click(sender As Object, e As EventArgs) - RegistraScript("$('#DivFletesYServicios').modal();") - CreaDTFacturas() - CreaDTServicios() - - End Sub - - Protected Sub BtnFiltrar_Click(sender As Object, e As EventArgs) - If DdlTipo.SelectedValue.ToEntero = 1 Then - - 'POR SI LLEGARA A TRONAR - If DtServicios Is Nothing Then CreaDTServicios() - DtServicios.Rows.Clear() - - Dim objps As New ClsProductosServicios - Dim dr As DataRow - dvFacturas.Visible = False - GvFacturas.Visible = False - - For Each DrGv As DataRow In TmpDT.Rows - If DrGv("CvePS").ToString.ToEntero > 0 Then - If objps.GetPS(DrGv("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) Then - If objps.DtResultados(0)("CveTipoPS").ToString.ToEntero = 1 Then - dr = DtServicios.NewRow() - dr("Consec") = DrGv("Consec").ToString.ToEntero - dr("Total") = DrGv("Total").ToString.ToDecimal - dr("CvePS") = DrGv("CvePS").ToString.ToEntero - dr("PS") = DrGv("PS").ToString - DtServicios.Rows.Add(dr) - End If - End If - End If - Next - - '[IPP] COMENTADO - MIRAS DE ELIMINAR - 8/FEBRERO/2018 - 'For Each gvr As GridViewRow In GvPS.Rows - ' If objps.GetPS(gvr.DataKey("CvePS").ToEntero, -1, UsuarioActual.CveEmpresa) Then - ' If objps.DtResultados(0)("CveTipoPS").ToString.ToEntero = 1 Then - ' dr = DtServicios.NewRow() - ' dr("Consec") = gvr.FCLabel("LtlConsecutivo").Text.ToEntero - ' dr("Total") = gvr.FCLiteral("LtlTotal").Text.ToDecimal - ' dr("PS") = gvr.DataKey("PS").ToString - ' DtServicios.Rows.Add(dr) - ' End If - ' End If - 'Next - objps.Dispose() - - If DtServicios.Rows.Count > 0 Then - GVServicios.DataSource = DtServicios - GVServicios.DataBind() - GVServicios.Visible = True - Else - GVServicios.DataSource = Nothing - GVServicios.DataBind() - End If - - UpGVServicios.Update() - UpFacturas.Update() - UPGVFacturas.Update() - - ElseIf DdlTipo.SelectedValue.ToEntero = 2 Then - GVServicios.Visible = False - dvFacturas.Visible = True - DdlProveedores.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa) - DdlProveedores.DataBind() - DdlProveedores.Items.Insert(0, New ListItem("Seleccione", "-1")) - UpFacturas.Update() - UpGVServicios.Update() - - - End If - - End Sub - - Public Sub btnAgregarFlete_Click(sender As Object, e As EventArgs) Handles BtnAgregarFlete.Click - - Dim ListaConsecutivas As New List(Of String) 'Almacena los consecutivos que pertenecen al almacen - Dim CostoIndirectoTotal As Decimal = 0 'Suma los costos indirectos calculados - Dim IndiceFila As Integer = 0 'Alamcena la fila actual iterada del TmpDT - Dim IndiceActualizar As Integer = -1 'Almacena el ultimo indice perteneciente a Almacen - - TotalFlete = 0 - TotalAlmacen = 0 - - 'Obtenemos el total del flete y marcamos los conceptos que pertenecen a flete - For Each gvr As GridViewRow In GVServicios.Rows - If gvr.FCCheckBox("chkServicios").Checked Then - Dim Dtr As DataRow = TmpDT.Select($"Consec = {gvr.FCLabel("LblConsec").Text.ToEntero}")(0) - Dtr("AplicaCostoIndirecto") = 1 - TotalFlete += Math.Round(gvr.FCLiteral("LtlTotalmodal").Text.ToDecimal, 2) - End If - Next - - 'Obtenemos el total del almacen y guardamos las consecutivas pertenecientes al mismo - For Each Dr As DataRow In DtInv.Rows - TotalAlmacen += Math.Round(Dr("Total").ToString.ToDecimal, 2) - ListaConsecutivas.Add(Dr("Consec").ToString) - Next - - 'Asignamos los costos indirectos y los indices - For Each Drt As DataRow In TmpDT.Rows - If ListaConsecutivas.Contains(Drt("Consec").ToString) Then - Dim CostoIndirecto As Decimal = CalculaCostoIndirectoFlete(Drt("Total").ToString.ToDecimal) - CostoIndirectoTotal += CostoIndirecto - Drt("CostoIndirectoAlmacen") = CostoIndirecto - Drt("OtrosGastos") = CostoIndirecto - IndiceActualizar = IndiceFila - End If - IndiceFila += 1 - Next - - 'Si los costosindirectos no suman el total exacto del flete ajustamos el ultimo concepto - If CostoIndirectoTotal <> TotalFlete AndAlso IndiceActualizar >= 0 Then - Dim Diferencia = TotalFlete - CostoIndirectoTotal - TmpDT.Rows(IndiceActualizar)("CostoIndirectoAlmacen") = TmpDT.Rows(IndiceActualizar)("CostoIndirectoAlmacen").ToString.ToDouble + Diferencia - TmpDT.Rows(IndiceActualizar)("OtrosGastos") = TmpDT.Rows(IndiceActualizar)("OtrosGastos").ToString.ToDouble + Diferencia - End If - - TmpDT.AcceptChanges() - CargaGvInv() - DdlTipoCompra.SelectedValueExist("8") - UpEstatus.Update() - - ''Marcamos todos los almacenes como check - 'GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True - 'cbAll_CheckedChanged(Nothing, Nothing) - - End Sub - - Private Sub CargaGastosServicios(CvePS As Integer) - 'POR SI LLEGARA A TRONAR - If DtServicios Is Nothing Then CreaDTServicios() - DtServicios.Rows.Clear() - - Dim objps As New ClsProductosServicios - Dim dr As DataRow - dvFacturas.Visible = False - GvFacturas.Visible = False - - For Each DrGv As DataRow In TmpDT.Rows - If DrGv("CvePS").ToString.ToEntero > 0 Then - If objps.GetPS(DrGv("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) Then - If objps.DtResultados IsNot Nothing AndAlso objps.DtResultados.Rows.Count > 0 AndAlso objps.DtResultados(0)("CveTipoPS").ToString.ToEntero = 1 Then - dr = DtServicios.NewRow() - dr("Consec") = DrGv("Consec").ToString.ToEntero - dr("Total") = DrGv("Total").ToString.ToDecimal - dr("CvePS") = DrGv("CvePS").ToString.ToEntero - dr("PS") = DrGv("PS").ToString - DtServicios.Rows.Add(dr) - End If - End If - End If - Next - - '[IPP] COMENTADO - MIRAS DE ELIMINAR - 8/FEBRERO/2018 - 'For Each gvr As GridViewRow In GvPS.Rows - ' If objps.GetPS(gvr.DataKey("CvePS").ToEntero, -1, UsuarioActual.CveEmpresa) Then - ' If objps.DtResultados(0)("CveTipoPS").ToString.ToEntero = 1 Then - ' dr = DtServicios.NewRow() - ' dr("Consec") = gvr.FCLabel("LtlConsecutivo").Text.ToEntero - ' dr("Total") = gvr.FCLiteral("LtlTotal").Text.ToDecimal - ' dr("PS") = gvr.DataKey("PS").ToString - ' DtServicios.Rows.Add(dr) - ' End If - ' End If - 'Next - objps.Dispose() - - If DtServicios.Rows.Count > 0 Then - GVServicios.DataSource = DtServicios - GVServicios.DataBind() - GVServicios.Visible = True - Else - GVServicios.DataSource = Nothing - GVServicios.DataBind() - End If - - UpGVServicios.Update() - UpFacturas.Update() - UPGVFacturas.Update() - - - Dim ListaConsecutivas As New List(Of String) 'Almacena los consecutivos que pertenecen al almacen - Dim CostoIndirectoTotal As Decimal = 0 'Suma los costos indirectos calculados - Dim IndiceFila As Integer = 0 'Alamcena la fila actual iterada del TmpDT - Dim IndiceActualizar As Integer = -1 'Almacena el ultimo indice perteneciente a Almacen - - TotalFlete = 0 - TotalAlmacen = 0 - - If DtInv IsNot Nothing Then - 'Obtenemos el total del almacen y guardamos las consecutivas pertenecientes al mismo - For Each Dr2 As DataRow In DtInv.Rows - TotalAlmacen += Math.Round(Dr2("Total").ToString.ToDecimal, 2) - ListaConsecutivas.Add(Dr2("Consec").ToString) - Next - End If - - 'sino hay producto en almacen para aplciarle un servicio, no se debe de amrcar como costo indirecto - 'esto aplica cuando la factura solo trae un concepto, y es el de servicio - If TotalAlmacen = 0 Then Exit Sub - - 'Obtenemos el total del flete y marcamos los conceptos que pertenecen a flete - For Each gvr As GridViewRow In GVServicios.Rows - If gvr.DataKey("CvePS").ToEntero = CvePS Or gvr.FCCheckBox("chkServicios").Checked Then - Dim Dtr As DataRow = TmpDT.Select($"Consec = {gvr.FCLabel("LblConsec").Text.ToEntero}")(0) - Dtr("AplicaCostoIndirecto") = 1 - TotalFlete += Math.Round(gvr.FCLiteral("LtlTotalmodal").Text.ToDecimal, 2) - gvr.FCCheckBox("chkServicios").Checked = True - End If - Next - UpGVServicios.Update() - - - If Not TotalFlete > 0 Then Exit Sub - - - 'Asignamos los costos indirectos y los indices - For Each Drt As DataRow In TmpDT.Rows - If ListaConsecutivas.Contains(Drt("Consec").ToString) Then - Dim CostoIndirecto As Decimal = CalculaCostoIndirectoFlete(Drt("Total").ToString.ToDecimal) - CostoIndirectoTotal += CostoIndirecto - Drt("CostoIndirectoAlmacen") = CostoIndirecto - Drt("OtrosGastos") = CostoIndirecto - IndiceActualizar = IndiceFila - End If - IndiceFila += 1 - Next - - 'Si los costosindirectos no suman el total exacto del flete ajustamos el ultimo concepto - If CostoIndirectoTotal <> TotalFlete AndAlso IndiceActualizar >= 0 Then - Dim Diferencia = TotalFlete - CostoIndirectoTotal - TmpDT.Rows(IndiceActualizar)("CostoIndirectoAlmacen") = TmpDT.Rows(IndiceActualizar)("CostoIndirectoAlmacen").ToString.ToDouble + Diferencia - TmpDT.Rows(IndiceActualizar)("OtrosGastos") = TmpDT.Rows(IndiceActualizar)("OtrosGastos").ToString.ToDouble + Diferencia - End If - - TmpDT.AcceptChanges() - CargaGvInv() - DdlTipoCompra.SelectedValueExist("8") - UpEstatus.Update() - - ''Marcamos todos los almacenes como check - 'GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True - 'cbAll_CheckedChanged(Nothing, Nothing) - End Sub - - - Protected Sub GVServicios_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVServicios.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - Dim TmpDr As DataRow = TmpDT.Select($"Consec = {e.Row.FCLabel("LblConsec").Text}")(0) - If TmpDr("AplicaCostoIndirecto").ToString = "1" Then - e.Row.FCCheckBox("chkServicios").Checked = True - e.Row.FCCheckBox("chkServicios").Enabled = Not CveCompra > 0 - End If - End If - End Sub - - Private Function CalculaCostoIndirectoFlete(ImporteAlmacen As Decimal) As Decimal - Dim CostoIndirecto As Decimal - CostoIndirecto = (ImporteAlmacen * TotalFlete) / TotalAlmacen - Return Math.Round(CostoIndirecto, 2) - End Function - - Protected Sub BtnAgregaFactura_Click(sender As Object, e As EventArgs) - Dim ObjComp As New ClsCompras - If ObjComp.GetCompras(DdlFacturas.SelectedValue.ToEntero, "-1", DdlFacturas.SelectedItem.ToString, -1, -1, 1) Then - - Dim dr As DataRow = DtFacturas.NewRow() - dr("CveCompra") = ObjComp.DtResultados(0)("CveCompra").ToString - dr("Folio") = ObjComp.DtResultados(0)("Folio").ToString - dr("Fecha") = ObjComp.DtResultados(0)("Fecha").ToString.ToDate.ToString("dd/MM/yyyy") - DtFacturas.Rows.Add(dr) - - If GvFacturas.Visible = False Then - GvFacturas.Visible = True - End If - - GvFacturas.DataSource = DtFacturas - GvFacturas.DataBind() - - Else - Alert("No se encontró la factura", TipoMensaje.MsgAdvertencia) - End If - - UPGVFacturas.Update() - ObjComp.Dispose() - End Sub - - Protected Sub DdlProveedores_SelectedIndexChanged(sender As Object, e As EventArgs) - CargarFacturas() - End Sub - - Private Sub CargarFacturas() - Dim objCompras As New ClsCompras - If objCompras.GetCompras(-1, "-1", "-1", DdlProveedores.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) Then - DdlFacturas.DataSource = objCompras.DtResultados - Else - DdlFacturas.DataSource = Nothing - Alert("No se encontraron folios con el proveedor seleccionado.", TipoMensaje.MsgAdvertencia) - End If - DdlFacturas.DataBind() - DdlFacturas.Items.Insert(0, New ListItem("Seleccione", "-1")) - - objCompras.Dispose() - End Sub - - Protected Sub GvFacturas_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvFacturas.RowDeleting - - DtFacturas.Rows.RemoveAt(e.RowIndex) - GvFacturas.DataSource = DtFacturas - GvFacturas.DataBind() - UPGVFacturas.Update() - UpFacturas.Update() - - - - End Sub - - Public Sub ValidaFletesServicios() - - If Not UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then - dvFacturas.Visible = False - GvFacturas.Visible = False - GVServicios.Visible = False - End If - - If UsuarioActual.Empresa.UsaInventarios And UsuarioActual.Empresa.CvePlataforma <> 2 Then - liServicios.Visible = True - liFletesImportaciones.Visible = True - End If - - End Sub - - Public Function AplicarCostoIndirecto(ObjInv As ClsInventarios, ObjCompras As ClsCompras) As Boolean - Return False - - Dim HayError As Boolean - - Dim dtTemporal As New DataTable - dtTemporal = Nothing - - If GvFacturas.Visible AndAlso GvFacturas.Rows.Count > 0 Then - - Dim IdCompras = New List(Of Integer) - Dim TotalServicios As Decimal = 0 - - TotalServicios = TxtSubTotal.Text.ToString.ToDecimal - If TotalServicios > 0 Then - - For Each row As GridViewRow In GvFacturas.Rows - IdCompras.Add(row.DataKey("CveCompra").ToEntero) - Next - For Each value As Integer In IdCompras - If ObjInv.GetMovimientosDetalle(-1, UsuarioActual.CveEmpresa, value) AndAlso ObjInv.DtResultados.Rows.Count > 0 Then - If dtTemporal Is Nothing Then - dtTemporal = ObjInv.DtResultados - Else - dtTemporal.Merge(ObjInv.DtResultados) - End If - End If - Next - - 'Dim DtProductos As New DataTable - ' DtProductos = ObjInv.DtResultados.DefaultView.ToTable(True, "CveMovimiento", "CvePS", "Cantidad", "PU", "Total") - 'Dim total As Decimal = 0 - 'For Each row As DataRow In DtProductos.Rows - ' total = total + row("Total").ToString.ToDecimal - 'Next - 'If total > 0 Then - - If dtTemporal IsNot Nothing Then - Dim TotalFacturas = dtTemporal.SUM("Total").ToString.ToDecimal - For Each row As DataRow In dtTemporal.Rows - Dim prorrateo As Decimal - prorrateo = (row("PU").ToString.ToDecimal * TotalServicios) / TotalFacturas - If Not ObjInv.UpdateCostoIndirectoMovimientoDetalle(row("CveMovimientoDetalle").ToString.ToEntero, prorrateo) Then - HayError = True - Exit For - - End If - Next - End If - Else - Alert("El total de los servicios a vincular debe ser mayor a $0.00", TipoMensaje.MsgError) - Return True - End If - - ElseIf GVServicios.Visible AndAlso GVServicios.Rows.Count > 0 Then - - Dim Dtcompra As New DataTable - Dim TotalServicios As Decimal = 0 - - Dim chk As Boolean = False - For Each gvr As GridViewRow In GVServicios.Rows - If gvr.FCCheckBox("chkServicios").Checked Then - TotalServicios += gvr.FCLiteral("LtlTotalmodal").Text.ToDecimal - chk = True - End If - Next - - If chk = False Then - Alert("Debe Seleccionar un Servicio", TipoMensaje.MsgInformacion) - Return False - Else - - If ObjCompras.GetCompraDetalle(CveCompra) Then - If ObjInv.GetMovimientosDetalle(-1, UsuarioActual.CveEmpresa, CveCompra) Then - Dtcompra = ObjInv.DtResultados - Dim TotalProductos = Dtcompra.SUM("Total").ToString.ToDecimal - If TotalProductos > 0 Then - For Each row As DataRow In Dtcompra.Rows - Dim prorrateo As Decimal - prorrateo = (row("PU").ToString.ToDecimal * TotalServicios) / TotalProductos - If Not ObjInv.UpdateCostoIndirectoMovimientoDetalle(row("CveMovimientoDetalle").ToString.ToEntero, prorrateo) Then - HayError = True - Exit For - - End If - Next - Else - Alert("No existen productos de inventario en esta factura", TipoMensaje.MsgError) - End If - End If - End If - - End If - Else - Return False - End If - - If HayError = True And ObjInv IsNot Nothing Then - Alert("Ocurrió un error al vincular un flete o servicio") - HayError = True - End If - - Return HayError - End Function - - Protected Sub BtnCancelar_Click(sender As Object, e As EventArgs) - 'dvFacturas.Visible = False - 'GvFacturas.Visible = False - 'GVServicios.Visible = False - 'UpFacturas.Update() - 'UPGVFacturas.Update() - 'UpGVServicios.Update() - End Sub - - Protected Sub DdlTipoComprobante_SelectedIndexChanged(sender As Object, e As EventArgs) - If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then - If DdlTipoComprobante.SelectedValue = "NC" Then - DivReembolso.Visible = False - RBLPago.Items(2).Enabled = False - Else - DivReembolso.Visible = True - RBLPago.Items(2).Enabled = True - End If - ImgAnticiposPendientes.Visible = False + 'LIMPIAMOS TMPDT + CreaDTCompras() + + Dim tasks As New List(Of Task)() + For Each gvr As GridViewRow In GvOC1.Rows + If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Or VinculacionCompleta Then + tasks.Add(AgregaConceptoOC(DTOCGV.Rows(gvr.RowIndex), gvr)) + End If + Next + Task.WaitAll(tasks.ToArray()) + + AddPS2(False) + + 'AJUSTE DE REDONDEO O DIFERENCIA PERMITIDA DE IMPORTE + AjustaImporteUltimoConcepto((TxtSubTotal2.Text.ToDouble - TmpDT.SUM("Total")).ToString.ToDecimal) + + BtnGuardar.Enabled = True + If Not CierrePeriodo Then + BtnGuardar.Visible = True + End If + AlmacenCambiaPS.Visible = False + UpFacturar.Update() + + TabGenerales.Enabled = True + Tab.ActiveTabIndex = 0 + UpTabs.Update() + + ImgClasificacion.Visible = False + ImgSubProyecto.Visible = False + LbAgregar.Visible = False + OCVinculada = True + UpPSS.Update() + + AsignaValoresOriginales(TxtSubTotal.Text.ToDouble, TxtSubTotal2.Text.ToDouble, TxtIVA.Text.ToDouble, TxtRetIVA.Text.ToDouble, TxtRetISR.Text.ToDouble, TxtTotal.Text.ToDouble) + + CargaGvInv() + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + CargaGVsAF() + + CargaTipoCentroCostoOC() + GvOC1.DataSource = DTOCGV + GvOC1.DataBind() + + Dim DTCVEOCS As DataTable = DTOCGV.FiltraParametros("", "", {"CveOrdenCompra"}) + If DTCVEOCS.Rows.Count > 1 Then + GvOC1.Columns(0).Visible = True + Else + GvOC1.Columns(0).Visible = False + End If + + GvOC2.DataSource = TmpDT + GvOC2.DataBind() + + LbSubTotalOC1.Text = LbSubTotalOC2.Text + LbSubTotal2OC1.Text = LblSubTotal2OC2.Text + LbIVAOC1.Text = LbIVAOC2.Text + LbIEPSOC1.Text = LbIEPSOC2.Text + LblRetIVAOC1.Text = LblRetIVAOC2.Text + LblRetISROC1.Text = LblRetISROC2.Text + LbDescuentoOC1.Text = LblDescuentoOC2.Text + LbTotalOC1.Text = LbTotalOC2.Text + + UpGvOC1.Update() + + 'Bloquea cambio de proyecto + DdlProyecto.Enabled = False + DdlSubProyecto.Enabled = False + DdlAsignarProyecto.Enabled = False + DdlAsignaSubProyecto.Enabled = False + UPPProyecto.Update() + + 'Bloquea cambio de OC ya que se concluyo alguna vinculacion + TxtOC.Enabled = False + UpParametros.Update() + + 'VERIFICA PE + If UsuarioActual.Empresa.UsaAC Then + CompruebaAgregar() + End If + + CargaGvPersonal() + + 'ANTICIPO OC + If DivOCSolicitudAnticipo.Visible Then + RegistraScript("MuestraAnticipos();", "MuestaAnticiposOC") + UpAnticipos.Update() + End If + + CalculaTotales() + + End Sub + + Private Function AgregaConceptoOC(dr As DataRow, gvr As GridViewRow) As Task + Return Task.Factory.StartNew(Sub() AgregaConceptoOCHilo(dr, gvr)) + End Function + Private Sub AgregaConceptoOCHilo(dr As DataRow, gvr As GridViewRow) + Dim Cantidad As Decimal = gvr.FCTextBox("TxtCantidad").Text.ToDecimal + Dim CantidadF As Decimal = gvr.DataKey("CantidadF").ToString.ToDecimal + Dim CveUM As Integer = dr("CveUM").ToString.ToEntero + Dim UM As String = dr("UM").ToString + Dim CveClasificacion As Integer = dr("CveClasificacion").ToString.ToEntero + Dim Clasificacion As String = dr("Clasificacion").ToString + Dim CvePS As Integer = dr("CvePS").ToString.ToEntero + Dim PS As String = dr("PS").ToString + Dim CveTipoPS As Integer = dr("CveTipoPS").ToString.ToEntero + Dim CveSubProyectoContrato As String = dr("CveSubProyecto").ToString + Dim CveProyecto As String = dr("CveProyecto").ToString + Dim SubProyecto As String = dr("SubProyecto").ToString + Dim Proyecto As String = dr("Proyecto").ToString + Dim Obs As String = dr("Obs").ToString + Dim PU As Decimal = gvr.FCTextBox("TxtPU").Text.ToDecimal + Dim Total As Decimal = gvr.FCTextBox("TxtTotalOC1").Text.ToDecimal + + Dim IVA As Decimal = dr("IVAPorcentaje").ToString.ToDecimal + Dim RetIVA As Double = dr("RetIVAPorcentaje").ToString.ToDecimal + Dim RetISR As Double = dr("RetISRPorcentaje").ToString.ToDecimal + Dim IEPSPS As Double = dr("IEPSPSPorcentaje").ToString.ToDecimal + Dim IEPSPSIVA As Double = dr("IEPSPSIVAPorcentaje").ToString.ToDecimal + Dim Descuento As Double = gvr.FCHiddenField("HdnOC1Descuento").Value.ToDecimal + Dim CveOrdenCompraDetalle As Integer = dr("CveOrdenCompraDetalle").ToString.ToEntero + Dim EntregaDirecta As Integer = dr("EntregaDirecta").ToString.ToEntero + Dim CveSATPS As Integer = gvr.FCDropDownLost("DdlSATPS").SelectedValue.ToEntero + Dim CveTipoGasto As Integer = -1 + Dim TipoGasto As String = "" + + '[IPP] PROVISIONAL PARA TIPO GASTO + If GlobalDTTiposGastos(UsuarioActual.CveEmpresa) IsNot Nothing AndAlso GlobalDTTiposGastos(UsuarioActual.CveEmpresa).Rows.Count = 1 Then + Dim DrTipoGasto = GlobalDTTiposGastos(UsuarioActual.CveEmpresa).FiltroPrimero("") + If DrTipoGasto IsNot Nothing Then + CveTipoGasto = DrTipoGasto("CveTipoGasto").ToString.ToEntero + TipoGasto = DrTipoGasto("TipoGasto").ToString + End If + End If + + 'AGREGA PS + Dim IndexVinculacionOC = AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, RetIVA, RetISR, IEPSPS, IEPSPSIVA, Descuento, CveOrdenCompraDetalle, False, CantidadF:=CantidadF, EntregaDirecta:=EntregaDirecta, CveSATPS:=CveSATPS, CveTipoGasto:=CveTipoGasto, TipoGasto:=TipoGasto) + + 'CARGA PE + TmpDT.Rows(IndexVinculacionOC)("CvePresupuestoEgreso") = dr("CvePresupuestoEgreso").ToString.ToEntero + TmpDT.Rows(IndexVinculacionOC)("CveProgramaOperativo") = dr("CveProgramaOperativo").ToString.ToEntero + TmpDT.Rows(IndexVinculacionOC)("CveUnidadAdministrativa") = dr("CveUnidadAdministrativa").ToString.ToEntero + TmpDT.Rows(IndexVinculacionOC)("CveFuenteFinanciamiento") = dr("CveFuenteFinanciamiento").ToString.ToEntero + TmpDT.Rows(IndexVinculacionOC)("CveTipoGastoAC") = dr("CveTipoGasto").ToString.ToEntero + TmpDT.Rows(IndexVinculacionOC)("CveClasificacionOG") = dr("CveClasificacionOG").ToString.ToEntero + + TmpDT.Rows(IndexVinculacionOC)("PSCodigo") = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimeroValor("PSCodigo", "").ToString + + Dim CveAF As String = dr("CveActivoFijo").ToString + If CveAF <> "" AndAlso CveAF <> "-1" Then + TmpDT.Rows(IndexVinculacionOC)("CveActivoFijo") = CveAF.ToEntero + TmpDT.Rows(IndexVinculacionOC)("CodAF") = dr("CodigoAF").ToString + TmpDT.Rows(IndexVinculacionOC)("TipoAF") = 1 + End If + 'actualizo los movimientos registrados + DTOCGV.Rows(gvr.RowIndex)("CantidadDisponible") = Cantidad + DTOCGV.Rows(gvr.RowIndex)("Importe") = PU + DTOCGV.Rows(gvr.RowIndex)("Total") = Total + End Sub + + + Protected Sub BtnTipoCambioOC_Click(sender As Object, e As EventArgs) + + If TxtTipoCambioOC.Text.ToDecimal = 0 Then + Alert("El tipo de cambio debe ser mayor a cero. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + For Each Dr As DataRow In DTOCTemp.Rows + + 'OC - COMPRA + 'DOLARES A PESOS + If DdlMoneda.SelectedValue.ToEntero = 1 Then + Dr("Importe") = Dr("PUTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal + Dr("Descuento") = Dr("DescuentoTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal + Dr("IVA") = Dr("IVATC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal + Dr("IEPSPS") = Dr("IEPSPSTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal + Dr("IEPSPSIVA") = Dr("IEPSPSIVATC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal + Dr("RetIVA") = Dr("RetIVATC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal + Dr("RetISR") = Dr("RetISRTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal + Dr("ImporteAjustadoDescuento") = Dr("TotalTC").ToString.ToDecimal * TxtTipoCambioOC.Text.ToDecimal + End If + + 'OC - COMPRA + 'PESOS A DOLARES + If DdlMoneda.SelectedValue.ToEntero = 2 Then + Dr("Importe") = Dr("PUTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal + Dr("Descuento") = Dr("DescuentoTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal + Dr("IVA") = Dr("IVATC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal + Dr("IEPSPS") = Dr("IEPSPSTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal + Dr("IEPSPSIVA") = Dr("IEPSPSIVATC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal + Dr("RetIVA") = Dr("RetIVATC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal + Dr("RetISR") = Dr("RetISRTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal + Dr("ImporteAjustadoDescuento") = Dr("TotalTC").ToString.ToDecimal / TxtTipoCambioOC.Text.ToDecimal + End If + + Dr.AcceptChanges() + Next + + TipoCambioOC = TxtTipoCambioOC.Text.ToDecimal + BtnVincularOC.Visible = True + CargaVinculacionOC() + End Sub + Protected Sub BtnDividirCompra_Click(sender As Object, e As EventArgs) + Dim Cantidad = CType(CType(sender, Button).NamingContainer, GridViewRow).FCTextBox("TxtDividir").Text.ToDouble + + If Cantidad < 0.1 Then + Exit Sub + End If + + Dim dr = TmpDT.Rows(CType(CType(sender, Button).NamingContainer, GridViewRow).RowIndex) + Dim drNuevo = TmpDT.NewRow + + drNuevo.ItemArray = dr.ItemArray + drNuevo("Cantidad") = Cantidad + drNuevo("Total") = drNuevo("Cantidad").ToString.ToEntero * drNuevo("PU").ToString.ToDouble + + dr("Cantidad") = dr("Cantidad").ToString.ToEntero - Cantidad + dr("Total") = dr("Cantidad").ToString.ToEntero * dr("PU").ToString.ToDouble + + TmpDT.Rows.InsertAt(drNuevo, CType(CType(sender, Button).NamingContainer, GridViewRow).RowIndex) + + If TxtOC.Text.Trim <> "" Then + 'If EmpresasOC.Contains(UsuarioActual.CveEmpresa) Then + ' GvOC1.DataSource = TmpDT + ' GvOC1.DataBind() + ' UpGvOC1.Update() + 'Else + GvOC2.DataSource = TmpDT + GvOC2.DataBind() + UpGvOC2.Update() + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + 'End If + Else + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + End If + + CargaGvInv() + + End Sub + Protected Sub BtnAlertaPUCero_Click(sender As Object, e As EventArgs) + Dim Argumentos = HdnAlertaPUCero.Value.Split("|"c) + Dim PS = Argumentos(0) + Dim Cantidad = Argumentos(1) + 'Alert($"El concepto tiene especificada una cantidad pero con costo de cero ($0).
br /<> b > En caso de vincular la OC de esta manera la cantidad especificada sera considerada como recibida.

De ser correcto Continue o de lo contrario rectifique.", TipoMensaje.MsgAdvertencia) + + + Alert($"El concepto {PS} tiene especificada la cantidad {Cantidad} pero un costo de cero ($0).

En caso de vincular la OC de esta manera la cantidad especificada sera considerada como recibida.

De ser correcto Continue o de lo contrario rectifique.", TipoMensaje.MsgAdvertencia) + End Sub +#End Region + +#Region "F L E T E S Y S E R V I C I O S" + + Public Sub CreaDTFacturas() + + Dim dt As New DataTable + + dt.Columns.Add("CveCompra", Type.GetType("System.Int32")) + dt.Columns.Add("Folio", Type.GetType("System.String")) + dt.Columns.Add("Fecha", Type.GetType("System.String")) + + DtFacturas = dt + End Sub + + Public Sub CreaDTServicios() + + Dim dt As New DataTable + + dt.Columns.Add("Total", Type.GetType("System.Double")) + dt.Columns.Add("PS", Type.GetType("System.String")) + dt.Columns.Add("Consec", Type.GetType("System.Int32")) + dt.Columns.Add("CvePS", Type.GetType("System.Int32")) + + DtServicios = dt + End Sub + + + + Protected Sub LbServicios_Click(sender As Object, e As EventArgs) + RegistraScript("$('#DivFletesYServicios').modal();") + CreaDTFacturas() + CreaDTServicios() + + End Sub + + Protected Sub BtnFiltrar_Click(sender As Object, e As EventArgs) + If DdlTipo.SelectedValue.ToEntero = 1 Then + + 'POR SI LLEGARA A TRONAR + If DtServicios Is Nothing Then CreaDTServicios() + DtServicios.Rows.Clear() + + Dim objps As New ClsProductosServicios + Dim dr As DataRow + dvFacturas.Visible = False + GvFacturas.Visible = False + + For Each DrGv As DataRow In TmpDT.Rows + If DrGv("CvePS").ToString.ToEntero > 0 Then + If objps.GetPS(DrGv("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) Then + If objps.DtResultados(0)("CveTipoPS").ToString.ToEntero = 1 Then + dr = DtServicios.NewRow() + dr("Consec") = DrGv("Consec").ToString.ToEntero + dr("Total") = DrGv("Total").ToString.ToDecimal + dr("CvePS") = DrGv("CvePS").ToString.ToEntero + dr("PS") = DrGv("PS").ToString + DtServicios.Rows.Add(dr) + End If + End If + End If + Next + + '[IPP] COMENTADO - MIRAS DE ELIMINAR - 8/FEBRERO/2018 + 'For Each gvr As GridViewRow In GvPS.Rows + ' If objps.GetPS(gvr.DataKey("CvePS").ToEntero, -1, UsuarioActual.CveEmpresa) Then + ' If objps.DtResultados(0)("CveTipoPS").ToString.ToEntero = 1 Then + ' dr = DtServicios.NewRow() + ' dr("Consec") = gvr.FCLabel("LtlConsecutivo").Text.ToEntero + ' dr("Total") = gvr.FCLiteral("LtlTotal").Text.ToDecimal + ' dr("PS") = gvr.DataKey("PS").ToString + ' DtServicios.Rows.Add(dr) + ' End If + ' End If + 'Next + objps.Dispose() + + If DtServicios.Rows.Count > 0 Then + GVServicios.DataSource = DtServicios + GVServicios.DataBind() + GVServicios.Visible = True + Else + GVServicios.DataSource = Nothing + GVServicios.DataBind() + End If + + UpGVServicios.Update() + UpFacturas.Update() + UPGVFacturas.Update() + + ElseIf DdlTipo.SelectedValue.ToEntero = 2 Then + GVServicios.Visible = False + dvFacturas.Visible = True + DdlProveedores.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa) + DdlProveedores.DataBind() + DdlProveedores.Items.Insert(0, New ListItem("Seleccione", "-1")) + UpFacturas.Update() + UpGVServicios.Update() + + + End If + + End Sub + + Public Sub btnAgregarFlete_Click(sender As Object, e As EventArgs) Handles BtnAgregarFlete.Click + + Dim ListaConsecutivas As New List(Of String) 'Almacena los consecutivos que pertenecen al almacen + Dim CostoIndirectoTotal As Decimal = 0 'Suma los costos indirectos calculados + Dim IndiceFila As Integer = 0 'Alamcena la fila actual iterada del TmpDT + Dim IndiceActualizar As Integer = -1 'Almacena el ultimo indice perteneciente a Almacen + + TotalFlete = 0 + TotalAlmacen = 0 + + 'Obtenemos el total del flete y marcamos los conceptos que pertenecen a flete + For Each gvr As GridViewRow In GVServicios.Rows + If gvr.FCCheckBox("chkServicios").Checked Then + Dim Dtr As DataRow = TmpDT.Select($"Consec = {gvr.FCLabel("LblConsec").Text.ToEntero}")(0) + Dtr("AplicaCostoIndirecto") = 1 + TotalFlete += Math.Round(gvr.FCLiteral("LtlTotalmodal").Text.ToDecimal, 2) + End If + Next + + 'Obtenemos el total del almacen y guardamos las consecutivas pertenecientes al mismo + For Each Dr As DataRow In DtInv.Rows + TotalAlmacen += Math.Round(Dr("Total").ToString.ToDecimal, 2) + ListaConsecutivas.Add(Dr("Consec").ToString) + Next + + 'Asignamos los costos indirectos y los indices + For Each Drt As DataRow In TmpDT.Rows + If ListaConsecutivas.Contains(Drt("Consec").ToString) Then + Dim CostoIndirecto As Decimal = CalculaCostoIndirectoFlete(Drt("Total").ToString.ToDecimal) + CostoIndirectoTotal += CostoIndirecto + Drt("CostoIndirectoAlmacen") = CostoIndirecto + Drt("OtrosGastos") = CostoIndirecto + IndiceActualizar = IndiceFila + End If + IndiceFila += 1 + Next + + 'Si los costosindirectos no suman el total exacto del flete ajustamos el ultimo concepto + If CostoIndirectoTotal <> TotalFlete AndAlso IndiceActualizar >= 0 Then + Dim Diferencia = TotalFlete - CostoIndirectoTotal + TmpDT.Rows(IndiceActualizar)("CostoIndirectoAlmacen") = TmpDT.Rows(IndiceActualizar)("CostoIndirectoAlmacen").ToString.ToDouble + Diferencia + TmpDT.Rows(IndiceActualizar)("OtrosGastos") = TmpDT.Rows(IndiceActualizar)("OtrosGastos").ToString.ToDouble + Diferencia + End If + + TmpDT.AcceptChanges() + CargaGvInv() + DdlTipoCompra.SelectedValueExist("8") + UpEstatus.Update() + + ''Marcamos todos los almacenes como check + 'GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True + 'cbAll_CheckedChanged(Nothing, Nothing) + + End Sub + + Private Sub CargaGastosServicios(CvePS As Integer) + 'POR SI LLEGARA A TRONAR + If DtServicios Is Nothing Then CreaDTServicios() + DtServicios.Rows.Clear() + + Dim objps As New ClsProductosServicios + Dim dr As DataRow + dvFacturas.Visible = False + GvFacturas.Visible = False + + For Each DrGv As DataRow In TmpDT.Rows + If DrGv("CvePS").ToString.ToEntero > 0 Then + If objps.GetPS(DrGv("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) Then + If objps.DtResultados IsNot Nothing AndAlso objps.DtResultados.Rows.Count > 0 AndAlso objps.DtResultados(0)("CveTipoPS").ToString.ToEntero = 1 Then + dr = DtServicios.NewRow() + dr("Consec") = DrGv("Consec").ToString.ToEntero + dr("Total") = DrGv("Total").ToString.ToDecimal + dr("CvePS") = DrGv("CvePS").ToString.ToEntero + dr("PS") = DrGv("PS").ToString + DtServicios.Rows.Add(dr) + End If + End If + End If + Next + + '[IPP] COMENTADO - MIRAS DE ELIMINAR - 8/FEBRERO/2018 + 'For Each gvr As GridViewRow In GvPS.Rows + ' If objps.GetPS(gvr.DataKey("CvePS").ToEntero, -1, UsuarioActual.CveEmpresa) Then + ' If objps.DtResultados(0)("CveTipoPS").ToString.ToEntero = 1 Then + ' dr = DtServicios.NewRow() + ' dr("Consec") = gvr.FCLabel("LtlConsecutivo").Text.ToEntero + ' dr("Total") = gvr.FCLiteral("LtlTotal").Text.ToDecimal + ' dr("PS") = gvr.DataKey("PS").ToString + ' DtServicios.Rows.Add(dr) + ' End If + ' End If + 'Next + objps.Dispose() + + If DtServicios.Rows.Count > 0 Then + GVServicios.DataSource = DtServicios + GVServicios.DataBind() + GVServicios.Visible = True + Else + GVServicios.DataSource = Nothing + GVServicios.DataBind() + End If + + UpGVServicios.Update() + UpFacturas.Update() + UPGVFacturas.Update() + + + Dim ListaConsecutivas As New List(Of String) 'Almacena los consecutivos que pertenecen al almacen + Dim CostoIndirectoTotal As Decimal = 0 'Suma los costos indirectos calculados + Dim IndiceFila As Integer = 0 'Alamcena la fila actual iterada del TmpDT + Dim IndiceActualizar As Integer = -1 'Almacena el ultimo indice perteneciente a Almacen + + TotalFlete = 0 + TotalAlmacen = 0 + + If DtInv IsNot Nothing Then + 'Obtenemos el total del almacen y guardamos las consecutivas pertenecientes al mismo + For Each Dr2 As DataRow In DtInv.Rows + TotalAlmacen += Math.Round(Dr2("Total").ToString.ToDecimal, 2) + ListaConsecutivas.Add(Dr2("Consec").ToString) + Next + End If + + 'sino hay producto en almacen para aplciarle un servicio, no se debe de amrcar como costo indirecto + 'esto aplica cuando la factura solo trae un concepto, y es el de servicio + If TotalAlmacen = 0 Then Exit Sub + + 'Obtenemos el total del flete y marcamos los conceptos que pertenecen a flete + For Each gvr As GridViewRow In GVServicios.Rows + If gvr.DataKey("CvePS").ToEntero = CvePS Or gvr.FCCheckBox("chkServicios").Checked Then + Dim Dtr As DataRow = TmpDT.Select($"Consec = {gvr.FCLabel("LblConsec").Text.ToEntero}")(0) + Dtr("AplicaCostoIndirecto") = 1 + TotalFlete += Math.Round(gvr.FCLiteral("LtlTotalmodal").Text.ToDecimal, 2) + gvr.FCCheckBox("chkServicios").Checked = True + End If + Next + UpGVServicios.Update() + + + If Not TotalFlete > 0 Then Exit Sub + + + 'Asignamos los costos indirectos y los indices + For Each Drt As DataRow In TmpDT.Rows + If ListaConsecutivas.Contains(Drt("Consec").ToString) Then + Dim CostoIndirecto As Decimal = CalculaCostoIndirectoFlete(Drt("Total").ToString.ToDecimal) + CostoIndirectoTotal += CostoIndirecto + Drt("CostoIndirectoAlmacen") = CostoIndirecto + Drt("OtrosGastos") = CostoIndirecto + IndiceActualizar = IndiceFila + End If + IndiceFila += 1 + Next + + 'Si los costosindirectos no suman el total exacto del flete ajustamos el ultimo concepto + If CostoIndirectoTotal <> TotalFlete AndAlso IndiceActualizar >= 0 Then + Dim Diferencia = TotalFlete - CostoIndirectoTotal + TmpDT.Rows(IndiceActualizar)("CostoIndirectoAlmacen") = TmpDT.Rows(IndiceActualizar)("CostoIndirectoAlmacen").ToString.ToDouble + Diferencia + TmpDT.Rows(IndiceActualizar)("OtrosGastos") = TmpDT.Rows(IndiceActualizar)("OtrosGastos").ToString.ToDouble + Diferencia + End If + + TmpDT.AcceptChanges() + CargaGvInv() + DdlTipoCompra.SelectedValueExist("8") + UpEstatus.Update() + + ''Marcamos todos los almacenes como check + 'GvInv.HeaderRow.FCCheckBox("cbAll").Checked = True + 'cbAll_CheckedChanged(Nothing, Nothing) + End Sub + + + Protected Sub GVServicios_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVServicios.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + Dim TmpDr As DataRow = TmpDT.Select($"Consec = {e.Row.FCLabel("LblConsec").Text}")(0) + If TmpDr("AplicaCostoIndirecto").ToString = "1" Then + e.Row.FCCheckBox("chkServicios").Checked = True + e.Row.FCCheckBox("chkServicios").Enabled = Not CveCompra > 0 + End If + End If + End Sub + + Private Function CalculaCostoIndirectoFlete(ImporteAlmacen As Decimal) As Decimal + Dim CostoIndirecto As Decimal + CostoIndirecto = (ImporteAlmacen * TotalFlete) / TotalAlmacen + Return Math.Round(CostoIndirecto, 2) + End Function + + Protected Sub BtnAgregaFactura_Click(sender As Object, e As EventArgs) + Dim ObjComp As New ClsCompras + If ObjComp.GetCompras(DdlFacturas.SelectedValue.ToEntero, "-1", DdlFacturas.SelectedItem.ToString, -1, -1, 1) Then + + Dim dr As DataRow = DtFacturas.NewRow() + dr("CveCompra") = ObjComp.DtResultados(0)("CveCompra").ToString + dr("Folio") = ObjComp.DtResultados(0)("Folio").ToString + dr("Fecha") = ObjComp.DtResultados(0)("Fecha").ToString.ToDate.ToString("dd/MM/yyyy") + DtFacturas.Rows.Add(dr) + + If GvFacturas.Visible = False Then + GvFacturas.Visible = True + End If + + GvFacturas.DataSource = DtFacturas + GvFacturas.DataBind() + + Else + Alert("No se encontró la factura", TipoMensaje.MsgAdvertencia) + End If + + UPGVFacturas.Update() + ObjComp.Dispose() + End Sub + + Protected Sub DdlProveedores_SelectedIndexChanged(sender As Object, e As EventArgs) + CargarFacturas() + End Sub + + Private Sub CargarFacturas() + Dim objCompras As New ClsCompras + If objCompras.GetCompras(-1, "-1", "-1", DdlProveedores.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) Then + DdlFacturas.DataSource = objCompras.DtResultados + Else + DdlFacturas.DataSource = Nothing + Alert("No se encontraron folios con el proveedor seleccionado.", TipoMensaje.MsgAdvertencia) + End If + DdlFacturas.DataBind() + DdlFacturas.Items.Insert(0, New ListItem("Seleccione", "-1")) + + objCompras.Dispose() + End Sub + + Protected Sub GvFacturas_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvFacturas.RowDeleting + + DtFacturas.Rows.RemoveAt(e.RowIndex) + GvFacturas.DataSource = DtFacturas + GvFacturas.DataBind() + UPGVFacturas.Update() + UpFacturas.Update() + + + + End Sub + + Public Sub ValidaFletesServicios() + + If Not UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then + dvFacturas.Visible = False + GvFacturas.Visible = False + GVServicios.Visible = False + End If + + If UsuarioActual.Empresa.UsaInventarios And UsuarioActual.Empresa.CvePlataforma <> 2 Then + liServicios.Visible = True + liFletesImportaciones.Visible = True + End If + + End Sub + + Public Function AplicarCostoIndirecto(ObjInv As ClsInventarios, ObjCompras As ClsCompras) As Boolean + Return False + + Dim HayError As Boolean + + Dim dtTemporal As New DataTable + dtTemporal = Nothing + + If GvFacturas.Visible AndAlso GvFacturas.Rows.Count > 0 Then + + Dim IdCompras = New List(Of Integer) + Dim TotalServicios As Decimal = 0 + + TotalServicios = TxtSubTotal.Text.ToString.ToDecimal + If TotalServicios > 0 Then + + For Each row As GridViewRow In GvFacturas.Rows + IdCompras.Add(row.DataKey("CveCompra").ToEntero) + Next + For Each value As Integer In IdCompras + If ObjInv.GetMovimientosDetalle(-1, UsuarioActual.CveEmpresa, value) AndAlso ObjInv.DtResultados.Rows.Count > 0 Then + If dtTemporal Is Nothing Then + dtTemporal = ObjInv.DtResultados + Else + dtTemporal.Merge(ObjInv.DtResultados) + End If + End If + Next + + 'Dim DtProductos As New DataTable + ' DtProductos = ObjInv.DtResultados.DefaultView.ToTable(True, "CveMovimiento", "CvePS", "Cantidad", "PU", "Total") + 'Dim total As Decimal = 0 + 'For Each row As DataRow In DtProductos.Rows + ' total = total + row("Total").ToString.ToDecimal + 'Next + 'If total > 0 Then + + If dtTemporal IsNot Nothing Then + Dim TotalFacturas = dtTemporal.SUM("Total").ToString.ToDecimal + For Each row As DataRow In dtTemporal.Rows + Dim prorrateo As Decimal + prorrateo = (row("PU").ToString.ToDecimal * TotalServicios) / TotalFacturas + If Not ObjInv.UpdateCostoIndirectoMovimientoDetalle(row("CveMovimientoDetalle").ToString.ToEntero, prorrateo) Then + HayError = True + Exit For + + End If + Next + End If + Else + Alert("El total de los servicios a vincular debe ser mayor a $0.00", TipoMensaje.MsgError) + Return True + End If + + ElseIf GVServicios.Visible AndAlso GVServicios.Rows.Count > 0 Then + + Dim Dtcompra As New DataTable + Dim TotalServicios As Decimal = 0 + + Dim chk As Boolean = False + For Each gvr As GridViewRow In GVServicios.Rows + If gvr.FCCheckBox("chkServicios").Checked Then + TotalServicios += gvr.FCLiteral("LtlTotalmodal").Text.ToDecimal + chk = True + End If + Next + + If chk = False Then + Alert("Debe Seleccionar un Servicio", TipoMensaje.MsgInformacion) + Return False + Else + + If ObjCompras.GetCompraDetalle(CveCompra) Then + If ObjInv.GetMovimientosDetalle(-1, UsuarioActual.CveEmpresa, CveCompra) Then + Dtcompra = ObjInv.DtResultados + Dim TotalProductos = Dtcompra.SUM("Total").ToString.ToDecimal + If TotalProductos > 0 Then + For Each row As DataRow In Dtcompra.Rows + Dim prorrateo As Decimal + prorrateo = (row("PU").ToString.ToDecimal * TotalServicios) / TotalProductos + If Not ObjInv.UpdateCostoIndirectoMovimientoDetalle(row("CveMovimientoDetalle").ToString.ToEntero, prorrateo) Then + HayError = True + Exit For + + End If + Next + Else + Alert("No existen productos de inventario en esta factura", TipoMensaje.MsgError) + End If + End If + End If + + End If + Else + Return False + End If + + If HayError = True And ObjInv IsNot Nothing Then + Alert("Ocurrió un error al vincular un flete o servicio") + HayError = True + End If + + Return HayError + End Function + + Protected Sub BtnCancelar_Click(sender As Object, e As EventArgs) + 'dvFacturas.Visible = False + 'GvFacturas.Visible = False + 'GVServicios.Visible = False + 'UpFacturas.Update() + 'UPGVFacturas.Update() + 'UpGVServicios.Update() + End Sub + + Protected Sub DdlTipoComprobante_SelectedIndexChanged(sender As Object, e As EventArgs) + If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV", "Ant") Then + If DdlTipoComprobante.SelectedValue = "NC" Then + DivReembolso.Visible = False + RBLPago.Items(2).Enabled = False + Else + DivReembolso.Visible = True + RBLPago.Items(2).Enabled = True + End If + ImgAnticiposPendientes.Visible = False If DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then paneldevolucion.Visible = True Pnlalmaceninventarios.Visible = False @@ -15919,216 +16057,216 @@ Partial Class Compras_Compras RBLPago.Items(2).Enabled = False UpPS.Update() - End If - End If - UPCondicionesPago.Update() + End If + End If + UPCondicionesPago.Update() End Sub -#Region " ENVIA CORREO NOTICIACION - VENDEDOR " - Private Sub MandaCorreoOCVendedores(CveCompra As Integer) - - 'SI NO TIENE FUNCIONALIDAD DATOS DE VENTA EN OC - If Not UsuarioActual.Empresa.Funcionalidad(108) = "1" Then - Exit Sub - End If - - Dim DTCorreos As New DataTable - Dim DTMovimientos As New DataTable - Dim strBody As New StringBuilder - Dim Asunto, Para, ArrayCC, Body As String - - Dim ObjOC As New ClsOC - ObjOC.GetOrdenesCompraCorreo(CveCompra) - DTCorreos = ObjOC.DtResultados - ObjOC.GetOrdenesCompraMovimiento(CveCompra) - DTMovimientos = ObjOC.DtResultados - ObjOC.Dispose() - - - For Each row As DataRow In DTCorreos.Rows - - strBody.Clear() - - 'SI DE UNA OC DE LA COMPRA NO SE RECIBIÓ NADA NO MANDA CORREO - If DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows.Count = 0 Then - Continue For - End If - - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append("") - strBody.Append("

Vinculación de orden de compra a factura

") - strBody.Append("

") - strBody.AppendFormat(" Se ha vinculado la OC # {0} {1}.", row("Folio"), If(row("FolioREQ").ToString.Length > 0, $", relacionada a la(s) requisicion(es) # {row("FolioREQ")}", "")) - strBody.Append("
") - strBody.Append(" Con los siguientes productos:") - strBody.Append("

") - - 'DETALLES - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - - For Each RowM As DataRow In DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows - strBody.AppendFormat(" ") - strBody.AppendFormat(" ", RowM("Cantidad").ToString.FormatoNumero) - strBody.AppendFormat(" ", RowM("UnidadMedida")) - strBody.AppendFormat(" ", RowM("Codigo")) - strBody.AppendFormat(" ", RowM("PS")) - strBody.AppendFormat(" ") - Next - - strBody.Append("
CantidadUMCódigoProducto
{0}{0}{0}{0}
") - strBody.Append("") - strBody.Append("") - - - '' ENVIO DEL CORREO - Asunto = "Vinculación de factura de OC " - Para = row("Correo").ToString - ArrayCC = "" - Body = strBody.ToString - Dim Mail As New ClsSisMail() - Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, ArrayCC) - Next - - - End Sub - Private Sub MandaCorreoOCVendedoresRecepcionAlmacen(CveCompra As Integer, CveMovimiento As Integer) - - - 'SI NO TIENE FUNCIONALIDAD DATOS DE VENTA EN OC - If Not UsuarioActual.Empresa.Funcionalidad(108) = "1" Then - Exit Sub - End If - - Dim DTCorreos As New DataTable - Dim DTMovimientos As New DataTable - Dim strBody As New StringBuilder - Dim Asunto, Para, ArrayCC, Body As String - - Dim ObjOC As New ClsOC - ObjOC.GetOrdenesCompraCorreo(CveCompra, CveMovimiento:=CveMovimiento) - DTCorreos = ObjOC.DtResultados - ObjOC.GetOrdenesCompraMovimiento(CveCompra, CveMovimiento:=CveMovimiento) - DTMovimientos = ObjOC.DtResultados - ObjOC.Dispose() - - - For Each row As DataRow In DTCorreos.Rows - - strBody.Clear() - - 'SI DE UNA OC DE LA COMPRA NO SE RECIBIÓ NADA NO MANDA CORREO - If DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows.Count = 0 Then - Continue For - End If - - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append("") - strBody.Append("

Notificación de recepción de material

") - strBody.Append("

") - strBody.AppendFormat(" Se confirma recepción de material en almacén {0} vinculado la OC # {1} {2}.", DTMovimientos.FiltroPrimeroValor("Almacen"), row("Folio").ToString, If(row("FolioREQ").ToString.Length > 0, $", relacionada a la(s) requisicion(es) # {row("FolioREQ")}", "")) - strBody.Append("
") - strBody.Append(" Con los siguientes productos:") - strBody.Append("

") - - 'DETALLES - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - strBody.Append(" ") - - For Each RowM As DataRow In DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows - strBody.AppendFormat(" ") - strBody.AppendFormat(" ", RowM("Cantidad").ToString.FormatoNumero) - strBody.AppendFormat(" ", RowM("UnidadMedida")) - strBody.AppendFormat(" ", RowM("Codigo")) - strBody.AppendFormat(" ", RowM("PS")) - strBody.AppendFormat(" ") - Next - - strBody.Append("
CantidadUMCódigoProducto
{0}{0}{0}{0}
") - strBody.Append("") - strBody.Append("") - - '' ENVIO DEL CORREO - Asunto = "Recepción de Material de OC " - Para = row("Correo").ToString - ArrayCC = row("CorreoAsistente").ToString - Body = strBody.ToString - Dim Mail As New ClsSisMail() - Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, ArrayCC) - Next - - +#Region " ENVIA CORREO NOTICIACION - VENDEDOR " + Private Sub MandaCorreoOCVendedores(CveCompra As Integer) + + 'SI NO TIENE FUNCIONALIDAD DATOS DE VENTA EN OC + If Not UsuarioActual.Empresa.Funcionalidad(108) = "1" Then + Exit Sub + End If + + Dim DTCorreos As New DataTable + Dim DTMovimientos As New DataTable + Dim strBody As New StringBuilder + Dim Asunto, Para, ArrayCC, Body As String + + Dim ObjOC As New ClsOC + ObjOC.GetOrdenesCompraCorreo(CveCompra) + DTCorreos = ObjOC.DtResultados + ObjOC.GetOrdenesCompraMovimiento(CveCompra) + DTMovimientos = ObjOC.DtResultados + ObjOC.Dispose() + + + For Each row As DataRow In DTCorreos.Rows + + strBody.Clear() + + 'SI DE UNA OC DE LA COMPRA NO SE RECIBIÓ NADA NO MANDA CORREO + If DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows.Count = 0 Then + Continue For + End If + + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append("") + strBody.Append("

Vinculación de orden de compra a factura

") + strBody.Append("

") + strBody.AppendFormat(" Se ha vinculado la OC # {0} {1}.", row("Folio"), If(row("FolioREQ").ToString.Length > 0, $", relacionada a la(s) requisicion(es) # {row("FolioREQ")}", "")) + strBody.Append("
") + strBody.Append(" Con los siguientes productos:") + strBody.Append("

") + + 'DETALLES + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + + For Each RowM As DataRow In DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", RowM("Cantidad").ToString.FormatoNumero) + strBody.AppendFormat(" ", RowM("UnidadMedida")) + strBody.AppendFormat(" ", RowM("Codigo")) + strBody.AppendFormat(" ", RowM("PS")) + strBody.AppendFormat(" ") + Next + + strBody.Append("
CantidadUMCódigoProducto
{0}{0}{0}{0}
") + strBody.Append("") + strBody.Append("") + + + '' ENVIO DEL CORREO + Asunto = "Vinculación de factura de OC " + Para = row("Correo").ToString + ArrayCC = "" + Body = strBody.ToString + Dim Mail As New ClsSisMail() + Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, ArrayCC) + Next + + + End Sub + Private Sub MandaCorreoOCVendedoresRecepcionAlmacen(CveCompra As Integer, CveMovimiento As Integer) + + + 'SI NO TIENE FUNCIONALIDAD DATOS DE VENTA EN OC + If Not UsuarioActual.Empresa.Funcionalidad(108) = "1" Then + Exit Sub + End If + + Dim DTCorreos As New DataTable + Dim DTMovimientos As New DataTable + Dim strBody As New StringBuilder + Dim Asunto, Para, ArrayCC, Body As String + + Dim ObjOC As New ClsOC + ObjOC.GetOrdenesCompraCorreo(CveCompra, CveMovimiento:=CveMovimiento) + DTCorreos = ObjOC.DtResultados + ObjOC.GetOrdenesCompraMovimiento(CveCompra, CveMovimiento:=CveMovimiento) + DTMovimientos = ObjOC.DtResultados + ObjOC.Dispose() + + + For Each row As DataRow In DTCorreos.Rows + + strBody.Clear() + + 'SI DE UNA OC DE LA COMPRA NO SE RECIBIÓ NADA NO MANDA CORREO + If DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows.Count = 0 Then + Continue For + End If + + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append("") + strBody.Append("

Notificación de recepción de material

") + strBody.Append("

") + strBody.AppendFormat(" Se confirma recepción de material en almacén {0} vinculado la OC # {1} {2}.", DTMovimientos.FiltroPrimeroValor("Almacen"), row("Folio").ToString, If(row("FolioREQ").ToString.Length > 0, $", relacionada a la(s) requisicion(es) # {row("FolioREQ")}", "")) + strBody.Append("
") + strBody.Append(" Con los siguientes productos:") + strBody.Append("

") + + 'DETALLES + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + + For Each RowM As DataRow In DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", RowM("Cantidad").ToString.FormatoNumero) + strBody.AppendFormat(" ", RowM("UnidadMedida")) + strBody.AppendFormat(" ", RowM("Codigo")) + strBody.AppendFormat(" ", RowM("PS")) + strBody.AppendFormat(" ") + Next + + strBody.Append("
CantidadUMCódigoProducto
{0}{0}{0}{0}
") + strBody.Append("") + strBody.Append("") + + '' ENVIO DEL CORREO + Asunto = "Recepción de Material de OC " + Para = row("Correo").ToString + ArrayCC = row("CorreoAsistente").ToString + Body = strBody.ToString + Dim Mail As New ClsSisMail() + Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, ArrayCC) + Next + + End Sub 'VIEJO - COMENTADO IPP 12 JULIO 2017 @@ -16182,1485 +16320,1485 @@ Partial Class Compras_Compras ' Next 'End Sub -#End Region +#End Region -#End Region +#End Region -#Region " CIERRE PERIODO " - Private Function ValidaCierrePeriodo() As Boolean - 'solo se permiten, mes actual, mes anterior <= #dias - Dim mesesTrans As Integer = DateDiff(DateInterval.Month, TxtFecha.Text.ToDate, Now).ToEntero - - If mesesTrans = 0 OrElse (mesesTrans = 1 AndAlso Day(Now) <= UsuarioActual.Empresa.Funcionalidad(123).ToEntero) Then - Return True - End If - Return False - - 'Dim mesesTrans As Integer = DateDiff(DateInterval.Month, TxtFecha.Text.ToDate, Now).ToEntero - 'If mesesTrans > 1 OrElse Day(Now) >= UsuarioActual.Empresa.Funcionalidad(123).ToEntero Then - ' Return True - 'End If - 'Return False +#Region " CIERRE PERIODO " + Private Function ValidaCierrePeriodo() As Boolean + 'solo se permiten, mes actual, mes anterior <= #dias + Dim mesesTrans As Integer = DateDiff(DateInterval.Month, TxtFecha.Text.ToDate, Now).ToEntero + + If mesesTrans = 0 OrElse (mesesTrans = 1 AndAlso Day(Now) <= UsuarioActual.Empresa.Funcionalidad(123).ToEntero) Then + Return True + End If + Return False + + 'Dim mesesTrans As Integer = DateDiff(DateInterval.Month, TxtFecha.Text.ToDate, Now).ToEntero + 'If mesesTrans > 1 OrElse Day(Now) >= UsuarioActual.Empresa.Funcionalidad(123).ToEntero Then + ' Return True + 'End If + 'Return False End Function -#End Region +#End Region -#Region " AGREGA POR SERIE/LOTE " - Private Sub CreaDtDetalle() - If DtDatosDetalle Is Nothing Then - DtDatosDetalle = New DataTable - DtDatosDetalle.Columns.Add("CvePS", GetType(Integer)) - DtDatosDetalle.Columns.Add("CveUM", GetType(Integer)) - DtDatosDetalle.Columns.Add("PU", GetType(Decimal)) - DtDatosDetalle.Columns.Add("Serie", GetType(String)) - DtDatosDetalle.Columns.Add("FechaCaducidad", GetType(String)) - DtDatosDetalle.Columns.Add("CvePersonal", GetType(Integer)) - End If - End Sub - Private Sub CargaSerie() - - Dim AplicaCaducidad = False - If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerieLote).Rows(0) IsNot Nothing Then - AplicaCaducidad = If(GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerieLote).Rows(0)("AplicaCaducidad").ToString = "True", True, False) - End If - - If AplicaCaducidad Then - GvSerie.Columns(1).Visible = True - TdCaducidad1.Visible = True - TdCaducidad2.Visible = True - Else - GvSerie.Columns(1).Visible = False - TdCaducidad1.Visible = False - TdCaducidad2.Visible = False - End If - - GvSerie.DataSource = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", CvePSSerieLote)) - GvSerie.DataBind() - - 'VALIDA QUE SIGA AGREGANDO - If Not DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", CvePSSerieLote)).Rows.Count < LbCantidadSerie.Text.ToEntero Then - BtnAgregarPS.Enabled = False - Else - BtnAgregarPS.Enabled = True - End If - - 'SI TIENE ENTRADA POR SERIE LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD - Dim Contador = 0 - For Each Gvr As GridViewRow In GvInv.Rows - Gvr.FCTextBox("TbCantidad").Enabled = False - If Gvr.DataKey("CvePS").ToEntero = CvePSSerieLote Then - Contador = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", Gvr.DataKey("CvePS"))).Rows.Count - If DtDatosDetalle IsNot Nothing AndAlso Contador > 0 Then - Gvr.FCCheckBox("cbInv").Enabled = False - 'Gvr.FCCheckBox("cbInv").Checked = True - Gvr.FCTextBox("TbCantidad").Enabled = False - Gvr.FCTextBox("TbCantidad").Text = Contador.ToString - Else - Gvr.FCCheckBox("cbInv").Enabled = False - Gvr.FCTextBox("TbCantidad").Enabled = False - Gvr.FCTextBox("TbCantidad").Text = "0" - End If - End If - Next - - UpINV.Update() - UpSerie.Update() - TxtSerieLote.Focus() - RegistraScript(String.Format("$('#DivSerie').on('shown.bs.modal', function () {{$('#DivSerie').focus(); $('#{0}').trigger(jQuery.Event('keypress', {{which: 13}})); }});$('#DivSerie').modal('show'); ", TxtSerieLote.ClientID)) - - End Sub - Protected Sub BtnAgregarPS_Click(sender As Object, e As EventArgs) - Dim SerieLote = TxtSerieLote.Text.Replace(" ", String.Empty) - Dim AplicaCaducidad = False - Dim dr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerieLote).FiltroPrimero("", "PS") - If dr IsNot Nothing Then AplicaCaducidad = dr("AplicaCaducidad").ToString = "True" - - 'VALIDA QUE LA SERIE NO SEA IGUAL AL CODIGO O CODIGOBARRAS - If SerieLote <> "" And (SerieLote = dr("Codigo").ToString.ToUpper Or SerieLote = dr("CodigoBarras").ToString.ToUpper) Then - Alert($"La serie indicada {SerieLote} coincide con el codigo o codigo de barras del producto. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - Dim Row = DtDatosDetalle.NewRow - Row("CvePS") = CvePSSerieLote - Row("CveUM") = CveUMSerieLote - Row("PU") = PUSerieLote - Row("Serie") = SerieLote - Row("FechaCaducidad") = If(AplicaCaducidad, TxtFechaCaducidad.Text, MinFecha.ToShortDateString) - DtDatosDetalle.Rows.Add(Row) - - TxtSerieLote.Text = "" - TxtFechaCaducidad.Text = Now.ToShortDateString - - CargaSerie() - End Sub - Protected Sub BtnSerieLote_Click(sender As Object, e As EventArgs) - - Dim Argumentos = CType(sender, Button).CommandArgument.Split("°"c) - - LbProducto.Text = Argumentos(3) - LbCantidadSerie.Text = Argumentos(4) - - CvePSSerieLote = Argumentos(0).ToEntero - CveUMSerieLote = Argumentos(1).ToEntero - PUSerieLote = Argumentos(2).ToDecimal - - - CargaSerie() - End Sub - Protected Sub GvSerie_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvSerie.RowDeleting - DtDatosDetalle.Rows.Remove(DtDatosDetalle.Rows(e.RowIndex)) - CargaSerie() +#Region " AGREGA POR SERIE/LOTE " + Private Sub CreaDtDetalle() + If DtDatosDetalle Is Nothing Then + DtDatosDetalle = New DataTable + DtDatosDetalle.Columns.Add("CvePS", GetType(Integer)) + DtDatosDetalle.Columns.Add("CveUM", GetType(Integer)) + DtDatosDetalle.Columns.Add("PU", GetType(Decimal)) + DtDatosDetalle.Columns.Add("Serie", GetType(String)) + DtDatosDetalle.Columns.Add("FechaCaducidad", GetType(String)) + DtDatosDetalle.Columns.Add("CvePersonal", GetType(Integer)) + End If End Sub -#End Region + Private Sub CargaSerie() + + Dim AplicaCaducidad = False + If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerieLote).Rows(0) IsNot Nothing Then + AplicaCaducidad = If(GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerieLote).Rows(0)("AplicaCaducidad").ToString = "True", True, False) + End If + + If AplicaCaducidad Then + GvSerie.Columns(1).Visible = True + TdCaducidad1.Visible = True + TdCaducidad2.Visible = True + Else + GvSerie.Columns(1).Visible = False + TdCaducidad1.Visible = False + TdCaducidad2.Visible = False + End If + + GvSerie.DataSource = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", CvePSSerieLote)) + GvSerie.DataBind() + + 'VALIDA QUE SIGA AGREGANDO + If Not DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", CvePSSerieLote)).Rows.Count < LbCantidadSerie.Text.ToEntero Then + BtnAgregarPS.Enabled = False + Else + BtnAgregarPS.Enabled = True + End If + + 'SI TIENE ENTRADA POR SERIE LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD + Dim Contador = 0 + For Each Gvr As GridViewRow In GvInv.Rows + Gvr.FCTextBox("TbCantidad").Enabled = False + If Gvr.DataKey("CvePS").ToEntero = CvePSSerieLote Then + Contador = DtDatosDetalle.FiltraParametros(String.Format("CvePS = {0}", Gvr.DataKey("CvePS"))).Rows.Count + If DtDatosDetalle IsNot Nothing AndAlso Contador > 0 Then + Gvr.FCCheckBox("cbInv").Enabled = False + 'Gvr.FCCheckBox("cbInv").Checked = True + Gvr.FCTextBox("TbCantidad").Enabled = False + Gvr.FCTextBox("TbCantidad").Text = Contador.ToString + Else + Gvr.FCCheckBox("cbInv").Enabled = False + Gvr.FCTextBox("TbCantidad").Enabled = False + Gvr.FCTextBox("TbCantidad").Text = "0" + End If + End If + Next + + UpINV.Update() + UpSerie.Update() + TxtSerieLote.Focus() + RegistraScript(String.Format("$('#DivSerie').on('shown.bs.modal', function () {{$('#DivSerie').focus(); $('#{0}').trigger(jQuery.Event('keypress', {{which: 13}})); }});$('#DivSerie').modal('show'); ", TxtSerieLote.ClientID)) -#Region " TIPO CAMBIO " - Protected Sub DdlMoneda_SelectedIndexChanged(sender As Object, e As EventArgs) - CambiaMoneda() - End Sub - Private Sub CambiaMoneda(Optional RecargaTipoCambio As Boolean = True) - TxtFecha.Attributes.Remove("onblur") - - If DdlMoneda.SelectedValue.ToEntero > 1 Then - TipoCambio = If(RecargaTipoCambio, GlobalTipoCambio(TxtFecha.Text.ToDate), TipoCambio) - LblTC.Text = String.Format("TC: {0}", TipoCambio.ToString("N4")) - TxtTC.Text = TipoCambio.ToString("N4") - If UsuarioActual.Empresa.UsaAC Then - TxtFecha.Attributes.Add("onblur", "CambiaFecha();CambiaFechaTC();") - Else - TxtFecha.Attributes.Add("onblur", "CambiaFechaTC();") - End If - - If CveCompra <= 0 Then 'And CveFactura <= 0 [IPP] 11Junio2018 - DivTC.Visible = True - LblTC.Visible = False - Else - DivTC.Visible = False - LblTC.Visible = True - End If - - Else - - If UsuarioActual.CveEmpresa.Contiene({4, 7, 11, 12, 145}) Then - RegistraScript("$('#ModalPesos').modal('show');") - TxtConvertirPesos.Text = If(TipoCambio > 0, TipoCambio, GlobalTipoCambio(TxtFecha.Text.ToDate)).ToString.FormatoNumero - End If - - TipoCambio = 1 - LblTC.Text = "" - TxtTC.Text = "" - If UsuarioActual.Empresa.UsaAC Then - TxtFecha.Attributes.Add("onblur", "CambiaFecha()") - End If - End If - - CargaCuentas() - End Sub - Protected Sub BtnCambiaFechaTC_Click(sender As Object, e As EventArgs) - LblTC.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString.FormatoNumero(4) - TxtTC.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString.FormatoNumero(4) End Sub -#End Region + Protected Sub BtnAgregarPS_Click(sender As Object, e As EventArgs) + Dim SerieLote = TxtSerieLote.Text.Replace(" ", String.Empty) + Dim AplicaCaducidad = False + Dim dr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerieLote).FiltroPrimero("", "PS") + If dr IsNot Nothing Then AplicaCaducidad = dr("AplicaCaducidad").ToString = "True" -#Region " CONVERTIR PESOS " - Protected Sub BtnConvertirPesos_Click(sender As Object, e As EventArgs) - Dim TipoCambioTemp = TxtConvertirPesos.Text.ToDouble - - If TipoCambioTemp <= 0 Then - Exit Sub - End If - - For Each Dr As DataRow In TmpDT.Rows - Dr("PU") = Dr("PU").ToString.ToDecimal * TipoCambioTemp - Dr("IVA") = Dr("IVA").ToString.ToDecimal * TipoCambioTemp - Dr("RetIVA") = Dr("RetIVA").ToString.ToDecimal * TipoCambioTemp - Dr("RetISR") = Dr("RetISR").ToString.ToDecimal * TipoCambioTemp - Dr("IEPSPS") = Dr("IEPSPS").ToString.ToDecimal * TipoCambioTemp - Dr("Descuento") = Dr("Descuento").ToString.ToDecimal * TipoCambioTemp - Dr("OtrosGastos") = Dr("OtrosGastos").ToString.ToDecimal * TipoCambioTemp - - Dim Total = (Dr("Cantidad").ToString.ToDecimal * Dr("PU").ToString.ToDecimal) - Dr("Descuento").ToString.ToDecimal + Dr("OtrosGastos").ToString.ToDecimal - Dr("Total") = Total - Next - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - - TxtSubTotal.Text = (TmpDT.SUMD("Total") + TmpDT.SUMD("Descuento")).FormatoNumero - TxtSubTotal2.Text = TmpDT.SUMD("Total").FormatoNumero() - TxtIVA.Text = TmpDT.SUMD("IVA").FormatoNumero() - - 'IPP CAMBIADO - 5 DICIEMBRE 2016 - 'TxtTotal.Text = (TxtSubTotal2.Text.ToDouble + TxtIVA.Text.ToDouble).ToString.FormatoNumero.Replace(","c, "") - TxtTotal.Text = (TmpDT.SUMD("Total") + TmpDT.SUMD("IVA") + TmpDT.SUMD("IEPSPS") - TmpDT.SUMD("RetIVA") - TmpDT.SUMD("RetISR")).FormatoNumero - - - SubTotalOriginal = TxtSubTotal.Text.ToDouble - SubTotal2Original = TxtSubTotal2.Text.ToDouble - - If TrDescuento.Visible Then TxtDescuento.Text = (TmpDT.SUMD("Descuento")).ToString.FormatoNumero - If TrRetIVA.Visible Then TxtRetIVA.Text = (TmpDT.SUMD("RetIVA")).ToString.FormatoNumero - If TrRetISR.Visible Then TxtRetISR.Text = (TmpDT.SUMD("RetISR")).ToString.FormatoNumero - If TrIEPS.Visible Then TxtIEPS.Text = (TmpDT.SUMD("IEPSPS")).ToString.FormatoNumero - If TrOtrosImpuestos.Visible Then TxtOtrosImpuestos.Text = (TmpDT.SUMD("OtrosGastos")).ToString.FormatoNumero - If TrRedondeo.Visible Then TxtRedondeo.Text = (TxtRedondeo.Text.ToDouble * TipoCambioTemp).ToString.FormatoNumero.Replace(","c, "") - - - If TxtSubTotal2.Text.ToDouble <> TmpDT.SUM("Total") Then - AjustaImporteUltimoConcepto((TxtSubTotal2.Text.ToDouble - TmpDT.SUM("Total")).ToString.ToDecimal) - End If - - DdlMoneda.Enabled = False - RegistraScript("$('#ModalPesos').modal('hide');") + 'VALIDA QUE LA SERIE NO SEA IGUAL AL CODIGO O CODIGOBARRAS + If SerieLote <> "" And (SerieLote = dr("Codigo").ToString.ToUpper Or SerieLote = dr("CodigoBarras").ToString.ToUpper) Then + Alert($"La serie indicada {SerieLote} coincide con el codigo o codigo de barras del producto. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + Dim Row = DtDatosDetalle.NewRow + Row("CvePS") = CvePSSerieLote + Row("CveUM") = CveUMSerieLote + Row("PU") = PUSerieLote + Row("Serie") = SerieLote + Row("FechaCaducidad") = If(AplicaCaducidad, TxtFechaCaducidad.Text, MinFecha.ToShortDateString) + DtDatosDetalle.Rows.Add(Row) + + TxtSerieLote.Text = "" + TxtFechaCaducidad.Text = Now.ToShortDateString + + CargaSerie() End Sub -#End Region + Protected Sub BtnSerieLote_Click(sender As Object, e As EventArgs) -#Region " TOTALES: VALIDA Y CALCULA " - Private Sub AsignaValoresOriginales(SubTotal As Double, SubTotal2 As Double, IVA As Double, RetIVA As Double, RetISR As Double, Total As Double) - SubTotalOriginal = SubTotal - SubTotal2Original = SubTotal2 - IVAOriginal = IVA - RetIVAOriginal = RetIVA - RetISROriginal = RetISR - TotalOriginal = Total - End Sub - Private Sub CalculaTotales(Optional CalculaIVA As Boolean = False, Optional EsNoDeducible As Boolean = False) - 'VARIABLES DE CALCULO - Dim SubTotal, Descuentos, Amortizacion, IVA, SubTotal2, RetIVA, RetISR, IEPSPS, Total, SubTotalIVA, SubTotalIEPSIVA As Double - - 'SE ACTUALIZA EL IVA DEL DtDetalle SI ES QUE AHORA SE VA A TOMAR EN CUENTA EL IVA - 'For Each Row As DataRow In TmpDT.Rows - ' If CalculaIVA Then - ' Row("IVA") = Row("IVAPorcentaje").ToString.ToDouble * Row("Total").ToString.ToDouble - ' Else - ' Row("IVA") = 0 - ' End If - 'Next - - 'HACEMOS CALCULOS - SubTotalIVA = TmpDT.SUM("IVA") - SubTotalIEPSIVA = TmpDT.SUM("IEPSPSIVA") - SubTotal = TmpDT.SUM("Total") + TmpDT.SUM("Descuento") - RetIVA = TmpDT.SUM("RetIVA") - RetISR = TmpDT.SUM("RetISR") - IEPSPS = TmpDT.SUM("IEPSPS") - IVA = If(TmpDT.SUM("IVA") > 0, SubTotalIVA + SubTotalIEPSIVA, 0) - 'If CalculaIVA Then IVA = TxtIVA.Text.ToDouble - Descuentos = TmpDT.SUM("Descuento") - - '[IPP] SI YA ES COMPRA REGISTRADA NO CONSIDERA LA AMORTIZACIÓN PARA EL CALCULO DE TOTAL - If Not CveCompra > 0 Then - Amortizacion = LblAmortizacion.Text.Trim.ToDouble - End If - - 'RETENCIONES - Dim Retenciones = 0D - Retenciones = TxtRetIVA.Text.ToDecimal - Retenciones += TxtRetISR.Text.ToDecimal - - - SubTotal2 = SubTotal - Descuentos ' - Amortizacion '[IPP] COMENTADO CASO JAM 12653 CON NC 27122 | 23/MAYO/2018 - Total = SubTotal2 + IVA + IEPSPS - Retenciones - - 'ASIGNAMOS VALORES A VISTA - If CveCompra > 0 Or CveFactura > 0 Or OCVinculada Then - TxtSubTotal.Text = SubTotal.ToString.FormatoNumero() - TxtSubTotal2.Text = SubTotal2.ToString.FormatoNumero() - TxtDescuento.Text = Descuentos.ToString.FormatoNumero() - If EsNoDeducible Then - TxtIVA.Text = IVA.ToString.FormatoNumero() - TxtRetIVA.Text = RetIVA.ToString.FormatoNumero() - If TxtRetIVA.Text.ToDouble > 0 Then TrRetIVA.Visible = True - TxtRetISR.Text = RetISR.ToString.FormatoNumero() - If TxtRetISR.Text.ToDouble > 0 Then TrRetISR.Visible = True - TxtIEPS.Text = IEPSPS.ToString.FormatoNumero() - If TxtIEPS.Text.ToDouble > 0 Then TrIEPS.Visible = True - End If - If TxtDescuento.Text.ToDouble > 0 Then TrDescuento.Visible = True - If ActualizaTotales And UsuarioActual.CveEmpresa = 72 Then TxtTotal.Text = Total.ToString.FormatoNumero() - Else - TxtSubTotal.Text = SubTotal.ToString.FormatoNumero() - TxtSubTotal2.Text = SubTotal2.ToString.FormatoNumero() - TxtIVA.Text = IVA.ToString.FormatoNumero() - TxtDescuento.Text = Descuentos.ToString.FormatoNumero() - If TxtDescuento.Text.ToDouble > 0 Then TrDescuento.Visible = True - TxtRetIVA.Text = RetIVA.ToString.FormatoNumero() - If TxtRetIVA.Text.ToDouble > 0 Then TrRetIVA.Visible = True - TxtRetISR.Text = RetISR.ToString.FormatoNumero() - If TxtRetISR.Text.ToDouble > 0 Then TrRetISR.Visible = True - TxtIEPS.Text = IEPSPS.ToString.FormatoNumero() - If TxtIEPS.Text.ToDouble > 0 Then TrIEPS.Visible = True - TxtTotal.Text = Total.ToString.FormatoNumero() - - 'VALORES PROPIEDAD - CompraSaldo = Total - HfTotalCompra.Value = Total.ToString - End If - - 'CUANDO SEA COMPRA, FACTURA O VENGA DE VINCULACIÓN OC NO SE MODIFICAN VALORES - 'SE VERIFICA SI ALGUN DATO ES DIFERENTE PARA MOSTRAR COLUMNA CON VALORES ORIGINALES - If (CveCompra > 0 Or CveFactura > 0 Or OCVinculada) And Not EsNoDeducible Then - If SubTotal <> SubTotalOriginal Then - OriginalesVisible(True) - LbSubTotalOriginal.Text = SubTotalOriginal.ToString.FormatoNumero(2) - Else - OriginalesVisible(False) - End If - End If - - LblRetIVA.Text = (If(SubTotal2 > 0, (RetIVA / SubTotal2), 0) * 100).FormatoNumero(3) + "%" - LblRetISR.Text = (If(SubTotal2 > 0, (RetISR / SubTotal2), 0) * 100).FormatoNumero(3) - - 'IMPORTES DE RESTRICCION - TxtDocumentoImporteFE.Text = Total.ToString.FormatoNumero(2) - RVDocumentoImporte.MaximumValue = Total.ToString.FormatoNumero(2) - RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue - RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue - - CargaRetIVAConcepto() + Dim Argumentos = CType(sender, Button).CommandArgument.Split("°"c) + + LbProducto.Text = Argumentos(3) + LbCantidadSerie.Text = Argumentos(4) + + CvePSSerieLote = Argumentos(0).ToEntero + CveUMSerieLote = Argumentos(1).ToEntero + PUSerieLote = Argumentos(2).ToDecimal + + + CargaSerie() + End Sub + Protected Sub GvSerie_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvSerie.RowDeleting + DtDatosDetalle.Rows.Remove(DtDatosDetalle.Rows(e.RowIndex)) + CargaSerie() + End Sub +#End Region + +#Region " TIPO CAMBIO " + Protected Sub DdlMoneda_SelectedIndexChanged(sender As Object, e As EventArgs) + CambiaMoneda() + End Sub + Private Sub CambiaMoneda(Optional RecargaTipoCambio As Boolean = True) + TxtFecha.Attributes.Remove("onblur") + + If DdlMoneda.SelectedValue.ToEntero > 1 Then + TipoCambio = If(RecargaTipoCambio, GlobalTipoCambio(TxtFecha.Text.ToDate), TipoCambio) + LblTC.Text = String.Format("TC: {0}", TipoCambio.ToString("N4")) + TxtTC.Text = TipoCambio.ToString("N4") + If UsuarioActual.Empresa.UsaAC Then + TxtFecha.Attributes.Add("onblur", "CambiaFecha();CambiaFechaTC();") + Else + TxtFecha.Attributes.Add("onblur", "CambiaFechaTC();") + End If + + If CveCompra <= 0 Then 'And CveFactura <= 0 [IPP] 11Junio2018 + DivTC.Visible = True + LblTC.Visible = False + Else + DivTC.Visible = False + LblTC.Visible = True + End If + + Else + + If UsuarioActual.CveEmpresa.Contiene({4, 7, 11, 12, 145}) Then + RegistraScript("$('#ModalPesos').modal('show');") + TxtConvertirPesos.Text = If(TipoCambio > 0, TipoCambio, GlobalTipoCambio(TxtFecha.Text.ToDate)).ToString.FormatoNumero + End If + + TipoCambio = 1 + LblTC.Text = "" + TxtTC.Text = "" + If UsuarioActual.Empresa.UsaAC Then + TxtFecha.Attributes.Add("onblur", "CambiaFecha()") + End If + End If + + CargaCuentas() + End Sub + Protected Sub BtnCambiaFechaTC_Click(sender As Object, e As EventArgs) + LblTC.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString.FormatoNumero(4) + TxtTC.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString.FormatoNumero(4) + End Sub +#End Region + +#Region " CONVERTIR PESOS " + Protected Sub BtnConvertirPesos_Click(sender As Object, e As EventArgs) + Dim TipoCambioTemp = TxtConvertirPesos.Text.ToDouble + + If TipoCambioTemp <= 0 Then + Exit Sub + End If + + For Each Dr As DataRow In TmpDT.Rows + Dr("PU") = Dr("PU").ToString.ToDecimal * TipoCambioTemp + Dr("IVA") = Dr("IVA").ToString.ToDecimal * TipoCambioTemp + Dr("RetIVA") = Dr("RetIVA").ToString.ToDecimal * TipoCambioTemp + Dr("RetISR") = Dr("RetISR").ToString.ToDecimal * TipoCambioTemp + Dr("IEPSPS") = Dr("IEPSPS").ToString.ToDecimal * TipoCambioTemp + Dr("Descuento") = Dr("Descuento").ToString.ToDecimal * TipoCambioTemp + Dr("OtrosGastos") = Dr("OtrosGastos").ToString.ToDecimal * TipoCambioTemp + + Dim Total = (Dr("Cantidad").ToString.ToDecimal * Dr("PU").ToString.ToDecimal) - Dr("Descuento").ToString.ToDecimal + Dr("OtrosGastos").ToString.ToDecimal + Dr("Total") = Total + Next + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + + TxtSubTotal.Text = (TmpDT.SUMD("Total") + TmpDT.SUMD("Descuento")).FormatoNumero + TxtSubTotal2.Text = TmpDT.SUMD("Total").FormatoNumero() + TxtIVA.Text = TmpDT.SUMD("IVA").FormatoNumero() + + 'IPP CAMBIADO - 5 DICIEMBRE 2016 + 'TxtTotal.Text = (TxtSubTotal2.Text.ToDouble + TxtIVA.Text.ToDouble).ToString.FormatoNumero.Replace(","c, "") + TxtTotal.Text = (TmpDT.SUMD("Total") + TmpDT.SUMD("IVA") + TmpDT.SUMD("IEPSPS") - TmpDT.SUMD("RetIVA") - TmpDT.SUMD("RetISR")).FormatoNumero + + + SubTotalOriginal = TxtSubTotal.Text.ToDouble + SubTotal2Original = TxtSubTotal2.Text.ToDouble + + If TrDescuento.Visible Then TxtDescuento.Text = (TmpDT.SUMD("Descuento")).ToString.FormatoNumero + If TrRetIVA.Visible Then TxtRetIVA.Text = (TmpDT.SUMD("RetIVA")).ToString.FormatoNumero + If TrRetISR.Visible Then TxtRetISR.Text = (TmpDT.SUMD("RetISR")).ToString.FormatoNumero + If TrIEPS.Visible Then TxtIEPS.Text = (TmpDT.SUMD("IEPSPS")).ToString.FormatoNumero + If TrOtrosImpuestos.Visible Then TxtOtrosImpuestos.Text = (TmpDT.SUMD("OtrosGastos")).ToString.FormatoNumero + If TrRedondeo.Visible Then TxtRedondeo.Text = (TxtRedondeo.Text.ToDouble * TipoCambioTemp).ToString.FormatoNumero.Replace(","c, "") + + + If TxtSubTotal2.Text.ToDouble <> TmpDT.SUM("Total") Then + AjustaImporteUltimoConcepto((TxtSubTotal2.Text.ToDouble - TmpDT.SUM("Total")).ToString.ToDecimal) + End If + + DdlMoneda.Enabled = False + RegistraScript("$('#ModalPesos').modal('hide');") + End Sub +#End Region + +#Region " TOTALES: VALIDA Y CALCULA " + Private Sub AsignaValoresOriginales(SubTotal As Double, SubTotal2 As Double, IVA As Double, RetIVA As Double, RetISR As Double, Total As Double) + SubTotalOriginal = SubTotal + SubTotal2Original = SubTotal2 + IVAOriginal = IVA + RetIVAOriginal = RetIVA + RetISROriginal = RetISR + TotalOriginal = Total + End Sub + Private Sub CalculaTotales(Optional CalculaIVA As Boolean = False, Optional EsNoDeducible As Boolean = False) + 'VARIABLES DE CALCULO + Dim SubTotal, Descuentos, Amortizacion, IVA, SubTotal2, RetIVA, RetISR, IEPSPS, Total, SubTotalIVA, SubTotalIEPSIVA As Double + + 'SE ACTUALIZA EL IVA DEL DtDetalle SI ES QUE AHORA SE VA A TOMAR EN CUENTA EL IVA + 'For Each Row As DataRow In TmpDT.Rows + ' If CalculaIVA Then + ' Row("IVA") = Row("IVAPorcentaje").ToString.ToDouble * Row("Total").ToString.ToDouble + ' Else + ' Row("IVA") = 0 + ' End If + 'Next + + 'HACEMOS CALCULOS + SubTotalIVA = TmpDT.SUM("IVA") + SubTotalIEPSIVA = TmpDT.SUM("IEPSPSIVA") + SubTotal = TmpDT.SUM("Total") + TmpDT.SUM("Descuento") + RetIVA = TmpDT.SUM("RetIVA") + RetISR = TmpDT.SUM("RetISR") + IEPSPS = TmpDT.SUM("IEPSPS") + IVA = If(TmpDT.SUM("IVA") > 0, SubTotalIVA + SubTotalIEPSIVA, 0) + 'If CalculaIVA Then IVA = TxtIVA.Text.ToDouble + Descuentos = TmpDT.SUM("Descuento") + + '[IPP] SI YA ES COMPRA REGISTRADA NO CONSIDERA LA AMORTIZACIÓN PARA EL CALCULO DE TOTAL + If Not CveCompra > 0 Then + Amortizacion = LblAmortizacion.Text.Trim.ToDouble + End If + + 'RETENCIONES + Dim Retenciones = 0D + Retenciones = TxtRetIVA.Text.ToDecimal + Retenciones += TxtRetISR.Text.ToDecimal + + + SubTotal2 = SubTotal - Descuentos ' - Amortizacion '[IPP] COMENTADO CASO JAM 12653 CON NC 27122 | 23/MAYO/2018 + Total = SubTotal2 + IVA + IEPSPS - Retenciones + + 'ASIGNAMOS VALORES A VISTA + If CveCompra > 0 Or CveFactura > 0 Or OCVinculada Then + TxtSubTotal.Text = SubTotal.ToString.FormatoNumero() + TxtSubTotal2.Text = SubTotal2.ToString.FormatoNumero() + TxtDescuento.Text = Descuentos.ToString.FormatoNumero() + If EsNoDeducible Then + TxtIVA.Text = IVA.ToString.FormatoNumero() + TxtRetIVA.Text = RetIVA.ToString.FormatoNumero() + If TxtRetIVA.Text.ToDouble > 0 Then TrRetIVA.Visible = True + TxtRetISR.Text = RetISR.ToString.FormatoNumero() + If TxtRetISR.Text.ToDouble > 0 Then TrRetISR.Visible = True + TxtIEPS.Text = IEPSPS.ToString.FormatoNumero() + If TxtIEPS.Text.ToDouble > 0 Then TrIEPS.Visible = True + End If + If TxtDescuento.Text.ToDouble > 0 Then TrDescuento.Visible = True + If ActualizaTotales And UsuarioActual.CveEmpresa = 72 Then TxtTotal.Text = Total.ToString.FormatoNumero() + Else + TxtSubTotal.Text = SubTotal.ToString.FormatoNumero() + TxtSubTotal2.Text = SubTotal2.ToString.FormatoNumero() + TxtIVA.Text = IVA.ToString.FormatoNumero() + TxtDescuento.Text = Descuentos.ToString.FormatoNumero() + If TxtDescuento.Text.ToDouble > 0 Then TrDescuento.Visible = True + TxtRetIVA.Text = RetIVA.ToString.FormatoNumero() + If TxtRetIVA.Text.ToDouble > 0 Then TrRetIVA.Visible = True + TxtRetISR.Text = RetISR.ToString.FormatoNumero() + If TxtRetISR.Text.ToDouble > 0 Then TrRetISR.Visible = True + TxtIEPS.Text = IEPSPS.ToString.FormatoNumero() + If TxtIEPS.Text.ToDouble > 0 Then TrIEPS.Visible = True + TxtTotal.Text = Total.ToString.FormatoNumero() + + 'VALORES PROPIEDAD + CompraSaldo = Total + HfTotalCompra.Value = Total.ToString + End If + + 'CUANDO SEA COMPRA, FACTURA O VENGA DE VINCULACIÓN OC NO SE MODIFICAN VALORES + 'SE VERIFICA SI ALGUN DATO ES DIFERENTE PARA MOSTRAR COLUMNA CON VALORES ORIGINALES + If (CveCompra > 0 Or CveFactura > 0 Or OCVinculada) And Not EsNoDeducible Then + If SubTotal <> SubTotalOriginal Then + OriginalesVisible(True) + LbSubTotalOriginal.Text = SubTotalOriginal.ToString.FormatoNumero(2) + Else + OriginalesVisible(False) + End If + End If + + LblRetIVA.Text = (If(SubTotal2 > 0, (RetIVA / SubTotal2), 0) * 100).FormatoNumero(3) + "%" + LblRetISR.Text = (If(SubTotal2 > 0, (RetISR / SubTotal2), 0) * 100).FormatoNumero(3) + + 'IMPORTES DE RESTRICCION + TxtDocumentoImporteFE.Text = Total.ToString.FormatoNumero(2) + RVDocumentoImporte.MaximumValue = Total.ToString.FormatoNumero(2) + RVDocumentoImporteFE.MaximumValue = RVDocumentoImporte.MaximumValue + RVDocumentoImporteCaja.MaximumValue = RVDocumentoImporte.MaximumValue + + CargaRetIVAConcepto() CargaRetISRConcepto() - End Sub - Private Sub OriginalesVisible(Accion As Boolean) - tdT0.Visible = Accion - tdT1.Visible = Accion - tdT2.Visible = Accion - tdT3.Visible = Accion - tdT4.Visible = Accion - tdT5.Visible = Accion - tdT6.Visible = Accion - tdT7.Visible = Accion - tdT8.Visible = Accion - tdT9.Visible = Accion - tdT10.Visible = Accion - tdT11.Visible = Accion - End Sub - - Private Function ValidaTotalesGuardar() As Boolean - Dim EsValido = True - - 'VALIDA IMPORTES - 'VALIDA TOTAL CON LOS IMPORTES TOTALES - Dim TempSubTotal, TempDescuentos, TempIVA, TempSubTotal2, TempRetIVA, TempRetISR, TempTotal, DifTotales, TempIEPS As Double - 'Dim TempPorcentajeRetIVA = LblRetIVA.Text.ToDouble / 100 - 'Dim TempPorcentajeRetISR = LblRetISR.Text.ToDouble / 100 - Dim Amortizacion As Decimal = 0 + End Sub + Private Sub OriginalesVisible(Accion As Boolean) + tdT0.Visible = Accion + tdT1.Visible = Accion + tdT2.Visible = Accion + tdT3.Visible = Accion + tdT4.Visible = Accion + tdT5.Visible = Accion + tdT6.Visible = Accion + tdT7.Visible = Accion + tdT8.Visible = Accion + tdT9.Visible = Accion + tdT10.Visible = Accion + tdT11.Visible = Accion + End Sub + + Private Function ValidaTotalesGuardar() As Boolean + Dim EsValido = True + + 'VALIDA IMPORTES + 'VALIDA TOTAL CON LOS IMPORTES TOTALES + Dim TempSubTotal, TempDescuentos, TempIVA, TempSubTotal2, TempRetIVA, TempRetISR, TempTotal, DifTotales, TempIEPS As Double + 'Dim TempPorcentajeRetIVA = LblRetIVA.Text.ToDouble / 100 + 'Dim TempPorcentajeRetISR = LblRetISR.Text.ToDouble / 100 + Dim Amortizacion As Decimal = 0 If UsuarioActual.CveEmpresa = 119 Then Amortizacion = LblAmortizacion.Text.Trim.ToDecimal TxtSubTotal.Text = (TxtSubTotal.Text.ToDouble + Amortizacion).ToString - End If - + End If + Dim TieneAmortizacion As Boolean = False If ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 Then TieneAmortizacion = True - End If - + End If + If CveCompra < 0 AndAlso Not TieneAmortizacion Then LblAmortizacion.Text = "0.00" - End If - - TempSubTotal = TxtSubTotal.Text.ToDouble - SubTotalOriginal = TxtSubTotal.Text.ToDouble - SubTotal2Original = TxtSubTotal2.Text.ToDouble - TempDescuentos = TxtDescuento.Text.Trim.ToDouble + Amortizacion - TempSubTotal2 = TempSubTotal - TempDescuentos - TempIVA = TxtIVA.Text.ToDouble - TempIEPS = TxtIEPS.Text.ToDouble - TempRetIVA = TxtRetIVA.Text.ToDouble - TempRetISR = TxtRetISR.Text.ToDouble - TempTotal = Math.Round(TempSubTotal2 + TempIVA + TempIEPS - TempRetIVA - TempRetISR - TxtOtrosImpuestos.Text.ToDouble - Amortizacion, 2) - DifTotales = TxtTotal.Text.ToDouble - TempTotal - Dim DiferenciaPermitida = 0.6 - - If Math.Abs(DifTotales) > DiferenciaPermitida Then - Alert("Los importes de los conceptos (Productos/Servicios) no cuadran con el total. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - EsValido = False - ElseIf DifTotales <> 0 Then - TxtSubTotal2.Text = (TxtSubTotal2.Text.ToDouble + DifTotales).ToString - TxtSubTotal.Text = (TxtSubTotal.Text.ToDouble + DifTotales).ToString - SubTotalOriginal = TxtSubTotal.Text.ToDouble - SubTotal2Original = TxtSubTotal2.Text.ToDouble - End If - - Dim DiferenciaSubtotales = 0.0D - If CveCompra > 0 Or CveFactura > 0 Or OCVinculada Then - - If SubTotalOriginal = Nothing Then - SubTotalOriginal = 0 - End If - - If SubTotal2Original = Nothing Then - SubTotal2Original = 0 - End If - - DiferenciaSubtotales = SubTotal2Original.ToString.ToDecimal - TmpDT.SUM("Total").ToString.ToDecimal - '[IPP] PARCHE: Factura TELMEX para APH 12/ENERO/2018 - If CveFactura = 286290 Then - DiferenciaSubtotales += TxtDescuento.Text.ToDecimal - End If - If Math.Abs(DiferenciaSubtotales) > 1 And Not EsNoDeducible Then - Alert("Los importes de los conceptos (Productos/Servicios) no cuadran con el total. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - EsValido = False - Else - AjustaImporteUltimoConcepto(DiferenciaSubtotales) - End If - Else - DiferenciaSubtotales = (TxtSubTotal2.Text.ToDouble - TmpDT.SUM("Total")).ToString.ToDecimal - If Math.Abs(DiferenciaSubtotales) > 1 Then - Alert("Los importes de los conceptos (Productos/Servicios) no cuadran con el total. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) - EsValido = False - Else - AjustaImporteUltimoConcepto(DiferenciaSubtotales) - End If - End If - - Return EsValido - End Function - - Private Sub LnkAcarreo_Click(sender As Object, e As EventArgs) Handles LnkAcarreo.Click - VerificarAcarreo() - End Sub - - Private Sub VerificarAcarreo() - RegistraScript(String.Format("$('#{0}').modal('show');", "divAddAcarreo")) - End Sub - - Private Sub BtnAgregarAcarreo_Click(sender As Object, e As EventArgs) Handles BtnAgregarAcarreo.Click - - tDTAcarreos.Clear() - TotAcarreos = 0 - For Each Gvr As GridViewRow In GvAcarreo.Rows - If CType(Gvr.FindControl("ChkRow"), System.Web.UI.WebControls.CheckBox).Checked = True Then - Dim Row As DataRow = Nothing - Row = tDTAcarreos.NewRow - Row("CvePreEstimacion") = Gvr.DataKey("CvePreEstimacion") - Row("Importe") = Gvr.DataKey("Importe") - tDTAcarreos.Rows.Add(Row) - TotAcarreos = TotAcarreos + Gvr.DataKey("Importe").ToDouble - - End If - Next - UpPS.Update() - RegistraScript(String.Format("$('#{0}').modal('hide');", "divAddAcarreo")) + End If + + TempSubTotal = TxtSubTotal.Text.ToDouble + SubTotalOriginal = TxtSubTotal.Text.ToDouble + SubTotal2Original = TxtSubTotal2.Text.ToDouble + TempDescuentos = TxtDescuento.Text.Trim.ToDouble + Amortizacion + TempSubTotal2 = TempSubTotal - TempDescuentos + TempIVA = TxtIVA.Text.ToDouble + TempIEPS = TxtIEPS.Text.ToDouble + TempRetIVA = TxtRetIVA.Text.ToDouble + TempRetISR = TxtRetISR.Text.ToDouble + TempTotal = Math.Round(TempSubTotal2 + TempIVA + TempIEPS - TempRetIVA - TempRetISR - TxtOtrosImpuestos.Text.ToDouble - Amortizacion, 2) + DifTotales = TxtTotal.Text.ToDouble - TempTotal + Dim DiferenciaPermitida = 0.6 + + If Math.Abs(DifTotales) > DiferenciaPermitida Then + Alert("Los importes de los conceptos (Productos/Servicios) no cuadran con el total. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + EsValido = False + ElseIf DifTotales <> 0 Then + TxtSubTotal2.Text = (TxtSubTotal2.Text.ToDouble + DifTotales).ToString + TxtSubTotal.Text = (TxtSubTotal.Text.ToDouble + DifTotales).ToString + SubTotalOriginal = TxtSubTotal.Text.ToDouble + SubTotal2Original = TxtSubTotal2.Text.ToDouble + End If + + Dim DiferenciaSubtotales = 0.0D + If CveCompra > 0 Or CveFactura > 0 Or OCVinculada Then + + If SubTotalOriginal = Nothing Then + SubTotalOriginal = 0 + End If + + If SubTotal2Original = Nothing Then + SubTotal2Original = 0 + End If + + DiferenciaSubtotales = SubTotal2Original.ToString.ToDecimal - TmpDT.SUM("Total").ToString.ToDecimal + '[IPP] PARCHE: Factura TELMEX para APH 12/ENERO/2018 + If CveFactura = 286290 Then + DiferenciaSubtotales += TxtDescuento.Text.ToDecimal + End If + If Math.Abs(DiferenciaSubtotales) > 1 And Not EsNoDeducible Then + Alert("Los importes de los conceptos (Productos/Servicios) no cuadran con el total. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + EsValido = False + Else + AjustaImporteUltimoConcepto(DiferenciaSubtotales) + End If + Else + DiferenciaSubtotales = (TxtSubTotal2.Text.ToDouble - TmpDT.SUM("Total")).ToString.ToDecimal + If Math.Abs(DiferenciaSubtotales) > 1 Then + Alert("Los importes de los conceptos (Productos/Servicios) no cuadran con el total. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + EsValido = False + Else + AjustaImporteUltimoConcepto(DiferenciaSubtotales) + End If + End If + + Return EsValido + End Function + + Private Sub LnkAcarreo_Click(sender As Object, e As EventArgs) Handles LnkAcarreo.Click + VerificarAcarreo() End Sub -#End Region -#Region "Historial de Modificacion" - Private Sub CargaGvBitacora() - ' COMENTADO POR IPP PARA SUBIR 5 ABRIL 2017 - Dim ObjGral As New ClsGenerales() - If ObjGral.GetHistorialBitacora(-1, -1, -1, -1, -1, CveCompra, -1, UsuarioActual.CveEmpresa) Then - GvBitacora.DataSource = ObjGral.DtResultados - GvBitacora.DataBind() - End If - ObjGral.Dispose() + Private Sub VerificarAcarreo() + RegistraScript(String.Format("$('#{0}').modal('show');", "divAddAcarreo")) End Sub -#End Region -#Region " FLETES " + Private Sub BtnAgregarAcarreo_Click(sender As Object, e As EventArgs) Handles BtnAgregarAcarreo.Click - Private Sub CargaFletes() - - If UsuarioActual.CveEmpresa <> 125 Or CveCompra > 0 Then - Exit Sub - End If - - HLModalFletes.Visible = True - - Dim ObjVentas As New ClsVentas - - If ObjVentas.GetFletes(UsuarioActual.CveEmpresa) Then - GVFletes.DataSource = ObjVentas.DtResultados - GVFletes.DataBind() - End If - - UpFletes.Update() - - ObjVentas.Dispose() + tDTAcarreos.Clear() + TotAcarreos = 0 + For Each Gvr As GridViewRow In GvAcarreo.Rows + If CType(Gvr.FindControl("ChkRow"), System.Web.UI.WebControls.CheckBox).Checked = True Then + Dim Row As DataRow = Nothing + Row = tDTAcarreos.NewRow + Row("CvePreEstimacion") = Gvr.DataKey("CvePreEstimacion") + Row("Importe") = Gvr.DataKey("Importe") + tDTAcarreos.Rows.Add(Row) + TotAcarreos = TotAcarreos + Gvr.DataKey("Importe").ToDouble + + End If + Next + UpPS.Update() + RegistraScript(String.Format("$('#{0}').modal('hide');", "divAddAcarreo")) + End Sub +#End Region + +#Region "Historial de Modificacion" + Private Sub CargaGvBitacora() + ' COMENTADO POR IPP PARA SUBIR 5 ABRIL 2017 + Dim ObjGral As New ClsGenerales() + If ObjGral.GetHistorialBitacora(-1, -1, -1, -1, -1, CveCompra, -1, UsuarioActual.CveEmpresa) Then + GvBitacora.DataSource = ObjGral.DtResultados + GvBitacora.DataBind() + End If + ObjGral.Dispose() + End Sub +#End Region + +#Region " FLETES " + + Private Sub CargaFletes() + + If UsuarioActual.CveEmpresa <> 125 Or CveCompra > 0 Then + Exit Sub + End If + + HLModalFletes.Visible = True + + Dim ObjVentas As New ClsVentas + + If ObjVentas.GetFletes(UsuarioActual.CveEmpresa) Then + GVFletes.DataSource = ObjVentas.DtResultados + GVFletes.DataBind() + End If + + UpFletes.Update() + + ObjVentas.Dispose() End Sub -#End Region +#End Region -#Region "I M P R I M I R D E S G L O S E" +#Region "I M P R I M I R D E S G L O S E" - Private Sub LnkExportaGv_Click(sender As Object, e As EventArgs) Handles LnkExportaGv.Click - Dim dt As New DataTable - dt.Columns.Add("Consecutivo", GetType(Integer)) - dt.Columns.Add("Cantidad", GetType(Double)) - dt.Columns.Add("PS", GetType(String)) - dt.Columns.Add("Observacion", GetType(String)) - dt.Columns.Add("UM", GetType(String)) - dt.Columns.Add("Referencia", GetType(String)) - dt.Columns.Add("Personal", GetType(String)) - - For Each Gv As GridViewRow In GvPersonal.Rows - Dim Row As DataRow = Nothing - Row = dt.NewRow() - Row("Consecutivo") = Gv.FCLabel("LtlConsecutivo").Text - Row("Cantidad") = Gv.FCLiteral("LtlCantidad").Text.ToDouble - Row("UM") = Gv.FCLabel("LtlUnidadMedida").Text - Row("PS") = Gv.FCHyperLink("HplPS").Text - Row("Observacion") = Gv.Cells(4).Text - Row("Referencia") = Gv.FCTextBox("TxtReferencia").Text - Row("Personal") = Gv.FCDropDownList("DdlPersonalGv").SelectedItem - dt.Rows.Add(Row) - Next - ExportToExcel(dt, "Desglose") + Private Sub LnkExportaGv_Click(sender As Object, e As EventArgs) Handles LnkExportaGv.Click + Dim dt As New DataTable + dt.Columns.Add("Consecutivo", GetType(Integer)) + dt.Columns.Add("Cantidad", GetType(Double)) + dt.Columns.Add("PS", GetType(String)) + dt.Columns.Add("Observacion", GetType(String)) + dt.Columns.Add("UM", GetType(String)) + dt.Columns.Add("Referencia", GetType(String)) + dt.Columns.Add("Personal", GetType(String)) + + For Each Gv As GridViewRow In GvPersonal.Rows + Dim Row As DataRow = Nothing + Row = dt.NewRow() + Row("Consecutivo") = Gv.FCLabel("LtlConsecutivo").Text + Row("Cantidad") = Gv.FCLiteral("LtlCantidad").Text.ToDouble + Row("UM") = Gv.FCLabel("LtlUnidadMedida").Text + Row("PS") = Gv.FCHyperLink("HplPS").Text + Row("Observacion") = Gv.Cells(4).Text + Row("Referencia") = Gv.FCTextBox("TxtReferencia").Text + Row("Personal") = Gv.FCDropDownList("DdlPersonalGv").SelectedItem + dt.Rows.Add(Row) + Next + ExportToExcel(dt, "Desglose") End Sub -#End Region +#End Region 'DE AQUI PARA ABAJO SE ESTAN REORDENANDO REGIONES --- FAVOR DE SI SE MUEVE UNA COSITA O SE HACE UNA NUEVA FUNCION/METODO AGRUPARLO EN LA REGION CORRECTA O GENERAR UNA EN CASO DE NO EXISTIR -#Region " MODAL ADD PS - AGREGAR Y EDITAR PS (PARTIDA-CONCEPTO) " - Private Sub HabilitaEdicionManualAgregar() - If Not (CveCompra > 0 Or CveFactura > 0 Or OCVinculada) Then - DdlIVA.Enabled = True - TxtRetIVAModal.Enabled = True - TxtRetISRModal.Enabled = True - TxtIEPSModal.Enabled = True - End If - End Sub - - Private Sub LnkAddPS_Click(sender As Object, e As EventArgs) Handles LnkAddPS.Click - Modalidad = "A" - LimpiaAgregar() - ChkAgregar.Checked = True - divagregrarotrops.Visible = True - - UpPSS.Update() - RegistraScript(String.Format("$('#{0}').modal('show');", "divAddProducto")) - End Sub - Private Sub LimpiaAgregar() - - 'VALORES ESCONDIDOS - HdnUnidadMedida.Value = "-1" - LblUnidadMedida.Text = "UM" - HdnClasificacion.Value = "-1" - HdnPS.Value = "-1" - ViewState("IVAPS") = -1 - ViewState("RetIVA") = -1 - ViewState("RetISR") = -1 - ViewState("IEPSPS") = -1 - ViewState("IEPSPSIVA") = -1 - ChkEsNoDeduciblePS.Checked = False - - 'FORMULARIO - TxtCantidad.Text = "" - DdlClasificacion.SelectedValueExist(-1) - CargaPS(-1) - If Not UsuarioActual.Empresa.Funcionalidad(105).ToString = "1" Then - DdlPS.SelectedValue = "-1" - Else - DdlPS.SelectedValue = "" - DdlPS.SelectedText = "" - End If - ddlUM.Items.Clear() - TxtObsPS.Text = "" - DdlProyecto.SelectedValueExist(-1) - CargaSubProyecto() - DdlSubProyecto.SelectedValueExist(-1) - DdlTipoGasto.SelectedValueExist(-1) - - TxtPrecio.Text = "" - LblTotalPS.Text = "" - DdlIVA.SelectedValueExist("1") - DdlIVA.Enabled = If(CveCompra > 0 Or CveFactura > 0 Or OCVinculada, False, True) - TxtRetIVAModal.Text = "" - TxtRetISRModal.Text = "" - TxtIEPSModal.Text = "" - TxtDescuentoModal.Text = "" - TxtOtrosGastos.Text = "" - - DivAddProductoAliasPS.Visible = False - - LbAgregar.Text = "Agregar" - - UPPClasificacion.Update() - UpPSS.Update() - End Sub - Public Sub Edit_Click(sender As Object, e As EventArgs) - - Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) - - Con = GvRow.DataKey("Consec").ToEntero - Index = Con - - 'MODALIDAD UPDATE - Modalidad = "U" - LbAgregar.Text = "Actualizar" - H1.InnerText = "Actualizar Concepto" - DivAddProductoAliasPS.Visible = False - - - 'CARGA VALROES DEL CONCEPTO - TxtCantidad.Text = GvRow.DataKey("Cantidad") - DdlClasificacion.SelectedValueExist(If(GvRow.DataKey("CveClasificacion") = "0", "-1", GvRow.DataKey("CveClasificacion"))) - DdlClasificacionChange() - - If GvRow.DataKey("CvePS") = "0" Then - If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then - DdlPS.SelectedValue = GvRow.DataKey("CvePS") - DdlPS.SelectedText = GvRow.DataKey("PS") - Else - DdlPS.ddl.Items.Insert(0, New ListItem(GvRow.DataKey("PS"), "0")) - End If - 'DivAddProductoAliasPS.Visible = True - Else - - 'Si el PS esta inactivo se lo inserto manual - If GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero).FiltroPrimeroValor("CveEstado", $"CvePS = '{GvRow.DataKey("CvePS")}'") <> "True" Then - DdlPS.ddl.Items.Insert(0, New ListItem(GvRow.DataKey("PS"), "0")) - Else - DdlPS.SelectedValue = GvRow.DataKey("CvePS") - End If - - If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then - DdlPS.SelectedText = GvRow.DataKey("PS") - End If - End If - - ddlUM.Items.Clear() - If UsuarioActual.Empresa.UsaInventarios Then - ddlUM.DataSource = GlobalDTProductosServiciosEquivalencias(GvRow.DataKey("CvePS").ToEntero, -1, UsuarioActual.CveEmpresa) - Else - ddlUM.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) - End If - ddlUM.Items.Insert(0, New ListItem("Seleccione", "-1")) - ddlUM.SelectedValue = "-1" - ddlUM.DataBind() - - ddlUM.SelectedValueExist(GvRow.DataKey("CveUM")) - If ddlUM.SelectedValue <> GvRow.DataKey("CveUM") Then - ddlUM.Items.Insert(1, New ListItem(GvRow.DataKey("UM"), GvRow.DataKey("CveUM"))) - ddlUM.SelectedValueExist(GvRow.DataKey("CveUM")) - End If - TxtObsPS.Text = GvRow.DataKey("Obs") - - If UsuarioActual.Empresa.Tipo_CentroCosto <> 1 And UsuarioActual.Empresa.Tipo_CentroCosto <> 2 Then - DdlProyecto.SelectedValueExist(GvRow.DataKey("CveProyecto")) - End If - - - CargaSubProyecto() - - - 'DdlProyecto.SelectedValueExist(GvRow.DataKey("CveProyecto")) - - DdlSubProyecto.SelectedValueExist(GvRow.DataKey("CveSubProyecto")) - DdlTipoGasto.SelectedValueExist(GvRow.DataKey("CveTipoGasto")) - - Dim PS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero).FiltroPrimero("") - DdlIVA.Enabled = True - ChkEsNoDeduciblePS.Checked = If(GvRow.DataKey("NoDeducible").ToUpper().Contiene("TRUE", "1"), True, False) - - If PS IsNot Nothing Then - If PS("IVA").ToString.ToEntero() <> -1 Then - ' DdlIVA.Enabled = False - Else - - 'DdlIVA.Enabled = If(CveCompra > 0 Or CveFactura > 0 Or OCVinculada, False, True) - End If - End If - - Select Case GvRow.DataKey("IVAPorcentaje").ToDouble - Case 0 - DdlIVA.SelectedValue = "1" - Case 0.16 - DdlIVA.SelectedValue = "1.16" - Case 0.08 - DdlIVA.SelectedValue = "1.08" - End Select - - - - 'TxtIVAModal.Text = FormatoNumero(GvRow.DataKey("IVAPorcentaje").ToDouble * 100, 0) - TxtRetIVAModal.Text = FormatoNumero(GvRow.DataKey("RetIVAPorcentaje").ToDouble * 100, 0) - TxtRetISRModal.Text = FormatoNumero(GvRow.DataKey("RetISRPorcentaje").ToDouble * 100, 0) - TxtIEPSModal.Text = FormatoNumero(GvRow.DataKey("IEPSPSPorcentaje").ToDouble * 100, 0) - - TxtPrecio.Text = GvRow.DataKey("PU").FormatoNumero(6) - TxtDescuentoModal.Text = GvRow.DataKey("Descuento").FormatoNumero(6) - TxtOtrosGastos.Text = GvRow.DataKey("OtrosGastos").FormatoNumero - LblTotalPS.Text = GvRow.DataKey("Total").FormatoNumero - - 'FUNCIONALIDAD DE SEGUIR AGREGANDO (NO CERRAR MODAL) - ChkAgregar.Checked = False - divagregrarotrops.Visible = False - - UpPSS.Update() - RegistraScript("$('#divAddProducto').modal('show');") - End Sub - Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlClasificacion.SelectedIndexChanged - DdlClasificacionChange() - End Sub - Private Sub DdlClasificacionChange() - CargaPS(DdlClasificacion.SelectedValue.ToEntero) - - If UsuarioActual.Empresa.Funcionalidad(200) = "1" Then - Dim ObjConta As New ClsContabilidad - If ObjConta.GetRetCuenta(6, DdlClasificacion.SelectedValue.ToEntero) AndAlso ObjConta.DtResultados.Rows.Count > 0 AndAlso ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Then - Else - Alert("La clasificacion no tiene una cuenta contable asignada.", TipoMensaje.MsgAdvertencia) - End If - ObjConta.Dispose() - End If - - UPPClasificacion.Update() - End Sub - Private Sub CargaPS(CveClasificacion As Integer) - DdlPS.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1") - - If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then - DdlPS.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue) - DdlPS.SelectedText = "" - DdlPS.SelectedValue = "-1" - Else - DdlPS.ddl.Items.Clear() - DdlPS.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacion) - DdlPS.ddl.DataBind() - DdlPS.ddl.Items.Insert(0, New ListItem("Seleccione el Producto", "-1")) - End If - - End Sub - Protected Sub DdlPS_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DdlPS.selectedindexchange - DdlPSChange() - End Sub - Protected Sub DdlSubProyecto_SelectedIndexChanged(sender As Object, e As EventArgs) - If Modalidad <> "U" Or Not CveFactura > 0 Then +#Region " MODAL ADD PS - AGREGAR Y EDITAR PS (PARTIDA-CONCEPTO) " + Private Sub HabilitaEdicionManualAgregar() + If Not (CveCompra > 0 Or CveFactura > 0 Or OCVinculada) Then + DdlIVA.Enabled = True + TxtRetIVAModal.Enabled = True + TxtRetISRModal.Enabled = True + TxtIEPSModal.Enabled = True + End If + End Sub + + Private Sub LnkAddPS_Click(sender As Object, e As EventArgs) Handles LnkAddPS.Click + Modalidad = "A" + LimpiaAgregar() + ChkAgregar.Checked = True + divagregrarotrops.Visible = True + + UpPSS.Update() + RegistraScript(String.Format("$('#{0}').modal('show');", "divAddProducto")) + End Sub + Private Sub LimpiaAgregar() + + 'VALORES ESCONDIDOS + HdnUnidadMedida.Value = "-1" + LblUnidadMedida.Text = "UM" + HdnClasificacion.Value = "-1" + HdnPS.Value = "-1" + ViewState("IVAPS") = -1 + ViewState("RetIVA") = -1 + ViewState("RetISR") = -1 + ViewState("IEPSPS") = -1 + ViewState("IEPSPSIVA") = -1 + ChkEsNoDeduciblePS.Checked = False + + 'FORMULARIO + TxtCantidad.Text = "" + DdlClasificacion.SelectedValueExist(-1) + CargaPS(-1) + If Not UsuarioActual.Empresa.Funcionalidad(105).ToString = "1" Then + DdlPS.SelectedValue = "-1" + Else + DdlPS.SelectedValue = "" + DdlPS.SelectedText = "" + End If + ddlUM.Items.Clear() + TxtObsPS.Text = "" + DdlProyecto.SelectedValueExist(-1) + CargaSubProyecto() + DdlSubProyecto.SelectedValueExist(-1) + DdlTipoGasto.SelectedValueExist(-1) + + TxtPrecio.Text = "" + LblTotalPS.Text = "" + DdlIVA.SelectedValueExist("1") + DdlIVA.Enabled = If(CveCompra > 0 Or CveFactura > 0 Or OCVinculada, False, True) + TxtRetIVAModal.Text = "" + TxtRetISRModal.Text = "" + TxtIEPSModal.Text = "" + TxtDescuentoModal.Text = "" + TxtOtrosGastos.Text = "" + + DivAddProductoAliasPS.Visible = False + + LbAgregar.Text = "Agregar" + + UPPClasificacion.Update() + UpPSS.Update() + End Sub + Public Sub Edit_Click(sender As Object, e As EventArgs) + + Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) + + Con = GvRow.DataKey("Consec").ToEntero + Index = Con + + 'MODALIDAD UPDATE + Modalidad = "U" + LbAgregar.Text = "Actualizar" + H1.InnerText = "Actualizar Concepto" + DivAddProductoAliasPS.Visible = False + + + 'CARGA VALROES DEL CONCEPTO + TxtCantidad.Text = GvRow.DataKey("Cantidad") + DdlClasificacion.SelectedValueExist(If(GvRow.DataKey("CveClasificacion") = "0", "-1", GvRow.DataKey("CveClasificacion"))) + DdlClasificacionChange() + + If GvRow.DataKey("CvePS") = "0" Then + If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then + DdlPS.SelectedValue = GvRow.DataKey("CvePS") + DdlPS.SelectedText = GvRow.DataKey("PS") + Else + DdlPS.ddl.Items.Insert(0, New ListItem(GvRow.DataKey("PS"), "0")) + End If + 'DivAddProductoAliasPS.Visible = True + Else + + 'Si el PS esta inactivo se lo inserto manual + If GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero).FiltroPrimeroValor("CveEstado", $"CvePS = '{GvRow.DataKey("CvePS")}'") <> "True" Then + DdlPS.ddl.Items.Insert(0, New ListItem(GvRow.DataKey("PS"), "0")) + Else + DdlPS.SelectedValue = GvRow.DataKey("CvePS") + End If + + If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then + DdlPS.SelectedText = GvRow.DataKey("PS") + End If + End If + + ddlUM.Items.Clear() + If UsuarioActual.Empresa.UsaInventarios Then + ddlUM.DataSource = GlobalDTProductosServiciosEquivalencias(GvRow.DataKey("CvePS").ToEntero, -1, UsuarioActual.CveEmpresa) + Else + ddlUM.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) + End If + ddlUM.Items.Insert(0, New ListItem("Seleccione", "-1")) + ddlUM.SelectedValue = "-1" + ddlUM.DataBind() + + ddlUM.SelectedValueExist(GvRow.DataKey("CveUM")) + If ddlUM.SelectedValue <> GvRow.DataKey("CveUM") Then + ddlUM.Items.Insert(1, New ListItem(GvRow.DataKey("UM"), GvRow.DataKey("CveUM"))) + ddlUM.SelectedValueExist(GvRow.DataKey("CveUM")) + End If + TxtObsPS.Text = GvRow.DataKey("Obs") + + If UsuarioActual.Empresa.Tipo_CentroCosto <> 1 And UsuarioActual.Empresa.Tipo_CentroCosto <> 2 Then + DdlProyecto.SelectedValueExist(GvRow.DataKey("CveProyecto")) + End If + + + CargaSubProyecto() + + + 'DdlProyecto.SelectedValueExist(GvRow.DataKey("CveProyecto")) + + DdlSubProyecto.SelectedValueExist(GvRow.DataKey("CveSubProyecto")) + DdlTipoGasto.SelectedValueExist(GvRow.DataKey("CveTipoGasto")) + + Dim PS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero).FiltroPrimero("") + DdlIVA.Enabled = True + ChkEsNoDeduciblePS.Checked = If(GvRow.DataKey("NoDeducible").ToUpper().Contiene("TRUE", "1"), True, False) + + If PS IsNot Nothing Then + If PS("IVA").ToString.ToEntero() <> -1 Then + ' DdlIVA.Enabled = False + Else + + 'DdlIVA.Enabled = If(CveCompra > 0 Or CveFactura > 0 Or OCVinculada, False, True) + End If + End If + + Select Case GvRow.DataKey("IVAPorcentaje").ToDouble + Case 0 + DdlIVA.SelectedValue = "1" + Case 0.16 + DdlIVA.SelectedValue = "1.16" + Case 0.08 + DdlIVA.SelectedValue = "1.08" + End Select + + + + 'TxtIVAModal.Text = FormatoNumero(GvRow.DataKey("IVAPorcentaje").ToDouble * 100, 0) + TxtRetIVAModal.Text = FormatoNumero(GvRow.DataKey("RetIVAPorcentaje").ToDouble * 100, 0) + TxtRetISRModal.Text = FormatoNumero(GvRow.DataKey("RetISRPorcentaje").ToDouble * 100, 0) + TxtIEPSModal.Text = FormatoNumero(GvRow.DataKey("IEPSPSPorcentaje").ToDouble * 100, 0) + + TxtPrecio.Text = GvRow.DataKey("PU").FormatoNumero(6) + TxtDescuentoModal.Text = GvRow.DataKey("Descuento").FormatoNumero(6) + TxtOtrosGastos.Text = GvRow.DataKey("OtrosGastos").FormatoNumero + LblTotalPS.Text = GvRow.DataKey("Total").FormatoNumero + + 'FUNCIONALIDAD DE SEGUIR AGREGANDO (NO CERRAR MODAL) + ChkAgregar.Checked = False + divagregrarotrops.Visible = False + + UpPSS.Update() + RegistraScript("$('#divAddProducto').modal('show');") + End Sub + Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlClasificacion.SelectedIndexChanged + DdlClasificacionChange() + End Sub + Private Sub DdlClasificacionChange() + CargaPS(DdlClasificacion.SelectedValue.ToEntero) + + If UsuarioActual.Empresa.Funcionalidad(200) = "1" Then + Dim ObjConta As New ClsContabilidad + If ObjConta.GetRetCuenta(6, DdlClasificacion.SelectedValue.ToEntero) AndAlso ObjConta.DtResultados.Rows.Count > 0 AndAlso ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Then + Else + Alert("La clasificacion no tiene una cuenta contable asignada.", TipoMensaje.MsgAdvertencia) + End If + ObjConta.Dispose() + End If + + UPPClasificacion.Update() + End Sub + Private Sub CargaPS(CveClasificacion As Integer) + DdlPS.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1") + + If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then + DdlPS.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue) + DdlPS.SelectedText = "" + DdlPS.SelectedValue = "-1" + Else + DdlPS.ddl.Items.Clear() + DdlPS.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacion) + DdlPS.ddl.DataBind() + DdlPS.ddl.Items.Insert(0, New ListItem("Seleccione el Producto", "-1")) + End If + + End Sub + Protected Sub DdlPS_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DdlPS.selectedindexchange + DdlPSChange() + End Sub + Protected Sub DdlSubProyecto_SelectedIndexChanged(sender As Object, e As EventArgs) + If Modalidad <> "U" Or Not CveFactura > 0 Then DdlPSChange() - End If - End Sub - Private Sub DdlPSChange() - If CveProveedor > 0 Then - If DdlPS.SelectedValue.ToEntero > 0 Then - Dim PS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero).FiltroPrimero("") - - If PS IsNot Nothing Then - HdnClasificacion.Value = PS("Clasificacion").ToString - HdnUnidadMedida.Value = PS("CveUM").ToString - HdnTipoPS.Value = PS("CveTipoPS").ToString - HdnPS.Value = PS("PS").ToString - LblUnidadMedida.Text = PS("UnidadMedida").ToString - - - ddlUM.Items.Clear() - If UsuarioActual.Empresa.UsaInventarios Then - ddlUM.DataSource = GlobalDTProductosServiciosEquivalencias(PS("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) - Else - ddlUM.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) - End If - ddlUM.Items.Insert(0, New ListItem("Seleccione", "-1")) - ddlUM.SelectedValue = "-1" - ddlUM.DataBind() - ddlUM.SelectedValueExist(PS("CveUnidadMedida").ToString) - - 'HdnIVAPS.Value = If(PS.Rows(0)("IVA").ToString = "-1", ViewState("IVA"), PS.Rows(0)("IVA").ToString).ToString - ViewState("IVAPS") = PS("IVA").ToString - If ViewState("IVAPS").ToString.ToEntero() = -1 Then - Dim Drr As DataRow = GlobalDTSubProyectos(-1, DdlSubProyecto.SelectedValue.ToEntero())(0) - ViewState("IVAPS") = Drr("IVA").ToString().ToDouble() + End If + End Sub + Private Sub DdlPSChange() + If CveProveedor > 0 Then + If DdlPS.SelectedValue.ToEntero > 0 Then + Dim PS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero).FiltroPrimero("") + + If PS IsNot Nothing Then + HdnClasificacion.Value = PS("Clasificacion").ToString + HdnUnidadMedida.Value = PS("CveUM").ToString + HdnTipoPS.Value = PS("CveTipoPS").ToString + HdnPS.Value = PS("PS").ToString + LblUnidadMedida.Text = PS("UnidadMedida").ToString + + + ddlUM.Items.Clear() + If UsuarioActual.Empresa.UsaInventarios Then + ddlUM.DataSource = GlobalDTProductosServiciosEquivalencias(PS("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) + Else + ddlUM.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) + End If + ddlUM.Items.Insert(0, New ListItem("Seleccione", "-1")) + ddlUM.SelectedValue = "-1" + ddlUM.DataBind() + ddlUM.SelectedValueExist(PS("CveUnidadMedida").ToString) + + 'HdnIVAPS.Value = If(PS.Rows(0)("IVA").ToString = "-1", ViewState("IVA"), PS.Rows(0)("IVA").ToString).ToString + ViewState("IVAPS") = PS("IVA").ToString + If ViewState("IVAPS").ToString.ToEntero() = -1 Then + Dim Drr As DataRow = GlobalDTSubProyectos(-1, DdlSubProyecto.SelectedValue.ToEntero())(0) + ViewState("IVAPS") = Drr("IVA").ToString().ToDouble() DdlProyecto.SelectedValueExist(Drr("CveProyecto")) 'DdlIVA.Enabled = True - If Not Modalidad = "U" Then - - Select Case ViewState("IVAPS").ToString().ToDouble - Case 0 - DdlIVA.SelectedValue = "1" - Case 0.16 - DdlIVA.SelectedValue = "1.16" - Case 0.08 - DdlIVA.SelectedValue = "1.08" - End Select - - End If - - - - Else - 'DdlIVA.SelectedValue = "1" - ' DdlIVA.Enabled = False - End If - - ViewState("RetIVA") = If(PS("RetIVA").ToString = "-1", ViewState("RetIVA"), PS("RetIVA").ToString).ToString - ViewState("RetISR") = If(PS("RetISR").ToString = "-1", ViewState("RetISR"), PS("RetISR").ToString).ToString - ViewState("IEPSPS") = If(PS("IEPSPorcentaje").ToString = "-1", ViewState("IEPSPS"), PS("IEPSPorcentaje").ToString).ToString - ViewState("IEPSPSIVA") = If(PS("IEPSGrabaIVA").ToString = "True", PS("IEPSPorcentaje").ToString.ToDouble, 0) - - - 'TxtIVAModal.Text = FormatoNumero(ViewState("IVAPS").ToString().ToDouble * 100, 0) - TxtRetIVAModal.Text = FormatoNumero(ViewState("RetIVA").ToString().ToDouble * 100, 0) - TxtRetISRModal.Text = FormatoNumero(ViewState("RetISR").ToString().ToDouble * 100, 0) - TxtIEPSModal.Text = FormatoNumero(ViewState("IEPSPS").ToString().ToDouble * 100, 0) - - UpIVA.Update() - - If DdlClasificacion.SelectedIndex = 0 Then - If PS("CveClasificacion").ToString IsNot Nothing Then - DdlClasificacion.SelectedValueExist(PS("CveClasificacion").ToString) - Else - Alert("El Productos/Servicio no tiene asignada una Clasificación.") - End If - - End If - UPPUM.Update() - UpPSS.Update() - End If - Else - 'SI ES UN PS NO REGISTRADO INSERTAMOS SELECCIONE - ddlUM.Items.Clear() - ddlUM.Items.Insert(0, New ListItem("Seleccione", "-1")) - ddlUM.SelectedValue = "-1" - End If - Else - Alert("Es necesario seleccionar el Proveedor al cual se le va a capturar.", TipoMensaje.MsgAdvertencia, "AbrirVentana(""/Compras/PopUpBuscarProveedor.aspx?Opt=Fact"", 800, 547, ""N"", ""PopUpBuscar"")") - End If - End Sub - Private Sub CargaProyecto() - DdlProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"}), GlobalDTProyectos(UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"})) - - 'DdlProyecto.DataSource = GlobalDTProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1) - DdlProyecto.DataBind() - End Sub - Protected Sub DdlProyectoAsignado_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlProyecto.SelectedIndexChanged - CargaSubProyecto() - End Sub - Private Sub CargaSubProyecto() - Dim CveProyecto = If(DdlProyecto.SelectedValue.ToEntero > 0, DdlProyecto.SelectedValue.ToEntero, -1) - DdlSubProyecto.Items.Clear() - If CveProyecto > 0 Or UsuarioActual.Empresa.Tipo_CentroCosto.Contiene(1, 2) Then - DdlSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, CveProyecto, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(CveProyecto, -1, UsuarioActual.CveEmpresa, 1)) - End If - DdlSubProyecto.DataBind() - DdlSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) - End Sub - Protected Sub LbAgregar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LbAgregar.Click - - 'VALIDACIONES - If Not DdlPS.SelectedValue.ToEntero > 0 Then - Alert("Es necesario seleccionar un Producto o Servicio registrado en el sistema.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If UsuarioActual.Empresa.Tipo_CentroCosto = 3 Or UsuarioActual.Empresa.Tipo_CentroCosto = 4 Or UsuarioActual.Empresa.Tipo_CentroCosto = 5 Then - If Not DdlProyecto.SelectedValue.ToEntero > 0 Then - Alert("Es necesario seleccionar un proyecto.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - - If Not DdlSubProyecto.SelectedValue.ToEntero > 0 Then - Alert("Es necesario seleccionar un subproyecto.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If Not CveProveedor > 0 Then - Alert("Es necesario seleccionar el proveedor al cual se le va a facturar.", TipoMensaje.MsgAdvertencia, "AbrirVentana('/Compras/PopUpBuscarProveedor.aspx?Opt=Fact', 800, 547, 'N', 'PopUpBuscar')") - Exit Sub - End If - - If UsuarioActual.Empresa.Funcionalidad(527) = "1" Then - If Not DdlTipoGasto.SelectedValue.ToEntero > 0 Then - Alert("Es necesario seleccionar un tipo de gasto.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - - Select Case Modalidad - Case "A" - If Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) <> TmpDT.MAX("IVAPorcentaje").ToDouble And TmpDT.MAX("IVAPorcentaje").ToDouble <> 0 And Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) <> 0 And TmpDT.Rows.Count > 0 Then - Alert("No puede haber dos tipos de IVA en la compra.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - Case "U" - If Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) <> TmpDT.FiltraParametros($"Consec <> {Index}").MAX("IVAPorcentaje").ToDouble And TmpDT.FiltraParametros($"Consec <> {Index}").MAX("IVAPorcentaje").ToDouble <> 0 And Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) <> 0 And TmpDT.FiltraParametros($"Consec <> {Index}").Rows.Count > 0 Then - Alert("No puede haber dos tipos de IVA en la compra.", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End Select - - - Dim Total As Decimal = (TxtCantidad.Text.ToDecimal * TxtPrecio.Text.ToDecimal) - TxtDescuentoModal.Text.ToDecimal + TxtOtrosGastos.Text.ToDecimal - - If UsuarioActual.Empresa.Funcionalidad(532) = "1" Then - Dim ObjCon As New ClsContratos - Dim CvePresupuesto As Integer = 0 - Dim Autorizado As Double = 0 - Dim Ejercido As Double = 0 - If ObjCon.GetPresupuestos(-1, "-1", DdlSubProyecto.SelectedValue.ToEntero, 2, -1, UsuarioActual.CveEmpresa) Then - If ObjCon.DtResultados.Rows.Count > 0 Then - CvePresupuesto = ObjCon.DtResultados.Rows(0)("CvePresupuesto").ToString.ToEntero - If CvePresupuesto > 0 Then - If ObjCon.GetPresupuestosDetalle(CvePresupuesto, -1, UsuarioActual.CveEmpresa) Then - If ObjCon.DtResultados.FiltraParametros($"CveClasificacion = {DdlClasificacion.SelectedValue.ToEntero} AND CveTipoGasto = {DdlTipoGasto.SelectedValue.ToEntero} AND Importe > 0").Rows.Count > 0 Then - Autorizado = ObjCon.DtResultados.FiltraParametros($"CveClasificacion = {DdlClasificacion.SelectedValue.ToEntero} AND CveTipoGasto = {DdlTipoGasto.SelectedValue.ToEntero} AND Importe > 0").Rows(0)("Importe").ToString.ToDouble - End If - End If - If ObjCon.GetPresupuestosRep(CvePresupuesto, DdlTipoGasto.SelectedValue.ToEntero, 1, $"01/09/{DateTime.Now.Year - 1}".ToDate, Now, UsuarioActual.CveEmpresa, DdlProyecto.SelectedValue.ToEntero, - DdlSubProyecto.SelectedValue.ToEntero, UsuarioActual.CveUsuario, DdlClasificacion.SelectedValue.ToEntero) Then - If ObjCon.DtResultados.Rows.Count > 0 Then - Ejercido = ObjCon.DtResultados.Rows(0)("Ejercido").ToString.ToDouble - End If - End If - End If - End If - End If - ObjCon.Dispose() - - If CvePresupuesto > 0 And Autorizado > 0 Then - Dim Diferencia As Double = (Ejercido + Total) - Autorizado - If Diferencia > 0 Then - Alert($"No hay presupuesto disponible en el subproyecto {DdlSubProyecto.SelectedItem.Text} con la clasificación {DdlClasificacion.SelectedItem.Text} y el tipo de gasto {DdlTipoGasto.SelectedItem.Text}. Se excede por {Diferencia.FormatoNumero}", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - End If - End If - - ActualizaTotales = True - Select Case Modalidad - Case "A" 'ADD - AddPS(TxtCantidad.Text.Trim.ToDouble, ddlUM.SelectedValue.ToEntero, ddlUM.SelectedItem.Text, DdlClasificacion.SelectedValue.ToEntero, DdlClasificacion.SelectedItem.Text, DdlPS.SelectedValue.ToEntero, DdlPS.SelectedText, HdnTipoPS.Value.ToEntero, - DdlSubProyecto.SelectedValue.ToString, DdlSubProyecto.SelectedItem.Text, DdlProyecto.SelectedItem.Text, DdlProyecto.SelectedValue.ToString, TxtObsPS.Text.Trim, TxtPrecio.Text.Trim.ToDouble, Total, Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2), TxtRetIVAModal.Text.ToDouble / 100, TxtRetISRModal.Text.ToDouble / 100, TxtIEPSModal.Text.ToDouble / 100, 0, TxtDescuentoModal.Text.ToDouble, OtrosGastos:=TxtOtrosGastos.Text.ToDouble, CveTipoGasto:=DdlTipoGasto.SelectedValue.ToEntero, TipoGasto:=DdlTipoGasto.SelectedItem.Text, NoDeducible:=ChkEsNoDeduciblePS.Checked) - - AddPS2() - LimpiaAgregar() - - If ChkAgregar.Checked = True And Modalidad = "A" Then - RegistraScript("displayToastr(1);", "display") - Else - RegistraScript(String.Format("$('#{0}').modal('hide');", "divAddProducto")) - End If - - Case "U" 'UPDATE - UpdatePS() - Alert("Concepto actualizado Correctamente.", TipoMensaje.MsgInformacion) - RegistraScript(String.Format("$('#{0}').modal('hide');", "divAddProducto")) - End Select - ActualizaTotales = False - - If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then CargaGastosServicios(UsuarioActual.Empresa.Funcionalidad(562).ToEntero) - - If UsuarioActual.Empresa.UsaAC Then - CompruebaAgregar() - GuardaAC() - End If - + If Not Modalidad = "U" Then + + Select Case ViewState("IVAPS").ToString().ToDouble + Case 0 + DdlIVA.SelectedValue = "1" + Case 0.16 + DdlIVA.SelectedValue = "1.16" + Case 0.08 + DdlIVA.SelectedValue = "1.08" + End Select + + End If + + + + Else + 'DdlIVA.SelectedValue = "1" + ' DdlIVA.Enabled = False + End If + + ViewState("RetIVA") = If(PS("RetIVA").ToString = "-1", ViewState("RetIVA"), PS("RetIVA").ToString).ToString + ViewState("RetISR") = If(PS("RetISR").ToString = "-1", ViewState("RetISR"), PS("RetISR").ToString).ToString + ViewState("IEPSPS") = If(PS("IEPSPorcentaje").ToString = "-1", ViewState("IEPSPS"), PS("IEPSPorcentaje").ToString).ToString + ViewState("IEPSPSIVA") = If(PS("IEPSGrabaIVA").ToString = "True", PS("IEPSPorcentaje").ToString.ToDouble, 0) + + + 'TxtIVAModal.Text = FormatoNumero(ViewState("IVAPS").ToString().ToDouble * 100, 0) + TxtRetIVAModal.Text = FormatoNumero(ViewState("RetIVA").ToString().ToDouble * 100, 0) + TxtRetISRModal.Text = FormatoNumero(ViewState("RetISR").ToString().ToDouble * 100, 0) + TxtIEPSModal.Text = FormatoNumero(ViewState("IEPSPS").ToString().ToDouble * 100, 0) + + UpIVA.Update() + + If DdlClasificacion.SelectedIndex = 0 Then + If PS("CveClasificacion").ToString IsNot Nothing Then + DdlClasificacion.SelectedValueExist(PS("CveClasificacion").ToString) + Else + Alert("El Productos/Servicio no tiene asignada una Clasificación.") + End If + + End If + UPPUM.Update() + UpPSS.Update() + End If + Else + 'SI ES UN PS NO REGISTRADO INSERTAMOS SELECCIONE + ddlUM.Items.Clear() + ddlUM.Items.Insert(0, New ListItem("Seleccione", "-1")) + ddlUM.SelectedValue = "-1" + End If + Else + Alert("Es necesario seleccionar el Proveedor al cual se le va a capturar.", TipoMensaje.MsgAdvertencia, "AbrirVentana(""/Compras/PopUpBuscarProveedor.aspx?Opt=Fact"", 800, 547, ""N"", ""PopUpBuscar"")") + End If + End Sub + Private Sub CargaProyecto() + DdlProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"}), GlobalDTProyectos(UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"})) + + 'DdlProyecto.DataSource = GlobalDTProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1) + DdlProyecto.DataBind() + End Sub + Protected Sub DdlProyectoAsignado_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlProyecto.SelectedIndexChanged + CargaSubProyecto() + End Sub + Private Sub CargaSubProyecto() + Dim CveProyecto = If(DdlProyecto.SelectedValue.ToEntero > 0, DdlProyecto.SelectedValue.ToEntero, -1) + DdlSubProyecto.Items.Clear() + If CveProyecto > 0 Or UsuarioActual.Empresa.Tipo_CentroCosto.Contiene(1, 2) Then + DdlSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, CveProyecto, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(CveProyecto, -1, UsuarioActual.CveEmpresa, 1)) + End If + DdlSubProyecto.DataBind() + DdlSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) + End Sub + Protected Sub LbAgregar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LbAgregar.Click + + 'VALIDACIONES + If Not DdlPS.SelectedValue.ToEntero > 0 Then + Alert("Es necesario seleccionar un Producto o Servicio registrado en el sistema.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If UsuarioActual.Empresa.Tipo_CentroCosto = 3 Or UsuarioActual.Empresa.Tipo_CentroCosto = 4 Or UsuarioActual.Empresa.Tipo_CentroCosto = 5 Then + If Not DdlProyecto.SelectedValue.ToEntero > 0 Then + Alert("Es necesario seleccionar un proyecto.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + + If Not DdlSubProyecto.SelectedValue.ToEntero > 0 Then + Alert("Es necesario seleccionar un subproyecto.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If Not CveProveedor > 0 Then + Alert("Es necesario seleccionar el proveedor al cual se le va a facturar.", TipoMensaje.MsgAdvertencia, "AbrirVentana('/Compras/PopUpBuscarProveedor.aspx?Opt=Fact', 800, 547, 'N', 'PopUpBuscar')") + Exit Sub + End If + + If UsuarioActual.Empresa.Funcionalidad(527) = "1" Then + If Not DdlTipoGasto.SelectedValue.ToEntero > 0 Then + Alert("Es necesario seleccionar un tipo de gasto.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + + Select Case Modalidad + Case "A" + If Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) <> TmpDT.MAX("IVAPorcentaje").ToDouble And TmpDT.MAX("IVAPorcentaje").ToDouble <> 0 And Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) <> 0 And TmpDT.Rows.Count > 0 Then + Alert("No puede haber dos tipos de IVA en la compra.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + Case "U" + If Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) <> TmpDT.FiltraParametros($"Consec <> {Index}").MAX("IVAPorcentaje").ToDouble And TmpDT.FiltraParametros($"Consec <> {Index}").MAX("IVAPorcentaje").ToDouble <> 0 And Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) <> 0 And TmpDT.FiltraParametros($"Consec <> {Index}").Rows.Count > 0 Then + Alert("No puede haber dos tipos de IVA en la compra.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End Select + + + Dim Total As Decimal = (TxtCantidad.Text.ToDecimal * TxtPrecio.Text.ToDecimal) - TxtDescuentoModal.Text.ToDecimal + TxtOtrosGastos.Text.ToDecimal + + If UsuarioActual.Empresa.Funcionalidad(532) = "1" Then + Dim ObjCon As New ClsContratos + Dim CvePresupuesto As Integer = 0 + Dim Autorizado As Double = 0 + Dim Ejercido As Double = 0 + If ObjCon.GetPresupuestos(-1, "-1", DdlSubProyecto.SelectedValue.ToEntero, 2, -1, UsuarioActual.CveEmpresa) Then + If ObjCon.DtResultados.Rows.Count > 0 Then + CvePresupuesto = ObjCon.DtResultados.Rows(0)("CvePresupuesto").ToString.ToEntero + If CvePresupuesto > 0 Then + If ObjCon.GetPresupuestosDetalle(CvePresupuesto, -1, UsuarioActual.CveEmpresa) Then + If ObjCon.DtResultados.FiltraParametros($"CveClasificacion = {DdlClasificacion.SelectedValue.ToEntero} AND CveTipoGasto = {DdlTipoGasto.SelectedValue.ToEntero} AND Importe > 0").Rows.Count > 0 Then + Autorizado = ObjCon.DtResultados.FiltraParametros($"CveClasificacion = {DdlClasificacion.SelectedValue.ToEntero} AND CveTipoGasto = {DdlTipoGasto.SelectedValue.ToEntero} AND Importe > 0").Rows(0)("Importe").ToString.ToDouble + End If + End If + If ObjCon.GetPresupuestosRep(CvePresupuesto, DdlTipoGasto.SelectedValue.ToEntero, 1, $"01/09/{DateTime.Now.Year - 1}".ToDate, Now, UsuarioActual.CveEmpresa, DdlProyecto.SelectedValue.ToEntero, + DdlSubProyecto.SelectedValue.ToEntero, UsuarioActual.CveUsuario, DdlClasificacion.SelectedValue.ToEntero) Then + If ObjCon.DtResultados.Rows.Count > 0 Then + Ejercido = ObjCon.DtResultados.Rows(0)("Ejercido").ToString.ToDouble + End If + End If + End If + End If + End If + ObjCon.Dispose() + + If CvePresupuesto > 0 And Autorizado > 0 Then + Dim Diferencia As Double = (Ejercido + Total) - Autorizado + If Diferencia > 0 Then + Alert($"No hay presupuesto disponible en el subproyecto {DdlSubProyecto.SelectedItem.Text} con la clasificación {DdlClasificacion.SelectedItem.Text} y el tipo de gasto {DdlTipoGasto.SelectedItem.Text}. Se excede por {Diferencia.FormatoNumero}", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + End If + + ActualizaTotales = True + Select Case Modalidad + Case "A" 'ADD + AddPS(TxtCantidad.Text.Trim.ToDouble, ddlUM.SelectedValue.ToEntero, ddlUM.SelectedItem.Text, DdlClasificacion.SelectedValue.ToEntero, DdlClasificacion.SelectedItem.Text, DdlPS.SelectedValue.ToEntero, DdlPS.SelectedText, HdnTipoPS.Value.ToEntero, + DdlSubProyecto.SelectedValue.ToString, DdlSubProyecto.SelectedItem.Text, DdlProyecto.SelectedItem.Text, DdlProyecto.SelectedValue.ToString, TxtObsPS.Text.Trim, TxtPrecio.Text.Trim.ToDouble, Total, Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2), TxtRetIVAModal.Text.ToDouble / 100, TxtRetISRModal.Text.ToDouble / 100, TxtIEPSModal.Text.ToDouble / 100, 0, TxtDescuentoModal.Text.ToDouble, OtrosGastos:=TxtOtrosGastos.Text.ToDouble, CveTipoGasto:=DdlTipoGasto.SelectedValue.ToEntero, TipoGasto:=DdlTipoGasto.SelectedItem.Text, NoDeducible:=ChkEsNoDeduciblePS.Checked) + + AddPS2() + LimpiaAgregar() + + If ChkAgregar.Checked = True And Modalidad = "A" Then + RegistraScript("displayToastr(1);", "display") + Else + RegistraScript(String.Format("$('#{0}').modal('hide');", "divAddProducto")) + End If + + Case "U" 'UPDATE + UpdatePS() + Alert("Concepto actualizado Correctamente.", TipoMensaje.MsgInformacion) + RegistraScript(String.Format("$('#{0}').modal('hide');", "divAddProducto")) + End Select + ActualizaTotales = False + + If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then CargaGastosServicios(UsuarioActual.Empresa.Funcionalidad(562).ToEntero) + + If UsuarioActual.Empresa.UsaAC Then + CompruebaAgregar() + GuardaAC() + End If + If UsuarioActual.Empresa.Funcionalidad(577).ToString = "1" Then 'If UsuarioActual.CveRol = 1 Then ' Alert($"Ok funcionalidad 577 RetencionIVA { RetencionIVA} IVAOriginal {IVAOriginal}") 'End If - If RetencionIVA = 0 And IVAOriginal > 0 Then - For Each dRow As DataRow In TmpDT.Rows + If RetencionIVA = 0 And IVAOriginal > 0 Then + For Each dRow As DataRow In TmpDT.Rows If dRow("CveTipoPS").ToString.ToEntero = 1 Then 'Comnetado para reubicar el boton 'tdIVA6.Visible = True - Exit For - End If - Next - End If - - End If - - - - UpPS.Update() - CargaGvPersonal() - End Sub - ''' - ''' Regresa el INDEX del row que acaba de agregar en el TMPDT - ''' - ''' - Private Function AddPS(Cantidad As Double, CveUM As Integer, UM As String, CveClasificacion As Integer, Clasificacion As String, CvePS As Integer, PS As String, CveTipoPS As Integer, CveSubProyectoContrato As String, SubProyecto As String, Proyecto As String, CveProyecto As String, - Obs As String, PU As Double, Total As Double, IVA As Double, RetIVA As Double, RetISR As Double, IEPSPS As Double, IEPSPSIVA As Double, Descuento As Double, Optional CveOrdenCompraDetalle As Integer = -1, Optional TCalculaTotales As Boolean = True, - Optional PSCodigo As String = "-", Optional PSDescripcion As String = "-", Optional CantidadF As Double = -1, Optional EntregaDirecta As Integer = -1, Optional OtrosGastos As Double = 0, - Optional CveSATPS As Integer = -1, Optional CargaXml As Boolean = False, Optional CveTipoGasto As Integer = -1, Optional TipoGasto As String = "", Optional PorcentajeIVA As Double = 0, - Optional PorcentajeIEPS As Double = 0, Optional PorcentajeRetIVA As Double = 0, Optional PorcentajeRetISR As Double = 0, Optional NoDeducible As Boolean = False) As Integer - - Dim Row As DataRow = Nothing - - Row = TmpDT.NewRow() - Dim Retorno As Integer = 0 - Dim CveContrato = -1 - Dim CveSubProyecto = -1 - Dim Valores As String() - - ''CONTRATOS - If CveSubProyectoContrato.Contains("|"c) Then - Valores = CveSubProyectoContrato.Split("|"c) - CveContrato = Valores(1).ToEntero - CveSubProyecto = Valores(0).ToEntero - Else - CveSubProyecto = CveSubProyectoContrato.ToEntero - End If - - 'DR PS - Dim DrPS As DataRow = Nothing - If CvePS > 0 Then - DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).Rows(0) - End If - - If DrPS IsNot Nothing Then - Row("PSCodigo") = If(PSCodigo = "", DrPS("PSCodigo").ToString, PSCodigo) - Row("CveMetodoInventario") = DrPS("Inv_CveMetodoInventario").ToString.ToEntero - Else - Row("PSCodigo") = PSCodigo - Row("CveMetodoInventario") = 0 - End If - - If Modalidad = "U" Then - Row("Consec") = Con - Else - Row("Consec") = TmpDT.Rows.Count + 1 - End If - - If Version = "3.3" And CveSATPS > 0 Then - Dim DrPSSAT As DataRow = Nothing - If CargaXml Then - If GlobalDTPSATPS().FiltraParametros(String.Format("SATClavePS={0}", CveSATPS)).Rows.Count > 0 Then - DrPSSAT = GlobalDTPSATPS().FiltraParametros(String.Format("SATClavePS={0}", CveSATPS)).Rows(0) - End If - Else - If GlobalDTPSATPS().FiltraParametros(String.Format("CveSATPS={0}", CveSATPS)).Rows.Count > 0 Then - DrPSSAT = GlobalDTPSATPS().FiltraParametros(String.Format("CveSATPS={0}", CveSATPS)).Rows(0) - End If - End If - If DrPSSAT IsNot Nothing Then - Row("SATClaveProductoServicio") = DrPSSAT("SATClaveProductoServicio").ToString - Row("CveSATPS") = DrPSSAT("CveSATPS").ToString - End If - End If - - Dim DecimalesPermitidos = 6 - - Row("CveConcepto") = TmpDT.Rows.Count + 1 - Row("Cantidad") = Math.Round(Cantidad, DecimalesPermitidos) - Row("CantidadF") = If(CantidadF = -1, Math.Round(Cantidad, DecimalesPermitidos), Math.Round(CantidadF, DecimalesPermitidos)) - Row("CveUM") = CveUM - Row("UM") = UM - Row("CveClasificacion") = CveClasificacion - Row("CveClasificacionActualizar") = CveClasificacion - Row("Clasificacion") = Clasificacion - Row("CvePS") = CvePS - Row("PS") = PS - Row("CveTipoPS") = CveTipoPS - - Row("PSDescripcion") = PSDescripcion - Row("CveSubProyecto") = CveSubProyecto.ToEntero - Row("CveProyecto") = CveProyecto.ToEntero - Row("CveContrato") = CveContrato.ToEntero - Row("SubProyecto") = If(SubProyecto = "Seleccione", "Sin Sub Proyecto", SubProyecto) - Row("Proyecto") = If(Proyecto = "Seleccione", "Sin Proyecto", Proyecto) - Row("CveActivoFijo") = -1 - Row("Obs") = Obs - Row("CveActivoFijo") = -1 - Row("CodAF") = "-1" - Row("TipoAF") = -1 - Row("CveOrdenCompraDetalle") = CveOrdenCompraDetalle - Row("EntregaDirecta") = EntregaDirecta - 'If GlobalDTProductosServiciosEquivalencias(CvePS, CveUM).Rows.Count = 0 Then Row("CveEq") = 1 Else Row("CveEq") = 0 - Row("NoDeducible") = NoDeducible - - Row("PU") = Math.Round(PU, DecimalesPermitidos) - If CargaXml And Version = "3.3" Then - Row("IVA") = Math.Round(IVA, DecimalesPermitidos) - Row("IVAPorcentaje") = PorcentajeIVA - Row("RetIVA") = Math.Round(RetIVA, DecimalesPermitidos) - Row("RetIVAPorcentaje") = PorcentajeRetIVA - Row("RetISR") = Math.Round(RetISR, DecimalesPermitidos) - Row("RetISRPorcentaje") = PorcentajeRetISR - Row("IEPSPS") = Math.Round(IEPSPS, DecimalesPermitidos) - Row("IEPSPSPorcentaje") = PorcentajeIEPS - Else - 'If DdlIVA.SelectedValue.ToDouble = 0 Then Row("IVA") = 0 Else Row("IVA") = Math.Round(IVA * Total, DecimalesPermitidos) - Row("IVA") = Math.Round(IVA * Total, DecimalesPermitidos) - Row("IVAPorcentaje") = IVA - Row("RetIVA") = Math.Round(RetIVA * Total, DecimalesPermitidos) - Row("RetIVAPorcentaje") = RetIVA - Row("RetISR") = Math.Round(RetISR * Total, DecimalesPermitidos) - Row("RetISRPorcentaje") = RetISR - Row("IEPSPS") = Math.Round(IEPSPS * Total, DecimalesPermitidos) - Row("IEPSPSPorcentaje") = IEPSPS - End If - Row("ImporteConImpuestos") = (Row("Cantidad").ToString.ToDouble * Row("PU").ToString.ToDouble) + Row("IVA").ToString.ToDouble + Row("IEPSPS").ToString.ToDouble - (Row("RetIVA").ToString.ToDouble + Row("RetISR").ToString.ToDouble) - Row("ImporteSinImpuestos") = Row("Cantidad").ToString.ToDouble * Row("PU").ToString.ToDouble - - Row("IEPSPSIVA") = Math.Round(IEPSPSIVA * Total, DecimalesPermitidos) - Row("IEPSPSIVAPorcentaje") = IEPSPSIVA - Row("Descuento") = Math.Round(Descuento, DecimalesPermitidos) - Row("OtrosGastos") = Math.Round(OtrosGastos, DecimalesPermitidos) - Row("Total") = Math.Round(Total, DecimalesPermitidos) - - Row("CveTipoGasto") = CveTipoGasto - Row("TipoGasto") = If(CveTipoGasto > 0, TipoGasto, "") - - If UsuarioActual.Empresa.UsaAC Then - Row("CveProgramaOperativo") = DdlACGeneral1.SelectedValue.ToEntero - Row("CveUnidadAdministrativa") = DdlACGeneral2.SelectedValue.ToEntero - Row("CveFuenteFinanciamiento") = DdlACGeneral3.SelectedValue.ToEntero - Row("CveTipoGastoAC") = DdlACGeneral4.SelectedValue.ToEntero - Row("CveClasificacionOG") = DdlACGeneral5.SelectedValue.ToEntero - End If - - - - TmpDT.Rows.Add(Row) - TmpDT.Rows.IndexOf(Row) - - If TCalculaTotales Then - CalculaTotales(True) - End If - - Return Retorno - End Function - Private Sub AddPS2(Optional pCalculaTotales As Boolean = True, Optional EsNoDeducible As Boolean = False) - Dim view As DataView = New DataView(TmpDT) - view.Sort = "Consec" - GvPS.DataSource = view - 'GvPS.DataSource = TmpDT - GvPS.DataBind() - CargaGvInv() - - If pCalculaTotales Then - CalculaTotales(True, EsNoDeducible) - End If - - End Sub - Private Sub UpdatePS() - Dim DrPS As DataRow = Nothing - Try - DrPS = TmpDT.Select($"Consec = {Index}")(0) - If DrPS Is Nothing Then - Alert("Ocurrió un error al editar el concepto.", TipoMensaje.MsgError) - Exit Sub - End If - Catch ex As Exception - Alert("Ocurrió un error al intentar editar el concepto.", TipoMensaje.MsgError) - Exit Sub - End Try - - - 'BANDERA - Dim AplicaCalculaTotales = False - - 'DATOS GENERALES - DrPS("Obs") = TxtObsPS.Text.Trim - DrPS("Proyecto") = DdlProyecto.SelectedItem.Text - DrPS("CveProyecto") = DdlProyecto.SelectedValue.ToEntero - DrPS("SubProyecto") = DdlSubProyecto.SelectedItem.Text - DrPS("CveSubProyecto") = DdlSubProyecto.SelectedValue.ToEntero - - 'IMPORTES - [CANTIDAD Y PRECIO] - Dim Cantidad = DrPS("Cantidad").ToString.ToDouble - Dim PU = DrPS("PU").ToString.ToDouble - Dim Descuento = DrPS("Descuento").ToString.ToDouble - Dim OtrosGastos = DrPS("OtrosGastos").ToString.ToDouble - Dim Total = (Cantidad * PU) - Descuento + OtrosGastos - DrPS("NoDeducible") = ChkEsNoDeduciblePS.Checked - - - If Cantidad <> TxtCantidad.Text.Trim.ToDouble OrElse PU <> TxtPrecio.Text.Trim.ToDouble OrElse Descuento <> TxtDescuentoModal.Text.ToDouble OrElse OtrosGastos <> TxtOtrosGastos.Text.ToDouble Then - Cantidad = TxtCantidad.Text.Trim.ToDouble - PU = TxtPrecio.Text.Trim.ToDouble - Descuento = TxtDescuentoModal.Text.ToDouble - OtrosGastos = TxtOtrosGastos.Text.ToDouble - Total = (Cantidad * PU) - Descuento + OtrosGastos - DrPS("Cantidad") = Cantidad - DrPS("PU") = PU - DrPS("Descuento") = Descuento - DrPS("OtrosGastos") = OtrosGastos - DrPS("Total") = Total - AplicaCalculaTotales = True - End If - - 'PS - CLASIFICACION - If DdlPS.SelectedValue.ToEntero > 0 Then - Dim PSRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero).FiltroPrimero("") - If PSRow IsNot Nothing Then - DrPS("CveClasificacion") = PSRow("CveClasificacion").ToString - DrPS("Clasificacion") = PSRow("Clasificacion").ToString - DrPS("CvePS") = DdlPS.SelectedValue - DrPS("PS") = PSRow("PS").ToString - DrPS("CveTipoPS") = PSRow("CveTipoPS").ToString.ToEntero - DrPS("CveSATPS") = PSRow("CveSATPS").ToString.ToEntero - DrPS("SATClaveProductoServicio") = PSRow("SATClaveProductoServicio").ToString - - 'RESPETAR VALORES DE LA PANTALLA - 'IVA = PSRow("IVA").ToString.ToDouble - 'If IVA = -1 Then - ' IVA = GlobalDTSubProyectos(-1, DdlSubProyecto.SelectedValue.ToEntero()).FiltroPrimeroValor("IVA").ToDouble - 'End If - 'RetIVA = If(PSRow("RetIVA").ToString = "-1", ViewState("RetIVA"), PSRow("RetIVA").ToString).ToString.ToDouble - 'RetISR = If(PSRow("RetISR").ToString = "-1", ViewState("RetISR"), PSRow("RetISR").ToString).ToString.ToDouble - 'IEPSPS = If(PSRow("IEPSPorcentaje").ToString = "-1", ViewState("IEPSPS"), PSRow("IEPSPorcentaje").ToString).ToString.ToDouble - 'IEPSPSIVA = If(PSRow("IEPSGrabaIVA").ToString = "True", PSRow("IEPSPorcentaje").ToString.ToDouble, 0) - End If - End If - - 'UM - DrPS("CveUM") = ddlUM.SelectedValue.ToEntero - DrPS("UM") = ddlUM.SelectedItem.Text - - 'TIPO DE GASTO - DrPS("CveTipoGasto") = DdlTipoGasto.SelectedValue.ToEntero - DrPS("TipoGasto") = If(DdlTipoGasto.SelectedValue.ToEntero > 0, DdlTipoGasto.SelectedItem.Text, "") - - If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then - DrPS("AplicaCostoIndirecto") = "0" - End If - - 'IMPUESTOS: SI ES COMPRA, FACUTRA O CON OC, NO MODIFICA IMPUESTOS!! - 'Dim IVA = (TxtIVAModal.Text.ToDouble / 100) - Dim IVA = Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) - Dim RetISR = (TxtRetISRModal.Text.ToDouble / 100) - Dim RetIVA = (TxtRetIVAModal.Text.ToDouble / 100) - Dim IEPSPS = (TxtIEPSModal.Text.ToDouble / 100) - Dim IEPSPSIVA = 0 - - If Not (CveCompra > 0 Or CveFactura > 0 Or OCVinculada) Then - 'If DdlIVA.SelectedValue.ToDouble = 0 Then DrPS("IVA") = 0 Else DrPS("IVA") = IVA * Total - DrPS("IVA") = IVA * Total - DrPS("IVAPorcentaje") = IVA - DrPS("RetIVA") = RetIVA * Total - DrPS("RetIVAPorcentaje") = RetIVA - DrPS("RetISR") = RetISR * Total - DrPS("RetISRPorcentaje") = RetISR - DrPS("IEPSPS") = IEPSPS * Total - DrPS("IEPSPSPorcentaje") = IEPSPS - DrPS("IEPSPSIVA") = IEPSPSIVA * Total - DrPS("IEPSPSIVAPorcentaje") = IEPSPSIVA - AplicaCalculaTotales = True - End If - - TmpDT.AcceptChanges() - - AddPS2(AplicaCalculaTotales) - CargaGvInv() - + Exit For + End If + Next + End If + + End If + + + + UpPS.Update() + CargaGvPersonal() End Sub -#End Region + ''' + ''' Regresa el INDEX del row que acaba de agregar en el TMPDT + ''' + ''' + Private Function AddPS(Cantidad As Double, CveUM As Integer, UM As String, CveClasificacion As Integer, Clasificacion As String, CvePS As Integer, PS As String, CveTipoPS As Integer, CveSubProyectoContrato As String, SubProyecto As String, Proyecto As String, CveProyecto As String, + Obs As String, PU As Double, Total As Double, IVA As Double, RetIVA As Double, RetISR As Double, IEPSPS As Double, IEPSPSIVA As Double, Descuento As Double, Optional CveOrdenCompraDetalle As Integer = -1, Optional TCalculaTotales As Boolean = True, + Optional PSCodigo As String = "-", Optional PSDescripcion As String = "-", Optional CantidadF As Double = -1, Optional EntregaDirecta As Integer = -1, Optional OtrosGastos As Double = 0, + Optional CveSATPS As Integer = -1, Optional CargaXml As Boolean = False, Optional CveTipoGasto As Integer = -1, Optional TipoGasto As String = "", Optional PorcentajeIVA As Double = 0, + Optional PorcentajeIEPS As Double = 0, Optional PorcentajeRetIVA As Double = 0, Optional PorcentajeRetISR As Double = 0, Optional NoDeducible As Boolean = False) As Integer + + Dim Row As DataRow = Nothing + + Row = TmpDT.NewRow() + Dim Retorno As Integer = 0 + Dim CveContrato = -1 + Dim CveSubProyecto = -1 + Dim Valores As String() + + ''CONTRATOS + If CveSubProyectoContrato.Contains("|"c) Then + Valores = CveSubProyectoContrato.Split("|"c) + CveContrato = Valores(1).ToEntero + CveSubProyecto = Valores(0).ToEntero + Else + CveSubProyecto = CveSubProyectoContrato.ToEntero + End If + + 'DR PS + Dim DrPS As DataRow = Nothing + If CvePS > 0 Then + DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).Rows(0) + End If + + If DrPS IsNot Nothing Then + Row("PSCodigo") = If(PSCodigo = "", DrPS("PSCodigo").ToString, PSCodigo) + Row("CveMetodoInventario") = DrPS("Inv_CveMetodoInventario").ToString.ToEntero + Else + Row("PSCodigo") = PSCodigo + Row("CveMetodoInventario") = 0 + End If + + If Modalidad = "U" Then + Row("Consec") = Con + Else + Row("Consec") = TmpDT.Rows.Count + 1 + End If + + If Version = "3.3" And CveSATPS > 0 Then + Dim DrPSSAT As DataRow = Nothing + If CargaXml Then + If GlobalDTPSATPS().FiltraParametros(String.Format("SATClavePS={0}", CveSATPS)).Rows.Count > 0 Then + DrPSSAT = GlobalDTPSATPS().FiltraParametros(String.Format("SATClavePS={0}", CveSATPS)).Rows(0) + End If + Else + If GlobalDTPSATPS().FiltraParametros(String.Format("CveSATPS={0}", CveSATPS)).Rows.Count > 0 Then + DrPSSAT = GlobalDTPSATPS().FiltraParametros(String.Format("CveSATPS={0}", CveSATPS)).Rows(0) + End If + End If + If DrPSSAT IsNot Nothing Then + Row("SATClaveProductoServicio") = DrPSSAT("SATClaveProductoServicio").ToString + Row("CveSATPS") = DrPSSAT("CveSATPS").ToString + End If + End If + + Dim DecimalesPermitidos = 6 + + Row("CveConcepto") = TmpDT.Rows.Count + 1 + Row("Cantidad") = Math.Round(Cantidad, DecimalesPermitidos) + Row("CantidadF") = If(CantidadF = -1, Math.Round(Cantidad, DecimalesPermitidos), Math.Round(CantidadF, DecimalesPermitidos)) + Row("CveUM") = CveUM + Row("UM") = UM + Row("CveClasificacion") = CveClasificacion + Row("CveClasificacionActualizar") = CveClasificacion + Row("Clasificacion") = Clasificacion + Row("CvePS") = CvePS + Row("PS") = PS + Row("CveTipoPS") = CveTipoPS + + Row("PSDescripcion") = PSDescripcion + Row("CveSubProyecto") = CveSubProyecto.ToEntero + Row("CveProyecto") = CveProyecto.ToEntero + Row("CveContrato") = CveContrato.ToEntero + Row("SubProyecto") = If(SubProyecto = "Seleccione", "Sin Sub Proyecto", SubProyecto) + Row("Proyecto") = If(Proyecto = "Seleccione", "Sin Proyecto", Proyecto) + Row("CveActivoFijo") = -1 + Row("Obs") = Obs + Row("CveActivoFijo") = -1 + Row("CodAF") = "-1" + Row("TipoAF") = -1 + Row("CveOrdenCompraDetalle") = CveOrdenCompraDetalle + Row("EntregaDirecta") = EntregaDirecta + 'If GlobalDTProductosServiciosEquivalencias(CvePS, CveUM).Rows.Count = 0 Then Row("CveEq") = 1 Else Row("CveEq") = 0 + Row("NoDeducible") = NoDeducible + + Row("PU") = Math.Round(PU, DecimalesPermitidos) + If CargaXml And Version = "3.3" Then + Row("IVA") = Math.Round(IVA, DecimalesPermitidos) + Row("IVAPorcentaje") = PorcentajeIVA + Row("RetIVA") = Math.Round(RetIVA, DecimalesPermitidos) + Row("RetIVAPorcentaje") = PorcentajeRetIVA + Row("RetISR") = Math.Round(RetISR, DecimalesPermitidos) + Row("RetISRPorcentaje") = PorcentajeRetISR + Row("IEPSPS") = Math.Round(IEPSPS, DecimalesPermitidos) + Row("IEPSPSPorcentaje") = PorcentajeIEPS + Else + 'If DdlIVA.SelectedValue.ToDouble = 0 Then Row("IVA") = 0 Else Row("IVA") = Math.Round(IVA * Total, DecimalesPermitidos) + Row("IVA") = Math.Round(IVA * Total, DecimalesPermitidos) + Row("IVAPorcentaje") = IVA + Row("RetIVA") = Math.Round(RetIVA * Total, DecimalesPermitidos) + Row("RetIVAPorcentaje") = RetIVA + Row("RetISR") = Math.Round(RetISR * Total, DecimalesPermitidos) + Row("RetISRPorcentaje") = RetISR + Row("IEPSPS") = Math.Round(IEPSPS * Total, DecimalesPermitidos) + Row("IEPSPSPorcentaje") = IEPSPS + End If + Row("ImporteConImpuestos") = (Row("Cantidad").ToString.ToDouble * Row("PU").ToString.ToDouble) + Row("IVA").ToString.ToDouble + Row("IEPSPS").ToString.ToDouble - (Row("RetIVA").ToString.ToDouble + Row("RetISR").ToString.ToDouble) + Row("ImporteSinImpuestos") = Row("Cantidad").ToString.ToDouble * Row("PU").ToString.ToDouble + + Row("IEPSPSIVA") = Math.Round(IEPSPSIVA * Total, DecimalesPermitidos) + Row("IEPSPSIVAPorcentaje") = IEPSPSIVA + Row("Descuento") = Math.Round(Descuento, DecimalesPermitidos) + Row("OtrosGastos") = Math.Round(OtrosGastos, DecimalesPermitidos) + Row("Total") = Math.Round(Total, DecimalesPermitidos) + + Row("CveTipoGasto") = CveTipoGasto + Row("TipoGasto") = If(CveTipoGasto > 0, TipoGasto, "") + + If UsuarioActual.Empresa.UsaAC Then + Row("CveProgramaOperativo") = DdlACGeneral1.SelectedValue.ToEntero + Row("CveUnidadAdministrativa") = DdlACGeneral2.SelectedValue.ToEntero + Row("CveFuenteFinanciamiento") = DdlACGeneral3.SelectedValue.ToEntero + Row("CveTipoGastoAC") = DdlACGeneral4.SelectedValue.ToEntero + Row("CveClasificacionOG") = DdlACGeneral5.SelectedValue.ToEntero + End If + + + + TmpDT.Rows.Add(Row) + TmpDT.Rows.IndexOf(Row) + + If TCalculaTotales Then + CalculaTotales(True) + End If + + Return Retorno + End Function + Private Sub AddPS2(Optional pCalculaTotales As Boolean = True, Optional EsNoDeducible As Boolean = False) + Dim view As DataView = New DataView(TmpDT) + view.Sort = "Consec" + GvPS.DataSource = view + 'GvPS.DataSource = TmpDT + GvPS.DataBind() + CargaGvInv() + + If pCalculaTotales Then + CalculaTotales(True, EsNoDeducible) + End If + + End Sub + Private Sub UpdatePS() + Dim DrPS As DataRow = Nothing + Try + DrPS = TmpDT.Select($"Consec = {Index}")(0) + If DrPS Is Nothing Then + Alert("Ocurrió un error al editar el concepto.", TipoMensaje.MsgError) + Exit Sub + End If + Catch ex As Exception + Alert("Ocurrió un error al intentar editar el concepto.", TipoMensaje.MsgError) + Exit Sub + End Try + + + 'BANDERA + Dim AplicaCalculaTotales = False + + 'DATOS GENERALES + DrPS("Obs") = TxtObsPS.Text.Trim + DrPS("Proyecto") = DdlProyecto.SelectedItem.Text + DrPS("CveProyecto") = DdlProyecto.SelectedValue.ToEntero + DrPS("SubProyecto") = DdlSubProyecto.SelectedItem.Text + DrPS("CveSubProyecto") = DdlSubProyecto.SelectedValue.ToEntero + + 'IMPORTES - [CANTIDAD Y PRECIO] + Dim Cantidad = DrPS("Cantidad").ToString.ToDouble + Dim PU = DrPS("PU").ToString.ToDouble + Dim Descuento = DrPS("Descuento").ToString.ToDouble + Dim OtrosGastos = DrPS("OtrosGastos").ToString.ToDouble + Dim Total = (Cantidad * PU) - Descuento + OtrosGastos + DrPS("NoDeducible") = ChkEsNoDeduciblePS.Checked + + + If Cantidad <> TxtCantidad.Text.Trim.ToDouble OrElse PU <> TxtPrecio.Text.Trim.ToDouble OrElse Descuento <> TxtDescuentoModal.Text.ToDouble OrElse OtrosGastos <> TxtOtrosGastos.Text.ToDouble Then + Cantidad = TxtCantidad.Text.Trim.ToDouble + PU = TxtPrecio.Text.Trim.ToDouble + Descuento = TxtDescuentoModal.Text.ToDouble + OtrosGastos = TxtOtrosGastos.Text.ToDouble + Total = (Cantidad * PU) - Descuento + OtrosGastos + DrPS("Cantidad") = Cantidad + DrPS("PU") = PU + DrPS("Descuento") = Descuento + DrPS("OtrosGastos") = OtrosGastos + DrPS("Total") = Total + AplicaCalculaTotales = True + End If + + 'PS - CLASIFICACION + If DdlPS.SelectedValue.ToEntero > 0 Then + Dim PSRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero).FiltroPrimero("") + If PSRow IsNot Nothing Then + DrPS("CveClasificacion") = PSRow("CveClasificacion").ToString + DrPS("Clasificacion") = PSRow("Clasificacion").ToString + DrPS("CvePS") = DdlPS.SelectedValue + DrPS("PS") = PSRow("PS").ToString + DrPS("CveTipoPS") = PSRow("CveTipoPS").ToString.ToEntero + DrPS("CveSATPS") = PSRow("CveSATPS").ToString.ToEntero + DrPS("SATClaveProductoServicio") = PSRow("SATClaveProductoServicio").ToString + + 'RESPETAR VALORES DE LA PANTALLA + 'IVA = PSRow("IVA").ToString.ToDouble + 'If IVA = -1 Then + ' IVA = GlobalDTSubProyectos(-1, DdlSubProyecto.SelectedValue.ToEntero()).FiltroPrimeroValor("IVA").ToDouble + 'End If + 'RetIVA = If(PSRow("RetIVA").ToString = "-1", ViewState("RetIVA"), PSRow("RetIVA").ToString).ToString.ToDouble + 'RetISR = If(PSRow("RetISR").ToString = "-1", ViewState("RetISR"), PSRow("RetISR").ToString).ToString.ToDouble + 'IEPSPS = If(PSRow("IEPSPorcentaje").ToString = "-1", ViewState("IEPSPS"), PSRow("IEPSPorcentaje").ToString).ToString.ToDouble + 'IEPSPSIVA = If(PSRow("IEPSGrabaIVA").ToString = "True", PSRow("IEPSPorcentaje").ToString.ToDouble, 0) + End If + End If + + 'UM + DrPS("CveUM") = ddlUM.SelectedValue.ToEntero + DrPS("UM") = ddlUM.SelectedItem.Text + + 'TIPO DE GASTO + DrPS("CveTipoGasto") = DdlTipoGasto.SelectedValue.ToEntero + DrPS("TipoGasto") = If(DdlTipoGasto.SelectedValue.ToEntero > 0, DdlTipoGasto.SelectedItem.Text, "") + + If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then + DrPS("AplicaCostoIndirecto") = "0" + End If + + 'IMPUESTOS: SI ES COMPRA, FACUTRA O CON OC, NO MODIFICA IMPUESTOS!! + 'Dim IVA = (TxtIVAModal.Text.ToDouble / 100) + Dim IVA = Math.Round(DdlIVA.SelectedValue.ToDouble - 1, 2) + Dim RetISR = (TxtRetISRModal.Text.ToDouble / 100) + Dim RetIVA = (TxtRetIVAModal.Text.ToDouble / 100) + Dim IEPSPS = (TxtIEPSModal.Text.ToDouble / 100) + Dim IEPSPSIVA = 0 + + If Not (CveCompra > 0 Or CveFactura > 0 Or OCVinculada) Then + 'If DdlIVA.SelectedValue.ToDouble = 0 Then DrPS("IVA") = 0 Else DrPS("IVA") = IVA * Total + DrPS("IVA") = IVA * Total + DrPS("IVAPorcentaje") = IVA + DrPS("RetIVA") = RetIVA * Total + DrPS("RetIVAPorcentaje") = RetIVA + DrPS("RetISR") = RetISR * Total + DrPS("RetISRPorcentaje") = RetISR + DrPS("IEPSPS") = IEPSPS * Total + DrPS("IEPSPSPorcentaje") = IEPSPS + DrPS("IEPSPSIVA") = IEPSPSIVA * Total + DrPS("IEPSPSIVAPorcentaje") = IEPSPSIVA + AplicaCalculaTotales = True + End If + + TmpDT.AcceptChanges() + + AddPS2(AplicaCalculaTotales) + CargaGvInv() + + End Sub +#End Region + +#Region " RECLASIFICA PARTIDAS - CLASIFICACION - SUBPROYECTO " + Private Sub CargaClasificaciones() + If UsuarioActual.Empresa.UsaAC Then + DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion") + DdlAplicaClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion") + Else + DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros("", Orderby:="Clasificacion") + DdlAplicaClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros("", Orderby:="Clasificacion") + End If + DdlClasificacion.DataBind() + DdlAplicaClasificacion.DataBind() + End Sub + Private Sub BtnAplicarClasificacion_Click(sender As Object, e As EventArgs) Handles BtnAplicarClasificacion.Click + ReclasificaClasificacion() + End Sub + Protected Sub DdlAplicaClasificacion_SelectedIndexChanged(sender As Object, e As EventArgs) + ReclasificaClasificacion() + End Sub + Private Sub ReclasificaClasificacion() + + + If Not DdlAplicaClasificacion.SelectedValue.ToEntero > 0 Then + Exit Sub + End If + + Dim ErrorPS = False + + 'Actualiza Clasificacion directamente a la DB cuando ya se tiene alguna clasificacion + 'Solo cuando el PS ya esta registrado + If UsuarioActual.TienePermisoProceso(104) Then + Dim ObjPS As New ClsProductosServicios + For Each gvr As GridViewRow In GvPS.Rows + If gvr.FCCheckBox("CheckClasificacion").Checked AndAlso gvr.DataKey("CvePS").ToString.ToEntero > 0 Then + If Not ObjPS.UpdateClasificacionPS(DdlAplicaClasificacion.SelectedValue.ToEntero, UsuarioActual.CveUsuario, gvr.DataKey("CvePS").ToString.ToEntero) Then + ErrorPS = True + Exit For + End If + End If + Next + ObjPS.Dispose() + End If + + If Not ErrorPS Then + Dim index = 0 + For Each Dr As DataRow In TmpDT.Rows + If Dr("CvePS").ToString.ToEntero = 0 OrElse Dr("CveClasificacion").ToString.ToEntero <= 0 Then + 'Dr("CveClasificacion") = DdlClasificacion.SelectedValue.ToEntero + Dr("Clasificacion") = DdlAplicaClasificacion.SelectedItem.Text + Dr("CveClasificacionActualizar") = DdlAplicaClasificacion.SelectedValue.ToEntero + ElseIf UsuarioActual.TienePermisoProceso(104) AndAlso GvPS.Rows(index).FCCheckBox("CheckClasificacion").Checked Then + Dr("Clasificacion") = DdlAplicaClasificacion.SelectedItem.Text + Dr("CveClasificacionActualizar") = DdlAplicaClasificacion.SelectedValue.ToEntero + End If + index += 1 + Next + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + Alert("La Clasificacion ha sido aplicada correctamente.", TipoMensaje.MsgInformacion) + + 'Para validar AC + If UsuarioActual.Empresa.UsaAC Then + CompruebaAgregar() + End If + Else + Alert("Ocurrio un error al actualizar la Clasificación de los Productos/Servicios") + End If + -#Region " RECLASIFICA PARTIDAS - CLASIFICACION - SUBPROYECTO " - Private Sub CargaClasificaciones() - If UsuarioActual.Empresa.UsaAC Then - DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion") - DdlAplicaClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion") - Else - DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros("", Orderby:="Clasificacion") - DdlAplicaClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros("", Orderby:="Clasificacion") - End If - DdlClasificacion.DataBind() - DdlAplicaClasificacion.DataBind() - End Sub - Private Sub BtnAplicarClasificacion_Click(sender As Object, e As EventArgs) Handles BtnAplicarClasificacion.Click - ReclasificaClasificacion() - End Sub - Protected Sub DdlAplicaClasificacion_SelectedIndexChanged(sender As Object, e As EventArgs) - ReclasificaClasificacion() - End Sub - Private Sub ReclasificaClasificacion() - - - If Not DdlAplicaClasificacion.SelectedValue.ToEntero > 0 Then - Exit Sub - End If - - Dim ErrorPS = False - - 'Actualiza Clasificacion directamente a la DB cuando ya se tiene alguna clasificacion - 'Solo cuando el PS ya esta registrado - If UsuarioActual.TienePermisoProceso(104) Then - Dim ObjPS As New ClsProductosServicios - For Each gvr As GridViewRow In GvPS.Rows - If gvr.FCCheckBox("CheckClasificacion").Checked AndAlso gvr.DataKey("CvePS").ToString.ToEntero > 0 Then - If Not ObjPS.UpdateClasificacionPS(DdlAplicaClasificacion.SelectedValue.ToEntero, UsuarioActual.CveUsuario, gvr.DataKey("CvePS").ToString.ToEntero) Then - ErrorPS = True - Exit For - End If - End If - Next - ObjPS.Dispose() - End If - - If Not ErrorPS Then - Dim index = 0 - For Each Dr As DataRow In TmpDT.Rows - If Dr("CvePS").ToString.ToEntero = 0 OrElse Dr("CveClasificacion").ToString.ToEntero <= 0 Then - 'Dr("CveClasificacion") = DdlClasificacion.SelectedValue.ToEntero - Dr("Clasificacion") = DdlAplicaClasificacion.SelectedItem.Text - Dr("CveClasificacionActualizar") = DdlAplicaClasificacion.SelectedValue.ToEntero - ElseIf UsuarioActual.TienePermisoProceso(104) AndAlso GvPS.Rows(index).FCCheckBox("CheckClasificacion").Checked Then - Dr("Clasificacion") = DdlAplicaClasificacion.SelectedItem.Text - Dr("CveClasificacionActualizar") = DdlAplicaClasificacion.SelectedValue.ToEntero - End If - index += 1 - Next - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - Alert("La Clasificacion ha sido aplicada correctamente.", TipoMensaje.MsgInformacion) - - 'Para validar AC - If UsuarioActual.Empresa.UsaAC Then - CompruebaAgregar() - End If - Else - Alert("Ocurrio un error al actualizar la Clasificación de los Productos/Servicios") - End If - - - End Sub - - Protected Sub DdlAsignarProyecto_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlAsignarProyecto.SelectedIndexChanged - CargaSubProyectoAsignado() - End Sub - Private Sub CargaProyectoAsignado() - DdlAsignarProyecto.Items.Clear() - DdlAsignarProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"}), GlobalDTProyectos(UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"})) - DdlAsignarProyecto.DataBind() - DdlAsignarProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) - UpReclasificarSubProyecto.Update() - End Sub - Private Sub CargaSubProyectoAsignado() - DdlAsignaSubProyecto.Items.Clear() - If DdlAsignarProyecto.SelectedValue.ToEntero > 0 Then - DdlAsignaSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, DdlAsignarProyecto.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(DdlAsignarProyecto.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa, 1)) - End If - DdlAsignaSubProyecto.DataBind() - DdlAsignaSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) - UpReclasificarSubProyecto.Update() - End Sub - Protected Sub DdlAsignaSubProyecto_SelectedIndexChanged(sender As Object, e As EventArgs) - ReclasificaSubProyecto() - End Sub - Private Sub BtnAsignarSubProyecto_Click(sender As Object, e As EventArgs) Handles BtnAsignarSubProyecto.Click - ReclasificaSubProyecto() - End Sub - Private Sub ReclasificaSubProyecto() - - If Not GvPS.Rows.Count > 0 Then - Alert("No hay partidas para reclasificar el SubProyecto", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If Not DdlAsignaSubProyecto.SelectedValue.ToEntero > 0 Then - Exit Sub - End If - - - Dim CveSubProyecto As Integer - Dim CveProyecto As Integer - If DdlAsignaSubProyecto.SelectedValue.Contains("|") Then - CveSubProyecto = DdlAsignaSubProyecto.SelectedValue.Split("|"c)(0).ToString.ToEntero - Else - CveSubProyecto = DdlAsignaSubProyecto.SelectedValue.ToEntero() - End If - - If DdlAsignarProyecto.SelectedValue.Contains("|") Then - CveProyecto = DdlAsignarProyecto.SelectedValue.Split("|"c)(0).ToString.ToEntero - Else - CveProyecto = DdlAsignarProyecto.SelectedValue.ToEntero() - End If - - For Each Dr As DataRow In TmpDT.Rows - Dr("CveProyecto") = CveProyecto - Dr("Proyecto") = If(CveSubProyecto = -1, "SE", DdlAsignarProyecto.SelectedItem.Text) - Dr("CveSubProyecto") = CveSubProyecto - Dr("SubProyecto") = If(CveSubProyecto = -1, "SE", DdlAsignaSubProyecto.SelectedItem.Text) - Next - - GvPS.DataSource = TmpDT.FiltraParametros("", "Consec") - GvPS.DataBind() - UpPS.Update() - CargaGvPersonal() - - 'Para validar AC - If UsuarioActual.Empresa.UsaAC Then - CompruebaAgregar() - End If - - Alert("SubProyectos cambiados correctamente", TipoMensaje.MsgInformacion) - - End Sub - - - Protected Sub DdlTipoGastoAsignar_SelectedIndexChanged(sender As Object, e As EventArgs) - If Not GvPS.Rows.Count > 0 Then - Alert("No hay partidas para reclasificar el tipo de gasto", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - If Not DdlTipoGastoAsignar.SelectedValue.ToEntero > 0 Then - Exit Sub - End If - - If DdlTipoGastoAsignar.SelectedValue.ToEntero > 0 Then - For Each Dr As DataRow In TmpDT.Rows - Dr("CveTipoGasto") = DdlTipoGastoAsignar.SelectedValue.ToEntero - Dr("TipoGasto") = DdlTipoGastoAsignar.SelectedItem.Text - Next - GvPS.DataSource = TmpDT.FiltraParametros("", "Consec") - GvPS.DataBind() - UpPS.Update() - End If - - If UsuarioActual.Empresa.UsaAC Then - CompruebaAgregar() - End If - - Alert("Los tipos de gastos han sido cambiados correctamente", TipoMensaje.MsgInformacion) - End Sub -#End Region + Protected Sub DdlAsignarProyecto_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlAsignarProyecto.SelectedIndexChanged + CargaSubProyectoAsignado() + End Sub + Private Sub CargaProyectoAsignado() + DdlAsignarProyecto.Items.Clear() + DdlAsignarProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"}), GlobalDTProyectos(UsuarioActual.CveEmpresa, -1).FiltraParametros("", "", {"CveProyecto", "Proyecto"})) + DdlAsignarProyecto.DataBind() + DdlAsignarProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) + UpReclasificarSubProyecto.Update() + End Sub + Private Sub CargaSubProyectoAsignado() + DdlAsignaSubProyecto.Items.Clear() + If DdlAsignarProyecto.SelectedValue.ToEntero > 0 Then + DdlAsignaSubProyecto.DataSource = If(UsuarioActual.Empresa.Funcionalidad(102) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, DdlAsignarProyecto.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(DdlAsignarProyecto.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa, 1)) + End If + DdlAsignaSubProyecto.DataBind() + DdlAsignaSubProyecto.Items.Insert(0, New ListItem("Seleccione", "-1")) + UpReclasificarSubProyecto.Update() + End Sub + Protected Sub DdlAsignaSubProyecto_SelectedIndexChanged(sender As Object, e As EventArgs) + ReclasificaSubProyecto() + End Sub + Private Sub BtnAsignarSubProyecto_Click(sender As Object, e As EventArgs) Handles BtnAsignarSubProyecto.Click + ReclasificaSubProyecto() + End Sub + Private Sub ReclasificaSubProyecto() -#Region " PS ALIAS " - Protected Sub DdlPSAlias_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPSAlias2.selectedindexchange - If Not DdlPSAlias2.SelectedValue = "" Then - Dim DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPSAlias2.SelectedValue.ToEntero).FiltroPrimero("") - If DrPS IsNot Nothing Then - DdlUnidadAlias.DataSource = GlobalDTProductosServiciosEquivalencias(DdlPSAlias2.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) - DdlUnidadAlias.DataBind() - HdnPSAliasCveClasificacion.Value = DrPS("CveClasificacion").ToString - HdnPSAliasClasificacion.Value = DrPS("Clasificacion").ToString - End If - End If - UpPSAlias.Update() - End Sub - Protected Sub BtnAddPSAlias_Click(sender As Object, e As EventArgs) Handles BtnAddPSAlias.Click - Dim PS As New ClsProductosServicios - Dim CvePS = -1 - Dim tPS = "" - - CvePS = DdlPSAlias2.SelectedValue.ToEntero - tPS = DdlPSAlias2.SelectedText - - If PS.AddPSAlias(TxtPSAlias.Text.Trim, CvePS) Then - GlobalDTProductosServiciosAlias(-1) = PS.DtResultados - - TmpDT.Rows(HdnAliasInd.Value.ToEntero)("CvePS") = CvePS - TmpDT.Rows(HdnAliasInd.Value.ToEntero)("PS") = tPS - TmpDT.Rows(HdnAliasInd.Value.ToEntero)("CveUM") = DdlUnidadAlias.SelectedValue.ToEntero - TmpDT.Rows(HdnAliasInd.Value.ToEntero)("UM") = DdlUnidadAlias.SelectedItem.Text - TmpDT.Rows(HdnAliasInd.Value.ToEntero)("CveClasificacion") = HdnPSAliasCveClasificacion.Value.ToEntero - TmpDT.Rows(HdnAliasInd.Value.ToEntero)("Clasificacion") = HdnPSAliasClasificacion.Value - TmpDT.Rows(HdnAliasInd.Value.ToEntero)("Obs") = TxtPSAlias.Text.Trim - - 'busco si el producto está en otros renglones QUE NO LO TENGAN ASIGNADO, LO VINCULE + If Not GvPS.Rows.Count > 0 Then + Alert("No hay partidas para reclasificar el SubProyecto", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If Not DdlAsignaSubProyecto.SelectedValue.ToEntero > 0 Then + Exit Sub + End If + + + Dim CveSubProyecto As Integer + Dim CveProyecto As Integer + If DdlAsignaSubProyecto.SelectedValue.Contains("|") Then + CveSubProyecto = DdlAsignaSubProyecto.SelectedValue.Split("|"c)(0).ToString.ToEntero + Else + CveSubProyecto = DdlAsignaSubProyecto.SelectedValue.ToEntero() + End If + + If DdlAsignarProyecto.SelectedValue.Contains("|") Then + CveProyecto = DdlAsignarProyecto.SelectedValue.Split("|"c)(0).ToString.ToEntero + Else + CveProyecto = DdlAsignarProyecto.SelectedValue.ToEntero() + End If + + For Each Dr As DataRow In TmpDT.Rows + Dr("CveProyecto") = CveProyecto + Dr("Proyecto") = If(CveSubProyecto = -1, "SE", DdlAsignarProyecto.SelectedItem.Text) + Dr("CveSubProyecto") = CveSubProyecto + Dr("SubProyecto") = If(CveSubProyecto = -1, "SE", DdlAsignaSubProyecto.SelectedItem.Text) + Next + + GvPS.DataSource = TmpDT.FiltraParametros("", "Consec") + GvPS.DataBind() + UpPS.Update() + CargaGvPersonal() + + 'Para validar AC + If UsuarioActual.Empresa.UsaAC Then + CompruebaAgregar() + End If + + Alert("SubProyectos cambiados correctamente", TipoMensaje.MsgInformacion) + + End Sub + + + Protected Sub DdlTipoGastoAsignar_SelectedIndexChanged(sender As Object, e As EventArgs) + If Not GvPS.Rows.Count > 0 Then + Alert("No hay partidas para reclasificar el tipo de gasto", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If Not DdlTipoGastoAsignar.SelectedValue.ToEntero > 0 Then + Exit Sub + End If + + If DdlTipoGastoAsignar.SelectedValue.ToEntero > 0 Then + For Each Dr As DataRow In TmpDT.Rows + Dr("CveTipoGasto") = DdlTipoGastoAsignar.SelectedValue.ToEntero + Dr("TipoGasto") = DdlTipoGastoAsignar.SelectedItem.Text + Next + GvPS.DataSource = TmpDT.FiltraParametros("", "Consec") + GvPS.DataBind() + UpPS.Update() + End If + + If UsuarioActual.Empresa.UsaAC Then + CompruebaAgregar() + End If + + Alert("Los tipos de gastos han sido cambiados correctamente", TipoMensaje.MsgInformacion) + + End Sub + +#End Region + +#Region " PS ALIAS " + Protected Sub DdlPSAlias_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPSAlias2.selectedindexchange + If Not DdlPSAlias2.SelectedValue = "" Then + Dim DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPSAlias2.SelectedValue.ToEntero).FiltroPrimero("") + If DrPS IsNot Nothing Then + DdlUnidadAlias.DataSource = GlobalDTProductosServiciosEquivalencias(DdlPSAlias2.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) + DdlUnidadAlias.DataBind() + HdnPSAliasCveClasificacion.Value = DrPS("CveClasificacion").ToString + HdnPSAliasClasificacion.Value = DrPS("Clasificacion").ToString + End If + End If + UpPSAlias.Update() + End Sub + Protected Sub BtnAddPSAlias_Click(sender As Object, e As EventArgs) Handles BtnAddPSAlias.Click + Dim PS As New ClsProductosServicios + Dim CvePS = -1 + Dim tPS = "" + + CvePS = DdlPSAlias2.SelectedValue.ToEntero + tPS = DdlPSAlias2.SelectedText + + If PS.AddPSAlias(TxtPSAlias.Text.Trim, CvePS) Then + GlobalDTProductosServiciosAlias(-1) = PS.DtResultados + + TmpDT.Rows(HdnAliasInd.Value.ToEntero)("CvePS") = CvePS + TmpDT.Rows(HdnAliasInd.Value.ToEntero)("PS") = tPS + TmpDT.Rows(HdnAliasInd.Value.ToEntero)("CveUM") = DdlUnidadAlias.SelectedValue.ToEntero + TmpDT.Rows(HdnAliasInd.Value.ToEntero)("UM") = DdlUnidadAlias.SelectedItem.Text + TmpDT.Rows(HdnAliasInd.Value.ToEntero)("CveClasificacion") = HdnPSAliasCveClasificacion.Value.ToEntero + TmpDT.Rows(HdnAliasInd.Value.ToEntero)("Clasificacion") = HdnPSAliasClasificacion.Value + TmpDT.Rows(HdnAliasInd.Value.ToEntero)("Obs") = TxtPSAlias.Text.Trim + + 'busco si el producto está en otros renglones QUE NO LO TENGAN ASIGNADO, LO VINCULE If UsuarioActual.CveEmpresa <> 141 Then For Each drt As DataRow In TmpDT.Select($"PS ='{TxtPSAlias.Text.Trim}' and ISNULL(CvePS,0) = 0") drt("CvePS") = CvePS @@ -17671,193 +17809,193 @@ Partial Class Compras_Compras drt("Clasificacion") = HdnPSAliasClasificacion.Value drt("Obs") = TxtPSAlias.Text.Trim Next - End If - - TmpDT.AcceptChanges() - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - Alert("Registro actualizado con exito.", TipoMensaje.MsgInformacion) - - RegistraScript("$('#ModalPSAlias').modal('hide');", "ModalPSAliasHide") - End If - PS.Dispose() - - - - End Sub - - Private Sub RecargaGlobalEquivalencias() - 'Dim Hilo As New System.Threading.Thread(AddressOf GeneraGlobalEquivalencias) - 'Hilo.Start() - GeneraGlobalEquivalencias() - End Sub - Private Sub GeneraGlobalEquivalencias() - GlobalDTProductosServiciosEquivalencias(-1, -1, UsuarioActual.CveEmpresa) = Nothing - 'Dim ObjPS = New ClsProductosServicios - 'If ObjPS.GetPSEquivalencias(-1, -1) Then - ' GlobalDTProductosServiciosEquivalencias(-1, -1, UsuarioActual.CveEmpresa) = ObjPS.DtResultados - 'End If - 'ObjPS.Dispose() - End Sub -#End Region + End If -#Region " UM: ALIAS - EQUIVALENCIAS " - Private Sub CargarUMAlias() - DdlUMAlias.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) - DdlUMAlias.DataBind() - DdlUMAlias.Items.Insert(0, New ListItem("Seleccione", "-1")) - UpUMAlias.Update() - End Sub - Protected Sub DdlUMAlias_SelectedIndexChanged(sender As Object, e As EventArgs) - If GlobalDTProductosServiciosEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, DdlUMAlias.SelectedValue.ToEntero, UsuarioActual.CveEmpresa).Rows.Count > 0 Then - RegistraScript("$('#RowUMEquivalencia').addClass('hidden')", "RowUMEquivalenciaShow") - Else - RegistraScript("$('#RowUMEquivalencia').removeClass('hidden')", "RowUMEquivalenciaHide") - End If - RegistraScript("$('#RowUMAlias').removeClass('hidden');$('#LtUMAlias').text('Registrar Unidad de Medida Alias'); $('#BtnUMAlias').val('Registrar Alias'); SetTextEquivalencia(1);", "RowUMAliasHide") - End Sub - Protected Sub BtnUMAlias_Click(sender As Object, e As EventArgs) - Dim ObjUM As New ClsUnidadesMedida - Dim ObjPS As New ClsProductosServicios(ObjUM.IniciaTransacSQL()) - - Dim TieneError = False - Dim DtEquivalencia = GlobalDTProductosServiciosEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) - Dim CveUM = -1 - Dim UM = "" - Dim Equivalencia = 0.0 - - - Select Case HdnUMAliasModalidad.Value.ToEntero - Case 1 'AGREGA ALIAS - If Not ObjUM.AddUnidadMedidaAlias(TxtUMAlias.Text.Trim, DdlUMAlias.SelectedValue.ToEntero, If(HdnUMAliasCveSATUM.Value.ToEntero > 0, HdnUMAliasCveSATUM.Value.ToEntero, -1)) Then - TieneError = True - End If - - 'SI NO TIENE EQUIVALENCIA DEL PS - AGREGA LA EQUIVALENCIA - If Not TieneError Then - If Not GlobalDTProductosServiciosEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, DdlUMAlias.SelectedValue.ToEntero, UsuarioActual.CveEmpresa).Rows.Count > 0 Then - If Not ObjPS.AddPSEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, DdlUMAlias.SelectedValue.ToEntero, TxtUMEquivalenciaCantidad.Text.ToDecimal, False, 0, UsuarioActual.CveUsuario) Then - TieneError = True - End If - End If - End If - - 'CveUM = DtEquivalencia.FiltroPrimeroValor("CveUM", "UnidadBase = 1").ToEntero - 'UM = DtEquivalencia.FiltroPrimeroValor("UM", "UnidadBase = 1") - CveUM = DdlUMAlias.SelectedValue.ToEntero - UM = TxtUMAlias.Text.Trim - Equivalencia = TxtUMEquivalenciaCantidad.Text.ToDouble - - Case 2 - - Case 3 'AGREGA EQUIVALENCIA - CveUM = DtEquivalencia.FiltroPrimeroValor("CveUM", "UnidadBase = 1").ToEntero - UM = DtEquivalencia.FiltroPrimeroValor("UM", "UnidadBase = 1") - Equivalencia = TxtUMEquivalenciaCantidad.Text.ToDouble - If Not TieneError Then - If Not ObjPS.AddPSEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CveUM").ToString.ToEntero, TxtUMEquivalenciaCantidad.Text.ToDecimal, False, 0, UsuarioActual.CveUsuario) Then - TieneError = True - End If - End If - Case 4 'AGREGA UNIDAD DE MEDIDA - - CveUM = ObjUM.AddUnidadMedida(TxtUMAlias.Text.Trim, TxtUMAbreviatura.Text.Trim, "", "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, If(HdnUMAliasCveSATUM.Value.ToEntero > 0, HdnUMAliasCveSATUM.Value.ToEntero, -1)) - UM = TxtUMAlias.Text.Trim - Equivalencia = TxtUMEquivalenciaCantidad.Text.ToDouble - - If Not CveUM > 0 Then - TieneError = True - End If - - 'AGREGA LA EQUIVALENCIA - If Not TieneError Then - If Not ObjPS.AddPSEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, CveUM, TxtUMEquivalenciaCantidad.Text.ToDecimal, False, 0, UsuarioActual.CveUsuario) Then - TieneError = True - End If - End If - - 'AGREGA ALIAS SI ES DIFERENTE EL TEXTO AL QUE VIENE EN EL XML - If Not TieneError And TxtUMAlias.Text.Trim <> HdnUMAlias.Value Then - If Not ObjUM.AddUnidadMedidaAlias(HdnUMAlias.Value, CveUM) Then - TieneError = True - End If - End If - - 'CveUM = DtEquivalencia.FiltroPrimeroValor("CveUM", "UnidadBase = 1").ToEntero - 'UM = DtEquivalencia.FiltroPrimeroValor("UM", "UnidadBase = 1") - - Case Else - - End Select - - If Not TieneError Then - ObjPS.Commit() - Alert("Unidad de medida actualizada correctamente.", TipoMensaje.MsgInformacion) - - 'ACTUALIZA DIRECTO DT - Dim Dr = TmpDT.Rows(HdnUMAliasInd.Value.ToEntero) - Dim CvePSModificado = Dr("CvePS").ToString.ToEntero - Dim CveUMModificada = Dr("CveUM").ToString.ToEntero - Dim UMModificada = Dr("UM").ToString - - For Each DrUM As DataRow In TmpDT.Rows - If DrUM("CveUM").ToString.ToEntero = CveUMModificada And DrUM("UM").ToString = UMModificada Then - DrUM("CveUM") = CveUM - DrUM("UM") = UM - If Equivalencia > 0 Then - DrUM("Cantidad") = DrUM("Cantidad").ToString.ToDouble * Equivalencia - DrUM("PU") = DrUM("PU").ToString.ToDouble / Equivalencia - End If - TmpDT.AcceptChanges() - End If - Next - - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - - RegistraScript("$('#ModalUMAlias').modal('hide');", "ModalUMAliasHide") - DdlUMAlias.SelectedValue = "-1" - UpUMAlias.Update() - - RecargaGlobalUM() - Else - ObjPS.RollBack() - Alert("Ocurrió un error al guardar la unidad de medida", TipoMensaje.MsgError) - End If - - ObjPS.Dispose() - End Sub - Protected Sub LBAplicarEquivalencia_Click(sender As Object, e As EventArgs) - Dim Dr = TmpDT.Rows(CType(CType(sender, LinkButton).NamingContainer, GridViewRow).RowIndex) - Dim DtEquivalencia = GlobalDTProductosServiciosEquivalencias(Dr("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) - Dim Equivalencia = DtEquivalencia.FiltroPrimeroValor("Cantidad", $"CveUM = {Dr("CveUM")}").ToDouble - - If Equivalencia > 0 Then - Dr("CveUM") = DtEquivalencia.FiltroPrimeroValor("CveUM", "UnidadBase = 1") - Dr("UM") = DtEquivalencia.FiltroPrimeroValor("UM", "UnidadBase = 1") - Dr("Cantidad") = Dr("Cantidad").ToString.ToDouble * Equivalencia - Dr("PU") = Math.Round(Dr("PU").ToString.ToDouble / Equivalencia, 6) - - TmpDT.AcceptChanges() - GvPS.DataSource = TmpDT - GvPS.DataBind() - UpPS.Update() - Else - Alert("La cantidad de equivalencia de la unidad de medida debe ser mayor a 0", TipoMensaje.MsgAdvertencia) - End If - - End Sub - Private Sub RecargaGlobalUM() - 'Dim Hilo As New System.Threading.Thread(AddressOf GeneraGlobalUM) - 'Hilo.Start() - GeneraGlobalUM() - End Sub + TmpDT.AcceptChanges() + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + Alert("Registro actualizado con exito.", TipoMensaje.MsgInformacion) + + RegistraScript("$('#ModalPSAlias').modal('hide');", "ModalPSAliasHide") + End If + PS.Dispose() + + + + End Sub + + Private Sub RecargaGlobalEquivalencias() + 'Dim Hilo As New System.Threading.Thread(AddressOf GeneraGlobalEquivalencias) + 'Hilo.Start() + GeneraGlobalEquivalencias() + End Sub + Private Sub GeneraGlobalEquivalencias() + GlobalDTProductosServiciosEquivalencias(-1, -1, UsuarioActual.CveEmpresa) = Nothing + 'Dim ObjPS = New ClsProductosServicios + 'If ObjPS.GetPSEquivalencias(-1, -1) Then + ' GlobalDTProductosServiciosEquivalencias(-1, -1, UsuarioActual.CveEmpresa) = ObjPS.DtResultados + 'End If + 'ObjPS.Dispose() + End Sub +#End Region + +#Region " UM: ALIAS - EQUIVALENCIAS " + Private Sub CargarUMAlias() + DdlUMAlias.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) + DdlUMAlias.DataBind() + DdlUMAlias.Items.Insert(0, New ListItem("Seleccione", "-1")) + UpUMAlias.Update() + End Sub + Protected Sub DdlUMAlias_SelectedIndexChanged(sender As Object, e As EventArgs) + If GlobalDTProductosServiciosEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, DdlUMAlias.SelectedValue.ToEntero, UsuarioActual.CveEmpresa).Rows.Count > 0 Then + RegistraScript("$('#RowUMEquivalencia').addClass('hidden')", "RowUMEquivalenciaShow") + Else + RegistraScript("$('#RowUMEquivalencia').removeClass('hidden')", "RowUMEquivalenciaHide") + End If + RegistraScript("$('#RowUMAlias').removeClass('hidden');$('#LtUMAlias').text('Registrar Unidad de Medida Alias'); $('#BtnUMAlias').val('Registrar Alias'); SetTextEquivalencia(1);", "RowUMAliasHide") + End Sub + Protected Sub BtnUMAlias_Click(sender As Object, e As EventArgs) + Dim ObjUM As New ClsUnidadesMedida + Dim ObjPS As New ClsProductosServicios(ObjUM.IniciaTransacSQL()) + + Dim TieneError = False + Dim DtEquivalencia = GlobalDTProductosServiciosEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) + Dim CveUM = -1 + Dim UM = "" + Dim Equivalencia = 0.0 + + + Select Case HdnUMAliasModalidad.Value.ToEntero + Case 1 'AGREGA ALIAS + If Not ObjUM.AddUnidadMedidaAlias(TxtUMAlias.Text.Trim, DdlUMAlias.SelectedValue.ToEntero, If(HdnUMAliasCveSATUM.Value.ToEntero > 0, HdnUMAliasCveSATUM.Value.ToEntero, -1)) Then + TieneError = True + End If + + 'SI NO TIENE EQUIVALENCIA DEL PS - AGREGA LA EQUIVALENCIA + If Not TieneError Then + If Not GlobalDTProductosServiciosEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, DdlUMAlias.SelectedValue.ToEntero, UsuarioActual.CveEmpresa).Rows.Count > 0 Then + If Not ObjPS.AddPSEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, DdlUMAlias.SelectedValue.ToEntero, TxtUMEquivalenciaCantidad.Text.ToDecimal, False, 0, UsuarioActual.CveUsuario) Then + TieneError = True + End If + End If + End If + + 'CveUM = DtEquivalencia.FiltroPrimeroValor("CveUM", "UnidadBase = 1").ToEntero + 'UM = DtEquivalencia.FiltroPrimeroValor("UM", "UnidadBase = 1") + CveUM = DdlUMAlias.SelectedValue.ToEntero + UM = TxtUMAlias.Text.Trim + Equivalencia = TxtUMEquivalenciaCantidad.Text.ToDouble + + Case 2 + + Case 3 'AGREGA EQUIVALENCIA + CveUM = DtEquivalencia.FiltroPrimeroValor("CveUM", "UnidadBase = 1").ToEntero + UM = DtEquivalencia.FiltroPrimeroValor("UM", "UnidadBase = 1") + Equivalencia = TxtUMEquivalenciaCantidad.Text.ToDouble + If Not TieneError Then + If Not ObjPS.AddPSEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CveUM").ToString.ToEntero, TxtUMEquivalenciaCantidad.Text.ToDecimal, False, 0, UsuarioActual.CveUsuario) Then + TieneError = True + End If + End If + Case 4 'AGREGA UNIDAD DE MEDIDA + + CveUM = ObjUM.AddUnidadMedida(TxtUMAlias.Text.Trim, TxtUMAbreviatura.Text.Trim, "", "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, If(HdnUMAliasCveSATUM.Value.ToEntero > 0, HdnUMAliasCveSATUM.Value.ToEntero, -1)) + UM = TxtUMAlias.Text.Trim + Equivalencia = TxtUMEquivalenciaCantidad.Text.ToDouble + + If Not CveUM > 0 Then + TieneError = True + End If + + 'AGREGA LA EQUIVALENCIA + If Not TieneError Then + If Not ObjPS.AddPSEquivalencias(TmpDT.Rows(HdnUMAliasInd.Value.ToEntero)("CvePS").ToString.ToEntero, CveUM, TxtUMEquivalenciaCantidad.Text.ToDecimal, False, 0, UsuarioActual.CveUsuario) Then + TieneError = True + End If + End If + + 'AGREGA ALIAS SI ES DIFERENTE EL TEXTO AL QUE VIENE EN EL XML + If Not TieneError And TxtUMAlias.Text.Trim <> HdnUMAlias.Value Then + If Not ObjUM.AddUnidadMedidaAlias(HdnUMAlias.Value, CveUM) Then + TieneError = True + End If + End If + + 'CveUM = DtEquivalencia.FiltroPrimeroValor("CveUM", "UnidadBase = 1").ToEntero + 'UM = DtEquivalencia.FiltroPrimeroValor("UM", "UnidadBase = 1") + + Case Else + + End Select + + If Not TieneError Then + ObjPS.Commit() + Alert("Unidad de medida actualizada correctamente.", TipoMensaje.MsgInformacion) + + 'ACTUALIZA DIRECTO DT + Dim Dr = TmpDT.Rows(HdnUMAliasInd.Value.ToEntero) + Dim CvePSModificado = Dr("CvePS").ToString.ToEntero + Dim CveUMModificada = Dr("CveUM").ToString.ToEntero + Dim UMModificada = Dr("UM").ToString + + For Each DrUM As DataRow In TmpDT.Rows + If DrUM("CveUM").ToString.ToEntero = CveUMModificada And DrUM("UM").ToString = UMModificada Then + DrUM("CveUM") = CveUM + DrUM("UM") = UM + If Equivalencia > 0 Then + DrUM("Cantidad") = DrUM("Cantidad").ToString.ToDouble * Equivalencia + DrUM("PU") = DrUM("PU").ToString.ToDouble / Equivalencia + End If + TmpDT.AcceptChanges() + End If + Next + + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + + RegistraScript("$('#ModalUMAlias').modal('hide');", "ModalUMAliasHide") + DdlUMAlias.SelectedValue = "-1" + UpUMAlias.Update() + + RecargaGlobalUM() + Else + ObjPS.RollBack() + Alert("Ocurrió un error al guardar la unidad de medida", TipoMensaje.MsgError) + End If + + ObjPS.Dispose() + End Sub + Protected Sub LBAplicarEquivalencia_Click(sender As Object, e As EventArgs) + Dim Dr = TmpDT.Rows(CType(CType(sender, LinkButton).NamingContainer, GridViewRow).RowIndex) + Dim DtEquivalencia = GlobalDTProductosServiciosEquivalencias(Dr("CvePS").ToString.ToEntero, -1, UsuarioActual.CveEmpresa) + Dim Equivalencia = DtEquivalencia.FiltroPrimeroValor("Cantidad", $"CveUM = {Dr("CveUM")}").ToDouble + + If Equivalencia > 0 Then + Dr("CveUM") = DtEquivalencia.FiltroPrimeroValor("CveUM", "UnidadBase = 1") + Dr("UM") = DtEquivalencia.FiltroPrimeroValor("UM", "UnidadBase = 1") + Dr("Cantidad") = Dr("Cantidad").ToString.ToDouble * Equivalencia + Dr("PU") = Math.Round(Dr("PU").ToString.ToDouble / Equivalencia, 6) + + TmpDT.AcceptChanges() + GvPS.DataSource = TmpDT + GvPS.DataBind() + UpPS.Update() + Else + Alert("La cantidad de equivalencia de la unidad de medida debe ser mayor a 0", TipoMensaje.MsgAdvertencia) + End If + + End Sub + Private Sub RecargaGlobalUM() + 'Dim Hilo As New System.Threading.Thread(AddressOf GeneraGlobalUM) + 'Hilo.Start() + GeneraGlobalUM() + End Sub Private Sub GeneraGlobalUM() - GlobalDTProductosServiciosEquivalencias(-1, -1, UsuarioActual.CveEmpresa) = Nothing + GlobalDTProductosServiciosEquivalencias(-1, -1, UsuarioActual.CveEmpresa) = Nothing GlobalDTUnidadesMedidaAlias(UsuarioActual.CveEmpresa) = Nothing 'Dim ObjPS = New ClsProductosServicios 'Dim OjbUM As New ClsUnidadesMedida @@ -17874,55 +18012,55 @@ Partial Class Compras_Compras 'OjbUM.Dispose() End Sub -#End Region +#End Region -#Region " COMPLEMENTOS PAGO " +#Region " COMPLEMENTOS PAGO " + + Private Sub CargaComplementosPago() + + Dim ObjCompras As New ClsCompras + + If ObjCompras.GetCompraComplementoPago(CveCompra, UsuarioActual.CveEmpresa) Then + GvComplementoPagos.DataSource = ObjCompras.DtResultados + LnkCompleplementos.Visible = ObjCompras.DtResultados.Rows.Count > 0 + Else + GvComplementoPagos.DataSource = Nothing + LnkCompleplementos.Visible = False + End If + + If UsuarioActual.TienePermisoProceso(272) Then + GvComplementoPagos.Columns(5).Visible = True + End If + + ObjCompras.Dispose() + + GvComplementoPagos.DataBind() + UpComplementoPagos.Update() - Private Sub CargaComplementosPago() - - Dim ObjCompras As New ClsCompras - - If ObjCompras.GetCompraComplementoPago(CveCompra, UsuarioActual.CveEmpresa) Then - GvComplementoPagos.DataSource = ObjCompras.DtResultados - LnkCompleplementos.Visible = ObjCompras.DtResultados.Rows.Count > 0 - Else - GvComplementoPagos.DataSource = Nothing - LnkCompleplementos.Visible = False - End If - - If UsuarioActual.TienePermisoProceso(272) Then - GvComplementoPagos.Columns(5).Visible = True - End If - - ObjCompras.Dispose() - - GvComplementoPagos.DataBind() - UpComplementoPagos.Update() - - End Sub - Protected Sub GvComplementoPagos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvComplementoPagos.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - e.Row.Cells(3).Text = String.Format("", Encripta(String.Format("OP=Fact&EXT=xml&CveFactura={0}&RFC={1}", e.Row.DBCampo("CveFactura"), e.Row.DBCampo(("RFCde").ToString.Replace("&", "%26%"))))) - e.Row.Cells(4).Text = String.Format("", Encripta(String.Format("OP=Fact&EXT=pdf&CveFactura={0}&RFC={1}", e.Row.DBCampo("CveFactura"), e.Row.DBCampo("RFCde").ToString.Replace("&", "%26%")))) - End If End Sub -#End Region + Protected Sub GvComplementoPagos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvComplementoPagos.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + e.Row.Cells(3).Text = String.Format("", Encripta(String.Format("OP=Fact&EXT=xml&CveFactura={0}&RFC={1}", e.Row.DBCampo("CveFactura"), e.Row.DBCampo(("RFCde").ToString.Replace("&", "%26%"))))) + e.Row.Cells(4).Text = String.Format("", Encripta(String.Format("OP=Fact&EXT=pdf&CveFactura={0}&RFC={1}", e.Row.DBCampo("CveFactura"), e.Row.DBCampo("RFCde").ToString.Replace("&", "%26%")))) + End If + End Sub +#End Region -#Region " OTROS GASTOS " +#Region " OTROS GASTOS " - Protected Sub LnkAddOtrosGastos_Click(sender As Object, e As EventArgs) - DdlOrdenCorte.SelectedIndex = 0 - DdlOrdenCorte.SelectedValueExist(CveOrdenCorte) - UpOtrosGastos.Update() - RegistraScript("$('#DivOtrosGastos').modal();") - End Sub - - Protected Sub BtnAddOtrosGastos_Click(sender As Object, e As EventArgs) - CveOrdenCorte = DdlOrdenCorte.SelectedValue.ToEntero() - RegistraScript("$('#DivOtrosGastos').modal('hide');") + Protected Sub LnkAddOtrosGastos_Click(sender As Object, e As EventArgs) + DdlOrdenCorte.SelectedIndex = 0 + DdlOrdenCorte.SelectedValueExist(CveOrdenCorte) + UpOtrosGastos.Update() + RegistraScript("$('#DivOtrosGastos').modal();") End Sub -#End Region + Protected Sub BtnAddOtrosGastos_Click(sender As Object, e As EventArgs) + CveOrdenCorte = DdlOrdenCorte.SelectedValue.ToEntero() + RegistraScript("$('#DivOtrosGastos').modal('hide');") + End Sub + +#End Region '#Region " DROPDOWN IVA " ' 'Protected Sub DdlIVA_SelectedIndexChanged(sender As Object, e As EventArgs) @@ -17930,1099 +18068,1099 @@ Partial Class Compras_Compras ' 'End Sub '#End Region -#Region " APLICA NC " +#Region " APLICA NC " - Private Sub InicializaAplicaNCFact() - HLAplicaNCFact.Visible = True - LblTotalNC.Text = TxtTotal.Text.FormatoNumero - CargaCuentasXPagar() - End Sub - - Private Sub CargaCuentasXPagar() - Dim ObjMovtos As New ClsMovimientos() - If ObjMovtos.GetCxPProveedor(CveProveedor, "-1", "-1", -1, -1, -1, -1, -1, -1, -1, -1, "-1", "-1") Then - GvFacturaNC.DataSource = ObjMovtos.DtResultados.FiltraParametros("Saldo > 0") - TmpCXP = ObjMovtos.DtResultados.FiltraParametros("Saldo > 0") - End If - ObjMovtos.Dispose() - GvFacturaNC.DataBind() - UpFacturaNC.Update() - End Sub - Protected Sub GvFacturaNC_RowDataBound(sender As Object, e As GridViewRowEventArgs) - If e.Row.RowType = DataControlRowType.DataRow Then - If Not e.Row.DBCampo("CveCompra").ToEntero > 0 Then - e.Row.CssClass = "Totales" - e.Row.Cells(0).Text = "" - e.Row.Cells(4).Text = "" - Else - e.Row.FCTextBox("TxtImporte").Attributes.Add("onkeyup", $"LimitaCantidadNC({e.Row.DBCampo("Saldo").ToDouble},{TxtTotal.Text.ToDouble}, this);") - e.Row.FCCheckBox("ChkFacturaNC").Attributes.Add("onclick", $"FnCambiaFacturaNC({e.Row.DBCampo("Saldo").ToDouble},{e.Row.FCTextBox("TxtImporte").ClientID},{TxtTotal.Text.ToDouble},{LblAplicado.ClientID}, this);") - End If - End If + Private Sub InicializaAplicaNCFact() + HLAplicaNCFact.Visible = True + LblTotalNC.Text = TxtTotal.Text.FormatoNumero + CargaCuentasXPagar() End Sub -#End Region - -#Region " DEVOLUCION DE ALMACEN - DEVOLUCION AL PROVEEDOR " - Private Sub InicializaDevolucionAlmacen() - If Not GvInv.Rows.Count > 0 Or LblCompraEstatus.Text = "CANCELADA" Then - Exit Sub - End If - - If CveCompra > 0 Then - 'If CveVenta > 0 And DdlTipoComprobante.SelectedValue.Contiene({"Rem", "Ped"}) Then - - If Not EstatusAlmacen = 2 Then - LiDevolucionAlmacen.Visible = True - End If - - If EstatusAlmacen = 1 Then - LBDevolucionAlmacen.Text = " Cancelar Devolución Almacén" - LBDevolucionAlmacen.ToolTip = "¿Está seguro de Cancelar la Devolución de Almacén?" - Else - LBDevolucionAlmacen.Text = " Solicitar Devolución Almacén" - LBDevolucionAlmacen.ToolTip = "¿Está seguro de Solicitar la Devolución de Almacén?" - End If - - End If - - 'UpInvDev.Update() - End Sub - Protected Sub LBDevolucionAlmacen_Click(sender As Object, e As EventArgs) - Dim ObjCompras As New ClsCompras - - If ObjCompras.UpdateEstatusAlmacen(CveCompra, If(EstatusAlmacen = 1, 0, 1)) Then - EstatusAlmacen = If(EstatusAlmacen = 1, 0, 1) - Alert(If(EstatusAlmacen = 1, "La solicitud de devolución de almacen se guardo correctamente.", "La solicitud de almacen se canceló correctamente.")) - End If - - ObjCompras.Dispose() - - InicializaDevolucionAlmacen() - End Sub - - Private Sub HabilitaNCInv() - - If Not UsuarioActual.CveUsuario = 100 Then - If Not UsuarioActual.CveEmpresa.Contiene(72, 119, 80) Then - Exit Sub - End If - End If - - - If CveCompra > 0 And GvInvMov.Rows.Count > 0 Then - - Dim ObjInventarios As New ClsInventarios - If ObjInventarios.RecepcionAlmacenGet(CveCompra, -1, UsuarioActual.CveEmpresa) AndAlso ObjInventarios.DtResultados.Rows.Count > 0 Then - DtPendientesAlmacen = ObjInventarios.DtResultados.FiltraParametros("CantidadF > 0").Copy - End If - ObjInventarios.Dispose() - - If DtPendientesAlmacen IsNot Nothing AndAlso DtPendientesAlmacen.Rows.Count > 0 Then - ChkNCInv.Visible = True - GVNCInv.DataSource = DtPendientesAlmacen - GVNCInv.DataBind() - End If - - End If - End Sub - Protected Sub ChkNCInv_CheckedChanged(sender As Object, e As EventArgs) - CargaAnticipos(CveProveedor, If(ChkNCInv.Checked, "NC", "-1")) - UpAnticipos.Update() - End Sub - Private Sub CargaNCINV() - - Dim SaldoAnticipo = 0.0 - Dim CveCompras As String = "" - If ChkNCInvNC.Checked Then - For Each gvr As GridViewRow In GvFacturaNC.Rows - If gvr.FCCheckBox("ChkFacturaNC") IsNot Nothing AndAlso gvr.FCCheckBox("ChkFacturaNC").Checked Then - SaldoAnticipo += gvr.FCTextBox("TxtImporte").Text.ToDouble - If CveCompras <> "" Then - CveCompras = $"{CveCompras},{gvr.DataKey("CveCompra").ToString}" - Else - CveCompras = gvr.DataKey("CveCompra").ToString - End If - End If - Next - Else - For Each gvr As GridViewRow In GVAnticipos.Rows - If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then - SaldoAnticipo += gvr.FCTextBox("TxtAnticipo").Text.ToDouble - End If - Next - End If - - - If SaldoAnticipo <= 0 Then - Alert("No hay movimientos seleccionados para aplicar", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - - LbNCInvSaldo.Text = SaldoAnticipo.FormatoNumero() - - If ChkNCInvNC.Checked Then - Dim ObjInventarios As New ClsInventarios - If ObjInventarios.RecepcionAlmacenGet(-1, -1, UsuarioActual.CveEmpresa, CveProveedor) AndAlso ObjInventarios.DtResultados.FiltraParametros($"CveCompra IN ({CveCompras}) AND CantidadF > 0").Rows.Count > 0 Then - DtPendientesAlmacen = ObjInventarios.DtResultados.FiltraParametros($"CveCompra IN ({CveCompras}) AND CantidadF > 0").Copy - End If - ObjInventarios.Dispose() - End If - - If (DtPendientesAlmacen IsNot Nothing AndAlso DtPendientesAlmacen.Rows.Count > 0) Then - If ChkNCInvNC.Checked Then - GVNCInv.DataSource = DtPendientesAlmacen - GVNCInv.DataBind() - UpNCInv.Update() - RegistraScript("$('#FacturaNC').modal('hide');", "FacturaNC") - End If - RegistraScript("$('#ModalNCInv').modal('show');", "ModalNCInv") - Else - If ChkNCInvNC.Checked Then - Alert("Niguna de las facturas seleccionadas cuenta con productos pendientes de darles entrada.", TipoMensaje.MsgAdvertencia) - ChkNCInvNC.Checked = False - UpChkNCInvNC.Update() - Exit Sub - Else - RegistraScript("$('#ModalNCConfirmación').modal('show');", "ModalNCInv") - End If - End If - - UpNCInv.Update() - - End Sub - Protected Sub GVNCInv_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVNCInv.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - 'e.Row.FCCheckBox("cbInv").Attributes.Add("onclick", "FnCambiaInvNC(this);") - e.Row.FCTextBox("TxtCantidadNCInv").Attributes.Add("onkeyup", $"ValidarCantidad(this,{e.Row.DBCampo("CantidadF")});FnCambiaInvNC(this);") - End If - End Sub - Protected Sub BtnNCInv_Click(sender As Object, e As EventArgs) - - If ChkNCInvNC.Checked Then - RegistraScript("$('#ModalNCInv').modal('hide');", "ModalNCInv") - RegistraScript("$('#DivAnticipos').modal('hide');", "FacturaNC") - Exit Sub - End If - - Dim Contador = 0 - Dim CveCompraNC = -1 - For Each gvr As GridViewRow In GVAnticipos.Rows - If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then - Contador += 1 - CveCompraNC = gvr.DataKey("CveCompra").ToString.ToEntero - End If - Next - - If Contador <> 1 Then - Alert("Debe seleccionar por lo menos una NC a aplicar.", TipoMensaje.MsgAdvertencia) - RegistraScript("$('#ModalNCInv').modal('hide');", "ModalNCInv") - RegistraScript("$('#DivAnticipos').modal('hide');", "ModalAnticipos") - Exit Sub - End If - - If Not CveCompraNC > 0 Then - Alert("Ocurrió un error al guardar la cancelación de inventarios. Por favor comuniquese con asistencia SIG", TipoMensaje.MsgError) - Exit Sub - End If - - - Dim ObjCompras As New ClsCompras - Dim ObjConta As New ClsContabilidad(ObjCompras.IniciaTransacSQL) - Dim TieneError = False - - For Each Gvr As GridViewRow In GVNCInv.Rows - If Gvr.FCTextBox("TxtCantidadNCInv").Text.ToDouble > 0 Then - If Not ObjCompras.ComprasDetalleDevolucionesAdd(Gvr.DataKey("CveCompraDetalle").ToEntero, CveCompraNC, Gvr.FCTextBox("TxtCantidadNCInv").Text.ToDouble, UsuarioActual.CveEmpresa) Then - TieneError = True - Exit For - End If - End If - Next - - If Not TieneError Then - GuardaAnticipos(ObjCompras, ObjConta) - Else - ObjCompras.RollBack() - End If - - ObjCompras.Dispose() - RegistraScript("$('#ModalNCInv').modal('hide');", "ModalNCInv") - RegistraScript("$('#DivAnticipos').modal('hide');", "ModalAnticipos") - - End Sub - Protected Sub BtnNCConfirmacion_Click(sender As Object, e As EventArgs) - GuardaAnticipos(Nothing, Nothing) + Private Sub CargaCuentasXPagar() + Dim ObjMovtos As New ClsMovimientos() + If ObjMovtos.GetCxPProveedor(CveProveedor, "-1", "-1", -1, -1, -1, -1, -1, -1, -1, -1, "-1", "-1") Then + GvFacturaNC.DataSource = ObjMovtos.DtResultados.FiltraParametros("Saldo > 0") + TmpCXP = ObjMovtos.DtResultados.FiltraParametros("Saldo > 0") + End If + ObjMovtos.Dispose() + GvFacturaNC.DataBind() + UpFacturaNC.Update() + End Sub + Protected Sub GvFacturaNC_RowDataBound(sender As Object, e As GridViewRowEventArgs) + If e.Row.RowType = DataControlRowType.DataRow Then + If Not e.Row.DBCampo("CveCompra").ToEntero > 0 Then + e.Row.CssClass = "Totales" + e.Row.Cells(0).Text = "" + e.Row.Cells(4).Text = "" + Else + e.Row.FCTextBox("TxtImporte").Attributes.Add("onkeyup", $"LimitaCantidadNC({e.Row.DBCampo("Saldo").ToDouble},{TxtTotal.Text.ToDouble}, this);") + e.Row.FCCheckBox("ChkFacturaNC").Attributes.Add("onclick", $"FnCambiaFacturaNC({e.Row.DBCampo("Saldo").ToDouble},{e.Row.FCTextBox("TxtImporte").ClientID},{TxtTotal.Text.ToDouble},{LblAplicado.ClientID}, this);") + End If + End If End Sub -#End Region -#Region " INVENTARIO: MOVIMIENTOS DE LA COMPRA " - Private Sub InventarioMov() - Dim ObjVentas As New ClsInventarios - - If ObjVentas.GetInv_ComprasMov(CveCompra, UsuarioActual.CveEmpresa) Then - If ObjVentas.DtResultados.Rows.Count > 0 Then - GvInvMov.DataSource = ObjVentas.DtResultados - End If - End If - GvInvMov.DataBind() - GvInvMov.Visible = True - - ObjVentas.Dispose() - UpINV.Update() - End Sub - Private Sub GvInvMov_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvInvMov.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - If e.Row.DBCampo("CvePS") = "" Then - e.Row.FCLiteral("LtlPS").Text = String.Format("Folio: {1} Fecha: {2} {3} {4}", e.Row.DBCampo("CveMovimiento"), e.Row.DBCampo("Folio"), e.Row.DBCampo("Fecha").ToString.ToDate.ToShortDateString, e.Row.DBCampo("Almacen").ToString, e.Row.DBCampo("Concepto").ToString) - - If e.Row.DataKey("Origen").ToEntero > 0 Then - e.Row.CssClass = "SubTotales" - Else - e.Row.BackColor = Drawing.Color.FromArgb(224, 130, 131) - e.Row.ForeColor = Drawing.Color.White - e.Row.Font.Bold = True - End If - Else - e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Left - End If - End If - End Sub - - Private Sub GvAcarreo_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvAcarreo.RowDataBound - If e.Row.RowType = DataControlRowType.DataRow Then - e.Row.FCLiteral("LtlImporte").Text = "$" + FormatNumber(e.Row.FCLiteral("LtlImporte").Text.ToDouble, 2, , , TriState.True) - End If +#End Region + +#Region " DEVOLUCION DE ALMACEN - DEVOLUCION AL PROVEEDOR " + Private Sub InicializaDevolucionAlmacen() + If Not GvInv.Rows.Count > 0 Or LblCompraEstatus.Text = "CANCELADA" Then + Exit Sub + End If + + If CveCompra > 0 Then + 'If CveVenta > 0 And DdlTipoComprobante.SelectedValue.Contiene({"Rem", "Ped"}) Then + + If Not EstatusAlmacen = 2 Then + LiDevolucionAlmacen.Visible = True + End If + + If EstatusAlmacen = 1 Then + LBDevolucionAlmacen.Text = " Cancelar Devolución Almacén" + LBDevolucionAlmacen.ToolTip = "¿Está seguro de Cancelar la Devolución de Almacén?" + Else + LBDevolucionAlmacen.Text = " Solicitar Devolución Almacén" + LBDevolucionAlmacen.ToolTip = "¿Está seguro de Solicitar la Devolución de Almacén?" + End If + + End If + + 'UpInvDev.Update() + End Sub + Protected Sub LBDevolucionAlmacen_Click(sender As Object, e As EventArgs) + Dim ObjCompras As New ClsCompras + + If ObjCompras.UpdateEstatusAlmacen(CveCompra, If(EstatusAlmacen = 1, 0, 1)) Then + EstatusAlmacen = If(EstatusAlmacen = 1, 0, 1) + Alert(If(EstatusAlmacen = 1, "La solicitud de devolución de almacen se guardo correctamente.", "La solicitud de almacen se canceló correctamente.")) + End If + + ObjCompras.Dispose() + + InicializaDevolucionAlmacen() + End Sub + + Private Sub HabilitaNCInv() + + If Not UsuarioActual.CveUsuario = 100 Then + If Not UsuarioActual.CveEmpresa.Contiene(72, 119, 80) Then + Exit Sub + End If + End If + + + If CveCompra > 0 And GvInvMov.Rows.Count > 0 Then + + Dim ObjInventarios As New ClsInventarios + If ObjInventarios.RecepcionAlmacenGet(CveCompra, -1, UsuarioActual.CveEmpresa) AndAlso ObjInventarios.DtResultados.Rows.Count > 0 Then + DtPendientesAlmacen = ObjInventarios.DtResultados.FiltraParametros("CantidadF > 0").Copy + End If + ObjInventarios.Dispose() + + If DtPendientesAlmacen IsNot Nothing AndAlso DtPendientesAlmacen.Rows.Count > 0 Then + ChkNCInv.Visible = True + GVNCInv.DataSource = DtPendientesAlmacen + GVNCInv.DataBind() + End If + + End If + End Sub + Protected Sub ChkNCInv_CheckedChanged(sender As Object, e As EventArgs) + CargaAnticipos(CveProveedor, If(ChkNCInv.Checked, "NC", "-1")) + UpAnticipos.Update() + End Sub + Private Sub CargaNCINV() + + Dim SaldoAnticipo = 0.0 + Dim CveCompras As String = "" + If ChkNCInvNC.Checked Then + For Each gvr As GridViewRow In GvFacturaNC.Rows + If gvr.FCCheckBox("ChkFacturaNC") IsNot Nothing AndAlso gvr.FCCheckBox("ChkFacturaNC").Checked Then + SaldoAnticipo += gvr.FCTextBox("TxtImporte").Text.ToDouble + If CveCompras <> "" Then + CveCompras = $"{CveCompras},{gvr.DataKey("CveCompra").ToString}" + Else + CveCompras = gvr.DataKey("CveCompra").ToString + End If + End If + Next + Else + For Each gvr As GridViewRow In GVAnticipos.Rows + If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then + SaldoAnticipo += gvr.FCTextBox("TxtAnticipo").Text.ToDouble + End If + Next + End If + + + If SaldoAnticipo <= 0 Then + Alert("No hay movimientos seleccionados para aplicar", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + LbNCInvSaldo.Text = SaldoAnticipo.FormatoNumero() + + If ChkNCInvNC.Checked Then + Dim ObjInventarios As New ClsInventarios + If ObjInventarios.RecepcionAlmacenGet(-1, -1, UsuarioActual.CveEmpresa, CveProveedor) AndAlso ObjInventarios.DtResultados.FiltraParametros($"CveCompra IN ({CveCompras}) AND CantidadF > 0").Rows.Count > 0 Then + DtPendientesAlmacen = ObjInventarios.DtResultados.FiltraParametros($"CveCompra IN ({CveCompras}) AND CantidadF > 0").Copy + End If + ObjInventarios.Dispose() + End If + + If (DtPendientesAlmacen IsNot Nothing AndAlso DtPendientesAlmacen.Rows.Count > 0) Then + If ChkNCInvNC.Checked Then + GVNCInv.DataSource = DtPendientesAlmacen + GVNCInv.DataBind() + UpNCInv.Update() + RegistraScript("$('#FacturaNC').modal('hide');", "FacturaNC") + End If + RegistraScript("$('#ModalNCInv').modal('show');", "ModalNCInv") + Else + If ChkNCInvNC.Checked Then + Alert("Niguna de las facturas seleccionadas cuenta con productos pendientes de darles entrada.", TipoMensaje.MsgAdvertencia) + ChkNCInvNC.Checked = False + UpChkNCInvNC.Update() + Exit Sub + Else + RegistraScript("$('#ModalNCConfirmación').modal('show');", "ModalNCInv") + End If + End If + + UpNCInv.Update() + + End Sub + Protected Sub GVNCInv_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVNCInv.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + 'e.Row.FCCheckBox("cbInv").Attributes.Add("onclick", "FnCambiaInvNC(this);") + e.Row.FCTextBox("TxtCantidadNCInv").Attributes.Add("onkeyup", $"ValidarCantidad(this,{e.Row.DBCampo("CantidadF")});FnCambiaInvNC(this);") + End If + End Sub + Protected Sub BtnNCInv_Click(sender As Object, e As EventArgs) + + If ChkNCInvNC.Checked Then + RegistraScript("$('#ModalNCInv').modal('hide');", "ModalNCInv") + RegistraScript("$('#DivAnticipos').modal('hide');", "FacturaNC") + Exit Sub + End If + + Dim Contador = 0 + Dim CveCompraNC = -1 + For Each gvr As GridViewRow In GVAnticipos.Rows + If gvr.FCCheckBox("Chk") IsNot Nothing AndAlso gvr.FCCheckBox("Chk").Checked Then + Contador += 1 + CveCompraNC = gvr.DataKey("CveCompra").ToString.ToEntero + End If + Next + + If Contador <> 1 Then + Alert("Debe seleccionar por lo menos una NC a aplicar.", TipoMensaje.MsgAdvertencia) + RegistraScript("$('#ModalNCInv').modal('hide');", "ModalNCInv") + RegistraScript("$('#DivAnticipos').modal('hide');", "ModalAnticipos") + Exit Sub + End If + + If Not CveCompraNC > 0 Then + Alert("Ocurrió un error al guardar la cancelación de inventarios. Por favor comuniquese con asistencia SIG", TipoMensaje.MsgError) + Exit Sub + End If + + + Dim ObjCompras As New ClsCompras + Dim ObjConta As New ClsContabilidad(ObjCompras.IniciaTransacSQL) + Dim TieneError = False + + For Each Gvr As GridViewRow In GVNCInv.Rows + If Gvr.FCTextBox("TxtCantidadNCInv").Text.ToDouble > 0 Then + If Not ObjCompras.ComprasDetalleDevolucionesAdd(Gvr.DataKey("CveCompraDetalle").ToEntero, CveCompraNC, Gvr.FCTextBox("TxtCantidadNCInv").Text.ToDouble, UsuarioActual.CveEmpresa) Then + TieneError = True + Exit For + End If + End If + Next + + If Not TieneError Then + GuardaAnticipos(ObjCompras, ObjConta) + Else + ObjCompras.RollBack() + End If + + ObjCompras.Dispose() + RegistraScript("$('#ModalNCInv').modal('hide');", "ModalNCInv") + RegistraScript("$('#DivAnticipos').modal('hide');", "ModalAnticipos") + + End Sub + Protected Sub BtnNCConfirmacion_Click(sender As Object, e As EventArgs) + GuardaAnticipos(Nothing, Nothing) + End Sub +#End Region + +#Region " INVENTARIO: MOVIMIENTOS DE LA COMPRA " + Private Sub InventarioMov() + Dim ObjVentas As New ClsInventarios + + If ObjVentas.GetInv_ComprasMov(CveCompra, UsuarioActual.CveEmpresa) Then + If ObjVentas.DtResultados.Rows.Count > 0 Then + GvInvMov.DataSource = ObjVentas.DtResultados + End If + End If + GvInvMov.DataBind() + GvInvMov.Visible = True + + ObjVentas.Dispose() + UpINV.Update() + End Sub + Private Sub GvInvMov_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvInvMov.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + If e.Row.DBCampo("CvePS") = "" Then + e.Row.FCLiteral("LtlPS").Text = String.Format("Folio: {1} Fecha: {2} {3} {4}", e.Row.DBCampo("CveMovimiento"), e.Row.DBCampo("Folio"), e.Row.DBCampo("Fecha").ToString.ToDate.ToShortDateString, e.Row.DBCampo("Almacen").ToString, e.Row.DBCampo("Concepto").ToString) + + If e.Row.DataKey("Origen").ToEntero > 0 Then + e.Row.CssClass = "SubTotales" + Else + e.Row.BackColor = Drawing.Color.FromArgb(224, 130, 131) + e.Row.ForeColor = Drawing.Color.White + e.Row.Font.Bold = True + End If + Else + e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Left + End If + End If + End Sub + + Private Sub GvAcarreo_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvAcarreo.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + e.Row.FCLiteral("LtlImporte").Text = "$" + FormatNumber(e.Row.FCLiteral("LtlImporte").Text.ToDouble, 2, , , TriState.True) + End If End Sub -#End Region +#End Region -#Region " REGENERA PREPOLIZA " - Protected Sub BtnRegenerarPrePolizaAlmacen_Click(sender As Object, e As EventArgs) - 'RegeneraPrePoliza() - - Dim ObjCompra As New ClsCompras - Dim ObjContabilidad As New ClsContabilidad(ObjCompra.IniciaTransacSQL) - - Dim Estatus = ActualizarPrePoliza(ObjContabilidad, ObjCompra) - - If Estatus Then - ObjCompra.Commit() - Alert("La PrePoliza se regeneró correctamente.", TipoMensaje.MsgInformacion) - Else - ObjCompra.RollBack() - Alert("Ocurrió un error al regenerar la PrePoliza.", TipoMensaje.MsgError) - End If - ObjCompra.Dispose() - - End Sub - - Private Sub RegeneraPrePoliza() - 'Alert($"CvePrePoliza de la compra: {CvePrePoliza}", TipoMensaje.MsgInformacion) - - 'MOVIMIENTOS DE ALMACEN DE LA COMPRA - Dim ObjInventarios As New ClsInventarios - Dim DtInv As New DataTable - If ObjInventarios.GetInv_ComprasMov(CveCompra, UsuarioActual.CveEmpresa) AndAlso ObjInventarios.DtResultados.Rows.Count > 0 Then - DtInv = ObjInventarios.DtResultados - End If - ObjInventarios.Dispose() - - Dim DtTemporal = TmpDT.Copy - DtTemporal.Columns.Add("ImporteEnAlmacen", GetType(Decimal)) - - Dim ObjConta As New ClsContabilidad - ObjConta.IniciaTransacSQL() - Dim TieneError = True - - 'ELIMINA DETALLES DE [AF - INV - GASTO] - If ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 49, CveCompra, 1) Then - If ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 68, CveCompra, 1) Then - If ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 6, CveCompra, 1) Then - TieneError = False - End If - End If - End If - - 'INGRESAMOS DETALLES - If Not TieneError Then - - 'CONFIGURACIONES - Dim CuentasContablesInvalidas As New StringBuilder - Dim CuentasContablesInvalidasSIG As New StringBuilder - Dim IdCtaContable As Integer = 0 - Dim CveCuenta As Integer = 0 - Dim CveProveedorConcepto = 0 - Dim Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - Dim Multiplicador = If(DdlTipoComprobante.SelectedValue = "NC", -1, 1) - - Dim ImporteMovimiento = 0.0D - Dim importeMN = 0.0D - - Dim TipoCambioActual = 0.0D - Dim TipoCambioPago = 0.0D - Dim FechaMovimiento As Date = TxtFecha.Text.ToDate - - 'TIPO CAMBIO - If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then - TipoCambioActual = GlobalTipoCambio(FechaMovimiento).ToString.ToDecimal - TipoCambioPago = GlobalTipoCambio(TxtFechaPago.Text.ToDate).ToString.ToDecimal - Else - TipoCambioActual = 1 - TipoCambioPago = 1 - End If - - 'CTA PROVEEDOR - Select Case RBLContado.SelectedValue - Case "4" ' Deudores - CveProveedorConcepto = DdlDeudor.SelectedValue.ToEntero - Case "5" ' Acreedores - CveProveedorConcepto = DdlAcreedor.SelectedValue.ToEntero - Case Else ' Proveedores - F y E - Doctos - CveProveedorConcepto = CveProveedor - End Select - - - 'INGRESA DETALLE DE AF(49) - TipoAF 2 es para las compras - Dim DT = DtTemporal.FiltraParametros("ISNULL(TipoAF,0) = 2") - If DT.Rows.Count > 0 AndAlso DdlTipoComprobante.SelectedValue <> "NC" Then - For Each Row2 As DataRow In DT.Rows - ImporteMovimiento = Row2("Total").ToString.ToDecimal * Multiplicador - importeMN = ImporteMovimiento * TipoCambioActual - If ObjConta.GetRetCuenta(49, Row2("CveActivoFijo").ToString.ToEntero) Then - If ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijo").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijoSIG").ToString.ToEntero - End If - End If - If ImporteMovimiento <> 0 Then - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 49))("ConceptoContable").ToString) - End If - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 49))("ConceptoContable").ToString) - End If - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, Row2("CodAF").ToString, 49, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveActivoFijo:=Row2("CveActivoFijo").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(TipoCambioActual = 1, 0, ImporteMovimiento), CveCuenta:=CveCuenta) Then - TieneError = True - End If - End If - Next - End If - - ImporteMovimiento = 0 - IdCtaContable = 0 - - 'INGRESA DETALLE DE ALMACÉN(68) - Dim DtAlmacenes = GlobalDTAlmacen(UsuarioActual.CveEmpresa) - If UsuarioActual.Empresa.UsaInventarios AndAlso Not UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - Dim CveMovimientoInventario = -1 - Dim ModalidadAlmacen = -1 - Dim DtMovtosAlmacen As New DataTable - DtMovtosAlmacen.Columns.Add("CveMovimiento", GetType(Integer)) - DtMovtosAlmacen.Columns.Add("IdCtaContable", GetType(Integer)) - DtMovtosAlmacen.Columns.Add("CveCuenta", GetType(Integer)) - DtMovtosAlmacen.Columns.Add("Importe", GetType(Decimal)) - - If DtTemporal.FiltraParametros("ISNULL(TipoAF,0) <> 2").Rows.Count > 0 Then - For Each Row2 As DataRow In DtTemporal.FiltraParametros("ISNULL(TipoAF,0) <> 2").Rows - 'VALIDAMOS TIPO ALMACEN DE LA COMPRA DETALLE - SI ES TIPO "SOLO EXISTENCIA" (0) SKIPEAMOS - ModalidadAlmacen = DtInv.MIN("ModalidadAlmacen", $"CveCompraDetalle = {Row2("CveCompraDetalle")}").ToEntero - If ModalidadAlmacen = 0 Then - Continue For - End If - CveMovimientoInventario = DtInv.MAX("CveMovimiento", $"CveCompraDetalle = {Row2("CveCompraDetalle")}").ToEntero - IdCtaContable = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen = {DtInv.MIN("CveAlmacen", $"CveCompraDetalle = {Row2("CveCompraDetalle")}")}").ToEntero - CveCuenta = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContableSIG", $"CveAlmacen = {DtInv.MIN("CveAlmacen", $"CveCompraDetalle = {Row2("CveCompraDetalle")}")}").ToEntero - - ImporteMovimiento = DtInv.SUM(If(DdlMoneda.SelectedValue = "1", "Total", "TotalExtranjero"), $"CveCompraDetalle = {Row2("CveCompraDetalle")}").ToDecimal - ImporteMovimiento = If(ImporteMovimiento > Row2("Total").ToString.ToDecimal, Row2("Total").ToString.ToDecimal, ImporteMovimiento) * Multiplicador - - 'VALIDA QUE CUANDO SEA DOLARES TENGA PUEXTRANJERO EN EL MOVTO DE ALMACEN - If DdlMoneda.SelectedValue = "2" And ImporteMovimiento = 0 And DtInv.SUM("Total", $"CveCompraDetalle = {Row2("CveCompraDetalle")}").ToDecimal > 0 Then - TieneError = True - Exit For - End If - - Dim DrInv = DtMovtosAlmacen.NewRow - DrInv("CveMovimiento") = CveMovimientoInventario - DrInv("IdCtaContable") = IdCtaContable - DrInv("CveCuenta") = CveCuenta - DrInv("Importe") = ImporteMovimiento - DtMovtosAlmacen.Rows.Add(DrInv) - - If ImporteMovimiento <> 0 Then - Row2("ImporteEnAlmacen") = ImporteMovimiento - End If - Next - - For Each Row As DataRow In DtMovtosAlmacen.FiltraParametros("", "", {"CveMovimiento", "IdCtaContable"}).Rows - ImporteMovimiento = DtMovtosAlmacen.SUM("Importe", $"CveMovimiento = {Row("CveMovimiento").ToString.ToEntero} AND IdCtaContable = {Row("IdCtaContable").ToString.ToEntero}").ToString.ToDecimal - importeMN = ImporteMovimiento * TipoCambioActual - If ImporteMovimiento <> 0 Then - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) - End If - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) - End If - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, Concepto, 68, Concepto, FechaMovimiento, Row("IdCtaContable").ToString.ToEntero, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveMovimientoAlmacen:=Row("CveMovimiento").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(TipoCambioActual = 1, 0, ImporteMovimiento), CveCuenta:=Row("CveCuenta").ToString.ToEntero) Then - TieneError = True - Exit For - End If - End If - Next - End If - End If - - ImporteMovimiento = 0 - IdCtaContable = 0 - CveCuenta = 0 - - 'INGRESA DETALLE DE GASTO(6) - DT = DtTemporal - 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN - For Each Dr As DataRow In DT.Rows - Dr("CveAlmacen") = DtInv.MIN("ModalidadAlmacen", $"CveCompraDetalle = {Dr("CveCompraDetalle")}").ToEntero - Dr.AcceptChanges() - Next - DT.AcceptChanges() - - If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - DT = DT.FiltraParametros("ISNULL(TipoAF,0) <> 2", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveProyecto", "CveSubProyecto"}) - Else - DT = DT.FiltraParametros("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveProyecto", "CveSubProyecto"}) - End If - - If DT.Rows.Count > 0 Then - Dim ImporteAlmacen = 0.0D - For Each Row2 As DataRow In DT.Rows - If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then - ImporteMovimiento = DtTemporal.SUM("Total", String.Format("ISNULL(TipoAF,0) <> 2 AND CveClasificacion = {0} AND CveSubProyecto = {1}", Row2("CveClasificacion"), Row2("CveSubProyecto"))).ToString.ToDecimal - ImporteAlmacen = DtTemporal.SUM("ImporteEnAlmacen", String.Format("ISNULL(TipoAF,0) <> 2 AND CveClasificacion = {0} AND CveSubProyecto = {1}", Row2("CveClasificacion"), Row2("CveSubProyecto"))).ToString.ToDecimal - Else - ImporteMovimiento = DtTemporal.SUM("Total", String.Format("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveClasificacion = {0} AND CveSubProyecto = {1}", Row2("CveClasificacion"), Row2("CveSubProyecto"))).ToString.ToDecimal - ImporteAlmacen = DtTemporal.SUM("ImporteEnAlmacen", String.Format("ISNULL(TipoAF,0) <> 2 AND CveClasificacion = {0} AND CveSubProyecto = {1}", Row2("CveClasificacion"), Row2("CveSubProyecto"))).ToString.ToDecimal - End If - ImporteMovimiento = (ImporteMovimiento - ImporteAlmacen) * Multiplicador - importeMN = ImporteMovimiento * TipoCambioActual - If Row2("CveClasificacion").ToString.ToEntero > 0 Then - If ObjConta.GetRetCuenta(6, Row2("CveClasificacion").ToString.ToEntero) Then - If ObjConta.DtResultados.Rows.Count > 0 AndAlso (ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Or ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero > 0) Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero - CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero - Else - IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGasto", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero - CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero - End If - End If - End If - Dim IdSegmentoNegocio As Integer = -1 - Dim drT As DataRow = GlobalDTSubProyectos(-1, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero).FiltroPrimero(String.Format("CveSubProyecto = {0} ", Row2("CveSubProyecto"))) - If drT IsNot Nothing Then - IdSegmentoNegocio = drT("IdSegNeg").ToString.ToEntero - End If - If ImporteMovimiento <> 0 Then - If IdCtaContable = 0 Then - CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) - End If - If CveCuenta = 0 Then - CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) - End If - Dim tcvecon As Integer = 6 - Dim tidctacon As Integer = 6 - tidctacon = IdCtaContable - If DdlTipoComprobante.SelectedValue = "Ant" Then - tcvecon = 264 - tidctacon = ViewState("CtaProveedorAnticipos").ToString.ToEntero - If DdlMoneda.SelectedValue = "2" Then - tidctacon = ViewState("CtaProveedorAnticiposExtranjera").ToString.ToEntero - End If - End If - - Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, Concepto, tcvecon, Concepto, FechaMovimiento, IdCtaContable, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveClasificacion:=Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(TipoCambioActual = 1, 0, ImporteMovimiento), CveCuenta:=CveCuenta) Then - TieneError = True - End If - - End If - Next - End If - - End If - - - If Not TieneError Then - ObjConta.Commit() - Alert("La PrePoliza se regeneró correctamente.", TipoMensaje.MsgInformacion) - Else - ObjConta.RollBack() - Alert("Ocurrió un error al regenerar la PrePoliza. Por favor vuelva a intentar.", TipoMensaje.MsgError) - End If - - ObjConta.Dispose() - - End Sub -#End Region +#Region " REGENERA PREPOLIZA " + Protected Sub BtnRegenerarPrePolizaAlmacen_Click(sender As Object, e As EventArgs) + 'RegeneraPrePoliza() -#Region " ACTUALIZAR TIPO CAMBIO PREPOLIZA " - Private Sub InicializaActualizarTC() - If CveCompra > 0 And DdlMoneda.SelectedValue.ToEntero = 2 And CvePrePoliza > 0 Then - TxtActualizarTC_TCActual.Text = TipoCambio.FormatoNumero(4) - TxtActualizarTC_TCActualizar.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).FormatoNumero(4) - HLModalActualizarTC.Visible = True - End If - End Sub - Protected Sub BtnActualizarTC_Click(sender As Object, e As EventArgs) - Dim ObjContabilidad As New ClsContabilidad - Dim ObjCompras As New ClsCompras(ObjContabilidad.IniciaTransacSQL()) - Dim ObjEventos As New ClsOIEventos(ObjContabilidad.IniciaTransacSQL()) - Dim TieneError = False - Dim MensajeError = "" - - If ObjEventos.AddEventoBitacora($"Se actualizó el Tipo de Cambio de la compra. TC anterior: {TxtActualizarTC_TCActual.Text.FormatoNumero(4)} | TC actual: {TxtActualizarTC_TCActualizar.Text.FormatoNumero(4)}", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then - If ObjCompras.UpdateCompraTipoCambio(TxtActualizarTC_TCActualizar.Text.ToDouble, CveCompra, CvePrePoliza, UsuarioActual.CveEmpresa) Then - If Not ObjContabilidad.ReconstruirPP_Compra(CveCompra) Then - TieneError = True - MensajeError = "Ocurrió un error al actualizar el Tipo de Cambio al documento" - End If - Else - TieneError = True - MensajeError = "Ocurrió un error al actualizar el asiento contable" - End If - Else - TieneError = True - MensajeError = "Ocurrió un error al guardar el historal al actualizar el Tipo de Cambio al documento" - End If - - If Not TieneError Then - ObjContabilidad.Commit() - Alert("Se actualizó correctamente el tipo de cambio del documento.", TipoMensaje.MsgInformacion) - RegistraScript("$('#ModalActualizarTC').modal('hide');") - Else - ObjContabilidad.RollBack() - Alert(MensajeError, TipoMensaje.MsgError) - End If - - ObjContabilidad.Dispose() - End Sub -#End Region + Dim ObjCompra As New ClsCompras + Dim ObjContabilidad As New ClsContabilidad(ObjCompra.IniciaTransacSQL) -#Region "PAQUETERIAS GUIAS" - Protected Sub LnkAgregarGuia_Click(sender As Object, e As EventArgs) - '' 25/05/2018 - Se agrega Link a Modulo Paqueterias Guias - RegistraScript(String.Format("AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveCompra={0}',800,620);", CveCompra)) - End Sub -#End Region + Dim Estatus = ActualizarPrePoliza(ObjContabilidad, ObjCompra) -#Region "DEDUCCIONES IEPS / OTROS IMPUESTOS" - Protected Sub CargaProductos(Ddl As DropDownList, CvePS As Integer) - Ddl.DataSource = TmpDT - Ddl.DataBind() - Ddl.Items.Insert(0, New ListItem("Seleccione un concepto", "-1")) - Ddl.SelectedValueExist("-1") - - If CvePS > 0 Then - Ddl.Items.Insert(1, New ListItem(GlobalDTPS(UsuarioActual.CveEmpresa, CvePS).FiltroPrimeroValor("PS"), CvePS.ToString)) - End If - - 'Ddl.Items.Insert(1, New ListItem(Concepto, "-1")) - End Sub - - Protected Sub BtnAgregarIEPS_Click(sender As Object, e As EventArgs) - TrasladoIEPS = TxtIEPS.Text.ToDecimal - OtrosImpuestos = TxtOtrosImpuestos.Text.ToDecimal - - If ChkIEPS.Checked Then IEPSGasto = True - If ChkOtrosI.Checked Then OtrosImpuestosGasto = True - - If IEPSGasto Or OtrosImpuestosGasto Then - - 'AGREGA IEPS COMO CONCEPTO - If IEPSGasto Then - Dim CvePS As Integer = DdlConceptoIEPS.SelectedValue.ToEntero - ' If CvePS = -1 Then CvePS = UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero - AgregarConceptoIEPS(TrasladoIEPS, CvePS) - TrasladoIEPS = 0 - TxtIEPS.Text = 0.ToString.FormatoNumero - TrIEPS.Visible = False - For Each Dr As DataRow In TmpDT.Rows - Dr("IEPSPS") = 0 - Dr("IEPSPSPorcentaje") = 0 - Next - TmpDT.AcceptChanges() - End If - 'AGREGA OTROS IMPUESTOS COMO CONCEPTO - If OtrosImpuestosGasto Then - Dim CvePS As Integer = DdlConceptoOI.SelectedValue.ToEntero - 'If CvePS = -1 Then CvePS = UsuarioActual.Empresa.Funcionalidad(305).ToString.ToEntero - AgregarConceptoIEPS(OtrosImpuestos, CvePS) - OtrosImpuestos = 0 - TxtOtrosImpuestos.Text = 0.ToString.FormatoNumero - TrOtrosImpuestos.Visible = False - End If - - CargaGvPersonal() - UpPS.Update() - RegistraScript("$('#ModalIEPS').modal('hide');") - Else - Alert("Debe seleccionar al menos un impuesto", TipoMensaje.MsgAdvertencia) - End If - - End Sub -#End Region + If Estatus Then + ObjCompra.Commit() + Alert("La PrePoliza se regeneró correctamente.", TipoMensaje.MsgInformacion) + Else + ObjCompra.RollBack() + Alert("Ocurrió un error al regenerar la PrePoliza.", TipoMensaje.MsgError) + End If + ObjCompra.Dispose() -#Region "C R E D I T O S" - - Private Sub ChkCreditoMultiple_CheckedChanged(sender As Object, e As EventArgs) Handles ChkCreditoMultiple.CheckedChanged - - If ChkCreditoMultiple.Checked Then - - romCreditosTabla.Visible = True - Dim ObjBancos As New ClsBancos - - If ObjBancos.GetCreditosDetalleCompras(UsuarioActual.CveEmpresa, CveProveedor, -1, -1, -1) Then - GvCreditos.DataSource = ObjBancos.DtResultados - Else - GvCreditos.DataSource = Nothing - End If - - ObjBancos.Dispose() - GvCreditos.DataBind() - - End If - End Sub - - Private Sub GvCreditos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvCreditos.RowDataBound - - If e.Row.RowType = DataControlRowType.DataRow Then - - Dim TxtCapital As TextBox = e.Row.FCTextBox("TxtCapital") - Dim TxtInteres As TextBox = e.Row.FCTextBox("TxtInteres") - Dim TxtAmbos As TextBox = e.Row.FCTextBox("TxtAmbos") - Dim CveCreditoDetalle As Integer = e.Row.DataKey("CveCreditoDetalle").ToEntero - - Dim CveCompraCapital As Integer = e.Row.DataKey("CveCompra").ToEntero - Dim CveCompraInteres As Integer = e.Row.DataKey("CveCompraInteres").ToEntero - - If CveCompraCapital > 0 Then - TxtCapital.Enabled = False - TxtAmbos.Enabled = False - End If - - If CveCompraInteres > 0 Then - TxtInteres.Enabled = False - TxtAmbos.Enabled = False - End If - - TxtCapital.Attributes.Add("class", $"CsCreGlobal CsSelCapital{CveCreditoDetalle}") - TxtCapital.Attributes.Add("onkeyup", $"ValidaCredito(this,event,{CveCreditoDetalle},1)") - 'TxtCapital.Attributes.Add("data-CD", CveCreditoDetalle.ToString) - - TxtInteres.Attributes.Add("class", $"CsCreGlobal CsSelInteres{CveCreditoDetalle}") - TxtInteres.Attributes.Add("onkeyup", $"ValidaCredito(this,event,{CveCreditoDetalle},1)") - 'TxtInteres.Attributes.Add("data-CD", CveCreditoDetalle.ToString) - - TxtAmbos.Attributes.Add("class", $"CsCreGlobal CsSelAmbos{CveCreditoDetalle}") - TxtAmbos.Attributes.Add("onkeyup", $"ValidaCredito(this,event,{CveCreditoDetalle},2)") - 'TxtAmbos.Attributes.Add("data-CD", CveCreditoDetalle.ToString) - - - - End If - End Sub - - Private Sub CargaCreditosDisponibles() - - - If RBLPago.SelectedValue.ToEntero = 4 Then - - Dim ObjBancos As New ClsBancos - If ObjBancos.GetCreditosDetalleCompras(UsuarioActual.CveEmpresa, CveProveedor, -1, -1, -1) Then - - GvCreditos.DataSource = ObjBancos.DtResultados - Else - GvCreditos.DataSource = Nothing - End If - ObjBancos.Dispose() - romCreditosTabla.Visible = True - GvCreditos.DataBind() - - Else - romCreditosTabla.Visible = False - End If - - UpGvCreditos.Update() - - End Sub -#End Region - -#Region "FLETES / IMPORTACIONES" - Private Sub CargaFolio() - Dim ObjFolios As New ClsGralFolios - If ObjFolios.GetFolios("FLE", UsuarioActual.CveEmpresa) Then - If ObjFolios.DtResultados.Rows.Count > 0 Then - LblFolioModalFletes.Text = ObjFolios.DtResultados(0)("FActual").ToString - BtnCrearFleteImportacion.Enabled = True - Else - Alert("Necesita registrar un folio de fletes", TipoMensaje.MsgAdvertencia) - BtnCrearFleteImportacion.Enabled = False - End If - End If - ObjFolios.Dispose() - End Sub - Protected Sub BtnGuardarModalFletesImportaciones_Click(sender As Object, e As EventArgs) - If DdlFleteImportacion.SelectedValue.ToEntero = 237 And Not DdlFletes.SelectedValue.ToEntero > 0 Then Alert("Tiene que seleccionar un flete", TipoMensaje.MsgAdvertencia) : Exit Sub - If DdlFleteImportacion.SelectedValue.ToEntero = 240 And Not DdlImportaciones.SelectedValue.ToEntero > 0 Then Alert("Tiene que seleccionar una importación", TipoMensaje.MsgAdvertencia) : Exit Sub - If DdlFletes.SelectedValue.ToEntero > 0 Then - Dim ObjInventario As New ClsInventarios - Dim Dr As DataRow = Nothing - If ObjInventario.GetFletes(UsuarioActual.CveEmpresa, DdlFletes.SelectedValue.ToEntero) Then - If ObjInventario.DtResultados.Rows.Count > 0 Then - Dr = ObjInventario.DtResultados.Rows(0) - End If - End If - If Dr IsNot Nothing Then - If Dr("CveCompra").ToString.ToEntero > 0 And RblFleteImportacionOpcion.SelectedValue.ToEntero = 1 Then - Alert("Este flete ya tiene compra asignada", TipoMensaje.MsgAdvertencia) - ObjInventario.Dispose() - Exit Sub - End If - End If - ObjInventario.Dispose() - End If - - If DdlFleteImportacion.SelectedValue.ToEntero = 237 Then DdlTipoCompra.SelectedValueExist("4") : UpEstatus.Update() - If DdlFleteImportacion.SelectedValue.ToEntero = 240 Then DdlTipoCompra.SelectedValueExist("5") : UpEstatus.Update() - - CveImportacion = DdlImportaciones.SelectedValue.ToEntero - CveFlete = DdlFletes.SelectedValue.ToEntero - FleteImportacionOpcion = RblFleteImportacionOpcion.SelectedValue.ToEntero - CveConceptoContableAlmacen = DdlFleteImportacion.SelectedValue.ToEntero - - - If CveCompra > 0 AndAlso (CveImportacion > 0 Or CveFlete > 0) Then - Dim ObjCompras As New ClsCompras - Dim ObjConta As New ClsContabilidad(ObjCompras.IniciaTransacSQL) - Dim ObjInventario As New ClsInventarios(ObjCompras.IniciaTransacSQL) - Dim ErrorTrans As Boolean = False - - Select Case CveConceptoContableAlmacen - Case 237 - Select Case FleteImportacionOpcion - Case 1 - Dim Dr As DataRow = Nothing - If ObjInventario.GetFletes(UsuarioActual.CveEmpresa, CveFlete) Then - If ObjInventario.DtResultados.Rows.Count > 0 Then - Dr = ObjInventario.DtResultados.Rows(0) - End If - End If - If Dr IsNot Nothing Then - If Not ObjInventario.UpdateFlete(CveFlete, Dr("Descripcion").ToString, Dr("Fecha").ToString.ToDate, -1, CveCompra, UsuarioActual.CveUsuario) Then - ErrorTrans = True - End If - Else - ErrorTrans = True - End If - Case 2 - If Not ObjInventario.AddFleteDetalle(CveFlete, CveCompra) Then - ErrorTrans = True - End If - 'actualiza la compra para que no se surta en almacen. sino por el flete o importación - If Not ObjCompras.UpdateEstatusAlmacen(CveCompra, 2) Then - ErrorTrans = True - End If - End Select - Case 240 - Select Case FleteImportacionOpcion - Case 1 - If Not ObjCompras.AddImportacionCompra(CveImportacion, CveCompra) Then - ErrorTrans = True - End If - Case 2 - If Not ObjCompras.AddImportacionDetalle(CveImportacion, CveCompra) Then - ErrorTrans = True - End If - 'actualiza la compra para que no se surta en almacen. sino por el flete o importación - If Not ObjCompras.UpdateEstatusAlmacen(CveCompra, 2) Then - ErrorTrans = True - End If - End Select - End Select - - 'Removemos los conceptos de la prepoliza - If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 6, CveCompra, 1) Then ErrorTrans = False 'GASTO - If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 68, CveCompra, 1) Then ErrorTrans = False 'ALMACEN - If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 49, CveCompra, 1) Then ErrorTrans = False 'AF - If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 205, CveCompra, 1) Then ErrorTrans = False 'PS YA RECIBIDO - If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 230, CveCompra, 1) Then ErrorTrans = False 'PS YA RECIBIDO - If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 231, CveCompra, 1) Then ErrorTrans = False 'PS YA RECIBIDO - If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 176, CveCompra, 1) Then ErrorTrans = False 'PS NO RECIBIDO - If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 228, CveCompra, 1) Then ErrorTrans = False 'PS NO RECIBIDO - If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 229, CveCompra, 1) Then ErrorTrans = False 'PS NO RECIBIDO - - Dim ConceptoContabilizacion As Integer = CveConceptoContableAlmacen - Dim ConceptoContabilizacionME As Integer = -1 - Dim ConceptoContabilizacionMEComp As Integer = -1 - Dim importeMovimiento As Decimal = 0 - Dim importeMN As Decimal = 0 - Dim IdCtaContable As Integer = -1 - Dim IdCtaContableME As Integer = -1 - Dim IdCtaContableMEComp As Integer = -1 - Dim tipoCambioActual As Decimal = 0 - Dim Multiplicador = If(DdlTipoComprobante.SelectedValue = "NC", -1, 1) - - If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then - tipoCambioActual = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString.ToDecimal - tipoCambioActual = If(DivTC.Visible, TipoCambio.ToDecimal, tipoCambioActual) - Else - tipoCambioActual = 1 - End If - - Select Case ConceptoContabilizacion - Case 237 - ConceptoContabilizacionME = 238 - ConceptoContabilizacionMEComp = 239 - importeMovimiento = TmpDT.SUMD(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")) - importeMN = importeMovimiento * tipoCambioActual * Multiplicador 'TIENE QUE TENER EL IMPORTEMN IGUAL AL IMPORTEMOVIMIENTO PORQUE NO TOMA EN CUENTA SI UN PRODUCTO ES TIPO SERVICIO - Case 240 - ConceptoContabilizacionME = 241 - ConceptoContabilizacionMEComp = 242 - importeMovimiento = TmpDT.SUMD(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")) - importeMN = importeMovimiento * tipoCambioActual * Multiplicador 'TIENE QUE TENER EL IMPORTEMN IGUAL AL IMPORTEMOVIMIENTO PORQUE NO TOMA EN CUENTA SI UN PRODUCTO ES TIPO SERVICIO - End Select - - If ObjConta.GetRetCuenta(ConceptoContabilizacion, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - End If - - If ObjConta.GetRetCuenta(ConceptoContabilizacionME, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableME = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - End If - - If ObjConta.GetRetCuenta(ConceptoContabilizacionMEComp, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableMEComp = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero - End If - Dim Concepto As String = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" - If DdlMoneda.SelectedValue.ToEntero <> 1 Then - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, Concepto, ConceptoContabilizacionME, Concepto, TxtFecha.Text.ToDate, IdCtaContableME, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMovimiento, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), TipoCambio:=tipoCambioActual) Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMN - importeMovimiento, Concepto, ConceptoContabilizacionMEComp, Concepto, TxtFecha.Text.ToDate, IdCtaContableMEComp, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMN - importeMovimiento, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), TipoCambio:=tipoCambioActual) Then - ErrorTrans = True - End If - Else - ErrorTrans = True - End If - Else - - If importeMN <> 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMN, Concepto, ConceptoContabilizacion, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), TipoCambio:=tipoCambioActual) Then - ErrorTrans = True - End If - End If - - If Not ErrorTrans Then - ObjCompras.Commit() - Else - ObjCompras.RollBack() - End If - ObjCompras.Dispose() - ObjConta.Dispose() - ObjInventario.Dispose() - - End If - - - RegistraScript("$('#ModalFletesImportaciones').modal('hide')") - End Sub - - Private Sub CargaModalFletesImportaciones() - - TxtFechaModalImportacionesFletes.Text = Now.ToShortDateString - TxtDescripcionModalFletesImportacion.Text = "" - TxtPedimento.Text = "" - RblTipo.SelectedValue = "1" - RblFleteImportacionOpcion.SelectedValue = "1" - CargaCombosFletesImportaciones() - CambiaTipo() - DdlFletes.SelectedValueExist(CveFlete) - DdlImportaciones.SelectedValueExist(CveImportacion) - If FleteImportacionOpcion > 0 Then RblFleteImportacionOpcion.SelectedValue = FleteImportacionOpcion.ToString - RegistraScript("$('#ModalFletesImportaciones').modal()") - UpModalFletesImportaciones.Update() - End Sub - Protected Sub RblTipo_SelectedIndexChanged(sender As Object, e As EventArgs) - CambiaTipo() - UpModalFletesImportaciones.Update() - End Sub - - Private Sub CambiaTipo() - Select Case RblTipo.SelectedValue.ToEntero - Case 1 - DivVinculacion.Visible = True - DivCrear.Visible = False - Select Case DdlFleteImportacion.SelectedValue.ToEntero - Case 237 - LblTitulo.Text = "Costo Indirecto" - DivFletes.Visible = True - DivImportaciones.Visible = False - Case 240 - LblTitulo.Text = "Importación" - DivFletes.Visible = False - DivImportaciones.Visible = True - End Select - Case 2 - DivVinculacion.Visible = False - DivCrear.Visible = True - Select Case DdlFleteImportacion.SelectedValue.ToEntero - Case 237 - LblTitulo.Text = "Costo Indirecto" - DivLblFolio.Visible = True - DivPedimento.Visible = False - CargaFolio() - Case 240 - LblTitulo.Text = "Importación" - DivLblFolio.Visible = False - DivPedimento.Visible = True - End Select - End Select - End Sub - Protected Sub BtnCrearFleteImportacion_Click(sender As Object, e As EventArgs) - Dim CveFlete As Integer = 0 - Dim CveImportacion As Integer = 0 - Select Case DdlFleteImportacion.SelectedValue.ToEntero - Case 237 - Dim ObjInv As New ClsInventarios - If ObjInv.AddFlete(LblFolioModalFletes.Text, TxtDescripcionModalFletesImportacion.Text.Trim, TxtFechaModalImportacionesFletes.Text.ToDate, -1, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then - CveFlete = ObjInv.CveFlete - Alert("Costo indirecto creado correctamente") - End If - ObjInv.Dispose() - Case 240 - Dim ObjCompras As New ClsCompras - CveImportacion = ObjCompras.AddImportacion(TxtPedimento.Text.Trim, TxtDescripcionModalFletesImportacion.Text.Trim, CveProveedor, -1, TxtFechaModalImportacionesFletes.Text.ToDate, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - ObjCompras.Dispose() - If CveImportacion > 0 Then Alert("Importación creada correctamente") - End Select - If CveFlete > 0 Or CveImportacion > 0 Then - RblTipo.SelectedValue = "1" - CambiaTipo() - CargaCombosFletesImportaciones() - Select Case DdlFleteImportacion.SelectedValue.ToEntero - Case 237 - DdlFletes.SelectedValueExist(CveFlete) - Case 240 - DdlImportaciones.SelectedValueExist(CveImportacion) - End Select - TxtFechaModalImportacionesFletes.Text = Now.ToShortDateString - TxtDescripcionModalFletesImportacion.Text = "" - TxtPedimento.Text = "" - UpModalFletesImportaciones.Update() - End If - End Sub - - Private Sub CargaCombosFletesImportaciones() - DdlFletes.Items.Clear() - DdlImportaciones.Items.Clear() - - Dim ObjCompras As New ClsCompras - If ObjCompras.GetImportaciones(-1, -1, -1, "-1", "-1", UsuarioActual.CveEmpresa) Then - DdlImportaciones.DataSource = ObjCompras.DtResultados - DdlImportaciones.Items.Insert(0, New ListItem("Seleccione", "-1")) - End If - ObjCompras.Dispose() - - Dim ObjInv As New ClsInventarios - If ObjInv.GetFletes(UsuarioActual.CveEmpresa) Then - DdlFletes.DataSource = ObjInv.DtResultados - DdlFletes.Items.Insert(0, New ListItem("Seleccione", "-1")) - End If - ObjInv.Dispose() - - DdlImportaciones.DataBind() - DdlFletes.DataBind() - - End Sub - - Private Sub LnkFletesImportaciones_Click(sender As Object, e As EventArgs) Handles LnkFletesImportaciones.Click - CargaModalFletesImportaciones() - End Sub - - - Protected Sub DdlFleteImportacion_SelectedIndexChanged1(sender As Object, e As EventArgs) - CambiaTipo() - UpModalFletesImportaciones.Update() End Sub -#End Region + Private Sub RegeneraPrePoliza() + 'Alert($"CvePrePoliza de la compra: {CvePrePoliza}", TipoMensaje.MsgInformacion) - Private Function AjustarPrePolizaVinculacionOC(ByRef OC As ClsOC, ByRef OCBitacora As ClsOIEventos, ByRef ObjInventarios As ClsInventarios, ByRef ObjConta As ClsContabilidad, ByRef ObjAC As ClsContPAQi) As Boolean - - 'VARIABLES - Dim CveProveedorSucursal As Integer = -1 - Dim CveProveedorContacto As Integer = -1 - Dim Retorno As Boolean = True - Dim CveProveedor As Integer = -1 - Dim GeneraReq = False - Dim IDPoliza As Integer = 0 - - - 'EMPIEZA OBJETOS Y TRANSACCIONES - 'Dim OC As New ClsOC - 'Dim OCBitacora As New ClsOIEventos(OC.IniciaTransacSQL()) - 'Dim ObjInventarios As New ClsInventarios(OC.IniciaTransacSQL()) - 'Dim ObjConta As New ClsContabilidad(OC.IniciaTransacSQL()) - - - - Dim DtInvOC As New DataTable - Dim DtInvOCDiferencias As New DataTable 'Actualizado con diferencia - DtInvOCDiferencias.Columns.Add("CveOrdenCompra", GetType(Integer)) - DtInvOCDiferencias.Columns.Add("CveOrdenCompraDetalle", GetType(Integer)) - DtInvOCDiferencias.Columns.Add("Diferencia", GetType(Decimal)) - DtInvOCDiferencias.Columns.Add("PUCompra", GetType(Decimal)) - DtInvOCDiferencias.Columns.Add("CveMoneda", GetType(Integer)) - DtInvOCDiferencias.Columns.Add("FolioOC", GetType(String)) - DtInvOCDiferencias.Columns.Add("CveProveedor", GetType(Integer)) - 'DtInvOCDiferencias.Columns.Add("ImporteMovto", GetType(Double)) - 'DtInvOCDiferencias.Columns.Add("ImporteMovtoDLLS", GetType(Double)) - DtInvOCDiferencias.Columns.Add("CveAlmacen", GetType(Integer)) - DtInvOCDiferencias.Columns.Add("CveMovimiento", GetType(Integer)) - DtInvOCDiferencias.Columns.Add("FolioAlmacen", GetType(String)) - DtInvOCDiferencias.Columns.Add("TipoCambioAjuste", GetType(Double)) - DtInvOCDiferencias.Columns.Add("ConceptoSalida", GetType(Integer)) - DtInvOCDiferencias.Columns.Add("PS", GetType(String)) - - - Dim dr2 As DataRow - For Each gvr As GridViewRow In GvOC1.Rows - If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Then - dr2 = DTOCGV.Rows(gvr.RowIndex) - - Dim diferencia As Decimal = (dr2("PU").ToString.ToDecimal - gvr.FCTextBox("TxtPU").Text.ToDecimal) * gvr.FCTextBox("TxtCantidad").Text.ToDecimal - - Dim DrInvOCDiferencias As DataRow - If diferencia <> 0 Then 'And DtInvOC.Rows.Count > 0 - DrInvOCDiferencias = DtInvOCDiferencias.NewRow - DrInvOCDiferencias("CveOrdenCompra") = dr2("CveOrdenCompra").ToString.ToEntero - DrInvOCDiferencias("CveOrdenCompraDetalle") = dr2("CveOrdenCompraDetalle").ToString.ToEntero - DrInvOCDiferencias("Diferencia") = diferencia.RoundSQL() - DrInvOCDiferencias("PUCompra") = Math.Round(gvr.FCTextBox("TxtPU").Text.ToDecimal, 6) - DrInvOCDiferencias("CveMoneda") = dr2("CveMoneda").ToString.ToEntero - DrInvOCDiferencias("FolioOC") = dr2("FolioOC").ToString - DrInvOCDiferencias("CveProveedor") = dr2("CveProveedorOC").ToString.ToEntero - DrInvOCDiferencias("PS") = dr2("PS").ToString - DrInvOCDiferencias("FolioAlmacen") = dr2("FolioAlmacen").ToString - - If DdlOCVinculaInv.SelectedValue.ToEntero.Contiene(205) Then - DrInvOCDiferencias("TipoCambioAjuste") = 0 - DrInvOCDiferencias("CveAlmacen") = 0 - DrInvOCDiferencias("CveMovimiento") = 0 - DrInvOCDiferencias("ConceptoSalida") = 0 - DtInvOCDiferencias.Rows.Add(DrInvOCDiferencias) - Else - If ObjInventarios.GetMovimientosOC(dr2("CveOrdenCompra").ToString.ToEntero, UsuarioActual.CveEmpresa) Then - DtInvOC = ObjInventarios.DtResultados.FiltraParametros($"CvePS > 0 AND CveOrdenCompraDetalle = {dr2("CveOrdenCompraDetalle").ToString.ToEntero}").Copy - End If - Dim drInv As DataRow = DtInvOC.FiltroPrimero("") + 'MOVIMIENTOS DE ALMACEN DE LA COMPRA + Dim ObjInventarios As New ClsInventarios + Dim DtInv As New DataTable + If ObjInventarios.GetInv_ComprasMov(CveCompra, UsuarioActual.CveEmpresa) AndAlso ObjInventarios.DtResultados.Rows.Count > 0 Then + DtInv = ObjInventarios.DtResultados + End If + ObjInventarios.Dispose() + + Dim DtTemporal = TmpDT.Copy + DtTemporal.Columns.Add("ImporteEnAlmacen", GetType(Decimal)) + + Dim ObjConta As New ClsContabilidad + ObjConta.IniciaTransacSQL() + Dim TieneError = True + + 'ELIMINA DETALLES DE [AF - INV - GASTO] + If ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 49, CveCompra, 1) Then + If ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 68, CveCompra, 1) Then + If ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 6, CveCompra, 1) Then + TieneError = False + End If + End If + End If + + 'INGRESAMOS DETALLES + If Not TieneError Then + + 'CONFIGURACIONES + Dim CuentasContablesInvalidas As New StringBuilder + Dim CuentasContablesInvalidasSIG As New StringBuilder + Dim IdCtaContable As Integer = 0 + Dim CveCuenta As Integer = 0 + Dim CveProveedorConcepto = 0 + Dim Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + Dim Multiplicador = If(DdlTipoComprobante.SelectedValue = "NC", -1, 1) + + Dim ImporteMovimiento = 0.0D + Dim importeMN = 0.0D + + Dim TipoCambioActual = 0.0D + Dim TipoCambioPago = 0.0D + Dim FechaMovimiento As Date = TxtFecha.Text.ToDate + + 'TIPO CAMBIO + If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then + TipoCambioActual = GlobalTipoCambio(FechaMovimiento).ToString.ToDecimal + TipoCambioPago = GlobalTipoCambio(TxtFechaPago.Text.ToDate).ToString.ToDecimal + Else + TipoCambioActual = 1 + TipoCambioPago = 1 + End If + + 'CTA PROVEEDOR + Select Case RBLContado.SelectedValue + Case "4" ' Deudores + CveProveedorConcepto = DdlDeudor.SelectedValue.ToEntero + Case "5" ' Acreedores + CveProveedorConcepto = DdlAcreedor.SelectedValue.ToEntero + Case Else ' Proveedores - F y E - Doctos + CveProveedorConcepto = CveProveedor + End Select + + + 'INGRESA DETALLE DE AF(49) - TipoAF 2 es para las compras + Dim DT = DtTemporal.FiltraParametros("ISNULL(TipoAF,0) = 2") + If DT.Rows.Count > 0 AndAlso DdlTipoComprobante.SelectedValue <> "NC" Then + For Each Row2 As DataRow In DT.Rows + ImporteMovimiento = Row2("Total").ToString.ToDecimal * Multiplicador + importeMN = ImporteMovimiento * TipoCambioActual + If ObjConta.GetRetCuenta(49, Row2("CveActivoFijo").ToString.ToEntero) Then + If ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijo").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCtaContActivoFijoSIG").ToString.ToEntero + End If + End If + If ImporteMovimiento <> 0 Then + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 49))("ConceptoContable").ToString) + End If + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 49))("ConceptoContable").ToString) + End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, Row2("CodAF").ToString, 49, Concepto, FechaMovimiento, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveActivoFijo:=Row2("CveActivoFijo").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(TipoCambioActual = 1, 0, ImporteMovimiento), CveCuenta:=CveCuenta) Then + TieneError = True + End If + End If + Next + End If + + ImporteMovimiento = 0 + IdCtaContable = 0 + + 'INGRESA DETALLE DE ALMACÉN(68) + Dim DtAlmacenes = GlobalDTAlmacen(UsuarioActual.CveEmpresa) + If UsuarioActual.Empresa.UsaInventarios AndAlso Not UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + Dim CveMovimientoInventario = -1 + Dim ModalidadAlmacen = -1 + Dim DtMovtosAlmacen As New DataTable + DtMovtosAlmacen.Columns.Add("CveMovimiento", GetType(Integer)) + DtMovtosAlmacen.Columns.Add("IdCtaContable", GetType(Integer)) + DtMovtosAlmacen.Columns.Add("CveCuenta", GetType(Integer)) + DtMovtosAlmacen.Columns.Add("Importe", GetType(Decimal)) + + If DtTemporal.FiltraParametros("ISNULL(TipoAF,0) <> 2").Rows.Count > 0 Then + For Each Row2 As DataRow In DtTemporal.FiltraParametros("ISNULL(TipoAF,0) <> 2").Rows + 'VALIDAMOS TIPO ALMACEN DE LA COMPRA DETALLE - SI ES TIPO "SOLO EXISTENCIA" (0) SKIPEAMOS + ModalidadAlmacen = DtInv.MIN("ModalidadAlmacen", $"CveCompraDetalle = {Row2("CveCompraDetalle")}").ToEntero + If ModalidadAlmacen = 0 Then + Continue For + End If + CveMovimientoInventario = DtInv.MAX("CveMovimiento", $"CveCompraDetalle = {Row2("CveCompraDetalle")}").ToEntero + IdCtaContable = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen = {DtInv.MIN("CveAlmacen", $"CveCompraDetalle = {Row2("CveCompraDetalle")}")}").ToEntero + CveCuenta = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContableSIG", $"CveAlmacen = {DtInv.MIN("CveAlmacen", $"CveCompraDetalle = {Row2("CveCompraDetalle")}")}").ToEntero + + ImporteMovimiento = DtInv.SUM(If(DdlMoneda.SelectedValue = "1", "Total", "TotalExtranjero"), $"CveCompraDetalle = {Row2("CveCompraDetalle")}").ToDecimal + ImporteMovimiento = If(ImporteMovimiento > Row2("Total").ToString.ToDecimal, Row2("Total").ToString.ToDecimal, ImporteMovimiento) * Multiplicador + + 'VALIDA QUE CUANDO SEA DOLARES TENGA PUEXTRANJERO EN EL MOVTO DE ALMACEN + If DdlMoneda.SelectedValue = "2" And ImporteMovimiento = 0 And DtInv.SUM("Total", $"CveCompraDetalle = {Row2("CveCompraDetalle")}").ToDecimal > 0 Then + TieneError = True + Exit For + End If + + Dim DrInv = DtMovtosAlmacen.NewRow + DrInv("CveMovimiento") = CveMovimientoInventario + DrInv("IdCtaContable") = IdCtaContable + DrInv("CveCuenta") = CveCuenta + DrInv("Importe") = ImporteMovimiento + DtMovtosAlmacen.Rows.Add(DrInv) + + If ImporteMovimiento <> 0 Then + Row2("ImporteEnAlmacen") = ImporteMovimiento + End If + Next + + For Each Row As DataRow In DtMovtosAlmacen.FiltraParametros("", "", {"CveMovimiento", "IdCtaContable"}).Rows + ImporteMovimiento = DtMovtosAlmacen.SUM("Importe", $"CveMovimiento = {Row("CveMovimiento").ToString.ToEntero} AND IdCtaContable = {Row("IdCtaContable").ToString.ToEntero}").ToString.ToDecimal + importeMN = ImporteMovimiento * TipoCambioActual + If ImporteMovimiento <> 0 Then + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) + End If + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 68))("ConceptoContable").ToString) + End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, Concepto, 68, Concepto, FechaMovimiento, Row("IdCtaContable").ToString.ToEntero, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveMovimientoAlmacen:=Row("CveMovimiento").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(TipoCambioActual = 1, 0, ImporteMovimiento), CveCuenta:=Row("CveCuenta").ToString.ToEntero) Then + TieneError = True + Exit For + End If + End If + Next + End If + End If + + ImporteMovimiento = 0 + IdCtaContable = 0 + CveCuenta = 0 + + 'INGRESA DETALLE DE GASTO(6) + DT = DtTemporal + 'RECORREMOS PARA DETECTAR LA MODALIDAD DEL ALMACEN, EN CASO DE SER SOLO EXISTENCIA LIMPIAMOS CVEALMACEN + For Each Dr As DataRow In DT.Rows + Dr("CveAlmacen") = DtInv.MIN("ModalidadAlmacen", $"CveCompraDetalle = {Dr("CveCompraDetalle")}").ToEntero + Dr.AcceptChanges() + Next + DT.AcceptChanges() + + If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + DT = DT.FiltraParametros("ISNULL(TipoAF,0) <> 2", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveProyecto", "CveSubProyecto"}) + Else + DT = DT.FiltraParametros("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1", "", {"CveClasificacion", "Clasificacion", "SubProyecto", "CveProyecto", "CveSubProyecto"}) + End If + + If DT.Rows.Count > 0 Then + Dim ImporteAlmacen = 0.0D + For Each Row2 As DataRow In DT.Rows + If UsuarioActual.Empresa.Funcionalidad(126) = "1" Then + ImporteMovimiento = DtTemporal.SUM("Total", String.Format("ISNULL(TipoAF,0) <> 2 AND CveClasificacion = {0} AND CveSubProyecto = {1}", Row2("CveClasificacion"), Row2("CveSubProyecto"))).ToString.ToDecimal + ImporteAlmacen = DtTemporal.SUM("ImporteEnAlmacen", String.Format("ISNULL(TipoAF,0) <> 2 AND CveClasificacion = {0} AND CveSubProyecto = {1}", Row2("CveClasificacion"), Row2("CveSubProyecto"))).ToString.ToDecimal + Else + ImporteMovimiento = DtTemporal.SUM("Total", String.Format("ISNULL(TipoAF,0) <> 2 AND ISNULL(CveAlmacen,0) = 0 AND ISNULL(AplicaCostoIndirecto,0) <> 1 AND CveClasificacion = {0} AND CveSubProyecto = {1}", Row2("CveClasificacion"), Row2("CveSubProyecto"))).ToString.ToDecimal + ImporteAlmacen = DtTemporal.SUM("ImporteEnAlmacen", String.Format("ISNULL(TipoAF,0) <> 2 AND CveClasificacion = {0} AND CveSubProyecto = {1}", Row2("CveClasificacion"), Row2("CveSubProyecto"))).ToString.ToDecimal + End If + ImporteMovimiento = (ImporteMovimiento - ImporteAlmacen) * Multiplicador + importeMN = ImporteMovimiento * TipoCambioActual + If Row2("CveClasificacion").ToString.ToEntero > 0 Then + If ObjConta.GetRetCuenta(6, Row2("CveClasificacion").ToString.ToEntero) Then + If ObjConta.DtResultados.Rows.Count > 0 AndAlso (ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero > 0 Or ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero > 0) Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaGasto").ToString.ToEntero + CveCuenta = ObjConta.DtResultados.Rows(0)("IdCuentaGastoSIG").ToString.ToEntero + Else + IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGasto", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero + CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", String.Format("CveClasificacion = {0}", Row2("CveClasificacion"))).ToString.ToEntero + End If + End If + End If + Dim IdSegmentoNegocio As Integer = -1 + Dim drT As DataRow = GlobalDTSubProyectos(-1, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero).FiltroPrimero(String.Format("CveSubProyecto = {0} ", Row2("CveSubProyecto"))) + If drT IsNot Nothing Then + IdSegmentoNegocio = drT("IdSegNeg").ToString.ToEntero + End If + If ImporteMovimiento <> 0 Then + If IdCtaContable = 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) + End If + If CveCuenta = 0 Then + CuentasContablesInvalidasSIG.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", 6))("ConceptoContable").ToString) + End If + Dim tcvecon As Integer = 6 + Dim tidctacon As Integer = 6 + tidctacon = IdCtaContable + If DdlTipoComprobante.SelectedValue = "Ant" Then + tcvecon = 264 + tidctacon = ViewState("CtaProveedorAnticipos").ToString.ToEntero + If DdlMoneda.SelectedValue = "2" Then + tidctacon = ViewState("CtaProveedorAnticiposExtranjera").ToString.ToEntero + End If + End If + + Concepto = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, Concepto, tcvecon, Concepto, FechaMovimiento, IdCtaContable, IdSegmentoNegocio, CveCompra:=CveCompra, CveProveedor:=CveProveedorConcepto, CveClasificacion:=Row2("CveClasificacion").ToString.ToEntero, CveSubProyecto:=Row2("CveSubProyecto").ToString.ToEntero, ImporteMX:=importeMN, ImporteME:=If(TipoCambioActual = 1, 0, ImporteMovimiento), CveCuenta:=CveCuenta) Then + TieneError = True + End If + + End If + Next + End If + + End If + + + If Not TieneError Then + ObjConta.Commit() + Alert("La PrePoliza se regeneró correctamente.", TipoMensaje.MsgInformacion) + Else + ObjConta.RollBack() + Alert("Ocurrió un error al regenerar la PrePoliza. Por favor vuelva a intentar.", TipoMensaje.MsgError) + End If + + ObjConta.Dispose() + + End Sub +#End Region + +#Region " ACTUALIZAR TIPO CAMBIO PREPOLIZA " + Private Sub InicializaActualizarTC() + If CveCompra > 0 And DdlMoneda.SelectedValue.ToEntero = 2 And CvePrePoliza > 0 Then + TxtActualizarTC_TCActual.Text = TipoCambio.FormatoNumero(4) + TxtActualizarTC_TCActualizar.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).FormatoNumero(4) + HLModalActualizarTC.Visible = True + End If + End Sub + Protected Sub BtnActualizarTC_Click(sender As Object, e As EventArgs) + Dim ObjContabilidad As New ClsContabilidad + Dim ObjCompras As New ClsCompras(ObjContabilidad.IniciaTransacSQL()) + Dim ObjEventos As New ClsOIEventos(ObjContabilidad.IniciaTransacSQL()) + Dim TieneError = False + Dim MensajeError = "" + + If ObjEventos.AddEventoBitacora($"Se actualizó el Tipo de Cambio de la compra. TC anterior: {TxtActualizarTC_TCActual.Text.FormatoNumero(4)} | TC actual: {TxtActualizarTC_TCActualizar.Text.FormatoNumero(4)}", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=CveCompra) Then + If ObjCompras.UpdateCompraTipoCambio(TxtActualizarTC_TCActualizar.Text.ToDouble, CveCompra, CvePrePoliza, UsuarioActual.CveEmpresa) Then + If Not ObjContabilidad.ReconstruirPP_Compra(CveCompra) Then + TieneError = True + MensajeError = "Ocurrió un error al actualizar el Tipo de Cambio al documento" + End If + Else + TieneError = True + MensajeError = "Ocurrió un error al actualizar el asiento contable" + End If + Else + TieneError = True + MensajeError = "Ocurrió un error al guardar el historal al actualizar el Tipo de Cambio al documento" + End If + + If Not TieneError Then + ObjContabilidad.Commit() + Alert("Se actualizó correctamente el tipo de cambio del documento.", TipoMensaje.MsgInformacion) + RegistraScript("$('#ModalActualizarTC').modal('hide');") + Else + ObjContabilidad.RollBack() + Alert(MensajeError, TipoMensaje.MsgError) + End If + + ObjContabilidad.Dispose() + End Sub +#End Region + +#Region "PAQUETERIAS GUIAS" + Protected Sub LnkAgregarGuia_Click(sender As Object, e As EventArgs) + '' 25/05/2018 - Se agrega Link a Modulo Paqueterias Guias + RegistraScript(String.Format("AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveCompra={0}',800,620);", CveCompra)) + End Sub +#End Region + +#Region "DEDUCCIONES IEPS / OTROS IMPUESTOS" + Protected Sub CargaProductos(Ddl As DropDownList, CvePS As Integer) + Ddl.DataSource = TmpDT + Ddl.DataBind() + Ddl.Items.Insert(0, New ListItem("Seleccione un concepto", "-1")) + Ddl.SelectedValueExist("-1") + + If CvePS > 0 Then + Ddl.Items.Insert(1, New ListItem(GlobalDTPS(UsuarioActual.CveEmpresa, CvePS).FiltroPrimeroValor("PS"), CvePS.ToString)) + End If + + 'Ddl.Items.Insert(1, New ListItem(Concepto, "-1")) + End Sub + + Protected Sub BtnAgregarIEPS_Click(sender As Object, e As EventArgs) + TrasladoIEPS = TxtIEPS.Text.ToDecimal + OtrosImpuestos = TxtOtrosImpuestos.Text.ToDecimal + + If ChkIEPS.Checked Then IEPSGasto = True + If ChkOtrosI.Checked Then OtrosImpuestosGasto = True + + If IEPSGasto Or OtrosImpuestosGasto Then + + 'AGREGA IEPS COMO CONCEPTO + If IEPSGasto Then + Dim CvePS As Integer = DdlConceptoIEPS.SelectedValue.ToEntero + ' If CvePS = -1 Then CvePS = UsuarioActual.Empresa.Funcionalidad(112).ToString.ToEntero + AgregarConceptoIEPS(TrasladoIEPS, CvePS) + TrasladoIEPS = 0 + TxtIEPS.Text = 0.ToString.FormatoNumero + TrIEPS.Visible = False + For Each Dr As DataRow In TmpDT.Rows + Dr("IEPSPS") = 0 + Dr("IEPSPSPorcentaje") = 0 + Next + TmpDT.AcceptChanges() + End If + 'AGREGA OTROS IMPUESTOS COMO CONCEPTO + If OtrosImpuestosGasto Then + Dim CvePS As Integer = DdlConceptoOI.SelectedValue.ToEntero + 'If CvePS = -1 Then CvePS = UsuarioActual.Empresa.Funcionalidad(305).ToString.ToEntero + AgregarConceptoIEPS(OtrosImpuestos, CvePS) + OtrosImpuestos = 0 + TxtOtrosImpuestos.Text = 0.ToString.FormatoNumero + TrOtrosImpuestos.Visible = False + End If + + CargaGvPersonal() + UpPS.Update() + RegistraScript("$('#ModalIEPS').modal('hide');") + Else + Alert("Debe seleccionar al menos un impuesto", TipoMensaje.MsgAdvertencia) + End If + + End Sub +#End Region + +#Region "C R E D I T O S" + + Private Sub ChkCreditoMultiple_CheckedChanged(sender As Object, e As EventArgs) Handles ChkCreditoMultiple.CheckedChanged + + If ChkCreditoMultiple.Checked Then + + romCreditosTabla.Visible = True + Dim ObjBancos As New ClsBancos + + If ObjBancos.GetCreditosDetalleCompras(UsuarioActual.CveEmpresa, CveProveedor, -1, -1, -1) Then + GvCreditos.DataSource = ObjBancos.DtResultados + Else + GvCreditos.DataSource = Nothing + End If + + ObjBancos.Dispose() + GvCreditos.DataBind() + + End If + End Sub + + Private Sub GvCreditos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvCreditos.RowDataBound + + If e.Row.RowType = DataControlRowType.DataRow Then + + Dim TxtCapital As TextBox = e.Row.FCTextBox("TxtCapital") + Dim TxtInteres As TextBox = e.Row.FCTextBox("TxtInteres") + Dim TxtAmbos As TextBox = e.Row.FCTextBox("TxtAmbos") + Dim CveCreditoDetalle As Integer = e.Row.DataKey("CveCreditoDetalle").ToEntero + + Dim CveCompraCapital As Integer = e.Row.DataKey("CveCompra").ToEntero + Dim CveCompraInteres As Integer = e.Row.DataKey("CveCompraInteres").ToEntero + + If CveCompraCapital > 0 Then + TxtCapital.Enabled = False + TxtAmbos.Enabled = False + End If + + If CveCompraInteres > 0 Then + TxtInteres.Enabled = False + TxtAmbos.Enabled = False + End If + + TxtCapital.Attributes.Add("class", $"CsCreGlobal CsSelCapital{CveCreditoDetalle}") + TxtCapital.Attributes.Add("onkeyup", $"ValidaCredito(this,event,{CveCreditoDetalle},1)") + 'TxtCapital.Attributes.Add("data-CD", CveCreditoDetalle.ToString) + + TxtInteres.Attributes.Add("class", $"CsCreGlobal CsSelInteres{CveCreditoDetalle}") + TxtInteres.Attributes.Add("onkeyup", $"ValidaCredito(this,event,{CveCreditoDetalle},1)") + 'TxtInteres.Attributes.Add("data-CD", CveCreditoDetalle.ToString) + + TxtAmbos.Attributes.Add("class", $"CsCreGlobal CsSelAmbos{CveCreditoDetalle}") + TxtAmbos.Attributes.Add("onkeyup", $"ValidaCredito(this,event,{CveCreditoDetalle},2)") + 'TxtAmbos.Attributes.Add("data-CD", CveCreditoDetalle.ToString) + + + + End If + End Sub + + Private Sub CargaCreditosDisponibles() + + + If RBLPago.SelectedValue.ToEntero = 4 Then + + Dim ObjBancos As New ClsBancos + If ObjBancos.GetCreditosDetalleCompras(UsuarioActual.CveEmpresa, CveProveedor, -1, -1, -1) Then + + GvCreditos.DataSource = ObjBancos.DtResultados + Else + GvCreditos.DataSource = Nothing + End If + ObjBancos.Dispose() + romCreditosTabla.Visible = True + GvCreditos.DataBind() + + Else + romCreditosTabla.Visible = False + End If + + UpGvCreditos.Update() + + End Sub +#End Region + +#Region "FLETES / IMPORTACIONES" + Private Sub CargaFolio() + Dim ObjFolios As New ClsGralFolios + If ObjFolios.GetFolios("FLE", UsuarioActual.CveEmpresa) Then + If ObjFolios.DtResultados.Rows.Count > 0 Then + LblFolioModalFletes.Text = ObjFolios.DtResultados(0)("FActual").ToString + BtnCrearFleteImportacion.Enabled = True + Else + Alert("Necesita registrar un folio de fletes", TipoMensaje.MsgAdvertencia) + BtnCrearFleteImportacion.Enabled = False + End If + End If + ObjFolios.Dispose() + End Sub + Protected Sub BtnGuardarModalFletesImportaciones_Click(sender As Object, e As EventArgs) + If DdlFleteImportacion.SelectedValue.ToEntero = 237 And Not DdlFletes.SelectedValue.ToEntero > 0 Then Alert("Tiene que seleccionar un flete", TipoMensaje.MsgAdvertencia) : Exit Sub + If DdlFleteImportacion.SelectedValue.ToEntero = 240 And Not DdlImportaciones.SelectedValue.ToEntero > 0 Then Alert("Tiene que seleccionar una importación", TipoMensaje.MsgAdvertencia) : Exit Sub + If DdlFletes.SelectedValue.ToEntero > 0 Then + Dim ObjInventario As New ClsInventarios + Dim Dr As DataRow = Nothing + If ObjInventario.GetFletes(UsuarioActual.CveEmpresa, DdlFletes.SelectedValue.ToEntero) Then + If ObjInventario.DtResultados.Rows.Count > 0 Then + Dr = ObjInventario.DtResultados.Rows(0) + End If + End If + If Dr IsNot Nothing Then + If Dr("CveCompra").ToString.ToEntero > 0 And RblFleteImportacionOpcion.SelectedValue.ToEntero = 1 Then + Alert("Este flete ya tiene compra asignada", TipoMensaje.MsgAdvertencia) + ObjInventario.Dispose() + Exit Sub + End If + End If + ObjInventario.Dispose() + End If + + If DdlFleteImportacion.SelectedValue.ToEntero = 237 Then DdlTipoCompra.SelectedValueExist("4") : UpEstatus.Update() + If DdlFleteImportacion.SelectedValue.ToEntero = 240 Then DdlTipoCompra.SelectedValueExist("5") : UpEstatus.Update() + + CveImportacion = DdlImportaciones.SelectedValue.ToEntero + CveFlete = DdlFletes.SelectedValue.ToEntero + FleteImportacionOpcion = RblFleteImportacionOpcion.SelectedValue.ToEntero + CveConceptoContableAlmacen = DdlFleteImportacion.SelectedValue.ToEntero + + + If CveCompra > 0 AndAlso (CveImportacion > 0 Or CveFlete > 0) Then + Dim ObjCompras As New ClsCompras + Dim ObjConta As New ClsContabilidad(ObjCompras.IniciaTransacSQL) + Dim ObjInventario As New ClsInventarios(ObjCompras.IniciaTransacSQL) + Dim ErrorTrans As Boolean = False + + Select Case CveConceptoContableAlmacen + Case 237 + Select Case FleteImportacionOpcion + Case 1 + Dim Dr As DataRow = Nothing + If ObjInventario.GetFletes(UsuarioActual.CveEmpresa, CveFlete) Then + If ObjInventario.DtResultados.Rows.Count > 0 Then + Dr = ObjInventario.DtResultados.Rows(0) + End If + End If + If Dr IsNot Nothing Then + If Not ObjInventario.UpdateFlete(CveFlete, Dr("Descripcion").ToString, Dr("Fecha").ToString.ToDate, -1, CveCompra, UsuarioActual.CveUsuario) Then + ErrorTrans = True + End If + Else + ErrorTrans = True + End If + Case 2 + If Not ObjInventario.AddFleteDetalle(CveFlete, CveCompra) Then + ErrorTrans = True + End If + 'actualiza la compra para que no se surta en almacen. sino por el flete o importación + If Not ObjCompras.UpdateEstatusAlmacen(CveCompra, 2) Then + ErrorTrans = True + End If + End Select + Case 240 + Select Case FleteImportacionOpcion + Case 1 + If Not ObjCompras.AddImportacionCompra(CveImportacion, CveCompra) Then + ErrorTrans = True + End If + Case 2 + If Not ObjCompras.AddImportacionDetalle(CveImportacion, CveCompra) Then + ErrorTrans = True + End If + 'actualiza la compra para que no se surta en almacen. sino por el flete o importación + If Not ObjCompras.UpdateEstatusAlmacen(CveCompra, 2) Then + ErrorTrans = True + End If + End Select + End Select + + 'Removemos los conceptos de la prepoliza + If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 6, CveCompra, 1) Then ErrorTrans = False 'GASTO + If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 68, CveCompra, 1) Then ErrorTrans = False 'ALMACEN + If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 49, CveCompra, 1) Then ErrorTrans = False 'AF + If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 205, CveCompra, 1) Then ErrorTrans = False 'PS YA RECIBIDO + If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 230, CveCompra, 1) Then ErrorTrans = False 'PS YA RECIBIDO + If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 231, CveCompra, 1) Then ErrorTrans = False 'PS YA RECIBIDO + If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 176, CveCompra, 1) Then ErrorTrans = False 'PS NO RECIBIDO + If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 228, CveCompra, 1) Then ErrorTrans = False 'PS NO RECIBIDO + If Not ObjConta.RemovePrePolizasDetalle(CvePrePoliza, 229, CveCompra, 1) Then ErrorTrans = False 'PS NO RECIBIDO + + Dim ConceptoContabilizacion As Integer = CveConceptoContableAlmacen + Dim ConceptoContabilizacionME As Integer = -1 + Dim ConceptoContabilizacionMEComp As Integer = -1 + Dim importeMovimiento As Decimal = 0 + Dim importeMN As Decimal = 0 + Dim IdCtaContable As Integer = -1 + Dim IdCtaContableME As Integer = -1 + Dim IdCtaContableMEComp As Integer = -1 + Dim tipoCambioActual As Decimal = 0 + Dim Multiplicador = If(DdlTipoComprobante.SelectedValue = "NC", -1, 1) + + If DdlMoneda.SelectedValue.ToString.ToEntero = 2 Then + tipoCambioActual = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString.ToDecimal + tipoCambioActual = If(DivTC.Visible, TipoCambio.ToDecimal, tipoCambioActual) + Else + tipoCambioActual = 1 + End If + + Select Case ConceptoContabilizacion + Case 237 + ConceptoContabilizacionME = 238 + ConceptoContabilizacionMEComp = 239 + importeMovimiento = TmpDT.SUMD(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")) + importeMN = importeMovimiento * tipoCambioActual * Multiplicador 'TIENE QUE TENER EL IMPORTEMN IGUAL AL IMPORTEMOVIMIENTO PORQUE NO TOMA EN CUENTA SI UN PRODUCTO ES TIPO SERVICIO + Case 240 + ConceptoContabilizacionME = 241 + ConceptoContabilizacionMEComp = 242 + importeMovimiento = TmpDT.SUMD(If(ListaDocumentos IsNot Nothing AndAlso ListaDocumentos.Count > 0 AndAlso ArrAnticipos IsNot Nothing AndAlso ArrAnticipos.Count > 0 AndAlso TxtTotal.Text.ToDecimal = 0, "ImporteSinImpuestos", "Total")) + importeMN = importeMovimiento * tipoCambioActual * Multiplicador 'TIENE QUE TENER EL IMPORTEMN IGUAL AL IMPORTEMOVIMIENTO PORQUE NO TOMA EN CUENTA SI UN PRODUCTO ES TIPO SERVICIO + End Select + + If ObjConta.GetRetCuenta(ConceptoContabilizacion, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + End If + + If ObjConta.GetRetCuenta(ConceptoContabilizacionME, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableME = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + End If + + If ObjConta.GetRetCuenta(ConceptoContabilizacionMEComp, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableMEComp = ObjConta.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero + End If + Dim Concepto As String = $"{NombreProveedor} {TxtSerie.Text} - {TxtFolio.Text}" + If DdlMoneda.SelectedValue.ToEntero <> 1 Then + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMovimiento, Concepto, ConceptoContabilizacionME, Concepto, TxtFecha.Text.ToDate, IdCtaContableME, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMovimiento, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), TipoCambio:=tipoCambioActual) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMN - importeMovimiento, Concepto, ConceptoContabilizacionMEComp, Concepto, TxtFecha.Text.ToDate, IdCtaContableMEComp, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMN - importeMovimiento, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), TipoCambio:=tipoCambioActual) Then + ErrorTrans = True + End If + Else + ErrorTrans = True + End If + Else + + If importeMN <> 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importeMN, Concepto, ConceptoContabilizacion, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=importeMN, ImporteME:=If(tipoCambioActual = 1, 0, importeMovimiento), TipoCambio:=tipoCambioActual) Then + ErrorTrans = True + End If + End If + + If Not ErrorTrans Then + ObjCompras.Commit() + Else + ObjCompras.RollBack() + End If + ObjCompras.Dispose() + ObjConta.Dispose() + ObjInventario.Dispose() + + End If + + + RegistraScript("$('#ModalFletesImportaciones').modal('hide')") + End Sub + + Private Sub CargaModalFletesImportaciones() + + TxtFechaModalImportacionesFletes.Text = Now.ToShortDateString + TxtDescripcionModalFletesImportacion.Text = "" + TxtPedimento.Text = "" + RblTipo.SelectedValue = "1" + RblFleteImportacionOpcion.SelectedValue = "1" + CargaCombosFletesImportaciones() + CambiaTipo() + DdlFletes.SelectedValueExist(CveFlete) + DdlImportaciones.SelectedValueExist(CveImportacion) + If FleteImportacionOpcion > 0 Then RblFleteImportacionOpcion.SelectedValue = FleteImportacionOpcion.ToString + RegistraScript("$('#ModalFletesImportaciones').modal()") + UpModalFletesImportaciones.Update() + End Sub + Protected Sub RblTipo_SelectedIndexChanged(sender As Object, e As EventArgs) + CambiaTipo() + UpModalFletesImportaciones.Update() + End Sub + + Private Sub CambiaTipo() + Select Case RblTipo.SelectedValue.ToEntero + Case 1 + DivVinculacion.Visible = True + DivCrear.Visible = False + Select Case DdlFleteImportacion.SelectedValue.ToEntero + Case 237 + LblTitulo.Text = "Costo Indirecto" + DivFletes.Visible = True + DivImportaciones.Visible = False + Case 240 + LblTitulo.Text = "Importación" + DivFletes.Visible = False + DivImportaciones.Visible = True + End Select + Case 2 + DivVinculacion.Visible = False + DivCrear.Visible = True + Select Case DdlFleteImportacion.SelectedValue.ToEntero + Case 237 + LblTitulo.Text = "Costo Indirecto" + DivLblFolio.Visible = True + DivPedimento.Visible = False + CargaFolio() + Case 240 + LblTitulo.Text = "Importación" + DivLblFolio.Visible = False + DivPedimento.Visible = True + End Select + End Select + End Sub + Protected Sub BtnCrearFleteImportacion_Click(sender As Object, e As EventArgs) + Dim CveFlete As Integer = 0 + Dim CveImportacion As Integer = 0 + Select Case DdlFleteImportacion.SelectedValue.ToEntero + Case 237 + Dim ObjInv As New ClsInventarios + If ObjInv.AddFlete(LblFolioModalFletes.Text, TxtDescripcionModalFletesImportacion.Text.Trim, TxtFechaModalImportacionesFletes.Text.ToDate, -1, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then + CveFlete = ObjInv.CveFlete + Alert("Costo indirecto creado correctamente") + End If + ObjInv.Dispose() + Case 240 + Dim ObjCompras As New ClsCompras + CveImportacion = ObjCompras.AddImportacion(TxtPedimento.Text.Trim, TxtDescripcionModalFletesImportacion.Text.Trim, CveProveedor, -1, TxtFechaModalImportacionesFletes.Text.ToDate, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + ObjCompras.Dispose() + If CveImportacion > 0 Then Alert("Importación creada correctamente") + End Select + If CveFlete > 0 Or CveImportacion > 0 Then + RblTipo.SelectedValue = "1" + CambiaTipo() + CargaCombosFletesImportaciones() + Select Case DdlFleteImportacion.SelectedValue.ToEntero + Case 237 + DdlFletes.SelectedValueExist(CveFlete) + Case 240 + DdlImportaciones.SelectedValueExist(CveImportacion) + End Select + TxtFechaModalImportacionesFletes.Text = Now.ToShortDateString + TxtDescripcionModalFletesImportacion.Text = "" + TxtPedimento.Text = "" + UpModalFletesImportaciones.Update() + End If + End Sub + + Private Sub CargaCombosFletesImportaciones() + DdlFletes.Items.Clear() + DdlImportaciones.Items.Clear() + + Dim ObjCompras As New ClsCompras + If ObjCompras.GetImportaciones(-1, -1, -1, "-1", "-1", UsuarioActual.CveEmpresa) Then + DdlImportaciones.DataSource = ObjCompras.DtResultados + DdlImportaciones.Items.Insert(0, New ListItem("Seleccione", "-1")) + End If + ObjCompras.Dispose() + + Dim ObjInv As New ClsInventarios + If ObjInv.GetFletes(UsuarioActual.CveEmpresa) Then + DdlFletes.DataSource = ObjInv.DtResultados + DdlFletes.Items.Insert(0, New ListItem("Seleccione", "-1")) + End If + ObjInv.Dispose() + + DdlImportaciones.DataBind() + DdlFletes.DataBind() + + End Sub + + Private Sub LnkFletesImportaciones_Click(sender As Object, e As EventArgs) Handles LnkFletesImportaciones.Click + CargaModalFletesImportaciones() + End Sub + + + Protected Sub DdlFleteImportacion_SelectedIndexChanged1(sender As Object, e As EventArgs) + CambiaTipo() + UpModalFletesImportaciones.Update() + End Sub + +#End Region + + Private Function AjustarPrePolizaVinculacionOC(ByRef OC As ClsOC, ByRef OCBitacora As ClsOIEventos, ByRef ObjInventarios As ClsInventarios, ByRef ObjConta As ClsContabilidad, ByRef ObjAC As ClsContPAQi) As Boolean + + 'VARIABLES + Dim CveProveedorSucursal As Integer = -1 + Dim CveProveedorContacto As Integer = -1 + Dim Retorno As Boolean = True + Dim CveProveedor As Integer = -1 + Dim GeneraReq = False + Dim IDPoliza As Integer = 0 + + + 'EMPIEZA OBJETOS Y TRANSACCIONES + 'Dim OC As New ClsOC + 'Dim OCBitacora As New ClsOIEventos(OC.IniciaTransacSQL()) + 'Dim ObjInventarios As New ClsInventarios(OC.IniciaTransacSQL()) + 'Dim ObjConta As New ClsContabilidad(OC.IniciaTransacSQL()) + + + + Dim DtInvOC As New DataTable + Dim DtInvOCDiferencias As New DataTable 'Actualizado con diferencia + DtInvOCDiferencias.Columns.Add("CveOrdenCompra", GetType(Integer)) + DtInvOCDiferencias.Columns.Add("CveOrdenCompraDetalle", GetType(Integer)) + DtInvOCDiferencias.Columns.Add("Diferencia", GetType(Decimal)) + DtInvOCDiferencias.Columns.Add("PUCompra", GetType(Decimal)) + DtInvOCDiferencias.Columns.Add("CveMoneda", GetType(Integer)) + DtInvOCDiferencias.Columns.Add("FolioOC", GetType(String)) + DtInvOCDiferencias.Columns.Add("CveProveedor", GetType(Integer)) + 'DtInvOCDiferencias.Columns.Add("ImporteMovto", GetType(Double)) + 'DtInvOCDiferencias.Columns.Add("ImporteMovtoDLLS", GetType(Double)) + DtInvOCDiferencias.Columns.Add("CveAlmacen", GetType(Integer)) + DtInvOCDiferencias.Columns.Add("CveMovimiento", GetType(Integer)) + DtInvOCDiferencias.Columns.Add("FolioAlmacen", GetType(String)) + DtInvOCDiferencias.Columns.Add("TipoCambioAjuste", GetType(Double)) + DtInvOCDiferencias.Columns.Add("ConceptoSalida", GetType(Integer)) + DtInvOCDiferencias.Columns.Add("PS", GetType(String)) + + + Dim dr2 As DataRow + For Each gvr As GridViewRow In GvOC1.Rows + If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Then + dr2 = DTOCGV.Rows(gvr.RowIndex) + + Dim diferencia As Decimal = (dr2("PU").ToString.ToDecimal - gvr.FCTextBox("TxtPU").Text.ToDecimal) * gvr.FCTextBox("TxtCantidad").Text.ToDecimal + + Dim DrInvOCDiferencias As DataRow + If diferencia <> 0 Then 'And DtInvOC.Rows.Count > 0 + DrInvOCDiferencias = DtInvOCDiferencias.NewRow + DrInvOCDiferencias("CveOrdenCompra") = dr2("CveOrdenCompra").ToString.ToEntero + DrInvOCDiferencias("CveOrdenCompraDetalle") = dr2("CveOrdenCompraDetalle").ToString.ToEntero + DrInvOCDiferencias("Diferencia") = diferencia.RoundSQL() + DrInvOCDiferencias("PUCompra") = Math.Round(gvr.FCTextBox("TxtPU").Text.ToDecimal, 6) + DrInvOCDiferencias("CveMoneda") = dr2("CveMoneda").ToString.ToEntero + DrInvOCDiferencias("FolioOC") = dr2("FolioOC").ToString + DrInvOCDiferencias("CveProveedor") = dr2("CveProveedorOC").ToString.ToEntero + DrInvOCDiferencias("PS") = dr2("PS").ToString + DrInvOCDiferencias("FolioAlmacen") = dr2("FolioAlmacen").ToString + + If DdlOCVinculaInv.SelectedValue.ToEntero.Contiene(205) Then + DrInvOCDiferencias("TipoCambioAjuste") = 0 + DrInvOCDiferencias("CveAlmacen") = 0 + DrInvOCDiferencias("CveMovimiento") = 0 + DrInvOCDiferencias("ConceptoSalida") = 0 + DtInvOCDiferencias.Rows.Add(DrInvOCDiferencias) + Else + If ObjInventarios.GetMovimientosOC(dr2("CveOrdenCompra").ToString.ToEntero, UsuarioActual.CveEmpresa) Then + DtInvOC = ObjInventarios.DtResultados.FiltraParametros($"CvePS > 0 AND CveOrdenCompraDetalle = {dr2("CveOrdenCompraDetalle").ToString.ToEntero}").Copy + End If + Dim drInv As DataRow = DtInvOC.FiltroPrimero("") If drInv IsNot Nothing Then 'sino existe no hay problema, porque puede ser le producto un servicio DrInvOCDiferencias("TipoCambioAjuste") = drInv("TipoCambioAjuste").ToString.ToDecimal DrInvOCDiferencias("Diferencia") = ((gvr.FCTextBox("TxtPU").Text.ToDecimal * drInv("TipoCambioAjuste").ToString.ToDecimal) - drInv("PU").ToString.ToDecimal) * gvr.FCTextBox("TxtCantidad").Text.ToDecimal 'diferencia * drInv("TipoCambioAjuste").ToString.ToDecimal ' @@ -19036,118 +19174,118 @@ Partial Class Compras_Compras End If End If - End If - Next - - If DdlOCVinculaInv.SelectedValue.ToEntero.Contiene(205) Then - If DtInvOCDiferencias.Rows.Count > 0 Then - For Each DrDiferencias As DataRow In DtInvOCDiferencias.Rows - Dim CveOrdenCompra As Integer = DrDiferencias("CveOrdenCompra").ToString.ToEntero - Dim CveOCDetalle As Integer = DrDiferencias("CveOrdenCompraDetalle").ToString.ToEntero - Dim PUCompra As Decimal = DrDiferencias("PUCompra").ToString.ToDecimal - Dim DiferenciaInvOC As Decimal = DrDiferencias("Diferencia").ToString.ToDecimal - If DiferenciaInvOC.RoundSQL() <> 0 Then - If Not OC.UpdateOrdenCompraDetalleAjuste(CveOrdenCompra, CveOCDetalle, PUCompra) Then - Retorno = False - Exit For - End If - End If - Next - End If - Else - 'PREPOLIZA DE AJUSTE ALMACEN POR ADELANTADO - If DtInvOCDiferencias.Rows.Count > 0 Then - - 'VARIABLES - Dim CveOrdenCompra = -1 - Dim DiferenciaInvOC = 0.0D - Dim CveMovimientoAlmacen = -1 - Dim CveOCDetalle = -1 - Dim CveAlmacen = -1 - Dim IdCtaContableAlmacen As Integer = -1 - Dim CveCuentaAlmacen As Integer = -1 - Dim IdCtaContableRecepcionOC = -1 - Dim IdCtaContableRecepcionOCME = -1 - Dim IdCtaContableRecepcionOCComplementaria = -1 - Dim IdCtaContableRecepcionOCER = -1 - Dim IdCtaContableRecepcionOCERME = -1 - Dim IdCtaContableRecepcionOCERComplementaria = -1 - Dim Fecha As Date = Now - Dim CveProveedorInvOC As Integer = -1 - Dim ProveedorNombre As String = "" - Dim SerieFolio As String = "" - Dim CvePrePoliza As Integer = -1 - Dim ConceptoSalida = -1 - Dim TCInvOC = 0.0D - Dim ImporteME = 0.0D - Dim ImporteMEComp = 0.0D - Dim SumatoriaMN = 0.0D - Dim SumatoriaME = 0.0D - Dim SumatoriaMEComp = 0.0D - Dim PUCompra = 0.0D - Dim CveMoneda As Integer = 1 - Dim PS As String = "" - - If ObjConta.GetRetCuenta(176, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableRecepcionOC = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero - End If - - If ObjConta.GetRetCuenta(228, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableRecepcionOCME = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero - End If - - If ObjConta.GetRetCuenta(229, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableRecepcionOCComplementaria = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero - End If - - If ObjConta.GetRetCuenta(177, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableRecepcionOCER = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero - End If - - If ObjConta.GetRetCuenta(232, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableRecepcionOCERME = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero - End If - - If ObjConta.GetRetCuenta(233, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then - IdCtaContableRecepcionOCERComplementaria = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero - End If - - 'AJUSTES EN PREPOLIZA - SALIDA CONTABLE (CON SALIDA DE VENTA O SIN SALIDA) - For Each DrDiferencias As DataRow In DtInvOCDiferencias.FiltraParametros("ConceptoSalida IN (0,1)").Rows - CveOrdenCompra = DrDiferencias("CveOrdenCompra").ToString.ToEntero - CveOCDetalle = DrDiferencias("CveOrdenCompraDetalle").ToString.ToEntero - CveMoneda = DrDiferencias("CveMoneda").ToString.ToEntero - DiferenciaInvOC = DrDiferencias("Diferencia").ToString.ToDecimal.RoundSQL() - PUCompra = DrDiferencias("PUCompra").ToString.ToDecimal - PS = DrDiferencias("PS").ToString - - Fecha = Now - SerieFolio = $"OC: {DrDiferencias("FolioOC").ToString}" - CveProveedor = DrDiferencias("CveProveedor").ToString.ToEntero - ProveedorNombre = GlobalDTCompProveedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("RazonSocial", $"CveProveedor = {CveProveedor}").ToString - Dim ConceptoPartida As String = String.Format("{0} OC: {1} Inv: {2}", ProveedorNombre, DrDiferencias("FolioOC"), DrDiferencias("FolioAlmacen")) - - ConceptoSalida = DrDiferencias("ConceptoSalida").ToString.ToEntero - CveAlmacen = DrDiferencias("CveAlmacen").ToString.ToEntero - CveMovimientoAlmacen = DrDiferencias("CveMovimiento").ToString.ToEntero - TCInvOC = DrDiferencias("TipoCambioAjuste").ToString.ToDecimal - - IdCtaContableAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen = {DrDiferencias("CveAlmacen").ToString.ToEntero}").ToEntero - CveCuentaAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContableSIG", $"CveAlmacen = {DrDiferencias("CveAlmacen").ToString.ToEntero}").ToEntero - + End If + Next + + If DdlOCVinculaInv.SelectedValue.ToEntero.Contiene(205) Then + If DtInvOCDiferencias.Rows.Count > 0 Then + For Each DrDiferencias As DataRow In DtInvOCDiferencias.Rows + Dim CveOrdenCompra As Integer = DrDiferencias("CveOrdenCompra").ToString.ToEntero + Dim CveOCDetalle As Integer = DrDiferencias("CveOrdenCompraDetalle").ToString.ToEntero + Dim PUCompra As Decimal = DrDiferencias("PUCompra").ToString.ToDecimal + Dim DiferenciaInvOC As Decimal = DrDiferencias("Diferencia").ToString.ToDecimal + If DiferenciaInvOC.RoundSQL() <> 0 Then + If Not OC.UpdateOrdenCompraDetalleAjuste(CveOrdenCompra, CveOCDetalle, PUCompra) Then + Retorno = False + Exit For + End If + End If + Next + End If + Else + 'PREPOLIZA DE AJUSTE ALMACEN POR ADELANTADO + If DtInvOCDiferencias.Rows.Count > 0 Then + + 'VARIABLES + Dim CveOrdenCompra = -1 + Dim DiferenciaInvOC = 0.0D + Dim CveMovimientoAlmacen = -1 + Dim CveOCDetalle = -1 + Dim CveAlmacen = -1 + Dim IdCtaContableAlmacen As Integer = -1 + Dim CveCuentaAlmacen As Integer = -1 + Dim IdCtaContableRecepcionOC = -1 + Dim IdCtaContableRecepcionOCME = -1 + Dim IdCtaContableRecepcionOCComplementaria = -1 + Dim IdCtaContableRecepcionOCER = -1 + Dim IdCtaContableRecepcionOCERME = -1 + Dim IdCtaContableRecepcionOCERComplementaria = -1 + Dim Fecha As Date = Now + Dim CveProveedorInvOC As Integer = -1 + Dim ProveedorNombre As String = "" + Dim SerieFolio As String = "" + Dim CvePrePoliza As Integer = -1 + Dim ConceptoSalida = -1 + Dim TCInvOC = 0.0D + Dim ImporteME = 0.0D + Dim ImporteMEComp = 0.0D + Dim SumatoriaMN = 0.0D + Dim SumatoriaME = 0.0D + Dim SumatoriaMEComp = 0.0D + Dim PUCompra = 0.0D + Dim CveMoneda As Integer = 1 + Dim PS As String = "" + + If ObjConta.GetRetCuenta(176, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableRecepcionOC = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero + End If + + If ObjConta.GetRetCuenta(228, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableRecepcionOCME = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero + End If + + If ObjConta.GetRetCuenta(229, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableRecepcionOCComplementaria = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero + End If + + If ObjConta.GetRetCuenta(177, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableRecepcionOCER = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero + End If + + If ObjConta.GetRetCuenta(232, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableRecepcionOCERME = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero + End If + + If ObjConta.GetRetCuenta(233, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then + IdCtaContableRecepcionOCERComplementaria = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero + End If + + 'AJUSTES EN PREPOLIZA - SALIDA CONTABLE (CON SALIDA DE VENTA O SIN SALIDA) + For Each DrDiferencias As DataRow In DtInvOCDiferencias.FiltraParametros("ConceptoSalida IN (0,1)").Rows + CveOrdenCompra = DrDiferencias("CveOrdenCompra").ToString.ToEntero + CveOCDetalle = DrDiferencias("CveOrdenCompraDetalle").ToString.ToEntero + CveMoneda = DrDiferencias("CveMoneda").ToString.ToEntero + DiferenciaInvOC = DrDiferencias("Diferencia").ToString.ToDecimal.RoundSQL() + PUCompra = DrDiferencias("PUCompra").ToString.ToDecimal + PS = DrDiferencias("PS").ToString + + Fecha = Now + SerieFolio = $"OC: {DrDiferencias("FolioOC").ToString}" + CveProveedor = DrDiferencias("CveProveedor").ToString.ToEntero + ProveedorNombre = GlobalDTCompProveedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("RazonSocial", $"CveProveedor = {CveProveedor}").ToString + Dim ConceptoPartida As String = String.Format("{0} OC: {1} Inv: {2}", ProveedorNombre, DrDiferencias("FolioOC"), DrDiferencias("FolioAlmacen")) + + ConceptoSalida = DrDiferencias("ConceptoSalida").ToString.ToEntero + CveAlmacen = DrDiferencias("CveAlmacen").ToString.ToEntero + CveMovimientoAlmacen = DrDiferencias("CveMovimiento").ToString.ToEntero + TCInvOC = DrDiferencias("TipoCambioAjuste").ToString.ToDecimal + + IdCtaContableAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen = {DrDiferencias("CveAlmacen").ToString.ToEntero}").ToEntero + CveCuentaAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContableSIG", $"CveAlmacen = {DrDiferencias("CveAlmacen").ToString.ToEntero}").ToEntero + Dim CveClasificacionCostoOC = TmpDT.FiltroPrimeroValor("CveClasificacion", "ISNULL(TipoAF, 0) <> 2 And ISNULL(CveAlmacen, 0) = 0 And ISNULL(AplicaCostoIndirecto, 0) <> 1 And ISNULL(CveTipoPS, 0) = 2").ToEntero Dim IdCtaContable69 As Integer = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {CveClasificacionCostoOC}").ToString.ToEntero '' CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", $"CveClasificacion = {CveClasificacionCostoOC}").ToString.ToEntero - If DiferenciaInvOC.RoundSQL() <> 0 Then - CvePrePoliza = ObjConta.AddPrePolizas("Compras/OC-(OCAlmacen)", 74, DiferenciaInvOC, DiferenciaInvOC, 1, Fecha, ConceptoPartida, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CvePrePoliza > 0 Then - - If CveMoneda = 2 And UsuarioActual.CveEmpresa.Contiene(119) Then - ImporteME = (DiferenciaInvOC / TCInvOC).RoundSQL() - ImporteMEComp = ((ImporteME * TCInvOC) - ImporteME).RoundSQL() - + If DiferenciaInvOC.RoundSQL() <> 0 Then + CvePrePoliza = ObjConta.AddPrePolizas("Compras/OC-(OCAlmacen)", 74, DiferenciaInvOC, DiferenciaInvOC, 1, Fecha, ConceptoPartida, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CvePrePoliza > 0 Then + + If CveMoneda = 2 And UsuarioActual.CveEmpresa.Contiene(119) Then + ImporteME = (DiferenciaInvOC / TCInvOC).RoundSQL() + ImporteMEComp = ((ImporteME * TCInvOC) - ImporteME).RoundSQL() + Dim DifImporte As Decimal = DiferenciaInvOC - (ImporteME + ImporteMEComp) @@ -19172,234 +19310,234 @@ Partial Class Compras_Compras End If Else '2018.11.24 se cambia concepto 177, de cargo a abono negativo., petición MALL - If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, -DiferenciaInvOC, SerieFolio, If(ConceptoSalida = 0, 177, 177), ConceptoPartida, Fecha, If(ConceptoSalida = 0, IdCtaContableAlmacen, IdCtaContableRecepcionOCER), -1, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimientoAlmacen, CveOC:=CveOrdenCompra, ImporteMX:=-DiferenciaInvOC, CveCuenta:=CveCuentaAlmacen, CveOCDetalle:=CveOCDetalle) Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, DiferenciaInvOC, SerieFolio, 176, ConceptoPartida, Fecha, IdCtaContableRecepcionOC, -1, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimientoAlmacen, CveOC:=CveOrdenCompra, ImporteMX:=DiferenciaInvOC, CveOCDetalle:=CveOCDetalle) Then - Retorno = False - Exit For - End If - Else - Retorno = False - Exit For - End If - End If - If Not OC.UpdateOrdenCompraDetalleAjuste(CveOrdenCompra, CveOCDetalle, PUCompra) Then - Retorno = False - Exit For - End If - - If Retorno Then - - If Not OCBitacora.AddEventoBitacora(String.Format("Se registró una póliza de ajuste por cambio de precio en producto: {0}", PS), "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveOC:=CveOrdenCompra) Then - Retorno = False - End If - End If - - If UsuarioActual.Empresa.Funcionalidad(200) = "1" AndAlso ObjAC IsNot Nothing Then - If Not ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjAC) Then - Retorno = False - End If - End If - End If - End If - Next - - - End If - End If - - - Return Retorno + If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, -DiferenciaInvOC, SerieFolio, If(ConceptoSalida = 0, 177, 177), ConceptoPartida, Fecha, If(ConceptoSalida = 0, IdCtaContableAlmacen, IdCtaContableRecepcionOCER), -1, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimientoAlmacen, CveOC:=CveOrdenCompra, ImporteMX:=-DiferenciaInvOC, CveCuenta:=CveCuentaAlmacen, CveOCDetalle:=CveOCDetalle) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, DiferenciaInvOC, SerieFolio, 176, ConceptoPartida, Fecha, IdCtaContableRecepcionOC, -1, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimientoAlmacen, CveOC:=CveOrdenCompra, ImporteMX:=DiferenciaInvOC, CveOCDetalle:=CveOCDetalle) Then + Retorno = False + Exit For + End If + Else + Retorno = False + Exit For + End If + End If + If Not OC.UpdateOrdenCompraDetalleAjuste(CveOrdenCompra, CveOCDetalle, PUCompra) Then + Retorno = False + Exit For + End If + + If Retorno Then + + If Not OCBitacora.AddEventoBitacora(String.Format("Se registró una póliza de ajuste por cambio de precio en producto: {0}", PS), "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveOC:=CveOrdenCompra) Then + Retorno = False + End If + End If + + If UsuarioActual.Empresa.Funcionalidad(200) = "1" AndAlso ObjAC IsNot Nothing Then + If Not ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjAC) Then + Retorno = False + End If + End If + End If + End If + Next + + + End If + End If + + + Return Retorno End Function -#Region "A G R E G A R - P R O D U C T O S S E R V I C I O S" - Private Sub CargaDatosAgregarPS() - DdlClasificacionPS.Items.Clear() - If UsuarioActual.Empresa.UsaAC Then - DdlClasificacionPS.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, UsoClasificacion:=If(UsuarioActual.Empresa.UsaContabilidad, -1, -1)).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion") - Else - DdlClasificacionPS.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, UsoClasificacion:=If(UsuarioActual.Empresa.UsaContabilidad, -1, -1)).FiltraParametros("", Orderby:="Clasificacion") - End If - DdlClasificacionPS.DataBind() - DdlClasificacionPS.Items.Insert(0, New ListItem("Seleccione", "-1")) - - DdlUnidadMedida.Items.Clear() - DdlUnidadMedida.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) - DdlUnidadMedida.DataBind() - - End Sub - - Protected Sub BtnAgregarPSNuevo_Click(sender As Object, e As EventArgs) - - Dim PS As New Modelos.MProductoServicio() - PS.Codigo = TxtCodigoPS.Text - PS.PS = TxtPS.Text - PS.CveUnidadMedida = DdlUnidadMedida.SelectedValue.ToEntero() - PS.CveClasificacion = DdlClasificacionPS.SelectedValue.ToEntero() - PS.CveTipoPS = DdlTipoPS.SelectedValue.ToEntero() - PS.AplicaParaVenta = True - PS.CveUsuario = UsuarioActual.CveUsuario - PS.CveEmpresa = UsuarioActual.CveEmpresa - - Dim ObjPS As New ClsProductosServicios - If ObjPS.AddPSSimplificado(PS) > 0 Then - Alert("El P/S fue agregado correctamente.") - GeneraGlobalDT(Nothing) - End If - ObjPS.Dispose() - - TxtPS.Text = "" - TxtCodigoPS.Text = "" - DdlUnidadMedida.SelectedValueExist(-1) - DdlClasificacionPS.SelectedValueExist(-1) - DdlTipoPS.SelectedValueExist(-1) - - UpAgregarPS.Update() - +#Region "A G R E G A R - P R O D U C T O S S E R V I C I O S" + Private Sub CargaDatosAgregarPS() + DdlClasificacionPS.Items.Clear() + If UsuarioActual.Empresa.UsaAC Then + DdlClasificacionPS.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, UsoClasificacion:=If(UsuarioActual.Empresa.UsaContabilidad, -1, -1)).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion") + Else + DdlClasificacionPS.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, UsoClasificacion:=If(UsuarioActual.Empresa.UsaContabilidad, -1, -1)).FiltraParametros("", Orderby:="Clasificacion") + End If + DdlClasificacionPS.DataBind() + DdlClasificacionPS.Items.Insert(0, New ListItem("Seleccione", "-1")) + + DdlUnidadMedida.Items.Clear() + DdlUnidadMedida.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) + DdlUnidadMedida.DataBind() + + End Sub + + Protected Sub BtnAgregarPSNuevo_Click(sender As Object, e As EventArgs) + + Dim PS As New Modelos.MProductoServicio() + PS.Codigo = TxtCodigoPS.Text + PS.PS = TxtPS.Text + PS.CveUnidadMedida = DdlUnidadMedida.SelectedValue.ToEntero() + PS.CveClasificacion = DdlClasificacionPS.SelectedValue.ToEntero() + PS.CveTipoPS = DdlTipoPS.SelectedValue.ToEntero() + PS.AplicaParaVenta = True + PS.CveUsuario = UsuarioActual.CveUsuario + PS.CveEmpresa = UsuarioActual.CveEmpresa + + Dim ObjPS As New ClsProductosServicios + If ObjPS.AddPSSimplificado(PS) > 0 Then + Alert("El P/S fue agregado correctamente.") + GeneraGlobalDT(Nothing) + End If + ObjPS.Dispose() + + TxtPS.Text = "" + TxtCodigoPS.Text = "" + DdlUnidadMedida.SelectedValueExist(-1) + DdlClasificacionPS.SelectedValueExist(-1) + DdlTipoPS.SelectedValueExist(-1) + + UpAgregarPS.Update() + RegistraScript("$('#DivAgregarPS').modal('hide');") End Sub -#End Region +#End Region -#Region "TIPO DE COMPRA" +#Region "TIPO DE COMPRA" + + Protected Sub DdlTipoCompra_SelectedIndexChanged(sender As Object, e As EventArgs) - Protected Sub DdlTipoCompra_SelectedIndexChanged(sender As Object, e As EventArgs) - End Sub -#End Region +#End Region - Protected Sub BtnFacturaNC_Click(sender As Object, e As EventArgs) - If ChkNCInvNC.Checked Then - CargaNCINV() - Else - RegistraScript("$('#FacturaNC').modal('hide');", "FacturaNC") - End If + Protected Sub BtnFacturaNC_Click(sender As Object, e As EventArgs) + If ChkNCInvNC.Checked Then + CargaNCINV() + Else + RegistraScript("$('#FacturaNC').modal('hide');", "FacturaNC") + End If End Sub -#Region "ES NO DEDUCIBLE" - Protected Sub ChkEsNoDeducible_CheckedChanged1(sender As Object, e As EventArgs) - If ChkEsNoDeducible.Checked Then - EsNoDeducible = True - dvNoDeducible.Visible = True - GvPS.Columns(10).Visible = True - UpEsNoDeduciblePS.Visible = True - Else - EsNoDeducible = False - dvNoDeducible.Visible = False - GvPS.Columns(10).Visible = False - UpEsNoDeduciblePS.Visible = False - End If - 'DivEsNoDeducible.Visible = False - 'For Each Dr As DataRow In TmpDT.Rows - ' Dim Total As Double = Dr("IVA").ToString.ToDouble - (Dr("RetIVA").ToString.ToDouble + Dr("RetISR").ToString.ToDouble) + Dr("IEPSPS").ToString.ToDouble + Dr("IEPSPSIVA").ToString.ToDouble - ' Dr("Total") = Dr("Total").ToString.ToDouble + Total - ' Dr("PU") = Dr("Total").ToString.ToDouble / Dr("Cantidad").ToString.ToDouble - ' Dr("IVA") = 0 - ' Dr("IVAPorcentaje") = 0 - ' Dr("RetIVA") = 0 - ' Dr("RetIVAPorcentaje") = 0 - ' Dr("RetISR") = 0 - ' Dr("RetISRPorcentaje") = 0 - ' Dr("IEPSPS") = 0 - ' Dr("IEPSPSPorcentaje") = 0 - ' Dr("IEPSPSIVA") = 0 - ' Dr("IEPSPSIVAPorcentaje") = 0 - 'Next - 'TmpDT.AcceptChanges() - AddPS2(EsNoDeducible:=EsNoDeducible) - UpPS.Update() +#Region "ES NO DEDUCIBLE" + Protected Sub ChkEsNoDeducible_CheckedChanged1(sender As Object, e As EventArgs) + If ChkEsNoDeducible.Checked Then + EsNoDeducible = True + dvNoDeducible.Visible = True + GvPS.Columns(10).Visible = True + UpEsNoDeduciblePS.Visible = True + Else + EsNoDeducible = False + dvNoDeducible.Visible = False + GvPS.Columns(10).Visible = False + UpEsNoDeduciblePS.Visible = False + End If + 'DivEsNoDeducible.Visible = False + 'For Each Dr As DataRow In TmpDT.Rows + ' Dim Total As Double = Dr("IVA").ToString.ToDouble - (Dr("RetIVA").ToString.ToDouble + Dr("RetISR").ToString.ToDouble) + Dr("IEPSPS").ToString.ToDouble + Dr("IEPSPSIVA").ToString.ToDouble + ' Dr("Total") = Dr("Total").ToString.ToDouble + Total + ' Dr("PU") = Dr("Total").ToString.ToDouble / Dr("Cantidad").ToString.ToDouble + ' Dr("IVA") = 0 + ' Dr("IVAPorcentaje") = 0 + ' Dr("RetIVA") = 0 + ' Dr("RetIVAPorcentaje") = 0 + ' Dr("RetISR") = 0 + ' Dr("RetISRPorcentaje") = 0 + ' Dr("IEPSPS") = 0 + ' Dr("IEPSPSPorcentaje") = 0 + ' Dr("IEPSPSIVA") = 0 + ' Dr("IEPSPSIVAPorcentaje") = 0 + 'Next + 'TmpDT.AcceptChanges() + AddPS2(EsNoDeducible:=EsNoDeducible) + UpPS.Update() End Sub -#End Region +#End Region - Public Sub LnkDesVincularComplemento_Click(sender As Object, e As EventArgs) - - Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) - Dim CveFacturaComplemento As Integer = GvRow.DataKey("CveFactura").ToEntero - - Dim ObjCompra As New ClsCompras - - If ObjCompra.RemoveComplementoPagoDesVincular(CveFacturaComplemento, UsuarioActual.CveEmpresa) Then - RegistraScript("$('#ModalComplementoPagos').modal('hide');") - Alert("Complemento des vinculado correctamente.") - End If - ObjCompra.Dispose() - - End Sub - - - Protected Sub LnkCompleplementos_Click(sender As Object, e As EventArgs) - 'ModalComplementoPagos - - CargaComplementosPago() - RegistraScript("$('#ModalComplementoPagos').modal('show');") - - End Sub - Protected Sub ChkEsNoDeduciblePS_CheckedChanged(sender As Object, e As EventArgs) - - Dim Chk As CheckBox = CType(sender, CheckBox) - Dim gvr As GridViewRow = CType(Chk.BindingContainer, GridViewRow) - - For Each drt As DataRow In TmpDT.Select("Consec = " & gvr.RowIndex + 1) - drt("NoDeducible") = Chk.Checked - Next - - TmpDT.AcceptChanges() - Alert((TmpDT.Select("Consec = " & gvr.RowIndex + 1)(0))("NoDeducible").ToString()) - AddPS2(EsNoDeducible:=EsNoDeducible) - - End Sub - Protected Sub LnkUpdateFechaPago_Click(sender As Object, e As EventArgs) - Dim ObjComp As New ClsCompras - Dim FechaPagoAnterior As String = "" - - If ObjComp.GetCompras(CveCompra, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then - If ObjComp.DtResultados.Rows.Count > 0 Then - FechaPagoAnterior = ObjComp.DtResultados.Rows(0)("FechaVencimiento").ToString.ToDate.ToShortDateString - End If - End If - - If FechaPagoAnterior = TxtFechaPago.Text Then - Alert("La fecha de pago seleccionada es igual que la anterior.", TipoMensaje.MsgAdvertencia) - ObjComp.Dispose() - Exit Sub - End If - - If ObjComp.UpdateFechaVencimientoCompra(CveCompra, TxtFechaPago.Text.ToDate, UsuarioActual.CveEmpresa) Then - Alert("Fecha de pago actualizada correctamente.") - End If - - ObjComp.Dispose() + Public Sub LnkDesVincularComplemento_Click(sender As Object, e As EventArgs) + + Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) + Dim CveFacturaComplemento As Integer = GvRow.DataKey("CveFactura").ToEntero + + Dim ObjCompra As New ClsCompras + + If ObjCompra.RemoveComplementoPagoDesVincular(CveFacturaComplemento, UsuarioActual.CveEmpresa) Then + RegistraScript("$('#ModalComplementoPagos').modal('hide');") + Alert("Complemento des vinculado correctamente.") + End If + ObjCompra.Dispose() + + End Sub + + + Protected Sub LnkCompleplementos_Click(sender As Object, e As EventArgs) + 'ModalComplementoPagos + + CargaComplementosPago() + RegistraScript("$('#ModalComplementoPagos').modal('show');") + + End Sub + Protected Sub ChkEsNoDeduciblePS_CheckedChanged(sender As Object, e As EventArgs) + + Dim Chk As CheckBox = CType(sender, CheckBox) + Dim gvr As GridViewRow = CType(Chk.BindingContainer, GridViewRow) + + For Each drt As DataRow In TmpDT.Select("Consec = " & gvr.RowIndex + 1) + drt("NoDeducible") = Chk.Checked + Next + + TmpDT.AcceptChanges() + Alert((TmpDT.Select("Consec = " & gvr.RowIndex + 1)(0))("NoDeducible").ToString()) + AddPS2(EsNoDeducible:=EsNoDeducible) + + End Sub + Protected Sub LnkUpdateFechaPago_Click(sender As Object, e As EventArgs) + Dim ObjComp As New ClsCompras + Dim FechaPagoAnterior As String = "" + + If ObjComp.GetCompras(CveCompra, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then + If ObjComp.DtResultados.Rows.Count > 0 Then + FechaPagoAnterior = ObjComp.DtResultados.Rows(0)("FechaVencimiento").ToString.ToDate.ToShortDateString + End If + End If + + If FechaPagoAnterior = TxtFechaPago.Text Then + Alert("La fecha de pago seleccionada es igual que la anterior.", TipoMensaje.MsgAdvertencia) + ObjComp.Dispose() + Exit Sub + End If + + If ObjComp.UpdateFechaVencimientoCompra(CveCompra, TxtFechaPago.Text.ToDate, UsuarioActual.CveEmpresa) Then + Alert("Fecha de pago actualizada correctamente.") + End If + + ObjComp.Dispose() End Sub Protected Sub btnpruebas_Click(sender As Object, e As EventArgs) - Dim GuardaNoDeducibles As Boolean = False - If ChkEsNoDeducible.Checked Then - For Each Row As DataRow In TmpDT.Rows - If Row("NoDeducible").ToString().ToUpper().Contiene("TRUE", "1") Then - GuardaNoDeducibles = True - End If - - Next - If GuardaNoDeducibles = False Then - Alert("Si la compra es No Deducible, mínimo se debe registrar un producto No Deducible", TipoMensaje.MsgAdvertencia) + Dim GuardaNoDeducibles As Boolean = False + If ChkEsNoDeducible.Checked Then + For Each Row As DataRow In TmpDT.Rows + If Row("NoDeducible").ToString().ToUpper().Contiene("TRUE", "1") Then + GuardaNoDeducibles = True + End If + + Next + If GuardaNoDeducibles = False Then + Alert("Si la compra es No Deducible, mínimo se debe registrar un producto No Deducible", TipoMensaje.MsgAdvertencia) Exit Sub - Else - Alert("todo bien!", TipoMensaje.MsgInformacion) - - End If + Else + Alert("todo bien!", TipoMensaje.MsgInformacion) + + End If End If End Sub #Region "PAGAR CON DIFERENTE MONEDA" Protected Sub ChkPagarConPesos_CheckedChanged(sender As Object, e As EventArgs) CargaAnticipos(CveProveedor) - UpAnticipos.Update() + UpAnticipos.Update() End Sub Protected Sub ChkPagarConDolares_CheckedChanged(sender As Object, e As EventArgs) CargaAnticipos(CveProveedor) - UpAnticipos.Update() + UpAnticipos.Update() End Sub #End Region diff --git a/Compras/ReembolsosComprobaciones.aspx b/Compras/ReembolsosComprobaciones.aspx index 391e282bf..15887b7b5 100644 --- a/Compras/ReembolsosComprobaciones.aspx +++ b/Compras/ReembolsosComprobaciones.aspx @@ -291,7 +291,7 @@ - + diff --git a/Compras/ReembolsosComprobaciones.aspx.vb b/Compras/ReembolsosComprobaciones.aspx.vb index b8638b6db..359041716 100644 --- a/Compras/ReembolsosComprobaciones.aspx.vb +++ b/Compras/ReembolsosComprobaciones.aspx.vb @@ -630,6 +630,18 @@ Partial Class Compras_ReembolsosComprobaciones ImportePagar = gvr.FCTextBox("TxtAbonar").Text.ToDecimal ImporteOriginal = gvr.FCTextBox("TxtAbonar").Text.ToDecimal + Dim CveConceptoContablePago As Integer = 17 + If gvr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoContablePago = 308 'cuando es acreedor + If CveMoneda <> 1 Then + Select Case CveConceptoContablePago + Case 17 + CveConceptoContablePago = 312 + Case 308 + CveConceptoContablePago = 309 + Case Else + End Select + End If + If SaldoCheque > 0 Then ImporteMovto = If(ImportePagar > SaldoCheque, SaldoCheque, ImportePagar) CvePrePolizaPago = CvePrePolizaIERegistrado @@ -670,7 +682,7 @@ Partial Class Compras_ReembolsosComprobaciones End If 'Pago Proveedores - If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaPago, False, ImporteMovto, Referencia, 17, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaProveedor, -1, CveIE:=CveIEPago, CvePersonal:=CvePersonal, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, ImporteMovto), ImporteMX:=ImporteMovto * tipoCambio, CveCuenta:=CveCuentaProveedor, CvePrePolizaOriginal:=CvePrePolizaPagoOriginal) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaPago, False, ImporteMovto, Referencia, CveConceptoContablePago, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaProveedor, -1, CveIE:=CveIEPago, CvePersonal:=CvePersonal, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, ImporteMovto), ImporteMX:=ImporteMovto * tipoCambio, CveCuenta:=CveCuentaProveedor, CvePrePolizaOriginal:=CvePrePolizaPagoOriginal) Then MsgError = "Detalle" End If @@ -935,7 +947,7 @@ Partial Class Compras_ReembolsosComprobaciones If UsuarioActual.Empresa.Funcionalidad(506) = "1" And CbPermitirExcedente.Checked = True And SaldoExcedente > 0 Then If DDlPermitirExcedente.SelectedValue = "1" Then - If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaPago, False, SaldoExcedente, Referencia, 17, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaProveedor, -1, CveIE:=CveIEPago, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, SaldoExcedente), ImporteMX:=(SaldoExcedente) * tipoCambio, CvePersonal:=CvePersonal, CveCuenta:=CveCuentaProveedor, CvePrePolizaOriginal:=CvePrePolizaPagoOriginal) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaPago, False, SaldoExcedente, Referencia, CveConceptoContablePago, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaProveedor, -1, CveIE:=CveIEPago, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, SaldoExcedente), ImporteMX:=(SaldoExcedente) * tipoCambio, CvePersonal:=CvePersonal, CveCuenta:=CveCuentaProveedor, CvePrePolizaOriginal:=CvePrePolizaPagoOriginal) Then MsgError = "Detalle Reembolso Personal" End If If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaPago, True, SaldoExcedente, Referencia, 132, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaOtrosProductos, -1, CveIE:=CveIEPago, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, SaldoExcedente), ImporteMX:=SaldoExcedente * tipoCambio, CvePersonal:=CvePersonal, CveCuenta:=CveCuentaOtrosProductos, CvePrePolizaOriginal:=CvePrePolizaPagoOriginal) Then @@ -943,7 +955,7 @@ Partial Class Compras_ReembolsosComprobaciones End If ElseIf DDlPermitirExcedente.SelectedValue = "2" Then - If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaPago, False, SaldoExcedente, Referencia, 17, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaProveedor, -1, CveIE:=CveIEPago, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, SaldoExcedente), ImporteMX:=SaldoExcedente * tipoCambio, CvePersonal:=CvePersonal, CveCuenta:=CveCuentaProveedor, CvePrePolizaOriginal:=CvePrePolizaPagoOriginal) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaPago, False, SaldoExcedente, Referencia, CveConceptoContablePago, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaProveedor, -1, CveIE:=CveIEPago, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, SaldoExcedente), ImporteMX:=SaldoExcedente * tipoCambio, CvePersonal:=CvePersonal, CveCuenta:=CveCuentaProveedor, CvePrePolizaOriginal:=CvePrePolizaPagoOriginal) Then MsgError = "Detalle Reembolso Personal Excedente" End If If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaPago, True, SaldoExcedente, Referencia, 29, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaPersonal, -1, CveIE:=CveIEPago, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, SaldoExcedente), ImporteMX:=SaldoExcedente * tipoCambio, CvePersonal:=CvePersonal, CveCuenta:=CveCuentaPersonal, CvePrePolizaOriginal:=CvePrePolizaPagoOriginal) Then @@ -990,7 +1002,7 @@ Partial Class Compras_ReembolsosComprobaciones If gvr.DataKey("Original").ToDecimal > 0 Then PorcentajePago = (ImporteMovto / gvr.DataKey("Original").ToDecimal).RoundSQL Else PorcentajePago = 1 - If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaExcedente, True, ImporteMovto, Referencia, 17, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaProveedor, -1, CveIE:=CveIEExcedente, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, ImporteMovto), ImporteMX:=(ImporteMovto * tipoCambio), CveCuenta:=CveCuentaProveedor) Then + If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaExcedente, True, ImporteMovto, Referencia, CveConceptoContablePago, ConceptoMovimiento, gvr.FCLiteral("LtlFecha").Text.ToDate, IdCtaProveedor, -1, CveIE:=CveIEExcedente, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteME:=If(tipoCambio = 1, 0, ImporteMovto), ImporteMX:=(ImporteMovto * tipoCambio), CveCuenta:=CveCuentaProveedor) Then MsgError = "Detalle" Exit For Else diff --git a/vwd.webinfo b/vwd.webinfo index 93df9a232..3f67b239f 100644 --- a/vwd.webinfo +++ b/vwd.webinfo @@ -26,6 +26,8 @@ + + From e77d1756067f435e21f3385fb1fc01b5aae3dc39 Mon Sep 17 00:00:00 2001 From: Rakcsle Supertramp Date: Fri, 13 Mar 2020 09:55:57 -0700 Subject: [PATCH 06/14] Pagos por grupos General --- App_Code/ClsBancos.vb | 7 +- App_Code/ClsPaginas.vb | 1 + Bancos/PagoElectronicoGrupos.aspx | 640 +++++ Bancos/PagoElectronicoGrupos.aspx.vb | 2777 ++++++++++++++++++ Bancos/ProveedoresAbonar.aspx.vb | 21 +- Compras/eFacturas.aspx | 2 +- Compras/eFacturas.aspx.vb | 28 +- Contabilidad/PopUpAuxiliar.aspx | 494 ++-- Contabilidad/Reportes/RepAnexoCatalogo.rdlc | 2815 +++++++++---------- Ventas/ClientesAbonar.aspx | 1544 +++++----- vwd.webinfo | 14 + 11 files changed, 5908 insertions(+), 2435 deletions(-) create mode 100644 Bancos/PagoElectronicoGrupos.aspx create mode 100644 Bancos/PagoElectronicoGrupos.aspx.vb diff --git a/App_Code/ClsBancos.vb b/App_Code/ClsBancos.vb index 4dbde281c..e7bde6bce 100644 --- a/App_Code/ClsBancos.vb +++ b/App_Code/ClsBancos.vb @@ -2839,11 +2839,11 @@ Public Class ClsBancos End Try Return Retorno - End Function + End Function #End Region - + #Region "B A N C O S - P A G O - E L E C T R O N I C O" - Public Function GetLayoutPagos(CveCuenta As Integer, CveBLE As Integer, Tipo As String) As Boolean + Public Function GetLayoutPagos(CveCuenta As Integer, CveBLE As Integer, Tipo As String, Optional PorGrupos As Boolean = False) As Boolean Dim Retorno As Boolean = False DataAdapter("PA_Banc_LayoutPagos") @@ -2852,6 +2852,7 @@ Public Class ClsBancos .Add("@CveCuenta", SqlDbType.Int).Value = CveCuenta .Add("@CveBLE", SqlDbType.Int).Value = CveBLE .Add("@Tipo", SqlDbType.VarChar).Value = Tipo + .Add("@PorGrupos", SqlDbType.Bit).Value = PorGrupos End With Try diff --git a/App_Code/ClsPaginas.vb b/App_Code/ClsPaginas.vb index 89892002b..56b0aa132 100644 --- a/App_Code/ClsPaginas.vb +++ b/App_Code/ClsPaginas.vb @@ -4690,6 +4690,7 @@ Public Class ClsPaginas PaginaDict.Add("/PV/PVRepCompras.aspx".ToUpper(), 272) PaginaDict.Add("/PV/PVRepVentasCompras.aspx".ToUpper(), 273) + PaginaDict.Add("/Bancos/PagoElectronicoGrupos.aspx".ToUpper(), -1) diff --git a/Bancos/PagoElectronicoGrupos.aspx b/Bancos/PagoElectronicoGrupos.aspx new file mode 100644 index 000000000..f1752353f --- /dev/null +++ b/Bancos/PagoElectronicoGrupos.aspx @@ -0,0 +1,640 @@ +<%@ Page Title="Bancos - Pago Electrónico" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PagoElectronicoGrupos.aspx.vb" Inherits="Bancos_PagoElectronicoGrupos" %> + +<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> + + + + + + + + Pago Electrónico + + + + + + + + + + + + + + + + +
+
+
+
    +
  • Cuenta: + +
  • +
  • Tipo: + + + + + + +
  • +
+
+
+ +
+
+ +
+
+
+
+ +
+ +
+ +
+ + +
+
+
+ + Generación de Archivos +
+
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+
+ + Alta Beneficiarios +
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + +
Altas: +
Interbancarias: +
Bancomer: +
+ +
+
+
+
+ +
+
+
+
+ + Pago Beneficiarios +
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + +
Movimientos: + +
Importe: $ + +
+ +
+
+
+
+ +
+ +
+
+
+ <%-- + + --%> +
+
+ +
+ +
+
+
+ + Cargar Archivos +
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + +
+ Seleccione el archivo TXT a cargar + +
+ + Seleccionar Archivo + +
+
+ +
+
+ Tipo de archivo a cargar: + + + +
+
+
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+
+ Layouts Pendientes +
+ + + + + + + + + + <%----%> + + + +    + + + <%----%> + + + + + +
+ +
+
+ Layouts Enviados +
+ + + + + + + + + + <%----%> + + + <%----%> + + + + + <%----%> + + + + + + +
+ +
+
+
+
+ +
+ +
+
+ + + + + <%-- + +
+
+
+
    +
  • Cuenta: + +
  • +
  • Estatus: + + + + + + +
  • +
  • Fecha.I.: + + + + + + + + +
  • +
  • Fecha.F.: + + + + + + + + +
  • +
+
+
+ +
+
+
+
+
--%> + + + + + + + + +
+
+
+ + "> + +
+
+
    +
  • Cuenta + +
  • +
  • Tipo + + + + + + +
  • +
  • Estatus + + + + + + +
  • +
  • F.I.   +
    + + + + + + + + + + +
    +
  • +
  • F.F    +
    + + + + + + + + + + +
    +
  • +
+
+ +
+
+ + <%--
+
+ + +
+
+
Cuenta:
+
+
+ +
Estatus:
+
+
+
Fecha I:
+
+
+
Fecha F:
+
+
+
+
+ +
+ +
--%> +
+
+
+ + <%-- + + + + + + + + + + + + + +
Cuenta:Estatus: Fecha.I.:  + +  Fecha.F.:  + +
+
+
--%> + +
+
+ + + + + + + <%----%> + + + + + + + + + + + + + + + + +
+
+ + + + + + + +
+
+
+
    +
  • Tipo: + + + + +
  • +
+
+
+ +
+
+
+
+
+
+ + + + + + + + +
+ +
+
+
+
+ + + + + + + <%----%> + <%----%> + + + + + + + + + + + <%----%> + <%-- + + + + --%> + <%----%> + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ + + + diff --git a/Bancos/PagoElectronicoGrupos.aspx.vb b/Bancos/PagoElectronicoGrupos.aspx.vb new file mode 100644 index 000000000..1bbca81d9 --- /dev/null +++ b/Bancos/PagoElectronicoGrupos.aspx.vb @@ -0,0 +1,2777 @@ +Option Explicit On +Option Strict On + +Imports System.Data +Imports Extensiones +Imports System.IO +Imports Ionic.Zip +Imports Microsoft.Reporting.WebForms + +Partial Class Bancos_PagoElectronicoGrupos + Inherits ClsPaginas + Private Shared missing As Object = System.Reflection.Missing.Value + +#Region "PROPIEDADES" + Private Property HeaderTexto As String + Get + Return ViewState("HeaderTexto").ToString + End Get + Set(value As String) + ViewState("HeaderTexto") = value + End Set + End Property + Private Property DetalleTexto As String + Get + Return ViewState("DetalleTexto").ToString + End Get + Set(value As String) + ViewState("DetalleTexto") = value + End Set + End Property + Private Property TrailerTexto As String + Get + Return ViewState("TrailerTexto").ToString + End Get + Set(value As String) + ViewState("TrailerTexto") = value + End Set + End Property + Private Property TextoCompleto As String + Get + Return ViewState("TextoCompleto").ToString + End Get + Set(value As String) + ViewState("TextoCompleto") = value + End Set + End Property + Private Property Vacio As String + Get + Return ViewState("Vacio").ToString + End Get + Set(value As String) + ViewState("Vacio") = value + End Set + End Property + Private Property NombreArchivo As String + Get + Return ViewState("NombreArchivo").ToString + End Get + Set(value As String) + ViewState("NombreArchivo") = value + End Set + End Property + Private Property DTPendientes As DataTable + Get + Return CType(ViewState("DTPendientes"), DataTable) + End Get + Set(value As DataTable) + ViewState("DTPendientes") = value + End Set + End Property + Private Property DTProveedores As DataTable + Get + Return CType(ViewState("DTProveedores"), DataTable) + End Get + Set(value As DataTable) + ViewState("DTProveedores") = value + End Set + End Property + Private Property DTFyE As DataTable + Get + Return CType(ViewState("DTFyE"), DataTable) + End Get + Set(value As DataTable) + ViewState("DTFyE") = value + End Set + End Property + Private Property DTReportes As DataTable + Get + Return CType(ViewState("DTReportes"), DataTable) + End Get + Set(value As DataTable) + ViewState("DTReportes") = value + End Set + End Property + Private Property DTPendienteActual As DataTable + Get + Return CType(ViewState("DTPendienteActual"), DataTable) + End Get + Set(value As DataTable) + ViewState("DTPendienteActual") = value + End Set + End Property + Private Property DTEnviadas As DataTable + Get + Return CType(ViewState("DTEnviadas"), DataTable) + End Get + Set(value As DataTable) + ViewState("DTEnviadas") = value + End Set + End Property + Private ReadOnly Property PadCeros As Char + Get + Return "0"c + End Get + End Property + Private Property TotalAcumulado As Double + Get + Return ViewState("TotalAcumulado").ToString.ToDouble + End Get + Set(value As Double) + ViewState("TotalAcumulado") = value + End Set + End Property + Private Property CveCuenta As Integer + Get + Return ViewState("CveCuenta").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("CveCuenta") = value + End Set + End Property + Private Property DtPago As DataTable + Get + Return CType(ViewState("DtPago"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtPago") = value + End Set + End Property + Private Property DtAlta As DataTable + Get + Return CType(ViewState("DtAlta"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtAlta") = value + End Set + End Property + Private Property CorreoNotificacionesEmpresa As String + Get + Return ViewState("CorreoNotificacionesEmpresa").ToString + End Get + Set(value As String) + ViewState("CorreoNotificacionesEmpresa") = value + End Set + End Property + Private Property TipoMasiva As Integer + Get + Return ViewState("TipoMasiva").ToString.ToEntero + End Get + Set(value As Integer) + ViewState("TipoMasiva") = value + End Set + End Property +#End Region + + Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load + + If Not IsPostBack Then + + ViewState("NombreArchivo") = "" + ViewState("HeaderTexto") = "" + ViewState("DetalleTexto") = "" + ViewState("TrailerTexto") = "" + ViewState("Vacio") = "" + ViewState("TotalAcumulado") = 0 + CveCuenta = -1 + TipoMasiva = 1 + + txtFechaI.Text = Date.Now.ToShortDateString + txtFechaF.Text = Date.Now.ToShortDateString + + CargaCuentas() + CargaProveedores() + InicializaDatosGenerales() + + + End If + + + End Sub + + +#Region " C A R G A - D A T O S " + Private Sub CargaCuentas() + DdlCuenta.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros("UsaLayoutGrupos = 1") + DdlCuenta.DataBind() + UpFiltros.Update() + + DdlCuentaReportes.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltraParametros("UsaLayoutGrupos = 1") + DdlCuentaReportes.DataBind() + UpFiltrosReporte.Update() + End Sub + Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) + CveCuenta = DdlCuenta.SelectedValue.ToEntero + CargaDatos() + End Sub + Private Sub CargaDatos() + + 'Carga datos en DT´s + Dim ObjBancos As New ClsBancos + If ObjBancos.GetLayoutPagos(CveCuenta, -1, DdlTipoGeneracion.SelectedValue, PorGrupos:=True) Then + DTPendientes = ObjBancos.DtResultados + Else + DTPendientes = Nothing + End If + + If ObjBancos.GetLayoutPagosEnviados(CveCuenta, 1, DdlTipoGeneracion.SelectedValue, "-1", "-1") Then + DTEnviadas = ObjBancos.DtResultados + Else + DTEnviadas = Nothing + End If + ObjBancos.Dispose() + + + 'Carga GvPendientes + If DTPendientes IsNot Nothing AndAlso DTPendientes.Rows.Count > 0 Then + GvPendientes.DataSource = DTPendientes + End If + GvPendientes.DataBind() + + 'Carga GvEnviadas + If DTEnviadas IsNot Nothing AndAlso DTEnviadas.Rows.Count > 0 Then + GvEnviadas.DataSource = DTEnviadas + End If + GvEnviadas.DataBind() + + UpGVDatos.Update() + + If DTPendientes IsNot Nothing AndAlso DTPendientes.Rows.Count > 0 Then + CargaDatosInformativos() + End If + + End Sub + Private Sub CargaDatosInformativos() + Dim Altas = 0 + Dim Interbancarias = 0 + Dim Bancomer = 0 + + Dim Movimientos = 0 + Dim Importe = 0.0 + + For Each dr As DataRow In DTPendientes.Rows + + If dr("EstatusCtaDeposito").ToString <> "True" Then + Continue For + End If + + If dr("CveCuentaDeposito").ToString <> "" And dr("EstatusPagoElectronicoGrupos").ToString <> "True" And dr("AltaCuenta").ToString = "1" Then + Altas += 1 + If dr("BancoNombre").ToString.ToUpper.Contains("BANCOMER") OrElse dr("BancoNombre").ToString.ToUpper.Contains("BBVA") Then + Bancomer += 1 + Else + Interbancarias += 1 + End If + + ElseIf dr("CveCuentaDeposito").ToString.ToEntero > 0 Then + Movimientos += 1 + Importe += dr("Abonado").ToString.ToDouble + End If + Next + + LbNumeroAltas.Text = Altas.ToString + LbNumeroInterbancarias.Text = Interbancarias.ToString + LbNumeroBancomer.Text = Bancomer.ToString + + LbNumeroMovimientos.Text = Movimientos.ToString + LbImporteMovimientos.Text = Importe.ToString.FormatoNumero + + UpComandosGeneracion.Update() + End Sub +#End Region + +#Region " DATOS GENERALES LAYOUT " + Private Sub InicializaDatosGenerales() + + If UsuarioActual.CveEmpresa = 66 Then + CorreoNotificacionesEmpresa = "pagos@gluyasconstrucciones.com" + ElseIf UsuarioActual.CveEmpresa = 13 Then + CorreoNotificacionesEmpresa = "signotificaciones@adssistemas.mx" + Else + CorreoNotificacionesEmpresa = "signotificaciones@adssistemas.mx" + End If + + End Sub +#End Region + + +#Region " GENERA Y DESCARGA ARCHIVO (TXT) " + Protected Sub CrearTXT() + Dim path As String = Server.MapPath(String.Format("~/Empresas/{0}/Layout/{1}.txt", UsuarioActual.CveEmpresa, NombreArchivo)) + ' Create or overwrite the file. + Dim fs As FileStream = File.Create(path) + + ' Add text to the file. + Dim info As Byte() = New UTF8Encoding(True).GetBytes(TextoCompleto) + fs.Write(info, 0, info.Length) + fs.Close() + End Sub + Private Sub DescargarArchivo() + With HttpContext.Current.Response + .Clear() + .Buffer = True + .ContentType = "textplain" + .AddHeader("Content-Disposition", String.Format("attachment;filename={0}{1}.txt", NombreArchivo, Date.Now.ToString("ddMMyyyy"))) + .Charset = "UTF-8" + .ContentEncoding = Encoding.Default + .Write(TextoCompleto) + .Flush() + .End() + End With + End Sub + Private Sub DescargaZip() + Dim path As String = Server.MapPath(String.Format("~/Empresas/{0}/Layout/", UsuarioActual.CveEmpresa)) + Response.Clear() + Dim ElZip As ZipFile = New ZipFile() + Using ElZip + ElZip.AddDirectory(path) + ElZip.Save(Response.OutputStream) + End Using + Response.AddHeader("Content-Disposition", "attachment; filename=LayoutPagos.zip") + Response.ContentType = "application/zip" + Response.End() + End Sub + Private Function CreaArchivo(Tipo As Integer) As Boolean + + + DirectoryExistsCreate(String.Format("{0}Layout", UsuarioActual.Empresa.Ruta)) + + NombreArchivo = String.Format("{2}{1}{0}.txt", UsuarioActual.CveUsuario, Date.Now.ToString("yyyyMMdd-HH-mm"), If(Tipo = 1, "LAYOUTPAGO", "LAYOUTALTA")) + + Dim path As String = String.Format("{0}Layout\{1}", UsuarioActual.Empresa.Ruta, NombreArchivo) + Dim fs As FileStream = File.Create(path) + + ' Add text to the file. + Dim info As Byte() = New UTF8Encoding(True).GetBytes(TextoCompleto) + fs.Write(info, 0, info.Length) + fs.Close() + + Return True + End Function + Private Function GuardaTXT() As Boolean + Dim Retorno = True + Try + Dim Ruta = "" + Dim FileName As String = Path.GetFileName(FUTxt.PostedFile.FileName) + NombreArchivo = FileName + Dim Extension As String = Path.GetExtension(FUTxt.PostedFile.FileName) + Dim FolderPath As String = String.Format("{0}Empresas\", Request.ApplicationPath) + Dim FilePath As String = Server.MapPath(FolderPath + FileName) + FUTxt.SaveAs(FilePath) + NombreArchivo = FilePath + Catch ex As Exception + Retorno = False + End Try + + Return Retorno + End Function +#End Region + +#Region " TAB PRINCIPAL " + + Protected Sub GvPendientes_RowDataBound(sender As Object, e As GridViewRowEventArgs) + If e.Row.RowType = DataControlRowType.DataRow Then + + 'Colorea GV + If e.Row.DBCampo("RazonSocial").ToString = "" Then + e.Row.BackColor = Drawing.Color.WhiteSmoke + Else + If e.Row.DBCampo("EstatusPagoElectronicoGrupos").ToString <> "True" Then + e.Row.BackColor = Drawing.Color.LightSalmon + e.Row.ToolTip = "Cuenta Deposito aun sin dar de Alta." + End If + + If e.Row.DBCampo("CveProveedor").ToString.ToEntero > 0 Then + e.Row.FCHyperLink("HLProveedor").NavigateUrl = String.Format("/Compras/Proveedores.aspx?CveProveedor={0}", e.Row.DBCampo("CveProveedor")) + Else + e.Row.FCHyperLink("HLProveedor").NavigateUrl = String.Format("/RH/Personal.aspx?CvePersonal={0}", e.Row.DBCampo("CvePersonal")) + End If + + End If + + If Not e.Row.DBCampo("CveCuentaDeposito").ToString.ToEntero > 0 Then + e.Row.Cells(0).BackColor = Drawing.Color.Red + e.Row.ToolTip = "Sin Cuenta Deposito asignada" + End If + + If e.Row.DBCampo("EstatusCtaDeposito").ToString = "False" Then + e.Row.Cells(0).BackColor = Drawing.Color.Red + e.Row.ToolTip = "Cuenta Deposito INACTIVA" + End If + + e.Row.FCHyperLink("HLImporte").NavigateUrl = String.Format("IE.aspx?CveIE={0}", e.Row.DBCampo("CveIE")) + + End If + End Sub + Protected Sub GvEnviadas_RowDataBound(sender As Object, e As GridViewRowEventArgs) + If e.Row.RowType = DataControlRowType.DataRow Then + 'Colorea GV + If e.Row.DBCampo("CveIE").ToString = "" Then + e.Row.BackColor = Drawing.Color.LightGray + + + 'Si la fecha de generacion del archivo es diferente de hoy activamos el boton REGENERAR + 'If e.Row.DBCampo("Fecha").ToDate.ToShortDateString <> Date.Now.ToShortDateString Then + ' e.Row.FCLinkButton("LBRegenerar").Visible = True + 'End If + If DTEnviadas.MAX("FueConciliado", String.Format("CveLayoutEnvio = {0}", e.Row.DBCampo("CveLayoutEnvio"))).ToEntero > 0 Then + e.Row.ToolTip = "El movimiento no se puede regenerar ya que alguno de sus movimientos ya fue conciliado" + Else + e.Row.FCLinkButton("LBRegenerar").Visible = True + End If + + Else + + If e.Row.DBCampo("FueConciliado") = "1" Then + e.Row.ForeColor = Drawing.Color.Red + e.Row.ToolTip = "Este movimiento ya fue conciliado." + End If + + If e.Row.DBCampo("CveProveedor").ToString.ToEntero > 0 Then + e.Row.FCHyperLink("HLProveedor").NavigateUrl = String.Format("/Compras/Proveedores.aspx?CveProveedor={0}", e.Row.DBCampo("CveProveedor")) + Else + e.Row.FCHyperLink("HLProveedor").NavigateUrl = String.Format("/RH/Personal.aspx?CvePersonal={0}", e.Row.DBCampo("CvePersonal")) + End If + e.Row.FCHyperLink("HLDetalle").NavigateUrl = String.Format("IE.aspx?CveIE={0}", e.Row.DBCampo("CveIE")) + End If + End If + End Sub + Protected Sub LBRegenerar_Click(sender As Object, e As EventArgs) + + Dim CveBLE = CType(sender, LinkButton).CommandArgument.ToEntero + Dim DtRegenerar As New DataTable + + Dim ObjBancos As New ClsBancos + If ObjBancos.GetLayoutPagos(CveCuenta, CveBLE, "-1") Then + DtRegenerar = ObjBancos.DtResultados + Else + DtRegenerar = Nothing + End If + ObjBancos.Dispose() + + If DtRegenerar IsNot Nothing Then + GeneraPago(DtRegenerar) + Else + Alert("Ocurrió un error al obtener los datos para generar el archivo. Por favor vuelva a intentar.", TipoMensaje.MsgError) + End If + + + End Sub + +#End Region + + + + 'RECARGA DATOS +#Region " RECARGA DATOS " + + Private Sub RecargaDatos() + CargaDatos() + TipoMasiva = 1 + DdlTipoCargaMasiva.SelectedValueExist("1") + CargaProveedores() + End Sub + +#End Region + + + + 'ARMA Y GENERA TXT'S + + +#Region "ALTA PROVEEDORES" + + + Protected Sub BtnAltas_Click(sender As Object, e As EventArgs) + + If Not DdlCuenta.SelectedValue.ToEntero > 0 Then + Alert("Primero debe seleccionar una Cuenta", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + AltaProveedores(1) + End Sub + + Private Sub AltaProveedores(TipoAlta As Integer) + + + NombreArchivo = "" + + Dim RegistrosAltaBancomer As New StringBuilder + Dim RegistrosAltaInterbancario As New StringBuilder + + Dim NombreArchivoBancomer As String = "" + Dim NombreArchivoInterbancario As String = "" + + Dim CeroRelleno As Char = "0"c + Dim EspacioRelleno As Char = Chr(32) + Dim ErrorLayout = False + + + Dim DtCuentasPendientesTemp As DataTable = DTPendientes.Copy + DtCuentasPendientesTemp.CaseSensitive = False + + Dim DtCuentasPendientesBancomer As DataTable = DtCuentasPendientesTemp.FiltraParametros($" (EstatusPagoElectronicoGrupos IS NULL OR EstatusPagoElectronicoGrupos = False) AND (CuentaPago like '%BBVA%' OR CuentaPago like '%BANCOMER%' ) ", "", {"CuentaPago", "NumCuenta", "AbreviaturaMon", "RazonSocial", "CveProveedor", "CveBanco"}) + Dim DtCuentasPendientesInterbancarias As DataTable = DtCuentasPendientesTemp.FiltraParametros($" (EstatusPagoElectronicoGrupos IS NULL OR EstatusPagoElectronicoGrupos = False) AND NOT (CuentaPago like '%BBVA%' OR CuentaPago like '%BANCOMER%' ) ", "", {"CuentaPago", "NumCuenta", "AbreviaturaMon", "RazonSocial", "CveProveedor", "CveBanco"}) + + + If DtCuentasPendientesBancomer.Rows.Count > 0 Then + For Each dRow As DataRow In DtCuentasPendientesBancomer.Rows + + + If dRow("NumCuenta").ToString.Length < 19 Then 'Tamaño maximo 18 + RegistrosAltaBancomer.Append(dRow("NumCuenta").ToString.PadLeft(18, CeroRelleno)) + + End If + + If dRow("AbreviaturaMon").ToString.Length = 3 AndAlso dRow("AbreviaturaMon").ToString.Contiene("MXN", "USD", "EUR") Then + RegistrosAltaBancomer.Append(dRow("AbreviaturaMon")) + End If + + RegistrosAltaBancomer.Append("0999999999999.99") + + If dRow("RazonSocial").ToString.Trim.Length < 31 Then 'Tamaño maximo 30 + RegistrosAltaBancomer.Append(dRow("RazonSocial").ToString.PadLeft(30, EspacioRelleno)) + Else + RegistrosAltaBancomer.Append(dRow("RazonSocial").ToString.Trim.Substring(0, 30)) + End If + + 'ALIAS DE LA CUENTA PENDIENTE TAMAÑO MAXIMO 30 + RegistrosAltaBancomer.Append(dRow("CveProveedor").ToString.PadLeft(30, EspacioRelleno)) + + 'CORREO OPCIONAL TAMAÑO MAXIMO 80 + 'RegistrosAlta.Append("".ToString.PadLeft(80, EspacioRelleno)) + + RegistrosAltaBancomer.Append(vbCrLf) + Next + + TextoCompleto = RegistrosAltaBancomer.ToString + + If CreaArchivo(2) Then + NombreArchivoBancomer = NombreArchivo + End If + + + End If + + + + + If DtCuentasPendientesInterbancarias.Rows.Count > 0 Then + + For Each dRow As DataRow In DtCuentasPendientesInterbancarias.Rows + + If Not (dRow("CuentaPago").ToString.ToUpper.Contains("BBVA") Or dRow("CuentaPago").ToString.ToUpper.Contains("BANCOMER")) Then + + If dRow("CveBanco").ToString = "" Then + RegistrosAltaInterbancario.Append(dRow("CveBanco").ToString) + Else + Alert("La cuenta deposito no tiene clave ABM(Clave SAT) asignada", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + End If + + + + If dRow("NumCuenta").ToString.Length < 19 Then 'Tamaño maximo 18 + RegistrosAltaInterbancario.Append(dRow("NumCuenta").ToString.PadLeft(18, CeroRelleno)) + End If + + If dRow("AbreviaturaMon").ToString.Length = 3 AndAlso dRow("AbreviaturaMon").ToString.Contiene("MXN", "USD", "EUR") Then + RegistrosAltaInterbancario.Append(dRow("AbreviaturaMon")) + End If + + RegistrosAltaInterbancario.Append("0999999999999.99") + + If dRow("RazonSocial").ToString.Trim.Length < 31 Then 'Tamaño maximo 30 + RegistrosAltaInterbancario.Append(dRow("RazonSocial").ToString.PadLeft(30, EspacioRelleno)) + Else + RegistrosAltaInterbancario.Append(dRow("RazonSocial").ToString.Trim.Substring(0, 30)) + End If + + 'ALIAS DE LA CUENTA PENDIENTE TAMAÑO MAXIMO 30 + RegistrosAltaInterbancario.Append(dRow("CveProveedor").ToString.PadLeft(30, EspacioRelleno)) + + 'CORREO OPCIONAL TAMAÑO MAXIMO 80 + 'RegistrosAlta.Append("".ToString.PadLeft(80, EspacioRelleno)) + + If Not (dRow("CuentaPago").ToString.ToUpper.Contains("BBVA") Or dRow("CuentaPago").ToString.ToUpper.Contains("BANCOMER")) Then + RegistrosAltaInterbancario.Append("40") + End If + + RegistrosAltaInterbancario.Append(vbCrLf) + + Next + + + TextoCompleto = RegistrosAltaInterbancario.ToString + If CreaArchivo(2) Then + NombreArchivoInterbancario = NombreArchivo + End If + + End If + + + Dim Mensaje As New StringBuilder + + + Mensaje.Append("Descarga Layouts
") + + If NombreArchivoBancomer.Trim.Length > 0 Then + Mensaje.Append($"Cuentas Bancomer Descarga Archivo cuentas Bancomer

") + End If + + + If NombreArchivoInterbancario.Trim.Length > 0 Then + Mensaje.Append($"Cuentas Interbancarias
Descarga Archivo cuentas Bancomer") + End If + + If NombreArchivoBancomer.Length > 0 Or NombreArchivoInterbancario.Length > 0 Then + Alert(Mensaje.ToString, TipoMensaje.MsgInformacion) + End If + + + + End Sub + + + + Private Sub AltaProveedoresViejo(TipoAlta As Integer) + Dim DtTemp As DataTable = Nothing + CreaDtAlta() + + + 'TIPO ALTA + '1 = Alta comun + '2 = Alta masiva + If TipoAlta = 1 Then + If DTPendientes Is Nothing OrElse DTPendientes.FiltraParametros("EstatusCtaDeposito = 'True'").Rows.Count <= 0 Then + Alert("No hay registros para generar", TipoMensaje.MsgAdvertencia) + Exit Sub + Else + DtTemp = DTPendientes.FiltraParametros("EstatusCtaDeposito = 'True'").Copy + End If + ElseIf TipoAlta = 2 Then + If DTProveedores Is Nothing OrElse DTProveedores.Rows.Count <= 0 Then + Alert("No hay registros para generar", TipoMensaje.MsgAdvertencia) + Exit Sub + Else + DtTemp = DTProveedores.Copy + End If + ElseIf TipoAlta = 3 Then + If DTFyE Is Nothing OrElse DTFyE.Rows.Count <= 0 Then + Alert("No hay registros para generar", TipoMensaje.MsgAdvertencia) + Exit Sub + Else + DtTemp = DTProveedores.Copy + End If + End If + + 'REINICIA PROPIEDAS + HeaderTexto = "" + DetalleTexto = "" + TrailerTexto = "" + TotalAcumulado = 0 + + ''VALIDA CUENTAS DEPOSITOS + Dim ErrorCuenta = False + Dim ProveedoresError As StringBuilder = New StringBuilder + ProveedoresError.AppendFormat("") + Dim TotalDetalles As Integer = 0 + Dim EsBancomer = False + For Each gvr As DataRow In DtTemp.Rows + If gvr("CveCuentaDeposito").ToString <> "" AndAlso gvr("EstatusPagoElectronico").ToString <> "True" AndAlso gvr("AltaCuenta").ToString = "1" Then + DTPendienteActual = DtTemp.FiltraParametros(String.Format("CveCuentaDeposito = {0}", gvr("CveCuentaDeposito").ToString)) + ErrorCuenta = False + EsBancomer = False + + If DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BBVA") Or DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BANCOMER") Or (DTPendienteActual(0)("CLABE").ToString.Length = 18 AndAlso DTPendienteActual(0)("CLABE").ToString.Substring(0, 3) = "012") Then + EsBancomer = True + End If + + ''COMENTADO PARA PERMITIR ENTRADA DE UNA CUENTA A PROVEEDOR, 22 DE SEPTIEMBRE, ISRAEL PIÑA + 'If Not ErrorCuenta Then + ' If EsBancomer AndAlso (DTPendienteActual(0)("CLABE").ToString.Length = 18 AndAlso Not DTPendienteActual(0)("CLABE").ToString.Substring(0, 3) = "012") Then + ' ProveedoresError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ' ErrorCuenta = True + ' End If + 'End If + + ''CLABE SIEMPRE OBLIGATORIA CUANDO NO ES BANCOMER CON CIE + 'If (DTPendienteActual(0)("CLABE").ToString.Trim.Length <> 18 And Not EsBancomer) Or (EsBancomer And TxtConvenioCIE.Text.Trim.Length <> 6 And DTPendienteActual(0)("CLABE").ToString.Trim.Length <> 18) Then + ' Alert("La CLABE es obligatoria y debe tener una longitud de 18 dígitos. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + ' Exit Sub + 'End If + + 'CLABE SIEMPRE OBLIGATORIA SI NO ES BANCOMER + If Not ErrorCuenta Then + If DTPendienteActual(0)("CLABE").ToString.Trim.Length <> 18 And DTPendienteActual(0)("CLABE").ToString.Trim.Length = 0 And Not EsBancomer Then + ProveedoresError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + 'SI CUENTA TIENE ALGO Y BANCO BANCOMER DEBE TENER UNA LOGITUD EXACTA DE 10 + If Not ErrorCuenta Then + If DTPendienteActual(0)("Cuenta").ToString.Trim.Length <> 0 AndAlso DTPendienteActual(0)("Cuenta").ToString.Trim.Length <> 10 AndAlso EsBancomer Then + ProveedoresError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + 'SI CLABE TIENE ALGO DEBE TENER UNA LOGITUD EXACTA DE 18 + If Not ErrorCuenta Then + If DTPendienteActual(0)("CLABE").ToString.Trim.Length <> 0 AndAlso DTPendienteActual(0)("CLABE").ToString.Trim.Length <> 18 Then + ProveedoresError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + 'SI CIE TIENE ALGO DEBE TENER REFERENCIA OBLIGATORIA + If Not ErrorCuenta Then + If DTPendienteActual(0)("CIE").ToString.Trim.Length <> 0 And DTPendienteActual(0)("Referencia").ToString.Trim.Length < 3 Then + ProveedoresError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + 'CUANDO SEA "BBVA" O "BANCOMER" DEBE TENER "CIE" O "CUENTA" + If Not ErrorCuenta Then + If EsBancomer AndAlso Not (DTPendienteActual(0)("Cuenta").ToString.Trim.Length = 10 Or DTPendienteActual(0)("CIE").ToString.Trim.Length <> 0) Then + ProveedoresError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + + 'DTPendienteActual(0)("").ToString + + 'VALDIACION ANTIGUA + 'If Not (DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BBVA") Or DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BANCOMER")) Then + ' If Not DTPendienteActual(0)("CLABE").ToString.Length = 18 Then + ' ProveedoresError.AppendFormat("Proveedor: {0}", DTPendienteActual(0)("RazonSocial").ToString) + ' ErrorCuenta = True + ' End If + 'End If + + If Not ErrorCuenta Then + If TotalDetalles > 0 Then + DetalleTexto &= vbCrLf + End If + CrearDetalle() + TotalDetalles += 1 + End If + + End If + Next + ProveedoresError.AppendFormat("
ProveedorCuentaError
{0}{1}CLABE NO PERTENECE A BANCOMER
{0}{1}CLABE ES OBLIGATORIA
{0}{1}NUMERO DE CUENTA CON FORMATO INCORRECTO
{0}{1}CLABE CON FORMATO INCORRECTO
{0}{1}CIE CON FORMATO INCORRECTO
{0}{1}CUENTA BANCOMER SIN CUENTA O CIE
") + + + If TotalDetalles > 0 Then + FormarTexto(TotalDetalles) + CreaArchivo(2) + + Dim Descargas As New StringBuilder() + Descargas.AppendFormat("
  • TXT
  • ", NombreArchivo) + 'Descargas.AppendFormat("
  • Reporte
  • ", NombreArchivo) + Descargas.AppendFormat("
  • Descargar Reporte
  • ", NombreArchivo) + + + Dim TextoErrorProveedores = "" + If ProveedoresError.Length > 160 Then TextoErrorProveedores = String.Format("


    Proveedores con Error:

    ------------------------------------------------------------------
    {0}

    ", ProveedoresError.ToString) + + Alert(String.Format("
    El Layout fue creado satisfactoriamente.{1}
    Descargas:
      {0}
    ", Descargas, TextoErrorProveedores), TipoMensaje.MsgInformacion) + + 'NombreArchivo = "LayoutAltaProveedores" + 'DescargarArchivo() + Else + Alert("No hay proveedores que dar de alta", TipoMensaje.MsgInformacion) + End If + + End Sub + + Protected Sub CrearDetalle() + Dim Resultado = True + Dim CuentaDeposito As String = "" + Dim TipoCuentaDeposito As String = "" + Dim TipoCuenta As String = "" + + ''''' LLENADO DE DETALLE + 'Campos #1-4 del Detalle + DetalleTexto &= String.Format("DA{0}N ", DTPendienteActual(0)("CveCuentaDeposito").ToString.ToUpper.PadLeft(30, PadCeros)) + + 'Banco BBVA + If DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BBVA") Or DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BANCOMER") Then + 'Llenamos datos de BBVA + 'Campo #5-7 del detalle + + 'Busca que cuenta sera la asignada para el proveedor + If DTPendienteActual(0)("CIE").ToString <> "" Then + CuentaDeposito = String.Format("02{0}", DTPendienteActual(0)("CIE").ToString.PadLeft(8, PadCeros)) + TipoCuenta = "50" + TipoCuentaDeposito = "CIE" + ElseIf DTPendienteActual(0)("Cuenta").ToString.Length = 10 Then + CuentaDeposito = DTPendienteActual(0)("Cuenta").ToString + TipoCuenta = "99" + TipoCuentaDeposito = "Cuenta" + ElseIf DTPendienteActual(0)("CLABE").ToString.Length = 18 Then + CuentaDeposito = DTPendienteActual(0)("CLABE").ToString + TipoCuenta = "40" + TipoCuentaDeposito = "CLABE" + End If + + + DetalleTexto &= String.Format("{0}{1}{2}", DTPendienteActual(0)("Abreviatura").ToString, TipoCuenta, CuentaDeposito.PadLeft(35, PadCeros)) + + 'Llenamos en blanco datos de otros bancos + 'Campos 8-17 del detalle --- 64 de otros bancos y 45 para FILLER --- Fecha de Alta + DetalleTexto &= String.Format("{0}{1}", Vacio.PadLeft(109), DateTime.Now().ToString("yyyy-MM-dd")) + + + 'Otros Bancos NACIONAL!! + Else + + CuentaDeposito = DTPendienteActual(0)("CLABE").ToString + TipoCuentaDeposito = "CLABE" + + 'Llenamos en blanco datos de BBVA + DetalleTexto &= Vacio.PadRight(40) + + 'Llenamos datos de otros bancos + 'Campos 8- 17 del detalle --- 44 de otros bancos --- 20 de internacional --- 45 Filler -- Fecha de Alta + DetalleTexto &= String.Format("{0}40{1}{2}{3}{4}{5}", DTPendienteActual(0)("Abreviatura").ToString, DTPendienteActual(0)("CLABE").ToString.PadLeft(35, PadCeros), DTPendienteActual(0)("CLABE").ToString.Substring(0, 3).PadLeft(4, PadCeros), Vacio.PadRight(20), Vacio.PadRight(45), DateTime.Now().ToString("yyyy-MM-dd")) + End If + + 'Llenamos datos de Tipo de Persona - Fisica o Moral + TipoPersona() + + 'Campos 27-32 --- Fillers --- datos de otros bancos (internacional) + DetalleTexto &= Vacio.PadLeft(153) + + 'Campos 33-36 --- Datos de confirmacion + DetalleTexto &= String.Format("{0}02{1}", Vacio.PadRight(40), CorreoNotificacionesEmpresa.ToUpper.PadRight(50)) + + 'If DTPendienteActual(0)("ContactoMail").ToString.Length > 0 Then + ' 'DetalleTexto &= String.Format("{0}02{1}", Vacio.PadRight(40), DTPendienteActual(0)("ContactoMail").ToString.ToUpper.PadRight(50)) + 'ElseIf DTPendienteActual(0)("ContactoMail").ToString.Length <= 0 Then + ' DetalleTexto &= String.Format("{0}00{1}", Vacio.PadRight(40), Vacio.PadRight(50)) + 'End If + + 'Campos 37-39 -- FILLER + DetalleTexto &= String.Format("00{0}", Vacio.PadRight(38)) + + + ''LLENA DT PARA REPORTE + Dim Row = DtAlta.NewRow() + Row("Proveedor") = DTPendienteActual(0)("RazonSocial").ToString + Row("Banco") = DTPendienteActual(0)("BancoNombre").ToString + Row("TipoCuenta") = TipoCuentaDeposito + Row("Cuenta") = String.Format("{0}", CuentaDeposito) + DtAlta.Rows.Add(Row) + End Sub + + Protected Sub TipoPersona() + 'Persona Moral + If DTPendienteActual(0)("RFC").ToString.Length = 12 Then + Dim fecha As String = DTPendienteActual(0)("FechaIng").ToString + Dim NombreProveedor = DTPendienteActual(0)("RazonSocial").ToString.Replace("‚"c, Vacio).Replace("‚"c, Vacio).ToUpper.PadRight(50) + NombreProveedor = If(NombreProveedor.Length > 50, NombreProveedor.Substring(0, 50), NombreProveedor) + + 'Campo 18-20 del detalle + DetalleTexto &= String.Format("M{0}{1}-{2}-{3}", NombreProveedor, fecha.Substring(6, 4), fecha.Substring(3, 2), fecha.Substring(0, 2)) + 'Campo 21-26 del detalle --- 10 FILLER - 70 de TipoPersona FISICA - 14 de RFC + DetalleTexto &= String.Format("{0}{1}", Vacio.PadLeft(80), DTPendienteActual(0)("RFC").ToString.ToUpper.PadRight(14)) + + 'Persona Fisica + ElseIf DTPendienteActual(0)("RFC").ToString.Length = 13 Then + + + If DTPendienteActual(0)("Tipo").ToString = "FyE" Then + + 'Llenamos datos de Tipo de Persona - Fisica nombres Primer apellido Segundo apellido + DetalleTexto &= String.Format("F{0}{1}{2}{3}", Vacio.PadRight(70), DTPendienteActual(0)("Nombres").ToString.PadRight(20).Substring(0, 20), DTPendienteActual(0)("APaterno").ToString.PadRight(20).Substring(0, 20), DTPendienteActual(0)("AMaterno").ToString.PadRight(20).Substring(0, 20)) + + 'Campo 25-26 del detalle -- Fecha Nacimiento -- RFC + DetalleTexto &= String.Format("{0}{1}", DTPendienteActual(0)("FechaNacimiento").ToString.ToDate.ToString("yyyy-MM-dd"), DTPendienteActual(0)("RFC").ToString.ToUpper.PadRight(14)) + + Else + + 'Obtener nombre + Dim Nombre() As String = Split(DTPendienteActual(0)("RazonSocial").ToString.Replace(",", "")) + + 'Campo 18-24 del detalle --- 60 Tipo Persona Moral --- 10 Filler -- Datos Persona Fisica + If Nombre.Length = 2 Then + DetalleTexto &= String.Format("F{0}{1}{2}{3}", Vacio.PadRight(70), Nombre(0).PadRight(20).Substring(0, 20), Nombre(1).PadRight(20).Substring(0, 20), Vacio.PadRight(20).Substring(0, 20)) + ElseIf Nombre.Length = 3 Then + DetalleTexto &= String.Format("F{0}{1}{2}{3}", Vacio.PadRight(70), Nombre(0).PadRight(20), Nombre(1).PadRight(20).Substring(0, 20), Nombre(2).PadRight(20).Substring(0, 20)) + ElseIf Nombre.Length = 4 Then + DetalleTexto &= String.Format("F{0}{1}{2}{3}", Vacio.PadRight(70), (Nombre(0) & " " & Nombre(1)).PadRight(20).Substring(0, 20), Nombre(2).PadRight(20).Substring(0, 20), Nombre(3).PadRight(20).Substring(0, 20)) + ElseIf Nombre.Length > 4 Then + + Dim NombreComplejo As New List(Of String) + + 'ignoramos cualquier palabra del nombre que tenga un length igual o menor a 2 + For index = 0 To Nombre.Length - 1 + If Nombre(index).Length > 2 Then + NombreComplejo.Add(Nombre(index)) + End If + Next + + If NombreComplejo.Count = 2 Then + DetalleTexto &= String.Format("F{0}{1}{2}{3}", Vacio.PadRight(70), NombreComplejo.Item(0).PadRight(20).Substring(0, 20), NombreComplejo.Item(1).PadRight(20).Substring(0, 20), Vacio.PadRight(20).Substring(0, 20)) + ElseIf NombreComplejo.Count = 3 Then + DetalleTexto &= String.Format("F{0}{1}{2}{3}", Vacio.PadRight(70), NombreComplejo.Item(0).PadRight(20), NombreComplejo.Item(1).PadRight(20).Substring(0, 20), NombreComplejo.Item(2).PadRight(20).Substring(0, 20)) + ElseIf NombreComplejo.Count = 4 Then + DetalleTexto &= String.Format("F{0}{1}{2}{3}", Vacio.PadRight(70), (NombreComplejo.Item(0) & " " & NombreComplejo.Item(1)).PadRight(20).Substring(0, 20), NombreComplejo.Item(2).PadRight(20).Substring(0, 20), NombreComplejo.Item(3).PadRight(20).Substring(0, 20)) + ElseIf NombreComplejo.Count > 4 Then + Dim Nombres = "" + + 'todas las palabras menos las 2 ultimas forman parte del nombre + For index = 0 To NombreComplejo.Count - 3 + If Nombres <> "" Then Nombres += " " + Nombres += NombreComplejo.Item(index) + Next + DetalleTexto &= String.Format("F{0}{1}{2}{3}", Vacio.PadRight(70), Nombres.PadRight(20).Substring(0, 20), NombreComplejo.Item(NombreComplejo.Count - 2).PadRight(20).Substring(0, 20), NombreComplejo.Item(NombreComplejo.Count - 1).PadRight(20).Substring(0, 20)) + + End If + + End If + + 'Campo 25-26 del detalle -- Fecha Nacimiento -- RFC + Dim fecha As String = DTPendienteActual(0)("RFC").ToString.Substring(4, 6) + DetalleTexto &= String.Format("19{0}-{1}-{2}{3}", fecha.Substring(0, 2), fecha.Substring(2, 2), fecha.Substring(4, 2), DTPendienteActual(0)("RFC").ToString.ToUpper.PadRight(14)) + + End If + + + Else + 'Alert("Hola") + End If + End Sub + Protected Sub FormarTexto(Registros As Integer) + '''''' LLENADO HEADER + Dim convenio As String = DTPendienteActual(0)("ConvenioPagoElectronico").ToString + 'Campos #1-4 del Header + HeaderTexto = String.Format("H{0}{1}GRUPO01 ", convenio.PadLeft(9, PadCeros), DateTime.Now().ToString("yyyy-MM-dd")) + 'Campo #5 del Header + + Dim IdentificadoUsuario As String = UsuarioActual.Usuario.Replace(" ", "").Replace(".", "").Replace("@", "").Replace("/", "").ToUpper.Trim + IdentificadoUsuario = If(IdentificadoUsuario.Length > 12, IdentificadoUsuario.Substring(0, 12), IdentificadoUsuario) + ' Dim Identificado As String = String.Format("{0}{1}", UsuarioActual.Usuario, DateTime.Now().ToString("yyyyMMdd"))) + + HeaderTexto &= String.Format("{0}{1}", IdentificadoUsuario, DateTime.Now().ToString("yyyyMMdd")).PadRight(20) + 'Campos #6-8 del Header + HeaderTexto &= String.Format("00").PadRight(586) + Dim HeaderLength = HeaderTexto.Length + + ''''' LLENADO DE TRAILER + TrailerTexto = String.Format("T{0}{1}{2}", Registros.ToString.PadLeft(10, PadCeros), Vacio.PadRight(50, PadCeros), Vacio.PadRight(575)) + + ''''' ARMADO DEL TEXTO COMPLETO + TextoCompleto = String.Format("{1}{0}{2}{0}{3}{0}", vbCrLf, HeaderTexto, DetalleTexto, TrailerTexto) + 'TxtAltas.Text = TextoCompleto + End Sub + +#End Region + +#Region "PAGO PROVEEDORES" + Protected Sub BtnPagos_Click(sender As Object, e As EventArgs) + + If Not DdlCuenta.SelectedValue.ToEntero > 0 Then + Alert("Primero debe seleccionar una Cuenta", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If DTPendientes.FiltraParametros("EstatusPagoElectronicoGrupos = 'True' AND EstatusCtaDeposito = 'True'") IsNot Nothing Then + + GeneraPago(DTPendientes.FiltraParametros("EstatusPagoElectronico > 0 AND EstatusCtaDeposito > 0")) + + Else + + Alert("No hay registros para generar", TipoMensaje.MsgAdvertencia) + + End If + End Sub + + Private Sub GeneraPago(DTPendientesTemp As DataTable) + + Dim RegistrosPago As New StringBuilder + Dim MENSAJE As New StringBuilder + + + Dim CeroRelleno As Char = "0"c + Dim EspacioRelleno As Char = Chr(32) + Dim ErrorLayout = False + + + For Each drow As DataRow In DTPendientesTemp.Rows + + + If drow("BancoNombre").ToString.ToUpper.Contains("BANCOMER") Or drow("BancoNombre").ToString.ToUpper.Contains("BBVA") Then + RegistrosPago.Append("PTC") + Else + RegistrosPago.Append("PSC") + End If + + If drow("CLABEOrigen").ToString.Trim.Length = 18 Then + RegistrosPago.Append(drow("CLABEOrigen").ToString) + Else + ErrorLayout = True + MENSAJE.AppendLine("ERROR EN CLABE") + Exit For + End If + + If drow("CLABEDestino").ToString.Trim.Length <> 18 Then + RegistrosPago.Append(drow("CLABEDestino").ToString) + Else + ErrorLayout = True + MENSAJE.AppendLine("ERROR EN CLABE") + Exit For + End If + + RegistrosPago.Append("Abreviatura") + + RegistrosPago.Append(drow("Abonado").ToString.ToDecimal.ToString("0000000000000.00")) + + RegistrosPago.Append(drow("CveIE").ToString.PadRight(30, EspacioRelleno)) + + RegistrosPago.Append(vbCrLf) + + 'CveIE + + Next + + + + End Sub + + Private Sub GeneraPagoViejo(DTTemp As DataTable, CveBLE As Integer) + If DTTemp.Rows.Count <= 0 Then + Alert("No hay registros para generar", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + 'For Each gvr As DataRow In DTTemp.Rows + ' If gvr("EstatusPagoElectronico").ToString.ToEntero <= 0 Then + ' Alert("Los proveedores tienen que estar dados de alta. Primero de alta a los proveedores") + ' Exit Sub + ' End If + 'Next + + 'Comprobamos la cuenta deposito y moneda de las cuentas deposito + For Each dr As DataRow In DTTemp.Rows + If dr("BancoNombre").ToString = "" Then + Alert(String.Format("El Pago '{0}' no tiene Cuenta Deposito Asociada.", dr("Observaciones")), TipoMensaje.MsgError) + Exit Sub + End If + + If dr("MonedaCtaDeposito").ToString = "" Or dr("MonedaCtaDeposito").ToString.ToEntero <= 0 Then + Alert(String.Format("La cuenta deposito '{0}' del proveedor '{1}' no tiene Moneda especificada.", dr("CuentaDeposito"), dr("RazonSocial")), TipoMensaje.MsgError) + Exit Sub + End If + Next + + 'Excluimos los registros que no tengan cuenta deposito dada de alta + 'DTTemp = DTTemp.FiltraParametros("EstatusPagoElectronico = 0") + + HeaderTexto = "" + DetalleTexto = "" + TrailerTexto = "" + TotalAcumulado = 0 + + 'Insertar en LayoutEnvios + Dim ObjBancos As New ClsBancos + ObjBancos.IniciaTransacSQL() + Dim ErrorLayout = False + + Dim TotalDetalles As Integer = 0 + + 'CREA CARPETA SI NO EXISTE + Dim path As String = Server.MapPath(String.Format("~/Empresas/{0}/Layout/", UsuarioActual.CveEmpresa)) + Dim exists = System.IO.Directory.Exists(path) + If Not exists Then + System.IO.Directory.CreateDirectory(path) + End If + + Dim CveIEs = "" + CreaDtPago() + + For Each gvr As DataRow In DTTemp.Rows + If gvr("CveCuentaDeposito").ToString <> "" Then + DTPendienteActual = DTTemp.FiltraParametros(String.Format("CveIE = {0}", gvr("CveIE").ToString)) + + 'ACTUALIZA FECHADOCUMENTO DEL IE + 'If CveBLE > 0 Then + ' ObjBancos.UpdateBancos_IE(Date.Now, Date.Now, DTPendienteActual(0)("CveIE").ToString.ToEntero) + 'End If + + If TotalDetalles > 0 Then + DetalleTexto &= vbCrLf + End If + CrearDetallePagos() + TotalDetalles += 1 + End If + Next + + FormarTextoPagos(TotalDetalles, TotalAcumulado.ToString.FormatoNumero.Replace(",", "").Replace(".", "")) + CreaArchivo(1) + + If CveBLE > 0 Then + 'ACTUALIZAMOS EL ENVIO SI ES REGENERACION + If Not ObjBancos.UpdateLayoutEnvios(CveBLE, Date.Now) Then + ErrorLayout = True + End If + + 'GUARDAMOS EL ENVIO SI NO ES REGENERACION + Else + + Dim CveLayoutEnvio = ObjBancos.AddLayoutEnvios(NombreArchivo, Date.Now, CveCuenta) + + If CveLayoutEnvio > 0 Then + For Each dr As DataRow In DTTemp.Rows + If dr("CveProveedor").ToString <> "" Or dr("CvePersonal").ToString <> "" Then + If Not ObjBancos.AddLayoutEnviosDetalle(CveLayoutEnvio, dr("CveIE").ToString.ToEntero, dr("CveProveedor").ToString.ToEntero, dr("CvePersonal").ToString.ToEntero, 1, "Observaciones") Then + ErrorLayout = True + End If + End If + Next + Else + ErrorLayout = True + End If + + End If + + + + If Not ErrorLayout Then + ObjBancos.Commit() + ObjBancos.Dispose() + + + Dim Des = String.Format("{0}Layout\{1}", UsuarioActual.Empresa.Ruta, NombreArchivo) + Dim Descargas As New StringBuilder() + Descargas.AppendFormat("
  • TXT
  • ", NombreArchivo) + ' Descargas.AppendFormat("
  • Reporte
  • ", NombreArchivo) + Descargas.AppendFormat("
  • Descargar Reporte
  • ", NombreArchivo) + + Alert(String.Format("
    El Layout fue creado satisfactoriamente.


    Descargas:
      {0}
    ", Descargas), TipoMensaje.MsgInformacion) + 'Alert("El Layout fue creado satisfactoriamente") + Else + ObjBancos.RollBack() + ObjBancos.Dispose() + Alert("Ocurrio un problema al registrar la creacion del Layout. Por favor vuelva a intentar.", TipoMensaje.MsgError) + End If + + End Sub + + Protected Sub CrearDetallePagos() + 'Dim Resultado = True + Dim Importe As String = DTPendienteActual(0)("Abonado").ToString ' importe + Dim Divisa As String = DTPendienteActual(0)("Abreviatura").ToString.ToUpper + 'Dim Factura As String = "FAC-123456".Replace("-", " ") + Dim Referencia As String = "" + + Dim Observaciones As String = DTPendienteActual(0)("Observaciones").ToString.Replace(":", "").Replace("-", " ").Replace(",", "").Replace(vbCrLf, " ").ToUpper + + ''PARA DETECTAR SI ES CIE + Dim CuentaDeposito As String + Dim CodigoOperacion As String = "2" + + 'Busca que cuenta sera la asignada para el proveedor + If DTPendienteActual(0)("CIE").ToString.Length >= 4 Then + CuentaDeposito = String.Format("02{0}", DTPendienteActual(0)("CIE").ToString.PadLeft(8, PadCeros)) + CodigoOperacion = "3" + Referencia = If(DTPendienteActual(0)("Referencia").ToString = "", "0", DTPendienteActual(0)("Referencia").ToString) 'String.Format("CVEIE{0}", DTPendienteActual(0)("CveIE").ToString).ToUpper 'cveIE + Else + Referencia = Observaciones.Replace(" ", "") + Referencia = If(Referencia.Length > 20, Referencia.Substring(0, 20), Referencia) + Referencia = If(Referencia.Length = 0, "PAGO", Referencia) + End If + + + ''CLAVE DE REGISTRO PARA CONTROL PROPIO ADSISTEMAS -- orita se esta guardando en el campo #9 + Dim Cve = String.Format("CVEIE{0}", DTPendienteActual(0)("CveIE").ToString).ToUpper 'cveIE + + + ''''' LLENADO DE DETALLE + 'Campos #1-6 del Detalle + DetalleTexto &= String.Format("DAP{0}{1}PDA", Referencia.PadRight(20), DTPendienteActual(0)("CveCuentaDeposito").ToString.PadLeft(30, PadCeros)) + + 'Pago a cuenta BBVA + If DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BANCOMER") Or DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BBVA") Then + 'Campos 7-24 del Detalle + 'CVE IE EN CAMPO 9 - VIEJO + 'DetalleTexto &= String.Format("{0}{1}{2}{3}N{4}", CodigoOperacion, Vacio.PadLeft(20, PadCeros), Cve.PadRight(15), Vacio.PadRight(139), Vacio.PadRight(187)) + DetalleTexto &= String.Format("{0}{1}{2}{3}{4}N{5}", CodigoOperacion, Vacio.PadLeft(20, PadCeros), Vacio.PadRight(40), Cve.PadRight(37), Vacio.PadRight(77), Vacio.PadRight(187)) + Else + Dim ReferenciaNumerica As String = "0" 'DTPendienteActual(0)("Referencia").ToString + Dim Motivo As String = "Pago de facturas" + + 'Campos 7-24 del Detalle + 'CVE IE EN CAMPO 9 - VIELO + 'DetalleTexto &= String.Format("6{0}{1}{2}{3}{4}N{5}", Vacio.PadRight(20, PadCeros), Cve.PadRight(15), ReferenciaNumerica.PadRight(25), Motivo.ToUpper.PadRight(37), Vacio.PadRight(77), Vacio.PadRight(187)) + DetalleTexto &= String.Format("6{0}{1}{2}{3}{4}N{5}", Vacio.PadRight(20, PadCeros), Vacio.PadRight(15), ReferenciaNumerica.PadRight(25), Cve.PadRight(37), Vacio.PadRight(77), Vacio.PadRight(187)) + End If + + 'OBTENEMOS EL CORREO DEL PROVEEDOR + Dim Correo = CorreoNotificacionesEmpresa.ToUpper.PadRight(50) + 'Correo = If(Correo.Length > 0, Correo.ToUpper.PadRight(50), Vacio.PadRight(50)) + + 'Campos 24-50 del Detalle 0 1 2 3 4 5 6 7 8 9 + DetalleTexto &= String.Format("{0}{1}FA{2}{3}01{4}N{5}{6}{7}{7}{7}{6}N {7}700{8}{9}{7}", Divisa, Vacio.PadLeft(20), Importe.FormatoNumero.Replace(",", "").Replace(".", "").PadLeft(15, PadCeros), Vacio.PadRight(15, PadCeros), Correo, Vacio.PadRight(12, PadCeros), DateTime.Now.ToString("yyyy-MM-dd"), "0001-01-01", Observaciones.PadRight(700), Vacio.PadRight(52)) + TotalAcumulado += Importe.ToDouble + + + + ''LLENA DTPAGOS PARA REPORTE + Dim Row = DtPago.NewRow() + Row("Proveedor") = DTPendienteActual(0)("RazonSocial").ToString + + If DTPendienteActual(0)("CIE").ToString <> "" Then + Row("Cuenta") = String.Format("02{0}", DTPendienteActual(0)("CIE").ToString.PadLeft(8, PadCeros)) + ElseIf DTPendienteActual(0)("Cuenta").ToString.Length = 10 Then + Row("Cuenta") = DTPendienteActual(0)("Cuenta").ToString + ElseIf DTPendienteActual(0)("CLABE").ToString.Length = 18 Then + Row("Cuenta") = DTPendienteActual(0)("CLABE").ToString + End If + + Row("Importe") = Importe + Row("Moneda") = DTPendienteActual(0)("Abreviatura").ToString.ToUpper + Row("Observaciones") = DTPendienteActual(0)("Observaciones").ToString + DtPago.Rows.Add(Row) + + End Sub + + Protected Sub FormarTextoPagos(Registros As Integer, Total As String) + Dim convenio As String = DTPendienteActual(0)("ConvenioPagoElectronico").ToString + + '''''' LLENADO HEADER + 'Campos #1-4 del Header + HeaderTexto = String.Format("H{0}{1}01", convenio.PadLeft(9, PadCeros), DateTime.Now().ToString("yyyy-MM-dd")) + 'Campo #5 del Header + HeaderTexto &= String.Format("P{0}{1}", DateTime.Now().ToString("s").Replace("-", "").Replace(":", ""), Vacio.PadRight(14)) + 'Campos #6-11 del Header + HeaderTexto &= String.Format("00").PadRight(1314) + + + ''''' LLENADO DE TRAILER + TrailerTexto = String.Format("T{0}{1}{2}{3}", Registros.ToString.PadLeft(10, PadCeros), Total.PadLeft(15, PadCeros), Vacio.PadRight(225, PadCeros), Vacio.PadRight(1115)) + + + ''''' ARMADO DEL TEXTO COMPLETO + TextoCompleto = String.Format("{1}{0}{2}{0}{3}{0}", vbCrLf, HeaderTexto, DetalleTexto, TrailerTexto) + + End Sub +#End Region + +#Region "CARGA ALTA PROVEEDORES" + + Private Sub CreaDtAlta() + + DtAlta = New DataTable + DtAlta.Columns.Add("CveProveedor", GetType(String)) + + DtAlta.Columns.Add("Proveedor", GetType(String)) + DtAlta.Columns.Add("Banco", GetType(String)) + DtAlta.Columns.Add("TipoCuenta", GetType(String)) + DtAlta.Columns.Add("Cuenta", GetType(String)) + DtAlta.Columns.Add("Estatus", GetType(String)) + + DtAlta.Columns.Add("MensajeAdicional", GetType(String)) + DtAlta.Columns.Add("Moneda", GetType(String)) + + End Sub + + + Protected Sub BtnCargarAlta_Click(sender As Object, e As EventArgs) + Dim ErrorArchivo = False + + If FUTxt.HasFile Then + If Not GuardaTXT() Then + Alert("Ocurrio un error al cargar el archivo", TipoMensaje.MsgError) + Exit Sub + End If + Else + Alert("No tiene ningun archivo", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + + 'LEE TXT + Dim Texto As String + + Dim sr As New System.IO.StreamReader(NombreArchivo) + Texto = sr.ReadToEnd() + sr.Close() + + Dim TextoArreglo() = Texto.Split(CChar(vbCrLf)) + + 'Alert(TextoArreglo.Length.ToString) + + 'LEE LINEA POR LINEA + Dim RespuestaHeader = "", RespuestaDetalle = "", RespuestaTrailer = "", CveCuentasDeposito = "" + CreaDtAlta() + Dim ObjGrales As New ClsGenerales + Dim Row As DataRow = Nothing + Dim TipoCuentaDeposito = "" + + For i = 0 To TextoArreglo.Length - 1 Step 1 + 'Valida que el primer renglon sea el HEADER + If i = 0 Then + If TextoArreglo(i).Substring(0, 1) <> "H" Then + ErrorArchivo = True + Exit For + Else + RespuestaHeader = TextoArreglo(i).Substring(50, 2) + End If + Else + 'LEE DETALLE + If TextoArreglo(i).Length > 1 Then + If TextoArreglo(i).Substring(1, 1) = "D" Then + + 'If i > 1 Then + ' RespuestaDetalle += vbCrLf + 'End If + + 'RespuestaDetalle += String.Format("{0}{1}", If(TextoArreglo(i).Substring(197, 1) = "M", TextoArreglo(i).Substring(198, 50).Trim, TextoArreglo(i).Substring(268, 60).Trim), (TextoArreglo(i).Substring(599, 30))) + + ''Guardo CveCuentaDeposito cuando la operacion salio exitosa para actualizar en la DB + If TextoArreglo(i).Substring(597, 2) = "00" Or TextoArreglo(i).Substring(597, 2) = "34" Then + CveCuentasDeposito += If(CveCuentasDeposito <> "", ",", "") + CveCuentasDeposito += TextoArreglo(i).Substring(3, 30).ToEntero.ToString + End If + + + ''LLENA DT PARA REPORTE + Row = DtAlta.NewRow() + + Row("Proveedor") = If(TextoArreglo(i).Substring(197, 1) = "M", TextoArreglo(i).Substring(198, 50).Trim, TextoArreglo(i).Substring(268, 60).Trim) + + 'BANCO + If ObjGrales.GetCuentasDepositos(CveCuentaDeposito:=TextoArreglo(i).Substring(3, 30).ToEntero) Then + If ObjGrales.DtResultados.Rows.Count = 1 Then + Row("Banco") = ObjGrales.DtResultados.Rows(0)("BancoNombre").ToString + Else + ErrorArchivo = True + Exit For + End If + Else + ErrorArchivo = True + Exit For + End If + + 'CUENTA + If TextoArreglo(i).Substring(41, 2).Trim <> "" Then + Row("Cuenta") = String.Format("{0}", TextoArreglo(i).Substring(43, 35).TrimStart("0"c)) + ElseIf TextoArreglo(i).Substring(81, 2).Trim <> "" Then + Row("Cuenta") = String.Format("{0}", TextoArreglo(i).Substring(83, 35).TrimStart("0"c)) + Row("TipoCuenta") = "CLABE" + Else + ErrorArchivo = True + Exit For + End If + + 'TIPO CUENTA + If Row("TipoCuenta").ToString = "" Then + If String.Format("{0}", TextoArreglo(i).Substring(43, 35).TrimStart("0"c)).Length = 8 Then + Row("TipoCuenta") = "CIE" + ElseIf String.Format("{0}", TextoArreglo(i).Substring(43, 35).TrimStart("0"c)).Length = 10 Or String.Format("{0}", TextoArreglo(i).Substring(43, 35).TrimStart("0"c)).Length = 9 Then + Row("TipoCuenta") = "Cuenta" + ElseIf String.Format("{0}", TextoArreglo(i).Substring(43, 35).TrimStart("0"c)).Length = 18 Then + Row("TipoCuenta") = "CLABE" + End If + End If + + Row("Estatus") = TextoArreglo(i).Substring(599, 30) + + DtAlta.Rows.Add(Row) + + ''LLENA PARA ALERT + 'If i > 1 Then + ' RespuestaDetalle += vbCrLf + 'End If + + 'RespuestaDetalle += String.Format("{0}{1}", If(TextoArreglo(i).Substring(197, 1) = "M", TextoArreglo(i).Substring(198, 50).Trim, TextoArreglo(i).Substring(268, 60).Trim), (TextoArreglo(i).Substring(599, 30))) + + + 'LEE TRAILER + ElseIf TextoArreglo(i).Substring(1, 1) = "T" Then + RespuestaTrailer = TextoArreglo(i).Substring(32, 10) + RespuestaTrailer += vbCrLf + RespuestaTrailer += TextoArreglo(i).Substring(42, 10) + RespuestaTrailer += vbCrLf + RespuestaTrailer += TextoArreglo(i).Substring(52, 10) + Exit For + Else + ErrorArchivo = True + Exit For + End If + End If + End If + Next + ObjGrales.Dispose() + + + Dim Respuesta As New StringBuilder + 'LEE ARCHIVO + If Not ErrorArchivo Then + 'TRADUCE CODIGO RESPUESTA HEADER + If RespuestaHeader = "01" Then + RespuestaHeader = "ACEPTADO TOTAL" + ElseIf RespuestaHeader = "02" Then + RespuestaHeader = "ACEPTADO PARCIAL" + ElseIf RespuestaHeader = "03" Then + RespuestaHeader = "RECHAZADO" + End If + + 'DIVIDE DETALLE + Dim Detalle() = RespuestaDetalle.Split(CChar(vbCrLf)) + + 'DIVIDE TRAILER + Dim Trailer() = RespuestaTrailer.Split(CChar(vbCrLf)) + + 'ARMADO DE RESPUESTA + Respuesta.AppendFormat("
    Resumen de respuesta: {0}
    ", RespuestaHeader) + Respuesta.AppendFormat("Numero de movimientos: {0}


    ", DtAlta.Rows.Count) + Respuesta.Append("------------------------------ Detalle de los movimientos ------------------------------
    ") + + Respuesta.Append("") + 'For i = 0 To Detalle.Length - 1 + ' Respuesta.AppendFormat("{1}", i + 1, Detalle(i).Trim) + 'Next + Dim i = 1 + Dim Style = "" + Dim TotalExitos = 0, TotalFracasos = 0 + For Each dr As DataRow In DtAlta.Rows + + If dr("estatus").ToString.Trim.Contiene("OPERACION EXITOSA", "ALTA TERCERO EXITOSO") Then + Style = "" + TotalExitos += 1 + Else + Style = "style=""background-color:#FF5F5F;"" " + TotalFracasos += 1 + End If + + Respuesta.AppendFormat("", i, dr("Proveedor"), dr("Banco"), dr("TipoCuenta"), dr("Cuenta"), dr("estatus"), Style) + i += 1 + Next + + Respuesta.Append("
    #ProveedorBancoTipo CuentaCuentaEstatus
    {0}
    {0}{1}{2}{3}{4}{5}
    -------------------------------------------------------------------------------------
    ") + + Respuesta.AppendFormat("Total de movimientos exitosos: {0}
    ", TotalExitos) + Respuesta.AppendFormat("Total de movimientos NO exitosos: {0}
    ", TotalFracasos) + + 'LEE DESDE EL LAYOUT + 'Respuesta.AppendFormat("Total de altas rechazadas: {0}
    ", Trailer(0).ToString.ToEntero) + 'Respuesta.AppendFormat("Total de bajas rechazadas: {0}
    ", Trailer(1).ToString.ToEntero) + 'Respuesta.AppendFormat("Total de cambios rechazados: {0}
    ", Trailer(2).ToString.ToEntero) + + End If + + If Not ErrorArchivo Then + + If CveCuentasDeposito <> "" Then + Dim ObjIE As New ClsBancos + Dim ErrorDB = False + ObjIE.IniciaTransacSQL() + Dim ArrayCuentasDeposito() = CveCuentasDeposito.Split(","c) + + For index = 0 To ArrayCuentasDeposito.Length - 1 + If Not ObjIE.UpdateCuentaDepositoPagoElectronico(ArrayCuentasDeposito(index).ToEntero) Then + ErrorDB = True + End If + Next + + If Not ErrorDB Then + ObjIE.Commit() + Respuesta.Append("

    NOTA: El archivo se analizo correctamente y se efectuaron todos los cambios en el sistema.") + 'Respuesta.AppendFormat("
    Descargar reporte", NombreArchivo) + Respuesta.AppendFormat("
  • Descargar Reporte
  • ", NombreArchivo) + + Alert(Respuesta.ToString, TipoMensaje.MsgInformacion) + Else + ObjIE.RollBack() + Respuesta.Append("

    NOTA: El archivo se analizo correctamente pero ocurrio un problema al efectuar los cambios en el sistema. Por favor vuelta a intentar.") + Alert(Respuesta.ToString, TipoMensaje.MsgError) + End If + + ObjIE.Dispose() + Else + Respuesta.AppendFormat("

    NOTA: El archivo se analizo correctamente pero ningun movimiento fue exitoso.") + 'Respuesta.AppendFormat("
    Descargar reporte", NombreArchivo) + Respuesta.AppendFormat("
  • Descargar Reporte
  • ", NombreArchivo) + + Alert(Respuesta.ToString, TipoMensaje.MsgAdvertencia) + End If + + Else + Alert("Ocurrio un problema al leer el archivo. Por favor revise que el archivo sea el correcto e intente de nuevo.", TipoMensaje.MsgError) + End If + + 'ELIMINA TXT + My.Computer.FileSystem.DeleteFile(NombreArchivo) + + RecargaDatos() + + End Sub +#End Region + +#Region "CARGA PAGO PROVEEDORES" + Private Sub CreaDtPago() + + DtPago = New DataTable + DtPago.Columns.Add("NumeroConvenio", GetType(String)) + DtPago.Columns.Add("ClaveProveedor", GetType(String)) + DtPago.Columns.Add("ReferenciaPago", GetType(String)) + DtPago.Columns.Add("TipoPago", GetType(String)) + + DtPago.Columns.Add("Proveedor", GetType(String)) + DtPago.Columns.Add("Cuenta", GetType(String)) + DtPago.Columns.Add("Importe", GetType(Decimal)) + DtPago.Columns.Add("Moneda", GetType(String)) + DtPago.Columns.Add("Observaciones", GetType(String)) + + DtPago.Columns.Add("FechaOperacion", GetType(String)) + + End Sub + + + Protected Sub BtnCargarPago_Click(sender As Object, e As System.EventArgs) + Dim ErrorArchivo = False + Dim TextoErrorArchivo = "Ocurrió un problema al leer el archivo, por favor revise que el archivo sea el correcto e intente de nuevo." + + If FUTxt.HasFile Then + If Not GuardaTXT() Then + Alert("Ocurrio un error al cargar el archivo", TipoMensaje.MsgError) + Exit Sub + End If + Else + Alert("No tiene ningun archivo", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + + 'LEE TXT + Dim Texto As String + Dim sr As New System.IO.StreamReader(NombreArchivo) + Texto = sr.ReadToEnd() + sr.Close() + Dim TextoArreglo() = Texto.Split(CChar(vbCrLf)) + + 'INICIALIZA VARIABLES + Dim ObjBancos As New ClsBancos + Dim RespuestaHeader = "", RespuestaDetalle = "", RespuestaTrailer = "", Proveedor = "", CuentaAbono = "", Estatus = "", CveIEs = "", EstatusIEs = "", FechaMovto = "", Correos = "" + Dim Row As DataRow = Nothing + Dim Convenio = "" + CreaDtPago() + + 'LEE LINEA POR LINEA + For i = 0 To TextoArreglo.Length - 1 + 'Valida que el primer renglon sea el HEADER + If i = 0 Then + If TextoArreglo(i).Substring(0, 1) <> "H" Then + ErrorArchivo = True + Exit For + Else + ' Codigo de respuesta | Cuenta cargo + RespuestaHeader = String.Format("{0}|{1}", TextoArreglo(i).Substring(52, 2), TextoArreglo(i).Substring(77, 35)) + Convenio = TextoArreglo(i).Substring(2, 9) + End If + Else + If TextoArreglo(i).Length > 1 Then + + 'LEE DETALLE + If TextoArreglo(i).Substring(1, 1) = "D" Then + If i > 1 Then + RespuestaDetalle += vbCrLf + End If + + 'TRUENA PORQUE AHORA ES LA CVECUENTADEPOSITO + 'Proveedor = GlobalDTCompProveedores(UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CveProveedor = {0}", TextoArreglo(i).Substring(24, 30).ToEntero)).Rows(0)("RazonSocial").ToString + + Correos += If(Correos <> "", "|", "") + + If ObjBancos.GetProveedorCuentaDeposito(TextoArreglo(i).Substring(24, 30).ToDouble.ToEntero) Then + If ObjBancos.DtResultados.Rows.Count > 0 Then + + Proveedor = ObjBancos.DtResultados.Rows(0)("RazonSocial").ToString + + 'Correos += If(TextoArreglo(i).Substring(477, 50).Trim = "", "-1", TextoArreglo(i).Substring(477, 50).Trim) + Correos += String.Format("{0};{1}", ObjBancos.DtResultados.Rows(0)("NotificarA").ToString, ObjBancos.DtResultados.Rows(0)("ContactoMailCobranza").ToString) + + + ''SELECCIONA CUENTA ABONO PARA CORREO + Select Case TextoArreglo(i).Substring(57, 1).ToEntero + Case 1 + CuentaAbono = "NO APLICA" + Case 2 + CuentaAbono = If(ObjBancos.DtResultados.Rows(0)("Cuenta").ToString <> "", ObjBancos.DtResultados.Rows(0)("Cuenta").ToString, ObjBancos.DtResultados.Rows(0)("CLABE").ToString) + Case 3 + CuentaAbono = ObjBancos.DtResultados.Rows(0)("CIE").ToString + Case 4 + CuentaAbono = ObjBancos.DtResultados.Rows(0)("SWIFT").ToString + Case 5, 6, 7 + CuentaAbono = ObjBancos.DtResultados.Rows(0)("CLABE").ToString + End Select + + Else + Proveedor = "PROVEEDOR NO ENCONTRADO" + End If + Else + Proveedor = "PROVEEDOR NO ENCONTRADO" + End If + + Estatus = If(TextoArreglo(i).Substring(1325, 2) = "00", "OPERACION EXITOSA: ", "OPERACION FALLIDA: ") + ' Proveedor | Importe | Descripcion estatus + RespuestaDetalle += String.Format("{0}{1}.{2} {5}{3}{4}", Proveedor, TextoArreglo(i).Substring(445, 13).ToDouble.ToEntero, TextoArreglo(i).Substring(458, 2).ToEntero, Estatus, TextoArreglo(i).Substring(1327, 30), TextoArreglo(i).Substring(420, 3)) + + ''Guardo CveIE cuando la operacion salio exitosa para actualizar en la DB el IE + 'If TextoArreglo(i).Substring(1325, 2) = "00" Then + CveIEs += If(CveIEs <> "", ",", "") + 'VIEJO IE EN CAMPO 9 + 'CveIEs += TextoArreglo(i).Substring(83, 10).Trim + CveIEs += TextoArreglo(i).Substring(123, 32).Trim + + 'SI VIENE SIN RESPUESTA ES ERROR DE ARCHIVO + If TextoArreglo(i).Substring(1325, 2).Trim = "" Then + ErrorArchivo = True + TextoErrorArchivo = "El archivo que se intento procesar no es de respuesta. Por favor verifique cargar el archivo correcto." + Exit For + End If + + EstatusIEs += If(EstatusIEs <> "", ",", "") + EstatusIEs += If(TextoArreglo(i).Substring(1325, 2) = "00", "2", "3") + + FechaMovto += If(FechaMovto <> "", ",", "") + FechaMovto += TextoArreglo(i).Substring(540, 10) + + 'If Proveedor = "PROVEEDOR NO ENCONTRADO" Or CuentaAbono = "" Then + ' Continue For + 'End If + + + ''LLENA DTPAGOS PARA CORREO + Row = DtPago.NewRow() + Row("NumeroConvenio") = Convenio + Row("ClaveProveedor") = TextoArreglo(i).Substring(24, 30) + Row("Proveedor") = Proveedor + Row("ReferenciaPago") = TextoArreglo(i).Substring(4, 20) + Row("Cuenta") = CuentaAbono + + Select Case TextoArreglo(i).Substring(57, 1).ToEntero + Case 1 + Row("TipoPago") = "1 .- ABONO EN VENTANILLA" + Case 2 + Row("TipoPago") = "2 .- ABONO A CUENTAS BANCOMER" + Case 3 + Row("TipoPago") = "3 .- ABONO A CONVENIO CIE" + Case 4 + Row("TipoPago") = "4 .- ABONO A CUENTA INTERNACIONAL VIA SWIFT" + Case 5 + Row("TipoPago") = "5 .- ABONO A CUENTA INTERBANCARIA DIA SIGUIENTE" + Case 6 + Row("TipoPago") = "6 .- ABONO A CUENTA INTERBANCARIA MISMO DIA" + Case 7 + Row("TipoPago") = "7 .- ABONO A CUENTA INTERNACIONAL VIA ACH" + End Select + + Try + Row("Cuenta") = If(Row("Cuenta").ToString = "", String.Format("******{0}", CuentaAbono.Substring(CuentaAbono.Length - 4, 4)), Row("Cuenta").ToString) + Catch ex As Exception + Row("Cuenta") = "******" + End Try + + Row("Importe") = String.Format("{0}.{1}", TextoArreglo(i).Substring(445, 13), TextoArreglo(i).Substring(458, 2)).ToDecimal.ToString + Row("FechaOperacion") = TextoArreglo(i).Substring(540, 10) + Row("Observaciones") = TextoArreglo(i).Substring(605, 700).Trim + DtPago.Rows.Add(Row) + + 'End If + + 'LEE TRAILER + ElseIf TextoArreglo(i).Substring(1, 1) = "T" Then + + 'PARA BCOM, YA QUE TRUNCA EL STRING CUANDO SOLO ES MXP + If TextoArreglo(i).Length < 1367 Then + TextoArreglo(i) = TextoArreglo(i).PadRight(1367) + End If + + RespuestaTrailer += "------------------------------------------------------------ RESUMEN ------------------------------------------------------------" + RespuestaTrailer += String.Format("") + RespuestaTrailer += String.Format("", TextoArreglo(i).Substring(77, 10).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(327, 10).ToDouble.ToEntero.ToString) + RespuestaTrailer += String.Format("", TextoArreglo(i).Substring(87, 13).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(100, 2).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(337, 13).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(350, 2).ToDouble.ToEntero.ToString) + RespuestaTrailer += String.Format("", TextoArreglo(i).Substring(177, 10).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(302, 10).ToDouble.ToEntero.ToString) + RespuestaTrailer += String.Format("
    ConceptoPesos (MXP)Dolares (USD)
    Total registros rechazados:{0}{1}
    Total Importe rechazado: $:{0}.{1}{2}.{3}
    Total registros aceptados:{0}{1}
    Total Importe aceptado $:{0}.{1}{2}.{3}
    ", TextoArreglo(i).Substring(187, 13).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(200, 2).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(312, 13).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(325, 2).ToDouble.ToEntero.ToString) + + 'RespuestaTrailer += String.Format("Total registros rechazados: {1}{0} Total Importe rechazado: $ {2}.{3}{0} Total registros aceptados: {4}{0} Total Importe aceptado: $ {5}.{6}{0}", "
    ", TextoArreglo(i).Substring(77, 10).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(87, 13).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(100, 2).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(177, 10).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(187, 13).ToDouble.ToEntero.ToString, TextoArreglo(i).Substring(200, 2).ToEntero.ToString) + Else + ErrorArchivo = True + Exit For + End If + End If + End If + Next + + ObjBancos.Dispose() + + Dim Respuesta As New StringBuilder + If Not ErrorArchivo Then + + 'DIVIDE HEADER + Dim Header() = RespuestaHeader.Split(CChar("|")) + 'TRADUCE CODIGO RESPUESTA HEADER + If Header(0) = "01" Then + RespuestaHeader = "ACEPTADO TOTAL" + ElseIf Header(0) = "02" Then + RespuestaHeader = "ACEPTADO PARCIAL" + ElseIf Header(0) = "03" Then + RespuestaHeader = "RECHAZADO" + End If + RespuestaHeader += String.Format("
    Cuenta Cargo: {0}", Header(1)) + + 'DIVIDE DETALLE + Dim Detalle() = RespuestaDetalle.Split(CChar(vbCrLf)) + + 'ARMADO DE RESPUESTA + Respuesta.AppendFormat("
    Resumen de respuesta: {0}
    ", RespuestaHeader) + Respuesta.AppendFormat("Numero de movimientos: {0}

    ", Detalle.Length.ToString) + Respuesta.Append("----------------------------------------------------- Detalle de los movimientos --------------------------------------------------
    ") + Respuesta.Append("") + For i = 0 To Detalle.Length - 1 + Respuesta.AppendFormat("{1}", i + 1, Detalle(i).Trim) + Next + Respuesta.Append("
    #ProveedorImporte($)MonedaEstatus
    {0}
    ----------------------------------------------------------------------------------------------------------------------
    ") + Respuesta.AppendFormat(RespuestaTrailer) + + + End If + + If Not ErrorArchivo Then + If CveIEs <> "" Then + Dim ObjIE As New ClsBancos + Dim ErrorDB = False + ObjIE.IniciaTransacSQL() + Dim ArrayCveIEs() = CveIEs.Split(","c) + Dim ArrayEstatusIEs() = EstatusIEs.Split(","c) + Dim ArrayFechasMovto() = FechaMovto.Split(","c) + Dim ArrayCorreos() = Correos.Split("|"c) + + Dim ArregloHilos As New Generic.List(Of System.Threading.Thread) + Dim ArregloParametros As New Generic.List(Of List(Of String)) + + For index = 0 To ArrayCveIEs.Length - 1 + If ObjIE.UpdatePagoElectronicoCarga(ArrayCveIEs(index).ToEntero, ArrayEstatusIEs(index).ToEntero) Then + + 'Cuando salio exitoso actualizamos el IE + If ArrayEstatusIEs(index).ToEntero = 2 Then + If ObjIE.UpdateIEPagoElectronico(ArrayCveIEs(index).ToEntero, ArrayFechasMovto(index).ToDate, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) Then 'DESPROGRAMA LAS COMPRAS RELACIONADAS EN ESTE PA + + 'Cambiamos estatus notificación + If ObjIE.UpdateBancos_IENotificaciones(2, "-1", "-1", ArrayCveIEs(index).ToEntero) Then + + 'Obtenemos los correos del movimiento + If ArrayCorreos(index) <> "-1" Or ArrayCorreos(index) <> "" Then + + 'Dim CorreosMovto() = ArrayCorreos(index).Split(";"c) + 'For index2 = 0 To CorreosMovto.Length - 1 + ' If CorreosMovto(index2).Length > 5 Then + ' End If + 'Next + + Dim Param As New List(Of String) + + Param.Add(ArrayCorreos(index)) 'Para + Param.Add("Notificación de Pago") 'Asunto + Param.Add(GeneraCorreo2(DtPago.Rows(index), ObjIE, ArrayCveIEs(index).ToEntero)) 'Body + + Dim Hilo As New Threading.Thread(AddressOf MandaCorreo) + ArregloHilos.Add(Hilo) + ArregloParametros.Add(Param) + End If + Else + ErrorDB = True + End If + + Else + ErrorDB = True + End If + Else + + 'Cuando salio NO exitoso cancelamos el IE + If Not ObjIE.CancelarBancos_IE(UsuarioActual.CveUsuario, ArrayCveIEs(index).ToEntero, False, -1, -1) Then + ErrorDB = True + End If + End If + + Else + ErrorDB = True + End If + Next + + If Not ErrorDB Then + ObjIE.Commit() + 'ObjIE.RollBack() + + 'EMPIEZA A ENVIAR CORREO POR HILOS + For index = 0 To ArregloHilos.Count - 1 + ArregloHilos(index).Start(ArregloParametros(index)) + Next + + Respuesta.Append("

    NOTA: El archivo se analizo correctamente y se efectuaron todos los cambios en el sistema.") + Alert(Respuesta.ToString, TipoMensaje.MsgInformacion) + + CargaDatos() + Else + ObjIE.RollBack() + Respuesta.Append("

    NOTA: El archivo se analizo correctamente pero ocurrió un problema al efectuar los cambios en el sistema. Por favor vuelva a intentar.") + Alert(Respuesta.ToString, TipoMensaje.MsgError) + End If + + ObjIE.Dispose() + Else + Respuesta.AppendFormat("

    NOTA: El archivo se analizo correctamente pero ningun movimiento fue exitoso.") + Alert(Respuesta.ToString, TipoMensaje.MsgAdvertencia) + End If + Else + Alert(TextoErrorArchivo, TipoMensaje.MsgError) + End If + + 'ELIMINA TXT + My.Computer.FileSystem.DeleteFile(NombreArchivo) + + RecargaDatos() + + End Sub +#End Region + + + + 'FUNCIONARIO O EMPLEADO +#Region " ALTA FUNCIONARIO " + Private Sub CargaFyE() + Dim ObjBancos As New ClsBancos + + If ObjBancos.GetLayoutFyE(DdlCuenta.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then + DTFyE = ObjBancos.DtResultados.FiltraParametros("LEN(RFC) IN (13)") + Else + DTFyE = Nothing + End If + ObjBancos.Dispose() + + If DTFyE.Rows.Count > 0 Then + GvProveedores.DataSource = DTFyE + End If + GvProveedores.DataBind() + + UpProveedores.Update() + End Sub + Private Sub GeneraAltaFyE() + Dim DtTemp As DataTable = Nothing + + 'REINICIA PROPIEDAS + HeaderTexto = "" + DetalleTexto = "" + TrailerTexto = "" + TotalAcumulado = 0 + CreaDtAlta() + + DtTemp = DTFyE + + ''VALIDA CUENTAS DEPOSITOS + Dim ErrorCuenta = False + Dim FyEError As StringBuilder = New StringBuilder + FyEError.AppendFormat("") + + Dim TotalDetalles As Integer = 0 + Dim EsBancomer = False + For Each gvr As DataRow In DtTemp.Rows + If gvr("CvePersonal").ToString <> "" AndAlso gvr("EstatusPagoElectronico").ToString <> "True" AndAlso gvr("AltaCuenta").ToString = "1" Then + DTPendienteActual = DtTemp.FiltraParametros(String.Format("CveCuentaDeposito = {0}", gvr("CveCuentaDeposito").ToString)) + ErrorCuenta = False + EsBancomer = False + + If DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BBVA") Or DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BANCOMER") Or (DTPendienteActual(0)("CLABE").ToString.Length = 18 AndAlso DTPendienteActual(0)("CLABE").ToString.Substring(0, 3) = "012") Then + EsBancomer = True + End If + + 'CLABE SIEMPRE OBLIGATORIA SI NO ES BANCOMER + If Not ErrorCuenta Then + If DTPendienteActual(0)("CLABE").ToString.Trim.Length <> 18 And DTPendienteActual(0)("CLABE").ToString.Trim.Length = 0 And Not EsBancomer Then + FyEError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + 'SI CUENTA TIENE ALGO Y BANCO BANCOMER DEBE TENER UNA LOGITUD EXACTA DE 10 + If Not ErrorCuenta Then + If DTPendienteActual(0)("Cuenta").ToString.Trim.Length <> 0 AndAlso DTPendienteActual(0)("Cuenta").ToString.Trim.Length <> 10 AndAlso EsBancomer Then + FyEError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + 'SI CLABE TIENE ALGO DEBE TENER UNA LOGITUD EXACTA DE 18 + If Not ErrorCuenta Then + If DTPendienteActual(0)("CLABE").ToString.Trim.Length <> 0 AndAlso DTPendienteActual(0)("CLABE").ToString.Trim.Length <> 18 Then + FyEError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + 'SI CIE TIENE ALGO DEBE TENER REFERENCIA OBLIGATORIA + If Not ErrorCuenta Then + If DTPendienteActual(0)("CIE").ToString.Trim.Length <> 0 And DTPendienteActual(0)("Referencia").ToString.Trim.Length < 3 Then + FyEError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + 'CUANDO SEA "BBVA" O "BANCOMER" DEBE TENER "CIE" O "CUENTA" + If Not ErrorCuenta Then + If EsBancomer AndAlso Not (DTPendienteActual(0)("Cuenta").ToString.Trim.Length = 10 Or DTPendienteActual(0)("CIE").ToString.Trim.Length <> 0) Then + FyEError.AppendFormat("", DTPendienteActual(0)("RazonSocial").ToString, DTPendienteActual(0)("BancoNombre").ToString) + ErrorCuenta = True + End If + End If + + If Not ErrorCuenta Then + If TotalDetalles > 0 Then + DetalleTexto &= vbCrLf + End If + GeneraAltaDetalleFyE() + TotalDetalles += 1 + End If + + End If + Next + FyEError.AppendFormat("
    PersonalCuentaError
    {0}{1}CLABE ES OBLIGATORIA
    {0}{1}NUMERO DE CUENTA CON FORMATO INCORRECTO
    {0}{1}CLABE CON FORMATO INCORRECTO
    {0}{1}CIE CON FORMATO INCORRECTO
    {0}{1}CUENTA BANCOMER SIN CUENTA O CIE
    ") + + + If TotalDetalles > 0 Then + FormarTextoAltaFyE(TotalDetalles) + CreaArchivo(2) + + Dim Descargas As New StringBuilder() + Descargas.AppendFormat("
  • TXT
  • ", NombreArchivo) + 'Descargas.AppendFormat("
  • Reporte
  • ", NombreArchivo) + Descargas.AppendFormat("
  • Descargar Reporte
  • ", NombreArchivo) + + + Dim TextoErrorProveedores = "" + If FyEError.Length > 160 Then TextoErrorProveedores = String.Format("


    Proveedores con Error:

    ------------------------------------------------------------------
    {0}

    ", FyEError.ToString) + + Alert(String.Format("
    El Layout fue creado satisfactoriamente.{1}
    Descargas:
      {0}
    ", Descargas, TextoErrorProveedores), TipoMensaje.MsgInformacion) + + 'NombreArchivo = "LayoutAltaProveedores" + 'DescargarArchivo() + Else + Alert("No hay proveedores que dar de alta", TipoMensaje.MsgInformacion) + End If + + + End Sub + Private Sub GeneraAltaDetalleFyE() + Dim Resultado = True + Dim CuentaDeposito As String = "" + Dim TipoCuentaDeposito As String = "" + Dim TipoCuenta As String = "" + + ''''' LLENADO DE DETALLE + 'Campos #1-4 del Detalle + DetalleTexto &= String.Format("DA{0}N ", DTPendienteActual(0)("CveCuentaDeposito").ToString.ToUpper.PadLeft(30, PadCeros)) + + 'Banco BBVA + If DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BBVA") Or DTPendienteActual(0)("BancoNombre").ToString.ToUpper.Contains("BANCOMER") Then + 'Llenamos datos de BBVA + 'Campo #5-7 del detalle + + 'Busca que cuenta sera la asignada para el proveedor + If DTPendienteActual(0)("CIE").ToString <> "" Then + CuentaDeposito = String.Format("02{0}", DTPendienteActual(0)("CIE").ToString.PadLeft(8, PadCeros)) + TipoCuenta = "50" + TipoCuentaDeposito = "CIE" + ElseIf DTPendienteActual(0)("Cuenta").ToString.Length = 10 Then + CuentaDeposito = DTPendienteActual(0)("Cuenta").ToString + TipoCuenta = "99" + TipoCuentaDeposito = "Cuenta" + ElseIf DTPendienteActual(0)("CLABE").ToString.Length = 18 Then + CuentaDeposito = DTPendienteActual(0)("CLABE").ToString + TipoCuenta = "40" + TipoCuentaDeposito = "CLABE" + End If + + + DetalleTexto &= String.Format("{0}{1}{2}", DTPendienteActual(0)("Abreviatura").ToString, TipoCuenta, CuentaDeposito.PadLeft(35, PadCeros)) + + 'Llenamos en blanco datos de otros bancos + 'Campos 8-17 del detalle --- 64 de otros bancos y 45 para FILLER --- Fecha de Alta + DetalleTexto &= String.Format("{0}{1}", Vacio.PadLeft(109), DateTime.Now().ToString("yyyy-MM-dd")) + + + 'Otros Bancos NACIONAL!! + Else + + CuentaDeposito = DTPendienteActual(0)("CLABE").ToString + TipoCuentaDeposito = "CLABE" + + 'Llenamos en blanco datos de BBVA + DetalleTexto &= Vacio.PadRight(40) + + 'Llenamos datos de otros bancos + 'Campos 8- 17 del detalle --- 44 de otros bancos --- 20 de internacional --- 45 Filler -- Fecha de Alta + DetalleTexto &= String.Format("{0}40{1}{2}{3}{4}{5}", DTPendienteActual(0)("Abreviatura").ToString, DTPendienteActual(0)("CLABE").ToString.PadLeft(35, PadCeros), DTPendienteActual(0)("CLABE").ToString.Substring(0, 3).PadLeft(4, PadCeros), Vacio.PadRight(20), Vacio.PadRight(45), DateTime.Now().ToString("yyyy-MM-dd")) + End If + + 'Llenamos datos de Tipo de Persona - Fisica + ' nombres Primer apellido Segundo apellido + DetalleTexto &= String.Format("F{0}{1}{2}{3}", Vacio.PadRight(70), DTPendienteActual(0)("Nombres").ToString.PadRight(20).Substring(0, 20), DTPendienteActual(0)("APaterno").ToString.PadRight(20).Substring(0, 20), DTPendienteActual(0)("AMaterno").ToString.PadRight(20).Substring(0, 20)) + + 'Campo 25-26 del detalle -- Fecha Nacimiento -- RFC + DetalleTexto &= String.Format("{0}{1}", DTPendienteActual(0)("FechaNacimiento").ToString.ToDate.ToString("yyyy-MM-dd"), DTPendienteActual(0)("RFC").ToString.ToUpper.PadRight(14)) + + 'Campos 27-32 --- Fillers --- datos de otros bancos (internacional) + DetalleTexto &= Vacio.PadLeft(153) + + 'Campos 33-36 --- Datos de confirmacion + DetalleTexto &= String.Format("{0}02{1}", Vacio.PadRight(40), CorreoNotificacionesEmpresa.ToUpper.PadRight(50)) + + 'If DTPendienteActual(0)("ContactoMail").ToString.Length > 0 Then + ' 'DetalleTexto &= String.Format("{0}02{1}", Vacio.PadRight(40), DTPendienteActual(0)("ContactoMail").ToString.ToUpper.PadRight(50)) + 'ElseIf DTPendienteActual(0)("ContactoMail").ToString.Length <= 0 Then + ' DetalleTexto &= String.Format("{0}00{1}", Vacio.PadRight(40), Vacio.PadRight(50)) + 'End If + + 'Campos 37-39 -- FILLER + DetalleTexto &= String.Format("00{0}", Vacio.PadRight(38)) + + + ''LLENA DT PARA REPORTE + Dim Row = DtAlta.NewRow() + Row("Proveedor") = DTPendienteActual(0)("RazonSocial").ToString + Row("Banco") = DTPendienteActual(0)("BancoNombre").ToString + Row("TipoCuenta") = TipoCuentaDeposito + Row("Cuenta") = String.Format("{0}", CuentaDeposito) + DtAlta.Rows.Add(Row) + End Sub + Protected Sub FormarTextoAltaFyE(Registros As Integer) + '''''' LLENADO HEADER + Dim convenio As String = DTPendienteActual(0)("ConvenioPagoElectronico").ToString + 'Campos #1-4 del Header + HeaderTexto = String.Format("H{0}{1}GRUPO01 ", convenio.PadLeft(9, PadCeros), DateTime.Now().ToString("yyyy-MM-dd")) + 'Campo #5 del Header + HeaderTexto &= String.Format("{0}{1}", UsuarioActual.CveUsuario, DateTime.Now().ToString("yyyyMMdd")).PadRight(20) + 'Campos #6-8 del Header + HeaderTexto &= String.Format("00").PadRight(586) + Dim HeaderLength = HeaderTexto.Length + + ''''' LLENADO DE TRAILER + TrailerTexto = String.Format("T{0}{1}{2}", Registros.ToString.PadLeft(10, PadCeros), Vacio.PadRight(50, PadCeros), Vacio.PadRight(575)) + + ''''' ARMADO DEL TEXTO COMPLETO + TextoCompleto = String.Format("{1}{0}{2}{0}{3}{0}", vbCrLf, HeaderTexto, DetalleTexto, TrailerTexto) + 'TxtAltas.Text = TextoCompleto + End Sub +#End Region + + + + 'TABS +#Region "R E P O R T E S" + Protected Sub BtnConsultarReportes_Click(sender As Object, e As EventArgs) + CargaReporte() + End Sub + + Private Sub CargaReporte() + Dim ObjBancos As New ClsBancos + Dim FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim(), "-1") + Dim FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim(), "-1") + + If ObjBancos.GetLayoutPagosEnviados(DdlCuentaReportes.SelectedValue.ToEntero, DdlEstatus.SelectedValue.ToEntero, DdlTipoReportes.SelectedValue, FechaI, DateAdd(DateInterval.Day, 1, FechaF.ToDate).ToShortDateString) Then + DTReportes = ObjBancos.DtResultados + Else + DTReportes = Nothing + End If + ObjBancos.Dispose() + + If DTReportes.Rows.Count > 0 Then + GvReportes.DataSource = DTReportes + End If + GvReportes.DataBind() + + UpDatosReportes.Update() + + End Sub + + Protected Sub GvReportes_RowDataBound(sender As Object, e As GridViewRowEventArgs) + If e.Row.RowType = DataControlRowType.DataRow Then + + 'Colorea GV + If e.Row.DBCampo("CveProveedor").ToString = "" Then + e.Row.BackColor = Drawing.Color.LightGray + Else + e.Row.FCHyperLink("HLProveedor").NavigateUrl = String.Format("/Compras/Proveedores.aspx?CveProveedor={0}", e.Row.DBCampo("CveProveedor")) + End If + End If + End Sub + + +#End Region + + +#Region "C A R G A - M A S I V A" + Protected Sub BtnCargaMasiva_Click(sender As Object, e As EventArgs) + If DdlTipoCargaMasiva.SelectedValue.ToEntero = 1 Then + TipoMasiva = 1 + GvProveedores.Columns(0).HeaderText = "Proveedor" + CargaProveedores() + BtnGenerarProveedores.Text = "Generar Layout Alta Proveedores" + Else + TipoMasiva = 2 + GvProveedores.Columns(0).HeaderText = "Funcionario" + CargaFyE() + BtnGenerarProveedores.Text = "Generar Layout Alta Funcionarios" + End If + End Sub + Protected Sub BtnGenerarProveedores_Click(sender As Object, e As EventArgs) + + If Not DdlCuenta.SelectedValue.ToEntero > 0 Then + Alert("Primero debe seleccionar una Cuenta", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If TipoMasiva = 1 Then + AltaProveedores(2) + Else + GeneraAltaFyE() + End If + + End Sub + Private Sub CargaProveedores() + Dim ObjBancos As New ClsBancos + + If ObjBancos.GetLayoutProveedores(DdlCuenta.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then + DTProveedores = ObjBancos.DtResultados.FiltraParametros("LEN(RFC) IN (12,13)") + Else + DTProveedores = Nothing + End If + ObjBancos.Dispose() + + If DTProveedores.Rows.Count > 0 Then + GvProveedores.DataSource = DTProveedores + End If + GvProveedores.DataBind() + + UpProveedores.Update() + End Sub + Protected Sub GvProveedores_RowDataBound(sender As Object, e As GridViewRowEventArgs) + If e.Row.RowType = DataControlRowType.DataRow Then + If TipoMasiva = 1 Then + e.Row.FCHyperLink("HLProveedor").NavigateUrl = String.Format("/Compras/Proveedores.aspx?CveProveedor={0}", e.Row.DBCampo("CveProveedor")) + Else + e.Row.FCHyperLink("HLProveedor").NavigateUrl = String.Format("/RH/Personal.aspx?CvePersonal={0}", e.Row.DBCampo("CvePersonal")) + End If + End If + + + + End Sub +#End Region + + + + 'CORREO +#Region " GENERA Y MANDA CORREO " + Private Sub MandaCorreo(data As Object) + Dim Parametros As List(Of String) = DirectCast(data, List(Of String)) + + Dim Mail As New ClsSisMail() + Dim Para As String = Parametros(0) + Dim Asunto As String = Parametros(1) + Dim Body As String = Parametros(2) + + 'NO SE OCUPAN + 'Dim CveIE As Integer = Parametros(3).ToEntero + 'Dim CveTipoTransaccion As Integer = Parametros(4).ToEntero + 'Dim Estatus As Integer = If(CveTipoTransaccion = 2, 2, 1) ' cuando es transferencia, no lo pasa por entregar + + ' Mail.MandaCorreo(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body) + Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body) + End Sub + + Private Function GeneraCorreo(CveIE As Integer, objIE As ClsBancos) As String + Dim strBody As New StringBuilder + + If objIE.GetBancosIE(CveIE, UsuarioActual.CveEmpresa) Then + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.AppendFormat("
    ") + strBody.AppendFormat("
    ") + strBody.AppendFormat(" {0}", UsuarioActual.Empresa.Empresa) + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", UsuarioActual.Empresa.Direccion) + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", UsuarioActual.Empresa.Colonia) + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", UsuarioActual.Empresa.Ciudad, UsuarioActual.Empresa.Estado, UsuarioActual.Empresa.CP) + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", UsuarioActual.Empresa.RFC) + strBody.AppendFormat(" ") + strBody.AppendFormat("
    {0}
    Col. {0}
    {0}, {1}, C.P.{2}
    RFC {0}
    ") + strBody.AppendFormat("
    ") + strBody.AppendFormat("


    ") + + strBody.AppendFormat("
    ") + strBody.AppendFormat("
    ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + + If objIE.CveTipoTransaccion = 1 Then ' cuando es cheque + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + End If + + If objIE.CveTipoTransaccion = 2 Then ' cuando es transf + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + End If + + strBody.Append(" ") + strBody.AppendFormat(" ") + strBody.Append(" ") + strBody.Append("
    Usted puede pasar a recorger el cheque en las oficinas administrativas.
    Se notifica el envío de transferencia de pago.
     
    ") + strBody.Append("
    ") + + + strBody.AppendFormat("
    ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat("
    ") + strBody.AppendFormat("
    ") + strBody.AppendFormat(" Beneficiario:{0} ", objIE.PagueseA) + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", objIE.Banco) + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", objIE.FechaDocumento.ToString("dd/MM/yyyy")) + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", objIE.Importe.FormatoNumero, objIE.Moneda) + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ", objIE.Observaciones) + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat(" ") + strBody.AppendFormat("
    Movimiento:Transferencia Bancaria
    Banco:{0}
    Fecha:{0}
    Importe:$ {0} {1}
    Observaciones:{0}
    ") + strBody.AppendFormat("
    ") + strBody.AppendFormat("
    ") + strBody.AppendFormat("
    ") + strBody.AppendFormat("
    ") + strBody.AppendFormat("
    ") + + + + strBody.Append("
    Favor de no responder a este correo.
    ") + + strBody.Append("") + End If + + Return strBody.ToString + End Function +#End Region + +#Region " GENERA CORREO 2" + + Private Function GeneraCorreo2(Dr As DataRow, ByRef ObjIE As ClsBancos, CveIE As Integer) As String + Dim strBody As New StringBuilder + + + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append("
    ") + strBody.Append("

    ") + + + 'strBody.Append(" De: Bancomer.com [mailto:alertatdu@serviciobancomer.com]
    ") + + strBody.Append("

    ") + strBody.AppendFormat(" ", UrlSitio) + strBody.Append("
    ") + + + strBody.AppendFormat(" Enviado el: {0} {1}
    ", Date.Now.ToLongDateString, Date.Now.ToShortTimeString) + strBody.AppendFormat(" Para:{0}
    ", If(UsuarioActual.CveEmpresa = 66, "PAGOS@GLUYASCONSTRUCCIONES.COM", "")) + strBody.Append(" Asunto: CONFIRMACION SIT DISPERSION ") + strBody.Append("

    ") + strBody.Append("

    ") + strBody.Append("   ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" ", UrlSitio) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append("   ") + strBody.Append("

    ") + strBody.Append("

    ") + strBody.Append(" Confirmación de pago realizado bajo las siguientes condiciones: ") + strBody.Append("

    ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append("
    ") + strBody.Append(" ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" NOMBRE DEL CLIENTE: ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" {0} ", UsuarioActual.Empresa.Empresa) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" NÚMERO DE CONVENIO: ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" {0} ", Dr("NumeroConvenio").ToString) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" CLAVE DEL PROVEEDOR: ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" {0} ", Dr("ClaveProveedor").ToString) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" NOMBRE DEL PROVEEDOR/TERCERO: ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" {0} ", Dr("Proveedor").ToString) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" REFERENCIA DEL PAGO: ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" {0} ", Dr("ReferenciaPago").ToString) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" TIPO DE PAGO: ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" {0} ", Dr("TipoPago").ToString) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" CUENTA DE ABONO: ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" {0} ", Dr("Cuenta").ToString) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" IMPORTE DEL PAGO: ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" ${0}  ", Dr("Importe").ToString.FormatoNumero) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" FECHA DE OPERACIÓN ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" {0} ", Dr("FechaOperacion").ToString) + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.Append(" MENSAJE ADICIONAL: ") + strBody.Append("

    ") + strBody.Append("
    ") + strBody.Append("

    ") + strBody.AppendFormat(" {0} ", Dr("Observaciones").ToString.PadRight(70, " "c).Replace(" ", " ")) + strBody.Append("

    ") + strBody.Append("
    ") + + + + strBody.Append("
    ") + strBody.AppendFormat(" ", UrlSitio) + strBody.Append("
    ") + + + + strBody.Append("

    ") + strBody.Append("   ") + strBody.Append("

    ") + strBody.Append("

    ") + strBody.Append("   ") + strBody.Append("

    ") + strBody.Append("

    ") + strBody.Append("   ") + strBody.Append("

    ") + strBody.Append("

    ") + strBody.Append("   ") + strBody.Append("

    ") + strBody.Append("

    ") + strBody.Append("   ") + strBody.Append("

    ") + + + If ObjIE.GetBancosIE(CveIE, UsuarioActual.CveEmpresa) Then + If ObjIE.DtResultados.Rows.Count > 0 Then + Dim dtMovs As DataTable + + Dim Mov As New ClsContabilidad + If Mov.GetPrePolizasDetalle(-1, CveIE) Then + dtMovs = Mov.DtResultados.FiltraParametros("CveConceptoContable IN (17)") + + strBody.Append(" ") + strBody.Append(" ") + + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + strBody.Append(" ") + + For Each Dr2 As DataRow In dtMovs.Rows + strBody.Append(" ") + strBody.Append($" ") + strBody.Append($" ") + strBody.Append($" ") + strBody.Append($" ") + strBody.Append($" ") + strBody.Append($" ") + strBody.Append(" ") + Next + + strBody.Append(" ") + strBody.Append("
    Listado de facturas pagadas
    Factura ") + strBody.Append(" Fecha ") + strBody.Append(" Original ") + strBody.Append(" Abonado ") + strBody.Append(" Nota Crédito ") + strBody.Append(" Saldo ") + strBody.Append("
    {Dr2("SerieFolio")}{Dr2("FechaCompra").ToString.ToDate.ToShortDateString}{Dr2("Total").ToString.ToDouble.FormatoNumero}{Dr2("Importe").ToString.ToDouble.FormatoNumero}{Dr2("ImporteNC").ToString.ToDouble.FormatoNumero}{Dr2("Saldo").ToString.ToDouble.FormatoNumero}
    ") + + strBody.Append("
    ") + strBody.Append(" ") + strBody.Append(" ") + + End If + Mov.Dispose() + + End If + End If + + Return strBody.ToString + End Function +#End Region + + + +#Region " IMPRIMIR " + Protected Sub BtnReporteAltaCarga_Click(sender As Object, e As EventArgs) + Dim Archivo As New System.IO.FileInfo(String.Format("{0}Formatos/LayoutAltaProveedor.rdlc", UsuarioActual.Empresa.Ruta)) + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + + + 'Estatus visible + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("MostrarEstatus", "True")) + + If Archivo.Exists Then + 'ImprimirPDF(UsuarioActual.Empresa.Ruta & "Formatos/LayoutAltaProveedor.rdlc", DtAlta, params, "LayoutAltaProveedor", RDSName:="DsPagoElectronico") + ImprimirPDF(String.Format("{0}Formatos\LayoutAltaProveedor.rdlc", UsuarioActual.Empresa.Ruta), DtAlta, params, "LayoutAltaProveedor", RDSName:="DsPagoElectronico") + Else + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + + + params.Add(New ReportParameter("Empresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("Direccion", UsuarioActual.Empresa.Direccion)) + params.Add(New ReportParameter("RFC", UsuarioActual.Empresa.RFC)) + params.Add(New ReportParameter("FechaImpresion", DateTime.Now.ToString("dd/MM/yyyy"))) + + + ImprimirPDF("Empresas/Grales/Formatos/LayoutAltaProveedor.rdlc", DtAlta, params, "LayoutAltaProveedor", RDSName:="DsPagoElectronico") + End If + End Sub + Protected Sub BtnReporteAltaGenera_Click(sender As Object, e As EventArgs) + Dim Archivo As New System.IO.FileInfo(String.Format("{0}Formatos/LayoutAltaProveedor.rdlc", UsuarioActual.Empresa.Ruta)) + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + + 'Estatus no visible + Dim params As New List(Of ReportParameter) + params.Add(New ReportParameter("MostrarEstatus", "False")) + + If Archivo.Exists Then + ImprimirPDF(String.Format("{0}Formatos\LayoutAltaProveedor.rdlc", UsuarioActual.Empresa.Ruta), DtAlta, params, "LayoutAltaProveedor", RDSName:="DsPagoElectronico") + Else + + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + + params.Add(New ReportParameter("Empresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("Direccion", UsuarioActual.Empresa.Direccion)) + params.Add(New ReportParameter("RFC", UsuarioActual.Empresa.RFC)) + params.Add(New ReportParameter("FechaImpresion", DateTime.Now.ToString("dd/MM/yyyy"))) + ImprimirPDF("Empresas/Grales/Formatos/LayoutAltaProveedor.rdlc", DtAlta, params, "LayoutAltaProveedor", RDSName:="DsPagoElectronico") + End If + + End Sub + Protected Sub BtnReportePago_Click(sender As Object, e As EventArgs) + Dim Archivo As New System.IO.FileInfo(String.Format("{0}Formatos/LayoutAltaProveedor.rdlc", UsuarioActual.Empresa.Ruta)) + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + + Dim params As New List(Of ReportParameter) + + + If Archivo.Exists Then + ImprimirPDF(String.Format("{0}Formatos\LayoutPagoProveedor.rdlc", UsuarioActual.Empresa.Ruta), DtPago, params, "LayoutPagoProveedor", RDSName:="DSPagoElectronicoV2") + Else + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + If Imagen.Exists Then + params.Add(New ReportParameter("LogoPath", logouri)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + + params.Add(New ReportParameter("Empresa", UsuarioActual.Empresa.Empresa)) + params.Add(New ReportParameter("Direccion", UsuarioActual.Empresa.Direccion)) + params.Add(New ReportParameter("RFC", UsuarioActual.Empresa.RFC)) + params.Add(New ReportParameter("FechaImpresion", DateTime.Now.ToString("dd/MM/yyyy"))) + ImprimirPDF("Empresas/Grales/Formatos/LayoutPagoProveedor.rdlc", DtPago, params, "LayoutPagoProveedor", RDSName:="DSPagoElectronicoV2") + End If + + End Sub +#End Region + + + 'NO QUITAR, SE OCUPA PARA EXPORTAR PDF + Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) + Return + End Sub + + + +End Class diff --git a/Bancos/ProveedoresAbonar.aspx.vb b/Bancos/ProveedoresAbonar.aspx.vb index bf0ac93bf..17bed395d 100644 --- a/Bancos/ProveedoresAbonar.aspx.vb +++ b/Bancos/ProveedoresAbonar.aspx.vb @@ -2389,6 +2389,10 @@ Partial Class Bancos_ProveedoresAbonar 'cuando es layout If tTipoTransaccion = 9 Then dt = dt.FiltraParametros("UsaLayout = 1") + End If + + If tTipoTransaccion = 17 Then + dt = dt.FiltraParametros("UsaLayoutGrupos = 1") End If DdlCuenta.DataSource = dt @@ -2462,7 +2466,8 @@ Partial Class Bancos_ProveedoresAbonar Dim Dep As New ClsGenerales If Dep.GetCuentasDepositos(CveProveedor:=CveProveedor) Then - If Dep.DtResultados.FiltraParametros("Estatus ='True'").Rows.Count > 0 Then + If Dep.DtResultados.FiltraParametros("Estatus ='True'").Rows.Count > 0 Then + If DdlTipoTransaccion.SelectedValue = "9" Then If Dep.DtResultados.Rows.Count > 0 Then @@ -2477,6 +2482,20 @@ Partial Class Bancos_ProveedoresAbonar Alert("El proveedor no tiene ninguna cuenta deposito registrada ante el sistema BBVA BANCOMER", TipoMensaje.MsgAdvertencia) End If + ElseIf DdlTipoTransaccion.SelectedValue = "17" Then + + If Dep.DtResultados.Rows.Count > 0 Then + DdlCuentaDeposito.DataSource = Dep.DtResultados.FiltraParametros("EstatusPagoElectronicoGrupos = 'True' AND Estatus ='True'") + End If + + If Dep.DtResultados.FiltraParametros("EstatusPagoElectronicoGrupos = 'True' AND Estatus ='True'").Rows.Count > 0 Then + trCuentaDeposito.Visible = True + DdlCuentaDeposito.Items.Insert(0, New ListItem("Seleccione una cuenta", "-1")) + Else + BtnIEGuardar.Enabled = False + Alert("El proveedor no tiene ninguna cuenta deposito registrada ante el sistema BBVA BANCOMER", TipoMensaje.MsgAdvertencia) + End If + Else DdlCuentaDeposito.DataSource = Dep.DtResultados.FiltraParametros("Estatus ='True'") If Dep.DtResultados.Rows.Count > 0 Then diff --git a/Compras/eFacturas.aspx b/Compras/eFacturas.aspx index dea3762d5..1dad856cc 100644 --- a/Compras/eFacturas.aspx +++ b/Compras/eFacturas.aspx @@ -554,7 +554,7 @@ diff --git a/Compras/eFacturas.aspx.vb b/Compras/eFacturas.aspx.vb index f68fe8254..322dd0d2e 100644 --- a/Compras/eFacturas.aspx.vb +++ b/Compras/eFacturas.aspx.vb @@ -2841,14 +2841,33 @@ Partial Class Compras_eFacturas - For Each drow As DataRow In ObjCompras.DtResultados.FiltraParametros("CveIE > 0 AND FechaDocumento IS NOT NULL", "", {"FechaDocumento"}).Rows + 'For Each drow As DataRow In ObjCompras.DtResultados.FiltraParametros("CveIE > 0 AND FechaDocumento IS NOT NULL", "", {"FechaDocumento"}).Rows - Dim FechaDocumento As Date = drow("FechaDocumento").ToString.ToDate + ' Dim FechaDocumento As Date = drow("FechaDocumento").ToString.ToDate + + ' Dim FT1 As Date = FechaDocumento.AddDays(-6) + ' Dim FT2 As Date = FechaDocumento.AddDays(7) + + ' If Not (FechaPago >= FT1 And FechaPago < FT2) Then + + ' BtnVincularPago.Visible = False + ' MSGComplemento = MSGComplemento & " Existen mas de 3 días de diferencia entre la fecha del documento y la fecha de complemento. " + + ' Exit For + ' End If + + 'Next + + + For Each GvRowF As GridViewRow In GVPDocumentosRelacionadosPagos.Rows + + Dim FechaDocumento As Date = GvRowF.DataKey("FechaPago").ToString.ToDate + Dim FechaDoRecibo As Date = GvRowF.DataKey("Fecha").ToString.ToDate Dim FT1 As Date = FechaDocumento.AddDays(-6) Dim FT2 As Date = FechaDocumento.AddDays(7) - If Not (FechaPago >= FT1 And FechaPago < FT2) Then + If Not (FechaDoRecibo >= FT1 And FechaDoRecibo < FT2) Then BtnVincularPago.Visible = False MSGComplemento = MSGComplemento & " Existen mas de 3 días de diferencia entre la fecha del documento y la fecha de complemento. " @@ -2858,6 +2877,9 @@ Partial Class Compras_eFacturas Next + + + If MSGComplemento.Trim.Length > 0 Then ' BtnVincularPago.Visible = False diff --git a/Contabilidad/PopUpAuxiliar.aspx b/Contabilidad/PopUpAuxiliar.aspx index fd8deccef..50fe4092b 100644 --- a/Contabilidad/PopUpAuxiliar.aspx +++ b/Contabilidad/PopUpAuxiliar.aspx @@ -1,249 +1,249 @@ -<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PopUpAuxiliar.aspx.vb" Inherits="PopUpAuxiliar" %> - -<%@ Import Namespace="Extensiones" %> - - - - - - - - - Auxiliar Contable - - - - - - - - - - - - + +
    -
    - - -          -          -          - -
    -
    -
    -
    -
    - - Movimientos -
    -
    - - - - - - - - - - -
    -
    - -
    -
    -
    - - - + +
    - - +<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PopUpAuxiliar.aspx.vb" Inherits="PopUpAuxiliar" %> + +<%@ Import Namespace="Extensiones" %> + + + + + + + + + Auxiliar Contable - + + + + + + + + + + + - -
    +
    + + +          +          +          + +
    +
    +
    +
    +
    + + Movimientos +
    +
    + + + + + + + + + + +
    +
    + +
    +
    +
    + + + - -
    + + - - - - Fecha - - - - - - Concepto - - - - - - Cargo - - - - - - Abono - - - - - - Folio (Ref.) - -   - - - - Contabilizado - - - - - - Num. Póliza - - - - - - Fecha Conta. - - - - - - Referencia - - - - - - Usuario - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Fecha + + + + + + Concepto + + + + + + Cargo + + + + + + Abono + + + + + + Folio (Ref.) + +   + + + + Contabilizado + + + + + + Num. Póliza + + + + + + Fecha Conta. + + + + + + Referencia + + + + + + Usuario + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - -
    - -
    -
    -
    -
    -
    - - - - - - - - - - - - - - - -
    - - + +
    + + +
    + +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + +
    + + diff --git a/Contabilidad/Reportes/RepAnexoCatalogo.rdlc b/Contabilidad/Reportes/RepAnexoCatalogo.rdlc index f94a74db7..ed3b469e3 100644 --- a/Contabilidad/Reportes/RepAnexoCatalogo.rdlc +++ b/Contabilidad/Reportes/RepAnexoCatalogo.rdlc @@ -1,1409 +1,1408 @@ - - - - - - - - - 2.27047cm - - - 5.35442cm - - - 2.03692cm - - - 1.82105cm - - - 2.37085cm - - - 2.56137cm - - - 2.39183cm - - - 1.75684cm - - - - - 0.635cm - - - - - true - true - - - - - - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Saldos Iniciales - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - 2 - - - - - - - true - true - - - - - - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Saldos Actuales - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - 2 - - - - - - - 0.6cm - - - - - true - true - - - - - Cuenta - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Nombre - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Deudor - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Acreedor - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Cargos - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Abonos - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Deudor - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - true - true - - - - - Acreedor - - - - - - - Black - - 1pt - - - Black - - 1pt - - 2pt - 2pt - 2pt - 2pt - - - - - - - - 0.4cm - - - - - true - true - - - - - =Fields!Codigo.Value - - - - - - 2pt - 2pt - 1pt - 1pt - - - - - - - - true - true - - - - - =Fields!Nombre.Value - - - - - - 1pt - 1pt - 1pt - 1pt - - - - - - - - true - true - - - - - =IIf(Fields!Tipo.Value <> "D", FormatNumber(Fields!SaldoInicial.Value,2) & " ", FormatNumber(Fields!SaldoInicial.Value,2)) - - - - - - - SaldoInicial - - - 2pt - 2pt - 1pt - 1pt - - - 2 - - - - - - - true - true - - - - - =Fields!Cargos.Value - - - - - - 2pt - 2pt - 1pt - 1pt - - - - - - - - true - true - - - - - =Fields!Abonos.Value - - - - - - 2pt - 2pt - 1pt - 1pt - - - - - - - - true - true - - - - - =IIf(Fields!Tipo.Value <> "D", FormatNumber(Fields!SaldoActual.Value,2) & " ", FormatNumber(Fields!SaldoActual.Value,2)) - - - - - - - SaldoActual - - - 2pt - 2pt - 1pt - 1pt - - - 2 - - - - - - - - - - - - - - - - - - - - - - - After - true - - - After - true - - - - - - - DataSet1 - 1.71477cm - 1.635cm - 20.56375cm - - - - - - true - true - - - - - Anexo del catálogo del - - - - =Parameters!pFechaInicio.Value - - - - al - - - - =Parameters!pFechaFin.Value - - - - - - - Textbox5 - 0.93839cm - 2.27047cm - 0.6cm - 18.29327cm - 1 - - - 2pt - 2pt - 2pt - 2pt - - - - External - = Parameters!pImg.Value - FitProportional - 0.01513cm - 0cm - 1.5cm - 2.27047cm - 2 - - - - - - true - true - - - - - =Parameters!pEmp.Value - - - - - - - Textbox10 - 0.89389in - 0.33891in - 7.20207in - 3 - - - 2pt - 2pt - 2pt - 2pt - - - - 1.41576in - - - - =Parameters!pFechaFin.Value - - - - - - - Textbox5 - 2.27047cm - 0.6cm - 18.29327cm - - = (Globals.PageNumber=1) - - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - - 0.52094in - true - true - - - true - true - - - - - ="Página " & Globals.PageNumber & " de " & Globals.TotalPages - - - - - - - Textbox3 - 0.14111cm - 16.41508cm - 0.6cm - 4.14867cm - - - 2pt - 2pt - 2pt - 2pt - - - - 0.06944in - 0in - 8.09596in - 1 - - - - - - true - true - - - - - Usuario: - - - - - - 2pt - 2pt - 2pt - 2pt - - - - true - true - - - - - =Parameters!usuarioImprimio.Value - - - - - - 2pt - 2pt - 2pt - 2pt - - - - true - true - - - - - Fecha Impresión: - - - - - - - Textbox2 - 0.08333in - 2.89776in - 0.20844in - 1.1182in - 4 - - - 2pt - 2pt - 2pt - 2pt - - - - true - true - - - - - =Globals!ExecutionTime - - - - - - - Textbox2 - 0.08333in - 4.01596in - 0.20844in - 2.10083in - 5 - - - 2pt - 2pt - 2pt - 2pt - - - - true - true - - - - - IMPRESO EN SIG, Anexo Catalogo - - - - - - 2pt - 2pt - 2pt - 2pt - - - - - - - - 0.19685in - 0.19685in - 0.3937in - 0.3937in - 0.05118in - + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Saldos Iniciales + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + 2 + + + + + + + true + true + + + + + + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Saldos Actuales + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + 2 + + + + + + + 0.6cm + + + + + true + true + + + + + Cuenta + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Nombre + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Deudor + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Acreedor + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Cargos + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Abonos + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Deudor + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Acreedor + + + + + + + Black + + 1pt + + + Black + + 1pt + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.4cm + + + + + true + true + + + + + =Fields!Codigo.Value + + + + + + 2pt + 2pt + 1pt + 1pt + + + + + + + + true + true + + + + + =Fields!Nombre.Value + + + + + + 1pt + 1pt + 1pt + 1pt + + + + + + + + true + true + + + + + =Fields!SaldoInicial.Value + + + + + + + SaldoInicial + + + 2pt + 2pt + 1pt + 1pt + + + 2 + + + + + + + true + true + + + + + =Fields!Cargos.Value + + + + + + 2pt + 2pt + 1pt + 1pt + + + + + + + + true + true + + + + + =Fields!Abonos.Value + + + + + + 2pt + 2pt + 1pt + 1pt + + + + + + + + true + true + + + + + =Fields!SaldoActual.Value + + + + + + + SaldoActual + + + 2pt + 2pt + 1pt + 1pt + + + 2 + + + + + + + + + + + + + + + + + + + + + + + After + true + + + After + true + + + + + + + DataSet1 + 1.71477cm + 1.635cm + 20.56375cm + + + + + + true + true + + + + + Anexo del catálogo del + + + + =Parameters!pFechaInicio.Value + + + + al + + + + =Parameters!pFechaFin.Value + + + + + + + Textbox5 + 0.93839cm + 2.27047cm + 0.6cm + 18.29327cm + 1 + + + 2pt + 2pt + 2pt + 2pt + + + + External + = Parameters!pImg.Value + FitProportional + 0.01513cm + 1.5cm + 2.27047cm + 2 + + + + + + true + true + + + + + =Parameters!pEmp.Value + + + + + + + Textbox10 + 0.89389in + 0.33891in + 7.20207in + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + 1.41576in + + + + =Parameters!pFechaFin.Value + + + + + + + Textbox5 + 2.27047cm + 0.6cm + 18.29327cm + + = (Globals.PageNumber=1) + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + 0.52094in + true + true + + + true + true + + + + + ="Página " & Globals.PageNumber & " de " & Globals.TotalPages + + + + + + + Textbox3 + 0.14111cm + 16.41508cm + 0.6cm + 4.14867cm + + + 2pt + 2pt + 2pt + 2pt + + + + 0.06944in + 0in + 8.09596in + 1 + + + + + + true + true + + + + + Usuario: + + + + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!usuarioImprimio.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + Fecha Impresión: + + + + + + + Textbox2 + 0.08333in + 2.89776in + 0.20844in + 1.1182in + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Globals!ExecutionTime + + + + + + + Textbox2 + 0.08333in + 4.01596in + 0.20844in + 2.10083in + 5 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + IMPRESO EN SIG, Anexo Catalogo + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.19685in + 0.19685in + 0.3937in + 0.3937in + 0.05118in + - - - - -
  • - Saldar Cuentas Incobrables -
  • -
  • - Vincular Intermediario -
  • -
    -
    -
    - - Abonar Cliente: - - - - - - - - - -
    - -
    -
    -
    -
    -
    - - Banco   - Ingresos x Comprobar - Pago Intermediario - -
    -
    - -
    - - -
    -
    - T.C: - - - - -
    - -
    - -
    - -
    - -
    - - - -
    -
    -
    -
    - -
    - - - -
    -
    -
    -
    -
    - -
    - - - - - -
    - -
    -
    - -
    - - - - - -
    - - - - -
    - T.C: - - - -
    - -
    -
    -
    -
    -
    - -
    -
    - - - - -
    - - - - - - - - - - - - -
    -
    -
    - -
    - - - -
    -
    - -
    - $ - - - -
    -
    -
    - -
    - -
    -
    -
    - -
    - - -
    -
    - $ - - - - -
    -
    -
    - -
    - -
    -
    - - - -
    - -
    - - <%-- - --%> -
    -
    -
    - -
    - - <%-- - --%> -
    -
    -
    -
    -
    -
    -
    - -
    -
    - -
    -
    - -
    - -
    -
    - -
    - - - - - - - - -
    - - - -
    - -
    - -
    -
    -
    -
    - -
    -
    - " style="display: inline-block; margin-right: -20px; width: 150px;" /> - " style="margin-top: -3px; margin-right: 20px" class="btn btn-circle btn-sm label-info"> -
    -
    - - - - - - - - - - - - - - - Venta - - - - - - <%----%> - - Fecha Venta - - - - - - Fecha Vencimiento - - - - - - Días Vencidos - -   - - - - - - Monto Compra - -   - - - - - -   - - - - Abonado - -   - - - - Saldo - -   - - - - Abonar - - - - - - - Ot. Ing. - - - - - - - Descuento Pronto Pago - -   - - - - - - - - - Auxiliar - - - - - - CveVenta - - - - - - - - - - - - - <%-- MODAL SALDAR INCOBRABLE--%> - - <%-- FIN MODAL SALDAR INCOBRABLE--%> - - - - -
    - - + + + - + } + + function FnLimites(chk, txt, limiteInferior, limiteSuperior) { + if (ToDouble(txt.value) < limiteInferior) { + txt.value = limiteInferior; + alert("El Importe no debe de exceder a el saldo"); + } else if (ToDouble(txt.value) > limiteSuperior) { + txt.value = limiteSuperior; + alert("El Importe no debe de exceder a el saldo"); + } + + var Suma = SumaValores(); + $get('TxtImporte').value = FormatoNumero(Suma, 2); + + if ($get('TxtTotal') != null) { + $get('TxtTotal').value = FormatoNumero(Suma + (ToDouble($get('TxtOtrosImportes').value * -1)), 2); + } + + CambiaPesosDolares() + CambiaDolaresPesos() + + } + + function CambiaPesosDolares() { + $get('TxtImporte').value = FormatoNumero(SumaValores(), 2); + $('#LtlTotalMXN').text(FormatoNumero(SumaValores(), 2)) + if ($("#LbImporteME").length) { + $get('LbImporteME').innerHTML = '$ ' + FormatoNumero(SumaValores(), 2) + ' USD'; + $get('TxtImporte').value = FormatoNumero(ToDouble($get('TxtImporte').value) * ToDouble($get('TxtTC').value), 2); + $get('LtlTotalMXN').value = FormatoNumero(ToDouble($get('TxtImporte').value) * ToDouble($get('TxtTC').value), 2); + } + + if ($get('TxtTotal') != null) { + $get('TxtTotal').value = FormatoNumero(ToDouble($get('TxtImporte').value) + (ToDouble($get('TxtOtrosImportes').value * -1)), 2); + } + } + + function CambiaDolaresPesos() { + + $get('TxtImporte').value = FormatoNumero(SumaValores(), 2); + $('#LtlTotalMXN').text(FormatoNumero(SumaValores(), 2)) + + + + if ($("#LbImporteMN").length) { + $get('LbImporteMN').innerHTML = '$ ' + FormatoNumero(SumaValores(), 2) + ' MXN'; + $get('TxtImporte').value = FormatoNumero(ToDouble($get('TxtImporte').value) / ToDouble($get('TxtTCDolares').value), 2); + $get('LtlTotalMXN').value = FormatoNumero(ToDouble($get('TxtImporte').value) / ToDouble($get('TxtTCDolares').value), 2); + + } + + if ($get('TxtTotal') != null) { + $get('TxtTotal').value = FormatoNumero(ToDouble($get('TxtImporte').value) + (ToDouble($get('TxtOtrosImportes').value * -1)), 2); + } + + } + + function waitforpastedata(elem, savedcontent) { + if (elem.childNodes && elem.childNodes.length > 0) { + processpaste(elem, savedcontent); + } + else { + that = { + e: elem, + s: savedcontent + } + that.callself = function () { + waitforpastedata(that.e, that.s) + } + setTimeout(that.callself, 20); + } + } + + function processpaste(elem, savedcontent) { + pasteddata = elem.innerHTML; + //^^Alternatively loop through dom (elem.childNodes or elem.getElementsByTagName) here + + elem.innerHTML = savedcontent; + + // Do whatever with gathered data; + alert(pasteddata); + } + + function CheckAll() { + var topLevelElem = document.getElementById("C_UPVentas"); + var textBoxes = topLevelElem.getElementsByTagName("input"); + var check = false; + + for (var i = 0; i < textBoxes.length; i++) { + if (textBoxes[i].type == "checkbox") { + + + if (textBoxes[i].id == "ChkAll") { + check = !textBoxes[i].checked; + continue; + } + + + if (textBoxes[i].checked && check) { + textBoxes[i].click(); + } else if (!textBoxes[i].checked && !check) { + textBoxes[i].click(); + } + + } + } + + } + + var TipoCambioActual = 0.0; + function CambiaTC(txt) { + let TipoCambioTxt = ToDouble(txt.value) + if (TipoCambioActual != TipoCambioTxt) { + $get("BtnCambiaTipoMoneda").click(); + TipoCambioActual = TipoCambioTxt; + } + } + + diff --git a/vwd.webinfo b/vwd.webinfo index 2f273a97f..9a68975f3 100644 --- a/vwd.webinfo +++ b/vwd.webinfo @@ -20,6 +20,20 @@ + + + + + + + + + + + + + + From 544a1a16852a971bfed2f059dc661a40cd31ba36 Mon Sep 17 00:00:00 2001 From: JORGE LUIS CAUDILLO ESPARZA Date: Fri, 13 Mar 2020 12:20:22 -0700 Subject: [PATCH 07/14] --- App_Code/ClsContabilidad.vb | 24 +- Contabilidad2/CatCuentas.aspx | 57 +++- Contabilidad2/CatCuentas.aspx.vb | 180 ++++++++++++- WebCaudillo20200311.config | 428 +++++++++++++++++++++++++++++++ vwd.webinfo | 2 + 5 files changed, 675 insertions(+), 16 deletions(-) create mode 100644 WebCaudillo20200311.config diff --git a/App_Code/ClsContabilidad.vb b/App_Code/ClsContabilidad.vb index ff6b8012f..f5e63f696 100644 --- a/App_Code/ClsContabilidad.vb +++ b/App_Code/ClsContabilidad.vb @@ -1962,9 +1962,28 @@ Public Class ClsContabilidad #End Region #Region " C O N T A B I L I D A D - C O N C E P T O S - C O N T A B L E S " - Public Function GetConta_ConceptosContables() As Boolean + Public Function GetConta_CuentasDataContabilidad(CveCuenta As Integer, CveEmpresa As Integer) As Boolean + Dim Retorno As Boolean = False + DataAdapter("PA_Conta_CuentasDataContabilidadGet") + With SqlAdapter.SelectCommand.Parameters + .Add("@CveCuenta", SqlDbType.Int).Value = CveCuenta + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + End With + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al obtener lod datos de Concepto Contables.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End Try + + Return Retorno + End Function + Public Function GetConta_ConceptosContables(Optional Estado As Integer = -1) As Boolean Dim Retorno As Boolean = False DataAdapter("PA_Conta_ConceptosContablesGet") + With SqlAdapter.SelectCommand.Parameters + .Add("@Estado", SqlDbType.Int).Value = Estado + End With Try SqlAdapter.Fill(Data) Retorno = True @@ -4605,7 +4624,7 @@ Public Class ClsContabilidad Public Function UpdateCuenta(CveCuenta As Integer, Nombre As String, Tipo As String, CtaMayor As Integer, CveMoneda As Integer, Optional DigAgrupador As Integer = -1, Optional CveAgrupadorSAT As Integer = -1, Optional NomIdioma As String = "", Optional CveConceptoAdmin As Integer = -1, Optional CveProveedor As Integer = -1, Optional CveCliente As Integer = -1, Optional CveClasificacion As Integer = -1, Optional PorcentajeImpuesto As Decimal = -1, - Optional CveBancoCuenta As Integer = -1) As Boolean + Optional CveBancoCuenta As Integer = -1, Optional CveAlmacen As Integer = -1) As Boolean Dim Retorno As Boolean = False DataAdapter("PA_Conta_UpdateCuentas") @@ -4625,6 +4644,7 @@ Public Class ClsContabilidad .Add("@CveClasificacion", SqlDbType.Int).Value = CveClasificacion .Add("@PorcentajeImpuesto", SqlDbType.Money).Value = PorcentajeImpuesto .Add("@CveBancoCuenta", SqlDbType.Int).Value = CveBancoCuenta + .Add("@CveAlmacen", SqlDbType.Int).Value = CveAlmacen End With Try diff --git a/Contabilidad2/CatCuentas.aspx b/Contabilidad2/CatCuentas.aspx index b61b15b26..0bbfc328f 100644 --- a/Contabilidad2/CatCuentas.aspx +++ b/Contabilidad2/CatCuentas.aspx @@ -75,7 +75,7 @@
    -<%--
    +
    +
    +
    +
    Concepto
    +
    + + +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    +
    + + + +
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    +
    + +
    +
    + +
    diff --git a/Contabilidad2/CatCuentas.aspx.vb b/Contabilidad2/CatCuentas.aspx.vb index 5f0fb2f53..f96e41d01 100644 --- a/Contabilidad2/CatCuentas.aspx.vb +++ b/Contabilidad2/CatCuentas.aspx.vb @@ -14,15 +14,66 @@ Partial Class Contabilidad2_CatCuentas ViewState("DtDatos") = value End Set End Property + + Private Property DtConceptosconta As DataTable + Get + Return CType(ViewState("DtConceptosconta"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtConceptosconta") = value + End Set + End Property Private Property IDSelected As Integer Get - Return ViewState("idsel").ToString.ToEntero + Return ViewState("idsel").ToString.ToEntero() End Get Set(value As Integer) ViewState("idsel") = value End Set End Property +#Region "Contabilidadnew" + Private Property CveProveedor As Integer + Get + Return ViewState("CveProveedor").ToString.ToEntero() + End Get + Set(value As Integer) + ViewState("CveProveedor") = value + End Set + End Property + Private Property CveCliente As Integer + Get + Return ViewState("CveCliente").ToString.ToEntero() + End Get + Set(value As Integer) + ViewState("CveCliente") = value + End Set + End Property + Private Property CveClasificacion As Integer + Get + Return ViewState("CveClasificacion").ToString.ToEntero() + End Get + Set(value As Integer) + ViewState("CveClasificacion") = value + End Set + End Property + Private Property CveBancoCuenta As Integer + Get + Return ViewState("CveBancoCuenta").ToString.ToEntero() + End Get + Set(value As Integer) + ViewState("CveBancoCuenta") = value + End Set + End Property + Private Property CveAlmacen As Integer + Get + Return ViewState("CveAlmacen").ToString.ToEntero() + End Get + Set(value As Integer) + ViewState("CveAlmacen") = value + End Set + End Property +#End Region #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load @@ -30,9 +81,18 @@ Partial Class Contabilidad2_CatCuentas 'inicio() 'RegistraScript("$('#Tsubcuenta').mask('00000-0000-0000-00000');") ' If UsuarioActual.Empresa.UsaContabilidad Then + DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + DdlAlmacen.DataBind() CargaMonedas() CargaAgrupadorSAT() CargaDatos() + Using objconta As New ClsContabilidad + objconta.GetConta_ConceptosContables(1) + DtConceptosconta = objconta.DtResultados + End Using + DdlConcepto.DataSource = DtConceptosconta + DdlConcepto.DataBind() + DdlConcepto.Items.Insert(0, New ListItem("Seleccione", "-1")) 'Else ' Alert("Este módulo requiere el uso de Contabilidad.", TipoMensaje.MsgAdvertencia) ' MEECuenta.Enabled = False @@ -126,9 +186,28 @@ Partial Class Contabilidad2_CatCuentas updatos.Update() End Sub + Private Sub limpiavalorescontables() + + DdlConcepto.SelectedValueExist(-1) + onconceptochange() + CveProveedor = -1 + DdlProveedores.SelectedText = "" + DdlProveedores.SelectedValue = CveProveedor + CveCliente = -1 + DdlClientesWS.SelectedText = "" + DdlClientesWS.SelectedValue = CveCliente + Dim PorcentajeImpuesto As Decimal = -1 + DdlClasificacion.SelectedValueExist(PorcentajeImpuesto) + CveClasificacion = -1 + DdlClasificacion.SelectedValueExist(CveClasificacion) + CveBancoCuenta = -1 + CveAlmacen = -1 + DdlAlmacen.SelectedValueExist(CveAlmacen) + End Sub Protected Sub editar_Click(sender As Object, e As EventArgs) Handles ArbolCuentas.editclick LimpiarCampos() + limpiavalorescontables() Dim dt As DataTable Dim obj As ADServerControl.DragableItem = DirectCast(sender, ADServerControl.DragableItem) IDSelected = obj.Cve @@ -141,6 +220,29 @@ Partial Class Contabilidad2_CatCuentas DTcuenta.SelectedValue = dr("Tipo").ToString() DcuentaMayor.SelectedValue = dr("CtaMayor").ToString DdlMoneda.SelectedValue = dr("CveMoneda").ToString + Using objconta As New ClsContabilidad + objconta.GetConta_CuentasDataContabilidad(IDSelected, UsuarioActual.CveEmpresa) + If objconta.DtResultados.Rows.Count > 0 Then + Dim rowcc As DataRow = objconta.DtResultados.Rows(0) + + DdlConcepto.SelectedValueExist(rowcc("CveConceptoAdmin").ToString().ToEntero()) + onconceptochange() + CveProveedor = rowcc("CveProveedor").ToString().ToEntero() + DdlProveedores.SelectedText = rowcc("Proveedor").ToString().ToEntero() + DdlProveedores.SelectedValue = CveProveedor + CveCliente = rowcc("CveCliente").ToString().ToEntero() + DdlClientesWS.SelectedText = rowcc("Cliente").ToString().ToEntero() + DdlClientesWS.SelectedValue = CveCliente + Dim PorcentajeImpuesto As Decimal = rowcc("PorcentajeImpuesto").ToString().ToDecimal() * 100 + DdlClasificacion.SelectedValueExist(PorcentajeImpuesto) + CveClasificacion = rowcc("CveClasificacion").ToString().ToEntero() + DdlClasificacion.SelectedValueExist(CveClasificacion) + CveBancoCuenta = rowcc("CveBancoCuenta").ToString().ToEntero() + CveAlmacen = rowcc("CveAlmacen").ToString().ToEntero() + DdlAlmacen.SelectedValueExist(CveAlmacen) + End If + + End Using If dr("CveAgrupadorSAT").ToString.ToEntero = 0 Then DdlAgrupadorSAT.SelectedValue = -1 @@ -178,23 +280,33 @@ Partial Class Contabilidad2_CatCuentas 'Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) Dim ObjConta As New ClsContabilidad - Dim ObjConta2 As New ClsContPAQi(UsuarioActual.Empresa) - If ObjConta.UpdateCuenta(IDSelected.ToEntero, Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, DdlMoneda.SelectedValue.ToEntero, TxtDigAgrup.Text.ToString.ToEntero, DdlAgrupadorSAT.SelectedValue.ToEntero, TxtNomIngles.Text.ToString) Then + Dim CveConceptoAdmin As Integer = DdlConcepto.SelectedValue.ToEntero() + Dim CveProveedor As Integer = DdlProveedores.SelectedValue.ToEntero() + Dim CveCliente As Integer = DdlClientesWS.SelectedValue.ToEntero() + Dim CveClasificacion As Integer = DdlClasificacion.SelectedValue.ToEntero() + Dim PorcentajeImpuesto As Decimal = TxtPorcentaje.Text.ToDecimal() / 100 + Dim CveBancoCuenta As Integer = -1 + Dim CveAlmacen As Integer = DdlAlmacen.SelectedValue.ToEntero() + If ObjConta.UpdateCuenta(IDSelected.ToEntero, Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, DdlMoneda.SelectedValue.ToEntero, TxtDigAgrup.Text.ToString.ToEntero, DdlAgrupadorSAT.SelectedValue.ToEntero, TxtNomIngles.Text.ToString, + CveConceptoAdmin:=CveConceptoAdmin, CveProveedor:=CveProveedor, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, PorcentajeImpuesto:=PorcentajeImpuesto, CveBancoCuenta:=CveBancoCuenta, CveAlmacen:=CveAlmacen) Then Dim codigo As String = DtDatos.FiltroPrimeroValor("Codigo", $"CveCuenta={IDSelected}") - If ObjConta2.GetCuentas(-1, "-1", -1) Then - Dim Id As Integer = ObjConta2.DtResultados.FiltroPrimeroValor("Id", $"Codigo='{codigo}'").ToEntero - Dim IdAgrupador As Integer + Using ObjConta2 As New ClsContPAQi(UsuarioActual.Empresa) - If ObjConta2.GetAgrupadoresSAT() Then - IdAgrupador = ObjConta2.DtResultados.FiltroPrimeroValor("Id", $"CodigoNombre='{DdlAgrupadorSAT.SelectedItem.Text}'").ToEntero - End If - If Id > 0 Then - If ObjConta2.UpdateCuenta(Id, Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, DdlMoneda.SelectedValue.ToEntero, IdAgrupador, SubCuentaDe:=Tsubcuenta.Text.Trim) > 0 Then + If ObjConta2.GetCuentas(-1, "-1", -1) Then + Dim Id As Integer = ObjConta2.DtResultados.FiltroPrimeroValor("Id", $"Codigo='{codigo}'").ToEntero + Dim IdAgrupador As Integer + + If ObjConta2.GetAgrupadoresSAT() Then + IdAgrupador = ObjConta2.DtResultados.FiltroPrimeroValor("Id", $"CodigoNombre='{DdlAgrupadorSAT.SelectedItem.Text}'").ToEntero + End If + If Id > 0 Then + If ObjConta2.UpdateCuenta(Id, Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, DdlMoneda.SelectedValue.ToEntero, IdAgrupador, SubCuentaDe:=Tsubcuenta.Text.Trim) > 0 Then + End If End If End If - End If + End Using Dim customerRow As Data.DataRow customerRow = DtDatos.Select(String.Format("CveCuenta = {0}", IDSelected))(0) @@ -216,7 +328,6 @@ Partial Class Contabilidad2_CatCuentas End If ObjConta.Dispose() - ObjConta2.Dispose() End Sub Protected Sub nuevacuenta_Click(sender As Object, e As EventArgs) Handles nuevacuenta.Click @@ -373,4 +484,47 @@ Partial Class Contabilidad2_CatCuentas 'Protected Sub BtnCambiaAgrupadorSAT_Click(sender As Object, e As EventArgs) ' CargaAgrupadorSAT() 'End Sub + Protected Sub DdlConcepto_SelectedIndexChanged(sender As Object, e As EventArgs) + onconceptochange() + End Sub + Private Sub onconceptochange(Optional CveCuenta As Integer = -1) + PnlOpcion1.Visible = False + pnlOpcion2.Visible = False + pnlOpcion3.Visible = False + pnlOpcion4.Visible = False + pnlOpcion5.Visible = False + pnlOpcion6.Visible = False + Dim CveConceptoContable As Integer = DdlConcepto.SelectedValue.ToEntero() + Dim row As DataRow = Nothing + Dim CveTipoSaldo As Integer = 0 + Dim CveParejaContable As Integer = 0 + If CveConceptoContable > 0 Then + row = DtConceptosconta.FiltroPrimero(String.Format("CveConceptoContable={0}", CveConceptoContable)) + CveTipoSaldo = row("CveTipoSaldo").ToString.ToEntero() + CveParejaContable = row("CveParejaContable").ToString().ToEntero() + End If + If Not IsNothing(row) Then + Select Case CveTipoSaldo + Case 1 + PnlOpcion1.Visible = True + Case 2 + pnlOpcion2.Visible = True + Case 3 + pnlOpcion3.Visible = True + If DdlClasificacion.Items.Count < 2 Then + DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, UsoClasificacion:=1) + DdlClasificacion.DataBind() + End If + Case 4 + pnlOpcion4.Visible = True + Case 5 + pnlOpcion5.Visible = True + + Case 6 + pnlOpcion6.Visible = True + + End Select + End If + End Sub + End Class \ No newline at end of file diff --git a/WebCaudillo20200311.config b/WebCaudillo20200311.config new file mode 100644 index 000000000..a2c0a5232 --- /dev/null +++ b/WebCaudillo20200311.config @@ -0,0 +1,428 @@ + + + + +
    + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vwd.webinfo b/vwd.webinfo index bfda47f43..a280964b8 100644 --- a/vwd.webinfo +++ b/vwd.webinfo @@ -23,6 +23,8 @@ + + \ No newline at end of file From 39243a89cde2328c75569d2c940d19b6da1dfedb Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Fri, 13 Mar 2020 12:50:50 -0700 Subject: [PATCH 08/14] Estatus de anticipos --- Ventas/RepVentaDetalle.aspx.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ventas/RepVentaDetalle.aspx.vb b/Ventas/RepVentaDetalle.aspx.vb index fb62c7439..1e00b530d 100644 --- a/Ventas/RepVentaDetalle.aspx.vb +++ b/Ventas/RepVentaDetalle.aspx.vb @@ -376,7 +376,7 @@ Partial Class RepVentaDetalle Private Sub CargaEstatus() DdlEstatus.Items.Clear() If DdlTipoComprobante.GetSelectedText <> "" Then - DdlEstatus.DataSource = GlobalDTEstatusFactura.FiltraParametros(String.Format("TipoDocto IN ({0})", DdlTipoComprobante.GetSelectedValuesM(True))) + DdlEstatus.DataSource = GlobalDTEstatusFactura.FiltraParametros(String.Format("TipoDocto IN ({0})", DdlTipoComprobante.GetSelectedValuesM(True).Replace("Ant", "Ing"))) Else DdlEstatus.DataSource = GlobalDTEstatusFactura End If From 387433952de7f1c523332a1415b3ee05366fa94f Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Fri, 13 Mar 2020 14:52:33 -0700 Subject: [PATCH 09/14] . --- Empresas/141/Formatos/Cotizacion.rdlc | 2 +- Empresas/141/Formatos/Factura.rdlc | 29 ++++++++++++++++++--------- RH/CatCursos.aspx.vb | 15 +++++++++----- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Empresas/141/Formatos/Cotizacion.rdlc b/Empresas/141/Formatos/Cotizacion.rdlc index f3e160397..eb94d461e 100644 --- a/Empresas/141/Formatos/Cotizacion.rdlc +++ b/Empresas/141/Formatos/Cotizacion.rdlc @@ -905,7 +905,7 @@ - =Fields!PS.Value & " " & Fields!Obs.Value + =Fields!PS.Value & IIF(Fields!Obs.Value <> "",System.Environment.NewLine &"Observaciones: ","") & Fields!Obs.Value - - - Actualizar Precios - - - - -
  • - Importar Listado -
  • -
    - - - - -
    -
    -
    - - -
    -
    -
    - -
    - -
    - -
    - -
    - -
    - -
    - - - - -
    -
    -
    - -
    -
    -
    - - -
    -
    -
    -
    -
    - - Actualizar Precio de Lista -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    - - - - -
    -
    -
    -
    -
    - - - - $ -
    -
    - -
    -
    -
    -
    - - - - $ -
    -
    - -
    - - -
    - - - -
    -
    - -
    -
    -
    -
    -
    -
    -
    - - -
    -
    - " style="display: inline-block; margin-right: -20px; width: 150px;" /> - " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    -
    - - - <%--CARGA EXCEL--%> - -
    - +<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="ActualizarPrecios.aspx.vb" Inherits="Ventas_ActualizarPrecios" %> + + + + + + + + Actualizar Precios + + + + +
  • + Importar Listado +
  • +
    + + + + +
    +
    +
    + + +
    +
    +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    + + + +
    +
    +
    +
    +
    +
    + +
    + +
    + +
    + + Todos + Activos + Incativos + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    +
    + + Actualizar Precio de Lista +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + + + + +
    +
    +
    +
    +
    + + + + $ +
    +
    + +
    +
    +
    +
    + + + + $ +
    +
    + +
    + + +
    + + + +
    +
    + +
    +
    +
    +
    +
    +
    +
    + + +
    +
    + " style="display: inline-block; margin-right: -20px; width: 150px;" /> + " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + + + <%--CARGA EXCEL--%> + +
    + - - + +
    + diff --git a/Ventas/ActualizarPrecios.aspx.vb b/Ventas/ActualizarPrecios.aspx.vb index 566773a6b..f170c6462 100644 --- a/Ventas/ActualizarPrecios.aspx.vb +++ b/Ventas/ActualizarPrecios.aspx.vb @@ -130,7 +130,7 @@ Partial Class Ventas_ActualizarPrecios If UsuarioActual.Empresa.Funcionalidad(130) = "1" Then Dim ObjMarcas As New ClsProductosServicios If ObjMarcas.GetMarcas(UsuarioActual.CveEmpresa) Then - DdlMarca.DataSource = ObjMarcas.DtResultados + DdlMarca.DataSource = ObjMarcas.DtResultados.Copy End If ObjMarcas.Dispose() DdlMarca.DataBind() @@ -145,6 +145,7 @@ Partial Class Ventas_ActualizarPrecios Dim objPS As New ClsProductosServicios Dim CveProveedor As Integer = -1 Dim CvePS As Integer = -1 + Dim Marcas As String = If(DdlMarca.GetSelectedValuesM = "", "-1", DdlMarca.GetSelectedValuesM) If DDlPs.SelectedValue.ToEntero > 0 Then CvePS = DDlPs.SelectedValue.ToEntero @@ -155,7 +156,7 @@ Partial Class Ventas_ActualizarPrecios End If If objPS.GetPSPreciosLista(UsuarioActual.CveEmpresa, DdlPrecioLista.SelectedValue.ToEntero, DDlClasificacion.SelectedValue.ToEntero, CvePS, - CveProveedor:=CveProveedor, Estado:=DdlEstado.SelectedValue.ToEntero, CveMarca:=DdlMarca.SelectedValue.ToEntero()) Then + CveProveedor:=CveProveedor, Estado:=DdlEstado.SelectedValue.ToEntero, Marcas:=Marcas) Then GVPrecios.DataSource = objPS.DtResultados End If objPS.Dispose() From 2605932ee12175aefbfb7e102d984389ddd37a8f Mon Sep 17 00:00:00 2001 From: JORGE LUIS CAUDILLO ESPARZA Date: Fri, 13 Mar 2020 16:48:55 -0700 Subject: [PATCH 11/14] --- Ventas/Ventas.aspx.vb | 112 +++++++++++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 33 deletions(-) diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index ce903284a..66f3ce64e 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -19102,7 +19102,7 @@ Partial Class Ventas Conexion.Open() Dim cmd = Conexion.CreateCommand() cmd.CommandType = CommandType.Text - cmd.CommandText = "Select * FROM [Hoja1$]" + cmd.CommandText = "Select * FROM [Hoja1$] WHERE Cantidad >=1" Dim DataAdapter = New Odbc.OdbcDataAdapter(cmd) DataAdapter.Fill(dt) Case Else @@ -19155,6 +19155,8 @@ Partial Class Ventas dt.TableName = "Datos" + Dim DtSubProyecto As DataTable = GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa) + DtSubProyecto.CaseSensitive = False If Not ErrorArchivo Then NumRow = 1 Dim RowNoEncontrados As String = "" @@ -19179,8 +19181,6 @@ Partial Class Ventas NumRow = NumRow + 1 If Proyecto <> "" Then - Dim DtSubProyecto As DataTable = GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa) - DtSubProyecto.CaseSensitive = False DrProyecto = DtSubProyecto.FiltroPrimero($"(SubProyecto) = '{Proyecto}'") If DrProyecto IsNot Nothing Then CveSubProyecto = DrProyecto("CveSubProyecto").ToString.ToEntero @@ -19193,38 +19193,80 @@ Partial Class Ventas End If If Codigo <> "" Then - Dim StrArray() As String = GetPS("Codigo", Codigo).Split("|"c) - If StrArray.Length > 0 Then - If CBool(StrArray(0)) = True Then - CvePS = StrArray(1).ToEntero + + Using ObjPS As New ClsProductosServicios + If ObjPS.GetPS(-1, -1, UsuarioActual.CveEmpresa, Codigo:=Codigo) Then + If ObjPS.CvePS > 0 Then + CvePS = ObjPS.CvePS + CveUM = ObjPS.CveUnidadMedida + + Else + RowNoEncontrados = String.Format("{3}    - No se encontró {0} en la fila {1}, columna {2}<\BR>", Codigo, NumRow, "Codigo", RowNoEncontrados) + End If Else - RowNoEncontrados &= StrArray(1) & "<\BR>" + RowNoEncontrados = String.Format("{3}    - No se encontró {0} en la fila {1}, columna {2}<\BR>(NoBD)", Codigo, NumRow, "Codigo", RowNoEncontrados) End If - End If + End Using + + 'Dim StrArray() As String = GetPS("Codigo", Codigo).Split("|"c) + 'If StrArray.Length > 0 Then + ' If CBool(StrArray(0)) = True Then + ' CvePS = StrArray(1).ToEntero + ' Else + ' RowNoEncontrados &= StrArray(1) & "<\BR>" + ' End If + 'End If ElseIf CodigoBarras <> "" Then - Dim StrArray() As String = GetPS("CodigoBarras", CodigoBarras).Split("|"c) - If StrArray.Length > 0 Then - If CBool(StrArray(0)) = True Then - CvePS = StrArray(1).ToEntero + + Using ObjPS As New ClsProductosServicios + If ObjPS.GetPS(-1, -1, UsuarioActual.CveEmpresa, CodigoBarras:=CodigoBarras) Then + If ObjPS.CvePS > 0 Then + CvePS = ObjPS.CvePS + CveUM = ObjPS.CveUnidadMedida + + Else + RowNoEncontrados = String.Format("{3}    - No se encontró {0} en la fila {1}, columna {2}<\BR>", Codigo, NumRow, "Codigo", RowNoEncontrados) + End If Else - RowNoEncontrados &= StrArray(1) & "<\BR>" + RowNoEncontrados = String.Format("{3}    - No se encontró {0} en la fila {1}, columna {2}<\BR>(NoBD)", Codigo, NumRow, "Codigo", RowNoEncontrados) End If - End If + End Using + 'Dim StrArray() As String = GetPS("CodigoBarras", CodigoBarras).Split("|"c) + 'If StrArray.Length > 0 Then + ' If CBool(StrArray(0)) = True Then + ' CvePS = StrArray(1).ToEntero + ' Else + ' RowNoEncontrados &= StrArray(1) & "<\BR>" + ' End If + 'End If ElseIf ProductoServicio <> "" Then - Dim StrArray() As String = GetPS("PS", ProductoServicio).Split("|"c) - If StrArray.Length > 0 Then - If CBool(StrArray(0)) = True Then - CvePS = StrArray(1).ToEntero + + Using ObjPS As New ClsProductosServicios + If ObjPS.GetPS(-1, -1, UsuarioActual.CveEmpresa, CodigoBarras:=CodigoBarras) Then + If ObjPS.CvePS > 0 Then + CvePS = ObjPS.CvePS + CveUM = ObjPS.CveUnidadMedida + Else + RowNoEncontrados = String.Format("{3}    - No se encontró {0} en la fila {1}, columna {2}<\BR>", Codigo, NumRow, "Codigo", RowNoEncontrados) + End If Else - RowNoEncontrados &= StrArray(1) & "<\BR>" + RowNoEncontrados = String.Format("{3}    - No se encontró {0} en la fila {1}, columna {2}<\BR>(NoBD)", Codigo, NumRow, "Codigo", RowNoEncontrados) End If - End If + End Using + 'Dim StrArray() As String = GetPS("PS", ProductoServicio).Split("|"c) + 'If StrArray.Length > 0 Then + ' If CBool(StrArray(0)) = True Then + ' CvePS = StrArray(1).ToEntero + ' Else + ' RowNoEncontrados &= StrArray(1) & "<\BR>" + ' End If + 'End If Else RowNoEncontrados &= "<\BR>    - En la fila " & NumRow & " no se especificó código, código de barras ó descripción." End If If CvePS > 0 Then - CveUM = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveUnidadMedida", $"CvePS = '{CvePS}'").ToString.ToEntero + 'CveUM = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveUnidadMedida", $"CvePS = '{CvePS}'").ToString.ToEntero AgregarProductoServicio(Cantidad, CveUM, UM, -1, "", CvePS, HdnPS.Value, Observaciones, PrecioUnitario, HdnDescuento.Value.ToDecimal, @@ -19276,17 +19318,21 @@ Partial Class Ventas Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError) End If End Sub - Private Function GetPS(Opt As String, Valor As String) As String - Dim StrReturn As String = String.Empty - Dim CvePS As Integer = 0 - CvePS = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CvePS", Opt & " = '" & Valor & "'").ToString.ToEntero - If CvePS > 0 Then - StrReturn = "True|" & CvePS.ToString - Else - StrReturn = "False|    - No se encontró " & Valor & " en la fila " & NumRow & ", columna " & Opt - End If - Return StrReturn - End Function + + + 'Private dtps As DataTable = Nothing + 'Private Function GetPS(Opt As String, Valor As String) As String + ' Dim StrReturn As String = String.Empty + ' Dim CvePS As Integer = 0 + ' If dtps Is Nothing Then dtps = GlobalDTPS(UsuarioActual.CveEmpresa) + ' CvePS = dtps.FiltroPrimeroValor("CvePS", Opt & " = '" & Valor & "'").ToString().ToEntero() + ' If CvePS > 0 Then + ' StrReturn = "True|" & CvePS.ToString + ' Else + ' StrReturn = "False|    - No se encontró " & Valor & " en la fila " & NumRow & ", columna " & Opt + ' End If + ' Return StrReturn + 'End Function #End Region #Region "P E D I D O S" From 05f2674191ef60eba2105cc45e21b21b1a7f782f Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Fri, 13 Mar 2020 18:42:38 -0700 Subject: [PATCH 12/14] . --- RH/CatCursos.aspx.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RH/CatCursos.aspx.vb b/RH/CatCursos.aspx.vb index f65601b07..80c664944 100644 --- a/RH/CatCursos.aspx.vb +++ b/RH/CatCursos.aspx.vb @@ -647,7 +647,7 @@ Partial Class RH_CatCursos Dim año As Integer = Year(FechaAux) Dim RutaArchivo As String = UsuarioActual.Empresa.Ruta & "\Formatos\CursoInvitacion.docx" Dim RutaLogo As String = Path.Combine(UsuarioActual.Empresa.Ruta, "Logo.png") - Dim Contenido As String = "Buen día. Estimado(a) " & _Nombres & vbLf & vbLf & vbLf & vbLf & " Por medio de la presente, el departamento de Recursos Humanos de esta " & UsuarioActual.Empresa.Empresa & " le hace la cordial invitación para asistir al curso " & _Curso & " impartido por el capacitador " & _Capacitador & ", el día " & dia & " de " & mesArray(mes - 1) & " de " & año & " en lugar " & _Ubicacion & "." & vbLf & vbLf & vbLf & vbLf & "Esperamos contar con su asistencia." + Dim Contenido As String = "Buen día. Estimado(a) " & _Nombres & vbLf & vbLf & vbLf & vbLf & " Por medio de la presente, el departamento de Capital Humano de esta " & UsuarioActual.Empresa.Empresa & " le hace la cordial invitación para asistir al curso " & _Curso & " impartido por el capacitador " & _Capacitador & ", el día " & dia & " de " & mesArray(mes - 1) & " de " & año & " en lugar " & _Ubicacion & "." & vbLf & vbLf & vbLf & vbLf & "Esperamos contar con su asistencia." If Not File.Exists(RutaArchivo) Then RutaArchivo = $"{Server.MapPath("~")}\Empresas\Grales\Formatos\CursoInvitacion.docx" @@ -778,7 +778,7 @@ Partial Class RH_CatCursos Dim ContenidoSB As New StringBuilder - ContenidoSB.Append("Buen día.
    Estimado(a) " & _Nombres & "
    Por medio de la presente el departamento de recursos humanos de la empresa le hace la cordial invitación para asistir al curso " & _Curso & " Impartido por " & _Capacitador & ". Esperamos contar con su asistencia.") + ContenidoSB.Append("Buen día.
    Estimado(a) " & _Nombres & "
    Por medio de la presente el departamento de Capital Humano de la empresa le hace la cordial invitación para asistir al curso " & _Curso & " Impartido por " & _Capacitador & ". Esperamos contar con su asistencia.") ContenidoSB.Append("

    ") ContenidoSB.AppendLine("") From 84a63520d21d30dfbf68ed8797b7371009c3ea2b Mon Sep 17 00:00:00 2001 From: JORGE LUIS CAUDILLO ESPARZA Date: Tue, 17 Mar 2020 17:47:58 -0700 Subject: [PATCH 13/14] kj --- GPS/Trayectos.aspx.vb | 2 +- vwd.webinfo | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/GPS/Trayectos.aspx.vb b/GPS/Trayectos.aspx.vb index 8e0b5654e..55d9f0f9e 100644 --- a/GPS/Trayectos.aspx.vb +++ b/GPS/Trayectos.aspx.vb @@ -185,7 +185,7 @@ Partial Class GPS_Trayectos Try Dim CveTrayecto As Integer = ObjGPS.AddTrayecto(Nombre, DateTime.Now, "", CveDispositivo, UsuarioActual.CveCliente, EnviarNotificacion:=ChkNotificacion.Checked, - CorreosNotificacion:=TxtCorreoNot.Text, Intervalo:=If(ChkNotificacion.Checked, 0, DdlIntervalo.SelectedValue.ToEntero()), + CorreosNotificacion:=TxtCorreoNot.Text, Intervalo:=If(ChkNotificacion.Checked, DdlIntervalo.SelectedValue.ToEntero(), 0), EnviarLiga:=ChkEnviarLiga.Checked) If CveTrayecto > 0 Then diff --git a/vwd.webinfo b/vwd.webinfo index a280964b8..93df9a232 100644 --- a/vwd.webinfo +++ b/vwd.webinfo @@ -21,6 +21,10 @@ + + + + From b7256ba33b7e2a09dee426e8685621e237f98bd8 Mon Sep 17 00:00:00 2001 From: JORGE LUIS CAUDILLO ESPARZA Date: Tue, 17 Mar 2020 18:17:43 -0700 Subject: [PATCH 14/14] last postaback en usuarios --- App_Code/ClsPaginas.vb | 4 +++- App_Code/Usuario.vb | 17 ++++++++++++++++- Sistemas/SessionesActivas.aspx | 12 +++++++++++- Sistemas/SessionesActivas.aspx.vb | 4 ++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/App_Code/ClsPaginas.vb b/App_Code/ClsPaginas.vb index 023ae689e..3e646964b 100644 --- a/App_Code/ClsPaginas.vb +++ b/App_Code/ClsPaginas.vb @@ -3502,7 +3502,9 @@ Public Class ClsPaginas End If If UsuarioActual.CveEmpresa = 42 Then Me.MasterPageFile = "~/Masters/Site42.master" - End If + End If + + ADSSession.ADSSessionConfig.SessionManager(ADSSession.OpcionSession.CambiarModulo, Nothing, -1, "", Request.Url.ToString()) 'If Me.Request.ServerVariables("http_user_agent").ToLower.Contains("safari") AndAlso Page.ClientTarget <> "uplevel" Then Page.ClientTarget = "uplevel" 'Código agregado para que muestre bién el menu, en chrome End If End Sub diff --git a/App_Code/Usuario.vb b/App_Code/Usuario.vb index 39b921fe9..11d6e8718 100644 --- a/App_Code/Usuario.vb +++ b/App_Code/Usuario.vb @@ -115,6 +115,7 @@ Namespace ADSSession getListasession = 3 'solo lectura CambiarEmpresa = 4 getSession = 5 + CambiarModulo = 6 End Enum Public Enum OpcionHub As Integer agregar = 1 @@ -158,7 +159,7 @@ Namespace ADSSession HttpContext.Current.Session(strsessionDpage) = value End Set End Property - Public Shared Function SessionManager(opcion As OpcionSession, Optional obj As ADSSessionObj = Nothing, Optional CveEmpresa As Integer = -1, Optional SessionID As String = Nothing) As Object + Public Shared Function SessionManager(opcion As OpcionSession, Optional obj As ADSSessionObj = Nothing, Optional CveEmpresa As Integer = -1, Optional SessionID As String = Nothing, Optional modulo As String = "") As Object SyncLock strsessionid 'todo el codigo que este dentro de este corchete no se ejecutara mas de una vez al mismo tiempo en el servidor If _dicSessionobj Is Nothing Then _dicSessionobj = New ConcurrentDictionary(Of String, ADSSessionObj) @@ -194,6 +195,18 @@ Namespace ADSSession obj.CveEmpresa = CveEmpresa End If retorno = obj + + Case OpcionSession.CambiarModulo + If Not IsNothing(HttpContext.Current) AndAlso Not IsNothing(HttpContext.Current.Session) AndAlso Not IsNothing(HttpContext.Current.Session(strsessionid)) Then + obj = DirectCast(HttpContext.Current.Session(strsessionid), ADSSessionObj) + obj.Modulo = modulo + obj.LastPostback = DateTime.Now + If _dicSessionobj.TryGetValue(obj.SessionID, obj) Then + obj.Modulo = modulo + obj.LastPostback = DateTime.Now + End If + retorno = obj + End If End Select Catch ex As Exception retorno = Nothing @@ -227,6 +240,8 @@ Namespace ADSSession End Sub Public Property CveUsuario As Integer Public Property CveEmpresa As Integer + Public Property Modulo As String + Public Property LastPostback As DateTime Protected Property _SessionID As String Private Property _ipAdrres As String Public ReadOnly Property IpAddres As String diff --git a/Sistemas/SessionesActivas.aspx b/Sistemas/SessionesActivas.aspx index 61e8ea10d..b8ba50c2f 100644 --- a/Sistemas/SessionesActivas.aspx +++ b/Sistemas/SessionesActivas.aspx @@ -67,7 +67,7 @@ - + @@ -75,6 +75,16 @@ + + + + + + + + + + diff --git a/Sistemas/SessionesActivas.aspx.vb b/Sistemas/SessionesActivas.aspx.vb index d75f57267..2139cef5a 100644 --- a/Sistemas/SessionesActivas.aspx.vb +++ b/Sistemas/SessionesActivas.aspx.vb @@ -33,6 +33,8 @@ Partial Class SessionesActivas Dim dtU As DataTable = objUsuarios.DtResultados dtU.Columns.Add("FechaSLogin", System.Type.GetType("System.DateTime")) dtU.Columns.Add("RemoteIpAddres", System.Type.GetType("System.String")) + dtU.Columns.Add("LastPostback", System.Type.GetType("System.DateTime")) + dtU.Columns.Add("Modulo", System.Type.GetType("System.String")) Dim dtF As DataTable = dtU.Clone Dim objlist As List(Of ADSSession.ADSSessionObj) = ADSSession.ADSSessionConfig.SessionManager(ADSSession.OpcionSession.getListasession) @@ -41,6 +43,8 @@ Partial Class SessionesActivas If Not IsNothing(row) Then row("FechaSLogin") = user.FechaLogin row("RemoteIpAddres") = user.IpAddres + row("LastPostback") = user.LastPostback + row("Modulo") = user.Modulo dtF.Rows.Add(row.ItemArray()) End If Next