public bool ClearDataSaleForReport(ClearDataSaleReportModels request) { NSLog.Logger.Info("ClearDataSaleForReport Request", request); UtilitiesFactory utilitiesFactory = new UtilitiesFactory(); var result = utilitiesFactory.DelDataSalereport(request); NSLog.Logger.Info("ClearDataSaleForReport Result", result); return(result.IsOk); }
//var jsonContent = JsonConvert.SerializeObject(lstInfo); //_baseFactory.InsertTrackingLog("G_DateOfWeeks", jsonContent, "DateOfWeeksId", result); public ResultModels DelDataSalereport(ClearDataSaleReportModels request) { ResultModels result = new ResultModels(); result.IsOk = true; using (NuWebContext cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { var lstBusinesDay = cxt.G_BusinessDay.Where(ww => ww.StartedOn >= request.DFrom && ww.StartedOn <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.G_BusinessDay.RemoveRange(lstBusinesDay); var lstOrderTip = cxt.G_OrderTip.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.G_OrderTip.RemoveRange(lstOrderTip); var lstPayments = cxt.G_PaymentMenthod.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.G_PaymentMenthod.RemoveRange(lstPayments); var lstAudits = cxt.R_AuditTrailReport.Where(ww => ww.ReceiptDate >= request.DFrom && ww.ReceiptDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_AuditTrailReport.RemoveRange(lstAudits); var lstCashIn = cxt.R_CashInOutReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_CashInOutReport.RemoveRange(lstCashIn); var lstCloseReceipts = cxt.R_ClosedReceiptReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_ClosedReceiptReport.RemoveRange(lstCloseReceipts); var lstDailyItems = cxt.R_DailyItemizedSalesReportDetail.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_DailyItemizedSalesReportDetail.RemoveRange(lstDailyItems); var lstDailyItemsForSet = cxt.R_DailyItemizedSalesReportDetailForSet.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_DailyItemizedSalesReportDetailForSet.RemoveRange(lstDailyItemsForSet); var lstDailyReceipt = cxt.R_DailyReceiptReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_DailyReceiptReport.RemoveRange(lstDailyReceipt); var lstDailySale = cxt.R_DailySalesReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_DailySalesReport.RemoveRange(lstDailySale); var lstDiscounts = cxt.R_DiscountAndMiscReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_DiscountAndMiscReport.RemoveRange(lstDiscounts); var lstDiscountDetails = cxt.R_DiscountDetailsReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_DiscountDetailsReport.RemoveRange(lstDiscountDetails); var lstHourlyItem = cxt.R_HourlyItemizedSalesReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_HourlyItemizedSalesReport.RemoveRange(lstHourlyItem); var lstHourlySale = cxt.R_HourlySalesReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_HourlySalesReport.RemoveRange(lstHourlySale); var lstItemizedSales = cxt.R_ItemizedSalesAnalysisReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_ItemizedSalesAnalysisReport.RemoveRange(lstItemizedSales); var lstItemizedSaleDetails = cxt.R_ItemizedSalesAnalysisReportDetail.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_ItemizedSalesAnalysisReportDetail.RemoveRange(lstItemizedSaleDetails); var lstNoIncludeSale = cxt.R_NoIncludeOnSaleDataReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_NoIncludeOnSaleDataReport.RemoveRange(lstNoIncludeSale); var lstNoSale = cxt.R_NoSaleDetailReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_NoSaleDetailReport.RemoveRange(lstNoSale); var lstReceiptsbyPaymentMethods = cxt.R_ReceiptsbyPaymentMethodsReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_ReceiptsbyPaymentMethodsReport.RemoveRange(lstReceiptsbyPaymentMethods); var lstTimeClock = cxt.R_TimeClockReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_TimeClockReport.RemoveRange(lstTimeClock); var lstTopSale = cxt.R_TopSellingProductsReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_TopSellingProductsReport.RemoveRange(lstTopSale); var lstRefund = cxt.R_Refund.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); if (lstRefund != null && lstRefund.Any()) { var lstId = lstRefund.Select(ss => ss.Id).ToList(); var lstRefundDetail = cxt.R_RefundDetail.Where(ww => lstId.Contains(ww.RefundId)); cxt.R_RefundDetail.RemoveRange(lstRefundDetail); cxt.R_Refund.RemoveRange(lstRefund); } var lstHourlyItemized = cxt.R_HourlyItemizedSalesReport.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_HourlyItemizedSalesReport.RemoveRange(lstHourlyItemized); var lstItemizedCancelOrRefund = cxt.R_ItemizedCancelOrRefundData.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_ItemizedCancelOrRefundData.RemoveRange(lstItemizedCancelOrRefund); //shiftlog var lstShiftLog = cxt.R_ShiftLog.Where(ww => ww.StartedOn >= request.DFrom && ww.StartedOn <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_ShiftLog.RemoveRange(lstShiftLog); //Pos Sale var posSales = cxt.R_PosSale.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_PosSale.RemoveRange(posSales); var posSalesDetail = cxt.R_PosSaleDetail.Where(ww => ww.CreatedDate >= request.DFrom && ww.CreatedDate <= request.DTo && request.ListStoreIds.Contains(ww.StoreId)); cxt.R_PosSaleDetail.RemoveRange(posSalesDetail); cxt.SaveChanges(); transaction.Commit(); NSLog.Logger.Info("Delete data sale report success", request); } catch (Exception ex) { NSLog.Logger.Error("Delete data sale report fail", ex); //_logger.Error(ex); result.IsOk = false; result.Message = ex.Message; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } return(result); }