public ActionResult EditBatalTruk(SalesOrderKontrak model, int DataTruckId, int IdDriver1, int IdDriver2, string btnsave)
        {
            Context.SalesOrderKontrakListSo dblist = RepoSalesOrderKontrakListSo.FindByNoSo(model.SONumber);
            dblist.IdDataTruck = DataTruckId;
            dblist.Driver1Id   = IdDriver1;
            if (IdDriver2 > 0)
            {
                dblist.Driver2Id = IdDriver2;
            }
            if (IdDriver2 > 0)
            {
                dblist.Driver2Id = IdDriver2;
            }
            if (btnsave != null && btnsave != "")
            {
                dblist.Status = "draft konfirmasi";
            }
            else
            {
                dblist.Status = "save planning";
            }
            dblist.Status = btnsave;
            model.Status  = "draft konfirmasi";
            //RepoSalesOrder.save(model);
            RepoSalesOrderKontrakListSo.OnlyUpdate(dblist);

            return(RedirectToAction("Index"));
        }
        public ActionResult View(int id)
        {
            Context.SalesOrder dbitem = RepoSalesOrder.FindByPK(id);

            if (dbitem.SalesOrderOncallId != null)
            {
                SalesOrderOncall model = new SalesOrderOncall(dbitem);
                ViewBag.name = model.SONumber;
                return(View("SalesOrderOncall/FormReadOnly", model));
            }
            else if (dbitem.SalesOrderPickupId != null)
            {
                SalesOrderPickup model = new SalesOrderPickup(dbitem);
                ViewBag.name = model.SONumber;
                return(View("SalesOrderPickup/FormReadOnly", model));
            }
            else if (dbitem.SalesOrderProsesKonsolidasiId != null)
            {
                SalesOrderProsesKonsolidasi model = new SalesOrderProsesKonsolidasi(dbitem);
                ViewBag.name = model.SONumber;
                return(View("SalesOrderProsesKonsolidasi/FormReadOnly", model));
            }
            else if (dbitem.SalesOrderKontrakId != null)
            {
                SalesOrderKontrak model = new SalesOrderKontrak(dbitem);
                ViewBag.name = model.SONumber;
                return(View("SalesOrderKontrak/FormReadOnly", model));
            }
            return(RedirectToAction("", ""));
        }
        public ActionResult Edit(int id)
        {
            Context.SalesOrder dbitem = RepoSalesOrder.FindByPK(id);
            SalesOrderKontrak  model  = new SalesOrderKontrak(dbitem);

            ViewBag.name = model.SONumber;
            return(View("Form", model));
        }
        public ActionResult Edit(int id)
        {
            Context.SalesOrder dbitem = RepoSalesOrder.FindByPK(id);
            SalesOrderKontrak  model  = new SalesOrderKontrak(dbitem);

            ViewBag.kondisi  = "planning";
            ViewBag.name     = model.SONumber;
            ViewBag.Title    = "Planning Sales Order Kontrak " + model.SONumber;
            ViewBag.PostData = "Edit";

            return(View("SalesOrderKontrak/FormReadOnly", model));
        }
        public ActionResult EditBatalTruk(string id)
        {
            Context.SalesOrderKontrakListSo detailsoitem = RepoSalesOrderKontrakListSo.FindByNoSo(id);
            Context.SalesOrder kontrakitem = RepoSalesOrder.FindByKontrak(detailsoitem.SalesKontrakId.Value);
            SalesOrderKontrak  model       = new SalesOrderKontrak(kontrakitem, detailsoitem);

            ViewBag.kondisi   = "planning";
            ViewBag.name      = model.SONumber;
            ViewBag.so_detail = detailsoitem;
            ViewBag.Title     = "Planning Sales Order Kontrak " + model.SONumber;
            ViewBag.PostData  = "EditBatalTruk";

            return(View("PlanningAfterBatalTruk", model));
        }
        public ActionResult Edit(SalesOrderKontrak model, string btnsave)
        {
            Context.SalesOrder dbitem = RepoSalesOrder.FindByPK(model.SalesOrderId.Value);
            if (btnsave != null && btnsave != "")
            {
                dbitem.Status = btnsave;
            }
            else
            {
                dbitem.Status = model.Status;
            }

            model.setDbOpertional(dbitem.SalesOrderKontrak);

            #region list kontrak SO
            dbitem.SalesOrderKontrak.SalesOrderKontrakListSo.Clear();

            int idx = 1;
            for (int j = 1; j <= (dbitem.SalesOrderKontrak.Rit); j++)
            {
                foreach (var dateItem in dbitem.SalesOrderKontrak.SalesOrderKontrakDetail)
                {
                    int trukIdx = 1;
                    foreach (var trukItem in dbitem.SalesOrderKontrak.SalesOrderKontrakTruck)
                    {
                        Context.SalesOrderKontrakListSo dblist = new Context.SalesOrderKontrakListSo();
                        dblist.SalesKontrakId = dbitem.SalesOrderKontrakId;
                        dblist.NoSo           = RepoSalesOrderKontrakListSo.generateCodeListSo(dbitem.SalesOrderKontrak.SONumber, dateItem.MuatDate, j, trukIdx, dbitem.SalesOrderKontrak.Urutan);
                        dblist.MuatDate       = dateItem.MuatDate;
                        dblist.IdDataTruck    = trukItem.DataTruckId;
                        dblist.Driver1Id      = trukItem.IdDriver1;
                        dblist.Driver2Id      = trukItem.IdDriver2;
                        RepoSalesOrderKontrakListSo.OnlyAdd(dblist);
                        idx++;
                        trukIdx++;
                    }
                }
            }
            #endregion list kontrak SO

            RepoSalesOrder.save(dbitem);
            return(RedirectToAction("Index"));
        }
        public ActionResult InputDp(int id, string status)
        {
            Context.SalesOrder dbitem = RepoSalesOrder.FindByPK(id);
            SalesOrderKontrak  model  = new SalesOrderKontrak(dbitem);

            ViewBag.name    = model.SONumber;
            ViewBag.kondisi = "inputdp";

            //if (status != "settlement" && status != "dispatched")
            //{
            //    TempData["errorMsgListOrder"] = "Maaf, Status SO belum Settlement ataupun Dispatched";
            //    return RedirectToAction("Index", "ListOrder");
            //}
            //else
            //{
            //    TempData.Remove("errorMsgListOrder");
            //    return View("SalesOrderKontrak/FormReadOnly", model);
            //}
            TempData.Remove("errorMsgListOrder");
            return(View("SalesOrderKontrak/FormReadOnly", model));
        }
        public ActionResult Edit(SalesOrderKontrak model, string btnsave)
        {
            //validasi tambahan
            bool palid = true;

            if (btnsave == null && model.Status == "save")
            {
                List <Context.DaftarHargaKontrak> dummy = RepoDaftarHarga.FindAll().Where(d =>
                                                                                          d.IdCust == model.CustomerId &&
                                                                                          d.DaftarHargaKontrakItem.Any(i => i.IdJenisTruck == model.JenisTruckId)).ToList();

                if (dummy.Count() < 1)
                {
                    palid            = false;
                    ViewBag.errorMsg = "Tidak terdapat daftar harga untuk jenis truck " + RepoJenisTruck.FindByPK(model.JenisTruckId.Value).StrJenisTruck;
                }
                else
                {
                    if (model.JsonDateMuat != null && model.JsonDateMuat != "")
                    {
                        List <string> wadah = new List <string>();
                        foreach (string item in model.JsonDateMuat.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            DateTime valDate = DateTime.Parse(item);

                            if (!dummy.Any(d => valDate >= d.PeriodStart && valDate <= d.PeriodEnd))
                            {
                                wadah.Add(item);
                            }
                        }
                        if (wadah.Count() > 0)
                        {
                            palid            = false;
                            ViewBag.errorMsg = "Tidak terdapat daftar harga untuk jenis truck " + RepoJenisTruck.FindByPK(model.JenisTruckId.Value).StrJenisTruck +
                                               " pada tanggal " + string.Join(", ", wadah);
                        }
                    }
                    else
                    {
                        palid            = false;
                        ViewBag.errorMsg = "Harap pilih tanggal muat.";
                    }
                }
            }
            else
            {
                if (model.JsonDateMuat == null || model.JsonDateMuat == "")
                {
                    palid            = false;
                    ViewBag.errorMsg = "Harap pilih tanggal muat.";
                }
            }

            if (palid)
            {
                if (ModelState.IsValid)
                {
                    if (model.existingMuatDate != "" && model.existingMuatDate != null)
                    {
                        model.existingMuatDate = RepoSalesOrder.IsMuatDateExist(model.JsonDateMuat.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries).ToList(), model.CustomerId.Value);
                        if (model.existingMuatDate != "")
                        {
                            return(View("Form", model));
                        }
                    }

                    Context.SalesOrder dbitem = RepoSalesOrder.FindByPK(model.SalesOrderId.Value);

                    model.setDb(dbitem.SalesOrderKontrak);

                    if (btnsave == "save")
                    {
                        dbitem.Status = "save";
                    }
                    else if (btnsave == "draft")
                    {
                        dbitem.Status = "draft";
                    }
                    else
                    {
                        dbitem.Status = model.Status;
                    }
                    dbitem.isReturn = false;
                    RepoSalesOrder.save(dbitem);

                    return(RedirectToAction("Index"));
                }
            }

            return(View("Form", model));
        }
        public ActionResult Add()
        {
            SalesOrderKontrak model = new SalesOrderKontrak();

            return(View("Form", model));
        }