Пример #1
0
        /**
         *  Get Checks of Payment Selection
         *
         *  @param C_PaySelection_ID Payment Selection
         *  @param PaymentRule Payment Rule
         *  @param startDocumentNo start document no
         *	@param trxName transaction
         *  @return array of checks
         */
        static public MPaySelectionCheck[] Get(int C_PaySelection_ID,
                                               String PaymentRule, int startDocumentNo, Trx trxName)
        {
            _log.Fine("C_PaySelection_ID=" + C_PaySelection_ID
                      + ", PaymentRule=" + PaymentRule + ", startDocumentNo=" + startDocumentNo);
            List <MPaySelectionCheck> list = new List <MPaySelectionCheck>();

            int    docNo = startDocumentNo;
            String sql   = "SELECT * FROM C_PaySelectionCheck "
                           + "WHERE C_PaySelection_ID=" + C_PaySelection_ID + " AND PaymentRule='"
                           + PaymentRule + "'";
            DataTable   dt;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, trxName);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();

                foreach (DataRow dr in dt.Rows)
                {
                    MPaySelectionCheck check = new MPaySelectionCheck(Env.GetContext(), dr, trxName);
                    //	Set new Check Document No - saved in confirmPrint
                    check.SetDocumentNo((docNo++).ToString());
                    list.Add(check);
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                }
                dt = null;
            }

            //  convert to Array
            MPaySelectionCheck[] retValue = new MPaySelectionCheck[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Пример #2
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);
        }