Exemplo n.º 1
0
        private void GetLoyaltyInfoFromDB(LoyaltyItem loyaltyItem)
        {
            SqlSelect sql = new SqlSelect("RETAILLOYALTYMSRCARDTABLE M "
                                          + "INNER JOIN RETAILLOYALTYCUSTTABLE C ON M.LOYALTYCUSTID = C.LOYALTYCUSTID "
                                          + "INNER JOIN RETAILLOYALTYSCHEMESTABLE S ON S.LOYALTYSCHEMEID = M.LOYALTYSCHEMEID ");

            sql.Select("M.LOYALTYSCHEMEID");
            sql.Select("M.LOYALTYCUSTID");
            sql.Select("ACCOUNTNUM");
            sql.Select("EXPIRATIONTIMEUNIT");
            sql.Select("EXPIRATIONTIMEVALUE");
            sql.Where("M.DATAAREAID", Application.Settings.Database.DataAreaID, true);
            sql.Where("M.CARDNUMBER", loyaltyItem.LoyaltyCardNumber, true);   // Sale Unit of Measure

            DataTable dataTable = new DBUtil(Application.Settings.Database.Connection).GetTable(sql);

            if (dataTable.Rows.Count > 0)
            {
                loyaltyItem.SchemeID      = Utility.ToString(dataTable.Rows[0]["LOYALTYSCHEMEID"]);
                loyaltyItem.LoyaltyCustID = Utility.ToString(dataTable.Rows[0]["LOYALTYCUSTID"]);
                loyaltyItem.CustID        = Utility.ToString(dataTable.Rows[0]["ACCOUNTNUM"]);
                loyaltyItem.ExpireUnit    = Utility.ToInt(dataTable.Rows[0]["EXPIRATIONTIMEUNIT"]);
                loyaltyItem.ExpireValue   = Utility.ToInt(dataTable.Rows[0]["EXPIRATIONTIMEVALUE"]);
            }
        }
Exemplo n.º 2
0
        private void UpdateIssuedLoyaltyPoints(LoyaltyItem loyaltyItem)
        {
            bool   valid   = false;
            string comment = string.Empty;

            try
            {
                try
                {
                    NewMessageWindow(50054, LSPosMessageTypeButton.NoButtons, System.Windows.Forms.MessageBoxIcon.Information);

                    this.Application.TransactionServices.UpdateIssuedLoyaltyPoints(
                        ref valid,
                        ref comment,
                        this.transaction.TransactionId,
                        "1",
                        this.transaction.StoreId,
                        this.transaction.TerminalId,
                        loyaltyItem.LoyaltyCardNumber,
                        ((IPosTransactionV1)this.transaction).BeginDateTime,
                        loyaltyItem.CalculatedLoyaltyPoints,
                        this.transaction.ReceiptId,
                        this.transaction.OperatorId);

                    if (valid)
                    {
                        UpdateTransactionAccumulatedLoyaltyPoint();
                    }
                }
                finally
                {
                    CloseExistingMessageWindow();
                }
            }
            catch (Exception ex)
            {
                NetTracer.Warning(ex, "Loyalty::UpdateIssuedLoyaltyPoints failed for loyaltyItem {0}. Setting valid to false.", loyaltyItem.LoyaltyCardNumber);
                valid = false;
            }

            if (!valid)
            {
                frmMessage errDialog = null;
                try
                {
                    if (string.IsNullOrEmpty(comment))
                    {
                        errDialog = new frmMessage(50058, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        errDialog = new frmMessage(comment, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    this.Application.ApplicationFramework.POSShowForm(errDialog);
                    CloseExistingMessageWindow();
                }
                finally
                {
                    if (errDialog != null)
                    {
                        errDialog.Dispose();
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This creates a loyalty line item based on the passed in card info, or prompts
        ///  to initialize default loyalty card info if no card info is supplied.
        /// </summary>
        /// <param name="cardInfo">Card info of loyalty card. If null, it will be initialized through user prompt.</param>
        /// <returns>Loyalty line item and loyalty card info if un-initialized</returns>
        private LoyaltyItem GetLoyaltyItem(ref ICardInfo cardInfo)
        {
            if (cardInfo == null)
            {
                // The loyalty card was not swiped and therefore we need to prompt for the card number...

                using (LSRetailPosis.POSProcesses.frmInputNumpad inputDialog = new LSRetailPosis.POSProcesses.frmInputNumpad(true, true))
                {
                    inputDialog.EntryTypes = NumpadEntryTypes.CardValidation;
                    inputDialog.PromptText = LSRetailPosis.ApplicationLocalizer.Language.Translate(50056); //Loyalty card number
                    inputDialog.Text       = ApplicationLocalizer.Language.Translate(50062);               // Add loyalty card
                    LP.POSFormsManager.ShowPOSForm(inputDialog);
                    DialogResult result = inputDialog.DialogResult;
                    // Quit if cancel is pressed...
                    if (result != System.Windows.Forms.DialogResult.OK)
                    {
                        return(null);
                    }
                    else
                    {
                        cardInfo = Utility.CreateCardInfo();
                        cardInfo.CardEntryType = CardEntryTypes.MANUALLY_ENTERED;
                        cardInfo.CardNumber    = inputDialog.InputText;
                        // Set card type to Loyalty card since this is a loyalty payment
                        //  Calling GetCardType sets the tender type properties on the cardInfo object or prompts user for more information.
                        cardInfo.CardType = CardTypes.LoyaltyCard;
                        this.Application.Services.Card.GetCardType(ref cardInfo);
                    }
                }
            }

            // Create the loyalty item
            LoyaltyItem loyaltyItem = (LoyaltyItem)this.Application.BusinessLogic.Utility.CreateLoyaltyItem();

            // Set its properties
            if (cardInfo.CardEntryType == CardEntryTypes.MAGNETIC_STRIPE_READ)
            {
                loyaltyItem.LoyaltyCardNumber = cardInfo.Track2Parts[0];
            }
            else
            {
                loyaltyItem.LoyaltyCardNumber = cardInfo.CardNumber;
            }

            // Check whether the card is allowed to collect loyalty points
            bool    cardIsValid           = false;
            string  comment               = string.Empty;
            int     loyaltyTenderTypeBase = 0;
            decimal pointsEarned          = 0;

            GetPointStatus(ref pointsEarned, ref cardIsValid, ref comment, ref loyaltyTenderTypeBase, loyaltyItem.LoyaltyCardNumber);

            if (cardIsValid)
            {
                loyaltyItem.AccumulatedLoyaltyPoints = pointsEarned;
                GetLoyaltyInfoFromDB(loyaltyItem);

                if (string.IsNullOrEmpty(this.transaction.Customer.CustomerId) ||
                    string.IsNullOrEmpty(loyaltyItem.CustID) ||
                    string.Compare(this.transaction.Customer.CustomerId, loyaltyItem.CustID, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(loyaltyItem);
                }
                else
                {
                    // loyalty payment could change customer, which is not desirable under various condition.
                    // All logic is captured in CustomerClear action, so we ask cashier to do that first.
                    LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSMessageDialog(3222);  // You must clear the customer before performing this operation.
                    return(null);
                }
            }
            else
            {
                LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSStatusBarText("Card ID: " + loyaltyItem.LoyaltyCardNumber); //License only allows limited number of item sales
                LSRetailPosis.POSProcesses.frmMessage dialog = null;
                try
                {
                    if (string.IsNullOrEmpty(comment))
                    {
                        dialog = new LSRetailPosis.POSProcesses.frmMessage(50058, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    }
                    else
                    {
                        dialog = new LSRetailPosis.POSProcesses.frmMessage(comment, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    }

                    LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog);    // Invalid loyaltycard
                    return(null);
                }
                finally
                {
                    if (dialog != null)
                    {
                        dialog.Dispose();
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void AddLoyaltyPayment(IRetailTransaction retailTransaction, ICardInfo cardInfo, decimal amount)
        {
            try
            {
                try
                {
                    NewMessageWindow(50051, LSPosMessageTypeButton.NoButtons, System.Windows.Forms.MessageBoxIcon.Information);

                    this.transaction = (RetailTransaction)retailTransaction;

                    // Getting the loyalty info for the card, how many points have previously been earned
                    LoyaltyItem paymentLoyaltyItem = GetLoyaltyItem(ref cardInfo);

                    if (paymentLoyaltyItem != null)
                    {
                        //customerData.
                        if (this.transaction.Customer == null || string.Equals(this.transaction.Customer.CustomerId, paymentLoyaltyItem.CustID, StringComparison.OrdinalIgnoreCase) == false)
                        {
                            UpdateTransactionWithNewCustomer(paymentLoyaltyItem.CustID);
                        }

                        // if the amount is higher than the "new" NetAmountWithTax, then it is acceptable to lower the amount
                        if (Math.Abs(amount) > Math.Abs(this.transaction.TransSalePmtDiff))
                        {
                            amount = this.transaction.TransSalePmtDiff;
                        }

                        // Getting all possible loyalty posssiblities for the found scheme id
                        DataTable loyaltyPointsTable = GetLoyaltyPointsSchemeFromDB(paymentLoyaltyItem.SchemeID);

                        decimal totalNumberOfPoints = 0;
                        bool    tenderRuleFound     = false;

                        // now we add the points needed to pay current tender
                        totalNumberOfPoints = CalculatePointsForTender(ref tenderRuleFound, cardInfo.TenderTypeId, amount, loyaltyPointsTable);

                        if (tenderRuleFound)
                        {
                            bool    cardIsValid           = false;
                            string  comment               = string.Empty;
                            int     loyaltyTenderTypeBase = 0;
                            decimal pointsEarned          = 0;

                            // check to see if the user can afford so many points
                            GetPointStatus(ref pointsEarned, ref cardIsValid, ref comment, ref loyaltyTenderTypeBase, paymentLoyaltyItem.LoyaltyCardNumber);

                            if ((cardIsValid) && ((LoyaltyTenderTypeBase)loyaltyTenderTypeBase != LoyaltyTenderTypeBase.NoTender))
                            {
                                if (pointsEarned >= (totalNumberOfPoints * -1))
                                {
                                    //customerData.
                                    if (this.transaction.Customer == null || string.Equals(this.transaction.Customer.CustomerId, paymentLoyaltyItem.CustID, StringComparison.OrdinalIgnoreCase) == false)
                                    {
                                        UpdateTransactionWithNewCustomer(paymentLoyaltyItem.CustID);
                                    }

                                    //Add loyalty item to transaction.
                                    this.transaction.LoyaltyItem           = paymentLoyaltyItem;
                                    this.transaction.LoyaltyItem.UsageType = LoyaltyItemUsageType.UsedForLoyaltyTender;

                                    // Gathering tender information
                                    TenderData tenderData = new TenderData(ApplicationSettings.Database.LocalConnection, ApplicationSettings.Database.DATAAREAID);
                                    ITender    tenderInfo = tenderData.GetTender(cardInfo.TenderTypeId, ApplicationSettings.Terminal.StoreId);

                                    // this is the grand total
                                    decimal totalAmountDue = this.transaction.TransSalePmtDiff - amount;

                                    TenderRequirement tenderRequirement = new TenderRequirement((Tender)tenderInfo, amount, true, this.transaction.TransSalePmtDiff);
                                    if (!string.IsNullOrWhiteSpace(tenderRequirement.ErrorText))
                                    {
                                        using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(tenderRequirement.ErrorText, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error))
                                        {
                                            LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog);
                                        }
                                    }

                                    //Add a loyalty tender item to transaction.
                                    LoyaltyTenderLineItem loyaltyTenderItem = (LoyaltyTenderLineItem)this.Application.BusinessLogic.Utility.CreateLoyaltyTenderLineItem();
                                    loyaltyTenderItem.CardNumber = paymentLoyaltyItem.LoyaltyCardNumber;
                                    loyaltyTenderItem.CardTypeId = cardInfo.CardTypeId;
                                    loyaltyTenderItem.Amount     = amount;

                                    //tenderInfo.
                                    loyaltyTenderItem.Description   = tenderInfo.TenderName;
                                    loyaltyTenderItem.TenderTypeId  = cardInfo.TenderTypeId;
                                    loyaltyTenderItem.LoyaltyPoints = totalNumberOfPoints;

                                    //convert from the store-currency to the company-currency...
                                    loyaltyTenderItem.CompanyCurrencyAmount = this.Application.Services.Currency.CurrencyToCurrency(
                                        ApplicationSettings.Terminal.StoreCurrency,
                                        ApplicationSettings.Terminal.CompanyCurrency,
                                        amount);

                                    // the exchange rate between the store amount(not the paid amount) and the company currency
                                    loyaltyTenderItem.ExchrateMST = this.Application.Services.Currency.ExchangeRate(
                                        ApplicationSettings.Terminal.StoreCurrency) * 100;

                                    // card tender processing and printing require an EFTInfo object to be attached.
                                    // however, we don't want loyalty info to show up where other EFT card info would on the receipt
                                    //  because loyalty has its own receipt template fields, so we just assign empty EFTInfo object
                                    loyaltyTenderItem.EFTInfo = Application.BusinessLogic.Utility.CreateEFTInfo();
                                    // we don't want Loyalty to be 'captured' by payment service, so explicitly set not to capture to be safe
                                    loyaltyTenderItem.EFTInfo.IsPendingCapture = false;

                                    loyaltyTenderItem.SignatureData = LSRetailPosis.POSProcesses.TenderOperation.ProcessSignatureCapture(tenderInfo, loyaltyTenderItem);

                                    this.transaction.Add(loyaltyTenderItem);
                                }
                                else
                                {
                                    using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(50057, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error))
                                    {
                                        LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog);
                                    } // Not enough points available to complete payment
                                }
                            }
                            else
                            {
                                LSRetailPosis.POSProcesses.frmMessage dialog = null;
                                try
                                {
                                    if (string.IsNullOrEmpty(comment))
                                    {
                                        dialog = new LSRetailPosis.POSProcesses.frmMessage(50058, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                                    }
                                    else
                                    {
                                        dialog = new LSRetailPosis.POSProcesses.frmMessage(comment, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                                    }

                                    LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog);    // Invalid loyaltycard
                                }
                                finally
                                {
                                    if (dialog != null)
                                    {
                                        dialog.Dispose();
                                    }
                                }
                            }
                        }
                        else
                        {
                            using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(50059, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error))
                            {
                                LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog); // Not enough points available to complete payment
                            }
                        }
                    }
                }
                finally
                {
                    CloseExistingMessageWindow();
                }
            }
            catch (Exception ex)
            {
                NetTracer.Error(ex, "Loyalty::AddLoyaltyPayment failed for retailTransaction {0} cardInfo {1} amount {2}", retailTransaction.TransactionId, cardInfo.CardNumber, amount);
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), ex);
                throw;
            }
        }
Exemplo n.º 5
0
        public bool AddLoyaltyRequest(IRetailTransaction retailTransaction, ICardInfo cardInfo)
        {
            try
            {
                try
                {
                    NewMessageWindow(50050, LSPosMessageTypeButton.NoButtons, System.Windows.Forms.MessageBoxIcon.Information);

                    LogMessage("Adding a loyalty record to the transaction...",
                               LSRetailPosis.LogTraceLevel.Trace,
                               "Loyalty.AddLoyaltyItem");

                    this.transaction = (RetailTransaction)retailTransaction;

                    // If a previous loyalty item exists on the transaction, the system should prompt the user whether to
                    // overwrite the existing loyalty item or cancel the operation.
                    if (transaction.LoyaltyItem.LoyaltyCardNumber != null)
                    {
                        // Display the dialog
                        using (frmMessage dialog = new frmMessage(50055, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                        {
                            LP.POSFormsManager.ShowPOSForm(dialog);
                            DialogResult result = dialog.DialogResult;

                            if (result != System.Windows.Forms.DialogResult.Yes)
                            {
                                return(false);
                            }
                        }

                        // If card to be overridden is being used as tender type then block loyalty payment.
                        if (transaction.LoyaltyItem.UsageType == LoyaltyItemUsageType.UsedForLoyaltyTender)
                        {
                            LP.POSFormsManager.ShowPOSMessageDialog(3223);  // This transaction already contains a loyalty request.
                            return(false);
                        }
                    }

                    // Add the loyalty item to the transaction

                    LoyaltyItem loyaltyItem = GetLoyaltyItem(ref cardInfo);

                    if (loyaltyItem != null)
                    {
                        transaction.LoyaltyItem = loyaltyItem;
                        this.transaction.LoyaltyItem.UsageType = LoyaltyItemUsageType.UsedForLoyaltyRequest;

                        UpdateTransactionWithNewCustomer(loyaltyItem.CustID);

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                finally
                {
                    CloseExistingMessageWindow();
                }
            }
            catch (Exception ex)
            {
                NetTracer.Error(ex, "Loyalty::AddLoyaltyRequest failed for retailTransaction {0} cardInfo {1}", retailTransaction.TransactionId, cardInfo.CardNumber);
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), ex);
                throw;
            }
        }