Esempio n. 1
0
        private void parseIB(SieDataItem di)
        {
            if (!KONTO.ContainsKey(di.GetString(1)))
            {
                KONTO.Add(di.GetString(1), new SieAccount()
                {
                    Number = di.GetString(1)
                });
            }

            var v = new SiePeriodValue()
            {
                YearNr   = di.GetInt(0),
                Account  = KONTO[di.GetString(1)],
                Amount   = di.GetDecimal(2),
                Quantity = di.GetDecimal(3),
                Token    = di.ItemType
            };

            Callbacks.CallbackIB(v);
            if (!StreamValues)
            {
                IB.Add(v);
            }
        }
Esempio n. 2
0
        private void parseRES(SieDataItem di)
        {
            if (!KONTO.ContainsKey(di.GetString(1)))
            {
                KONTO.Add(di.GetString(1), new SieAccount()
                {
                    Number = di.GetString(1)
                });
            }
            var objOffset = 0;

            if (di.RawData.Contains("{"))
            {
                objOffset = 1;
            }
            var v = new SiePeriodValue()
            {
                YearNr   = di.GetInt(0),
                Account  = KONTO[di.GetString(1)],
                Amount   = di.GetDecimal(2 + objOffset),
                Quantity = di.GetDecimal(3 + objOffset),
                Token    = di.ItemType
            };

            Callbacks.CallbackRES(v);
            if (!StreamValues)
            {
                RES.Add(v);
            }
            return;
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        private void parseOBJEKT(SieDataItem di)
        {
            var dimNumber = di.GetString(0);
            var number    = di.GetString(1);
            var name      = di.GetString(2);

            if (!DIM.ContainsKey(dimNumber))
            {
                DIM.Add(dimNumber, new SieDimension()
                {
                    Number = dimNumber
                });
            }

            var dim = DIM[dimNumber];

            var obj = new SieObject()
            {
                Dimension = dim, Number = number, Name = name
            };

            if (!dim.Objects.ContainsKey(number))
            {
                dim.Objects.Add(number, obj);
            }
            else
            {
                dim.Objects[number] = obj;
            }
        }
Esempio n. 5
0
        private void parseRAR(SieDataItem di)
        {
            rar       = new SieBookingYear();
            rar.ID    = di.GetInt(0);
            rar.Start = di.GetDate(1);
            rar.End   = di.GetDate(2);

            RAR.Add(rar.ID, rar);
        }
Esempio n. 6
0
        private void parseKSUMMA(SieDataItem di)
        {
            KSUMMA = di.GetLong(0);
            long checksum = CRC.Checksum();

            if (KSUMMA != checksum)
            {
                Callbacks.CallbackException(new SieInvalidChecksumException(_fileName));
            }
        }
Esempio n. 7
0
 private void parseSRU(SieDataItem di)
 {
     if (!KONTO.ContainsKey(di.GetString(0)))
     {
         KONTO.Add(di.GetString(0), new SieAccount()
         {
             Number = di.GetString(0)
         });
     }
     KONTO[di.GetString(0)].SRU.Add(di.GetString(1));
 }
Esempio n. 8
0
 private void parseKTYP(SieDataItem di)
 {
     //Create the account if it hasn't been loaded yet.
     if (!KONTO.ContainsKey(di.GetString(0)))
     {
         KONTO.Add(di.GetString(0), new SieAccount()
         {
             Number = di.GetString(0)
         });
     }
     KONTO[di.GetString(0)].Type = di.GetString(1);
 }
Esempio n. 9
0
 private void parseKONTO(SieDataItem di)
 {
     if (KONTO.ContainsKey(di.GetString(0)))
     {
         KONTO[di.GetString(0)].Name = di.GetString(1);
     }
     else
     {
         KONTO.Add(di.GetString(0), new SieAccount()
         {
             Number = di.GetString(0), Name = di.GetString(1)
         });
     }
 }
Esempio n. 10
0
        public void AddData(SieDataItem item)
        {
            var buffer  = new List <byte>();
            var encoder = Encoding.GetEncoding(437);

            buffer.AddRange(encoder.GetBytes(item.ItemType));

            foreach (var d in item.Data)
            {
                var foo = d.Replace("{", "").Replace("}", "");
                buffer.AddRange(encoder.GetBytes(foo));
            }
            CRC_ackumulera(buffer);
        }
Esempio n. 11
0
        /// <summary>
        /// Does a fast scan of the file to get the Sie version it adheres to.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns>-1 if no SIE version was found in the file else SIETYPE is returned.</returns>
        public static int GetSieVersion(string fileName)
        {
            int ret = -1;

            foreach (var line in File.ReadLines(fileName, Encoding.GetEncoding(437)))
            {
                if (line.StartsWith("#SIETYP"))
                {
                    var di = new SieDataItem(line, null);
                    ret = di.GetInt(0);
                    break;
                }
            }

            return(ret);
        }
Esempio n. 12
0
        private SiePeriodValue parsePBUDGET_PSALDO(SieDataItem di)
        {
            //Create the account if it hasn't been loaded yet.
            if (!KONTO.ContainsKey(di.GetString(2)))
            {
                KONTO.Add(di.GetString(2), new SieAccount()
                {
                    Number = di.GetString(2)
                });
            }

            if (SIETYP == 1)
            {
                Callbacks.CallbackException(new SieInvalidFeatureException("Neither PSALDO or PBUDGET is part of SIE 1"));
            }

            if (SIETYP == 2 && di.RawData.Contains("{") && !di.RawData.Contains("{}"))
            {
                //Applications reading SIE type 2 should ignore PSALDO containing non empty dimension.
                return(null);
            }

            var objOffset = 0;

            if (di.RawData.Contains("{"))
            {
                objOffset = 1;
            }

            var v = new SiePeriodValue()
            {
                YearNr   = di.GetInt(0),
                Period   = di.GetInt(1),
                Account  = KONTO[di.GetString(2)],
                Amount   = di.GetDecimal(3 + objOffset),
                Quantity = di.GetDecimal(4 + objOffset),
                Token    = di.ItemType
            };

            if (SIETYP != 2 && di.RawData.Contains("{"))
            {
                v.Objects = di.GetObjects();
            }
            return(v);
        }
Esempio n. 13
0
        private void parseDimension(SieDataItem di)
        {
            var d = di.GetString(0);
            var n = di.GetString(1);

            if (!DIM.ContainsKey(d))
            {
                DIM.Add(d, new SieDimension()
                {
                    Name = n, Number = d
                });
            }
            else
            {
                DIM[d].Name      = n;
                DIM[d].IsDefault = false;
            }
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        private SiePeriodValue parseOIB_OUB(SieDataItem di)
        {
            //Create the account if it hasn't been loaded yet.
            if (!KONTO.ContainsKey(di.GetString(1)))
            {
                KONTO.Add(di.GetString(1), new SieAccount()
                {
                    Number = di.GetString(1)
                });
            }

            if (SIETYP < 3)
            {
                Callbacks.CallbackException(new SieInvalidFeatureException("Neither OIB or OUB is part of SIE < 3"));
            }

            var objOffset = 0;

            if (di.RawData.Contains("{"))
            {
                objOffset = 1;
            }

            var v = new SiePeriodValue()
            {
                YearNr   = di.GetInt(0),
                Period   = di.GetInt(1),
                Account  = KONTO[di.GetString(1)],
                Amount   = di.GetDecimal(3 + objOffset),
                Quantity = di.GetDecimal(4) + objOffset,
                Objects  = di.GetObjects(),
                Token    = di.ItemType
            };

            return(v);
        }
Esempio n. 16
0
        /// <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);
        }
Esempio n. 17
0
        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();
        }