/// <summary> /// Process for delete quotation data /// </summary> /// <param name="UserId"></param> /// <param name="BatchDate"></param> /// <returns></returns> public doBatchProcessResult QUP010_DeleteQuotationProcess(string UserId, DateTime BatchDate) { doBatchProcessResult result = new doBatchProcessResult(); List <SECOM_AJIS.DataEntity.Quotation.dtBatchProcessResult> deleteResult = new List <SECOM_AJIS.DataEntity.Quotation.dtBatchProcessResult>(); using (TransactionScope scope = new TransactionScope()) { try { deleteResult = base.DeleteQuotation(FlagType.C_FLAG_ON, FlagType.C_FLAG_OFF); scope.Complete(); } catch (Exception ex) { scope.Dispose(); } } // Clone if (deleteResult.Count > 0) { result.Total = (deleteResult[0].Total ?? 0); result.Complete = (deleteResult[0].Complete ?? 0); result.Failed = (deleteResult[0].Failed ?? 0); result.ErrorMessage = deleteResult[0].ErrorMessage; result.BatchUser = UserId; result.Result = (deleteResult[0].Failed ?? 0) == 0; } return(result); }
//IncomeHandler-BatchGenDebtSummary /// <summary> /// Batch Process to generate debt summary information. call "sp_IC_BatchGenDebtSummary" store procedure /// </summary>a /// <param name="UserId">employee no.</param> /// <param name="BatchDate">process datetime</param> /// <returns></returns> public doBatchProcessResult ICP030_BatchGenDebtSummaryProcess(string UserId, DateTime BatchDate) { #region Prepare //Result doBatchProcessResult result = new doBatchProcessResult(); result.Result = FlagType.C_FLAG_ON; result.BatchStatus = null; result.Total = 0; result.Complete = 0; result.Failed = 0; result.ErrorMessage = string.Empty; result.BatchUser = UserId; ObjectParameter pTotoalEffectRow = new ObjectParameter("TotalEffectRow", typeof(int)); #endregion using (TransactionScope scope = new TransactionScope()) { try { //Call store procedure this.BatchGenDebtSummary(ProcessID.C_PROCESS_ID_GENERATE_DEBT_SUMMARY , BatchDate , BillingTypeGroup.C_BILLING_TYPE_GROUP_CONTINUES , PaymentStatus.C_PAYMENT_STATUS_INV_BANK_COLLECT , PaymentStatus.C_PAYMENT_STATUS_GEN_AUTO_CREDIT , PaymentStatus.C_PAYMENT_STATUS_INV_AUTO_CREDIT , PaymentStatus.C_PAYMENT_STATUS_FAIL_AUTO_INV_BANK , PaymentStatus.C_PAYMENT_STATUS_FAIL_NOTE_INV_BANK , PaymentStatus.C_PAYMENT_STATUS_FAIL_CHEQUE_INV_BANK , PaymentStatus.C_PAYMENT_STATUS_PARTIALLY_PAID , PaymentStatus.C_PAYMENT_STATUS_PARTIALLY_PAID_CN , pTotoalEffectRow); //Success scope.Complete(); result.Result = FlagType.C_FLAG_ON; result.Total = (int)pTotoalEffectRow.Value; result.Complete = (int)pTotoalEffectRow.Value; } catch (Exception ex) { scope.Dispose(); result.Result = FlagType.C_FLAG_OFF; result.Failed = 0; result.Total = 0; result.ErrorMessage += string.Format("Process has Error : {0} {1}\n", ex.Message, ex.InnerException != null ? ex.InnerException.Message : string.Empty); } } return(result); }
public doBatchProcessResult BatchAutoRenewProcess(string UserId, DateTime BatchDate) { //BatchDate = Convert.ToDateTime("2555-02-04"); doBatchProcessResult result = new doBatchProcessResult(); RentralContractHandler rcHandler = new RentralContractHandler(); MaintenanceHandler mHandler = new MaintenanceHandler(); List <doContractAutoRenew> doContractAutoRenewList = rcHandler.GetContractExpireNextMonth(BatchDate); // Initial value of doBatchProcessResult result.Result = FlagType.C_FLAG_ON; result.BatchStatus = null; result.Total = doContractAutoRenewList.Count; result.Complete = 0; result.Failed = 0; result.ErrorMessage = string.Empty; result.BatchUser = UserId; //DateTime dtEndDateOfNextMonth = (new DateTime(BatchDate.Year, BatchDate.Month + 2, 1)).AddDays(-1); //Add by Jutarat A. on 09052013 DateTime dtEndDateOfNextMonth = (new DateTime(BatchDate.Year, BatchDate.Month, 1)).AddMonths(2).AddDays(-1); //Add by Jutarat A. on 09052013 foreach (var doContractAutoRenew in doContractAutoRenewList) { using (TransactionScope scope = new TransactionScope()) { try { //================= Update implement data in rental security basic table ============== DateTime tmpDate = Convert.ToDateTime(doContractAutoRenew.CalContractEndDate).AddMonths(Convert.ToInt32(doContractAutoRenew.AutoRenewMonth)); //Add by Jutarat A. on 09052013 if (doContractAutoRenew.AutoRenewMonth != null && doContractAutoRenew.AutoRenewMonth > 0) { while (tmpDate <= dtEndDateOfNextMonth) { tmpDate = tmpDate.AddMonths(Convert.ToInt32(doContractAutoRenew.AutoRenewMonth)); } } //End Add base.UpdateAutoRenew(doContractAutoRenew.ContractCode, doContractAutoRenew.OCC, tmpDate, BatchDate, ProcessID.C_PROCESS_ID_AUTO_RENEW); //================= Update unimplement data in rental security basic table ============ string strUnimplementOCC = string.Empty; strUnimplementOCC = rcHandler.GetLastUnimplementedOCC(doContractAutoRenew.ContractCode); base.UpdateAutoRenew(doContractAutoRenew.ContractCode, strUnimplementOCC, tmpDate, BatchDate, ProcessID.C_PROCESS_ID_AUTO_RENEW); //if(doContractAutoRenew.ProductTypeCode == ProductType.C_PROD_TYPE_MA ) if (doContractAutoRenew.ProductTypeCode == ProductType.C_PROD_TYPE_MA || doContractAutoRenew.ProductTypeCode == ProductType.C_PROD_TYPE_AL || doContractAutoRenew.ProductTypeCode == ProductType.C_PROD_TYPE_RENTAL_SALE) //Modify by Jutarat A. on 11042013 { //mHandler.GenerateMaintenanceSchedule(doContractAutoRenew.ContractCode,GenerateMAProcessType.C_GEN_MA_TYPE_RE_CREATE); mHandler.GenerateMaintenanceSchedule(doContractAutoRenew.ContractCode, GenerateMAProcessType.C_GEN_MA_TYPE_RE_CREATE, BatchDate, ProcessID.C_PROCESS_ID_AUTO_RENEW, false); //Modify by Jutarat A. on 09052013 (Add createDate, createBy, isWriteTransLog) } scope.Complete(); result.Complete++; } catch (Exception ex) { scope.Dispose(); result.Failed++; result.ErrorMessage += string.Format("Error: {0} {1}\n", ex.Message, ex.InnerException != null ? ex.InnerException.Message : ""); } } } result.Result = result.Failed > 0 ? FlagType.C_FLAG_OFF : FlagType.C_FLAG_ON; return(result); }
public void RunProcess(dtBatchProcess batchProcess, string batchUser, DateTime batchDate, BatchCallBackDel callback) { doBatchProcessResult result = new doBatchProcessResult(); try { if (callback != null) { result.BatchName = batchProcess.BatchName; result.BatchCode = batchProcess.BatchCode; result.BatchStatus = BatchStatus.C_BATCH_STATUS_PROCESSING; result.BatchUser = batchUser; result.BatchDate = batchDate; callback(result); } string[] batchJobName = batchProcess.BatchJobName.Split(','); string assemblyName = batchJobName[0]; string typeName = assemblyName + '.' + batchJobName[1]; Assembly assembly = Assembly.Load(assemblyName + ", Version=0.0.0.0, PublicKeyToken=null,Culture=neutral"); Type type = assembly.GetType(typeName); IBatchProcess process = (IBatchProcess)Activator.CreateInstance(type); result = process.WorkProcess(batchUser, batchDate); // Added by Non A. 30/Mar/2012 : Set BatchStatus only if it's null. if (string.IsNullOrWhiteSpace(result.BatchStatus)) { if (result.Result == true) { result.BatchStatus = BatchStatus.C_BATCH_STATUS_SUCCEEDED; } else { result.BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED; } } } catch (Exception ex) { result.ErrorMessage = string.Format("{0} {1}", ex.Message, ex.InnerException != null ? ex.InnerException.Message : string.Empty); result.BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED; throw ex; } finally { if (string.IsNullOrWhiteSpace(result.BatchUser)) { result.BatchUser = batchUser; } result.BatchJobName = batchProcess.BatchCode; result.BatchName = batchProcess.BatchName; result.BatchCode = batchProcess.BatchCode; result.BatchDate = batchDate; if (callback != null) { callback(result); } } }
//IncomeHandler-BatchGenReceiptAfterPayment /// <summary> /// Batch Process to generate tax invoice pdf report, receipt pdf report after payment on shared report folder /// </summary> /// <param name="UserId">employee no.</param> /// <param name="BatchDate">process datetime</param> /// <returns></returns> public doBatchProcessResult ICP010_BatchGenReceiptAfterPaymentProcess(string UserId, DateTime BatchDate) { #region Prepare //Handler IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler; IBillingDocumentHandler billingDocumentHandler = ServiceContainer.GetService <IBillingDocumentHandler>() as IBillingDocumentHandler; IIncomeHandler incomeHandler = ServiceContainer.GetService <IIncomeHandler>() as IIncomeHandler; IIncomeDocumentHandler incomeDocumentHandler = ServiceContainer.GetService <IIncomeDocumentHandler>() as IIncomeDocumentHandler; //Get data List <doPaidInvoiceNoReceipt> paidInvoices = this.GetPaidInvoiceNoReceipt(); //Initial batch result doBatchProcessResult result = new doBatchProcessResult(); result.Result = FlagType.C_FLAG_ON; result.BatchStatus = null; result.Total = paidInvoices.Count; result.Failed = 0; result.Complete = 0; result.ErrorMessage = string.Empty; result.BatchUser = UserId; #endregion if (paidInvoices.Count > 0) { foreach (doPaidInvoiceNoReceipt doPaidInvoice in paidInvoices) { using (TransactionScope scope = new TransactionScope()) { try { doInvoice doInvoice = billingHandler.GetInvoice(doPaidInvoice.InvoiceNo); if (doPaidInvoice.BillingTypeGroup != BillingTypeGroup.C_BILLING_TYPE_GROUP_SALE && (doPaidInvoice.IssueReceiptTiming == IssueRecieptTime.C_ISSUE_REC_TIME_NOT_ISSUE || doPaidInvoice.IssueReceiptTiming == IssueRecieptTime.C_ISSUE_REC_TIME_AFTER_PAYMENT) ) { #region Issue tax invoice tbt_TaxInvoice doCheckTaxInvoice = billingHandler.GetTaxInvoiceData(doInvoice.InvoiceNo, doInvoice.InvoiceOCC); //Add by Jutarat A. on 04072013 if (doCheckTaxInvoice != null) //Add by Jutarat A. on 14112013 { //Add by Jutarat A. on 17102013 List <tbt_TaxInvoice> doCheckTaxInvoiceList = new List <tbt_TaxInvoice>(); doCheckTaxInvoiceList.Add(doCheckTaxInvoice); doCheckTaxInvoiceList = (from t in doCheckTaxInvoiceList where t.TaxInvoiceCanceledFlag == false select t).ToList <tbt_TaxInvoice>(); if (doCheckTaxInvoiceList != null && doCheckTaxInvoiceList.Count > 0) { doCheckTaxInvoice = CommonUtil.CloneObject <tbt_TaxInvoice, tbt_TaxInvoice>(doCheckTaxInvoiceList[0]); } else { doCheckTaxInvoice = null; } //End Add } if (doCheckTaxInvoice == null) //Add by Jutarat A. on 04072013 (Check not exist TaxInvoice) { tbt_TaxInvoice doTaxInvoice = billingHandler.IssueTaxInvoice( doInvoice, doPaidInvoice.PaymentDate, ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_AFTER_PAYMENT, BatchDate); if (doTaxInvoice != null) { // Comment by Jirawat Jannet //BLR020 TaxInvoice report //billingDocumentHandler.GenerateBLR020FilePath( // doTaxInvoice.TaxInvoiceNo // , ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_AFTER_PAYMENT // , BatchDate); throw new Exception("กำลังดำเนินการแก้ไข report BLR020"); } else { throw new Exception("Error generate tax invoice"); } } #endregion #region Issue receipt tbt_Receipt doReceipt = incomeHandler.IssueReceipt(doInvoice, doPaidInvoice.PaymentDate, ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_AFTER_PAYMENT, BatchDate, false); //Add (isWriteTransLog) by Jutarat A. on 07062013 if (doReceipt != null) { //ICR010 Receipt report incomeDocumentHandler.GenerateICR010FilePath(doReceipt.ReceiptNo , ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_AFTER_PAYMENT , BatchDate); if (doInvoice.BillingTypeCode == BillingType.C_BILLING_TYPE_DEPOSIT) { bool isSuccess = billingHandler.UpdateReceiptNoDepositFee(doPaidInvoice.InvoiceNo, doReceipt.ReceiptNo, ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_AFTER_PAYMENT, BatchDate); if (!isSuccess) { throw new Exception("Error update receipt no to deposit table"); } } } else { throw new Exception("Error generate receipt"); } #endregion } else { #region Issued receipt only DateTime receiptDate = doPaidInvoice.PaymentDate; if (doPaidInvoice.BillingTypeGroup != BillingTypeGroup.C_BILLING_TYPE_GROUP_SALE && doPaidInvoice.IssueReceiptTiming == IssueRecieptTime.C_ISSUE_REC_TIME_SAME_INV && (doPaidInvoice.PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_BANK_TRANSFER || doPaidInvoice.PaymentMethod == PaymentMethodType.C_PAYMENT_METHOD_MESSENGER)) { receiptDate = doPaidInvoice.IssueInvDate.Value; } tbt_Receipt doReceipt = incomeHandler.IssueReceipt(doInvoice, receiptDate, ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_AFTER_PAYMENT, BatchDate, false); //Add (isWriteTransLog) by Jutarat A. on 07062013 if (doReceipt != null) { //ICR010 Receipt report incomeDocumentHandler.GenerateICR010FilePath(doReceipt.ReceiptNo , ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_AFTER_PAYMENT , BatchDate); if (doInvoice.BillingTypeCode == BillingType.C_BILLING_TYPE_DEPOSIT) { bool isSuccess = billingHandler.UpdateReceiptNoDepositFee(doPaidInvoice.InvoiceNo, doReceipt.ReceiptNo, ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_AFTER_PAYMENT, BatchDate); if (!isSuccess) { throw new Exception("Error update receipt no to deposit table"); } } } else { throw new Exception("Error generate receipt"); } #endregion } //Success scope.Complete(); result.Complete++; } catch (Exception ex) { scope.Dispose(); result.Failed++; result.ErrorMessage += string.Format("Invoice no. {0} has Error : {1} {2}\n", doPaidInvoice.InvoiceNo, ex.Message, ex.InnerException != null ? ex.InnerException.Message : string.Empty); } } } //Update batch result, at lease one transaction fail => batch fail result.Result = (result.Failed == 0); } return(result); }
internal doBatchProcessResult BatchPrintDebtTracingNoticeProcess(string UserId, DateTime BatchDate, string strServiceTypeCode) { doBatchProcessResult result = new doBatchProcessResult(); IncomeHandler incomeHandler = new IncomeHandler(); ILogHandler logHandler = ServiceContainer.GetService <ILogHandler>() as ILogHandler; ICommonHandler comHandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; string pathFoxit = ConfigurationManager.AppSettings["PrintPDFFoxit"]; string pathFileName = string.Empty; string processID = (strServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE ? ProcessID.C_PROCESS_ID_PRINTING_DEBT_NOTICE_SALE : ProcessID.C_PROCESS_ID_PRINTING_DEBT_NOTICE_RENTAL); string printflag = (strServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE ? PrintingFlag.C_PRINTING_FLAG_ICP080 : PrintingFlag.C_PRINTING_FLAG_ICP090); List <doDebtTracingDocNoForPrinting> lstDocNo = incomeHandler.GetDebtTracingDocNoForPrinting(BatchDate, strServiceTypeCode); if (lstDocNo != null && lstDocNo.Count > 0) { result.Result = false; result.Total = lstDocNo.Count; result.Complete = 0; result.Failed = 0; result.ErrorMessage = string.Empty; string strErrorMessage = string.Empty; bool bResult = comHandler.AllocatePrintingProcess(printflag, processID, ref strErrorMessage); if (bResult) { foreach (doDebtTracingDocNoForPrinting doc in lstDocNo) { using (TransactionScope scope = new TransactionScope()) { try { doDocumentDownloadLog cond = new doDocumentDownloadLog(); cond.DocumentNo = doc.DocumentNo; cond.DocumentCode = doc.DocumentCode; cond.DocumentOCC = doc.DocumentOCC; cond.DownloadDate = BatchDate; cond.DownloadBy = processID; logHandler.WriteDocumentDownloadLog(cond); incomeHandler.UpdateDebtTracingNoticePrintFlag(doc.DocumentNo); comHandler.PrintPDF(doc.FilePathDocument); scope.Complete(); result.Complete++; } catch (Exception ex) { scope.Dispose(); result.Failed++; result.ErrorMessage += string.Format("DocumentNo {0} DocumentCode {1} DocumentOCC {2} has Error : {3} {4}\n" , doc.DocumentNo , doc.DocumentCode , doc.DocumentOCC , ex.Message , ex.InnerException != null ? ex.InnerException.Message : "" ); break; } } } bResult = comHandler.ResetPrintingProcess(processID); } else { result.Failed = result.Total; if (String.IsNullOrEmpty(strErrorMessage) == false) { result.ErrorMessage = strErrorMessage; } } } result.Result = (result.Failed == 0); result.BatchStatus = (result.Result ? BatchStatus.C_BATCH_STATUS_SUCCEEDED : BatchStatus.C_BATCH_STATUS_FAILED); return(result); }
internal doBatchProcessResult BatchGenerateDebtTracingNoticeProcess(string UserId, DateTime BatchDate, string strServiceTypeCode) { string BatchUserID = (strServiceTypeCode == ServiceType.C_SERVICE_TYPE_SALE ? "ICP060" : "ICP070"); try { var handler = new IncomeHandler(); var dochandler = new IncomeDocumentHandler(); handler.GenerateDebtTracingNotice(BatchDate, null, strServiceTypeCode, BatchDate, BatchUserID); List <doDebtTracingDocNoForGenerate> lstDocNo = handler.GetDebtTracingDocNoForGenerate(BatchDate, strServiceTypeCode); var result = new doBatchProcessResult() { Result = FlagType.C_FLAG_ON, BatchStatus = BatchStatus.C_BATCH_STATUS_SUCCEEDED, Total = lstDocNo.Count, Complete = 0, Failed = 0, ErrorMessage = null, BatchUser = BatchUserID, BatchDate = BatchDate }; foreach (var doc in lstDocNo) { using (TransactionScope scope = new TransactionScope()) { try { string reportpath = null; if (doc.DocumentType == RunningType.C_RUNNING_TYPE_DEBT_TRACING_NOTICE1) { reportpath = dochandler.GenerateICR030FilePath(doc.DocumentNo, BatchUserID, BatchDate); } else if (doc.DocumentType == RunningType.C_RUNNING_TYPE_DEBT_TRACING_NOTICE2) { reportpath = dochandler.GenerateICR040FilePath(doc.DocumentNo, BatchUserID, BatchDate); } handler.UpdateDebtTracingNoticeGenerateFlag(doc.DocumentNo); if (string.IsNullOrEmpty(reportpath)) { result.Failed++; } else { result.Complete++; } scope.Complete(); } catch (Exception ex) { result.Failed++; result.ErrorMessage = ex.Message; scope.Dispose(); return(result); } } } return(result); } catch (Exception ex) { return(new doBatchProcessResult() { Result = FlagType.C_FLAG_OFF, BatchStatus = BatchStatus.C_BATCH_STATUS_FAILED, Total = 1, Complete = 0, Failed = 1, ErrorMessage = ex.Message, //msg.Message, BatchUser = BatchUserID, BatchDate = BatchDate }); } }
//IncomeHandler-BatchDeleteDebtTracing /// <summary> /// Batch Process to delete unused deb tracing information. call "sp_IC_BatchDeleteDebtTracing" store procedure /// </summary> /// <param name="UserId">employee no.</param> /// <param name="BatchDate">process datetime</param> /// <returns></returns> public doBatchProcessResult ICP050_BatchDeleteDebtTracingProcess(string UserId, DateTime BatchDate) { #region Prepare //Result doBatchProcessResult result = new doBatchProcessResult(); result.Result = FlagType.C_FLAG_ON; result.BatchStatus = null; result.Total = 0; result.Complete = 0; result.Failed = 0; result.ErrorMessage = string.Empty; result.BatchUser = UserId; ObjectParameter pTotalRow = new ObjectParameter("TotalRow", typeof(int)); ObjectParameter pCompletedRow = new ObjectParameter("CompletedRow", typeof(int)); #endregion using (TransactionScope scope = new TransactionScope()) { try { //Call store procedure this.BatchDeleteDebtTracing( PaymentStatus.C_PAYMENT_STATUS_BANK_PAID , PaymentStatus.C_PAYMENT_STATUS_AUTO_PAID , PaymentStatus.C_PAYMENT_STATUS_CANCEL , PaymentStatus.C_PAYMENT_STATUS_CASH_PAID , PaymentStatus.C_PAYMENT_STATUS_PAYMENT_MATCH_CANCELLED , PaymentStatus.C_PAYMENT_STATUS_BILLING_EXEMPTION , PaymentStatus.C_PAYMENT_STATUS_CHEQUE_PAID , PaymentStatus.C_PAYMENT_STATUS_NOTE_MATCHED , PaymentStatus.C_PAYMENT_STATUS_NOTE_ENCASHED , PaymentStatus.C_PAYMENT_STATUS_NOTE_FAIL , PaymentStatus.C_PAYMENT_STATUS_CASHIER_PAID , PaymentStatus.C_PAYMENT_STATUS_POST_MATCHED , PaymentStatus.C_PAYMENT_STATUS_POST_ENCASHED , PaymentStatus.C_PAYMENT_STATUS_POST_FAIL , PaymentStatus.C_PAYMENT_STATUS_AUTO_FAIL_BANK_PAID , PaymentStatus.C_PAYMENT_STATUS_NOTE_FAIL_BANK_PAID , PaymentStatus.C_PAYMENT_STATUS_POST_FAIL_BANK_PAID , PaymentStatus.C_PAYMENT_STATUS_PAID_WITH_PARTIAL_CN , PaymentStatus.C_PAYMENT_STATUS_PAID_WITH_PARTIAL_REFUND , PaymentStatus.C_PAYMENT_STATUS_REFUND_PAID , pTotalRow , pCompletedRow); //Success scope.Complete(); result.Result = FlagType.C_FLAG_ON; result.Total = (int)pTotalRow.Value; result.Complete = (int)pCompletedRow.Value; } catch (Exception ex) { scope.Dispose(); result.Result = FlagType.C_FLAG_OFF; result.Total = 0; result.Failed = 0; result.ErrorMessage += string.Format("Process has Error : {0} {1}\n", ex.Message, ex.InnerException != null ? ex.InnerException.Message : string.Empty); } } return(result); }
//IncomeHandler-BatchGenAdvanceReceipt /// <summary> /// Batch Process to generate advance receipt pdf report on shared report folder /// </summary> /// <param name="UserId">employee no.</param> /// <param name="BatchDate">process datetime</param> /// <returns></returns> public doBatchProcessResult ICP011_BatchGenAdvanceReceiptProcess(string UserId, DateTime BatchDate) { #region Prepare //Handler IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler; IBillingDocumentHandler billingDocumentHandler = ServiceContainer.GetService <IBillingDocumentHandler>() as IBillingDocumentHandler; IIncomeHandler incomeHandler = ServiceContainer.GetService <IIncomeHandler>() as IIncomeHandler; IIncomeDocumentHandler incomeDocumentHandler = ServiceContainer.GetService <IIncomeDocumentHandler>() as IIncomeDocumentHandler; //Get data List <doInvoiceAdvanceReceipt> invoiceAdvanceReceipts = this.GetInvoiceAdvanceReceipt(); //Result doBatchProcessResult result = new doBatchProcessResult(); result.Result = FlagType.C_FLAG_ON; result.BatchStatus = null; result.Total = invoiceAdvanceReceipts.Count; result.Failed = 0; result.Complete = 0; result.ErrorMessage = string.Empty; result.BatchUser = UserId; #endregion if (invoiceAdvanceReceipts.Count > 0) { foreach (doInvoiceAdvanceReceipt doAdvanceReceipt in invoiceAdvanceReceipts) { using (TransactionScope scope = new TransactionScope()) { try { doInvoice doInvoice = CommonUtil.CloneObject <doInvoiceAdvanceReceipt, doInvoice>(doAdvanceReceipt); tbt_Receipt doReceipt = incomeHandler.IssueAdvanceReceipt(doInvoice, doInvoice.IssueInvDate.Value , ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_ADVANCE, BatchDate); if (doReceipt != null) { //ICR010 Receipt report incomeDocumentHandler.GenerateICR010FilePath(doReceipt.ReceiptNo , ProcessID.C_PROCESS_ID_GENERATE_RECEIPT_ADVANCE , BatchDate); } else { throw new Exception("Error issue receipt"); } //Success scope.Complete(); result.Complete++; } catch (Exception ex) { scope.Dispose(); result.Failed++; result.ErrorMessage += string.Format("Invoice no. {0} has Error : {1} {2}\n", doAdvanceReceipt.InvoiceNo, ex.Message, ex.InnerException != null ? ex.InnerException.Message : string.Empty); } } } //Update batch result, at lease one transaction fail => batch fail result.Result = (result.Failed == 0); } return(result); }
// CMP120 /// <summary> /// Batch Printing Service Process (call sp_CM_DocumentListForPrining) /// </summary> /// <param name="UserId">User id</param> /// <param name="BatchDate">Batch date</param> /// <returns></returns> public doBatchProcessResult CMP120_PrintingServiceProcess(string UserId, DateTime BatchDate) { doBatchProcessResult result = new doBatchProcessResult(); DocumentHandler documentHandler = new DocumentHandler(); ILogHandler logHandler = ServiceContainer.GetService <ILogHandler>() as ILogHandler; IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler; ICommonHandler comHandler = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler; //Add by Jutarat A. on 17092013 //--- variable string pathFoxit = ConfigurationManager.AppSettings["PrintPDFFoxit"]; string pathFileName = string.Empty; List <dtDocumentListForPrining> dtDocumentListForPriningData = documentHandler.GetDocumentListForPrining(DocumentType.C_DOCUMENT_TYPE_INCOME, DocumentType.C_DOCUMENT_TYPE_COMMON, BatchDate, null, null); if (dtDocumentListForPriningData != null && dtDocumentListForPriningData.Count > 0) { // Initial value of doBatchProcessResult result.Result = false; result.Total = dtDocumentListForPriningData.Count; result.Complete = 0; result.Failed = 0; result.ErrorMessage = string.Empty; //logHandler.SearchFoxitProcess("CMP120"); //Add by Jutarat A. on 20082013 //} //Add by Jutarat A. on 17092013 string strErrorMessage = string.Empty; bool bResult = comHandler.AllocatePrintingProcess(PrintingFlag.C_PRINTING_FLAG_CMP120, ProcessID.C_PROCESS_ID_PRINTING_SERVICE, ref strErrorMessage); if (bResult) //End Add { foreach (dtDocumentListForPrining list in dtDocumentListForPriningData) { using (TransactionScope scope = new TransactionScope()) { try { //3.1 doDocumentDownloadLog cond = new doDocumentDownloadLog(); cond.DocumentNo = list.DocumentNo; cond.DocumentCode = list.DocumentCode; cond.DocumentOCC = list.DocumentOCC; cond.DownloadDate = BatchDate; cond.DownloadBy = ProcessID.C_PROCESS_ID_PRINTING_SERVICE; logHandler.WriteDocumentDownloadLog(cond); //============ Teerapong 23/07/2012 =============== billingHandler.UpdateFirstIssue(list.DocumentNo, cond.DocumentOCC, BatchDate, UserId); //================================================= //3.2 Send data to specified printer to print documents //PrintPDF(list.FilePathDocument); comHandler.PrintPDF(list.FilePathDocument); //Modify by Jutarat A. on 17092013 //3.3 scope.Complete(); result.Complete++; } catch (Exception ex) { scope.Dispose(); result.Failed++; result.ErrorMessage += string.Format("DocumentNo {0} DocumentCode {1} DocumentOCC {2} has Error : {3} {4}\n", list.DocumentNo, list.DocumentCode, list.DocumentOCC, ex.Message, ex.InnerException != null ? ex.InnerException.Message : ""); break; //Add by Jutarat A. on 03072013 } } } bResult = comHandler.ResetPrintingProcess(ProcessID.C_PROCESS_ID_PRINTING_SERVICE); //Add by Jutarat A. on 17092013 } //Add by Jutarat A. on 17092013 else { result.Failed = result.Total; if (String.IsNullOrEmpty(strErrorMessage) == false) { result.ErrorMessage = strErrorMessage; } } //End Add } result.Result = (result.Failed == 0); result.BatchStatus = (result.Result ? BatchStatus.C_BATCH_STATUS_SUCCEEDED : BatchStatus.C_BATCH_STATUS_FAILED); return(result); }
// 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); }
// CMP130 /// <summary> /// Batch Generate Issue List Process (sp_CM_GetBillingOffice, sp_CM_GetMaxmanagementNo, sp_CM_GetNextIssueListNo, ) /// </summary> /// <param name="UserId">User id</param> /// <param name="BatchDate">Batch date</param> /// <returns></returns> public doBatchProcessResult CMP130_GenerateIssueListProcess(string UserId, DateTime BatchDate) { doBatchProcessResult result = new doBatchProcessResult(); DocumentHandler documentHandler = new DocumentHandler(); List <dtBillingOffice> dtBillingOfficeList = documentHandler.GetBillingOffice(DocumentType.C_DOCUMENT_TYPE_INCOME, (DateTime?)BatchDate); if (dtBillingOfficeList.Count > 0) { // Initial value of doBatchProcessResult result.Result = false; //Comment by Jutarat A. on 04012013 (Move to set data after process) //result.Total = dtBillingOfficeList.Count; //result.Complete = 0; //result.Failed = 0; //End Comment result.ErrorMessage = string.Empty; } //Add by Jutarat A. on 04012013 int iTotalCount = 0; int iSuccessCount = 0; //End Add foreach (dtBillingOffice list in dtBillingOfficeList) { using (TransactionScope scope = new TransactionScope()) { //Add by Jutarat A. on 04012013 bool hasIssueList = false; bool isSuccess = false; //End Add try { //1.2.2 Get max No List <int?> iMaxManagementNo = documentHandler.GetMaxManagementNo(DocumentType.C_DOCUMENT_TYPE_INCOME, list.Issuedate); if (iMaxManagementNo.Count > 0) { //Name Code IssueListNo - yyyymmdd string strIssueNo = documentHandler.GetNextIssueListNo("IssueListNo-" + DateTime.Now.ToString("yyyyMMdd")); string pdfReport = documentHandler.GenerateCMR010FilePath(strIssueNo, list.BillingOfficeCode, iMaxManagementNo[0], ProcessID.C_PROCESS_ID_GENERATE_ISSUE_LIST, list.Issuedate.Value, ref hasIssueList, ref isSuccess); //Modify by Jutarat A. (Add isSuccess) on 04012013 //Complete scope.Complete(); result.Complete++; } } catch (Exception ex) { scope.Dispose(); result.Failed++; result.ErrorMessage += string.Format("BillingOfficeCode {0} has Error : {1} {2}\n", list.BillingOfficeCode, ex.Message, ex.InnerException != null ? ex.InnerException.Message : ""); } //Add by Jutarat A. on 04012013 if (hasIssueList) { iTotalCount++; if (isSuccess) { iSuccessCount++; } } //End Add } } //Add by Jutarat A. on 04012013 result.Total = iTotalCount; result.Complete = iSuccessCount; result.Failed = (iTotalCount - iSuccessCount); //End Add result.Result = (result.Failed == 0); result.BatchStatus = (result.Result?BatchStatus.C_BATCH_STATUS_SUCCEEDED:BatchStatus.C_BATCH_STATUS_FAILED); return(result); }