public ActionResult sync_driver() { foreach (Context.Driver dbitem in RepoDriver.FindAll()) { if (Repoptnr_mstr.FindByPK(dbitem.Id + 7000000) == null) { Repoptnr_mstr.saveDriver(dbitem); } } return(RedirectToAction("Index")); }
public ActionResult EditOncall(SalesOrderOncall model, string btnsave) { //validasi manual bool palid = true; int urutan = 1; if (btnsave != "draft" && model.Status != "draft") { if (!model.IdDataTruck.HasValue) { ModelState.AddModelError("IdDataTruck", "Truk harus diisi."); palid = false; } if (!model.Driver1Id.HasValue || model.Driver1Id.Value == 0) { ModelState.AddModelError("Driver1Id", "Driver harus diisi."); palid = false; } if (model.Driver1Id != null) { Context.Driver item = RepoDriver.FindAll().Where(d => d.Id == model.Driver1Id.Value).FirstOrDefault(); List <Context.SalesOrder> dbso = RepoSalesOrder.FindAll().ToList(); List <Context.SettlementBatal> dbsb = RepoSettlementBatal.FindAll().Where(s => s.IsProses == false).ToList(); Driver driver = new Driver(item, dbso, dbsb); Context.SalesOrder dbsoDriver = RepoSalesOrder.FindAll().Where(d => (d.Status == "save" || d.Status == "draft planning" || d.Status == "draft konfirmasi" || d.Status == "save konfirmasi" || d.Status == "dispatched") && ( (d.SalesOrderOncallId.HasValue && (d.SalesOrderOncall.Driver1Id == model.Driver1Id || d.SalesOrderOncall.Driver2Id == model.Driver1Id)) || (d.SalesOrderPickupId.HasValue && (d.SalesOrderPickup.Driver1Id == model.Driver1Id || d.SalesOrderPickup.Driver2Id == model.Driver1Id)) || (d.SalesOrderProsesKonsolidasiId.HasValue && (d.SalesOrderProsesKonsolidasi.Driver1Id == model.Driver1Id || d.SalesOrderProsesKonsolidasi.Driver2Id == model.Driver1Id)) ) ).FirstOrDefault(); if (driver.StatusSo != "Available" && dbsoDriver != null && RepoSalesOrder.FindArea(dbsoDriver.SalesOrderOncall.IdDaftarHargaItem.Value) != "YES") { List <Context.SalesOrder> dbsoDriverList = RepoSalesOrder.FindAll().Where(d => (d.Status == "save" || d.Status == "draft planning" || d.Status == "draft konfirmasi" || d.Status == "save konfirmasi" || d.Status == "dispatched") && ( (d.SalesOrderOncallId.HasValue && (d.SalesOrderOncall.Driver1Id == model.Driver1Id || d.SalesOrderOncall.Driver2Id == model.Driver1Id)) || (d.SalesOrderPickupId.HasValue && (d.SalesOrderPickup.Driver1Id == model.Driver1Id || d.SalesOrderPickup.Driver2Id == model.Driver1Id)) || (d.SalesOrderProsesKonsolidasiId.HasValue && (d.SalesOrderProsesKonsolidasi.Driver1Id == model.Driver1Id || d.SalesOrderProsesKonsolidasi.Driver2Id == model.Driver1Id)) ) ).ToList(); urutan = dbsoDriver.urutan + 1; //SO yg sdh jalan Context.Rute rute = RepoSalesOrder.FindRute(dbsoDriver.SalesOrderOncall.IdDaftarHargaItem.Value); int waktuKerja = int.Parse(rute.WaktuKerja.ToString()); //SO yg sedang diplanning Context.SalesOrder so = RepoSalesOrder.FindByOnCall(model.SalesOrderId.Value); Context.Rute rutePlanning = null; if (so != null && so.SalesOrderOncall != null && so.SalesOrderOncall.IdDaftarHargaItem != null) { rutePlanning = RepoSalesOrder.FindRute(so.SalesOrderOncall.IdDaftarHargaItem.Value); int waktuKerjaPlanning = int.Parse(rutePlanning.WaktuKerja.ToString()); bool used_at_that_date = dbsoDriverList.Any(d => DateTime.Parse(d.SalesOrderOncall.TanggalMuat.ToString()).AddDays(waktuKerja) >= model.TanggalMuat || DateTime.Parse(d.SalesOrderOncall.TanggalMuat.ToString()) <= DateTime.Parse(model.TanggalMuat.ToString()).AddDays(waktuKerja) ); if (used_at_that_date) { ModelState.AddModelError("Driver1Id", "Driver tidak tersedia, harap pilih driver lain."); palid = false; } else if (urutan > 2 && rutePlanning.IsAreaPulang != true) { ModelState.AddModelError("Driver1Id", "Driver tidak tersedia, harap pilih driver lain."); palid = false; } } } } } if (model.Status == "draft") { if (model.CommentUser == "" || model.CommentUser == null) { ModelState.AddModelError("CommentUser", "Comment harus diisi."); palid = false; } } if (palid) { Context.SalesOrder dbitem = RepoSalesOrder.FindByPK(model.SalesOrderId.Value); dbitem.isReturn = false; dbitem.UpdatedBy = UserPrincipal.id; dbitem.urutan = urutan; string act = ""; if (btnsave != null && btnsave != "") { act = "Draft"; dbitem.Status = btnsave; } else { if (model.Status.ToLower() == "save") { act = "Return"; dbitem.isReturn = true; } else { act = "Submit"; dbitem.isReturn = false; } dbitem.Status = model.Status; } model.setDbOperasional(dbitem.SalesOrderOncall, act, "Operational"); RepoSalesOrder.save(dbitem); RepoAuditrail.savePlanningHistory(dbitem); Context.so_mstr dbptnr = Reposo_mstr.FindByPK(dbitem.SalesOrderOncall.SONumber); Context.DataTruck truck = RepoDataTruck.FindByPK(model.IdDataTruck); try { dbptnr.so_vehicle = Repocode_mstr.FindByCodeName(truck.VehicleNo).id; Reposo_mstr.UpdateSoMstrVehicle(dbptnr); } catch (Exception) { } return(RedirectToAction("Index")); } else { ViewBag.kondisi = "planning"; ViewBag.name = model.SONumber; ViewBag.Title = "Planning Sales Order Oncall " + model.SONumber; ViewBag.PostData = "EditOncall"; return(View("SalesOrderOncall/FormReadOnly", model)); } }