示例#1
0
        public void CalculateTax(ITaxableItem taxableItem, IRetailTransaction retailTransaction)
        {
            var codes = GetTaxCodes(taxableItem);

            LineTaxResult lineTaxResult = new LineTaxResult
            {
                HasExempt      = false,
                TaxRatePercent = decimal.Zero,
                TaxAmount      = decimal.Zero,
                ExemptAmount   = decimal.Zero
            };

            foreach (TaxCode code in codes)
            {
                lineTaxResult.TaxAmount += code.CalculateTaxAmount(codes);

                // sum up the amounts that are exempt
                if (code.Exempt)
                {
                    lineTaxResult.HasExempt     = true;
                    lineTaxResult.ExemptAmount += lineTaxResult.TaxAmount;
                }
            }

            // Set the 'virtual tax rate', if extended price is ZERO, then just add the full amount
            decimal extendedPrice = (taxableItem.Price * Math.Abs(taxableItem.Quantity));

            if (extendedPrice == decimal.Zero)
            {
                extendedPrice = decimal.One;
            }

            lineTaxResult.TaxRatePercent = ((lineTaxResult.TaxAmount * 100) / extendedPrice);
            SetLineItemTaxRate(taxableItem, lineTaxResult);
        }
示例#2
0
        /// <summary>
        /// Marks only processed RFID's.
        /// </summary>
        /// <param name="transaction"></param>
        public void MarkProcessedRFIDs(IRetailTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }

            string updList = "";

            //Go through the RFIDs scanned and add them to the RFIDInfo class
            foreach (ISaleLineItem item in ((RetailTransaction)transaction).SaleItems)
            {
                if (!string.IsNullOrEmpty(item.RFIDTagId))
                {
                    //Create an update list that will be used to update all the RFID's read in the previous
                    //sql query. The list is created in case more RFID's might have been read since the query was executed.
                    if (updList.Length != 0)
                    {
                        updList += ", ";
                    }
                    updList += "'" + item.RFIDTagId + "'";
                }
            }

            if (updList.Length != 0)
            {
                //Update the read RFIDs with the current transaction id.
                string sqlUpd = " UPDATE POSISRFIDTABLE " +
                                " SET TRANSACTIONID = '" + transaction.TransactionId + "' " +
                                " WHERE RFID IN (" + updList + ") ";
                DBUtil dbUtil = new DBUtil(Application.Settings.Database.Connection);
                dbUtil.Execute(sqlUpd);
            }
        }
示例#3
0
        /// <summary>
        /// Returns true if add/update loyalty item to transaction is successfull.
        /// </summary>
        /// <param name="retailTransaction"></param>
        /// <param name="cardNumber"></param>
        /// <returns></returns>
        public bool AddLoyaltyRequest(IRetailTransaction retailTransaction, string cardNumber)
        {
            ICardInfo cardInfo = Utility.CreateCardInfo();

            cardInfo.CardNumber = cardNumber;

            return(AddLoyaltyRequest(retailTransaction, cardInfo));
        }
示例#4
0
        public void AddToGiftCard(IRetailTransaction retailTransaction, ITender gcTenderInfo)
        {
            //Start: added on 16/07/2014 for customer selection is must
            RetailTransaction retailTrans = retailTransaction as RetailTransaction;

            if (retailTrans != null)
            {
                if (Convert.ToString(retailTrans.Customer.CustomerId) == string.Empty || string.IsNullOrEmpty(retailTrans.Customer.CustomerId))
                {
                    using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage("Add a customer to transaction before making a deposit", MessageBoxButtons.OK, MessageBoxIcon.Error))
                    {
                        LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog);
                    }
                    return;
                }
            }
            //End: added on 16/07/2014 for customer selection is must

            LogMessage("Adding money to gift card.",
                       LSRetailPosis.LogTraceLevel.Trace,
                       "GiftCard.AddToGiftCard");

            GiftCardController controller = new GiftCardController(GiftCardController.ContextType.GiftCardAddTo, (PosTransaction)retailTransaction, (Tender)gcTenderInfo);

            using (GiftCardForm giftCardForm = new GiftCardForm(controller))
            {
                POSFormsManager.ShowPOSForm(giftCardForm);

                if (giftCardForm.DialogResult == DialogResult.OK)
                {
                    // Add the gift card to the transaction.
                    GiftCertificateItem giftCardItem = (GiftCertificateItem)this.Application.BusinessLogic.Utility.CreateGiftCardLineItem(
                        ApplicationSettings.Terminal.StoreCurrency, this.Application.Services.Rounding, retailTransaction);

                    giftCardItem.SerialNumber  = controller.CardNumber;
                    giftCardItem.StoreId       = retailTransaction.StoreId;
                    giftCardItem.TerminalId    = retailTransaction.TerminalId;
                    giftCardItem.StaffId       = retailTransaction.OperatorId;
                    giftCardItem.TransactionId = retailTransaction.TransactionId;
                    giftCardItem.ReceiptId     = retailTransaction.ReceiptId;
                    giftCardItem.Amount        = controller.Amount;
                    giftCardItem.Balance       = controller.Balance;
                    giftCardItem.Date          = DateTime.Now;
                    giftCardItem.AddTo         = true;

                    giftCardItem.Price = giftCardItem.Amount;
                    giftCardItem.StandardRetailPrice = giftCardItem.Amount;
                    giftCardItem.Quantity            = 1;
                    giftCardItem.TaxRatePct          = 0;
                    giftCardItem.Description         = ApplicationLocalizer.Language.Translate(55000); // Add to Gift Card
                    giftCardItem.Comment             = controller.CardNumber;
                    giftCardItem.NoDiscountAllowed   = true;
                    giftCardItem.Found = true;

                    ((RetailTransaction)retailTransaction).Add(giftCardItem);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Called to update points when conclude a transaction.
        /// </summary>
        /// <param name="retailTransaction"></param>
        public void UpdateLoyaltyPoints(IRetailTransaction retailTransaction)
        {
            if (retailTransaction == null)
            {
                throw new ArgumentNullException("retailTransaction");
            }

            this.transaction = (RetailTransaction)retailTransaction;

            // Sending confirmation to the transactions service about earned points
            if (this.transaction.LoyaltyItem != null)
            {
                if (this.transaction.LoyaltyItem.UsageType == LoyaltyItemUsageType.UsedForLoyaltyRequest)
                {
                    UpdateIssuedLoyaltyPoints(this.transaction.LoyaltyItem);

                    if (this.transaction.LoyaltyItem.CalculatedLoyaltyPoints < 0)
                    {
                        bool    cardIsValid           = false;
                        string  comment               = string.Empty;
                        int     loyaltyTenderTypeBase = 0;
                        decimal pointsEarned          = 0M;

                        GetPointStatus(ref pointsEarned, ref cardIsValid, ref comment, ref loyaltyTenderTypeBase, this.transaction.LoyaltyItem.LoyaltyCardNumber);

                        if (cardIsValid && pointsEarned < 0)
                        {
                            string message = string.Format(LSRetailPosis.ApplicationLocalizer.Language.Translate(50500), pointsEarned);

                            using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(message, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error))
                            {
                                LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(dialog); // Not enough points available to complete payment
                            }
                        }
                    }
                }
                else if (this.transaction.LoyaltyItem.UsageType == LoyaltyItemUsageType.UsedForLoyaltyTender)
                {
                    // Sending confirmation to the transaction service about used points
                    foreach (ITenderLineItem tenderItem in this.transaction.TenderLines)
                    {
                        ILoyaltyTenderLineItem asLoyaltyTenderLineItem = tenderItem as ILoyaltyTenderLineItem;

                        if ((asLoyaltyTenderLineItem != null) && !asLoyaltyTenderLineItem.Voided)
                        {
                            if (asLoyaltyTenderLineItem.LoyaltyPoints != 0)
                            {
                                UpdateUsedLoyaltyPoints(asLoyaltyTenderLineItem);
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// Calculates the charges.
        /// </summary>
        /// <param name="transaction ">The retail transaction.</param>
        public void CalculateCharges(IRetailTransaction transaction)
        {
            RetailTransaction retailTransaction = (RetailTransaction)transaction;

            // TODO:ibrahimd - Update the service for auto charges.

            // put charges on the transaction lines
            foreach (var salesLine in retailTransaction.SaleItems)
            {
                CalculatePriceCharges(salesLine);
            }
        }
示例#7
0
        /// <summary>
        /// Sum up all amounts from the Tax-On-Tax for the whole transaction
        /// </summary>
        /// <param name="retailTransaction"></param>
        /// <returns></returns>
        private decimal CalculateTaxOnTax(IRetailTransaction retailTransaction)
        {
            decimal taxAmount = decimal.Zero;

            if (!String.IsNullOrEmpty(this.TaxOnTax))
            {
                //For each SaleItem, for each TaxLine that matches, sum the TaxLine.Amounts
                taxAmount = ((RetailTransaction)retailTransaction).SaleItems.Sum(
                    saleItem => saleItem.TaxLines.Where(taxLine => taxLine.TaxCode == this.TaxOnTax).Sum(taxLine => taxLine.Amount));
            }

            return(taxAmount);
        }
示例#8
0
        public void PreReturnTransaction(IPreTriggerResult preTriggerResult, IRetailTransaction originalTransaction, IPosTransaction posTransaction)
        {
            if (preTriggerResult == null)
            {
                throw new ArgumentNullException("preTriggerResult");
            }

            // Don't allow returns
            preTriggerResult.ContinueOperation = false;

            // Optional - Specify resource ID and to display message box to user
            preTriggerResult.MessageId = 3033; // "This operation is invalid for this type of transaction.

            Debug.WriteLine("PreReturnTransaction");
        }
示例#9
0
        /// <summary>
        /// Print balance of credit card memo.
        /// </summary>
        /// <param name="formType"></param>
        /// <param name="balance"></param>
        /// <param name="copyReceipt"></param>
        public void PrintCreditMemoBalance(FormType formType, Decimal balance, bool copyReceipt)
        {
            PrintingActions.Print(formType, copyReceipt, true,
                                  delegate(FormModulation formMod, FormInfo formInfo)
            {
                IRetailTransaction tr = Printing.InternalApplication.BusinessLogic.Utility.CreateRetailTransaction(
                    ApplicationSettings.Terminal.StoreId,
                    ApplicationSettings.Terminal.StoreCurrency,
                    ApplicationSettings.Terminal.TaxIncludedInPrice,
                    Printing.InternalApplication.Services.Rounding);
                tr.AmountToAccount = balance;
                formMod.GetTransformedTransaction(formInfo, (RetailTransaction)tr);

                return(formInfo.Header);
            });
        }
示例#10
0
        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;
            }
        }
示例#11
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="context">Context of the gift card form</param>
        /// <param name="posTransaction">Transaction object.</param>
        /// <param name="tenderInfo">Tender information about GC (Required for Payment Context) </param>
        public GiftCardController(ContextType context, PosTransaction posTransaction, Tender tenderInfo)
        {
            this.Context     = context;
            this.Transaction = posTransaction;
            this.tenderInfo  = tenderInfo;
            this.CardNumber  = string.Empty;

            // Get the balance of the transaction.
            IRetailTransaction         retailTransaction          = Transaction as IRetailTransaction;
            CustomerPaymentTransaction customerPaymentTransaction = Transaction as CustomerPaymentTransaction;

            if (retailTransaction != null)
            {
                TransactionAmount = retailTransaction.TransSalePmtDiff;
            }
            else if (customerPaymentTransaction != null)
            {
                TransactionAmount = customerPaymentTransaction.TransSalePmtDiff;
            }
        }
示例#12
0
        public void CalculateTax(ISaleLineItem lineItem, IRetailTransaction transaction)
        {
            try
            {
                lineItem.TaxRatePct = 0;
                lineItem.TaxLines.Clear();
                lineItem.CalculateLine();

                foreach (ITaxProvider provider in Providers)
                {
                    provider.CalculateTax(lineItem, transaction);
                }
            }
            catch (Exception x)
            {
                NetTracer.Error(x, "CalculateTax threw an exception: {0}", x.Message);
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x);
                throw;
            }
        }
        public void ClearTenderRestriction(IRetailTransaction retailTransaction)
        {
            NetTracer.Information("TenderRestriction::ClearTenderRestriction - Start");
            RetailTransaction transaction = retailTransaction as RetailTransaction;

            if (transaction == null)
            {
                throw new ArgumentNullException("retailTransaction");
            }

            for (int i = 0; i < transaction.SaleItems.Count; i++)
            {
                ISaleLineItem lineItem = transaction.GetItem(i + 1);

                lineItem.TenderRestrictionId = string.Empty;
                lineItem.FleetCardNumber     = string.Empty;
                lineItem.PaymentIndex        = -1;
            }
            NetTracer.Information("TenderRestriction::ClearTenderRestriction - End");
        }
示例#14
0
        public void CalculateLoyaltyPoints(IRetailTransaction retailTransaction)
        {
            try
            {
                LogMessage("Adding loyalty points...",
                           LSRetailPosis.LogTraceLevel.Trace,
                           "Loyalty.CalculateLoyaltyPoints");

                this.transaction = (RetailTransaction)retailTransaction;

                //if we already have a loyalty item for tender, we don't accumulated points for this transaction.
                if (this.transaction.LoyaltyItem != null && this.transaction.LoyaltyItem.UsageType == LoyaltyItemUsageType.UsedForLoyaltyTender)
                {
                    return;
                }

                //calculate points.
                this.transaction.LoyaltyItem.UsageType = LoyaltyItemUsageType.NotUsed;
                decimal totalNumberOfPoints = 0;

                // Get the table containing the point logic
                DataTable loyaltyPointsTable = GetLoyaltyPointsSchemeFromDB(this.transaction.LoyaltyItem.SchemeID);

                // Loop through the transaction and calculate the aquired loyalty points.
                if (loyaltyPointsTable != null && loyaltyPointsTable.Rows.Count > 0)
                {
                    totalNumberOfPoints = CalculatePointsForTransaction(loyaltyPointsTable);

                    this.transaction.LoyaltyItem.CalculatedLoyaltyPoints = totalNumberOfPoints;
                    this.transaction.LoyaltyItem.UsageType = LoyaltyItemUsageType.UsedForLoyaltyRequest;
                }

                UpdateTransactionAccumulatedLoyaltyPoint();
            }
            catch (Exception ex)
            {
                NetTracer.Error(ex, "Loyalty::CalculateLoyaltyPoints failed for retailTransaction {0}", retailTransaction.TransactionId);
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), ex);
                throw;
            }
        }
示例#15
0
        /// <summary>
        /// Called when used points are being voided.
        /// </summary>
        /// <param name="voided"></param>
        /// <param name="comment"></param>
        /// <param name="retailTransaction"></param>
        /// <param name="loyaltyTenderItem"></param>
        public bool VoidLoyaltyPayment(IRetailTransaction retailTransaction, ILoyaltyTenderLineItem loyaltyTenderItem)
        {
            if (retailTransaction == null)
            {
                throw new ArgumentNullException("retailTransaction");
            }

            if (loyaltyTenderItem == null)
            {
                throw new ArgumentNullException("loyaltyTenderItem");
            }

            this.transaction = (RetailTransaction)retailTransaction;

            this.transaction.VoidPaymentLine(loyaltyTenderItem.LineId);
            this.transaction.LoyaltyItem = (LoyaltyItem)this.Application.BusinessLogic.Utility.CreateLoyaltyItem();

            UpdateTransactionWithNewCustomer(null);

            return(true);
        }
示例#16
0
        /// <summary>
        /// Calculates the tax for the last item.
        /// </summary>
        /// <param name="retailTransaction">The transaction to be calculated</param>
        public void CalculateTax(IRetailTransaction retailTransaction)
        {
            RetailTransaction transaction = retailTransaction as RetailTransaction;

            if (transaction == null)
            {
                NetTracer.Error("Argument retailTransaction is null");
                throw new ArgumentNullException("retailTransaction");
            }
            foreach (ISaleLineItem saleItem in transaction.SaleItems)
            {
                saleItem.TaxRatePct = 0;
                saleItem.TaxLines.Clear();
                saleItem.CalculateLine();
            }

            ClearMiscChargeTaxLines(transaction);

            foreach (ITaxProvider provider in Providers)
            {
                provider.CalculateTax(transaction);
            }
        }
示例#17
0
        /// <summary>
        /// Calculate taxes for the transaction
        /// </summary>
        /// <param name="retailTransaction"></param>
        public void CalculateTax(IRetailTransaction retailTransaction)
        {
            RetailTransaction transaction = retailTransaction as RetailTransaction;

            if (transaction == null)
            {
                throw new ArgumentNullException("retailTransaction");
            }

            // Clear the cache if transaction is changed.
            if (string.IsNullOrWhiteSpace(cachedTransactionID) ||
                (taxCodeCache.Count > 0 && !cachedTransactionID.Equals(transaction.TransactionId, StringComparison.OrdinalIgnoreCase)))
            {
                cachedTransactionID = transaction.TransactionId;
                taxCodeCache.Clear();
            }

            // at different we have different implementations of Itaxable. Flatten them into a list and loop.
            List <ITaxableItem> taxableItems = new List <ITaxableItem>();

            // Order level charges
            taxableItems.AddRange(transaction.MiscellaneousCharges);

            // Line Level
            foreach (SaleLineItem lineItem in transaction.SaleItems)
            {
                // lineitem itself
                taxableItems.Add(lineItem);

                // associated charges
                taxableItems.AddRange(lineItem.MiscellaneousCharges);
            }

            // Calculate tax on order-level miscellaneous charges
            foreach (ITaxableItem taxableItem in taxableItems)
            {
                //Start : ************AM added on 18/01/2018
                int    iIsTaxableAdv = 0;
                string sAdJustItem   = AdjustmentItemID(ref iIsTaxableAdv);
                int    iTaxIncluded  = getPriceTaxIncludedOrNo();//added RH on 120718

                if (taxableItem.ItemId == sAdJustItem)
                {
                    if (iIsTaxableAdv == 1)
                    {
                        transaction.TaxIncludedInPrice = true;
                    }
                    else
                    {
                        transaction.TaxIncludedInPrice = false;
                    }
                }
                //else if (iTaxIncluded == 0)//added RH on 120718
                //{
                //    transaction.TaxIncludedInPrice = false;
                //}
                //End : ************AM added on 18/01/2018

                this.CalculateTax(taxableItem, transaction);
            }

            //Round by Tax Group if required.
            IEnumerable <string> groups = GetTaxGroupsToRound();

            foreach (string group in groups)
            {
                foreach (BaseSaleItem lineItem in transaction.SaleItems)
                {
                    RoundTaxGroup(lineItem, group);
                }
            }
        }
        public decimal FindTenderRestriction(IRetailTransaction retailTransaction, ICardInfo cardInfo)
        {
            NetTracer.Information("TenderRestriction::FindTenderRestriction - Start");
            RetailTransaction transaction = retailTransaction as RetailTransaction;

            if (transaction == null)
            {
                throw new ArgumentNullException("retailTransaction");
            }

            if (cardInfo == null)
            {
                throw new ArgumentNullException("cardInfo");
            }

            decimal    payableAmount = 0; //the return value of total amount payd with tender id
            ItemStatus itemStatus;        //is the item included / excluded by the tender id

            // Check if there are items in the transaction
            if (transaction.SaleItems.Count == 0)
            {
                POSFormsManager.ShowPOSMessageDialog(50251); //"There are no sales items to check."
                return(payableAmount);
            }

            // Calclulating how much amount of the original amount can be paid.
            foreach (ISaleLineItem lineItem in transaction.SaleItems)
            {
                if (string.IsNullOrEmpty(lineItem.TenderRestrictionId) && (!lineItem.Voided))
                {
                    itemStatus = CheckTenderRestriction(cardInfo.RestrictionCode, cardInfo.TenderTypeId, lineItem.ItemId, lineItem.ItemGroupId);

                    if (itemStatus == ItemStatus.INCLUDE)
                    {
                        lineItem.TenderRestrictionId = cardInfo.RestrictionCode;
                        lineItem.FleetCardNumber     = cardInfo.CardNumber;
                        lineItem.PaymentIndex        = transaction.TenderLines.Count;
                        payableAmount += lineItem.NetAmountWithTax;
                    }
                }
            }

            if (payableAmount != retailTransaction.NetAmountWithTax)
            {
                // If nothing can be paid, then it can be concluded that this card is prohibited
                if (payableAmount == 0)
                {
                    using (LSRetailPosis.POSProcesses.frmMessage dialog = new LSRetailPosis.POSProcesses.frmMessage(50253))
                    {
                        this.Application.ApplicationFramework.POSShowForm(dialog);
                    }
                }
                else
                {
                    string message = string.Format(
                        LSRetailPosis.ApplicationLocalizer.Language.Translate(50151),
                        this.Application.Services.Rounding.Round(payableAmount, false));

                    using (frmTenderRestriction frmExcluded = new frmTenderRestriction(transaction))
                    {
                        frmExcluded.DisplayMsg = message;
                        this.Application.ApplicationFramework.POSShowForm(frmExcluded);

                        if (frmExcluded.DialogResult == DialogResult.No)
                        {
                            ClearTenderRestriction(retailTransaction);
                            return(0);
                        }
                    }
                }
            }

            NetTracer.Information("TenderRestriction::FindTenderRestriction - End");
            return(payableAmount);
        }
示例#19
0
        public void VoidCreditMemoPayment(ref bool voided, ref string comment, string creditMemoNumber, IRetailTransaction retailTransaction)
        {
            try
            {
                LogMessage("Cancelling the used marking of the credit memo...",
                           LogTraceLevel.Trace,
                           "CreditMemo.VoidCreditMemoPayment");

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

                try
                {
                    this.Application.TransactionServices.VoidCreditMemoPayment(ref voided, ref comment, creditMemoNumber,
                                                                               retailTransaction.StoreId,
                                                                               retailTransaction.TerminalId);
                }
                catch (Exception x)
                {
                    LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x);
                    throw;
                }
            }
            catch (Exception x)
            {
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x);
                throw;
            }
        }
示例#20
0
        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;
            }
        }
示例#21
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;
            }
        }
示例#22
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;
            }
        }