private void Buildธนาคารจ่ายดอกเบี้ยเงินฝากประจำเดือน1จำนวน1000บาทตัดผ่านระบบ(List <AccountingTransaction> tranEntries)
        {
            var costAcct    = acctList.Where(x => x.Code == "321").Single();
            var liaAcct     = acctList.Where(x => x.Code == "201").Single();
            var newTranCode = "INT-1";
            var entry1      = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = costAcct,
                Entry           = new Entry
                {
                    ID          = 22,
                    Amount      = 1000,
                    Description = "ดอกเบี้ยเงินฝาก",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry2 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = liaAcct,
                Entry           = new Entry
                {
                    ID          = 23,
                    Amount      = 1000,
                    Description = "ดอกเบี้ยเงินฝาก",
                    EntryType   = EntryType.Credit,
                }
            };

            tranEntries.Add(entry1);
            tranEntries.Add(entry2);
        }
        private void Buildลูกค้านำเงินสดมาฝาก100000บาท(List <AccountingTransaction> tranEntries)
        {
            var cashAcct = acctList.Where(x => x.Code == "101").Single();
            var liaAcct  = acctList.Where(x => x.Code == "201").Single();

            var newTranCode = "DEP-1";
            var entry1      = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = cashAcct,
                Entry           = new Entry
                {
                    ID          = 18,
                    Amount      = 100000,
                    Description = "ฝากเงิน",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry2 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = liaAcct,
                Entry           = new Entry
                {
                    ID          = 19,
                    Amount      = 100000,
                    Description = "ฝากเงิน",
                    EntryType   = EntryType.Credit,
                }
            };

            tranEntries.Add(entry1);
            tranEntries.Add(entry2);
        }
        private void Buildธนาคารปล่อยกู้ให้ลูกค้าจำนวน100000บาทโอนเงินเข้าบัญชีลูกค้า(List <AccountingTransaction> tranEntries)
        {
            var receivableAcct = acctList.Where(x => x.Code == "111").Single();
            var liaAcct        = acctList.Where(x => x.Code == "201").Single();

            var newTranCode = "LON-1";
            var entry1      = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = receivableAcct,
                Entry           = new Entry
                {
                    ID          = 20,
                    Amount      = 100000,
                    Description = "กู้เงิน",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry2 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = liaAcct,
                Entry           = new Entry
                {
                    ID          = 21,
                    Amount      = 100000,
                    Description = "โอนเงินเข้าบัญชี",
                    EntryType   = EntryType.Credit,
                }
            };

            tranEntries.Add(entry1);
            tranEntries.Add(entry2);
        }
        private void Buildซื้อสินค้าเป็นเงินเชื่อ10000บาท(List <AccountingTransaction> tranEntries)
        {
            var goodsAcct = acctList.Where(x => x.Code == "121").Single();
            var liaAcct   = acctList.Where(x => x.Code == "201").Single();

            var newTranCode = "IV-2";
            var entry1      = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = goodsAcct,
                Entry           = new Entry
                {
                    ID          = 5,
                    Amount      = 10000,
                    Description = "ซื้อสินค้า 10 ชิ้น",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry2 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = liaAcct,
                Entry           = new Entry
                {
                    ID          = 6,
                    Amount      = 10000,
                    Description = "กู้ยืมซื้อสินค้า",
                    EntryType   = EntryType.Credit,
                }
            };

            tranEntries.Add(entry1);
            tranEntries.Add(entry2);
        }
 public void WhenTransactionExecutedMoreThenOnceThenExceptionGenerated()
 {
     var tx = new AccountingTransaction("tx1",
         new Account("acc1"),
         new Account("acc2"), 0.0m);
     tx.Execute();
     Assert.Throws<InvalidOperationException>(tx.Execute);
 }
        public void WhenTransactionCreatedThenEventGenerated()
        {
            EntityCreatedEvent<AccountingTransaction> @event = null;
            Container.Resolve<IDomainEventBus>()
                .RegisterThreaded<EntityCreatedEvent<AccountingTransaction>>(e => { @event = e; });

            var tx = new AccountingTransaction("tx1",
                new Account("acc1"),
                new Account("acc2"), 0.0m);
            Assert.IsNotNull(@event);
            Assert.AreEqual(tx, @event.Subject);
        }
        public void TestBookAndUnBook()
        {
            // Actors
            Account               _cash = null, _cashCredit = null;
            OCurrency             cashBalance1 = 0, cashBalance2 = 0;
            OCurrency             cashBalance3 = 0, cashBalance4 = 0;
            Booking               mvt         = null;
            AccountingTransaction movementSet = null;

            // Activites
            chartOfAccounts.Accounts = new List <Account>();
            _cash            = new Account();
            _cash.DebitPlus  = true;
            _cash.Number     = "1011";
            _cash.Balance    = 1000;
            _cash.TypeCode   = "CASH";
            _cash.CurrencyId = 1;

            _cashCredit            = new Account();
            _cashCredit.DebitPlus  = true;
            _cashCredit.Number     = "1031";
            _cashCredit.TypeCode   = "CASH_CREDIT";
            _cashCredit.Balance    = 0;
            _cashCredit.CurrencyId = 1;
            chartOfAccounts.AddAccount(_cash);
            chartOfAccounts.AddAccount(_cashCredit);
            movementSet = new AccountingTransaction();

            // Asertions
            mvt = new Booking(2, _cashCredit, 100, cash, movementSet.Date, new Branch {
                Id = 1
            });
            movementSet.AddBooking(mvt);
            chartOfAccounts.Book(movementSet);
            cashBalance1 = chartOfAccounts.GetAccountByTypeCode("CASH", 1).Balance;
            cashBalance2 = chartOfAccounts.GetAccountByTypeCode("CASH_CREDIT", 1).Balance;
            chartOfAccounts.UnBook(movementSet);
            cashBalance3 = chartOfAccounts.GetAccountByTypeCode("CASH", 1).Balance;
            cashBalance4 = chartOfAccounts.GetAccountByTypeCode("CASH_CREDIT", 1).Balance;

            // Asertions
            Assert.AreEqual(1100m, cashBalance1.Value);
            Assert.AreEqual(-100m, cashBalance2.Value);
            Assert.AreEqual(1000m, cashBalance3.Value);
            Assert.AreEqual(0m, cashBalance4.Value);
        }
        public void TestBook()
        {
            Account cashCredit = new Account();

            cashCredit.DebitPlus  = true;
            cashCredit.Number     = "1031";
            cashCredit.TypeCode   = "CASH_CREDIT";
            cashCredit.Balance    = 0;
            cashCredit.CurrencyId = 1;
            chartOfAccounts.AddAccount(cash);
            chartOfAccounts.AddAccount(cashCredit);
            // OMFS-200
            AccountingTransaction movementSet = new AccountingTransaction();
            Booking mvt = new Booking(2, cashCredit, 100, cash, movementSet.Date, new Branch {
                Id = 1
            });

            movementSet.AddBooking(mvt);
            chartOfAccounts.Book(movementSet);
            Assert.AreEqual(1100m, chartOfAccounts.GetAccountByTypeCode("CASH", 1).Balance.Value);
            Assert.AreEqual(-100m, chartOfAccounts.GetAccountByTypeCode("CASH_CREDIT", 1).Balance.Value);
        }
        public void AddAccoutingTransaction_WithBooking()
        {
            AccountingTransactionManager accountingTransactionManager = (AccountingTransactionManager)container["AccountingTransactionManager"];

            AccountingTransaction accountingTransaction = new AccountingTransaction
            {
                Date = new DateTime(2009, 2, 3),
                User = new User {
                    Id = 1
                }
            };

            accountingTransaction.AddBooking(new Booking
            {
                Number        = 1,
                Amount        = 1000,
                CreditAccount = new Account {
                    Id = 1
                },
                DebitAccount = new Account {
                    Id = 2
                },
                Label = OAccountingLabels.Capital
            });
            accountingTransaction.AddBooking(new Booking
            {
                Number        = 2,
                Amount        = 1000,
                CreditAccount = new Account {
                    Id = 2
                },
                DebitAccount = new Account {
                    Id = 4
                },
                Label = OAccountingLabels.Fees
            });
        }
        public void WhenAccountsCreatedAreCreatedInDatabaseAndTransactionExecutedThenOk()
        {
            OnUow(() =>
                      {
                          var acc1 = new Account("root");
                          var acc2 = new Account("some another");

                          var tx = new AccountingTransaction("tx1", acc1, acc2, 42.0m);
                          tx.Execute();
                      }
                );
        }
        private void BuildOpeningOwnerInvestCash1000(List <AccountingTransaction> tranEntries)
        {
            var cashAcct  = acctList.Where(x => x.Code == "101").Single();
            var bondAcct  = acctList.Where(x => x.Code == "102").Single();
            var ownerAcct = acctList.Where(x => x.Code == "301").Single();

            var newTranCode = "IV-1";
            var entry1      = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = cashAcct,
                Entry           = new Entry
                {
                    ID          = 1,
                    Amount      = 1000,
                    Description = "เจ้าของนำเงินสดมาลงทุน",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry2 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = cashAcct,
                Entry           = new Entry
                {
                    ID          = 2,
                    Amount      = 1000,
                    Description = "ซื้อหุ้น",
                    EntryType   = EntryType.Credit,
                }
            };

            var entry3 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = bondAcct,
                Entry           = new Entry
                {
                    ID          = 3,
                    Amount      = 1000,
                    Description = "ซื้อหุ้น",
                    EntryType   = EntryType.Debit,
                }
            };

            var entry4 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = ownerAcct,
                Entry           = new Entry
                {
                    ID          = 4,
                    Amount      = 1000,
                    Description = "นำเงินสดมาลงทุน",
                    EntryType   = EntryType.Credit,
                }
            };

            tranEntries.Add(entry1);
            tranEntries.Add(entry2);
            tranEntries.Add(entry3);
            tranEntries.Add(entry4);
        }
        private void Buildธนาคารรับชำระเงินจากลูกค้าเงินกู้งวดที่1คิดเป็นเงินต้น8000บาทและดอกเบี้ย2000บาทด้วยเงินสด(List <AccountingTransaction> tranEntries)
        {
            var cashAcct       = acctList.Where(x => x.Code == "101").Single();
            var revAcct        = acctList.Where(x => x.Code == "311").Single();
            var costAcct       = acctList.Where(x => x.Code == "321").Single();
            var receivableAcct = acctList.Where(x => x.Code == "111").Single();
            var newTranCode    = "RELON-1";
            var entry1         = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = cashAcct,
                Entry           = new Entry
                {
                    ID          = 24,
                    Amount      = 10000,
                    Description = "ชำระเงินกู้งวด 1",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry2 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = revAcct,
                Entry           = new Entry
                {
                    ID          = 25,
                    Amount      = 8000,
                    Description = "เงินต้น",
                    EntryType   = EntryType.Credit,
                }
            };
            var entry3 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = revAcct,
                Entry           = new Entry
                {
                    ID          = 26,
                    Amount      = 2000,
                    Description = "ดอกเบี้ย",
                    EntryType   = EntryType.Credit,
                }
            };

            var entry4 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = costAcct,
                Entry           = new Entry
                {
                    ID          = 27,
                    Amount      = 8000,
                    Description = "หักยอดลูกหนี้",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry5 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = receivableAcct,
                Entry           = new Entry
                {
                    ID          = 28,
                    Amount      = 8000,
                    Description = "หักยอดลูกหนี้",
                    EntryType   = EntryType.Credit,
                }
            };

            tranEntries.Add(entry1);
            tranEntries.Add(entry2);
            tranEntries.Add(entry3);
            tranEntries.Add(entry4);
            tranEntries.Add(entry5);
        }
        private void Buildขายสินค้าได้3ชิ้นผ่านระบบออนไลย์รับเงินผ่านบัตรเครดิตมา4600บาท(List <AccountingTransaction> tranEntries)
        {
            var revAcct   = acctList.Where(x => x.Code == "311").Single();
            var recAcct   = acctList.Where(x => x.Code == "111").Single();
            var costAcct  = acctList.Where(x => x.Code == "321").Single();
            var goodsAcct = acctList.Where(x => x.Code == "121").Single();
            var liaAcct   = acctList.Where(x => x.Code == "201").Single();

            var newTranCode = "REV-2";
            var entry1      = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = recAcct,
                Entry           = new Entry
                {
                    ID          = 11,
                    Amount      = 4600,
                    Description = "ขายสินค้า 3 ชิ้น บวก ค่าขนส่ง",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry2 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = revAcct,
                Entry           = new Entry
                {
                    ID          = 12,
                    Amount      = 4500,
                    Description = "ขายสินค้า 3 ชิ้น",
                    EntryType   = EntryType.Credit,
                }
            };
            var entry3 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = revAcct,
                Entry           = new Entry
                {
                    ID          = 13,
                    Amount      = 100,
                    Description = "ค่าขนส่ง",
                    EntryType   = EntryType.Credit,
                }
            };
            var entry4 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = costAcct,
                Entry           = new Entry
                {
                    ID          = 14,
                    Amount      = 3000,
                    Description = "ขายสินค้า 3 ชิ้น",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry5 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = costAcct,
                Entry           = new Entry
                {
                    ID          = 15,
                    Amount      = 100,
                    Description = "ค่าขนส่ง",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry6 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = goodsAcct,
                Entry           = new Entry
                {
                    ID          = 16,
                    Amount      = 3000,
                    Description = "ขายสินค้า 3 ชิ้น",
                    EntryType   = EntryType.Credit,
                }
            };
            var entry7 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = liaAcct,
                Entry           = new Entry
                {
                    ID          = 17,
                    Amount      = 100,
                    Description = "ค่าขนส่ง",
                    EntryType   = EntryType.Credit,
                }
            };

            tranEntries.Add(entry1);
            tranEntries.Add(entry2);
            tranEntries.Add(entry3);
            tranEntries.Add(entry4);
            tranEntries.Add(entry5);
            tranEntries.Add(entry6);
            tranEntries.Add(entry7);
        }
        private void Buildขายสินค้าได้2ชิ้นรับเงินสดมา3000บาท(List <AccountingTransaction> tranEntries)
        {
            var revAcct  = acctList.Where(x => x.Code == "311").Single();
            var cashAcct = acctList.Where(x => x.Code == "101").Single();

            var costAcct  = acctList.Where(x => x.Code == "321").Single();
            var goodsAcct = acctList.Where(x => x.Code == "121").Single();

            var newTranCode = "REV-1";
            // บันทึกการขาย
            var entry1 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = cashAcct,
                Entry           = new Entry
                {
                    ID          = 7,
                    Amount      = 3000,
                    Description = "เงินสดรับ",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry2 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = revAcct,
                Entry           = new Entry
                {
                    ID          = 8,
                    Amount      = 3000,
                    Description = "ขายสินค้าได้ 2 ชิ้น",
                    EntryType   = EntryType.Credit,
                }
            };

            // บันทึกปรับสินค้าคงคลัง
            var entry3 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = costAcct,
                Entry           = new Entry
                {
                    ID          = 9,
                    Amount      = 2000,
                    Description = "ต้นทุนสินค้า 2 ชิ้น",
                    EntryType   = EntryType.Debit,
                }
            };
            var entry4 = new AccountingTransaction
            {
                TransactionCode = newTranCode,
                Account         = goodsAcct,
                Entry           = new Entry
                {
                    ID          = 10,
                    Amount      = 2000,
                    Description = "ต้นทุนสินค้า 2 ชิ้น",
                    EntryType   = EntryType.Credit,
                }
            };

            tranEntries.Add(entry1);
            tranEntries.Add(entry2);
            tranEntries.Add(entry3);
            tranEntries.Add(entry4);
        }
        public void WhenTransactionExecutedOnPairedAccountsThenParametersCalculated()
        {
            var rootAccount = new Account("root");
            var accIncome = rootAccount.CreateSubaccount("income");
            var accOutcome = rootAccount.CreateSubaccount("expences");

            const decimal amount = 77.0m;

            var tx = new AccountingTransaction("tx1",
                accIncome,
                accOutcome,
                amount);
            tx.Execute();

            Assert.AreEqual(0.0m, accIncome.CreditTurnover);
            Assert.AreEqual(amount, accIncome.DebtTurnover);
            Assert.AreEqual(-amount, accIncome.GetBalance());

            Assert.AreEqual(0.0m, accOutcome.DebtTurnover);
            Assert.AreEqual(amount, accOutcome.CreditTurnover);
            Assert.AreEqual(amount, accOutcome.GetBalance());

            Assert.AreEqual(0.0m, rootAccount.GetBalance());
            Assert.AreEqual(2 * amount, rootAccount.GetTurnover());
        }
 public void Save(AccountingTransaction tx)
 {
     _sessionManager.GetActiveSession().Save(tx);
 }