コード例 #1
0
        /// <summary>
        /// Loads user preferences and displays them
        /// </summary>
        private void LoadPreferences()
        {
            DescuentoValue        = UserPreferences.GetDescuento();
            DescuentoInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", DescuentoValue);

            NumeroReciboValue        = UserPreferences.GetNumeroRecibo();
            NumeroReciboInitialValue = NumeroReciboValue;

            UbicacionValue        = UserPreferences.GetPreferredLocation();
            UbicacionInitialValue = UbicacionValue;

            RecibosValue        = UserPreferences.GetRecibosLocation();
            RecibosInitialValue = RecibosValue;

            FacturasValue        = UserPreferences.GetFacturasLocation();
            FacturasInitialValue = FacturasValue;

            ReconexionValue        = UserPreferences.GetReconexionValue();
            ReconexionInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ReconexionValue);

            AfiliacionValue        = UserPreferences.GetAfiliacionValue();
            AfiliacionInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", AfiliacionValue);

            DerivacionValue        = UserPreferences.GetDerivacionValue();
            DerivacionInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", DerivacionValue);

            TrasladoValue        = UserPreferences.GetTrasladoValue();
            TrasladoInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", TrasladoValue);

            TVvalue        = UserPreferences.GetTVValue();
            TVInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", TVvalue);

            Megas3Value        = UserPreferences.Get3MegasValue();
            Megas3InitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", Megas3Value);

            Megas5Value        = UserPreferences.Get5MegasValue();
            Megas5InitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", Megas5Value);

            Megas7Value        = UserPreferences.Get7MegasValue();
            Megas7InitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", Megas7Value);

            Megas10Value        = UserPreferences.Get10MegasValue();
            Megas10InitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", Megas10Value);

            (ComboTV3Value, ComboInternet3Value) = UserPreferences.GetCombo3();
            Combo3TVInitialValue       = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboTV3Value);
            Combo3InternetInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboInternet3Value);

            (ComboTV5Value, ComboInternet5Value) = UserPreferences.GetCombo5();
            Combo5TVInitialValue       = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboTV5Value);
            Combo5InternetInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboInternet5Value);

            (ComboTV7Value, ComboInternet7Value) = UserPreferences.GetCombo7();
            Combo7TVInitialValue       = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboTV7Value);
            Combo7InternetInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboInternet7Value);

            (ComboTV10Value, ComboInternet10Value) = UserPreferences.GetCombo10();
            Combo10TVInitialValue       = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboTV10Value);
            Combo10InternetInitialValue = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C}", ComboInternet10Value);
        }
        /// <summary>
        /// Creates a single invoice
        /// </summary>
        /// <param name="customer">Customer associated with the invoice</param>
        /// <returns>A invoice object</returns>
        private Factura CreateInvoice(Customer customer)
        {
            StringBuilder numeroFactura = new StringBuilder(customer.Cedula).Append("-").Append(TypeOfRecibos.MENSUALIDAD).Append("-").Append(DateManager.GetMonthInSpanish()).Append("-").Append(DateManager.GetToday().Year);
            DateTime      fecha         = DateManager.GetToday();
            Mes           mesCargado    = DateManager.GetMonth();
            DateTime      fechaLimite;
            List <Cargo>  cargos = new List <Cargo>();

            if (customer.HasTV && customer.HasInternet)
            {
                fechaLimite = DateManager.GetDateLimit(false);
                if (customer.EstadoTV == Estado.Pendiente || customer.EstadoInternet == Estado.Pendiente)
                {
                    return(null);
                }
                else
                {
                    //No pending
                    int internet = 0, tv = 0;
                    switch (customer.Megas)
                    {
                    case 3:
                        (tv, internet) = UserPreferences.GetCombo3();
                        break;

                    case 5:
                        (tv, internet) = UserPreferences.GetCombo5();
                        break;

                    case 7:
                        (tv, internet) = UserPreferences.GetCombo7();
                        break;

                    case 10:
                        (tv, internet) = UserPreferences.GetCombo10();
                        break;
                    }

                    internet -= customer.Descuento;

                    if (IncompleteCharge(customer.FechaAfiliacionInternet))
                    {
                        Calculadora.CalcularPrecioRealBasadoEnDias(ref internet, 30 - DateManager.GetToday().Day);
                    }

                    if (IncompleteCharge(customer.FechaAfiliacionTV))
                    {
                        if (DateManager.GetToday().Day < 16)
                        {
                            Calculadora.CalcularPrecioRealBasadoEnDias(ref tv, 30 - DateManager.GetToday().Day);
                        }
                        else
                        {
                            tv = 0;
                        }
                    }

                    Cargo cargoTV       = new Cargo(tv, 0, Concepto.TV);
                    Cargo cargoInternet = new Cargo(internet, 0, Concepto.Internet);

                    cargos.Add(cargoTV);
                    cargos.Add(cargoInternet);

                    AddPreviousCharges(customer.Cedula, cargos);
                    return(new Factura(numeroFactura.ToString(), fecha, fechaLimite, mesCargado, cargos, customer.Cedula));
                }
            }
            else if (customer.HasInternet)
            {
                if (customer.EstadoInternet == Estado.Pendiente)
                {
                    return(null);
                }


                fechaLimite = DateManager.GetDateLimit(false);
                int internet = 0;

                switch (customer.Megas)
                {
                case 3:
                    internet = UserPreferences.Get3MegasValue();
                    break;

                case 5:
                    internet = UserPreferences.Get5MegasValue();
                    break;

                case 7:
                    internet = UserPreferences.Get7MegasValue();
                    break;

                case 10:
                    internet = UserPreferences.Get10MegasValue();
                    break;
                }
                internet -= customer.Descuento;

                if (IncompleteCharge(customer.FechaAfiliacionInternet))
                {
                    Calculadora.CalcularPrecioRealBasadoEnDias(ref internet, 30 - DateManager.GetToday().Day);
                }

                Cargo cargoInternet = new Cargo(internet, 0, Concepto.Internet);

                cargos.Add(cargoInternet);

                AddPreviousCharges(customer.Cedula, cargos);
                return(new Factura(numeroFactura.ToString(), fecha, fechaLimite, mesCargado, cargos, customer.Cedula));
            }
            else if (customer.HasTV)
            {
                if (customer.EstadoTV == Estado.Pendiente)
                {
                    return(null);
                }

                fechaLimite = DateManager.GetDateLimit(true);

                int tv = UserPreferences.GetTVValue();

                if (IncompleteCharge(customer.FechaAfiliacionTV))
                {
                    if (DateManager.GetToday().Day < 16)
                    {
                        Calculadora.CalcularPrecioRealBasadoEnDias(ref tv, 30 - DateManager.GetToday().Day);
                    }
                    else
                    {
                        tv = 0;
                    }
                }

                Cargo cargoTV = new Cargo(tv, 0, Concepto.TV);

                cargos.Add(cargoTV);

                AddPreviousCharges(customer.Cedula, cargos);
                return(new Factura(numeroFactura.ToString(), fecha, fechaLimite, mesCargado, cargos, customer.Cedula));
            }
            else
            {
                if (customer.Saldo == 0)
                {
                    return(null);
                }
                //If program hits this part, it means customer has no services but it owes money
                fechaLimite = DateManager.GetDateLimit(true);
            }
            //Get previous charges
            AddPreviousCharges(customer.Cedula, cargos);
            return(new Factura(numeroFactura.ToString(), fecha, fechaLimite, mesCargado, cargos, customer.Cedula));
        }