src-db/database/model/functions/FACT_ACCT_RESET.xml
changeset 1605 8a0fe0193bef
parent 785 8dba91261590
child 1929 ad0353d93b0f
equal deleted inserted replaced
1604:a1c518e6ed93 1605:8a0fe0193bef
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     2   <database name="FUNCTION FACT_ACCT_RESET">
     2   <database name="FUNCTION FACT_ACCT_RESET">
     3     <function name="FACT_ACCT_RESET" type="NULL">
     3     <function name="FACT_ACCT_RESET" type="NULL">
     4       <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
     4       <parameter name="p_pinstance_id" type="VARCHAR" mode="in">
     5         <default/>
     5         <default/>
     6       </parameter>
     6       </parameter>
     7       <body><![CDATA[/*************************************************************************
     7       <body><![CDATA[/*************************************************************************
     8   * The contents of this file are subject to the Compiere Public
     8   * The contents of this file are subject to the Compiere Public
     9   * License 1.1 ("License"); You may not use this file except in
     9   * License 1.1 ("License"); You may not use this file except in
    34   ************************************************************************/
    34   ************************************************************************/
    35   -- Logistice
    35   -- Logistice
    36   v_ResultStr VARCHAR2(2000):='';
    36   v_ResultStr VARCHAR2(2000):='';
    37   v_Message VARCHAR2(2000):='';
    37   v_Message VARCHAR2(2000):='';
    38   v_Result NUMBER:=1; -- 0=failure
    38   v_Result NUMBER:=1; -- 0=failure
    39   v_Record_ID NUMBER;
    39   v_Record_ID VARCHAR2(32);
    40   v_AD_User_ID NUMBER;
    40   v_AD_User_ID VARCHAR2(32);
    41   v_DateColumn VARCHAR2(2000):='';
    41   v_DateColumn VARCHAR2(2000):='';
    42   -- Parameter
    42   -- Parameter
    43   TYPE RECORD IS REF CURSOR;
    43   TYPE RECORD IS REF CURSOR;
    44     Cur_Parameter RECORD;
    44     Cur_Parameter RECORD;
    45     -- Parameter Variables
    45     -- Parameter Variables
    46     v_AD_Client_ID NUMBER(10) ;
    46     v_AD_Client_ID VARCHAR2(32) ;
    47     v_AD_Table_ID NUMBER(10) ;
    47     v_AD_Table_ID VARCHAR2(32) ;
    48     v_DeletePosting VARCHAR(1):='N';
    48     v_DeletePosting VARCHAR(1):='N';
    49     --
    49     --
    50     v_Updated NUMBER(10):=0;
    50     v_Updated NUMBER(10):=0;
    51     v_Deleted NUMBER(10):=0;
    51     v_Deleted NUMBER(10):=0;
    52     v_Cmd VARCHAR2(2000):='';
    52     v_Cmd VARCHAR2(2000):='';
    74       )
    74       )
    75     LOOP
    75     LOOP
    76       v_Record_ID:=Cur_Parameter.Record_ID;
    76       v_Record_ID:=Cur_Parameter.Record_ID;
    77       v_AD_User_ID:=Cur_Parameter.AD_User_ID;
    77       v_AD_User_ID:=Cur_Parameter.AD_User_ID;
    78       IF(Cur_Parameter.ParameterName='AD_Client_ID') THEN
    78       IF(Cur_Parameter.ParameterName='AD_Client_ID') THEN
    79         v_AD_Client_ID:=Cur_Parameter.P_Number;
    79         v_AD_Client_ID:=Cur_Parameter.P_String;
    80         DBMS_OUTPUT.PUT_LINE('  AD_Client_ID=' || v_AD_Client_ID) ;
    80         DBMS_OUTPUT.PUT_LINE('  AD_Client_ID=' || v_AD_Client_ID) ;
    81       ELSIF(Cur_Parameter.ParameterName='AD_Table_ID') THEN
    81       ELSIF(Cur_Parameter.ParameterName='AD_Table_ID') THEN
    82         v_AD_Table_ID:=Cur_Parameter.P_Number;
    82         v_AD_Table_ID:=Cur_Parameter.P_String;
    83         DBMS_OUTPUT.PUT_LINE('  AD_Table_ID=' || v_AD_Table_ID) ;
    83         DBMS_OUTPUT.PUT_LINE('  AD_Table_ID=' || v_AD_Table_ID) ;
    84       ELSIF(Cur_Parameter.ParameterName='DeletePosting') THEN
    84       ELSIF(Cur_Parameter.ParameterName='DeletePosting') THEN
    85         v_DeletePosting:=Cur_Parameter.P_String;
    85         v_DeletePosting:=Cur_Parameter.P_String;
    86         DBMS_OUTPUT.PUT_LINE('  DeletePosting=' || v_DeletePosting) ;
    86         DBMS_OUTPUT.PUT_LINE('  DeletePosting=' || v_DeletePosting) ;
    87       ELSE
    87       ELSE
    98       FOR Cur_Clients IN
    98       FOR Cur_Clients IN
    99         (SELECT AD_Client_ID
    99         (SELECT AD_Client_ID
   100         FROM AD_CLIENT
   100         FROM AD_CLIENT
   101         WHERE(v_AD_Client_ID IS NULL
   101         WHERE(v_AD_Client_ID IS NULL
   102           OR AD_Client_ID=v_AD_Client_ID)
   102           OR AD_Client_ID=v_AD_Client_ID)
   103           AND AD_Client_ID<>0
   103           AND AD_Client_ID<>'0'
   104         )
   104         )
   105       LOOP
   105       LOOP
   106         FOR Cur_Tables IN
   106         FOR Cur_Tables IN
   107           (SELECT DISTINCT t.AD_Table_ID,
   107           (SELECT DISTINCT t.AD_Table_ID,
   108             t.TableName,
   108             t.TableName,
   148                       AND fa_aux.DATEACCT<C_PERIOD.EndDate + 1
   148                       AND fa_aux.DATEACCT<C_PERIOD.EndDate + 1
   149                       AND fa_aux.AD_TABLE_ID = FACT_ACCT.AD_TABLE_ID
   149                       AND fa_aux.AD_TABLE_ID = FACT_ACCT.AD_TABLE_ID
   150                       AND fa_aux.RECORD_ID = FACT_ACCT.RECORD_ID
   150                       AND fa_aux.RECORD_ID = FACT_ACCT.RECORD_ID
   151                     )
   151                     )
   152                 AND Record_ID=(
   152                 AND Record_ID=(
   153                       CASE COALESCE(v_Record_ID, 0) WHEN 0 THEN Record_ID ELSE v_Record_ID
   153                       CASE COALESCE(v_Record_ID, '0') WHEN '0' THEN Record_ID ELSE v_Record_ID
   154                       END)
   154                       END)
   155                 AND AD_Client_ID = Cur_Clients.AD_Client_ID
   155                 AND AD_Client_ID = Cur_Clients.AD_Client_ID
   156               ) LOOP
   156               ) LOOP
   157               IF(Cur_Tables.AD_Table_ID IN(472, 473)) THEN
   157               IF(Cur_Tables.AD_Table_ID IN('472', '473')) THEN
   158                 v_DateColumn:='DATETRX';
   158                 v_DateColumn:='DATETRX';
   159               ELSIF(Cur_Tables.AD_Table_ID IN(392)) THEN
   159               ELSIF(Cur_Tables.AD_Table_ID IN('392')) THEN
   160                 v_DateColumn:='STATEMENTDATE';
   160                 v_DateColumn:='STATEMENTDATE';
   161               ELSIF(Cur_Tables.AD_Table_ID IN(321, 323, 325)) THEN
   161               ELSIF(Cur_Tables.AD_Table_ID IN('321', '323', '325')) THEN
   162                 v_DateColumn:='MOVEMENTDATE';
   162                 v_DateColumn:='MOVEMENTDATE';
   163               ELSE
   163               ELSE
   164                 v_DateColumn:='DATEACCT';
   164                 v_DateColumn:='DATEACCT';
   165               END IF;
   165               END IF;
   166               v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'', Processing=''N'' WHERE AD_Client_ID='  || Cur_Clients.AD_Client_ID
   166               v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'', Processing=''N'' WHERE AD_Client_ID='''  || Cur_Clients.AD_Client_ID
   167         || ' AND (Posted<>''N'' OR Posted IS NULL OR Processing<>''N'' OR Processing IS NULL) AND '   ||
   167         || ''' AND (Posted<>''N'' OR Posted IS NULL OR Processing<>''N'' OR Processing IS NULL) AND '   ||
   168         Cur_Tables.TableName||'_ID = '||Cur_Fact_Acct.Record_ID;
   168         Cur_Tables.TableName||'_ID = '''||Cur_Fact_Acct.Record_ID||'''';
   169               -- DBMS_OUTPUT.PUT_LINE('  executing: ' || v_Cmd);
   169               -- DBMS_OUTPUT.PUT_LINE('  executing: ' || v_Cmd);
   170               EXECUTE IMMEDIATE v_Cmd;
   170               EXECUTE IMMEDIATE v_Cmd;
   171               v_rowcount:=SQL%ROWCOUNT;
   171               v_rowcount:=SQL%ROWCOUNT;
   172               v_Updated:=v_Updated + v_rowcount;
   172               v_Updated:=v_Updated + v_rowcount;
   173               DBMS_OUTPUT.PUT_LINE('  updated=' || v_rowcount) ;
   173               DBMS_OUTPUT.PUT_LINE('  updated=' || v_rowcount) ;
   192 
   192 
   193               v_rowcount:=SQL%ROWCOUNT;
   193               v_rowcount:=SQL%ROWCOUNT;
   194               v_Deleted:=v_Deleted + v_rowcount;
   194               v_Deleted:=v_Deleted + v_rowcount;
   195               DBMS_OUTPUT.PUT_LINE('  deleted=' || v_rowcount) ;
   195               DBMS_OUTPUT.PUT_LINE('  deleted=' || v_rowcount) ;
   196             END LOOP;
   196             END LOOP;
   197         v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'', Processing=''N'' WHERE AD_Client_ID='  || Cur_Clients.AD_Client_ID
   197         v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'', Processing=''N'' WHERE AD_Client_ID='''  || Cur_Clients.AD_Client_ID
   198         || ' AND (Posted=''Y'' OR Processing<>''N'' OR Processing IS NULL) AND NOT EXISTS (SELECT 1 FROM FACT_ACCT WHERE AD_TABLE_ID =' || Cur_Tables.AD_Table_ID ||
   198         || ''' AND (Posted=''Y'' OR Processing<>''N'' OR Processing IS NULL) AND NOT EXISTS (SELECT 1 FROM FACT_ACCT WHERE AD_TABLE_ID =''' || Cur_Tables.AD_Table_ID ||
   199         ' AND RECORD_ID = ' || Cur_Tables.TableName || '_ID AND AD_CLIENT_ID =' || Cur_Clients.AD_Client_ID || ' )';
   199         ''' AND RECORD_ID = ' || Cur_Tables.TableName || '_ID AND AD_CLIENT_ID =''' || Cur_Clients.AD_Client_ID || ''' )';
   200             -- DBMS_OUTPUT.PUT_LINE('  executing: ' || v_Cmd);
   200             -- DBMS_OUTPUT.PUT_LINE('  executing: ' || v_Cmd);
   201             EXECUTE IMMEDIATE v_Cmd;
   201             EXECUTE IMMEDIATE v_Cmd;
   202             v_rowcount:=SQL%ROWCOUNT;
   202             v_rowcount:=SQL%ROWCOUNT;
   203             v_Updated:=v_Updated + v_rowcount;
   203             v_Updated:=v_Updated + v_rowcount;
   204             DBMS_OUTPUT.PUT_LINE('  updated=' || v_rowcount) ;
   204             DBMS_OUTPUT.PUT_LINE('  updated=' || v_rowcount) ;
   205           ELSE
   205           ELSE
   206             v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Processing=''N'' WHERE AD_Client_ID='  || Cur_Clients.AD_Client_ID  || ' AND Processing<>''N'' OR Processing IS NULL';
   206             v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Processing=''N'' WHERE AD_Client_ID='''  || Cur_Clients.AD_Client_ID  || ''' AND Processing<>''N'' OR Processing IS NULL';
   207             EXECUTE IMMEDIATE v_Cmd;
   207             EXECUTE IMMEDIATE v_Cmd;
   208             v_rowcount:=SQL%ROWCOUNT;
   208             v_rowcount:=SQL%ROWCOUNT;
   209             v_Updated:=v_Updated + v_rowcount;
   209             v_Updated:=v_Updated + v_rowcount;
   210             DBMS_OUTPUT.PUT_LINE('  unlocked=' || v_rowcount) ;
   210             DBMS_OUTPUT.PUT_LINE('  unlocked=' || v_rowcount) ;
   211             v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'' WHERE AD_Client_ID='  || Cur_Clients.AD_Client_ID  || ' AND Posted NOT IN (''Y'',''N'') AND Processed=''Y''';
   211             v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'' WHERE AD_Client_ID='''  || Cur_Clients.AD_Client_ID  || ''' AND Posted NOT IN (''Y'',''N'') AND Processed=''Y''';
   212             EXECUTE IMMEDIATE v_Cmd;
   212             EXECUTE IMMEDIATE v_Cmd;
   213             v_rowcount:=SQL%ROWCOUNT;
   213             v_rowcount:=SQL%ROWCOUNT;
   214             v_Updated:=v_Updated + v_rowcount;
   214             v_Updated:=v_Updated + v_rowcount;
   215             DBMS_OUTPUT.PUT_LINE('  updated=' || v_rowcount) ;
   215             DBMS_OUTPUT.PUT_LINE('  updated=' || v_rowcount) ;
   216           END IF;
   216           END IF;