private void customButtonVoid_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(comboBoxReason.Text))
            {
                MessageBox.Show("You must Select a void Reason");
                comboBoxReason.Focus();
                return;
            }

            ProcessTenderProcedures.ProcessTenderMode mode;
            List <PurchaseVO> purchaseList = new List <PurchaseVO>();

            purchaseList.Add(currentPurchase);
            bool transactionStarted = false;

            bool skipped;

            try
            {
                if ((voidBuyFlow && !voidVendorBuy) || voidReturnFlow)
                {
                    if (currentPurchase.Receipts != null)
                    {
                        string rcptId;

                        if (voidReturnFlow)
                        {
                            rcptId = (from receipt in currentPurchase.Receipts
                                      where (receipt.Event == ReceiptEventTypes.RET.ToString() &&
                                             receipt.RefNumber == currentPurchase.TicketNumber.ToString())
                                      select receipt).First().ReceiptDetailNumber;
                        }
                        else
                        {
                            rcptId = (from receipt in currentPurchase.Receipts
                                      where (receipt.Event == ReceiptEventTypes.PUR.ToString() &&
                                             receipt.RefNumber == currentPurchase.TicketNumber.ToString())
                                      select receipt).First().ReceiptDetailNumber;
                        }

                        VoidLoanForm.LoanVoidDetails lvd = new VoidLoanForm.LoanVoidDetails();
                        lvd.TickNum     = labelTransactionNo.Text;
                        lvd.StoreNum    = GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber;
                        lvd.OpRef       = labelTransactionNo.Text;
                        lvd.OpCode      = voidReturnFlow ? "Return" : "Purchase";
                        lvd.OpCd        = voidReturnFlow ? ReceiptEventTypes.VRET.ToString() : ReceiptEventTypes.VPR.ToString();
                        lvd.Amount      = Utilities.GetDecimalValue(currentPurchase.Amount, 0.0M);
                        lvd.HoldType    = "";
                        lvd.RecId       = Utilities.GetLongValue(rcptId);
                        lvd.PfiEligDate = Utilities.GetDateTimeValue(currentPurchase.PfiEligible, DateTime.MaxValue);
                        lvd.CreatedBy   = Utilities.GetStringValue(currentPurchase.CreatedBy, string.Empty);

                        //BZ # 512
                        lvd.VoidReason  = Utilities.GetStringValue(comboBoxReason.Text, string.Empty);
                        lvd.VoidComment = Utilities.GetStringValue(customTextBoxComment.Text, string.Empty);
                        //BZ # 512 - end
                        string errorCode;
                        string errorText;
                        var    retValue = VoidProcedures.PerformVoid(lvd, out errorCode, out errorText);

                        if (retValue)
                        {
                            MessageBox.Show(voidReturnFlow
                                                    ? "Void purchase return completed successfully"
                                                    : "Void purchase completed successfully");
                        }
                        else
                        {
                            DialogResult dgr;
                            dgr = MessageBox.Show("Void transaction failed. Do you want to retry?", "Void Error", MessageBoxButtons.OKCancel);
                            if (dgr == DialogResult.OK)
                            {
                                return;
                            }
                        }
                        GlobalDataAccessor.Instance.DesktopSession.ClearCustomerList();
                        GlobalDataAccessor.Instance.DesktopSession.ClearSessionData();
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Error in  void transaction processing");
                        FileLogger.Instance.logMessage(LogLevel.ERROR, this, "No receipts found for purchase " + currentPurchase.TicketNumber + " to void.");
                        Close();
                    }
                }
                if (voidVendorBuy)
                {
                    string errorCode;
                    string errorText;
                    int    receiptNumber;
                    mode = ProcessTenderProcedures.ProcessTenderMode.VOIDBUY;

                    GlobalDataAccessor.Instance.beginTransactionBlock();
                    transactionStarted = true;
                    bool retValue = VoidProcedures.VoidVendorPurchase(GlobalDataAccessor.Instance.OracleDA,
                                                                      Utilities.GetIntegerValue(labelTransactionNo.Text, 0),
                                                                      GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber,
                                                                      ShopDateTime.Instance.ShopDate.ToShortDateString(),
                                                                      ShopDateTime.Instance.ShopDate.ToShortDateString() + " " + ShopDateTime.Instance.ShopTime.ToString(),
                                                                      comboBoxReason.SelectedItem.ToString(),
                                                                      customTextBoxComment.Text,
                                                                      GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.UserName,
                                                                      out receiptNumber,
                                                                      out errorCode,
                                                                      out errorText);

                    //here add receipt printing code
                    //here call process tender to print void receipt //
                    List <string> refDate   = new List <string>();
                    List <string> refNumber = new List <string>();
                    List <string> refType   = new List <string>();
                    List <string> refEvent  = new List <string>();
                    List <string> refAmount = new List <string>();
                    List <string> refStore  = new List <string>();
                    List <string> refTime   = new List <string>();

                    refEvent.Add(ReceiptEventTypes.VPR.ToString());
                    refStore.Add(GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber);
                    refType.Add("4");
                    refAmount.Add(currentPurchase.Amount.ToString());
                    refTime.Add(ShopDateTime.Instance.ShopTransactionTime);
                    refNumber.Add(GlobalDataAccessor.Instance.DesktopSession.ActivePurchase.TicketNumber.ToString());
                    ReceiptDetailsVO rdVo = new ReceiptDetailsVO();
                    rdVo.ReceiptDate   = ShopDateTime.Instance.ShopDate;
                    rdVo.RefNumbers    = refNumber;
                    rdVo.ReceiptNumber = receiptNumber.ToString();
                    rdVo.RefEvents     = refEvent;
                    rdVo.RefAmounts    = refAmount;
                    rdVo.RefStores     = refStore;
                    rdVo.RefTypes      = refType;
                    //NOTE: Only use process tender controller instance, do not allocate a new one
                    ProcessTenderController pct = ProcessTenderController.Instance;
                    pct.generatePurchaseReceipt(mode, GlobalDataAccessor.Instance.DesktopSession.UserName.ToLowerInvariant(),
                                                GlobalDataAccessor.Instance.DesktopSession.ActiveCustomer,
                                                purchaseList,
                                                GlobalDataAccessor.Instance.DesktopSession.ActiveVendor != null ? GlobalDataAccessor.Instance.DesktopSession.ActiveVendor.Name : "",
                                                rdVo);

                    if (!retValue)
                    {
                        GlobalDataAccessor.Instance.endTransactionBlock(EndTransactionType.ROLLBACK);
                        transactionStarted = false;
                        MessageBox.Show("Failed to void vendor purchase " + errorText);
                        Close();
                    }
                    GlobalDataAccessor.Instance.endTransactionBlock(EndTransactionType.COMMIT);
                    transactionStarted = false;
                    MessageBox.Show("Void vendor purchase completed successfully");
                    GlobalDataAccessor.Instance.DesktopSession.ClearSessionData();
                    this.Close();
                }
                if (voidSaleFlow || voidSaleRefundFlow)
                {
                    if (currentSale.Receipts != null)
                    {
                        string rcptId;
                        if (voidSaleFlow)
                        {
                            rcptId = (from receipt in currentSale.Receipts
                                      where (receipt.Event == ReceiptEventTypes.SALE.ToString() &&
                                             receipt.RefNumber == currentSale.TicketNumber.ToString())
                                      select receipt).First().ReceiptDetailNumber;
                        }
                        else
                        {
                            rcptId = (from receipt in currentSale.Receipts
                                      where (receipt.Event == ReceiptEventTypes.REF.ToString() &&
                                             receipt.RefNumber == currentSale.TicketNumber.ToString())
                                      select receipt).First().ReceiptDetailNumber;
                        }


                        string errorCode;
                        string errorText;
                        int    receiptNumber;
                        GlobalDataAccessor.Instance.beginTransactionBlock();
                        transactionStarted = true;
                        bool retValue;
                        // = new ProcessTenderController.ProcessTenderMode();
                        if (voidSaleFlow)
                        {
                            mode     = ProcessTenderProcedures.ProcessTenderMode.RETAILVOID;
                            retValue = VoidProcedures.VoidSale(GlobalDataAccessor.Instance.OracleDA,
                                                               Utilities.GetIntegerValue(labelTransactionNo.Text, 0),
                                                               GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber,
                                                               GlobalDataAccessor.Instance.CurrentSiteId.TerminalId,
                                                               GlobalDataAccessor.Instance.DesktopSession.CashDrawerId,
                                                               comboBoxReason.SelectedItem.ToString(),
                                                               customTextBoxComment.Text,
                                                               Utilities.GetIntegerValue(labelTransactionNo.Text, 0),
                                                               currentSale.TotalSaleAmount.ToString(),
                                                               1,
                                                               Utilities.GetIntegerValue(rcptId),
                                                               ShopDateTime.Instance.ShopDate.ToShortDateString(),
                                                               ShopDateTime.Instance.ShopTransactionTime.ToString(),
                                                               GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.UserName,
                                                               out receiptNumber,
                                                               out errorCode,
                                                               out errorText);
                        }
                        else
                        {
                            mode     = ProcessTenderProcedures.ProcessTenderMode.RETAILVOIDREFUND;
                            retValue = VoidProcedures.VoidSaleRefund(GlobalDataAccessor.Instance.OracleDA,
                                                                     Utilities.GetIntegerValue(labelTransactionNo.Text, 0),
                                                                     GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber,
                                                                     GlobalDataAccessor.Instance.CurrentSiteId.TerminalId,
                                                                     GlobalDataAccessor.Instance.DesktopSession.CashDrawerId,
                                                                     comboBoxReason.SelectedItem.ToString(),
                                                                     customTextBoxComment.Text,
                                                                     Utilities.GetIntegerValue(labelTransactionNo.Text, 0),
                                                                     currentSale.Amount.ToString(),
                                                                     1,
                                                                     Utilities.GetIntegerValue(rcptId),
                                                                     ShopDateTime.Instance.ShopDate.ToShortDateString(),
                                                                     ShopDateTime.Instance.ShopTransactionTime.ToString(),
                                                                     GlobalDataAccessor.Instance.DesktopSession.LoggedInUserSecurityProfile.UserName,
                                                                     out receiptNumber,
                                                                     out errorCode,
                                                                     out errorText);
                        }

                        if (retValue)
                        {
                            GlobalDataAccessor.Instance.DesktopSession.endTransactionBlock(EndTransactionType.COMMIT);
                            transactionStarted = false;
                            if (currentSale.TenderDataDetails != null)
                            {
                                ProcessPaidTenderData(currentSale.TenderDataDetails);
                            }
                            //here call process tender to print void receipt //
                            var refDate   = new List <string>();
                            var refNumber = new List <string>();
                            var refType   = new List <string>();
                            var refEvent  = new List <string>();
                            var refAmount = new List <string>();
                            var refStore  = new List <string>();
                            var refTime   = new List <string>();

                            refEvent.Add(ReceiptEventTypes.VRET.ToString());
                            refStore.Add(GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber);
                            refType.Add("4");
                            refTime.Add(ShopDateTime.Instance.ShopTransactionTime);
                            refNumber.Add(GlobalDataAccessor.Instance.DesktopSession.ActiveRetail.TicketNumber.ToString());
                            ReceiptDetailsVO rdVo = new ReceiptDetailsVO();
                            rdVo.ReceiptDate   = ShopDateTime.Instance.ShopDate;
                            rdVo.RefNumbers    = refNumber;
                            rdVo.ReceiptNumber = receiptNumber.ToString();
                            rdVo.RefEvents     = refEvent;
                            rdVo.RefStores     = refStore;
                            rdVo.RefTypes      = refType;
                            //NOTE: Only use process tender controller instance, do not allocate a new one
                            ProcessTenderController pct = ProcessTenderController.Instance;
                            pct.GenerateSaleReceipt(mode, GlobalDataAccessor.Instance.DesktopSession.UserName.ToLowerInvariant(),
                                                    GlobalDataAccessor.Instance.DesktopSession.ActiveCustomer,
                                                    GlobalDataAccessor.Instance.DesktopSession.ActiveRetail,
                                                    GlobalDataAccessor.Instance.DesktopSession.ActiveVendor != null ? GlobalDataAccessor.Instance.DesktopSession.ActiveVendor.Name : "",
                                                    rdVo);
                            MessageBox.Show(voidSaleFlow
                                                    ? "Void Sale completed successfully"
                                                    : "Void Sale Refund completed successfully");
                            GlobalDataAccessor.Instance.DesktopSession.ClearCustomerList();
                            GlobalDataAccessor.Instance.DesktopSession.ClearSessionData();
                            this.Close();
                        }
                        else
                        {
                            GlobalDataAccessor.Instance.DesktopSession.endTransactionBlock(EndTransactionType.ROLLBACK);
                            transactionStarted = false;
                            DialogResult dgr;
                            dgr = MessageBox.Show("Void transaction failed. Do you want to retry?", "Void Error", MessageBoxButtons.OKCancel);
                            if (dgr == DialogResult.OK)
                            {
                                return;
                            }
                            Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error in  void transaction processing");
                        FileLogger.Instance.logMessage(LogLevel.ERROR, this, "No receipts found for sale " + currentSale.TicketNumber + " to void.");
                        Close();
                    }
                }
            }
            catch (Exception ex)
            {
                if (transactionStarted)
                {
                    GlobalDataAccessor.Instance.DesktopSession.endTransactionBlock(EndTransactionType.ROLLBACK);
                    transactionStarted = false;
                }
                if (FileLogger.Instance.IsLogError)
                {
                    FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Error when voiding " + ex.Message);
                }
            }
        }
        private void customButtonVoid_Click(object sender, EventArgs e)
        {
            try
            {
                if (currentPurchase.Receipts != null)
                {
                    string rcptId;
                    if (voidReturnFlow)
                    {
                        rcptId = (from receipt in currentPurchase.Receipts
                                  where (receipt.Event == ReceiptEventTypes.RET.ToString() &&
                                         receipt.RefNumber == currentPurchase.TicketNumber.ToString())
                                  select receipt).First().ReceiptDetailNumber;
                    }
                    else
                    {
                        rcptId = (from receipt in currentPurchase.Receipts
                                  where (receipt.Event == ReceiptEventTypes.PUR.ToString() &&
                                         receipt.RefNumber == currentPurchase.TicketNumber.ToString())
                                  select receipt).First().ReceiptDetailNumber;
                    }

                    var lvd = new VoidLoanForm.LoanVoidDetails();
                    lvd.TickNum     = labelPurchaseNo.Text;
                    lvd.StoreNum    = GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber;
                    lvd.OpRef       = labelPurchaseNo.Text;
                    lvd.OpCode      = voidReturnFlow ? "Return" : "Purchase";
                    lvd.OpCd        = voidReturnFlow ? ReceiptEventTypes.VRET.ToString() : ReceiptEventTypes.VPR.ToString();
                    lvd.Amount      = Utilities.GetDecimalValue(currentPurchase.Amount, 0.0M);
                    lvd.HoldType    = "";
                    lvd.RecId       = Utilities.GetLongValue(rcptId);
                    lvd.PfiEligDate = Utilities.GetDateTimeValue(currentPurchase.PfiEligible, DateTime.MaxValue);
                    lvd.CreatedBy   = Utilities.GetStringValue(currentPurchase.CreatedBy, string.Empty);

                    string errorCode;
                    string errorText;
                    bool   retValue = VoidProcedures.PerformVoid(lvd, out errorCode, out errorText);
                    if (retValue)
                    {
                        MessageBox.Show(voidReturnFlow
                                                ? "Void purchase return completed successfully"
                                                : "Void purchase completed successfully");
                        this.Close();
                    }
                    else
                    {
                        DialogResult dgr;
                        dgr = MessageBox.Show("Void transaction failed. Do you want to retry?", "Void Error", MessageBoxButtons.OKCancel);
                        if (dgr == DialogResult.OK)
                        {
                            return;
                        }
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("Error in  void transaction processing");
                    FileLogger.Instance.logMessage(LogLevel.ERROR, this, "No receipts found for purchase " + currentPurchase.TicketNumber + " to void.");
                    Close();
                }
            }
            catch (Exception ex)
            {
                FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Error when voiding buy return " + ex.Message);
            }
        }