/// <summary>
        /// Confirm billing target data
        /// </summary>
        /// <param name="doTbmBillingClient"></param>
        /// <param name="doTbtBillingTarget"></param>
        /// <returns></returns>
        public ActionResult BLS010_ConfirmBillingTargetData(SECOM_AJIS.DataEntity.Master.tbm_BillingClient doTbmBillingClient, tbt_BillingTarget doTbtBillingTarget)
        //public ActionResult BLS010_ConfirmBillingTargetData(BLS010_ScreenParameter param)
        {
            ObjectResultData res     = new ObjectResultData();
            CommonUtil       comUtil = new CommonUtil();
            IBillingHandler  handler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;

            SECOM_AJIS.DataEntity.Master.IBillingMasterHandler handlerMaster = ServiceContainer.GetService <SECOM_AJIS.DataEntity.Master.IBillingMasterHandler>() as SECOM_AJIS.DataEntity.Master.IBillingMasterHandler;
            string strBillingClientCode = null;
            string strBillingTargetCode = null;

            BLS010_ScreenParameter sParam = GetScreenObject <BLS010_ScreenParameter>();

            // tbm_BillingClient doTbmBillingClient = param.doTbmBillingClientParam;
            // tbt_BillingTarget doTbtBillingTarget = param.doTbt_BillingTarget;
            try
            {
                ///////// Check Suspending //////////
                ICommonHandler chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (chandler.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }


                /////// Check permission //////////
                if (!CheckUserPermission(ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }

                //clone tbtBillingClientData to tbm_billingcliebtData
                doTbmBillingClient = CommonUtil.CloneObject <SECOM_AJIS.DataEntity.Master.dtBillingClientData, SECOM_AJIS.DataEntity.Master.tbm_BillingClient>(sParam.doBillingClient);
                doTbmBillingClient.BillingClientCode = comUtil.ConvertBillingClientCode(doTbmBillingClient.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                doTbtBillingTarget.BillingClientCode = comUtil.ConvertBillingClientCode(doTbtBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG);

                //validatebusiness
                tbt_BillingTarget tmpTbtBillingTarget = new tbt_BillingTarget();
                if (!CommonUtil.IsNullOrEmpty(doTbmBillingClient.BillingClientCode))
                {
                    List <tbt_BillingTarget> lst = new List <tbt_BillingTarget>();
                    lst = handler.GetTbt_BillingTarget(null, doTbmBillingClient.BillingClientCode, doTbtBillingTarget.BillingOfficeCode);
                    if (lst.Count > 0)
                    {
                        tmpTbtBillingTarget = lst[0];
                    }
                    else
                    {
                        tmpTbtBillingTarget = null;
                    }


                    if (tmpTbtBillingTarget != null)
                    {
                        res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;

                        res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                            ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET,
                                            MessageUtil.MODULE_BILLING,
                                            MessageUtil.MessageList.MSG6002,
                                            new string[] { comUtil.ConvertBillingTargetCode(tmpTbtBillingTarget.BillingTargetCode, CommonUtil.CONVERT_TYPE.TO_SHORT) },
                                            null);
                        return(Json(res));
                    }
                }


                var tmpdoTbmBillingClient = CommonUtil.CloneObject <tbm_BillingClient, tbm_BillingClient>(doTbmBillingClient);
                var tmpdoTbtBillingTarget = CommonUtil.CloneObject <tbt_BillingTarget, tbt_BillingTarget>(doTbtBillingTarget);

                //register new billing target
                using (TransactionScope scope = new TransactionScope())
                {
                    //7.3.4
                    if (CommonUtil.IsNullOrEmpty(tmpdoTbtBillingTarget.BillingClientCode))
                    {
                        strBillingClientCode = handlerMaster.ManageBillingClient(tmpdoTbmBillingClient);
                        tmpdoTbtBillingTarget.BillingClientCode = strBillingClientCode;
                    }

                    //7.3.5 create billing target
                    strBillingTargetCode = handler.CreateBillingTarget(tmpdoTbtBillingTarget);
                    tmpdoTbtBillingTarget.BillingTargetCode = comUtil.ConvertBillingClientCode(strBillingTargetCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                    tmpdoTbmBillingClient.BillingClientCode = comUtil.ConvertBillingClientCode(tmpdoTbmBillingClient.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                    scope.Complete();

                    doTbmBillingClient = CommonUtil.CloneObject <tbm_BillingClient, tbm_BillingClient>(tmpdoTbmBillingClient);
                    doTbtBillingTarget = CommonUtil.CloneObject <tbt_BillingTarget, tbt_BillingTarget>(tmpdoTbtBillingTarget);
                }
                doTbtBillingTarget.BillingClientCode = comUtil.ConvertBillingClientCode(doTbtBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                sParam.doTbt_BillingTarget           = doTbtBillingTarget;
                res.ResultData  = doTbtBillingTarget;
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION_OK;
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0046, null, null);
                return(Json(res));
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }
        /// <summary>
        /// Register billing target
        /// </summary>
        /// <param name="doTbtBillingTarget"></param>
        /// <param name="doBillingClientDdata"></param>
        /// <returns></returns>
        public ActionResult BLS010_RegisterData(tbt_BillingTarget doTbtBillingTarget, dtBillingClientData doBillingClientDdata)
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
            ValidatorUtil validator = new ValidatorUtil();
            CommonUtil    comUtil   = new CommonUtil();

            try
            {
                BLS010_ScreenParameter     sParam  = GetScreenObject <BLS010_ScreenParameter>();
                BLS010_ScreenInputValidate obj     = new BLS010_ScreenInputValidate();
                IBillingHandler            handler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
                List <string> lstParam             = new List <string>();
                List <string> lstControl           = new List <string>();

                ///////// Check Suspending //////////
                ICommonHandler chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (chandler.IsSystemSuspending())
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }

                /////// Check permission //////////
                if (!CheckUserPermission(ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }

                //if (sParam.doBillingClientList == null)
                //{
                //    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                //    //res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0007, new string[] { "lblBillingClientCode" }, new string[] { "lblBillingClientCode" });
                //    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                //                     ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET,
                //                     MessageUtil.MODULE_COMMON,
                //                     MessageUtil.MessageList.MSG0007,
                //                     new string[] { "lblBillingClientCode" },
                //                      new string[] { "lblBillingClientCode" });
                //    return Json(res);
                //}
                ////////////////5.2 Check mandatory
                //if (CommonUtil.IsNullOrEmpty(sParam.doBillingClientList[0].BillingClientCode))
                //{
                //    if (CommonUtil.IsNullOrEmpty(sParam.doBillingClientList[0].NameEN))
                //    {
                //        lstParam.Add("lblNameEnglish");
                //        lstControl.Add("FullNameEN");
                //    }
                //    if (CommonUtil.IsNullOrEmpty(sParam.doBillingClientList[0].NameLC))
                //    {
                //        lstParam.Add("lblNameLocal");
                //        lstControl.Add("FullNameEN");
                //    }
                //    if (CommonUtil.IsNullOrEmpty(sParam.doBillingClientList[0].CustTypeCode))
                //    {
                //        lstParam.Add("lblCustTypeCode");
                //        lstControl.Add("CustTypeName");

                //    }
                //}

                // Modify by siripoj 06-06-12
                if (CommonUtil.IsNullOrEmpty(doBillingClientDdata.BillingClientCode))
                {
                    if (CommonUtil.IsNullOrEmpty(doBillingClientDdata.NameEN))
                    {
                        lstParam.Add("lblNameEnglish");
                        lstControl.Add("FullNameEN");
                    }
                    // 2017.02.15 delete matsuda start
                    //if (CommonUtil.IsNullOrEmpty(doBillingClientDdata.NameLC))
                    //{
                    //    lstParam.Add("lblNameLocal");
                    //    lstControl.Add("FullNameLC");
                    //}
                    // 2017.02.15 delete matsuda end
                    if (CommonUtil.IsNullOrEmpty(doBillingClientDdata.CustTypeCode))
                    {
                        lstParam.Add("lblCustTypeCode");
                        lstControl.Add("CustTypeName");
                    }
                }

                if (CommonUtil.IsNullOrEmpty(doTbtBillingTarget.BillingOfficeCode))
                {
                    lstParam.Add("lblBillingOffice");
                    lstControl.Add("BillingOfficeCode");
                }
                if (lstParam.Count > 0 && lstControl.Count > 0)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    // res.AddErrorMessage(MessageUtil.MODULE_BILLING, MessageUtil.MessageList.MSG0007, lstParam.ToArray(), lstControl.ToArray());
                    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                        ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET,
                                        MessageUtil.MODULE_COMMON,
                                        MessageUtil.MessageList.MSG0007,
                                        lstParam.ToArray(),
                                        lstControl.ToArray());
                    return(Json(res));
                }

                //Clone Data
                //obj = CommonUtil.CloneObject<dtBillingClientData, BLS010_ScreenInputValidate>(sParam.doBillingClientList[0]);
                //obj.BillingOfficeCode = doTbtBillingTarget.BillingOfficeCode;

                ////////////////5.2 Check mandatory
                //ValidatorUtil.BuildErrorMessage(res, this, new object[] { obj });
                //if (res.IsError)
                //{

                //    return Json(res);
                //}
                ///////////////5.3 Validate Business
                //doTbtBillingTarget = CommonUtil.CloneObject<dtBillingClientData, tbt_BillingTarget>(sParam.doBillingClientList[0]);

                res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

                // Modify by Siripoj 06-06-12
                //doTbtBillingTarget.BillingClientCode = sParam.doBillingClientList[0].BillingClientCode;
                doTbtBillingTarget.BillingClientCode = doBillingClientDdata.BillingClientCode;

                if (CommonUtil.IsNullOrEmpty(doTbtBillingTarget.IssueInvMonth))
                {
                    doTbtBillingTarget.IssueInvMonth = 0;
                }
                if (doTbtBillingTarget.IssueInvMonth > 60)
                {
                    //res.AddErrorMessage(MessageUtil.MODULE_BILLING, MessageUtil.MessageList.MSG6001, new string[] { "IssueInvTime" }, new string[] { "IssueInvTime" });
                    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                        ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET,
                                        MessageUtil.MODULE_BILLING,
                                        MessageUtil.MessageList.MSG6001,
                                        new string[] { "lblIssueInvoiceTiming" },
                                        new string[] { "IssueInvMonth" });
                    return(Json(res));
                }
                if (!CommonUtil.IsNullOrEmpty(doTbtBillingTarget.BillingClientCode))
                {
                    List <tbt_BillingTarget> lst = new List <tbt_BillingTarget>();
                    lst = handler.GetTbt_BillingTarget(null, comUtil.ConvertBillingClientCode(doTbtBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG), doTbtBillingTarget.BillingOfficeCode);
                    if (lst.Count > 0)
                    {
                        doTbtBillingTarget = lst[0];
                    }
                    else
                    {
                        doTbtBillingTarget = null;
                    }
                    //doTbtBillingTarget = handler.GetTbt_BillingTarget(null, comUtil.ConvertBillingClientCode(doTbtBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG), doTbtBillingTarget.BillingOfficeCode);
                    if (doTbtBillingTarget != null)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                            ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET,
                                            MessageUtil.MODULE_BILLING,
                                            MessageUtil.MessageList.MSG6002,
                                            new string[] { comUtil.ConvertBillingTargetCode(doTbtBillingTarget.BillingTargetCode, CommonUtil.CONVERT_TYPE.TO_SHORT) },
                                            new string[] { "BillingClientCodeView" });
                        return(Json(res));
                    }
                }
                res.ResultData             = true;
                sParam.doBillingClient     = doBillingClientDdata;
                sParam.doTbt_BillingTarget = doTbtBillingTarget;
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        /// <summary>
        /// Confirm for edit billing target
        /// </summary>
        /// <param name="doBillingTarget"></param>
        /// <returns></returns>
        public ActionResult BLS020_ConfirmEditBillingTarget(dtTbt_BillingTargetForView doBillingTarget)
        {
            ObjectResultData       res                 = new ObjectResultData();
            CommonUtil             comUtil             = new CommonUtil();
            BLS020_ScreenParameter sParam              = GetScreenObject <BLS020_ScreenParameter>();
            tbt_BillingTarget      doTbt_BillingTarget = new tbt_BillingTarget();
            IBillingHandler        handler             = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;

            try
            {
                ///////// Check Suspending //////////
                ICommonHandler chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

                if (chandler.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }
                if (ModelState.IsValid == false)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    ValidatorUtil.BuildErrorMessage(res, this);
                    return(Json(res));
                }

                ///// Check permission //////////
                if (!CheckUserPermission(ScreenID.C_SCREEN_ID_EDIT_BILL_TARGET, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }

                ///////////////5.3 Validate Business
                //check duplicate
                List <tbt_BillingTarget> lst = new List <tbt_BillingTarget>();
                lst = handler.GetTbt_BillingTarget(null, comUtil.ConvertBillingClientCode(doBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG), doBillingTarget.BillingOfficeCode);
                if (lst.Count > 0)
                {
                    doTbt_BillingTarget = lst[0];
                }
                else
                {
                    doTbt_BillingTarget = null;
                }
                //doTbt_BillingTarget = handler.GetTbt_BillingTarget(null, comUtil.ConvertBillingClientCode(doBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG), doBillingTarget.BillingOfficeCode);
                doBillingTarget.BillingTargetCode = comUtil.ConvertBillingClientCode(doBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG) + "-" + doBillingTarget.BillingTargetNo;
                if (doTbt_BillingTarget != null &&
                    doTbt_BillingTarget.BillingTargetCode != doBillingTarget.BillingTargetCode)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                        ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET,
                                        MessageUtil.MODULE_BILLING,
                                        MessageUtil.MessageList.MSG6002,
                                        new string[] { doTbt_BillingTarget.BillingTargetCode },
                                        new string[] { "BillingClientCode", "BillingTargetNo", "BillingOfficeCode" });

                    return(Json(res));
                }
                //Update Billing target
                doTbt_BillingTarget = new tbt_BillingTarget();
                doTbt_BillingTarget.BillingTargetCode = doBillingTarget.BillingTargetCode;
                doTbt_BillingTarget.BillingTargetNo   = doBillingTarget.BillingTargetNo;
                doTbt_BillingTarget.BillingClientCode = comUtil.ConvertBillingClientCode(doBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG);
                doTbt_BillingTarget.BillingOfficeCode = doBillingTarget.BillingOfficeCode;
                doTbt_BillingTarget.ContactPersonName = doBillingTarget.ContactPersonName;
                doTbt_BillingTarget.Memo               = doBillingTarget.Memo;
                doTbt_BillingTarget.IssueInvTime       = doBillingTarget.IssueInvTime;
                doTbt_BillingTarget.IssueInvMonth      = doBillingTarget.IssueInvMonth;
                doTbt_BillingTarget.IssueInvDate       = doBillingTarget.IssueInvDate;
                doTbt_BillingTarget.InvFormatType      = doBillingTarget.InvFormatType;
                doTbt_BillingTarget.SignatureType      = doBillingTarget.SignatureType;
                doTbt_BillingTarget.DocLanguage        = doBillingTarget.DocLanguage;
                doTbt_BillingTarget.ShowDueDate        = doBillingTarget.ShowDueDate;
                doTbt_BillingTarget.IssueReceiptTiming = doBillingTarget.IssueReceiptTiming;
                doTbt_BillingTarget.ShowAccType        = doBillingTarget.ShowAccType;
                doTbt_BillingTarget.WhtDeductionType   = doBillingTarget.WhtDeductionType;
                doTbt_BillingTarget.ShowIssueDate      = doBillingTarget.ShowIssueDate;
                doTbt_BillingTarget.PayByChequeFlag    = doBillingTarget.PayByChequeFlag;
                doTbt_BillingTarget.ShowInvWHTFlag     = doBillingTarget.ShowInvWHTFlag;
                doTbt_BillingTarget.SeparateInvType    = doBillingTarget.SeparateInvType;
                doTbt_BillingTarget.SuppleInvAddress   = doBillingTarget.SuppleInvAddress;

                // tt
                doTbt_BillingTarget.RealBillingClientNameEN    = doBillingTarget.RealBillingClientNameEN;
                doTbt_BillingTarget.RealBillingClientNameLC    = doBillingTarget.RealBillingClientNameLC;
                doTbt_BillingTarget.RealBillingClientAddressEN = doBillingTarget.RealBillingClientAddressEN;
                doTbt_BillingTarget.RealBillingClientAddressLC = doBillingTarget.RealBillingClientAddressLC;

                // Akat K. 2014-05-23 : update PrintAdvanceDate
                doTbt_BillingTarget.PrintAdvanceDate = doBillingTarget.PrintAdvanceDate;

                using (TransactionScope scope = new TransactionScope())
                {
                    handler.UpdateTbt_BillingTarget(doTbt_BillingTarget);

                    // Akat K. 2014-05-21 also update billing office
                    handler.UpdateDebtTracingOffice(doBillingTarget.BillingTargetCode, doBillingTarget.BillingOfficeCode);

                    scope.Complete();
                }
                sParam.doBillingTarget     = doBillingTarget;
                sParam.doTbt_BillingTarget = doTbt_BillingTarget;
                res.ResultData             = sParam.doBillingTarget;
                res.MessageType            = MessageModel.MESSAGE_TYPE.INFORMATION_OK;
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0046, null, null);
                return(Json(res));
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }
Beispiel #4
0
        public ActionResult CTP060_UpdateEmailContentOfNotifyEmail()
        {
            ObjectResultData        res                  = new ObjectResultData();
            IContractHandler        conHandler           = ServiceContainer.GetService <IContractHandler>() as IContractHandler;
            IRentralContractHandler rentalConHandler     = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
            IMasterHandler          masterHandler        = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;
            IEmployeeMasterHandler  empMasterHandler     = ServiceContainer.GetService <IEmployeeMasterHandler>() as IEmployeeMasterHandler;
            IBillingMasterHandler   billingmasterhandler = ServiceContainer.GetService <IBillingMasterHandler>() as IBillingMasterHandler;
            IOfficeMasterHandler    officehandler        = ServiceContainer.GetService <IOfficeMasterHandler>() as IOfficeMasterHandler;
            IBillingHandler         billinghandler       = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;

            List <tbm_Customer>  dtCustomer;
            List <doGetTbm_Site> dtSite;
            List <tbm_Employee>  dtEmployee;
            decimal?contractFeeBeforeChange;
            decimal?ChangeContractFee;

            try
            {
                CommonUtil comUtil = new CommonUtil();
                doNotifyChangeFeeContract doNotifyEmail           = new doNotifyChangeFeeContract();
                List <tbt_ContractEmail>  updateContractEmailList = new List <tbt_ContractEmail>();

                using (TransactionScope scope = new TransactionScope())
                {
                    List <tbt_ContractEmail> contractEmailList = conHandler.GetUnsentNotifyEmail();
                    foreach (tbt_ContractEmail data in contractEmailList)
                    {
                        List <tbt_BillingBasic>  doBillingBasic  = billinghandler.GetTbt_BillingBasic(data.ContractCode, "01");
                        List <tbt_BillingTarget> doBillingTarget = billinghandler.GetTbt_BillingTarget(doBillingBasic[0].BillingTargetCode, null, null);

                        dsRentalContractData dsRentalContract = rentalConHandler.GetEntireContract(data.ContractCode, data.OCC);
                        if (dsRentalContract.dtTbt_RentalSecurityBasic[0].ReturnToOriginalFeeDate != null)
                        {
                            var operationOfficeDat = officehandler.GetTbm_Office(dsRentalContract.dtTbt_RentalContractBasic[0].OperationOfficeCode);
                            var billingOfficeDat   = officehandler.GetTbm_Office(doBillingTarget[0].BillingOfficeCode);

                            EmailTemplateUtil mailUtil = new EmailTemplateUtil(EmailTemplateName.C_EMAIL_TEMPLATE_NAME_CHANGE_FEE);
                            dtCustomer = masterHandler.GetTbm_Customer(dsRentalContract.dtTbt_RentalContractBasic[0].ContractTargetCustCode);
                            dtSite     = masterHandler.GetTbm_Site(dsRentalContract.dtTbt_RentalContractBasic[0].SiteCode);
                            dtEmployee = empMasterHandler.GetTbm_Employee(data.CreateBy);
                            contractFeeBeforeChange = rentalConHandler.GetContractFeeBeforeChange(dsRentalContract.dtTbt_RentalContractBasic[0].ContractCode, dsRentalContract.dtTbt_RentalSecurityBasic[0].OCC, dsRentalContract);

                            doNotifyEmail.ContractCode            = comUtil.ConvertContractCode(dsRentalContract.dtTbt_RentalContractBasic[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                            doNotifyEmail.ContractTargetNameEN    = dtCustomer[0].CustFullNameEN;
                            doNotifyEmail.ContractTargetNameLC    = dtCustomer[0].CustFullNameLC;
                            doNotifyEmail.SiteNameEN              = dtSite[0].SiteNameEN;
                            doNotifyEmail.SiteNameLC              = dtSite[0].SiteNameLC;
                            doNotifyEmail.ChangeDateOfContractFee = CommonUtil.TextDate(dsRentalContract.dtTbt_RentalSecurityBasic[0].ChangeImplementDate);
                            doNotifyEmail.ContractFeeBeforeChange = CommonUtil.TextNumeric(contractFeeBeforeChange);

                            if (dsRentalContract.dtTbt_RentalContractBasic[0].ContractStatus == ContractStatus.C_CONTRACT_STATUS_STOPPING)
                            {
                                ChangeContractFee = dsRentalContract.dtTbt_RentalSecurityBasic[0].ContractFeeOnStop;
                            }
                            else
                            {
                                ChangeContractFee = dsRentalContract.dtTbt_RentalSecurityBasic[0].OrderContractFee;
                            }

                            doNotifyEmail.ContractFeeAfterChange  = CommonUtil.TextNumeric(ChangeContractFee);
                            doNotifyEmail.ReturnToOriginalFeeDate = CommonUtil.TextDate(dsRentalContract.dtTbt_RentalSecurityBasic[0].ReturnToOriginalFeeDate);
                            doNotifyEmail.OperationOfficeEN       = operationOfficeDat[0].OfficeNameEN;
                            doNotifyEmail.OperationOfficeLC       = operationOfficeDat[0].OfficeNameLC;
                            doNotifyEmail.RegisterChangeEmpNameEN = dtEmployee[0].EmpFirstNameEN + ' ' + dtEmployee[0].EmpLastNameEN;
                            doNotifyEmail.RegisterChangeEmpNameLC = dtEmployee[0].EmpFirstNameLC + ' ' + dtEmployee[0].EmpLastNameLC;
                            doNotifyEmail.BillingOfficeEN         = billingOfficeDat[0].OfficeNameEN;
                            doNotifyEmail.BillingOfficeLC         = billingOfficeDat[0].OfficeNameLC;

                            var mailTemplate = mailUtil.LoadTemplate(doNotifyEmail);
                            data.EmailContent = mailTemplate.TemplateContent;

                            tbt_ContractEmail conEmailTemp = CommonUtil.CloneObject <tbt_ContractEmail, tbt_ContractEmail>(data);
                            updateContractEmailList.Add(conEmailTemp);
                        }
                    }

                    if (updateContractEmailList != null && updateContractEmailList.Count > 0)
                    {
                        conHandler.UpdateTbt_ContractEmail(updateContractEmailList);
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        /// <summary>
        /// Register billing target
        /// </summary>
        /// <param name="sValid"></param>
        /// <param name="doBillingTarget"></param>
        /// <returns></returns>
        public ActionResult BLS020_RegisterBillingTarge(BLS020_ScreenInputValidate sValid, dtTbt_BillingTargetForView doBillingTarget)
        {
            ObjectResultData       res                 = new ObjectResultData();
            CommonUtil             comUtil             = new CommonUtil();
            BLS020_ScreenParameter sParam              = GetScreenObject <BLS020_ScreenParameter>();
            tbt_BillingTarget      doTbt_BillingTarget = new tbt_BillingTarget();
            IBillingHandler        handler             = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;

            try
            {
                ///////// Check Suspending //////////
                ICommonHandler chandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;

                if (chandler.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }
                if (ModelState.IsValid == false)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    ValidatorUtil.BuildErrorMessage(res, this);
                    return(Json(res));
                }

                ///// Check permission //////////
                if (!CheckUserPermission(ScreenID.C_SCREEN_ID_EDIT_BILL_TARGET, FunctionID.C_FUNC_ID_OPERATE))
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0053);
                    return(Json(res));
                }

                ///////////////5.3 Validate Business
                if (CommonUtil.IsNullOrEmpty(doBillingTarget.IssueInvMonth))
                {
                    doBillingTarget.IssueInvMonth = 0;
                }
                if (doBillingTarget.IssueInvMonth > 60)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                        ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET,
                                        MessageUtil.MODULE_BILLING,
                                        MessageUtil.MessageList.MSG6001,
                                        new string[] { "lblIssueInvoiceTiming" },
                                        new string[] { "IssueInvMonth" });
                    return(Json(res));
                }

                //check duplicate
                List <tbt_BillingTarget> lst = new List <tbt_BillingTarget>();
                lst = handler.GetTbt_BillingTarget(null, comUtil.ConvertBillingClientCode(doBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG), doBillingTarget.BillingOfficeCode);
                if (lst.Count > 0)
                {
                    doTbt_BillingTarget = lst[0];
                }
                else
                {
                    doTbt_BillingTarget = null;
                }
                //doTbt_BillingTarget = handler.GetTbt_BillingTarget(null, comUtil.ConvertBillingClientCode(doBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG), doBillingTarget.BillingOfficeCode);
                doBillingTarget.BillingTargetCode = comUtil.ConvertBillingClientCode(doBillingTarget.BillingClientCode, CommonUtil.CONVERT_TYPE.TO_LONG) + "-" + doBillingTarget.BillingTargetNo;
                if (doTbt_BillingTarget != null &&
                    doTbt_BillingTarget.BillingTargetCode != doBillingTarget.BillingTargetCode)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
                    // res.AddErrorMessage(MessageUtil.MODULE_BILLING, MessageUtil.MessageList.MSG6002, new string[] { doTbtBillingTarget.BillingTargetCode }, new string[] { "BillingClientCodeView" });
                    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                        ScreenID.C_SCREEN_ID_REGIST_BILL_TARGET,
                                        MessageUtil.MODULE_BILLING,
                                        MessageUtil.MessageList.MSG6002,
                                        new string[] { comUtil.ConvertBillingTargetCode(doTbt_BillingTarget.BillingTargetCode, CommonUtil.CONVERT_TYPE.TO_SHORT) },
                                        new string[] { "BillingClientCode", "BillingTargetNo", "BillingOfficeCode" });

                    return(Json(res));
                }
                res.ResultData = true;
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }