/// <summary> /// get value /// </summary> /// <param name="fieldName"></param> /// <returns></returns> /// <exception cref="NoFieldNameException"></exception> public Object GetValue(String fieldName) { if (fieldName.Equals(CUSTOMER)) { return(_customer); } else if (fieldName.Equals(GL_ACCOUNT)) { return(_glAccount); } else if (fieldName.Equals(REC_ACC)) { return(_recAcc); } else if (fieldName.Equals(EntryTemplate.POSTING_DATE)) { return(_date); } else if (fieldName.Equals(EntryTemplate.AMOUNT)) { if (_amount == null || _amount.IsZero()) { return(null); } return(new CurrencyAmount(_amount)); } else if (fieldName.Equals(EntryTemplate.TEXT)) { return(_text); } throw new NoFieldNameException(fieldName); }
/// <summary> /// check wether mandatory fields is empty /// </summary> /// <exception cref="MandatoryFieldIsMissing"></exception> public void CheckMandatory() { // check account if (_type == AccountType.GL_ACCOUNT) { if (!(_glAccount != null && _customer == null && _vendor == null)) { _coreDriver .logDebugInfo( this.GetType(), 319, "Check line item before save, account error when account type is G/L account.", MessageType.ERRO); throw new MandatoryFieldIsMissing("G/L Account"); } } else if (_type == AccountType.CUSTOMER) { if (!(_glAccount != null && _customer != null && _vendor == null)) { _coreDriver .logDebugInfo( this.GetType(), 319, "Check line item before save, account error when account type is customer.", MessageType.ERRO); throw new MandatoryFieldIsMissing("Customer"); } } else { if (!(_glAccount != null && _customer == null && _vendor != null)) { _coreDriver .logDebugInfo( this.GetType(), 319, "Check line item before save, account error when account type is vendor.", MessageType.ERRO); throw new MandatoryFieldIsMissing("Vendor"); } } if (_amount.IsZero() || _amount.IsNegative()) { _coreDriver.logDebugInfo(this.GetType(), 319, "Check line item before save, amount <= 0.", MessageType.ERRO); throw new MandatoryFieldIsMissing("Amount"); } _coreDriver.logDebugInfo(this.GetType(), 319, String.Format( "Check line item %d before save successfully", _lineNum), MessageType.INFO); }
/// <summary> /// Check the document entry before saving /// </summary> /// <exception cref="MandatoryFieldIsMissing"></exception> public void CheckBeforeSave() { if (_srcAccount == null) { throw new MandatoryFieldIsMissing(SRC_ACCOUNT); } if (_dstAccount == null) { throw new MandatoryFieldIsMissing(DST_ACCOUNT); } if (_amount.IsNegative() || _amount.IsZero()) { throw new MandatoryFieldIsMissing(EntryTemplate.AMOUNT); } if (_pstDate == null) { throw new MandatoryFieldIsMissing(EntryTemplate.POSTING_DATE); } }
/// <summary> /// /// </summary> /// <param name="fieldName"></param> /// <returns></returns> /// <exception cref="NoFieldNameException"> no such field name</exception> public Object GetValue(String fieldName) { if (fieldName.Equals(VENDOR)) { return(_vendor); } else if (fieldName.Equals(GL_ACCOUNT)) { return(_glAccount); } else if (fieldName.Equals(REC_ACC)) { return(_recAcc); } else if (fieldName.Equals(EntryTemplate.POSTING_DATE)) { return(_date); } else if (fieldName.Equals(EntryTemplate.AMOUNT)) { if (_amount == null || _amount.IsZero()) { return(null); } return(new CurrencyAmount(_amount)); } else if (fieldName.Equals(EntryTemplate.TEXT)) { return(_text); } else if (fieldName.Equals(BUSINESS_AREA)) { return(_businessArea); } throw new NoFieldNameException(fieldName); }
/// <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> /// Set value /// </summary> /// <param name="fieldName"></param> /// <param name="value"></param> /// <exception cref="NoFieldNameException"></exception> /// <exception cref="NotInValueRangeException"></exception> public void SetValue(String fieldName, Object value) { if (_isSaved) { return; } if (value == null) { throw new NotInValueRangeException(fieldName, ""); } if (fieldName.Equals(CUSTOMER)) { MasterDataIdentity customer = value as MasterDataIdentity; if (customer == null) { throw new NotInValueRangeException(fieldName, value); } setCustomer(customer); } else if (fieldName.Equals(GL_ACCOUNT)) { MasterDataIdentity_GLAccount glAccount = value as MasterDataIdentity_GLAccount; if (glAccount == null) { throw new NotInValueRangeException(fieldName, value); } setGLAccount(glAccount); } else if (fieldName.Equals(REC_ACC)) { MasterDataIdentity_GLAccount recAcc = value as MasterDataIdentity_GLAccount; if (recAcc == null) { throw new NotInValueRangeException(fieldName, value); } setRecAccount(recAcc); } else if (fieldName.Equals(EntryTemplate.POSTING_DATE)) { if (!(value is DateTime)) { throw new NotInValueRangeException(fieldName, value); } DateTime date = (DateTime)value; _date = date; } else if (fieldName.Equals(EntryTemplate.AMOUNT)) { try { CurrencyAmount amount = CurrencyAmount.Parse(value.ToString()); if (amount.IsZero() || amount.IsNegative()) { throw new NotInValueRangeException(fieldName, value); } _amount = amount; } catch (CurrencyAmountFormatException) { throw new NotInValueRangeException(fieldName, value); } } else if (fieldName.Equals(EntryTemplate.TEXT)) { _text = value.ToString(); } else { throw new NoFieldNameException(fieldName); } }
/// <summary> /// set value /// </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> public void SetValue(String fieldName, Object value) { if (_isSaved) { return; } if (value == null) { throw new NotInValueRangeException(fieldName, ""); } if (fieldName.Equals(DST_ACCOUNT)) { if (!(value is MasterDataIdentity_GLAccount)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity_GLAccount id = (MasterDataIdentity_GLAccount)value; setDstAccount(id); } else if (fieldName.Equals(SRC_ACCOUNT)) { if (!(value is MasterDataIdentity_GLAccount)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity_GLAccount id = (MasterDataIdentity_GLAccount)value; setSourceAccount(id); } else if (fieldName.Equals(EntryTemplate.TEXT)) { _text = value.ToString(); } else if (fieldName.Equals(EntryTemplate.AMOUNT)) { try { CurrencyAmount amount = CurrencyAmount.Parse(value.ToString()); if (amount.IsZero() || amount.IsNegative()) { throw new NotInValueRangeException(fieldName, value); } _amount = amount; } catch (CurrencyAmountFormatException) { throw new NotInValueRangeException(fieldName, value); } } else if (fieldName.Equals(EntryTemplate.POSTING_DATE)) { if (!(value is DateTime)) { throw new NotInValueRangeException(fieldName, value); } DateTime pstDate = (DateTime)value; _pstDate = pstDate; } else { throw new NoFieldNameException(fieldName); } }
/// <summary> /// set value /// </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> public void SetValue(String fieldName, Object value) { if (_isSaved) { return; } if (value == null) { throw new NotInValueRangeException(fieldName, ""); } if (fieldName.Equals(VENDOR)) { if (!(value is MasterDataIdentity)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity vendor = (MasterDataIdentity)value; setVendor(vendor); } else if (fieldName.Equals(GL_ACCOUNT)) { if (!(value is MasterDataIdentity_GLAccount)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity_GLAccount glAccount = (MasterDataIdentity_GLAccount)value; setGLAccount(glAccount); } else if (fieldName.Equals(REC_ACC)) { if (!(value is MasterDataIdentity_GLAccount)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity_GLAccount recAcc = (MasterDataIdentity_GLAccount)value; setRecAccount(recAcc); } else if (fieldName.Equals(EntryTemplate.POSTING_DATE)) { if (!(value is DateTime)) { throw new NotInValueRangeException(fieldName, value); } DateTime date = (DateTime)value; _date = date; } else if (fieldName.Equals(EntryTemplate.AMOUNT)) { try { CurrencyAmount amount = CurrencyAmount.Parse(value.ToString()); if (amount.IsZero() || amount.IsNegative()) { throw new NotInValueRangeException(fieldName, value); } _amount = amount; } catch (CurrencyAmountFormatException) { throw new NotInValueRangeException(fieldName, value); } } else if (fieldName.Equals(EntryTemplate.TEXT)) { _text = value.ToString(); } else if (fieldName.Equals(BUSINESS_AREA)) { if (!(value is MasterDataIdentity)) { throw new NotInValueRangeException(fieldName, value); } MasterDataIdentity businessArea = (MasterDataIdentity)value; setBusinessArea(businessArea); } else { throw new NoFieldNameException(fieldName); } }
/// <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); }