Пример #1
0
        public string Binding()
        {
            GridRequestParameters param = GridRequestParameters.Current;

            List <Context.DaftarHargaOnCall> items = RepoDHO.FindAll(param.Skip, param.Take, (param.Sortings != null ? param.Sortings.ToList() : null), param.Filters);

            List <DaftarHargaOnCall> ListModel = new List <DaftarHargaOnCall>();

            foreach (Context.DaftarHargaOnCall item in items)
            {
                ListModel.Add(new DaftarHargaOnCall(item));
            }

            int total = RepoDHO.Count(param.Filters);

            return(new JavaScriptSerializer().Serialize(new { total = total, data = ListModel }));
        }
        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));
        }