FR [ 2006255 ] Configurable "Create Periods" process.

Merge from old trunk.
This commit is contained in:
phib 2009-07-08 23:29:33 +00:00
parent 7897bc9bdc
commit c0e629b84d
4 changed files with 149 additions and 23 deletions

View File

@ -19,6 +19,7 @@ package org.compiere.model;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
@ -171,7 +172,7 @@ public class MYear extends X_C_Year
return true;
} // beforeSave
/**
/**
* Create 12 Standard (Jan-Dec) Periods.
* Creates also Period Control from DocType.
* @see DocumentTypeVerify#createPeriodControls(Properties, int, SvrProcess, String)
@ -179,6 +180,21 @@ public class MYear extends X_C_Year
* @return true if created
*/
public void createStdPeriods(Locale locale)
{
createStdPeriods(locale, null, null);
} // createStdPeriods
/**
* Create 12 Standard Periods from the specified start date.
* Creates also Period Control from DocType.
* @see DocumentTypeVerify#createPeriodControls(Properties, int, SvrProcess, String)
* @param locale locale
* @param startDate first day of the calendar year
* @param dateFormat SimpleDateFormat pattern for generating the period names.
* @return true if created
*/
public boolean createStdPeriods(Locale locale, Timestamp startDate, String dateFormat)
{
if (locale == null)
{
@ -191,35 +207,39 @@ public class MYear extends X_C_Year
if (locale == null)
locale = Env.getLanguage(getCtx()).getLocale();
//
String[] months = null;
try
{
DateFormatSymbols symbols = new DateFormatSymbols(locale);
months = symbols.getShortMonths();
}
catch (Exception e)
{
months = new String[]{"Jan", "Feb", "Nar",
"Apr", "May", "Jun",
"Jul", "Aug", "Sep",
"Oct", "Nov", "Dec"};
}
SimpleDateFormat formatter;
if ( dateFormat == null || dateFormat.equals("") )
dateFormat = "MMM-yy";
formatter = new SimpleDateFormat(dateFormat, locale);
//
int year = getYearAsInt();
GregorianCalendar cal = new GregorianCalendar(locale);
if ( startDate != null )
{
cal.setTime(startDate);
if ( cal.get(Calendar.YEAR) != year) // specified start date takes precedence in setting year
year = cal.get(Calendar.YEAR);
}
else
{
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DAY_OF_MONTH, 1);
}
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
//
for (int month = 0; month < 12; month++)
{
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, 1);
Timestamp start = new Timestamp(cal.getTimeInMillis());
String name = months[month] + "-" + getYY();
//
String name = formatter.format(start);
// get last day of same month
cal.add(Calendar.MONTH, 1);
cal.add(Calendar.DAY_OF_YEAR, -1);
Timestamp end = new Timestamp(cal.getTimeInMillis());
@ -238,7 +258,12 @@ public class MYear extends X_C_Year
period.setEndDate(end);
}
period.saveEx(get_TrxName()); // Creates Period Control
// get first day of next month
cal.add(Calendar.DAY_OF_YEAR, 1);
}
return true;
} // createStdPeriods
} // MYear

View File

@ -16,6 +16,9 @@
*****************************************************************************/
package org.compiere.process;
import java.sql.Timestamp;
import java.util.logging.Level;
import org.compiere.model.MYear;
import org.compiere.util.AdempiereUserError;
@ -28,12 +31,28 @@ import org.compiere.util.AdempiereUserError;
public class YearCreatePeriods extends SvrProcess
{
private int p_C_Year_ID = 0;
private Timestamp p_StartDate;
private String p_DateFormat;
/**
* Prepare
*/
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("StartDate"))
p_StartDate = (Timestamp) para[i].getParameter();
else if (name.equals("DateFormat"))
p_DateFormat = (String) para[i].getParameter();
else
log.log(Level.SEVERE, "Unknown Parameter: " + name);
}
p_C_Year_ID = getRecord_ID();
} // prepare
@ -50,8 +69,9 @@ public class YearCreatePeriods extends SvrProcess
throw new AdempiereUserError ("@NotFound@: @C_Year_ID@ - " + p_C_Year_ID);
log.info(year.toString());
//
year.createStdPeriods(null);
return "@OK@";
if (year.createStdPeriods(null, p_StartDate, p_DateFormat))
return "@OK@";
return "@Error@";
} // doIt
} // YearCreatePeriods

View File

@ -0,0 +1,41 @@
-- 26/06/2008 16:29:22
-- Period creation improvements
INSERT INTO AD_Process_Para (AD_Client_ID,AD_Element_ID,AD_Org_ID,AD_Process_ID,AD_Process_Para_ID,AD_Reference_ID,ColumnName,Created,CreatedBy,EntityType,FieldLength,IsActive,IsCentrallyMaintained,IsMandatory,IsRange,Name,SeqNo,Updated,UpdatedBy) VALUES (0,574,0,100,53203,15,'StartDate',TO_DATE('2008-06-26 16:29:19','YYYY-MM-DD HH24:MI:SS'),100,'D',0,'Y','Y','N','N','Start Date',10,TO_DATE('2008-06-26 16:29:19','YYYY-MM-DD HH24:MI:SS'),100)
;
-- 26/06/2008 16:29:22
-- Period creation improvements
INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=53203 AND EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Process_Para_ID!=t.AD_Process_Para_ID)
;
-- 26/06/2008 16:32:25
-- Period creation improvements
UPDATE AD_Process SET Description='Create 12 standard calendar periods.', Help='Creates 12 calendar month long standard periods from the specified start date. If no start date is specified, 1st of Jan will be used.',Updated=TO_DATE('2008-06-26 16:32:25','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=100
;
-- 26/06/2008 16:32:25
-- Period creation improvements
UPDATE AD_Process_Trl SET IsTranslated='N' WHERE AD_Process_ID=100
;
-- 26/06/2008 17:18:13
-- Period creation improvements
INSERT INTO AD_Process_Para (AD_Client_ID,AD_Org_ID,AD_Process_ID,AD_Process_Para_ID,AD_Reference_ID,ColumnName,Created,CreatedBy,DefaultValue,EntityType,FieldLength,IsActive,IsCentrallyMaintained,IsMandatory,IsRange,Name,SeqNo,Updated,UpdatedBy) VALUES (0,0,100,53205,10,'DateFormat',TO_DATE('2008-06-26 17:18:12','YYYY-MM-DD HH24:MI:SS'),100,'MMM-yy','D',0,'Y','Y','N','N','Period Name Format',20,TO_DATE('2008-06-26 17:18:12','YYYY-MM-DD HH24:MI:SS'),100)
;
-- 26/06/2008 17:18:13
-- Period creation improvements
INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=53205 AND EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Process_Para_ID!=t.AD_Process_Para_ID)
;
-- 26/06/2008 17:19:53
-- Period creation improvements
UPDATE AD_Process SET Help='Creates 12 calendar month long standard periods from the specified start date. If no start date is specified, 1st of Jan will be used. The period name will be generated from the start date of each period using the java SimpleDateFormat pattern provided. ',Updated=TO_DATE('2008-06-26 17:19:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=100
;
-- 26/06/2008 17:19:53
-- Period creation improvements
UPDATE AD_Process_Trl SET IsTranslated='N' WHERE AD_Process_ID=100
;

View File

@ -0,0 +1,40 @@
-- 26/06/2008 16:29:22
-- Period creation improvements
INSERT INTO AD_Process_Para (AD_Client_ID,AD_Element_ID,AD_Org_ID,AD_Process_ID,AD_Process_Para_ID,AD_Reference_ID,ColumnName,Created,CreatedBy,EntityType,FieldLength,IsActive,IsCentrallyMaintained,IsMandatory,IsRange,Name,SeqNo,Updated,UpdatedBy) VALUES (0,574,0,100,53203,15,'StartDate',TO_TIMESTAMP('2008-06-26 16:29:19','YYYY-MM-DD HH24:MI:SS'),100,'D',0,'Y','Y','N','N','Start Date',10,TO_TIMESTAMP('2008-06-26 16:29:19','YYYY-MM-DD HH24:MI:SS'),100)
;
-- 26/06/2008 16:29:22
-- Period creation improvements
INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=53203 AND EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Process_Para_ID!=t.AD_Process_Para_ID)
;
-- 26/06/2008 16:32:25
-- Period creation improvements
UPDATE AD_Process SET Description='Create 12 standard calendar periods.', Help='Creates 12 calendar month long standard periods from the specified start date. If no start date is specified, 1st of Jan will be used.',Updated=TO_TIMESTAMP('2008-06-26 16:32:25','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=100
;
-- 26/06/2008 16:32:25
-- Period creation improvements
UPDATE AD_Process_Trl SET IsTranslated='N' WHERE AD_Process_ID=100
;
-- 26/06/2008 17:18:13
-- Period creation improvements
INSERT INTO AD_Process_Para (AD_Client_ID,AD_Org_ID,AD_Process_ID,AD_Process_Para_ID,AD_Reference_ID,ColumnName,Created,CreatedBy,DefaultValue,EntityType,FieldLength,IsActive,IsCentrallyMaintained,IsMandatory,IsRange,Name,SeqNo,Updated,UpdatedBy) VALUES (0,0,100,53205,10,'DateFormat',TO_TIMESTAMP('2008-06-26 17:18:12','YYYY-MM-DD HH24:MI:SS'),100,'MMM-yy','D',0,'Y','Y','N','N','Period Name Format',20,TO_TIMESTAMP('2008-06-26 17:18:12','YYYY-MM-DD HH24:MI:SS'),100)
;
-- 26/06/2008 17:18:13
-- Period creation improvements
INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Description,t.Help,t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=53205 AND EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Process_Para_ID!=t.AD_Process_Para_ID)
;
-- 26/06/2008 17:19:53
-- Period creation improvements
UPDATE AD_Process SET Help='Creates 12 calendar month long standard periods from the specified start date. If no start date is specified, 1st of Jan will be used. The period name will be generated from the start date of each period using the java SimpleDateFormat pattern provided. ',Updated=TO_TIMESTAMP('2008-06-26 17:19:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=100
;
-- 26/06/2008 17:19:53
-- Period creation improvements
UPDATE AD_Process_Trl SET IsTranslated='N' WHERE AD_Process_ID=100
;