public List <RecapPurchasingItemViewModel> RetrieveRecap(DateTime dateFrom, DateTime dateTo, int supplierId) { List <Purchasing> purchaseResult = _purchasingRepository.GetMany(i => DbFunctions.TruncateTime(i.CreateDate) >= DbFunctions.TruncateTime(dateFrom) && DbFunctions.TruncateTime(i.CreateDate) <= DbFunctions.TruncateTime(dateTo) && i.Status != (int)DbConstant.DefaultDataStatus.Deleted && i.PaymentStatus != (int)DbConstant.PaymentStatus.Settled && i.SupplierId == supplierId).ToList(); purchaseResult = purchaseResult.OrderBy(i => i.CreateDate).ToList(); List <PurchasingViewModel> mappedPurchaseResult = new List <PurchasingViewModel>(); Map(purchaseResult, mappedPurchaseResult); List <PurchaseReturn> purchaseReturnResult = _purchaseReturnRepository.GetMany(i => DbFunctions.TruncateTime(i.CreateDate) >= DbFunctions.TruncateTime(dateFrom) && DbFunctions.TruncateTime(i.CreateDate) <= DbFunctions.TruncateTime(dateTo) && i.Status != (int)DbConstant.DefaultDataStatus.Deleted && i.Purchasing.PaymentStatus != (int)DbConstant.PaymentStatus.Settled && i.Purchasing.SupplierId == supplierId).ToList(); purchaseReturnResult = purchaseReturnResult.OrderBy(i => i.CreateDate).ToList(); List <PurchaseReturnViewModel> mappedPurchaseReturnResult = new List <PurchaseReturnViewModel>(); Map(purchaseReturnResult, mappedPurchaseReturnResult); List <RecapPurchasingItemViewModel> mappedResult = new List <RecapPurchasingItemViewModel>(); foreach (var itemPurchase in mappedPurchaseResult) { mappedResult.Add(new RecapPurchasingItemViewModel { Code = itemPurchase.Code, Date = itemPurchase.Date, IsReturn = false, Supplier = itemPurchase.Supplier, TotalPrice = itemPurchase.TotalPrice }); } foreach (var itemPurchaseReturn in mappedPurchaseReturnResult) { mappedResult.Add(new RecapPurchasingItemViewModel { Code = itemPurchaseReturn.Code, Date = itemPurchaseReturn.Date, IsReturn = true, Supplier = itemPurchaseReturn.Purchasing.Supplier, TotalPrice = -1 * itemPurchaseReturn.TotalPriceReturn }); } return(mappedResult); }
public void InsertPurchasingMethod(PurchasingViewModel purchasing, List <PurchasingDetailViewModel> purchasingDetails, int userID) { DateTime serverTime = DateTime.Now; purchasing.CreateDate = serverTime; purchasing.CreateUserId = userID; purchasing.ModifyUserId = userID; purchasing.ModifyDate = serverTime; purchasing.Status = (int)DbConstant.PurchasingStatus.NotVerified; purchasing.PaymentMethodId = _referenceRepository.GetMany(c => c.Code == DbConstant.REF_PURCHASE_PAYMENTMETHOD_UTANG).FirstOrDefault().Id; purchasing.TotalHasPaid = 0; string code = "PRC" + "-" + serverTime.Month.ToString() + serverTime.Day.ToString() + "-"; //get total purchasing created today List <Purchasing> todayPCR = _purchasingRepository.GetMany(s => s.Code.ToString().Contains(code) && s.CreateDate.Year == serverTime.Year).ToList(); code = code + (todayPCR.Count + 1); purchasing.Code = code; Purchasing entity = new Purchasing(); Map(purchasing, entity); _purchasingRepository.AttachNavigation(entity.CreateUser); _purchasingRepository.AttachNavigation(entity.ModifyUser); _purchasingRepository.AttachNavigation(entity.PaymentMethod); _purchasingRepository.AttachNavigation(entity.Supplier); Purchasing purchasingInserted = _purchasingRepository.Add(entity); _unitOfWork.SaveChanges(); foreach (var itemPurchasingDetail in purchasingDetails) { PurchasingDetail newPurchasingDetail = new PurchasingDetail(); newPurchasingDetail.CreateDate = serverTime; newPurchasingDetail.CreateUserId = userID; newPurchasingDetail.ModifyUserId = userID; newPurchasingDetail.ModifyDate = serverTime; newPurchasingDetail.PurchasingId = purchasingInserted.Id; newPurchasingDetail.SparepartId = itemPurchasingDetail.SparepartId; newPurchasingDetail.Qty = itemPurchasingDetail.Qty; newPurchasingDetail.Price = itemPurchasingDetail.Price; newPurchasingDetail.SerialNumber = itemPurchasingDetail.SerialNumber; newPurchasingDetail.Status = (int)DbConstant.PurchasingStatus.NotVerified; _purchasingDetailRepository.AttachNavigation(newPurchasingDetail.CreateUser); _purchasingDetailRepository.AttachNavigation(newPurchasingDetail.ModifyUser); _purchasingDetailRepository.AttachNavigation(newPurchasingDetail.Purchasing); _purchasingDetailRepository.AttachNavigation(newPurchasingDetail.Sparepart); PurchasingDetail purchasingDetailInserted = _purchasingDetailRepository.Add(newPurchasingDetail); } _unitOfWork.SaveChanges(); Recalculate(purchasingInserted); }
public List <PurchasingViewModel> SearchPurchasing(DateTime?dateFrom, DateTime?dateTo, DbConstant.PurchasingStatus purchasingStatus) { List <Purchasing> result = null; if (dateFrom.HasValue && dateTo.HasValue) { dateFrom = dateFrom.Value.Date; dateTo = dateTo.Value.Date.AddDays(1).AddSeconds(-1); result = _purchasingRepository.GetMany(c => c.Date >= dateFrom && c.Date <= dateTo && c.Status != (int)DbConstant.PurchasingStatus.Deleted).OrderBy(c => c.Date).ToList(); } else { result = _purchasingRepository.GetMany(c => c.Status != (int)DbConstant.PurchasingStatus.Deleted).OrderBy(c => c.Date).ToList(); } if ((int)purchasingStatus != 9) { result = result.Where(p => p.Status == (int)purchasingStatus).ToList(); } List <PurchasingViewModel> mappedResult = new List <PurchasingViewModel>(); return(Map(result, mappedResult)); }
public List <PurchasingViewModel> SearchTransaction(DateTime?dateFrom, DateTime?dateTo, int paymentStatus) { List <Purchasing> result = null; if (dateFrom.HasValue && dateTo.HasValue) { dateFrom = dateFrom.Value.Date; dateTo = dateTo.Value.Date.AddDays(1).AddSeconds(-1); result = _purchasingRepository.GetMany(c => c.Date >= dateFrom && c.Date <= dateTo && c.Status == (int)DbConstant.PurchasingStatus.Active || c.Status == (int)DbConstant.PurchasingStatus.HasReturn).OrderBy(c => c.Date).ToList(); } else { result = _purchasingRepository.GetMany(c => c.Status == (int)DbConstant.PurchasingStatus.Active || c.Status == (int)DbConstant.PurchasingStatus.HasReturn).OrderBy(c => c.Date).ToList(); } if (paymentStatus > -1) { result = result.Where(p => p.PaymentStatus == paymentStatus).ToList(); } List <PurchasingViewModel> mappedResult = new List <PurchasingViewModel>(); return(Map(result, mappedResult)); }