/// <summary> /// /// </summary> /// <param name="param"></param> /// <returns></returns> public ActionResult CMS480_UpdateManageCarryOverProfit(List <CMS480_ManageCarryOverProfit_Param> param, string productTypeCode) { ObjectResultData res = new ObjectResultData(); try { if (param == null && param.Count == 0) { throw new ArgumentNullException("param", "\"Manage carry over profit\" data can't be empty"); } CommonUtil com = new CommonUtil(); using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 5, 0))) { foreach (CMS480_ManageCarryOverProfit_Param item in param) { string reportMonth = !string.IsNullOrEmpty(item.ReportMonthYear) ? item.ReportMonthYear.Split('/')[0] : null; string reportYear = !string.IsNullOrEmpty(item.ReportMonthYear) ? item.ReportMonthYear.Split('/')[1] : null; string contractCode = !string.IsNullOrEmpty(item.BillingCode) ? item.BillingCode.Split('-')[0] : null; string billingOCC = !string.IsNullOrEmpty(item.BillingCode) ? item.BillingCode.Split('-')[1] : null; if (item.ReceiveAmountCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US) { item.ReceiveAmountUsd = item.ReceiveAmount; item.ReceiveAmount = null; } if (item.IncomeRentalFeeCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US) { //item.IncomeRentalFeeUsd = item.ReceiveAmount; item.IncomeRentalFeeUsd = item.IncomeRentalFee; item.IncomeRentalFee = null; } if (item.AccumulatedReceiveAmountCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US) { // item.AccumulatedReceiveAmountUsd = item.ReceiveAmount; item.AccumulatedReceiveAmountUsd = item.AccumulatedReceiveAmount; item.AccumulatedReceiveAmount = null; } if (item.AccumulatedUnpaidCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US) { // item.AccumulatedUnpaidUsd = item.ReceiveAmount; item.AccumulatedUnpaidUsd = item.AccumulatedUnpaid; item.AccumulatedUnpaid = null; } if (item.IncomeVatCurrencyType == SECOM_AJIS.Common.Util.ConstantValue.CurrencyUtil.C_CURRENCY_US) { // item.IncomeVatUsd = item.ReceiveAmount; item.IncomeVatUsd = item.IncomeVat; item.IncomeVat = null; } ICommonHandler srvCommon = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; srvCommon.UpdateTbtManageCarryOverProfit(reportYear, reportMonth, com.ConvertContractCode(contractCode, CommonUtil.CONVERT_TYPE.TO_LONG), billingOCC, item.ReceiveAmount, item.ReceiveAmountUsd, item.ReceiveAmountCurrencyType, item.IncomeRentalFee, item.IncomeRentalFeeUsd, item.IncomeRentalFeeCurrencyType, item.AccumulatedReceiveAmount, item.AccumulatedReceiveAmountUsd, item.AccumulatedReceiveAmountCurrencyType, item.AccumulatedUnpaid, item.AccumulatedUnpaidUsd, item.AccumulatedUnpaidCurrencyType, item.IncomeVat, item.IncomeVatUsd, item.IncomeVatCurrencyType, item.UnpaidPeriod, item.IncomeDate, CommonUtil.dsTransData.dtUserData.EmpNo); } trans.Complete(); this.Dispose(); } // - Generate CSV Files - string paramReportMonth = param[0].ReportMonthYear.Split('/')[0]; string paramReportYear = param[0].ReportMonthYear.Split('/')[1]; IDocumentHandler documentHandler = ServiceContainer.GetService <IDocumentHandler>() as IDocumentHandler; documentHandler.GenerateCMR020FilePath(paramReportYear, paramReportMonth, productTypeCode, ProcessID.C_PROCESS_ID_GEN_ACCOUNT_CARRY_OVER_AND_PROFIT, DateTime.Now, false); res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION; res.ResultData = this.CMS480_UpdateManageCarryOverProfit_CreateResult(true); return(Json(res)); } catch (Exception ex) { res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION; res.AddErrorMessage(ex); res.ResultData = this.CMS480_UpdateManageCarryOverProfit_CreateResult(false); return(Json(res)); } }
// CMP140 /// <summary> /// CMP140: Batch generate account data of carry-over & Profit Process /// </summary> /// <param name="UserId">User id</param> /// <param name="BatchDate">Batch date</param> /// <returns></returns> public doBatchProcessResult CMP140_GenerateAccountDataOfCarryOverAndProfitProcess(string UserId, DateTime BatchDate) { #region Prepare doBatchProcessResult result = new doBatchProcessResult() { Total = 0, Complete = 0, Failed = 0, ErrorMessage = string.Empty }; CommonHandler commonHandler = new CommonHandler(); #endregion #region Do process //Get business date parameter dtBusinessDateForAccountDataOfCarryOverAndProfit businessDate = commonHandler.GetBusinessDateForAccountDataOfCarryOverAndProfitProcess((DateTime?)BatchDate).FirstOrDefault(); if (BatchDate.Date >= businessDate.FiveBusinessDate.Value.Date && businessDate.RecordCount == 0) { #region Generate account data of carry-over & Profit //Get account data by each product type code using (TransactionScope scope = new TransactionScope()) { //Product type code list string[] productTypeCodes = { GroupProductType.C_GROUP_PRODUCT_TYPE_N, GroupProductType.C_GROUP_PRODUCT_TYPE_SG, GroupProductType.C_GROUP_PRODUCT_TYPE_MA }; //current process product type code string processProductTypeCode = string.Empty; try { IDocumentHandler documentHandler = ServiceContainer.GetService <IDocumentHandler>() as IDocumentHandler; foreach (string productTypeCode in productTypeCodes) { //Set current process productTypeCode processProductTypeCode = productTypeCode; //Get account data List <dtAccountDataOfCarryOverAndProfit> accountData = commonHandler.GetAccountDataOfCarryOverAndProfit( businessDate.StartTargetDate.Value, businessDate.EndTargetDate.Value, businessDate.FiveBusinessDate.Value, productTypeCode); //Freeze data to tbt_ManageCarryOverProfit List <tbt_ManageCarryOverProfit> dtManageCarryPreInsert = new List <tbt_ManageCarryOverProfit>(); foreach (dtAccountDataOfCarryOverAndProfit dtAccountData in accountData) { tbt_ManageCarryOverProfit dtManageCarryItem = new tbt_ManageCarryOverProfit() { ReportYear = businessDate.ReportYear, ReportMonth = businessDate.ReportMonth, ProductType = productTypeCode, ContractCode = dtAccountData.ContractCode, BillingOCC = dtAccountData.BillingOCC, BillingTargetCode = dtAccountData.BillingTargetCode, BillingOfficeCode = dtAccountData.BillingOfficeCode, BillingOfficeName = dtAccountData.BillingOfficeName, BillingTargetName = dtAccountData.BillingTargetName, FirstOperationDate = dtAccountData.FirstOperationDate, MonthlyBillingAmount = dtAccountData.MonthlyBillingAmount, LastAccumulatedReceiveAmount = dtAccountData.LastAccumulatedReceiveAmount, LastAccumulatedUnpaid = dtAccountData.LastAccumulatedUnpaid, ReceiveAmount = dtAccountData.ReceiveAmount, IncomeRentalFee = dtAccountData.IncomeRentalFee, AccumulatedReceiveAmount = dtAccountData.AccumulatedReceiveAmount, AccumulatedUnpaid = dtAccountData.AccumulatedUnpaid, IncomeVat = dtAccountData.IncomeVat, UnpaidPeriod = dtAccountData.UnpaidPeriod, IncomeDate = dtAccountData.IncomeDate, ContractStatus = dtAccountData.ContractStatus, CalDailyFeeStatus = dtAccountData.CalDailyFeeStatus, StartTargetDate = businessDate.StartTargetDate, EndTargetDate = businessDate.EndTargetDate, FiveBusinessDate = businessDate.FiveBusinessDate, CreateDate = BatchDate, CreateBy = ProcessID.C_PROCESS_ID_GEN_ACCOUNT_CARRY_OVER_AND_PROFIT, UpdateDate = BatchDate, UpdateBy = ProcessID.C_PROCESS_ID_GEN_ACCOUNT_CARRY_OVER_AND_PROFIT }; dtManageCarryPreInsert.Add(dtManageCarryItem); } //Insert freeze data into db commonHandler.InsertTbt_ManageCarryOverProfit(CommonUtil.ConvertToXml_Store <tbt_ManageCarryOverProfit>(dtManageCarryPreInsert)); //Update billing history commonHandler.UpdateBillingHistoryOfManageCarryOverProfit(businessDate.ReportYear, businessDate.ReportMonth, productTypeCode, (DateTime?)BatchDate, ProcessID.C_PROCESS_ID_GEN_ACCOUNT_CARRY_OVER_AND_PROFIT); //Genereate CMR020 report (Csv formatted) documentHandler.GenerateCMR020FilePath(businessDate.ReportYear, businessDate.ReportMonth, productTypeCode, ProcessID.C_PROCESS_ID_GEN_ACCOUNT_CARRY_OVER_AND_PROFIT, BatchDate); //Record info result.Total += accountData.Count; } //Completed scope.Complete(); result.Complete = result.Total; } catch (Exception ex) { //All failed scope.Dispose(); result.Failed = result.Total; result.ErrorMessage += string.Format("Product type code {0} has Error : {1} {2}\n", processProductTypeCode, ex.Message, ex.InnerException != null ? ex.InnerException.Message : ""); result.Result = FlagType.C_FLAG_OFF; result.BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED; return(result); } } #endregion } else { if (businessDate.RecordCount > 0) { #region Already generated data result.Result = FlagType.C_FLAG_ON; result.BatchStatus = BatchStatus.C_BATCH_STATUS_SUCCEEDED; result.ErrorMessage = "Generate data already"; return(result); #endregion } } #endregion //All success, include no process case, no error case result.Result = FlagType.C_FLAG_ON; result.BatchStatus = BatchStatus.C_BATCH_STATUS_SUCCEEDED; return(result); }