public bool Save(WasteDto wasteDto, string userId) { var isNewData = true; #region ------get description code----- var company = _companyBll.GetById(wasteDto.CompanyCode); var plant = _plantBll.GetT001WById(wasteDto.PlantWerks); var brandDesc = _brandRegistrationBll.GetById(wasteDto.PlantWerks, wasteDto.FaCode); wasteDto.CompanyName = company.BUTXT; wasteDto.PlantName = plant.NAME1; wasteDto.BrandDescription = brandDesc.BRAND_CE; #endregion var dbWaste = Mapper.Map <WASTE>(wasteDto); dbWaste.MARKER_REJECT_STICK_QTY = wasteDto.MarkerStr == null ? 0 : Convert.ToDecimal(wasteDto.MarkerStr); dbWaste.PACKER_REJECT_STICK_QTY = wasteDto.PackerStr == null ? 0 : Convert.ToDecimal(wasteDto.PackerStr); dbWaste.DUST_WASTE_GRAM_QTY = wasteDto.DustGramStr == null ? 0 : Convert.ToDecimal(wasteDto.DustGramStr); dbWaste.FLOOR_WASTE_GRAM_QTY = wasteDto.FloorGramStr == null ? 0 : Convert.ToDecimal(wasteDto.FloorGramStr); dbWaste.DUST_WASTE_STICK_QTY = wasteDto.DustStickStr == null ? 0 : Convert.ToDecimal(wasteDto.DustStickStr); dbWaste.FLOOR_WASTE_STICK_QTY = wasteDto.FloorStickStr == null ? 0 : Convert.ToDecimal(wasteDto.FloorStickStr); dbWaste.STAMP_WASTE_QTY = wasteDto.StampWasteQtyStr == null ? 0 : Convert.ToDecimal(wasteDto.StampWasteQtyStr); var origin = _repository.GetByID(wasteDto.CompanyCodeX, wasteDto.PlantWerksX, wasteDto.FaCodeX, wasteDto.WasteProductionDateX); var originDto = Mapper.Map <WasteDto>(origin); dbWaste.CREATED_BY = userId; dbWaste.CREATED_DATE = DateTime.Now; if (originDto != null) { SetChange(originDto, wasteDto, userId); isNewData = false; } _repository.InsertOrUpdate(dbWaste); _uow.SaveChanges(); //update waste stock table UpdateWasteStockTable(dbWaste, userId, isNewData); _uow.SaveChanges(); return(isNewData); }
public ActionResult UploadManualWaste(WasteUploadViewModel model) { var modelDto = Mapper.Map <WasteDto>(model); try { var listWaste = new List <WasteUploadItems>(); //check validation foreach (var item in modelDto.UploadItems) { var company = _companyBll.GetById(item.CompanyCode); var plant = _plantBll.GetT001WById(item.PlantWerks); var brandCe = _brandRegistrationBll.GetByFaCode(item.PlantWerks, item.FaCode); if (brandCe == null) { continue; } if (brandCe.IS_DELETED == true || (brandCe.STATUS == false || brandCe.STATUS == null)) { //AddMessageInfo("Data Brand Description Is Inactive", Enums.MessageInfoType.Error); //return RedirectToAction("UploadManualWaste"); continue; } item.CompanyName = company.BUTXT; item.PlantName = plant.NAME1; item.UseForLack10 = item.UseForLack10.ToLower(); if (item.BrandDescription != brandCe.BRAND_CE) { //AddMessageInfo("Data Brand Description Is Not valid", Enums.MessageInfoType.Error); //return RedirectToAction("UploadManualWaste"); continue; } item.CreatedDate = DateTime.Now; item.CreatedBy = CurrentUser.USER_ID; var existingData = _wasteBll.GetExistDto(item.CompanyCode, item.PlantWerks, item.FaCode, Convert.ToDateTime(item.WasteProductionDate)); //if (existingData != null) //{ // AddMessageInfo("Data Already Exist, Please Check Data Company Code, Plant Code, Fa Code, and Production Date", Enums.MessageInfoType.Warning); // return RedirectToAction("UploadManualWaste"); //} listWaste.Add(item); } //do save foreach (var data in listWaste) { _wasteBll.SaveUpload(data, CurrentUser.USER_ID); } if (listWaste.Count == 0) { AddMessageInfo("Error, Data is not Valid", Enums.MessageInfoType.Error); } else { AddMessageInfo(Constans.SubmitMessage.Saved, Enums.MessageInfoType.Success); } } catch (Exception) { AddMessageInfo("Error, Data is not Valid", Enums.MessageInfoType.Error); return(RedirectToAction("UploadManualWaste")); } return(RedirectToAction("Index")); }
public SaveProductionOutput Save(ProductionDto productionDto, string userId) { var output = new SaveProductionOutput(); output.isNewData = true; output.isFromSap = false; #region ----- get description code-------- var company = _companyBll.GetById(productionDto.CompanyCode); var plant = _plantBll.GetT001WById(productionDto.PlantWerks); var brandDesc = _brandRegistrationBll.GetById(productionDto.PlantWerks, productionDto.FaCode); productionDto.CompanyName = company.BUTXT; productionDto.PlantName = plant.NAME1; productionDto.BrandDescription = brandDesc.BRAND_CE; #endregion var dbProduction = Mapper.Map <PRODUCTION>(productionDto); dbProduction.QTY_PACKED = productionDto.QtyPackedStr == null ? 0 : Convert.ToDecimal(productionDto.QtyPackedStr); dbProduction.QTY = productionDto.QtyStr == null ? 0 : Convert.ToDecimal(productionDto.QtyStr); dbProduction.PROD_QTY_STICK = productionDto.ProdQtyStickStr == null ? 0 : Convert.ToDecimal(productionDto.ProdQtyStickStr); dbProduction.ZB = productionDto.ZbStr == null ? 0 : Convert.ToDecimal(productionDto.ZbStr); dbProduction.PACKED_ADJUSTED = productionDto.PackedAdjustedStr == null ? 0 : Convert.ToDecimal(productionDto.PackedAdjustedStr); var origin = _repository.GetByID(productionDto.CompanyCodeX, productionDto.PlantWerksX, productionDto.FaCodeX, Convert.ToDateTime(productionDto.ProductionDateX)); var originDto = Mapper.Map <ProductionDto>(origin); //to do ask and to do refactor if (originDto != null) { SetChange(originDto, productionDto, userId); output.isNewData = false; } if (dbProduction.UOM == "TH") { dbProduction.UOM = "Btg"; //dbProduction.QTY_PACKED = dbProduction.QTY_PACKED * 1000; dbProduction.QTY = dbProduction.QTY * 1000; } var existing = _repository.GetByID(productionDto.CompanyCode, productionDto.PlantWerks, productionDto.FaCode, productionDto.ProductionDate); if (existing != null) { dbProduction.MODIFIED_DATE = DateTime.Now; dbProduction.MODIFIED_BY = userId; dbProduction.CREATED_BY = existing.CREATED_BY; dbProduction.CREATED_DATE = existing.CREATED_DATE; } else { dbProduction.CREATED_DATE = DateTime.Now; dbProduction.CREATED_BY = userId; } if (origin != null) { //dbProduction.CREATED_DATE = origin.CREATED_DATE; //dbProduction.CREATED_BY = origin.CREATED_BY; if (dbProduction.COMPANY_CODE != origin.COMPANY_CODE || dbProduction.WERKS != origin.WERKS || dbProduction.FA_CODE != origin.FA_CODE || Convert.ToDateTime(dbProduction.PRODUCTION_DATE) != Convert.ToDateTime(origin.PRODUCTION_DATE)) { dbProduction.BATCH = null; } if (origin.QTY_PACKED.HasValue && origin.QTY_PACKED != 0) { output.isFromSap = true; } } _repository.InsertOrUpdate(dbProduction); _uow.SaveChanges(); return(output); }
public ActionResult UploadManualProduction(ProductionUploadViewModel model) { var modelDto = Mapper.Map <ProductionDto>(model); try { var listProduction = new List <ProductionUploadItems>(); //check validation foreach (var item in modelDto.UploadItems) { var company = _companyBll.GetById(item.CompanyCode); var plant = _plantBll.GetT001WById(item.PlantWerks); var brandCe = _brandRegistrationBll.GetByFaCode(item.PlantWerks, item.FaCode); if (brandCe == null) { continue; } if (brandCe.IS_DELETED == true || (brandCe.STATUS == false || brandCe.STATUS == null)) { //AddMessageInfo("Data Brand Description Is Inactive", Enums.MessageInfoType.Error); //return RedirectToAction("UploadManualProduction"); continue; } item.QtyPacked = "0"; if (item.Uom == "TH") { item.Uom = "Btg"; //item.QtyPacked = Convert.ToString(Convert.ToDecimal(item.QtyPacked) * 1000); item.Qty = Convert.ToString(Convert.ToDecimal(item.Qty) * 1000); item.Zb = Convert.ToDecimal(item.Zb) * 1000; } if (item.Uom == "KG") { item.Uom = "G"; item.QtyPacked = Convert.ToString(Convert.ToDecimal(item.QtyPacked) * 1000); item.Qty = Convert.ToString(Convert.ToDecimal(item.Qty) * 1000); item.PackedAdjusted = item.PackedAdjusted * 1000; } item.CompanyName = company.BUTXT; item.PlantName = plant.NAME1; if (item.BrandDescription != brandCe.BRAND_CE) { //AddMessageInfo("Data Brand Description Is Not valid", Enums.MessageInfoType.Error); //return RedirectToAction("UploadManualProduction"); continue; } item.CreatedDate = DateTime.Now; item.CreatedBy = CurrentUser.USER_ID; var existingData = _productionBll.GetExistDto(item.CompanyCode, item.PlantWerks, item.FaCode, Convert.ToDateTime(item.ProductionDate)); if (existingData != null) { //AddMessageInfo("Data Already Exist, Please Check Data Company Code," + // " Plant Code, Fa Code, and Waste Production Date", Enums.MessageInfoType.Warning); //return RedirectToAction("UploadManualProduction"); var existItem = Mapper.Map <ProductionUploadItems>(existingData); existItem.Qty = item.Qty; existItem.PackedAdjusted = item.PackedAdjusted; existItem.Zb = item.Zb; existItem.Remark = item.Remark; existItem.ModifiedDate = DateTime.Now; existItem.ModifiedBy = CurrentUser.USER_ID; listProduction.Add(existItem); continue; } listProduction.Add(item); } //do save foreach (var data in listProduction) { _productionBll.SaveUpload(data, CurrentUser.USER_ID); } if (listProduction.Count == 0) { AddMessageInfo("Error, Data is not Valid", Enums.MessageInfoType.Error); } else { AddMessageInfo(Constans.SubmitMessage.Saved, Enums.MessageInfoType.Success); } } catch (Exception) { AddMessageInfo("Error, Data is not Valid", Enums.MessageInfoType.Error); return(RedirectToAction("UploadManualProduction")); } return(RedirectToAction("Index")); }
public JsonResult GetCompanyDetail(string id) { var data = _companyBll.GetById(id); return(Json(data)); }
public CompanyDTO GetById(int id) { return(_CompanyBLL.GetById(id)); }