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