public override ProductViewModel AddProductByProductId(Guid pTerminalId, Guid pProductId, decimal pQuantity = 0, decimal pPrice = 0) { ProductViewModel res = null; try { var CurReceipt = GetCurrentReceiptByTerminalId(pTerminalId); //var g = CurReceipt.ReceiptId; var WId = new IdReceiptWares { WaresId = pProductId }; var RW = Bl.AddWaresCode(CurReceipt, WId.CodeWares, WId.CodeUnit, pQuantity, pPrice); //TODO: OnReceiptChanged?.Invoke(receipt,terminalId); if (RW != null) { res = GetProductViewModel(RW); } FileLogger.WriteLogMessage($"ApiPSU.AddProductByProductId =>(pTerminalId=>{pTerminalId},pProductId=>{pProductId},pQuantity={pQuantity})=>({res?.ToJSON()})", eTypeLog.Full); } catch (Exception e) { FileLogger.WriteLogMessage($"ApiPSU.AddProductByProductId Exception =>(pTerminalId=>{pTerminalId},pProductId=>{pProductId},pQuantity={pQuantity}) => (){Environment.NewLine}Message=>{e.Message}{Environment.NewLine}StackTrace=>{e.StackTrace}", eTypeLog.Error); throw new Exception("ApiPSU.AddProductByProductId", e); } return(res); }
public virtual MinPriceIndicative GetMinPriceIndicative(IdReceiptWares parIdReceiptWares) { var res = db.Execute <IdReceiptWares, MinPriceIndicative>(SqlGetMinPriceIndicative, parIdReceiptWares); if (res != null) { return(res.FirstOrDefault()); } return(null); }
public bool InsertWeight(string parBarCode, int parWeight, Guid parWares, TypeSaveWeight parTypeSaveWeight) { var CodeWares = 0; if (string.IsNullOrEmpty(parBarCode) && parWares == Guid.Empty) { return(false); } if (parWares != Guid.Empty) { CodeWares = new IdReceiptWares(new IdReceipt(), parWares).CodeWares; } return(db.InsertWeight(new { BarCode = (parTypeSaveWeight == TypeSaveWeight.Add || parBarCode == null ? CodeWares.ToString() : parBarCode), Weight = (decimal)parWeight / 1000m, Status = parTypeSaveWeight })); }
public virtual IEnumerable <ReceiptWares> ViewReceiptWares(IdReceiptWares parIdReceiptWares, bool pIsReceiptWaresPromotion = false) { var r = this.db.Execute <IdReceiptWares, ReceiptWares>(SqlViewReceiptWares, parIdReceiptWares); if (r != null && pIsReceiptWaresPromotion) { var wrp = GetReceiptWaresPromotion(parIdReceiptWares); if (wrp != null) { foreach (var el in r) { el.ReceiptWaresPromotions = wrp.Where(rr => ((IdReceiptWares)rr).Equals((IdReceiptWares)el)); } } } return(r); }
public bool ChangeQuantity(IdReceiptWares pReceiptWaresId, decimal pQuantity) { bool isZeroPrice = false; var res = false; var W = db.FindWares(null, null, pReceiptWaresId.CodeWares, pReceiptWaresId.CodeUnit); if (W.Count() == 1) { var w = W.First(); w.SetIdReceipt(pReceiptWaresId); if (pQuantity == 0) { db.DeleteReceiptWares(w); _ = VR.SendMessageAsync(w.IdWorkplace, w.NameWares, w.Articl, w.Quantity, w.Sum, VR.eTypeVRMessage.DeleteWares); } else { //w.SetIdReceiptWares(); w.Quantity = pQuantity; w.Sort = -1; if (w.AmountSalesBan > 0 && w.Quantity > w.AmountSalesBan && (w.CodeUnit != Global.WeightCodeUnit && w.CodeUnit != Global.WeightCodeUnit)) { w.Quantity = w.AmountSalesBan; if (Global.IsOldInterface) { isZeroPrice = true; } else { Global.OnClientWindows?.Invoke(w.IdWorkplace, eTypeWindows.LimitSales, $"Даний товар {w.NameWares} {Environment.NewLine} має обмеження в кількості {w.AmountSalesBan} шт"); } } res = db.UpdateQuantityWares(w); _ = VR.SendMessageAsync(w.IdWorkplace, w.NameWares, w.Articl, w.Quantity, w.Sum, VR.eTypeVRMessage.UpdateWares); } if (Global.RecalcPriceOnLine) { db.RecalcPriceAsync(pReceiptWaresId); } } return(res); }
/* * public override eRezultFind FindData(string parStr, eTypeFind parTypeFind = eTypeFind.All) * { * eRezultFind varRezult; * varRezult.Count = 0; * varRezult.TypeFind = eTypeFind.All; * string varStr = parStr.Trim(); * Int64 varNumber = 0; * Int64.TryParse(varStr, out varNumber); * this.db.ExecuteNonQuery("delete from T$1"); * // Шукаемо Товар * * if (parTypeFind != eTypeFind.Client) * { * varRezult.TypeFind = eTypeFind.Wares; * if (varNumber > 0) * { * if (varStr.Length >= GlobalVar.MinLenghtBarCodeWares) * {//Шукаємо по штрихкоду * this.db.ExecuteNonQuery(this.SqlFindWaresBar, new { BarCode = varStr }); * } * else//Шукаемо по коду * { * if (GlobalVar.TypeFindWares < 2) * this.db.ExecuteNonQuery(this.SqlFindWaresCode + varStr); * } * } * else // Шукаємо по назві * { * if (GlobalVar.TypeFindWares == 0)//Можна шукати по назві * this.db.ExecuteNonQuery(SqlFindWaresName + "'%" + varStr.ToUpper().Replace(" ", "%") + "%'"); * } * varRezult.Count = this.GetCountT1(); * * if (varRezult.Count > 0) return varRezult;//Знайшли товар * } * // ШукаемоКлієнта * * if (parTypeFind != eTypeFind.Wares) * { * varRezult.TypeFind = eTypeFind.Client; * if (varNumber > 0) * { * if (varStr.Length >= GlobalVar.MinLenghtBarCodeClient) * {//Шукаємо по штрихкоду * * this.db.ExecuteNonQuery(SqlFindClientBar, new { BarCode = varStr }); * * } * else * if (GlobalVar.TypeFindClient < 2) * { * this.db.ExecuteNonQuery<object>(SqlFindClientCode, new { CodePrivat = varStr }); * } * } * else // Пошук по назві * { * if (GlobalVar.TypeFindClient == 0)//Можна шукати по назві * this.db.ExecuteNonQuery(SqlFindClientName + "'%" + varStr.Replace(" ", "%") + "%'"); * * } * } * varRezult.Count=this.GetCountT1(); * * if( varRezult.Count==0) * varRezult.TypeFind=eTypeFind.All; * * return varRezult; * * } */ public Task RecalcPriceAsync(IdReceiptWares pIdReceiptWares) { return(Task.Run(() => RecalcPrice(pIdReceiptWares)).ContinueWith(async res => { if (await res) { //Console.WriteLine(OnReceiptCalculationComplete != null); var r = ViewReceiptWares(new IdReceiptWares(pIdReceiptWares, 0), true);//вертаємо весь чек. Global.OnReceiptCalculationComplete?.Invoke(r, pIdReceiptWares); if (r == null || r.Count() == 0) { return; } var parW = r.Last(); if (parW != null) { var SumAll = r.Sum(d => d.Sum - d.SumDiscount); _ = VR.SendMessageAsync(parW.IdWorkplace, parW.NameWares, parW.Articl, parW.Quantity, parW.Sum, VR.eTypeVRMessage.AddWares, SumAll); } } })); }
public override ReceiptViewModel ChangeQuantity(Guid pTerminalId, Guid pProductId, decimal pQuantity) { ReceiptViewModel Res = null; try { var CurReceipt = GetCurrentReceiptByTerminalId(pTerminalId); var CurReceiptWares = new IdReceiptWares(CurReceipt, pProductId); if (Bl.ChangeQuantity(CurReceiptWares, pQuantity)) { Res = GetReceiptViewModel(CurReceipt); } FileLogger.WriteLogMessage($"ApiPSU.AddProductByProductId =>(pTerminalId=>{pTerminalId},pProductId=>{pProductId},pQuantity={pQuantity})=>({Res?.ToJSON()})", eTypeLog.Full); } catch (Exception e) { FileLogger.WriteLogMessage($"ApiPSU.AddProductByProductId Exception =>(pTerminalId=>{pTerminalId},pProductId=>{pProductId},pQuantity={pQuantity}) => (){Environment.NewLine}Message=>{e.Message}{Environment.NewLine}StackTrace=>{e.StackTrace}", eTypeLog.Error); throw new Exception("ApiPSU.ChangeQuantity", e); } return(Res); }
public virtual decimal GetLastQuantity(IdReceiptWares parIdReceiptWares) { return(db.ExecuteScalar <IdReceiptWares, decimal>(SqlGetLastQuantity, parIdReceiptWares)); }
public virtual Int64 GetPricePromotionSale2Category(IdReceiptWares parIdReceiptWares) { return(db.ExecuteScalar <IdReceiptWares, Int64>(SqlGetPricePromotionSale2Category, parIdReceiptWares)); }
/// <summary> /// Перераховує ціни з врахуванням акцій, кількостей і ТД /// </summary> /// <param name="parCodeReceipt">Код чека</param> /// <returns> ///Успішно чи ні виконана операція ///</returns> public virtual bool RecalcPrice(IdReceiptWares parIdReceipt) { return(false); }
public virtual decimal GetCountWares(IdReceiptWares parIdReceiptWares) { return(db.ExecuteScalar <IdReceiptWares, decimal>(SqlGetCountWares, parIdReceiptWares)); }
public virtual int GetQuantitySalesBan(IdReceiptWares pSB) { return(db.ExecuteScalar <IdReceiptWares, int>(SqlGetQuantitySalesBan, pSB)); }
public virtual IEnumerable <WaresReceiptPromotion> GetReceiptWaresPromotion(IdReceiptWares parIdReceiptWares) { return(this.db.Execute <IdReceipt, WaresReceiptPromotion>(SqlGetReceiptWaresPromotion, parIdReceiptWares)); }
static void CreateReceipDay() { var SQLGetReceipt = @"SELECT top(500) ISNULL(td.PERCENT_DISCOUNT,0) AS PERCENT_DISCOUNT, dc.bar_code, dr.number,dr.date_time ,w.Code_Wares ,dbo.GetCodeUnit(ud.code_unit) AS Code_Unit , drw.amount ,drw.price ,[disc_perc] as disc_perc_manual ,drw.sum+drw.sum_bonus AS sum ,[disc_perc_auto] ,[is_promotion] ,dr.comment --,drw._Fld11310_RRRef ,CONVERT(nchar(32), _Fld17312RRef, 2) AS type_Promotion , sc._Description AS BarCode2Category -- COUNT(*) FROM dbo.V1C_doc_receipt dr JOIN dbo.V1C_doc_receipt_wares drw ON dr._IDRRef = drw._IDRRef JOIN dbo.Wares w ON drw.nomen_RRef=w._IDRRef LEFT JOIN dbo.V1C_DIM_CARD dc ON dr.card_RRef = dc.Card_RRef LEFT JOIN dbo.V1C_DIM_TYPE_DISCOUNT TD ON TD.TYPE_DISCOUNT_RRef =DC.TYPE_DISCOUNT_RRef JOIN dbo.V1C_dim_addition_unit au ON drw.uom_RRef=au._IDRRef JOIN dbo.V1C_DIM_UNIT_DIMENSION ud ON au.Unit_dimention_RRef=ud.UNIT_DIMENSION_RRef LEFT JOIN UTPPSU.dbo._Reference18060 sc ON drw.barcode_2 = sc._IDRRef WHERE dr._Date_Time BETWEEN CONVERT(DATE,DATEADD(DAY,0,DATEADD(YEAR,2000,GETDATE()))) AND CONVERT(DATE,DATEADD(DAY,1,DATEADD(YEAR,2000,GETDATE()))) --AND ROUND(drw.amount*drw.price,2)<>drw.sum+drw.sum_bonus --and is_promotion=1 AND dr.warehouse_RRef= 0xB7A3001517DE370411DF7DD82E29F000 -- --AND _Fld17312RRef=0xAF5E2CDABF65241E4EB3EC36EC1F11E2 --Комплект --AND _Fld17312RRef=0xA6F61431ECE9ED4646ECAA3A735174ED --По виду дисконтних карт /*0x8CA05E08A127F853433EF4373AE9DC39 --Скидка на день рождения 0xA19CCECEDC498AF84560C115E6F7418A --Количество одного товара в документе превысило 0xA6F61431ECE9ED4646ECAA3A735174ED --По виду дисконтных карт 0xAD63C44DBEEA7E344A9E865F34168F14 --Вторая категория 0xAF5E2CDABF65241E4EB3EC36EC1F11E2 --Комплект*/ --AND td.PERCENT_DISCOUNT<>[disc_perc_auto] --AND dr.number='К1300008702' -- AND drw.sum_bonus>0 ORDER BY dr._IDRRef"; var TerminalId = Guid.Parse("abb75469-0f34-4124-8c53-c5392115269d"); var Api = new ApiPSU(); var LastLine = new TestReceipt(); var MsSQL = new WDB_MsSql(); var Receipt = MsSQL.db.Execute <TestReceipt>(SQLGetReceipt); IdReceiptWares IdWares; var LastReceipt = new IdReceipt(); foreach (var L in Receipt) { IdWares = new IdReceiptWares() { CodeWares = L.Code_Wares, CodeUnit = L.Code_Unit }; if (!L.Number.Equals(LastLine.Number)) { if (LastLine.Number != null) { Api.AddFiscalNumber(LastReceipt.ReceiptId, LastLine.Number); } } var p = Api.AddProductByProductId(TerminalId, IdWares.WaresId, L.Amount); //Api.ChangeQuantity(TerminalId, IdWares.WaresId, L.Amount); if (!L.Number.Equals(LastLine.Number)) { LastReceipt = Api.GetCurrentReceiptByTerminalId(TerminalId); if (L.Bar_Code != null) { Api.GetCustomerByBarCode(TerminalId, L.Bar_Code); } var RH = Api.Bl.GetReceiptHead(LastReceipt); RH.AdditionN1 = L.Percent_Discount; RH.AdditionC1 = L.Number; RH.AdditionD1 = L.Date_Time; RH.DateReceipt = L.Date_Time; Api.Bl.db.ReplaceReceipt(RH); } var RW = Api.Bl.db.ViewReceiptWares(LastReceipt); var RWE = RW.FirstOrDefault(d => d.CodeWares == L.Code_Wares); RWE.AdditionN1 = L.Disc_Perc_Auto; RWE.AdditionN2 = L.Sum * (100m - L.Disc_perc_manual) / 100; RWE.AdditionN3 = L.Is_Promotion; RWE.AdditionC1 = L.Price.ToString() + " " + L.Type_Promotion; RWE.BarCode2Category = L.BarCode2Category; RWE.Description = L.Disc_perc_manual.ToString(); Api.Bl.db.ReplaceWaresReceipt(RWE); LastLine = L; } if (LastLine.Number != null) { Api.AddFiscalNumber(LastReceipt.ReceiptId, LastLine.Number); } }
public ReceiptEvent(IdReceiptWares pRW) : base(pRW) { }
public override bool RecalcPrice(IdReceiptWares pIdReceiptWares) { var startTime = System.Diagnostics.Stopwatch.StartNew(); lock (GetObjectForLockByIdWorkplace(pIdReceiptWares.IdWorkplace)) { try { var RH = ViewReceipt(pIdReceiptWares); ParameterPromotion par; var InfoClient = GetInfoClientByReceipt(pIdReceiptWares); if (InfoClient.Count() == 1) { par = InfoClient.First(); } else { par = new ParameterPromotion(); } //par.BirthDay = DateTime.Now.Date; Test par.CodeWarehouse = Global.CodeWarehouse; par.Time = Convert.ToInt32(RH.DateReceipt.ToString("HHmm")); par.CodeDealer = Global.DefaultCodeDealer; var r = ViewReceiptWares(pIdReceiptWares); foreach (var RW in r) { var MPI = GetMinPriceIndicative((IdReceiptWares)RW); par.CodeWares = RW.CodeWares; var Res = GetPrice(par); if (Res != null && RW.ParPrice1 != 999999 && (Res.Priority > 0 || string.IsNullOrEmpty(RW.BarCode2Category)))//Не перераховуємо для Сигарет s для 2 категорії окрім пріоритет 1 { RW.Price = MPI.GetPrice(Res.Price, Res.IsIgnoreMinPrice == 0, Res.CodePs > 0); RW.TypePrice = MPI.typePrice; RW.ParPrice1 = Res.CodePs; RW.ParPrice2 = (int)Res.TypeDiscont; RW.ParPrice3 = Res.Data; RW.Priority = Res.Priority; } //Якщо друга категорія - перераховуємо на основі Роздрібної ціни. if (Res.Priority == 0 && !string.IsNullOrEmpty(RW.BarCode2Category) && RW.BarCode2Category.Length == 13) { RW.Price = RW.PriceDealer; } ReplaceWaresReceipt(RW); } GetPricePromotionKit(pIdReceiptWares, pIdReceiptWares.CodeWares); RecalcHeadReceipt(pIdReceiptWares); startTime.Stop(); Console.WriteLine($"RecalcPrice=>{startTime.Elapsed} {r?.Count()}"); /*foreach (var RW in r) * Console.WriteLine($"{RW.NameWares}");*/ return(true); } catch (Exception ex) { Global.OnSyncInfoCollected?.Invoke(new SyncInformation { TerminalId = Global.GetTerminalIdByIdWorkplace(pIdReceiptWares.IdWorkplace), Exception = ex, Status = eSyncStatus.Error, StatusDescription = "RecalcPrice=>" + ex.Message + '\n' + new System.Diagnostics.StackTrace().ToString() }); return(false); } } }