/// <summary>
        /// Retrieve invoice information of specific invoice no.
        /// </summary>
        /// <param name="invoiceNo">invoice no.</param>
        /// <param name="res"></param>
        /// <returns></returns>
        private doInvoice ICS040_GetInvoice(string invoiceNo, ObjectResultData res)
        {
            IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
            ValidatorUtil   validator      = new ValidatorUtil();
            doInvoice       doInvoice      = billingHandler.GetInvoice(invoiceNo);

            if (doInvoice == null)
            {
                validator.AddErrorMessage(MessageUtil.MODULE_INCOME, "ICS040"
                                          , MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7003
                                          , "InvoiceNo", "lblInvoiceNo", "InvoiceNo");

                ValidatorUtil.BuildErrorMessage(res, validator, null);
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                return(null);
            }
            return(doInvoice);
        }
Exemple #2
0
        /// <summary>
        /// Event when click confirm cancel button, this function will cancel the issued receipt information of specific receipt no. to the system.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult ICS060_cmdConfirmCancel(ICS060_ScreenParameter param)
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;
            doReceipt doReceipt;

            try
            {
                if (IsSuspend(res))
                {
                    return(Json(res));
                }

                if (!ICS060_IsAllowOperate(res))
                {
                    return(Json(res));
                }


                //Validate receipt business
                doReceipt = ICS060_ValidateReceiptBusiness(param, res);
                if (res.IsError || doReceipt == null)
                {
                    return(Json(res));
                }


                //Connect db
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        //Cancel receipt
                        IIncomeHandler incomeHandler = ServiceContainer.GetService <IIncomeHandler>() as IIncomeHandler;

                        bool isSuccess = incomeHandler.CancelReceipt(doReceipt);
                        if (!isSuccess)
                        {
                            throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7031, null);
                        }

                        IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
                        //Get Invoice
                        doInvoice doInvoice = billingHandler.GetInvoice(doReceipt.InvoiceNo);
                        if (doInvoice == null)
                        {
                            throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7031, null);
                        }

                        //string invoiceType = billingHandler.GetInvoiceType(doInvoice.BillingTypeCode);
                        //if ((invoiceType == InvoiceType.C_INVOICE_TYPE_DEPOSIT || invoiceType == InvoiceType.C_INVOICE_TYPE_SERVICE)
                        //    && (doInvoice.IssueReceiptTiming != IssueRecieptTime.C_ISSUE_REC_TIME_SAME_INV
                        //        || (doInvoice.IssueReceiptTiming == IssueRecieptTime.C_ISSUE_REC_TIME_SAME_INV
                        //             && doInvoice.PaymentMethod == PaymentMethod.C_PAYMENT_METHOD_MESSENGER_TRANSFER)))
                        bool isIssuedTaxInvoice = billingHandler.CheckInvoiceIssuedTaxInvoice(doReceipt.InvoiceNo, doReceipt.InvoiceOCC);
                        if (isIssuedTaxInvoice == true)
                        {
                            if (param.CancelMethod == CancelReceiptTarget.C_CANCEL_TAX_INVOICE_RECEIPT)
                            {
                                //Cancel tax invoice (Update cancel flag only)
                                isSuccess = billingHandler.CancelTaxInvoice(doReceipt.TaxInvoiceNo);
                                if (!isSuccess)
                                {
                                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7032, null);
                                }
                            }
                            else
                            {
                                //Clear receipt no.
                                isSuccess = billingHandler.UpdateReceiptNo(doReceipt.InvoiceNo, doReceipt.InvoiceOCC, null);
                                if (!isSuccess)
                                {
                                    throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7032, null);
                                }
                            }
                        }


                        //Clear receipt no, invoice no of deposit fee
                        if (doInvoice.BillingTypeCode == BillingType.C_BILLING_TYPE_DEPOSIT &&
                            (doReceipt.AdvanceReceiptStatus == AdvanceReceiptStatus.C_INC_ADVANCE_RECEIPT_STATUS_NOT ||
                             doReceipt.AdvanceReceiptStatus == AdvanceReceiptStatus.C_INC_ADVANCE_RECEIPT_STATUS_PAID))
                        {
                            isSuccess = billingHandler.UpdateReceiptNoDepositFeeCancelReceipt(doInvoice.InvoiceNo, doReceipt.ReceiptNo
                                                                                              , CommonUtil.dsTransData.dtUserData.EmpNo
                                                                                              , CommonUtil.dsTransData.dtOperationData.ProcessDateTime);

                            if (!isSuccess)
                            {
                                throw ApplicationErrorException.ThrowErrorException(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7032, null);
                            }
                        }


                        //Show attention in case of paid receipt
                        if (doReceipt.AdvanceReceiptStatus == SECOM_AJIS.Common.Util.ConstantValue.AdvanceReceiptStatus.C_INC_ADVANCE_RECEIPT_STATUS_NOT ||
                            doReceipt.AdvanceReceiptStatus == SECOM_AJIS.Common.Util.ConstantValue.AdvanceReceiptStatus.C_INC_ADVANCE_RECEIPT_STATUS_PAID)
                        {
                            res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION_OK;
                            res.AddErrorMessage(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7030);
                        }

                        //Success
                        scope.Complete();
                        res.ResultData = "1";
                    }
                    catch (Exception ex)
                    {
                        scope.Dispose();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }
Exemple #3
0
        //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);
        }