示例#1
0
        /// <summary>
        /// Returns a List of SummaryHeader information in the BAI file
        /// </summary>
        /// <param name="data">The translated BAI object</param>
        /// <returns>A List of SummaryHeader</returns>
        public static List <SummaryHeader> GetSummaryInformation(TranslatedBaiFile data)
        {
            var ret = new List <SummaryHeader>();

            foreach (var group in data.Groups)
            {
                foreach (var account in group.Accounts)
                {
                    foreach (var fund in account.FundsTypes)
                    {
                        var amount = BaiFileHelpers.GetAmount(fund.Amount, group.CurrencyCode);
                        ret.Add(new SummaryHeader()
                        {
                            Date                     = group.AsOfDateTime,
                            CreationDate             = data.FileCreationDateTime,
                            SenderIdentification     = data.SenderIdentification,
                            ReceiverIndetification   = data.ReceiverIdentification,
                            FileIdentificationNumber = data.FileIdentificationNumber,
                            CurrencyCode             = group.CurrencyCode,
                            CustomerAccountNumber    = account.CustomerAccountNumber,
                            Amount                   = amount,
                            Count                    = fund.ItemCount,
                            FundType                 = fund.FundsType,
                            TypeCode                 = fund.Detail.TypeCode,
                            TypeDescription          = fund.Detail.Description
                        });
                    }
                }
            }
            return(ret);
        }
示例#2
0
 public FundType(string typeCode, string amount, string itemCount, string fundsType)
 {
     TypeCode  = typeCode;
     Detail    = BaiFileHelpers.GetTransactionDetail(typeCode);
     Amount    = amount;
     ItemCount = itemCount;
     FundsType = fundsType;
 }
        public TranslatedBaiFile(BaiFile data)
        {
            Groups = new List <Group>();

            // Translate myself, and walk the file
            if (!data.FileHeader.Trim().EndsWith("/"))
            {
                throw new NotImplementedException("Bai file is not properly formatted, I don't know how to handle this");
            }
            if (!data.FileTrailer.Trim().EndsWith("/"))
            {
                throw new NotImplementedException("Bai file is not properly formatted, I don't know how to handle this");
            }
            var fields = data.FileHeader.Trim().Split(',');

            if (fields.Length != 9)
            {
                throw new NotImplementedException("Bai file does not have proper number of FileHeader elements, I don't know how to handle this");
            }


            HeaderRecordCode         = fields[0];
            SenderIdentification     = fields[1];
            ReceiverIdentification   = fields[2];
            FileIdentificationNumber = fields[5];
            PhysicalRecordLength     = fields[6];
            BlockSize     = fields[7];
            VersionNumber = fields[8].Replace("/", "");

            if (VersionNumber != "2")
            {
                throw new NotImplementedException("Bai file not version 2 format, I don't know how to handle this!");
            }

            // Handle date 3, 4
            FileCreationDateTime = BaiFileHelpers.DateTimeFromFields(fields[3], fields[4]);
            // End of Header

            foreach (var group in data.Groups)
            {
                Groups.Add(new Group(group));
            }

            // Beginning of Trailer
            fields = data.FileTrailer.Split(',');
            if (fields.Length != 4)
            {
                throw new NotImplementedException("Bai file does not have proper number of FileTrailer elements, I don't know how to handle this");
            }
            TrailerRecordCode = fields[0];
            FileControlTotal  = fields[1];
            NumberOfGroups    = int.Parse(fields[2]);
            NumberOfRecords   = int.Parse(fields[3].Replace("/", ""));
        }
示例#4
0
        public Group(BaiGroup data)
        {
            Accounts = new List <Account>();

            if (!data.GroupHeader.Trim().EndsWith("/"))
            {
                throw new NotImplementedException("Bai file is not properly formatted, I don't know how to handle this");
            }
            if (!data.GroupTrailer.Trim().EndsWith("/"))
            {
                throw new NotImplementedException("Bai file is not properly formatted, I don't know how to handle this");
            }
            var fields = data.GroupHeader.Trim().Split(',');

            if (fields.Length != 8)
            {
                throw new NotImplementedException("Bai file does not have proper number of GroupHeader elements, I don't know how to handle this");
            }

            HeaderRecordCode = fields[0];
            UltimateReceiverIdentification = fields[1];
            OriginatorIdentification       = fields[2];
            GroupStatus      = BaiFileHelpers.GetGroupStatus(fields[3]);
            AsOfDateTime     = BaiFileHelpers.DateTimeFromFields(fields[4], fields[5]);
            CurrencyCode     = BaiFileHelpers.GetCurrencyCode(fields[6]);
            AsOfDateModifier = BaiFileHelpers.GetAsOfDateModifier(fields[7]);

            foreach (var account in data.Accounts)
            {
                Accounts.Add(new Account(account, CurrencyCode));
            }

            fields = data.GroupTrailer.Split(',');
            if (fields.Length != 4)
            {
                throw new NotImplementedException("Bai file does not have proper number of FileTrailer elements, I don't know how to handle this");
            }
            TrailerRecordCode = fields[0];
            GroupControlTotal = fields[1];
            NumberOfAccounts  = int.Parse(fields[2]);
            NumberOfRecords   = int.Parse(fields[3].Replace("/", ""));
        }
示例#5
0
        public Account(BaiAccount data, string currencyCode)
        {
            FundsTypes = new List <FundType>();
            Details    = new List <Detail>();

            var list = new List <string> {
                data.AccountIdentifier
            };

            list.AddRange(data.AccountContinuation);

            var factory = new AccountFundTypeFactory(list);

            IdentifierRecordCode  = factory.RecordCode;
            CustomerAccountNumber = factory.CustomerAccountNumber;
            CurrencyCode          = factory.CurrencyCode;

            var fundType = factory.GetNext();

            while (fundType != null)
            {
                FundsTypes.Add(fundType);
                fundType = factory.GetNext();
            }


            // Time to get the details
            foreach (var detail in data.Details)
            {
                Details.Add(new Detail(detail, currencyCode));
            }

            var fields = data.AccountTrailer.Split(',');

            if (fields.Length != 3)
            {
                throw new NotImplementedException("Bai file does not have proper number of AccountTrailer elements, I don't know how to handle this");
            }
            TrailerRecordCode   = fields[0];
            AccountControlTotal = BaiFileHelpers.GetAmount(fields[1], CurrencyCode);
            NumberOfRecords     = int.Parse(fields[2].Replace("/", ""));
        }
示例#6
0
        public static FundType GetNext(Stack stack, string currencyCode)
        {
            if (stack.Count < 4)
            {
                return(null);
            }
            var typeCode  = stack.Pop().ToString();
            var amount    = stack.Pop().ToString();
            var itemCount = stack.Pop().ToString();
            var fundsType = stack.Pop().ToString();

            switch (fundsType.ToUpper())
            {
            case "S":
                var immediate = stack.Pop().ToString();
                var oneDay    = stack.Pop().ToString();
                var moreDays  = stack.Pop().ToString();

                return(new FundType(typeCode, amount, itemCount, fundsType, immediate, oneDay, moreDays));

            case "D":
                // next field is the number of distripution pairs
                // number of days, avalible amount
                var info  = new Dictionary <int, decimal>();
                var count = int.Parse(stack.Pop().ToString());
                for (var i = 0; i < count; i++)
                {
                    var key = int.Parse(stack.Pop().ToString());
                    var v   = BaiFileHelpers.GetAmount(stack.Pop().ToString(), currencyCode);
                    info.Add(key, v);
                }
                return(new FundType(typeCode, amount, itemCount, fundsType, count.ToString(), info));

            case "V":
                var date  = stack.Pop().ToString();
                var time  = stack.Pop().ToString();
                var value = BaiFileHelpers.DateTimeFromFields(date, time);
                return(new FundType(typeCode, amount, itemCount, fundsType, value));
            }
            return(new FundType(typeCode, amount, itemCount, fundsType));
        }
示例#7
0
        public Detail(BaiDetail data, string currencyCode)
        {
            TextList       = new List <string>();
            TextDictionary = new Dictionary <string, string>();

            var list = new List <string> {
                data.TransactionDetail
            };

            list.AddRange(data.DetailContinuation);

            var lineData = "";

            foreach (var section in list)
            {
                var line = section.Trim();
                // Some / are optional?
                //if (!line.EndsWith("/")) throw new Exception("I got a line without a trailing /");

                if (line.StartsWith("16"))
                {
                    line = line.Replace("/", "");
                }
                else if (line.StartsWith("88"))
                {
                    line = line.Substring(2);//.Replace("/", " ");
                }
                else
                {
                    throw new Exception("I got a bad line: " + line);
                }
                lineData += line;
            }

            // Now try to figure out what's left ;-)
            var stack = new Stack(lineData.Split(',').Reverse().ToArray());

            RecordCode = stack.Pop().ToString();
            TypeCode   = stack.Pop().ToString();
            Amount     = stack.Pop().ToString();
            FundsType  = stack.Pop().ToString();

            switch (FundsType.ToUpper())
            {
            case "S":
                Immediate     = stack.Pop().ToString();
                OneDay        = stack.Pop().ToString();
                TwoOrMoreDays = stack.Pop().ToString();
                break;

            case "D":
                // next field is the number of distripution pairs
                // number of days, avalible amount
                // currencyCode would be used here
                throw new Exception("I don't want to deal with this one yet - " + currencyCode);

            case "V":
                var date = stack.Pop().ToString();
                var time = stack.Pop().ToString();
                AvalibleDate = BaiFileHelpers.DateTimeFromFields(date, time);
                break;
            }

            BankReferenceNumber     = stack.Pop().ToString();
            CustomerReferenceNumber = stack.Pop().ToString();
            // What's left on the stack?
            Text = LeftoverStackToString(stack);

            CreateTextList();
            CreateTextDictionary();
        }
示例#8
0
        /// <summary>
        /// Returns a List of DetailSummary
        /// </summary>
        /// <param name="data">The translated BAI object</param>
        /// <param name="dictionaryKeys">Any Keys in the Detail.TextDictionary (if any) you would like to export</param>
        /// <returns>A List of DetailSummary</returns>
        public static List <DetailSummary> GetDetailInformation(TranslatedBaiFile data, List <string> dictionaryKeys)
        {
            var ret = new List <DetailSummary>();

            foreach (var group in data.Groups)
            {
                foreach (var account in group.Accounts)
                {
                    foreach (var detail in account.Details)
                    {
                        var detailType     = BaiFileHelpers.GetTransactionDetail(detail.TypeCode);
                        var textDictionary = new Dictionary <string, string>();

                        if (dictionaryKeys != null)
                        {
                            foreach (var key in dictionaryKeys)
                            {
                                if (detail.TextDictionary.ContainsKey(key))
                                {
                                    textDictionary.Add(key, detail.TextDictionary[key]);
                                }
                            }
                        }

                        var ds = new DetailSummary()
                        {
                            Date                     = group.AsOfDateTime,
                            CreationDate             = data.FileCreationDateTime,
                            FileIdentificationNumber = data.FileIdentificationNumber,
                            SenderIdentification     = data.SenderIdentification,
                            Amount                   = BaiFileHelpers.GetAmount(detail.Amount, group.CurrencyCode),
                            BankReferenceNumber      = detail.BankReferenceNumber,
                            CustomerReferenceNumber  = detail.CustomerReferenceNumber,
                            CustomerAccountNumber    = account.CustomerAccountNumber,
                            Text                     = detail.Text,
                            TypeCode                 = detailType.TypeCode,
                            TypeDescription          = detailType.Description,
                            FundType                 = detail.FundsType,
                            TextDictionary           = textDictionary
                        };

                        // I don't want to return an optional, I want a blank string
                        if (!string.IsNullOrEmpty(detail.Immediate))
                        {
                            ds.Immediate = BaiFileHelpers.GetAmount(detail.Immediate, group.CurrencyCode).ToString(CultureInfo.CurrentCulture);
                        }
                        if (!string.IsNullOrEmpty(detail.OneDay))
                        {
                            ds.OneDay = BaiFileHelpers.GetAmount(detail.OneDay, group.CurrencyCode).ToString(CultureInfo.CurrentCulture);
                        }
                        if (!string.IsNullOrEmpty(detail.TwoOrMoreDays))
                        {
                            ds.TwoOrMoreDays = BaiFileHelpers.GetAmount(detail.TwoOrMoreDays, group.CurrencyCode).ToString(CultureInfo.CurrentCulture);
                        }

                        ret.Add(ds);
                    }
                }
            }
            return(ret);
        }