/// <summary>
        /// Constructor
        /// </summary>
        /// <param name="coreDriver"></param>
        /// <param name="management"></param>
        /// <param name="id"></param>
        /// <param name="descp"></param>
        /// <param name="bankAccount"></param>
        /// <exception cref="ArgumentNullException">Argument is null.</exception>
        /// <exception cref="NoGLAccountGroupException">No such G\L account group exception</exception>
        public GLAccountMasterData(CoreDriver coreDriver,
                MasterDataManagement management, MasterDataIdentity_GLAccount id,
                String descp, MasterDataIdentity bankAccount)
            : base(coreDriver, management, id, descp)
        {
            // check id and get group
            String groupId = id.ToString().Substring(0, 4);
            try
            {
                _group = GLAccountGroup.Parse(groupId);
            }
            catch (GLAccountGroupFormatException)
            {
                throw new NoGLAccountGroupException(groupId);
            }

            if (bankAccount == null)
            {
                _bankAccount = null;
            }
            else
            {
                MasterDataBase bankAccountId = _management.GetMasterData(
                        bankAccount, MasterDataType.BANK_ACCOUNT);
                if (bankAccountId == null)
                {
                    throw new MasterDataIdentityNotDefined(bankAccount,
                            MasterDataType.BANK_ACCOUNT);
                }
                _bankAccount = bankAccountId.GetIdentity();
            }

            // init amount
            _initAmount = new CurrencyAmount();
        }
        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> CreateCustomerDoc(CoreDriver coreDriver, DateTime date)
        {
            HeadEntity headEntity = new HeadEntity(coreDriver,
                    coreDriver.MdMgmt);
            headEntity.setPostingDate(date);
            headEntity.SetDocumentType(DocumentType.CUSTOMER_INVOICE);
            headEntity.SetDocText(TestData.TEXT_CUSTOMER_DOC);

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

            ItemEntity item2 = headEntity.CreateEntity();
            MasterDataIdentity_GLAccount account2 = new MasterDataIdentity_GLAccount(
                    TestData.GL_ACCOUNT_BANK);
            item2.SetCustomer(new MasterDataIdentity(TestData.CUSTOMER1),
                    account2);
            item2.SetAmount(CreditDebitIndicator.DEBIT,
                    TestData.AMOUNT_CUSTOMER);

            try
            {
                await headEntity.SaveAsync(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }

            return headEntity;
        }
        internal GLAccountBalanceItem(MasterDataIdentity_GLAccount glAccount)
        {
            _glAccount = glAccount;
            _list = new Dictionary<MonthIdentity, CurrencyAmount>();
            _sum = new CurrencyAmount();

        }
        private void glAccountInitAmountChanged(MasterDataIdentity_GLAccount glAccountId
            , CurrencyAmount orgAmount, CurrencyAmount newAmount)
        {
            GLAccountBalanceItem item;
            if (!_items.TryGetValue(glAccountId, out item))
            {
                return;
            }

            // ret += newAmount - orgAmount
            item.AddAmount(_coreDriver.StartMonthId
                , CurrencyAmount.Minus(newAmount, orgAmount));
        }
        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>
        /// set dst account
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        /// <exception cref="NoFieldNameException">No such field name</exception>
        /// <exception cref="NotInValueRangeException">The value is not supported</exception>
        private void setDstAccount(MasterDataIdentity_GLAccount dstAccount)
        {
            if (dstAccount == null)
            {
                throw new NotInValueRangeException(DST_ACCOUNT, "");
            }

            List<MasterDataBase> valueSet = this.GetValueSet(DST_ACCOUNT);
            foreach (Object obj in valueSet)
            {
                GLAccountMasterData glAccount = (GLAccountMasterData)obj;
                if (glAccount.GLIdentity.Equals(dstAccount))
                {
                    _dstAccount = dstAccount;
                    return;
                }
            }
            throw new NotInValueRangeException(SRC_ACCOUNT, dstAccount);
        }
        /// <summary>
        /// set gl account
        /// </summary>
        /// <param name="glAccount"></param>
        /// <exception cref="NotInValueRangeException"></exception>
        private void setGLAccount(MasterDataIdentity_GLAccount glAccount)
        {
            if (glAccount == null)
            {
                throw new NotInValueRangeException(GL_ACCOUNT, "");
            }

            List<MasterDataBase> valueSet = this.GetValueSet(GL_ACCOUNT);
            foreach (Object obj in valueSet)
            {
                GLAccountMasterData glAcc = (GLAccountMasterData)obj;
                if (glAcc.GLIdentity.Equals(glAccount))
                {
                    _glAccount = glAccount;
                    return;
                }
            }

            throw new NotInValueRangeException(GL_ACCOUNT, glAccount);
        }
        public static void CheckAccountBalance(CoreDriver coreDriver)
        {
            TransactionDataManagement transMgmt = coreDriver.TransMgmt;
            GLAccountBalanceCollection balCol = transMgmt.AccountBalanceCol;

            MonthIdentity month07 = new MonthIdentity(2012, 7);
            MonthIdentity month08 = new MonthIdentity(2012, 8);

            MasterDataIdentity_GLAccount glAccount2 = new MasterDataIdentity_GLAccount(
                    TestData.GL_ACCOUNT_CASH);
            GLAccountBalanceItem balItem = balCol.GetBalanceItem(glAccount2);
            CurrencyAmount amount2 = new CurrencyAmount(123.45 - 23.45);
            Assert.AreEqual(amount2, balItem.Sum);
            Assert.AreEqual(amount2, balItem.GetAmount(month07));
            Assert.AreEqual(new CurrencyAmount(), balItem.GetAmount(month08));

            Assert.AreEqual(amount2, balCol.GetGroupBalance(GLAccountGroupENUM.CASH));
            Assert.AreEqual(amount2,
                    balCol.GetGroupBalance(GLAccountGroupENUM.CASH, month07, month07));
            Assert.AreEqual(new CurrencyAmount(),
                    balCol.GetGroupBalance(GLAccountGroupENUM.CASH, month08, month08));

            // cost
            Assert.AreEqual(new CurrencyAmount(123.45),
                    balCol.GetGroupBalance(GLAccountGroupENUM.COST_PURE));
            Assert.AreEqual(new CurrencyAmount(123.45), balCol.GetGroupBalance(
                    GLAccountGroupENUM.COST_PURE, month07, month07));
            Assert.AreEqual(new CurrencyAmount(), balCol.GetGroupBalance(
                    GLAccountGroupENUM.COST_PURE, month08, month08));

            // revenue
            Assert.AreEqual(new CurrencyAmount(-543.21),
                    balCol.GetGroupBalance(GLAccountGroupENUM.SALARY));
            Assert.AreEqual(new CurrencyAmount(-543.21),
                    balCol.GetGroupBalance(GLAccountGroupENUM.SALARY, month07, month07));
            Assert.AreEqual(new CurrencyAmount(),
                    balCol.GetGroupBalance(GLAccountGroupENUM.SALARY, month08, month08));
        }
Пример #10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="coreDriver"></param>
        /// <param name="management"></param>
        /// <param name="id"></param>
        /// <param name="descp"></param>
        /// <param name="bankAccount"></param>
        /// <exception cref="ArgumentNullException">Argument is null.</exception>
        /// <exception cref="NoGLAccountGroupException">No such G\L account group exception</exception>
        public GLAccountMasterData(CoreDriver coreDriver,
                                   MasterDataManagement management, MasterDataIdentity_GLAccount id,
                                   String descp, MasterDataIdentity bankAccount)
            : base(coreDriver, management, id, descp)
        {
            // check id and get group
            String groupId = id.ToString().Substring(0, 4);

            try
            {
                _group = GLAccountGroup.Parse(groupId);
            }
            catch (GLAccountGroupFormatException)
            {
                throw new NoGLAccountGroupException(groupId);
            }

            if (bankAccount == null)
            {
                _bankAccount = null;
            }
            else
            {
                MasterDataBase bankAccountId = _management.GetMasterData(
                    bankAccount, MasterDataType.BANK_ACCOUNT);
                if (bankAccountId == null)
                {
                    throw new MasterDataIdentityNotDefined(bankAccount,
                                                           MasterDataType.BANK_ACCOUNT);
                }
                _bankAccount = bankAccountId.GetIdentity();
            }

            // init amount
            _initAmount = new CurrencyAmount();
        }
Пример #11
0
        /// <summary>
        /// set recocciliation account
        /// </summary>
        /// <param name="recAcc"></param>
        /// <exception cref="NotInValueRangeException"></exception>
        private void setRecAccount(MasterDataIdentity_GLAccount recAcc)
        {
            if (recAcc == null)
            {
                throw new NotInValueRangeException(REC_ACC, "");
            }

            List<MasterDataBase> valueSet = this.GetValueSet(REC_ACC);
            foreach (Object obj in valueSet)
            {
                GLAccountMasterData glAccount = (GLAccountMasterData)obj;
                if (glAccount.GLIdentity.Equals(recAcc))
                {
                    _recAcc = recAcc;
                    return;
                }
            }

            throw new NotInValueRangeException(REC_ACC, recAcc);
        }
        /// <summary>
        /// Create new master data
        /// </summary>
        /// <param name="identity"></param>
        /// <param name="descp"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        /// <exception cref="ParametersException">Parameters Exception</exception>
        /// <exception cref="MasterDataIdentityExists">Duplicated master data identity exists </exception>
        /// <exception cref="MasterDataIdentityNotDefined">Master data identity is not defined</exception>
        /// <exception cref="ArgumentNullException">Argument is null</exception>
        /// <exception cref="SystemException">Bug</exception>
        public override MasterDataBase CreateNewMasterDataBase(MasterDataIdentity identity,
                                                               String descp, params Object[] objects)
        {
            // check id is G/L identity
            MasterDataIdentity_GLAccount identity_gl = identity as MasterDataIdentity_GLAccount;

            if (identity_gl == null)
            {
                throw new ParametersException();
            }
            // check duplicated
            if (_list.ContainsKey(identity))
            {
                throw new MasterDataIdentityExists();
            }

            MasterDataIdentity bankAccount = null;

            if (objects.Length == 0 || objects.Length == 1)
            {
            }
            else
            {
                throw new ParametersException(1, objects.Length);
            }

            if (objects.Length == 1)
            {
                // contain bank account
                bankAccount = objects[0] as MasterDataIdentity;
                if (bankAccount == null)
                {
                    throw new ParametersException();
                }
            }

            GLAccountMasterData glAccount;

            try
            {
                glAccount = new GLAccountMasterData(_coreDriver, _management,
                                                    identity_gl, descp, bankAccount);
            }
            catch (ArgumentNullException e)
            {
                throw new SystemException(e);
            }
            catch (NoGLAccountGroupException)
            {
                throw new ParametersException();
            }

            this._containDirtyData = true;
            this._list.Add(identity_gl, glAccount);

            // raise create master data
            _coreDriver.ListenerMgmt.CreateMasterData(this, glAccount);
            _coreDriver.logDebugInfo(this.GetType(), 84,
                                     String.Format("Create G/L account ({0}).", glAccount.Identity.ToString()),
                                     MessageType.INFO);
            return(glAccount);
        }
        /// <summary>
        /// Parse master data from XML
        /// </summary>
        /// <param name="coreDriver"></param>
        /// <param name="elem"></param>
        /// <returns></returns>
        /// <exception cref="MasterDataFileFormatException">Master Data file exception</exception>
        /// <exception cref="ArgumentNullException">Argument is null</exception>
        /// <exception cref="SystemException">Bug</exception>
        public override MasterDataBase ParseMasterData(CoreDriver coreDriver, XElement elem)
        {
            XAttribute id             = elem.Attribute(MasterDataUtils.XML_ID);
            XAttribute descp          = elem.Attribute(MasterDataUtils.XML_DESCP);
            XAttribute bankAccStr     = elem.Attribute(MasterDataUtils.XML_BANK_ACCOUNT);
            XAttribute initAmountAttr = elem.Attribute(MasterDataUtils.XML_INIT_AMOUNT);

            MasterDataIdentity_GLAccount identity;
            MasterDataIdentity           bankAccId = null;

            try
            {
                identity = new MasterDataIdentity_GLAccount(
                    id.Value);

                // bank account
                if (bankAccStr != null)
                {
                    bankAccId = new MasterDataIdentity(
                        bankAccStr.Value);
                }
            }
            catch (Exception e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 150, e.Message, MessageType.ERRO);
                throw new MasterDataFileFormatException(MasterDataType.GL_ACCOUNT);
            }

            CurrencyAmount initAmount = new CurrencyAmount();

            if (initAmountAttr != null)
            {
                try
                {
                    initAmount = CurrencyAmount.Parse(initAmountAttr.Value);
                }
                catch (CurrencyAmountFormatException e)
                {
                    _coreDriver.logDebugInfo(this.GetType(), 150, e.Message, MessageType.ERRO);
                    throw new MasterDataFileFormatException(MasterDataType.GL_ACCOUNT);
                }
            }
            try
            {
                GLAccountMasterData glAccount;
                if (bankAccId == null)
                {
                    glAccount = (GLAccountMasterData)this.CreateNewMasterDataBase(
                        identity, descp.Value);
                }
                else
                {
                    glAccount = (GLAccountMasterData)this.CreateNewMasterDataBase(
                        identity, descp.Value, bankAccId);
                }
                glAccount.setInitAmountInternal(initAmount);
                _coreDriver
                .logDebugInfo(
                    this.GetType(),
                    167,
                    String.Format("Parse G/L account ({0}).",
                                  glAccount.Identity.ToString()), MessageType.INFO);
                return(glAccount);
            }
            catch (Exception e)
            {
                throw new SystemException(e);
            }
        }
        /// <summary>
        /// Parse master data from XML
        /// </summary>
        /// <param name="coreDriver"></param>
        /// <param name="elem"></param>
        /// <returns></returns>
        /// <exception cref="MasterDataFileFormatException">Master Data file exception</exception>
        /// <exception cref="ArgumentNullException">Argument is null</exception>
        /// <exception cref="SystemException">Bug</exception>
        public override MasterDataBase ParseMasterData(CoreDriver coreDriver, XElement elem)
        {
            XAttribute id = elem.Attribute(MasterDataUtils.XML_ID);
            XAttribute descp = elem.Attribute(MasterDataUtils.XML_DESCP);
            XAttribute bankAccStr = elem.Attribute(MasterDataUtils.XML_BANK_ACCOUNT);
            XAttribute initAmountAttr = elem.Attribute(MasterDataUtils.XML_INIT_AMOUNT);

            MasterDataIdentity_GLAccount identity;
            MasterDataIdentity bankAccId = null;
            try
            {
                identity = new MasterDataIdentity_GLAccount(
                        id.Value);

                // bank account
                if (bankAccStr != null)
                {
                    bankAccId = new MasterDataIdentity(
                            bankAccStr.Value);
                }

            }
            catch (Exception e)
            {
                _coreDriver.logDebugInfo(this.GetType(), 150, e.Message, MessageType.ERRO);
                throw new MasterDataFileFormatException(MasterDataType.GL_ACCOUNT);
            }

            CurrencyAmount initAmount = new CurrencyAmount();
            if (initAmountAttr != null)
            {
                try
                {
                    initAmount = CurrencyAmount.Parse(initAmountAttr.Value);
                }
                catch (CurrencyAmountFormatException e)
                {
                    _coreDriver.logDebugInfo(this.GetType(), 150, e.Message, MessageType.ERRO);
                    throw new MasterDataFileFormatException(MasterDataType.GL_ACCOUNT);
                }
            }
            try
            {
                GLAccountMasterData glAccount;
                if (bankAccId == null)
                {
                    glAccount = (GLAccountMasterData)this.CreateNewMasterDataBase(
                            identity, descp.Value);
                }
                else
                {
                    glAccount = (GLAccountMasterData)this.CreateNewMasterDataBase(
                                identity, descp.Value, bankAccId);
                }
                glAccount.setInitAmountInternal(initAmount);
                _coreDriver
                            .logDebugInfo(
                                    this.GetType(),
                                    167,
                                    String.Format("Parse G/L account ({0}).",
                                            glAccount.Identity.ToString()), MessageType.INFO);
                return glAccount;
            }
            catch (Exception e)
            {
                throw new SystemException(e);
            }

        }
 public CostReportItem(MasterDataIdentity_GLAccount id
     , String name, CurrencyAmount amount, CostReportsAdapter parent)
     : base(id, name, parent)
 {
     _amount = amount;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="source"></param>
 /// <param name="glAccountId"></param>
 /// <param name="orgAmount"></param>
 /// <param name="newAmount"></param>
 public void GLAccountInitAmountChanged(Object source, MasterDataIdentity_GLAccount glAccountId,
     CurrencyAmount orgAmount, CurrencyAmount newAmount)
 {
     foreach (GLAccountInitAmountChanged d in 
         GLAccountInitAmountChangedHandler.GetInvocationList())
     {
         d(glAccountId, orgAmount, newAmount);
     }
 }
Пример #17
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="coreDriver"></param>
 /// <param name="management"></param>
 /// <param name="id"></param>
 /// <param name="descp"></param>
 /// <exception cref="ArgumentNullException">argument is null</exception>
 public GLAccountMasterData(CoreDriver coreDriver,
                            MasterDataManagement management, MasterDataIdentity_GLAccount id,
                            String descp)
     : this(coreDriver, management, id, descp, null)
 {
 }
 /// <summary>
 /// get balance item
 /// </summary>
 /// <param name="glAccount"></param>
 /// <returns></returns>
 public GLAccountBalanceItem GetBalanceItem(
         MasterDataIdentity_GLAccount glAccount)
 {
     GLAccountBalanceItem item;
     if (!_items.TryGetValue(glAccount, out item))
     {
         return null;
     }
     return item;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="coreDriver"></param>
 /// <param name="management"></param>
 /// <param name="id"></param>
 /// <param name="descp"></param>
 /// <exception cref="ArgumentNullException">argument is null</exception>
 public GLAccountMasterData(CoreDriver coreDriver,
         MasterDataManagement management, MasterDataIdentity_GLAccount id,
         String descp)
     : this(coreDriver, management, id, descp, null)
 {
 }
Пример #20
0
        public void TestMasterDataIdentity()
        {
            MasterDataIdentity test;
            // test length
            StringBuilder builder = new StringBuilder();
            for (int i = 1; i <= 10; ++i)
            {
                builder.Append('A');
                try
                {
                    test = new MasterDataIdentity(builder.ToString());
                    test.ToString();
                }
                catch (Exception e)
                {
                    Assert.Fail(e.Message);
                }
            }

            // test low case
            test = new MasterDataIdentity("abcdefg");
            Assert.AreEqual(test.ToString(), "000ABCDEFG");


            // test number
            test = new MasterDataIdentity("123456789");
            Assert.AreEqual(test.ToString(), "0123456789");

            // test '_'
            test = new MasterDataIdentity("_123456789");
            Assert.AreEqual(test.ToString(), "_123456789");


            // test equals
            MasterDataIdentity test1 = new MasterDataIdentity("123");
            MasterDataIdentity test2 = new MasterDataIdentity("123");
            Assert.AreEqual(test1, test2);
            Assert.AreEqual(test1.GetHashCode(), test2.GetHashCode());

            // zero length
            try
            {
                test = new MasterDataIdentity("");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when length is zero");
            }
            catch (IdentityNoData)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityNoData should occur when length is zero, but it is other exception");
            }

            // no data
            try
            {
                test = new MasterDataIdentity("00");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when there is no data");
            }
            catch (IdentityNoData)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityNoData should occur when length is zero, but it is other exception");
            }

            // format error
            try
            {
                test = new MasterDataIdentity("a?");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when there is no data");
            }
            catch (IdentityInvalidChar)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityInvalidChar should occur when length is zero, but it is other exception");
            }

            // too long
            try
            {
                test = new MasterDataIdentity("12345678901");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when there is no data");
            }
            catch (IdentityTooLong)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityInvalidChar should occur when length is zero, but it is other exception");
            }

            // identity for gl account
            MasterDataIdentity_GLAccount glAccountTest = new MasterDataIdentity_GLAccount(
                    "113100");
            Assert.AreEqual(glAccountTest.ToString(), "0000113100");


            // identity for gl account
            // format error
            try
            {
                glAccountTest = new MasterDataIdentity_GLAccount("abcd");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when there is no data");
            }
            catch (IdentityInvalidChar)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityInvalidChar should occur when length is zero, but it is other exception");
            }

        }