adempiere: cleanup libero

Lot more work to do. Any help is appreciated.
This commit is contained in:
teo_sarca 2009-02-05 16:56:45 +00:00
parent a72ef132f0
commit da13e38779
18 changed files with 0 additions and 4869 deletions

View File

@ -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<MPPOrder> 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;
}
}

View File

@ -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<EFBFBD>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<Col> list = new ArrayList<Col>();
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;
}
}
}

View File

@ -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<MProduct> 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;
}
}

View File

@ -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<MCost> 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";
}
}

View File

@ -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<Object> paramsElements = new ArrayList<Object>();
if (p_M_CostElement_ID > 0)
{
whereClauseElements = MCostElement.COLUMNNAME_M_CostElement_ID+"=?";
paramsElements.add(p_M_CostElement_ID);
}
Collection<MCostElement> elements = new Query(getCtx(), MCostElement.Table_Name, whereClauseElements, get_TrxName())
.setParameters(paramsElements)
.list();
String whereClauseProducts= "";
ArrayList<Object> paramsProducts= new ArrayList<Object>();
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<Object> paramsOrg = new ArrayList<Object>();
//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

View File

@ -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
}

View File

@ -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<Object> params = new ArrayList<Object>();
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++;
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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";
}
}

File diff suppressed because it is too large Load Diff

View File

@ -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 <Object> parameters = new ArrayList<Object>();
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 <MResource> 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<Object>();
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 <MOrg> 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 + "<br>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 + "<br>finish MRP to Organization " +organization.getName();
}
result = result + "<br>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<Object> params = new ArrayList<Object>();
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<Object> params = new ArrayList<Object>();
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<Object> params = new ArrayList<Object>();
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<Object> params = new ArrayList<Object>();
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<Object>();
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<Object> 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<Object> params)
{
// TODO: refactor this method and move it to org.compiere.model.Query class
POResultSet<PO> rs = new Query(getCtx(), tableName, whereClause, get_TrxName())
.setParameters(params)
.scroll();
try
{
while(rs.hasNext())
{
rs.next().deleteEx(true);
commit();
}
}
finally
{
rs.close();
}
}
}

View File

@ -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<Integer> m_list = new ArrayList<Integer>();
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 <Integer> tabla = new ArrayList<Integer>();
while (rsMail.next())
{
tabla.add(new Integer(rsMail.getInt(3)));
}
for(int i=0;i<tabla.size();i++)
{
Boolean ok = sendIndividualMail ("", tabla.get(i).intValue(), null);
if (ok == null);
else if (ok.booleanValue())
m_counter++;
else
m_errors++;
}
rsMail.close();
pstmt.close();
pstmt = null;
}
catch (SQLException ex)
{
log.log(Level.SEVERE, sql, ex);
}
// Clean Up
try
{
if (pstmt != null)
pstmt.close();
}
catch (SQLException ex1)
{
}
pstmt = null;
} // sendBPGroup
/**
* Send Individual Mail
* @param Name user name
* @param AD_User_ID user
* @param unsubscribe unsubscribe message
* @return true if mail has been sent
*/
private Boolean sendIndividualMail (String Name, int C_BPartner_ID,String unsubscribe)
{
// Prevent two email
try
{
Integer ii = new Integer (C_BPartner_ID);
//int BPartner_ID=0;
if (m_list.contains(ii))
return null;
m_list.add(ii);
//
//MUser to = new MUser (getCtx(), AD_User_ID, null);
MBPartner to = new MBPartner(getCtx(), C_BPartner_ID, null);
//m_MailText.setUser(AD_User_ID); // parse context
//BPartner_ID=to.getC_BPartner_ID();
String message = m_MailText.getMailText(true);
// Unsubscribe
if (unsubscribe != null)
message += unsubscribe;
//
//EMail email = new EMail(m_client,m_from.getEMail(),to.getURL(),m_MailText.getMailHeader(), message);
EMail email = m_client.createEMail(m_from, to.getURL(), m_MailText.getMailHeader(), message);
if (m_MailText.isHtml())
email.setMessageHTML(m_MailText.getMailHeader(), message);
else
{
email.setSubject (m_MailText.getMailHeader());
email.setMessageText (message);
}
email.addAttachment(CreatePDF(C_BPartner_ID));
if (!email.isValid() && !email.isValid(true))
{
log.warning("NOT VALID - " + email);
to.setIsActive(false);
to.save();
return Boolean.FALSE;
}
boolean OK = EMail.SENT_OK.equals(email.send());
//new MUserMail(m_MailText, AD_User_ID, email).save();
//
if (OK)
log.fine(to.getURL());
else
log.warning("FAILURE - " + to.getURL());
addLog(0, null, null, (OK ? "@OK@" : "@ERROR@") + " - " + to.getURL());
return new Boolean(OK);
}catch(Exception e)
{
return new Boolean(false);
}
} // sendIndividualMail
private File CreatePDF(int BPartner_ID)
{
File attachment = null;
int AD_Process_ID = m_AD_Process_ID;
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
if (!instance.save())
{
return null;
}
//call process
ProcessInfo pi = new ProcessInfo ("PH_SendEmail", AD_Process_ID);
pi.setAD_PInstance_ID (instance.getAD_PInstance_ID());
// Add Parameter - Selection=Y
MPInstancePara ip = new MPInstancePara(instance, 10);
pi.setRecord_ID(m_HR_Process_ID);
pi.setIsBatch(true);
MProcess worker = new MProcess(getCtx(),AD_Process_ID,get_TrxName());
worker.processIt(pi, Trx.get(get_TrxName(), true));
attachment=pi.getPDFReport();
return attachment;
}
} // SendMailText

View File

@ -1,219 +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.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.MCostType;
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.MPPMRP;
import org.eevolution.model.MPPProductBOM;
import org.eevolution.model.MPPProductBOMLine;
import org.eevolution.model.MPPProductPlanning;
/**
* Roll-UP Bill of Material
*
* @author victor.perez@e-evolution.com, e-Evolution, S.C.
* @version $Id: RollupBillOfMaterial.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $
*/
public class RollupBillOfMaterial 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;
/* Costing Method */
private String p_ConstingMethod = MCostElement.COSTINGMETHOD_StandardCosting;
/* Product */
private int p_M_Product_ID = 0;
/* Product Category */
private int p_M_Product_Category_ID = 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(MCostElement.COLUMNNAME_AD_Org_ID))
p_AD_Org_ID = para.getParameterAsInt();
else if (name.equals(MAcctSchema.COLUMNNAME_C_AcctSchema_ID))
p_C_AcctSchema_ID = para.getParameterAsInt();
else if (name.equals(MCostType.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
/**
* Generate Calculate Cost
* @return info
* @throws Exception
*/
protected String doIt() throws Exception
{
int maxLowLevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName());
// Cost Roll-up for all levels
for (int lowLevel = maxLowLevel; lowLevel >= 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<MCostElement> 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<MCost> 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<MProduct> getProducts(int lowLevel)
{
List<Object> params = new ArrayList<Object>();
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();
}
}

View File

@ -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
* <li>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<Object> params = new ArrayList<Object>();
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<MProduct> 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<MCostElement> elements = MCostElement.getByCostingMethod(getCtx(), p_ConstingMethod);
for (MCostElement element : elements)
{
Collection<MCost> 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@";
}
}

View File

@ -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 <MCostElement> 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<MPPProductBOM> 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<MPPProductBOM> getBOMs(MProduct product, boolean includeAlternativeBOMs)
{
ArrayList<Object> params = new ArrayList<Object>();
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<MPPProductBOM> 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 <MCost> 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++;
}
}
}

View File

@ -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