Search in sources :

Example 26 with MPayment

use of org.compiere.model.MPayment in project adempiere by adempiere.

the class Doc_AllocationTax method isInterOrg.

//  createFact
/** Verify if the posting involves two or more organizations
	@return true if there are more than one org involved on the posting
	 */
private boolean isInterOrg(MAcctSchema as) {
    MAcctSchemaElement elementorg = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_Organization);
    if (elementorg == null || !elementorg.isBalanced()) {
        // no org element or not need to be balanced
        return false;
    }
    if (p_lines.length <= 0) {
        // no lines
        return false;
    }
    int startorg = p_lines[0].getAD_Org_ID();
    // validate if the allocation involves more than one org
    for (int i = 0; i < p_lines.length; i++) {
        DocLine_Allocation line = (DocLine_Allocation) p_lines[i];
        int orgpayment = startorg;
        MPayment payment = null;
        if (line.getC_Payment_ID() != 0) {
            payment = new MPayment(getCtx(), line.getC_Payment_ID(), getTrxName());
            orgpayment = payment.getAD_Org_ID();
        }
        int orginvoice = startorg;
        MInvoice invoice = null;
        if (line.getC_Invoice_ID() != 0) {
            invoice = new MInvoice(getCtx(), line.getC_Invoice_ID(), getTrxName());
            orginvoice = invoice.getAD_Org_ID();
        }
        int orgcashline = startorg;
        MCashLine cashline = null;
        if (line.getC_CashLine_ID() != 0) {
            cashline = new MCashLine(getCtx(), line.getC_CashLine_ID(), getTrxName());
            orgcashline = cashline.getAD_Org_ID();
        }
        int orgorder = startorg;
        MOrder order = null;
        if (line.getC_Order_ID() != 0) {
            order = new MOrder(getCtx(), line.getC_Order_ID(), getTrxName());
            orgorder = order.getAD_Org_ID();
        }
        if (line.getAD_Org_ID() != startorg || orgpayment != startorg || orginvoice != startorg || orgcashline != startorg || orgorder != startorg)
            return true;
    }
    return false;
}
Also used : MOrder(org.compiere.model.MOrder) MPayment(org.compiere.model.MPayment) MInvoice(org.compiere.model.MInvoice) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement) MCashLine(org.compiere.model.MCashLine)

Example 27 with MPayment

use of org.compiere.model.MPayment in project adempiere by adempiere.

the class Merge method postMerge.

//	mergeTable
/**
	 * 	Post Merge
	 *	@param ColumnName column name
	 *	@param to_ID ID
	 */
public void postMerge(String ColumnName, int to_ID) {
    if (ColumnName.equals(AD_ORG_ID)) {
    } else if (ColumnName.equals(AD_USER_ID)) {
    } else if (ColumnName.equals(C_BPARTNER_ID)) {
        MBPartner bp = new MBPartner(Env.getCtx(), to_ID, null);
        if (bp.get_ID() != 0) {
            MPayment[] payments = MPayment.getOfBPartner(Env.getCtx(), bp.getC_BPartner_ID(), null);
            for (int i = 0; i < payments.length; i++) {
                MPayment payment = payments[i];
                if (payment.testAllocation())
                    payment.saveEx();
            }
            MInvoice[] invoices = MInvoice.getOfBPartner(Env.getCtx(), bp.getC_BPartner_ID(), null);
            for (int i = 0; i < invoices.length; i++) {
                MInvoice invoice = invoices[i];
                if (invoice.testAllocation())
                    invoice.saveEx();
            }
            bp.setTotalOpenBalance();
            bp.setActualLifeTimeValue();
            bp.saveEx();
        }
    } else if (ColumnName.equals(M_PRODUCT_ID)) {
    }
}
Also used : MPayment(org.compiere.model.MPayment) MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner)

Example 28 with MPayment

use of org.compiere.model.MPayment in project adempiere by adempiere.

the class FixPaymentCashLine method doIt.

//        prepare
/**
     *  Perform process.
     *  @return Message (clear text)
     *  @throws Exception if not successful
     */
protected String doIt() throws Exception {
    String sql = "SELECT cl.C_CashLine_ID, c.Name FROM C_CashLine cl INNER JOIN C_Cash c ON (c.C_Cash_ID=cl.C_Cash_ID) WHERE cl.CashType='T'";
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            Trx trx = Trx.get(Trx.createTrxName(), true);
            MCashLine cashline = new MCashLine(Env.getCtx(), rs.getInt(1), trx.getTrxName());
            Integer c_cashline_id = cashline.getC_CashLine_ID();
            MPayment[] payments = getOfCash(Env.getCtx(), rs.getString(2), cashline.getAmount(), cashline.getC_BankAccount_ID(), cashline.getAD_Client_ID(), trx.getTrxName());
            for (MPayment payment : payments) {
                cashline.setC_Payment_ID(payment.getC_Payment_ID());
                if (!cashline.save())
                    throw new IllegalStateException("Cannot assign payment to Cash Line");
                // only the first
                break;
            }
            trx.commit();
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        s_log.log(Level.SEVERE, sql, e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    return "@ProcessOK@";
}
Also used : MPayment(org.compiere.model.MPayment) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Trx(org.compiere.util.Trx) MCashLine(org.compiere.model.MCashLine)

Example 29 with MPayment

use of org.compiere.model.MPayment in project adempiere by adempiere.

the class FixPaymentCashLine method getOfCash.

//        doIt
/**
	 * 	Get Payment of Cash
	 *	@param ctx context
	 *	@param cashName Cash Name
	 *	@return payments of cash
	 *	@param trxName transaction
	 */
public static MPayment[] getOfCash(Properties ctx, String cashName, BigDecimal amt, int C_BankAccount_ID, int AD_Client_ID, String trxName) {
    String sql = "SELECT * FROM C_Payment p WHERE p.DocumentNo=? AND R_PnRef=? AND PayAmt=? AND C_BankAccount_ID=? AND AD_Client_ID=? " + " AND TrxType='X' AND TenderType='X'";
    ArrayList<MPayment> list = new ArrayList<MPayment>();
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(sql, trxName);
        pstmt.setString(1, cashName);
        pstmt.setString(2, cashName);
        pstmt.setBigDecimal(3, amt.negate());
        pstmt.setInt(4, C_BankAccount_ID);
        pstmt.setInt(5, AD_Client_ID);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) list.add(new MPayment(ctx, rs, trxName));
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        s_log.log(Level.SEVERE, sql, e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    MPayment[] retValue = new MPayment[list.size()];
    list.toArray(retValue);
    return retValue;
}
Also used : MPayment(org.compiere.model.MPayment) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 30 with MPayment

use of org.compiere.model.MPayment in project adempiere by adempiere.

the class OrderServlet method createPayment.

//	doPost
/**************************************************************************
	 * 	Create Payment, but don't save it
	 * 	@param session session
	 * 	@param ctx context
	 * 	@param wu web user
	 * 	@param wo Order
	 * 	@return Payment
	 */
private MPayment createPayment(HttpSession session, Properties ctx, WebUser wu, WebOrder wo) {
    //	See PaymentServlet.doGet
    MPayment p = new MPayment(ctx, 0, null);
    p.setAD_Org_ID(wo.getAD_Org_ID());
    p.setIsSelfService(true);
    //	for CC selection
    p.setAmount(wo.getC_Currency_ID(), wo.getGrandTotal());
    p.setIsOnline(true);
    //	Sales CC Trx
    p.setC_DocType_ID(true);
    p.setTrxType(MPayment.TRXTYPE_Sales);
    p.setTenderType(MPayment.TENDERTYPE_CreditCard);
    //	Order Info
    p.setC_Order_ID(wo.getC_Order_ID());
    //	BP Info
    p.setBP_BankAccount(wu.getBankAccount());
    //
    return p;
}
Also used : MPayment(org.compiere.model.MPayment)

Aggregations

MPayment (org.compiere.model.MPayment)47 BigDecimal (java.math.BigDecimal)14 MInvoice (org.compiere.model.MInvoice)12 Timestamp (java.sql.Timestamp)8 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 ArrayList (java.util.ArrayList)7 MCashLine (org.compiere.model.MCashLine)5 AdempiereSystemError (org.compiere.util.AdempiereSystemError)5 MAllocationLine (org.compiere.model.MAllocationLine)4 MBankStatement (org.compiere.model.MBankStatement)4 MOrder (org.compiere.model.MOrder)4 Properties (java.util.Properties)3 RequestDispatcher (javax.servlet.RequestDispatcher)3 HttpSession (javax.servlet.http.HttpSession)3 MAllocationHdr (org.compiere.model.MAllocationHdr)3 MBankAccount (org.compiere.model.MBankAccount)3 MBankStatementLine (org.compiere.model.MBankStatementLine)3 AdempiereUserError (org.compiere.util.AdempiereUserError)3 KeyNamePair (org.compiere.util.KeyNamePair)3