/************************************************************************/

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

            Id            = new SecurityId(GetNestedNode(rootNode, SecurityId.NodeName));
            HeldInAccount = GetNodeValue(rootNode, nameof(HeldInAccount));
            PositionType  = GetNodeValue(rootNode, nameof(PositionType));
            Units         = GetDecimalValue(rootNode, nameof(Units));
            UnitPrice     = GetDecimalValue(rootNode, nameof(UnitPrice));
            MarketValue   = GetDecimalValue(rootNode, nameof(MarketValue));
            DateAsOf      = GetNullableDateTimeValue(rootNode, nameof(DateAsOf));
            Currency      = new CurrencyAggregate(rootNode, owner);
        }
Beispiel #2
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);
            }
        }