Beispiel #1
0
        public PenetapanDriver(Context.PenetapanDriver dbitem)
        {
            Id          = dbitem.Id;
            IdDataTruck = dbitem.IdDataTruck;
            VehicleNo   = dbitem.DataTruck.VehicleNo;
            JenisTruck  = dbitem.DataTruck.IdJenisTruck.HasValue ? dbitem.DataTruck.JenisTrucks.StrJenisTruck : "";

            IdDriver1         = dbitem.IdDriver1;
            Kode1             = dbitem.Driver1.KodeDriver;
            Nama1             = dbitem.Driver1.NamaDriver;
            Panggilan1        = dbitem.Driver1.NamaPangilan;
            NoHp1Driver1      = dbitem.NoHp1Driver1;
            NoHp2Driver1      = dbitem.NoHp2Driver1;
            Sim1              = dbitem.Driver1.LookupCodeJenisSim.Nama;
            BerlakuSim1       = dbitem.Driver1.TglBerlakuSim.Value.Date;
            IdDitetapkanOleh1 = dbitem.DitetapkanOleh1;

            if (dbitem.IdDriver2.HasValue)
            {
                IdDriver2         = dbitem.IdDriver2;
                Kode2             = dbitem.Driver2.KodeDriver;
                Nama2             = dbitem.Driver2.NamaDriver;
                Panggilan2        = dbitem.Driver2.NamaPangilan;
                NoHp1Driver2      = dbitem.NoHp1Driver2;
                NoHp2Driver2      = dbitem.NoHp2Driver2;
                Sim2              = dbitem.Driver2.LookupCodeJenisSim.Nama;
                BerlakuSim2       = dbitem.Driver2.TglBerlakuSim.Value.Date;
                IdDitetapkanOleh2 = dbitem.DitetapkanOleh2;
            }
        }
        public ActionResult Edit(int id)
        {
            Context.PenetapanDriver dbitem = RepoPenetapanDriver.FindByPK(id);
            PenetapanDriver         model  = new PenetapanDriver(dbitem);

            ViewBag.name = model.VehicleNo;
            return(View("Form", model));
        }
        public JsonResult Delete(int id)
        {
            ResponeModel response = new ResponeModel(true);

            Context.PenetapanDriver dbItem = RepoPenetapanDriver.FindByPK(id);

            RepoPenetapanDriver.delete(dbItem);

            return(Json(response));
        }
        public string BindingHistory(int id)
        {
            Context.PenetapanDriver db = RepoPenetapanDriver.FindByPK(id);

            return(new JavaScriptSerializer().Serialize(db.PenetapanDriverHistory.
                                                        Select(d => new {
                Driver1 = d.Driver1,
                Driver2 = d.Driver2,
                CreatedBy = d.CreatedBy,
                ModifiedBy = d.ModifiedBy,
                ModifiedDate = d.ModifiedDate
            })));
        }
Beispiel #5
0
        public void SetDb(Context.PenetapanDriver dbitem, string user)
        {
            dbitem.IdDataTruck = IdDataTruck;

            dbitem.IdDriver1    = IdDriver1;
            dbitem.NoHp1Driver1 = NoHp1Driver1;
            dbitem.NoHp2Driver1 = NoHp1Driver1;

            dbitem.IdDriver2    = IdDriver2;
            dbitem.NoHp1Driver2 = NoHp1Driver2;
            dbitem.NoHp2Driver2 = NoHp2Driver2;

            dbitem.DitetapkanOleh1 = IdDitetapkanOleh1;
            dbitem.DitetapkanOleh2 = IdDitetapkanOleh2;

            dbitem.ModifiedBy   = user;
            dbitem.ModifiedDate = DateTime.Now;
        }
Beispiel #6
0
        public DataTruckDetail(Context.DataTruck dbitem, List <Context.PenetapanDriver> dbPenetapanDriver = null, List <Context.SalesOrder> dbso = null)
        {
            Id = dbitem.Id;
            //cek status order
            StatusOrder = "";
            StatusTruk  = "Available";
            if (dbso != null)
            {
                if (dbso.Any(d => (d.Status == "save" || d.Status == "draft planning") &&
                             ((d.SalesOrderOncallId.HasValue ? d.SalesOrderOncall.IdDataTruck == dbitem.Id : false) ||
                              (d.SalesOrderPickupId.HasValue ? d.SalesOrderPickup.IdDataTruck == dbitem.Id : false) ||
                              (d.SalesOrderProsesKonsolidasiId.HasValue ? d.SalesOrderProsesKonsolidasi.IdDataTruck == dbitem.Id : false) ||
                              (d.SalesOrderKontrakId.HasValue ? d.SalesOrderKontrak.SalesOrderKontrakTruck.Any(k => k.DataTruckId == dbitem.Id) : false))))
                {
                    StatusOrder = "Planning";
                    StatusTruk  = "On Duty";
                }
                else if (dbso.Any(d => (d.Status == "save planning" || d.Status == "draft konfirmasi") &&
                                  ((d.SalesOrderOncallId.HasValue ? d.SalesOrderOncall.IdDataTruck == dbitem.Id : false) ||
                                   (d.SalesOrderPickupId.HasValue ? d.SalesOrderPickup.IdDataTruck == dbitem.Id : false) ||
                                   (d.SalesOrderProsesKonsolidasiId.HasValue ? d.SalesOrderProsesKonsolidasi.IdDataTruck == dbitem.Id : false) ||
                                   (d.SalesOrderKontrakId.HasValue ? d.SalesOrderKontrak.SalesOrderKontrakTruck.Any(k => k.DataTruckId == dbitem.Id) : false))))
                {
                    StatusOrder = "Konfirmasi";
                    StatusTruk  = "On Duty";
                }
                else if (dbso.Any(d => (d.Status == "save konfirmasi" || d.Status == "dispatched") &&
                                  ((d.SalesOrderOncallId.HasValue ? d.SalesOrderOncall.IdDataTruck == dbitem.Id : false) ||
                                   (d.SalesOrderPickupId.HasValue ? d.SalesOrderPickup.IdDataTruck == dbitem.Id : false) ||
                                   (d.SalesOrderProsesKonsolidasiId.HasValue ? d.SalesOrderProsesKonsolidasi.IdDataTruck == dbitem.Id : false) ||
                                   (d.SalesOrderKontrakId.HasValue ? d.SalesOrderKontrak.SalesOrderKontrakTruck.Any(k => k.DataTruckId == dbitem.Id) : false))))
                {
                    StatusOrder = "Dispatched";
                    StatusTruk  = "On Duty";
                }
            }
            //StatusTruk =
            VehicleNo = dbitem.VehicleNo;
            Merk      = dbitem.IdMerk != null ? dbitem.LookupCodeMerk.Nama : "";
            JenisTruk = !dbitem.IdJenisTruck.HasValue ? "" : dbitem.JenisTrucks.StrJenisTruck;
            if (dbitem.DataPendingin.Count > 0)
            {
                Context.DataPendingin dbpendingin = dbitem.DataPendingin.FirstOrDefault();
                Pendingin = dbpendingin.Merk + " - " + dbpendingin.Model;
            }
            if (dbitem.DataBox.Count > 0)
            {
                Context.DataBox dbbox    = dbitem.DataBox.FirstOrDefault();
                List <string>   _lantai  = new List <string>();
                List <string>   _dinding = new List <string>();

                if (dbbox.Lantai != null && dbbox.Lantai != "")
                {
                    _lantai.Add(dbbox.Lantai);
                }
                if (dbbox.Dinding != null && dbbox.Dinding != "")
                {
                    _dinding.Add(dbbox.Dinding);
                }
                foreach (DataBoxLantai item in dbbox.DataBoxLantai)
                {
                    _lantai.Add(item.LookupCodeLantaiCode.Nama);
                }
                foreach (DataBoxDinding item in dbbox.DataBoxDinding)
                {
                    _dinding.Add(item.LookupCodeDinding.Nama);
                }
                if (_lantai.Count() > 0)
                {
                    Lantai = string.Join(", ", _lantai);
                }
                if (_dinding.Count() > 0)
                {
                    Dinding = string.Join(", ", _dinding);
                }
            }
            KondisiKhusus = dbitem.Kondisi;
            List <string> _dok = new List <string>();

            if (dbitem.STNK != null && dbitem.STNK.Value >= DateTime.Now)
            {
                _dok.Add("STNK");
            }
            if (dbitem.KIR != null && dbitem.KIR.Value >= DateTime.Now)
            {
                _dok.Add("KIR");
            }
            if (dbitem.KIU != null && dbitem.KIU.Value >= DateTime.Now)
            {
                _dok.Add("KIU/SIPA");
            }
            if (dbitem.IBM != null && dbitem.IBM.Value >= DateTime.Now)
            {
                _dok.Add("IBM");
            }
            if (dbitem.Asuransi != null && dbitem.Asuransi.Value >= DateTime.Now)
            {
                _dok.Add("Asuransi");
            }
            if (dbitem.Reklame != null && dbitem.Reklame.Value >= DateTime.Now)
            {
                _dok.Add("Pajak Reklame");
            }
            if (_dok.Count > 0)
            {
                DokumenExp = string.Join(", ", _dok);
            }

            if (dbPenetapanDriver != null)
            {
                Context.PenetapanDriver dbPenetapan = dbPenetapanDriver.Where(d => d.IdDataTruck == dbitem.Id).FirstOrDefault();
                if (dbPenetapan != null)
                {
                    IdDriver1     = dbPenetapan.IdDriver1.Value;
                    KodeDriver1   = dbPenetapan.Driver1.KodeDriver;
                    NamaDriver1   = dbPenetapan.Driver1.NamaDriver;
                    StatusDriver1 = dbPenetapan.Driver1.LookupCodeStatus.Nama;
                    if (dbPenetapan.IdDriver2.HasValue)
                    {
                        IdDriver2     = dbPenetapan.IdDriver2.Value;
                        KodeDriver2   = dbPenetapan.Driver2.KodeDriver;
                        NamaDriver2   = dbPenetapan.Driver2.NamaDriver;
                        StatusDriver2 = dbPenetapan.Driver2.LookupCodeStatus.Nama;
                    }
                }
            }
        }
        public ActionResult Add(PenetapanDriver model)
        {
            if (ModelState.IsValid)
            {
                bool isPalid = true;
                if (RepoPenetapanDriver.IsExist(model.IdDataTruck.Value))
                {
                    isPalid = false;
                    ModelState.AddModelError("IdDataTruck", "Data truck sudah digunakan.");
                }

                if (RepoPenetapanDriver.isExistDriver(model.IdDriver1.Value, 0))
                {
                    isPalid = false;
                    ModelState.AddModelError("idDriver1", "Driver sudah digunakan.");
                }

                if (model.IdDriver2.HasValue)
                {
                    if (RepoPenetapanDriver.isExistDriver(model.IdDriver2.Value, 0))
                    {
                        isPalid = false;
                        ModelState.AddModelError("IdDriver2", "Driver sudah digunakan.");
                    }
                    if (model.IdDriver1 == model.IdDriver2)
                    {
                        isPalid = false;
                        ModelState.AddModelError("IdDriver1", "Driver tidak boleh sama.");
                        ModelState.AddModelError("IdDriver2", "Driver tidak boleh sama.");
                    }
                    if (model.IdDitetapkanOleh2 == null)
                    {
                        isPalid = false;
                        ModelState.AddModelError("IdDitetapkanOleh2", "Penetap Driver 2 Belum Ditentukan.");
                    }
                }

                if (model.IdDitetapkanOleh1 == null)
                {
                    isPalid = false;
                    ModelState.AddModelError("IdDitetapkanOleh1", "Penetap Driver 1 Belum Ditentukan.");
                }

                if (!isPalid)
                {
                    return(View("Form", model));
                }

                Context.PenetapanDriver        dbitem        = new Context.PenetapanDriver();
                Context.PenetapanDriverHistory dbitemHistory = new Context.PenetapanDriverHistory();
                //history
                model.SetDb(dbitem, UserPrincipal.firstname + ' ' + UserPrincipal.lastname);
                model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                dbitemHistory.CreatedBy   = UserPrincipal.firstname + " " + UserPrincipal.lastname;
                dbitemHistory.CreatedDate = DateTime.Now;
                dbitem.PenetapanDriverHistory.Add(dbitemHistory);
                //history driver
                Context.DataTruck dbtruck = RepoTruck.FindByPK(model.IdDataTruck.Value);

                Context.Driver             dbdriver1        = RepoDriver.FindByPK(model.IdDriver1.Value);
                Context.DriverTruckHistory dbdriverHistory1 = new Context.DriverTruckHistory();
                dbdriver1.NoHp1          = model.NoHp1Driver1;
                dbdriver1.NoHp2          = model.NoHp2Driver1;
                dbdriverHistory1.Tanggal = DateTime.Now;
                dbdriverHistory1.Nopol   = dbtruck.VehicleNo;
                dbdriverHistory1.Type    = model.JenisTruck;
                dbdriver1.DriverTruckHistory.Add(dbdriverHistory1);
                RepoDriver.save(dbdriver1);
                string query = "UPDATE dbo.\"Driver\" SET \"NoHp1\" = " + dbdriver1.NoHp1 + ", \"NoHp2\" = " + dbdriver1.NoHp2 + " WHERE \"Id\" = " + dbdriver1.Id + ";INSERT INTO dbo.\"DriverTruckHistory\" (\"IdDriver\", " +
                               "\"Tanggal\", \"Type\", \"Nopol\") VALUES (" + dbdriverHistory1.IdDriver + ", " + dbdriverHistory1.Tanggal + ", " + dbdriverHistory1.Type + ", " + dbdriverHistory1.Nopol + ");";
                RepoAuditrail.SetAuditTrail(query, "Penetapan Driver", "Add", UserPrincipal.id);

                if (model.IdDriver2.HasValue)
                {
                    Context.Driver             dbdriver2        = RepoDriver.FindByPK(model.IdDriver2.Value);
                    Context.DriverTruckHistory dbdriverHistory2 = new Context.DriverTruckHistory();
                    dbdriver2.NoHp1          = model.NoHp1Driver2;
                    dbdriver2.NoHp2          = model.NoHp2Driver2;
                    dbdriverHistory2.Tanggal = DateTime.Now;
                    dbdriverHistory2.Nopol   = dbtruck.VehicleNo;
                    dbdriverHistory2.Type    = model.JenisTruck;
                    dbdriver2.DriverTruckHistory.Add(dbdriverHistory2);
                    RepoDriver.save(dbdriver2);
                    query = "UPDATE dbo.\"Driver\" SET \"NoHp1\" = " + dbdriver2.NoHp1 + ", \"NoHp2\" = " + dbdriver2.NoHp2 + " WHERE \"Id\" = " + dbdriver2.Id + ";INSERT INTO dbo.\"DriverTruckHistory\" ( " +
                            "\"IdDriver\", \"Tanggal\", \"Type\", \"Nopol\") VALUES (" + dbdriverHistory2.IdDriver + ", " + dbdriverHistory2.Tanggal + ", " + dbdriverHistory2.Type + ", " + dbdriverHistory2.Nopol + ");";
                    RepoAuditrail.SetAuditTrail(query, "Penetapan Driver", "Add", UserPrincipal.id);
                }


                RepoPenetapanDriver.save(dbitem);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
        public string Upload(IEnumerable <HttpPostedFileBase> filesPenetapanDriver)
        {
            ResponeModel response = new ResponeModel();


            if (filesPenetapanDriver != null)
            {
                foreach (var file in filesPenetapanDriver)
                {
                    try
                    {
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            var noOfCol      = workSheet.Dimension.End.Column;
                            var noOfRow      = workSheet.Dimension.End.Row;



                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                if (workSheet.Cells[rowIterator, 1].Value != null && workSheet.Cells[rowIterator, 2].Value != null && RepoTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()) != null)
                                {
                                    int id = 0;
                                    int resId;


                                    if (workSheet.Cells[rowIterator, 10].Value != null)
                                    {
                                        if (int.TryParse(workSheet.Cells[rowIterator, 10].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }

                                    Context.PenetapanDriver db = new Context.PenetapanDriver();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            db = RepoPenetapanDriver.FindByPK(id);
                                        }
                                        Context.Driver dr1 = RepoDriver.FindByCode(workSheet.Cells[rowIterator, 2].Value.ToString());
                                        Context.Driver dr2 = workSheet.Cells[rowIterator, 6].Value == null ? null : RepoDriver.FindByCode(workSheet.Cells[rowIterator, 6].Value.ToString());
                                        db.IdDataTruck = RepoTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id;

                                        if (id == 0 && RepoPenetapanDriver.IsExist(db.IdDataTruck.Value))
                                        {
                                            continue;
                                        }

                                        if (dr1 != null)
                                        {
                                            if (RepoPenetapanDriver.isExistDriver(dr1.Id, id))
                                            {
                                                continue;
                                            }
                                        }

                                        if (dr2 != null)
                                        {
                                            if (RepoPenetapanDriver.isExistDriver(dr2.Id, id))
                                            {
                                                continue;
                                            }
                                        }

                                        if (dr1 != null && dr2 != null)
                                        {
                                            if (dr2.Id.Equals(dr1.Id))
                                            {
                                                continue;
                                            }
                                        }

                                        db.IdDriver1       = dr1.Id;
                                        db.NoHp1Driver1    = workSheet.Cells[rowIterator, 3].Value == null ? dr1.NoHp1 : workSheet.Cells[rowIterator, 3].Value.ToString();
                                        db.NoHp2Driver1    = workSheet.Cells[rowIterator, 4].Value == null ? dr1.NoHp2 : workSheet.Cells[rowIterator, 4].Value.ToString();
                                        db.DitetapkanOleh1 = workSheet.Cells[rowIterator, 5].Value == null ? null : workSheet.Cells[rowIterator, 5].Value.ToString();

                                        if (dr2 != null)
                                        {
                                            db.IdDriver2       = dr2.Id;
                                            db.NoHp1Driver2    = workSheet.Cells[rowIterator, 7].Value == null ? dr2.NoHp1 : workSheet.Cells[rowIterator, 7].Value.ToString();
                                            db.NoHp2Driver2    = workSheet.Cells[rowIterator, 8].Value == null ? dr2.NoHp2 : workSheet.Cells[rowIterator, 8].Value.ToString();
                                            db.DitetapkanOleh2 = workSheet.Cells[rowIterator, 9].Value == null ? null : workSheet.Cells[rowIterator, 9].Value.ToString();
                                            dr2.NoHp1          = db.NoHp1Driver2;
                                            dr2.NoHp2          = db.NoHp2Driver2;
                                        }

                                        db.ModifiedBy   = UserPrincipal.username;
                                        db.ModifiedDate = DateTime.Now;

                                        dr1.NoHp1 = db.NoHp1Driver1;
                                        dr1.NoHp2 = db.NoHp2Driver1;

                                        RepoPenetapanDriver.save(db);

                                        int resultId = db.Id;

                                        //save penetapan driver history
                                        Context.PenetapanDriverHistory dbItemHistory = new Context.PenetapanDriverHistory();
                                        Context.PenetapanDriver        pd            = RepoPenetapanDriver.FindByPK(resultId);

                                        dbItemHistory.IdPenetapanDriver = resultId;
                                        dbItemHistory.Driver1           = dr1.NamaDriver;
                                        if (dr2 != null)
                                        {
                                            dbItemHistory.Driver2 = dr2.NamaDriver;
                                        }
                                        dbItemHistory.CreatedBy    = UserPrincipal.firstname + " " + UserPrincipal.lastname;
                                        dbItemHistory.ModifiedBy   = UserPrincipal.firstname + " " + UserPrincipal.lastname;
                                        dbItemHistory.ModifiedDate = DateTime.Now;
                                        pd.PenetapanDriverHistory.Add(dbItemHistory);

                                        //history driver

                                        Context.DriverTruckHistory dbdriverHistory1 = new Context.DriverTruckHistory();
                                        Context.DriverTruckHistory dbdriverHistory2 = new Context.DriverTruckHistory();
                                        Context.DataTruck          dbtruck          = RepoTruck.FindByPK(db.IdDataTruck.Value);

                                        dbdriverHistory1.Tanggal = DateTime.Now;
                                        dbdriverHistory1.Nopol   = dbtruck.VehicleNo;
                                        dbdriverHistory1.Type    = dbtruck.JenisTrucks.StrJenisTruck;

                                        dbdriverHistory2.Tanggal = DateTime.Now;
                                        dbdriverHistory2.Nopol   = dbtruck.VehicleNo;
                                        dbdriverHistory2.Type    = dbtruck.JenisTrucks.StrJenisTruck;

                                        dr1.DriverTruckHistory.Add(dbdriverHistory1);

                                        RepoDriver.save(dr1);
                                        string query = "UPDATE dbo.\"Driver\" SET \"NoHp1\" = " + dr1.NoHp1 + ", \"NoHp2\" = " + dr1.NoHp2 + " WHERE \"Id\" = " + dr1.Id + ";INSERT INTO dbo.\"DriverTruckHistory\" ( " +
                                                       "\"IdDriver\", \"Tanggal\", \"Type\", \"Nopol\") VALUES (" + dbdriverHistory1.IdDriver + ", " + dbdriverHistory1.Tanggal + ", " + dbdriverHistory1.Type + ", " +
                                                       dbdriverHistory1.Nopol + ");";
                                        RepoAuditrail.SetAuditTrail(query, "Penetapan Driver", "Import", UserPrincipal.id);
                                        if (dr2 != null)
                                        {
                                            dr2.NoHp1 = db.NoHp1Driver2;
                                            dr2.NoHp2 = db.NoHp2Driver2;
                                            dr2.DriverTruckHistory.Add(dbdriverHistory2);
                                            RepoDriver.save(dr2);
                                            query = "UPDATE dbo.\"Driver\" SET \"NoHp1\" = " + dr2.NoHp1 + ", \"NoHp2\" = " + dr2.NoHp2 + " WHERE \"Id\" = " + dr2.Id + ";INSERT INTO dbo.\"DriverTruckHistory\" ( " +
                                                    "\"IdDriver\", \"Tanggal\", \"Type\", \"Nopol\") VALUES (" + dbdriverHistory2.IdDriver + ", " + dbdriverHistory2.Tanggal + ", " + dbdriverHistory2.Type + ", " +
                                                    dbdriverHistory2.Nopol + ");";
                                            RepoAuditrail.SetAuditTrail(query, "Penetapan Driver", "Import", UserPrincipal.id);
                                        }
                                        RepoPenetapanDriver.save(pd);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }

                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }
            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }