diff --git a/org.adempiere.base.process/src/org/compiere/process/ExpenseAPInvoice.java b/org.adempiere.base.process/src/org/compiere/process/ExpenseAPInvoice.java index 5a1d206a39..491dbabf9b 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ExpenseAPInvoice.java +++ b/org.adempiere.base.process/src/org/compiere/process/ExpenseAPInvoice.java @@ -76,21 +76,21 @@ public class ExpenseAPInvoice extends SvrProcess */ protected String doIt() throws java.lang.Exception { - StringBuffer sql = new StringBuffer ("SELECT * " - + "FROM S_TimeExpense e " - + "WHERE e.Processed='Y'" - + " AND e.AD_Client_ID=?"); // #1 + StringBuilder sql = new StringBuilder ("SELECT * ") + .append("FROM S_TimeExpense e ") + .append("WHERE e.Processed='Y'") + .append(" AND e.AD_Client_ID=?"); // #1 if (m_C_BPartner_ID != 0) sql.append(" AND e.C_BPartner_ID=?"); // #2 if (m_DateFrom != null) sql.append(" AND e.DateReport >= ?"); // #3 if (m_DateTo != null) sql.append(" AND e.DateReport <= ?"); // #4 - sql.append(" AND EXISTS (SELECT * FROM S_TimeExpenseLine el " - + "WHERE e.S_TimeExpense_ID=el.S_TimeExpense_ID" - + " AND el.C_InvoiceLine_ID IS NULL" - + " AND el.ConvertedAmt<>0) " - + "ORDER BY e.C_BPartner_ID, e.S_TimeExpense_ID"); + sql.append(" AND EXISTS (SELECT * FROM S_TimeExpenseLine el ") + .append("WHERE e.S_TimeExpense_ID=el.S_TimeExpense_ID") + .append(" AND el.C_InvoiceLine_ID IS NULL") + .append(" AND el.ConvertedAmt<>0) ") + .append("ORDER BY e.C_BPartner_ID, e.S_TimeExpense_ID"); // int old_BPartner_ID = -1; MInvoice invoice = null; @@ -128,18 +128,19 @@ public class ExpenseAPInvoice extends SvrProcess invoice.setBPartner(bp); if (invoice.getC_BPartner_Location_ID() == 0) { - log.log(Level.SEVERE, "No BP Location: " + bp); - addLog(0, te.getDateReport(), - null, "No Location: " + te.getDocumentNo() + " " + bp.getName()); + StringBuilder msglog = new StringBuilder("No BP Location: ").append(bp); + log.log(Level.SEVERE, msglog.toString()); + msglog = new StringBuilder("No Location: ").append(te.getDocumentNo()).append(" ").append(bp.getName()); + addLog(0, te.getDateReport(), null, msglog.toString() ); invoice = null; break; } invoice.setM_PriceList_ID(te.getM_PriceList_ID()); invoice.setSalesRep_ID(te.getDoc_User_ID()); - String descr = Msg.translate(getCtx(), "S_TimeExpense_ID") - + ": " + te.getDocumentNo() + " " - + DisplayType.getDateFormat(DisplayType.Date).format(te.getDateReport()); - invoice.setDescription(descr); + StringBuilder descr = new StringBuilder(Msg.translate(getCtx(), "S_TimeExpense_ID")) + .append(": ").append(te.getDocumentNo()).append(" " ) + .append(DisplayType.getDateFormat(DisplayType.Date).format(te.getDateReport())); + invoice.setDescription(descr.toString()); if (!invoice.save()) new IllegalStateException("Cannot save Invoice"); old_BPartner_ID = bp.getC_BPartner_ID(); @@ -200,7 +201,8 @@ public class ExpenseAPInvoice extends SvrProcess rs = null; pstmt = null; } completeInvoice (invoice); - return "@Created@=" + m_noInvoices; + StringBuilder msgreturn = new StringBuilder("@Created@=").append(m_noInvoices); + return msgreturn.toString(); } // doIt /** @@ -213,8 +215,9 @@ public class ExpenseAPInvoice extends SvrProcess return; invoice.setDocAction(DocAction.ACTION_Prepare); if (!invoice.processIt(DocAction.ACTION_Prepare)) { - log.warning("Invoice Process Failed: " + invoice + " - " + invoice.getProcessMsg()); - throw new IllegalStateException("Invoice Process Failed: " + invoice + " - " + invoice.getProcessMsg()); + StringBuilder msglog = new StringBuilder("Invoice Process Failed: ").append(invoice).append(" - ").append(invoice.getProcessMsg()); + log.warning(msglog.toString()); + throw new IllegalStateException(msglog.toString()); } if (!invoice.save()) diff --git a/org.adempiere.base.process/src/org/compiere/process/ExpenseSOrder.java b/org.adempiere.base.process/src/org/compiere/process/ExpenseSOrder.java index a60b9852d6..b494651fb1 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ExpenseSOrder.java +++ b/org.adempiere.base.process/src/org/compiere/process/ExpenseSOrder.java @@ -84,18 +84,18 @@ public class ExpenseSOrder extends SvrProcess */ protected String doIt() throws java.lang.Exception { - StringBuffer sql = new StringBuffer("SELECT * FROM S_TimeExpenseLine el " - + "WHERE el.AD_Client_ID=?" // #1 - + " AND el.C_BPartner_ID>0 AND el.IsInvoiced='Y'" // Business Partner && to be invoiced - + " AND el.C_OrderLine_ID IS NULL" // not invoiced yet - + " AND EXISTS (SELECT * FROM S_TimeExpense e " // processed only - + "WHERE el.S_TimeExpense_ID=e.S_TimeExpense_ID AND e.Processed='Y')"); + StringBuilder sql = new StringBuilder("SELECT * FROM S_TimeExpenseLine el ") + .append("WHERE el.AD_Client_ID=?") // #1 + .append(" AND el.C_BPartner_ID>0 AND el.IsInvoiced='Y'") // Business Partner && to be invoiced + .append(" AND el.C_OrderLine_ID IS NULL") // not invoiced yet + .append(" AND EXISTS (SELECT * FROM S_TimeExpense e ") // processed only + .append("WHERE el.S_TimeExpense_ID=e.S_TimeExpense_ID AND e.Processed='Y')"); if (p_C_BPartner_ID != 0) sql.append(" AND el.C_BPartner_ID=?"); // #2 if (p_DateFrom != null || m_DateTo != null) { - sql.append(" AND EXISTS (SELECT * FROM S_TimeExpense e " - + "WHERE el.S_TimeExpense_ID=e.S_TimeExpense_ID"); + sql.append(" AND EXISTS (SELECT * FROM S_TimeExpense e ") + .append("WHERE el.S_TimeExpense_ID=e.S_TimeExpense_ID"); if (p_DateFrom != null) sql.append(" AND e.DateReport >= ?"); // #3 if (m_DateTo != null) @@ -158,8 +158,8 @@ public class ExpenseSOrder extends SvrProcess rs = null; pstmt = null; } completeOrder (); - - return "@Created@=" + m_noOrders; + StringBuilder msgreturn = new StringBuilder("@Created@=").append(m_noOrders); + return msgreturn.toString(); } // doIt /** @@ -180,9 +180,11 @@ public class ExpenseSOrder extends SvrProcess m_order.setBPartner(bp); if (m_order.getC_BPartner_Location_ID() == 0) { - log.log(Level.SEVERE, "No BP Location: " + bp); + StringBuilder msglog = new StringBuilder("No BP Location: ").append(bp); + log.log(Level.SEVERE, msglog.toString()); + msglog = new StringBuilder("No Location: ").append(te.getDocumentNo()).append(" ").append(bp.getName()); addLog(0, te.getDateReport(), - null, "No Location: " + te.getDocumentNo() + " " + bp.getName()); + null, msglog.toString()); m_order = null; return; } @@ -271,8 +273,10 @@ public class ExpenseSOrder extends SvrProcess return; m_order.setDocAction(DocAction.ACTION_Prepare); if (!m_order.processIt(DocAction.ACTION_Prepare)) { - log.warning("Order Process Failed: " + m_order + " - " + m_order.getProcessMsg()); - throw new IllegalStateException("Order Process Failed: " + m_order + " - " + m_order.getProcessMsg()); + StringBuilder msglog = new StringBuilder("Order Process Failed: ").append(m_order).append(" - ").append(m_order.getProcessMsg()); + log.warning(msglog.toString()); + msglog = new StringBuilder("Order Process Failed: ").append(m_order).append(" - ").append(m_order.getProcessMsg()); + throw new IllegalStateException(msglog.toString()); } if (!m_order.save()) throw new IllegalStateException("Cannot save Order"); diff --git a/org.adempiere.base.process/src/org/compiere/process/FactAcctSummary.java b/org.adempiere.base.process/src/org/compiere/process/FactAcctSummary.java index 60f1f18f60..389297eb12 100644 --- a/org.adempiere.base.process/src/org/compiere/process/FactAcctSummary.java +++ b/org.adempiere.base.process/src/org/compiere/process/FactAcctSummary.java @@ -55,11 +55,11 @@ public class FactAcctSummary extends SvrProcess { @Override protected String doIt() throws Exception { - String where = ""; + StringBuilder where = new StringBuilder(); if ( p_Cube_ID > 0) - where = "PA_ReportCube_ID = " + p_Cube_ID; + where = new StringBuilder("PA_ReportCube_ID = ").append(p_Cube_ID); - List cubes = new Query(getCtx(), MReportCube.Table_Name, where, get_TrxName()) + List cubes = new Query(getCtx(), MReportCube.Table_Name, where.toString(), get_TrxName()) .setOnlyActiveRecords(true).setClient_ID() .list(); diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportAccount.java b/org.adempiere.base.process/src/org/compiere/process/ImportAccount.java index ff377ffe29..68f54f42a6 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportAccount.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportAccount.java @@ -88,35 +88,35 @@ public class ImportAccount extends SvrProcess */ protected String doIt() throws java.lang.Exception { - StringBuffer sql = null; + StringBuilder sql = null; int no = 0; - String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID; + StringBuilder clientCheck = new StringBuilder(" AND AD_Client_ID=").append(m_AD_Client_ID); // **** Prepare **** // Delete Old Imported if (m_deleteOldImported) { - sql = new StringBuffer ("DELETE I_ElementValue " - + "WHERE I_IsImported='Y'").append(clientCheck); + sql = new StringBuilder ("DELETE I_ElementValue ") + .append("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_ElementValue " - + "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 = ' '," - + " Processed = 'N', " - + " Processing = 'Y', " - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),") + .append(" AD_Org_ID = COALESCE (AD_Org_ID, 0),") + .append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" Processed = 'N', ") + .append(" Processing = 'Y', ") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Reset=" + no); @@ -125,53 +125,53 @@ public class ImportAccount extends SvrProcess // Set Element if (m_C_Element_ID != 0) { - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET ElementName=(SELECT Name FROM C_Element WHERE C_Element_ID=").append(m_C_Element_ID).append(") " - + "WHERE ElementName IS NULL AND C_Element_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET ElementName=(SELECT Name FROM C_Element WHERE C_Element_ID=").append(m_C_Element_ID).append(") ") + .append("WHERE ElementName IS NULL AND C_Element_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Element Default=" + no); } // - sql = new StringBuffer ("UPDATE I_ElementValue i " - + "SET C_Element_ID = (SELECT C_Element_ID FROM C_Element e" - + " WHERE i.ElementName=e.Name AND i.AD_Client_ID=e.AD_Client_ID)" - + "WHERE C_Element_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue i ") + .append("SET C_Element_ID = (SELECT C_Element_ID FROM C_Element e") + .append(" WHERE i.ElementName=e.Name AND i.AD_Client_ID=e.AD_Client_ID)") + .append("WHERE C_Element_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Element=" + no); // - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Element, ' " - + "WHERE C_Element_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Element, ' ") + .append("WHERE C_Element_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid Element=" + no); // No Name, Value - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Name, ' " - + "WHERE (Value IS NULL OR Name IS NULL)" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Name, ' ") + .append("WHERE (Value IS NULL OR Name IS NULL)") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid Name=" + no); // Set Column - sql = new StringBuffer ("UPDATE I_ElementValue i " - + "SET AD_Column_ID = (SELECT AD_Column_ID FROM AD_Column c" - + " WHERE UPPER(i.Default_Account)=UPPER(c.ColumnName)" - + " AND c.AD_Table_ID IN (315,266) AND AD_Reference_ID=25) " - + "WHERE Default_Account IS NOT NULL AND AD_Column_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue i ") + .append("SET AD_Column_ID = (SELECT AD_Column_ID FROM AD_Column c") + .append(" WHERE UPPER(i.Default_Account)=UPPER(c.ColumnName)") + .append(" AND c.AD_Table_ID IN (315,266) AND AD_Reference_ID=25) ") + .append("WHERE Default_Account IS NOT NULL AND AD_Column_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Column=" + no); // - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Column, ' " - + "WHERE AD_Column_ID IS NULL AND Default_Account IS NOT NULL" - + " AND UPPER(Default_Account)<>'DEFAULT_ACCT'" // ignore default account - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Column, ' ") + .append("WHERE AD_Column_ID IS NULL AND Default_Account IS NOT NULL") + .append(" AND UPPER(Default_Account)<>'DEFAULT_ACCT'") // ignore default account + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid Column=" + no); @@ -179,76 +179,77 @@ public class ImportAccount extends SvrProcess String[] yColumns = new String[] {"PostActual", "PostBudget", "PostStatistical", "PostEncumbrance"}; for (int i = 0; i < yColumns.length; i++) { - sql = new StringBuffer ("UPDATE I_ElementValue SET ") + sql = new StringBuilder ("UPDATE I_ElementValue SET ") .append(yColumns[i]).append("='Y' WHERE ") .append(yColumns[i]).append(" IS NULL OR ") - .append(yColumns[i]).append(" NOT IN ('Y','N')" - + " AND I_IsImported<>'Y'").append(clientCheck); + .append(yColumns[i]).append(" NOT IN ('Y','N')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); - log.fine("Set " + yColumns[i] + " Default=" + no); + StringBuilder msglog = new StringBuilder("Set ").append(yColumns[i]).append(" Default=").append(no); + log.fine(msglog.toString()); } // Summary - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET IsSummary='N' " - + "WHERE IsSummary IS NULL OR IsSummary NOT IN ('Y','N')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET IsSummary='N' ") + .append("WHERE IsSummary IS NULL OR IsSummary NOT IN ('Y','N')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set IsSummary Default=" + no); // Doc Controlled - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET IsDocControlled = CASE WHEN AD_Column_ID IS NOT NULL THEN 'Y' ELSE 'N' END " - + "WHERE IsDocControlled IS NULL OR IsDocControlled NOT IN ('Y','N')" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET IsDocControlled = CASE WHEN AD_Column_ID IS NOT NULL THEN 'Y' ELSE 'N' END ") + .append("WHERE IsDocControlled IS NULL OR IsDocControlled NOT IN ('Y','N')") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set IsDocumentControlled Default=" + no); // Check Account Type A (E) L M O R - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET AccountType='E' " - + "WHERE AccountType IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET AccountType='E' ") + .append("WHERE AccountType IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set AccountType Default=" + no); // - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid AccountType, ' " - + "WHERE AccountType NOT IN ('A','E','L','M','O','R')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid AccountType, ' ") + .append("WHERE AccountType NOT IN ('A','E','L','M','O','R')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid AccountType=" + no); // Check Account Sign (N) C B - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET AccountSign='N' " - + "WHERE AccountSign IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET AccountSign='N' ") + .append("WHERE AccountSign IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set AccountSign Default=" + no); // - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid AccountSign, ' " - + "WHERE AccountSign NOT IN ('N','C','D')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid AccountSign, ' ") + .append("WHERE AccountSign NOT IN ('N','C','D')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid AccountSign=" + no); // No Value - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Key, ' " - + "WHERE (Value IS NULL OR Value='')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Key, ' ") + .append("WHERE (Value IS NULL OR Value='')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid Key=" + no); // **** Update ElementValue from existing - sql = new StringBuffer ("UPDATE I_ElementValue i " - + "SET C_ElementValue_ID=(SELECT C_ElementValue_ID FROM C_ElementValue ev" - + " INNER JOIN C_Element e ON (ev.C_Element_ID=e.C_Element_ID)" - + " WHERE i.C_Element_ID=e.C_Element_ID AND i.AD_Client_ID=e.AD_Client_ID" - + " AND i.Value=ev.Value) " - + "WHERE C_ElementValue_ID IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue i ") + .append("SET C_ElementValue_ID=(SELECT C_ElementValue_ID FROM C_ElementValue ev") + .append(" INNER JOIN C_Element e ON (ev.C_Element_ID=e.C_Element_ID)") + .append(" WHERE i.C_Element_ID=e.C_Element_ID AND i.AD_Client_ID=e.AD_Client_ID") + .append(" AND i.Value=ev.Value) ") + .append("WHERE C_ElementValue_ID IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Found ElementValue=" + no); @@ -259,9 +260,9 @@ public class ImportAccount extends SvrProcess int noUpdate = 0; // Go through Records - sql = new StringBuffer ("SELECT * " - + "FROM I_ElementValue " - + "WHERE I_IsImported='N'").append(clientCheck) + sql = new StringBuilder ("SELECT * ") + .append("FROM I_ElementValue ") + .append("WHERE I_IsImported='N'").append(clientCheck) .append(" ORDER BY I_ElementValue_ID"); try { @@ -286,8 +287,8 @@ public class ImportAccount extends SvrProcess } else { - sql = new StringBuffer ("UPDATE I_ElementValue i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert ElementValue ")) + sql = new StringBuilder ("UPDATE I_ElementValue i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert ElementValue ")) .append("WHERE I_ElementValue_ID=").append(I_ElementValue_ID); DB.executeUpdate(sql.toString(), get_TrxName()); } @@ -308,8 +309,8 @@ public class ImportAccount extends SvrProcess } else { - sql = new StringBuffer ("UPDATE I_ElementValue i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Update ElementValue")) + sql = new StringBuilder ("UPDATE I_ElementValue i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Update ElementValue")) .append("WHERE I_ElementValue_ID=").append(I_ElementValue_ID); DB.executeUpdate(sql.toString(), get_TrxName()); } @@ -324,9 +325,9 @@ public class ImportAccount extends SvrProcess } // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("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_ElementValue_ID@: @Inserted@"); @@ -335,29 +336,29 @@ public class ImportAccount extends SvrProcess commitEx(); // ***** Set Parent - sql = new StringBuffer ("UPDATE I_ElementValue i " - + "SET ParentElementValue_ID=(SELECT C_ElementValue_ID" - + " FROM C_ElementValue ev WHERE i.C_Element_ID=ev.C_Element_ID" - + " AND i.ParentValue=ev.Value AND i.AD_Client_ID=ev.AD_Client_ID) " - + "WHERE ParentElementValue_ID IS NULL" - + " AND I_IsImported='Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue i ") + .append("SET ParentElementValue_ID=(SELECT C_ElementValue_ID") + .append(" FROM C_ElementValue ev WHERE i.C_Element_ID=ev.C_Element_ID") + .append(" AND i.ParentValue=ev.Value AND i.AD_Client_ID=ev.AD_Client_ID) ") + .append("WHERE ParentElementValue_ID IS NULL") + .append(" AND I_IsImported='Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Found Parent ElementValue=" + no); // - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET I_ErrorMsg=I_ErrorMsg||'Info=ParentNotFound, ' " - + "WHERE ParentElementValue_ID IS NULL AND ParentValue IS NOT NULL" - + " AND I_IsImported='Y' AND Processed='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET I_ErrorMsg=I_ErrorMsg||'Info=ParentNotFound, ' ") + .append("WHERE ParentElementValue_ID IS NULL AND ParentValue IS NOT NULL") + .append(" AND I_IsImported='Y' AND Processed='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Not Found Parent ElementValue=" + no); // - sql = new StringBuffer ("SELECT i.ParentElementValue_ID, i.I_ElementValue_ID," - + " e.AD_Tree_ID, i.C_ElementValue_ID, i.Value||'-'||i.Name AS Info " - + "FROM I_ElementValue i" - + " INNER JOIN C_Element e ON (i.C_Element_ID=e.C_Element_ID) " - + "WHERE i.C_ElementValue_ID IS NOT NULL AND e.AD_Tree_ID IS NOT NULL" - + " AND i.ParentElementValue_ID IS NOT NULL" - + " AND i.I_IsImported='Y' AND Processed='N' AND i.AD_Client_ID=").append(m_AD_Client_ID); + sql = new StringBuilder ("SELECT i.ParentElementValue_ID, i.I_ElementValue_ID,") + .append(" e.AD_Tree_ID, i.C_ElementValue_ID, i.Value||'-'||i.Name AS Info ") + .append("FROM I_ElementValue i") + .append(" INNER JOIN C_Element e ON (i.C_Element_ID=e.C_Element_ID) ") + .append("WHERE i.C_ElementValue_ID IS NOT NULL AND e.AD_Tree_ID IS NOT NULL") + .append(" AND i.ParentElementValue_ID IS NOT NULL") + .append(" AND i.I_IsImported='Y' AND Processed='N' AND i.AD_Client_ID=").append(m_AD_Client_ID); int noParentUpdate = 0; try { @@ -402,10 +403,10 @@ public class ImportAccount extends SvrProcess commitEx(); // Reset Processing Flag - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET Processing='-'" - + "WHERE I_IsImported='Y' AND Processed='N' AND Processing='Y'" - + " AND C_ElementValue_ID IS NOT NULL") + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET Processing='-'") + .append("WHERE I_IsImported='Y' AND Processed='N' AND Processing='Y'") + .append(" AND C_ElementValue_ID IS NOT NULL") .append(clientCheck); if (m_updateDefaultAccounts) sql.append(" AND AD_Column_ID IS NULL"); @@ -413,17 +414,17 @@ public class ImportAccount extends SvrProcess log.fine("Reset Processing Flag=" + no); if (m_updateDefaultAccounts) - updateDefaults(clientCheck); + updateDefaults(clientCheck.toString()); // Update Description - sql = new StringBuffer("SELECT * FROM C_ValidCombination vc " - + "WHERE EXISTS (SELECT * FROM I_ElementValue i " - + "WHERE vc.Account_ID=i.C_ElementValue_ID)"); + sql = new StringBuilder("SELECT * FROM C_ValidCombination vc ") + .append("WHERE EXISTS (SELECT * FROM I_ElementValue i ") + .append("WHERE vc.Account_ID=i.C_ElementValue_ID)"); // Done - sql = new StringBuffer ("UPDATE I_ElementValue " - + "SET Processing='N', Processed='Y'" - + "WHERE I_IsImported='Y'") + sql = new StringBuilder ("UPDATE I_ElementValue ") + .append("SET Processing='N', Processed='Y'") + .append("WHERE I_IsImported='Y'") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Processed=" + no); @@ -441,8 +442,8 @@ public class ImportAccount extends SvrProcess log.config("CreateNewCombination=" + m_createNewCombination); // **** Update Defaults - StringBuffer sql = new StringBuffer ("SELECT C_AcctSchema_ID FROM C_AcctSchema_Element " - + "WHERE C_Element_ID=?").append(clientCheck); + StringBuilder sql = new StringBuilder ("SELECT C_AcctSchema_ID FROM C_AcctSchema_Element ") + .append("WHERE C_Element_ID=?").append(clientCheck); try { PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); @@ -459,14 +460,14 @@ public class ImportAccount extends SvrProcess } // Default Account DEFAULT_ACCT - sql = new StringBuffer ("UPDATE C_AcctSchema_Element e " - + "SET C_ElementValue_ID=(SELECT C_ElementValue_ID FROM I_ElementValue i" - + " WHERE e.C_Element_ID=i.C_Element_ID AND i.C_ElementValue_ID IS NOT NULL" - + " AND UPPER(i.Default_Account)='DEFAULT_ACCT') " - + "WHERE EXISTS (SELECT * FROM I_ElementValue i" - + " WHERE e.C_Element_ID=i.C_Element_ID AND i.C_ElementValue_ID IS NOT NULL" - + " AND UPPER(i.Default_Account)='DEFAULT_ACCT' " - + " AND i.I_IsImported='Y' AND i.Processing='-')") + sql = new StringBuilder ("UPDATE C_AcctSchema_Element e ") + .append("SET C_ElementValue_ID=(SELECT C_ElementValue_ID FROM I_ElementValue i") + .append(" WHERE e.C_Element_ID=i.C_Element_ID AND i.C_ElementValue_ID IS NOT NULL") + .append(" AND UPPER(i.Default_Account)='DEFAULT_ACCT') ") + .append("WHERE EXISTS (SELECT * FROM I_ElementValue i") + .append(" WHERE e.C_Element_ID=i.C_Element_ID AND i.C_ElementValue_ID IS NOT NULL") + .append(" AND UPPER(i.Default_Account)='DEFAULT_ACCT' ") + .append(" AND i.I_IsImported='Y' AND i.Processing='-')") .append(clientCheck); int no = DB.executeUpdate(sql.toString(), get_TrxName()); addLog (0, null, new BigDecimal (no), "@C_AcctSchema_Element_ID@: @Updated@"); @@ -484,21 +485,22 @@ public class ImportAccount extends SvrProcess MAcctSchema as = new MAcctSchema (getCtx(), C_AcctSchema_ID, get_TrxName()); if (as.getAcctSchemaElement("AC").getC_Element_ID() != m_C_Element_ID) { - log.log(Level.SEVERE, "C_Element_ID=" + m_C_Element_ID + " not in AcctSchema=" + as); + StringBuilder msglog = new StringBuilder("C_Element_ID=").append(m_C_Element_ID).append(" not in AcctSchema=").append(as); + log.log(Level.SEVERE, msglog.toString()); return; } int[] counts = new int[] {0, 0, 0}; - String sql = "SELECT i.C_ElementValue_ID, t.TableName, c.ColumnName, i.I_ElementValue_ID " - + "FROM I_ElementValue i" - + " INNER JOIN AD_Column c ON (i.AD_Column_ID=c.AD_Column_ID)" - + " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID) " - + "WHERE i.I_IsImported='Y' AND Processing='Y'" - + " AND i.C_ElementValue_ID IS NOT NULL AND C_Element_ID=?"; + StringBuilder sql = new StringBuilder("SELECT i.C_ElementValue_ID, t.TableName, c.ColumnName, i.I_ElementValue_ID ") + .append("FROM I_ElementValue i") + .append(" INNER JOIN AD_Column c ON (i.AD_Column_ID=c.AD_Column_ID)") + .append(" INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID) ") + .append("WHERE i.I_IsImported='Y' AND Processing='Y'") + .append(" AND i.C_ElementValue_ID IS NOT NULL AND C_Element_ID=?"); try { - PreparedStatement pstmt = DB.prepareStatement(sql, get_TrxName()); + PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); pstmt.setInt(1, m_C_Element_ID); ResultSet rs = pstmt.executeQuery(); while (rs.next()) @@ -512,8 +514,8 @@ public class ImportAccount extends SvrProcess counts[u]++; if (u != UPDATE_ERROR) { - sql = "UPDATE I_ElementValue SET Processing='N' " - + "WHERE I_ElementValue_ID=" + I_ElementValue_ID; + sql = new StringBuilder("UPDATE I_ElementValue SET Processing='N' ") + .append("WHERE I_ElementValue_ID=").append(I_ElementValue_ID); int no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 1) log.log(Level.SEVERE, "Updated=" + no); @@ -552,9 +554,10 @@ public class ImportAccount extends SvrProcess */ private int updateDefaultAccount (String TableName, String ColumnName, int C_AcctSchema_ID, int C_ElementValue_ID) { - log.fine(TableName + "." + ColumnName + " - " + C_ElementValue_ID); + StringBuilder msglog = new StringBuilder(TableName).append(".").append(ColumnName).append(" - ").append(C_ElementValue_ID); + log.fine(msglog.toString()); int retValue = UPDATE_ERROR; - StringBuffer sql = new StringBuffer ("SELECT x.") + StringBuilder sql = new StringBuilder ("SELECT x.") .append(ColumnName).append(",Account_ID FROM ") .append(TableName).append(" x INNER JOIN C_ValidCombination vc ON (x.") .append(ColumnName).append("=vc.C_ValidCombination_ID) ") @@ -586,13 +589,14 @@ public class ImportAccount extends SvrProcess int newC_ValidCombination_ID = acct.getC_ValidCombination_ID(); if (C_ValidCombination_ID != newC_ValidCombination_ID) { - sql = new StringBuffer ("UPDATE ").append(TableName) + sql = new StringBuilder ("UPDATE ").append(TableName) .append(" SET ").append(ColumnName).append("=").append(newC_ValidCombination_ID) .append(" WHERE C_AcctSchema_ID=").append(C_AcctSchema_ID); int no = DB.executeUpdate(sql.toString(), get_TrxName()); - log.fine("New #" + no + " - " - + TableName + "." + ColumnName + " - " + C_ElementValue_ID - + " -- " + C_ValidCombination_ID + " -> " + newC_ValidCombination_ID); + msglog = new StringBuilder("New #").append(no).append(" - ") + .append(TableName).append(".").append(ColumnName).append(" - ").append(C_ElementValue_ID) + .append(" -- ").append(C_ValidCombination_ID).append(" -> ").append(newC_ValidCombination_ID); + log.fine(msglog.toString()); if (no == 1) retValue = UPDATE_YES; } @@ -603,25 +607,28 @@ public class ImportAccount extends SvrProcess else // Replace Combination { // Only Acct Combination directly - sql = new StringBuffer ("UPDATE C_ValidCombination SET Account_ID=") + sql = new StringBuilder ("UPDATE C_ValidCombination SET Account_ID=") .append(C_ElementValue_ID).append(" WHERE C_ValidCombination_ID=").append(C_ValidCombination_ID); int no = DB.executeUpdate(sql.toString(), get_TrxName()); - log.fine("Replace #" + no + " - " - + "C_ValidCombination_ID=" + C_ValidCombination_ID + ", New Account_ID=" + C_ElementValue_ID); + msglog = new StringBuilder("Replace #").append(no).append(" - ") + .append("C_ValidCombination_ID=").append(C_ValidCombination_ID).append(", New Account_ID=").append(C_ElementValue_ID); + log.fine(msglog.toString()); if (no == 1) { retValue = UPDATE_YES; // Where Acct was used - sql = new StringBuffer ("UPDATE C_ValidCombination SET Account_ID=") + sql = new StringBuilder ("UPDATE C_ValidCombination SET Account_ID=") .append(C_ElementValue_ID).append(" WHERE Account_ID=").append(Account_ID); no = DB.executeUpdate(sql.toString(), get_TrxName()); - log.fine("ImportAccount.updateDefaultAccount - Replace VC #" + no + " - " - + "Account_ID=" + Account_ID + ", New Account_ID=" + C_ElementValue_ID); - sql = new StringBuffer ("UPDATE Fact_Acct SET Account_ID=") + msglog = new StringBuilder("ImportAccount.updateDefaultAccount - Replace VC #").append(no).append(" - ") + .append("Account_ID=").append(Account_ID).append(", New Account_ID=").append(C_ElementValue_ID); + log.fine(msglog.toString()); + sql = new StringBuilder ("UPDATE Fact_Acct SET Account_ID=") .append(C_ElementValue_ID).append(" WHERE Account_ID=").append(Account_ID); no = DB.executeUpdate(sql.toString(), get_TrxName()); - log.fine("ImportAccount.updateDefaultAccount - Replace Fact #" + no + " - " - + "Account_ID=" + Account_ID + ", New Account_ID=" + C_ElementValue_ID); + msglog = new StringBuilder("ImportAccount.updateDefaultAccount - Replace Fact #").append(no).append(" - ") + .append("Account_ID=").append(Account_ID).append(", New Account_ID=").append(C_ElementValue_ID); + log.fine(msglog.toString()); } } // replace combination } // need to update diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportBPartner.java b/org.adempiere.base.process/src/org/compiere/process/ImportBPartner.java index be27f2c990..e3234ad12d 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportBPartner.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportBPartner.java @@ -91,7 +91,7 @@ implements ImportProcess */ protected String doIt() throws java.lang.Exception { - StringBuffer sql = null; + StringBuilder sql = null; int no = 0; String clientCheck = getWhereClause(); @@ -100,50 +100,50 @@ implements ImportProcess // Delete Old Imported if (m_deleteOldImported) { - sql = new StringBuffer ("DELETE I_BPartner " - + "WHERE I_IsImported='Y'").append(clientCheck); + sql = new StringBuilder ("DELETE I_BPartner ") + .append("WHERE I_IsImported='Y'").append(clientCheck); no = DB.executeUpdateEx(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 = ' '," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql = new StringBuilder ("UPDATE I_BPartner ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),") + .append(" AD_Org_ID = COALESCE (AD_Org_ID, 0),") + .append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdateEx(sql.toString(), get_TrxName()); log.fine("Reset=" + no); ModelValidationEngine.get().fireImportValidate(this, null, null, ImportValidator.TIMING_BEFORE_VALIDATE); // Set BP_Group - sql = new StringBuffer ("UPDATE I_BPartner i " - + "SET GroupValue=(SELECT MAX(Value) FROM C_BP_Group g WHERE g.IsDefault='Y'" - + " AND g.AD_Client_ID=i.AD_Client_ID) "); - sql.append("WHERE GroupValue IS NULL AND C_BP_Group_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET GroupValue=(SELECT MAX(Value) FROM C_BP_Group g WHERE g.IsDefault='Y'") + .append(" AND g.AD_Client_ID=i.AD_Client_ID) "); + sql.append("WHERE GroupValue IS NULL AND C_BP_Group_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET C_BP_Group_ID=(SELECT C_BP_Group_ID FROM C_BP_Group g") + .append(" WHERE i.GroupValue=g.Value AND g.AD_Client_ID=i.AD_Client_ID) ") + .append("WHERE C_BP_Group_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Group, ' ") + .append("WHERE C_BP_Group_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(sql.toString(), get_TrxName()); log.config("Invalid Group=" + no); @@ -158,123 +158,123 @@ implements ImportProcess 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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET C_Country_ID=(SELECT C_Country_ID FROM C_Country c") + .append(" WHERE i.CountryCode=c.CountryCode AND c.AD_Client_ID IN (0, i.AD_Client_ID)) ") + .append("WHERE C_Country_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Country, ' ") + .append("WHERE C_Country_ID IS NULL AND (City IS NOT NULL OR Address1 IS NOT NULL)") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(sql.toString(), get_TrxName()); log.config("Invalid Country=" + no); // Set Region - sql = new StringBuffer ("UPDATE I_BPartner i " - + "Set RegionName=(SELECT MAX(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)) " ); - sql.append("WHERE RegionName IS NULL AND C_Region_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("Set RegionName=(SELECT MAX(Name) FROM C_Region r") + .append(" WHERE r.IsDefault='Y' AND r.C_Country_ID=i.C_Country_ID") + .append(" AND r.AD_Client_ID IN (0, i.AD_Client_ID)) " ); + sql.append("WHERE RegionName IS NULL AND C_Region_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("Set C_Region_ID=(SELECT C_Region_ID FROM C_Region r") + .append(" WHERE r.Name=i.RegionName AND r.C_Country_ID=i.C_Country_ID") + .append(" AND r.AD_Client_ID IN (0, i.AD_Client_ID)) ") + .append("WHERE C_Region_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Region, ' ") + .append("WHERE C_Region_ID IS NULL ") + .append(" AND EXISTS (SELECT * FROM C_Country c") + .append(" WHERE c.C_Country_ID=i.C_Country_ID AND c.HasRegion='Y')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET C_Greeting_ID=(SELECT C_Greeting_ID FROM C_Greeting g") + .append(" WHERE i.BPContactGreeting=g.Name AND g.AD_Client_ID IN (0, i.AD_Client_ID)) ") + .append("WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Greeting, ' ") + .append("WHERE C_Greeting_ID IS NULL AND BPContactGreeting IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET (C_BPartner_ID,AD_User_ID)=") + .append("(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u ") + .append("WHERE i.EMail=u.EMail AND u.AD_Client_ID=i.AD_Client_ID) ") + .append("WHERE i.EMail IS NOT NULL AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner p") + .append(" WHERE i.Value=p.Value AND p.AD_Client_ID=i.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NULL AND Value IS NOT NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET AD_User_ID=(SELECT AD_User_ID FROM AD_User c") + .append(" WHERE i.ContactName=c.Name AND i.C_BPartner_ID=c.C_BPartner_ID AND c.AD_Client_ID=i.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NOT NULL AND AD_User_ID IS NULL AND ContactName IS NOT NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdateEx(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 (i.Address1=l.Address1 OR (i.Address1 IS NULL AND l.Address1 IS NULL))" - + " AND (i.Address2=l.Address2 OR (i.Address2 IS NULL AND l.Address2 IS NULL))" - + " AND (i.City=l.City OR (i.City IS NULL AND l.City IS NULL))" - + " AND (i.Postal=l.Postal OR (i.Postal IS NULL AND l.Postal IS NULL))" - + " AND (i.Postal_Add=l.Postal_Add OR (l.Postal_Add IS NULL AND l.Postal_Add IS NULL))" - + " AND (i.C_Region_ID=l.C_Region_ID OR (l.C_Region_ID IS NULL AND i.C_Region_ID IS NULL))" - + " AND i.C_Country_ID=l.C_Country_ID) " - + "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET C_BPartner_Location_ID=(SELECT C_BPartner_Location_ID") + .append(" FROM C_BPartner_Location bpl INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)") + .append(" WHERE i.C_BPartner_ID=bpl.C_BPartner_ID AND bpl.AD_Client_ID=i.AD_Client_ID") + .append(" AND (i.Address1=l.Address1 OR (i.Address1 IS NULL AND l.Address1 IS NULL))") + .append(" AND (i.Address2=l.Address2 OR (i.Address2 IS NULL AND l.Address2 IS NULL))") + .append(" AND (i.City=l.City OR (i.City IS NULL AND l.City IS NULL))") + .append(" AND (i.Postal=l.Postal OR (i.Postal IS NULL AND l.Postal IS NULL))") + .append(" AND (i.Postal_Add=l.Postal_Add OR (l.Postal_Add IS NULL AND l.Postal_Add IS NULL))") + .append(" AND (i.C_Region_ID=l.C_Region_ID OR (l.C_Region_ID IS NULL AND i.C_Region_ID IS NULL))") + .append(" AND i.C_Country_ID=l.C_Country_ID) ") + .append("WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdateEx(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); + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET R_InterestArea_ID=(SELECT R_InterestArea_ID FROM R_InterestArea ia ") + .append("WHERE i.InterestAreaName=ia.Name AND ia.AD_Client_ID=i.AD_Client_ID) ") + .append("WHERE R_InterestArea_ID IS NULL AND InterestAreaName IS NOT NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdateEx(sql.toString(), get_TrxName()); log.fine("Set Interest Area=" + no); // Value is mandatory error - sql = new StringBuffer ("UPDATE I_BPartner " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Value is mandatory, ' " - + "WHERE Value IS NULL " - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_BPartner ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Value is mandatory, ' ") + .append("WHERE Value IS NULL ") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(sql.toString(), get_TrxName()); log.config("Value is mandatory=" + no); @@ -290,8 +290,8 @@ implements ImportProcess int noUpdate = 0; // Go through Records - sql = new StringBuffer ("SELECT * FROM I_BPartner " - + "WHERE I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("SELECT * FROM I_BPartner ") + .append("WHERE I_IsImported='N'").append(clientCheck); // gody: 20070113 - Order so the same values are consecutive. sql.append(" ORDER BY Value, I_BPartner_ID"); PreparedStatement pstmt = null; @@ -313,11 +313,12 @@ implements ImportProcess // Remember Value - only first occurance of the value is BP String New_BPValue = rs.getString("Value") ; - 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()); + X_I_BPartner impBP = new X_I_BPartner (getCtx(), rs, get_TrxName()); + StringBuilder msglog = new StringBuilder("I_BPartner_ID=") .append(impBP.getI_BPartner_ID()) + .append(", C_BPartner_ID=").append(impBP.getC_BPartner_ID()) + .append(", C_BPartner_Location_ID=").append(impBP.getC_BPartner_Location_ID()) + .append(", AD_User_ID=").append(impBP.getAD_User_ID()); + log.fine(msglog.toString()); if ( ! New_BPValue.equals(Old_BPValue)) { @@ -333,14 +334,15 @@ implements ImportProcess if (bp.save()) { - impBP.setC_BPartner_ID(bp.getC_BPartner_ID()); - log.finest("Insert BPartner - " + bp.getC_BPartner_ID()); + impBP.setC_BPartner_ID(bp.getC_BPartner_ID()); + msglog = new StringBuilder("Insert BPartner - ").append(bp.getC_BPartner_ID()); + log.finest(msglog.toString()); noInsert++; } else { - sql = new StringBuffer ("UPDATE I_BPartner i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") .append("'Cannot Insert BPartner, ' ") .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); DB.executeUpdateEx(sql.toString(), get_TrxName()); @@ -374,13 +376,14 @@ implements ImportProcess // if (bp.save()) { - log.finest("Update BPartner - " + bp.getC_BPartner_ID()); + msglog = new StringBuilder("Update BPartner - ").append(bp.getC_BPartner_ID()); + log.finest(msglog.toString()); noUpdate++; } else { - sql = new StringBuffer ("UPDATE I_BPartner i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") .append("'Cannot Update BPartner, ' ") .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); DB.executeUpdateEx(sql.toString(), get_TrxName()); @@ -425,14 +428,16 @@ implements ImportProcess 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()); + if (location.save()){ + msglog = new StringBuilder("Insert Location - ").append(location.getC_Location_ID()); + log.finest(msglog.toString()); + } else { rollback(); noInsert--; - sql = new StringBuffer ("UPDATE I_BPartner i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") .append("'Cannot Insert Location, ' ") .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); DB.executeUpdateEx(sql.toString(), get_TrxName()); @@ -447,15 +452,16 @@ implements ImportProcess ModelValidationEngine.get().fireImportValidate(this, impBP, bpl, ImportValidator.TIMING_AFTER_IMPORT); if (bpl.save()) { - log.finest("Insert BP Location - " + bpl.getC_BPartner_Location_ID()); + msglog = new StringBuilder("Insert BP Location - ").append(bpl.getC_BPartner_Location_ID()); + log.finest(msglog.toString()); 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||") + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") .append("'Cannot Insert BPLocation, ' ") .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); DB.executeUpdateEx(sql.toString(), get_TrxName()); @@ -477,8 +483,8 @@ implements ImportProcess { rollback(); noInsert--; - sql = new StringBuffer ("UPDATE I_BPartner i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") .append("'BP of User <> BP, ' ") .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); DB.executeUpdateEx(sql.toString(), get_TrxName()); @@ -511,14 +517,15 @@ implements ImportProcess ModelValidationEngine.get().fireImportValidate(this, impBP, user, ImportValidator.TIMING_AFTER_IMPORT); if (user.save()) { - log.finest("Update BP Contact - " + user.getAD_User_ID()); + msglog = new StringBuilder("Update BP Contact - ").append(user.getAD_User_ID()); + log.finest(msglog.toString()); } else { rollback(); noInsert--; - sql = new StringBuffer ("UPDATE I_BPartner i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") .append("'Cannot Update BP Contact, ' ") .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); DB.executeUpdateEx(sql.toString(), get_TrxName()); @@ -548,15 +555,16 @@ implements ImportProcess ModelValidationEngine.get().fireImportValidate(this, impBP, user, ImportValidator.TIMING_AFTER_IMPORT); if (user.save()) { - log.finest("Insert BP Contact - " + user.getAD_User_ID()); + msglog = new StringBuilder("Insert BP Contact - ").append(user.getAD_User_ID()); + log.finest(msglog.toString()); 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||") + sql = new StringBuilder ("UPDATE I_BPartner i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||") .append("'Cannot Insert BPContact, ' ") .append("WHERE I_BPartner_ID=").append(impBP.getI_BPartner_ID()); DB.executeUpdateEx(sql.toString(), get_TrxName()); @@ -592,9 +600,9 @@ implements ImportProcess DB.close(rs, pstmt); rs = null; pstmt = null; // 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); + sql = new StringBuilder ("UPDATE I_BPartner ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("WHERE I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdateEx(sql.toString(), get_TrxName()); addLog (0, null, new BigDecimal (no), "@Errors@"); addLog (0, null, new BigDecimal (noInsert), "@C_BPartner_ID@: @Inserted@"); @@ -607,7 +615,8 @@ implements ImportProcess //@Override public String getWhereClause() { - return " AND AD_Client_ID=" + m_AD_Client_ID; + StringBuilder msgreturn = new StringBuilder(" AND AD_Client_ID=").append(m_AD_Client_ID); + return msgreturn.toString(); } diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportBankStatement.java b/org.adempiere.base.process/src/org/compiere/process/ImportBankStatement.java index 327147eed7..f608302731 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportBankStatement.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportBankStatement.java @@ -82,249 +82,250 @@ public class ImportBankStatement extends SvrProcess */ protected String doIt() throws java.lang.Exception { - log.info("AD_Org_ID=" + p_AD_Org_ID + ", C_BankAccount_ID" + p_C_BankAccount_ID); - StringBuffer sql = null; + StringBuilder msglog = new StringBuilder("AD_Org_ID=").append(p_AD_Org_ID).append(", C_BankAccount_ID").append(p_C_BankAccount_ID); + log.info(msglog.toString()); + StringBuilder sql = null; int no = 0; - String clientCheck = " AND AD_Client_ID=" + p_AD_Client_ID; + StringBuilder clientCheck = new StringBuilder(" AND AD_Client_ID=").append(p_AD_Client_ID); // **** Prepare **** // Delete Old Imported if (p_deleteOldImported) { - sql = new StringBuffer ("DELETE I_BankStatement " - + "WHERE I_IsImported='Y'").append (clientCheck); + sql = new StringBuilder ("DELETE I_BankStatement ") + .append("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_BankStatement " - + "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (p_AD_Client_ID).append (")," - + " AD_Org_ID = COALESCE (AD_Org_ID,").append (p_AD_Org_ID).append ("),"); - sql.append(" IsActive = COALESCE (IsActive, 'Y')," - + " Created = COALESCE (Created, SysDate)," - + " CreatedBy = COALESCE (CreatedBy, 0)," - + " Updated = COALESCE (Updated, SysDate)," - + " UpdatedBy = COALESCE (UpdatedBy, 0)," - + " I_ErrorMsg = ' '," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL OR AD_Client_ID IS NULL OR AD_Org_ID IS NULL OR AD_Client_ID=0 OR AD_Org_ID=0"); + sql = new StringBuilder ("UPDATE I_BankStatement ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID,").append (p_AD_Client_ID).append ("),") + .append(" AD_Org_ID = COALESCE (AD_Org_ID,").append (p_AD_Org_ID).append ("),"); + sql.append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL OR AD_Client_ID IS NULL OR AD_Org_ID IS NULL OR AD_Client_ID=0 OR AD_Org_ID=0"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info ("Reset=" + no); - sql = new StringBuffer ("UPDATE I_BankStatement o " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '" - + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0" - + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_BankStatement o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '") + .append("WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0") + .append(" OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Org=" + no); // Set Bank Account - sql = new StringBuffer("UPDATE I_BankStatement i " - + "SET C_BankAccount_ID=" - + "( " - + " SELECT C_BankAccount_ID " - + " FROM C_BankAccount a, C_Bank b " - + " WHERE b.IsOwnBank='Y' " - + " AND a.AD_Client_ID=i.AD_Client_ID " - + " AND a.C_Bank_ID=b.C_Bank_ID " - + " AND a.AccountNo=i.BankAccountNo " - + " AND b.RoutingNo=i.RoutingNo " - + " OR b.SwiftCode=i.RoutingNo " - + ") " - + "WHERE i.C_BankAccount_ID IS NULL " - + "AND i.I_IsImported<>'Y' " - + "OR i.I_IsImported IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement i ") + .append("SET C_BankAccount_ID=") + .append("( ") + .append(" SELECT C_BankAccount_ID ") + .append(" FROM C_BankAccount a, C_Bank b ") + .append(" WHERE b.IsOwnBank='Y' ") + .append(" AND a.AD_Client_ID=i.AD_Client_ID ") + .append(" AND a.C_Bank_ID=b.C_Bank_ID ") + .append(" AND a.AccountNo=i.BankAccountNo ") + .append(" AND b.RoutingNo=i.RoutingNo ") + .append(" OR b.SwiftCode=i.RoutingNo ") + .append(") ") + .append("WHERE i.C_BankAccount_ID IS NULL ") + .append("AND i.I_IsImported<>'Y' ") + .append("OR i.I_IsImported IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Bank Account (With Routing No)=" + no); // - sql = new StringBuffer("UPDATE I_BankStatement i " - + "SET C_BankAccount_ID=" - + "( " - + " SELECT C_BankAccount_ID " - + " FROM C_BankAccount a, C_Bank b " - + " WHERE b.IsOwnBank='Y' " - + " AND a.C_Bank_ID=b.C_Bank_ID " - + " AND a.AccountNo=i.BankAccountNo " - + " AND a.AD_Client_ID=i.AD_Client_ID " - + ") " - + "WHERE i.C_BankAccount_ID IS NULL " - + "AND i.I_isImported<>'Y' " - + "OR i.I_isImported IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement i ") + .append("SET C_BankAccount_ID=") + .append("( ") + .append(" SELECT C_BankAccount_ID ") + .append(" FROM C_BankAccount a, C_Bank b ") + .append(" WHERE b.IsOwnBank='Y' ") + .append(" AND a.C_Bank_ID=b.C_Bank_ID ") + .append(" AND a.AccountNo=i.BankAccountNo ") + .append(" AND a.AD_Client_ID=i.AD_Client_ID ") + .append(") ") + .append("WHERE i.C_BankAccount_ID IS NULL ") + .append("AND i.I_isImported<>'Y' ") + .append("OR i.I_isImported IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Bank Account (Without Routing No)=" + no); // - sql = new StringBuffer("UPDATE I_BankStatement i " - + "SET C_BankAccount_ID=(SELECT C_BankAccount_ID FROM C_BankAccount a WHERE a.C_BankAccount_ID=").append(p_C_BankAccount_ID); - sql.append(" and a.AD_Client_ID=i.AD_Client_ID) " - + "WHERE i.C_BankAccount_ID IS NULL " - + "AND i.BankAccountNo IS NULL " - + "AND i.I_isImported<>'Y' " - + "OR i.I_isImported IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement i ") + .append("SET C_BankAccount_ID=(SELECT C_BankAccount_ID FROM C_BankAccount a WHERE a.C_BankAccount_ID=").append(p_C_BankAccount_ID) + .append(" and a.AD_Client_ID=i.AD_Client_ID) ") + .append("WHERE i.C_BankAccount_ID IS NULL ") + .append("AND i.BankAccountNo IS NULL ") + .append("AND i.I_isImported<>'Y' ") + .append("OR i.I_isImported IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Bank Account=" + no); // - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET I_isImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Bank Account, ' " - + "WHERE C_BankAccount_ID IS NULL " - + "AND I_isImported<>'Y' " - + "OR I_isImported IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET I_isImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Bank Account, ' ") + .append("WHERE C_BankAccount_ID IS NULL ") + .append("AND I_isImported<>'Y' ") + .append("OR I_isImported IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Invalid Bank Account=" + no); // Set Currency - sql = new StringBuffer ("UPDATE I_BankStatement i " - + "SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c" - + " WHERE i.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) " - + "WHERE C_Currency_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_BankStatement i ") + .append("SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c") + .append(" WHERE i.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) ") + .append("WHERE C_Currency_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Set Currency=" + no); // - sql = new StringBuffer("UPDATE I_BankStatement i " - + "SET C_Currency_ID=(SELECT C_Currency_ID FROM C_BankAccount WHERE C_BankAccount_ID=i.C_BankAccount_ID) " - + "WHERE i.C_Currency_ID IS NULL " - + "AND i.ISO_Code IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement i ") + .append("SET C_Currency_ID=(SELECT C_Currency_ID FROM C_BankAccount WHERE C_BankAccount_ID=i.C_BankAccount_ID) ") + .append("WHERE i.C_Currency_ID IS NULL ") + .append("AND i.ISO_Code IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Set Currency=" + no); // - sql = new StringBuffer ("UPDATE I_BankStatement " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency,' " - + "WHERE C_Currency_ID IS NULL " - + "AND I_IsImported<>'E' " - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_BankStatement ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency,' ") + .append("WHERE C_Currency_ID IS NULL ") + .append("AND I_IsImported<>'E' ") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Invalid Currency=" + no); // Set Amount - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET ChargeAmt=0 " - + "WHERE ChargeAmt IS NULL " - + "AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET ChargeAmt=0 ") + .append("WHERE ChargeAmt IS NULL ") + .append("AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Charge Amount=" + no); // - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET InterestAmt=0 " - + "WHERE InterestAmt IS NULL " - + "AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET InterestAmt=0 ") + .append("WHERE InterestAmt IS NULL ") + .append("AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Interest Amount=" + no); // - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET TrxAmt=StmtAmt - InterestAmt - ChargeAmt " - + "WHERE TrxAmt IS NULL " - + "AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET TrxAmt=StmtAmt - InterestAmt - ChargeAmt ") + .append("WHERE TrxAmt IS NULL ") + .append("AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Transaction Amount=" + no); // - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET I_isImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Amount, ' " - + "WHERE TrxAmt + ChargeAmt + InterestAmt <> StmtAmt " - + "AND I_isImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET I_isImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Amount, ' ") + .append("WHERE TrxAmt + ChargeAmt + InterestAmt <> StmtAmt ") + .append("AND I_isImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Invaid Amount=" + no); // Set Valuta Date - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET ValutaDate=StatementLineDate " - + "WHERE ValutaDate IS NULL " - + "AND I_isImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET ValutaDate=StatementLineDate ") + .append("WHERE ValutaDate IS NULL ") + .append("AND I_isImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Valuta Date=" + no); // Check Payment<->Invoice combination - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->Invoice, ' " - + "WHERE I_BankStatement_ID IN " - + "(SELECT I_BankStatement_ID " - + "FROM I_BankStatement i" - + " INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) " - + "WHERE i.C_Invoice_ID IS NOT NULL " - + " AND p.C_Invoice_ID IS NOT NULL " - + " AND p.C_Invoice_ID<>i.C_Invoice_ID) ") + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->Invoice, ' ") + .append("WHERE I_BankStatement_ID IN ") + .append("(SELECT I_BankStatement_ID ") + .append("FROM I_BankStatement i") + .append(" INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) ") + .append("WHERE i.C_Invoice_ID IS NOT NULL ") + .append(" AND p.C_Invoice_ID IS NOT NULL ") + .append(" AND p.C_Invoice_ID<>i.C_Invoice_ID) ") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Payment<->Invoice Mismatch=" + no); // Check Payment<->BPartner combination - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->BPartner, ' " - + "WHERE I_BankStatement_ID IN " - + "(SELECT I_BankStatement_ID " - + "FROM I_BankStatement i" - + " INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) " - + "WHERE i.C_BPartner_ID IS NOT NULL " - + " AND p.C_BPartner_ID IS NOT NULL " - + " AND p.C_BPartner_ID<>i.C_BPartner_ID) ") + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->BPartner, ' ") + .append("WHERE I_BankStatement_ID IN ") + .append("(SELECT I_BankStatement_ID ") + .append("FROM I_BankStatement i") + .append(" INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) ") + .append("WHERE i.C_BPartner_ID IS NOT NULL ") + .append(" AND p.C_BPartner_ID IS NOT NULL ") + .append(" AND p.C_BPartner_ID<>i.C_BPartner_ID) ") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Payment<->BPartner Mismatch=" + no); // Check Invoice<->BPartner combination - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Invoice<->BPartner, ' " - + "WHERE I_BankStatement_ID IN " - + "(SELECT I_BankStatement_ID " - + "FROM I_BankStatement i" - + " INNER JOIN C_Invoice v ON (i.C_Invoice_ID=v.C_Invoice_ID) " - + "WHERE i.C_BPartner_ID IS NOT NULL " - + " AND v.C_BPartner_ID IS NOT NULL " - + " AND v.C_BPartner_ID<>i.C_BPartner_ID) ") + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Invoice<->BPartner, ' ") + .append("WHERE I_BankStatement_ID IN ") + .append("(SELECT I_BankStatement_ID ") + .append("FROM I_BankStatement i") + .append(" INNER JOIN C_Invoice v ON (i.C_Invoice_ID=v.C_Invoice_ID) ") + .append("WHERE i.C_BPartner_ID IS NOT NULL ") + .append(" AND v.C_BPartner_ID IS NOT NULL ") + .append(" AND v.C_BPartner_ID<>i.C_BPartner_ID) ") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Invoice<->BPartner Mismatch=" + no); // Check Invoice.BPartner<->Payment.BPartner combination - sql = new StringBuffer("UPDATE I_BankStatement " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Invoice.BPartner<->Payment.BPartner, ' " - + "WHERE I_BankStatement_ID IN " - + "(SELECT I_BankStatement_ID " - + "FROM I_BankStatement i" - + " INNER JOIN C_Invoice v ON (i.C_Invoice_ID=v.C_Invoice_ID)" - + " INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) " - + "WHERE p.C_Invoice_ID<>v.C_Invoice_ID" - + " AND v.C_BPartner_ID<>p.C_BPartner_ID) ") + sql = new StringBuilder("UPDATE I_BankStatement ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Invoice.BPartner<->Payment.BPartner, ' ") + .append("WHERE I_BankStatement_ID IN ") + .append("(SELECT I_BankStatement_ID ") + .append("FROM I_BankStatement i") + .append(" INNER JOIN C_Invoice v ON (i.C_Invoice_ID=v.C_Invoice_ID)") + .append(" INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) ") + .append("WHERE p.C_Invoice_ID<>v.C_Invoice_ID") + .append(" AND v.C_BPartner_ID<>p.C_BPartner_ID) ") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Invoice.BPartner<->Payment.BPartner Mismatch=" + no); // Detect Duplicates - sql = new StringBuffer("SELECT i.I_BankStatement_ID, l.C_BankStatementLine_ID, i.EftTrxID " - + "FROM I_BankStatement i, C_BankStatement s, C_BankStatementLine l " - + "WHERE i.I_isImported='N' " - + "AND s.C_BankStatement_ID=l.C_BankStatement_ID " - + "AND i.EftTrxID IS NOT NULL AND " + sql = new StringBuilder("SELECT i.I_BankStatement_ID, l.C_BankStatementLine_ID, i.EftTrxID ") + .append("FROM I_BankStatement i, C_BankStatement s, C_BankStatementLine l ") + .append("WHERE i.I_isImported='N' ") + .append("AND s.C_BankStatement_ID=l.C_BankStatement_ID ") + .append("AND i.EftTrxID IS NOT NULL AND ") // Concatenate EFT Info - + "(l.EftTrxID||l.EftAmt||l.EftStatementLineDate||l.EftValutaDate||l.EftTrxType||l.EftCurrency||l.EftReference||s.EftStatementReference " - + "||l.EftCheckNo||l.EftMemo||l.EftPayee||l.EftPayeeAccount) " - + "= " - + "(i.EftTrxID||i.EftAmt||i.EftStatementLineDate||i.EftValutaDate||i.EftTrxType||i.EftCurrency||i.EftReference||i.EftStatementReference " - + "||i.EftCheckNo||i.EftMemo||i.EftPayee||i.EftPayeeAccount) "); + .append("(l.EftTrxID||l.EftAmt||l.EftStatementLineDate||l.EftValutaDate||l.EftTrxType||l.EftCurrency||l.EftReference||s.EftStatementReference ") + .append("||l.EftCheckNo||l.EftMemo||l.EftPayee||l.EftPayeeAccount) ") + .append("= ") + .append("(i.EftTrxID||i.EftAmt||i.EftStatementLineDate||i.EftValutaDate||i.EftTrxType||i.EftCurrency||i.EftReference||i.EftStatementReference ") + .append("||i.EftCheckNo||i.EftMemo||i.EftPayee||i.EftPayeeAccount) "); - StringBuffer updateSql = new StringBuffer("UPDATE I_Bankstatement " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Duplicate['||?||']' " - + "WHERE I_BankStatement_ID=?").append(clientCheck); + StringBuilder updateSql = new StringBuilder("UPDATE I_Bankstatement ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Duplicate['||?||']' ") + .append("WHERE I_BankStatement_ID=?").append(clientCheck); PreparedStatement pupdt = DB.prepareStatement(updateSql.toString(), get_TrxName()); PreparedStatement pstmtDuplicates = null; @@ -335,9 +336,9 @@ public class ImportBankStatement extends SvrProcess ResultSet rs = pstmtDuplicates.executeQuery(); while (rs.next()) { - String info = "Line_ID=" + rs.getInt(2) // l.C_BankStatementLine_ID - + ",EDTTrxID=" + rs.getString(3); // i.EftTrxID - pupdt.setString(1, info); + StringBuilder info = new StringBuilder("Line_ID=").append(rs.getInt(2)) // l.C_BankStatementLine_ID + .append(",EDTTrxID=").append(rs.getString(3)); // i.EftTrxID + pupdt.setString(1, info.toString()); pupdt.setInt(2, rs.getInt(1)); // i.I_BankStatement_ID pupdt.executeUpdate(); no++; @@ -360,9 +361,9 @@ public class ImportBankStatement extends SvrProcess commitEx(); //Import Bank Statement - sql = new StringBuffer("SELECT * FROM I_BankStatement" - + " WHERE I_IsImported='N'" - + " ORDER BY C_BankAccount_ID, Name, EftStatementDate, EftStatementReference"); + sql = new StringBuilder("SELECT * FROM I_BankStatement") + .append(" WHERE I_IsImported='N'") + .append(" ORDER BY C_BankAccount_ID, Name, EftStatementDate, EftStatementReference"); MBankStatement statement = null; MBankAccount account = null; @@ -383,14 +384,16 @@ public class ImportBankStatement extends SvrProcess { account = MBankAccount.get (m_ctx, imp.getC_BankAccount_ID()); statement = null; - log.info("New Statement, Account=" + account.getAccountNo()); + msglog = new StringBuilder("New Statement, Account=").append(account.getAccountNo()); + log.info(msglog.toString()); } // Create a new Bank Statement for every account else if (account.getC_BankAccount_ID() != imp.getC_BankAccount_ID()) { account = MBankAccount.get (m_ctx, imp.getC_BankAccount_ID()); statement = null; - log.info("New Statement, Account=" + account.getAccountNo()); + msglog = new StringBuilder("New Statement, Account=").append(account.getAccountNo()); + log.info(msglog.toString()); } // Create a new Bank Statement for every statement name else if ((statement.getName() != null) && (imp.getName() != null)) @@ -398,7 +401,8 @@ public class ImportBankStatement extends SvrProcess if (!statement.getName().equals(imp.getName())) { statement = null; - log.info("New Statement, Statement Name=" + imp.getName()); + msglog = new StringBuilder("New Statement, Statement Name=").append(imp.getName()); + log.info(msglog.toString()); } } // Create a new Bank Statement for every statement reference @@ -407,7 +411,8 @@ public class ImportBankStatement extends SvrProcess if (!statement.getEftStatementReference().equals(imp.getEftStatementReference())) { statement = null; - log.info("New Statement, Statement Reference=" + imp.getEftStatementReference()); + msglog = new StringBuilder("New Statement, Statement Reference=").append(imp.getEftStatementReference()); + log.info(msglog.toString()); } } // Create a new Bank Statement for every statement date @@ -416,7 +421,8 @@ public class ImportBankStatement extends SvrProcess if (!statement.getStatementDate().equals(imp.getStatementDate())) { statement = null; - log.info("New Statement, Statement Date=" + imp.getStatementDate()); + msglog = new StringBuilder("New Statement, Statement Date=").append(imp.getStatementDate()); + log.info(msglog.toString()); } } @@ -513,9 +519,9 @@ public class ImportBankStatement extends SvrProcess } // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_BankStatement " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_BankStatement ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("WHERE I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); addLog (0, null, new BigDecimal (no), "@Errors@"); // diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportConversionRate.java b/org.adempiere.base.process/src/org/compiere/process/ImportConversionRate.java index b52a423dd8..21cccbb37d 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportConversionRate.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportConversionRate.java @@ -84,138 +84,139 @@ public class ImportConversionRate extends SvrProcess */ protected String doIt() throws Exception { - log.info("doIt - AD_Client_ID=" + p_AD_Client_ID - + ",AD_Org_ID=" + p_AD_Org_ID - + ",C_ConversionType_ID=" + p_C_ConversionType_ID - + ",ValidFrom=" + p_ValidFrom - + ",CreateReciprocalRate=" + p_CreateReciprocalRate); + StringBuilder msglog = new StringBuilder("doIt - AD_Client_ID=").append(p_AD_Client_ID) + .append(",AD_Org_ID=").append(p_AD_Org_ID) + .append(",C_ConversionType_ID=").append(p_C_ConversionType_ID) + .append(",ValidFrom=").append(p_ValidFrom) + .append(",CreateReciprocalRate=").append(p_CreateReciprocalRate); + log.info(msglog.toString()); // - StringBuffer sql = null; + StringBuilder sql = null; int no = 0; - String clientCheck = " AND AD_Client_ID=" + p_AD_Client_ID; + StringBuilder clientCheck = new StringBuilder(" AND AD_Client_ID=").append(p_AD_Client_ID); // **** Prepare **** // Delete Old Imported if (p_DeleteOldImported) { - sql = new StringBuffer ("DELETE I_Conversion_Rate " - + "WHERE I_IsImported='Y'").append (clientCheck); + sql = new StringBuilder ("DELETE I_Conversion_Rate ") + .append("WHERE I_IsImported='Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Delete Old Impored =" + no); } // Set Client, Org, Location, IsActive, Created/Updated - sql = new StringBuffer ("UPDATE I_Conversion_Rate " - + "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (p_AD_Client_ID).append (")," - + " AD_Org_ID = COALESCE (AD_Org_ID,").append (p_AD_Org_ID).append ("),"); + sql = new StringBuilder ("UPDATE I_Conversion_Rate ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID,").append (p_AD_Client_ID).append ("),") + .append(" AD_Org_ID = COALESCE (AD_Org_ID,").append (p_AD_Org_ID).append ("),"); if (p_C_ConversionType_ID != 0) sql.append(" C_ConversionType_ID = COALESCE (C_ConversionType_ID,").append (p_C_ConversionType_ID).append ("),"); if (p_ValidFrom != null) sql.append(" ValidFrom = COALESCE (ValidFrom,").append (DB.TO_DATE(p_ValidFrom)).append ("),"); else sql.append(" ValidFrom = COALESCE (ValidFrom,SysDate),"); - sql.append(" CreateReciprocalRate = COALESCE (CreateReciprocalRate,'").append (p_CreateReciprocalRate ? "Y" : "N").append ("')," - + " IsActive = COALESCE (IsActive, 'Y')," - + " Created = COALESCE (Created, SysDate)," - + " CreatedBy = COALESCE (CreatedBy, 0)," - + " Updated = COALESCE (Updated, SysDate)," - + " UpdatedBy = ").append(getAD_User_ID()).append("," - + " I_ErrorMsg = ' '," - + " Processed = 'N'," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql.append(" CreateReciprocalRate = COALESCE (CreateReciprocalRate,'").append (p_CreateReciprocalRate ? "Y" : "N").append ("'),") + .append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = ").append(getAD_User_ID()).append(",") + .append(" I_ErrorMsg = ' ',") + .append(" Processed = 'N'," ) + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info ("Reset =" + no); // Org - sql = new StringBuffer ("UPDATE I_Conversion_Rate o " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '" - + "WHERE (AD_Org_ID IS NULL" - + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '") + .append("WHERE (AD_Org_ID IS NULL") + .append(" OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Org =" + no); // Conversion Type - sql = new StringBuffer ("UPDATE I_Conversion_Rate i " - + "SET C_ConversionType_ID = (SELECT C_ConversionType_ID FROM C_ConversionType c" - + " WHERE c.Value=i.ConversionTypeValue AND c.AD_Client_ID IN (0,i.AD_Client_ID) AND c.IsActive='Y') " - + "WHERE C_ConversionType_ID IS NULL AND ConversionTypeValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate i ") + .append("SET C_ConversionType_ID = (SELECT C_ConversionType_ID FROM C_ConversionType c") + .append(" WHERE c.Value=i.ConversionTypeValue AND c.AD_Client_ID IN (0,i.AD_Client_ID) AND c.IsActive='Y') ") + .append("WHERE C_ConversionType_ID IS NULL AND ConversionTypeValue IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no > 0) log.fine("Set ConversionType =" + no); - sql = new StringBuffer ("UPDATE I_Conversion_Rate i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ConversionType, ' " - + "WHERE (C_ConversionType_ID IS NULL" - + " OR NOT EXISTS (SELECT * FROM C_ConversionType c " - + "WHERE i.C_ConversionType_ID=c.C_ConversionType_ID AND c.IsActive='Y'" - + " AND c.AD_Client_ID IN (0,i.AD_Client_ID)))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ConversionType, ' ") + .append("WHERE (C_ConversionType_ID IS NULL") + .append(" OR NOT EXISTS (SELECT * FROM C_ConversionType c ") + .append("WHERE i.C_ConversionType_ID=c.C_ConversionType_ID AND c.IsActive='Y'") + .append(" AND c.AD_Client_ID IN (0,i.AD_Client_ID)))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid ConversionType =" + no); // Currency - sql = new StringBuffer ("UPDATE I_Conversion_Rate i " - + "SET C_Currency_ID = (SELECT C_Currency_ID FROM C_Currency c" - + " WHERE c.ISO_Code=i.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID) AND c.IsActive='Y') " - + "WHERE C_Currency_ID IS NULL AND ISO_Code IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate i ") + .append("SET C_Currency_ID = (SELECT C_Currency_ID FROM C_Currency c") + .append(" WHERE c.ISO_Code=i.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID) AND c.IsActive='Y') ") + .append("WHERE C_Currency_ID IS NULL AND ISO_Code IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no > 0) log.fine("Set Currency =" + no); - sql = new StringBuffer ("UPDATE I_Conversion_Rate i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency, ' " - + "WHERE (C_Currency_ID IS NULL" - + " OR NOT EXISTS (SELECT * FROM C_Currency c " - + "WHERE i.C_Currency_ID=c.C_Currency_ID AND c.IsActive='Y'" - + " AND c.AD_Client_ID IN (0,i.AD_Client_ID)))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency, ' ") + .append("WHERE (C_Currency_ID IS NULL") + .append(" OR NOT EXISTS (SELECT * FROM C_Currency c ") + .append("WHERE i.C_Currency_ID=c.C_Currency_ID AND c.IsActive='Y'") + .append(" AND c.AD_Client_ID IN (0,i.AD_Client_ID)))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Currency =" + no); // Currency To - sql = new StringBuffer ("UPDATE I_Conversion_Rate i " - + "SET C_Currency_ID_To = (SELECT C_Currency_ID FROM C_Currency c" - + " WHERE c.ISO_Code=i.ISO_Code_To AND c.AD_Client_ID IN (0,i.AD_Client_ID) AND c.IsActive='Y') " - + "WHERE C_Currency_ID_To IS NULL AND ISO_Code_To IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate i ") + .append("SET C_Currency_ID_To = (SELECT C_Currency_ID FROM C_Currency c") + .append(" WHERE c.ISO_Code=i.ISO_Code_To AND c.AD_Client_ID IN (0,i.AD_Client_ID) AND c.IsActive='Y') ") + .append("WHERE C_Currency_ID_To IS NULL AND ISO_Code_To IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no > 0) log.fine("Set Currency To =" + no); - sql = new StringBuffer ("UPDATE I_Conversion_Rate i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency To, ' " - + "WHERE (C_Currency_ID_To IS NULL" - + " OR NOT EXISTS (SELECT * FROM C_Currency c " - + "WHERE i.C_Currency_ID_To=c.C_Currency_ID AND c.IsActive='Y'" - + " AND c.AD_Client_ID IN (0,i.AD_Client_ID)))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency To, ' ") + .append("WHERE (C_Currency_ID_To IS NULL") + .append(" OR NOT EXISTS (SELECT * FROM C_Currency c ") + .append("WHERE i.C_Currency_ID_To=c.C_Currency_ID AND c.IsActive='Y'") + .append(" AND c.AD_Client_ID IN (0,i.AD_Client_ID)))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Currency To =" + no); // Rates - sql = new StringBuffer ("UPDATE I_Conversion_Rate i " - + "SET MultiplyRate = 1 / DivideRate " - + "WHERE (MultiplyRate IS NULL OR MultiplyRate = 0) AND DivideRate IS NOT NULL AND DivideRate<>0" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate i ") + .append("SET MultiplyRate = 1 / DivideRate ") + .append("WHERE (MultiplyRate IS NULL OR MultiplyRate = 0) AND DivideRate IS NOT NULL AND DivideRate<>0") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no > 0) log.fine("Set MultiplyRate =" + no); - sql = new StringBuffer ("UPDATE I_Conversion_Rate i " - + "SET DivideRate = 1 / MultiplyRate " - + "WHERE (DivideRate IS NULL OR DivideRate = 0) AND MultiplyRate IS NOT NULL AND MultiplyRate<>0" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate i ") + .append("SET DivideRate = 1 / MultiplyRate ") + .append("WHERE (DivideRate IS NULL OR DivideRate = 0) AND MultiplyRate IS NOT NULL AND MultiplyRate<>0") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no > 0) log.fine("Set DivideRate =" + no); - sql = new StringBuffer ("UPDATE I_Conversion_Rate i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Rates, ' " - + "WHERE (MultiplyRate IS NULL OR MultiplyRate = 0 OR DivideRate IS NULL OR DivideRate = 0)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Rates, ' ") + .append("WHERE (MultiplyRate IS NULL OR MultiplyRate = 0 OR DivideRate IS NULL OR DivideRate = 0)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Rates =" + no); @@ -231,8 +232,8 @@ public class ImportConversionRate extends SvrProcess /*********************************************************************/ int noInsert = 0; - sql = new StringBuffer ("SELECT * FROM I_Conversion_Rate " - + "WHERE I_IsImported='N'").append (clientCheck) + sql = new StringBuilder ("SELECT * FROM I_Conversion_Rate ") + .append("WHERE I_IsImported='N'").append (clientCheck) .append(" ORDER BY C_Currency_ID, C_Currency_ID_To, ValidFrom"); PreparedStatement pstmt = null; try @@ -289,9 +290,9 @@ public class ImportConversionRate extends SvrProcess } // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_Conversion_Rate " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Conversion_Rate ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("WHERE I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); addLog (0, null, new BigDecimal (no), "@Errors@"); // diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportDelete.java b/org.adempiere.base.process/src/org/compiere/process/ImportDelete.java index 21b3083104..24e794990a 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportDelete.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportDelete.java @@ -58,20 +58,25 @@ public class ImportDelete extends SvrProcess */ protected String doIt() throws Exception { - log.info("AD_Table_ID=" + p_AD_Table_ID); + StringBuilder msglog = new StringBuilder("AD_Table_ID=").append(p_AD_Table_ID); + log.info(msglog.toString()); // get Table Info MTable table = new MTable (getCtx(), p_AD_Table_ID, get_TrxName()); - if (table.get_ID() == 0) - throw new IllegalArgumentException ("No AD_Table_ID=" + p_AD_Table_ID); + if (table.get_ID() == 0){ + StringBuilder msgexc = new StringBuilder("No AD_Table_ID=").append(p_AD_Table_ID); + throw new IllegalArgumentException (msgexc.toString()); + } String tableName = table.getTableName(); - if (!tableName.startsWith("I")) - throw new IllegalArgumentException ("Not an import table = " + tableName); + if (!tableName.startsWith("I")){ + StringBuilder msgexc = new StringBuilder("Not an import table = ").append(tableName); + throw new IllegalArgumentException (msgexc.toString()); + } // Delete - String sql = "DELETE FROM " + tableName + " WHERE AD_Client_ID=" + getAD_Client_ID(); - int no = DB.executeUpdate(sql, get_TrxName()); - String msg = Msg.translate(getCtx(), tableName + "_ID") + " #" + no; - return msg; + StringBuilder sql = new StringBuilder("DELETE FROM ").append(tableName).append(" WHERE AD_Client_ID=").append(getAD_Client_ID()); + int no = DB.executeUpdate(sql.toString(), get_TrxName()); + StringBuilder msg = new StringBuilder(Msg.translate(getCtx(), tableName + "_ID")).append(" #").append(no); + return msg.toString(); } // ImportDelete } // ImportDelete diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportGLJournal.java b/org.adempiere.base.process/src/org/compiere/process/ImportGLJournal.java index 54435b23ce..2c4a8e25cd 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportGLJournal.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportGLJournal.java @@ -95,271 +95,272 @@ public class ImportGLJournal extends SvrProcess */ protected String doIt() throws java.lang.Exception { - log.info("IsValidateOnly=" + m_IsValidateOnly + ", IsImportOnlyNoErrors=" + m_IsImportOnlyNoErrors); - StringBuffer sql = null; + StringBuilder msglog = new StringBuilder("IsValidateOnly=").append(m_IsValidateOnly).append(", IsImportOnlyNoErrors=").append(m_IsImportOnlyNoErrors); + log.info(msglog.toString()); + StringBuilder sql = null; int no = 0; - String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID; + StringBuilder clientCheck = new StringBuilder(" AND AD_Client_ID=").append(m_AD_Client_ID); // **** Prepare **** // Delete Old Imported if (m_DeleteOldImported) { - sql = new StringBuffer ("DELETE I_GLJournal " - + "WHERE I_IsImported='Y'").append (clientCheck); + sql = new StringBuilder ("DELETE I_GLJournal ") + .append("WHERE I_IsImported='Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Delete Old Impored =" + no); } // Set IsActive, Created/Updated - sql = new StringBuffer ("UPDATE I_GLJournal " - + "SET IsActive = COALESCE (IsActive, 'Y')," - + " Created = COALESCE (Created, SysDate)," - + " CreatedBy = COALESCE (CreatedBy, 0)," - + " Updated = COALESCE (Updated, SysDate)," - + " UpdatedBy = COALESCE (UpdatedBy, 0)," - + " I_ErrorMsg = ' '," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql = new StringBuilder ("UPDATE I_GLJournal ") + .append("SET IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info ("Reset=" + no); // Set Client from Name - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET AD_Client_ID=(SELECT c.AD_Client_ID FROM AD_Client c WHERE c.Value=i.ClientValue) " - + "WHERE (AD_Client_ID IS NULL OR AD_Client_ID=0) AND ClientValue IS NOT NULL" - + " AND I_IsImported<>'Y'"); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET AD_Client_ID=(SELECT c.AD_Client_ID FROM AD_Client c WHERE c.Value=i.ClientValue) ") + .append("WHERE (AD_Client_ID IS NULL OR AD_Client_ID=0) AND ClientValue IS NOT NULL") + .append(" AND I_IsImported<>'Y'"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Client from Value=" + no); // Set Default Client, Doc Org, AcctSchema, DatAcct - sql = new StringBuffer ("UPDATE I_GLJournal " - + "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append (")," - + " AD_OrgDoc_ID = COALESCE (AD_OrgDoc_ID,").append (m_AD_Org_ID).append ("),"); + sql = new StringBuilder ("UPDATE I_GLJournal ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append ("),") + .append(" AD_OrgDoc_ID = COALESCE (AD_OrgDoc_ID,").append (m_AD_Org_ID).append ("),"); if (m_C_AcctSchema_ID != 0) sql.append(" C_AcctSchema_ID = COALESCE (C_AcctSchema_ID,").append (m_C_AcctSchema_ID).append ("),"); if (m_DateAcct != null) sql.append(" DateAcct = COALESCE (DateAcct,").append (DB.TO_DATE(m_DateAcct)).append ("),"); - sql.append(" Updated = COALESCE (Updated, SysDate) " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql.append(" Updated = COALESCE (Updated, SysDate) ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Client/DocOrg/Default=" + no); // Error Doc Org - sql = new StringBuffer ("UPDATE I_GLJournal o " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Doc Org, '" - + "WHERE (AD_OrgDoc_ID IS NULL OR AD_OrgDoc_ID=0" - + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_OrgDoc_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Doc Org, '") + .append("WHERE (AD_OrgDoc_ID IS NULL OR AD_OrgDoc_ID=0") + .append(" OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_OrgDoc_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Doc Org=" + no); // Set AcctSchema - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET C_AcctSchema_ID=(SELECT a.C_AcctSchema_ID FROM C_AcctSchema a" - + " WHERE i.AcctSchemaName=a.Name AND i.AD_Client_ID=a.AD_Client_ID) " - + "WHERE C_AcctSchema_ID IS NULL AND AcctSchemaName IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET C_AcctSchema_ID=(SELECT a.C_AcctSchema_ID FROM C_AcctSchema a") + .append(" WHERE i.AcctSchemaName=a.Name AND i.AD_Client_ID=a.AD_Client_ID) ") + .append("WHERE C_AcctSchema_ID IS NULL AND AcctSchemaName IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set AcctSchema from Name=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET C_AcctSchema_ID=(SELECT c.C_AcctSchema1_ID FROM AD_ClientInfo c WHERE c.AD_Client_ID=i.AD_Client_ID) " - + "WHERE C_AcctSchema_ID IS NULL AND AcctSchemaName IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET C_AcctSchema_ID=(SELECT c.C_AcctSchema1_ID FROM AD_ClientInfo c WHERE c.AD_Client_ID=i.AD_Client_ID) ") + .append("WHERE C_AcctSchema_ID IS NULL AND AcctSchemaName IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set AcctSchema from Client=" + no); // Error AcctSchema - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid AcctSchema, '" - + "WHERE (C_AcctSchema_ID IS NULL OR C_AcctSchema_ID=0" - + " OR NOT EXISTS (SELECT * FROM C_AcctSchema a WHERE i.AD_Client_ID=a.AD_Client_ID))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid AcctSchema, '") + .append("WHERE (C_AcctSchema_ID IS NULL OR C_AcctSchema_ID=0") + .append(" OR NOT EXISTS (SELECT * FROM C_AcctSchema a WHERE i.AD_Client_ID=a.AD_Client_ID))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid AcctSchema=" + no); // Set DateAcct (mandatory) - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET DateAcct=SysDate " - + "WHERE DateAcct IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET DateAcct=SysDate ") + .append("WHERE DateAcct IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set DateAcct=" + no); // Document Type - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET C_DocType_ID=(SELECT d.C_DocType_ID FROM C_DocType d" - + " WHERE d.Name=i.DocTypeName AND d.DocBaseType='GLJ' AND i.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET C_DocType_ID=(SELECT d.C_DocType_ID FROM C_DocType d") + .append(" WHERE d.Name=i.DocTypeName AND d.DocBaseType='GLJ' AND i.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set DocType=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocType, '" - + "WHERE (C_DocType_ID IS NULL OR C_DocType_ID=0" - + " OR NOT EXISTS (SELECT * FROM C_DocType d WHERE i.AD_Client_ID=d.AD_Client_ID AND d.DocBaseType='GLJ'))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocType, '") + .append("WHERE (C_DocType_ID IS NULL OR C_DocType_ID=0") + .append(" OR NOT EXISTS (SELECT * FROM C_DocType d WHERE i.AD_Client_ID=d.AD_Client_ID AND d.DocBaseType='GLJ'))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid DocType=" + no); // GL Category - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET GL_Category_ID=(SELECT c.GL_Category_ID FROM GL_Category c" - + " WHERE c.Name=i.CategoryName AND i.AD_Client_ID=c.AD_Client_ID) " - + "WHERE GL_Category_ID IS NULL AND CategoryName IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET GL_Category_ID=(SELECT c.GL_Category_ID FROM GL_Category c") + .append(" WHERE c.Name=i.CategoryName AND i.AD_Client_ID=c.AD_Client_ID) ") + .append("WHERE GL_Category_ID IS NULL AND CategoryName IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set DocType=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Category, '" - + "WHERE (GL_Category_ID IS NULL OR GL_Category_ID=0)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Category, '") + .append("WHERE (GL_Category_ID IS NULL OR GL_Category_ID=0)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid GLCategory=" + no); // Set Currency - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET C_Currency_ID=(SELECT c.C_Currency_ID FROM C_Currency c" - + " WHERE c.ISO_Code=i.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) " - + "WHERE C_Currency_ID IS NULL AND ISO_Code IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET C_Currency_ID=(SELECT c.C_Currency_ID FROM C_Currency c") + .append(" WHERE c.ISO_Code=i.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) ") + .append("WHERE C_Currency_ID IS NULL AND ISO_Code IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Currency from ISO=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET C_Currency_ID=(SELECT a.C_Currency_ID FROM C_AcctSchema a" - + " WHERE a.C_AcctSchema_ID=i.C_AcctSchema_ID AND a.AD_Client_ID=i.AD_Client_ID)" - + "WHERE C_Currency_ID IS NULL AND ISO_Code IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET C_Currency_ID=(SELECT a.C_Currency_ID FROM C_AcctSchema a") + .append(" WHERE a.C_AcctSchema_ID=i.C_AcctSchema_ID AND a.AD_Client_ID=i.AD_Client_ID)") + .append("WHERE C_Currency_ID IS NULL AND ISO_Code IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Default Currency=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency, '" - + "WHERE (C_Currency_ID IS NULL OR C_Currency_ID=0)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Currency, '") + .append("WHERE (C_Currency_ID IS NULL OR C_Currency_ID=0)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Currency=" + no); // Set Conversion Type - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET ConversionTypeValue='S' " - + "WHERE C_ConversionType_ID IS NULL AND ConversionTypeValue IS NULL" - + " AND I_IsImported='N'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET ConversionTypeValue='S' ") + .append("WHERE C_ConversionType_ID IS NULL AND ConversionTypeValue IS NULL") + .append(" AND I_IsImported='N'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set CurrencyType Value to Spot =" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET C_ConversionType_ID=(SELECT c.C_ConversionType_ID FROM C_ConversionType c" - + " WHERE c.Value=i.ConversionTypeValue AND c.AD_Client_ID IN (0,i.AD_Client_ID)) " - + "WHERE C_ConversionType_ID IS NULL AND ConversionTypeValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET C_ConversionType_ID=(SELECT c.C_ConversionType_ID FROM C_ConversionType c") + .append(" WHERE c.Value=i.ConversionTypeValue AND c.AD_Client_ID IN (0,i.AD_Client_ID)) ") + .append("WHERE C_ConversionType_ID IS NULL AND ConversionTypeValue IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set CurrencyType from Value=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CurrencyType, '" - + "WHERE (C_ConversionType_ID IS NULL OR C_ConversionType_ID=0) AND ConversionTypeValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CurrencyType, '") + .append("WHERE (C_ConversionType_ID IS NULL OR C_ConversionType_ID=0) AND ConversionTypeValue IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid CurrencyTypeValue=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No ConversionType, '" - + "WHERE (C_ConversionType_ID IS NULL OR C_ConversionType_ID=0)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No ConversionType, '") + .append("WHERE (C_ConversionType_ID IS NULL OR C_ConversionType_ID=0)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No CourrencyType=" + no); // Set/Overwrite Home Currency Rate - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET CurrencyRate=1" - + "WHERE EXISTS (SELECT * FROM C_AcctSchema a" - + " WHERE a.C_AcctSchema_ID=i.C_AcctSchema_ID AND a.C_Currency_ID=i.C_Currency_ID)" - + " AND C_Currency_ID IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET CurrencyRate=1") + .append("WHERE EXISTS (SELECT * FROM C_AcctSchema a") + .append(" WHERE a.C_AcctSchema_ID=i.C_AcctSchema_ID AND a.C_Currency_ID=i.C_Currency_ID)") + .append(" AND C_Currency_ID IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Home CurrencyRate=" + no); // Set Currency Rate - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET CurrencyRate=(SELECT MAX(r.MultiplyRate) FROM C_Conversion_Rate r, C_AcctSchema s" - + " WHERE s.C_AcctSchema_ID=i.C_AcctSchema_ID AND s.AD_Client_ID=i.AD_Client_ID" - + " AND r.C_Currency_ID=i.C_Currency_ID AND r.C_Currency_ID_TO=s.C_Currency_ID" - + " AND r.AD_Client_ID=i.AD_Client_ID AND r.AD_Org_ID=i.AD_OrgDoc_ID" - + " AND r.C_ConversionType_ID=i.C_ConversionType_ID" - + " AND i.DateAcct BETWEEN r.ValidFrom AND r.ValidTo " + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET CurrencyRate=(SELECT MAX(r.MultiplyRate) FROM C_Conversion_Rate r, C_AcctSchema s") + .append(" WHERE s.C_AcctSchema_ID=i.C_AcctSchema_ID AND s.AD_Client_ID=i.AD_Client_ID") + .append(" AND r.C_Currency_ID=i.C_Currency_ID AND r.C_Currency_ID_TO=s.C_Currency_ID") + .append(" AND r.AD_Client_ID=i.AD_Client_ID AND r.AD_Org_ID=i.AD_OrgDoc_ID") + .append(" AND r.C_ConversionType_ID=i.C_ConversionType_ID") + .append(" AND i.DateAcct BETWEEN r.ValidFrom AND r.ValidTo ") // ORDER BY ValidFrom DESC - + ") WHERE CurrencyRate IS NULL OR CurrencyRate=0 AND C_Currency_ID>0" - + " AND I_IsImported<>'Y'").append (clientCheck); + .append(") WHERE CurrencyRate IS NULL OR CurrencyRate=0 AND C_Currency_ID>0") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Org Rate=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET CurrencyRate=(SELECT MAX(r.MultiplyRate) FROM C_Conversion_Rate r, C_AcctSchema s" - + " WHERE s.C_AcctSchema_ID=i.C_AcctSchema_ID AND s.AD_Client_ID=i.AD_Client_ID" - + " AND r.C_Currency_ID=i.C_Currency_ID AND r.C_Currency_ID_TO=s.C_Currency_ID" - + " AND r.AD_Client_ID=i.AD_Client_ID" - + " AND r.C_ConversionType_ID=i.C_ConversionType_ID" - + " AND i.DateAcct BETWEEN r.ValidFrom AND r.ValidTo " + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET CurrencyRate=(SELECT MAX(r.MultiplyRate) FROM C_Conversion_Rate r, C_AcctSchema s") + .append(" WHERE s.C_AcctSchema_ID=i.C_AcctSchema_ID AND s.AD_Client_ID=i.AD_Client_ID") + .append(" AND r.C_Currency_ID=i.C_Currency_ID AND r.C_Currency_ID_TO=s.C_Currency_ID") + .append(" AND r.AD_Client_ID=i.AD_Client_ID") + .append(" AND r.C_ConversionType_ID=i.C_ConversionType_ID") + .append(" AND i.DateAcct BETWEEN r.ValidFrom AND r.ValidTo ") // ORDER BY ValidFrom DESC - + ") WHERE CurrencyRate IS NULL OR CurrencyRate=0 AND C_Currency_ID>0" - + " AND I_IsImported<>'Y'").append (clientCheck); + .append(") WHERE CurrencyRate IS NULL OR CurrencyRate=0 AND C_Currency_ID>0") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Client Rate=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Rate, '" - + "WHERE CurrencyRate IS NULL OR CurrencyRate=0" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Rate, '") + .append("WHERE CurrencyRate IS NULL OR CurrencyRate=0") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No Rate=" + no); // Set Period - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET C_Period_ID=(SELECT MAX(p.C_Period_ID) FROM C_Period p" - + " INNER JOIN C_Year y ON (y.C_Year_ID=p.C_Year_ID)" - + " INNER JOIN AD_ClientInfo c ON (c.C_Calendar_ID=y.C_Calendar_ID)" - + " WHERE c.AD_Client_ID=i.AD_Client_ID" + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET C_Period_ID=(SELECT MAX(p.C_Period_ID) FROM C_Period p") + .append(" INNER JOIN C_Year y ON (y.C_Year_ID=p.C_Year_ID)") + .append(" INNER JOIN AD_ClientInfo c ON (c.C_Calendar_ID=y.C_Calendar_ID)") + .append(" WHERE c.AD_Client_ID=i.AD_Client_ID") // globalqss - cruiz - Bug [ 1577712 ] Financial Period Bug - + " AND i.DateAcct BETWEEN p.StartDate AND p.EndDate AND p.IsActive='Y' AND p.PeriodType='S') " - + "WHERE C_Period_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + .append(" AND i.DateAcct BETWEEN p.StartDate AND p.EndDate AND p.IsActive='Y' AND p.PeriodType='S') ") + .append("WHERE C_Period_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Period=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Period, '" - + "WHERE C_Period_ID IS NULL OR C_Period_ID NOT IN" - + "(SELECT C_Period_ID FROM C_Period p" - + " INNER JOIN C_Year y ON (y.C_Year_ID=p.C_Year_ID)" - + " INNER JOIN AD_ClientInfo c ON (c.C_Calendar_ID=y.C_Calendar_ID) " - + " WHERE c.AD_Client_ID=i.AD_Client_ID" + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Period, '") + .append("WHERE C_Period_ID IS NULL OR C_Period_ID NOT IN") + .append("(SELECT C_Period_ID FROM C_Period p") + .append(" INNER JOIN C_Year y ON (y.C_Year_ID=p.C_Year_ID)") + .append(" INNER JOIN AD_ClientInfo c ON (c.C_Calendar_ID=y.C_Calendar_ID) ") + .append(" WHERE c.AD_Client_ID=i.AD_Client_ID") // globalqss - cruiz - Bug [ 1577712 ] Financial Period Bug - + " AND i.DateAcct BETWEEN p.StartDate AND p.EndDate AND p.IsActive='Y' AND p.PeriodType='S')" - + " AND I_IsImported<>'Y'").append (clientCheck); + .append(" AND i.DateAcct BETWEEN p.StartDate AND p.EndDate AND p.IsActive='Y' AND p.PeriodType='S')") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Period=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_ErrorMsg=I_ErrorMsg||'WARN=Period Closed, ' " - + "WHERE C_Period_ID IS NOT NULL AND NOT EXISTS" - + " (SELECT * FROM C_PeriodControl pc WHERE pc.C_Period_ID=i.C_Period_ID AND DocBaseType='GLJ' AND PeriodStatus='O') " - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_ErrorMsg=I_ErrorMsg||'WARN=Period Closed, ' ") + .append("WHERE C_Period_ID IS NOT NULL AND NOT EXISTS") + .append(" (SELECT * FROM C_PeriodControl pc WHERE pc.C_Period_ID=i.C_Period_ID AND DocBaseType='GLJ' AND PeriodStatus='O') ") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Period Closed=" + no); // Posting Type - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET PostingType='A' " - + "WHERE PostingType IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET PostingType='A' ") + .append("WHERE PostingType IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Actual PostingType=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid PostingType, ' " - + "WHERE PostingType IS NULL OR NOT EXISTS" - + " (SELECT * FROM AD_Ref_List r WHERE r.AD_Reference_ID=125 AND i.PostingType=r.Value)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid PostingType, ' ") + .append("WHERE PostingType IS NULL OR NOT EXISTS") + .append(" (SELECT * FROM AD_Ref_List r WHERE r.AD_Reference_ID=125 AND i.PostingType=r.Value)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid PostingTypee=" + no); @@ -369,152 +370,152 @@ public class ImportGLJournal extends SvrProcess // (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) // Set Org from Name (* is overwritten and default) - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET AD_Org_ID=COALESCE((SELECT o.AD_Org_ID FROM AD_Org o" - + " WHERE o.Value=i.OrgValue AND o.IsSummary='N' AND i.AD_Client_ID=o.AD_Client_ID),AD_Org_ID) " - + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0) AND OrgValue IS NOT NULL" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'"); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET AD_Org_ID=COALESCE((SELECT o.AD_Org_ID FROM AD_Org o") + .append(" WHERE o.Value=i.OrgValue AND o.IsSummary='N' AND i.AD_Client_ID=o.AD_Client_ID),AD_Org_ID) ") + .append("WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0) AND OrgValue IS NOT NULL") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Org from Value=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET AD_Org_ID=AD_OrgDoc_ID " - + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0) AND OrgValue IS NULL AND AD_OrgDoc_ID IS NOT NULL AND AD_OrgDoc_ID<>0" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET AD_Org_ID=AD_OrgDoc_ID ") + .append("WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0) AND OrgValue IS NULL AND AD_OrgDoc_ID IS NOT NULL AND AD_OrgDoc_ID<>0") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Org from Doc Org=" + no); // Error Org - sql = new StringBuffer ("UPDATE I_GLJournal o " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '" - + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0" - + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '") + .append("WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0") + .append(" OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Org=" + no); // Set Account - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET Account_ID=(SELECT MAX(ev.C_ElementValue_ID) FROM C_ElementValue ev" - + " INNER JOIN C_Element e ON (e.C_Element_ID=ev.C_Element_ID)" - + " INNER JOIN C_AcctSchema_Element ase ON (e.C_Element_ID=ase.C_Element_ID AND ase.ElementType='AC')" - + " WHERE ev.Value=i.AccountValue AND ev.IsSummary='N'" - + " AND i.C_AcctSchema_ID=ase.C_AcctSchema_ID AND i.AD_Client_ID=ev.AD_Client_ID) " - + "WHERE Account_ID IS NULL AND AccountValue IS NOT NULL" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET Account_ID=(SELECT MAX(ev.C_ElementValue_ID) FROM C_ElementValue ev") + .append(" INNER JOIN C_Element e ON (e.C_Element_ID=ev.C_Element_ID)") + .append(" INNER JOIN C_AcctSchema_Element ase ON (e.C_Element_ID=ase.C_Element_ID AND ase.ElementType='AC')") + .append(" WHERE ev.Value=i.AccountValue AND ev.IsSummary='N'") + .append(" AND i.C_AcctSchema_ID=ase.C_AcctSchema_ID AND i.AD_Client_ID=ev.AD_Client_ID) ") + .append("WHERE Account_ID IS NULL AND AccountValue IS NOT NULL") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Account from Value=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Account, '" - + "WHERE (Account_ID IS NULL OR Account_ID=0)" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Account, '") + .append("WHERE (Account_ID IS NULL OR Account_ID=0)") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Account=" + no); // Set BPartner - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET C_BPartner_ID=(SELECT bp.C_BPartner_ID FROM C_BPartner bp" - + " WHERE bp.Value=i.BPartnerValue AND bp.IsSummary='N' AND i.AD_Client_ID=bp.AD_Client_ID) " - + "WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET C_BPartner_ID=(SELECT bp.C_BPartner_ID FROM C_BPartner bp") + .append(" WHERE bp.Value=i.BPartnerValue AND bp.IsSummary='N' AND i.AD_Client_ID=bp.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set BPartner from Value=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid BPartner, '" - + "WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid BPartner, '") + .append("WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid BPartner=" + no); // Set Product - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET M_Product_ID=(SELECT MAX(p.M_Product_ID) FROM M_Product p" - + " WHERE (p.Value=i.ProductValue OR p.UPC=i.UPC OR p.SKU=i.SKU)" - + " AND p.IsSummary='N' AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL OR UPC IS NOT NULL OR SKU IS NOT NULL)" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET M_Product_ID=(SELECT MAX(p.M_Product_ID) FROM M_Product p") + .append(" WHERE (p.Value=i.ProductValue OR p.UPC=i.UPC OR p.SKU=i.SKU)") + .append(" AND p.IsSummary='N' AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL OR UPC IS NOT NULL OR SKU IS NOT NULL)") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) 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_GLJournal i " - + "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 (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Product, '") + .append("WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL OR UPC IS NOT NULL OR SKU IS NOT NULL)") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Product=" + no); // Set Project - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET C_Project_ID=(SELECT p.C_Project_ID FROM C_Project p" - + " WHERE p.Value=i.ProjectValue AND p.IsSummary='N' AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_Project_ID IS NULL AND ProjectValue IS NOT NULL" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET C_Project_ID=(SELECT p.C_Project_ID FROM C_Project p") + .append(" WHERE p.Value=i.ProjectValue AND p.IsSummary='N' AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_Project_ID IS NULL AND ProjectValue IS NOT NULL") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Project from Value=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Project, '" - + "WHERE C_Project_ID IS NULL AND ProjectValue IS NOT NULL" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Project, '") + .append("WHERE C_Project_ID IS NULL AND ProjectValue IS NOT NULL") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Project=" + no); // Set TrxOrg - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET AD_OrgTrx_ID=(SELECT o.AD_Org_ID FROM AD_Org o" - + " WHERE o.Value=i.OrgValue AND o.IsSummary='N' AND i.AD_Client_ID=o.AD_Client_ID) " - + "WHERE AD_OrgTrx_ID IS NULL AND OrgTrxValue IS NOT NULL" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET AD_OrgTrx_ID=(SELECT o.AD_Org_ID FROM AD_Org o") + .append(" WHERE o.Value=i.OrgValue AND o.IsSummary='N' AND i.AD_Client_ID=o.AD_Client_ID) ") + .append("WHERE AD_OrgTrx_ID IS NULL AND OrgTrxValue IS NOT NULL") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set OrgTrx from Value=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid OrgTrx, '" - + "WHERE AD_OrgTrx_ID IS NULL AND OrgTrxValue IS NOT NULL" - + " AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid OrgTrx, '") + .append("WHERE AD_OrgTrx_ID IS NULL AND OrgTrxValue IS NOT NULL") + .append(" AND (C_ValidCombination_ID IS NULL OR C_ValidCombination_ID=0) AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid OrgTrx=" + no); // Source Amounts - sql = new StringBuffer ("UPDATE I_GLJournal " - + "SET AmtSourceDr = 0 " - + "WHERE AmtSourceDr IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal ") + .append("SET AmtSourceDr = 0 ") + .append("WHERE AmtSourceDr IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set 0 Source Dr=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal " - + "SET AmtSourceCr = 0 " - + "WHERE AmtSourceCr IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal ") + .append("SET AmtSourceCr = 0 ") + .append("WHERE AmtSourceCr IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set 0 Source Cr=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_ErrorMsg=I_ErrorMsg||'WARN=Zero Source Balance, ' " - + "WHERE (AmtSourceDr-AmtSourceCr)=0" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_ErrorMsg=I_ErrorMsg||'WARN=Zero Source Balance, ' ") + .append("WHERE (AmtSourceDr-AmtSourceCr)=0") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Zero Source Balance=" + no); // Accounted Amounts (Only if No Error) - sql = new StringBuffer ("UPDATE I_GLJournal " - + "SET AmtAcctDr = ROUND(AmtSourceDr * CurrencyRate, 2) " // HARDCODED rounding - + "WHERE AmtAcctDr IS NULL OR AmtAcctDr=0" - + " AND I_IsImported='N'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal ") + .append("SET AmtAcctDr = ROUND(AmtSourceDr * CurrencyRate, 2) ") // HARDCODED rounding + .append("WHERE AmtAcctDr IS NULL OR AmtAcctDr=0") + .append(" AND I_IsImported='N'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Calculate Acct Dr=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal " - + "SET AmtAcctCr = ROUND(AmtSourceCr * CurrencyRate, 2) " - + "WHERE AmtAcctCr IS NULL OR AmtAcctCr=0" - + " AND I_IsImported='N'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal ") + .append("SET AmtAcctCr = ROUND(AmtSourceCr * CurrencyRate, 2) ") + .append("WHERE AmtAcctCr IS NULL OR AmtAcctCr=0") + .append(" AND I_IsImported='N'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Calculate Acct Cr=" + no); - sql = new StringBuffer ("UPDATE I_GLJournal i " - + "SET I_ErrorMsg=I_ErrorMsg||'WARN=Zero Acct Balance, ' " - + "WHERE (AmtSourceDr-AmtSourceCr)<>0 AND (AmtAcctDr-AmtAcctCr)=0" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal i ") + .append("SET I_ErrorMsg=I_ErrorMsg||'WARN=Zero Acct Balance, ' ") + .append("WHERE (AmtSourceDr-AmtSourceCr)<>0 AND (AmtAcctDr-AmtAcctCr)=0") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Zero Acct Balance=" + no); @@ -533,9 +534,9 @@ public class ImportGLJournal extends SvrProcess /*********************************************************************/ // Get Balance - sql = new StringBuffer ("SELECT SUM(AmtSourceDr)-SUM(AmtSourceCr), SUM(AmtAcctDr)-SUM(AmtAcctCr) " - + "FROM I_GLJournal " - + "WHERE I_IsImported='N'").append (clientCheck); + sql = new StringBuilder ("SELECT SUM(AmtSourceDr)-SUM(AmtSourceCr), SUM(AmtAcctDr)-SUM(AmtAcctCr) ") + .append("FROM I_GLJournal ") + .append("WHERE I_IsImported='N'").append (clientCheck); PreparedStatement pstmt = null; try { @@ -548,8 +549,10 @@ public class ImportGLJournal extends SvrProcess if (source != null && source.signum() == 0 && acct != null && acct.signum() == 0) log.info ("Import Balance = 0"); - else - log.warning("Balance Source=" + source + ", Acct=" + acct); + else{ + msglog = new StringBuilder("Balance Source=").append(source).append(", Acct=").append(acct); + log.warning(msglog.toString()); + } if (source != null) addLog (0, null, source, "@AmtSourceDr@ - @AmtSourceCr@"); if (acct != null) @@ -585,10 +588,12 @@ public class ImportGLJournal extends SvrProcess if (m_IsValidateOnly || m_IsImportOnlyNoErrors) throw new Exception ("@Errors@=" + errors); } - else if (m_IsValidateOnly) - return "@Errors@=" + errors; - - log.info("Validation Errors=" + errors); + else if (m_IsValidateOnly){ + StringBuilder msgreturn = new StringBuilder("@Errors@=").append(errors); + return msgreturn.toString(); + } + msglog = new StringBuilder("Validation Errors=").append(errors); + log.info(msglog.toString()); // moved commit above to save error messages // commit(); @@ -606,11 +611,11 @@ public class ImportGLJournal extends SvrProcess boolean wasCreateNewBatch = false; // Go through Journal Records - sql = new StringBuffer ("SELECT * FROM I_GLJournal " - + "WHERE I_IsImported='N'").append (clientCheck) - .append(" ORDER BY COALESCE(BatchDocumentNo, TO_NCHAR(I_GLJournal_ID)||' '), COALESCE(JournalDocumentNo, " + - "TO_NCHAR(I_GLJournal_ID)||' '), C_AcctSchema_ID, PostingType, C_DocType_ID, GL_Category_ID, " + - "C_Currency_ID, TRUNC(DateAcct), Line, I_GLJournal_ID"); + sql = new StringBuilder ("SELECT * FROM I_GLJournal ") + .append("WHERE I_IsImported='N'").append (clientCheck) + .append(" ORDER BY COALESCE(BatchDocumentNo, TO_NCHAR(I_GLJournal_ID)||' '), COALESCE(JournalDocumentNo, ") + .append("TO_NCHAR(I_GLJournal_ID)||' '), C_AcctSchema_ID, PostingType, C_DocType_ID, GL_Category_ID, ") + .append("C_Currency_ID, TRUNC(DateAcct), Line, I_GLJournal_ID"); try { pstmt = DB.prepareStatement (sql.toString (), get_TrxName()); @@ -647,13 +652,13 @@ public class ImportGLJournal extends SvrProcess batch.setDocumentNo (imp.getBatchDocumentNo()); batch.setC_DocType_ID(imp.getC_DocType_ID()); batch.setPostingType(imp.getPostingType()); - String description = imp.getBatchDescription(); + StringBuilder description = new StringBuilder(imp.getBatchDescription()); if (description == null || description.length() == 0) - description = "*Import-"; + description = new StringBuilder("*Import-"); else - description += " *Import-"; - description += new Timestamp(System.currentTimeMillis()); - batch.setDescription(description); + description.append(" *Import-"); + description.append(new Timestamp(System.currentTimeMillis())); + batch.setDescription(description.toString()); if (!batch.save()) { log.log(Level.SEVERE, "Batch not saved"); @@ -795,9 +800,9 @@ public class ImportGLJournal extends SvrProcess pstmt = null; // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_GLJournal " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_GLJournal ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("WHERE I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); addLog (0, null, new BigDecimal (no), "@Errors@"); // diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportInOutConfirm.java b/org.adempiere.base.process/src/org/compiere/process/ImportInOutConfirm.java index f95bfda9d5..a3b4ef52d3 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportInOutConfirm.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportInOutConfirm.java @@ -68,67 +68,68 @@ public class ImportInOutConfirm extends SvrProcess */ protected String doIt () throws Exception { - log.info("I_InOutLineConfirm_ID=" + p_I_InOutLineConfirm_ID); - StringBuffer sql = null; + StringBuilder msglog = new StringBuilder("I_InOutLineConfirm_ID=").append(p_I_InOutLineConfirm_ID); + log.info(msglog.toString()); + StringBuilder sql = null; int no = 0; - String clientCheck = " AND AD_Client_ID=" + p_AD_Client_ID; + StringBuilder clientCheck = new StringBuilder(" AND AD_Client_ID=").append(p_AD_Client_ID); // Delete Old Imported if (p_DeleteOldImported) { - sql = new StringBuffer ("DELETE I_InOutLineConfirm " - + "WHERE I_IsImported='Y'").append (clientCheck); + sql = new StringBuilder ("DELETE I_InOutLineConfirm ") + .append("WHERE I_IsImported='Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Delete Old Impored =" + no); } // Set IsActive, Created/Updated - sql = new StringBuffer ("UPDATE I_InOutLineConfirm " - + "SET IsActive = COALESCE (IsActive, 'Y')," - + " Created = COALESCE (Created, SysDate)," - + " CreatedBy = COALESCE (CreatedBy, 0)," - + " Updated = COALESCE (Updated, SysDate)," - + " UpdatedBy = COALESCE (UpdatedBy, 0)," - + " I_ErrorMsg = ' '," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql = new StringBuilder ("UPDATE I_InOutLineConfirm ") + .append("SET IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info ("Reset=" + no); // Set Client from Name - sql = new StringBuffer ("UPDATE I_InOutLineConfirm i " - + "SET AD_Client_ID=COALESCE (AD_Client_ID,").append (p_AD_Client_ID).append (") " - + "WHERE (AD_Client_ID IS NULL OR AD_Client_ID=0)" - + " AND I_IsImported<>'Y'"); + sql = new StringBuilder ("UPDATE I_InOutLineConfirm i ") + .append("SET AD_Client_ID=COALESCE (AD_Client_ID,").append (p_AD_Client_ID).append (") ") + .append("WHERE (AD_Client_ID IS NULL OR AD_Client_ID=0)") + .append(" AND I_IsImported<>'Y'"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Client from Value=" + no); // Error Confirmation Line - sql = new StringBuffer ("UPDATE I_InOutLineConfirm i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Confirmation Line, '" - + "WHERE (M_InOutLineConfirm_ID IS NULL OR M_InOutLineConfirm_ID=0" - + " OR NOT EXISTS (SELECT * FROM M_InOutLineConfirm c WHERE i.M_InOutLineConfirm_ID=c.M_InOutLineConfirm_ID))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_InOutLineConfirm i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Confirmation Line, '") + .append("WHERE (M_InOutLineConfirm_ID IS NULL OR M_InOutLineConfirm_ID=0") + .append(" OR NOT EXISTS (SELECT * FROM M_InOutLineConfirm c WHERE i.M_InOutLineConfirm_ID=c.M_InOutLineConfirm_ID))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid InOutLineConfirm=" + no); // Error Confirmation No - sql = new StringBuffer ("UPDATE I_InOutLineConfirm i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Missing Confirmation No, '" - + "WHERE (ConfirmationNo IS NULL OR ConfirmationNo='')" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_InOutLineConfirm i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Missing Confirmation No, '") + .append("WHERE (ConfirmationNo IS NULL OR ConfirmationNo='')") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid ConfirmationNo=" + no); // Qty - sql = new StringBuffer ("UPDATE I_InOutLineConfirm i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Target<>(Confirmed+Difference+Scrapped), ' " - + "WHERE EXISTS (SELECT * FROM M_InOutLineConfirm c " - + "WHERE i.M_InOutLineConfirm_ID=c.M_InOutLineConfirm_ID" - + " AND c.TargetQty<>(i.ConfirmedQty+i.ScrappedQty+i.DifferenceQty))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_InOutLineConfirm i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Target<>(Confirmed+Difference+Scrapped), ' ") + .append("WHERE EXISTS (SELECT * FROM M_InOutLineConfirm c ") + .append("WHERE i.M_InOutLineConfirm_ID=c.M_InOutLineConfirm_ID") + .append(" AND c.TargetQty<>(i.ConfirmedQty+i.ScrappedQty+i.DifferenceQty))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Qty=" + no); @@ -138,8 +139,8 @@ public class ImportInOutConfirm extends SvrProcess /*********************************************************************/ PreparedStatement pstmt = null; - sql = new StringBuffer ("SELECT * FROM I_InOutLineConfirm " - + "WHERE I_IsImported='N'").append (clientCheck) + sql = new StringBuilder ("SELECT * FROM I_InOutLineConfirm ") + .append("WHERE I_IsImported='N'").append (clientCheck) .append(" ORDER BY I_InOutLineConfirm_ID"); no = 0; try @@ -193,8 +194,8 @@ public class ImportInOutConfirm extends SvrProcess { pstmt = null; } - - return "@Updated@ #" + no; + StringBuilder msgreturn = new StringBuilder("@Updated@ #").append(no); + return msgreturn.toString(); } // doIt } // ImportInOutConfirm diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java b/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java index 31bbbc89ba..d1b86a13ad 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java @@ -112,7 +112,8 @@ public class ImportInventory extends SvrProcess */ protected String doIt() throws java.lang.Exception { - log.info("M_Locator_ID=" + p_M_Locator_ID + ",MovementDate=" + p_MovementDate); + StringBuilder msglog = new StringBuilder("M_Locator_ID=").append(p_M_Locator_ID).append(",MovementDate=").append(p_MovementDate); + log.info(msglog.toString()); if (p_UpdateCosting) { if (p_C_AcctSchema_ID <= 0) { @@ -130,174 +131,174 @@ public class ImportInventory extends SvrProcess acctSchema = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID, get_TrxName()); } - StringBuffer sql = null; + StringBuilder sql = null; int no = 0; - String clientCheck = " AND AD_Client_ID=" + p_AD_Client_ID; + StringBuilder clientCheck = new StringBuilder(" AND AD_Client_ID=").append(p_AD_Client_ID); // **** Prepare **** // Delete Old Imported if (p_DeleteOldImported) { - sql = new StringBuffer ("DELETE I_Inventory " - + "WHERE I_IsImported='Y'").append (clientCheck); + sql = new StringBuilder ("DELETE I_Inventory ") + .append("WHERE I_IsImported='Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); log.fine("Delete Old Imported=" + no); } // Set Client, Org, Location, IsActive, Created/Updated - sql = new StringBuffer ("UPDATE I_Inventory " - + "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (p_AD_Client_ID).append (")," - + " AD_Org_ID = DECODE (NVL(AD_Org_ID),0,").append (p_AD_Org_ID).append (",AD_Org_ID),"); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID,").append (p_AD_Client_ID).append ("),") + .append(" AD_Org_ID = DECODE (NVL(AD_Org_ID),0,").append (p_AD_Org_ID).append (",AD_Org_ID),"); if (p_MovementDate != null) sql.append(" MovementDate = COALESCE (MovementDate,").append (DB.TO_DATE(p_MovementDate)).append ("),"); - sql.append(" IsActive = COALESCE (IsActive, 'Y')," - + " Created = COALESCE (Created, SysDate)," - + " CreatedBy = COALESCE (CreatedBy, 0)," - + " Updated = COALESCE (Updated, SysDate)," - + " UpdatedBy = COALESCE (UpdatedBy, 0)," - + " I_ErrorMsg = ' '," - + " M_Warehouse_ID = NULL," // reset - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql.append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" M_Warehouse_ID = NULL,") // reset + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate (sql.toString (), get_TrxName()); log.info ("Reset=" + no); - sql = new StringBuffer ("UPDATE I_Inventory o " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '" - + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0" - + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '") + .append("WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0") + .append(" OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); if (no != 0) log.warning ("Invalid Org=" + no); // Document Type - sql = new StringBuffer ("UPDATE I_Inventory i " - + "SET C_DocType_ID=(SELECT d.C_DocType_ID FROM C_DocType d" - + " WHERE d.Name=i.DocTypeName AND d.DocBaseType='MMI' AND i.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory i ") + .append("SET C_DocType_ID=(SELECT d.C_DocType_ID FROM C_DocType d") + .append(" WHERE d.Name=i.DocTypeName AND d.DocBaseType='MMI' AND i.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set DocType=" + no); - sql = new StringBuffer ("UPDATE I_Inventory i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocType, ' " - + "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocType, ' ") + .append("WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid DocType=" + no); // Locator - sql = new StringBuffer ("UPDATE I_Inventory i " - + "SET M_Locator_ID=(SELECT MAX(M_Locator_ID) FROM M_Locator l" - + " WHERE i.LocatorValue=l.Value AND i.AD_Client_ID=l.AD_Client_ID) " - + "WHERE M_Locator_ID IS NULL AND LocatorValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory i ") + .append("SET M_Locator_ID=(SELECT MAX(M_Locator_ID) FROM M_Locator l") + .append(" WHERE i.LocatorValue=l.Value AND i.AD_Client_ID=l.AD_Client_ID) ") + .append("WHERE M_Locator_ID IS NULL AND LocatorValue IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); log.fine("Set Locator from Value =" + no); - sql = new StringBuffer ("UPDATE I_Inventory i " - + "SET M_Locator_ID=(SELECT MAX(M_Locator_ID) FROM M_Locator l" - + " WHERE i.X=l.X AND i.Y=l.Y AND i.Z=l.Z AND i.AD_Client_ID=l.AD_Client_ID) " - + "WHERE M_Locator_ID IS NULL AND X IS NOT NULL AND Y IS NOT NULL AND Z IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory i ") + .append("SET M_Locator_ID=(SELECT MAX(M_Locator_ID) FROM M_Locator l") + .append(" WHERE i.X=l.X AND i.Y=l.Y AND i.Z=l.Z AND i.AD_Client_ID=l.AD_Client_ID) ") + .append("WHERE M_Locator_ID IS NULL AND X IS NOT NULL AND Y IS NOT NULL AND Z IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); log.fine("Set Locator from X,Y,Z =" + no); if (p_M_Locator_ID != 0) { - sql = new StringBuffer ("UPDATE I_Inventory " - + "SET M_Locator_ID = ").append (p_M_Locator_ID).append ( - " WHERE M_Locator_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET M_Locator_ID = ").append (p_M_Locator_ID) + .append (" WHERE M_Locator_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); log.fine("Set Locator from Parameter=" + no); } - sql = new StringBuffer ("UPDATE I_Inventory " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Location, ' " - + "WHERE M_Locator_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Location, ' ") + .append("WHERE M_Locator_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); if (no != 0) log.warning ("No Location=" + no); // Set M_Warehouse_ID - sql = new StringBuffer ("UPDATE I_Inventory i " - + "SET M_Warehouse_ID=(SELECT M_Warehouse_ID FROM M_Locator l WHERE i.M_Locator_ID=l.M_Locator_ID) " - + "WHERE M_Locator_ID IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory i ") + .append("SET M_Warehouse_ID=(SELECT M_Warehouse_ID FROM M_Locator l WHERE i.M_Locator_ID=l.M_Locator_ID) ") + .append("WHERE M_Locator_ID IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); log.fine("Set Warehouse from Locator =" + no); - sql = new StringBuffer ("UPDATE I_Inventory " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Warehouse, ' " - + "WHERE M_Warehouse_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Warehouse, ' ") + .append("WHERE M_Warehouse_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); if (no != 0) log.warning ("No Warehouse=" + no); // Product - sql = new StringBuffer ("UPDATE I_Inventory i " - + "SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p" - + " WHERE i.Value=p.Value AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL AND Value IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory i ") + .append("SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p") + .append(" WHERE i.Value=p.Value AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL AND Value IS NOT NULL") + .append(" 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_Inventory i " - + "SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p" - + " WHERE i.UPC=p.UPC AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL AND UPC IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory i ") + .append("SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p") + .append(" WHERE i.UPC=p.UPC AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL AND UPC IS NOT NULL") + .append(" 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_Inventory " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Product, ' " - + "WHERE M_Product_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Product, ' ") + .append("WHERE M_Product_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); if (no != 0) log.warning ("No Product=" + no); // Charge - sql = new StringBuffer ("UPDATE I_Inventory o " - + "SET C_Charge_ID=(SELECT C_Charge_ID FROM C_Charge p" - + " WHERE o.ChargeName=p.Name AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_Charge_ID IS NULL AND ChargeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory o ") + .append("SET C_Charge_ID=(SELECT C_Charge_ID FROM C_Charge p") + .append(" WHERE o.ChargeName=p.Name AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_Charge_ID IS NULL AND ChargeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Charge=" + no); - sql = new StringBuffer ("UPDATE I_Inventory " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Charge, ' " - + "WHERE C_Charge_ID IS NULL AND (ChargeName IS NOT NULL)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Charge, ' ") + .append("WHERE C_Charge_ID IS NULL AND (ChargeName IS NOT NULL)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Charge=" + no); // No QtyCount or QtyInternalUse - sql = new StringBuffer ("UPDATE I_Inventory " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Qty Count or Internal Use, ' " - + "WHERE QtyCount IS NULL AND QtyInternalUse IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Qty Count or Internal Use, ' ") + .append("WHERE QtyCount IS NULL AND QtyInternalUse IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); if (no != 0) log.warning ("No QtyCount or QtyInternalUse=" + no); // Excluding quantities - sql = new StringBuffer ("UPDATE I_Inventory " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Excluding quantities, ' " - + "WHERE NVL(QtyInternalUse,0)<>0 AND (NVL(QtyCount,0)<>0 OR NVL(QtyBook,0)<>0) " - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Excluding quantities, ' ") + .append("WHERE NVL(QtyInternalUse,0)<>0 AND (NVL(QtyCount,0)<>0 OR NVL(QtyBook,0)<>0) ") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); if (no != 0) log.warning ("Excluding quantities=" + no); // Required charge for internal use - sql = new StringBuffer ("UPDATE I_Inventory " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Required charge, ' " - + "WHERE NVL(QtyInternalUse,0)<>0 AND NVL(C_Charge_ID,0)=0 " - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Required charge, ' ") + .append("WHERE NVL(QtyInternalUse,0)<>0 AND NVL(C_Charge_ID,0)=0 ") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate (sql.toString (), get_TrxName()); if (no != 0) log.warning ("Required charge=" + no); @@ -312,8 +313,8 @@ public class ImportInventory extends SvrProcess int noInsertLine = 0; // Go through Inventory Records - sql = new StringBuffer ("SELECT * FROM I_Inventory " - + "WHERE I_IsImported='N'").append (clientCheck) + sql = new StringBuilder ("SELECT * FROM I_Inventory ") + .append("WHERE I_IsImported='N'").append (clientCheck) .append(" ORDER BY M_Warehouse_ID, TRUNC(MovementDate), I_Inventory_ID"); try { @@ -415,9 +416,9 @@ public class ImportInventory extends SvrProcess } // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_Inventory " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("WHERE I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); addLog (0, null, new BigDecimal (no), "@Errors@"); // diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportInvoice.java b/org.adempiere.base.process/src/org/compiere/process/ImportInvoice.java index bf05db3b21..c3cd8010c7 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportInvoice.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportInvoice.java @@ -86,282 +86,282 @@ public class ImportInvoice extends SvrProcess */ protected String doIt() throws java.lang.Exception { - StringBuffer sql = null; + StringBuilder sql = null; int no = 0; - String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID; + StringBuilder clientCheck = new StringBuilder(" AND AD_Client_ID=").append(m_AD_Client_ID); // **** Prepare **** // Delete Old Imported if (m_deleteOldImported) { - sql = new StringBuffer ("DELETE I_Invoice " - + "WHERE I_IsImported='Y'").append (clientCheck); + sql = new StringBuilder ("DELETE I_Invoice ") + .append("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_Invoice " - + "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append (")," - + " AD_Org_ID = COALESCE (AD_Org_ID,").append (m_AD_Org_ID).append (")," - + " IsActive = COALESCE (IsActive, 'Y')," - + " Created = COALESCE (Created, SysDate)," - + " CreatedBy = COALESCE (CreatedBy, 0)," - + " Updated = COALESCE (Updated, SysDate)," - + " UpdatedBy = COALESCE (UpdatedBy, 0)," - + " I_ErrorMsg = ' '," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append ("),") + .append(" AD_Org_ID = COALESCE (AD_Org_ID,").append (m_AD_Org_ID).append ("),") + .append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info ("Reset=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '" - + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0" - + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '") + .append("WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0") + .append(" OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Org=" + no); // Document Type - PO - SO - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName" - + " AND d.DocBaseType IN ('API','APC') AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx='N' AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName") + .append(" AND d.DocBaseType IN ('API','APC') AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx='N' AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set PO DocType=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName" - + " AND d.DocBaseType IN ('ARI','ARC') AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx='Y' AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName") + .append(" AND d.DocBaseType IN ('ARI','ARC') AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx='Y' AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set SO DocType=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName" - + " AND d.DocBaseType IN ('API','ARI','APC','ARC') AND o.AD_Client_ID=d.AD_Client_ID) " + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName") + .append(" AND d.DocBaseType IN ('API','ARI','APC','ARC') AND o.AD_Client_ID=d.AD_Client_ID) ") //+ "WHERE C_DocType_ID IS NULL AND IsSOTrx IS NULL AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); - + "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + .append("WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set DocType=" + no); - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocTypeName, ' " - + "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocTypeName, ' ") + .append("WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid DocTypeName=" + no); // DocType Default - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'" - + " AND d.DocBaseType='API' AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx='N' AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'") + .append(" AND d.DocBaseType='API' AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx='N' AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set PO Default DocType=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'" - + " AND d.DocBaseType='ARI' AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx='Y' AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'") + .append(" AND d.DocBaseType='ARI' AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx='Y' AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set SO Default DocType=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'" - + " AND d.DocBaseType IN('ARI','API') AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'") + .append(" AND d.DocBaseType IN('ARI','API') AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set Default DocType=" + no); - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No DocType, ' " - + "WHERE C_DocType_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No DocType, ' ") + .append("WHERE C_DocType_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No DocType=" + no); // Set IsSOTrx - sql = new StringBuffer ("UPDATE I_Invoice o SET IsSOTrx='Y' " - + "WHERE EXISTS (SELECT * FROM C_DocType d WHERE o.C_DocType_ID=d.C_DocType_ID AND d.DocBaseType='ARI' AND o.AD_Client_ID=d.AD_Client_ID)" - + " AND C_DocType_ID IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o SET IsSOTrx='Y' ") + .append("WHERE EXISTS (SELECT * FROM C_DocType d WHERE o.C_DocType_ID=d.C_DocType_ID AND d.DocBaseType='ARI' AND o.AD_Client_ID=d.AD_Client_ID)") + .append(" AND C_DocType_ID IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set IsSOTrx=Y=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o SET IsSOTrx='N' " - + "WHERE EXISTS (SELECT * FROM C_DocType d WHERE o.C_DocType_ID=d.C_DocType_ID AND d.DocBaseType='API' AND o.AD_Client_ID=d.AD_Client_ID)" - + " AND C_DocType_ID IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o SET IsSOTrx='N' ") + .append("WHERE EXISTS (SELECT * FROM C_DocType d WHERE o.C_DocType_ID=d.C_DocType_ID AND d.DocBaseType='API' AND o.AD_Client_ID=d.AD_Client_ID)") + .append(" AND C_DocType_ID IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set IsSOTrx=N=" + no); // Price List - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p WHERE p.IsDefault='Y'" - + " AND p.C_Currency_ID=o.C_Currency_ID AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_PriceList_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p WHERE p.IsDefault='Y'") + .append(" AND p.C_Currency_ID=o.C_Currency_ID AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_PriceList_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Default Currency PriceList=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p WHERE p.IsDefault='Y'" - + " AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_PriceList_ID IS NULL AND C_Currency_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p WHERE p.IsDefault='Y'") + .append(" AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_PriceList_ID IS NULL AND C_Currency_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Default PriceList=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p " - + " WHERE p.C_Currency_ID=o.C_Currency_ID AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_PriceList_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p ") + .append(" WHERE p.C_Currency_ID=o.C_Currency_ID AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_PriceList_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Currency PriceList=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p " - + " WHERE p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_PriceList_ID IS NULL AND C_Currency_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p ") + .append(" WHERE p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_PriceList_ID IS NULL AND C_Currency_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set PriceList=" + no); // - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No PriceList, ' " - + "WHERE M_PriceList_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No PriceList, ' ") + .append("WHERE M_PriceList_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("No PriceList=" + no); // Payment Term - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_PaymentTerm_ID=(SELECT C_PaymentTerm_ID FROM C_PaymentTerm p" - + " WHERE o.PaymentTermValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_PaymentTerm_ID IS NULL AND PaymentTermValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_PaymentTerm_ID=(SELECT C_PaymentTerm_ID FROM C_PaymentTerm p") + .append(" WHERE o.PaymentTermValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_PaymentTerm_ID IS NULL AND PaymentTermValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set PaymentTerm=" + no); - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_PaymentTerm_ID=(SELECT MAX(C_PaymentTerm_ID) FROM C_PaymentTerm p" - + " WHERE p.IsDefault='Y' AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_PaymentTerm_ID IS NULL AND o.PaymentTermValue IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_PaymentTerm_ID=(SELECT MAX(C_PaymentTerm_ID) FROM C_PaymentTerm p") + .append(" WHERE p.IsDefault='Y' AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_PaymentTerm_ID IS NULL AND o.PaymentTermValue IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Default PaymentTerm=" + no); // - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No PaymentTerm, ' " - + "WHERE C_PaymentTerm_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No PaymentTerm, ' ") + .append("WHERE C_PaymentTerm_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No PaymentTerm=" + no); // globalqss - Add project and activity // Project - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_Project_ID=(SELECT C_Project_ID FROM C_Project p" - + " WHERE o.ProjectValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_Project_ID IS NULL AND ProjectValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_Project_ID=(SELECT C_Project_ID FROM C_Project p") + .append(" WHERE o.ProjectValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_Project_ID IS NULL AND ProjectValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Project=" + no); - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Project, ' " - + "WHERE C_Project_ID IS NULL AND (ProjectValue IS NOT NULL)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Project, ' ") + .append("WHERE C_Project_ID IS NULL AND (ProjectValue IS NOT NULL)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Project=" + no); // Activity - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_Activity_ID=(SELECT C_Activity_ID FROM C_Activity p" - + " WHERE o.ActivityValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_Activity_ID IS NULL AND ActivityValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_Activity_ID=(SELECT C_Activity_ID FROM C_Activity p") + .append(" WHERE o.ActivityValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_Activity_ID IS NULL AND ActivityValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Activity=" + no); - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Activity, ' " - + "WHERE C_Activity_ID IS NULL AND (ActivityValue IS NOT NULL)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Activity, ' ") + .append("WHERE C_Activity_ID IS NULL AND (ActivityValue IS NOT NULL)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Activity=" + no); // globalqss - add charge // Charge - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_Charge_ID=(SELECT C_Charge_ID FROM C_Charge p" - + " WHERE o.ChargeName=p.Name AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_Charge_ID IS NULL AND ChargeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_Charge_ID=(SELECT C_Charge_ID FROM C_Charge p") + .append(" WHERE o.ChargeName=p.Name AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_Charge_ID IS NULL AND ChargeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Charge=" + no); - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Charge, ' " - + "WHERE C_Charge_ID IS NULL AND (ChargeName IS NOT NULL)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Charge, ' ") + .append("WHERE C_Charge_ID IS NULL AND (ChargeName IS NOT NULL)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Charge=" + no); // // BP from EMail - sql = new StringBuffer ("UPDATE I_Invoice 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); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET (C_BPartner_ID,AD_User_ID)=(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u") + .append(" WHERE o.EMail=u.EMail AND o.AD_Client_ID=u.AD_Client_ID AND u.C_BPartner_ID IS NOT NULL) ") + .append("WHERE C_BPartner_ID IS NULL AND EMail IS NOT NULL") + .append(" 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_Invoice 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); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET (C_BPartner_ID,AD_User_ID)=(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u") + .append(" WHERE o.ContactName=u.Name AND o.AD_Client_ID=u.AD_Client_ID AND u.C_BPartner_ID IS NOT NULL) ") + .append("WHERE C_BPartner_ID IS NULL AND ContactName IS NOT NULL") + .append(" 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)") + .append(" 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_Invoice o " - + "SET C_BPartner_ID=(SELECT MAX(C_BPartner_ID) FROM C_BPartner bp" - + " WHERE o.BPartnerValue=bp.Value AND o.AD_Client_ID=bp.AD_Client_ID) " - + "WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_BPartner_ID=(SELECT MAX(C_BPartner_ID) FROM C_BPartner bp") + .append(" WHERE o.BPartnerValue=bp.Value AND o.AD_Client_ID=bp.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL") + .append(" 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_Invoice 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); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_BPartner_ID=(SELECT C_BPartnerCashTrx_ID FROM AD_ClientInfo c") + .append(" WHERE o.AD_Client_ID=c.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NULL AND Name IS NULL") + .append(" 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_Invoice o " - + "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 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 o.C_Region_ID=l.C_Region_ID AND o.C_Country_ID=l.C_Country_ID) " - + "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL" - + " AND I_IsImported='N'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_BPartner_Location_ID=(SELECT C_BPartner_Location_ID") + .append(" FROM C_BPartner_Location bpl INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)") + .append(" WHERE o.C_BPartner_ID=bpl.C_BPartner_ID AND bpl.AD_Client_ID=o.AD_Client_ID") + .append(" AND DUMP(o.Address1)=DUMP(l.Address1) AND DUMP(o.Address2)=DUMP(l.Address2)") + .append(" AND DUMP(o.City)=DUMP(l.City) AND DUMP(o.Postal)=DUMP(l.Postal)") + .append(" AND o.C_Region_ID=l.C_Region_ID AND o.C_Country_ID=l.C_Country_ID) ") + .append("WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL") + .append(" AND I_IsImported='N'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Found Location=" + no); // Set Location from BPartner - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_BPartner_Location_ID=(SELECT MAX(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 o.IsSOTrx='N')" - + ") " - + "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_BPartner_Location_ID=(SELECT MAX(C_BPartner_Location_ID) FROM C_BPartner_Location l") + .append(" WHERE l.C_BPartner_ID=o.C_BPartner_ID AND o.AD_Client_ID=l.AD_Client_ID") + .append(" AND ((l.IsBillTo='Y' AND o.IsSOTrx='Y') OR o.IsSOTrx='N')") + .append(") ") + .append("WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL") + .append(" 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_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BP Location, ' " - + "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BP Location, ' ") + .append("WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No BP Location=" + no); @@ -376,102 +376,102 @@ public class ImportInvoice extends SvrProcess no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Country Default=" + no); **/ - sql = new StringBuffer ("UPDATE I_Invoice 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); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_Country_ID=(SELECT C_Country_ID FROM C_Country c") + .append(" WHERE o.CountryCode=c.CountryCode AND c.AD_Client_ID IN (0, o.AD_Client_ID)) ") + .append("WHERE C_BPartner_ID IS NULL AND C_Country_ID IS NULL AND CountryCode IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Country=" + no); // - sql = new StringBuffer ("UPDATE I_Invoice " - + "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); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Country, ' ") + .append("WHERE C_BPartner_ID IS NULL AND C_Country_ID IS NULL") + .append(" 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_Invoice o " - + "Set RegionName=(SELECT MAX(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)) " - + "WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL AND RegionName IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("Set RegionName=(SELECT MAX(Name) FROM C_Region r") + .append(" WHERE r.IsDefault='Y' AND r.C_Country_ID=o.C_Country_ID") + .append(" AND r.AD_Client_ID IN (0, o.AD_Client_ID)) ") + .append("WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL AND RegionName IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Region Default=" + no); // - sql = new StringBuffer ("UPDATE I_Invoice 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); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("Set C_Region_ID=(SELECT C_Region_ID FROM C_Region r") + .append(" WHERE r.Name=o.RegionName AND r.C_Country_ID=o.C_Country_ID") + .append(" AND r.AD_Client_ID IN (0, o.AD_Client_ID)) ") + .append("WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL AND RegionName IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Region=" + no); // - sql = new StringBuffer ("UPDATE I_Invoice 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); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Region, ' ") + .append("WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL ") + .append(" AND EXISTS (SELECT * FROM C_Country c") + .append(" WHERE c.C_Country_ID=o.C_Country_ID AND c.HasRegion='Y')") + .append(" 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_Invoice o " - + "SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p" - + " WHERE o.ProductValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL AND ProductValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p") + .append(" WHERE o.ProductValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL AND ProductValue IS NOT NULL") + .append(" 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_Invoice o " - + "SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p" - + " WHERE o.UPC=p.UPC AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL AND UPC IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p") + .append(" WHERE o.UPC=p.UPC AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL AND UPC IS NOT NULL") + .append(" 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_Invoice o " - + "SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p" - + " WHERE o.SKU=p.SKU AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL AND SKU IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p") + .append(" WHERE o.SKU=p.SKU AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL AND SKU IS NOT NULL") + .append(" 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_Invoice " - + "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); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Product, ' ") + .append("WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL OR UPC IS NOT NULL OR SKU IS NOT NULL)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Product=" + no); // globalqss - charge and product are exclusive - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Product and Charge, ' " - + "WHERE M_Product_ID IS NOT NULL AND C_Charge_ID IS NOT NULL " - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Product and Charge, ' ") + .append("WHERE M_Product_ID IS NOT NULL AND C_Charge_ID IS NOT NULL ") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Product and Charge exclusive=" + no); // Tax - sql = new StringBuffer ("UPDATE I_Invoice o " - + "SET C_Tax_ID=(SELECT MAX(C_Tax_ID) FROM C_Tax t" - + " WHERE o.TaxIndicator=t.TaxIndicator AND o.AD_Client_ID=t.AD_Client_ID) " - + "WHERE C_Tax_ID IS NULL AND TaxIndicator IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice o ") + .append("SET C_Tax_ID=(SELECT MAX(C_Tax_ID) FROM C_Tax t") + .append(" WHERE o.TaxIndicator=t.TaxIndicator AND o.AD_Client_ID=t.AD_Client_ID) ") + .append("WHERE C_Tax_ID IS NULL AND TaxIndicator IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Tax=" + no); - sql = new StringBuffer ("UPDATE I_Invoice " - + "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); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Tax, ' ") + .append("WHERE C_Tax_ID IS NULL AND TaxIndicator IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Tax=" + no); @@ -481,8 +481,8 @@ public class ImportInvoice extends SvrProcess // -- New BPartner --------------------------------------------------- // Go through Invoice Records w/o C_BPartner_ID - sql = new StringBuffer ("SELECT * FROM I_Invoice " - + "WHERE I_IsImported='N' AND C_BPartner_ID IS NULL").append (clientCheck); + sql = new StringBuilder ("SELECT * FROM I_Invoice ") + .append("WHERE I_IsImported='N' AND C_BPartner_ID IS NULL").append (clientCheck); try { PreparedStatement pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); @@ -601,10 +601,10 @@ public class ImportInvoice extends SvrProcess { log.log(Level.SEVERE, "CreateBP", e); } - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BPartner, ' " - + "WHERE C_BPartner_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BPartner, ' ") + .append("WHERE C_BPartner_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No BPartner=" + no); @@ -617,8 +617,8 @@ public class ImportInvoice extends SvrProcess int noInsertLine = 0; // Go through Invoice Records w/o - sql = new StringBuffer ("SELECT * FROM I_Invoice " - + "WHERE I_IsImported='N'").append (clientCheck) + sql = new StringBuilder ("SELECT * FROM I_Invoice ") + .append("WHERE I_IsImported='N'").append (clientCheck) .append(" ORDER BY C_BPartner_ID, C_BPartner_Location_ID, I_Invoice_ID"); try { @@ -760,9 +760,9 @@ public class ImportInvoice extends SvrProcess } // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_Invoice " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Invoice ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("WHERE I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); addLog (0, null, new BigDecimal (no), "@Errors@"); // diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportOrder.java b/org.adempiere.base.process/src/org/compiere/process/ImportOrder.java index 187243b998..06d12d54f5 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportOrder.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportOrder.java @@ -88,7 +88,7 @@ public class ImportOrder extends SvrProcess */ protected String doIt() throws java.lang.Exception { - StringBuffer sql = null; + StringBuilder sql = null; int no = 0; String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID; @@ -97,272 +97,272 @@ public class ImportOrder extends SvrProcess // Delete Old Imported if (m_deleteOldImported) { - sql = new StringBuffer ("DELETE I_Order " - + "WHERE I_IsImported='Y'").append (clientCheck); + sql = new StringBuilder ("DELETE I_Order ") + .append("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_Order " - + "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append (")," - + " AD_Org_ID = COALESCE (AD_Org_ID,").append (m_AD_Org_ID).append (")," - + " IsActive = COALESCE (IsActive, 'Y')," - + " Created = COALESCE (Created, SysDate)," - + " CreatedBy = COALESCE (CreatedBy, 0)," - + " Updated = COALESCE (Updated, SysDate)," - + " UpdatedBy = COALESCE (UpdatedBy, 0)," - + " I_ErrorMsg = ' '," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID,").append (m_AD_Client_ID).append ("),") + .append(" AD_Org_ID = COALESCE (AD_Org_ID,").append (m_AD_Org_ID).append ("),") + .append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info ("Reset=" + no); - sql = new StringBuffer ("UPDATE I_Order o " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '" - + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0" - + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '") + .append("WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0") + .append(" OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Org=" + no); // Document Type - PO - SO - sql = new StringBuffer ("UPDATE I_Order o " // PO Document Type Name - + "SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName" - + " AND d.DocBaseType='POO' AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx='N' AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") // PO Document Type Name + .append("SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName") + .append(" AND d.DocBaseType='POO' AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx='N' AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set PO DocType=" + no); - sql = new StringBuffer ("UPDATE I_Order o " // SO Document Type Name - + "SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName" - + " AND d.DocBaseType='SOO' AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx='Y' AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") // SO Document Type Name + .append("SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName") + .append(" AND d.DocBaseType='SOO' AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx='Y' AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set SO DocType=" + no); - sql = new StringBuffer ("UPDATE I_Order o " - + "SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName" - + " AND d.DocBaseType IN ('SOO','POO') AND o.AD_Client_ID=d.AD_Client_ID) " + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=o.DocTypeName") + .append(" AND d.DocBaseType IN ('SOO','POO') AND o.AD_Client_ID=d.AD_Client_ID) ") //+ "WHERE C_DocType_ID IS NULL AND IsSOTrx IS NULL AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); - + "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + .append("WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set DocType=" + no); - sql = new StringBuffer ("UPDATE I_Order " // Error Invalid Doc Type Name - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocTypeName, ' " - + "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order ") // Error Invalid Doc Type Name + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocTypeName, ' ") + .append("WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid DocTypeName=" + no); // DocType Default - sql = new StringBuffer ("UPDATE I_Order o " // Default PO - + "SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'" - + " AND d.DocBaseType='POO' AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx='N' AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") // Default PO + .append("SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'") + .append(" AND d.DocBaseType='POO' AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx='N' AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set PO Default DocType=" + no); - sql = new StringBuffer ("UPDATE I_Order o " // Default SO - + "SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'" - + " AND d.DocBaseType='SOO' AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx='Y' AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") // Default SO + .append("SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'") + .append(" AND d.DocBaseType='SOO' AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx='Y' AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set SO Default DocType=" + no); - sql = new StringBuffer ("UPDATE I_Order o " - + "SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'" - + " AND d.DocBaseType IN('SOO','POO') AND o.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND IsSOTrx IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_DocType_ID=(SELECT MAX(C_DocType_ID) FROM C_DocType d WHERE d.IsDefault='Y'") + .append(" AND d.DocBaseType IN('SOO','POO') AND o.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND IsSOTrx IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Default DocType=" + no); - sql = new StringBuffer ("UPDATE I_Order " // No DocType - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No DocType, ' " - + "WHERE C_DocType_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order ") // No DocType + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No DocType, ' ") + .append("WHERE C_DocType_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No DocType=" + no); // Set IsSOTrx - sql = new StringBuffer ("UPDATE I_Order o SET IsSOTrx='Y' " - + "WHERE EXISTS (SELECT * FROM C_DocType d WHERE o.C_DocType_ID=d.C_DocType_ID AND d.DocBaseType='SOO' AND o.AD_Client_ID=d.AD_Client_ID)" - + " AND C_DocType_ID IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o SET IsSOTrx='Y' ") + .append("WHERE EXISTS (SELECT * FROM C_DocType d WHERE o.C_DocType_ID=d.C_DocType_ID AND d.DocBaseType='SOO' AND o.AD_Client_ID=d.AD_Client_ID)") + .append(" AND C_DocType_ID IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set IsSOTrx=Y=" + no); - sql = new StringBuffer ("UPDATE I_Order o SET IsSOTrx='N' " - + "WHERE EXISTS (SELECT * FROM C_DocType d WHERE o.C_DocType_ID=d.C_DocType_ID AND d.DocBaseType='POO' AND o.AD_Client_ID=d.AD_Client_ID)" - + " AND C_DocType_ID IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o SET IsSOTrx='N' ") + .append("WHERE EXISTS (SELECT * FROM C_DocType d WHERE o.C_DocType_ID=d.C_DocType_ID AND d.DocBaseType='POO' AND o.AD_Client_ID=d.AD_Client_ID)") + .append(" AND C_DocType_ID IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set IsSOTrx=N=" + no); // Price List - sql = new StringBuffer ("UPDATE I_Order o " - + "SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p WHERE p.IsDefault='Y'" - + " AND p.C_Currency_ID=o.C_Currency_ID AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_PriceList_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p WHERE p.IsDefault='Y'") + .append(" AND p.C_Currency_ID=o.C_Currency_ID AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_PriceList_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Default Currency PriceList=" + no); - sql = new StringBuffer ("UPDATE I_Order o " - + "SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p WHERE p.IsDefault='Y'" - + " AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_PriceList_ID IS NULL AND C_Currency_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p WHERE p.IsDefault='Y'") + .append(" AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_PriceList_ID IS NULL AND C_Currency_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Default PriceList=" + no); - sql = new StringBuffer ("UPDATE I_Order o " - + "SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p " - + " WHERE p.C_Currency_ID=o.C_Currency_ID AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_PriceList_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p ") + .append(" WHERE p.C_Currency_ID=o.C_Currency_ID AND p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_PriceList_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Currency PriceList=" + no); - sql = new StringBuffer ("UPDATE I_Order o " - + "SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p " - + " WHERE p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_PriceList_ID IS NULL AND C_Currency_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET M_PriceList_ID=(SELECT MAX(M_PriceList_ID) FROM M_PriceList p ") + .append(" WHERE p.IsSOPriceList=o.IsSOTrx AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_PriceList_ID IS NULL AND C_Currency_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set PriceList=" + no); // - sql = new StringBuffer ("UPDATE I_Order " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No PriceList, ' " - + "WHERE M_PriceList_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No PriceList, ' ") + .append("WHERE M_PriceList_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("No PriceList=" + no); // @Trifon - Import Order Source - sql = new StringBuffer ("UPDATE I_Order o " - + "SET C_OrderSource_ID=(SELECT C_OrderSource_ID FROM C_OrderSource p" - + " WHERE o.C_OrderSourceValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_OrderSource_ID IS NULL AND C_OrderSourceValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_OrderSource_ID=(SELECT C_OrderSource_ID FROM C_OrderSource p") + .append(" WHERE o.C_OrderSourceValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_OrderSource_ID IS NULL AND C_OrderSourceValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Order Source=" + no); // Set proper error message - sql = new StringBuffer ("UPDATE I_Order " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Not Found Order Source, ' " - + "WHERE C_OrderSource_ID IS NULL AND C_OrderSourceValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Not Found Order Source, ' ") + .append("WHERE C_OrderSource_ID IS NULL AND C_OrderSourceValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("No OrderSource=" + no); // Payment Term - sql = new StringBuffer ("UPDATE I_Order o " - + "SET C_PaymentTerm_ID=(SELECT C_PaymentTerm_ID FROM C_PaymentTerm p" - + " WHERE o.PaymentTermValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_PaymentTerm_ID IS NULL AND PaymentTermValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_PaymentTerm_ID=(SELECT C_PaymentTerm_ID FROM C_PaymentTerm p") + .append(" WHERE o.PaymentTermValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_PaymentTerm_ID IS NULL AND PaymentTermValue IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set PaymentTerm=" + no); - sql = new StringBuffer ("UPDATE I_Order o " - + "SET C_PaymentTerm_ID=(SELECT MAX(C_PaymentTerm_ID) FROM C_PaymentTerm p" - + " WHERE p.IsDefault='Y' AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_PaymentTerm_ID IS NULL AND o.PaymentTermValue IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_PaymentTerm_ID=(SELECT MAX(C_PaymentTerm_ID) FROM C_PaymentTerm p") + .append(" WHERE p.IsDefault='Y' AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_PaymentTerm_ID IS NULL AND o.PaymentTermValue IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Default PaymentTerm=" + no); // - sql = new StringBuffer ("UPDATE I_Order " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No PaymentTerm, ' " - + "WHERE C_PaymentTerm_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No PaymentTerm, ' ") + .append("WHERE C_PaymentTerm_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No PaymentTerm=" + no); // Warehouse - sql = new StringBuffer ("UPDATE I_Order o " - + "SET M_Warehouse_ID=(SELECT MAX(M_Warehouse_ID) FROM M_Warehouse w" - + " WHERE o.AD_Client_ID=w.AD_Client_ID AND o.AD_Org_ID=w.AD_Org_ID) " - + "WHERE M_Warehouse_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET M_Warehouse_ID=(SELECT MAX(M_Warehouse_ID) FROM M_Warehouse w") + .append(" WHERE o.AD_Client_ID=w.AD_Client_ID AND o.AD_Org_ID=w.AD_Org_ID) ") + .append("WHERE M_Warehouse_ID IS NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); // Warehouse for Org if (no != 0) 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); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET M_Warehouse_ID=(SELECT M_Warehouse_ID FROM M_Warehouse w") + .append(" WHERE o.AD_Client_ID=w.AD_Client_ID) ") + .append("WHERE M_Warehouse_ID IS NULL") + .append(" 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)") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Warehouse, ' ") + .append("WHERE M_Warehouse_ID IS NULL") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET (C_BPartner_ID,AD_User_ID)=(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u") + .append(" WHERE o.EMail=u.EMail AND o.AD_Client_ID=u.AD_Client_ID AND u.C_BPartner_ID IS NOT NULL) ") + .append("WHERE C_BPartner_ID IS NULL AND EMail IS NOT NULL") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET (C_BPartner_ID,AD_User_ID)=(SELECT C_BPartner_ID,AD_User_ID FROM AD_User u") + .append(" WHERE o.ContactName=u.Name AND o.AD_Client_ID=u.AD_Client_ID AND u.C_BPartner_ID IS NOT NULL) ") + .append("WHERE C_BPartner_ID IS NULL AND ContactName IS NOT NULL") + .append(" 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)") + .append(" 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 MAX(C_BPartner_ID) FROM C_BPartner bp" - + " WHERE o.BPartnerValue=bp.Value AND o.AD_Client_ID=bp.AD_Client_ID) " - + "WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_BPartner_ID=(SELECT MAX(C_BPartner_ID) FROM C_BPartner bp") + .append(" WHERE o.BPartnerValue=bp.Value AND o.AD_Client_ID=bp.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_BPartner_ID=(SELECT C_BPartnerCashTrx_ID FROM AD_ClientInfo c") + .append(" WHERE o.AD_Client_ID=c.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NULL AND Name IS NULL") + .append(" 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 o.C_Region_ID=l.C_Region_ID AND o.C_Country_ID=l.C_Country_ID) " - + "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL" - + " AND I_IsImported='N'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET (BillTo_ID,C_BPartner_Location_ID)=(SELECT C_BPartner_Location_ID,C_BPartner_Location_ID") + .append(" FROM C_BPartner_Location bpl INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)") + .append(" WHERE o.C_BPartner_ID=bpl.C_BPartner_ID AND bpl.AD_Client_ID=o.AD_Client_ID") + .append(" AND DUMP(o.Address1)=DUMP(l.Address1) AND DUMP(o.Address2)=DUMP(l.Address2)") + .append(" AND DUMP(o.City)=DUMP(l.City) AND DUMP(o.Postal)=DUMP(l.Postal)") + .append(" AND o.C_Region_ID=l.C_Region_ID AND o.C_Country_ID=l.C_Country_ID) ") + .append("WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL") + .append(" 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 MAX(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'))" - + ") " - + "WHERE C_BPartner_ID IS NOT NULL AND BillTo_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET BillTo_ID=(SELECT MAX(C_BPartner_Location_ID) FROM C_BPartner_Location l") + .append(" WHERE l.C_BPartner_ID=o.C_BPartner_ID AND o.AD_Client_ID=l.AD_Client_ID") + .append(" AND ((l.IsBillTo='Y' AND o.IsSOTrx='Y') OR (l.IsPayFrom='Y' AND o.IsSOTrx='N'))") + .append(") ") + .append("WHERE C_BPartner_ID IS NOT NULL AND BillTo_ID IS NULL") + .append(" 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 MAX(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')" - + ") " - + "WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_BPartner_Location_ID=(SELECT MAX(C_BPartner_Location_ID) FROM C_BPartner_Location l") + .append(" WHERE l.C_BPartner_ID=o.C_BPartner_ID AND o.AD_Client_ID=l.AD_Client_ID") + .append(" AND ((l.IsShipTo='Y' AND o.IsSOTrx='Y') OR o.IsSOTrx='N')") + .append(") ") + .append("WHERE C_BPartner_ID IS NOT NULL AND C_BPartner_Location_ID IS NULL") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BP Location, ' ") + .append("WHERE C_BPartner_ID IS NOT NULL AND (BillTo_ID IS NULL OR C_BPartner_Location_ID IS NULL)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No BP Location=" + no); @@ -377,117 +377,117 @@ public class ImportOrder extends SvrProcess 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); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_Country_ID=(SELECT C_Country_ID FROM C_Country c") + .append(" WHERE o.CountryCode=c.CountryCode AND c.AD_Client_ID IN (0, o.AD_Client_ID)) ") + .append("WHERE C_BPartner_ID IS NULL AND C_Country_ID IS NULL AND CountryCode IS NOT NULL") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Country, ' ") + .append("WHERE C_BPartner_ID IS NULL AND C_Country_ID IS NULL") + .append(" 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 MAX(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)) " - + "WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL AND RegionName IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("Set RegionName=(SELECT MAX(Name) FROM C_Region r") + .append(" WHERE r.IsDefault='Y' AND r.C_Country_ID=o.C_Country_ID") + .append(" AND r.AD_Client_ID IN (0, o.AD_Client_ID)) ") + .append("WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL AND RegionName IS NULL") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("Set C_Region_ID=(SELECT C_Region_ID FROM C_Region r") + .append(" WHERE r.Name=o.RegionName AND r.C_Country_ID=o.C_Country_ID") + .append(" AND r.AD_Client_ID IN (0, o.AD_Client_ID)) ") + .append("WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL AND RegionName IS NOT NULL") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Region, ' ") + .append("WHERE C_BPartner_ID IS NULL AND C_Region_ID IS NULL ") + .append(" AND EXISTS (SELECT * FROM C_Country c") + .append(" WHERE c.C_Country_ID=o.C_Country_ID AND c.HasRegion='Y')") + .append(" 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 MAX(M_Product_ID) FROM M_Product p" - + " WHERE o.ProductValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL AND ProductValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p") + .append(" WHERE o.ProductValue=p.Value AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL AND ProductValue IS NOT NULL") + .append(" 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 MAX(M_Product_ID) FROM M_Product p" - + " WHERE o.UPC=p.UPC AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL AND UPC IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p") + .append(" WHERE o.UPC=p.UPC AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL AND UPC IS NOT NULL") + .append(" 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 MAX(M_Product_ID) FROM M_Product p" - + " WHERE o.SKU=p.SKU AND o.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL AND SKU IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p") + .append(" WHERE o.SKU=p.SKU AND o.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL AND SKU IS NOT NULL") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Product, ' ") + .append("WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL OR UPC IS NOT NULL OR SKU IS NOT NULL)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Product=" + no); // Charge - sql = new StringBuffer ("UPDATE I_Order o " - + "SET C_Charge_ID=(SELECT C_Charge_ID FROM C_Charge c" - + " WHERE o.ChargeName=c.Name AND o.AD_Client_ID=c.AD_Client_ID) " - + "WHERE C_Charge_ID IS NULL AND ChargeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_Charge_ID=(SELECT C_Charge_ID FROM C_Charge c") + .append(" WHERE o.ChargeName=c.Name AND o.AD_Client_ID=c.AD_Client_ID) ") + .append("WHERE C_Charge_ID IS NULL AND ChargeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Charge=" + no); - sql = new StringBuffer ("UPDATE I_Order " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Charge, ' " - + "WHERE C_Charge_ID IS NULL AND (ChargeName IS NOT NULL)" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Charge, ' ") + .append("WHERE C_Charge_ID IS NULL AND (ChargeName IS NOT NULL)") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Charge=" + no); // - sql = new StringBuffer ("UPDATE I_Order " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Product and Charge, ' " - + "WHERE M_Product_ID IS NOT NULL AND C_Charge_ID IS NOT NULL " - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Product and Charge, ' ") + .append("WHERE M_Product_ID IS NOT NULL AND C_Charge_ID IS NOT NULL ") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Product and Charge exclusive=" + no); // Tax - sql = new StringBuffer ("UPDATE I_Order o " - + "SET C_Tax_ID=(SELECT MAX(C_Tax_ID) FROM C_Tax t" - + " WHERE o.TaxIndicator=t.TaxIndicator AND o.AD_Client_ID=t.AD_Client_ID) " - + "WHERE C_Tax_ID IS NULL AND TaxIndicator IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order o ") + .append("SET C_Tax_ID=(SELECT MAX(C_Tax_ID) FROM C_Tax t") + .append(" WHERE o.TaxIndicator=t.TaxIndicator AND o.AD_Client_ID=t.AD_Client_ID) ") + .append("WHERE C_Tax_ID IS NULL AND TaxIndicator IS NOT NULL") + .append(" 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); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Tax, ' ") + .append("WHERE C_Tax_ID IS NULL AND TaxIndicator IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Tax=" + no); @@ -497,8 +497,8 @@ public class ImportOrder extends SvrProcess // -- 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); + sql = new StringBuilder ("SELECT * FROM I_Order ") + .append("WHERE I_IsImported='N' AND C_BPartner_ID IS NULL").append (clientCheck); try { PreparedStatement pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); @@ -618,10 +618,10 @@ public class ImportOrder extends SvrProcess { log.log(Level.SEVERE, "BP - " + sql.toString(), e); } - sql = new StringBuffer ("UPDATE I_Order " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BPartner, ' " - + "WHERE C_BPartner_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BPartner, ' ") + .append("WHERE C_BPartner_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No BPartner=" + no); @@ -634,8 +634,8 @@ public class ImportOrder extends SvrProcess int noInsertLine = 0; // Go through Order Records w/o - sql = new StringBuffer ("SELECT * FROM I_Order " - + "WHERE I_IsImported='N'").append (clientCheck) + sql = new StringBuilder ("SELECT * FROM I_Order ") + .append("WHERE I_IsImported='N'").append (clientCheck) .append(" ORDER BY C_BPartner_ID, BillTo_ID, C_BPartner_Location_ID, I_Order_ID"); try { @@ -788,15 +788,16 @@ public class ImportOrder extends SvrProcess } // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_Order " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Order ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("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_Order_ID@: @Inserted@"); addLog (0, null, new BigDecimal (noInsertLine), "@C_OrderLine_ID@: @Inserted@"); - return "#" + noInsert + "/" + noInsertLine; + StringBuilder msgreturn = new StringBuilder("#").append(noInsert).append("/").append(noInsertLine); + return msgreturn.toString(); } // doIt } // ImportOrder diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java b/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java index 59ca16b95d..d14a362c84 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java @@ -90,7 +90,7 @@ public class ImportPayment extends SvrProcess p_AD_Org_ID = ba.getAD_Org_ID(); log.info("AD_Org_ID=" + p_AD_Org_ID); - StringBuffer sql = null; + StringBuilder sql = null; int no = 0; String clientCheck = " AND AD_Client_ID=" + ba.getAD_Client_ID(); @@ -99,307 +99,307 @@ public class ImportPayment extends SvrProcess // Delete Old Imported if (p_deleteOldImported) { - sql = new StringBuffer ("DELETE I_Payment " - + "WHERE I_IsImported='Y'").append (clientCheck); + sql = new StringBuilder ("DELETE I_Payment ") + .append("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_Payment " - + "SET AD_Client_ID = COALESCE (AD_Client_ID,").append (ba.getAD_Client_ID()).append (")," - + " AD_Org_ID = COALESCE (AD_Org_ID,").append (p_AD_Org_ID).append ("),"); - sql.append(" IsActive = COALESCE (IsActive, 'Y')," - + " Created = COALESCE (Created, SysDate)," - + " CreatedBy = COALESCE (CreatedBy, 0)," - + " Updated = COALESCE (Updated, SysDate)," - + " UpdatedBy = COALESCE (UpdatedBy, 0)," - + " I_ErrorMsg = ' '," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL OR AD_Client_ID IS NULL OR AD_Org_ID IS NULL OR AD_Client_ID=0 OR AD_Org_ID=0"); + sql = new StringBuilder ("UPDATE I_Payment ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID,").append (ba.getAD_Client_ID()).append ("),") + .append(" AD_Org_ID = COALESCE (AD_Org_ID,").append (p_AD_Org_ID).append ("),"); + sql.append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL OR AD_Client_ID IS NULL OR AD_Org_ID IS NULL OR AD_Client_ID=0 OR AD_Org_ID=0"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info ("Reset=" + no); - sql = new StringBuffer ("UPDATE I_Payment o " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '" - + "WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0" - + " OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Payment o ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Org, '") + .append("WHERE (AD_Org_ID IS NULL OR AD_Org_ID=0") + .append(" OR EXISTS (SELECT * FROM AD_Org oo WHERE o.AD_Org_ID=oo.AD_Org_ID AND (oo.IsSummary='Y' OR oo.IsActive='N')))") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid Org=" + no); // Set Bank Account - sql = new StringBuffer("UPDATE I_Payment i " - + "SET C_BankAccount_ID=" - + "( " - + " SELECT C_BankAccount_ID " - + " FROM C_BankAccount a, C_Bank b " - + " WHERE b.IsOwnBank='Y' " - + " AND a.AD_Client_ID=i.AD_Client_ID " - + " AND a.C_Bank_ID=b.C_Bank_ID " - + " AND a.AccountNo=i.BankAccountNo " - + " AND b.RoutingNo=i.RoutingNo " - + " OR b.SwiftCode=i.RoutingNo " - + ") " - + "WHERE i.C_BankAccount_ID IS NULL " - + "AND i.I_IsImported<>'Y' " - + "OR i.I_IsImported IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment i ") + .append("SET C_BankAccount_ID=") + .append("( ") + .append(" SELECT C_BankAccount_ID ") + .append(" FROM C_BankAccount a, C_Bank b ") + .append(" WHERE b.IsOwnBank='Y' ") + .append(" AND a.AD_Client_ID=i.AD_Client_ID ") + .append(" AND a.C_Bank_ID=b.C_Bank_ID ") + .append(" AND a.AccountNo=i.BankAccountNo ") + .append(" AND b.RoutingNo=i.RoutingNo ") + .append(" OR b.SwiftCode=i.RoutingNo ") + .append(") ") + .append("WHERE i.C_BankAccount_ID IS NULL ") + .append("AND i.I_IsImported<>'Y' ") + .append("OR i.I_IsImported IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Bank Account (With Routing No)=" + no); // - sql = new StringBuffer("UPDATE I_Payment i " - + "SET C_BankAccount_ID=" - + "( " - + " SELECT C_BankAccount_ID " - + " FROM C_BankAccount a, C_Bank b " - + " WHERE b.IsOwnBank='Y' " - + " AND a.C_Bank_ID=b.C_Bank_ID " - + " AND a.AccountNo=i.BankAccountNo " - + " AND a.AD_Client_ID=i.AD_Client_ID " - + ") " - + "WHERE i.C_BankAccount_ID IS NULL " - + "AND i.I_isImported<>'Y' " - + "OR i.I_isImported IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment i ") + .append("SET C_BankAccount_ID=") + .append("( ") + .append(" SELECT C_BankAccount_ID ") + .append(" FROM C_BankAccount a, C_Bank b ") + .append(" WHERE b.IsOwnBank='Y' ") + .append(" AND a.C_Bank_ID=b.C_Bank_ID ") + .append(" AND a.AccountNo=i.BankAccountNo ") + .append(" AND a.AD_Client_ID=i.AD_Client_ID ") + .append(") ") + .append("WHERE i.C_BankAccount_ID IS NULL ") + .append("AND i.I_isImported<>'Y' ") + .append("OR i.I_isImported IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Bank Account (Without Routing No)=" + no); // - sql = new StringBuffer("UPDATE I_Payment i " - + "SET C_BankAccount_ID=(SELECT C_BankAccount_ID FROM C_BankAccount a WHERE a.C_BankAccount_ID=").append(p_C_BankAccount_ID); - sql.append(" and a.AD_Client_ID=i.AD_Client_ID) " - + "WHERE i.C_BankAccount_ID IS NULL " - + "AND i.BankAccountNo IS NULL " - + "AND i.I_isImported<>'Y' " - + "OR i.I_isImported IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment i ") + .append("SET C_BankAccount_ID=(SELECT C_BankAccount_ID FROM C_BankAccount a WHERE a.C_BankAccount_ID=").append(p_C_BankAccount_ID); + sql.append(" and a.AD_Client_ID=i.AD_Client_ID) ") + .append("WHERE i.C_BankAccount_ID IS NULL ") + .append("AND i.BankAccountNo IS NULL ") + .append("AND i.I_isImported<>'Y' ") + .append("OR i.I_isImported IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Bank Account=" + no); // - sql = new StringBuffer("UPDATE I_Payment " - + "SET I_isImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Bank Account, ' " - + "WHERE C_BankAccount_ID IS NULL " - + "AND I_isImported<>'Y' " - + "OR I_isImported IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET I_isImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Bank Account, ' ") + .append("WHERE C_BankAccount_ID IS NULL ") + .append("AND I_isImported<>'Y' ") + .append("OR I_isImported IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Invalid Bank Account=" + no); // Set Currency - sql = new StringBuffer ("UPDATE I_Payment i " - + "SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c" - + " WHERE i.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) " - + "WHERE C_Currency_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Payment i ") + .append("SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c") + .append(" WHERE i.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) ") + .append("WHERE C_Currency_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Set Currency=" + no); // - sql = new StringBuffer("UPDATE I_Payment i " - + "SET C_Currency_ID=(SELECT C_Currency_ID FROM C_BankAccount WHERE C_BankAccount_ID=i.C_BankAccount_ID) " - + "WHERE i.C_Currency_ID IS NULL " - + "AND i.ISO_Code IS NULL").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment i ") + .append("SET C_Currency_ID=(SELECT C_Currency_ID FROM C_BankAccount WHERE C_BankAccount_ID=i.C_BankAccount_ID) ") + .append("WHERE i.C_Currency_ID IS NULL ") + .append("AND i.ISO_Code IS NULL").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Set Currency=" + no); // - sql = new StringBuffer ("UPDATE I_Payment " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Currency,' " - + "WHERE C_Currency_ID IS NULL " - + "AND I_IsImported<>'E' " - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Payment ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Currency,' ") + .append("WHERE C_Currency_ID IS NULL ") + .append("AND I_IsImported<>'E' ") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("No Currency=" + no); // Set Amount - sql = new StringBuffer("UPDATE I_Payment " - + "SET ChargeAmt=0 " - + "WHERE ChargeAmt IS NULL " - + "AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET ChargeAmt=0 ") + .append("WHERE ChargeAmt IS NULL ") + .append("AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Charge Amount=" + no); // - sql = new StringBuffer("UPDATE I_Payment " - + "SET TaxAmt=0 " - + "WHERE TaxAmt IS NULL " - + "AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET TaxAmt=0 ") + .append("WHERE TaxAmt IS NULL ") + .append("AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Tax Amount=" + no); // - sql = new StringBuffer("UPDATE I_Payment " - + "SET WriteOffAmt=0 " - + "WHERE WriteOffAmt IS NULL " - + "AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET WriteOffAmt=0 ") + .append("WHERE WriteOffAmt IS NULL ") + .append("AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("WriteOff Amount=" + no); // - sql = new StringBuffer("UPDATE I_Payment " - + "SET DiscountAmt=0 " - + "WHERE DiscountAmt IS NULL " - + "AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET DiscountAmt=0 ") + .append("WHERE DiscountAmt IS NULL ") + .append("AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Discount Amount=" + no); // // Set Date - sql = new StringBuffer("UPDATE I_Payment " - + "SET DateTrx=Created " - + "WHERE DateTrx IS NULL " - + "AND I_isImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET DateTrx=Created ") + .append("WHERE DateTrx IS NULL ") + .append("AND I_isImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Trx Date=" + no); - sql = new StringBuffer("UPDATE I_Payment " - + "SET DateAcct=DateTrx " - + "WHERE DateAcct IS NULL " - + "AND I_isImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET DateAcct=DateTrx ") + .append("WHERE DateAcct IS NULL ") + .append("AND I_isImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Acct Date=" + no); // Invoice - sql = new StringBuffer ("UPDATE I_Payment i " - + "SET C_Invoice_ID=(SELECT MAX(C_Invoice_ID) FROM C_Invoice ii" - + " WHERE i.InvoiceDocumentNo=ii.DocumentNo AND i.AD_Client_ID=ii.AD_Client_ID) " - + "WHERE C_Invoice_ID IS NULL AND InvoiceDocumentNo IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Payment i ") + .append("SET C_Invoice_ID=(SELECT MAX(C_Invoice_ID) FROM C_Invoice ii") + .append(" WHERE i.InvoiceDocumentNo=ii.DocumentNo AND i.AD_Client_ID=ii.AD_Client_ID) ") + .append("WHERE C_Invoice_ID IS NULL AND InvoiceDocumentNo IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set Invoice from DocumentNo=" + no); // BPartner - sql = new StringBuffer ("UPDATE I_Payment i " - + "SET C_BPartner_ID=(SELECT MAX(C_BPartner_ID) FROM C_BPartner bp" - + " WHERE i.BPartnerValue=bp.Value AND i.AD_Client_ID=bp.AD_Client_ID) " - + "WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Payment i ") + .append("SET C_BPartner_ID=(SELECT MAX(C_BPartner_ID) FROM C_BPartner bp") + .append(" WHERE i.BPartnerValue=bp.Value AND i.AD_Client_ID=bp.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NULL AND BPartnerValue IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set BP from Value=" + no); - sql = new StringBuffer ("UPDATE I_Payment i " - + "SET C_BPartner_ID=(SELECT MAX(C_BPartner_ID) FROM C_Invoice ii" - + " WHERE i.C_Invoice_ID=ii.C_Invoice_ID AND i.AD_Client_ID=ii.AD_Client_ID) " - + "WHERE C_BPartner_ID IS NULL AND C_Invoice_ID IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Payment i ") + .append("SET C_BPartner_ID=(SELECT MAX(C_BPartner_ID) FROM C_Invoice ii") + .append(" WHERE i.C_Invoice_ID=ii.C_Invoice_ID AND i.AD_Client_ID=ii.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NULL AND C_Invoice_ID IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set BP from Invoice=" + no); - sql = new StringBuffer ("UPDATE I_Payment " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BPartner,' " - + "WHERE C_BPartner_ID IS NULL " - + "AND I_IsImported<>'E' " - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Payment ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BPartner,' ") + .append("WHERE C_BPartner_ID IS NULL ") + .append("AND I_IsImported<>'E' ") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("No BPartner=" + no); // Check Payment<->Invoice combination - sql = new StringBuffer("UPDATE I_Payment " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->Invoice, ' " - + "WHERE I_Payment_ID IN " - + "(SELECT I_Payment_ID " - + "FROM I_Payment i" - + " INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) " - + "WHERE i.C_Invoice_ID IS NOT NULL " - + " AND p.C_Invoice_ID IS NOT NULL " - + " AND p.C_Invoice_ID<>i.C_Invoice_ID) ") + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->Invoice, ' ") + .append("WHERE I_Payment_ID IN ") + .append("(SELECT I_Payment_ID ") + .append("FROM I_Payment i") + .append(" INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) ") + .append("WHERE i.C_Invoice_ID IS NOT NULL ") + .append(" AND p.C_Invoice_ID IS NOT NULL ") + .append(" AND p.C_Invoice_ID<>i.C_Invoice_ID) ") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Payment<->Invoice Mismatch=" + no); // Check Payment<->BPartner combination - sql = new StringBuffer("UPDATE I_Payment " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->BPartner, ' " - + "WHERE I_Payment_ID IN " - + "(SELECT I_Payment_ID " - + "FROM I_Payment i" - + " INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) " - + "WHERE i.C_BPartner_ID IS NOT NULL " - + " AND p.C_BPartner_ID IS NOT NULL " - + " AND p.C_BPartner_ID<>i.C_BPartner_ID) ") + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Payment<->BPartner, ' ") + .append("WHERE I_Payment_ID IN ") + .append("(SELECT I_Payment_ID ") + .append("FROM I_Payment i") + .append(" INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) ") + .append("WHERE i.C_BPartner_ID IS NOT NULL ") + .append(" AND p.C_BPartner_ID IS NOT NULL ") + .append(" AND p.C_BPartner_ID<>i.C_BPartner_ID) ") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Payment<->BPartner Mismatch=" + no); // Check Invoice<->BPartner combination - sql = new StringBuffer("UPDATE I_Payment " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Invoice<->BPartner, ' " - + "WHERE I_Payment_ID IN " - + "(SELECT I_Payment_ID " - + "FROM I_Payment i" - + " INNER JOIN C_Invoice v ON (i.C_Invoice_ID=v.C_Invoice_ID) " - + "WHERE i.C_BPartner_ID IS NOT NULL " - + " AND v.C_BPartner_ID IS NOT NULL " - + " AND v.C_BPartner_ID<>i.C_BPartner_ID) ") + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Invoice<->BPartner, ' ") + .append("WHERE I_Payment_ID IN ") + .append("(SELECT I_Payment_ID ") + .append("FROM I_Payment i") + .append(" INNER JOIN C_Invoice v ON (i.C_Invoice_ID=v.C_Invoice_ID) ") + .append("WHERE i.C_BPartner_ID IS NOT NULL ") + .append(" AND v.C_BPartner_ID IS NOT NULL ") + .append(" AND v.C_BPartner_ID<>i.C_BPartner_ID) ") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Invoice<->BPartner Mismatch=" + no); // Check Invoice.BPartner<->Payment.BPartner combination - sql = new StringBuffer("UPDATE I_Payment " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Invoice.BPartner<->Payment.BPartner, ' " - + "WHERE I_Payment_ID IN " - + "(SELECT I_Payment_ID " - + "FROM I_Payment i" - + " INNER JOIN C_Invoice v ON (i.C_Invoice_ID=v.C_Invoice_ID)" - + " INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) " - + "WHERE p.C_Invoice_ID<>v.C_Invoice_ID" - + " AND v.C_BPartner_ID<>p.C_BPartner_ID) ") + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Err=Invalid Invoice.BPartner<->Payment.BPartner, ' ") + .append("WHERE I_Payment_ID IN ") + .append("(SELECT I_Payment_ID ") + .append("FROM I_Payment i") + .append(" INNER JOIN C_Invoice v ON (i.C_Invoice_ID=v.C_Invoice_ID)") + .append(" INNER JOIN C_Payment p ON (i.C_Payment_ID=p.C_Payment_ID) ") + .append("WHERE p.C_Invoice_ID<>v.C_Invoice_ID") + .append(" AND v.C_BPartner_ID<>p.C_BPartner_ID) ") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("Invoice.BPartner<->Payment.BPartner Mismatch=" + no); // TrxType - sql = new StringBuffer("UPDATE I_Payment " - + "SET TrxType='S' " // MPayment.TRXTYPE_Sales - + "WHERE TrxType IS NULL " - + "AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET TrxType='S' ") // MPayment.TRXTYPE_Sales + .append("WHERE TrxType IS NULL ") + .append("AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("TrxType Default=" + no); // TenderType - sql = new StringBuffer("UPDATE I_Payment " - + "SET TenderType='K' " // MPayment.TENDERTYPE_Check - + "WHERE TenderType IS NULL " - + "AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder("UPDATE I_Payment ") + .append("SET TenderType='K' ") // MPayment.TENDERTYPE_Check + .append("WHERE TenderType IS NULL ") + .append("AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.info("TenderType Default=" + no); // Document Type - sql = new StringBuffer ("UPDATE I_Payment i " - + "SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=i.DocTypeName" - + " AND d.DocBaseType IN ('ARR','APP') AND i.AD_Client_ID=d.AD_Client_ID) " - + "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Payment i ") + .append("SET C_DocType_ID=(SELECT C_DocType_ID FROM C_DocType d WHERE d.Name=i.DocTypeName") + .append(" AND d.DocBaseType IN ('ARR','APP') AND i.AD_Client_ID=d.AD_Client_ID) ") + .append("WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine("Set DocType=" + no); - sql = new StringBuffer ("UPDATE I_Payment " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocTypeName, ' " - + "WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Payment ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid DocTypeName, ' ") + .append("WHERE C_DocType_ID IS NULL AND DocTypeName IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("Invalid DocTypeName=" + no); - sql = new StringBuffer ("UPDATE I_Payment " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No DocType, ' " - + "WHERE C_DocType_ID IS NULL" - + " AND I_IsImported<>'Y'").append (clientCheck); + sql = new StringBuilder ("UPDATE I_Payment ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No DocType, ' ") + .append("WHERE C_DocType_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append (clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning ("No DocType=" + no); @@ -407,9 +407,9 @@ public class ImportPayment extends SvrProcess commitEx(); //Import Bank Statement - sql = new StringBuffer("SELECT * FROM I_Payment" - + " WHERE I_IsImported='N'" - + " ORDER BY C_BankAccount_ID, CheckNo, DateTrx, R_AuthCode"); + sql = new StringBuilder("SELECT * FROM I_Payment") + .append(" WHERE I_IsImported='N'") + .append(" ORDER BY C_BankAccount_ID, CheckNo, DateTrx, R_AuthCode"); MBankAccount account = null; PreparedStatement pstmt = null; @@ -526,9 +526,9 @@ public class ImportPayment extends SvrProcess } // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_Payment " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Payment ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("WHERE I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); addLog (0, null, new BigDecimal (no), "@Errors@"); // diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportProduct.java b/org.adempiere.base.process/src/org/compiere/process/ImportProduct.java index a53510c97b..3b2c644945 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportProduct.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportProduct.java @@ -83,7 +83,7 @@ public class ImportProduct extends SvrProcess implements ImportProcess */ protected String doIt() throws java.lang.Exception { - StringBuffer sql = null; + StringBuilder sql = null; int no = 0; String clientCheck = getWhereClause(); @@ -92,43 +92,43 @@ public class ImportProduct extends SvrProcess implements ImportProcess // Delete Old Imported if (m_deleteOldImported) { - sql = new StringBuffer ("DELETE I_Product " - + "WHERE I_IsImported='Y'").append(clientCheck); + sql = new StringBuilder ("DELETE I_Product ") + .append("WHERE I_IsImported='Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Delete Old Imported =" + no); } // Set Client, Org, IaActive, Created/Updated, ProductType - sql = new StringBuffer ("UPDATE I_Product " - + "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)," - + " ProductType = COALESCE (ProductType, 'I')," - + " I_ErrorMsg = ' '," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql = new StringBuilder ("UPDATE I_Product ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),") + .append(" AD_Org_ID = COALESCE (AD_Org_ID, 0),") + .append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" ProductType = COALESCE (ProductType, 'I'),") + .append(" I_ErrorMsg = ' ',") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Reset=" + no); ModelValidationEngine.get().fireImportValidate(this, null, null, ImportValidator.TIMING_BEFORE_VALIDATE); // Set Optional BPartner - sql = new StringBuffer ("UPDATE I_Product i " - + "SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner p" - + " WHERE i.BPartner_Value=p.Value AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE C_BPartner_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner p") + .append(" WHERE i.BPartner_Value=p.Value AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE C_BPartner_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("BPartner=" + no); // - sql = new StringBuffer ("UPDATE I_Product " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid BPartner,' " - + "WHERE C_BPartner_ID IS NULL AND BPartner_Value IS NOT NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid BPartner,' ") + .append("WHERE C_BPartner_ID IS NULL AND BPartner_Value IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Invalid BPartner=" + no); @@ -136,48 +136,48 @@ public class ImportProduct extends SvrProcess implements ImportProcess // **** Find Product // EAN/UPC - sql = new StringBuffer ("UPDATE I_Product i " - + "SET M_Product_ID=(SELECT M_Product_ID FROM M_Product p" - + " WHERE i.UPC=p.UPC AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET M_Product_ID=(SELECT M_Product_ID FROM M_Product p") + .append(" WHERE i.UPC=p.UPC AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Product Existing UPC=" + no); // Value - sql = new StringBuffer ("UPDATE I_Product i " - + "SET M_Product_ID=(SELECT M_Product_ID FROM M_Product p" - + " WHERE i.Value=p.Value AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET M_Product_ID=(SELECT M_Product_ID FROM M_Product p") + .append(" WHERE i.Value=p.Value AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Product Existing Value=" + no); // BP ProdNo - sql = new StringBuffer ("UPDATE I_Product i " - + "SET M_Product_ID=(SELECT M_Product_ID FROM M_Product_po p" - + " WHERE i.C_BPartner_ID=p.C_BPartner_ID" - + " AND i.VendorProductNo=p.VendorProductNo AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET M_Product_ID=(SELECT M_Product_ID FROM M_Product_po p") + .append(" WHERE i.C_BPartner_ID=p.C_BPartner_ID") + .append(" AND i.VendorProductNo=p.VendorProductNo AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Product Existing Vendor ProductNo=" + no); // Set Product Category - sql = new StringBuffer ("UPDATE I_Product " - + "SET ProductCategory_Value=(SELECT MAX(Value) FROM M_Product_Category" - + " WHERE IsDefault='Y' AND AD_Client_ID=").append(m_AD_Client_ID).append(") " - + "WHERE ProductCategory_Value IS NULL AND M_Product_Category_ID IS NULL" - + " AND M_Product_ID IS NULL" // set category only if product not found - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product ") + .append("SET ProductCategory_Value=(SELECT MAX(Value) FROM M_Product_Category") + .append(" WHERE IsDefault='Y' AND AD_Client_ID=").append(m_AD_Client_ID).append(") ") + .append("WHERE ProductCategory_Value IS NULL AND M_Product_Category_ID IS NULL") + .append(" AND M_Product_ID IS NULL") // set category only if product not found + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Category Default Value=" + no); // - sql = new StringBuffer ("UPDATE I_Product i " - + "SET M_Product_Category_ID=(SELECT M_Product_Category_ID FROM M_Product_Category c" - + " WHERE i.ProductCategory_Value=c.Value AND i.AD_Client_ID=c.AD_Client_ID) " - + "WHERE ProductCategory_Value IS NOT NULL AND M_Product_Category_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET M_Product_Category_ID=(SELECT M_Product_Category_ID FROM M_Product_Category c") + .append(" WHERE i.ProductCategory_Value=c.Value AND i.AD_Client_ID=c.AD_Client_ID) ") + .append("WHERE ProductCategory_Value IS NOT NULL AND M_Product_Category_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Set Category=" + no); @@ -188,12 +188,12 @@ public class ImportProduct extends SvrProcess implements ImportProcess "Discontinued","DiscontinuedBy","DiscontinuedAt","ImageURL","DescriptionURL"}; for (int i = 0; i < strFields.length; i++) { - sql = new StringBuffer ("UPDATE I_Product i " - + "SET ").append(strFields[i]).append(" = (SELECT ").append(strFields[i]).append(" FROM M_Product p" - + " WHERE i.M_Product_ID=p.M_Product_ID AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NOT NULL" - + " AND ").append(strFields[i]).append(" IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET ").append(strFields[i]).append(" = (SELECT ").append(strFields[i]).append(" FROM M_Product p") + .append(" WHERE i.M_Product_ID=p.M_Product_ID AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NOT NULL") + .append(" AND ").append(strFields[i]).append(" IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine(strFields[i] + " - default from existing Product=" + no); @@ -202,12 +202,12 @@ public class ImportProduct extends SvrProcess implements ImportProcess "Volume","Weight","ShelfWidth","ShelfHeight","ShelfDepth","UnitsPerPallet"}; for (int i = 0; i < numFields.length; i++) { - sql = new StringBuffer ("UPDATE I_PRODUCT i " - + "SET ").append(numFields[i]).append(" = (SELECT ").append(numFields[i]).append(" FROM M_Product p" - + " WHERE i.M_Product_ID=p.M_Product_ID AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NOT NULL" - + " AND (").append(numFields[i]).append(" IS NULL OR ").append(numFields[i]).append("=0)" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_PRODUCT i ") + .append("SET ").append(numFields[i]).append(" = (SELECT ").append(numFields[i]).append(" FROM M_Product p") + .append(" WHERE i.M_Product_ID=p.M_Product_ID AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NOT NULL") + .append(" AND (").append(numFields[i]).append(" IS NULL OR ").append(numFields[i]).append("=0)") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine(numFields[i] + " default from existing Product=" + no); @@ -219,13 +219,13 @@ public class ImportProduct extends SvrProcess implements ImportProcess "Discontinued","DiscontinuedBy", "DiscontinuedAt"}; for (int i = 0; i < strFieldsPO.length; i++) { - sql = new StringBuffer ("UPDATE I_PRODUCT i " - + "SET ").append(strFieldsPO[i]).append(" = (SELECT ").append(strFieldsPO[i]) - .append(" FROM M_Product_PO p" - + " WHERE i.M_Product_ID=p.M_Product_ID AND i.C_BPartner_ID=p.C_BPartner_ID AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NOT NULL AND C_BPartner_ID IS NOT NULL" - + " AND ").append(strFieldsPO[i]).append(" IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_PRODUCT i ") + .append("SET ").append(strFieldsPO[i]).append(" = (SELECT ").append(strFieldsPO[i]) + .append(" FROM M_Product_PO p") + .append(" WHERE i.M_Product_ID=p.M_Product_ID AND i.C_BPartner_ID=p.C_BPartner_ID AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NOT NULL AND C_BPartner_ID IS NOT NULL") + .append(" AND ").append(strFieldsPO[i]).append(" IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine(strFieldsPO[i] + " default from existing Product PO=" + no); @@ -235,111 +235,111 @@ public class ImportProduct extends SvrProcess implements ImportProcess "Order_Min","Order_Pack","CostPerOrder","DeliveryTime_Promised"}; for (int i = 0; i < numFieldsPO.length; i++) { - sql = new StringBuffer ("UPDATE I_PRODUCT i " - + "SET ").append(numFieldsPO[i]).append(" = (SELECT ").append(numFieldsPO[i]) - .append(" FROM M_Product_PO p" - + " WHERE i.M_Product_ID=p.M_Product_ID AND i.C_BPartner_ID=p.C_BPartner_ID AND i.AD_Client_ID=p.AD_Client_ID) " - + "WHERE M_Product_ID IS NOT NULL AND C_BPartner_ID IS NOT NULL" - + " AND (").append(numFieldsPO[i]).append(" IS NULL OR ").append(numFieldsPO[i]).append("=0)" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_PRODUCT i ") + .append("SET ").append(numFieldsPO[i]).append(" = (SELECT ").append(numFieldsPO[i]) + .append(" FROM M_Product_PO p") + .append(" WHERE i.M_Product_ID=p.M_Product_ID AND i.C_BPartner_ID=p.C_BPartner_ID AND i.AD_Client_ID=p.AD_Client_ID) ") + .append("WHERE M_Product_ID IS NOT NULL AND C_BPartner_ID IS NOT NULL") + .append(" AND (").append(numFieldsPO[i]).append(" IS NULL OR ").append(numFieldsPO[i]).append("=0)") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.fine(numFieldsPO[i] + " default from existing Product PO=" + no); } // Invalid Category - sql = new StringBuffer ("UPDATE I_Product " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ProdCategory,' " - + "WHERE M_Product_Category_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ProdCategory,' ") + .append("WHERE M_Product_Category_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Invalid Category=" + no); // Set UOM (System/own) - sql = new StringBuffer ("UPDATE I_Product i " - + "SET X12DE355 = " - + "(SELECT MAX(X12DE355) FROM C_UOM u WHERE u.IsDefault='Y' AND u.AD_Client_ID IN (0,i.AD_Client_ID)) " - + "WHERE X12DE355 IS NULL AND C_UOM_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET X12DE355 = ") + .append("(SELECT MAX(X12DE355) FROM C_UOM u WHERE u.IsDefault='Y' AND u.AD_Client_ID IN (0,i.AD_Client_ID)) ") + .append("WHERE X12DE355 IS NULL AND C_UOM_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set UOM Default=" + no); // - sql = new StringBuffer ("UPDATE I_Product i " - + "SET C_UOM_ID = (SELECT C_UOM_ID FROM C_UOM u WHERE u.X12DE355=i.X12DE355 AND u.AD_Client_ID IN (0,i.AD_Client_ID)) " - + "WHERE C_UOM_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET C_UOM_ID = (SELECT C_UOM_ID FROM C_UOM u WHERE u.X12DE355=i.X12DE355 AND u.AD_Client_ID IN (0,i.AD_Client_ID)) ") + .append("WHERE C_UOM_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Set UOM=" + no); // - sql = new StringBuffer ("UPDATE I_Product " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid UOM, ' " - + "WHERE C_UOM_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid UOM, ' ") + .append("WHERE C_UOM_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Invalid UOM=" + no); // Set Currency - sql = new StringBuffer ("UPDATE I_Product i " - + "SET ISO_Code=(SELECT ISO_Code FROM C_Currency c" - + " INNER JOIN C_AcctSchema a ON (a.C_Currency_ID=c.C_Currency_ID)" - + " INNER JOIN AD_ClientInfo ci ON (a.C_AcctSchema_ID=ci.C_AcctSchema1_ID)" - + " WHERE ci.AD_Client_ID=i.AD_Client_ID) " - + "WHERE C_Currency_ID IS NULL AND ISO_Code IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET ISO_Code=(SELECT ISO_Code FROM C_Currency c") + .append(" INNER JOIN C_AcctSchema a ON (a.C_Currency_ID=c.C_Currency_ID)") + .append(" INNER JOIN AD_ClientInfo ci ON (a.C_AcctSchema_ID=ci.C_AcctSchema1_ID)") + .append(" WHERE ci.AD_Client_ID=i.AD_Client_ID) ") + .append("WHERE C_Currency_ID IS NULL AND ISO_Code IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set Currency Default=" + no); // - sql = new StringBuffer ("UPDATE I_Product i " - + "SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c" - + " WHERE i.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) " - + "WHERE C_Currency_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c") + .append(" WHERE i.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,i.AD_Client_ID)) ") + .append("WHERE C_Currency_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("doIt- Set Currency=" + no); // - sql = new StringBuffer ("UPDATE I_Product " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Currency,' " - + "WHERE C_Currency_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Currency,' ") + .append("WHERE C_Currency_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Invalid Currency=" + no); // Verify ProductType - sql = new StringBuffer ("UPDATE I_Product " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ProductType,' " - + "WHERE ProductType NOT IN ('E','I','R','S')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ProductType,' ") + .append("WHERE ProductType NOT IN ('E','I','R','S')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Invalid ProductType=" + no); // Unique UPC/Value - sql = new StringBuffer ("UPDATE I_Product i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Value not unique,' " - + "WHERE I_IsImported<>'Y'" - + " AND Value IN (SELECT Value FROM I_Product ii WHERE i.AD_Client_ID=ii.AD_Client_ID GROUP BY Value HAVING COUNT(*) > 1)").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Value not unique,' ") + .append("WHERE I_IsImported<>'Y'") + .append(" AND Value IN (SELECT Value FROM I_Product ii WHERE i.AD_Client_ID=ii.AD_Client_ID GROUP BY Value HAVING COUNT(*) > 1)").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Not Unique Value=" + no); // - sql = new StringBuffer ("UPDATE I_Product i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=UPC not unique,' " - + "WHERE I_IsImported<>'Y'" - + " AND UPC IN (SELECT UPC FROM I_Product ii WHERE i.AD_Client_ID=ii.AD_Client_ID GROUP BY UPC HAVING COUNT(*) > 1)").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=UPC not unique,' ") + .append("WHERE I_IsImported<>'Y'") + .append(" AND UPC IN (SELECT UPC FROM I_Product ii WHERE i.AD_Client_ID=ii.AD_Client_ID GROUP BY UPC HAVING COUNT(*) > 1)").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("Not Unique UPC=" + no); // Mandatory Value - sql = new StringBuffer ("UPDATE I_Product i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Mandatory Value,' " - + "WHERE Value IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Mandatory Value,' ") + .append("WHERE Value IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) log.warning("No Mandatory Value=" + no); @@ -351,19 +351,19 @@ public class ImportProduct extends SvrProcess implements ImportProcess // + " AND VendorProductNo IS NULL AND (C_BPartner_ID IS NOT NULL OR BPartner_Value IS NOT NULL)").append(clientCheck); // no = DB.executeUpdate(sql.toString(), get_TrxName()); // log.info(log.l3_Util, "No Mandatory VendorProductNo=" + no); - sql = new StringBuffer ("UPDATE I_Product " - + "SET VendorProductNo=Value " - + "WHERE C_BPartner_ID IS NOT NULL AND VendorProductNo IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product ") + .append("SET VendorProductNo=Value ") + .append("WHERE C_BPartner_ID IS NOT NULL AND VendorProductNo IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("VendorProductNo Set to Value=" + no); // - sql = new StringBuffer ("UPDATE I_Product i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=VendorProductNo not unique,' " - + "WHERE I_IsImported<>'Y'" - + " AND C_BPartner_ID IS NOT NULL" - + " AND (C_BPartner_ID, VendorProductNo) IN " - + " (SELECT C_BPartner_ID, VendorProductNo FROM I_Product ii WHERE i.AD_Client_ID=ii.AD_Client_ID GROUP BY C_BPartner_ID, VendorProductNo HAVING COUNT(*) > 1)") + sql = new StringBuilder ("UPDATE I_Product i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=VendorProductNo not unique,' ") + .append("WHERE I_IsImported<>'Y'") + .append(" AND C_BPartner_ID IS NOT NULL") + .append(" AND (C_BPartner_ID, VendorProductNo) IN ") + .append(" (SELECT C_BPartner_ID, VendorProductNo FROM I_Product ii WHERE i.AD_Client_ID=ii.AD_Client_ID GROUP BY C_BPartner_ID, VendorProductNo HAVING COUNT(*) > 1)") .append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); if (no != 0) @@ -373,8 +373,8 @@ public class ImportProduct extends SvrProcess implements ImportProcess int C_TaxCategory_ID = 0; try { - PreparedStatement pstmt = DB.prepareStatement - ("SELECT C_TaxCategory_ID FROM C_TaxCategory WHERE IsDefault='Y'" + clientCheck, get_TrxName()); + StringBuilder dbpst = new StringBuilder("SELECT C_TaxCategory_ID FROM C_TaxCategory WHERE IsDefault='Y'").append(clientCheck); + PreparedStatement pstmt = DB.prepareStatement(dbpst.toString(), get_TrxName()); ResultSet rs = pstmt.executeQuery(); if (rs.next()) C_TaxCategory_ID = rs.getInt(1); @@ -399,7 +399,7 @@ public class ImportProduct extends SvrProcess implements ImportProcess // Go through Records log.fine("start inserting/updating ..."); - sql = new StringBuffer ("SELECT * FROM I_Product WHERE I_IsImported='N'") + sql = new StringBuilder ("SELECT * FROM I_Product WHERE I_IsImported='N'") .append(clientCheck); try { @@ -504,8 +504,8 @@ public class ImportProduct extends SvrProcess implements ImportProcess } else { - StringBuffer sql0 = new StringBuffer ("UPDATE I_Product i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert Product failed")) + StringBuilder sql0 = new StringBuilder ("UPDATE I_Product i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert Product failed")) .append("WHERE I_Product_ID=").append(I_Product_ID); DB.executeUpdate(sql0.toString(), get_TrxName()); continue; @@ -513,19 +513,19 @@ public class ImportProduct extends SvrProcess implements ImportProcess } else // Update Product { - String sqlt = "UPDATE M_PRODUCT " - + "SET (Value,Name,Description,DocumentNote,Help," - + "UPC,SKU,C_UOM_ID,M_Product_Category_ID,Classification,ProductType," - + "Volume,Weight,ShelfWidth,ShelfHeight,ShelfDepth,UnitsPerPallet," - + "Discontinued,DiscontinuedBy, DiscontinuedAt, Updated,UpdatedBy)= " - + "(SELECT Value,Name,Description,DocumentNote,Help," - + "UPC,SKU,C_UOM_ID,M_Product_Category_ID,Classification,ProductType," - + "Volume,Weight,ShelfWidth,ShelfHeight,ShelfDepth,UnitsPerPallet," - + "Discontinued,DiscontinuedBy, DiscontinuedAt, SysDate,UpdatedBy" - + " FROM I_Product WHERE I_Product_ID="+I_Product_ID+") " - + "WHERE M_Product_ID="+M_Product_ID; + StringBuilder sqlt = new StringBuilder("UPDATE M_PRODUCT ") + .append("SET (Value,Name,Description,DocumentNote,Help,") + .append("UPC,SKU,C_UOM_ID,M_Product_Category_ID,Classification,ProductType,") + .append("Volume,Weight,ShelfWidth,ShelfHeight,ShelfDepth,UnitsPerPallet,") + .append("Discontinued,DiscontinuedBy, DiscontinuedAt, Updated,UpdatedBy)= ") + .append("(SELECT Value,Name,Description,DocumentNote,Help,") + .append("UPC,SKU,C_UOM_ID,M_Product_Category_ID,Classification,ProductType,") + .append("Volume,Weight,ShelfWidth,ShelfHeight,ShelfDepth,UnitsPerPallet,") + .append("Discontinued,DiscontinuedBy, DiscontinuedAt, SysDate,UpdatedBy") + .append(" FROM I_Product WHERE I_Product_ID=").append(I_Product_ID).append(") ") + .append("WHERE M_Product_ID=").append(M_Product_ID); PreparedStatement pstmt_updateProduct = DB.prepareStatement - (sqlt, get_TrxName()); + (sqlt.toString(), get_TrxName()); //jz pstmt_updateProduct.setInt(1, I_Product_ID); // pstmt_updateProduct.setInt(2, M_Product_ID); @@ -538,8 +538,8 @@ public class ImportProduct extends SvrProcess implements ImportProcess catch (SQLException ex) { log.warning("Update Product - " + ex.toString()); - StringBuffer sql0 = new StringBuffer ("UPDATE I_Product i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Update Product: " + ex.toString())) + StringBuilder sql0 = new StringBuilder ("UPDATE I_Product i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Update Product: " + ex.toString())) .append("WHERE I_Product_ID=").append(I_Product_ID); DB.executeUpdate(sql0.toString(), get_TrxName()); continue; @@ -554,22 +554,22 @@ public class ImportProduct extends SvrProcess implements ImportProcess // If Product existed, Try to Update first if (!newProduct) { - String sqlt = "UPDATE M_Product_PO " - + "SET (IsCurrentVendor,C_UOM_ID,C_Currency_ID,UPC," - + "PriceList,PricePO,RoyaltyAmt,PriceEffective," - + "VendorProductNo,VendorCategory,Manufacturer," - + "Discontinued,DiscontinuedBy, DiscontinuedAt, Order_Min,Order_Pack," - + "CostPerOrder,DeliveryTime_Promised,Updated,UpdatedBy)= " - + "(SELECT CAST('Y' AS CHAR),C_UOM_ID,C_Currency_ID,UPC," //jz fix EDB unknown datatype error - + "PriceList,PricePO,RoyaltyAmt,PriceEffective," - + "VendorProductNo,VendorCategory,Manufacturer," - + "Discontinued,DiscontinuedBy, DiscontinuedAt, Order_Min,Order_Pack," - + "CostPerOrder,DeliveryTime_Promised,SysDate,UpdatedBy" - + " FROM I_Product" - + " WHERE I_Product_ID="+I_Product_ID+") " - + "WHERE M_Product_ID="+M_Product_ID+" AND C_BPartner_ID="+C_BPartner_ID; + StringBuilder sqlt = new StringBuilder("UPDATE M_Product_PO ") + .append("SET (IsCurrentVendor,C_UOM_ID,C_Currency_ID,UPC,") + .append("PriceList,PricePO,RoyaltyAmt,PriceEffective,") + .append("VendorProductNo,VendorCategory,Manufacturer,") + .append("Discontinued,DiscontinuedBy, DiscontinuedAt, Order_Min,Order_Pack,") + .append("CostPerOrder,DeliveryTime_Promised,Updated,UpdatedBy)= ") + .append("(SELECT CAST('Y' AS CHAR),C_UOM_ID,C_Currency_ID,UPC,") //jz fix EDB unknown datatype error + .append("PriceList,PricePO,RoyaltyAmt,PriceEffective,") + .append("VendorProductNo,VendorCategory,Manufacturer,") + .append("Discontinued,DiscontinuedBy, DiscontinuedAt, Order_Min,Order_Pack,") + .append("CostPerOrder,DeliveryTime_Promised,SysDate,UpdatedBy") + .append(" FROM I_Product") + .append(" WHERE I_Product_ID=").append(I_Product_ID).append(") ") + .append("WHERE M_Product_ID=").append(M_Product_ID).append(" AND C_BPartner_ID=").append(C_BPartner_ID); PreparedStatement pstmt_updateProductPO = DB.prepareStatement - (sqlt, get_TrxName()); + (sqlt.toString(), get_TrxName()); //jz pstmt_updateProductPO.setInt(1, I_Product_ID); // pstmt_updateProductPO.setInt(2, M_Product_ID); // pstmt_updateProductPO.setInt(3, C_BPartner_ID); @@ -584,8 +584,8 @@ public class ImportProduct extends SvrProcess implements ImportProcess log.warning("Update Product_PO - " + ex.toString()); noUpdate--; rollback(); - StringBuffer sql0 = new StringBuffer ("UPDATE I_Product i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Update Product_PO: " + ex.toString())) + StringBuilder sql0 = new StringBuilder ("UPDATE I_Product i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Update Product_PO: " + ex.toString())) .append("WHERE I_Product_ID=").append(I_Product_ID); DB.executeUpdate(sql0.toString(), get_TrxName()); continue; @@ -608,8 +608,8 @@ public class ImportProduct extends SvrProcess implements ImportProcess log.warning("Insert Product_PO - " + ex.toString()); noInsert--; // assume that product also did not exist rollback(); - StringBuffer sql0 = new StringBuffer ("UPDATE I_Product i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert Product_PO: " + ex.toString())) + StringBuilder sql0 = new StringBuilder ("UPDATE I_Product i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert Product_PO: " + ex.toString())) .append("WHERE I_Product_ID=").append(I_Product_ID); DB.executeUpdate(sql0.toString(), get_TrxName()); continue; @@ -659,9 +659,9 @@ public class ImportProduct extends SvrProcess implements ImportProcess } // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_Product " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_Product ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("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), "@M_Product_ID@: @Inserted@"); @@ -680,7 +680,8 @@ public class ImportProduct extends SvrProcess implements ImportProcess @Override public String getWhereClause() { - return " AND AD_Client_ID=" + m_AD_Client_ID; + StringBuilder msgreturn = new StringBuilder(" AND AD_Client_ID=").append(m_AD_Client_ID); + return msgreturn.toString(); } } // ImportProduct diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportReportLine.java b/org.adempiere.base.process/src/org/compiere/process/ImportReportLine.java index 0bf01f1e83..f93ef38233 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportReportLine.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportReportLine.java @@ -76,181 +76,181 @@ public class ImportReportLine extends SvrProcess */ protected String doIt() throws java.lang.Exception { - StringBuffer sql = null; + StringBuilder sql = null; int no = 0; - String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID; + StringBuilder clientCheck = new StringBuilder(" AND AD_Client_ID=").append(m_AD_Client_ID); // **** Prepare **** // Delete Old Imported if (m_deleteOldImported) { - sql = new StringBuffer ("DELETE I_ReportLine " - + "WHERE I_IsImported='Y'").append(clientCheck); + sql = new StringBuilder ("DELETE I_ReportLine ") + .append("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_ReportLine " - + "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 = ' '," - + " I_IsImported = 'N' " - + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),") + .append(" AD_Org_ID = COALESCE (AD_Org_ID, 0),") + .append(" IsActive = COALESCE (IsActive, 'Y'),") + .append(" Created = COALESCE (Created, SysDate),") + .append(" CreatedBy = COALESCE (CreatedBy, 0),") + .append(" Updated = COALESCE (Updated, SysDate),") + .append(" UpdatedBy = COALESCE (UpdatedBy, 0),") + .append(" I_ErrorMsg = ' ',") + .append(" I_IsImported = 'N' ") + .append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL"); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Reset=" + no); // ReportLineSetName (Default) if (m_PA_ReportLineSet_ID != 0) { - sql = new StringBuffer ("UPDATE I_ReportLine i " - + "SET ReportLineSetName=(SELECT Name FROM PA_ReportLineSet r" - + " WHERE PA_ReportLineSet_ID=").append(m_PA_ReportLineSet_ID).append(" AND i.AD_Client_ID=r.AD_Client_ID) " - + "WHERE ReportLineSetName IS NULL AND PA_ReportLineSet_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine i ") + .append("SET ReportLineSetName=(SELECT Name FROM PA_ReportLineSet r") + .append(" WHERE PA_ReportLineSet_ID=").append(m_PA_ReportLineSet_ID).append(" AND i.AD_Client_ID=r.AD_Client_ID) ") + .append("WHERE ReportLineSetName IS NULL AND PA_ReportLineSet_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set ReportLineSetName Default=" + no); } // Set PA_ReportLineSet_ID - sql = new StringBuffer ("UPDATE I_ReportLine i " - + "SET PA_ReportLineSet_ID=(SELECT PA_ReportLineSet_ID FROM PA_ReportLineSet r" - + " WHERE i.ReportLineSetName=r.Name AND i.AD_Client_ID=r.AD_Client_ID) " - + "WHERE PA_ReportLineSet_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine i ") + .append("SET PA_ReportLineSet_ID=(SELECT PA_ReportLineSet_ID FROM PA_ReportLineSet r") + .append(" WHERE i.ReportLineSetName=r.Name AND i.AD_Client_ID=r.AD_Client_ID) ") + .append("WHERE PA_ReportLineSet_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set PA_ReportLineSet_ID=" + no); // - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ReportLineSet, ' " - + "WHERE PA_ReportLineSet_ID IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ReportLineSet, ' ") + .append("WHERE PA_ReportLineSet_ID IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid ReportLineSet=" + no); // Ignore if there is no Report Line Name or ID - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Ignored=NoLineName, ' " - + "WHERE PA_ReportLine_ID IS NULL AND Name IS NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'Ignored=NoLineName, ' ") + .append("WHERE PA_ReportLine_ID IS NULL AND Name IS NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid LineName=" + no); // Validate ElementValue - sql = new StringBuffer ("UPDATE I_ReportLine i " - + "SET C_ElementValue_ID=(SELECT C_ElementValue_ID FROM C_ElementValue e" - + " WHERE i.ElementValue=e.Value AND i.AD_Client_ID=e.AD_Client_ID) " - + "WHERE C_ElementValue_ID IS NULL AND ElementValue IS NOT NULL" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine i ") + .append("SET C_ElementValue_ID=(SELECT C_ElementValue_ID FROM C_ElementValue e") + .append(" WHERE i.ElementValue=e.Value AND i.AD_Client_ID=e.AD_Client_ID) ") + .append("WHERE C_ElementValue_ID IS NULL AND ElementValue IS NOT NULL") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set C_ElementValue_ID=" + no); // Validate C_ElementValue_ID - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ElementValue, ' " - + "WHERE C_ElementValue_ID IS NULL AND LineType<>'C'" // MReportLine.LINETYPE_Calculation - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid ElementValue, ' ") + .append("WHERE C_ElementValue_ID IS NULL AND LineType<>'C'") // MReportLine.LINETYPE_Calculation + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid AccountType=" + no); // Set SeqNo - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET SeqNo=I_ReportLine_ID " - + "WHERE SeqNo IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET SeqNo=I_ReportLine_ID ") + .append("WHERE SeqNo IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set SeqNo Default=" + no); // Copy/Sync from first Row of Line - sql = new StringBuffer ("UPDATE I_ReportLine i " - + "SET (Description, SeqNo, IsSummary, IsPrinted, LineType, CalculationType, AmountType, PAAmountType, PAPeriodType, PostingType)=" - + " (SELECT Description, SeqNo, IsSummary, IsPrinted, LineType, CalculationType, AmountType, PAAmountType, PAPeriodType, PostingType" - + " FROM I_ReportLine ii WHERE i.Name=ii.Name AND i.PA_ReportLineSet_ID=ii.PA_ReportLineSet_ID" - + " AND ii.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii" - + " WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID)) " - + "WHERE EXISTS (SELECT *" - + " FROM I_ReportLine ii WHERE i.Name=ii.Name AND i.PA_ReportLineSet_ID=ii.PA_ReportLineSet_ID" - + " AND ii.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii" - + " WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID))" - + " AND I_IsImported='N'").append(clientCheck); // not if previous error + sql = new StringBuilder ("UPDATE I_ReportLine i ") + .append("SET (Description, SeqNo, IsSummary, IsPrinted, LineType, CalculationType, AmountType, PAAmountType, PAPeriodType, PostingType)=") + .append(" (SELECT Description, SeqNo, IsSummary, IsPrinted, LineType, CalculationType, AmountType, PAAmountType, PAPeriodType, PostingType") + .append(" FROM I_ReportLine ii WHERE i.Name=ii.Name AND i.PA_ReportLineSet_ID=ii.PA_ReportLineSet_ID") + .append(" AND ii.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii") + .append(" WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID)) ") + .append("WHERE EXISTS (SELECT *") + .append(" FROM I_ReportLine ii WHERE i.Name=ii.Name AND i.PA_ReportLineSet_ID=ii.PA_ReportLineSet_ID") + .append(" AND ii.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii") + .append(" WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID))") + .append(" AND I_IsImported='N'").append(clientCheck); // not if previous error no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Sync from first Row of Line=" + no); // Validate IsSummary - (N) Y - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET IsSummary='N' " - + "WHERE IsSummary IS NULL OR IsSummary NOT IN ('Y','N')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET IsSummary='N' ") + .append("WHERE IsSummary IS NULL OR IsSummary NOT IN ('Y','N')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set IsSummary Default=" + no); // Validate IsPrinted - (Y) N - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET IsPrinted='Y' " - + "WHERE IsPrinted IS NULL OR IsPrinted NOT IN ('Y','N')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET IsPrinted='Y' ") + .append("WHERE IsPrinted IS NULL OR IsPrinted NOT IN ('Y','N')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set IsPrinted Default=" + no); // Validate Line Type - (S) C - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET LineType='S' " - + "WHERE LineType IS NULL OR LineType NOT IN ('S','C')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET LineType='S' ") + .append("WHERE LineType IS NULL OR LineType NOT IN ('S','C')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set LineType Default=" + no); // Validate Optional Calculation Type - A P R S - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CalculationType, ' " - + "WHERE CalculationType IS NOT NULL AND CalculationType NOT IN ('A','P','R','S')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CalculationType, ' ") + .append("WHERE CalculationType IS NOT NULL AND CalculationType NOT IN ('A','P','R','S')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid CalculationType=" + no); // Convert Optional Amount Type to PAAmount Type and PAPeriodType - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET PAAmountType = substr(AmountType,1,1), PAPeriodType = substr(AmountType,1,2) " - + "WHERE AmountType IS NOT NULL AND (PAAmountType IS NULL OR PAPeriodType IS NULL) " - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET PAAmountType = substr(AmountType,1,1), PAPeriodType = substr(AmountType,1,2) ") + .append("WHERE AmountType IS NOT NULL AND (PAAmountType IS NULL OR PAPeriodType IS NULL) ") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Converted AmountType=" + no); // Validate Optional Amount Type - - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid PAAmountType, ' " - + "WHERE PAAmountType IS NOT NULL AND UPPER(AmountType) NOT IN ('B','C','D','Q','S','R')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid PAAmountType, ' ") + .append("WHERE PAAmountType IS NOT NULL AND UPPER(AmountType) NOT IN ('B','C','D','Q','S','R')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid AmountType=" + no); // Validate Optional Period Type - - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid PAPeriodType, ' " - + "WHERE PAPeriodType IS NOT NULL AND UPPER(AmountType) NOT IN ('P','Y','T','N')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid PAPeriodType, ' ") + .append("WHERE PAPeriodType IS NOT NULL AND UPPER(AmountType) NOT IN ('P','Y','T','N')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid PeriodType=" + no); // Validate Optional Posting Type - A B E S R - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CalculationType, ' " - + "WHERE PostingType IS NOT NULL AND PostingType NOT IN ('A','B','E','S','R')" - + " AND I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid CalculationType, ' ") + .append("WHERE PostingType IS NOT NULL AND PostingType NOT IN ('A','B','E','S','R')") + .append(" AND I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Invalid PostingType=" + no); // Set PA_ReportLine_ID - sql = new StringBuffer ("UPDATE I_ReportLine i " - + "SET PA_ReportLine_ID=(SELECT MAX(PA_ReportLine_ID) FROM PA_ReportLine r" - + " WHERE i.Name=r.Name AND i.PA_ReportLineSet_ID=r.PA_ReportLineSet_ID) " - + "WHERE PA_ReportLine_ID IS NULL AND PA_ReportLineSet_ID IS NOT NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine i ") + .append("SET PA_ReportLine_ID=(SELECT MAX(PA_ReportLine_ID) FROM PA_ReportLine r") + .append(" WHERE i.Name=r.Name AND i.PA_ReportLineSet_ID=r.PA_ReportLineSet_ID) ") + .append("WHERE PA_ReportLine_ID IS NULL AND PA_ReportLineSet_ID IS NOT NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set PA_ReportLine_ID=" + no); @@ -261,29 +261,29 @@ public class ImportReportLine extends SvrProcess int noUpdateLine = 0; // **** Create Missing ReportLines - sql = new StringBuffer ("SELECT DISTINCT PA_ReportLineSet_ID, Name " - + "FROM I_ReportLine " - + "WHERE I_IsImported='N' AND PA_ReportLine_ID IS NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("SELECT DISTINCT PA_ReportLineSet_ID, Name ") + .append("FROM I_ReportLine ") + .append("WHERE I_IsImported='N' AND PA_ReportLine_ID IS NULL") + .append(" AND I_IsImported='N'").append(clientCheck); try { // Insert ReportLine - PreparedStatement pstmt_insertLine = DB.prepareStatement - ("INSERT INTO PA_ReportLine " - + "(PA_ReportLine_ID,PA_ReportLineSet_ID," - + "AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy," - + "Name,SeqNo,IsPrinted,IsSummary,LineType)" - + "SELECT ?,PA_ReportLineSet_ID," - + "AD_Client_ID,AD_Org_ID,'Y',SysDate,CreatedBy,SysDate,UpdatedBy," - + "Name,SeqNo,IsPrinted,IsSummary,LineType " - //jz + "FROM I_ReportLine " - // + "WHERE PA_ReportLineSet_ID=? AND Name=? AND ROWNUM=1" // #2..3 - + "FROM I_ReportLine " - + "WHERE I_ReportLine_ID=(SELECT MAX(I_ReportLine_ID) " - + "FROM I_ReportLine " - + "WHERE PA_ReportLineSet_ID=? AND Name=? " // #2..3 - //jz + clientCheck, get_TrxName()); - + clientCheck + ")", get_TrxName()); + StringBuilder dbpst = new StringBuilder("INSERT INTO PA_ReportLine ") + .append("(PA_ReportLine_ID,PA_ReportLineSet_ID,") + .append("AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,") + .append("Name,SeqNo,IsPrinted,IsSummary,LineType)") + .append("SELECT ?,PA_ReportLineSet_ID,") + .append("AD_Client_ID,AD_Org_ID,'Y',SysDate,CreatedBy,SysDate,UpdatedBy,") + .append("Name,SeqNo,IsPrinted,IsSummary,LineType ") + //jz + "FROM I_ReportLine " + // + "WHERE PA_ReportLineSet_ID=? AND Name=? AND ROWNUM=1" // #2..3 + .append("FROM I_ReportLine ") + .append("WHERE I_ReportLine_ID=(SELECT MAX(I_ReportLine_ID) ") + .append("FROM I_ReportLine ") + .append("WHERE PA_ReportLineSet_ID=? AND Name=? ") // #2..3 + //jz + clientCheck, get_TrxName()); + .append(clientCheck).append(")"); + PreparedStatement pstmt_insertLine = DB.prepareStatement(dbpst.toString(), get_TrxName()); PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); ResultSet rs = pstmt.executeQuery(); @@ -322,25 +322,25 @@ public class ImportReportLine extends SvrProcess } // Set PA_ReportLine_ID (for newly created) - sql = new StringBuffer ("UPDATE I_ReportLine i " - + "SET PA_ReportLine_ID=(SELECT MAX(PA_ReportLine_ID) FROM PA_ReportLine r" - + " WHERE i.Name=r.Name AND i.PA_ReportLineSet_ID=r.PA_ReportLineSet_ID) " - + "WHERE PA_ReportLine_ID IS NULL AND PA_ReportLineSet_ID IS NOT NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine i ") + .append("SET PA_ReportLine_ID=(SELECT MAX(PA_ReportLine_ID) FROM PA_ReportLine r") + .append(" WHERE i.Name=r.Name AND i.PA_ReportLineSet_ID=r.PA_ReportLineSet_ID) ") + .append("WHERE PA_ReportLine_ID IS NULL AND PA_ReportLineSet_ID IS NOT NULL") + .append(" AND I_IsImported='N'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("Set PA_ReportLine_ID=" + no); // **** Update ReportLine - sql = new StringBuffer ("UPDATE PA_ReportLine r " - + "SET (Description,SeqNo,IsSummary,IsPrinted,LineType,CalculationType,AmountType,PAAmountType,PAPeriodType,PostingType,Updated,UpdatedBy)=" - + " (SELECT Description,SeqNo,IsSummary,IsPrinted,LineType,CalculationType,AmountType,PAAmountType,PAPeriodType,PostingType,SysDate,UpdatedBy" - + " FROM I_ReportLine i WHERE r.Name=i.Name AND r.PA_ReportLineSet_ID=i.PA_ReportLineSet_ID" - + " AND i.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii" - + " WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID)) " - + "WHERE EXISTS (SELECT *" - + " FROM I_ReportLine i WHERE r.Name=i.Name AND r.PA_ReportLineSet_ID=i.PA_ReportLineSet_ID" - + " AND i.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii" - + " WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID AND i.I_IsImported='N'))") + sql = new StringBuilder ("UPDATE PA_ReportLine r ") + .append("SET (Description,SeqNo,IsSummary,IsPrinted,LineType,CalculationType,AmountType,PAAmountType,PAPeriodType,PostingType,Updated,UpdatedBy)=") + .append(" (SELECT Description,SeqNo,IsSummary,IsPrinted,LineType,CalculationType,AmountType,PAAmountType,PAPeriodType,PostingType,SysDate,UpdatedBy") + .append(" FROM I_ReportLine i WHERE r.Name=i.Name AND r.PA_ReportLineSet_ID=i.PA_ReportLineSet_ID") + .append(" AND i.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii") + .append(" WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID)) ") + .append("WHERE EXISTS (SELECT *") + .append(" FROM I_ReportLine i WHERE r.Name=i.Name AND r.PA_ReportLineSet_ID=i.PA_ReportLineSet_ID") + .append(" AND i.I_ReportLine_ID=(SELECT MIN(I_ReportLine_ID) FROM I_ReportLine iii") + .append(" WHERE i.Name=iii.Name AND i.PA_ReportLineSet_ID=iii.PA_ReportLineSet_ID AND i.I_IsImported='N'))") .append(clientCheck); noUpdateLine = DB.executeUpdate(sql.toString(), get_TrxName()); log.config("Update PA_ReportLine=" + noUpdateLine); @@ -351,26 +351,26 @@ public class ImportReportLine extends SvrProcess int noUpdateSource = 0; // **** Create ReportSource - sql = new StringBuffer ("SELECT I_ReportLine_ID, PA_ReportSource_ID " - + "FROM I_ReportLine " - + "WHERE PA_ReportLine_ID IS NOT NULL" - + " AND I_IsImported='N'").append(clientCheck); + sql = new StringBuilder ("SELECT I_ReportLine_ID, PA_ReportSource_ID ") + .append("FROM I_ReportLine ") + .append("WHERE PA_ReportLine_ID IS NOT NULL") + .append(" AND I_IsImported='N'").append(clientCheck); try { // Insert ReportSource - PreparedStatement pstmt_insertSource = DB.prepareStatement - ("INSERT INTO PA_ReportSource " - + "(PA_ReportSource_ID," - + "AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy," - + "PA_ReportLine_ID,ElementType,C_ElementValue_ID) " - + "SELECT ?," - + "AD_Client_ID,AD_Org_ID,'Y',SysDate,CreatedBy,SysDate,UpdatedBy," - + "PA_ReportLine_ID,'AC',C_ElementValue_ID " - + "FROM I_ReportLine " - + "WHERE I_ReportLine_ID=?" - + " AND I_IsImported='N'" - + clientCheck, get_TrxName()); + StringBuilder dbpst = new StringBuilder("INSERT INTO PA_ReportSource ") + .append("(PA_ReportSource_ID,") + .append("AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,") + .append("PA_ReportLine_ID,ElementType,C_ElementValue_ID) ") + .append("SELECT ?,") + .append("AD_Client_ID,AD_Org_ID,'Y',SysDate,CreatedBy,SysDate,UpdatedBy,") + .append("PA_ReportLine_ID,'AC',C_ElementValue_ID ") + .append("FROM I_ReportLine ") + .append("WHERE I_ReportLine_ID=?") + .append(" AND I_IsImported='N'") + .append(clientCheck); + PreparedStatement pstmt_insertSource = DB.prepareStatement(dbpst.toString(), get_TrxName()); // Update ReportSource //jz @@ -387,11 +387,11 @@ public class ImportReportLine extends SvrProcess */ // Delete ReportSource - afalcone 22/02/2007 - F.R. [ 1642250 ] Import ReportLine / Very Slow Reports - PreparedStatement pstmt_deleteSource = DB.prepareStatement - ("DELETE FROM PA_ReportSource " - + "WHERE C_ElementValue_ID IS NULL" - + " AND PA_ReportSource_ID=?" - + clientCheck, get_TrxName()); + dbpst = new StringBuilder("DELETE FROM PA_ReportSource ") + .append("WHERE C_ElementValue_ID IS NULL") + .append(" AND PA_ReportSource_ID=?") + .append(clientCheck); + PreparedStatement pstmt_deleteSource = DB.prepareStatement(dbpst.toString(), get_TrxName()); //End afalcone 22/02/2007 - F.R. [ 1642250 ] Import ReportLine / Very Slow Reports // Set Imported = Y @@ -424,8 +424,8 @@ public class ImportReportLine extends SvrProcess catch (Exception ex) { log.finest("Insert ReportSource - " + ex.toString()); - sql = new StringBuffer ("UPDATE I_ReportLine i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert ElementSource: " + ex.toString())) + sql = new StringBuilder ("UPDATE I_ReportLine i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert ElementSource: " + ex.toString())) .append("WHERE I_ReportLine_ID=").append(I_ReportLine_ID); DB.executeUpdate(sql.toString(), get_TrxName()); continue; @@ -434,15 +434,15 @@ public class ImportReportLine extends SvrProcess else // update Report Source { //jz - String sqlt="UPDATE PA_ReportSource " - + "SET (ElementType,C_ElementValue_ID,Updated,UpdatedBy)=" - + " (SELECT CAST('AC' AS CHAR(2)),C_ElementValue_ID,SysDate,UpdatedBy" //jz - + " FROM I_ReportLine" - + " WHERE I_ReportLine_ID=" + I_ReportLine_ID + ") " - + "WHERE PA_ReportSource_ID="+PA_ReportSource_ID+" " - + clientCheck; + StringBuilder sqlt= new StringBuilder("UPDATE PA_ReportSource ") + .append("SET (ElementType,C_ElementValue_ID,Updated,UpdatedBy)=") + .append(" (SELECT CAST('AC' AS CHAR(2)),C_ElementValue_ID,SysDate,UpdatedBy") //jz + .append(" FROM I_ReportLine") + .append(" WHERE I_ReportLine_ID=").append(I_ReportLine_ID).append(") ") + .append("WHERE PA_ReportSource_ID=").append(PA_ReportSource_ID).append(" ") + .append(clientCheck); PreparedStatement pstmt_updateSource = DB.prepareStatement - (sqlt, get_TrxName()); + (sqlt.toString(), get_TrxName()); //pstmt_updateSource.setInt(1, I_ReportLine_ID); //pstmt_updateSource.setInt(2, PA_ReportSource_ID); try @@ -455,8 +455,8 @@ public class ImportReportLine extends SvrProcess catch (SQLException ex) { log.finest( "Update ReportSource - " + ex.toString()); - sql = new StringBuffer ("UPDATE I_ReportLine i " - + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Update ElementSource: " + ex.toString())) + sql = new StringBuilder ("UPDATE I_ReportLine i ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Update ElementSource: " + ex.toString())) .append("WHERE I_ReportLine_ID=").append(I_ReportLine_ID); DB.executeUpdate(sql.toString(), get_TrxName()); continue; @@ -494,9 +494,9 @@ public class ImportReportLine extends SvrProcess } // Set Error to indicator to not imported - sql = new StringBuffer ("UPDATE I_ReportLine " - + "SET I_IsImported='N', Updated=SysDate " - + "WHERE I_IsImported<>'Y'").append(clientCheck); + sql = new StringBuilder ("UPDATE I_ReportLine ") + .append("SET I_IsImported='N', Updated=SysDate ") + .append("WHERE I_IsImported<>'Y'").append(clientCheck); no = DB.executeUpdate(sql.toString(), get_TrxName()); addLog (0, null, new BigDecimal (no), "@Errors@"); diff --git a/org.adempiere.base.process/src/org/compiere/process/InOutGenerate.java b/org.adempiere.base.process/src/org/compiere/process/InOutGenerate.java index baa436e83b..f12c5b4fb8 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InOutGenerate.java +++ b/org.adempiere.base.process/src/org/compiere/process/InOutGenerate.java @@ -74,7 +74,7 @@ public class InOutGenerate extends SvrProcess private int m_lastC_BPartner_Location_ID = -1; /** The Query sql */ - private String m_sql = null; + private StringBuffer m_sql = null; /** Storages temp space */ @@ -147,38 +147,38 @@ public class InOutGenerate extends SvrProcess if (p_Selection) // VInOutGen { - m_sql = "SELECT C_Order.* FROM C_Order, T_Selection " - + "WHERE C_Order.DocStatus='CO' AND C_Order.IsSOTrx='Y' AND C_Order.AD_Client_ID=? " - + "AND C_Order.C_Order_ID = T_Selection.T_Selection_ID " - + "AND T_Selection.AD_PInstance_ID=? "; + m_sql = new StringBuffer("SELECT C_Order.* FROM C_Order, T_Selection ") + .append("WHERE C_Order.DocStatus='CO' AND C_Order.IsSOTrx='Y' AND C_Order.AD_Client_ID=? ") + .append("AND C_Order.C_Order_ID = T_Selection.T_Selection_ID ") + .append("AND T_Selection.AD_PInstance_ID=? "); } else { - m_sql = "SELECT * FROM C_Order o " - + "WHERE DocStatus='CO' AND IsSOTrx='Y'" + m_sql = new StringBuffer("SELECT * FROM C_Order o ") + .append("WHERE DocStatus='CO' AND IsSOTrx='Y'") // No Offer,POS - + " AND o.C_DocType_ID IN (SELECT C_DocType_ID FROM C_DocType " - + "WHERE DocBaseType='SOO' AND DocSubTypeSO NOT IN ('ON','OB','WR'))" - + " AND o.IsDropShip='N'" + .append(" AND o.C_DocType_ID IN (SELECT C_DocType_ID FROM C_DocType ") + .append("WHERE DocBaseType='SOO' AND DocSubTypeSO NOT IN ('ON','OB','WR'))") + .append(" AND o.IsDropShip='N'") // No Manual - + " AND o.DeliveryRule<>'M'" + .append(" AND o.DeliveryRule<>'M'") // Open Order Lines with Warehouse - + " AND EXISTS (SELECT * FROM C_OrderLine ol " - + "WHERE ol.M_Warehouse_ID=?"; // #1 + .append(" AND EXISTS (SELECT * FROM C_OrderLine ol ") + .append("WHERE ol.M_Warehouse_ID=?"); // #1 if (p_DatePromised != null) - m_sql += " AND TRUNC(ol.DatePromised)<=?"; // #2 - m_sql += " AND o.C_Order_ID=ol.C_Order_ID AND ol.QtyOrdered<>ol.QtyDelivered)"; + m_sql.append(" AND TRUNC(ol.DatePromised)<=?"); // #2 + m_sql.append(" AND o.C_Order_ID=ol.C_Order_ID AND ol.QtyOrdered<>ol.QtyDelivered)"); // if (p_C_BPartner_ID != 0) - m_sql += " AND o.C_BPartner_ID=?"; // #3 + m_sql.append(" AND o.C_BPartner_ID=?"); // #3 } - m_sql += " ORDER BY M_Warehouse_ID, PriorityRule, M_Shipper_ID, C_BPartner_ID, C_BPartner_Location_ID, C_Order_ID"; + m_sql.append(" ORDER BY M_Warehouse_ID, PriorityRule, M_Shipper_ID, C_BPartner_ID, C_BPartner_Location_ID, C_Order_ID"); // m_sql += " FOR UPDATE"; PreparedStatement pstmt = null; try { - pstmt = DB.prepareStatement (m_sql, get_TrxName()); + pstmt = DB.prepareStatement (m_sql.toString(), get_TrxName()); int index = 1; if (p_Selection) { @@ -196,7 +196,7 @@ public class InOutGenerate extends SvrProcess } catch (Exception e) { - log.log(Level.SEVERE, m_sql, e); + log.log(Level.SEVERE, m_sql.toString(), e); } return generate(pstmt); } // doIt @@ -228,23 +228,23 @@ public class InOutGenerate extends SvrProcess Timestamp minGuaranteeDate = m_movementDate; boolean completeOrder = MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule()); // OrderLine WHERE - String where = " AND M_Warehouse_ID=" + p_M_Warehouse_ID; + StringBuilder where = new StringBuilder(" AND M_Warehouse_ID=").append(p_M_Warehouse_ID); if (p_DatePromised != null) - where += " AND (TRUNC(DatePromised)<=" + DB.TO_DATE(p_DatePromised, true) - + " OR DatePromised IS NULL)"; + where.append(" AND (TRUNC(DatePromised)<=").append(DB.TO_DATE(p_DatePromised, true)) + .append(" OR DatePromised IS NULL)"); // Exclude Auto Delivery if not Force if (!MOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) - where += " AND (C_OrderLine.M_Product_ID IS NULL" - + " OR EXISTS (SELECT * FROM M_Product p " - + "WHERE C_OrderLine.M_Product_ID=p.M_Product_ID" - + " AND IsExcludeAutoDelivery='N'))"; + where.append(" AND (C_OrderLine.M_Product_ID IS NULL") + .append(" OR EXISTS (SELECT * FROM M_Product p ") + .append("WHERE C_OrderLine.M_Product_ID=p.M_Product_ID") + .append(" AND IsExcludeAutoDelivery='N'))"); // Exclude Unconfirmed if (!p_IsUnconfirmedInOut) - where += " AND NOT EXISTS (SELECT * FROM M_InOutLine iol" - + " INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID) " - + "WHERE iol.C_OrderLine_ID=C_OrderLine.C_OrderLine_ID AND io.DocStatus IN ('IP','WC'))"; + where.append(" AND NOT EXISTS (SELECT * FROM M_InOutLine iol") + .append(" INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID) ") + .append("WHERE iol.C_OrderLine_ID=C_OrderLine.C_OrderLine_ID AND io.DocStatus IN ('IP','WC'))"); // Deadlock Prevention - Order by M_Product_ID - MOrderLine[] lines = order.getLines (where, "C_BPartner_Location_ID, M_Product_ID"); + MOrderLine[] lines = order.getLines (where.toString(), "C_BPartner_Location_ID, M_Product_ID"); for (int i = 0; i < lines.length; i++) { MOrderLine line = lines[i]; @@ -272,18 +272,18 @@ public class InOutGenerate extends SvrProcess line.getC_OrderLine_ID(), where2, null); for (int j = 0; j < iols.length; j++) unconfirmedShippedQty = unconfirmedShippedQty.add(iols[j].getMovementQty()); - String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty - + " - ToDeliver=" + toDeliver + "->"; + StringBuilder logInfo = new StringBuilder("Unconfirmed Qty=").append(unconfirmedShippedQty) + .append(" - ToDeliver=").append(toDeliver).append("->"); toDeliver = toDeliver.subtract(unconfirmedShippedQty); - logInfo += toDeliver; + logInfo.append(toDeliver); if (toDeliver.signum() < 0) { toDeliver = Env.ZERO; - logInfo += " (set to 0)"; + logInfo.append(" (set to 0)"); } // Adjust On Hand onHand = onHand.subtract(unconfirmedShippedQty); - log.fine(logInfo); + log.fine(logInfo.toString()); } // Comments & lines w/o product & services @@ -397,7 +397,7 @@ public class InOutGenerate extends SvrProcess } catch (Exception e) { - log.log(Level.SEVERE, m_sql, e); + log.log(Level.SEVERE, m_sql.toString(), e); } try { @@ -410,7 +410,8 @@ public class InOutGenerate extends SvrProcess pstmt = null; } completeShipment(); - return "@Created@ = " + m_created; + StringBuilder msgreturn = new StringBuilder("@Created@ = ").append(m_created); + return msgreturn.toString(); } // generate diff --git a/org.adempiere.base.process/src/org/compiere/process/InventoryCountCreate.java b/org.adempiere.base.process/src/org/compiere/process/InventoryCountCreate.java index 71f55f9c6e..8a6e836b7a 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InventoryCountCreate.java +++ b/org.adempiere.base.process/src/org/compiere/process/InventoryCountCreate.java @@ -119,16 +119,16 @@ public class InventoryCountCreate extends SvrProcess if (p_DeleteOld) { //Added Line by armen - String sql1 = "DELETE FROM M_InventoryLineMA ma WHERE EXISTS " - + "(SELECT * FROM M_InventoryLine l WHERE l.M_InventoryLine_ID=ma.M_InventoryLine_ID" - + " AND Processed='N' AND M_Inventory_ID=" + p_M_Inventory_ID + ")"; - int no1 = DB.executeUpdate(sql1, get_TrxName()); + StringBuilder sql1 = new StringBuilder("DELETE FROM M_InventoryLineMA ma WHERE EXISTS ") + .append("(SELECT * FROM M_InventoryLine l WHERE l.M_InventoryLine_ID=ma.M_InventoryLine_ID") + .append(" AND Processed='N' AND M_Inventory_ID=").append(p_M_Inventory_ID).append(")"); + int no1 = DB.executeUpdate(sql1.toString(), get_TrxName()); log.fine("doIt - Deleted MA #" + no1); //End of Added Line - String sql = "DELETE M_InventoryLine WHERE Processed='N' " - + "AND M_Inventory_ID=" + p_M_Inventory_ID; - int no = DB.executeUpdate(sql, get_TrxName()); + StringBuilder sql = new StringBuilder("DELETE M_InventoryLine WHERE Processed='N' ") + .append("AND M_Inventory_ID=").append(p_M_Inventory_ID); + int no = DB.executeUpdate(sql.toString(), get_TrxName()); log.fine("doIt - Deleted #" + no); } @@ -257,15 +257,16 @@ public class InventoryCountCreate extends SvrProcess // Set Count to Zero if (p_InventoryCountSetZero) { - String sql1 = "UPDATE M_InventoryLine l " - + "SET QtyCount=0 " - + "WHERE M_Inventory_ID=" + p_M_Inventory_ID; - int no = DB.executeUpdate(sql1, get_TrxName()); + StringBuilder sql1 = new StringBuilder("UPDATE M_InventoryLine l ") + .append("SET QtyCount=0 ") + .append("WHERE M_Inventory_ID=").append(p_M_Inventory_ID); + int no = DB.executeUpdate(sql1.toString(), get_TrxName()); log.info("Set Cont to Zero=" + no); } // - return "@M_InventoryLine_ID@ - #" + count; + StringBuilder msgreturn = new StringBuilder("@M_InventoryLine_ID@ - #").append(count); + return msgreturn.toString(); } // doIt /** @@ -350,7 +351,7 @@ public class InventoryCountCreate extends SvrProcess private String getSubCategoryWhereClause(int productCategoryId) throws SQLException, AdempiereSystemError{ //if a node with this id is found later in the search we have a loop in the tree int subTreeRootParentId = 0; - String retString = " "; + StringBuilder retString = new StringBuilder(); String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category"; final Vector categories = new Vector(100); Statement stmt = DB.createStatement(); @@ -361,10 +362,10 @@ public class InventoryCountCreate extends SvrProcess } categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2))); } - retString += getSubCategoriesString(productCategoryId, categories, subTreeRootParentId); + retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId)); rs.close(); stmt.close(); - return retString; + return retString.toString(); } /** @@ -389,7 +390,8 @@ public class InventoryCountCreate extends SvrProcess } } log.fine(ret.toString()); - return ret.toString() + productCategoryId; + StringBuilder msgreturn = new StringBuilder(ret).append(productCategoryId); + return msgreturn.toString(); } /** diff --git a/org.adempiere.base.process/src/org/compiere/process/InventoryCountUpdate.java b/org.adempiere.base.process/src/org/compiere/process/InventoryCountUpdate.java index 336d922967..eb5a51f68a 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InventoryCountUpdate.java +++ b/org.adempiere.base.process/src/org/compiere/process/InventoryCountUpdate.java @@ -75,34 +75,34 @@ public class InventoryCountUpdate extends SvrProcess throw new AdempiereSystemError ("Not found: M_Inventory_ID=" + p_M_Inventory_ID); // Multiple Lines for one item - String sql = "UPDATE M_InventoryLine SET IsActive='N' " - + "WHERE M_Inventory_ID=" + p_M_Inventory_ID - + " AND (M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID) IN " - + "(SELECT M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID " - + "FROM M_InventoryLine " - + "WHERE M_Inventory_ID=" + p_M_Inventory_ID - + " GROUP BY M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID " - + "HAVING COUNT(*) > 1)"; - int multiple = DB.executeUpdate(sql, get_TrxName()); + StringBuilder sql = new StringBuilder("UPDATE M_InventoryLine SET IsActive='N' ") + .append("WHERE M_Inventory_ID=").append(p_M_Inventory_ID) + .append(" AND (M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID) IN ") + .append("(SELECT M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID ") + .append("FROM M_InventoryLine ") + .append("WHERE M_Inventory_ID=").append(p_M_Inventory_ID) + .append(" GROUP BY M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID ") + .append("HAVING COUNT(*) > 1)"); + int multiple = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Multiple=" + multiple); int delMA = MInventoryLineMA.deleteInventoryMA(p_M_Inventory_ID, get_TrxName()); log.info("DeletedMA=" + delMA); // ASI - sql = "UPDATE M_InventoryLine l " - + "SET (QtyBook,QtyCount) = " - + "(SELECT QtyOnHand,QtyOnHand FROM M_Storage s " - + "WHERE s.M_Product_ID=l.M_Product_ID AND s.M_Locator_ID=l.M_Locator_ID" - + " AND s.M_AttributeSetInstance_ID=l.M_AttributeSetInstance_ID)," - + " Updated=SysDate," - + " UpdatedBy=" + getAD_User_ID() + sql = new StringBuilder("UPDATE M_InventoryLine l ") + .append("SET (QtyBook,QtyCount) = ") + .append("(SELECT QtyOnHand,QtyOnHand FROM M_Storage s ") + .append("WHERE s.M_Product_ID=l.M_Product_ID AND s.M_Locator_ID=l.M_Locator_ID") + .append(" AND s.M_AttributeSetInstance_ID=l.M_AttributeSetInstance_ID),") + .append(" Updated=SysDate,") + .append(" UpdatedBy=").append(getAD_User_ID()) // - + " WHERE M_Inventory_ID=" + p_M_Inventory_ID - + " AND EXISTS (SELECT * FROM M_Storage s " - + "WHERE s.M_Product_ID=l.M_Product_ID AND s.M_Locator_ID=l.M_Locator_ID" - + " AND s.M_AttributeSetInstance_ID=l.M_AttributeSetInstance_ID)"; - int no = DB.executeUpdate(sql, get_TrxName()); + .append(" WHERE M_Inventory_ID=").append(p_M_Inventory_ID) + .append(" AND EXISTS (SELECT * FROM M_Storage s ") + .append("WHERE s.M_Product_ID=l.M_Product_ID AND s.M_Locator_ID=l.M_Locator_ID") + .append(" AND s.M_AttributeSetInstance_ID=l.M_AttributeSetInstance_ID)"); + int no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Update with ASI=" + no); // No ASI @@ -111,17 +111,19 @@ public class InventoryCountUpdate extends SvrProcess // Set Count to Zero if (p_InventoryCountSetZero) { - sql = "UPDATE M_InventoryLine l " - + "SET QtyCount=0 " - + "WHERE M_Inventory_ID=" + p_M_Inventory_ID; - no = DB.executeUpdate(sql, get_TrxName()); + sql = new StringBuilder("UPDATE M_InventoryLine l ") + .append("SET QtyCount=0 ") + .append("WHERE M_Inventory_ID=").append(p_M_Inventory_ID); + no = DB.executeUpdate(sql.toString(), get_TrxName()); log.info("Set Count to Zero=" + no); } - if (multiple > 0) - return "@M_InventoryLine_ID@ - #" + (no + noMA) + " --> @InventoryProductMultiple@"; - - return "@M_InventoryLine_ID@ - #" + no; + if (multiple > 0){ + StringBuilder msgreturn = new StringBuilder("@M_InventoryLine_ID@ - #").append((no + noMA)).append(" --> @InventoryProductMultiple@"); + return msgreturn.toString(); + } + StringBuilder msgreturn = new StringBuilder("@M_InventoryLine_ID@ - #").append(no); + return msgreturn.toString(); } // doIt /**