internal void CallbackVER(SieVoucher v) { if (VER != null) { VER(v); } }
private void parseTRANS(SieDataItem di, SieVoucher v) { if (!KONTO.ContainsKey(di.GetString(0))) { KONTO.Add(di.GetString(0), new SieAccount() { Number = di.GetString(0) }); } var objOffset = 0; if (di.RawData.Contains("{")) { objOffset = 1; } var vr = new SieVoucherRow() { Account = KONTO[di.GetString(0)], Objects = di.GetObjects(), Amount = di.GetDecimal(1 + objOffset), RowDate = di.GetDate(2 + objOffset).HasValue ? di.GetDate(2 + objOffset).Value : v.VoucherDate, Text = di.GetString(3 + objOffset), Quantity = di.GetIntNull(4 + objOffset), CreatedBy = di.GetString(5 + objOffset), Token = di.ItemType }; v.Rows.Add(vr); }
private SieVoucher parseVER(SieDataItem di) { if (!di.GetDate(2).HasValue) { Callbacks.CallbackException(new MissingFieldException("Vaoucher date")); } var v = new SieVoucher() { Series = di.GetString(0), Number = di.GetString(1), VoucherDate = di.GetDate(2).HasValue ? di.GetDate(2).Value : new DateTime(), Text = di.GetString(3), CreatedDate = di.GetInt(4), CreatedBy = di.GetString(5), Token = di.ItemType }; return(v); }
private void closeVoucher(SieVoucher v) { //Check sum of rows decimal check = 0; foreach (var r in v.Rows) { check += r.Amount; } if (check != 0) { Callbacks.CallbackException(new SieVoucherMissmatchException(v.Series + "." + v.Number + " Sum is not zero.")); } Callbacks.CallbackVER(v); if (!StreamValues) { VER.Add(v); } }
private bool voucherComparer(SieVoucher vA, SieVoucher vB) { if (vA.Number != vB.Number) { return(false); } if (vA.Series != vB.Series) { return(false); } if (vA.Text != vB.Text) { return(false); } if (vA.Token != vB.Token) { return(false); } if (vA.VoucherDate != vB.VoucherDate) { return(false); } if (vA.Rows.Count != vB.Rows.Count) { return(false); } else { foreach (var rA in vA.Rows) { bool foundIt = true; foreach (var rB in vB.Rows) { if (rA.Account.Number != rB.Account.Number) { foundIt = false; } if (rA.Amount != rB.Amount) { foundIt = false; } if (rA.CreatedBy != rB.CreatedBy) { foundIt = false; } if (rA.RowDate != rB.RowDate) { foundIt = false; } if (rA.Quantity != rB.Quantity) { foundIt = false; } if (!compareObjects(rA.Objects, rB.Objects)) { foundIt = false; } if (foundIt) { break; } } if (foundIt) { return(true); } } } return(true); }
public void ReadDocument(string fileName) { _fileName = fileName; if (ThrowErrors) { Callbacks.SieException += throwCallbackException; } #region Initialize lists FNAMN = new SieCompany(); KONTO = new Dictionary <string, SieAccount>(); DIM = new Dictionary <string, SieDimension>(); OIB = new List <SiePeriodValue>(); OUB = new List <SiePeriodValue>(); PSALDO = new List <SiePeriodValue>(); PBUDGET = new List <SiePeriodValue>(); PROGRAM = new List <string>(); RAR = new Dictionary <int, SieBookingYear>(); IB = new List <SiePeriodValue>(); UB = new List <SiePeriodValue>(); RES = new List <SiePeriodValue>(); VER = new List <SieVoucher>(); ValidationExceptions = new List <Exception>(); InitializeDimensions(); #endregion //Initialize listst SieVoucher curVoucher = null; bool firstLine = true; foreach (var line in File.ReadLines(_fileName, Encoding.GetEncoding(437))) { Callbacks.CallbackLine(line); var di = new SieDataItem(line, this); if (firstLine) { firstLine = false; if (di.ItemType != "#FLAGGA") { Callbacks.CallbackException(new SieInvalidFileException(_fileName)); return; } } if (CRC.Started && di.ItemType != "#KSUMMA") { CRC.AddData(di); } SiePeriodValue pv = null; switch (di.ItemType) { case "#ADRESS": FNAMN.Contact = di.GetString(0); FNAMN.Street = di.GetString(1); FNAMN.ZipCity = di.GetString(2); FNAMN.Phone = di.GetString(3); break; case "#BKOD": FNAMN.SNI = di.GetInt(0); break; case "#BTRANS": if (!IgnoreBTRANS) { parseTRANS(di, curVoucher); } break; case "#DIM": parseDimension(di); break; case "#ENHET": parseENHET(di); break; case "#FLAGGA": FLAGGA = di.GetInt(0); break; case "#FNAMN": FNAMN.Name = di.GetString(0); break; case "#FNR": FNAMN.Code = di.GetString(0); break; case "#FORMAT": FORMAT = di.GetString(0); break; case "#FTYP": FNAMN.OrgType = di.GetString(0); break; case "#GEN": GEN_DATE = di.GetDate(0); GEN_NAMN = di.GetString(1); break; case "#IB": parseIB(di); break; case "#KONTO": parseKONTO(di); break; case "#KSUMMA": if (CRC.Started) { parseKSUMMA(di); } else { CRC.Start(); } break; case "#KTYP": parseKTYP(di); break; case "#KPTYP": KPTYP = di.GetString(0); break; case "#OBJEKT": parseOBJEKT(di); break; case "#OIB": pv = parseOIB_OUB(di); Callbacks.CallbackOIB(pv); if (!StreamValues) { OIB.Add(pv); } break; case "#OUB": pv = parseOIB_OUB(di); Callbacks.CallbackOUB(pv); if (!StreamValues) { OUB.Add(pv); } break; case "#ORGNR": FNAMN.OrgIdentifier = di.GetString(0); break; case "#OMFATTN": OMFATTN = di.GetDate(0); break; case "#PBUDGET": pv = parsePBUDGET_PSALDO(di); if (pv != null) { Callbacks.CallbackPBUDGET(pv); if (!StreamValues) { PBUDGET.Add(pv); } } break; case "#PROGRAM": PROGRAM = di.Data; break; case "#PROSA": PROSA = di.GetString(0); break; case "#PSALDO": pv = parsePBUDGET_PSALDO(di); if (pv != null) { Callbacks.CallbackPSALDO(pv); if (!StreamValues) { PSALDO.Add(pv); } } break; case "#RAR": parseRAR(di); break; case "#RTRANS": if (!IgnoreBTRANS) { parseTRANS(di, curVoucher); } break; case "#SIETYP": SIETYP = di.GetInt(0); break; case "#SRU": parseSRU(di); break; case "#TAXAR": TAXAR = di.GetInt(0); break; case "#UB": parseUB(di); break; case "#TRANS": parseTRANS(di, curVoucher); break; case "#RES": parseRES(di); break; case "#VALUTA": VALUTA = di.GetString(0); break; case "#VER": curVoucher = parseVER(di); break; case "": //Empty line break; case "{": break; case "}": if (curVoucher != null) { closeVoucher(curVoucher); } curVoucher = null; break; default: Callbacks.CallbackException(new NotImplementedException(di.ItemType)); break; } } validateDocument(); }
/// <summary> /// /// </summary> /// <param name="sr"></param> /// <returns>true if start of file is valid SIE-format</returns> private bool parseLines(StreamReader sr) { bool firstLine = true; SieVoucher curVoucher = null; do { var line = sr.ReadLine(); Callbacks.CallbackLine(line); var di = new SieDataItem(line, this); if (firstLine) { firstLine = false; if (di.ItemType != "#FLAGGA") { Callbacks.CallbackException(new SieInvalidFileException(_fileName)); return(true); } } if (CRC.Started && di.ItemType != "#KSUMMA") { CRC.AddData(di); } SiePeriodValue pv = null; switch (di.ItemType) { case "#ADRESS": FNAMN.Contact = di.GetString(0); FNAMN.Street = di.GetString(1); FNAMN.ZipCity = di.GetString(2); FNAMN.Phone = di.GetString(3); break; case "#BKOD": FNAMN.SNI = di.GetInt(0); break; case "#BTRANS": if (!IgnoreBTRANS) { parseTRANS(di, curVoucher); } break; case "#DIM": parseDimension(di); break; case "#ENHET": parseENHET(di); break; case "#FLAGGA": FLAGGA = di.GetInt(0); break; case "#FNAMN": FNAMN.Name = di.GetString(0); break; case "#FNR": FNAMN.Code = di.GetString(0); break; case "#FORMAT": FORMAT = di.GetString(0); break; case "#FTYP": FNAMN.OrgType = di.GetString(0); break; case "#GEN": GEN_DATE = di.GetDate(0); GEN_NAMN = di.GetString(1); break; case "#IB": parseIB(di); break; case "#KONTO": parseKONTO(di); break; case "#KSUMMA": if (CRC.Started) { parseKSUMMA(di); } else { CRC.Start(); } break; case "#KTYP": parseKTYP(di); break; case "#KPTYP": KPTYP = di.GetString(0); break; case "#OBJEKT": parseOBJEKT(di); break; case "#OIB": pv = parseOIB_OUB(di); Callbacks.CallbackOIB(pv); if (!StreamValues) { OIB.Add(pv); } break; case "#OUB": pv = parseOIB_OUB(di); Callbacks.CallbackOUB(pv); if (!StreamValues) { OUB.Add(pv); } break; case "#ORGNR": FNAMN.OrgIdentifier = di.GetString(0); break; case "#OMFATTN": OMFATTN = di.GetDate(0); break; case "#PBUDGET": pv = parsePBUDGET_PSALDO(di); if (pv != null) { Callbacks.CallbackPBUDGET(pv); if (!StreamValues) { PBUDGET.Add(pv); } } break; case "#PROGRAM": PROGRAM = di.Data; break; case "#PROSA": PROSA = di.GetString(0); break; case "#PSALDO": pv = parsePBUDGET_PSALDO(di); if (pv != null) { Callbacks.CallbackPSALDO(pv); if (!StreamValues) { PSALDO.Add(pv); } } break; case "#RAR": parseRAR(di); break; case "#RTRANS": if (!IgnoreBTRANS) { parseTRANS(di, curVoucher); } break; case "#SIETYP": SIETYP = di.GetInt(0); break; case "#SRU": parseSRU(di); break; case "#TAXAR": TAXAR = di.GetInt(0); break; case "#UB": parseUB(di); break; case "#TRANS": parseTRANS(di, curVoucher); break; case "#RES": parseRES(di); break; case "#VALUTA": VALUTA = di.GetString(0); break; case "#VER": curVoucher = parseVER(di); break; case "": //Empty line break; case "{": break; case "}": if (curVoucher != null) { closeVoucher(curVoucher); } curVoucher = null; break; default: Callbacks.CallbackException(new NotImplementedException(di.ItemType)); break; } } while (!sr.EndOfStream); return(false); }