//Get Customer Invoices
        private string GetInvoices(Customer customer, int customerId, QuickBooksOnlineConnectionStringBuilder connString)
        {
            _logger.LogInfo("Start Add or update invoice operation for customer for customer id " + customerId + " for subscriber id " + subscriberId);
            // Need to clear the list
            invoiceList = new List <Invoice>();
            // To insert error log in catch statement, made this variable public
            currentMethodName = this.ControllerContext.RouteData.Values["action"].ToString();
            bool     addInvoice = false;
            int      CustId;
            string   QBIId;
            int      colIndex = 0;
            string   IDNbr    = "";
            DateTime IDate;
            DateTime IDueDate;
            Decimal  ITotalAmt;
            Decimal  IBalance;
            string   ITxns;

            try
            {
                using (QuickBooksOnlineConnection connInv = new QuickBooksOnlineConnection(connString.ToString()))
                {
                    connInv.RuntimeLicense = runTimeLicense;
                    using (QuickBooksOnlineCommand cmdInv = new QuickBooksOnlineCommand("Select * FROM Invoices WHERE CustomerRef = " + customer.QBCustomerId, connInv))
                    {
                        using (QuickBooksOnlineDataReader reader = cmdInv.ExecuteReader())
                        {
                            DateTime ILastPymtDate = DateTime.MaxValue;
                            DateTime ILastReminder = DateTime.MaxValue;
                            while (reader.Read())
                            {
                                //if (Int32.TryParse((string)reader["Id"], out int IId))
                                //{
                                //}
                                //else
                                //{
                                //    continue;
                                //}
                                QBIId     = reader.GetString("Id");
                                CustId    = customerId;
                                colIndex  = reader.GetOrdinal("DocNumber");
                                IDNbr     = reader.GetString(colIndex);
                                IDate     = reader.GetDateTime("TxnDate");
                                IDueDate  = reader.GetDateTime("DueDate");
                                ITotalAmt = reader.GetDecimal("TotalAmt");
                                IBalance  = reader.GetDecimal("Balance");
                                colIndex  = reader.GetOrdinal("LinkedTxnAggregate");
                                ITxns     = Validate.SafeGetString(reader, colIndex);
                                //Filter Invoices to keep
                                addInvoice = false;
                                if (IBalance > 0)
                                {
                                    // we always want to add the invoice if the balance > 0
                                    addInvoice = true;
                                }
                                // Get the last payment date
                                XmlDocument xDoc = new XmlDocument();
                                // Convert string to stream
                                byte[]       byteArray = Encoding.ASCII.GetBytes(ITxns);
                                MemoryStream stream    = new MemoryStream(byteArray);
                                if (stream.Length > 0)
                                {
                                    xDoc.Load(stream);
                                    XmlNodeList xnList = xDoc.SelectNodes("/LinkedTxnAggregate/Row");
                                    // If we have transaction information, process it
                                    if (xnList.Count > 0)
                                    {
                                        foreach (XmlNode xn in xnList)
                                        {
                                            string txnId   = xn["TxnId"].InnerXml;
                                            string txnType = xn["TxnType"].InnerXml;
                                            if (txnType == "Payment")
                                            {
                                                DateTime txnDate = GetPymtDate(txnId, connString, IDNbr);
                                                DateTime now     = DateTime.Now;
                                                //for test data
                                                //DateTime now = new DateTime(2014, 12, 31);
                                                int monthDiff = GetMonthDifference(now, txnDate);
                                                if (monthDiff < 6)
                                                {
                                                    ILastPymtDate = txnDate;
                                                    addInvoice    = true;
                                                    break;
                                                }
                                                else
                                                {
                                                    if (addInvoice == true)
                                                    {
                                                        //Balance is greater than zero
                                                        //Add the invoice
                                                        ILastPymtDate = txnDate;
                                                    }
                                                    else
                                                    {
                                                        addInvoice = false;
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                                // Don't add the invoice
                                if (addInvoice == false)
                                {
                                    continue;
                                }

                                invoiceList.Add(new Invoice
                                {
                                    InvoiceId        = 0,
                                    QBInvoiceId      = QBIId,
                                    CustomerId       = CustId,
                                    InvDocNbr        = IDNbr,
                                    InvDate          = IDate,
                                    InvDueDate       = IDueDate,
                                    InvTotalAmt      = ITotalAmt,
                                    InvBalance       = IBalance,
                                    InvTxns          = ITxns,
                                    InvLastPymtDate  = ILastPymtDate,
                                    InvLastReminder  = ILastReminder,
                                    SendAutoReminder = true
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("error occurred at invoice level" + ex.Message);
                _errorLogRepo.InsertErrorLog(new ErrorLog
                {
                    SubscriberId  = subscriberId,
                    ErrorMessage  = ex.Message,
                    InvDocNbr     = IDNbr,
                    ServiceName   = serviceName,
                    MethodName    = currentMethodName,
                    ErrorDateTime = DateTime.Now
                });
                return("Error occurred " + ex.Message);
            }

            foreach (var inv in invoiceList)
            {
                Invoice invoice = _invoiceRepo.GetByID(inv.CustomerId, inv.QBInvoiceId);
                if (invoice == null)
                {
                    // Need to add a invoice record
                    var result = _invoiceRepo.AddInvoice(inv);
                    if (result == false)
                    {
                        return("Not able to add Invoice.");
                    }
                }
                else
                {
                    // Need to update invoice
                    inv.InvoiceId = invoice.InvoiceId;
                    var result = _invoiceRepo.UpdateInvoice(inv);
                    if (result == false)
                    {
                        return("Not able to update Invoice.");
                    }
                }
            }
            _logger.LogInfo("End Add or update invoice operation for customer for customer id " + customerId + " for subscriber id " + subscriberId);
            return(SuccessMessage);
        }