//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);
        }
Пример #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));
        }
        //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);
        }