コード例 #1
0
ファイル: Promotion.cs プロジェクト: serhatmorkoc/cepos
        internal String[] CreateProductPromotion()
        {
            long pointsEarned = 0;

            ICustomer customer = null;

            if (SecurityConnector.CurrentCustomer != null && customerCode == SecurityConnector.CurrentCustomer.Code)
            {
                customer = SecurityConnector.CurrentCustomer;
            }

            foreach (IPromotion pr in Settings.SalePromotions)
            {
                if (!pr.PromotionCoverAll(this.promotionRange))
                {
                    continue;
                }
                if (this.promotionRange == PromotionRange.CUSTOMER)
                {
                    if (customer == null || !((BasePromotion)pr).CheckCustomerGroup(customer))
                    {
                        continue;
                    }
                }
                BasePromotion basePRM = (BasePromotion)pr;
                if (basePRM.LimitType != LimitType.NoLimit)
                {
                    continue;
                }

                //compare promotions with requirement totals
                if (CheckLimit(basePRM))
                {
                    soldItems.SetPromotion(basePRM, false);
                }
            }

            //Apply product and category promotion to document
            BasePromotion[] tempPromotions = soldItems.Promotions;
            foreach (BasePromotion prm in tempPromotions)
            {
                ((IPromotion)prm).ApplyPromotion();
                pointsEarned += ((IPromotion)prm).PointEarned;
            }

            List <String> promoLines = soldItems.PromotedLines;

            if (promoLines.Count > 0)
            {
                promoLines.Add(String.Format("00,KOD,{0}", Settings.PromoKey));
            }
            for (int cntr = 0; cntr < promoLines.Count; cntr++)
            {
                promoLines[cntr] = String.Format("1,{0:D5},{1}", cntr + 1, promoLines[cntr]);
            }


            return(promoLines.ToArray());
        }
コード例 #2
0
ファイル: SoldItem.cs プロジェクト: serhatmorkoc/cepos
 internal void SetPromotion(BasePromotion basePRM, bool isApplied)
 {
     DataRow[] rows = promotions.Select("Id = '" + basePRM.Id + "'");
     if (rows.Length > 0)
     {
         if (!(bool)rows[0]["IsApplied"])
         {
             rows[0]["IsApplied"] = isApplied;
         }
     }
     else
     {
         promotions.Rows.Add(basePRM.Id, basePRM, isApplied);
     }
 }
コード例 #3
0
ファイル: SoldItem.cs プロジェクト: serhatmorkoc/cepos
        internal List <int> GetSalesID(BasePromotion basePRM)
        {
            List <int> salesIDList = new List <int>();

            string query = String.Format("Plu ={0} And Quantity > 0", basePRM.GiftProductLabelNo);

            DataRow[] rows = SoldItem.Instance().Select(query);

            foreach (DataRow row in rows)
            {
                salesIDList.Add((int)row["LineNo"]);
            }

            return(salesIDList);
        }
コード例 #4
0
ファイル: Promotion.cs プロジェクト: serhatmorkoc/cepos
        private bool CheckLimit(BasePromotion basePRM)
        {
            switch (basePRM.LimitType)
            {
            case LimitType.NoLimit:
                return(SoldItem.Instance().TotalAmount(basePRM) > 0m);

            case LimitType.Amount:
                return(soldItems.TotalAmount(basePRM) >= basePRM.RequiredAmount);

            case LimitType.Quantity:
                return(soldItems.LineTotal(basePRM) >= basePRM.RequiredQuantity);

            default:
                return(false);
            }
        }
コード例 #5
0
ファイル: SoldItem.cs プロジェクト: serhatmorkoc/cepos
        internal void GiveAsPromotion(BasePromotion basePRM)
        {
            decimal giftQuantity    = basePRM.GiftProductQuantity;
            decimal appliedQuantity = 0m;
            string  query           = String.Format("Plu ={0} And Quantity > 0", basePRM.GiftProductLabelNo);

            DataRow[] rows = SoldItem.Instance().Select(query);
            if (rows.Length > 0)
            {
                foreach (DataRow row in rows)
                {
                    appliedQuantity       = Math.Min(giftQuantity, (decimal)row["Quantity"]);
                    giftQuantity         -= appliedQuantity;
                    row["DiscountAmount"] = (decimal)row["DiscountAmount"] +
                                            Math.Round(appliedQuantity * ((decimal)row["Amount"] - (decimal)row["DiscountAmount"]) / (decimal)row["Quantity"], 2);
                    row["Quantity"] = (decimal)row["Quantity"] - appliedQuantity;
                    if (giftQuantity <= 0)
                    {
                        break;
                    }
                }
            }
            SetPromotion(basePRM, appliedQuantity > 0);
        }
コード例 #6
0
ファイル: Promotion.cs プロジェクト: serhatmorkoc/cepos
        internal String[] CreatePromotionList()
        {
            if (documentTotalAmount == 0)
            {
                return new String[] { }
            }
            ;

            List <String> promoRemarks = new List <string>();
            long          pointsEarned = 0;

            ICustomer customer = null;

            if (SecurityConnector.CurrentCustomer != null && customerCode == SecurityConnector.CurrentCustomer.Code)
            {
                customer = SecurityConnector.CurrentCustomer;
            }

            if (customer != null)
            {
                remarks.Add("M", customer.Name);
            }

            foreach (IPromotion pr in Settings.SalePromotions)
            {
                if (!pr.PromotionCoverAll(this.promotionRange))
                {
                    continue;
                }
                if (this.promotionRange == PromotionRange.CUSTOMER)
                {
                    if (customer == null || !((BasePromotion)pr).CheckCustomerGroup(customer))
                    {
                        continue;
                    }
                }
                BasePromotion basePRM = (BasePromotion)pr;

                IProduct giftProduct = null;
                if (basePRM.GiftProductLabelNo > 0)
                {
                    giftProduct = FindProductByLabel(basePRM.GiftProductLabelNo);
                }
                if (basePRM.LimitType == LimitType.NoLimit && giftProduct == null && basePRM.Points == 0)
                {
                    continue;
                }
                //compare promotions with requirement totals
                if (CheckLimit(basePRM))
                {
                    soldItems.SetPromotion(basePRM, false);
                    if (giftProduct != null && soldItems.LineTotal(basePRM.GiftProductLabelNo) > 0m)
                    {
                        if (basePRM.LimitType == LimitType.Amount)
                        {
                            soldItems.GiveAsPromotion(basePRM);
                        }
                        else if (soldItems.LineTotal(basePRM) >= basePRM.RequiredQuantity)
                        {
                            //calculates how many times promotion will applied
                            int giftRatio = (int)(soldItems.LineTotal(basePRM) / basePRM.RequiredQuantity);
                            for (int i = 0; i < giftRatio; i++)
                            {
                                soldItems.GiveAsPromotion(basePRM);
                            }
                        }
                    }
                }
            }

            //Apply product and category promotion to document
            BasePromotion[] tempPromotions = soldItems.Promotions;
            foreach (BasePromotion prm in tempPromotions)
            {
                ((IPromotion)prm).ApplyPromotion();
                pointsEarned += ((IPromotion)prm).PointEarned;
            }
            //Gets total discount amount
            totalDiscount = soldItems.TotalDiscount();
            List <String> promoLines = soldItems.PromotedLines;

            String promocodeApplied = "";
            List <TotalPromotion> giftPromotions = new List <TotalPromotion>();

            //define best total promotion
            TotalPromotion bestTotalPromotion = null;
            //Decimal promotedTotal = paymentAmount - totalDiscount;
            Decimal promotedTotal = documentTotalAmount - totalDiscount;

            foreach (IPromotion pr in Settings.TotalPromotions)
            {
                if (!pr.PromotionCoverAll(this.promotionRange))
                {
                    continue;
                }
                if (!pr.CheckPaymentType(paymentType))
                {
                    continue;
                }
                if ((this.promotionRange == PromotionRange.CUSTOMER) && (customer == null || !((TotalPromotion)pr).CheckCustomerGroup(customer)))
                {
                    continue;
                }

                TotalPromotion totalPromo = (TotalPromotion)pr;
                if (totalPromo.GiftProductLabelNo > 0)
                {
                    giftPromotions.Add((TotalPromotion)pr);

#if ISKULTUR
                    IProduct product  = FindProductByLabel(totalPromo.GiftProductLabelNo);
                    Decimal  quantity = soldItems.LineTotal(totalPromo.GiftProductLabelNo);

                    Decimal amountWithoutProduct = promotedTotal - product.UnitPrice * quantity;
                    if (amountWithoutProduct >= totalPromo.RequiredAmount)
                    {
                        promotedTotal = amountWithoutProduct;
                    }
#endif
                }
                else
                {
                    Decimal requiredAmount = totalPromo.HavePayment ? promotedTotal : (documentTotalAmount - totalDiscount);
                    //select best total promotion as discount amount
                    if (totalPromo.RequiredAmount <= requiredAmount)
                    {
                        bestTotalPromotion = bestTotalPromotion == null ? totalPromo : ComparePromotions(bestTotalPromotion, totalPromo, documentTotalAmount);
                    }
                }
            }

            Decimal discountTotalPromotion = 0, discountCustomerPromotion = 0;

            if (bestTotalPromotion != null)
            {
                // Promosyonun ödeme tipine baðlý deðilse promosyon ödeme parçalý olsa da aratoplama uygulanýyor.
                //if (!bestTotalPromotion.HavePayment)
                //{
                //    paymentAmount = documentTotalAmount;
                //    promotedTotal = paymentAmount - totalDiscount;
                //}
            }

            //Qunatity to be promotion applied
            int ratio = 0;
            if (bestTotalPromotion != null)
            {
                ratio = (int)((promotedTotal) / bestTotalPromotion.RequiredAmount);
                discountTotalPromotion = Math.Max(bestTotalPromotion.Discount, promotedTotal * bestTotalPromotion.PercentDiscount / 100m);
                if (bestTotalPromotion.RequiredAmount <= promotedTotal)
                {
                    discountTotalPromotion = Math.Max(bestTotalPromotion.Discount * ratio, promotedTotal * bestTotalPromotion.PercentDiscount / 100m);
                }
                else
                {
                    discountTotalPromotion = discountTotalPromotion > totalDiscount ? discountTotalPromotion : 0;
                }

                //pointsEarned += (bestTotalPromotion.Points + bestTotalPromotion.ExtraPoints) * ratio;
            }

            //Apply gift product promotions
            Decimal promoReqAmount = promotedTotal;

#if ISKULTUR
            promoReqAmount -= discountTotalPromotion;
#endif

            while (true)
            {
                TotalPromotion tp = BestGiftPromotion(giftPromotions, promoReqAmount);
                if (tp == null)
                {
                    break;
                }
                ratio = (int)((promoReqAmount) / tp.RequiredAmount);
                IProduct giftProduct  = FindProductByLabel(tp.GiftProductLabelNo);
                Decimal  lineQuantity = soldItems.LineTotal(tp.GiftProductLabelNo);
                for (int i = 0; i < ratio && lineQuantity > 0; i++)
                {
                    promoReqAmount -= tp.RequiredAmount;
                    decimal lineDiscount = Math.Max(tp.Discount, giftProduct.UnitPrice * tp.PercentDiscount / 100m);
                    long    linePoint    = (tp.Points + tp.ExtraPoints);

                    if (lineQuantity < 1)
                    {
                        lineDiscount = lineDiscount * lineQuantity;
                        linePoint    = (long)(linePoint * lineQuantity);
                    }

#if ISKULTUR
                    promoLines.Add(
                        String.Format("06,IND,SAT {0:D4} %{1:D2},  {2:D10}",
                                      soldItems.GetSalesID((BasePromotion)tp)[i],
                                      (int)0,
                                      (int)Math.Round(lineDiscount * 100, 0)));

                    if (promoLines.Count > 0)
                    {
                        promoLines.Add(String.Format("00,KOD,{0}", Settings.PromoKey));
                    }
                    for (int cntr = 0; cntr < promoLines.Count; cntr++)
                    {
                        promoLines[cntr] = String.Format("1,{0:D5},{1}", cntr + 1, promoLines[cntr]);
                    }

                    pointsEarned += linePoint;
                    lineQuantity  = soldItems.LineTotal(tp.GiftProductLabelNo);
#else
                    discountTotalPromotion += lineDiscount;
                    pointsEarned           += linePoint;
                    soldItems.GiveAsPromotion(tp);
                    lineQuantity = soldItems.LineTotal(tp.GiftProductLabelNo);
#endif
                }
            }

#if ISKULTUR
            promotedTotal = documentTotalAmount;
#endif
            promotedTotal -= discountTotalPromotion;

            String[] appliedCodes = soldItems.AppliedCodes;
            foreach (String appliedCode in appliedCodes)
            {
                if (appliedCode.Length > 0 && !Str.Contains(promocodeApplied, (appliedCode.Trim() + ",")))
                {
                    promocodeApplied = promocodeApplied + appliedCode.Trim();
                }
            }
            TotalPromotion bestPointPromo = null;

            if (customer != null)
            {
                discountCustomerPromotion = documentTotalAmount * customer.PromotionLimit / 100m;
            }

            promotedTotal -= discountCustomerPromotion;
            if (discountCustomerPromotion > 0)
            {
                promocodeApplied += "M";
            }

            if (bestTotalPromotion != null)
            {
                promocodeApplied += bestTotalPromotion.PromotionCode;
            }

            //decimal ttlDiscount = paymentAmount - promotedTotal - totalDiscount;
            decimal ttlDiscount = 0;
            if (isFirstPayment)
            {
                ttlDiscount = documentTotalAmount - promotedTotal - totalDiscount;
            }


            if (paymentAmount > promotedTotal && isFirstPayment)
            {
                paymentAmount = promotedTotal;
            }

            bestPointPromo = BestPointPromotion(paymentAmount);

            if (bestPointPromo != null)
            {
                int pointMultiple = (int)((paymentAmount) / bestPointPromo.RequiredAmount);

                pointsEarned += (bestPointPromo.Points + bestPointPromo.ExtraPoints) * pointMultiple;
                if (!bestPointPromo.Equals(bestTotalPromotion))
                {
                    promocodeApplied += bestPointPromo.PromotionCode;
                }
            }

#if ISKULTUR
            int startIndex = promoLines.Count;
#else
            int startIndex = 0;
#endif

            if (ttlDiscount > 0)
            {
                promoLines.Add(String.Format("06,IND,TOP {0:D4} %,  {1:D10}", 0, (Int64)(ttlDiscount * 100)));//%00
            }
            if (promocodeApplied.Length > 0)
            {
                promoLines.Add(String.Format("22,MSG,{0} {1}", PosMessage.PROMOTION_CODE, promocodeApplied));
            }

            if (promoRemarks.Count > 0)
            {
                foreach (string pr in promoRemarks)
                {
                    promoLines.Add("29,NOT," + pr);
                }
            }
            if (pointsEarned > 0 && customer != null && !(Str.Contains(customer.Code, "*")))
            {
                promoLines.Add(String.Format("22,PRM,{0:D9}", pointsEarned));
            }

            if (customer != null && int.Parse(customer.Number) > 0)
            {
                promoLines.Add(String.Format("23,PNT,{0:D9}", customer.Number));
            }
            if (promoLines.Count > 0)
            {
                promoLines.Add(String.Format("00,KOD,{0}", Settings.PromoKey));
            }
            for (int cntr = startIndex; cntr < promoLines.Count; cntr++)
            {
                promoLines[cntr] = String.Format("1,{0:D5},{1}", cntr + 1, promoLines[cntr]);
            }

            return(promoLines.ToArray());
        }
コード例 #7
0
ファイル: SoldItem.cs プロジェクト: serhatmorkoc/cepos
 internal decimal LineTotal(BasePromotion basePRM)
 {
     return(((IPromotion)basePRM).LineQuantity());
 }
コード例 #8
0
ファイル: SoldItem.cs プロジェクト: serhatmorkoc/cepos
 internal decimal TotalAmount(BasePromotion basePRM)
 {
     return(((IPromotion)basePRM).TotalAmount());
 }