Ejemplo n.º 1
0
        /**
         *  Create Check for Payment
         *	@param ctx context
         *	@param C_Payment_ID id
         *	@param trxName transaction
         *	@return pay selection check for payment or null
         */
        public static MPaySelectionCheck CreateForPayment(Ctx ctx, int C_Payment_ID, Trx trxName)
        {
            if (C_Payment_ID == 0)
            {
                return(null);
            }
            MPayment payment = new MPayment(ctx, C_Payment_ID, null);
            //	Map Payment Rule <- Tender Type
            String PaymentRule = PAYMENTRULE_Check;

            if (payment.GetTenderType().Equals(X_C_Payment.TENDERTYPE_CreditCard))
            {
                PaymentRule = PAYMENTRULE_CreditCard;
            }
            else if (payment.GetTenderType().Equals(X_C_Payment.TENDERTYPE_DirectDebit))
            {
                PaymentRule = PAYMENTRULE_DirectDebit;
            }
            else if (payment.GetTenderType().Equals(X_C_Payment.TENDERTYPE_DirectDeposit))
            {
                PaymentRule = PAYMENTRULE_DirectDeposit;
            }
            //	else if (payment.GetTenderType().Equals(MPayment.TENDERTYPE_Check))
            //		PaymentRule = MPaySelectionCheck.PAYMENTRULE_Check;

            //	Create new PaySelection
            MPaySelection ps = new MPaySelection(ctx, 0, trxName);

            ps.SetC_BankAccount_ID(payment.GetC_BankAccount_ID());
            ps.SetName(Msg.Translate(ctx, "C_Payment_ID") + ": " + payment.GetDocumentNo());
            ps.SetDescription(payment.GetDescription());
            ps.SetPayDate(payment.GetDateTrx());
            ps.SetTotalAmt(payment.GetPayAmt());
            ps.SetIsApproved(true);
            ps.Save();

            //	Create new PaySelection Line
            MPaySelectionLine psl = null;

            if (payment.GetC_Invoice_ID() != 0)
            {
                psl = new MPaySelectionLine(ps, 10, PaymentRule);
                psl.SetC_Invoice_ID(payment.GetC_Invoice_ID());
                psl.SetIsSOTrx(payment.IsReceipt());
                psl.SetOpenAmt(Decimal.Add(payment.GetPayAmt(), payment.GetDiscountAmt()));
                psl.SetPayAmt(payment.GetPayAmt());
                psl.SetDiscountAmt(payment.GetDiscountAmt());
                psl.SetDifferenceAmt(Env.ZERO);
                psl.Save();
            }

            //	Create new PaySelection Check
            MPaySelectionCheck psc = new MPaySelectionCheck(ps, PaymentRule);

            psc.SetC_BPartner_ID(payment.GetC_BPartner_ID());
            psc.SetC_Payment_ID(payment.GetC_Payment_ID());
            psc.SetIsReceipt(payment.IsReceipt());
            psc.SetPayAmt(payment.GetPayAmt());
            psc.SetDiscountAmt(payment.GetDiscountAmt());
            psc.SetQty(1);
            psc.SetDocumentNo(payment.GetDocumentNo());
            psc.SetProcessed(true);
            psc.Save();

            //	Update optional Line
            if (psl != null)
            {
                psl.SetC_PaySelectionCheck_ID(psc.GetC_PaySelectionCheck_ID());
                psl.SetProcessed(true);
                psl.Save();
            }

            //	Indicate Done
            ps.SetProcessed(true);
            ps.Save();
            return(psc);
        }