/// <summary>
        /// Register input data to database (BLS030)
        /// </summary>
        /// <param name="validData"></param>
        /// <returns></returns>
        public ActionResult BLS030_RegisterData(BLS030_ValidateData validData)
        {
            ObjectResultData       res                   = new ObjectResultData();
            ICommonHandler         handlerCommon         = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            ICommonContractHandler commonContractHandler = ServiceContainer.GetService <ICommonContractHandler>() as ICommonContractHandler;
            IBillingHandler        billingHandler        = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;

            CommonUtil comUtil = new CommonUtil();

            try
            {
                if (handlerCommon.IsSystemSuspending())
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }

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



                BLS030_ScreenParameter sParam = GetScreenObject <BLS030_ScreenParameter>();

                // === Business validate ===

                List <doServiceProductTypeCode> lstContractServiceProductType = commonContractHandler.GetServiceProductTypeCode(sParam.ContractProjectCodeLong);
                List <doServiceProductTypeCode> lstProjectServiceProductType  = commonContractHandler.GetServiceProductTypeCode(sParam.ContractProjectCodeLong);


                bool isContractCode = false;
                bool isProjectCode  = false;

                if (lstContractServiceProductType.Count > 0 && lstProjectServiceProductType.Count > 0)
                {
                    isContractCode = (string.IsNullOrEmpty(lstContractServiceProductType[0].ServiceTypeCode) == false);
                    if (isContractCode == false)
                    {
                        isProjectCode = (string.IsNullOrEmpty(lstProjectServiceProductType[0].ServiceTypeCode) == false);
                    }
                }

                //------ (1)
                if (isContractCode == false && isProjectCode == false)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                        "BLS030",
                                        MessageUtil.MODULE_COMMON,
                                        MessageUtil.MessageList.MSG0011,
                                        new string[] { "lblContractProjectCode" },
                                        new string[] { "ContractCodeProjectCode" });
                    return(Json(res));
                }

                //------ (2)
                var lst = billingHandler.GetTbt_BillingTargetForView(sParam.BillingClientCode + "-" + sParam.BillingTargetRunningNo, MiscType.C_CUST_TYPE);

                if (lst.Count == 0)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                        "BLS030",
                                        MessageUtil.MODULE_BILLING,
                                        MessageUtil.MessageList.MSG6040,
                                        null,
                                        null);
                    return(Json(res));
                }


                //------ (1) + (2)
                var lstdoBillingBasic = billingHandler.GetBillingBasic(sParam.ContractProjectCodeLong, null, sParam.BillingClientCode + "-" + sParam.BillingTargetRunningNo, null, null, CurrencyUtil.C_CURRENCY_LOCAL, CurrencyUtil.C_CURRENCY_US);

                if (lstdoBillingBasic.Count > 0)
                {
                    res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                    res.AddErrorMessage(MessageUtil.MODULE_BILLING,
                                        "BLS030",
                                        MessageUtil.MODULE_BILLING,
                                        MessageUtil.MessageList.MSG6003,
                                        new string[] { comUtil.ConvertBillingCode(lstdoBillingBasic[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT) + "-" + lstdoBillingBasic[0].BillingOCC },
                                        null);
                    return(Json(res));
                }


                using (TransactionScope scope = new TransactionScope())
                {
                    //=== Billing Basic ===
                    DataEntity.Billing.tbt_BillingBasic doBillingBasic2 = new DataEntity.Billing.tbt_BillingBasic()
                    {
                        ContractCode               = sParam.ContractProjectCodeLong,
                        BillingTargetCode          = sParam.BillingClientCode + "-" + sParam.BillingTargetRunningNo,
                        DebtTracingOfficeCode      = sParam.doBillingTarget.BillingOfficeCode,
                        PaymentMethod              = sParam.PaymentMethod,
                        SortingType                = sParam.SortingType,
                        StopBillingFlag            = true,
                        VATUnchargedFlag           = false,
                        BillingCycle               = BillingCycle.C_BILLING_CYCLE_DEFAULT_ONETIME,
                        CreditTerm                 = CreditTerm.C_CREDIT_TERM_DEFAULT,
                        CalDailyFeeStatus          = CalculationDailyFeeType.C_CALC_DAILY_FEE_TYPE_CALENDAR,
                        ResultBasedMaintenanceFlag = false,

                        // Narupon
                        PreviousBillingTargetCode = sParam.BillingClientCode + "-" + sParam.BillingTargetRunningNo
                    };

                    // CREATE !!
                    string strBillingOCC = billingHandler.CreateBillingBasic(doBillingBasic2);


                    if (sParam.PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_AUTO_TRANSFER)
                    {
                        //=== Auto Transfer ===

                        string strAccountNo = string.Empty;
                        strAccountNo = string.IsNullOrEmpty(sParam.doAutoTransferBankAccount.AccountNo) ? string.Empty : sParam.doAutoTransferBankAccount.AccountNo.Replace("-", "");

                        tbt_AutoTransferBankAccount doTbt_AutoTransferBankAccount = new tbt_AutoTransferBankAccount()
                        {
                            ContractCode     = sParam.ContractProjectCodeLong,
                            BillingOCC       = strBillingOCC,
                            BankCode         = sParam.doAutoTransferBankAccount.BankCode,
                            BankBranchCode   = sParam.doAutoTransferBankAccount.BankBranchCode,
                            AccountNo        = strAccountNo, // Edit Narupon W. 29/05/2012
                            AccountName      = sParam.doAutoTransferBankAccount.AccountName,
                            AccountType      = sParam.doAutoTransferBankAccount.AccountType,
                            AutoTransferDate = sParam.doAutoTransferBankAccount.AutoTransferDate
                        };

                        List <tbt_AutoTransferBankAccount> doTbt_AutoTransferBankAccountList = new List <tbt_AutoTransferBankAccount>();
                        doTbt_AutoTransferBankAccountList.Add(doTbt_AutoTransferBankAccount);
                        billingHandler.InsertTbt_AutoTransferBankAccountData(doTbt_AutoTransferBankAccountList);
                    }
                    else if (sParam.PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_CREDIT_CARD_TRANSFER)
                    {
                        //=== Credit Card ===

                        string strCreditCardNo = string.IsNullOrEmpty(sParam.doCreditCard.CreditCardNo) ? string.Empty : sParam.doCreditCard.CreditCardNo.Replace("-", "");

                        tbt_CreditCard doTbt_CreditCard = new tbt_CreditCard()
                        {
                            ContractCode          = sParam.ContractProjectCodeLong,
                            BillingOCC            = strBillingOCC,
                            CreditCardCompanyCode = sParam.doCreditCard.CreditCardCompanyCode,
                            CreditCardType        = sParam.doCreditCard.CreditCardType,
                            CreditCardNo          = strCreditCardNo, // Edit by Narupon W. 28/05/2012
                            CardName = sParam.doCreditCard.CardName,
                            ExpMonth = sParam.doCreditCard.ExpMonth,
                            ExpYear  = sParam.doCreditCard.ExpYear
                        };

                        List <tbt_CreditCard> doTbt_CreditCardList = new List <tbt_CreditCard>();
                        doTbt_CreditCardList.Add(doTbt_CreditCard);
                        billingHandler.InsertTbt_CreditCard(doTbt_CreditCardList);
                    }

                    // === Billing Type Detail ===
                    if (sParam.doBillingTypeList != null)
                    {
                        foreach (tbt_BillingTypeDetail doBillingType in sParam.doBillingTypeList)
                        {
                            doBillingType.ContractCode     = sParam.ContractProjectCodeLong;
                            doBillingType.BillingOCC       = strBillingOCC;
                            doBillingType.IssueInvoiceFlag = true;
                            doBillingType.ProductCode      = null;
                            doBillingType.ProductTypeCode  = sParam.ProductTypeCode;

                            if (doBillingType.BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRODUCT_PRICE ||
                                doBillingType.BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRICE ||
                                doBillingType.BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRICE_DOWN ||
                                doBillingType.BillingTypeCode == BillingType.C_BILLING_TYPE_SALE_PRICE_PARTIAL)
                            {
                                // tt
                                doBillingType.InvoiceDescriptionEN = doBillingType.InvoiceDescriptionEN;
                                doBillingType.InvoiceDescriptionLC = doBillingType.InvoiceDescriptionLC;
                            }
                            else
                            {
                                // tt
                                doBillingType.InvoiceDescriptionEN = null;
                                doBillingType.InvoiceDescriptionLC = null;
                            }

                            billingHandler.CreateBillingTypeDetail(doBillingType);
                        }
                    }
                    scope.Complete();
                    res.ResultData = true;
                }
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }