コード例 #1
0
        /// <summary>
        /// Register input data to database (BLS090)
        /// </summary>
        /// <returns></returns>
        public ActionResult BLS090_Confirm()
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
            List <dtBillingContract> list = new List <dtBillingContract>();

            try
            {
                // Is suspend ?
                ICommonHandler handlerCommon = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
                if (handlerCommon.IsSystemSuspending())
                {
                    res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0049);
                    return(Json(res));
                }

                BLS090_ScreenParameter param          = GetScreenObject <BLS090_ScreenParameter>();
                IBillingHandler        handlerBilling = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;

                if (param.RegisterData == null)
                {
                    param.RegisterData = new List <BLS090_DetailData>();
                }

                var updateList = (from p in param.RegisterData where p.MonthlyBillingAmount != p.NewBillingFee || p.MonthlyBillingAmountCurrencyType != p.NewMonthlyBillingAmountCurrency select p).ToList <BLS090_DetailData>();

                // Prepare
                List <tbt_BillingBasic> billiingBasicList = new List <tbt_BillingBasic>();
                tbt_BillingBasic        billiingBasic;

                List <tbt_MonthlyBillingHistory> billingHistoryList_ForInsert = new List <tbt_MonthlyBillingHistory>();
                List <tbt_MonthlyBillingHistory> billingHistoryList_ForUpdate = new List <tbt_MonthlyBillingHistory>();
                tbt_MonthlyBillingHistory        billingHistory;
                foreach (var item in updateList)
                {
                    decimal?amount   = null;
                    decimal?amountUS = null;
                    if (item.NewMonthlyBillingAmountCurrency == CurrencyUtil.C_CURRENCY_LOCAL)
                    {
                        amount = item.NewBillingFee;
                    }
                    else
                    {
                        amountUS = item.NewBillingFee;
                    }

                    // Billig basic
                    billiingBasic = new tbt_BillingBasic()
                    {
                        ContractCode    = item.ContractCode,
                        BillingOCC      = item.BillingOCC,
                        StopBillingFlag = (Convert.ToDecimal(item.NewBillingFee) <= 0), // ***
                        //MonthlyBillingAmount = item.NewBillingFee,  // ***
                        MonthlyBillingAmount    = amount,                               // add by jirawat jannet @ 2016-08-29
                        MonthlyBillingAmountUsd = amountUS,                             // add by jirawat jannet @ 2016-08-29
                        UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo,
                        UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                        MonthlyBillingAmountCurrencyType = item.NewMonthlyBillingAmountCurrency
                    };
                    billiingBasicList.Add(billiingBasic);



                    // Billing history

                    var lastBillingHistory = handlerBilling.GetLastBillingHistory(item.ContractCode, item.BillingOCC, CurrencyUtil.C_CURRENCY_LOCAL, CurrencyUtil.C_CURRENCY_US);

                    if (lastBillingHistory.Count > 0)
                    {
                        // Case UPDATE.
                        var billingHistory_update = lastBillingHistory[0];
                        billingHistory_update.MonthlyBillingAmount             = amount;// item.NewBillingFee; // ***
                        billingHistory_update.MonthlyBillingAmountUsd          = amountUS;
                        billingHistory_update.MonthlyBillingAmountCurrencyType = item.NewMonthlyBillingAmountCurrency;
                        billingHistory_update.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                        billingHistory_update.UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;

                        billingHistoryList_ForUpdate.Add(billingHistory_update);
                    }
                    else
                    {
                        // Case CREATE.
                        billingHistory = new tbt_MonthlyBillingHistory()
                        {
                            ContractCode         = item.ContractCode,
                            BillingOCC           = item.BillingOCC,
                            MonthlyBillingAmount = item.NewBillingFee,  // ***
                            BillingStartDate     = DateTime.Now,
                            CreateDate           = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                            CreateBy             = CommonUtil.dsTransData.dtUserData.EmpNo,
                            UpdateDate           = CommonUtil.dsTransData.dtOperationData.ProcessDateTime,
                            UpdateBy             = CommonUtil.dsTransData.dtUserData.EmpNo
                        };
                        billingHistoryList_ForInsert.Add(billingHistory);
                    }
                }

                // TODO : (Narupon W.) , Uncomment as finally
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        // Save to DB !!

                        handlerBilling.UpdateMonthlyBillingAmount(billiingBasicList);

                        // Case Create.
                        handlerBilling.InsertTbt_MonthlyBillingHistory(CommonUtil.ConvertToXml_Store(billingHistoryList_ForInsert));
                        // Case Update.
                        handlerBilling.UpdateTbt_MonthlyBillingHistoryData(CommonUtil.ConvertToXml_Store(billingHistoryList_ForUpdate));
                        scope.Complete();
                    }
                    catch (Exception ex)
                    {
                        scope.Dispose();
                        throw ex;
                    }
                }

                res.ResultData  = "1";
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION_OK;
                res.AddErrorMessage(MessageUtil.MODULE_COMMON, MessageUtil.MessageList.MSG0046, null, null);
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }