diff --git a/App_Code/ClsInventarios.vb b/App_Code/ClsInventarios.vb index 8cc4b1e42..e21615b2c 100644 --- a/App_Code/ClsInventarios.vb +++ b/App_Code/ClsInventarios.vb @@ -3232,6 +3232,32 @@ Public Class ClsInventarios Return Retorno End Function + + Public Function GetProductosDevolucion(CvePS As Integer, CveCliente As Integer, CveSubProyecto As Integer, FechaInicio As DateTime, FechaFin As DateTime, Serie As String, Lote As String, FechaCaducidad As DateTime, CveEmpresa As Integer) As Boolean + Dim Retorno As Boolean = False + DataAdapter("PA_Vta_ProductosDevolucionAlmacen") + + With SqlAdapter.SelectCommand.Parameters + .Add("@CvePS", SqlDbType.Int).Value = CvePS + .Add("@CveCliente", SqlDbType.Int).Value = CveCliente + .Add("@CveSubProyecto", SqlDbType.Int).Value = CvePS + .Add("@FechaInicio", SqlDbType.DateTime).Value = FechaInicio + .Add("@FechaFin", SqlDbType.DateTime).Value = FechaFin + .Add("@Serie", SqlDbType.VarChar).Value = Serie + .Add("@Lote", SqlDbType.VarChar).Value = Lote + .Add("@FechaCaducidad", SqlDbType.DateTime).Value = FechaCaducidad + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al obtener datos de devolución.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno + End Function Public Function GetSaldoVentaDetalle(CveVenta As Integer, CveEmpresa As Integer) As Boolean Dim Retorno As Boolean = False DataAdapter("PA_Vta_VentaDetalleSaldo") diff --git a/App_Code/ClsPaginas.vb b/App_Code/ClsPaginas.vb index b3d91f4c4..856644c2e 100644 --- a/App_Code/ClsPaginas.vb +++ b/App_Code/ClsPaginas.vb @@ -4681,6 +4681,7 @@ Public Class ClsPaginas PaginaDict.Add("/Inventarios/EntregasPorRealizar.aspx".ToUpper(), 728) PaginaDict.Add("/Inventarios/CatAlmacenClasificacionSecciones.aspx".ToUpper(), 764) PaginaDict.Add("/Inventarios/ReconstruirCostos.aspx".ToUpper(), 764) + PaginaDict.Add("/Inventarios/RecepcionDevolucion.aspx".ToUpper(), 696) #End Region diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index adda24263..f57554961 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -1507,10 +1507,17 @@ Namespace Modelos Row("CveVentaDetalle") = ObjVentas.CveVentaDetalle If DtInventario IsNot Nothing Then - If DtInventario.Select($"CvePS={Row("CvePS").ToString.ToEntero}").Length > 0 Then - Dim rowInv As DataRow = DtInventario.Select($"CvePS={Row("CvePS").ToString.ToEntero}")(0) - rowInv("CveVentaDetalle") = ObjVentas.CveVentaDetalle - End If + 'If DtInventario.Select($"CvePS={Row("CvePS").ToString.ToEntero}").Length > 0 Then + ' Dim rowInv As DataRow = DtInventario.Select($"CvePS={Row("CvePS").ToString.ToEntero}")(0) + ' rowInv("CveVentaDetalle") = ObjVentas.CveVentaDetalle + 'End If + + Try + Dim InvDr As DataRow = DtInventario.Select($"Consec = {Row("Consec").ToString()}")(0) + InvDr("CveVentaDetalle") = ObjVentas.CveVentaDetalle + Catch ex As Exception + End Try + End If If DtRecepcionUsados IsNot Nothing Then @@ -1738,7 +1745,7 @@ Namespace Modelos GuardarVentaPrePolizas(factura, ObjConta, TmpDTDetalle, CveNCaVincular, objContPaqi, ObjBancos, ObjVentas, ObjEventos:=ObjEventos, ObjInventario:=ObjInventario) If ErrorList.Count = 0 Then 'inventarios - GuardarVentaInventarios(factura, ObjInventario, ObjConta, ObjVentas, ObjAcum) + GuardarVentaInventarios(Resp, factura, ObjInventario, ObjConta, ObjVentas, ObjAcum) 'GuardaRecepcionUsados(factura, ObjInventario, ObjConta) @@ -2142,7 +2149,7 @@ Namespace Modelos For Each drow As DataRow In ObjFactura.DtPolizasVirtuales.Rows If ObjAcum.AddPolizaVirtual(ObjFactura.CveVenta, drow("CveVentaDetalle").ToString().ToEntero(), drow("CvePS").ToString.ToEntero, drow("Cantidad").ToString.ToDecimal, drow("PU").ToString.ToDecimal, drow("Descuento").ToString.ToDecimal, drow("Total").ToString.ToDecimal, drow("TipoServicio").ToString.ToEntero, drow("TipoPoliza").ToString.ToEntero, drow("CveModeloAuto").ToString.ToEntero, drow("AnioVehiculo").ToString.ToEntero, CBool(drow("TieneUsado").ToString), - drow("FechaUsado").ToString().ToDateTime, drow("CvePSUsado").ToString.ToEntero, drow("CveBCIUsado").ToString.ToEntero) Then + drow("FechaUsado").ToString().ToDateTime, drow("CvePSUsado").ToString.ToEntero, drow("CveBCIUsado").ToString.ToEntero, drow("CveMarcaUsado").ToString.ToEntero) Then Else Resultado = False Exit For @@ -3709,7 +3716,7 @@ Namespace Modelos Return OcurrioError End Function - Private Function GuardarVentaInventarios(ByRef factura As Modelos.Factura, ObjInventario As ClsInventarios, ObjConta As ClsContabilidad, ObjVentas As ClsVentas, ObjAcum As ClsAcumuladores) As Boolean + Private Function GuardarVentaInventarios(ByRef Resp As MMensajeFactura, ByRef factura As Modelos.Factura, ObjInventario As ClsInventarios, ObjConta As ClsContabilidad, ObjVentas As ClsVentas, ObjAcum As ClsAcumuladores) As Boolean Dim OcurrioError As Boolean = False If UsuarioActual.Empresa.UsaInventarios AndAlso factura.TipoDocto.Contiene("Ing", "Egs", "Rem") Then @@ -3751,6 +3758,24 @@ Namespace Modelos End If + 'SI ES UNA RNC DE CARGO GENERA EL MOVIMIENTO DE ALMACEN AQUI + If factura.TipoDocto = "RNC" AndAlso factura.Num3 = 10 Then + Dim CveMovimiento = GenerarMovimientoAlmacenDevolucionRNC(ObjInventario, factura, DtInventario, factura.CveAlmacen, factura.CveConceptoMovimiento, factura.CveMoneda, factura.CveVenta, "Modelos/RNC1") + If CveMovimiento <= 0 Then + OcurrioError = True + Else + If Resp IsNot Nothing Then + Resp.CveMovimientoUsado = CveMovimiento + + If CveMovimiento > 0 Then + If ObjInventario.GetMovimientos(CveMovimiento, -1, -1, UsuarioActual.CveEmpresa) Then + Resp.FolioUsado = ObjInventario.DtResultados.FiltroPrimeroValor("Folio") + End If + End If + End If + End If + End If + Return OcurrioError End Function Private Function CuadrarFacturaMovimientos(MovDetalle As DataTable) As DataTable @@ -4158,6 +4183,148 @@ Namespace Modelos Return CveMovimientoInventario End Function + Private Function GenerarMovimientoAlmacenDevolucionRNC(ByRef ObjInventario As ClsInventarios, ByRef factura As Modelos.Factura, DtInventario As DataTable, CveAlmacen As Integer, CveConcepto As Integer, CveMoneda As Integer, CveVenta As Integer, Modulo As String, Optional MovimientoPrePoliza As Boolean = False, Optional ByRef ObjConta As ClsContabilidad = Nothing, Optional CveMovimientoRelacionado As Integer = -1) As Integer + Dim OcurrioError As Boolean = False + + Dim CveMovimientoInventario As Integer = ObjInventario.AddMovimiento(CveAlmacen, CveConcepto, factura.CveMoneda, factura.Fecha, -1, factura.CveUsuario, factura.CveEmpresa, -1, factura.CveVenta, -1, -1, Modulo:=Modulo, CveMovimientoRelacionado:=CveMovimientoRelacionado) + + If CveMovimientoInventario <= 0 Then + OcurrioError = True + ErrorList.Add("Ocurrió un error al agregar los Movimientos de salida al Inventario.
Revise su factura y cualquier detalle comuníquese a Soporte Técnico") + Else + If CveMovimientoRelacionado > 0 Then + If ObjInventario.GetMovimientosDetalle(CveMovimientoRelacionado, UsuarioActual.CveEmpresa) Then + + For Each Dr As DataRow In ObjInventario.DtResultados.Rows + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoInventario, Dr("Cantidad").ToString().ToDouble, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then + OcurrioError = True + ErrorList.Add("Ocurrió un Error al guardar los movimientos de entrada") + Exit For + End If + Next + + End If + Else + Dim Mensaje As String = "" + Dim i As Integer = 0 + + Dim Cantidad As Decimal = 0 + Dim PU As Decimal = 0 + Dim CveUM As Integer = 0 + Dim CvePS As Integer = 0 + + Dim AplicaSerie As Boolean + Dim AplicaLote As Boolean + Dim AplicaCaducidad As Boolean + + Dim Serie As String = "" + Dim Lote As String = "" + Dim FechaCaducidad As DateTime = MinFecha + + For Each Dr As DataRow In DtInventario.Rows + + CvePS = Dr("CvePS").ToString.ToEntero + CveUM = Dr("CveUM").ToString.ToEntero + Cantidad = Dr("Cantidad").ToString.ToDecimal + PU = Dr("PU").ToString.ToDecimal + + AplicaSerie = CBool(Dr("AplicaSerie")) + Serie = If(AplicaSerie, Dr("Serie").ToString, "") + + AplicaLote = CBool(Dr("AplicaLote")) + Lote = If(AplicaLote, Dr("Lote").ToString, "") + + AplicaCaducidad = CBool(Dr("AplicaCaducidad")) + FechaCaducidad = If(AplicaCaducidad, Dr("FechaCaducidad").ToString.ToDateTime, MinFecha) + + If Dr("CveTipoInvPS").ToString.ToEntero = 5 AndAlso AplicaSerie AndAlso Serie = "" Then + OcurrioError = True + ErrorList.Add("Se deben especificar las Series de los productos de almacén") + Exit For + End If + + If CvePS > 0 Then + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoInventario, Cantidad, CveUM, CvePS, PU, CveSeccionAlmacen:=-3, Serie:=Serie, Lote:=Lote, FechaCaducidad:=FechaCaducidad, CveVentaDetalle:=Dr("CveVentaDetalle").ToString.ToEntero) Then + OcurrioError = True + ErrorList.Add("Ocurrió un error al agregar los Movimientos de salida al Inventario.
") + Exit For + End If + Else + OcurrioError = True + ErrorList.Add("Ocurrió un error al agregar los Movimientos de salida al Inventario.
") + Exit For + End If + + + i = i + 1 + Next + End If + + 'REGISTRO LA PREPOLIZA DE COSTO VS ALMACEN + If MovimientoPrePoliza AndAlso Not OcurrioError Then + Dim DtCostos As DataTable = Nothing + Dim ValorInventario As Decimal = 0 + Dim TotalCosto As Decimal = 0 + + Dim TipoMovto68 As Boolean = True + Dim TipoMovto69 As Boolean = False + + If CveConcepto.Contiene(18, 41) Then + TipoMovto68 = False + TipoMovto69 = True + End If + + If ObjInventario.GetMovimientosDetalle(CveMovimientoInventario, UsuarioActual.CveEmpresa) Then + DtCostos = ObjInventario.DtResultados + TotalCosto = DtCostos.SUMD("Total").RoundSQL + Dim tmpCostos As DataTable = DtCostos.FiltraParametros("", "", {"CveClasificacion"}) + Dim IdCtaContable As Integer = 0 + Dim CveCuenta As Integer = 0 + If tmpCostos.Rows.Count > 0 Then + Dim TotalCostoAcumulado As Decimal = 0 + Dim cont As Integer = 1 + 'Se agrega movimiento separado por la cuenta de ventas (ER) + For Each RowInv As DataRow In tmpCostos.Rows + ValorInventario = DtCostos.SUMD("Total", $"CveClasificacion = {RowInv("CveClasificacion")}").RoundSQL + TotalCostoAcumulado += ValorInventario + + 'cuando es el último movimiento y hay diferencias en los importes + If cont = tmpCostos.Rows.Count AndAlso TotalCosto <> TotalCostoAcumulado Then + ValorInventario = ValorInventario + (TotalCosto - TotalCostoAcumulado) + End If + + 'Concepto = String.Format("{0} - {1}", Row2("Clasificacion").ToString(), Row2("SubProyecto").ToString()) + IdCtaContable = GlobalDTClasificaciones(factura.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {RowInv("CveClasificacion")}").ToEntero() + 'CveCuenta = GlobalDTClasificaciones(factura.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", $"CveClasificacion = {RowInv("CveClasificacion")}").ToEntero() + 'If ValorInventario <> 0 Then + + If Not ObjConta.AddPrePolizasDetalle(factura.CvePrePoliza, TipoMovto69, ValorInventario, factura.SerieFolio, 69, factura.SerieFolio, factura.Fecha, IdCtaContable, -1, CveVenta:=factura.CveVenta, CveCliente:=factura.CveCliente, CveSubProyecto:=factura.CveSubProyecto, CveClasificacion:=RowInv("CveClasificacion").ToString().ToEntero(), CveMovimientoAlmacen:=CveMovimientoInventario, ImporteMX:=ValorInventario, CveCuenta:=CveCuenta) Then + OcurrioError = True + End If + 'End If + cont += 1 + Next + End If + IdCtaContable = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", String.Format("CveAlmacen = {0}", CveAlmacen)).ToEntero() + + 'If TotalCosto <> 0 Then + If Not ObjConta.AddPrePolizasDetalle(factura.CvePrePoliza, TipoMovto68, TotalCosto, factura.SerieFolio, 68, factura.SerieFolio, factura.Fecha, IdCtaContable, -1, CveVenta:=factura.CveVenta, CveCliente:=factura.CveCliente, CveMovimientoAlmacen:=CveMovimientoInventario, ImporteMX:=TotalCosto, CveCuenta:=CveCuenta, CveSubProyecto:=factura.CveSubProyecto) Then + OcurrioError = True + End If + 'End If + + Else + OcurrioError = True + End If + factura.Inv_CveMovimiento = CveMovimientoInventario + factura.Inv_ValorInventario = ValorInventario + End If + + End If + + Return CveMovimientoInventario + End Function + Private Sub GuardarVentaEstimaciones(ByRef factura As Modelos.Factura, ObjContr As ClsContratos) 'debe de ser por contrato el movimiento If factura.CveContratoSecciones.Length > 0 Then diff --git a/Inventarios/RecepcionDevolucion.aspx b/Inventarios/RecepcionDevolucion.aspx new file mode 100644 index 000000000..70f34f34e --- /dev/null +++ b/Inventarios/RecepcionDevolucion.aspx @@ -0,0 +1,376 @@ +<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="RecepcionDevolucion.aspx.vb" Inherits="Inventarios_RecepcionDevolucion" %> + + + + + + + + Devolución desde almacen + + + + + + +
  • + + +
  • +
    +
    +
    + + + + + +
    +
    +
    +
    +
    + "> + +
    +
    + Información del movimiento +
    +
    +
    > +
    +
    + +
    + +
    +
    +
    + +
    + + + + + +
    +
    +
    + +
    + + + +
    +
    +
    + +
    + + + + <%----%> +
    +
    +
    + +
    + +
    +
    + +
    +
    +
    +
    +
    +
    +
    + + +
    +
    +
    + + Productos a devolver +
    +
    +
    +
    +
    +
    + +
    +
    +
    + <%--GV DATOS--%> + + + + + + + + + + + + + + + + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    +
    + + + + + +
    +
    +
    +
    +
    + +
    + + + + diff --git a/Inventarios/RecepcionDevolucion.aspx.vb b/Inventarios/RecepcionDevolucion.aspx.vb new file mode 100644 index 000000000..6a937ce9a --- /dev/null +++ b/Inventarios/RecepcionDevolucion.aspx.vb @@ -0,0 +1,879 @@ +Option Strict On +Option Explicit On + +Imports System.Data +Imports Extensiones + +Partial Class Inventarios_RecepcionDevolucion + Inherits ClsPaginas + +#Region "P R O P I E D A D E S" + Private Property ObjRemisionNC As Modelos.Factura + Get + Return CType(ViewState("ObjRemisionNC"), Modelos.Factura) + End Get + Set(value As Modelos.Factura) + ViewState("ObjRemisionNC") = value + End Set + End Property + Public Property DtMovimientos As DataTable + Get + Return CType(ViewState("DtMovimientos"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtMovimientos") = 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 + InicializaValores() + End If + End Sub + + Protected Sub CreaDT() + Dim dt As New DataTable + + Dim column As DataColumn = New DataColumn("Consec") + column.DataType = GetType(Integer) + With column + .AutoIncrement = True + .AutoIncrementSeed = 1 + .AutoIncrementStep = 1 + End With + + dt.Columns.Add(column) + dt.Columns.Add("CantidadDevuelta", GetType(Decimal)) + dt.Columns.Add("CantidadVenta", GetType(Decimal)) + dt.Columns.Add("CveVentaDetalle", GetType(Integer)) + dt.Columns.Add("CveVenta", GetType(Integer)) + dt.Columns.Add("Venta", GetType(String)) + dt.Columns.Add("CveUM", GetType(Integer)) + dt.Columns.Add("UnidadMedida", GetType(String)) + dt.Columns.Add("CvePS", GetType(Integer)) + dt.Columns.Add("PS", GetType(String)) + dt.Columns.Add("PU", GetType(Decimal)) + dt.Columns.Add("Total", GetType(Decimal)) + dt.Columns.Add("CveClasificacion", GetType(Integer)) + dt.Columns.Add("CveSeccionAlmacen", GetType(Integer)) + dt.Columns.Add("SeccionAlmacen", GetType(String)) + dt.Columns.Add("Serie", GetType(String)) + dt.Columns.Add("Lote", GetType(String)) + dt.Columns.Add("FechaCaducidad", GetType(DateTime)) + dt.Columns.Add("Observaciones", GetType(String)) + + DtMovimientos = dt.Clone() + End Sub + + Private Sub InicializaValores() + Dim StrAlmacenes As String = "CveTipoAlmacen IN (1)" + + If (UsuarioActual.Empresa.Funcionalidad(105) = "1" Or UsuarioActual.Empresa.Funcionalidad(141) = "1") Then + DdlCliente.setEsWebService(True) + DdlCliente.Attributes.Add("data-metodo", "getcliente") + DdlCliente.SelectedText = "Todos" + DdlCliente.SelectedValue = "-1" + Else + DdlCliente.setEsWebService(False) + DdlCliente.ddl.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa) + DdlCliente.ddl.DataBind() + DdlCliente.ddl.Items.Insert(0, New ListItem("Seleccione", "-1")) + End If + + DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros(StrAlmacenes) 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) + DdlAlmacen.DataBind() + DdlAlmacen.Items.Insert(0, New ListItem("Seleccione ", "-1")) + DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen) + + + DdlSubProyecto.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, CveEstatus:=1) + DdlSubProyecto.DataBind() + DdlSubProyecto.Items.Insert(0, New ListItem("Seleccione ", "-1")) + + TxtFechaI.Text = $"01/{Now.Month}/{Now.Year}" + TxtFechaF.Text = Now.ToString("dd/MM/yyyy") + + GvDatos.DataSource = Nothing + GvDatos.DataBind() + + LimpiarDatos() + + CargaPS(-1, DdlPS, AplicaAlmacen:=False) + + CreaDT() + + UpGenerales.Update() + End Sub + + Protected Sub DdlSubProyecto_SelectedIndexChanged(sender As Object, e As EventArgs) + Dim StrAlmacenes As String = $"CveTipoAlmacen IN (1) AND CveSubProyecto={DdlSubProyecto.SelectedValue.ToEntero()}" + + DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros(StrAlmacenes) 'GlobalDTAlmacen(UsuarioActual.CveEmpresa) + DdlAlmacen.DataBind() + DdlAlmacen.Items.Insert(0, New ListItem("Seleccione ", "-1")) + DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen) + + UpGenerales.Update() + End Sub + + Protected Sub LnkAgregarProducto_Click(sender As Object, e As EventArgs) + Dim CveCliente As Integer = DdlCliente.SelectedValue.ToEntero() + Dim CveSubProyecto As Integer = DdlSubProyecto.SelectedValue.ToEntero() + + If CveCliente <= 0 Then + Alert("Debe seleccionar un cliente", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If CveSubProyecto <= 0 Then + Alert("Debe seleccionar un sub proyecto", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + LimpiarDatos() + + RegistraScript("$('#DivModalAgregar').modal('show');") + End Sub + + Private Sub LimpiarDatos() + + GvPSAgregar.DataSource = Nothing + GvPSAgregar.DataBind() + + ChkAplicaSerie.Checked = False + ChkAplicaLote.Checked = False + ChkAplicaCaducidad.Checked = False + + ChkAplicaSerie_CheckedChanged(ChkAplicaSerie, EventArgs.Empty) + ChkAplicaLote_CheckedChanged(ChkAplicaSerie, EventArgs.Empty) + ChkAplicaCaducidad_CheckedChanged(ChkAplicaSerie, EventArgs.Empty) + + End Sub + + Private Sub CargaPS(CveClasificacion As Integer, Objeto As ADServerControl.Dropdownlost, Optional AplicaAlmacen As Boolean = True, Optional CveMarca As Integer = -1) + Objeto.setEsWebService(UsuarioActual.Empresa.Funcionalidad(141).ToString = "1") + If Not UsuarioActual.Empresa.Funcionalidad(141).ToString = "1" Then + Objeto.ddl.Items.Clear() + Objeto.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacion, Estatus:=1, AplicaParaVenta:=1) + Objeto.ddl.DataBind() + Objeto.ddl.Items.Insert(0, New ListItem("*** Actualizar listado de Productos o Servicios ***", "-2")) + Objeto.ddl.Items.Insert(0, New ListItem("Seleccione el Producto", "-1")) + Else + Objeto.Attributes.Add("data-cvesubproyecto", "-1") + Objeto.ddlWS.Attributes.Add("data-cveclasificacion", "-1") + Objeto.ddlWS.Attributes.Add("data-aplicaparaventa", "1") + + If AplicaAlmacen Then + Objeto.ddlWS.Attributes.Add("data-pagina", "ventas/ventas") + Else + Objeto.ddlWS.Attributes.Add("data-pagina", "-1") + End If + Objeto.ddlWS.Attributes.Add("data-aplicaparaventa", "1") + Objeto.ddlWS.Attributes.Add("data-cvemarca", CveMarca.ToString) + Objeto.ddlWS.Attributes.Add("data-Estatus", "1") + End If + End Sub + Protected Sub ChkAplicaSerie_CheckedChanged(sender As Object, e As EventArgs) + lblSerie.Visible = ChkAplicaSerie.Checked + DivSerie.Visible = ChkAplicaSerie.Checked + UpModalAgregar.Update() + End Sub + Protected Sub ChkAplicaLote_CheckedChanged(sender As Object, e As EventArgs) + lblLote.Visible = ChkAplicaLote.Checked + DivLote.Visible = ChkAplicaLote.Checked + UpModalAgregar.Update() + End Sub + Protected Sub ChkAplicaCaducidad_CheckedChanged(sender As Object, e As EventArgs) + lblCaducidad.Visible = ChkAplicaCaducidad.Checked + DivCaducidad.Visible = ChkAplicaCaducidad.Checked + UpModalAgregar.Update() + End Sub + Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) + Dim CvePS As Integer = DdlPS.SelectedValue.ToEntero() + Dim CveCliente As Integer = DdlCliente.SelectedValue.ToEntero() + Dim CveSubProyecto As Integer = DdlSubProyecto.SelectedValue.ToEntero() + + If CvePS <= 0 Then + Alert("Debe seleccionar un producto", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If CveCliente <= 0 Then + Alert("Debe seleccionar un cliente", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If CveSubProyecto <= 0 Then + Alert("Debe seleccionar un sub proyecto", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + Dim FechaI As DateTime = TxtFechaI.Text.ToDateTime() + Dim FechaF As DateTime = TxtFechaF.Text.ToDateTime() + + Dim Serie As String = If(ChkAplicaSerie.Checked, TxtSerie.Text.Trim, "-1") + Dim Lote As String = If(ChkAplicaLote.Checked, TxtLote.Text.Trim, "-1") + Dim FechaCaducidad As DateTime = If(ChkAplicaCaducidad.Checked, TxtFechaCaducidad.Text.ToDateTime, MinFecha) + + Dim ObjInv As New ClsInventarios + Try + If ObjInv.GetProductosDevolucion(CvePS, CveCliente, CveSubProyecto, FechaI, FechaF, Serie, Lote, FechaCaducidad, UsuarioActual.CveEmpresa) Then + GvPSAgregar.DataSource = ObjInv.DtResultados + End If + Catch ex As Exception + OnError("Ocurrio un error al obtener los datos de devolución", ex) + End Try + ObjInv.Dispose() + + GvPSAgregar.DataBind() + + UpModalAgregar.Update() + End Sub + + Protected Sub GvPSAgregar_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvPSAgregar.RowDataBound + If e.Row.RowType = DataControlRowType.DataRow Then + + If e.Row.DBCampo("CvePS").ToEntero() <= 0 Then + e.Row.CssClass = "Totales" + e.Row.FCCheckBox("ChkAplicar").Visible = False + e.Row.FCTextBox("TxtCantidad").Visible = False + End If + End If + End Sub + Protected Sub LnkModalAgregarUsado_Click(sender As Object, e As EventArgs) + If DtMovimientos IsNot Nothing Then + For Each GvRow As GridViewRow In GvPSAgregar.Rows + If GvRow.RowType = DataControlRowType.DataRow Then + If GvRow.FCCheckBox("ChkAplicar").Checked Then + Dim RowDevolucion As DataRow = DtMovimientos.NewRow + + RowDevolucion("CantidadDevuelta") = GvRow.FCTextBox("TxtCantidad").Text.ToDecimal() + RowDevolucion("CantidadVenta") = GvRow.DataKey("Cantidad").ToDecimal() + RowDevolucion("CveVentaDetalle") = GvRow.DataKey("CveVentaDetalle").ToEntero() + RowDevolucion("CveVenta") = GvRow.DataKey("CveVenta").ToEntero() + RowDevolucion("Venta") = GvRow.DataKey("SerieFolio") + RowDevolucion("CveUM") = GvRow.DataKey("CveUM").ToEntero() + RowDevolucion("UnidadMedida") = GvRow.DataKey("UnidadMedida") + RowDevolucion("CvePS") = GvRow.DataKey("CvePS").ToEntero() + RowDevolucion("PS") = GvRow.DataKey("PS") + RowDevolucion("PU") = GvRow.DataKey("PU").ToDecimal() + RowDevolucion("Total") = (GvRow.FCTextBox("TxtCantidad").Text.ToDecimal() * GvRow.DataKey("PU").ToDecimal()) + RowDevolucion("CveClasificacion") = GvRow.DataKey("CveClasificacion").ToEntero() + RowDevolucion("CveSeccionAlmacen") = GvRow.DataKey("CveSeccionAlmacen").ToEntero() + RowDevolucion("SeccionAlmacen") = GvRow.DataKey("SeccionAlmacen") + RowDevolucion("Serie") = GvRow.DataKey("Serie") + RowDevolucion("Lote") = GvRow.DataKey("Lote") + RowDevolucion("FechaCaducidad") = If(String.IsNullOrEmpty(GvRow.DataKey("FechaCaducidad")), Nothing, GvRow.DataKey("FechaCaducidad").ToDateTime()) + RowDevolucion("Observaciones") = "" + + 'If GvRow.DataKey("CveAlmacen").ToEntero() > 0 AndAlso DdlAlmacen.SelectedValue.ToEntero() <= 0 Then + ' DdlAlmacen.SelectedValueExist(GvRow.DataKey("CveAlmacen")) + 'End If + + DtMovimientos.Rows.Add(RowDevolucion) + End If + + End If + Next + + GvDatos.DataSource = DtMovimientos + GvDatos.DataBind() + + If DtMovimientos.Rows.Count > 0 Then + DivFactura.Visible = True + DdlFactura.DataSource = DtMovimientos.FiltraParametros("", DistinctColumns:={"CveVenta", "Venta"}) + DdlFactura.DataBind() + End If + + End If + + UpDatos.Update() + UpGenerales.Update() + + RegistraScript("$('#DivModalAgregar').modal('hide');") + + + End Sub + + +#Region "C R E A R - R N C" + Private Sub CreaRemisionNC(CveCliente As Integer, CveSubProyecto As Integer) + If ObjRemisionNC IsNot Nothing Then + ObjRemisionNC.Dispose() + ObjRemisionNC = Nothing + End If + Me.ObjRemisionNC = New Modelos.Factura(UsuarioActual) + + Me.ObjRemisionNC.TipoMensajeRespuesta = Modelos.TipoMensajeRespuesta.HTML + Me.ObjRemisionNC.Serie = "-1" + Me.ObjRemisionNC.Folio = -1 'Folio.ToEntero() + Me.ObjRemisionNC.Version = "3.3" + Me.ObjRemisionNC.FolioFiscal = "" + Me.ObjRemisionNC.CveUsuario = UsuarioActual.CveUsuario + Me.ObjRemisionNC.CveEmpresa = UsuarioActual.CveEmpresa + Me.ObjRemisionNC.ConvertirPesos = False + Me.ObjRemisionNC.CveVentaPadre = DdlFactura.SelectedValue.ToEntero() + + Dim ObjVentasPadre As New ClsVentas + If ObjVentasPadre.GetVenta(Me.ObjRemisionNC.CveVentaPadre, UsuarioActual.CveEmpresa) AndAlso ObjVentasPadre.DtResultados.Rows.Count > 0 Then + Me.ObjRemisionNC.CveMoneda = ObjVentasPadre.DtResultados.FiltroPrimeroValor("CveMoneda").ToString().ToEntero() + End If + ObjVentasPadre.Dispose() + + If Me.ObjRemisionNC.CveMoneda = 1 Then + Me.ObjRemisionNC.TipoCambio = 1 + Else + Me.ObjRemisionNC.TipoCambio = GlobalTipoCambio(Now).ToDecimal() + End If + + Me.ObjRemisionNC.Moneda = GlobalDTMonedas.FiltroPrimeroValor("Moneda", String.Format("CveMoneda = {0} ", Me.ObjRemisionNC.CveMoneda)) + Me.ObjRemisionNC.MonedaSAT = GlobalDTMonedas.FiltroPrimeroValor("AbreviaturaSAT", String.Format("CveMoneda = {0} ", Me.ObjRemisionNC.CveMoneda)) + Me.ObjRemisionNC.TipoDocto = "RNC" + Me.ObjRemisionNC.RefDocto = "" + Me.ObjRemisionNC.CveMesa = -1 + Me.ObjRemisionNC.Fecha = Now + Me.ObjRemisionNC.CvePrePoliza = -1 + Me.ObjRemisionNC.FechaPago = Now + Me.ObjRemisionNC.MotivoDescuento = "" + Me.ObjRemisionNC.FechaEjecucion = Now + Me.ObjRemisionNC.UsuarioCreo = UsuarioActual.Usuario + Me.ObjRemisionNC.CveCondicionEntrega = -1 + Me.ObjRemisionNC.CondicionEntrega = "" + Me.ObjRemisionNC.NumeroCuenta = "" + Me.ObjRemisionNC.CondicionesPago = 0 + Me.ObjRemisionNC.FormaPago = 0 + Me.ObjRemisionNC.PedidoContrato = "" + Me.ObjRemisionNC.NumeroContrato = "" + Me.ObjRemisionNC.DescripcionContrato = "" + Me.ObjRemisionNC.CveCorte = -1 + Me.ObjRemisionNC.TipoDocumento = "Remisión" + 'NUM 1- CARGO 2- BONIFICACION + Me.ObjRemisionNC.Num1 = 0 + 'NUM 0- USADO 1- AJUSTE/GARANTIA + Me.ObjRemisionNC.Num2 = 0 + 'ES PARA GENERAR DEVOLUCION + Me.ObjRemisionNC.Num3 = 10 + Me.ObjRemisionNC.Alfa1 = "" + Me.ObjRemisionNC.Alfa2 = "" + Me.ObjRemisionNC.Alfa3 = "" + Me.ObjRemisionNC.CveContrato = -1 + Me.ObjRemisionNC.ConvertirPesos = False + Me.ObjRemisionNC.CveSubProyecto = CveSubProyecto + Me.ObjRemisionNC.CveSubProyectoCobranza = CveSubProyecto + Me.ObjRemisionNC.CveSubProyectoEjecucion = CveSubProyecto + Me.ObjRemisionNC.SubProyecto = New Modelos.SubProyectoModel(GlobalDTSubProyectos(-1).FiltroPrimero(String.Format("CveSubProyecto = {0}", CveSubProyecto))) + Me.ObjRemisionNC.SubProyectoMatriz = New Modelos.SubProyectoModel(GlobalDTSubProyectos(-1, CveSubProyecto:=-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero("TipoSucursal=1")) + + 'CLIENTE + Me.ObjRemisionNC.CveCliente = CveCliente + Me.ObjRemisionNC.SetCliente() + Me.ObjRemisionNC.CveAlmacen = -1 + + Dim ObjCliente As New ClsClientes + If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then + If ObjCliente.DtResultados.Rows.Count > 0 Then + Me.ObjRemisionNC.CveFormaPago33 = ObjCliente.CveFormaPago33 + Me.ObjRemisionNC.FormaPago33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("FormaPago", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) + Me.ObjRemisionNC.FormaPagoSAT33 = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", String.Format("CveFormaPago = {0}", ObjCliente.CveFormaPago33)) + + Me.ObjRemisionNC.CveMetodoPago33 = ObjCliente.CveMetodoPago33 + Me.ObjRemisionNC.MetodoPago33 = GlobalDTVtaMetodoPago.FiltroPrimeroValor("MetodoPago", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) + Me.ObjRemisionNC.ClaveMetodoPagoSAT = GlobalDTVtaMetodoPago.FiltroPrimeroValor("ClaveMetodoPagoSAT", String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)) + + Me.ObjRemisionNC.CveUsoCFDI = ObjCliente.CveUsoCFDI + Me.ObjRemisionNC.UsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI)) + Me.ObjRemisionNC.ClaveUsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("UsoCFDI", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI)) + + Me.ObjRemisionNC.CveMetodoPago = ObjCliente.CveMetodoPago33 + + If GlobalDTMetodosPago.FiltraParametros(String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)).Rows.Count > 0 Then + Me.ObjRemisionNC.MetodoPago = GlobalDTMetodosPago.FiltraParametros(String.Format("CveMetodoPago = {0}", ObjCliente.CveMetodoPago33)).Rows(0)("MetodoPago").ToString + Else + Me.ObjRemisionNC.CveMetodoPago = 1 + Me.ObjRemisionNC.MetodoPago = "Efectivo" + End If + + If UsuarioActual.CveEmpresa = 119 Then + Me.ObjRemisionNC.FormaPago = 20 'POR DEFINIR AND (@CveMetodoPago33 = 3 AND @CveFormaPago33 <> 20) + If Me.ObjRemisionNC.CveMetodoPago33 = 3 Then + Me.ObjRemisionNC.CveFormaPago33 = 20 + End If + End If + End If + End If + + If ObjCliente.GetSucursales(CveCliente) Then + If ObjCliente.DtResultados.Rows.Count > 0 Then + Me.ObjRemisionNC.CveClienteSucursal = If(String.IsNullOrEmpty(ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "Estatus = 'Activo'")), -1, ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "Estatus = 'Activo'").ToEntero()) + Else + Me.ObjRemisionNC.CveClienteSucursal = -1 + End If + End If + ObjCliente.Dispose() + + 'DETALLES + Me.ObjRemisionNC.DtDetalle = CreaDTDetalleRNC() + + CargaDTDetalleRNC() + + 'VALIDA PROMOCIONES Y EXISTENCIAS + Dim ObjVentas As New ClsVentas + If ObjVentas.GetPromocionesPS(-1, Now, CveSubProyecto, Me.ObjRemisionNC.CveCliente, Me.ObjRemisionNC.CveVendedor, 1, UsuarioActual.CveEmpresa) Then + Me.ObjRemisionNC.DtPromociones = ObjVentas.DtResultados.Copy() + End If + ObjVentas.Dispose() + + Me.ObjRemisionNC.Observaciones = TxtObservaciones.Text + Me.ObjRemisionNC.OrdenCompra = "" + Me.ObjRemisionNC.PedidoContrato = "" + Me.ObjRemisionNC.ObservacionesAlmacen = "" + + + + 'If TmpDTPolizaVirtual IsNot Nothing Then + ' Me.ObjRemisionNC.DtPolizasVirtuales = TmpDTPolizaVirtual + 'End If + + End Sub + + Private Function AddPSRNC(ByRef TmpDT As DataTable, Cantidad As Decimal, CveUM As Integer, UM As String, CveClasificacion As Integer, Clasificacion As String, CvePS As Integer, PS As String, Obs As String, + PU As Decimal, Descuento As Decimal, + CveProyecto As Integer, Proyecto As String, CveSubProyecto As Integer, SubProyecto As String, + Optional Serie As String = "", Optional TiempoEntrega As String = "", Optional EntregaDirecta As Integer = 0, + Optional CveContratoDetalle As Integer = 0, Optional CveVentaDetalle As Integer = 0, Optional CveMovimientoDetallePedido As Integer = 0, + Optional CveOrdenCompraDetalle As Integer = 0, Optional CveVentaDetalleRemision As Integer = 0, Optional CveVentaDetalleCotizacion As Integer = 0, + Optional CuentaPredial As String = "", Optional RegeneraIEPS As Boolean = True, Optional CveVentaDetallePedido2 As Integer = 0, Optional EsCargo As Boolean = False, Optional PorcentajeIVA As Decimal = 0D, Optional CveTamaño As Integer = 0) As Boolean + + Dim Retorno As Boolean = False + If Not CvePS > 0 Then + Alert("Ocurrió un error al cargar la información del producto a agregar. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Return False + End If + + If (Obs.Length + PS.Length > 1000) Then + Alert(String.Format("El Nombre y observación del producto tiene longitud de {0} caracteres y excede los 1000 caracteres permitidos.", Obs.Length + PS.Length), TipoMensaje.MsgAdvertencia) + Return False + End If + + + Dim Row As DataRow = Nothing + Dim TotalCalculableImpuestos As Decimal = 0D, TotalCalculableImpuestosIVA = 0D + PU = Math.Round(PU, 6) ' el precio unitario puede llevar hasta 6 decimales permitidos + + Row = TmpDT.NewRow() + Row("CveProyecto") = CveProyecto + Row("Proyecto") = Proyecto + Row("CveSubProyecto") = CveSubProyecto + Row("SubProyecto") = SubProyecto + Row("Serie") = Serie + Row("TiempoEntrega") = TiempoEntrega + Row("Orden") = TmpDT.Rows.Count + 1 + Row("Cantidad") = Cantidad + Row("CveUM") = CveUM + Row("UM") = UM + Row("CveClasificacion") = CveClasificacion + Row("Clasificacion") = Clasificacion + Row("CvePS") = CvePS + Row("Obs") = Obs + + Dim DrPS As DataRow = Nothing + + DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimero("") ' Estado = -1 + + If DrPS Is Nothing Then + Alert("Ocurrió un error al cargar la información del Producto. Por favor vuelva a intentar.", TipoMensaje.MsgAdvertencia) + Return False + End If + + 'verifica si tiene ventaminima + If Cantidad > 0 AndAlso DrPS("VentaMinima").ToString.ToDecimal > 0 Then + 'verifico que la cantidad sea multiplo de venta minima, es decir ventaminima =5, solo puede vender 5,10,15... + If Cantidad Mod DrPS("VentaMinima").ToString.ToDecimal <> 0 Then + Alert(String.Format("El producto se vende solo en cantidades de {0}", DrPS("VentaMinima").ToString)) + Return False + End If + End If + + TotalCalculableImpuestos = ((Cantidad * (PU)) - Descuento) + TotalCalculableImpuestosIVA = TotalCalculableImpuestos * (1 + DrPS("IEPSPorcentaje").ToString().ToDecimal) + + Row("PU") = PU + Row("Codigo") = DrPS("Codigo") + Row("NoIdentificacion") = DrPS("Codigo") + Row("ClaveSATFraccionArancelaria") = DrPS("ClaveSATFraccionArancelaria") + Row("ClaveSATUnidadAduana") = DrPS("ClaveSATUnidadAduana") + Row("ClaveSATFraccionArancelariaDescripcion") = DrPS("ClaveSATFraccionArancelariaDescripcion") + Row("ClaveSATUnidadAduanaDescripcion") = DrPS("ClaveSATUnidadAduanaDescripcion") + Row("Consec") = TmpDT.Rows.Count + 1 + + Row("PS") = DrPS("PS") + Row("CodigoPS") = DrPS("PSCodigo").ToString + Row("CveTipoPS") = DrPS("CveTipoPS") + Row("CveTipoInvPS") = DrPS("Inv_CveMetodoInventario") + Row("CveTamaño") = DrPS("CveTamaño") + + If CveClasificacion <= 0 Then Row("CveClasificacion") = DrPS("CveClasificacion") + If Clasificacion = "" Then Row("Clasificacion") = DrPS("Clasificacion") + + If DrPS("IVA").ToString().Contiene("-1", "") Then + Row("PorcentajeIVA") = PorcentajeIVA + Else + Row("PorcentajeIVA") = DrPS("IVA") + End If + + Row("IVA") = Row("PorcentajeIVA") + Row("ImporteIVA") = Math.Round(Row("PorcentajeIVA").ToString.ToDecimal * TotalCalculableImpuestosIVA, 2) + + + Row("ImporteRetIVA") = 0D + Row("ImporteRetISR") = 0D + Row("PorcentajeRetIVA") = 0D + Row("PorcentajeRetISR") = 0D + Row("PorcentajeIEPS") = DrPS("IEPSPorcentaje") + Row("ImporteIEPS") = Math.Round(DrPS("IEPSPorcentaje").ToString.ToDecimal * TotalCalculableImpuestos, 2) + Row("IEPS") = Row("ImporteIEPS") + Row("Descuento") = Math.Round(Descuento, 2) + Row("TipoDescuento") = 0 + Row("Total") = (Cantidad * PU) + Row("TotalImporte") = Math.Round(Cantidad * PU, 2) + + Row("SATClaveProdServ") = DrPS("SATClavePS") + Row("SATClaveUM") = DrPS("SATClaveUnidadMedida") + + + Row("EntregaDirecta") = EntregaDirecta + 'Contratos + Row("CveContratoDetalle") = CveContratoDetalle + Row("CveVentaDetalle") = CveVentaDetalle + Row("CveMovimientoDetallePedido") = CveMovimientoDetallePedido + Row("CveOrdenCompraDetalle") = CveOrdenCompraDetalle + Row("CveVentaDetalleRemision") = CveVentaDetalleRemision + Row("CveVentaDetalleCotizacion") = CveVentaDetalleCotizacion + Row("CveVentaDetallePedido2") = CveVentaDetallePedido2 + Row("CuentaPredial") = CuentaPredial + Row("EsCargo") = EsCargo + Row("CveTamaño") = CveTamaño + + 'RECARGAR GV + TmpDT.Rows.Add(Row) + TmpDT.AcceptChanges() + Retorno = True + Return Retorno + + End Function + Protected Function CreaDTDetalleRNC() As DataTable + Dim TmpDT = New DataTable + TmpDT.Columns.Add("CveVenta", GetType(Integer)) + 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("SATClaveUM", GetType(String)) + TmpDT.Columns.Add("CveClasificacion", GetType(Integer)) + TmpDT.Columns.Add("Clasificacion", GetType(String)) + TmpDT.Columns.Add("CvePS", GetType(Integer)) + TmpDT.Columns.Add("PS", GetType(String)) + TmpDT.Columns.Add("CodigoPS", GetType(String)) + TmpDT.Columns.Add("SATClaveProdServ", GetType(String)) + TmpDT.Columns.Add("NoIdentificacion", GetType(String)) + TmpDT.Columns.Add("CveTipoPS", GetType(Integer)) + TmpDT.Columns.Add("CveTipoInvPS", GetType(Integer)) + TmpDT.Columns.Add("Serie", GetType(String)) + TmpDT.Columns.Add("CuentaPredial", GetType(String)) + TmpDT.Columns.Add("Obs", GetType(String)) + TmpDT.Columns.Add("TiempoEntrega", GetType(String)) + TmpDT.Columns.Add("PU", GetType(Decimal)) + TmpDT.Columns.Add("IVA", GetType(Decimal)) + TmpDT.Columns.Add("ImporteIVA", GetType(Decimal)) + TmpDT.Columns.Add("PorcentajeIVA", GetType(Decimal)) + TmpDT.Columns.Add("ImporteRetIVA", GetType(Decimal)) + TmpDT.Columns.Add("ImporteRetISR", GetType(Decimal)) + TmpDT.Columns.Add("PorcentajeRetIVA", GetType(Decimal)) + TmpDT.Columns.Add("PorcentajeRetISR", GetType(Decimal)) + TmpDT.Columns.Add("ImporteIEPS", GetType(Decimal)) + TmpDT.Columns.Add("IEPS", GetType(Decimal)) + TmpDT.Columns.Add("PorcentajeIEPS", GetType(Decimal)) + TmpDT.Columns.Add("Descuento", GetType(Decimal)) + TmpDT.Columns.Add("TipoDescuento", GetType(Integer)) + TmpDT.Columns.Add("TotalImporte", GetType(Decimal)) + TmpDT.Columns.Add("Total", GetType(Decimal)) + 'Para uso del módulo contable + TmpDT.Columns.Add("AsientoContableVentas", GetType(Integer)) + TmpDT.Columns.Add("IdCtaContVentas", GetType(Integer)) + TmpDT.Columns.Add("AplicaParaConcepto", GetType(Boolean)) + TmpDT.Columns.Add("CveProyecto", GetType(Integer)) + TmpDT.Columns.Add("Proyecto", GetType(String)) + TmpDT.Columns.Add("CveSubProyecto", GetType(Integer)) + TmpDT.Columns.Add("SubProyecto", GetType(String)) + TmpDT.Columns.Add("CveVentaDetallePadre", GetType(Integer)) + + 'TipoDescuento: 1 = Descuento * PU; 2 = Descuento por Total del concepto + TmpDT.Columns.Add("CvePresupuestoIngreso", GetType(Integer)) + TmpDT.Columns.Add("CveFuenteRecaudacion", GetType(Integer)) + 'Contratos + TmpDT.Columns.Add("CveContratoDetalle", GetType(Integer)) + 'Remisiones a Facturas + TmpDT.Columns.Add("CveVentaDetalle", GetType(Integer)) + TmpDT.Columns.Add("CveVentaDetalleRemision", GetType(Integer)) + TmpDT.Columns.Add("CveVentaDetalleCotizacion", GetType(Integer)) + + 'Pedido2 a Facturas + TmpDT.Columns.Add("CveVentaDetallePedido2", GetType(Integer)) + + TmpDT.Columns.Add("Origen", GetType(Integer)) + 'Ordenes Servicio + TmpDT.Columns.Add("CveOS", GetType(Integer)) + TmpDT.Columns.Add("CveOSDetalle", GetType(Integer)) + TmpDT.Columns.Add("SeFacturara", GetType(Integer)) + TmpDT.Columns.Add("Folio", GetType(Integer)) + TmpDT.Columns.Add("Estatus", GetType(String)) + 'Ordenamiento + TmpDT.Columns.Add("Orden", GetType(Integer)) + TmpDT.Columns.Add("TipoDocto", GetType(String)) + 'OC + TmpDT.Columns.Add("CveOrdenCompraDetalle", GetType(Integer)) + TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) + + TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer)) + TmpDT.Columns.Add("CantidadFacturadaRem", GetType(Decimal)) + TmpDT.Columns.Add("CantidadFacturadaCot", GetType(Decimal)) + TmpDT.Columns.Add("CantidadFacturadaPed2", GetType(Decimal)) + TmpDT.Columns.Add("CantidadInventario", GetType(Decimal)) + + TmpDT.Columns.Add("ClaveSATFraccionArancelaria", GetType(String)) + TmpDT.Columns.Add("ClaveSATUnidadAduana", GetType(String)) + TmpDT.Columns.Add("ClaveSATFraccionArancelariaDescripcion", GetType(String)) + TmpDT.Columns.Add("ClaveSATUnidadAduanaDescripcion", GetType(String)) + + TmpDT.Columns.Add("CveTamaño", GetType(Integer)) + TmpDT.Columns.Add("EsCargo", GetType(Boolean)) + + Return TmpDT + End Function + Protected Sub CargaDTDetalleRNC() + 'CvePS = Dr("CvePS").ToString.ToEntero + 'CveUM = Dr("CveUM").ToString.ToEntero + 'Cantidad = Dr("Cantidad").ToString.ToDecimal + 'PU = Dr("PU").ToString.ToDecimal + + 'AplicaSerie = CBool(Dr("AplicaSerie")) + 'Serie = If(AplicaSerie, Dr("Serie").ToString, "-1") + + 'AplicaLote = CBool(Dr("AplicaLote")) + 'Lote = If(AplicaSerie, Dr("Lote").ToString, "-1") + + 'AplicaCaducidad = CBool(Dr("AplicaCaducidad")) + 'FechaCaducidad = If(AplicaCaducidad, Dr("FechaCaducidad").ToString.ToDateTime, MinFecha) + + 'If Dr("CveTipoInvPS").ToString.ToEntero = 5 AndAlso AplicaSerie AndAlso Serie = "" Then + ' OcurrioError = True + ' ErrorList.Add("Se deben especificar las Series de los productos de almacén") + ' Exit For + 'End If + + Dim DtInventario As DataTable = New DataTable + Dim column As DataColumn = New DataColumn("Consec") + column.DataType = GetType(Integer) + With column + .AutoIncrement = True + .AutoIncrementSeed = 1 + .AutoIncrementStep = 1 + End With + + DtInventario.Columns.Add(column) + DtInventario.Columns.Add("Cantidad", GetType(Decimal)) + DtInventario.Columns.Add("CveVentaDetalle", GetType(Integer)) + DtInventario.Columns.Add("CvePS", GetType(Integer)) + DtInventario.Columns.Add("CveUM", GetType(Integer)) + DtInventario.Columns.Add("PU", GetType(Decimal)) + DtInventario.Columns.Add("CveTipoInvPS", GetType(Integer)) + DtInventario.Columns.Add("AplicaSerie", GetType(Boolean)) + DtInventario.Columns.Add("Serie", GetType(String)) + DtInventario.Columns.Add("AplicaLote", GetType(Boolean)) + DtInventario.Columns.Add("Lote", GetType(String)) + DtInventario.Columns.Add("AplicaCaducidad", GetType(Boolean)) + DtInventario.Columns.Add("FechaCaducidad", GetType(DateTime)) + + For Each Row As DataRow In DtMovimientos.Rows + + Dim Cantidad As Decimal = Row("CantidadDevuelta").ToString().ToDecimal() + Dim PU As Decimal = Row("PU").ToString().ToDecimal() + Dim SubTotal As Decimal = Cantidad * PU + + Dim CveUnidadMedida As Integer = 0 + Dim CveClasificacion As Integer = 0 + Dim UnidadMedida As String = "" + Dim Clasificacion As String = "" + Dim PS As String = "" + Dim PorcentajeIVA As Decimal = 0 + Dim CvePS As Integer = Row("CvePS").ToString().ToEntero() + + If CvePS > 0 Then + Dim Dr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).Rows(0) + Dim DrSubProyecto As DataRow = GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveSubProyecto = {0}", ObjRemisionNC.CveSubProyecto)) + If Dr IsNot Nothing AndAlso DrSubProyecto IsNot Nothing Then + CveUnidadMedida = Dr("CveUnidadMedida").ToString.ToEntero + CveClasificacion = Dr("CveClasificacion").ToString.ToEntero + PS = Dr("PSCodigo").ToString + UnidadMedida = Dr("UnidadMedida").ToString + Clasificacion = Dr("Clasificacion").ToString + PorcentajeIVA = DrSubProyecto("IVA").ToString().ToDecimal + + If AddPSRNC(ObjRemisionNC.DtDetalle, Cantidad, CveUnidadMedida, UnidadMedida, CveClasificacion, Clasificacion, CvePS, PS, "", PU, 0, -1, "", ObjRemisionNC.CveSubProyecto, ObjRemisionNC.SubProyecto.SubProyecto, PorcentajeIVA:=PorcentajeIVA, CveTamaño:=-1, CveVentaDetalle:=Row("CveVentaDetalle").ToString().ToEntero()) Then + Dim RowInventario As DataRow = DtInventario.NewRow + + RowInventario("Cantidad") = Cantidad + RowInventario("CveVentaDetalle") = -1 + RowInventario("CvePS") = CvePS + RowInventario("CveUM") = CveUnidadMedida + RowInventario("PU") = PU + RowInventario("CveTipoInvPS") = 0 + RowInventario("AplicaSerie") = Not String.IsNullOrEmpty(Row("Serie").ToString()) + RowInventario("Serie") = Row("Serie") + RowInventario("AplicaLote") = Not String.IsNullOrEmpty(Row("Lote").ToString()) + RowInventario("Lote") = Row("Lote") + Dim AplicaCaducidad = If(String.IsNullOrEmpty(Row("FechaCaducidad").ToString()), False, If(Row("FechaCaducidad").ToString().ToDateTime() <= MinFecha, False, True)) + RowInventario("AplicaCaducidad") = AplicaCaducidad + RowInventario("FechaCaducidad") = Row("FechaCaducidad") + + DtInventario.Rows.Add(RowInventario) + End If + + End If + + + Else + Alert("No se pudo cargar el producto", TipoMensaje.MsgError) + End If + Next + + Dim TotalImporte As Decimal = ObjRemisionNC.DtDetalle.SUM("TotalImporte").ToDecimal() + Dim ImporteIVA As Decimal = ObjRemisionNC.DtDetalle.SUM("ImporteIVA").ToDecimal() + Dim ImporteRetIVA As Decimal = ObjRemisionNC.DtDetalle.SUM("ImporteRetIVA").ToDecimal() + Dim ImporteRetISR As Decimal = ObjRemisionNC.DtDetalle.SUM("ImporteRetISR").ToDecimal() + Dim ImporteIEPS As Decimal = ObjRemisionNC.DtDetalle.SUM("ImporteIEPS").ToDecimal() + Dim Descuento As Decimal = ObjRemisionNC.DtDetalle.SUM("Descuento").ToDecimal() + Dim Amortizacion As Decimal = 0 + + Dim Total As Decimal = (TotalImporte + ImporteIVA + ImporteIEPS) - (ImporteRetIVA + ImporteRetISR + Descuento + Amortizacion) + + 'DETALLES + ObjRemisionNC.SubTotal = TotalImporte + ObjRemisionNC.Descuento = Descuento + ObjRemisionNC.Amortizacion = Amortizacion + ObjRemisionNC.IVA = ImporteIVA + ObjRemisionNC.RetIVA = ImporteRetIVA + ObjRemisionNC.RetISR = ImporteRetISR + ObjRemisionNC.IEPS = ImporteIEPS + ObjRemisionNC.Total = Total + ObjRemisionNC.TotalOtrosConceptos = 0 + ObjRemisionNC.ObservacionesMovimiento = TxtObservaciones.Text + + ObjRemisionNC.DtInventario = DtInventario + + 'Select Case DtMovimientos.FiltroPrimeroValor("CveConcepto").ToEntero() + ' Case 40 + ' ObjRemisionNC.CveConceptoMovimiento = 41 ' DEVOLUCION DEL CLIENTE + ' Case 3 + ' ObjRemisionNC.CveConceptoMovimiento = 18 ' DEVOLUCION DEL CLIENTE + 'End Select + + ObjRemisionNC.CveAlmacen = DdlAlmacen.SelectedValue.ToEntero() + + Dim CveTipoAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=ObjRemisionNC.CveAlmacen).FiltroPrimeroValor("CveTipoAlmacen").ToEntero + + Select Case CveTipoAlmacen + Case 10 + ObjRemisionNC.CveConceptoMovimiento = 41 ' DEVOLUCION DIRECTA DEL CLIENTE + Case Else + ObjRemisionNC.CveConceptoMovimiento = 18 ' DEVOLUCION DEL CLIENTE + End Select + + End Sub +#End Region + + Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) + Dim CveCliente As Integer = DdlCliente.SelectedValue.ToEntero() + Dim CveSubProyecto As Integer = DdlSubProyecto.SelectedValue.ToEntero() + Dim CveAlmacen As Integer = DdlAlmacen.SelectedValue.ToEntero() + + If CveCliente <= 0 Then + Alert("Debe seleccionar un cliente", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If CveSubProyecto <= 0 Then + Alert("Debe seleccionar un sub proyecto", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If CveAlmacen <= 0 Then + Alert("Debe seleccionar un almacen", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + If DtMovimientos Is Nothing OrElse DtMovimientos.Rows.Count = 0 Then + Alert("No hay producto para devolver", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + + Try + CreaRemisionNC(CveCliente, CveSubProyecto) + + If ObjRemisionNC IsNot Nothing Then + Dim Resp = ObjRemisionNC.EmitirFactura(False) + + If Resp.Mensajes.Count > 0 AndAlso Resp.CveVenta > 0 Then + Dim Msg As New StringBuilder + + If Resp.CveVenta > 0 Then + If Resp IsNot Nothing Then + For Each mensaje2 As String In Resp.Mensajes + Msg.AppendFormat("
    {0}", mensaje2) + Next + End If + End If + + Msg.AppendFormat("
    El Movimiento se registro con el Folio: {0}", Resp.FolioUsado, Resp.CveMovimientoUsado) + Msg.AppendFormat("

    Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", Resp.CveMovimientoUsado))) + + Alert(Msg.ToString(), If(Resp.TieneError, TipoMensaje.MsgError, TipoMensaje.MsgInformacion), JSBtnAceptar:="BtnRefrescarPagina();", ShowCloseButton:=False) + + ElseIf Resp.Mensajes.Count <= 0 AndAlso Resp.CveVenta <= 0 Then + Alert("Ocurrió un error al guardar", TipoMensaje.MsgError) + ElseIf Resp.Mensajes.Count >= 0 AndAlso Resp.CveVenta <= 0 Then + For Each Mensaje In Resp.Mensajes + Alert(Mensaje, If(Resp.TieneError, TipoMensaje.MsgError, TipoMensaje.MsgInformacion), If(Resp.TieneError, "", Resp.LigaPV), ShowCloseButton:=False) + Next + End If + + End If + + Catch ex As Exception + OnError("Ocurrió un error al guardar", ex) + End Try + + + End Sub + + Protected Sub GvDatos_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) + Dim GvRow As GridViewRow = GvDatos.Rows(e.RowIndex) + + If DtMovimientos IsNot Nothing Then + Dim ConsecEliminar As Integer = GvRow.DataKey("Consec").ToEntero() + If ConsecEliminar > 0 Then + Dim RowEliminar = DtMovimientos.Select($"Consec={ConsecEliminar}") + If RowEliminar IsNot Nothing AndAlso RowEliminar.Length > 0 AndAlso RowEliminar.Length = 1 Then + RowEliminar(0).Delete() + End If + End If + + GvDatos.DataSource = DtMovimientos + GvDatos.DataBind() + End If + + UpDatos.Update() + End Sub +End Class