Cancelacion de factura por Objeto
This commit is contained in:
@@ -7262,7 +7262,13 @@ Partial Class Ventas
|
||||
|
||||
|
||||
Private Sub CreaObjetosVenta(Optional VistaPrevia As Boolean = False)
|
||||
ObjFactura = New Modelos.Factura
|
||||
|
||||
If Me.CveVenta > 0 Then
|
||||
ObjFactura = New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa)
|
||||
Else
|
||||
ObjFactura = New Modelos.Factura
|
||||
End If
|
||||
|
||||
|
||||
ObjFactura.Version = "3.3"
|
||||
ObjFactura.CveUsuario = UsuarioActual.CveUsuario
|
||||
@@ -17061,6 +17067,8 @@ Partial Class Ventas
|
||||
TxtPrecio.Text = GvRow.FCLiteral("LtlPU").Text
|
||||
RegistraScript("Recalcula();")
|
||||
LbAgregar_Click(Nothing, Nothing)
|
||||
Else
|
||||
DdlPS_SelectedIndexChanged(Nothing, Nothing)
|
||||
End If
|
||||
End Sub
|
||||
Protected Sub OrdenarGvPS(ByVal sender As Object, ByVal e As EventArgs)
|
||||
@@ -17347,874 +17355,40 @@ Partial Class Ventas
|
||||
CancelarRefacturada()
|
||||
End If
|
||||
|
||||
'La validacion de saldos cuando es refacturacion se hace antes asi que si es refacturacion ignoramos esta condicion, si es Anticipo verifica que no esté aplicado
|
||||
If DdlTipoComprobante.SelectedValue = "Ant" AndAlso (HdnPagado.Value.ToDecimal > 0 Or GvAntNC.Rows.Count > 0) Then
|
||||
Alert("La factura no se puede cancelar debido a que tiene pagos vinculados.", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
'La validacion de saldos cuando es refacturacion se hace antes asi que si es refacturacion ignoramos esta condicion
|
||||
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem") AndAlso HdnPagado.Value.ToDecimal > 0 Then
|
||||
Alert("La factura no se puede cancelar debido a que tiene pagos vinculados.", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
|
||||
'Si la remision esta facturada no se puede cancelar
|
||||
If DdlTipoComprobante.SelectedValue = "Rem" Then
|
||||
Dim ObjV As New ClsVentas
|
||||
If ObjV.VerificarRemisionFacturada(CveVenta) Then
|
||||
If ObjV.DtResultados.Rows.Count > 0 Then
|
||||
Alert("La remisión no se puede cancelar debido a que ya esta vinculada a una factura.", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
End If
|
||||
ObjV.Dispose()
|
||||
End If
|
||||
|
||||
'CARGA REMISIONES DE LA VENTA DEVUELTA
|
||||
Dim DtDevRem As New DataTable
|
||||
If Not EsRefacturacion Then
|
||||
Dim ObjInventarioTemporal As New ClsInventarios()
|
||||
If ObjInventarioTemporal.GetDevolucionRemisionesCanceladas(CveVenta) Then
|
||||
DtDevRem = ObjInventarioTemporal.DtResultados
|
||||
Else
|
||||
Alert("Ocurrió un error al verificar los movimientos de almacén relacionados al documento.", TipoMensaje.MsgError)
|
||||
ObjInventarioTemporal.Dispose()
|
||||
Exit Sub
|
||||
End If
|
||||
ObjInventarioTemporal.Dispose()
|
||||
End If
|
||||
|
||||
'[IPP] FALTA TERMINAR 27/Noviembre/2018
|
||||
'' si tiene movimientos en almacen que se hallan surtido en el documento actual, y sigue sin ser marcado como devuelto
|
||||
'If (GvInv.Rows.Count > 0 AndAlso DevolucionAlmacen.Contiene(0, 1)) And DtDevRem.COUNT("CantidadSurtida", "ISNULL(CveRem,0) = 0") > 0 Then ' [COMENTADO IPP 3 Agosto 2017] | AndAlso Not (DdlTipoComprobante.SelectedValue.Contiene("Rem", "DPe")) | REMISION YA SE DEBE HACER POR EL PROCESO DE DEVOLUCION DE ALMACEN
|
||||
' Alert("La factura no se puede cancelar debido a que tiene movimientos de inventario.", TipoMensaje.MsgAdvertencia)
|
||||
' Exit Sub
|
||||
'End If
|
||||
|
||||
Dim ReviveRemision As Boolean = False
|
||||
'RMF. ANOTACION. cuando se cancela, y tiene relacionada una remisión, y esta no se cancelará. debe de hacer en automático los movimientos al almacen de entrega por adelantado
|
||||
If Not EsRefacturacion AndAlso ChkCanRem.Visible AndAlso ChkCanRem.Checked = False Then
|
||||
ReviveRemision = True
|
||||
End If
|
||||
If Not EsRefacturacion AndAlso (VentaSaldoAlmacen > 0 AndAlso DevolucionAlmacen.Contiene(0, 1)) AndAlso Not ChkDevAlm.Checked And ReviveRemision = False Then ' [COMENTADO IPP 3 Agosto 2017] | AndAlso Not (DdlTipoComprobante.SelectedValue.Contiene("Rem", "DPe")) | REMISION YA SE DEBE HACER POR EL PROCESO DE DEVOLUCION DE ALMACEN
|
||||
Alert("La factura no se puede cancelar debido a que tiene movimientos de inventario.", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim CancelacionFecha As Date
|
||||
Dim CancelacionAcuse As String = ""
|
||||
Dim MensajeError As String = ""
|
||||
Dim ObjCancelacion As New Timbrado
|
||||
Dim TotalT As Decimal = TxtTotal.Text.ToDecimal
|
||||
Dim RFCReceptor As String = LblRFC.Text.Trim
|
||||
Dim CvePACCancelacion As Integer = CvePAC
|
||||
Dim CveEstatus As Integer = 4
|
||||
Dim IDPoliza As Integer = -1
|
||||
Dim CvePrePoliza As Integer
|
||||
Dim CvePlantillaPoliza As Integer
|
||||
Dim ErrorCancelar As Boolean = False
|
||||
|
||||
Dim Continuar As Boolean = False
|
||||
Dim ContinuarCancelacion As Boolean = False
|
||||
Dim ObtenerAcuse As Boolean = False
|
||||
Dim RequiereAceptacion As Boolean = False
|
||||
Dim Mensaje As String = ""
|
||||
Try
|
||||
If FolioFiscal <> "" Then
|
||||
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Dev", "Egs") Then
|
||||
|
||||
Dim Vigencia = Timbrado.VerificarVigenciaSAT(FolioFiscal, UsuarioActual.Empresa.RFC, RFCReceptor, TotalT.ToString(), UsuarioActual.Empresa.FacturaProduccion)
|
||||
If Vigencia IsNot Nothing Then
|
||||
If Vigencia.EsCancelable.ToUpper() = "NO CANCELABLE" Then
|
||||
Alert("Esta factura no es cancelable.", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
If Vigencia.Estado.ToUpper().Contains("CANCELADO") Then
|
||||
ContinuarCancelacion = False
|
||||
ObtenerAcuse = True
|
||||
Dim solicitud = New WSGF.Service1SoapClient()
|
||||
Dim acuse = solicitud.GetAcuse(UsuarioActual.Empresa.RFC, "rene.molina@adsistemas.mx", "rene2018", FolioFiscal)
|
||||
|
||||
If acuse.Estado = 0 Then
|
||||
Dim xmlAcuse = New System.Xml.XmlDocument()
|
||||
xmlAcuse.LoadXml(DecodeBase64(acuse.CfdiB64))
|
||||
CancelacionAcuse = xmlAcuse.GetElementsByTagName("SignatureValue")(0).InnerText
|
||||
CancelacionFecha = xmlAcuse.SelectSingleNode("Acuse").Attributes("Fecha").Value.ToDate()
|
||||
CveEstatus = 5
|
||||
Else
|
||||
CancelacionFecha = Now.Date
|
||||
CancelacionAcuse = ""
|
||||
CveEstatus = 5
|
||||
End If
|
||||
|
||||
ElseIf Vigencia.Estado.ToUpper().Contains("VIGENTE") Then
|
||||
|
||||
If Vigencia.EstatusCancelacion.ToUpper() = "EN PROCESO" Then
|
||||
CveEstatus = 20
|
||||
ContinuarCancelacion = False
|
||||
If ChkCanRem.Checked Then SeCancelaRemisionProceso = True
|
||||
ElseIf Vigencia.EsCancelable.ToUpper() = "CANCELABLE CON ACEPTACIÓN" Then
|
||||
CveEstatus = 20
|
||||
ContinuarCancelacion = True
|
||||
RequiereAceptacion = True
|
||||
If ChkCanRem.Checked Then SeCancelaRemisionProceso = True
|
||||
ElseIf Vigencia.EsCancelable.ToUpper() = "CANCELABLE SIN ACEPTACIÓN" Then
|
||||
ContinuarCancelacion = True
|
||||
CveEstatus = 5
|
||||
End If
|
||||
|
||||
Else
|
||||
If Vigencia.EsCancelable.ToUpper() = "CANCELABLE SIN ACEPTACIÓN" Then
|
||||
ContinuarCancelacion = True
|
||||
CveEstatus = 5
|
||||
Else
|
||||
'Alert("La factura no se puede cancelar debido a que no se encontro su estatus en el SAT.", TipoMensaje.MsgAdvertencia)
|
||||
'Exit Sub
|
||||
CveEstatus = 20
|
||||
ContinuarCancelacion = False
|
||||
CancelacionFecha = Now.Date
|
||||
CancelacionAcuse = ""
|
||||
If ChkCanRem.Checked Then SeCancelaRemisionProceso = True
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
Alert("No se pudo comprobar la vigencia de la factura.", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
If Not ObtenerAcuse Then
|
||||
If ContinuarCancelacion Then
|
||||
If ObjCancelacion.CFDICancelar(UsuarioActual.Empresa, FolioFiscal, TotalT, RFCReceptor, UsuarioActual.Empresa.RFC, CvePACCancelacion) Then
|
||||
'Generamos el acuse y mandamos mail de con el acuse de cancelación - DF 13/01/2017
|
||||
If RequiereAceptacion Then
|
||||
CancelacionFecha = Now.Date
|
||||
CancelacionAcuse = ""
|
||||
CveEstatus = 20
|
||||
If ChkCanRem.Checked Then SeCancelaRemisionProceso = True
|
||||
Else
|
||||
CancelacionFecha = ObjCancelacion.CancelacionFecha
|
||||
CancelacionAcuse = ObjCancelacion.CancelacionAcuse
|
||||
CveEstatus = 5
|
||||
End If
|
||||
Else
|
||||
Alert("La factura no se pudo cancelar ante el SAT", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End If
|
||||
Else
|
||||
CancelacionFecha = Now.Date
|
||||
CancelacionAcuse = ""
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
CancelacionFecha = Now.Date
|
||||
CancelacionAcuse = ""
|
||||
End If
|
||||
Else
|
||||
CancelacionFecha = Now.Date
|
||||
CancelacionAcuse = ""
|
||||
End If
|
||||
Catch ex As Exception
|
||||
MensajeError = "Ocurrió un Error al Cancelar la factura con los servicios del SAT."
|
||||
GuardaLog($"{MensajeError} - Error:{ex.Message}")
|
||||
Alert(MensajeError, TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End Try
|
||||
|
||||
Dim ObjVentas As New ClsVentas() : ObjVentas.IniciaTransacSQL()
|
||||
Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL())
|
||||
Dim ObjBancos As New ClsBancos(ObjVentas.IniciaTransacSQL())
|
||||
Dim ObjInventario As New ClsInventarios(ObjVentas.IniciaTransacSQL())
|
||||
Dim ObjContrato As New ClsContratos(ObjVentas.IniciaTransacSQL())
|
||||
Dim ObjEventos As New ClsOIEventos(ObjVentas.IniciaTransacSQL())
|
||||
Dim ObjAC As ClsContPAQi = Nothing
|
||||
If UsuarioActual.Empresa.UsaAC Then
|
||||
ObjAC = New ClsContPAQi(UsuarioActual.Empresa) : ObjAC.IniciaTransacSQL()
|
||||
End If
|
||||
CreaObjetosVenta()
|
||||
Dim resp As Modelos.Factura.MCancelacionVentaMensaje = Nothing
|
||||
|
||||
ObjFactura.CveVenta = CveVenta
|
||||
If ObjFactura.TipoDocto.Contiene("Egs", "Dev") Then
|
||||
CvePlantillaPoliza = 7
|
||||
ElseIf ObjFactura.TipoDocto.Contiene("Ing", "Rem", "Ant") Then
|
||||
CvePlantillaPoliza = 4
|
||||
Else
|
||||
CvePlantillaPoliza = 4
|
||||
End If
|
||||
If ObjFactura IsNot Nothing AndAlso ObjFactura.CveVenta > 0 Then
|
||||
|
||||
If ((HplSaldoAuxiliar.Text.ToDecimal > 0 OrElse (TxtTotal.Text.ToDecimal = 0 AndAlso UsuarioActual.CveEmpresa.Contiene(72) AndAlso ObjFactura.TipoDocto.Contiene("Ing"))) AndAlso CveEstatus.Contiene(4, 5)) OrElse CvePlantillaPoliza = 7 Then
|
||||
'RMF. 2018.08.08 cuando se cancela, la póliza debe de ser de diario
|
||||
CvePrePoliza = ObjConta.AddPrePolizas("Ventas/CancelarDocumento", CvePlantillaPoliza, TxtTotal.Text.ToDouble, TxtTotal.Text.ToDouble, DdlMoneda.SelectedValue.ToEntero, Now, NombreCliente, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoPoliza:=3)
|
||||
ObjFactura.CvePrePoliza = CvePrePoliza
|
||||
|
||||
'CANCELAR PAGOS
|
||||
If ObjFactura.TipoDocto.Contiene("Egs", "Dev") Then
|
||||
If Not ErrorCancelar Then
|
||||
If Not ObjConta.PrePolizasCancelarPagos(CveDevolucion, CvePrePoliza) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al generar la prepoliza de cancelación de pago."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
'CANCELA PREPOLIZA
|
||||
If Not ErrorCancelar Then
|
||||
ErrorCancelar = ProcesoPrepolizas(ObjConta, ObjFactura, -1, TmpDT, ObjAC, -1, ObjBancos, ObjVentas, ObjEventos)
|
||||
MensajeError = "Ocurrió un error al generar la prepoliza de cancelación."
|
||||
End If
|
||||
|
||||
'CANCELA IMPUESTOS LOCALES
|
||||
If Not ErrorCancelar Then
|
||||
ErrorCancelar = GuardarVentaImpuestosLocales(ObjVentas, ObjConta, ObjFactura, -1)
|
||||
MensajeError = "Ocurrió un error al cancelar los impuestos locales."
|
||||
End If
|
||||
End If
|
||||
|
||||
'CANCELA CONTRATOS
|
||||
If Not EsRefacturacion Then
|
||||
If Not ErrorCancelar Then
|
||||
ErrorList = New List(Of String)
|
||||
If ObjFactura.CveContrato > 0 AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant") Then
|
||||
GuardarContratoAvanceEstimaciones(ObjContrato, ObjFactura, ErrorList, -1, True)
|
||||
ErrorCancelar = ErrorList.Count > 0
|
||||
MensajeError = "Ocurrió un error al cancelar las estimaciones del contrato."
|
||||
ElseIf ObjFactura.CveContrato > 0 AndAlso DdlTipoComprobante.SelectedValue.Contiene("Egs", "Dev") Then
|
||||
GuardarContratoAvanceEstimaciones(ObjContrato, ObjFactura, ErrorList, 1, True)
|
||||
ErrorCancelar = ErrorList.Count > 0
|
||||
MensajeError = "Ocurrió un error al cancelar los avances del contrato."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
'DESVINCULA COTIZACIONES PREDECESORAS
|
||||
If Not EsRefacturacion Then
|
||||
If Not ErrorCancelar Then
|
||||
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem") Then
|
||||
If Not ObjVentas.LiberarCotizacionesFacturadas(CveVenta) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al desvincular las cotizaciones."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
'DESVINCULA PEDIDOS2 PREDECESORES
|
||||
If Not EsRefacturacion Then
|
||||
If Not ErrorCancelar Then
|
||||
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Rem") Then
|
||||
If Not ObjVentas.LiberarPedidos2Facturados(CveVenta) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al desvincular los pedidos."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
'DESVINCULA OCs PREDECESORAS
|
||||
If Not EsRefacturacion Then
|
||||
If Not ErrorCancelar Then
|
||||
If DdlTipoComprobante.SelectedValue = "Ing" Then
|
||||
If Not ObjVentas.LiberarOCFacturadas(CveVenta) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al desvincular las Ordenes de Compra."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
'ELIMINA LAS VENTAS DETALLE DE LA DEVOLUCION
|
||||
If Not EsRefacturacion Then
|
||||
If Not ErrorCancelar Then
|
||||
If DdlTipoComprobante.SelectedValue = "Dev" Then
|
||||
If Not ObjVentas.RemoveVentaDetalleDevolucion(CveVenta) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al eliminar las ventas detalle devolución."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
'POLIZA DE CANCELACION
|
||||
If Not EsRefacturacion Then
|
||||
If Not ErrorCancelar Then
|
||||
If UsuarioActual.Empresa.UsaAC Then
|
||||
IDPoliza = GenerarPolizaAC(ObjAC, True)
|
||||
If IDPoliza <= 0 Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al generar la poliza de cancelación."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
'DEVOLUCION DE ALMACEN
|
||||
If ChkDevAlm.Checked Or ReviveRemision Then
|
||||
Dim TieneSalida As Boolean = False
|
||||
Dim DtDatos As New DataTable
|
||||
Dim DtExistencias As New DataTable
|
||||
|
||||
If DevolucionAlmacen = 0 Then
|
||||
Dim EstatusDevolucion = 1
|
||||
If Not ObjVentas.UpdateVentasDevolucionAlmacen(EstatusDevolucion, CveVenta) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al solicitar la devolucion de almacen."
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not ErrorCancelar AndAlso ObjInventario.EntregaAlmacenGet(CveVenta) Then
|
||||
If ObjInventario.DtResultados IsNot Nothing AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
|
||||
DtDatos = ObjInventario.DtResultados
|
||||
DtDatos.Columns.Add("Consec", GetType(Integer))
|
||||
DtDatos.Columns.Add("CantidadGV", GetType(Double))
|
||||
DtDatos.Columns.Add("CantidadTraspaso", GetType(Double))
|
||||
Dim Index = 1
|
||||
For Each Dr As DataRow In DtDatos.Rows
|
||||
Dr("Consec") = Index
|
||||
Dr("CantidadGV") = Dr("CantidadF")
|
||||
Index += 1
|
||||
Next
|
||||
|
||||
If DtDatos IsNot Nothing AndAlso DtDatos.Rows.Count > 0 AndAlso ObjInventario.DtResultados.Rows(0)("CveVentaPadre").ToString.ToEntero > 0 Then
|
||||
Dim Filtro As String '= If(ObjInventario.DtResultados.Rows(0)("TipoDocto").ToString.Contiene({"Ing", "Dev", "Ped"}), "CveConcepto = 3", "CveConcepto = 9")
|
||||
Select Case ObjInventario.DtResultados.Rows(0)("TipoDocto").ToString
|
||||
Case "Ing", "Ped"
|
||||
Filtro = "CveConcepto = 3"
|
||||
Case "Dev"
|
||||
Filtro = "CveConcepto = 3"
|
||||
Case Else
|
||||
Filtro = "CveConcepto = 9"
|
||||
End Select
|
||||
If ObjInventario.GetInv_Mov(ObjInventario.DtResultados.Rows(0)("CveVentaPadre").ToString.ToEntero, UsuarioActual.CveEmpresa) Then
|
||||
DtExistencias = ObjInventario.DtResultados.FiltraParametros($"CvePS Is Not NULL AND {Filtro}")
|
||||
|
||||
If DtExistencias.Rows.Count > 0 Then
|
||||
TieneSalida = True
|
||||
End If
|
||||
|
||||
Else
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al cargar los datos de devolución. Por favor vuelva a intentar."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not ErrorCancelar AndAlso TieneSalida Then
|
||||
Dim DtDatosDetalle As New DataTable
|
||||
DtDatosDetalle.Columns.Add("CveVentaDetalle", GetType(Integer))
|
||||
DtDatosDetalle.Columns.Add("Consec", GetType(Integer))
|
||||
DtDatosDetalle.Columns.Add("ConsecId", GetType(Integer))
|
||||
DtDatosDetalle.Columns.Add("CvePS", GetType(Integer))
|
||||
DtDatosDetalle.Columns.Add("PS", GetType(String))
|
||||
DtDatosDetalle.Columns.Add("CveUM", GetType(Integer))
|
||||
DtDatosDetalle.Columns.Add("SerieLote", GetType(String))
|
||||
DtDatosDetalle.Columns.Add("FechaCaducidad", GetType(String))
|
||||
DtDatosDetalle.Columns.Add("FueTraspaso", GetType(Integer))
|
||||
|
||||
Dim DtDatosDetalleLote As New DataTable
|
||||
DtDatosDetalleLote.Columns.Add("CveVentaDetalle", GetType(Integer))
|
||||
DtDatosDetalleLote.Columns.Add("Consec", GetType(Integer))
|
||||
DtDatosDetalleLote.Columns.Add("ConsecId", GetType(Integer))
|
||||
DtDatosDetalleLote.Columns.Add("Cantidad", GetType(Double))
|
||||
DtDatosDetalleLote.Columns.Add("CvePS", GetType(Integer))
|
||||
DtDatosDetalleLote.Columns.Add("PS", GetType(String))
|
||||
DtDatosDetalleLote.Columns.Add("CveUM", GetType(Integer))
|
||||
DtDatosDetalleLote.Columns.Add("Lote", GetType(String))
|
||||
DtDatosDetalleLote.Columns.Add("Batch", GetType(String))
|
||||
DtDatosDetalleLote.Columns.Add("FechaCaducidad", GetType(String))
|
||||
DtDatosDetalleLote.Columns.Add("FueTraspaso", GetType(Integer))
|
||||
|
||||
Dim DtTraspasos As New DataTable
|
||||
DtTraspasos.Columns.Add("CveAlmacen", GetType(Integer))
|
||||
DtTraspasos.Columns.Add("Almacen", GetType(String))
|
||||
DtTraspasos.Columns.Add("CveMovimientoSalida", GetType(Integer))
|
||||
DtTraspasos.Columns.Add("FolioSalida", GetType(Integer))
|
||||
DtTraspasos.Columns.Add("CveMovimientoEntrada", GetType(Integer))
|
||||
DtTraspasos.Columns.Add("FolioEntrada", GetType(Integer))
|
||||
|
||||
Dim ConceptoMovimiento = 18
|
||||
Dim CveMovimiento As Integer = 0
|
||||
Dim Folio As Integer = 0
|
||||
Dim CantidadPendiente As Decimal = 0
|
||||
Dim DtDetalle As New DataTable
|
||||
Dim DtDetalleLote As New DataTable
|
||||
|
||||
CveMovimiento = ObjInventario.AddMovimiento(CveAlmacenDevolucion, ConceptoMovimiento, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVenta, -1, -1, Observaciones:="", Guia:="", CveContrato:=CveContrato, CveAlmacenDestino:=-1)
|
||||
Folio = ObjInventario.Folio
|
||||
|
||||
'SALIDA DE ALMACEN - SALIDA POR TRASPASO CUANDO ES REMISION - DEVOLUCION (SI ES TRASPASO Y TIENE CONTRATO NO HACE DEVOLUCIóN)
|
||||
'If Not (CveContrato > 0 And CveAlmacenTraspasoDestino > 0) Then
|
||||
If CveMovimiento > 0 Then
|
||||
|
||||
'ES EL MOVIMIENTO PRINCIPAL
|
||||
CantidadPendiente = 0
|
||||
For Each Dr As DataRow In DtDatos.Rows
|
||||
CantidadPendiente = Dr("CantidadGV").ToString.ToDecimal - Dr("CantidadTraspaso").ToString.ToDecimal
|
||||
If CantidadPendiente > 0 Then
|
||||
Dim PU As Decimal = 0
|
||||
|
||||
'SI FUE POR SERIELOTE
|
||||
DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec")))
|
||||
DtDetalleLote = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec")))
|
||||
If DtDetalle.Rows.Count > 0 Then
|
||||
For Each Dr1 As DataRow In DtDetalle.Rows
|
||||
If DtExistencias IsNot Nothing Then
|
||||
PU = DtExistencias.FiltroPrimeroValor("PU", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString.ToEntero} AND SerieLote = '{Dr1("SerieLote").ToString}'").ToString.ToDecimal
|
||||
End If
|
||||
|
||||
If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, 1, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, PU, -1, SerieLote:=Dr1("SerieLote").ToString, CveVentaDetalle:=Dr("CveVentaDetalle").ToString.ToEntero) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar."
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
ElseIf DtDetalleLote.Rows.Count > 0 Then
|
||||
For Each Dr1 As DataRow In DtDetalleLote.Rows
|
||||
If DtExistencias IsNot Nothing Then
|
||||
PU = DtExistencias.FiltroPrimeroValor("PU", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString.ToEntero} AND SerieLote = '{Dr1("SerieLote").ToString}'").ToString.ToDecimal
|
||||
End If
|
||||
|
||||
If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr1("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, PU, -1, Lote:=Dr1("Lote").ToString, Batch:=Dr1("Batch").ToString, CveVentaDetalle:=Dr("CveVentaDetalle").ToString.ToEntero) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar."
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Else
|
||||
If DtExistencias IsNot Nothing Then
|
||||
PU = DtExistencias.FiltroPrimeroValor("PU", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString.ToEntero}").ToString.ToDecimal
|
||||
End If
|
||||
|
||||
If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, CantidadPendiente, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, PU, -1, CveVentaDetalle:=Dr("CveVentaDetalle").ToString.ToEntero) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al procesar los conceptos de salida. Por favor vuelva a intentar."
|
||||
Exit For
|
||||
End If
|
||||
End If
|
||||
|
||||
End If
|
||||
Next
|
||||
Else
|
||||
ErrorCancelar = True
|
||||
End If
|
||||
|
||||
If Not ErrorCancelar Then
|
||||
Dim DtCostos As DataTable = Nothing
|
||||
Dim ValorInventario As Decimal = 0
|
||||
If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then
|
||||
DtCostos = ObjInventario.DtResultados
|
||||
|
||||
Dim tmpCostos As DataTable = DtCostos.FiltraParametros("", "", {"CveClasificacion"})
|
||||
Dim IdCtaContableAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen = {CveAlmacenDevolucion}").ToEntero
|
||||
Dim CveCuentaAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContableSIG", $"CveAlmacen = {CveAlmacenDevolucion}").ToEntero
|
||||
Dim IdCtaContable As Integer = 0
|
||||
Dim CveCuenta As Integer = 0
|
||||
If tmpCostos.Rows.Count > 0 Then
|
||||
|
||||
|
||||
If ObjVentas.GetVenta(CveVenta, UsuarioActual.CveEmpresa) Then
|
||||
Dim Fecha As Date = Now
|
||||
Dim CveCliente As Integer = ObjVentas.DtResultados(0)("CveCliente").ToString.ToEntero
|
||||
Dim ClienteNombre As String = ObjVentas.DtResultados(0)("ClienteNombre").ToString
|
||||
Dim SerieFolio As String = ObjVentas.DtResultados(0)("SerieFolio").ToString
|
||||
Dim TotalCosto As Decimal = DtCostos.SUMD("Total").RoundSQL()
|
||||
Dim TotalCostoAcumulado As Decimal = 0
|
||||
Dim cont As Integer = 1
|
||||
|
||||
Dim CvePrePolizaDev As Integer = ObjConta.AddPrePolizas("Inventario/RecepcionEntrega", 4, TotalCosto, TotalCosto, 1, Fecha, ClienteNombre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
||||
'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 = DtCostos.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(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {RowInv("CveClasificacion")}").ToEntero
|
||||
CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostosSIG", $"CveClasificacion = {RowInv("CveClasificacion")}").ToEntero
|
||||
|
||||
If Not ErrorCancelar Then
|
||||
If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaDev, False, -1 * ValorInventario, SerieFolio, 69, SerieFolio, Fecha, IdCtaContable, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, CveMovimientoAlmacen:=CveMovimiento, CveSubProyecto:=DdlSubProyectoDatos.SelectedValue.ToEntero, ImporteMX:=-1 * ValorInventario, CveCuenta:=CveCuenta, CveClasificacion:=RowInv("CveClasificacion").ToString.ToEntero) Then
|
||||
ErrorCancelar = True
|
||||
End If
|
||||
End If
|
||||
|
||||
cont += 1
|
||||
Next
|
||||
|
||||
If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaDev, True, -1 * TotalCosto, SerieFolio, 68, SerieFolio, Fecha, IdCtaContableAlmacen, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, CveMovimientoAlmacen:=CveMovimiento, CveSubProyecto:=DdlSubProyectoDatos.SelectedValue.ToEntero, ImporteMX:=-1 * TotalCosto, CveCuenta:=CveCuentaAlmacen) Then
|
||||
ErrorCancelar = True
|
||||
End If
|
||||
|
||||
'AutoConta - El movimiento 1 es el de Venta
|
||||
|
||||
Dim AutoConta As Boolean = UsuarioActual.Empresa.Funcionalidad(200) = "1"
|
||||
|
||||
If UsuarioActual.CveEmpresa = 119 AndAlso DdlTipoComprobante.SelectedValue = "Ant" Then
|
||||
AutoConta = False
|
||||
End If
|
||||
|
||||
If AutoConta And Not ErrorCancelar Then
|
||||
Dim ObjContPaq = New ClsContPAQi(UsuarioActual.Empresa)
|
||||
|
||||
If IdCtaContable > 0 Then
|
||||
If Not ObjConta.ContabilizarPrePoliza(CvePrePolizaDev, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContPaq) Then
|
||||
Alert("Ocurrio un Error al contabilizar, pongase en contacto con Soporte Técnico")
|
||||
End If
|
||||
Else
|
||||
Alert(String.Format("No se puede contabilizar ya que falta asignación de las cuentas contables"), TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
|
||||
ObjContPaq.Dispose()
|
||||
End If
|
||||
|
||||
Else
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un Error al ingresar las prepolizas"
|
||||
End If
|
||||
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not ErrorCancelar Then
|
||||
If ObjInventario.VentasAlmacenApartadosGet(CveVenta) Then
|
||||
|
||||
Dim DtTempApartados = ObjInventario.DtResultados.FiltraParametros("CveTipoAlmacen = 9", "CveAlmacen")
|
||||
Dim CveMovimientoSalidaApartado = -1
|
||||
Dim CveAlmacenApartado = -1
|
||||
Dim CveAlmacenOrigen = CveAlmacenDevolucion
|
||||
Dim FolioSalida As Integer = 0, FolioEntrada = 0, CveMovimientoSalida = 0, CveMovimientoEntradaApartado = 0
|
||||
|
||||
For Each Dr As DataRow In DtTempApartados.Rows
|
||||
|
||||
If CveMovimientoSalidaApartado = -1 Or CveAlmacenApartado <> Dr("CveAlmacen").ToString.ToEntero Then
|
||||
CveMovimientoSalidaApartado = ObjInventario.AddMovimiento(CveAlmacenOrigen, 8, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVenta, -1, -1, Observaciones:="", Guia:="", CveContrato:=CveContrato, CveVendedor:=1, CveCliente:=CveCliente, CveAlmacenDestino:=Dr("CveAlmacen").ToString.ToEntero)
|
||||
FolioSalida = ObjInventario.Folio
|
||||
CveAlmacenApartado = Dr("CveAlmacen").ToString.ToEntero
|
||||
|
||||
Dim DrMovto = DtTraspasos.NewRow
|
||||
DrMovto("Almacen") = Dr("Almacen").ToString.ToEntero
|
||||
DrMovto("CveAlmacen") = Dr("CveAlmacen").ToString.ToEntero
|
||||
DrMovto("CveMovimientoSalida") = CveMovimientoSalidaApartado
|
||||
DrMovto("FolioSalida") = FolioSalida
|
||||
DtTraspasos.Rows.Add(DrMovto)
|
||||
End If
|
||||
|
||||
If Not CveMovimientoSalidaApartado > 0 Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al guardar los movimientos de control de apartados"
|
||||
Exit For
|
||||
End If
|
||||
|
||||
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalidaApartado, Dr("Cantidad").ToString.ToDecimal, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDecimal, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, CveVentaDetalle:=Dr("CveVentaDetalle").ToString.ToEntero, Lote:=Dr("Lote").ToString, Batch:=Dr("Batch").ToString) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al guardar los movimientos de control de apartados"
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If Not ErrorCancelar Then
|
||||
For Each Dr1 As DataRow In DtTraspasos.Rows
|
||||
CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString.ToEntero
|
||||
|
||||
CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString.ToEntero, 9, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVenta, -1, -1, Observaciones:="", CveAlmacenDestino:=CveAlmacenDevolucion, CveMovimientoRelacionado:=CveMovimientoSalida, Guia:="", CveContrato:=CveContrato, CveVendedor:=-1, CveCliente:=CveCliente)
|
||||
FolioEntrada = ObjInventario.Folio
|
||||
|
||||
If Not CveMovimientoEntradaApartado > 0 Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar."
|
||||
Exit For
|
||||
End If
|
||||
|
||||
Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado
|
||||
Dr1("FolioEntrada") = FolioEntrada
|
||||
|
||||
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
|
||||
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
|
||||
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString.ToDecimal, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDecimal, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString.ToEntero, Lote:=Dr("Lote").ToString, Batch:=Dr("Batch").ToString) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar."
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
If ErrorCancelar Then Exit For
|
||||
Next
|
||||
End If
|
||||
|
||||
End If
|
||||
End If
|
||||
|
||||
'DEVOLUCION REMISION - REGRESA LAS EXISTENCIAS A ENTREGA POR ADELANTADO SI LA FACTURA VIENE DE REMISION
|
||||
If Not ErrorCancelar Then
|
||||
Dim DtMovtosDev As New DataTable
|
||||
Dim CveAlmacenTraspasoDestinoDevRem = -1
|
||||
|
||||
Dim CveVentaDetalleRem = -1
|
||||
Dim CantidadDevolver As Decimal = 0
|
||||
Dim CantidadRem As Decimal = 0
|
||||
Dim CveMovimientoSalidaDevRem As Integer = 0
|
||||
Dim FolioMovimientoSalidaDevRem As Integer = 0
|
||||
Dim CveMovimientoEntradaDevRem As Integer = 0
|
||||
Dim FolioMovimientoEntradaDevRem As Integer = 0
|
||||
|
||||
'CARGA REMISIONES DE LA VENTA DEVUELTA
|
||||
If ObjInventario.GetDevolucionRemisionesFacturadas(CveVenta) Then
|
||||
DtDevRem = ObjInventario.DtResultados.FiltraParametros("CantidadAlmacen > 0")
|
||||
Else
|
||||
ErrorCancelar = True
|
||||
End If
|
||||
|
||||
'CARGA CONCEPTOS DEVUELTOS EN LA VENTA
|
||||
If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then
|
||||
DtMovtosDev = ObjInventario.DtResultados
|
||||
Else
|
||||
ErrorCancelar = True
|
||||
End If
|
||||
|
||||
If Not ErrorCancelar Then
|
||||
If DtDevRem.Rows.Count > 0 And DtMovtosDev.Rows.Count > 0 Then
|
||||
|
||||
For Each DrMovtos As DataRow In DtDevRem.FiltraParametros("", "CveRem", {"CveRem", "CveAlmacenTraspasoDestino"}).Rows
|
||||
|
||||
'CHECO SI NO SE VA A CANCELAR
|
||||
Dim SeCancela As Boolean = False
|
||||
If ChkCanRem.Checked Then
|
||||
For Each Gvr As GridViewRow In GvCancelarRemisiones.Rows
|
||||
If Gvr.FCCheckBox("ChkCancelarRemision").Checked AndAlso DrMovtos("CveRem").ToString.ToEntero = Gvr.DataKey("CveVenta").ToString.ToEntero Then
|
||||
SeCancela = True
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
If Not SeCancela Then
|
||||
|
||||
CveAlmacenTraspasoDestinoDevRem = DrMovtos("CveAlmacenTraspasoDestino").ToString.ToEntero
|
||||
If Not CveAlmacenTraspasoDestinoDevRem > 0 Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al obtener el almacén de devolucion de remisión."
|
||||
Exit For
|
||||
End If
|
||||
|
||||
'SALIDA GENERAL
|
||||
CveMovimientoSalidaDevRem = ObjInventario.AddMovimiento(CveAlmacenDevolucion, 8, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, DrMovtos("CveRem").ToString.ToEntero, -1, -1, Observaciones:="", Guia:="", CveContrato:=CveContrato, CveMovimientoRelacionado:=CveMovimiento, CveAlmacenDestino:=CveAlmacenTraspasoDestinoDevRem)
|
||||
FolioMovimientoSalidaDevRem = ObjInventario.Folio
|
||||
|
||||
'ENTRADA ADELANTADO
|
||||
CveMovimientoEntradaDevRem = ObjInventario.AddMovimiento(CveAlmacenTraspasoDestinoDevRem, 9, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, DrMovtos("CveRem").ToString.ToEntero, -1, -1, Observaciones:="", Guia:="", CveContrato:=CveContrato, CveMovimientoRelacionado:=CveMovimientoSalidaDevRem, CveAlmacenDestino:=CveAlmacenDevolucion)
|
||||
FolioMovimientoEntradaDevRem = ObjInventario.Folio
|
||||
|
||||
If Not (CveMovimientoSalidaDevRem > 0 And CveMovimientoEntradaDevRem > 0) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al generar los movimientos de devolución a remisión."
|
||||
Exit For
|
||||
End If
|
||||
|
||||
|
||||
'SALIDA POR TRAPASO DE GENERAL
|
||||
For Each DrRem As DataRow In DtDevRem.FiltraParametros($"CveRem = {DrMovtos("CveRem")}").Rows
|
||||
CveVentaDetalleRem = DrRem("CveVentaDetalleRem").ToString.ToEntero
|
||||
CantidadRem = DrRem("CantidadFacturada").ToString.ToDecimal
|
||||
'CantidadDevolver = DtMovtosDev.FiltroPrimeroValor("Cantidad", $"CveVentaDetalle = {DrRem("CveVentaDetalle").ToString.ToEntero}").ToDouble
|
||||
'If (Dr("Cantidad").ToString.ToDouble > CantidadRem, CantidadRem, Dr("Cantidad").ToString.ToDouble) Then
|
||||
|
||||
If Not CveVentaDetalleRem > 0 Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al obtener la relación de la venta con la remisión."
|
||||
Exit For
|
||||
End If
|
||||
|
||||
For Each Dr As DataRow In DtMovtosDev.FiltraParametros($"CveVentaDetalle = {DrRem("CveVentaDetalle").ToString.ToEntero}").Rows
|
||||
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalidaDevRem, Dr("Cantidad").ToString.ToDecimal, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDouble, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, CveVentaDetalle:=CveVentaDetalleRem, Lote:=Dr("Lote").ToString, Batch:=Dr("Batch").ToString) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al guardar los movimientos de salida de traspaso de devolucion de remisión."
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If ErrorCancelar Then
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If ErrorCancelar Then
|
||||
Exit For
|
||||
End If
|
||||
|
||||
'ENTRADA POR TRAPASO A ENTREGA POR ADELANTADO
|
||||
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalidaDevRem, UsuarioActual.CveEmpresa) Then
|
||||
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
|
||||
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaDevRem, Dr("Cantidad").ToString.ToDecimal, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDecimal, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, CveVentaDetalle:=Dr("CveVentaDetalle").ToString.ToEntero, Lote:=Dr("Lote").ToString, Batch:=Dr("Batch").ToString) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al guardar los movimientos de entrada de traspaso de devolucion de remisión."
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If ErrorCancelar Then
|
||||
Exit For
|
||||
End If
|
||||
|
||||
Else
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al obtener los detalles de la devolución de almacén"
|
||||
Exit For
|
||||
End If
|
||||
|
||||
|
||||
If Not ObjVentas.UpdateVentasDevolucionAlmacen(0, DrMovtos("CveRem").ToString.ToEntero) Then
|
||||
MensajeError = "Ocurrió un error al hacer la devolucion hacia la remision. Por favor vuelva a intentar."
|
||||
ErrorCancelar = True
|
||||
Exit For
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
Next
|
||||
End If
|
||||
Else
|
||||
MensajeError = "Ocurrió un error al hacer la devolucion a remisión. Por favor vuelva a intentar."
|
||||
ErrorCancelar = True
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
If Not ErrorCancelar Then
|
||||
'QUEMA DEVOLUCION | QUEMA = LA QUITA DE PENDIENTE POR RECIBIR (DEVOLVER)
|
||||
If Not ErrorCancelar Then
|
||||
If Not ObjVentas.UpdateVentasDevolucionAlmacen(2, CveVenta) Then
|
||||
MensajeError = "Ocurrió un error al hacer la devolucion. Por favor vuelva a intentar."
|
||||
ErrorCancelar = True
|
||||
End If
|
||||
End If
|
||||
|
||||
'AGREGA BITACORA A VENTA
|
||||
If Not ErrorCancelar Then
|
||||
Dim MensajeBitacora = "Devuelta"
|
||||
If Not ObjEventos.AddEventoBitacora(String.Format("Venta {2} en Folio: <a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a>", CveMovimiento, Folio, MensajeBitacora), "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=CveVenta) Then
|
||||
ErrorCancelar = True
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
End If
|
||||
End If
|
||||
|
||||
'DESVINCULA REMISIONES PREDECESORAS
|
||||
If Not EsRefacturacion Then
|
||||
If Not ErrorCancelar Then
|
||||
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant") Then
|
||||
If Not ChkCanRem.Checked Then
|
||||
If Not ObjVentas.LiberarRemisionesFacturadas(CveVenta) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al desvincular las remisiones."
|
||||
End If
|
||||
Else
|
||||
For Each Gvr As GridViewRow In GvCancelarRemisiones.Rows
|
||||
If Not Gvr.FCCheckBox("ChkCancelarRemision").Checked Then
|
||||
If Not ObjVentas.LiberarRemisionesFacturadas(CveVenta, Gvr.DataKey("CveVenta").ToEntero) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al desvincular las remisiones."
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
'ACTUALIZA ESTATUS
|
||||
If Not ErrorCancelar Then
|
||||
Select Case DdlTipoComprobante.SelectedValue
|
||||
Case "Rem"
|
||||
CveEstatus = 12
|
||||
Case "Com"
|
||||
CveEstatus = 9
|
||||
End Select
|
||||
'0 Sin Refacturacion, 1 Refacturacion en Proceso, 3. Refacturación en proceso sin aceptación
|
||||
Me.CveEstatusRefacturacion = 0
|
||||
If EsRefacturacion Then
|
||||
If CveEstatus = 5 Then
|
||||
CveEstatusRefacturacion = 3 ' refacturación en proceso sin autorización de cancelación
|
||||
Else
|
||||
CveEstatusRefacturacion = 1 ' refacturación en proceso con autorización de cancelación
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
If Not ObjVentas.UpdateEstatusFactura(CveEstatus, FolioFiscal, CancelacionAcuse, CancelacionFecha, CveVenta, IDPoliza, CvePAC:=CvePACCancelacion, CveEstatusRefacturacion:=CveEstatusRefacturacion,
|
||||
CveUsuarioCambiaEstatus:=UsuarioActual.CveUsuario, FechaCambioEstatus:=Now.ToString("yyyy-MM-dd hh:mm:ss.mmm")) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al guardar el estatus de cancelación."
|
||||
End If
|
||||
|
||||
If ChkCanRem.Checked Then
|
||||
For Each Gvr As GridViewRow In GvCancelarRemisiones.Rows
|
||||
If Gvr.FCCheckBox("ChkCancelarRemision").Checked Then
|
||||
If Not SeCancelaRemisionProceso Then
|
||||
If Not ObjVentas.UpdateEstatusFactura(12, "", "", CancelacionFecha, Gvr.DataKey("CveVenta").ToEntero) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al guardar el estatus de cancelación de la remisión."
|
||||
End If
|
||||
Else
|
||||
If Not ObjVentas.AddRemisionesXCancelar(CveVenta, Gvr.DataKey("CveVenta").ToEntero) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al guardar la remisión x cancelar."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
If SeCancelaRemisionProceso Then
|
||||
If Not ObjVentas.UpdateCancelaRemision(CveVenta, SeCancelaRemisionProceso) Then
|
||||
ErrorCancelar = True
|
||||
MensajeError = "Ocurrió un error al actualizar que la remision sea cancelable."
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
If Not ErrorCancelar Then
|
||||
ObjVentas.Commit()
|
||||
|
||||
If CveEstatus = 5 Then
|
||||
Dim MensajeAlert As New StringBuilder
|
||||
MensajeAlert.Append("El Documento se canceló correctamente.")
|
||||
MensajeAlert.Append($"</br> <a href='/Compras/PopUpVerFactura.aspx?P={Encripta($"OP=CAN&CVEVTA={CveVenta}")}' class='Texto' target='_blank'>Imprimir Acuse</a>")
|
||||
MensajeAlert.Append("</br></br> ¿Desea enviar el Acuse de Cancelación al Cliente?")
|
||||
Alert(MensajeAlert.ToString, TipoMensaje.MsgConfirmacion, JSBtnAceptar:="BtnEnviarMailCancelacion();", TextoConfirmacion:=" Si ", TextoCancelacion:=" <a onclick='Recargar()'>No</> ")
|
||||
|
||||
resp = ObjFactura.CancelarPorRefacturacion()
|
||||
Else
|
||||
If Not EsRefacturacion Then
|
||||
Alert("El documento se canceló exitosamente.", TipoMensaje.MsgInformacion, JSBtnAceptar:="BtnRefrescarPagina();")
|
||||
Else
|
||||
Response.Redirect($"/Ventas/RepCancelacionesPorRespuesta.aspx?CveVenta={Me.CveVenta}")
|
||||
Dim ListaRemisionesCancelar As New List(Of Integer)
|
||||
If ChkCanRem.Checked Then
|
||||
For Each Gvr As GridViewRow In GvCancelarRemisiones.Rows
|
||||
If Gvr.FCCheckBox("ChkCancelarRemision").Checked Then
|
||||
ListaRemisionesCancelar.Add(Gvr.DataKey("CveVenta").ToEntero)
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
If ChkDevAlm.Checked Then
|
||||
ObjFactura.CveAlmacenDevolucion = CveAlmacenDevolucion
|
||||
End If
|
||||
|
||||
resp = ObjFactura.CancelarFactura(ChkDevAlm.Checked, ListaRemisionesCancelar)
|
||||
End If
|
||||
|
||||
Me.CveEstatus = CveEstatus
|
||||
If CveEstatus = 5 Then LbCancelarDocumento.Enabled = False
|
||||
If ObjAC IsNot Nothing Then ObjAC.Commit()
|
||||
Else
|
||||
Alert(MensajeError, TipoMensaje.MsgError)
|
||||
ObjVentas.RollBack()
|
||||
If ObjAC IsNot Nothing Then ObjAC.RollBack()
|
||||
End If
|
||||
If resp.CveEstatus = 5 Then
|
||||
Alert(resp.Mensaje, resp.TipoMensaje, JSBtnAceptar:="BtnEnviarMailCancelacion();", TextoConfirmacion:=" Si ", TextoCancelacion:=" <a onclick='Recargar()'>No</> ")
|
||||
Else
|
||||
Alert(resp.Mensaje, resp.TipoMensaje, JSBtnAceptar:="BtnRefrescarPagina();")
|
||||
End If
|
||||
|
||||
ObjVentas.Dispose()
|
||||
ObjBancos.Dispose()
|
||||
ObjInventario.Dispose()
|
||||
ObjContrato.Dispose()
|
||||
ObjConta.Dispose()
|
||||
If ObjAC IsNot Nothing Then ObjAC.Dispose()
|
||||
ObjFactura.CveAlmacen = -1
|
||||
Else
|
||||
Alert("Ocurrió un error al generar la cancelación", TipoMensaje.MsgError)
|
||||
End If
|
||||
|
||||
UpEstatus.Update()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user