Пример #1
0
        public ActionResult Edit(int id)
        {
            JenisTruck model = new JenisTruck(RepoJenisTruck.FindByPK(id));

            ViewBag.name = model.StrJenisTruck;
            return(View("Form", model));
        }
        public ActionResult Add(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        dbso   = new Context.SalesOrder();
                    Context.SalesOrderKontrak dbitem = new Context.SalesOrderKontrak();

                    model.setDb(dbitem);
                    dbitem.DocDate         = DateTime.Now;
                    dbitem.Urutan          = RepoSalesOrder.getUrutanKontrak() + 1;
                    dbitem.SONumber        = RepoSalesOrder.generateCodeKontrak(dbitem.Urutan);
                    dbitem.DN              = "DN" + dbitem.SONumber;
                    dbso.SalesOrderKontrak = dbitem;

                    if (btnsave == "save")
                    {
                        dbso.Status = "save";
                    }
                    else if (btnsave == "draft")
                    {
                        dbso.Status = "draft";
                    }
                    else
                    {
                        dbso.Status = model.Status;
                    }

                    RepoSalesOrder.save(dbso);

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

            return(View("Form", model));
        }
        public ActionResult Add(SalesOrderOncall model, string btnsave)
        {
            //validasi tambahan
            bool palid = true;

            if (ModelState.IsValid)
            {
                if (btnsave == null && model.Status == "save")
                {
                    List <Context.DaftarHargaOnCall> dummy = RepoDaftarHarga.FindAll().Where(d => d.IdCust == model.CustomerId && (model.TanggalMuat >= d.PeriodStart && model.TanggalMuat <= d.PeriodEnd)).ToList();

                    if (dummy.Where(d => d.DaftarHargaOnCallItem.Any(i => i.IdJenisTruck == model.JenisTruckId)).Count() < 1)
                    {
                        palid            = false;
                        ViewBag.errorMsg = "Tidak terdapat daftar harga untuk jenis truck " + RepoJnsTruck.FindByPK(model.JenisTruckId.Value).StrJenisTruck;
                    }
                }
            }

            SalesOrderLoadUnload[] resultLoad = JsonConvert.DeserializeObject <SalesOrderLoadUnload[]>(model.StrLoad);
            model.ListLoad = resultLoad.ToList();
            SalesOrderLoadUnload[] resultUnload = JsonConvert.DeserializeObject <SalesOrderLoadUnload[]>(model.StrUnload);
            model.ListUnload = resultUnload.ToList();

            if (palid)
            {
                if (ModelState.IsValid)
                {
                    Context.SalesOrder       dbso   = new Context.SalesOrder();
                    Context.SalesOrderOncall dbitem = new Context.SalesOrderOncall();
                    dbitem.Urutan   = RepoSalesOrder.getUrutanOnCAll(model.TanggalMuat.Value) + 1;
                    dbitem.SONumber = RepoSalesOrder.generateCodeOnCall(model.TanggalMuat.Value, dbitem.Urutan);
                    dbitem.DN       = "DN" + dbitem.SONumber;
                    if (btnsave == "save")
                    {
                        dbso.Status = "save";
                    }
                    else if (btnsave == "draft")
                    {
                        dbso.Status = "draft";
                    }
                    else
                    {
                        dbso.Status = model.Status;
                    }

                    if (model.Status == "save")
                    {
                        //{ Nama: "Sales Order", Id: "S" },
                        //{ Nama: "Planning Order", Id: "P" },
                        //{ Nama: "Konfirmasi Planning", Id: "KP" },
                        //{ Nama: "Admin Uang Jalan", Id: "A" },
                        //{ Nama: "Kasir", Id: "K" }
                        RepoListNotif.save("P",
                                           "PLANNING SO : " + model.SONumber + " " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " belum diproses.",
                                           "PLANNING SO : " + model.SONumber + " " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " belum diproses.");
                    }

                    model.setDb(dbitem, model.Status == "save" ? "Submit" : model.Status == "draft" ? "Draft" : "", "Marketing");
                    dbso.SalesOrderOncall = dbitem;
                    dbso.isReturn         = false;
                    dbso.CreatedBy        = UserPrincipal.id;
                    dbso.UpdatedBy        = UserPrincipal.id;
                    string sod_guid = Guid.NewGuid().ToString();
                    dbso.oidErp = sod_guid;
                    RepoSalesOrder.save(dbso);
                    Context.SalesOrder so = RepoSalesOrder.FindByOnCallCode(dbitem.SONumber);
                    RepoAuditrail.saveOrderHistory(so);
                    return(RedirectToAction("Index"));
                }
            }

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