Beispiel #1
0
        public string Binding()
        {
            GridRequestParameters param = GridRequestParameters.Current;

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

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

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

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

            return(new JavaScriptSerializer().Serialize(new
            {
                total = total,
                data = ListModel.Select(i => new
                {
                    Id = i.Id,
                    IdCust = i.IdCust,
                    KodeCustomer = i.KodeCustomer,
                    KodeNama = i.KodeNama,
                    NamaCustomer = i.NamaCustomer,
                    AlamatCustomer = i.AlamatCustomer,
                    TelpCustomer = i.TelpCustomer,
                    FaxCustomer = i.FaxCustomer,
                    ContactCustomer = i.ContactCustomer,
                    HpCustomer = i.HpCustomer,
                    PeriodStart = i.PeriodStart,
                    PeriodEnd = i.PeriodEnd,
                    IdTypeKontrak = i.IdTypeKontrak,
                    listItem = i.listItem,
                    listAtt = i.listAtt,
                    listKondisi = i.listKondisi
                })
            }));
        }
        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));
        }