Search in sources :

Example 36 with MPayment

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

the class GenerateWithdrawal method createPayment.

private void createPayment(Integer bankAccountId, Integer pOSTerminalId, Integer businessPartnerId, String documentNo, String referenceNo, String description, Integer documentTypeId, Integer chargeId, String tenderType, Integer currencyId, BigDecimal amount, Timestamp transactionDate, Timestamp accountDate, Boolean isReceipt, Integer paymentBatchId) {
    MPayment payment = new MPayment(getCtx(), 0, get_TrxName());
    payment.setC_POS_ID(pOSTerminalId);
    payment.setDateTrx(transactionDate);
    if (documentNo != null && documentNo.length() > 0)
        payment.setDocumentNo(documentNo);
    if (referenceNo != null && referenceNo.length() > 0)
        payment.setVoiceAuthCode(referenceNo);
    payment.setC_BankAccount_ID(bankAccountId);
    payment.setDateAcct(accountDate);
    payment.setC_BPartner_ID(businessPartnerId);
    payment.addDescription(description);
    payment.setTenderType(tenderType);
    payment.setIsReceipt(isReceipt);
    payment.setC_Charge_ID(chargeId);
    payment.setC_DocType_ID(documentTypeId);
    payment.setC_Currency_ID(currencyId);
    payment.setAmount(currencyId, amount);
    payment.setC_PaymentBatch_ID(paymentBatchId);
    payment.saveEx();
    payment.processIt(DocAction.STATUS_Completed);
    payment.saveEx();
    addLog(payment.getDocumentInfo());
}
Also used : MPayment(org.compiere.model.MPayment)

Example 37 with MPayment

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

the class CPOS method completeReturn.

/**
	 * Complete return material
	 * @param trxName
	 * @return String error Message
	 */
private String completeReturn(String trxName) {
    if (isDrafted() || isInProgress() || isInvalid()) {
        if (!processOrder(trxName, false, false)) {
            return Msg.parseTranslation(getCtx(), " @ProcessRunError@. " + "@order.no@: " + getDocumentNo() + ". @Process@: " + CommandManager.COMPLETE_DOCUMENT);
        }
        // For certain documents, there is no further processing
        String docSubTypeSO = getDocSubTypeSO();
        if ((docSubTypeSO.equals(MOrder.DocSubTypeSO_Standard) || docSubTypeSO.equals(MOrder.DocSubTypeSO_OnCredit) || docSubTypeSO.equals(MOrder.DocSubTypeSO_Warehouse)) && isCompleted())
            return "@POS.IsNotReturn@";
    }
    //	Create
    MOrder returnOrder = new MOrder(getCtx(), getC_Order_ID(), trxName);
    returnOrder.setInvoiceRule(MOrder.INVOICERULE_Immediate);
    returnOrder.setDeliveryRule(MOrder.DELIVERYRULE_Force);
    returnOrder.saveEx();
    List<Integer> selectionIds = new ArrayList<Integer>();
    selectionIds.add(returnOrder.get_ID());
    //Generate Return using InOutGenerate
    ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(199).withParameter(MOrder.COLUMNNAME_M_Warehouse_ID, getM_Warehouse_ID()).withParameter("Selection", true).withSelectedRecordsIds(selectionIds).withoutTransactionClose().execute(trxName);
    if (processInfo.isError()) {
        return processInfo.getLogInfo();
    }
    //Force the confirmation
    for (MInOut customerReturn : returnOrder.getShipments()) {
        customerReturn.processIt(DocAction.ACTION_Complete);
        customerReturn.saveEx();
        for (MInOutConfirm confirm : customerReturn.getConfirmations(true)) {
            for (MInOutLineConfirm confirmLine : confirm.getLines(true)) {
                confirmLine.setConfirmedQty(confirmLine.getTargetQty());
                confirmLine.saveEx();
            }
            confirm.processIt(DocAction.ACTION_Complete);
            confirm.saveEx();
        }
    }
    MOrder sourceOrder = (MOrder) returnOrder.getRef_Order();
    if (sourceOrder != null && returnOrder.getC_Order_ID() > 0) {
        if (sourceOrder.getInvoices().length > 0) {
            //Generate Credit note InvoiceGenerate
            processInfo = ProcessBuilder.create(getCtx()).process(134).withTitle(processInfo.getTitle()).withParameter("Selection", true).withSelectedRecordsIds(selectionIds).withParameter(MInvoice.COLUMNNAME_DocAction, MInvoice.DOCACTION_Complete).withoutTransactionClose().execute(trxName);
            //	Validate Error
            if (processInfo.isError()) {
                return processInfo.getLogInfo();
            }
        } else // if not exist invoice then return of payment
        {
            Timestamp today = new Timestamp(System.currentTimeMillis());
            // Create return payment
            MPayment payment = new MPayment(returnOrder.getCtx(), 0, returnOrder.get_TrxName());
            payment.setDateTrx(today);
            payment.setC_Order_ID(returnOrder.getC_Order_ID());
            payment.setC_BankAccount_ID(getC_BankAccount_ID());
            payment.setDateAcct(today);
            payment.addDescription(Msg.parseTranslation(returnOrder.getCtx(), " @C_Order_ID@ " + returnOrder.getDocumentNo()));
            payment.setIsReceipt(false);
            payment.setC_DocType_ID(MDocType.getDocType(MDocType.DOCBASETYPE_APPayment));
            payment.setAmount(returnOrder.getC_Currency_ID(), returnOrder.getGrandTotal());
            payment.setDocAction(DocAction.ACTION_Complete);
            payment.setDocStatus(DocAction.STATUS_Drafted);
            payment.setIsPrepayment(true);
            payment.saveEx();
            payment.processIt(DocAction.ACTION_Complete);
            payment.saveEx();
            returnOrder.setC_POS_ID(getC_POS_ID());
            returnOrder.saveEx();
            processInfo.addLog(0, null, null, payment.getDocumentInfo());
        }
    }
    setIsToPrint(true);
    //	Default return
    return null;
}
Also used : MInOut(org.compiere.model.MInOut) MOrder(org.compiere.model.MOrder) MInOutLineConfirm(org.compiere.model.MInOutLineConfirm) MPayment(org.compiere.model.MPayment) ArrayList(java.util.ArrayList) ProcessInfo(org.compiere.process.ProcessInfo) MInOutConfirm(org.compiere.model.MInOutConfirm) Timestamp(java.sql.Timestamp)

Example 38 with MPayment

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

the class Collect method payCreditMemo.

// payCheck
/**
	 * 	Payment with credit note
	 * 
	 * @return true if payment processed correctly; otherwise false
	 * 
	 */
public boolean payCreditMemo(MInvoice creditNote, BigDecimal amount) {
    int invoiceId = order.getC_Invoice_ID();
    if (invoiceId == 0)
        return false;
    MPayment payment = createPayment(MPayment.TENDERTYPE_Account);
    if (payment.getC_Invoice_ID() > 0)
        payment.setC_Invoice_ID(0);
    if (payment.getC_Order_ID() > 0)
        payment.setC_Order_ID(0);
    if (payment.getC_Charge_ID() > 0)
        payment.setC_Charge_ID(0);
    payment.setAmount(order.getC_Currency_ID(), Env.ZERO);
    payment.setC_BankAccount_ID(entityPOS.getC_BankAccount_ID());
    payment.setDateTrx(getDateTrx());
    payment.setDateAcct(getDateTrx());
    payment.saveEx();
    //Invoice
    MPaymentAllocate paymentAllocate = new MPaymentAllocate(Env.getCtx(), 0, trxName);
    paymentAllocate.setC_Payment_ID(payment.getC_Payment_ID());
    paymentAllocate.setC_Invoice_ID(invoiceId);
    paymentAllocate.setInvoiceAmt(amount);
    paymentAllocate.setAmount(amount);
    paymentAllocate.saveEx();
    //CreditNote
    paymentAllocate = new MPaymentAllocate(Env.getCtx(), 0, trxName);
    paymentAllocate.setC_Payment_ID(payment.getC_Payment_ID());
    paymentAllocate.setC_Invoice_ID(creditNote.getC_Invoice_ID());
    paymentAllocate.setAmount(amount.negate());
    paymentAllocate.setInvoiceAmt(amount.negate());
    paymentAllocate.saveEx();
    payment.setDocAction(MPayment.DOCACTION_Complete);
    payment.setDocStatus(MPayment.DOCSTATUS_Drafted);
    if (payment.processIt(MPayment.DOCACTION_Complete)) {
        payment.saveEx();
        MBankStatement.addPayment(payment);
        return true;
    } else {
        return false;
    }
}
Also used : MPayment(org.compiere.model.MPayment) MPaymentAllocate(org.compiere.model.MPaymentAllocate)

Example 39 with MPayment

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

the class MHRPaySelectionCheck method confirmPrint.

//  getBPartnerInfo
/**************************************************************************
	 * 	Confirm Print.
	 * 	Create Payments the first time 
	 * 	@param checks checks
	 * 	@param batch batch
	 * 	@return last Document number or 0 if nothing printed
	 */
public static int confirmPrint(Collection<MHRPaySelectionCheck> checks, MPaymentBatch batch) {
    int lastDocumentNo = 0;
    for (MHRPaySelectionCheck check : checks) {
        StringBuilder sqlConcept = new StringBuilder();
        sqlConcept.append("SELECT HR_Concept_ID FROM HR_Movement m ").append(" WHERE EXISTS(SELECT 1 FROM HR_PaySelectionLine psl ").append(" WHERE psl.HR_Movement_ID = m.HR_Movement_ID AND m.C_BPartner_ID=?").append(" AND psl.HR_PaySelection_ID=?)");
        int conceptId = DB.getSQLValue(check.get_TrxName(), sqlConcept.toString(), check.getC_BPartner_ID(), check.getHR_PaySelection_ID());
        StringBuilder sqlPayroll = new StringBuilder();
        sqlPayroll.append("SELECT HR_Payroll_ID FROM HR_PaySelection ps INNER JOIN HR_Process p ON (p.HR_Process_ID=ps.HR_Process_ID) ").append("WHERE ps.HR_PaySelection_ID=?");
        int payrollId = DB.getSQLValueEx(check.get_TrxName(), sqlPayroll.toString(), check.getHR_PaySelection_ID());
        MHRConcept concept = new MHRConcept(check.getCtx(), conceptId, check.get_TrxName());
        MHRPayroll payroll = new MHRPayroll(check.getCtx(), payrollId, check.get_TrxName());
        MPayment payment = new MPayment(check.getCtx(), check.getC_Payment_ID(), check.get_TrxName());
        //	Existing Payment
        if (check.getC_Payment_ID() > 0) {
            //	Update check number
            if (check.getPaymentRule().equals(PAYMENTRULE_Check)) {
                payment.setCheckNo(check.getDocumentNo());
                if (!payment.save())
                    s_log.log(Level.SEVERE, "Payment not saved: " + payment);
            }
        } else //	New Payment
        {
            payment = new MPayment(check.getCtx(), 0, check.get_TrxName());
            if (check.getPaymentRule().equals(PAYMENTRULE_Check))
                payment.setBankCheck(check.getParent().getC_BankAccount_ID(), false, check.getDocumentNo());
            else if (check.getPaymentRule().equals(PAYMENTRULE_CreditCard))
                payment.setTenderType(X_C_Payment.TENDERTYPE_CreditCard);
            else if (check.getPaymentRule().equals(PAYMENTRULE_DirectDeposit) || check.getPaymentRule().equals(PAYMENTRULE_DirectDebit))
                payment.setTenderType(X_C_Payment.TENDERTYPE_DirectDebit);
            else {
                s_log.log(Level.SEVERE, "Unsupported Payment Rule=" + check.getPaymentRule());
                continue;
            }
            payment.setTrxType(X_C_Payment.TRXTYPE_CreditPayment);
            payment.setDescription(check.getHR_PaySelection().getDescription());
            payment.setIsReceipt(check.isReceipt());
            payment.setAmount(check.getParent().getC_Currency_ID(), check.getPayAmt());
            payment.setDiscountAmt(check.getDiscountAmt());
            payment.setDateTrx(check.getParent().getPayDate());
            // globalqss [ 2030685 ]
            payment.setDateAcct(payment.getDateTrx());
            payment.setC_BPartner_ID(check.getC_BPartner_ID());
            /*
				//	Link to Batch
				if (batch != null)
				{
					if (batch.getC_PaymentBatch_ID() == 0)
						batch.save();	//	new
					payment.setC_PaymentBatch_ID(batch.getC_PaymentBatch_ID());
				}
				*/
            if (concept.isPrepayment()) {
                payment.setIsPrepayment(true);
            } else {
                int C_Charge_ID = DB.getSQLValue(check.get_TrxName(), "SELECT MAX(C_Charge_ID) FROM HR_Attribute WHERE IsActive='Y' AND HR_Concept_ID=" + conceptId);
                if (// modify e-Evolution 25May2010  if(C_Charge_ID < 0)
                C_Charge_ID <= 0)
                    payment.setC_Charge_ID(payroll.getC_Charge_ID());
                else
                    payment.setC_Charge_ID(C_Charge_ID);
            }
            payment.setC_BankAccount_ID(check.getParent().getC_BankAccount_ID());
            payment.setWriteOffAmt(Env.ZERO);
            payment.saveEx();
            int C_Payment_ID = payment.get_ID();
            if (C_Payment_ID < 1)
                s_log.log(Level.SEVERE, "Payment not created=" + check);
            else {
                check.setC_Payment_ID(C_Payment_ID);
                //	Payment process needs it
                check.save();
                //	Should start WF
                payment.processIt(DocAction.ACTION_Complete);
                if (!payment.save())
                    s_log.log(Level.SEVERE, "Payment not saved: " + payment);
                payment.setAD_Org_ID(check.getAD_Org_ID());
                payment.setAD_OrgTrx_ID(check.getAD_Org_ID());
                payment.saveEx();
            }
        }
        //	Get Check Document No
        try {
            int no = Integer.parseInt(check.getDocumentNo());
            if (lastDocumentNo < no)
                lastDocumentNo = no;
        } catch (NumberFormatException ex) {
            s_log.log(Level.SEVERE, "DocumentNo=" + check.getDocumentNo(), ex);
        }
        check.setIsPrinted(true);
        check.setProcessed(true);
        check.saveEx();
    }
    //	all checks
    s_log.fine("Last Document No = " + lastDocumentNo);
    return lastDocumentNo;
}
Also used : MPayment(org.compiere.model.MPayment)

Example 40 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)

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