Adempiere 3.1.2
This commit is contained in:
parent
39a4889c05
commit
6c5fa90281
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -3,95 +3,216 @@
|
|||
* 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;
|
||||
* 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.Level;
|
||||
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
||||
/**
|
||||
* BP Bank Account Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MBPBankAccount.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MBPBankAccount.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||
*/
|
||||
public class MBPBankAccount extends X_C_BP_BankAccount
|
||||
{
|
||||
|
||||
/**
|
||||
* Get Accounst Of BPartner
|
||||
* @param ctx context
|
||||
* @param C_BPartner_ID bpartner
|
||||
* @return
|
||||
*/
|
||||
public static MBPBankAccount[] getOfBPartner (Properties ctx, int C_BPartner_ID)
|
||||
{
|
||||
String sql = "SELECT * FROM C_BP_BankAccount WHERE C_BPartner_ID=? AND IsActive='Y'";
|
||||
ArrayList<MBPBankAccount> list = new ArrayList<MBPBankAccount>();
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, C_BPartner_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
list.add(new MBPBankAccount(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;
|
||||
}
|
||||
|
||||
|
||||
MBPBankAccount[] retValue = new MBPBankAccount[list.size()];
|
||||
list.toArray(retValue);
|
||||
return retValue;
|
||||
} // getOfBPartner
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger(MBPBankAccount.class);
|
||||
|
||||
/**************************************************************************
|
||||
* Constructor
|
||||
* @param ctx context
|
||||
* @param C_BP_BankAccount_ID BP bank account
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MBPBankAccount (Properties ctx, int C_BP_BankAccount_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_BP_BankAccount_ID, trxName);
|
||||
if (C_BP_BankAccount_ID == 0)
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MBPBankAccount (Properties ctx, int C_BP_BankAccount_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_BP_BankAccount_ID, trxName);
|
||||
if (C_BP_BankAccount_ID == 0)
|
||||
{
|
||||
// setC_BPartner_ID (0);
|
||||
setIsACH (false);
|
||||
setBPBankAcctUse(BPBANKACCTUSE_Both);
|
||||
}
|
||||
} // MBP_BankAccount
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MBPBankAccount (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MBP_BankAccount
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param ctx context
|
||||
* @param bp BP
|
||||
* @param bpc BP Contact
|
||||
* @param location Location
|
||||
/**
|
||||
* Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MBPBankAccount (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MBP_BankAccount
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param ctx context
|
||||
* @param bp BP
|
||||
* @param bpc BP Contact
|
||||
* @param location Location
|
||||
*/
|
||||
public MBPBankAccount (Properties ctx, MBPartner bp, MUser bpc, MLocation location)
|
||||
{
|
||||
super(ctx, 0, bp.get_TrxName());
|
||||
this(ctx, 0, bp.get_TrxName());
|
||||
setIsACH (false);
|
||||
//
|
||||
setC_BPartner_ID(bp.getC_BPartner_ID());
|
||||
//
|
||||
setA_Name(bpc.getName());
|
||||
setA_EMail(bpc.getEMail());
|
||||
//
|
||||
setA_Street(location.getAddress1());
|
||||
setA_City(location.getCity());
|
||||
setA_Zip(location.getPostal());
|
||||
setA_State(location.getRegionName(true));
|
||||
//
|
||||
setA_Name(bpc.getName());
|
||||
setA_EMail(bpc.getEMail());
|
||||
//
|
||||
setA_Street(location.getAddress1());
|
||||
setA_City(location.getCity());
|
||||
setA_Zip(location.getPostal());
|
||||
setA_State(location.getRegionName(true));
|
||||
setA_Country(location.getCountryName());
|
||||
} // MBP_BankAccount
|
||||
|
||||
/** Bank Link */
|
||||
private MBank m_bank = null;
|
||||
|
||||
/*************************************************************************/
|
||||
/**
|
||||
* Is Direct Deposit
|
||||
* @return true if dd
|
||||
*/
|
||||
public boolean isDirectDeposit()
|
||||
{
|
||||
if (!isACH())
|
||||
return false;
|
||||
String s = getBPBankAcctUse();
|
||||
if (s == null)
|
||||
return true;
|
||||
return (s.equals(BPBANKACCTUSE_Both) || s.equals(BPBANKACCTUSE_DirectDeposit));
|
||||
} // isDirectDeposit
|
||||
|
||||
/**
|
||||
* Is Direct Debit
|
||||
* @return true if dd
|
||||
*/
|
||||
public boolean isDirectDebit()
|
||||
{
|
||||
if (!isACH())
|
||||
return false;
|
||||
String s = getBPBankAcctUse();
|
||||
if (s == null)
|
||||
return true;
|
||||
return (s.equals(BPBANKACCTUSE_Both) || s.equals(BPBANKACCTUSE_DirectDebit));
|
||||
} // isDirectDebit
|
||||
|
||||
|
||||
/**
|
||||
* Get Bank
|
||||
* @return bank
|
||||
*/
|
||||
public MBank getBank()
|
||||
{
|
||||
int C_BP_BankAccount_ID = getC_BP_BankAccount_ID();
|
||||
if (C_BP_BankAccount_ID == 0)
|
||||
return null;
|
||||
if (m_bank == null)
|
||||
m_bank = new MBank (getCtx(), C_BP_BankAccount_ID, get_TrxName());
|
||||
return m_bank;
|
||||
} // getBank
|
||||
|
||||
/**
|
||||
* Get Routing No
|
||||
* @return routing No
|
||||
*/
|
||||
public String getRoutingNo()
|
||||
{
|
||||
MBank bank = getBank();
|
||||
String rt = super.getRoutingNo();
|
||||
if (bank != null)
|
||||
rt = bank.getRoutingNo();
|
||||
return rt;
|
||||
} // getRoutingNo
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave(boolean newRecord)
|
||||
{
|
||||
// maintain routing on bank level
|
||||
if (isACH() && getBank() != null)
|
||||
setRoutingNo(null);
|
||||
//
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MBP_BankAccount[")
|
||||
.append (get_ID ())
|
||||
.append(", Name=").append(getA_Name())
|
||||
.append ("]");
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
} // MBPBankAccount
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MBP_BankAccount[")
|
||||
.append (get_ID ())
|
||||
.append(", Name=").append(getA_Name())
|
||||
.append ("]");
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
} // MBPBankAccount
|
||||
|
|
|
@ -3,237 +3,238 @@
|
|||
* 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.text.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.apache.ecs.xhtml.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Chat Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MChat.java,v 1.4 2006/07/30 00:51:05 jjanke Exp $
|
||||
*/
|
||||
public class MChat extends X_CM_Chat
|
||||
{
|
||||
/**
|
||||
* Get Chats Of Table - of client in context
|
||||
* @param ctx context
|
||||
* @param AD_Table_ID table
|
||||
* @return array of chats
|
||||
*/
|
||||
public static MChat[] getOfTable (Properties ctx, int AD_Table_ID)
|
||||
{
|
||||
int AD_Client_ID = Env.getAD_Client_ID(ctx);
|
||||
ArrayList<MChat> list = new ArrayList<MChat>();
|
||||
//
|
||||
String sql = "SELECT * FROM CM_Chat "
|
||||
+ "WHERE AD_Client_ID=? AND AD_Table_ID=? ORDER BY Record_ID";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, AD_Client_ID);
|
||||
pstmt.setInt (2, AD_Table_ID);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
list.add (new MChat (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;
|
||||
}
|
||||
//
|
||||
MChat[] retValue = new MChat[list.size()];
|
||||
list.toArray (retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MChat.class);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param CM_Chat_ID id
|
||||
* @param trxName transcation
|
||||
*/
|
||||
public MChat (Properties ctx, int CM_Chat_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_Chat_ID, trxName);
|
||||
if (CM_Chat_ID == 0)
|
||||
{
|
||||
* 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.text.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.apache.ecs.xhtml.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Chat Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MChat.java,v 1.4 2006/07/30 00:51:05 jjanke Exp $
|
||||
*/
|
||||
public class MChat extends X_CM_Chat
|
||||
{
|
||||
/**
|
||||
* Get Chats Of Table - of client in context
|
||||
* @param ctx context
|
||||
* @param AD_Table_ID table
|
||||
* @return array of chats
|
||||
*/
|
||||
public static MChat[] getOfTable (Properties ctx, int AD_Table_ID)
|
||||
{
|
||||
int AD_Client_ID = Env.getAD_Client_ID(ctx);
|
||||
ArrayList<MChat> list = new ArrayList<MChat>();
|
||||
//
|
||||
String sql = "SELECT * FROM CM_Chat "
|
||||
+ "WHERE AD_Client_ID=? AND AD_Table_ID=? ORDER BY Record_ID";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, AD_Client_ID);
|
||||
pstmt.setInt (2, AD_Table_ID);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
list.add (new MChat (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;
|
||||
}
|
||||
//
|
||||
MChat[] retValue = new MChat[list.size()];
|
||||
list.toArray (retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MChat.class);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param CM_Chat_ID id
|
||||
* @param trxName transcation
|
||||
*/
|
||||
public MChat (Properties ctx, int CM_Chat_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_Chat_ID, trxName);
|
||||
if (CM_Chat_ID == 0)
|
||||
{
|
||||
// setAD_Table_ID (0);
|
||||
// setRecord_ID (0);
|
||||
setConfidentialType (CONFIDENTIALTYPE_PublicInformation);
|
||||
setModerationType (MODERATIONTYPE_NotModerated);
|
||||
// setDescription (null);
|
||||
}
|
||||
} // MChat
|
||||
|
||||
/**
|
||||
* Full Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Table_ID table
|
||||
* @param Record_ID record
|
||||
* @param Description description
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChat (Properties ctx, int AD_Table_ID, int Record_ID,
|
||||
String Description, String trxName)
|
||||
{
|
||||
this (ctx, 0, trxName);
|
||||
setAD_Table_ID (AD_Table_ID);
|
||||
setRecord_ID (Record_ID);
|
||||
setDescription (Description);
|
||||
} // MChat
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChat (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MChat
|
||||
|
||||
/** The Lines */
|
||||
private MChatEntry[] m_entries = null;
|
||||
/** Date Format */
|
||||
private SimpleDateFormat m_format = null;
|
||||
|
||||
|
||||
/**
|
||||
* Get Entries
|
||||
* @param reload reload data
|
||||
* @return array of lines
|
||||
*/
|
||||
public MChatEntry[] getEntries (boolean reload)
|
||||
{
|
||||
if (m_entries != null && !reload)
|
||||
return m_entries;
|
||||
ArrayList<MChatEntry> list = new ArrayList<MChatEntry>();
|
||||
String sql = "SELECT * FROM CM_ChatEntry WHERE CM_Chat_ID=? ORDER BY Created";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, getCM_Chat_ID());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
list.add (new MChatEntry (getCtx(), rs, get_TrxName()));
|
||||
}
|
||||
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_entries = new MChatEntry[list.size ()];
|
||||
list.toArray (m_entries);
|
||||
return m_entries;
|
||||
} // getEntries
|
||||
|
||||
|
||||
/**
|
||||
* Set Description
|
||||
*
|
||||
* @param Description
|
||||
*/
|
||||
public void setDescription (String Description)
|
||||
{
|
||||
if (Description != null && Description.length() > 0)
|
||||
super.setDescription (Description);
|
||||
else
|
||||
super.setDescription (getAD_Table_ID() + "#" + getRecord_ID());
|
||||
} // setDescription
|
||||
|
||||
/**
|
||||
* Get History as htlp paragraph
|
||||
* @param ConfidentialType confidentiality
|
||||
* @return html paragraph
|
||||
*/
|
||||
public p getHistory (String ConfidentialType)
|
||||
{
|
||||
p history = new p();
|
||||
getEntries(false);
|
||||
boolean first = true;
|
||||
for (int i = 0; i < m_entries.length; i++)
|
||||
{
|
||||
MChatEntry entry = m_entries[i];
|
||||
if (!entry.isActive() || !entry.isConfidentialType(ConfidentialType))
|
||||
continue;
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
history.addElement(new hr());
|
||||
// User & Date
|
||||
b b = new b();
|
||||
MUser user = MUser.get(getCtx(), entry.getCreatedBy());
|
||||
b.addElement(user.getName());
|
||||
b.addElement(" \t");
|
||||
Timestamp created = entry.getCreated();
|
||||
if (m_format == null)
|
||||
m_format = DisplayType.getDateFormat(DisplayType.DateTime);
|
||||
b.addElement(m_format.format(created));
|
||||
history.addElement(b);
|
||||
// history.addElement(new br());
|
||||
//
|
||||
p p = new p();
|
||||
String data = entry.getCharacterData();
|
||||
data = Util.maskHTML(data, true);
|
||||
p.addElement(data);
|
||||
history.addElement(p);
|
||||
} // entry
|
||||
//
|
||||
return history;
|
||||
} // getHistory
|
||||
|
||||
|
||||
} // MChat
|
||||
|
||||
/**
|
||||
* Full Constructor
|
||||
* @param ctx context
|
||||
* @param AD_Table_ID table
|
||||
* @param Record_ID record
|
||||
* @param Description description
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChat (Properties ctx, int AD_Table_ID, int Record_ID,
|
||||
String Description, String trxName)
|
||||
{
|
||||
this (ctx, 0, trxName);
|
||||
setAD_Table_ID (AD_Table_ID);
|
||||
setRecord_ID (Record_ID);
|
||||
setDescription (Description);
|
||||
} // MChat
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChat (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MChat
|
||||
|
||||
/** The Lines */
|
||||
private MChatEntry[] m_entries = null;
|
||||
/** Date Format */
|
||||
private SimpleDateFormat m_format = null;
|
||||
|
||||
|
||||
/**
|
||||
* Get Entries
|
||||
* @param reload reload data
|
||||
* @return array of lines
|
||||
*/
|
||||
public MChatEntry[] getEntries (boolean reload)
|
||||
{
|
||||
if (m_entries != null && !reload)
|
||||
return m_entries;
|
||||
ArrayList<MChatEntry> list = new ArrayList<MChatEntry>();
|
||||
String sql = "SELECT * FROM CM_ChatEntry WHERE CM_Chat_ID=? ORDER BY Created";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, getCM_Chat_ID());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
list.add (new MChatEntry (getCtx(), rs, get_TrxName()));
|
||||
}
|
||||
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_entries = new MChatEntry[list.size ()];
|
||||
list.toArray (m_entries);
|
||||
return m_entries;
|
||||
} // getEntries
|
||||
|
||||
|
||||
/**
|
||||
* Set Description
|
||||
*
|
||||
* @param Description
|
||||
*/
|
||||
public void setDescription (String Description)
|
||||
{
|
||||
if (Description != null && Description.length() > 0)
|
||||
super.setDescription (Description);
|
||||
else
|
||||
super.setDescription (getAD_Table_ID() + "#" + getRecord_ID());
|
||||
} // setDescription
|
||||
|
||||
/**
|
||||
* Get History as htlp paragraph
|
||||
* @param ConfidentialType confidentiality
|
||||
* @return html paragraph
|
||||
*/
|
||||
public p getHistory (String ConfidentialType)
|
||||
{
|
||||
p history = new p();
|
||||
getEntries(false);
|
||||
boolean first = true;
|
||||
for (int i = 0; i < m_entries.length; i++)
|
||||
{
|
||||
MChatEntry entry = m_entries[i];
|
||||
if (!entry.isActive() || !entry.isConfidentialType(ConfidentialType))
|
||||
continue;
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
history.addElement(new hr());
|
||||
// User & Date
|
||||
b b = new b();
|
||||
MUser user = MUser.get(getCtx(), entry.getCreatedBy());
|
||||
b.addElement(user.getName());
|
||||
b.addElement(" \t");
|
||||
Timestamp created = entry.getCreated();
|
||||
if (m_format == null)
|
||||
m_format = DisplayType.getDateFormat(DisplayType.DateTime);
|
||||
b.addElement(m_format.format(created));
|
||||
history.addElement(b);
|
||||
// history.addElement(new br());
|
||||
//
|
||||
p p = new p();
|
||||
String data = entry.getCharacterData();
|
||||
data = Util.maskHTML(data, true);
|
||||
p.addElement(data);
|
||||
history.addElement(p);
|
||||
} // entry
|
||||
//
|
||||
return history;
|
||||
} // getHistory
|
||||
|
||||
|
||||
} // MChat
|
||||
|
|
|
@ -3,91 +3,116 @@
|
|||
* 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;
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Chat Entry Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MChatEntry.java,v 1.2 2006/07/30 00:51:03 jjanke Exp $
|
||||
*/
|
||||
public class MChatEntry extends X_CM_ChatEntry
|
||||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx cintext
|
||||
* @param CM_ChatEntry_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MChatEntry.java,v 1.2 2006/07/30 00:51:03 jjanke Exp $
|
||||
*/
|
||||
public class MChatEntry extends X_CM_ChatEntry
|
||||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx cintext
|
||||
* @param CM_ChatEntry_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChatEntry (Properties ctx, int CM_ChatEntry_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_ChatEntry_ID, trxName);
|
||||
if (CM_ChatEntry_ID == 0)
|
||||
{
|
||||
setChatEntryType (CHATENTRYTYPE_NoteFlat); // N
|
||||
setConfidentialType (CONFIDENTIALTYPE_PublicInformation);
|
||||
}
|
||||
} // MChatEntry
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param chat parent
|
||||
* @param data text
|
||||
*/
|
||||
public MChatEntry (MChat chat, String data)
|
||||
{
|
||||
this (chat.getCtx(), 0, chat.get_TrxName());
|
||||
* Parent Constructor
|
||||
* @param chat parent
|
||||
* @param data text
|
||||
*/
|
||||
public MChatEntry (MChat chat, String data)
|
||||
{
|
||||
this (chat.getCtx(), 0, chat.get_TrxName());
|
||||
setCM_Chat_ID(chat.getCM_Chat_ID());
|
||||
setConfidentialType(chat.getConfidentialType());
|
||||
setCharacterData(data);
|
||||
setChatEntryType (CHATENTRYTYPE_NoteFlat); // N
|
||||
} // MChatEntry
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
* Thread Constructor
|
||||
* @param entry peer
|
||||
* @param data text
|
||||
*/
|
||||
public MChatEntry (Properties ctx, ResultSet rs, String trxName)
|
||||
public MChatEntry (MChatEntry peer, String data)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
this (peer.getCtx(), 0, peer.get_TrxName());
|
||||
setCM_Chat_ID(peer.getCM_Chat_ID());
|
||||
setCM_ChatEntryParent_ID (peer.getCM_ChatEntryParent_ID());
|
||||
// Set GrandParent
|
||||
int id = peer.getCM_ChatEntryGrandParent_ID();
|
||||
if (id == 0)
|
||||
id = peer.getCM_ChatEntryParent_ID();
|
||||
setCM_ChatEntryGrandParent_ID (id);
|
||||
setConfidentialType(peer.getConfidentialType());
|
||||
setCharacterData(data);
|
||||
setChatEntryType (CHATENTRYTYPE_ForumThreaded);
|
||||
} // MChatEntry
|
||||
|
||||
/**
|
||||
* Can be published
|
||||
* @param ConfidentialType minimum confidential type
|
||||
* @return true if withing confidentiality
|
||||
*/
|
||||
public boolean isConfidentialType(String ConfidentialType)
|
||||
{
|
||||
String ct = getConfidentialType();
|
||||
if (ConfidentialType == null
|
||||
|| CONFIDENTIALTYPE_PublicInformation.equals(ct))
|
||||
return true;
|
||||
if (CONFIDENTIALTYPE_PartnerConfidential.equals(ct))
|
||||
{
|
||||
return CONFIDENTIALTYPE_PartnerConfidential.equals(ConfidentialType);
|
||||
}
|
||||
else if (CONFIDENTIALTYPE_PrivateInformation.equals(ct))
|
||||
{
|
||||
return CONFIDENTIALTYPE_Internal.equals(ConfidentialType)
|
||||
|| CONFIDENTIALTYPE_PrivateInformation.equals(ConfidentialType);
|
||||
}
|
||||
else if (CONFIDENTIALTYPE_Internal.equals(ct))
|
||||
{
|
||||
return CONFIDENTIALTYPE_Internal.equals(ConfidentialType);
|
||||
}
|
||||
return false;
|
||||
} //
|
||||
|
||||
} // MChatEntry
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChatEntry (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MChatEntry
|
||||
|
||||
/**
|
||||
* Can be published
|
||||
* @param ConfidentialType minimum confidential type
|
||||
* @return true if withing confidentiality
|
||||
*/
|
||||
public boolean isConfidentialType(String ConfidentialType)
|
||||
{
|
||||
String ct = getConfidentialType();
|
||||
if (ConfidentialType == null
|
||||
|| CONFIDENTIALTYPE_PublicInformation.equals(ct))
|
||||
return true;
|
||||
if (CONFIDENTIALTYPE_PartnerConfidential.equals(ct))
|
||||
{
|
||||
return CONFIDENTIALTYPE_PartnerConfidential.equals(ConfidentialType);
|
||||
}
|
||||
else if (CONFIDENTIALTYPE_PrivateInformation.equals(ct))
|
||||
{
|
||||
return CONFIDENTIALTYPE_Internal.equals(ConfidentialType)
|
||||
|| CONFIDENTIALTYPE_PrivateInformation.equals(ConfidentialType);
|
||||
}
|
||||
else if (CONFIDENTIALTYPE_Internal.equals(ct))
|
||||
{
|
||||
return CONFIDENTIALTYPE_Internal.equals(ConfidentialType);
|
||||
}
|
||||
return false;
|
||||
} //
|
||||
|
||||
} // MChatEntry
|
||||
|
|
|
@ -3,73 +3,75 @@
|
|||
* 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.*;
|
||||
|
||||
/**
|
||||
* Chat Type Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MChatType.java,v 1.2 2006/07/30 00:51:03 jjanke Exp $
|
||||
*/
|
||||
public class MChatType extends X_CM_ChatType
|
||||
{
|
||||
/**
|
||||
* Get MChatType from Cache
|
||||
* @param ctx context
|
||||
* @param CM_ChatType_ID id
|
||||
* @return MChatType
|
||||
*/
|
||||
public static MChatType get (Properties ctx, int CM_ChatType_ID)
|
||||
{
|
||||
Integer key = new Integer (CM_ChatType_ID);
|
||||
MChatType retValue = (MChatType)s_cache.get (key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
retValue = new MChatType (ctx, CM_ChatType_ID, null);
|
||||
if (retValue.get_ID () != CM_ChatType_ID)
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer, MChatType> s_cache
|
||||
= new CCache<Integer, MChatType> ("CM_ChatType", 20);
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param CM_ChatType_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Chat Type Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MChatType.java,v 1.2 2006/07/30 00:51:03 jjanke Exp $
|
||||
*/
|
||||
public class MChatType extends X_CM_ChatType
|
||||
{
|
||||
/**
|
||||
* Get MChatType from Cache
|
||||
* @param ctx context
|
||||
* @param CM_ChatType_ID id
|
||||
* @return MChatType
|
||||
*/
|
||||
public static MChatType get (Properties ctx, int CM_ChatType_ID)
|
||||
{
|
||||
Integer key = new Integer (CM_ChatType_ID);
|
||||
MChatType retValue = (MChatType)s_cache.get (key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
retValue = new MChatType (ctx, CM_ChatType_ID, null);
|
||||
if (retValue.get_ID () != CM_ChatType_ID)
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer, MChatType> s_cache
|
||||
= new CCache<Integer, MChatType> ("CM_ChatType", 20);
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param CM_ChatType_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChatType (Properties ctx, int CM_ChatType_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_ChatType_ID, trxName);
|
||||
if (CM_ChatType_ID == 0)
|
||||
setModerationType (MODERATIONTYPE_NotModerated);
|
||||
} // MChatType
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChatType (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MChatType
|
||||
|
||||
} // MChatType
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MChatType (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MChatType
|
||||
|
||||
} // MChatType
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,115 +3,160 @@
|
|||
* 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.*;
|
||||
|
||||
/**
|
||||
* CStage Element
|
||||
*
|
||||
* @author Yves Sandfort
|
||||
* @version $Id$
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* CStage Element
|
||||
*
|
||||
* @author Yves Sandfort
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MContainerElement extends X_CM_Container_Element
|
||||
{
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 7230036377422361941L;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MContainer.class);
|
||||
|
||||
/**
|
||||
* get Container Element by ID
|
||||
* @param ctx
|
||||
* @param CM_ContainerElement_ID
|
||||
* @param trxName
|
||||
* @return ContainerElement
|
||||
*/
|
||||
public static MContainerElement get(Properties ctx, int CM_ContainerElement_ID, String trxName) {
|
||||
MContainerElement thisContainerElement = null;
|
||||
String sql = "SELECT * FROM CM_Container_Element WHERE CM_Container_Element_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, trxName);
|
||||
pstmt.setInt(1, CM_ContainerElement_ID);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
thisContainerElement = (new MContainerElement(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;
|
||||
}
|
||||
return thisContainerElement;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* Standard Constructor
|
||||
*
|
||||
* @param ctx context
|
||||
* @param CM_Container_Element_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MContainerElement (Properties ctx, int CM_Container_Element_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_Container_Element_ID, trxName);
|
||||
if (CM_Container_Element_ID == 0)
|
||||
{
|
||||
setIsValid(false);
|
||||
}
|
||||
} // MContainerElement
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
*
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MContainerElement (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MContainerElement
|
||||
|
||||
/** Parent */
|
||||
private MContainer m_parent = null;
|
||||
|
||||
/**
|
||||
* Get Container get's related Container
|
||||
* @return MContainer
|
||||
*/
|
||||
public MContainer getParent()
|
||||
{
|
||||
if (m_parent == null)
|
||||
m_parent = new MContainer (getCtx(), getCM_Container_ID(), get_TrxName());
|
||||
return m_parent;
|
||||
|
||||
/** No reason to do this ?? - should never return null - always there - JJ
|
||||
int[] thisContainer = MContainer.getAllIDs("CM_Container","CM_Container_ID=" + this.getCM_Container_ID(), get_TrxName());
|
||||
if (thisContainer != null)
|
||||
{
|
||||
if (thisContainer.length==1)
|
||||
return new MContainer(getCtx(), thisContainer[0], get_TrxName());
|
||||
}
|
||||
return null;
|
||||
**/
|
||||
} // getContainer
|
||||
|
||||
/**
|
||||
* After Save.
|
||||
* Insert
|
||||
* - create / update index
|
||||
* @param newRecord insert
|
||||
* @param success save success
|
||||
* @return true if saved
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
if (!success)
|
||||
return success;
|
||||
reIndex(newRecord);
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* reIndex
|
||||
* @param newRecord
|
||||
*/
|
||||
public void reIndex(boolean newRecord)
|
||||
{
|
||||
int CMWebProjectID = 0;
|
||||
if (getParent()!=null)
|
||||
CMWebProjectID = getParent().getCM_WebProject_ID();
|
||||
String [] toBeIndexed = new String[3];
|
||||
toBeIndexed[0] = this.getName();
|
||||
toBeIndexed[1] = this.getDescription();
|
||||
toBeIndexed[2] = this.getContentHTML();
|
||||
MIndex.reIndex (newRecord, toBeIndexed, getCtx(),
|
||||
getAD_Client_ID(), get_Table_ID(), get_ID(), CMWebProjectID, this.getUpdated());
|
||||
} // reIndex
|
||||
|
||||
} // MContainerElement
|
||||
* @param ctx context
|
||||
* @param CM_Container_Element_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MContainerElement (Properties ctx, int CM_Container_Element_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_Container_Element_ID, trxName);
|
||||
if (CM_Container_Element_ID == 0)
|
||||
{
|
||||
setIsValid(false);
|
||||
}
|
||||
} // MContainerElement
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
*
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MContainerElement (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MContainerElement
|
||||
|
||||
/** Parent */
|
||||
private MContainer m_parent = null;
|
||||
|
||||
/**
|
||||
* Get Container get's related Container
|
||||
* @return MContainer
|
||||
*/
|
||||
public MContainer getParent()
|
||||
{
|
||||
if (m_parent == null)
|
||||
m_parent = new MContainer (getCtx(), getCM_Container_ID(), get_TrxName());
|
||||
return m_parent;
|
||||
|
||||
/** No reason to do this ?? - should never return null - always there - JJ
|
||||
int[] thisContainer = MContainer.getAllIDs("CM_Container","CM_Container_ID=" + this.getCM_Container_ID(), get_TrxName());
|
||||
if (thisContainer != null)
|
||||
{
|
||||
if (thisContainer.length==1)
|
||||
return new MContainer(getCtx(), thisContainer[0], get_TrxName());
|
||||
}
|
||||
return null;
|
||||
**/
|
||||
} // getContainer
|
||||
|
||||
/**
|
||||
* After Save.
|
||||
* Insert
|
||||
* - create / update index
|
||||
* @param newRecord insert
|
||||
* @param success save success
|
||||
* @return true if saved
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
if (!success)
|
||||
return success;
|
||||
reIndex(newRecord);
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* reIndex
|
||||
* @param newRecord
|
||||
*/
|
||||
public void reIndex(boolean newRecord)
|
||||
{
|
||||
int CMWebProjectID = 0;
|
||||
if (getParent()!=null)
|
||||
CMWebProjectID = getParent().getCM_WebProject_ID();
|
||||
String [] toBeIndexed = new String[3];
|
||||
toBeIndexed[0] = this.getName();
|
||||
toBeIndexed[1] = this.getDescription();
|
||||
toBeIndexed[2] = this.getContentHTML();
|
||||
MIndex.reIndex (newRecord, toBeIndexed, getCtx(),
|
||||
getAD_Client_ID(), get_Table_ID(), get_ID(), CMWebProjectID, this.getUpdated());
|
||||
} // reIndex
|
||||
|
||||
} // MContainerElement
|
||||
|
|
|
@ -3,51 +3,115 @@
|
|||
* 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;
|
||||
* 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.Level;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
||||
|
||||
/**
|
||||
* Dunning Level Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MDunningLevel.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
|
||||
* Dunning Level Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MDunningLevel.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class MDunningLevel extends X_C_DunningLevel
|
||||
{
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MPayment.class);
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_DunningLevel_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningLevel (Properties ctx, int C_DunningLevel_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_DunningLevel_ID, trxName);
|
||||
} // MDunningLevel
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningLevel (Properties ctx, ResultSet rs, String trxName)
|
||||
* @param C_DunningLevel_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningLevel (Properties ctx, int C_DunningLevel_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_DunningLevel_ID, trxName);
|
||||
} // MDunningLevel
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningLevel (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MDunningLevel
|
||||
|
||||
private MDunning m_dunning = null;
|
||||
|
||||
/**
|
||||
* get Parent
|
||||
* @return Parent Dunning
|
||||
*/
|
||||
public MDunning getParent()
|
||||
{
|
||||
if (m_dunning==null)
|
||||
m_dunning = new MDunning(getCtx(), getC_Dunning_ID(), get_TrxName());
|
||||
return m_dunning;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Previous Levels
|
||||
* @return Array of previous DunningLevels
|
||||
*/
|
||||
public MDunningLevel[] getPreviousLevels()
|
||||
{
|
||||
// Prevent generation if not Sequentially
|
||||
if (!getParent().isCreateLevelsSequentially ())
|
||||
return null;
|
||||
ArrayList<MDunningLevel> list = new ArrayList<MDunningLevel>();
|
||||
String sql = "SELECT * FROM C_DunningLevel WHERE C_Dunning_ID=? AND DaysAfterDue+DaysBetweenDunning<?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
||||
pstmt.setInt(1, getParent().get_ID ());
|
||||
int totalDays = getDaysAfterDue ().intValue ()+getDaysBetweenDunning ();
|
||||
pstmt.setInt(2, totalDays);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
list.add(new MDunningLevel(getCtx(), rs, get_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;
|
||||
}
|
||||
|
||||
//
|
||||
MDunningLevel[] retValue = new MDunningLevel[list.size()];
|
||||
list.toArray(retValue);
|
||||
return retValue;
|
||||
}
|
||||
} // MDunningLevel
|
||||
|
|
|
@ -3,134 +3,206 @@
|
|||
* 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;
|
||||
* 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.Level;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Dunning Run Entry Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MDunningRunEntry.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
|
||||
* Dunning Run Entry Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MDunningRunEntry.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
|
||||
*/
|
||||
public class MDunningRunEntry extends X_C_DunningRunEntry
|
||||
{
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MPayment.class);
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_DunningRunEntry_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningRunEntry (Properties ctx, int C_DunningRunEntry_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_DunningRunEntry_ID, trxName);
|
||||
if (C_DunningRunEntry_ID == 0)
|
||||
{
|
||||
// setC_BPartner_ID (0);
|
||||
// setC_BPartner_Location_ID (0);
|
||||
// setAD_User_ID (0);
|
||||
|
||||
// setSalesRep_ID (0);
|
||||
// setC_Currency_ID (0);
|
||||
setAmt (Env.ZERO);
|
||||
setQty (Env.ZERO);
|
||||
setProcessed (false);
|
||||
}
|
||||
} // MDunningRunEntry
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningRunEntry (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MDunningRunEntry
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param parent parent
|
||||
*/
|
||||
public MDunningRunEntry (MDunningRun parent)
|
||||
{
|
||||
this (parent.getCtx(), 0, parent.get_TrxName());
|
||||
setClientOrg(parent);
|
||||
setC_DunningRun_ID(parent.getC_DunningRun_ID());
|
||||
m_parent = parent;
|
||||
} // MDunningRunEntry
|
||||
|
||||
/** Parent */
|
||||
private MDunningRun m_parent = null;
|
||||
|
||||
/**
|
||||
* Set BPartner
|
||||
* @param bp partner
|
||||
* @param isSOTrx SO
|
||||
*/
|
||||
public void setBPartner (MBPartner bp, boolean isSOTrx)
|
||||
{
|
||||
setC_BPartner_ID(bp.getC_BPartner_ID());
|
||||
MBPartnerLocation[] locations = bp.getLocations(false);
|
||||
// Location
|
||||
if (locations.length == 1)
|
||||
setC_BPartner_Location_ID (locations[0].getC_BPartner_Location_ID());
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < locations.length; i++)
|
||||
{
|
||||
MBPartnerLocation location = locations[i];
|
||||
if ((location.isPayFrom() && isSOTrx)
|
||||
|| (location.isRemitTo() && !isSOTrx))
|
||||
{
|
||||
setC_BPartner_Location_ID (location.getC_BPartner_Location_ID());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getC_BPartner_Location_ID() == 0)
|
||||
{
|
||||
String msg = "@C_BPartner_ID@ " + bp.getName();
|
||||
if (isSOTrx)
|
||||
msg += " @No@ @IsPayFrom@";
|
||||
else
|
||||
msg += " @No@ @IsRemitTo@";
|
||||
throw new IllegalArgumentException (msg);
|
||||
}
|
||||
// User with location
|
||||
MUser[] users = MUser.getOfBPartner(getCtx(), bp.getC_BPartner_ID());
|
||||
if (users.length == 1)
|
||||
setAD_User_ID (users[0].getAD_User_ID());
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < users.length; i++)
|
||||
{
|
||||
MUser user = users[i];
|
||||
if (user.getC_BPartner_Location_ID() == getC_BPartner_Location_ID())
|
||||
{
|
||||
setAD_User_ID (users[i].getAD_User_ID());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
int SalesRep_ID = bp.getSalesRep_ID();
|
||||
if (SalesRep_ID != 0)
|
||||
* @param C_DunningRunEntry_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningRunEntry (Properties ctx, int C_DunningRunEntry_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_DunningRunEntry_ID, trxName);
|
||||
if (C_DunningRunEntry_ID == 0)
|
||||
{
|
||||
// setC_BPartner_ID (0);
|
||||
// setC_BPartner_Location_ID (0);
|
||||
// setAD_User_ID (0);
|
||||
|
||||
// setSalesRep_ID (0);
|
||||
// setC_Currency_ID (0);
|
||||
setAmt (Env.ZERO);
|
||||
setQty (Env.ZERO);
|
||||
setProcessed (false);
|
||||
}
|
||||
} // MDunningRunEntry
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningRunEntry (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MDunningRunEntry
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param parent parent
|
||||
*/
|
||||
public MDunningRunEntry (MDunningRun parent)
|
||||
{
|
||||
this (parent.getCtx(), 0, parent.get_TrxName());
|
||||
setClientOrg(parent);
|
||||
setC_DunningRun_ID(parent.getC_DunningRun_ID());
|
||||
m_parent = parent;
|
||||
} // MDunningRunEntry
|
||||
|
||||
/** Parent */
|
||||
private MDunningRun m_parent = null;
|
||||
|
||||
/**
|
||||
* Set BPartner
|
||||
* @param bp partner
|
||||
* @param isSOTrx SO
|
||||
*/
|
||||
public void setBPartner (MBPartner bp, boolean isSOTrx)
|
||||
{
|
||||
setC_BPartner_ID(bp.getC_BPartner_ID());
|
||||
MBPartnerLocation[] locations = bp.getLocations(false);
|
||||
// Location
|
||||
if (locations.length == 1)
|
||||
setC_BPartner_Location_ID (locations[0].getC_BPartner_Location_ID());
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < locations.length; i++)
|
||||
{
|
||||
MBPartnerLocation location = locations[i];
|
||||
if ((location.isPayFrom() && isSOTrx)
|
||||
|| (location.isRemitTo() && !isSOTrx))
|
||||
{
|
||||
setC_BPartner_Location_ID (location.getC_BPartner_Location_ID());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getC_BPartner_Location_ID() == 0)
|
||||
{
|
||||
String msg = "@C_BPartner_ID@ " + bp.getName();
|
||||
if (isSOTrx)
|
||||
msg += " @No@ @IsPayFrom@";
|
||||
else
|
||||
msg += " @No@ @IsRemitTo@";
|
||||
throw new IllegalArgumentException (msg);
|
||||
}
|
||||
// User with location
|
||||
MUser[] users = MUser.getOfBPartner(getCtx(), bp.getC_BPartner_ID());
|
||||
if (users.length == 1)
|
||||
setAD_User_ID (users[0].getAD_User_ID());
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < users.length; i++)
|
||||
{
|
||||
MUser user = users[i];
|
||||
if (user.getC_BPartner_Location_ID() == getC_BPartner_Location_ID())
|
||||
{
|
||||
setAD_User_ID (users[i].getAD_User_ID());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
int SalesRep_ID = bp.getSalesRep_ID();
|
||||
if (SalesRep_ID != 0)
|
||||
setSalesRep_ID (SalesRep_ID);
|
||||
} // setBPartner
|
||||
|
||||
/**
|
||||
* get Lines
|
||||
* @return Array of all lines for this Run
|
||||
*/
|
||||
public MDunningRunLine[] getLines()
|
||||
{
|
||||
ArrayList<MDunningRunLine> list = new ArrayList<MDunningRunLine>();
|
||||
String sql = "SELECT * FROM C_DunningRunLine WHERE C_DunningRunEntry_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
||||
pstmt.setInt(1, get_ID ());
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
list.add(new MDunningRunLine(getCtx(), rs, get_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;
|
||||
}
|
||||
|
||||
//
|
||||
MDunningRunLine[] retValue = new MDunningRunLine[list.size()];
|
||||
list.toArray(retValue);
|
||||
return retValue;
|
||||
}
|
||||
|
||||
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
// Set Amt
|
||||
if (isProcessed ())
|
||||
{
|
||||
MDunningRunLine[] theseLines = getLines();
|
||||
for (int i=0;i<theseLines.length;i++)
|
||||
{
|
||||
theseLines[i].setProcessed (true);
|
||||
theseLines[i].save (get_TrxName());
|
||||
}
|
||||
if (m_parent.getLevel ().isSetCreditStop () || m_parent.getLevel ().isSetPaymentTerm ())
|
||||
{
|
||||
MBPartner thisBPartner = MBPartner.get (getCtx(), getC_BPartner_ID());
|
||||
if (m_parent.getLevel ().isSetCreditStop ())
|
||||
thisBPartner.setSOCreditStatus (X_C_BPartner.SOCREDITSTATUS_CreditStop);
|
||||
if (m_parent.getLevel ().isSetPaymentTerm ())
|
||||
thisBPartner.setC_PaymentTerm_ID (m_parent.getLevel().getC_PaymentTerm_ID ());
|
||||
thisBPartner.save ();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
|
||||
|
||||
} // MDunningRunEntry
|
||||
|
|
|
@ -3,304 +3,339 @@
|
|||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Dunning Run Line Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MDunningRunLine.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class MDunningRunLine extends X_C_DunningRunLine
|
||||
{
|
||||
/**
|
||||
* Standarc Constructor
|
||||
* @param ctx ctx
|
||||
* @param C_DunningRunLine_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningRunLine (Properties ctx, int C_DunningRunLine_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_DunningRunLine_ID, trxName);
|
||||
if (C_DunningRunLine_ID == 0)
|
||||
{
|
||||
setAmt (Env.ZERO);
|
||||
setOpenAmt(Env.ZERO);
|
||||
setConvertedAmt (Env.ZERO);
|
||||
setFeeAmt (Env.ZERO);
|
||||
setInterestAmt (Env.ZERO);
|
||||
setTotalAmt (Env.ZERO);
|
||||
setDaysDue (0);
|
||||
setTimesDunned (0);
|
||||
setIsInDispute(false);
|
||||
setProcessed (false);
|
||||
}
|
||||
} // MDunningRunLine
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningRunLine (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MDunningRunLine
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param parent parent
|
||||
*/
|
||||
public MDunningRunLine (MDunningRunEntry parent)
|
||||
{
|
||||
this(parent.getCtx(), 0, parent.get_TrxName());
|
||||
setClientOrg(parent);
|
||||
setC_DunningRunEntry_ID(parent.getC_DunningRunEntry_ID());
|
||||
//
|
||||
m_parent = parent;
|
||||
m_C_CurrencyTo_ID = parent.getC_Currency_ID();
|
||||
} // MDunningRunLine
|
||||
|
||||
private MDunningRunEntry m_parent = null;
|
||||
private MInvoice m_invoice = null;
|
||||
private MPayment m_payment = null;
|
||||
private int m_C_CurrencyFrom_ID = 0;
|
||||
private int m_C_CurrencyTo_ID = 0;
|
||||
|
||||
/**
|
||||
* Get Parent
|
||||
* @return parent
|
||||
*/
|
||||
public MDunningRunEntry getParent()
|
||||
{
|
||||
if (m_parent == null)
|
||||
m_parent = new MDunningRunEntry (getCtx(), getC_DunningRunEntry_ID(), get_TrxName());
|
||||
return m_parent;
|
||||
} // getParent
|
||||
|
||||
/**
|
||||
* Get Invoice
|
||||
* @return Returns the invoice.
|
||||
*/
|
||||
public MInvoice getInvoice ()
|
||||
{
|
||||
if (getC_Invoice_ID() == 0)
|
||||
m_invoice = null;
|
||||
else if (m_invoice == null)
|
||||
m_invoice = new MInvoice (getCtx(), getC_Invoice_ID(), get_TrxName());
|
||||
return m_invoice;
|
||||
} // getInvoice
|
||||
|
||||
/**
|
||||
* Set Invoice
|
||||
* @param invoice The invoice to set.
|
||||
*/
|
||||
public void setInvoice (MInvoice invoice)
|
||||
{
|
||||
m_invoice = invoice;
|
||||
if (invoice != null)
|
||||
{
|
||||
m_C_CurrencyFrom_ID = invoice.getC_Currency_ID();
|
||||
setAmt(invoice.getGrandTotal());
|
||||
setOpenAmt(getAmt()); // not correct
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
getC_CurrencyFrom_ID(), getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_C_CurrencyFrom_ID = 0;
|
||||
setAmt(Env.ZERO);
|
||||
setOpenAmt(Env.ZERO);
|
||||
setConvertedAmt(Env.ZERO);
|
||||
}
|
||||
} // setInvoice
|
||||
|
||||
/**
|
||||
* Set Invoice
|
||||
* @param C_Invoice_ID
|
||||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Dunning Run Line Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MDunningRunLine.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class MDunningRunLine extends X_C_DunningRunLine
|
||||
{
|
||||
/**
|
||||
* Standarc Constructor
|
||||
* @param ctx ctx
|
||||
* @param C_DunningRunLine_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningRunLine (Properties ctx, int C_DunningRunLine_ID, String trxName)
|
||||
{
|
||||
super (ctx, C_DunningRunLine_ID, trxName);
|
||||
if (C_DunningRunLine_ID == 0)
|
||||
{
|
||||
setAmt (Env.ZERO);
|
||||
setOpenAmt(Env.ZERO);
|
||||
setConvertedAmt (Env.ZERO);
|
||||
setFeeAmt (Env.ZERO);
|
||||
setInterestAmt (Env.ZERO);
|
||||
setTotalAmt (Env.ZERO);
|
||||
setDaysDue (0);
|
||||
setTimesDunned (0);
|
||||
setIsInDispute(false);
|
||||
setProcessed (false);
|
||||
}
|
||||
} // MDunningRunLine
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MDunningRunLine (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MDunningRunLine
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param parent parent
|
||||
*/
|
||||
public MDunningRunLine (MDunningRunEntry parent)
|
||||
{
|
||||
this(parent.getCtx(), 0, parent.get_TrxName());
|
||||
setClientOrg(parent);
|
||||
setC_DunningRunEntry_ID(parent.getC_DunningRunEntry_ID());
|
||||
//
|
||||
m_parent = parent;
|
||||
m_C_CurrencyTo_ID = parent.getC_Currency_ID();
|
||||
} // MDunningRunLine
|
||||
|
||||
private MDunningRunEntry m_parent = null;
|
||||
private MInvoice m_invoice = null;
|
||||
private MPayment m_payment = null;
|
||||
private int m_C_CurrencyFrom_ID = 0;
|
||||
private int m_C_CurrencyTo_ID = 0;
|
||||
|
||||
/**
|
||||
* Get Parent
|
||||
* @return parent
|
||||
*/
|
||||
public MDunningRunEntry getParent()
|
||||
{
|
||||
if (m_parent == null)
|
||||
m_parent = new MDunningRunEntry (getCtx(), getC_DunningRunEntry_ID(), get_TrxName());
|
||||
return m_parent;
|
||||
} // getParent
|
||||
|
||||
/**
|
||||
* Get Invoice
|
||||
* @return Returns the invoice.
|
||||
*/
|
||||
public MInvoice getInvoice ()
|
||||
{
|
||||
if (getC_Invoice_ID() == 0)
|
||||
m_invoice = null;
|
||||
else if (m_invoice == null)
|
||||
m_invoice = new MInvoice (getCtx(), getC_Invoice_ID(), get_TrxName());
|
||||
return m_invoice;
|
||||
} // getInvoice
|
||||
|
||||
/**
|
||||
* Set Invoice
|
||||
* @param invoice The invoice to set.
|
||||
*/
|
||||
public void setInvoice (MInvoice invoice)
|
||||
{
|
||||
m_invoice = invoice;
|
||||
if (invoice != null)
|
||||
{
|
||||
m_C_CurrencyFrom_ID = invoice.getC_Currency_ID();
|
||||
setAmt(invoice.getGrandTotal());
|
||||
setOpenAmt(getAmt()); // not correct
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
getC_CurrencyFrom_ID(), getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_C_CurrencyFrom_ID = 0;
|
||||
setAmt(Env.ZERO);
|
||||
setOpenAmt(Env.ZERO);
|
||||
setConvertedAmt(Env.ZERO);
|
||||
}
|
||||
} // setInvoice
|
||||
|
||||
/**
|
||||
* Set Invoice
|
||||
* @param C_Invoice_ID
|
||||
* @param C_Currency_ID
|
||||
* @param GrandTotal
|
||||
* @param Open
|
||||
* @param FeeAmount
|
||||
* @param DaysDue
|
||||
* @param IsInDispute
|
||||
* @param TimesDunned
|
||||
* @param DaysAfterLast not used
|
||||
* @param DaysAfterLast not used
|
||||
*/
|
||||
public void setInvoice (int C_Invoice_ID, int C_Currency_ID,
|
||||
BigDecimal GrandTotal, BigDecimal Open,
|
||||
BigDecimal FeeAmount,
|
||||
int DaysDue, boolean IsInDispute,
|
||||
int TimesDunned, int DaysAfterLast)
|
||||
{
|
||||
setC_Invoice_ID(C_Invoice_ID);
|
||||
setC_Invoice_ID(C_Invoice_ID);
|
||||
m_C_CurrencyFrom_ID = C_Currency_ID;
|
||||
setAmt (GrandTotal);
|
||||
setOpenAmt (Open);
|
||||
setFeeAmt (FeeAmount);
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
C_Currency_ID, getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
|
||||
setIsInDispute(IsInDispute);
|
||||
setDaysDue(DaysDue);
|
||||
setTimesDunned(TimesDunned);
|
||||
} // setInvoice
|
||||
setDaysDue(DaysDue);
|
||||
setTimesDunned(TimesDunned);
|
||||
} // setInvoice
|
||||
|
||||
|
||||
/**
|
||||
* Set Fee
|
||||
* @param C_Currency_ID
|
||||
* @param FeeAmount
|
||||
*/
|
||||
public void setFee (int C_Currency_ID,
|
||||
BigDecimal FeeAmount)
|
||||
{
|
||||
m_C_CurrencyFrom_ID = C_Currency_ID;
|
||||
setAmt (FeeAmount);
|
||||
setOpenAmt (FeeAmount);
|
||||
setFeeAmt (FeeAmount);
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
C_Currency_ID, getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
|
||||
} // setInvoice
|
||||
|
||||
/**
|
||||
* Get Payment
|
||||
* @return Returns the payment.
|
||||
*/
|
||||
public MPayment getPayment ()
|
||||
{
|
||||
if (getC_Payment_ID() == 0)
|
||||
m_payment = null;
|
||||
else if (m_payment == null)
|
||||
m_payment = new MPayment (getCtx(), getC_Payment_ID(), get_TrxName());
|
||||
return m_payment;
|
||||
} // getPayment
|
||||
|
||||
/**
|
||||
* Set Payment
|
||||
*
|
||||
public void setPayment (MPayment payment)
|
||||
{
|
||||
m_payment = payment;
|
||||
if (payment != null)
|
||||
{
|
||||
m_C_CurrencyFrom_ID = payment.getC_Currency_ID();
|
||||
setAmt(payment.getPayAmt()); // need to reverse
|
||||
setOpenAmt(getAmt()); // not correct
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
getC_CurrencyFrom_ID(), getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_C_CurrencyFrom_ID = 0;
|
||||
setAmt(Env.ZERO);
|
||||
setConvertedAmt(Env.ZERO);
|
||||
}
|
||||
} // setPayment
|
||||
|
||||
/**
|
||||
* Set Payment
|
||||
* @param C_Payment_ID
|
||||
* @param C_Currency_ID
|
||||
* @param PayAmt
|
||||
* @param OpenAmt
|
||||
*/
|
||||
public void setPayment (int C_Payment_ID, int C_Currency_ID,
|
||||
BigDecimal PayAmt, BigDecimal OpenAmt)
|
||||
{
|
||||
setC_Payment_ID(C_Payment_ID);
|
||||
m_C_CurrencyFrom_ID = C_Currency_ID;
|
||||
setAmt (PayAmt);
|
||||
setOpenAmt (OpenAmt);
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
C_Currency_ID, getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
|
||||
} // setPayment
|
||||
|
||||
|
||||
/**
|
||||
* Get Currency From (Invoice/Payment)
|
||||
* @return Returns the Currency From
|
||||
*/
|
||||
public int getC_CurrencyFrom_ID ()
|
||||
{
|
||||
if (m_C_CurrencyFrom_ID == 0)
|
||||
{
|
||||
if (getC_Invoice_ID() != 0)
|
||||
m_C_CurrencyFrom_ID = getInvoice().getC_Currency_ID();
|
||||
else if (getC_Payment_ID() != 0)
|
||||
m_C_CurrencyFrom_ID = getPayment().getC_Currency_ID();
|
||||
}
|
||||
return m_C_CurrencyFrom_ID;
|
||||
} // getC_CurrencyFrom_ID
|
||||
|
||||
/**
|
||||
* Get Currency To from Parent
|
||||
* @return Returns the Currency To
|
||||
*/
|
||||
public int getC_CurrencyTo_ID ()
|
||||
{
|
||||
if (m_C_CurrencyTo_ID == 0)
|
||||
m_C_CurrencyTo_ID = getParent().getC_Currency_ID();
|
||||
return m_C_CurrencyTo_ID;
|
||||
} // getC_CurrencyTo_ID
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
// Set Amt
|
||||
if (getC_Invoice_ID() == 0 && getC_Payment_ID() == 0)
|
||||
{
|
||||
setAmt(Env.ZERO);
|
||||
setOpenAmt(Env.ZERO);
|
||||
}
|
||||
// Converted Amt
|
||||
if (Env.ZERO.compareTo(getOpenAmt()) == 0)
|
||||
setConvertedAmt (Env.ZERO);
|
||||
else if (Env.ZERO.compareTo(getConvertedAmt()) == 0)
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
public MPayment getPayment ()
|
||||
{
|
||||
if (getC_Payment_ID() == 0)
|
||||
m_payment = null;
|
||||
else if (m_payment == null)
|
||||
m_payment = new MPayment (getCtx(), getC_Payment_ID(), get_TrxName());
|
||||
return m_payment;
|
||||
} // getPayment
|
||||
|
||||
/**
|
||||
* Set Payment
|
||||
*
|
||||
public void setPayment (MPayment payment)
|
||||
{
|
||||
m_payment = payment;
|
||||
if (payment != null)
|
||||
{
|
||||
m_C_CurrencyFrom_ID = payment.getC_Currency_ID();
|
||||
setAmt(payment.getPayAmt()); // need to reverse
|
||||
setOpenAmt(getAmt()); // not correct
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
getC_CurrencyFrom_ID(), getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_C_CurrencyFrom_ID = 0;
|
||||
setAmt(Env.ZERO);
|
||||
setConvertedAmt(Env.ZERO);
|
||||
}
|
||||
} // setPayment
|
||||
|
||||
/**
|
||||
* Set Payment
|
||||
* @param C_Payment_ID
|
||||
* @param C_Currency_ID
|
||||
* @param PayAmt
|
||||
* @param OpenAmt
|
||||
*/
|
||||
public void setPayment (int C_Payment_ID, int C_Currency_ID,
|
||||
BigDecimal PayAmt, BigDecimal OpenAmt)
|
||||
{
|
||||
setC_Payment_ID(C_Payment_ID);
|
||||
m_C_CurrencyFrom_ID = C_Currency_ID;
|
||||
setAmt (PayAmt);
|
||||
setOpenAmt (OpenAmt);
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
C_Currency_ID, getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
|
||||
} // setPayment
|
||||
|
||||
|
||||
/**
|
||||
* Get Currency From (Invoice/Payment)
|
||||
* @return Returns the Currency From
|
||||
*/
|
||||
public int getC_CurrencyFrom_ID ()
|
||||
{
|
||||
if (m_C_CurrencyFrom_ID == 0)
|
||||
{
|
||||
if (getC_Invoice_ID() != 0)
|
||||
m_C_CurrencyFrom_ID = getInvoice().getC_Currency_ID();
|
||||
else if (getC_Payment_ID() != 0)
|
||||
m_C_CurrencyFrom_ID = getPayment().getC_Currency_ID();
|
||||
}
|
||||
return m_C_CurrencyFrom_ID;
|
||||
} // getC_CurrencyFrom_ID
|
||||
|
||||
/**
|
||||
* Get Currency To from Parent
|
||||
* @return Returns the Currency To
|
||||
*/
|
||||
public int getC_CurrencyTo_ID ()
|
||||
{
|
||||
if (m_C_CurrencyTo_ID == 0)
|
||||
m_C_CurrencyTo_ID = getParent().getC_Currency_ID();
|
||||
return m_C_CurrencyTo_ID;
|
||||
} // getC_CurrencyTo_ID
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
// Set Amt
|
||||
if (getC_Invoice_ID() == 0 && getC_Payment_ID() == 0)
|
||||
{
|
||||
setAmt(Env.ZERO);
|
||||
setOpenAmt(Env.ZERO);
|
||||
}
|
||||
// Converted Amt
|
||||
if (Env.ZERO.compareTo(getOpenAmt()) == 0)
|
||||
setConvertedAmt (Env.ZERO);
|
||||
else if (Env.ZERO.compareTo(getConvertedAmt()) == 0)
|
||||
setConvertedAmt (MConversionRate.convert(getCtx(), getOpenAmt(),
|
||||
getC_CurrencyFrom_ID(), getC_CurrencyTo_ID(), getAD_Client_ID(), getAD_Org_ID()));
|
||||
// Total
|
||||
setTotalAmt(getConvertedAmt().add(getFeeAmt()).add(getInterestAmt()));
|
||||
// Reset Collection Status only if null
|
||||
if (getInvoice().getInvoiceCollectionType ()==null)
|
||||
{
|
||||
if (m_invoice!=null)
|
||||
{
|
||||
m_invoice.setInvoiceCollectionType (X_C_Invoice.INVOICECOLLECTIONTYPE_Dunning);
|
||||
m_invoice.save ();
|
||||
}
|
||||
}
|
||||
//
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
updateEntry();
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* After Delete
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterDelete (boolean success)
|
||||
{
|
||||
updateEntry();
|
||||
return success;
|
||||
} // afterDelete
|
||||
|
||||
/**
|
||||
* Update Entry.
|
||||
* Calculate/update Amt/Qty
|
||||
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
updateEntry();
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* After Delete
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterDelete (boolean success)
|
||||
{
|
||||
updateEntry();
|
||||
return success;
|
||||
} // afterDelete
|
||||
|
||||
/**
|
||||
* Update Entry.
|
||||
* Calculate/update Amt/Qty
|
||||
*/
|
||||
private void updateEntry()
|
||||
{
|
||||
// we do not count the fee line as an item, but it sum it up.
|
||||
String sql = "UPDATE C_DunningRunEntry e "
|
||||
+ "SET (Amt,Qty)=(SELECT SUM(Amt),COUNT(*) FROM C_DunningRunLine l "
|
||||
+ "WHERE e.C_DunningRunEntry_ID=l.C_DunningRunEntry_ID) "
|
||||
+ "WHERE C_DunningRunEntry_ID=" + getC_DunningRunEntry_ID();
|
||||
+ "SET Amt=(SELECT SUM(ConvertedAmt)+SUM(FeeAmt)"
|
||||
+ " FROM C_DunningRunLine l "
|
||||
+ "WHERE e.C_DunningRunEntry_ID=l.C_DunningRunEntry_ID), "
|
||||
+ "QTY=(SELECT COUNT(*)"
|
||||
+ " FROM C_DunningRunLine l "
|
||||
+ "WHERE e.C_DunningRunEntry_ID=l.C_DunningRunEntry_ID "
|
||||
+ " AND (NOT C_Invoice_ID IS NULL OR NOT C_Payment_ID IS NULL))"
|
||||
+ " WHERE C_DunningRunEntry_ID=" + getC_DunningRunEntry_ID();
|
||||
|
||||
DB.executeUpdate(sql, get_TrxName());
|
||||
} // updateEntry
|
||||
|
||||
} // MDunningRunLine
|
||||
} // MDunningRunLine
|
||||
|
|
|
@ -3,164 +3,224 @@
|
|||
* 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;
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* Interest Area.
|
||||
* Note: if model is changed, update
|
||||
* org.compiere.wstore.Info.getInterests()
|
||||
* manually
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MInterestArea.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $
|
||||
*/
|
||||
/**
|
||||
* Interest Area.
|
||||
* Note: if model is changed, update
|
||||
* org.compiere.wstore.Info.getInterests()
|
||||
* manually
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MInterestArea.java,v 1.3 2006/07/30 00:51:05 jjanke Exp $
|
||||
*/
|
||||
public class MInterestArea extends X_R_InterestArea
|
||||
{
|
||||
/**
|
||||
* Get all active interest areas
|
||||
* @param ctx context
|
||||
* @return interest areas
|
||||
*/
|
||||
public static MInterestArea[] getAll (Properties ctx)
|
||||
{
|
||||
ArrayList<MInterestArea> list = new ArrayList<MInterestArea>();
|
||||
String sql = "SELECT * FROM R_InterestArea WHERE IsActive='Y'";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
MInterestArea ia = new MInterestArea (ctx, rs, null);
|
||||
list.add (ia);
|
||||
}
|
||||
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;
|
||||
}
|
||||
MInterestArea[] retValue = new MInterestArea[list.size ()];
|
||||
list.toArray (retValue);
|
||||
return retValue;
|
||||
} // getAll
|
||||
|
||||
|
||||
/**
|
||||
* Get MInterestArea from Cache
|
||||
* @param ctx context
|
||||
* @param R_InterestArea_ID id
|
||||
* @return MInterestArea
|
||||
*/
|
||||
public static MInterestArea get (Properties ctx, int R_InterestArea_ID)
|
||||
{
|
||||
Integer key = new Integer (R_InterestArea_ID);
|
||||
MInterestArea retValue = (MInterestArea) s_cache.get (key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
retValue = new MInterestArea (ctx, R_InterestArea_ID, null);
|
||||
if (retValue.get_ID () != 0)
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
* @return MInterestArea
|
||||
*/
|
||||
public static MInterestArea get (Properties ctx, int R_InterestArea_ID)
|
||||
{
|
||||
Integer key = new Integer (R_InterestArea_ID);
|
||||
MInterestArea retValue = (MInterestArea) s_cache.get (key);
|
||||
if (retValue != null)
|
||||
return retValue;
|
||||
retValue = new MInterestArea (ctx, R_InterestArea_ID, null);
|
||||
if (retValue.get_ID () != 0)
|
||||
s_cache.put (key, retValue);
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
/** Cache */
|
||||
private static CCache<Integer,MInterestArea> s_cache = new CCache<Integer,MInterestArea>("R_InterestArea", 5);
|
||||
private static CCache<Integer,MInterestArea> s_cache =
|
||||
new CCache<Integer,MInterestArea>("R_InterestArea", 5);
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MInterestArea.class);
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param ctx context
|
||||
* @param R_InterestArea_ID interest area
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MInterestArea (Properties ctx, int R_InterestArea_ID, String trxName)
|
||||
{
|
||||
super (ctx, R_InterestArea_ID, trxName);
|
||||
if (R_InterestArea_ID == 0)
|
||||
* Constructor
|
||||
* @param ctx context
|
||||
* @param R_InterestArea_ID interest area
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MInterestArea (Properties ctx, int R_InterestArea_ID, String trxName)
|
||||
{
|
||||
super (ctx, R_InterestArea_ID, trxName);
|
||||
if (R_InterestArea_ID == 0)
|
||||
{
|
||||
// setName (null);
|
||||
// setR_InterestArea_ID (0);
|
||||
setIsSelfService (false);
|
||||
}
|
||||
} // MInterestArea
|
||||
|
||||
/**
|
||||
* Loader Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MInterestArea (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
/**
|
||||
* Loader Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MInterestArea (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MInterestArea
|
||||
|
||||
|
||||
/**
|
||||
* Get Value
|
||||
* @return value
|
||||
*/
|
||||
public String getValue()
|
||||
{
|
||||
String s = super.getValue ();
|
||||
if (s != null && s.length () > 0)
|
||||
return s;
|
||||
return super.getName();
|
||||
} // getValue
|
||||
|
||||
/**
|
||||
* String representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MInterestArea[")
|
||||
* @return info
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MInterestArea[")
|
||||
.append (get_ID()).append(" - ").append(getName())
|
||||
.append ("]");
|
||||
return sb.toString ();
|
||||
}
|
||||
} // toString
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
private int m_AD_User_ID = -1;
|
||||
private MContactInterest m_ci = null;
|
||||
|
||||
/**
|
||||
* Set Subscription info "constructor".
|
||||
* Create inactive Subscription
|
||||
* @param AD_User_ID contact
|
||||
*/
|
||||
public void setSubscriptionInfo (int AD_User_ID)
|
||||
{
|
||||
m_AD_User_ID = AD_User_ID;
|
||||
m_ci = MContactInterest.get(getCtx(), getR_InterestArea_ID(), AD_User_ID,
|
||||
false, get_TrxName());
|
||||
} // setSubscription
|
||||
|
||||
/**
|
||||
* Set AD_User_ID
|
||||
* @param AD_User_ID user
|
||||
*/
|
||||
public void setAD_User_ID (int AD_User_ID)
|
||||
{
|
||||
m_AD_User_ID = AD_User_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AD_User_ID
|
||||
* @return user
|
||||
*/
|
||||
public int getAD_User_ID ()
|
||||
{
|
||||
return m_AD_User_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Subscribe Date
|
||||
* @return subscribe date
|
||||
*/
|
||||
public Timestamp getSubscribeDate ()
|
||||
{
|
||||
if (m_ci != null)
|
||||
return m_ci.getSubscribeDate();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Opt Out Date
|
||||
* @return opt-out date
|
||||
*/
|
||||
public Timestamp getOptOutDate ()
|
||||
{
|
||||
if (m_ci != null)
|
||||
return m_ci.getOptOutDate();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Subscribed
|
||||
* @return true if sunscribed
|
||||
*/
|
||||
public boolean isSubscribed()
|
||||
{
|
||||
if (m_AD_User_ID <= 0 || m_ci == null)
|
||||
return false;
|
||||
// We have a BPartner Contact
|
||||
return m_ci.isSubscribed();
|
||||
} // isSubscribed
|
||||
|
||||
} // MInterestArea
|
||||
private int m_AD_User_ID = -1;
|
||||
private MContactInterest m_ci = null;
|
||||
|
||||
/**
|
||||
* Set Subscription info "constructor".
|
||||
* Create inactive Subscription
|
||||
* @param AD_User_ID contact
|
||||
*/
|
||||
public void setSubscriptionInfo (int AD_User_ID)
|
||||
{
|
||||
m_AD_User_ID = AD_User_ID;
|
||||
m_ci = MContactInterest.get(getCtx(), getR_InterestArea_ID(), AD_User_ID,
|
||||
false, get_TrxName());
|
||||
} // setSubscription
|
||||
|
||||
/**
|
||||
* Set AD_User_ID
|
||||
* @param AD_User_ID user
|
||||
*/
|
||||
public void setAD_User_ID (int AD_User_ID)
|
||||
{
|
||||
m_AD_User_ID = AD_User_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AD_User_ID
|
||||
* @return user
|
||||
*/
|
||||
public int getAD_User_ID ()
|
||||
{
|
||||
return m_AD_User_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Subscribe Date
|
||||
* @return subscribe date
|
||||
*/
|
||||
public Timestamp getSubscribeDate ()
|
||||
{
|
||||
if (m_ci != null)
|
||||
return m_ci.getSubscribeDate();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Opt Out Date
|
||||
* @return opt-out date
|
||||
*/
|
||||
public Timestamp getOptOutDate ()
|
||||
{
|
||||
if (m_ci != null)
|
||||
return m_ci.getOptOutDate();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Subscribed
|
||||
* @return true if sunscribed
|
||||
*/
|
||||
public boolean isSubscribed()
|
||||
{
|
||||
if (m_AD_User_ID <= 0 || m_ci == null)
|
||||
return false;
|
||||
// We have a BPartner Contact
|
||||
return m_ci.isSubscribed();
|
||||
} // isSubscribed
|
||||
|
||||
} // MInterestArea
|
||||
|
|
|
@ -3,413 +3,413 @@
|
|||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Physical Inventory Line Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MInventoryLine.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class MInventoryLine extends X_M_InventoryLine
|
||||
{
|
||||
/**
|
||||
* Get Inventory Line with parameters
|
||||
* @param inventory inventory
|
||||
* @param M_Locator_ID locator
|
||||
* @param M_Product_ID product
|
||||
* @param M_AttributeSetInstance_ID asi
|
||||
* @return line or null
|
||||
*/
|
||||
public static MInventoryLine get (MInventory inventory,
|
||||
int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID)
|
||||
{
|
||||
MInventoryLine retValue = null;
|
||||
String sql = "SELECT * FROM M_InventoryLine "
|
||||
+ "WHERE M_Inventory_ID=? AND M_Locator_ID=?"
|
||||
+ " AND M_Product_ID=? AND M_AttributeSetInstance_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, inventory.get_TrxName());
|
||||
pstmt.setInt (1, inventory.getM_Inventory_ID());
|
||||
pstmt.setInt(2, M_Locator_ID);
|
||||
pstmt.setInt(3, M_Product_ID);
|
||||
pstmt.setInt(4, M_AttributeSetInstance_ID);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
retValue = new MInventoryLine (inventory.getCtx(), rs, inventory.get_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;
|
||||
}
|
||||
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MInventoryLine.class);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Default Constructor
|
||||
* @param ctx context
|
||||
* @param M_InventoryLine_ID line
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MInventoryLine (Properties ctx, int M_InventoryLine_ID, String trxName)
|
||||
{
|
||||
super (ctx, M_InventoryLine_ID, trxName);
|
||||
if (M_InventoryLine_ID == 0)
|
||||
{
|
||||
// setM_Inventory_ID (0); // Parent
|
||||
// setM_InventoryLine_ID (0); // PK
|
||||
// setM_Locator_ID (0); // FK
|
||||
setLine(0);
|
||||
// setM_Product_ID (0); // FK
|
||||
setM_AttributeSetInstance_ID(0); // FK
|
||||
setInventoryType (INVENTORYTYPE_InventoryDifference);
|
||||
setQtyBook (Env.ZERO);
|
||||
setQtyCount (Env.ZERO);
|
||||
setProcessed(false);
|
||||
}
|
||||
} // MInventoryLine
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MInventoryLine (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MInventoryLine
|
||||
|
||||
/**
|
||||
* Detail Constructor.
|
||||
* Locator/Product/AttributeSetInstance must be unique
|
||||
* @param inventory parent
|
||||
* @param M_Locator_ID locator
|
||||
* @param M_Product_ID product
|
||||
* @param M_AttributeSetInstance_ID instance
|
||||
* @param QtyBook book value
|
||||
* @param QtyCount count value
|
||||
*/
|
||||
public MInventoryLine (MInventory inventory,
|
||||
int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID,
|
||||
BigDecimal QtyBook, BigDecimal QtyCount)
|
||||
{
|
||||
this (inventory.getCtx(), 0, inventory.get_TrxName());
|
||||
if (inventory.get_ID() == 0)
|
||||
throw new IllegalArgumentException("Header not saved");
|
||||
m_parent = inventory;
|
||||
setM_Inventory_ID (inventory.getM_Inventory_ID()); // Parent
|
||||
setClientOrg (inventory.getAD_Client_ID(), inventory.getAD_Org_ID());
|
||||
setM_Locator_ID (M_Locator_ID); // FK
|
||||
setM_Product_ID (M_Product_ID); // FK
|
||||
setM_AttributeSetInstance_ID (M_AttributeSetInstance_ID);
|
||||
//
|
||||
if (QtyBook != null)
|
||||
setQtyBook (QtyBook);
|
||||
if (QtyCount != null && QtyCount.signum() != 0)
|
||||
setQtyCount (QtyCount);
|
||||
m_isManualEntry = false;
|
||||
} // MInventoryLine
|
||||
|
||||
/** Manually created */
|
||||
private boolean m_isManualEntry = true;
|
||||
/** Parent */
|
||||
private MInventory m_parent = null;
|
||||
/** Product */
|
||||
private MProduct m_product = null;
|
||||
|
||||
/**
|
||||
* Get Qty Book
|
||||
* @return Qty Book
|
||||
*/
|
||||
public BigDecimal getQtyBook ()
|
||||
{
|
||||
BigDecimal bd = super.getQtyBook ();
|
||||
if (bd == null)
|
||||
bd = Env.ZERO;
|
||||
return bd;
|
||||
} // getQtyBook
|
||||
|
||||
/**
|
||||
* Get Qty Count
|
||||
* @return Qty Count
|
||||
*/
|
||||
public BigDecimal getQtyCount ()
|
||||
{
|
||||
BigDecimal bd = super.getQtyCount();
|
||||
if (bd == null)
|
||||
bd = Env.ZERO;
|
||||
return bd;
|
||||
} // getQtyBook
|
||||
|
||||
/**
|
||||
* Get Product
|
||||
* @return product or null if not defined
|
||||
*/
|
||||
public MProduct getProduct()
|
||||
{
|
||||
int M_Product_ID = getM_Product_ID();
|
||||
if (M_Product_ID == 0)
|
||||
return null;
|
||||
if (m_product != null && m_product.getM_Product_ID() != M_Product_ID)
|
||||
m_product = null; // reset
|
||||
if (m_product == null)
|
||||
m_product = MProduct.get(getCtx(), M_Product_ID);
|
||||
return m_product;
|
||||
} // getProduct
|
||||
|
||||
/**
|
||||
* Set Count Qty - enforce UOM
|
||||
* @param QtyCount qty
|
||||
*/
|
||||
public void setQtyCount (BigDecimal QtyCount)
|
||||
{
|
||||
if (QtyCount != null)
|
||||
{
|
||||
MProduct product = getProduct();
|
||||
if (product != null)
|
||||
{
|
||||
int precision = product.getUOMPrecision();
|
||||
QtyCount = QtyCount.setScale(precision, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
}
|
||||
super.setQtyCount(QtyCount);
|
||||
} // setQtyCount
|
||||
|
||||
/**
|
||||
* Set Internal Use Qty - enforce UOM
|
||||
* @param QtyInternalUse qty
|
||||
*/
|
||||
public void setQtyInternalUse (BigDecimal QtyInternalUse)
|
||||
{
|
||||
if (QtyInternalUse != null)
|
||||
{
|
||||
MProduct product = getProduct();
|
||||
if (product != null)
|
||||
{
|
||||
int precision = product.getUOMPrecision();
|
||||
QtyInternalUse = QtyInternalUse.setScale(precision, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
}
|
||||
super.setQtyInternalUse(QtyInternalUse);
|
||||
} // setQtyInternalUse
|
||||
|
||||
|
||||
/**
|
||||
* Add to Description
|
||||
* @param description text
|
||||
*/
|
||||
public void addDescription (String description)
|
||||
{
|
||||
String desc = getDescription();
|
||||
if (desc == null)
|
||||
setDescription(description);
|
||||
else
|
||||
setDescription(desc + " | " + description);
|
||||
} // addDescription
|
||||
|
||||
/**
|
||||
* Get Parent
|
||||
* @param parent parent
|
||||
*/
|
||||
protected void setParent(MInventory parent)
|
||||
{
|
||||
m_parent = parent;
|
||||
} // setParent
|
||||
|
||||
/**
|
||||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Physical Inventory Line Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MInventoryLine.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class MInventoryLine extends X_M_InventoryLine
|
||||
{
|
||||
/**
|
||||
* Get Inventory Line with parameters
|
||||
* @param inventory inventory
|
||||
* @param M_Locator_ID locator
|
||||
* @param M_Product_ID product
|
||||
* @param M_AttributeSetInstance_ID asi
|
||||
* @return line or null
|
||||
*/
|
||||
public static MInventoryLine get (MInventory inventory,
|
||||
int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID)
|
||||
{
|
||||
MInventoryLine retValue = null;
|
||||
String sql = "SELECT * FROM M_InventoryLine "
|
||||
+ "WHERE M_Inventory_ID=? AND M_Locator_ID=?"
|
||||
+ " AND M_Product_ID=? AND M_AttributeSetInstance_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, inventory.get_TrxName());
|
||||
pstmt.setInt (1, inventory.getM_Inventory_ID());
|
||||
pstmt.setInt(2, M_Locator_ID);
|
||||
pstmt.setInt(3, M_Product_ID);
|
||||
pstmt.setInt(4, M_AttributeSetInstance_ID);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
retValue = new MInventoryLine (inventory.getCtx(), rs, inventory.get_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;
|
||||
}
|
||||
|
||||
return retValue;
|
||||
} // get
|
||||
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MInventoryLine.class);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Default Constructor
|
||||
* @param ctx context
|
||||
* @param M_InventoryLine_ID line
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MInventoryLine (Properties ctx, int M_InventoryLine_ID, String trxName)
|
||||
{
|
||||
super (ctx, M_InventoryLine_ID, trxName);
|
||||
if (M_InventoryLine_ID == 0)
|
||||
{
|
||||
// setM_Inventory_ID (0); // Parent
|
||||
// setM_InventoryLine_ID (0); // PK
|
||||
// setM_Locator_ID (0); // FK
|
||||
setLine(0);
|
||||
// setM_Product_ID (0); // FK
|
||||
setM_AttributeSetInstance_ID(0); // FK
|
||||
setInventoryType (INVENTORYTYPE_InventoryDifference);
|
||||
setQtyBook (Env.ZERO);
|
||||
setQtyCount (Env.ZERO);
|
||||
setProcessed(false);
|
||||
}
|
||||
} // MInventoryLine
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MInventoryLine (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MInventoryLine
|
||||
|
||||
/**
|
||||
* Detail Constructor.
|
||||
* Locator/Product/AttributeSetInstance must be unique
|
||||
* @param inventory parent
|
||||
* @param M_Locator_ID locator
|
||||
* @param M_Product_ID product
|
||||
* @param M_AttributeSetInstance_ID instance
|
||||
* @param QtyBook book value
|
||||
* @param QtyCount count value
|
||||
*/
|
||||
public MInventoryLine (MInventory inventory,
|
||||
int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID,
|
||||
BigDecimal QtyBook, BigDecimal QtyCount)
|
||||
{
|
||||
this (inventory.getCtx(), 0, inventory.get_TrxName());
|
||||
if (inventory.get_ID() == 0)
|
||||
throw new IllegalArgumentException("Header not saved");
|
||||
m_parent = inventory;
|
||||
setM_Inventory_ID (inventory.getM_Inventory_ID()); // Parent
|
||||
setClientOrg (inventory.getAD_Client_ID(), inventory.getAD_Org_ID());
|
||||
setM_Locator_ID (M_Locator_ID); // FK
|
||||
setM_Product_ID (M_Product_ID); // FK
|
||||
setM_AttributeSetInstance_ID (M_AttributeSetInstance_ID);
|
||||
//
|
||||
if (QtyBook != null)
|
||||
setQtyBook (QtyBook);
|
||||
if (QtyCount != null && QtyCount.signum() != 0)
|
||||
setQtyCount (QtyCount);
|
||||
m_isManualEntry = false;
|
||||
} // MInventoryLine
|
||||
|
||||
/** Manually created */
|
||||
private boolean m_isManualEntry = true;
|
||||
/** Parent */
|
||||
private MInventory m_parent = null;
|
||||
/** Product */
|
||||
private MProduct m_product = null;
|
||||
|
||||
/**
|
||||
* Get Qty Book
|
||||
* @return Qty Book
|
||||
*/
|
||||
public BigDecimal getQtyBook ()
|
||||
{
|
||||
BigDecimal bd = super.getQtyBook ();
|
||||
if (bd == null)
|
||||
bd = Env.ZERO;
|
||||
return bd;
|
||||
} // getQtyBook
|
||||
|
||||
/**
|
||||
* Get Qty Count
|
||||
* @return Qty Count
|
||||
*/
|
||||
public BigDecimal getQtyCount ()
|
||||
{
|
||||
BigDecimal bd = super.getQtyCount();
|
||||
if (bd == null)
|
||||
bd = Env.ZERO;
|
||||
return bd;
|
||||
} // getQtyBook
|
||||
|
||||
/**
|
||||
* Get Product
|
||||
* @return product or null if not defined
|
||||
*/
|
||||
public MProduct getProduct()
|
||||
{
|
||||
int M_Product_ID = getM_Product_ID();
|
||||
if (M_Product_ID == 0)
|
||||
return null;
|
||||
if (m_product != null && m_product.getM_Product_ID() != M_Product_ID)
|
||||
m_product = null; // reset
|
||||
if (m_product == null)
|
||||
m_product = MProduct.get(getCtx(), M_Product_ID);
|
||||
return m_product;
|
||||
} // getProduct
|
||||
|
||||
/**
|
||||
* Set Count Qty - enforce UOM
|
||||
* @param QtyCount qty
|
||||
*/
|
||||
public void setQtyCount (BigDecimal QtyCount)
|
||||
{
|
||||
if (QtyCount != null)
|
||||
{
|
||||
MProduct product = getProduct();
|
||||
if (product != null)
|
||||
{
|
||||
int precision = product.getUOMPrecision();
|
||||
QtyCount = QtyCount.setScale(precision, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
}
|
||||
super.setQtyCount(QtyCount);
|
||||
} // setQtyCount
|
||||
|
||||
/**
|
||||
* Set Internal Use Qty - enforce UOM
|
||||
* @param QtyInternalUse qty
|
||||
*/
|
||||
public void setQtyInternalUse (BigDecimal QtyInternalUse)
|
||||
{
|
||||
if (QtyInternalUse != null)
|
||||
{
|
||||
MProduct product = getProduct();
|
||||
if (product != null)
|
||||
{
|
||||
int precision = product.getUOMPrecision();
|
||||
QtyInternalUse = QtyInternalUse.setScale(precision, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
}
|
||||
super.setQtyInternalUse(QtyInternalUse);
|
||||
} // setQtyInternalUse
|
||||
|
||||
|
||||
/**
|
||||
* Add to Description
|
||||
* @param description text
|
||||
*/
|
||||
public void addDescription (String description)
|
||||
{
|
||||
String desc = getDescription();
|
||||
if (desc == null)
|
||||
setDescription(description);
|
||||
else
|
||||
setDescription(desc + " | " + description);
|
||||
} // addDescription
|
||||
|
||||
/**
|
||||
* Get Parent
|
||||
* @param parent parent
|
||||
*/
|
||||
protected void setParent(MInventory parent)
|
||||
{
|
||||
m_parent = parent;
|
||||
} // setParent
|
||||
|
||||
/**
|
||||
* Get Parent
|
||||
* @return parent
|
||||
*/
|
||||
private MInventory getParent()
|
||||
public MInventory getParent()
|
||||
{
|
||||
if (m_parent == null)
|
||||
m_parent = new MInventory (getCtx(), getM_Inventory_ID(), get_TrxName());
|
||||
return m_parent;
|
||||
} // getParent
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MInventoryLine[");
|
||||
sb.append (get_ID())
|
||||
.append("-M_Product_ID=").append (getM_Product_ID())
|
||||
.append(",QtyCount=").append(getQtyCount())
|
||||
.append(",QtyInternalUse=").append(getQtyInternalUse())
|
||||
.append(",QtyBook=").append(getQtyBook())
|
||||
.append(",M_AttributeSetInstance_ID=").append(getM_AttributeSetInstance_ID())
|
||||
.append("]");
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true if can be saved
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (newRecord && m_isManualEntry)
|
||||
{
|
||||
// Product requires ASI
|
||||
if (getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
|
||||
if (product.getM_AttributeSet_ID() != 0)
|
||||
{
|
||||
MAttributeSet mas = MAttributeSet.get(getCtx(), product.getM_AttributeSet_ID());
|
||||
if (mas.isInstanceAttribute()
|
||||
&& (mas.isMandatory() || mas.isMandatoryAlways()))
|
||||
{
|
||||
log.saveError("FillMandatory", Msg.getElement(getCtx(), "M_AttributeSetInstance_ID"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // No ASI
|
||||
} // new or manual
|
||||
|
||||
// Set Line No
|
||||
if (getLine() == 0)
|
||||
{
|
||||
String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_InventoryLine WHERE M_Inventory_ID=?";
|
||||
int ii = DB.getSQLValue (get_TrxName(), sql, getM_Inventory_ID());
|
||||
setLine (ii);
|
||||
}
|
||||
|
||||
// Enforce Qty UOM
|
||||
if (newRecord || is_ValueChanged("QtyCount"))
|
||||
setQtyCount(getQtyCount());
|
||||
if (newRecord || is_ValueChanged("QtyInternalUse"))
|
||||
setQtyInternalUse(getQtyInternalUse());
|
||||
|
||||
// InternalUse Inventory
|
||||
if (getQtyInternalUse().signum() != 0)
|
||||
{
|
||||
if (!INVENTORYTYPE_ChargeAccount.equals(getInventoryType()))
|
||||
setInventoryType(INVENTORYTYPE_ChargeAccount);
|
||||
//
|
||||
if (getC_Charge_ID() == 0)
|
||||
{
|
||||
log.saveError("InternalUseNeedsCharge", "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (INVENTORYTYPE_ChargeAccount.equals(getInventoryType()))
|
||||
{
|
||||
if (getC_Charge_ID() == 0)
|
||||
{
|
||||
log.saveError("FillMandatory", Msg.getElement(getCtx(), "C_Charge_ID"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (getC_Charge_ID() != 0)
|
||||
setC_Charge_ID(0);
|
||||
|
||||
// Set AD_Org to parent if not charge
|
||||
if (getC_Charge_ID() == 0)
|
||||
setAD_Org_ID(getParent().getAD_Org_ID());
|
||||
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return true
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
// Create MA
|
||||
if (newRecord && success
|
||||
&& m_isManualEntry && getM_AttributeSetInstance_ID() == 0)
|
||||
createMA();
|
||||
return true;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* Create Material Allocations for new Instances
|
||||
*/
|
||||
private void createMA()
|
||||
{
|
||||
MStorage[] storages = MStorage.getAll(getCtx(), getM_Product_ID(),
|
||||
getM_Locator_ID(), get_TrxName());
|
||||
boolean allZeroASI = true;
|
||||
for (int i = 0; i < storages.length; i++)
|
||||
{
|
||||
if (storages[i].getM_AttributeSetInstance_ID() != 0)
|
||||
{
|
||||
allZeroASI = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allZeroASI)
|
||||
return;
|
||||
|
||||
MInventoryLineMA ma = null;
|
||||
BigDecimal sum = Env.ZERO;
|
||||
for (int i = 0; i < storages.length; i++)
|
||||
{
|
||||
MStorage storage = storages[i];
|
||||
if (storage.getQtyOnHand().signum() == 0)
|
||||
continue;
|
||||
if (ma != null
|
||||
&& ma.getM_AttributeSetInstance_ID() == storage.getM_AttributeSetInstance_ID())
|
||||
ma.setMovementQty(ma.getMovementQty().add(storage.getQtyOnHand()));
|
||||
else
|
||||
ma = new MInventoryLineMA (this,
|
||||
storage.getM_AttributeSetInstance_ID(), storage.getQtyOnHand());
|
||||
if (!ma.save())
|
||||
;
|
||||
sum = sum.add(storage.getQtyOnHand());
|
||||
}
|
||||
if (sum.compareTo(getQtyBook()) != 0)
|
||||
{
|
||||
log.warning("QtyBook=" + getQtyBook() + " corrected to Sum of MA=" + sum);
|
||||
setQtyBook(sum);
|
||||
}
|
||||
} // createMA
|
||||
|
||||
} // MInventoryLine
|
||||
return m_parent;
|
||||
} // getParent
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MInventoryLine[");
|
||||
sb.append (get_ID())
|
||||
.append("-M_Product_ID=").append (getM_Product_ID())
|
||||
.append(",QtyCount=").append(getQtyCount())
|
||||
.append(",QtyInternalUse=").append(getQtyInternalUse())
|
||||
.append(",QtyBook=").append(getQtyBook())
|
||||
.append(",M_AttributeSetInstance_ID=").append(getM_AttributeSetInstance_ID())
|
||||
.append("]");
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true if can be saved
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
if (newRecord && m_isManualEntry)
|
||||
{
|
||||
// Product requires ASI
|
||||
if (getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
|
||||
if (product.getM_AttributeSet_ID() != 0)
|
||||
{
|
||||
MAttributeSet mas = MAttributeSet.get(getCtx(), product.getM_AttributeSet_ID());
|
||||
if (mas.isInstanceAttribute()
|
||||
&& (mas.isMandatory() || mas.isMandatoryAlways()))
|
||||
{
|
||||
log.saveError("FillMandatory", Msg.getElement(getCtx(), "M_AttributeSetInstance_ID"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // No ASI
|
||||
} // new or manual
|
||||
|
||||
// Set Line No
|
||||
if (getLine() == 0)
|
||||
{
|
||||
String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_InventoryLine WHERE M_Inventory_ID=?";
|
||||
int ii = DB.getSQLValue (get_TrxName(), sql, getM_Inventory_ID());
|
||||
setLine (ii);
|
||||
}
|
||||
|
||||
// Enforce Qty UOM
|
||||
if (newRecord || is_ValueChanged("QtyCount"))
|
||||
setQtyCount(getQtyCount());
|
||||
if (newRecord || is_ValueChanged("QtyInternalUse"))
|
||||
setQtyInternalUse(getQtyInternalUse());
|
||||
|
||||
// InternalUse Inventory
|
||||
if (getQtyInternalUse().signum() != 0)
|
||||
{
|
||||
if (!INVENTORYTYPE_ChargeAccount.equals(getInventoryType()))
|
||||
setInventoryType(INVENTORYTYPE_ChargeAccount);
|
||||
//
|
||||
if (getC_Charge_ID() == 0)
|
||||
{
|
||||
log.saveError("InternalUseNeedsCharge", "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (INVENTORYTYPE_ChargeAccount.equals(getInventoryType()))
|
||||
{
|
||||
if (getC_Charge_ID() == 0)
|
||||
{
|
||||
log.saveError("FillMandatory", Msg.getElement(getCtx(), "C_Charge_ID"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (getC_Charge_ID() != 0)
|
||||
setC_Charge_ID(0);
|
||||
|
||||
// Set AD_Org to parent if not charge
|
||||
if (getC_Charge_ID() == 0)
|
||||
setAD_Org_ID(getParent().getAD_Org_ID());
|
||||
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return true
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
// Create MA
|
||||
if (newRecord && success
|
||||
&& m_isManualEntry && getM_AttributeSetInstance_ID() == 0)
|
||||
createMA();
|
||||
return true;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* Create Material Allocations for new Instances
|
||||
*/
|
||||
private void createMA()
|
||||
{
|
||||
MStorage[] storages = MStorage.getAll(getCtx(), getM_Product_ID(),
|
||||
getM_Locator_ID(), get_TrxName());
|
||||
boolean allZeroASI = true;
|
||||
for (int i = 0; i < storages.length; i++)
|
||||
{
|
||||
if (storages[i].getM_AttributeSetInstance_ID() != 0)
|
||||
{
|
||||
allZeroASI = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allZeroASI)
|
||||
return;
|
||||
|
||||
MInventoryLineMA ma = null;
|
||||
BigDecimal sum = Env.ZERO;
|
||||
for (int i = 0; i < storages.length; i++)
|
||||
{
|
||||
MStorage storage = storages[i];
|
||||
if (storage.getQtyOnHand().signum() == 0)
|
||||
continue;
|
||||
if (ma != null
|
||||
&& ma.getM_AttributeSetInstance_ID() == storage.getM_AttributeSetInstance_ID())
|
||||
ma.setMovementQty(ma.getMovementQty().add(storage.getQtyOnHand()));
|
||||
else
|
||||
ma = new MInventoryLineMA (this,
|
||||
storage.getM_AttributeSetInstance_ID(), storage.getQtyOnHand());
|
||||
if (!ma.save())
|
||||
;
|
||||
sum = sum.add(storage.getQtyOnHand());
|
||||
}
|
||||
if (sum.compareTo(getQtyBook()) != 0)
|
||||
{
|
||||
log.warning("QtyBook=" + getQtyBook() + " corrected to Sum of MA=" + sum);
|
||||
setQtyBook(sum);
|
||||
}
|
||||
} // createMA
|
||||
|
||||
} // MInventoryLine
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/******************************************************************************
|
||||
* 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.
|
||||
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
|
||||
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
|
||||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Ldap Access Log
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MLdapAccess extends X_AD_LdapAccess
|
||||
{
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_LdapAccess_ID id
|
||||
* @param trxName trx
|
||||
*/
|
||||
public MLdapAccess(Properties ctx, int AD_LdapAccess_ID, String trxName)
|
||||
{
|
||||
super (ctx, AD_LdapAccess_ID, trxName);
|
||||
} // MLdapAccess
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MLdapAccess(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MLdapAccess
|
||||
|
||||
|
||||
|
||||
|
||||
} // MLdapAccess
|
|
@ -0,0 +1,545 @@
|
|||
/******************************************************************************
|
||||
* 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.
|
||||
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
|
||||
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
|
||||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* LDAP Server Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MLdapProcessor extends X_AD_LdapProcessor implements AdempiereProcessor
|
||||
{
|
||||
/**
|
||||
* Get Active LDAP Server
|
||||
* @return array of Servers
|
||||
*/
|
||||
public static MLdapProcessor[] getActive(Properties ctx)
|
||||
{
|
||||
ArrayList<MLdapProcessor> list = new ArrayList<MLdapProcessor>();
|
||||
String sql = "SELECT * FROM AD_LdapProcessor WHERE IsActive='Y'";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add (new MLdapProcessor (ctx, 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;
|
||||
}
|
||||
|
||||
MLdapProcessor[] retValue = new MLdapProcessor[list.size()];
|
||||
list.toArray(retValue);
|
||||
return retValue;
|
||||
} // getActive
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger (MLdapProcessor.class);
|
||||
|
||||
/**************************************************************************
|
||||
* Ldap Processor
|
||||
* @param ctx context
|
||||
* @param AD_LdapProcessor_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MLdapProcessor(Properties ctx, int AD_LdapProcessor_ID, String trxName)
|
||||
{
|
||||
super (ctx, AD_LdapProcessor_ID, trxName);
|
||||
} // MLdapProcessor
|
||||
|
||||
/**
|
||||
* Ldap Processor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MLdapProcessor(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MLdapProcessor
|
||||
|
||||
/** Array of Clients */
|
||||
private MClient[] m_clients = null;
|
||||
/** Array of Interest Areas */
|
||||
private MInterestArea[] m_interests = null;
|
||||
|
||||
private int m_auth = 0;
|
||||
private int m_ok = 0;
|
||||
private int m_error = 0;
|
||||
|
||||
/**
|
||||
* Get Server ID
|
||||
* @return id
|
||||
*/
|
||||
public String getServerID ()
|
||||
{
|
||||
return "Ldap" + get_ID();
|
||||
} // getServerID
|
||||
|
||||
/**
|
||||
* Get Info
|
||||
* @return info
|
||||
*/
|
||||
public String getInfo()
|
||||
{
|
||||
return "Auth=" + m_auth
|
||||
+ ", OK=" + m_ok + ", Error=" + m_error;
|
||||
} // getInfo
|
||||
|
||||
/**
|
||||
* Get Date Next Run
|
||||
* @param requery requery
|
||||
* @return date next run
|
||||
*/
|
||||
public Timestamp getDateNextRun (boolean requery)
|
||||
{
|
||||
if (requery)
|
||||
load(get_TrxName());
|
||||
return getDateNextRun();
|
||||
} // getDateNextRun
|
||||
|
||||
/**
|
||||
* Get Logs
|
||||
* @return logs
|
||||
*/
|
||||
public AdempiereProcessorLog[] getLogs ()
|
||||
{
|
||||
ArrayList<MLdapProcessorLog> list = new ArrayList<MLdapProcessorLog>();
|
||||
String sql = "SELECT * "
|
||||
+ "FROM AD_LdapProcessorLog "
|
||||
+ "WHERE AD_LdapProcessor_ID=? "
|
||||
+ "ORDER BY Created DESC";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
pstmt.setInt (1, getAD_LdapProcessor_ID());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add (new MLdapProcessorLog (getCtx(), rs, get_TrxName()));
|
||||
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;
|
||||
}
|
||||
MLdapProcessorLog[] retValue = new MLdapProcessorLog[list.size ()];
|
||||
list.toArray (retValue);
|
||||
return retValue;
|
||||
} // getLogs
|
||||
|
||||
/**
|
||||
* Delete old Request Log
|
||||
* @return number of records
|
||||
*/
|
||||
public int deleteLog()
|
||||
{
|
||||
if (getKeepLogDays() < 1)
|
||||
return 0;
|
||||
String sql = "DELETE AD_LdapProcessorLog "
|
||||
+ "WHERE AD_LdapProcessor_ID=" + getAD_LdapProcessor_ID()
|
||||
+ " AND (Created+" + getKeepLogDays() + ") < SysDate";
|
||||
int no = DB.executeUpdate(sql, get_TrxName());
|
||||
return no;
|
||||
} // deleteLog
|
||||
|
||||
/**
|
||||
* Get Frequency (n/a)
|
||||
* @return 1
|
||||
*/
|
||||
public int getFrequency()
|
||||
{
|
||||
return 1;
|
||||
} // getFrequency
|
||||
|
||||
/**
|
||||
* Get Frequency Type (n/a)
|
||||
* @return minute
|
||||
*/
|
||||
public String getFrequencyType()
|
||||
{
|
||||
return X_R_RequestProcessor.FREQUENCYTYPE_Minute;
|
||||
} // getFrequencyType
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("MLdapProcessor[");
|
||||
sb.append (get_ID()).append ("-").append (getName())
|
||||
.append (",Port=").append (getLdapPort())
|
||||
.append ("]");
|
||||
return sb.toString ();
|
||||
} // toString
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Authenticate and Authorize
|
||||
* @param ldapUser MLdapUser object
|
||||
* @param usr user name
|
||||
* @param o organization = Client Name
|
||||
* @param ou optional organization unit = Interest Group
|
||||
* @return ldapUser MLdapUser with updated information
|
||||
*/
|
||||
public MLdapUser authenticate(MLdapUser ldapUser, String usr, String o, String ou)
|
||||
{
|
||||
// Ensure something to return
|
||||
if (ldapUser == null)
|
||||
ldapUser = new MLdapUser();
|
||||
|
||||
String error = null;
|
||||
String info = null;
|
||||
|
||||
// User
|
||||
if (usr == null || usr.trim().length () == 0)
|
||||
{
|
||||
error = "@NotFound@ User";
|
||||
ldapUser.setErrorString(error);
|
||||
m_error++;
|
||||
log.warning (error);
|
||||
return ldapUser;
|
||||
}
|
||||
usr = usr.trim();
|
||||
// Client
|
||||
if (o == null || o.length () == 0)
|
||||
{
|
||||
error = "@NotFound@ O";
|
||||
ldapUser.setErrorString(error);
|
||||
m_error++;
|
||||
log.warning (error);
|
||||
return ldapUser;
|
||||
}
|
||||
int AD_Client_ID = findClient(o);
|
||||
if (AD_Client_ID == 0)
|
||||
{
|
||||
error = "@NotFound@ O=" + o;
|
||||
ldapUser.setErrorString(error);
|
||||
m_error++;
|
||||
log.config (error);
|
||||
return ldapUser;
|
||||
}
|
||||
// Optional Interest Area
|
||||
int R_InterestArea_ID = 0;
|
||||
if (ou != null && ou.length () > 0)
|
||||
{
|
||||
R_InterestArea_ID = findInterestArea (AD_Client_ID, ou);
|
||||
if (R_InterestArea_ID == 0)
|
||||
{
|
||||
error = "@NotFound@ OU=" + ou;
|
||||
ldapUser.setErrorString(error);
|
||||
m_error++;
|
||||
log.config (error);
|
||||
return ldapUser;
|
||||
}
|
||||
}
|
||||
|
||||
m_auth++;
|
||||
// Query 1 - Validate User
|
||||
int AD_User_ID = 0;
|
||||
String Value = null;
|
||||
String LdapUser = null;
|
||||
String EMail = null;
|
||||
String Name = null;
|
||||
String Password = null;
|
||||
boolean IsActive = false;
|
||||
String EMailVerify = null; // is timestamp
|
||||
boolean isUnique = false;
|
||||
//
|
||||
String sql = "SELECT AD_User_ID, Value, LdapUser, EMail," // 1..4
|
||||
+ " Name, Password, IsActive, EMailVerify "
|
||||
+ "FROM AD_User "
|
||||
+ "WHERE AD_Client_ID=? AND (EMail=? OR Value=? OR LdapUser=?)";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, AD_Client_ID);
|
||||
pstmt.setString (2, usr);
|
||||
pstmt.setString (3, usr);
|
||||
pstmt.setString (4, usr);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
if (rs.next())
|
||||
{
|
||||
AD_User_ID = rs.getInt (1);
|
||||
Value = rs.getString (2);
|
||||
LdapUser = rs.getString (3);
|
||||
EMail = rs.getString (4);
|
||||
//
|
||||
Name = rs.getString (5);
|
||||
Password = rs.getString (6);
|
||||
IsActive = "Y".equals (rs.getString (7));
|
||||
EMailVerify = rs.getString (8);
|
||||
isUnique = rs.next();
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log (Level.SEVERE, sql, e);
|
||||
error = "System Error";
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
if (error != null)
|
||||
{
|
||||
m_error++;
|
||||
ldapUser.setErrorString(error);
|
||||
return ldapUser;
|
||||
}
|
||||
//
|
||||
if (AD_User_ID == 0)
|
||||
{
|
||||
error = "@NotFound@ User=" + usr;
|
||||
info = "User not found - " + usr;
|
||||
}
|
||||
else if (!IsActive)
|
||||
{
|
||||
error = "@NotFound@ User=" + usr;
|
||||
info = "User not active - " + usr;
|
||||
}
|
||||
else if (EMailVerify == null)
|
||||
{
|
||||
error = "@UserNotVerified@ User=" + usr;
|
||||
info = "User EMail not verified - " + usr;
|
||||
}
|
||||
else if (usr.equalsIgnoreCase(LdapUser))
|
||||
info = "User verified - Ldap=" + usr
|
||||
+ (isUnique ? "" : " - Not Unique");
|
||||
else if (usr.equalsIgnoreCase(Value))
|
||||
info = "User verified - Value=" + usr
|
||||
+ (isUnique ? "" : " - Not Unique");
|
||||
else if (usr.equalsIgnoreCase(EMail))
|
||||
info = "User verified - EMail=" + usr
|
||||
+ (isUnique ? "" : " - Not Unique");
|
||||
else
|
||||
info = "User verified ?? " + usr
|
||||
+ " - Name=" + Name
|
||||
+ ", Ldap=" + LdapUser + ", Value=" + Value
|
||||
+ (isUnique ? "" : " - Not Unique");
|
||||
|
||||
// Error
|
||||
if (error != null) // should use Language of the User
|
||||
{
|
||||
logAccess (AD_Client_ID, AD_User_ID, R_InterestArea_ID, info, error);
|
||||
ldapUser.setErrorString(Msg.translate (getCtx(), error));
|
||||
return ldapUser;
|
||||
}
|
||||
// Done
|
||||
if (R_InterestArea_ID == 0)
|
||||
{
|
||||
logAccess (AD_Client_ID, AD_User_ID, R_InterestArea_ID, info, null);
|
||||
ldapUser.setOrg(o);
|
||||
ldapUser.setOrgUnit(ou);
|
||||
ldapUser.setUserId(usr);
|
||||
ldapUser.setPassword(Password);
|
||||
return ldapUser;
|
||||
}
|
||||
|
||||
// Query 2 - Validate Subscription
|
||||
String OptOutDate = null;
|
||||
boolean found = false;
|
||||
sql = "SELECT IsActive, OptOutDate "
|
||||
+ "FROM R_ContactInterest "
|
||||
+ "WHERE R_InterestArea_ID=? AND AD_User_ID=?";
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setInt (1, R_InterestArea_ID);
|
||||
pstmt.setInt (2, AD_User_ID);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
if (rs.next())
|
||||
{
|
||||
found = true;
|
||||
IsActive = "Y".equals (rs.getString (1));
|
||||
OptOutDate = rs.getString (2);
|
||||
isUnique = rs.next();
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log (Level.SEVERE, sql, e);
|
||||
error = "System Error (2)";
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
// System Error
|
||||
if (error != null)
|
||||
{
|
||||
m_error++;
|
||||
ldapUser.setErrorString(error);
|
||||
return ldapUser;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
error = "@UserNotSubscribed@ User=" + usr;
|
||||
info = "No User Interest - " + usr
|
||||
+ " - R_InterestArea_ID=" + R_InterestArea_ID;
|
||||
}
|
||||
else if (OptOutDate != null)
|
||||
{
|
||||
error = "@UserNotSubscribed@ User=" + usr + " @OptOutDate@=" + OptOutDate;
|
||||
info = "Opted out - " + usr + " - OptOutDate=" + OptOutDate;
|
||||
}
|
||||
else if (!IsActive)
|
||||
{
|
||||
error = "@UserNotSubscribed@ User=" + usr;
|
||||
info = "User Interest Not Active - " + usr;
|
||||
}
|
||||
else
|
||||
info = "User subscribed - " + usr;
|
||||
|
||||
|
||||
if (error != null) // should use Language of the User
|
||||
{
|
||||
logAccess (AD_Client_ID, AD_User_ID, R_InterestArea_ID, info, error);
|
||||
ldapUser.setErrorString(Msg.translate (getCtx(), error));
|
||||
return ldapUser;
|
||||
}
|
||||
// Done
|
||||
logAccess (AD_Client_ID, AD_User_ID, R_InterestArea_ID, info, null);
|
||||
ldapUser.setOrg(o);
|
||||
ldapUser.setOrgUnit(ou);
|
||||
ldapUser.setUserId(usr);
|
||||
ldapUser.setPassword(Password);
|
||||
return ldapUser;
|
||||
} // authenticate
|
||||
|
||||
/**
|
||||
* Find Client
|
||||
* @param client client name
|
||||
* @return AD_Client_ID
|
||||
*/
|
||||
private int findClient (String client)
|
||||
{
|
||||
if (m_clients == null)
|
||||
m_clients = MClient.getAll(getCtx());
|
||||
for (int i = 0; i < m_clients.length; i++)
|
||||
{
|
||||
if ((client.equalsIgnoreCase (m_clients[i].getValue())))
|
||||
return m_clients[i].getAD_Client_ID ();
|
||||
}
|
||||
return 0;
|
||||
} // findClient
|
||||
|
||||
/**
|
||||
* Find Interest Area
|
||||
* @param interset Name client name
|
||||
* @return AD_Client_ID
|
||||
*/
|
||||
private int findInterestArea (int AD_Client_ID, String interestArea)
|
||||
{
|
||||
if (m_interests == null)
|
||||
m_interests = MInterestArea.getAll(getCtx());
|
||||
for (int i = 0; i < m_interests.length; i++)
|
||||
{
|
||||
if (AD_Client_ID == m_interests[i].getAD_Client_ID()
|
||||
&& interestArea.equalsIgnoreCase (m_interests[i].getValue ()))
|
||||
return m_interests[i].getR_InterestArea_ID();
|
||||
}
|
||||
return 0;
|
||||
} // findInterestArea
|
||||
|
||||
/**
|
||||
* Log Access
|
||||
* @param AD_Client_ID client
|
||||
* @param AD_User_ID user
|
||||
* @param R_InterestArea_ID interest area
|
||||
* @param info info
|
||||
* @param error error
|
||||
*/
|
||||
private void logAccess (int AD_Client_ID,
|
||||
int AD_User_ID, int R_InterestArea_ID,
|
||||
String info, String error)
|
||||
{
|
||||
if (error != null)
|
||||
{
|
||||
log.log (Level.CONFIG, info);
|
||||
m_error++;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.log (Level.INFO, info);
|
||||
m_ok++;
|
||||
}
|
||||
//
|
||||
MLdapAccess access = new MLdapAccess (getCtx(), 0, null);
|
||||
access.setAD_Client_ID (AD_Client_ID);
|
||||
access.setAD_User_ID (AD_User_ID);
|
||||
access.setR_InterestArea_ID (R_InterestArea_ID);
|
||||
access.setIsError (error != null);
|
||||
access.setSummary (info);
|
||||
access.save ();
|
||||
} // logAccess
|
||||
|
||||
} // MLdapProcessor
|
|
@ -0,0 +1,72 @@
|
|||
/******************************************************************************
|
||||
* 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.
|
||||
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
|
||||
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
|
||||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* LDAP Server Log
|
||||
* @author Jorg Janke
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MLdapProcessorLog extends X_AD_LdapProcessorLog implements AdempiereProcessorLog
|
||||
{
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_LdapProcessorLog_ID id
|
||||
* @param trxName trx
|
||||
*/
|
||||
public MLdapProcessorLog(Properties ctx, int AD_LdapProcessorLog_ID,
|
||||
String trxName)
|
||||
{
|
||||
super (ctx, AD_LdapProcessorLog_ID, trxName);
|
||||
if (AD_LdapProcessorLog_ID == 0)
|
||||
{
|
||||
// setAD_LdapProcessorLog_ID (0);
|
||||
// setAD_LdapProcessor_ID (0);
|
||||
setIsError (false);
|
||||
}
|
||||
} // MLdapProcessorLog
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MLdapProcessorLog(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MLdapProcessorLog
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param parent parent
|
||||
* @param summary summary
|
||||
*/
|
||||
public MLdapProcessorLog(MLdapProcessor parent, String summary)
|
||||
{
|
||||
this (parent.getCtx (), 0, null);
|
||||
setClientOrg (parent);
|
||||
setAD_LdapProcessor_ID (parent.getAD_LdapProcessor_ID());
|
||||
setSummary (summary);
|
||||
} // MLdapProcessorLog
|
||||
|
||||
} // MLdapProcessorLog
|
|
@ -0,0 +1,140 @@
|
|||
/******************************************************************************
|
||||
* 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.
|
||||
* You may reach us at: ComPiere, Inc. - http://www.compiere.org/license.html
|
||||
* 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA or info@compiere.org
|
||||
*****************************************************************************/
|
||||
package org.compiere.model;
|
||||
|
||||
/*
|
||||
* MLdapUser, data object stores the user information such as userid,
|
||||
* password, organization and so on.
|
||||
*/
|
||||
public class MLdapUser
|
||||
{
|
||||
/** organization */
|
||||
private String org = null;
|
||||
/** organization unit */
|
||||
private String orgUnit = null;
|
||||
/** user password */
|
||||
private String passwd = null;
|
||||
/** user id */
|
||||
private String userId = null;
|
||||
/** error string */
|
||||
private String errStr = null;
|
||||
|
||||
public MLdapUser()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset attributes
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
org = null;
|
||||
orgUnit = null;
|
||||
passwd = null;
|
||||
userId = null;
|
||||
errStr = null;
|
||||
} // reset()
|
||||
|
||||
/**
|
||||
* Set the organization
|
||||
* @param org organization
|
||||
*/
|
||||
public void setOrg(String org)
|
||||
{
|
||||
this.org = org;
|
||||
} // setOrg()
|
||||
|
||||
/**
|
||||
* Set the organization unit
|
||||
* @param orgUnit organization unit
|
||||
*/
|
||||
public void setOrgUnit(String orgUnit)
|
||||
{
|
||||
this.orgUnit = orgUnit;
|
||||
} // setOrg()
|
||||
|
||||
/**
|
||||
* Set the user password
|
||||
* @param passwd User password string
|
||||
*/
|
||||
public void setPassword(String passwd)
|
||||
{
|
||||
this.passwd = passwd;
|
||||
} // setPassword()
|
||||
|
||||
/**
|
||||
* Set the user id
|
||||
* @param passwd User id string
|
||||
*/
|
||||
public void setUserId(String userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
} // setUserId()
|
||||
|
||||
/**
|
||||
* Set the error String
|
||||
* @param errStr Error String
|
||||
*/
|
||||
public void setErrorString(String errStr)
|
||||
{
|
||||
this.errStr = errStr;
|
||||
} // setErrorStr()
|
||||
|
||||
/**
|
||||
* Get the organization
|
||||
* @return org organization
|
||||
*/
|
||||
public String getOrg()
|
||||
{
|
||||
return org;
|
||||
} // getOrg()
|
||||
|
||||
/**
|
||||
* Get the organization unit
|
||||
* @return orgUnit organization unit
|
||||
*/
|
||||
public String getOrgUnit()
|
||||
{
|
||||
return orgUnit;
|
||||
} // getOrgUnit()
|
||||
|
||||
/**
|
||||
* Get the user password
|
||||
* @return passwd User password string
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return passwd;
|
||||
} // getPassword()
|
||||
|
||||
/**
|
||||
* Get the user id
|
||||
* @return User id string
|
||||
*/
|
||||
public String getUserId()
|
||||
{
|
||||
return userId;
|
||||
} // getUserId()
|
||||
|
||||
/**
|
||||
* Get the error string
|
||||
* @return errStr Error String
|
||||
*/
|
||||
public String getErrorMsg()
|
||||
{
|
||||
return errStr;
|
||||
} // getErrorString()
|
||||
} // MLdapUser
|
|
@ -3,167 +3,181 @@
|
|||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Inventory Move Line Model
|
||||
*
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MMovementLine.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||
*/
|
||||
public class MMovementLine extends X_M_MovementLine
|
||||
{
|
||||
/**
|
||||
* Standard Cosntructor
|
||||
* @param ctx context
|
||||
* @param M_MovementLine_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MMovementLine (Properties ctx, int M_MovementLine_ID, String trxName)
|
||||
{
|
||||
super (ctx, M_MovementLine_ID, trxName);
|
||||
if (M_MovementLine_ID == 0)
|
||||
public class MMovementLine extends X_M_MovementLine
|
||||
{
|
||||
/**
|
||||
* Standard Cosntructor
|
||||
* @param ctx context
|
||||
* @param M_MovementLine_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MMovementLine (Properties ctx, int M_MovementLine_ID, String trxName)
|
||||
{
|
||||
super (ctx, M_MovementLine_ID, trxName);
|
||||
if (M_MovementLine_ID == 0)
|
||||
{
|
||||
// setM_LocatorTo_ID (0); // @M_LocatorTo_ID@
|
||||
// setM_Locator_ID (0); // @M_Locator_ID@
|
||||
// setM_MovementLine_ID (0);
|
||||
// setLine (0);
|
||||
// setM_MovementLine_ID (0);
|
||||
// setLine (0);
|
||||
// setM_Product_ID (0);
|
||||
setM_AttributeSetInstance_ID(0); // ID
|
||||
setMovementQty (Env.ZERO); // 1
|
||||
setTargetQty (Env.ZERO); // 0
|
||||
setTargetQty (Env.ZERO); // 0
|
||||
setScrappedQty(Env.ZERO);
|
||||
setConfirmedQty(Env.ZERO);
|
||||
setProcessed (false);
|
||||
}
|
||||
}
|
||||
} // MMovementLine
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MMovementLine (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MMovementLine
|
||||
|
||||
/**
|
||||
* Parent constructor
|
||||
* @param parent parent
|
||||
*/
|
||||
public MMovementLine (MMovement parent)
|
||||
{
|
||||
this (parent.getCtx(), 0, parent.get_TrxName());
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MMovementLine (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MMovementLine
|
||||
|
||||
/**
|
||||
* Parent constructor
|
||||
* @param parent parent
|
||||
*/
|
||||
public MMovementLine (MMovement parent)
|
||||
{
|
||||
this (parent.getCtx(), 0, parent.get_TrxName());
|
||||
setClientOrg(parent);
|
||||
setM_Movement_ID(parent.getM_Movement_ID());
|
||||
} // MMovementLine
|
||||
|
||||
|
||||
/**
|
||||
* Get AttributeSetInstance To
|
||||
* @return ASI
|
||||
*/
|
||||
public int getM_AttributeSetInstanceTo_ID ()
|
||||
{
|
||||
int M_AttributeSetInstanceTo_ID = super.getM_AttributeSetInstanceTo_ID();
|
||||
if (M_AttributeSetInstanceTo_ID == 0)
|
||||
*/
|
||||
public int getM_AttributeSetInstanceTo_ID ()
|
||||
{
|
||||
int M_AttributeSetInstanceTo_ID = super.getM_AttributeSetInstanceTo_ID();
|
||||
if (M_AttributeSetInstanceTo_ID == 0)
|
||||
M_AttributeSetInstanceTo_ID = super.getM_AttributeSetInstance_ID();
|
||||
return M_AttributeSetInstanceTo_ID;
|
||||
} // getM_AttributeSetInstanceTo_ID
|
||||
|
||||
|
||||
/**
|
||||
* Add to Description
|
||||
* @param description text
|
||||
*/
|
||||
public void addDescription (String description)
|
||||
{
|
||||
String desc = getDescription();
|
||||
if (desc == null)
|
||||
setDescription(description);
|
||||
else
|
||||
setDescription(desc + " | " + description);
|
||||
} // addDescription
|
||||
|
||||
/**
|
||||
* Get Product
|
||||
* @return product or null if not defined
|
||||
*/
|
||||
public MProduct getProduct()
|
||||
{
|
||||
if (getM_Product_ID() != 0)
|
||||
*/
|
||||
public void addDescription (String description)
|
||||
{
|
||||
String desc = getDescription();
|
||||
if (desc == null)
|
||||
setDescription(description);
|
||||
else
|
||||
setDescription(desc + " | " + description);
|
||||
} // addDescription
|
||||
|
||||
/**
|
||||
* Get Product
|
||||
* @return product or null if not defined
|
||||
*/
|
||||
public MProduct getProduct()
|
||||
{
|
||||
if (getM_Product_ID() != 0)
|
||||
return MProduct.get(getCtx(), getM_Product_ID());
|
||||
return null;
|
||||
} // getProduct
|
||||
|
||||
|
||||
/**
|
||||
* Set Movement Qty - enforce UOM
|
||||
* Set Movement Qty - enforce UOM
|
||||
* @param MovementQty qty
|
||||
*/
|
||||
public void setMovementQty (BigDecimal MovementQty)
|
||||
{
|
||||
if (MovementQty != null)
|
||||
{
|
||||
{
|
||||
if (MovementQty != null)
|
||||
{
|
||||
MProduct product = getProduct();
|
||||
if (product != null)
|
||||
{
|
||||
int precision = product.getUOMPrecision();
|
||||
int precision = product.getUOMPrecision();
|
||||
MovementQty = MovementQty.setScale(precision, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
}
|
||||
super.setMovementQty(MovementQty);
|
||||
} // setMovementQty
|
||||
|
||||
/** Parent */
|
||||
private MMovement m_parent = null;
|
||||
|
||||
/**
|
||||
* get Parent
|
||||
* @return Parent Movement
|
||||
*/
|
||||
public MMovement getParent()
|
||||
{
|
||||
if (m_parent == null)
|
||||
m_parent = new MMovement (getCtx(), getM_Movement_ID(), get_TrxName());
|
||||
return m_parent;
|
||||
} // getParent
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
// Set Line No
|
||||
if (getLine() == 0)
|
||||
{
|
||||
String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=?";
|
||||
String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM C_M_MovementLine WHERE M_Movement_ID=?";
|
||||
int ii = DB.getSQLValue (get_TrxName(), sql, getM_Movement_ID());
|
||||
setLine (ii);
|
||||
}
|
||||
|
||||
|
||||
if (getM_Locator_ID() == getM_LocatorTo_ID())
|
||||
{
|
||||
log.saveError("Error", Msg.parseTranslation(getCtx(), "@M_Locator_ID@ == @M_LocatorTo_ID@"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getMovementQty().signum() == 0)
|
||||
{
|
||||
log.saveError("FillMandatory", Msg.getElement(getCtx(), "MovementQty"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Qty Precision
|
||||
if (newRecord || is_ValueChanged("QtyEntered"))
|
||||
setMovementQty(getMovementQty());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getMovementQty().signum() == 0)
|
||||
{
|
||||
log.saveError("FillMandatory", Msg.getElement(getCtx(), "MovementQty"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Qty Precision
|
||||
if (newRecord || is_ValueChanged("QtyEntered"))
|
||||
setMovementQty(getMovementQty());
|
||||
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
|
||||
|
||||
} // MMovementLine
|
||||
|
|
|
@ -3,135 +3,134 @@
|
|||
* 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.*;
|
||||
|
||||
/**
|
||||
* News ItemModel
|
||||
*
|
||||
* @author Yves Sandfort
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MNewsItem extends X_CM_NewsItem
|
||||
{
|
||||
/***
|
||||
* Standard Constructor
|
||||
*
|
||||
* @param ctx context
|
||||
* @param CM_NewsItem_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MNewsItem (Properties ctx, int CM_NewsItem_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_NewsItem_ID, trxName);
|
||||
} // MNewsItem
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MNewsItem (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MNewsItem
|
||||
|
||||
/**
|
||||
* getNewsChannel
|
||||
* @return NewsChannel
|
||||
*/
|
||||
public MNewsChannel getNewsChannel()
|
||||
{
|
||||
int[] thisNewsChannel = MNewsChannel.getAllIDs("CM_NewsChannel","CM_NewsChannel_ID=" + this.getCM_NewsChannel_ID(), get_TrxName());
|
||||
if (thisNewsChannel!=null)
|
||||
{
|
||||
if (thisNewsChannel.length==1)
|
||||
return new MNewsChannel(getCtx(), thisNewsChannel[0], get_TrxName());
|
||||
}
|
||||
return null;
|
||||
} // getNewsChannel
|
||||
|
||||
/**
|
||||
* Get rss2 Item Code
|
||||
* @param xmlCode xml
|
||||
* @param thisChannel channel
|
||||
* @return rss item code
|
||||
*/
|
||||
public StringBuffer get_rss2ItemCode(StringBuffer xmlCode, MNewsChannel thisChannel)
|
||||
{
|
||||
if (this != null) // never null ??
|
||||
{
|
||||
xmlCode.append ("<item>");
|
||||
xmlCode.append ("<CM_NewsItem_ID>"+ this.get_ID() + "</CM_NewsItem_ID>");
|
||||
xmlCode.append (" <title><![CDATA["
|
||||
+ this.getTitle () + "]]></title>");
|
||||
xmlCode.append (" <description><![CDATA["
|
||||
+ this.getDescription ()
|
||||
+ "]]></description>");
|
||||
xmlCode.append (" <content><![CDATA["
|
||||
+ this.getContentHTML ()
|
||||
+ "]]></content>");
|
||||
xmlCode.append (" <link>"
|
||||
+ thisChannel.getLink ()
|
||||
+ "?CM_NewsItem_ID=" + this.get_ID() + "</link>");
|
||||
xmlCode.append (" <author><![CDATA["
|
||||
+ this.getAuthor () + "]]></author>");
|
||||
xmlCode.append (" <pubDate>"
|
||||
+ this.getPubDate () + "</pubDate>");
|
||||
xmlCode.append ("</item>");
|
||||
}
|
||||
return xmlCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* After Save.
|
||||
* Insert
|
||||
* - create / update index
|
||||
* @param newRecord insert
|
||||
* @param success save success
|
||||
* @return true if saved
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
if (!success)
|
||||
return success;
|
||||
if (!newRecord)
|
||||
{
|
||||
MIndex.cleanUp(get_TrxName(), getAD_Client_ID(), get_Table_ID(), get_ID());
|
||||
}
|
||||
reIndex(newRecord);
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
* 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.*;
|
||||
|
||||
/**
|
||||
* News ItemModel
|
||||
*
|
||||
* @author Yves Sandfort
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MNewsItem extends X_CM_NewsItem
|
||||
{
|
||||
/***
|
||||
* Standard Constructor
|
||||
*
|
||||
* @param ctx context
|
||||
* @param CM_NewsItem_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MNewsItem (Properties ctx, int CM_NewsItem_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_NewsItem_ID, trxName);
|
||||
} // MNewsItem
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MNewsItem (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MNewsItem
|
||||
|
||||
/**
|
||||
* getNewsChannel
|
||||
* @return NewsChannel
|
||||
*/
|
||||
public MNewsChannel getNewsChannel()
|
||||
{
|
||||
int[] thisNewsChannel = MNewsChannel.getAllIDs("CM_NewsChannel","CM_NewsChannel_ID=" + this.getCM_NewsChannel_ID(), get_TrxName());
|
||||
if (thisNewsChannel!=null)
|
||||
{
|
||||
if (thisNewsChannel.length==1)
|
||||
return new MNewsChannel(getCtx(), thisNewsChannel[0], get_TrxName());
|
||||
}
|
||||
return null;
|
||||
} // getNewsChannel
|
||||
|
||||
/**
|
||||
* Get rss2 Item Code
|
||||
* @param xmlCode xml
|
||||
* @param thisChannel channel
|
||||
* @return rss item code
|
||||
*/
|
||||
public StringBuffer get_rss2ItemCode(StringBuffer xmlCode, MNewsChannel thisChannel)
|
||||
{
|
||||
if (this != null) // never null ??
|
||||
{
|
||||
xmlCode.append ("<item>");
|
||||
xmlCode.append ("<CM_NewsItem_ID>"+ this.get_ID() + "</CM_NewsItem_ID>");
|
||||
xmlCode.append (" <title><![CDATA["
|
||||
+ this.getTitle () + "]]></title>");
|
||||
xmlCode.append (" <description><![CDATA["
|
||||
+ this.getDescription ()
|
||||
+ "]]></description>");
|
||||
xmlCode.append (" <content><![CDATA["
|
||||
+ this.getContentHTML ()
|
||||
+ "]]></content>");
|
||||
xmlCode.append (" <link>"
|
||||
+ thisChannel.getLink ()
|
||||
+ "?CM_NewsItem_ID=" + this.get_ID() + "</link>");
|
||||
xmlCode.append (" <author><![CDATA["
|
||||
+ this.getAuthor () + "]]></author>");
|
||||
xmlCode.append (" <pubDate>"
|
||||
+ this.getPubDate () + "</pubDate>");
|
||||
xmlCode.append ("</item>");
|
||||
}
|
||||
return xmlCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* After Save.
|
||||
* Insert
|
||||
* - create / update index
|
||||
* @param newRecord insert
|
||||
* @param success save success
|
||||
* @return true if saved
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
if (!success)
|
||||
return success;
|
||||
if (!newRecord)
|
||||
{
|
||||
MIndex.cleanUp(get_TrxName(), getAD_Client_ID(), get_Table_ID(), get_ID());
|
||||
}
|
||||
reIndex(newRecord);
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* reIndex
|
||||
* @param newRecord
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void reIndex(boolean newRecord)
|
||||
{
|
||||
int CMWebProjectID = 0;
|
||||
if (getNewsChannel()!=null)
|
||||
CMWebProjectID = getNewsChannel().getCM_WebProject_ID();
|
||||
String [] toBeIndexed = new String[4];
|
||||
toBeIndexed[0] = this.getAuthor();
|
||||
toBeIndexed[1] = this.getDescription();
|
||||
toBeIndexed[2] = this.getTitle();
|
||||
toBeIndexed[3] = this.getContentHTML();
|
||||
MIndex.reIndex (newRecord, toBeIndexed, getCtx(), getAD_Client_ID(), get_Table_ID(), get_ID(), CMWebProjectID, this.getUpdated());
|
||||
} // reIndex
|
||||
}
|
||||
int CMWebProjectID = 0;
|
||||
if (getNewsChannel()!=null)
|
||||
CMWebProjectID = getNewsChannel().getCM_WebProject_ID();
|
||||
String [] toBeIndexed = new String[4];
|
||||
toBeIndexed[0] = this.getAuthor();
|
||||
toBeIndexed[1] = this.getDescription();
|
||||
toBeIndexed[2] = this.getTitle();
|
||||
toBeIndexed[3] = this.getContentHTML();
|
||||
MIndex.reIndex (newRecord, toBeIndexed, getCtx(), getAD_Client_ID(), get_Table_ID(), get_ID(), CMWebProjectID, this.getUpdated());
|
||||
} // reIndex
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -3,176 +3,175 @@
|
|||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Payment Selection Line Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MPaySelectionLine.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||
*/
|
||||
public class MPaySelectionLine extends X_C_PaySelectionLine
|
||||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_PaySelectionLine_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MPaySelectionLine (Properties ctx, int C_PaySelectionLine_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_PaySelectionLine_ID, trxName);
|
||||
if (C_PaySelectionLine_ID == 0)
|
||||
{
|
||||
// setC_PaySelection_ID (0);
|
||||
// setPaymentRule (null); // S
|
||||
// setLine (0); // @SQL=SELECT NVL(MAX(Line),0)+10 AS DefaultValue FROM C_PaySelectionLine WHERE C_PaySelection_ID=@C_PaySelection_ID@
|
||||
// setC_Invoice_ID (0);
|
||||
setIsSOTrx (false);
|
||||
setOpenAmt(Env.ZERO);
|
||||
setPayAmt (Env.ZERO);
|
||||
setDiscountAmt(Env.ZERO);
|
||||
setDifferenceAmt (Env.ZERO);
|
||||
setIsManual (false);
|
||||
}
|
||||
} // MPaySelectionLine
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MPaySelectionLine(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MPaySelectionLine
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param ps parent
|
||||
* @param Line line
|
||||
* @param PaymentRule payment rule
|
||||
*/
|
||||
public MPaySelectionLine (MPaySelection ps, int Line, String PaymentRule)
|
||||
{
|
||||
this (ps.getCtx(), 0, ps.get_TrxName());
|
||||
setClientOrg(ps);
|
||||
setC_PaySelection_ID(ps.getC_PaySelection_ID());
|
||||
setLine(Line);
|
||||
setPaymentRule(PaymentRule);
|
||||
} // MPaySelectionLine
|
||||
|
||||
/** Invoice */
|
||||
private MInvoice m_invoice = null;
|
||||
|
||||
/**
|
||||
* Set Invoice Info
|
||||
* @param C_Invoice_ID invoice
|
||||
* @param isSOTrx sales trx
|
||||
* @param PayAmt payment
|
||||
* @param OpenAmt open
|
||||
* @param DiscountAmt discount
|
||||
*/
|
||||
public void setInvoice (int C_Invoice_ID, boolean isSOTrx, BigDecimal OpenAmt,
|
||||
BigDecimal PayAmt, BigDecimal DiscountAmt)
|
||||
{
|
||||
setC_Invoice_ID (C_Invoice_ID);
|
||||
setIsSOTrx(isSOTrx);
|
||||
setOpenAmt(OpenAmt);
|
||||
setPayAmt (PayAmt);
|
||||
setDiscountAmt(DiscountAmt);
|
||||
setDifferenceAmt(OpenAmt.subtract(PayAmt).subtract(DiscountAmt));
|
||||
} // setInvoive
|
||||
|
||||
/**
|
||||
* Get Invoice
|
||||
* @return invoice
|
||||
*/
|
||||
public MInvoice getInvoice()
|
||||
{
|
||||
if (m_invoice == null)
|
||||
m_invoice = new MInvoice (getCtx(), getC_Invoice_ID(), get_TrxName());
|
||||
* 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.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Payment Selection Line Model
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MPaySelectionLine.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||
*/
|
||||
public class MPaySelectionLine extends X_C_PaySelectionLine
|
||||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param C_PaySelectionLine_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MPaySelectionLine (Properties ctx, int C_PaySelectionLine_ID, String trxName)
|
||||
{
|
||||
super(ctx, C_PaySelectionLine_ID, trxName);
|
||||
if (C_PaySelectionLine_ID == 0)
|
||||
{
|
||||
// setC_PaySelection_ID (0);
|
||||
// setPaymentRule (null); // S
|
||||
// setLine (0); // @SQL=SELECT NVL(MAX(Line),0)+10 AS DefaultValue FROM C_PaySelectionLine WHERE C_PaySelection_ID=@C_PaySelection_ID@
|
||||
// setC_Invoice_ID (0);
|
||||
setIsSOTrx (false);
|
||||
setOpenAmt(Env.ZERO);
|
||||
setPayAmt (Env.ZERO);
|
||||
setDiscountAmt(Env.ZERO);
|
||||
setDifferenceAmt (Env.ZERO);
|
||||
setIsManual (false);
|
||||
}
|
||||
} // MPaySelectionLine
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MPaySelectionLine(Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MPaySelectionLine
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param ps parent
|
||||
* @param Line line
|
||||
* @param PaymentRule payment rule
|
||||
*/
|
||||
public MPaySelectionLine (MPaySelection ps, int Line, String PaymentRule)
|
||||
{
|
||||
this (ps.getCtx(), 0, ps.get_TrxName());
|
||||
setClientOrg(ps);
|
||||
setC_PaySelection_ID(ps.getC_PaySelection_ID());
|
||||
setLine(Line);
|
||||
setPaymentRule(PaymentRule);
|
||||
} // MPaySelectionLine
|
||||
|
||||
/** Invoice */
|
||||
private MInvoice m_invoice = null;
|
||||
|
||||
/**
|
||||
* Set Invoice Info
|
||||
* @param C_Invoice_ID invoice
|
||||
* @param isSOTrx sales trx
|
||||
* @param PayAmt payment
|
||||
* @param OpenAmt open
|
||||
* @param DiscountAmt discount
|
||||
*/
|
||||
public void setInvoice (int C_Invoice_ID, boolean isSOTrx, BigDecimal OpenAmt,
|
||||
BigDecimal PayAmt, BigDecimal DiscountAmt)
|
||||
{
|
||||
setC_Invoice_ID (C_Invoice_ID);
|
||||
setIsSOTrx(isSOTrx);
|
||||
setOpenAmt(OpenAmt);
|
||||
setPayAmt (PayAmt);
|
||||
setDiscountAmt(DiscountAmt);
|
||||
setDifferenceAmt(OpenAmt.subtract(PayAmt).subtract(DiscountAmt));
|
||||
} // setInvoive
|
||||
|
||||
/**
|
||||
* Get Invoice
|
||||
* @return invoice
|
||||
*/
|
||||
public MInvoice getInvoice()
|
||||
{
|
||||
if (m_invoice == null)
|
||||
m_invoice = new MInvoice (getCtx(), getC_Invoice_ID(), get_TrxName());
|
||||
return m_invoice;
|
||||
} // getInvoice
|
||||
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
setDifferenceAmt(getOpenAmt().subtract(getPayAmt()).subtract(getDiscountAmt()));
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
setHeader();
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* After Delete
|
||||
* @param success success
|
||||
* @return sucess
|
||||
*/
|
||||
protected boolean afterDelete (boolean success)
|
||||
{
|
||||
setHeader();
|
||||
return success;
|
||||
} // afterDelete
|
||||
|
||||
/**
|
||||
* Recalculate Header Sum
|
||||
*/
|
||||
private void setHeader()
|
||||
{
|
||||
// Update Header
|
||||
String sql = "UPDATE C_PaySelection ps "
|
||||
+ "SET TotalAmt = (SELECT COALESCE(SUM(psl.PayAmt),0) "
|
||||
+ "FROM C_PaySelectionLine psl "
|
||||
+ "WHERE ps.C_PaySelection_ID=psl.C_PaySelection_ID AND psl.IsActive='Y') "
|
||||
+ "WHERE C_PaySelection_ID=" + getC_PaySelection_ID();
|
||||
DB.executeUpdate(sql, get_TrxName());
|
||||
} // setHeader
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MPaySelectionLine[");
|
||||
sb.append(get_ID()).append(",C_Invoice_ID=").append(getC_Invoice_ID())
|
||||
.append(",PayAmt=").append(getPayAmt())
|
||||
.append(",DifferenceAmt=").append(getDifferenceAmt())
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
} // MPaySelectionLine
|
||||
* @return true
|
||||
*/
|
||||
protected boolean beforeSave (boolean newRecord)
|
||||
{
|
||||
setDifferenceAmt(getOpenAmt().subtract(getPayAmt()).subtract(getDiscountAmt()));
|
||||
return true;
|
||||
} // beforeSave
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return success
|
||||
*/
|
||||
protected boolean afterSave (boolean newRecord, boolean success)
|
||||
{
|
||||
setHeader();
|
||||
return success;
|
||||
} // afterSave
|
||||
|
||||
/**
|
||||
* After Delete
|
||||
* @param success success
|
||||
* @return sucess
|
||||
*/
|
||||
protected boolean afterDelete (boolean success)
|
||||
{
|
||||
setHeader();
|
||||
return success;
|
||||
} // afterDelete
|
||||
|
||||
/**
|
||||
* Recalculate Header Sum
|
||||
*/
|
||||
private void setHeader()
|
||||
{
|
||||
// Update Header
|
||||
String sql = "UPDATE C_PaySelection ps "
|
||||
+ "SET TotalAmt = (SELECT COALESCE(SUM(psl.PayAmt),0) "
|
||||
+ "FROM C_PaySelectionLine psl "
|
||||
+ "WHERE ps.C_PaySelection_ID=psl.C_PaySelection_ID AND psl.IsActive='Y') "
|
||||
+ "WHERE C_PaySelection_ID=" + getC_PaySelection_ID();
|
||||
DB.executeUpdate(sql, get_TrxName());
|
||||
} // setHeader
|
||||
|
||||
/**
|
||||
* String Representation
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("MPaySelectionLine[");
|
||||
sb.append(get_ID()).append(",C_Invoice_ID=").append(getC_Invoice_ID())
|
||||
.append(",PayAmt=").append(getPayAmt())
|
||||
.append(",DifferenceAmt=").append(getDifferenceAmt())
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
} // MPaySelectionLine
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,436 +3,438 @@
|
|||
* 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.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Payment Validion Routines
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MPaymentValidate.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
|
||||
*/
|
||||
public class MPaymentValidate
|
||||
{
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MPaymentValidate.class);
|
||||
|
||||
|
||||
/**
|
||||
* Is this a valid Credit Card Exp Date?
|
||||
* @param mmyy Exp in form of mmyy
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardExp (String mmyy)
|
||||
{
|
||||
String exp = checkNumeric(mmyy);
|
||||
if (exp.length() != 4)
|
||||
return "CreditCardExpFormat";
|
||||
//
|
||||
String mmStr = exp.substring(0,2);
|
||||
String yyStr = exp.substring(2,4);
|
||||
//
|
||||
int mm = 0;
|
||||
int yy = 0;
|
||||
try
|
||||
{
|
||||
mm = Integer.parseInt(mmStr);
|
||||
yy = Integer.parseInt(yyStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return "CreditCardExpFormat";
|
||||
}
|
||||
return validateCreditCardExp(mm,yy);
|
||||
} // validateCreditCardExp
|
||||
|
||||
/**
|
||||
* Return Month of Exp
|
||||
* @param mmyy Exp in form of mmyy
|
||||
* @return month
|
||||
*/
|
||||
public static int getCreditCardExpMM (String mmyy)
|
||||
{
|
||||
String mmStr = mmyy.substring(0,2);
|
||||
int mm = 0;
|
||||
try
|
||||
{
|
||||
mm = Integer.parseInt(mmStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
return mm;
|
||||
} // getCreditCardExpMM
|
||||
|
||||
/**
|
||||
* Return Year of Exp
|
||||
* @param mmyy Exp in form of mmyy
|
||||
* @return year
|
||||
*/
|
||||
public static int getCreditCardExpYY (String mmyy)
|
||||
{
|
||||
String yyStr = mmyy.substring(2);
|
||||
int yy = 0;
|
||||
try
|
||||
{
|
||||
yy = Integer.parseInt(yyStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
return yy;
|
||||
} // getCreditCardExpYY
|
||||
|
||||
/**
|
||||
* Is this a valid Credit Card Exp Date?
|
||||
* @param mm month
|
||||
* @param yy year
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardExp (int mm, int yy)
|
||||
{
|
||||
if (mm < 1 || mm > 12)
|
||||
return "CreditCardExpMonth";
|
||||
// if (yy < 0 || yy > EXP_YEAR)
|
||||
// return "CreditCardExpYear";
|
||||
|
||||
// Today's date
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int year = cal.get(Calendar.YEAR) - 2000; // two digits
|
||||
int month = cal.get(Calendar.MONTH) + 1; // zero based
|
||||
//
|
||||
if (yy < year)
|
||||
return "CreditCardExpired";
|
||||
else if (yy == year && mm < month)
|
||||
return "CreditCardExpired";
|
||||
return "";
|
||||
} // validateCreditCardExp
|
||||
|
||||
|
||||
/**
|
||||
* Validate Credit Card Number.
|
||||
* - Based on LUHN formula
|
||||
* @param creditCardNumber credit card number
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardNumber (String creditCardNumber)
|
||||
{
|
||||
if (creditCardNumber == null || creditCardNumber.length() == 0)
|
||||
return "CreditCardNumberError";
|
||||
|
||||
/**
|
||||
* 1: Double the value of alternate digits beginning with
|
||||
* the first right-hand digit (low order).
|
||||
* 2: Add the individual digits comprising the products
|
||||
* obtained in step 1 to each of the unaffected digits
|
||||
* in the original number.
|
||||
* 3: Subtract the total obtained in step 2 from the next higher
|
||||
* number ending in 0 [this in the equivalent of calculating
|
||||
* the "tens complement" of the low order digit (unit digit)
|
||||
* of the total].
|
||||
* If the total obtained in step 2 is a number ending in zero
|
||||
* (30, 40 etc.), the check digit is 0.
|
||||
* Example:
|
||||
* Account number: 4992 73 9871 6
|
||||
*
|
||||
* 4 9 9 2 7 3 9 8 7 1 6
|
||||
* x2 x2 x2 x2 x2
|
||||
* -------------------------------
|
||||
* 4 18 9 4 7 6 9 16 7 2 6
|
||||
*
|
||||
* 4 + 1 + 8 + 9 + 4 + 7 + 6 + 9 + 1 + 6 + 7 + 2 + 6 = 70
|
||||
* 70 % 10 = 0
|
||||
*/
|
||||
|
||||
// Clean up number
|
||||
String ccNumber1 = checkNumeric(creditCardNumber);
|
||||
int ccLength = ccNumber1.length();
|
||||
// Reverse string
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = ccLength; i != 0; i--)
|
||||
buf.append(ccNumber1.charAt(i-1));
|
||||
String ccNumber = buf.toString();
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < ccLength; i++)
|
||||
{
|
||||
int digit = Character.getNumericValue(ccNumber.charAt(i));
|
||||
if (i % 2 == 1)
|
||||
{
|
||||
digit *= 2;
|
||||
if (digit > 9)
|
||||
digit -= 9;
|
||||
}
|
||||
sum += digit;
|
||||
}
|
||||
if (sum % 10 == 0)
|
||||
return "";
|
||||
|
||||
s_log.fine("validateCreditCardNumber - " + creditCardNumber + " -> "
|
||||
+ ccNumber + ", Luhn=" + sum);
|
||||
return "CreditCardNumberError";
|
||||
} // validateCreditCardNumber
|
||||
|
||||
/**
|
||||
* Validate Credit Card Number.
|
||||
* - Check Card Type and Length
|
||||
* @param creditCardNumber CC Number
|
||||
* @param creditCardType CC Type
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardNumber (String creditCardNumber, String creditCardType)
|
||||
{
|
||||
if (creditCardNumber == null || creditCardType == null)
|
||||
return "CreditCardNumberError";
|
||||
|
||||
// http://www.beachnet.com/~hstiles/cardtype.html
|
||||
// http://staff.semel.fi/~kribe/document/luhn.htm
|
||||
|
||||
* 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.util.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Payment Validion Routines
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MPaymentValidate.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
|
||||
*/
|
||||
public class MPaymentValidate
|
||||
{
|
||||
/** Static Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MPaymentValidate.class);
|
||||
|
||||
|
||||
/**
|
||||
* Is this a valid Credit Card Exp Date?
|
||||
* @param mmyy Exp in form of mmyy
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardExp (String mmyy)
|
||||
{
|
||||
String exp = checkNumeric(mmyy);
|
||||
if (exp.length() != 4)
|
||||
return "CreditCardExpFormat";
|
||||
//
|
||||
String mmStr = exp.substring(0,2);
|
||||
String yyStr = exp.substring(2,4);
|
||||
//
|
||||
int mm = 0;
|
||||
int yy = 0;
|
||||
try
|
||||
{
|
||||
mm = Integer.parseInt(mmStr);
|
||||
yy = Integer.parseInt(yyStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return "CreditCardExpFormat";
|
||||
}
|
||||
return validateCreditCardExp(mm,yy);
|
||||
} // validateCreditCardExp
|
||||
|
||||
/**
|
||||
* Return Month of Exp
|
||||
* @param mmyy Exp in form of mmyy
|
||||
* @return month
|
||||
*/
|
||||
public static int getCreditCardExpMM (String mmyy)
|
||||
{
|
||||
String mmStr = mmyy.substring(0,2);
|
||||
int mm = 0;
|
||||
try
|
||||
{
|
||||
mm = Integer.parseInt(mmStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
return mm;
|
||||
} // getCreditCardExpMM
|
||||
|
||||
/**
|
||||
* Return Year of Exp
|
||||
* @param mmyy Exp in form of mmyy
|
||||
* @return year
|
||||
*/
|
||||
public static int getCreditCardExpYY (String mmyy)
|
||||
{
|
||||
String yyStr = mmyy.substring(2);
|
||||
int yy = 0;
|
||||
try
|
||||
{
|
||||
yy = Integer.parseInt(yyStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
return yy;
|
||||
} // getCreditCardExpYY
|
||||
|
||||
/**
|
||||
* Is this a valid Credit Card Exp Date?
|
||||
* @param mm month
|
||||
* @param yy year
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardExp (int mm, int yy)
|
||||
{
|
||||
if (mm < 1 || mm > 12)
|
||||
return "CreditCardExpMonth";
|
||||
// if (yy < 0 || yy > EXP_YEAR)
|
||||
// return "CreditCardExpYear";
|
||||
|
||||
// Today's date
|
||||
Calendar cal = Calendar.getInstance();
|
||||
int year = cal.get(Calendar.YEAR) - 2000; // two digits
|
||||
int month = cal.get(Calendar.MONTH) + 1; // zero based
|
||||
//
|
||||
if (yy < year)
|
||||
return "CreditCardExpired";
|
||||
else if (yy == year && mm < month)
|
||||
return "CreditCardExpired";
|
||||
return "";
|
||||
} // validateCreditCardExp
|
||||
|
||||
|
||||
/**
|
||||
* Validate Credit Card Number.
|
||||
* - Based on LUHN formula
|
||||
* @param creditCardNumber credit card number
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardNumber (String creditCardNumber)
|
||||
{
|
||||
if (creditCardNumber == null || creditCardNumber.length() == 0)
|
||||
return "CreditCardNumberError";
|
||||
|
||||
/**
|
||||
* 1: Double the value of alternate digits beginning with
|
||||
* the first right-hand digit (low order).
|
||||
* 2: Add the individual digits comprising the products
|
||||
* obtained in step 1 to each of the unaffected digits
|
||||
* in the original number.
|
||||
* 3: Subtract the total obtained in step 2 from the next higher
|
||||
* number ending in 0 [this in the equivalent of calculating
|
||||
* the "tens complement" of the low order digit (unit digit)
|
||||
* of the total].
|
||||
* If the total obtained in step 2 is a number ending in zero
|
||||
* (30, 40 etc.), the check digit is 0.
|
||||
* Example:
|
||||
* Account number: 4992 73 9871 6
|
||||
*
|
||||
* 4 9 9 2 7 3 9 8 7 1 6
|
||||
* x2 x2 x2 x2 x2
|
||||
* -------------------------------
|
||||
* 4 18 9 4 7 6 9 16 7 2 6
|
||||
*
|
||||
* 4 + 1 + 8 + 9 + 4 + 7 + 6 + 9 + 1 + 6 + 7 + 2 + 6 = 70
|
||||
* 70 % 10 = 0
|
||||
*/
|
||||
|
||||
// Clean up number
|
||||
String ccNumber1 = checkNumeric(creditCardNumber);
|
||||
int ccLength = ccNumber1.length();
|
||||
// Reverse string
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = ccLength; i != 0; i--)
|
||||
buf.append(ccNumber1.charAt(i-1));
|
||||
String ccNumber = buf.toString();
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < ccLength; i++)
|
||||
{
|
||||
int digit = Character.getNumericValue(ccNumber.charAt(i));
|
||||
if (i % 2 == 1)
|
||||
{
|
||||
digit *= 2;
|
||||
if (digit > 9)
|
||||
digit -= 9;
|
||||
}
|
||||
sum += digit;
|
||||
}
|
||||
if (sum % 10 == 0)
|
||||
return "";
|
||||
|
||||
s_log.fine("validateCreditCardNumber - " + creditCardNumber + " -> "
|
||||
+ ccNumber + ", Luhn=" + sum);
|
||||
return "CreditCardNumberError";
|
||||
} // validateCreditCardNumber
|
||||
|
||||
/**
|
||||
* Validate Credit Card Number.
|
||||
* - Check Card Type and Length
|
||||
* @param creditCardNumber CC Number
|
||||
* @param creditCardType CC Type
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardNumber (String creditCardNumber, String creditCardType)
|
||||
{
|
||||
if (creditCardNumber == null || creditCardType == null)
|
||||
return "CreditCardNumberError";
|
||||
|
||||
// http://www.beachnet.com/~hstiles/cardtype.html
|
||||
// http://staff.semel.fi/~kribe/document/luhn.htm
|
||||
|
||||
String ccStartList = ""; // comma separated list of starting numbers
|
||||
String ccLengthList = ""; // comma separated list of lengths
|
||||
//
|
||||
if (creditCardType.equals(MPayment.CREDITCARDTYPE_MasterCard))
|
||||
if (creditCardType.equals(X_C_Payment.CREDITCARDTYPE_MasterCard))
|
||||
{
|
||||
ccStartList = "51,52,53,54,55";
|
||||
ccLengthList = "16";
|
||||
}
|
||||
else if (creditCardType.equals(MPayment.CREDITCARDTYPE_Visa))
|
||||
else if (creditCardType.equals(X_C_Payment.CREDITCARDTYPE_Visa))
|
||||
{
|
||||
ccStartList = "4";
|
||||
ccLengthList = "13,16";
|
||||
}
|
||||
else if (creditCardType.equals(MPayment.CREDITCARDTYPE_Amex))
|
||||
else if (creditCardType.equals(X_C_Payment.CREDITCARDTYPE_Amex))
|
||||
{
|
||||
ccStartList = "34,37";
|
||||
ccLengthList = "15";
|
||||
}
|
||||
else if (creditCardType.equals(MPayment.CREDITCARDTYPE_Discover))
|
||||
else if (creditCardType.equals(X_C_Payment.CREDITCARDTYPE_Discover))
|
||||
{
|
||||
ccStartList = "6011";
|
||||
ccLengthList = "16";
|
||||
}
|
||||
else if (creditCardType.equals(MPayment.CREDITCARDTYPE_Diners))
|
||||
else if (creditCardType.equals(X_C_Payment.CREDITCARDTYPE_Diners))
|
||||
{
|
||||
ccStartList = "300,301,302,303,304,305,36,38";
|
||||
ccLengthList = "14";
|
||||
}
|
||||
else
|
||||
{
|
||||
// enRouteCard
|
||||
ccStartList = "2014,2149";
|
||||
ccLengthList = "15";
|
||||
// JCBCard
|
||||
ccStartList += ",3088,3096,3112,3158,3337,3528";
|
||||
ccLengthList += ",16";
|
||||
// JCBCard
|
||||
ccStartList += ",2131,1800";
|
||||
ccLengthList += ",15";
|
||||
}
|
||||
|
||||
// Clean up number
|
||||
String ccNumber = checkNumeric(creditCardNumber);
|
||||
|
||||
/**
|
||||
* Check Length
|
||||
*/
|
||||
int ccLength = ccNumber.length();
|
||||
boolean ccLengthOK = false;
|
||||
StringTokenizer st = new StringTokenizer(ccLengthList, ",", false);
|
||||
while (st.hasMoreTokens() && !ccLengthOK)
|
||||
{
|
||||
int l = Integer.parseInt(st.nextToken());
|
||||
if (ccLength == l)
|
||||
ccLengthOK = true;
|
||||
}
|
||||
if (!ccLengthOK)
|
||||
{
|
||||
s_log.fine("validateCreditCardNumber Length="
|
||||
+ ccLength + " <> " + ccLengthList);
|
||||
return "CreditCardNumberError";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Start Digits
|
||||
*/
|
||||
boolean ccIdentified = false;
|
||||
st = new StringTokenizer(ccStartList, ",", false);
|
||||
while (st.hasMoreTokens() && !ccIdentified)
|
||||
{
|
||||
if (ccNumber.startsWith(st.nextToken()))
|
||||
ccIdentified = true;
|
||||
}
|
||||
if (!ccIdentified)
|
||||
s_log.fine("validateCreditCardNumber Type="
|
||||
+ creditCardType + " <> " + ccStartList);
|
||||
|
||||
//
|
||||
String check = validateCreditCardNumber(ccNumber);
|
||||
if (check.length() != 0)
|
||||
return check;
|
||||
if (!ccIdentified)
|
||||
return "CreditCardNumberProblem?";
|
||||
return "";
|
||||
} // validateCreditCardNumber
|
||||
|
||||
|
||||
/**
|
||||
* Validate Validation Code
|
||||
* @param creditCardVV CC Verification Code
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardVV (String creditCardVV)
|
||||
{
|
||||
if (creditCardVV == null)
|
||||
return "";
|
||||
int length = checkNumeric(creditCardVV).length();
|
||||
if (length == 3 || length == 4)
|
||||
return "";
|
||||
try
|
||||
{
|
||||
Integer.parseInt (creditCardVV);
|
||||
return "";
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
s_log.fine("validateCreditCardVV - " + ex);
|
||||
}
|
||||
s_log.fine("validateCreditCardVV - length=" + length);
|
||||
return "CreditCardVVError";
|
||||
} // validateCreditCardVV
|
||||
|
||||
/**
|
||||
* Validate Validation Code
|
||||
* @param creditCardVV CC Verification Code
|
||||
* @param creditCardType CC Type see CC_
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardVV (String creditCardVV, String creditCardType)
|
||||
{
|
||||
// no data
|
||||
if (creditCardVV == null || creditCardVV.length() == 0
|
||||
|| creditCardType == null || creditCardType.length() == 0)
|
||||
return "";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// enRouteCard
|
||||
ccStartList = "2014,2149";
|
||||
ccLengthList = "15";
|
||||
// JCBCard
|
||||
ccStartList += ",3088,3096,3112,3158,3337,3528";
|
||||
ccLengthList += ",16";
|
||||
// JCBCard
|
||||
ccStartList += ",2131,1800";
|
||||
ccLengthList += ",15";
|
||||
}
|
||||
|
||||
// Clean up number
|
||||
String ccNumber = checkNumeric(creditCardNumber);
|
||||
|
||||
/**
|
||||
* Check Length
|
||||
*/
|
||||
int ccLength = ccNumber.length();
|
||||
boolean ccLengthOK = false;
|
||||
StringTokenizer st = new StringTokenizer(ccLengthList, ",", false);
|
||||
while (st.hasMoreTokens() && !ccLengthOK)
|
||||
{
|
||||
int l = Integer.parseInt(st.nextToken());
|
||||
if (ccLength == l)
|
||||
ccLengthOK = true;
|
||||
}
|
||||
if (!ccLengthOK)
|
||||
{
|
||||
s_log.fine("validateCreditCardNumber Length="
|
||||
+ ccLength + " <> " + ccLengthList);
|
||||
return "CreditCardNumberError";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Start Digits
|
||||
*/
|
||||
boolean ccIdentified = false;
|
||||
st = new StringTokenizer(ccStartList, ",", false);
|
||||
while (st.hasMoreTokens() && !ccIdentified)
|
||||
{
|
||||
if (ccNumber.startsWith(st.nextToken()))
|
||||
ccIdentified = true;
|
||||
}
|
||||
if (!ccIdentified)
|
||||
s_log.fine("validateCreditCardNumber Type="
|
||||
+ creditCardType + " <> " + ccStartList);
|
||||
|
||||
//
|
||||
String check = validateCreditCardNumber(ccNumber);
|
||||
if (check.length() != 0)
|
||||
return check;
|
||||
if (!ccIdentified)
|
||||
return "CreditCardNumberProblem?";
|
||||
return "";
|
||||
} // validateCreditCardNumber
|
||||
|
||||
|
||||
/**
|
||||
* Validate Validation Code
|
||||
* @param creditCardVV CC Verification Code
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardVV (String creditCardVV)
|
||||
{
|
||||
if (creditCardVV == null)
|
||||
return "";
|
||||
int length = checkNumeric(creditCardVV).length();
|
||||
if (length == 3 || length == 4)
|
||||
return "";
|
||||
try
|
||||
{
|
||||
Integer.parseInt (creditCardVV);
|
||||
return "";
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
s_log.fine("validateCreditCardVV - " + ex);
|
||||
}
|
||||
s_log.fine("validateCreditCardVV - length=" + length);
|
||||
return "CreditCardVVError";
|
||||
} // validateCreditCardVV
|
||||
|
||||
/**
|
||||
* Validate Validation Code
|
||||
* @param creditCardVV CC Verification Code
|
||||
* @param creditCardType CC Type see CC_
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCreditCardVV (String creditCardVV, String creditCardType)
|
||||
{
|
||||
// no data
|
||||
if (creditCardVV == null || creditCardVV.length() == 0
|
||||
|| creditCardType == null || creditCardType.length() == 0)
|
||||
return "";
|
||||
|
||||
int length = checkNumeric(creditCardVV).length();
|
||||
|
||||
// Amex = 4 digits
|
||||
if (creditCardType.equals(MPayment.CREDITCARDTYPE_Amex))
|
||||
if (creditCardType.equals(X_C_Payment.CREDITCARDTYPE_Amex))
|
||||
{
|
||||
if (length == 4)
|
||||
{
|
||||
try
|
||||
{
|
||||
Integer.parseInt (creditCardVV);
|
||||
return "";
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
s_log.fine("validateCreditCardVV - " + ex);
|
||||
}
|
||||
}
|
||||
s_log.fine("validateCreditCardVV(4) CC=" + creditCardType + ", length=" + length);
|
||||
try
|
||||
{
|
||||
Integer.parseInt (creditCardVV);
|
||||
return "";
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
s_log.fine("validateCreditCardVV - " + ex);
|
||||
}
|
||||
}
|
||||
s_log.fine("validateCreditCardVV(4) CC=" + creditCardType + ", length=" + length);
|
||||
return "CreditCardVVError";
|
||||
}
|
||||
// Visa & MasterCard - 3 digits
|
||||
if (creditCardType.equals(MPayment.CREDITCARDTYPE_Visa)
|
||||
|| creditCardType.equals(MPayment.CREDITCARDTYPE_MasterCard))
|
||||
if (creditCardType.equals(X_C_Payment.CREDITCARDTYPE_Visa)
|
||||
|| creditCardType.equals(X_C_Payment.CREDITCARDTYPE_MasterCard))
|
||||
{
|
||||
if (length == 3)
|
||||
{
|
||||
try
|
||||
{
|
||||
Integer.parseInt (creditCardVV);
|
||||
return "";
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
s_log.fine("validateCreditCardVV - " + ex);
|
||||
}
|
||||
}
|
||||
s_log.fine("validateCreditCardVV(3) CC=" + creditCardType + ", length=" + length);
|
||||
return "CreditCardVVError";
|
||||
}
|
||||
|
||||
// Other
|
||||
return "";
|
||||
} // validateCreditCardVV
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Validate Routing Number
|
||||
* @param routingNo Routing No
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateRoutingNo (String routingNo)
|
||||
{
|
||||
int length = checkNumeric(routingNo).length();
|
||||
try
|
||||
{
|
||||
Integer.parseInt (creditCardVV);
|
||||
return "";
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
s_log.fine("validateCreditCardVV - " + ex);
|
||||
}
|
||||
}
|
||||
s_log.fine("validateCreditCardVV(3) CC=" + creditCardType + ", length=" + length);
|
||||
return "CreditCardVVError";
|
||||
}
|
||||
|
||||
// Other
|
||||
return "";
|
||||
} // validateCreditCardVV
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Validate Routing Number
|
||||
* @param routingNo Routing No
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateRoutingNo (String routingNo)
|
||||
{
|
||||
int length = checkNumeric(routingNo).length();
|
||||
// US - length 9
|
||||
// Germany - length 8
|
||||
// Japan - 7
|
||||
if (length == 7 || length == 8 || length == 9)
|
||||
// CH - 5
|
||||
// Issue: Bank account country
|
||||
if (length > 0)
|
||||
return "";
|
||||
return "PaymentBankRoutingNotValid";
|
||||
} // validateBankRoutingNo
|
||||
|
||||
/**
|
||||
* Validate Account No
|
||||
* @param AccountNo AccountNo
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateAccountNo (String AccountNo)
|
||||
{
|
||||
int length = checkNumeric(AccountNo).length();
|
||||
if (length > 0)
|
||||
return "";
|
||||
return "PaymentBankAccountNotValid";
|
||||
} // validateBankAccountNo
|
||||
|
||||
/**
|
||||
* Validate Check No
|
||||
* @param CheckNo CheckNo
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCheckNo (String CheckNo)
|
||||
{
|
||||
int length = checkNumeric(CheckNo).length();
|
||||
if (length > 0)
|
||||
return "";
|
||||
return "PaymentBankCheckNotValid";
|
||||
} // validateBankCheckNo
|
||||
|
||||
/**
|
||||
* Check Numeric
|
||||
* @param data input
|
||||
* @return the digits of the data - ignore the rest
|
||||
*/
|
||||
public static String checkNumeric (String data)
|
||||
{
|
||||
if (data == null || data.length() == 0)
|
||||
return "";
|
||||
// Remove all non Digits
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < data.length(); i++)
|
||||
{
|
||||
if (Character.isDigit(data.charAt(i)))
|
||||
sb.append(data.charAt(i));
|
||||
}
|
||||
return sb.toString();
|
||||
} // checkNumeric
|
||||
|
||||
|
||||
} // MPaymentValidate
|
||||
|
||||
/**
|
||||
* Validate Account No
|
||||
* @param AccountNo AccountNo
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateAccountNo (String AccountNo)
|
||||
{
|
||||
int length = checkNumeric(AccountNo).length();
|
||||
if (length > 0)
|
||||
return "";
|
||||
return "PaymentBankAccountNotValid";
|
||||
} // validateBankAccountNo
|
||||
|
||||
/**
|
||||
* Validate Check No
|
||||
* @param CheckNo CheckNo
|
||||
* @return "" or Error AD_Message
|
||||
*/
|
||||
public static String validateCheckNo (String CheckNo)
|
||||
{
|
||||
int length = checkNumeric(CheckNo).length();
|
||||
if (length > 0)
|
||||
return "";
|
||||
return "PaymentBankCheckNotValid";
|
||||
} // validateBankCheckNo
|
||||
|
||||
/**
|
||||
* Check Numeric
|
||||
* @param data input
|
||||
* @return the digits of the data - ignore the rest
|
||||
*/
|
||||
public static String checkNumeric (String data)
|
||||
{
|
||||
if (data == null || data.length() == 0)
|
||||
return "";
|
||||
// Remove all non Digits
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < data.length(); i++)
|
||||
{
|
||||
if (Character.isDigit(data.charAt(i)))
|
||||
sb.append(data.charAt(i));
|
||||
}
|
||||
return sb.toString();
|
||||
} // checkNumeric
|
||||
|
||||
|
||||
} // MPaymentValidate
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,27 +3,27 @@
|
|||
* 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.*;
|
||||
|
||||
|
||||
/**
|
||||
* Scheduler Log
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* 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.*;
|
||||
|
||||
|
||||
/**
|
||||
* Scheduler Log
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MSchedulerLog.java,v 1.3 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class MSchedulerLog extends X_AD_SchedulerLog
|
||||
|
@ -31,37 +31,39 @@ public class MSchedulerLog extends X_AD_SchedulerLog
|
|||
{
|
||||
/**
|
||||
* Standard Constructor
|
||||
* @param ctx context
|
||||
* @param AD_SchedulerLog_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
* @param ctx context
|
||||
* @param AD_SchedulerLog_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MSchedulerLog (Properties ctx, int AD_SchedulerLog_ID, String trxName)
|
||||
{
|
||||
super (ctx, AD_SchedulerLog_ID, trxName);
|
||||
if (AD_SchedulerLog_ID == 0)
|
||||
setIsError(false);
|
||||
} // MSchedulerLog
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MSchedulerLog (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MSchedulerLog
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param parent parent
|
||||
* @param summary summary
|
||||
*/
|
||||
public MSchedulerLog (MScheduler parent, String summary)
|
||||
{
|
||||
this (parent.getCtx(), 0, parent.get_TrxName());
|
||||
setClientOrg(parent);
|
||||
setAD_Scheduler_ID(parent.getAD_Scheduler_ID());
|
||||
setSummary(summary);
|
||||
} // MSchedulerLog
|
||||
|
||||
} // MSchedulerLog
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MSchedulerLog (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super(ctx, rs, trxName);
|
||||
} // MSchedulerLog
|
||||
|
||||
/**
|
||||
* Parent Constructor
|
||||
* @param parent parent
|
||||
* @param summary summary
|
||||
*/
|
||||
public MSchedulerLog (MScheduler parent, String summary)
|
||||
{
|
||||
this (parent.getCtx(), 0, parent.get_TrxName());
|
||||
setClientOrg(parent);
|
||||
setAD_Scheduler_ID(parent.getAD_Scheduler_ID());
|
||||
setSummary(summary);
|
||||
} // MSchedulerLog
|
||||
|
||||
} // MSchedulerLog
|
||||
|
|
|
@ -3,50 +3,99 @@
|
|||
* 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;
|
||||
* 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.Level;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
||||
/**
|
||||
* Web Project Domain
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MWebProjectDomain.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: MWebProjectDomain.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class MWebProjectDomain extends X_CM_WebProject_Domain
|
||||
{
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 5134789895039452551L;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger s_log = CLogger.getCLogger (MContainer.class);
|
||||
|
||||
/**
|
||||
* Web Project Domain Constructor
|
||||
* @param ctx context
|
||||
* @param CM_WebProject_Domain_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MWebProjectDomain (Properties ctx, int CM_WebProject_Domain_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_WebProject_Domain_ID, trxName);
|
||||
} // MWebProjectDomain
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MWebProjectDomain (Properties ctx, ResultSet rs, String trxName)
|
||||
* @param CM_WebProject_Domain_ID id
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MWebProjectDomain (Properties ctx, int CM_WebProject_Domain_ID, String trxName)
|
||||
{
|
||||
super (ctx, CM_WebProject_Domain_ID, trxName);
|
||||
} // MWebProjectDomain
|
||||
|
||||
/**
|
||||
* Load Constructor
|
||||
* @param ctx context
|
||||
* @param rs result set
|
||||
* @param trxName transaction
|
||||
*/
|
||||
public MWebProjectDomain (Properties ctx, ResultSet rs, String trxName)
|
||||
{
|
||||
super (ctx, rs, trxName);
|
||||
} // MWebProjectDomain
|
||||
|
||||
/**
|
||||
* get WebProjectDomain by Name
|
||||
* @param ctx
|
||||
* @param ServerName
|
||||
* @param trxName
|
||||
* @return ContainerElement
|
||||
*/
|
||||
public static MWebProjectDomain get(Properties ctx, String ServerName, String trxName) {
|
||||
MWebProjectDomain thisWebProjectDomain = null;
|
||||
String sql = "SELECT * FROM CM_WebProject_Domain WHERE lower(FQDN) LIKE ? ORDER by CM_WebProject_Domain_ID DESC";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, trxName);
|
||||
pstmt.setString(1, ServerName);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
thisWebProjectDomain = (new MWebProjectDomain(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;
|
||||
}
|
||||
return thisWebProjectDomain;
|
||||
}
|
||||
|
||||
|
||||
} // MWebProjectDomain
|
||||
|
|
|
@ -3,78 +3,78 @@
|
|||
* 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.process;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.print.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Dunning Letter Print
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DunningPrint.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class DunningPrint extends SvrProcess
|
||||
{
|
||||
/** Mail PDF */
|
||||
private boolean p_EMailPDF = false;
|
||||
/** Mail Template */
|
||||
private int p_R_MailText_ID = 0;
|
||||
/** Dunning Run */
|
||||
private int p_C_DunningRun_ID = 0;
|
||||
/** Print only Outstanding */
|
||||
private boolean p_IsOnlyIfBPBalance = true;
|
||||
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("EMailPDF"))
|
||||
p_EMailPDF = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("R_MailText_ID"))
|
||||
p_R_MailText_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_DunningRun_ID"))
|
||||
p_C_DunningRun_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("IsOnlyIfBPBalance"))
|
||||
p_IsOnlyIfBPBalance = "Y".equals(para[i].getParameter());
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
* Pocess
|
||||
* @return info
|
||||
* @throws Exception
|
||||
*/
|
||||
protected String doIt () throws Exception
|
||||
{
|
||||
log.info("C_DunningRun_ID=" + p_C_DunningRun_ID + ",R_MailText_ID=" + p_R_MailText_ID
|
||||
+ ", EmailPDF=" + p_EMailPDF + ",IsOnlyIfBPBalance=" + p_IsOnlyIfBPBalance);
|
||||
* 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.process;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.print.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Dunning Letter Print
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DunningPrint.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class DunningPrint extends SvrProcess
|
||||
{
|
||||
/** Mail PDF */
|
||||
private boolean p_EMailPDF = false;
|
||||
/** Mail Template */
|
||||
private int p_R_MailText_ID = 0;
|
||||
/** Dunning Run */
|
||||
private int p_C_DunningRun_ID = 0;
|
||||
/** Print only Outstanding */
|
||||
private boolean p_IsOnlyIfBPBalance = true;
|
||||
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("EMailPDF"))
|
||||
p_EMailPDF = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("R_MailText_ID"))
|
||||
p_R_MailText_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_DunningRun_ID"))
|
||||
p_C_DunningRun_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("IsOnlyIfBPBalance"))
|
||||
p_IsOnlyIfBPBalance = "Y".equals(para[i].getParameter());
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
* Pocess
|
||||
* @return info
|
||||
* @throws Exception
|
||||
*/
|
||||
protected String doIt () throws Exception
|
||||
{
|
||||
log.info("C_DunningRun_ID=" + p_C_DunningRun_ID + ",R_MailText_ID=" + p_R_MailText_ID
|
||||
+ ", EmailPDF=" + p_EMailPDF + ",IsOnlyIfBPBalance=" + p_IsOnlyIfBPBalance);
|
||||
|
||||
// Need to have Template
|
||||
if (p_EMailPDF && p_R_MailText_ID == 0)
|
||||
|
@ -95,122 +95,127 @@ public class DunningPrint extends SvrProcess
|
|||
// Print Format on Dunning Level
|
||||
MDunningLevel level = new MDunningLevel (getCtx(), run.getC_DunningLevel_ID(), get_TrxName());
|
||||
MPrintFormat format = MPrintFormat.get (getCtx(), level.getDunning_PrintFormat_ID(), false);
|
||||
|
||||
MClient client = MClient.get(getCtx());
|
||||
|
||||
int count = 0;
|
||||
int errors = 0;
|
||||
MDunningRunEntry[] entries = run.getEntries(false);
|
||||
for (int i = 0; i < entries.length; i++)
|
||||
{
|
||||
MDunningRunEntry entry = entries[i];
|
||||
if (p_IsOnlyIfBPBalance && entry.getAmt().signum() <= 0)
|
||||
continue;
|
||||
// To BPartner
|
||||
MBPartner bp = new MBPartner (getCtx(), entry.getC_BPartner_ID(), get_TrxName());
|
||||
if (bp.get_ID() == 0)
|
||||
{
|
||||
addLog (entry.get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.getC_BPartner_ID());
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
// To User
|
||||
MUser to = new MUser (getCtx(), entry.getAD_User_ID(), get_TrxName());
|
||||
if (p_EMailPDF)
|
||||
{
|
||||
if (to.get_ID() == 0)
|
||||
{
|
||||
addLog (entry.get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.getName());
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
else if (to.getEMail() == null || to.getEMail().length() == 0)
|
||||
{
|
||||
addLog (entry.get_ID(), null, null, "@NotFound@: @EMail@ - " + to.getName());
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// BP Language
|
||||
Language language = Language.getLoginLanguage(); // Base Language
|
||||
String tableName = "C_Dunning_Header_v";
|
||||
if (client.isMultiLingualDocument())
|
||||
{
|
||||
tableName += "t";
|
||||
String AD_Language = bp.getAD_Language();
|
||||
if (AD_Language != null)
|
||||
language = Language.getLanguage(AD_Language);
|
||||
}
|
||||
format.setLanguage(language);
|
||||
format.setTranslationLanguage(language);
|
||||
// query
|
||||
MQuery query = new MQuery(tableName);
|
||||
query.addRestriction("C_DunningRunEntry_ID", MQuery.EQUAL,
|
||||
new Integer(entry.getC_DunningRunEntry_ID()));
|
||||
|
||||
// Engine
|
||||
PrintInfo info = new PrintInfo(
|
||||
bp.getName(),
|
||||
X_C_DunningRunEntry.Table_ID,
|
||||
entry.getC_DunningRunEntry_ID(),
|
||||
entry.getC_BPartner_ID());
|
||||
info.setDescription(bp.getName() + ", Amt=" + entry.getAmt());
|
||||
ReportEngine re = new ReportEngine(getCtx(), format, query, info);
|
||||
boolean printed = false;
|
||||
if (p_EMailPDF)
|
||||
{
|
||||
EMail email = client.createEMail(to.getEMail(), null, null);
|
||||
if (!email.isValid())
|
||||
{
|
||||
addLog (entry.get_ID(), null, null,
|
||||
"@RequestActionEMailError@ Invalid EMail: " + to);
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
mText.setUser(to); // variable context
|
||||
mText.setBPartner(bp);
|
||||
mText.setPO(entry);
|
||||
String message = mText.getMailText(true);
|
||||
if (mText.isHtml())
|
||||
email.setMessageHTML(mText.getMailHeader(), message);
|
||||
else
|
||||
{
|
||||
email.setSubject (mText.getMailHeader());
|
||||
email.setMessageText (message);
|
||||
}
|
||||
//
|
||||
File attachment = re.getPDF(File.createTempFile("Dunning", ".pdf"));
|
||||
log.fine(to + " - " + attachment);
|
||||
email.addAttachment(attachment);
|
||||
//
|
||||
String msg = email.send();
|
||||
MUserMail um = new MUserMail(mText, entry.getAD_User_ID(), email);
|
||||
um.save();
|
||||
if (msg.equals(EMail.SENT_OK))
|
||||
{
|
||||
addLog (entry.get_ID(), null, null,
|
||||
bp.getName() + " @RequestActionEMailOK@");
|
||||
count++;
|
||||
printed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
addLog (entry.get_ID(), null, null,
|
||||
bp.getName() + " @RequestActionEMailError@ " + msg);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
re.print ();
|
||||
|
||||
MClient client = MClient.get(getCtx());
|
||||
|
||||
int count = 0;
|
||||
int errors = 0;
|
||||
MDunningRunEntry[] entries = run.getEntries(false);
|
||||
for (int i = 0; i < entries.length; i++)
|
||||
{
|
||||
MDunningRunEntry entry = entries[i];
|
||||
if (p_IsOnlyIfBPBalance && entry.getAmt().signum() <= 0)
|
||||
continue;
|
||||
// To BPartner
|
||||
MBPartner bp = new MBPartner (getCtx(), entry.getC_BPartner_ID(), get_TrxName());
|
||||
if (bp.get_ID() == 0)
|
||||
{
|
||||
addLog (entry.get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.getC_BPartner_ID());
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
// To User
|
||||
MUser to = new MUser (getCtx(), entry.getAD_User_ID(), get_TrxName());
|
||||
if (p_EMailPDF)
|
||||
{
|
||||
if (to.get_ID() == 0)
|
||||
{
|
||||
addLog (entry.get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.getName());
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
else if (to.getEMail() == null || to.getEMail().length() == 0)
|
||||
{
|
||||
addLog (entry.get_ID(), null, null, "@NotFound@: @EMail@ - " + to.getName());
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// BP Language
|
||||
Language language = Language.getLoginLanguage(); // Base Language
|
||||
String tableName = "C_Dunning_Header_v";
|
||||
if (client.isMultiLingualDocument())
|
||||
{
|
||||
tableName += "t";
|
||||
String AD_Language = bp.getAD_Language();
|
||||
if (AD_Language != null)
|
||||
language = Language.getLanguage(AD_Language);
|
||||
}
|
||||
format.setLanguage(language);
|
||||
format.setTranslationLanguage(language);
|
||||
// query
|
||||
MQuery query = new MQuery(tableName);
|
||||
query.addRestriction("C_DunningRunEntry_ID", MQuery.EQUAL,
|
||||
new Integer(entry.getC_DunningRunEntry_ID()));
|
||||
|
||||
// Engine
|
||||
PrintInfo info = new PrintInfo(
|
||||
bp.getName(),
|
||||
X_C_DunningRunEntry.Table_ID,
|
||||
entry.getC_DunningRunEntry_ID(),
|
||||
entry.getC_BPartner_ID());
|
||||
info.setDescription(bp.getName() + ", Amt=" + entry.getAmt());
|
||||
ReportEngine re = new ReportEngine(getCtx(), format, query, info);
|
||||
boolean printed = false;
|
||||
if (p_EMailPDF)
|
||||
{
|
||||
EMail email = client.createEMail(to.getEMail(), null, null);
|
||||
if (!email.isValid())
|
||||
{
|
||||
addLog (entry.get_ID(), null, null,
|
||||
"@RequestActionEMailError@ Invalid EMail: " + to);
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
mText.setUser(to); // variable context
|
||||
mText.setBPartner(bp);
|
||||
mText.setPO(entry);
|
||||
String message = mText.getMailText(true);
|
||||
if (mText.isHtml())
|
||||
email.setMessageHTML(mText.getMailHeader(), message);
|
||||
else
|
||||
{
|
||||
email.setSubject (mText.getMailHeader());
|
||||
email.setMessageText (message);
|
||||
}
|
||||
//
|
||||
File attachment = re.getPDF(File.createTempFile("Dunning", ".pdf"));
|
||||
log.fine(to + " - " + attachment);
|
||||
email.addAttachment(attachment);
|
||||
//
|
||||
String msg = email.send();
|
||||
MUserMail um = new MUserMail(mText, entry.getAD_User_ID(), email);
|
||||
um.save();
|
||||
if (msg.equals(EMail.SENT_OK))
|
||||
{
|
||||
addLog (entry.get_ID(), null, null,
|
||||
bp.getName() + " @RequestActionEMailOK@");
|
||||
count++;
|
||||
printed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
addLog (entry.get_ID(), null, null,
|
||||
bp.getName() + " @RequestActionEMailError@ " + msg);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
re.print ();
|
||||
count++;
|
||||
printed = true;
|
||||
}
|
||||
if (printed)
|
||||
{
|
||||
entry.setProcessed (true);
|
||||
entry.save ();
|
||||
}
|
||||
|
||||
} // for all dunning letters
|
||||
if (p_EMailPDF)
|
||||
return "@Sent@=" + count + " - @Errors@=" + errors;
|
||||
return "@Printed@=" + count;
|
||||
} // doIt
|
||||
|
||||
} // DunningPrint
|
||||
return "@Sent@=" + count + " - @Errors@=" + errors;
|
||||
return "@Printed@=" + count;
|
||||
} // doIt
|
||||
|
||||
} // DunningPrint
|
||||
|
|
|
@ -3,350 +3,395 @@
|
|||
* 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.process;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Create Dunning Run Entries/Lines
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DunningRunCreate.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class DunningRunCreate extends SvrProcess
|
||||
* 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.process;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Create Dunning Run Entries/Lines
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: DunningRunCreate.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class DunningRunCreate extends SvrProcess
|
||||
{
|
||||
private boolean p_IncludeInDispute = false;
|
||||
private boolean p_OnlySOTrx = false;
|
||||
private boolean p_IsAllCurrencies = false;
|
||||
private int p_SalesRep_ID = 0;
|
||||
private int p_C_Currency_ID = 0;
|
||||
private int p_C_BPartner_ID = 0;
|
||||
private int p_C_BP_Group_ID = 0;
|
||||
private int p_C_BP_Group_ID = 0;
|
||||
private int p_C_DunningRun_ID = 0;
|
||||
|
||||
private MDunningRun m_run = null;
|
||||
private MDunningLevel m_level = null;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("IncludeInDispute"))
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("IncludeInDispute"))
|
||||
p_IncludeInDispute = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("OnlySOTrx"))
|
||||
p_OnlySOTrx = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("IsAllCurrencies"))
|
||||
p_IsAllCurrencies = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("SalesRep_ID"))
|
||||
p_SalesRep_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_Currency_ID"))
|
||||
p_C_Currency_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_BPartner_ID"))
|
||||
p_C_BPartner_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_BP_Group_ID"))
|
||||
p_C_BP_Group_ID = para[i].getParameterAsInt();
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
p_C_DunningRun_ID = getRecord_ID();
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
* Process
|
||||
* @return message
|
||||
* @throws Exception
|
||||
*/
|
||||
protected String doIt () throws Exception
|
||||
{
|
||||
log.info("C_DunningRun_ID=" + p_C_DunningRun_ID
|
||||
+ ", Dispute=" + p_IncludeInDispute
|
||||
+ ", C_BP_Group_ID=" + p_C_BP_Group_ID
|
||||
+ ", C_BPartner_ID=" + p_C_BPartner_ID);
|
||||
m_run = new MDunningRun (getCtx(),p_C_DunningRun_ID, get_TrxName());
|
||||
if (m_run.get_ID() == 0)
|
||||
throw new IllegalArgumentException ("Not found MDunningRun");
|
||||
if (!m_run.deleteEntries(true))
|
||||
throw new IllegalArgumentException ("Cannot delete existing entries");
|
||||
if (p_SalesRep_ID == 0)
|
||||
throw new IllegalArgumentException ("No SalesRep");
|
||||
p_C_Currency_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_BPartner_ID"))
|
||||
p_C_BPartner_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_BP_Group_ID"))
|
||||
p_C_BP_Group_ID = para[i].getParameterAsInt();
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
p_C_DunningRun_ID = getRecord_ID();
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
* Process
|
||||
* @return message
|
||||
* @throws Exception
|
||||
*/
|
||||
protected String doIt () throws Exception
|
||||
{
|
||||
log.info("C_DunningRun_ID=" + p_C_DunningRun_ID
|
||||
+ ", Dispute=" + p_IncludeInDispute
|
||||
+ ", C_BP_Group_ID=" + p_C_BP_Group_ID
|
||||
+ ", C_BPartner_ID=" + p_C_BPartner_ID);
|
||||
m_run = new MDunningRun (getCtx(),p_C_DunningRun_ID, get_TrxName());
|
||||
if (m_run.get_ID() == 0)
|
||||
throw new IllegalArgumentException ("Not found MDunningRun");
|
||||
if (!m_run.deleteEntries(true))
|
||||
throw new IllegalArgumentException ("Cannot delete existing entries");
|
||||
if (p_SalesRep_ID == 0)
|
||||
throw new IllegalArgumentException ("No SalesRep");
|
||||
if (p_C_Currency_ID == 0)
|
||||
throw new IllegalArgumentException ("No Currency");
|
||||
//
|
||||
m_level = m_run.getLevel ();
|
||||
|
||||
int inv = addInvoices();
|
||||
int pay = addPayments();
|
||||
|
||||
if (m_level.isChargeFee ())
|
||||
addFees();
|
||||
|
||||
return "@C_Invoice_ID@ #" + inv + " - @C_Payment_ID@=" + pay;
|
||||
} // doIt
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Add Invoices to Run
|
||||
* @return no of invoices
|
||||
*/
|
||||
private int addInvoices()
|
||||
{
|
||||
int count = 0;
|
||||
String sql = "SELECT i.C_Invoice_ID, i.C_Currency_ID,"
|
||||
+ " i.GrandTotal*i.MultiplierAP,"
|
||||
+ " invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID)*MultiplierAP,"
|
||||
+ " COALESCE(daysBetween(?,ips.DueDate),paymentTermDueDays(i.C_PaymentTerm_ID,i.DateInvoiced,?))," // ##1/2
|
||||
+ " i.IsInDispute, i.C_BPartner_ID "
|
||||
+ "FROM C_Invoice_v i "
|
||||
+ " LEFT OUTER JOIN C_InvoicePaySchedule ips ON (i.C_InvoicePaySchedule_ID=ips.C_InvoicePaySchedule_ID) "
|
||||
+ "WHERE i.IsPaid='N' AND i.AD_Client_ID=?" // ##3
|
||||
+ " AND i.DocStatus IN ('CO','CL')"
|
||||
// Only BP(Group) with Dunning defined
|
||||
+ " AND EXISTS (SELECT * FROM C_DunningLevel dl "
|
||||
+ "WHERE dl.C_DunningLevel_ID=?" // // ##4
|
||||
+ " AND dl.C_Dunning_ID IN "
|
||||
+ "(SELECT COALESCE(bp.C_Dunning_ID, bpg.C_Dunning_ID) "
|
||||
+ "FROM C_BPartner bp"
|
||||
+ " INNER JOIN C_BP_Group bpg ON (bp.C_BP_Group_ID=bpg.C_BP_Group_ID) "
|
||||
+ "WHERE i.C_BPartner_ID=bp.C_BPartner_ID))";
|
||||
if (p_C_BPartner_ID != 0)
|
||||
sql += " AND i.C_BPartner_ID=?"; // ##5
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
sql += " AND EXISTS (SELECT * FROM C_BPartner bp "
|
||||
|
||||
/**************************************************************************
|
||||
* Add Invoices to Run
|
||||
* @return no of invoices
|
||||
*/
|
||||
private int addInvoices()
|
||||
{
|
||||
int count = 0;
|
||||
String sql = "SELECT i.C_Invoice_ID, i.C_Currency_ID,"
|
||||
+ " i.GrandTotal*i.MultiplierAP,"
|
||||
+ " invoiceOpen(i.C_Invoice_ID,i.C_InvoicePaySchedule_ID)*MultiplierAP,"
|
||||
+ " COALESCE(daysBetween(?,ips.DueDate),paymentTermDueDays(i.C_PaymentTerm_ID,i.DateInvoiced,?))," // ##1/2
|
||||
+ " i.IsInDispute, i.C_BPartner_ID "
|
||||
+ "FROM C_Invoice_v i "
|
||||
+ " LEFT OUTER JOIN C_InvoicePaySchedule ips ON (i.C_InvoicePaySchedule_ID=ips.C_InvoicePaySchedule_ID) "
|
||||
+ "WHERE i.IsPaid='N' AND i.AD_Client_ID=?" // ##3
|
||||
+ " AND i.DocStatus IN ('CO','CL')"
|
||||
// Only BP(Group) with Dunning defined
|
||||
+ " AND EXISTS (SELECT * FROM C_DunningLevel dl "
|
||||
+ "WHERE dl.C_DunningLevel_ID=?" // // ##4
|
||||
+ " AND dl.C_Dunning_ID IN "
|
||||
+ "(SELECT COALESCE(bp.C_Dunning_ID, bpg.C_Dunning_ID) "
|
||||
+ "FROM C_BPartner bp"
|
||||
+ " INNER JOIN C_BP_Group bpg ON (bp.C_BP_Group_ID=bpg.C_BP_Group_ID) "
|
||||
+ "WHERE i.C_BPartner_ID=bp.C_BPartner_ID))";
|
||||
if (p_C_BPartner_ID != 0)
|
||||
sql += " AND i.C_BPartner_ID=?"; // ##5
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
sql += " AND EXISTS (SELECT * FROM C_BPartner bp "
|
||||
+ "WHERE i.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)"; // ##5
|
||||
if (p_OnlySOTrx)
|
||||
sql += " AND i.IsSOTrx='Y'";
|
||||
if (!p_IsAllCurrencies)
|
||||
sql += " AND i.C_Currency_ID=" + p_C_Currency_ID;
|
||||
// log.info(sql);
|
||||
|
||||
// Sub Query
|
||||
String sql2 = "SELECT COUNT(*), COALESCE(TRUNC(SysDate-MAX(dr.DunningDate)),0) "
|
||||
|
||||
String sql2=null;
|
||||
|
||||
// if sequentially we must check for other levels with smaller days for
|
||||
// which this invoice is not yet included!
|
||||
if (m_level.getParent ().isCreateLevelsSequentially ()) {
|
||||
// Build a list of all topmost Dunning Levels
|
||||
MDunningLevel[] previousLevels = m_level.getPreviousLevels();
|
||||
if (previousLevels!=null && previousLevels.length>0) {
|
||||
String sqlAppend = "";
|
||||
for (int i=0; i<previousLevels.length; i++)
|
||||
{
|
||||
sqlAppend += " AND i.C_Invoice_ID IN (SELECT C_Invoice_ID FROM C_DunningRunLine WHERE " +
|
||||
"C_DunningRunEntry_ID IN (SELECT C_DunningRunEntry_ID FROM C_DunningRunEntry WHERE " +
|
||||
"C_DunningRun_ID IN (SELECT C_DunningRun_ID FROM C_DunningRun WHERE " +
|
||||
"C_DunningLevel_ID=" + previousLevels[i].get_ID () + ")) AND Processed<>'N')";
|
||||
}
|
||||
sql += sqlAppend;
|
||||
}
|
||||
}
|
||||
sql2 = "SELECT COUNT(*), COALESCE(TRUNC(SysDate-MAX(dr.DunningDate)),0) "
|
||||
+ "FROM C_DunningRun dr"
|
||||
+ " INNER JOIN C_DunningRunEntry dre ON (dr.C_DunningRun_ID=dre.C_DunningRun_ID)"
|
||||
+ " INNER JOIN C_DunningRunLine drl ON (dre.C_DunningRunEntry_ID=drl.C_DunningRunEntry_ID) "
|
||||
+ "WHERE drl.Processed='Y' AND drl.C_Invoice_ID=?";
|
||||
|
||||
|
||||
BigDecimal DaysAfterDue = m_run.getLevel().getDaysAfterDue();
|
||||
int DaysBetweenDunning = m_run.getLevel().getDaysBetweenDunning();
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
PreparedStatement pstmt2 = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
pstmt.setTimestamp(1, m_run.getDunningDate());
|
||||
pstmt.setTimestamp(2, m_run.getDunningDate());
|
||||
pstmt.setInt (3, m_run.getAD_Client_ID());
|
||||
pstmt.setInt(4, m_run.getC_DunningLevel_ID());
|
||||
if (p_C_BPartner_ID != 0)
|
||||
pstmt.setInt (5, p_C_BPartner_ID);
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
pstmt.setInt (5, p_C_BP_Group_ID);
|
||||
//
|
||||
pstmt2 = DB.prepareStatement (sql2, get_TrxName());
|
||||
//
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
int C_Invoice_ID = rs.getInt(1);
|
||||
int C_Currency_ID = rs.getInt(2);
|
||||
BigDecimal GrandTotal = rs.getBigDecimal(3);
|
||||
BigDecimal Open = rs.getBigDecimal(4);
|
||||
int DaysDue = rs.getInt(5);
|
||||
boolean IsInDispute = "Y".equals(rs.getString(6));
|
||||
int C_BPartner_ID = rs.getInt(7);
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
PreparedStatement pstmt2 = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
pstmt.setTimestamp(1, m_run.getDunningDate());
|
||||
pstmt.setTimestamp(2, m_run.getDunningDate());
|
||||
pstmt.setInt (3, m_run.getAD_Client_ID());
|
||||
pstmt.setInt(4, m_run.getC_DunningLevel_ID());
|
||||
if (p_C_BPartner_ID != 0)
|
||||
pstmt.setInt (5, p_C_BPartner_ID);
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
pstmt.setInt (5, p_C_BP_Group_ID);
|
||||
//
|
||||
pstmt2 = DB.prepareStatement (sql2, get_TrxName());
|
||||
//
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
int C_Invoice_ID = rs.getInt(1);
|
||||
int C_Currency_ID = rs.getInt(2);
|
||||
BigDecimal GrandTotal = rs.getBigDecimal(3);
|
||||
BigDecimal Open = rs.getBigDecimal(4);
|
||||
int DaysDue = rs.getInt(5);
|
||||
boolean IsInDispute = "Y".equals(rs.getString(6));
|
||||
int C_BPartner_ID = rs.getInt(7);
|
||||
//
|
||||
if (!p_IncludeInDispute && IsInDispute)
|
||||
continue;
|
||||
if (DaysDue < DaysAfterDue.intValue())
|
||||
if (DaysDue < DaysAfterDue.intValue() && !m_level.isShowAllDue ())
|
||||
continue;
|
||||
if (Env.ZERO.compareTo(Open) == 0)
|
||||
continue;
|
||||
//
|
||||
int TimesDunned = 0;
|
||||
int DaysAfterLast = 0;
|
||||
// SubQuery
|
||||
pstmt2.setInt (1, C_Invoice_ID);
|
||||
ResultSet rs2 = pstmt2.executeQuery ();
|
||||
if (rs2.next())
|
||||
{
|
||||
TimesDunned = rs2.getInt(1);
|
||||
DaysAfterLast = rs2.getInt(2);
|
||||
//
|
||||
int TimesDunned = 0;
|
||||
int DaysAfterLast = 0;
|
||||
// SubQuery
|
||||
pstmt2.setInt (1, C_Invoice_ID);
|
||||
ResultSet rs2 = pstmt2.executeQuery ();
|
||||
if (rs2.next())
|
||||
{
|
||||
TimesDunned = rs2.getInt(1);
|
||||
DaysAfterLast = rs2.getInt(2);
|
||||
}
|
||||
rs2.close();
|
||||
// SubQuery
|
||||
if (DaysBetweenDunning != 0 && DaysAfterLast < DaysBetweenDunning)
|
||||
|
||||
if (DaysBetweenDunning != 0 && DaysAfterLast < DaysBetweenDunning && !m_level.isShowAllDue () && !m_level.isShowNotDue ())
|
||||
continue;
|
||||
//
|
||||
createInvoiceLine (C_Invoice_ID, C_Currency_ID, GrandTotal, Open,
|
||||
DaysDue, IsInDispute, C_BPartner_ID,
|
||||
TimesDunned, DaysAfterLast);
|
||||
count++;
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
pstmt2.close();
|
||||
pstmt2 = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "addInvoices", e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
if (pstmt2 != null)
|
||||
pstmt2.close ();
|
||||
pstmt = null;
|
||||
pstmt2 = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
pstmt2 = null;
|
||||
}
|
||||
return count;
|
||||
} // addInvoices
|
||||
|
||||
/**
|
||||
* Create Invoice Line
|
||||
* @param C_Invoice_ID
|
||||
* @param C_Currency_ID
|
||||
* @param GrandTotal
|
||||
* @param Open
|
||||
* @param DaysDue
|
||||
* @param IsInDispute
|
||||
* @param C_BPartner_ID
|
||||
* @param TimesDunned
|
||||
* @param DaysAfterLast
|
||||
*/
|
||||
private void createInvoiceLine (int C_Invoice_ID, int C_Currency_ID,
|
||||
BigDecimal GrandTotal, BigDecimal Open,
|
||||
int DaysDue, boolean IsInDispute,
|
||||
int C_BPartner_ID, int TimesDunned, int DaysAfterLast)
|
||||
{
|
||||
MDunningRunEntry entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID);
|
||||
if (entry.get_ID() == 0)
|
||||
if (!entry.save())
|
||||
throw new IllegalStateException("Cannot save MDunningRunEntry");
|
||||
DaysDue, IsInDispute, C_BPartner_ID,
|
||||
TimesDunned, DaysAfterLast);
|
||||
count++;
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
pstmt2.close();
|
||||
pstmt2 = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "addInvoices", e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
if (pstmt2 != null)
|
||||
pstmt2.close ();
|
||||
pstmt = null;
|
||||
pstmt2 = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
pstmt2 = null;
|
||||
}
|
||||
return count;
|
||||
} // addInvoices
|
||||
|
||||
/**
|
||||
* Create Invoice Line
|
||||
* @param C_Invoice_ID
|
||||
* @param C_Currency_ID
|
||||
* @param GrandTotal
|
||||
* @param Open
|
||||
* @param DaysDue
|
||||
* @param IsInDispute
|
||||
* @param C_BPartner_ID
|
||||
* @param TimesDunned
|
||||
* @param DaysAfterLast
|
||||
*/
|
||||
private void createInvoiceLine (int C_Invoice_ID, int C_Currency_ID,
|
||||
BigDecimal GrandTotal, BigDecimal Open,
|
||||
int DaysDue, boolean IsInDispute,
|
||||
int C_BPartner_ID, int TimesDunned, int DaysAfterLast)
|
||||
{
|
||||
MDunningRunEntry entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID);
|
||||
if (entry.get_ID() == 0)
|
||||
if (!entry.save())
|
||||
throw new IllegalStateException("Cannot save MDunningRunEntry");
|
||||
//
|
||||
MDunningRunLine line = new MDunningRunLine (entry);
|
||||
line.setInvoice(C_Invoice_ID, C_Currency_ID, GrandTotal, Open,
|
||||
DaysDue, IsInDispute, TimesDunned, DaysAfterLast);
|
||||
new BigDecimal(0), DaysDue, IsInDispute, TimesDunned,
|
||||
DaysAfterLast);
|
||||
if (!line.save())
|
||||
throw new IllegalStateException("Cannot save MDunningRunLine");
|
||||
} // createInvoiceLine
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Add Payments to Run
|
||||
* @return no of payments
|
||||
*/
|
||||
private int addPayments()
|
||||
{
|
||||
String sql = "SELECT C_Payment_ID, C_Currency_ID, PayAmt,"
|
||||
+ " paymentAvailable(C_Payment_ID), C_BPartner_ID "
|
||||
+ "FROM C_Payment_v p "
|
||||
+ "WHERE AD_Client_ID=?" // ##1
|
||||
+ " AND IsAllocated='N' AND C_BPartner_ID IS NOT NULL"
|
||||
+ " AND C_Charge_ID IS NULL"
|
||||
+ " AND DocStatus IN ('CO','CL')"
|
||||
// Only BP with Dunning defined
|
||||
+ " AND EXISTS (SELECT * FROM C_BPartner bp "
|
||||
+ "WHERE p.C_BPartner_ID=bp.C_BPartner_ID"
|
||||
+ " AND bp.C_Dunning_ID=(SELECT C_Dunning_ID FROM C_DunningLevel WHERE C_DunningLevel_ID=?))"; // ##2
|
||||
if (p_C_BPartner_ID != 0)
|
||||
sql += " AND C_BPartner_ID=?"; // ##3
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
sql += " AND EXISTS (SELECT * FROM C_BPartner bp "
|
||||
+ "WHERE p.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)"; // ##3
|
||||
if (p_OnlySOTrx)
|
||||
sql += " AND IsReceipt='Y'";
|
||||
|
||||
int count = 0;
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
pstmt.setInt (1, getAD_Client_ID());
|
||||
pstmt.setInt (2, m_run.getC_DunningLevel_ID());
|
||||
if (p_C_BPartner_ID != 0)
|
||||
pstmt.setInt (3, p_C_BPartner_ID);
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
pstmt.setInt (3, p_C_BP_Group_ID);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
int C_Payment_ID = rs.getInt(1);
|
||||
int C_Currency_ID = rs.getInt(2);
|
||||
BigDecimal PayAmt = rs.getBigDecimal(3).negate();
|
||||
BigDecimal OpenAmt = rs.getBigDecimal(4).negate();
|
||||
int C_BPartner_ID = rs.getInt(5);
|
||||
//
|
||||
if (Env.ZERO.compareTo(OpenAmt) == 0)
|
||||
continue;
|
||||
//
|
||||
createPaymentLine (C_Payment_ID, C_Currency_ID, PayAmt, OpenAmt,
|
||||
C_BPartner_ID);
|
||||
count++;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return count;
|
||||
} // addPayments
|
||||
|
||||
/**
|
||||
* Create Payment Line
|
||||
* @param C_Payment_ID
|
||||
* @param C_Currency_ID
|
||||
* @param PayAmt
|
||||
* @param OpenAmt
|
||||
* @param C_BPartner_ID
|
||||
*/
|
||||
private void createPaymentLine (int C_Payment_ID, int C_Currency_ID,
|
||||
BigDecimal PayAmt, BigDecimal OpenAmt, int C_BPartner_ID)
|
||||
{
|
||||
MDunningRunEntry entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID);
|
||||
if (entry.get_ID() == 0)
|
||||
if (!entry.save())
|
||||
throw new IllegalStateException("Cannot save MDunningRunEntry");
|
||||
//
|
||||
MDunningRunLine line = new MDunningRunLine (entry);
|
||||
line.setPayment(C_Payment_ID, C_Currency_ID, PayAmt, OpenAmt);
|
||||
if (!line.save())
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Add Payments to Run
|
||||
* @return no of payments
|
||||
*/
|
||||
private int addPayments()
|
||||
{
|
||||
String sql = "SELECT C_Payment_ID, C_Currency_ID, PayAmt,"
|
||||
+ " paymentAvailable(C_Payment_ID), C_BPartner_ID "
|
||||
+ "FROM C_Payment_v p "
|
||||
+ "WHERE AD_Client_ID=?" // ##1
|
||||
+ " AND IsAllocated='N' AND C_BPartner_ID IS NOT NULL"
|
||||
+ " AND C_Charge_ID IS NULL"
|
||||
+ " AND DocStatus IN ('CO','CL')"
|
||||
// Only BP with Dunning defined
|
||||
+ " AND EXISTS (SELECT * FROM C_BPartner bp "
|
||||
+ "WHERE p.C_BPartner_ID=bp.C_BPartner_ID"
|
||||
+ " AND bp.C_Dunning_ID=(SELECT C_Dunning_ID FROM C_DunningLevel WHERE C_DunningLevel_ID=?))"; // ##2
|
||||
if (p_C_BPartner_ID != 0)
|
||||
sql += " AND C_BPartner_ID=?"; // ##3
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
sql += " AND EXISTS (SELECT * FROM C_BPartner bp "
|
||||
+ "WHERE p.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)"; // ##3
|
||||
if (p_OnlySOTrx)
|
||||
sql += " AND IsReceipt='Y'";
|
||||
|
||||
int count = 0;
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
pstmt.setInt (1, getAD_Client_ID());
|
||||
pstmt.setInt (2, m_run.getC_DunningLevel_ID());
|
||||
if (p_C_BPartner_ID != 0)
|
||||
pstmt.setInt (3, p_C_BPartner_ID);
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
pstmt.setInt (3, p_C_BP_Group_ID);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
int C_Payment_ID = rs.getInt(1);
|
||||
int C_Currency_ID = rs.getInt(2);
|
||||
BigDecimal PayAmt = rs.getBigDecimal(3).negate();
|
||||
BigDecimal OpenAmt = rs.getBigDecimal(4).negate();
|
||||
int C_BPartner_ID = rs.getInt(5);
|
||||
//
|
||||
if (Env.ZERO.compareTo(OpenAmt) == 0)
|
||||
continue;
|
||||
//
|
||||
createPaymentLine (C_Payment_ID, C_Currency_ID, PayAmt, OpenAmt,
|
||||
C_BPartner_ID);
|
||||
count++;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return count;
|
||||
} // addPayments
|
||||
|
||||
/**
|
||||
* Create Payment Line
|
||||
* @param C_Payment_ID
|
||||
* @param C_Currency_ID
|
||||
* @param PayAmt
|
||||
* @param OpenAmt
|
||||
* @param C_BPartner_ID
|
||||
*/
|
||||
private void createPaymentLine (int C_Payment_ID, int C_Currency_ID,
|
||||
BigDecimal PayAmt, BigDecimal OpenAmt, int C_BPartner_ID)
|
||||
{
|
||||
MDunningRunEntry entry = m_run.getEntry (C_BPartner_ID, p_C_Currency_ID, p_SalesRep_ID);
|
||||
if (entry.get_ID() == 0)
|
||||
if (!entry.save())
|
||||
throw new IllegalStateException("Cannot save MDunningRunEntry");
|
||||
//
|
||||
MDunningRunLine line = new MDunningRunLine (entry);
|
||||
line.setPayment(C_Payment_ID, C_Currency_ID, PayAmt, OpenAmt);
|
||||
if (!line.save())
|
||||
throw new IllegalStateException("Cannot save MDunningRunLine");
|
||||
} // createPaymentLine
|
||||
|
||||
private void addFees()
|
||||
{
|
||||
MDunningRunEntry [] entries = m_run.getEntries (true);
|
||||
if (entries!=null && entries.length>0) {
|
||||
for (int i=0;i<entries.length;i++) {
|
||||
MDunningRunLine line = new MDunningRunLine (entries[i]);
|
||||
line.setFee (p_C_Currency_ID, m_level.getFeeAmt ());
|
||||
if (!line.save())
|
||||
throw new IllegalStateException("Cannot save MDunningRunLine");
|
||||
entries[i].setQty (entries[i].getQty ().subtract (new BigDecimal(1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // DunningRunCreate
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
* 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. *
|
||||
* 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 *
|
||||
|
@ -17,511 +17,511 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.process;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Import BPartners from I_BPartner
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: ImportBPartner.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class ImportBPartner extends SvrProcess
|
||||
{
|
||||
/** Client to be imported to */
|
||||
private int m_AD_Client_ID = 0;
|
||||
/** Delete old Imported */
|
||||
private boolean m_deleteOldImported = false;
|
||||
|
||||
/** Organization to be imported to */
|
||||
private int m_AD_Org_ID = 0;
|
||||
/** Effective */
|
||||
private Timestamp m_DateValue = null;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (name.equals("AD_Client_ID"))
|
||||
m_AD_Client_ID = ((BigDecimal)para[i].getParameter()).intValue();
|
||||
else if (name.equals("DeleteOldImported"))
|
||||
m_deleteOldImported = "Y".equals(para[i].getParameter());
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
if (m_DateValue == null)
|
||||
m_DateValue = new Timestamp (System.currentTimeMillis());
|
||||
} // prepare
|
||||
|
||||
|
||||
/**
|
||||
* Perrform process.
|
||||
* @return Message
|
||||
* @throws Exception
|
||||
*/
|
||||
protected String doIt() throws java.lang.Exception
|
||||
{
|
||||
StringBuffer sql = null;
|
||||
int no = 0;
|
||||
String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID;
|
||||
|
||||
// **** Prepare ****
|
||||
|
||||
// Delete Old Imported
|
||||
if (m_deleteOldImported)
|
||||
{
|
||||
sql = new StringBuffer ("DELETE I_BPartner "
|
||||
+ "WHERE I_IsImported='Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Delete Old Impored =" + no);
|
||||
}
|
||||
|
||||
// Set Client, Org, IsActive, Created/Updated
|
||||
sql = new StringBuffer ("UPDATE I_BPartner "
|
||||
+ "SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),"
|
||||
+ " AD_Org_ID = COALESCE (AD_Org_ID, 0),"
|
||||
+ " IsActive = COALESCE (IsActive, 'Y'),"
|
||||
+ " Created = COALESCE (Created, SysDate),"
|
||||
+ " CreatedBy = COALESCE (CreatedBy, 0),"
|
||||
+ " Updated = COALESCE (Updated, SysDate),"
|
||||
+ " UpdatedBy = COALESCE (UpdatedBy, 0),"
|
||||
+ " I_ErrorMsg = NULL,"
|
||||
+ " I_IsImported = 'N' "
|
||||
+ "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Reset=" + no);
|
||||
|
||||
// Set BP_Group
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET GroupValue=(SELECT Value FROM C_BP_Group g WHERE g.IsDefault='Y'"
|
||||
+ " AND g.AD_Client_ID=i.AD_Client_ID AND ROWNUM=1) "
|
||||
+ "WHERE GroupValue IS NULL AND C_BP_Group_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Group Default=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_BP_Group_ID=(SELECT C_BP_Group_ID FROM C_BP_Group g"
|
||||
+ " WHERE i.GroupValue=g.Value AND g.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE C_BP_Group_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Group=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Group, ' "
|
||||
+ "WHERE C_BP_Group_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.config("Invalid Group=" + no);
|
||||
|
||||
// Set Country
|
||||
/**
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET CountryCode=(SELECT CountryCode FROM C_Country c WHERE c.IsDefault='Y'"
|
||||
+ " AND c.AD_Client_ID IN (0, i.AD_Client_ID) AND ROWNUM=1) "
|
||||
+ "WHERE CountryCode IS NULL AND C_Country_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Country Default=" + no);
|
||||
**/
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_Country_ID=(SELECT C_Country_ID FROM C_Country c"
|
||||
+ " WHERE i.CountryCode=c.CountryCode AND c.AD_Client_ID IN (0, i.AD_Client_ID)) "
|
||||
+ "WHERE C_Country_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Country=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Country, ' "
|
||||
+ "WHERE C_Country_ID IS NULL AND (City IS NOT NULL OR Address1 IS NOT NULL)"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.config("Invalid Country=" + no);
|
||||
|
||||
// Set Region
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "Set RegionName=(SELECT Name FROM C_Region r"
|
||||
+ " WHERE r.IsDefault='Y' AND r.C_Country_ID=i.C_Country_ID"
|
||||
+ " AND r.AD_Client_ID IN (0, i.AD_Client_ID) AND ROWNUM=1) "
|
||||
+ "WHERE RegionName IS NULL AND C_Region_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Region Default=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "Set C_Region_ID=(SELECT C_Region_ID FROM C_Region r"
|
||||
+ " WHERE r.Name=i.RegionName AND r.C_Country_ID=i.C_Country_ID"
|
||||
+ " AND r.AD_Client_ID IN (0, i.AD_Client_ID)) "
|
||||
+ "WHERE C_Region_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Region=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Region, ' "
|
||||
+ "WHERE C_Region_ID IS NULL "
|
||||
+ " AND EXISTS (SELECT * FROM C_Country c"
|
||||
+ " WHERE c.C_Country_ID=i.C_Country_ID AND c.HasRegion='Y')"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.config("Invalid Region=" + no);
|
||||
|
||||
// Set Greeting
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_Greeting_ID=(SELECT C_Greeting_ID FROM C_Greeting g"
|
||||
+ " WHERE i.BPContactGreeting=g.Name AND g.AD_Client_ID IN (0, i.AD_Client_ID)) "
|
||||
+ "WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Greeting=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Greeting, ' "
|
||||
+ "WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.config("Invalid Greeting=" + no);
|
||||
|
||||
// Existing User ?
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET (C_BPartner_ID,AD_User_ID)="
|
||||
+ "(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u "
|
||||
+ "WHERE i.EMail=u.EMail AND u.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE i.EMail IS NOT NULL AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Found EMail User=" + no);
|
||||
|
||||
// Existing BPartner ? Match Value
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner p"
|
||||
+ " WHERE i.Value=p.Value AND p.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE C_BPartner_ID IS NULL AND Value IS NOT NULL"
|
||||
+ " AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Found BPartner=" + no);
|
||||
|
||||
// Existing Contact ? Match Name
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET AD_User_ID=(SELECT AD_User_ID FROM AD_User c"
|
||||
+ " WHERE i.ContactName=c.Name AND i.C_BPartner_ID=c.C_BPartner_ID AND c.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE C_BPartner_ID IS NOT NULL AND AD_User_ID IS NULL AND ContactName IS NOT NULL"
|
||||
+ " AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Found Contact=" + no);
|
||||
|
||||
// Existing Location ? Exact Match
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_BPartner_Location_ID=(SELECT C_BPartner_Location_ID"
|
||||
+ " FROM C_BPartner_Location bpl INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)"
|
||||
+ " WHERE i.C_BPartner_ID=bpl.C_BPartner_ID AND bpl.AD_Client_ID=i.AD_Client_ID"
|
||||
+ " AND DUMP(i.Address1)=DUMP(l.Address1) AND DUMP(i.Address2)=DUMP(l.Address2)"
|
||||
+ " AND DUMP(i.City)=DUMP(l.City) AND DUMP(i.Postal)=DUMP(l.Postal) AND DUMP(i.Postal_Add)=DUMP(l.Postal_Add)"
|
||||
+ " AND DUMP(i.C_Region_ID)=DUMP(l.C_Region_ID) AND DUMP(i.C_Country_ID)=DUMP(l.C_Country_ID)) "
|
||||
+ "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL"
|
||||
+ " AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Found Location=" + no);
|
||||
|
||||
// Interest Area
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET R_InterestArea_ID=(SELECT R_InterestArea_ID FROM R_InterestArea ia "
|
||||
+ "WHERE i.InterestAreaName=ia.Name AND ia.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE R_InterestArea_ID IS NULL AND InterestAreaName IS NOT NULL"
|
||||
+ " AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Interest Area=" + no);
|
||||
|
||||
|
||||
commit();
|
||||
// -------------------------------------------------------------------
|
||||
int noInsert = 0;
|
||||
int noUpdate = 0;
|
||||
|
||||
// Go through Records
|
||||
sql = new StringBuffer ("SELECT * FROM I_BPartner "
|
||||
+ "WHERE I_IsImported='N'").append(clientCheck);
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
X_I_BPartner impBP = new X_I_BPartner (getCtx(), rs, get_TrxName());
|
||||
log.fine("I_BPartner_ID=" + impBP.getI_BPartner_ID()
|
||||
+ ", C_BPartner_ID=" + impBP.getC_BPartner_ID()
|
||||
+ ", C_BPartner_Location_ID=" + impBP.getC_BPartner_Location_ID()
|
||||
+ ", AD_User_ID=" + impBP.getAD_User_ID());
|
||||
|
||||
|
||||
// **** Create/Update BPartner ****
|
||||
MBPartner bp = null;
|
||||
if (impBP.getC_BPartner_ID() == 0) // Insert new BPartner
|
||||
{
|
||||
bp = new MBPartner(impBP);
|
||||
if (bp.save())
|
||||
{
|
||||
impBP.setC_BPartner_ID(bp.getC_BPartner_ID());
|
||||
log.finest("Insert BPartner - " + bp.getC_BPartner_ID());
|
||||
noInsert++;
|
||||
}
|
||||
else
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Import BPartners from I_BPartner
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: ImportBPartner.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class ImportBPartner extends SvrProcess
|
||||
{
|
||||
/** Client to be imported to */
|
||||
private int m_AD_Client_ID = 0;
|
||||
/** Delete old Imported */
|
||||
private boolean m_deleteOldImported = false;
|
||||
|
||||
/** Organization to be imported to */
|
||||
private int m_AD_Org_ID = 0;
|
||||
/** Effective */
|
||||
private Timestamp m_DateValue = null;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (name.equals("AD_Client_ID"))
|
||||
m_AD_Client_ID = ((BigDecimal)para[i].getParameter()).intValue();
|
||||
else if (name.equals("DeleteOldImported"))
|
||||
m_deleteOldImported = "Y".equals(para[i].getParameter());
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
if (m_DateValue == null)
|
||||
m_DateValue = new Timestamp (System.currentTimeMillis());
|
||||
} // prepare
|
||||
|
||||
|
||||
/**
|
||||
* Perrform process.
|
||||
* @return Message
|
||||
* @throws Exception
|
||||
*/
|
||||
protected String doIt() throws java.lang.Exception
|
||||
{
|
||||
StringBuffer sql = null;
|
||||
int no = 0;
|
||||
String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID;
|
||||
|
||||
// **** Prepare ****
|
||||
|
||||
// Delete Old Imported
|
||||
if (m_deleteOldImported)
|
||||
{
|
||||
sql = new StringBuffer ("DELETE I_BPartner "
|
||||
+ "WHERE I_IsImported='Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Delete Old Impored =" + no);
|
||||
}
|
||||
|
||||
// Set Client, Org, IsActive, Created/Updated
|
||||
sql = new StringBuffer ("UPDATE I_BPartner "
|
||||
+ "SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),"
|
||||
+ " AD_Org_ID = COALESCE (AD_Org_ID, 0),"
|
||||
+ " IsActive = COALESCE (IsActive, 'Y'),"
|
||||
+ " Created = COALESCE (Created, SysDate),"
|
||||
+ " CreatedBy = COALESCE (CreatedBy, 0),"
|
||||
+ " Updated = COALESCE (Updated, SysDate),"
|
||||
+ " UpdatedBy = COALESCE (UpdatedBy, 0),"
|
||||
+ " I_ErrorMsg = NULL,"
|
||||
+ " I_IsImported = 'N' "
|
||||
+ "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Reset=" + no);
|
||||
|
||||
// Set BP_Group
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET GroupValue=(SELECT Value FROM C_BP_Group g WHERE g.IsDefault='Y'"
|
||||
+ " AND g.AD_Client_ID=i.AD_Client_ID AND ROWNUM=1) "
|
||||
+ "WHERE GroupValue IS NULL AND C_BP_Group_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Group Default=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_BP_Group_ID=(SELECT C_BP_Group_ID FROM C_BP_Group g"
|
||||
+ " WHERE i.GroupValue=g.Value AND g.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE C_BP_Group_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Group=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Group, ' "
|
||||
+ "WHERE C_BP_Group_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.config("Invalid Group=" + no);
|
||||
|
||||
// Set Country
|
||||
/**
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET CountryCode=(SELECT CountryCode FROM C_Country c WHERE c.IsDefault='Y'"
|
||||
+ " AND c.AD_Client_ID IN (0, i.AD_Client_ID) AND ROWNUM=1) "
|
||||
+ "WHERE CountryCode IS NULL AND C_Country_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Country Default=" + no);
|
||||
**/
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_Country_ID=(SELECT C_Country_ID FROM C_Country c"
|
||||
+ " WHERE i.CountryCode=c.CountryCode AND c.AD_Client_ID IN (0, i.AD_Client_ID)) "
|
||||
+ "WHERE C_Country_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Country=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Country, ' "
|
||||
+ "WHERE C_Country_ID IS NULL AND (City IS NOT NULL OR Address1 IS NOT NULL)"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.config("Invalid Country=" + no);
|
||||
|
||||
// Set Region
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "Set RegionName=(SELECT Name FROM C_Region r"
|
||||
+ " WHERE r.IsDefault='Y' AND r.C_Country_ID=i.C_Country_ID"
|
||||
+ " AND r.AD_Client_ID IN (0, i.AD_Client_ID) AND ROWNUM=1) "
|
||||
+ "WHERE RegionName IS NULL AND C_Region_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Region Default=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "Set C_Region_ID=(SELECT C_Region_ID FROM C_Region r"
|
||||
+ " WHERE r.Name=i.RegionName AND r.C_Country_ID=i.C_Country_ID"
|
||||
+ " AND r.AD_Client_ID IN (0, i.AD_Client_ID)) "
|
||||
+ "WHERE C_Region_ID IS NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Region=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Region, ' "
|
||||
+ "WHERE C_Region_ID IS NULL "
|
||||
+ " AND EXISTS (SELECT * FROM C_Country c"
|
||||
+ " WHERE c.C_Country_ID=i.C_Country_ID AND c.HasRegion='Y')"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.config("Invalid Region=" + no);
|
||||
|
||||
// Set Greeting
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_Greeting_ID=(SELECT C_Greeting_ID FROM C_Greeting g"
|
||||
+ " WHERE i.BPContactGreeting=g.Name AND g.AD_Client_ID IN (0, i.AD_Client_ID)) "
|
||||
+ "WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Greeting=" + no);
|
||||
//
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Greeting, ' "
|
||||
+ "WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL"
|
||||
+ " AND I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.config("Invalid Greeting=" + no);
|
||||
|
||||
// Existing User ?
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET (C_BPartner_ID,AD_User_ID)="
|
||||
+ "(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u "
|
||||
+ "WHERE i.EMail=u.EMail AND u.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE i.EMail IS NOT NULL AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Found EMail User=" + no);
|
||||
|
||||
// Existing BPartner ? Match Value
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner p"
|
||||
+ " WHERE i.Value=p.Value AND p.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE C_BPartner_ID IS NULL AND Value IS NOT NULL"
|
||||
+ " AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Found BPartner=" + no);
|
||||
|
||||
// Existing Contact ? Match Name
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET AD_User_ID=(SELECT AD_User_ID FROM AD_User c"
|
||||
+ " WHERE i.ContactName=c.Name AND i.C_BPartner_ID=c.C_BPartner_ID AND c.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE C_BPartner_ID IS NOT NULL AND AD_User_ID IS NULL AND ContactName IS NOT NULL"
|
||||
+ " AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Found Contact=" + no);
|
||||
|
||||
// Existing Location ? Exact Match
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET C_BPartner_Location_ID=(SELECT C_BPartner_Location_ID"
|
||||
+ " FROM C_BPartner_Location bpl INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)"
|
||||
+ " WHERE i.C_BPartner_ID=bpl.C_BPartner_ID AND bpl.AD_Client_ID=i.AD_Client_ID"
|
||||
+ " AND DUMP(i.Address1)=DUMP(l.Address1) AND DUMP(i.Address2)=DUMP(l.Address2)"
|
||||
+ " AND DUMP(i.City)=DUMP(l.City) AND DUMP(i.Postal)=DUMP(l.Postal) AND DUMP(i.Postal_Add)=DUMP(l.Postal_Add)"
|
||||
+ " AND DUMP(i.C_Region_ID)=DUMP(l.C_Region_ID) AND DUMP(i.C_Country_ID)=DUMP(l.C_Country_ID)) "
|
||||
+ "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL"
|
||||
+ " AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Found Location=" + no);
|
||||
|
||||
// Interest Area
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET R_InterestArea_ID=(SELECT R_InterestArea_ID FROM R_InterestArea ia "
|
||||
+ "WHERE i.InterestAreaName=ia.Name AND ia.AD_Client_ID=i.AD_Client_ID) "
|
||||
+ "WHERE R_InterestArea_ID IS NULL AND InterestAreaName IS NOT NULL"
|
||||
+ " AND I_IsImported='N'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
log.fine("Set Interest Area=" + no);
|
||||
|
||||
|
||||
commit();
|
||||
// -------------------------------------------------------------------
|
||||
int noInsert = 0;
|
||||
int noUpdate = 0;
|
||||
|
||||
// Go through Records
|
||||
sql = new StringBuffer ("SELECT * FROM I_BPartner "
|
||||
+ "WHERE I_IsImported='N'").append(clientCheck);
|
||||
try
|
||||
{
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
X_I_BPartner impBP = new X_I_BPartner (getCtx(), rs, get_TrxName());
|
||||
log.fine("I_BPartner_ID=" + impBP.getI_BPartner_ID()
|
||||
+ ", C_BPartner_ID=" + impBP.getC_BPartner_ID()
|
||||
+ ", C_BPartner_Location_ID=" + impBP.getC_BPartner_Location_ID()
|
||||
+ ", AD_User_ID=" + impBP.getAD_User_ID());
|
||||
|
||||
|
||||
// **** Create/Update BPartner ****
|
||||
MBPartner bp = null;
|
||||
if (impBP.getC_BPartner_ID() == 0) // Insert new BPartner
|
||||
{
|
||||
bp = new MBPartner(impBP);
|
||||
if (bp.save())
|
||||
{
|
||||
impBP.setC_BPartner_ID(bp.getC_BPartner_ID());
|
||||
log.finest("Insert BPartner - " + bp.getC_BPartner_ID());
|
||||
noInsert++;
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
|
||||
.append("'Cannot Insert BPartner, ' ")
|
||||
.append("Cannot Insert BPartner")
|
||||
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
|
||||
DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else // Update existing BPartner
|
||||
{
|
||||
bp = new MBPartner(getCtx(), impBP.getC_BPartner_ID(), get_TrxName());
|
||||
// if (impBP.getValue() != null) // not to overwite
|
||||
// bp.setValue(impBP.getValue());
|
||||
if (impBP.getName() != null)
|
||||
{
|
||||
bp.setName(impBP.getName());
|
||||
bp.setName2(impBP.getName2());
|
||||
}
|
||||
if (impBP.getDUNS() != null)
|
||||
bp.setDUNS(impBP.getDUNS());
|
||||
if (impBP.getTaxID() != null)
|
||||
bp.setTaxID(impBP.getTaxID());
|
||||
if (impBP.getNAICS() != null)
|
||||
bp.setNAICS(impBP.getNAICS());
|
||||
if (impBP.getC_BP_Group_ID() != 0)
|
||||
bp.setC_BP_Group_ID(impBP.getC_BP_Group_ID());
|
||||
//
|
||||
if (bp.save())
|
||||
{
|
||||
log.finest("Update BPartner - " + bp.getC_BPartner_ID());
|
||||
noUpdate++;
|
||||
}
|
||||
else
|
||||
}
|
||||
}
|
||||
else // Update existing BPartner
|
||||
{
|
||||
bp = new MBPartner(getCtx(), impBP.getC_BPartner_ID(), get_TrxName());
|
||||
// if (impBP.getValue() != null) // not to overwite
|
||||
// bp.setValue(impBP.getValue());
|
||||
if (impBP.getName() != null)
|
||||
{
|
||||
bp.setName(impBP.getName());
|
||||
bp.setName2(impBP.getName2());
|
||||
}
|
||||
if (impBP.getDUNS() != null)
|
||||
bp.setDUNS(impBP.getDUNS());
|
||||
if (impBP.getTaxID() != null)
|
||||
bp.setTaxID(impBP.getTaxID());
|
||||
if (impBP.getNAICS() != null)
|
||||
bp.setNAICS(impBP.getNAICS());
|
||||
if (impBP.getC_BP_Group_ID() != 0)
|
||||
bp.setC_BP_Group_ID(impBP.getC_BP_Group_ID());
|
||||
//
|
||||
if (bp.save())
|
||||
{
|
||||
log.finest("Update BPartner - " + bp.getC_BPartner_ID());
|
||||
noUpdate++;
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
|
||||
.append("'Cannot Update BPartner, ' ")
|
||||
.append("Cannot Update BPartner")
|
||||
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
|
||||
DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// **** Create/Update BPartner Location ****
|
||||
MBPartnerLocation bpl = null;
|
||||
if (impBP.getC_BPartner_Location_ID() != 0) // Update Location
|
||||
{
|
||||
bpl = new MBPartnerLocation(getCtx(), impBP.getC_BPartner_Location_ID(), get_TrxName());
|
||||
MLocation location = new MLocation(getCtx(), bpl.getC_Location_ID(), get_TrxName());
|
||||
location.setC_Country_ID(impBP.getC_Country_ID());
|
||||
location.setC_Region_ID(impBP.getC_Region_ID());
|
||||
location.setCity(impBP.getCity());
|
||||
location.setAddress1(impBP.getAddress1());
|
||||
location.setAddress2(impBP.getAddress2());
|
||||
location.setPostal(impBP.getPostal());
|
||||
location.setPostal_Add(impBP.getPostal_Add());
|
||||
if (!location.save())
|
||||
log.warning("Location not updated");
|
||||
else
|
||||
bpl.setC_Location_ID(location.getC_Location_ID());
|
||||
if (impBP.getPhone() != null)
|
||||
bpl.setPhone(impBP.getPhone());
|
||||
if (impBP.getPhone2() != null)
|
||||
bpl.setPhone2(impBP.getPhone2());
|
||||
if (impBP.getFax() != null)
|
||||
bpl.setFax(impBP.getFax());
|
||||
bpl.save();
|
||||
}
|
||||
else // New Location
|
||||
if (impBP.getC_Country_ID() != 0
|
||||
&& impBP.getAddress1() != null
|
||||
&& impBP.getCity() != null)
|
||||
{
|
||||
MLocation location = new MLocation(getCtx(), impBP.getC_Country_ID(),
|
||||
impBP.getC_Region_ID(), impBP.getCity(), get_TrxName());
|
||||
location.setAddress1(impBP.getAddress1());
|
||||
location.setAddress2(impBP.getAddress2());
|
||||
location.setPostal(impBP.getPostal());
|
||||
location.setPostal_Add(impBP.getPostal_Add());
|
||||
if (location.save())
|
||||
log.finest("Insert Location - " + location.getC_Location_ID());
|
||||
else
|
||||
{
|
||||
rollback();
|
||||
}
|
||||
}
|
||||
|
||||
// **** Create/Update BPartner Location ****
|
||||
MBPartnerLocation bpl = null;
|
||||
if (impBP.getC_BPartner_Location_ID() != 0) // Update Location
|
||||
{
|
||||
bpl = new MBPartnerLocation(getCtx(), impBP.getC_BPartner_Location_ID(), get_TrxName());
|
||||
MLocation location = new MLocation(getCtx(), bpl.getC_Location_ID(), get_TrxName());
|
||||
location.setC_Country_ID(impBP.getC_Country_ID());
|
||||
location.setC_Region_ID(impBP.getC_Region_ID());
|
||||
location.setCity(impBP.getCity());
|
||||
location.setAddress1(impBP.getAddress1());
|
||||
location.setAddress2(impBP.getAddress2());
|
||||
location.setPostal(impBP.getPostal());
|
||||
location.setPostal_Add(impBP.getPostal_Add());
|
||||
if (!location.save())
|
||||
log.warning("Location not updated");
|
||||
else
|
||||
bpl.setC_Location_ID(location.getC_Location_ID());
|
||||
if (impBP.getPhone() != null)
|
||||
bpl.setPhone(impBP.getPhone());
|
||||
if (impBP.getPhone2() != null)
|
||||
bpl.setPhone2(impBP.getPhone2());
|
||||
if (impBP.getFax() != null)
|
||||
bpl.setFax(impBP.getFax());
|
||||
bpl.save();
|
||||
}
|
||||
else // New Location
|
||||
if (impBP.getC_Country_ID() != 0
|
||||
&& impBP.getAddress1() != null
|
||||
&& impBP.getCity() != null)
|
||||
{
|
||||
MLocation location = new MLocation(getCtx(), impBP.getC_Country_ID(),
|
||||
impBP.getC_Region_ID(), impBP.getCity(), get_TrxName());
|
||||
location.setAddress1(impBP.getAddress1());
|
||||
location.setAddress2(impBP.getAddress2());
|
||||
location.setPostal(impBP.getPostal());
|
||||
location.setPostal_Add(impBP.getPostal_Add());
|
||||
if (location.save())
|
||||
log.finest("Insert Location - " + location.getC_Location_ID());
|
||||
else
|
||||
{
|
||||
rollback();
|
||||
noInsert--;
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
|
||||
.append("'Cannot Insert Location, ' ")
|
||||
.append("Cannot Insert Location")
|
||||
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
|
||||
DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
continue;
|
||||
}
|
||||
//
|
||||
bpl = new MBPartnerLocation (bp);
|
||||
bpl.setC_Location_ID(location.getC_Location_ID());
|
||||
bpl.setPhone(impBP.getPhone());
|
||||
bpl.setPhone2(impBP.getPhone2());
|
||||
bpl.setFax(impBP.getFax());
|
||||
if (bpl.save())
|
||||
{
|
||||
log.finest("Insert BP Location - " + bpl.getC_BPartner_Location_ID());
|
||||
impBP.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID());
|
||||
}
|
||||
else
|
||||
{
|
||||
rollback();
|
||||
}
|
||||
//
|
||||
bpl = new MBPartnerLocation (bp);
|
||||
bpl.setC_Location_ID(location.getC_Location_ID());
|
||||
bpl.setPhone(impBP.getPhone());
|
||||
bpl.setPhone2(impBP.getPhone2());
|
||||
bpl.setFax(impBP.getFax());
|
||||
if (bpl.save())
|
||||
{
|
||||
log.finest("Insert BP Location - " + bpl.getC_BPartner_Location_ID());
|
||||
impBP.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID());
|
||||
}
|
||||
else
|
||||
{
|
||||
rollback();
|
||||
noInsert--;
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
|
||||
.append("'Cannot Insert BPLocation, ' ")
|
||||
.append("Cannot Insert BPLocation")
|
||||
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
|
||||
DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// **** Create/Update Contact ****
|
||||
MUser user = null;
|
||||
if (impBP.getAD_User_ID() != 0)
|
||||
{
|
||||
user = new MUser (getCtx(), impBP.getAD_User_ID(), get_TrxName());
|
||||
if (user.getC_BPartner_ID() == 0)
|
||||
user.setC_BPartner_ID(bp.getC_BPartner_ID());
|
||||
else if (user.getC_BPartner_ID() != bp.getC_BPartner_ID())
|
||||
{
|
||||
rollback();
|
||||
}
|
||||
}
|
||||
|
||||
// **** Create/Update Contact ****
|
||||
MUser user = null;
|
||||
if (impBP.getAD_User_ID() != 0)
|
||||
{
|
||||
user = new MUser (getCtx(), impBP.getAD_User_ID(), get_TrxName());
|
||||
if (user.getC_BPartner_ID() == 0)
|
||||
user.setC_BPartner_ID(bp.getC_BPartner_ID());
|
||||
else if (user.getC_BPartner_ID() != bp.getC_BPartner_ID())
|
||||
{
|
||||
rollback();
|
||||
noInsert--;
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
|
||||
.append("'BP of User <> BP, ' ")
|
||||
.append("BP of User <> BP")
|
||||
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
|
||||
DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
continue;
|
||||
}
|
||||
if (impBP.getC_Greeting_ID() != 0)
|
||||
user.setC_Greeting_ID(impBP.getC_Greeting_ID());
|
||||
String name = impBP.getContactName();
|
||||
if (name == null || name.length() == 0)
|
||||
name = impBP.getEMail();
|
||||
user.setName(name);
|
||||
if (impBP.getTitle() != null)
|
||||
user.setTitle(impBP.getTitle());
|
||||
if (impBP.getContactDescription() != null)
|
||||
user.setDescription(impBP.getContactDescription());
|
||||
if (impBP.getComments() != null)
|
||||
user.setComments(impBP.getComments());
|
||||
if (impBP.getPhone() != null)
|
||||
user.setPhone(impBP.getPhone());
|
||||
if (impBP.getPhone2() != null)
|
||||
user.setPhone(impBP.getPhone2());
|
||||
if (impBP.getFax() != null)
|
||||
user.setFax(impBP.getFax());
|
||||
if (impBP.getEMail() != null)
|
||||
user.setEMail(impBP.getEMail());
|
||||
if (impBP.getBirthday() != null)
|
||||
user.setBirthday(impBP.getBirthday());
|
||||
if (bpl != null)
|
||||
user.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID());
|
||||
if (user.save())
|
||||
{
|
||||
log.finest("Update BP Contact - " + user.getAD_User_ID());
|
||||
}
|
||||
else
|
||||
{
|
||||
rollback();
|
||||
}
|
||||
if (impBP.getC_Greeting_ID() != 0)
|
||||
user.setC_Greeting_ID(impBP.getC_Greeting_ID());
|
||||
String name = impBP.getContactName();
|
||||
if (name == null || name.length() == 0)
|
||||
name = impBP.getEMail();
|
||||
user.setName(name);
|
||||
if (impBP.getTitle() != null)
|
||||
user.setTitle(impBP.getTitle());
|
||||
if (impBP.getContactDescription() != null)
|
||||
user.setDescription(impBP.getContactDescription());
|
||||
if (impBP.getComments() != null)
|
||||
user.setComments(impBP.getComments());
|
||||
if (impBP.getPhone() != null)
|
||||
user.setPhone(impBP.getPhone());
|
||||
if (impBP.getPhone2() != null)
|
||||
user.setPhone(impBP.getPhone2());
|
||||
if (impBP.getFax() != null)
|
||||
user.setFax(impBP.getFax());
|
||||
if (impBP.getEMail() != null)
|
||||
user.setEMail(impBP.getEMail());
|
||||
if (impBP.getBirthday() != null)
|
||||
user.setBirthday(impBP.getBirthday());
|
||||
if (bpl != null)
|
||||
user.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID());
|
||||
if (user.save())
|
||||
{
|
||||
log.finest("Update BP Contact - " + user.getAD_User_ID());
|
||||
}
|
||||
else
|
||||
{
|
||||
rollback();
|
||||
noInsert--;
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
|
||||
.append("'Cannot Update BP Contact, ' ")
|
||||
.append("Cannot Update BP Contact")
|
||||
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
|
||||
DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else // New Contact
|
||||
if (impBP.getContactName() != null || impBP.getEMail() != null)
|
||||
{
|
||||
user = new MUser (bp);
|
||||
if (impBP.getC_Greeting_ID() != 0)
|
||||
user.setC_Greeting_ID(impBP.getC_Greeting_ID());
|
||||
String name = impBP.getContactName();
|
||||
if (name == null || name.length() == 0)
|
||||
name = impBP.getEMail();
|
||||
user.setName(name);
|
||||
user.setTitle(impBP.getTitle());
|
||||
user.setDescription(impBP.getContactDescription());
|
||||
user.setComments(impBP.getComments());
|
||||
user.setPhone(impBP.getPhone());
|
||||
user.setPhone(impBP.getPhone2());
|
||||
user.setFax(impBP.getFax());
|
||||
user.setEMail(impBP.getEMail());
|
||||
user.setBirthday(impBP.getBirthday());
|
||||
if (bpl != null)
|
||||
user.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID());
|
||||
if (user.save())
|
||||
{
|
||||
log.finest("Insert BP Contact - " + user.getAD_User_ID());
|
||||
impBP.setAD_User_ID(user.getAD_User_ID());
|
||||
}
|
||||
else
|
||||
{
|
||||
rollback();
|
||||
}
|
||||
}
|
||||
else // New Contact
|
||||
if (impBP.getContactName() != null || impBP.getEMail() != null)
|
||||
{
|
||||
user = new MUser (bp);
|
||||
if (impBP.getC_Greeting_ID() != 0)
|
||||
user.setC_Greeting_ID(impBP.getC_Greeting_ID());
|
||||
String name = impBP.getContactName();
|
||||
if (name == null || name.length() == 0)
|
||||
name = impBP.getEMail();
|
||||
user.setName(name);
|
||||
user.setTitle(impBP.getTitle());
|
||||
user.setDescription(impBP.getContactDescription());
|
||||
user.setComments(impBP.getComments());
|
||||
user.setPhone(impBP.getPhone());
|
||||
user.setPhone(impBP.getPhone2());
|
||||
user.setFax(impBP.getFax());
|
||||
user.setEMail(impBP.getEMail());
|
||||
user.setBirthday(impBP.getBirthday());
|
||||
if (bpl != null)
|
||||
user.setC_BPartner_Location_ID(bpl.getC_BPartner_Location_ID());
|
||||
if (user.save())
|
||||
{
|
||||
log.finest("Insert BP Contact - " + user.getAD_User_ID());
|
||||
impBP.setAD_User_ID(user.getAD_User_ID());
|
||||
}
|
||||
else
|
||||
{
|
||||
rollback();
|
||||
noInsert--;
|
||||
sql = new StringBuffer ("UPDATE I_BPartner i "
|
||||
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
|
||||
.append("'Cannot Insert BPContact, ' ")
|
||||
.append("Cannot Insert BPContact")
|
||||
.append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID());
|
||||
DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Interest Area
|
||||
if (impBP.getR_InterestArea_ID() != 0 && user != null)
|
||||
{
|
||||
MContactInterest ci = MContactInterest.get(getCtx(),
|
||||
impBP.getR_InterestArea_ID(), user.getAD_User_ID(),
|
||||
true, get_TrxName());
|
||||
ci.save(); // don't subscribe or re-activate
|
||||
}
|
||||
//
|
||||
impBP.setI_IsImported(true);
|
||||
impBP.setProcessed(true);
|
||||
impBP.setProcessing(false);
|
||||
impBP.save();
|
||||
commit();
|
||||
} // for all I_Product
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, "", e);
|
||||
rollback();
|
||||
}
|
||||
|
||||
// Set Error to indicator to not imported
|
||||
sql = new StringBuffer ("UPDATE I_BPartner "
|
||||
+ "SET I_IsImported='N', Updated=SysDate "
|
||||
+ "WHERE I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
addLog (0, null, new BigDecimal (no), "@Errors@");
|
||||
addLog (0, null, new BigDecimal (noInsert), "@C_BPartner_ID@: @Inserted@");
|
||||
addLog (0, null, new BigDecimal (noUpdate), "@C_BPartner_ID@: @Updated@");
|
||||
return "";
|
||||
} // doIt
|
||||
|
||||
} // ImportBPartner
|
||||
}
|
||||
}
|
||||
|
||||
// Interest Area
|
||||
if (impBP.getR_InterestArea_ID() != 0 && user != null)
|
||||
{
|
||||
MContactInterest ci = MContactInterest.get(getCtx(),
|
||||
impBP.getR_InterestArea_ID(), user.getAD_User_ID(),
|
||||
true, get_TrxName());
|
||||
ci.save(); // don't subscribe or re-activate
|
||||
}
|
||||
//
|
||||
impBP.setI_IsImported(true);
|
||||
impBP.setProcessed(true);
|
||||
impBP.setProcessing(false);
|
||||
impBP.save();
|
||||
commit();
|
||||
} // for all I_Product
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, "", e);
|
||||
rollback();
|
||||
}
|
||||
|
||||
// Set Error to indicator to not imported
|
||||
sql = new StringBuffer ("UPDATE I_BPartner "
|
||||
+ "SET I_IsImported='N', Updated=SysDate "
|
||||
+ "WHERE I_IsImported<>'Y'").append(clientCheck);
|
||||
no = DB.executeUpdate(sql.toString(), get_TrxName());
|
||||
addLog (0, null, new BigDecimal (no), "@Errors@");
|
||||
addLog (0, null, new BigDecimal (noInsert), "@C_BPartner_ID@: @Inserted@");
|
||||
addLog (0, null, new BigDecimal (noUpdate), "@C_BPartner_ID@: @Updated@");
|
||||
return "";
|
||||
} // doIt
|
||||
|
||||
} // ImportBPartner
|
||||
|
|
|
@ -3,366 +3,366 @@
|
|||
* 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.process;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import java.math.*;
|
||||
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Invoice Not realized Gain & Loss.
|
||||
* The actual data shown is T_InvoiceGL_v
|
||||
* @author Jorg Janke
|
||||
* @version $Id: InvoiceNGL.java,v 1.3 2006/08/04 03:53:59 jjanke Exp $
|
||||
*/
|
||||
public class InvoiceNGL extends SvrProcess
|
||||
{
|
||||
/** Mandatory Acct Schema */
|
||||
private int p_C_AcctSchema_ID = 0;
|
||||
/** Mandatory Conversion Type */
|
||||
private int p_C_ConversionTypeReval_ID = 0;
|
||||
/** Revaluation Date */
|
||||
private Timestamp p_DateReval = null;
|
||||
/** Only AP/AR Transactions */
|
||||
private String p_APAR = "A";
|
||||
private static String ONLY_AP = "P";
|
||||
private static String ONLY_AR = "R";
|
||||
/** Report all Currencies */
|
||||
private boolean p_IsAllCurrencies = false;
|
||||
/** Optional Invoice Currency */
|
||||
private int p_C_Currency_ID = 0;
|
||||
/** GL Document Type */
|
||||
private int p_C_DocTypeReval_ID = 0;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("C_AcctSchema_ID"))
|
||||
p_C_AcctSchema_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_ConversionTypeReval_ID"))
|
||||
p_C_ConversionTypeReval_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("DateReval"))
|
||||
p_DateReval = (Timestamp)para[i].getParameter();
|
||||
else if (name.equals("APAR"))
|
||||
p_APAR = (String)para[i].getParameter();
|
||||
else if (name.equals("IsAllCurrencies"))
|
||||
p_IsAllCurrencies = "Y".equals((String)para[i].getParameter());
|
||||
else if (name.equals("C_Currency_ID"))
|
||||
p_C_Currency_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_DocTypeReval_ID"))
|
||||
p_C_DocTypeReval_ID = para[i].getParameterAsInt();
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
* Process
|
||||
* @return info
|
||||
* @throws Exception
|
||||
*/
|
||||
protected String doIt () throws Exception
|
||||
{
|
||||
if (p_IsAllCurrencies)
|
||||
p_C_Currency_ID = 0;
|
||||
log.info("C_AcctSchema_ID=" + p_C_AcctSchema_ID
|
||||
+ ",C_ConversionTypeReval_ID=" + p_C_ConversionTypeReval_ID
|
||||
+ ",DateReval=" + p_DateReval
|
||||
+ ", APAR=" + p_APAR
|
||||
+ ", IsAllCurrencies=" + p_IsAllCurrencies
|
||||
+ ",C_Currency_ID=" + p_C_Currency_ID
|
||||
+ ", C_DocType_ID=" + p_C_DocTypeReval_ID);
|
||||
|
||||
// Parameter
|
||||
if (p_DateReval == null)
|
||||
p_DateReval = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
// Delete - just to be sure
|
||||
String sql = "DELETE T_InvoiceGL WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
|
||||
int no = DB.executeUpdate(sql, get_TrxName());
|
||||
if (no > 0)
|
||||
log.info("Deleted #" + no);
|
||||
|
||||
// Insert Trx
|
||||
String dateStr = DB.TO_DATE(p_DateReval, true);
|
||||
sql = "INSERT INTO T_InvoiceGL (AD_Client_ID, AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy,"
|
||||
+ " AD_PInstance_ID, C_Invoice_ID, GrandTotal, OpenAmt, "
|
||||
+ " Fact_Acct_ID, AmtSourceBalance, AmtAcctBalance, "
|
||||
+ " AmtRevalDr, AmtRevalCr, C_DocTypeReval_ID, IsAllCurrencies, "
|
||||
+ " DateReval, C_ConversionTypeReval_ID, AmtRevalDrDiff, AmtRevalCrDiff, APAR) "
|
||||
// --
|
||||
+ "SELECT i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created,i.CreatedBy, i.Updated,i.UpdatedBy,"
|
||||
+ getAD_PInstance_ID() + ", i.C_Invoice_ID, i.GrandTotal, invoiceOpen(i.C_Invoice_ID, 0), "
|
||||
+ " fa.Fact_Acct_ID, fa.AmtSourceDr-fa.AmtSourceCr, fa.AmtAcctDr-fa.AmtAcctCr, "
|
||||
// AmtRevalDr, AmtRevalCr,
|
||||
+ " currencyConvert(fa.AmtSourceDr, i.C_Currency_ID, a.C_Currency_ID, " + dateStr + ", " + p_C_ConversionTypeReval_ID + ", i.AD_Client_ID, i.AD_Org_ID),"
|
||||
+ " currencyConvert(fa.AmtSourceCr, i.C_Currency_ID, a.C_Currency_ID, " + dateStr + ", " + p_C_ConversionTypeReval_ID + ", i.AD_Client_ID, i.AD_Org_ID),"
|
||||
+ (p_C_DocTypeReval_ID==0 ? "NULL" : String.valueOf(p_C_DocTypeReval_ID)) + ", "
|
||||
+ (p_IsAllCurrencies ? "'Y'," : "'N',")
|
||||
+ dateStr + ", " + p_C_ConversionTypeReval_ID + ", 0, 0, '" + p_APAR + "' "
|
||||
//
|
||||
+ "FROM C_Invoice_v i"
|
||||
+ " INNER JOIN Fact_Acct fa ON (fa.AD_Table_ID=318 AND fa.Record_ID=i.C_Invoice_ID"
|
||||
+ " AND (i.GrandTotal=fa.AmtSourceDr OR i.GrandTotal=fa.AmtSourceCr))"
|
||||
+ " INNER JOIN C_AcctSchema a ON (fa.C_AcctSchema_ID=a.C_AcctSchema_ID) "
|
||||
+ "WHERE i.IsPaid='N'"
|
||||
+ " AND EXISTS (SELECT * FROM C_ElementValue ev "
|
||||
+ "WHERE ev.C_ElementValue_ID=fa.Account_ID AND (ev.AccountType='A' OR ev.AccountType='L'))"
|
||||
+ " AND fa.C_AcctSchema_ID=" + p_C_AcctSchema_ID;
|
||||
if (!p_IsAllCurrencies)
|
||||
sql += " AND i.C_Currency_ID<>a.C_Currency_ID";
|
||||
if (ONLY_AR.equals(p_APAR))
|
||||
sql += " AND i.IsSOTrx='Y'";
|
||||
else if (ONLY_AP.equals(p_APAR))
|
||||
sql += " AND i.IsSOTrx='N'";
|
||||
if (!p_IsAllCurrencies && p_C_Currency_ID != 0)
|
||||
sql += " AND i.C_Currency_ID=" + p_C_Currency_ID;
|
||||
|
||||
no = DB.executeUpdate(sql, get_TrxName());
|
||||
if (no != 0)
|
||||
log.info("Inserted #" + no);
|
||||
else if (CLogMgt.isLevelFiner())
|
||||
log.warning("Inserted #" + no + " - " + sql);
|
||||
else
|
||||
log.warning("Inserted #" + no);
|
||||
|
||||
// Calculate Difference
|
||||
sql = "UPDATE T_InvoiceGL gl "
|
||||
+ "SET (AmtRevalDrDiff,AmtRevalCrDiff)="
|
||||
+ "(SELECT gl.AmtRevalDr-fa.AmtAcctDr, gl.AmtRevalCr-fa.AmtAcctCr "
|
||||
+ "FROM Fact_Acct fa "
|
||||
+ "WHERE gl.Fact_Acct_ID=fa.Fact_Acct_ID) "
|
||||
+ "WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
|
||||
int noT = DB.executeUpdate(sql, get_TrxName());
|
||||
if (noT > 0)
|
||||
log.config("Difference #" + noT);
|
||||
|
||||
// Percentage
|
||||
sql = "UPDATE T_InvoiceGL SET Percent = 100 "
|
||||
+ "WHERE GrandTotal=OpenAmt AND AD_PInstance_ID=" + getAD_PInstance_ID();
|
||||
no = DB.executeUpdate(sql, get_TrxName());
|
||||
* 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.process;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import java.math.*;
|
||||
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
/**
|
||||
* Invoice Not realized Gain & Loss.
|
||||
* The actual data shown is T_InvoiceGL_v
|
||||
* @author Jorg Janke
|
||||
* @version $Id: InvoiceNGL.java,v 1.3 2006/08/04 03:53:59 jjanke Exp $
|
||||
*/
|
||||
public class InvoiceNGL extends SvrProcess
|
||||
{
|
||||
/** Mandatory Acct Schema */
|
||||
private int p_C_AcctSchema_ID = 0;
|
||||
/** Mandatory Conversion Type */
|
||||
private int p_C_ConversionTypeReval_ID = 0;
|
||||
/** Revaluation Date */
|
||||
private Timestamp p_DateReval = null;
|
||||
/** Only AP/AR Transactions */
|
||||
private String p_APAR = "A";
|
||||
private static String ONLY_AP = "P";
|
||||
private static String ONLY_AR = "R";
|
||||
/** Report all Currencies */
|
||||
private boolean p_IsAllCurrencies = false;
|
||||
/** Optional Invoice Currency */
|
||||
private int p_C_Currency_ID = 0;
|
||||
/** GL Document Type */
|
||||
private int p_C_DocTypeReval_ID = 0;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("C_AcctSchema_ID"))
|
||||
p_C_AcctSchema_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_ConversionTypeReval_ID"))
|
||||
p_C_ConversionTypeReval_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("DateReval"))
|
||||
p_DateReval = (Timestamp)para[i].getParameter();
|
||||
else if (name.equals("APAR"))
|
||||
p_APAR = (String)para[i].getParameter();
|
||||
else if (name.equals("IsAllCurrencies"))
|
||||
p_IsAllCurrencies = "Y".equals((String)para[i].getParameter());
|
||||
else if (name.equals("C_Currency_ID"))
|
||||
p_C_Currency_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_DocTypeReval_ID"))
|
||||
p_C_DocTypeReval_ID = para[i].getParameterAsInt();
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
* Process
|
||||
* @return info
|
||||
* @throws Exception
|
||||
*/
|
||||
protected String doIt () throws Exception
|
||||
{
|
||||
if (p_IsAllCurrencies)
|
||||
p_C_Currency_ID = 0;
|
||||
log.info("C_AcctSchema_ID=" + p_C_AcctSchema_ID
|
||||
+ ",C_ConversionTypeReval_ID=" + p_C_ConversionTypeReval_ID
|
||||
+ ",DateReval=" + p_DateReval
|
||||
+ ", APAR=" + p_APAR
|
||||
+ ", IsAllCurrencies=" + p_IsAllCurrencies
|
||||
+ ",C_Currency_ID=" + p_C_Currency_ID
|
||||
+ ", C_DocType_ID=" + p_C_DocTypeReval_ID);
|
||||
|
||||
// Parameter
|
||||
if (p_DateReval == null)
|
||||
p_DateReval = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
// Delete - just to be sure
|
||||
String sql = "DELETE T_InvoiceGL WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
|
||||
int no = DB.executeUpdate(sql, get_TrxName());
|
||||
if (no > 0)
|
||||
log.info("Deleted #" + no);
|
||||
|
||||
// Insert Trx
|
||||
String dateStr = DB.TO_DATE(p_DateReval, true);
|
||||
sql = "INSERT INTO T_InvoiceGL (AD_Client_ID, AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy,"
|
||||
+ " AD_PInstance_ID, C_Invoice_ID, GrandTotal, OpenAmt, "
|
||||
+ " Fact_Acct_ID, AmtSourceBalance, AmtAcctBalance, "
|
||||
+ " AmtRevalDr, AmtRevalCr, C_DocTypeReval_ID, IsAllCurrencies, "
|
||||
+ " DateReval, C_ConversionTypeReval_ID, AmtRevalDrDiff, AmtRevalCrDiff, APAR) "
|
||||
// --
|
||||
+ "SELECT i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created,i.CreatedBy, i.Updated,i.UpdatedBy,"
|
||||
+ getAD_PInstance_ID() + ", i.C_Invoice_ID, i.GrandTotal, invoiceOpen(i.C_Invoice_ID, 0), "
|
||||
+ " fa.Fact_Acct_ID, fa.AmtSourceDr-fa.AmtSourceCr, fa.AmtAcctDr-fa.AmtAcctCr, "
|
||||
// AmtRevalDr, AmtRevalCr,
|
||||
+ " currencyConvert(fa.AmtSourceDr, i.C_Currency_ID, a.C_Currency_ID, " + dateStr + ", " + p_C_ConversionTypeReval_ID + ", i.AD_Client_ID, i.AD_Org_ID),"
|
||||
+ " currencyConvert(fa.AmtSourceCr, i.C_Currency_ID, a.C_Currency_ID, " + dateStr + ", " + p_C_ConversionTypeReval_ID + ", i.AD_Client_ID, i.AD_Org_ID),"
|
||||
+ (p_C_DocTypeReval_ID==0 ? "NULL" : String.valueOf(p_C_DocTypeReval_ID)) + ", "
|
||||
+ (p_IsAllCurrencies ? "'Y'," : "'N',")
|
||||
+ dateStr + ", " + p_C_ConversionTypeReval_ID + ", 0, 0, '" + p_APAR + "' "
|
||||
//
|
||||
+ "FROM C_Invoice_v i"
|
||||
+ " INNER JOIN Fact_Acct fa ON (fa.AD_Table_ID=318 AND fa.Record_ID=i.C_Invoice_ID"
|
||||
+ " AND (i.GrandTotal=fa.AmtSourceDr OR i.GrandTotal=fa.AmtSourceCr))"
|
||||
+ " INNER JOIN C_AcctSchema a ON (fa.C_AcctSchema_ID=a.C_AcctSchema_ID) "
|
||||
+ "WHERE i.IsPaid='N'"
|
||||
+ " AND EXISTS (SELECT * FROM C_ElementValue ev "
|
||||
+ "WHERE ev.C_ElementValue_ID=fa.Account_ID AND (ev.AccountType='A' OR ev.AccountType='L'))"
|
||||
+ " AND fa.C_AcctSchema_ID=" + p_C_AcctSchema_ID;
|
||||
if (!p_IsAllCurrencies)
|
||||
sql += " AND i.C_Currency_ID<>a.C_Currency_ID";
|
||||
if (ONLY_AR.equals(p_APAR))
|
||||
sql += " AND i.IsSOTrx='Y'";
|
||||
else if (ONLY_AP.equals(p_APAR))
|
||||
sql += " AND i.IsSOTrx='N'";
|
||||
if (!p_IsAllCurrencies && p_C_Currency_ID != 0)
|
||||
sql += " AND i.C_Currency_ID=" + p_C_Currency_ID;
|
||||
|
||||
no = DB.executeUpdate(sql, get_TrxName());
|
||||
if (no != 0)
|
||||
log.info("Inserted #" + no);
|
||||
else if (CLogMgt.isLevelFiner())
|
||||
log.warning("Inserted #" + no + " - " + sql);
|
||||
else
|
||||
log.warning("Inserted #" + no);
|
||||
|
||||
// Calculate Difference
|
||||
sql = "UPDATE T_InvoiceGL gl "
|
||||
+ "SET (AmtRevalDrDiff,AmtRevalCrDiff)="
|
||||
+ "(SELECT gl.AmtRevalDr-fa.AmtAcctDr, gl.AmtRevalCr-fa.AmtAcctCr "
|
||||
+ "FROM Fact_Acct fa "
|
||||
+ "WHERE gl.Fact_Acct_ID=fa.Fact_Acct_ID) "
|
||||
+ "WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
|
||||
int noT = DB.executeUpdate(sql, get_TrxName());
|
||||
if (noT > 0)
|
||||
log.config("Difference #" + noT);
|
||||
|
||||
// Percentage
|
||||
sql = "UPDATE T_InvoiceGL SET Percent = 100 "
|
||||
+ "WHERE GrandTotal=OpenAmt AND AD_PInstance_ID=" + getAD_PInstance_ID();
|
||||
no = DB.executeUpdate(sql, get_TrxName());
|
||||
if (no > 0)
|
||||
log.info("Not Paid #" + no);
|
||||
|
||||
sql = "UPDATE T_InvoiceGL SET Percent = ROUND(OpenAmt*100/GrandTotal,4) "
|
||||
sql = "UPDATE T_InvoiceGL SET Percent = ROUND(OpenAmt*100/GrandTotal,6) "
|
||||
+ "WHERE GrandTotal<>OpenAmt AND GrandTotal <> 0 AND AD_PInstance_ID=" + getAD_PInstance_ID();
|
||||
no = DB.executeUpdate(sql, get_TrxName());
|
||||
if (no > 0)
|
||||
log.info("Partial Paid #" + no);
|
||||
|
||||
sql = "UPDATE T_InvoiceGL SET AmtRevalDr = AmtRevalDr * Percent/100,"
|
||||
+ " AmtRevalCr = AmtRevalCr * Percent/100,"
|
||||
+ " AmtRevalDrDiff = AmtRevalDrDiff * Percent/100,"
|
||||
+ " AmtRevalCrDiff = AmtRevalCrDiff * Percent/100 "
|
||||
+ "WHERE Percent <> 100 AND AD_PInstance_ID=" + getAD_PInstance_ID();
|
||||
no = DB.executeUpdate(sql, get_TrxName());
|
||||
if (no > 0)
|
||||
log.config("Partial Calc #" + no);
|
||||
|
||||
// Create Document
|
||||
String info = "";
|
||||
if (p_C_DocTypeReval_ID != 0)
|
||||
{
|
||||
if (p_C_Currency_ID != 0)
|
||||
log.warning("Can create Journal only for all currencies");
|
||||
else
|
||||
info = createGLJournal();
|
||||
}
|
||||
return "#" + noT + info;
|
||||
} // doIt
|
||||
|
||||
/**
|
||||
* Create GL Journal
|
||||
* @return document info
|
||||
*/
|
||||
private String createGLJournal()
|
||||
{
|
||||
ArrayList<X_T_InvoiceGL> list = new ArrayList<X_T_InvoiceGL>();
|
||||
String sql = "SELECT * FROM T_InvoiceGL "
|
||||
+ "WHERE AD_PInstance_ID=" + getAD_PInstance_ID()
|
||||
+ " ORDER BY AD_Org_ID";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
list.add (new X_T_InvoiceGL (getCtx(), rs, get_TrxName()));
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (list.size() == 0)
|
||||
return " - No Records found";
|
||||
|
||||
//
|
||||
MAcctSchema as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID);
|
||||
MAcctSchemaDefault asDefaultAccts = MAcctSchemaDefault.get(getCtx(), p_C_AcctSchema_ID);
|
||||
MGLCategory cat = MGLCategory.getDefaultSystem(getCtx());
|
||||
if (cat == null)
|
||||
{
|
||||
MDocType docType = MDocType.get(getCtx(), p_C_DocTypeReval_ID);
|
||||
cat = MGLCategory.get(getCtx(), docType.getGL_Category_ID());
|
||||
}
|
||||
//
|
||||
MJournalBatch batch = new MJournalBatch(getCtx(), 0, get_TrxName());
|
||||
batch.setDescription (getName());
|
||||
batch.setC_DocType_ID(p_C_DocTypeReval_ID);
|
||||
batch.setDateDoc(new Timestamp(System.currentTimeMillis()));
|
||||
batch.setDateAcct(p_DateReval);
|
||||
batch.setC_Currency_ID(as.getC_Currency_ID());
|
||||
if (!batch.save())
|
||||
return " - Could not create Batch";
|
||||
//
|
||||
MJournal journal = null;
|
||||
BigDecimal drTotal = Env.ZERO;
|
||||
BigDecimal crTotal = Env.ZERO;
|
||||
int AD_Org_ID = 0;
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
{
|
||||
X_T_InvoiceGL gl = list.get(i);
|
||||
if (gl.getAmtRevalDrDiff().signum() == 0 && gl.getAmtRevalCrDiff().signum() == 0)
|
||||
continue;
|
||||
MInvoice invoice = new MInvoice(getCtx(), gl.getC_Invoice_ID(), null);
|
||||
if (invoice.getC_Currency_ID() == as.getC_Currency_ID())
|
||||
continue;
|
||||
//
|
||||
if (journal == null)
|
||||
{
|
||||
journal = new MJournal (batch);
|
||||
journal.setC_AcctSchema_ID (as.getC_AcctSchema_ID());
|
||||
journal.setC_Currency_ID(as.getC_Currency_ID());
|
||||
journal.setC_ConversionType_ID(p_C_ConversionTypeReval_ID);
|
||||
MOrg org = MOrg.get(getCtx(), gl.getAD_Org_ID());
|
||||
journal.setDescription (getName() + " - " + org.getName());
|
||||
journal.setGL_Category_ID (cat.getGL_Category_ID());
|
||||
if (!journal.save())
|
||||
return " - Could not create Journal";
|
||||
}
|
||||
//
|
||||
MJournalLine line = new MJournalLine(journal);
|
||||
line.setLine((i+1) * 10);
|
||||
line.setDescription(invoice.getSummary());
|
||||
//
|
||||
MFactAcct fa = new MFactAcct (getCtx(), gl.getFact_Acct_ID(), null);
|
||||
line.setC_ValidCombination_ID(MAccount.get(fa));
|
||||
BigDecimal dr = gl.getAmtRevalDrDiff();
|
||||
BigDecimal cr = gl.getAmtRevalCrDiff();
|
||||
drTotal = drTotal.add(dr);
|
||||
crTotal = crTotal.add(cr);
|
||||
line.setAmtSourceDr (dr);
|
||||
line.setAmtAcctDr (dr);
|
||||
line.setAmtSourceCr (cr);
|
||||
line.setAmtAcctCr (cr);
|
||||
line.save();
|
||||
//
|
||||
if (AD_Org_ID == 0) // invoice org id
|
||||
AD_Org_ID = gl.getAD_Org_ID();
|
||||
// Change in Org
|
||||
if (AD_Org_ID != gl.getAD_Org_ID())
|
||||
{
|
||||
createBalancing (asDefaultAccts, journal, drTotal, crTotal, AD_Org_ID, (i+1) * 10);
|
||||
//
|
||||
AD_Org_ID = gl.getAD_Org_ID();
|
||||
drTotal = Env.ZERO;
|
||||
crTotal = Env.ZERO;
|
||||
journal = null;
|
||||
}
|
||||
}
|
||||
createBalancing (asDefaultAccts, journal, drTotal, crTotal, AD_Org_ID, (list.size()+1) * 10);
|
||||
|
||||
return " - " + batch.getDocumentNo() + " #" + list.size();
|
||||
} // createGLJournal
|
||||
|
||||
/**
|
||||
* Create Balancing Entry
|
||||
* @param asDefaultAccts acct schema default accounts
|
||||
* @param journal journal
|
||||
* @param drTotal dr
|
||||
* @param crTotal cr
|
||||
* @param AD_Org_ID org
|
||||
* @param lineNo base line no
|
||||
*/
|
||||
private void createBalancing (MAcctSchemaDefault asDefaultAccts, MJournal journal,
|
||||
BigDecimal drTotal, BigDecimal crTotal, int AD_Org_ID, int lineNo)
|
||||
{
|
||||
if (journal == null)
|
||||
throw new IllegalArgumentException("Jornal is null");
|
||||
// CR Entry = Gain
|
||||
if (drTotal.signum() != 0)
|
||||
{
|
||||
MJournalLine line = new MJournalLine(journal);
|
||||
line.setLine(lineNo+1);
|
||||
MAccount base = MAccount.get(getCtx(), asDefaultAccts.getUnrealizedGain_Acct());
|
||||
MAccount acct = MAccount.get(getCtx(), asDefaultAccts.getAD_Client_ID(), AD_Org_ID,
|
||||
asDefaultAccts.getC_AcctSchema_ID(), base.getAccount_ID(), base.getC_SubAcct_ID(),
|
||||
base.getM_Product_ID(), base.getC_BPartner_ID(), base.getAD_OrgTrx_ID(),
|
||||
base.getC_LocFrom_ID(), base.getC_LocTo_ID(), base.getC_SalesRegion_ID(),
|
||||
base.getC_Project_ID(), base.getC_Campaign_ID(), base.getC_Activity_ID(),
|
||||
base.getUser1_ID(), base.getUser2_ID(), base.getUserElement1_ID(), base.getUserElement2_ID());
|
||||
line.setDescription(Msg.getElement(getCtx(), "UnrealizedGain_Acct"));
|
||||
line.setC_ValidCombination_ID(acct.getC_ValidCombination_ID());
|
||||
line.setAmtSourceCr (drTotal);
|
||||
line.setAmtAcctCr (drTotal);
|
||||
line.save();
|
||||
}
|
||||
// DR Entry = Loss
|
||||
if (crTotal.signum() != 0)
|
||||
{
|
||||
MJournalLine line = new MJournalLine(journal);
|
||||
line.setLine(lineNo+2);
|
||||
MAccount base = MAccount.get(getCtx(), asDefaultAccts.getUnrealizedLoss_Acct());
|
||||
MAccount acct = MAccount.get(getCtx(), asDefaultAccts.getAD_Client_ID(), AD_Org_ID,
|
||||
asDefaultAccts.getC_AcctSchema_ID(), base.getAccount_ID(), base.getC_SubAcct_ID(),
|
||||
base.getM_Product_ID(), base.getC_BPartner_ID(), base.getAD_OrgTrx_ID(),
|
||||
base.getC_LocFrom_ID(), base.getC_LocTo_ID(), base.getC_SalesRegion_ID(),
|
||||
base.getC_Project_ID(), base.getC_Campaign_ID(), base.getC_Activity_ID(),
|
||||
base.getUser1_ID(), base.getUser2_ID(), base.getUserElement1_ID(), base.getUserElement2_ID());
|
||||
line.setDescription(Msg.getElement(getCtx(), "UnrealizedLoss_Acct"));
|
||||
line.setC_ValidCombination_ID(acct.getC_ValidCombination_ID());
|
||||
line.setAmtSourceDr (crTotal);
|
||||
line.setAmtAcctDr (crTotal);
|
||||
line.save();
|
||||
}
|
||||
} // createBalancing
|
||||
|
||||
} // InvoiceNGL
|
||||
log.info("Partial Paid #" + no);
|
||||
|
||||
sql = "UPDATE T_InvoiceGL SET AmtRevalDr = AmtRevalDr * Percent/100,"
|
||||
+ " AmtRevalCr = AmtRevalCr * Percent/100,"
|
||||
+ " AmtRevalDrDiff = AmtRevalDrDiff * Percent/100,"
|
||||
+ " AmtRevalCrDiff = AmtRevalCrDiff * Percent/100 "
|
||||
+ "WHERE Percent <> 100 AND AD_PInstance_ID=" + getAD_PInstance_ID();
|
||||
no = DB.executeUpdate(sql, get_TrxName());
|
||||
if (no > 0)
|
||||
log.config("Partial Calc #" + no);
|
||||
|
||||
// Create Document
|
||||
String info = "";
|
||||
if (p_C_DocTypeReval_ID != 0)
|
||||
{
|
||||
if (p_C_Currency_ID != 0)
|
||||
log.warning("Can create Journal only for all currencies");
|
||||
else
|
||||
info = createGLJournal();
|
||||
}
|
||||
return "#" + noT + info;
|
||||
} // doIt
|
||||
|
||||
/**
|
||||
* Create GL Journal
|
||||
* @return document info
|
||||
*/
|
||||
private String createGLJournal()
|
||||
{
|
||||
ArrayList<X_T_InvoiceGL> list = new ArrayList<X_T_InvoiceGL>();
|
||||
String sql = "SELECT * FROM T_InvoiceGL "
|
||||
+ "WHERE AD_PInstance_ID=" + getAD_PInstance_ID()
|
||||
+ " ORDER BY AD_Org_ID";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
list.add (new X_T_InvoiceGL (getCtx(), rs, get_TrxName()));
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (list.size() == 0)
|
||||
return " - No Records found";
|
||||
|
||||
//
|
||||
MAcctSchema as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID);
|
||||
MAcctSchemaDefault asDefaultAccts = MAcctSchemaDefault.get(getCtx(), p_C_AcctSchema_ID);
|
||||
MGLCategory cat = MGLCategory.getDefaultSystem(getCtx());
|
||||
if (cat == null)
|
||||
{
|
||||
MDocType docType = MDocType.get(getCtx(), p_C_DocTypeReval_ID);
|
||||
cat = MGLCategory.get(getCtx(), docType.getGL_Category_ID());
|
||||
}
|
||||
//
|
||||
MJournalBatch batch = new MJournalBatch(getCtx(), 0, get_TrxName());
|
||||
batch.setDescription (getName());
|
||||
batch.setC_DocType_ID(p_C_DocTypeReval_ID);
|
||||
batch.setDateDoc(new Timestamp(System.currentTimeMillis()));
|
||||
batch.setDateAcct(p_DateReval);
|
||||
batch.setC_Currency_ID(as.getC_Currency_ID());
|
||||
if (!batch.save())
|
||||
return " - Could not create Batch";
|
||||
//
|
||||
MJournal journal = null;
|
||||
BigDecimal drTotal = Env.ZERO;
|
||||
BigDecimal crTotal = Env.ZERO;
|
||||
int AD_Org_ID = 0;
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
{
|
||||
X_T_InvoiceGL gl = list.get(i);
|
||||
if (gl.getAmtRevalDrDiff().signum() == 0 && gl.getAmtRevalCrDiff().signum() == 0)
|
||||
continue;
|
||||
MInvoice invoice = new MInvoice(getCtx(), gl.getC_Invoice_ID(), null);
|
||||
if (invoice.getC_Currency_ID() == as.getC_Currency_ID())
|
||||
continue;
|
||||
//
|
||||
if (journal == null)
|
||||
{
|
||||
journal = new MJournal (batch);
|
||||
journal.setC_AcctSchema_ID (as.getC_AcctSchema_ID());
|
||||
journal.setC_Currency_ID(as.getC_Currency_ID());
|
||||
journal.setC_ConversionType_ID(p_C_ConversionTypeReval_ID);
|
||||
MOrg org = MOrg.get(getCtx(), gl.getAD_Org_ID());
|
||||
journal.setDescription (getName() + " - " + org.getName());
|
||||
journal.setGL_Category_ID (cat.getGL_Category_ID());
|
||||
if (!journal.save())
|
||||
return " - Could not create Journal";
|
||||
}
|
||||
//
|
||||
MJournalLine line = new MJournalLine(journal);
|
||||
line.setLine((i+1) * 10);
|
||||
line.setDescription(invoice.getSummary());
|
||||
//
|
||||
MFactAcct fa = new MFactAcct (getCtx(), gl.getFact_Acct_ID(), null);
|
||||
line.setC_ValidCombination_ID(MAccount.get(fa));
|
||||
BigDecimal dr = gl.getAmtRevalDrDiff();
|
||||
BigDecimal cr = gl.getAmtRevalCrDiff();
|
||||
drTotal = drTotal.add(dr);
|
||||
crTotal = crTotal.add(cr);
|
||||
line.setAmtSourceDr (dr);
|
||||
line.setAmtAcctDr (dr);
|
||||
line.setAmtSourceCr (cr);
|
||||
line.setAmtAcctCr (cr);
|
||||
line.save();
|
||||
//
|
||||
if (AD_Org_ID == 0) // invoice org id
|
||||
AD_Org_ID = gl.getAD_Org_ID();
|
||||
// Change in Org
|
||||
if (AD_Org_ID != gl.getAD_Org_ID())
|
||||
{
|
||||
createBalancing (asDefaultAccts, journal, drTotal, crTotal, AD_Org_ID, (i+1) * 10);
|
||||
//
|
||||
AD_Org_ID = gl.getAD_Org_ID();
|
||||
drTotal = Env.ZERO;
|
||||
crTotal = Env.ZERO;
|
||||
journal = null;
|
||||
}
|
||||
}
|
||||
createBalancing (asDefaultAccts, journal, drTotal, crTotal, AD_Org_ID, (list.size()+1) * 10);
|
||||
|
||||
return " - " + batch.getDocumentNo() + " #" + list.size();
|
||||
} // createGLJournal
|
||||
|
||||
/**
|
||||
* Create Balancing Entry
|
||||
* @param asDefaultAccts acct schema default accounts
|
||||
* @param journal journal
|
||||
* @param drTotal dr
|
||||
* @param crTotal cr
|
||||
* @param AD_Org_ID org
|
||||
* @param lineNo base line no
|
||||
*/
|
||||
private void createBalancing (MAcctSchemaDefault asDefaultAccts, MJournal journal,
|
||||
BigDecimal drTotal, BigDecimal crTotal, int AD_Org_ID, int lineNo)
|
||||
{
|
||||
if (journal == null)
|
||||
throw new IllegalArgumentException("Jornal is null");
|
||||
// CR Entry = Gain
|
||||
if (drTotal.signum() != 0)
|
||||
{
|
||||
MJournalLine line = new MJournalLine(journal);
|
||||
line.setLine(lineNo+1);
|
||||
MAccount base = MAccount.get(getCtx(), asDefaultAccts.getUnrealizedGain_Acct());
|
||||
MAccount acct = MAccount.get(getCtx(), asDefaultAccts.getAD_Client_ID(), AD_Org_ID,
|
||||
asDefaultAccts.getC_AcctSchema_ID(), base.getAccount_ID(), base.getC_SubAcct_ID(),
|
||||
base.getM_Product_ID(), base.getC_BPartner_ID(), base.getAD_OrgTrx_ID(),
|
||||
base.getC_LocFrom_ID(), base.getC_LocTo_ID(), base.getC_SalesRegion_ID(),
|
||||
base.getC_Project_ID(), base.getC_Campaign_ID(), base.getC_Activity_ID(),
|
||||
base.getUser1_ID(), base.getUser2_ID(), base.getUserElement1_ID(), base.getUserElement2_ID());
|
||||
line.setDescription(Msg.getElement(getCtx(), "UnrealizedGain_Acct"));
|
||||
line.setC_ValidCombination_ID(acct.getC_ValidCombination_ID());
|
||||
line.setAmtSourceCr (drTotal);
|
||||
line.setAmtAcctCr (drTotal);
|
||||
line.save();
|
||||
}
|
||||
// DR Entry = Loss
|
||||
if (crTotal.signum() != 0)
|
||||
{
|
||||
MJournalLine line = new MJournalLine(journal);
|
||||
line.setLine(lineNo+2);
|
||||
MAccount base = MAccount.get(getCtx(), asDefaultAccts.getUnrealizedLoss_Acct());
|
||||
MAccount acct = MAccount.get(getCtx(), asDefaultAccts.getAD_Client_ID(), AD_Org_ID,
|
||||
asDefaultAccts.getC_AcctSchema_ID(), base.getAccount_ID(), base.getC_SubAcct_ID(),
|
||||
base.getM_Product_ID(), base.getC_BPartner_ID(), base.getAD_OrgTrx_ID(),
|
||||
base.getC_LocFrom_ID(), base.getC_LocTo_ID(), base.getC_SalesRegion_ID(),
|
||||
base.getC_Project_ID(), base.getC_Campaign_ID(), base.getC_Activity_ID(),
|
||||
base.getUser1_ID(), base.getUser2_ID(), base.getUserElement1_ID(), base.getUserElement2_ID());
|
||||
line.setDescription(Msg.getElement(getCtx(), "UnrealizedLoss_Acct"));
|
||||
line.setC_ValidCombination_ID(acct.getC_ValidCombination_ID());
|
||||
line.setAmtSourceDr (crTotal);
|
||||
line.setAmtAcctDr (crTotal);
|
||||
line.save();
|
||||
}
|
||||
} // createBalancing
|
||||
|
||||
} // InvoiceNGL
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.compiere.process;
|
|||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.AdempiereUserError;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -50,9 +51,11 @@ public class PaySelectionCreateCheck extends SvrProcess
|
|||
else if (name.equals("PaymentRule"))
|
||||
p_PaymentRule = (String)para[i].getParameter();
|
||||
else
|
||||
log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name);
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
p_C_PaySelection_ID = getRecord_ID();
|
||||
if (p_PaymentRule != null & p_PaymentRule.equals(X_C_Order.PAYMENTRULE_DirectDebit))
|
||||
p_PaymentRule = null;
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
|
@ -62,7 +65,7 @@ public class PaySelectionCreateCheck extends SvrProcess
|
|||
*/
|
||||
protected String doIt () throws Exception
|
||||
{
|
||||
log.info ("doIt - C_PaySelection_ID=" + p_C_PaySelection_ID
|
||||
log.info ("C_PaySelection_ID=" + p_C_PaySelection_ID
|
||||
+ ", PaymentRule=" + p_PaymentRule);
|
||||
|
||||
MPaySelection psel = new MPaySelection (getCtx(), p_C_PaySelection_ID, get_TrxName());
|
||||
|
@ -70,8 +73,6 @@ public class PaySelectionCreateCheck extends SvrProcess
|
|||
throw new IllegalArgumentException("Not found C_PaySelection_ID=" + p_C_PaySelection_ID);
|
||||
if (psel.isProcessed())
|
||||
throw new IllegalArgumentException("@Processed@");
|
||||
if (p_PaymentRule == null)
|
||||
throw new IllegalArgumentException("No PaymentRule");
|
||||
//
|
||||
MPaySelectionLine[] lines = psel.getLines(false);
|
||||
for (int i = 0; i < lines.length; i++)
|
||||
|
@ -91,8 +92,9 @@ public class PaySelectionCreateCheck extends SvrProcess
|
|||
/**
|
||||
* Create Check from line
|
||||
* @param line
|
||||
* @throws Exception for invalid bank accounts
|
||||
*/
|
||||
private void createCheck (MPaySelectionLine line)
|
||||
private void createCheck (MPaySelectionLine line) throws Exception
|
||||
{
|
||||
// Try to find one
|
||||
for (int i = 0; i < m_list.size(); i++)
|
||||
|
@ -103,22 +105,35 @@ public class PaySelectionCreateCheck extends SvrProcess
|
|||
{
|
||||
check.addLine(line);
|
||||
if (!check.save())
|
||||
throw new IllegalStateException("Cannot Save MPaySelectionCheck");
|
||||
throw new IllegalStateException("Cannot save MPaySelectionCheck");
|
||||
line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
|
||||
line.setProcessed(true);
|
||||
if (!line.save())
|
||||
throw new IllegalStateException("Cannot Save MPaySelectionLine");
|
||||
throw new IllegalStateException("Cannot save MPaySelectionLine");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Create new
|
||||
MPaySelectionCheck check = new MPaySelectionCheck(line, p_PaymentRule);
|
||||
String PaymentRule = line.getPaymentRule();
|
||||
if (p_PaymentRule != null)
|
||||
{
|
||||
if (!X_C_Order.PAYMENTRULE_DirectDebit.equals(PaymentRule))
|
||||
PaymentRule = p_PaymentRule;
|
||||
}
|
||||
MPaySelectionCheck check = new MPaySelectionCheck(line, PaymentRule);
|
||||
if (!check.isValid())
|
||||
{
|
||||
int C_BPartner_ID = check.getC_BPartner_ID();
|
||||
MBPartner bp = MBPartner.get(getCtx(), C_BPartner_ID);
|
||||
String msg = "@NotFound@ @C_BP_BankAccount@: " + bp.getName();
|
||||
throw new AdempiereUserError(msg);
|
||||
}
|
||||
if (!check.save())
|
||||
throw new IllegalStateException("Cannot Save MPaySelectionCheck");
|
||||
throw new IllegalStateException("Cannot save MPaySelectionCheck");
|
||||
line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
|
||||
line.setProcessed(true);
|
||||
if (!line.save())
|
||||
throw new IllegalStateException("Cannot Save MPaySelectionLine");
|
||||
throw new IllegalStateException("Cannot save MPaySelectionLine");
|
||||
m_list.add(check);
|
||||
} // createCheck
|
||||
|
||||
|
|
|
@ -3,236 +3,236 @@
|
|||
* 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.process;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Create Payment Selection Lines from AP Invoices
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: PaySelectionCreateFrom.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class PaySelectionCreateFrom extends SvrProcess
|
||||
{
|
||||
/** Only When Discount */
|
||||
private boolean p_OnlyDiscount = false;
|
||||
/** Only when Due */
|
||||
private boolean p_OnlyDue = false;
|
||||
/** Include Disputed */
|
||||
private boolean p_IncludeInDispute = false;
|
||||
/** Match Requirement */
|
||||
private String p_MatchRequirement = "N";
|
||||
/** Payment Rule */
|
||||
private String p_PaymentRule = null;
|
||||
/** BPartner */
|
||||
private int p_C_BPartner_ID = 0;
|
||||
/** BPartner Group */
|
||||
private int p_C_BP_Group_ID = 0;
|
||||
/** Payment Selection */
|
||||
private int p_C_PaySelection_ID = 0;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("OnlyDiscount"))
|
||||
p_OnlyDiscount = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("OnlyDue"))
|
||||
p_OnlyDue = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("IncludeInDispute"))
|
||||
p_IncludeInDispute = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("MatchRequirement"))
|
||||
p_MatchRequirement = (String)para[i].getParameter();
|
||||
else if (name.equals("PaymentRule"))
|
||||
p_PaymentRule = (String)para[i].getParameter();
|
||||
else if (name.equals("C_BPartner_ID"))
|
||||
p_C_BPartner_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_BP_Group_ID"))
|
||||
p_C_BP_Group_ID = para[i].getParameterAsInt();
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
p_C_PaySelection_ID = getRecord_ID();
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
* Perrform process.
|
||||
* @return Message
|
||||
* @throws Exception if not successful
|
||||
*/
|
||||
protected String doIt() throws Exception
|
||||
{
|
||||
log.info ("C_PaySelection_ID=" + p_C_PaySelection_ID
|
||||
+ ", OnlyDiscount=" + p_OnlyDiscount + ", OnlyDue=" + p_OnlyDue
|
||||
+ ", IncludeInDispute=" + p_IncludeInDispute
|
||||
+ ", MatchRequirement=" + p_MatchRequirement
|
||||
+ ", PaymentRule=" + p_PaymentRule
|
||||
+ ", C_BP_Group_ID=" + p_C_BP_Group_ID + ", C_BPartner_ID=" + p_C_BPartner_ID);
|
||||
|
||||
MPaySelection psel = new MPaySelection (getCtx(), p_C_PaySelection_ID, get_TrxName());
|
||||
if (psel.get_ID() == 0)
|
||||
throw new IllegalArgumentException("Not found C_PaySelection_ID=" + p_C_PaySelection_ID);
|
||||
if (psel.isProcessed())
|
||||
throw new IllegalArgumentException("@Processed@");
|
||||
// psel.getPayDate();
|
||||
|
||||
String sql = "SELECT C_Invoice_ID,"
|
||||
// Open
|
||||
+ " currencyConvert(invoiceOpen(i.C_Invoice_ID, 0)"
|
||||
+ ",i.C_Currency_ID, ?,?, i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)," // ##1/2 Currency_To,PayDate
|
||||
* 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.process;
|
||||
|
||||
import java.math.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
import org.compiere.model.*;
|
||||
import org.compiere.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* Create Payment Selection Lines from AP Invoices
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: PaySelectionCreateFrom.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||
*/
|
||||
public class PaySelectionCreateFrom extends SvrProcess
|
||||
{
|
||||
/** Only When Discount */
|
||||
private boolean p_OnlyDiscount = false;
|
||||
/** Only when Due */
|
||||
private boolean p_OnlyDue = false;
|
||||
/** Include Disputed */
|
||||
private boolean p_IncludeInDispute = false;
|
||||
/** Match Requirement */
|
||||
private String p_MatchRequirement = "N";
|
||||
/** Payment Rule */
|
||||
private String p_PaymentRule = null;
|
||||
/** BPartner */
|
||||
private int p_C_BPartner_ID = 0;
|
||||
/** BPartner Group */
|
||||
private int p_C_BP_Group_ID = 0;
|
||||
/** Payment Selection */
|
||||
private int p_C_PaySelection_ID = 0;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("OnlyDiscount"))
|
||||
p_OnlyDiscount = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("OnlyDue"))
|
||||
p_OnlyDue = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("IncludeInDispute"))
|
||||
p_IncludeInDispute = "Y".equals(para[i].getParameter());
|
||||
else if (name.equals("MatchRequirement"))
|
||||
p_MatchRequirement = (String)para[i].getParameter();
|
||||
else if (name.equals("PaymentRule"))
|
||||
p_PaymentRule = (String)para[i].getParameter();
|
||||
else if (name.equals("C_BPartner_ID"))
|
||||
p_C_BPartner_ID = para[i].getParameterAsInt();
|
||||
else if (name.equals("C_BP_Group_ID"))
|
||||
p_C_BP_Group_ID = para[i].getParameterAsInt();
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
p_C_PaySelection_ID = getRecord_ID();
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
* Perrform process.
|
||||
* @return Message
|
||||
* @throws Exception if not successful
|
||||
*/
|
||||
protected String doIt() throws Exception
|
||||
{
|
||||
log.info ("C_PaySelection_ID=" + p_C_PaySelection_ID
|
||||
+ ", OnlyDiscount=" + p_OnlyDiscount + ", OnlyDue=" + p_OnlyDue
|
||||
+ ", IncludeInDispute=" + p_IncludeInDispute
|
||||
+ ", MatchRequirement=" + p_MatchRequirement
|
||||
+ ", PaymentRule=" + p_PaymentRule
|
||||
+ ", C_BP_Group_ID=" + p_C_BP_Group_ID + ", C_BPartner_ID=" + p_C_BPartner_ID);
|
||||
|
||||
MPaySelection psel = new MPaySelection (getCtx(), p_C_PaySelection_ID, get_TrxName());
|
||||
if (psel.get_ID() == 0)
|
||||
throw new IllegalArgumentException("Not found C_PaySelection_ID=" + p_C_PaySelection_ID);
|
||||
if (psel.isProcessed())
|
||||
throw new IllegalArgumentException("@Processed@");
|
||||
// psel.getPayDate();
|
||||
|
||||
String sql = "SELECT C_Invoice_ID,"
|
||||
// Open
|
||||
+ " currencyConvert(invoiceOpen(i.C_Invoice_ID, 0)"
|
||||
+ ",i.C_Currency_ID, ?,?, i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)," // ##1/2 Currency_To,PayDate
|
||||
// Discount
|
||||
+ " currencyConvert(paymentTermDiscount(i.GrandTotal,i.C_Currency_ID,i.C_PaymentTerm_ID,i.DateInvoiced, ?)" // ##3 PayDate
|
||||
+ ",i.C_Currency_ID, ?,?,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)," // ##4/5 Currency_To,PayDate
|
||||
+ " PaymentRule, IsSOTrx "
|
||||
+ " PaymentRule, IsSOTrx " // 4..6
|
||||
+ "FROM C_Invoice i "
|
||||
+ "WHERE IsSOTrx='N' AND IsPaid='N' AND DocStatus IN ('CO','CL')"
|
||||
+ " AND AD_Client_ID=?" // ##6
|
||||
// Existing Payments - Will reselect Invoice if prepared but not paid
|
||||
+ " AND NOT EXISTS (SELECT * FROM C_PaySelectionLine psl "
|
||||
+ "WHERE i.C_Invoice_ID=psl.C_Invoice_ID AND psl.IsActive='Y'"
|
||||
+ " AND psl.C_PaySelectionCheck_ID IS NOT NULL)";
|
||||
// Disputed
|
||||
if (!p_IncludeInDispute)
|
||||
sql += " AND i.IsInDispute='N'";
|
||||
// PaymentRule (optional)
|
||||
if (p_PaymentRule != null)
|
||||
sql += " AND PaymentRule=?"; // ##
|
||||
// OnlyDiscount
|
||||
if (p_OnlyDiscount)
|
||||
{
|
||||
if (p_OnlyDue)
|
||||
sql += " AND (";
|
||||
else
|
||||
sql += " AND ";
|
||||
sql += "paymentTermDiscount(invoiceOpen(C_Invoice_ID, 0), C_Currency_ID, C_PaymentTerm_ID, DateInvoiced, ?) > 0"; // ##
|
||||
}
|
||||
// OnlyDue
|
||||
if (p_OnlyDue)
|
||||
{
|
||||
if (p_OnlyDiscount)
|
||||
sql += " OR ";
|
||||
else
|
||||
sql += " AND ";
|
||||
sql += "paymentTermDueDays(C_PaymentTerm_ID, DateInvoiced, ?) >= 0"; // ##
|
||||
if (p_OnlyDiscount)
|
||||
sql += ")";
|
||||
}
|
||||
// Business Partner
|
||||
if (p_C_BPartner_ID != 0)
|
||||
sql += " AND C_BPartner_ID=?"; // ##
|
||||
// Business Partner Group
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
sql += " AND EXISTS (SELECT * FROM C_BPartner bp "
|
||||
+ "WHERE bp.C_BPartner_ID=i.C_BPartner_ID AND bp.C_BP_Group_ID=?)"; // ##
|
||||
// PO Matching Requiremnent
|
||||
if (p_MatchRequirement.equals("P") || p_MatchRequirement.equals("B"))
|
||||
{
|
||||
sql += " AND EXISTS (SELECT * FROM C_InvoiceLine il "
|
||||
+ "WHERE i.C_Invoice_ID=il.C_Invoice_ID"
|
||||
+ " AND QtyInvoiced=(SELECT SUM(Qty) FROM M_MatchPO m "
|
||||
+ "WHERE il.C_InvoiceLine_ID=m.C_InvoiceLine_ID))";
|
||||
}
|
||||
// Receipt Matching Requiremnent
|
||||
if (p_MatchRequirement.equals("R") || p_MatchRequirement.equals("B"))
|
||||
{
|
||||
sql += " AND EXISTS (SELECT * FROM C_InvoiceLine il "
|
||||
+ "WHERE i.C_Invoice_ID=il.C_Invoice_ID"
|
||||
+ " AND QtyInvoiced=(SELECT SUM(Qty) FROM M_MatchInv m "
|
||||
+ "WHERE il.C_InvoiceLine_ID=m.C_InvoiceLine_ID))";
|
||||
}
|
||||
|
||||
//
|
||||
int lines = 0;
|
||||
int C_CurrencyTo_ID = psel.getC_Currency_ID();
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
int index = 1;
|
||||
pstmt.setInt (index++, C_CurrencyTo_ID);
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
//
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
pstmt.setInt (index++, C_CurrencyTo_ID);
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
//
|
||||
pstmt.setInt(index++, psel.getAD_Client_ID());
|
||||
if (p_PaymentRule != null)
|
||||
pstmt.setString(index++, p_PaymentRule);
|
||||
if (p_OnlyDiscount)
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
if (p_OnlyDue)
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
if (p_C_BPartner_ID != 0)
|
||||
pstmt.setInt (index++, p_C_BPartner_ID);
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
pstmt.setInt (index++, p_C_BP_Group_ID);
|
||||
//
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
int C_Invoice_ID = rs.getInt(1);
|
||||
BigDecimal PayAmt = rs.getBigDecimal(2);
|
||||
if (C_Invoice_ID == 0 || Env.ZERO.compareTo(PayAmt) == 0)
|
||||
continue;
|
||||
BigDecimal DiscountAmt = rs.getBigDecimal(3);
|
||||
String PaymentRule = rs.getString(4);
|
||||
boolean isSOTrx = "Y".equals(rs.getString(5));
|
||||
//
|
||||
lines++;
|
||||
MPaySelectionLine pselLine = new MPaySelectionLine (psel, lines*10, PaymentRule);
|
||||
pselLine.setInvoice (C_Invoice_ID, isSOTrx,
|
||||
PayAmt, PayAmt.subtract(DiscountAmt), DiscountAmt);
|
||||
if (!pselLine.save())
|
||||
{
|
||||
pstmt.close();
|
||||
throw new IllegalStateException ("Cannot save MPaySelectionLine");
|
||||
}
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
// Existing Payments - Will reselect Invoice if prepared but not paid
|
||||
+ " AND NOT EXISTS (SELECT * FROM C_PaySelectionLine psl "
|
||||
+ "WHERE i.C_Invoice_ID=psl.C_Invoice_ID AND psl.IsActive='Y'"
|
||||
+ " AND psl.C_PaySelectionCheck_ID IS NOT NULL)";
|
||||
// Disputed
|
||||
if (!p_IncludeInDispute)
|
||||
sql += " AND i.IsInDispute='N'";
|
||||
// PaymentRule (optional)
|
||||
if (p_PaymentRule != null)
|
||||
sql += " AND PaymentRule=?"; // ##
|
||||
// OnlyDiscount
|
||||
if (p_OnlyDiscount)
|
||||
{
|
||||
if (p_OnlyDue)
|
||||
sql += " AND (";
|
||||
else
|
||||
sql += " AND ";
|
||||
sql += "paymentTermDiscount(invoiceOpen(C_Invoice_ID, 0), C_Currency_ID, C_PaymentTerm_ID, DateInvoiced, ?) > 0"; // ##
|
||||
}
|
||||
// OnlyDue
|
||||
if (p_OnlyDue)
|
||||
{
|
||||
if (p_OnlyDiscount)
|
||||
sql += " OR ";
|
||||
else
|
||||
sql += " AND ";
|
||||
sql += "paymentTermDueDays(C_PaymentTerm_ID, DateInvoiced, ?) >= 0"; // ##
|
||||
if (p_OnlyDiscount)
|
||||
sql += ")";
|
||||
}
|
||||
// Business Partner
|
||||
if (p_C_BPartner_ID != 0)
|
||||
sql += " AND C_BPartner_ID=?"; // ##
|
||||
// Business Partner Group
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
sql += " AND EXISTS (SELECT * FROM C_BPartner bp "
|
||||
+ "WHERE bp.C_BPartner_ID=i.C_BPartner_ID AND bp.C_BP_Group_ID=?)"; // ##
|
||||
// PO Matching Requiremnent
|
||||
if (p_MatchRequirement.equals("P") || p_MatchRequirement.equals("B"))
|
||||
{
|
||||
sql += " AND EXISTS (SELECT * FROM C_InvoiceLine il "
|
||||
+ "WHERE i.C_Invoice_ID=il.C_Invoice_ID"
|
||||
+ " AND QtyInvoiced=(SELECT SUM(Qty) FROM M_MatchPO m "
|
||||
+ "WHERE il.C_InvoiceLine_ID=m.C_InvoiceLine_ID))";
|
||||
}
|
||||
// Receipt Matching Requiremnent
|
||||
if (p_MatchRequirement.equals("R") || p_MatchRequirement.equals("B"))
|
||||
{
|
||||
sql += " AND EXISTS (SELECT * FROM C_InvoiceLine il "
|
||||
+ "WHERE i.C_Invoice_ID=il.C_Invoice_ID"
|
||||
+ " AND QtyInvoiced=(SELECT SUM(Qty) FROM M_MatchInv m "
|
||||
+ "WHERE il.C_InvoiceLine_ID=m.C_InvoiceLine_ID))";
|
||||
}
|
||||
|
||||
//
|
||||
int lines = 0;
|
||||
int C_CurrencyTo_ID = psel.getC_Currency_ID();
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
int index = 1;
|
||||
pstmt.setInt (index++, C_CurrencyTo_ID);
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
//
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
pstmt.setInt (index++, C_CurrencyTo_ID);
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
//
|
||||
pstmt.setInt(index++, psel.getAD_Client_ID());
|
||||
if (p_PaymentRule != null)
|
||||
pstmt.setString(index++, p_PaymentRule);
|
||||
if (p_OnlyDiscount)
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
if (p_OnlyDue)
|
||||
pstmt.setTimestamp(index++, psel.getPayDate());
|
||||
if (p_C_BPartner_ID != 0)
|
||||
pstmt.setInt (index++, p_C_BPartner_ID);
|
||||
else if (p_C_BP_Group_ID != 0)
|
||||
pstmt.setInt (index++, p_C_BP_Group_ID);
|
||||
//
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
{
|
||||
int C_Invoice_ID = rs.getInt(1);
|
||||
BigDecimal PayAmt = rs.getBigDecimal(2);
|
||||
if (C_Invoice_ID == 0 || Env.ZERO.compareTo(PayAmt) == 0)
|
||||
continue;
|
||||
BigDecimal DiscountAmt = rs.getBigDecimal(3);
|
||||
String PaymentRule = rs.getString(4);
|
||||
boolean isSOTrx = "Y".equals(rs.getString(5));
|
||||
//
|
||||
lines++;
|
||||
MPaySelectionLine pselLine = new MPaySelectionLine (psel, lines*10, PaymentRule);
|
||||
pselLine.setInvoice (C_Invoice_ID, isSOTrx,
|
||||
PayAmt, PayAmt.subtract(DiscountAmt), DiscountAmt);
|
||||
if (!pselLine.save())
|
||||
{
|
||||
pstmt.close();
|
||||
throw new IllegalStateException ("Cannot save MPaySelectionLine");
|
||||
}
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "doIt - " + sql, e);
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
|
||||
return "@C_PaySelectionLine_ID@ - #" + lines;
|
||||
} // doIt
|
||||
|
||||
} // PaySelectionCreateFrom
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
|
||||
return "@C_PaySelectionLine_ID@ - #" + lines;
|
||||
} // doIt
|
||||
|
||||
} // PaySelectionCreateFrom
|
||||
|
|
Loading…
Reference in New Issue