public List <SimpleOutstandingPallets> ListOutstandingPalletsPerClient(string email, string apikey) { CustomSearchModel csm = new CustomSearchModel() { BalanceStatus = BalanceStatus.NotBalanced }; List <SimpleOutstandingPallets> response = new List <SimpleOutstandingPallets>(); using (ClientLoadService clservice = new ClientLoadService()) { clservice.CurrentUser = clservice.GetUser(email); response = clservice.ListOutstandingPalletsPerClient(csm); if (!response.NullableAny()) { return(response); } csm.ToDate = new DateTime(DateTime.Now.AddMonths(-3).Year, DateTime.Now.AddMonths(-3).Month, 1); //csm.ToDate = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth( DateTime.Now.Year, DateTime.Now.Month ) ); List <SimpleOutstandingPallets> response30 = clservice.ListOutstandingPalletsPerClient(csm); foreach (SimpleOutstandingPallets s in response) { s.Past30 = response30?.FirstOrDefault(r => r.ClientId == s.ClientId)?.Total ?? 0; } } return(response); }
// // POST || GET: /DashBoard/LoadsPerMonth public ActionResult LoadsPerMonth(CustomSearchModel csm, bool givedata = false) { using (ClientLoadService service = new ClientLoadService()) { DateTime fromDate = csm.FromDate ?? new DateTime(DateTime.Now.AddMonths(-2).Year, DateTime.Now.AddMonths(-2).Month, 1); DateTime toDate = csm.ToDate ?? new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); if (givedata) { csm.ToDate = toDate; csm.FromDate = fromDate; List <ClientLoadCustomModel> loadsPerMonth = service.List1(new PagingModel() { Take = int.MaxValue }, csm); return(PartialView("_LoadsPerMonthData", loadsPerMonth)); } List <LoadsPerMonth> loads = new List <LoadsPerMonth>(); int months = ((toDate.Year - fromDate.Year) * 12) + toDate.Month - fromDate.Month; months = months <= 0 ? 1 : months + 1; LoadsPerMonth load; for (int i = 0; i < months; i++) { csm.FromDate = new DateTime(DateTime.Now.AddMonths(-i).Year, DateTime.Now.AddMonths(-i).Month, 1); csm.ToDate = new DateTime(csm.FromDate.Value.Year, csm.FromDate.Value.Month, DateTime.DaysInMonth(csm.FromDate.Value.Year, csm.FromDate.Value.Month)); load = service.LoadsPerMonth(csm); load.MonthYear = csm.FromDate.Value.Year; load.MonthNumber = csm.FromDate.Value.Month; load.MonthName = $"{csm.FromDate.Value:MMMM} {csm.FromDate.Value:yyyy}"; loads.Add(load); } //Yearly cumulative csm.FromDate = new DateTime(DateTime.Now.Year, 1, 1); csm.ToDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); load = service.LoadsPerMonth(csm); load.MonthNumber = int.MaxValue; load.MonthYear = int.MaxValue; load.MonthName = csm.FromDate.Value.ToString("yyyy"); loads.Add(load); loads = loads.OrderBy(o => o.MonthYear).ThenBy(o => o.MonthNumber).ToList(); return(PartialView("_LoadsPerMonth", loads)); } }
public HttpResponseMessage UpdateShipment(ClientLoadCustomModel model) { using (ClientLoadService clservice = new ClientLoadService()) { clservice.CurrentUser = clservice.GetUser(model.Email); ClientLoad load = clservice.GetById(model.Id); if (load == null) { return(Request.CreateResponse(HttpStatusCode.OK, new ResponseModel() { Code = -1, Description = "Shipment could not be found" })); } //load.OutstandingReasonId = null; load.PCNNumber = model.PCNNumber; load.PODNumber = model.PODNumber; load.PRNNumber = model.PRNNumber; load.PCNCommentDate = DateTime.Now; load.PODCommentDate = DateTime.Now; load.PRNCommentDate = DateTime.Now; load.PCNComments = model.PCNComments; load.PODComments = model.PODComments; load.PRNComments = model.PRNComments; load.PODStatus = ( int )Status.Active; load.PODCommentById = clservice.CurrentUser.Id; load.PCNCommentById = clservice.CurrentUser.Id; load.PRNCommentById = clservice.CurrentUser.Id; clservice.Update(load); CustomSearchModel csm = new CustomSearchModel(); PagingModel pm = new PagingModel() { SortBy = "cl.PCNNumber, cl.PRNNumber, cl.PODNumber" }; List <ClientLoadCustomModel> loads = clservice.ListOutstandingShipments(pm, csm); return(Request.CreateResponse(HttpStatusCode.OK, new { OutstandingShipments = loads, Code = 1, Description = "Shipment updated" })); } }
public HttpResponseMessage OutstandingShipments(string email, string apikey) { using (ClientLoadService service = new ClientLoadService()) { service.CurrentUser = service.GetUser(email); CustomSearchModel csm = new CustomSearchModel(); PagingModel pm = new PagingModel() { SortBy = "cl.PCNNumber, cl.PRNNumber, cl.PODNumber", Skip = 0, Take = int.MaxValue }; List <ClientLoadCustomModel> model = service.ListOutstandingShipments(pm, csm); return(Request.CreateResponse(HttpStatusCode.OK, model)); } }
// // GET: /Transporter/PODManagement public ActionResult PODManagement(PagingModel pm, CustomSearchModel csm, bool givecsm = false) { if (givecsm) { ViewBag.ViewName = "PODManagement"; return(PartialView("_PODManagementCustomSearch", new CustomSearchModel("PODManagement"))); } using (ClientLoadService service = new ClientLoadService()) { List <ClientLoadCustomModel> model = service.ListOutstandingShipments(pm, csm); int total = (model.Count < pm.Take && pm.Skip == 0) ? model.Count : service.Total1(pm, csm); PagingExtension paging = PagingExtension.Create(model, total, pm.Skip, pm.Take, pm.Page); return(PartialView("_PODManagement", paging)); } }
public ActionResult EditClientLoad(ClientLoadViewModel model, PagingModel pm, CustomSearchModel csm) { using (ImageService iservice = new ImageService()) using (ClientLoadService clservice = new ClientLoadService()) { ClientLoad load = clservice.GetById(model.Id); if (load == null) { Notify("Sorry, the requested resource could not be found. Please try again", NotificationType.Error); return(PartialView("_AccessDenied")); } #region Update Client Load load.PODNumber = model.PODNumber; load.PCNNumber = model.PCNNumber; load.PRNNumber = model.PRNNumber; load.PODCommentDate = DateTime.Now; load.PCNCommentDate = DateTime.Now; load.PRNCommentDate = DateTime.Now; load.PODCommentId = model.PODCommentId; load.PCNComments = model.PCNComments; load.PRNComments = model.PRNComments; load.PODCommentById = CurrentUser.Id; load.PCNCommentById = CurrentUser.Id; load.PRNCommentById = CurrentUser.Id; clservice.Update(load); #endregion #region Any Uploads? if (model.Files.NullableAny(f => f.File != null)) { // Create folder string path = Server.MapPath($"~/{VariableExtension.SystemRules.ImagesLocation}/ClientLoad/{load.LoadNumber?.Trim()}/"); string now = DateTime.Now.ToString("yyyyMMddHHmmss"); foreach (FileViewModel f in model.Files.Where(f => f.File != null)) { string ext = Path.GetExtension(f.File.FileName), name = f.File.FileName.Replace(ext, ""); // Check if a logo already exists? Image img = iservice.Get(load.Id, f.Name, true); if (img != null) { DeleteImage(img.Id); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } Image image = new Image() { Name = name, IsMain = true, Extension = ext, ObjectId = load.Id, ObjectType = f.Name, Size = f.File.ContentLength, Location = $"ClientLoad/{load.LoadNumber?.Trim()}/{now}-{f.File.FileName}" }; iservice.Create(image); string fullpath = Path.Combine(path, $"{now}-{f.File.FileName}"); f.File.SaveAs(fullpath); } } #endregion } Notify("The selected Client Load details were successfully updated.", NotificationType.Success); return(PODManagement(pm, csm)); }
public ActionResult EditClientLoad(int id) { using (ImageService iservice = new ImageService()) using (ClientLoadService clservice = new ClientLoadService()) { ClientLoad load = clservice.GetById(id); if (load == null) { Notify("Sorry, the requested resource could not be found. Please try again", NotificationType.Error); return(PartialView("_AccessDenied")); } ClientLoadViewModel model = new ClientLoadViewModel() { Id = load.Id, EditMode = true, PODNumber = load.PODNumber, PCNNumber = load.PCNNumber, PRNNumber = load.PRNNumber, PODCommentId = load.PODCommentId, PCNComments = load.PCNComments, PRNComments = load.PRNComments, Files = new List <FileViewModel>() }; Image podImg = iservice.Get(model.Id, "PODNumber", true); Image pcnImg = iservice.Get(model.Id, "PCNNumber", true); Image prnImg = iservice.Get(model.Id, "PRNNumber", true); if (podImg != null) { model.Files.Add(new FileViewModel() { Id = podImg.Id, Name = "PODNumber", Extension = podImg.Extension }); } if (pcnImg != null) { model.Files.Add(new FileViewModel() { Id = pcnImg.Id, Name = "PCNNumber", Extension = pcnImg.Extension }); } if (prnImg != null) { model.Files.Add(new FileViewModel() { Id = prnImg.Id, Name = "PRNNumber", Extension = prnImg.Extension }); } return(View(model)); } }
public List <SimpleOutstandingPallets> ListOutstandingPalletsPerSite(string email, string apikey) { List <SimpleOutstandingPallets> response = new List <SimpleOutstandingPallets>(); CustomSearchModel csm = new CustomSearchModel() { BalanceStatus = BalanceStatus.NotBalanced }; using (ClientLoadService clservice = new ClientLoadService()) { clservice.CurrentUser = clservice.GetUser(email); response = clservice.ListOutstandingPalletsPerSite(csm); if (!response.NullableAny()) { return(response); } // 0-3 Months csm.FromDate = new DateTime(DateTime.Now.AddMonths(-3).Year, DateTime.Now.AddMonths(-3).Month, 1); csm.ToDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); List <SimpleOutstandingPallets> rep = clservice.ListOutstandingPalletsPerSite(csm); foreach (SimpleOutstandingPallets s in response) { s.Month1 = rep?.FirstOrDefault(r => r.SiteId == s.SiteId)?.Total ?? 0; } // 4-6 Months csm.FromDate = new DateTime(DateTime.Now.AddMonths(-6).Year, DateTime.Now.AddMonths(-6).Month, 1); csm.ToDate = new DateTime(DateTime.Now.AddMonths(-3).Year, DateTime.Now.AddMonths(-3).Month, DateTime.DaysInMonth(DateTime.Now.AddMonths(-3).Year, DateTime.Now.AddMonths(-3).Month)); rep = clservice.ListOutstandingPalletsPerSite(csm); foreach (SimpleOutstandingPallets s in response) { s.Month2 = rep?.FirstOrDefault(r => r.SiteId == s.SiteId)?.Total ?? 0; } // 7-12 Months csm.FromDate = new DateTime(DateTime.Now.AddMonths(-12).Year, DateTime.Now.AddMonths(-12).Month, 1); csm.ToDate = new DateTime(DateTime.Now.AddMonths(-6).Year, DateTime.Now.AddMonths(-6).Month, DateTime.DaysInMonth(DateTime.Now.AddMonths(-6).Year, DateTime.Now.AddMonths(-6).Month)); rep = clservice.ListOutstandingPalletsPerSite(csm); foreach (SimpleOutstandingPallets s in response) { s.Month3 = rep?.FirstOrDefault(r => r.SiteId == s.SiteId)?.Total ?? 0; } // +12 Months csm.FromDate = null; csm.ToDate = new DateTime(DateTime.Now.AddMonths(-12).Year, DateTime.Now.AddMonths(-12).Month, DateTime.DaysInMonth(DateTime.Now.AddMonths(-12).Year, DateTime.Now.AddMonths(-12).Month)); rep = clservice.ListOutstandingPalletsPerSite(csm); foreach (SimpleOutstandingPallets s in response) { s.Month4 = rep?.FirstOrDefault(r => r.SiteId == s.SiteId)?.Total ?? 0; } } return(response); }
public HttpResponseMessage UploadShipment(int id, string apikey, string objecttype, string comment, string email) { try { using (ImageService iservice = new ImageService()) using (ClientLoadService saservice = new ClientLoadService()) { saservice.CurrentUser = saservice.GetUser(email); ClientLoad load = saservice.GetById(id); if (load == null) { return(Request.CreateResponse(HttpStatusCode.OK, new ResponseModel() { Code = -1, Description = "Shipment could not be found" })); } HttpPostedFile file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null; if (file == null) { return(Request.CreateResponse(HttpStatusCode.OK, new ResponseModel() { Code = -1, Description = "No file uploaded!" })); } // Create folder string path = HostingEnvironment.MapPath($"~/{VariableExtension.SystemRules.ImagesLocation}/ClientLoad/{load.LoadNumber?.Trim()}/"); string now = DateTime.Now.ToString("yyyyMMddHHmmss"); string ext = Path.GetExtension(file.FileName), name = file.FileName.Replace(ext, ""); // Check if a logo already exists? Image img = iservice.Get(load.Id, objecttype, true); if (img != null) { baseC.DeleteImage(img.Id); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } Image image = new Image() { Name = name, ObjectId = load.Id, ObjectType = objecttype, Size = file.ContentLength, Description = comment, IsMain = true, Extension = ext, Location = $"ClientLoad/{load.LoadNumber?.Trim()}/{now}-{file.FileName}" }; iservice.Create(image); string fullpath = Path.Combine(path, $"{now}-{file.FileName}"); file.SaveAs(fullpath); return(Request.CreateResponse(HttpStatusCode.OK, saservice.OldObject)); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.OK, ex.Message.ToString())); } }
// // POST || GET: /DashBoard/AuthorisationCodes public ActionResult AuthorisationCodes(CustomSearchModel csm, bool givedata = false) { using (ClientLoadService clservice = new ClientLoadService()) using (ClientAuthorisationService aservice = new ClientAuthorisationService()) { DateTime fromDate = csm.FromDate ?? new DateTime(DateTime.Now.AddMonths(-2).Year, DateTime.Now.AddMonths(-2).Month, 1); DateTime toDate = csm.ToDate ?? new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); if (givedata) { csm.ToDate = toDate; csm.FromDate = fromDate; csm.HasAuthorisationCode = true; List <ClientAuthorisationCustomModel> authCodes = aservice.List1(new PagingModel() { Take = int.MaxValue }, csm); return(PartialView("_AuthorisationCodesData", authCodes)); } List <AuthorisationCodes> auths = new List <AuthorisationCodes>(); int months = ((toDate.Year - fromDate.Year) * 12) + toDate.Month - fromDate.Month; months = months <= 0 ? 1 : months + 1; AuthorisationCodes auth; for (int i = 0; i < months; i++) { csm.FromDate = new DateTime(DateTime.Now.AddMonths(-i).Year, DateTime.Now.AddMonths(-i).Month, 1); csm.ToDate = new DateTime(csm.FromDate.Value.Year, csm.FromDate.Value.Month, DateTime.DaysInMonth(csm.FromDate.Value.Year, csm.FromDate.Value.Month)); auth = clservice.AuthorisationCodesPerMonth(csm); auth.MonthYear = csm.FromDate.Value.Year; auth.MonthNumber = csm.FromDate.Value.Month; auth.MonthName = $"{csm.FromDate.Value:MMMM} {csm.FromDate.Value:yyyy}"; auths.Add(auth); } //Yearly cumulative csm.FromDate = new DateTime(DateTime.Now.Year, 1, 1); csm.ToDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); auth = clservice.AuthorisationCodesPerMonth(csm); auth.MonthYear = int.MaxValue; auth.MonthNumber = int.MaxValue; auth.MonthName = csm.FromDate.Value.ToString("yyyy"); auths.Add(auth); auths = auths.OrderBy(o => o.MonthYear).ThenBy(o => o.MonthNumber).ToList(); return(PartialView("_AuthorisationCodes", auths)); } }