/// <summary>
        /// Creates a customer based on input data
        /// </summary>
        private void CreateCustomer()
        {
            String   cedula, nombre, apellido, telefono, celular, correo, direccion, barrio, mac, precinto;
            int      nodo, megas, saldo, descuento;
            bool     internet, tv;
            DateTime?fechaAfiliacionTv, fechaAfiliacionInternet;
            Estado   estadoTv, estadoInternet;

            cedula    = this.CedulaText.Text != string.Empty ? this.CedulaText.Text.Trim() : null;
            nombre    = this.NombresText.Text != String.Empty ? this.NombresText.Text.Trim() : null;
            apellido  = this.ApellidosText.Text != String.Empty ? this.ApellidosText.Text.Trim() : null;
            telefono  = this.TelefonoText.Text != String.Empty ? this.TelefonoText.Text.Trim() : null;
            celular   = this.CelularText.Text != String.Empty ? this.CelularText.Text.Trim() : null;
            correo    = this.CorreoText.Text != String.Empty ? this.CorreoText.Text.Trim() : null;
            direccion = this.DireccionText.Text != String.Empty ? this.DireccionText.Text.Trim() : null;
            barrio    = this.BarrioBox.Text != String.Empty ? this.BarrioBox.Text : null;
            mac       = this.MACText.Text != String.Empty ? this.MACText.Text.Trim() : null;
            precinto  = this.PrecintoText.Text != String.Empty ? this.PrecintoText.Text.Trim() : null;
            nodo      = Int32.TryParse(this.NodoBox.Text.Trim(), out nodo) ? nodo : -1;
            megas     = Int32.TryParse(this.MegasBox.Text.Trim(), out megas) ? megas : -1;
            descuento = Int32.TryParse(this.DescuentoText.Text.Trim(), out descuento) ? descuento : 0;
            internet  = this.InternetRadioButton.IsChecked ?? false;
            tv        = this.TelevisionRadioButton.IsChecked ?? false;

            fechaAfiliacionTv       = null;
            fechaAfiliacionInternet = null;

            estadoTv       = Estado.Pendiente;
            estadoInternet = Estado.Pendiente;

            saldo = 0;

            if (cedula == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.CedulaIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (nombre == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.NombreIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (apellido == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.ApellidoIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (direccion == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.DireccionIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (barrio == null)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.BarrioIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (nodo == -1)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.NodoIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (megas == -1)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.MegasIsAMandatoryField, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }


            if (!(internet || tv))
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.AtLeastOneServiceMustBeProvided, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (megas != 0 && !internet)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show(Messages.InputRequirements.MegasOnlyApplyForInternetService, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }


            Customer      customer      = new Customer(cedula, nombre, apellido, telefono, celular, correo, direccion, barrio, mac, precinto, nodo, megas, saldo, descuento, tv, internet, fechaAfiliacionTv, fechaAfiliacionInternet, estadoTv, estadoInternet);
            StringBuilder numeroFactura = new StringBuilder(cedula).Append("-").Append(TypeOfRecibos.AFILIACION).Append("-").Append(DateManager.GetDateInSpanish());
            List <Cargo>  cargos        = new List <Cargo>();
            Cargo         cargo         = new Cargo(UserPreferences.GetAfiliacionValue(), UserPreferences.GetAfiliacionValue(), Concepto.Afiliacion);

            cargos.Add(cargo);
            Factura factura = new Factura(numeroFactura.ToString(), DateManager.GetToday(), null, null, cargos, customer.Cedula);

            RecibosManager                    RecibosManager = new RecibosManager();
            Tuple <Factura, Customer>         pair           = new Tuple <Factura, Customer>(factura, customer);
            List <Tuple <Factura, Customer> > info           = new List <Tuple <Factura, Customer> >();

            info.Add(pair);
            try
            {
                RecibosManager.Valor = cargo.Valor;
                LoadingWindow loadingWindow = new LoadingWindow();
                loadingWindow.Show();
                loadingWindow.StartWorking((object sender, DoWorkEventArgs e) => {
                    RecibosManager.GenerateFiles(info, TypeOfRecibos.AFILIACION, sender, loadingWindow.Status);

                    try
                    {
                        if (BDManager.CreateCustomerWithInitialFinancialInformation(customer, factura, cargo))
                        {
                            this.Dispatcher.Invoke(delegate
                            {
                                loadingWindow.Hide();
                                SystemSounds.Beep.Play();
                                MessageBox.Show(Messages.SuccesfulOperation.customerWasSuccesfullyCreated, Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                                Clean();
                            });
                        }
                    }
                    catch (MySqlException ex)
                    {
                        if (ex.Number == (int)MySqlErrorCode.DuplicateKeyEntry)
                        {
                            this.Dispatcher.Invoke(delegate
                            {
                                loadingWindow.Hide();
                                SystemSounds.Beep.Play();
                                MessageBox.Show(Messages.Errors.CustomerAlreadyExists, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                            });
                        }
                        else if (ex.Number == (int)MySqlErrorCode.DataTooLong)
                        {
                            this.Dispatcher.Invoke(delegate
                            {
                                loadingWindow.Hide();
                                SystemSounds.Beep.Play();
                                MessageBox.Show("Uno de los campos no es valido. La informacion es demasiado larga!", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                            });
                        }
                        else
                        {
                            this.Dispatcher.Invoke(delegate
                            {
                                loadingWindow.Hide();
                                SystemSounds.Beep.Play();
                                MessageBox.Show(Messages.Errors.setErrorCodeMessage(ex.Number.ToString()), Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                            });
                        }
                    }
                }
                                           );
            }
            catch (Exception)
            {
                this.Dispatcher.Invoke(delegate
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show(Messages.Errors.CouldntReadFile, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                });
            }
        }
        /// <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));
        }
 /// <summary>
 /// Determines if a charge should be reduced based on registration date
 /// </summary>
 /// <param name="fechaAfiliacion">Registration date</param>
 /// <returns>True if price should be reduced</returns>
 private bool IncompleteCharge(DateTime?fechaAfiliacion)
 {
     if (!fechaAfiliacion.HasValue)
     {
         throw (new Exception("Error, variable nula"));
     }
     return(fechaAfiliacion.Value.Month == DateManager.GetMonthNumber() && fechaAfiliacion.Value.Year == DateManager.GetToday().Year);
 }
예제 #4
0
        /// <summary>
        /// Adds other charges to a customer
        /// </summary>
        private void AddOtros()
        {
            Customer     customer = this.ListViewCustomers.SelectedItem as Customer;
            List <Cargo> cargos   = new List <Cargo>();

            SystemSounds.Beep.Play();
            var r = MessageBox.Show("¿Esta seguro de que desea generar un cargo por otros para el cliente con cedula " + customer.Cedula + " ?", "Informacion", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if ((r == MessageBoxResult.Yes))
            {
                string numeroFactura = new StringBuilder(customer.Cedula).Append("-").Append(TypeOfRecibos.OTROS).Append("-").Append(DateManager.GetDateInSpanish()).ToString();

                string ans = Microsoft.VisualBasic.Interaction.InputBox("Digite el valor del cargo", "Cargo");

                if (Int32.TryParse(ans, out int pago))
                {
                    Cargo cargo = new Cargo(pago, pago, Concepto.Otros);
                    cargos.Add(cargo);
                    Factura factura = new Factura(numeroFactura, DateManager.GetToday(), null, null, cargos, customer.Cedula);

                    RecibosManager                    recibosManager = new RecibosManager();
                    Tuple <Factura, Customer>         pair           = new Tuple <Factura, Customer>(factura, customer);
                    List <Tuple <Factura, Customer> > info           = new List <Tuple <Factura, Customer> >();
                    info.Add(pair);


                    try
                    {
                        recibosManager.Valor = cargo.Valor;
                        LoadingWindow loadingWindow = new LoadingWindow();
                        loadingWindow.Show();
                        loadingWindow.StartWorking((object sender, DoWorkEventArgs e) =>
                        {
                            recibosManager.GenerateFiles(info, TypeOfRecibos.OTROS, sender, loadingWindow.Status);

                            try
                            {
                                if (BDManager.AddChargeSimple(factura))
                                {
                                    this.Dispatcher.Invoke(delegate
                                    {
                                        loadingWindow.Hide();
                                        SystemSounds.Beep.Play();
                                        MessageBox.Show("Cargo generado exitosamente!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                                    });
                                }
                            }
                            catch (MySqlException ex)
                            {
                                this.Dispatcher.Invoke(delegate {
                                    loadingWindow.Hide();
                                    SystemSounds.Beep.Play();
                                    MessageBox.Show(Messages.Errors.setErrorCodeMessage(ex.Number.ToString()), Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                                });
                            }
                            catch (Exception ex)
                            {
                                this.Dispatcher.Invoke(delegate {
                                    loadingWindow.Hide();
                                    SystemSounds.Beep.Play();
                                    MessageBox.Show(ex.Message, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                                });
                            }
                        }
                                                   );
                    }
                    catch (Exception)
                    {
                        this.Dispatcher.Invoke(delegate
                        {
                            SystemSounds.Beep.Play();
                            MessageBox.Show(Messages.Errors.CouldntReadFile, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                        });
                    }
                }
                else
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Valor no valido!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Adds a traslado to a customer
        /// </summary>
        private void AddTraslado()
        {
            Customer     customer = this.ListViewCustomers.SelectedItem as Customer;
            List <Cargo> cargos   = new List <Cargo>();

            SystemSounds.Beep.Play();
            var r = MessageBox.Show("¿Esta seguro de que desea generar un traslado para el cliente con cedula " + customer.Cedula + " ?", "Informacion", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if ((r == MessageBoxResult.Yes))
            {
                string numeroFactura  = new StringBuilder(customer.Cedula).Append("-").Append(TypeOfRecibos.TRASLADO).Append("-").Append(DateManager.GetDateInSpanish()).ToString();
                int    traslado_value = UserPreferences.GetTrasladoValue();
                Cargo  cargo          = new Cargo(traslado_value, traslado_value, Concepto.Traslado);
                cargos.Add(cargo);
                Factura factura = new Factura(numeroFactura, DateManager.GetToday(), null, null, cargos, customer.Cedula);

                RecibosManager                    recibosManager = new RecibosManager();
                Tuple <Factura, Customer>         pair           = new Tuple <Factura, Customer>(factura, customer);
                List <Tuple <Factura, Customer> > info           = new List <Tuple <Factura, Customer> >();
                info.Add(pair);


                try
                {
                    recibosManager.Valor = cargo.Valor;
                    LoadingWindow loadingWindow = new LoadingWindow();
                    loadingWindow.Show();
                    loadingWindow.StartWorking((object sender, DoWorkEventArgs e) =>
                    {
                        recibosManager.GenerateFiles(info, TypeOfRecibos.TRASLADO, sender, loadingWindow.Status);

                        try
                        {
                            if (BDManager.AddChargeSimple(factura))
                            {
                                this.Dispatcher.Invoke(delegate
                                {
                                    loadingWindow.Hide();
                                    SystemSounds.Beep.Play();
                                    MessageBox.Show("Traslado generado exitosamente!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                                });
                            }
                        }
                        catch (MySqlException ex)
                        {
                            this.Dispatcher.Invoke(delegate {
                                loadingWindow.Hide();
                                SystemSounds.Beep.Play();
                                MessageBox.Show(Messages.Errors.setErrorCodeMessage(ex.Number.ToString()), Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                            });
                        }
                        catch (Exception ex)
                        {
                            this.Dispatcher.Invoke(delegate {
                                loadingWindow.Hide();
                                SystemSounds.Beep.Play();
                                MessageBox.Show(ex.Message, Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                            });
                        }
                    }
                                               );
                }
                catch (Exception)
                {
                    this.Dispatcher.Invoke(delegate
                    {
                        SystemSounds.Beep.Play();
                        MessageBox.Show(Messages.Errors.CouldntReadFile, Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Warning);
                    });
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Updates the state of a service
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="estado"></param>
        /// <param name="service"></param>
        /// <param name="updateDate"></param>
        private void UpdateServiceStatus(Customer customer, Estado estado, string service, bool updateDate)
        {
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                SystemSounds.Beep.Play();
                try
                {
                    if (updateDate)
                    {
                        if (BDManager.UpdateCustomerEstado(customer.Cedula, service, estado, true, DateManager.GetToday()))
                        {
                            MessageBox.Show("Cliente actualizado!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else
                        {
                            MessageBox.Show("Error al actualizar el cliente!", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                    }
                    else
                    {
                        if (BDManager.UpdateCustomerEstado(customer.Cedula, service, estado, false))
                        {
                            MessageBox.Show("Cliente actualizado!", Messages.Titles.Success, MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        else
                        {
                            MessageBox.Show("Error al actualizar el cliente!", Messages.Titles.Warninig, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                    }
                } catch (Exception)
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Error!", Messages.Titles.Alert, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                foreach (Customer _customer in Customers)
                {
                    if (_customer.Cedula == customer.Cedula)
                    {
                        if (service == "estadoTV")
                        {
                            if (updateDate)
                            {
                                _customer.FechaAfiliacionTV = DateManager.GetToday();
                            }
                            _customer.EstadoTV = estado;
                        }
                        else
                        {
                            if (updateDate)
                            {
                                _customer.FechaAfiliacionInternet = DateManager.GetToday();
                            }
                            _customer.EstadoInternet = estado;
                        }
                        break;
                    }
                }

                this.ListViewCustomers.Dispatcher.Invoke(delegate
                {
                    ICollectionView view = CollectionViewSource.GetDefaultView(this.ListViewCustomers.ItemsSource);
                    view.Refresh();
                });
            }).Start();
        }