public void ActualizarFechaDeCierre(int tarjetaId, int anio, int mes, DateTime fechaCierre)
        {
            var tarjeta            = TarjetaRepository.GetById(tarjetaId);
            var fechaCierreTarjeta = TarjetaFechaCierreRepository.GetFechaDeCierrePorMesYAnio(tarjeta, mes, anio);

            fechaCierreTarjeta.FechaCierre = fechaCierre;
        }
        private void CargarComboTarjetas()
        {
            if (TitularSeleccionado > -1)
            {
                var titular = (ComboBoxItem)cboTitulares.SelectedItem;

                var tarjetasTitular =
                    TarjetaRepository.PorTitular(titular.Value).OrderBy(x => x.Banco.RazonSocial).ThenBy(
                        x => x.TipoTarjeta.Descripcion)
                    .Select(x => new ComboBoxItem
                {
                    Text  = x.Banco.RazonSocial + " - " + x.TipoTarjeta.Descripcion + " -   [" + x.NumeroTarjeta + "]",
                    Value = x.Id
                });
                var list = new List <ComboBoxItem> {
                    new ComboBoxItem {
                        Text = "--- Seleccione una Tarjeta ---", Value = -1
                    }
                };
                list.AddRange(tarjetasTitular);

                cboTarjetas.DataSource    = list;
                cboTarjetas.ValueMember   = "Value";
                cboTarjetas.DisplayMember = "Text";
            }
        }
        public void GrabarCupon(int tarjetaId, DateTime fechaCupon,
                                int comercioId, int nroCupon, double importe,
                                int cantidadCuotas, string observaciones)
        {
            if (ExisteCupon(tarjetaId, fechaCupon, comercioId, nroCupon))
            {
                throw new Exception("El cupón ya existe");
            }

            var tarjeta = TarjetaRepository.GetById(tarjetaId);

            if (tarjeta == null)
            {
                throw new Exception("La Tarjeta es requerida");
            }

            var comercio = ComercioRepository.GetById(comercioId);

            if (comercio == null)
            {
                throw new Exception("El Comercio es requerido");
            }

            var fechaCierreTarjeta = TarjetaFechaCierreRepository.GetFechaDeCierrePorMesYAnio(tarjeta, fechaCupon.Month, fechaCupon.Year);

            if (fechaCierreTarjeta == null)
            {
                throw new Exception("La fecha de cierre de la Tarjeta es requerida");
            }

            var cuotas = CalcularCuotas(fechaCupon, importe, cantidadCuotas, tarjeta);

            // Creo la cabecera de la transaccion, o sea el cupon por el total del importe
            var transaccion = new Transaccion
            {
                Tarjeta            = tarjeta,
                Comercio           = comercio,
                FechaCompra        = fechaCupon,
                NumeroCupon        = nroCupon,
                Importe            = importe,
                CantidadCuotas     = cantidadCuotas,
                Observaciones      = observaciones,
                TarjetaFechaCierre = fechaCierreTarjeta
            };

            foreach (var cuota in cuotas)
            {
                var transaccionCuota = new TransaccionCuota
                {
                    Transaccion = transaccion,
                    NumeroCuota = cuota.NroCuota,
                    Fecha       = cuota.Fecha,
                    Importe     = cuota.Importe
                };
                TransaccionCuotaRepository.Add(transaccionCuota);
            }
        }
        public void ActualizarCupon(int cuponId, int tarjetaId, DateTime fechaCupon,
                                    int comercioId, int nroCupon, double importe,
                                    int cantidadCuotas, string observaciones)
        {
            var cupon = TraerCuponPorId(cuponId);

            if (cupon == null)
            {
                throw new Exception("Cupón inexistente");
            }

            var fechaAnterior          = cupon.FechaCompra;
            var importeAnterior        = cupon.Importe;
            var cantidadCuotasAnterior = cupon.CantidadCuotas;

            var comercio = ComercioRepository.GetById(comercioId);

            if (comercio == null)
            {
                throw new Exception("El Comercio es requerido");
            }
            cupon.Comercio = comercio;

            cupon.FechaCompra    = fechaCupon;
            cupon.NumeroCupon    = nroCupon;
            cupon.Importe        = importe;
            cupon.CantidadCuotas = cantidadCuotas;
            cupon.Observaciones  = observaciones;

            if (fechaAnterior != fechaCupon || importeAnterior != importe ||
                cantidadCuotasAnterior != cantidadCuotas)
            {
                // Acá tengo que actualizar las cuotas
                EliminarCuotasDeCupon(cupon);
                var tarjeta = TarjetaRepository.GetById(tarjetaId);
                if (tarjeta == null)
                {
                    throw new Exception("La Tarjeta es requerida");
                }
                var cuotas = CalcularCuotas(fechaCupon, importe, cantidadCuotas, tarjeta);

                foreach (var cuota in cuotas)
                {
                    var transaccionCuota = new TransaccionCuota
                    {
                        Transaccion = cupon,
                        NumeroCuota = cuota.NroCuota,
                        Fecha       = cuota.Fecha,
                        Importe     = cuota.Importe
                    };
                    TransaccionCuotaRepository.Add(transaccionCuota);
                }
            }
        }
        public DateTime?TraerFechaDeCierre(int tarjetaId, int anio, int mes)
        {
            var tarjeta = TarjetaRepository.GetById(tarjetaId);

            if (tarjeta == null)
            {
                return(null);
            }
            var fechaCierre = TarjetaFechaCierreRepository.GetFechaDeCierrePorMesYAnio(tarjeta, mes, anio);

            if (fechaCierre == null)
            {
                return(null);
            }
            return(fechaCierre.FechaCierre);
        }
        public void GrabarFechaDeCierre(int tarjetaId, int anio, int mes, DateTime fechaCierre)
        {
            var fecha = TraerFechaDeCierre(tarjetaId, anio, mes);

            if (fecha != null)
            {
                throw new Exception("Fecha de cierre existente");
            }
            var tarjeta = TarjetaRepository.GetById(tarjetaId);

            if (tarjeta == null)
            {
                throw new Exception("Tarjeta inexistente");
            }
            var tarjetaFechaCierre = new TarjetaFechaCierre
            {
                Tarjeta     = tarjeta,
                Anio        = anio,
                Mes         = mes,
                FechaCierre = fechaCierre
            };

            TarjetaFechaCierreRepository.Add(tarjetaFechaCierre);
        }
Example #7
0
        public static Task <List <Tarjeta> > ObtenerAsync()
        {
            ITarjetaRepository tarjetaRepository = new TarjetaRepository(new VentaContext());

            return(tarjetaRepository.Obtener());
        }