diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index 871ba36d3..5d1cd4b98 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -3946,7 +3946,7 @@ Partial Class Ventas If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then Dim ObjUsados As New ClsVentas - If ObjUsados.GetVentasUsados(CveVenta, DdlSubProyectoDatos.SelectedValue.ToEntero(), DbRowVenta("Fecha").ToString().ToDateTime, UsuarioActual.CveEmpresa) Then + If ObjUsados.GetVentasUsados(CveVenta, -1, DbRowVenta("Fecha").ToString().ToDateTime, UsuarioActual.CveEmpresa) Then DtUsados = ObjUsados.DtResultados End If ObjUsados.Dispose() @@ -11299,6 +11299,9 @@ Partial Class Ventas Dim CveCuentaIVAxTrasladar As Integer = 0 Dim CveCuentaIVATrasladado As Integer = 0 Dim SeContabiliza As Boolean = True + + Dim SimplificarPrePoliza As Boolean = False + If (UsuarioActual.Empresa.Funcionalidad(343) = "1" AndAlso ObjFactura.TipoDocto = "Ant") Or (ChkAntEspecial.Checked AndAlso ObjFactura.TipoDocto = "Ant") Then SeContabiliza = False End If @@ -12614,7 +12617,7 @@ Partial Class Ventas If CveIEPago > 0 Then importeMovimiento = DrPago("Importe").ToString().ToDecimal * ValorMultiplicador - importeMX = importeMovimiento * tipoCambio * Multiplicador + importeMX = (importeMovimiento * tipoCambio * Multiplicador).RoundSQL IdCtaContable = 0 CveCuenta = 0 CveSubProyectoContabilizar = CveSubProyectoVenta @@ -12633,20 +12636,61 @@ Partial Class Ventas ' CuentasContablesInvalidasSIG.AppendFormat("
{0}", GlobalDTBancosCuentas(UsuarioActual.CveUsuario, DrPago("CveCuenta").ToString().ToEntero()).Rows(0)("NumCuentaMoneda").ToString().ToEntero()) ' CveCuentaContabilizacion = 0 'End If + 'MONEDA EXTRANJERA + If ObjFactura.CveMoneda > 1 Then + 'BANCOS + Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, 30, NombreCliente, $"{ObjFactura.Serie}-{ObjFactura.Folio}", FolioIE.ToString()) + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=CveCliente, CveIE:=CveIEPago, ImporteMX:=importeMovimiento, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, CveSubProyecto:=CveSubProyectoContabilizar) Then + ErrorPrepoliza = True + Exit For + End If + + 'BANCOS COMPLEMENTARIA + If UsaComplementariaClientes Then + Dim ImporteComplementaria As Decimal = ((importeMovimiento * tipoCambio) - importeMovimiento).RoundSQL + + Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, 204, NombreCliente, $"{ObjFactura.Serie}-{ObjFactura.Folio}", FolioIE.ToString()) + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 204, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveIE:=CveIEPago, ImporteMX:=ImporteComplementaria, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), TipoCambio:=tipoCambio, TipoCambioPago:=tipoCambio, CveCuenta:=CveCuenta, CveSubProyecto:=CveSubProyectoContabilizar, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + End If + + 'PAGO CLIENTES + Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, 2, NombreCliente, $"{ObjFactura.Serie}-{ObjFactura.Folio}", FolioIE.ToString()) + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 2, Concepto, Fecha, IdCtaContableCliente, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=CveCliente, CveIE:=CveIEPago, ImporteMX:=importeMovimiento, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), CveCuenta:=CveCuentaCliente, CveSubProyecto:=CveSubProyectoContabilizar) Then + ErrorPrepoliza = True + Exit For + End If + + 'PAGO CLIENTES COMPLEMENTARIA + If UsaComplementariaClientes Then + Dim ImporteComplementaria As Decimal = ((importeMovimiento * tipoCambio) - importeMovimiento).RoundSQL + + Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, 207, NombreCliente, $"{ObjFactura.Serie}-{ObjFactura.Folio}", FolioIE.ToString()) + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, Not TipoMovimiento, 0, Referencia, 207, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveIE:=CveIEPago, ImporteMX:=ImporteComplementaria, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), TipoCambio:=tipoCambio, TipoCambioPago:=tipoCambio, CveCuenta:=CveCuenta, CveSubProyecto:=CveSubProyectoContabilizar, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + End If + End If + + SimplificarPrePoliza = True + + Else + 'BANCOS + Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, 30, NombreCliente, $"{ObjFactura.Serie}-{ObjFactura.Folio}", FolioIE.ToString()) + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=CveCliente, CveIE:=CveIEPago, ImporteMX:=importeMX, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, CveSubProyecto:=CveSubProyectoContabilizar) Then + ErrorPrepoliza = True + Exit For + End If + + 'PAGO CLIENTES + Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, 2, NombreCliente, $"{ObjFactura.Serie}-{ObjFactura.Folio}", FolioIE.ToString()) + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 2, Concepto, Fecha, IdCtaContableCliente, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=CveCliente, CveIE:=CveIEPago, ImporteMX:=importeMX, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), CveCuenta:=CveCuentaCliente, CveSubProyecto:=CveSubProyectoContabilizar) Then + ErrorPrepoliza = True + Exit For + End If - 'BANCOS - Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, 30, NombreCliente, $"{ObjFactura.Serie}-{ObjFactura.Folio}", FolioIE.ToString()) - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, Fecha, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=CveCliente, CveIE:=CveIEPago, ImporteMX:=importeMX, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), CveCuenta:=CveCuenta) Then - ErrorPrepoliza = True - Exit For End If - 'CLIENTES - Concepto = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, 2, NombreCliente, $"{ObjFactura.Serie}-{ObjFactura.Folio}", FolioIE.ToString()) - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, Not TipoMovimiento, importeMovimiento, Referencia, 2, Concepto, Fecha, IdCtaContableCliente, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=CveCliente, CveIE:=CveIEPago, ImporteMX:=importeMX, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), CveCuenta:=CveCuentaCliente, CveSubProyecto:=CveSubProyectoContabilizar) Then - ErrorPrepoliza = True - Exit For - End If If ObjFactura.IVA <> 0 Then @@ -12795,7 +12839,7 @@ Partial Class Ventas End If 'Simplificacion de PrePolizas - If ObjFactura.TipoDocto.Contiene("Egs", "Dev") Then + If ObjFactura.TipoDocto.Contiene("Egs", "Dev") OrElse SimplificarPrePoliza Then If Not ObjConta.PrePolizaSimplificacion(ObjFactura.CvePrePoliza, UsuarioActual.CveEmpresa) Then Alert("No se pudo simplificar los movimientos", TipoMensaje.MsgError) End If @@ -27328,11 +27372,29 @@ Partial Class Ventas RemisionesLista.Clear() + Dim MsgUsados As New StringBuilder + Dim UsadosValidados As Boolean = True + If dtSeleccionadas.Rows.Count > 0 Then Select Case RblTipo.SelectedValue Case "1" 'T O T A L G E N E R A L For Each row As DataRow In dtSeleccionadas.Rows - RemisionesLista.Add(row("CveVenta").ToString().ToEntero()) + + If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then + Using ObjUsados As New ClsVentas + If ObjUsados.GetVentasUsados(row("CveVenta").ToString().ToEntero(), -1, row("Fecha").ToString().ToDateTime, UsuarioActual.CveEmpresa) Then + If ObjUsados.DtResultados.Rows.Count > 0 Then + UsadosValidados = False + MsgUsados.AppendFormat("{0},", row("Folio").ToString()) + End If + End If + End Using + End If + + If UsadosValidados Then + RemisionesLista.Add(row("CveVenta").ToString().ToEntero()) + End If + Next IsTotalxConcepto = False Dim PU As Decimal = dtSeleccionadas.SUM("SubTotal").ToDecimal @@ -27347,7 +27409,22 @@ Partial Class Ventas CalculaTotalesVenta() Case "2" 'T O T A L X R E M I S I O N For Each row As DataRow In dtSeleccionadas.Rows - RemisionesLista.Add(row("CveVenta").ToString().ToEntero()) + + If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then + Using ObjUsados As New ClsVentas + If ObjUsados.GetVentasUsados(row("CveVenta").ToString().ToEntero(), -1, row("Fecha").ToString().ToDateTime, UsuarioActual.CveEmpresa) Then + If ObjUsados.DtResultados.Rows.Count > 0 Then + UsadosValidados = False + MsgUsados.AppendFormat("{0},", row("Folio").ToString()) + End If + End If + End Using + End If + + If UsadosValidados Then + RemisionesLista.Add(row("CveVenta").ToString().ToEntero()) + End If + Next Dim PS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa)(0) Dim rowSP As DataRow = GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa)(0) @@ -27368,17 +27445,51 @@ Partial Class Ventas For Each row As DataRow In dtSeleccionadas.Rows sb.Append($"{row("CveVentaDetalle").ToString()},") Next - For Each row As DataRow In dtSeleccionadas.FiltraParametros("", DistinctColumns:={"CveVenta"}).Rows - RemisionesLista.Add(row("CveVenta").ToString().ToEntero()) + For Each row As DataRow In dtSeleccionadas.FiltraParametros("", DistinctColumns:={"CveVenta", "Fecha", "Folio"}).Rows + + If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then + Using ObjUsados As New ClsVentas + If ObjUsados.GetVentasUsados(row("CveVenta").ToString().ToEntero(), -1, row("Fecha").ToString().ToDateTime, UsuarioActual.CveEmpresa) Then + If ObjUsados.DtResultados.Rows.Count > 0 Then + UsadosValidados = False + MsgUsados.AppendFormat("{0},", row("Folio").ToString()) + End If + End If + End Using + End If + + If UsadosValidados Then + RemisionesLista.Add(row("CveVenta").ToString().ToEntero()) + End If Next Else For Each row As DataRow In dtSeleccionadas.Rows sb.Append($"{row("CveVenta").ToString()},") - RemisionesLista.Add(row("CveVenta").ToString().ToEntero()) + + If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then + Using ObjUsados As New ClsVentas + If ObjUsados.GetVentasUsados(row("CveVenta").ToString().ToEntero(), -1, row("Fecha").ToString().ToDateTime, UsuarioActual.CveEmpresa) Then + If ObjUsados.DtResultados.Rows.Count > 0 Then + UsadosValidados = False + MsgUsados.AppendFormat("{0},", row("Folio").ToString()) + End If + End If + End Using + End If + + If UsadosValidados Then + RemisionesLista.Add(row("CveVenta").ToString().ToEntero()) + End If Next End If + + sb.Remove(sb.Length - 1, 1) - CargaConceptosRemisionPorFacturar(sb.ToString(), If(ChkRemProductos.Checked, 2, 1)) + + If UsadosValidados Then + CargaConceptosRemisionPorFacturar(sb.ToString(), If(ChkRemProductos.Checked, 2, 1)) + End If + sb.Clear() End Select @@ -27430,6 +27541,15 @@ Partial Class Ventas ObsPedido.Clear() ObsInv.Clear() End If + + If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso Not UsadosValidados Then + If MsgUsados.Length > 0 Then + MsgUsados.Remove(MsgUsados.Length - 1, 1) + End If + Alert($"Las siguientes remisiones no se pueden facturar porque no se ha recibido el usado correspondiente:
{MsgUsados.ToString()}", TipoMensaje.MsgAdvertencia) + BtnEmitirImprimir.Visible = False + End If + End If TxtFechaPago.Text = If(EsDiasCreditoFijo, Now.AddDays(DiasCredito).ToShortDateString, TxtFechaPago.Text) @@ -28570,7 +28690,10 @@ Partial Class Ventas Else Row("PorcentajeIVA") = DrPS("IVA") End If - Dim TotalCalculableImpuestos As Decimal = (Row("Cantidad").ToString().ToDecimal * Row("PU").ToString().ToDecimal) - Row("Descuento").ToString().ToDecimal + + Dim PU = Row("PU").ToString().ToDecimal().RoundSQL(6) ' el precio unitario puede llevar hasta 6 decimales permitidos + + Dim TotalCalculableImpuestos As Decimal = (Row("Cantidad").ToString().ToDecimal * PU) - Row("Descuento").ToString().ToDecimal Dim TotalCalculableImpuestosIVA As Decimal = TotalCalculableImpuestos * (1 + Row("PorcentajeIEPS").ToString().ToDecimal) Row("IVA") = Row("PorcentajeIVA").ToString().ToDouble