Beispiel #1
0
        public ActionResult Edit(int id)
        {
            LookupCode model = new LookupCode(RepoLookup.FindByPK(id));

            ViewBag.name = model.Nama;
            return(View("Form", model));
        }
Beispiel #2
0
        public ActionResult Dynamic()
        {
            ViewBag.LookupCodesSPBU  = RepoLookup.FindAll().Where(d => d.LookupCodeCategories.Category == "tms_SPBU").ToList();
            ViewBag.LookupCodesKapal = RepoLookup.FindAll().Where(d => d.LookupCodeCategories.Category == "tms_penyebrangan").ToList();
            ViewBag.Pool             = RepoMasterPool.FindAll();

            return(View("Dynamic"));
        }
Beispiel #3
0
        public JsonResult Delete(int id)
        {
            ResponeModel response = new ResponeModel(true);

            Context.LookupCode dbItem = RepoLookup.FindByPK(id);

            RepoLookup.delete(dbItem);

            return(Json(response));
        }
Beispiel #4
0
        public ActionResult Edit(LookupCode model)
        {
            if (ModelState.IsValid)
            {
                Context.LookupCode dbitem = RepoLookup.FindByPK(model.Id);
                model.setDb(dbitem);
                RepoLookup.save(dbitem);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
Beispiel #5
0
        public ActionResult Add(LookupCode model)
        {
            if (ModelState.IsValid)
            {
                Context.LookupCode dbitem = new Context.LookupCode();
                model.setDb(dbitem);
                RepoLookup.save(dbitem);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
Beispiel #6
0
        public string UploadLookUpCode(IEnumerable <HttpPostedFileBase> filesLookUp)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesLookUp != null)
            {
                foreach (var file in filesLookUp)
                {
                    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 ||
                                    workSheet.Cells[rowIterator, 3].Value != null || workSheet.Cells[rowIterator, 4].Value != null)
                                {
                                    string             namaKategori = workSheet.Cells[rowIterator, 1].Value.ToString();
                                    int?               idKategori   = RepoKategori.FindAll().Where(k => k.Category == namaKategori).Select(k => k.Id).FirstOrDefault();
                                    string             namaLookUp   = RepoLookup.FindAll().Where(l => l.Nama == workSheet.Cells[rowIterator, 2].Value.ToString()).Select(l => l.Nama).FirstOrDefault();
                                    Context.LookupCode dbitem       = new Context.LookupCode();

                                    if (idKategori.HasValue && namaLookUp == null && idKategori > 0)
                                    {
                                        dbitem.IdKategori = idKategori.Value;
                                        dbitem.Nama       = workSheet.Cells[rowIterator, 2].Value.ToString();
                                        dbitem.Order      = int.Parse(workSheet.Cells[rowIterator, 3].Value.ToString());
                                        dbitem.Deskripsi  = workSheet.Cells[rowIterator, 4].Value.ToString();

                                        RepoLookup.save(dbitem);
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
Beispiel #7
0
        public string Binding()
        {
            GridRequestParameters param = GridRequestParameters.Current;

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

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

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

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

            return(new JavaScriptSerializer().Serialize(new { total = total, data = ListModel }));
        }
Beispiel #8
0
        public string BindingKonsolidasi()
        {
            GridRequestParameters param = GridRequestParameters.Current;

            List <Context.LookupCode> items = RepoLookup.FindAll(param.Skip, 200, (param.Sortings != null ? param.Sortings.ToList() : null), param.Filters).Where(d => d.LookupCodeCategories.Category == "tms_customer_konsolidasi").ToList();

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

            foreach (Context.LookupCode item in items)
            {
                LookupCode lc = new LookupCode(item);
                ListModel.Add(lc);
            }

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

            return(new JavaScriptSerializer().Serialize(new { total = total, data = ListModel }));
        }
        public ActionResult Add(DataBox model)
        {
            if (ModelState.IsValid)
            {
                if (RepoDataBox.IsBoxExist(model.IdDataTruck.Value))
                {
                    ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang box, harap ganti dengan truck yang lain");
                    return(View("Form", model));
                }
                Context.DataBox dbitem = new Context.DataBox();
                model.SetDb(dbitem);
                //generate code
                dbitem.Urutan = RepoDataBox.getUrutan() + 1;
                dbitem.NoBox  = RepoDataBox.generateCode(dbitem.Urutan);

                Context.DataBoxHistory dbitemHistory = new Context.DataBoxHistory();
                model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                dbitemHistory.Vehicle     = RepoDataTruck.FindByPK(model.IdDataTruck.Value).VehicleNo;
                dbitemHistory.NoBox       = dbitem.NoBox;
                dbitemHistory.strKategori = model.IdKategori.HasValue ? RepoLookup.FindByPK(model.IdKategori.Value).Nama : "";
                dbitemHistory.strType     = model.IdType.HasValue ? RepoLookup.FindByPK(model.IdType.Value).Nama : "";
                dbitem.DataBoxHistory.Add(dbitemHistory);
                Context.DataTruckBoxHistory dbtruckHistory = new Context.DataTruckBoxHistory();
                model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                RepoDataBox.save(dbitem, UserPrincipal.id, dbitemHistory, dbtruckHistory);

                Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value);
                dbtruckHistory.Vehicle     = dbtruck.VehicleNo;
                dbtruckHistory.NoBox       = dbitem.NoBox;
                dbtruckHistory.strKategori = model.IdKategori.HasValue ? RepoLookup.FindByPK(model.IdKategori.Value).Nama : "";
                dbtruckHistory.strType     = model.IdType.HasValue ? RepoLookup.FindByPK(model.IdType.Value).Nama : "";
                dbtruck.DataTruckBoxHistory.Add(dbtruckHistory);
                RepoDataTruck.save(dbtruck, UserPrincipal.id);


                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
        public ActionResult Add(DataPendingin model)
        {
            if (ModelState.IsValid)
            {
                if (RepoPendingin.IsBoxExist(model.IdDataTruk.Value))
                {
                    ModelState.AddModelError("IdDataTruk", "Truck sudah tepasang pendingin, harap ganti dengan truck yang lain");
                    return(View("Form", model));
                }
                Context.DataPendingin dbitem = new Context.DataPendingin();
                model.setDb(dbitem);

                //generate code
                dbitem.Urutan      = RepoPendingin.getUrutan() + 1;
                dbitem.NoPendingin = RepoPendingin.generateCode(dbitem.Urutan);

                Context.DataPendinginHistory dbitemhistory = new Context.DataPendinginHistory();
                model.setDbHistory(dbitemhistory, UserPrincipal.firstname + ' ' + UserPrincipal.lastname);
                dbitemhistory.NoPendingin       = dbitem.NoPendingin;
                dbitemhistory.strDataTruk       = RepoDataTruck.FindByPK(dbitem.IdDataTruk).VehicleNo;
                dbitemhistory.strJenisPendingin = dbitem.IdJenisPendingin.HasValue ? RepoLookup.FindByPK(dbitem.IdJenisPendingin).Nama : "";
                dbitem.ListHistoryPendingin.Add(dbitemhistory);
                Context.DataTruckPendinginHistory dbtruckhistory = new Context.DataTruckPendinginHistory();
                model.setDbTruckHistory(dbtruckhistory, UserPrincipal.firstname + ' ' + UserPrincipal.lastname);
                RepoPendingin.save(dbitem, UserPrincipal.id, dbitemhistory, dbtruckhistory);

                Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruk.Value);
                dbtruckhistory.NoPendingin       = dbitem.NoPendingin;
                dbtruckhistory.strDataTruk       = RepoDataTruck.FindByPK(dbitem.IdDataTruk).VehicleNo;
                dbtruckhistory.strJenisPendingin = dbitem.IdJenisPendingin.HasValue ? RepoLookup.FindByPK(dbitem.IdJenisPendingin).Nama : "";
                dbtruck.DataTruckPendinginHistory.Add(dbtruckhistory);
                RepoDataTruck.save(dbtruck, UserPrincipal.id);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
Beispiel #11
0
        public string UploadProduct(IEnumerable <HttpPostedFileBase> filesProduct)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesProduct != null)
            {
                foreach (var file in filesProduct)
                {
                    try
                    {
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            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 && workSheet.Cells[rowIterator, 3].Value != null &&
                                    workSheet.Cells[rowIterator, 4].Value != null && workSheet.Cells[rowIterator, 5].Value != null && workSheet.Cells[rowIterator, 6].Value != null &&
                                    decimal.Parse(workSheet.Cells[rowIterator, 3].Value.ToString()) >= -30 && decimal.Parse(workSheet.Cells[rowIterator, 3].Value.ToString()) <= 30 &&
                                    decimal.Parse(workSheet.Cells[rowIterator, 4].Value.ToString()) >= -30 && decimal.Parse(workSheet.Cells[rowIterator, 4].Value.ToString()) <= 30 &&
                                    decimal.Parse(workSheet.Cells[rowIterator, 5].Value.ToString()) >= -30 && decimal.Parse(workSheet.Cells[rowIterator, 5].Value.ToString()) <= 30)
                                {
                                    int id = 0;

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

                                    //cara gancang ngarah teu kudu aya pengecekan tiap field
                                    Context.MasterProduct dbitem = new Context.MasterProduct();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoProduct.FindByPK(id);
                                            if (RepoProduct.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString(), id))
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            if (RepoProduct.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString()))
                                            {
                                                continue;
                                            }
                                        }


                                        dbitem.NamaProduk = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        dbitem.IdKategori = RepoLookup.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()).Id;
                                        dbitem.TargetSuhu = decimal.Parse(workSheet.Cells[rowIterator, 3].Value.ToString());
                                        dbitem.MaxTemps   = decimal.Parse(workSheet.Cells[rowIterator, 4].Value.ToString());
                                        dbitem.MinTemps   = decimal.Parse(workSheet.Cells[rowIterator, 5].Value.ToString());
                                        dbitem.Treshold   = int.Parse(workSheet.Cells[rowIterator, 6].Value.ToString());
                                        dbitem.Remarks    = workSheet.Cells[rowIterator, 7].Value == null ? "" : workSheet.Cells[rowIterator, 7].Value.ToString();

                                        RepoProduct.save(dbitem);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
Beispiel #12
0
        public string GetLookUpByName(string nama)
        {
            Context.LookupCode db = RepoLookup.FindByName(nama);

            return(new JavaScriptSerializer().Serialize(db));
        }
        public string UploadDataBox(IEnumerable <HttpPostedFileBase> filesDataBox)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesDataBox != null)
            {
                foreach (var file in filesDataBox)
                {
                    try
                    {
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            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 &&
                                                                                   * workSheet.Cells[rowIterator, 3].Value != null && workSheet.Cells[rowIterator, 4].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 5].Value != null && workSheet.Cells[rowIterator, 6].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 7].Value != null && workSheet.Cells[rowIterator, 8].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 9].Value != null && workSheet.Cells[rowIterator, 10].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 11].Value != null && workSheet.Cells[rowIterator, 12].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 13].Value != null && workSheet.Cells[rowIterator, 14].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 15].Value != null && workSheet.Cells[rowIterator, 16].Value != null*/)
                                {
                                    int id = 0;
                                    int resId;
                                    int temprow = rowIterator;
                                    if (workSheet.Cells[rowIterator, 17].Value != null)
                                    {
                                        if (int.TryParse(workSheet.Cells[rowIterator, 17].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }

                                    Context.DataBox dbitem = new Context.DataBox();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            if (RepoDataBox.IsBoxExist(RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id, id))
                                            {
                                                continue;
                                            }
                                            dbitem = RepoDataBox.FindByPK(id);
                                            dbitem.DataBoxLantai.Clear();
                                            dbitem.DataBoxDinding.Clear();
                                        }
                                        else
                                        {
                                            if (RepoDataBox.IsBoxExist(RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id))
                                            {
                                                continue;
                                            }
                                            dbitem.Urutan = RepoDataBox.getUrutan() + 1;
                                            dbitem.NoBox  = RepoDataBox.generateCode(dbitem.Urutan);
                                        }
                                        dbitem.IdDataTruck  = RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id;
                                        dbitem.Karoseri     = workSheet.Cells[rowIterator, 2].Value == null ? null : workSheet.Cells[rowIterator, 2].Value.ToString();
                                        dbitem.Tahun        = workSheet.Cells[rowIterator, 3].Value == null ? (int?)null : int.Parse(workSheet.Cells[rowIterator, 3].Value.ToString());
                                        dbitem.IdType       = workSheet.Cells[rowIterator, 4].Value == null ? (int?)null : RepoLookup.FindByName(workSheet.Cells[rowIterator, 4].Value.ToString()).Id;
                                        dbitem.IdKategori   = workSheet.Cells[rowIterator, 5].Value == null ? (int?)null : RepoLookup.FindByName(workSheet.Cells[rowIterator, 5].Value.ToString()).Id;
                                        dbitem.tglPasang    = workSheet.Cells[rowIterator, 6].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 6].Value.ToString());
                                        dbitem.Lantai       = workSheet.Cells[rowIterator, 7].Value == null ? null : workSheet.Cells[rowIterator, 7].Value.ToString();
                                        dbitem.Dinding      = workSheet.Cells[rowIterator, 9].Value == null ? null : workSheet.Cells[rowIterator, 9].Value.ToString();
                                        dbitem.PintuSamping = workSheet.Cells[rowIterator, 11].Value == null ? (bool?)null : bool.Parse(workSheet.Cells[rowIterator, 11].Value.ToString());
                                        dbitem.Sekat        = workSheet.Cells[rowIterator, 12].Value == null ? (bool?)null : bool.Parse(workSheet.Cells[rowIterator, 12].Value.ToString());
                                        dbitem.garansiStr   = workSheet.Cells[rowIterator, 13].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 13].Value.ToString());
                                        dbitem.garansiEnd   = workSheet.Cells[rowIterator, 14].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 14].Value.ToString());
                                        dbitem.asuransiStr  = workSheet.Cells[rowIterator, 15].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 15].Value.ToString());
                                        dbitem.asuransiEnd  = workSheet.Cells[rowIterator, 16].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 16].Value.ToString());
                                        //lantai
                                        int idx1 = 0;
                                        for (idx1 = rowIterator; idx1 <= noOfRow; idx1++)
                                        {
                                            if (workSheet.Cells[idx1, 1].Value == null || idx1 == rowIterator)
                                            {
                                                if (workSheet.Cells[idx1, 8].Value != null)
                                                {
                                                    Context.DataBoxLantai item = new Context.DataBoxLantai();
                                                    item.IdLantaiCode = RepoLookup.FindByName(workSheet.Cells[idx1, 8].Value.ToString()).Id;
                                                    dbitem.DataBoxLantai.Add(item);
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                        //dinding
                                        int idx2 = 0;
                                        for (idx2 = rowIterator; idx2 <= noOfRow; idx2++)
                                        {
                                            if (workSheet.Cells[idx2, 1].Value == null || idx2 == rowIterator)
                                            {
                                                if (workSheet.Cells[idx2, 10].Value != null)
                                                {
                                                    Context.DataBoxDinding item = new Context.DataBoxDinding();
                                                    item.IdDindingCode = RepoLookup.FindByName(workSheet.Cells[idx2, 10].Value.ToString()).Id;
                                                    dbitem.DataBoxDinding.Add(item);
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }

                                        if (idx1 > idx2)
                                        {
                                            rowIterator = idx1 - 1;
                                        }
                                        else
                                        {
                                            rowIterator = idx2 - 1;
                                        }

                                        //history
                                        Context.DataBoxHistory dbhistory = new Context.DataBoxHistory();
                                        dbhistory.NoBox        = dbitem.NoBox;
                                        dbhistory.Vehicle      = workSheet.Cells[rowIterator, 1].Value == null ? null : workSheet.Cells[temprow, 1].Value.ToString();
                                        dbhistory.Karoseri     = dbitem.Karoseri;
                                        dbhistory.Tahun        = dbitem.Tahun;
                                        dbhistory.strType      = workSheet.Cells[rowIterator, 4].Value == null ? null : workSheet.Cells[temprow, 4].Value.ToString();
                                        dbhistory.strKategori  = workSheet.Cells[rowIterator, 5].Value == null ? null : workSheet.Cells[temprow, 5].Value.ToString();
                                        dbhistory.Lantai       = dbitem.Lantai;
                                        dbhistory.Dinding      = dbitem.Dinding;
                                        dbhistory.PintuSamping = dbitem.PintuSamping;
                                        dbhistory.Sekat        = dbitem.Sekat;
                                        dbhistory.garansiStr   = dbitem.garansiStr;
                                        dbhistory.garansiEnd   = dbitem.garansiEnd;
                                        dbhistory.asuransiStr  = dbitem.asuransiStr;
                                        dbhistory.asuransiEnd  = dbitem.asuransiEnd;
                                        dbhistory.tglPasang    = dbitem.tglPasang;
                                        dbhistory.Tanggal      = DateTime.Now;
                                        dbhistory.username     = UserPrincipal.firstname + " " + UserPrincipal.lastname;

                                        //foreach (LantaiModel item in )
                                        //{
                                        //    if (item.IsSelect)
                                        //    {
                                        //        dbitem.Lantai = dbitem.Lantai + ", " + item.StrLantai;
                                        //    }
                                        //}
                                        //foreach (DindingModel item in ListDinding)
                                        //{
                                        //    if (item.IsSelect)
                                        //    {
                                        //        dbitem.Dinding = dbitem.Dinding + ", " + item.StrDinding;
                                        //    }
                                        //}

                                        dbitem.DataBoxHistory.Add(dbhistory);

                                        RepoDataBox.save(dbitem, UserPrincipal.id, dbhistory);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
        public string UploadRekening(IEnumerable <HttpPostedFileBase> filesRekening)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesRekening != null)
            {
                foreach (var file in filesRekening)
                {
                    try
                    {
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            var noOfRow      = workSheet.Dimension.End.Row;
                            var regexItem    = new System.Text.RegularExpressions.Regex("^[0-9]*$");

                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                //cek mandatory field
                                if (workSheet.Cells[rowIterator, 1].Value != null && workSheet.Cells[rowIterator, 2].Value != null &&
                                    workSheet.Cells[rowIterator, 3].Value != null && workSheet.Cells[rowIterator, 4].Value != null &&
                                    regexItem.IsMatch(workSheet.Cells[rowIterator, 2].Value.ToString()))
                                {
                                    int id = 0;

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

                                    try
                                    {
                                        Context.Rekenings dbitem = new Context.Rekenings();;
                                        if (id != 0)
                                        {
                                            if (RepoRekening.IsExist(RepoLookup.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id, workSheet.Cells[rowIterator, 2].Value.ToString(), id))
                                            {
                                                continue;
                                            }
                                            dbitem = RepoRekening.FindByPK(id);
                                        }
                                        else
                                        {
                                            if (RepoRekening.IsExist(RepoLookup.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id, workSheet.Cells[rowIterator, 2].Value.ToString()))
                                            {
                                                ModelState.AddModelError("NoRekening", "No Rekening sudah terdaftar.");
                                                continue;
                                            }
                                        }
                                        dbitem.Id           = id;
                                        dbitem.NamaRekening = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        dbitem.NoRekening   = workSheet.Cells[rowIterator, 2].Value.ToString();
                                        dbitem.IdBank       = RepoLookup.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id;
                                        string type = workSheet.Cells[rowIterator, 4].Value.ToString().ToUpper();
                                        if (type != "PPN" && type != "NON PPN")
                                        {
                                            continue;
                                        }
                                        dbitem.Type = type;

                                        RepoRekening.save(dbitem);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
Beispiel #15
0
        public string UploadATM(IEnumerable <HttpPostedFileBase> filesAtm)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesAtm != null)
            {
                foreach (var file in filesAtm)
                {
                    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 &&
                                    workSheet.Cells[rowIterator, 3].Value != null && workSheet.Cells[rowIterator, 4].Value != null &&
                                    workSheet.Cells[rowIterator, 5].Value != null)
                                {
                                    int id = 0;

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

                                    //cara gancang ngarah teu kudu aya pengecekan tiap field
                                    Context.Atm dbitem = new Context.Atm();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoAtm.FindByPK(id);
                                        }
                                        dbitem.NoKartu    = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        dbitem.IdBank     = RepoLookup.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()).Id;
                                        dbitem.NoRekening = workSheet.Cells[rowIterator, 3].Value.ToString();
                                        dbitem.AtasNama   = workSheet.Cells[rowIterator, 4].Value.ToString();
                                        dbitem.IdDriver   = RepoDriver.FindByCode(workSheet.Cells[rowIterator, 5].Value.ToString()).Id;

                                        RepoAtm.save(dbitem, UserPrincipal.id);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
Beispiel #16
0
        public string UploadDataTruck(IEnumerable <HttpPostedFileBase> filesDataTruck)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesDataTruck != null)
            {
                foreach (var file in filesDataTruck)
                {
                    try
                    {
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            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 && RepoLookup.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()) != null)
                                {
                                    int id = 0;

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

                                    Context.DataTruck dbitem = new Context.DataTruck();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoDataTruck.FindByPK(id);
                                            if (RepoDataTruck.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString(), id))
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            if (RepoDataTruck.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString()))
                                            {
                                                continue;
                                            }
                                            dbitem.urutan  = RepoDataTruck.getUrutan() + 1;
                                            dbitem.NoTruck = RepoDataTruck.generateCode(dbitem.urutan);
                                        }

                                        dbitem.VehicleNo = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        if (workSheet.Cells[rowIterator, 2].Value != null)
                                        {
                                            dbitem.IdMerk = RepoLookup.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()).Id;
                                        }
                                        if (workSheet.Cells[rowIterator, 3].Value != null)
                                        {
                                            dbitem.IdJenisTruck = JenisTruck.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id;
                                        }
                                        if (workSheet.Cells[rowIterator, 4].Value != null)
                                        {
                                            dbitem.TahunBuat = int.Parse(workSheet.Cells[rowIterator, 4].Value.ToString());
                                        }
                                        if (workSheet.Cells[rowIterator, 5].Value != null)
                                        {
                                            dbitem.TahunBeli = int.Parse(workSheet.Cells[rowIterator, 5].Value.ToString());
                                        }
                                        if (workSheet.Cells[rowIterator, 6].Value != null)
                                        {
                                            dbitem.IdPool = MasterPool.FindByNamePool(workSheet.Cells[rowIterator, 6].Value.ToString()).Id;
                                        }
                                        if (workSheet.Cells[rowIterator, 7].Value != null && RepoLookup.FindByName(workSheet.Cells[rowIterator, 7].Value.ToString()) != null)
                                        {
                                            dbitem.IdUnit = RepoLookup.FindByName(workSheet.Cells[rowIterator, 7].Value.ToString()).Id;
                                        }
                                        dbitem.Keterangan = workSheet.Cells[rowIterator, 8].Value != null ? workSheet.Cells[rowIterator, 8].Value.ToString() : "";
                                        dbitem.Kondisi    = workSheet.Cells[rowIterator, 9].Value != null ? workSheet.Cells[rowIterator, 9].Value.ToString() : "";
                                        dbitem.SpecModel  = workSheet.Cells[rowIterator, 10].Value != null ? workSheet.Cells[rowIterator, 10].Value.ToString() : "";
                                        dbitem.KmLimit    = workSheet.Cells[rowIterator, 11].Value != null?int.Parse(workSheet.Cells[rowIterator, 11].Value.ToString()) : 0;

                                        dbitem.NoMesin  = workSheet.Cells[rowIterator, 12].Value != null ? workSheet.Cells[rowIterator, 12].Value.ToString() : "";
                                        dbitem.NoRangka = workSheet.Cells[rowIterator, 13].Value != null ? workSheet.Cells[rowIterator, 13].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 14].Value != null)
                                        {
                                            dbitem.GaransiStr = DateTime.Parse(workSheet.Cells[rowIterator, 14].Value.ToString());
                                        }
                                        if (workSheet.Cells[rowIterator, 15].Value != null)
                                        {
                                            dbitem.GaransiEnd = DateTime.Parse(workSheet.Cells[rowIterator, 15].Value.ToString());
                                        }
                                        dbitem.SpecKeterangan = workSheet.Cells[rowIterator, 16].Value != null ? workSheet.Cells[rowIterator, 16].Value.ToString() : "";
                                        dbitem.AtasNama       = workSheet.Cells[rowIterator, 17].Value != null ? workSheet.Cells[rowIterator, 17].Value.ToString() : "";
                                        dbitem.BPKB           = workSheet.Cells[rowIterator, 18].Value != null ? workSheet.Cells[rowIterator, 18].Value.ToString() : "";
                                        dbitem.keteranganBPKB = workSheet.Cells[rowIterator, 19].Value != null ? workSheet.Cells[rowIterator, 19].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 20].Value != null)
                                        {
                                            dbitem.STNK = DateTime.Parse(workSheet.Cells[rowIterator, 20].Value.ToString());
                                        }
                                        dbitem.keteranganSTNK = workSheet.Cells[rowIterator, 21].Value != null ? workSheet.Cells[rowIterator, 21].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 22].Value != null)
                                        {
                                            dbitem.KIR = DateTime.Parse(workSheet.Cells[rowIterator, 22].Value.ToString());
                                        }
                                        dbitem.keteranganKIR = workSheet.Cells[rowIterator, 23].Value != null ? workSheet.Cells[rowIterator, 23].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 24].Value != null)
                                        {
                                            dbitem.KIU = DateTime.Parse(workSheet.Cells[rowIterator, 24].Value.ToString());
                                        }
                                        dbitem.keteranganKIU = workSheet.Cells[rowIterator, 25].Value != null ? workSheet.Cells[rowIterator, 25].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 26].Value != null)
                                        {
                                            dbitem.IBM = DateTime.Parse(workSheet.Cells[rowIterator, 26].Value.ToString());
                                        }
                                        dbitem.keteranganIBM = workSheet.Cells[rowIterator, 27].Value != null ? workSheet.Cells[rowIterator, 27].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 28].Value != null)
                                        {
                                            dbitem.Asuransi = DateTime.Parse(workSheet.Cells[rowIterator, 28].Value.ToString());
                                        }
                                        dbitem.keteranganAsuransi = workSheet.Cells[rowIterator, 29].Value != null ? workSheet.Cells[rowIterator, 29].Value.ToString() : null;
                                        if (workSheet.Cells[rowIterator, 30].Value != null)
                                        {
                                            dbitem.Reklame = DateTime.Parse(workSheet.Cells[rowIterator, 30].Value.ToString());
                                        }
                                        else
                                        {
                                            dbitem.Reklame = null;
                                        }
                                        dbitem.keteranganReklame  = workSheet.Cells[rowIterator, 31].Value != null ? workSheet.Cells[rowIterator, 31].Value.ToString() : "";
                                        dbitem.NoPolis            = workSheet.Cells[rowIterator, 32].Value != null ? workSheet.Cells[rowIterator, 32].Value.ToString() : null;
                                        dbitem.keteranganNoPolis  = workSheet.Cells[rowIterator, 33].Value != null ? workSheet.Cells[rowIterator, 33].Value.ToString() : "";
                                        dbitem.Peminjam           = workSheet.Cells[rowIterator, 34].Value != null ? workSheet.Cells[rowIterator, 34].Value.ToString() : null;
                                        dbitem.keteranganPeminjam = workSheet.Cells[rowIterator, 35].Value != null ? workSheet.Cells[rowIterator, 35].Value.ToString() : "";
                                        dbitem.Leasing            = workSheet.Cells[rowIterator, 36].Value != null ? workSheet.Cells[rowIterator, 36].Value.ToString() : null;
                                        dbitem.keteranganLeasing  = workSheet.Cells[rowIterator, 37].Value != null ? workSheet.Cells[rowIterator, 37].Value.ToString() : "";

                                        RepoDataTruck.save(dbitem, UserPrincipal.id);
                                    }
                                    catch (Exception)
                                    {
                                        response.Message = response.Message + Environment.NewLine + " " + rowIterator;
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
Beispiel #17
0
        public string Upload(IEnumerable <HttpPostedFileBase> files)
        {
            ResponeModel response = new ResponeModel();

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

                            //sheet 1
                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                if (workSheet.Cells[rowIterator, 1].Value != null && workSheet.Cells[rowIterator, 2].Value != null && workSheet.Cells[rowIterator, 3].Value != null &&
                                    workSheet.Cells[rowIterator, 4].Value != null && workSheet.Cells[rowIterator, 5].Value != null && workSheet.Cells[rowIterator, 6].Value != null &&
                                    workSheet.Cells[rowIterator, 7].Value != null && workSheet.Cells[rowIterator, 8].Value != null && workSheet.Cells[rowIterator, 9].Value != null &&
                                    workSheet.Cells[rowIterator, 10].Value != null && workSheet.Cells[rowIterator, 11].Value != null && workSheet.Cells[rowIterator, 12].Value != null &&
                                    workSheet.Cells[rowIterator, 13].Value != null && workSheet.Cells[rowIterator, 14].Value != null && workSheet.Cells[rowIterator, 15].Value != null)
                                {
                                    int id = 0;

                                    int resId;
                                    if (workSheet.Cells[rowIterator, 17].Value != null)
                                    {
                                        if (int.TryParse(workSheet.Cells[rowIterator, 17].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }
                                    //cara gancang ngarah teu kudu aya pengecekan tiap field
                                    Context.MasterPool dbitem = new Context.MasterPool();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoPool.FindByPK(id);
                                            if (RepoPool.IsExist(workSheet.Cells[rowIterator, 2].Value.ToString(), id))
                                            {
                                                continue;
                                            }
                                        }

                                        if (RepoPool.IsExist(workSheet.Cells[rowIterator, 2].Value.ToString(), 2))
                                        {
                                            continue;
                                        }

                                        dbitem.IsActive   = bool.Parse(workSheet.Cells[rowIterator, 1].Value.ToString());
                                        dbitem.NamePool   = workSheet.Cells[rowIterator, 2].Value.ToString();
                                        dbitem.Capacity   = int.Parse(workSheet.Cells[rowIterator, 3].Value.ToString());
                                        dbitem.Address    = workSheet.Cells[rowIterator, 4].Value.ToString();
                                        dbitem.IdProvinsi = RepoLoc.FindByNama(workSheet.Cells[rowIterator, 5].Value.ToString()).Id;
                                        dbitem.IdKabKota  = RepoLoc.FindByNama(workSheet.Cells[rowIterator, 6].Value.ToString()).Id;
                                        dbitem.IdKec      = RepoLoc.FindByNama(workSheet.Cells[rowIterator, 7].Value.ToString()).Id;
                                        dbitem.IdKel      = RepoLoc.FindByNama(workSheet.Cells[rowIterator, 8].Value.ToString()).Id;
                                        dbitem.Longitude  = workSheet.Cells[rowIterator, 9].Value.ToString();
                                        dbitem.Latitude   = workSheet.Cells[rowIterator, 10].Value.ToString();
                                        dbitem.Radius     = int.Parse(workSheet.Cells[rowIterator, 11].Value.ToString());
                                        dbitem.KodeTelp   = workSheet.Cells[rowIterator, 12].Value.ToString();
                                        dbitem.Telp       = workSheet.Cells[rowIterator, 13].Value.ToString();
                                        dbitem.Pic        = workSheet.Cells[rowIterator, 14].Value.ToString();
                                        dbitem.Handphone  = workSheet.Cells[rowIterator, 15].Value.ToString();
                                        dbitem.ListZoneParkir.Clear();
                                        int idx = 0;
                                        for (idx = rowIterator; idx <= noOfRow; idx++)
                                        {
                                            if (workSheet.Cells[idx, 1].Value == null || idx == rowIterator)
                                            {
                                                if (workSheet.Cells[idx, 16].Value != null && workSheet.Cells[idx, 17].Value != null)
                                                {
                                                    try
                                                    {
                                                        Context.ZoneParkir dbparkir = new Context.ZoneParkir();
                                                        dbparkir.IdZone = RepoLookup.FindByName(workSheet.Cells[idx, 16].Value.ToString()).Id;
                                                        dbparkir.Pit    = int.Parse(workSheet.Cells[idx, 17].Value.ToString());

                                                        dbitem.ListZoneParkir.Add(dbparkir);
                                                    }
                                                    catch (Exception)
                                                    {
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                        rowIterator = idx - 1;
                                        RepoPool.save(dbitem, UserPrincipal.id);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
        public string UploadMekanik(IEnumerable <HttpPostedFileBase> filesMekanik)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesMekanik != null)
            {
                foreach (var file in filesMekanik)
                {
                    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 && workSheet.Cells[rowIterator, 3].Value != null)
                                {
                                    if (workSheet.Cells[rowIterator, 5].Value == null)
                                    {
                                        // insert new row
                                        string namaMekaniks = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        //string namaMekanik = RepoMekanik.FindAll().Where(m => m.NamaMekanik == namaMekaniks).Select(m => m.NamaMekanik).FirstOrDefault();
                                        int?            idBagian  = RepoLookup.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()).Id;
                                        int?            idGrade   = RepoLookup.FindByNameAndCat(workSheet.Cells[rowIterator, 3].Value.ToString()).Id;
                                        Context.Mekanik dbmekanik = new Context.Mekanik();

                                        if (idGrade.HasValue && idBagian.HasValue)
                                        {
                                            dbmekanik.NamaMekanik  = namaMekaniks;
                                            dbmekanik.IdBagian     = idBagian;
                                            dbmekanik.IdGrade      = idGrade;
                                            dbmekanik.Keterampilan = workSheet.Cells[rowIterator, 4].Value == null ? "" : workSheet.Cells[rowIterator, 4].Value.ToString();

                                            RepoMekanik.save(dbmekanik);
                                        }
                                    }
                                    else
                                    {
                                        // update existing row
                                        Context.Mekanik dbmekanik = RepoMekanik.FindByPK(int.Parse(workSheet.Cells[rowIterator, 5].Value.ToString()));
                                        dbmekanik.NamaMekanik  = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        dbmekanik.IdBagian     = RepoLookup.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()).Id;
                                        dbmekanik.IdGrade      = RepoLookup.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id;
                                        dbmekanik.Keterampilan = workSheet.Cells[rowIterator, 4].Value.ToString();
                                        RepoMekanik.save(dbmekanik);
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
        public ActionResult Edit(SettlementBatal model)
        {
            if (ModelState.IsValid)
            {
                Context.SettlementBatal dbitem = RepoSettlementBatal.FindByPK(model.Id);
                if (dbitem.IdSoKontrak == "" || dbitem.IdSoKontrak == null)
                {
                    Context.SalesOrder     dbso      = RepoSalesOrder.FindByPK(model.IdSalesOrder.Value);
                    Context.AdminUangJalan db        = RepoAdminUangJalan.FindByPK(dbso.AdminUangJalanId.Value);
                    Context.ERPConfig      erpConfig = RepoERPConfig.FindByFrist();
                    dbitem.Code = "SB-" + (dbso.SalesOrderOncallId.HasValue ? dbso.SalesOrderOncall.SONumber : dbso.SalesOrderProsesKonsolidasiId.HasValue ?
                                           dbso.SalesOrderProsesKonsolidasi.SONumber : dbso.SalesOrderPickupId.HasValue ? dbso.SalesOrderPickup.SONumber : dbso.SalesOrderKontrak.SONumber);
                    model.SetDb(dbitem);

                    //Jurnal Pengembalian Uang Jalan //(uang, dll dikembalikan utuh), mau utuh mau ngga, nominal cash yg dikembalikan mah ambil dari form :p
                    decimal nominalHutangUangJalanDriver = (model.KasAktual == null ? 0 : model.KasAktual.Value) + (model.TransferAktual == null ? 0 : model.TransferAktual.Value);
                    decimal nomDiakui  = (model.KasDiakui == null ? 0 : model.KasDiakui.Value) + (model.TransferDiakui == null ? 0 : model.TransferDiakui.Value) + (model.SolarDiakui == null ? 0 : model.SolarDiakui.Value) + (model.KapalDiakui == null ? 0 : model.KapalDiakui.Value);
                    decimal nomSelisih = (dbitem.KasSelisih == null ? 0 : dbitem.KasSelisih.Value) + (dbitem.TransferSelisih == null ? 0 : dbitem.TransferSelisih.Value) + (dbitem.KapalSelisih == null ? 0 : dbitem.KapalSelisih.Value);

                    nominalHutangUangJalanDriver += decimal.Parse(db.AdminUangJalanVoucherSpbu.Select(d => d.Value).Sum().ToString());
                    nominalHutangUangJalanDriver += decimal.Parse(db.AdminUangJalanVoucherKapal.Select(d => d.Value).Sum().ToString());
                    nominalHutangUangJalanDriver += db.KasbonDriver1 == null ? 0 : db.KasbonDriver1.Value;
                    nominalHutangUangJalanDriver += db.KlaimDriver1 == null ? 0 : db.KlaimDriver1.Value;
                    nominalHutangUangJalanDriver += decimal.Parse(db.AdminUangJalanPotonganDriver.Select(d => d.Value).Sum().ToString());
                    decimal?TotalBiaya = nomDiakui;
                    int     idx        = 2;
                    if (nomDiakui > 0)
                    {
                        Repoglt_det.saveFromAc(2, "SB-" + dbso.SalesOrderOncall.SONumber, nomDiakui, 0, Repoac_mstr.FindByPk(erpConfig.IdBiayaBatalJalan));//BIAYA BATAL JALAN
                    }
                    foreach (Context.AdminUangJalanVoucherSpbu aujvs in db.AdminUangJalanVoucherSpbu)
                    {
                        idx++;
                        if (model.SPBUKembali != null && model.SPBUKembali.Contains(aujvs.Keterangan))                                                                                //jurnal balik, ga jadi hutangnya
                        {
                            Repoglt_det.saveFromAc(idx, "SB-" + dbso.SalesOrderOncall.SONumber, aujvs.Value, 0, Repoac_mstr.FindByPk(RepoLookup.FindByName(aujvs.Keterangan).ac_id)); //HUTANG SPBU 34.171.04 Pangkalan 2 dan atau
                            TotalBiaya += aujvs.Value;
                        }
                        else //jadi hutang SPBU, masuk ke AP Inv
                        {
                            string           a        = aujvs.Keterangan;
                            string           username = UserPrincipal.username;
                            int?             vend     = RepoLookup.FindByName(aujvs.Keterangan).VendorId;
                            int              vendorId = RepoLookup.FindByName(aujvs.Keterangan).VendorId.Value;
                            Context.Customer cust     = RepoCustomer.FindByPK(RepoLookup.FindByName(aujvs.Keterangan).VendorId.Value);
                            Repogr_mstr.save(aujvs.Value, cust, username, dbitem.Code);
                        }
                    }
                    Repoglt_det.saveFromAc(idx, "SB-" + dbso.SalesOrderOncall.SONumber, dbitem.SolarSelisih, 0, Repoac_mstr.FindByPk(erpConfig.IdPiutangDriverBatalJalanSementaraSolar));
                    TotalBiaya += dbitem.SolarSelisih;
                    if (dbitem.KapalAktual > 0)
                    {
                        foreach (Context.AdminUangJalanVoucherKapal aujvs in db.AdminUangJalanVoucherKapal)
                        {
                            idx++;
                            Repoglt_det.saveFromAc(idx, "SB-" + dbso.SalesOrderOncall.SONumber, aujvs.Value, 0, Repoac_mstr.FindByPk(RepoLookup.FindByName(aujvs.Keterangan).ac_id));//HUTANG SPBU 34.171.04 Pangkalan 2 dan atau
                            TotalBiaya += aujvs.Value;
                        }
                    }
//                if (nomSelisih > 0){
                    idx++;
                    Repoglt_det.saveFromAc(idx, "SB-" + dbso.SalesOrderOncall.SONumber, nomSelisih, 0, Repoac_mstr.FindByPk(erpConfig.IdPiutangDriverBatalJalan), "Selisih Kas/Transfer/Kapal");//PIUTANG DRIVER BATAL JALAN
                    TotalBiaya += nomSelisih;
                    //              }
                    //mau utuh mau ngga, nominal cash yg dikembalikan mah ambil dari form :p
                    Repoglt_det.saveFromAc(2, "SB-" + dbso.SalesOrderOncall.SONumber, model.KasAktual, 0, Repoac_mstr.FindByPk(RepoMasterPool.FindByIPAddress().IdCreditCash)); //BCA Audy 386-7957777 atau
                    Repoglt_det.saveFromAc(2, "SB-" + dbso.SalesOrderOncall.SONumber, model.TransferAktual, 0, Repoac_mstr.FindByPk(dbitem.IdCreditTf));                        //BCA Audy 386-7957777 atau
                    TotalBiaya += (model.KasAktual + model.TransferAktual);
                    Repoglt_det.saveFromAc(1, "SB-" + dbso.SalesOrderOncall.SONumber, 0, TotalBiaya, Repoac_mstr.FindByPk(erpConfig.IdAUJCredit));                              //Hutang Uang Jalan Driver

                    RepoSettlementBatal.save(dbitem, UserPrincipal.id, "Settlement Batal");
                    try {//masuklah ke saldo piutang driver, save to pby_mstr&det
                        var glt_oid = Guid.NewGuid().ToString();
                        Repopbyd_det.saveMstr(glt_oid, dbitem.Code, erpConfig.IdAUJCredit.Value, "Settlement Batal " + dbitem.Code, db.IdDriver1.Value + 7000000);
                        Repopbyd_det.save(
                            glt_oid, dbitem.Code, erpConfig.IdAUJCredit.Value, "Settlement Batal " + dbitem.Code, db.IdDriver1.Value + 7000000,
                            erpConfig.IdAUJCredit.Value, Repoac_mstr.FindByPk(erpConfig.IdAUJCredit).ac_name, 0
                            );
                    }
                    catch (Exception e) {}
                }
                else
                {
                    Context.SalesOrder dbso = RepoSalesOrder.FindByPK(model.IdSalesOrder.Value);
                    Context.SalesOrderKontrakListSo dbKontrak = dbso.SalesOrderKontrak.SalesOrderKontrakListSo.Where(d => d.Id == int.Parse(dbitem.IdSoKontrak)).FirstOrDefault();
                    Context.AdminUangJalan          db        = RepoAdminUangJalan.FindByPK(dbKontrak.IdAdminUangJalan.Value);
                    Context.ERPConfig erpConfig = RepoERPConfig.FindByFrist();
                    dbitem.Code = "SB-" + (dbso.SalesOrderOncallId.HasValue ? dbso.SalesOrderOncall.SONumber : dbso.SalesOrderProsesKonsolidasiId.HasValue ?
                                           dbso.SalesOrderProsesKonsolidasi.SONumber : dbso.SalesOrderPickupId.HasValue ? dbso.SalesOrderPickup.SONumber : dbso.SalesOrderKontrak.SONumber);
                    model.SetDb(dbitem);

                    //Jurnal Pengembalian Uang Jalan //(uang, dll dikembalikan utuh), mau utuh mau ngga, nominal cash yg dikembalikan mah ambil dari form :p
                    decimal nominalHutangUangJalanDriver = model.KasAktual ?? model.KasAktual.Value + model.TransferAktual ?? model.TransferAktual.Value;
                    decimal nomDiakui  = model.KasDiakui ?? model.KasDiakui.Value + model.TransferDiakui ?? model.TransferDiakui.Value + model.SolarDiakui ?? model.SolarDiakui.Value + model.KapalDiakui ?? model.KapalDiakui.Value;
                    decimal nomSelisih = dbitem.KasSelisih.Value + dbitem.TransferSelisih.Value + dbitem.KapalSelisih.Value;

                    nominalHutangUangJalanDriver += decimal.Parse(db.AdminUangJalanVoucherSpbu.Select(d => d.Value).Sum().ToString());
                    nominalHutangUangJalanDriver += decimal.Parse(db.AdminUangJalanVoucherKapal.Select(d => d.Value).Sum().ToString());
                    nominalHutangUangJalanDriver += db.KasbonDriver1 == null ? 0 : db.KasbonDriver1.Value;
                    nominalHutangUangJalanDriver += db.KlaimDriver1 == null ? 0 : db.KlaimDriver1.Value;
                    nominalHutangUangJalanDriver += decimal.Parse(db.AdminUangJalanPotonganDriver.Select(d => d.Value).Sum().ToString());
                    int idx = 2;
                    Repoglt_det.saveFromAc(1, "SB-" + dbKontrak.NoSo, 0, nominalHutangUangJalanDriver, Repoac_mstr.FindByPk(erpConfig.IdAUJCredit));//Hutang Uang Jalan Driver
                    if (nomDiakui > 0)
                    {
                        Repoglt_det.saveFromAc(2, "SB-" + dbKontrak.NoSo, nomDiakui, 0, Repoac_mstr.FindByPk(erpConfig.IdBiayaBatalJalan));//BIAYA BATAL JALAN
                    }
                    foreach (Context.AdminUangJalanVoucherSpbu aujvs in db.AdminUangJalanVoucherSpbu)
                    {
                        idx++;
                        if (model.SPBUKembali.Contains(aujvs.Keterangan))
                        {
                            Repoglt_det.saveFromAc(idx, "SB-" + dbKontrak.NoSo, aujvs.Value, 0, Repoac_mstr.FindByPk(RepoLookup.FindByName(aujvs.Keterangan).ac_id));//HUTANG SPBU 34.171.04 Pangkalan 2 dan atau
                        }
                        else
                        {
                            Repoglt_det.saveFromAc(idx, "SB-" + dbKontrak.NoSo, aujvs.Value, 0, Repoac_mstr.FindByPk(erpConfig.IdPiutangDriverBatalJalanSementaraSolar), "Voucher SPBU " + aujvs.Keterangan);
                        }
                    }
                    foreach (Context.AdminUangJalanVoucherKapal aujvs in db.AdminUangJalanVoucherKapal)
                    {
                        idx++;
                        Repoglt_det.saveFromAc(idx, "SB-" + dbKontrak.NoSo, aujvs.Value, 0, Repoac_mstr.FindByPk(RepoLookup.FindByName(aujvs.Keterangan).ac_id));//HUTANG SPBU 34.171.04 Pangkalan 2 dan atau
                    }
//                if (nomSelisih > 0){
                    idx++;
                    Repoglt_det.saveFromAc(idx, "SB-" + dbKontrak.NoSo, nomSelisih, 0, Repoac_mstr.FindByPk(erpConfig.IdPiutangDriverBatalJalan), "Selisih Kas/Transfer/Kapal");//PIUTANG DRIVER BATAL JALAN
                    //              }
                    if (db.PotonganB > 0)
                    {
                        idx++;
                        Repoglt_det.saveFromAc(idx, "SB-" + dbKontrak.NoSo, db.PotonganB, 0, Repoac_mstr.FindByPk(erpConfig.IdPiutangDriverBatalJalan));//PIUTANG DRIVER BATAL JALAN
                    }
                    if (db.PotonganP > 0)
                    {
                        idx++;
                        Repoglt_det.saveFromAc(idx, "SB-" + dbKontrak.NoSo, db.PotonganP, 0, Repoac_mstr.FindByPk(erpConfig.IdPiutangDriverPribadi));//PIUTANG DRIVER BATAL JALAN / SEMENTARA TUNAI
                    }
                    if (db.PotonganK > 0)
                    {
                        idx++;
                        Repoglt_det.saveFromAc(idx, "SB-" + dbKontrak.NoSo, db.PotonganK, 0, Repoac_mstr.FindByPk(erpConfig.IdPendapatanPengembalianPiutangDriver));
                    }
                    if (db.PotonganT > 0)
                    {
                        idx++;
                        Repoglt_det.saveFromAc(idx, "SB-" + dbKontrak.NoSo, db.PotonganT, 0, Repoac_mstr.FindByPk(erpConfig.IdTabunganDriver));
                    }

                    //mau utuh mau ngga, nominal cash yg dikembalikan mah ambil dari form :p
                    Repoglt_det.saveFromAc(2, "SB-" + dbKontrak.NoSo, model.KasAktual, 0, Repoac_mstr.FindByPk(RepoMasterPool.FindByIPAddress().IdCreditCash));            //BCA Audy 386-7957777 atau
                    Repoglt_det.saveFromAc(2, "SB-" + dbKontrak.NoSo, model.TransferAktual, 0, Repoac_mstr.FindByPk(db.AdminUangJalanUangTf.FirstOrDefault().IdCreditTf)); //BCA Audy 386-7957777 atau

                    RepoSettlementBatal.save(dbitem, UserPrincipal.id, "Settlement Batal");
                    try {//masuklah ke saldo piutang driver, save to pby_mstr&det
                        var glt_oid = Guid.NewGuid().ToString();
                        Repopbyd_det.saveMstr(glt_oid, dbitem.Code, erpConfig.IdAUJCredit.Value, "Settlement Batal " + dbitem.Code, db.IdDriver1.Value + 7000000);
                        Repopbyd_det.save(
                            glt_oid, dbitem.Code, erpConfig.IdAUJCredit.Value, "Settlement Batal " + dbitem.Code, db.IdDriver1.Value + 7000000,
                            erpConfig.IdAUJCredit.Value, Repoac_mstr.FindByPk(erpConfig.IdAUJCredit).ac_name, 0
                            );
                    }
                    catch (Exception e) {}
                }
                return(RedirectToAction("Index"));
            }

            return(View("Form", model));
        }
Beispiel #20
0
        public string Upload(IEnumerable <HttpPostedFileBase> files)
        {
            ResponeModel response = new ResponeModel();

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

                            //sheet 1
                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                if (workSheet.Cells[rowIterator, 1].Value != null && workSheet.Cells[rowIterator, 2].Value != null && workSheet.Cells[rowIterator, 3].Value != null &&
                                    workSheet.Cells[rowIterator, 4].Value != null && workSheet.Cells[rowIterator, 5].Value != null)
                                {
                                    int id = 0;

                                    int resId;
                                    if (workSheet.Cells[rowIterator, 6].Value != null)
                                    {
                                        if (int.TryParse(workSheet.Cells[rowIterator, 6].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }
                                    //cara gancang ngarah teu kudu aya pengecekan tiap field
                                    Context.VendorGps dbitem = new Context.VendorGps();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoVendor.FindByPK(id);
                                        }

                                        dbitem.Nama   = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        dbitem.Alamat = workSheet.Cells[rowIterator, 2].Value.ToString();
                                        dbitem.Telp   = workSheet.Cells[rowIterator, 3].Value.ToString();
                                        dbitem.Email  = workSheet.Cells[rowIterator, 4].Value.ToString();
                                        dbitem.Web    = workSheet.Cells[rowIterator, 5].Value.ToString();

                                        RepoVendor.save(dbitem, UserPrincipal.id);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }

                            //sheet 2
                            workSheet = currentSheet.Where(s => s.Index == 2).FirstOrDefault();
                            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 && workSheet.Cells[rowIterator, 3].Value != null &&
                                    workSheet.Cells[rowIterator, 4].Value != null && workSheet.Cells[rowIterator, 5].Value != null)
                                {
                                    if (workSheet.Cells[rowIterator, 6].Value.ToString() != null && workSheet.Cells[rowIterator, 7].Value.ToString() != null)
                                    {
                                        //edit
                                        try
                                        {
                                            Context.VendorGps db  = RepoVendor.FindByPK(int.Parse(workSheet.Cells[rowIterator, 6].Value.ToString()));
                                            int            iditem = int.Parse(workSheet.Cells[rowIterator, 7].Value.ToString());
                                            Context.Kontak dbitem = db.ListKontak.Where(d => d.Id == iditem).FirstOrDefault();
                                            dbitem.Nama      = workSheet.Cells[rowIterator, 2].Value.ToString();
                                            dbitem.IdJabatan = RepoLookup.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id;
                                            dbitem.Hp        = workSheet.Cells[rowIterator, 4].Value.ToString();
                                            dbitem.Email     = workSheet.Cells[rowIterator, 5].Value.ToString();
                                            RepoVendor.save(db, UserPrincipal.id);
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                    else
                                    {
                                        //add
                                        try
                                        {
                                            Context.VendorGps db     = RepoVendor.FindByPK(int.Parse(workSheet.Cells[rowIterator, 6].Value.ToString()));
                                            Context.Kontak    dbitem = new Context.Kontak();
                                            dbitem.Nama      = workSheet.Cells[rowIterator, 2].Value.ToString();
                                            dbitem.IdJabatan = RepoLookup.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id;
                                            dbitem.Hp        = workSheet.Cells[rowIterator, 4].Value.ToString();
                                            dbitem.Email     = workSheet.Cells[rowIterator, 5].Value.ToString();
                                            db.ListKontak.Add(dbitem);
                                            RepoVendor.save(db, UserPrincipal.id);
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }