diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index 6df87817e..52c6d3c82 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -541,7 +541,7 @@ Namespace Modelos End Class - Public Function EmitirFactura(Optional Timbrar As Boolean = True) As MMensajeFactura + Public Function EmitirFactura(Optional Timbrar As Boolean = True, Optional Trasac As SqlClient.SqlTransaction = Nothing, Optional ObjContPaqTransac As ClsContPAQi = Nothing) As MMensajeFactura Dim Retorno As New MMensajeFactura() If Me.Version = "3.3" AndAlso Not Me.TipoDocto.Contiene("Ped", "PeC") Then @@ -586,9 +586,16 @@ Namespace Modelos End If If Me.CveCliente > 0 Or Me.CveEmpresaCRM > 0 Then - If DtDetalle.Rows.Count > 0 Then + If DtDetalle.Rows.Count > 0 Then + + Dim ObjVentas As ClsVentas = Nothing + If Trasac IsNot Nothing Then + ObjVentas = New ClsVentas(Trasac) + Else + ObjVentas = New ClsVentas() + ObjVentas.IniciaTransacSQL() + End If - Dim ObjVentas As New ClsVentas() Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) Dim ObjInventario As New ClsInventarios(ObjVentas.IniciaTransacSQL()) Dim ObjContr As New ClsContratos(ObjVentas.IniciaTransacSQL()) @@ -604,10 +611,15 @@ Namespace Modelos Try 'CONTABILIDAD AUTOMATICA Y AC - If UsuarioActual.Empresa.UsaAC OrElse UsuarioActual.Empresa.Funcionalidad(200) = "1" Then - ObjContPaq = New ClsContPAQi(UsuarioActual.Empresa) + If ObjContPaqTransac IsNot Nothing Then + ObjContPaq = ObjContPaqTransac + Else + If UsuarioActual.Empresa.UsaAC OrElse UsuarioActual.Empresa.Funcionalidad(200) = "1" Then + ObjContPaq = New ClsContPAQi(UsuarioActual.Empresa) + End If End If + 'GUARDA VENTA Dim TieneAnticipo As Boolean = False Dim CveAnticipoPadre As Integer = 0 ' vinculación con anticipo @@ -787,9 +799,15 @@ Namespace Modelos End If End If - If Me.CveVenta > 0 AndAlso ErrorList.Count = 0 AndAlso (SeGuardoPrePoliza Or Me.TipoDocto.Contiene("Ped", "Cot", "DPe", "PeC", "PA", "Pd2")) Then - ObjVentas.Commit() - If ObjContPaq IsNot Nothing Then ObjContPaq.Commit() + If Me.CveVenta > 0 AndAlso ErrorList.Count = 0 AndAlso (SeGuardoPrePoliza Or Me.TipoDocto.Contiene("Ped", "Cot", "DPe", "PeC", "PA", "Pd2")) Then + + If Trasac Is Nothing Then + ObjVentas.Commit() + End If + If ObjContPaqTransac Is Nothing Then + If ObjContPaq IsNot Nothing Then ObjContPaq.Commit() + End If + Try If Not String.IsNullOrEmpty(DirectorioServidor) Then Dim DirectoriArchivoXML As String = System.IO.Path.Combine(DirectorioServidor, "Empresas", UsuarioActual.CveEmpresa.ToString, Me.TipoDocto) @@ -986,42 +1004,61 @@ Namespace Modelos Retorno.Mensajes = ListaMensajes End Try Else - ObjVentas.RollBack() - If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack() + If Trasac Is Nothing Then + ObjVentas.RollBack() + End If + If ObjContPaqTransac Is Nothing Then + If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack() + End If Retorno.Mensajes = ErrorList Retorno.TieneError = True End If Else - ObjVentas.RollBack() - If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack() + If Trasac Is Nothing Then + ObjVentas.RollBack() + End If + + If ObjContPaqTransac Is Nothing Then + If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack() + End If + ErrorList.Add("Ocurrió un error al procesar los datos. Por favor rectifique y vuelta a intentar.") Retorno.Mensajes = ErrorList Retorno.TieneError = True End If Catch ex As Exception Me.ErrorList.Add(ex.ToString()) - ObjVentas.RollBack() - If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack() + + If Trasac Is Nothing Then + ObjVentas.RollBack() + End If + If ObjContPaqTransac Is Nothing Then + If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack() + End If + Retorno.Mensajes = ErrorList Retorno.TieneError = True Finally - ObjVentas.Dispose() - ObjConta.Dispose() - ObjInventario.Dispose() - ObjCGame.Dispose() - ObjContr.Dispose() - ObjDocCliente.Dispose() - ObjClientes.Dispose() - ObjAcum.Dispose() - If ObjContPaq IsNot Nothing Then ObjContPaq.Dispose() + If Trasac Is Nothing Then + ObjVentas.Dispose() + ObjConta.Dispose() + ObjInventario.Dispose() + ObjCGame.Dispose() + ObjContr.Dispose() + ObjDocCliente.Dispose() + ObjClientes.Dispose() + ObjAcum.Dispose() + End If + If ObjContPaqTransac Is Nothing Then + If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack() + End If End Try Else Retorno.Mensajes.Add("No se han agregado productos/servicios") End If End If - Return Retorno End Function @@ -5086,7 +5123,8 @@ Namespace Modelos Public Property CveAlmacenRecepcionUsados As Integer = -1 Public Property CveDireccionEnvio As Integer Public Property RefacturacionGeneroNC As Boolean = False - Public Property Pagado As Decimal + Public Property Pagado As Decimal + Public Property DescuentoProntoPago As Decimal 'Public Property Sucursal As SucursalModel Public Property SubProyecto As Modelos.SubProyectoModel diff --git a/Compras/Compras.aspx.vb b/Compras/Compras.aspx.vb index 8fea41205..b52e68192 100644 --- a/Compras/Compras.aspx.vb +++ b/Compras/Compras.aspx.vb @@ -13638,19 +13638,32 @@ Partial Class Compras_Compras End Sub Private Sub VinculaDevolucion() - 'Borramos el TmpDT - TmpDT.Clear() + 'LIMPIAR PARTIDAS DE LA COMPRA PARA AGREGAR NUEVAS + TmpDT.Clear() + + Dim SubTotalCompra As Decimal = TxtSubTotal.Text.ToDecimal() + Dim TotalCompra As Decimal = TxtTotal.Text.ToDecimal() + Dim IVACompra As Decimal = TxtIVA.Text.ToDecimal() + Dim IEPSCompra As Decimal = TxtIEPS.Text.ToDecimal() + Dim RetIVACompra As Decimal = TxtRetIVA.Text.ToDecimal() + Dim RetISRCompra As Decimal = TxtRetISR.Text.ToDecimal() + + 'Dim TotalCalculable As Decimal = TotalCompra - IEPSCompra + RetIVACompra + RetISRCompra + + Dim IVAPorcentajeCompra As Decimal = Math.Round((IVACompra / SubTotalCompra), 2) 'Iteramos el GridView de la OC For Each gvr As GridViewRow In GVDevolucion.Rows - If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Then - + If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Then + + Dim CvePS As Integer = gvr.DataKey("CvePS").ToString.ToEntero + Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).Rows(0) + Dim Cantidad As Decimal = gvr.FCTextBox("TxtCantidad").Text.ToDecimal Dim CveUM As Integer = gvr.DataKey("CveUM").ToString.ToEntero Dim UM As String = gvr.DataKey("UM").ToString Dim CveClasificacion As Integer = gvr.DataKey("CveClasificacion").ToString.ToEntero Dim Clasificacion As String = gvr.DataKey("Clasificacion").ToString - Dim CvePS As Integer = gvr.DataKey("CvePS").ToString.ToEntero Dim PS As String = gvr.DataKey("PS").ToString Dim CveTipoPS As Integer = gvr.DataKey("CveTipoPS").ToString.ToEntero Dim CveSubProyectoContrato As String = "-1" @@ -13660,7 +13673,7 @@ Partial Class Compras_Compras Dim Obs As String = "" Dim PU As Decimal = gvr.DataKey("PU").ToString.ToDecimal Dim Total As Decimal = gvr.FCTextBox("TxtTotalDevolucion").Text.ToDecimal - Dim IVA As Decimal = 0 + Dim IVA As Decimal = IVAPorcentajeCompra 'Math.Round(Total * IVAPorcentajeCompra, 2) Dim Descuento As Decimal = 0 AddPS(Cantidad, CveUM, UM, CveClasificacion, Clasificacion, CvePS, PS, CveTipoPS, CveSubProyectoContrato, SubProyecto, Proyecto, CveProyecto, Obs, PU, Total, IVA, 0, 0, 0, 0, Descuento, -1, False) @@ -17531,15 +17544,17 @@ Partial Class Compras_Compras TmpDT.Rows(HdnAliasInd.Value.ToEntero)("Obs") = TxtPSAlias.Text.Trim 'busco si el producto está en otros renglones QUE NO LO TENGAN ASIGNADO, LO VINCULE - For Each drt As DataRow In TmpDT.Select($"PS ='{TxtPSAlias.Text.Trim}' and ISNULL(CvePS,0) = 0") - drt("CvePS") = CvePS - drt("PS") = tPS - drt("CveUM") = DdlUnidadAlias.SelectedValue.ToEntero - drt("UM") = DdlUnidadAlias.SelectedItem.Text - drt("CveClasificacion") = HdnPSAliasCveClasificacion.Value.ToEntero - drt("Clasificacion") = HdnPSAliasClasificacion.Value - drt("Obs") = TxtPSAlias.Text.Trim - Next + If UsuarioActual.CveEmpresa <> 141 Then + For Each drt As DataRow In TmpDT.Select($"PS ='{TxtPSAlias.Text.Trim}' and ISNULL(CvePS,0) = 0") + drt("CvePS") = CvePS + drt("PS") = tPS + drt("CveUM") = DdlUnidadAlias.SelectedValue.ToEntero + drt("UM") = DdlUnidadAlias.SelectedItem.Text + drt("CveClasificacion") = HdnPSAliasCveClasificacion.Value.ToEntero + drt("Clasificacion") = HdnPSAliasClasificacion.Value + drt("Obs") = TxtPSAlias.Text.Trim + Next + End If TmpDT.AcceptChanges() diff --git a/Empresas/141/Formatos/Cotizacion.rdlc b/Empresas/141/Formatos/Cotizacion.rdlc index b27d690f7..f3e160397 100644 --- a/Empresas/141/Formatos/Cotizacion.rdlc +++ b/Empresas/141/Formatos/Cotizacion.rdlc @@ -2621,7 +2621,7 @@ - IVA (16%): + IVA