Пример #1
0
        /************************************************************************/

        #region Constructor (internal)
        /// <summary>
        /// Initializes a new instance of the <see cref="Transaction"/> class.
        /// </summary>
        /// <param name="rootNode">The root node from which to find data for this class.</param>
        /// <param name="owner">The statement that owns this transaction.</param>
        internal Transaction(XmlNode rootNode, CommonStatementBase owner)
        {
            // Null values here indicate programmer error.
            ValidateNull(rootNode, nameof(rootNode));
            ValidateNull(owner, nameof(owner));

            TransType     = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(TransType)))).ToOfxTransactionType();
            DatePosted    = GetDateTimeValue(rootNode, nameof(DatePosted));
            DateInitiated = GetNullableDateTimeValue(rootNode, nameof(DateInitiated));
            DateAvailable = GetNullableDateTimeValue(rootNode, nameof(DateAvailable));
            Amount        = GetDecimalValue(GetNestedNode(rootNode, GetNodeName(nameof(Amount))));

            TransactionId = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(TransactionId))));
            ValidateOfxParseOperation(String.IsNullOrEmpty(TransactionId), "Cannot retreive transaction id");

            CorrectedTransactionId = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(CorrectedTransactionId))));
            CorrectionAction       = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(CorrectionAction)))).ToTransactionCorrectionAction();
            ServerTransactionId    = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(ServerTransactionId))));

            CheckNumber = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(CheckNumber))));
            // the check number may come in left-padded with zeros. Take out left padding.
            while (CheckNumber.StartsWith("0") && CheckNumber.Length > 0)
            {
                CheckNumber = CheckNumber.Remove(0, 1);
            }

            ReferenceNumber = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(ReferenceNumber))));
            Sic             = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(Sic))));
            PayeeId         = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(PayeeId))));

            Name = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(Name))));
            Memo = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(Memo))));

            // This is not strictly spec. Some ofx responses don't have Name b/c they have a Payee
            if (String.IsNullOrEmpty(Name))
            {
                Name = Memo;
            }

            // Get the payee if it exists.
            XmlNode payeeNode = GetNestedNode(rootNode, GetNodeName(nameof(Payee)));

            if (payeeNode != null)
            {
                Payee = new Payee(payeeNode);
            }

            Currency = new CurrencyAggregate(rootNode, owner);

            //Currency = GetNodeValue(GetNestedNode(rootNode, GetNodeName(nameof(Currency))));
            //if (String.IsNullOrEmpty(Currency))
            //{
            //    Currency = GetNodeValue(GetNestedNode(rootNode, "ORIGCURRENCY"));
            //    if (String.IsNullOrEmpty(Currency))
            //    {
            //        Currency = defaultCurrency;
            //    }
            //}

            XmlNode bankToNode = GetNestedNode(rootNode, "BANKACCTTO");
            XmlNode ccToNode   = GetNestedNode(rootNode, "CCACCTTO");

            if (bankToNode != null)
            {
                ToAccount = new BankAccount(bankToNode);
            }
            else if (ccToNode != null)
            {
                ToAccount = new CreditCardAccount(ccToNode);
            }
        }