integration with PosteritaWebPOS.
This commit is contained in:
parent
3dd9e1f820
commit
9e48aeb32d
|
@ -81,6 +81,7 @@ public class ReportStarter implements ProcessCall, ClientProcess {
|
|||
private static File REPORT_HOME = null;
|
||||
|
||||
private static JRViewerProvider viewerProvider = new SwingJRViewerProvider();
|
||||
private static JasperPrint jasperPrint;
|
||||
|
||||
static {
|
||||
// System.setProperty( "javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
|
||||
|
@ -511,7 +512,7 @@ public class ReportStarter implements ProcessCall, ClientProcess {
|
|||
Connection conn = null;
|
||||
try {
|
||||
conn = getConnection();
|
||||
JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, params, conn);
|
||||
jasperPrint = JasperFillManager.fillReport( jasperReport, params, conn);
|
||||
if (reportData.isDirectPrint())
|
||||
{
|
||||
log.info( "ReportStarter.startProcess print report -" + jasperPrint.getName());
|
||||
|
@ -557,6 +558,12 @@ public class ReportStarter implements ProcessCall, ClientProcess {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static JasperPrint getJasperPrint()
|
||||
{
|
||||
return jasperPrint;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get .property resource file from process attachment
|
||||
* @param jasperName
|
||||
|
|
|
@ -554,6 +554,10 @@ public class MCash extends X_C_Cash implements DocAction
|
|||
pay.set_Value("TrxType", "X"); // Transfer
|
||||
pay.set_Value("TenderType", "X");
|
||||
//
|
||||
//Modification for cash payment - Posterita
|
||||
pay.setC_CashBook_ID(getC_CashBook_ID());
|
||||
//End of modification - Posterita
|
||||
|
||||
pay.setC_BankAccount_ID(line.getC_BankAccount_ID());
|
||||
pay.setC_DocType_ID(true); // Receipt
|
||||
pay.setDateTrx(getStatementDate());
|
||||
|
|
|
@ -36,12 +36,24 @@ public class MCashBook extends X_C_CashBook
|
|||
* @return MCashBook
|
||||
*/
|
||||
public static MCashBook get (Properties ctx, int C_CashBook_ID)
|
||||
{
|
||||
return get(ctx, C_CashBook_ID, null);
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Gets MCashBook from Cache under transaction scope
|
||||
* @param ctx context
|
||||
* @param C_CashBook_ID id of cashbook to load
|
||||
* @param trxName transaction name
|
||||
* @return Cashbook
|
||||
*/
|
||||
public static MCashBook get(Properties ctx, int C_CashBook_ID, String trxName)
|
||||
{
|
||||
Integer key = new Integer (C_CashBook_ID);
|
||||
MCashBook retValue = (MCashBook) s_cache.get (key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
retValue = new MCashBook (ctx, C_CashBook_ID, null);
|
||||
retValue = new MCashBook (ctx, C_CashBook_ID, trxName);
|
||||
if (retValue.get_ID () != 0)
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
|
|
|
@ -97,13 +97,13 @@ public class MPOS extends X_C_POS
|
|||
if (newRecord
|
||||
|| is_ValueChanged("C_CashBook_ID") || is_ValueChanged("M_Warehouse_ID"))
|
||||
{
|
||||
MCashBook cb = MCashBook.get(getCtx(), getC_CashBook_ID());
|
||||
MCashBook cb = MCashBook.get(getCtx(), getC_CashBook_ID(), get_TrxName());
|
||||
if (cb.getAD_Org_ID() != getAD_Org_ID())
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@AD_Org_ID@: @C_CashBook_ID@"));
|
||||
return false;
|
||||
}
|
||||
MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID());
|
||||
MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID(), get_TrxName());
|
||||
if (wh.getAD_Org_ID() != getAD_Org_ID())
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@AD_Org_ID@: @M_Warehouse_ID@"));
|
||||
|
|
|
@ -542,6 +542,23 @@ public final class MPayment extends X_C_Payment
|
|||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
// @Trifon - CashPayments
|
||||
//if ( getTenderType().equals("X") ) {
|
||||
if ( isCashTrx() ) {
|
||||
// Cash Book Is mandatory
|
||||
if ( getC_CashBook_ID() <= 0 ) {
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@Mandatory@: @C_CashBook_ID@"));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Bank Account Is mandatory
|
||||
if ( getC_BankAccount_ID() <= 0 ) {
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@Mandatory@: @C_BankAccount_ID@"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// end @Trifon - CashPayments
|
||||
|
||||
// We have a charge
|
||||
if (getC_Charge_ID() != 0)
|
||||
{
|
||||
|
@ -685,7 +702,8 @@ public final class MPayment extends X_C_Payment
|
|||
*/
|
||||
public boolean testAllocation()
|
||||
{
|
||||
// Cash Trx always allocated
|
||||
// Cash Trx always allocated!!! WHY???
|
||||
/* @Trifon - CashPayments
|
||||
if (isCashTrx())
|
||||
{
|
||||
if (!isAllocated())
|
||||
|
@ -695,6 +713,7 @@ public final class MPayment extends X_C_Payment
|
|||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
//
|
||||
BigDecimal alloc = getAllocatedAmt();
|
||||
if (alloc == null)
|
||||
|
@ -1780,6 +1799,54 @@ public final class MPayment extends X_C_Payment
|
|||
if (counter != null)
|
||||
m_processMsg += " @CounterDoc@: @C_Payment_ID@=" + counter.getDocumentNo();
|
||||
|
||||
// @Trifon - CashPayments
|
||||
//if ( getTenderType().equals("X") ) {
|
||||
if ( isCashTrx() ) {
|
||||
// Create Cash Book entry
|
||||
if ( getC_CashBook_ID() <= 0 ) {
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@Mandatory@: @C_CashBook_ID@"));
|
||||
m_processMsg = "@NoCashBook@";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
MCash cash = MCash.get (getCtx(), getAD_Org_ID(), getDateAcct(), getC_Currency_ID(), get_TrxName());
|
||||
if (cash == null || cash.get_ID() == 0)
|
||||
{
|
||||
m_processMsg = "@NoCashBook@";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
MCashLine cl = new MCashLine( cash );
|
||||
cl.setCashType( X_C_CashLine.CASHTYPE_GeneralReceipts );
|
||||
cl.setDescription("Generated From Payment #" + getDocumentNo());
|
||||
cl.setC_Currency_ID( this.getC_Currency_ID() );
|
||||
cl.setC_Payment_ID( getC_Payment_ID() ); // Set Reference to payment.
|
||||
StringBuffer info=new StringBuffer();
|
||||
info.append("Cash journal ( ")
|
||||
.append(cash.getDocumentNo()).append(" )");
|
||||
m_processMsg = info.toString();
|
||||
// Amount
|
||||
BigDecimal amt = this.getPayAmt();
|
||||
/*
|
||||
MDocType dt = MDocType.get(getCtx(), invoice.getC_DocType_ID());
|
||||
if (MDocType.DOCBASETYPE_APInvoice.equals( dt.getDocBaseType() )
|
||||
|| MDocType.DOCBASETYPE_ARCreditMemo.equals( dt.getDocBaseType() )
|
||||
) {
|
||||
amt = amt.negate();
|
||||
}
|
||||
*/
|
||||
cl.setAmount( amt );
|
||||
//
|
||||
cl.setDiscountAmt( Env.ZERO );
|
||||
cl.setWriteOffAmt( Env.ZERO );
|
||||
cl.setIsGenerated( true );
|
||||
|
||||
if (!cl.save(get_TrxName()))
|
||||
{
|
||||
m_processMsg = "Could not save Cash Journal Line";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
}
|
||||
// End Trifon - CashPayments
|
||||
|
||||
// User Validation
|
||||
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
|
||||
if (valid != null)
|
||||
|
@ -1883,7 +1950,7 @@ public final class MPayment extends X_C_Payment
|
|||
int C_BankAccount_ID = DB.getSQLValue(get_TrxName(), sql, getC_Currency_ID(), counterAD_Org_ID);
|
||||
counter.setC_BankAccount_ID(C_BankAccount_ID);
|
||||
|
||||
// Refernces
|
||||
// References
|
||||
counter.setC_Activity_ID(getC_Activity_ID());
|
||||
counter.setC_Campaign_ID(getC_Campaign_ID());
|
||||
counter.setC_Project_ID(getC_Project_ID());
|
||||
|
|
|
@ -43,13 +43,25 @@ public class MWarehouse extends X_M_Warehouse
|
|||
* @return warehouse
|
||||
*/
|
||||
public static MWarehouse get (Properties ctx, int M_Warehouse_ID)
|
||||
{
|
||||
return get(ctx, M_Warehouse_ID, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves warehouse from cache under transaction scope
|
||||
* @param ctx context
|
||||
* @param M_Warehouse_ID id of warehouse to load
|
||||
* @param trxName transaction name
|
||||
* @return warehouse
|
||||
*/
|
||||
public static MWarehouse get (Properties ctx, int M_Warehouse_ID, String trxName)
|
||||
{
|
||||
Integer key = new Integer(M_Warehouse_ID);
|
||||
MWarehouse retValue = (MWarehouse)s_cache.get(key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
//
|
||||
retValue = new MWarehouse (ctx, M_Warehouse_ID, null);
|
||||
retValue = new MWarehouse (ctx, M_Warehouse_ID, trxName);
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
|
|
@ -1,780 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.process.DocAction;
|
||||
import org.compiere.process.DocumentEngine;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.TimeUtil;
|
||||
|
||||
/**
|
||||
* Cash Journal Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MCash.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||
*
|
||||
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||
* <li>BF [ 1831997 ] Cash journal allocation reversed
|
||||
* <li>BF [ 1894524 ] Pay an reversed invoice
|
||||
*/
|
||||
public class MCash extends X_C_Cash implements DocAction
|
||||
{
|
||||
/**
|
||||
* Get Cash Journal for currency, org and date
|
||||
* @param ctx context
|
||||
* @param C_Currency_ID currency
|
||||
* @param AD_Org_ID org
|
||||
* @param dateAcct date
|
||||
* @param trxName transaction
|
||||
* @return cash
|
||||
*/
|
||||
public static MCash get (Properties ctx, int AD_Org_ID,
|
||||
Timestamp dateAcct, int C_Currency_ID, String trxName)
|
||||
{
|
||||
MCash retValue = null;
|
||||
// Existing Journal
|
||||
String sql;
|
||||
sql = "SELECT * FROM C_Cash c "
|
||||
+ "WHERE c.AD_Org_ID=?" // #1
|
||||
+ " AND TRUNC(c.StatementDate)=?" // #2
|
||||
+ " AND c.Processed='N'"
|
||||
+ " AND EXISTS (SELECT * FROM C_CashBook cb "
|
||||
+ "WHERE c.C_CashBook_ID=cb.C_CashBook_ID AND cb.AD_Org_ID=c.AD_Org_ID"
|
||||
+ " AND cb.C_Currency_ID=?)"; // #3
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, trxName);
|
||||
pstmt.setInt (1, AD_Org_ID);
|
||||
pstmt.setTimestamp (2, TimeUtil.getDay(dateAcct));
|
||||
pstmt.setInt (3, C_Currency_ID);
|
||||
rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
retValue = new MCash (ctx, rs, trxName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
|
||||
// Get CashBook
|
||||
MCashBook cb = MCashBook.get (ctx, AD_Org_ID, C_Currency_ID);
|
||||
if (cb == null)
|
||||
{
|
||||
s_log.warning("No CashBook for AD_Org_ID=" + AD_Org_ID + ", C_Currency_ID=" + C_Currency_ID);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create New Journal
|
||||
retValue = new MCash (cb, dateAcct);
|
||||
retValue.save(trxName);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Get Cash Journal for CashBook and date
|
||||
* @param ctx context
|
||||
* @param C_CashBook_ID cashbook
|
||||
* @param dateAcct date
|
||||
* @param trxName transaction
|
||||
* @return cash
|
||||
*/
|
||||
public static MCash get (Properties ctx, int C_CashBook_ID,
|
||||
Timestamp dateAcct, String trxName)
|
||||
{
|
||||
MCash retValue = null;
|
||||
// Existing Journal
|
||||
String sql = "SELECT * FROM C_Cash c "
|
||||
+ "WHERE c.C_CashBook_ID=?" // #1
|
||||
+ " AND TRUNC(c.StatementDate)=?" // #2
|
||||
+ " AND c.Processed='N'";
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, trxName);
|
||||
pstmt.setInt (1, C_CashBook_ID);
|
||||
pstmt.setTimestamp (2, TimeUtil.getDay(dateAcct));
|
||||
rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
retValue = new MCash (ctx, rs, trxName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
|
||||
// Get CashBook
|
||||
MCashBook cb = new MCashBook (ctx, C_CashBook_ID, trxName);
|
||||
if (cb.get_ID() ==0)
|
||||
{
|
||||
s_log.warning("Not found C_CashBook_ID=" + C_CashBook_ID);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create New Journal
|
||||
retValue = new MCash (cb, dateAcct);
|
||||
retValue.save(trxName);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MCash.class);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_Cash_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MCash (Properties ctx, int C_Cash_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_Cash_ID, trxName);
|
||||
if (C_Cash_ID == 0)
|
||||
{
|
||||
// setC_CashBook_ID (0); // FK
|
||||
setBeginningBalance (Env.ZERO);
|
||||
setEndingBalance (Env.ZERO);
|
||||
setStatementDifference(Env.ZERO);
|
||||
setDocAction(DOCACTION_Complete);
|
||||
setDocStatus(DOCSTATUS_Drafted);
|
||||
//
|
||||
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
|
||||
setStatementDate (today); // @#Date@
|
||||
setDateAcct (today); // @#Date@
|
||||
String name = DisplayType.getDateFormat(DisplayType.Date).format(today)
|
||||
+ " " + MOrg.get(ctx, getAD_Org_ID()).getValue();
|
||||
setName (name);
|
||||
setIsApproved(false);
|
||||
setPosted (false); // N
|
||||
setProcessed (false);
|
||||
}
|
||||
} // MCash
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MCash (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MCash
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param cb cash book
|
||||
* @param today date - if null today
|
||||
*/
|
||||
public MCash (MCashBook cb, Timestamp today)
|
||||
{
|
||||
this (cb.getCtx(), 0, cb.get_TrxName());
|
||||
setClientOrg(cb);
|
||||
setC_CashBook_ID(cb.getC_CashBook_ID());
|
||||
if (today != null)
|
||||
{
|
||||
setStatementDate (today);
|
||||
setDateAcct (today);
|
||||
String name = DisplayType.getDateFormat(DisplayType.Date).format(today)
|
||||
+ " " + cb.getName();
|
||||
setName (name);
|
||||
}
|
||||
m_book = cb;
|
||||
} // MCash
|
||||
|
||||
/** Lines */
|
||||
private MCashLine[] m_lines = null;
|
||||
/** CashBook */
|
||||
private MCashBook m_book = null;
|
||||
|
||||
/**
|
||||
* Get Lines
|
||||
* @param requery requery
|
||||
* @return lines
|
||||
*/
|
||||
public MCashLine[] getLines (boolean requery)
|
||||
{
|
||||
if (m_lines != null && !requery) {
|
||||
set_TrxName(m_lines, get_TrxName());
|
||||
return m_lines;
|
||||
}
|
||||
ArrayList<MCashLine> list = new ArrayList<MCashLine>();
|
||||
String sql = "SELECT * FROM C_CashLine WHERE C_Cash_ID=? ORDER BY Line";
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
pstmt.setInt (1, getC_Cash_ID());
|
||||
rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add (new MCashLine (getCtx(), rs, get_TrxName()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
|
||||
m_lines = new MCashLine[list.size ()];
|
||||
list.toArray (m_lines);
|
||||
return m_lines;
|
||||
} // getLines
|
||||
|
||||
/**
|
||||
* Get Cash Book
|
||||
* @return cash book
|
||||
*/
|
||||
public MCashBook getCashBook()
|
||||
{
|
||||
if (m_book == null)
|
||||
m_book = MCashBook.get(getCtx(), getC_CashBook_ID());
|
||||
return m_book;
|
||||
} // getCashBook
|
||||
|
||||
/**
|
||||
* Get Document No
|
||||
* @return name
|
||||
*/
|
||||
public String getDocumentNo()
|
||||
{
|
||||
return getName();
|
||||
} // getDocumentNo
|
||||
|
||||
/**
|
||||
* Get Document Info
|
||||
* @return document info (untranslated)
|
||||
*/
|
||||
public String getDocumentInfo()
|
||||
{
|
||||
return Msg.getElement(getCtx(), "C_Cash_ID") + " " + getDocumentNo();
|
||||
} // getDocumentInfo
|
||||
|
||||
/**
|
||||
* Create PDF
|
||||
* @return File or null
|
||||
*/
|
||||
public File createPDF ()
|
||||
{
|
||||
try
|
||||
{
|
||||
File temp = File.createTempFile(get_TableName()+get_ID()+"_", ".pdf");
|
||||
return createPDF (temp);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.severe("Could not create PDF - " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
} // getPDF
|
||||
|
||||
/**
|
||||
* Create PDF file
|
||||
* @param file output file
|
||||
* @return file if success
|
||||
*/
|
||||
public File createPDF (File file)
|
||||
{
|
||||
// ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.INVOICE, getC_Invoice_ID());
|
||||
// if (re == null)
|
||||
return null;
|
||||
// return re.getPDF(file);
|
||||
} // createPDF
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
setAD_Org_ID(getCashBook().getAD_Org_ID());
|
||||
if (getAD_Org_ID() == 0)
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@AD_Org_ID@"));
|
||||
return false;
|
||||
}
|
||||
// Calculate End Balance
|
||||
setEndingBalance(getBeginningBalance().add(getStatementDifference()));
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Process document
|
||||
* @param processAction document action
|
||||
* @return true if performed
|
||||
*/
|
||||
public boolean processIt (String processAction)
|
||||
{
|
||||
m_processMsg = null;
|
||||
DocumentEngine engine = new DocumentEngine (this, getDocStatus());
|
||||
return engine.processIt (processAction, getDocAction());
|
||||
} // process
|
||||
|
||||
/** Process Message */
|
||||
private String m_processMsg = null;
|
||||
/** Just Prepared Flag */
|
||||
private boolean m_justPrepared = false;
|
||||
|
||||
/**
|
||||
* Unlock Document.
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean unlockIt()
|
||||
{
|
||||
log.info(toString());
|
||||
setProcessing(false);
|
||||
return true;
|
||||
} // unlockIt
|
||||
|
||||
/**
|
||||
* Invalidate Document
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean invalidateIt()
|
||||
{
|
||||
log.info(toString());
|
||||
setDocAction(DOCACTION_Prepare);
|
||||
return true;
|
||||
} // invalidateIt
|
||||
|
||||
/**
|
||||
* Prepare Document
|
||||
* @return new status (In Progress or Invalid)
|
||||
*/
|
||||
public String prepareIt()
|
||||
{
|
||||
log.info(toString());
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
|
||||
if (m_processMsg != null)
|
||||
return DocAction.STATUS_Invalid;
|
||||
|
||||
// Std Period open?
|
||||
if (!MPeriod.isOpen(getCtx(), getDateAcct(), MDocType.DOCBASETYPE_CashJournal))
|
||||
{
|
||||
m_processMsg = "@PeriodClosed@";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
MCashLine[] lines = getLines(false);
|
||||
if (lines.length == 0)
|
||||
{
|
||||
m_processMsg = "@NoLines@";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
// Add up Amounts
|
||||
BigDecimal difference = Env.ZERO;
|
||||
int C_Currency_ID = getC_Currency_ID();
|
||||
for (int i = 0; i < lines.length; i++)
|
||||
{
|
||||
MCashLine line = lines[i];
|
||||
if (!line.isActive())
|
||||
continue;
|
||||
if (C_Currency_ID == line.getC_Currency_ID())
|
||||
difference = difference.add(line.getAmount());
|
||||
else
|
||||
{
|
||||
BigDecimal amt = MConversionRate.convert(getCtx(), line.getAmount(),
|
||||
line.getC_Currency_ID(), C_Currency_ID, getDateAcct(), 0,
|
||||
getAD_Client_ID(), getAD_Org_ID());
|
||||
if (amt == null)
|
||||
{
|
||||
m_processMsg = "No Conversion Rate found - @C_CashLine_ID@= " + line.getLine();
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
difference = difference.add(amt);
|
||||
}
|
||||
}
|
||||
setStatementDifference(difference);
|
||||
// setEndingBalance(getBeginningBalance().add(getStatementDifference()));
|
||||
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
|
||||
if (m_processMsg != null)
|
||||
return DocAction.STATUS_Invalid;
|
||||
|
||||
m_justPrepared = true;
|
||||
if (!DOCACTION_Complete.equals(getDocAction()))
|
||||
setDocAction(DOCACTION_Complete);
|
||||
return DocAction.STATUS_InProgress;
|
||||
} // prepareIt
|
||||
|
||||
/**
|
||||
* Approve Document
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean approveIt()
|
||||
{
|
||||
log.info(toString());
|
||||
setIsApproved(true);
|
||||
return true;
|
||||
} // approveIt
|
||||
|
||||
/**
|
||||
* Reject Approval
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean rejectIt()
|
||||
{
|
||||
log.info(toString());
|
||||
setIsApproved(false);
|
||||
return true;
|
||||
} // rejectIt
|
||||
|
||||
/**
|
||||
* Complete Document
|
||||
* @return new status (Complete, In Progress, Invalid, Waiting ..)
|
||||
*/
|
||||
public String completeIt()
|
||||
{
|
||||
// Re-Check
|
||||
if (!m_justPrepared)
|
||||
{
|
||||
String status = prepareIt();
|
||||
if (!DocAction.STATUS_InProgress.equals(status))
|
||||
return status;
|
||||
}
|
||||
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE);
|
||||
if (m_processMsg != null)
|
||||
return DocAction.STATUS_Invalid;
|
||||
|
||||
|
||||
// Implicit Approval
|
||||
if (!isApproved())
|
||||
approveIt();
|
||||
//
|
||||
log.info(toString());
|
||||
|
||||
MCashLine[] lines = getLines(false);
|
||||
for (int i = 0; i < lines.length; i++)
|
||||
{
|
||||
MCashLine line = lines[i];
|
||||
if (MCashLine.CASHTYPE_Invoice.equals(line.getCashType()))
|
||||
{
|
||||
// Check if the invoice is completed - teo_sarca BF [ 1894524 ]
|
||||
MInvoice invoice = line.getInvoice();
|
||||
if (!MInvoice.DOCSTATUS_Completed.equals(invoice.getDocStatus())
|
||||
&& !MInvoice.DOCSTATUS_Closed.equals(invoice.getDocStatus()))
|
||||
{
|
||||
m_processMsg = "@Line@ "+line.getLine()+": @InvoiceCreateDocNotCompleted@";
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
//
|
||||
String name = Msg.translate(getCtx(), "C_Cash_ID") + ": " + getName()
|
||||
+ " - " + Msg.translate(getCtx(), "Line") + " " + line.getLine();
|
||||
MAllocationHdr hdr = new MAllocationHdr(getCtx(), false,
|
||||
getDateAcct(), line.getC_Currency_ID(),
|
||||
name, get_TrxName());
|
||||
hdr.setAD_Org_ID(getAD_Org_ID());
|
||||
if (!hdr.save())
|
||||
{
|
||||
m_processMsg = CLogger.retrieveErrorString("Could not create Allocation Hdr");
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
// Allocation Line
|
||||
MAllocationLine aLine = new MAllocationLine (hdr, line.getAmount(),
|
||||
line.getDiscountAmt(), line.getWriteOffAmt(), Env.ZERO);
|
||||
aLine.setC_Invoice_ID(line.getC_Invoice_ID());
|
||||
aLine.setC_CashLine_ID(line.getC_CashLine_ID());
|
||||
if (!aLine.save())
|
||||
{
|
||||
m_processMsg = CLogger.retrieveErrorString("Could not create Allocation Line");
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
// Should start WF
|
||||
if(!hdr.processIt(DocAction.ACTION_Complete)) {
|
||||
m_processMsg = CLogger.retrieveErrorString("Could not process Allocation");
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
if (!hdr.save()) {
|
||||
m_processMsg = CLogger.retrieveErrorString("Could not save Allocation");
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
}
|
||||
else if (MCashLine.CASHTYPE_BankAccountTransfer.equals(line.getCashType()))
|
||||
{
|
||||
// Payment just as intermediate info
|
||||
MPayment pay = new MPayment (getCtx(), 0, get_TrxName());
|
||||
pay.setAD_Org_ID(getAD_Org_ID());
|
||||
String documentNo = getName();
|
||||
pay.setDocumentNo(documentNo);
|
||||
pay.setR_PnRef(documentNo);
|
||||
pay.set_Value("TrxType", "X"); // Transfer
|
||||
pay.set_Value("TenderType", "X");
|
||||
//
|
||||
//Modification for cash payment
|
||||
pay.setC_CashBook_ID(getC_CashBook_ID());
|
||||
//End of modification
|
||||
|
||||
pay.setC_BankAccount_ID(line.getC_BankAccount_ID());
|
||||
pay.setC_DocType_ID(true); // Receipt
|
||||
pay.setDateTrx(getStatementDate());
|
||||
pay.setDateAcct(getDateAcct());
|
||||
pay.setAmount(line.getC_Currency_ID(), line.getAmount().negate()); // Transfer
|
||||
pay.setDescription(line.getDescription());
|
||||
pay.setDocStatus(MPayment.DOCSTATUS_Closed);
|
||||
pay.setDocAction(MPayment.DOCACTION_None);
|
||||
pay.setPosted(true);
|
||||
pay.setIsAllocated(true); // Has No Allocation!
|
||||
pay.setProcessed(true);
|
||||
if (!pay.save())
|
||||
{
|
||||
m_processMsg = CLogger.retrieveErrorString("Could not create Payment");
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// User Validation
|
||||
String valid = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_COMPLETE);
|
||||
if (valid != null)
|
||||
{
|
||||
m_processMsg = valid;
|
||||
return DocAction.STATUS_Invalid;
|
||||
}
|
||||
//
|
||||
setProcessed(true);
|
||||
setDocAction(DOCACTION_Close);
|
||||
return DocAction.STATUS_Completed;
|
||||
} // completeIt
|
||||
|
||||
/**
|
||||
* Void Document.
|
||||
* Same as Close.
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean voidIt()
|
||||
{
|
||||
log.info(toString());
|
||||
// Before Void
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_VOID);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
// After Void
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_VOID);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
setDocAction(DOCACTION_None);
|
||||
return false;
|
||||
} // voidIt
|
||||
|
||||
/**
|
||||
* Close Document.
|
||||
* Cancel not delivered Qunatities
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean closeIt()
|
||||
{
|
||||
log.info(toString());
|
||||
// Before Close
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_CLOSE);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
// After Close
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_CLOSE);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
|
||||
setDocAction(DOCACTION_None);
|
||||
return true;
|
||||
} // closeIt
|
||||
|
||||
/**
|
||||
* Reverse Correction
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean reverseCorrectIt()
|
||||
{
|
||||
log.info(toString());
|
||||
// Before reverseCorrect
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_REVERSECORRECT);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
|
||||
// After reverseCorrect
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_REVERSECORRECT);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
} // reverseCorrectionIt
|
||||
|
||||
/**
|
||||
* Reverse Accrual - none
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean reverseAccrualIt()
|
||||
{
|
||||
log.info(toString());
|
||||
// Before reverseAccrual
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_REVERSEACCRUAL);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
|
||||
// After reverseAccrual
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_REVERSEACCRUAL);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
} // reverseAccrualIt
|
||||
|
||||
/**
|
||||
* Re-activate
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean reActivateIt()
|
||||
{
|
||||
log.info(toString());
|
||||
// Before reActivate
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_BEFORE_REACTIVATE);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
|
||||
setProcessed(false);
|
||||
if (reverseCorrectIt())
|
||||
return true;
|
||||
|
||||
// After reActivate
|
||||
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_REACTIVATE);
|
||||
if (m_processMsg != null)
|
||||
return false;
|
||||
return false;
|
||||
} // reActivateIt
|
||||
|
||||
/**
|
||||
* Set Processed
|
||||
* @param processed processed
|
||||
*/
|
||||
public void setProcessed (boolean processed)
|
||||
{
|
||||
super.setProcessed (processed);
|
||||
String sql = "UPDATE C_CashLine SET Processed='"
|
||||
+ (processed ? "Y" : "N")
|
||||
+ "' WHERE C_Cash_ID=" + getC_Cash_ID();
|
||||
int noLine = DB.executeUpdate (sql, get_TrxName());
|
||||
m_lines = null;
|
||||
log.fine(processed + " - Lines=" + noLine);
|
||||
} // setProcessed
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MCash[");
|
||||
sb.append (get_ID ())
|
||||
.append ("-").append (getName())
|
||||
.append(", Balance=").append(getBeginningBalance())
|
||||
.append("->").append(getEndingBalance())
|
||||
.append ("]");
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
/*************************************************************************
|
||||
* Get Summary
|
||||
* @return Summary of Document
|
||||
*/
|
||||
public String getSummary()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(getName());
|
||||
// : Total Lines = 123.00 (#1)
|
||||
sb.append(": ")
|
||||
.append(Msg.translate(getCtx(),"BeginningBalance")).append("=").append(getBeginningBalance())
|
||||
.append(",")
|
||||
.append(Msg.translate(getCtx(),"EndingBalance")).append("=").append(getEndingBalance())
|
||||
.append(" (#").append(getLines(false).length).append(")");
|
||||
// - Description
|
||||
if (getDescription() != null && getDescription().length() > 0)
|
||||
sb.append(" - ").append(getDescription());
|
||||
return sb.toString();
|
||||
} // getSummary
|
||||
|
||||
/**
|
||||
* Get Process Message
|
||||
* @return clear text error message
|
||||
*/
|
||||
public String getProcessMsg()
|
||||
{
|
||||
return m_processMsg;
|
||||
} // getProcessMsg
|
||||
|
||||
/**
|
||||
* Get Document Owner (Responsible)
|
||||
* @return AD_User_ID
|
||||
*/
|
||||
public int getDoc_User_ID()
|
||||
{
|
||||
return getCreatedBy();
|
||||
} // getDoc_User_ID
|
||||
|
||||
/**
|
||||
* Get Document Approval Amount
|
||||
* @return amount difference
|
||||
*/
|
||||
public BigDecimal getApprovalAmt()
|
||||
{
|
||||
return getStatementDifference();
|
||||
} // getApprovalAmt
|
||||
|
||||
/**
|
||||
* Get Currency
|
||||
* @return Currency
|
||||
*/
|
||||
public int getC_Currency_ID ()
|
||||
{
|
||||
return getCashBook().getC_Currency_ID();
|
||||
} // getC_Currency_ID
|
||||
|
||||
} // MCash
|
|
@ -1,170 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Cash Book Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MCashBook.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class MCashBook extends X_C_CashBook
|
||||
{
|
||||
/**
|
||||
* Get MCashBook from Cache
|
||||
* @param ctx context
|
||||
* @param C_CashBook_ID id
|
||||
* @return MCashBook
|
||||
*/
|
||||
public static MCashBook get (Properties ctx, int C_CashBook_ID)
|
||||
{
|
||||
return get(ctx, C_CashBook_ID, null);
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Gets MCashBook from Cache under transaction scope
|
||||
* @param ctx context
|
||||
* @param C_CashBook_ID id of cashbook to load
|
||||
* @param trxName transaction name
|
||||
* @return Cashbook
|
||||
*/
|
||||
public static MCashBook get(Properties ctx, int C_CashBook_ID, String trxName)
|
||||
{
|
||||
Integer key = new Integer (C_CashBook_ID);
|
||||
MCashBook retValue = (MCashBook) s_cache.get (key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
retValue = new MCashBook (ctx, C_CashBook_ID, trxName);
|
||||
if (retValue.get_ID () != 0)
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
}
|
||||
/**
|
||||
* Get CashBook for Org and Currency
|
||||
* @param ctx context
|
||||
* @param AD_Org_ID org
|
||||
* @param C_Currency_ID currency
|
||||
* @return cash book or null
|
||||
*/
|
||||
public static MCashBook get (Properties ctx, int AD_Org_ID, int C_Currency_ID)
|
||||
{
|
||||
// Try from cache
|
||||
Iterator it = s_cache.values().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
MCashBook cb = (MCashBook)it.next();
|
||||
if (cb.getAD_Org_ID() == AD_Org_ID && cb.getC_Currency_ID() == C_Currency_ID)
|
||||
return cb;
|
||||
}
|
||||
|
||||
// Get from DB
|
||||
MCashBook retValue = null;
|
||||
String sql = "SELECT * FROM C_CashBook "
|
||||
+ "WHERE AD_Org_ID=? AND C_Currency_ID=? "
|
||||
+ "ORDER BY IsDefault DESC";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, AD_Org_ID);
|
||||
pstmt.setInt (2, C_Currency_ID);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
{
|
||||
retValue = new MCashBook (ctx, rs, null);
|
||||
Integer key = new Integer (retValue.getC_CashBook_ID());
|
||||
s_cache.put (key, retValue);
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, "get", e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer,MCashBook> s_cache
|
||||
= new CCache<Integer,MCashBook>("", 20);
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MCashBook.class);
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_CashBook_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MCashBook (Properties ctx, int C_CashBook_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_CashBook_ID, trxName);
|
||||
} // MCashBook
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MCashBook (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MCashBook
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
if (newRecord && success)
|
||||
insert_Accounting("C_CashBook_Acct", "C_AcctSchema_Default", null);
|
||||
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* Before Delete
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeDelete ()
|
||||
{
|
||||
return delete_Accounting("C_Cashbook_Acct");
|
||||
} // beforeDelete
|
||||
|
||||
} // MCashBook
|
|
@ -1,262 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Natural Account
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MElementValue.java,v 1.3 2006/07/30 00:58:37 jjanke Exp $
|
||||
*/
|
||||
public class MElementValue extends X_C_ElementValue
|
||||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_ElementValue_ID ID or 0 for new
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MElementValue(Properties ctx, int C_ElementValue_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_ElementValue_ID, trxName);
|
||||
if (C_ElementValue_ID == 0)
|
||||
{
|
||||
// setC_Element_ID (0); // Parent
|
||||
// setName (null);
|
||||
// setValue (null);
|
||||
setIsSummary (false);
|
||||
setAccountSign (ACCOUNTSIGN_Natural);
|
||||
setAccountType (ACCOUNTTYPE_Expense);
|
||||
setIsDocControlled(false);
|
||||
setIsForeignCurrency(false);
|
||||
setIsBankAccount(false);
|
||||
//
|
||||
setPostActual (true);
|
||||
setPostBudget (true);
|
||||
setPostEncumbrance (true);
|
||||
setPostStatistical (true);
|
||||
}
|
||||
} // MElementValue
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MElementValue(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MElementValue
|
||||
|
||||
/**
|
||||
* Full Constructor
|
||||
* @param ctx context
|
||||
* @param Value value
|
||||
* @param Name name
|
||||
* @param Description description
|
||||
* @param AccountType account type
|
||||
* @param AccountSign account sign
|
||||
* @param IsDocControlled doc controlled
|
||||
* @param IsSummary summary
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MElementValue (Properties ctx, String Value, String Name, String Description,
|
||||
String AccountType, String AccountSign,
|
||||
boolean IsDocControlled, boolean IsSummary, String trxName)
|
||||
{
|
||||
this (ctx, 0, trxName);
|
||||
setValue(Value);
|
||||
setName(Name);
|
||||
setDescription(Description);
|
||||
setAccountType(AccountType);
|
||||
setAccountSign(AccountSign);
|
||||
setIsDocControlled(IsDocControlled);
|
||||
setIsSummary(IsSummary);
|
||||
} // MElementValue
|
||||
|
||||
/**
|
||||
* Import Constructor
|
||||
* @param imp import
|
||||
*/
|
||||
public MElementValue (X_I_ElementValue imp)
|
||||
{
|
||||
this (imp.getCtx(), 0, imp.get_TrxName());
|
||||
setClientOrg(imp);
|
||||
set(imp);
|
||||
} // MElementValue
|
||||
|
||||
/**
|
||||
* Set/Update Settings from import
|
||||
* @param imp import
|
||||
*/
|
||||
public void set (X_I_ElementValue imp)
|
||||
{
|
||||
setValue(imp.getValue());
|
||||
setName(imp.getName());
|
||||
setDescription(imp.getDescription());
|
||||
setAccountType(imp.getAccountType());
|
||||
setAccountSign(imp.getAccountSign());
|
||||
setIsSummary(imp.isSummary());
|
||||
setIsDocControlled(imp.isDocControlled());
|
||||
setC_Element_ID(imp.getC_Element_ID());
|
||||
//
|
||||
setPostActual(imp.isPostActual());
|
||||
setPostBudget(imp.isPostBudget());
|
||||
setPostEncumbrance(imp.isPostEncumbrance());
|
||||
setPostStatistical(imp.isPostStatistical());
|
||||
//
|
||||
// setC_BankAccount_ID(imp.getC_BankAccount_ID());
|
||||
// setIsForeignCurrency(imp.isForeignCurrency());
|
||||
// setC_Currency_ID(imp.getC_Currency_ID());
|
||||
// setIsBankAccount(imp.isIsBankAccount());
|
||||
// setValidFrom(null);
|
||||
// setValidTo(null);
|
||||
} // set
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Is this a Balance Sheet Account
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isBalanceSheet()
|
||||
{
|
||||
String accountType = getAccountType();
|
||||
return (ACCOUNTTYPE_Asset.equals(accountType)
|
||||
|| ACCOUNTTYPE_Liability.equals(accountType)
|
||||
|| ACCOUNTTYPE_OwnerSEquity.equals(accountType));
|
||||
} // isBalanceSheet
|
||||
|
||||
/**
|
||||
* Is this an Activa Account
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isActiva()
|
||||
{
|
||||
return ACCOUNTTYPE_Asset.equals(getAccountType());
|
||||
} // isActive
|
||||
|
||||
/**
|
||||
* Is this a Passiva Account
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isPassiva()
|
||||
{
|
||||
String accountType = getAccountType();
|
||||
return (ACCOUNTTYPE_Liability.equals(accountType)
|
||||
|| ACCOUNTTYPE_OwnerSEquity.equals(accountType));
|
||||
} // isPassiva
|
||||
|
||||
/**
|
||||
* User String Representation
|
||||
* @return info value - name
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ();
|
||||
sb.append(getValue()).append(" - ").append(getName());
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Extended String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toStringX ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MElementValue[");
|
||||
sb.append(get_ID()).append(",").append(getValue()).append(" - ").append(getName())
|
||||
.append ("]");
|
||||
return sb.toString ();
|
||||
} // toStringX
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord
|
||||
* @return true if ir can be saved
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (getAD_Org_ID() != 0)
|
||||
setAD_Org_ID(0);
|
||||
//
|
||||
if (!newRecord && isSummary()
|
||||
&& is_ValueChanged("IsSummary"))
|
||||
{
|
||||
String sql = "SELECT COUNT(*) FROM Fact_Acct WHERE Account_ID=?";
|
||||
int no = DB.getSQLValue(get_TrxName(), sql, getC_ElementValue_ID());
|
||||
if (no != 0)
|
||||
{
|
||||
log.saveError("Error", "Already posted to");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
if (newRecord)
|
||||
{
|
||||
// afalcone [Bugs #1837219]
|
||||
// sendy (transaction scope included)
|
||||
int ad_Tree_ID= (new MElement(getCtx(), getC_Element_ID(), get_TrxName())).getAD_Tree_ID();
|
||||
String treeType= (new MTree(getCtx(),ad_Tree_ID, get_TrxName())).getTreeType();
|
||||
insert_Tree(treeType, getC_Element_ID());
|
||||
// insert_Tree(MTree_Base.TREETYPE_ElementValue, getC_Element_ID()); Old
|
||||
|
||||
}
|
||||
|
||||
// Value/Name change
|
||||
if (!newRecord && (is_ValueChanged("Value") || is_ValueChanged("Name")))
|
||||
{
|
||||
MAccount.updateValueDescription(getCtx(), "Account_ID=" + getC_ElementValue_ID(),get_TrxName());
|
||||
if ("Y".equals(Env.getContext(getCtx(), "$Element_U1")))
|
||||
MAccount.updateValueDescription(getCtx(), "User1_ID=" + getC_ElementValue_ID(),get_TrxName());
|
||||
if ("Y".equals(Env.getContext(getCtx(), "$Element_U2")))
|
||||
MAccount.updateValueDescription(getCtx(), "User2_ID=" + getC_ElementValue_ID(),get_TrxName());
|
||||
}
|
||||
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* After Delete
|
||||
* @param success
|
||||
* @return deleted
|
||||
*/
|
||||
protected boolean afterDelete (boolean success)
|
||||
{
|
||||
if (success)
|
||||
delete_Tree(MTree_Base.TREETYPE_ElementValue);
|
||||
return success;
|
||||
} // afterDelete
|
||||
|
||||
} // MElementValue
|
|
@ -16,29 +16,44 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.print.*;
|
||||
import org.compiere.process.*;
|
||||
import org.compiere.util.*;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.print.ReportEngine;
|
||||
import org.compiere.process.DocAction;
|
||||
import org.compiere.process.DocumentEngine;
|
||||
import org.compiere.report.MReportTree;
|
||||
import org.compiere.util.CCache;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.eevolution.model.MPPProductBOM;
|
||||
import org.eevolution.model.MPPProductBOMLine;
|
||||
|
||||
|
||||
/**
|
||||
* Invoice Model.
|
||||
* Please do not set DocStatus and C_DocType_ID directly.
|
||||
* They are set in the process() method.
|
||||
* Use DocAction and C_DocTypeTarget_ID instead.
|
||||
* Invoice Model.
|
||||
* Please do not set DocStatus and C_DocType_ID directly.
|
||||
* They are set in the process() method.
|
||||
* Use DocAction and C_DocTypeTarget_ID instead.
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MInvoice.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*
|
||||
* @author victor.perez@e-evolution.com
|
||||
* @see http://sourceforge.net/tracker/?func=detail&atid=879335&aid=1948157&group_id=176962
|
||||
* Modifications: Added RMA functionality (Ashley Ramdass)
|
||||
*/
|
||||
public class MInvoice extends X_C_Invoice implements DocAction
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Get Payments Of BPartner
|
||||
* @param ctx context
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* POS Terminal definition
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MPOS.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $
|
||||
*/
|
||||
public class MPOS extends X_C_POS
|
||||
{
|
||||
/**
|
||||
* Get POS from Cache
|
||||
* @param ctx context
|
||||
* @param C_POS_ID id
|
||||
* @return MPOS
|
||||
*/
|
||||
public static MPOS get (Properties ctx, int C_POS_ID)
|
||||
{
|
||||
Integer key = new Integer (C_POS_ID);
|
||||
MPOS retValue = (MPOS) s_cache.get (key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
retValue = new MPOS (ctx, C_POS_ID, null);
|
||||
if (retValue.get_ID () != 0)
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer,MPOS> s_cache = new CCache<Integer,MPOS>("C_POS", 20);
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_POS_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MPOS (Properties ctx, int C_POS_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_POS_ID, trxName);
|
||||
if (C_POS_ID == 0)
|
||||
{
|
||||
// setName (null);
|
||||
// setSalesRep_ID (0);
|
||||
// setC_CashBook_ID (0);
|
||||
// setM_PriceList_ID (0);
|
||||
setIsModifyPrice (false); // N
|
||||
// setM_Warehouse_ID (0);
|
||||
}
|
||||
} // MPOS
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MPOS (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MPOS
|
||||
|
||||
/** Cash Business Partner */
|
||||
private MBPartner m_template = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
// Org Consistency
|
||||
if (newRecord
|
||||
|| is_ValueChanged("C_CashBook_ID") || is_ValueChanged("M_Warehouse_ID"))
|
||||
{
|
||||
MCashBook cb = MCashBook.get(getCtx(), getC_CashBook_ID(), get_TrxName());
|
||||
if (cb.getAD_Org_ID() != getAD_Org_ID())
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@AD_Org_ID@: @C_CashBook_ID@"));
|
||||
return false;
|
||||
}
|
||||
MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID(), get_TrxName());
|
||||
if (wh.getAD_Org_ID() != getAD_Org_ID())
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@AD_Org_ID@: @M_Warehouse_ID@"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
|
||||
/**
|
||||
* Get default Cash BPartner
|
||||
* @return BPartner
|
||||
*/
|
||||
public MBPartner getBPartner()
|
||||
{
|
||||
if (m_template == null)
|
||||
{
|
||||
if (getC_BPartnerCashTrx_ID() == 0)
|
||||
m_template = MBPartner.getBPartnerCashTrx (getCtx(), getAD_Client_ID());
|
||||
else
|
||||
m_template = new MBPartner(getCtx(), getC_BPartnerCashTrx_ID(), get_TrxName());
|
||||
log.fine("getBPartner - " + m_template);
|
||||
}
|
||||
return m_template;
|
||||
} // getBPartner
|
||||
|
||||
} // MPOS
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,247 +0,0 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Warehouse Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MWarehouse.java,v 1.3 2006/07/30 00:58:05 jjanke Exp $
|
||||
*/
|
||||
public class MWarehouse extends X_M_Warehouse
|
||||
{
|
||||
/**
|
||||
* Get from Cache
|
||||
* @param ctx context
|
||||
* @param M_Warehouse_ID id
|
||||
* @return warehouse
|
||||
*/
|
||||
public static MWarehouse get (Properties ctx, int M_Warehouse_ID)
|
||||
{
|
||||
return get(ctx, M_Warehouse_ID, null);
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Retrieves warehouse from cache under transaction scope
|
||||
* @param ctx context
|
||||
* @param M_Warehouse_ID id of warehouse to load
|
||||
* @param trxName transaction name
|
||||
* @return warehouse
|
||||
*/
|
||||
public static MWarehouse get (Properties ctx, int M_Warehouse_ID, String trxName)
|
||||
{
|
||||
Integer key = new Integer(M_Warehouse_ID);
|
||||
MWarehouse retValue = (MWarehouse)s_cache.get(key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
//
|
||||
retValue = new MWarehouse (ctx, M_Warehouse_ID, trxName);
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
}
|
||||
/**
|
||||
* Get Warehouses for Org
|
||||
* @param ctx context
|
||||
* @param AD_Org_ID id
|
||||
* @return warehouse
|
||||
*/
|
||||
public static MWarehouse[] getForOrg (Properties ctx, int AD_Org_ID)
|
||||
{
|
||||
ArrayList<MWarehouse> list = new ArrayList<MWarehouse>();
|
||||
String sql = "SELECT * FROM M_Warehouse WHERE AD_Org_ID=? ORDER BY Created";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, AD_Org_ID);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add (new MWarehouse (ctx, rs, null));
|
||||
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;
|
||||
}
|
||||
MWarehouse[] retValue = new MWarehouse[list.size ()];
|
||||
list.toArray (retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer,MWarehouse> s_cache = new CCache<Integer,MWarehouse>("M_Warehouse", 5);
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MWarehouse.class);
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param M_Warehouse_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MWarehouse (Properties ctx, int M_Warehouse_ID, String trxName)
|
||||
{
|
||||
super(ctx, M_Warehouse_ID, trxName);
|
||||
if (M_Warehouse_ID == 0)
|
||||
{
|
||||
// setValue (null);
|
||||
// setName (null);
|
||||
// setC_Location_ID (0);
|
||||
setSeparator ("*"); // *
|
||||
}
|
||||
} // MWarehouse
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MWarehouse (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MWarehouse
|
||||
|
||||
/**
|
||||
* Organization Constructor
|
||||
* @param org parent
|
||||
*/
|
||||
public MWarehouse (MOrg org)
|
||||
{
|
||||
this (org.getCtx(), 0, org.get_TrxName());
|
||||
setClientOrg(org);
|
||||
setValue (org.getValue());
|
||||
setName (org.getName());
|
||||
if (org.getInfo() != null)
|
||||
setC_Location_ID (org.getInfo().getC_Location_ID());
|
||||
} // MWarehouse
|
||||
|
||||
/** Warehouse Locators */
|
||||
private MLocator[] m_locators = null;
|
||||
|
||||
/**
|
||||
* Get Locators
|
||||
* @param reload if true reload
|
||||
* @return array of locators
|
||||
*/
|
||||
public MLocator[] getLocators(boolean reload)
|
||||
{
|
||||
if (!reload && m_locators != null)
|
||||
return m_locators;
|
||||
//
|
||||
String sql = "SELECT * FROM M_Locator WHERE M_Warehouse_ID=? ORDER BY X,Y,Z";
|
||||
ArrayList<MLocator> list = new ArrayList<MLocator>();
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, getM_Warehouse_ID());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add(new MLocator (getCtx(), rs, null));
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
//
|
||||
m_locators = new MLocator[list.size()];
|
||||
list.toArray (m_locators);
|
||||
return m_locators;
|
||||
} // getLocators
|
||||
|
||||
/**
|
||||
* Get Default Locator
|
||||
* @return (first) default locator
|
||||
*/
|
||||
public MLocator getDefaultLocator()
|
||||
{
|
||||
MLocator[] locators = getLocators(false);
|
||||
for (int i = 0; i < locators.length; i++)
|
||||
{
|
||||
if (locators[i].isDefault() && locators[i].isActive())
|
||||
return locators[i];
|
||||
}
|
||||
// No Default - first one
|
||||
if (locators.length > 0)
|
||||
{
|
||||
log.warning("No default locator for " + getName());
|
||||
return locators[0];
|
||||
}
|
||||
// No Locator - create one
|
||||
MLocator loc = new MLocator (this, "Standard");
|
||||
loc.setIsDefault(true);
|
||||
loc.save();
|
||||
log.info("Created default locator for " + getName());
|
||||
return loc;
|
||||
} // getLocators
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
if (newRecord && success)
|
||||
insert_Accounting("M_Warehouse_Acct", "C_AcctSchema_Default", null);
|
||||
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* Before Delete
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeDelete ()
|
||||
{
|
||||
return delete_Accounting("M_Warehouse_Acct");
|
||||
} // beforeDelete
|
||||
|
||||
} // MWarehouse
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue