Esempio n. 1
0
 public GncAccount(GncBook book, XElement xml)
     : this(book)
 {
     _name       = xml.ChkElement(GncName.Act("name")).Value;
     _guid       = xml.ChkElement(GncName.Act("id")).Value;
     _parentGuid = xml.ValueOrDefault(GncName.Act("parent"), (string)null);
     _commodity  = book.GetCommodity(GncCommodity.MakeIdentifier(xml.Element(GncName.Act("commodity"))));
     if (_commodity == null && xml.Element(GncName.Act("type"))?.Value == "ROOT")
     {
         _commodity = _book.BaseCurrency;
     }
     string scu = xml.ValueOrDefault(GncName.Act("commodity-scu"), "1");
     _commodityDecimals = scu.Count(c => c == '0');
     if (scu != "1" + new string('0', _commodityDecimals))
     {
         throw new Exception("Could not parse commodity-scu: expected a power of 10.");
     }
     _commodityScu = int.Parse(scu);
     _description  = xml.ValueOrDefault(GncName.Act("description"), (string)null);
 }
Esempio n. 2
0
 public GncTransaction(GncBook book, XElement xml)
     : this(book)
 {
     _guid        = xml.ChkElement(GncName.Trn("id")).Value;
     _datePosted  = DateTimeOffset.Parse(xml.ChkElement(GncName.Trn("date-posted")).ChkElement(GncName.Ts("date")).Value).Date.AssumeUtc();
     _dateEntered = DateTimeOffset.Parse(xml.ChkElement(GncName.Trn("date-entered")).ChkElement(GncName.Ts("date")).Value).UtcDateTime;
     _num         = xml.ValueOrDefault(GncName.Trn("num"), "");
     _description = xml.ChkElement(GncName.Trn("description")).Value;
     _commodity   = _book.GetCommodity(GncCommodity.MakeIdentifier(xml.ChkElement(GncName.Trn("currency"))));
     foreach (var el in xml.ChkElement(GncName.Trn("splits")).Elements(GncName.Trn("split")))
     {
         try
         {
             GncSplit split = new GncSplit(this, el);
             _splits.Add(split.Guid, split);
         }
         catch (Exception e)
         {
             throw new Exception($"Could not read split for transaction: {_datePosted}, descr {_description}, {e.Message} ({_guid})", e);
         }
     }
 }