/// <summary> /// Add received contract document /// </summary> /// <param name="cond"></param> /// <returns></returns> public ActionResult CTS190_AddReceivedContractDoc(CTS190_ScreenParameter cond) { ObjectResultData res = new ObjectResultData(); res.MessageType = MessageModel.MESSAGE_TYPE.WARNING; CommonUtil cm = new CommonUtil(); IMasterHandler handlerMaster = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler; List <dtDocumentTemplateByDocumentCode> listDocTemplate = new List <dtDocumentTemplateByDocumentCode>(); string contracCode; string quotationTargetCode; try { ICommonContractHandler handler = ServiceContainer.GetService <ICommonContractHandler>() as ICommonContractHandler; List <dtContractDocHeader> list = new List <dtContractDocHeader>(); contracCode = cm.ConvertContractCode(cond.ContractCode_QuotationTargetCode, CommonUtil.CONVERT_TYPE.TO_LONG); quotationTargetCode = cm.ConvertQuotationTargetCode(cond.ContractCode_QuotationTargetCode, CommonUtil.CONVERT_TYPE.TO_LONG); // Check required field. if (ModelState.IsValid == false) { ValidatorUtil.BuildErrorMessage(res, this); if (res.IsError) { return(Json(res)); } } // Business check 1 if (cond.OCC_Alphabet == null) { cond.OCC_Alphabet = string.Empty; } if (!(cond.OCC_Alphabet.ToUpper() == ParticularOCC.C_PARTICULAR_OCC_PO.ToUpper())) //|| cond.OCC_Alphabet.ToUpper() == ParticularOCC.C_PARTICULAR_OCC_START_CONFIRM_LETTER.ToUpper())) //Comment by Jutarat A. on 22042013 { //Then Check "Contract document OCC" field // ---> Then show message at warning section (MSG3234: Please specify contract document occurrence) if (CommonUtil.IsNullOrEmpty(cond.ContractDocOCC) == true) { res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3234, null, new string[] { "ContractDocOCC" }); return(Json(res)); } } // Business check 2 if (CommonUtil.IsNullOrEmpty(cond.ContractDocOCC) == true) // Not fill ContractDocOCC { if (!(cond.OCC_Alphabet.ToUpper() == ParticularOCC.C_PARTICULAR_OCC_PO.ToUpper())) //|| cond.OCC_Alphabet.ToUpper() == ParticularOCC.C_PARTICULAR_OCC_START_CONFIRM_LETTER.ToUpper())) //Comment by Jutarat A. on 22042013 { res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001); return(Json(res)); } //#region Check billing basic data //if (cond.OCC_Alphabet.ToUpper().CompareTo(ParticularOCC.C_PARTICULAR_OCC_MIN_BILLING_MEMO.ToUpper()) >= 0 // && cond.OCC_Alphabet.ToUpper().CompareTo(ParticularOCC.C_PARTICULAR_OCC_MAX_BILLING_MEMO.ToUpper()) <= 0) //{ // string occ = cond.OCC_Alphabet.Trim(); // if (occ.Length > 2) // occ = occ.Substring(occ.Length - 2); // IBillingHandler bhandler = ServiceContainer.GetService<IBillingHandler>() as IBillingHandler; // doTbt_BillingBasic bs = bhandler.GetBillingBasicData(contracCode.Trim(), occ, null, null, null); // if (bs == null) // { // res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3242); // return Json(res); // } //} //#endregion list = handler.GetContractDocHeader(contracCode.Trim(), quotationTargetCode.Trim(), cond.OCC_Alphabet.Trim(), cond.ContractDocOCC); if (list.Count == 0) // not found ! (ContractDoc Header) { //Comment by Jutarat A. on 22042013 //if (cond.OCC_Alphabet.ToUpper() == ParticularOCC.C_PARTICULAR_OCC_START_CONFIRM_LETTER.ToUpper()) //{ // res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001); // return Json(res); //} //End Comment IRentralContractHandler handlerRental = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler; List <tbt_RentalContractBasic> rentalList = handlerRental.GetTbt_RentalContractBasic(contracCode, null); if (rentalList.Count == 0) { res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001); return(Json(res)); } else { // Create dt !! dtContractDocHeader dt = new dtContractDocHeader(); dt.ContractCode = contracCode.ToUpper(); dt.OCC = cond.OCC_Alphabet.Trim().ToUpper(); if (cond.OCC_Alphabet.Trim().ToUpper() == ParticularOCC.C_PARTICULAR_OCC_PO.ToUpper()) { dt.DocumentCode = DocumentCode.C_DOCUMENT_CODE_PO; } //else //{ // dt.DocumentCode = DocumentCode.C_DOCUMENT_CODE_CHANGE_PAYMENT_MEMO; //} listDocTemplate = handlerMaster.GetDocumentTemplateByDocumentCode(dt.DocumentCode); if (listDocTemplate.Count > 0) { dt.DocumentNameEN = listDocTemplate[0].DocumentNameEN; dt.DocumentNameJP = listDocTemplate[0].DocumentNameJP; dt.DocumentNameLC = listDocTemplate[0].DocumentNameLC; } dt.ContractOfficeCode = rentalList[0].ContractOfficeCode; dt.OperationOfficeCode = rentalList[0].OperationOfficeCode; dt.DocStatus = ContractDocStatus.C_CONTRACT_DOC_STATUS_COLLECTED; dt.DocAuditResult = cond.DocAuditResult; dt.CollectDocDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime; // extra field dt.ContractCode_QuotationTargetCode = contracCode.ToUpper(); dt.OCC_Alphabet = cond.OCC_Alphabet.Trim().ToUpper(); dt.IsCreateFlag = true; //*** dt.IsContractFlag = true; //*** list.Clear(); list.Add(dt); } } else // Found !! (ContractDoc Header) { // Update dt !! list[0].IsCreateFlag = false; // is updated list[0].DocStatus = ContractDocStatus.C_CONTRACT_DOC_STATUS_COLLECTED; list[0].DocAuditResult = cond.DocAuditResult; list[0].CollectDocDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime; } } else // ContractDocOCC is filled { list = handler.GetContractDocHeader(contracCode.Trim(), quotationTargetCode.Trim(), cond.OCC_Alphabet.Trim(), cond.ContractDocOCC.Trim()); if (list.Count > 0) { // get Document templete for get "ReportFlag" listDocTemplate = handlerMaster.GetDocumentTemplateByDocumentCode(list[0].DocumentCode); if (listDocTemplate.Count == 0) { res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION; res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0111, new string[] { "Document Template is not found." }, null); return(Json(res)); } // Business check if (CommonUtil.IsNullOrEmpty(list[0].ContractCode) == true) { res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3160); return(Json(res)); } // Business check if (listDocTemplate[0].ReportFlag == true) { if (list[0].DocStatus == ContractDocStatus.C_CONTRACT_DOC_STATUS_NOT_ISSUED || list[0].IssuedDate.HasValue == false) { res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3179); return(Json(res)); } } else { if (list[0].DocStatus == ContractDocStatus.C_CONTRACT_DOC_STATUS_NOT_ISSUED) { res.AddErrorMessage(MessageUtil.MODULE_CONTRACT, MessageUtil.MessageList.MSG3179); return(Json(res)); } } // Update dt !! list[0].IsCreateFlag = false; // is updated list[0].DocStatus = ContractDocStatus.C_CONTRACT_DOC_STATUS_COLLECTED; list[0].DocAuditResult = cond.DocAuditResult; list[0].CollectDocDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime; } } if (list.Count > 0) { // CheckDataAuthority if (CTS190_CheckDataAuthority(list[0]) == false) { res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0063); return(Json(res)); } } else { res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0001); return(Json(res)); } CommonUtil.MappingObjectLanguage <dtContractDocHeader>(list); MiscTypeMappingList miscList = new MiscTypeMappingList(); miscList.AddMiscType(list.ToArray()); ICommonHandler comHandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; comHandler.MiscTypeMappingList(miscList); if (list.Count > 0) { if (list[0].IsContractFlag.Value) { list[0].ContractCode_QuotationTargetCode = cm.ConvertContractCode(list[0].ContractCode_QuotationTargetCode, CommonUtil.CONVERT_TYPE.TO_SHORT); } else { list[0].ContractCode_QuotationTargetCode = cm.ConvertQuotationTargetCode(list[0].ContractCode_QuotationTargetCode, CommonUtil.CONVERT_TYPE.TO_SHORT); } string myContractCode = cm.ConvertContractCode(list[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT); string myOCC = list[0].OCC; string myQuotationTargetCode = cm.ConvertQuotationTargetCode(list[0].QuotationTargetCode, CommonUtil.CONVERT_TYPE.TO_SHORT); string myAlphabet = list[0].Alphabet; string myDocOCC = list[0].ContractDocOCC; if (cond.OCC_Alphabet.ToUpper() == ParticularOCC.C_PARTICULAR_OCC_PO.ToUpper()) { //|| cond.OCC_Alphabet.ToUpper() == ParticularOCC.C_PARTICULAR_OCC_START_CONFIRM_LETTER.ToUpper()) //Comment by Jutarat A. on 22042013 myDocOCC = ""; } // Update my_checked_id_by_ct , my_checked_id_by_quo , my_checked_id list[0].my_checked_id_by_ct = string.Format("{0}-{1}-{2}", myContractCode, myOCC, myDocOCC).ToUpper(); list[0].my_checked_id_by_quo = string.Format("{0}-{1}-{2}", myQuotationTargetCode, myAlphabet, myDocOCC).ToUpper(); list[0].my_checked_id = string.Format("{0}-{1}", list[0].my_checked_id_by_ct, list[0].my_checked_id_by_quo).ToUpper(); res.ResultData = list[0]; } return(Json(res)); } catch (Exception ex) { res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION; res.AddErrorMessage(ex); return(Json(res)); } }