📄 importbpartner.java
字号:
// **** 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("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
{
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.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();
noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.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();
noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.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();
noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.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();
noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.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();
noInsert--;
sql = new StringBuffer ("UPDATE I_BPartner i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||")
.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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -