From da13e387799b0c194de9e49a2512825fa662654d Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Thu, 5 Feb 2009 16:56:45 +0000 Subject: [PATCH] adempiere: cleanup libero Lot more work to do. Any help is appreciated. --- base/src/org/eevolution/process/CRP.java | 358 ----- .../org/eevolution/process/CRPSummary.java | 599 -------- .../eevolution/process/CalculateLowLevel.java | 72 - .../process/CopyPriceToStandard.java | 156 -- .../eevolution/process/CreateCostElement.java | 196 --- .../org/eevolution/process/CreateDocType.java | 162 --- .../process/CreateProductPlanning.java | 263 ---- .../process/HRAttributeEmployee.java | 46 - .../eevolution/process/HRCreateConcept.java | 70 - .../eevolution/process/HRCreatePeriods.java | 62 - .../src/org/eevolution/process/LoadRoles.java | 116 -- base/src/org/eevolution/process/MRP.java | 1273 ----------------- .../src/org/eevolution/process/MRPUpdate.java | 371 ----- .../eevolution/process/PayrollViaEMail.java | 280 ---- .../process/RollupBillOfMaterial.java | 219 --- .../eevolution/process/RollupWorkflow.java | 210 --- .../eevolution/report/CostBillOfMaterial.java | 255 ---- .../process/CompletePrintOrder.java | 161 --- 18 files changed, 4869 deletions(-) delete mode 100644 base/src/org/eevolution/process/CRP.java delete mode 100644 base/src/org/eevolution/process/CRPSummary.java delete mode 100644 base/src/org/eevolution/process/CalculateLowLevel.java delete mode 100644 base/src/org/eevolution/process/CopyPriceToStandard.java delete mode 100644 base/src/org/eevolution/process/CreateCostElement.java delete mode 100644 base/src/org/eevolution/process/CreateDocType.java delete mode 100644 base/src/org/eevolution/process/CreateProductPlanning.java delete mode 100644 base/src/org/eevolution/process/HRAttributeEmployee.java delete mode 100644 base/src/org/eevolution/process/HRCreateConcept.java delete mode 100644 base/src/org/eevolution/process/HRCreatePeriods.java delete mode 100644 base/src/org/eevolution/process/LoadRoles.java delete mode 100644 base/src/org/eevolution/process/MRP.java delete mode 100644 base/src/org/eevolution/process/MRPUpdate.java delete mode 100644 base/src/org/eevolution/process/PayrollViaEMail.java delete mode 100644 base/src/org/eevolution/process/RollupBillOfMaterial.java delete mode 100644 base/src/org/eevolution/process/RollupWorkflow.java delete mode 100644 base/src/org/eevolution/report/CostBillOfMaterial.java delete mode 100644 client/src/org/eevolution/process/CompletePrintOrder.java diff --git a/base/src/org/eevolution/process/CRP.java b/base/src/org/eevolution/process/CRP.java deleted file mode 100644 index 57480f31a8..0000000000 --- a/base/src/org/eevolution/process/CRP.java +++ /dev/null @@ -1,358 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ - -package org.eevolution.process; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.logging.Level; - -import org.adempiere.exceptions.AdempiereException; -import org.compiere.model.MResource; -import org.compiere.model.MResourceType; -import org.compiere.model.MSysConfig; -import org.compiere.model.POResultSet; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; -import org.compiere.util.TimeUtil; -import org.eevolution.model.MPPOrder; -import org.eevolution.model.MPPOrderNode; -import org.eevolution.model.MPPOrderWorkflow; -import org.eevolution.model.reasoner.CRPReasoner; - -/** - * Capacity Requirement Planning - * - * @author Gunther Hoppe, tranSIT GmbH Ilmenau/Germany (Original by Victor Perez, e-Evolution, S.C.) - * @version 1.0, October 14th 2005 - * - * @author Teo Sarca, www.arhipac.ro - */ -public class CRP extends SvrProcess -{ - public static final String FORWARD_SCHEDULING = "F"; - public static final String BACKWARD_SCHEDULING = "B"; - - private int p_S_Resource_ID; - private String p_ScheduleType; - - /** SysConfig parameter - maximum number of algorithm iterations */ - private int p_MaxIterationsNo = -1; - public static final String SYSCONFIG_MaxIterationsNo = "CRP.MaxIterationsNo"; - public static final int DEFAULT_MaxIterationsNo = 1000; - - /** CRP Reasoner */ - private CRPReasoner reasoner; - - protected void prepare() - { - for (ProcessInfoParameter para : getParameter()) - { - String name = para.getParameterName(); - if (para.getParameter() == null) - ; - if (name.equals("S_Resource_ID")) { - p_S_Resource_ID = para.getParameterAsInt(); - } - else if (name.equals("ScheduleType")) { - p_ScheduleType = (String)para.getParameter(); - } - else { - log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name); - } - } - // - p_MaxIterationsNo = MSysConfig.getIntValue(SYSCONFIG_MaxIterationsNo, DEFAULT_MaxIterationsNo, getAD_Client_ID()); - } - - protected String doIt() throws Exception - { - reasoner = new CRPReasoner(); - return runCRP(); - } - - private String runCRP() - { - POResultSet rs = reasoner.getPPOrdersNotCompletedQuery(p_S_Resource_ID, get_TrxName()) - .scroll(); - try - { - while(rs.hasNext()) - { - runCRP(rs.next()); - } - } - finally - { - DB.close(rs); - rs = null; - } - - return "OK"; - } - - public void runCRP(MPPOrder order) - { - log.info("PP_Order DocumentNo:" + order.getDocumentNo()); - BigDecimal qtyOpen = order.getQtyOpen(); - MPPOrderWorkflow owf = order.getMPPOrderWorkflow(); - log.info("PP_Order Workflow:" + owf.getName()); - - // Schedule Fordward - if (p_ScheduleType.equals(FORWARD_SCHEDULING)) - { - Timestamp date = order.getDateStartSchedule(); - int nodeId = owf.getPP_Order_Node_ID(); - MPPOrderNode node = null; - - while(nodeId != 0) - { - node = owf.getNode(nodeId); - log.info("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : ""); - MResource resource = MResource.get(getCtx(), node.getS_Resource_ID()); - - // Skip this node if there is no resource - if(resource == null) - { - nodeId = owf.getNext(nodeId, getAD_Client_ID()); - continue; - } - - if(!reasoner.isAvailable(resource)) - { - throw new AdempiereException("@ResourceNotInSlotDay@"); - } - - MResourceType resourceType = resource.getResourceType(); - long nodeMillis = calculateMillisFor(node, resourceType, qtyOpen, owf.getDurationBaseSec()); - Timestamp dateFinish = scheduleForward(date, nodeMillis ,resource); - - node.setDateStartSchedule(date); - node.setDateFinishSchedule(dateFinish); - node.saveEx(get_TrxName()); - - date = node.getDateFinishSchedule(); - nodeId = owf.getNext(nodeId, getAD_Client_ID()); - } - // Update order finish date - if (node != null && node.getDateFinishSchedule()!= null) - { - order.setDateFinishSchedule(node.getDateFinishSchedule()); - } - } - // Schedule backward - else if (p_ScheduleType.equals(BACKWARD_SCHEDULING)) - { - Timestamp date = order.getDateFinishSchedule(); - int nodeId = owf.getNodeLastID(getAD_Client_ID()); - MPPOrderNode node = null; - - while(nodeId != 0) - { - node = owf.getNode(nodeId); - log.info("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : ""); - MResource resource = MResource.get(getCtx(), node.getS_Resource_ID()); - - // Skip this node if there is no resource - if(resource == null) - { - nodeId = owf.getPrevious(nodeId, getAD_Client_ID()); - continue; - } - - if(!reasoner.isAvailable(resource)) - { - throw new AdempiereException("@ResourceNotInSlotDay@"); - } - - MResourceType resourceType = resource.getResourceType(); - long nodeMillis = calculateMillisFor(node, resourceType, qtyOpen, owf.getDurationBaseSec()); - Timestamp dateStart = scheduleBackward(date, nodeMillis ,resource); - - node.setDateStartSchedule(dateStart); - node.setDateFinishSchedule(date); - node.saveEx(); - - date = node.getDateStartSchedule(); - nodeId = owf.getPrevious(nodeId, getAD_Client_ID()); - } - // Update order start date - if (node != null && node.getDateStartSchedule() != null) - { - order.setDateStartSchedule(node.getDateStartSchedule()) ; - } - } - else - { - throw new AdempiereException("Unknown scheduling method - "+p_ScheduleType); - } - - order.saveEx(get_TrxName()); - } - - /** - * Calculate how many millis take to complete given qty on given node(operation). - * @param node operation - * @param type resource type - * @param resource resource involved in that operation - * @param qty required quantity - * @param commonBase - * @return duration in millis - */ - private long calculateMillisFor(MPPOrderNode node, MResourceType type, BigDecimal qty, long commonBase) - { -// // Available time factor of the resource of the workflow node -// double actualDay = type.getDayDurationMillis(); -// final double aDay24 = 24*60*60*1000; // A day of 24 hours in milliseconds -// BigDecimal factorAvailablility = new BigDecimal((actualDay / aDay24)); - - // Total duration of workflow node (seconds) ... - // ... its static single parts ... - long totalDuration = - + node.getQueuingTime() - + node.getSetupTimeRequiered() // Use the present required setup time to notice later changes - + node.getMovingTime() - + node.getWaitingTime() - ; - // ... and its qty dependend working time ... (Use the present required duration time to notice later changes) - totalDuration += qty.doubleValue() * node.getDuration(); - - // Returns the total duration of a node in milliseconds. - return (long)(totalDuration * commonBase * 1000); - } - - private Timestamp scheduleForward(Timestamp start, long nodeDurationMillis, MResource r) - { - MResourceType t = r.getResourceType(); - Timestamp end = null; - int iteration = 0; // statistical interation count - do - { - start = reasoner.getAvailableDate(r, start, false); - Timestamp dayStart = t.getDayStart(start); - Timestamp dayEnd = t.getDayEnd(start); - // If working has already began at this day and the value is in the range of the - // resource's availability, switch start time to the given again - if(start.after(dayStart) && start.before(dayEnd)) - { - dayStart = start; - } - - // The available time at this day in milliseconds - long availableDayDuration = dayEnd.getTime() - dayStart.getTime(); - if (availableDayDuration < 0) - { - throw new AdempiereException("@TimeSlotStart@ > @TimeSlotEnd@ ("+dayEnd+" > "+dayStart+")"); - } - - // The work can be finish on this day. - if(availableDayDuration >= nodeDurationMillis) - { - end = new Timestamp(dayStart.getTime() + nodeDurationMillis); - nodeDurationMillis = 0; - break; - } - // Otherwise recall with next day and the remained node duration. - else - { - start = TimeUtil.addDays(TimeUtil.getDayBorder(start, null, false), 1); - nodeDurationMillis -= availableDayDuration; - } - - iteration++; - if (iteration > p_MaxIterationsNo) - { - throw new AdempiereException("Maximum number of iterations exceeded ("+p_MaxIterationsNo+")"); - } - } while (nodeDurationMillis > 0); - - return end; - } - - /** - * Calculate start date having duration and resource - * @param end end date - * @param nodeDurationMillis duration [millis] - * @param r resource - * @return start date - */ - private Timestamp scheduleBackward(Timestamp end, long nodeDurationMillis, MResource r) - { - MResourceType t = r.getResourceType(); - log.info("--> ResourceType " + t); - Timestamp start = null; - int iteration = 0; // statistical iteration count - do - { - log.info("--> end=" + end); - log.info("--> nodeDuration=" + nodeDurationMillis); - - end = reasoner.getAvailableDate(r, end, true); - log.info("--> end(available)=" + end); - Timestamp dayEnd = t.getDayEnd(end); - Timestamp dayStart = t.getDayStart(end); - log.info("--> dayStart=" + dayStart + ", dayEnd=" + dayEnd); - - // If working has already began at this day and the value is in the range of the - // resource's availability, switch end time to the given again - if(end.before(dayEnd) && end.after(dayStart)) - { - dayEnd = end; - } - - // The available time at this day in milliseconds - long availableDayDuration = dayEnd.getTime() - dayStart.getTime(); - log.info("--> availableDayDuration " + availableDayDuration); - if (availableDayDuration < 0) - { - throw new AdempiereException("@TimeSlotStart@ > @TimeSlotEnd@ ("+dayEnd+" > "+dayStart+")"); - } - - // The work can be finish on this day. - if(availableDayDuration >= nodeDurationMillis) - { - log.info("--> availableDayDuration >= nodeDuration true " + availableDayDuration + "|" + nodeDurationMillis ); - start = new Timestamp(dayEnd.getTime() - nodeDurationMillis); - nodeDurationMillis = 0; - break; - } - // Otherwise recall with previous day and the remained node duration. - else - { - log.info("--> availableDayDuration >= nodeDuration false " + availableDayDuration + "|" + nodeDurationMillis ); - log.info("--> nodeDuration-availableDayDuration " + (nodeDurationMillis-availableDayDuration) ); - - end = TimeUtil.addDays(TimeUtil.getDayBorder(end, null, true), -1); - nodeDurationMillis -= availableDayDuration; - } - // - iteration++; - if (iteration > p_MaxIterationsNo) - { - throw new AdempiereException("Maximum number of iterations exceeded ("+p_MaxIterationsNo+")"); - } - } - while(nodeDurationMillis > 0); - - log.info(" --> start=" + start + " <---------------------------------------- "); - return start; - } - - -} - diff --git a/base/src/org/eevolution/process/CRPSummary.java b/base/src/org/eevolution/process/CRPSummary.java deleted file mode 100644 index 3737ffc975..0000000000 --- a/base/src/org/eevolution/process/CRPSummary.java +++ /dev/null @@ -1,599 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.process; - - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.logging.Level; - -import org.compiere.model.MResource; -import org.compiere.model.MResourceType; -import org.compiere.model.MUOM; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.eevolution.model.X_T_MRP_CRP; - -/** - * Re-Open Order Process (from Closed to Completed) - * - * @author Victor P�rez, e-Evolution, S.C. - * @version $Id: CreateCost.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ - */ -public class CRPSummary extends SvrProcess -{ - /** */ - - private int p_S_Resource_ID = 0 ; - private Timestamp p_DateFrom = null; - private Timestamp p_DateTo = null; - private String p_FrequencyType = null; - private int AD_Client_ID = 0; - private int AD_PInstance_ID = 0; - - - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - AD_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID")); - ProcessInfoParameter[] para = getParameter(); - - AD_PInstance_ID = getAD_PInstance_ID(); - - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - - if (para[i].getParameter() == null) - ; - else if (name.equals("S_Resource_ID")) - { - p_S_Resource_ID = ((BigDecimal)para[i].getParameter()).intValue(); - - } - else if (name.equals("DateFrom")) - { - p_DateFrom = ((Timestamp)para[i].getParameter()); - } - else if (name.equals("DateTo")) - { - p_DateTo = ((Timestamp)para[i].getParameter()); - } - else if (name.equals("FrequencyType")) - { - p_FrequencyType = ((String)para[i].getParameter()); - } - else - log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); - } - } // prepare - - protected String doIt() throws Exception - { - - return runCRP(); - } - - protected String runCRP() - { - /* - String sql = "SELECT owf.PP_Order_Workflow_ID , o.DateStartSchedule , o.DateFinishSchedule ,o.QtyOrdered - o.QtyDelivered - o.QtyScrap AS QtyOpen FROM PP_Order o INNER JOIN PP_Order_Workflow owf ON (owf.PP_ORDER_ID = o.PP_Order_ID) WHERE o.DocStatus <> 'CL' AND o.AD_Client_ID = ? AND o.S_Resource_ID= ? ORDER BY DatePromised" ; - try - { - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql); - pstmt.setInt(1, AD_Client_ID); - pstmt.setInt(1, p_S_Resource_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - BigDecimal QtyOpen = rs.getBigDecimal(4); - - MPP_OrderWorkflow owf = new MPP_OrderWorkflow(getCtx(), rs.getInt(1),null); - - - // Schedule Fordward - if (p_ScheduleType.equals("F")) - { - Timestamp date = rs.getTimestamp(2); - int node = owf.getPP_Order_Node_ID(); - long seconds = 0; - while(node != 0) - { - MPP_OrderNode n = new MPP_OrderNode(getCtx(),node , null); - // Calculate Total seconds for Node - seconds = (n.getQueuingTime() + n.getSetupTime() + QtyOpen.multiply(new BigDecimal(n.getDuration())).longValue() + n.getMovingTime() + n.getWaitingTime()) * owf.getDurationBaseSec(); - // Calculate Factor Day - MResource r = MResource.get(getCtx(),n.getS_Resource_ID()); - if (r == null) - continue; - - MResourceType type = MResourceType.get(Env.getCtx(),r.getS_ResourceType_ID()); - long hours = 0 ; - - if (type.isTimeSlot()) - hours = getHoursAvailable(type.getTimeSlotStart(),type.getTimeSlotStart()); - else - hours = 24; - - long factor = (hours * 3600) / 86400; // factor = second for a day / avlailable hour in sencond - System.out.print("factor:" + factor); - long totalseconds = (seconds / factor) ; // (total seconds * factor seconds avaialble) / a day in seconds - Long day = new Long((totalseconds/(hours* 3600))); - Timestamp dateFinishSchedule = getDate(date, day.intValue() ,type); - n.setDateStartSchedule(date); - n.setDateFinishSchedule(dateFinishSchedule); - n.save(get_TrxName()); - node = owf.getNext(node); - date = n.getDateFinishSchedule(); - } - } - - // schedule backward - if (p_ScheduleType.equals("B")) - { - Timestamp date = rs.getTimestamp(3); - int node = owf.getLast(0); - //System.out.print("First Node" + node); - long seconds = 0; - while(node != 0) - { - MPP_OrderNode n = new MPP_OrderNode(getCtx(),node , null); - // Calculate Total seconds for Node - seconds = (n.getQueuingTime() + n.getSetupTime() + QtyOpen.multiply(new BigDecimal(n.getDuration())).longValue() + n.getMovingTime() + n.getWaitingTime()) * owf.getDurationBaseSec(); - // Calculate Factor Day - MResource r = MResource.get(getCtx(),n.getS_Resource_ID()); - if (r == null) - continue; - - MResourceType type = MResourceType.get(Env.getCtx(),r.getS_ResourceType_ID()); - long hours = 0 ; - - if (type.isTimeSlot()) - hours = getHoursAvailable(type.getTimeSlotStart(),type.getTimeSlotStart()); - else - hours = 24; - - long factor = (hours * 3600) / 86400; // factor = second for a day / avlailable hour in sencond - System.out.print("factor:" + factor); - long totalseconds = (seconds / factor) ; // (total seconds * factor seconds avaialble) / a day in seconds - Long day = new Long((totalseconds/(hours* 3600)) * -1 ); - Timestamp dateStartSchedule = getDate(date, day.intValue() ,type); - n.setDateFinishSchedule(date); - n.setDateStartSchedule(dateStartSchedule); - n.save(get_TrxName()); - node = owf.getPrevious(node); - date = n.getDateStartSchedule(); - } - } - } - rs.close(); - pstmt.close(); - } - catch (Exception e) - { - log.log(Level.SEVERE,"doIt - " + sql, e); - return ""; - } */ - return ""; - } - - /** - * Return DateTime + offset in Second - * @param dateTime Date and Time - * @param offset Second offset - * @return dateTime + offset in Second - */ - static public Timestamp addSecond (Timestamp dateTime, long offset) - { - if (dateTime == null) - dateTime = new Timestamp(System.currentTimeMillis()); - if (offset == 0) - return dateTime; - // - GregorianCalendar cal = new GregorianCalendar(); - cal.setTime(dateTime); - cal.add(Calendar.SECOND, new Long(offset).intValue()); // may have a problem with negative - return new Timestamp (cal.getTimeInMillis()); - } // addMinutes - - - /** - * Return horus in - * @param Time Start - * @param Time End - * @return hours - */ - public long getHoursAvailable(Timestamp time1 , Timestamp time2) - { - GregorianCalendar g1 = new GregorianCalendar(); - g1.setTimeInMillis(time1.getTime()); - GregorianCalendar g2 = new GregorianCalendar(); - g1.setTimeInMillis(time2.getTime()); - // the above two dates are one second apart - Date d1 = g1.getTime(); - Date d2 = g2.getTime(); - long l1 = d1.getTime(); - long l2 = d2.getTime(); - long difference = l2 - l1; - System.out.println("Elapsed milliseconds: " + difference); - return difference; - } - - // Calculate Days not Avialable from Date to Date for a Resource - public int getNotAvailbleDays(Timestamp start, Timestamp end, MResourceType t) - { - if (!t.isDateSlot()) - return 0; - - GregorianCalendar g1 = new GregorianCalendar(); - g1.setTimeInMillis(start.getTime()); - GregorianCalendar g2 = new GregorianCalendar(); - g2.setTimeInMillis(end.getTime()); - - //int elapsed = 1; - GregorianCalendar gc1, gc2; - - if (g2.after(g1)) { - gc2 = (GregorianCalendar) g2.clone(); - gc1 = (GregorianCalendar) g1.clone(); - } - else { - gc2 = (GregorianCalendar) g1.clone(); - gc1 = (GregorianCalendar) g2.clone(); - } - - gc1.clear(Calendar.MILLISECOND); - gc1.clear(Calendar.SECOND); - gc1.clear(Calendar.MINUTE); - gc1.clear(Calendar.HOUR_OF_DAY); - - gc2.clear(Calendar.MILLISECOND); - gc2.clear(Calendar.SECOND); - gc2.clear(Calendar.MINUTE); - gc2.clear(Calendar.HOUR_OF_DAY); - - int DaysNotAvialable = 0; - - - while ( gc1.before(gc2) ) - { - gc1.add(Calendar.DATE, 1); - - switch(gc1.get(Calendar.DAY_OF_WEEK)) - { - case Calendar.SUNDAY: - if (!t.isOnSunday()) - DaysNotAvialable++; - break; - case Calendar.MONDAY: - if (!t.isOnMonday()) - DaysNotAvialable++; - break; - case Calendar.TUESDAY: - if (!t.isOnTuesday()) - DaysNotAvialable++; - break; - case Calendar.WEDNESDAY: - if (!t.isOnWednesday()) - DaysNotAvialable++; - break; - case Calendar.THURSDAY: - if (!t.isOnThursday()) - DaysNotAvialable++; - break; - case Calendar.FRIDAY: - if (!t.isOnFriday()) - DaysNotAvialable++; - break; - case Calendar.SATURDAY: - if (!t.isOnSaturday()) - DaysNotAvialable++; - break; - } - } - - - - System.out.println("DaysNotAvialable"+ DaysNotAvialable); - return DaysNotAvialable; - } - - public void Summary(Timestamp start, Timestamp finish , MResource r) - { - - GregorianCalendar gc1 = new GregorianCalendar(); - gc1.setTimeInMillis(start.getTime()); - gc1.clear(Calendar.MILLISECOND); - gc1.clear(Calendar.SECOND); - gc1.clear(Calendar.MINUTE); - gc1.clear(Calendar.HOUR_OF_DAY); - - GregorianCalendar gc2 = new GregorianCalendar(); - gc2.setTimeInMillis(finish.getTime()); - gc2.clear(Calendar.MILLISECOND); - gc2.clear(Calendar.SECOND); - gc2.clear(Calendar.MINUTE); - gc2.clear(Calendar.HOUR_OF_DAY); - - MResourceType t = MResourceType.get(Env.getCtx(),r.getS_ResourceType_ID()); - long hours = 0; - - if (t.isTimeSlot()) - hours = getHoursAvailable(t.getTimeSlotStart(),t.getTimeSlotStart()); - else - hours = 24; - - boolean available = false; - ArrayList list = new ArrayList(); - - int col = 0; - int row = 1; - int summary = 0; - - Col cols = new Col(); - cols.setFrom("Past Due"); - cols.setTo(start.toString()); - cols.setDays(0); - cols.setCapacity(0); - cols.setLoad(0); - cols.setSummary(0); - - list.add(0,cols); - - col ++; - - while(gc1.before(gc2)) - { - gc1.add(Calendar.DATE, 1); - - switch(gc1.get(Calendar.DAY_OF_WEEK)) - { - case Calendar.SUNDAY: - if (t.isOnSunday()) - available = true; - break; - case Calendar.MONDAY: - if (t.isOnMonday()) - available = true; - break; - case Calendar.TUESDAY: - if (t.isOnTuesday()) - available = true; - break; - case Calendar.WEDNESDAY: - if (t.isOnWednesday()) - available = true; - break; - case Calendar.THURSDAY: - if (t.isOnThursday()) - available = true; - break; - case Calendar.FRIDAY: - if (t.isOnFriday()) - available = true; - break; - case Calendar.SATURDAY: - if (t.isOnSaturday()) - available = true; - break; - } - - - - if (available) - { - cols = new Col(); - cols.setFrom(gc1.getTime().toString()); - cols.setTo(gc1.getTime().toString()); - cols.setDays(1); - Long Hours = new Long(hours); - cols.setCapacity(Hours.intValue()); - int C_UOM_ID = DB.getSQLValue(null,"SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? " , r.getS_Resource_ID()); - MUOM oum = MUOM.get(getCtx(),C_UOM_ID); - if (oum.isHour()) - { - Timestamp date = new Timestamp(gc1.getTimeInMillis()); - int seconds = getLoad(r.getS_Resource_ID(),date ,date); - cols.setLoad(seconds / 3600 ); - } - cols.setSummary(summary + cols.getDifference()); - summary = cols.getSummary(); - list.add(col,cols); - } - } - - col = 0; - boolean newrow = true; - Col[] lines = new Col[list.size()]; - - //set Title - for (int z = 0 ; z <= lines.length ; z ++) - { - - } - - for (int i = 0 ; i <= lines.length ; i ++) - { - - if (newrow) - { - X_T_MRP_CRP crp = new X_T_MRP_CRP(getCtx(),0 , null); - crp.setDescription("CRP Resource" + r.getName()); - //crp.setRange00(lines[i].getFrom() + "/" + lines[i].getTo()); - - } - - - switch(col) - { - case 0: - col++; - case 1: - col++; - case 2: - col++; - case 3: - col++; - case 4: - col++; - case 5: - col++; - case 6: - col++; - case 7: - col++; - case 8: - col++; - case 9: - col++; - case 10: - col++; - case 11: - col++; - case 12: - col=0; - newrow = true; - } - - col ++; - } - - } - - int getLoad(int S_Resource_ID, Timestamp start, Timestamp end) - { - int load = 0; - String sql = "SELECT SUM( CASE WHEN ow.DurationUnit = 's' THEN 1 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'm' THEN 60 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'h' THEN 3600 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'Y' THEN 31536000 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'M' THEN 2592000 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'D' THEN 86400 END ) AS Load FROM PP_Order_Node onode INNER JOIN PP_Order_Workflow ow ON (ow.PP_Order_Workflow_ID = onode.PP_Order_Workflow_ID) INNER JOIN PP_Order o ON (o.PP_Order_ID = onode.PP_Order_ID) WHERE onode. = ? AND onode.DateStartSchedule => ? AND onode.DateFinishSchedule =< ? AND onode.AD_Client_ID = ?" ; - try - { - PreparedStatement pstmt = null; - pstmt = DB.prepareStatement (sql, get_TrxName()); - pstmt.setInt(1, S_Resource_ID); - pstmt.setTimestamp(1, start); - pstmt.setTimestamp(2, end); - pstmt.setInt(3,AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - load = rs.getInt(1); - } - rs.close(); - pstmt.close(); - return load; - } - catch (Exception e) - { - log.log(Level.SEVERE,"doIt - " + sql, e); - } - return 0; - } - - - private class Col - { - int Day = 0; - String From = null; - String To = null; - int Capacity = 0; - int Load = 0; - int Summary = 0; - - public Col() - { - } - - void setDays(int day) - { - Day = day; - } - - int getDays() - { - return Day; - } - - void setCapacity(int capacity) - { - Capacity = capacity; - } - - int getCapacity() - { - return Capacity; - } - - void setLoad(int load) - { - Load = load; - } - - int getLoad() - { - return Load; - } - - int getDifference() - { - return Capacity - Load; - } - - void setSummary(int summary) - { - Summary = summary; - } - - int getSummary() - { - return Summary; - } - - void setFrom(String from) - { - From = from; - } - - String getFrom() - { - return From; - } - - void setTo(String to) - { - To = to; - } - - String getTo() - { - return To; - } - - } - - } - diff --git a/base/src/org/eevolution/process/CalculateLowLevel.java b/base/src/org/eevolution/process/CalculateLowLevel.java deleted file mode 100644 index 2da104ae1d..0000000000 --- a/base/src/org/eevolution/process/CalculateLowLevel.java +++ /dev/null @@ -1,72 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.process; - -import java.util.logging.Level; - -import org.compiere.model.MProduct; -import org.compiere.model.POResultSet; -import org.compiere.model.Query; -import org.compiere.process.SvrProcess; -import org.compiere.util.Env; -import org.eevolution.model.MPPProductBOMLine; - -/** - * CalculateLowLevel for MRP - * - * @author Victor Perez, e-Evolution, S.C. - * @version $Id: CalculateLowLevel.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ - * - * @author Teo Sarca, SC ARHIPAC SERVICE SRL - */ -public class CalculateLowLevel extends SvrProcess -{ - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - } // prepare - - protected String doIt() throws Exception - { - int count_ok = 0; - int count_err = 0; - // - POResultSet rs = new Query(getCtx(), MProduct.Table_Name, "AD_Client_ID=?", get_TrxName()) - .setParameters(new Object[]{Env.getAD_Client_ID(getCtx())}) - .setOrderBy(MProduct.COLUMNNAME_M_Product_ID) - .scroll(); - rs.setCloseOnError(true); - while(rs.hasNext()) { - MProduct product = rs.next(); - try { - int lowlevel = MPPProductBOMLine.getLowLevel(getCtx(), product.get_ID(), get_TrxName()); - product.setLowLevel(lowlevel); - product.saveEx(); - count_ok++; - } - catch(Exception e) { - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - count_err++; - } - } - rs.close(); - - return "@Ok@ #"+count_ok+" @Error@ #"+count_err; - } -} diff --git a/base/src/org/eevolution/process/CopyPriceToStandard.java b/base/src/org/eevolution/process/CopyPriceToStandard.java deleted file mode 100644 index ff61d044be..0000000000 --- a/base/src/org/eevolution/process/CopyPriceToStandard.java +++ /dev/null @@ -1,156 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.process; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Collection; -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.model.MAcctSchema; -import org.compiere.model.MConversionRate; -import org.compiere.model.MCost; -import org.compiere.model.MCostElement; -import org.compiere.model.MProduct; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; -import org.compiere.util.Env; - - -/** - * CopyPriceToStandard - * - * @author Victor Perez, e-Evolution, S.C. - * @version $Id: CopyPriceToStandard.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ - */ -public class CopyPriceToStandard extends SvrProcess -{ - /** */ - private int p_AD_Org_ID = 0; - private int p_C_AcctSchema_ID = 0; - private int p_M_CostType_ID = 0; - private int p_M_CostElement_ID = 0; - private int p_M_PriceList_Version_ID =0; - private Properties ctx = Env.getCtx(); - - - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - - - - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - - if (para[i].getParameter() == null) - ; - else if (name.equals("M_CostType_ID")) - { - p_M_CostType_ID = ((BigDecimal)para[i].getParameter()).intValue(); - - } - else if (name.equals("AD_Org_ID")) - { - p_AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue(); - - } - else if (name.equals("C_AcctSchema_ID")) - { - p_C_AcctSchema_ID = ((BigDecimal)para[i].getParameter()).intValue(); - - } - - else if (name.equals("M_CostElement_ID")) - { - p_M_CostElement_ID = ((BigDecimal)para[i].getParameter()).intValue(); - - } - else if (name.equals("M_PriceList_Version_ID")) - { - p_M_PriceList_Version_ID = ((BigDecimal)para[i].getParameter()).intValue(); - } - else - log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); - } - } // prepare - - - - protected String doIt() throws Exception - { - BigDecimal price = Env.ZERO; - BigDecimal convrate = Env.ZERO; - int M_PriceList_ID =0; - int M_PriceList_Version_ID = 0; - int M_Product_ID =0; - int C_Currency_ID = 0; - BigDecimal list = Env.ZERO; - MAcctSchema as = new MAcctSchema(ctx,p_C_AcctSchema_ID ,null); - StringBuffer sql = new StringBuffer("SELECT M_Product_ID,M_PriceList_Version_ID, PriceStd FROM M_ProductPrice WHERE M_PriceList_Version_ID =" +p_M_PriceList_Version_ID +" AND PriceStd <> 0"); - try - { - //System.out.println("query " +sql.toString()); - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); - - // - while (rs.next()) - { - M_Product_ID = rs.getInt(1); - M_PriceList_Version_ID = rs.getInt(2); - - M_PriceList_ID = DB.getSQLValue(get_TrxName(),"SELECT M_PriceList_ID FROM M_PriceList_Version WHERE M_PriceList_Version_ID = ? " ,M_PriceList_Version_ID ); - C_Currency_ID = DB.getSQLValue(get_TrxName() , "SELECT C_Currency_ID FROM M_PriceList WHERE M_PriceList_ID = ?",M_PriceList_ID); - - if (C_Currency_ID!=as.getC_Currency_ID()) - { - price = MConversionRate.convert(ctx,rs.getBigDecimal(3),C_Currency_ID,as.getC_Currency_ID(),getAD_Client_ID(),p_AD_Org_ID); - } - else - price = rs.getBigDecimal(3); - MProduct product = MProduct.get(getCtx(), M_Product_ID); - Collection costs = MCost.getByCostType(product, as, p_M_CostType_ID, p_AD_Org_ID, 0, MCostElement.COSTELEMENTTYPE_Material); - - for (MCost cost : costs) - { - MCostElement element = new MCostElement(getCtx(), p_M_CostElement_ID, get_TrxName()); - cost.setFutureCostPrice(price); - cost.save(); - break; - } - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, "doIt - " + sql, e); - } - - return "ok"; - } -} diff --git a/base/src/org/eevolution/process/CreateCostElement.java b/base/src/org/eevolution/process/CreateCostElement.java deleted file mode 100644 index 6a11045b0d..0000000000 --- a/base/src/org/eevolution/process/CreateCostElement.java +++ /dev/null @@ -1,196 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ - -package org.eevolution.process; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.logging.Level; - -import org.compiere.model.MAcctSchema; -import org.compiere.model.MCost; -import org.compiere.model.MCostElement; -import org.compiere.model.MOrg; -import org.compiere.model.MProduct; -import org.compiere.model.Query; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; - - - -/** - * Create Cost Element - * - * @author victor.perez@e-evolution.com, e-Evolution, S.C. - * @version $Id: CreateCostElement.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ - * - * @author Teo Sarca, www.arhipac.ro - */ -public class CreateCostElement extends SvrProcess -{ - private Integer p_AD_Org_ID = null; - private int p_C_AcctSchema_ID = 0; - private int p_M_CostType_ID = 0; - private int p_M_CostElement_ID = 0; - private int p_M_Product_Category_ID = 0; - private int p_M_Product_ID = 0; - private int p_M_AttributeSetInstance_ID= 0; - - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) - { - ; - } - else if (name.equals("AD_Org_ID")) - { - p_AD_Org_ID = para[i].getParameterAsInt(); - } - else if (name.equals(MCost.COLUMNNAME_C_AcctSchema_ID)) - { - p_C_AcctSchema_ID = para[i].getParameterAsInt(); - } - else if (name.equals(MCost.COLUMNNAME_M_CostType_ID)) - { - p_M_CostType_ID = para[i].getParameterAsInt(); - } - else if (name.equals(MCost.COLUMNNAME_M_CostElement_ID)) - { - p_M_CostElement_ID = para[i].getParameterAsInt(); - } - else if (name.equals(MProduct.COLUMNNAME_M_Product_Category_ID)) - { - p_M_Product_Category_ID = para[i].getParameterAsInt(); - } - else if (name.equals(MCost.COLUMNNAME_M_Product_ID)) - { - p_M_Product_ID = para[i].getParameterAsInt(); - } - else if (name.equals(MCost.COLUMNNAME_M_AttributeSetInstance_ID)) - { - p_M_AttributeSetInstance_ID = para[i].getParameterAsInt(); - } - else - log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); - } - } // prepare - - protected String doIt() throws Exception - { - MAcctSchema as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID); - - String whereClauseElements= ""; - ArrayList paramsElements = new ArrayList(); - - if (p_M_CostElement_ID > 0) - { - whereClauseElements = MCostElement.COLUMNNAME_M_CostElement_ID+"=?"; - paramsElements.add(p_M_CostElement_ID); - } - - - Collection elements = new Query(getCtx(), MCostElement.Table_Name, whereClauseElements, get_TrxName()) - .setParameters(paramsElements) - .list(); - - String whereClauseProducts= ""; - ArrayList paramsProducts= new ArrayList(); - - if (p_M_Product_Category_ID > 0) - { - whereClauseProducts = MProduct.COLUMNNAME_M_Product_Category_ID+"=?"; - paramsProducts.add(p_M_Product_Category_ID); - } - - if (p_M_Product_ID > 0) - { - if(p_M_Product_Category_ID > 0) - whereClauseProducts += " AND "; - - whereClauseProducts += MProduct.COLUMNNAME_M_Product_ID+"=?"; - paramsProducts.add(p_M_Product_ID); - } - - int[] product_ids = new Query(getCtx(), MProduct.Table_Name, whereClauseProducts, get_TrxName()) - .setParameters(paramsProducts) - .getIDs(); - int count_costs = 0; - for(int org_id : getOrgs(as)) - { - for(int product_id: product_ids) - { - for(MCostElement element : elements) - { - - MCost cost = MCost.get (getCtx(), getAD_Client_ID(), org_id, product_id, - p_M_CostType_ID, as.getC_AcctSchema_ID(), element.get_ID(), - p_M_AttributeSetInstance_ID); - if(cost == null) - { - cost = new MCost (MProduct.get(getCtx(), product_id), p_M_AttributeSetInstance_ID,as, org_id, element.get_ID()); - cost.setM_CostType_ID(p_M_CostType_ID); - cost.saveEx(get_TrxName()); - count_costs++; - } - } - } - } - - - return "@Created@ #"+count_costs; - } - - /** - * get the IDs for Organization and Valid the Cost Level - * @param as Account Schema - * @return array of IDs - */ - private int [] getOrgs(MAcctSchema as) - { - int[] orgs_ids = new int[1]; - orgs_ids[0] = 0; - String whereClauseOrg = ""; - ArrayList paramsOrg = new ArrayList(); - //Set the Costing Level - String CostingLevel = as.getCostingLevel(); - if (p_AD_Org_ID != null) - { - if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) - { - p_AD_Org_ID = 0; - p_M_AttributeSetInstance_ID = 0; - return orgs_ids; - } - - whereClauseOrg = "AD_Org_ID=?"; - paramsOrg.add(p_AD_Org_ID); - } - - orgs_ids = new Query(getCtx(), MOrg.Table_Name, whereClauseOrg, get_TrxName()) - .setParameters(paramsOrg) - .getIDs(); - return orgs_ids; - } -} // Create Cost Element diff --git a/base/src/org/eevolution/process/CreateDocType.java b/base/src/org/eevolution/process/CreateDocType.java deleted file mode 100644 index 977f1570d5..0000000000 --- a/base/src/org/eevolution/process/CreateDocType.java +++ /dev/null @@ -1,162 +0,0 @@ -package org.eevolution.process; - -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.model.MDocType; -import org.compiere.model.MGLCategory; -import org.compiere.model.MSequence; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.Env; - - -/** - * AddLiberoRecords - * - * @author Tim Heath - * @version $Id: AddLiberoRecords.java,v 1 xp_prg Exp $ - */ -public class CreateDocType extends SvrProcess -{ - /** */ - - private int AD_Client_ID = 0 ; - private String trxname = null; - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - System.out.println("In AddLiberoRecords prepare"); - log.fine("In AddLiberoRecords prepare"); - AD_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID")); - ProcessInfoParameter[] para = getParameter(); - } // prepare - - - protected String doIt() throws Exception - { - System.out.println("In AddLiberoRecords doIt"); - log.fine("In AddLiberoRecords doIt"); - - //MClient c = (MClient)po; - Properties m_ctx = Env.getCtx(); - trxname = get_TrxName(); - //Manufacturing Document - int GL_Manufacturing = createGLCategory("Manufactuing", MGLCategory.CATEGORYTYPE_Document, false); - int GL_Distribution = createGLCategory("Distribution", MGLCategory.CATEGORYTYPE_Document, false); - //Payroll GLCategory created in 140_FB1935325HRProcess.sql - //int GL_Payroll = createGLCategory("Payroll", MGLCategory.CATEGORYTYPE_Document, false); - - createDocType("Manufacturing Order", "Manufacturing Order", - MDocType.DOCBASETYPE_ManufacturingOrder, null, - 0, 0, 80000, GL_Manufacturing); - createDocType("Manufacturing Order Planning","Order Planning", - MDocType.DOCBASETYPE_ManufacturingOrder, null, - 0, 0, 81000, GL_Manufacturing); - createDocType("Maintenance Order","Maintenance Order", - MDocType.DOCBASETYPE_MaintenanceOrder, null, - 0, 0, 86000, GL_Manufacturing); - createDocType("Quality Order","Quality Order", - MDocType.DOCBASETYPE_QualityOrder, null, - 0, 0, 87000, GL_Manufacturing); - createDocType("Distribution Order","Distribution Orde", - MDocType.DOCBASETYPE_DistributionOrder, null, - 0, 0, 88000, GL_Distribution); -/* //Payroll DocType created in 140_FB1935325HRProcess.sql - createDocType("Payroll","Payroll", - MDocType.DOCBASETYPE_Payroll, null, - 0, 0, 90000, GL_Payroll); -*/ - return "ok"; - - } - - - /** - * Create GL Category - * @param Name name - * @param CategoryType category type MGLCategory.CATEGORYTYPE_* - * @param isDefault is default value - * @return GL_Category_ID - */ - private int createGLCategory (String Name, String CategoryType, boolean isDefault) - { - MGLCategory cat = new MGLCategory (Env.getCtx() , 0, trxname); - cat.setName(Name); - cat.setCategoryType(CategoryType); - cat.setIsDefault(isDefault); - if (!cat.save()) - { - log.log(Level.SEVERE, "GL Category NOT created - " + Name); - return 0; - } - // - return cat.getGL_Category_ID(); - } // createGLCategory - - /** - * Create Document Types with Sequence - * @param Name name - * @param PrintName print name - * @param DocBaseType document base type - * @param DocSubTypeSO sales order sub type - * @param C_DocTypeShipment_ID shipment doc - * @param C_DocTypeInvoice_ID invoice doc - * @param StartNo start doc no - * @param GL_Category_ID gl category - * @return C_DocType_ID doc type or 0 for error - */ - private int createDocType (String Name, String PrintName, - String DocBaseType, String DocSubTypeSO, - int C_DocTypeShipment_ID, int C_DocTypeInvoice_ID, - int StartNo, int GL_Category_ID) - { - log.fine("In createDocType"); - log.fine("docBaseType: " + DocBaseType); - log.fine("GL_Category_ID: " + GL_Category_ID); - MSequence sequence = null; - if (StartNo != 0) - { - sequence = new MSequence(Env.getCtx(), getAD_Client_ID(), Name, StartNo, trxname); - if (!sequence.save()) - { - log.log(Level.SEVERE, "Sequence NOT created - " + Name); - return 0; - } - } - - //MDocType dt = new MDocType (Env.getCtx(), DocBaseType, Name, trxname); - MDocType dt = new MDocType (Env.getCtx(),0 , trxname); - dt.setAD_Org_ID(0); - dt.set_CustomColumn("DocBaseType", (Object) DocBaseType); - dt.setName (Name); - dt.setPrintName (Name); - if (DocSubTypeSO != null) - dt.setDocSubTypeSO(DocSubTypeSO); - if (C_DocTypeShipment_ID != 0) - dt.setC_DocTypeShipment_ID(C_DocTypeShipment_ID); - if (C_DocTypeInvoice_ID != 0) - dt.setC_DocTypeInvoice_ID(C_DocTypeInvoice_ID); - if (GL_Category_ID != 0) - dt.setGL_Category_ID(GL_Category_ID); - if (sequence == null) - dt.setIsDocNoControlled(false); - else - { - dt.setIsDocNoControlled(true); - dt.setDocNoSequence_ID(sequence.getAD_Sequence_ID()); - } - dt.setIsSOTrx(false); - if (!dt.save()) - { - log.log(Level.SEVERE, "DocType NOT created - " + Name); - return 0; - } - // - return dt.getC_DocType_ID(); - } // createDocType - -} diff --git a/base/src/org/eevolution/process/CreateProductPlanning.java b/base/src/org/eevolution/process/CreateProductPlanning.java deleted file mode 100644 index 691ed6b9da..0000000000 --- a/base/src/org/eevolution/process/CreateProductPlanning.java +++ /dev/null @@ -1,263 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ - -package org.eevolution.process; - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.logging.Level; - -import org.adempiere.exceptions.DBException; -import org.compiere.model.MWarehouse; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.eevolution.model.MPPProductPlanning; - -/** - * CreateProductPlanning - * - * @author Victor Perez, e-Evolution, S.C. - * @version $Id: CreateProductPlanning.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ - * - * @author Teo Sarca, http://www.arhipac.ro - */ -public class CreateProductPlanning extends SvrProcess -{ - /** Process Parameters */; - private int p_M_Product_Category_ID = 0; - private int p_M_Warehouse_ID = 0; - private int p_S_Resource_ID = 0 ; - private int p_Planner = 0 ; - private BigDecimal p_DeliveryTime_Promised = Env.ZERO; - private int p_DD_NetworkDistribution_ID = 0; - private int p_AD_Workflow_ID = 0; - private BigDecimal p_TimeFence = Env.ZERO; - private boolean p_CreatePlan = false; - private boolean p_MPS = false; - private String p_OrderPolicy = ""; - private BigDecimal p_OrderPeriod = Env.ZERO; - private BigDecimal p_TransferTime = Env.ZERO; - private BigDecimal p_SafetyStock = Env.ZERO; - private BigDecimal p_Order_Min = Env.ZERO; - private BigDecimal p_Order_Max = Env.ZERO; - private BigDecimal p_Order_Pack = Env.ZERO; - private BigDecimal p_Order_Qty = Env.ZERO; - private BigDecimal p_WorkingTime = Env.ZERO; - private int p_Yield = 0; - private int m_AD_Org_ID = 0; - private int m_AD_Client_ID = 0; - - // Statistics - private int count_created = 0; - private int count_updated = 0; - private int count_error = 0; - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - for (ProcessInfoParameter para : getParameter()) - { - String name = para.getParameterName(); - if (para.getParameter() == null) - ; - else if (name.equals("M_Product_Category_ID")) - { - p_M_Product_Category_ID = para.getParameterAsInt(); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_M_Warehouse_ID)) - { - p_M_Warehouse_ID = para.getParameterAsInt(); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_S_Resource_ID)) - { - p_S_Resource_ID = para.getParameterAsInt(); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_IsCreatePlan)) - { - p_CreatePlan = "Y".equals((String)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_IsMPS)) - { - p_MPS = "Y".equals((String)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_DD_NetworkDistribution_ID)) - { - p_DD_NetworkDistribution_ID = para.getParameterAsInt(); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_AD_Workflow_ID)) - { - p_AD_Workflow_ID = para.getParameterAsInt(); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_TimeFence)) - { - p_TimeFence = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_TransfertTime)) - { - p_TransferTime = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_SafetyStock)) - { - p_SafetyStock = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_Order_Min)) - { - p_Order_Min = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_Order_Max)) - { - p_Order_Max = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_Order_Pack)) - { - p_Order_Pack = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_Order_Qty)) - { - p_Order_Qty = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_WorkingTime)) - { - p_WorkingTime = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_Yield)) - { - p_Yield = ((BigDecimal)para.getParameter()).intValue(); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_DeliveryTime_Promised)) - { - p_DeliveryTime_Promised = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_Order_Period)) - { - p_OrderPeriod = ((BigDecimal)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_Order_Policy)) - { - p_OrderPolicy = ((String)para.getParameter()); - } - else if (name.equals(MPPProductPlanning.COLUMNNAME_Planner_ID)) - { - p_Planner = para.getParameterAsInt(); - } - else - { - log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name); - } - } - - m_AD_Client_ID = Env.getAD_Client_ID(getCtx()); - if(p_M_Warehouse_ID > 0) - { - MWarehouse w = MWarehouse.get(getCtx(), p_M_Warehouse_ID); - m_AD_Org_ID = w.getAD_Org_ID(); - } - } // prepare - - - /*************************************************************************** - * Create Data Planning record - */ - protected String doIt() throws Exception - { - ArrayList params = new ArrayList(); - String sql = "SELECT p.M_Product_ID FROM M_Product p WHERE p.AD_Client_ID=?"; - params.add(m_AD_Client_ID); - - if (p_M_Product_Category_ID > 0 ) - { - sql += " AND p.M_Product_Category_ID=?"; - params.add(p_M_Product_Category_ID); - } - - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql,get_TrxName()); - DB.setParameters(pstmt, params); - rs = pstmt.executeQuery (); - while (rs.next()) - { - int M_Product_ID = rs.getInt(1); - createPlanning(M_Product_ID); - } - } - catch (SQLException e) - { - throw new DBException(e, sql); - } - finally - { - DB.close(rs, pstmt); - rs = null; - pstmt = null; - } - return "@Created@ #"+count_created - +" @Updated@ #"+count_updated - +" @Error@ #"+count_error; - } - - private void createPlanning(int M_Product_ID) - { - MPPProductPlanning pp = MPPProductPlanning.get(getCtx(),m_AD_Client_ID , m_AD_Org_ID , p_M_Warehouse_ID, p_S_Resource_ID,M_Product_ID, get_TrxName()); - boolean isNew = pp == null; - // Create Product Data Planning - if (pp == null) - { - pp = new MPPProductPlanning(getCtx(), 0, get_TrxName()); - pp.setAD_Org_ID(m_AD_Org_ID); - pp.setM_Warehouse_ID(p_M_Warehouse_ID); - pp.setS_Resource_ID(p_S_Resource_ID); - pp.setM_Product_ID(M_Product_ID); - } - pp.setDD_NetworkDistribution_ID (p_DD_NetworkDistribution_ID); - pp.setAD_Workflow_ID(p_AD_Workflow_ID); - pp.setIsCreatePlan(p_CreatePlan); - pp.setIsMPS(p_MPS); - pp.setIsRequiredMRP(true); - pp.setIsRequiredDRP(true); - pp.setDeliveryTime_Promised(p_DeliveryTime_Promised); - pp.setOrder_Period(p_OrderPeriod); - pp.setPlanner_ID(p_Planner); - pp.setOrder_Policy(p_OrderPolicy); - pp.setSafetyStock(p_SafetyStock); - pp.setOrder_Qty(p_Order_Qty); - pp.setOrder_Min(p_Order_Min); - pp.setOrder_Max(p_Order_Max); - pp.setOrder_Pack(p_Order_Pack); - pp.setTimeFence(p_TimeFence); - pp.setTransfertTime(p_TransferTime); - pp.setIsPhantom(false); - pp.setWorkingTime(p_WorkingTime); - pp.setYield(p_Yield); - // - if (!pp.save()) - count_error++; - if (isNew) - count_created++; - else - count_updated++; - } -} \ No newline at end of file diff --git a/base/src/org/eevolution/process/HRAttributeEmployee.java b/base/src/org/eevolution/process/HRAttributeEmployee.java deleted file mode 100644 index 8184987243..0000000000 --- a/base/src/org/eevolution/process/HRAttributeEmployee.java +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * The contents of this file are subject to the Compiere License Version 1.1 - * ("License"); You may not use this file except in compliance with the License - * You may obtain a copy of the License at http://www.compiere.org/license.html - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for - * the specific language governing rights and limitations under the License. - * The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial - * Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke - * are Copyright (C) 1999-2005 Jorg Janke. - * All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved. - * Contributor(s): ______________________________________. - *****************************************************************************/ -//package org.eevolution.process; -package org.eevolution.process; - -import org.compiere.process.SvrProcess; - -/** - * Create Concept of current Payroll - * - * @author Oscar Gómez Islas - * @version $Id: HRCreateConcept.java,v 1.0 2005/10/24 04:58:38 ogomezi Exp $ - */ -public class HRAttributeEmployee extends SvrProcess -{ - private int p_HR_Payroll_ID = 0; - - /** - * Prepare - */ - protected void prepare () - { - p_HR_Payroll_ID = getRecord_ID(); - } // prepare - - /** - * Process - * @return info - * @throws Exception - */ - protected String doIt () throws Exception - { - return "@OK"; - } // doIt -} // Create Concept of the current Payroll diff --git a/base/src/org/eevolution/process/HRCreateConcept.java b/base/src/org/eevolution/process/HRCreateConcept.java deleted file mode 100644 index 8c43425039..0000000000 --- a/base/src/org/eevolution/process/HRCreateConcept.java +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** - * The contents of this file are subject to the Compiere License Version 1.1 - * ("License"); You may not use this file except in compliance with the License - * You may obtain a copy of the License at http://www.compiere.org/license.html - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for - * the specific language governing rights and limitations under the License. - * The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial - * Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke - * are Copyright (C) 1999-2005 Jorg Janke. - * All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved. - * Contributor(s): ______________________________________. - *****************************************************************************/ -//package org.eevolution.process; -package org.eevolution.process; - -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; -import org.eevolution.model.MHRConcept; -import org.eevolution.model.MHRPayrollConcept; - -/** - * Create Concept of current Payroll - * - * @author Oscar Gómez Islas - * @version $Id: HRCreateConcept.java,v 1.0 2005/10/24 04:58:38 ogomezi Exp $ - * - * @author Cristina Ghita, www.arhipac.ro - */ -public class HRCreateConcept extends SvrProcess -{ - private int p_HR_Payroll_ID = 0; - - /** - * Prepare - */ - protected void prepare () - { - p_HR_Payroll_ID = getRecord_ID(); - } // prepare - - /** - * Process - * @return info - * @throws Exception - */ - protected String doIt () throws Exception - { - int count = 0; - - for(MHRConcept concept : MHRConcept.getConcepts(p_HR_Payroll_ID, 0, 0, null)) - { - int HR_Concept_ID = concept.get_ID(); - if(isPayrollConcept(HR_Concept_ID)) - { - MHRPayrollConcept payrollConcept = new MHRPayrollConcept (concept, p_HR_Payroll_ID); - payrollConcept.set_TrxName(get_TrxName()); - payrollConcept.saveEx(); - count++; - } - } - return "@Created@/@Updated@ #" + count; - } // doIt - - private boolean isPayrollConcept(int HR_Concept_ID) - { - final String sql = "SELECT HR_Concept_ID FROM HR_PayrollConcept WHERE HR_Payroll_ID=? AND HR_Concept_ID=?"; - return DB.getSQLValue(get_TrxName(),sql, p_HR_Payroll_ID, HR_Concept_ID) > 0; - } -} // Create Concept of the current Payroll diff --git a/base/src/org/eevolution/process/HRCreatePeriods.java b/base/src/org/eevolution/process/HRCreatePeriods.java deleted file mode 100644 index cd69d23efe..0000000000 --- a/base/src/org/eevolution/process/HRCreatePeriods.java +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2008 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Oscar Gómez www.e-evolution.com * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ -//package org.eevolution.process; -package org.eevolution.process; - -import org.compiere.process.SvrProcess; -import org.compiere.util.Msg; -import org.eevolution.model.MHRYear; - -/** - * Create Periods of Payroll - * - * @author Oscar Gómez Islas - * @version $Id: HRCreatePeriods.java,v 1.0 2005/10/05 04:58:38 ogomezi Exp $ - */ -public class HRCreatePeriods extends SvrProcess -{ - /** - * Prepare - */ - protected void prepare () - { - } // prepare - - /** - * Process - * @return info - * @throws Exception - */ - protected String doIt () - throws Exception - { - int year_ID = getRecord_ID(); - MHRYear year = new MHRYear (getCtx(), getRecord_ID(), get_TrxName()); - if (year.get_ID() <= 0 || year.get_ID() != year_ID) - return "Year not exist"; - else if(year.isProcessed()) - return "No Created, The Period's exist"; - log.info(year.toString()); - // - if (year.createPeriods()){ - year.setProcessed(true); - year.save(); - return "@OK@ Create Periods"; - } - return Msg.translate(getCtx(), "PeriodNotValid"); - } // doIt -} // YearCreatePeriods diff --git a/base/src/org/eevolution/process/LoadRoles.java b/base/src/org/eevolution/process/LoadRoles.java deleted file mode 100644 index 0ec6162820..0000000000 --- a/base/src/org/eevolution/process/LoadRoles.java +++ /dev/null @@ -1,116 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.process; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.logging.Level; - -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; - - -/** - * LoadRoles - * - * @author Victor Perez, e-Evolution, S.C. - * @version $Id: CreateCost.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ - */ -public class LoadRoles extends SvrProcess -{ - /** */ - - - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - } // prepare - - - protected String doIt() throws Exception - { - - - String sql = "SELECT i.AD_Role_ID, i.AD_Window_ID ,i.AD_Process_ID , i.AD_Form_ID , i.AD_Workflow_ID , i.IsReadWrite , i.IsView FROM I_Role_Access i"; - - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql,get_TrxName()); - ResultSet rs = pstmt.executeQuery (); - - while (rs.next()) - { - int AD_Role_ID = rs.getInt(1); - int AD_Window_ID = rs.getInt(2); - int AD_Process_ID = rs.getInt(3); - int AD_Form_ID = rs.getInt(4); - int AD_Workflow_ID = rs.getInt(5); - - - //System.out.println ("AD_Role_ID:" + AD_Role_ID + "AD_Window_ID:" + AD_Window_ID + "AD_Process_ID:" + AD_Process_ID + "Ad_Form_ID:" + AD_Form_ID); - - if (AD_Window_ID > 0) - { - - String sqlupdate = "UPDATE AD_Window_Access SET IsReadWrite = '" + rs.getString(6) + "', IsActive='" + rs.getString(7) + "' WHERE AD_Window_ID =" +AD_Window_ID + " AND AD_Role_ID ="+ AD_Role_ID; - //System.out.println("SQL AD_Window" + sql); - DB.executeUpdate(sqlupdate, get_TrxName()); - } - else if (AD_Form_ID > 0) - { - - String sqlupdate = "UPDATE AD_Form_Access SET IsReadWrite = '" + rs.getString(6) + "', IsActive = '" + rs.getString(7) + "' WHERE AD_Form_ID =" +AD_Form_ID + " AND AD_Role_ID ="+ AD_Form_ID; - //System.out.println("SQL AD_Form" + sql); - DB.executeUpdate(sqlupdate,get_TrxName()); - - } - else if (AD_Process_ID > 0) - { - - String sqlupdate = "UPDATE AD_Process_Access SET IsReadWrite = '" + rs.getString(6) + "', IsActive = '" +rs.getString(7)+ "' WHERE AD_Process_ID =" +AD_Process_ID + " AND AD_Role_ID ="+ AD_Role_ID; - //System.out.println("SQL AD_Process" + sql); - DB.executeUpdate(sqlupdate, get_TrxName()); - - } - else if (AD_Workflow_ID > 0) - { - - String sqlupdate = "UPDATE AD_Workflow_Access SET IsReadWrite = '" + rs.getString(6) + "', IsActive = '" +rs.getString(7)+ "' WHERE AD_Workflow_ID =" + AD_Workflow_ID + " AND AD_Role_ID ="+ AD_Role_ID; - //System.out.println("SQL AD_Process" + sql); - DB.executeUpdate(sqlupdate, get_TrxName()); - - } - } - - rs.close(); - pstmt.close(); - - } - catch (Exception e) - { - log.log(Level.SEVERE,"doIt - " + sql, e); - } - - return "ok"; - } -} diff --git a/base/src/org/eevolution/process/MRP.java b/base/src/org/eevolution/process/MRP.java deleted file mode 100644 index a611cc656c..0000000000 --- a/base/src/org/eevolution/process/MRP.java +++ /dev/null @@ -1,1273 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ - -package org.eevolution.process; - - -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Level; - -import org.adempiere.exceptions.AdempiereException; -import org.adempiere.exceptions.DBException; -import org.compiere.model.MBPartner; -import org.compiere.model.MDocType; -import org.compiere.model.MLocator; -import org.compiere.model.MMessage; -import org.compiere.model.MNote; -import org.compiere.model.MOrg; -import org.compiere.model.MProduct; -import org.compiere.model.MProductPO; -import org.compiere.model.MRequisition; -import org.compiere.model.MRequisitionLine; -import org.compiere.model.MResource; -import org.compiere.model.MStorage; -import org.compiere.model.MWarehouse; -import org.compiere.model.PO; -import org.compiere.model.POResultSet; -import org.compiere.model.Query; -import org.compiere.process.DocAction; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.CCache; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.compiere.util.TimeUtil; -import org.compiere.util.Util; -import org.compiere.wf.MWorkflow; -import org.eevolution.model.I_PP_Product_Planning; -import org.eevolution.model.MDDNetworkDistribution; -import org.eevolution.model.MDDNetworkDistributionLine; -import org.eevolution.model.MDDOrder; -import org.eevolution.model.MDDOrderLine; -import org.eevolution.model.MPPMRP; -import org.eevolution.model.MPPOrder; -import org.eevolution.model.MPPProductBOM; -import org.eevolution.model.MPPProductPlanning; -import org.eevolution.model.X_PP_Product_Planning; -/** - * Calculate Material Plan MRP - * - * @author Victor Perez, e-Evolution, S.C. - * @author Teo Sarca, www.arhipac.ro - */ -public class MRP extends SvrProcess -{ - private int p_AD_Org_ID = 0; - private int p_S_Resource_ID = 0; - private int p_M_Warehouse_ID= 0; - private boolean p_IsRequiredDRP = false; - private int p_Planner_ID = 0; - @SuppressWarnings("unused") - private String p_Version = "1"; - /** Product ID - for testing purposes */ - protected int p_M_Product_ID = 0; - - // Global Variables - private I_PP_Product_Planning m_product_planning = null; - private BigDecimal QtyProjectOnHand = Env.ZERO; - private BigDecimal QtyGrossReqs = Env.ZERO; - private BigDecimal QtyScheduledReceipts = Env.ZERO; - private Timestamp DatePromisedFrom = null; - private Timestamp DatePromisedTo = null; - private Timestamp Today = new Timestamp (System.currentTimeMillis()); - private Timestamp TimeFence = null; - private Timestamp Planning_Horizon = null; - // Document Types - private int docTypeReq_ID = 0; - private int docTypeMO_ID = 0; - private int docTypeDO_ID = 0; - // Statistics - private int count_MO = 0; - private int count_MR = 0; - private int count_DO = 0; - private int count_Msg = 0; - // Cache - private static CCache dd_order_id_cache = new CCache(MDDOrder.COLUMNNAME_DD_Order_ID, 50); - private static CCache partner_cache = new CCache(MBPartner.Table_Name, 50); - - - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) - ; - else if (name.equals("AD_Org_ID")) - { - p_AD_Org_ID = para[i].getParameterAsInt(); - } - else if (name.equals("S_Resource_ID")) - { - p_S_Resource_ID = para[i].getParameterAsInt(); - } - else if (name.equals("M_Warehouse_ID")) - { - p_M_Warehouse_ID = para[i].getParameterAsInt(); - } - else if (name.equals("IsRequiredDRP")) - { - p_IsRequiredDRP = para[i].getParameterAsBoolean(); - } - else if (name.equals("Version")) - { - p_Version = (String)para[i].getParameter(); - } - else - log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); - } - } // prepare - - /** - * @return the p_AD_Org_ID - */ - public int getAD_Org_ID() - { - return p_AD_Org_ID; - } - - /** - * @return the p_S_Resource_ID - */ - public int getPlant_ID() - { - return p_S_Resource_ID; - } - - /** - * @return the M_Warehouse_ID - */ - public int getM_Warehouse_ID() - { - return p_M_Warehouse_ID; - } - - /** - * @return the p_IsRequiredDRP - */ - public boolean isRequiredDRP() - { - return p_IsRequiredDRP; - } - - public int getPlanner_ID() - { - if (this.p_Planner_ID <= 0) - { - this.p_Planner_ID = Env.getAD_User_ID(getCtx()); - } - return this.p_Planner_ID; - } - - protected String doIt() throws Exception - { - StringBuffer resultMsg = new StringBuffer(); - - // Set Default Document Type To Requisition - docTypeReq_ID = getDocType(MDocType.DOCBASETYPE_PurchaseRequisition); - docTypeMO_ID = getDocType(MDocType.DOCBASETYPE_ManufacturingOrder); - docTypeDO_ID = getDocType(MDocType.DOCBASETYPE_DistributionOrder); - - ArrayList parameters = new ArrayList(); - StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType+"=? AND AD_Client_ID=?"); - parameters.add(MResource.MANUFACTURINGRESOURCETYPE_Plant); - parameters.add(getAD_Client_ID()); - if (getPlant_ID() > 0) - { - whereClause.append(" AND "+MResource.COLUMNNAME_S_Resource_ID+"=?"); - parameters.add(getPlant_ID()); - } - List plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(parameters) - .list(); - for(MResource plant : plants) - { - log.info("Run MRP to Plant: " + plant.getName()); - this.Planning_Horizon = TimeUtil.addDays(getToday(), plant.getPlanningHorizon()); - parameters = new ArrayList(); - whereClause = new StringBuffer("AD_Client_ID=?"); - parameters.add(getAD_Client_ID()); - - if (getAD_Org_ID() > 0) - { - whereClause.append(" AND AD_Org_ID=?"); - parameters.add(getAD_Org_ID()); - } - - - List orgList = new Query(getCtx(),MOrg.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(parameters) - .list(); - - for (MOrg org : orgList) - { - log.info("Run MRP to Organization: " + org.getName()); - MWarehouse[] ws; - if(getM_Warehouse_ID() <= 0) - { - ws = MWarehouse.getForOrg(getCtx(), org.getAD_Org_ID()); - } - else - { - ws = new MWarehouse[]{MWarehouse.get(getCtx(), getM_Warehouse_ID())}; - } - // - for(MWarehouse w : ws) - { - if(plant.getM_Warehouse_ID() == w.getM_Warehouse_ID() && isRequiredDRP()) - continue; - - log.info("Run MRP to Wharehouse: " + w.getName()); - runMRP(getAD_Client_ID(), org.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID()); - resultMsg.append("
finish MRP to Warehouse " +w.getName()); - } - resultMsg.append("
finish MRP to Organization " +org.getName()); - } - resultMsg.append("
" +Msg.translate(getCtx(), "Created")); - resultMsg.append("
"); - resultMsg.append("
" +Msg.translate(getCtx(), "PP_Order_ID")+":"+count_MO); - resultMsg.append("
" +Msg.translate(getCtx(), "DD_Order_ID")+":"+count_DO); - resultMsg.append("
" +Msg.translate(getCtx(), "M_Requisition_ID")+":"+count_MR); - resultMsg.append("
" +Msg.translate(getCtx(), "AD_Note_ID")+":"+count_Msg); - resultMsg.append("
finish MRP to Plant " +plant.getName()); - } - // - return resultMsg.toString(); - } - - - /************************************************************************** - * Delete old record in MRP table to calculate again MRP and Document with Draft status - * @param AD_Client_ID Client_ID - * @param AD_Org_ID Orgganization ID - * @param M_Warehouse_ID Warehouse ID - */ - protected void deleteMRP(int AD_Client_ID, int AD_Org_ID,int S_Resource_ID, int M_Warehouse_ID) - { - // Delete Manufacturing Order with Close Status from MRP Table - String sql = "DELETE FROM PP_MRP WHERE OrderType = 'MOP' AND DocStatus ='CL' AND AD_Client_ID=" + AD_Client_ID + " AND AD_Org_ID=" + AD_Org_ID + " AND M_Warehouse_ID="+M_Warehouse_ID + " AND S_Resource_ID="+S_Resource_ID ; - DB.executeUpdateEx(sql, get_TrxName()); - commit(); - //Delete Manufacturing Order with Draft Status - String whereClause = "DocStatus='DR' AND AD_Client_ID=? AND AD_Org_ID=? AND M_Warehouse_ID=? AND S_Resource_ID=?"; - deletePO(MPPOrder.Table_Name, whereClause, new Object[]{AD_Client_ID, AD_Org_ID, M_Warehouse_ID, S_Resource_ID}); - - // Delete Requisition with Status Close from MRP Table - sql = "DELETE FROM PP_MRP WHERE OrderType = 'POR' AND DocStatus IN ('CL','DR') AND AD_Client_ID = " + AD_Client_ID + " AND AD_Org_ID=" + AD_Org_ID+ " AND M_Warehouse_ID="+M_Warehouse_ID; - DB.executeUpdateEx(sql, get_TrxName()); - commit(); - //Delete Requisition with Draft Status - whereClause = "DocStatus IN ('CL','DR') AND AD_Client_ID=? AND AD_Org_ID=? AND M_Warehouse_ID=?"; - deletePO(MRequisition.Table_Name, whereClause, new Object[]{AD_Client_ID, AD_Org_ID, M_Warehouse_ID}); - - // Delete Action Notice - sql = "DELETE FROM AD_Note WHERE AD_Table_ID=? AND AD_Client_ID=? AND AD_Org_ID=?"; - DB.executeUpdateEx(sql, new Object[]{MPPMRP.Table_ID, AD_Client_ID, AD_Org_ID}, get_TrxName()); - commit(); - - if (isRequiredDRP()) - { - //Delete Distribution Order with Draft Status - whereClause = "DocStatus='DR' AND AD_Client_ID=? AND AD_Org_ID=?" - +" AND EXISTS (SELECT 1 FROM DD_OrderLine ol INNER JOIN M_Locator l ON (l.M_Locator_ID=ol.M_LocatorTo_ID) " - +" WHERE ol.DD_Order_ID=DD_Order.DD_Order_ID AND l.M_Warehouse_ID=?)"; - deletePO(MDDOrder.Table_Name, whereClause, new Object[]{AD_Client_ID, AD_Org_ID, M_Warehouse_ID}); - } - - // Mark all supply MRP records as available - DB.executeUpdateEx("UPDATE PP_MRP SET IsAvailable ='Y' WHERE TypeMRP = 'S' AND AD_Client_ID = ? AND AD_Org_ID=? AND M_Warehouse_ID=?", new Object[]{AD_Client_ID,AD_Org_ID,M_Warehouse_ID} ,get_TrxName()); - commit(); - } - - /************************************************************************** - * Calculate plan - * @param AD_Client_ID Client ID - * @param AD_Org_ID Organization ID - * @param M_Warehuse_ID Warehouse ID - */ - protected String runMRP(int AD_Client_ID , int AD_Org_ID, int S_Resource_ID , int M_Warehouse_ID) - { - deleteMRP(AD_Client_ID,AD_Org_ID,S_Resource_ID,M_Warehouse_ID); - - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - MProduct product = null; - - int BeforePP_MRP_ID = 0; - Timestamp BeforeDateStartSchedule = null; - Timestamp POQDateStartSchedule = null; - - int lowlevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName()); - log.info("Low Level Is :"+lowlevel); - // Calculate MRP for all levels - for (int level = 0 ; level <= lowlevel ; level++) - { - log.info("Current Level Is :" + level); - String sql = "SELECT p.M_Product_ID, p.Name, p.LowLevel, mrp.Qty, mrp.DatePromised" - + ", mrp.TypeMRP, mrp.OrderType, mrp.DateOrdered, mrp.M_Warehouse_ID" - + ", mrp.PP_MRP_ID, mrp.DateStartSchedule, mrp.DateFinishSchedule" - +" FROM PP_MRP mrp" - +" INNER JOIN M_Product p ON (p.M_Product_ID = mrp.M_Product_ID)" - +" WHERE mrp.TypeMRP=?" - +" AND mrp.AD_Client_ID=?" - +" AND mrp.AD_Org_ID=? " - +" AND M_Warehouse_ID=? " - +" AND mrp.DatePromised<=?" - +" AND COALESCE(p.LowLevel,0)=? " - +(p_M_Product_ID > 0 ? " AND mrp.M_Product_ID="+p_M_Product_ID : "") - +" ORDER BY mrp.M_Product_ID , mrp.DatePromised"; - pstmt = DB.prepareStatement (sql, get_TrxName()); - pstmt.setString(1, MPPMRP.TYPEMRP_Demand); - pstmt.setInt(2, AD_Client_ID); - pstmt.setInt(3, AD_Org_ID); - pstmt.setInt(4, M_Warehouse_ID); - pstmt.setTimestamp(5, Planning_Horizon); - pstmt.setInt(6, level); - rs = pstmt.executeQuery(); - while (rs.next()) - { - final int PP_MRP_ID = rs.getInt(MPPMRP.COLUMNNAME_PP_MRP_ID); - final String TypeMRP = rs.getString(MPPMRP.COLUMNNAME_TypeMRP); - final String OrderType = rs.getString(MPPMRP.COLUMNNAME_OrderType); - final Timestamp DatePromised = rs.getTimestamp(MPPMRP.COLUMNNAME_DatePromised); - final Timestamp DateStartSchedule = rs.getTimestamp(MPPMRP.COLUMNNAME_DateStartSchedule); - final BigDecimal Qty = rs.getBigDecimal(MPPMRP.COLUMNNAME_Qty); - final int M_Product_ID = rs.getInt(MPPMRP.COLUMNNAME_M_Product_ID); - - //MRP-150 - //Past Due Demand - //Indicates that a demand order is past due. - if(DatePromised.compareTo(getToday()) < 0) - { - String comment = Msg.translate(getCtx(), MPPOrder.COLUMNNAME_DatePromised) - + ": " + DatePromised; - createMRPNote("MRP-150", AD_Org_ID, PP_MRP_ID, product, MPPMRP.getDocumentNo(PP_MRP_ID), - Qty, comment); - } - - // if demand is a forecast and this is minor today then is ignore this QtyGrossReq - if (MPPMRP.TYPEMRP_Demand.equals(TypeMRP) - && MPPMRP.ORDERTYPE_Forecast.equals(OrderType) - && DatePromised.compareTo(getToday()) <= 0) - { - continue; - } - - // New Product - if (product == null || product.get_ID() != M_Product_ID) - { - product = MProduct.get(getCtx(), M_Product_ID); - log.info("Calculte Plan to this Product:" + product.getName()); - - //if exist QtyGrossReq of last Demand verify plan - if (QtyGrossReqs.signum() != 0) - { - if (X_PP_Product_Planning.ORDER_POLICY_PeriodOrderQuantity.equals(m_product_planning.getOrder_Policy()) && POQDateStartSchedule.compareTo(Planning_Horizon) < 0) - { - BeforeDateStartSchedule = POQDateStartSchedule; - calculatePlan(AD_Client_ID, AD_Org_ID,M_Warehouse_ID ,BeforePP_MRP_ID , product ,BeforeDateStartSchedule); - } - else if (X_PP_Product_Planning.ORDER_POLICY_LoteForLote.equals(m_product_planning.getOrder_Policy()) && BeforeDateStartSchedule.compareTo(Planning_Horizon) <= 0 ) - { - calculatePlan(AD_Client_ID, AD_Org_ID,M_Warehouse_ID ,BeforePP_MRP_ID , product ,BeforeDateStartSchedule ); - } - QtyGrossReqs = Env.ZERO; - } - - - // Define m_product_planning - setProduct(AD_Client_ID,AD_Org_ID ,S_Resource_ID , M_Warehouse_ID, product); - - // If No Product Planning found, go to next MRP record - if (m_product_planning == null) - continue; - - //first DatePromised.compareTo for ORDER_POLICY_PeriodOrderQuantity - if (X_PP_Product_Planning.ORDER_POLICY_PeriodOrderQuantity.equals(m_product_planning.getOrder_Policy())) - { - DatePromisedFrom = DatePromised; - DatePromisedTo = TimeUtil.addDays(DatePromised , m_product_planning.getOrder_Period().intValue()); - //set the POQDateStartSchedule && POQDateStartSchedule to first period - //POQDateStartSchedule = (level == 0 ? DatePromised : DateStartSchedule); - POQDateStartSchedule = DatePromised; - } - } // new product - - // If No Product Planning found, go to next MRP record - if (m_product_planning == null) - continue; - - BeforePP_MRP_ID = PP_MRP_ID; - - if (X_PP_Product_Planning.ORDER_POLICY_PeriodOrderQuantity.equals(m_product_planning.getOrder_Policy())) - { - // Verify if is DatePromised < DatePromisedTo then Accumulation QtyGrossReqs - if (DatePromisedTo != null && DatePromised.compareTo(DatePromisedTo) < 0) - { - QtyGrossReqs = QtyGrossReqs.add(Qty); - log.info("Accumulation QtyGrossReqs:" + QtyGrossReqs); - log.info("DatePromised:" + DatePromised); - log.info("DatePromisedTo:" + DatePromisedTo); - continue; - } - else - { // if not then create new range for next period - BeforeDateStartSchedule = POQDateStartSchedule; - calculatePlan(AD_Client_ID,AD_Org_ID,M_Warehouse_ID,PP_MRP_ID,product ,BeforeDateStartSchedule); - QtyGrossReqs = Qty; - DatePromisedFrom = DatePromised; - DatePromisedTo = TimeUtil.addDays(DatePromised, m_product_planning.getOrder_Period().intValue()); - POQDateStartSchedule = (level == 0 ? DatePromised : DateStartSchedule); - continue; - } - } - // If Order_Policy = LoteForLote then always create new range for next period and put QtyGrossReqs - else if (X_PP_Product_Planning.ORDER_POLICY_LoteForLote.equals(m_product_planning.getOrder_Policy())) - { - QtyGrossReqs = Qty; - BeforeDateStartSchedule = DatePromised; - calculatePlan(AD_Client_ID, AD_Org_ID,M_Warehouse_ID,PP_MRP_ID,product,BeforeDateStartSchedule); - continue; - } - } // end while - - //if exist QtyGrossReq of last Demand after finish while verify plan - if (QtyGrossReqs.signum() != 0 && product != null) - { - if (X_PP_Product_Planning.ORDER_POLICY_PeriodOrderQuantity.equals(m_product_planning.getOrder_Policy()) - && POQDateStartSchedule.compareTo(Planning_Horizon) < 0) - { - BeforeDateStartSchedule = POQDateStartSchedule; - calculatePlan(AD_Client_ID,AD_Org_ID,M_Warehouse_ID,BeforePP_MRP_ID , product ,BeforeDateStartSchedule); - } - else if (X_PP_Product_Planning.ORDER_POLICY_LoteForLote.equals(m_product_planning.getOrder_Policy()) - && BeforeDateStartSchedule.compareTo(Planning_Horizon) <= 0 ) - { - calculatePlan(AD_Client_ID,AD_Org_ID,M_Warehouse_ID,BeforePP_MRP_ID , product ,BeforeDateStartSchedule ); - } - - } - else if (product != null) - { - //Create Action Notice if exist supply - getNetRequierements( - AD_Client_ID, - AD_Org_ID, - M_Warehouse_ID, - product, - null); - } - - DB.close(rs, pstmt); - } // end for - } // try - catch (SQLException ex) - { - throw new DBException(ex); - } - finally { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - - return "ok"; - } - - /************************************************************************** - * Define the product to calculate plan - * @param AD_Client_ID Client ID - * @param AD_Org_ID Organization ID - * @param M_Warehuse_ID Warehouse ID - * @param MProduct - */ - private void setProduct(int AD_Client_ID , int AD_Org_ID, int S_Resource_ID , int M_Warehouse_ID, MProduct product) - { - DatePromisedTo = null; - DatePromisedFrom = null; - // - // Find data product planning demand - m_product_planning = getProductPlanning(AD_Client_ID, AD_Org_ID, S_Resource_ID, M_Warehouse_ID, product); - if (m_product_planning == null) - { - createMRPNote("MRP-120", AD_Org_ID, 0, product, null, null , null); - return; - } - - if(m_product_planning.getTimeFence().signum() > 0) - { - TimeFence = TimeUtil.addDays(getToday(), m_product_planning.getTimeFence().intValue()); - } - - QtyProjectOnHand = getQtyOnHand(m_product_planning); - if(QtyProjectOnHand.signum() < 0) - { - String comment = Msg.translate(getCtx(), MStorage.COLUMNNAME_QtyOnHand) - + ": " + QtyProjectOnHand; - //MRP-140 - //Beginning Quantity Less Than Zero - //Indicates that the quantity on hand is negative. - createMRPNote("MRP-140", AD_Org_ID, 0, product , null , QtyProjectOnHand , comment); - } - - // Quantity Project On hand 100 - // Safety Stock 150 - // 150 > 100 The Quantity Project On hand is now 50 - if(m_product_planning.getSafetyStock().signum() > 0 - && m_product_planning.getSafetyStock().compareTo(QtyProjectOnHand) > 0) - { - String comment = Msg.translate(getCtx(), MStorage.COLUMNNAME_QtyOnHand) - + ": " + QtyProjectOnHand - + " " + Msg.translate(getCtx(), I_PP_Product_Planning.COLUMNNAME_SafetyStock) - + ": " + m_product_planning.getSafetyStock(); - createMRPNote("MRP-001", AD_Org_ID, 0, product , null , QtyProjectOnHand , comment); - QtyProjectOnHand = QtyProjectOnHand.subtract(m_product_planning.getSafetyStock()); - } - log.info("QtyOnHand :" + QtyProjectOnHand); - - } - - protected I_PP_Product_Planning getProductPlanning(int AD_Client_ID , int AD_Org_ID, int S_Resource_ID , int M_Warehouse_ID, MProduct product) - { - // Find data product planning demand - MPPProductPlanning pp = MPPProductPlanning.find(getCtx() ,AD_Org_ID , M_Warehouse_ID, S_Resource_ID , product.getM_Product_ID(), get_TrxName()); - if (pp == null) - { - return null; - } - MPPProductPlanning pp2 = new MPPProductPlanning(getCtx(), 0 , null); - MPPProductPlanning.copyValues(pp, pp2); - pp2.setIsRequiredDRP(isRequiredDRP()); - // - if (pp2.getPP_Product_BOM_ID() <= 0 && product.isBOM()) - { - pp2.setPP_Product_BOM_ID(MPPProductBOM.getBOMSearchKey(product)); - } - if (pp2.getAD_Workflow_ID() <= 0 && product.isBOM()) - { - pp2.setAD_Workflow_ID(MWorkflow.getWorkflowSearchKey(product)); - } - if (pp2.getPlanner_ID() <= 0) - { - pp2.setPlanner_ID(getPlanner_ID()); - } - if(pp2.getM_Warehouse_ID() <= 0) - { - pp2.setM_Warehouse_ID(M_Warehouse_ID); - } - if (pp2.getS_Resource_ID() <= 0) - { - pp2.setS_Resource_ID(S_Resource_ID); - } - if (pp2.getOrder_Policy() == null) - { - pp2.setOrder_Policy(X_PP_Product_Planning.ORDER_POLICY_LoteForLote); - } - - //Find Vendor - if (!isRequiredDRP()) - { - if(product.isPurchased()) - { - int C_BPartner_ID = 0; - MProductPO[] ppos = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), get_TrxName()); - for (int i = 0; i < ppos.length; i++) - { - if (ppos[i].isCurrentVendor() && ppos[i].getC_BPartner_ID() != 0) - { - C_BPartner_ID = ppos[i].getC_BPartner_ID(); - pp2.setDeliveryTime_Promised(BigDecimal.valueOf(ppos[i].getDeliveryTime_Promised())); - pp2.setOrder_Min(ppos[i].getOrder_Min()); - pp2.setOrder_Max(Env.ZERO); - pp2.setOrder_Pack(ppos[i].getOrder_Pack()); - break; - } - } - if(C_BPartner_ID <= 0) - { - createMRPNote("MRP-130", AD_Org_ID, 0, product, null, null , null); - pp2.setIsCreatePlan(false); - } - } - if (product.isBOM()) - { - if (pp2.getAD_Workflow_ID() <= 0) - log.info("Error: Do not exist workflow ("+product.getValue()+")"); - } - } - // - return pp2; - } - - protected BigDecimal getQtyOnHand(I_PP_Product_Planning pp) - { - return MPPMRP.getQtyOnHand(getCtx(), pp.getM_Warehouse_ID() , pp.getM_Product_ID(), get_TrxName()); - } - - protected Timestamp getToday() - { - return this.Today; - } - - /************************************************************************** - * Calculate Plan this product - * @param PP_MRP_ID MRP ID - * @param M_Warehouse_ID Warehoue ID - * @param product Product - * @param DemandDateStartSchedule Demand Date Start Schedule - */ - private void calculatePlan(int AD_Client_ID, int AD_Org_ID, int M_Warehouse_ID, int PP_MRP_ID, - MProduct M_Product, Timestamp DemandDateStartSchedule) - { - //Set Yield o QtyGrossReqs - // Note : the variables DemandDateStartSchedule , DemandDateFinishSchedule are same DatePromised to Demands Sales Order Type - - log.info("Create Plan ..."); - - BigDecimal DecimalYield = new BigDecimal(m_product_planning.getYield()/100); - if (DecimalYield.signum() != 0) - QtyGrossReqs = QtyGrossReqs.divide(DecimalYield, 4, BigDecimal.ROUND_HALF_UP); - - BigDecimal QtyNetReqs = getNetRequierements( - AD_Client_ID, - AD_Org_ID, - M_Warehouse_ID, - M_Product, - DemandDateStartSchedule); - - BigDecimal QtyPlanned = Env.ZERO; - - ((PO)m_product_planning).dump(); - log.info(" Product:" + M_Product.getName()); - log.info(" Demand Date Start Schedule:" + DemandDateStartSchedule); - log.info(" DatePromisedFrom:" + DatePromisedFrom + " DatePromisedTo:" + DatePromisedTo); - log.info(" Qty Planned:" + QtyPlanned); - log.info(" Qty Scheduled Receipts:" + QtyScheduledReceipts); - log.info(" QtyProjectOnHand:" + QtyProjectOnHand); - log.info(" QtyGrossReqs:" + QtyGrossReqs); - log.info(" Supply:" + (QtyScheduledReceipts).add(QtyProjectOnHand)); - log.info(" QtyNetReqs:" + QtyNetReqs); - - if (QtyNetReqs.signum() > 0) - { // entire qty is available or scheduled to receipt - QtyProjectOnHand = QtyNetReqs; - QtyNetReqs = Env.ZERO; - QtyScheduledReceipts = Env.ZERO; - QtyPlanned = Env.ZERO; - QtyGrossReqs = Env.ZERO; - return; - } - else - { - QtyPlanned = QtyNetReqs.negate(); - QtyGrossReqs = Env.ZERO; - QtyScheduledReceipts = Env.ZERO; - } - - // ***** Order Modifier ******** - // Check Order Min - if(QtyPlanned.signum() > 0 && m_product_planning.getOrder_Min().signum() > 0) - { - if (m_product_planning.getOrder_Min().compareTo(QtyPlanned) > 0) - { - String comment = Msg.translate(getCtx(), I_PP_Product_Planning.COLUMNNAME_Order_Min) - + ":" + m_product_planning.getOrder_Min(); - createMRPNote("MRP-080", AD_Org_ID, PP_MRP_ID, M_Product , null, QtyPlanned, comment); - } - QtyPlanned = QtyPlanned.max(m_product_planning.getOrder_Min()); - } - - // Check Order Max - if(QtyPlanned.compareTo(m_product_planning.getOrder_Max()) > 0 && m_product_planning.getOrder_Max().signum() > 0) - { - String comment = Msg.translate(getCtx(), I_PP_Product_Planning.COLUMNNAME_Order_Max) - + ":" + m_product_planning.getOrder_Max(); - createMRPNote("MRP-090", AD_Org_ID, PP_MRP_ID, M_Product , null , QtyPlanned , comment); - } - // Check Order Pack - if (m_product_planning.getOrder_Pack().signum() > 0 && QtyPlanned.signum() > 0) - { - QtyPlanned = m_product_planning.getOrder_Pack().multiply(QtyPlanned.divide(m_product_planning.getOrder_Pack(), 0 , BigDecimal.ROUND_UP)); - } - - QtyProjectOnHand = QtyPlanned.add(QtyNetReqs); - - log.info("QtyNetReqs:" + QtyNetReqs); - log.info("QtyPlanned:" + QtyPlanned); - log.info("QtyProjectOnHand:" + QtyProjectOnHand); - - //MRP-100 Time Fence Conflict Action Notice - //Indicates that there is an unsatisfied material requirement inside the planning time fence for this product. - //You should either manually schedule and expedite orders to fill this demand or delay fulfillment of the requirement that created the demand. - if(TimeFence != null && DemandDateStartSchedule.compareTo(TimeFence) < 0) - { - String comment = Msg.translate(getCtx(), I_PP_Product_Planning.COLUMNNAME_TimeFence) - + ":" + m_product_planning.getTimeFence() - + "-" - + Msg.getMsg(getCtx(), "Date") - + ":" + TimeFence + " " - + Msg.translate(getCtx(), MPPOrder.COLUMNNAME_DatePromised) - + ":" + DemandDateStartSchedule; - createMRPNote("MRP-100", AD_Org_ID, PP_MRP_ID, M_Product , null , QtyPlanned , comment); - } - - if (m_product_planning.isCreatePlan() == false && QtyPlanned.signum() > 0) - { - createMRPNote("MRP-020", AD_Org_ID, PP_MRP_ID, M_Product , null , QtyPlanned , null); - return; - } - - if (QtyPlanned.signum() > 0) - { - int loops = 1; - if (m_product_planning.getOrder_Policy().equals(X_PP_Product_Planning.ORDER_POLICY_FixedOrderQuantity)) - { - if (m_product_planning.getOrder_Qty().compareTo(Env.ZERO) != 0) - loops = (QtyPlanned.divide(m_product_planning.getOrder_Qty() , 0 , BigDecimal.ROUND_UP)).intValue(); - QtyPlanned = m_product_planning.getOrder_Qty(); - } - - for (int ofq = 1 ; ofq <= loops ; ofq ++ ) - { - log.info("Is Purchased: "+ M_Product.isPurchased()+ " Is BOM: " + M_Product.isBOM()); - - // Distribution Order - if(isRequiredDRP() && m_product_planning.getDD_NetworkDistribution_ID() > 0) - { - createDDOrder(AD_Org_ID, PP_MRP_ID, M_Product, QtyPlanned, DemandDateStartSchedule); - } - // Requisition - else if (M_Product.isPurchased()) // then create M_Requisition - { - createRequisition(AD_Org_ID,PP_MRP_ID, M_Product, QtyPlanned ,DemandDateStartSchedule); - } - // Manufacturing Order - else if (M_Product.isBOM()) - { - createPPOrder(AD_Org_ID,PP_MRP_ID, M_Product,QtyPlanned, DemandDateStartSchedule); - } - else - { - // TODO: throw error ? - } - } // end for oqf - } - else - { - log.info("No Create Plan"); - } - } - - protected void createDDOrder(int AD_Org_ID, int PP_MRP_ID, MProduct product,BigDecimal QtyPlanned ,Timestamp DemandDateStartSchedule) - { - //TODO vpj-cd I need to create logic for DRP-040 Shipment Due Action Notice - //Indicates that a shipment for a Order Distribution is due. - // Action should be taken at the source warehouse to ensure that the order is received on time. - - //TODO vpj-cd I need to create logic for DRP-050 Shipment Pas Due Action Notice - //Indicates that a shipment for a Order Distribution is past due. You should either delay the orders created the requirement for the product - //or expedite them when the product does arrive. - - if(m_product_planning.getDD_NetworkDistribution_ID() == 0) - { - //Indicates that the Product Planning Data for this product does not specify a valid network distribution. - createMRPNote("DRP-060", AD_Org_ID, PP_MRP_ID, product , null , null , null); - } - MDDNetworkDistribution network = MDDNetworkDistribution.get(getCtx(),m_product_planning.getDD_NetworkDistribution_ID()); - MDDNetworkDistributionLine[] network_lines = network.getLines(m_product_planning.getM_Warehouse_ID()); - int M_Shipper_ID = 0; - MDDOrder order = null; - Integer DD_Order_ID = 0; - - for (MDDNetworkDistributionLine network_line : network_lines) - { - //get supply source warehouse and locator - MWarehouse source = MWarehouse.get(getCtx(), network_line.getM_WarehouseSource_ID()); - MLocator locator = source.getDefaultLocator(); - - //get supply target warehouse and locator - MWarehouse target = MWarehouse.get(getCtx(), network_line.getM_Warehouse_ID()); - MLocator locator_to =target.getDefaultLocator(); - //get the transfer time - BigDecimal transfertTime = network_line.getTransfertTime(); - if(transfertTime.compareTo(Env.ZERO) <= 0) - { - transfertTime = m_product_planning.getTransfertTime(); - } - - if (locator == null || locator_to == null) - { - String comment = Msg.translate(getCtx(), MDDNetworkDistributionLine.COLUMNNAME_M_WarehouseSource_ID) - + ":" + source.getName(); - createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product , null , null , comment); - continue; - } - //get the warehouse in transit - MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), source.getAD_Org_ID()); - - if (wsts == null) - { - - String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) - + ":" + MOrg.get(getCtx(), AD_Org_ID).getName(); - createMRPNote("DRP-010", AD_Org_ID, PP_MRP_ID, product , null , null , comment); - continue; - } - - if(network_line.getM_Shipper_ID()==0) - { - String comment = Msg.translate(getCtx(), MDDNetworkDistribution.COLUMNNAME_Name) - + ":" + network.getName(); - createMRPNote("DRP-030", AD_Org_ID, PP_MRP_ID, product , null , null , comment); - continue; - } - - if(M_Shipper_ID != network_line.getM_Shipper_ID()) - { - - //Org Must be linked to BPartner - MOrg org = MOrg.get(getCtx(), locator_to.getAD_Org_ID()); - int C_BPartner_ID = org.getLinkedC_BPartner_ID(get_TrxName()); - if (C_BPartner_ID == 0) - { - String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) - + ":" + MOrg.get(getCtx(), AD_Org_ID).getName(); - createMRPNote("DRP-020", AD_Org_ID, PP_MRP_ID, product, null , null , comment); - continue; - } - - MBPartner bp = getBPartner(C_BPartner_ID); - // Try found some order with Shipper , Business Partner and Doc Status = Draft - // Consolidate the demand in a single order for each Shipper , Business Partner , DemandDateStartSchedule - DD_Order_ID = getDDOrder_ID(AD_Org_ID,wsts[0].get_ID(),network_line.getM_Shipper_ID(), bp.getC_BPartner_ID(),DemandDateStartSchedule); - if (DD_Order_ID < 0) - { - order = new MDDOrder(getCtx() , 0 , get_TrxName()); - order.setAD_Org_ID(target.getAD_Org_ID()); - order.setC_BPartner_ID(C_BPartner_ID); - //order.setAD_User_ID(bp.getPrimaryAD_User_ID()); - order.setAD_User_ID(m_product_planning.getPlanner_ID()); - order.setC_DocType_ID(docTypeDO_ID); - order.setM_Warehouse_ID(wsts[0].get_ID()); - order.setDocAction(MDDOrder.DOCACTION_Complete); - order.setDateOrdered(getToday()); - order.setDatePromised(DemandDateStartSchedule); - order.setM_Shipper_ID(network_line.getM_Shipper_ID()); - order.setIsInDispute(false); - order.setIsInTransit(false); - //order.setSalesRep_ID(m_product_planning.getPlanner_ID()); - order.setSalesRep_ID(bp.getPrimaryAD_User_ID()); - order.saveEx(); - DD_Order_ID = order.get_ID(); - String key = network_line.getM_Shipper_ID()+"#"+C_BPartner_ID+"#"+DemandDateStartSchedule+"DR"; - dd_order_id_cache.put(key,DD_Order_ID); - } - M_Shipper_ID = network_line.getM_Shipper_ID(); - } - - BigDecimal QtyOrdered = QtyPlanned.multiply(network_line.getPercent()).divide(Env.ONEHUNDRED); - - MDDOrderLine oline = new MDDOrderLine(getCtx(), 0 , get_TrxName()); - oline.setDD_Order_ID(DD_Order_ID); - oline.setM_Locator_ID(locator.getM_Locator_ID()); - oline.setM_LocatorTo_ID(locator_to.getM_Locator_ID()); - oline.setM_Product_ID(m_product_planning.getM_Product_ID()); - oline.setDateOrdered(getToday()); - oline.setDatePromised(DemandDateStartSchedule); - oline.setQtyEntered(QtyOrdered); - oline.setQtyOrdered(QtyOrdered); - oline.setTargetQty(MPPMRP.getQtyReserved(getCtx(), target.getM_Warehouse_ID(), m_product_planning.getM_Product_ID(), DemandDateStartSchedule, get_TrxName())); - oline.setIsInvoiced(false); - oline.saveEx(); - - - - // Set Correct Dates for Plan - final String whereClause = MPPMRP.COLUMNNAME_DD_OrderLine_ID+"=?"; - List mrpList = new Query(getCtx(), MPPMRP.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{oline.getDD_OrderLine_ID()}) - .list(); - for (MPPMRP mrp : mrpList) - { - mrp.setDateOrdered(getToday()); - mrp.setS_Resource_ID(m_product_planning.getS_Resource_ID()); - mrp.setDatePromised(TimeUtil.addDays(DemandDateStartSchedule , (m_product_planning.getDeliveryTime_Promised().add(transfertTime)).negate().intValue())); - mrp.setDateFinishSchedule(DemandDateStartSchedule); - mrp.saveEx(); - } - } - count_DO += 1; - commit(); - } - - protected void createRequisition(int AD_Org_ID , int PP_MRP_ID, MProduct product,BigDecimal QtyPlanned, Timestamp DemandDateStartSchedule) - { - log.info("Create Requisition"); - - // Duration = Lead Time + Transfer Time - int duration = m_product_planning.getDeliveryTime_Promised().intValue() - + m_product_planning.getTransfertTime().intValue(); - - MRequisition req = new MRequisition(getCtx(),0, get_TrxName()); - req.setAD_Org_ID(AD_Org_ID); - req.setAD_User_ID(m_product_planning.getPlanner_ID()); - req.setDateRequired(TimeUtil.addDays(DemandDateStartSchedule, 0 - duration)); - req.setDescription("Generate from MRP"); // TODO: add translation - req.setM_Warehouse_ID(m_product_planning.getM_Warehouse_ID()); - req.setC_DocType_ID(docTypeReq_ID); - req.setM_PriceList_ID(); - req.saveEx(); - - - - MRequisitionLine reqline = new MRequisitionLine(req); - reqline.setLine(10); - reqline.setAD_Org_ID(AD_Org_ID); - reqline.setM_Product_ID(m_product_planning.getM_Product_ID()); - reqline.setPrice(); - reqline.setPriceActual(Env.ZERO); - reqline.setQty(QtyPlanned); - reqline.saveEx(); - - - - // Set Correct Dates for Plan - final String whereClause = MPPMRP.COLUMNNAME_M_Requisition_ID+"=?"; - List mrpList = new Query(getCtx(), MPPMRP.Table_Name, whereClause, get_TrxName()) - .setParameters(new Object[]{req.getM_Requisition_ID()}) - .list(); - for (MPPMRP mrp : mrpList) - { - mrp.setDateOrdered(getToday()); - mrp.setS_Resource_ID(m_product_planning.getS_Resource_ID()); - mrp.setDatePromised(req.getDateRequired()); - mrp.setDateStartSchedule(req.getDateRequired()); - mrp.setDateFinishSchedule(DemandDateStartSchedule); - mrp.saveEx(); - - } - commit(); - count_MR += 1; - } - - protected void createPPOrder(int AD_Org_ID, int PP_MRP_ID, MProduct product,BigDecimal QtyPlanned,Timestamp DemandDateStartSchedule) - { - log.info("PP_Product_BOM_ID" + m_product_planning.getPP_Product_BOM_ID() + "AD_Workflow_ID" + m_product_planning.getAD_Workflow_ID()); - if (m_product_planning.getPP_Product_BOM_ID() == 0 || m_product_planning.getAD_Workflow_ID() == 0) - { - throw new AdempiereException("@FillMandatory: @PP_Product_BOM_ID@, @AD_Workflow_ID@ ( @M_Product_ID@="+product.getValue()+")"); - } - - log.info("Manufacturing Order Create"); - MPPOrder order = new MPPOrder(getCtx(), 0, get_TrxName()); - order.setAD_Org_ID(AD_Org_ID); - order.setLine(10); - order.setC_DocTypeTarget_ID(docTypeMO_ID); - order.setC_DocType_ID(docTypeMO_ID); - order.setS_Resource_ID(m_product_planning.getS_Resource_ID()); - order.setM_Warehouse_ID(m_product_planning.getM_Warehouse_ID()); - order.setM_Product_ID(m_product_planning.getM_Product_ID()); - order.setM_AttributeSetInstance_ID(0); - order.setPP_Product_BOM_ID(m_product_planning.getPP_Product_BOM_ID()); - order.setAD_Workflow_ID(m_product_planning.getAD_Workflow_ID()); - order.setPlanner_ID(m_product_planning.getPlanner_ID()); - order.setQtyDelivered(Env.ZERO); - order.setQtyReject(Env.ZERO); - order.setQtyScrap(Env.ZERO); - order.setDateOrdered(getToday()); - order.setDatePromised(DemandDateStartSchedule); - - if (m_product_planning.getDeliveryTime_Promised().signum() == 0) - order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, (MPPMRP.getDays(order.getCtx(), order.getS_Resource_ID(), order.getAD_Workflow_ID(), QtyPlanned, get_TrxName()).add(m_product_planning.getTransfertTime())).negate().intValue())); - else - order.setDateStartSchedule(TimeUtil.addDays(DemandDateStartSchedule, (m_product_planning.getDeliveryTime_Promised().add(m_product_planning.getTransfertTime())).negate().intValue())); - order.setDateFinishSchedule(DemandDateStartSchedule); - order.setQty(QtyPlanned); - order.setQtyBatchs(Env.ONE); - order.setQtyBatchSize(QtyPlanned); - order.setC_UOM_ID(product.getC_UOM_ID()); - order.setPosted(false); - order.setProcessed(false); - order.setYield(Env.ZERO); - order.setScheduleType(MPPMRP.TYPEMRP_Demand); - order.setPriorityRule(MPPOrder.PRIORITYRULE_Medium); - order.setDocStatus(MPPOrder.DOCSTATUS_Drafted); - order.setDocAction(MPPOrder.DOCSTATUS_Completed); - order.saveEx(); - commit(); - - count_MO += 1; - - } - - private void deletePO(String tableName, String whereClause, Object[] params) - { - // TODO: refactor this method and move it to org.compiere.model.Query class - POResultSet rs = new Query(getCtx(), tableName, whereClause, get_TrxName()) - .setParameters(params) - .scroll(); - try { - while(rs.hasNext()) { - rs.next().deleteEx(true); - } - } - finally { - rs.close(); - } - commit(); - } - - /** - * Create MRP Notice - * @param code MRP/DRP Code (see MRP-xxx and DRP-xxx messages) - * @param AD_Org_ID organization - * @param PP_MRP_ID MRP record id - * @param product product (optional) - * @param documentNo Document# (optional) - * @param qty quantity (optional) - * @param comment comment (optional) - */ - protected void createMRPNote(String code, int AD_Org_ID, int PP_MRP_ID, MProduct product, String documentNo, BigDecimal qty, String comment) - { - documentNo = documentNo != null ? documentNo : ""; - comment = comment != null ? comment : ""; - qty = qty != null ? qty : Env.ZERO; - - MMessage msg = MMessage.get(getCtx(), code); - String message = Msg.getMsg(getCtx(), msg.getValue()); - - int user_id = 0; - if (m_product_planning != null) - { - user_id = m_product_planning.getPlanner_ID(); - } - - String reference = ""; - if (product != null) - { - reference = product.getValue() + " " + product.getName(); - } - - if (!Util.isEmpty(documentNo, true)) - { - message += " " + Msg.translate(getCtx(), MPPOrder.COLUMNNAME_DocumentNo) +":" + documentNo; - } - if (qty != null) - { - message += " " + Msg.translate(getCtx(), "QtyPlan") + ":" + qty; - } - if (!Util.isEmpty(comment, true)) - { - message += " " + comment; - } - - MNote note = new MNote(getCtx(), - msg.getAD_Message_ID(), - user_id, - MPPMRP.Table_ID, PP_MRP_ID, - reference, - message, - get_TrxName()); - note.setAD_Org_ID(AD_Org_ID); - note.saveEx(); - commit(); - log.info(code+": "+note.getTextMsg()); - count_Msg += 1; - } - - private int getDDOrder_ID(int AD_Org_ID,int M_Warehouse_ID, int M_Shipper_ID,int C_BPartner_ID, Timestamp DatePromised) - { - String key = AD_Org_ID+"#"+M_Warehouse_ID+"#"+M_Shipper_ID+"#"+C_BPartner_ID+"#"+DatePromised+"DR"; - Integer order_id = dd_order_id_cache.get(key.toString()); - if ( order_id == null) - { - String sql = "SELECT DD_Order_ID FROM DD_Order WHERE AD_Org_ID=? AND M_Warehouse_ID=? AND M_Shipper_ID = ? AND C_BPartner_ID=? AND DatePromised=? AND DocStatus=?"; - order_id = DB.getSQLValueEx(get_TrxName(), sql, - new Object[]{ AD_Org_ID, - M_Warehouse_ID, - M_Shipper_ID, - C_BPartner_ID, - DatePromised, - MDDOrder.DOCSTATUS_Drafted }); - if(order_id > 0) - dd_order_id_cache.put(key,order_id); - } - return order_id; - } - - private MBPartner getBPartner(int C_BPartner_ID) - { - MBPartner partner = partner_cache.get(C_BPartner_ID); - if ( partner == null) - { - partner = MBPartner.get(getCtx(), C_BPartner_ID); - partner_cache.put(C_BPartner_ID, partner); - } - return partner; - } - - /** - * return ScheduledReceipts to cover the ProjectQtyOnhand - * @param AD_Client_ID - * @param AD_Org_ID - * @param M_Warehouse_ID - * @param M_Product - * @param ProjectQtyOnhand - * @param DemandDateStartSchedule - * @return - */ - private BigDecimal getNetRequierements(int AD_Client_ID, int AD_Org_ID, - int M_Warehouse_ID, MProduct M_Product, - Timestamp DemandDateStartSchedule) - { - BigDecimal QtyNetReqs = QtyProjectOnHand.subtract(QtyGrossReqs); - final String whereClause = " AD_Client_ID=? AND AD_Org_ID=?" - + " AND M_Product_ID = ?" - + " AND M_Warehouse_ID = ?" - + " AND DocStatus IN (?,?) AND IsAvailable = ? AND TypeMRP = ?"; - ArrayList parameters= new ArrayList(); - parameters.add(AD_Client_ID); - parameters.add(AD_Org_ID); - parameters.add(M_Product.get_ID()); - parameters.add(M_Warehouse_ID); - parameters.add(DocAction.STATUS_Completed); - parameters.add(DocAction.STATUS_InProgress); - parameters.add(true); - parameters.add(MPPMRP.TYPEMRP_Supply); - - Collection mrps = new Query(getCtx(), MPPMRP.Table_Name, whereClause, get_TrxName()) - .setParameters(parameters) - .setOrderBy(MPPMRP.COLUMNNAME_DateStartSchedule) - .list(); - for (MPPMRP mrp : mrps) - { - QtyScheduledReceipts = QtyScheduledReceipts.add(mrp.getQty()); - - if(DemandDateStartSchedule != null) - { - //MRP-030 De-Expedite Action Notice - //Indicates that a schedule supply order is due before it is needed and should be delayed, - //or demand rescheduled to an earlier date. - if(QtyNetReqs.negate().signum() > 0 - && mrp.getDateStartSchedule().compareTo(DemandDateStartSchedule) < 0) - { - String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DateStartSchedule) - + ":" + mrp.getDateStartSchedule() - + " " + Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) - + ":" + DemandDateStartSchedule; - createMRPNote("MRP-030", AD_Org_ID, mrp.get_ID(), M_Product, - MPPMRP.getDocumentNo(mrp.get_ID()), mrp.getQty(), comment); - } - - //MRP-040 Expedite Action Notice - //Indicates that a scheduled supply order is due after is needed and should be rescheduled to - //an earlier date or demand rescheduled to a later date. - if(QtyNetReqs.negate().signum() < 0 - && mrp.getDateStartSchedule().compareTo(DemandDateStartSchedule) > 0) - { - String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DateStartSchedule) - + ":" + mrp.getDateStartSchedule() - + " " + Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) - + ":" + DemandDateStartSchedule; - createMRPNote("MRP-040", AD_Org_ID, mrp.get_ID(), M_Product, - MPPMRP.getDocumentNo(mrp.get_ID()), mrp.getQty(), comment); - } - - //TODO vpj-cd I need to create logic for MRP-060 Release Due For Action Notice in time - //Indicate that a supply order should be released. if it is a draft order , it must also be approved. - // if(date release > today && date release + after floating) - - //TODO vpj-cd I need to create logic for MRP-070 Release Past Due For Action Notice overdue - //Indicates that a supply order was not released when it was due, and should be either released - //or expedited now, or the demand rescheduled for a later date. - //if (date release < today && date erelese + before floating) - - - //MRP-110 Past Due Action Notice - //Indicates that a schedule supply order receipt is past due. - if(mrp.getDatePromised().compareTo(getToday()) < 0) - { - String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) - + ":" + mrp.getDatePromised(); - createMRPNote("MRP-110", AD_Org_ID, mrp.get_ID(), M_Product, - MPPMRP.getDocumentNo(mrp.get_ID()), mrp.getQty(), comment); - } - - mrp.setIsAvailable(false); - mrp.saveEx(); - - QtyNetReqs.add(mrp.getQty()); - - if (QtyNetReqs.signum() == 0) - { - return QtyNetReqs; - } - } - else - { - //MRP-050 Cancel Action Notice - //Indicate that a scheduled supply order is no longer needed and should be deleted. - if(QtyScheduledReceipts.signum() > 0) - { - String comment = Msg.translate(getCtx(), MPPMRP.COLUMNNAME_DatePromised) - + ":" + mrp.getDatePromised(); - createMRPNote("MRP-050", AD_Org_ID, mrp.get_ID(), M_Product, - MPPMRP.getDocumentNo(mrp.get_ID()), mrp.getQty(), comment); - } - QtyNetReqs.add(mrp.getQty()); - mrp.setIsAvailable(false); - mrp.saveEx(); - } - } - - return QtyNetReqs; - } - - protected int getDocType(String docBaseType) - { - MDocType[] doc = MDocType.getOfDocBaseType(getCtx(), docBaseType); - - if (doc == null || doc.length == 0) - { - String reference = Msg.getMsg(getCtx(), "SequenceDocNotFound"); - String textMsg = "Not found default document type for docbasetype "+ docBaseType; - MNote note = new MNote(getCtx(), MMessage.getAD_Message_ID (getCtx(), "SequenceDocNotFound"), - getPlanner_ID(), MPPMRP.Table_ID, 0, - reference, - textMsg, - get_TrxName()); - note.saveEx(); - throw new AdempiereException(textMsg); - } - else - { - log.info("Doc Type for "+docBaseType+": "+ doc[0].getC_DocType_ID()); - return doc[0].getC_DocType_ID(); - } - } -} - diff --git a/base/src/org/eevolution/process/MRPUpdate.java b/base/src/org/eevolution/process/MRPUpdate.java deleted file mode 100644 index 5675f1ddde..0000000000 --- a/base/src/org/eevolution/process/MRPUpdate.java +++ /dev/null @@ -1,371 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ - -package org.eevolution.process; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import org.compiere.model.MOrg; -import org.compiere.model.MRequisition; -import org.compiere.model.MResource; -import org.compiere.model.MWarehouse; -import org.compiere.model.PO; -import org.compiere.model.POResultSet; -import org.compiere.model.Query; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.eevolution.model.MDDOrder; -import org.eevolution.model.MPPMRP; -import org.eevolution.model.MPPOrder; - -/** - * MRPUpdate - * - * @author Victor Perez, e-Evolution, S.C. - * @author Teo Sarca, www.arhipac.ro - */ -public class MRPUpdate extends SvrProcess -{ - private int m_AD_Client_ID = 0; - private int p_AD_Org_ID = 0; - private int p_S_Resource_ID = 0 ; - private int p_M_Warehouse_ID= 0; -// private int Planner_ID= 0; - - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - m_AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); -// Planner_ID = Integer.parseInt(Env.getContext(getCtx(), "#AD_User_ID")); - ProcessInfoParameter[] para = getParameter(); - - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - - if (para[i].getParameter() == null) - ; - else if (name.equals("AD_Org_ID")) - { - p_AD_Org_ID = ((BigDecimal)para[i].getParameter()).intValue(); - } - else if (name.equals("S_Resource_ID")) - { - p_S_Resource_ID = ((BigDecimal)para[i].getParameter()).intValue(); - } - else if (name.equals("M_Warehouse_ID")) - { - p_M_Warehouse_ID = ((BigDecimal)para[i].getParameter()).intValue(); - } - else - log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); - } - - } // prepare - - - /** - * doIT - run process - */ - protected String doIt() throws Exception - { - - String result = null; - ArrayList parameters = new ArrayList(); - StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType+"=? AND AD_Client_ID=?"); - parameters.add(MResource.MANUFACTURINGRESOURCETYPE_Plant); - parameters.add(m_AD_Client_ID); - - if (p_S_Resource_ID > 0) - { - whereClause.append(" AND S_Resource_ID=?"); - parameters.add(p_S_Resource_ID); - } - - List plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(parameters) - .list(); - - for(MResource plant : plants) - { - log.info("Run MRP to Plant: " + plant.getName()); - parameters = new ArrayList(); - whereClause = new StringBuffer("AD_Client_ID=?"); - parameters.add(m_AD_Client_ID); - - if (p_AD_Org_ID > 0) - { - whereClause.append(" AND AD_Org_ID=?"); - parameters.add(p_AD_Org_ID); - } - - - List organizations = new Query(getCtx(),MOrg.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(parameters) - .list(); - - for (MOrg organization : organizations) - { - log.info("Run MRP to Organization: " + organization.getName()); - if(p_M_Warehouse_ID==0) - { - MWarehouse[] ws = MWarehouse.getForOrg(getCtx(), organization.getAD_Org_ID()); - for(MWarehouse w : ws) - { - log.info("Run MRP to Wharehouse: " + w.getName()); - deleteRecords(m_AD_Client_ID,organization.getAD_Org_ID(),plant.getS_Resource_ID(),w.getM_Warehouse_ID()); - createRecords(m_AD_Client_ID,organization.getAD_Org_ID(),plant.getS_Resource_ID(),w.getM_Warehouse_ID()); - - result = result + "
finish MRP to Warehouse " +w.getName(); - } - } - else - { - log.info("Run MRP to Wharehouse: " + p_M_Warehouse_ID); - deleteRecords(m_AD_Client_ID,organization.getAD_Org_ID(),plant.getS_Resource_ID(),p_M_Warehouse_ID); - createRecords(m_AD_Client_ID,organization.getAD_Org_ID(),plant.getS_Resource_ID(),p_M_Warehouse_ID); - } - result = result + "
finish MRP to Organization " +organization.getName(); - } - result = result + "
finish MRP to Plant " +plant.getName(); - } - - return result + Msg.getMsg(getCtx(), "ProcessOK"); - } - - /** - * Delete MRP records - */ - private void deleteRecords(int AD_Client_ID, int AD_Org_ID,int S_Resource_ID, int M_Warehouse_ID) - { - // Delete MRP records (Orders (SO,PO), Forecasts, Material Requisitions): - { - List params = new ArrayList(); - params.add(AD_Client_ID); - params.add(AD_Org_ID); - params.add(M_Warehouse_ID); - String whereClause = "OrderType IN ('FCT','POR', 'SOO', 'POO') AND AD_Client_ID=? AND AD_Org_ID=? AND M_Warehouse_ID=?"; - executeUpdate("DELETE FROM PP_MRP WHERE "+whereClause, params); - - //Delete Material Requisitions Document - whereClause = "DocStatus IN ('DR','CL') AND AD_Client_ID=? AND AD_Org_ID=? AND M_Warehouse_ID=?"; - deletePO(MRequisition.Table_Name, whereClause, params); - // Delete Distribution Orders: - deletePO(MDDOrder.Table_Name, whereClause, params); - - } - - { - List params = new ArrayList(); - params.add(AD_Client_ID); - params.add(AD_Org_ID); - params.add(S_Resource_ID); - params.add(M_Warehouse_ID); - String whereClause = "OrderType IN ('MOP','DOO') AND AD_Client_ID=? AND AD_Org_ID=? AND S_Resource_ID= ? AND M_Warehouse_ID=?"; - executeUpdate("DELETE FROM PP_MRP WHERE "+whereClause, params); - - // Delete Mfg. Orders: - whereClause = "DocStatus='DR' AND AD_Client_ID=? AND AD_Org_ID=? AND S_Resource_ID= ? AND M_Warehouse_ID=?"; - deletePO(MPPOrder.Table_Name, whereClause, params); - } - - // Delete notes: - { - List params = new ArrayList(); - params.add(AD_Client_ID); - params.add(AD_Org_ID); - String whereClause = "AD_Table_ID="+MPPMRP.Table_ID+" AND AD_Client_ID=? AND AD_Org_ID=?"; - executeUpdate("DELETE FROM AD_Note WHERE "+whereClause, params); - } - } - - /** - * Create MRP records - */ - private void createRecords (int AD_Client_ID, int AD_Org_ID,int S_Resource_ID, int M_Warehouse_ID) - { - final String sql = "INSERT INTO PP_MRP (" - +"ad_org_id, created, createdby , dateordered," - +"datepromised, datestart, datestartschedule, description," - +"docstatus, isactive , " - +"m_forecastline_id, m_forecast_id," - +"pp_order_id, pp_order_bomline_id," - +"c_order_id, c_orderline_id," - +"m_requisition_id, m_requisitionline_id," - +"m_product_id, m_warehouse_id, " - +"pp_mrp_id, planner_id, " - +"qty, typemrp, ordertype, updated, updatedby, value, " - +"ad_client_id, s_resource_id, c_bpartner_id )"; - - // - //Insert from M_ForecastLine - List params = new ArrayList(); - - params.add(AD_Client_ID); - params.add(AD_Org_ID); - params.add(M_Warehouse_ID); - - String sql_insert = " SELECT t.ad_org_id," - +"t.created, t.createdby , t.datepromised," - +"t.datepromised, t.datepromised, t.datepromised, f.Name," - +"'IP', t.isactive , " - +"t.m_forecastline_id, t.m_forecast_id, " - + "null, null," - + "null, null," - + "null, null," - +"t.m_product_id, t.m_warehouse_id," - + "nextidfunc(53040,'N'), null ," - +"t.qty, 'D', 'FCT', t.updated, t.updatedby, f.Name," - +"t.ad_client_id , null as S_Resource_ID, null as C_BPartner_ID " - +" FROM M_ForecastLine t " - +" INNER JOIN M_Forecast f ON (f.M_Forecast_ID=t.M_Forecast_ID) " - +" WHERE t.Qty > 0 AND " - +"t.AD_Client_ID=? AND t.AD_Org_ID=? AND t.M_Warehouse_ID= ?"; - executeUpdate(sql + sql_insert, params); - - // Insert from C_OrderLine - sql_insert = " SELECT t.ad_org_id," - +"t.created, t.createdby , t.datepromised," - +"t.datepromised, t.datepromised, t.datepromised, o.DocumentNo," - +"o.DocStatus, o.isactive , " - +" null, null, " - +" null, null, " - +" t.c_order_id, t.c_orderline_id, " - +" null, null, " - +"t.m_product_id, t.m_warehouse_id," - + "nextidfunc(53040,'N'), null ," - +"t.QtyOrdered-t.QtyDelivered, (case when o.IsSOTrx='Y' then 'D' else 'S' end) , (case when o.IsSOTrx='Y' then 'SOO' else 'POO' end), t.updated, t.updatedby, o.DocumentNo," - +"t.ad_client_id , null as S_Resource_ID, o.C_BPartner_ID" - +" FROM C_OrderLine t" - +" INNER JOIN C_Order o ON (o.c_order_id=t.c_order_id)" - +" WHERE (t.QtyOrdered - t.QtyDelivered) <> 0 AND o.DocStatus IN ('IP','CO') AND " - +"t.AD_Client_ID=? AND t.AD_Org_ID=? AND t.M_Warehouse_ID= ?"; - executeUpdate(sql + sql_insert, params); - - - // Insert from M_RequisitionLine - sql_insert = " SELECT rl.ad_org_id," - +"rl.created, rl.createdby , t.daterequired," - +" t.daterequired, t.daterequired, t.daterequired, t.DocumentNo," - +"t.DocStatus, t.isactive , " - +" null, null, " - +" null, null, " - +" null, null, " - +"rl.m_requisition_id, rl.m_requisitionline_id, " - +"rl.m_product_id, t.m_warehouse_id," - + "nextidfunc(53040,'N'), null ," - +"rl.Qty, 'S', 'POR', rl.updated, rl.updatedby, t.DocumentNo," - +"rl.ad_client_id , null as S_Resource_ID, null as C_BPartner_ID " - +" FROM M_RequisitionLine rl" - +" INNER JOIN M_Requisition t ON (rl.m_requisition_id=t.m_requisition_id)" - +" WHERE rl.Qty > 0 AND t.DocStatus IN ('DR','IN') AND " - +"t.AD_Client_ID=? AND t.AD_Org_ID=? AND t.M_Warehouse_ID= ?"; - executeUpdate(sql + sql_insert, params); - - //Insert from PP_Order - params = new ArrayList(); - params.add(AD_Client_ID); - params.add(AD_Org_ID); - params.add(S_Resource_ID); - params.add(M_Warehouse_ID); - sql_insert = " SELECT t.ad_org_id," - +"t.created, t.createdby , t.datepromised," - +"t.datepromised, t.datepromised, t.datepromised, t.DocumentNo," - +"t.DocStatus, t.isactive , " - +" null, null, " - +"t.pp_order_id, null," - +" null, null, " - +" null, null, " - +"t.m_product_id, t.m_warehouse_id," - + "nextidfunc(53040,'N'), null ," - +"t.QtyOrdered-t.QtyDelivered, 'S', 'MOP', t.updated, t.updatedby, t.DocumentNo," - +"t.ad_client_id, t.S_Resource_ID, null as C_BPartner_ID " - +" FROM PP_Order t " - +" WHERE (t.QtyOrdered - t.QtyDelivered) <> 0 AND t.DocStatus IN ('DR','IP','CO') AND " - +"t.AD_Client_ID=? AND t.AD_Org_ID=? AND t.S_Resource_ID=? AND t.M_Warehouse_ID= ?"; - executeUpdate(sql + sql_insert, params); - - // - //Insert from PP_Order_BOMLine - sql_insert = " SELECT t.ad_org_id," - +"t.created, t.createdby , o.datepromised," - +"o.datepromised, o.datepromised, o.datepromised, o.DocumentNo," - +"o.DocStatus, o.isactive , " - +" null, null, " - +"t.pp_order_id, t.pp_order_bomline_id," - +" null, null, " - +" null, null, " - +"t.m_product_id, t.m_warehouse_id," - + "nextidfunc(53040,'N'), null ," - +"t.QtyRequiered-t.QtyDelivered, 'D', 'MOP', t.updated, t.updatedby, o.DocumentNo," - +"t.ad_client_id, o.S_Resource_ID, null as C_BPartner_ID " - +" FROM PP_Order_BOMLine t " - +" INNER JOIN PP_Order o ON (o.pp_order_id=t.pp_order_id)" - +" WHERE (t.QtyRequiered-t.QtyDelivered) <> 0 AND o.DocStatus IN ('DR','IP','CO') AND " - +"t.AD_Client_ID=? AND t.AD_Org_ID=? AND o.S_Resource_ID=? AND t.M_Warehouse_ID= ?"; - executeUpdate(sql + sql_insert , params); - } - - - private void executeUpdate(String sql, List params) - { - Object[] pa = null; - if (params != null) - { - pa = params.toArray(new Object[params.size()]); - } - else - { - pa = new Object[]{}; - } - - int no = DB.executeUpdateEx(sql, pa, get_TrxName()); - commit(); - log.fine("#"+no+" -- "+sql); - - } - - - private void deletePO(String tableName, String whereClause, List params) - { - // TODO: refactor this method and move it to org.compiere.model.Query class - POResultSet rs = new Query(getCtx(), tableName, whereClause, get_TrxName()) - .setParameters(params) - .scroll(); - try - { - while(rs.hasNext()) - { - rs.next().deleteEx(true); - commit(); - } - } - finally - { - rs.close(); - } - } -} diff --git a/base/src/org/eevolution/process/PayrollViaEMail.java b/base/src/org/eevolution/process/PayrollViaEMail.java deleted file mode 100644 index 7c307f60d0..0000000000 --- a/base/src/org/eevolution/process/PayrollViaEMail.java +++ /dev/null @@ -1,280 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.process; - -import java.io.File; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import org.compiere.model.MBPartner; -import org.compiere.model.MClient; -import org.compiere.model.MInterestArea; -import org.compiere.model.MMailText; -import org.compiere.model.MPInstance; -import org.compiere.model.MPInstancePara; -import org.compiere.model.MProcess; -import org.compiere.model.MUser; -import org.compiere.process.ProcessInfo; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.DB; -import org.compiere.util.EMail; -import org.compiere.util.Env; -import org.compiere.util.Trx; - -/** - * Send Mail to Interest Area Subscribers - * - * @author Antonio Canaveral, www.e-evolution.com - */ -public class PayrollViaEMail extends SvrProcess -{ - /** What to send */ - private int m_R_MailText_ID = -1; - /** Mail Text */ - private MMailText m_MailText = null; - - /** From (sender) */ - private int m_AD_User_ID = -1; - /** Client Info */ - private MClient m_client = null; - /** From */ - private MUser m_from = null; - /** Recipient List to prevent duplicate mails */ - private ArrayList m_list = new ArrayList(); - - - private int m_counter = 0; - private int m_errors = 0; - /** To Subscribers */ - private int m_HR_Process_ID = -1; - /** Interest Area */ - private MInterestArea m_ia = null; - /** To Customer Type */ - private int m_C_BP_Group_ID = -1; - /** To Purchaser of Product */ - // comes here - private int m_AD_Process_ID=-1; - - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) - { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null); - else if (name.equals("HR_Process_ID")) - m_HR_Process_ID = para[i].getParameterAsInt(); - else if (name.equals("R_MailText_ID")) - m_R_MailText_ID = para[i].getParameterAsInt(); - else if (name.equals("C_BP_Group_ID")) - m_C_BP_Group_ID = para[i].getParameterAsInt(); - else if (name.equals("AD_User_ID")) - m_AD_User_ID = para[i].getParameterAsInt(); - else if (name.equals("AD_Process_ID")) - m_AD_Process_ID = para[i].getParameterAsInt(); - else - log.log(Level.SEVERE, "Unknown Parameter: " + name); - } - } // prepare - - /** - * Perform process. - * @return Message - * @throws Exception - */ - protected String doIt() throws Exception - { - log.info("R_MailText_ID=" + m_R_MailText_ID); - // Mail Test - m_MailText = new MMailText (getCtx(), m_R_MailText_ID, get_TrxName()); - if (m_MailText.getR_MailText_ID() == 0) - throw new Exception ("Not found @R_MailText_ID@=" + m_R_MailText_ID); - // Client Info - m_client = MClient.get (getCtx()); - if (m_client.getAD_Client_ID() == 0) - throw new Exception ("Not found @AD_Client_ID@"); - if (m_client.getSMTPHost() == null || m_client.getSMTPHost().length() == 0) - throw new Exception ("No SMTP Host found"); - // - long start = System.currentTimeMillis(); - - m_from = new MUser(getCtx(),Env.getAD_User_ID(getCtx()),get_TrxName()); - if (m_from.getAD_User_ID() == 0) - throw new Exception ("No found @AD_User_ID@=" + m_AD_User_ID); - if (m_AD_User_ID > 0) - { - MUser tmpUser = new MUser(getCtx(),m_AD_User_ID,get_TrxName()); - sendIndividualMail (m_from.getName(), tmpUser.getC_BPartner_ID(), null); - }else - sendBPGroup(); - log.fine("From " + m_from); - - - return "@Created@=" + m_counter + ", @Errors@=" + m_errors + " - " - + (System.currentTimeMillis()-start) + "ms"; - } // doIt - - /** - * Send to BPGroup - */ - private void sendBPGroup() - { - log.info("C_BP_Group_ID=" + m_C_BP_Group_ID); - String sql = " SELECT bp.Name, bp.url, bp.c_bpartner_id" - + " FROM C_BPartner bp" - + " WHERE bp.IsActive='Y'" - + " AND bp.url IS NOT NULL"; - if (m_C_BP_Group_ID > 0) - sql += " AND bp.C_BP_Group_ID=?"; - - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement(sql, get_TrxName()); - if (m_C_BP_Group_ID > 0) - pstmt.setInt(1, m_C_BP_Group_ID); - ResultSet rsMail = pstmt.executeQuery(); - List tabla = new ArrayList(); - while (rsMail.next()) - { - tabla.add(new Integer(rsMail.getInt(3))); - } - for(int i=0;i= 0; lowLevel--) - { - for (MProduct product : getProducts(lowLevel)) - { - int AD_Org_ID = p_AD_Org_ID; - MPPProductPlanning pp = MPPProductPlanning.find(getCtx(), p_AD_Org_ID, - 0, // M_Warehouse_ID - 0, // S_Resource_ID - product.getM_Product_ID(), - get_TrxName()); - - int PP_Product_BOM_ID = 0; - if (pp != null) - { - PP_Product_BOM_ID = pp.getPP_Product_BOM_ID(); - - } - if (PP_Product_BOM_ID <= 0) - { - PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(product); - } - - MPPProductBOM bom = MPPProductBOM.get(getCtx(), PP_Product_BOM_ID); - - Collection elements = MCostElement.getByCostingMethod(getCtx(), p_ConstingMethod); - - for (MCostElement element : elements) - { - for (MCost cost : getCosts(product, element.getCostElementType())) - { - log.info("Calculate Lower Cost for: "+ product.getName()); - log.info("Element Cost: "+ element.getName()); - BigDecimal price = getCurrentCostPriceLL(bom, element); - log.info(element.getName() + " Cost Low Level:" + price); - cost.setCurrentCostPriceLL(price); - cost.saveEx(); - } // for each Costs - } // for ELements - } // for each Products - } // for each LLC - return "@OK@"; - } - - /** - * get the sum Current Cost Price Level Low for this Cost Element - * @param bom MPPProductBOM - * @param element MCostElement - * @return Cost Price Lower Level - */ - private BigDecimal getCurrentCostPriceLL(MPPProductBOM bom, MCostElement element) - { - log.info("ElementType: "+ element.getCostElementType()); - BigDecimal costPriceLL = Env.ZERO; - if(bom == null) - return costPriceLL; - - for (MPPProductBOMLine bomline : bom.getLines()) - { - MProduct component = MProduct.get(getCtx(), bomline.getM_Product_ID()); - // get the rate for this resource - for (MCost cost : getCosts(component, element.getCostElementType())) - { - BigDecimal qtyPercentage = bomline.getQtyBatch().divide(Env.ONEHUNDRED, 8, BigDecimal.ROUND_UP); - BigDecimal qtyBOM = bomline.getQtyBOM(); - BigDecimal scrapDec = bomline.getScrap().divide(Env.ONEHUNDRED, 4, BigDecimal.ROUND_UP); - BigDecimal qtyTotal = Env.ZERO; - if (bomline.isQtyPercentage()) - { - qtyTotal = qtyPercentage.divide(Env.ONE.subtract(scrapDec), 4, BigDecimal.ROUND_HALF_UP); - } - else - { - qtyTotal = qtyBOM.divide(Env.ONE.subtract(scrapDec), 4, BigDecimal.ROUND_HALF_UP); - } - - BigDecimal costPrice = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL()); - costPriceLL = costPriceLL.add(costPrice.multiply(qtyTotal)); - log.info("Cost Element:"+element.getName() - + ", Total Cost Element: " + costPriceLL - + ", QtyPercentage: " + qtyPercentage - + ", QtyBOM: " + qtyBOM); - } // for each cost - } // for each BOM line - return costPriceLL; - } - - private Collection getCosts(MProduct product,String CostElementType) - { - MAcctSchema as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID); - return MCost.getByCostType( - product, - as, - p_M_CostType_ID, - p_AD_Org_ID, - 0, // ASI - CostElementType); - } - - private Collection getProducts(int lowLevel) - { - List params = new ArrayList(); - StringBuffer whereClause = new StringBuffer("AD_Client_ID=? AND LowLevel=? AND ProductType=?"); - params.add(getAD_Client_ID()); - params.add(lowLevel); - params.add(MProduct.PRODUCTTYPE_Item); - - if (p_M_Product_ID > 0) - { - whereClause.append(" AND M_Product_ID=?"); - params.add(p_M_Product_ID); - } - else if (p_M_Product_Category_ID > 0) - { - whereClause.append(" AND M_Product_Category_ID=?"); - params.add(p_M_Product_Category_ID); - } - - return new Query(getCtx(),MProduct.Table_Name, whereClause.toString(), get_TrxName()) - .setParameters(params) - .list(); - - } -} diff --git a/base/src/org/eevolution/process/RollupWorkflow.java b/base/src/org/eevolution/process/RollupWorkflow.java deleted file mode 100644 index fefaf60f82..0000000000 --- a/base/src/org/eevolution/process/RollupWorkflow.java +++ /dev/null @@ -1,210 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Bogdan Ioan, www.arhipac.ro * - *****************************************************************************/ - -package org.eevolution.process; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Level; - -import org.compiere.model.MAcctSchema; -import org.compiere.model.MCost; -import org.compiere.model.MCostElement; -import org.compiere.model.MProduct; -import org.compiere.model.Query; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.Env; -import org.compiere.wf.MWFNode; -import org.compiere.wf.MWorkflow; -import org.eevolution.model.MPPProductPlanning; - -/** - * RollUp of Cost Manufacturing Workflow - * This process calculate the Labor, Overhead, Burden Cost - * @author Victor Perez, e-Evolution, S.C. - * @version $Id: RollupWorkflow.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $ - * - * @author Bogdan Ioan, www.arhipac.ro - *
  • BF [ 2093001 ] Error in Cost Workflow & Process Details - */ -public class RollupWorkflow extends SvrProcess -{ - - /* Organization */ - private int p_AD_Org_ID = 0; - /* Account Schema */ - private int p_C_AcctSchema_ID = 0; - /* Cost Type */ - private int p_M_CostType_ID = 0; - /* Product */ - private int p_M_Product_ID = 0; - /* Product Category */ - private int p_M_Product_Category_ID = 0; - /* Costing Method */ - private String p_ConstingMethod = MCostElement.COSTINGMETHOD_StandardCosting; - - private MAcctSchema m_as = null; - - protected void prepare() - { - for (ProcessInfoParameter para : getParameter()) - { - String name = para.getParameterName(); - - if (para.getParameter() == null) - ; - else if (name.equals(MCost.COLUMNNAME_AD_Org_ID)) - p_AD_Org_ID = para.getParameterAsInt(); - else if (name.equals(MCost.COLUMNNAME_C_AcctSchema_ID)) - { - p_C_AcctSchema_ID = para.getParameterAsInt(); - m_as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID); - } - else if (name.equals(MCost.COLUMNNAME_M_CostType_ID)) - p_M_CostType_ID = para.getParameterAsInt(); - else if (name.equals(MCostElement.COLUMNNAME_CostingMethod)) - p_ConstingMethod=(String)para.getParameter(); - else if (name.equals(MProduct.COLUMNNAME_M_Product_ID)) - p_M_Product_ID = para.getParameterAsInt(); - else if (name.equals(MProduct.COLUMNNAME_M_Product_Category_ID)) - p_M_Product_Category_ID = para.getParameterAsInt(); - else - log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); - } - } // prepare - - protected String doIt() throws Exception - { - List params = new ArrayList(); - StringBuffer whereClause = new StringBuffer("AD_Client_ID=?"); - params.add(getAD_Client_ID()); - - whereClause.append(" AND ").append(MProduct.COLUMNNAME_ProductType).append("=?"); - params.add(MProduct.PRODUCTTYPE_Item); - - whereClause.append(" AND ").append(MProduct.COLUMNNAME_IsBOM).append("=?"); - params.add(true); - - if (p_M_Product_ID > 0) - { - whereClause.append(" AND ").append(MProduct.COLUMNNAME_M_Product_ID).append("=?"); - params.add(p_M_Product_ID); - } - else if (p_M_Product_Category_ID > 0) - { - whereClause.append(" AND ").append(MProduct.COLUMNNAME_M_Product_Category_ID).append("=?"); - params.add(p_M_Product_Category_ID); - } - - Collection products = new Query(getCtx(),MProduct.Table_Name, whereClause.toString(), get_TrxName()) - .setOrderBy(MProduct.COLUMNNAME_LowLevel) - .setParameters(params) - .list(); - - for (MProduct product : products) - { - log.info("Product: "+product); - MPPProductPlanning pp = MPPProductPlanning.find( getCtx(), p_AD_Org_ID , 0, 0, product.get_ID(), get_TrxName()); - int AD_Workflow_ID = 0; - if (pp != null) - { - AD_Workflow_ID = pp.getAD_Workflow_ID(); - } - if (AD_Workflow_ID <= 0) - { - AD_Workflow_ID = MWorkflow.getWorkflowSearchKey(product); - } - if(AD_Workflow_ID <= 0) - { - continue; - } - - MWorkflow workflow = MWorkflow.get(getCtx(), AD_Workflow_ID); - log.info("Workflow: "+workflow); - workflow.setCost(Env.ZERO); - - MWFNode[] nodes = workflow.getNodes(false, getAD_Client_ID()); - for (MWFNode node : nodes) - { - node.setCost(Env.ZERO); - } - - BigDecimal labor = Env.ZERO; - BigDecimal burden = Env.ZERO; - Collection elements = MCostElement.getByCostingMethod(getCtx(), p_ConstingMethod); - for (MCostElement element : elements) - { - Collection costs = MCost.getByCostType( - product, - m_as, - p_M_CostType_ID, - p_AD_Org_ID, - 0,element.getCostElementType()); // ASI - for (MCost cost : costs) - { - if(MCostElement.COSTELEMENTTYPE_Resource.equals(element.getCostElementType()) - || MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(element.getCostElementType())) - { - - for (MWFNode node : nodes) - { - BigDecimal nodeCost = Env.ZERO; - // check if element cost is of type Labor - if (MCostElement.COSTELEMENTTYPE_Resource.equals(element.getCostElementType())) - { - nodeCost = node.getCostForCostElementType(MCostElement.COSTELEMENTTYPE_Resource ,p_C_AcctSchema_ID, p_M_CostType_ID, p_AD_Org_ID, node.getSetupTime(), node.getDuration()); - labor = labor.add(nodeCost); - log.info("Node="+node+" : Labor : nodeCost="+nodeCost+" => Cost="+labor); - } - else if (MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(element.getCostElementType())) - { - nodeCost = node.getCostForCostElementType(MCostElement.COSTELEMENTTYPE_BurdenMOverhead ,p_C_AcctSchema_ID, p_M_CostType_ID, p_AD_Org_ID, node.getSetupTime(), node.getDuration()); - burden = burden.add(nodeCost); - log.info("Node="+node+" : Burden : nodeCost="+nodeCost+" => Cost="+burden); - } - if(nodeCost.signum() != 0) - { - node.setCost(node.getCost().add(nodeCost)); - node.saveEx(); - } - } - // check if element cost is of type Labor - if (MCostElement.COSTELEMENTTYPE_Resource.equals(element.getCostElementType())) - { - log.info("Product:"+product.getName()+" Labor: " + labor); - cost.setCurrentCostPrice(labor); - cost.saveEx(); - } - else if (MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(element.getCostElementType())) - { - log.info("Product:"+product.getName()+" Burden: " + burden); - cost.setCurrentCostPrice(burden); - cost.saveEx(); - } - } - } // MCost - } // Cost Elements - workflow.setCost(labor.add(burden)); - workflow.saveEx(get_TrxName()); - - } - return "@OK@"; - } -} diff --git a/base/src/org/eevolution/report/CostBillOfMaterial.java b/base/src/org/eevolution/report/CostBillOfMaterial.java deleted file mode 100644 index 2dcb8fe9f3..0000000000 --- a/base/src/org/eevolution/report/CostBillOfMaterial.java +++ /dev/null @@ -1,255 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.report; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Level; - -import org.adempiere.exceptions.AdempiereException; -import org.adempiere.exceptions.FillMandatoryException; -import org.compiere.model.MAcctSchema; -import org.compiere.model.MCost; -import org.compiere.model.MCostElement; -import org.compiere.model.MProduct; -import org.compiere.model.Query; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.Env; -import org.eevolution.model.MPPProductBOM; -import org.eevolution.model.MPPProductBOMLine; -import org.eevolution.model.X_T_BOMLine; - -/** - * Cost Multi-Level BOM & Formula Review - * - * @author victor.perez@e-evolution.com - * @author Teo Sarca, www.arhipac.ro - * - */ -public class CostBillOfMaterial extends SvrProcess -{ - private static final String LEVELS = "...................."; - // - private int p_AD_Org_ID = 0; - private int p_C_AcctSchema_ID = 0; - private int p_M_Product_ID = 0; - private int p_M_CostType_ID = 0; - private String p_ConstingMethod = MCostElement.COSTINGMETHOD_StandardCosting; - private boolean p_implosion = false; - // - private int m_LevelNo = 0; - private int m_SeqNo = 0; - private MAcctSchema m_as = null; - private Collection m_costElements = null; - - protected void prepare() - { - for (ProcessInfoParameter para : getParameter()) - { - String name = para.getParameterName(); - if (para.getParameter() == null) - ; - else if (name.equals(MCost.COLUMNNAME_AD_Org_ID)) - p_AD_Org_ID = para.getParameterAsInt(); - else if (name.equals(MCost.COLUMNNAME_C_AcctSchema_ID)) - { - p_C_AcctSchema_ID= para.getParameterAsInt(); - m_as = MAcctSchema.get(getCtx(), p_C_AcctSchema_ID); - } - else if (name.equals(MCost.COLUMNNAME_M_CostType_ID)) - p_M_CostType_ID= para.getParameterAsInt(); - else if (name.equals(MCostElement.COLUMNNAME_CostingMethod)) - p_ConstingMethod=(String)para.getParameter(); - else if (name.equals(MCost.COLUMNNAME_M_Product_ID)) - p_M_Product_ID = para.getParameterAsInt(); - else - log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name); - } - } // prepare - - /** - * Perform process. - * - * @return Message (clear text) - * @throws Exception - * if not successful - */ - protected String doIt() throws Exception - { - if (p_M_Product_ID == 0) - { - throw new FillMandatoryException("M_Product_ID"); - } - m_costElements = MCostElement.getByCostingMethod(getCtx(), p_ConstingMethod); - explodeProduct(p_M_Product_ID, false); - // - return ""; - } // doIt - - /** - * Generate an Explosion for this product - * @param product - * @param isComponent component / header - */ - private void explodeProduct(int M_Product_ID, boolean isComponent) - { - MProduct product = MProduct.get(getCtx(), M_Product_ID); - List list = getBOMs(product, isComponent); - if (!isComponent && list.size() == 0) - { - throw new AdempiereException("@Error@ Product is not a BOM"); - } - // - for (MPPProductBOM bom : list) - { - // Create header - if (!isComponent) - { - createLines(bom, null); - } - m_LevelNo++; - // Create Lines: - for (MPPProductBOMLine bomLine : bom.getLines()) - { - if (!bomLine.isActive()) - { - continue; - } - createLines(bom, bomLine); - explodeProduct(bomLine.getM_Product_ID(), true); - } - m_LevelNo--; - } - } - - /** - * Get BOMs for given product - * @param product - * @param isComponent - * @return list of MPPProductBOM - */ - private List getBOMs(MProduct product, boolean includeAlternativeBOMs) - { - ArrayList params = new ArrayList(); - StringBuffer whereClause = new StringBuffer(); - whereClause.append(MPPProductBOM.COLUMNNAME_M_Product_ID).append("=?"); - params.add(product.get_ID()); - // Allow alternative BOMs - if (includeAlternativeBOMs) - { - whereClause.append(" AND ").append(MPPProductBOM.COLUMNNAME_Value).append("=?"); - params.add(product.getValue()); - } - List list = new Query(getCtx(), MPPProductBOM.Table_Name, whereClause.toString(), null) - .setParameters(params) - .setOnlyActiveRecords(true) - .setOrderBy(MPPProductBOM.COLUMNNAME_Value) - .list(); - return list; - } - - /** - * Create T_BOMLine - * @param product - * @param costElement - * @param qty - * @param bomLine - * @return - */ - private void createLines(MPPProductBOM bom, MPPProductBOMLine bomLine) - { - MProduct product; - BigDecimal qty; - if (bomLine != null) - { - product = MProduct.get(getCtx(), bomLine.getM_Product_ID()); - qty = bomLine.getQty(); - } - else if (bom != null) - { - product = MProduct.get(getCtx(), bom.getM_Product_ID()); - qty = Env.ONE; - } - else - { - throw new AdempiereException("@NotFound@ @PP_Product_BOM_ID@"); - } - for (MCostElement costElement : m_costElements) - { - X_T_BOMLine tboml = new X_T_BOMLine(getCtx(), 0, get_TrxName()); - tboml.setAD_Org_ID(p_AD_Org_ID); - tboml.setSel_Product_ID(p_M_Product_ID); - tboml.setImplosion(p_implosion); - tboml.setC_AcctSchema_ID(p_C_AcctSchema_ID); - tboml.setM_CostType_ID(p_M_CostType_ID); - tboml.setCostingMethod(p_ConstingMethod); - tboml.setAD_PInstance_ID(getAD_PInstance_ID()); - tboml.setM_CostElement_ID(costElement.get_ID()); - tboml.setM_Product_ID(product.get_ID()); - tboml.setQtyBOM(qty); - // - tboml.setSeqNo(m_SeqNo); - tboml.setLevelNo(m_LevelNo); - tboml.setLevels(LEVELS.substring(0, m_LevelNo) + m_LevelNo); - // - // Set Costs: - Collection costs = MCost.getByCostType( - product, - m_as, - p_M_CostType_ID, - p_AD_Org_ID, - 0, // ASI - costElement.getCostElementType()); - BigDecimal currentCostPrice = Env.ZERO; - BigDecimal currentCostPriceLL = Env.ZERO; - BigDecimal futureCostPrice = Env.ZERO; - BigDecimal futureCostPriceLL = Env.ZERO; - boolean isCostFrozen = false; - for (MCost cost : costs) - { - currentCostPrice = currentCostPrice.add(cost.getCurrentCostPrice()); - currentCostPriceLL = currentCostPriceLL.add(cost.getCurrentCostPriceLL()); - futureCostPrice = futureCostPrice.add(cost.getFutureCostPrice()); - futureCostPriceLL = futureCostPriceLL.add(cost.getFutureCostPriceLL()); - isCostFrozen = cost.isCostFrozen(); - - } - tboml.setCurrentCostPrice(currentCostPrice); - tboml.setCurrentCostPriceLL(currentCostPriceLL); - tboml.setFutureCostPrice(currentCostPrice); - tboml.setFutureCostPriceLL(currentCostPriceLL); - tboml.setIsCostFrozen(isCostFrozen); - // - // Reference - if (bomLine != null) - { - tboml.setPP_Product_BOM_ID(bomLine.getPP_Product_BOM_ID()); - tboml.setPP_Product_BOMLine_ID(bomLine.getPP_Product_BOMLine_ID()); - } - else if (bom != null) - { - tboml.setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID()); - } - // - tboml.saveEx(); - m_SeqNo++; - } - } -} diff --git a/client/src/org/eevolution/process/CompletePrintOrder.java b/client/src/org/eevolution/process/CompletePrintOrder.java deleted file mode 100644 index 9f31f39922..0000000000 --- a/client/src/org/eevolution/process/CompletePrintOrder.java +++ /dev/null @@ -1,161 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - * Teo Sarca, www.arhipac.ro * - *****************************************************************************/ -package org.eevolution.process; - - -import java.util.logging.Level; - -import org.adempiere.exceptions.AdempiereException; -import org.adempiere.exceptions.FillMandatoryException; -import org.compiere.model.MQuery; -import org.compiere.model.PrintInfo; -import org.compiere.model.Query; -import org.compiere.print.MPrintFormat; -import org.compiere.print.ReportCtl; -import org.compiere.print.ReportEngine; -import org.compiere.process.ClientProcess; -import org.compiere.process.ProcessInfoParameter; -import org.compiere.process.SvrProcess; -import org.compiere.util.Language; -import org.eevolution.model.MPPOrder; -import org.eevolution.model.MPPOrderWorkflow; - -/** - * Complete & Print Manufacturing Order - * @author victor.perez@e-evolution.com - * @author Teo Sarca, www.arhipac.ro - */ -public class CompletePrintOrder extends SvrProcess -implements ClientProcess -{ - /** The Order */ - private int p_PP_Order_ID = 0; - private boolean p_IsPrintPickList = false; - private boolean p_IsPrintWorkflow = false; - @SuppressWarnings("unused") - private boolean p_IsPrintPackList = false; // for future use - private boolean p_IsComplete = false; - - /** - * Prepare - e.g., get Parameters. - */ - protected void prepare() - { - for (ProcessInfoParameter para : getParameter()) - { - String name = para.getParameterName(); - if (para.getParameter() == null) - ; - else if (name.equals("PP_Order_ID")) - p_PP_Order_ID = para.getParameterAsInt(); - else if (name.equals("IsPrintPickList")) - p_IsPrintPickList = para.getParameterAsBoolean(); - else if (name.equals("IsPrintWorkflow")) - p_IsPrintWorkflow = para.getParameterAsBoolean(); - else if (name.equals("IsPrintPackingList")) - p_IsPrintPackList = para.getParameterAsBoolean(); - else if (name.equals("IsComplete")) - p_IsComplete = para.getParameterAsBoolean(); - else - log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name); - } - } // prepare - - /** - * Perform process. - * - * @return Message (clear text) - * @throws Exception - * if not successful - */ - protected String doIt() throws Exception - { - - if (p_PP_Order_ID == 0) - { - throw new FillMandatoryException(MPPOrder.COLUMNNAME_PP_Order_ID); - } - - if (p_IsComplete) - { - MPPOrder order = new MPPOrder(getCtx(), p_PP_Order_ID, get_TrxName()); - if (!order.isAvailable()) - { - throw new AdempiereException("@NoQtyAvailable@"); - } - // - // Process document - boolean ok = order.processIt(MPPOrder.DOCSTATUS_Completed); - order.saveEx(); - if (!ok) - { - throw new AdempiereException(order.getProcessMsg()); - } - // - // Document Status should be completed - if (!MPPOrder.DOCSTATUS_Completed.equals(order.getDocStatus())) - { - throw new AdempiereException(order.getProcessMsg()); - } - } - - if (p_IsPrintPickList) - { - // Get Format & Data - ReportEngine re = ReportEngine.get(getCtx(), ReportEngine.MANUFACTURING_ORDER, p_PP_Order_ID); - ReportCtl.preview(re); - re.print(); - } - if (p_IsPrintWorkflow) - { - MPrintFormat format = getAD_PrintFormat(MPPOrderWorkflow.Table_ID); - if (format == null) - { - addLog("@NotFound@ @AD_PrintFormat_ID@ @PP_Order_Workflow_ID@"); - } - // query - MQuery query = new MQuery(MPPOrderWorkflow.Table_Name); - query.addRestriction(MPPOrderWorkflow.COLUMNNAME_PP_Order_ID, MQuery.EQUAL, p_PP_Order_ID); - // Engine - PrintInfo info = new PrintInfo(MPPOrderWorkflow.Table_Name, MPPOrderWorkflow.Table_ID, p_PP_Order_ID); - ReportEngine re = new ReportEngine(getCtx(), format, query, info); - ReportCtl.preview(re); - re.print(); // prints only original - } - - return "@OK@"; - - } // doIt - - private MPrintFormat getAD_PrintFormat(int AD_Table_ID) - { - final String whereClause = MPrintFormat.COLUMNNAME_AD_Table_ID+"=?" - +" AND AD_Client_ID IN (0,?)"; - MPrintFormat format = new Query(getCtx(), MPrintFormat.Table_Name, whereClause, null) - .setParameters(new Object[]{AD_Table_ID, getAD_Client_ID()}) - .setOrderBy("IsDefault DESC, AD_Client_ID DESC") - .first(); - if (format == null) - { - return null; - } - Language language = Language.getLoginLanguage(); // Base Language - format.setLanguage(language); - format.setTranslationLanguage(language); - return format; - } -} // CompletePrintOrder