Ejemplo n.º 1
0
        private bool ValidateBrandCe(string plantWerk, string faCode, string brandCe, out List <string> message,
                                     out ZAIDM_EX_BRAND brandData)
        {
            brandData = null;
            var valResult   = false;
            var messageList = new List <string>();

            #region ----------BrandCE Validation--------------

            if (!string.IsNullOrWhiteSpace(brandCe))
            {
                brandData = _brandRegistrationBll.GetBrandCe(plantWerk, faCode, brandCe);
                if (brandData == null)
                {
                    messageList.Add("Brand Description [" + brandCe + "] not registered yet in plant [" + plantWerk + "]");
                }
                else
                {
                    valResult = true;
                }
            }
            else
            {
                messageList.Add("Brand Description  is empty");
            }

            #endregion

            message = messageList;
            return(valResult);
        }
Ejemplo n.º 2
0
        private bool ValidateFaCode(string plantWerks, string faCode, out List <string> message,
                                    out ZAIDM_EX_BRAND brandData)
        {
            brandData = null;
            var valResult   = false;
            var messageList = new List <string>();

            #region ----------FA Code Validation--------------

            if (!string.IsNullOrWhiteSpace(faCode))
            {
                brandData = _brandRegistrationBll.GetByFaCode(plantWerks, faCode);
                if (brandData == null)
                {
                    messageList.Add("Finish Goods [" + faCode + "] not valid");
                }
                else
                {
                    valResult = true;
                }
            }
            else
            {
                messageList.Add("Finish Goods Code is empty");
            }

            #endregion

            message = messageList;
            return(valResult);
        }
        public ActionResult Create(BrandRegistrationCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool isExist;
                var  dbBrand = new ZAIDM_EX_BRAND();

                dbBrand = Mapper.Map <ZAIDM_EX_BRAND>(model);
                if (dbBrand.STICKER_CODE.Length > 18)
                {
                    dbBrand.STICKER_CODE = dbBrand.STICKER_CODE.Substring(0, 17);
                }
                dbBrand.FA_CODE         = model.FaCode.Trim();
                dbBrand.STICKER_CODE    = model.StickerCode.Trim();
                dbBrand.CREATED_DATE    = DateTime.Now;
                dbBrand.CREATED_BY      = CurrentUser.USER_ID;
                dbBrand.IS_FROM_SAP     = model.IsFromSAP;
                dbBrand.HJE_IDR         = model.HjeValueStr == null ? 0 : Convert.ToDecimal(model.HjeValueStr);
                dbBrand.TARIFF          = model.TariffValueStr == null ? 0 : Convert.ToDecimal(model.TariffValueStr);
                dbBrand.CONVERSION      = model.ConversionValueStr == null ? 0 : Convert.ToDecimal(model.ConversionValueStr);
                dbBrand.PRINTING_PRICE  = model.PrintingPrice == null ? 0 : Convert.ToDecimal(model.PrintingPriceValueStr);
                dbBrand.STATUS          = model.IsActive;
                dbBrand.PACKED_ADJUSTED = model.IsPackedAdjusted;
                dbBrand.BAHAN_KEMASAN   = string.IsNullOrEmpty(model.BahanKemasan) ? null : model.BahanKemasan.Trim();
                if (!string.IsNullOrEmpty(dbBrand.PER_CODE_DESC))
                {
                    dbBrand.PER_CODE_DESC = model.PersonalizationCodeDescription.Split('-')[1];
                }

                try
                {
                    MASTER_DATA_APPROVAL approvalData;
                    _masterDataAprovalBLL.MasterDataApprovalValidation((int)Enums.MenuList.BrandRegistration,
                                                                       CurrentUser.USER_ID, new ZAIDM_EX_BRAND(), dbBrand, out isExist, out approvalData, true);
                    // AddHistoryCreate(dbBrand.WERKS, dbBrand.FA_CODE, dbBrand.STICKER_CODE);

                    //_brandRegistrationBll.Save(dbBrand);

                    _masterDataAprovalBLL.SendEmailWorkflow(approvalData.APPROVAL_ID);
                    AddMessageInfo(Constans.SubmitMessage.Saved, Enums.MessageInfoType.Success);
                    return(RedirectToAction("Index"));
                }
                catch (BLLException ex)
                {
                    AddMessageInfo(ex.Message, Enums.MessageInfoType.Error);
                }
                catch (Exception)
                {
                    AddMessageInfo("Save Failed.", Enums.MessageInfoType.Error);
                }
            }

            InitCreate(model);

            return(View(model));
        }
 public void Save(ZAIDM_EX_BRAND data)
 {
     _repository.InsertOrUpdate(data);
 }
        private void SetChangesLog(ZAIDM_EX_BRAND origin, BrandRegistrationEditViewModel updatedModel)
        {
            var changesData = new Dictionary <string, bool>();

            updatedModel.HjeValue      = updatedModel.HjeValueStr == null ? 0: Convert.ToDecimal(updatedModel.HjeValueStr);
            updatedModel.Tariff        = updatedModel.TariffValueStr == null ? 0 : Convert.ToDecimal(updatedModel.TariffValueStr);
            updatedModel.Conversion    = updatedModel.ConversionValueStr == null ? 0 : Convert.ToDecimal(updatedModel.ConversionValueStr);
            updatedModel.PrintingPrice = updatedModel.PrintingPriceValueStr == null ? 0 : Convert.ToDecimal(updatedModel.PrintingPriceValueStr);


            if (origin.IS_FROM_SAP.HasValue == false || origin.IS_FROM_SAP.Value == false)
            {
                changesData.Add("FACode", origin.FA_CODE == updatedModel.FaCode);
                changesData.Add("PersonalizationCode", origin.PER_CODE == updatedModel.PersonalizationCode);
                changesData.Add("BrandName", origin.BRAND_CE == updatedModel.BrandName);
                changesData.Add("SkepNo", origin.SKEP_NO == updatedModel.SkepNo);
                changesData.Add("SkepDate", origin.SKEP_DATE == updatedModel.SkepDate);
                changesData.Add("ProductCode", origin.PROD_CODE == updatedModel.ProductCode);
                changesData.Add("SeriesId", origin.SERIES_CODE == updatedModel.SeriesId);
                changesData.Add("Content", origin.BRAND_CONTENT == updatedModel.Content);
                changesData.Add("MarketId", origin.MARKET_ID == updatedModel.MarketId);
                changesData.Add("CountryId", origin.COUNTRY == updatedModel.CountryId);
                changesData.Add("HjeValue", origin.HJE_IDR == updatedModel.HjeValue);
                changesData.Add("HjeCurrency", origin.HJE_CURR == updatedModel.HjeCurrency);
                changesData.Add("Tariff", origin.TARIFF == updatedModel.Tariff);
                changesData.Add("TariffCurrency", origin.TARIF_CURR == updatedModel.TariffCurrency);
                changesData.Add("ColourName", origin.COLOUR == updatedModel.ColourName);
                changesData.Add("GoodType", origin.EXC_GOOD_TYP == updatedModel.GoodType);
                changesData.Add("StartDate", origin.START_DATE == updatedModel.StartDate);
                changesData.Add("EndDate", origin.END_DATE == updatedModel.EndDate);
                changesData.Add("Status", origin.STATUS == updatedModel.IsActive);
            }

            changesData.Add("Conversion", origin.CONVERSION == updatedModel.Conversion);
            changesData.Add("CutFilterCode", origin.CUT_FILLER_CODE == updatedModel.CutFillerCode);
            changesData.Add("PRINTING_PRICE", origin.PRINTING_PRICE == updatedModel.PrintingPrice);
            changesData.Add("BahanKemasan", origin.BAHAN_KEMASAN == updatedModel.BahanKemasan);

            foreach (var listChange in changesData)
            {
                if (listChange.Value)
                {
                    continue;
                }
                var changes = new CHANGES_HISTORY();
                changes.FORM_TYPE_ID  = Enums.MenuList.BrandRegistration;
                changes.FORM_ID       = origin.WERKS + origin.FA_CODE + origin.STICKER_CODE;
                changes.FIELD_NAME    = listChange.Key;
                changes.MODIFIED_BY   = CurrentUser.USER_ID;
                changes.MODIFIED_DATE = DateTime.Now;
                switch (listChange.Key)
                {
                case "STICKER_CODE":
                    changes.OLD_VALUE = origin.STICKER_CODE ?? null;
                    changes.NEW_VALUE = updatedModel.StickerCode ?? null;
                    break;

                case "PlantId":
                    changes.OLD_VALUE = _plantBll.GetPlantWerksById(origin.WERKS);
                    changes.NEW_VALUE = _plantBll.GetPlantWerksById(updatedModel.PlantId);
                    break;

                case "FACode":
                    changes.OLD_VALUE = origin.FA_CODE;
                    changes.NEW_VALUE = updatedModel.FaCode;
                    break;

                case "PersonalizationCode":
                    changes.OLD_VALUE = _masterBll.GetPersonalizationDescById(origin.PER_CODE);
                    changes.NEW_VALUE = _masterBll.GetPersonalizationDescById(updatedModel.PersonalizationCode);
                    break;

                case "BrandName":
                    changes.OLD_VALUE = origin.BRAND_CE;
                    changes.NEW_VALUE = updatedModel.BrandName;
                    break;

                case "SkepNo":
                    changes.OLD_VALUE = origin.SKEP_NO;
                    changes.NEW_VALUE = updatedModel.SkepNo;
                    break;

                case "SkepDate":
                    changes.OLD_VALUE = origin.SKEP_DATE == null ? string.Empty : Convert.ToDateTime(origin.SKEP_DATE).ToString("dd MMM yyyy");
                    changes.NEW_VALUE = updatedModel.SkepDate.ToString("dd MMM yyyy");
                    break;

                case "ProductCode":
                    changes.OLD_VALUE = _masterBll.GetProductCodeTypeDescById(origin.PROD_CODE);
                    changes.NEW_VALUE = _masterBll.GetProductCodeTypeDescById(updatedModel.ProductCode);
                    break;

                case "SeriesId":
                    changes.OLD_VALUE = _masterBll.GetDataSeriesDescById(origin.SERIES_CODE).ToString();
                    changes.NEW_VALUE = _masterBll.GetDataSeriesDescById(updatedModel.SeriesId).ToString();
                    break;

                case "Content":
                    changes.OLD_VALUE = origin.BRAND_CONTENT == null ? string.Empty : origin.BRAND_CONTENT.ToString();
                    changes.NEW_VALUE = updatedModel.Content == null? string.Empty : updatedModel.Content.ToString();
                    break;

                case "MarketId":
                    changes.OLD_VALUE = _masterBll.GetMarketDescById(origin.MARKET_ID);
                    changes.NEW_VALUE = _masterBll.GetMarketDescById(updatedModel.MarketId);
                    break;

                case "CountryId":
                    changes.OLD_VALUE = origin.COUNTRY;
                    changes.NEW_VALUE = updatedModel.CountryId;
                    break;

                case "HjeValue":
                    changes.OLD_VALUE = origin.HJE_IDR.ToString();
                    changes.NEW_VALUE = updatedModel.HjeValue.ToString();
                    break;

                case "HjeCurrency":
                    changes.OLD_VALUE = origin.HJE_CURR;
                    changes.NEW_VALUE = updatedModel.HjeCurrency;
                    break;

                case "Tariff":
                    changes.OLD_VALUE = origin.TARIFF.ToString();
                    changes.NEW_VALUE = updatedModel.Tariff.ToString();
                    break;

                case "TariffCurrency":
                    changes.OLD_VALUE = origin.TARIF_CURR;
                    changes.NEW_VALUE = updatedModel.TariffCurrency;
                    break;

                case "ColourName":
                    changes.OLD_VALUE = origin.COLOUR;
                    changes.NEW_VALUE = updatedModel.ColourName;
                    break;

                case "GoodType":
                    changes.OLD_VALUE = _goodTypeBll.GetGoodTypeDescById(origin.EXC_GOOD_TYP);
                    changes.NEW_VALUE = _goodTypeBll.GetGoodTypeDescById(updatedModel.GoodType);
                    break;

                case "StartDate":
                    changes.OLD_VALUE = origin.START_DATE.HasValue ? origin.START_DATE.Value.ToString("dd MMM yyyy") : string.Empty;
                    changes.NEW_VALUE = updatedModel.StartDate.HasValue? updatedModel.StartDate.Value.ToString("dd MMM yyyy") : string.Empty;
                    break;

                case "EndDate":
                    changes.OLD_VALUE = origin.END_DATE.HasValue ? origin.END_DATE.Value.ToString("dd MMM yyyy"): string.Empty;
                    changes.NEW_VALUE = updatedModel.EndDate.HasValue ? updatedModel.EndDate.Value.ToString("dd MMM yyyy"): string.Empty;
                    break;

                case "Conversion":
                    changes.OLD_VALUE = origin.CONVERSION.ToString();
                    changes.NEW_VALUE = updatedModel.Conversion.ToString();
                    break;

                case "CutFilterCode":
                    changes.OLD_VALUE = origin.CUT_FILLER_CODE;
                    changes.NEW_VALUE = updatedModel.CutFillerCode;
                    break;

                case "Status":
                    changes.OLD_VALUE = origin.STATUS.ToString();
                    changes.NEW_VALUE = updatedModel.IsActive.ToString();
                    break;

                case "PRINTING_PRICE":
                    changes.OLD_VALUE = origin.PRINTING_PRICE.ToString();
                    changes.NEW_VALUE = updatedModel.PrintingPrice.ToString();
                    break;

                case "BahanKemasan":
                    changes.OLD_VALUE = origin.BAHAN_KEMASAN;
                    changes.NEW_VALUE = updatedModel.BahanKemasan;
                    break;
                }
                _changesHistoryBll.AddHistory(changes);
            }
        }
        public ActionResult Edit(BrandRegistrationEditViewModel model)
        {
            ZAIDM_EX_BRAND dbBrand = null;
            bool           isApprovalExist;

            try
            {
                dbBrand = _brandRegistrationBll.GetById(model.PlantId, model.FaCode, model.StickerCode);
            }
            catch (Exception ex)
            {
                dbBrand = null;
            }

            var oldDbBrand = Mapper.Map <BrandRegistrationEditViewModel>(dbBrand);
            var oldObject  = Mapper.Map <ZAIDM_EX_BRAND>(oldDbBrand);

            if (dbBrand == null)
            {
                ModelState.AddModelError("BrandName", "Data Not Found redirected to create form");
                var modelCreate = Mapper.Map <BrandRegistrationCreateViewModel>(model);
                modelCreate = InitCreate(modelCreate);

                return(View("Create", modelCreate));
            }

            SetChangesLog(dbBrand, model);

            //if (dbBrand.IS_FROM_SAP.HasValue && dbBrand.IS_FROM_SAP.Value)
            //{
            //    dbBrand.PRINTING_PRICE = model.PrintingPrice;
            //    dbBrand.CONVERSION = model.Conversion;
            //    dbBrand.CUT_FILLER_CODE = model.CutFillerCode;
            //    dbBrand.STATUS = model.IsActive;
            //}
            //else
            Mapper.Map(model, dbBrand);
            dbBrand.HJE_IDR        = model.HjeValueStr == null ? (decimal?)null : Convert.ToDecimal(model.HjeValueStr);
            dbBrand.TARIFF         = model.TariffValueStr == null ? (decimal?)null : Convert.ToDecimal(model.TariffValueStr);
            dbBrand.CONVERSION     = model.ConversionValueStr == null ? (decimal?)null : Convert.ToDecimal(model.ConversionValueStr);
            dbBrand.PRINTING_PRICE = model.PrintingPriceValueStr == null ? (decimal?)null : Convert.ToDecimal(model.PrintingPriceValueStr);
            dbBrand.FA_CODE        = model.FaCode.Trim();
            dbBrand.STICKER_CODE   = model.StickerCode.Trim();
            dbBrand.BAHAN_KEMASAN  = string.IsNullOrEmpty(model.BahanKemasan) ? null : model.BahanKemasan.Trim();
            //dbBrand.PACKED_ADJUSTED = model.IsPackedAdjusted;
            //dbBrand.BRAND_CE = model.BrandName;
            //dbBrand.IS_FROM_SAP = model.IsFromSAP;
            //dbBrand.CREATED_BY = CurrentUser.USER_ID;
            if (!string.IsNullOrEmpty(model.PersonalizationCodeDescription))
            {
                dbBrand.PER_CODE_DESC = model.PersonalizationCodeDescription;
            }

            var materialData = _materialBll.GetByPlantIdAndStickerCode(model.PlantId, model.FaCode);

            if (materialData == null)
            {
                AddMessageInfo("Fa code and plant not registered on Material Master.", Enums.MessageInfoType.Error);
                model = InitEdit(model);

                return(View("Edit", model));
            }

            try
            {
                MASTER_DATA_APPROVAL approvalData;
                dbBrand = _masterDataAprovalBLL.MasterDataApprovalValidation((int)Enums.MenuList.BrandRegistration,
                                                                             CurrentUser.USER_ID, oldObject, dbBrand, out isApprovalExist, out approvalData);
                _brandRegistrationBll.Save(dbBrand);

                _masterDataAprovalBLL.SendEmailWorkflow(approvalData.APPROVAL_ID);
                AddMessageInfo(Constans.SubmitMessage.Updated, Enums.MessageInfoType.Success);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                AddMessageInfo(ex.Message, Enums.MessageInfoType.Error);
            }

            model = InitEdit(model);

            return(View("Edit", model));
        }
Ejemplo n.º 7
0
        public void Save(ZAIDM_EX_BRAND brandRegistration)
        {
            _repository.InsertOrUpdate(brandRegistration);

            _uow.SaveChanges();
        }
Ejemplo n.º 8
0
        private object UpdateObjectByFormId(MASTER_DATA_APPROVAL approvalData, out bool isDelete)
        {
            PropertyInfo propInfo;

            isDelete = false;
            if (approvalData.PAGE_ID == (int)Enums.MenuList.BrandRegistration)
            {
                var tempId      = approvalData.FORM_ID.Split('-');
                var werks       = tempId[0];
                var facode      = tempId[1];
                var stickerCode = tempId[2];

                var dataBrand = _brandRegistrationBLL.GetByPlantIdAndFaCodeStickerCode(werks, facode, stickerCode);
                if (dataBrand != null)
                {
                    foreach (var detail in approvalData.MASTER_DATA_APPROVAL_DETAIL)
                    {
                        propInfo = typeof(ZAIDM_EX_BRAND).GetProperty(detail.COLUMN_NAME);
                        dataBrand.GetType()
                        .GetProperty(detail.COLUMN_NAME)
                        .SetValue(dataBrand, CastPropertyValue(propInfo, detail.NEW_VALUE));
                    }

                    return(null);
                }
                else
                {
                    ZAIDM_EX_BRAND data = new ZAIDM_EX_BRAND();

                    foreach (var detail in approvalData.MASTER_DATA_APPROVAL_DETAIL)
                    {
                        propInfo = typeof(ZAIDM_EX_BRAND).GetProperty(detail.COLUMN_NAME);
                        data.GetType()
                        .GetProperty(detail.COLUMN_NAME)
                        .SetValue(data, CastPropertyValue(propInfo, detail.NEW_VALUE));
                    }

                    return(data);
                }
            }
            else if (approvalData.PAGE_ID == (int)Enums.MenuList.POA)
            {
                var dataPoa = _poaBll.GetById(approvalData.FORM_ID);
                if (dataPoa != null)
                {
                    foreach (var detail in approvalData.MASTER_DATA_APPROVAL_DETAIL)
                    {
                        propInfo = typeof(POA).GetProperty(detail.COLUMN_NAME);
                        dataPoa.GetType()
                        .GetProperty(detail.COLUMN_NAME)
                        .SetValue(dataPoa, CastPropertyValue(propInfo, detail.NEW_VALUE));
                    }

                    return(null);
                }
                else
                {
                    POA data = new POA();

                    foreach (var detail in approvalData.MASTER_DATA_APPROVAL_DETAIL)
                    {
                        propInfo = typeof(POA).GetProperty(detail.COLUMN_NAME);
                        data.GetType()
                        .GetProperty(detail.COLUMN_NAME)
                        .SetValue(data, CastPropertyValue(propInfo, detail.NEW_VALUE));
                    }

                    return(data);
                }
            }
            else if (approvalData.PAGE_ID == (int)Enums.MenuList.POAMap)
            {
                var tempId  = approvalData.FORM_ID.Split('-');
                var poaId   = tempId[0];
                var nppbkc  = tempId[1];
                var plantid = tempId[2];

                var dataPoaMap = _poaMapBLL.GetByNppbckId(nppbkc, plantid, poaId);
                if (dataPoaMap != null)
                {
                    isDelete = approvalData.MASTER_DATA_APPROVAL_DETAIL.Where(x => x.NEW_VALUE == null).Any();
                    if (!isDelete)
                    {
                        foreach (var detail in approvalData.MASTER_DATA_APPROVAL_DETAIL)
                        {
                            propInfo = typeof(POA_MAP).GetProperty(detail.COLUMN_NAME);
                            dataPoaMap.GetType()
                            .GetProperty(detail.COLUMN_NAME)
                            .SetValue(dataPoaMap, CastPropertyValue(propInfo, detail.NEW_VALUE));
                        }
                    }



                    return(null);
                }
                else
                {
                    POA_MAP data = new POA_MAP();

                    foreach (var detail in approvalData.MASTER_DATA_APPROVAL_DETAIL)
                    {
                        propInfo = typeof(POA_MAP).GetProperty(detail.COLUMN_NAME);
                        data.GetType()
                        .GetProperty(detail.COLUMN_NAME)
                        .SetValue(data, CastPropertyValue(propInfo, detail.NEW_VALUE));
                    }

                    return(data);
                }
            }
            else if (approvalData.PAGE_ID == (int)Enums.MenuList.MaterialMaster)
            {
                var tempId         = approvalData.FORM_ID.Split('-');
                var werks          = tempId[0];
                var materialnumber = tempId[1];
                var dataMaterial   = _materialBLL.GetByMaterialAndPlantId(materialnumber, werks);
                if (dataMaterial != null)
                {
                    foreach (var detail in approvalData.MASTER_DATA_APPROVAL_DETAIL)
                    {
                        if (detail.COLUMN_NAME == "CONVERTION")
                        {
                            var materialUoms = detail.NEW_VALUE.Split(',');
                            var uomList      = new List <MATERIAL_UOM>();
                            foreach (var detailConvertion in materialUoms)
                            {
                                if (string.IsNullOrEmpty(detailConvertion))
                                {
                                    continue;
                                }
                                var convertionVal = decimal.Parse(detailConvertion.Trim().Split(' ')[0]);
                                var convertionUom = detailConvertion.Trim().Split(' ')[1];
                                //if (dataMaterial.MATERIAL_UOM.Any(x => x.MEINH == convertionUom))
                                //{
                                //    uomList.FirstOrDefault(x => x.MEINH == convertionUom).UMREN = convertionVal;
                                //}
                                //else
                                //{
                                uomList.Add(new MATERIAL_UOM()
                                {
                                    STICKER_CODE = dataMaterial.STICKER_CODE,
                                    WERKS        = dataMaterial.WERKS,
                                    UMREN        = convertionVal,
                                    MEINH        = convertionUom
                                });

                                //}
                            }
                            dataMaterial.MATERIAL_UOM = uomList;

                            continue;
                        }
                        propInfo = typeof(ZAIDM_EX_MATERIAL).GetProperty(detail.COLUMN_NAME);
                        dataMaterial.GetType().GetProperty(detail.COLUMN_NAME).SetValue(dataMaterial, CastPropertyValue(propInfo, detail.NEW_VALUE));

                        if (detail.COLUMN_NAME == "CLIENT_DELETION")
                        {
                            var materialClientDto = Mapper.Map <MaterialDto>(dataMaterial);
                            _materialBLL.ClientDeletion(materialClientDto, approvalData.APPROVED_BY);
                        }
                        else if (detail.COLUMN_NAME == "PLANT_DELETION")
                        {
                            var materialPlantDto = Mapper.Map <MaterialDto>(dataMaterial);
                            _materialBLL.ClientDeletion(materialPlantDto, approvalData.APPROVED_BY);
                        }
                    }
                    return(null);
                }
                else
                {
                    ZAIDM_EX_MATERIAL data = new ZAIDM_EX_MATERIAL();

                    foreach (var detail in approvalData.MASTER_DATA_APPROVAL_DETAIL)
                    {
                        if (detail.COLUMN_NAME == "CONVERTION")
                        {
                            continue;
                        }
                        propInfo = typeof(ZAIDM_EX_MATERIAL).GetProperty(detail.COLUMN_NAME);
                        data.GetType()
                        .GetProperty(detail.COLUMN_NAME)
                        .SetValue(data, CastPropertyValue(propInfo, detail.NEW_VALUE));
                    }


                    //convertion add
                    var firstOrDefault = approvalData.MASTER_DATA_APPROVAL_DETAIL.Where(x => x.COLUMN_NAME == "CONVERTION").Select(x => x.NEW_VALUE).FirstOrDefault();
                    if (firstOrDefault != null)
                    {
                        var detailConvertions = firstOrDefault.Split(',');
                        data.MATERIAL_UOM = new Collection <MATERIAL_UOM>();
                        foreach (var detailConvertion in detailConvertions)
                        {
                            data.MATERIAL_UOM.Add(new MATERIAL_UOM()
                            {
                                STICKER_CODE = data.STICKER_CODE,
                                WERKS        = data.WERKS,
                                UMREN        = decimal.Parse(detailConvertion.Trim().Split(' ')[0]),
                                MEINH        = detailConvertion.Trim().Split(' ')[1]
                            });
                        }
                    }

                    return(data);
                }
            }

            return(null);
        }
Ejemplo n.º 9
0
        public List <WasteUploadItemsOuput> ValidationWasteUploadDocumentProcess(List <WasteUploadItemsInput> inputs)
        {
            var messageList = new List <string>();
            var outputList  = new List <WasteUploadItemsOuput>();

            foreach (var inputItem in inputs)
            {
                messageList.Clear();
                var output = Mapper.Map <WasteUploadItemsOuput>(inputItem);

                output.IsValid = true;

                var checkCountdataWasteProduction =
                    inputs.Where(
                        c =>
                        c.CompanyCode == output.CompanyCode && c.PlantWerks == output.PlantWerks &&
                        c.FaCode == output.FaCode && c.WasteProductionDate == output.WasteProductionDate).ToList();

                if (checkCountdataWasteProduction.Count > 1)
                {
                    //Existing Waste Production data
                    output.IsValid = false;
                    messageList.Add("Duplicate Waste Production Data  [" + output.CompanyCode + ", " + output.PlantWerks + ", "
                                    + output.FaCode + ", " + output.WasteProductionDate + "]");
                }

                List <string> messages;

                #region -------------- Company Code Validation ---------------

                T001 companyTypedata = null;
                if (ValidateCompanyCode(output.CompanyCode, out messages, out companyTypedata))
                {
                    output.CompanyCode = companyTypedata.BUKRS;
                }
                else
                {
                    output.IsValid = false;
                    messageList.AddRange(messages);
                }
                #endregion

                #region -------------- Plant Code Validation ---------------

                Plant plantTypeData = null;
                if (ValidationPlantCode(output.PlantWerks, out messages, out plantTypeData))
                {
                    output.PlantWerks = plantTypeData.WERKS;
                }
                else
                {
                    output.IsValid = false;
                    messageList.AddRange(messages);
                }

                #endregion

                #region -------------- Fa Code Vlidation ------------------

                ZAIDM_EX_BRAND brandTypeData = null;
                if (ValidationFaCode(output.PlantWerks, output.FaCode, out messages, out brandTypeData))
                {
                    output.FaCode = brandTypeData.FA_CODE;
                }
                else
                {
                    output.IsValid = false;
                    messageList.AddRange(messages);
                }
                #endregion

                #region ------------ Brand Description Validation -----------------

                if (ValidationBrandCe(output.PlantWerks, output.FaCode, output.BrandDescription, out messages, out brandTypeData))
                {
                    output.BrandDescription = brandTypeData.BRAND_CE;
                }
                else
                {
                    output.IsValid = false;
                    messageList.AddRange(messages);
                }
                #endregion

                #region ---------------Waste Production Date validation-------------
                int temp;
                if (Int32.TryParse(output.WasteProductionDate, out temp))
                {
                    try
                    {
                        output.WasteProductionDate = DateTime.FromOADate(Convert.ToDouble(output.WasteProductionDate)).ToString("dd MMM yyyy");
                    }
                    catch (Exception)
                    {
                        messageList.Add("Waste Production Date [" + output.WasteProductionDate + "] not valid");
                    }
                }
                else
                {
                    messageList.Add("Waste Production Date [" + output.WasteProductionDate + "] not valid");
                }
                #endregion

                #region -----------MarkerRejectStickQty Validation-------------

                decimal tempDecimal;
                if (decimal.TryParse(output.MarkerRejectStickQty, out tempDecimal) || output.MarkerRejectStickQty == "" || output.MarkerRejectStickQty == "-")
                {
                    output.MarkerRejectStickQty = output.MarkerRejectStickQty == "" || output.MarkerRejectStickQty == "-" ? "0" : output.MarkerRejectStickQty;
                }
                else
                {
                    output.MarkerRejectStickQty = output.MarkerRejectStickQty;
                    messageList.Add("Marker Reject Stick Qty [" + output.MarkerRejectStickQty + "] not valid");
                }
                #endregion

                #region -----------PackerRejectStickQty Validation-------------
                if (decimal.TryParse(output.PackerRejectStickQty, out tempDecimal) || output.PackerRejectStickQty == "" || output.PackerRejectStickQty == "-")
                {
                    output.PackerRejectStickQty = output.PackerRejectStickQty == "" || output.PackerRejectStickQty == "-" ? "0" : output.PackerRejectStickQty;
                }
                else
                {
                    output.PackerRejectStickQty = output.PackerRejectStickQty;
                    messageList.Add("Packer Reject Stick Qty [" + output.PackerRejectStickQty + "] not valid");
                }
                #endregion

                #region -----------DustWasteGramQty Validation-------------
                if (decimal.TryParse(output.DustWasteGramQty, out tempDecimal) || output.DustWasteGramQty == "" || output.DustWasteGramQty == "-")
                {
                    output.DustWasteGramQty = output.DustWasteGramQty == "" || output.DustWasteGramQty == "-" ? "0" : output.DustWasteGramQty;
                }
                else
                {
                    output.DustWasteGramQty = output.DustWasteGramQty;
                    messageList.Add("Dust Waste Gram Qty [" + output.DustWasteGramQty + "] not valid");
                }
                #endregion

                #region -----------FloorWasteGramQty Validation-------------
                if (decimal.TryParse(output.FloorWasteGramQty, out tempDecimal) || output.FloorWasteGramQty == "" || output.FloorWasteGramQty == "-")
                {
                    output.FloorWasteGramQty = output.FloorWasteGramQty == "" || output.FloorWasteGramQty == "-" ? "0" : output.FloorWasteGramQty;
                }
                else
                {
                    output.FloorWasteGramQty = output.FloorWasteGramQty;
                    messageList.Add("Floor Waste Gram Qty [" + output.FloorWasteGramQty + "] not valid");
                }
                #endregion

                #region -----------DustWasteStickQty Validation-------------
                //if (decimal.TryParse(output.DustWasteStickQty, out tempDecimal) || output.DustWasteStickQty == "" || output.DustWasteStickQty == "-")
                //{
                //    output.DustWasteStickQty = output.DustWasteStickQty == "" || output.DustWasteStickQty == "-" ? "0" : output.DustWasteStickQty;
                //}
                //else
                //{
                //    output.DustWasteStickQty = output.DustWasteStickQty;
                //    messageList.Add("Dust Waste Stick Qty [" + output.DustWasteStickQty + "] not valid");
                //}
                #endregion

                #region -----------FloorWasteStickQty Validation-------------
                //if (decimal.TryParse(output.FloorWasteStickQty, out tempDecimal) || output.FloorWasteStickQty == "" || output.FloorWasteStickQty == "-")
                //{
                //    output.FloorWasteStickQty = output.FloorWasteStickQty == "" || output.FloorWasteStickQty == "-" ? "0" : output.FloorWasteStickQty;
                //}
                //else
                //{
                //    output.FloorWasteStickQty = output.FloorWasteStickQty;
                //    messageList.Add("Floor Waste stick Qty [" + output.FloorWasteStickQty + "] not valid");
                //}
                #endregion

                #region -----------StampWasteGramQty Validation-------------
                if (decimal.TryParse(output.StampWasteQty, out tempDecimal) || output.StampWasteQty == "" || output.StampWasteQty == "-")
                {
                    output.StampWasteQty = output.StampWasteQty == "" || output.StampWasteQty == "-" ? "0" : output.StampWasteQty;
                }
                else
                {
                    output.StampWasteQty = output.StampWasteQty;
                    messageList.Add("Stem Waste Gram Qty [" + output.StampWasteQty + "] not valid");
                }
                #endregion

                #region --------------Month Closing Validation --------------------

                var param = new MonthClosingGetByParam();
                param.PlantId     = output.PlantWerks;
                param.ClosingDate = Convert.ToDateTime(output.WasteProductionDate);

                var data = _monthClosingBll.GetDataByParam(param);

                if (data != null)
                {
                    messageList.Add("Check Closing Date");
                }

                #endregion

                #region -----------Use For Lack10 Validation-------------
                if (output.UseForLack10.Trim().ToLower() == "yes" || output.UseForLack10.Trim().ToLower() == "no")
                {
                    output.UseForLack10 = output.UseForLack10;
                }
                else
                {
                    output.UseForLack10 = output.UseForLack10;
                    messageList.Add("Use For Lack10 [" + output.UseForLack10 + "] not valid");
                }
                #endregion

                #region -------------- Set Message Info if exists ---------------

                if (messageList.Count > 0)
                {
                    output.IsValid = false;

                    output.Message = "";
                    foreach (var message in messageList)
                    {
                        output.Message += message + ";";
                    }
                }
                else
                {
                    output.Message = string.Empty;
                    output.IsValid = true;
                }

                #endregion


                outputList.Add(output);
            }

            return(outputList);
        }