private void btnSubmit_Click(object sender, EventArgs e)
        {
            StringBuilder messageToShow = new StringBuilder();

            messageToShow.Append("A manager's authorization is required." + System.Environment.NewLine);
            //bring up dialog
            List <ManagerOverrideType>            overrideTypes    = new List <ManagerOverrideType>();
            List <ManagerOverrideTransactionType> transactionTypes = new List <ManagerOverrideTransactionType>();

            transactionTypes.Add(ManagerOverrideTransactionType.FIREARMSBUYOUT);
            overrideTypes.Add(ManagerOverrideType.FIREARMSBUYOUT);
            ManageOverrides overrideFrm = new ManageOverrides(ManageOverrides.OVERRIDE_TRIGGER)
            {
                MessageToShow                   = messageToShow.ToString(),
                ManagerOverrideTypes            = overrideTypes,
                ManagerOverrideTransactionTypes = transactionTypes
            };

            overrideFrm.ShowDialog();
            if (overrideFrm.OverrideAllowed)
            {
                //add code here to set items to processtender
                GlobalDataAccessor.Instance.DesktopSession.BuyoutLoans = SelectedLoan;
            }
        }
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            var messageToShow = new StringBuilder();

            Transactions = new List <OverrideTransaction>();
            foreach (DataGridViewRow dgvr in this.customDataGridViewOverrideTransactions.Rows)
            {
                DataGridViewCheckBoxCell dgcell = (DataGridViewCheckBoxCell)dgvr.Cells[0];

                if ((bool)dgcell.Value)
                {
                    messageToShow.Append(dgvr.Cells[1].Value.ToString());
                    messageToShow.Append("-");
                    messageToShow.Append(dgvr.Cells[2].Value.ToString());
                    messageToShow.Append(System.Environment.NewLine);
                    //Update the Transactions list with only the selected ones
                    //So the calling program would know
                    OverrideTransaction newTran = new OverrideTransaction();
                    newTran.ReasonForOverride = new List <Commons.StringValue>();
                    newTran.TicketNumber      =
                        Utilities.GetIntegerValue(dgvr.Cells[1].Value.ToString(),
                                                  0);

                    newTran.ReasonForOverride.Add(new Commons.StringValue(dgvr.Cells[2].Value.ToString()));
                    newTran.OverrideType    = (ManagerOverrideType)dgvr.Cells[3].Value;
                    newTran.TransactionType = (ManagerOverrideTransactionType)dgvr.Cells[4].Value;

                    Transactions.Add(newTran);
                }
            }

            if (Transactions.Count > 0)
            {
                List <ManagerOverrideType>            overrideTypes    = new List <ManagerOverrideType>();
                List <ManagerOverrideTransactionType> transactionTypes = new List <ManagerOverrideTransactionType>();
                List <int> ticketNumbers = new List <int>();
                foreach (OverrideTransaction tran in Transactions)
                {
                    overrideTypes.Add(tran.OverrideType);
                    transactionTypes.Add(tran.TransactionType);
                    ticketNumbers.Add(tran.TicketNumber);
                }
                ManageOverrides overrideFrm = new ManageOverrides(ManageOverrides.OVERRIDE_TRIGGER)
                {
                    MessageToShow                   = messageToShow.ToString(),
                    ManagerOverrideTypes            = overrideTypes,
                    ManagerOverrideTransactionTypes = transactionTypes,
                    TransactionNumbers              = ticketNumbers
                };
                overrideFrm.ShowDialog(this);
                //If the override did not pass, send back 0 transactions
                //so the calling program would know that the override did not happen
                if (!(overrideFrm.OverrideAllowed))
                {
                    Transactions = new List <OverrideTransaction>();
                }
            }


            Close();
        }
        public void AddTenderEntry(TenderEntryVO tenderEntry, bool addToInternalList)
        {
            if (tenderEntry == null)
            {
                return;
            }

            string       cardType = string.Empty;
            DataGridView dV;

            cardType = tenderEntry.CardTypeString ?? string.Empty;
            //Determine table to create data row from
            if (this.tenderTableType == TenderTablePanelType.TENDERIN)
            {
                dV = this.tenderInDataGridView;
            }
            else
            {
                if (this.tenderTableType == TenderTablePanelType.TENDEROUT_REFUND ||
                    this.tenderTableType == TenderTablePanelType.TENDEROUT_PARTIALREFUND)
                {
                    dV = (this.tenderTableType == TenderTablePanelType.TENDEROUT_REFUND) ?
                         this.tenderOutRefundDataGridView :
                         this.tenderOutPurchaseDataGridView;
                    if (!addToInternalList)
                    {
                        if (this.tenderTableType == TenderTablePanelType.TENDEROUT_PARTIALREFUND)
                        {
                            dV = this.tenderOutPartialRefundDataGridView;
                        }
                        else
                        {
                            //Initial loading of purchases noted for refund
                            dV = this.tenderOutPurchaseDataGridView;
                        }
                    }
                    else
                    {
                        if (initialTenderAdded)
                        {
                            dV = this.tenderOutRefundDataGridView;
                        }
                    }
                }
                else
                {
                    dV = this.tenderOutPurchaseDataGridView;
                }
            }

            //Add common data row types
            string tenderType = TenderTypeStrings[(int)tenderEntry.TenderType];
            //Enum.Format(typeof(TenderTypes), tenderEntry.TenderType, "g");
            string refNumber = tenderEntry.ReferenceNumber ?? string.Empty;
            string amount    = tenderEntry.Amount.ToString("C");

            //Construct data row array
            object[] rowData = null;
            rowData = new string[]
            {
                tenderType, refNumber, cardType, amount
            };

            if ((this.tenderTableType == TenderTablePanelType.TENDEROUT_REFUND ||
                 this.tenderTableType == TenderTablePanelType.TENDEROUT_PARTIALREFUND) &&
                addToInternalList && initialTenderAdded)
            {
                string msg;
                if (!this.validateRefundTenderMatrix(tenderEntry, out msg))
                {
                    MessageBox.Show("Improper tender added: " + msg);
                    return;
                }
            }

            /* SR 6/15/2011 Removing coupon as a MOP
             * //SR 12/27/2010 If the current tender entry type is coupon make sure this is the
             * //first type selected
             * if (this.tenderTableType == TenderTablePanelType.TENDERIN && tenderEntry.TenderType == TenderTypes.COUPON)
             * {
             *  if (GetTenderList.Count > 0)
             *  {
             *      MessageBox.Show("Coupon Tender needs to be applied first. " + System.Environment.NewLine + "Please remove previously used tender types.", "Process Tender Warning");
             *      return;
             *  }
             * }*/

            //SR 03/12/2011 If the current tender entry for tender in is store credit ask for manager override
            //if the transaction is sale
            if (this.tenderTableType == TenderTablePanelType.TENDERIN && tenderEntry.TenderType == TenderTypes.STORECREDIT && GlobalDataAccessor.Instance.DesktopSession.CompleteSale)
            {
                var overrideTypes    = new List <ManagerOverrideType>();
                var transactionTypes = new List <ManagerOverrideTransactionType>();
                var messageToShow    = new StringBuilder();
                messageToShow.Append("Store Credit is being used ");
                overrideTypes.Add(ManagerOverrideType.SCRDT);
                transactionTypes.Add(ManagerOverrideTransactionType.SALE);
                var overrideFrm = new ManageOverrides(ManageOverrides.OVERRIDE_TRIGGER)
                {
                    MessageToShow                   = messageToShow.ToString(),
                    ManagerOverrideTypes            = overrideTypes,
                    ManagerOverrideTransactionTypes = transactionTypes
                };

                overrideFrm.ShowDialog();
                if (!overrideFrm.OverrideAllowed)
                {
                    MessageBox.Show("Manager override needed to proceed with using store credit");
                    return;
                }
            }

            //SR 12/27/2010 Check if the current tender type is cash and there is already a cash tender
            //type entered. In that case the amount needs to be added to the original row and should not
            //enter a new row
            //SR 2/23/2011 The same logic applies for Shop credit
            bool    addRow           = true;
            decimal currentRowAmount = 0.0m;

            if (RowIdx == -1)
            {
                if ((tenderTableType == TenderTablePanelType.TENDERIN && (tenderEntry.TenderType == TenderTypes.CASHIN || tenderEntry.TenderType == TenderTypes.STORECREDIT)) ||
                    ((tenderTableType == TenderTablePanelType.TENDEROUT_REFUND || tenderTableType == TenderTablePanelType.TENDEROUT_PARTIALREFUND) &&
                     (tenderEntry.TenderType == TenderTypes.CASHOUT || (tenderEntry.TenderType == TenderTypes.STORECREDIT && addToInternalList))))
                {
                    foreach (DataGridViewRow dgvr in dV.Rows)
                    {
                        var strObjVal = (dgvr.Cells.Count > 0)
                                        ? dgvr.Cells[0].Value
                                        : null;

                        if (strObjVal != null && tenderType == strObjVal.ToString() && (tenderEntry.TenderType == TenderTypes.CASHIN || tenderEntry.TenderType == TenderTypes.CASHOUT) && (strObjVal.ToString().Equals("Cash", StringComparison.OrdinalIgnoreCase)))
                        {
                            var strObjVal2 = (dgvr.Cells.Count > 3)
                                             ? dgvr.Cells[3].Value
                                             : null;
                            if (strObjVal2 != null)
                            {
                                var cellValStr = strObjVal2.ToString();
                                if (!string.IsNullOrEmpty(cellValStr) && cellValStr.Length > 1)
                                {
                                    currentRowAmount    = Utilities.GetDecimalValue(cellValStr.Substring(1));
                                    currentCardType     = string.Empty;
                                    dgvr.Cells[3].Value = amount;
                                    addRow = false;
                                }
                            }
                        }
                        if (strObjVal != null && tenderEntry.TenderType == TenderTypes.STORECREDIT && (strObjVal.ToString().Equals("Store Credit", StringComparison.OrdinalIgnoreCase)))
                        {
                            var strObjVal2 = (dgvr.Cells.Count > 3)
                                             ? dgvr.Cells[3].Value
                                             : null;
                            if (strObjVal2 != null)
                            {
                                var cellValStr = strObjVal2.ToString();
                                if (!string.IsNullOrEmpty(cellValStr) && cellValStr.Length > 1)
                                {
                                    currentRowAmount    = Utilities.GetDecimalValue(cellValStr.Substring(1));
                                    currentCardType     = string.Empty;
                                    dgvr.Cells[3].Value = amount;
                                    addRow = false;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                currentRowAmount = Utilities.GetDecimalValue(dV.Rows[RowIdx].Cells[3].Value.ToString().Substring(1));
                currentCardType  = Utilities.GetStringValue(dV.Rows[RowIdx].Cells[2].Value);
                dV.Rows.RemoveAt(RowIdx);
                dV.Rows.Insert(RowIdx, rowData);
                addRow = false;
            }

            //Add data row array to appropriate data grid view
            if (addRow)
            {
                dV.Rows.Add(rowData);
            }

            //Add entry to tender list

            if (addToInternalList)
            {
                if (this.tenderTableType == TenderTablePanelType.TENDERIN)
                {
                    if (!addRow)
                    {
                        int rowIdx = GetTenderList.FindIndex(tenderData => tenderData.TenderType == tenderEntry.TenderType && tenderData.CardTypeString == currentCardType);
                        if (rowIdx >= 0)
                        {
                            GetTenderList.RemoveAt(rowIdx);
                            GetTenderList.Insert(rowIdx, tenderEntry);
                            this.adjustAmount(-currentRowAmount);
                        }
                    }
                    else
                    {
                        this.GetTenderList.Add(tenderEntry);
                    }
                }
                else if (this.tenderTableType == TenderTablePanelType.TENDEROUT_REFUND || this.tenderTableType == TenderTablePanelType.TENDEROUT_PARTIALREFUND)
                {
                    if (!addRow)
                    {
                        int rowIdx = GetRefundTenderList.FindIndex(tenderData => tenderData.TenderType == tenderEntry.TenderType && tenderData.CardTypeString == currentCardType);
                        if (rowIdx >= 0)
                        {
                            GetRefundTenderList.RemoveAt(rowIdx);
                            GetRefundTenderList.Insert(rowIdx, tenderEntry);
                            this.adjustAmount(-currentRowAmount);
                        }
                    }
                    else
                    if (initialTenderAdded)
                    {
                        this.GetRefundTenderList.Add(tenderEntry);
                    }
                }

                decimal adjustTenderAmount = tenderEntry.Amount;
                if (this.tenderTableType == TenderTablePanelType.TENDERIN)
                {
                    this.adjustAmount(adjustTenderAmount);
                }
                else if (dV != this.tenderOutPurchaseDataGridView)
                {
                    this.adjustAmount(adjustTenderAmount);
                }
            }
        }
        private void customButtonSubmit_Click(object sender, EventArgs e)
        {
            if (customButtonSubmit.Text == "Continue")
            {
                currIndex++;
                tableLayoutPanelAddlFees.Controls.Clear();
                tableLayoutPanelAddlFeeHeading.Visible = false;
                panelAdditionalFeesHeading.Visible     = false;
                LoadData();
            }
            else
            {
                //If any of the loan fees were waived or prorated
                //and if manager override is needed, show the manager override form
                bool updateserviceloans = true;
                List <ManagerOverrideType>            overrideTypes    = new List <ManagerOverrideType>();
                List <ManagerOverrideTransactionType> transactionTypes = new List <ManagerOverrideTransactionType>();
                List <int> transactionsForServiceOverride = new List <int>();

                foreach (PawnLoan pl in pawnloansToView)
                {
                    List <Fee> loanFees = pl.OriginalFees;
                    Fee        feedata  = (from fee in loanFees
                                           where fee.Waived || fee.Prorated
                                           select fee).FirstOrDefault();
                    if (feedata.Waived || feedata.Prorated)
                    {
                        if (new BusinessRulesProcedures(GlobalDataAccessor.Instance.DesktopSession).IsManagerOverrideRequiredForProrateWaive(currentStoreSiteId))
                        {
                            transactionsForServiceOverride.Add(pl.TicketNumber);
                            if (feedata.Waived)
                            {
                                overrideTypes.Add(ManagerOverrideType.WV);
                            }
                            else
                            {
                                overrideTypes.Add(ManagerOverrideType.PRO);
                            }
                            if (pl.TempStatus == StateStatus.P)
                            {
                                transactionTypes.Add(ManagerOverrideTransactionType.PU);
                            }
                            else if (pl.TempStatus == StateStatus.RN)
                            {
                                transactionTypes.Add(ManagerOverrideTransactionType.RN);
                            }
                            else if (pl.TempStatus == StateStatus.PD)
                            {
                                transactionTypes.Add(ManagerOverrideTransactionType.PD);
                            }
                        }
                    }
                }
                if (transactionsForServiceOverride.Count > 0)
                {
                    ManageOverrides overrideFrm = new ManageOverrides(ManageOverrides.OVERRIDE_TRIGGER)
                    {
                        MessageToShow =
                            Commons.GetMessageString("WaiveFeesOverrideMessage"),
                        ManagerOverrideTypes            = overrideTypes,
                        ManagerOverrideTransactionTypes = transactionTypes,
                        TransactionNumbers = transactionsForServiceOverride
                    };
                    overrideFrm.ShowDialog();
                    if (!(overrideFrm.OverrideAllowed))
                    {
                        //If Manager override Failed
                        //Waive or prorate of the fees cannot be persisted
                        updateserviceloans = false;
                    }
                }

                //Do not update the service loans if manager override did not go through
                if (updateserviceloans)
                {
                    GlobalDataAccessor.Instance.DesktopSession.ServiceLoans = pawnloansToView;
                }
                this.Close();
            }
        }