/// <summary>
        /// Deletes cheque requests for client or office.
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service</param>
        /// <param name="selectedChequeRequests">Collection of cheque requests for client or office for deletion</param>
        /// <param name="isClientChequeRequest">Flag whether deletion is for client or office</param>
        /// <returns>Deletes cheque requests for client or office.</returns>
        public ChequeRequestReturnValue DeleteChequeRequests(Guid logonId, List<int> selectedChequeRequestsIds, bool isClientChequeRequest)
        {
            ChequeRequestReturnValue returnValue = new ChequeRequestReturnValue();

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid);
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                            // Can do everything
                            break;
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            throw new Exception("Access denied");
                        default:
                            throw new Exception("Access denied");
                    }

                    if (selectedChequeRequestsIds.Count > 0)
                    {
                        SrvClientChequeRequest srvClientChequeRequest = null;
                        SrvOfficeChequeRequest srvOfficeChequeRequest = null;

                        if (isClientChequeRequest)
                        {
                            srvClientChequeRequest = new SrvClientChequeRequest();
                        }
                        else
                        {
                            srvOfficeChequeRequest = new SrvOfficeChequeRequest();
                        }

                        for (int index = 0; index < selectedChequeRequestsIds.Count; index++)
                        {
                            int chequeRequestId = selectedChequeRequestsIds[index];

                            if (isClientChequeRequest)
                            {
                                srvClientChequeRequest.Delete(chequeRequestId, UserInformation.Instance.UserMemberId, DateTime.Now);
                            }
                            else
                            {
                                srvOfficeChequeRequest.Delete(chequeRequestId, UserInformation.Instance.UserMemberId, DateTime.Now);
                            }
                        }
                    }
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Message = ex.Message;
            }

            return returnValue;
        }
        /// <summary>
        /// Adds or edits client cheque requests depending on the 'IsClientChequeRequest' property
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service</param>
        /// <param name="chequeRequest">ChequeRequest properties to add/edit cheque request.</param>
        /// <returns>Returns cheque request id after adding or editting cheque request.</returns>
        public ChequeRequestReturnValue SaveClientChequeRequest(Guid logonId, ChequeRequest clientChequeRequest)
        {
            ChequeRequestReturnValue returnValue = new ChequeRequestReturnValue();

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid);
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                            // Can do everything
                            break;
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            throw new Exception("Access denied");
                        default:
                            throw new Exception("Access denied");
                    }

                    //243 = RequestClientCredits
                    //242 = RequestClientDebits

                    if (clientChequeRequest.ClientChequeRequestsIsCredit)
                        if (!UserSecuritySettings.GetUserSecuitySettings((int)AccountsSettings.RequestClientCredits))
                            //if (!UserSecuritySettings.GetUserSecuitySettings(243))
                            throw new Exception("You do not have sufficient permissions to carry out this request");

                    if (!clientChequeRequest.ClientChequeRequestsIsCredit)
                        if (!UserSecuritySettings.GetUserSecuitySettings((int)AccountsSettings.RequestClientDebits))
                            //if (!UserSecuritySettings.GetUserSecuitySettings(242))
                            throw new Exception("You do not have sufficient permissions to carry out this request");

                    string errorMessage = string.Empty;
                    string warningMessage = string.Empty;
                    string errorCaption = string.Empty;

                    // Creates object for client cheque request service class
                    SrvClientChequeRequest srvClientChequeRequest = new SrvClientChequeRequest();

                    // Sets properties
                    srvClientChequeRequest.Id = clientChequeRequest.ChequeRequestId;
                    srvClientChequeRequest.ProjectId = clientChequeRequest.ProjectId;
                    srvClientChequeRequest.Date = clientChequeRequest.ChequeRequestDate;
                    srvClientChequeRequest.ClientBankId = clientChequeRequest.BankId;
                    srvClientChequeRequest.Description = clientChequeRequest.ChequeRequestDescription;
                    srvClientChequeRequest.Payee = clientChequeRequest.ChequeRequestPayee;
                    srvClientChequeRequest.Amount = clientChequeRequest.ChequeRequestAmount;
                    srvClientChequeRequest.Reference = clientChequeRequest.ChequeRequestReference;
                    srvClientChequeRequest.MemberId = clientChequeRequest.MemberId;
                    srvClientChequeRequest.ClearanceDaysChq = clientChequeRequest.ClientChequeRequestsClearanceDaysChq;
                    srvClientChequeRequest.ClearanceDaysElec = clientChequeRequest.ClientChequeRequestsClearanceDaysElec;
                    srvClientChequeRequest.ClearanceTypeId = clientChequeRequest.ClearanceTypeId;
                    srvClientChequeRequest.IsCredit = clientChequeRequest.ClientChequeRequestsIsCredit;

                    if (clientChequeRequest.ProceedIfOverDrawn)
                    {
                        // If the 'ProceedIfOverDrawn' flag is false then it should be true for next
                        // save click event. As its false for warning messages.
                        srvClientChequeRequest.ProceedIfOverDrawn = true;
                    }

                    returnValue.Success = srvClientChequeRequest.Save(out errorMessage, out warningMessage, out errorCaption);

                    if (returnValue.Success)
                    {
                        // if client cheque request is saved then authorises it.
                        if (clientChequeRequest.IsChequeRequestAuthorised && UserSecuritySettings.GetUserSecuitySettings((int)AccountsSettings.AuthoriseClientChequeRequest))
                        {
                            if (UserSecuritySettings.GetUserSecuitySettings((int)AccountsSettings.AuthoriseChequeRequestHigherAmount))
                            {
                                // As Suggested by client to use the overloaded method and requestId property
                                if (srvClientChequeRequest.RequesterId == UserInformation.Instance.DbUid)
                                {
                                    SrvClientChequeRequestCommon.AddAuthoriseClientChequeRequests(srvClientChequeRequest.Id, UserInformation.Instance.UserMemberId, DateTime.Now);
                                }
                                else
                                {
                                    SrvClientChequeRequestCommon.AddAuthoriseClientChequeRequests(srvClientChequeRequest.Id, UserInformation.Instance.UserMemberId, DateTime.Now, srvClientChequeRequest.RequesterId, srvClientChequeRequest.Description);
                                }
                            }
                            else
                            {
                                Decimal clientChequeRequestHigherAmount = Convert.ToDecimal(UserSecuritySettings.GetUserSecuitySettingsFeatureValue((int)AccountsSettings.ClientChequeRequestHigherAmount));

                                if (Convert.ToDecimal(srvClientChequeRequest.Amount) > clientChequeRequestHigherAmount)
                                {
                                    errorMessage = "You are not allowed to Authorise Client Cheque Requests over the value of £" +
                                                     clientChequeRequestHigherAmount.ToString("0.00") + ".";
                                }
                                else
                                {
                                    SrvClientChequeRequestCommon.AddAuthoriseClientChequeRequests(srvClientChequeRequest.Id, UserInformation.Instance.UserMemberId, DateTime.Now);
                                }
                            }
                        }

                        clientChequeRequest.ChequeRequestId = srvClientChequeRequest.Id;
                        returnValue.ChequeRequest = clientChequeRequest;
                    }

                    returnValue.Message = errorMessage;
                    returnValue.WarningMessage = warningMessage;
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Message = ex.Message;
            }

            return returnValue;
        }
        /// <summary>
        /// Loads client cheque request details
        /// </summary>
        /// <param name="logonId">Logon id obtained when logging on to the logon service</param>
        /// <param name="officeChequeRequestId">Client Cheque Request id to get details</param>
        /// <returns>Loads client cheque request details</returns>
        public ChequeRequestReturnValue LoadClientChequeRequestDetails(Guid logonId, int clientChequeRequestId)
        {
            ChequeRequestReturnValue returnValue = new ChequeRequestReturnValue();

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid);
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                            // Can do everything
                            break;
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            throw new Exception("Access denied");
                        default:
                            throw new Exception("Access denied");
                    }

                    SrvClientChequeRequest srvClientChequeRequest = new SrvClientChequeRequest();
                    srvClientChequeRequest.Id = clientChequeRequestId;
                    srvClientChequeRequest.Load();

                    ChequeRequest chequeRequest = new ChequeRequest();
                    chequeRequest.ProjectId = srvClientChequeRequest.ProjectId;
                    chequeRequest.ChequeRequestReference = srvClientChequeRequest.Reference;
                    chequeRequest.ChequeRequestDate = srvClientChequeRequest.Date;
                    chequeRequest.ChequeRequestDescription = srvClientChequeRequest.Description;
                    chequeRequest.ChequeRequestPayee = srvClientChequeRequest.Payee;
                    chequeRequest.BankId = srvClientChequeRequest.ClientBankId;
                    chequeRequest.ChequeRequestAmount = srvClientChequeRequest.Amount;
                    chequeRequest.IsChequeRequestAuthorised = srvClientChequeRequest.IsAuthorised;
                    chequeRequest.MemberId = srvClientChequeRequest.MemberId;
                    chequeRequest.ClientChequeRequestsIsCredit = srvClientChequeRequest.IsCredit;
                    chequeRequest.ClientChequeRequestsClearanceDaysElec = srvClientChequeRequest.ClearanceDaysElec;
                    chequeRequest.ClientChequeRequestsClearanceDaysChq = srvClientChequeRequest.ClearanceDaysChq;
                    chequeRequest.ClearanceTypeId = srvClientChequeRequest.ClearanceTypeId;

                    returnValue.ChequeRequest = chequeRequest;
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception Ex)
            {
                returnValue.Success = false;
                returnValue.Message = Ex.Message;
            }

            return returnValue;
        }