public object Post(ProductionDto.Product dto) { using (var ds = _daf.OpenDomainAccess()) { return new { SavedId = ProductionDomain.Product.Save(ds,dto) }; } }
public ActionResult Create(ProductionDto dto) { if (!ModelState.IsValid) { TempData["error"] = "Check your input."; return(RedirectToAction(nameof(Create))); } try { executor.ExecuteCommand(addProduction, dto); return(RedirectToAction(nameof(Index))); } catch (EntityNotAllowedException) { return(RedirectToAction("PageNotFound", "Redirections")); } catch (EntityAlreadyExistsException e) { TempData["error"] = e.Message; } catch (Exception e) { TempData["error"] = e.Message; } return(RedirectToAction(nameof(Index))); }
public IActionResult Post([FromBody] ProductionDto dto) { try { addProduction.Execute(dto); return(StatusCode(201)); } catch (EntityAlreadyExistsException e) { return(StatusCode(409, new { Errors = new List <string> { e.Message } })); } catch (Exception e) { return(StatusCode(500, new { Errors = new List <string> { e.Message } })); } }
public static int Save(IDomainAccess ds, ProductionDto.Product dto) { var p = new Product { ProductName = dto.ProductName, ProductCategory = ds.Load<ProductCategory>(dto.ProductCategoryId) }; return (int)ds.Save(p); }
public void Execute(ProductionDto request) { if (Context.Production.Any(p => p.Name.ToLower() == request.Name.ToLower())) { throw new EntityAlreadyExistsException("Production"); } Context.Production.Add(new Production { Name = request.Name }); Context.SaveChanges(); }
private void MoveOldChangeLogHistory(ProductionDto item) { DateTime productionDateX = Convert.ToDateTime(item.ProductionDateX); DateTime productionDate = Convert.ToDateTime(item.ProductionDate); var listHistory = _changeHistoryBll.GetByFormTypeAndFormId(Enums.MenuList.CK4C, "Daily_" + item.CompanyCodeX + "_" + item.PlantWerksX + "_" + item.FaCodeX + "_" + productionDateX.ToString("ddMMMyyyy")); var oldFormId = "Daily_" + item.CompanyCode + "_" + item.PlantWerks + "_" + item.FaCode + "_" + productionDate.ToString("ddMMMyyyy"); foreach (var data in listHistory) { _changeHistoryBll.MoveHistoryToNewData(data, oldFormId); } }
private List <ProductionDto> GetOldSaldo(string company, string plant, string facode, DateTime prodDate, List <REVERSAL> listReversal, List <WASTE> listWaste) { List <ProductionDto> data = new List <ProductionDto>(); var list = _repository.Get(p => p.COMPANY_CODE == company && p.WERKS == plant && p.FA_CODE == facode && p.PRODUCTION_DATE < prodDate).OrderBy(p => p.PRODUCTION_DATE).ToList(); var lastUnpacked = Convert.ToDecimal(0); foreach (var item in list) { //var reversalData = _reversalBll.GetListByParam(item.WERKS, item.FA_CODE, item.PRODUCTION_DATE); var reversalData = listReversal.Where(r => r.WERKS == item.WERKS && r.FA_CODE == item.FA_CODE && r.PRODUCTION_DATE == item.PRODUCTION_DATE); var existReversal = reversalData == null ? 0 : reversalData.Sum(x => x.REVERSAL_QTY.Value); //var wasteData = _wasteBll.GetExistDto(item.COMPANY_CODE, item.WERKS, item.FA_CODE, item.PRODUCTION_DATE); var wasteData = listWaste.Where(w => w.COMPANY_CODE == item.COMPANY_CODE && w.WERKS == item.WERKS && w.FA_CODE == item.FA_CODE && w.WASTE_PROD_DATE == item.PRODUCTION_DATE).FirstOrDefault(); var oldWaste = wasteData == null ? 0 : wasteData.PACKER_REJECT_STICK_QTY; var prodQty = item.QTY == null ? 0 : item.QTY; var packed = item.QTY_PACKED == null ? 0 : item.QTY_PACKED; var prodWaste = oldWaste <= prodQty ? oldWaste : 0; var prod = new ProductionDto { PlantWerks = item.WERKS, FaCode = item.FA_CODE, ProductionDate = item.PRODUCTION_DATE, QtyProduced = prodQty - prodWaste, QtyPacked = (packed - existReversal), QtyUnpacked = lastUnpacked + (prodQty - oldWaste) - (packed - existReversal) }; lastUnpacked = prod.QtyUnpacked == null ? 0 : prod.QtyUnpacked.Value; data.Add(prod); } return(data); }
public ActionResult Edit(int id, ProductionDto dto) { try { dto.Id = id; executor.ExecuteCommand(editProduction, dto); return(RedirectToAction(nameof(Index))); } catch (EntityNotAllowedException) { return(RedirectToAction("PageNotFound", "Redirections")); } catch (EntityAlreadyExistsException e) { TempData["error"] = e.Message; } catch (Exception e) { TempData["error"] = e.Message; } return(RedirectToAction(nameof(Index))); }
public void Execute(ProductionDto request) { var production = Context.Production.Find(request.Id); if (production == null || production.IsDeleted == true) { throw new EntityNotFoundException("Production"); } if (request.Name.ToLower() != production.Name.ToLower() && Context.Production.Any(p => p.Name.ToLower() == request.Name.ToLower())) { throw new EntityAlreadyExistsException("Production"); } if (request.Name == "") { throw new EntityCannotBeNullException("Production"); } production.Name = request.Name; Context.SaveChanges(); }
public IActionResult Put(int id, [FromBody] ProductionDto dto) { try { dto.Id = id; editProduction.Execute(dto); return(StatusCode(204)); } catch (EntityAlreadyExistsException e) { return(StatusCode(409, new { Errors = new List <string> { e.Message } })); } catch (EntityCannotBeNullException e) { return(StatusCode(422, new { Errors = new List <string> { e.Message } })); } catch (Exception e) { return(StatusCode(500, new { Errors = new List <string> { e.Message } })); } }
private bool SetChange(ProductionDto origin, ProductionDto data, string userId) { bool isModified = false; var changeData = new Dictionary <string, bool>(); changeData.Add("COMPANY_CODE", origin.CompanyCode == data.CompanyCode); changeData.Add("WERKS", origin.PlantWerks == data.PlantWerks); changeData.Add("FA_CODE", origin.FaCode == data.FaCode); changeData.Add("PRODUCTION_DATE", origin.ProductionDate == data.ProductionDate); changeData.Add("BRAND_DESC", origin.BrandDescription == data.BrandDescription); changeData.Add("QTY_PACKED", origin.QtyPacked == Convert.ToDecimal(data.QtyPackedStr)); changeData.Add("QTY", origin.Qty == Convert.ToDecimal(data.QtyStr)); changeData.Add("UOM", origin.Uom == data.Uom); //changeData.Add("PROD_QTY_STICK", origin.ProdQtyStick == Convert.ToDecimal(data.ProdQtyStickStr)); string isFromSapString = string.IsNullOrEmpty(origin.Batch) ? "" : "[FROM SAP]"; foreach (var listChange in changeData) { if (listChange.Value) { continue; } { var changes = new CHANGES_HISTORY { FORM_TYPE_ID = Core.Enums.MenuList.CK4C, FORM_ID = "Daily_" + data.CompanyCode + "_" + data.PlantWerks + "_" + data.FaCode + "_" + data.ProductionDate.ToString("ddMMMyyyy"), FIELD_NAME = listChange.Key, MODIFIED_BY = userId, MODIFIED_DATE = DateTime.Now }; switch (listChange.Key) { case "COMPANY_CODE": changes.OLD_VALUE = origin.CompanyCode; changes.NEW_VALUE = data.CompanyCode; changes.FIELD_NAME = "Company" + isFromSapString; break; case "WERKS": changes.OLD_VALUE = origin.PlantWerks; changes.NEW_VALUE = data.PlantWerks; changes.FIELD_NAME = "Plant"; break; case "FA_CODE": changes.OLD_VALUE = origin.FaCode; changes.NEW_VALUE = data.FaCode; changes.FIELD_NAME = "Finish Goods"; break; case "PRODUCTION_DATE": changes.OLD_VALUE = origin.ProductionDate.ToString(); changes.NEW_VALUE = data.ProductionDate.ToString(); changes.FIELD_NAME = "Daily Production Date"; break; case "BRAND_DESC": changes.OLD_VALUE = origin.BrandDescription; changes.NEW_VALUE = data.BrandDescription; changes.FIELD_NAME = "Brand Description"; break; case "QTY_PACKED": changes.OLD_VALUE = origin.QtyPacked.ToString(); changes.NEW_VALUE = data.QtyPackedStr; changes.FIELD_NAME = "Qty Packed" + isFromSapString; break; case "QTY": changes.OLD_VALUE = origin.Qty.ToString(); changes.NEW_VALUE = data.QtyStr; changes.FIELD_NAME = "Produced Qty" + isFromSapString; break; case "UOM": changes.OLD_VALUE = origin.Uom; changes.NEW_VALUE = data.Uom; changes.FIELD_NAME = "Uom"; break; //case "PROD_QTY_STICK": // changes.OLD_VALUE = origin.ProdQtyStick.ToString(); // changes.NEW_VALUE = data.ProdQtyStickStr; // changes.FIELD_NAME = " Produced Qty Stick"; // break; default: break; } _changesHistoryBll.AddHistory(changes); isModified = true; } } return(isModified); }
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 List <ProductionDto> GetCompleteData(List <ProductionDto> listItem, GetOtherProductionByParamInput input) { List <ProductionDto> list = new List <ProductionDto>(); List <ProductionDto> newList = new List <ProductionDto>(); //search editable other brand var prodCode = _repositoryProd.GetQuery().Where(x => x.CK4CEDITABLE == true).Select(x => x.PROD_CODE).ToList(); var plantList = _plantBll.GetAll().Where(x => x.WERKS == input.Plant); var listBrand = _brandRegistrationBll.GetAllBrandsOnly(); if (input.IsNppbkc) { plantList = _plantBll.GetPlantByNppbkc(input.Nppbkc).Distinct(); } DateTime firstDay = new DateTime(input.Year, input.Month, 1); DateTime startDate = firstDay; DateTime endDate = new DateTime(input.Year, input.Month, 14); if (input.Period == 2) { startDate = new DateTime(input.Year, input.Month, 15); endDate = firstDay.AddMonths(1).AddDays(-1); } for (var j = startDate.Day; j <= endDate.Day; j++) { foreach (var item in plantList) { Int32 isInt; var activeBrand = listBrand.Where(x => x.WERKS == item.WERKS && Int32.TryParse(x.BRAND_CONTENT, out isInt) && (x.EXC_GOOD_TYP == "01" || x.EXC_GOOD_TYP == "02") && prodCode.Contains(x.PROD_CODE)); foreach (var data in activeBrand.Distinct()) { var newItem = new ProductionDto(); newItem.CompanyCode = input.Company; newItem.ProductionDate = startDate; newItem.FaCode = data.FA_CODE; newItem.PlantWerks = item.WERKS; newItem.LevelPlant = item.WERKS; newItem.BrandDescription = data.BRAND_CE; newItem.PlantName = item.NAME1; newItem.TobaccoProductType = data.ZAIDM_EX_PRODTYP.PRODUCT_TYPE; newItem.Hje = data.HJE_IDR; newItem.Tarif = data.TARIFF; newItem.QtyPacked = 0; newItem.QtyUnpacked = 0; newItem.QtyProduced = 0; newItem.Uom = data.ZAIDM_EX_PRODTYP.PRODUCT_ALIAS == "TIS" ? "G" : "Btg"; newItem.ProdCode = data.PROD_CODE; newItem.ContentPerPack = Convert.ToInt32(data.BRAND_CONTENT); newItem.PackedInPack = 0; newItem.PackedInPackZb = 0; newItem.IsEditable = true; newItem.Zb = 0; newItem.PackedAdjusted = 0; newList.Add(newItem); } } startDate = startDate.AddDays(1); } var sameData = from a in newList join b in listItem on new { a.ProductionDate, a.FaCode, a.PlantWerks } equals new { b.ProductionDate, b.FaCode, b.PlantWerks } select a; list = newList.Except(sameData).ToList(); list.AddRange(listItem); return(list.OrderBy(x => x.FaCode).OrderBy(x => x.ProductionDate).ToList()); }