Files
Jorge Luis caudillo esparza 83acc6b4f1 Version OScar
2026-04-24 07:54:31 -07:00

736 lines
26 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ADSUtileriasWF.Helpers;
using Microsoft.VisualBasic;
namespace ADSUtileriasWF.Data.Externa.PV
{
public class ClsVentas : CLSExternoBase
{
#region Propiedades
public int CveVentaTerminal { get; set; }
public int CveMesa { get; set; }
public string Mesa { get; set; }
public string Cuenta { get; set; }
public int CveCliente { get; set; }
public string NombreCliente { get; set; }
public int NumeroPersonas { get; set; }
public int CveVendedor { get; set; }
public int Orden { get; set; }
public string Vendedor { get; set; }
public DateTime FechaApertura { get; set; }
public DateTime FechaCierre { get; set; }
public DateTime Fecha { get; set; }
public int CveEstatusFactura { get; set; }
public double SubTotal { get; set; }
public double Descuento { get; set; }
public int DescuentoPorcentaje { get; set; }
public double IVA { get; set; }
public double Total { get; set; }
public double Cambio { get; set; }
public bool Impreso { get; set; }
public int CveUsuario { get; set; }
public int CveEmpresa { get; set; }
public int CveVentaDetalleTerminal { get; set; }
#endregion
public ClsVentas() { }
public partial class ClsVentaDetalles : object, System.ComponentModel.INotifyPropertyChanged
{
#region local propierties
private int CveVentaField;
private int CvePSField;
private double CantidadField;
private int CveUnidadMedidaField;
private double PUField;
private double IVAField;
private double TotalIVAField;
private double TotalField;
private int CveEstautusFacturaField;
private string ObservacionesField;
private double OfertaField;
private double PrecioFinalField;
private double DescuentoField;
private int TipoDescuentoField;
private int CveSubProyectoField;
private string PSField;
private string CodigoField;
#endregion
#region public propierties
public int CveVenta
{
get
{
return this.CveVentaField;
}
set
{
if ((this.CveVentaField.Equals(value) != true))
{
this.CveVentaField = value;
this.RaisePropertyChanged("CveVenta");
}
}
}
public int CvePS
{
get
{
return this.CvePSField;
}
set
{
if ((this.CvePSField.Equals(value) != true))
{
this.CvePSField = value;
this.RaisePropertyChanged("CvePS");
}
}
}
public double Cantidad
{
get
{
return this.CantidadField;
}
set
{
if ((this.CantidadField.Equals(value) != true))
{
this.CantidadField = value;
this.RaisePropertyChanged("Cantidad");
}
}
}
public int CveUnidadMedida
{
get
{
return this.CveUnidadMedidaField;
}
set
{
if ((this.CveUnidadMedidaField.Equals(value) != true))
{
this.CveUnidadMedidaField = value;
this.RaisePropertyChanged("CveUnidadMedida");
}
}
}
public double PU
{
get
{
return this.PUField;
}
set
{
if ((this.PUField.Equals(value) != true))
{
this.PUField = value;
this.RaisePropertyChanged("PU");
}
}
}
public double IVA
{
get
{
return this.IVAField;
}
set
{
if ((this.IVAField.Equals(value) != true))
{
this.IVAField = value;
this.RaisePropertyChanged("IVA");
}
}
}
public double TotalIVA
{
get
{
return this.TotalIVAField;
}
set
{
if ((this.TotalIVAField.Equals(value) != true))
{
this.TotalIVAField = value;
this.RaisePropertyChanged("TotalIVA");
}
}
}
public double Total
{
get
{
return this.TotalField;
}
set
{
if ((this.TotalField.Equals(value) != true))
{
this.TotalField = value;
this.RaisePropertyChanged("Total");
}
}
}
public int CveEstautusFactura
{
get
{
return this.CveEstautusFacturaField;
}
set
{
if ((this.CveEstautusFacturaField.Equals(value) != true))
{
this.CveEstautusFacturaField = value;
this.RaisePropertyChanged("CveEstautusFactura");
}
}
}
public string Observaciones
{
get
{
return this.ObservacionesField;
}
set
{
if ((object.ReferenceEquals(this.ObservacionesField, value) != true))
{
this.ObservacionesField = value;
this.RaisePropertyChanged("Observaciones");
}
}
}
public double Oferta
{
get
{
return this.OfertaField;
}
set
{
if ((this.OfertaField.Equals(value) != true))
{
this.OfertaField = value;
this.RaisePropertyChanged("Oferta");
}
}
}
public double PrecioFinal
{
get
{
return this.PrecioFinalField;
}
set
{
if ((this.PrecioFinalField.Equals(value) != true))
{
this.PrecioFinalField = value;
this.RaisePropertyChanged("PrecioFinal");
}
}
}
public double Descuento
{
get
{
return this.DescuentoField;
}
set
{
if ((this.DescuentoField.Equals(value) != true))
{
this.DescuentoField = value;
this.RaisePropertyChanged("Descuento");
}
}
}
public int TipoDescuento
{
get
{
return this.TipoDescuentoField;
}
set
{
if ((this.TipoDescuentoField.Equals(value) != true))
{
this.TipoDescuentoField = value;
this.RaisePropertyChanged("TipoDescuento");
}
}
}
public int CveSubProyecto
{
get
{
return this.CveSubProyectoField;
}
set
{
if ((this.CveSubProyectoField.Equals(value) != true))
{
this.CveSubProyectoField = value;
this.RaisePropertyChanged("CveSubProyecto");
}
}
}
public string PS
{
get
{
return this.PSField;
}
set
{
if ((object.ReferenceEquals(this.PSField, value) != true))
{
this.PSField = value;
this.RaisePropertyChanged("PS");
}
}
}
public string Codigo
{
get
{
return this.CodigoField;
}
set
{
if ((object.ReferenceEquals(this.CodigoField, value) != true))
{
this.CodigoField = value;
this.RaisePropertyChanged("Codigo");
}
}
}
#endregion
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ( propertyChanged != null) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
public bool AddVenta(string TipoDocto, int FolioFact, int CveCliente, double SubTotal, double Descuento, double IVA, double Total, int CveMoneda, double TipoCambio, int CveMetodoPago, DateTime Fecha, string MotivoDescuento, string Observaciones, int CveEstatusFactura, int CveVendedor, int CveCorteTerminal, int CveMesa, int NumeroPersonas, string Cuenta, int CveUsuario, int CveSucursal, int CveEmpresa)
{
bool Retorno = false;
try
{
datos = proxy.AddVenta(TipoDocto, FolioFact, CveCliente, SubTotal, Descuento, IVA, Total, CveMoneda, TipoCambio, CveMetodoPago, Fecha, MotivoDescuento, Observaciones, CveEstatusFactura, CveVendedor, CveCorteTerminal, CveMesa, NumeroPersonas, Cuenta, CveUsuario, CveSucursal, CveEmpresa);
CveVentaTerminal = datos.CveRetorno;
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al Guardar la Venta.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool AddVentaDetalle(int CveVentaTerminal, int CvePS, double Cantidad, int CveUnidadMedida, double PU, double IVA, double Total, string Observaciones, double Descuento, int TipoDescuento, int ComandaOrden, double TasaIVA, bool EsVentaDetalle = true, int CveVentaDetalleTerminalPadre = -1, bool EsPromocion = false)
{
bool Retorno = false;
try
{
datos = proxy.AddVentaDetalle(CveVentaTerminal, CvePS, Cantidad, CveUnidadMedida, PU, IVA, Total, Observaciones, Descuento, TipoDescuento, ComandaOrden, TasaIVA, EsVentaDetalle, CveVentaDetalleTerminalPadre, EsPromocion);
CveVentaDetalleTerminal = datos.CveRetorno;
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al agregar el Producto o Servicio a la Venta.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool AddVta_VentasPago(int CveVentaTerminal, int CveMetodoPago, double Importe, double ImportePropina)
{
bool Retorno = false;
try
{
datos = proxy.AddVta_VentasPago(CveVentaTerminal, CveMetodoPago, Importe, ImportePropina);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al agregar el Pago de la Venta.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool RemoveVta_VentasPago(int CveVentaTerminal, int CveMetodoPago)
{
bool Retorno = false;
try
{
datos = proxy.RemoveVta_VentasPago(CveVentaTerminal, CveMetodoPago);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al Elimnar el Pago de la Venta.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool GetVta_VentasPago(int CveCorteTerminal, int CveEmpresa)
{
bool Retorno = false;
try
{
datos = proxy.GetVta_VentasPagoCorte(CveCorteTerminal, CveEmpresa);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al cargar los Pagos de Ventas.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool GetVta_VentasPago(int CveVentaTerminal)
{
bool Retorno = false;
try
{
datos = proxy.GetVta_VentasPago(CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al cargar los Pagos de Ventas.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool GetVentas(int CveVentaTerminal, int CveEstatusFactura, int CveVendedor, string Cuenta, int CveCorteTerminal, int CveUsuario, int CveEmpresa, EstatusVentaTerminal CveVenta = EstatusVentaTerminal.Todas, int Modificadas = -1)
{
bool Retorno = false;
try
{
datos = proxy.GetVentas(CveVentaTerminal, CveEstatusFactura, CveVendedor, Cuenta, CveCorteTerminal, CveUsuario, CveEmpresa, CveVenta, Modificadas);
if (datos.Tabla.Rows.Count > 0)
{
DataRow dr = datos.Tabla.Rows[0];
this.CveVentaTerminal = dr["CveVentaTerminal"].ToString().ToEntero();
this.Cuenta = !IsDBNull(dr["Cuenta"]) ? dr["Cuenta"].ToString() : "-1";
this.NombreCliente = !IsDBNull(dr["Nombre"]) ? dr["Nombre"].ToString() : "";
this.CveCliente = !IsDBNull(dr["CveCliente"]) ? dr["CveCliente"].ToString().ToEntero() : -1;
this.NumeroPersonas = dr["NumeroPersonas"].ToString().ToEntero();
this.CveVendedor = !IsDBNull(dr["CveVendedor"]) ? dr["CveVendedor"].ToString().ToEntero() : -1;
this.Vendedor = !IsDBNull(dr["Vendedor"]) ? dr["Vendedor"].ToString() : "";
this.CveMesa = !IsDBNull(dr["CveMesa"]) ? dr["CveMesa"].ToString().ToEntero() : -1;
this.Mesa = !IsDBNull(dr["Mesa"]) ? dr["Mesa"].ToString() : "";
this.FechaApertura = !IsDBNull(dr["Fecha"]) ? dr["Fecha"].ToString().ToDateTime() : DateTime.MinValue;
this.Impreso = dr["Impreso"].ToString().ToBool();
this.CveEstatusFactura = !IsDBNull(dr["CveEstatusFactura"]) ? dr["CveEstatusFactura"].ToString().ToEntero() : -1;
this.Fecha = !IsDBNull(dr["Fecha"]) ? dr["Fecha"].ToString().ToDateTime() : DateTime.MinValue;
this.SubTotal = dr["SubTotal"].ToString().ToDouble();
this.Descuento = dr["Descuento"].ToString().ToDouble();
this.DescuentoPorcentaje = dr["DescuentoPorcentaje"].ToString().ToEntero();
this.IVA = dr["IVA"].ToString().ToDouble();
this.Total = dr["Total"].ToString().ToDouble();
this.Cambio = !IsDBNull(dr["Total"]) ? dr["Total"].ToString().ToDouble() : 0;
}
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al cargar las cuentas.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool UpdateVenta(double SubTotal, double Descuento, double IVA, double Total, double Propina, int CveEstatusFactura, int CveVentaTerminal)
{
bool Retorno = false;
try
{
datos = proxy.UpdateVenta(SubTotal, Descuento, IVA, Total, Propina, CveEstatusFactura, CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al Pagar la Venta.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public int AddVentaCopia(int CveVentaTerminal, string Cuenta, int CveUsuario)
{
int Retorno = -1;
try
{
datos = proxy.AddVentaCopia(CveVentaTerminal, Cuenta, CveUsuario);
CveVentaTerminal = datos.CveRetorno;
Retorno = CveVentaTerminal;
}
catch (Exception ex)
{
OnError("Ocurrió un error al Guardar la Venta.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool DivideVenta(int CveVentaDetalleTerminal, int CveVentaTerminal)
{
bool Retorno = false;
try
{
datos = proxy.DivideVenta(CveVentaDetalleTerminal, CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al dividr la cuenta.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool JuntaVenta(int CveVentaTerminalPrincipal, int CveVentaTerminal)
{
bool Retorno = false;
try
{
datos = proxy.JuntaVenta(CveVentaTerminalPrincipal, CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al Juntar las cuentas.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool GetVentasDetalle(int CveVentaTerminal, WCF_PV.ClsVentasEstatusEntrega EstatusEntrega = WCF_PV.ClsVentasEstatusEntrega.Todas)
{
bool Retorno = false;
try
{
datos = proxy.GetVentasDetalle(CveVentaTerminal, EstatusEntrega);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al ver la Venta.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool GetVentasDetalleComandaOrden(int CveCorteTerminal)
{
bool Retorno = false;
try
{
datos = proxy.GetVentasDetallesComandaOrden(CveCorteTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al consulta la Comanda Orden.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool DeleteVentaDetalle(int CveVentaDetalleTerminal, int CveVentaTerminal)
{
bool Retorno = false;
try
{
datos = proxy.DeleteVentaDetalle(CveVentaDetalleTerminal, CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al eliminar.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool UpdateEstatusEntregaVentaDetalle(int CveVentaTerminal, int CveVentaDetalleTerminal, WCF_PV.ClsVentasEstatusEntrega EstatusEntregaFiltro, WCF_PV.ClsVentasEstatusEntrega EstatusEntrega)
{
bool Retorno = false;
try
{
datos = proxy.UpdateEstatusEntregaVentaDetalle(CveVentaTerminal, CveVentaDetalleTerminal, EstatusEntregaFiltro, EstatusEntrega);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al actualizar el Estado de Entrega.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool UpdateCantidadVentaDetalle(int CveVentaTerminal, int CveVentaDetalleTerminal, double Cantidad, bool EsVentaDetalle = true)
{
bool Retorno = false;
try
{
datos = proxy.UpdateCantidadVentaDetalle(CveVentaTerminal, CveVentaDetalleTerminal, Cantidad, EsVentaDetalle);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al actualizar la cantidad.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool UpdateCambiarMesa(int CveMesa, int CveVentaTerminal)
{
bool Retorno = false;
try
{
datos = proxy.UpdateCambiarMesa(CveMesa, CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al actualizar la cantidad.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool UpdateCliente(int CveCliente, int CveVentaTerminal)
{
bool Retorno = false;
try
{
datos = proxy.UpdateCliente(CveCliente, CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al actualizar el Cliente.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool UpdateDescuentoPorcentaje(int DescuentoPorcentaje, int CveVentaTerminal, bool AplicarloDetalles = false)
{
bool Retorno = false;
try
{
datos = proxy.UpdateDescuentoPorcentaje(DescuentoPorcentaje, CveVentaTerminal, AplicarloDetalles);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al actualizar el descuento porcentaje.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool UpdateImpreso(int CveVentaTerminal)
{
bool Retorno = false;
try
{
datos = proxy.UpdateImpreso(CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al actualizar impresion.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool UpdateImpresoComanda(int CveVentaTerminal, int ComandaOrden)
{
bool Retorno = false;
try
{
datos = proxy.UpdateImpresoComanda(CveVentaTerminal, ComandaOrden);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al actualizar impresion de la Comanda.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool UpdateVendedor(int CveVendedor, int CveVentaTerminal)
{
bool Retorno = false;
try
{
datos = proxy.UpdateVendedor(CveVendedor, CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al actualizar el vendedor.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool AddVentasDetallesCaracteristicas(int CveOpcion, int CvePS, int CveVentaDetalleTerminal)
{
bool Retorno = false;
try
{
datos = proxy.AddVentasDetallesCaracteristicas(CveOpcion, CvePS, CveVentaDetalleTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al Agregar la Caracteristica del Producto.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool RemoveVentasDetallesCaracteristicas(int CveOpcion, int CvePS, int CveVentaDetalleTerminal)
{
bool Retorno = false;
try
{
datos = proxy.RemoveVentasDetallesCaracteristicas(CveOpcion, CvePS, CveVentaDetalleTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al Eliminar la Caracteristica del Producto.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
public bool GetVentasDetallesCaracteristicas(int CveVentaDetalleTerminal, int CveVentaTerminal = -1)
{
bool Retorno = false;
try
{
datos = proxy.GetVentasDetallesCaracteristicas(CveVentaDetalleTerminal, CveVentaTerminal);
Retorno = true;
}
catch (Exception ex)
{
OnError("Ocurrió un error al ver la Venta.", "Error", ex, MessageBoxIcon.Error);
}
return Retorno;
}
}
}