public void IssueCreditMemo(ICreditMemoTenderLineItem creditMemoItem, IRetailTransaction transaction)
        {
            if (creditMemoItem == null)
            {
                throw new ArgumentNullException("creditMemoItem");
            }

            RetailTransaction retailTransaction = transaction as RetailTransaction;

            if (retailTransaction == null)
            {
                throw new ArgumentNullException("retailTransaction");
            }
            else
            {
                if (retailTransaction.SaleIsReturnSale == true && retailTransaction.AmountDue < 0)
                {
                    InputConfirmation inC = new InputConfirmation();
                    inC.PromptText = "Remarks";
                    inC.InputType  = InputType.Normal;

                    Interaction.frmInput Oinput = new Interaction.frmInput(inC);
                    Oinput.ShowDialog();
                    if (!string.IsNullOrEmpty(Oinput.InputText))
                    {
                        retailTransaction.PartnerData.Remarks = Oinput.InputText;
                    }
                    else
                    {
                        retailTransaction.PartnerData.Remarks = "";
                    }
                }
            }

            try
            {
                LogMessage("Issuing a credit memo....", LogTraceLevel.Trace, "CreditMemo.IssueCreditMemo");

                bool   retVal           = false;
                string comment          = string.Empty;
                string creditMemoNumber = string.Empty;
                string currencyCode     = ApplicationSettings.Terminal.StoreCurrency;

                try
                {
                    // Begin by checking if there is a connection to the Transaction Service
                    this.Application.TransactionServices.CheckConnection();

                    // Publish the credit memo to the Head Office through the Transaction Services...
                    this.Application.TransactionServices.IssueCreditMemo(ref retVal, ref comment, ref creditMemoNumber,
                                                                         retailTransaction.StoreId,
                                                                         retailTransaction.TerminalId,
                                                                         retailTransaction.OperatorId,
                                                                         retailTransaction.TransactionId,
                                                                         retailTransaction.ReceiptId,
                                                                         "1",
                                                                         currencyCode,
                                                                         creditMemoItem.Amount * -1,
                                                                         DateTime.Now);

                    retailTransaction.CreditMemoItem.CreditMemoNumber = creditMemoNumber;
                    retailTransaction.CreditMemoItem.Amount           = creditMemoItem.Amount * -1;
                    creditMemoItem.SerialNumber = creditMemoNumber;
                    creditMemoItem.Comment      = creditMemoNumber;
                }
                catch (LSRetailPosis.PosisException px)
                {
                    // We cannot publish the credit memo to the HO, so we need to take action...

                    retailTransaction.TenderLines.RemoveLast();
                    retailTransaction.CalcTotals();

                    retailTransaction.CreditMemoItem = (CreditMemoItem)this.Application.BusinessLogic.Utility.CreateCreditMemoItem();

                    LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), px);
                    throw;
                }
                catch (Exception x)
                {
                    // We cannot publish the credit memo to the HO, so we need to take action...

                    retailTransaction.TenderLines.RemoveLast();
                    retailTransaction.CalcTotals();
                    retailTransaction.CreditMemoItem = (CreditMemoItem)this.Application.BusinessLogic.Utility.CreateCreditMemoItem();

                    LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x);
                    throw new LSRetailPosis.PosisException(52300, x);
                }

                if (!retVal)
                {
                    LogMessage("Error storing the credit memo centrally...",
                               LSRetailPosis.LogTraceLevel.Error,
                               "CreditMemo.IssueCreditMemo");

                    retailTransaction.TenderLines.RemoveLast();
                    retailTransaction.CalcTotals();
                    retailTransaction.CreditMemoItem = (CreditMemoItem)this.Application.BusinessLogic.Utility.CreateCreditMemoItem();

                    throw new LSRetailPosis.PosisException(52300, new Exception(comment));
                }
            }
            catch (Exception x)
            {
                // Start :  On 14/07/2014
                foreach (SaleLineItem saleLineItem in retailTransaction.SaleItems)
                {
                    if (saleLineItem.ItemType == LSRetailPosis.Transaction.Line.SaleItem.BaseSaleItem.ItemTypes.Service)
                    {
                        updateCustomerAdvanceAdjustment(Convert.ToString(saleLineItem.PartnerData.ServiceItemCashAdjustmentTransactionID),
                                                        Convert.ToString(saleLineItem.PartnerData.ServiceItemCashAdjustmentStoreId),
                                                        Convert.ToString(saleLineItem.PartnerData.ServiceItemCashAdjustmentTerminalId), 0);
                    }
                }
                // End :  On 14/07/2014

                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x);
                throw;
            }
        }
        public void UpdateCreditMemo(string creditMemoNumber, decimal amount, IRetailTransaction retailTransaction, ICreditMemoTenderLineItem creditMemoTenderLineItem)
        {
            try
            {
                LogMessage("Marking a credit memo as used....", LogTraceLevel.Trace, "CreditMemo.UpdateCreditMemo");

                bool   retVal  = false;
                string comment = string.Empty;

                try
                {
                    // Begin by checking if there is a connection to the Transaction Service
                    this.Application.TransactionServices.CheckConnection();

                    this.Application.TransactionServices.UpdateCreditMemo(ref retVal, ref comment, creditMemoNumber,
                                                                          retailTransaction.StoreId,
                                                                          retailTransaction.TerminalId,
                                                                          retailTransaction.OperatorId,
                                                                          retailTransaction.TransactionId,
                                                                          retailTransaction.ReceiptId,
                                                                          "1",
                                                                          amount,
                                                                          DateTime.Now);
                }
                catch (Exception)
                {
                    LogMessage("Error updating the credit memo centrally, as used...",
                               LogTraceLevel.Error,
                               "CreditMemo.UpdateCreditMemo");
                }

                if (retVal == false)
                {
                    LogMessage("Error updating the credit memo centrally, as used...",
                               LogTraceLevel.Error,
                               "CreditMemo.UpdateCreditMemo");
                }
            }
            catch (Exception x)
            {
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x);
                throw;
            }
        }