From 9de87fea93aad23c84e8f9627be0ab051f25ec95 Mon Sep 17 00:00:00 2001 From: monhate Date: Sat, 26 Mar 2011 01:20:18 -0500 Subject: [PATCH] FR [3067850] - Bug coping details from other Project http://sourceforge.net/support/tracker.php?aid=3067850 --- .../src/org/compiere/model/MProject.java | 32 +++++++--- .../src/org/compiere/model/MProjectPhase.java | 60 +++++++++++++++++-- .../src/org/compiere/model/MProjectTask.java | 58 +++++++++++++++++- 3 files changed, 138 insertions(+), 12 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MProject.java b/org.adempiere.base/src/org/compiere/model/MProject.java index 984dfe4ed5..d2c44f745f 100644 --- a/org.adempiere.base/src/org/compiere/model/MProject.java +++ b/org.adempiere.base/src/org/compiere/model/MProject.java @@ -33,11 +33,10 @@ import org.compiere.util.Env; */ public class MProject extends X_C_Project { - - /** - * - */ - private static final long serialVersionUID = -1781787100948563589L; + /** + * + */ + private static final long serialVersionUID = 2151648902207548617L; /** * Create new Project by copying @@ -279,6 +278,10 @@ public class MProject extends X_C_Project MProjectLine[] fromLines = project.getLines(); for (int i = 0; i < fromLines.length; i++) { + //BF 3067850 - monhate + if((fromLines[i].getC_ProjectPhase_ID() != 0)|| + (fromLines[i].getC_ProjectTask_ID() != 0)) continue; + MProjectLine line = new MProjectLine (getCtx(), 0, project.get_TrxName()); PO.copyValues(fromLines[i], line, getAD_Client_ID(), getAD_Org_ID()); line.setC_Project_ID(getC_Project_ID()); @@ -306,7 +309,7 @@ public class MProject extends X_C_Project if (isProcessed() || fromProject == null) return 0; int count = 0; - int taskCount = 0; + int taskCount = 0, lineCount = 0; // Get Phases MProjectPhase[] myPhases = getPhases(); MProjectPhase[] fromPhases = fromProject.getPhases(); @@ -343,13 +346,15 @@ public class MProject extends X_C_Project { count++; taskCount += toPhase.copyTasksFrom (fromPhases[i]); + //BF 3067850 - monhate + lineCount += toPhase.copyLinesFrom(fromPhases[i]); } } } if (fromPhases.length != count) log.warning("Count difference - Project=" + fromPhases.length + " <> Saved=" + count); - return count + taskCount; + return count + taskCount + lineCount; } // copyPhasesFrom @@ -458,5 +463,18 @@ public class MProject extends X_C_Project delete_Tree(MTree_Base.TREETYPE_Project); return success; } // afterDelete + + /** + * Return the Invoices Generated for this Project + * @return invoices + * @author monhate + */ + public MInvoice[] getMInvoices(){ + StringBuilder sb = new StringBuilder(); + sb.append(MInvoice.COLUMNNAME_C_Project_ID).append("=?"); + Query qry = new Query(getCtx(), MInvoice.Table_Name, sb.toString(), get_TrxName()); + qry.setParameters(getC_Project_ID()); + return (MInvoice[]) qry.list().toArray(); + } } // MProject diff --git a/org.adempiere.base/src/org/compiere/model/MProjectPhase.java b/org.adempiere.base/src/org/compiere/model/MProjectPhase.java index c007b615f5..af02ba0bd4 100644 --- a/org.adempiere.base/src/org/compiere/model/MProjectPhase.java +++ b/org.adempiere.base/src/org/compiere/model/MProjectPhase.java @@ -20,6 +20,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.List; import java.util.Properties; import java.util.logging.Level; @@ -37,7 +38,7 @@ public class MProjectPhase extends X_C_ProjectPhase /** * */ - private static final long serialVersionUID = 3445836323245259566L; + private static final long serialVersionUID = 5824045445920353065L; /** * Standard Constructor @@ -142,9 +143,40 @@ public class MProjectPhase extends X_C_ProjectPhase return retValue; } // getTasks + /** + * Copy Lines from other Phase + * BF 3067850 - monhate + * @param fromPhase from phase + * @return number of tasks copied + */ + public int copyLinesFrom (MProjectPhase fromPhase) + { + if (fromPhase == null) + return 0; + int count = 0; + // + MProjectLine[] fromLines = fromPhase.getLines(); + // Copy Project Lines + for (int i = 0; i < fromLines.length; i++) + { + if(fromLines[i].getC_ProjectTask_ID() != 0) continue; + MProjectLine toLine = new MProjectLine(getCtx (), 0, get_TrxName()); + PO.copyValues (fromLines[i], toLine, getAD_Client_ID (), getAD_Org_ID ()); + toLine.setC_Project_ID(getC_Project_ID ()); + toLine.setC_ProjectPhase_ID (getC_ProjectPhase_ID ()); + if (toLine.save ()) + count++; + } + if (fromLines.length != count) + log.warning("Count difference - ProjectLine=" + fromLines.length + " <> Saved=" + count); + return count; + } + + /** * Copy Tasks from other Phase + * BF 3067850 - monhate * @param fromPhase from phase * @return number of tasks copied */ @@ -152,7 +184,7 @@ public class MProjectPhase extends X_C_ProjectPhase { if (fromPhase == null) return 0; - int count = 0; + int count = 0, countLine = 0; // MProjectTask[] myTasks = getTasks(); MProjectTask[] fromTasks = fromPhase.getTasks(); @@ -183,14 +215,17 @@ public class MProjectPhase extends X_C_ProjectPhase MProjectTask toTask = new MProjectTask (getCtx (), 0, get_TrxName()); PO.copyValues (fromTasks[i], toTask, getAD_Client_ID (), getAD_Org_ID ()); toTask.setC_ProjectPhase_ID (getC_ProjectPhase_ID ()); - if (toTask.save ()) + if (toTask.save ()){ count++; + //BF 3067850 - monhate + countLine += toTask.copyLinesFrom(fromTasks[i]); + } } } if (fromTasks.length != count) log.warning("Count difference - ProjectPhase=" + fromTasks.length + " <> Saved=" + count); - return count; + return count + countLine; } // copyTasksFrom /** @@ -217,6 +252,23 @@ public class MProjectPhase extends X_C_ProjectPhase return count; } // copyTasksFrom + + /************************************************************************** + * Get Project Lines + * BF 3067850 - monhate + * @return Array of lines + */ public MProjectLine[] getLines() + { + final String whereClause = "C_Project_ID=? and C_ProjectPhase_ID=?"; + List list = new Query(getCtx(), I_C_ProjectLine.Table_Name, whereClause, get_TrxName()) + .setParameters(getC_Project_ID(), getC_ProjectPhase_ID()) + .setOrderBy("Line") + .list(); + // + MProjectLine[] retValue = new MProjectLine[list.size()]; + list.toArray(retValue); + return retValue; + } /** * String Representation diff --git a/org.adempiere.base/src/org/compiere/model/MProjectTask.java b/org.adempiere.base/src/org/compiere/model/MProjectTask.java index 4245a6c38b..07463f44e7 100644 --- a/org.adempiere.base/src/org/compiere/model/MProjectTask.java +++ b/org.adempiere.base/src/org/compiere/model/MProjectTask.java @@ -17,6 +17,7 @@ package org.compiere.model; import java.sql.ResultSet; +import java.util.List; import java.util.Properties; import org.compiere.util.Env; @@ -32,7 +33,7 @@ public class MProjectTask extends X_C_ProjectTask /** * */ - private static final long serialVersionUID = -4031011454351572357L; + private static final long serialVersionUID = 6714520156233475723L; /** * Standard Constructor @@ -94,6 +95,61 @@ public class MProjectTask extends X_C_ProjectTask setM_Product_ID(task.getM_Product_ID()); setQty(task.getStandardQty()); } // MProjectTask + + /************************************************************************** + * Get Project Lines + * BF 3067850 - monhate + * @return Array of lines + */ public MProjectLine[] getLines() + { + final String whereClause = "C_ProjectPhase_ID=? and C_ProjectTask_ID=? "; + List list = new Query(getCtx(), I_C_ProjectLine.Table_Name, whereClause, get_TrxName()) + .setParameters(getC_ProjectPhase_ID(), getC_ProjectTask_ID()) + .setOrderBy("Line") + .list(); + // + MProjectLine[] retValue = new MProjectLine[list.size()]; + list.toArray(retValue); + return retValue; + } + + /** + * Copy Lines from other Task + * BF 3067850 - monhate + * @param fromTask from Task + * @return number of lines copied + */ + public int copyLinesFrom (MProjectTask fromTask) + { + if (fromTask == null) + return 0; + int count = 0; + // + MProjectLine[] fromLines = fromTask.getLines(); + // Copy Project Lines + for (int i = 0; i < fromLines.length; i++) + { + MProjectLine toLine = new MProjectLine(getCtx (), 0, get_TrxName()); + PO.copyValues (fromLines[i], toLine, getAD_Client_ID (), getAD_Org_ID ()); + toLine.setC_Project_ID(getC_Project_ID(false)); + toLine.setC_ProjectPhase_ID (getC_ProjectPhase_ID ()); + toLine.setC_ProjectTask_ID(getC_ProjectTask_ID ()); + if (toLine.save ()) + count++; + } + if (fromLines.length != count) + log.warning("Count difference - ProjectLine=" + fromLines.length + " <> Saved=" + count); + + return count; + } + + private int C_Project_ID = 0; + + private int getC_Project_ID(boolean reQuery) { + if (C_Project_ID==0 || reQuery) + C_Project_ID = getC_ProjectPhase().getC_Project_ID(); + return C_Project_ID; + } /** * String Representation