IDEMPIERE-332 Document sequence organization level and restart monthly / Thanks to Nicolas Micoud

This commit is contained in:
Carlos Ruiz 2012-09-07 16:56:44 -05:00
parent 0329963b14
commit 368ce19b6e
15 changed files with 1022 additions and 864 deletions

View File

@ -1,25 +0,0 @@
CREATE or REPLACE PROCEDURE NextIDByYear
(
p_AD_Sequence_ID IN NUMBER,
p_IncrementNo IN NUMBER,
p_CalendarYear IN CHAR,
o_NextID OUT NUMBER
)
AS
BEGIN
SELECT CurrentNext
INTO o_NextID
FROM AD_Sequence_No
WHERE AD_Sequence_ID=p_AD_Sequence_ID
AND CalendarYear = p_CalendarYear
FOR UPDATE OF CurrentNext;
--
UPDATE AD_Sequence_No
SET CurrentNext = CurrentNext + p_IncrementNo
WHERE AD_Sequence_ID=p_AD_Sequence_ID
AND CalendarYear = p_CalendarYear;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END NextIDByYear;
/

View File

@ -1,24 +0,0 @@
CREATE or REPLACE FUNCTION NextIDByYear
(
p_AD_Sequence_ID IN numeric,
p_IncrementNo IN numeric,
p_CalendarYear IN varchar
)
RETURNS numeric AS $$
DECLARE
o_NextID numeric;
BEGIN
SELECT CurrentNext
INTO o_NextID
FROM ad_sequence_no
WHERE AD_Sequence_ID=p_AD_Sequence_ID
AND CalendarYear = p_CalendarYear
FOR UPDATE OF ad_sequence_no;
--
UPDATE ad_sequence_no
SET CurrentNext = CurrentNext + p_IncrementNo
WHERE AD_Sequence_ID=p_AD_Sequence_ID
AND CalendarYear = p_CalendarYear;
RETURN o_NextID;
END
$$ LANGUAGE plpgsql;

View File

@ -0,0 +1,240 @@
-- Jul 12, 2012 9:29:41 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,200060,0,'StartNewMonth',TO_DATE('2012-07-12 09:29:39','YYYY-MM-DD HH24:MI:SS'),0,'D','Y','Restart sequence every month','Restart sequence every month',TO_DATE('2012-07-12 09:29:39','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:29:41 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=200060 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Jul 12, 2012 9:30:32 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,Description,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,200061,0,'IsOrgLevelSequence',TO_DATE('2012-07-12 09:30:32','YYYY-MM-DD HH24:MI:SS'),0,'This sequence can be defined for each organization','D','Y','Organization level','Organization level',TO_DATE('2012-07-12 09:30:32','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:30:32 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=200061 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Jul 12, 2012 9:32:18 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,DefaultValue,EntityType,FieldLength,IsActive,IsAllowCopy,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,200212,200060,0,20,115,'StartNewMonth',TO_DATE('2012-07-12 09:32:18','YYYY-MM-DD HH24:MI:SS'),0,'N','D',1,'Y','Y','Y','N','N','N','N','N','Y','N','N','N','N','Y','Restart sequence every month',0,TO_DATE('2012-07-12 09:32:18','YYYY-MM-DD HH24:MI:SS'),0,0)
;
-- Jul 12, 2012 9:32:19 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=200212 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Jul 12, 2012 9:32:48 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
ALTER TABLE AD_Sequence ADD StartNewMonth CHAR(1) DEFAULT 'N' CHECK (StartNewMonth IN ('Y','N')) NOT NULL
;
-- Jul 12, 2012 9:33:30 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,DefaultValue,Description,EntityType,FieldLength,IsActive,IsAllowCopy,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,200213,200061,0,20,115,'IsOrgLevelSequence',TO_DATE('2012-07-12 09:33:29','YYYY-MM-DD HH24:MI:SS'),0,'N','This sequence can be defined for each organization','D',1,'Y','Y','Y','N','N','N','N','N','Y','N','N','N','N','Y','Organization level',0,TO_DATE('2012-07-12 09:33:29','YYYY-MM-DD HH24:MI:SS'),0,0)
;
-- Jul 12, 2012 9:33:30 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=200213 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Jul 12, 2012 9:33:31 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
ALTER TABLE AD_Sequence ADD IsOrgLevelSequence CHAR(1) DEFAULT 'N' CHECK (IsOrgLevelSequence IN ('Y','N')) NOT NULL
;
-- Jul 12, 2012 9:34:03 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,Description,EntityType,FieldLength,Help,IsActive,IsAllowCopy,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,MandatoryLogic,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,200214,1591,0,10,115,'OrgColumn',TO_DATE('2012-07-12 09:34:03','YYYY-MM-DD HH24:MI:SS'),0,'Fully qualified Organization column (AD_Org_ID)','D',60,'The Organization Column indicates the organization to be used in calculating this measurement.','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','Y','@IsUseOrgLevelSequence@=Y','Org Column',0,TO_DATE('2012-07-12 09:34:03','YYYY-MM-DD HH24:MI:SS'),0,0)
;
-- Jul 12, 2012 9:34:03 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=200214 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Jul 12, 2012 9:34:04 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
ALTER TABLE AD_Sequence ADD OrgColumn NVARCHAR2(60) DEFAULT NULL
;
-- Jul 12, 2012 9:35:04 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength,EntityType,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,200213,200162,0,146,TO_DATE('2012-07-12 09:35:03','YYYY-MM-DD HH24:MI:SS'),0,'This sequence can be defined for each organization',0,'D','Y','Y','Y','N','N','N','N','N','Organization level',170,0,TO_DATE('2012-07-12 09:35:03','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:35:04 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_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_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=200162 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Jul 12, 2012 9:35:24 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength,DisplayLogic,EntityType,Help,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,200214,200163,0,146,TO_DATE('2012-07-12 09:35:23','YYYY-MM-DD HH24:MI:SS'),0,'Fully qualified Organization column (AD_Org_ID)',0,'@IsOrgLevelSequence@=Y','D','The Organization Column indicates the organization to be used in calculating this measurement.','Y','Y','Y','N','N','N','N','Y','Org Column',180,0,TO_DATE('2012-07-12 09:35:23','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:35:24 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_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_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=200163 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Jul 12, 2012 9:35:39 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,DisplayLength,DisplayLogic,EntityType,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,200212,200164,0,146,TO_DATE('2012-07-12 09:35:39','YYYY-MM-DD HH24:MI:SS'),0,0,'@StartNewYear@=Y','D','Y','Y','Y','N','N','N','N','N','Restart sequence every month',190,0,TO_DATE('2012-07-12 09:35:39','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:35:39 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_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_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=200164 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=110,IsDisplayed='Y' WHERE AD_Field_ID=54391
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=120,IsDisplayed='Y' WHERE AD_Field_ID=332
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=130,IsDisplayed='Y' WHERE AD_Field_ID=333
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=140,IsDisplayed='Y' WHERE AD_Field_ID=200162
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=150,IsDisplayed='Y' WHERE AD_Field_ID=200163
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=160,IsDisplayed='Y' WHERE AD_Field_ID=335
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=170,IsDisplayed='Y' WHERE AD_Field_ID=54357
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=180,IsDisplayed='Y' WHERE AD_Field_ID=200164
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=190,IsDisplayed='Y' WHERE AD_Field_ID=1555
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=200,IsDisplayed='Y' WHERE AD_Field_ID=334
;
-- Jul 12, 2012 9:38:29 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET DisplayLogic='@IsAutoSequence@=Y & @IsTableID@=N', IsSameLine='N',Updated=TO_DATE('2012-07-12 09:38:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=1555
;
-- Jul 12, 2012 9:38:51 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET IsSameLine='Y',Updated=TO_DATE('2012-07-12 09:38:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=54357
;
-- Jul 12, 2012 9:41:56 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,Description,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,200062,0,'CalendarYearMonth',TO_DATE('2012-07-12 09:41:55','YYYY-MM-DD HH24:MI:SS'),0,'YYYYMM','D','Y','YearMonth','YearMonth',TO_DATE('2012-07-12 09:41:55','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:41:56 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=200062 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Aug 1, 2012 8:32:42 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Column SET Help=NULL, FieldLength=6, AD_Element_ID=200062, IsUpdateable='N', ColumnName='CalendarYearMonth', Description='YYYYMM', Name='YearMonth',Updated=TO_DATE('2012-08-01 08:32:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=262
;
-- Aug 1, 2012 8:32:42 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Column_Trl SET IsTranslated='N' WHERE AD_Column_ID=262
;
-- Aug 1, 2012 8:32:42 AM COT
UPDATE AD_Field SET Name='YearMonth', Description='YYYYMM', Help=NULL WHERE AD_Column_ID=262 AND IsCentrallyMaintained='Y'
;
ALTER TABLE AD_SEQUENCE_NO MODIFY ( CALENDARYEAR VARCHAR2(6) )
;
ALTER TABLE AD_SEQUENCE_NO RENAME COLUMN CALENDARYEAR TO CALENDARYEARMONTH
;
ALTER TABLE AD_SEQUENCE_NO DROP CONSTRAINT AD_SEQUENCE_NO_KEY
;
DROP INDEX AD_SEQUENCE_NO_KEY
;
ALTER TABLE AD_SEQUENCE_NO ADD ( CONSTRAINT AD_SEQUENCE_NO_KEY PRIMARY KEY (AD_SEQUENCE_ID, CALENDARYEARMONTH, AD_ORG_ID) )
;
-- Jul 12, 2012 9:44:43 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Tab SET DisplayLogic='@StartNewYear@=''Y'' | @IsOrgLevelSequence@=Y',Updated=TO_DATE('2012-07-12 09:44:43','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Tab_ID=200001
;
-- Jul 12, 2012 9:46:03 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Column SET ReadOnlyLogic='@StartNewYear@=N & @IsOrgLevelSequence@=N',Updated=TO_DATE('2012-07-12 09:46:03','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=2746
;
DROP PROCEDURE nextidbyyear;
-- Sep 7, 2012 11:04:53 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Process_Para SET IsActive='N',Updated=TO_DATE('2012-09-07 11:04:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=53129
;
-- Sep 7, 2012 11:04:57 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Process SET IsActive='N',Updated=TO_DATE('2012-09-07 11:04:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=53068
;
-- Sep 7, 2012 11:04:57 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Menu SET Name='Update Sequence No', Description=NULL, IsActive='N',Updated=TO_DATE('2012-09-07 11:04:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Menu_ID=53087
;
-- Sep 7, 2012 11:04:57 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Menu_Trl SET IsTranslated='N' WHERE AD_Menu_ID=53087
;
-- Sep 7, 2012 2:30:26 PM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET DisplayLogic='@IsTableID@=N',Updated=TO_DATE('2012-09-07 14:30:26','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=200162
;
-- Sep 7, 2012 2:32:51 PM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Sequence SET StartNewMonth='Y', IsOrgLevelSequence='Y', OrgColumn='AD_Org_ID', StartNewYear='Y', Prefix='@AD_Org_ID<AD_Org.Value>@-', DateColumn='DateOrdered', Suffix='-@DateAcct<yyyyMM>@', DecimalPattern='0000000',Updated=TO_DATE('2012-09-07 14:32:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Sequence_ID=383
;
UPDATE AD_System
SET LastMigrationScriptApplied='856_IDEMPIERE_332.sql'
WHERE LastMigrationScriptApplied<'856_IDEMPIERE_332.sql'
OR LastMigrationScriptApplied IS NULL;

View File

@ -0,0 +1,237 @@
-- Jul 12, 2012 9:29:41 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,200060,0,'StartNewMonth',TO_TIMESTAMP('2012-07-12 09:29:39','YYYY-MM-DD HH24:MI:SS'),0,'D','Y','Restart sequence every month','Restart sequence every month',TO_TIMESTAMP('2012-07-12 09:29:39','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:29:41 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=200060 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Jul 12, 2012 9:30:32 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,Description,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,200061,0,'IsOrgLevelSequence',TO_TIMESTAMP('2012-07-12 09:30:32','YYYY-MM-DD HH24:MI:SS'),0,'This sequence can be defined for each organization','D','Y','Organization level','Organization level',TO_TIMESTAMP('2012-07-12 09:30:32','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:30:32 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=200061 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Jul 12, 2012 9:32:18 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,DefaultValue,EntityType,FieldLength,IsActive,IsAllowCopy,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,200212,200060,0,20,115,'StartNewMonth',TO_TIMESTAMP('2012-07-12 09:32:18','YYYY-MM-DD HH24:MI:SS'),0,'N','D',1,'Y','Y','Y','N','N','N','N','N','Y','N','N','N','N','Y','Restart sequence every month',0,TO_TIMESTAMP('2012-07-12 09:32:18','YYYY-MM-DD HH24:MI:SS'),0,0)
;
-- Jul 12, 2012 9:32:19 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=200212 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Jul 12, 2012 9:32:48 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
ALTER TABLE AD_Sequence ADD COLUMN StartNewMonth CHAR(1) DEFAULT 'N' CHECK (StartNewMonth IN ('Y','N')) NOT NULL
;
-- Jul 12, 2012 9:33:30 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,DefaultValue,Description,EntityType,FieldLength,IsActive,IsAllowCopy,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,200213,200061,0,20,115,'IsOrgLevelSequence',TO_TIMESTAMP('2012-07-12 09:33:29','YYYY-MM-DD HH24:MI:SS'),0,'N','This sequence can be defined for each organization','D',1,'Y','Y','Y','N','N','N','N','N','Y','N','N','N','N','Y','Organization level',0,TO_TIMESTAMP('2012-07-12 09:33:29','YYYY-MM-DD HH24:MI:SS'),0,0)
;
-- Jul 12, 2012 9:33:30 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=200213 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Jul 12, 2012 9:33:31 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
ALTER TABLE AD_Sequence ADD COLUMN IsOrgLevelSequence CHAR(1) DEFAULT 'N' CHECK (IsOrgLevelSequence IN ('Y','N')) NOT NULL
;
-- Jul 12, 2012 9:34:03 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column (AD_Client_ID,AD_Column_ID,AD_Element_ID,AD_Org_ID,AD_Reference_ID,AD_Table_ID,ColumnName,Created,CreatedBy,Description,EntityType,FieldLength,Help,IsActive,IsAllowCopy,IsAllowLogging,IsAlwaysUpdateable,IsAutocomplete,IsEncrypted,IsIdentifier,IsKey,IsMandatory,IsParent,IsSelectionColumn,IsSyncDatabase,IsTranslated,IsUpdateable,MandatoryLogic,Name,SeqNo,Updated,UpdatedBy,Version) VALUES (0,200214,1591,0,10,115,'OrgColumn',TO_TIMESTAMP('2012-07-12 09:34:03','YYYY-MM-DD HH24:MI:SS'),0,'Fully qualified Organization column (AD_Org_ID)','D',60,'The Organization Column indicates the organization to be used in calculating this measurement.','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','Y','@IsUseOrgLevelSequence@=Y','Org Column',0,TO_TIMESTAMP('2012-07-12 09:34:03','YYYY-MM-DD HH24:MI:SS'),0,0)
;
-- Jul 12, 2012 9:34:03 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Column_Trl (AD_Language,AD_Column_ID, Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Column_ID, t.Name, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Column t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Column_ID=200214 AND NOT EXISTS (SELECT * FROM AD_Column_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Column_ID=t.AD_Column_ID)
;
-- Jul 12, 2012 9:34:04 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
ALTER TABLE AD_Sequence ADD COLUMN OrgColumn VARCHAR(60) DEFAULT NULL
;
-- Jul 12, 2012 9:35:04 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength,EntityType,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,200213,200162,0,146,TO_TIMESTAMP('2012-07-12 09:35:03','YYYY-MM-DD HH24:MI:SS'),0,'This sequence can be defined for each organization',0,'D','Y','Y','Y','N','N','N','N','N','Organization level',170,0,TO_TIMESTAMP('2012-07-12 09:35:03','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:35:04 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_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_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=200162 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Jul 12, 2012 9:35:24 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,Description,DisplayLength,DisplayLogic,EntityType,Help,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,200214,200163,0,146,TO_TIMESTAMP('2012-07-12 09:35:23','YYYY-MM-DD HH24:MI:SS'),0,'Fully qualified Organization column (AD_Org_ID)',0,'@IsOrgLevelSequence@=Y','D','The Organization Column indicates the organization to be used in calculating this measurement.','Y','Y','Y','N','N','N','N','Y','Org Column',180,0,TO_TIMESTAMP('2012-07-12 09:35:23','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:35:24 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_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_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=200163 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Jul 12, 2012 9:35:39 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field (AD_Client_ID,AD_Column_ID,AD_Field_ID,AD_Org_ID,AD_Tab_ID,Created,CreatedBy,DisplayLength,DisplayLogic,EntityType,IsActive,IsCentrallyMaintained,IsDisplayed,IsEncrypted,IsFieldOnly,IsHeading,IsReadOnly,IsSameLine,Name,SeqNo,SortNo,Updated,UpdatedBy) VALUES (0,200212,200164,0,146,TO_TIMESTAMP('2012-07-12 09:35:39','YYYY-MM-DD HH24:MI:SS'),0,0,'@StartNewYear@=Y','D','Y','Y','Y','N','N','N','N','N','Restart sequence every month',190,0,TO_TIMESTAMP('2012-07-12 09:35:39','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:35:39 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Field_Trl (AD_Language,AD_Field_ID, Description,Help,Name, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Field_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_Field t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Field_ID=200164 AND NOT EXISTS (SELECT * FROM AD_Field_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Field_ID=t.AD_Field_ID)
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=110,IsDisplayed='Y' WHERE AD_Field_ID=54391
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=120,IsDisplayed='Y' WHERE AD_Field_ID=332
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=130,IsDisplayed='Y' WHERE AD_Field_ID=333
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=140,IsDisplayed='Y' WHERE AD_Field_ID=200162
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=150,IsDisplayed='Y' WHERE AD_Field_ID=200163
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=160,IsDisplayed='Y' WHERE AD_Field_ID=335
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=170,IsDisplayed='Y' WHERE AD_Field_ID=54357
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=180,IsDisplayed='Y' WHERE AD_Field_ID=200164
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=190,IsDisplayed='Y' WHERE AD_Field_ID=1555
;
-- Jul 12, 2012 9:36:20 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET SeqNo=200,IsDisplayed='Y' WHERE AD_Field_ID=334
;
-- Jul 12, 2012 9:38:29 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET DisplayLogic='@IsAutoSequence@=Y & @IsTableID@=N', IsSameLine='N',Updated=TO_TIMESTAMP('2012-07-12 09:38:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=1555
;
-- Jul 12, 2012 9:38:51 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET IsSameLine='Y',Updated=TO_TIMESTAMP('2012-07-12 09:38:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=54357
;
-- Jul 12, 2012 9:41:56 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element (AD_Client_ID,AD_Element_ID,AD_Org_ID,ColumnName,Created,CreatedBy,Description,EntityType,IsActive,Name,PrintName,Updated,UpdatedBy) VALUES (0,200062,0,'CalendarYearMonth',TO_TIMESTAMP('2012-07-12 09:41:55','YYYY-MM-DD HH24:MI:SS'),0,'YYYYMM','D','Y','YearMonth','YearMonth',TO_TIMESTAMP('2012-07-12 09:41:55','YYYY-MM-DD HH24:MI:SS'),0)
;
-- Jul 12, 2012 9:41:56 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
INSERT INTO AD_Element_Trl (AD_Language,AD_Element_ID, Description,Help,Name,PO_Description,PO_Help,PO_Name,PO_PrintName,PrintName, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Element_ID, t.Description,t.Help,t.Name,t.PO_Description,t.PO_Help,t.PO_Name,t.PO_PrintName,t.PrintName, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Element t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Element_ID=200062 AND NOT EXISTS (SELECT * FROM AD_Element_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Element_ID=t.AD_Element_ID)
;
-- Aug 1, 2012 8:32:42 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Column SET Help=NULL, FieldLength=6, AD_Element_ID=200062, IsUpdateable='N', ColumnName='CalendarYearMonth', Description='YYYYMM', Name='YearMonth',Updated=TO_TIMESTAMP('2012-08-01 08:32:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=262
;
-- Aug 1, 2012 8:32:42 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Column_Trl SET IsTranslated='N' WHERE AD_Column_ID=262
;
-- Aug 1, 2012 8:32:42 AM COT
UPDATE AD_Field SET Name='YearMonth', Description='YYYYMM', Help=NULL WHERE AD_Column_ID=262 AND IsCentrallyMaintained='Y'
;
ALTER TABLE ad_sequence_no ALTER COLUMN calendaryear TYPE varchar(6)
;
ALTER TABLE ad_sequence_no RENAME calendaryear TO calendaryearmonth
;
ALTER TABLE ad_sequence_no DROP CONSTRAINT ad_sequence_no_pkey CASCADE
;
ALTER TABLE ad_sequence_no ADD CONSTRAINT ad_sequence_no_pkey PRIMARY KEY (ad_sequence_id, calendaryearmonth, ad_org_id)
;
-- Jul 12, 2012 9:44:43 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Tab SET DisplayLogic='@StartNewYear@=''Y'' | @IsOrgLevelSequence@=Y',Updated=TO_TIMESTAMP('2012-07-12 09:44:43','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Tab_ID=200001
;
-- Jul 12, 2012 9:46:03 AM CEST
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Column SET ReadOnlyLogic='@StartNewYear@=N & @IsOrgLevelSequence@=N',Updated=TO_TIMESTAMP('2012-07-12 09:46:03','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=2746
;
DROP FUNCTION nextidbyyear(numeric, numeric, character varying);
-- Sep 7, 2012 11:04:53 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Process_Para SET IsActive='N',Updated=TO_TIMESTAMP('2012-09-07 11:04:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=53129
;
-- Sep 7, 2012 11:04:57 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Process SET IsActive='N',Updated=TO_TIMESTAMP('2012-09-07 11:04:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=53068
;
-- Sep 7, 2012 11:04:57 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Menu SET Name='Update Sequence No', Description=NULL, IsActive='N',Updated=TO_TIMESTAMP('2012-09-07 11:04:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Menu_ID=53087
;
-- Sep 7, 2012 11:04:57 AM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Menu_Trl SET IsTranslated='N' WHERE AD_Menu_ID=53087
;
-- Sep 7, 2012 2:30:26 PM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Field SET DisplayLogic='@IsTableID@=N',Updated=TO_TIMESTAMP('2012-09-07 14:30:26','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=200162
;
-- Sep 7, 2012 2:32:51 PM COT
-- IDEMPIERE-332 Document sequence organization level and restart monthly
UPDATE AD_Sequence SET StartNewMonth='Y', IsOrgLevelSequence='Y', OrgColumn='AD_Org_ID', StartNewYear='Y', Prefix='@AD_Org_ID<AD_Org.Value>@-', DateColumn='DateOrdered', Suffix='-@DateAcct<yyyyMM>@', DecimalPattern='0000000',Updated=TO_TIMESTAMP('2012-09-07 14:32:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Sequence_ID=383
;
UPDATE AD_System
SET LastMigrationScriptApplied='856_IDEMPIERE_332.sql'
WHERE LastMigrationScriptApplied<'856_IDEMPIERE_332.sql'
OR LastMigrationScriptApplied IS NULL;

View File

@ -174,8 +174,8 @@ public class CalloutInOut extends CalloutEngine
if (C_DocType_ID == null || C_DocType_ID.intValue() == 0)
return "";
String sql = "SELECT d.DocBaseType, d.IsDocNoControlled, s.CurrentNext, " //1..3
+ "s.AD_Sequence_ID, s.StartNewYear, s.DateColumn, d.IsSOTrx " //4..7
String sql = "SELECT d.DocBaseType, d.IsDocNoControlled, " //1..2
+ "s.AD_Sequence_ID, d.IsSOTrx " //3..4
+ "FROM C_DocType d "
+ "LEFT OUTER JOIN AD_Sequence s ON (d.DocNoSequence_ID=s.AD_Sequence_ID) "
+ "WHERE C_DocType_ID=?"; // 1
@ -192,7 +192,7 @@ public class CalloutInOut extends CalloutEngine
// Set Movement Type
String DocBaseType = rs.getString("DocBaseType");
// BF [2708789] Read IsSOTrx from C_DocType
String trxFlag = rs.getString(7);
String trxFlag = rs.getString("IsSOTrx");
if (!(trxFlag.equals(mTab.getValue("IsSOTrx"))))
mTab.setValue("IsSOTrx", trxFlag);
if (DocBaseType.equals("MMS")) // Material Shipments
@ -220,17 +220,8 @@ public class CalloutInOut extends CalloutEngine
// DocumentNo
if (rs.getString("IsDocNoControlled").equals("Y"))
{
if ("Y".equals(rs.getString(5)))
{
String dateColumn = rs.getString(6);
int AD_Sequence_ID = rs.getInt(4);
mTab.setValue("DocumentNo",
"<"
+ MSequence.getPreliminaryNoByYear(mTab, AD_Sequence_ID, dateColumn, null)
+ ">");
}
else
mTab.setValue("DocumentNo", "<" + rs.getString("CurrentNext") + ">");
int AD_Sequence_ID = rs.getInt("AD_Sequence_ID");
mTab.setValue("DocumentNo", MSequence.getPreliminaryNo(mTab, AD_Sequence_ID));
}
}
}

View File

@ -59,12 +59,12 @@ public class CalloutInvoice extends CalloutEngine
if (C_DocType_ID == null || C_DocType_ID.intValue() == 0)
return "";
String sql = "SELECT d.HasCharges,'N',d.IsDocNoControlled," // 1..3
+ "s.CurrentNext, d.DocBaseType, " // 4..5
+ "s.StartNewYear, s.DateColumn, s.AD_Sequence_ID " //6..8
+ "FROM C_DocType d, AD_Sequence s "
+ "WHERE C_DocType_ID=?" // 1
+ " AND d.DocNoSequence_ID=s.AD_Sequence_ID(+)";
String sql = "SELECT d.HasCharges,d.IsDocNoControlled," // 1..2
+ "d.DocBaseType, " // 3
+ "s.AD_Sequence_ID " //4
+ "FROM C_DocType d "
+ "LEFT OUTER JOIN AD_Sequence s ON (d.DocNoSequence_ID=s.AD_Sequence_ID) "
+ "WHERE C_DocType_ID=?"; // 1
PreparedStatement pstmt = null;
ResultSet rs = null;
try
@ -75,23 +75,15 @@ public class CalloutInvoice extends CalloutEngine
if (rs.next())
{
// Charges - Set Context
Env.setContext(ctx, WindowNo, "HasCharges", rs.getString(1));
Env.setContext(ctx, WindowNo, "HasCharges", rs.getString("HasCharges"));
// DocumentNo
if (rs.getString(3).equals("Y"))
if (rs.getString("IsDocNoControlled").equals("Y"))
{
if ("Y".equals(rs.getString(6)))
{
String dateColumn = rs.getString(7);
mTab.setValue("DocumentNo",
"<"
+ MSequence.getPreliminaryNoByYear(mTab, rs.getInt(8), dateColumn, null)
+ ">");
}
else
mTab.setValue("DocumentNo", "<" + rs.getString(4) + ">");
int AD_Sequence_ID = rs.getInt("AD_Sequence_ID");
mTab.setValue("DocumentNo", MSequence.getPreliminaryNo(mTab, AD_Sequence_ID));
}
// DocBaseType - Set Context
String s = rs.getString(5);
String s = rs.getString("DocBaseType");
Env.setContext(ctx, WindowNo, "DocBaseType", s);
// AP Check & AR Credit Memo
if (s.startsWith("AP"))
@ -108,6 +100,7 @@ public class CalloutInvoice extends CalloutEngine
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return "";
} // docType

View File

@ -72,18 +72,17 @@ public class CalloutOrder extends CalloutEngine
newDocNo = true;
Integer oldC_DocType_ID = (Integer)mTab.getValue("C_DocType_ID");
String sql = "SELECT d.DocSubTypeSO,d.HasCharges,'N'," // 1..3
+ "d.IsDocNoControlled,s.CurrentNext,s.CurrentNextSys," // 4..6
+ "s.AD_Sequence_ID,d.IsSOTrx, " // 7..8
+ "s.StartNewYear, s.DateColumn " // 9..10
+ "FROM C_DocType d, AD_Sequence s "
+ "WHERE C_DocType_ID=?" // #1
+ " AND d.DocNoSequence_ID=s.AD_Sequence_ID(+)";
String sql = "SELECT d.DocSubTypeSO,d.HasCharges," // 1..2
+ "d.IsDocNoControlled," // 3
+ "s.AD_Sequence_ID,d.IsSOTrx " // 4..5
+ "FROM C_DocType d "
+ "LEFT OUTER JOIN AD_Sequence s ON (d.DocNoSequence_ID=s.AD_Sequence_ID) "
+ "WHERE C_DocType_ID=?"; // #1
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
int AD_Sequence_ID = 0;
int oldAD_Sequence_ID = 0;
// Get old AD_SeqNo for comparison
if (!newDocNo && oldC_DocType_ID.intValue() != 0)
@ -92,7 +91,7 @@ public class CalloutOrder extends CalloutEngine
pstmt.setInt(1, oldC_DocType_ID.intValue());
rs = pstmt.executeQuery();
if (rs.next())
AD_Sequence_ID = rs.getInt(7);
oldAD_Sequence_ID = rs.getInt("AD_Sequence_ID");
DB.close(rs, pstmt);
rs = null;
pstmt = null;
@ -106,7 +105,7 @@ public class CalloutOrder extends CalloutEngine
if (rs.next()) // we found document type
{
// Set Context: Document Sub Type for Sales Orders
DocSubTypeSO = rs.getString(1);
DocSubTypeSO = rs.getString("DocSubTypeSO");
if (DocSubTypeSO == null)
DocSubTypeSO = "--";
Env.setContext(ctx, WindowNo, "OrderType", DocSubTypeSO);
@ -137,34 +136,20 @@ public class CalloutOrder extends CalloutEngine
mTab.setValue("PaymentRule", X_C_Order.PAYMENTRULE_OnCredit);
// IsSOTrx
if ("N".equals(rs.getString(8)))
if ("N".equals(rs.getString("IsSOTrx")))
IsSOTrx = false;
// Set Context:
Env.setContext(ctx, WindowNo, "HasCharges", rs.getString(2));
Env.setContext(ctx, WindowNo, "HasCharges", rs.getString("HasCharges"));
// DocumentNo
if (rs.getString(4).equals("Y")) // IsDocNoControlled
if (rs.getString("IsDocNoControlled").equals("Y")) // IsDocNoControlled
{
if (!newDocNo && AD_Sequence_ID != rs.getInt(7))
if (!newDocNo && oldAD_Sequence_ID != rs.getInt("AD_Sequence_ID"))
newDocNo = true;
if (newDocNo)
if (Ini.isPropertyBool(Ini.P_ADEMPIERESYS) && Env.getAD_Client_ID(Env.getCtx()) < 1000000)
mTab.setValue("DocumentNo", "<" + rs.getString(6) + ">");
else
{
if ("Y".equals(rs.getString(9)))
{
String dateColumn = rs.getString(10);
mTab.setValue("DocumentNo",
"<"
+ MSequence.getPreliminaryNoByYear(mTab, rs.getInt(7), dateColumn, null)
+ ">");
}
else
{
mTab.setValue("DocumentNo", "<" + rs.getString(5) + ">");
}
if (newDocNo) {
int AD_Sequence_ID = rs.getInt("AD_Sequence_ID");
mTab.setValue("DocumentNo", MSequence.getPreliminaryNo(mTab, AD_Sequence_ID));
}
}
}

View File

@ -1,76 +0,0 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2008 Adempiere, Inc. All Rights Reserved. *
* 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. *
*****************************************************************************/
package org.adempiere.process;
import java.sql.PreparedStatement;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
import org.compiere.util.DB;
/**
* Insert AD_Sequence records that restart sequence at every year into
* AD_Sequence_No table if the record does not exists
*
* @author Elaine
*
*/
public class UpdateSequenceNo extends SvrProcess {
private String year;
@Override
protected void prepare() {
ProcessInfoParameter[] parameters = this.getParameter();
for (ProcessInfoParameter p : parameters) {
if (p.getParameterName().equals("CalendarYear")) {
year = p.getParameter().toString();
}
}
}
@Override
protected String doIt() throws Exception {
PreparedStatement insertStmt = null;
try {
insertStmt = DB
.prepareStatement(
"INSERT INTO AD_Sequence_No(AD_SEQUENCE_ID, CALENDARYEAR, "
+ "AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, "
+ "UPDATED, UPDATEDBY, CURRENTNEXT) "
+ "(SELECT AD_Sequence_ID, '" + year + "', "
+ "AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, "
+ "Updated, UpdatedBy, StartNo "
+ "FROM AD_Sequence a "
+ "WHERE StartNewYear = 'Y' AND NOT EXISTS ( "
+ "SELECT AD_Sequence_ID "
+ "FROM AD_Sequence_No b "
+ "WHERE a.AD_Sequence_ID = b.AD_Sequence_ID "
+ "AND CalendarYear = ?)) ",
get_TrxName());
insertStmt.setString(1, year);
insertStmt.executeUpdate();
commitEx();
} catch (Exception ex) {
rollback();
throw ex;
} finally {
DB.close(insertStmt);
}
return "Sequence No updated successfully";
}
}

View File

@ -31,7 +31,7 @@ public interface I_AD_Sequence
public static final String Table_Name = "AD_Sequence";
/** AD_Table_ID=115 */
public static final int Table_ID = MTable.getTable_ID(Table_Name);
public static final int Table_ID = 115;
KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name);
@ -75,6 +75,15 @@ public interface I_AD_Sequence
*/
public int getAD_Sequence_ID();
/** Column name AD_Sequence_UU */
public static final String COLUMNNAME_AD_Sequence_UU = "AD_Sequence_UU";
/** Set AD_Sequence_UU */
public void setAD_Sequence_UU (String AD_Sequence_UU);
/** Get AD_Sequence_UU */
public String getAD_Sequence_UU();
/** Column name Created */
public static final String COLUMNNAME_Created = "Created";
@ -208,6 +217,19 @@ public interface I_AD_Sequence
*/
public boolean isAutoSequence();
/** Column name IsOrgLevelSequence */
public static final String COLUMNNAME_IsOrgLevelSequence = "IsOrgLevelSequence";
/** Set Organization level.
* This sequence can be defined for each organization
*/
public void setIsOrgLevelSequence (boolean IsOrgLevelSequence);
/** Get Organization level.
* This sequence can be defined for each organization
*/
public boolean isOrgLevelSequence();
/** Column name IsTableID */
public static final String COLUMNNAME_IsTableID = "IsTableID";
@ -234,6 +256,19 @@ public interface I_AD_Sequence
*/
public String getName();
/** Column name OrgColumn */
public static final String COLUMNNAME_OrgColumn = "OrgColumn";
/** Set Org Column.
* Fully qualified Organization column (AD_Org_ID)
*/
public void setOrgColumn (String OrgColumn);
/** Get Org Column.
* Fully qualified Organization column (AD_Org_ID)
*/
public String getOrgColumn();
/** Column name Prefix */
public static final String COLUMNNAME_Prefix = "Prefix";
@ -247,6 +282,15 @@ public interface I_AD_Sequence
*/
public String getPrefix();
/** Column name StartNewMonth */
public static final String COLUMNNAME_StartNewMonth = "StartNewMonth";
/** Set Restart sequence every month */
public void setStartNewMonth (boolean StartNewMonth);
/** Get Restart sequence every month */
public boolean isStartNewMonth();
/** Column name StartNewYear */
public static final String COLUMNNAME_StartNewYear = "StartNewYear";

View File

@ -31,7 +31,7 @@ public interface I_AD_Sequence_No
public static final String Table_Name = "AD_Sequence_No";
/** AD_Table_ID=122 */
public static final int Table_ID = MTable.getTable_ID(Table_Name);
public static final int Table_ID = 122;
KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name);
@ -75,20 +75,29 @@ public interface I_AD_Sequence_No
*/
public int getAD_Sequence_ID();
public I_AD_Sequence getAD_Sequence() throws RuntimeException;
public org.compiere.model.I_AD_Sequence getAD_Sequence() throws RuntimeException;
/** Column name CalendarYear */
public static final String COLUMNNAME_CalendarYear = "CalendarYear";
/** Column name AD_Sequence_No_UU */
public static final String COLUMNNAME_AD_Sequence_No_UU = "AD_Sequence_No_UU";
/** Set Year.
* Calendar Year
/** Set AD_Sequence_No_UU */
public void setAD_Sequence_No_UU (String AD_Sequence_No_UU);
/** Get AD_Sequence_No_UU */
public String getAD_Sequence_No_UU();
/** Column name CalendarYearMonth */
public static final String COLUMNNAME_CalendarYearMonth = "CalendarYearMonth";
/** Set YearMonth.
* YYYYMM
*/
public void setCalendarYear (String CalendarYear);
public void setCalendarYearMonth (String CalendarYearMonth);
/** Get Year.
* Calendar Year
/** Get YearMonth.
* YYYYMM
*/
public String getCalendarYear();
public String getCalendarYearMonth();
/** Column name Created */
public static final String COLUMNNAME_Created = "Created";

View File

@ -20,13 +20,11 @@ import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
@ -56,17 +54,15 @@ public class MSequence extends X_AD_Sequence
/**
*
*/
private static final long serialVersionUID = -6827013120475678483L;
/** Use SQL procedure to get next id */
//begin vpj-cd e-evolution 02/11/2005 PostgreSQL
//private static final boolean USE_PROCEDURE = true;
private static boolean USE_PROCEDURE = false;
//end vpj-cd e-evolution 02/11/2005
private static final long serialVersionUID = -1204207754819125876L;
/** Log Level for Next ID Call */
private static final Level LOGLEVEL = Level.ALL;
private static final int QUERY_TIME_OUT = 30;
private static final String NoYearNorMonth = "-";
public static int getNextID (int AD_Client_ID, String TableName)
{
return getNextID(AD_Client_ID, TableName, null);
@ -113,7 +109,6 @@ public class MSequence extends X_AD_Sequence
+ "WHERE Name=?"
+ " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' "
+ " FOR UPDATE OF AD_Sequence ";
USE_PROCEDURE=false;
}
else
{
@ -122,11 +117,8 @@ public class MSequence extends X_AD_Sequence
+ "WHERE Name=?"
+ " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' ";
USE_PROCEDURE = true;
}
//hengsin: executing getNextID in transaction create huge performance and locking issue
//Trx trx = trxName == null ? null : Trx.get(trxName, true);
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
@ -143,9 +135,7 @@ public class MSequence extends X_AD_Sequence
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
pstmt.setString(1, TableName);
//
if (!USE_PROCEDURE )
{
//postgresql use special syntax instead of the setQueryTimeout methodk
//postgresql use special syntax instead of the setQueryTimeout method
if (DB.isPostgreSQL())
{
Statement timeoutStatement = conn.createStatement();
@ -155,7 +145,6 @@ public class MSequence extends X_AD_Sequence
{
pstmt.setQueryTimeout(QUERY_TIME_OUT);
}
}
rs = pstmt.executeQuery();
if (CLogMgt.isLevelFinest())
s_log.finest("AC=" + conn.getAutoCommit() + ", RO=" + conn.isReadOnly()
@ -225,13 +214,6 @@ public class MSequence extends X_AD_Sequence
}
if (! gotFromHTTP) {
//
if (USE_PROCEDURE)
{
retValue = nextID(conn, AD_Sequence_ID, adempiereSys);
}
else
{
PreparedStatement updateSQL;
int incrementNo = rs.getInt(3);
if (adempiereSys) {
@ -251,7 +233,6 @@ public class MSequence extends X_AD_Sequence
updateSQL.close();
}
}
}
//if (trx == null)
conn.commit();
@ -292,96 +273,6 @@ public class MSequence extends X_AD_Sequence
return retValue;
} // getNextID
/**
* Get Next ID
* @param conn connection
* @param AD_Sequence_ID sequence
* @param adempiereSys sys
* @return next id or -1 (error) or -3 (parameter)
*/
private static int nextID (Connection conn, int AD_Sequence_ID, boolean adempiereSys)
{
if (conn == null || AD_Sequence_ID == 0)
return -3;
//
int retValue = -1;
String sqlUpdate = "{call nextID(?,?,?)}";
CallableStatement cstmt = null;
try
{
cstmt = conn.prepareCall (sqlUpdate,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
cstmt.setInt(1, AD_Sequence_ID);
cstmt.setString(2, adempiereSys ? "Y" : "N");
cstmt.registerOutParameter(3, Types.INTEGER);
//postgresql use special syntax instead of the setQueryTimeout method
if (DB.isPostgreSQL())
{
Statement timeoutStatement = conn.createStatement();
timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( QUERY_TIME_OUT * 1000 ));
}
else if (DB.getDatabase().isQueryTimeoutSupported())
{
cstmt.setQueryTimeout(QUERY_TIME_OUT);
}
cstmt.execute();
retValue = cstmt.getInt(3);
}
catch (Exception e)
{
s_log.log(Level.SEVERE, e.toString());
}
finally
{
DB.close(cstmt);
}
return retValue;
} // nextID
/**
* Get next id by year
* @param conn
* @param AD_Sequence_ID
* @param incrementNo
* @param calendarYear
* @return next id
*/
private static int nextIDByYear(Connection conn, int AD_Sequence_ID,
int incrementNo, String calendarYear) {
if (conn == null || AD_Sequence_ID == 0)
return -3;
//
int retValue = -1;
String sqlUpdate = "{call nextIDByYear(?,?,?,?)}";
CallableStatement cstmt = null;
try {
cstmt = conn.prepareCall(sqlUpdate, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
cstmt.setInt(1, AD_Sequence_ID);
cstmt.setInt(2, incrementNo);
cstmt.setString(3, calendarYear);
cstmt.registerOutParameter(4, Types.INTEGER);
//postgresql use special syntax instead of the setQueryTimeout method
if (DB.isPostgreSQL())
{
Statement timeoutStatement = conn.createStatement();
timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( QUERY_TIME_OUT * 1000 ));
}
else if (DB.getDatabase().isQueryTimeoutSupported())
{
cstmt.setQueryTimeout(QUERY_TIME_OUT);
}
cstmt.execute();
retValue = cstmt.getInt(4);
} catch (Exception e) {
s_log.log(Level.SEVERE, e.toString());
} finally {
DB.close(cstmt);
}
return retValue;
} // nextID
/**************************************************************************
* Get Document No from table
* @param AD_Client_ID client
@ -395,11 +286,11 @@ public class MSequence extends X_AD_Sequence
}
/**************************************************************************
* Get Document No from table
* Get Document No from table (when the document doesn't have a c_doctype)
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @param PO
* @param PO - used to get the date, org and parse context variables
* @return document no or null
*/
public static String getDocumentNo (int AD_Client_ID, String TableName, String trxName, PO po)
@ -407,6 +298,19 @@ public class MSequence extends X_AD_Sequence
if (TableName == null || TableName.length() == 0)
throw new IllegalArgumentException("TableName missing");
MSequence seq = get(Env.getCtx(), TableName, trxName, /*tableID=*/false);
if (seq == null || seq.get_ID() == 0) {
if (!MSequence.createTableSequence(Env.getCtx(), TableName, trxName, /*tableID=*/false))
throw new AdempiereException("Could not create table sequence");
seq = get(Env.getCtx(), TableName, trxName, /*tableID=*/false);
if (seq == null || seq.get_ID() == 0)
throw new AdempiereException("Could not find table sequence");
}
return getDocumentNoFromSeq(seq, trxName, po);
} // getDocumentNo
private static String getDocumentNoFromSeq(MSequence seq, String trxName, PO po) {
// Check AdempiereSys
boolean adempiereSys = false;
if (Ini.isClient())
@ -418,99 +322,57 @@ public class MSequence extends X_AD_Sequence
String sysProperty = Env.getCtx().getProperty("AdempiereSys", "N");
adempiereSys = "y".equalsIgnoreCase(sysProperty) || "true".equalsIgnoreCase(sysProperty);
}
if (adempiereSys && AD_Client_ID > 11)
if (adempiereSys && Env.getAD_Client_ID(Env.getCtx()) > 11)
adempiereSys = false;
//
if (CLogMgt.isLevel(LOGLEVEL))
s_log.log(LOGLEVEL, TableName + " - AdempiereSys=" + adempiereSys + " [" + trxName + "]");
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean isStartNewYear = false;
String dateColumn = null;
if (!adempiereSys)
{
// Get the Start New Year flag
String startNewYearSQL = "SELECT StartNewYear, DateColumn FROM AD_Sequence "
+ "WHERE Name = ? AND IsActive = 'Y' AND IsTableID = 'N' AND IsAutoSequence='Y' AND AD_Client_ID = ?";
try
{
pstmt = DB.prepareStatement(startNewYearSQL, trxName);
pstmt.setString(1, PREFIX_DOCSEQ + TableName);
pstmt.setInt(2, AD_Client_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
isStartNewYear = "Y".equals(rs.getString(1));
dateColumn = rs.getString(2);
}
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e);
}
finally
{
DB.close(rs, pstmt);
}
}
int AD_Sequence_ID = seq.getAD_Sequence_ID();
boolean isStartNewYear = seq.isStartNewYear();
boolean isStartNewMonth = seq.isStartNewMonth();
String dateColumn = seq.getDateColumn();
boolean isUseOrgLevel = seq.isOrgLevelSequence();
String orgColumn = seq.getOrgColumn();
int startNo = seq.getStartNo();
int incrementNo = seq.getIncrementNo();
String prefix = seq.getPrefix();
String suffix = seq.getSuffix();
String decimalPattern = seq.getDecimalPattern();
String selectSQL = null;
if (DB.isOracle() == false)
{
if (isStartNewYear) {
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Sequence_ID "
if (isStartNewYear || isUseOrgLevel) {
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys "
+ "FROM AD_Sequence_No y, AD_Sequence s "
+ "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID "
+ "AND s.Name = ? "
+ "AND s.AD_Client_ID = ? "
+ "AND y.CalendarYear = ? "
+ "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' "
+ "ORDER BY s.AD_Client_ID DESC "
+ "FOR UPDATE OF y";
} else {
selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Sequence_ID "
+ "FROM AD_Sequence "
+ "WHERE Name = ? "
+ "AND AD_Client_ID = ? "
+ "AND IsActive='Y' AND IsTableID='N' AND IsAutoSequence='Y' "
+ "ORDER BY AD_Client_ID DESC "
+ "FOR UPDATE OF AD_Sequence";
}
USE_PROCEDURE=false;
}
else
{
if (isStartNewYear) {
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, Prefix, Suffix, DecimalPattern, s.AD_Sequence_ID "
+ "FROM AD_Sequence_No y, AD_Sequence s "
+ "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID "
+ "AND s.Name = ? "
+ "AND s.AD_Client_ID = ? "
+ "AND y.CalendarYear = ? "
+ "AND s.AD_Sequence_ID = ? "
+ "AND y.CalendarYearMonth = ? "
+ "AND y.AD_Org_ID = ? "
+ "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' "
+ "ORDER BY s.AD_Client_ID DESC";
} else {
selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Sequence_ID "
+ "FROM AD_Sequence "
+ "WHERE Name = ? "
+ "AND AD_Client_ID = ? "
+ "AND IsActive='Y' AND IsTableID='N' AND IsAutoSequence='Y' "
+ "ORDER BY AD_Client_ID DESC";
selectSQL = "SELECT s.CurrentNext, s.CurrentNextSys "
+ "FROM AD_Sequence s "
+ "WHERE s.AD_Sequence_ID = ? "
+ "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' "
+ "ORDER BY s.AD_Client_ID DESC";
}
if (DB.isPostgreSQL())
{
if ( ( isStartNewYear || isUseOrgLevel ) && !adempiereSys ) {
selectSQL = selectSQL + " FOR UPDATE OF y";
} else {
selectSQL = selectSQL + " FOR UPDATE OF s";
}
USE_PROCEDURE = true;
}
Connection conn = null;
Trx trx = trxName == null ? null : Trx.get(trxName, true);
//
int AD_Sequence_ID = 0;
int incrementNo = 0;
String calendarYearMonth = NoYearNorMonth;
int docOrg_ID = 0;
int next = -1;
String prefix = "";
String suffix = "";
String decimalPattern = "";
String calendarYear = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
if (trx != null)
@ -523,30 +385,41 @@ public class MSequence extends X_AD_Sequence
if (isStartNewYear)
{
SimpleDateFormat sdf = null;
if (isStartNewMonth)
sdf = new SimpleDateFormat("yyyyMM");
else
sdf = new SimpleDateFormat("yyyy");
if (po != null && dateColumn != null && dateColumn.length() > 0)
{
Date docDate = (Date)po.get_Value(dateColumn);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
calendarYear = sdf.format(docDate);
calendarYearMonth = sdf.format(docDate);
}
else
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
calendarYear = sdf.format(new Date());
calendarYearMonth = sdf.format(new Date());
}
}
if (isUseOrgLevel)
{
if (po != null && orgColumn != null && orgColumn.length() > 0)
{
docOrg_ID = po.get_ValueAsInt(orgColumn);
}
}
//
pstmt = conn.prepareStatement(selectSQL,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
pstmt.setString(1, PREFIX_DOCSEQ + TableName);
pstmt.setInt(2, AD_Client_ID);
if (isStartNewYear)
pstmt.setString(3, calendarYear);
int index = 1;
pstmt.setInt(index++, AD_Sequence_ID);
if (isUseOrgLevel || isStartNewYear) {
pstmt.setString(index++, calendarYearMonth);
pstmt.setInt(index++, docOrg_ID);
}
//
if (!USE_PROCEDURE)
{
//postgresql use special syntax instead of the setQueryTimeout method
if (DB.isPostgreSQL())
{
@ -557,44 +430,34 @@ public class MSequence extends X_AD_Sequence
{
pstmt.setQueryTimeout(QUERY_TIME_OUT);
}
}
rs = pstmt.executeQuery();
// s_log.fine("AC=" + conn.getAutoCommit() + " -Iso=" + conn.getTransactionIsolation()
// + " - Type=" + pstmt.getResultSetType() + " - Concur=" + pstmt.getResultSetConcurrency());
if (rs.next())
{
AD_Sequence_ID = rs.getInt(7);
prefix = rs.getString(4);
suffix = rs.getString(5);
decimalPattern = rs.getString(6);
incrementNo = rs.getInt(3);
if (USE_PROCEDURE)
{
next = isStartNewYear
? nextIDByYear(conn, AD_Sequence_ID, incrementNo, calendarYear)
: nextID(conn, AD_Sequence_ID, adempiereSys);
}
else
{
s_log.fine("AD_Sequence_ID="+AD_Sequence_ID);
PreparedStatement updateSQL = null;
try
{
if (adempiereSys) {
updateSQL = conn
.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
next = rs.getInt(2);
} else {
String sql = isStartNewYear
? "UPDATE AD_Sequence_No SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ? AND CalendarYear = ?"
: "UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?";
updateSQL = conn
.prepareStatement(sql);
String sql;
if (isStartNewYear || isUseOrgLevel)
sql = "UPDATE AD_Sequence_No SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID=? AND CalendarYearMonth=? AND AD_Org_ID=?";
else
sql = "UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID=?";
updateSQL = conn.prepareStatement(sql);
next = rs.getInt(1);
}
updateSQL.setInt(1, incrementNo);
updateSQL.setInt(2, AD_Sequence_ID);
if (isStartNewYear)
updateSQL.setString(3, calendarYear);
if (isStartNewYear || isUseOrgLevel) {
updateSQL.setString(3, calendarYearMonth);
updateSQL.setInt(4, docOrg_ID);
}
updateSQL.executeUpdate();
}
finally
@ -602,13 +465,24 @@ public class MSequence extends X_AD_Sequence
DB.close(updateSQL);
}
}
}
else
{ // did not find sequence no
if (isUseOrgLevel || isStartNewYear)
{ // create sequence (CurrentNo = StartNo + IncrementNo) for this year/month/org and return first number (=StartNo)
next = startNo;
X_AD_Sequence_No seqno = new X_AD_Sequence_No(Env.getCtx(), 0, trxName);
seqno.setAD_Sequence_ID(AD_Sequence_ID);
seqno.setAD_Org_ID(docOrg_ID);
seqno.setCalendarYearMonth(calendarYearMonth);
seqno.setCurrentNext(startNo + incrementNo);
seqno.saveEx();
}
else // standard
{
s_log.warning ("(Table) - no record found - " + TableName);
MSequence seq = new MSequence (Env.getCtx(), AD_Client_ID, TableName, null);
next = seq.getNextID();
seq.saveEx();
s_log.warning ("(Sequence)- no record found - " + seq);
next = -2;
}
}
// Commit
if (trx == null)
@ -618,7 +492,7 @@ public class MSequence extends X_AD_Sequence
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e);
s_log.log(Level.SEVERE, "(DocType) [" + trxName + "]", e);
if (DBException.isTimeout(e))
throw new AdempiereException("GenerateDocumentNoTimeOut", e);
else
@ -626,8 +500,8 @@ public class MSequence extends X_AD_Sequence
}
finally
{
//Finish
DB.close(rs, pstmt);
// Finish
try
{
if (trx == null && conn != null) {
@ -637,10 +511,9 @@ public class MSequence extends X_AD_Sequence
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "(Table) - finish", e);
s_log.log(Level.SEVERE, "(DocType) - finish", e);
}
}
// Error
if (next < 0)
return null;
@ -649,6 +522,7 @@ public class MSequence extends X_AD_Sequence
StringBuffer doc = new StringBuffer();
if (prefix != null && prefix.length() > 0)
doc.append(Env.parseVariable(prefix, po, trxName, false));
if (decimalPattern != null && decimalPattern.length() > 0)
doc.append(new DecimalFormat(decimalPattern).format(next));
else
@ -657,9 +531,9 @@ public class MSequence extends X_AD_Sequence
doc.append(Env.parseVariable(suffix, po, trxName, false));
String documentNo = doc.toString();
s_log.finer (documentNo + " (" + incrementNo + ")"
+ " - Table=" + TableName + " [" + trx + "]");
+ " - Sequence=" + AD_Sequence_ID + " [" + trx + "]");
return documentNo;
} // getDocumentNo
}
/**
* Get Document No based on Document Type
@ -708,7 +582,7 @@ public class MSequence extends X_AD_Sequence
return null;
}
if (definite && ! dt.isOverwriteSeqOnComplete()) {
s_log.finer("DocType_ID=" + C_DocType_ID + " Not Sequence Overwrite on Complete");
s_log.warning("DocType_ID=" + C_DocType_ID + " Not Sequence Overwrite on Complete");
return null;
}
if (dt == null || dt.getDocNoSequence_ID() == 0)
@ -721,248 +595,13 @@ public class MSequence extends X_AD_Sequence
s_log.warning ("No Definite Sequence for DocType - " + dt);
return null;
}
int seqID = ( definite ? dt.getDefiniteSequence_ID() : dt.getDocNoSequence_ID() );
MSequence seq = new MSequence(Env.getCtx(), seqID, trxName);
// Check AdempiereSys
boolean adempiereSys = false;
if (Ini.isClient())
{
adempiereSys = Ini.isPropertyBool(Ini.P_ADEMPIERESYS);
}
else
{
String sysProperty = Env.getCtx().getProperty("AdempiereSys", "N");
adempiereSys = "y".equalsIgnoreCase(sysProperty) || "true".equalsIgnoreCase(sysProperty);
}
if (CLogMgt.isLevel(LOGLEVEL))
s_log.log(LOGLEVEL, "DocType_ID=" + C_DocType_ID + " [" + trxName + "]");
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean isStartNewYear = false;
String dateColumn = null;
if (!adempiereSys)
{
// Get the Start New Year & Sequence Type
String startNewYearSQL = "SELECT StartNewYear, DateColumn FROM AD_Sequence "
+ "WHERE AD_Sequence_ID = ? AND IsActive = 'Y' AND IsTableID = 'N' AND IsAutoSequence='Y'";
try {
pstmt = DB.prepareStatement(startNewYearSQL, trxName);
pstmt.setInt(1, definite ? dt.getDefiniteSequence_ID() : dt
.getDocNoSequence_ID());
rs = pstmt.executeQuery();
if (rs.next()) {
isStartNewYear = "Y".equals(rs.getString(1));
dateColumn = rs.getString(2);
}
} catch (Exception e) {
s_log.log(Level.SEVERE, "(Table) [" + trxName + "]", e);
}
finally
{
DB.close(rs, pstmt);
}
}
String selectSQL = null;
if (DB.isOracle() == false)
{
if (isStartNewYear)
{
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Client_ID, s.AD_Sequence_ID "
+ "FROM AD_Sequence_No y, AD_Sequence s "
+ "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID "
+ "AND s.AD_Sequence_ID = ? "
+ "AND y.CalendarYear = ? "
+ "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' "
+ "FOR UPDATE OF y";
}
else
{
selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Client_ID, AD_Sequence_ID "
+ "FROM AD_Sequence "
+ "WHERE AD_Sequence_ID = ? "
+ "AND IsActive='Y' AND IsTableID='N' AND IsAutoSequence='Y' "
+ "FOR UPDATE OF AD_Sequence";
}
USE_PROCEDURE=false;
}
else
{
if (isStartNewYear) {
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Client_ID, s.AD_Sequence_ID "
+ "FROM AD_Sequence_No y, AD_Sequence s "
+ "WHERE y.AD_Sequence_ID = s.AD_Sequence_ID "
+ "AND s.AD_Sequence_ID = ? "
+ "AND y.CalendarYear = ? "
+ "AND s.IsActive='Y' AND s.IsTableID='N' AND s.IsAutoSequence='Y' ";
} else {
selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, Prefix, Suffix, DecimalPattern, AD_Client_ID, AD_Sequence_ID "
+ "FROM AD_Sequence "
+ "WHERE AD_Sequence_ID = ? "
+ "AND IsActive='Y' AND IsTableID='N' AND IsAutoSequence='Y' ";
}
USE_PROCEDURE = true;
}
Connection conn = null;
Trx trx = trxName == null ? null : Trx.get(trxName, true);
//
int AD_Sequence_ID = 0;
int incrementNo = 0;
int next = -1;
String prefix = "";
String suffix = "";
String decimalPattern = "";
String calendarYear = "";
try
{
if (trx != null)
conn = trx.getConnection();
else
conn = DB.getConnectionID();
// Error
if (conn == null)
return null;
if (isStartNewYear)
{
if (po != null && dateColumn != null && dateColumn.length() > 0)
{
Date docDate = (Date)po.get_Value(dateColumn);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
calendarYear = sdf.format(docDate);
}
else
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
calendarYear = sdf.format(new Date());
}
}
pstmt = conn.prepareStatement(selectSQL,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
if (definite)
pstmt.setInt(1, dt.getDefiniteSequence_ID());
else
pstmt.setInt(1, dt.getDocNoSequence_ID());
if (isStartNewYear)
pstmt.setString(2, calendarYear);
//
if (!USE_PROCEDURE)
{
//postgresql use special syntax instead of the setQueryTimeout method
if (DB.isPostgreSQL())
{
Statement timeoutStatement = conn.createStatement();
timeoutStatement.execute("SET LOCAL statement_timeout TO " + ( QUERY_TIME_OUT * 1000 ));
}
else if (DB.getDatabase().isQueryTimeoutSupported())
{
pstmt.setQueryTimeout(QUERY_TIME_OUT);
}
}
rs = pstmt.executeQuery();
// s_log.fine("AC=" + conn.getAutoCommit() + " -Iso=" + conn.getTransactionIsolation()
// + " - Type=" + pstmt.getResultSetType() + " - Concur=" + pstmt.getResultSetConcurrency());
if (rs.next())
{
incrementNo = rs.getInt(3);
prefix = rs.getString(4);
suffix = rs.getString(5);
decimalPattern = rs.getString(6);
int AD_Client_ID = rs.getInt(7);
if (adempiereSys && AD_Client_ID > 11)
adempiereSys = false;
AD_Sequence_ID = rs.getInt(8);
if (USE_PROCEDURE)
{
next = isStartNewYear
? nextIDByYear(conn, AD_Sequence_ID, incrementNo, calendarYear)
: nextID(conn, AD_Sequence_ID, adempiereSys);
}
else
{
PreparedStatement updateSQL = null;
try
{
if (adempiereSys) {
updateSQL = conn
.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
next = rs.getInt(2);
} else {
String sql = isStartNewYear
? "UPDATE AD_Sequence_No SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ? AND CalendarYear = ?"
: "UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?";
updateSQL = conn.prepareStatement(sql);
next = rs.getInt(1);
}
updateSQL.setInt(1, incrementNo);
updateSQL.setInt(2, AD_Sequence_ID);
if (isStartNewYear)
updateSQL.setString(3, calendarYear);
updateSQL.executeUpdate();
}
finally
{
DB.close(updateSQL);
}
}
}
else
{
s_log.warning ("(DocType)- no record found - " + dt);
next = -2;
}
// Commit
if (trx == null)
{
conn.commit();
}
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "(DocType) [" + trxName + "]", e);
if (DBException.isTimeout(e))
throw new AdempiereException("GenerateDocumentNoTimeOut", e);
else
throw new AdempiereException("GenerateDocumentNoError", e);
}
finally
{
// Finish
try
{
DB.close(rs, pstmt);
if (trx == null && conn != null) {
conn.close();
conn = null;
}
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "(DocType) - finish", e);
}
}
// Error
if (next < 0)
return null;
// create DocumentNo
StringBuffer doc = new StringBuffer();
if (prefix != null && prefix.length() > 0)
doc.append(Env.parseVariable(prefix, po, trxName, false));
if (decimalPattern != null && decimalPattern.length() > 0)
doc.append(new DecimalFormat(decimalPattern).format(next));
else
doc.append(next);
if (suffix != null && suffix.length() > 0)
doc.append(Env.parseVariable(suffix, po, trxName, false));
String documentNo = doc.toString();
s_log.finer (documentNo + " (" + incrementNo + ")"
+ " - C_DocType_ID=" + C_DocType_ID + " [" + trx + "]");
return documentNo;
return getDocumentNoFromSeq(seq, trxName, po);
} // getDocumentNo
@ -1028,6 +667,10 @@ public class MSequence extends X_AD_Sequence
} // checkClientSequences
public static boolean createTableSequence (Properties ctx, String TableName, String trxName) {
return createTableSequence (ctx, TableName, trxName, true);
}
/**
* Create Table ID Sequence
* @param ctx context
@ -1035,36 +678,34 @@ public class MSequence extends X_AD_Sequence
* @param trxName transaction
* @return true if created
*/
public static boolean createTableSequence (Properties ctx, String TableName, String trxName)
public static boolean createTableSequence (Properties ctx, String TableName, String trxName, boolean tableID)
{
boolean SYSTEM_NATIVE_SEQUENCE = MSysConfig.getBooleanValue(MSysConfig.SYSTEM_NATIVE_SEQUENCE,false);
if(SYSTEM_NATIVE_SEQUENCE)
{
int next_id = MSequence.getNextID(Env.getAD_Client_ID(ctx), TableName, trxName);
if(next_id == -1)
{
MSequence seq = new MSequence (ctx, 0, trxName);
if (tableID)
seq.setClientOrg(0, 0);
else
seq.setClientOrg(Env.getAD_Client_ID(Env.getCtx()), 0);
if (tableID) {
seq.setName(TableName);
seq.setDescription("Table " + TableName);
seq.setIsTableID(true);
seq.saveEx();
next_id = 1000000;
} else {
seq.setName(PREFIX_DOCSEQ + TableName);
seq.setDescription("DocumentNo/Value for Table " + TableName);
}
seq.setIsTableID(tableID);
seq.saveEx();
if(CConnection.get().getDatabase().createSequence(TableName+"_SQ", 1, 0 , 99999999, next_id, trxName))
return true;
if (tableID && SYSTEM_NATIVE_SEQUENCE)
{
int next_id = seq.getCurrentNext();
if (! CConnection.get().getDatabase().createSequence(TableName+"_SQ", 1, 0 , 99999999, next_id, trxName))
return false;
}
MSequence seq = new MSequence (ctx, 0, trxName);
seq.setClientOrg(0, 0);
seq.setName(TableName);
seq.setDescription("Table " + TableName);
seq.setIsTableID(true);
return seq.save();
return true;
} // createTableSequence
@ -1079,18 +720,31 @@ public class MSequence extends X_AD_Sequence
return get(ctx, tableName, null);
}
/* Get the tableID sequence based on the TableName */
public static MSequence get (Properties ctx, String tableName, String trxName)
{
return get (ctx, tableName, trxName, true);
}
/**
* Get Sequence
* @param ctx context
* @param tableName table name
* @param trxName optional transaction name
* @param tableID
* @return Sequence
*/
public static MSequence get (Properties ctx, String tableName, String trxName)
public static MSequence get (Properties ctx, String tableName, String trxName, boolean tableID)
{
if (! tableID) {
tableName = PREFIX_DOCSEQ + tableName;
}
String sql = "SELECT * FROM AD_Sequence "
+ "WHERE UPPER(Name)=?"
+ " AND IsTableID='Y'";
+ " AND IsTableID=?";
if (! tableID)
sql = sql + " AND AD_Client_ID=?";
MSequence retValue = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
@ -1098,6 +752,9 @@ public class MSequence extends X_AD_Sequence
{
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setString(1, tableName.toUpperCase());
pstmt.setString(2, ( tableID ? "Y" : "N" ) );
if (! tableID)
pstmt.setInt (3, Env.getAD_Client_ID(Env.getCtx()));
rs = pstmt.executeQuery();
if (rs.next ())
retValue = new MSequence (ctx, rs, trxName);
@ -1117,14 +774,14 @@ public class MSequence extends X_AD_Sequence
return retValue;
} // get
/** Sequence for Table Document No's */
private static final String PREFIX_DOCSEQ = "DocumentNo_";
/** Start Number */
public static final int INIT_NO = 1000000; // 1 Mio
public static final int INIT_NO = 1000000; // 1M
/** Start System Number */
// public static final int INIT_SYS_NO = 100; // start number for Compiere
public static final int INIT_SYS_NO = 50000; // start number for Adempiere
// public static final int INIT_SYS_NO = 50000; // start number for Adempiere
public static final int INIT_SYS_NO = 200000; // start number for iDempiere
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger(MSequence.class);
@ -1640,22 +1297,64 @@ public class MSequence extends X_AD_Sequence
return false;
}
@Override
protected boolean beforeSave(boolean newRecord) {
if (isStartNewMonth() && !isStartNewYear())
setStartNewMonth(false);
return true;
}
/**
* Get preliminary document no by year
* @param tab
* @param AD_Sequence_ID
* @param dateColumn
* @return Preliminary document no
*/
public static String getPreliminaryNoByYear(GridTab tab, int AD_Sequence_ID, String dateColumn, String trxName) {
Date d = (Date)tab.getValue(dateColumn);
public static String getPreliminaryNo(GridTab tab, int AD_Sequence_ID) {
String prelim = null;
if (AD_Sequence_ID > 0) {
MSequence seq = new MSequence(Env.getCtx(), AD_Sequence_ID, null);
boolean startNewYear = seq.isStartNewYear();
boolean startNewMonth = seq.isStartNewMonth();
boolean orgLevelSeq = seq.isOrgLevelSequence();
int currentNext = seq.getCurrentNext();
if (startNewYear || orgLevelSeq) {
String cym = NoYearNorMonth;
int org = 0;
if (startNewYear || startNewMonth) {
Date d = (Date)tab.getValue(seq.getDateColumn());
if (d == null)
d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
String calendarYear = sdf.format(d);
String sql = "select CurrentNext From AD_Sequence_No Where AD_Sequence_ID = ? and CalendarYear = ?";
SimpleDateFormat sdf = null;
if (startNewMonth)
sdf = new SimpleDateFormat("yyyyMM");
else
sdf = new SimpleDateFormat("yyyy");
cym = sdf.format(d);
}
if (orgLevelSeq) {
org = (Integer)tab.getValue(seq.getOrgColumn());
}
String sql = "SELECT CurrentNext FROM AD_Sequence_No WHERE AD_Sequence_ID=? AND CalendarYearMonth=? AND AD_Org_ID=?";
currentNext = DB.getSQLValue(null, sql, AD_Sequence_ID, cym, org);
}
String decimalPattern = seq.getDecimalPattern();
if (decimalPattern != null && decimalPattern.length() > 0)
prelim = new DecimalFormat(decimalPattern).format(currentNext);
else
prelim = String.valueOf(currentNext);
}
if (prelim == null)
prelim = "?";
return "<" + prelim + ">";
}
return DB.getSQLValueString(trxName, sql, AD_Sequence_ID, calendarYear);
@Override
public String getOrgColumn() {
if (super.getOrgColumn() == null)
return COLUMNNAME_AD_Org_ID;
else
return super.getOrgColumn();
}
} // MSequence

View File

@ -459,23 +459,14 @@ public class MTable extends X_AD_Table
protected boolean afterSave (boolean newRecord, boolean success)
{
// Sync Table ID
if (newRecord)
{
MSequence seq = MSequence.get(getCtx(), getTableName(), get_TrxName());
if (seq == null || seq.get_ID() == 0)
MSequence.createTableSequence(getCtx(), getTableName(), get_TrxName());
}
else
{
MSequence seq = MSequence.get(getCtx(), getTableName(), get_TrxName());
if (seq == null || seq.get_ID() == 0)
MSequence.createTableSequence(getCtx(), getTableName(), get_TrxName());
else if (!seq.getName().equals(getTableName()))
else if (seq != null && !seq.getName().equals(getTableName()))
{
seq.setName(getTableName());
seq.saveEx();
}
}
return success;
} // afterSave

View File

@ -30,7 +30,7 @@ public class X_AD_Sequence extends PO implements I_AD_Sequence, I_Persistent
/**
*
*/
private static final long serialVersionUID = 20100614L;
private static final long serialVersionUID = 20120907L;
/** Standard Constructor */
public X_AD_Sequence (Properties ctx, int AD_Sequence_ID, String trxName)
@ -46,7 +46,11 @@ public class X_AD_Sequence extends PO implements I_AD_Sequence, I_Persistent
setIncrementNo (0);
// 1
setIsAutoSequence (false);
setIsOrgLevelSequence (false);
// N
setName (null);
setStartNewMonth (false);
// N
setStartNo (0);
// 1000000
} */
@ -103,6 +107,20 @@ public class X_AD_Sequence extends PO implements I_AD_Sequence, I_Persistent
return ii.intValue();
}
/** Set AD_Sequence_UU.
@param AD_Sequence_UU AD_Sequence_UU */
public void setAD_Sequence_UU (String AD_Sequence_UU)
{
set_Value (COLUMNNAME_AD_Sequence_UU, AD_Sequence_UU);
}
/** Get AD_Sequence_UU.
@return AD_Sequence_UU */
public String getAD_Sequence_UU ()
{
return (String)get_Value(COLUMNNAME_AD_Sequence_UU);
}
/** Set Current Next.
@param CurrentNext
The next number to be used
@ -262,6 +280,30 @@ public class X_AD_Sequence extends PO implements I_AD_Sequence, I_Persistent
return false;
}
/** Set Organization level.
@param IsOrgLevelSequence
This sequence can be defined for each organization
*/
public void setIsOrgLevelSequence (boolean IsOrgLevelSequence)
{
set_Value (COLUMNNAME_IsOrgLevelSequence, Boolean.valueOf(IsOrgLevelSequence));
}
/** Get Organization level.
@return This sequence can be defined for each organization
*/
public boolean isOrgLevelSequence ()
{
Object oo = get_Value(COLUMNNAME_IsOrgLevelSequence);
if (oo != null)
{
if (oo instanceof Boolean)
return ((Boolean)oo).booleanValue();
return "Y".equals(oo);
}
return false;
}
/** Set Used for Record ID.
@param IsTableID
The document number will be used as the record key
@ -311,6 +353,23 @@ public class X_AD_Sequence extends PO implements I_AD_Sequence, I_Persistent
return new KeyNamePair(get_ID(), getName());
}
/** Set Org Column.
@param OrgColumn
Fully qualified Organization column (AD_Org_ID)
*/
public void setOrgColumn (String OrgColumn)
{
set_Value (COLUMNNAME_OrgColumn, OrgColumn);
}
/** Get Org Column.
@return Fully qualified Organization column (AD_Org_ID)
*/
public String getOrgColumn ()
{
return (String)get_Value(COLUMNNAME_OrgColumn);
}
/** Set Prefix.
@param Prefix
Prefix before the sequence number
@ -328,6 +387,27 @@ public class X_AD_Sequence extends PO implements I_AD_Sequence, I_Persistent
return (String)get_Value(COLUMNNAME_Prefix);
}
/** Set Restart sequence every month.
@param StartNewMonth Restart sequence every month */
public void setStartNewMonth (boolean StartNewMonth)
{
set_Value (COLUMNNAME_StartNewMonth, Boolean.valueOf(StartNewMonth));
}
/** Get Restart sequence every month.
@return Restart sequence every month */
public boolean isStartNewMonth ()
{
Object oo = get_Value(COLUMNNAME_StartNewMonth);
if (oo != null)
{
if (oo instanceof Boolean)
return ((Boolean)oo).booleanValue();
return "Y".equals(oo);
}
return false;
}
/** Set Restart sequence every Year.
@param StartNewYear
Restart the sequence with Start on every 1/1

View File

@ -29,7 +29,7 @@ public class X_AD_Sequence_No extends PO implements I_AD_Sequence_No, I_Persiste
/**
*
*/
private static final long serialVersionUID = 20100614L;
private static final long serialVersionUID = 20120907L;
/** Standard Constructor */
public X_AD_Sequence_No (Properties ctx, int AD_Sequence_No_ID, String trxName)
@ -38,7 +38,7 @@ public class X_AD_Sequence_No extends PO implements I_AD_Sequence_No, I_Persiste
/** if (AD_Sequence_No_ID == 0)
{
setAD_Sequence_ID (0);
setCalendarYear (null);
setCalendarYearMonth (null);
setCurrentNext (0);
} */
}
@ -71,9 +71,9 @@ public class X_AD_Sequence_No extends PO implements I_AD_Sequence_No, I_Persiste
return sb.toString();
}
public I_AD_Sequence getAD_Sequence() throws RuntimeException
public org.compiere.model.I_AD_Sequence getAD_Sequence() throws RuntimeException
{
return (I_AD_Sequence)MTable.get(getCtx(), I_AD_Sequence.Table_Name)
return (org.compiere.model.I_AD_Sequence)MTable.get(getCtx(), org.compiere.model.I_AD_Sequence.Table_Name)
.getPO(getAD_Sequence_ID(), get_TrxName()); }
/** Set Sequence.
@ -99,21 +99,35 @@ public class X_AD_Sequence_No extends PO implements I_AD_Sequence_No, I_Persiste
return ii.intValue();
}
/** Set Year.
@param CalendarYear
Calendar Year
*/
public void setCalendarYear (String CalendarYear)
/** Set AD_Sequence_No_UU.
@param AD_Sequence_No_UU AD_Sequence_No_UU */
public void setAD_Sequence_No_UU (String AD_Sequence_No_UU)
{
set_ValueNoCheck (COLUMNNAME_CalendarYear, CalendarYear);
set_Value (COLUMNNAME_AD_Sequence_No_UU, AD_Sequence_No_UU);
}
/** Get Year.
@return Calendar Year
*/
public String getCalendarYear ()
/** Get AD_Sequence_No_UU.
@return AD_Sequence_No_UU */
public String getAD_Sequence_No_UU ()
{
return (String)get_Value(COLUMNNAME_CalendarYear);
return (String)get_Value(COLUMNNAME_AD_Sequence_No_UU);
}
/** Set YearMonth.
@param CalendarYearMonth
YYYYMM
*/
public void setCalendarYearMonth (String CalendarYearMonth)
{
set_ValueNoCheck (COLUMNNAME_CalendarYearMonth, CalendarYearMonth);
}
/** Get YearMonth.
@return YYYYMM
*/
public String getCalendarYearMonth ()
{
return (String)get_Value(COLUMNNAME_CalendarYearMonth);
}
/** Set Current Next.

View File

@ -1432,7 +1432,7 @@ public final class Env
String table = tblIndex > 0 ? format.substring(0, tblIndex) : token.substring(0, token.length() - 3);
String column = tblIndex > 0 ? format.substring(tblIndex + 1) : format;
outStr.append(DB.getSQLValueString(trxName,
"select " + column + " from " + table + " where " + table + "_id = ?", (Integer)v));
"SELECT " + column + " FROM " + table + " WHERE " + table + "_ID = ?", (Integer)v));
} else if (v instanceof Date) {
SimpleDateFormat df = new SimpleDateFormat(format);
outStr.append(df.format((Date)v));