📄 importorder.java
字号:
log.fine("Set Warehouse=" + no);
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET M_Warehouse_ID=(SELECT M_Warehouse_ID FROM M_Warehouse w"
+ " WHERE o.AD_Client_ID=w.AD_Client_ID) "
+ "WHERE M_Warehouse_ID IS NULL"
+ " AND EXISTS (SELECT AD_Client_ID FROM M_Warehouse w WHERE w.AD_Client_ID=o.AD_Client_ID GROUP BY AD_Client_ID HAVING COUNT(*)=1)"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.fine("Set Only Client Warehouse=" + no);
//
sql = new StringBuffer ("UPDATE I_Order "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Warehouse, ' "
+ "WHERE M_Warehouse_ID IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning ("No Warehouse=" + no);
// BP from EMail
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET (C_BPartner_ID,AD_User_ID)=(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u"
+ " WHERE o.EMail=u.EMail AND o.AD_Client_ID=u.AD_Client_ID AND u.C_BPartner_ID IS NOT NULL) "
+ "WHERE C_BPartner_ID IS NULL AND EMail IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set BP from EMail=" + no);
// BP from ContactName
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET (C_BPartner_ID,AD_User_ID)=(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u"
+ " WHERE o.ContactName=u.Name AND o.AD_Client_ID=u.AD_Client_ID AND u.C_BPartner_ID IS NOT NULL) "
+ "WHERE C_BPartner_ID IS NULL AND ContactName IS NOT NULL"
+ " AND EXISTS (SELECT Name FROM AD_User u WHERE o.ContactName=u.Name AND o.AD_Client_ID=u.AD_Client_ID AND u.C_BPartner_ID IS NOT NULL GROUP BY Name HAVING COUNT(*)=1)"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set BP from ContactName=" + no);
// BP from Value
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner bp"
+ " WHERE o.BPartnerValue=bp.Value AND o.AD_Client_ID=bp.AD_Client_ID AND ROWNUM=1) "
+ "WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set BP from Value=" + no);
// Default BP
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET C_BPartner_ID=(SELECT C_BPartnerCashTrx_ID FROM AD_ClientInfo c"
+ " WHERE o.AD_Client_ID=c.AD_Client_ID) "
+ "WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NULL AND Name IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Default BP=" + no);
// Existing Location ? Exact Match
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET (BillTo_ID,C_BPartner_Location_ID)=(SELECT C_BPartner_Location_ID,C_BPartner_Location_ID"
+ " FROM C_BPartner_Location bpl INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)"
+ " WHERE o.C_BPartner_ID=bpl.C_BPartner_ID AND bpl.AD_Client_ID=o.AD_Client_ID"
+ " AND DUMP(o.Address1)=DUMP(l.Address1) AND DUMP(o.Address2)=DUMP(l.Address2)"
+ " AND DUMP(o.City)=DUMP(l.City) AND DUMP(o.Postal)=DUMP(l.Postal)"
+ " AND DUMP(o.C_Region_ID)=DUMP(l.C_Region_ID) AND DUMP(o.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);
// Set Bill Location from BPartner
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET BillTo_ID=(SELECT C_BPartner_Location_ID FROM C_BPartner_Location l"
+ " WHERE l.C_BPartner_ID=o.C_BPartner_ID AND o.AD_Client_ID=l.AD_Client_ID"
+ " AND ((l.IsBillTo='Y' AND o.IsSOTrx='Y') OR (l.IsPayFrom='Y' AND o.IsSOTrx='N'))"
+ " AND ROWNUM=1) "
+ "WHERE C_BPartner_ID IS NOT NULL AND BillTo_ID IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set BP BillTo from BP=" + no);
// Set Location from BPartner
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET C_BPartner_Location_ID=(SELECT C_BPartner_Location_ID FROM C_BPartner_Location l"
+ " WHERE l.C_BPartner_ID=o.C_BPartner_ID AND o.AD_Client_ID=l.AD_Client_ID"
+ " AND ((l.IsShipTo='Y' AND o.IsSOTrx='Y') OR o.IsSOTrx='N')"
+ " AND ROWNUM=1) "
+ "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set BP Location from BP=" + no);
//
sql = new StringBuffer ("UPDATE I_Order "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BP Location, ' "
+ "WHERE C_BPartner_ID IS NOT NULL AND (BillTo_ID IS NULL OR C_BPartner_Location_ID IS NULL)"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning ("No BP Location=" + no);
// Set Country
/**
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET CountryCode=(SELECT CountryCode FROM C_Country c WHERE c.IsDefault='Y'"
+ " AND c.AD_Client_ID IN (0, o.AD_Client_ID) AND ROWNUM=1) "
+ "WHERE C_BPartner_ID IS NULL AND 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_Order o "
+ "SET C_Country_ID=(SELECT C_Country_ID FROM C_Country c"
+ " WHERE o.CountryCode=c.CountryCode AND c.AD_Client_ID IN (0, o.AD_Client_ID)) "
+ "WHERE C_BPartner_ID IS NULL AND C_Country_ID IS NULL AND CountryCode IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Country=" + no);
//
sql = new StringBuffer ("UPDATE I_Order "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Country, ' "
+ "WHERE C_BPartner_ID IS NULL AND C_Country_ID IS NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning ("Invalid Country=" + no);
// Set Region
sql = new StringBuffer ("UPDATE I_Order o "
+ "Set RegionName=(SELECT Name FROM C_Region r"
+ " WHERE r.IsDefault='Y' AND r.C_Country_ID=o.C_Country_ID"
+ " AND r.AD_Client_ID IN (0, o.AD_Client_ID) AND ROWNUM=1) "
+ "WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL AND RegionName 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_Order o "
+ "Set C_Region_ID=(SELECT C_Region_ID FROM C_Region r"
+ " WHERE r.Name=o.RegionName AND r.C_Country_ID=o.C_Country_ID"
+ " AND r.AD_Client_ID IN (0, o.AD_Client_ID)) "
+ "WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL AND RegionName IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Region=" + no);
//
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Region, ' "
+ "WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL "
+ " AND EXISTS (SELECT * FROM C_Country c"
+ " WHERE c.C_Country_ID=o.C_Country_ID AND c.HasRegion='Y')"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning ("Invalid Region=" + no);
// Product
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET M_Product_ID=(SELECT M_Product_ID FROM M_Product p"
+ " WHERE o.ProductValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID AND ROWNUM=1) "
+ "WHERE M_Product_ID IS NULL AND ProductValue IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Product from Value=" + no);
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET M_Product_ID=(SELECT M_Product_ID FROM M_Product p"
+ " WHERE o.UPC=p.UPC AND o.AD_Client_ID=p.AD_Client_ID AND ROWNUM=1) "
+ "WHERE M_Product_ID IS NULL AND UPC IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Product from UPC=" + no);
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET M_Product_ID=(SELECT M_Product_ID FROM M_Product p"
+ " WHERE o.SKU=p.SKU AND o.AD_Client_ID=p.AD_Client_ID AND ROWNUM=1) "
+ "WHERE M_Product_ID IS NULL AND SKU IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Product fom SKU=" + no);
sql = new StringBuffer ("UPDATE I_Order "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Product, ' "
+ "WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL OR UPC IS NOT NULL OR SKU IS NOT NULL)"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning ("Invalid Product=" + no);
// Tax
sql = new StringBuffer ("UPDATE I_Order o "
+ "SET C_Tax_ID=(SELECT C_Tax_ID FROM C_Tax t"
+ " WHERE o.TaxIndicator=t.TaxIndicator AND o.AD_Client_ID=t.AD_Client_ID AND ROWNUM=1) "
+ "WHERE C_Tax_ID IS NULL AND TaxIndicator IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Tax=" + no);
sql = new StringBuffer ("UPDATE I_Order "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Tax, ' "
+ "WHERE C_Tax_ID IS NULL AND TaxIndicator IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning ("Invalid Tax=" + no);
commit();
// -- New BPartner ---------------------------------------------------
// Go through Order Records w/o C_BPartner_ID
sql = new StringBuffer ("SELECT * FROM I_Order "
+ "WHERE I_IsImported='N' AND C_BPartner_ID IS NULL").append (clientCheck);
try
{
PreparedStatement pstmt = DB.prepareStatement (sql.toString(), get_TrxName());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
{
X_I_Order imp = new X_I_Order (getCtx (), rs, get_TrxName());
if (imp.getBPartnerValue () == null)
{
if (imp.getEMail () != null)
imp.setBPartnerValue (imp.getEMail ());
else if (imp.getName () != null)
imp.setBPartnerValue (imp.getName ());
else
continue;
}
if (imp.getName () == null)
{
if (imp.getContactName () != null)
imp.setName (imp.getContactName ());
else
imp.setName (imp.getBPartnerValue ());
}
// BPartner
MBPartner bp = MBPartner.get (getCtx(), imp.getBPartnerValue());
if (bp == null)
{
bp = new MBPartner (getCtx (), -1, get_TrxName());
bp.setClientOrg (imp.getAD_Client_ID (), imp.getAD_Org_ID ());
bp.setValue (imp.getBPartnerValue ());
bp.setName (imp.getName ());
if (!bp.save ())
continue;
}
imp.setC_BPartner_ID (bp.getC_BPartner_ID ());
// BP Location
MBPartnerLocation bpl = null;
MBPartnerLocation[] bpls = bp.getLocations(true);
for (int i = 0; bpl == null && i < bpls.length; i++)
{
if (imp.getC_BPartner_Location_ID() == bpls[i].getC_BPartner_Location_ID())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -