/// <summary>
        /// Method to close batch
        /// </summary>
        /// <param name="posId">Pos Id</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="registerNumber">Register number</param>
        /// <param name="error">Error message</param>
        /// <returns>List of report</returns>
        public List <Report> CloseBatch(byte posId, int tillNumber, int saleNumber, byte registerNumber, out ErrorMessage error)
        {
            var   reports = new List <Report>();
            short termNos = 0;

            string[,] Terminals = new string[3, 3];
            short    i               = 0;
            string   rFileName       = "";
            DateTime batchDate       = default(DateTime);
            bool     blnNoDebitTrans = false;
            var      emvProcess      = _policyManager.EMVVersion;
            var      offSet          = _policyManager.LoadStoreInfo().OffSet;
            var      sale            = _saleManager.GetCurrentSale(saleNumber, tillNumber, registerNumber, UserCode, out error);

            if (!string.IsNullOrEmpty(error?.MessageStyle?.Message))
            {
                return(null);
            }
            var rFileNumber = (short)(FileSystem.FreeFile());

            try
            {
                if (GetConnection())
                {
                    var terminals = _maintenanceService.GetTerminalIds(posId);
                    if (terminals == null)
                    {
                        WriteToLogFile("***PROBLEM WITH CLOSE BATCH*** " + " " + _resourceManager.GetResString(offSet, 1287)); // Shiny Mar6, 2008 -EKO
                                                                                                                               //MsgBoxStyle temp_VbStyle = (int)MsgBoxStyle.Critical + MsgBoxStyle.OkOnly;
                                                                                                                               //Chaps_Main.DisplayMessage(12, (short)87, temp_VbStyle, null, (byte)0);
                        error = new ErrorMessage
                        {
                            MessageStyle = _resourceManager.CreateMessage(offSet, 12, 87, null, CriticalOkMessageType)
                        };
                        return(null);
                    }
                    //ButtonsEnabled(false);
                    rFileName = Path.GetTempPath() + "BankEod_ " + PosId + ".txt";
                    FileSystem.FileOpen(rFileNumber, rFileName, OpenMode.Append);
                    termNos = 0;
                    foreach (Terminal terminal in terminals)
                    {
                        if (string.IsNullOrEmpty(terminal.TerminalType) || string.IsNullOrEmpty(terminal.TerminalId))
                        {
                            WriteToLogFile("***PROBLEM WITH CLOSE BATCH***" + " " + _resourceManager.GetResString(offSet, 1287)); // Shiny Mar6, 2008 -EKO
                                                                                                                                  //MsgBoxStyle temp_VbStyle2 = (int)MsgBoxStyle.Critical + MsgBoxStyle.OkOnly;
                                                                                                                                  //Chaps_Main.DisplayMessage(this, (short)87, temp_VbStyle2, null, (byte)0);
                            error = new ErrorMessage
                            {
                                MessageStyle = _resourceManager.CreateMessage(offSet, 12, 87, null, CriticalOkMessageType)
                            };
                            FileSystem.FileClose(rFileNumber);
                            return(null);
                        }

                        modTPS.cc = new Credit_Card();

                        WriteToLogFile("EMVprocess:" + Convert.ToString(emvProcess));
                        SendToTps(_cardManager.GetRequestString(ref modTPS.cc, sale, "EODTerminal", terminal.TerminalType, 0, terminal.TerminalId), ref modTPS.cc, emvProcess);
                        var eodTimer = DateAndTime.Timer;
                        while (Convert.ToInt32(DateAndTime.Timer - Convert.ToDouble(eodTimer)) < 120) // shiny changed this waiting to 2 minutes- 4 is too much 240)
                        {
                            if (modTPS.cc.Response.Length > 0)
                            {
                                break;
                            }
                        }

                        if (modTPS.cc.Response.ToUpper() == "APPROVED")
                        {
                            termNos++;
                            Terminals[termNos, 1] = modTPS.cc.TerminalID;
                            Terminals[termNos, 2] = modTPS.cc.Sequence_Number;
                            FileSystem.PrintLine(rFileNumber, modTPS.cc.Report);
                            batchDate = modTPS.cc.Trans_Date;
                            WriteToLogFile("SUCCESS WITH CLOSE BATCH"); // Shiny Mar6, 2008 -EKO

                            //  - added as part of Datawire Integeration (added by Mina)
                            //#:5:TPS does handshake after sending EOD for debit. If there weren’t any debit transactions between closes batches, POS has to send special indication that there weren’t any debit transactions. Having gotten that flag, TPS doesn’t do handshake.
                            if (Strings.UCase(Convert.ToString(_policyManager.BankSystem)) == "GLOBAL")
                            {
                                blnNoDebitTrans = modTPS.cc.Report.IndexOf("No Transactions", StringComparison.Ordinal) + 1 > 0;
                            }
                            _maintenanceService.SetCloseBatchNumber(modTPS.cc);
                        }
                        else // Behrooz Jan-09
                        {
                            if (modTPS.cc.Receipt_Display.Length > 0)
                            {
                                WriteToLogFile("***PROBLEM WITH CLOSE BATCH***" + " " + modTPS.cc.Receipt_Display); // Shiny Mar6, 2008 -EKO
                                                                                                                    //Chaps_Main.DisplayMsgForm(modTPS.cc.Receipt_Display, (short)100, null, (byte)0, (byte)0, "", "", "", "");
                                error = new ErrorMessage
                                {
                                    MessageStyle = new MessageStyle
                                    {
                                        Message     = modTPS.cc.Receipt_Display,
                                        MessageType = MessageType.OkOnly
                                    }
                                };
                                FileSystem.FileClose(rFileNumber);
                                return(null);
                            }
                            else
                            {
                                WriteToLogFile("***PROBLEM WITH CLOSE BATCH***" + " " + _resourceManager.GetResString(offSet, 1284)); // Shiny Mar6, 2008 -EKO
                                                                                                                                      //Chaps_Main.DisplayMsgForm((Convert.ToDouble(12)) * 100 + 84, (short)99, null, (byte)0, (byte)0, "", "", "", "");
                                error = new ErrorMessage
                                {
                                    MessageStyle = new MessageStyle
                                    {
                                        Message     = _resourceManager.GetResString(offSet, 1284),
                                        MessageType = MessageType.OkOnly
                                    }
                                };
                                FileSystem.FileClose(rFileNumber);
                                return(null);
                            }
                        }
                        modTPS.cc = null;
                        i++;
                    }
                }
                else
                {
                    WriteToLogFile("***PROBLEM WITH CLOSE BATCH***" + " " + _resourceManager.GetResString(offSet, 1296)); // Shiny Mar6, 2008 -EKO
                                                                                                                          //Chaps_Main.DisplayMsgForm((Convert.ToDouble(12)) * 100 + 96, (short)99, null, (byte)0, (byte)0, "", "", "", "");
                    error = new ErrorMessage
                    {
                        MessageStyle = new MessageStyle
                        {
                            Message     = _resourceManager.GetResString(offSet, 1296),
                            MessageType = MessageType.OkOnly
                        }
                    };
                    //return;
                }

                FileSystem.FileClose(rFileNumber);
                if (!string.IsNullOrEmpty(rFileName))
                {
                    var stream = File.OpenRead(rFileName);
                    FileSystem.FileClose(rFileNumber);
                    var bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, Convert.ToInt32(stream.Length));
                    stream.Close();
                    var content = Convert.ToBase64String(bytes);
                    reports.Add(new Report
                    {
                        ReportName    = "BankEod.txt",
                        ReportContent = content,
                        Copies        = 1
                    });
                }
                if (termNos == i)
                {
                    if (GetConnection()) //Nancy
                    {
                        //  - Datawire Integration (Added by Mina)
                        //#5: TPS does handshake after sending EOD for debit. If there weren’t any debit transactions between closes batches, POS has to send special indication that there weren’t any debit transactions. Having gotten that flag, TPS doesn’t do handshake.
                        if (Strings.UCase(Convert.ToString(_policyManager.BankSystem)) == "GLOBAL")
                        {
                            if (blnNoDebitTrans) //Added by Mina
                            {
                                SendToTps(_cardManager.GetRequestString(ref modTPS.cc, sale, "CloseBatchInside", "NoDebit", 0, ""), ref modTPS.cc, emvProcess);
                            }
                            else
                            {
                                SendToTps(_cardManager.GetRequestString(ref modTPS.cc, sale, "CloseBatchInside", "Credit", 0, ""), ref modTPS.cc, emvProcess);
                            }
                        }
                        else
                        {
                            SendToTps(_cardManager.GetRequestString(ref modTPS.cc, sale, "CloseBatchInside", "Credit", 0, ""), ref modTPS.cc, emvProcess);
                        }
                    }
                    else
                    {
                        return(null); //Call DisplayMsgForm(Me.Tag * 100 + 96, 99)
                    }
                }
                if (termNos > 0)
                {
                    //modPrint.Dump_To_Printer(RFileName, (short)1, true, true, false);
                    //FileStream fs = new FileStream(RFileName, FileMode.Open, FileAccess.Read);
                    var date      = DateTime.Parse("12:00:00 AM");
                    var eodReport = _tillCloseManager.PrintEodDetails(tillNumber, ref date, ref date, Terminals[1, 1],
                                                                      Terminals[1, 2], Terminals[2, 1], Terminals[2, 2], false, batchDate);
                    reports.Add(eodReport);
                }
                return(reports);
            }
            finally
            {
                if (!string.IsNullOrEmpty(rFileName))
                {
                    FileSystem.Kill(rFileName);
                }
            }
        }