diff --git a/Agropecuaria/CierreCultivo.aspx b/Agropecuaria/CierreCultivo.aspx index cfe196643..1766b5ce7 100644 --- a/Agropecuaria/CierreCultivo.aspx +++ b/Agropecuaria/CierreCultivo.aspx @@ -1,14 +1,11 @@ -<%@ Page Title="Catálogo de Unidades" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="CierreCultivo.aspx.vb" Inherits="Agrupecuaria_CierreCultivo" EnableEventValidation="false" %> +<%@ Page Title="Cierre de Cultivo" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="CierreCultivo.aspx.vb" Inherits="Agrupecuaria_CierreCultivo" EnableEventValidation="false" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> - @@ -18,10 +15,10 @@ - +
  • - + Cerrar Cultivo
  • @@ -33,32 +30,39 @@ -
    -
    -
    - - "> - -
    -
    -
    +
    +
    +
    + + + "> + +
    +
    +
    + +
    Temporada:
    +
    + + +
    +
    +
    + +
    + + + -
    Temporada:
    -
    - -
    - +
    +
    >
    -
    > 1 - -
    -
    - + @@ -69,15 +73,15 @@
    - - - - + + + + - - + +
    @@ -87,6 +91,53 @@ + + + + + diff --git a/Agropecuaria/CierreCultivo.aspx.vb b/Agropecuaria/CierreCultivo.aspx.vb index 9b6b4f83e..cabf77d83 100644 --- a/Agropecuaria/CierreCultivo.aspx.vb +++ b/Agropecuaria/CierreCultivo.aspx.vb @@ -1,21 +1,26 @@ -Imports Extensiones +Imports System.Data +Imports Extensiones Partial Class Agrupecuaria_CierreCultivo Inherits ClsPaginas - Private Property CveCamion As Integer + Private Property DT_Datos_Cierre As DataTable Get - If ViewState("CveCamion") Is Nothing Then - Return -1 - Else - Return ViewState("CveCamion").ToString().ToEntero() + If ViewState("DT_Datos_Cierre") Is Nothing Then + ViewState("DataTable") = New DataTable End If + + Return DirectCast(ViewState("DT_Datos_Cierre"), DataTable) + End Get - Set(ByVal value As Integer) - ViewState("CveCamion") = value + Set(ByVal value As DataTable) + ViewState("DT_Datos_Cierre") = value End Set End Property + + + Private Sub Agrupecuaria_CierreCultivo_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then CargaCombos() @@ -36,6 +41,9 @@ Partial Class Agrupecuaria_CierreCultivo UpFiltros.Update() + + CargarCentrosDeCosto(Nothing, DdlSubProyectoCierreCultivo, Nothing, LblSubProyecto, "Seleccione Uno") + End Sub @@ -51,10 +59,14 @@ Partial Class Agrupecuaria_CierreCultivo If ObjGral.GetCierreCultivos(DdlTemporada.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then GvDatos.DataSource = ObjGral.DtResultados + DT_Datos_Cierre = ObjGral.DtResultados Else GvDatos.DataSource = Nothing + DT_Datos_Cierre = Nothing End If + OcultarmostrarControles(DT_Datos_Cierre) + ObjGral.Dispose() GvDatos.DataBind() UpDatos.Update() @@ -63,16 +75,66 @@ Partial Class Agrupecuaria_CierreCultivo End Sub - Private Sub CierraCultivo() - - End Sub - - - - - - Protected Sub btConsultar_Click(sender As Object, e As EventArgs) CargaDatos() End Sub + + Protected Sub LnkAccionesCerrarCultivo_Click(sender As Object, e As EventArgs) + + + + RegistraScript("$('#DivModalCerrarCultivo').modal('show');") + UpModalCerrarCultivo.Update() + + + End Sub + + + Public Sub OcultarmostrarControles(ByRef DTCierreCultivos As DataTable) + + If DTCierreCultivos IsNot Nothing AndAlso DTCierreCultivos.Rows.Count > 0 Then + LnkAccionesCerrarCultivo.Visible = True + Else + LnkAccionesCerrarCultivo.Visible = False + End If + + UpAcciones.Update() + + End Sub + + + Private Sub CierraCultivo() + + Dim ObjConta As New ClsContabilidad() + ObjConta.IniciaTransacSQL() + Dim CvePrePoliza As Integer = -1 + Dim ErrorProceso As Boolean = False + + Dim CveSubProyecto As Integer = DdlSubProyectoCierreCultivo.SelectedValue.ToEntero + + + Dim ImporteCierre As Decimal = DT_Datos_Cierre.SUMD("Importe") + + CvePrePoliza = ObjConta.AddPrePolizas("CierreCultivo/Cerrar", 1, ImporteCierre, ImporteCierre, 1, TxtmodalFechaCierreCultivo.Text.ToDate, $"Cierre Temporada {DdlTemporada.Text}", 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 + + Else + ErrorProceso = True + End If + + + If ErrorProceso Then + ObjConta.RollBack() + Else + ObjConta.Commit() + + RegistraScript("$('#DivModalCerrarCultivo').modal('hide');") + End If + + ObjConta.Dispose() + + End Sub + + End Class diff --git a/App_Code/ClsGenerales.vb b/App_Code/ClsGenerales.vb index c530e3297..73df9a9aa 100644 --- a/App_Code/ClsGenerales.vb +++ b/App_Code/ClsGenerales.vb @@ -4070,7 +4070,7 @@ Public Class ClsGenerales .Add("@Cantidad", SqlDbType.Float).Value = Cantidad .Add("@CveUnidadMedida", SqlDbType.Int).Value = CveUnidadMedida .Add("@CveUsuario", SqlDbType.Int).Value = CveUsuario - .Add("@PesoKg", SqlDbType.SmallMoney).Value = CveUsuario + .Add("@PesoKg", SqlDbType.SmallMoney).Value = PesoKg End With diff --git a/App_Code/ClsInventarios.vb b/App_Code/ClsInventarios.vb index 318ff16ff..926d626e3 100644 --- a/App_Code/ClsInventarios.vb +++ b/App_Code/ClsInventarios.vb @@ -13,6 +13,7 @@ Public Class ClsInventarios Private SqlAdapter As SqlDataAdapter Private SqlTransacc As SqlTransaction Private Data As DataTable + Private Dataset As DataSet Private disposedValue As Boolean = False ' Para detectar llamadas redundantes 'REGISTRAR CONEXIONES ABIERTAS @@ -140,6 +141,12 @@ Public Class ClsInventarios End Get End Property + Public ReadOnly Property DataSetResultados() As DataSet + Get + DataSetResultados = DataSet + End Get + End Property + #End Region Sub New(Optional TransaccionCompartida As SqlTransaction = Nothing) @@ -5875,6 +5882,27 @@ Public Class ClsInventarios End Function #End Region +#Region "JAM - POG" + Public Function GetJAM_BASF_POG(Fecha As Date) As Boolean + Dim Retorno As Boolean = False + Dataset = New DataSet() + DataAdapter("PA_JAM_BASF_POG") + With SqlAdapter.SelectCommand.Parameters + .Add("@Fecha", SqlDbType.Date).Value = Fecha + End With + + Try + SqlAdapter.Fill(Dataset) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al obtener las existencias.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno + + End Function +#End Region + #Region " IDisposable Support " ' IDisposable Protected Overridable Sub Dispose(ByVal disposing As Boolean) @@ -5882,6 +5910,7 @@ Public Class ClsInventarios If disposing Then ' TODO: Liberar otro estado (objetos administrados). If Not Data Is Nothing Then Data.Dispose() : Data = Nothing + If Not Dataset Is Nothing Then Dataset.Dispose() : Dataset = Nothing If Not SqlAdapter Is Nothing Then SqlAdapter.Dispose() : SqlAdapter = Nothing If Not SqlTransacc Is Nothing Then SqlTransacc.Dispose() : SqlTransacc = Nothing If SqlConexion.State <> ConnectionState.Closed Then SqlConexion.Close() diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index c9e847174..37ac787cc 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -379,7 +379,7 @@ Namespace Modelos End If Timbre = New CFDITimbre End Sub - Public Sub New(UsuarioActual As Usuario, CveVenta As Integer, CveEmpresa As Integer, Optional DirectorioServidor As String = "", Optional EsCancelacion As Boolean = False) + Public Sub New(UsuarioActual As Usuario, CveVenta As Integer, CveEmpresa As Integer, Optional DirectorioServidor As String = "", Optional EsCancelacion As Boolean = False, Optional CargaDTDetalle As Boolean = True, Optional CargaDatosCliente As Boolean = True, Optional CargaDatosRelacionados As Boolean = True) Me.UsuarioActual = UsuarioActual Me.CveVenta = CveVenta Me.CveEmpresa = CveEmpresa @@ -397,9 +397,12 @@ Namespace Modelos SetMetodoPago() SetMoneda() - SetSubProyecto() - SetSubProyectoMatriz() - SetCliente() + + If Me.CveSubProyecto > 0 Then + SetSubProyecto() + SetSubProyectoMatriz() + End If + If ObjVentas.DtResultados.Rows(0)("IEPS").ToString.ToDecimal <= 0 Then Me.VentaDesglosaIEPS = False Else @@ -408,11 +411,23 @@ Namespace Modelos SetTotales(ObjVentas.DtResultados, ObjVentas) End If End If - If ObjVentas.GetVentaDetalle(CveVenta) Then - Me.DtDetalle = ObjVentas.DtResultados.Copy() + + If CargaDTDetalle Then + If ObjVentas.GetVentaDetalle(CveVenta) Then + Me.DtDetalle = ObjVentas.DtResultados.Copy() + End If End If + ObjVentas.Dispose() - IniciaValoresVentas(EsCancelacion) + + If CargaDatosCliente Then + SetCliente() + End If + + If CargaDatosRelacionados Then + IniciaValoresVentas(EsCancelacion) + End If + If String.IsNullOrEmpty(DirectorioServidor) Then DirectorioServidor = ModExtensiones.DirectorioBaseEmpresas End If @@ -5543,11 +5558,11 @@ Namespace Modelos End If If SaldoAlmacenExA <> 0 Then - 'If Not CancelarMovimientosRemision(CveRemision, CveAlmacen, CveAlmacenDevolucion, DtDevRemision.FiltraParametros($"CveMovimiento={RowDevolucion("CveMovimiento")}"), ObjVentas, ObjInventario) Then - ' ErrorCancelar = True - ' MensajeError = "Ocurrió un error al cancelar los movimientos de la remisión." - ' Exit For - 'End If + If Not CancelarMovimientosRemision(CveRemision, CveAlmacen, CveAlmacenDevolucion, DtDevRemision.FiltraParametros($"CveMovimiento={RowDevolucion("CveMovimiento")}"), ObjVentas, ObjInventario, ObjConta) Then + ErrorCancelar = True + MensajeError = "Ocurrió un error al cancelar los movimientos de la remisión." + Exit For + End If End If Next @@ -5665,11 +5680,11 @@ Namespace Modelos For Each RowDevolucion As DataRow In DtDevMovs.Rows CveAlmacen = RowDevolucion("CveAlmacen").ToString().ToEntero() - 'If Not CancelarMovimientosRemision(CveVenta, CveAlmacen, CveAlmacenGeneral, DtMovRemision.FiltraParametros($"CveMovimiento={RowDevolucion("CveMovimiento")} AND CvePS > 0"), ObjVentas, ObjInventario) Then - ' ErrorCancelar = True - ' MensajeError = "Ocurrió un error al cancelar los movimientos de la remisión." - ' Exit For - 'End If + If Not CancelarMovimientosRemision(CveVenta, CveAlmacen, CveAlmacenGeneral, DtMovRemision.FiltraParametros($"CveMovimiento={RowDevolucion("CveMovimiento")} AND CvePS > 0"), ObjVentas, ObjInventario, ObjConta) Then + ErrorCancelar = True + MensajeError = "Ocurrió un error al cancelar los movimientos de la remisión." + Exit For + End If Next End If @@ -6639,7 +6654,7 @@ Namespace Modelos Public Property ObservacionesAlmacen As String Public Property CveOC As Integer = -1 Public Property CveCuentaTerminal As Integer = -1 - Public Property ClienteEsDistribuidor As Boolean = False + Public Property EsDistribuidor As Boolean = False Public Property AplicaGastoContrato As Boolean = False Public Property FacturaDevolucion As Modelos.Factura Public Property CveOrdenProduccion As Integer = -1 @@ -7065,7 +7080,7 @@ Namespace Modelos Public Sub SetSubProyecto() If CveSubProyecto > 0 AndAlso UsuarioActual IsNot Nothing Then - SubProyecto = New Modelos.SubProyectoModel(GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero($"CveSubProyecto = {CveSubProyecto}")) + SubProyecto = New Modelos.SubProyectoModel(GlobalDTSubProyectos(-1, CveSubProyecto:=CveSubProyecto, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero("")) End If End Sub Public Sub SetSubProyectoMatriz() diff --git a/App_Code/Timbrado.vb b/App_Code/Timbrado.vb index cf660b490..94e8e4207 100644 --- a/App_Code/Timbrado.vb +++ b/App_Code/Timbrado.vb @@ -600,7 +600,6 @@ Public Class Timbrado Dim Clave As String = Empresa.ContraseñaKey Dim UrlServicio As String = "" ' Produccion - 'UrlServicio = "http://juancalderon-001-site1.ftempurl.com/timbrado.asmx?WSDL" 'UrlServicio = "http://alterno.gofac.com.mx/cfdi/timbrado.asmx?WSDL" ' alterno UrlServicio = "https://cfdi.gofac.com.mx/timbrado.asmx?WSDL" @@ -1138,10 +1137,10 @@ Public Class Timbrado Equivalencia = 1 'condiciones especiales para el pago en pesos, facturas en moneda extranjera ElseIf MonedaPago = "MXN" AndAlso VentaAbreviaturaSAT <> "MXN" Then - VentaTipoCambio = VentaTipoCambio.RoundSQL(6) - Equivalencia = (1 / VentaTipoCambio).RoundSQL(6) + VentaTipoCambio = Math.Round(VentaTipoCambio, 6) + Equivalencia = Math.Round((1 / VentaTipoCambio), 6) ElseIf MonedaPago = "USD" AndAlso VentaAbreviaturaSAT <> "USD" Then - VentaTipoCambio = VentaTipoCambio.RoundSQL(6) + VentaTipoCambio = Math.Round(VentaTipoCambio, 6) Equivalencia = VentaTipoCambio End If @@ -1167,8 +1166,8 @@ Public Class Timbrado .TasaOCuota = drp("PorcentajeImpuesto").ToString().ToDecimal, .Impuesto = drp("TipoImpuesto").ToString, .Importe = drp("Importe").ToString().ToDecimal.RoundSQL, - .BaseMN = (drp("Base").ToString.ToDecimal / Equivalencia).RoundSQL(2), - .ImporteMN = (drp("Importe").ToString.ToDecimal / Equivalencia).RoundSQL(2) + .BaseMN = Math.Round((drp("Base").ToString.ToDecimal / Equivalencia), 2), + .ImporteMN = Math.Round((drp("Importe").ToString.ToDecimal / Equivalencia), 2) } ) @@ -2235,7 +2234,6 @@ Public Class Timbrado Case 2 UrlServicio = "http://generacfdi.com.mx/rvltimbrado/service1.asmx?WSDL" 'productivo Case 4 - 'UrlServicio = "http://juancalderon-001-site1.ftempurl.com/timbrado.asmx?WSDL" 'UrlServicio = "http://alterno.gofac.com.mx/cfdi/timbrado.asmx?WSDL" ' alterno UrlServicio = "https://cfdi.gofac.com.mx/timbrado.asmx?WSDL" End Select @@ -2260,7 +2258,7 @@ Public Class Timbrado Case 4 UsuarioServicio = "UserTest" ClaveServicio = "1234567890" - UrlServicio = "http://juancalderon-001-site1.ftempurl.com/timbrado.asmx?WSDL" + UrlServicio = "https://cfdi.gofac.com.mx/timbrado.asmx" End Select End If @@ -4074,52 +4072,11 @@ Public Class Timbrado #Region " Complemento Pago" If ObjCFDITimbre.Comprobante.TipoComprobante = "P" Then - Dim ComPag = New Profact.TimbraCFDI40.Complementos.Pagos20.Pagos() - ComPag.Pago = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPago(0) {} - ComPag.Pago(0) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPago() - ComPag.Pago(0).FechaPago = ObjCFDITimbre.ComplementoPagos.FechaPago.ToString("yyyy-MM-ddTHH:mm:ss").ToDate() - ComPag.Pago(0).FormaDePagoP = ObjCFDITimbre.ComplementoPagos.FormaDePagoP - ComPag.Pago(0).MonedaP = ObjCFDITimbre.ComplementoPagos.MonedaP - ComPag.Pago(0).TipoCambioPSpecified = True 'If(ObjCFDITimbre.ComplementoPagos.MonedaP = "MXN", False, True) - ComPag.Pago(0).TipoCambioP = ObjCFDITimbre.ComplementoPagos.TipoCambioP - ComPag.Pago(0).Monto = ObjCFDITimbre.ComplementoPagos.Monto - If ObjCFDITimbre.ComplementoPagos.NumOperacion <> "" Then - ComPag.Pago(0).NumOperacion = ObjCFDITimbre.ComplementoPagos.NumOperacion - End If - If ObjCFDITimbre.ComplementoPagos.RfcEmisorCtaOrd <> "" Then - ComPag.Pago(0).RfcEmisorCtaOrd = ObjCFDITimbre.ComplementoPagos.RfcEmisorCtaOrd - End If - If ObjCFDITimbre.ComplementoPagos.NomBancoOrdExt <> "" Then - ComPag.Pago(0).NomBancoOrdExt = ObjCFDITimbre.ComplementoPagos.NomBancoOrdExt - End If - If ObjCFDITimbre.ComplementoPagos.CtaOrdenante <> "" Then - ComPag.Pago(0).CtaOrdenante = ObjCFDITimbre.ComplementoPagos.CtaOrdenante - End If - If ObjCFDITimbre.ComplementoPagos.RfcEmisorCtaBen <> "" Then - ComPag.Pago(0).RfcEmisorCtaBen = ObjCFDITimbre.ComplementoPagos.RfcEmisorCtaBen - End If - If ObjCFDITimbre.ComplementoPagos.CtaBeneficiario <> "" Then - ComPag.Pago(0).CtaBeneficiario = ObjCFDITimbre.ComplementoPagos.CtaBeneficiario - End If - If ObjCFDITimbre.ComplementoPagos.TipoCadPago <> "" Then - ComPag.Pago(0).TipoCadPagoSpecified = True - ComPag.Pago(0).TipoCadPago = ObjCFDITimbre.ComplementoPagos.TipoCadPago - End If - If ObjCFDITimbre.ComplementoPagos.CertPago <> "" Then - ComPag.Pago(0).CertPago = System.Text.Encoding.Default.GetBytes(ObjCFDITimbre.ComplementoPagos.CertPago).ToString() - End If - If ObjCFDITimbre.ComplementoPagos.CadPago <> "" Then - ComPag.Pago(0).CadPago = ObjCFDITimbre.ComplementoPagos.CadPago - End If - If ObjCFDITimbre.ComplementoPagos.SelloPago <> "" Then - ComPag.Pago(0).SelloPago = System.Text.Encoding.Default.GetBytes(ObjCFDITimbre.ComplementoPagos.SelloPago).ToString() - End If + If ObjCFDITimbre.ComplementoPagos20.ComplementoPagos.Count > 0 Then - If ObjCFDITimbre.ComplementoPagos.DocumentosRelacionados.Count > 0 Then - Dim Totales As New Profact.TimbraCFDI40.Complementos.Pagos20.PagosTotales() - 'Totales Generales + Dim Totales As New Profact.TimbraCFDI40.Complementos.Pagos20.PagosTotales() 'Totales Generales Totales.MontoTotalPagos = ObjCFDITimbre.ComplementoPagos20.MontoTotalPagos.RoundSQL @@ -4137,6 +4094,7 @@ Public Class Timbrado Totales.TotalTrasladosBaseIVA0Specified = Totales.TotalTrasladosBaseIVA0 > 0 Totales.TotalTrasladosImpuestoIVA0 = 0 Totales.TotalTrasladosImpuestoIVA0Specified = Totales.TotalTrasladosBaseIVA0 > 0 ' si hay base > 0, debe de ponerse aunque sea en cero + If ObjCFDITimbre.ComplementoPagos20.TotalRetencionesIEPS > 0 Then Totales.TotalRetencionesIEPS = ObjCFDITimbre.ComplementoPagos20.TotalRetencionesIEPS.RoundSQL Totales.TotalRetencionesIEPSSpecified = True @@ -4144,105 +4102,141 @@ Public Class Timbrado Totales.TotalRetencionesIEPSSpecified = False End If + Dim ComPag = New Profact.TimbraCFDI40.Complementos.Pagos20.Pagos() + ComPag.Totales = Totales + ComPag.Pago = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPago(ObjCFDITimbre.ComplementoPagos20.ComplementoPagos.Count - 1) {} + Dim ii As Integer = 0 + For Each docp As CFDIComplementoPago In ObjCFDITimbre.ComplementoPagos20.ComplementoPagos - ComPag.Pago(0).DoctoRelacionado = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionado(ObjCFDITimbre.ComplementoPagos.DocumentosRelacionados.Count - 1) {} - Dim i As Integer - For Each doc As CFDIComplementoPagosDocsRelacionados In ObjCFDITimbre.ComplementoPagos.DocumentosRelacionados - ComPag.Pago(0).DoctoRelacionado(i) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionado() - ComPag.Pago(0).DoctoRelacionado(i).IdDocumento = doc.IdDocumento - If Not String.IsNullOrEmpty(doc.Serie) Then - ComPag.Pago(0).DoctoRelacionado(i).Serie = doc.Serie + ComPag.Pago(ii) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPago() + ComPag.Pago(ii).FechaPago = docp.FechaPago.ToString("yyyy-MM-ddTHH:mm:ss").ToDate() + ComPag.Pago(ii).FormaDePagoP = docp.FormaDePagoP + ComPag.Pago(ii).MonedaP = docp.MonedaP + ComPag.Pago(ii).TipoCambioPSpecified = True 'If(ObjCFDITimbre.ComplementoPagos.MonedaP = "MXN", False, True) + ComPag.Pago(ii).TipoCambioP = docp.TipoCambioP + ComPag.Pago(ii).Monto = docp.Monto + If docp.NumOperacion <> "" Then ComPag.Pago(ii).NumOperacion = docp.NumOperacion + + If docp.RfcEmisorCtaOrd <> "" Then ComPag.Pago(ii).RfcEmisorCtaOrd = docp.RfcEmisorCtaOrd + + If docp.NomBancoOrdExt <> "" Then ComPag.Pago(ii).NomBancoOrdExt = docp.NomBancoOrdExt + + If docp.CtaOrdenante <> "" Then ComPag.Pago(ii).CtaOrdenante = docp.CtaOrdenante + + If docp.RfcEmisorCtaBen <> "" Then ComPag.Pago(ii).RfcEmisorCtaBen = docp.RfcEmisorCtaBen + + If docp.CtaBeneficiario <> "" Then ComPag.Pago(ii).CtaBeneficiario = docp.CtaBeneficiario + + If docp.TipoCadPago <> "" Then + ComPag.Pago(ii).TipoCadPagoSpecified = True + ComPag.Pago(ii).TipoCadPago = docp.TipoCadPago End If - ComPag.Pago(0).DoctoRelacionado(i).Folio = doc.Folio - ComPag.Pago(0).DoctoRelacionado(i).MonedaDR = doc.MonedaDR - ComPag.Pago(0).DoctoRelacionado(i).NumParcialidad = doc.NumParcialidad.ToString - ComPag.Pago(0).DoctoRelacionado(i).ImpSaldoAnt = doc.ImpSaldoAnt.RoundSQL - ComPag.Pago(0).DoctoRelacionado(i).ImpPagadoSpecified = True - ComPag.Pago(0).DoctoRelacionado(i).ImpPagado = doc.ImpPagado.RoundSQL - ComPag.Pago(0).DoctoRelacionado(i).ImpSaldoInsoluto = doc.ImpSaldoInsoluto.RoundSQL - ComPag.Pago(0).DoctoRelacionado(i).EquivalenciaDR = doc.EquivalenciaDR.RoundSQL(6) - ComPag.Pago(0).DoctoRelacionado(i).EquivalenciaDRSpecified = True - ComPag.Pago(0).DoctoRelacionado(i).ObjetoImpDR = doc.ObjetoImpuesto - If doc.Impuestos IsNot Nothing Then - ComPag.Pago(0).DoctoRelacionado(i).ImpuestosDR = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDR + If docp.CertPago <> "" Then ComPag.Pago(ii).CertPago = System.Text.Encoding.Default.GetBytes(docp.CertPago).ToString() - ''retenciones - If (doc.Impuestos).Where(Function(x) x.TrasladooRetencion = "R").Count > 0 Then - Dim j As Integer = 0 - ComPag.Pago(0).DoctoRelacionado(i).ImpuestosDR.RetencionesDR = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDRRetencionDR(doc.Impuestos.Where(Function(x) x.TrasladooRetencion = "R").Count - 1) {} + If docp.CadPago <> "" Then ComPag.Pago(ii).CadPago = docp.CadPago - For Each docimp As CFDIConceptosImpuestos In doc.Impuestos.Where(Function(x) x.TrasladooRetencion = "R") - If docimp.TrasladooRetencion = "R" Then - Dim Tra As New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDRRetencionDR - Tra.BaseDR = docimp.Base.RoundSQL(2) - Tra.ImporteDR = docimp.Importe.RoundSQL(2) - Tra.ImpuestoDR = docimp.Impuesto - Tra.TipoFactorDR = docimp.TipoFactor - Tra.TasaOCuotaDR = docimp.TasaOCuota.RoundSQL(6) - ComPag.Pago(0).DoctoRelacionado(i).ImpuestosDR.RetencionesDR(j) = Tra - End If - j += 1 + If docp.SelloPago <> "" Then ComPag.Pago(ii).SelloPago = System.Text.Encoding.Default.GetBytes(docp.SelloPago).ToString() + + ComPag.Pago(ii).DoctoRelacionado = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionado(docp.DocumentosRelacionados.Count - 1) {} + + Dim i As Integer + For Each doc As CFDIComplementoPagosDocsRelacionados In docp.DocumentosRelacionados + ComPag.Pago(ii).DoctoRelacionado(i) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionado() + ComPag.Pago(ii).DoctoRelacionado(i).IdDocumento = doc.IdDocumento + If Not String.IsNullOrEmpty(doc.Serie) Then + ComPag.Pago(ii).DoctoRelacionado(i).Serie = doc.Serie + End If + ComPag.Pago(ii).DoctoRelacionado(i).Folio = doc.Folio + ComPag.Pago(ii).DoctoRelacionado(i).MonedaDR = doc.MonedaDR + ComPag.Pago(ii).DoctoRelacionado(i).NumParcialidad = doc.NumParcialidad.ToString + ComPag.Pago(ii).DoctoRelacionado(i).ImpSaldoAnt = doc.ImpSaldoAnt.RoundSQL + ComPag.Pago(ii).DoctoRelacionado(i).ImpPagadoSpecified = True + ComPag.Pago(ii).DoctoRelacionado(i).ImpPagado = doc.ImpPagado.RoundSQL + ComPag.Pago(ii).DoctoRelacionado(i).ImpSaldoInsoluto = doc.ImpSaldoInsoluto.RoundSQL + ComPag.Pago(ii).DoctoRelacionado(i).EquivalenciaDR = doc.EquivalenciaDR.RoundSQL(6) + ComPag.Pago(ii).DoctoRelacionado(i).EquivalenciaDRSpecified = True + ComPag.Pago(ii).DoctoRelacionado(i).ObjetoImpDR = doc.ObjetoImpuesto + + If doc.Impuestos IsNot Nothing Then + ComPag.Pago(ii).DoctoRelacionado(i).ImpuestosDR = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDR + + ''retenciones + If (doc.Impuestos).Where(Function(x) x.TrasladooRetencion = "R").Count > 0 Then + Dim j As Integer = 0 + ComPag.Pago(ii).DoctoRelacionado(i).ImpuestosDR.RetencionesDR = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDRRetencionDR(doc.Impuestos.Where(Function(x) x.TrasladooRetencion = "R").Count - 1) {} + + For Each docimp As CFDIConceptosImpuestos In doc.Impuestos.Where(Function(x) x.TrasladooRetencion = "R") + If docimp.TrasladooRetencion = "R" Then + Dim Tra As New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDRRetencionDR + Tra.BaseDR = docimp.Base.RoundSQL(2) + Tra.ImporteDR = docimp.Importe.RoundSQL(2) + Tra.ImpuestoDR = docimp.Impuesto + Tra.TipoFactorDR = docimp.TipoFactor + Tra.TasaOCuotaDR = docimp.TasaOCuota.RoundSQL(6) + ComPag.Pago(ii).DoctoRelacionado(i).ImpuestosDR.RetencionesDR(j) = Tra + End If + j += 1 + Next + End If + + ''traslados + If (doc.Impuestos).Where(Function(x) x.TrasladooRetencion = "T").Count > 0 Then + Dim j As Integer = 0 + ComPag.Pago(ii).DoctoRelacionado(i).ImpuestosDR.TrasladosDR = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDRTrasladoDR(doc.Impuestos.Where(Function(x) x.TrasladooRetencion = "T").Count - 1) {} + + For Each docimp As CFDIConceptosImpuestos In doc.Impuestos.Where(Function(x) x.TrasladooRetencion = "T") + + If docimp.TrasladooRetencion = "T" Then + Dim Tra As New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDRTrasladoDR + Tra.BaseDR = docimp.Base.RoundSQL(2) + Tra.ImporteDRSpecified = True + Tra.ImporteDR = docimp.Importe.RoundSQL(2) + Tra.ImpuestoDR = docimp.Impuesto + Tra.TipoFactorDR = docimp.TipoFactor + Tra.TasaOCuotaDRSpecified = True + Tra.TasaOCuotaDR = docimp.TasaOCuota.RoundSQL(6) + ComPag.Pago(ii).DoctoRelacionado(i).ImpuestosDR.TrasladosDR(j) = Tra + End If + j += 1 + Next + End If + End If + i += 1 + Next + + If docp.Retenciones.Count > 0 OrElse docp.Traslados.Count > 0 Then + ComPag.Pago(ii).ImpuestosP = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosP(0) {} + ComPag.Pago(ii).ImpuestosP(0) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosP() + + If docp.Retenciones.Count > 0 Then + Dim x As Integer + ComPag.Pago(ii).ImpuestosP(0).RetencionesP = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosPRetencionP(docp.Retenciones.Count - 1) {} + For Each Ret As CFDIRetenciones In ObjCFDITimbre.ComplementoPagos.Retenciones + ComPag.Pago(ii).ImpuestosP(0).RetencionesP(x) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosPRetencionP() + ComPag.Pago(ii).ImpuestosP(0).RetencionesP(x).ImpuestoP = Ret.Impuesto + ComPag.Pago(ii).ImpuestosP(0).RetencionesP(x).ImporteP = Ret.ImporteMN + x += 1 Next End If - ''traslados - If (doc.Impuestos).Where(Function(x) x.TrasladooRetencion = "T").Count > 0 Then - Dim j As Integer = 0 - ComPag.Pago(0).DoctoRelacionado(i).ImpuestosDR.TrasladosDR = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDRTrasladoDR(doc.Impuestos.Where(Function(x) x.TrasladooRetencion = "T").Count - 1) {} - - For Each docimp As CFDIConceptosImpuestos In doc.Impuestos.Where(Function(x) x.TrasladooRetencion = "T") - - If docimp.TrasladooRetencion = "T" Then - Dim Tra As New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoDoctoRelacionadoImpuestosDRTrasladoDR - Tra.BaseDR = docimp.Base.RoundSQL(2) - Tra.ImporteDRSpecified = True - Tra.ImporteDR = docimp.Importe.RoundSQL(2) - Tra.ImpuestoDR = docimp.Impuesto - Tra.TipoFactorDR = docimp.TipoFactor - Tra.TasaOCuotaDRSpecified = True - Tra.TasaOCuotaDR = docimp.TasaOCuota.RoundSQL(6) - ComPag.Pago(0).DoctoRelacionado(i).ImpuestosDR.TrasladosDR(j) = Tra - End If - j += 1 + If docp.Traslados.Count > 0 Then + Dim x As Integer + ComPag.Pago(ii).ImpuestosP(0).TrasladosP = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosPTrasladoP(docp.Traslados.Count - 1) {} + For Each Tra As CFDITraslados In (docp.Traslados) + ComPag.Pago(ii).ImpuestosP(0).TrasladosP(x) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosPTrasladoP() + ComPag.Pago(ii).ImpuestosP(0).TrasladosP(x).ImpuestoP = Tra.Impuesto + ComPag.Pago(ii).ImpuestosP(0).TrasladosP(x).TipoFactorP = Tra.TipoFactor + ComPag.Pago(ii).ImpuestosP(0).TrasladosP(x).TasaOCuotaP = Tra.TasaOCuota.RoundSQL(6) + ComPag.Pago(ii).ImpuestosP(0).TrasladosP(x).ImporteP = Tra.ImporteMN.RoundSQL(6) + ComPag.Pago(ii).ImpuestosP(0).TrasladosP(x).BaseP = Tra.BaseMN.RoundSQL(2) + x += 1 Next End If End If - i += 1 Next - If (ObjCFDITimbre.ComplementoPagos.Retenciones).Count > 0 OrElse ObjCFDITimbre.ComplementoPagos.Traslados.Count > 0 Then - ComPag.Pago(0).ImpuestosP = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosP(0) {} - ComPag.Pago(0).ImpuestosP(0) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosP() - - If (ObjCFDITimbre.ComplementoPagos.Retenciones).Count > 0 Then - Dim x As Integer - ComPag.Pago(0).ImpuestosP(0).RetencionesP = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosPRetencionP((ObjCFDITimbre.ComplementoPagos.Retenciones).Count - 1) {} - For Each Ret As CFDIRetenciones In ObjCFDITimbre.ComplementoPagos.Retenciones - ComPag.Pago(0).ImpuestosP(0).RetencionesP(x) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosPRetencionP() - ComPag.Pago(0).ImpuestosP(0).RetencionesP(x).ImpuestoP = Ret.Impuesto - ComPag.Pago(0).ImpuestosP(0).RetencionesP(x).ImporteP = Ret.ImporteMN - x += 1 - Next - End If - - If ObjCFDITimbre.ComplementoPagos.Traslados.Count > 0 Then - Dim x As Integer - ComPag.Pago(0).ImpuestosP(0).TrasladosP = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosPTrasladoP((ObjCFDITimbre.ComplementoPagos.Traslados).Count - 1) {} - For Each Tra As CFDITraslados In (ObjCFDITimbre.ComplementoPagos.Traslados) - ComPag.Pago(0).ImpuestosP(0).TrasladosP(x) = New Profact.TimbraCFDI40.Complementos.Pagos20.PagosPagoImpuestosPTrasladoP() - ComPag.Pago(0).ImpuestosP(0).TrasladosP(x).ImpuestoP = Tra.Impuesto - ComPag.Pago(0).ImpuestosP(0).TrasladosP(x).TipoFactorP = Tra.TipoFactor - ComPag.Pago(0).ImpuestosP(0).TrasladosP(x).TasaOCuotaP = Tra.TasaOCuota.RoundSQL(6) - ComPag.Pago(0).ImpuestosP(0).TrasladosP(x).ImporteP = Tra.ImporteMN.RoundSQL(6) - ComPag.Pago(0).ImpuestosP(0).TrasladosP(x).BaseP = Tra.BaseMN.RoundSQL(2) - x += 1 - Next - End If - End If - - Dim nsComp As New System.Xml.Serialization.XmlSerializerNamespaces() nsComp.Add("pago20", "http://www.sat.gob.mx/Pagos20") Dim xmlComp As String = Profact.TimbraCFDI.XMLUtilerias.SerializaObjeto(ComPag, GetType(Profact.TimbraCFDI40.Complementos.Pagos20.Pagos), nsComp) diff --git a/Ashx/E119.ashx b/Ashx/E119.ashx new file mode 100644 index 000000000..2c1abbc0b --- /dev/null +++ b/Ashx/E119.ashx @@ -0,0 +1,303 @@ +<%@ WebHandler Language="VB" Class="E119" %> + +Option Strict On +Option Explicit On + +Imports System.Data +Imports System.IO +Imports System.Net.Http +Imports Newtonsoft.Json +Imports Newtonsoft.Json.Linq +Imports Extensiones + +Public Class E119 : Implements IHttpHandler + + Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable + Get + Return False + End Get + End Property + + Private ReadOnly Property CveEmpresa As Integer = 119 + + Public ReadOnly Property EsProduccion As Boolean + Get + If IsNothing(System.Configuration.ConfigurationManager.AppSettings("EsProduccion")) Then + Return False + Else + Return (System.Configuration.ConfigurationManager.AppSettings("EsProduccion").ToString() = "1") + End If + End Get + End Property + Public ReadOnly Property UsuarioWSE119 As String + Get + If IsNothing(System.Configuration.ConfigurationManager.AppSettings("UsuarioWSE119")) Then + Return "" + Else + Return System.Configuration.ConfigurationManager.AppSettings("UsuarioWSE119").ToString() + End If + End Get + End Property + Public ReadOnly Property PasswordWSE119 As String + Get + If IsNothing(System.Configuration.ConfigurationManager.AppSettings("PasswordWSE119")) Then + Return "" + Else + Return System.Configuration.ConfigurationManager.AppSettings("PasswordWSE119").ToString() + End If + End Get + End Property + Public ReadOnly Property TokenAutorizacion As String + Get + Return "$2y$10$LGqtRWUloKQmAt.jcUldc.PmS5LJ6l.WU2w1G4PBOTLMVKZRNQFPS" + End Get + End Property + + Public ReadOnly Property URLBase As String + Get + Return "https://services.fidelityapps.mx/" + End Get + End Property + + +#Region "V A L I D A - D A T O S" + Private Function ValidaUsuarioSistema(CveUsuario As Integer, CveEmpresa As Integer) As Usuario + Dim UsuarioActual As Usuario = Nothing + Dim ObjUsuarios As New ClsSisUsuarios + If ObjUsuarios.GetUsuarios(CveUsuario) Then + If ObjUsuarios.DtResultados.Rows.Count > 0 Then + Dim Usuario = ObjUsuarios.DtResultados.Rows(0)("Usuario").ToString() + Dim Contrasenia = ObjUsuarios.DtResultados.Rows(0)("Contraseña").ToString() + UsuarioActual = ObjUsuarios.ValidaUsuario(Usuario, Contrasenia, IMEI, CveEmpresa) + UsuarioActual.CveEmpresa = CveEmpresa + CreaObjetoEmpresa(UsuarioActual) + End If + End If + ObjUsuarios.Dispose() + Return UsuarioActual + End Function + Private Sub CreaObjetoEmpresa(ByRef UsuarioActual As Usuario) + Dim ObjEmpresa As New ClsSisEmpresas() + If ObjEmpresa.GetEmpresas(UsuarioActual.CveEmpresa, "-1", "-1", "-1", "-1") Then + If ObjEmpresa.GetEmpresasFuncionalidades(UsuarioActual.CveEmpresa) Then + Dim dttmp As Data.DataTable = ObjEmpresa.DtResultados + + Dim EmpresasFuncionalidades As New HybridDictionary + For Each Row As Data.DataRow In dttmp.Rows + EmpresasFuncionalidades.Add(Convert.ToInt32(Row("CveFuncionalidad")), Row("Valor").ToString) + Next + ObjEmpresa.Empresa.SetFuncionalidades(EmpresasFuncionalidades) + End If + + UsuarioActual.Empresa = ObjEmpresa.Empresa + End If + ObjEmpresa.Dispose() + End Sub +#End Region + + Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest + Dim retorno As String = "" + Try + Dim Metodo = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString()) + 'OBTENER EXISTENCIAS + If Metodo = "ConsultaBASF_POG" Then + context.Response.ContentType = "application/json" + Dim Auth = ValidarSolicitud(context) + + If Auth.IsSucces Then + retorno = ConsultaDatos(context) + Else + context.Response.StatusCode = Auth.StatusCode + retorno = JsonConvert.SerializeObject(Auth.ErrorMessage) + End If + + End If + + context.Response.Write(retorno) + + Catch ex As Exception + context.Response.ContentType = "text/html" + retorno = ex.ToString() + ex.GuardaLog(ex.ToString()) + + context.Response.Write(retorno) + End Try + End Sub + + Private Function ValidarSolicitud(ByVal context As HttpContext) As AuthMessage + Dim unauthorized As Boolean = True + Dim respuesta As New AuthMessage + + Dim authHeader = context.Request.Headers("Authorization") + If authHeader IsNot Nothing Then + Dim basicAuth As String = authHeader.Replace("Basic ", "") + + Dim usernamePasswordArray = Encoding.UTF8.GetString(Convert.FromBase64String(basicAuth)).Split(":"c) + + Dim userName = usernamePasswordArray(0) + Dim password = usernamePasswordArray(1) + unauthorized = Not (userName = Me.UsuarioWSE119 AndAlso password = Me.PasswordWSE119) + + Else + respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña son requeridos"} + respuesta.IsSucces = False + respuesta.StatusCode = 200 + + Return respuesta + End If + + If unauthorized Then + respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña no son validos"} + respuesta.IsSucces = False + respuesta.StatusCode = 200 + + Return respuesta + Else + respuesta.ErrorMessage = Nothing + respuesta.IsSucces = True + respuesta.StatusCode = 200 + + Return respuesta + End If + + End Function + + + Private Function ConsultaDatos(ByVal context As HttpContext) As String + Dim Respuesta As New ResponseMsg + Dim RespuestaError As New ResponseMsgError + Dim TieneError As Boolean = False + + Dim strFecha = If(context.Request("Fecha") = Nothing, "", context.Request("Fecha").ToString()) + + If String.IsNullOrEmpty(strFecha) Then + RespuestaError.message = "Debe especificar una fecha" + context.Response.StatusCode = 200 + Return JsonConvert.SerializeObject(RespuestaError) + End If + + If Not IsDate(strFecha) Then + RespuestaError.message = "La fecha no tiene el formato correcto" + context.Response.StatusCode = 200 + Return JsonConvert.SerializeObject(RespuestaError) + End If + + Dim Fecha As DateTime = strFecha.ToDateTime() + Dim Facturas As JArray = Nothing + Dim Stock As JArray = Nothing + + If Fecha > MinFecha Then + Using ObjInventario As New ClsInventarios + If ObjInventario.GetJAM_BASF_POG(Fecha) AndAlso ObjInventario.DataSetResultados IsNot Nothing Then + Facturas = JArray.Parse(ObjInventario.DataSetResultados.Tables(0).DataTableToJSONIPP()) + Stock = JArray.Parse(ObjInventario.DataSetResultados.Tables(1).DataTableToJSONIPP()) + Else + RespuestaError.message = "no se pudo obtener los datos" + TieneError = True + End If + End Using + Else + RespuestaError.message = "la fecha no es leida correctamente" + TieneError = True + End If + + If TieneError Then + context.Response.StatusCode = 200 + Return JsonConvert.SerializeObject(RespuestaError) + Else + context.Response.StatusCode = 200 + Try + Respuesta.data = New JObject(New JProperty("Facturas", Facturas), New JProperty("Stock", Stock)) + Respuesta.message = "Los datos se obtuvieron correctamente" + Return JsonConvert.SerializeObject(Respuesta) + Catch ex As Exception + RespuestaError.message = "Ocurrió un error al generar la petición" + Return JsonConvert.SerializeObject(RespuestaError) + End Try + + End If + End Function + + Private Class ResponseMsg + Sub New() + status = "success" + End Sub + Public Property status As String + Public Property data As Object + Public Property message As String + End Class + + Private Class ResponseMsgError + Sub New() + status = "error" + End Sub + Public Property status As String + Public Property message As String + End Class + + Private Class AuthMessage + Public Property IsSucces As Boolean + Public Property ErrorMessage As ResponseMsgError + Public Property StatusCode As Integer + End Class + + 'Private Function ActualizarExistenciasJson(Todos As Boolean) As String + ' Dim payload = New JObject() + + ' Dim CountPeticiones As Integer = 0, CountPeticionesExitosas As Integer = 0 + + ' Dim DtPS As DataTable = Nothing + ' Using ObjPS As New ClsProductosServicios + ' If ObjPS.GetExistenciasEmpresa("-1", CveEmpresa) Then + ' DtPS = ObjPS.DtResultados.Copy() + ' End If + ' End Using + + ' If DtPS IsNot Nothing Then + ' payload.Add(New JProperty("stock", GenerarPayloadExistencias(DtPS))) + ' End If + + ' Return payload.ToString() + 'End Function + + + + Private Function Parametros(Cadena As String) As Hashtable + Dim P1() As String = Cadena.Split("&"c) + Dim Tmp As String + Dim P2() As String + + Dim URLParametros As New Hashtable + + For Each Tmp In P1 + P2 = Tmp.Replace("%26%", "&").Split("="c) + URLParametros.Add(P2(0).ToString.ToUpper, P2(1)) + Next + Return URLParametros + End Function + + Private Shared Function IsValidJson(ByVal strInput As String) As Boolean + If String.IsNullOrWhiteSpace(strInput) Then + Return False + End If + + strInput = strInput.Trim() + + If (strInput.StartsWith("{") AndAlso strInput.EndsWith("}")) OrElse (strInput.StartsWith("[") AndAlso strInput.EndsWith("]")) Then + + Try + Dim obj = JToken.Parse(strInput) + Return True + Catch jex As JsonReaderException + Console.WriteLine(jex.Message) + Return False + Catch ex As Exception + Console.WriteLine(ex.ToString()) + Return False + End Try + Else + Return False + End If + End Function + +End Class \ No newline at end of file diff --git a/Compras/Compras.aspx b/Compras/Compras.aspx index 6497c6564..198291fb2 100644 --- a/Compras/Compras.aspx +++ b/Compras/Compras.aspx @@ -734,7 +734,7 @@ - + <%-- 0 --%> @@ -773,7 +773,7 @@ - + <%-- 6 --%> @@ -4389,10 +4389,10 @@
    -
    +
    - diff --git a/Compras/Compras.aspx.vb b/Compras/Compras.aspx.vb index 98e73dc6e..1d54b6c32 100644 --- a/Compras/Compras.aspx.vb +++ b/Compras/Compras.aspx.vb @@ -1324,7 +1324,7 @@ Partial Class Compras_Compras If Request("CveCompra") IsNot Nothing AndAlso IsNumeric(Request("CveCompra")) AndAlso Request("CveCompra").ToEntero > 0 Then extrafiltro = "" End If - DdlCultivosCuadro.DataSource = GlobalDTCultivosCuadro(UsuarioActual.CveEmpresa).FiltraParametros($"{extrafiltro} CveSubProyecto = {DdlSubProyecto.SelectedValue}") + DdlCultivosCuadro.DataSource = GlobalDTCultivosCuadro(UsuarioActual.CveEmpresa).FiltraParametros($"{extrafiltro} CveSubProyecto = {DdlSubProyecto.SelectedValue}", "TemporadaCuadro") DdlCultivosCuadro.DataBind() DdlCultivosCuadro.Items.Insert(0, New ListItem("Seleccione uno", "-1")) @@ -10927,18 +10927,27 @@ Partial Class Compras_Compras If Version = "3.3" OrElse Version = "4.0" Then For Each traslado As XmlNode In nodeTraslados - If traslado.Attributes("Impuesto").Value = "002" Then TrasladoIVA += traslado.Attributes("Importe").Value.ToDecimal - If traslado.Attributes("Impuesto").Value = "003" Then TrasladoIEPS += traslado.Attributes("Importe").Value.ToDecimal + If traslado.Attributes("Importe") IsNot Nothing Then + If traslado.Attributes("Impuesto").Value = "002" Then TrasladoIVA += traslado.Attributes("Importe").Value.ToDecimal + If traslado.Attributes("Impuesto").Value = "003" Then TrasladoIEPS += traslado.Attributes("Importe").Value.ToDecimal + End If + + Next Else For Each traslado As XmlNode In nodeTraslados - If traslado.Attributes("impuesto").Value = "IVA" Then TrasladoIVA += traslado.Attributes("importe").Value.ToDecimal - If traslado.Attributes("impuesto").Value = "IEPS" Then TrasladoIEPS += traslado.Attributes("importe").Value.ToDecimal + + If traslado.Attributes("Importe") IsNot Nothing Then + If traslado.Attributes("impuesto").Value = "IVA" Then TrasladoIVA += traslado.Attributes("importe").Value.ToDecimal + + If traslado.Attributes("impuesto").Value = "IEPS" Then TrasladoIEPS += traslado.Attributes("importe").Value.ToDecimal + End If + Next End If @@ -11439,6 +11448,7 @@ Partial Class Compras_Compras TmpDT.Columns.Add("CveContratoDetalle", GetType(Integer)) TmpDT.Columns.Add("CveCultivoCuadroDetalle", GetType(Integer)) + TmpDT.Columns.Add("TemporadaCuadro", GetType(String)) TmpDTOriginal = New DataTable TmpDTOriginal.Columns.Add("Consec", GetType(Integer)) @@ -11548,6 +11558,7 @@ Partial Class Compras_Compras TmpDTOriginal.Columns.Add("Importe", GetType(Double)) TmpDTOriginal.Columns.Add("CveContratoDetalle", GetType(Double)) TmpDTOriginal.Columns.Add("CveCultivoCuadroDetalle", GetType(Double)) + TmpDTOriginal.Columns.Add("TemporadaCuadro", GetType(String)) End Sub @@ -17767,6 +17778,9 @@ Partial Class Compras_Compras 'DdlProyecto.SelectedValueExist(GvRow.DataKey("CveProyecto")) DdlSubProyecto.SelectedValueExist(GvRow.DataKey("CveSubProyecto")) + + DdlSubProyecto_SelectedIndexChanged(Nothing, Nothing) + DdlTipoGasto.SelectedValueExist(GvRow.DataKey("CveTipoGasto")) Dim PS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlPS.SelectedValue.ToEntero).FiltroPrimero("") @@ -17817,6 +17831,7 @@ Partial Class Compras_Compras DVModalAddPSChkDesvincularAF.Visible = True End If + DdlCultivosCuadro.SelectedValueExist(GvRow.DataKey("CveCultivoCuadroDetalle")) UpPSS.Update() RegistraScript("$('#divAddProducto').modal('show');") @@ -17903,7 +17918,7 @@ Partial Class Compras_Compras extrafiltro = "" End If DdlCultivosCuadro.Items.Clear() - DdlCultivosCuadro.DataSource = GlobalDTCultivosCuadro(UsuarioActual.CveEmpresa).FiltraParametros($"{extrafiltro} CveSubProyecto = {DdlSubProyecto.SelectedValue}") + DdlCultivosCuadro.DataSource = GlobalDTCultivosCuadro(UsuarioActual.CveEmpresa).FiltraParametros($"{extrafiltro} CveSubProyecto = {DdlSubProyecto.SelectedValue}", "TemporadaCuadro") DdlCultivosCuadro.DataBind() DdlCultivosCuadro.Items.Insert(0, New ListItem("Seleccione uno", "-1")) @@ -18194,7 +18209,8 @@ Partial Class Compras_Compras AddPS(TxtCantidad.Text.Trim.ToDecimal, 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.ToDecimal, Total, IVA, TxtRetIVAModal.Text.ToDecimal / 100, TxtRetISRModal.Text.ToDecimal / 100, TxtIEPSModal.Text.ToDecimal / 100, 0, TxtDescuentoModal.Text.ToDecimal, OtrosGastos:=TxtOtrosGastos.Text.ToDecimal, CveTipoGasto:=DdlTipoGasto.SelectedValue.ToEntero, TipoGasto:=DdlTipoGasto.SelectedItem.Text, - NoDeducible:=ChkEsNoDeduciblePS.Checked, CveSATPS:=SATClavePS, CveContratoDetalle:=CveContratoDetalle) + NoDeducible:=ChkEsNoDeduciblePS.Checked, CveSATPS:=SATClavePS, CveContratoDetalle:=CveContratoDetalle, + CveCultivoCuadroDetalle:=If(DdlCultivosCuadro.SelectedValue.ToEntero > 0, DdlCultivosCuadro.SelectedValue.ToEntero, -1), TemporadaCuadro:=If(DdlCultivosCuadro.SelectedValue.ToEntero > 0, DdlCultivosCuadro.SelectedItem.Text, "")) AddPS2() LimpiaAgregar() @@ -18266,7 +18282,8 @@ Partial Class Compras_Compras Obs As String, PU As Decimal, Total As Decimal, IVA As Decimal, RetIVA As Decimal, RetISR As Decimal, IEPSPS As Decimal, IEPSPSIVA As Decimal, Descuento As Decimal, 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 Decimal = 0, Optional CveSATPS As Integer = -1, Optional CargaXml As Boolean = False, Optional CveTipoGasto As Integer = -1, Optional TipoGasto As String = "", Optional PorcentajeIVA As Decimal = 0, - Optional PorcentajeIEPS As Decimal = 0, Optional PorcentajeRetIVA As Decimal = 0, Optional PorcentajeRetISR As Decimal = 0, Optional NoDeducible As Boolean = False, Optional CveContratoDetalle As Integer = -1, Optional CveCultivoCuadroDetalle As Integer = -1, Optional CveSATPSActualizado As Boolean = False) As Integer + Optional PorcentajeIEPS As Decimal = 0, Optional PorcentajeRetIVA As Decimal = 0, Optional PorcentajeRetISR As Decimal = 0, Optional NoDeducible As Boolean = False, Optional CveContratoDetalle As Integer = -1, Optional CveCultivoCuadroDetalle As Integer = -1, + Optional CveSATPSActualizado As Boolean = False, Optional TemporadaCuadro As String = "") As Integer Dim Row As DataRow = Nothing @@ -18374,8 +18391,17 @@ Partial Class Compras_Compras Row("PU") = Math.Round(PU, DecimalesPermitidos) If CargaXml And (Version = "3.3" Or Version = "4.0") Then - Row("IVA") = Math.Round(IVA, DecimalesPermitidos) - Row("IVAPorcentaje") = PorcentajeIVA + + If CveFactura > 0 And TxtIVA.Text.ToDecimal = 0 Then + Row("IVA") = 0 + Row("IVAPorcentaje") = 0 + Else + Row("IVA") = Math.Round(IVA, DecimalesPermitidos) + Row("IVAPorcentaje") = PorcentajeIVA + End If + + + Row("RetIVA") = Math.Round(RetIVA, DecimalesPermitidos) Row("RetIVAPorcentaje") = PorcentajeRetIVA Row("RetISR") = Math.Round(RetISR, DecimalesPermitidos) @@ -18384,8 +18410,16 @@ Partial Class Compras_Compras Row("IEPSPSPorcentaje") = PorcentajeIEPS Else 'If DdlIVA.SelectedValue.ToDouble = 0 Then Row("IVA") = 0 Else Row("IVA") = Math.Round(IVA * Total, DecimalesPermitidos) - Row("IVA") = (IVA * Total).RoundSQL - Row("IVAPorcentaje") = IVA + + If CveFactura > 0 And TxtIVA.Text.ToDecimal = 0 Then + Row("IVA") = 0 + Row("IVAPorcentaje") = 0 + Else + Row("IVA") = (IVA * Total).RoundSQL + Row("IVAPorcentaje") = IVA + End If + + Row("RetIVA") = (RetIVA * Total).RoundSQL Row("RetIVAPorcentaje") = RetIVA Row("RetISR") = (RetISR * Total).RoundSQL @@ -18408,6 +18442,7 @@ Partial Class Compras_Compras Row("CveContratoDetalle") = CveContratoDetalle Row("CveCultivoCuadroDetalle") = CveCultivoCuadroDetalle + Row("TemporadaCuadro") = TemporadaCuadro If UsuarioActual.Empresa.UsaAC Then Row("CveProgramaOperativo") = DdlACGeneral1.SelectedValue.ToEntero @@ -18436,7 +18471,9 @@ Partial Class Compras_Compras 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 @@ -18549,8 +18586,15 @@ Partial Class Compras_Compras 'I f 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).RoundSQL - DrPS("IVAPorcentaje") = IVA + + If CveFactura > 0 And TxtIVA.Text.ToDecimal = 0 Then + DrPS("IVA") = 0 + DrPS("IVAPorcentaje") = 0 + Else + DrPS("IVA") = (IVA * Total).RoundSQL + DrPS("IVAPorcentaje") = IVA + End If + DrPS("RetIVA") = (RetIVA * Total).RoundSQL DrPS("RetIVAPorcentaje") = RetIVA DrPS("RetISR") = RetISR * Total @@ -18560,6 +18604,12 @@ Partial Class Compras_Compras DrPS("IEPSPSIVA") = (IEPSPSIVA * Total).RoundSQL DrPS("IEPSPSIVAPorcentaje") = IEPSPSIVA + DrPS("CveCultivoCuadroDetalle") = If(DdlCultivosCuadro.SelectedValue.ToEntero > 0, DdlCultivosCuadro.SelectedValue.ToEntero, -1) + DrPS("TemporadaCuadro") = If(DdlCultivosCuadro.SelectedValue.ToEntero > 0, DdlCultivosCuadro.SelectedItem.Text, "") + + + + 'Esta parte es para validar cuando la factura tenga ieps en o se asignara el ieps como una partida ya no se considere If (CveFactura > 0 Or CveCompra > 0) And TxtIEPS.Text.ToDecimal = 0 Then diff --git a/Compras/RepComprasAF.aspx.vb b/Compras/RepComprasAF.aspx.vb index 87a10b5f0..aa9cb1ed9 100644 --- a/Compras/RepComprasAF.aspx.vb +++ b/Compras/RepComprasAF.aspx.vb @@ -138,6 +138,8 @@ Partial Class Compras_RepComprasAF LblSubProyecto.Text = "Sucursal" End If + CargaPS(-1) + End Sub Private Sub DdlTipoActivoFijo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlTipoActivoFijo.SelectedIndexChanged @@ -209,18 +211,15 @@ Partial Class Compras_RepComprasAF FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim(), "-1") FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim(), "-1") Dim PS As String = DdlPS.txtText.Value - Dim CvePS As String = DdlPS.txtValue.Value - If CvePS = "" Or CvePS = "0" Then - CvePS = "-1" - End If + Dim CvePS As Integer = DdlPS.txtValue.Value.ToEntero If e.Row.DBCampo("Orden") = "1" Then - Dim Liga As String = $"/Compras/RepComprasAFDetalle.aspx?GPO={DdlGrupo.SelectedValue}&Anio={e.Row.DBCampo("Anio")}&Mes={e.Row.DBCampo("Mes")}&AnioMes={ e.Row.DBCampo("AnioMes")}&Fecha={e.Row.DBCampo("Fecha")}&CveProveedor={ e.Row.DBCampo("CveProveedor")}&CveActivoFijo={e.Row.DBCampo("CveActivoFijo")}&CveTipoActivoFijo={e.Row.DBCampo("CveTipoActivoFijo")}&CveSubTipoActivoFijo={e.Row.DBCampo("CveSubTipoActivoFijo")}&CveProyecto={ DdlProyecto.SelectedValue}&CveSubProyecto={DdlSubProyecto.SelectedValue}&CvePS={CvePS}&CveClasificacion={e.Row.DBCampo("CveClasificacion")}&CveMoneda={ e.Row.DBCampo("CveMoneda")}&FechaI={FechaI}&FechaF={FechaF}&PS={PS}&CveClasificacion2={e.Row.DBCampo("CveClasificacion2")}" + Dim Liga As String = $"/Compras/RepComprasAFDetalle.aspx?GPO={DdlGrupo.SelectedValue}&Anio={e.Row.DBCampo("Anio")}&Mes={e.Row.DBCampo("Mes")}&AnioMes={ e.Row.DBCampo("AnioMes")}&Fecha={e.Row.DBCampo("Fecha")}&CveProveedor={ e.Row.DBCampo("CveProveedor")}&CveActivoFijo={e.Row.DBCampo("CveActivoFijo")}&CveTipoActivoFijo={e.Row.DBCampo("CveTipoActivoFijo")}&CveSubTipoActivoFijo={e.Row.DBCampo("CveSubTipoActivoFijo")}&CveProyecto={ DdlProyecto.SelectedValue}&CveSubProyecto={DdlSubProyecto.SelectedValue}&CvePS={ If(CvePS > 0, CvePS.ToString, e.Row.DBCampo("CvePS").ToString) }&CveClasificacion={e.Row.DBCampo("CveClasificacion")}&CveMoneda={ e.Row.DBCampo("CveMoneda")}&FechaI={FechaI}&FechaF={FechaF}&PS={PS}&CveClasificacion2={e.Row.DBCampo("CveClasificacion2")}" e.Row.Cells(0).Text = String.Format("{2}", "Texto", Liga, e.Row.DataKey("GPO").ToString) Else e.Row.BackColor = Drawing.Color.LightGray - Dim Liga As String = $"/Compras/RepComprasAFDetalle.aspx?GPO=-1&Anio={e.Row.DBCampo("Anio")}&Mes={e.Row.DBCampo("Mes")}&AnioMes={ e.Row.DBCampo("AnioMes")}&Fecha={e.Row.DBCampo("Fecha")}&CveProveedor={ e.Row.DBCampo("CveProveedor")}&CveActivoFijo={e.Row.DBCampo("CveActivoFijo")}&CveTipoActivoFijo={e.Row.DBCampo("CveTipoActivoFijo")}&CveSubTipoActivoFijo={e.Row.DBCampo("CveSubTipoActivoFijo")}&CveProyecto={ DdlProyecto.SelectedValue}&CveSubProyecto={DdlSubProyecto.SelectedValue}&CvePS={CvePS}&CveClasificacion={e.Row.DBCampo("CveClasificacion")}&CveMoneda={ e.Row.DBCampo("CveMoneda")}&FechaI={FechaI}&FechaF={FechaF}&PS={PS}&CveClasificacion2={e.Row.DBCampo("CveClasificacion2")}" + Dim Liga As String = $"/Compras/RepComprasAFDetalle.aspx?GPO=-1&Anio={e.Row.DBCampo("Anio")}&Mes={e.Row.DBCampo("Mes")}&AnioMes={ e.Row.DBCampo("AnioMes")}&Fecha={e.Row.DBCampo("Fecha")}&CveProveedor={ e.Row.DBCampo("CveProveedor")}&CveActivoFijo={e.Row.DBCampo("CveActivoFijo")}&CveTipoActivoFijo={e.Row.DBCampo("CveTipoActivoFijo")}&CveSubTipoActivoFijo={e.Row.DBCampo("CveSubTipoActivoFijo")}&CveProyecto={ DdlProyecto.SelectedValue}&CveSubProyecto={DdlSubProyecto.SelectedValue}&CvePS={ If(CvePS > 0, CvePS.ToString, e.Row.DBCampo("CvePS").ToString)}&CveClasificacion={e.Row.DBCampo("CveClasificacion")}&CveMoneda={ e.Row.DBCampo("CveMoneda")}&FechaI={FechaI}&FechaF={FechaF}&PS={PS}&CveClasificacion2={e.Row.DBCampo("CveClasificacion2")}" e.Row.Cells(0).Text = String.Format("{2}", "Texto", Liga, e.Row.DataKey("Moneda").ToString) @@ -476,7 +475,12 @@ Partial Class Compras_RepComprasAF If Not UsuarioActual.Empresa.Funcionalidad(105).ToString = "1" Then DdlPS.ddl.Items.Clear() - DdlPS.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacion, Estatus:=1) + + If CveClasificacion > 0 Then + DdlPS.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacion, Estatus:=1) + End If + + DdlPS.ddl.DataBind() DdlPS.ddl.Items.Insert(0, New ListItem("*** Actualizar listado de Productos o Servicios ***", "-2")) DdlPS.ddl.Items.Insert(0, New ListItem("Seleccione el Producto", "-1")) diff --git a/Empresas/13/Formatos/Factura.rdlc b/Empresas/13/Formatos/Factura.rdlc index d10956995..5c642c501 100644 --- a/Empresas/13/Formatos/Factura.rdlc +++ b/Empresas/13/Formatos/Factura.rdlc @@ -662,7 +662,7 @@ - + true true @@ -674,13 +674,19 @@ 7pt + + + + - Codigo1 + SATClaveProdServ - SATClaveProdServ + Codigo