/// <summary>
        /// apply tender button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void applyBtn_Click(object sender, EventArgs e)
        {
            try
            {
                int tenderId = 0;
                var tenders  = TendersCache.Tenders;

                if (tenders != null && tenders.Any())
                {
                    var getGiftCardTender = tenders.ToList().Find(t => t.TenderTypeName.Equals(_conFigHelper.DW_LOYALTY_TENDER_NAME, StringComparison.CurrentCultureIgnoreCase));
                    if (getGiftCardTender != null && !string.IsNullOrWhiteSpace(getGiftCardTender.ID))
                    {
                        int.TryParse(getGiftCardTender.ID, out tenderId);
                    }
                }

                decimal applyBalance = 0;
                decimal.TryParse(textApplyBalance.Text, out applyBalance);

                if (tenderId != 0)
                {
                    if (applyBalance <= 0)
                    {
                        lblApplyBalanceError.Text = "Please enter an amount greater than 0.";
                    }
                    else if (_ticketAmountDue == 0)
                    {
                        var ticketMenuItems = _dwProvider.GetTicketMenuItems(_currentUserId, _currentOpenTicketId);
                        lblApplyBalanceError.Text = ticketMenuItems != null && ticketMenuItems.Count() > 0 ? "Amount due on this ticket is $0." : "Please add at least 1 item to apply loyalty tender.";
                    }
                    else if (applyBalance > _ticketAmountDue)
                    {
                        lblApplyBalanceError.Text = "Entered amount exceeds ticket amount due of $" + Math.Round(_ticketAmountDue, 2);
                    }
                    else if (_availableBalance > 0 && applyBalance > 0)
                    {
                        ApplyLoyaltyTender(tenderId, applyBalance);
                        bLoyalLoyaltyTenderExtension.currentOpenTicketId = string.Empty;
                    }
                    else if (applyBalance > _availableBalance)
                    {
                        lblApplyBalanceError.Text = "Entered amount exceeds available balance of $" + Math.Round(_availableBalance, 2);
                    }
                }
                else
                {
                    //bLoyal Loyalty Tenders not find in Dinerware
                    this.Hide();
                    frmTenderNotFoundWarning show = new frmTenderNotFoundWarning(Messages.LOYALTY_TENDER_NOT_CONFIGURED);
                    show.ShowDialog();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "applyBtn_Click");
            }
        }
Пример #2
0
        /// <summary>
        /// Apply button click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void applyBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(txtGiftCardNumber.Text))
                {
                    int tenderId = 0;
                    var tenders  = TendersCache.Tenders;

                    if (tenders != null && tenders.Any())
                    {
                        var getGiftCardTender = tenders.ToList().Find(t => t.TenderTypeName.Equals(_conFigHelper.DW_GIFTCARD_TENDER_NAME, StringComparison.CurrentCultureIgnoreCase));
                        if (getGiftCardTender != null && !string.IsNullOrWhiteSpace(getGiftCardTender.ID))
                        {
                            int.TryParse(getGiftCardTender.ID, out tenderId);
                        }
                    }
                    if (tenderId != 0)
                    {
                        decimal applyBalanceAmt = 0;
                        decimal.TryParse(textApplyBalance.Text, out applyBalanceAmt);

                        try
                        {
                            FinancialCard financialCardHelper = new FinancialCard(txtGiftCardNumber.Text);
                            txtGiftCardNumber.Text = financialCardHelper.CardNumber;
                        }
                        catch (Exception ex)
                        {
                            _logger.WriteLogError(ex, "applyBtn_Click error for Swap GiftCard");
                        }

                        var cardResponse = GetGiftCardBalance(false);
                        lblEmptyCardNumberError.Visible = false;
                        if (cardResponse.AvailableBalance == 0 && cardResponse.Status == PaymentEngine.CardRequestStatus.Approved && !string.IsNullOrWhiteSpace(cardResponse.Message) && (cardResponse.Message.StartsWith("Current balance is") || cardResponse.Message.StartsWith("Gift card is not provisioned - number is auto provisioned enabled")))
                        {
                            lblAvailableBalance.Visible = true;
                            lblAvailableBalanceAmt.Text = "0";
                            lblApplyBalanceError.Text   = cardResponse.Message;
                        }
                        else if (cardResponse.Status == PaymentEngine.CardRequestStatus.Declined)
                        {
                            lblAvailableBalance.Visible = false;
                            lblAvailableBalanceAmt.Text = "0";
                            lblApplyBalanceError.Text   = cardResponse.Message;
                        }
                        else if (applyBalanceAmt <= 0)
                        {
                            lblApplyBalanceError.Text = "Please enter an amount greater than 0.";
                        }
                        else if (_ticketAmountDue == 0)
                        {
                            var ticketMenuItems = _dinerwareProvider.GetTicketMenuItems(_currentUserId, _currentOpenTicketId);
                            lblApplyBalanceError.Text = ticketMenuItems != null && ticketMenuItems.Count() > 0 ? "Amount due on this ticket is $0." : "Please add at least 1 item to apply Gift Card tender.";
                        }
                        else if (applyBalanceAmt > _ticketAmountDue)
                        {
                            lblApplyBalanceError.Text = "Entered amount exceeds ticket amount due of $" + Math.Round(_ticketAmountDue, 2);
                        }
                        else if (((_availableBalance >= applyBalanceAmt) || _availableBalance <= _ticketAmountDue))
                        {
                            if (AddTransactionToTicket(tenderId, _availableBalance >= applyBalanceAmt ? applyBalanceAmt : _availableBalance))
                            {
                                bLoyalGiftCardTenderExtension.currentOpenTicketId = string.Empty;
                                this.Close();
                            }
                            else
                            {
                                lblApplyBalanceError.Text = Messages.SERVICE_UNAVAILBLE_WARNING;
                            }
                        }
                    }
                    else
                    {
                        //bLoyal GiftCard Tenders not find in Dinerware
                        this.Hide();
                        frmTenderNotFoundWarning show = new frmTenderNotFoundWarning(Messages.GC_TENDER_NOT_CONFIGURED);
                        show.ShowDialog();
                        this.Close();
                    }
                }
                else
                {
                    lblEmptyCardNumberError.Visible = true;
                    lblEmptyCardNumberError.Text    = "Please enter gift card number.";
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "bLoyal Gift Card applyBtn_Click");
            }
        }