예제 #1
0
 public static SoldItem Instance()
 {
     if (soldItem == null)
     {
         soldItem = new SoldItem();
     }
     return(soldItem);
 }
예제 #2
0
        public decimal LineQuantity()
        {
            decimal total = 0m;

            System.Data.DataRow[] rows = SoldItem.Instance().Select("CategoryId = '" + this.Id + "'");
            if (rows.Length > 0)
            {
                total = Convert.ToDecimal(SoldItem.Instance().Compute("Sum(Quantity)", "CategoryId = '" + this.Id + "'"));
            }
            return(total);
        }
예제 #3
0
        internal decimal LineTotal(int plu)
        {
            decimal total = 0m;

            System.Data.DataRow[] rows = SoldItem.Instance().Select("Plu = '" + plu + "'");
            if (rows.Length > 0)
            {
                total = Convert.ToDecimal(SoldItem.Instance().Compute("Sum(Quantity)", "Plu = '" + plu + "'"));
            }

            return(total);
        }
예제 #4
0
        public decimal TotalAmount()
        {
            decimal total = 0m;

            System.Data.DataRow[] rows = SoldItem.Instance().Select("Plu = '" + this.Id + "'");
            if (rows.Length > 0)
            {
                total = Convert.ToDecimal(SoldItem.Instance().Compute("Sum(Amount)", "Plu = '" + this.Id + "'"));
            }

            return(total);
        }
예제 #5
0
        public decimal TotalAmount()
        {
            decimal subtotal = (decimal)SoldItem.Instance().Compute("Sum(Amount) - Sum(DiscountAmount)", "");

            if (base.GiftProductQuantity > 0)
            {
                IProduct p         = Promotion.FindProductByLabel(base.GiftProductLabelNo);
                int      giftRatio = (int)(subtotal / base.requiredAmount);
                subtotal = p.UnitPrice * Math.Min(SoldItem.Instance().LineTotal(base.GiftProductLabelNo), giftRatio);
            }
            return(subtotal);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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);
        }
예제 #9
0
        internal Promotion(String[] saleList, bool isFirstPayment)
        {
            String[] lineitems;
            Decimal  quantity;
            Decimal  amount;
            Int32    pluno;
            Int32    lineno;

            this.isFirstPayment = isFirstPayment;

            soldItems = SoldItem.Initialize();

            for (int cntr = 0; cntr < saleList.Length; cntr++)
            {
                lineitems = saleList[cntr].Split(',');

                if (lineitems.Length < 2)
                {
                    continue;
                }
                try
                {
                    switch (lineitems[3])
                    {
                    case Message.SAT:
                    case Message.IPT:
                        int quantityLength = lineitems[4].IndexOf('.') + 4;
                        pluno    = Int32.Parse(lineitems[4].Substring(quantityLength, 6));
                        lineno   = Int32.Parse(lineitems[1]);
                        quantity = Decimal.Parse(lineitems[4].Substring(0, quantityLength)) / 1000;
                        amount   = Decimal.Parse(lineitems[5].Substring(2, 10)) / 100;

                        int sign = lineitems[3] == Message.SAT ? 1 : -1;

                        IProduct p = FindProductByLabel(pluno);
                        if (p == null)
                        {
                            break;
                        }

                        int categoryId = Convert.ToInt32(p.Category);

                        soldItems.Add(pluno, lineno, sign * quantity, sign * amount);
                        break;

                    case Message.NAK:
                        paymentMethod = PaymentMethods.CASH;
                        paymentType   = "NAK";
                        paymentAmount = Decimal.Parse(lineitems[5].Substring(2, 10)) / 100;
                        break;

                    case Message.KRD:
                        paymentMethod = PaymentMethods.CREDIT;
                        paymentType   = String.Format("K{0,2}", lineitems[4].Substring(lineitems[4].Length - 2, 2));
                        paymentAmount = Decimal.Parse(lineitems[5].Substring(2, 10)) / 100;
                        break;

                    case Message.CHK:
                        paymentMethod = PaymentMethods.CHECK;
                        paymentType   = "CEK";
                        paymentAmount = Decimal.Parse(lineitems[5].Substring(2, 10)) / 100;
                        break;

                    case Message.DVZ:
                        paymentMethod = PaymentMethods.FOREIGNCURRENCY;
                        paymentType   = String.Format("D{0,2}", lineitems[4].Substring(0, 1));
                        paymentAmount = Decimal.Parse(lineitems[5].Substring(2, 10)) / 100;
                        break;

                    case Message.TOP:
                        documentTotalAmount = Decimal.Parse(lineitems[5].Substring(2, 10)) / 100;
                        break;

                    case Message.END:
                        if (lineitems[4].Trim() != String.Empty)
                        {
                            promotionRange = PromotionRange.CUSTOMER;
                        }
                        customerCode = lineitems[4].Trim() + lineitems[5].Substring(0, 8).Trim();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Settings.Log(String.Format("Hata Olustu! {0}", ex.Message));
                }
            }
            if (paymentMethod == PaymentMethods.NONE)
            {
                paymentAmount = documentTotalAmount;
            }

            /*if the no sale line for the void line*/

            //foreach (int catId in saleCategories.Keys)
            //{
            //    saleCategories[catId].ClearNonconsistentVoids();
            //}
        }
예제 #10
0
 internal static SoldItem Initialize()
 {
     return(soldItem = new SoldItem());
 }
예제 #11
0
        public void ApplyPromotion()
        {
            decimal ratio = 0m;
            decimal lineDiscount = 0m, percDiscount = 0m;

            switch (base.LimitType)
            {
            case LimitType.Quantity:
                ratio        = (int)(LineQuantity() / base.RequiredQuantity);
                lineDiscount = ratio * base.Discount;
                percDiscount = Rounder.RoundDecimal((TotalPercantageDiscount() / LineQuantity()) * (ratio * base.RequiredQuantity), 2, true);
                break;

            case LimitType.Amount:
                ratio        = (TotalAmount() / base.RequiredAmount);
                lineDiscount = LineQuantity() * base.Discount;
                percDiscount = Rounder.RoundDecimal(TotalPercantageDiscount(), 2, true);
                break;

            default:
                ratio        = LineQuantity();
                lineDiscount = ratio * base.Discount;
                percDiscount = Rounder.RoundDecimal(TotalPercantageDiscount(), 2, true);
                break;
            }

            bool isPercentage = false;

            if (percDiscount > lineDiscount)
            {
                lineDiscount = percDiscount;
                isPercentage = true;
            }
            DataRow[] items = SoldItem.Instance().Select(String.Format("Plu = '{0}'", base.Id));

            if (base.limitType != LimitType.Quantity && isPercentage)
            {
                foreach (DataRow rowItems in items)
                {
                    rowItems["DiscountAmount"]  = Rounder.RoundDecimal(((decimal)rowItems["Amount"] * base.PercentDiscount) / 100, 2, true);
                    rowItems["PercentDiscount"] = base.PercentDiscount;
                }
            }
            else
            {
                decimal discItemQuantity = base.RequiredQuantity * ratio;
                decimal unitDisc         = Rounder.RoundDecimal(lineDiscount / discItemQuantity, 2, true);
                decimal diff             = lineDiscount - Rounder.RoundDecimal(unitDisc * discItemQuantity, 2, true);
                decimal amount           = 0m;

                foreach (DataRow rowItems in items)
                {
                    decimal lineDiscQuantity = (decimal)rowItems["Quantity"];
                    if (lineDiscQuantity <= 0)
                    {
                        continue;
                    }
                    int percRate = base.PercentDiscount;
                    if ((decimal)rowItems["Quantity"] > discItemQuantity)
                    {
                        lineDiscQuantity = discItemQuantity;
                        amount           = (unitDisc * lineDiscQuantity) + diff;
                        percRate         = 0;
                    }
                    else
                    {
                        amount = (unitDisc * lineDiscQuantity) + diff;
                    }

                    diff                       = 0;
                    discItemQuantity          -= lineDiscQuantity;
                    rowItems["DiscountAmount"] = (decimal)rowItems["DiscountAmount"] + amount;
                    if (isPercentage)
                    {
                        rowItems["PercentDiscount"] = percRate;
                    }
                    if (discItemQuantity == 0)
                    {
                        break;
                    }
                }
            }

            decimal appliedDisc = (decimal)SoldItem.Instance().Compute("Sum(DiscountAmount)", String.Format("Plu = '{0}'", base.Id));

            pointEarned = (long)ratio * (base.Points + base.ExtraPoints);
            SoldItem.Instance().SetPromotion(this, appliedDisc + pointEarned > 0);
        }