Impuestos en remisiones de NC, validacion de cotizaciones

This commit is contained in:
2020-11-06 20:02:12 -07:00
parent 7bf581ec2d
commit d49ea482d8
4 changed files with 718 additions and 371 deletions

View File

@@ -1052,10 +1052,11 @@ Partial Class Inventarios_RecepcionUsados
Protected Sub Guardar(Optional GenerarRNC As Boolean = False)
If GvM.Rows.Count > 0 Then
Dim Msg As New StringBuilder()
Dim Resp As Modelos.Factura.MMensajeFactura = Nothing
Dim ObjInventario As New ClsInventarios
Dim ObjAcum As New ClsAcumuladores(ObjInventario.IniciaTransacSQL())
Dim ObjVentas As New ClsVentas(ObjInventario.IniciaTransacSQL())
Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL())
Dim ErrorMovInv As Boolean = False
Dim ErrorAC As Boolean = False
@@ -1089,93 +1090,116 @@ Partial Class Inventarios_RecepcionUsados
CveVenta = -1
End If
If Not ErrorMovInv AndAlso GenerarRNC AndAlso ObjRemisionNC IsNot Nothing Then
CargaDTDetalleRNC()
Dim Resp = ObjRemisionNC.EmitirFactura(False, ObjInventario.IniciaTransacSQL)
For Each mensaje2 As String In Resp.Mensajes
Msg.AppendFormat("<br>{0}", mensaje2)
Next
Resp = ObjRemisionNC.EmitirFactura(False, ObjInventario.IniciaTransacSQL)
'For Each mensaje2 As String In Resp.Mensajes
' Msg.AppendFormat("<br>{0}", mensaje2)
'Next
If Resp.TieneError Then ErrorMovInv = True
Alert(Msg.ToString, If(Resp.CveVenta > 0, TipoMensaje.MsgInformacion, TipoMensaje.MsgAdvertencia))
'Alert(Msg.ToString, If(Resp.CveVenta > 0, TipoMensaje.MsgInformacion, TipoMensaje.MsgAdvertencia))
CveVenta = Resp.CveVenta
End If
CveMovimiento = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero, CveConcepto, 1, Fecha, tFolio, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVenta,
Dim Mensaje As String = ""
Dim FolioInv As String = ""
If GenerarRNC Then
CveMovimiento = Resp.CveMovimientoUsado
FolioInv = Resp.FolioUsado
Else
CveMovimiento = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero, CveConcepto, 1, Fecha, tFolio, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVenta,
CveSubProyecto, ActivoFijo, Guia:=TxtGuia.Text, Observaciones:=TxtObservaciones.Text, CvePersonal:=DdlPersonal.SelectedValue.ToEntero,
Recibio:=TxtResponsable.Text.Trim, CveCliente:=CveCliente, CveClienteSucursal:=CveClienteSucursal, DepartamentoEntrega:=TxtDepartamentoEntrega.Text,
PedidoContrato:=TxtPedidoContrato.Text, CveProveedor:=tCveProveedor, Modulo:="RU/G")
If CveMovimiento <= 0 Then
Alert("No se pudo almacenar el movimiento correctamente", TipoMensaje.MsgError)
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
ObjInventario.RollBack() 'deshace lo insertado
Else
Dim Mensaje As String = ""
If CveMovimiento <= 0 Then
Mensaje = "Error al guardar los movimientos"
ErrorMovInv = True
Else
FolioInv = ObjInventario.Folio.ToString()
For Each Dr As DataRow In DtMovimientos.Rows
If CveConcepto = 42 AndAlso DdlMoneda.SelectedValue.ToEntero = 2 Then
ImporteConcepto = Dr("PU").ToString.ToDecimal * GlobalTipoCambio(TxtFecha.Text.ToDate).ToDecimal
Else
ImporteConcepto = Dr("PU").ToString.ToDecimal
End If
For Each Dr As DataRow In DtMovimientos.Rows
If CveConcepto = 42 AndAlso DdlMoneda.SelectedValue.ToEntero = 2 Then
ImporteConcepto = Dr("PU").ToString.ToDecimal * GlobalTipoCambio(TxtFecha.Text.ToDate).ToDecimal
Else
ImporteConcepto = Dr("PU").ToString.ToDecimal
End If
If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, ImporteConcepto, CveAF:=Dr("CveAF").ToString.ToEntero, Serie:=Dr("Serie").ToString, Lote:=Dr("Lote").ToString, FechaCaducidad:=Dr("FechaCaducidad").ToString.ToDate, Observaciones:=Dr("Observaciones").ToString, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then
Mensaje = "Error al guardar los movimientos"
ErrorMovInv = True
Exit For
End If
If CveVenta > 0 AndAlso Not ObjVentas.UpdateVentaUsadoRecibido(CveVenta, Dr("CvePS").ToString.ToEntero, True, CveMovimiento) Then
Mensaje = "Error al actualizar el recibo de los usados"
ErrorMovInv = True
Exit For
End If
'si es selectedvalue = 42, es entrada ,3 -salida
Dim CveConceptoUsados As Integer = If(RBLOpcion.SelectedValue.ToEntero = 42, 1, 2)
If EsDistribuidor AndAlso RBLOpcion.SelectedValue.ToEntero = 42 AndAlso Dr("CveTamaño").ToString.ToEntero > 0 Then
If Not ObjAcum.DistribuidorMovtosAdd(DdlClientes.SelectedValue.ToEntero, Dr("Cantidad").ToString.ToEntero(), Dr("CveTamaño").ToString.ToEntero, CveConceptoUsados, CveVenta, UsuarioActual.CveUsuario,
UsuarioActual.CveEmpresa, 0, Dr("Observaciones").ToString, CveMovimiento:=CveMovimiento) Then
Mensaje = "Error al guardar Movimientos de distribuidor"
If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, ImporteConcepto, CveAF:=Dr("CveAF").ToString.ToEntero, Serie:=Dr("Serie").ToString, Lote:=Dr("Lote").ToString, FechaCaducidad:=Dr("FechaCaducidad").ToString.ToDate, Observaciones:=Dr("Observaciones").ToString, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then
Mensaje = "Error al guardar los movimientos"
ErrorMovInv = True
Exit For
End If
End If
Next
If CveVenta > 0 AndAlso Not ObjVentas.UpdateVentaUsadoRecibido(CveVenta, Dr("CvePS").ToString.ToEntero, True, CveMovimiento) Then
Mensaje = "Error al actualizar el recibo de los usados"
ErrorMovInv = True
Exit For
End If
If Not ErrorMovInv Then
'si es selectedvalue = 42, es entrada ,3 -salida
Dim CveConceptoUsados As Integer = If(RBLOpcion.SelectedValue.ToEntero = 42, 1, 2)
If EsDistribuidor AndAlso RBLOpcion.SelectedValue.ToEntero = 42 AndAlso Dr("CveTamaño").ToString.ToEntero > 0 Then
Msg.AppendFormat("<br/>El Movimiento se registro con el Folio: <b><a href='Inventarios/EntradasSalidas.aspx?CveMovimiento={1}'>{0}</a></b>", ObjInventario.Folio, CveMovimiento)
Msg.AppendFormat("<br/><br/> <a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Movimiento</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimiento)))
If Not ObjAcum.DistribuidorMovtosAdd(DdlClientes.SelectedValue.ToEntero, Dr("Cantidad").ToString.ToEntero(), Dr("CveTamaño").ToString.ToEntero, CveConceptoUsados, CveVenta, UsuarioActual.CveUsuario,
UsuarioActual.CveEmpresa, 0, Dr("Observaciones").ToString, CveMovimiento:=CveMovimiento) Then
Mensaje = "Error al guardar Movimientos de distribuidor"
ErrorMovInv = True
Exit For
End If
If IDPoliza > 0 Then Msg = Msg.AppendFormat("<br/><br/> <a class=""Texto"" target='_blank' href=""/Contabilidad/RegPoliza.aspx?IdPoliza={0}"">Ver Póliza</a>", IDPoliza)
End If
Next
ObjInventario.Commit() ' aplica los movimientos insertados
'GENERA LA PREPOLIZA DE ALMACEN VS EL CONCEPTO DE RNC
'If Not ErrorMovInv Then
' ErrorMovInv = Not GeneraPrePoliza(CveMovimiento, ObjInventario, ObjConta, True)
'End If
'Limpia Valores cuando inserta de campos especiales
If UsuarioActual.CveEmpresa = 66 Then
DdlSubProyecto.SelectedValueExist("-1")
End If
' EnvioCorreo()
CargaPendientesRecibir()
UPDatos.Update()
Else
ObjInventario.RollBack() 'deshace lo insertado
CveMovimiento = 0
Alert("ocurrió un Error al registrar los movimientos", TipoMensaje.MsgError)
End If
End If
If Not ErrorMovInv Then
If Resp IsNot Nothing Then
For Each mensaje2 As String In Resp.Mensajes
Msg.AppendFormat("<br>{0}", mensaje2)
Next
End If
End If
If Not ErrorMovInv Then
Msg.AppendFormat("<br/>El Movimiento se registro con el Folio: <b><a href='/Inventarios/EntradasSalidas.aspx?CveMovimiento={1}' target='_blank'>{0}</a></b>", FolioInv, CveMovimiento)
Msg.AppendFormat("<br/><br/> <a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Movimiento</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimiento)))
If IDPoliza > 0 Then Msg = Msg.AppendFormat("<br/><br/> <a class=""Texto"" target='_blank' href=""/Contabilidad/RegPoliza.aspx?IdPoliza={0}"">Ver Póliza</a>", IDPoliza)
ObjInventario.Commit() ' aplica los movimientos insertados
'Limpia Valores cuando inserta de campos especiales
If UsuarioActual.CveEmpresa = 66 Then
DdlSubProyecto.SelectedValueExist("-1")
End If
' EnvioCorreo()
CargaPendientesRecibir()
UPDatos.Update()
Else
ObjInventario.RollBack() 'deshace lo insertado
CveMovimiento = 0
Alert("ocurrió un Error al registrar los movimientos", TipoMensaje.MsgError)
End If
End If
Catch ex As Exception
ObjInventario.RollBack() 'deshace lo insertado
@@ -1202,6 +1226,94 @@ Partial Class Inventarios_RecepcionUsados
End Sub
Private Function GeneraPrePoliza(CveMovimiento As Integer, ByRef ObjInventario As ClsInventarios, ByRef ObjConta As ClsContabilidad, EsContabilizable As Boolean) As Boolean
Dim Correcto As Boolean = True
Try
Dim DtCostos As DataTable = Nothing
Dim ValorInventario As Decimal = 0
Dim ValorInventarioME As Decimal = 0
ObjInventario.GetMovimientos(CveMovimiento, -1, -1, UsuarioActual.CveEmpresa)
Dim CveVenta As Integer = ObjInventario.CveVenta
Dim CveAlmacen As Integer = ObjInventario.CveAlmacen
Dim SerieFolio As String = ObjInventario.DtResultados.Rows(0)("SerieFolioVenta").ToString
Dim MovAlmacen As Boolean = True
Dim CveConcepto As Integer = ObjInventario.DtResultados.Rows(0)("CveConcepto").ToString().ToEntero()
Dim OrigenMov As Integer = GlobalDTInvConceptos.FiltroPrimeroValor("Origen", "CveConcepto = " & CveConcepto).ToEntero
If OrigenMov = 1 Then MovAlmacen = False Else MovAlmacen = True
If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then
DtCostos = ObjInventario.DtResultados
Dim tmpCostos As DataTable = DtCostos.FiltraParametros("", "", {"CveClasificacion"})
Dim IdCtaContable As Integer = 0
Dim ConceptoPoliza As String = String.Format("{0}-{1}", "Salida de Almacen", SerieFolio)
If tmpCostos.Rows.Count > 0 Then
Dim Concepto As String = ConceptoPoliza
Dim CvePrePoliza = ObjConta.AddPrePolizas("Inv_EntradaSalida", 74, DtCostos.SUM("Total"), DtCostos.SUM("Total"), 1, TxtFecha.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
Dim tCveSubProyecto = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen={CveAlmacen}").ToEntero
Dim tCveConcepto As Integer = 278
For Each RowInv As DataRow In tmpCostos.Rows
ValorInventario = DtCostos.SUM("Total", $"CveClasificacion = {RowInv("CveClasificacion")}").ToString.ToDecimal.RoundSQL
If tCveConcepto = 69 Then
IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {RowInv("CveClasificacion")}").ToEntero
End If
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not MovAlmacen, ValorInventario, Concepto, tCveConcepto, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveVenta:=CveVenta, CveClasificacion:=RowInv("CveClasificacion").ToString.ToEntero, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=ValorInventario, CveSubProyecto:=tCveSubProyecto, Contabilizable:=EsContabilizable) Then
Correcto = False
Exit For
End If
Next
IdCtaContable = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen={CveAlmacen}").ToEntero
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, MovAlmacen, DtCostos.SUMD("Total").RoundSQL, Concepto, 68, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveVenta:=CveVenta, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=DtCostos.SUMD("Total").RoundSQL, Contabilizable:=EsContabilizable) Then
Correcto = False
End If
If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, -1) Then
If ObjConta.ValorPolizaDescuadre > 0 Then
GuardaLogAD($"Inventarios/RecepcionAlmacen-PPCompOC | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas")
Correcto = False
End If
End If
'CONTABILIZAR - SIMPLIFICAR
If Correcto Then
If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then
If Not ObjConta.PrePolizaSimplificacion(CvePrePoliza, UsuarioActual.CveEmpresa) Then
Correcto = False
End If
End If
'If UsuarioActual.Empresa.Funcionalidad(200) = "1" Then
' If ObjContaContPAQ Is Nothing Then
' ObjContaContPAQ = New ClsContPAQi(UsuarioActual.Empresa)
' ObjContaContPAQ.IniciaTransacSQL()
' End If
' If Not ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContaContPAQ) Then
' Retorno = False
' End If
'End If
End If
Else
Correcto = False
End If
Else
Correcto = False
End If
Catch ex As Exception
OnError("Ocurrió un error al guadar la prepoliza", ex)
Correcto = False
End Try
Return Correcto
End Function
#End Region
#Region " ADD INVENTARIO INICIAL "
@@ -2451,6 +2563,12 @@ Partial Class Inventarios_RecepcionUsados
ObjRemisionNC.IEPS = ImporteIEPS
ObjRemisionNC.Total = Total
ObjRemisionNC.TotalOtrosConceptos = 0
ObjRemisionNC.DtMovimientosUsados = DtMovimientos
ObjRemisionNC.CveAlmacen = DdlAlmacen.SelectedValue.ToEntero()
ObjRemisionNC.ObservacionesMovimiento = TxtObservaciones.Text
ObjRemisionNC.CveConceptoMovimiento = CveConcepto
End Sub
Protected Sub CargaTamaños()