Exemple #1
0
        public ReceiptWares AddWaresCode(IdReceipt pIdReceipt, int pCodeWares, int pCodeUnit, decimal pQuantity = 0, decimal pPrice = 0)
        {
            if (pIdReceipt == null)
            {
                pIdReceipt = curRecipt;
            }
            var w = db.FindWares(null, null, pCodeWares, pCodeUnit);

            if (w.Count() == 1)
            {
                var W = w.First();
                W.RecalcTobacco();
                if (pQuantity == 0)
                {
                    return(W);
                }
                W.SetIdReceipt(pIdReceipt);
                if (pPrice > 0 || !W.IsMultiplePrices)
                {
                    W.Quantity = (W.CodeUnit == Global.WeightCodeUnit ? pQuantity / 1000m : pQuantity);//Хак для вагового товару Який приходить в грамах.
                    var res = AddReceiptWares(W, false);
                    if (pPrice > 0 && W.IsMultiplePrices)
                    {
                        WaresReceiptPromotion[] r = new WaresReceiptPromotion[1] {
                            new WaresReceiptPromotion(W)
                            {
                                CodeWares = W.CodeWares, Price = Math.Round(pPrice * (W.TypeWares == 2?1.05M:1M), 2), TypeDiscount = eTypeDiscount.Price, Quantity = pQuantity, CodePS = 999999
                            }
                        };
                        db.ReplaceWaresReceiptPromotion(r);
                        db.RecalcHeadReceipt(pIdReceipt);
                    }
                    if (Global.RecalcPriceOnLine)
                    {
                        db.RecalcPriceAsync(W);
                    }
                    return(res);
                }
                else
                {
                    return(W);
                }
            }
            return(null);
        }