public AccountingRuleCollection SelectAllByEventType(string type) { const string sqlText = @"SELECT id, rule_type FROM [AccountingRules] WHERE deleted = 0 AND (event_type = @event_type OR @event_type = '')"; AccountingRuleCollection rules = new AccountingRuleCollection(); using (SqlConnection conn = GetConnection()) { using (OpenCbsCommand select = new OpenCbsCommand(sqlText, conn)) { select.AddParam("@event_type", type); using (OpenCbsReader reader = select.ExecuteReader()) { if (reader.Empty) { return(rules); } while (reader.Read()) { if (reader.GetChar("rule_type") == 'C') { rules.Add(new ContractAccountingRule { Id = reader.GetInt("id") }); } } } } } List <Account> accounts = _accountManager.SelectAllAccounts(); for (int i = 0; i < rules.Count; i++) { if (rules[i] is ContractAccountingRule) { rules[i] = SelectContractAccountingRule(rules[i].Id); } else { rules[i] = SelectFundingLineAccountingRule(rules[i].Id); } rules[i].DebitAccount = accounts.FirstOrDefault(item => item.Id == rules[i].DebitAccount.Id); rules[i].CreditAccount = accounts.FirstOrDefault(item => item.Id == rules[i].CreditAccount.Id); } return(rules); }
public void SetUp() { _rules = new AccountingRuleCollection(); _accounts = DefaultAccounts.DefaultAccount(1); Account cashSavings = new Account("1020", "CASH_SAVINGS", 0, "CASH_SAVIGNS", true, OAccountCategories.BalanceSheetAsset, 1); _accounts.Add(cashSavings); _rules.Add(new ContractAccountingRule { DebitAccount = _accounts[0], CreditAccount = cashSavings, ProductType = OProductTypes.Saving, SavingProduct = null, ClientType = OClientTypes.All, EconomicActivity = null, BookingDirection = OBookingDirections.Both }); _loanProductEde34 = new LoanProduct { Id = 1, Code = "EDE34", Name = "EDEN 34", Currency = new Currency { Id = 1} }; Account cashEDE34 = new Account("1051", "CASH_EDE34", 0, "CASH_EDE34", true, OAccountCategories.BalanceSheetAsset, 1); _accounts.Add(cashEDE34); _rules.Add(new ContractAccountingRule { DebitAccount = _accounts[0], CreditAccount = cashEDE34, ProductType = OProductTypes.Loan, LoanProduct = _loanProductEde34, ClientType = OClientTypes.Person, EconomicActivity = new EconomicActivity(1, "Agriculture", null, false), BookingDirection = OBookingDirections.Both }); _loanProductEde60 = new LoanProduct { Id = 2, Code = "EDE60", Name = "EDEN 60", Currency = new Currency { Id = 1 } }; Account cashEDE60 = new Account("1052", "CASH_EDE60", 0, "CASH_EDE60", true, OAccountCategories.BalanceSheetAsset, 1); _accounts.Add(cashEDE60); _rules.Add(new ContractAccountingRule { DebitAccount = _accounts[0], CreditAccount = cashEDE60, ProductType = OProductTypes.Loan, LoanProduct = _loanProductEde60, ClientType = OClientTypes.Person, EconomicActivity = new EconomicActivity(1, "Agriculture", null, false), BookingDirection = OBookingDirections.Credit }); }
private void Initialize() { string eventType = cbEventTypes.SelectedItem.ToString() == "All" ? "" : ((EventType) cbEventTypes.SelectedItem).EventCode; AccountingRuleCollection rules = ServicesProvider.GetInstance().GetAccountingRuleServices().SelectAllByEventType(eventType); listViewContractsRules.Items.Clear(); foreach (ContractAccountingRule rule in rules.GetContractAccountingRules()) { listViewContractsRules.Items.Add(GetListViewItem(rule)); if (_maxOrder < rule.Order) _maxOrder = rule.Order; } listViewContractsRules.Sorting = SortOrder.Descending; _sorter.ByColumn = 4; _sorter.reset = true; listViewContractsRules.Sort(); }
public AccountingRuleCollection SelectAllByEventType(string type) { const string sqlText = @"SELECT id, rule_type FROM [AccountingRules] WHERE deleted = 0 AND (event_type = @event_type OR @event_type = '')"; AccountingRuleCollection rules = new AccountingRuleCollection(); using (SqlConnection conn = GetConnection()) { using (OpenCbsCommand select = new OpenCbsCommand(sqlText, conn)) { select.AddParam("@event_type", type); using (OpenCbsReader reader = select.ExecuteReader()) { if (reader.Empty) return rules; while (reader.Read()) { if (reader.GetChar("rule_type") == 'C') rules.Add(new ContractAccountingRule { Id = reader.GetInt("id") }); } } } } List<Account> accounts = _accountManager.SelectAllAccounts(); for (int i = 0; i < rules.Count; i++) { if (rules[i] is ContractAccountingRule) { rules[i] = SelectContractAccountingRule(rules[i].Id); } else { rules[i] = SelectFundingLineAccountingRule(rules[i].Id); } rules[i].DebitAccount = accounts.FirstOrDefault(item => item.Id == rules[i].DebitAccount.Id); rules[i].CreditAccount = accounts.FirstOrDefault(item => item.Id == rules[i].CreditAccount.Id); } return rules; }
private void GetBookings(ClosureOptions options) { List <Booking> bookings = new List <Booking>(); EventStock eventStock = new EventStock(); AccountingRuleCollection rules = ServicesProvider.GetInstance().GetAccountingRuleServices().SelectAll(); rules.SortByOrder(); if (options.DoLoanClosure) { UpdateStatus("LoanClosureProcessing", ""); eventStock = ServicesProvider.GetInstance().GetEventProcessorServices().SelectEventsForClosure(_beginDate, _endDate, _branch); UpdateStatus("LoanClosureProcessing", eventStock.GetEvents().Count.ToString()); //add generated events for processing } if (options.DoSavingClosure) { UpdateStatus("SavingsClosureProcessing", ""); eventStock.AddRange( ServicesProvider.GetInstance().GetSavingServices().SelectEventsForClosure( _beginDate, _endDate, _branch)); UpdateStatus("SavingsClosureProcessing", eventStock.GetEvents().Count.ToString()); } if (options.DoTellerManagementClosure) { UpdateStatus("TellerManagementProcessing", ""); eventStock.AddRange(ServicesProvider.GetInstance().GetEventProcessorServices().GetTellerEventsForClosure( _beginDate, _endDate)); UpdateStatus("EventClosureProcessing", eventStock.GetEvents().Count.ToString()); } //important to have sorted list eventStock.SortEventsById(); //closure procesing timerClosure.Start(); timerClosure.Enabled = true; //set ex rate List <ExchangeRate> rates = ServicesProvider.GetInstance().GetExchangeRateServices().SelectRatesByDate(_beginDate, _endDate); List <CoreDomain.Accounting.FiscalYear> fiscalYears = ServicesProvider.GetInstance().GetChartOfAccountsServices().SelectFiscalYears(); bookings.AddRange( _accountingClosure.GetBookings( rules, eventStock, ServicesProvider.GetInstance().GetTellerServices().FindAllTellers(), ServicesProvider.GetInstance().GetPaymentMethodServices().GetAllPaymentMethodsForClosure(), rates, fiscalYears)); timerClosure.Stop(); timerClosure.Enabled = false; //manual transactions if (options.DoManualEntries) { bookings.AddRange(ServicesProvider.GetInstance().GetAccountingServices().SelectMovements(false, rates, fiscalYears)); } #region Reversal if (options.DoReversalTransactions) { UpdateStatus("ReversalTransactionProcessing", ""); bookings.AddRange(ServicesProvider.GetInstance().GetAccountingServices().SelectMovementsForReverse( rates, fiscalYears)); } #endregion //add reversal provision booking if (options.DoLoanClosure) { bookings.AddRange( _generatedEvents.GetProvisionEvents().Select( provisionEvent => ServicesProvider.GetInstance().GetAccountingServices().SelectProvisionMovments( provisionEvent.ContracId, rates, fiscalYears)).Where(b => b != null)); } SortBookingsByDate(bookings); FillListView(bookings); }
public void SetUp() { _rules = new AccountingRuleCollection(); _accounts = DefaultAccounts.DefaultAccount(1); Account cashSavings = new Account("1020", "CASH_SAVINGS", 0, "CASH_SAVIGNS", true, OAccountCategories.BalanceSheetAsset, 1); _accounts.Add(cashSavings); _rules.Add(new ContractAccountingRule { DebitAccount = _accounts[0], CreditAccount = cashSavings, ProductType = OProductTypes.Saving, SavingProduct = null, ClientType = OClientTypes.All, EconomicActivity = null, BookingDirection = OBookingDirections.Both }); _loanProductEde34 = new LoanProduct { Id = 1, Code = "EDE34", Name = "EDEN 34", Currency = new Currency { Id = 1 } }; Account cashEDE34 = new Account("1051", "CASH_EDE34", 0, "CASH_EDE34", true, OAccountCategories.BalanceSheetAsset, 1); _accounts.Add(cashEDE34); _rules.Add(new ContractAccountingRule { DebitAccount = _accounts[0], CreditAccount = cashEDE34, ProductType = OProductTypes.Loan, LoanProduct = _loanProductEde34, ClientType = OClientTypes.Person, EconomicActivity = new EconomicActivity(1, "Agriculture", null, false), BookingDirection = OBookingDirections.Both }); _loanProductEde60 = new LoanProduct { Id = 2, Code = "EDE60", Name = "EDEN 60", Currency = new Currency { Id = 1 } }; Account cashEDE60 = new Account("1052", "CASH_EDE60", 0, "CASH_EDE60", true, OAccountCategories.BalanceSheetAsset, 1); _accounts.Add(cashEDE60); _rules.Add(new ContractAccountingRule { DebitAccount = _accounts[0], CreditAccount = cashEDE60, ProductType = OProductTypes.Loan, LoanProduct = _loanProductEde60, ClientType = OClientTypes.Person, EconomicActivity = new EconomicActivity(1, "Agriculture", null, false), BookingDirection = OBookingDirections.Credit }); }
public void SelectAll() { Account genericAccount = _accountManager.Select(1); Account specificAccount = _accountManager.Select(2); EventType eventType = _eventManager.SelectEventTypeByEventType("RGLE"); EventAttribute eventAttribute = _eventManager.SelectEventAttributeByCode("principal"); #region adding rule 1 ContractAccountingRule ruleOne = new ContractAccountingRule { DebitAccount = genericAccount, CreditAccount = specificAccount, ProductType = OProductTypes.All, ClientType = OClientTypes.All, BookingDirection = OBookingDirections.Both, EventType = eventType, EventAttribute = eventAttribute }; ruleOne.Id = _accountingRuleManager.AddAccountingRule(ruleOne); Assert.AreNotEqual(0, ruleOne.Id); #endregion #region adding rule 2 LoanProduct loanProduct = _loanProductManager.Select(1); ContractAccountingRule ruleTwo = new ContractAccountingRule { DebitAccount = genericAccount, CreditAccount = specificAccount, ProductType = OProductTypes.Loan, LoanProduct = loanProduct, ClientType = OClientTypes.Corporate, BookingDirection = OBookingDirections.Credit, EventType = eventType, EventAttribute = eventAttribute }; ruleTwo.Id = _accountingRuleManager.AddAccountingRule(ruleTwo); Assert.AreNotEqual(0, ruleTwo.Id); #endregion #region adding rule 3 ContractAccountingRule ruleThree = new ContractAccountingRule { DebitAccount = genericAccount, CreditAccount = specificAccount, //ProductType = OProductTypes.Guarantee, ClientType = OClientTypes.Group, BookingDirection = OBookingDirections.Debit, EventType = eventType, EventAttribute = eventAttribute }; ruleThree.Id = _accountingRuleManager.AddAccountingRule(ruleThree); Assert.AreNotEqual(0, ruleThree.Id); #endregion #region adding rule 4 ISavingProduct savingsProduct = _savingProductManager.SelectSavingProduct(1); ContractAccountingRule ruleFour = new ContractAccountingRule { DebitAccount = genericAccount, CreditAccount = specificAccount, ProductType = OProductTypes.Saving, SavingProduct = savingsProduct, ClientType = OClientTypes.Person, BookingDirection = OBookingDirections.Both, EventType = eventType, EventAttribute = eventAttribute }; ruleFour.Id = _accountingRuleManager.AddAccountingRule(ruleFour); Assert.AreNotEqual(0, ruleFour.Id); #endregion #region adding rule 5 EconomicActivity economicActivty = _economicActivityManager.SelectEconomicActivity(1); ContractAccountingRule ruleFive = new ContractAccountingRule { DebitAccount = genericAccount, CreditAccount = specificAccount, ProductType = OProductTypes.All, ClientType = OClientTypes.Village, EconomicActivity = economicActivty, BookingDirection = OBookingDirections.Credit, EventType = eventType, EventAttribute = eventAttribute }; ruleFive.Id = _accountingRuleManager.AddAccountingRule(ruleFive); Assert.AreNotEqual(0, ruleFive.Id); #endregion AccountingRuleCollection rules = _accountingRuleManager.SelectAll(); Assert.AreEqual(5, rules.Count); _compareRules(ruleOne, rules[0] as ContractAccountingRule); _compareRules(ruleTwo, rules[1] as ContractAccountingRule); _compareRules(ruleThree, rules[2] as ContractAccountingRule); _compareRules(ruleFour, rules[3] as ContractAccountingRule); _compareRules(ruleFive, rules[4] as ContractAccountingRule); }
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 }); }
public List<Booking> GetBookings(AccountingRuleCollection rules, EventStock eventStock, List<Teller> tellers, List<PaymentMethod> paymentMethods, List<ExchangeRate> rates, List<FiscalYear> fiscalYears) { if (eventStock == null) return new List<Booking>(); rules.SortByOrder(); eventStock.SortEventsById(); bool isExported = false; var bookings = new List<Booking>(); foreach (Event eventItem in eventStock) { ClosureStatus = "Closure"; ClosureStatusInfo = " ->" + eventItem.Code + "-" + eventItem.Id; var attributes = new List<EventAttribute>(); List<ContractAccountingRule> rulesToApply = rules.GetContractAccountingRules().Where(item => item.EventType.EventCode == eventItem.Code).ToList(); rules.SortByOrder(); List<ContractAccountingRule> orders = rulesToApply.GroupBy(a => a.Order).Select(g => g.Last()).ToList(); foreach (ContractAccountingRule orderRule in orders) { foreach (ContractAccountingRule rule in rulesToApply.Where(r => r.Order == orderRule.Order).ToList()) { List<EventAttribute> evtAttributes = (from eventAtt in attributes where eventAtt.Name == rule.EventAttribute.Name select eventAtt).ToList(); if (rule.EventType.EventCode == eventItem.Code && evtAttributes.Count <= rulesToApply.Count(r => r.Order == orderRule.Order) - 1) { ContractAccountingRule tempRule = rule.Copy(); if (paymentMethods != null && eventItem.PaymentMethod != null) tempRule = GetParentPaymentAccount(eventItem.PaymentMethod.Id, tempRule, paymentMethods); // teller must be last if (tellers != null && eventItem.TellerId != null) { //that copy is very important because the rule might be over written by payment method tempRule = rule.Copy(); tempRule = GetParentTellerAccount(eventItem.TellerId, tempRule, tellers); } Booking b = GetBooking(tempRule, eventItem); if (b != null && b.Amount > 0) { //setting fiscal year if (fiscalYears != null) b.FiscalYear = fiscalYears .First( f => f.OpenDate <= b.Date.Date && (f.CloseDate == null || f.CloseDate >= b.Date.Date) ); //setting xrate ExchangeRate rate = null; if (rates != null) rate = rates.FirstOrDefault(r => r.Date.Date == b.Date.Date); b.ExchangeRate = b.Currency.IsPivot ? 1 : rate == null ? 0 : rate.Rate; isExported = true; attributes.Add(tempRule.EventAttribute); bookings.Add(b); } } } } if(eventItem is TellerCashInEvent || eventItem is TellerCashOutEvent) { bookings.Add(GetTellerBooking((TellerEvent) eventItem, tellers, fiscalYears)); } eventItem.IsFired = false; eventItem.IsFired = isExported; } return bookings; }
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 }); }