Exemplo n.º 1
0
        public void setDb(Context.SalesOrderKontrak dbitem)
        {
            dbitem.SalesOrderKontrakId = SalesOrderKontrakId;

            dbitem.CustomerId      = CustomerId;
            dbitem.JenisTruckId    = JenisTruckId;
            dbitem.ProductId       = ProductId;
            dbitem.PeriodStr       = PeriodStr.Value;
            dbitem.PeriodEnd       = PeriodEnd.Value;
            dbitem.JamMuat         = JamMuat.Value;
            dbitem.JumlahTruck     = JumlahTruck.Value;
            dbitem.Rit             = Rit.Value;
            dbitem.Keterangan      = Keterangan;
            dbitem.JumlahHari      = JumHari;
            dbitem.JumlahHariKerja = Kerja;
            dbitem.JumlahHariLibur = libur;

            dbitem.SalesOrderKontrakDetail.Clear();
            if (JsonDateMuat != null && JsonDateMuat != "")
            {
                foreach (string item in JsonDateMuat.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    dbitem.SalesOrderKontrakDetail.Add(new Context.SalesOrderKontrakDetail()
                    {
                        MuatDate = DateTime.Parse(item)
                    });
                }
            }
        }
        public void deleteAdd(int?id)
        {
            Context.SalesOrderKontrak dbitem = context.SalesOrderKontrak.Where(d => d.SalesOrderKontrakId == id).FirstOrDefault();

            if (dbitem.SalesOrderKontrakListSo != null)
            {
                context.SalesOrderKontrakListSo.RemoveRange(dbitem.SalesOrderKontrakListSo);
            }
            context.SaveChanges();
        }
Exemplo n.º 3
0
 public void setDbOpertional(Context.SalesOrderKontrak dbitem)
 {
     SalesOrderKontrakItemTruck[] resultLoad = JsonConvert.DeserializeObject <SalesOrderKontrakItemTruck[]>(strListTruck);
     dbitem.SalesOrderKontrakTruck.Clear();
     foreach (SalesOrderKontrakItemTruck item in resultLoad)
     {
         dbitem.SalesOrderKontrakTruck.Add(new SalesOrderKontrakTruck()
         {
             DataTruckId = item.IdTruk,
             IdDriver1   = item.IdDriver1,
             IdDriver2   = item.IdDriver2 == 0 ? null : item.IdDriver2,
             StatusTruk  = item.Status,
         });
     }
 }
        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));
        }