/// <summary> /// Close warehouse vehicle inventory at specified month. /// </summary> /// <param name="code"></param> /// <param name="dealerCode"></param> /// <param name="month"></param> /// <param name="year"></param> /// <param name="dc"></param> public static void DoCloseW(string code, string dealerCode, int month, int year, VehicleDataContext dc) { if ((year > DateTime.Now.Year) //|| (year < 2000) || ((year == DateTime.Now.Year) && (month > DateTime.Now.Month)) || (month > 12) || (month < 1) ) { throw new Exception("Invalid closing month!"); } // check for valid warehouse var wh = VDMS.II.BasicData.WarehouseDAO.GetWarehouse(code, dealerCode, VDMS.II.Entity.WarehouseType.Vehicle); if (wh == null) throw new Exception("Invalid closing warehouse!"); // get lock record for current closed month var ilck = dc.SaleInventoryLocks.SingleOrDefault(i => i.DealerCode == GetWLockCode(dealerCode, code) && i.IsLocked == 1); if (ilck == null)// never closed before { if (year < 2007) throw new Exception("Invalid closing month at first time!"); // lock month valid to first inventory action? SaleInventory frstIv = dc.SaleInventories.Where(i => i.BranchCode == code && i.DealerCode == dealerCode).OrderBy(i => i.Year).OrderBy(i => i.Month).FirstOrDefault(); if (frstIv != null) { DateTime fDt = new DateTime(frstIv.Year, frstIv.Month, 1); DateTime cDt = new DateTime(year, month, 1); if (fDt.AddMonths(1) < cDt) throw new Exception("At first time, closing month cannot be greater than the first month that changing inventory action happen!"); } ilck = new SaleInventoryLock { DealerCode = GetWLockCode(wh.DealerCode, wh.Code), Month = month, Year = year, IsLocked = 1 }; dc.SaleInventoryLocks.InsertOnSubmit(ilck); } else { // change locked month to new Closed month if (ilck.Month == 12) { ilck.Month = 1; ilck.Year++; } else ilck.Month++; if ((ilck.Year > DateTime.Now.Year) || ((ilck.Year == DateTime.Now.Year) && (ilck.Month > DateTime.Now.Month))) throw new Exception("Invalid closing month!"); } dc.SubmitChanges(); // summarization InventoryHelper.DoInventory2(code, dealerCode, (int)ilck.Month, (int)ilck.Year, dc); // gen excel file //new VDMS.II.Report.PartMonthlyReport(wId.ToString(), wh.DealerCode, ilck.Month, ilck.Year).DoReport(); }
/// <summary> /// Close dealer vehicle inventory at specified month. /// </summary> /// <param name="dealerCode"></param> /// <param name="month"></param> /// <param name="year"></param> /// <param name="dc"></param> public static void DoCloseD(string dealerCode, int month, int year, VehicleDataContext dc) { if ((year > DateTime.Now.Year) //|| (year < 2000) || ((year == DateTime.Now.Year) && (month > DateTime.Now.Month)) || (month > 12) || (month < 1) ) { throw new Exception("Invalid closing month!"); } // check Dealer exist var d = DealerDAO.GetDealerByCode(dealerCode); if (d == null) throw new Exception("Invalid closing dealer!"); // check all warehouse and sub dealer are closed if (!InventoryHelper.CanCloseDealer(dealerCode, year, month, dc)) throw new Exception(string.Format("Cannot close {0}! All sub components must be closed before.", dealerCode)); // get lock record for current closed month var ilck = dc.SaleInventoryLocks.SingleOrDefault(i => i.DealerCode == dealerCode && i.IsLocked == 0); if (ilck == null) // never closed before { if (year < 2007) throw new Exception("Invalid closing month at first time!"); // create new lock record ilck = new SaleInventoryLock { IsLocked = 0, DealerCode = d.DealerCode, Month = month, Year = year }; dc.SaleInventoryLocks.InsertOnSubmit(ilck); } else // update locked record to new closing month { if (ilck.Month == 12) { ilck.Month = 1; ilck.Year++; } else ilck.Month++; if ((ilck.Year > DateTime.Now.Year) || ((ilck.Year == DateTime.Now.Year) && (ilck.Month > DateTime.Now.Month))) throw new Exception("Invalid closing month!"); } dc.SubmitChanges(); }