public override bool InsertBarCode2Cat(WaresReceiptPromotion parWRP) { using (var DB = new SQLite(ReceiptFile)) { DB.ExecuteNonQuery <WaresReceiptPromotion>(SqlInsertBarCode2Cat, parWRP); } return(true); }
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); }
public virtual bool InsertBarCode2Cat(WaresReceiptPromotion parWRP) { //var o = new { CodePeriod = parIdReceipt.CodePeriod, CodeReceipt = parIdReceipt.CodeReceipt, IdWorkplace = parIdReceipt.IdWorkplace, CodeWares= parIdReceipt.CodeWares, BarCode = parBarCode }; db.ExecuteNonQuery <WaresReceiptPromotion>(SqlInsertBarCode2Cat, parWRP); return(true); }
/// <summary> /// Розраховуємо знижки по наборах /// Можливо зумію це зробити колись на рівні БД /// </summary> /// <param name="parIdReceipt"></param> /// <returns></returns> public bool GetPricePromotionKit(IdReceipt parIdReceipt, int parCodeWares) { if (parCodeWares > 0 && !IsWaresInPromotionKit(parCodeWares)) { return(true); } var varRes = new List <WaresReceiptPromotion>(); var par = new ParamPricePromotionKit(parIdReceipt, ModelMID.Global.CodeWarehouse); var r = db.Execute <ParamPricePromotionKit, PromotionWaresKit>(SqlGetPricePromotionKit, par); int NumberGroup = 0; decimal Quantity = 0, AddQuantity = 0; Int64 CodePS = 0; var RW = ViewReceiptWares(parIdReceipt); foreach (var el in r) //цикл по Можливим позиціям з знижкою. { if (el.CodePS != CodePS || el.NumberGroup != NumberGroup) { Quantity = el.Quantity; CodePS = el.CodePS; NumberGroup = el.NumberGroup; } if (Quantity > 0) // Надаєм знижку на інші позиції набору. { var varQuantityReceipt = RW.Where(e => e.CodeWares == el.CodeWares).Sum(e => e.Quantity); // Можливо поправить ситуацію з неправильно заведенеми акцічми. var varQuantityUsed = varRes.Where(e => e.CodeWares == el.CodeWares /*&& e.NumberGroup==el.NumberGroup*/).Sum(e => e.Quantity); if (varQuantityReceipt - varQuantityUsed > 0) //Якщо ще можемо дати знижку на позицію { if (varQuantityReceipt - varQuantityUsed >= Quantity) { AddQuantity = Quantity; Quantity = 0; } else { AddQuantity = varQuantityReceipt - varQuantityUsed; Quantity -= varQuantityReceipt - varQuantityUsed; } decimal vPrice = el.Price; if (el.TypeDiscount == eTypeDiscount.PercentDiscount) { var Price = RW.Where(e => e.CodeWares == el.CodeWares).Sum(e => e.Price); vPrice = Price * el.DataDiscount / 100m; } var RWP = new WaresReceiptPromotion(parIdReceipt) { CodeWares = el.CodeWares, Quantity = AddQuantity, Price = vPrice, CodePS = el.CodePS, NumberGroup = el.NumberGroup }; varRes.Add(RWP); } } } DeleteWaresReceiptPromotion(parIdReceipt); if (varRes.Count > 0) { ReplaceWaresReceiptPromotion(varRes); } return(true); }