/// <summary> /// Function for update Receipt information to DB. (sp_IC_UpdateTbt_Receipt) /// </summary> /// <param name="doTbt_Receipt">Receipt information</param> /// <returns></returns> public int UpdateTbt_Receipt(tbt_Receipt doTbt_Receipt) { try { //set updateDate and updateBy doTbt_Receipt.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime; doTbt_Receipt.UpdateBy = CommonUtil.dsTransData.dtUserData.EmpNo; List <tbt_Receipt> doUpdateList = new List <tbt_Receipt>(); doUpdateList.Add(doTbt_Receipt); List <tbt_Receipt> updatedList = base.UpdateTbt_Receipt(CommonUtil.ConvertToXml_Store <tbt_Receipt>(doUpdateList)); //Insert Log if (updatedList != null && updatedList.Count > 0) { doTransactionLog logData = new doTransactionLog(); logData.TransactionType = doTransactionLog.eTransactionType.Update; logData.TableName = TableName.C_TBL_NAME_RECEIPT; logData.TableData = CommonUtil.ConvertToXml(updatedList); ILogHandler hand = ServiceContainer.GetService <ILogHandler>() as ILogHandler; hand.WriteTransactionLog(logData); } return(updatedList.Count); } catch (Exception ex) { throw ex; } }
//ICP010 /// <summary> /// Function for issue a receipt for paid invoice (after payment matched) (Used by batch). /// </summary> /// <param name="doInvoice">invoice information</param> /// <param name="receiptDate">receipt date</param> /// <param name="batchId">batch id</param> /// <param name="batchDate">batch datetime</param> /// <returns></returns> public tbt_Receipt IssueReceipt(doInvoice doInvoice, DateTime receiptDate, string batchId, DateTime batchDate, bool isWriteTransLog = true) //Add (isWriteTransLog) by Jutarat A. on 07062013 { IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler; //call running no for batch process string receiptNo = billingHandler.GetNextRunningNoByTypeMonthYear(RunningType.C_RUNNING_TYPE_RECEIPT, batchId, receiptDate /*batchDate*/); //Edit by Patcharee T. For issue Reciept no. in month of receiptDate 11-Jun-2013 //Determin receipt issue flag bool receiptIssueFlag = doInvoice.IssueReceiptTiming == IssueRecieptTime.C_ISSUE_REC_TIME_NOT_ISSUE ? false : true; tbt_Receipt doReceipt = new tbt_Receipt() { ReceiptNo = receiptNo, ReceiptDate = receiptDate, BillingTargetCode = doInvoice.BillingTargetCode, InvoiceNo = doInvoice.InvoiceNo, InvoiceOCC = doInvoice.InvoiceOCC, ReceiptAmount = (doInvoice.PaidAmountIncVat ?? 0) + (doInvoice.RegisteredWHTAmount ?? 0), AdvanceReceiptStatus = AdvanceReceiptStatus.C_INC_ADVANCE_RECEIPT_STATUS_NOT, ReceiptIssueFlag = receiptIssueFlag, CancelFlag = false, CreateDate = batchDate, CreateBy = batchId, UpdateDate = batchDate, UpdateBy = batchId }; List <tbt_Receipt> receipts = new List <tbt_Receipt>(); receipts.Add(doReceipt); List <tbt_Receipt> result = this.InsertTbt_Receipt(receipts, isWriteTransLog); //Add (isWriteTransLog) by Jutarat A. on 07062013 if (result != null && result.Count > 0) { bool isSuccess = billingHandler.UpdateReceiptNo(doInvoice.InvoiceNo, doInvoice.InvoiceOCC, receiptNo, batchId, batchDate); //Success if (isSuccess) { return(result[0]); } } //all fail, No insert data return(null); }
//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); }
//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); }
//ICP011 /// <summary> /// Function for issue an advance issued receipt for unpaid invoice. (Used by batch) /// </summary> /// <param name="doInvoice">invoice information</param> /// <param name="receiptDate">receipt date</param> /// <param name="batchId">batch id</param> /// <param name="batchDate">batch datetime</param> /// <returns></returns> public tbt_Receipt IssueAdvanceReceipt(doInvoice doInvoice, DateTime receiptDate, string batchId, DateTime batchDate) { IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler; //Genereate receipt no string receiptNo = billingHandler.GetNextRunningNoByTypeMonthYear(RunningType.C_RUNNING_TYPE_RECEIPT, batchId, receiptDate /*batchDate*/); //Edit by Patcharee T. For issue Reciept no. in month of receiptDate 11-Jun-2013 //Determine advacen receipt status string advanceReceiptStatus = string.Empty; if (doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_INV_BANK_COLLECT || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_GEN_AUTO_CREDIT || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_INV_AUTO_CREDIT || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_FAIL_AUTO_INV_BANK || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_FAIL_NOTE_INV_BANK || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_FAIL_CHEQUE_INV_BANK || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_PARTIALLY_PAID || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_PARTIALLY_PAID_CN) { advanceReceiptStatus = AdvanceReceiptStatus.C_INC_ADVANCE_RECEIPT_STATUS_ISSUED; } else { advanceReceiptStatus = AdvanceReceiptStatus.C_INC_ADVANCE_RECEIPT_STATUS_NOT; } //Determin receipt issue flag bool receiptIssueFlag = doInvoice.IssueReceiptTiming == IssueRecieptTime.C_ISSUE_REC_TIME_NOT_ISSUE ? false : true; //Prepare receipt tbt_Receipt doReceipt = new tbt_Receipt() { ReceiptNo = receiptNo, ReceiptDate = receiptDate, BillingTargetCode = doInvoice.BillingTargetCode, InvoiceNo = doInvoice.InvoiceNo, InvoiceOCC = doInvoice.InvoiceOCC, ReceiptAmount = (doInvoice.InvoiceAmount ?? 0) + (doInvoice.VatAmount ?? 0), AdvanceReceiptStatus = advanceReceiptStatus, ReceiptIssueFlag = receiptIssueFlag, CancelFlag = false, CreateDate = batchDate, CreateBy = batchId, UpdateDate = batchDate, UpdateBy = batchId }; List <tbt_Receipt> receipts = new List <tbt_Receipt>(); receipts.Add(doReceipt); List <tbt_Receipt> result = this.InsertTbt_Receipt(receipts, false); //Modify (Add isWriteTransLog) by Jutarat A. on 27022014 if (result != null && result.Count > 0) { //Update receipt no. to taxinvoice bool isSuccess = billingHandler.UpdateReceiptNo(doInvoice.InvoiceNo, doInvoice.InvoiceOCC, receiptNo, batchId, batchDate); if (isSuccess) { //Success return(result[0]); } } //All fail, No insert data return(null); }
//ICS050 /// <summary> /// Function for force issue receipt of specific invoice information and receipt date. /// </summary> /// <param name="doInvoice">invoice information</param> /// <param name="receiptDate">receipt date</param> /// <returns></returns> public tbt_Receipt ForceIssueReceipt(doInvoice doInvoice, DateTime receiptDate) { IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler; //Genereate receipt no string receiptNo = billingHandler.GetNextRunningNoByTypeMonthYear(RunningType.C_RUNNING_TYPE_RECEIPT , CommonUtil.dsTransData.dtUserData.EmpNo , receiptDate /*CommonUtil.dsTransData.dtOperationData.ProcessDateTime*/); //Edit by Patcharee T. For get Reciept no. in month of receiptDate 11-Jun-2013 //Determine advacen receipt status string advanceReceiptStatus = string.Empty; if (doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_INV_BANK_COLLECT || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_GEN_AUTO_CREDIT || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_INV_AUTO_CREDIT || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_FAIL_AUTO_INV_BANK || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_FAIL_NOTE_INV_BANK || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_FAIL_CHEQUE_INV_BANK || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_PARTIALLY_PAID || doInvoice.InvoicePaymentStatus == PaymentStatus.C_PAYMENT_STATUS_PARTIALLY_PAID_CN) { advanceReceiptStatus = AdvanceReceiptStatus.C_INC_ADVANCE_RECEIPT_STATUS_ISSUED; } else { advanceReceiptStatus = AdvanceReceiptStatus.C_INC_ADVANCE_RECEIPT_STATUS_NOT; } decimal?ReceiptAmt = (doInvoice.InvoiceAmount ?? 0) + (doInvoice.VatAmount ?? 0); //Prepare receipt tbt_Receipt doReceipt = new tbt_Receipt() { ReceiptNo = receiptNo, ReceiptDate = receiptDate, BillingTargetCode = doInvoice.BillingTargetCode, InvoiceNo = doInvoice.InvoiceNo, InvoiceOCC = doInvoice.InvoiceOCC, ReceiptAmount = doInvoice.InvoiceAmountCurrencyType == CurrencyUtil.C_CURRENCY_LOCAL ? ReceiptAmt : null, ReceiptAmountUsd = doInvoice.InvoiceAmountCurrencyType == CurrencyUtil.C_CURRENCY_US ? ReceiptAmt : null, ReceiptAmountCurrencyType = doInvoice.InvoiceAmountCurrencyType, AdvanceReceiptStatus = advanceReceiptStatus, ReceiptIssueFlag = true, CancelFlag = false, CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime, CreateBy = CommonUtil.dsTransData.dtUserData.EmpNo, UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime, UpdateBy = CommonUtil.dsTransData.dtUserData.EmpNo }; List <tbt_Receipt> receipts = new List <tbt_Receipt>(); receipts.Add(doReceipt); List <tbt_Receipt> result = this.InsertTbt_Receipt(receipts); if (result != null && result.Count > 0) { //Update receipt no. to taxinvoice bool isSuccess = billingHandler.UpdateReceiptNo(doInvoice.InvoiceNo, doInvoice.InvoiceOCC, receiptNo, CommonUtil.dsTransData.dtUserData.EmpNo, CommonUtil.dsTransData.dtOperationData.ProcessDateTime); if (isSuccess) { //Success return(result[0]); } } //All fail, No insert data return(null); }