Esempio n. 1
0
        /// <summary>
        /// Generate revenue no. and save revenue information to DB.
        /// </summary>
        /// <param name="_dotbt_Revenue"></param>
        /// <returns></returns>
        public tbt_Revenue RegisterRevenue(tbt_Revenue _dotbt_Revenue)
        {
            try
            {
                IBillingHandler iBillingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
                _dotbt_Revenue.RevenueNo = iBillingHandler.GetNextRunningNoByTypeMonthYear(RunningType.C_RUNNING_TYPE_REVENUE);

                //set CreateDate, CreateBy, UpdateDate and UpdateBy
                _dotbt_Revenue.CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                _dotbt_Revenue.CreateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                _dotbt_Revenue.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                _dotbt_Revenue.UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;

                if (InsertTbt_Revenue(_dotbt_Revenue) == 0)
                {
                    return(null);
                }
                else
                {
                    return(_dotbt_Revenue);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Function for generate credit note no. and save credit note information to DB.
        /// </summary>
        /// <param name="_dotbt_CreditNote">credit note information</param>
        /// <returns></returns>
        public tbt_CreditNote RegisterCreditNote(tbt_CreditNote _dotbt_CreditNote)
        {
            try
            {
                IBillingHandler iBillingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
                _dotbt_CreditNote.CreditNoteNo = iBillingHandler.GetNextRunningNoByTypeMonthYear(RunningType.C_RUNNING_TYPE_CREDIT_NOTE, CommonUtil.dsTransData.dtUserData.EmpNo, _dotbt_CreditNote.CreditNoteDate == null ? CommonUtil.dsTransData.dtOperationData.ProcessDateTime : _dotbt_CreditNote.CreditNoteDate.Value);

                //set CreateDate, CreateBy, UpdateDate and UpdateBy
                _dotbt_CreditNote.CreateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                _dotbt_CreditNote.CreateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;
                _dotbt_CreditNote.UpdateDate = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                _dotbt_CreditNote.UpdateBy   = CommonUtil.dsTransData.dtUserData.EmpNo;

                _dotbt_CreditNote.CancelFlag = false;

                if (InsertTbt_CreditNote(_dotbt_CreditNote) == 0)
                {
                    return(null);
                }
                else
                {
                    return(_dotbt_CreditNote);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        //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);
        }
        /// <summary>
        /// Update receipt status that has been register with a payment. (sp_IC_UpdateAdvanceReceiptRegisterPayment)
        /// </summary>
        /// <param name="receiptNo">receipt no.</param>
        /// <returns></returns>
        public List <tbt_Payment> RegisterPayment(List <tbt_Payment> payments)
        {
            IBillingHandler handler       = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
            string          paymentTranNo = string.Empty;

            foreach (var item in payments)
            {
                paymentTranNo = handler.GetNextRunningNoByTypeMonthYear(RunningType.C_RUNNING_TYPE_PAYMENT_TRANS);

                item.PaymentTransNo = paymentTranNo;
                item.CreateBy       = CommonUtil.dsTransData.dtUserData.EmpNo;
                item.CreateDate     = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
                item.UpdateBy       = CommonUtil.dsTransData.dtUserData.EmpNo;
                item.UpdateDate     = CommonUtil.dsTransData.dtOperationData.ProcessDateTime;
            }

            List <tbt_Payment> result = this.InsertTbt_Payment(CommonUtil.ConvertToXml_Store <tbt_Payment>(payments));

            if (result.Count == payments.Count)
            {
                foreach (var item in result)
                {
                    if (!CommonUtil.IsNullOrEmpty(item.RefAdvanceReceiptNo))
                    {
                        if (!UpdateAdvanceReceiptRegisterPayment(item.RefAdvanceReceiptNo))
                        {
                            //Fail
                            return(null);
                        }
                    }
                }
            }
            else
            {
                //Fail
                return(null);
            }
            //Success
            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);
        }