示例#1
0
文件: User.cs 项目: mokus1975/opencbs
 public void AddTeller(Teller teller)
 {
     Debug.Assert(teller != null, "Teller is null");
     if (HasTeller(teller))
     {
         return;
     }
     _tellers.Add(teller);
 }
示例#2
0
        public Teller Add(Teller teller, SqlTransaction t)
        {
            const string sqlText =
                @"INSERT INTO dbo.Tellers (name, [desc], account_id, branch_id, user_id, currency_id,
                                            amount_min, amount_max, deposit_amount_min, deposit_amount_max, withdrawal_amount_min, withdrawal_amount_max)
                                   VALUES (@name, @desc, @account_id, @branch_id, @user_id, @currency_id,
                                            @amount_min, @amount_max, @deposit_amount_min, @deposit_amount_max, @withdrawal_amount_min, @withdrawal_amount_max)
                                            SELECT SCOPE_IDENTITY()";
            using (var c = new OpenCbsCommand(sqlText, t.Connection, t))
            {

                c.AddParam("@name", teller.Name);
                c.AddParam("@desc", teller.Description);

                if (teller.Branch != null)
                    c.AddParam("@branch_id", teller.Branch.Id);
                else
                    c.AddParam("@branch_id", null);

                if (teller.Account != null)
                    c.AddParam("@account_id", teller.Account.Id);
                else
                    c.AddParam("@account_id", null);

                if (teller.User != null)
                    c.AddParam("@user_id", teller.User.Id);
                else
                    c.AddParam("@user_id", null);

                if (teller.Currency != null)
                    c.AddParam("@currency_id", teller.Currency.Id);
                else
                    c.AddParam("@currency_id", null);

                c.AddParam("@amount_min", teller.MinAmountTeller);
                c.AddParam("@amount_max", teller.MaxAmountTeller);
                c.AddParam("@deposit_amount_min", teller.MinAmountDeposit);
                c.AddParam("@deposit_amount_max", teller.MaxAmountDeposit);
                c.AddParam("@withdrawal_amount_min", teller.MinAmountWithdrawal);
                c.AddParam("@withdrawal_amount_max", teller.MaxAmountWithdrawal);

                teller.Id = Convert.ToInt32(c.ExecuteScalar());
            }
            return teller;
        }
示例#3
0
 private void Initialize(Teller teller)
 {
     _isNew = teller == null;
     _teller = teller ?? new Teller();
     _user = _isNew ? null : _teller.User;
     cmbBranch.SelectedIndexChanged -= cmbBranch_SelectedIndexChanged;
     cmbCurrency.SelectedIndexChanged -= cmbCurrency_SelectedIndexChanged;
     cmbAccount.SelectedIndexChanged -= cmbAccount_SelectedIndexChanged;
     cmbUser.SelectedIndexChanged -= cmbUser_SelectedIndexChanged;
     InitializeAccount();
     InitializeCurrency();
     InitializeBranches();
     InitializeUsers();
     InitializeAmounts();
     cmbBranch.SelectedIndexChanged += cmbBranch_SelectedIndexChanged;
     cmbCurrency.SelectedIndexChanged += cmbCurrency_SelectedIndexChanged;
     cmbAccount.SelectedIndexChanged += cmbAccount_SelectedIndexChanged;
     cmbUser.SelectedIndexChanged += cmbUser_SelectedIndexChanged;
 }
示例#4
0
 public Teller Add(Teller teller)
 {
     using (SqlConnection conn = _manager.GetConnection())
     {
         SqlTransaction t = conn.BeginTransaction();
         try
         {
             LoadTellers();
             _manager.Add(teller, t);
             _tellers.Add(teller);
             t.Commit();
             return teller;
         }
         catch (Exception)
         {
             t.Rollback();
             throw;
         }
     }
 }
示例#5
0
        public List<SavingEvent> CloseAndTransfer(ISavingsContract from, ISavingsContract to, DateTime date, User pUser,
            OCurrency amount, bool pIsDesactivateFees, Teller teller)
        {
            if (to.Status == OSavingsStatus.Closed)
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.CreditTransferAccountInvalid);

            if (from.Id == to.Id)
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.SavingsContractForTransferIdenticals);

            if (from.Product.Currency.Id != to.Product.Currency.Id)
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.SavingsContractForTransferNotSameCurrncy);

            OCurrency balance = SimulateCloseAccount(from, date, pUser, pIsDesactivateFees, teller).GetBalance(date);
            if (from is SavingBookContract && !pIsDesactivateFees) balance -= ((SavingBookContract)from).CloseFees;

            if (balance != amount)
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.TransferAmountIsInvalid);

            List<SavingEvent> events = new List<SavingEvent>();
            events.AddRange(from.Transfer(to, amount, 0, date, "Closing transfer"));
            events.AddRange(from.Close(date, pUser, "Close savings contract", pIsDesactivateFees, teller, false));
            foreach (SavingEvent e in events)
                _ePS.FireEvent(e);

            if (from.ClosedDate != null)
                _savingManager.UpdateStatus(from.Id, from.Status, from.ClosedDate.Value);

            return events;
        }
示例#6
0
        public void ValidateTeller(Teller teller)
        {
            if (string.IsNullOrEmpty(teller.Name))
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.NameIsEmpty);

            if (teller.Account == null)
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.AccountIsEmpty);

            if (teller.User == null)
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.UserIsEmpty);

            if (teller.Branch == null)
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.BranchIsEmpty);

            if (teller.Currency == null)
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.CurrencyIsEmpty);

            if (CheckMinMaxAndValueCorrectlyFilled(teller.MinAmountDeposit, teller.MaxAmountDeposit, null))
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.MinMaxAmountIsInvalid);

            if (CheckMinMaxAndValueCorrectlyFilled(teller.MinAmountWithdrawal, teller.MaxAmountWithdrawal, null))
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.MinMaxAmountIsInvalid);

            if (CheckMinMaxAndValueCorrectlyFilled(teller.MinAmountTeller, teller.MaxAmountTeller, null))
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.MinMaxAmountIsInvalid);

            if (teller.Id == null && Find(teller.Name) != null)
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.NameIsExists);

            if (teller.User.Id == 0 && _manager.SelectVault(teller.Branch.Id) != null)
                throw new OpenCbsTellerException(OpenCbsTellerExceptionEnum.VaultExists);
        }
示例#7
0
文件: User.cs 项目: mokus1975/opencbs
 public bool HasTeller(Teller teller)
 {
     return(_tellers.IndexOf(teller) > -1);
 }
示例#8
0
        public void Update(Teller teller, SqlTransaction t)
        {
            const string sqlText = @"UPDATE dbo.Tellers
                                              SET name = @name,
                                                 [desc] = @desc,
                                                 account_id = @account_id,
                                                 branch_id = @branch_id,
                                                 user_id = @user_id,
                                                 currency_id = @currency_id,
                                                 amount_min = @amount_min,
                                                 amount_max = @amount_max,
                                                 deposit_amount_min = @deposit_amount_min,
                                                 deposit_amount_max = @deposit_amount_max,
                                                 withdrawal_amount_min = @withdrawal_amount_min,
                                                 withdrawal_amount_max = @withdrawal_amount_max
                                              WHERE id = @id";
            using (var c = new OpenCbsCommand(sqlText, t.Connection, t))
            {
                c.AddParam("@id", teller.Id);
                c.AddParam("@name", teller.Name);
                c.AddParam("@desc", teller.Description);

                if (teller.Branch != null)
                    c.AddParam("@branch_id", teller.Branch.Id);
                else
                    c.AddParam("@branch_id", null);

                if (teller.Account != null)
                    c.AddParam("@account_id", teller.Account.Id);
                else
                    c.AddParam("@account_id", null);

                if (teller.User != null)
                    c.AddParam("@user_id", teller.User.Id);
                else
                    c.AddParam("@user_id", null);

                if (teller.Currency != null)
                    c.AddParam("@currency_id", teller.Currency.Id);
                else
                    c.AddParam("@currency_id", null);

                c.AddParam("@amount_min", teller.MinAmountTeller);
                c.AddParam("@amount_max", teller.MaxAmountTeller);
                c.AddParam("@deposit_amount_min", teller.MinAmountDeposit);
                c.AddParam("@deposit_amount_max", teller.MaxAmountDeposit);
                c.AddParam("@withdrawal_amount_min", teller.MinAmountWithdrawal);
                c.AddParam("@withdrawal_amount_max", teller.MaxAmountWithdrawal);

                c.ExecuteNonQuery();
            }
        }
示例#9
0
        public Teller SelectTellerOfUser(int userId)
        {
            var teller = new Teller();
            const string q = @"SELECT id
                                    , name
                                    , [desc]
                                    , account_id
                                    , deleted
                                    , branch_id
                                    , user_id
                                    , currency_id
                                    , amount_min
                                    , amount_max
                                    , deposit_amount_min
                                    , deposit_amount_max
                                    , withdrawal_amount_min
                                    , withdrawal_amount_max
                                    FROM dbo.Tellers
                                    WHERE user_id = @user_id AND deleted = 0";
            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
            {
                c.AddParam("@user_id", userId);
                using (OpenCbsReader r = c.ExecuteReader())
                {
                    if (r.Empty) return teller;

                    while (r.Read())
                    {
                        teller.Id = r.GetInt("id");
                        teller.Name = r.GetString("name");
                        teller.Description = r.GetString("desc");
                        teller.Deleted = r.GetBool("deleted");
                        teller.Account = accountManager.Select(r.GetInt("account_id"));
                        teller.Branch = branchManager.Select(r.GetInt("branch_id"));
                        int uId = r.GetInt("user_id");
                        teller.User = uId == 0 ? new User {Id = 0} : userManager.SelectUser(uId, false);
                        teller.Currency = currencyManager.SelectCurrencyById(r.GetInt("currency_id"));
                        teller.MinAmountTeller = r.GetMoney("amount_min");
                        teller.MaxAmountTeller = r.GetMoney("amount_max");
                        teller.MinAmountDeposit = r.GetMoney("deposit_amount_min");
                        teller.MaxAmountDeposit = r.GetMoney("deposit_amount_max");
                        teller.MinAmountWithdrawal = r.GetMoney("withdrawal_amount_min");
                        teller.MaxAmountWithdrawal = r.GetMoney("withdrawal_amount_max");
                    }
                }
            }
            return teller;
        }
示例#10
0
 public OCurrency GetLatestTellerOpenBalance(Teller teller)
 {
     const string sql =
                         @"SELECT TOP 1 [amount]
                         FROM [TellerEvents]
                         WHERE  [teller_id] = @teller_id
                            AND [event_code] = 'ODAE'
                         ORDER BY id DESC";
     using (SqlConnection connection = GetConnection())
     {
         using (OpenCbsCommand cmd = new OpenCbsCommand(sql, connection))
         {
             cmd.AddParam("@teller_id", teller.Id);
             object balance = cmd.ExecuteScalar();
             if (balance == null)
                 return 0;
             return decimal.Parse(balance.ToString());
         }
     }
 }
示例#11
0
        public void FirstDeposit(ISavingsContract saving, OCurrency initialAmount, DateTime creationDate, 
                                 OCurrency entryFees, User user, Teller teller)
        {
            if (!IsEntryFeesCorrect(saving, entryFees))
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.EntryFeesIsInvalid);

            if (!IsSavingBalanceCorrect(saving, initialAmount))
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.BalanceIsInvalid);
            using(SqlConnection conn = _savingManager.GetConnection())
            using (SqlTransaction sqlTransaction = conn.BeginTransaction())
            {
                try
                {
                    saving.FirstDeposit(initialAmount, creationDate, entryFees, user, teller);

                    if (_ePS != null)
                    {
                        foreach (SavingEvent savingEvent in saving.Events)
                        {
                            _ePS.FireEvent(savingEvent, saving, sqlTransaction);
                        }
                    }

                    saving.Status = OSavingsStatus.Active;
                    _savingManager.UpdateStatus(saving.Id, saving.Status, null);
                    sqlTransaction.Commit();
                }
                catch (Exception)
                {
                    sqlTransaction.Rollback();
                    throw;
                }
            }
        }
示例#12
0
        public void SetUp()
        {
            _rules = new AccountingRuleCollection();
            _accounts = DefaultAccounts.DefaultAccount(1);

            Account account1 = new Account("1020", "Test1", 0, "Test1", true, OAccountCategories.BalanceSheetAsset, 1);
            _accounts.Add(account1);

            Account account2 = new Account("1052", "Test2", 0, "Test2", true, OAccountCategories.BalanceSheetAsset, 1);
            _accounts.Add(account2);

            Account account3 = new Account("1051", "Test3", 0, "Test3", true, OAccountCategories.BalanceSheetAsset, 1);
            _accounts.Add(account3);

            Account vaultAccount = new Account("1999", "VaultAccount", 0, "VA", true, OAccountCategories.BalanceSheetAsset, 1);
            _accounts.Add(vaultAccount);

            Account tellerAccount1 = new Account("1991", "TellerAccount1", 0, "TA1", true, OAccountCategories.BalanceSheetAsset, 1);
            _accounts.Add(tellerAccount1);

            Account tellerAccount2 = new Account("1992", "TellerAccount2", 0, "TA2", true, OAccountCategories.BalanceSheetAsset, 1);
            _accounts.Add(tellerAccount2);

            _loanProductEde60 = new LoanProduct { Id = 2, Code = "EDE60", Name = "EDEN 60", Currency = new Currency { Id = 1 } };
            _loanProductEde34 = new LoanProduct { Id = 1, Code = "EDE34", Name = "EDEN 34", Currency = new Currency { Id = 1 } };

            var vault = new Teller
                               {
                                   Id = 1,
                                   Name = "Vault",
                                   Account = vaultAccount,
                                   Branch = new Branch {Id = 1},
                                   Currency = new Currency {Id = 1},
                                   User = new User {Id = 0},
                                   Deleted = false
                               };
            _tellers.Add(vault);

            var teller1 = new Teller
                              {
                                  Id = 2,
                                  Name = "Teller1",
                                  Account = tellerAccount1,
                                  Branch = new Branch {Id = 1},
                                  Currency = new Currency {Id = 1},
                                  User = new User {Id = 1},
                                  Deleted = false,
                                  Vault = vault
                              };

            _tellers.Add(teller1);

            var teller2 = new Teller
                              {
                                  Id = 3,
                                  Name = "Teller2",
                                  Account = tellerAccount2,
                                  Branch = new Branch {Id = 1},
                                  Currency = new Currency {Id = 1},
                                  User = new User {Id = 2},
                                  Deleted = false,
                                  Vault = vault
                              };
            _tellers.Add(teller2);

            _rules.Add(new ContractAccountingRule
            {
                DebitAccount = account2,
                CreditAccount = account3,
                Order = 1,
                EventType = new EventType("RGLE"),
                EventAttribute = new EventAttribute("principal", "RGLE"),
                ProductType = OProductTypes.Loan,
                LoanProduct = _loanProductEde60,
                ClientType = OClientTypes.Person,
                //EconomicActivity = new EconomicActivity(1, "Agriculture", null, false),
                BookingDirection = OBookingDirections.Credit,
                Currency = new Currency { Id = 1 }
            });

            _rules.Add(new ContractAccountingRule
                           {
                               DebitAccount = account1,
                               CreditAccount = account2,
                               Order = 4,
                               EventType = new EventType("RGLE"),
                               EventAttribute = new EventAttribute("principal", "RGLE"),
                               ProductType = OProductTypes.All,
                               LoanProduct = null,
                               ClientType = OClientTypes.Group,
                               EconomicActivity = null,
                               BookingDirection = OBookingDirections.Credit,
                               Currency = new Currency { Id = 2 }
                           });

            _rules.Add(new ContractAccountingRule
            {
                DebitAccount = account1,
                CreditAccount = account2,
                Order = 9,
                EventType = new EventType("RGLE"),
                EventAttribute = new EventAttribute("principal", "RGLE"),
                ProductType = OProductTypes.All,
                SavingProduct = null,
                ClientType = OClientTypes.All,
                EconomicActivity = null,
                BookingDirection = OBookingDirections.Both
            });

            _rules.Add(new ContractAccountingRule
            {
                DebitAccount = account2,
                CreditAccount = account1,
                Order = 3,
                EventType = new EventType("LODE"),
                EventAttribute = new EventAttribute("amount", "LODE"),
                ProductType = OProductTypes.Loan,
                LoanProduct = null,
                ClientType = OClientTypes.Person,
                EconomicActivity = new EconomicActivity(1, "Agriculture", null, false),
                BookingDirection = OBookingDirections.Both
            });
        }
示例#13
0
        public void FirstDeposit(ISavingsContract saving, OCurrency initialAmount, DateTime creationDate,
                                 OCurrency entryFees, User user, Teller teller)
        {
            if (!IsEntryFeesCorrect(saving, entryFees))
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.EntryFeesIsInvalid);

            if (!IsSavingBalanceCorrect(saving, initialAmount))
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.BalanceIsInvalid);
            if (saving.Client == null)
                saving.Client =
                    ServicesProvider.GetInstance().GetClientServices().FindTiersBySavingsId(saving.Id);
            using (SqlConnection conn = _savingManager.GetConnection())
            using (SqlTransaction sqlTransaction = conn.BeginTransaction())
            {
                try
                {
                    saving.FirstDeposit(initialAmount, creationDate, entryFees, user, teller);

                    if (_ePS != null)
                    {
                        foreach (SavingEvent savingEvent in saving.Events)
                        {
                            _ePS.FireEvent(savingEvent, saving, sqlTransaction);
                            ServicesProvider.GetInstance()
                                       .GetContractServices()
                                       .CallInterceptor(new Dictionary<string, object>
                                            {
                                                {"Saving", saving},
                                                {"Event", savingEvent},
                                                {"SqlTransaction", sqlTransaction}
                                            });
                        }
                    }

                    saving.Status = OSavingsStatus.Active;
                    _savingManager.UpdateStatus(saving.Id, saving.Status, null);
                    sqlTransaction.Commit();
                }
                catch (Exception)
                {
                    sqlTransaction.Rollback();
                    throw;
                }
            }
        }
示例#14
0
        public List<SavingEvent> Withdraw(ISavingsContract pSaving, DateTime pDate, OCurrency pWithdrawAmount,
                                          string pDescription, User pUser, Teller teller, SqlTransaction sqlTransaction, PaymentMethod paymentMethod)
        {
            ValidateWithdrawal(pWithdrawAmount, pSaving, pDate, pDescription, pUser, teller, paymentMethod);

            List<SavingEvent> events = pSaving.Withdraw(pWithdrawAmount, pDate, pDescription, pUser, false, teller, paymentMethod);
            foreach (SavingEvent savingEvent in events)
            {
                _ePS.FireEvent(savingEvent, pSaving, sqlTransaction);
            }

            // Charge overdraft fees if the balance is negative
            if (pSaving is SavingBookContract)
            {
                if (pSaving.GetBalance() < 0 && !((SavingBookContract)pSaving).InOverdraft)
                {
                    SavingEvent overdraftFeeEvent = pSaving.ChargeOverdraftFee(pDate, pUser);
                    _ePS.FireEvent(overdraftFeeEvent, pSaving, sqlTransaction);

                    ((SavingBookContract)pSaving).InOverdraft = true;
                    UpdateOverdraftStatus(pSaving.Id, true);
                }
            }

            return events;
        }
示例#15
0
        /// <summary>
        /// Checks DepositAmount and balance simulation
        /// </summary>
        /// <param name="pSaving"></param>
        /// <param name="pDate"></param>
        /// <param name="pWithdrawAmount"></param>
        /// <param name="pDescription"></param>
        /// <param name="pUser"></param>
        /// <returns></returns>
        public List<SavingEvent> Withdraw(ISavingsContract pSaving, DateTime pDate, OCurrency pWithdrawAmount, string pDescription, User pUser, Teller teller, PaymentMethod paymentMethod)
        {
            ValidateWithdrawal(pWithdrawAmount, pSaving, pDate, pDescription, pUser, teller, paymentMethod);
            if (pSaving.Client == null)
                pSaving.Client =
                    ServicesProvider.GetInstance().GetClientServices().FindTiersBySavingsId(pSaving.Id);
            List<SavingEvent> events = pSaving.Withdraw(pWithdrawAmount, pDate, pDescription, pUser, false, teller, paymentMethod);
            using (SqlConnection conn = _savingManager.GetConnection())
            using (SqlTransaction sqlTransaction = conn.BeginTransaction())
            {
                try
                {
                    foreach (SavingEvent savingEvent in events)
                    {
                        _ePS.FireEvent(savingEvent, pSaving, sqlTransaction);
                        ServicesProvider.GetInstance()
                            .GetContractServices()
                            .CallInterceptor(new Dictionary<string, object>
                            {
                                {"Saving", pSaving},
                                {"Event", new SavingWithdrawEvent
                                {
                                    Id = savingEvent.Id,
                                    Code = savingEvent.Code,
                                    Amount = savingEvent.Amount,
                                    Description = savingEvent.Description,
                                    PaymentsMethod = paymentMethod
                                   }},
                                {"SqlTransaction", sqlTransaction}
                            });
                    }

                    // Charge overdraft fees if the balance is negative
                    if (pSaving is SavingBookContract)
                    {
                        if (pSaving.GetBalance() < 0 && !((SavingBookContract)pSaving).InOverdraft)
                        {
                            SavingEvent overdraftFeeEvent = pSaving.ChargeOverdraftFee(pDate, pUser);
                            _ePS.FireEvent(overdraftFeeEvent, pSaving, sqlTransaction);

                            ((SavingBookContract)pSaving).InOverdraft = true;
                            UpdateOverdraftStatus(pSaving.Id, true);
                        }
                    }

                    sqlTransaction.Commit();
                    return events;
                }
                catch (Exception)
                {
                    sqlTransaction.Rollback();
                    throw;
                }
            }
        }
示例#16
0
 public Teller Delete(Teller teller)
 {
     _tellers.Remove(teller);
     _manager.Delete(teller.Id);
     return teller;
 }
示例#17
0
        public List<SavingEvent> CloseAndWithdraw(ISavingsContract saving, DateTime date, User user, OCurrency withdrawAmount, 
                                                 bool isDesactivateFees, Teller teller)
        {
            OCurrency balance = SimulateCloseAccount(saving, date, user, isDesactivateFees, teller).GetBalance(date);

            if (balance != withdrawAmount)
            {
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.WithdrawAmountIsInvalid);
            }

            List<SavingEvent> events = saving.Withdraw(withdrawAmount, date, "Withdraw savings", user, true,
                                                        Teller.CurrentTeller);
            events.AddRange(saving.Close(date, user, "Close savings contract", isDesactivateFees, teller, false));
            using (SqlConnection conn = _savingManager.GetConnection())
            using (SqlTransaction sqlTransaction = conn.BeginTransaction())
            {
                try
                {
                    foreach (SavingEvent savingEvent in events)
                        _ePS.FireEvent(savingEvent, saving, sqlTransaction);

                    if (saving.ClosedDate != null)
                        _savingManager.UpdateStatus(saving.Id, saving.Status, saving.ClosedDate.Value);

                    sqlTransaction.Commit();
                    return events;
                }
                catch (Exception)
                {
                    sqlTransaction.Rollback();
                    throw;
                }
            }
        }
示例#18
0
 private void btnConfirm_Click(object sender, EventArgs e)
 {
     try
     {
         OCurrency amount = decimal.Parse(tbAmount.Text);
         if (_isOpen)
         {
             foreach (Teller teller in ServicesProvider.GetInstance().GetTellerServices().FindAllNonDeletedTellersOfUser(User.CurrentUser))
             {
                 if ((int)cmbTellers.SelectedValue == (int)teller.Id)
                 {
                     _teller = teller;
                 }
             }
             if (Check(_teller) && !CheckIfTellerAmountIsValid(amount, _teller))
                 throw new Exception(GetString("AmountShouldBeBetweenValues.Text"));
             GenerateTellerEvents(amount, _isOpen);
         }
         else
         {
             if (Check(Teller.CurrentTeller) && !CheckIfTellerAmountIsValid(amount, _teller))
                 throw new Exception(GetString("AmountShouldBeBetweenValues.Text"));
             GenerateTellerEvents(amount, _isOpen);
             Notify(Teller.CurrentTeller.Name + " " + GetString("tellerIsClosedText"));
         }
         _canClose = true;
         Close();
     }
     catch (Exception ex)
     {
         new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
     }
 }
示例#19
0
        public List<SavingEvent> Deposit(ISavingsContract saving, DateTime dateTime, OCurrency depositAmount,
            string description, User user, bool isPending, OSavingsMethods savingsMethod, int? pendingEventId, Teller teller)
        {
            using (SqlConnection conn = _savingManager.GetConnection())
            using (SqlTransaction sqlTransaction = conn.BeginTransaction())
            {
                try
                {
                    if (!IsDepositAmountCorrect(depositAmount, saving, savingsMethod))
                        throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.DepositAmountIsInvalid);

                    ISavingsContract savingSimulation = (ISavingsContract) saving.Clone();
                        // Create a fake Saving object

                    // Do deposit to the fake Saving object
                    savingSimulation.Deposit(depositAmount, dateTime, description, user, false, isPending, savingsMethod,
                                             pendingEventId, teller);

                    if (!IsSavingBalanceCorrect(savingSimulation)) // Check balance simulation
                        throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.BalanceIsInvalid);

                    List<SavingEvent> events = saving.Deposit(depositAmount, dateTime, description, user, false,
                                                              isPending,
                                                              savingsMethod, pendingEventId, teller);

                    foreach (SavingEvent savingEvent in events)
                    {
                        _ePS.FireEvent(savingEvent, saving, sqlTransaction);
                    }

                    // Change overdraft state
                    if (saving is SavingBookContract)
                    {
                        if (saving.GetBalance() > 0)
                        {
                            ((SavingBookContract) saving).InOverdraft = false;
                            UpdateOverdraftStatus(saving.Id, false);
                        }
                    }
                    sqlTransaction.Commit();
                    return events;
                }
                catch (Exception)
                {
                    sqlTransaction.Rollback();
                    throw;
                }
            }
        }
示例#20
0
 private bool Check(Teller teller)
 {
     return teller.MinAmountTeller < teller.MaxAmountTeller && teller.MaxAmountTeller > 0;
 }
示例#21
0
        public ISavingsContract SimulateCloseAccount(ISavingsContract saving, DateTime date, User user, bool isDesactivateFees, Teller teller)
        {
            ISavingsContract savingSimulation = (ISavingsContract) saving.Clone();
            savingSimulation.SimulateClose(date, user, "Close savings contract", isDesactivateFees, teller);

            return savingSimulation;
        }
示例#22
0
 private bool CheckIfTellerAmountIsValid(OCurrency amount, Teller teller)
 {
     return teller.MinAmountTeller <= amount && amount <= teller.MaxAmountTeller;
 }
示例#23
0
 public OCurrency GetTellerBalance(Teller teller)
 {
     using (SqlConnection conn = GetConnection())
     {
         using (var c = new OpenCbsCommand("GetTellerBalance", conn).AsStoredProcedure())
         {
             c.AddParam("@teller_id", teller.Id);
             return decimal.Parse(c.ExecuteScalar().ToString());
         }
     }
 }
示例#24
0
 private void cmbTellers_SelectedValueChanged(object sender, System.EventArgs e)
 {
     if (cmbTellers.SelectedValue != null)
     {
         foreach (Teller teller in ServicesProvider.GetInstance().GetTellerServices().FindAllNonDeletedTellersOfUser(User.CurrentUser))
         {
             if ((int) cmbTellers.SelectedValue == (int) teller.Id)
             {
                 _teller = teller;
             }
         }
     }
 }
示例#25
0
        public Teller SelectVault(int branchId)
        {
            var teller = new Teller();
            const string q = @"SELECT id
                                    , name
                                    , [desc]
                                    , account_id
                                    , deleted
                                    , branch_id
                                    , currency_id
                                    FROM dbo.Tellers
                                    WHERE branch_id = @branch_id AND deleted = 0 AND user_id = 0";

            using (var conn = GetConnection())
            using (var c = new OpenCbsCommand(q, conn))
            {
                c.AddParam("@branch_id", branchId);
                using (OpenCbsReader r = c.ExecuteReader())
                {
                    r.Read();
                    if (r.Empty) return null;
                    teller.Id = r.GetInt("id");
                    teller.Name = r.GetString("name");
                    teller.Description = r.GetString("desc");
                    teller.Deleted = r.GetBool("deleted");
                    teller.Account = accountManager.Select(r.GetInt("account_id"));
                    teller.Branch = branchManager.Select(r.GetInt("branch_id"));
                    teller.Currency = currencyManager.SelectCurrencyById(r.GetInt("currency_id"));
                }
            }
            return teller;
        }
示例#26
0
文件: User.cs 项目: TalasZh/opencbs
 public void AddTeller(Teller teller)
 {
     Debug.Assert(teller != null, "Teller is null");
     if(HasTeller(teller)) return;
     _tellers.Add(teller);
 }
示例#27
0
 public OCurrency GetTellerBalance(Teller teller)
 {
     return  _manager.GetTellerBalance(teller);
 }
示例#28
0
 public OCurrency GetLatestTellerOpenBalance(Teller teller)
 {
     return _manager.GetLatestTellerOpenBalance(teller);
 }
示例#29
0
        /// <summary>
        /// Checks DepositAmount and balance simulation
        /// </summary>
        /// <param name="pSaving"></param>
        /// <param name="pDate"></param>
        /// <param name="pWithdrawAmount"></param>
        /// <param name="pDescription"></param>
        /// <param name="pUser"></param>
        /// <returns></returns>
        public List<SavingEvent> Withdraw(ISavingsContract pSaving, DateTime pDate, OCurrency pWithdrawAmount, string pDescription, User pUser, Teller teller)
        {
            ValidateWithdrawal(pWithdrawAmount, pSaving, pDate, pDescription, pUser, teller);

            List<SavingEvent> events = pSaving.Withdraw(pWithdrawAmount, pDate, pDescription, pUser, false, teller);
            using (SqlConnection conn = _savingManager.GetConnection())
            using (SqlTransaction sqlTransaction = conn.BeginTransaction())
            {
                try
                {
                    foreach (SavingEvent savingEvent in events)
                    {
                        _ePS.FireEvent(savingEvent, pSaving, sqlTransaction);
                    }

                    // Charge overdraft fees if the balance is negative
                    if (pSaving is SavingBookContract)
                    {
                        if (pSaving.GetBalance() < 0 && !((SavingBookContract) pSaving).InOverdraft)
                        {
                            SavingEvent overdraftFeeEvent = pSaving.ChargeOverdraftFee(pDate, pUser);
                            _ePS.FireEvent(overdraftFeeEvent, pSaving, sqlTransaction);

                            ((SavingBookContract) pSaving).InOverdraft = true;
                            UpdateOverdraftStatus(pSaving.Id, true);
                        }
                    }

                    sqlTransaction.Commit();
                    return events;
                }
                catch (Exception)
                {
                    sqlTransaction.Rollback();
                    throw;
                }
            }
        }
示例#30
0
 public Teller Update(Teller teller)
 {
     using (SqlConnection conn =_manager.GetConnection())
     {
         SqlTransaction t = conn.BeginTransaction();
         try
         {
             _manager.Update(teller, t);
             t.Commit();
             return teller;
         }
         catch (Exception)
         {
             t.Rollback();
             throw;
         }
     }
 }
示例#31
0
文件: User.cs 项目: TalasZh/opencbs
 public bool HasTeller(Teller teller)
 {
     return _tellers.IndexOf(teller) > -1;
 }
示例#32
0
        private void ValidateWithdrawal(OCurrency pWithdrawAmount, ISavingsContract pSaving, DateTime pDate, string pDescription, User pUser, Teller teller)
        {
            if (!IsWithdrawAmountCorrect(pWithdrawAmount, pSaving))
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.WithdrawAmountIsInvalid);

            if (pSaving is SavingBookContract)
            {
                OCurrency fee;
                if(((SavingBookContract) pSaving).RateWithdrawFees.HasValue)
                {
                    fee = ((SavingBookContract) pSaving).RateWithdrawFees.Value*pWithdrawAmount;
                }
                else
                {
                    fee = ((SavingBookContract) pSaving).FlatWithdrawFees;
                }
                OCurrency totalAmount = pWithdrawAmount + fee;

                if (((SavingBookContract)pSaving).GetBalance() - totalAmount < 0)
                    CanUserMakeBalanceNegative();//Check if current user is allowed to make balance negative

                decimal vBalance = CheckVirtualBalance((SavingBookContract) pSaving, totalAmount);
                if (vBalance > 0)
                {
                    List<string> messages = new List<string>
                                                {
                                                    ServicesHelper.ConvertDecimalToString(((SavingBookContract) pSaving).GetBalance().Value),
                                                    ServicesHelper.ConvertDecimalToString(vBalance),
                                                    ((SavingBookContract) pSaving).Loans.Count.ToString(),
                                                    ServicesHelper.ConvertDecimalToString(((SavingBookContract) pSaving).GetBalance().Value - vBalance)
                                                };

                    throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.BalanceOnCurrentSavingAccount, messages);
                }
            }

            // Create a fake Saving object
            ISavingsContract savingSimulation = (ISavingsContract)pSaving.Clone();
            // Do withdraw in the fake Saving object
            savingSimulation.Withdraw(pWithdrawAmount, pDate, pDescription, pUser, false, teller);
            // Check balance simulation
            if (!IsSavingBalanceCorrect(savingSimulation))
                throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.BalanceIsInvalid);
        }