/// <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)); } }
public void TestCurrencyAmount() { // test to string CurrencyAmount amount = new CurrencyAmount(123.45); Assert.AreEqual("123.45", amount.ToString()); // test parse amount = CurrencyAmount.Parse("123.45"); Assert.AreEqual("123.45", amount.ToString()); // test add CurrencyAmount amount2 = new CurrencyAmount(543.21); amount = new CurrencyAmount(123.45); Assert.AreEqual("666.66", CurrencyAmount.Add(amount, amount2).ToString()); amount.AddTo(amount2); Assert.AreEqual("666.66", amount.ToString()); // test minus amount2 = new CurrencyAmount(543.21); amount = new CurrencyAmount(123.45); Assert.AreEqual("-419.76", CurrencyAmount.Minus(amount, amount2).ToString()); Assert.AreEqual("419.76", CurrencyAmount.Minus(amount2, amount).ToString()); Assert.AreEqual("0.00", CurrencyAmount.Minus(amount2, amount2).ToString()); // is zero Assert.AreEqual(true, CurrencyAmount.Minus(amount2, amount2).IsZero()); }
/// <summary> /// Get group balance from start month to end month /// </summary> /// <param name="accountGroup"></param> /// <param name="startMonthId"></param> /// <param name="endMonthId"></param> /// <returns></returns> /// <exception cref="SystemException"></exception> public CurrencyAmount GetGroupBalance(GLAccountGroupENUM accountGroup, MonthIdentity startMonthId, MonthIdentity endMonthId) { CurrencyAmount ret = new CurrencyAmount(); MasterDataManagement mdMgmt = this._mdMgmt; foreach (var item in _items) { GLAccountMasterData glAccount; try { glAccount = (GLAccountMasterData)mdMgmt .GetMasterData(item.Key, MasterDataType.GL_ACCOUNT); } catch (Exception e) { _coreDriver.logDebugInfo(this.GetType(), 183, e.Message, MessageType.ERRO); throw new SystemException(e); } if (glAccount.Group.Identity == accountGroup) { ret.AddTo(item.Value.GetSumAmount(startMonthId, endMonthId)); } } return(ret); }
/// <summary> /// get amount /// </summary> /// <param name="monthID"></param> /// <returns></returns> public CurrencyAmount getAmount(MonthIdentity monthID) { CurrencyAmount sum = new CurrencyAmount(); CurrencyAmount amount; if (_amountList.TryGetValue(monthID, out amount)) { sum.AddTo(amount); } return(sum); }
/// <summary> /// Get sum of amount from start month to end month /// </summary> /// <param name="startId">id of start month</param> /// <param name="endId">id of end month</param> /// <returns></returns> public CurrencyAmount GetSumAmount(MonthIdentity startId, MonthIdentity endId) { CurrencyAmount sum = new CurrencyAmount(); foreach (var item in _list) { if (item.Key.CompareTo(startId) >= 0 && item.Key.CompareTo(endId) <= 0) { sum.AddTo(item.Value); } } return sum; }
/// <summary> /// Get sum of amount from start month to end month /// </summary> /// <param name="startId">id of start month</param> /// <param name="endId">id of end month</param> /// <returns></returns> public CurrencyAmount GetSumAmount(MonthIdentity startId, MonthIdentity endId) { CurrencyAmount sum = new CurrencyAmount(); foreach (var item in _list) { if (item.Key.CompareTo(startId) >= 0 && item.Key.CompareTo(endId) <= 0) { sum.AddTo(item.Value); } } return(sum); }
/// <summary> /// Add amount /// </summary> /// <param name="monthId"></param> /// <param name="amount"></param> internal void AddAmount(MonthIdentity monthId, CurrencyAmount amount) { _sum.AddTo(amount); if (_list.ContainsKey(monthId)) { CurrencyAmount sum; _list.TryGetValue(monthId, out sum); sum.AddTo(amount); } else { _list.Add(monthId, new CurrencyAmount(amount)); } }
/// <summary> /// get amount /// </summary> /// <param name="startId">start month identity</param> /// <param name="endId">end month identity</param> /// <returns></returns> public CurrencyAmount getAmount(MonthIdentity startId, MonthIdentity endId) { CurrencyAmount amount = new CurrencyAmount(); List <HeadEntity> docs = this.getEntities(startId, endId); foreach (HeadEntity head in docs) { List <ItemEntity> items = head.Items; foreach (ItemEntity item in items) { amount.AddTo(getAmountFromItem(item)); } } return(amount); }
/// <summary> /// check before document is save /// </summary> /// <exception cref="MandatoryFieldIsMissing"></exception> /// <exception cref="BalanceNotZero"></exception> public void CheckBeforeSave() { // check posting date if (_postingDate == null) { _coreDriver.logDebugInfo(this.GetType(), 478, "Check document before save, posting date is null", MessageType.ERRO); throw new MandatoryFieldIsMissing("Posting Date"); } CurrencyAmount sum = new CurrencyAmount(); foreach (ItemEntity item in _items) { item.CheckMandatory(); if (item.CdIndicator == CreditDebitIndicator.CREDIT) { sum.MinusTo(item.Amount); } else if (item.CdIndicator == CreditDebitIndicator.DEBIT) { sum.AddTo(item.Amount); } } // check balance if (!sum.IsZero()) { _coreDriver.logDebugInfo(this.GetType(), 478, "Check document before save, balance is not zero", MessageType.ERRO); throw new BalanceNotZero(); } _coreDriver.logDebugInfo(this.GetType(), 319, "Check document before save successfully", MessageType.INFO); }
/// <summary> /// Get group balance from start month to end month /// </summary> /// <param name="accountGroup"></param> /// <param name="startMonthId"></param> /// <param name="endMonthId"></param> /// <returns></returns> /// <exception cref="SystemException"></exception> public CurrencyAmount GetGroupBalance(GLAccountGroupENUM accountGroup, MonthIdentity startMonthId, MonthIdentity endMonthId) { CurrencyAmount ret = new CurrencyAmount(); MasterDataManagement mdMgmt = this._mdMgmt; foreach (var item in _items) { GLAccountMasterData glAccount; try { glAccount = (GLAccountMasterData)mdMgmt .GetMasterData(item.Key, MasterDataType.GL_ACCOUNT); } catch (Exception e) { _coreDriver.logDebugInfo(this.GetType(), 183, e.Message, MessageType.ERRO); throw new SystemException(e); } if (glAccount.Group.Identity == accountGroup) { ret.AddTo(item.Value.GetSumAmount(startMonthId, endMonthId)); } } return ret; }
/// <summary> /// set balance data /// </summary> private void setBalanceData() { // int index = MonthSelection.SelectedIndex; MonthItem monthItem = MonthSelection.SelectedItem as MonthItem; if (monthItem == null) { return; } CoreDriver coreDriver = DataCore.GetInstance().BackendCoreDriver; if (coreDriver.IsInitialize == false) { return; } TransactionDataManagement transMgmt = coreDriver.TransMgmt; GLAccountBalanceCollection balCol = transMgmt.AccountBalanceCol; #region revenue CurrencyAmount revenue = new CurrencyAmount(); foreach (GLAccountGroupENUM group in GLAccountGroup.REVENUE_GROUP) { CurrencyAmount cur = balCol .GetGroupBalance(group, monthItem.MonthId, monthItem.MonthId); cur.Negate(); revenue.AddTo(cur); } // set value incomingAmount.Text = revenue.ToString(); #endregion #region cost CurrencyAmount cost = new CurrencyAmount(); foreach (GLAccountGroupENUM group in GLAccountGroup.COST_GROUP) { CurrencyAmount cur = balCol .GetGroupBalance(group, monthItem.MonthId, monthItem.MonthId); cost.AddTo(cur); } // set value this.outgoingAmount.Text = cost.ToString(); #endregion #region balance CurrencyAmount balance = new CurrencyAmount(); foreach (GLAccountGroupENUM group in GLAccountGroup.BALANCE_GROUP) { CurrencyAmount cur = balCol .GetGroupBalance(group); balance.AddTo(cur); } // set value this.balanceAmount.Text = balance.ToString(); #endregion #region liquidity CurrencyAmount liquidity = new CurrencyAmount(); foreach (GLAccountGroupENUM group in GLAccountGroup.Liquidity_GROUP) { CurrencyAmount cur = balCol .GetGroupBalance(group); liquidity.AddTo(cur); } // set value this.liquidityAmount.Text = liquidity.ToString(); #endregion }
/// <summary> /// get amount /// </summary> /// <param name="monthID"></param> /// <returns></returns> public CurrencyAmount getAmount(MonthIdentity monthID) { CurrencyAmount sum = new CurrencyAmount(); CurrencyAmount amount; if (_amountList.TryGetValue(monthID, out amount)) { sum.AddTo(amount); } return sum; }
/// <summary> /// Parse XElement to header /// </summary> /// <param name="coreDriver"></param> /// <param name="management"></param> /// <param name="elem"></param> /// <returns></returns> /// <exception cref="TransactionDataFileFormatException"></exception> public static HeadEntity Parse(CoreDriver coreDriver, MasterDataManagement management, XElement elem) { HeadEntity head = new HeadEntity(coreDriver, management); head._isSaved = true; #region get document number XAttribute docNumStr = elem.Attribute(TransDataUtils.XML_DOC_NUM); if (docNumStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 271, String.Format( "Field {0} is missing in.", TransDataUtils.XML_DOC_NUM), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } try { head._docNumber = new DocumentNumber(docNumStr.Value.ToCharArray()); } catch (Exception) { coreDriver.logDebugInfo(typeof(HeadEntity), 271, String.Format( "Format of field {0} is error.", TransDataUtils.XML_DOC_NUM), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } #endregion #region fiscal year XAttribute yearStr = elem.Attribute(TransDataUtils.XML_YEAR); if (yearStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 283, String.Format( "Field %s is missing in.", TransDataUtils.XML_YEAR), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } int year; if (!Int32.TryParse(yearStr.Value, out year)) { coreDriver.logDebugInfo(typeof(HeadEntity), 271, String.Format( "Format of field {0} is error.", TransDataUtils.XML_YEAR), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } #endregion #region fiscal month XAttribute monthStr = elem.Attribute(TransDataUtils.XML_MONTH); if (monthStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 295, String.Format( "Field %s is missing in.", TransDataUtils.XML_MONTH), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } int month; if (!Int32.TryParse(monthStr.Value, out month)) { coreDriver.logDebugInfo(typeof(HeadEntity), 271, String.Format( "Format of field {0} is error.", TransDataUtils.XML_MONTH), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } #endregion try { head._monthId = new MonthIdentity(year, month); } catch (FiscalMonthRangeException) { coreDriver.logDebugInfo(typeof(HeadEntity), 271, String.Format( "Format of field {0} is error.", TransDataUtils.XML_MONTH), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } catch (FiscalYearRangeException) { coreDriver.logDebugInfo(typeof(HeadEntity), 271, String.Format( "Format of field {0} is error.", TransDataUtils.XML_YEAR), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } // posting date XAttribute dateStr = elem.Attribute(TransDataUtils.XML_DATE); if (dateStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 307, String.Format( "Field %s is missing in.", TransDataUtils.XML_DATE), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } if (!DateTime.TryParse(dateStr.Value, out head._postingDate)) { coreDriver.logDebugInfo(typeof(HeadEntity), 271, String.Format( "Format of field {0} is error.", TransDataUtils.XML_DATE), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } // text XAttribute text = elem.Attribute(TransDataUtils.XML_TEXT); if (text == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 325, String.Format( "Field %s is missing in.", TransDataUtils.XML_TEXT), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } head._docText = text.Value; // document type XAttribute docTypeStr = elem.Attribute(TransDataUtils.XML_DOC_TYPE); if (docTypeStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 325, String.Format( "Field %s is missing in.", TransDataUtils.XML_DOC_TYPE), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } if (docTypeStr.Value.Length != 1 || (docTypeStr.Value[0] != (char)DocumentType.CUSTOMER_INVOICE && docTypeStr.Value[0] != (char)DocumentType.GL && docTypeStr.Value[0] != (char)DocumentType.VENDOR_INVOICE)) { coreDriver.logDebugInfo(typeof(HeadEntity), 271, String.Format( "Format of field {0} is error.", TransDataUtils.XML_DOC_TYPE), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } head._type = (DocumentType)docTypeStr.Value[0]; // is reversed XAttribute isReversedStr = elem .Attribute(TransDataUtils.XML_IS_REVERSED); if (isReversedStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 338, String.Format( "Field %s is missing in.", TransDataUtils.XML_IS_REVERSED), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } if (!bool.TryParse(isReversedStr.Value, out head._isReversed)) { coreDriver.logDebugInfo(typeof(HeadEntity), 271, String.Format( "Format of field {0} is error.", TransDataUtils.XML_IS_REVERSED), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } // parse item foreach (XElement itemElem in elem.Elements(TransDataUtils.XML_ITEM)) { ItemEntity item = ItemEntity.Parse(coreDriver, management, head, itemElem); item._isSaved = true; coreDriver .logDebugInfo( typeof(HeadEntity), 377, String.Format( "Line Item %d appended during parsing document.", item.LineNum), MessageType.INFO); head._items.Add(item); } // addition attributes foreach (XAttribute attr in elem.Attributes()) { head._fields.Add(attr.Name.LocalName, attr.Value); } // remove fields is not additional fields foreach (String str in TransDataUtils.HEAD_XML_TAGS) { head._fields.Remove(str); } // check balance CurrencyAmount sum = new CurrencyAmount(); foreach (ItemEntity item in head._items) { if (item.CdIndicator == CreditDebitIndicator.DEBIT) { sum.AddTo(item.Amount); } else { sum.MinusTo(item.Amount); } } if (sum.IsZero() == false) { throw new TransactionDataFileFormatException("No Balance"); } StringBuilder strBuilder = new StringBuilder( String.Format( "Parse document %s with posting date %s, text %s, type %s, is_reversed %s", head.DocIdentity, head.PstDate, head.DocText, head.DocType, head.IsReversed)); coreDriver.logDebugInfo(typeof(HeadEntity), 377, strBuilder.ToString(), MessageType.INFO); return(head); }
/// <summary> /// get amount /// </summary> /// <param name="startId">start month identity</param> /// <param name="endId">end month identity</param> /// <returns></returns> public CurrencyAmount getAmount(MonthIdentity startId, MonthIdentity endId) { CurrencyAmount amount = new CurrencyAmount(); List<HeadEntity> docs = this.getEntities(startId, endId); foreach (HeadEntity head in docs) { List<ItemEntity> items = head.Items; foreach (ItemEntity item in items) { amount.AddTo(getAmountFromItem(item)); } } return amount; }