IDempiere Documents
From iDempiere en
SmartPOS: Various documents
Documents supported
Among others:
- createSalesOrder
- createPurchaseOrder
- createOrderLine
- createMInOut
- createIOLine
- createInvoice
- createInvoiceLine
- createPayment
- createMovement
- createMovementLine
Link to source code
- Source code: https://bitbucket.org/PedroRozo_SmartJSP/smartpos3-erp/src/6aa37da834fd9301db4e50ff2530be1087ff8b56/SmartPOSWeb/src/com/smj/util/Documents.java?at=default
- Plugin: http://wiki.idempiere.org/en/Plugin:_SmartPOS
- Credit: User:Smartjsp (talk) - SmartJSP
Notes
- Recommended, that in the code given above, remove the exception handlers, and change .save to .saveEx
Create payment
Example of payment creation, with various features.
private void createPayment() {
m_payment = new MPayment(m_ctx, 0, m_trxName);
m_payment.setAD_Org_ID( m_AD_Org_ID );
/****************************************************************************
* Set fields
****************************************************************************/
m_payment.setC_BPartner_ID( m_matchSetup.getC_BPartner_ID() );
if ( ! m_payment.getC_BPartner().isActive() ) {
throw new AdempiereException( String.format("Business Partner is inactive" ) );
}
m_payment.setDateAcct ( m_dateAcct );
m_payment.setDateTrx ( m_dateAcct );
m_payment.setPayAmt ( m_stmtAmt.abs() );
m_payment.setC_BankAccount_ID ( m_C_BankAccount_ID );
// if ( ! m_po.getC_BankAccount().isActive() ) {
// throw new AdempiereException( String.format("Bank Account is inactive" ) );
// }
// m_po.setDocumentNo( thedocumentno );
m_payment.setIsReceipt( m_isReceipt );
// Still need to share NTierUtils on the Wiki
m_payment.setC_Currency_ID( MClient.get(Env.getCtx()).getC_Currency_ID() );
//
m_payment.saveEx();
// Chat - see http://wiki.idempiere.org/en/Code_Scratchpad:_Java:_General
NTierChatUtils.addChat (m_payment.getCtx(), m_payment.get_TrxName(),
m_payment,
String.format(NBSM_Common.getChatPrefix() + "Payment created. ") +
String.format("Bank statement: '%s'/Line No: %s ", m_bankStatementName, m_bankStatementLineNo) +
m_matchSetup.toString() );
// Sanity check
if ( m_payment.getAD_Org_ID() != m_AD_Org_ID ) {
throw new AdempiereException( String.format(
"The org has changed after saving the record. This is caused by the bank account " +
" having a different org to the requested org. Please select a different bank account, " +
" or correct the org on the selected bank account.") );
}
info.setC_Payment_ID( m_payment.get_ID() );
/****************************************************************************
* Complete Document
****************************************************************************/
String docAction = DocAction.ACTION_Complete;
m_payment.setDocAction( docAction );
m_payment.processIt( docAction );
m_payment.saveEx();
if ( ! docAction.equals( m_payment.getDocStatus() )) {
String msg = String.format("Error completing document: Invalid resulting status:- '%s' (expected '%s') Process Message:- '%s'",
m_payment.getDocStatus(), docAction, m_payment.getProcessMsg() );
throw new AdempiereException( msg );
}
// addInfo("Payment has been created and successfully completed.");
return;
}
Credit: nTier Software Services http://www.ntier.co.za
