public ActionResult IndexForUpdate(string plantName,
                                           string departmentName,
                                           string partId,
                                           string operationName,
                                           int operationId,
                                           double?weight,
                                           double?cost,
                                           int?scrapId = 0)
        {
            ViewBag.departmentName = departmentName;
            ViewBag.plantName      = plantName;
            ViewBag.partId         = partId;
            ViewBag.operationName  = operationName;
            ViewBag.operationId    = operationId;
            ViewBag.unitWeight     = weight;
            ViewBag.unitCost       = cost;
            ViewBag.date           = DateTime.Now;
            ViewBag.scrapId        = 0;

            ScrapViewModel scrapViewModel = new ScrapViewModel();

            scrapViewModel.plantId      = plantName;
            scrapViewModel.departmentId = departmentName;
            scrapViewModel.partId       = partId;
            scrapViewModel.operationId  = operationName;
            scrapViewModel.unitWeight   = weight;
            scrapViewModel.unitCost     = cost;
            scrapViewModel.date         = System.DateTime.Now;
            scrapViewModel.ObjectState  = ObjectState.Added;

            getLisMachinesForEdit(partId, departmentName, operationName);

            return(View(scrapViewModel));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Scrap scrap = _stackpoleContext.Scraps.Find(id);

            if (scrap == null)
            {
                return(HttpNotFound());
            }

            // Get data for dropdownlists
            getListPlants(false);
            getListDepartments(scrap.plantId);
            getListPartsByPlantName(scrap.departmentId);
            getListOperations(scrap.partId, scrap.departmentId);
            getLisMachinesForEdit(scrap.partId, scrap.departmentId, scrap.operationId);

            ScrapViewModel scrapViewModel = ViewModels.Helpers.CreateScrapViewModelFromScrap(scrap);

            scrapViewModel.MessageToClient = string.Format("The original id of Scrap is {0}.", scrapViewModel.id);
            scrapViewModel.date            = System.DateTime.Now;

            if (string.IsNullOrEmpty(scrapViewModel.cancelled))
            {
                scrapViewModel.cancelled = "";
            }

            return(View(scrapViewModel));
        }
        public ActionResult Create()
        {
            ScrapViewModel scrapViewModel = new ScrapViewModel();

            scrapViewModel.date        = System.DateTime.Now;
            scrapViewModel.ObjectState = ObjectState.Added;

            getListPlants();

            return(View(scrapViewModel));
        }
Esempio n. 4
0
        public IQueryable <ScrapViewModel> GetScrapReport(DateTime?dateFrom, DateTime?dateTo, int offset)
        {
            DateTime Datefrom = dateFrom == null ? new DateTime(1970, 1, 1) : (DateTime)dateFrom;
            DateTime Dateto   = dateTo == null ? new DateTime(1970, 1, 1) : (DateTime)dateTo;
            string   DateFrom = Datefrom.ToString("yyyy-MM-dd");
            string   DateTo   = Dateto.ToString("yyyy-MM-dd");
            List <ScrapViewModel> scrapData = new List <ScrapViewModel>();

            try
            {
                string connectionString = APIEndpoint.ConnectionString;
                using (SqlConnection conn =
                           new SqlConnection(connectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand("select HASIL.*,convert(float, (HASIL.SaldoAwal + (HASIL.Pemasukan - HASIL.Pengeluaran))) as SaldoBuku from (select DATA.ClassificationID, DATA.ClassificationCode, DATA.ClassificationName, DATA.StockId, DATA.DestinationId, DATA.UnitQtyName,convert(float,((DATA.saldoIn + DATA.koreksisaldoIn) - (DATA.saldoOut + DATA.koreksisaldoOut))) as SaldoAwal,convert(float,(DATA.transaksiIn + DATA.koreksitransaksiIn)) as Pemasukan,convert(float,(DATA.transaksiOut + DATA.koreksitransaksiOut)) as Pengeluaran,convert(float,0) as Penyesuaian,convert(float,0) as StockOpname,convert(float,0) as Selisih from (select SC.ClassificationID, SC.ClassificationCode, SC.ClassificationName, SS.StockId, SS.DestinationId, UQ.UnitQtyName,(select isnull(SUM(b.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID where a.TransactionType = 'IN' and a.TransactionDate < '" + DateFrom + "' and b.ClassificationID = SC.ClassificationID and a.Destination = SS.DestinationId) as saldoIn,(select isnull(SUM(b.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID where a.TransactionType = 'OUT' and a.TransactionDate < '" + DateFrom + "' and b.ClassificationID = SC.ClassificationID) as saldoOut,(select isnull(SUM(c.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID inner join ScrapCorrectionDetail c on b.DetailID = c.DetailTransactionId inner join ScrapCorrection d on c.CorrectionId = d.CorrectionId where a.TransactionType = 'IN' and d.CorrectionDate < '" + DateFrom + "' and b.ClassificationID = SC.ClassificationID and a.Destination = SS.DestinationId and c.DetailType = 'PLUS') - (select isnull(SUM(c.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID inner join ScrapCorrectionDetail c on b.DetailID = c.DetailTransactionId inner join ScrapCorrection d on c.CorrectionId = d.CorrectionId where a.TransactionType = 'IN' and d.CorrectionDate < '" + DateFrom + "' and b.ClassificationID = SC.ClassificationID and a.Destination = SS.DestinationId and c.DetailType = 'MINUS') as koreksisaldoIn,(select isnull(SUM(c.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID inner join ScrapCorrectionDetail c on b.DetailID = c.DetailTransactionId inner join ScrapCorrection d on c.CorrectionId = d.CorrectionId where a.TransactionType = 'OUT' and d.CorrectionDate < '" + DateFrom + "' and b.ClassificationID = SC.ClassificationID and c.DetailType = 'PLUS')-(select isnull(SUM(c.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID inner join ScrapCorrectionDetail c on b.DetailID = c.DetailTransactionId inner join ScrapCorrection d on c.CorrectionId = d.CorrectionId where a.TransactionType = 'OUT' and d.CorrectionDate < '" + DateFrom + "' and b.ClassificationID = SC.ClassificationID and c.DetailType = 'MINUS') as koreksisaldoOut,(select isnull(SUM(b.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID where a.TransactionType = 'IN' and a.TransactionDate >= '" + DateFrom + "' and a.TransactionDate < dateadd(day, 1, '" + DateTo + "') and b.ClassificationID = SC.ClassificationID and a.Destination = SS.DestinationId) as transaksiIn,(select isnull(SUM(b.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID where a.TransactionType = 'OUT' and a.TransactionDate >= '" + DateFrom + "' and a.TransactionDate < dateadd(day, 1,  '" + DateTo + "') and b.ClassificationID = SC.ClassificationID) as transaksiOut,(select isnull(SUM(c.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID inner join ScrapCorrectionDetail c on b.DetailID = c.DetailTransactionId inner join ScrapCorrection d on c.CorrectionId = d.CorrectionId where a.TransactionType = 'IN' and d.CorrectionDate >= '" + DateFrom + "' and d.CorrectionDate < dateadd(day, 1,'" + DateTo + "') and b.ClassificationID = SC.ClassificationID and a.Destination = SS.DestinationId and c.DetailType = 'PLUS')-(select isnull(SUM(c.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID inner join ScrapCorrectionDetail c on b.DetailID = c.DetailTransactionId inner join ScrapCorrection d on c.CorrectionId = d.CorrectionId where a.TransactionType = 'IN' and d.CorrectionDate >= '" + DateFrom + "' and d.CorrectionDate < dateadd(day, 1,  '" + DateTo + "') and b.ClassificationID = SC.ClassificationID and a.Destination = SS.DestinationId and c.DetailType = 'MINUS') as koreksitransaksiIn,(select isnull(SUM(c.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID inner join ScrapCorrectionDetail c on b.DetailID = c.DetailTransactionId inner join ScrapCorrection d on c.CorrectionId = d.CorrectionId where a.TransactionType = 'OUT' and d.CorrectionDate >= '" + DateFrom + "' and d.CorrectionDate < dateadd(day, 1, '" + DateTo + "') and b.ClassificationID = SC.ClassificationID and c.DetailType = 'PLUS')-(select isnull(SUM(c.Quantity), 0) from ScrapTransaction a inner join ScrapTransactionDetail b on a.TransactionID = b.TransactionID inner join ScrapCorrectionDetail c on b.DetailID = c.DetailTransactionId inner join ScrapCorrection d on c.CorrectionId = d.CorrectionId where a.TransactionType = 'OUT' and d.CorrectionDate >= '" + DateFrom + "' and d.CorrectionDate < dateadd(day, 1,  '" + DateTo + "') and b.ClassificationID = SC.ClassificationID and c.DetailType = 'MINUS') as koreksitransaksiOut from ScrapClassification SC inner join ScrapStock SS on SC.ClassificationID = SS.ClassificationId inner join UNITQUANTITY UQ on SS.UnitQty = UQ.UnitQtyCode )DATA)HASIL", conn))
                    {
                        SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
                        DataSet        dSet        = new DataSet();
                        dataAdapter.Fill(dSet);
                        foreach (DataRow data in dSet.Tables[0].Rows)
                        {
                            ScrapViewModel view = new ScrapViewModel {
                                ClassificationId   = data["ClassificationId"].ToString(),
                                ClassificationCode = data["ClassificationCode"].ToString(),
                                ClassificationName = data["ClassificationName"].ToString(),
                                DestinationId      = data["DestinationId"].ToString(),
                                Pemasukan          = String.Format("{0:n}", (double)data["Pemasukan"]),
                                Pengeluaran        = String.Format("{0:n}", (double)data["Pengeluaran"]),
                                SaldoAwal          = String.Format("{0:n}", (double)data["SaldoAwal"]),
                                SaldoBuku          = String.Format("{0:n}", (double)data["SaldoBuku"]),
                                UnitQtyName        = data["UnitQtyName"].ToString(),
                                Penyesuaian        = String.Format("{0:n}", (double)data["Penyesuaian"]),
                                StockOpname        = String.Format("{0:n}", (double)data["StockOpname"]),
                                Selisih            = String.Format("{0:n}", (double)data["Selisih"]),
                                StockId            = data["StockId"].ToString()
                            };
                            scrapData.Add(view);
                        }
                    }
                    conn.Close();
                }
            }
            catch (SqlException ex)
            {
                //Log exception
                //Display Error message
            }

            return(scrapData.AsQueryable());
        }
        public JsonResult Save(ScrapViewModel scrapViewModel)
        {
            Scrap scrap = ViewModels.Helpers.CreateScrapFromScrapViewModel(scrapViewModel);

            scrap.date = DateTime.UtcNow;

            _stackpoleContext.Scraps.Attach(scrap);

            if (scrap.ObjectState == ObjectState.Deleted)
            {
                foreach (ScrapDetailViewModel scrapDetailViewModel in scrapViewModel.ScrapDetails)
                {
                    ScrapDetail scrapDetail = _stackpoleContext.ScrapDetails.Find(scrapDetailViewModel.id);
                    if (scrapDetail != null)
                    {
                        scrapDetail.ObjectState = ObjectState.Deleted;
                    }
                }
            }
            else
            {
                foreach (int scrapDetailID in scrapViewModel.ScrapDetailsToDelete)
                {
                    ScrapDetail scrapDetail = _stackpoleContext.ScrapDetails.Find(scrapDetailID);
                    if (scrapDetail != null)
                    {
                        scrapDetail.ObjectState = ObjectState.Deleted;
                    }
                }
            }

            _stackpoleContext.ApplyStateChanges();
            _stackpoleContext.SaveChanges();

            if (scrap.ObjectState == ObjectState.Deleted)
            {
                return(Json(new { newLocation = "/Scraps/Index/" }));
            }

            string messageToClient = ViewModels.Helpers.GetMessageToClient(scrapViewModel.ObjectState, scrap.id.ToString());

            scrapViewModel = ViewModels.Helpers.CreateScrapViewModelFromScrap(scrap);
            scrapViewModel.MessageToClient = messageToClient;

            return(Json(new { scrapViewModel }));
            //var json = Newtonsoft.Json.JsonConvert.SerializeObject(scrapViewModel);
            //return Json(new { json });

            // to convert date format from Microsoft JSON format to normal JSON
            //return new CustomJsonResult { Data = new { scrapViewModel } };
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Scrap scrap = _stackpoleContext.Scraps.Find(id);

            if (scrap == null)
            {
                return(HttpNotFound());
            }

            ScrapViewModel scrapViewModel = ViewModels.Helpers.CreateScrapViewModelFromScrap(scrap);

            scrapViewModel.MessageToClient = "I originated from the viewmodel, rather than the model.";

            return(View(scrapViewModel));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Scrap scrap = _stackpoleContext.Scraps.Find(id);

            if (scrap == null)
            {
                return(HttpNotFound());
            }

            ScrapViewModel scrapViewModel = ViewModels.Helpers.CreateScrapViewModelFromScrap(scrap);

            scrapViewModel.MessageToClient = "You are about to permanently delete this scrap.";
            scrapViewModel.ObjectState     = ObjectState.Deleted;

            return(View(scrapViewModel));
        }