Example #1
0
        private static OCurrency GetValue(RepaymentOverWriteOffEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "principal")
            {
                amount = eventItem.Principal;
            }

            if (rule.EventAttribute.Name.ToLower() == "interests")
            {
                amount = eventItem.Interests;
            }

            if (rule.EventAttribute.Name.ToLower() == "penalties")
            {
                amount = eventItem.Penalties;
            }

            if (rule.EventAttribute.Name == "commissions")
            {
                amount = eventItem.Commissions;
            }
            return(amount);
        }
Example #2
0
        private static OCurrency GetValue(WriteOffEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            switch (rule.EventAttribute.Name.ToLower())
            {
            case "olb":
                amount = eventItem.OLB;
                break;

            case "accrued_interests":
                amount = eventItem.AccruedInterests;
                break;

            case "accrued_penalties":
                amount = eventItem.AccruedPenalties;
                break;

            case "past_due_days":
                amount = eventItem.PastDueDays;
                break;

            case "overdue_principal":
                amount = eventItem.OverduePrincipal;
                break;
            }
            return(amount);
        }
        public void Get_Set_ClientType()
        {
            ContractAccountingRule rule = new ContractAccountingRule { ClientType = OClientTypes.All };
            Assert.AreEqual(OClientTypes.All, rule.ClientType);

            rule.ClientType = OClientTypes.Person;
            Assert.AreEqual(OClientTypes.Person, rule.ClientType);
        }
        public void Get_Set_Deleted()
        {
            ContractAccountingRule rule = new ContractAccountingRule { Deleted = true };
            Assert.AreEqual(true, rule.Deleted);

            rule = new ContractAccountingRule();
            Assert.AreEqual(false, rule.Deleted);
        }
        public void Get_Set_BookingDirection()
        {
            ContractAccountingRule rule = new ContractAccountingRule { BookingDirection = OBookingDirections.Credit };
            Assert.AreEqual(OBookingDirections.Credit, rule.BookingDirection);

            rule.BookingDirection = OBookingDirections.Both;
            Assert.AreEqual(OBookingDirections.Both, rule.BookingDirection);
        }
        public void Get_Set_EconomicActivity()
        {
            ContractAccountingRule rule = new ContractAccountingRule();
            Assert.AreEqual(null, rule.EconomicActivity);

            EconomicActivity economicActivity = new EconomicActivity { Id = 1, Name = "Econimic Acvitity" };
            rule.EconomicActivity = economicActivity;
            Assert.AreEqual(economicActivity, rule.EconomicActivity);
        }
Example #7
0
        private static OCurrency GetValue(LoanEntryFeeEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "fee")
            {
                amount = eventItem.Fee;
            }
            return(amount);
        }
Example #8
0
        private static OCurrency GetValue(AccruedInterestEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "accrued_interest")
            {
                amount = eventItem.AccruedInterest;
            }
            return(amount);
        }
Example #9
0
        private static OCurrency GetValue(ProvisionEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "amount")
            {
                amount = eventItem.Amount;
            }
            return(amount);
        }
Example #10
0
        private static ContractAccountingRule GetParentTellerAccount(int? tellerId, ContractAccountingRule rule,
                                                                     List<Teller> tellers)
        {
            foreach (Teller teller in tellers)
            {
                if (tellerId == teller.Id)
                {
                    if (teller.Account.ParentAccountId == rule.DebitAccount.Id) rule.DebitAccount = teller.Account;
                    if (teller.Account.ParentAccountId == rule.CreditAccount.Id) rule.CreditAccount = teller.Account;
                }
            }

            return rule;
        }
Example #11
0
        private static OCurrency GetValue(CreditInsuranceEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "principal")
            {
                amount = eventItem.Principal;
            }

            if (rule.EventAttribute.Name.ToLower() == "commission")
            {
                amount = eventItem.Commission;
            }
            return(amount);
        }
Example #12
0
        private static OCurrency GetValue(RescheduleLoanEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "amount")
            {
                amount = eventItem.Amount;
            }

            if (rule.EventAttribute.Name.ToLower() == "interest")
            {
                amount = eventItem.Interest;
            }
            return(amount);
        }
Example #13
0
        private static OCurrency GetValue(OverdueEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "olb")
            {
                amount = eventItem.OLB;
            }

            if (rule.EventAttribute.Name.ToLower() == "overdue_principal")
            {
                amount = eventItem.OverduePrincipal;
            }
            return(amount);
        }
Example #14
0
        private static ContractAccountingRule GetParentPaymentAccount(int? paymentMethodId, ContractAccountingRule rule,
                                                                      List<PaymentMethod> paymentMethods)
        {
            foreach (PaymentMethod paymentMethod in paymentMethods)
            {
                if (paymentMethodId == paymentMethod.Id)
                {
                    if (paymentMethod.Account.ParentAccountId == rule.DebitAccount.Id)
                        rule.DebitAccount = paymentMethod.Account;
                    if (paymentMethod.Account.ParentAccountId == rule.CreditAccount.Id)
                        rule.CreditAccount = paymentMethod.Account;
                }
            }

            return rule;
        }
Example #15
0
        private static ContractAccountingRule GetParentTellerAccount(int?tellerId, ContractAccountingRule rule,
                                                                     List <Teller> tellers)
        {
            foreach (Teller teller in tellers)
            {
                if (tellerId == teller.Id)
                {
                    if (teller.Account.ParentAccountId == rule.DebitAccount.Id)
                    {
                        rule.DebitAccount = teller.Account;
                    }
                    if (teller.Account.ParentAccountId == rule.CreditAccount.Id)
                    {
                        rule.CreditAccount = teller.Account;
                    }
                }
            }

            return(rule);
        }
Example #16
0
 private static Booking GetBooking(ContractAccountingRule rule, Event eventItem)
 {
     if (eventItem.Code == rule.EventType.EventCode)
     {
         if ((rule.LoanProduct == null ||
              (eventItem.LoanProduct != null && eventItem.LoanProduct.Id == rule.LoanProduct.Id)) &&
             (rule.SavingProduct == null ||
              (eventItem.SavingProduct != null && eventItem.SavingProduct.Id == rule.SavingProduct.Id)) &&
             (rule.Currency == null ||
              (eventItem.Currency != null && eventItem.Currency.Id == rule.Currency.Id)) &&
             (rule.ClientType == OClientTypes.All ||
              eventItem.ClientType == rule.ClientType) &&
             (rule.EconomicActivity == null
              ||
              (eventItem.EconomicActivity != null && eventItem.EconomicActivity.Id == rule.EconomicActivity.Id)))
         {
             var booking = new Booking
             {
                 Amount        = GetValue(rule, eventItem),
                 CreditAccount = rule.CreditAccount,
                 DebitAccount  = rule.DebitAccount,
                 ContractId    = eventItem.ContracId,
                 Date          = eventItem.Date,
                 EventId       = eventItem.Id,
                 RuleId        = rule.Id,
                 ExchangeRate  = 1,
                 Currency      = eventItem.Currency,
                 Branch        = eventItem.Branch,
                 EventType     = eventItem.Code,
                 Name          = eventItem.Description + " [" + eventItem.Date + "]",
                 Type          = eventItem is SavingEvent
                                              ? OMovementType.Saving
                                              : eventItem is TellerEvent
                                                    ? OMovementType.Teller
                                                    : OMovementType.Loan
             };
             return(booking);
         }
     }
     return(null);
 }
        public void AddContractRuleForAll()
        {
            Account genericAccount = _accountManager.Select(1);
            Account specificAccount = _accountManager.Select(2);
            EventType eventType = _eventManager.SelectEventTypeByEventType("RGLE");
            EventAttribute eventAttribute = _eventManager.SelectEventAttributeByCode("principal");

            ContractAccountingRule rule = new ContractAccountingRule
                                              {
                                                  DebitAccount = genericAccount,
                                                  CreditAccount = specificAccount,
                                                  ProductType = OProductTypes.Loan,
                                                  ClientType = OClientTypes.All,
                                                  BookingDirection = OBookingDirections.Both,
                                                  EventType = eventType,
                                                  EventAttribute = eventAttribute
                                              };

            rule.Id = _accountingRuleManager.AddAccountingRule(rule);
            Assert.AreNotEqual(0, rule.Id);

            ContractAccountingRule retrievedRule = _accountingRuleManager.Select(rule.Id) as ContractAccountingRule;
            _compareRules(rule, retrievedRule);
        }
Example #18
0
        private static OCurrency GetValue(RescheduleLoanEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "amount")
            {
                amount = eventItem.Amount;
            }

            if (rule.EventAttribute.Name.ToLower() == "interest")
            {
                amount = eventItem.Interest;
            }
            return amount;
        }
Example #19
0
        private static OCurrency GetValue(WriteOffEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            switch (rule.EventAttribute.Name.ToLower())
            {
                case "olb":
                    amount = eventItem.OLB;
                    break;
                case "accrued_interests":
                    amount = eventItem.AccruedInterests;
                    break;
                case "accrued_penalties":
                    amount = eventItem.AccruedPenalties;
                    break;
                case "past_due_days":
                    amount = eventItem.PastDueDays;
                    break;
                case "overdue_principal":
                    amount = eventItem.OverduePrincipal;
                    break;
            }
            return amount;
        }
Example #20
0
        private static OCurrency GetValue(ContractAccountingRule rule, Event eventItem)
        {
            OCurrency amount = 0;

            if (eventItem is SavingEvent)
            {
                if (rule.EventAttribute.Name.ToLower() == "amount")
                {
                    amount = (eventItem as SavingEvent).Amount;
                }

                if (rule.EventAttribute.Name.ToLower() == "fees")
                {
                    amount = (eventItem as SavingEvent).Fee;
                }
            }

            if (eventItem.Code == "LODE")
            {
                var e = (LoanDisbursmentEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "RGLE" ||
                eventItem.Code == "RBLE" ||
                eventItem.Code == "APR" ||
                eventItem.Code == "ATR" ||
                eventItem.Code == "APTR" ||
                eventItem.Code == "RRLE")
            {
                var e = (RepaymentEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "ROWO")
            {
                var e = (RepaymentOverWriteOffEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code.Substring(0, 3) == "LEE")
            {
                var e = (LoanEntryFeeEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "LCIP" || eventItem.Code == "LCIE" || eventItem.Code == "LCIW")
            {
                var e = (CreditInsuranceEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "TEET")
            {
                var e = (TrancheEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "ROLE")
            {
                var e = (RescheduleLoanEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "WROE")
            {
                var e = (WriteOffEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "GLBL" ||
                eventItem.Code == "LLBL" ||
                eventItem.Code == "BLGL" ||
                eventItem.Code == "GLLL" ||
                eventItem.Code == "BLLL" ||
                eventItem.Code == "BLRL" ||
                eventItem.Code == "LLGL" ||
                eventItem.Code == "BLRL" ||
                eventItem.Code == "GLRL" ||
                eventItem.Code == "LLRL")
            {
                var e = (OverdueEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "LIAE")
            {
                var e = (AccruedInterestEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "LLPE")
            {
                var e = (ProvisionEvent) eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem is TellerEvent)
            {
                var e = (TellerEvent) eventItem;
                amount = GetValue(e, rule);
            }

            return amount;
        }
Example #21
0
        private static OCurrency GetValue(ContractAccountingRule rule, Event eventItem)
        {
            OCurrency amount = 0;

            if (eventItem is SavingEvent)
            {
                if (rule.EventAttribute.Name.ToLower() == "amount")
                {
                    amount = (eventItem as SavingEvent).Amount;
                }

                if (rule.EventAttribute.Name.ToLower() == "fees")
                {
                    amount = (eventItem as SavingEvent).Fee;
                }
            }

            if (eventItem.Code == "LODE")
            {
                var e = (LoanDisbursmentEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "RGLE" ||
                eventItem.Code == "RBLE" ||
                eventItem.Code == "APR" ||
                eventItem.Code == "ATR" ||
                eventItem.Code == "APTR" ||
                eventItem.Code == "RRLE")
            {
                var e = (RepaymentEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "ROWO")
            {
                var e = (RepaymentOverWriteOffEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code.Substring(0, 3) == "LEE")
            {
                var e = (LoanEntryFeeEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "LCIP" || eventItem.Code == "LCIE" || eventItem.Code == "LCIW")
            {
                var e = (CreditInsuranceEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "TEET")
            {
                var e = (TrancheEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "ROLE")
            {
                var e = (RescheduleLoanEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "WROE")
            {
                var e = (WriteOffEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "GLBL" ||
                eventItem.Code == "LLBL" ||
                eventItem.Code == "BLGL" ||
                eventItem.Code == "GLLL" ||
                eventItem.Code == "BLLL" ||
                eventItem.Code == "BLRL" ||
                eventItem.Code == "LLGL" ||
                eventItem.Code == "BLRL" ||
                eventItem.Code == "GLRL" ||
                eventItem.Code == "LLRL")
            {
                var e = (OverdueEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "LIAE")
            {
                var e = (AccruedInterestEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem.Code == "LLPE")
            {
                var e = (ProvisionEvent)eventItem;
                amount = GetValue(e, rule);
            }

            if (eventItem is TellerEvent)
            {
                var e = (TellerEvent)eventItem;
                amount = GetValue(e, rule);
            }

            return(amount);
        }
Example #22
0
 private static Booking GetBooking(ContractAccountingRule rule, Event eventItem)
 {
     if (eventItem.Code == rule.EventType.EventCode)
     {
         if ((rule.LoanProduct == null
              || (eventItem.LoanProduct != null && eventItem.LoanProduct.Id == rule.LoanProduct.Id))
             && (rule.SavingProduct == null
                 || (eventItem.SavingProduct != null && eventItem.SavingProduct.Id == rule.SavingProduct.Id))
             && (rule.Currency == null
                 || (eventItem.Currency != null && eventItem.Currency.Id == rule.Currency.Id))
             && (rule.ClientType == OClientTypes.All
                 || eventItem.ClientType == rule.ClientType)
             && (rule.EconomicActivity == null
                 ||
                 (eventItem.EconomicActivity != null && eventItem.EconomicActivity.Id == rule.EconomicActivity.Id)))
         {
             var booking = new Booking
                               {
                                   Amount = GetValue(rule, eventItem),
                                   CreditAccount = rule.CreditAccount,
                                   DebitAccount = rule.DebitAccount,
                                   ContractId = eventItem.ContracId,
                                   Date = eventItem.Date,
                                   EventId = eventItem.Id,
                                   RuleId = rule.Id,
                                   ExchangeRate = 1,
                                   Currency = eventItem.Currency,
                                   Branch = eventItem.Branch,
                                   EventType = eventItem.Code,
                                   Name = eventItem.Description + " [" + eventItem.Date + "]",
                                   Type = eventItem is SavingEvent
                                              ? OMovementType.Saving
                                              : eventItem is TellerEvent
                                                    ? OMovementType.Teller
                                                    : OMovementType.Loan
                               };
             return booking;
         }
     }
     return null;
 }
Example #23
0
        private static OCurrency GetValue(RepaymentOverWriteOffEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "principal")
            {
                amount = eventItem.Principal;
            }

            if (rule.EventAttribute.Name.ToLower() == "interests")
            {
                amount = eventItem.Interests;
            }

            if (rule.EventAttribute.Name.ToLower() == "penalties")
            {
                amount = eventItem.Penalties;
            }

            if (rule.EventAttribute.Name == "commissions")
            {
                amount = eventItem.Commissions;
            }
            return amount;
        }
Example #24
0
        public IAccountingRule Select(int pId)
        {
            const string sqlText = @"SELECT rule_type
                                     FROM [AccountingRules]
                                     WHERE deleted = 0
                                     AND id = @id";

            IAccountingRule rule = new ContractAccountingRule();
            using (SqlConnection conn = GetConnection())
            {
                using (OpenCbsCommand select = new OpenCbsCommand(sqlText, conn))
                {
                    select.AddParam("@id", pId);

                    using (OpenCbsReader reader = select.ExecuteReader())
                    {
                        if (reader.Empty) return null;

                        reader.Read();
                        if (reader.GetChar("rule_type") == 'C')
                            rule = new ContractAccountingRule {Id = pId};
                    }
                }
            }

            if (rule is ContractAccountingRule)
                rule = SelectContractAccountingRule(rule.Id);

            List<Account> accounts = _accountManager.SelectAllAccounts();
            rule.DebitAccount = accounts.FirstOrDefault(item => item.Id == rule.DebitAccount.Id);
            rule.CreditAccount = accounts.FirstOrDefault(item => item.Id == rule.CreditAccount.Id);

            return rule;
        }
        private void ValidateContractAccountingRule(ContractAccountingRule pRule)
        {
            if (!Enum.IsDefined(typeof(OProductTypes), pRule.ProductType.ToString()))
                throw new OpenCbsAccountingRuleException(OpenCbsAccountingRuleExceptionEnum.ProductTypeIsInvalid);

            if (!Enum.IsDefined(typeof(OClientTypes), pRule.ClientType.ToString()))
                throw new OpenCbsAccountingRuleException(OpenCbsAccountingRuleExceptionEnum.ClientTypeIsInvalid);
        }
Example #26
0
        private static OCurrency GetValue(OverdueEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "olb")
            {
                amount = eventItem.OLB;
            }

            if (rule.EventAttribute.Name.ToLower() == "overdue_principal")
            {
                amount = eventItem.OverduePrincipal;
            }
            return amount;
        }
Example #27
0
        private static ContractAccountingRule GetParentPaymentAccount(int?paymentMethodId, ContractAccountingRule rule,
                                                                      List <PaymentMethod> paymentMethods)
        {
            foreach (PaymentMethod paymentMethod in paymentMethods)
            {
                if (paymentMethodId == paymentMethod.Id)
                {
                    if (paymentMethod.Account.ParentAccountId == rule.DebitAccount.Id)
                    {
                        rule.DebitAccount = paymentMethod.Account;
                    }
                    if (paymentMethod.Account.ParentAccountId == rule.CreditAccount.Id)
                    {
                        rule.CreditAccount = paymentMethod.Account;
                    }
                }
            }

            return(rule);
        }
        public void DeleteRule()
        {
            Account genericAccount = _accountManager.Select(1);
            Account specificAccount = _accountManager.Select(2);
            EventType eventType = _eventManager.SelectEventTypeByEventType("RGLE");
            EventAttribute eventAttribute = _eventManager.SelectEventAttributeByCode("principal");

            ContractAccountingRule rule = new ContractAccountingRule
            {
                DebitAccount = genericAccount,
                CreditAccount = specificAccount,
                ProductType = OProductTypes.Loan,
                ClientType = OClientTypes.All,
                BookingDirection = OBookingDirections.Both,
                EventAttribute = eventAttribute,
                EventType = eventType
            };

            rule.Id = _accountingRuleManager.AddAccountingRule(rule);
            Assert.AreNotEqual(0, rule.Id);

            _accountingRuleManager.DeleteAccountingRule(rule);
            Assert.AreEqual(null, _accountingRuleManager.Select(rule.Id));
        }
Example #29
0
        private static OCurrency GetValue(AccruedInterestEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "accrued_interest")
            {
                amount = eventItem.AccruedInterest;
            }
            return amount;
        }
Example #30
0
        private static OCurrency GetValue(CreditInsuranceEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "principal")
            {
                amount = eventItem.Principal;
            }

            if (rule.EventAttribute.Name.ToLower() == "commission")
            {
                amount = eventItem.Commission;
            }
            return amount;
        }
Example #31
0
        private static ContractAccountingRule GetContractAccountingRule(OpenCbsReader reader)
        {
            ContractAccountingRule rule = new ContractAccountingRule();

            rule.Id = reader.GetInt("id");
            rule.EventType = new EventType
                                 {
                                     EventCode = reader.GetString("event_type"),
                                     Description = reader.GetString("event_description")
                                 };
            rule.EventAttribute = new EventAttribute
                                      {
                                          Id = reader.GetInt("event_attribute_id"),
                                          Name = reader.GetString("attribute_name")
                                      };
            rule.DebitAccount = new Account { Id = reader.GetInt("debit_account_number_id") };
            rule.CreditAccount = new Account { Id = reader.GetInt("credit_account_number_id") };
            rule.BookingDirection = (OBookingDirections)reader.GetSmallInt("booking_direction");
            rule.Order = reader.GetInt("order");
            rule.Description = reader.GetString("rule_description");

            rule.ProductType = (OProductTypes)reader.GetSmallInt("product_type");

            int? loanProductId = reader.GetNullInt("loan_product_id");
            if (loanProductId.HasValue)
                rule.LoanProduct = new LoanProduct { Id = loanProductId.Value };

            int? currencyId = reader.GetNullInt("currency_id");
            if (currencyId.HasValue)
                rule.Currency = new Currency { Id = currencyId.Value };

            int? savingsProductId = reader.GetNullInt("savings_product_id");
            if (savingsProductId.HasValue)
                rule.SavingProduct = new SavingsBookProduct { Id = savingsProductId.Value };

            rule.ClientType = reader.GetChar("client_type").ConvertToClientType();

            int? activityId = reader.GetNullInt("activity_id");

            if (activityId.HasValue)
                rule.EconomicActivity = new EconomicActivity { Id = activityId.Value };

            return rule;
        }
Example #32
0
        private static OCurrency GetValue(LoanEntryFeeEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "fee")
            {
                amount = eventItem.Fee;
            }
            return amount;
        }
Example #33
0
        private void AddContractAccountingRule(ContractAccountingRule rule)
        {
            const string sqlText = @"INSERT INTO
                                       [ContractAccountingRules]
                                         ([id],
                                          [product_type],
                                          [loan_product_id],
                                          [savings_product_id],
                                          [client_type],
                                          [activity_id],
                                          [currency_id])
                                     VALUES
                                        (@id,
                                         @productType,
                                         @loanProductId,
                                         @savingsProductId,
                                         @clientType,
                                         @activityId,
                                         @currency_id)";

            using (SqlConnection conn = GetConnection())
            {
                using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, conn))
                {
                    SetAccountingRule(cmd, rule);
                    cmd.ExecuteNonQuery();
                }
            }
        }
Example #34
0
        private static OCurrency GetValue(LoanDisbursmentEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;
            if (rule.EventAttribute.Name.ToLower() == "amount")
            {
                amount = eventItem.Amount;
            }

            if (rule.EventAttribute.Name.ToLower() == "fees")
            {
                amount = eventItem.Fee;
            }

            if (rule.EventAttribute.Name.ToLower() == "interest")
            {
                amount = eventItem.Interest;
            }
            return amount;
        }
Example #35
0
        private void SetAccountingRule(OpenCbsCommand cmd, ContractAccountingRule rule)
        {
            cmd.AddParam("@id", rule.Id);
            cmd.AddParam("@productType", (int)rule.ProductType);

            if (rule.LoanProduct != null)
                cmd.AddParam("@loanProductId", rule.LoanProduct.Id);
            else
                cmd.AddParam("@loanProductId", null);

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

            if (rule.SavingProduct != null)
                cmd.AddParam("@savingsProductId", rule.SavingProduct.Id);
            else
                cmd.AddParam("@savingsProductId", null);

            if (rule.ClientType == OClientTypes.Corporate)
                cmd.AddParam("@clientType", 'C');
            else if (rule.ClientType == OClientTypes.Group)
                cmd.AddParam("@clientType", 'G');
            else if (rule.ClientType == OClientTypes.Person)
                cmd.AddParam("@clientType", 'I');
            else if (rule.ClientType == OClientTypes.Village)
                cmd.AddParam("@clientType", 'V');
            else
                cmd.AddParam("@clientType", '-');

            if (rule.EconomicActivity != null)
                cmd.AddParam("@activityId", rule.EconomicActivity.Id);
            else
                cmd.AddParam("@activityId", null);
        }
Example #36
0
        private ListViewItem GetListViewItem(ContractAccountingRule rule)
        {
            ListViewItem item = new ListViewItem(rule.EventType.ToString());

            item.SubItems.Add(GetString("EventAttributes", rule.EventAttribute.ToString()));
            item.SubItems.Add(rule.DebitAccount.ToString());
            item.SubItems.Add(rule.CreditAccount.ToString());
            item.SubItems.Add(rule.Order.ToString());
            item.SubItems.Add(rule.Description);
            item.SubItems.Add(MultiLanguageStrings.GetString(Ressource.AccountingRule, rule.ProductType + @".Text") ??
                              rule.ProductType.ToString());
            
            switch (rule.ProductType)
            {
                case OProductTypes.All:
                    item.SubItems.Add(MultiLanguageStrings.GetString(Ressource.AccountingRule, @"All.Text")); break;
                case OProductTypes.Loan:
                    item.SubItems.Add(rule.LoanProduct != null
                                          ? rule.LoanProduct.Name
                                          : MultiLanguageStrings.GetString(Ressource.AccountingRule, @"All.Text"));
                    break;
                case OProductTypes.Saving:
                    item.SubItems.Add(rule.SavingProduct != null
                                          ? rule.SavingProduct.Name
                                          : MultiLanguageStrings.GetString(Ressource.AccountingRule, @"All.Text"));
                    break;
            }

            item.SubItems.Add(MultiLanguageStrings.GetString(Ressource.AccountingRule, rule.ClientType + @".Text") ??
                              rule.ClientType.ToString());

            item.SubItems.Add(rule.EconomicActivity != null
                                  ? rule.EconomicActivity.Name
                                  : MultiLanguageStrings.GetString(Ressource.AccountingRule, @"All.Text"));
            
            item.SubItems.Add(rule.Currency != null
                                  ? rule.Currency.Name
                                  : MultiLanguageStrings.GetString(Ressource.AccountingRule, @"All.Text"));
            item.SubItems.Add(rule.PaymentMethod.Name);
            item.Tag = rule;

            return item;
        }
Example #37
0
 private void UpdateContractAccountingRule(ContractAccountingRule rule)
 {
     const string sqlText = @"UPDATE [ContractAccountingRules]
                              SET [product_type] = @productType,
                                  [loan_product_id] = @loanProductId,
                                  [savings_product_id] = @savingsProductId,
                                  [client_type] = @clientType,
                                  [activity_id] = @activityId,
                                  [currency_id] = @currency_id
                              WHERE id = @id";
     using (SqlConnection conn = GetConnection())
     {
         using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, conn))
         {
             SetAccountingRule(cmd, rule);
             cmd.ExecuteNonQuery();
         }
     }
 }
        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);
        }
Example #39
0
        private static OCurrency GetValue(ProvisionEvent eventItem, ContractAccountingRule rule)
        {
            OCurrency amount = 0;

            if (rule.EventAttribute.Name.ToLower() == "amount")
            {
                amount = eventItem.Amount;
            }
            return amount;
        }
Example #40
0
        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 UpdateContractRule()
        {
            Account genericAccount = _accountManager.Select(1);
            Account specificAccount = _accountManager.Select(2);
            EventType eventType = _eventManager.SelectEventTypeByEventType("RGLE");
            EventAttribute eventAttribute = _eventManager.SelectEventAttributeByCode("principal");

            ContractAccountingRule rule = new ContractAccountingRule
            {
                DebitAccount = genericAccount,
                CreditAccount = specificAccount,
                ProductType = OProductTypes.Loan,
                ClientType = OClientTypes.All,
                BookingDirection = OBookingDirections.Both,
                EventType = eventType,
                EventAttribute = eventAttribute
            };

            rule.Id = _accountingRuleManager.AddAccountingRule(rule);
            Assert.AreNotEqual(0, rule.Id);

            rule.DebitAccount = _accountManager.Select(2);
            rule.CreditAccount = _accountManager.Select(4);
            rule.ProductType = OProductTypes.Saving;
            rule.LoanProduct = null;
            rule.SavingProduct = _savingProductManager.SelectSavingProduct(1);
            rule.ClientType = OClientTypes.Person;
            rule.EconomicActivity = _economicActivityManager.SelectEconomicActivity(1);
            rule.BookingDirection = OBookingDirections.Credit;

            _accountingRuleManager.UpdateAccountingRule(rule);
            ContractAccountingRule retrievedRule = _accountingRuleManager.Select(rule.Id) as ContractAccountingRule;
            _compareRules(rule, retrievedRule);
        }
        public void Test_SaveContractAccountingRule_When_SpecificAccount_Is_Null()
        {
            ContractAccountingRule rule = new ContractAccountingRule
            {
                DebitAccount = new Account { Id = 1, Number = "1150" },
                ClientType = OClientTypes.All,
                ProductType = OProductTypes.All
            };

            try
            {
                _accountingRuleServices.SaveAccountingRule(rule);
                Assert.Fail("Accounting Rule shouldn't pass validation test while trying to save (Generic Account is Null).");
            }
            catch (OpenCbsAccountingRuleException exception)
            {
                Assert.AreEqual(OpenCbsAccountingRuleExceptionEnum.SpecificAccountIsInvalid, exception.Code);
            }
        }
        private void _compareRules(ContractAccountingRule originalRule, ContractAccountingRule retrievedRule)
        {
            Assert.AreEqual(originalRule.Id, retrievedRule.Id);
            Assert.AreEqual(originalRule.DebitAccount.Id, retrievedRule.DebitAccount.Id);
            Assert.AreEqual(originalRule.CreditAccount.Id, retrievedRule.CreditAccount.Id);

            Assert.AreEqual(originalRule.ProductType, retrievedRule.ProductType);
            if (originalRule.LoanProduct != null)
                Assert.AreEqual(originalRule.LoanProduct.Id, retrievedRule.LoanProduct.Id);
            else
                Assert.AreEqual(null, retrievedRule.LoanProduct);
            if (originalRule.SavingProduct != null)
                Assert.AreEqual(originalRule.SavingProduct.Id, retrievedRule.SavingProduct.Id);
            else
                Assert.AreEqual(null, retrievedRule.SavingProduct);
            Assert.AreEqual(originalRule.ClientType, retrievedRule.ClientType);
            if (originalRule.EconomicActivity != null)
                Assert.AreEqual(originalRule.EconomicActivity.Id, retrievedRule.EconomicActivity.Id);
            else
                Assert.AreEqual(null, retrievedRule.EconomicActivity);
        }