Ejemplo n.º 1
0
        private void BSaveClick(object sender, EventArgs e)
        {
            nudAmount_ValueChanged(sender, e);
            bool pending = cbxPending.Visible && cbxPending.Checked;

            try
            {
                _date = new DateTime(dtpDate.Value.Year, dtpDate.Value.Month, dtpDate.Value.Day, TimeProvider.Now.Hour,
                                     TimeProvider.Now.Minute, TimeProvider.Now.Second);

                SavingServices savingServices = ServicesProvider.GetInstance().GetSavingServices();

                if (_date.Date < TimeProvider.Today.Date)
                {
                    savingServices.PerformBackDateOperations(_date);
                }
                else if (_date.Date > TimeProvider.Today.Date)
                {
                    savingServices.PerformFutureDateOperations(_date);
                }

                if (_saving.HasPendingEvents())
                {
                    if (!savingServices.AllowOperationsDuringPendingDeposit())
                    {
                        return;
                    }
                }

                if ((_flatFees.HasValue && updAmountFees.Value != _flatFees) || (_rateFees.HasValue && updAmountFees.Value != (decimal)(_rateFees * 100)))
                {
                    if (!savingServices.AllowSettingSavingsOperationsFeesManually())
                    {
                        return;
                    }
                }

                switch (_bookingDirection)
                {
                case OSavingsOperation.Credit:
                {
                    var paymentMethod = (PaymentMethod)cbSavingsMethod.SelectedItem;

                    OSavingsMethods savingsMethod = (OSavingsMethods)Enum.Parse(typeof(OSavingsMethods), paymentMethod.Name);
                    if (_saving is SavingBookContract)
                    {
                        if (savingsMethod == OSavingsMethods.Cheque)
                        {
                            ((SavingBookContract)_saving).ChequeDepositFees = updAmountFees.Value;
                        }
                        else
                        {
                            ((SavingBookContract)_saving).DepositFees = updAmountFees.Value;
                        }
                    }

                    savingServices.Deposit(_saving, _date, _amount, _description, User.CurrentUser, pending,
                                           savingsMethod, paymentMethod, null, Teller.CurrentTeller, _chequeNumberTextBox.Text);
                    _saving.Status = OSavingsStatus.Active;
                    savingServices.UpdateStatus(_saving);
                    break;
                }

                case OSavingsOperation.Debit:
                {
                    var paymentMethod = (PaymentMethod)cbSavingsMethod.SelectedItem;
                    if (_saving is SavingBookContract)
                    {
                        if (_flatFees.HasValue)
                        {
                            ((SavingBookContract)_saving).FlatWithdrawFees = updAmountFees.Value;
                        }
                        else
                        {
                            ((SavingBookContract)_saving).RateWithdrawFees = (double)(updAmountFees.Value / 100);
                        }
                    }

                    savingServices.Withdraw(_saving, _date, _amount, _description, User.CurrentUser,
                                            Teller.CurrentTeller, paymentMethod, _chequeNumberTextBox.Text);
                    break;
                }

                case OSavingsOperation.Transfer:
                {
                    if (_saving is SavingBookContract)
                    {
                        if (_flatFees.HasValue)
                        {
                            ((SavingBookContract)_saving).FlatTransferFees = updAmountFees.Value;
                        }
                        else
                        {
                            ((SavingBookContract)_saving).RateTransferFees = (double)(updAmountFees.Value / 100);
                        }
                    }
                    decimal fee = nudTotalAmount.Value - nudAmount.Value;
                    savingServices.Transfer(_saving, _savingTarget, _date, _amount, fee, _description,
                                            User.CurrentUser, false);
                    break;
                }

                case OSavingsOperation.SpecialOperation:
                {
                    OSavingsMethods savingsMethod =
                        (OSavingsMethods)
                        Enum.Parse(typeof(OSavingsMethods), cbSavingsMethod.SelectedValue.ToString());
                    if (cbBookings.SelectedItem != null)
                    {
                        Booking booking = (Booking)cbBookings.SelectedItem;
                        booking.Branch = _saving.Branch;
                        savingServices.SpecialOperation(_saving, _date, _amount, _description, User.CurrentUser,
                                                        savingsMethod, rbxCredit.Checked, booking);
                        break;
                    }
                    throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.TransactionInvalid);
                }
                }

                Close();
            }
            catch (Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            QueuedSMSServices     _queuedSMSService     = ServiceProvider.GetQueuedSMSServices();
            UserServices          _userService          = ServiceProvider.GetUserServices();
            ClientServices        _clientService        = ServiceProvider.GetClientServices();
            SavingServices        _savingService        = ServiceProvider.GetSavingServices();
            PaymentMethodServices _paymentMethodService = ServiceProvider.GetPaymentMethodServices();

            var generalSettingsService = ServicesProvider.GetInstance().GetApplicationSettingsServices();

            generalSettingsService.FillGeneralDatabaseParameter();

            Console.WriteLine("Executing sms charges job");

            var queuedsms = _queuedSMSService.GetUncharged();

            Console.WriteLine("");
            Console.WriteLine("-------------------------------------");
            Console.WriteLine("Charging SMS");
            Console.WriteLine("Uncharged sms count: " + queuedsms.Count);

            decimal smsCharge = Convert.ToDecimal(ApplicationSettings.GetInstance("").GetSpecificParameter(OGeneralSettings.SMS_CHARGE));

            var adminUser     = _userService.Find(1);
            var paymentMethod = _paymentMethodService.GetPaymentMethodByName("Cash");

            foreach (QueuedSMS qe in queuedsms)
            {
                try
                {
                    if (qe.ContractId.HasValue && qe.Charged.HasValue && !qe.Charged.Value)
                    {
                        SavingBookContract _saving = _savingService.GetSaving(qe.ContractId.Value);

                        //Get all sms for same saving book contract
                        var smsGroup = _queuedSMSService.FindByContractId(_saving.Id);

                        string description = "";

                        string formatedAccountNumber = "******" + _saving.Code.Substring(_saving.Code.Length - 4);

                        OCurrency SMSCharges = smsGroup.Count * smsCharge;

                        if (smsGroup.Count > 0)
                        {
                            string   desc  = "SMS charges of {0:.00} for {1:dd.MM.yyyy} - {2:dd.MM.yyyy} : {3}";
                            object[] items = new object[] { SMSCharges.GetFormatedValue(true), smsGroup.First().CreatedOnUtc, smsGroup.Last().CreatedOnUtc, formatedAccountNumber };
                            description = string.Format(desc, items);
                        }
                        if (smsGroup.Count == 0)
                        {
                            string   desc  = "SMS charges of {0:.00} for {1:dd.MM.yyyy} : {3}";
                            object[] items = new object[] { SMSCharges.GetFormatedValue(true), smsGroup.First().CreatedOnUtc, formatedAccountNumber };
                            description = string.Format(desc, items);
                            smsGroup.First().Charged = true;
                        }
                        _savingService.Withdraw(_saving, DateTime.Now, SMSCharges, true, description, "", adminUser,
                                                Teller.CurrentTeller, paymentMethod);

                        qe.Charged = true;
                        foreach (var sms in smsGroup)
                        {
                            sms.Charged = true;
                            queuedsms.Where(s => s.Id == sms.Id).First().Charged = true;
                            _queuedSMSService.Update(sms);
                        }

                        //Send sms charge notification
                        Person person = _clientService.FindPersonById(qe.RecipientId.Value);
                        if (person != null)
                        {
                            if (person.SMSDelivery.HasValue && person.SMSDelivery.Value)
                            {
                                string mfbName = Convert.ToString(ServicesProvider.GetInstance().GetGeneralSettings().GetSpecificParameter(OGeneralSettings.MFI_NAME));
                                //var message = messageTemplate.Body;
                                var messageReplaced = mfbName + " " + description;// Tokenizer.Replace(message, tokens, false);

                                var sms = new QueuedSMS()
                                {
                                    From         = Convert.ToString(ServicesProvider.GetInstance().GetGeneralSettings().GetSpecificParameter(OGeneralSettings.SMS_FROM_NUMBER)),
                                    Recipient    = person.PersonalPhone,
                                    RecipientId  = person.Id,
                                    ContractId   = _saving != null ? _saving.Id : 0,
                                    Charged      = true,
                                    Message      = messageReplaced,
                                    SentTries    = 0,
                                    CreatedOnUtc = DateTime.UtcNow,
                                };

                                _queuedSMSService.Add(sms);
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(string.Format("Error charging sms: {0}", exc.Message), exc);
                }
                finally
                {
                }
            }
        }