Example #1
0
        public async Task TestCreateTransData()
        {
            Assert.IsTrue(_coreDriver.IsInitialize);
            MasterDataCreater.CreateMasterData(_coreDriver);

            DateTime date = DateTime.Parse("2012.07.02");
            // ledger
            await DocumentCreater.CreateVendorDoc(_coreDriver, date);

            await DocumentCreater.CreateCustomerDoc(_coreDriver, date);

            await DocumentCreater.CreateGLDoc(_coreDriver, date);

            await _coreDriver.RestartAsync();

            date = DateTime.Parse("2012.08.02");
            HeadEntity headEntity = await DocumentCreater.CreateVendorDoc(_coreDriver,
                                                                          date);

            _coreDriver.TransMgmt.ReverseDocument(headEntity.DocIdentity);


            TransactionDataChecker.CheckTransactionData(_coreDriver);

            // reload
            await _coreDriver.RestartAsync();

            TransactionDataChecker.CheckTransactionData(_coreDriver);
        }
Example #2
0
        public static async Task <HeadEntity> CreateVendorDoc(CoreDriver coreDriver, DateTime date)
        {
            HeadEntity headEntity = new HeadEntity(coreDriver,
                                                   coreDriver.MdMgmt);

            headEntity.setPostingDate(date);
            headEntity.SetDocumentType(DocumentType.VENDOR_INVOICE);
            headEntity.SetDocText(TestData.TEXT_VENDOR_DOC);

            ItemEntity item1 = headEntity.CreateEntity();
            MasterDataIdentity_GLAccount rec_account = new MasterDataIdentity_GLAccount(
                TestData.GL_ACCOUNT_CASH);

            item1.SetVendor(new MasterDataIdentity(TestData.VENDOR_BUS),
                            rec_account);
            item1.SetAmount(CreditDebitIndicator.CREDIT, TestData.AMOUNT_VENDOR);

            ItemEntity item2 = headEntity.CreateEntity();

            item2.SetGLAccount(new MasterDataIdentity_GLAccount(
                                   TestData.GL_ACCOUNT_COST));
            item2.SetAmount(CreditDebitIndicator.DEBIT, TestData.AMOUNT_VENDOR);
            item2.SetBusinessArea(new MasterDataIdentity(
                                      TestData.BUSINESS_AREA_WORK));

            try
            {
                await headEntity.SaveAsync(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
            return(headEntity);
        }
Example #3
0
        public static async Task <HeadEntity> CreateGLDoc(CoreDriver coreDriver, DateTime date)
        {
            HeadEntity headEntity = new HeadEntity(coreDriver,
                                                   coreDriver.MdMgmt);

            headEntity.setPostingDate(date);
            headEntity.SetDocumentType(DocumentType.GL);
            headEntity.SetDocText(TestData.TEXT_GL_DOC);

            ItemEntity item1 = headEntity.CreateEntity();

            item1.SetGLAccount(new MasterDataIdentity_GLAccount(
                                   TestData.GL_ACCOUNT_BANK));
            item1.SetAmount(CreditDebitIndicator.CREDIT, TestData.AMOUNT_GL);

            ItemEntity item2 = headEntity.CreateEntity();

            item2.SetGLAccount(new MasterDataIdentity_GLAccount(
                                   TestData.GL_ACCOUNT_CASH));
            item2.SetAmount(CreditDebitIndicator.DEBIT, TestData.AMOUNT_GL);
            try
            {
                await headEntity.SaveAsync(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
            return(headEntity);
        }
Example #4
0
 /// <summary>
 /// Raise reverse document event
 /// </summary>
 /// <param name="doc"></param>
 public void ReverseDoc(HeadEntity doc)
 {
     foreach (DocumentReversed d in DocumentReversedHandler.GetInvocationList())
     {
         d(doc);
     }
 }
 /// <summary>
 /// Raise load document event
 /// </summary>
 /// <param name="source"></param>
 /// <param name="doc"></param>
 public void LoadDoc(Object source, HeadEntity doc)
 {
     foreach (DocumentLoad d in DocumentLoadHandler.GetInvocationList())
     {
         d(source, doc);
     }
 }
 /// <summary>
 /// Raise reverse document event
 /// </summary>
 /// <param name="doc"></param>
 public void ReverseDoc(HeadEntity doc)
 {
     foreach (DocumentReversed d in DocumentReversedHandler.GetInvocationList())
     {
         d(doc);
     }
 }
Example #7
0
 /// <summary>
 /// Raise load document event
 /// </summary>
 /// <param name="source"></param>
 /// <param name="doc"></param>
 public void LoadDoc(Object source, HeadEntity doc)
 {
     foreach (DocumentLoad d in DocumentLoadHandler.GetInvocationList())
     {
         d(source, doc);
     }
 }
        protected override void newDoc(HeadEntity head)
        {
            List <ItemEntity> items = head.Items;

            foreach (ItemEntity itemEntity in items)
            {
                MasterDataIdentity id = itemEntity.GLAccount;
                if (id != null)
                {
                    DocumentIndexItem item;
                    if (!_list.TryGetValue(id, out item))
                    {
                        item = new DocumentIndexItemWithBalance(_coreDriver, id,
                                                                MasterDataType.BUSINESS_AREA);
                        _list.Add(id, item);
                    }
                    // add document
                    item.addDoc(head);
                    // add amount
                    CurrencyAmount amount = itemEntity.Amount;
                    if (itemEntity.CdIndicator == CreditDebitIndicator.CREDIT)
                    {
                        amount.Negate();
                    }
                    item.addAmount(head.MonthID, amount);
                }
            }
        }
 protected override void newDoc(HeadEntity head)
 {
     List<ItemEntity> items = head.Items;
     foreach (ItemEntity itemEntity in items)
     {
         MasterDataIdentity id = itemEntity.GLAccount;
         if (id != null)
         {
             DocumentIndexItem item;
             if (!_list.TryGetValue(id, out item))
             {
                 item = new DocumentIndexItemWithBalance(_coreDriver, id,
                         MasterDataType.BUSINESS_AREA);
                 _list.Add(id, item);
             }
             // add document
             item.addDoc(head);
             // add amount
             CurrencyAmount amount = itemEntity.Amount;
             if (itemEntity.CdIndicator == CreditDebitIndicator.CREDIT)
             {
                 amount.Negate();
             }
             item.addAmount(head.MonthID, amount);
         }
     }
 }
        public static async Task<HeadEntity> CreateVendorDoc(CoreDriver coreDriver, DateTime date)
        {
            HeadEntity headEntity = new HeadEntity(coreDriver,
                    coreDriver.MdMgmt);
            headEntity.setPostingDate(date);
            headEntity.SetDocumentType(DocumentType.VENDOR_INVOICE);
            headEntity.SetDocText(TestData.TEXT_VENDOR_DOC);

            ItemEntity item1 = headEntity.CreateEntity();
            MasterDataIdentity_GLAccount rec_account = new MasterDataIdentity_GLAccount(
                    TestData.GL_ACCOUNT_CASH);
            item1.SetVendor(new MasterDataIdentity(TestData.VENDOR_BUS),
                    rec_account);
            item1.SetAmount(CreditDebitIndicator.CREDIT, TestData.AMOUNT_VENDOR);

            ItemEntity item2 = headEntity.CreateEntity();
            item2.SetGLAccount(new MasterDataIdentity_GLAccount(
                    TestData.GL_ACCOUNT_COST));
            item2.SetAmount(CreditDebitIndicator.DEBIT, TestData.AMOUNT_VENDOR);
            item2.SetBusinessArea(new MasterDataIdentity(
                    TestData.BUSINESS_AREA_WORK));

            try
            {
                await headEntity.SaveAsync(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
            return headEntity;
        }
        public static async Task<HeadEntity> CreateGLDoc(CoreDriver coreDriver, DateTime date)
        {
            HeadEntity headEntity = new HeadEntity(coreDriver,
                    coreDriver.MdMgmt);
            headEntity.setPostingDate(date);
            headEntity.SetDocumentType(DocumentType.GL);
            headEntity.SetDocText(TestData.TEXT_GL_DOC);

            ItemEntity item1 = headEntity.CreateEntity();
            item1.SetGLAccount(new MasterDataIdentity_GLAccount(
                    TestData.GL_ACCOUNT_BANK));
            item1.SetAmount(CreditDebitIndicator.CREDIT, TestData.AMOUNT_GL);

            ItemEntity item2 = headEntity.CreateEntity();
            item2.SetGLAccount(new MasterDataIdentity_GLAccount(
                    TestData.GL_ACCOUNT_CASH));
            item2.SetAmount(CreditDebitIndicator.DEBIT, TestData.AMOUNT_GL);
            try
            {
                await headEntity.SaveAsync(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
            return headEntity;
        }
        /// <summary>
        /// reverse document
        /// </summary>
        /// <param name="head"></param>
        protected override void reverseDoc(HeadEntity head)
        {
            List <ItemEntity> items = head.Items;

            foreach (ItemEntity itemEntity in items)
            {
                MasterDataIdentity id = itemEntity.GLAccount;
                if (!_list.ContainsKey(id))
                {
                    continue;
                }
                DocumentIndexItem item;
                if (_list.TryGetValue(id, out item) == false)
                {
                    continue;
                }

                // remove document
                item.removeDoc(head);
                // remove amount
                CurrencyAmount amount = itemEntity.Amount;
                if (itemEntity.CdIndicator == CreditDebitIndicator.DEBIT)
                {
                    amount.Negate();
                }
                item.addAmount(head.MonthID, amount);
            }
        }
        /// <summary>
        /// reverse document
        /// </summary>
        /// <param name="head"></param>
        protected override void reverseDoc(HeadEntity head)
        {
            List<ItemEntity> items = head.Items;

            foreach (ItemEntity itemEntity in items)
            {
                MasterDataIdentity id = itemEntity.GLAccount;
                if (!_list.ContainsKey(id))
                {
                    continue;
                }
                DocumentIndexItem item;
                if (_list.TryGetValue(id, out item) == false)
                {
                    continue;
                }

                // remove document
                item.removeDoc(head);
                // remove amount
                CurrencyAmount amount = itemEntity.Amount;
                if (itemEntity.CdIndicator == CreditDebitIndicator.DEBIT)
                {
                    amount.Negate();
                }
                item.addAmount(head.MonthID, amount);
            }
        }
Example #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="saved"></param>
        /// <exception cref="MandatoryFieldIsMissing"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        public async Task SaveAsync(bool store)
        {
            if (_isSaved)
            {
                return;
            }

            // check before save
            CheckBeforeSave();

            try
            {
                HeadEntity doc = new HeadEntity(_coreDriver,
                                                _coreDriver.MdMgmt);
                doc.SetDocText(_text);
                doc.SetDocumentType(DocumentType.VENDOR_INVOICE);
                doc.setPostingDate(_date);

                // credit item
                ItemEntity creditItem = doc.CreateEntity();
                creditItem.SetAmount(CreditDebitIndicator.CREDIT, _amount);
                creditItem.SetVendor(_vendor, _recAcc);

                // debit item
                ItemEntity debitItem = doc.CreateEntity();
                debitItem.SetAmount(CreditDebitIndicator.DEBIT, _amount);
                debitItem.SetGLAccount(_glAccount);
                debitItem.SetBusinessArea(_businessArea);


                await doc.SaveAsync(store);


                _isSaved = true;
                _doc     = doc;
            }
            catch (ArgumentNullException e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 123, e.ToString(),
                                         MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (MasterDataIdentityNotDefined e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 123, e.ToString(),
                                         MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (BalanceNotZero)
            {
                _coreDriver.logDebugInfo(this.GetType(), 163,
                                         "Balance is not zero", MessageType.ERRO);
            }
        }
        /// <summary>
        /// Add document
        /// </summary>
        /// <param name="head"></param>
        internal override void addDoc(HeadEntity head)
        {
            base.addDoc(head);

            // add the balance items
            List<ItemEntity> items = head.Items;
            foreach (ItemEntity item in items)
            {
                _sum.AddTo(getAmountFromItem(item));
            }
        }
Example #16
0
        /// <summary>
        /// Add document
        /// </summary>
        /// <param name="head"></param>
        internal override void addDoc(HeadEntity head)
        {
            base.addDoc(head);

            // add the balance items
            List <ItemEntity> items = head.Items;

            foreach (ItemEntity item in items)
            {
                _sum.AddTo(getAmountFromItem(item));
            }
        }
        /// <summary>
        /// remove document
        /// </summary>
        /// <param name="head"></param>
        internal override void removeDoc(HeadEntity head)
        {
            base.removeDoc(head);

            // add the balance items
            List<ItemEntity> items = head.Items;
            foreach (ItemEntity item in items)
            {
                CurrencyAmount amount = getAmountFromItem(item);
                amount.Negate();
                _sum.AddTo(amount);
            }
        }
Example #18
0
        /// <summary>
        /// save document
        /// </summary>
        /// <param name="store"></param>
        /// <exception cref="MandatoryFieldIsMissing"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        public async Task SaveAsync(bool store)
        {
            if (_isSaved)
            {
                return;
            }
            CheckBeforeSave();

            try
            {
                HeadEntity doc = new HeadEntity(_coreDriver,
                                                _coreDriver.MdMgmt);
                doc.SetDocText(_text);
                doc.SetDocumentType(DocumentType.CUSTOMER_INVOICE);
                doc.setPostingDate(_date);

                // credit item
                ItemEntity creditItem = doc.CreateEntity();
                creditItem.SetAmount(CreditDebitIndicator.CREDIT, _amount);
                creditItem.SetGLAccount(_glAccount);

                // debit item
                ItemEntity debitItem = doc.CreateEntity();
                debitItem.SetAmount(CreditDebitIndicator.DEBIT, _amount);
                debitItem.SetCustomer(_customer, _recAcc);

                await doc.SaveAsync(store);


                _isSaved = true;
                _doc     = doc;
            }
            catch (ArgumentNullException e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 267,
                                         "Null value not acceptable.", MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (MasterDataIdentityNotDefined e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 267,
                                         "Master data identity is not defined.", MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (BalanceNotZero e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 267,
                                         "Balance is not zero.", MessageType.ERRO);
                throw new SystemException(e);
            }
        }
Example #19
0
        /// <summary>
        /// remove document
        /// </summary>
        /// <param name="head"></param>
        internal override void removeDoc(HeadEntity head)
        {
            base.removeDoc(head);

            // add the balance items
            List <ItemEntity> items = head.Items;

            foreach (ItemEntity item in items)
            {
                CurrencyAmount amount = getAmountFromItem(item);
                amount.Negate();
                _sum.AddTo(amount);
            }
        }
Example #20
0
        public VendorEntry(CoreDriver coreDriver, MasterDataManagement mdMgmt)
        {
            _coreDriver = coreDriver;
            _mdMgmt     = mdMgmt;
            _text       = "";

            _recAcc       = null;
            _glAccount    = null;
            _vendor       = null;
            _amount       = new CurrencyAmount();
            _businessArea = null;

            _doc = null;
        }
        public VendorEntry(CoreDriver coreDriver, MasterDataManagement mdMgmt)
        {
            _coreDriver = coreDriver;
            _mdMgmt = mdMgmt;
            _text = "";

            _recAcc = null;
            _glAccount = null;
            _vendor = null;
            _amount = new CurrencyAmount();
            _businessArea = null;

            _doc = null;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="store"></param>
        /// <exception cref="MandatoryFieldIsMissing"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        public async Task SaveAsync(bool store)
        {
            if (_isSaved)
            {
                return;
            }

            CheckBeforeSave();
            try
            {
                HeadEntity head = new HeadEntity(_coreDriver,
                                                 _coreDriver.MdMgmt);
                head.setPostingDate(_pstDate);
                head.SetDocText(_text);
                head.SetDocumentType(DocumentType.GL);

                ItemEntity srcItem = head.CreateEntity();
                srcItem.SetAmount(CreditDebitIndicator.CREDIT, _amount);
                srcItem.SetGLAccount(_srcAccount);

                ItemEntity dstItem = head.CreateEntity();
                dstItem.SetAmount(CreditDebitIndicator.DEBIT, _amount);
                dstItem.SetGLAccount(_dstAccount);


                await head.SaveAsync(store);


                _isSaved = true;
                _doc     = head;
            }
            catch (ArgumentNullException e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 123, e.ToString(),
                                         MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (MasterDataIdentityNotDefined e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 123, e.ToString(),
                                         MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (BalanceNotZero)
            {
                _coreDriver.logDebugInfo(this.GetType(), 163,
                                         "Balance is not zero", MessageType.ERRO);
            }
        }
        public async Task TestCreateTransWithTemplate()
        {
            Assert.IsTrue(_coreDriver.IsInitialize);
            MasterDataCreater.CreateMasterData(_coreDriver);

            await TemplateCreater.CreateTemplate(_coreDriver, _coreDriver.TmMgmt);

            // create transaction data
            DateTime date = DateTime.Parse("2012.07.02");

            VendorEntry vendor = (VendorEntry)_coreDriver.TmMgmt.GetEntryTemplate(1)
                                 .GenerateEntry();

            vendor.SetValue(EntryTemplate.POSTING_DATE, date);
            await vendor.SaveAsync(true);

            CustomerEntry customer = (CustomerEntry)_coreDriver.TmMgmt.GetEntryTemplate(3)
                                     .GenerateEntry();

            customer.SetValue(EntryTemplate.POSTING_DATE, date);
            customer.SetValue(EntryTemplate.AMOUNT, TestData.AMOUNT_CUSTOMER);
            await customer.SaveAsync(true);

            GLAccountEntry glEntry = (GLAccountEntry)_coreDriver.TmMgmt.GetEntryTemplate(2)
                                     .GenerateEntry();

            glEntry.SetValue(EntryTemplate.POSTING_DATE, date);
            glEntry.SetValue(EntryTemplate.AMOUNT, TestData.AMOUNT_GL);
            await glEntry.SaveAsync(true);

            TransactionDataManagement transManagement = _coreDriver.TransMgmt;

            // month 08
            date = DateTime.Parse("2012.08.02");
            HeadEntity headEntity = await DocumentCreater.CreateVendorDoc(_coreDriver,
                                                                          date);

            DocumentIdentity docId = headEntity.DocIdentity;

            transManagement.ReverseDocument(docId);

            // check
            TransactionDataChecker.CheckTransactionData(_coreDriver);

            // reload
            await _coreDriver.RestartAsync();

            TransactionDataChecker.CheckTransactionData(_coreDriver);
        }
Example #24
0
    protected virtual void Awake()
    {
        Health       = maxHealth;
        IsDead       = false;
        scoreTracker = GetComponent <PlayerScoreTracker>();
        nStoredDate  = NetworkStoredData.instance;

        if (headPlacement != null)
        {
            GameObject go = new GameObject("Head Collider");
            go.transform.position = transform.position;
            HeadEntity newHead = go.AddComponent <HeadEntity>();
            newHead.SetUp(headPlacement, transform, this);
        }
    }
Example #25
0
        public void CopyProperties(IInvoice other)
        {
            other.CheckArgument(nameof(other));
            other.InvoiceHead.CheckArgument(nameof(other));
            other.InvoicePositions.CheckArgument(nameof(other));

            HeadEntity.CopyProperties(other.InvoiceHead);
            PositionEntities.Clear();
            foreach (var item in other.InvoicePositions)
            {
                var pos = new InvoicePosition();

                pos.CopyProperties(item);
                PositionEntities.Add(pos);
            }
        }
Example #26
0
        /// <summary>
        /// parse to vendor entry
        /// </summary>
        /// <param name="head"></param>
        /// <returns>return null if parse error</returns>
        public static VendorEntry Parse(HeadEntity head)
        {
            // check
            if (head.DocType != DocumentType.VENDOR_INVOICE)
            {
                return(null);
            }
            List <ItemEntity> items = head.Items;

            if (items.Count != 2)
            {
                return(null);
            }
            // credit item
            ItemEntity creditItem = items[0];

            if (creditItem.AccType != AccountType.VENDOR)
            {
                return(null);
            }
            ItemEntity debitItem = items[1];

            if (debitItem.AccType != AccountType.GL_ACCOUNT)
            {
                return(null);
            }

            VendorEntry entry = new VendorEntry(head._coreDriver, head._coreDriver.MdMgmt);

            entry._recAcc       = creditItem.GLAccount;
            entry._vendor       = creditItem.Vendor;
            entry._glAccount    = debitItem.GLAccount;
            entry._businessArea = debitItem.BusinessArea;

            entry._date   = head.PstDate;
            entry._amount = creditItem.Amount;
            if (creditItem.CdIndicator == CreditDebitIndicator.DEBIT)
            {
                // reverse
                entry._amount.Negate();
            }
            entry._text    = head.DocText;
            entry._isSaved = true;
            entry._doc     = head;

            return(entry);
        }
Example #27
0
        /// <summary>
        /// pasrse document to customer entry
        /// </summary>
        /// <param name="head"></param>
        /// <returns>return null, when cannot parse</returns>
        public static CustomerEntry parse(HeadEntity head, MasterDataManagement mdMgmt)
        {
            // check
            if (head.DocType != DocumentType.CUSTOMER_INVOICE)
            {
                return(null);
            }
            List <ItemEntity> items = head.Items;

            if (items.Count != 2)
            {
                return(null);
            }
            // credit item
            ItemEntity creditItem = items[0];

            if (creditItem.AccType != AccountType.GL_ACCOUNT)
            {
                return(null);
            }
            ItemEntity debitItem = items[1];

            if (debitItem.AccType != AccountType.CUSTOMER)
            {
                return(null);
            }

            CustomerEntry entry = new CustomerEntry(head._coreDriver
                                                    , head._coreDriver.MdMgmt);

            entry._glAccount = creditItem.GLAccount;
            entry._recAcc    = debitItem.GLAccount;
            entry._customer  = debitItem.Customer;
            entry._date      = head.PstDate;
            entry._amount    = creditItem.Amount;
            if (creditItem.CdIndicator == CreditDebitIndicator.DEBIT)
            {
                // reverse
                entry._amount.Negate();
            }
            entry._text    = head.DocText;
            entry._isSaved = true;
            entry._doc     = head;

            return(entry);
        }
Example #28
0
        /// <summary>
        /// check customer document
        /// </summary>
        /// <param name="customerDoc"></param>
        private static void checkCustomerDoc(HeadEntity customerDoc)
        {
            // check document number
            Assert.AreEqual(TestData.DOC_NUM2, customerDoc.DocNumber
                            .ToString());
            // check posting date
            Assert.AreEqual(TestData.DATE_2012_07, customerDoc.PstDate.ToString(
                                MasterDataUtils.DATE_FORMAT));
            MonthIdentity monthId = customerDoc.MonthID;

            Assert.AreEqual(TestData.YEAR, monthId.FiscalYear);
            Assert.AreEqual(TestData.MONTH_07, monthId.FiscalMonth);
            // check document type
            Assert.AreEqual(DocumentType.CUSTOMER_INVOICE,
                            customerDoc.DocType);
            // check text
            Assert.AreEqual(TestData.TEXT_CUSTOMER_DOC, customerDoc.DocText);
            // check is reversed
            Assert.AreEqual(false, customerDoc.IsReversed);

            Assert.AreEqual(2, customerDoc.ItemCount);
            List <ItemEntity> items = customerDoc.Items;

            // check revenue item
            Assert.AreEqual(0, items[0].LineNum);
            Assert.AreEqual(AccountType.GL_ACCOUNT, items[0].AccType);
            Assert.AreEqual(CreditDebitIndicator.CREDIT, items[0].CdIndicator);
            Assert.AreEqual(TestData.AMOUNT_CUSTOMER, items[0].Amount);
            Assert.AreEqual(null, items[0].Customer);
            Assert.AreEqual(null, items[0].Vendor);
            Assert.AreEqual(TestData.GL_ACCOUNT_REV, items[0].GLAccount
                            .ToString());
            Assert.AreEqual(null, items[0].BusinessArea);

            // check customer item
            Assert.AreEqual(1, items[1].LineNum);
            Assert.AreEqual(AccountType.CUSTOMER, items[1].AccType);
            Assert.AreEqual(CreditDebitIndicator.DEBIT, items[1].CdIndicator);
            Assert.AreEqual(TestData.AMOUNT_CUSTOMER, items[1].Amount);
            Assert.AreEqual(TestData.CUSTOMER1, items[1].Customer.ToString());
            Assert.AreEqual(null, items[1].Vendor);
            Assert.AreEqual(TestData.GL_ACCOUNT_BANK, items[1].GLAccount
                            .ToString());
            Assert.AreEqual(null, items[1].BusinessArea);
        }
        /// <summary>
        /// Parse from head to entry
        /// </summary>
        /// <param name="head"></param>
        /// <returns>return null if parse error</returns>
        public static GLAccountEntry parse(HeadEntity head)
        {
            // check
            if (head.DocType != DocumentType.GL)
            {
                return(null);
            }
            List <ItemEntity> items = head.Items;

            if (items.Count != 2)
            {
                return(null);
            }
            // credit item
            ItemEntity srcItem = items[0];

            if (srcItem.AccType != AccountType.GL_ACCOUNT)
            {
                return(null);
            }
            ItemEntity dstItem = items[1];

            if (dstItem.AccType != AccountType.GL_ACCOUNT)
            {
                return(null);
            }

            GLAccountEntry entry = new GLAccountEntry(head._coreDriver
                                                      , head._coreDriver.MdMgmt);

            entry._srcAccount = srcItem.GLAccount;
            entry._dstAccount = dstItem.GLAccount;
            entry._pstDate    = head.PstDate;
            entry._amount     = srcItem.Amount;
            if (srcItem.CdIndicator == CreditDebitIndicator.DEBIT)
            {
                // reverse
                entry._amount.Negate();
            }
            entry._text    = head.DocText;
            entry._isSaved = true;
            entry._doc     = head;

            return(entry);
        }
        /// <summary>
        /// reverse document
        /// </summary>
        /// <param name="doc"></param>
        private void reverseDoc(HeadEntity doc)
        {
            foreach (ItemEntity item in doc.DocItems)
            {
                CurrencyAmount amount = item.Amount;
                if (item.CdIndicator == CreditDebitIndicator.DEBIT)
                {
                    amount.Negate();
                }
                GLAccountBalanceItem balItem;
                if (!_items.TryGetValue(item.GLAccount, out balItem))
                {
                    continue;
                }

                balItem.AddAmount(doc.MonthID, amount);
            }
        }
Example #31
0
        /// <summary>
        /// check vendor document
        /// </summary>
        /// <param name="vendorDoc"></param>
        private static void checkVendorDoc(HeadEntity vendorDoc)
        {
            // check document number
            Assert.AreEqual(TestData.DOC_NUM1, vendorDoc.DocNumber
                            .ToString());
            // check posting date
            Assert.AreEqual(TestData.DATE_2012_07, vendorDoc.PstDate.ToString(MasterDataUtils.DATE_FORMAT));
            MonthIdentity monthId = vendorDoc.MonthID;

            Assert.AreEqual(TestData.YEAR, monthId.FiscalYear);
            Assert.AreEqual(TestData.MONTH_07, monthId.FiscalMonth);
            // check document type
            Assert.AreEqual(DocumentType.VENDOR_INVOICE, vendorDoc.DocType);
            // check text
            Assert.AreEqual(TestData.TEXT_VENDOR_DOC, vendorDoc.DocText);
            // check is reversed
            Assert.AreEqual(false, vendorDoc.IsReversed);

            Assert.AreEqual(2, vendorDoc.ItemCount);
            List <ItemEntity> items = vendorDoc.Items;

            // check the vendor item
            Assert.AreEqual(0, items[0].LineNum);
            Assert.AreEqual(AccountType.VENDOR, items[0].AccType);
            Assert.AreEqual(CreditDebitIndicator.CREDIT, items[0].CdIndicator);
            Assert.AreEqual(TestData.AMOUNT_VENDOR, items[0].Amount);
            Assert.AreEqual(null, items[0].Customer);
            Assert.AreEqual(TestData.VENDOR_BUS, items[0].Vendor.ToString());
            Assert.AreEqual(TestData.GL_ACCOUNT_CASH, items[0].GLAccount
                            .ToString());
            Assert.AreEqual(null, items[0].BusinessArea);

            // check cost item
            Assert.AreEqual(1, items[1].LineNum);
            Assert.AreEqual(AccountType.GL_ACCOUNT, items[1].AccType);
            Assert.AreEqual(CreditDebitIndicator.DEBIT, items[1].CdIndicator);
            Assert.AreEqual(TestData.AMOUNT_VENDOR, items[1].Amount);
            Assert.AreEqual(null, items[1].Customer);
            Assert.AreEqual(null, items[1].Vendor);
            Assert.AreEqual(TestData.GL_ACCOUNT_COST, items[1].GLAccount
                            .ToString());
            Assert.AreEqual(TestData.BUSINESS_AREA_WORK, items[1].BusinessArea
                            .ToString());
        }
        /// <summary>
        /// check vendor document
        /// </summary>
        /// <param name="vendorDoc"></param>
        private static void checkVendorDoc(HeadEntity vendorDoc)
        {
            // check document number
            Assert.AreEqual(TestData.DOC_NUM1, vendorDoc.DocNumber
                    .ToString());
            // check posting date
            Assert.AreEqual(TestData.DATE_2012_07, vendorDoc.PstDate.ToString(MasterDataUtils.DATE_FORMAT));
            MonthIdentity monthId = vendorDoc.MonthID;
            Assert.AreEqual(TestData.YEAR, monthId.FiscalYear);
            Assert.AreEqual(TestData.MONTH_07, monthId.FiscalMonth);
            // check document type
            Assert.AreEqual(DocumentType.VENDOR_INVOICE, vendorDoc.DocType);
            // check text
            Assert.AreEqual(TestData.TEXT_VENDOR_DOC, vendorDoc.DocText);
            // check is reversed
            Assert.AreEqual(false, vendorDoc.IsReversed);

            Assert.AreEqual(2, vendorDoc.ItemCount);
            List<ItemEntity> items = vendorDoc.Items;
            // check the vendor item
            Assert.AreEqual(0, items[0].LineNum);
            Assert.AreEqual(AccountType.VENDOR, items[0].AccType);
            Assert.AreEqual(CreditDebitIndicator.CREDIT, items[0].CdIndicator);
            Assert.AreEqual(TestData.AMOUNT_VENDOR, items[0].Amount);
            Assert.AreEqual(null, items[0].Customer);
            Assert.AreEqual(TestData.VENDOR_BUS, items[0].Vendor.ToString());
            Assert.AreEqual(TestData.GL_ACCOUNT_CASH, items[0].GLAccount
                    .ToString());
            Assert.AreEqual(null, items[0].BusinessArea);

            // check cost item
            Assert.AreEqual(1, items[1].LineNum);
            Assert.AreEqual(AccountType.GL_ACCOUNT, items[1].AccType);
            Assert.AreEqual(CreditDebitIndicator.DEBIT, items[1].CdIndicator);
            Assert.AreEqual(TestData.AMOUNT_VENDOR, items[1].Amount);
            Assert.AreEqual(null, items[1].Customer);
            Assert.AreEqual(null, items[1].Vendor);
            Assert.AreEqual(TestData.GL_ACCOUNT_COST, items[1].GLAccount
                    .ToString());
            Assert.AreEqual(TestData.BUSINESS_AREA_WORK, items[1].BusinessArea
                    .ToString());
        }
 /// <summary>
 /// Add document
 /// </summary>
 /// <param name="head"></param>
 internal virtual void addDoc(HeadEntity head)
 {
     _list.Add(head);
     _list.Sort(DocumentIndex.COMPARATOR_DATE);
 }
 /// <summary>
 /// remove document
 /// </summary>
 /// <param name="head"></param>
 internal virtual void removeDoc(HeadEntity head)
 {
     _list.Remove(head);
 }
        /// <summary>
        /// Parse from head to entry
        /// </summary>
        /// <param name="head"></param>
        /// <returns>return null if parse error</returns>
        public static GLAccountEntry parse(HeadEntity head)
        {
            // check
            if (head.DocType != DocumentType.GL)
            {
                return null;
            }
            List<ItemEntity> items = head.Items;
            if (items.Count != 2)
            {
                return null;
            }
            // credit item
            ItemEntity srcItem = items[0];
            if (srcItem.AccType != AccountType.GL_ACCOUNT)
            {
                return null;
            }
            ItemEntity dstItem = items[1];
            if (dstItem.AccType != AccountType.GL_ACCOUNT)
            {
                return null;
            }

            GLAccountEntry entry = new GLAccountEntry(head._coreDriver
                , head._coreDriver.MdMgmt);
            entry._srcAccount = srcItem.GLAccount;
            entry._dstAccount = dstItem.GLAccount;
            entry._pstDate = head.PstDate;
            entry._amount = srcItem.Amount;
            if (srcItem.CdIndicator == CreditDebitIndicator.DEBIT)
            {
                // reverse
                entry._amount.Negate();
            }
            entry._text = head.DocText;
            entry._isSaved = true;
            entry._doc = head;

            return entry;
        }
 /// <summary>
 /// remove document
 /// </summary>
 /// <param name="head"></param>
 internal virtual void removeDoc(HeadEntity head)
 {
     _list.Remove(head);
 }
        /// <summary>
        /// save document
        /// </summary>
        /// <param name="store"></param>
        /// <exception cref="MandatoryFieldIsMissing"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        public async Task SaveAsync(bool store)
        {
            if (_isSaved)
            {
                return;
            }
            CheckBeforeSave();

            try
            {
                HeadEntity doc = new HeadEntity(_coreDriver,
                        _coreDriver.MdMgmt);
                doc.SetDocText(_text);
                doc.SetDocumentType(DocumentType.CUSTOMER_INVOICE);
                doc.setPostingDate(_date);

                // credit item
                ItemEntity creditItem = doc.CreateEntity();
                creditItem.SetAmount(CreditDebitIndicator.CREDIT, _amount);
                creditItem.SetGLAccount(_glAccount);

                // debit item
                ItemEntity debitItem = doc.CreateEntity();
                debitItem.SetAmount(CreditDebitIndicator.DEBIT, _amount);
                debitItem.SetCustomer(_customer, _recAcc);

                await doc.SaveAsync(store);


                _isSaved = true;
                _doc = doc;

            }
            catch (ArgumentNullException e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 267,
                        "Null value not acceptable.", MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (MasterDataIdentityNotDefined e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 267,
                        "Master data identity is not defined.", MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (BalanceNotZero e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 267,
                        "Balance is not zero.", MessageType.ERRO);
                throw new SystemException(e);
            }
        }
Example #38
0
        // reveser document listener

        private void documentReversed(HeadEntity doc)
        {
            reverseDoc(doc);
        }
 private void documentSaved(HeadEntity document)
 {
     newDoc(document);
 }
 /// <summary>
 /// set report when new document
 /// </summary>
 /// <param name="head"></param>
 protected abstract void newDoc(HeadEntity head);
 private void documentLoad(Object source, HeadEntity document)
 {
     newDoc(document);
 }
 private void documentReversed(HeadEntity doc)
 {
     reverseDoc(doc);
 }
        /// <summary>
        /// set report when new doc
        /// </summary>
        /// <param name="head"></param>
        private void newDoc(HeadEntity head)
        {
            foreach (ItemEntity item in head.DocItems)
            {
                CurrencyAmount amount = item.Amount;
                if (item.CdIndicator == CreditDebitIndicator.CREDIT)
                {
                    amount.Negate();
                }
                GLAccountBalanceItem balItem;
                if (!_items.TryGetValue(item.GLAccount, out balItem))
                {
                    continue;
                }

                balItem.AddAmount(head.MonthID, amount);
            }
        }
Example #44
0
 // load document listener
 private void documentLoad(Object source, HeadEntity document)
 {
     newDoc(document);
 }
Example #45
0
 // save document listener
 private void documentSaved(HeadEntity document)
 {
     newDoc(document);
 }
 /// <summary>
 /// Add document
 /// </summary>
 /// <param name="head"></param>
 internal virtual void addDoc(HeadEntity head)
 {
     _list.Add(head);
     _list.Sort(DocumentIndex.COMPARATOR_DATE);
 }
Example #47
0
 protected abstract void reverseDoc(HeadEntity head);
 protected abstract void reverseDoc(HeadEntity head);
Example #49
0
 /// <summary>
 /// set report when new document
 /// </summary>
 /// <param name="head"></param>
 protected abstract void newDoc(HeadEntity head);
        /// <summary>
        /// pasrse document to customer entry
        /// </summary>
        /// <param name="head"></param>
        /// <returns>return null, when cannot parse</returns>
        public static CustomerEntry parse(HeadEntity head, MasterDataManagement mdMgmt)
        {
            // check
            if (head.DocType != DocumentType.CUSTOMER_INVOICE)
            {
                return null;
            }
            List<ItemEntity> items = head.Items;
            if (items.Count != 2)
            {
                return null;
            }
            // credit item
            ItemEntity creditItem = items[0];
            if (creditItem.AccType != AccountType.GL_ACCOUNT)
            {
                return null;
            }
            ItemEntity debitItem = items[1];
            if (debitItem.AccType != AccountType.CUSTOMER)
            {
                return null;
            }

            CustomerEntry entry = new CustomerEntry(head._coreDriver
                , head._coreDriver.MdMgmt);
            entry._glAccount = creditItem.GLAccount;
            entry._recAcc = debitItem.GLAccount;
            entry._customer = debitItem.Customer;
            entry._date = head.PstDate;
            entry._amount = creditItem.Amount;
            if (creditItem.CdIndicator == CreditDebitIndicator.DEBIT)
            {
                // reverse
                entry._amount.Negate();
            }
            entry._text = head.DocText;
            entry._isSaved = true;
            entry._doc = head;

            return entry;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="store"></param>
        /// <exception cref="MandatoryFieldIsMissing"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        public async Task SaveAsync(bool store)
        {
            if (_isSaved)
            {
                return;
            }

            CheckBeforeSave();
            try
            {
                HeadEntity head = new HeadEntity(_coreDriver,
                        _coreDriver.MdMgmt);
                head.setPostingDate(_pstDate);
                head.SetDocText(_text);
                head.SetDocumentType(DocumentType.GL);

                ItemEntity srcItem = head.CreateEntity();
                srcItem.SetAmount(CreditDebitIndicator.CREDIT, _amount);
                srcItem.SetGLAccount(_srcAccount);

                ItemEntity dstItem = head.CreateEntity();
                dstItem.SetAmount(CreditDebitIndicator.DEBIT, _amount);
                dstItem.SetGLAccount(_dstAccount);


                await head.SaveAsync(store);


                _isSaved = true;
                _doc = head;

            }
            catch (ArgumentNullException e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 123, e.ToString(),
                        MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (MasterDataIdentityNotDefined e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 123, e.ToString(),
                        MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (BalanceNotZero)
            {
                _coreDriver.logDebugInfo(this.GetType(), 163,
                        "Balance is not zero", MessageType.ERRO);
            }

        }
 /// <summary>
 /// Add new entity
 /// </summary>
 /// <param name="head"></param>
 internal void Add(HeadEntity head)
 {
     DocumentIdentity id = head.DocIdentity;
     _list.Add(id, head);
 }
Example #53
0
        public async Task TestCreateTransDataWithEntry()
        {
            Assert.IsTrue(_coreDriver.IsInitialize);
            MasterDataCreater.CreateMasterData(_coreDriver);

            // month 08, reverse document
            DateTime date = DateTime.Parse("2012.07.02");
            // ledger
            VendorEntry vendorEntry = new VendorEntry(_coreDriver, _coreDriver.MdMgmt);

            vendorEntry.SetValue(EntryTemplate.POSTING_DATE, date);
            vendorEntry.SetValue(EntryTemplate.TEXT, TestData.TEXT_VENDOR_DOC);
            vendorEntry.SetValue(VendorEntry.VENDOR, new MasterDataIdentity(
                                     TestData.VENDOR_BUS));
            vendorEntry.SetValue(VendorEntry.REC_ACC,
                                 new MasterDataIdentity_GLAccount(TestData.GL_ACCOUNT_CASH));
            vendorEntry.SetValue(VendorEntry.GL_ACCOUNT,
                                 new MasterDataIdentity_GLAccount(TestData.GL_ACCOUNT_COST));
            vendorEntry.SetValue(VendorEntry.BUSINESS_AREA, new MasterDataIdentity(
                                     TestData.BUSINESS_AREA_WORK));
            vendorEntry.SetValue(EntryTemplate.AMOUNT, TestData.AMOUNT_VENDOR);
            await vendorEntry.SaveAsync(true);

            // customer
            CustomerEntry customerEntry = new CustomerEntry(_coreDriver, _coreDriver.MdMgmt);

            customerEntry.SetValue(EntryTemplate.POSTING_DATE, date);
            customerEntry.SetValue(EntryTemplate.TEXT, TestData.TEXT_CUSTOMER_DOC);
            customerEntry.SetValue(CustomerEntry.CUSTOMER, new MasterDataIdentity(
                                       TestData.CUSTOMER1));
            customerEntry.SetValue(CustomerEntry.REC_ACC,
                                   new MasterDataIdentity_GLAccount(TestData.GL_ACCOUNT_BANK));
            customerEntry.SetValue(CustomerEntry.GL_ACCOUNT,
                                   new MasterDataIdentity_GLAccount(TestData.GL_ACCOUNT_REV));
            customerEntry.SetValue(EntryTemplate.AMOUNT, TestData.AMOUNT_CUSTOMER);
            await customerEntry.SaveAsync(true);

            // GL
            GLAccountEntry glAccEntry = new GLAccountEntry(_coreDriver, _coreDriver.MdMgmt);

            glAccEntry.SetValue(EntryTemplate.POSTING_DATE, date);
            glAccEntry.SetValue(EntryTemplate.TEXT, TestData.TEXT_GL_DOC);
            glAccEntry.SetValue(GLAccountEntry.SRC_ACCOUNT,
                                new MasterDataIdentity_GLAccount(TestData.GL_ACCOUNT_BANK));
            glAccEntry.SetValue(GLAccountEntry.DST_ACCOUNT,
                                new MasterDataIdentity_GLAccount(TestData.GL_ACCOUNT_CASH));
            glAccEntry.SetValue(EntryTemplate.AMOUNT, TestData.AMOUNT_GL);
            await glAccEntry.SaveAsync(true);

            TransactionDataManagement transManagement = _coreDriver.TransMgmt;

            date = DateTime.Parse("2012.08.02");
            HeadEntity headEntity = await DocumentCreater.CreateVendorDoc(_coreDriver,
                                                                          date);

            DocumentIdentity docId = headEntity.DocIdentity;

            transManagement.ReverseDocument(docId);

            // check
            TransactionDataChecker.CheckTransactionData(_coreDriver);

            // reload
            await _coreDriver.RestartAsync();

            TransactionDataChecker.CheckTransactionData(_coreDriver);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="saved"></param>
        /// <exception cref="MandatoryFieldIsMissing"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        public async Task SaveAsync(bool store)
        {
            if (_isSaved)
            {
                return;
            }

            // check before save
            CheckBeforeSave();

            try
            {
                HeadEntity doc = new HeadEntity(_coreDriver,
                        _coreDriver.MdMgmt);
                doc.SetDocText(_text);
                doc.SetDocumentType(DocumentType.VENDOR_INVOICE);
                doc.setPostingDate(_date);

                // credit item
                ItemEntity creditItem = doc.CreateEntity();
                creditItem.SetAmount(CreditDebitIndicator.CREDIT, _amount);
                creditItem.SetVendor(_vendor, _recAcc);

                // debit item
                ItemEntity debitItem = doc.CreateEntity();
                debitItem.SetAmount(CreditDebitIndicator.DEBIT, _amount);
                debitItem.SetGLAccount(_glAccount);
                debitItem.SetBusinessArea(_businessArea);


                await doc.SaveAsync(store);


                _isSaved = true;
                _doc = doc;

            }
            catch (ArgumentNullException e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 123, e.ToString(),
                        MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (MasterDataIdentityNotDefined e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 123, e.ToString(),
                        MessageType.ERRO);
                throw new SystemException(e);
            }
            catch (BalanceNotZero)
            {
                _coreDriver.logDebugInfo(this.GetType(), 163,
                        "Balance is not zero", MessageType.ERRO);
            }
        }
 internal CostDocumentAdapterItem(HeadEntity head, string name, 
     DocumentsAdapter parent)
     : base(head.DocIdentity, name, parent)
 {
     _head = head;
 }
        /// <summary>
        /// parse to vendor entry
        /// </summary>
        /// <param name="head"></param>
        /// <returns>return null if parse error</returns>
        public static VendorEntry Parse(HeadEntity head)
        {
            // check
            if (head.DocType != DocumentType.VENDOR_INVOICE)
            {
                return null;
            }
            List<ItemEntity> items = head.Items;
            if (items.Count != 2)
            {
                return null;
            }
            // credit item
            ItemEntity creditItem = items[0];
            if (creditItem.AccType != AccountType.VENDOR)
            {
                return null;
            }
            ItemEntity debitItem = items[1];
            if (debitItem.AccType != AccountType.GL_ACCOUNT)
            {
                return null;
            }

            VendorEntry entry = new VendorEntry(head._coreDriver, head._coreDriver.MdMgmt);
            entry._recAcc = creditItem.GLAccount;
            entry._vendor = creditItem.Vendor;
            entry._glAccount = debitItem.GLAccount;
            entry._businessArea = debitItem.BusinessArea;

            entry._date = head.PstDate;
            entry._amount = creditItem.Amount;
            if (creditItem.CdIndicator == CreditDebitIndicator.DEBIT)
            {
                // reverse
                entry._amount.Negate();
            }
            entry._text = head.DocText;
            entry._isSaved = true;
            entry._doc = head;

            return entry;
        }
Example #57
0
 internal CostDocumentAdapterItem(HeadEntity head, string name,
                                  DocumentsAdapter parent)
     : base(head.DocIdentity, name, parent)
 {
     _head = head;
 }
        /// <summary>
        /// check customer document
        /// </summary>
        /// <param name="customerDoc"></param>
        private static void checkCustomerDoc(HeadEntity customerDoc)
        {
            // check document number
            Assert.AreEqual(TestData.DOC_NUM2, customerDoc.DocNumber
                    .ToString());
            // check posting date
            Assert.AreEqual(TestData.DATE_2012_07, customerDoc.PstDate.ToString(
                MasterDataUtils.DATE_FORMAT));
            MonthIdentity monthId = customerDoc.MonthID;
            Assert.AreEqual(TestData.YEAR, monthId.FiscalYear);
            Assert.AreEqual(TestData.MONTH_07, monthId.FiscalMonth);
            // check document type
            Assert.AreEqual(DocumentType.CUSTOMER_INVOICE,
                    customerDoc.DocType);
            // check text
            Assert.AreEqual(TestData.TEXT_CUSTOMER_DOC, customerDoc.DocText);
            // check is reversed
            Assert.AreEqual(false, customerDoc.IsReversed);

            Assert.AreEqual(2, customerDoc.ItemCount);
            List<ItemEntity> items = customerDoc.Items;
            // check revenue item
            Assert.AreEqual(0, items[0].LineNum);
            Assert.AreEqual(AccountType.GL_ACCOUNT, items[0].AccType);
            Assert.AreEqual(CreditDebitIndicator.CREDIT, items[0].CdIndicator);
            Assert.AreEqual(TestData.AMOUNT_CUSTOMER, items[0].Amount);
            Assert.AreEqual(null, items[0].Customer);
            Assert.AreEqual(null, items[0].Vendor);
            Assert.AreEqual(TestData.GL_ACCOUNT_REV, items[0].GLAccount
                    .ToString());
            Assert.AreEqual(null, items[0].BusinessArea);

            // check customer item
            Assert.AreEqual(1, items[1].LineNum);
            Assert.AreEqual(AccountType.CUSTOMER, items[1].AccType);
            Assert.AreEqual(CreditDebitIndicator.DEBIT, items[1].CdIndicator);
            Assert.AreEqual(TestData.AMOUNT_CUSTOMER, items[1].Amount);
            Assert.AreEqual(TestData.CUSTOMER1, items[1].Customer.ToString());
            Assert.AreEqual(null, items[1].Vendor);
            Assert.AreEqual(TestData.GL_ACCOUNT_BANK, items[1].GLAccount
                    .ToString());
            Assert.AreEqual(null, items[1].BusinessArea);
        }
        /// <summary>
        /// save document
        /// </summary>
        /// <param name="head"></param>
        /// <param name="needStroe"></param>
        /// <exception cref="SystemException"></exception>
        /// <exception cref="SaveClosedLedgerException"></exception>
        internal async Task saveDocumentAsync(HeadEntity head, bool needStroe)
        {
            _coreDriver.logDebugInfo(this.GetType(), 231,
                    "Call transaction to save the document", MessageType.INFO);

            if (head.IsSaved)
            {
                _coreDriver.logDebugInfo(this.GetType(), 235,
                        "Document is saved, just to store the update on disk.",
                        MessageType.INFO);
            }
            else
            {
                _coreDriver.logDebugInfo(this.GetType(), 239,
                        "Document is never saved", MessageType.INFO);

                MonthIdentity monthId = head.MonthID;
                MonthLedger ledger = this.GetLedger(monthId);
                if (ledger == null)
                {
                    _coreDriver.logDebugInfo(this.GetType(), 239,
                            "Error in document month identity", MessageType.ERRO);
                    throw new SaveClosedLedgerException();
                }

                // set document number
                DocumentNumber num;
                List<HeadEntity> entities = ledger.Entities;
                if (entities.Count == 0)
                {
                    try
                    {
                        num = new DocumentNumber("1000000001".ToCharArray());
                    }
                    catch (IdentityTooLong e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                    catch (IdentityNoData e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                    catch (IdentityInvalidChar e)
                    {
                        _coreDriver.logDebugInfo(this.GetType(), 239,
                                e.ToString(), MessageType.ERRO);
                        throw new SystemException(e);
                    }
                }
                else
                {
                    HeadEntity last = entities[entities.Count - 1];
                    num = last.DocNumber.Next();
                }
                _coreDriver.logDebugInfo(this.GetType(), 239,
                        "Generate document number " + num.ToString(),
                        MessageType.INFO);
                head._docNumber = num;

                ledger.Add(head);
            }

            if (needStroe)
            {
                await StoreAsync(head.MonthID);
                _coreDriver.logDebugInfo(this.GetType(), 465,
                        "Memory has been stored to disk", MessageType.INFO);
            }
            else
            {
                _coreDriver.logDebugInfo(this.GetType(), 465,
                        "Memory has NOT been stored to disk", MessageType.INFO);
            }

            _coreDriver.logDebugInfo(this.GetType(), 278,
                    "Call transaction to save the document successfully",
                    MessageType.INFO);
        }