Esempio n. 1
0
        ///<summary>
        ///  Parameters:  none
        ///</summary>

        /* structure btl91 format:
         *  1 line of file information
         *  1 batches consisting of
         *    x payments consisting of
         *        4 payment transaction records
         *    y currency total records
         *  1 line of file closing information.
         */
        private void buildInfo(List <Erp.Internal.EI.Payment_Def.TmpElec> TmpElecRows)
        {
            string   CurGroupCurrencyCode     = string.Empty;
            DateTime?CurCheckDate             = null;
            string   BankCurrencySymbol       = string.Empty;
            string   VendorBankISOCountryCode = string.Empty;
            string   VendorISOCountryCode     = string.Empty;
            string   SAmount                = string.Empty;
            string   TAmount                = string.Empty;
            int      TotalRecords           = 0;
            string   PaymentNumber          = string.Empty;
            int      TotalOrders            = 0;
            string   Selfbanknumber         = string.Empty;
            string   Description_1          = string.Empty;
            int      TotalInvoice           = 0;
            string   TransferCost           = string.Empty;
            string   VendorBankSWIFTAddress = string.Empty;
            string   IsoCurrencySymbol      = string.Empty;
            string   v_CurrCode             = string.Empty;
            int      lineLevel              = 0;

            SFCommon.OutFileLine OutFileLineRow;
            SFCommon.OutFileLine OutFileLineRow2;

            #region >>===== ABL Source ================================>>
            //
            //FIND first Currency WHERE Currency.Company = cur-comp and
            //                              Currency.BaseCurr = true no-lock
            //
            #endregion == ABL Source =================================<<

            Currency = this.FindFirstCurrency(Session.CompanyID, true);
            if (Currency != null)
            {
                v_CurrCode = Currency.CurrencyCode;
            }
            else
            {
                v_CurrCode = "";
            }


            #region >>===== ABL Source ================================>>
            //
            //find first TmpElec no-lock no-error;
            //
            #endregion == ABL Source =================================<<

            var TmpElec = (from row in TmpElecRows select row).FirstOrDefault();
            if (TmpElec == null)
            {
                throw new BLException(GlobalStrings.InterErrorTmpElecHasNoRecords);
            }
            else
            {
                CurGroupCurrencyCode = TmpElec.GroupCurrCode;
                CurCheckDate         = TmpElec.ProcessDate;
            }


            #region >>===== ABL Source ================================>>
            //
            //FIND first Company WHERE Company.Company = CUR-COMP no-lock
            //
            #endregion == ABL Source =================================<<

            Company = this.FindFirstCompany(Session.CompanyID);
            if (Company == null)
            {
                throw new BLException(GlobalStrings.CompanyNotFound);
            }


            #region >>===== ABL Source ================================>>
            //
            //FIND first Country WHERE Country.Company = CUR-COMP and Country.CountryNum = Company.CountryNum no-lock
            //
            #endregion == ABL Source =================================<<

            Country = this.FindFirstCountry(Session.CompanyID, Company.CountryNum);
            if (Country == null)
            {
                throw new BLException(GlobalStrings.AValidCountryOfYourCompanyIsRequi);
            }


            #region >>===== ABL Source ================================>>
            //
            //FIND first BankAcct WHERE BankAcct.Company = Cur-comp and BankAcct.BankAcctID = TmpElec.FromBankAcctID no-lock
            //
            #endregion == ABL Source =================================<<

            BankAcct = this.FindFirstBankAcct(Session.CompanyID, TmpElec.FromBankAcctID);
            if (BankAcct == null)
            {
                throw new BLException(GlobalStrings.AValidFromBankAcctIsRequired);
            }

            //Selfbanknumber = Payment_Common.BankAccount(BankAcct.CheckingAccount);
//needs to be right justified, zero filled
            //Selfbanknumber = String.Format("{0:00000000000000000000}", Payment_Common.BankAccount(BankAcct.CheckingAccount));
            //Selfbanknumber = String.Format("{0:00000000000000000000}", Convert.ToInt32(Payment_Common.BankAccount(BankAcct.CheckingAccount)));
            Selfbanknumber = String.Format("{0:00000000000000000000}", Convert.ToDouble(Payment_Common.BankAccount(BankAcct.CheckingAccount)));


            BankCurrencySymbol = GetCurrencyID(BankAcct.CurrencyCode);
            IsoCurrencySymbol  = GetCurrencyID(CurGroupCurrencyCode);/* CurGroupCurrencyCode will be blank if more than one currency in the group 67341*/

            /* The line below is commented out per SCR # 64216 */
            /*if CurGroupCurrencyCode = v-CurrCode then IsoCurrencySymbol = "EUR":U.*/

            if (String.IsNullOrEmpty(Selfbanknumber))
            {
                throw new BLException(GlobalStrings.AValidYourBankAccountNumberIsRequi);
            }

            /* if the currency of the bankaccount is not Dutch Guilder or Euro then
             * the currency of the bankaccount must be equal to the currency of the payment */
            if ((!(BankCurrencySymbol.Compare("NLG") == 0 || BankCurrencySymbol.Compare("EUR") == 0 || BankCurrencySymbol.Compare("?") == 0)) && (IsoCurrencySymbol.Compare(BankCurrencySymbol) != 0))
            {
                throw new BLException(GlobalStrings.OnlyPaymeInTheCurreOfThisBankAccountAreAllowed);
            }
            SFCommon.ttOutFileLineRows = new List <SFCommon.OutFileLine>();
            SFCommon.ttOutFileLineRows.Clear();
            /* 11: file information */
            lineLevel    = 11;
            TotalRecords = 0;

//zzz fix the doc notes:

            /* This code adds information from the specified payment method into a document.
             * The document will have the structure like this:
             *
             *  1 line of payment method information
             *  1 line of file information
             *  1 batches consisting of
             *    x payments consisting of
             *        4 payment transaction records
             *    y currency total records
             *  1 line of file closing information.
             *
             * SCR 40680  - uncomment the string below if you want insert payment method information  */
            /*
             * create OutFileLine.
             * {ei/SoftFormat.i &TableName        = PayMethodProp
             *               &EFTHeadUID       = EFTHeadUID
             *               &LineOut          = OutFileLine.Line-out
             *               &LineLen          = lineLen
             *               &LineLevel        = lineLevel
             *               &LineLevelFormat  = lineLevelFormat
             *               &TotalRecords     = TotalRecords}
             */
            OutFileLineRow = new SFCommon.OutFileLine();
            SFCommon.ttOutFileLineRows.Add(OutFileLineRow);

            // FILE HEADER RECORD (1)
            string line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
            // field 1
            line_out = ErpUtilities.Overlay(line_out, 0, "1", 1);
            // field 2
            line_out = ErpUtilities.Overlay(line_out, 1, "01", 2);
            // field 3
            line_out = ErpUtilities.Overlay(line_out, 3, "0021000021", 10);
            // field 4
            line_out = ErpUtilities.Overlay(line_out, 13, "0000000000", 10);
            // field 5
            line_out = ErpUtilities.Overlay(line_out, 23, DateTime.Now.ToString("yyMMdd"), 6);
            // field 6
            line_out = ErpUtilities.Overlay(line_out, 29, DateTime.Now.ToString("HHmm"), 4);
            // field 7
            line_out = ErpUtilities.Overlay(line_out, 33, "A", 1);
            // field 8
            line_out = ErpUtilities.Overlay(line_out, 34, "094", 3);
            // field 9
            line_out = ErpUtilities.Overlay(line_out, 37, "10", 2);
            // field 10
            line_out = ErpUtilities.Overlay(line_out, 39, "1", 1);
            // field 11
            line_out = ErpUtilities.Overlay(line_out, 40, "JPMORGAN CHASE", 23);
            // field 12
            line_out = ErpUtilities.Overlay(line_out, 63, Company.Name, 23);
            // field 13
            line_out = ErpUtilities.Overlay(line_out, 86, "", 8);

            TotalRecords            = TotalRecords + 1;
            lineLevel               = lineLevel + 1;
            PaymentNumber           = "";
            TotalOrders             = 0;
            OutFileLineRow.Line_out = line_out;


            // BATCH HEADER RECORD (5)
            OutFileLineRow2 = new SFCommon.OutFileLine();
            SFCommon.ttOutFileLineRows.Add(OutFileLineRow2);


            string line_out2 = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
            // field 1
            line_out2 = ErpUtilities.Overlay(line_out2, 0, "5", 1);

//need logic here
//	220 for credits
//	225 for debits
//	can't combine both
            // field 2
            line_out2 = ErpUtilities.Overlay(line_out2, 1, "???", 3);


            // field 3
            line_out2 = ErpUtilities.Overlay(line_out2, 4, "", 16);
            // field 4
            line_out2 = ErpUtilities.Overlay(line_out2, 20, Selfbanknumber, 20);
            // field 5
            line_out2 = ErpUtilities.Overlay(line_out2, 40, "0000000000", 10);
            // field 6
            line_out2 = ErpUtilities.Overlay(line_out2, 50, "CCD", 3);
            // field 7
            line_out2 = ErpUtilities.Overlay(line_out2, 53, "ACH PMT", 10);
            // field 8
            line_out2 = ErpUtilities.Overlay(line_out2, 63, DateTime.Now.ToString("MMM dd"), 6);
            // field 9
            line_out2 = ErpUtilities.Overlay(line_out2, 69, DateTime.Now.ToString("yyMMdd"), 6);
            // field 10
            line_out2 = ErpUtilities.Overlay(line_out2, 75, "", 3);
            // field 11
            line_out2 = ErpUtilities.Overlay(line_out2, 78, "1", 1);
            // field 12
            line_out2 = ErpUtilities.Overlay(line_out2, 79, "02100002", 8);

//zzzz
//batch number need to figure out:
//for each APTran where APTran.Company = Cur-Comp and APTran.HeadNum = TmpElec.HeadNum no-lock
//                             by APTran.Company
//                               by APTran.HeadNum
//                                 by APTranNo
//                                   by InvoiceNum:

            // field 13
            //line_out2 = ErpUtilities.Overlay(line_out2, 87, TmpElec.HeadNum.ToString(), 7);
//Selfbanknumber = String.Format("{0:00000}", Payment_Common.BankAccount(BankAcct.CheckingAccount));
//this is not the check number:
            //line_out2 = ErpUtilities.Overlay(line_out2, 87, String.Format("{0:0000000}", TmpElec.HeadNum), 7);
            // >> yields: 0000774
//note: CheckHed.CheckNum is currently 8 digits, field 13 is only 7
//		that is bad anyway because it's per payment, not ap batch

//not a line, just for testing:
            string x = GetPaymentBankBatchID(string.Empty);
            line_out2 = ErpUtilities.Overlay(line_out2, 87, x, 7);



            TotalRecords  = TotalRecords + 1;
            lineLevel     = lineLevel + 1;
            PaymentNumber = "";
            TotalOrders   = 0;
//zzzz
            OutFileLineRow2.Line_out = line_out2;



//zzz fix the doc notes:

            /* This code adds information from the specified payment method into a document.
             * The document will have the structure like this:
             *
             *  1 line of file information
             *  1 line of payment method information
             *  1 batches consisting of
             *    x payments consisting of
             *        4 payment transaction records
             *    y currency total records
             *  1 line of file closing information.
             *
             * SCR 40680  - uncomment the string below if you want insert payment method information  */
            /*
             * create OutFileLine.
             * {ei/SoftFormat.i &TableName        = PayMethodProp
             *               &EFTHeadUID       = EFTHeadUID
             *               &LineOut          = OutFileLine.Line-out
             *               &LineLen          = lineLen
             *               &LineLevel        = lineLevel
             *               &LineLevelFormat  = lineLevelFormat
             *               &TotalRecords     = TotalRecords}
             */

            #region >>===== ABL Source ================================>>
            //
            //for each TmpElec no-lock:
            //
            //
            //
            #endregion == ABL Source =================================<<

            foreach (var _TmpElec in TmpElecRows)
            {
                TmpElec                = _TmpElec;
                lineLevel              = 21;
                Description_1          = "";
                TotalInvoice           = 0;
                TotalOrders            = TotalOrders + 1;
                TransferCost           = "3";
                PaymentNumber          = Compatibility.Convert.ToString(TotalOrders, "9999");
                VendorBankSWIFTAddress = TmpElec.VendorBankSwiftNum;
                IsoCurrencySymbol      = GetCurrencyID(TmpElec.CurrencyCode);
                if (String.IsNullOrEmpty(TmpElec.VendorBankAcctNumber))
                {
                    throw new BLException(GlobalStrings.AValidSupplBankAccountNumberIsRequi);
                }


                #region >>===== ABL Source ================================>>
                //
                //FIND first Country WHERE Country.Company = CUR-COMP and Country.CountryNum = TmpElec.VendorCountryNum no-lock
                //
                #endregion == ABL Source =================================<<

                Country = this.FindFirstCountry2(Session.CompanyID, TmpElec.VendorCountryNum);
                if (Country == null)
                {
                    throw new BLException(GlobalStrings.AValidCountryOfTheSupplIsRequi);
                }
                if (String.IsNullOrEmpty(Country.ISOCode))
                {
                    throw new BLException(GlobalStrings.TheISOCountryCodeOfTheSupplIsRequi(TmpElec.VendorName));
                }
                VendorISOCountryCode = Country.ISOCode;


                #region >>===== ABL Source ================================>>
                //
                //FIND first Country WHERE Country.Company = CUR-COMP and Country.CountryNum = TmpElec.VendorBankCountryNum no-lock
                //
                #endregion == ABL Source =================================<<

                Country = this.FindFirstCountry3(Session.CompanyID, TmpElec.VendorBankCountryNum);
                if (Country == null)
                {
                    throw new BLException(GlobalStrings.AValidCountryOfTheBankOfTheSupplIsRequi);
                }
                if (String.IsNullOrEmpty(Country.ISOCode))
                {
                    throw new BLException(GlobalStrings.AValidCountryISOCodeOfTheBankOfTheSupplIsRequi);
                }
                VendorBankISOCountryCode = Country.ISOCode;

                /* fill the Description with invoice numbers,
                 * unless there are too many invoices */


                #region >>===== ABL Source ================================>>
                //
                //for each APTran where APTran.Company = Cur-Comp and APTran.HeadNum = TmpElec.HeadNum no-lock
                //                             by APTran.Company
                //                               by APTran.HeadNum
                //                                 by APTranNo
                //                                   by InvoiceNum:
                //
                //
                //
                //
                #endregion == ABL Source =================================<<

                //invoices:
                //this is a list of invoice numbers
                foreach (var APTran_iterator in (this.SelectAPTran(Session.CompanyID, TmpElec.HeadNum)))
                {
                    APTran = APTran_iterator;
                    if (!String.IsNullOrEmpty(APTran.InvoiceNum) && TotalInvoice < 35)
                    {
                        if (TotalInvoice == 0)
                        {
                            TotalInvoice  = TotalInvoice + 1;
                            Description_1 = GlobalStrings.Ref(APTran.InvoiceNum);
                        }
                        else if (Description_1.Length + APTran.InvoiceNum.Length <= 35)
                        {
                            TotalInvoice  = TotalInvoice + 1;
                            Description_1 = Description_1 + APTran.InvoiceNum + " ";
                        }
                        else
                        {
                            TotalInvoice  = 99;
                            Description_1 = "";
                            break;
                        }
                    }
                }

                SAmount = this.cnvAmount(IsoCurrencySymbol, Compatibility.Convert.ToString((TmpElec.DocCheckAmt * 100), "999999999999999"), 14);
                /* 21: batch payment record part 1 */
//zzz
                OutFileLineRow = new SFCommon.OutFileLine();
                SFCommon.ttOutFileLineRows.Add(OutFileLineRow);

                line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
                /*  1 */
                line_out = ErpUtilities.Overlay(line_out, 0, Compatibility.Convert.ToString(lineLevel), 2);
                /*  2 */
                line_out = ErpUtilities.Overlay(line_out, 2, PaymentNumber, 4);
                /*  3 */
                line_out = ErpUtilities.Overlay(line_out, 6, BankCurrencySymbol, 3);
                /*  4 */
                line_out = ErpUtilities.Overlay(line_out, 9, Selfbanknumber, 10);
                /*  5 */
                line_out = ErpUtilities.Overlay(line_out, 19, IsoCurrencySymbol, 3);
                /*  6 */
                line_out = ErpUtilities.Overlay(line_out, 22, SAmount, 15);
                //testing: line_out = ErpUtilities.Overlay(line_out, 22, "12345", 15);
                /*  7 */
                line_out = ErpUtilities.Overlay(line_out, 37, Compatibility.Convert.ToString(((DateTime)CurCheckDate).Year, "9999") + Compatibility.Convert.ToString(((DateTime)CurCheckDate).Month, "99") + Compatibility.Convert.ToString(((DateTime)CurCheckDate).Day, "99"), 8);
                /*  8 */
                line_out = ErpUtilities.Overlay(line_out, 45, "1", 1);         /* Standard for euro transfer */
                /*  9 */
                line_out = ErpUtilities.Overlay(line_out, 46, TransferCost, 1);
                /* 10 */
                line_out = ErpUtilities.Overlay(line_out, 47, "0", 1);         /* banktransfer */
                /* 11 */
                line_out = ErpUtilities.Overlay(line_out, 48, "0", 1);         /* Swift normal speed */
                /* 12 */
                line_out = ErpUtilities.Overlay(line_out, 49, " ", 1);         /* not allowed for euro transfer */
                /* 13 */
                line_out = ErpUtilities.Overlay(line_out, 50, " ", 1);         /* not allowed for euro transfer */
                /* 14 */
                line_out = ErpUtilities.Overlay(line_out, 51, "  ", 2);        /* not allowed for euro transfer */
                /* 15 */
                line_out = ErpUtilities.Overlay(line_out, 53, "  ", 2);        /* not allowed for euro transfer */
                /* 16 */
                line_out = ErpUtilities.Overlay(line_out, 55, "  ", 2);        /* not allowed for euro transfer */
                /* 17 */
                line_out = ErpUtilities.Overlay(line_out, 57, "  ", 2);        /* not allowed for euro transfer */
                /* 18 */
                line_out = ErpUtilities.Overlay(line_out, 59, "1", 1);
                /* 19 */
                /* not required */
                /* 20 */
                /* not required */
                /* 21 */
                /* not required */
                /* 22 */
                /* not required */
                /* 23 */
                /* not required */
                /* 24 */
                /* not required */
                TotalRecords            = TotalRecords + 1;
                lineLevel               = lineLevel + 1;
                OutFileLineRow.Line_out = line_out;
                OutFileLineRow.HeadNum  = TmpElec.HeadNum;
                /* 22: batch payment record part 2 */
                OutFileLineRow = new SFCommon.OutFileLine();
                SFCommon.ttOutFileLineRows.Add(OutFileLineRow);
                line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
                /*  1 */
                line_out = ErpUtilities.Overlay(line_out, 0, Compatibility.Convert.ToString(lineLevel), 2);
                /*  2 */
                line_out = ErpUtilities.Overlay(line_out, 2, PaymentNumber, 4);
                /*  3 */
                line_out = ErpUtilities.Overlay(line_out, 6, TmpElec.VendorBankAcctNumber, 34);
                /*  4 */
                line_out = ErpUtilities.Overlay(line_out, 40, ((TmpElec.VendorBankNameOnAccount.Trim().Length > 0) ? TmpElec.VendorBankNameOnAccount : TmpElec.VendorName), 35);
                /*  5 */
                line_out = ErpUtilities.Overlay(line_out, 75, TmpElec.VendorAddress1, 35);
                /*  6 */
                line_out = ErpUtilities.Overlay(line_out, 110, TmpElec.VendorCity, 35);
                /*  7 */
                line_out = ErpUtilities.Overlay(line_out, 145, VendorISOCountryCode, 2);
                /*  8 */
                line_out                = ErpUtilities.Overlay(line_out, 147, TmpElec.VendorCountry, 35);
                TotalRecords            = TotalRecords + 1;
                lineLevel               = lineLevel + 1;
                OutFileLineRow.Line_out = line_out;
                if ((VendorBankISOCountryCode.Compare("NL") == 0 || String.IsNullOrEmpty(VendorBankISOCountryCode)))
                {
                    if (String.IsNullOrEmpty(VendorBankSWIFTAddress))
                    {
                        throw new BLException(GlobalStrings.TheSWIFTAddressOfTheBankOfTheSupplIsRequi(TmpElec.VendorName));
                    }
                    if (String.IsNullOrEmpty(TmpElec.VendorBankName))
                    {
                        throw new BLException(GlobalStrings.TheNameOfTheBankOfTheSupplIsRequi(TmpElec.VendorName));
                    }
                    if (String.IsNullOrEmpty(TmpElec.VendorBankCity))
                    {
                        throw new BLException(GlobalStrings.TheCityOfTheBankOfSupplIsRequi(TmpElec.VendorName));
                    }
                }
                /* 23: batch payment record part 3 */
                OutFileLineRow = new SFCommon.OutFileLine();
                SFCommon.ttOutFileLineRows.Add(OutFileLineRow);
                line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
                /*  1 */
                line_out = ErpUtilities.Overlay(line_out, 0, Compatibility.Convert.ToString(lineLevel), 2);
                /*  2 */
                line_out = ErpUtilities.Overlay(line_out, 2, PaymentNumber, 4);
                /*  3 */
                line_out = ErpUtilities.Overlay(line_out, 6, VendorBankSWIFTAddress, 11);
                /*  4 */
                line_out = ErpUtilities.Overlay(line_out, 17, TmpElec.VendorBankName, 35);
                /*  5 */
                line_out = ErpUtilities.Overlay(line_out, 52, TmpElec.VendorBankAddress1, 35);
                /*  6 */
                line_out = ErpUtilities.Overlay(line_out, 87, TmpElec.VendorBankCity, 35);
                /*  7 */
                line_out = ErpUtilities.Overlay(line_out, 122, VendorBankISOCountryCode, 2);
                /*  8 */
                line_out                = ErpUtilities.Overlay(line_out, 124, TmpElec.VendorBankCountry, 35);
                TotalRecords            = TotalRecords + 1;
                lineLevel               = lineLevel + 1;
                OutFileLineRow.Line_out = line_out;
                /* 24: batch payment record part 4 */
                OutFileLineRow = new SFCommon.OutFileLine();
                SFCommon.ttOutFileLineRows.Add(OutFileLineRow);
                line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
                /*  1 */
                line_out = ErpUtilities.Overlay(line_out, 0, Compatibility.Convert.ToString(lineLevel), 2);
                /*  2 */
                line_out = ErpUtilities.Overlay(line_out, 2, PaymentNumber, 4);
                /*  3 */
                line_out = ErpUtilities.Overlay(line_out, 6, Description_1, 35);
                /*  4 */
                /* not allowed for euro transfer */
                /*  5 */
                /* not allowed for euro transfer */
                /*  6 */
                /* not allowed for euro transfer */
                TotalRecords            = TotalRecords + 1;
                lineLevel               = lineLevel + 1;
                OutFileLineRow.Line_out = line_out;

                #region >>===== ABL Source ================================>>
                //
                //find TmpCurrTotal where TmpCurrTotal.ISOCurrencyCode = IsoCurrencySymbol exclusive-lock no-error;
                //
                #endregion == ABL Source =================================<<

                ttTmpCurrTotal = (from TmpCurrTotal_Row in ttTmpCurrTotalRows
                                  where TmpCurrTotal_Row.ISOCurrencyCode.Compare(IsoCurrencySymbol) == 0
                                  select TmpCurrTotal_Row).FirstOrDefault();
                if (ttTmpCurrTotal == null)
                {
                    ttTmpCurrTotal = new TmpCurrTotal();
                    ttTmpCurrTotalRows.Add(ttTmpCurrTotal);
                    ttTmpCurrTotal.ISOCurrencyCode = IsoCurrencySymbol;
                    ttTmpCurrTotal.TotalAmount     = TmpElec.DocCheckAmt;
                    ttTmpCurrTotal.TotalPayments   = 1;
                }
                else
                {
                    ttTmpCurrTotal.TotalAmount   = ttTmpCurrTotal.TotalAmount + TmpElec.DocCheckAmt;
                    ttTmpCurrTotal.TotalPayments = ttTmpCurrTotal.TotalPayments + 1;
                }
            }/* for each TmpElec... */

            lineLevel = 31;

            #region >>===== ABL Source ================================>>
            //
            //for each TmpCurrTotal:
            //
            //
            //
            #endregion == ABL Source =================================<<

            foreach (var ttTmpCurrTotal in ttTmpCurrTotalRows)
            {
                TAmount = this.cnvAmount(ttTmpCurrTotal.ISOCurrencyCode, Compatibility.Convert.ToString((ttTmpCurrTotal.TotalAmount * 100), "999999999999999"), 14);
                /* 31: batch currency total record  */
                OutFileLineRow = new SFCommon.OutFileLine();
                SFCommon.ttOutFileLineRows.Add(OutFileLineRow);
                line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
                /*  1 */
                line_out = ErpUtilities.Overlay(line_out, 0, Compatibility.Convert.ToString(lineLevel), 2);
                /*  2 */
                line_out = ErpUtilities.Overlay(line_out, 2, ttTmpCurrTotal.ISOCurrencyCode, 3);
                /*  3 */
                line_out = ErpUtilities.Overlay(line_out, 5, TAmount, 15);
                /*  4 */
                line_out                = ErpUtilities.Overlay(line_out, 20, Compatibility.Convert.ToString(ttTmpCurrTotal.TotalPayments, "9999"), 4);
                TotalRecords            = TotalRecords + 1;
                lineLevel               = lineLevel + 1;
                OutFileLineRow.Line_out = line_out;
            }

            /* 41: Batch Closing record */
            lineLevel = 41;

            /* This code adds information from the specified payment method into a document.
             * The document will have the structure like this:
             *
             *  1 line of file information
             *  1 batches consisting of
             *    x payments consisting of
             *        4 payment transaction records
             *    y currency total records
             *  1 line of payment method information
             *  1 line of file closing information.
             *
             * SCR 40680  - uncomment the string below if you want insert payment method information  */
            /*
             * create OutFileLine.
             * {ei/SoftFormat.i &TableName        = PayMethodProp
             *               &EFTHeadUID       = EFTHeadUID
             *               &LineOut          = OutFileLine.Line-out
             *               &LineLen          = lineLen
             *               &LineLevel        = lineLevel
             *               &LineLevelFormat  = lineLevelFormat
             *               &TotalRecords     = TotalRecords}
             */
            OutFileLineRow = new SFCommon.OutFileLine();
            SFCommon.ttOutFileLineRows.Add(OutFileLineRow);
            line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
            /*  1 */
            line_out = ErpUtilities.Overlay(line_out, 0, Compatibility.Convert.ToString(lineLevel), 2);
            /*  2 */
            line_out = ErpUtilities.Overlay(line_out, 2, Compatibility.Convert.ToString(TotalRecords + 1, "999999"), 6);
            /*  3 */
            line_out = ErpUtilities.Overlay(line_out, 8, Compatibility.Convert.ToString(TotalOrders, "9999"), 4);
            OutFileLineRow.Line_out = line_out;
        }
        ///<summary>
        ///  Parameters:  none
        ///</summary>

        /* stucture JPMorgan NACHA format:
         *  1 line of file header information
         *  1 line of batch header information
         *      n Entry detail transaction records
         *  1 line of batch control information
         *  1 line of File control information.
         */
        private void buildInfo(List <Payment_Def.TmpElec> ttTmpElecRows)
        {
            Payment_Def.TmpElec TmpElec = null;
            string   ImmediateOrigine   = string.Empty;
            DateTime?CurCheckDate       = null;
            string   CompanyBankAcct    = string.Empty;
            string   VendorBankNumber   = string.Empty;

            //eb1:
            string SelfBankNumber = string.Empty;

            decimal TotalAmount  = decimal.Zero;
            decimal TotalNumber  = decimal.Zero;
            int     Payment      = 0;
            string  STotalAmount = string.Empty;
            string  STotalNumber = string.Empty;
            string  SPayment     = string.Empty;
            string  Sblocks      = string.Empty;
            string  SAmount      = string.Empty;
            //eb5:
            string  SCheckNum        = string.Empty;
            decimal CheckingAccount  = decimal.Zero;
            string  SCheckingAccount = string.Empty;


            #region >>===== ABL Source ================================>>
            //
            //find first TmpElec no-lock no-error;
            //
            #endregion == ABL Source =================================<<

            TmpElec = (from ttTmpElec_Row in ttTmpElecRows select ttTmpElec_Row).FirstOrDefault();

            if (TmpElec == null)
            {
                throw new BLException(GlobalStrings.InterErrorTmpElecHasNoRecords);
            }
            else
            {
                CurCheckDate = TmpElec.ProcessDate;
            }



            #region >>===== ABL Source ================================>>
            //
            //FIND first Company WHERE Company.Company = CUR-COMP no-lock
            //
            #endregion == ABL Source =================================<<

            Company = this.FindFirstCompany(Session.CompanyID);
            if (Company == null)
            {
                throw new BLException(GlobalStrings.CompanyNotFound);
            }
            ImmediateOrigine = "1" + System.Text.RegularExpressions.Regex.Replace(Company.FEIN, "[^0-9]", "");

            #region >>===== ABL Source ================================>>
            //
            //FIND first BankAcct WHERE BankAcct.Company = Cur-comp and BankAcct.BankAcctID = TmpElec.FromBankAcctID no-lock
            //
            #endregion == ABL Source =================================<<

            BankAcct = this.FindFirstBankAcct(Session.CompanyID, TmpElec.FromBankAcctID);
            if (BankAcct == null)
            {
                throw new BLException(GlobalStrings.AValidFromBankAcctIsRequired);
            }
            CompanyBankAcct = ((10 > 0) ? "b".PadRight(10 + "b".Length, 'b') : null);
            if (BankAcct.CheckingAccount.Length <= 10)
            {
                ErpUtilities.Overlay(CompanyBankAcct, (11 - BankAcct.CheckingAccount.Length), BankAcct.CheckingAccount, 10);
            }
            else
            {
                throw new BLException(GlobalStrings.CheckingNumberIsTooLong);
            }

            //eb1:
            SelfBankNumber = String.Format("{0:00000000000000000000}", Convert.ToDouble(Payment_Common.BankAccount(BankAcct.CheckingAccount)));

            if (EISFCommon.ttOutFileLineRows == null)
            {
                EISFCommon.ttOutFileLineRows = new List <SFCommon.OutFileLine>();
            }
            else
            {
                EISFCommon.ttOutFileLineRows.Clear();
            }

            ttOutFileLine = new SFCommon.OutFileLine();

            /* 1 - file header information */
            //eb5: only need detail lines for positive pay, so take out this whole section


            /* 5 - batch header information */
            //eb5: only need detail lines for positive pay, so take out this whole section


            /* transactions */


            #region >>===== ABL Source ================================>>
            //
            //for each TmpElec:
            //
            //
            //
            //
            #endregion == ABL Source =================================<<

            foreach (var _TmpElec in ttTmpElecRows)
            {
                TmpElec = _TmpElec;

                #region >>===== ABL Source ================================>>
                //
                //FIND first VendBank WHERE VendBank.Company = cur-comp and
                //                                  VendBank.VendorNum = TmpElec.VendorNum and
                //                                  VendBank.BankID = TmpElec.VendorBankID  no-lock
                //
                #endregion == ABL Source =================================<<

                VendBank = this.FindFirstVendBank(Session.CompanyID, TmpElec.VendorNum, TmpElec.VendorBankID);
                if (VendBank == null)
                {
                    throw new BLException(GlobalStrings.AValidVendorBankIsRequired);
                }
                VendorBankNumber = Payment_Common.FillZero(Payment_Common.GetOnlyNumbers(TmpElec.VendorBankAcctNumber), 17);
                TotalAmount      = TotalAmount + (TmpElec.DocCheckAmt);

                //eb3:
                //TotalNumber = TotalNumber + Compatibility.Convert.ToInt32(VendBank.DFIIdentification);
                //eb4: the last digit in the BankRoutingNum is a check digit so need to strip it off
                //TotalNumber = TotalNumber + Compatibility.Convert.ToInt32(BankAcct.BankRoutingNum);
                TotalNumber = TotalNumber + Compatibility.Convert.ToInt32(BankAcct.BankRoutingNum.Substring(0, BankAcct.BankRoutingNum.Length - 1));

                Payment = Payment + 1;
                if (String.IsNullOrEmpty(TmpElec.VendorBankAcctNumber))
                {
                    throw new BLException(GlobalStrings.AValidSupplBankAccountNumberIsRequi);
                }
                //SAmount = this.cnvAmount(Compatibility.Convert.ToString((TmpElec.DocCheckAmt * 100), "9999999999"), 10);
                SAmount = this.cnvAmount(Compatibility.Convert.ToString((TmpElec.DocCheckAmt * 100), "999999999999999999"), 18);

                //eb5:  (right justify, zero filled, 18 characters)
                //SCheckingAccount = string.Format("{0:00000000000000000000}", BankAcct.CheckingAccount);
                CheckingAccount  = Convert.ToDecimal(BankAcct.CheckingAccount);
                SCheckingAccount = string.Format("{0:00000000000000000000}", CheckingAccount);
                //SCheckNum = Compatibility.Convert.ToString(TmpElec.CheckNum);
                SCheckNum = string.Format("{0:000000000000000000}", TmpElec.CheckNum);
                string SBankName = "";
                for (int i = 0; i < BankAcct.BankName.Length; i++)
                {
                    SBankName += BankAcct.BankName[i];
                }

                /* 6 - Entry Detail transaction information */
                ttOutFileLine = new SFCommon.OutFileLine();

                EISFCommon.ttOutFileLineRows.Add(ttOutFileLine);
                ttOutFileLine.HeadNum  = TmpElec.HeadNum;
                ttOutFileLine.Line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 0, "P", 1); //Record Type
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, " ", 1); //Filler

                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 2, BankAcct.CheckingAccount, 20);  //Account  Number
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 2, SCheckingAccount, 20);                                                                                                                                                                                                  //Account  Number
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 22, " ", 1);                                                                                                                                                                                                               //Filler

                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 23, SCheckNum, 18);                                                                                                                                                                                                        //Serial/Check Number
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 41, " ", 1);                                                                                                                                                                                                               //Filler

                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 42, SAmount, 18);                                                                                                                                                                                                          //Amount
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 60, " ", 1);                                                                                                                                                                                                               //Filler

                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 61, Compatibility.Convert.ToString(((DateTime)CurCheckDate).Year, "9999") + Compatibility.Convert.ToString(((DateTime)CurCheckDate).Month, "99") + Compatibility.Convert.ToString(((DateTime)CurCheckDate).Day, "99"), 8); //Issue Date
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 69, " ", 1);                                                                                                                                                                                                               //Filler

                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 70, Compatibility.Convert.ToString(((DateTime)CurCheckDate).Year, "9999") + Compatibility.Convert.ToString(((DateTime)CurCheckDate).Month, "99") + Compatibility.Convert.ToString(((DateTime)CurCheckDate).Day, "99"), 8); //Paid Date
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 78, " ", 1);                                                                                                                                                                                                               //Filler

                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 79, "", 15);                                                                                                                                                                                                               //Additional Data

                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 94, TmpElec.VendorBankNameOnAccount, 50);                                                                                                                                                                                  //Expanded Additional Data (Payee Name)
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 144, "", 50);                                                                                                                                                                                                              //2nd Payee Name
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 194, "", 6);                                                                                                                                                                                                               //Filler
            }/* for each TmpElec: */
             /* convert amounts and numbers to string and replace speces with zeros */

            STotalAmount = this.cnvAmount(Compatibility.Convert.ToString((TotalAmount * 100), "9999999999"), 12);
            STotalNumber = this.cnvAmount(Compatibility.Convert.ToString(TotalNumber), 10);

            SPayment = this.cnvAmount(Compatibility.Convert.ToString(Payment), 6);
            Sblocks  = this.cnvAmount(Compatibility.Convert.ToString(Payment + 4), 6);


            /* 8 - Batch control record information */
            //eb5: only need detail lines for positive pay, so take out this whole section


            /* 9 - file control record information */
            //eb5: only need detail lines for positive pay, so take out this whole section
        }
        ///<summary>
        ///  Parameters:  none
        ///</summary>

        /* stucture JPMorgan NACHA format:
         *  1 line of file header information
         *  1 line of batch header information
         *      n Entry detail transaction records
         *  1 line of batch control information
         *  1 line of File control information.
         */
        private void buildInfo(List <Payment_Def.TmpElec> ttTmpElecRows)
        {
            Payment_Def.TmpElec TmpElec = null;
            string   ImmediateOrigine   = string.Empty;
            DateTime?CurCheckDate       = null;
            string   CompanyBankAcct    = string.Empty;
            string   VendorBankNumber   = string.Empty;

            //eb1:
            string SelfBankNumber = string.Empty;

            decimal TotalAmount  = decimal.Zero;
            decimal TotalNumber  = decimal.Zero;
            int     Payment      = 0;
            string  STotalAmount = string.Empty;
            string  STotalNumber = string.Empty;
            string  SPayment     = string.Empty;
            string  Sblocks      = string.Empty;
            string  SAmount      = string.Empty;
            //eb6:
            int Record6Count = 0;

            #region >>===== ABL Source ================================>>
            //
            //find first TmpElec no-lock no-error;
            //
            #endregion == ABL Source =================================<<

            TmpElec = (from ttTmpElec_Row in ttTmpElecRows select ttTmpElec_Row).FirstOrDefault();

            if (TmpElec == null)
            {
                throw new BLException(GlobalStrings.InterErrorTmpElecHasNoRecords);
            }
            else
            {
                CurCheckDate = TmpElec.ProcessDate;
            }



            #region >>===== ABL Source ================================>>
            //
            //FIND first Company WHERE Company.Company = CUR-COMP no-lock
            //
            #endregion == ABL Source =================================<<

            Company = this.FindFirstCompany(Session.CompanyID);
            if (Company == null)
            {
                throw new BLException(GlobalStrings.CompanyNotFound);
            }

            //eb7:
            //ImmediateOrigine = "1" + System.Text.RegularExpressions.Regex.Replace(Company.FEIN, "[^0-9]", "");

            #region >>===== ABL Source ================================>>
            //
            //FIND first BankAcct WHERE BankAcct.Company = Cur-comp and BankAcct.BankAcctID = TmpElec.FromBankAcctID no-lock
            //
            #endregion == ABL Source =================================<<


            BankAcct = this.FindFirstBankAcct(Session.CompanyID, TmpElec.FromBankAcctID);
            if (BankAcct == null)
            {
                throw new BLException(GlobalStrings.AValidFromBankAcctIsRequired);
            }
            CompanyBankAcct = ((10 > 0) ? "b".PadRight(10 + "b".Length, 'b') : null);
            if (BankAcct.CheckingAccount.Length <= 10)
            {
                ErpUtilities.Overlay(CompanyBankAcct, (11 - BankAcct.CheckingAccount.Length), BankAcct.CheckingAccount, 10);
            }
            else
            {
                throw new BLException(GlobalStrings.CheckingNumberIsTooLong);
            }

            //eb1:
            SelfBankNumber = String.Format("{0:00000000000000000000}", Convert.ToDouble(Payment_Common.BankAccount(BankAcct.CheckingAccount)));

            //eb7:
            ImmediateOrigine = BankAcct.ImmediateOrigin_c;


            if (EISFCommon.ttOutFileLineRows == null)
            {
                EISFCommon.ttOutFileLineRows = new List <SFCommon.OutFileLine>();
            }
            else
            {
                EISFCommon.ttOutFileLineRows.Clear();
            }

            /* 1 - file header information */
            ttOutFileLine = new SFCommon.OutFileLine();

            EISFCommon.ttOutFileLineRows.Add(ttOutFileLine);
            ttOutFileLine.Line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 0, "1", 1);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, "01", 2);

            //eb1:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 3, CompanyBankAcct, 10);
            //spec example: 0021000021
            //BankAcct.CheckingAccount = 390198528
            //eb2:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 3, BankAcct.CheckingAccount, 10);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 3, " 021000021", 10);


            //eb2:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 13, ImmediateOrigine, 10);
            //eb7:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 13, "8184584039", 10);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 13, ImmediateOrigine, 10);

            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 23, Compatibility.Convert.ToString(CompanyTime.Today().Day, "99") + Compatibility.Convert.ToString(CompanyTime.Today().Month, "99") + Compatibility.Convert.ToString(CompanyTime.Today().Year, "9999").SubString(2, 2), 6);
            //eb7:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 23, DateTime.Now.ToString("yyMMdd"), 6);
            DateTime checkDate = (DateTime)TmpElec.CheckDate;
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 23, checkDate.ToString("yyMMdd"), 6);


            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 29, Compatibility.Convert.TimeToString(CompanyTime.Now(), "HH:MM").Replace(":", ""), 4);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 29, DateTime.Now.ToString("HHmm"), 4);

            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 33, Compatibility.Convert.ToString(CompanyTime.Today().Day, "99").SubString(1, 1), 1);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 33, "A", 1);


            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 34, "094", 3);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 37, "10", 2);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 39, "1", 1);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 40, "JPMORGAN CHASE", 23);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 63, Company.Name.ToUpperInvariant().SubString(0, 23), 23);/* long company name */


            /* 5 - batch header information */
            ttOutFileLine = new SFCommon.OutFileLine();

            EISFCommon.ttOutFileLineRows.Add(ttOutFileLine);
            ttOutFileLine.Line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 0, "5", 1);

            //eb1:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, "200", 3);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, "220", 3);

            //eb3:
            ////eb1: chase wants this blank as per the spec
            ////ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 4, Company.Name.ToUpperInvariant().SubString(0, 16), 16);  /* short company name */
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 4, "", 16);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 4, Company.Name.ToUpperInvariant().SubString(0, 16), 16);              /* short company name */

            //eb1: was missing, not sure why:
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 20, SelfBankNumber, 20);


            // COMPANY IDENTIFICATION (Assigned by JPMC)
            //eb2:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 40, ImmediateOrigine, 10);
            //eb7:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 40, "9198528000", 10);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 40, ImmediateOrigine, 10);

            // STANDARD ENTRY CLASS CODE
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 50, "PPD", 3);
            //eb8:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 50, "CCD", 3);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 50, "CTX", 3);

            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 53, "PAYROLL", 10);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 53, "ACH PMT", 10);

            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 63, GlobalStrings.JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC.Entry(CompanyTime.Today().Month - 1, ',') + " " + Compatibility.Convert.ToString(CompanyTime.Today().Year, "9999").SubString(2, 2), 6);
            //eb7:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 63, DateTime.Now.ToString("MMM dd"), 6);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 63, checkDate.ToString("MMM dd"), 6);


            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 69, Compatibility.Convert.ToString(((DateTime)CurCheckDate).Day, "99") + Compatibility.Convert.ToString(((DateTime)CurCheckDate).Month, "99") + Compatibility.Convert.ToString(((DateTime)CurCheckDate).Year, "9999").SubString(2, 2), 6);
            //eb7:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 69, DateTime.Now.ToString("yyMMdd"), 6);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 69, checkDate.ToString("yyMMdd"), 6);

            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 75, "", 3);


            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 78, "1", 1);

            // bank routing number first 8 digits
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 79, ImmediateOrigine.SubString(1, 8), 8);
            //eb3:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 79, BankAcct.BankRoutingNum.SubString(0, 8), 8);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 79, "02100002", 8);

            // batch number
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 87, "0000001", 7);

            /* transactions */


            #region >>===== ABL Source ================================>>
            //
            //for each TmpElec:
            //
            //
            //
            //
            #endregion == ABL Source =================================<<

            foreach (var _TmpElec in ttTmpElecRows)
            {
                TmpElec = _TmpElec;

                #region >>===== ABL Source ================================>>
                //
                //FIND first VendBank WHERE VendBank.Company = cur-comp and
                //                                  VendBank.VendorNum = TmpElec.VendorNum and
                //                                  VendBank.BankID = TmpElec.VendorBankID  no-lock
                //
                #endregion == ABL Source =================================<<

                VendBank = this.FindFirstVendBank(Session.CompanyID, TmpElec.VendorNum, TmpElec.VendorBankID);
                if (VendBank == null)
                {
                    throw new BLException(GlobalStrings.AValidVendorBankIsRequired);
                }
                VendorBankNumber = Payment_Common.FillZero(Payment_Common.GetOnlyNumbers(TmpElec.VendorBankAcctNumber), 17);
                TotalAmount      = TotalAmount + (TmpElec.DocCheckAmt);

                //eb3:
                //TotalNumber = TotalNumber + Compatibility.Convert.ToInt32(VendBank.DFIIdentification);
                //eb4: the last digit in the BankRoutingNum is a check digit so need to strip it off
                //TotalNumber = TotalNumber + Compatibility.Convert.ToInt32(BankAcct.BankRoutingNum);
                TotalNumber = TotalNumber + Compatibility.Convert.ToInt32(BankAcct.BankRoutingNum.Substring(0, BankAcct.BankRoutingNum.Length - 1));

                Payment = Payment + 1;
                if (String.IsNullOrEmpty(TmpElec.VendorBankAcctNumber))
                {
                    throw new BLException(GlobalStrings.AValidSupplBankAccountNumberIsRequi);
                }
                SAmount = this.cnvAmount(Compatibility.Convert.ToString((TmpElec.DocCheckAmt * 100), "9999999999"), 10);


                /* 6 - Entry Detail transaction information */
                ttOutFileLine = new SFCommon.OutFileLine();

                //eb6:
                Record6Count += 1;

                EISFCommon.ttOutFileLineRows.Add(ttOutFileLine);
                ttOutFileLine.HeadNum  = TmpElec.HeadNum;
                ttOutFileLine.Line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 0, "6", 1);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, "22", 2);    /*vendbank.Character03 or hardcode:"22":U   checking */

                //eb2:  changes needed here: sh be...  position 4-12 : Receiving DFI Routing Number
                //		that was definition in one doc, the proper doc says:
                //			4-11	RECEIVING DFI ID	Must be a valid Routing Number
                //			12-12	CHECK DIGIT			Routing Number Check Digit
                //		SOOO... the last digit in routing number is a check digit
                //		SOOO... when using routing number later, strip off the last digit
                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 3, ((VendBank.DFIIdentification.Length > 7) ? VendBank.DFIIdentification.Substring(0, 8) : string.Empty), 8);  /* ROUTING NUMBER */
                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 11, ((VendBank.DFIIdentification.Length > 8) ? VendBank.DFIIdentification.Substring(8, 1) : string.Empty), 1);  /* ROUTING NUMBER CHECK DIGIT */
                //eb5:
                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 3, BankAcct.BankRoutingNum, 9);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 3, VendBank.SwiftNum, 9);

                //eb2:  changes needed here: sh be...  position 13-29 : Receving DFI account number
                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 12, VendorBankNumber, 17);
                //eb5:
                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 12, BankAcct.CheckingAccount, 17);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 12, VendBank.BankAcctNumber, 17);

                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 29, SAmount, 10);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 39, TmpElec.VendorBankID, 15);  /* or maybe tmpElect.VendorAccountRef ?*/

//zzz
                //eb8:
                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 54, TmpElec.VendorBankNameOnAccount.Trim().SubString(0, 22), 22);
                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 78, "0", 1);
                ////eb3:
                ////ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 79, ImmediateOrigine.SubString(1, 8) + Compatibility.Convert.ToString(Payment, "9999999"), 15);
                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 79, "02100002", 8);
                //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 87, "0000001", 7);
                int record7TotalCount = 0;
                int record7Yes        = 0;
                foreach (var APTran_iterator in (this.SelectAPTran(Session.CompanyID, TmpElec.HeadNum)))
                {
                    if (APTran_iterator.InvoiceNum != "")
                    {
                        record7TotalCount += 1;
                        record7Yes         = 1;
                    }
                }
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 54, record7TotalCount.ToString("D4"), 4);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 58, TmpElec.VendorBankNameOnAccount.Trim().SubString(0, 16), 16);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 74, "  ", 2);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 76, "  ", 2);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 78, record7Yes.ToString(), 1);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 79, "02100002", 8);
                ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 87, "0000001", 7);



                //eb7:
                //invoices:
                //this is a list of invoice numbers
                /* 7 - Addenda Record */
                //eb8: moved this up:

                /*
                 * int record7TotalCount = 0;
                 * foreach (var APTran_iterator in (this.SelectAPTran(Session.CompanyID, TmpElec.HeadNum)))
                 * {
                 *      if (APTran_iterator.InvoiceNum != "")
                 *      {
                 *              record7TotalCount += 1;
                 *      }
                 * }
                 */

                int record7Counter = 0;
                foreach (var APTran_iterator in (this.SelectAPTran(Session.CompanyID, TmpElec.HeadNum)))
                {
                    if (APTran_iterator.InvoiceNum != "")
                    {
                        record7Counter += 1;

                        ttOutFileLine          = new SFCommon.OutFileLine();
                        ttOutFileLine.Line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
                        EISFCommon.ttOutFileLineRows.Add(ttOutFileLine);

                        ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 0, "7", 1);
                        //eb8:
                        //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, "200", 3);
                        ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, "05", 2);

                        ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 3, "Invoice " + APTran_iterator.InvoiceNum.ToString(), 80);

                        //KEEP for testing:
                        //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 40, "HeadNum " + TmpElec.HeadNum, 40);

                        ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 83, record7TotalCount.ToString("D4"), 4);
                        ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 87, record7Counter.ToString("D7"), 7);
                    }
                }
            }/* for each TmpElec: */
             /* convert amounts and numbers to string and replace speces with zeros */

            STotalAmount = this.cnvAmount(Compatibility.Convert.ToString((TotalAmount * 100), "9999999999"), 12);
            //eb6:
            //STotalNumber = this.cnvAmount(Compatibility.Convert.ToString(TotalNumber), 10);
            STotalNumber = this.cnvAmount(Compatibility.Convert.ToString(Record6Count * 02100002), 10);


            SPayment = this.cnvAmount(Compatibility.Convert.ToString(Payment), 6);
            Sblocks  = this.cnvAmount(Compatibility.Convert.ToString(Payment + 4), 6);



            /* 8 - Batch control record information */
            ttOutFileLine = new SFCommon.OutFileLine();

            EISFCommon.ttOutFileLineRows.Add(ttOutFileLine);
            ttOutFileLine.Line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 0, "8", 1);

            //eb1:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, "200", 3);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, "220", 3);

            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 4, SPayment, 6);

            //The sum of positions 4-11 of all Entry Detail (6) Records in the batch.
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 10, STotalNumber, 10);

            //Must equal the total debit dollar amount in the batch.
            //eb4:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 20, STotalAmount, 12);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 20, "000000000000", 12);

            //Must equal the total credit dollar amount in the batch.
            //eb4:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 32, "0", 12);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 32, STotalAmount, 12);

            //eb2:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 44, ImmediateOrigine, 10);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 44, "9198528000", 10);

            //eb2:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 79, ImmediateOrigine.SubString(1, 8), 8);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 79, "02100002", 8);


            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 87, "0000001", 7);


            /* 9 - file control record information */
            ttOutFileLine = new SFCommon.OutFileLine();

            EISFCommon.ttOutFileLineRows.Add(ttOutFileLine);
            ttOutFileLine.Line_out = ((lineLen > 0) ? " ".PadRight(lineLen + " ".Length, ' ') : null);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 0, "9", 1);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 1, "000001", 6);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 7, Sblocks, 6);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 13, "00" + SPayment, 8);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 21, STotalNumber, 10);

            //eb4:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 31, STotalAmount, 12);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 31, "000000000000", 12);

            //eb4:
            //ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 43, "0", 12);
            ttOutFileLine.Line_out = ErpUtilities.Overlay(ttOutFileLine.Line_out, 43, STotalAmount, 12);
        }