Structure without blank spaces (sqlplus step)
authorAntonio Moreno <antonio.moreno@openbravo.com>
Tue, 22 Apr 2008 13:47:26 +0000
changeset 737 935386ff0f30
parent 736 f97f2c98b645
child 738 5aebdcd19000
Structure without blank spaces (sqlplus step)
database/model/functions/AD_APPLICATION_IMPORT.xml
database/model/functions/AD_DELETE_CLIENT.xml
database/model/functions/AD_DELETE_CLIENT0.xml
database/model/functions/AD_UPDATE_ACCESS.xml
database/model/functions/AD_UPDATE_SEQUENCE.xml
database/model/functions/AD_UPDATE_SEQUENCE_GENERATE.xml
database/model/functions/AGING_GET_SCOPE.xml
database/model/functions/A_ASSET_POST.xml
database/model/functions/CHANGEPROJECTSTATUSTOORDER.xml
database/model/functions/CLOSEPROJECT.xml
database/model/functions/C_BANKSTATEMENT_POST.xml
database/model/functions/C_CALCULATECOST_CATSALARY.xml
database/model/functions/C_CALCULATE_CATSALARY.xml
database/model/functions/C_GETWITHHOLDING.xml
database/model/functions/C_INVOICE_POST.xml
database/model/functions/C_TAXPAYMENT_POST.xml
database/model/functions/FACT_ACCT_RESET.xml
database/model/functions/GENERATEPOFROMPROJECT.xml
database/model/functions/GENERATESOFROMPROJECT.xml
database/model/functions/GENERATESOFROMPROJECTPHASE.xml
database/model/functions/GET_PARETO_ABC.xml
database/model/functions/GET_PURCHASE_PRICE.xml
database/model/functions/MA_WORKEFFORT_VALIDATE.xml
database/model/functions/MRP_PROCESSPLAN.xml
database/model/functions/MRP_PURCHASEORDER.xml
database/model/functions/MRP_REQUISITION.xml
database/model/functions/MRP_RUN_INITIALIZE.xml
database/model/functions/MRP_WORKREQUIREMENT.xml
database/model/functions/M_INOUT_CREATE.xml
database/model/functions/M_INVENTORY_LISTCREATE.xml
database/model/functions/M_REQUISITIONLINE_STATUS.xml
database/model/functions/M_REQUISITION_CREATEPO.xml
database/model/functions/M_REQUISITION_POST.xml
database/model/functions/M_UPDATE_PARETO_PRODUCT.xml
database/model/functions/S_TIMEEXPENSE_POST.xml
database/model/triggers/AD_MENU_TRG.xml
database/model/triggers/AD_PROCESS_TRG.xml
database/model/triggers/AD_REFERENCE_TRG.xml
database/model/triggers/AD_TABLE_TRG.xml
database/model/triggers/AD_TAB_TRG2.xml
database/model/triggers/AD_TREENODE_TRG.xml
database/model/triggers/AD_WINDOW_TRG.xml
database/model/triggers/AD_WINDOW_TRL_TRG.xml
database/model/triggers/AD_WORKBENCH_TRG.xml
database/model/triggers/A_AMORTIZATIONLINE_TRG.xml
database/model/triggers/A_AMORTIZATION_TRG.xml
database/model/triggers/C_BANKACCOUNTIBAN_TRG.xml
database/model/triggers/C_BANKCOUNTRY_TRG.xml
database/model/triggers/C_BP_BANKACCOUNTIBAN_TRG.xml
database/model/triggers/C_BP_SALCATEGORY_TRG.xml
database/model/triggers/C_BP_SALCATEGORY_TRG2.xml
database/model/triggers/C_BSTMTLINE_CHK_RESTRICT_TRG.xml
database/model/triggers/C_BUDGETLINE_TRG.xml
database/model/triggers/C_CASHLINE_CHK_RESTRICT_TRG.xml
database/model/triggers/C_CASH_CHK_RESTRICTIONS_TRG.xml
database/model/triggers/C_CONVERSION_RATE_TRG.xml
database/model/triggers/C_COUNTRY_TRG.xml
database/model/triggers/C_CURRENCY_TRG.xml
database/model/triggers/C_DEBT_PAYMENT_TRG.xml
database/model/triggers/C_DPMLINE_CHK_RESTRICTIONS_TRG.xml
database/model/triggers/C_INVOICELINE_TRG3.xml
database/model/triggers/C_INVOICETAX_TRG.xml
database/model/triggers/C_INVOICETAX_TRG2.xml
database/model/triggers/C_ORDERTAX_TRG.xml
database/model/triggers/C_ORDER_CHK_RESTRINCTIONS_TRG.xml
database/model/triggers/C_ORDLINE_CHK_RESTRICTIONS_TRG.xml
database/model/triggers/C_TAXPAYMENT_TRG.xml
database/model/triggers/C_TAXREGISTERLINE_TRG.xml
database/model/triggers/C_TAXREGISTER_TRG.xml
database/model/triggers/GL_JL_CHK_RESTRICTIONS_TRG.xml
database/model/triggers/M_INOUT_CHK_RESTRICTIONS_TRG.xml
database/model/triggers/M_PRODUCT_TRG.xml
database/model/triggers/M_REQUISITIONLINE_TRG.xml
database/model/triggers/M_REQUISITION_TRG.xml
database/model/triggers/S_TIMEEXPENSELINE_TRG.xml
database/model/views/AD_REF_LIST_V.xml
database/model/views/AD_TABLE_POST_V.xml
database/model/views/C_DEBT_PAYMENT_V.xml
database/model/views/C_INVOICELINE_V.xml
database/model/views/C_INVOICE_LINETAX_V.xml
database/model/views/C_INVOICE_LINETAX_VT.xml
database/model/views/C_INVOICE_V.xml
database/model/views/C_ORDER_LINETAX_V.xml
database/model/views/C_ORDER_LINETAX_VT.xml
database/model/views/C_PROJECT_DETAILS_V.xml
database/model/views/C_PROJECT_DETAILS_VT.xml
database/model/views/MA_SEQUENCE_EMPLOYEE_COST.xml
database/model/views/MA_SEQUENCE_INDIRECT_COST_COST.xml
database/model/views/MA_SEQUENCE_MACHINE_COST.xml
database/model/views/M_INOUT_LINE_V.xml
database/model/views/M_INOUT_LINE_VT.xml
database/model/views/RV_C_INVOICE.xml
database/model/views/RV_C_INVOICELINE.xml
database/model/views/RV_C_INVOICE_CUSTOMERPRODQTR.xml
database/model/views/RV_C_INVOICE_CUSTOMERVENDQTR.xml
database/model/views/RV_C_INVOICE_DAY.xml
database/model/views/RV_C_INVOICE_MONTH.xml
database/model/views/RV_C_INVOICE_PRODMONTH.xml
database/model/views/RV_C_INVOICE_PRODWEEK.xml
database/model/views/RV_C_INVOICE_VENDORMONTH.xml
database/model/views/RV_C_INVOICE_WEEK.xml
database/model/views/RV_PRODUCT_COSTING.xml
--- a/database/model/functions/AD_APPLICATION_IMPORT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/AD_APPLICATION_IMPORT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -46,535 +46,535 @@
       <parameter name="p_baseinstalation" type="CHAR" mode="in">
         <default/>
       </parameter>
-      <body><![CDATA[/************************************************************************* 
-* The contents of this file are subject to the Openbravo  Public  License 
-* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License 
-* Version 1.1  with a permitted attribution clause; you may not  use this 
-* file except in compliance with the License. You  may  obtain  a copy of 
-* the License at http://www.openbravo.com/legal/license.html 
-* Software distributed under the License  is  distributed  on  an "AS IS" 
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
-* License for the specific  language  governing  rights  and  limitations 
-* under the License. 
-* The Original Code is Openbravo ERP. 
-* The Initial Developer of the Original Code is Openbravo SL 
-* All portions are Copyright (C) 2001-2006 Openbravo SL 
-* All Rights Reserved. 
-* Contributor(s):  ______________________________________. 
-************************************************************************/ 
- v_minId     NUMBER(10); 
--- v_maxId     NUMBER(10); 
- v_tableOffset   NUMBER(10); 
- v_windowOffset   NUMBER(10); 
- v_columnOffset   NUMBER(10); 
- v_tabOffset    NUMBER(10); 
- v_auxiliarinputOffset NUMBER(10); 
- v_fieldOffset   NUMBER(10); 
- v_fieldgroupOffset  NUMBER(10); 
- v_referenceOffset  NUMBER(10); 
- v_reftableOffset  NUMBER(10); --NOT needed because it lacks of an ID 
- v_reflistOffset   NUMBER(10); 
- v_valruleOffset   NUMBER(10); 
- v_elementOffset   NUMBER(10); 
- v_formOffset   NUMBER(10); 
- v_messageOffset   NUMBER(10); 
- v_menuOffset   NUMBER(10); 
- v_reportviewOffset  NUMBER(10); 
- v_processOffset   NUMBER(10); 
- v_processparaOffset  NUMBER(10); 
- v_sequenceOffset  NUMBER(10); 
- v_taskOffset   NUMBER(10); 
- v_treeOffset   NUMBER(10); 
- v_workflowOffset  NUMBER(10); 
- v_wfnodeOffset   NUMBER(10); 
- v_wfnodenextOffset  NUMBER(10); 
- v_nextNo    NUMBER(10); 
-BEGIN 
---AD_Table 
- --Next sequence number (blocking for update) 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Table' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+      <body><![CDATA[/*************************************************************************
+* The contents of this file are subject to the Openbravo  Public  License
+* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+* Version 1.1  with a permitted attribution clause; you may not  use this
+* file except in compliance with the License. You  may  obtain  a copy of
+* the License at http://www.openbravo.com/legal/license.html
+* Software distributed under the License  is  distributed  on  an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific  language  governing  rights  and  limitations
+* under the License.
+* The Original Code is Openbravo ERP.
+* The Initial Developer of the Original Code is Openbravo SL
+* All portions are Copyright (C) 2001-2006 Openbravo SL
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************/
+ v_minId     NUMBER(10);
+-- v_maxId     NUMBER(10);
+ v_tableOffset   NUMBER(10);
+ v_windowOffset   NUMBER(10);
+ v_columnOffset   NUMBER(10);
+ v_tabOffset    NUMBER(10);
+ v_auxiliarinputOffset NUMBER(10);
+ v_fieldOffset   NUMBER(10);
+ v_fieldgroupOffset  NUMBER(10);
+ v_referenceOffset  NUMBER(10);
+ v_reftableOffset  NUMBER(10); --NOT needed because it lacks of an ID
+ v_reflistOffset   NUMBER(10);
+ v_valruleOffset   NUMBER(10);
+ v_elementOffset   NUMBER(10);
+ v_formOffset   NUMBER(10);
+ v_messageOffset   NUMBER(10);
+ v_menuOffset   NUMBER(10);
+ v_reportviewOffset  NUMBER(10);
+ v_processOffset   NUMBER(10);
+ v_processparaOffset  NUMBER(10);
+ v_sequenceOffset  NUMBER(10);
+ v_taskOffset   NUMBER(10);
+ v_treeOffset   NUMBER(10);
+ v_workflowOffset  NUMBER(10);
+ v_wfnodeOffset   NUMBER(10);
+ v_wfnodenextOffset  NUMBER(10);
+ v_nextNo    NUMBER(10);
+BEGIN
+--AD_Table
+ --Next sequence number (blocking for update)
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Table' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- --Mininum and maximum values of ID in TAX_AUX 
- SELECT MIN(AD_TABLE_ID)--, MAX(AD_TABLE_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_TABLE WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo; 
- v_tableOffset:=v_nextNo - v_minId; 
-/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Table' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'; */ 
- 
- 
---AD_Column 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Column' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ --Mininum and maximum values of ID in TAX_AUX
+ SELECT MIN(AD_TABLE_ID)--, MAX(AD_TABLE_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_TABLE WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo;
+ v_tableOffset:=v_nextNo - v_minId;
+/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Table' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'; */
+
+
+--AD_Column
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Column' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_COLUMN_ID)--, MAX(AD_COLUMN_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_COLUMN WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo; 
- v_columnOffset:=v_nextNo - v_minId; 
-/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Column' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'; */ 
- 
- 
---AD_Tab 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Tab' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_COLUMN_ID)--, MAX(AD_COLUMN_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_COLUMN WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo;
+ v_columnOffset:=v_nextNo - v_minId;
+/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Column' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'; */
+
+
+--AD_Tab
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Tab' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_TAB_ID)--, MAX(AD_TAB_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo; 
- v_tabOffset:=v_nextNo - v_minId; 
-/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Tab' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/ 
---AD_Window 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Window' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_TAB_ID)--, MAX(AD_TAB_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo;
+ v_tabOffset:=v_nextNo - v_minId;
+/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Tab' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/
+--AD_Window
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Window' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_WINDOW_ID)--, MAX(AD_WINDOW_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_WINDOW WHERE AD_WINDOW_ID IN 
-   (SELECT AD_WINDOW_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo) 
- AND AD_WINDOW_ID BETWEEN p_windowIdFrom AND p_windowIdTo; 
- v_windowOffset:=v_nextNo - v_minId; 
-/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Window' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/ 
---AD_Field 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Field' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_WINDOW_ID)--, MAX(AD_WINDOW_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_WINDOW WHERE AD_WINDOW_ID IN
+   (SELECT AD_WINDOW_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo)
+ AND AD_WINDOW_ID BETWEEN p_windowIdFrom AND p_windowIdTo;
+ v_windowOffset:=v_nextNo - v_minId;
+/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Window' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/
+--AD_Field
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Field' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_FIELD_ID)--, MAX(AD_FIELD_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_FIELD WHERE AD_TAB_ID IN 
-   (SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo); 
- v_fieldOffset:=v_nextNo - v_minId; 
-/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Field' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/ 
---AD_FieldGroup 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_FieldGroup' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_FIELD_ID)--, MAX(AD_FIELD_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_FIELD WHERE AD_TAB_ID IN
+   (SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo);
+ v_fieldOffset:=v_nextNo - v_minId;
+/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Field' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/
+--AD_FieldGroup
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_FieldGroup' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_FIELDGROUP_ID)--, MAX(AD_FIELDGROUP_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_FIELDGROUP WHERE AD_FIELDGROUP_ID IN 
-   (SELECT AD_FIELDGROUP_ID FROM TAD_AUX.AD_FIELD WHERE AD_TAB_ID IN 
-      (SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo)); 
- v_fieldgroupOffset:=v_nextNo - v_minId; 
-/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_FieldGroup' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/ 
---AD_Reference 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Reference' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_FIELDGROUP_ID)--, MAX(AD_FIELDGROUP_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_FIELDGROUP WHERE AD_FIELDGROUP_ID IN
+   (SELECT AD_FIELDGROUP_ID FROM TAD_AUX.AD_FIELD WHERE AD_TAB_ID IN
+      (SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo));
+ v_fieldgroupOffset:=v_nextNo - v_minId;
+/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_FieldGroup' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/
+--AD_Reference
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Reference' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_REFERENCE_ID)--, MAX(AD_REFERENCE_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_REFERENCE WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo; 
- v_referenceOffset:=v_nextNo - v_minId; 
- /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Reference' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/ 
---AD_Ref_List 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Ref_List' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_REFERENCE_ID)--, MAX(AD_REFERENCE_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_REFERENCE WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo;
+ v_referenceOffset:=v_nextNo - v_minId;
+ /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Reference' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/
+--AD_Ref_List
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Ref_List' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_REF_LIST_ID)--, MAX(AD_REF_LIST_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_REF_LIST WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo; 
- v_reflistOffset:=v_nextNo - v_minId; 
- /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Ref_List' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/ 
---AD_Val_Rule 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Val_Rule' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_REF_LIST_ID)--, MAX(AD_REF_LIST_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_REF_LIST WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo;
+ v_reflistOffset:=v_nextNo - v_minId;
+ /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Ref_List' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/
+--AD_Val_Rule
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Val_Rule' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_VAL_RULE_ID)--, MAX(AD_VAL_RULE_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_VAL_RULE WHERE AD_VAL_RULE_ID BETWEEN p_valruleIdFrom AND p_valruleIdTo; 
- v_valruleOffset:=v_nextNo - v_minId; 
- /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Val_Rule' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/ 
---AD_Element 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Element' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_VAL_RULE_ID)--, MAX(AD_VAL_RULE_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_VAL_RULE WHERE AD_VAL_RULE_ID BETWEEN p_valruleIdFrom AND p_valruleIdTo;
+ v_valruleOffset:=v_nextNo - v_minId;
+ /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Val_Rule' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/
+--AD_Element
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Element' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_ELEMENT_ID)--, MAX(AD_ELEMENT_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_ELEMENT WHERE AD_ELEMENT_ID BETWEEN p_elementIdFrom AND p_elementIdTo; 
- v_elementOffset:=v_nextNo - v_minId; 
- /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Element' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/ 
---AD_Menu 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Menu' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_ELEMENT_ID)--, MAX(AD_ELEMENT_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_ELEMENT WHERE AD_ELEMENT_ID BETWEEN p_elementIdFrom AND p_elementIdTo;
+ v_elementOffset:=v_nextNo - v_minId;
+ /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Element' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/
+--AD_Menu
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Menu' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_MENU_ID)--, MAX(AD_MENU_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_MENU WHERE AD_MENU_ID BETWEEN p_menuIdFrom AND p_menuIdTo; 
- v_menuOffset:=v_nextNo - v_minId; 
- /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Menu' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/ 
---AD_Sequence 
- SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence 
- WHERE Name='AD_Sequence' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' 
+ SELECT MIN(AD_MENU_ID)--, MAX(AD_MENU_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_MENU WHERE AD_MENU_ID BETWEEN p_menuIdFrom AND p_menuIdTo;
+ v_menuOffset:=v_nextNo - v_minId;
+ /*UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Menu' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';*/
+--AD_Sequence
+ SELECT CurrentNextSys INTO v_nextNo FROM AD_Sequence
+ WHERE Name='AD_Sequence' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'
  FOR UPDATE OF CurrentNextSys;
- SELECT MIN(AD_SEQUENCE_ID)--, MAX(AD_SEQUENCE_ID) 
- INTO v_minId--, v_maxId 
- FROM TAD_AUX.AD_SEQUENCE WHERE AD_SEQUENCE_ID BETWEEN p_sequenceIdFrom AND p_sequenceIdTo; 
- v_sequenceOffset:=v_nextNo - v_minId; 
-/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO 
- WHERE  Name='AD_Sequence' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y'; 
-*/ 
- 
- 
---AD_REF_TABLE doesn't need a translation because it lacks of an ID 
---Por la misma razon, tampoco necesitan traslacion las tablas de traduccion (..._TRL) 
- 
---Comienzo de carga de datos. 
---Primero, inhabilitar constraints de integridad referencial (existen referencias circulares...) 
- --AD_Table. No inhabilitamos el trigger para que inserte valores en ad_sequence 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TABLE DISABLE CONSTRAINT AD_WINDOW_TABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TABLE DISABLE CONSTRAINT AD_VALRULE_TABLE'); 
- --AD_Column. No tiene trigger para insert 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT ADPROCESS_ADCOLUMN'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_ELEMENT_AD_COLUMN'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_REFERENCE_COLUMNDATATYPE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_REFERENCE_COLUMNVALUE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_TABLE_COLUMN'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_VALRULE_COLUMN'); 
- --AD_Tab. Inhabilitamos trigger para que no inserte en ad_tab_trl 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_TAB_TRG DISABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT ADCOLUMN_ADTABSORTORDER'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT ADCOLUMN_ADTABSORTYESNO'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT ADPROCESS_ADTAB'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT ADTAB_INCLUDED'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT AD_COLUMN_AD_TAB'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT AD_TABLE_TAB'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT AD_WINDOW_TAB'); 
- --AD_Window. Constraints no necesita. Triggers si. Habra que insertar a mano en la window_access!!! 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_WINDOW_TRG DISABLE'); 
- --AD_Window_Access 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_ACCESS DISABLE CONSTRAINT ADWINDOW_ADWINDOWACCESS'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_ACCESS DISABLE CONSTRAINT ADROLE_ADWINDOWACCESS'); 
- --AD_Field 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_FIELD_TRG DISABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD DISABLE CONSTRAINT ADFIELDGROUP_ADFIELD'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD DISABLE CONSTRAINT AD_COLUMN_FIELD'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD DISABLE CONSTRAINT AD_TAB_FIELD'); 
- --AD_FieldGroup no necesita. Triggers si 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_FIELDGROUP_TRG DISABLE'); 
- --AD_Reference no necesita. Triggers si 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_REFERENCE_TRG DISABLE'); 
- --AD_Ref_List 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_REF_LIST_TRG DISABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_LIST DISABLE CONSTRAINT AD_REFERENCE_REFLIST'); 
- --AD_Ref_Table 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE DISABLE CONSTRAINT ADD_TABLE_REFTABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE DISABLE CONSTRAINT AD_COLUMN_REFTABLE_DISPLAY'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE DISABLE CONSTRAINT AD_COLUMN_REFTABLE_ID'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE DISABLE CONSTRAINT AD_REFERENCE_REFTABLE'); 
- --AD_Menu 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_MENU_TRG DISABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADFORM_ADMENU'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADPROCESS_ADMENU'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADTASK_ADMENU'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADWINDOW_ADMENU'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADWORKFLOW_ADMENU'); 
- --AD_Treenode 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TREENODE DISABLE CONSTRAINT ADTREE_ADTREENODE'); 
- --AD_Element 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_ELEMENT_TRG DISABLE'); 
- --AD_Val_Rule no necesita ni constraints ni triggers 
- --AD_Tab_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB_TRL DISABLE CONSTRAINT AD_TABTRL'); 
- --AD_Window_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_TRL DISABLE CONSTRAINT AD_WINDOWTRL'); 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_WINDOW_TRL_TRG DISABLE'); 
- --AD_Field_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD_TRL DISABLE CONSTRAINT AD_FIELDTRL'); 
- --AD_FieldGroup_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELDGROUP_TRL DISABLE CONSTRAINT ADFIELDGROUP_TRL'); 
- --AD_Ref_List_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_LIST_TRL DISABLE CONSTRAINT AD_REFLISTTRL'); 
- --AD_Element_Trl 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_ELEMENT_TRL_TRG DISABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_ELEMENT_TRL DISABLE CONSTRAINT ADELEMENT_ADELEMENTTRL'); 
- --AD_Menu_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU_TRL DISABLE CONSTRAINT AD_MENUTRL'); 
- 
- 
- 
- 
- --Insercion de valores, con traslacion de claves 
- --AD_Table 
- INSERT INTO AD_TABLE (AD_TABLE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, 
- NAME, DESCRIPTION, HELP, TABLENAME, ISVIEW, ACCESSLEVEL, ENTITYTYPE, AD_WINDOW_ID, AD_VAL_RULE_ID, 
- LOADSEQ, ISSECURITYENABLED, ISDELETEABLE, ISHIGHVOLUME, IMPORTTABLE, ISCHANGELOG, REPLICATIONTYPE, 
- PO_WINDOW_ID, ISDEFAULTACCT) 
- SELECT AD_TABLE_ID+v_tableOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, 
- NAME, DESCRIPTION, HELP, TABLENAME, ISVIEW, ACCESSLEVEL, ENTITYTYPE, CASE WHEN AD_WINDOW_ID>699999 
- THEN AD_WINDOW_ID+v_windowOffset ELSE AD_WINDOW_ID END, AD_VAL_RULE_ID+v_valruleOffset, 
- LOADSEQ, ISSECURITYENABLED, ISDELETEABLE, ISHIGHVOLUME, IMPORTTABLE, ISCHANGELOG, REPLICATIONTYPE, 
- CASE WHEN PO_WINDOW_ID>699999 THEN PO_WINDOW_ID+v_windowOffset ELSE PO_WINDOW_ID END, ISDEFAULTACCT 
- FROM TAD_AUX.AD_TABLE WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo; 
- 
- --AD_Column 
- INSERT INTO AD_COLUMN (AD_COLUMN_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, UPDATED, CREATEDBY, UPDATEDBY, 
- NAME, DESCRIPTION, HELP, VERSION, ENTITYTYPE, COLUMNNAME, AD_TABLE_ID, AD_REFERENCE_ID, 
- AD_REFERENCE_VALUE_ID, AD_VAL_RULE_ID, FIELDLENGTH, DEFAULTVALUE, ISKEY, ISPARENT, 
- ISMANDATORY, ISUPDATEABLE, READONLYLOGIC, ISIDENTIFIER, SEQNO, ISTRANSLATED, ISENCRYPTED, 
- CALLOUT, VFORMAT, VALUEMIN, VALUEMAX, ISSELECTIONCOLUMN, AD_ELEMENT_ID, AD_PROCESS_ID, 
- ISSYNCDATABASE, ISSESSIONATTR, ISSECONDARYKEY) 
- SELECT AD_COLUMN_ID+v_columnOffset, 0, 0, ISACTIVE, now(), now(), 0, 0, 
- NAME, DESCRIPTION, HELP, VERSION, ENTITYTYPE, COLUMNNAME, AD_TABLE_ID+v_tableOffset, 
- CASE WHEN AD_REFERENCE_ID>699999 THEN AD_REFERENCE_ID+v_referenceOffset ELSE AD_REFERENCE_ID END, 
- CASE WHEN AD_REFERENCE_VALUE_ID>699999 THEN AD_REFERENCE_VALUE_ID+v_referenceOffset ELSE AD_REFERENCE_VALUE_ID END, 
- CASE WHEN AD_VAL_RULE_ID>699999 THEN AD_VAL_RULE_ID+v_valruleOffset ELSE AD_VAL_RULE_ID END, FIELDLENGTH, DEFAULTVALUE, ISKEY, ISPARENT, 
- ISMANDATORY, ISUPDATEABLE, READONLYLOGIC, ISIDENTIFIER, SEQNO, ISTRANSLATED, ISENCRYPTED, 
- CALLOUT, VFORMAT, VALUEMIN, VALUEMAX, ISSELECTIONCOLUMN, CASE WHEN AD_ELEMENT_ID>699999 
- THEN AD_ELEMENT_ID+v_elementOffset ELSE AD_ELEMENT_ID END, AD_PROCESS_ID+v_processOffset, 
- ISSYNCDATABASE, ISSESSIONATTR, ISSECONDARYKEY 
- FROM TAD_AUX.AD_COLUMN WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo; 
- 
- 
- --ad_tab 
- INSERT INTO AD_TAB (AD_TAB_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, 
- UPDATEDBY, NAME, DESCRIPTION, HELP, AD_TABLE_ID, AD_WINDOW_ID, SEQNO, TABLEVEL, ISSINGLEROW, 
- ISINFOTAB, ISTRANSLATIONTAB, ISREADONLY, AD_COLUMN_ID, HASTREE, WHERECLAUSE, ORDERBYCLAUSE, 
- COMMITWARNING, AD_PROCESS_ID, PROCESSING, AD_IMAGE_ID, IMPORTFIELDS, AD_COLUMNSORTORDER_ID, 
- AD_COLUMNSORTYESNO_ID, ISSORTTAB, ENTITYTYPE, INCLUDED_TAB_ID, FILTERCLAUSE) 
- SELECT AD_TAB_ID+v_tabOffset, 0, 0, ISACTIVE, now(), 0, now(), 
- 0, NAME, DESCRIPTION, HELP, AD_TABLE_ID+v_tableOffset, CASE WHEN AD_WINDOW_ID>699999 
- THEN AD_WINDOW_ID+v_windowOffset ELSE AD_WINDOW_ID END, SEQNO, TABLEVEL, 
- ISSINGLEROW, ISINFOTAB, ISTRANSLATIONTAB, ISREADONLY, AD_COLUMN_ID+v_columnOffset, HASTREE, WHERECLAUSE, 
- ORDERBYCLAUSE, COMMITWARNING, AD_PROCESS_ID+v_processOffset, PROCESSING, AD_IMAGE_ID, IMPORTFIELDS, 
- AD_COLUMNSORTORDER_ID+v_columnOffset, AD_COLUMNSORTYESNO_ID+v_columnOffset, ISSORTTAB, ENTITYTYPE, 
- INCLUDED_TAB_ID+v_tabOffset, FILTERCLAUSE 
- FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo; 
- 
- --ad_tab_trl 
- INSERT INTO AD_TAB_TRL (AD_TAB_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, 
- CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, COMMITWARNING, ISTRANSLATED) 
- SELECT AD_TAB_ID+v_tabOffset,AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 
- 0, NAME, DESCRIPTION, HELP, COMMITWARNING, ISTRANSLATED 
- FROM TAD_AUX.AD_TAB_TRL WHERE AD_TAB_ID IN ( 
-   SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo); 
- 
- --ad_window 
- INSERT INTO AD_WINDOW (AD_WINDOW_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, 
- UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, WINDOWTYPE, ISSOTRX, ENTITYTYPE, PROCESSING, 
- AD_IMAGE_ID, AD_COLOR_ID, ISDEFAULT) 
- SELECT AD_WINDOW_ID+v_windowOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, 
- NAME, DESCRIPTION, HELP, WINDOWTYPE, ISSOTRX, ENTITYTYPE, PROCESSING, AD_IMAGE_ID, 
- AD_COLOR_ID, ISDEFAULT 
- FROM TAD_AUX.AD_WINDOW WHERE AD_WINDOW_ID BETWEEN p_windowIdFrom AND p_windowIdTo; 
- 
- --ad_window_trl 
- INSERT INTO AD_WINDOW_TRL (AD_WINDOW_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, 
- CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, ISTRANSLATED) 
- SELECT AD_WINDOW_ID+v_windowOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0, 
- NAME, DESCRIPTION, HELP, ISTRANSLATED 
- FROM TAD_AUX.AD_WINDOW_TRL WHERE AD_WINDOW_ID BETWEEN p_windowIdFrom AND p_windowIdTo; 
- 
- --ad_window_access 
- INSERT INTO AD_WINDOW_ACCESS (AD_WINDOW_ID, AD_ROLE_ID, AD_CLIENT_ID, AD_ORG_ID, 
- ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, ISREADWRITE) 
- SELECT AD_WINDOW_ID+v_windowOffset, AD_ROLE_ID, 0, 0, 'Y', now(), 0, now(), 0, 'Y' 
- FROM TAD_AUX.AD_WINDOW_ACCESS WHERE AD_WINDOW_ID BETWEEN p_windowIdFrom AND p_windowIdTo; 
- 
- --ad_auxiliarinput no esta hecho porque no hay ninguno en produccion 
- 
- --ad_field 
- INSERT INTO AD_FIELD (AD_FIELD_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, 
- UPDATEDBY, NAME, DESCRIPTION, HELP, ISCENTRALLYMAINTAINED, AD_TAB_ID, AD_COLUMN_ID, AD_FIELDGROUP_ID, 
- ISDISPLAYED, DISPLAYLOGIC, DISPLAYLENGTH, ISREADONLY, SEQNO, SORTNO, ISSAMELINE, ISHEADING, 
- ISFIELDONLY, ISENCRYPTED, ENTITYTYPE, SHOWINRELATION) 
- SELECT AD_FIELD_ID+v_fieldOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME, 
- DESCRIPTION, HELP, ISCENTRALLYMAINTAINED, AD_TAB_ID+v_tabOffset, AD_COLUMN_ID+v_columnOffset, 
- AD_FIELDGROUP_ID+v_fieldgroupOffset, ISDISPLAYED, DISPLAYLOGIC, DISPLAYLENGTH, ISREADONLY, 
- SEQNO, SORTNO, ISSAMELINE, ISHEADING, ISFIELDONLY, ISENCRYPTED, ENTITYTYPE, SHOWINRELATION 
- FROM TAD_AUX.AD_FIELD WHERE AD_TAB_ID IN ( 
-   SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo); 
- 
- --ad_field_trl 
- INSERT INTO AD_FIELD_TRL (AD_FIELD_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, 
- CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, ISTRANSLATED) 
- SELECT AD_FIELD_ID+v_fieldOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME, 
- DESCRIPTION, HELP, ISTRANSLATED 
- FROM TAD_AUX.AD_FIELD_TRL WHERE AD_FIELD_ID IN ( 
-   SELECT AD_FIELD_ID FROM TAD_AUX.AD_FIELD 
-   WHERE AD_TAB_ID IN ( 
-       SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo)); 
- 
- --ad_fieldgroup no hay en produccion 
- 
- --ad_fieldgroup_trl no hay en produccion 
- 
- --ad_element 
- INSERT INTO AD_ELEMENT (AD_ELEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, 
- UPDATED, UPDATEDBY, COLUMNNAME, ENTITYTYPE, NAME, PRINTNAME, DESCRIPTION, HELP, PO_NAME, 
- PO_PRINTNAME, PO_DESCRIPTION, PO_HELP) 
- SELECT AD_ELEMENT_ID+v_elementOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, COLUMNNAME, 
- ENTITYTYPE, NAME, PRINTNAME, DESCRIPTION, HELP, PO_NAME, PO_PRINTNAME, PO_DESCRIPTION, PO_HELP 
- FROM TAD_AUX.AD_ELEMENT WHERE AD_ELEMENT_ID BETWEEN p_elementIdFrom AND p_elementIdTo; 
- 
- --ad_element_trl 
- INSERT INTO AD_ELEMENT_TRL (AD_ELEMENT_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, 
- CREATEDBY, UPDATED, UPDATEDBY, NAME, PRINTNAME, DESCRIPTION, HELP, PO_NAME, PO_PRINTNAME, 
- PO_DESCRIPTION, PO_HELP, ISTRANSLATED) 
- SELECT AD_ELEMENT_ID+v_elementOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0, 
- NAME, PRINTNAME, DESCRIPTION, HELP, PO_NAME, PO_PRINTNAME, PO_DESCRIPTION, PO_HELP, ISTRANSLATED 
- FROM TAD_AUX.AD_ELEMENT_TRL WHERE AD_ELEMENT_ID BETWEEN p_elementIdFrom AND p_elementIdTo; 
- 
- 
- --ad_reference 
- INSERT INTO AD_REFERENCE (AD_REFERENCE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, 
- UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, VALIDATIONTYPE, VFORMAT, ENTITYTYPE) 
- SELECT AD_REFERENCE_ID+v_referenceOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME, DESCRIPTION, 
- HELP, VALIDATIONTYPE, VFORMAT, ENTITYTYPE 
- FROM TAD_AUX.AD_REFERENCE WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo; 
- 
- --ad_reference_trl 
- INSERT INTO AD_REFERENCE_TRL (AD_REFERENCE_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, 
- CREATED, CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, ISTRANSLATED) 
- SELECT AD_REFERENCE_ID+v_referenceOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0, 
- NAME, DESCRIPTION, HELP, ISTRANSLATED 
- FROM TAD_AUX.AD_REFERENCE_TRL WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo; 
- 
- --ad_ref_table 
- INSERT INTO AD_REF_TABLE (AD_REFERENCE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, 
- UPDATED, UPDATEDBY, AD_TABLE_ID, AD_KEY, AD_DISPLAY, ISVALUEDISPLAYED, WHERECLAUSE, ORDERBYCLAUSE, 
- ENTITYTYPE) 
- SELECT AD_REFERENCE_ID+v_referenceOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, 
- AD_TABLE_ID+v_tableOffset, CASE WHEN AD_KEY>699999 THEN AD_KEY+v_columnOffset ELSE AD_KEY END, 
- CASE WHEN AD_DISPLAY>699999 THEN AD_DISPLAY+v_columnOffset ELSE AD_DISPLAY END, 
- ISVALUEDISPLAYED, WHERECLAUSE, ORDERBYCLAUSE, ENTITYTYPE 
- FROM TAD_AUX.AD_REF_TABLE WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo; 
- 
- --ad_ref_list 
- INSERT INTO AD_REF_LIST (AD_REF_LIST_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, 
- UPDATED, UPDATEDBY, VALUE, NAME, DESCRIPTION, AD_REFERENCE_ID, VALIDFROM, VALIDTO, ENTITYTYPE) 
- SELECT AD_REF_LIST_ID+v_reflistOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, VALUE, NAME, 
- DESCRIPTION, AD_REFERENCE_ID+v_referenceOffset, VALIDFROM, VALIDTO, ENTITYTYPE 
- FROM TAD_AUX.AD_REF_LIST WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo; 
- 
- --ad_ref_list_trl 
- INSERT INTO AD_REF_LIST_TRL (AD_REF_LIST_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, 
- CREATED, CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, ISTRANSLATED) 
- SELECT AD_REF_LIST_ID+v_reflistOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0, 
- NAME, DESCRIPTION, ISTRANSLATED 
- FROM TAD_AUX.AD_REF_LIST_TRL WHERE AD_REF_LIST_ID IN ( 
-   SELECT AD_REF_LIST_ID FROM TAD_AUX.AD_REF_LIST 
-   WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo); 
- 
- 
- --ad_menu 
- INSERT INTO AD_MENU (AD_MENU_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, 
- NAME, UPDATEDBY, DESCRIPTION, ISSUMMARY, ISSOTRX, ISREADONLY, ACTION, AD_WINDOW_ID, AD_WORKFLOW_ID, 
- AD_TASK_ID, AD_PROCESS_ID, AD_FORM_ID, AD_WORKBENCH_ID, ENTITYTYPE) 
- SELECT AD_MENU_ID+v_menuOffset, 0, 0, ISACTIVE, now(), 0, now(), NAME, UPDATEDBY, DESCRIPTION, 
- ISSUMMARY, ISSOTRX, ISREADONLY, ACTION, AD_WINDOW_ID+v_windowOffset, AD_WORKFLOW_ID+v_workflowOffset, 
- AD_TASK_ID+v_taskOffset, AD_PROCESS_ID+v_processOffset, AD_FORM_ID+v_formOffset, AD_WORKBENCH_ID, 
- ENTITYTYPE 
- FROM TAD_AUX.AD_MENU WHERE AD_MENU_ID BETWEEN p_menuIdFrom AND p_menuIdTo; 
- 
- --ad_menu_trl 
- INSERT INTO AD_MENU_TRL (AD_MENU_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, 
- CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, ISTRANSLATED) 
- SELECT AD_MENU_ID+v_menuOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME, 
- DESCRIPTION, ISTRANSLATED 
- FROM TAD_AUX.AD_MENU_TRL WHERE AD_MENU_ID BETWEEN p_menuIdFrom AND p_menuIdTo; 
- 
- --ad_treenode 
- INSERT INTO AD_TREENODE (AD_TREE_ID, NODE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, 
- CREATEDBY, UPDATED, UPDATEDBY, PARENT_ID, SEQNO) 
- SELECT AD_TREE_ID, NODE_ID+v_menuOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, 
- CASE WHEN PARENT_ID>699999 THEN PARENT_ID+v_menuOffset ELSE PARENT_ID END, SEQNO 
- FROM TAD_AUX.AD_TREENODE WHERE NODE_ID BETWEEN p_menuIdFrom AND p_menuIdTo; 
- 
- --ad_val_rule 
- INSERT INTO AD_VAL_RULE (AD_VAL_RULE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, 
- UPDATED, UPDATEDBY, NAME, DESCRIPTION, TYPE, CODE, ENTITYTYPE) 
- SELECT AD_VAL_RULE_ID+v_valruleOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME, 
- DESCRIPTION, TYPE, CODE, ENTITYTYPE 
- FROM TAD_AUX.AD_VAL_RULE WHERE AD_VAL_RULE_ID BETWEEN p_valruleIdFrom AND p_valruleIdTo; 
- 
- 
- 
---  por si falla lo del nulo!!!! 
--- (CASE WHEN INCLUDED_TAB_ID IS  NULL THEN  NULL ELSE  INCLUDED_TAB_ID+v_tabOffset END) 
- 
- 
- 
- --AD_Table. No inhabilitamos el trigger para que inserte valores en ad_sequence 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TABLE ENABLE CONSTRAINT AD_WINDOW_TABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TABLE ENABLE CONSTRAINT AD_VALRULE_TABLE'); 
- --AD_Column. No tiene trigger para insert 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT ADPROCESS_ADCOLUMN'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_ELEMENT_AD_COLUMN'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_REFERENCE_COLUMNDATATYPE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_REFERENCE_COLUMNVALUE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_TABLE_COLUMN'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_VALRULE_COLUMN'); 
- --AD_Tab. Inhabilitamos trigger para que no inserte en ad_tab_trl 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_TAB_TRG ENABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT ADCOLUMN_ADTABSORTORDER'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT ADCOLUMN_ADTABSORTYESNO'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT ADPROCESS_ADTAB'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT ADTAB_INCLUDED'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT AD_COLUMN_AD_TAB'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT AD_TABLE_TAB'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT AD_WINDOW_TAB'); 
- --AD_Window. Constraints no necesita. Triggers si. Habra que insertar a mano en la window_access!!! 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_WINDOW_TRG ENABLE'); 
- --AD_Window_Access 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_ACCESS ENABLE CONSTRAINT ADWINDOW_ADWINDOWACCESS'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_ACCESS ENABLE CONSTRAINT ADROLE_ADWINDOWACCESS'); 
- --AD_Field 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_FIELD_TRG ENABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD ENABLE CONSTRAINT ADFIELDGROUP_ADFIELD'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD ENABLE CONSTRAINT AD_COLUMN_FIELD'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD ENABLE CONSTRAINT AD_TAB_FIELD'); 
- --AD_FieldGroup no necesita. Triggers si 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_FIELDGROUP_TRG ENABLE'); 
- --AD_Reference no necesita. Triggers si 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_REFERENCE_TRG ENABLE'); 
- --AD_Ref_List 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_REF_LIST_TRG ENABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_LIST ENABLE CONSTRAINT AD_REFERENCE_REFLIST'); 
- --AD_Ref_Table 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE ENABLE CONSTRAINT ADD_TABLE_REFTABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE ENABLE CONSTRAINT AD_COLUMN_REFTABLE_DISPLAY'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE ENABLE CONSTRAINT AD_COLUMN_REFTABLE_ID'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE ENABLE CONSTRAINT AD_REFERENCE_REFTABLE'); 
- --AD_Menu 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_MENU_TRG ENABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADFORM_ADMENU'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADPROCESS_ADMENU'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADTASK_ADMENU'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADWINDOW_ADMENU'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADWORKFLOW_ADMENU'); 
- --AD_Treenode 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TREENODE ENABLE CONSTRAINT ADTREE_ADTREENODE'); 
- --AD_Element 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_ELEMENT_TRG ENABLE'); 
- --AD_Tab_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB_TRL ENABLE CONSTRAINT AD_TABTRL'); 
- --AD_Window_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_TRL ENABLE CONSTRAINT AD_WINDOWTRL'); 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_WINDOW_TRL_TRG ENABLE'); 
- --AD_Field_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD_TRL ENABLE CONSTRAINT AD_FIELDTRL'); 
- --AD_FieldGroup_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELDGROUP_TRL ENABLE CONSTRAINT ADFIELDGROUP_TRL'); 
- --AD_Ref_List_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_LIST_TRL ENABLE CONSTRAINT AD_REFLISTTRL'); 
- --AD_Element_Trl 
- EXECUTE IMMEDIATE ('ALTER TRIGGER AD_ELEMENT_TRL_TRG ENABLE'); 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_ELEMENT_TRL ENABLE CONSTRAINT ADELEMENT_ADELEMENTTRL'); 
- --AD_Menu_Trl 
- EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU_TRL ENABLE CONSTRAINT AD_MENUTRL'); 
- 
- 
- --Se ejecuta el proceso AD_UPDATE_SEQUENCE 
- --AD_UPDATE_SEQUENCE(p_baseinstalation);  --mirar 
+ SELECT MIN(AD_SEQUENCE_ID)--, MAX(AD_SEQUENCE_ID)
+ INTO v_minId--, v_maxId
+ FROM TAD_AUX.AD_SEQUENCE WHERE AD_SEQUENCE_ID BETWEEN p_sequenceIdFrom AND p_sequenceIdTo;
+ v_sequenceOffset:=v_nextNo - v_minId;
+/* UPDATE AD_SEQUENCE SET CurrentNextSys=CurrentNextSys + (v_maxId-v_minId) + INCREMENTNO
+ WHERE  Name='AD_Sequence' AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y';
+*/
+
+
+--AD_REF_TABLE doesn't need a translation because it lacks of an ID
+--Por la misma razon, tampoco necesitan traslacion las tablas de traduccion (..._TRL)
+
+--Comienzo de carga de datos.
+--Primero, inhabilitar constraints de integridad referencial (existen referencias circulares...)
+ --AD_Table. No inhabilitamos el trigger para que inserte valores en ad_sequence
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TABLE DISABLE CONSTRAINT AD_WINDOW_TABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TABLE DISABLE CONSTRAINT AD_VALRULE_TABLE');
+ --AD_Column. No tiene trigger para insert
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT ADPROCESS_ADCOLUMN');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_ELEMENT_AD_COLUMN');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_REFERENCE_COLUMNDATATYPE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_REFERENCE_COLUMNVALUE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_TABLE_COLUMN');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN DISABLE CONSTRAINT AD_VALRULE_COLUMN');
+ --AD_Tab. Inhabilitamos trigger para que no inserte en ad_tab_trl
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_TAB_TRG DISABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT ADCOLUMN_ADTABSORTORDER');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT ADCOLUMN_ADTABSORTYESNO');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT ADPROCESS_ADTAB');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT ADTAB_INCLUDED');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT AD_COLUMN_AD_TAB');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT AD_TABLE_TAB');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB DISABLE CONSTRAINT AD_WINDOW_TAB');
+ --AD_Window. Constraints no necesita. Triggers si. Habra que insertar a mano en la window_access!!!
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_WINDOW_TRG DISABLE');
+ --AD_Window_Access
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_ACCESS DISABLE CONSTRAINT ADWINDOW_ADWINDOWACCESS');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_ACCESS DISABLE CONSTRAINT ADROLE_ADWINDOWACCESS');
+ --AD_Field
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_FIELD_TRG DISABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD DISABLE CONSTRAINT ADFIELDGROUP_ADFIELD');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD DISABLE CONSTRAINT AD_COLUMN_FIELD');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD DISABLE CONSTRAINT AD_TAB_FIELD');
+ --AD_FieldGroup no necesita. Triggers si
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_FIELDGROUP_TRG DISABLE');
+ --AD_Reference no necesita. Triggers si
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_REFERENCE_TRG DISABLE');
+ --AD_Ref_List
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_REF_LIST_TRG DISABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_LIST DISABLE CONSTRAINT AD_REFERENCE_REFLIST');
+ --AD_Ref_Table
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE DISABLE CONSTRAINT ADD_TABLE_REFTABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE DISABLE CONSTRAINT AD_COLUMN_REFTABLE_DISPLAY');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE DISABLE CONSTRAINT AD_COLUMN_REFTABLE_ID');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE DISABLE CONSTRAINT AD_REFERENCE_REFTABLE');
+ --AD_Menu
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_MENU_TRG DISABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADFORM_ADMENU');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADPROCESS_ADMENU');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADTASK_ADMENU');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADWINDOW_ADMENU');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU DISABLE CONSTRAINT ADWORKFLOW_ADMENU');
+ --AD_Treenode
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TREENODE DISABLE CONSTRAINT ADTREE_ADTREENODE');
+ --AD_Element
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_ELEMENT_TRG DISABLE');
+ --AD_Val_Rule no necesita ni constraints ni triggers
+ --AD_Tab_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB_TRL DISABLE CONSTRAINT AD_TABTRL');
+ --AD_Window_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_TRL DISABLE CONSTRAINT AD_WINDOWTRL');
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_WINDOW_TRL_TRG DISABLE');
+ --AD_Field_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD_TRL DISABLE CONSTRAINT AD_FIELDTRL');
+ --AD_FieldGroup_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELDGROUP_TRL DISABLE CONSTRAINT ADFIELDGROUP_TRL');
+ --AD_Ref_List_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_LIST_TRL DISABLE CONSTRAINT AD_REFLISTTRL');
+ --AD_Element_Trl
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_ELEMENT_TRL_TRG DISABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_ELEMENT_TRL DISABLE CONSTRAINT ADELEMENT_ADELEMENTTRL');
+ --AD_Menu_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU_TRL DISABLE CONSTRAINT AD_MENUTRL');
+
+
+
+
+ --Insercion de valores, con traslacion de claves
+ --AD_Table
+ INSERT INTO AD_TABLE (AD_TABLE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
+ NAME, DESCRIPTION, HELP, TABLENAME, ISVIEW, ACCESSLEVEL, ENTITYTYPE, AD_WINDOW_ID, AD_VAL_RULE_ID,
+ LOADSEQ, ISSECURITYENABLED, ISDELETEABLE, ISHIGHVOLUME, IMPORTTABLE, ISCHANGELOG, REPLICATIONTYPE,
+ PO_WINDOW_ID, ISDEFAULTACCT)
+ SELECT AD_TABLE_ID+v_tableOffset, 0, 0, ISACTIVE, now(), 0, now(), 0,
+ NAME, DESCRIPTION, HELP, TABLENAME, ISVIEW, ACCESSLEVEL, ENTITYTYPE, CASE WHEN AD_WINDOW_ID>699999
+ THEN AD_WINDOW_ID+v_windowOffset ELSE AD_WINDOW_ID END, AD_VAL_RULE_ID+v_valruleOffset,
+ LOADSEQ, ISSECURITYENABLED, ISDELETEABLE, ISHIGHVOLUME, IMPORTTABLE, ISCHANGELOG, REPLICATIONTYPE,
+ CASE WHEN PO_WINDOW_ID>699999 THEN PO_WINDOW_ID+v_windowOffset ELSE PO_WINDOW_ID END, ISDEFAULTACCT
+ FROM TAD_AUX.AD_TABLE WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo;
+
+ --AD_Column
+ INSERT INTO AD_COLUMN (AD_COLUMN_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, UPDATED, CREATEDBY, UPDATEDBY,
+ NAME, DESCRIPTION, HELP, VERSION, ENTITYTYPE, COLUMNNAME, AD_TABLE_ID, AD_REFERENCE_ID,
+ AD_REFERENCE_VALUE_ID, AD_VAL_RULE_ID, FIELDLENGTH, DEFAULTVALUE, ISKEY, ISPARENT,
+ ISMANDATORY, ISUPDATEABLE, READONLYLOGIC, ISIDENTIFIER, SEQNO, ISTRANSLATED, ISENCRYPTED,
+ CALLOUT, VFORMAT, VALUEMIN, VALUEMAX, ISSELECTIONCOLUMN, AD_ELEMENT_ID, AD_PROCESS_ID,
+ ISSYNCDATABASE, ISSESSIONATTR, ISSECONDARYKEY)
+ SELECT AD_COLUMN_ID+v_columnOffset, 0, 0, ISACTIVE, now(), now(), 0, 0,
+ NAME, DESCRIPTION, HELP, VERSION, ENTITYTYPE, COLUMNNAME, AD_TABLE_ID+v_tableOffset,
+ CASE WHEN AD_REFERENCE_ID>699999 THEN AD_REFERENCE_ID+v_referenceOffset ELSE AD_REFERENCE_ID END,
+ CASE WHEN AD_REFERENCE_VALUE_ID>699999 THEN AD_REFERENCE_VALUE_ID+v_referenceOffset ELSE AD_REFERENCE_VALUE_ID END,
+ CASE WHEN AD_VAL_RULE_ID>699999 THEN AD_VAL_RULE_ID+v_valruleOffset ELSE AD_VAL_RULE_ID END, FIELDLENGTH, DEFAULTVALUE, ISKEY, ISPARENT,
+ ISMANDATORY, ISUPDATEABLE, READONLYLOGIC, ISIDENTIFIER, SEQNO, ISTRANSLATED, ISENCRYPTED,
+ CALLOUT, VFORMAT, VALUEMIN, VALUEMAX, ISSELECTIONCOLUMN, CASE WHEN AD_ELEMENT_ID>699999
+ THEN AD_ELEMENT_ID+v_elementOffset ELSE AD_ELEMENT_ID END, AD_PROCESS_ID+v_processOffset,
+ ISSYNCDATABASE, ISSESSIONATTR, ISSECONDARYKEY
+ FROM TAD_AUX.AD_COLUMN WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo;
+
+
+ --ad_tab
+ INSERT INTO AD_TAB (AD_TAB_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED,
+ UPDATEDBY, NAME, DESCRIPTION, HELP, AD_TABLE_ID, AD_WINDOW_ID, SEQNO, TABLEVEL, ISSINGLEROW,
+ ISINFOTAB, ISTRANSLATIONTAB, ISREADONLY, AD_COLUMN_ID, HASTREE, WHERECLAUSE, ORDERBYCLAUSE,
+ COMMITWARNING, AD_PROCESS_ID, PROCESSING, AD_IMAGE_ID, IMPORTFIELDS, AD_COLUMNSORTORDER_ID,
+ AD_COLUMNSORTYESNO_ID, ISSORTTAB, ENTITYTYPE, INCLUDED_TAB_ID, FILTERCLAUSE)
+ SELECT AD_TAB_ID+v_tabOffset, 0, 0, ISACTIVE, now(), 0, now(),
+ 0, NAME, DESCRIPTION, HELP, AD_TABLE_ID+v_tableOffset, CASE WHEN AD_WINDOW_ID>699999
+ THEN AD_WINDOW_ID+v_windowOffset ELSE AD_WINDOW_ID END, SEQNO, TABLEVEL,
+ ISSINGLEROW, ISINFOTAB, ISTRANSLATIONTAB, ISREADONLY, AD_COLUMN_ID+v_columnOffset, HASTREE, WHERECLAUSE,
+ ORDERBYCLAUSE, COMMITWARNING, AD_PROCESS_ID+v_processOffset, PROCESSING, AD_IMAGE_ID, IMPORTFIELDS,
+ AD_COLUMNSORTORDER_ID+v_columnOffset, AD_COLUMNSORTYESNO_ID+v_columnOffset, ISSORTTAB, ENTITYTYPE,
+ INCLUDED_TAB_ID+v_tabOffset, FILTERCLAUSE
+ FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo;
+
+ --ad_tab_trl
+ INSERT INTO AD_TAB_TRL (AD_TAB_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
+ CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, COMMITWARNING, ISTRANSLATED)
+ SELECT AD_TAB_ID+v_tabOffset,AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(),
+ 0, NAME, DESCRIPTION, HELP, COMMITWARNING, ISTRANSLATED
+ FROM TAD_AUX.AD_TAB_TRL WHERE AD_TAB_ID IN (
+   SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo);
+
+ --ad_window
+ INSERT INTO AD_WINDOW (AD_WINDOW_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
+ UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, WINDOWTYPE, ISSOTRX, ENTITYTYPE, PROCESSING,
+ AD_IMAGE_ID, AD_COLOR_ID, ISDEFAULT)
+ SELECT AD_WINDOW_ID+v_windowOffset, 0, 0, ISACTIVE, now(), 0, now(), 0,
+ NAME, DESCRIPTION, HELP, WINDOWTYPE, ISSOTRX, ENTITYTYPE, PROCESSING, AD_IMAGE_ID,
+ AD_COLOR_ID, ISDEFAULT
+ FROM TAD_AUX.AD_WINDOW WHERE AD_WINDOW_ID BETWEEN p_windowIdFrom AND p_windowIdTo;
+
+ --ad_window_trl
+ INSERT INTO AD_WINDOW_TRL (AD_WINDOW_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
+ CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, ISTRANSLATED)
+ SELECT AD_WINDOW_ID+v_windowOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0,
+ NAME, DESCRIPTION, HELP, ISTRANSLATED
+ FROM TAD_AUX.AD_WINDOW_TRL WHERE AD_WINDOW_ID BETWEEN p_windowIdFrom AND p_windowIdTo;
+
+ --ad_window_access
+ INSERT INTO AD_WINDOW_ACCESS (AD_WINDOW_ID, AD_ROLE_ID, AD_CLIENT_ID, AD_ORG_ID,
+ ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, ISREADWRITE)
+ SELECT AD_WINDOW_ID+v_windowOffset, AD_ROLE_ID, 0, 0, 'Y', now(), 0, now(), 0, 'Y'
+ FROM TAD_AUX.AD_WINDOW_ACCESS WHERE AD_WINDOW_ID BETWEEN p_windowIdFrom AND p_windowIdTo;
+
+ --ad_auxiliarinput no esta hecho porque no hay ninguno en produccion
+
+ --ad_field
+ INSERT INTO AD_FIELD (AD_FIELD_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED,
+ UPDATEDBY, NAME, DESCRIPTION, HELP, ISCENTRALLYMAINTAINED, AD_TAB_ID, AD_COLUMN_ID, AD_FIELDGROUP_ID,
+ ISDISPLAYED, DISPLAYLOGIC, DISPLAYLENGTH, ISREADONLY, SEQNO, SORTNO, ISSAMELINE, ISHEADING,
+ ISFIELDONLY, ISENCRYPTED, ENTITYTYPE, SHOWINRELATION)
+ SELECT AD_FIELD_ID+v_fieldOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME,
+ DESCRIPTION, HELP, ISCENTRALLYMAINTAINED, AD_TAB_ID+v_tabOffset, AD_COLUMN_ID+v_columnOffset,
+ AD_FIELDGROUP_ID+v_fieldgroupOffset, ISDISPLAYED, DISPLAYLOGIC, DISPLAYLENGTH, ISREADONLY,
+ SEQNO, SORTNO, ISSAMELINE, ISHEADING, ISFIELDONLY, ISENCRYPTED, ENTITYTYPE, SHOWINRELATION
+ FROM TAD_AUX.AD_FIELD WHERE AD_TAB_ID IN (
+   SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo);
+
+ --ad_field_trl
+ INSERT INTO AD_FIELD_TRL (AD_FIELD_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
+ CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, ISTRANSLATED)
+ SELECT AD_FIELD_ID+v_fieldOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME,
+ DESCRIPTION, HELP, ISTRANSLATED
+ FROM TAD_AUX.AD_FIELD_TRL WHERE AD_FIELD_ID IN (
+   SELECT AD_FIELD_ID FROM TAD_AUX.AD_FIELD
+   WHERE AD_TAB_ID IN (
+       SELECT AD_TAB_ID FROM TAD_AUX.AD_TAB WHERE AD_TABLE_ID BETWEEN p_tableIdFrom AND p_tableIdTo));
+
+ --ad_fieldgroup no hay en produccion
+
+ --ad_fieldgroup_trl no hay en produccion
+
+ --ad_element
+ INSERT INTO AD_ELEMENT (AD_ELEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
+ UPDATED, UPDATEDBY, COLUMNNAME, ENTITYTYPE, NAME, PRINTNAME, DESCRIPTION, HELP, PO_NAME,
+ PO_PRINTNAME, PO_DESCRIPTION, PO_HELP)
+ SELECT AD_ELEMENT_ID+v_elementOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, COLUMNNAME,
+ ENTITYTYPE, NAME, PRINTNAME, DESCRIPTION, HELP, PO_NAME, PO_PRINTNAME, PO_DESCRIPTION, PO_HELP
+ FROM TAD_AUX.AD_ELEMENT WHERE AD_ELEMENT_ID BETWEEN p_elementIdFrom AND p_elementIdTo;
+
+ --ad_element_trl
+ INSERT INTO AD_ELEMENT_TRL (AD_ELEMENT_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
+ CREATEDBY, UPDATED, UPDATEDBY, NAME, PRINTNAME, DESCRIPTION, HELP, PO_NAME, PO_PRINTNAME,
+ PO_DESCRIPTION, PO_HELP, ISTRANSLATED)
+ SELECT AD_ELEMENT_ID+v_elementOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0,
+ NAME, PRINTNAME, DESCRIPTION, HELP, PO_NAME, PO_PRINTNAME, PO_DESCRIPTION, PO_HELP, ISTRANSLATED
+ FROM TAD_AUX.AD_ELEMENT_TRL WHERE AD_ELEMENT_ID BETWEEN p_elementIdFrom AND p_elementIdTo;
+
+
+ --ad_reference
+ INSERT INTO AD_REFERENCE (AD_REFERENCE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
+ UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, VALIDATIONTYPE, VFORMAT, ENTITYTYPE)
+ SELECT AD_REFERENCE_ID+v_referenceOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME, DESCRIPTION,
+ HELP, VALIDATIONTYPE, VFORMAT, ENTITYTYPE
+ FROM TAD_AUX.AD_REFERENCE WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo;
+
+ --ad_reference_trl
+ INSERT INTO AD_REFERENCE_TRL (AD_REFERENCE_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
+ CREATED, CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, HELP, ISTRANSLATED)
+ SELECT AD_REFERENCE_ID+v_referenceOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0,
+ NAME, DESCRIPTION, HELP, ISTRANSLATED
+ FROM TAD_AUX.AD_REFERENCE_TRL WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo;
+
+ --ad_ref_table
+ INSERT INTO AD_REF_TABLE (AD_REFERENCE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
+ UPDATED, UPDATEDBY, AD_TABLE_ID, AD_KEY, AD_DISPLAY, ISVALUEDISPLAYED, WHERECLAUSE, ORDERBYCLAUSE,
+ ENTITYTYPE)
+ SELECT AD_REFERENCE_ID+v_referenceOffset, 0, 0, ISACTIVE, now(), 0, now(), 0,
+ AD_TABLE_ID+v_tableOffset, CASE WHEN AD_KEY>699999 THEN AD_KEY+v_columnOffset ELSE AD_KEY END,
+ CASE WHEN AD_DISPLAY>699999 THEN AD_DISPLAY+v_columnOffset ELSE AD_DISPLAY END,
+ ISVALUEDISPLAYED, WHERECLAUSE, ORDERBYCLAUSE, ENTITYTYPE
+ FROM TAD_AUX.AD_REF_TABLE WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo;
+
+ --ad_ref_list
+ INSERT INTO AD_REF_LIST (AD_REF_LIST_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
+ UPDATED, UPDATEDBY, VALUE, NAME, DESCRIPTION, AD_REFERENCE_ID, VALIDFROM, VALIDTO, ENTITYTYPE)
+ SELECT AD_REF_LIST_ID+v_reflistOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, VALUE, NAME,
+ DESCRIPTION, AD_REFERENCE_ID+v_referenceOffset, VALIDFROM, VALIDTO, ENTITYTYPE
+ FROM TAD_AUX.AD_REF_LIST WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo;
+
+ --ad_ref_list_trl
+ INSERT INTO AD_REF_LIST_TRL (AD_REF_LIST_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
+ CREATED, CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, ISTRANSLATED)
+ SELECT AD_REF_LIST_ID+v_reflistOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0,
+ NAME, DESCRIPTION, ISTRANSLATED
+ FROM TAD_AUX.AD_REF_LIST_TRL WHERE AD_REF_LIST_ID IN (
+   SELECT AD_REF_LIST_ID FROM TAD_AUX.AD_REF_LIST
+   WHERE AD_REFERENCE_ID BETWEEN p_referenceIdFrom AND p_referenceIdTo);
+
+
+ --ad_menu
+ INSERT INTO AD_MENU (AD_MENU_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED,
+ NAME, UPDATEDBY, DESCRIPTION, ISSUMMARY, ISSOTRX, ISREADONLY, ACTION, AD_WINDOW_ID, AD_WORKFLOW_ID,
+ AD_TASK_ID, AD_PROCESS_ID, AD_FORM_ID, AD_WORKBENCH_ID, ENTITYTYPE)
+ SELECT AD_MENU_ID+v_menuOffset, 0, 0, ISACTIVE, now(), 0, now(), NAME, UPDATEDBY, DESCRIPTION,
+ ISSUMMARY, ISSOTRX, ISREADONLY, ACTION, AD_WINDOW_ID+v_windowOffset, AD_WORKFLOW_ID+v_workflowOffset,
+ AD_TASK_ID+v_taskOffset, AD_PROCESS_ID+v_processOffset, AD_FORM_ID+v_formOffset, AD_WORKBENCH_ID,
+ ENTITYTYPE
+ FROM TAD_AUX.AD_MENU WHERE AD_MENU_ID BETWEEN p_menuIdFrom AND p_menuIdTo;
+
+ --ad_menu_trl
+ INSERT INTO AD_MENU_TRL (AD_MENU_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
+ CREATEDBY, UPDATED, UPDATEDBY, NAME, DESCRIPTION, ISTRANSLATED)
+ SELECT AD_MENU_ID+v_menuOffset, AD_LANGUAGE, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME,
+ DESCRIPTION, ISTRANSLATED
+ FROM TAD_AUX.AD_MENU_TRL WHERE AD_MENU_ID BETWEEN p_menuIdFrom AND p_menuIdTo;
+
+ --ad_treenode
+ INSERT INTO AD_TREENODE (AD_TREE_ID, NODE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
+ CREATEDBY, UPDATED, UPDATEDBY, PARENT_ID, SEQNO)
+ SELECT AD_TREE_ID, NODE_ID+v_menuOffset, 0, 0, ISACTIVE, now(), 0, now(), 0,
+ CASE WHEN PARENT_ID>699999 THEN PARENT_ID+v_menuOffset ELSE PARENT_ID END, SEQNO
+ FROM TAD_AUX.AD_TREENODE WHERE NODE_ID BETWEEN p_menuIdFrom AND p_menuIdTo;
+
+ --ad_val_rule
+ INSERT INTO AD_VAL_RULE (AD_VAL_RULE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
+ UPDATED, UPDATEDBY, NAME, DESCRIPTION, TYPE, CODE, ENTITYTYPE)
+ SELECT AD_VAL_RULE_ID+v_valruleOffset, 0, 0, ISACTIVE, now(), 0, now(), 0, NAME,
+ DESCRIPTION, TYPE, CODE, ENTITYTYPE
+ FROM TAD_AUX.AD_VAL_RULE WHERE AD_VAL_RULE_ID BETWEEN p_valruleIdFrom AND p_valruleIdTo;
+
+
+
+--  por si falla lo del nulo!!!!
+-- (CASE WHEN INCLUDED_TAB_ID IS  NULL THEN  NULL ELSE  INCLUDED_TAB_ID+v_tabOffset END)
+
+
+
+ --AD_Table. No inhabilitamos el trigger para que inserte valores en ad_sequence
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TABLE ENABLE CONSTRAINT AD_WINDOW_TABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TABLE ENABLE CONSTRAINT AD_VALRULE_TABLE');
+ --AD_Column. No tiene trigger para insert
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT ADPROCESS_ADCOLUMN');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_ELEMENT_AD_COLUMN');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_REFERENCE_COLUMNDATATYPE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_REFERENCE_COLUMNVALUE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_TABLE_COLUMN');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_COLUMN ENABLE CONSTRAINT AD_VALRULE_COLUMN');
+ --AD_Tab. Inhabilitamos trigger para que no inserte en ad_tab_trl
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_TAB_TRG ENABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT ADCOLUMN_ADTABSORTORDER');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT ADCOLUMN_ADTABSORTYESNO');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT ADPROCESS_ADTAB');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT ADTAB_INCLUDED');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT AD_COLUMN_AD_TAB');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT AD_TABLE_TAB');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB ENABLE CONSTRAINT AD_WINDOW_TAB');
+ --AD_Window. Constraints no necesita. Triggers si. Habra que insertar a mano en la window_access!!!
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_WINDOW_TRG ENABLE');
+ --AD_Window_Access
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_ACCESS ENABLE CONSTRAINT ADWINDOW_ADWINDOWACCESS');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_ACCESS ENABLE CONSTRAINT ADROLE_ADWINDOWACCESS');
+ --AD_Field
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_FIELD_TRG ENABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD ENABLE CONSTRAINT ADFIELDGROUP_ADFIELD');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD ENABLE CONSTRAINT AD_COLUMN_FIELD');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD ENABLE CONSTRAINT AD_TAB_FIELD');
+ --AD_FieldGroup no necesita. Triggers si
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_FIELDGROUP_TRG ENABLE');
+ --AD_Reference no necesita. Triggers si
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_REFERENCE_TRG ENABLE');
+ --AD_Ref_List
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_REF_LIST_TRG ENABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_LIST ENABLE CONSTRAINT AD_REFERENCE_REFLIST');
+ --AD_Ref_Table
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE ENABLE CONSTRAINT ADD_TABLE_REFTABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE ENABLE CONSTRAINT AD_COLUMN_REFTABLE_DISPLAY');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE ENABLE CONSTRAINT AD_COLUMN_REFTABLE_ID');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_TABLE ENABLE CONSTRAINT AD_REFERENCE_REFTABLE');
+ --AD_Menu
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_MENU_TRG ENABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADFORM_ADMENU');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADPROCESS_ADMENU');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADTASK_ADMENU');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADWINDOW_ADMENU');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU ENABLE CONSTRAINT ADWORKFLOW_ADMENU');
+ --AD_Treenode
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TREENODE ENABLE CONSTRAINT ADTREE_ADTREENODE');
+ --AD_Element
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_ELEMENT_TRG ENABLE');
+ --AD_Tab_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_TAB_TRL ENABLE CONSTRAINT AD_TABTRL');
+ --AD_Window_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_WINDOW_TRL ENABLE CONSTRAINT AD_WINDOWTRL');
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_WINDOW_TRL_TRG ENABLE');
+ --AD_Field_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELD_TRL ENABLE CONSTRAINT AD_FIELDTRL');
+ --AD_FieldGroup_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_FIELDGROUP_TRL ENABLE CONSTRAINT ADFIELDGROUP_TRL');
+ --AD_Ref_List_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_REF_LIST_TRL ENABLE CONSTRAINT AD_REFLISTTRL');
+ --AD_Element_Trl
+ EXECUTE IMMEDIATE ('ALTER TRIGGER AD_ELEMENT_TRL_TRG ENABLE');
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_ELEMENT_TRL ENABLE CONSTRAINT ADELEMENT_ADELEMENTTRL');
+ --AD_Menu_Trl
+ EXECUTE IMMEDIATE ('ALTER TABLE AD_MENU_TRL ENABLE CONSTRAINT AD_MENUTRL');
+
+
+ --Se ejecuta el proceso AD_UPDATE_SEQUENCE
+ --AD_UPDATE_SEQUENCE(p_baseinstalation);  --mirar
 END AD_APPLICATION_IMPORT
 ]]></body>
     </function>
--- a/database/model/functions/AD_DELETE_CLIENT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/AD_DELETE_CLIENT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -7,114 +7,114 @@
       <parameter name="p_ad_client_id" type="NUMERIC" mode="in">
         <default/>
       </parameter>
-      <body><![CDATA[/************************************************************************* 
-* The contents of this file are subject to the Openbravo  Public  License 
-* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License 
-* Version 1.1  with a permitted attribution clause; you may not  use this 
-* file except in compliance with the License. You  may  obtain  a copy of 
-* the License at http://www.openbravo.com/legal/license.html 
-* Software distributed under the License  is  distributed  on  an "AS IS" 
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
-* License for the specific  language  governing  rights  and  limitations 
-* under the License. 
-* The Original Code is Openbravo ERP. 
-* The Initial Developer of the Original Code is Openbravo SL 
-* All portions are Copyright (C) 2001-2008 Openbravo SL 
-* All Rights Reserved. 
-* Contributor(s):  ______________________________________. 
-************************************************************************/ 
-  /************************************************************************* 
-  * Title: Delete client 
-  * Description: 
-  *   Delete data (for every table in TAD schema) from the client selected 
-  ************************************************************************/ 
-  -- Logistice 
-  v_ResultStr VARCHAR2(4000):=''; 
-  v_Message VARCHAR2(4000):=''; 
-  v_Result NUMBER:=1; -- 0=failure 
-  -- Parameter 
-  TYPE RECORD IS REF CURSOR; 
-    Cur_Parameter RECORD; 
-    -- Parameter Variables 
-    v_AD_Client_ID NUMBER(10) ; 
-    p_NewClientValue VARCHAR2(80) ; 
-    -- 
-    Cur_Triggers RECORD; 
-    Cur_Constraints RECORD; 
-    Cur_ConstraintsEnable RECORD; 
-    Cur_Tables RECORD; 
-    Cur_Script RECORD; 
-    -- 
-    v_seqNo NUMBER:=0; 
-    v_NextNo NUMBER(10):=1000000; 
-    v_count NUMBER:=0; 
-    v_ID_Column VARCHAR2(30) ; 
-    v_minID NUMBER(10) ; 
-    v_maxID NUMBER(10) ; 
-    v_nextID NUMBER(10) ; 
-    v_strTemp VARCHAR2(4000):=''; 
-    v_strSql VARCHAR2(4000):=''; 
-    v_tableActual VARCHAR2(30) ; 
-  BEGIN 
-    IF(p_PInstance_ID IS NOT NULL) THEN 
-      --  Update AD_PInstance 
-      DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ; 
-      v_ResultStr:='PInstanceNotFound'; 
-      AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ; 
-      -- Get Parameters 
-      v_ResultStr:='ReadingParameters'; 
+      <body><![CDATA[/*************************************************************************
+* The contents of this file are subject to the Openbravo  Public  License
+* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+* Version 1.1  with a permitted attribution clause; you may not  use this
+* file except in compliance with the License. You  may  obtain  a copy of
+* the License at http://www.openbravo.com/legal/license.html
+* Software distributed under the License  is  distributed  on  an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific  language  governing  rights  and  limitations
+* under the License.
+* The Original Code is Openbravo ERP.
+* The Initial Developer of the Original Code is Openbravo SL
+* All portions are Copyright (C) 2001-2008 Openbravo SL
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************/
+  /*************************************************************************
+  * Title: Delete client
+  * Description:
+  *   Delete data (for every table in TAD schema) from the client selected
+  ************************************************************************/
+  -- Logistice
+  v_ResultStr VARCHAR2(4000):='';
+  v_Message VARCHAR2(4000):='';
+  v_Result NUMBER:=1; -- 0=failure
+  -- Parameter
+  TYPE RECORD IS REF CURSOR;
+    Cur_Parameter RECORD;
+    -- Parameter Variables
+    v_AD_Client_ID NUMBER(10) ;
+    p_NewClientValue VARCHAR2(80) ;
+    --
+    Cur_Triggers RECORD;
+    Cur_Constraints RECORD;
+    Cur_ConstraintsEnable RECORD;
+    Cur_Tables RECORD;
+    Cur_Script RECORD;
+    --
+    v_seqNo NUMBER:=0;
+    v_NextNo NUMBER(10):=1000000;
+    v_count NUMBER:=0;
+    v_ID_Column VARCHAR2(30) ;
+    v_minID NUMBER(10) ;
+    v_maxID NUMBER(10) ;
+    v_nextID NUMBER(10) ;
+    v_strTemp VARCHAR2(4000):='';
+    v_strSql VARCHAR2(4000):='';
+    v_tableActual VARCHAR2(30) ;
+  BEGIN
+    IF(p_PInstance_ID IS NOT NULL) THEN
+      --  Update AD_PInstance
+      DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
+      v_ResultStr:='PInstanceNotFound';
+      AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
+      -- Get Parameters
+      v_ResultStr:='ReadingParameters';
 
-      FOR Cur_Parameter IN 
-        (SELECT p.ParameterName, p.P_String, p.P_Number 
-        FROM AD_PInstance i 
-        LEFT JOIN AD_PInstance_Para p 
-          ON i.AD_PInstance_ID=p.AD_PInstance_ID 
-        WHERE i.AD_PInstance_ID=p_PInstance_ID 
-        ORDER BY p.SeqNo 
-        ) 
-      LOOP 
-        IF(Cur_Parameter.ParameterName='AD_Client_ID') THEN 
-          v_AD_Client_ID:=Cur_Parameter.P_Number; 
-          DBMS_OUTPUT.PUT_LINE('  AD_Client_ID=' || v_AD_Client_ID) ; 
-        ELSE 
-          DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ; 
-        END IF; 
-      END LOOP; -- Get Parameter 
-    ELSE 
-      v_AD_Client_ID:=p_AD_Client_ID; 
-      --v_Message := '@ADPinstanceIsNull@'; 
-      --GOTO END_PROCESS; 
-    END IF; 
-  BEGIN --BODY 
+      FOR Cur_Parameter IN
+        (SELECT p.ParameterName, p.P_String, p.P_Number
+        FROM AD_PInstance i
+        LEFT JOIN AD_PInstance_Para p
+          ON i.AD_PInstance_ID=p.AD_PInstance_ID
+        WHERE i.AD_PInstance_ID=p_PInstance_ID
+        ORDER BY p.SeqNo
+        )
+      LOOP
+        IF(Cur_Parameter.ParameterName='AD_Client_ID') THEN
+          v_AD_Client_ID:=Cur_Parameter.P_Number;
+          DBMS_OUTPUT.PUT_LINE('  AD_Client_ID=' || v_AD_Client_ID) ;
+        ELSE
+          DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ;
+        END IF;
+      END LOOP; -- Get Parameter
+    ELSE
+      v_AD_Client_ID:=p_AD_Client_ID;
+      --v_Message := '@ADPinstanceIsNull@';
+      --GOTO END_PROCESS;
+    END IF;
+  BEGIN --BODY
     IF (v_AD_Client_ID = 0) THEN
       RAISE_APPLICATION_ERROR(-20000, '@DeletingSystemClient@') ;
     END IF;
-    
-    DELETE FROM AD_SCRIPT_SQL; 
+
+    DELETE FROM AD_SCRIPT_SQL;
     v_ResultStr := 'Disabling  triggers';
     v_seqNo := ad_script_disable_triggers(v_seqNo);
-    v_ResultStr:='Disabling constraints'; 
+    v_ResultStr:='Disabling constraints';
     v_seqNo := ad_script_disable_constraints(v_seqNo);
-    AD_Sequence_Next('AD_Client', 1000000, v_NextNo) ; 
-    FOR Cur_Tables IN 
-      (SELECT AD_Table_ID, UPPER(TableName) AS NAME 
-    FROM AD_Table 
-    WHERE IsView='N'  AND UPPER(TableName)<>'AD_CLIENT'  AND EXISTS 
-      (SELECT 1 
-      FROM AD_Column 
-      WHERE AD_Table_ID=AD_Table.AD_Table_ID  AND UPPER(ColumnName)='AD_CLIENT_ID' 
-      ) 
-    ORDER BY TableName) 
-    LOOP 
-      v_seqNo:=v_seqNo + 1; 
-      INSERT 
-      INTO AD_SCRIPT_SQL VALUES 
-        (v_seqNo, 'DELETE FROM '||Cur_Tables.NAME||' WHERE AD_Client_ID = '||v_AD_Client_ID) ; 
-    END LOOP; 
-    v_seqNo:=v_seqNo + 1; 
-    INSERT 
-    INTO AD_SCRIPT_SQL VALUES 
-      (v_seqNo, 'DELETE FROM AD_Client WHERE AD_Client_ID = '||v_AD_Client_ID) ; 
+    AD_Sequence_Next('AD_Client', 1000000, v_NextNo) ;
+    FOR Cur_Tables IN
+      (SELECT AD_Table_ID, UPPER(TableName) AS NAME
+    FROM AD_Table
+    WHERE IsView='N'  AND UPPER(TableName)<>'AD_CLIENT'  AND EXISTS
+      (SELECT 1
+      FROM AD_Column
+      WHERE AD_Table_ID=AD_Table.AD_Table_ID  AND UPPER(ColumnName)='AD_CLIENT_ID'
+      )
+    ORDER BY TableName)
+    LOOP
+      v_seqNo:=v_seqNo + 1;
+      INSERT
+      INTO AD_SCRIPT_SQL VALUES
+        (v_seqNo, 'DELETE FROM '||Cur_Tables.NAME||' WHERE AD_Client_ID = '||v_AD_Client_ID) ;
+    END LOOP;
+    v_seqNo:=v_seqNo + 1;
+    INSERT
+    INTO AD_SCRIPT_SQL VALUES
+      (v_seqNo, 'DELETE FROM AD_Client WHERE AD_Client_ID = '||v_AD_Client_ID) ;
 -- Deal with users that have defaults set to the deleted client
  v_seqNo := v_seqNo + 1;
  INSERT INTO AD_SCRIPT_SQL VALUES (v_seqNo, 'UPDATE AD_USER SET DEFAULT_AD_CLIENT_ID=null where DEFAULT_AD_CLIENT_ID NOT IN (SELECT AD_Client_ID from AD_Client)');
@@ -129,13 +129,13 @@
  INSERT INTO AD_SCRIPT_SQL VALUES (v_seqNo, 'UPDATE AD_USER SET DEFAULT_AD_CLIENT_ID=0, DEFAULT_AD_ORG_ID=0, DEFAULT_AD_ROLE_ID=0 where AD_USER_ID=100 AND DEFAULT_AD_CLIENT_ID is null and DEFAULT_AD_ORG_ID is null and DEFAULT_AD_ROLE_ID is null');
 
 
-    v_ResultStr:='Enabling  constraints'; 
+    v_ResultStr:='Enabling  constraints';
     v_seqNo := ad_script_enable_constraints(v_seqNo);
     v_ResultStr := 'Enabling  triggers';
     v_seqNo := ad_script_enable_triggers(v_seqNo);
-    -- Update sequence values 
-    v_ResultStr:='Updating sequences'; 
-    AD_UPDATE_SEQUENCE_GENERATE() ; 
+    -- Update sequence values
+    v_ResultStr:='Updating sequences';
+    AD_UPDATE_SEQUENCE_GENERATE() ;
     v_ResultStr:='Executing';
     v_ResultStr := ad_script_execute(v_ResultStr);
 
--- a/database/model/functions/AD_DELETE_CLIENT0.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/AD_DELETE_CLIENT0.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -4,29 +4,29 @@
       <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
         <default/>
       </parameter>
-      <body><![CDATA[/************************************************************************* 
- * The contents of this file are subject to the Openbravo  Public  License 
- * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License 
- * Version 1.1  with a permitted attribution clause; you may not  use this 
- * file except in compliance with the License. You  may  obtain  a copy of 
- * the License at http://www.openbravo.com/legal/license.html 
- * Software distributed under the License  is  distributed  on  an "AS IS" 
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
- * License for the specific  language  governing  rights  and  limitations 
- * under the License. 
- * The Original Code is Openbravo ERP. 
- * The Initial Developer of the Original Code is Openbravo SL 
- * All portions are Copyright (C) 2001-2006 Openbravo SL 
- * All Rights Reserved. 
- * Contributor(s):  ______________________________________. 
- ************************************************************************/ 
-/************************************************************************* 
- * Title: Delete client0 
- * Description: 
- *   Delete data (for every table in TAD schema) from the instance selected 
- ************************************************************************/ 
-BEGIN 
- AD_DELETE_CLIENT(p_PInstance_ID, NULL); 
+      <body><![CDATA[/*************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SL
+ * All portions are Copyright (C) 2001-2006 Openbravo SL
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************/
+/*************************************************************************
+ * Title: Delete client0
+ * Description:
+ *   Delete data (for every table in TAD schema) from the instance selected
+ ************************************************************************/
+BEGIN
+ AD_DELETE_CLIENT(p_PInstance_ID, NULL);
 END AD_DELETE_CLIENT0
 ]]></body>
     </function>
--- a/database/model/functions/AD_UPDATE_ACCESS.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/AD_UPDATE_ACCESS.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -16,12 +16,12 @@
 * All portions are Copyright (C) 2007 Openbravo SL
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
-************************************************************************/   
+************************************************************************/
 BEGIN
 --AD_FORM_ACCESS
   DELETE FROM AD_FORM_ACCESS
   WHERE AD_ROLE_ID IN (SELECT AD_ROLE_ID FROM AD_ROLE WHERE ISMANUAL='N');
-  
+
   INSERT INTO AD_Form_Access
     (
       AD_Form_ID, AD_Role_ID, AD_Client_ID,
@@ -46,8 +46,8 @@
   WHERE AD_ROLE_ID IN (SELECT AD_ROLE_ID FROM AD_ROLE WHERE ISMANUAL='N');
 
   INSERT INTO AD_Process_Access
-    (AD_Process_ID, AD_Role_ID, AD_Client_ID, 
-     AD_Org_ID, IsActive, Created, 
+    (AD_Process_ID, AD_Role_ID, AD_Client_ID,
+     AD_Org_ID, IsActive, Created,
      CreatedBy, Updated, UpdatedBy, IsReadWrite)
   SELECT AD_PROCESS.AD_PROCESS_ID, AD_ROLE.AD_ROLE_ID, AD_ROLE.AD_CLIENT_ID,
     AD_ROLE.AD_ORG_ID, 'Y', now(),
@@ -61,7 +61,7 @@
       OR
       (AD_ROLE.USERLEVEL = '  O' AND AD_PROCESS.ACCESSLEVEL IN ('3','1','7'))
     );
-     
+
 --AD_ROLE_ORGACCESS
   INSERT INTO AD_Role_OrgAccess
     (
@@ -84,8 +84,8 @@
   WHERE AD_ROLE_ID IN (SELECT AD_ROLE_ID FROM AD_ROLE WHERE ISMANUAL='N');
 
   INSERT INTO AD_TASK_Access
-    (AD_TASK_ID, AD_Role_ID, AD_Client_ID, 
-     AD_Org_ID, IsActive, Created, 
+    (AD_TASK_ID, AD_Role_ID, AD_Client_ID,
+     AD_Org_ID, IsActive, Created,
      CreatedBy, Updated, UpdatedBy, IsReadWrite)
   SELECT AD_TASK.AD_TASK_ID, AD_ROLE.AD_ROLE_ID, AD_ROLE.AD_CLIENT_ID,
     AD_ROLE.AD_ORG_ID, 'Y', now(),
--- a/database/model/functions/AD_UPDATE_SEQUENCE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/AD_UPDATE_SEQUENCE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -22,14 +22,14 @@
    Cur_Tables RECORD;
    v_NextNo NUMBER;
    v_Aux NUMBER;
-   v_StartWith VARCHAR(10) ; 
-   v_StartWithSys VARCHAR(10) ; 
+   v_StartWith VARCHAR(10) ;
+   v_StartWithSys VARCHAR(10) ;
  BEGIN
    select count(*)
     into v_aux
       from ad_sequence
     where name='AD_Sequence';
-    
+
     if v_Aux=0 then
       INSERT INTO AD_Sequence
         (AD_Sequence_ID, AD_Client_ID, AD_Org_ID,
@@ -43,50 +43,50 @@
         'AD_Sequence', 'AD_Sequence',
         'Y', 1000000, 1, 2, 0,
         'N', 'Y', 'N');
-     
+
     end if;
-    
+
     --Update sequence for ad_update_sequence table
-    SELECT TAD_LEVEL INTO v_StartWithSys  FROM AD_SYSTEM  WHERE AD_SYSTEM_ID=0; 
-    v_StartWith:=TO_CHAR(TO_NUMBER(v_StartWithSys) +1) || '00000'; 
-    v_StartWithSys:=v_StartWithSys || '00000'; 
-    UPDATE AD_SEQUENCE 
-      SET CURRENTNEXT=(SELECT AD_SEQUENCE.INCREMENTNO + 
-                                   (CASE SIGN(COALESCE((SELECT MAX(t.AD_Sequence_ID) 
-                                                          FROM AD_Sequence t 
+    SELECT TAD_LEVEL INTO v_StartWithSys  FROM AD_SYSTEM  WHERE AD_SYSTEM_ID=0;
+    v_StartWith:=TO_CHAR(TO_NUMBER(v_StartWithSys) +1) || '00000';
+    v_StartWithSys:=v_StartWithSys || '00000';
+    UPDATE AD_SEQUENCE
+      SET CURRENTNEXT=(SELECT AD_SEQUENCE.INCREMENTNO +
+                                   (CASE SIGN(COALESCE((SELECT MAX(t.AD_Sequence_ID)
+                                                          FROM AD_Sequence t
                                                           WHERE t.AD_Sequence_ID<TO_NUMBER(v_StartWith)),0)-TO_NUMBER(v_StartWithSys))
-                                    WHEN  -1  THEN TO_NUMBER(v_StartWithSys)-AD_SEQUENCE.INCREMENTNO 
-                                    ELSE (SELECT MAX(t.AD_Sequence_ID) 
-                                            FROM AD_Sequence t 
-                                           WHERE t.AD_Sequence_ID<TO_NUMBER(v_StartWith)) 
-                                     END) AS SEQUENCE 
-                             FROM AD_SEQUENCE 
+                                    WHEN  -1  THEN TO_NUMBER(v_StartWithSys)-AD_SEQUENCE.INCREMENTNO
+                                    ELSE (SELECT MAX(t.AD_Sequence_ID)
+                                            FROM AD_Sequence t
+                                           WHERE t.AD_Sequence_ID<TO_NUMBER(v_StartWith))
+                                     END) AS SEQUENCE
+                             FROM AD_SEQUENCE
                             WHERE UPPER(NAME) = 'AD_SEQUENCE')
      WHERE UPPER(NAME) = 'AD_SEQUENCE';
-     
-     UPDATE AD_SEQUENCE 
-        SET CURRENTNEXTSYS=(SELECT AD_SEQUENCE.INCREMENTNO + 
-                                  COALESCE((SELECT MAX(t.AD_SEQUENCE_ID) 
-                                              FROM AD_SEQUENCE t 
+
+     UPDATE AD_SEQUENCE
+        SET CURRENTNEXTSYS=(SELECT AD_SEQUENCE.INCREMENTNO +
+                                  COALESCE((SELECT MAX(t.AD_SEQUENCE_ID)
+                                              FROM AD_SEQUENCE t
                                              WHERE t.AD_SEQUENCE_ID<TO_NUMBER(v_StartWith)),(TO_NUMBER(v_StartWithSys)-AD_SEQUENCE.INCREMENTNO))
-                              FROM AD_SEQUENCE 
+                              FROM AD_SEQUENCE
                              WHERE UPPER(NAME) = 'AD_SEQUENCE')
-       WHERE UPPER(NAME) = 'AD_SEQUENCE'; 
-       
-       
+       WHERE UPPER(NAME) = 'AD_SEQUENCE';
+
+
      --Check for fac_acct_group sequence
      select count(*)
     into v_aux
       from ad_sequence
     where name='Fact_Acct_Group';
-    
+
     if v_Aux=0 then
       AD_Sequence_Next('AD_Sequence', 0, v_NextNo);
       INSERT INTO AD_Sequence
         (AD_Sequence_ID, AD_Client_ID, AD_Org_ID,
         IsActive, Created, CreatedBy, Updated, UpdatedBy,
         Name, Description,
-        IsAutoSequence, IncrementNo, StartNo,  
+        IsAutoSequence, IncrementNo, StartNo,
         CurrentNextSys, CurrentNext,
         IsAudited, IsTableID, StartNewYear)
      VALUES
@@ -94,26 +94,26 @@
         'Y', now(), 0, now(), 0,
         'Fact_Acct_Group', 'Fact_Acct_Group',
         'Y', 1, 1000000,
-        (SELECT AD_SEQUENCE.INCREMENTNO + 
-                COALESCE((SELECT MAX(t.Fact_Acct_Group_id) 
-                            FROM FACT_ACCT t 
+        (SELECT AD_SEQUENCE.INCREMENTNO +
+                COALESCE((SELECT MAX(t.Fact_Acct_Group_id)
+                            FROM FACT_ACCT t
                            WHERE t.Fact_Acct_Group_id< TO_NUMBER(v_StartWith)),(TO_NUMBER(v_StartWithSys)-AD_SEQUENCE.INCREMENTNO))
-            FROM AD_SEQUENCE 
-           WHERE UPPER(NAME) = 'AD_SEQUENCE'), 
-        (SELECT AD_SEQUENCE.INCREMENTNO + 
-               (CASE SIGN(COALESCE((SELECT MAX(t.Fact_Acct_Group_id) 
-                                      FROM fact_acct t 
+            FROM AD_SEQUENCE
+           WHERE UPPER(NAME) = 'AD_SEQUENCE'),
+        (SELECT AD_SEQUENCE.INCREMENTNO +
+               (CASE SIGN(COALESCE((SELECT MAX(t.Fact_Acct_Group_id)
+                                      FROM fact_acct t
                                       WHERE t.Fact_Acct_Group_id<TO_NUMBER(v_StartWith)),0)-TO_NUMBER(v_StartWithSys))
-                WHEN  -1  THEN TO_NUMBER(v_StartWithSys)-AD_SEQUENCE.INCREMENTNO 
-                ELSE (SELECT MAX(t.Fact_Acct_Group_id) 
+                WHEN  -1  THEN TO_NUMBER(v_StartWithSys)-AD_SEQUENCE.INCREMENTNO
+                ELSE (SELECT MAX(t.Fact_Acct_Group_id)
                         FROM fact_acct t
                        WHERE t.Fact_Acct_Group_id< TO_NUMBER(v_StartWith))
-                 END) AS SEQUENCE 
-         FROM AD_SEQUENCE 
+                 END) AS SEQUENCE
+         FROM AD_SEQUENCE
         WHERE UPPER(NAME) = 'AD_SEQUENCE'),
         'N', 'Y', 'N');
     end if;
-       
+
      FOR Cur_Tables IN (
      SELECT AD_TABLE_ID, TABLENAME
      FROM AD_TABLE
--- a/database/model/functions/AD_UPDATE_SEQUENCE_GENERATE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/AD_UPDATE_SEQUENCE_GENERATE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,82 +1,82 @@
 <?xml version="1.0"?>
   <database name="FUNCTION AD_UPDATE_SEQUENCE_GENERATE">
     <function name="AD_UPDATE_SEQUENCE_GENERATE" type="NULL">
-      <body><![CDATA[/************************************************************************* 
-* The contents of this file are subject to the Openbravo  Public  License 
-* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License 
-* Version 1.1  with a permitted attribution clause; you may not  use this 
-* file except in compliance with the License. You  may  obtain  a copy of 
-* the License at http://www.openbravo.com/legal/license.html 
-* Software distributed under the License  is  distributed  on  an "AS IS" 
-* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
-* License for the specific  language  governing  rights  and  limitations 
-* under the License. 
-* The Original Code is Openbravo ERP. 
-* The Initial Developer of the Original Code is Openbravo SL 
-* All portions are Copyright (C) 2001-2006 Openbravo SL 
-* All Rights Reserved. 
-* Contributor(s):  ______________________________________. 
-************************************************************************/ 
-  v_StartWith VARCHAR(10) ; 
-  v_StartWithSys VARCHAR(10) ; 
-  TYPE RECORD IS REF CURSOR; 
-    Cur_Tables RECORD; 
-  BEGIN 
-    SELECT TAD_LEVEL INTO v_StartWithSys  FROM AD_SYSTEM  WHERE AD_SYSTEM_ID=0; 
-    v_StartWith:=TO_CHAR(TO_NUMBER(v_StartWithSys) +1) || '00000'; 
-    v_StartWithSys:=v_StartWithSys || '00000'; 
-    FOR Cur_Tables IN 
-      (SELECT C.COLUMNNAME, 
-        UPPER(T.TABLENAME) AS NAME 
-      FROM AD_COLUMN C, 
-        AD_TABLE T 
-      WHERE C.AD_TABLE_ID=T.AD_TABLE_ID 
-        AND UPPER(C.COLUMNNAME)=UPPER(T.TABLENAME) || '_ID' 
-      ORDER BY T.TABLENAME 
-      ) 
-    LOOP 
-      INSERT 
-      INTO AD_SCRIPT_SQL VALUES 
-        ( 
-          (SELECT COALESCE(MAX(SEQNO), 0) +1 
-          FROM AD_SCRIPT_SQL 
-          ) 
-          , 
-           'UPDATE AD_SEQUENCE SET CURRENTNEXT=(SELECT AD_SEQUENCE.INCREMENTNO + ' ||  'COALESCE((SELECT MAX(t.' || Cur_Tables.NAME || '_ID) FROM ' || Cur_Tables.NAME || 
-           ' t WHERE t.' || Cur_Tables.NAME || '_ID>=AD_SEQUENCE.STARTNO),' ||  'AD_SEQUENCE.STARTNO-AD_SEQUENCE.INCREMENTNO) AS SEQUENCE FROM AD_SEQUENCE WHERE UPPER(NAME) = '||''''||Cur_Tables.NAME||''''|| 
-           ') WHERE UPPER(NAME) = '||''''||Cur_Tables.NAME||'''' 
-        ) 
-        ; 
-      IF(UPPER(Cur_Tables.NAME) LIKE 'AD_%') THEN 
-        INSERT 
-        INTO AD_SCRIPT_SQL VALUES 
-          ( 
-            (SELECT COALESCE(MAX(SEQNO), 0) +1 
-            FROM AD_SCRIPT_SQL 
-            ) 
-            , 
-             'UPDATE AD_SEQUENCE SET CURRENTNEXTSYS=('|| 
-       ' SELECT AD_SEQUENCE.INCREMENTNO + ( CASE SIGN(COALESCE((SELECT MAX(t.' || Cur_Tables.NAME ||'_ID) FROM '||Cur_Tables.NAME||' t ' || 
-             ' WHERE t.' || Cur_Tables.NAME || '_ID<' || v_StartWith ||'),0)-' || v_StartWithSys || ') WHEN  -1  THEN '||v_StartWithSys || '-AD_SEQUENCE.INCREMENTNO ELSE ' || '(SELECT MAX(t.' || Cur_Tables.NAME || 
-             '_ID) FROM ' ||Cur_Tables.NAME||  ' t WHERE t.' ||Cur_Tables.NAME ||'_ID<' || v_StartWith || ') END) AS SEQUENCE '||  ' FROM AD_SEQUENCE '||  ' WHERE UPPER(NAME) = ' || '''' || Cur_Tables.NAME || ''''||') '|| 
-             ' WHERE UPPER(NAME) = ' ||''''|| Cur_Tables.NAME || '''' 
-          ) 
-          ; 
-      ELSE 
-        INSERT 
-        INTO AD_SCRIPT_SQL VALUES 
-          ( 
-            (SELECT COALESCE(MAX(SEQNO), 0) +1 
-            FROM AD_SCRIPT_SQL 
-            ) 
-            , 
-             'UPDATE AD_SEQUENCE SET CURRENTNEXTSYS=(' ||  ' SELECT AD_SEQUENCE.INCREMENTNO + COALESCE((SELECT MAX(t.' || Cur_Tables.NAME || 
-             '_ID) FROM ' || Cur_Tables.NAME ||' t WHERE t.' || Cur_Tables.NAME ||'_ID<' || v_StartWith ||'),(' || v_StartWithSys || '-AD_SEQUENCE.INCREMENTNO))' || 
-             ' FROM AD_SEQUENCE WHERE UPPER(NAME) = ' || '''' || Cur_Tables.NAME || ''''||')' ||  ' WHERE UPPER(NAME) = ' ||''''|| Cur_Tables.NAME || '''' 
-          ) 
-          ; 
-      END IF; 
-    END LOOP; 
+      <body><![CDATA[/*************************************************************************
+* The contents of this file are subject to the Openbravo  Public  License
+* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+* Version 1.1  with a permitted attribution clause; you may not  use this
+* file except in compliance with the License. You  may  obtain  a copy of
+* the License at http://www.openbravo.com/legal/license.html
+* Software distributed under the License  is  distributed  on  an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific  language  governing  rights  and  limitations
+* under the License.
+* The Original Code is Openbravo ERP.
+* The Initial Developer of the Original Code is Openbravo SL
+* All portions are Copyright (C) 2001-2006 Openbravo SL
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************/
+  v_StartWith VARCHAR(10) ;
+  v_StartWithSys VARCHAR(10) ;
+  TYPE RECORD IS REF CURSOR;
+    Cur_Tables RECORD;
+  BEGIN
+    SELECT TAD_LEVEL INTO v_StartWithSys  FROM AD_SYSTEM  WHERE AD_SYSTEM_ID=0;
+    v_StartWith:=TO_CHAR(TO_NUMBER(v_StartWithSys) +1) || '00000';
+    v_StartWithSys:=v_StartWithSys || '00000';
+    FOR Cur_Tables IN
+      (SELECT C.COLUMNNAME,
+        UPPER(T.TABLENAME) AS NAME
+      FROM AD_COLUMN C,
+        AD_TABLE T
+      WHERE C.AD_TABLE_ID=T.AD_TABLE_ID
+        AND UPPER(C.COLUMNNAME)=UPPER(T.TABLENAME) || '_ID'
+      ORDER BY T.TABLENAME
+      )
+    LOOP
+      INSERT
+      INTO AD_SCRIPT_SQL VALUES
+        (
+          (SELECT COALESCE(MAX(SEQNO), 0) +1
+          FROM AD_SCRIPT_SQL
+          )
+          ,
+           'UPDATE AD_SEQUENCE SET CURRENTNEXT=(SELECT AD_SEQUENCE.INCREMENTNO + ' ||  'COALESCE((SELECT MAX(t.' || Cur_Tables.NAME || '_ID) FROM ' || Cur_Tables.NAME ||
+           ' t WHERE t.' || Cur_Tables.NAME || '_ID>=AD_SEQUENCE.STARTNO),' ||  'AD_SEQUENCE.STARTNO-AD_SEQUENCE.INCREMENTNO) AS SEQUENCE FROM AD_SEQUENCE WHERE UPPER(NAME) = '||''''||Cur_Tables.NAME||''''||
+           ') WHERE UPPER(NAME) = '||''''||Cur_Tables.NAME||''''
+        )
+        ;
+      IF(UPPER(Cur_Tables.NAME) LIKE 'AD_%') THEN
+        INSERT
+        INTO AD_SCRIPT_SQL VALUES
+          (
+            (SELECT COALESCE(MAX(SEQNO), 0) +1
+            FROM AD_SCRIPT_SQL
+            )
+            ,
+             'UPDATE AD_SEQUENCE SET CURRENTNEXTSYS=('||
+       ' SELECT AD_SEQUENCE.INCREMENTNO + ( CASE SIGN(COALESCE((SELECT MAX(t.' || Cur_Tables.NAME ||'_ID) FROM '||Cur_Tables.NAME||' t ' ||
+             ' WHERE t.' || Cur_Tables.NAME || '_ID<' || v_StartWith ||'),0)-' || v_StartWithSys || ') WHEN  -1  THEN '||v_StartWithSys || '-AD_SEQUENCE.INCREMENTNO ELSE ' || '(SELECT MAX(t.' || Cur_Tables.NAME ||
+             '_ID) FROM ' ||Cur_Tables.NAME||  ' t WHERE t.' ||Cur_Tables.NAME ||'_ID<' || v_StartWith || ') END) AS SEQUENCE '||  ' FROM AD_SEQUENCE '||  ' WHERE UPPER(NAME) = ' || '''' || Cur_Tables.NAME || ''''||') '||
+             ' WHERE UPPER(NAME) = ' ||''''|| Cur_Tables.NAME || ''''
+          )
+          ;
+      ELSE
+        INSERT
+        INTO AD_SCRIPT_SQL VALUES
+          (
+            (SELECT COALESCE(MAX(SEQNO), 0) +1
+            FROM AD_SCRIPT_SQL
+            )
+            ,
+             'UPDATE AD_SEQUENCE SET CURRENTNEXTSYS=(' ||  ' SELECT AD_SEQUENCE.INCREMENTNO + COALESCE((SELECT MAX(t.' || Cur_Tables.NAME ||
+             '_ID) FROM ' || Cur_Tables.NAME ||' t WHERE t.' || Cur_Tables.NAME ||'_ID<' || v_StartWith ||'),(' || v_StartWithSys || '-AD_SEQUENCE.INCREMENTNO))' ||
+             ' FROM AD_SEQUENCE WHERE UPPER(NAME) = ' || '''' || Cur_Tables.NAME || ''''||')' ||  ' WHERE UPPER(NAME) = ' ||''''|| Cur_Tables.NAME || ''''
+          )
+          ;
+      END IF;
+    END LOOP;
 END AD_UPDATE_SEQUENCE_GENERATE
 ]]></body>
     </function>
--- a/database/model/functions/AGING_GET_SCOPE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/AGING_GET_SCOPE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -49,7 +49,7 @@
     return 3;
   elsif (pDate<=now()+pCol4) then
     return 4;
-  else 
+  else
     return 5;
   end if;
 END AGING_GET_SCOPE
--- a/database/model/functions/A_ASSET_POST.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/A_ASSET_POST.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -154,7 +154,7 @@
       FROM A_AmortizationLine al, A_Amortization am
       WHERE A_Asset_ID=V_Record_ID  AND am.A_Amortization_ID=al.A_Amortization_ID;
       --we get the standard precision for the selected currency
-      SELECT STDPRECISION 
+      SELECT STDPRECISION
       INTO v_Currency_Pre
       FROM C_CURRENCY
       WHERE C_CURRENCY_ID = v_C_CURRENCY_ID;
--- a/database/model/functions/CHANGEPROJECTSTATUSTOORDER.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/CHANGEPROJECTSTATUSTOORDER.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -134,10 +134,10 @@
               RAISE_APPLICATION_ERROR(-20000, '@NoProjectPhases@');
             END IF;
           END IF;
-          /*In order to create a particular price list for the current project, 
+          /*In order to create a particular price list for the current project,
             project must be a service project and Create Temporary Price List option must be checked*/
           IF (Cur_SO.PROJECTCATEGORY<>'S' AND Cur_SO.CREATETEMPPRICELIST='Y') THEN
-            
+
             Ad_Sequence_Next('M_PriceList', v_AD_Client_ID, v_PriceList) ;
             INSERT
             INTO m_pricelist
@@ -271,14 +271,14 @@
             SET m_pricelist_id=v_PriceListPO
           WHERE c_project_id=v_Record_ID;
         END IF;
-        
-        /*In order to update the price list of the current project, 
+
+        /*In order to update the price list of the current project,
           project must be a service project and Create Temporary Price List option must be checked*/
         SELECT projectcategory, createtemppricelist
         INTO v_projectcategory, v_temppricelist
         FROM c_project
         WHERE c_project_id = v_Record_ID;
-        
+
         IF (v_projectcategory<>'S' AND v_temppricelist='Y') THEN
           UPDATE C_PROJECT
             SET projectstatus=v_ProjectStatus,
--- a/database/model/functions/CLOSEPROJECT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/CLOSEPROJECT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -68,7 +68,7 @@
     END LOOP; -- Get Parameter
     DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_p_Record_ID) ;
     -- Check that we have some restrictions
-    
+
     SELECT projectcategory, createtemppricelist
     INTO v_projectcategory, v_temppricelist
     FROM c_project
--- a/database/model/functions/C_BANKSTATEMENT_POST.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/C_BANKSTATEMENT_POST.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -4,608 +4,608 @@
       <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
         <default/>
       </parameter>
-      <body><![CDATA[/************************************************************************* 
-  * The contents of this file are subject to the Compiere License 
-  * Version 2.5.0 ("License"); You may not use this file except in 
-  * compliance with the License. You may obtain a copy of the License at 
-  * http://www.compiere.org/license.html 
-  * Software distributed under the License is distributed on an 
-  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 
-  * implied. See the License for the specific language governing rights 
-  * and limitations under the License. 
-  * The Original Code is  Compiere  ERP &  Business Solution 
-  * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, 
-  Inc. 
-  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, 
-  * parts created by ComPiere are Copyright (C) ComPiere, Inc.; 
-  * All Rights Reserved. 
-  * Contributor(s): Openbravo SL 
-  * Contributions are Copyright (C) 1999-2005 Openbravo, S.L 
-  ************************************************************************* 
-  * $Id: C_BankStatement_Post.sql,v 1.2 2002/05/22 02:48:28 jjanke Exp $ 
-  *** 
-  * Title: Post Bank Statments 
-  * Description: 
-  * - Update Balance and De-Activate 
-  ************************************************************************/ 
-  -- Logistice 
-  v_ResultStr VARCHAR2(2000):=''; 
-  v_Result NUMBER; 
-  v_Message VARCHAR2(2000):=''; 
-  v_Record_ID NUMBER; 
-  v_User NUMBER; 
-  v_DPManagementDocType_ID NUMBER; 
-  v_DPMId NUMBER; 
-  v_DPMLineId NUMBER; 
-   --Added by P.SAROBE 
-    v_C_Debt_Payment_Id NUMBER; 
- v_documentno_Settlement VARCHAR2(40); 
- v_documentno_Dp_Management VARCHAR2(50); 
- v_column_identifier VARCHAR2(200); 
- v_dateSettlement DATE; 
- v_Cancel_Processed CHAR(1); 
- v_nameBankstatement VARCHAR2 (60); 
- v_dateBankstatement DATE; 
- v_nameCash VARCHAR2 (60); 
- v_dateCash DATE; 
- v_Bankstatementline_ID NUMBER; 
- v_CashLine_ID NUMBER; 
- v_Settlement_Cancel_ID NUMBER; 
- v_ispaid CHAR(1); 
- --Finish added by P.Sarobe 
-  -- Parameter 
-  TYPE RECORD IS REF CURSOR; 
-    Cur_Parameter RECORD; 
+      <body><![CDATA[/*************************************************************************
+  * The contents of this file are subject to the Compiere License
+  * Version 2.5.0 ("License"); You may not use this file except in
+  * compliance with the License. You may obtain a copy of the License at
+  * http://www.compiere.org/license.html
+  * Software distributed under the License is distributed on an
+  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+  * implied. See the License for the specific language governing rights
+  * and limitations under the License.
+  * The Original Code is  Compiere  ERP &  Business Solution
+  * The Initial Developer of the Original Code is Jorg Janke  and ComPiere,
+  Inc.
+  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
+  * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
+  * All Rights Reserved.
+  * Contributor(s): Openbravo SL
+  * Contributions are Copyright (C) 1999-2005 Openbravo, S.L
+  *************************************************************************
+  * $Id: C_BankStatement_Post.sql,v 1.2 2002/05/22 02:48:28 jjanke Exp $
+  ***
+  * Title: Post Bank Statments
+  * Description:
+  * - Update Balance and De-Activate
+  ************************************************************************/
+  -- Logistice
+  v_ResultStr VARCHAR2(2000):='';
+  v_Result NUMBER;
+  v_Message VARCHAR2(2000):='';
+  v_Record_ID NUMBER;
+  v_User NUMBER;
+  v_DPManagementDocType_ID NUMBER;
+  v_DPMId NUMBER;
+  v_DPMLineId NUMBER;
+   --Added by P.SAROBE
+    v_C_Debt_Payment_Id NUMBER;
+ v_documentno_Settlement VARCHAR2(40);
+ v_documentno_Dp_Management VARCHAR2(50);
+ v_column_identifier VARCHAR2(200);
+ v_dateSettlement DATE;
+ v_Cancel_Processed CHAR(1);
+ v_nameBankstatement VARCHAR2 (60);
+ v_dateBankstatement DATE;
+ v_nameCash VARCHAR2 (60);
+ v_dateCash DATE;
+ v_Bankstatementline_ID NUMBER;
+ v_CashLine_ID NUMBER;
+ v_Settlement_Cancel_ID NUMBER;
+ v_ispaid CHAR(1);
+ --Finish added by P.Sarobe
+  -- Parameter
+  TYPE RECORD IS REF CURSOR;
+    Cur_Parameter RECORD;
     Cur_BankstatementDebtpayment RECORD;
-    -- Parameter Variables 
-    --  Parameter Variables 
-    v_Processed CHAR(1) ; 
-    v_Posted CHAR(1) ; 
-    v_count NUMBER; 
-    v_SettlementDocType_ID NUMBER(10) ; 
-    v_settlementID NUMBER(10) ; 
-    v_DocumentNo NUMBER(10) ; 
-    v_line C_CASHLINE.LINE%TYPE; 
-    -- BankAccount 
-    v_BA_Currency_ID NUMBER(10) ; 
-    v_BS_Date DATE; 
-    v_AD_Org_ID NUMBER; 
-    v_AD_Client_ID NUMBER(10) ; 
-    FINISH_PROCESS BOOLEAN:=false; 
-  BEGIN 
-    --  Update AD_PInstance 
-    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ; 
-    v_ResultStr:='PInstanceNotFound'; 
-    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ; 
-  BEGIN --BODY 
-    --  Get Parameters 
-    v_ResultStr:='ReadingParameters'; 
-    FOR Cur_Parameter IN 
-      (SELECT i.Record_ID, 
-        i.AD_User_ID, 
-        p.ParameterName, 
-        p.P_String, 
-        p.P_Number, 
-        p.P_Date 
-      FROM AD_PInstance i 
-      LEFT JOIN AD_PInstance_Para p 
-        ON i.AD_PInstance_ID=p.AD_PInstance_ID 
-      WHERE i.AD_PInstance_ID=p_PInstance_ID 
-      ORDER BY p.SeqNo 
-      ) 
-    LOOP 
-      v_Record_ID:=Cur_Parameter.Record_ID; 
-      v_User:=Cur_Parameter.AD_User_ID; 
-    END LOOP; --  Get Parameter 
-    SELECT PROCESSED, 
-      POSTED, 
-      AD_Client_ID, 
-      AD_Org_ID 
-    INTO v_Processed, 
-      v_Posted, 
-      v_AD_Client_ID, 
-      v_AD_Org_ID 
-    FROM C_BANKSTATEMENT 
-    WHERE C_BankStatement_ID=v_Record_ID; 
-    IF(v_Posted='Y') THEN 
+    -- Parameter Variables
+    --  Parameter Variables
+    v_Processed CHAR(1) ;
+    v_Posted CHAR(1) ;
+    v_count NUMBER;
+    v_SettlementDocType_ID NUMBER(10) ;
+    v_settlementID NUMBER(10) ;
+    v_DocumentNo NUMBER(10) ;
+    v_line C_CASHLINE.LINE%TYPE;
+    -- BankAccount
+    v_BA_Currency_ID NUMBER(10) ;
+    v_BS_Date DATE;
+    v_AD_Org_ID NUMBER;
+    v_AD_Client_ID NUMBER(10) ;
+    FINISH_PROCESS BOOLEAN:=false;
+  BEGIN
+    --  Update AD_PInstance
+    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
+    v_ResultStr:='PInstanceNotFound';
+    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
+  BEGIN --BODY
+    --  Get Parameters
+    v_ResultStr:='ReadingParameters';
+    FOR Cur_Parameter IN
+      (SELECT i.Record_ID,
+        i.AD_User_ID,
+        p.ParameterName,
+        p.P_String,
+        p.P_Number,
+        p.P_Date
+      FROM AD_PInstance i
+      LEFT JOIN AD_PInstance_Para p
+        ON i.AD_PInstance_ID=p.AD_PInstance_ID
+      WHERE i.AD_PInstance_ID=p_PInstance_ID
+      ORDER BY p.SeqNo
+      )
+    LOOP
+      v_Record_ID:=Cur_Parameter.Record_ID;
+      v_User:=Cur_Parameter.AD_User_ID;
+    END LOOP; --  Get Parameter
+    SELECT PROCESSED,
+      POSTED,
+      AD_Client_ID,
+      AD_Org_ID
+    INTO v_Processed,
+      v_Posted,
+      v_AD_Client_ID,
+      v_AD_Org_ID
+    FROM C_BANKSTATEMENT
+    WHERE C_BankStatement_ID=v_Record_ID;
+    IF(v_Posted='Y') THEN
       RAISE_APPLICATION_ERROR(-20000, '@BankStatementDocumentPosted@') ;
-    END IF; 
-    IF(NOT FINISH_PROCESS) THEN 
-      DECLARE 
-        Cur_AutomaticSettlementCancel RECORD; 
-        CUR_MANAGEMENTLINES RECORD; 
-        v_DP_MANAGEMENT NUMBER; 
-        v_DATEACCT DATE; 
-        v_DATETRX DATE; 
-      BEGIN 
-        /* 
-        *  Reversing process 
-        */ 
-       IF (v_Processed = 'Y') THEN 
-          v_ResultStr := 'Reversed'; 
- 
-   --Unpost Settlement 
-   FOR Cur_AutomaticSettlementCancel IN (SELECT DISTINCT S.C_SETTLEMENT_ID 
-            FROM C_DEBT_PAYMENT DP, C_SETTLEMENT S 
-            WHERE DP.C_SETTLEMENT_CANCEL_ID = S.C_SETTLEMENT_ID 
-            AND DP.C_BANKSTATEMENTLINE_ID IN 
-               (SELECT C_BANKSTATEMENTLINE_ID FROM C_BANKSTATEMENTLINE 
-             WHERE C_BANKSTATEMENT_ID = v_Record_ID) 
-            AND S.DOCUMENTNO LIKE '*BSP*%') LOOP 
-      -- Reset fact acct 
-     DELETE FROM FACT_ACCT WHERE AD_TABLE_ID = 800019 AND RECORD_ID = Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID; 
-     UPDATE C_SETTLEMENT SET POSTED='N' WHERE C_SETTLEMENT_ID = Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID; 
- 
- 
-     UPDATE C_DEBT_PAYMENT 
-     SET C_BANKSTATEMENTLINE_ID = NULL, C_SETTLEMENT_CANCEL_ID = NULL, ISPAID = 'N', CANCEL_PROCESSED = 'N' 
-     WHERE C_SETTLEMENT_CANCEL_ID = Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID; 
- 
-     C_SETTLEMENT_POST(null, Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID); 
- 
-     DELETE FROM C_SETTLEMENT WHERE C_SETTLEMENT_ID = Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID; 
-   END LOOP; 
- 
-   --Unpost DP returned from remittances 
-    FOR CUR_MANAGEMENTLINES IN (SELECT  BSL.C_DP_MANAGEMENT_ID, RL.C_REMITTANCELINE_ID, BSL.C_BANKSTATEMENTLINE_ID, BSL.LINE 
-                        FROM C_REMITTANCE_TYPE RT, C_REMITTANCE R, C_REMITTANCELINE RL, C_BANKSTATEMENTLINE BSL, C_DEBT_PAYMENT DP, 
-                        C_DEBT_PAYMENT DP2 
-                        WHERE R.C_REMITTANCE_ID = RL.C_REMITTANCE_ID 
-                        AND RT.C_REMITTANCE_TYPE_ID = R.C_REMITTANCE_TYPE_ID 
-                        AND RL.C_DEBT_PAYMENT_CANCELLED = BSL.C_DEBT_PAYMENT_ID 
-                        AND BSL.C_DEBT_PAYMENT_ID = DP.C_DEBT_PAYMENT_ID 
-                        AND RL.C_DEBT_PAYMENT_ID = DP2.C_DEBT_PAYMENT_ID 
-                        AND BSL.C_BANKSTATEMENT_ID = v_Record_ID 
-                        AND RT.STATUS_RETURNED = DP.STATUS 
+    END IF;
+    IF(NOT FINISH_PROCESS) THEN
+      DECLARE
+        Cur_AutomaticSettlementCancel RECORD;
+        CUR_MANAGEMENTLINES RECORD;
+        v_DP_MANAGEMENT NUMBER;
+        v_DATEACCT DATE;
+        v_DATETRX DATE;
+      BEGIN
+        /*
+        *  Reversing process
+        */
+       IF (v_Processed = 'Y') THEN
+          v_ResultStr := 'Reversed';
+
+   --Unpost Settlement
+   FOR Cur_AutomaticSettlementCancel IN (SELECT DISTINCT S.C_SETTLEMENT_ID
+            FROM C_DEBT_PAYMENT DP, C_SETTLEMENT S
+            WHERE DP.C_SETTLEMENT_CANCEL_ID = S.C_SETTLEMENT_ID
+            AND DP.C_BANKSTATEMENTLINE_ID IN
+               (SELECT C_BANKSTATEMENTLINE_ID FROM C_BANKSTATEMENTLINE
+             WHERE C_BANKSTATEMENT_ID = v_Record_ID)
+            AND S.DOCUMENTNO LIKE '*BSP*%') LOOP
+      -- Reset fact acct
+     DELETE FROM FACT_ACCT WHERE AD_TABLE_ID = 800019 AND RECORD_ID = Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID;
+     UPDATE C_SETTLEMENT SET POSTED='N' WHERE C_SETTLEMENT_ID = Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID;
+
+
+     UPDATE C_DEBT_PAYMENT
+     SET C_BANKSTATEMENTLINE_ID = NULL, C_SETTLEMENT_CANCEL_ID = NULL, ISPAID = 'N', CANCEL_PROCESSED = 'N'
+     WHERE C_SETTLEMENT_CANCEL_ID = Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID;
+
+     C_SETTLEMENT_POST(null, Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID);
+
+     DELETE FROM C_SETTLEMENT WHERE C_SETTLEMENT_ID = Cur_AutomaticSettlementCancel.C_SETTLEMENT_ID;
+   END LOOP;
+
+   --Unpost DP returned from remittances
+    FOR CUR_MANAGEMENTLINES IN (SELECT  BSL.C_DP_MANAGEMENT_ID, RL.C_REMITTANCELINE_ID, BSL.C_BANKSTATEMENTLINE_ID, BSL.LINE
+                        FROM C_REMITTANCE_TYPE RT, C_REMITTANCE R, C_REMITTANCELINE RL, C_BANKSTATEMENTLINE BSL, C_DEBT_PAYMENT DP,
+                        C_DEBT_PAYMENT DP2
+                        WHERE R.C_REMITTANCE_ID = RL.C_REMITTANCE_ID
+                        AND RT.C_REMITTANCE_TYPE_ID = R.C_REMITTANCE_TYPE_ID
+                        AND RL.C_DEBT_PAYMENT_CANCELLED = BSL.C_DEBT_PAYMENT_ID
+                        AND BSL.C_DEBT_PAYMENT_ID = DP.C_DEBT_PAYMENT_ID
+                        AND RL.C_DEBT_PAYMENT_ID = DP2.C_DEBT_PAYMENT_ID
+                        AND BSL.C_BANKSTATEMENT_ID = v_Record_ID
+                        AND RT.STATUS_RETURNED = DP.STATUS
                         AND RT.STATUS_RETURNED = DP2.STATUS
-                        AND EXISTS (SELECT 1 
+                        AND EXISTS (SELECT 1
                                       FROM C_DP_MANAGEMENT
-                                     WHERE BSL.C_DP_MANAGEMENT_ID=C_DP_MANAGEMENT.C_DP_MANAGEMENT_ID)) LOOP 
-    begin 
-      DELETE FROM FACT_ACCT WHERE AD_TABLE_ID = 800176 AND RECORD_ID = CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID; 
-      UPDATE C_DP_MANAGEMENT SET POSTED='N' WHERE C_DP_MANAGEMENT_ID = CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID; 
- 
-      C_DP_MANAGEMENT_POST(NULL, CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID); 
-      DELETE FROM C_DP_MANAGEMENTLINE WHERE C_DP_MANAGEMENT_ID = CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID; 
-      UPDATE C_BANKSTATEMENTLINE SET C_DP_MANAGEMENT_ID =  NULL WHERE C_BANKSTATEMENTLINE_ID = CUR_MANAGEMENTLINES.C_BANKSTATEMENTLINE_ID; 
-      DELETE FROM C_DP_MANAGEMENT WHERE C_DP_MANAGEMENT_ID = CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID; 
-      UPDATE C_REMITTANCELINE SET RETURNED = 'N' WHERE C_REMITTANCELINE_ID = CUR_MANAGEMENTLINES.C_REMITTANCELINE_ID; 
-    exception when others then 
-     ROLLBACK; 
-     v_ResultStr:='@ErrorUnoprocessingBS@ Line:' ||CUR_MANAGEMENTLINES.LINE|| ': ' || SQLERRM || ' - ' || v_Message; 
-     DBMS_OUTPUT.PUT_LINE(v_ResultStr) ; 
-     AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ; 
-     RETURN; 
-    end; 
-   END LOOP; 
- 
- 
-         UPDATE C_DEBT_PAYMENT SET C_BANKSTATEMENTLINE_ID = NULL 
-          WHERE C_BANKSTATEMENTLINE_ID IS NOT NULL 
-            AND C_BANKSTATEMENTLINE_ID IN 
-                                        (SELECT C_BANKSTATEMENTLINE_ID FROM C_BANKSTATEMENTLINE 
-                                          WHERE C_BANKSTATEMENT_ID = v_Record_ID); 
-          UPDATE C_BANKSTATEMENT 
-             SET PROCESSED = 'N', 
-                 StatementDifference=NULL, 
-                 EndingBalance=0 
-           WHERE C_BANKSTATEMENT_ID = v_Record_ID; 
-          FINISH_PROCESS := true; 
-       END IF; 
-      END; 
-    END IF;--FINISH_PROCESS 
- 
-    IF(NOT FINISH_PROCESS) THEN 
-      /* 
-      *  Checking Restrictions 
-      */ 
-      v_ResultStr:='CheckingRestrictions - C_BANKSTATEMENT ORG IS IN C_BANKACCOUNT ORG TREE'; 
-      SELECT COUNT(*) 
-      INTO v_count 
-      FROM C_BANKSTATEMENT c, 
-        C_BANKACCOUNT b 
-      WHERE c.C_BankStatement_ID=v_Record_ID 
-        AND c.C_BANKACCOUNT_ID=b.C_BANKACCOUNT_ID 
-        AND Ad_Isorgincluded(c.AD_ORG_ID, b.AD_ORG_ID, b.AD_CLIENT_ID)=-1; 
-      IF v_count>0 THEN 
+                                     WHERE BSL.C_DP_MANAGEMENT_ID=C_DP_MANAGEMENT.C_DP_MANAGEMENT_ID)) LOOP
+    begin
+      DELETE FROM FACT_ACCT WHERE AD_TABLE_ID = 800176 AND RECORD_ID = CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID;
+      UPDATE C_DP_MANAGEMENT SET POSTED='N' WHERE C_DP_MANAGEMENT_ID = CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID;
+
+      C_DP_MANAGEMENT_POST(NULL, CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID);
+      DELETE FROM C_DP_MANAGEMENTLINE WHERE C_DP_MANAGEMENT_ID = CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID;
+      UPDATE C_BANKSTATEMENTLINE SET C_DP_MANAGEMENT_ID =  NULL WHERE C_BANKSTATEMENTLINE_ID = CUR_MANAGEMENTLINES.C_BANKSTATEMENTLINE_ID;
+      DELETE FROM C_DP_MANAGEMENT WHERE C_DP_MANAGEMENT_ID = CUR_MANAGEMENTLINES.C_DP_MANAGEMENT_ID;
+      UPDATE C_REMITTANCELINE SET RETURNED = 'N' WHERE C_REMITTANCELINE_ID = CUR_MANAGEMENTLINES.C_REMITTANCELINE_ID;
+    exception when others then
+     ROLLBACK;
+     v_ResultStr:='@ErrorUnoprocessingBS@ Line:' ||CUR_MANAGEMENTLINES.LINE|| ': ' || SQLERRM || ' - ' || v_Message;
+     DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
+     AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
+     RETURN;
+    end;
+   END LOOP;
+
+
+         UPDATE C_DEBT_PAYMENT SET C_BANKSTATEMENTLINE_ID = NULL
+          WHERE C_BANKSTATEMENTLINE_ID IS NOT NULL
+            AND C_BANKSTATEMENTLINE_ID IN
+                                        (SELECT C_BANKSTATEMENTLINE_ID FROM C_BANKSTATEMENTLINE
+                                          WHERE C_BANKSTATEMENT_ID = v_Record_ID);
+          UPDATE C_BANKSTATEMENT
+             SET PROCESSED = 'N',
+                 StatementDifference=NULL,
+                 EndingBalance=0
+           WHERE C_BANKSTATEMENT_ID = v_Record_ID;
+          FINISH_PROCESS := true;
+       END IF;
+      END;
+    END IF;--FINISH_PROCESS
+
+    IF(NOT FINISH_PROCESS) THEN
+      /*
+      *  Checking Restrictions
+      */
+      v_ResultStr:='CheckingRestrictions - C_BANKSTATEMENT ORG IS IN C_BANKACCOUNT ORG TREE';
+      SELECT COUNT(*)
+      INTO v_count
+      FROM C_BANKSTATEMENT c,
+        C_BANKACCOUNT b
+      WHERE c.C_BankStatement_ID=v_Record_ID
+        AND c.C_BANKACCOUNT_ID=b.C_BANKACCOUNT_ID
+        AND Ad_Isorgincluded(c.AD_ORG_ID, b.AD_ORG_ID, b.AD_CLIENT_ID)=-1;
+      IF v_count>0 THEN
         RAISE_APPLICATION_ERROR(-20000, '@NotCorrectOrgBankaccount@') ;
-      END IF; 
-    END IF;--FINISH_PROCESS 
-    IF(NOT FINISH_PROCESS) THEN 
-      v_ResultStr:='CheckingRestrictions - C_BANKSTATEMENT ORG IS IN C_DEBT_PAYMENT ORG TREE'; 
-      /*--Deprecated by PSarobe--SELECT COUNT(*) 
-      INTO v_count 
-      FROM 
-        (SELECT * 
-        FROM 
-          (SELECT l.AD_ORG_ID AS A, 
-            bp.AD_ORG_ID AS B, 
-            c.AD_ORG_ID AS C, 
-            c.AD_CLIENT_ID AS D 
-          FROM C_BANKSTATEMENT c, 
-            C_BANKSTATEMENTLINE cl, 
-            C_DEBT_PAYMENT l, 
-            C_BPARTNER bp 
-          WHERE c.C_BankStatement_ID=cl.C_BankStatement_ID 
-            AND c.C_BankStatement_ID=v_Record_ID 
-            AND cl.C_DEBT_PAYMENT_ID=l.C_DEBT_PAYMENT_ID 
-            AND l.C_BPARTNER_ID=bp.C_BPARTNER_ID 
-          ) 
-          S 
-        GROUP BY A, 
-          B, 
-          C, 
-          D 
-        HAVING Ad_Isorgincluded(A, B, D)=-1 
-          OR Ad_Isorgincluded(A, C, D)=-1 
-        ) 
-        SS;*/ 
-   --Added by PSarobe. Same way as C_CASH_POST 
-   SELECT COUNT(*), 
-        MAX(cl.Line) 
-      INTO v_count, 
-        v_line 
-      FROM C_BANKSTATEMENT c, 
-        C_BANKSTATEMENTLINE cl, 
-        C_DEBT_PAYMENT l, 
-        C_BPARTNER bp 
-      WHERE c.C_BANKSTATEMENT_ID=cl.C_BANKSTATEMENT_ID 
-        AND c.C_BANKSTATEMENT_ID=v_Record_ID 
-        AND cl.C_DEBT_PAYMENT_ID=l.C_DEBT_PAYMENT_ID 
-        AND l.C_BPARTNER_ID=bp.C_BPARTNER_ID 
-        AND(Ad_Isorgincluded(l.AD_ORG_ID, bp.AD_ORG_ID, bp.AD_CLIENT_ID)=-1--To be deprecated, to be fixed. This Check restriction should be checked when debt payment is created. Added by PSarobe 
-        OR Ad_Isorgincluded(l.AD_ORG_ID, c.AD_ORG_ID, c.AD_CLIENT_ID)=-1) ; 
-      IF v_count>0 THEN 
+      END IF;
+    END IF;--FINISH_PROCESS
+    IF(NOT FINISH_PROCESS) THEN
+      v_ResultStr:='CheckingRestrictions - C_BANKSTATEMENT ORG IS IN C_DEBT_PAYMENT ORG TREE';
+      /*--Deprecated by PSarobe--SELECT COUNT(*)
+      INTO v_count
+      FROM
+        (SELECT *
+        FROM
+          (SELECT l.AD_ORG_ID AS A,
+            bp.AD_ORG_ID AS B,
+            c.AD_ORG_ID AS C,
+            c.AD_CLIENT_ID AS D
+          FROM C_BANKSTATEMENT c,
+            C_BANKSTATEMENTLINE cl,
+            C_DEBT_PAYMENT l,
+            C_BPARTNER bp
+          WHERE c.C_BankStatement_ID=cl.C_BankStatement_ID
+            AND c.C_BankStatement_ID=v_Record_ID
+            AND cl.C_DEBT_PAYMENT_ID=l.C_DEBT_PAYMENT_ID
+            AND l.C_BPARTNER_ID=bp.C_BPARTNER_ID
+          )
+          S
+        GROUP BY A,
+          B,
+          C,
+          D
+        HAVING Ad_Isorgincluded(A, B, D)=-1
+          OR Ad_Isorgincluded(A, C, D)=-1
+        )
+        SS;*/
+   --Added by PSarobe. Same way as C_CASH_POST
+   SELECT COUNT(*),
+        MAX(cl.Line)
+      INTO v_count,
+        v_line
+      FROM C_BANKSTATEMENT c,
+        C_BANKSTATEMENTLINE cl,
+        C_DEBT_PAYMENT l,
+        C_BPARTNER bp
+      WHERE c.C_BANKSTATEMENT_ID=cl.C_BANKSTATEMENT_ID
+        AND c.C_BANKSTATEMENT_ID=v_Record_ID
+        AND cl.C_DEBT_PAYMENT_ID=l.C_DEBT_PAYMENT_ID
+        AND l.C_BPARTNER_ID=bp.C_BPARTNER_ID
+        AND(Ad_Isorgincluded(l.AD_ORG_ID, bp.AD_ORG_ID, bp.AD_CLIENT_ID)=-1--To be deprecated, to be fixed. This Check restriction should be checked when debt payment is created. Added by PSarobe
+        OR Ad_Isorgincluded(l.AD_ORG_ID, c.AD_ORG_ID, c.AD_CLIENT_ID)=-1) ;
+      IF v_count>0 THEN
         RAISE_APPLICATION_ERROR(-20000, '@Inline@'||v_line||' '||'@NotCorrectOrgDebtpaymentBankstatement@') ;
-      END IF;--Finish added by PSarobe 
-    END IF;--FINISH_PROCESS 
-    IF(NOT FINISH_PROCESS) THEN 
-      SELECT COUNT(*), 
-        MAX(bsl.Line) 
-      INTO v_count, 
-        v_line 
-      FROM C_BANKSTATEMENTLINE bsl, 
-        C_DEBT_PAYMENT dp 
-      WHERE bsl.C_BankStatement_ID=v_Record_ID 
-        AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID 
-        AND bsl.C_Currency_ID=dp.C_Currency_ID 
-        AND CASE dp.IsReceipt WHEN 'Y' THEN -- If IsReceipt = N, amount*-1 
-            (dp.Amount-coalesce(dp.WriteOffAmt,0)) ELSE(coalesce(dp.WriteOffAmt,0)-dp.Amount) 
-        END <>(bsl.TrxAmt) ; 
-      IF v_count>0 THEN 
+      END IF;--Finish added by PSarobe
+    END IF;--FINISH_PROCESS
+    IF(NOT FINISH_PROCESS) THEN
+      SELECT COUNT(*),
+        MAX(bsl.Line)
+      INTO v_count,
+        v_line
+      FROM C_BANKSTATEMENTLINE bsl,
+        C_DEBT_PAYMENT dp
+      WHERE bsl.C_BankStatement_ID=v_Record_ID
+        AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID
+        AND bsl.C_Currency_ID=dp.C_Currency_ID
+        AND CASE dp.IsReceipt WHEN 'Y' THEN -- If IsReceipt = N, amount*-1
+            (dp.Amount-coalesce(dp.WriteOffAmt,0)) ELSE(coalesce(dp.WriteOffAmt,0)-dp.Amount)
+        END <>(bsl.TrxAmt) ;
+      IF v_count>0 THEN
        RAISE_APPLICATION_ERROR(-20000, '@Inline@'||v_line||' '||'@DebtAmountsSamemoneyNoMatch@') ;
-      END IF; 
-    END IF;--FINISH_PROCESS 
-    IF(NOT FINISH_PROCESS) THEN 
-      SELECT COUNT(*), 
-        MAX(bsl.Line) 
-      INTO v_count, 
-        v_line 
-      FROM C_BANKSTATEMENTLINE bsl, 
-        C_BANKSTATEMENT bs, 
-        C_DEBT_PAYMENT dp 
-      WHERE bsl.C_BankStatement_ID=bs.C_BankStatement_ID 
-        AND bsl.C_BankStatement_ID=v_Record_ID 
-        AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID 
-        AND bsl.C_Currency_ID<>dp.C_Currency_ID 
-    AND 
-        C_Currency_Round(C_Currency_Convert( 
-        (CASE dp.IsReceipt WHEN 'Y' THEN -- If IsReceipt = N, amount*-1 
-          (dp.Amount-coalesce(dp.WriteOffAmt,0)) ELSE(coalesce(dp.WriteOffAmt,0)-dp.Amount) 
-        END), dp.C_Currency_ID, bsl.C_Currency_ID, bs.StatementDate, NULL, bs.AD_Client_ID, bs.AD_Org_ID),bsl.C_Currency_ID, null) 
-        <> C_Currency_Round(bsl.TrxAmt, bsl.C_Currency_ID, null); 
-      IF v_count>0 THEN 
+      END IF;
+    END IF;--FINISH_PROCESS
+    IF(NOT FINISH_PROCESS) THEN
+      SELECT COUNT(*),
+        MAX(bsl.Line)
+      INTO v_count,
+        v_line
+      FROM C_BANKSTATEMENTLINE bsl,
+        C_BANKSTATEMENT bs,
+        C_DEBT_PAYMENT dp
+      WHERE bsl.C_BankStatement_ID=bs.C_BankStatement_ID
+        AND bsl.C_BankStatement_ID=v_Record_ID
+        AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID
+        AND bsl.C_Currency_ID<>dp.C_Currency_ID
+    AND
+        C_Currency_Round(C_Currency_Convert(
+        (CASE dp.IsReceipt WHEN 'Y' THEN -- If IsReceipt = N, amount*-1
+          (dp.Amount-coalesce(dp.WriteOffAmt,0)) ELSE(coalesce(dp.WriteOffAmt,0)-dp.Amount)
+        END), dp.C_Currency_ID, bsl.C_Currency_ID, bs.StatementDate, NULL, bs.AD_Client_ID, bs.AD_Org_ID),bsl.C_Currency_ID, null)
+        <> C_Currency_Round(bsl.TrxAmt, bsl.C_Currency_ID, null);
+      IF v_count>0 THEN
         RAISE_APPLICATION_ERROR(-20000, '@Inline@'||v_line||' '||'@DebtAmountsDifferentMoneyNoMatch@') ;
-      END IF; 
-    END IF;--FINISH_PROCESS 
-    IF(NOT FINISH_PROCESS) THEN 
-      SELECT COUNT(*), MAX(bsl.C_BANKSTATEMENTLINE_ID) 
-      INTO v_count, v_Bankstatementline_ID 
-      FROM C_BANKSTATEMENTLINE bsl, 
-        C_DEBT_PAYMENT dp 
-      WHERE bsl.C_BankStatement_ID=v_Record_ID 
-        AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID 
-        AND C_Debt_Payment_Status(dp.C_SETTLEMENT_CANCEL_ID, dp.Cancel_Processed, dp.Generate_Processed, dp.IsPaid, dp.IsValid, dp.C_CashLine_ID, dp.C_BankStatementLine_ID) NOT IN('P', 'A') ; 
-      IF v_count>0 THEN 
-        --Added by P.Sarobe. New messages 
-    SELECT line, c_Debt_payment_Id INTO v_line, v_C_Debt_Payment_Id 
-    FROM C_Bankstatementline WHERE c_Bankstatementline_Id = v_Bankstatementline_ID; 
- 
-    SELECT c_Bankstatementline_Id, c_cashline_id, c_settlement_cancel_id, ispaid, cancel_processed 
-    INTO v_Bankstatementline_ID, v_CashLine_ID, v_Settlement_Cancel_ID, v_ispaid, v_Cancel_Processed 
-    FROM C_DEBT_PAYMENT WHERE C_Debt_Payment_ID = v_C_Debt_Payment_Id; 
- 
-        IF v_Bankstatementline_ID IS NOT NULL THEN 
-        SELECT C_BANKSTATEMENT.NAME, C_BANKSTATEMENT.STATEMENTDATE 
-     INTO v_nameBankstatement, v_dateBankstatement 
-     FROM C_BANKSTATEMENT, C_BANKSTATEMENTLINE 
-     WHERE C_BANKSTATEMENT.C_BANKSTATEMENT_ID = C_BANKSTATEMENTLINE.C_BANKSTATEMENT_ID 
-     AND C_BANKSTATEMENTLINE.C_BANKSTATEMENTLINE_ID = v_Bankstatementline_ID; 
+      END IF;
+    END IF;--FINISH_PROCESS
+    IF(NOT FINISH_PROCESS) THEN
+      SELECT COUNT(*), MAX(bsl.C_BANKSTATEMENTLINE_ID)
+      INTO v_count, v_Bankstatementline_ID
+      FROM C_BANKSTATEMENTLINE bsl,
+        C_DEBT_PAYMENT dp
+      WHERE bsl.C_BankStatement_ID=v_Record_ID
+        AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID
+        AND C_Debt_Payment_Status(dp.C_SETTLEMENT_CANCEL_ID, dp.Cancel_Processed, dp.Generate_Processed, dp.IsPaid, dp.IsValid, dp.C_CashLine_ID, dp.C_BankStatementLine_ID) NOT IN('P', 'A') ;
+      IF v_count>0 THEN
+        --Added by P.Sarobe. New messages
+    SELECT line, c_Debt_payment_Id INTO v_line, v_C_Debt_Payment_Id
+    FROM C_Bankstatementline WHERE c_Bankstatementline_Id = v_Bankstatementline_ID;
+
+    SELECT c_Bankstatementline_Id, c_cashline_id, c_settlement_cancel_id, ispaid, cancel_processed
+    INTO v_Bankstatementline_ID, v_CashLine_ID, v_Settlement_Cancel_ID, v_ispaid, v_Cancel_Processed
+    FROM C_DEBT_PAYMENT WHERE C_Debt_Payment_ID = v_C_Debt_Payment_Id;
+
+        IF v_Bankstatementline_ID IS NOT NULL THEN
+        SELECT C_BANKSTATEMENT.NAME, C_BANKSTATEMENT.STATEMENTDATE
+     INTO v_nameBankstatement, v_dateBankstatement
+     FROM C_BANKSTATEMENT, C_BANKSTATEMENTLINE
+     WHERE C_BANKSTATEMENT.C_BANKSTATEMENT_ID = C_BANKSTATEMENTLINE.C_BANKSTATEMENT_ID
+     AND C_BANKSTATEMENTLINE.C_BANKSTATEMENTLINE_ID = v_Bankstatementline_ID;
              RAISE_APPLICATION_ERROR(-20000, '@Inline@'||v_line||' '||'@ManagedDebtPaymentBank@'||v_nameBankstatement||' '||'@Bydate@'||v_dateBankstatement) ;
-      END IF; 
-      IF v_CashLine_ID IS NOT NULL THEN--This is also checked in the unique index C_CASHLINE_DEBT_PAYMENT 
-        SELECT C_CASH.NAME, C_CASH.STATEMENTDATE 
-     INTO v_nameCash, v_dateCash 
-     FROM C_CASH, C_CASHLINE 
-     WHERE C_CASH.C_CASH_ID = C_CASHLINE.C_CASH_ID 
-     AND C_CASHLINE.C_CASHLINE_ID = v_CashLine_ID; 
+      END IF;
+      IF v_CashLine_ID IS NOT NULL THEN--This is also checked in the unique index C_CASHLINE_DEBT_PAYMENT
+        SELECT C_CASH.NAME, C_CASH.STATEMENTDATE
+     INTO v_nameCash, v_dateCash
+     FROM C_CASH, C_CASHLINE
+     WHERE C_CASH.C_CASH_ID = C_CASHLINE.C_CASH_ID
+     AND C_CASHLINE.C_CASHLINE_ID = v_CashLine_ID;
              RAISE_APPLICATION_ERROR(-20000, '@Inline@'||v_line||' '||'@ManagedDebtPaymentCash@'||v_nameCash||' '||'@Bydate@'||v_dateCash) ;
-      END IF; 
-      IF v_Cancel_Processed='Y' AND v_ispaid='N' THEN 
-        SELECT documentno, datetrx 
-     INTO v_documentno_Settlement, v_dateSettlement 
-     FROM C_SETTLEMENT 
-     WHERE C_SETTLEMENT_ID = v_Settlement_Cancel_ID; 
+      END IF;
+      IF v_Cancel_Processed='Y' AND v_ispaid='N' THEN
+        SELECT documentno, datetrx
+     INTO v_documentno_Settlement, v_dateSettlement
+     FROM C_SETTLEMENT
+     WHERE C_SETTLEMENT_ID = v_Settlement_Cancel_ID;
      RAISE_APPLICATION_ERROR(-20000, '@Inline@'||v_line||' '||'@ManagedDebtPaymentCancel@'||v_documentno_Settlement||' '||'@Bydate@'||v_dateSettlement) ;
-      END IF; 
-      END IF; 
-    END IF;--FINISH_PROCESS 
-  IF (NOT FINISH_PROCESS) THEN 
-     SELECT COUNT(*), MAX(Line) 
-      INTO v_Count, v_Line 
-       FROM C_BANKSTATEMENTLINE 
-     WHERE C_BankStatement_ID=v_Record_ID 
-       AND STMTAMT != TRXAMT-CHARGEAMT-CONVERTCHARGEAMT; 
-   IF v_count>0 THEN 
+      END IF;
+      END IF;
+    END IF;--FINISH_PROCESS
+  IF (NOT FINISH_PROCESS) THEN
+     SELECT COUNT(*), MAX(Line)
+      INTO v_Count, v_Line
+       FROM C_BANKSTATEMENTLINE
+     WHERE C_BankStatement_ID=v_Record_ID
+       AND STMTAMT != TRXAMT-CHARGEAMT-CONVERTCHARGEAMT;
+   IF v_count>0 THEN
         RAISE_APPLICATION_ERROR(-20000, '@Inline@'||v_line||' '||'@ChargeAmtsDontMatch@');
-      END IF; 
-  END IF; --FINISH_PROCESS 
-    IF(NOT FINISH_PROCESS) THEN 
-   SELECT COUNT(*), MAX(debtpayment_Id) 
-   INTO v_count, v_C_Debt_Payment_Id 
-   FROM 
-   (SELECT min(dp.C_Debt_Payment_ID) as debtpayment_Id 
-        FROM C_BANKSTATEMENTLINE bsl, 
-          C_DEBT_PAYMENT dp 
-        WHERE bsl.C_BankStatement_ID=v_Record_ID 
-          AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID 
-        GROUP BY dp.C_Debt_Payment_ID 
-        HAVING COUNT(*)>1 
-  ) A; 
-      IF v_count>0 THEN 
-        --Added by PSarobe. 
-     FOR Cur_BankstatementDebtpayment IN (SELECT line 
-             FROM c_Bankstatementline 
-          WHERE c_Bankstatementline.c_Bankstatement_id=v_Record_ID 
-          AND c_Bankstatementline.c_debt_payment_id=v_C_Debt_Payment_Id 
-          ORDER BY line) LOOP 
-   v_Message:=v_Message||Cur_BankstatementDebtpayment.line||', '; 
-   END LOOP; 
+      END IF;
+  END IF; --FINISH_PROCESS
+    IF(NOT FINISH_PROCESS) THEN
+   SELECT COUNT(*), MAX(debtpayment_Id)
+   INTO v_count, v_C_Debt_Payment_Id
+   FROM
+   (SELECT min(dp.C_Debt_Payment_ID) as debtpayment_Id
+        FROM C_BANKSTATEMENTLINE bsl,
+          C_DEBT_PAYMENT dp
+        WHERE bsl.C_BankStatement_ID=v_Record_ID
+          AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID
+        GROUP BY dp.C_Debt_Payment_ID
+        HAVING COUNT(*)>1
+  ) A;
+      IF v_count>0 THEN
+        --Added by PSarobe.
+     FOR Cur_BankstatementDebtpayment IN (SELECT line
+             FROM c_Bankstatementline
+          WHERE c_Bankstatementline.c_Bankstatement_id=v_Record_ID
+          AND c_Bankstatementline.c_debt_payment_id=v_C_Debt_Payment_Id
+          ORDER BY line) LOOP
+   v_Message:=v_Message||Cur_BankstatementDebtpayment.line||', ';
+   END LOOP;
    RAISE_APPLICATION_ERROR(-20000, '@Inlines@'||v_Message||' '||'@Samedebtpayment@') ;
-      END IF; 
-    END IF;--FINISH_PROCESS 
-    IF(NOT FINISH_PROCESS) THEN 
-      /** 
-      *  Generate C_Settlement 
-      */ 
-      DECLARE 
-        CUR_BSLINES_DATES RECORD; 
-        Cur_ManagementLines1 RECORD; 
-       /* Map error NUMBER returned by raise_application_error to user-defined exception. */ 
+      END IF;
+    END IF;--FINISH_PROCESS
+    IF(NOT FINISH_PROCESS) THEN
+      /**
+      *  Generate C_Settlement
+      */
+      DECLARE
+        CUR_BSLINES_DATES RECORD;
+        Cur_ManagementLines1 RECORD;
+       /* Map error NUMBER returned by raise_application_error to user-defined exception. */
   OB_exception Exception;
-  PRAGMA EXCEPTION_INIT(OB_exception, -20000); 
-      BEGIN 
-        FOR Cur_ManagementLines1 IN 
-          (SELECT BSL.C_DEBT_PAYMENT_ID AS DP1, RT.STATUS_RETURNED, RL.C_DEBT_PAYMENT_ID AS DP2, 
-            RL.AD_ORG_ID, R.AD_CLIENT_ID, BSL.DATEACCT, 
-            BSL.VALUTADATE, BSL.C_CURRENCY_ID, DP.STATUS, 
-            DP2.STATUS AS DP2_STATUS, BSL.UPDATEDBY, RL.C_REMITTANCELINE_ID, 
-            BSL.C_BANKSTATEMENTLINE_ID 
-          FROM C_REMITTANCE_TYPE RT, C_REMITTANCE R, C_REMITTANCELINE RL, 
-            C_BANKSTATEMENTLINE BSL, C_DEBT_PAYMENT DP, C_DEBT_PAYMENT DP2 
-          WHERE R.C_REMITTANCE_ID=RL.C_REMITTANCE_ID 
-            AND RT.C_REMITTANCE_TYPE_ID=R.C_REMITTANCE_TYPE_ID 
-            AND RL.C_DEBT_PAYMENT_CANCELLED=BSL.C_DEBT_PAYMENT_ID 
-            AND BSL.C_DEBT_PAYMENT_ID=DP.C_DEBT_PAYMENT_ID 
-            AND RL.C_DEBT_PAYMENT_ID=DP2.C_DEBT_PAYMENT_ID 
-            AND BSL.C_BANKSTATEMENT_ID=v_Record_ID 
-            AND RL.RETURNED='N' 
-          ) 
-        LOOP 
-          --Create DPManagement 
+  PRAGMA EXCEPTION_INIT(OB_exception, -20000);
+      BEGIN
+        FOR Cur_ManagementLines1 IN
+          (SELECT BSL.C_DEBT_PAYMENT_ID AS DP1, RT.STATUS_RETURNED, RL.C_DEBT_PAYMENT_ID AS DP2,
+            RL.AD_ORG_ID, R.AD_CLIENT_ID, BSL.DATEACCT,
+            BSL.VALUTADATE, BSL.C_CURRENCY_ID, DP.STATUS,
+            DP2.STATUS AS DP2_STATUS, BSL.UPDATEDBY, RL.C_REMITTANCELINE_ID,
+            BSL.C_BANKSTATEMENTLINE_ID
+          FROM C_REMITTANCE_TYPE RT, C_REMITTANCE R, C_REMITTANCELINE RL,
+            C_BANKSTATEMENTLINE BSL, C_DEBT_PAYMENT DP, C_DEBT_PAYMENT DP2
+          WHERE R.C_REMITTANCE_ID=RL.C_REMITTANCE_ID
+            AND RT.C_REMITTANCE_TYPE_ID=R.C_REMITTANCE_TYPE_ID
+            AND RL.C_DEBT_PAYMENT_CANCELLED=BSL.C_DEBT_PAYMENT_ID
+            AND BSL.C_DEBT_PAYMENT_ID=DP.C_DEBT_PAYMENT_ID
+            AND RL.C_DEBT_PAYMENT_ID=DP2.C_DEBT_PAYMENT_ID
+            AND BSL.C_BANKSTATEMENT_ID=v_Record_ID
+            AND RL.RETURNED='N'
+          )
+        LOOP
+          --Create DPManagement
           v_DPManagementDocType_ID:=Ad_Get_DocType(Cur_ManagementLines1.AD_Client_ID, Cur_ManagementLines1.AD_Org_ID, 'DPM') ;
-          Ad_Sequence_Next('C_DP_Management', Cur_ManagementLines1.AD_Org_ID, v_DPMId) ; 
-          Ad_Sequence_Doctype(v_DPManagementDocType_ID, v_Record_ID, 'Y', v_DocumentNo) ; 
-          IF(v_DocumentNo IS NULL) THEN 
-            Ad_Sequence_Doc('DocumentNo_C_DP_Management', Cur_ManagementLines1.AD_Client_ID, 'Y', v_DocumentNo) ; 
-          END IF; 
-          INSERT 
-          INTO C_DP_Management 
-            ( 
-              C_DP_MANAGEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, 
-              CREATED, CREATEDBY, UPDATED, UPDATEDBY, 
-              DOCUMENTNO, DATETRX, C_DOCTYPE_ID, DATEACCT, 
-              C_Currency_ID 
-            ) 
-            VALUES 
-            ( 
-              v_DPMId, Cur_ManagementLines1.ad_Client_Id, Cur_ManagementLines1.AD_Org_Id, 'Y', 
-              now(), Cur_ManagementLines1.UPDATEDBY, now(), Cur_ManagementLines1.UPDATEDBY, 
-              v_DocumentNo, Cur_ManagementLines1.VALUTADATE, v_DPManagementDocType_ID, Cur_ManagementLines1.DATEACCT, 
-              Cur_ManagementLines1.C_Currency_ID 
-            ) 
-            ; 
-          Ad_Sequence_Next('C_DP_ManagementLine', Cur_ManagementLines1.AD_Org_ID, v_DPMLineId) ; 
-          INSERT 
-          INTO C_DP_ManagementLine 
-            ( 
-              C_DP_MANAGEMENTLINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, 
-              CREATED, CREATEDBY, UPDATED, UPDATEDBY, 
-              C_DP_MANAGEMENT_ID, STATUS_FROM, STATUS_TO, C_DEBT_PAYMENT_ID 
-            ) 
-            VALUES 
-            ( 
-              v_DPMLineId, Cur_ManagementLines1.ad_Client_Id, Cur_ManagementLines1.AD_Org_Id, 'Y', 
-              now(), Cur_ManagementLines1.UPDATEDBY, now(), Cur_ManagementLines1.UPDATEDBY, 
-              v_DPMId, Cur_ManagementLines1.DP2_STATUS, Cur_ManagementLines1.STATUS_RETURNED, Cur_ManagementLines1.DP2 
-            ) 
-            ; 
-          Ad_Sequence_Next('C_DP_ManagementLine', Cur_ManagementLines1.AD_Org_ID, v_DPMLineId) ; 
-          INSERT 
-          INTO C_DP_ManagementLine 
-            ( 
-              C_DP_MANAGEMENTLINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, 
-              CREATED, CREATEDBY, UPDATED, UPDATEDBY, 
-              C_DP_MANAGEMENT_ID, STATUS_FROM, STATUS_TO, C_DEBT_PAYMENT_ID 
-            ) 
-            VALUES 
-            ( 
-              v_DPMLineId, Cur_ManagementLines1.ad_Client_Id, Cur_ManagementLines1.AD_Org_Id, 'Y', 
-              now(), Cur_ManagementLines1.UPDATEDBY, now(), Cur_ManagementLines1.UPDATEDBY, 
-              v_DPMId, Cur_ManagementLines1.STATUS, Cur_ManagementLines1.STATUS_RETURNED, Cur_ManagementLines1.DP1 
-            ) 
-            ; 
-          UPDATE C_REMITTANCELINE 
-            SET RETURNED='Y' 
-          WHERE C_REMITTANCELINE_ID=Cur_ManagementLines1.C_REMITTANCELINE_ID; 
-          UPDATE C_BANKSTATEMENTLINE 
-            SET C_DP_MANAGEMENT_ID=v_DPMId 
-          WHERE C_BANKSTATEMENTLINE_ID=Cur_ManagementLines1.C_BANKSTATEMENTLINE_ID; 
-          C_DP_MANAGEMENT_POST(null, v_DPMId) ; 
-        END LOOP; 
-        v_ResultStr:='GettingBankAccountInfo'; 
-        SELECT ba.C_Currency_ID, 
-          bs.StatementDate 
-        INTO v_BA_Currency_ID, 
-          v_BS_Date 
-        FROM C_BANKACCOUNT ba, 
-          C_BANKSTATEMENT bs 
-        WHERE ba.C_BankAccount_ID=bs.C_BankAccount_ID 
-          AND bs.C_BankStatement_ID=v_Record_ID; 
+          Ad_Sequence_Next('C_DP_Management', Cur_ManagementLines1.AD_Org_ID, v_DPMId) ;
+          Ad_Sequence_Doctype(v_DPManagementDocType_ID, v_Record_ID, 'Y', v_DocumentNo) ;
+          IF(v_DocumentNo IS NULL) THEN
+            Ad_Sequence_Doc('DocumentNo_C_DP_Management', Cur_ManagementLines1.AD_Client_ID, 'Y', v_DocumentNo) ;
+          END IF;
+          INSERT
+          INTO C_DP_Management
+            (
+              C_DP_MANAGEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
+              CREATED, CREATEDBY, UPDATED, UPDATEDBY,
+              DOCUMENTNO, DATETRX, C_DOCTYPE_ID, DATEACCT,
+              C_Currency_ID
+            )
+            VALUES
+            (
+              v_DPMId, Cur_ManagementLines1.ad_Client_Id, Cur_ManagementLines1.AD_Org_Id, 'Y',
+              now(), Cur_ManagementLines1.UPDATEDBY, now(), Cur_ManagementLines1.UPDATEDBY,
+              v_DocumentNo, Cur_ManagementLines1.VALUTADATE, v_DPManagementDocType_ID, Cur_ManagementLines1.DATEACCT,
+              Cur_ManagementLines1.C_Currency_ID
+            )
+            ;
+          Ad_Sequence_Next('C_DP_ManagementLine', Cur_ManagementLines1.AD_Org_ID, v_DPMLineId) ;
+          INSERT
+          INTO C_DP_ManagementLine
+            (
+              C_DP_MANAGEMENTLINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
+              CREATED, CREATEDBY, UPDATED, UPDATEDBY,
+              C_DP_MANAGEMENT_ID, STATUS_FROM, STATUS_TO, C_DEBT_PAYMENT_ID
+            )
+            VALUES
+            (
+              v_DPMLineId, Cur_ManagementLines1.ad_Client_Id, Cur_ManagementLines1.AD_Org_Id, 'Y',
+              now(), Cur_ManagementLines1.UPDATEDBY, now(), Cur_ManagementLines1.UPDATEDBY,
+              v_DPMId, Cur_ManagementLines1.DP2_STATUS, Cur_ManagementLines1.STATUS_RETURNED, Cur_ManagementLines1.DP2
+            )
+            ;
+          Ad_Sequence_Next('C_DP_ManagementLine', Cur_ManagementLines1.AD_Org_ID, v_DPMLineId) ;
+          INSERT
+          INTO C_DP_ManagementLine
+            (
+              C_DP_MANAGEMENTLINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
+              CREATED, CREATEDBY, UPDATED, UPDATEDBY,
+              C_DP_MANAGEMENT_ID, STATUS_FROM, STATUS_TO, C_DEBT_PAYMENT_ID
+            )
+            VALUES
+            (
+              v_DPMLineId, Cur_ManagementLines1.ad_Client_Id, Cur_ManagementLines1.AD_Org_Id, 'Y',
+              now(), Cur_ManagementLines1.UPDATEDBY, now(), Cur_ManagementLines1.UPDATEDBY,
+              v_DPMId, Cur_ManagementLines1.STATUS, Cur_ManagementLines1.STATUS_RETURNED, Cur_ManagementLines1.DP1
+            )
+            ;
+          UPDATE C_REMITTANCELINE
+            SET RETURNED='Y'
+          WHERE C_REMITTANCELINE_ID=Cur_ManagementLines1.C_REMITTANCELINE_ID;
+          UPDATE C_BANKSTATEMENTLINE
+            SET C_DP_MANAGEMENT_ID=v_DPMId
+          WHERE C_BANKSTATEMENTLINE_ID=Cur_ManagementLines1.C_BANKSTATEMENTLINE_ID;
+          C_DP_MANAGEMENT_POST(null, v_DPMId) ;
+        END LOOP;
+        v_ResultStr:='GettingBankAccountInfo';
+        SELECT ba.C_Currency_ID,
+          bs.StatementDate
+        INTO v_BA_Currency_ID,
+          v_BS_Date
+        FROM C_BANKACCOUNT ba,
+          C_BANKSTATEMENT bs
+        WHERE ba.C_BankAccount_ID=bs.C_BankAccount_ID
+          AND bs.C_BankStatement_ID=v_Record_ID;
         v_SettlementDocType_ID:=Ad_Get_DocType(v_AD_Client_ID, v_AD_Org_ID, 'STT') ;
-        FOR CUR_BSLINES_DATES IN 
-          (SELECT DISTINCT bsl.DATEACCT 
-          FROM C_BANKSTATEMENTLINE bsl, 
-            C_DEBT_PAYMENT dp 
-          WHERE bsl.C_BankStatement_ID=v_Record_ID 
-            AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID 
-            AND C_Debt_Payment_Status(dp.C_SETTLEMENT_CANCEL_ID, dp.Cancel_Processed, dp.Generate_Processed, dp.IsPaid, dp.IsValid, dp.C_CashLine_ID, dp.C_BankStatementLine_ID)='P' 
-          ) 
-        LOOP 
-          Ad_Sequence_Next('C_Settlement', v_Record_ID, v_settlementID) ; 
-          Ad_Sequence_Doctype(v_SettlementDocType_ID, v_Record_ID, 'Y', v_DocumentNo) ; 
-          IF(v_DocumentNo IS NULL) THEN 
-            Ad_Sequence_Doc('DocumentNo_C_Settlement', v_AD_Client_ID, 'Y', v_DocumentNo) ; 
-          END IF; 
-          INSERT 
-          INTO C_SETTLEMENT 
-            ( 
-              C_SETTLEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, 
-              CREATED, CREATEDBY, UPDATED, UPDATEDBY, 
-              DOCUMENTNO, DATETRX, DATEACCT, SETTLEMENTTYPE, 
-             C_DOCTYPE_ID, PROCESSING, PROCESSED, POSTED, 
-              C_CURRENCY_ID, C_PROJECT_ID, C_CAMPAIGN_ID, C_ACTIVITY_ID, 
-              USER1_ID, USER2_ID, CREATEFROM, ISGENERATED 
-            ) 
-          SELECT v_settlementID, 
-            AD_Client_ID, AD_Org_ID, 'Y', now(), 
-            UpdatedBy, now(), UpdatedBy, '*BSP*'||v_DocumentNo, TRUNC(v_BS_Date), 
-            CUR_BSLINES_DATES.DATEACCT, 'B', v_SettlementDocType_ID, 'N', 
-            'N', 'N', v_BA_Currency_ID, NULL, 
-            NULL, NULL, NULL, NULL, 
-            'N', 'Y' 
-          FROM C_BANKSTATEMENT 
-          WHERE C_BankStatement_ID=v_Record_ID; 
-          UPDATE C_DEBT_PAYMENT 
-            SET C_SETTLEMENT_CANCEL_ID=v_settlementID, 
-            IsPaid='Y' 
-          WHERE C_DEBT_PAYMENT.C_Debt_Payment_ID IN 
-            (SELECT C_Debt_Payment_ID 
-            FROM C_BANKSTATEMENTLINE 
-            WHERE C_BankStatement_ID=v_Record_ID 
-              AND DateAcct=CUR_BSLINES_DATES.DATEACCT 
-            ) 
-            AND C_Debt_Payment_Status(C_DEBT_PAYMENT.C_SETTLEMENT_CANCEL_ID, C_DEBT_PAYMENT.Cancel_Processed, C_DEBT_PAYMENT.Generate_Processed, C_DEBT_PAYMENT.IsPaid, C_DEBT_PAYMENT.IsValid, C_DEBT_PAYMENT.C_CashLine_ID, C_DEBT_PAYMENT.C_BankStatementLine_ID)='P'; 
-          C_SETTLEMENT_POST(NULL, v_settlementID) ; 
-        END LOOP; 
-  --Added by PSarobe 
-   EXCEPTION 
-     WHEN OB_exception THEN 
-    IF (SQLERRM LIKE '%@DPAccountdatelaterSettlementdate@') THEN 
-     DBMS_OUTPUT.PUT_LINE(v_ResultStr) ; 
-    SELECT MAX(C_DP_Management.DOCUMENTNO), MAX(C_Bankstatementline.line) 
-    INTO v_documentno_Dp_Management, v_line 
-    FROM C_Bankstatement, C_Bankstatementline, C_DP_Management, C_DP_Managementline 
-    WHERE C_Bankstatement.C_Bankstatement_Id = C_Bankstatementline.C_BANKSTATEMENT_ID 
-    AND C_Bankstatementline.C_DEBT_PAYMENT_ID = C_DP_Managementline.C_DEBT_PAYMENT_ID 
-    AND C_DP_Managementline.C_DP_MANAGEMENT_ID = C_DP_Management.C_DP_MANAGEMENT_ID 
-    AND C_DP_Management.DATEACCT > C_Bankstatementline.DATEACCT 
-    AND C_Bankstatement.C_Bankstatement_Id = v_Record_ID; 
+        FOR CUR_BSLINES_DATES IN
+          (SELECT DISTINCT bsl.DATEACCT
+          FROM C_BANKSTATEMENTLINE bsl,
+            C_DEBT_PAYMENT dp
+          WHERE bsl.C_BankStatement_ID=v_Record_ID
+            AND bsl.C_Debt_Payment_ID=dp.C_Debt_Payment_ID
+            AND C_Debt_Payment_Status(dp.C_SETTLEMENT_CANCEL_ID, dp.Cancel_Processed, dp.Generate_Processed, dp.IsPaid, dp.IsValid, dp.C_CashLine_ID, dp.C_BankStatementLine_ID)='P'
+          )
+        LOOP
+          Ad_Sequence_Next('C_Settlement', v_Record_ID, v_settlementID) ;
+          Ad_Sequence_Doctype(v_SettlementDocType_ID, v_Record_ID, 'Y', v_DocumentNo) ;
+          IF(v_DocumentNo IS NULL) THEN
+            Ad_Sequence_Doc('DocumentNo_C_Settlement', v_AD_Client_ID, 'Y', v_DocumentNo) ;
+          END IF;
+          INSERT
+          INTO C_SETTLEMENT
+            (
+              C_SETTLEMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
+              CREATED, CREATEDBY, UPDATED, UPDATEDBY,
+              DOCUMENTNO, DATETRX, DATEACCT, SETTLEMENTTYPE,
+             C_DOCTYPE_ID, PROCESSING, PROCESSED, POSTED,
+              C_CURRENCY_ID, C_PROJECT_ID, C_CAMPAIGN_ID, C_ACTIVITY_ID,
+              USER1_ID, USER2_ID, CREATEFROM, ISGENERATED
+            )
+          SELECT v_settlementID,
+            AD_Client_ID, AD_Org_ID, 'Y', now(),
+            UpdatedBy, now(), UpdatedBy, '*BSP*'||v_DocumentNo, TRUNC(v_BS_Date),
+            CUR_BSLINES_DATES.DATEACCT, 'B', v_SettlementDocType_ID, 'N',
+            'N', 'N', v_BA_Currency_ID, NULL,
+            NULL, NULL, NULL, NULL,
+            'N', 'Y'
+          FROM C_BANKSTATEMENT
+          WHERE C_BankStatement_ID=v_Record_ID;
+          UPDATE C_DEBT_PAYMENT
+            SET C_SETTLEMENT_CANCEL_ID=v_settlementID,
+            IsPaid='Y'
+          WHERE C_DEBT_PAYMENT.C_Debt_Payment_ID IN
+            (SELECT C_Debt_Payment_ID
+            FROM C_BANKSTATEMENTLINE
+            WHERE C_BankStatement_ID=v_Record_ID
+              AND DateAcct=CUR_BSLINES_DATES.DATEACCT
+            )
+            AND C_Debt_Payment_Status(C_DEBT_PAYMENT.C_SETTLEMENT_CANCEL_ID, C_DEBT_PAYMENT.Cancel_Processed, C_DEBT_PAYMENT.Generate_Processed, C_DEBT_PAYMENT.IsPaid, C_DEBT_PAYMENT.IsValid, C_DEBT_PAYMENT.C_CashLine_ID, C_DEBT_PAYMENT.C_BankStatementLine_ID)='P';
+          C_SETTLEMENT_POST(NULL, v_settlementID) ;
+        END LOOP;
+  --Added by PSarobe
+   EXCEPTION
+     WHEN OB_exception THEN
+    IF (SQLERRM LIKE '%@DPAccountdatelaterSettlementdate@') THEN
+     DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
+    SELECT MAX(C_DP_Management.DOCUMENTNO), MAX(C_Bankstatementline.line)
+    INTO v_documentno_Dp_Management, v_line
+    FROM C_Bankstatement, C_Bankstatementline, C_DP_Management, C_DP_Managementline
+    WHERE C_Bankstatement.C_Bankstatement_Id = C_Bankstatementline.C_BANKSTATEMENT_ID
+    AND C_Bankstatementline.C_DEBT_PAYMENT_ID = C_DP_Managementline.C_DEBT_PAYMENT_ID
+    AND C_DP_Managementline.C_DP_MANAGEMENT_ID = C_DP_Management.C_DP_MANAGEMENT_ID
+    AND C_DP_Management.DATEACCT > C_Bankstatementline.DATEACCT
+    AND C_Bankstatement.C_Bankstatement_Id = v_Record_ID;
      RAISE_APPLICATION_ERROR(-20000, '@Inline@'||v_line||' '||'@debtpayment@'||'@DPDebtPaymentManaged@'||v_documentno_Dp_Management||' '||'@DPAccountdatelaterBankstatementlinedate@') ;
-    ELSE 
-     DBMS_OUTPUT.PUT_LINE(v_ResultStr); 
+    ELSE
+     DBMS_OUTPUT.PUT_LINE(v_ResultStr);
      RAISE_APPLICATION_ERROR(-20000, SUBSTR(SQLERRM,12,2000)) ;
-    END IF; 
-    WHEN OTHERS THEN 
-       DBMS_OUTPUT.PUT_LINE(v_ResultStr) ; 
+    END IF;
+    WHEN OTHERS THEN
+       DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
    RAISE;
-      END; 
-    END IF;--FINISH_PROCESS 
-    IF(NOT FINISH_PROCESS) THEN 
-      /** 
-      *  Update Balances + De-Activate + Conciliate Debt_Payments 
-      */ 
-      DECLARE 
-        v_Total NUMBER:=0; 
-        v_Currency_ID NUMBER(10):=NULL; 
-        -- Lines 
-        Cur_Lines RECORD; 
-      BEGIN 
-        -- Calculate Total 
-        FOR Cur_Lines IN 
-          (SELECT * FROM C_BANKSTATEMENTLINE WHERE C_BankStatement_ID=v_Record_ID) 
-        LOOP 
-          v_ResultStr:='GettingTrxCurrency'; 
-          -- Get Debt_Payment Currency and conciliate Debt/Payments 
-          IF(Cur_Lines.C_Debt_Payment_ID IS NOT NULL) THEN 
-            UPDATE C_DEBT_PAYMENT 
-              SET C_BankStatementLine_ID=Cur_Lines.C_BankStatementLine_ID 
-            WHERE C_Debt_Payment_ID=Cur_Lines.C_Debt_Payment_ID; 
-            /* Lines are converted to the bankAccount currency, this is not necesary 
-      SELECT C_Currency_ID 
-            INTO v_Currency_ID 
-            FROM C_DEBT_PAYMENT 
-            WHERE C_Debt_Payment_ID=Cur_Lines.C_Debt_Payment_ID; 
-      */ 
-          END IF; 
-     v_Total:=v_Total + Cur_Lines.StmtAmt; 
-     /* Lines are converted to the bankAccount currency, this is not necesary 
-          -- Assume BankAccount Currency for Charge 
-          IF(v_Currency_ID IS NULL) THEN 
-            v_Currency_ID:=v_BA_Currency_ID; 
-          END IF; 
-          v_ResultStr:='CalculatingSum'; 
-          IF(v_Currency_ID<>v_BA_Currency_ID) THEN 
-            v_Total:=v_Total + C_Currency_Convert(Cur_Lines.StmtAmt, v_Currency_ID, v_BA_Currency_ID, v_BS_Date, NULL, Cur_Lines.AD_Client_ID, Cur_Lines.AD_Org_ID) ; 
-          ELSE 
-            v_Total:=v_Total + Cur_Lines.StmtAmt; 
-          END IF; 
-     */ 
-        END LOOP; 
-        -- 
-        DBMS_OUTPUT.PUT_LINE('BankStatement Complete - Total=' || v_Total) ; 
-        v_ResultStr:='UpdatingRecord'; 
-        UPDATE C_BANKSTATEMENT 
-          SET StatementDifference=v_Total, 
-          EndingBalance=COALESCE(BeginningBalance, 0) + v_Total, 
-          Processed='Y', 
-          Updated=now() 
-        WHERE C_BankStatement_ID=v_Record_ID; 
-      END; 
-    END IF;--FINISH_PROCESS 
-    --<<FINISH_PROCESS>> 
-    --  Update AD_PInstance 
-    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ; 
-    AD_UPDATE_PINSTANCE(p_PInstance_ID, v_User, 'N', 1, v_Message) ; 
-    RETURN; 
-  END; --BODY 
-EXCEPTION 
-WHEN OTHERS THEN 
-  ROLLBACK; 
-  v_ResultStr:= '@ERROR=' || SQLERRM; 
-  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ; 
-  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ; 
-  RETURN; 
+      END;
+    END IF;--FINISH_PROCESS
+    IF(NOT FINISH_PROCESS) THEN
+      /**
+      *  Update Balances + De-Activate + Conciliate Debt_Payments
+      */
+      DECLARE
+        v_Total NUMBER:=0;
+        v_Currency_ID NUMBER(10):=NULL;
+        -- Lines
+        Cur_Lines RECORD;
+      BEGIN
+        -- Calculate Total
+        FOR Cur_Lines IN
+          (SELECT * FROM C_BANKSTATEMENTLINE WHERE C_BankStatement_ID=v_Record_ID)
+        LOOP
+          v_ResultStr:='GettingTrxCurrency';
+          -- Get Debt_Payment Currency and conciliate Debt/Payments
+          IF(Cur_Lines.C_Debt_Payment_ID IS NOT NULL) THEN
+            UPDATE C_DEBT_PAYMENT
+              SET C_BankStatementLine_ID=Cur_Lines.C_BankStatementLine_ID
+            WHERE C_Debt_Payment_ID=Cur_Lines.C_Debt_Payment_ID;
+            /* Lines are converted to the bankAccount currency, this is not necesary
+      SELECT C_Currency_ID
+            INTO v_Currency_ID
+            FROM C_DEBT_PAYMENT
+            WHERE C_Debt_Payment_ID=Cur_Lines.C_Debt_Payment_ID;
+      */
+          END IF;
+     v_Total:=v_Total + Cur_Lines.StmtAmt;
+     /* Lines are converted to the bankAccount currency, this is not necesary
+          -- Assume BankAccount Currency for Charge
+          IF(v_Currency_ID IS NULL) THEN
+            v_Currency_ID:=v_BA_Currency_ID;
+          END IF;
+          v_ResultStr:='CalculatingSum';
+          IF(v_Currency_ID<>v_BA_Currency_ID) THEN
+            v_Total:=v_Total + C_Currency_Convert(Cur_Lines.StmtAmt, v_Currency_ID, v_BA_Currency_ID, v_BS_Date, NULL, Cur_Lines.AD_Client_ID, Cur_Lines.AD_Org_ID) ;
+          ELSE
+            v_Total:=v_Total + Cur_Lines.StmtAmt;
+          END IF;
+     */
+        END LOOP;
+        --
+        DBMS_OUTPUT.PUT_LINE('BankStatement Complete - Total=' || v_Total) ;
+        v_ResultStr:='UpdatingRecord';
+        UPDATE C_BANKSTATEMENT
+          SET StatementDifference=v_Total,
+          EndingBalance=COALESCE(BeginningBalance, 0) + v_Total,
+          Processed='Y',
+          Updated=now()
+        WHERE C_BankStatement_ID=v_Record_ID;
+      END;
+    END IF;--FINISH_PROCESS
+    --<<FINISH_PROCESS>>
+    --  Update AD_PInstance
+    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
+    AD_UPDATE_PINSTANCE(p_PInstance_ID, v_User, 'N', 1, v_Message) ;
+    RETURN;
+  END; --BODY
+EXCEPTION
+WHEN OTHERS THEN
+  ROLLBACK;
+  v_ResultStr:= '@ERROR=' || SQLERRM;
+  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
+  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
+  RETURN;
 END C_BANKSTATEMENT_POST
 ]]></body>
     </function>
--- a/database/model/functions/C_CALCULATECOST_CATSALARY.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/C_CALCULATECOST_CATSALARY.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -28,12 +28,12 @@
 BEGIN
 
  SELECT COST into vResult
-         FROM  c_salary_category_cost, (SELECT MAX(datefrom) AS datefrom 
+         FROM  c_salary_category_cost, (SELECT MAX(datefrom) AS datefrom
 		                                from c_salary_category_cost
-										where c_salary_category_id= pCatSal 
+										where c_salary_category_id= pCatSal
                                         and datefrom<=pDate
 										order by datefrom desc ) AAA
- WHERE c_salary_category_cost.c_salary_category_id = pCatSal 
+ WHERE c_salary_category_cost.c_salary_category_id = pCatSal
  AND c_salary_category_cost.datefrom = aaa.datefrom;
 
  RETURN vResult;
--- a/database/model/functions/C_CALCULATE_CATSALARY.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/C_CALCULATE_CATSALARY.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -28,14 +28,14 @@
 BEGIN
 
  SELECT c_salary_category_id INTO vResult
- FROM  c_bp_salcategory, (SELECT MAX(datefrom) AS datefrom  
-                          from c_bp_salcategory   
-                          where c_bpartner_id= pCBPartner 
+ FROM  c_bp_salcategory, (SELECT MAX(datefrom) AS datefrom
+                          from c_bp_salcategory
+                          where c_bpartner_id= pCBPartner
                           and datefrom<=pDate
                           order by datefrom desc ) AAA
- WHERE c_bp_salcategory.c_bpartner_id= pCBPartner 
+ WHERE c_bp_salcategory.c_bpartner_id= pCBPartner
  AND c_bp_salcategory.datefrom = aaa.datefrom;
-  
+
  RETURN vResult;
 END C_CALCULATE_CATSALARY
 ]]></body>
--- a/database/model/functions/C_GETWITHHOLDING.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/C_GETWITHHOLDING.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -98,9 +98,9 @@
 
 -- 1) Calcolo la %inps
 if IsIncludedTax = 'Y' then
-   select coalesce(sum(TAXAMT),0) into  TaxAmount from C_invoicetax  
+   select coalesce(sum(TAXAMT),0) into  TaxAmount from C_invoicetax
    where C_TAX_ID= IdTax and C_INVOICE_ID = id_invoice_in;
-      
+
    FOR curTaxInps IN
     (SELECT *
         FROM C_TAX
@@ -110,7 +110,7 @@
         IsWithHoldingTax:=curTaxInps.is_withholdingtax;
     EXIT;
     END LOOP;
-  
+
      if not (IsWithHoldingTax='Y') then
       TaxAmount := 0;
      end if;
--- a/database/model/functions/C_INVOICE_POST.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/C_INVOICE_POST.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -240,7 +240,7 @@
       END IF;
     END IF;--FINISH_PROCESS
     --cbt taxpayment
-    
+
     IF(NOT finish_process) THEN
     IF(v_docaction IN ('VO', 'RE', 'RC')
        AND v_docstatus IN('CO',   'CL')) THEN
@@ -254,7 +254,7 @@
         and tp.processed='Y';
       IF v_aux > 0 THEN
           RAISE_APPLICATION_ERROR(-20615,   '@InvoiceInTaxRegister@');
-      ELSE    
+      ELSE
         delete from c_taxregisterline trl where trl.c_invoicetax_id in
         (select trl.c_invoicetax_id
         FROM c_taxregisterline trl
@@ -262,11 +262,11 @@
         inner join c_taxregister tr on tr.c_taxregister_id= trl.c_taxregister_id
         inner join c_taxpayment tp on tr.c_taxpayment_id=tp.c_taxpayment_id
         WHERE it.c_invoice_id = v_record_id
-        and tp.processed='N');  
+        and tp.processed='N');
       end if;
       end if;
       end if;
-      
+
     --end cbt taxpaymant
     IF(NOT FINISH_PROCESS) THEN
       /**
@@ -1405,7 +1405,7 @@
             SET IsValid='Y'
           WHERE C_INVOICE_ID=v_Record_ID
             AND IsValid!='Y';
-            
+
             -- Is it a Credit Memo:4
           SELECT DocBaseType
           INTO v_TargetDocBaseType
@@ -1413,8 +1413,8 @@
           WHERE C_DocType_ID=v_DocTypeTarget_ID;
           IF v_TargetDocBaseType in ('ARC','APC') THEN
             v_MultiplierARC:=-1;
-          END IF;  
-            
+          END IF;
+
           --Sums debt payments from the order and the ones that have been inserted manually, added by ALO
           SELECT COALESCE(SUM(C_Currency_Round(C_Currency_Convert((Amount + WriteOffAmt)*v_MultiplierARC, C_Currency_ID, v_Currency_ID, v_DateInvoiced, NULL, v_Client_ID, v_Org_ID), v_Currency_ID, NULL)), 0)
           INTO v_totalCash
--- a/database/model/functions/C_TAXPAYMENT_POST.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/C_TAXPAYMENT_POST.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -79,13 +79,13 @@
 v_totalcredit NUMBER;
 
 
-v_acctschema_id NUMBER; 
-v_currency_id NUMBER; 
-v_currencyratetype VARCHAR2(30); 
+v_acctschema_id NUMBER;
+v_currency_id NUMBER;
+v_currencyratetype VARCHAR2(30);
 v_gl_category_id NUMBER;
-v_period_id NUMBER; 
+v_period_id NUMBER;
 
-v_name NVARCHAR2(255); 
+v_name NVARCHAR2(255);
 
 
 
@@ -114,52 +114,52 @@
 
     -- Get Parameter
     DBMS_OUTPUT.PUT_LINE('  v_Record_ID=' || v_record_id);
-    
+
     BEGIN
       -- BODY
-      
-      select dateto, ad_client_id, ad_org_id, createdby, updatedby, generatepayment, c_acctschema_id, c_currency_id, name, C_BPARTNER_ID, processed 
-        into v_date, v_client_id, v_org_id, v_createdby, v_updatedby, v_ispayment, v_acctschema_id, v_currency_id, v_name, v_bpartner_id, v_processed 
+
+      select dateto, ad_client_id, ad_org_id, createdby, updatedby, generatepayment, c_acctschema_id, c_currency_id, name, C_BPARTNER_ID, processed
+        into v_date, v_client_id, v_org_id, v_createdby, v_updatedby, v_ispayment, v_acctschema_id, v_currency_id, v_name, v_bpartner_id, v_processed
         from c_taxpayment
         where c_taxpayment_id=v_record_id;
-        
-      select gl_category_id 
-      into v_gl_category_id 
-      from gl_category where name='Standard';       
-        
-        v_paymentrule := 'T'; 
+
+      select gl_category_id
+      into v_gl_category_id
+      from gl_category where name='Standard';
+
+        v_paymentrule := 'T';
         v_currencyratetype := 'S';
-        
+
       select c_period_id into v_period_id from c_period
       where enddate = (select max(enddate) from c_period where enddate <=v_date);
-      
+
      --start processing
-     
+
      update c_taxpayment
      set processing='Y' where c_taxpayment_id=v_record_id;
-     
+
      --unprocess
      if v_processed='Y' then
       begin
-      
+
       select tp.gl_journal_id ,  gljb.gl_journalbatch_id, tp.c_settlement_id
       into v_gl_journalid, v_gl_journalbatchid, v_settlementid
       from c_taxpayment tp
       inner join gl_journal glj on tp.gl_journal_id=glj.gl_journal_id
       inner join gl_journalbatch gljb on gljb.gl_journalbatch_id=glj.gl_journal_id
       where tp.C_TAXPAYMENT_ID = v_record_id;
-      
+
       update gl_journal set docaction='RE' where gl_journal_id=v_gl_journalid;
       GL_JOURNAL_POST(null, v_gl_journalid);
         update c_taxpayment set gl_journal_id=null where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
         delete from gl_journalline where gl_journal_id=v_gl_journalid;
         delete from gl_journal where gl_journal_id=v_gl_journalid;
         delete from gl_journalbatch where gl_journalbatch_id=v_gl_journalbatchid;
-      
+
       if v_ispayment = 'Y' then
         C_SETTLEMENT_POST(null, v_settlementid);
         update c_taxpayment set c_settlement_id=null where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
-        delete from c_debt_payment_balancing where c_debt_payment_id in 
+        delete from c_debt_payment_balancing where c_debt_payment_id in
         (select c_debt_payment_id from c_debt_payment where c_settlement_generate_id = v_settlementid);
         delete from c_debt_payment where c_settlement_generate_id = v_settlementid;
         delete from c_settlement where c_settlement_id=v_settlementid;
@@ -167,32 +167,32 @@
       end;
        update c_taxpayment set processed='N' where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
       end if;
-     
-     
+
+
    if v_processed='N' then
    begin
-      --gl journal 
+      --gl journal
         ad_sequence_next('GL_JournalBatch', v_record_id, v_gl_journalbatchid);
         ad_sequence_doc('DocumentNo_GL_JournalBatch', v_client_id, 'Y', v_gljbdocumentno);
-        
-        insert 
+
+        insert
         into gl_journalbatch (gl_journalbatch_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby,   documentno, description, postingtype,   datedoc,   dateacct, c_period_id, c_currency_id)
-        values (v_gl_journalbatchid, v_client_id, v_org_id,'Y', now(), v_createdby, now(), v_updatedby, v_gljbdocumentno, v_name, 'A', v_date, v_date, v_period_id, v_currency_id); 
-      
+        values (v_gl_journalbatchid, v_client_id, v_org_id,'Y', now(), v_createdby, now(), v_updatedby, v_gljbdocumentno, v_name, 'A', v_date, v_date, v_period_id, v_currency_id);
+
         v_gl_journaldoctype_id := ad_get_doctype(v_client_id,   v_org_id,   to_char('GLJ'));
         ad_sequence_next('GL_Journal', v_record_id, v_gl_journalid);
         ad_sequence_doctype(v_gl_journaldoctype_id, v_record_id, 'Y', v_gljdocumentno);
-      
-        insert 
+
+        insert
         into gl_journal (gl_journal_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby, c_acctschema_id, c_doctype_id, documentno, docstatus, docaction, isapproved,description, postingtype, gl_category_id,   datedoc,   dateacct, c_period_id, c_currency_id, currencyratetype, gl_journalbatch_id)
-        values (v_gl_journalid, v_client_id, v_org_id,'Y', now(), v_createdby, now(), v_updatedby, v_acctschema_id, v_gl_journaldoctype_id, v_gljdocumentno, 'DR', 'CO', 'Y', v_name, 'A', v_gl_category_id, v_date, v_date, v_period_id, v_currency_id, v_currencyratetype, v_gl_journalbatchid); 
-        
+        values (v_gl_journalid, v_client_id, v_org_id,'Y', now(), v_createdby, now(), v_updatedby, v_acctschema_id, v_gl_journaldoctype_id, v_gljdocumentno, 'DR', 'CO', 'Y', v_name, 'A', v_gl_category_id, v_date, v_date, v_period_id, v_currency_id, v_currencyratetype, v_gl_journalbatchid);
+
       v_line:=0;
-      v_totaldebit:=0; 
+      v_totaldebit:=0;
       v_totalcredit:=0;
-      
+
       for cur_line in
-      (select  
+      (select
       ttl.c_tax_id,
       tt.issotrx,
       case when tt.issotrx='Y' then max(ta.t_due_acct) else max(ta.t_credit_acct) end as acct_id
@@ -201,10 +201,10 @@
       inner join c_tax_acct ta on ta.c_tax_id=ttl.c_tax_id
       where tt.isactive='Y' and ttl.isactive='Y' and ta.isactive='Y'
       group by ttl.c_tax_id, tt.issotrx )
-       
+
       loop --move the sum over
-      
-      select sum(trl.taxamt) 
+
+      select sum(trl.taxamt)
       into v_taxamtfromreglines
       from c_taxregisterline trl
       inner join c_taxregister tr on tr.c_taxregister_id=trl.c_taxregister_id
@@ -212,14 +212,14 @@
       where trl.c_tax_id=cur_line.c_tax_id
       and trt.issotrx=cur_line.issotrx
       and tr.c_taxpayment_id=v_record_id;
-      
+
       ad_sequence_next('GL_JournalLine', v_record_id, v_gl_journallineid);
-      
-         
+
+
       if v_taxamtfromreglines is null then
       v_taxamtfromreglines := 0;
       end if;
-      
+
       if cur_line.issotrx='N'  then
       v_credit := v_taxamtfromreglines;
       v_debit := 0;
@@ -227,30 +227,30 @@
       v_credit := 0;
       v_debit := v_taxamtfromreglines;
       end if;
-      
+
       if v_taxamtfromreglines <> 0 then
       begin
       v_line := v_line + 10;
-      insert 
+      insert
       into gl_journalline(gl_journalline_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby, gl_journal_id, line, c_currency_id, currencyratetype, dateacct, c_validcombination_id, AMTSOURCEDR, AMTSOURCECR, AMTACCTDR, AMTACCTCR)
       values
-      (v_gl_journallineid, v_client_id, v_org_id,'Y', now(), v_createdby, now(), v_updatedby, v_gl_journalid, v_line, v_currency_id, v_currencyratetype, v_date, cur_line.acct_id, v_debit, v_credit, v_debit, v_credit);  
+      (v_gl_journallineid, v_client_id, v_org_id,'Y', now(), v_createdby, now(), v_updatedby, v_gl_journalid, v_line, v_currency_id, v_currencyratetype, v_date, cur_line.acct_id, v_debit, v_credit, v_debit, v_credit);
       end;
       end if;
-      
+
       v_totaldebit := v_totaldebit+v_credit;
       v_totalcredit := v_totalcredit+v_debit;
-      
+
       end loop;
-      
+
       select case when tt.issotrx='Y' then max(glitem_debit_acct) else max(glitem_credit_acct) end, max(tt.c_glitem_id)
       into v_glitem_acct, v_glitem_id
       from c_taxregister_type tt
       inner join c_glitem_acct gia on gia.c_glitem_id=tt.c_glitem_id
       where tt.isactive='Y' and gia.isactive='Y' and tt.issotrx= case when v_totalcredit - v_totaldebit > 0 then 'N' else 'Y' end
       group by tt.issotrx;
-      
-      if v_totalcredit - v_totaldebit > 0 
+
+      if v_totalcredit - v_totaldebit > 0
       then
        v_totalcredit := v_totalcredit - v_totaldebit;
        v_totaldebit := 0;
@@ -258,24 +258,24 @@
        v_totaldebit := v_totaldebit - v_totalcredit;
         v_totalcredit := 0;
         end if;
-      
+
       v_line := v_line + 10;
       ad_sequence_next('GL_JournalLine', v_record_id, v_gl_journallineid);
-     insert 
+     insert
      into gl_journalline(gl_journalline_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby, gl_journal_id,    line, c_currency_id, currencyratetype, dateacct, c_validcombination_id, AMTSOURCEDR, AMTSOURCECR, AMTACCTDR, AMTACCTCR)
                  values (v_gl_journallineid,   v_client_id,      v_org_id,        'Y',     now(), v_createdby,   now(), v_updatedby, v_gl_journalid, v_line, v_currency_id, v_currencyratetype, v_date, v_glitem_acct, v_totaldebit, v_totalcredit, v_totaldebit, v_totalcredit);
-      
+
     GL_JOURNAL_POST(null, v_gl_journalid);
-      
-      UPDATE c_taxpayment 
+
+      UPDATE c_taxpayment
         SET gl_journal_id = v_gl_journalid
         where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
-      
+
       --settlement
-      
-      
+
+
       if v_ispayment='Y' then
-      
+
         v_settlementdoctype_id := ad_get_doctype(v_client_id,   v_org_id,   to_char('STM'));
         ad_sequence_next('C_Settlement', v_record_id, v_settlementid);
         ad_sequence_doctype(v_settlementdoctype_id, v_record_id, 'Y', v_sdocumentno);
@@ -283,7 +283,7 @@
         IF(v_sdocumentno IS NULL) THEN --to do send by mail
         ad_sequence_doc('DocumentNo_C_Settlement', v_client_id, 'Y', v_sdocumentno);
         END IF;
-      
+
         INSERT
                 INTO c_settlement(c_settlement_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby,   documentno,   datetrx,   dateacct,   settlementtype,   c_doctype_id,   processing,   processed,   posted,   createfrom,   isgenerated, c_currency_id)
                 SELECT v_settlementid,
@@ -303,83 +303,83 @@
                   'N',
                   'N',
                   'N',
-                  'N',               
+                  'N',
                   v_currency_id
                 FROM c_taxpayment
                WHERE c_taxpayment_id = v_record_id;
-              
-      
-            
-        select sum(case when  c_taxregister.C_TAXREGISTER_TYPE_ID in 
+
+
+
+        select sum(case when  c_taxregister.C_TAXREGISTER_TYPE_ID in
         (select C_TAXREGISTER_TYPE_ID from c_taxregister_type where c_taxregister_type.ISSOTRX='Y')
         then taxtotalamt
         else -taxtotalamt end ),
-        sum(case when  c_taxregister.C_TAXREGISTER_TYPE_ID in 
+        sum(case when  c_taxregister.C_TAXREGISTER_TYPE_ID in
         (select C_TAXREGISTER_TYPE_ID from c_taxregister_type where c_taxregister_type.ISSOTRX='Y')
         then -lastregaccumamt
         else lastregaccumamt end )
         into v_taxtotalamt, v_prevvatcredit
         from c_taxregister where c_taxregister.C_TAXPAYMENT_ID=v_record_id;
-      
+
         if v_prevvatcredit < 0 then v_prevvatcredit := 0;
         end if;
         v_paymentamt := v_taxtotalamt - v_prevvatcredit;
-   
-        
-      if v_paymentamt <=0 
-      then 
+
+
+      if v_paymentamt <=0
+      then
       begin
       v_isreceipt:='Y';
       v_paymentamt:=(-1)*v_paymentamt;
       v_paymentcreditamt  := v_paymentamt;
       v_paymentdebitamt := 0;
       end;
-      else 
+      else
       begin
-      v_isreceipt:='N';  
+      v_isreceipt:='N';
       v_paymentcreditamt  := 0;
       v_paymentdebitamt := v_paymentamt;
       end;
       end if;
-    
-      
+
+
         ad_sequence_next('C_Debt_Payment', v_record_id, v_debtpaymentid);
-      
+
         INSERT
          INTO c_debt_payment(c_debt_payment_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby,   isreceipt,   c_settlement_cancel_id,   c_settlement_generate_id,   description,   c_invoice_id,   c_bpartner_id,   c_currency_id,   c_cashline_id,   c_bankaccount_id,   c_cashbook_id,   paymentrule,   ispaid,   amount,   writeoffamt,   dateplanned,   ismanual,   isvalid,   c_bankstatementline_id,   changesettlementcancel,   cancel_processed,   generate_processed,   c_project_id,   status,   status_initial)
           VALUES(v_debtpaymentid,   v_client_id,   v_org_id,   'Y',   now(),   v_createdby,   now(),   v_updatedby,   v_isreceipt,   NULL,   v_settlementid, v_name,   NULL,   v_bpartner_id,   v_currency_id,   NULL,   NULL,   NULL,   v_paymentrule,   'N',  v_paymentamt ,   0,   v_date,   'Y',   'Y',   NULL,   'N',   'N',   'Y',   null,   'DE',   'DE');
-      
- 
+
+
       ad_sequence_next('C_Debt_Payment_Balancing', v_record_id, v_debtpaymentbalancingid);
-      
+
        insert
        into c_debt_payment_balancing(c_debt_payment_balancing_id,   ad_client_id,   ad_org_id,   isactive,   created,   createdby,   updated,   updatedby, c_debt_payment_id, AMOUNTDEBIT, AMOUNTCREDIT, C_GLITEM_ID)
       values(v_debtpaymentbalancingid,   v_client_id,   v_org_id,   'Y',   now(),   v_createdby,   now(),   v_updatedby, v_debtpaymentid, v_paymentdebitamt, v_paymentcreditamt, v_glitem_id);
-       
-       
 
-       
+
+
+
        C_SETTLEMENT_POST(null, v_settlementid);
-        
-       UPDATE c_taxpayment 
-        SET c_settlement_id = v_settlementid       
+
+       UPDATE c_taxpayment
+        SET c_settlement_id = v_settlementid
         where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
-        
-        
-       
-      end if; 
-      
-         UPDATE c_taxpayment 
-        SET processed = 'Y'       
-        where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;    
+
+
+
+      end if;
+
+         UPDATE c_taxpayment
+        SET processed = 'Y'
+        where c_taxpayment.C_TAXPAYMENT_ID = v_record_id;
      END;
-    
- end if;   
- 
+
+ end if;
+
  -- stop processing
   update c_taxpayment
      set processing='N' where c_taxpayment_id=v_record_id;
- 
+
  end;
      IF(p_pinstance_id IS NOT NULL) THEN
     --  Update AD_PInstance
@@ -388,7 +388,7 @@
     ELSE
     DBMS_OUTPUT.PUT_LINE('--<<C_TaxPayment_Post finished>> ' || v_message);
     END IF;
-     
+
      RETURN;
 END C_TAXPAYMENT_POST
 ]]></body>
--- a/database/model/functions/FACT_ACCT_RESET.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/FACT_ACCT_RESET.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -161,7 +161,7 @@
               ELSE
                 v_DateColumn:='DATEACCT';
               END IF;
-              v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'', Processing=''N'' WHERE AD_Client_ID='  || Cur_Clients.AD_Client_ID  
+              v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'', Processing=''N'' WHERE AD_Client_ID='  || Cur_Clients.AD_Client_ID
         || ' AND (Posted<>''N'' OR Posted IS NULL OR Processing<>''N'' OR Processing IS NULL) AND '   ||
         Cur_Tables.TableName||'_ID = '||Cur_Fact_Acct.Record_ID;
               -- DBMS_OUTPUT.PUT_LINE('  executing: ' || v_Cmd);
@@ -192,7 +192,7 @@
               v_Deleted:=v_Deleted + v_rowcount;
               DBMS_OUTPUT.PUT_LINE('  deleted=' || v_rowcount) ;
             END LOOP;
-        v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'', Processing=''N'' WHERE AD_Client_ID='  || Cur_Clients.AD_Client_ID  
+        v_Cmd:='UPDATE ' || Cur_Tables.TableName  || ' SET Posted=''N'', Processing=''N'' WHERE AD_Client_ID='  || Cur_Clients.AD_Client_ID
         || ' 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 ||
         ' AND RECORD_ID = ' || Cur_Tables.TableName || '_ID AND AD_CLIENT_ID =' || Cur_Clients.AD_Client_ID || ' )';
             -- DBMS_OUTPUT.PUT_LINE('  executing: ' || v_Cmd);
--- a/database/model/functions/GENERATEPOFROMPROJECT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/GENERATEPOFROMPROJECT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -74,7 +74,7 @@
       v_Discount NUMBER;
       v_Tax_ID NUMBER;
       v_M_PriceList_Version_ID NUMBER;
-      
+
     TYPE RECORD IS REF CURSOR;
       Cur_SO RECORD;
       Cur_SOLINES RECORD;
@@ -128,29 +128,29 @@
         ELSIF Cur_SO.SALESREP_ID IS NULL THEN
           RAISE_APPLICATION_ERROR(-20000, '@ProjectSalesRepNotFound@'||'.');
         END IF;
-        
+
         v_C_DOCTYPE_ID:=Ad_Get_DocType(Cur_SO.AD_Client_ID, Cur_SO.AD_Org_ID, 'POO') ;
         AD_Sequence_DocType(v_C_DOCTYPE_ID, Cur_SO.AD_Client_ID, 'Y', v_DocumentNo) ;
         IF(v_DocumentNo IS NULL) THEN
           AD_Sequence_Doc('DocumentNo_C_Order', Cur_SO.AD_Client_ID, 'Y', v_DocumentNo) ;
         END IF;
-        
+
         -- Get Business Partner Ship Location
         v_BPartner_Location_ID := C_GetBPLocationID(Cur_SO.C_BPartner_ID, 'S') ;
         IF (v_BPartner_Location_ID IS NULL) THEN
           RAISE_APPLICATION_ERROR(-20000, '@ThebusinessPartner@'||' '||' @ShiptoNotdefined@'||'.');
         END IF;
-        
+
         -- Get Business Partner Bill Location
         v_Billto_ID := C_GetBPLocationID(Cur_SO.C_BPartner_ID, 'B') ;
         IF (v_Billto_ID IS NULL) THEN
           RAISE_APPLICATION_ERROR(-20000, '@ThebusinessPartner@'||' '||' @BillToNotdefined@'||'.');
         END IF;
-        
+
         -- Get next C_Order_ID
         Ad_Sequence_Next('C_Order', Cur_SO.AD_CLIENT_ID, v_C_Order_ID) ;
         v_ResultStr:='C_ORDER_ID - ' || v_C_Order_ID;
-        
+
         INSERT
         INTO C_ORDER
           (
@@ -181,21 +181,21 @@
             TRUNC(now(), 'DD'), Cur_SO.DESCRIPTION
           )
           ;
-        
+
         -- Select the price list version that a applies for the price list of the header
         SELECT Get_Pricelist_Version(Cur_SO.M_PriceList_ID, TRUNC(now(), 'DD'))
         INTO v_M_PriceList_Version_ID
-        FROM DUAL;        
+        FROM DUAL;
         IF (v_M_PriceList_Version_ID IS NULL) THEN
           RAISE_APPLICATION_ERROR(-20000, '@PriceListVersionNotFound@'||'.');
-        ELSE        
+        ELSE
          -- Select products, quantities, sequence numbers, descriptions and unit prices of the project
             -- In both cases, if no unit price has been defined for a product,
             -- price is taken from the price list of the project.
             -- And if no price is defined in the price list, price is set to 0.
           FOR Cur_SOLINES IN
             (
-            SELECT pl.LINE AS SEQNO, pl.PRODUCT_DESCRIPTION AS DESCRIPTION, pl.M_PRODUCT_ID, 
+            SELECT pl.LINE AS SEQNO, pl.PRODUCT_DESCRIPTION AS DESCRIPTION, pl.M_PRODUCT_ID,
               pl.PLANNEDQTY AS QTY, pl.PLANNEDPOPRICE AS PRICEACTUAL, pl.C_TAX_ID
             FROM C_PROJECTLINE pl, C_PROJECT_VENDOR  pv
             WHERE pv.C_PROJECT_VENDOR_ID = v_Record_ID
@@ -204,8 +204,8 @@
               AND pl.IsActive = 'Y'
             ORDER BY SEQNO ASC
             )
-          LOOP                    
-            
+          LOOP
+
             -- Take StdPrice, PriceList and PriceLimit from Price List Version
             SELECT COUNT(*)
             INTO v_Size
@@ -217,7 +217,7 @@
               AND p.M_Product_ID=Cur_SOLINES.M_PRODUCT_ID
               AND pv.M_PriceList_Version_ID=v_M_PriceList_Version_ID
               AND pl.C_Currency_ID=Cur_SO.C_CURRENCY_ID;
-            IF (v_Size>0) THEN 
+            IF (v_Size>0) THEN
               SELECT Bom_Pricestd(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceStd,
                 Bom_Pricelist(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceList,
                 Bom_Pricelimit(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceLimit,
@@ -238,32 +238,32 @@
               v_PriceLimit := NULL;
               v_C_UOM_ID := NULL;
             END IF;
-            
+
             -- Calculate Price Actual
             IF (Cur_SOLINES.priceactual=0) THEN
               Cur_SOLINES.priceactual:=NULL;
             END IF;
-            v_PriceActual := COALESCE(Cur_SOLINES.priceactual,M_Get_Offers_Price(now(), Cur_SO.C_BPARTNER_ID, Cur_SOLINES.M_PRODUCT_ID, v_PriceStd, Cur_SOLINES.Qty, Cur_SO.M_PRICELIST_ID),0);           
-            
+            v_PriceActual := COALESCE(Cur_SOLINES.priceactual,M_Get_Offers_Price(now(), Cur_SO.C_BPARTNER_ID, Cur_SOLINES.M_PRODUCT_ID, v_PriceStd, Cur_SOLINES.Qty, Cur_SO.M_PRICELIST_ID),0);
+
             IF (v_PriceStd IS NULL) THEN
              v_PriceStd :=  v_PriceActual ;
             END IF;
-            
+
             IF (v_PriceList IS NULL) THEN
               v_PriceList :=  v_PriceActual ;
             END IF;
-            
+
             IF (v_PriceLimit IS NULL) THEN
               v_PriceLimit :=  v_PriceActual ;
             END IF;
-            
+
             IF (v_PriceList = 0) THEN
                v_Discount := 0 ;
             ELSE
               -- Calculate rounded discount
               v_Discount :=ROUND((v_PriceList-v_PriceActual) / v_PriceList*100, 2);
             END IF;
-            
+
             IF (v_C_UOM_ID IS NULL) THEN
               SELECT P.C_UOM_ID
               INTO v_UOM
@@ -272,17 +272,17 @@
             ELSE
               v_UOM := v_C_UOM_ID;
             END IF;
-            
+
             IF (Cur_SOLINES.C_TAX_ID IS NULL) THEN
               v_Tax_ID:= C_Gettax(Cur_SOLINES.M_PRODUCT_ID, TRUNC(now(), 'DD'), Cur_SO.AD_ORG_ID, Cur_SO.M_WAREHOUSE_ID, v_BPartner_Location_ID, v_BPartner_Location_ID, Cur_SO.C_PROJECT_ID, 'Y') ;
             ELSE
               v_Tax_ID:=Cur_SOLINES.C_TAX_ID;
             END IF;
-            
+
             -- Get next C_OrderLine_ID
             Ad_Sequence_Next('C_OrderLine', Cur_SO.AD_CLIENT_ID, v_C_OrderLine_ID) ;
             v_ResultStr:='C_OrderLine_ID - ' || v_C_OrderLine_ID;
-            
+
             INSERT
             INTO C_ORDERLINE
               (
@@ -314,10 +314,10 @@
                 v_Discount, v_PriceLimit, NULL, v_PriceActual * Cur_SOLINES.Qty,
                 NULL, 'N', v_PriceStd
               )
-              ;              
+              ;
           END LOOP;
         END IF;
-        
+
         IF v_Message IS NOT NULL THEN
           v_Message:=v_Message || ', ';
         END IF;
--- a/database/model/functions/GENERATESOFROMPROJECT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/GENERATESOFROMPROJECT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -71,11 +71,11 @@
       v_M_PriceList_ID NUMBER;
       v_Billto_ID NUMBER;
       v_InvoiceRule CHAR;
-      v_M_PriceList_Version_ID NUMBER;    
+      v_M_PriceList_Version_ID NUMBER;
       v_PriceActual NUMBER;
       v_Discount NUMBER;
       v_Tax_ID NUMBER;
-      
+
     TYPE RECORD IS REF CURSOR;
       Cur_SO RECORD;
       Cur_SOLINES RECORD;
@@ -111,24 +111,24 @@
         IF (v_Billto_ID IS NULL) THEN
           v_Billto_ID := C_GetBPLocationID(Cur_SO.C_BPartner_ID, 'B') ;
         END IF;
-        
+
         SELECT InvoiceRule INTO v_InvoiceRule
         FROM C_BPARTNER
         WHERE C_BPartner_ID = Cur_SO.C_BPARTNER_ID;
         IF (v_InvoiceRule IS NULL) THEN
            RAISE_APPLICATION_ERROR(-20000, '@ThebusinessPartner@'||' '||' @InvoiceRuleNotdefined@'||'.');
         END IF;
-        
+
         v_C_DOCTYPE_ID:=Ad_Get_DocType(Cur_SO.AD_Client_ID, Cur_SO.AD_Org_ID, 'SOO', 'SO') ;
         AD_Sequence_DocType(v_C_DOCTYPE_ID, Cur_SO.AD_Client_ID, 'Y', v_DocumentNo) ;
         IF(v_DocumentNo IS NULL) THEN
           AD_Sequence_Doc('DocumentNo_C_Order', Cur_SO.AD_Client_ID, 'Y', v_DocumentNo) ;
         END IF;
-        
+
         -- Get next C_Order_ID
         Ad_Sequence_Next('C_Order', Cur_SO.AD_CLIENT_ID, v_C_Order_ID) ;
         v_ResultStr:='C_ORDER_ID - ' || v_C_Order_ID;
-        
+
         INSERT
         INTO C_ORDER
           (
@@ -157,21 +157,21 @@
              'N', TRUNC(now(), 'DD')
           )
           ;
-        
+
         -- Select the price list version that a applies for the price list of the header
         SELECT Get_Pricelist_Version(Cur_SO.M_PriceList_ID, TRUNC(now(), 'DD'))
         INTO v_M_PriceList_Version_ID
-        FROM DUAL;        
+        FROM DUAL;
         IF (v_M_PriceList_Version_ID IS NULL) THEN
           RAISE_APPLICATION_ERROR(-20000, '@PriceListVersionNotFound@'||'.');
-        ELSE        
+        ELSE
          -- Select products, quantities, sequence numbers, descriptions and unit prices of the project
             -- In both cases, if no unit price has been defined for a product,
             -- price is taken from the price list of the project.
             -- And if no price is defined in the price list, price is set to 0.
           FOR Cur_SOLINES IN
             (
-            SELECT pl.LINE AS SEQNO, pl.PRODUCT_DESCRIPTION AS DESCRIPTION, pl.M_PRODUCT_ID, 
+            SELECT pl.LINE AS SEQNO, pl.PRODUCT_DESCRIPTION AS DESCRIPTION, pl.M_PRODUCT_ID,
               pl.PLANNEDQTY AS QTY, pl.PLANNEDPRICE AS PRICEACTUAL, pl.C_TAX_ID
             FROM C_PROJECTLINE pl
             WHERE pl.C_PROJECT_ID = v_Record_ID
@@ -179,8 +179,8 @@
               AND pl.IsActive = 'Y'
             ORDER BY SEQNO ASC
             )
-          LOOP                    
-            
+          LOOP
+
             -- Take StdPrice, PriceList and PriceLimit from Price List Version
             SELECT COUNT(*)
             INTO v_Size
@@ -192,7 +192,7 @@
               AND p.M_Product_ID=Cur_SOLINES.M_PRODUCT_ID
               AND pv.M_PriceList_Version_ID=v_M_PriceList_Version_ID
               AND pl.C_Currency_ID=Cur_SO.C_CURRENCY_ID;
-            IF (v_Size>0) THEN 
+            IF (v_Size>0) THEN
               SELECT Bom_Pricestd(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceStd,
                 Bom_Pricelist(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceList,
                 Bom_Pricelimit(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceLimit,
@@ -213,32 +213,32 @@
               v_PriceLimit := NULL;
               v_C_UOM_ID := NULL;
             END IF;
-            
+
             -- Calculate Price Actual
             IF (Cur_SOLINES.priceactual=0) THEN
               Cur_SOLINES.priceactual:=NULL;
             END IF;
-            v_PriceActual := COALESCE(Cur_SOLINES.priceactual,M_Get_Offers_Price(now(), Cur_SO.C_BPARTNER_ID, Cur_SOLINES.M_PRODUCT_ID, v_PriceStd, Cur_SOLINES.Qty, Cur_SO.M_PRICELIST_ID),0);           
-            
+            v_PriceActual := COALESCE(Cur_SOLINES.priceactual,M_Get_Offers_Price(now(), Cur_SO.C_BPARTNER_ID, Cur_SOLINES.M_PRODUCT_ID, v_PriceStd, Cur_SOLINES.Qty, Cur_SO.M_PRICELIST_ID),0);
+
             IF (v_PriceStd IS NULL) THEN
              v_PriceStd :=  v_PriceActual ;
             END IF;
-            
+
             IF (v_PriceList IS NULL) THEN
               v_PriceList :=  v_PriceActual ;
             END IF;
-            
+
             IF (v_PriceLimit IS NULL) THEN
               v_PriceLimit :=  v_PriceActual ;
             END IF;
-            
+
             IF (v_PriceList = 0) THEN
                v_Discount := 0 ;
             ELSE
               -- Calculate rounded discount
               v_Discount :=ROUND((v_PriceList-v_PriceActual) / v_PriceList*100, 2);
             END IF;
-            
+
             IF (v_C_UOM_ID IS NULL) THEN
               SELECT P.C_UOM_ID
               INTO v_UOM
@@ -247,17 +247,17 @@
             ELSE
               v_UOM := v_C_UOM_ID;
             END IF;
-            
+
             IF (Cur_SOLINES.C_TAX_ID IS NULL) THEN
               v_Tax_ID:= C_Gettax(Cur_SOLINES.M_PRODUCT_ID, TRUNC(now(), 'DD'), Cur_SO.AD_ORG_ID, Cur_SO.M_WAREHOUSE_ID, Cur_SO.C_BPARTNER_LOCATION_ID, Cur_SO.C_BPARTNER_LOCATION_ID, Cur_SO.C_PROJECT_ID, 'Y') ;
             ELSE
               v_Tax_ID:=Cur_SOLINES.C_TAX_ID;
             END IF;
-            
+
             -- Get next C_OrderLine_ID
             Ad_Sequence_Next('C_OrderLine', Cur_SO.AD_CLIENT_ID, v_C_OrderLine_ID) ;
             v_ResultStr:='C_OrderLine_ID - ' || v_C_OrderLine_ID;
-            
+
             INSERT
             INTO C_ORDERLINE
               (
@@ -289,10 +289,10 @@
                 v_Discount, v_PriceLimit, NULL, v_PriceActual * Cur_SOLINES.Qty,
                 NULL, 'N', v_PriceStd
               )
-              ;              
+              ;
           END LOOP;
-        END IF;  
-        
+        END IF;
+
         IF v_Message IS NOT NULL THEN
           v_Message:=v_Message || ', ';
         END IF;
--- a/database/model/functions/GENERATESOFROMPROJECTPHASE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/GENERATESOFROMPROJECTPHASE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -63,10 +63,10 @@
       v_M_PriceList_ID NUMBER;
       v_Billto_ID NUMBER;
       v_InvoiceRule CHAR;
-      v_M_PriceList_Version_ID NUMBER;    
+      v_M_PriceList_Version_ID NUMBER;
       v_PriceActual NUMBER;
       v_Discount NUMBER;
-      
+
     TYPE RECORD IS REF CURSOR;
       Cur_SO RECORD;
       Cur_SOLINES RECORD;
@@ -106,27 +106,27 @@
         ELSIF Cur_SO.SALESREP_ID IS NULL THEN
           RAISE_APPLICATION_ERROR(-20000, '@ProjectSalesRepNotFound@'||'.');
         END IF;
-        
+
         -- Get Business Partner Location
         v_Billto_ID := Cur_SO.BILLTO_ID;
         IF (v_Billto_ID IS NULL) THEN
           v_Billto_ID := C_GetBPLocationID(Cur_SO.C_BPartner_ID, 'B') ;
         END IF;
-        
+
         SELECT InvoiceRule INTO v_InvoiceRule
         FROM C_BPARTNER
         WHERE C_BPartner_ID = Cur_SO.C_BPARTNER_ID;
         IF (v_InvoiceRule IS NULL) THEN
            RAISE_APPLICATION_ERROR(-20000, '@ThebusinessPartner@'||' '||' @InvoiceRuleNotdefined@'||'.');
         END IF;
-        
+
         v_C_DOCTYPE_ID:=Ad_Get_Doctype(Cur_SO.AD_Client_ID, Cur_SO.AD_Org_ID, 'SOO', 'SO') ;
         v_ResultStr:='C_DOCTYPE_ID - ' || v_C_DOCTYPE_ID;
         Ad_Sequence_Doctype(v_C_DOCTYPE_ID, Cur_SO.AD_Client_ID, 'Y', v_DocumentNo) ;
         IF(v_DocumentNo IS NULL) THEN
           Ad_Sequence_Doc('DocumentNo_C_Order', Cur_SO.AD_Client_ID, 'Y', v_DocumentNo) ;
         END IF;
-        
+
         -- Get next C_Order_ID
         Ad_Sequence_Next('C_Order', Cur_SO.AD_CLIENT_ID, v_C_Order_ID) ;
         v_ResultStr:='C_ORDER_ID - ' || v_C_Order_ID;
@@ -159,32 +159,32 @@
             v_Billto_ID, Cur_SO.C_CAMPAIGN_ID, Cur_SO.C_PROJECT_ID, Cur_SO.AD_User_ID,
              'N', TRUNC(now(), 'DD'), Cur_SO.PHASE_NAME ||' - '|| Cur_SO.DESCRIPTION
           );
-          
+
         UPDATE C_PROJECTPHASE
         SET C_ORDER_ID = v_C_Order_ID
         WHERE C_PROJECTPHASE_ID = v_Record_ID;
-        
+
         -- Select the price list version that a applies for the price list of the header
         SELECT Get_Pricelist_Version(Cur_SO.M_PriceList_ID, TRUNC(now(), 'DD'))
         INTO v_M_PriceList_Version_ID
-        FROM DUAL;        
+        FROM DUAL;
         IF (v_M_PriceList_Version_ID IS NULL) THEN
           RAISE_APPLICATION_ERROR(-20000, '@PriceListVersionNotFound@'||'.');
-        ELSE        
+        ELSE
          -- Select products, quantities, sequence numbers, descriptions and unit prices of the project phases and tasks
             -- In both cases, if no unit price has been defined for a product,
             -- price is taken from the price list of the project.
             -- And if no price is defined in the price list, price is set to 0.
           FOR Cur_SOLINES IN
             (
-            SELECT 'phase' AS PROV, pp.SEQNO, pp.NAME AS LINE_NAME, pp.DESCRIPTION, pr.NAME AS PRODUCT_NAME, pp.M_PRODUCT_ID, pp.QTY, pp.PRICEACTUAL 
+            SELECT 'phase' AS PROV, pp.SEQNO, pp.NAME AS LINE_NAME, pp.DESCRIPTION, pr.NAME AS PRODUCT_NAME, pp.M_PRODUCT_ID, pp.QTY, pp.PRICEACTUAL
             FROM C_PROJECTPHASE pp, M_PRODUCT pr
             WHERE pp.C_PROJECTPHASE_ID = v_Record_ID
               AND pp.M_PRODUCT_ID = pr.M_PRODUCT_ID
               AND pp.M_Product_ID IS NOT NULL
               AND pp.IsActive = 'Y'
             UNION
-            SELECT 'task' as PROV, pt.SEQNO, pt.NAME AS LINE_NAME, pt.DESCRIPTION, pr.NAME AS PRODUCT_NAME, pt.M_PRODUCT_ID, pt.QTY, pt.PRICEACTUAL 
+            SELECT 'task' as PROV, pt.SEQNO, pt.NAME AS LINE_NAME, pt.DESCRIPTION, pr.NAME AS PRODUCT_NAME, pt.M_PRODUCT_ID, pt.QTY, pt.PRICEACTUAL
             FROM C_PROJECTTASK pt, C_PROJECTPHASE pp, M_PRODUCT pr
             WHERE pp.C_PROJECTPHASE_ID = v_Record_ID
               AND pp.C_PROJECTPHASE_ID = pt.C_PROJECTPHASE_ID
@@ -193,8 +193,8 @@
               AND pt.IsActive = 'Y'
             ORDER BY PROV ASC, SEQNO ASC
             )
-          LOOP                    
-                        
+          LOOP
+
             -- Take StdPrice, PriceList and PriceLimit from Price List Version
             SELECT COUNT(*)
             INTO v_Size
@@ -206,7 +206,7 @@
               AND p.M_Product_ID=Cur_SOLINES.M_PRODUCT_ID
               AND pv.M_PriceList_Version_ID=v_M_PriceList_Version_ID
               AND pl.C_Currency_ID=Cur_SO.C_CURRENCY_ID;
-            IF (v_Size>0) THEN 
+            IF (v_Size>0) THEN
               SELECT Bom_Pricestd(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceStd,
                 Bom_Pricelist(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceList,
                 Bom_Pricelimit(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceLimit,
@@ -227,29 +227,29 @@
               v_PriceLimit := NULL;
               v_C_UOM_ID := NULL;
             END IF;
-            
-            -- Calculate Price Actual                      
-            v_PriceActual := COALESCE(Cur_SOLINES.priceactual,M_Get_Offers_Price(now(), Cur_SO.C_BPARTNER_ID, Cur_SOLINES.M_PRODUCT_ID, v_PriceStd, Cur_SOLINES.Qty, Cur_SO.M_PRICELIST_ID),0);           
-            
+
+            -- Calculate Price Actual
+            v_PriceActual := COALESCE(Cur_SOLINES.priceactual,M_Get_Offers_Price(now(), Cur_SO.C_BPARTNER_ID, Cur_SOLINES.M_PRODUCT_ID, v_PriceStd, Cur_SOLINES.Qty, Cur_SO.M_PRICELIST_ID),0);
+
             IF (v_PriceStd IS NULL) THEN
              v_PriceStd :=  v_PriceActual ;
             END IF;
-            
+
             IF (v_PriceList IS NULL) THEN
               v_PriceList :=  v_PriceActual ;
             END IF;
-            
+
              IF (v_PriceLimit IS NULL) THEN
               v_PriceLimit :=  v_PriceActual ;
             END IF;
-            
+
             IF (v_PriceList = 0) THEN
                v_Discount := 0 ;
             ELSE
               -- Calculate rounded discount
               v_Discount :=ROUND((v_PriceList-v_PriceActual) / v_PriceList*100, 2);
             END IF;
-            
+
             IF (v_C_UOM_ID IS NULL) THEN
               SELECT P.C_UOM_ID
               INTO v_UOM
@@ -258,11 +258,11 @@
             ELSE
               v_UOM := v_C_UOM_ID;
             END IF;
-            
+
             -- Get next C_OrderLine_ID
             Ad_Sequence_Next('C_OrderLine', Cur_SO.AD_CLIENT_ID, v_C_OrderLine_ID) ;
             v_ResultStr:='C_OrderLine_ID - ' || v_C_OrderLine_ID;
-            
+
             INSERT
             INTO C_ORDERLINE
               (
--- a/database/model/functions/GET_PARETO_ABC.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/GET_PARETO_ABC.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -31,7 +31,7 @@
   VARaCUM NUMBER:=0;
   VARaCUMB NUMBER:=0;
   v_limitA NUMBER:=80;
-  v_limitB NUMBER:=15;  
+  v_limitB NUMBER:=15;
   varComprobadoA NUMBER:=0;
   varComprobadoB NUMBER:=0;
   TYPE RECORD IS REF CURSOR;
@@ -40,20 +40,20 @@
   varAcum :=0;
   varComprobadoA := 0;
   for Cur_Cursor in (
-   SELECT 
-  100*(GET_PRODUCT_COST(PR.M_PRODUCT_ID,TO_DATE(now()),'AV')/ (select SUM(GET_PRODUCT_COST(PR1.M_PRODUCT_ID,TO_DATE(now()),'AV')) 
-                                                       from M_WAREHOUSE MW1  
+   SELECT
+  100*(GET_PRODUCT_COST(PR.M_PRODUCT_ID,TO_DATE(now()),'AV')/ (select SUM(GET_PRODUCT_COST(PR1.M_PRODUCT_ID,TO_DATE(now()),'AV'))
+                                                       from M_WAREHOUSE MW1
                                                        LEFT JOIN M_LOCATOR ML1 ON ML1.M_WAREHOUSE_ID=MW1.M_WAREHOUSE_ID
                                                        LEFT JOIN M_STORAGE_DETAIL MSD1 ON ML1.M_LOCATOR_ID=MSD1.M_LOCATOR_ID
-                                                       LEFT JOIN M_PRODUCT PR1 ON MSD1.M_PRODUCT_ID=PR1.M_PRODUCT_ID   
+                                                       LEFT JOIN M_PRODUCT PR1 ON MSD1.M_PRODUCT_ID=PR1.M_PRODUCT_ID
                                                        WHERE (p_warehouse_ID IS NULL OR MW1.M_WAREHOUSE_ID=p_warehouse_ID)
                                                        AND (p_org_ID IS NULL OR MW1.AD_ORG_ID=p_org_ID)
                                                        AND MSD1.QTYONHAND>0) ) as PORCENTAJE
   FROM
-   M_WAREHOUSE MW 
+   M_WAREHOUSE MW
      LEFT JOIN M_LOCATOR ML ON ML.M_WAREHOUSE_ID=MW.M_WAREHOUSE_ID
      LEFT JOIN M_STORAGE_DETAIL MSD ON ML.M_LOCATOR_ID=MSD.M_LOCATOR_ID
-     LEFT JOIN M_PRODUCT PR ON MSD.M_PRODUCT_ID=PR.M_PRODUCT_ID   
+     LEFT JOIN M_PRODUCT PR ON MSD.M_PRODUCT_ID=PR.M_PRODUCT_ID
   WHERE (p_warehouse_ID IS NULL OR MW.M_WAREHOUSE_ID=p_warehouse_ID)
      AND (p_org_ID IS NULL OR MW.AD_ORG_ID=p_org_ID)
      AND MSD.QTYONHAND>0
@@ -63,7 +63,7 @@
   varAcum := varAcum+Cur_Cursor.porcentaje;
    if(varComprobadoA=0)then
      if (varAcum>=v_limitA) then
-       if (p_porcentajeactual>=Cur_Cursor.porcentaje) then 
+       if (p_porcentajeactual>=Cur_Cursor.porcentaje) then
 	     return 'A';
        else
          varComprobadoA:=-1;
@@ -78,7 +78,7 @@
      if (p_porcentajeactual>=Cur_Cursor.porcentaje) then return 'B';
 	 else varComprobadoB:=-1;
      end if;
-   end if;   
+   end if;
   end if;
 
  end loop;
--- a/database/model/functions/GET_PURCHASE_PRICE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/GET_PURCHASE_PRICE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -56,7 +56,7 @@
       LOOP
         v_Price := Cur_Orderline.PRICE;
         EXIT;
-      END LOOP;          
+      END LOOP;
     END IF;
     IF(v_Price IS NULL) THEN
       FOR Cur_Pricelist_Version IN
--- a/database/model/functions/MA_WORKEFFORT_VALIDATE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/MA_WORKEFFORT_VALIDATE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -287,7 +287,7 @@
       v_ResultStr:='Updating used toolsets';
       FOR Cur_Toolset IN
         (SELECT MA_TOOLSETUSED.*
-         FROM MA_TOOLSETUSED, M_PRODUCTIONPLAN 
+         FROM MA_TOOLSETUSED, M_PRODUCTIONPLAN
          WHERE MA_TOOLSETUSED.M_PRODUCTIONPLAN_ID = M_PRODUCTIONPLAN.M_PRODUCTIONPLAN_ID
            AND M_PRODUCTIONPLAN.M_PRODUCTION_ID = v_Record_ID) LOOP
         UPDATE MA_TOOLSET
--- a/database/model/functions/MRP_PROCESSPLAN.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/MRP_PROCESSPLAN.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -59,7 +59,7 @@
 
 BEGIN
   BEGIN --BODY
-     
+
     --SET AS PLANNED PURCHASE PRODUCTS
     UPDATE MRP_RUN_PRODUCTIONLINE
     SET ISPLANNED = 'Y'
--- a/database/model/functions/MRP_PURCHASEORDER.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/MRP_PURCHASEORDER.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -235,17 +235,17 @@
 
     END LOOP;
   v_ResultStr :='Set requisition lines as planned';
-  UPDATE M_RequisitionLine 
+  UPDATE M_RequisitionLine
   SET REQSTATUS = 'P'
   WHERE M_RequisitionLine_ID IN (SELECT M_RequisitionLine_ID
                                  FROM MRP_RUN_PURCHASELINE
                                  WHERE MRP_RUN_PURCHASE_ID = v_Record_ID
                                    AND INOUTTRXTYPE = 'MF');
-  
+
   UPDATE M_Requisition
   SET DocStatus = 'CL'
-  WHERE M_Requisition_ID IN (SELECT M_Requisition_ID 
-                            FROM M_RequisitionLine 
+  WHERE M_Requisition_ID IN (SELECT M_Requisition_ID
+                            FROM M_RequisitionLine
                             WHERE M_RequisitionLine_ID IN (SELECT M_RequisitionLine_ID
                                                           FROM MRP_RUN_PURCHASELINE
                                                           WHERE MRP_RUN_PURCHASE_ID = v_Record_ID
@@ -253,7 +253,7 @@
     AND NOT EXISTS (SELECT 1
                     FROM M_RequisitionLine rl
                     WHERE rl.REQSTATUS = 'O'
-                      AND rl.M_Requisition_ID = M_Requisition.M_Requisition_ID);    
+                      AND rl.M_Requisition_ID = M_Requisition.M_Requisition_ID);
   END;--BODY
   IF(p_PInstance_ID IS NOT NULL) THEN
     AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', v_Result, v_Message) ;
--- a/database/model/functions/MRP_REQUISITION.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/MRP_REQUISITION.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -68,7 +68,7 @@
       INTO v_Description0, v_Description
     FROM MRP_RUN_PRODUCTION
     WHERE MRP_RUN_PRODUCTION_ID = v_Record_ID;
-     
+
     SELECT count(*) INTO v_Count
     FROM MRP_RUN_PRODUCTIONLINE
     WHERE MRP_RUN_PRODUCTION_ID = v_Record_ID
@@ -81,7 +81,7 @@
 
     Ad_Sequence_Next('M_Requisition', v_Client_ID, v_MRequisition_ID);
     Ad_Sequence_Doc('DocumentNo_M_Requisition', v_Client_ID, 'Y', v_DocumentNo);
-    
+
     v_Description := 'MRP: ' || v_Description0 || CHR(10) || v_Description;
 
     INSERT INTO M_Requisition (
@@ -93,7 +93,7 @@
       'Y', now(), v_User_ID, now(), v_User_ID,
       v_Description, v_DocumentNo, v_User_ID
     );
-    
+
     FOR Cur_workproposal IN (
       SELECT *
       FROM MRP_RUN_PRODUCTIONLINE
@@ -125,17 +125,17 @@
   END; --BODY
   v_Message := '@CreatedRequisition@: ' || v_DocumentNo;
   v_ResultStr :='Set requisition lines as planned';
-  UPDATE M_RequisitionLine 
+  UPDATE M_RequisitionLine
   SET REQSTATUS = 'P'
   WHERE M_RequisitionLine_ID IN (SELECT M_RequisitionLine_ID
                                  FROM MRP_RUN_PRODUCTIONLINE
                                  WHERE MRP_RUN_PRODUCTION_ID = v_Record_ID
                                    AND INOUTTRXTYPE = 'MF');
-  
+
   UPDATE M_Requisition
   SET DocStatus = 'CL'
-  WHERE M_Requisition_ID IN (SELECT M_Requisition_ID 
-                            FROM M_RequisitionLine 
+  WHERE M_Requisition_ID IN (SELECT M_Requisition_ID
+                            FROM M_RequisitionLine
                             WHERE M_RequisitionLine_ID IN (SELECT M_RequisitionLine_ID
                                                           FROM MRP_RUN_PRODUCTIONLINE
                                                           WHERE MRP_RUN_PRODUCTION_ID = v_Record_ID
--- a/database/model/functions/MRP_RUN_INITIALIZE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/MRP_RUN_INITIALIZE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -270,7 +270,7 @@
                                            AND r.M_REQUISITION_ID = rr.M_REQUISITION_ID
                                            AND rr.DOCSTATUS = 'CO'
                                            AND r.REQSTATUS = 'O'
-                                           AND NOT (COALESCE(r.LOCKEDBY, p_User_ID) <> p_User_ID 
+                                           AND NOT (COALESCE(r.LOCKEDBY, p_User_ID) <> p_User_ID
                                                     AND COALESCE(r.LOCKDATE, TO_DATE('01-01-1900', 'DD-MM-YYYY')) >= (now()-3))
                                            AND Mrp_Check_Planningmethod(Cur_Product.MRP_PlanningMethod_ID,
                                               'MF', TO_NUMBER(r.NeedByDate - p_PlanningDate), p_TimeHorizon) <> -1
--- a/database/model/functions/MRP_WORKREQUIREMENT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/MRP_WORKREQUIREMENT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -97,17 +97,17 @@
        WHERE MRP_RUN_PRODUCTIONLINE_ID = Cur_workproposal.MRP_RUN_PRODUCTIONLINE_ID;
     END LOOP;
   v_ResultStr :='Set requisition lines as planned';
-  UPDATE M_RequisitionLine 
+  UPDATE M_RequisitionLine
   SET REQSTATUS = 'P'
   WHERE M_RequisitionLine_ID IN (SELECT M_RequisitionLine_ID
                                  FROM MRP_RUN_PRODUCTIONLINE
                                  WHERE MRP_RUN_PRODUCTION_ID = v_Record_ID
                                    AND INOUTTRXTYPE = 'MF');
-  
+
   UPDATE M_Requisition
   SET DocStatus = 'CL'
-  WHERE M_Requisition_ID IN (SELECT M_Requisition_ID 
-                            FROM M_RequisitionLine 
+  WHERE M_Requisition_ID IN (SELECT M_Requisition_ID
+                            FROM M_RequisitionLine
                             WHERE M_RequisitionLine_ID IN (SELECT M_RequisitionLine_ID
                                                           FROM MRP_RUN_PRODUCTIONLINE
                                                           WHERE MRP_RUN_PRODUCTION_ID = v_Record_ID
--- a/database/model/functions/M_INOUT_CREATE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/M_INOUT_CREATE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -211,7 +211,7 @@
              o.DateOrdered, o.DeliveryRule, o.FreightCostRule, o.FreightAmt,
              o.C_Project_ID, o.C_Activity_ID, o.C_Campaign_ID, o.AD_OrgTrx_ID,
              o.User1_ID, o.User2_ID, o.DeliveryViaRule, o.M_Shipper_ID,
-             o.C_Charge_ID, o.ChargeAmt, o.PriorityRule, o.SALESREP_ID,              
+             o.C_Charge_ID, o.ChargeAmt, o.PriorityRule, o.SALESREP_ID,
              o.DELIVERY_LOCATION_ID -- Added by Rafa Roda to include delivery location
            FROM C_ORDER o INNER JOIN C_ORDERLINE l ON(o.C_Order_ID=l.C_Order_ID) --  Orders are IP  or CO if Standard Orders
            WHERE(o.DocStatus='IP' OR(o.DocStatus='CO'
@@ -303,7 +303,7 @@
               C_Campaign_ID, AD_OrgTrx_ID, User1_ID, User2_ID,
               DeliveryViaRule, M_Shipper_ID, C_Charge_ID, ChargeAmt,
               PriorityRule, DocStatus, DocAction, Processing,
-              Processed, SALESREP_ID, 
+              Processed, SALESREP_ID,
               DELIVERY_LOCATION_ID) -- Added by Rafa Roda to include delivery location
             VALUES
               (p_InOut_ID, Cur_Order.C_Order_ID, Cur_Order.IsSOTrx, Cur_Order.AD_Client_ID,
@@ -316,7 +316,7 @@
               Cur_Order.C_Campaign_ID, Cur_Order.AD_OrgTrx_ID, Cur_Order.User1_ID, Cur_Order.User2_ID,
               Cur_Order.DeliveryViaRule, Cur_Order.M_Shipper_ID, Cur_Order.C_Charge_ID, Cur_Order.ChargeAmt,
               Cur_Order.PriorityRule, 'DR', 'CO', 'N',
-              'N', Cur_Order.SALESREP_ID, 
+              'N', Cur_Order.SALESREP_ID,
               Cur_Order.DELIVERY_LOCATION_ID); -- Added by Rafa Roda to include delivery location
           END IF;--Next_Order
           IF(NOT Next_Order) THEN
--- a/database/model/functions/M_INVENTORY_LISTCREATE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/M_INVENTORY_LISTCREATE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -97,7 +97,7 @@
         DBMS_OUTPUT.PUT_LINE('  M_Product_Category_ID=' || v_Product_Category_ID) ;
       ELSIF(Cur_Parameter.ParameterName='ABC') THEN
         v_ABC:=Cur_Parameter.P_String;
-        DBMS_OUTPUT.PUT_LINE('  ABC=' || v_ABC) ;        
+        DBMS_OUTPUT.PUT_LINE('  ABC=' || v_ABC) ;
       ELSE
         DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ;
       END IF;
@@ -211,14 +211,14 @@
       INNER JOIN M_Storage_Detail s
         ON(s.M_Product_ID=p.M_Product_ID)
       LEFT JOIN M_Product_org o
-        ON(o.M_Product_ID=p.M_Product_ID) 
+        ON(o.M_Product_ID=p.M_Product_ID)
       WHERE p.AD_Client_ID=v_Client_ID  --    only ..
         AND(v_ProductValue IS NULL
         OR UPPER(p.Value) LIKE v_ProductValue)
         AND(v_Locator_ID IS NULL
         OR s.M_Locator_ID=v_Locator_ID)
         AND(v_ABC IS NULL
-        OR o.ABC=v_ABC)        
+        OR o.ABC=v_ABC)
         AND(v_Warehouse_ID IS NULL
         OR s.M_Locator_ID IN
         (SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=v_Warehouse_ID))
--- a/database/model/functions/M_REQUISITIONLINE_STATUS.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/M_REQUISITIONLINE_STATUS.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -67,13 +67,13 @@
                     WHEN 'P' THEN 'P'
                     WHEN 'C' THEN 'O'
                     WHEN 'D' THEN 'O'
-                    ELSE (CASE OrderedQty 
+                    ELSE (CASE OrderedQty
                          WHEN 0 THEN 'D'
                          ELSE 'C' END) END),
         Updated = now(),
         UpdatedBy = v_User_ID
     WHERE M_RequisitionLine_ID = v_Record_ID;
-    
+
     UPDATE M_Requisition
     SET DocStatus = 'CL'
     WHERE M_Requisition_ID = (SELECT M_Requisition_ID FROM M_RequisitionLine WHERE M_RequisitionLine_ID = v_Record_ID)
--- a/database/model/functions/M_REQUISITION_CREATEPO.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/M_REQUISITION_CREATEPO.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -41,14 +41,14 @@
   v_NoRecords NUMBER:=0;
   v_RequisitionOrder_ID NUMBER;
   v_PaymentTerm_ID NUMBER;
-  
+
   v_PriceList NUMBER;
   v_PriceLimit NUMBER;
   v_PriceStd NUMBER;
   v_PriceActual NUMBER;
   v_Discount NUMBER;
   v_Tax_ID NUMBER;
-  
+
   p_OrderDate DATE;
   p_Vendor_ID NUMBER;
   p_PriceList_ID NUMBER;
@@ -59,7 +59,7 @@
   TYPE RECORD IS REF CURSOR;
   Cur_Parameter RECORD;
   Cur_Product RECORD;
-  Cur_Lines RECORD;	
+  Cur_Lines RECORD;
 BEGIN
   DBMS_OUTPUT.PUT_LINE('BEGIN M_REQUISITION_ORDER ' || p_PInstance_ID) ;
   v_ResultStr:='PInstanceNotFound';
@@ -91,7 +91,7 @@
       v_User_ID:=Cur_Parameter.AD_User_ID;
       v_Client_ID := Cur_Parameter.AD_Client_ID;
     END LOOP; -- Get Parameter
-    
+
     v_ResultStr := 'Checking vendor';
     IF (p_Vendor_ID IS NULL OR p_Vendor_ID = '') THEN
       FOR Cur_Product IN (
@@ -114,8 +114,8 @@
     END IF;
 
     v_ResultStr:='Start lines cursor';
-    FOR Cur_Lines IN 
-      (SELECT A.*, 
+    FOR Cur_Lines IN
+      (SELECT A.*,
            COALESCE(A.A_PRICELIST_ID, C_BPARTNER.PO_PRICELIST_ID) AS PRICELIST_ID,
            C_BPARTNER.PAYMENTRULEPO AS PAYMENTRULE, C_BPARTNER.PO_PAYMENTTERM_ID AS C_PAYMENTTERM_ID,
            C_BPARTNER.DELIVERYRULE, C_BPARTNER.FREIGHTCOSTRULE, C_BPARTNER.DELIVERYVIARULE
@@ -123,7 +123,7 @@
                  COALESCE(p_PriceList_ID, M_REQUISITIONLINE.M_PRICELIST_ID, M_REQUISITION.M_PRICELIST_ID) AS A_PRICELIST_ID,
                  M_REQUISITIONLINE.*
               FROM M_REQUISITION, M_REQUISITIONLINE LEFT JOIN (SELECT MAX(C_BPARTNER_ID) AS C_BPARTNER_ID, M_PRODUCT_ID
-                                                               FROM M_PRODUCT_PO 
+                                                               FROM M_PRODUCT_PO
                                                                WHERE ISCURRENTVENDOR = 'Y'
                                                                  AND ISACTIVE = 'Y'
                                                                  AND DISCONTINUED = 'N'
@@ -132,18 +132,18 @@
               WHERE M_REQUISITION.M_REQUISITION_ID = M_REQUISITIONLINE.M_REQUISITION_ID
                 AND M_REQUISITION.M_REQUISITION_ID = v_Record_ID
                 AND M_REQUISITIONLINE.REQSTATUS = 'O'
-                AND NOT (COALESCE(M_REQUISITIONLINE.LOCKEDBY, v_User_ID) <> v_User_ID 
+                AND NOT (COALESCE(M_REQUISITIONLINE.LOCKEDBY, v_User_ID) <> v_User_ID
                          AND COALESCE(M_REQUISITIONLINE.LOCKDATE, TO_DATE('01-01-1900', 'DD-MM-YYYY')) >= (now()-3))
               ) A, C_BPARTNER
        WHERE A.VENDOR_ID = C_BPARTNER.C_BPARTNER_ID
        ORDER BY A.VENDOR_ID, COALESCE(A.A_PRICELIST_ID, C_BPARTNER.PO_PRICELIST_ID)) LOOP
       v_ResultStr:='Line start';
-      
+
       IF (Cur_Lines.PRICELIST_ID IS NULL ) THEN
         v_Message := '@PriceListVersionNotFound@';
         RAISE_APPLICATION_ERROR(-20000, v_Message);
       END IF;
-      
+
       IF (v_C_Order_ID IS NULL OR v_Vendor_Old <> Cur_Lines.Vendor_ID OR v_PriceList_Old <> Cur_Lines.PriceList_ID) THEN
         IF (v_C_Order_ID IS NOT NULL) THEN
           v_ResultStr := 'Post Order ' || v_C_Order_ID;
@@ -171,16 +171,16 @@
         WHERE ISACTIVE='Y'
           AND ISBILLTO='Y'
           AND C_BPARTNER_ID=Cur_Lines.Vendor_ID;
-        
+
         SELECT C_CURRENCY_ID INTO v_Currency_ID
         FROM M_PRICELIST
         WHERE M_PRICELIST_ID = Cur_Lines.Pricelist_ID;
-        
+
         IF(Cur_Lines.C_PAYMENTTERM_ID IS NULL) THEN
           SELECT c_paymentterm_id INTO v_PaymentTerm_ID
-          FROM c_paymentterm 
-          WHERE isactive='Y' 
-            AND isdefault='Y' 
+          FROM c_paymentterm
+          WHERE isactive='Y'
+            AND isdefault='Y'
             AND AD_Client_ID = v_Client_ID;
         END IF;
 
@@ -208,7 +208,7 @@
             NULL, 'N', p_OrderDate
         );
       END IF;
-      
+
       v_ResultStr := 'Create C_Order_Line';
       v_Line := v_Line + 10;
       Ad_Sequence_Next('C_OrderLine', v_Client_ID, v_COrderLine_ID);
@@ -218,21 +218,21 @@
              ROUND((COALESCE(pp.PRICELIST, Cur_Lines.PRICELIST, Cur_Lines.PRICEACTUAL) - COALESCE(Cur_Lines.PRICEACTUAL, pp.PRICESTD))/
                  COALESCE(pp.PRICELIST, Cur_Lines.PRICELIST, Cur_Lines.PRICEACTUAL)*100,CUR.PRICEPRECISION)
         INTO v_PriceList, v_PriceLimit, v_PriceStd, v_PriceActual, v_Discount
-      FROM 
+      FROM
         (SELECT COALESCE(MAX(M_PRODUCTPRICE.PRICELIST), Cur_Lines.PRICELIST, Cur_Lines.PRICEACTUAL) AS PRICELIST,
              COALESCE(MAX(M_PRODUCTPRICE.PRICELIMIT), Cur_Lines.PRICEACTUAL) AS PRICELIMIT,
              COALESCE(MAX(M_PRODUCTPRICE.PRICESTD), Cur_Lines.PRICEACTUAL) AS PRICESTD
          FROM M_PRODUCTPRICE
          WHERE M_PRICELIST_VERSION_ID = GET_PRICELIST_VERSION(Cur_Lines.PRICELIST_ID, p_OrderDate)
            AND M_PRODUCT_ID = Cur_Lines.M_PRODUCT_ID) pp, (SELECT PRICEPRECISION FROM C_CURRENCY WHERE C_CURRENCY_ID = v_Currency_ID) CUR;
-        
+
       IF (v_PriceActual IS NULL) THEN
         v_Message := '@PriceNotFound@';
         RAISE_APPLICATION_ERROR(-20000, v_Message);
       END IF;
-      
+
       v_Tax_ID := C_GetTax(Cur_Lines.M_Product_ID, p_OrderDate, p_Org_ID, p_Warehouse_ID, v_BillTo_ID, v_BPartner_Location_ID, null, 'N');
-      
+
       v_ResultStr:='Insert order line';
       INSERT INTO C_OrderLine (
           C_ORDERLINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
@@ -255,11 +255,11 @@
           v_PriceStd, v_PriceActual*(Cur_Lines.QTY - Cur_Lines.ORDEREDQTY),v_Discount,
           v_Tax_ID
       );
-      
+
       Ad_Sequence_Next('M_RequisitionOrder', v_User_ID, v_RequisitionOrder_ID);
-      
+
       INSERT INTO M_REQUISITIONORDER (
-        M_REQUISITIONORDER_ID, AD_CLIENT_ID, AD_ORG_ID, 
+        M_REQUISITIONORDER_ID, AD_CLIENT_ID, AD_ORG_ID,
         CREATED, CREATEDBY, UPDATED, UPDATEDBY, ISACTIVE,
         M_REQUISITIONLINE_ID, C_ORDERLINE_ID, QTY
       ) VALUES (
@@ -269,14 +269,14 @@
       );
       M_REQUISITIONLINE_STATUS(NULL, Cur_Lines.M_RequisitionLine_ID, v_User_ID);
     END LOOP;
-        
+
     v_ResultStr := 'Post last Order ' || v_C_Order_ID;
     C_ORDER_POST1(null, v_C_Order_ID);
     v_Message := v_Message || ', ' || '@OrderDocumentno@ ' || v_DocumentNo;
-    
-    
-    
-    
+
+
+
+
 
   END; --BODY
   v_Message:='@Created@: ' || v_NoRecords || v_Message;
--- a/database/model/functions/M_REQUISITION_POST.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/M_REQUISITION_POST.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -52,7 +52,7 @@
       v_Record_ID:=Cur_Parameter.Record_ID;
       v_User_ID:=Cur_Parameter.AD_User_ID;
     END LOOP; -- Get Parameter
-    
+
     SELECT DocAction, DocStatus INTO v_DocAction, v_DocStatus
     FROM M_REQUISITION
     WHERE M_REquisition_ID = v_Record_ID;
--- a/database/model/functions/M_UPDATE_PARETO_PRODUCT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/M_UPDATE_PARETO_PRODUCT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -28,17 +28,17 @@
 ************************************************************************/
 
   v_ResultStr VARCHAR2(2000):='';
-  v_Result NUMBER:= 1;  
+  v_Result NUMBER:= 1;
   v_Message VARCHAR2(2000):='';
   v_exist NUMBER:=0;
   v_M_Product_Org_ID NUMBER(10);
   v_warehouse_ID NUMBER(10);
   v_org_ID NUMBER(10);
   v_count_update NUMBER:= 0;
-  v_count_insert NUMBER:= 0;  
+  v_count_insert NUMBER:= 0;
   TYPE RECORD IS REF CURSOR;
   Cur_Cursor RECORD;
-  Cur_Parameter RECORD;  
+  Cur_Parameter RECORD;
 BEGIN
 
   IF(p_PInstance_ID IS NOT NULL) THEN
@@ -64,58 +64,58 @@
     ELSE
       DBMS_OUTPUT.PUT_LINE('--<<M_UPDATE_PARETO_PRODUCT>>') ;
       v_warehouse_ID:=p_warehouse_ID;
-      v_org_ID:=p_org_ID;    
+      v_org_ID:=p_org_ID;
     END IF;
     BEGIN --BODY
-    
+
   for Cur_Cursor in (
      SELECT ORGID, SEARCHKEY, NAME, COST, PORCENTAJE,
      GET_PARETO_ABC(v_warehouse_ID, v_org_ID, PORCENTAJE) AS ISABC,
      AD_ORG_ID, AD_CLIENT_ID, M_PRODUCT_ID
      FROM
      (
-     SELECT 
+     SELECT
       AD_ORG.NAME AS ORGID,
       PR.VALUE AS SEARCHKEY,
       PR.NAME,
       GET_PRODUCT_COST(PR.M_PRODUCT_ID,TO_DATE(now()),'AV') AS COST,
-      100*(GET_PRODUCT_COST(PR.M_PRODUCT_ID,TO_DATE(now()),'AV')/ (SELECT SUM(GET_PRODUCT_COST(PR1.M_PRODUCT_ID,TO_DATE(now()),'AV')) 
-                                                           from M_WAREHOUSE MW1  
+      100*(GET_PRODUCT_COST(PR.M_PRODUCT_ID,TO_DATE(now()),'AV')/ (SELECT SUM(GET_PRODUCT_COST(PR1.M_PRODUCT_ID,TO_DATE(now()),'AV'))
+                                                           from M_WAREHOUSE MW1
                                                            LEFT JOIN M_LOCATOR ML1 ON ML1.M_WAREHOUSE_ID=MW1.M_WAREHOUSE_ID
                                                            LEFT JOIN M_STORAGE_DETAIL MSD1 ON ML1.M_LOCATOR_ID=MSD1.M_LOCATOR_ID
-                                                           LEFT JOIN M_PRODUCT PR1 ON MSD1.M_PRODUCT_ID=PR1.M_PRODUCT_ID   
+                                                           LEFT JOIN M_PRODUCT PR1 ON MSD1.M_PRODUCT_ID=PR1.M_PRODUCT_ID
                                                            WHERE MSD1.QTYONHAND>0
                                                            AND (v_warehouse_ID IS NULL OR MW1.M_WAREHOUSE_ID = TO_NUMBER(v_warehouse_ID))
-                                                           AND (v_org_ID IS NULL OR MW1.AD_ORG_ID = TO_NUMBER(v_org_ID)) 
+                                                           AND (v_org_ID IS NULL OR MW1.AD_ORG_ID = TO_NUMBER(v_org_ID))
                                                            ) ) as PORCENTAJE,
       MW.AD_ORG_ID,
       MW.AD_CLIENT_ID,
       PR.M_PRODUCT_ID
      FROM
-     M_WAREHOUSE MW 
+     M_WAREHOUSE MW
        LEFT JOIN M_LOCATOR ML ON ML.M_WAREHOUSE_ID=MW.M_WAREHOUSE_ID
        LEFT JOIN M_STORAGE_DETAIL MSD ON ML.M_LOCATOR_ID=MSD.M_LOCATOR_ID
-       LEFT JOIN M_PRODUCT PR ON MSD.M_PRODUCT_ID=PR.M_PRODUCT_ID, AD_ORG   
+       LEFT JOIN M_PRODUCT PR ON MSD.M_PRODUCT_ID=PR.M_PRODUCT_ID, AD_ORG
      WHERE (v_warehouse_ID IS NULL OR MW.M_WAREHOUSE_ID = TO_NUMBER(v_warehouse_ID))
        AND (v_org_ID IS NULL OR MW.AD_ORG_ID = TO_NUMBER(v_org_ID))
        AND MSD.QTYONHAND>0
        AND GET_PRODUCT_COST(PR.M_PRODUCT_ID,TO_DATE(now()),'AV') IS NOT NULL
        AND GET_PRODUCT_COST(PR.M_PRODUCT_ID,TO_DATE(now()),'AV') <> 0
        AND MSD.AD_ORG_ID = AD_ORG.AD_ORG_ID
-     GROUP BY AD_ORG.NAME ,PR.VALUE, PR.NAME, MW.AD_ORG_ID, MW.AD_CLIENT_ID, PR.M_PRODUCT_ID    
+     GROUP BY AD_ORG.NAME ,PR.VALUE, PR.NAME, MW.AD_ORG_ID, MW.AD_CLIENT_ID, PR.M_PRODUCT_ID
      ORDER BY PORCENTAJE DESC) BBB) loop
-     
-     SELECT COUNT(*) 
-     INTO v_exist 
+
+     SELECT COUNT(*)
+     INTO v_exist
      FROM M_PRODUCT_ORG
      WHERE M_PRODUCT_ID = Cur_Cursor.M_PRODUCT_ID
-     AND AD_ORG_ID = Cur_Cursor.AD_ORG_ID; 
-     
+     AND AD_ORG_ID = Cur_Cursor.AD_ORG_ID;
+
      IF (v_exist > 0) THEN
        UPDATE M_PRODUCT_ORG SET
        ABC = Cur_Cursor.ISABC
        WHERE M_PRODUCT_ID = Cur_Cursor.M_PRODUCT_ID
-       AND AD_ORG_ID = Cur_Cursor.AD_ORG_ID; 
+       AND AD_ORG_ID = Cur_Cursor.AD_ORG_ID;
        v_count_update := v_count_update + 1;
      ELSE
        AD_Sequence_Next('M_Product_Org', Cur_Cursor.AD_CLIENT_ID, v_M_Product_Org_ID) ;
--- a/database/model/functions/S_TIMEEXPENSE_POST.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/functions/S_TIMEEXPENSE_POST.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -78,7 +78,7 @@
     CUR_te RECORD;
     v_Hours NUMBER;
   BEGIN
-  
+
   /* Check if there are expense lines to process */
   SELECT COUNT(S_TimeExpenseLine.S_TimeExpenseLine_Id)
   INTO v_ExpenseLines
@@ -89,7 +89,7 @@
   IF (v_ExpenseLines = 0) THEN
     RAISE_APPLICATION_ERROR(-20000, '@NoExpenseLines@'||'.');
   END IF;
-  
+
     -- For ease id having access to all variables
   SELECT S_TimeExpense.Processed,
   MAX(S_TimeExpenseLine.C_InvoiceLine_ID), MAX(S_TimeExpenseLine.C_OrderLine_ID)
--- a/database/model/triggers/AD_MENU_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/AD_MENU_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -105,17 +105,17 @@
       END IF;
     END IF;
   END IF;
-  -- Updating 
+  -- Updating
   IF DELETING THEN
     --  Delete TreeNode
-    --  get AD_Tree_ID, AD_Menu_ID    
+    --  get AD_Tree_ID, AD_Menu_ID
     SELECT c.AD_Tree_Menu_ID
       INTO v_xTree_ID
       FROM AD_ClientInfo c,
         AD_TreeNode n
       WHERE c.AD_Tree_Menu_ID=n.AD_Tree_ID
         AND n.Parent_ID IS NULL
-        AND c.AD_Client_ID=:old.AD_Client_ID;    
+        AND c.AD_Client_ID=:old.AD_Client_ID;
     --Assign children to principal node
     UPDATE AD_Treenode
       SET Parent_ID=0
@@ -126,7 +126,7 @@
       FROM AD_Treenode
       WHERE AD_Client_ID=:old.AD_Client_ID
         AND AD_Tree_ID=v_xTree_ID
-        AND Node_ID=:old.AD_Menu_ID;   
+        AND Node_ID=:old.AD_Menu_ID;
   END IF;
   -- Deleting
 EXCEPTION
--- a/database/model/triggers/AD_PROCESS_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/AD_PROCESS_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -67,7 +67,7 @@
 --      update AD_Column/AD_Field Name
   IF UPDATING
   THEN
-  
+
     IF(    COALESCE (:OLD.NAME, '.') <> COALESCE (:NEW.NAME, '.')
         OR COALESCE (:OLD.Description, '.') <> COALESCE (:NEW.Description, '.')
         OR COALESCE (:OLD.HELP, '.') <> COALESCE (:NEW.HELP, '.') )
--- a/database/model/triggers/AD_REFERENCE_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/AD_REFERENCE_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -5,7 +5,7 @@
 
 
 
- 
+
 /*************************************************************************
 * The contents of this file are subject to the Compiere License
 * Version 2.5.0 ("License"); You may not use this file except in
--- a/database/model/triggers/AD_TABLE_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/AD_TABLE_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -5,127 +5,127 @@
 
 
 
- 
-/************************************************************************* 
- * The contents of this file are subject to the Compiere License 
- * Version 2.5.0 ("License"); You may not use this file except in 
- * compliance with the License. You may obtain a copy of the License at 
- * http://www.compiere.org/license.html 
- * Software distributed under the License is distributed on an 
- * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 
- * implied. See the License for the specific language governing rights 
- * and limitations under the License. 
- * The Original Code is  Compiere  ERP &  Business Solution 
- * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, 
-Inc. 
- * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, 
- * parts created by ComPiere are Copyright (C) ComPiere, Inc.; 
- * All Rights Reserved. 
- * Contributor(s): Openbravo SL 
- * Contributions are Copyright (C) 1999-2005 Openbravo, S.L 
- ************************************************************************* 
- * $Id: AD_Table_Trg.sql,v 1.2 2003/07/26 04:29:44 jjanke Exp $ 
- *** 
- * Title:   Synchronize with AD_Sequence and AD_Replication 
- * Description: 
- ************************************************************************/ 
- 
-   TYPE RECORD IS REF CURSOR; 
-   CUR_Replication RECORD; 
- 
-  v_NextNo      NUMBER; 
-  v_CurrentNext    NUMBER; 
-  v_CurrentNextSys NUMBER; 
-  v_StartWith     VARCHAR(7); 
-  v_StartWithSys    VARCHAR(7); 
- 
- 
-BEGIN 
- -- Insert new Key Sequence 
- IF INSERTING THEN 
- 
-  --try to get CurrentNext 
-  BEGIN 
-   EXECUTE IMMEDIATE 'SELECT 1 + COALESCE((SELECT MAX('||:new.tableName||'_id)'|| 
-                                'FROM '||:new.tableName|| 
-                     ' WHERE '||:new.tableName||'_ID>=1000000),1000000-1)'|| 
-            ' from dual' into v_CurrentNext; 
- 
-   Exception WHEN OTHERS THEN 
-     v_CurrentNext := 1000000; 
-  END; 
- 
-  --try to get CurrentNextSys 
-  BEGIN 
-    SELECT TAD_LEVEL INTO v_StartWithSys 
-    FROM AD_SYSTEM 
-    WHERE AD_SYSTEM_ID=0; 
- 
-   v_StartWith    := TO_CHAR(TO_NUMBER(v_StartWithSys)+1) || '00000'; 
-   v_StartWithSys := v_StartWithSys || '00000'; 
- 
-   IF (UPPER(:new.TableName) LIKE 'AD_%') THEN 
-       EXECUTE IMMEDIATE ' SELECT 1 + (CASE SIGN(COALESCE((SELECT MAX(' || :new.tableName ||'_ID) FROM '||:new.tableName|| 
-             ' WHERE ' ||:new.tableName || '_ID<' || v_StartWith ||'),0)-' || v_StartWithSys || ') WHEN -1 THEN '||v_StartWithSys || '-1 ELSE ' || '(SELECT MAX(' ||:new.Name || '_ID) FROM ' ||:new.Name|| 
-             ' WHERE ' ||:new.tableName ||'_ID<' || v_StartWith || ') END) AS SEQUENCE '|| 
-             ' FROM dual' INTO v_CurrentNextSys; 
-   ELSE 
-     EXECUTE IMMEDIATE ' SELECT 1 + COALESCE((SELECT MAX('||:new.tableName||'_ID) FROM ' ||:new.tableName||' WHERE ' ||:new.tableName||'_ID<' || v_StartWith ||'),(' || v_StartWithSys || '-1))' || 
-             ' FROM dual' INTO v_CurrentNextSys; 
-   END IF; 
-   Exception WHEN OTHERS THEN v_CurrentNextSys := 100; 
-  END; 
- 
-  -- Make sure that we can insert 
-  DELETE FROM AD_Sequence 
-  WHERE  UPPER(Name) = UPPER(:new.TableName); 
-     --  Get next number 
-     AD_Sequence_Next('AD_Sequence', :new.AD_Table_ID, v_NextNo); 
- 
- 
-   --  Insert 
-     INSERT INTO AD_Sequence 
-         (AD_Sequence_ID, AD_Client_ID, AD_Org_ID, 
-         IsActive, Created, CreatedBy, Updated, UpdatedBy, 
-         Name, Description, 
-         IsAutoSequence, StartNo, IncrementNo, CurrentNextSys, CurrentNext, 
-         IsAudited, IsTableID, StartNewYear) 
-     VALUES 
-         (v_NextNo, :new.AD_Client_ID, :new.AD_Org_ID, 
-         'Y', now(), 0, now(), 0, 
-         :new.TableName, :new.TableName, 
-         'Y', 1000000, 1, v_CurrentNextSys, v_CurrentNext, 
-         'N', 'Y', 'N'); 
-        -- 
-        DECLARE 
- 
-        BEGIN 
-            FOR CUR_Replication IN (SELECT  AD_ReplicationStrategy_ID 
-                            FROM    AD_ReplicationStrategy) LOOP 
-             AD_Sequence_Next('AD_ReplicationTable', :new.AD_Table_ID, v_NextNo); 
-                INSERT INTO AD_ReplicationTable 
-                    (AD_ReplicationTable_ID, AD_Client_ID, AD_Org_ID, 
-                 IsActive, Created, CreatedBy, Updated, UpdatedBy, 
-                    AD_ReplicationStrategy_ID, AD_TABLE_ID, REPLICATIONTYPE, EntityType) 
-                VALUES (v_NextNo, :new.AD_Client_ID, :new.AD_Org_ID, 
-                 'Y', now(), 0, now(), 0, 
-                    CUR_Replication.AD_ReplicationStrategy_ID, :new.AD_Table_ID, 'L', :new.EntityType); 
-            END LOOP; 
-        END; 
- END IF; -- Inserting 
- 
- -- Update TableName 
- --  Sync TableName 
- IF UPDATING THEN 
-   IF (COALESCE(:old.TableName,'.')<>COALESCE(:NEW.TableName,'.')) THEN 
-     UPDATE  AD_Sequence 
-     SET     Name = :new.TableName, 
-    Updated=now() 
-     WHERE   UPPER(Name) = UPPER(:old.TableName) 
-       AND   IsTableID='Y'; 
-   END IF; 
- END IF; -- Updating 
- 
+
+/*************************************************************************
+ * The contents of this file are subject to the Compiere License
+ * Version 2.5.0 ("License"); You may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.compiere.org/license.html
+ * Software distributed under the License is distributed on an
+ * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing rights
+ * and limitations under the License.
+ * The Original Code is  Compiere  ERP &  Business Solution
+ * The Initial Developer of the Original Code is Jorg Janke  and ComPiere,
+Inc.
+ * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
+ * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
+ * All Rights Reserved.
+ * Contributor(s): Openbravo SL
+ * Contributions are Copyright (C) 1999-2005 Openbravo, S.L
+ *************************************************************************
+ * $Id: AD_Table_Trg.sql,v 1.2 2003/07/26 04:29:44 jjanke Exp $
+ ***
+ * Title:   Synchronize with AD_Sequence and AD_Replication
+ * Description:
+ ************************************************************************/
+
+   TYPE RECORD IS REF CURSOR;
+   CUR_Replication RECORD;
+
+  v_NextNo      NUMBER;
+  v_CurrentNext    NUMBER;
+  v_CurrentNextSys NUMBER;
+  v_StartWith     VARCHAR(7);
+  v_StartWithSys    VARCHAR(7);
+
+
+BEGIN
+ -- Insert new Key Sequence
+ IF INSERTING THEN
+
+  --try to get CurrentNext
+  BEGIN
+   EXECUTE IMMEDIATE 'SELECT 1 + COALESCE((SELECT MAX('||:new.tableName||'_id)'||
+                                'FROM '||:new.tableName||
+                     ' WHERE '||:new.tableName||'_ID>=1000000),1000000-1)'||
+            ' from dual' into v_CurrentNext;
+
+   Exception WHEN OTHERS THEN
+     v_CurrentNext := 1000000;
+  END;
+
+  --try to get CurrentNextSys
+  BEGIN
+    SELECT TAD_LEVEL INTO v_StartWithSys
+    FROM AD_SYSTEM
+    WHERE AD_SYSTEM_ID=0;
+
+   v_StartWith    := TO_CHAR(TO_NUMBER(v_StartWithSys)+1) || '00000';
+   v_StartWithSys := v_StartWithSys || '00000';
+
+   IF (UPPER(:new.TableName) LIKE 'AD_%') THEN
+       EXECUTE IMMEDIATE ' SELECT 1 + (CASE SIGN(COALESCE((SELECT MAX(' || :new.tableName ||'_ID) FROM '||:new.tableName||
+             ' WHERE ' ||:new.tableName || '_ID<' || v_StartWith ||'),0)-' || v_StartWithSys || ') WHEN -1 THEN '||v_StartWithSys || '-1 ELSE ' || '(SELECT MAX(' ||:new.Name || '_ID) FROM ' ||:new.Name||
+             ' WHERE ' ||:new.tableName ||'_ID<' || v_StartWith || ') END) AS SEQUENCE '||
+             ' FROM dual' INTO v_CurrentNextSys;
+   ELSE
+     EXECUTE IMMEDIATE ' SELECT 1 + COALESCE((SELECT MAX('||:new.tableName||'_ID) FROM ' ||:new.tableName||' WHERE ' ||:new.tableName||'_ID<' || v_StartWith ||'),(' || v_StartWithSys || '-1))' ||
+             ' FROM dual' INTO v_CurrentNextSys;
+   END IF;
+   Exception WHEN OTHERS THEN v_CurrentNextSys := 100;
+  END;
+
+  -- Make sure that we can insert
+  DELETE FROM AD_Sequence
+  WHERE  UPPER(Name) = UPPER(:new.TableName);
+     --  Get next number
+     AD_Sequence_Next('AD_Sequence', :new.AD_Table_ID, v_NextNo);
+
+
+   --  Insert
+     INSERT INTO AD_Sequence
+         (AD_Sequence_ID, AD_Client_ID, AD_Org_ID,
+         IsActive, Created, CreatedBy, Updated, UpdatedBy,
+         Name, Description,
+         IsAutoSequence, StartNo, IncrementNo, CurrentNextSys, CurrentNext,
+         IsAudited, IsTableID, StartNewYear)
+     VALUES
+         (v_NextNo, :new.AD_Client_ID, :new.AD_Org_ID,
+         'Y', now(), 0, now(), 0,
+         :new.TableName, :new.TableName,
+         'Y', 1000000, 1, v_CurrentNextSys, v_CurrentNext,
+         'N', 'Y', 'N');
+        --
+        DECLARE
+
+        BEGIN
+            FOR CUR_Replication IN (SELECT  AD_ReplicationStrategy_ID
+                            FROM    AD_ReplicationStrategy) LOOP
+             AD_Sequence_Next('AD_ReplicationTable', :new.AD_Table_ID, v_NextNo);
+                INSERT INTO AD_ReplicationTable
+                    (AD_ReplicationTable_ID, AD_Client_ID, AD_Org_ID,
+                 IsActive, Created, CreatedBy, Updated, UpdatedBy,
+                    AD_ReplicationStrategy_ID, AD_TABLE_ID, REPLICATIONTYPE, EntityType)
+                VALUES (v_NextNo, :new.AD_Client_ID, :new.AD_Org_ID,
+                 'Y', now(), 0, now(), 0,
+                    CUR_Replication.AD_ReplicationStrategy_ID, :new.AD_Table_ID, 'L', :new.EntityType);
+            END LOOP;
+        END;
+ END IF; -- Inserting
+
+ -- Update TableName
+ --  Sync TableName
+ IF UPDATING THEN
+   IF (COALESCE(:old.TableName,'.')<>COALESCE(:NEW.TableName,'.')) THEN
+     UPDATE  AD_Sequence
+     SET     Name = :new.TableName,
+    Updated=now()
+     WHERE   UPPER(Name) = UPPER(:old.TableName)
+       AND   IsTableID='Y';
+   END IF;
+ END IF; -- Updating
+
 END AD_TABLE_TRG
 ]]></body>
     </trigger>
--- a/database/model/triggers/AD_TAB_TRG2.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/AD_TAB_TRG2.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -33,7 +33,7 @@
     IF NOT((COALESCE(:old.NAME,'.')<>COALESCE(:NEW.NAME,'.') OR COALESCE(:old.IsActive,'.')<>COALESCE(:NEW.IsActive,'.'))) THEN
       RETURN;
     END IF;
-    
+
     SELECT MAX(TO_CHAR(ISACTIVE)) INTO v_IsActive
     FROM AD_WINDOW
     WHERE AD_WINDOW_ID = :NEW.AD_WINDOW_ID;
@@ -41,24 +41,24 @@
     IF v_IsActive <> 'Y' THEN
       v_IsActive := :NEW.ISACTIVE;
     END IF;
-    
+
     SELECT AD_MAPPING_FORMAT(TO_CHAR(W.NAME)), AD_MAPPING_FORMAT(TO_CHAR(:new.NAME))
     INTO v_WindowName, v_ClassName
     FROM AD_WINDOW W
     WHERE W.AD_WINDOW_ID = :new.AD_WINDOW_ID;
-    
-    SELECT COUNT(*) INTO v_Count 
+
+    SELECT COUNT(*) INTO v_Count
     FROM AD_MODEL_OBJECT
     WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W'
     AND CLASSNAME LIKE 'org.openbravo.erpWindows.%';
-    
+
     IF v_Count > 0 THEN
-      SELECT AD_MODEL_OBJECT_ID INTO v_ID 
+      SELECT AD_MODEL_OBJECT_ID INTO v_ID
       FROM AD_MODEL_OBJECT
       WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W'
       AND CLASSNAME LIKE 'org.openbravo.erpWindows.%';
-    
-      UPDATE AD_MODEL_OBJECT 
+
+      UPDATE AD_MODEL_OBJECT
       SET AD_CLIENT_ID = :new.AD_CLIENT_ID,
         AD_ORG_ID = :new.AD_ORG_ID,
         ISACTIVE = v_IsActive,
@@ -66,23 +66,23 @@
         UPDATEDBY = :new.UPDATEDBY,
         CLASSNAME = 'org.openbravo.erpWindows.' || v_WindowName || '.' || v_ClassName
       WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W'
-      AND CLASSNAME LIKE 'org.openbravo.erpWindows.%'; 
-      
+      AND CLASSNAME LIKE 'org.openbravo.erpWindows.%';
+
     ELSE
       Ad_Sequence_Next('AD_Model_Object', :new.AD_Client_ID, v_ID);
       INSERT INTO AD_MODEL_OBJECT (AD_MODEL_OBJECT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
       UPDATED, UPDATEDBY, ACTION, AD_TAB_ID, CLASSNAME, ISDEFAULT)
       VALUES (v_ID, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, now(), :new.CREATEDBY,
       now(), :new.UPDATEDBY, 'W', :new.AD_TAB_ID, 'org.openbravo.erpWindows.' || v_WindowName || '.' || v_ClassName, 'Y');
-      
-    END IF; 
 
-    SELECT COUNT(*) INTO v_Count 
+    END IF;
+
+    SELECT COUNT(*) INTO v_Count
     FROM AD_MODEL_OBJECT_MAPPING
     WHERE AD_MODEL_OBJECT_ID IN (
       SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W')
     AND MAPPINGNAME LIKE '/%/%_Relation.html';
-    
+
     IF v_Count > 0 THEN
       UPDATE AD_MODEL_OBJECT_MAPPING
       SET AD_CLIENT_ID = :new.AD_CLIENT_ID,
@@ -94,22 +94,22 @@
       WHERE AD_MODEL_OBJECT_ID IN (
         SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W')
       AND MAPPINGNAME LIKE '/%/%_Relation.html';
-      
+
     ELSE
       Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP);
       INSERT INTO AD_MODEL_OBJECT_MAPPING (AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
       ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID, MAPPINGNAME, ISDEFAULT)
       VALUES (v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, now(), :new.CREATEDBY,
       now(), :new.UPDATEDBY, v_ID, ('/' || v_WindowName || '/' || v_ClassName || '_Relation.html'), 'Y');
-      
+
     END IF;
-  
-    SELECT COUNT(*) INTO v_Count 
+
+    SELECT COUNT(*) INTO v_Count
     FROM AD_MODEL_OBJECT_MAPPING
     WHERE AD_MODEL_OBJECT_ID IN (
       SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W')
     AND MAPPINGNAME LIKE '/%/%_Edition.html';
-    
+
     IF v_Count > 0 THEN
       UPDATE AD_MODEL_OBJECT_MAPPING
       SET AD_CLIENT_ID = :new.AD_CLIENT_ID,
@@ -121,23 +121,23 @@
       WHERE AD_MODEL_OBJECT_ID IN (
         SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W')
       AND MAPPINGNAME LIKE '/%/%_Edition.html';
-      
+
     ELSE
       Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP);
       INSERT INTO AD_MODEL_OBJECT_MAPPING (AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
       ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID, MAPPINGNAME, ISDEFAULT)
       VALUES (v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, now(), :new.CREATEDBY,
       now(), :new.UPDATEDBY, v_ID, ('/' || v_WindowName || '/' || v_ClassName || '_Edition.html'), 'N');
-      
+
     END IF;
-  
-    SELECT COUNT(*) INTO v_Count 
+
+    SELECT COUNT(*) INTO v_Count
     FROM AD_MODEL_OBJECT_MAPPING
     WHERE AD_MODEL_OBJECT_ID IN (
       SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W')
-    AND MAPPINGNAME LIKE '/%/%_Excel.xls';  
-    
-    IF v_Count > 0 THEN  
+    AND MAPPINGNAME LIKE '/%/%_Excel.xls';
+
+    IF v_Count > 0 THEN
       UPDATE AD_MODEL_OBJECT_MAPPING
       SET AD_CLIENT_ID = :new.AD_CLIENT_ID,
         AD_ORG_ID = :new.AD_ORG_ID,
@@ -147,24 +147,24 @@
         MAPPINGNAME = ('/' || v_WindowName || '/' || v_ClassName || '_Excel.xls')
       WHERE AD_MODEL_OBJECT_ID IN (
         SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W')
-      AND MAPPINGNAME LIKE '/%/%_Excel.xls';  
-      
+      AND MAPPINGNAME LIKE '/%/%_Excel.xls';
+
     ELSE
       Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP);
       INSERT INTO AD_MODEL_OBJECT_MAPPING (AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
       ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID, MAPPINGNAME, ISDEFAULT)
       VALUES (v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, now(), :new.CREATEDBY,
       now(), :new.UPDATEDBY, v_ID, ('/' || v_WindowName || '/' || v_ClassName || '_Excel.xls'), 'N');
-      
+
     END IF;
-  
-    SELECT COUNT(*) INTO v_Count 
+
+    SELECT COUNT(*) INTO v_Count
     FROM AD_MODEL_OBJECT
     WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W'
     AND CLASSNAME LIKE 'org.openbravo.erpCommon.ad_callouts.ComboReloads%';
-    
+
     IF v_Count > 0 THEN
-      UPDATE AD_MODEL_OBJECT 
+      UPDATE AD_MODEL_OBJECT
       SET AD_CLIENT_ID = :new.AD_CLIENT_ID,
         AD_ORG_ID = :new.AD_ORG_ID,
         ISACTIVE = v_IsActive,
@@ -172,24 +172,24 @@
         UPDATEDBY = :new.UPDATEDBY,
         CLASSNAME = 'org.openbravo.erpCommon.ad_callouts.ComboReloads' || :new.ad_tab_id
       WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W'
-      AND CLASSNAME LIKE 'org.openbravo.erpCommon.ad_callouts.ComboReloads%';  
-      
+      AND CLASSNAME LIKE 'org.openbravo.erpCommon.ad_callouts.ComboReloads%';
+
     ELSE
       Ad_Sequence_Next('AD_Model_Object', :new.AD_Client_ID, v_ID);
       INSERT INTO AD_MODEL_OBJECT (AD_MODEL_OBJECT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
       UPDATED, UPDATEDBY, ACTION, AD_TAB_ID, CLASSNAME, ISDEFAULT)
       VALUES (v_ID, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, now(), :new.CREATEDBY,
       now(), :new.UPDATEDBY, 'W', :new.AD_TAB_ID, 'org.openbravo.erpCommon.ad_callouts.ComboReloads' || :new.ad_tab_id, 'N');
-      
+
     END IF;
- 
-    SELECT COUNT(*) INTO v_Count 
+
+    SELECT COUNT(*) INTO v_Count
     FROM AD_MODEL_OBJECT_MAPPING
     WHERE AD_MODEL_OBJECT_ID IN (
       SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W')
     AND MAPPINGNAME LIKE '/ad_callouts/ComboReloads%.html';
-    
-    IF v_Count > 0 THEN  
+
+    IF v_Count > 0 THEN
       UPDATE AD_MODEL_OBJECT_MAPPING
       SET AD_CLIENT_ID = :new.AD_CLIENT_ID,
         AD_ORG_ID = :new.AD_ORG_ID,
@@ -200,18 +200,18 @@
       WHERE AD_MODEL_OBJECT_ID IN (
         SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W')
       AND MAPPINGNAME LIKE '/ad_callouts/ComboReloads%.html';
-    
+
     ELSE
       Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP);
       INSERT INTO AD_MODEL_OBJECT_MAPPING (AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
       ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID, MAPPINGNAME, ISDEFAULT)
       VALUES (v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, now(), :new.CREATEDBY,
       now(), :new.UPDATEDBY, v_ID, ('/ad_callouts/ComboReloads' || :new.ad_tab_id || '.html'), 'N');
-      
+
     END IF;
-  
+
  END IF;
- 
+
  IF (DELETING) THEN
   DELETE FROM AD_MODEL_OBJECT_MAPPING WHERE AD_MODEL_OBJECT_ID IN (
       SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W');
--- a/database/model/triggers/AD_TREENODE_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/AD_TREENODE_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -33,7 +33,7 @@
     SELECT TREETYPE INTO v_TreeType
     FROM AD_TREE
     WHERE AD_TREE_ID = :new.AD_TREE_ID;
- 
+
     IF (v_TreeType='AR' AND :new.parent_id<>0) THEN
 
       SELECT COUNT(*) INTO v_EqualAcctSchema
--- a/database/model/triggers/AD_WINDOW_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/AD_WINDOW_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -99,7 +99,7 @@
         WHERE AD_Window_ID=:new.AD_Window_ID
           AND IsCentrallyMaintained='Y';
     END IF;
-    
+
     -- Translation
     UPDATE AD_Window_Trl
       SET IsTranslated='N',
--- a/database/model/triggers/AD_WINDOW_TRL_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/AD_WINDOW_TRL_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -34,7 +34,7 @@
       IF UPDATING THEN
        IF(COALESCE(:old.Name, '.') <> COALESCE(:NEW.Name, '.')
        OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')
-       OR COALESCE(:old.Help, '.') <> COALESCE(:NEW.Help, '.')) 
+       OR COALESCE(:old.Help, '.') <> COALESCE(:NEW.Help, '.'))
        THEN
     -- Update Menu
   UPDATE AD_Menu_Trl
--- a/database/model/triggers/AD_WORKBENCH_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/AD_WORKBENCH_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -63,7 +63,7 @@
     Description=:new.Description
   WHERE AD_Workbench_ID=:new.AD_Workbench_ID;
   -- reset Translation flag
-  IF( COALESCE(:old.Name,'.') <> COALESCE(:new.Name,'.') 
+  IF( COALESCE(:old.Name,'.') <> COALESCE(:new.Name,'.')
   OR COALESCE(:old.Description,'.') <> COALESCE(:new.Description,'.')
   OR COALESCE(:old.Help,'.') <> COALESCE(:new.Help,'.') ) THEN
     UPDATE AD_Workbench_Trl
--- a/database/model/triggers/A_AMORTIZATIONLINE_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/A_AMORTIZATIONLINE_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -32,7 +32,7 @@
   ELSE
     v_AmortizationID := :OLD.A_Amortization_ID;
   END IF;
-  
+
     begin
       SELECT processed,
              POSTED
--- a/database/model/triggers/A_AMORTIZATION_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/A_AMORTIZATION_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -43,7 +43,7 @@
     OR COALESCE(:old.USER1_ID, 0)!=COALESCE(:new.USER1_ID, 0)
     OR COALESCE(:old.USER2_ID, 0)!=COALESCE(:new.USER2_ID, 0)
     OR COALESCE(:old.C_CURRENCY_ID, 0)!=COALESCE(:new.C_CURRENCY_ID, 0)
-    OR COALESCE(:old.TOTALAMORTIZATION, 0)!=COALESCE(:new.TOTALAMORTIZATION, 0) 
+    OR COALESCE(:old.TOTALAMORTIZATION, 0)!=COALESCE(:new.TOTALAMORTIZATION, 0)
     OR COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0)
     OR COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0) ))
     THEN  RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
--- a/database/model/triggers/C_BANKACCOUNTIBAN_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_BANKACCOUNTIBAN_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -33,7 +33,7 @@
   v_DigitBank NVARCHAR2(1);
   v_Country NUMBER;
   v_CountryId NVARCHAR2(2);
-  v_Length NUMBER;  
+  v_Length NUMBER;
 BEGIN
   --  Default Accounts for all AcctSchema
   IF(INSERTING OR UPDATING) THEN
@@ -79,7 +79,7 @@
           RAISE_APPLICATION_ERROR(-20259, 'The IBAN number defined in the bank account tab, must fit the IBAN data of the country defined in the bank tab.');
         END IF;
       END IF;
-    IF (:NEW.SHOWSPANISH='Y') THEN 
+    IF (:NEW.SHOWSPANISH='Y') THEN
       SELECT CODEBANK, CODEBRANCH, DIGITCONTROL
       INTO v_Bank, v_Branch, v_DigitBank
       FROM C_BANK
--- a/database/model/triggers/C_BANKCOUNTRY_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_BANKCOUNTRY_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -35,7 +35,7 @@
   v_DigitBank NVARCHAR2(1);
   v_Country NUMBER;
   v_CountryId NVARCHAR2(2);
-  v_Length NUMBER;  
+  v_Length NUMBER;
 BEGIN
   --  Default Accounts for all AcctSchema
   IF(INSERTING OR UPDATING) THEN
--- a/database/model/triggers/C_BP_BANKACCOUNTIBAN_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_BP_BANKACCOUNTIBAN_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -32,7 +32,7 @@
   v_Branch NVARCHAR2(4);
   v_DigitBank NVARCHAR2(1);
   v_CountryId NVARCHAR2(2);
-  v_Length NUMBER;  
+  v_Length NUMBER;
 BEGIN
   --  Default Accounts for all AcctSchema
   IF(INSERTING OR UPDATING) THEN
--- a/database/model/triggers/C_BP_SALCATEGORY_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_BP_SALCATEGORY_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -2,7 +2,7 @@
   <database name="TRIGGER C_BP_SALCATEGORY_TRG">
     <trigger name="C_BP_SALCATEGORY_TRG" table="C_BP_SALCATEGORY" fires="before" insert="true" update="true" delete="false" foreach="row">
       <body><![CDATA[
-	  
+
 /*************************************************************************
 * The contents of this file are subject to the Openbravo  Public  License
 * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
@@ -25,7 +25,7 @@
 
 BEGIN
 
-      
+
   IF (UPDATING OR INSERTING)  THEN
 
     SELECT ISCOSTAPPLIED INTO v_isCostApplied
@@ -34,26 +34,26 @@
 
     IF (v_isCostApplied='Y') THEN
 
-      SELECT COUNT(*) INTO v_count 
-      FROM C_SALARY_CATEGORY_COST 
+      SELECT COUNT(*) INTO v_count
+      FROM C_SALARY_CATEGORY_COST
       WHERE C_SALARY_CATEGORY_ID=:NEW.C_SALARY_CATEGORY_ID;
-      
+
       IF (v_count=0) THEN
         RAISE_APPLICATION_ERROR(-20519,'@Salary Category without cost@');
-      ELSE      
-    
-        SELECT COUNT(*) INTO v_count 
-        FROM C_SALARY_CATEGORY_COST 
-        WHERE C_SALARY_CATEGORY_ID=:NEW.C_SALARY_CATEGORY_ID 
+      ELSE
+
+        SELECT COUNT(*) INTO v_count
+        FROM C_SALARY_CATEGORY_COST
+        WHERE C_SALARY_CATEGORY_ID=:NEW.C_SALARY_CATEGORY_ID
         AND DATEFROM<=:NEW.DATEFROM;
 
-        IF (v_count=0) THEN		
+        IF (v_count=0) THEN
           RAISE_APPLICATION_ERROR(-20518,'@Cost not available for Dates@');
         END IF;
       END IF;
     END IF;
   END IF;
-  
+
 
 END C_BP_SALCATEGORY_TRG
 ]]></body>
--- a/database/model/triggers/C_BP_SALCATEGORY_TRG2.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_BP_SALCATEGORY_TRG2.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -2,7 +2,7 @@
   <database name="TRIGGER C_BP_SALCATEGORY_TRG2">
     <trigger name="C_BP_SALCATEGORY_TRG2" table="C_BP_SALCATEGORY" fires="after" insert="true" update="true" delete="true" foreach="statement">
       <body><![CDATA[
-	  
+
 /*************************************************************************
 * The contents of this file are subject to the Openbravo  Public  License
 * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
@@ -22,47 +22,47 @@
   v_count NUMBER;
   v_dateFrom DATE;
   v_cBPSalCategory NUMBER(10);
-  
+
   TYPE RECORD IS REF CURSOR;
   Cur_Employees RECORD;
-   
+
 BEGIN
 
-     
+
   IF (UPDATING OR INSERTING OR DELETING)  THEN
 
     FOR Cur_Employees IN (SELECT C_BPARTNER_ID
                           FROM C_BPARTNER
-                          WHERE ISEMPLOYEE = 'Y') LOOP 
-                          
+                          WHERE ISEMPLOYEE = 'Y') LOOP
+
     SELECT MAX(DATEFROM)
-    INTO v_dateFrom 
+    INTO v_dateFrom
     FROM C_BP_SALCATEGORY
     WHERE C_BP_SALCATEGORY.C_BPARTNER_ID = Cur_Employees.C_BPARTNER_ID;
-    
+
     v_cBPSalCategory := null;
-    
+
     SELECT COUNT(*) INTO v_count
-    FROM C_BP_SALCATEGORY 
+    FROM C_BP_SALCATEGORY
     WHERE C_BP_SALCATEGORY.C_BPARTNER_ID = Cur_Employees.C_BPARTNER_ID
     AND DATEFROM = v_dateFrom;
-    
+
     IF (v_count<>0) THEN
-    
+
       SELECT C_SALARY_CATEGORY_ID INTO v_cBPSalCategory
-      FROM C_BP_SALCATEGORY 
+      FROM C_BP_SALCATEGORY
       WHERE C_BP_SALCATEGORY.C_BPARTNER_ID = Cur_Employees.C_BPARTNER_ID
       AND DATEFROM = v_dateFrom;
-    
+
     END IF;
-    
+
     UPDATE C_BPARTNER SET
     C_SALARY_CATEGORY_ID = v_cBPSalCategory
     WHERE C_BPARTNER.C_BPARTNER_ID = Cur_Employees.C_BPARTNER_ID;
-    
+
     END LOOP;
   END IF;
-  
+
 
 END C_BP_SALCATEGORY_TRG2
 ]]></body>
--- a/database/model/triggers/C_BSTMTLINE_CHK_RESTRICT_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_BSTMTLINE_CHK_RESTRICT_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -7,57 +7,57 @@
 
 
 
-    /************************************************************************* 
-    * The contents of this file are subject to the Openbravo  Public  License 
-    * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License 
-    * Version 1.1  with a permitted attribution clause; you may not  use this 
-    * file except in compliance with the License. You  may  obtain  a copy of 
-    * the License at http://www.openbravo.com/legal/license.html 
-    * Software distributed under the License  is  distributed  on  an "AS IS" 
-    * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
-    * License for the specific  language  governing  rights  and  limitations 
-    * under the License. 
-    * The Original Code is Openbravo ERP. 
-    * The Initial Developer of the Original Code is Openbravo SL 
-    * All portions are Copyright (C) 2001-2006 Openbravo SL 
-    * All Rights Reserved. 
-    * Contributor(s):  ______________________________________. 
+    /*************************************************************************
+    * The contents of this file are subject to the Openbravo  Public  License
+    * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
+    * Version 1.1  with a permitted attribution clause; you may not  use this
+    * file except in compliance with the License. You  may  obtain  a copy of
+    * the License at http://www.openbravo.com/legal/license.html
+    * Software distributed under the License  is  distributed  on  an "AS IS"
+    * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+    * License for the specific  language  governing  rights  and  limitations
+    * under the License.
+    * The Original Code is Openbravo ERP.
+    * The Initial Developer of the Original Code is Openbravo SL
+    * All portions are Copyright (C) 2001-2006 Openbravo SL
+    * All Rights Reserved.
+    * Contributor(s):  ______________________________________.
     ************************************************************************/
-  v_Processed CHAR(1) ; 
-  v_Posted             CHAR(1) ; 
+  v_Processed CHAR(1) ;
+  v_Posted             CHAR(1) ;
   v_C_BANKSTATEMENT_ID NUMBER(10) ;
   v_DateNull DATE := TO_DATE('01-01-1900', 'DD-MM-YYYY');
-BEGIN 
-  IF INSERTING THEN 
-    v_C_BANKSTATEMENT_ID:=:NEW.C_BANKSTATEMENT_ID; 
-  ELSE 
-    v_C_BANKSTATEMENT_ID:=:OLD.C_BANKSTATEMENT_ID; 
-  END IF; 
-  SELECT PROCESSED, 
-    POSTED 
-  INTO v_Processed, 
-    v_Posted 
-  FROM C_BANKSTATEMENT 
-  WHERE C_BANKSTATEMENT_ID=v_C_BANKSTATEMENT_ID; 
-  IF UPDATING THEN 
-    IF(v_Processed='Y' 
-      AND ((COALESCE(:OLD.LINE, 0) <> COALESCE(:NEW.LINE, 0)) 
-      OR(COALESCE(:OLD.C_CHARGE_ID, 0) <> COALESCE(:NEW.C_CHARGE_ID, 0)) 
-      OR(COALESCE(:OLD.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0)) 
+BEGIN
+  IF INSERTING THEN
+    v_C_BANKSTATEMENT_ID:=:NEW.C_BANKSTATEMENT_ID;
+  ELSE
+    v_C_BANKSTATEMENT_ID:=:OLD.C_BANKSTATEMENT_ID;
+  END IF;
+  SELECT PROCESSED,
+    POSTED
+  INTO v_Processed,
+    v_Posted
+  FROM C_BANKSTATEMENT
+  WHERE C_BANKSTATEMENT_ID=v_C_BANKSTATEMENT_ID;
+  IF UPDATING THEN
+    IF(v_Processed='Y'
+      AND ((COALESCE(:OLD.LINE, 0) <> COALESCE(:NEW.LINE, 0))
+      OR(COALESCE(:OLD.C_CHARGE_ID, 0) <> COALESCE(:NEW.C_CHARGE_ID, 0))
+      OR(COALESCE(:OLD.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0))
       OR(COALESCE(:OLD.STMTAMT, 0) <> COALESCE(:NEW.STMTAMT, 0))
-      OR(COALESCE(:OLD.TRXAMT, 0) <> COALESCE(:NEW.TRXAMT, 0)) 
+      OR(COALESCE(:OLD.TRXAMT, 0) <> COALESCE(:NEW.TRXAMT, 0))
       OR(COALESCE(:OLD.C_DEBT_PAYMENT_ID, 0) <> COALESCE(:NEW.C_DEBT_PAYMENT_ID, 0))
       OR(COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0))
-      OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0)) )) THEN 
+      OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0)) )) THEN
       RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
-    END IF; 
-    IF(v_Posted='Y' AND ((COALESCE(:OLD.DATEACCT, v_DateNull) <> COALESCE(:NEW.DATEACCT, v_DateNull)))) THEN 
+    END IF;
+    IF(v_Posted='Y' AND ((COALESCE(:OLD.DATEACCT, v_DateNull) <> COALESCE(:NEW.DATEACCT, v_DateNull)))) THEN
       RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
-    END IF; 
-  END IF; 
-  IF((DELETING OR INSERTING) AND v_Processed='Y') THEN 
+    END IF;
+  END IF;
+  IF((DELETING OR INSERTING) AND v_Processed='Y') THEN
     RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
-  END IF; 
+  END IF;
 END C_BSTMTLINE_CHK_RESTRICT_TRG
 ]]></body>
     </trigger>
--- a/database/model/triggers/C_BUDGETLINE_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_BUDGETLINE_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -26,7 +26,7 @@
     * Description:
     *    - create default Account records
     ************************************************************************/
-  v_Type NUMBER;  
+  v_Type NUMBER;
 BEGIN
   IF(INSERTING OR UPDATING) THEN
     SELECT BUDGET_TYPE
--- a/database/model/triggers/C_CASHLINE_CHK_RESTRICT_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_CASHLINE_CHK_RESTRICT_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -33,7 +33,7 @@
   END IF;
   SELECT PROCESSED INTO v_Processed FROM C_CASH WHERE C_CASH_ID=v_C_CASH_ID;
   IF UPDATING THEN
-    IF(v_Processed='Y' 
+    IF(v_Processed='Y'
       AND (
         (COALESCE(:OLD.LINE, 0) <> COALESCE(:NEW.LINE, 0))
         OR(COALESCE(:OLD.C_CHARGE_ID, 0) <> COALESCE(:NEW.C_CHARGE_ID, 0))
@@ -42,7 +42,7 @@
         OR(COALESCE(:OLD.DISCOUNTAMT, 0) <> COALESCE(:NEW.DISCOUNTAMT, 0))
         OR(COALESCE(:OLD.WRITEOFFAMT, 0) <> COALESCE(:NEW.WRITEOFFAMT, 0))
         OR(
-          COALESCE(:OLD.C_DEBT_PAYMENT_ID, 0) <> COALESCE(:NEW.C_DEBT_PAYMENT_ID, 0) 
+          COALESCE(:OLD.C_DEBT_PAYMENT_ID, 0) <> COALESCE(:NEW.C_DEBT_PAYMENT_ID, 0)
           AND(:OLD.C_ORDER_ID IS NULL))
         OR(COALESCE(:OLD.C_ORDER_ID, 0) <> COALESCE(:NEW.C_ORDER_ID, 0))
         OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0)))) THEN
--- a/database/model/triggers/C_CASH_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_CASH_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -31,10 +31,10 @@
         OR(COALESCE(:old.USER1_ID, 0) <> COALESCE(:new.USER1_ID, 0))
         OR(COALESCE(:old.USER2_ID, 0) <> COALESCE(:new.USER2_ID, 0))
         OR(COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0))
-        OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0)))) THEN 
+        OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0)))) THEN
           RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
       END IF;
-      IF(:old.Posted='Y' 
+      IF(:old.Posted='Y'
         AND ((COALESCE(:old.DATEACCT, v_DateNull) <> COALESCE(:new.DATEACCT, v_DateNull))
         OR(COALESCE(:old.C_CAMPAIGN_ID, 0) <> COALESCE(:new.C_CAMPAIGN_ID, 0))
         OR(COALESCE(:old.C_PROJECT_ID, 0) <> COALESCE(:new.C_PROJECT_ID, 0))
@@ -42,7 +42,7 @@
           RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
       END IF;
     END IF;
-    
+
    IF(DELETING) THEN
     IF(:old.Processed='Y') THEN
       RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
--- a/database/model/triggers/C_CONVERSION_RATE_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_CONVERSION_RATE_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -5,105 +5,105 @@
 
 
 
- 
-    /************************************************************************* 
-    * The contents of this file are subject to the Compiere License 
-    * Version 2.5.0 ("License"); You may not use this file except in 
-    * compliance with the License. You may obtain a copy of the License at 
-    * http://www.compiere.org/license.html 
-    * Software distributed under the License is distributed on an 
-    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 
-    * implied. See the License for the specific language governing rights 
-    * and limitations under the License. 
-    * The Original Code is  Compiere  ERP &  Business Solution 
-    * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, 
-    Inc. 
-    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, 
-    * parts created by ComPiere are Copyright (C) ComPiere, Inc.; 
-    * All Rights Reserved. 
-    * Contributor(s): Openbravo SL 
-    * Contributions are Copyright (C) 1999-2005 Openbravo, S.L 
-    ************************************************************************* 
-    * $Id: C_Conversion_Rate_Trg.sql,v 1.3 2002/10/08 13:25:46 jjanke Exp $ 
-    *** 
-    * Title: Set ToDate 
-    * Description: 
-    * If there is no valid ToDate set it to arbitrary end date 
-    ************************************************************************/ 
-      v_Count NUMBER; 
-  BEGIN   
-  --RAISE_APPLICATION_ERROR (-20506, 'Cannot modify used rate'); 
-  IF(:new.ValidTo IS NULL) THEN 
-    -- If there is no end date, set it to X 
+
+    /*************************************************************************
+    * The contents of this file are subject to the Compiere License
+    * Version 2.5.0 ("License"); You may not use this file except in
+    * compliance with the License. You may obtain a copy of the License at
+    * http://www.compiere.org/license.html
+    * Software distributed under the License is distributed on an
+    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+    * implied. See the License for the specific language governing rights
+    * and limitations under the License.
+    * The Original Code is  Compiere  ERP &  Business Solution
+    * The Initial Developer of the Original Code is Jorg Janke  and ComPiere,
+    Inc.
+    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
+    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
+    * All Rights Reserved.
+    * Contributor(s): Openbravo SL
+    * Contributions are Copyright (C) 1999-2005 Openbravo, S.L
+    *************************************************************************
+    * $Id: C_Conversion_Rate_Trg.sql,v 1.3 2002/10/08 13:25:46 jjanke Exp $
+    ***
+    * Title: Set ToDate
+    * Description:
+    * If there is no valid ToDate set it to arbitrary end date
+    ************************************************************************/
+      v_Count NUMBER;
+  BEGIN
+  --RAISE_APPLICATION_ERROR (-20506, 'Cannot modify used rate');
+  IF(:new.ValidTo IS NULL) THEN
+    -- If there is no end date, set it to X
       :new.ValidTo:=TO_DATE('31-12-9999', 'DD-MM-YYYY') ;
-  END IF; 
-  --Check for invalid dates 
-  IF :new.ValidTo < :new.ValidFrom THEN 
+  END IF;
+  --Check for invalid dates
+  IF :new.ValidTo < :new.ValidFrom THEN
     RAISE_APPLICATION_ERROR(-20505, 'Date To is lower than Date From');
-  END IF; 
-   
-  IF UPDATING THEN 
-     --Check for changes of used rates 
-    /*select count(*) 
-      into v_Count 
-      from c_bankstatement     b, 
-          c_bankstatementline bs, 
-          c_debt_payment      p 
-     where bs.c_debt_payment_id = p.c_debt_payment_id 
-       and b.c_bankstatement_id = bs.c_bankstatement_id 
-       and p.C_currency_id  = :old.C_Currency_ID 
-      and bs.C_currency_id = :old.C_Currency_ID_TO 
-      and b.StatementDate between :old.ValidFrom and :old.ValidTo 
-      and ((not (b.StatementDate between :new.ValidFrom and :new.ValidTo)) 
-          or (:new.C_Currency_ID    != :old.C_Currency_ID) 
-        or (:new.C_Currency_ID_To != :old.C_Currency_ID_To) 
-        or (:new.MultiplyRate     != :old.MultiplyRate) 
-      ) 
-      and processed ='Y';*/ 
-       
-    select count(*)  
-    into v_count 
-     from fact_acct    f, 
-         c_acctschema s 
-    where f.c_acctschema_id = s.c_acctschema_id 
-      and f.c_currency_id = :old.C_Currency_ID 
-     and s.c_currency_id = :old.C_Currency_ID_TO 
-     and f.dateacct between :old.ValidFrom and :old.ValidTo 
-     and ((not (f.dateacct between :new.ValidFrom and :new.ValidTo)) 
-          or (:new.C_Currency_ID    != :old.C_Currency_ID) 
-        or (:new.C_Currency_ID_To != :old.C_Currency_ID_To) 
-        or (:new.MultiplyRate     != :old.MultiplyRate) 
-      ); 
-        
-    IF v_count>0 THEN 
+  END IF;
+
+  IF UPDATING THEN
+     --Check for changes of used rates
+    /*select count(*)
+      into v_Count
+      from c_bankstatement     b,
+          c_bankstatementline bs,
+          c_debt_payment      p
+     where bs.c_debt_payment_id = p.c_debt_payment_id
+       and b.c_bankstatement_id = bs.c_bankstatement_id
+       and p.C_currency_id  = :old.C_Currency_ID
+      and bs.C_currency_id = :old.C_Currency_ID_TO
+      and b.StatementDate between :old.ValidFrom and :old.ValidTo
+      and ((not (b.StatementDate between :new.ValidFrom and :new.ValidTo))
+          or (:new.C_Currency_ID    != :old.C_Currency_ID)
+        or (:new.C_Currency_ID_To != :old.C_Currency_ID_To)
+        or (:new.MultiplyRate     != :old.MultiplyRate)
+      )
+      and processed ='Y';*/
+
+    select count(*)
+    into v_count
+     from fact_acct    f,
+         c_acctschema s
+    where f.c_acctschema_id = s.c_acctschema_id
+      and f.c_currency_id = :old.C_Currency_ID
+     and s.c_currency_id = :old.C_Currency_ID_TO
+     and f.dateacct between :old.ValidFrom and :old.ValidTo
+     and ((not (f.dateacct between :new.ValidFrom and :new.ValidTo))
+          or (:new.C_Currency_ID    != :old.C_Currency_ID)
+        or (:new.C_Currency_ID_To != :old.C_Currency_ID_To)
+        or (:new.MultiplyRate     != :old.MultiplyRate)
+      );
+
+    IF v_count>0 THEN
       RAISE_APPLICATION_ERROR(-20506, 'Cannot modify used rate');
-    END IF;     
-  END IF; 
-  IF DELETING THEN 
-    /*select count(*) 
-      into v_Count 
-      from c_bankstatement     b, 
-          c_bankstatementline bs, 
-          c_debt_payment      p 
-     where bs.c_debt_payment_id = p.c_debt_payment_id 
-       and b.c_bankstatement_id = bs.c_bankstatement_id 
-       and p.C_currency_id  = :old.C_Currency_ID 
-      and bs.C_currency_id = :old.C_Currency_ID_TO 
-      and b.StatementDate between :old.ValidFrom and :old.ValidTo 
-      and processed ='Y';*/ 
-   select count(*)  
-    into v_count 
-     from fact_acct    f, 
-         c_acctschema s 
-    where f.c_acctschema_id = s.c_acctschema_id 
-      and f.c_currency_id = :old.C_Currency_ID 
-     and s.c_currency_id = :old.C_Currency_ID_TO 
-     and f.dateacct between :old.ValidFrom and :old.ValidTo; 
-    IF v_count>0 THEN 
+    END IF;
+  END IF;
+  IF DELETING THEN
+    /*select count(*)
+      into v_Count
+      from c_bankstatement     b,
+          c_bankstatementline bs,
+          c_debt_payment      p
+     where bs.c_debt_payment_id = p.c_debt_payment_id
+       and b.c_bankstatement_id = bs.c_bankstatement_id
+       and p.C_currency_id  = :old.C_Currency_ID
+      and bs.C_currency_id = :old.C_Currency_ID_TO
+      and b.StatementDate between :old.ValidFrom and :old.ValidTo
+      and processed ='Y';*/
+   select count(*)
+    into v_count
+     from fact_acct    f,
+         c_acctschema s
+    where f.c_acctschema_id = s.c_acctschema_id
+      and f.c_currency_id = :old.C_Currency_ID
+     and s.c_currency_id = :old.C_Currency_ID_TO
+     and f.dateacct between :old.ValidFrom and :old.ValidTo;
+    IF v_count>0 THEN
       RAISE_APPLICATION_ERROR(-20506, 'Cannot modify used rate');
-    END IF;   
-  END IF; 
- 
+    END IF;
+  END IF;
+
 END C_CONVERSION_RATE_TRG
 ]]></body>
     </trigger>
--- a/database/model/triggers/C_COUNTRY_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_COUNTRY_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -42,7 +42,7 @@
   SELECT :new.C_COUNTRY_ID,
     AD_Language, :new.AD_Client_ID, :new.AD_Org_ID,
     :new.IsActive, :new.Created, :new.CreatedBy,
-    :new.Updated, :new.UpdatedBy, 
+    :new.Updated, :new.UpdatedBy,
     'N', :new.Name, :new.Description,
     :new.RegionName, :new.DisplaySequence
   FROM AD_Language
--- a/database/model/triggers/C_CURRENCY_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_CURRENCY_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -41,7 +41,7 @@
   SELECT :new.C_CURRENCY_ID,
     AD_Language, :new.AD_Client_ID, :new.AD_Org_ID,
     :new.IsActive, :new.Created, :new.CreatedBy,
-    :new.Updated, :new.UpdatedBy, 
+    :new.Updated, :new.UpdatedBy,
     'N', :new.CurSymbol, :new.Description
   FROM AD_Language
   WHERE IsActive='Y'
--- a/database/model/triggers/C_DEBT_PAYMENT_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_DEBT_PAYMENT_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -58,10 +58,10 @@
         RAISE_APPLICATION_ERROR(-20510, 'The settlement is processed');
       END IF;
     END IF;
-  
+
   IF (COALESCE(:NEW.IsAutomaticGenerated,'Y')='N' AND :NEW.C_Order_ID IS NOT NULL) THEN
       -- Check if it is totally invoiced
-      SELECT COALESCE(SUM(NOTINVOICED),0)  
+      SELECT COALESCE(SUM(NOTINVOICED),0)
         INTO v_Aux
         FROM (SELECT (O.QTYORDERED- COALESCE(LL.QTYINVOICED,0)) AS NOTINVOICED
                 FROM C_ORDERLINE O LEFT JOIN (SELECT IL.C_INVOICELINE_ID, IL.QTYINVOICED, IL.C_ORDERLINE_ID
@@ -80,7 +80,7 @@
              RAISE_APPLICATION_ERROR(-20000, '@OrderCompletelyInvoiced@');
            end if;
         END IF;
-        
+
       -- If Order is processed, DP should be valid
       SELECT PROCESSED
        INTO v_IsProcessed
@@ -90,7 +90,7 @@
          :NEW.IsValid:='Y';
       END IF;
     END IF;
-  
+
   IF (COALESCE(:new.IsAutomaticGenerated,'Y')='N' AND :new.C_Invoice_ID IS NOT NULL) THEN
       SELECT Processed
      INTO v_IsProcessed
--- a/database/model/triggers/C_DPMLINE_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_DPMLINE_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -36,7 +36,7 @@
   FROM C_DP_Management
   WHERE C_DP_Management_ID=v_C_DP_ID;
   IF UPDATING THEN
-    IF(v_Processed='Y' 
+    IF(v_Processed='Y'
       AND ((COALESCE(:OLD.LINE, 0) <> COALESCE(:NEW.LINE, 0))
       OR(COALESCE(:OLD.C_DEBT_PAYMENT_ID, 0) <> COALESCE(:NEW.C_DEBT_PAYMENT_ID, 0))
       OR(COALESCE(:OLD.STATUS_FROM, 0) <> COALESCE(:NEW.STATUS_FROM, 0))
--- a/database/model/triggers/C_INVOICELINE_TRG3.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_INVOICELINE_TRG3.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -22,7 +22,7 @@
 vBusPartId NUMBER;
 vIsSalesInvoice CHAR(1);
 vProcessed  CHAR(1);
---InvoiceLine 
+--InvoiceLine
 v_invoiceid NUMBER;
 vexcludeforwh CHAR(1);
 vlinebaseamountnew NUMBER;
@@ -32,11 +32,11 @@
 baseamountpercent NUMBER;
 includetaxinps CHAR(1);
 taxinps_id NUMBER;
--- Tax 
+-- Tax
 vTaxAmount  NUMBER;
 -- Withholding
 withpercent NUMBER;
---Calculated Variable 
+--Calculated Variable
 vwithholdingnew NUMBER;
 vwithholdingold NUMBER;
 taxamountwith  NUMBER;
@@ -49,22 +49,22 @@
     vexcludeforwh := :NEW.excludeforwithholding;
     vlinebaseamountnew := :NEW.linenetamt;
     vlinebaseamountold := 0;
-    
+
     ELSIF(UPDATING) THEN
       v_invoiceid := :NEW.c_invoice_id;
       vexcludeforwh := :NEW.excludeforwithholding;
       vlinebaseamountnew := :NEW.linenetamt;
       vlinebaseamountold := :OLD.linenetamt;
-      
+
       ELSIF(DELETING) THEN
         v_invoiceid := :OLD.c_invoice_id;
         vexcludeforwh := :OLD.excludeforwithholding;
         vlinebaseamountnew := 0;
         vlinebaseamountold := :OLD.linenetamt;
-        
+
       END IF;
 
-      -- If The lines is excluded for calculate the witholding --> exit 
+      -- If The lines is excluded for calculate the witholding --> exit
       IF vexcludeforwh = 'Y' THEN
         finish_process:= true;
       END IF;
@@ -78,26 +78,26 @@
       -- Se the invoice isn't purchase exit from trigger
       if (vIsSalesInvoice <> 'N') then
         finish_process:= true;
-      end if; 
+      end if;
   END IF;
   IF (NOT finish_process) THEN
     BEGIN
       select bpwh.is_percent_wh, bpwh.wh_percent, bpwh.include_tax, bpwh.c_tax_id,wh.rate
       into isbaseamountpercent, baseamountpercent,  includetaxinps, taxinps_id,withpercent
         from c_bp_withholding bpwh, c_withholding wh
-       where bpwh.c_bpartner_id = vBusPartId 
-       and bpwh.c_withholding_id = wh.c_withholding_id 
+       where bpwh.c_bpartner_id = vBusPartId
+       and bpwh.c_withholding_id = wh.c_withholding_id
        and bpwh.c_withholding_id = vwithid;
 
-    EXCEPTION 
+    EXCEPTION
     When NO_DATA_FOUND THEN
       finish_process:= true;
     end;
   END IF;
   IF (NOT finish_process) THEN
-   -- ReadOnly Check    
+   -- ReadOnly Check
     IF (vProcessed = 'N') THEN
-    
+
       IF(isbaseamountpercent <> 'Y') THEN
         baseamountpercent := 100;
       END IF;
@@ -109,17 +109,17 @@
       vwithholdingold :=(withpercent *vlinebaseamountold) / 100;
 
 
-      -- WithHolding Tax  
+      -- WithHolding Tax
       vTaxAmount := 0;
       IF (includetaxinps = 'Y') THEN
        select coalesce(sum(taxamt),0) into vTaxAmount
-        from c_invoicetax invtax , c_tax tax 
+        from c_invoicetax invtax , c_tax tax
        where tax.c_tax_id = invtax.c_tax_id
         and tax.is_withholdingtax='Y'
         and invtax.c_invoice_id = v_invoiceid
         and tax.c_tax_id=taxinps_id;
       END IF;
-      
+
       taxamountwith := baseamountpercent * (vTaxAmount)/100;
       vwithholdingtax :=  withpercent*taxamountwith/100 ;
 
@@ -132,7 +132,7 @@
       WHERE c_invoice_id = v_invoiceid;
     END IF;
   END IF;
-  
+
 END C_INVOICELINE_TRG3
 ]]></body>
     </trigger>
--- a/database/model/triggers/C_INVOICETAX_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_INVOICETAX_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -39,9 +39,9 @@
     INTO v_Processed
     FROM C_INVOICE
     WHERE C_INVOICE_ID=:old.C_INVOICE_ID;
-    IF(v_Processed='Y' 
-    AND ((COALESCE(:old.TAXBASEAMT, 0) <> COALESCE(:new.TAXBASEAMT, 0)) 
-    OR(COALESCE(:old.TAXAMT, 0) <> COALESCE(:new.TAXAMT, 0)) 
+    IF(v_Processed='Y'
+    AND ((COALESCE(:old.TAXBASEAMT, 0) <> COALESCE(:new.TAXBASEAMT, 0))
+    OR(COALESCE(:old.TAXAMT, 0) <> COALESCE(:new.TAXAMT, 0))
     OR(COALESCE(:old.C_TAX_ID, 0) <> COALESCE(:new.C_TAX_ID, 0))
     OR(COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0))
     OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0)))) THEN
--- a/database/model/triggers/C_INVOICETAX_TRG2.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_INVOICETAX_TRG2.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -60,30 +60,30 @@
         taxamountnew := 0;
         taxamountold := :OLD.taxamt;
       END IF;
-     -- Read data from invoice 
+     -- Read data from invoice
      select c_bpartner_id,withholdingamount,inpsamt,issotrx , coalesce(processed,'N') ,c_withholding_id
      into v_buspartid, whamountold, inpsamountold, vissalesinvoice, vProcessed   ,vwithid
-     from c_invoice 
+     from c_invoice
      where c_invoice_id=v_invoiceid;
      -- Se the invoice isn't purchase exit from trigger
      if (vIsSalesInvoice <> 'N') then
         finish_process:= true;
-     end if; 
+     end if;
 
   IF (NOT finish_process) THEN
      -- Read data from tax
      select is_withholdingtax into v_IsWithTax from c_tax where c_tax_id=v_taxid;
-     
-     -- Read data from Withholding 
+
+     -- Read data from Withholding
      BEGIN
-       select bpwh.is_percent_wh, bpwh.wh_percent, bpwh.include_tax, bpwh.c_tax_id , wh.rate 
+       select bpwh.is_percent_wh, bpwh.wh_percent, bpwh.include_tax, bpwh.c_tax_id , wh.rate
        into isbaseamountpercent, baseamountpercent,  includetaxinps, taxinps_id, withpercent
-       from c_bp_withholding bpwh ,c_withholding wh 
-       where bpwh.c_bpartner_id  = v_buspartid 
+       from c_bp_withholding bpwh ,c_withholding wh
+       where bpwh.c_bpartner_id  = v_buspartid
        and bpwh.c_withholding_id = wh.c_withholding_id
         and bpwh.c_withholding_id = vwithid;
 
-     EXCEPTION 
+     EXCEPTION
       when NO_DATA_FOUND THEN
         finish_process:= true;
      end;
@@ -94,9 +94,9 @@
       END IF;
   END IF;
   IF (NOT finish_process) THEN
-   -- ReadOnly Check    
+   -- ReadOnly Check
     IF (vProcessed = 'N') THEN
-      -- Is the tax is for WithHolding and the BP have the flag activate it add the tax amount 
+      -- Is the tax is for WithHolding and the BP have the flag activate it add the tax amount
       IF (v_IsWithTax= 'Y') and (includetaxinps = 'Y') THEN
         baseamount := baseamountpercent * (taxamountnew-taxamountold)/100;
         whamountnew := whamountold + withpercent*baseamount/100 ;
--- a/database/model/triggers/C_ORDERTAX_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_ORDERTAX_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -48,9 +48,9 @@
   FROM C_ORDER
   WHERE C_ORDER_ID=v_C_ORDER_ID;
   IF UPDATING THEN
-    IF(v_Processed='Y' AND v_Docaction <> 'CL' 
-    AND ((COALESCE(:old.TAXBASEAMT, 0) <> COALESCE(:new.TAXBASEAMT, 0)) 
-    OR(COALESCE(:old.TAXAMT, 0) <> COALESCE(:new.TAXAMT, 0)) 
+    IF(v_Processed='Y' AND v_Docaction <> 'CL'
+    AND ((COALESCE(:old.TAXBASEAMT, 0) <> COALESCE(:new.TAXBASEAMT, 0))
+    OR(COALESCE(:old.TAXAMT, 0) <> COALESCE(:new.TAXAMT, 0))
     OR(COALESCE(:old.C_TAX_ID, 0) <> COALESCE(:new.C_TAX_ID, 0))
     OR(COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0))
     OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0)))) THEN
--- a/database/model/triggers/C_ORDER_CHK_RESTRINCTIONS_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_ORDER_CHK_RESTRINCTIONS_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -17,8 +17,8 @@
 
 BEGIN
   IF UPDATING THEN
-    IF(:OLD.Processed='Y' AND :OLD.Docaction <> 'CL' 
-          AND( 
+    IF(:OLD.Processed='Y' AND :OLD.Docaction <> 'CL'
+          AND(
                (COALESCE(:OLD.C_BPartner_ID, 0) <> COALESCE(:NEW.C_BPartner_ID, 0))
                OR(COALESCE(:OLD.DOCUMENTNO, '.') <> COALESCE(:NEW.DOCUMENTNO, '.'))
                OR(COALESCE(:OLD.C_DOCTYPE_ID, 0) <> COALESCE(:NEW.C_DOCTYPE_ID, 0))
--- a/database/model/triggers/C_ORDLINE_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_ORDLINE_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -31,7 +31,7 @@
     v_C_ORDER_ID:=:NEW.C_ORDER_ID;
   ELSE
     v_C_ORDER_ID:=:OLD.C_ORDER_ID;
-  END IF;  
+  END IF;
   IF UPDATING THEN
     IF((COALESCE(:old.LINE, 0) <> COALESCE(:NEW.LINE, 0) OR COALESCE(:old.M_PRODUCT_ID, 0) <> COALESCE(:NEW.M_PRODUCT_ID, 0) OR COALESCE(:old.QTYORDERED, 0) <> COALESCE(:NEW.QTYORDERED, 0) OR COALESCE(:old.PRICELIST, 0) <> COALESCE(:NEW.PRICELIST, 0) OR COALESCE(:old.PRICEACTUAL, 0) <> COALESCE(:NEW.PRICEACTUAL, 0) OR COALESCE(:old.PRICELIMIT, 0) <> COALESCE(:NEW.PRICELIMIT, 0) OR COALESCE(:old.LINENETAMT, 0) <> COALESCE(:NEW.LINENETAMT, 0) OR COALESCE(:old.C_CHARGE_ID, 0) <> COALESCE(:NEW.C_CHARGE_ID, 0) OR COALESCE(:old.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0) OR COALESCE(:old.C_TAX_ID, 0) <> COALESCE(:NEW.C_TAX_ID, 0) OR COALESCE(:old.LOT, '.') <> COALESCE(:NEW.LOT, '.') OR COALESCE(:old.SERNO, '.') <> COALESCE(:NEW.SERNO, '.') OR COALESCE(:old.DIRECTSHIP, '.') <> COALESCE(:NEW.DIRECTSHIP, '.') OR COALESCE(:old.M_ATTRIBUTESETINSTANCE_ID, 0) <> COALESCE(:NEW.M_ATTRIBUTESETINSTANCE_ID, 0) OR COALESCE(:old.QUANTITYORDER, 0) <> COALESCE(:NEW.QUANTITYORDER, 0) OR COALESCE(
       :old.M_PRODUCT_UOM_ID, 0) <> COALESCE(:NEW.M_PRODUCT_UOM_ID, 0) )) THEN
@@ -41,10 +41,10 @@
     v_Docaction
   FROM C_ORDER
   WHERE C_ORDER_ID=v_C_ORDER_ID;
-      IF(v_Processed='Y' 
-        AND v_Docaction <> 'CL' 
+      IF(v_Processed='Y'
+        AND v_Docaction <> 'CL'
         AND (
-          (COALESCE(:OLD.LINE, 0) <> COALESCE(:NEW.LINE, 0)) 
+          (COALESCE(:OLD.LINE, 0) <> COALESCE(:NEW.LINE, 0))
           OR(COALESCE(:OLD.M_PRODUCT_ID, 0) <> COALESCE(:NEW.M_PRODUCT_ID, 0))
           OR(COALESCE(:OLD.QTYORDERED, 0) <> COALESCE(:NEW.QTYORDERED, 0))
           OR(COALESCE(:OLD.PRICELIST, 0) <> COALESCE(:NEW.PRICELIST, 0))
--- a/database/model/triggers/C_TAXPAYMENT_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_TAXPAYMENT_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -2,7 +2,7 @@
   <database name="TRIGGER C_TAXPAYMENT_TRG">
     <trigger name="C_TAXPAYMENT_TRG" table="C_TAXPAYMENT" fires="before" insert="true" update="true" delete="true" foreach="row">
       <body><![CDATA[
-      
+
     /*************************************************************************
     * The contents of this file are subject to the Compiere License
     * Version 2.5.0 ("License"); You may not use this file except in
@@ -22,8 +22,8 @@
     * Contributions are Copyright (C) 1999-2005 Openbravo, S.L
     *************************************************************************
     * Insert Translation
-    */  
-      
+    */
+
     BEGIN
     IF UPDATING
     THEN  IF (:OLD.PROCESSED)='Y' AND (:OLD.processing) = 'N' and (:OLD.processing)=(:new.processing)
--- a/database/model/triggers/C_TAXREGISTERLINE_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_TAXREGISTERLINE_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -7,8 +7,8 @@
 V_PROCESSING VARCHAR2(1);
 
     BEGIN
-    IF UPDATING THEN 
-    SELECT  TP.PROCESSED, TP.PROCESSING     
+    IF UPDATING THEN
+    SELECT  TP.PROCESSED, TP.PROCESSING
     INTO V_PROCESSED, V_PROCESSING
     FROM C_TAXPAYMENT TP
     INNER JOIN C_TAXREGISTER TR ON TP.C_TAXPAYMENT_ID=TR.C_TAXPAYMENT_ID
@@ -18,7 +18,7 @@
     END IF;
   END IF;
   IF(INSERTING) THEN
-  SELECT  TP.PROCESSED, TP.PROCESSING     
+  SELECT  TP.PROCESSED, TP.PROCESSING
     INTO V_PROCESSED, V_PROCESSING
     FROM C_TAXPAYMENT TP
     INNER JOIN C_TAXREGISTER TR ON TP.C_TAXPAYMENT_ID=TR.C_TAXPAYMENT_ID
@@ -28,7 +28,7 @@
    END IF;
   END IF;
   IF(DELETING) THEN
-  SELECT  TP.PROCESSED, TP.PROCESSING     
+  SELECT  TP.PROCESSED, TP.PROCESSING
     INTO V_PROCESSED, V_PROCESSING
     FROM C_TAXPAYMENT TP
     INNER JOIN C_TAXREGISTER TR ON TP.C_TAXPAYMENT_ID=TR.C_TAXPAYMENT_ID
--- a/database/model/triggers/C_TAXREGISTER_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/C_TAXREGISTER_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -7,28 +7,28 @@
 V_PROCESSING VARCHAR2(1);
 
     BEGIN
-    IF UPDATING THEN 
-    SELECT  PROCESSED, PROCESSING     
+    IF UPDATING THEN
+    SELECT  PROCESSED, PROCESSING
     INTO V_PROCESSED, V_PROCESSING
-    FROM C_TAXPAYMENT 
+    FROM C_TAXPAYMENT
     WHERE C_TAXPAYMENT_ID=(:OLD.C_TAXPAYMENT_ID);
     IF(V_PROCESSED='Y' AND V_PROCESSING='N')
     THEN  RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
     END IF;
   END IF;
   IF(INSERTING) THEN
-   SELECT  PROCESSED, PROCESSING     
+   SELECT  PROCESSED, PROCESSING
     INTO V_PROCESSED, V_PROCESSING
-    FROM C_TAXPAYMENT 
+    FROM C_TAXPAYMENT
     WHERE C_TAXPAYMENT_ID=(:new.C_TAXPAYMENT_ID);
    IF(V_PROCESSED='Y' AND V_PROCESSING='N') THEN
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
    END IF;
   END IF;
   IF(DELETING) THEN
-  SELECT  PROCESSED, PROCESSING     
+  SELECT  PROCESSED, PROCESSING
     INTO V_PROCESSED, V_PROCESSING
-    FROM C_TAXPAYMENT 
+    FROM C_TAXPAYMENT
     WHERE C_TAXPAYMENT_ID=(:OLD.C_TAXPAYMENT_ID);
    IF(V_PROCESSED='Y' AND V_PROCESSING='N') THEN
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
--- a/database/model/triggers/GL_JL_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/GL_JL_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -42,22 +42,22 @@
         v_Posted
       FROM GL_JOURNAL
       WHERE GL_JOURNAL_ID=v_GL_JOURNAL_ID;
-      IF(v_Processed='Y' 
-        AND ((COALESCE(:old.LINE, 0) <> COALESCE(:new.LINE, 0)) 
-        OR (COALESCE(:old.C_DEBT_PAYMENT_ID, 0) <> COALESCE(:new.C_DEBT_PAYMENT_ID, 0)) 
-        OR(COALESCE(:old.AMTSOURCEDR, 0) <> COALESCE(:new.AMTSOURCEDR, 0)) 
-        OR(COALESCE(:old.AMTSOURCECR, 0) <> COALESCE(:new.AMTSOURCECR, 0)) 
-        OR(COALESCE(:old.C_CURRENCY_ID, 0) <> COALESCE(:new.C_CURRENCY_ID, 0)) 
+      IF(v_Processed='Y'
+        AND ((COALESCE(:old.LINE, 0) <> COALESCE(:new.LINE, 0))
+        OR (COALESCE(:old.C_DEBT_PAYMENT_ID, 0) <> COALESCE(:new.C_DEBT_PAYMENT_ID, 0))
+        OR(COALESCE(:old.AMTSOURCEDR, 0) <> COALESCE(:new.AMTSOURCEDR, 0))
+        OR(COALESCE(:old.AMTSOURCECR, 0) <> COALESCE(:new.AMTSOURCECR, 0))
+        OR(COALESCE(:old.C_CURRENCY_ID, 0) <> COALESCE(:new.C_CURRENCY_ID, 0))
         OR(COALESCE(:old.C_UOM_ID, 0) <> COALESCE(:new.C_UOM_ID, 0))
         OR(COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0))
         OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0)))) THEN
         RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
       END IF;
 
-      IF(v_Posted='Y' 
-        AND ((COALESCE(:old.DATEACCT, v_DateNull) <> COALESCE(:new.DATEACCT, v_DateNull)) 
-        OR(COALESCE(:old.C_VALIDCOMBINATION_ID, 0) <> COALESCE(:new.C_VALIDCOMBINATION_ID, 0)) 
-        OR(COALESCE(:old.AMTACCTDR, 0) <> COALESCE(:new.AMTACCTDR, 0)) 
+      IF(v_Posted='Y'
+        AND ((COALESCE(:old.DATEACCT, v_DateNull) <> COALESCE(:new.DATEACCT, v_DateNull))
+        OR(COALESCE(:old.C_VALIDCOMBINATION_ID, 0) <> COALESCE(:new.C_VALIDCOMBINATION_ID, 0))
+        OR(COALESCE(:old.AMTACCTDR, 0) <> COALESCE(:new.AMTACCTDR, 0))
         OR(COALESCE(:old.AMTACCTCR, 0) <> COALESCE(:new.AMTACCTCR, 0)))) THEN
         RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
       END IF;
@@ -80,7 +80,7 @@
     INTO v_Processed,
       v_Posted
     FROM GL_JOURNAL
-    WHERE GL_JOURNAL_ID=v_GL_JOURNAL_ID;  
+    WHERE GL_JOURNAL_ID=v_GL_JOURNAL_ID;
     IF (v_Processed='Y') THEN
       RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
     END IF;
--- a/database/model/triggers/M_INOUT_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/M_INOUT_CHK_RESTRICTIONS_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -22,7 +22,7 @@
     * All Rights Reserved.
     * Contributor(s):  ______________________________________.
     ************************************************************************/
-  
+
   v_DateNull DATE := TO_DATE('01-01-1900', 'DD-MM-YYYY');
 
  BEGIN
--- a/database/model/triggers/M_PRODUCT_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/M_PRODUCT_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -49,8 +49,8 @@
     RAISE_APPLICATION_ERROR(-20400, 'Product has active Inventory');
    END IF;
   END IF;
-  
-  IF( COALESCE(:old.Name,'.') <> COALESCE(:new.Name,'.') 
+
+  IF( COALESCE(:old.Name,'.') <> COALESCE(:new.Name,'.')
   OR COALESCE(:old.documentnote,'.') <> COALESCE(:new.documentnote,'.') ) THEN
     UPDATE M_PRODUCT_Trl
       SET IsTranslated='N'
--- a/database/model/triggers/M_REQUISITIONLINE_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/M_REQUISITIONLINE_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -21,8 +21,8 @@
   v_DocStatus CHAR(2);
   v_ReqStatus CHAR(1);
   v_OrderedQty NUMBER;
-  
-  BEGIN  
+
+  BEGIN
   IF INSERTING THEN
     SELECT DocStatus, :new.ReqStatus, 0 INTO v_DocStatus, v_ReqStatus, v_OrderedQty
     FROM M_Requisition
@@ -32,11 +32,11 @@
     FROM M_Requisition
     WHERE M_Requisition_ID = :old.M_Requisition_ID;
   END IF;
-  
+
   IF (v_DocStatus = 'CL') THEN
     RAISE_APPLICATION_ERROR(-20527, 'It is not possible to modify a closed requisition');
   END IF;
-  
+
   IF (v_DocStatus = 'CO' AND INSERTING) THEN
     RAISE_APPLICATION_ERROR(-20525, 'It is not possible insert a new line in a completed requisition');
   END IF;
@@ -44,7 +44,7 @@
   IF (v_ReqStatus = 'P') THEN
     RAISE_APPLICATION_ERROR(-20526, 'It is not possible to modify planned requisition lines');
   END IF;
-  
+
   IF (v_ReqStatus <> 'O') THEN
     RAISE_APPLICATION_ERROR(-20520, 'It is not possible to modify closed or cancelled requisition lines');
   END IF;
--- a/database/model/triggers/M_REQUISITION_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/M_REQUISITION_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -19,18 +19,18 @@
 * Contributor(s):  ______________________________________.
 ************************************************************************/
   v_DocStatus CHAR(2);
-  BEGIN  
+  BEGIN
   IF INSERTING THEN
     v_DocStatus := :new.DocStatus;
   ELSE
     v_DocStatus := :old.DocStatus;
   END IF;
-  
+
   IF ((v_DocStatus = 'CL')
       OR ((v_DocStatus = 'CO') AND NOT UPDATING)) THEN
     RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted');
   END IF;
-  
+
   IF (v_DocStatus = 'CO' AND UPDATING) THEN
     IF ((COALESCE(:old.DocumentNo, '.') <> COALESCE(:new.DocumentNo,'.'))
        OR (COALESCE(:old.C_BPartner_ID, 0) <> COALESCE(:new.C_BPartner_ID, 0))
--- a/database/model/triggers/S_TIMEEXPENSELINE_TRG.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/triggers/S_TIMEEXPENSELINE_TRG.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -29,9 +29,9 @@
       v_need_verification := false;
     END IF;
    END IF;
-   
+
    IF (v_need_verification) THEN
-   -- ReadOnly Check   
+   -- ReadOnly Check
     SELECT  COUNT(*)
      INTO v_RO
     FROM S_TIMEEXPENSE
--- a/database/model/views/AD_REF_LIST_V.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/AD_REF_LIST_V.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -2,7 +2,7 @@
   <database name="VIEW AD_REF_LIST_V">
     <view name="AD_REF_LIST_V"><![CDATA[SELECT ad_ref_list.ad_ref_list_id, ad_ref_list.value, to_char(ad_ref_list.name) AS name, 'en_US' AS ad_language, ad_ref_list.ad_reference_id
    FROM ad_ref_list
-UNION 
+UNION
  SELECT v1.ad_ref_list_id, v1.value, COALESCE(v1.name_trl, v2.name) AS name, v1.ad_language, v1.ad_reference_id
    FROM ( SELECT ad_ref_list.ad_ref_list_id, ad_ref_list.value, to_char(ad_ref_list_trl.name) AS name_trl, '' AS name, ad_ref_list_trl.ad_language, ad_ref_list.ad_reference_id
            FROM ad_ref_list, ad_ref_list_trl
--- a/database/model/views/AD_TABLE_POST_V.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/AD_TABLE_POST_V.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
   <database name="VIEW AD_TABLE_POST_V">
-    <view name="AD_TABLE_POST_V"><![CDATA[SELECT ad_table.ad_table_id, (w2.name || 
+    <view name="AD_TABLE_POST_V"><![CDATA[SELECT ad_table.ad_table_id, (w2.name ||
         CASE
             WHEN w2.name IS NULL THEN ''
             ELSE ' - '
@@ -11,8 +11,8 @@
   WHERE (EXISTS ( SELECT c.ad_column_id, c.ad_client_id, c.ad_org_id, c.isactive, c.created, c.updated, c.createdby, c.updatedby, c.name, c.description, c.help, c.version, c.entitytype, c.columnname, c.ad_table_id, c.ad_reference_id, c.ad_reference_value_id, c.ad_val_rule_id, c.fieldlength, c.defaultvalue, c.iskey, c.isparent, c.ismandatory, c.isupdateable, c.readonlylogic, c.isidentifier, c.seqno, c.istranslated, c.isencrypted, c.callout, c.vformat, c.valuemin, c.valuemax, c.isselectioncolumn, c.ad_element_id, c.ad_process_id, c.issyncdatabase, c.issessionattr, c.issecondarykey, c.isdesencryptable, c.ad_callout_id, c.developmentstatus
    FROM ad_column c
   WHERE ad_table.ad_table_id = c.ad_table_id AND c.columnname = 'Posted')) AND w1.ad_language = COALESCE(w2.ad_language, w1.ad_language) AND ad_table.isactive = 'Y'
-UNION 
- SELECT ad_table.ad_table_id, (w2.name || 
+UNION
+ SELECT ad_table.ad_table_id, (w2.name ||
         CASE
             WHEN w2.name IS NULL THEN ''
             ELSE ' - '
--- a/database/model/views/C_DEBT_PAYMENT_V.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/C_DEBT_PAYMENT_V.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,14 +1,14 @@
 <?xml version="1.0"?>
   <database name="VIEW C_DEBT_PAYMENT_V">
-    <view name="C_DEBT_PAYMENT_V"><![CDATA[SELECT c_debt_payment.c_debt_payment_id, c_debt_payment.ad_client_id, c_debt_payment.ad_org_id, c_debt_payment.isactive, c_debt_payment.created, c_debt_payment.createdby, c_debt_payment.updated, c_debt_payment.updatedby, c_debt_payment.isreceipt, c_debt_payment.c_settlement_cancel_id, c_debt_payment.c_settlement_generate_id, c_debt_payment.description, c_debt_payment.c_invoice_id, c_debt_payment.c_bpartner_id, c_debt_payment.c_currency_id, c_debt_payment.c_cashline_id, c_debt_payment.c_bankaccount_id, c_debt_payment.c_cashbook_id, c_debt_payment.paymentrule, c_debt_payment.ispaid, c_debt_payment.dateplanned, c_debt_payment.ismanual, c_debt_payment.isvalid, c_debt_payment.c_bankstatementline_id, c_debt_payment.changesettlementcancel, c_debt_payment.cancel_processed, c_debt_payment.generate_processed, 
+    <view name="C_DEBT_PAYMENT_V"><![CDATA[SELECT c_debt_payment.c_debt_payment_id, c_debt_payment.ad_client_id, c_debt_payment.ad_org_id, c_debt_payment.isactive, c_debt_payment.created, c_debt_payment.createdby, c_debt_payment.updated, c_debt_payment.updatedby, c_debt_payment.isreceipt, c_debt_payment.c_settlement_cancel_id, c_debt_payment.c_settlement_generate_id, c_debt_payment.description, c_debt_payment.c_invoice_id, c_debt_payment.c_bpartner_id, c_debt_payment.c_currency_id, c_debt_payment.c_cashline_id, c_debt_payment.c_bankaccount_id, c_debt_payment.c_cashbook_id, c_debt_payment.paymentrule, c_debt_payment.ispaid, c_debt_payment.dateplanned, c_debt_payment.ismanual, c_debt_payment.isvalid, c_debt_payment.c_bankstatementline_id, c_debt_payment.changesettlementcancel, c_debt_payment.cancel_processed, c_debt_payment.generate_processed,
         CASE c_debt_payment.isreceipt
             WHEN 'Y' THEN c_debt_payment.amount
             ELSE c_debt_payment.amount * -1
-        END AS amount, 
+        END AS amount,
         CASE c_debt_payment.isreceipt
             WHEN 'Y' THEN c_debt_payment.writeoffamt
             ELSE c_debt_payment.writeoffamt * -1
-        END AS writeoffamt, 
+        END AS writeoffamt,
         CASE c_debt_payment.isreceipt
             WHEN 'Y' THEN 1
             ELSE -1
--- a/database/model/views/C_INVOICELINE_V.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/C_INVOICELINE_V.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
   <database name="VIEW C_INVOICELINE_V">
-    <view name="C_INVOICELINE_V"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.c_invoiceline_id, i.c_invoice_id, i.salesrep_id, i.c_bpartner_id, il.m_product_id, i.documentno, i.dateinvoiced, i.dateacct, i.issotrx, i.docstatus, round(i.multiplier * il.linenetamt, 2) AS linenetamt, round(i.multiplier * il.pricelist * il.qtyinvoiced, 2) AS linelistamt, 
+    <view name="C_INVOICELINE_V"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.c_invoiceline_id, i.c_invoice_id, i.salesrep_id, i.c_bpartner_id, il.m_product_id, i.documentno, i.dateinvoiced, i.dateacct, i.issotrx, i.docstatus, round(i.multiplier * il.linenetamt, 2) AS linenetamt, round(i.multiplier * il.pricelist * il.qtyinvoiced, 2) AS linelistamt,
         CASE
             WHEN il.pricelimit IS NULL THEN round(i.multiplier * il.linenetamt, 2)
             ELSE round(i.multiplier * il.pricelimit * il.qtyinvoiced, 2)
-        END AS linelimitamt, round(i.multiplier * il.pricelist * il.qtyinvoiced - il.linenetamt, 2) AS linediscountamt, 
+        END AS linelimitamt, round(i.multiplier * il.pricelist * il.qtyinvoiced - il.linenetamt, 2) AS linediscountamt,
         CASE
             WHEN il.pricelimit IS NULL THEN 0
             ELSE round(i.multiplier * il.linenetamt - il.pricelimit * il.qtyinvoiced, 2)
--- a/database/model/views/C_INVOICE_LINETAX_V.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/C_INVOICE_LINETAX_V.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,30 +1,30 @@
 <?xml version="1.0"?>
   <database name="VIEW C_INVOICE_LINETAX_V">
-    <view name="C_INVOICE_LINETAX_V"><![CDATA[((( SELECT il.ad_client_id, il.ad_org_id, il.isactive, il.created, il.createdby, il.updated, il.updatedby, 'en_US' AS ad_language, il.c_invoice_id, il.c_invoiceline_id, il.c_tax_id, il.line, 
+    <view name="C_INVOICE_LINETAX_V"><![CDATA[((( SELECT il.ad_client_id, il.ad_org_id, il.isactive, il.created, il.createdby, il.updated, il.updatedby, 'en_US' AS ad_language, il.c_invoice_id, il.c_invoiceline_id, il.c_tax_id, il.line,
         CASE
             WHEN il.qtyinvoiced <> 0 OR il.m_product_id IS NOT NULL THEN il.qtyinvoiced
             ELSE NULL
-        END AS qtyinvoiced, 
+        END AS qtyinvoiced,
         CASE
             WHEN il.qtyinvoiced <> 0 OR il.m_product_id IS NOT NULL THEN uom.uomsymbol
             ELSE NULL
-        END AS uomsymbol, COALESCE(p.name, il.description) AS name, 
+        END AS uomsymbol, COALESCE(p.name, il.description) AS name,
         CASE
             WHEN p.name IS NOT NULL THEN il.description
             ELSE NULL
-        END AS description, p.documentnote, p.upc, p.sku, p.value AS productvalue, ra.description AS resourcedescription, 
+        END AS description, p.documentnote, p.upc, p.sku, p.value AS productvalue, ra.description AS resourcedescription,
         CASE
             WHEN i.isdiscountprinted = 'Y' AND (il.pricelist <> 0 OR il.m_product_id IS NOT NULL) THEN il.pricelist
             ELSE NULL
-        END AS pricelist, 
+        END AS pricelist,
         CASE
             WHEN i.isdiscountprinted = 'Y' AND il.pricelist > il.priceactual THEN (il.pricelist - il.priceactual) / il.pricelist * 100
             ELSE NULL
-        END AS discount, 
+        END AS discount,
         CASE
             WHEN il.priceactual <> 0 OR il.m_product_id IS NOT NULL THEN il.priceactual
             ELSE NULL
-        END AS priceactual, 
+        END AS priceactual,
         CASE
             WHEN il.linenetamt <> 0 OR il.m_product_id IS NOT NULL THEN il.linenetamt
             ELSE NULL
@@ -34,21 +34,21 @@
    JOIN c_invoice i ON il.c_invoice_id = i.c_invoice_id
    LEFT JOIN m_product p ON il.m_product_id = p.m_product_id
    LEFT JOIN s_resourceassignment ra ON il.s_resourceassignment_id = ra.s_resourceassignment_id
-UNION 
+UNION
  SELECT il.ad_client_id, il.ad_org_id, il.isactive, il.created, il.createdby, il.updated, il.updatedby, 'en_US' AS ad_language, il.c_invoice_id, il.c_invoiceline_id, il.c_tax_id, il.line + b.line / 100 AS line, il.qtyinvoiced * b.bomqty AS qtyinvoiced, uom.uomsymbol, p.name, b.description, p.documentnote, p.upc, p.sku, p.value AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM m_product_bom b
    JOIN c_invoiceline il ON b.m_product_id = il.m_product_id
    JOIN m_product bp ON bp.m_product_id = il.m_product_id AND bp.isbom = 'Y' AND bp.isverified = 'Y' AND bp.isinvoiceprintdetails = 'Y'
    JOIN m_product p ON b.m_productbom_id = p.m_product_id
    JOIN c_uom uom ON p.c_uom_id = uom.c_uom_id)
-UNION 
+UNION
  SELECT il.ad_client_id, il.ad_org_id, il.isactive, il.created, il.createdby, il.updated, il.updatedby, 'en_US' AS ad_language, il.c_invoice_id, il.c_invoiceline_id, il.c_tax_id, il.line, NULL AS qtyinvoiced, NULL AS uomsymbol, il.description AS name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM c_invoiceline il
   WHERE il.c_uom_id IS NULL)
-UNION 
+UNION
  SELECT c_invoice.ad_client_id, c_invoice.ad_org_id, c_invoice.isactive, c_invoice.created, c_invoice.createdby, c_invoice.updated, c_invoice.updatedby, 'en_US' AS ad_language, c_invoice.c_invoice_id, NULL AS c_invoiceline_id, NULL AS c_tax_id, 9998 AS line, NULL AS qtyinvoiced, NULL AS uomsymbol, NULL AS name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM c_invoice)
-UNION 
+UNION
  SELECT it.ad_client_id, it.ad_org_id, it.isactive, it.created, it.createdby, it.updated, it.updatedby, 'en_US' AS ad_language, it.c_invoice_id, NULL AS c_invoiceline_id, it.c_tax_id, 9999 AS line, NULL AS qtyinvoiced, NULL AS uomsymbol, t.name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, it.taxbaseamt AS priceactual, it.taxamt AS linenetamt
    FROM c_invoicetax it
    JOIN c_tax t ON it.c_tax_id = t.c_tax_id]]></view>
--- a/database/model/views/C_INVOICE_LINETAX_VT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/C_INVOICE_LINETAX_VT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,30 +1,30 @@
 <?xml version="1.0"?>
   <database name="VIEW C_INVOICE_LINETAX_VT">
-    <view name="C_INVOICE_LINETAX_VT"><![CDATA[((( SELECT il.ad_client_id, il.ad_org_id, il.isactive, il.created, il.createdby, il.updated, il.updatedby, uom.ad_language, il.c_invoice_id, il.c_invoiceline_id, il.c_tax_id, il.line, 
+    <view name="C_INVOICE_LINETAX_VT"><![CDATA[((( SELECT il.ad_client_id, il.ad_org_id, il.isactive, il.created, il.createdby, il.updated, il.updatedby, uom.ad_language, il.c_invoice_id, il.c_invoiceline_id, il.c_tax_id, il.line,
         CASE
             WHEN il.qtyinvoiced <> 0 OR il.m_product_id IS NOT NULL THEN il.qtyinvoiced
             ELSE NULL
-        END AS qtyinvoiced, 
+        END AS qtyinvoiced,
         CASE
             WHEN il.qtyinvoiced <> 0 OR il.m_product_id IS NOT NULL THEN uom.uomsymbol
             ELSE NULL
-        END AS uomsymbol, COALESCE(COALESCE(pt.name, p.name), il.description) AS name, 
+        END AS uomsymbol, COALESCE(COALESCE(pt.name, p.name), il.description) AS name,
         CASE
             WHEN COALESCE(pt.name, p.name) IS NOT NULL THEN il.description
             ELSE NULL
-        END AS description, COALESCE(pt.documentnote, p.documentnote) AS documentnote, p.upc, p.sku, p.value AS productvalue, ra.description AS resourcedescription, 
+        END AS description, COALESCE(pt.documentnote, p.documentnote) AS documentnote, p.upc, p.sku, p.value AS productvalue, ra.description AS resourcedescription,
         CASE
             WHEN i.isdiscountprinted = 'Y' AND (il.pricelist <> 0 OR il.m_product_id IS NOT NULL) THEN il.pricelist
             ELSE NULL
-        END AS pricelist, 
+        END AS pricelist,
         CASE
             WHEN i.isdiscountprinted = 'Y' AND il.pricelist > il.priceactual THEN (il.pricelist - il.priceactual) / il.pricelist * 100
             ELSE NULL
-        END AS discount, 
+        END AS discount,
         CASE
             WHEN il.priceactual <> 0 OR il.m_product_id IS NOT NULL THEN il.priceactual
             ELSE NULL
-        END AS priceactual, 
+        END AS priceactual,
         CASE
             WHEN il.linenetamt <> 0 OR il.m_product_id IS NOT NULL THEN il.linenetamt
             ELSE NULL
@@ -35,7 +35,7 @@
    LEFT JOIN m_product p ON il.m_product_id = p.m_product_id
    LEFT JOIN m_product_trl pt ON il.m_product_id = pt.m_product_id AND uom.ad_language = pt.ad_language
    LEFT JOIN s_resourceassignment ra ON il.s_resourceassignment_id = ra.s_resourceassignment_id
-UNION 
+UNION
  SELECT il.ad_client_id, il.ad_org_id, il.isactive, il.created, il.createdby, il.updated, il.updatedby, uom.ad_language, il.c_invoice_id, il.c_invoiceline_id, il.c_tax_id, il.line + b.line / 100 AS line, il.qtyinvoiced * b.bomqty AS qtyinvoiced, uom.uomsymbol, COALESCE(pt.name, p.name) AS name, b.description, COALESCE(pt.documentnote, p.documentnote) AS documentnote, p.upc, p.sku, p.value AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM m_product_bom b
    JOIN c_invoiceline il ON b.m_product_id = il.m_product_id
@@ -43,15 +43,15 @@
    JOIN m_product p ON b.m_productbom_id = p.m_product_id
    JOIN c_uom_trl uom ON p.c_uom_id = uom.c_uom_id
    JOIN m_product_trl pt ON b.m_productbom_id = pt.m_product_id AND uom.ad_language = pt.ad_language)
-UNION 
+UNION
  SELECT il.ad_client_id, il.ad_org_id, il.isactive, il.created, il.createdby, il.updated, il.updatedby, l.ad_language, il.c_invoice_id, il.c_invoiceline_id, il.c_tax_id, il.line, NULL AS qtyinvoiced, NULL AS uomsymbol, il.description AS name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM c_invoiceline il, ad_language l
   WHERE il.c_uom_id IS NULL AND l.isbaselanguage = 'N' AND l.issystemlanguage = 'Y')
-UNION 
+UNION
  SELECT i.ad_client_id, i.ad_org_id, i.isactive, i.created, i.createdby, i.updated, i.updatedby, l.ad_language, i.c_invoice_id, NULL AS c_invoiceline_id, NULL AS c_tax_id, 9998 AS line, NULL AS qtyinvoiced, NULL AS uomsymbol, NULL AS name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM c_invoice i, ad_language l
   WHERE l.isbaselanguage = 'N' AND l.issystemlanguage = 'Y')
-UNION 
+UNION
  SELECT it.ad_client_id, it.ad_org_id, it.isactive, it.created, it.createdby, it.updated, it.updatedby, l.ad_language, it.c_invoice_id, NULL AS c_invoiceline_id, it.c_tax_id, 9999 AS line, NULL AS qtyinvoiced, NULL AS uomsymbol, t.name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, it.taxbaseamt AS priceactual, it.taxamt AS linenetamt
    FROM c_invoicetax it
    JOIN c_tax t ON it.c_tax_id = t.c_tax_id, ad_language l
--- a/database/model/views/C_INVOICE_V.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/C_INVOICE_V.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,22 +1,22 @@
 <?xml version="1.0"?>
   <database name="VIEW C_INVOICE_V">
-    <view name="C_INVOICE_V"><![CDATA[SELECT i.c_invoice_id, i.ad_client_id, i.ad_org_id, i.isactive, i.created, i.createdby, i.updated, i.updatedby, i.issotrx, i.documentno, i.docstatus, i.docaction, i.processing, i.processed, i.c_doctype_id, i.c_doctypetarget_id, i.c_order_id, i.description, i.isapproved, i.istransferred, i.salesrep_id, i.dateinvoiced, i.dateprinted, i.dateacct, i.c_bpartner_id, i.c_bpartner_location_id, i.ad_user_id, i.poreference, i.dateordered, i.c_currency_id, i.paymentrule, i.c_paymentterm_id, i.c_charge_id, i.m_pricelist_id, i.c_campaign_id, i.c_project_id, i.c_activity_id, i.isprinted, i.isdiscountprinted, i.ispaid, 
+    <view name="C_INVOICE_V"><![CDATA[SELECT i.c_invoice_id, i.ad_client_id, i.ad_org_id, i.isactive, i.created, i.createdby, i.updated, i.updatedby, i.issotrx, i.documentno, i.docstatus, i.docaction, i.processing, i.processed, i.c_doctype_id, i.c_doctypetarget_id, i.c_order_id, i.description, i.isapproved, i.istransferred, i.salesrep_id, i.dateinvoiced, i.dateprinted, i.dateacct, i.c_bpartner_id, i.c_bpartner_location_id, i.ad_user_id, i.poreference, i.dateordered, i.c_currency_id, i.paymentrule, i.c_paymentterm_id, i.c_charge_id, i.m_pricelist_id, i.c_campaign_id, i.c_project_id, i.c_activity_id, i.isprinted, i.isdiscountprinted, i.ispaid,
         CASE
             WHEN substr(d.docbasetype, 3) = 'C' THEN i.chargeamt * -1
             ELSE i.chargeamt
-        END AS chargeamt, 
+        END AS chargeamt,
         CASE
             WHEN substr(d.docbasetype, 3) = 'C' THEN i.totallines * -1
             ELSE i.totallines
-        END AS totallines, 
+        END AS totallines,
         CASE
             WHEN substr(d.docbasetype, 3) = 'C' THEN i.grandtotal * -1
             ELSE i.grandtotal
-        END AS grandtotal, 
+        END AS grandtotal,
         CASE
             WHEN substr(d.docbasetype, 3) = 'C' THEN -1
             ELSE 1
-        END AS multiplier, 
+        END AS multiplier,
         CASE
             WHEN substr(d.docbasetype, 2, 1) = 'P' THEN -1
             ELSE 1
--- a/database/model/views/C_ORDER_LINETAX_V.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/C_ORDER_LINETAX_V.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,14 +1,14 @@
 <?xml version="1.0"?>
   <database name="VIEW C_ORDER_LINETAX_V">
-    <view name="C_ORDER_LINETAX_V"><![CDATA[(( SELECT ol.ad_client_id, ol.ad_org_id, ol.isactive, ol.created, ol.createdby, ol.updated, ol.updatedby, 'en_US' AS ad_language, ol.c_order_id, ol.c_orderline_id, ol.c_tax_id, ol.line, ol.qtyordered, uom.uomsymbol, COALESCE(p.name, ol.description) AS name, 
+    <view name="C_ORDER_LINETAX_V"><![CDATA[(( SELECT ol.ad_client_id, ol.ad_org_id, ol.isactive, ol.created, ol.createdby, ol.updated, ol.updatedby, 'en_US' AS ad_language, ol.c_order_id, ol.c_orderline_id, ol.c_tax_id, ol.line, ol.qtyordered, uom.uomsymbol, COALESCE(p.name, ol.description) AS name,
         CASE
             WHEN p.name IS NOT NULL THEN ol.description
             ELSE NULL
-        END AS description, p.documentnote, p.upc, p.sku, p.value AS productvalue, ra.description AS resourcedescription, 
+        END AS description, p.documentnote, p.upc, p.sku, p.value AS productvalue, ra.description AS resourcedescription,
         CASE
             WHEN i.isdiscountprinted = 'Y' THEN ol.pricelist
             ELSE NULL
-        END AS pricelist, 
+        END AS pricelist,
         CASE
             WHEN i.isdiscountprinted = 'Y' AND ol.pricelist > ol.priceactual THEN (ol.pricelist - ol.priceactual) / ol.pricelist * 100
             ELSE NULL
@@ -18,17 +18,17 @@
    JOIN c_order i ON ol.c_order_id = i.c_order_id
    LEFT JOIN m_product p ON ol.m_product_id = p.m_product_id
    LEFT JOIN s_resourceassignment ra ON ol.s_resourceassignment_id = ra.s_resourceassignment_id
-UNION 
+UNION
  SELECT ol.ad_client_id, ol.ad_org_id, ol.isactive, ol.created, ol.createdby, ol.updated, ol.updatedby, 'en_US' AS ad_language, ol.c_order_id, ol.c_orderline_id, ol.c_tax_id, ol.line + b.line / 100 AS line, ol.qtyordered * b.bomqty AS qtyordered, uom.uomsymbol, p.name, b.description, p.documentnote, p.upc, p.sku, p.value AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM m_product_bom b
    JOIN c_orderline ol ON b.m_product_id = ol.m_product_id
    JOIN m_product bp ON bp.m_product_id = ol.m_product_id AND bp.isbom = 'Y' AND bp.isverified = 'Y' AND bp.isinvoiceprintdetails = 'Y'
    JOIN m_product p ON b.m_productbom_id = p.m_product_id
    JOIN c_uom uom ON p.c_uom_id = uom.c_uom_id)
-UNION 
+UNION
  SELECT c_order.ad_client_id, c_order.ad_org_id, c_order.isactive, c_order.created, c_order.createdby, c_order.updated, c_order.updatedby, 'en_US' AS ad_language, c_order.c_order_id, NULL AS c_orderline_id, NULL AS c_tax_id, NULL AS line, NULL AS qtyordered, NULL AS uomsymbol, NULL AS name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM c_order)
-UNION 
+UNION
  SELECT ot.ad_client_id, ot.ad_org_id, ot.isactive, ot.created, ot.createdby, ot.updated, ot.updatedby, 'en_US' AS ad_language, ot.c_order_id, NULL AS c_orderline_id, ot.c_tax_id, NULL AS line, NULL AS qtyordered, NULL AS uomsymbol, t.name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, ot.taxbaseamt AS priceactual, ot.taxamt AS linenetamt
    FROM c_ordertax ot
    JOIN c_tax t ON ot.c_tax_id = t.c_tax_id]]></view>
--- a/database/model/views/C_ORDER_LINETAX_VT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/C_ORDER_LINETAX_VT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,14 +1,14 @@
 <?xml version="1.0"?>
   <database name="VIEW C_ORDER_LINETAX_VT">
-    <view name="C_ORDER_LINETAX_VT"><![CDATA[(( SELECT ol.ad_client_id, ol.ad_org_id, ol.isactive, ol.created, ol.createdby, ol.updated, ol.updatedby, uom.ad_language, ol.c_order_id, ol.c_orderline_id, ol.c_tax_id, ol.line, ol.qtyordered, uom.uomsymbol, COALESCE(COALESCE(pt.name, p.name), ol.description) AS name, 
+    <view name="C_ORDER_LINETAX_VT"><![CDATA[(( SELECT ol.ad_client_id, ol.ad_org_id, ol.isactive, ol.created, ol.createdby, ol.updated, ol.updatedby, uom.ad_language, ol.c_order_id, ol.c_orderline_id, ol.c_tax_id, ol.line, ol.qtyordered, uom.uomsymbol, COALESCE(COALESCE(pt.name, p.name), ol.description) AS name,
         CASE
             WHEN COALESCE(pt.name, p.name) IS NOT NULL THEN ol.description
             ELSE NULL
-        END AS description, COALESCE(pt.documentnote, p.documentnote) AS documentnote, p.upc, p.sku, p.value AS productvalue, ra.description AS resourcedescription, 
+        END AS description, COALESCE(pt.documentnote, p.documentnote) AS documentnote, p.upc, p.sku, p.value AS productvalue, ra.description AS resourcedescription,
         CASE
             WHEN i.isdiscountprinted = 'Y' THEN ol.pricelist
             ELSE NULL
-        END AS pricelist, 
+        END AS pricelist,
         CASE
             WHEN i.isdiscountprinted = 'Y' AND ol.pricelist > ol.priceactual THEN (ol.pricelist - ol.priceactual) / ol.pricelist * 100
             ELSE NULL
@@ -19,7 +19,7 @@
    LEFT JOIN m_product p ON ol.m_product_id = p.m_product_id
    LEFT JOIN m_product_trl pt ON ol.m_product_id = pt.m_product_id AND uom.ad_language = pt.ad_language
    LEFT JOIN s_resourceassignment ra ON ol.s_resourceassignment_id = ra.s_resourceassignment_id
-UNION 
+UNION
  SELECT ol.ad_client_id, ol.ad_org_id, ol.isactive, ol.created, ol.createdby, ol.updated, ol.updatedby, uom.ad_language, ol.c_order_id, ol.c_orderline_id, ol.c_tax_id, ol.line + b.line / 100 AS line, ol.qtyordered * b.bomqty AS qtyordered, uom.uomsymbol, COALESCE(pt.name, p.name) AS name, b.description, COALESCE(pt.documentnote, p.documentnote) AS documentnote, p.upc, p.sku, p.value AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM m_product_bom b
    JOIN c_orderline ol ON b.m_product_id = ol.m_product_id
@@ -27,11 +27,11 @@
    JOIN m_product p ON b.m_productbom_id = p.m_product_id
    JOIN c_uom_trl uom ON p.c_uom_id = uom.c_uom_id
    JOIN m_product_trl pt ON b.m_productbom_id = pt.m_product_id AND uom.ad_language = pt.ad_language)
-UNION 
+UNION
  SELECT o.ad_client_id, o.ad_org_id, o.isactive, o.created, o.createdby, o.updated, o.updatedby, l.ad_language, o.c_order_id, NULL AS c_orderline_id, NULL AS c_tax_id, NULL AS line, NULL AS qtyordered, NULL AS uomsymbol, NULL AS name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, NULL AS priceactual, NULL AS linenetamt
    FROM c_order o, ad_language l
   WHERE l.isbaselanguage = 'N' AND l.issystemlanguage = 'Y')
-UNION 
+UNION
  SELECT ot.ad_client_id, ot.ad_org_id, ot.isactive, ot.created, ot.createdby, ot.updated, ot.updatedby, l.ad_language, ot.c_order_id, NULL AS c_orderline_id, ot.c_tax_id, NULL AS line, NULL AS qtyordered, NULL AS uomsymbol, t.name, NULL AS description, NULL AS documentnote, NULL AS upc, NULL AS sku, NULL AS productvalue, NULL AS resourcedescription, NULL AS pricelist, NULL AS discount, ot.taxbaseamt AS priceactual, ot.taxamt AS linenetamt
    FROM c_ordertax ot
    JOIN c_tax t ON ot.c_tax_id = t.c_tax_id, ad_language l
--- a/database/model/views/C_PROJECT_DETAILS_V.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/C_PROJECT_DETAILS_V.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
   <database name="VIEW C_PROJECT_DETAILS_V">
-    <view name="C_PROJECT_DETAILS_V"><![CDATA[SELECT pl.ad_client_id, pl.ad_org_id, pl.isactive, pl.created, pl.createdby, pl.updated, pl.updatedby, to_char('en_US') AS ad_language, pj.c_project_id, pl.c_projectline_id, pl.line, pl.plannedqty, pl.plannedprice, pl.plannedamt, pl.plannedmarginamt, pl.committedamt, pl.m_product_id, COALESCE(p.name, pl.description) AS name, 
+    <view name="C_PROJECT_DETAILS_V"><![CDATA[SELECT pl.ad_client_id, pl.ad_org_id, pl.isactive, pl.created, pl.createdby, pl.updated, pl.updatedby, to_char('en_US') AS ad_language, pj.c_project_id, pl.c_projectline_id, pl.line, pl.plannedqty, pl.plannedprice, pl.plannedamt, pl.plannedmarginamt, pl.committedamt, pl.m_product_id, COALESCE(p.name, pl.description) AS name,
         CASE
             WHEN p.name IS NOT NULL THEN pl.description
             ELSE NULL
--- a/database/model/views/C_PROJECT_DETAILS_VT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/C_PROJECT_DETAILS_VT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
   <database name="VIEW C_PROJECT_DETAILS_VT">
-    <view name="C_PROJECT_DETAILS_VT"><![CDATA[SELECT pl.ad_client_id, pl.ad_org_id, pl.isactive, pl.created, pl.createdby, pl.updated, pl.updatedby, to_char('en_US') AS ad_language, pj.c_project_id, pl.c_projectline_id, pl.line, pl.plannedqty, pl.plannedprice, pl.plannedamt, pl.plannedmarginamt, pl.committedamt, pl.m_product_id, COALESCE(p.name, pl.description) AS name, 
+    <view name="C_PROJECT_DETAILS_VT"><![CDATA[SELECT pl.ad_client_id, pl.ad_org_id, pl.isactive, pl.created, pl.createdby, pl.updated, pl.updatedby, to_char('en_US') AS ad_language, pj.c_project_id, pl.c_projectline_id, pl.line, pl.plannedqty, pl.plannedprice, pl.plannedamt, pl.plannedmarginamt, pl.committedamt, pl.m_product_id, COALESCE(p.name, pl.description) AS name,
         CASE
             WHEN p.name IS NOT NULL THEN pl.description
             ELSE NULL
--- a/database/model/views/MA_SEQUENCE_EMPLOYEE_COST.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/MA_SEQUENCE_EMPLOYEE_COST.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
   <database name="VIEW MA_SEQUENCE_EMPLOYEE_COST">
-    <view name="MA_SEQUENCE_EMPLOYEE_COST"><![CDATA[SELECT ma_sequence.ma_sequence_id, c_salary_category_cost.c_salary_category_id, 
+    <view name="MA_SEQUENCE_EMPLOYEE_COST"><![CDATA[SELECT ma_sequence.ma_sequence_id, c_salary_category_cost.c_salary_category_id,
         CASE c_salary_category_cost.costuom
             WHEN 'H' THEN ma_sequence.costcenteruse * c_salary_category_cost.cost
             WHEN 'U' THEN sum(ma_sequenceproduct.quantity) * c_salary_category_cost.cost
--- a/database/model/views/MA_SEQUENCE_INDIRECT_COST_COST.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/MA_SEQUENCE_INDIRECT_COST_COST.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
   <database name="VIEW MA_SEQUENCE_INDIRECT_COST_COST">
-    <view name="MA_SEQUENCE_INDIRECT_COST_COST"><![CDATA[SELECT ma_sequence.ma_sequence_id, ma_indirect_cost_value.ma_indirect_cost_id, 
+    <view name="MA_SEQUENCE_INDIRECT_COST_COST"><![CDATA[SELECT ma_sequence.ma_sequence_id, ma_indirect_cost_value.ma_indirect_cost_id,
         CASE ma_indirect_cost_value.cost_uom
             WHEN 'H' THEN ma_sequence.costcenteruse * ma_indirect_cost_value.cost
             WHEN 'U' THEN sum(ma_sequenceproduct.quantity) * ma_indirect_cost_value.cost
--- a/database/model/views/MA_SEQUENCE_MACHINE_COST.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/MA_SEQUENCE_MACHINE_COST.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
   <database name="VIEW MA_SEQUENCE_MACHINE_COST">
-    <view name="MA_SEQUENCE_MACHINE_COST"><![CDATA[SELECT ma_sequence.ma_sequence_id, ma_machine_cost.ma_machine_id, 
+    <view name="MA_SEQUENCE_MACHINE_COST"><![CDATA[SELECT ma_sequence.ma_sequence_id, ma_machine_cost.ma_machine_id,
         CASE ma_machine_cost.costuom
             WHEN 'H' THEN ma_sequence.costcenteruse * ma_machine_cost.cost
             WHEN 'U' THEN sum(ma_sequenceproduct.quantity) * ma_machine_cost.cost
--- a/database/model/views/M_INOUT_LINE_V.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/M_INOUT_LINE_V.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
   <database name="VIEW M_INOUT_LINE_V">
-    <view name="M_INOUT_LINE_V"><![CDATA[SELECT iol.ad_client_id, iol.ad_org_id, iol.isactive, iol.created, iol.createdby, iol.updated, iol.updatedby, 'en_US' AS ad_language, iol.m_inout_id, iol.m_inoutline_id, iol.line, iol.movementqty, uom.uomsymbol, COALESCE(p.name, iol.description) AS name, 
+    <view name="M_INOUT_LINE_V"><![CDATA[SELECT iol.ad_client_id, iol.ad_org_id, iol.isactive, iol.created, iol.createdby, iol.updated, iol.updatedby, 'en_US' AS ad_language, iol.m_inout_id, iol.m_inoutline_id, iol.line, iol.movementqty, uom.uomsymbol, COALESCE(p.name, iol.description) AS name,
         CASE
             WHEN p.name IS NOT NULL THEN iol.description
             ELSE NULL
@@ -8,7 +8,7 @@
    FROM m_inoutline iol
    JOIN c_uom uom ON iol.c_uom_id = uom.c_uom_id
    LEFT JOIN m_product p ON iol.m_product_id = p.m_product_id
-UNION 
+UNION
  SELECT iol.ad_client_id, iol.ad_org_id, iol.isactive, iol.created, iol.createdby, iol.updated, iol.updatedby, 'en_US' AS ad_language, iol.m_inout_id, iol.m_inoutline_id, iol.line + b.line / 100 AS line, iol.movementqty * b.bomqty AS movementqty, uom.uomsymbol, p.name, b.description, p.documentnote, p.upc, p.sku, p.value AS productvalue, iol.m_locator_id, iol.lot, iol.serno
    FROM m_product_bom b
    JOIN m_inoutline iol ON b.m_product_id = iol.m_product_id
--- a/database/model/views/M_INOUT_LINE_VT.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/M_INOUT_LINE_VT.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
   <database name="VIEW M_INOUT_LINE_VT">
-    <view name="M_INOUT_LINE_VT"><![CDATA[SELECT iol.ad_client_id, iol.ad_org_id, iol.isactive, iol.created, iol.createdby, iol.updated, iol.updatedby, uom.ad_language, iol.m_inout_id, iol.m_inoutline_id, iol.line, iol.movementqty, uom.uomsymbol, COALESCE(COALESCE(pt.name, p.name), iol.description) AS name, 
+    <view name="M_INOUT_LINE_VT"><![CDATA[SELECT iol.ad_client_id, iol.ad_org_id, iol.isactive, iol.created, iol.createdby, iol.updated, iol.updatedby, uom.ad_language, iol.m_inout_id, iol.m_inoutline_id, iol.line, iol.movementqty, uom.uomsymbol, COALESCE(COALESCE(pt.name, p.name), iol.description) AS name,
         CASE
             WHEN COALESCE(pt.name, p.name) IS NOT NULL THEN iol.description
             ELSE NULL
@@ -9,7 +9,7 @@
    JOIN c_uom_trl uom ON iol.c_uom_id = uom.c_uom_id
    LEFT JOIN m_product p ON iol.m_product_id = p.m_product_id
    LEFT JOIN m_product_trl pt ON iol.m_product_id = pt.m_product_id AND uom.ad_language = pt.ad_language
-UNION 
+UNION
  SELECT iol.ad_client_id, iol.ad_org_id, iol.isactive, iol.created, iol.createdby, iol.updated, iol.updatedby, uom.ad_language, iol.m_inout_id, iol.m_inoutline_id, iol.line + b.line / 100 AS line, iol.movementqty * b.bomqty AS movementqty, uom.uomsymbol, COALESCE(pt.name, p.name) AS name, b.description, COALESCE(pt.documentnote, p.documentnote) AS documentnote, p.upc, p.sku, p.value AS productvalue, iol.m_locator_id, iol.lot, iol.serno
    FROM m_product_bom b
    JOIN m_inoutline iol ON b.m_product_id = iol.m_product_id
--- a/database/model/views/RV_C_INVOICE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,18 +1,18 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICE">
-    <view name="RV_C_INVOICE"><![CDATA[SELECT i.c_invoice_id, i.ad_client_id, i.ad_org_id, i.isactive, i.created, i.createdby, i.updated, i.updatedby, i.issotrx, i.documentno, i.docstatus, i.docaction, i.isprinted, i.isdiscountprinted, i.processing, i.processed, i.istransferred, i.ispaid, i.c_doctype_id, i.c_doctypetarget_id, i.c_order_id, i.description, i.isapproved, i.salesrep_id, i.dateinvoiced, i.dateprinted, i.dateacct, i.c_bpartner_id, i.c_bpartner_location_id, i.ad_user_id, b.c_bp_group_id, i.poreference, i.dateordered, i.c_currency_id, i.paymentrule, i.c_paymentterm_id, i.m_pricelist_id, i.c_campaign_id, i.c_project_id, i.c_activity_id, i.c_charge_id, 
+    <view name="RV_C_INVOICE"><![CDATA[SELECT i.c_invoice_id, i.ad_client_id, i.ad_org_id, i.isactive, i.created, i.createdby, i.updated, i.updatedby, i.issotrx, i.documentno, i.docstatus, i.docaction, i.isprinted, i.isdiscountprinted, i.processing, i.processed, i.istransferred, i.ispaid, i.c_doctype_id, i.c_doctypetarget_id, i.c_order_id, i.description, i.isapproved, i.salesrep_id, i.dateinvoiced, i.dateprinted, i.dateacct, i.c_bpartner_id, i.c_bpartner_location_id, i.ad_user_id, b.c_bp_group_id, i.poreference, i.dateordered, i.c_currency_id, i.paymentrule, i.c_paymentterm_id, i.m_pricelist_id, i.c_campaign_id, i.c_project_id, i.c_activity_id, i.c_charge_id,
         CASE substr(d.docbasetype, 3)
             WHEN 'C' THEN i.chargeamt * -1
             ELSE i.chargeamt
-        END AS chargeamt, 
+        END AS chargeamt,
         CASE substr(d.docbasetype, 3)
             WHEN 'C' THEN i.totallines * -1
             ELSE i.totallines
-        END AS totallines, 
+        END AS totallines,
         CASE substr(d.docbasetype, 3)
             WHEN 'C' THEN i.grandtotal * -1
             ELSE i.grandtotal
-        END AS grandtotal, 
+        END AS grandtotal,
         CASE substr(d.docbasetype, 3)
             WHEN 'C' THEN -1
             ELSE 1
--- a/database/model/views/RV_C_INVOICELINE.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICELINE.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,18 +1,18 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICELINE">
-    <view name="RV_C_INVOICELINE"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.c_invoiceline_id, i.c_invoice_id, i.salesrep_id, i.c_bpartner_id, i.c_bp_group_id, il.m_product_id, p.m_product_category_id, i.dateinvoiced, i.dateacct, il.qtyinvoiced * i.multiplier AS qtyinvoiced, il.pricelist, il.priceactual, il.pricelimit, 
+    <view name="RV_C_INVOICELINE"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.c_invoiceline_id, i.c_invoice_id, i.salesrep_id, i.c_bpartner_id, i.c_bp_group_id, il.m_product_id, p.m_product_category_id, i.dateinvoiced, i.dateacct, il.qtyinvoiced * i.multiplier AS qtyinvoiced, il.pricelist, il.priceactual, il.pricelimit,
         CASE il.pricelist
             WHEN 0 THEN 0
             ELSE round((il.pricelist - il.priceactual) / il.pricelist * 100, 2)
-        END AS discount, 
+        END AS discount,
         CASE il.pricelimit
             WHEN 0 THEN 0
             ELSE round((il.priceactual - il.pricelimit) / il.pricelimit * 100, 2)
-        END AS margin, round(i.multiplier * il.linenetamt, 2) AS linenetamt, round(i.multiplier * il.pricelist * il.qtyinvoiced, 2) AS linelistamt, 
+        END AS margin, round(i.multiplier * il.linenetamt, 2) AS linenetamt, round(i.multiplier * il.pricelist * il.qtyinvoiced, 2) AS linelistamt,
         CASE
             WHEN il.pricelimit IS NULL THEN round(i.multiplier * il.linenetamt, 2)
             ELSE round(i.multiplier * il.pricelimit * il.qtyinvoiced, 2)
-        END AS linelimitamt, round(i.multiplier * il.pricelist * il.qtyinvoiced - il.linenetamt, 2) AS linediscountamt, 
+        END AS linelimitamt, round(i.multiplier * il.pricelist * il.qtyinvoiced - il.linenetamt, 2) AS linediscountamt,
         CASE
             WHEN il.pricelimit IS NULL THEN 0
             ELSE round(i.multiplier * il.linenetamt - il.pricelimit * il.qtyinvoiced, 2)
--- a/database/model/views/RV_C_INVOICE_CUSTOMERPRODQTR.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICE_CUSTOMERPRODQTR.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICE_CUSTOMERPRODQTR">
-    <view name="RV_C_INVOICE_CUSTOMERPRODQTR"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.c_bpartner_id, il.m_product_category_id, TRUNC(il.dateinvoiced, 'Q') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt, 
+    <view name="RV_C_INVOICE_CUSTOMERPRODQTR"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.c_bpartner_id, il.m_product_category_id, TRUNC(il.dateinvoiced, 'Q') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt,
         CASE sum(il.linelistamt)
             WHEN 0 THEN 0
             ELSE round((sum(il.linelistamt) - sum(il.linenetamt)) / sum(il.linelistamt) * 100, 2)
-        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt, 
+        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt,
         CASE sum(il.linenetamt)
             WHEN 0 THEN 0
             ELSE 100 - round((sum(il.linenetamt) - sum(il.lineoverlimitamt)) / sum(il.linenetamt) * 100, 2)
--- a/database/model/views/RV_C_INVOICE_CUSTOMERVENDQTR.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICE_CUSTOMERVENDQTR.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICE_CUSTOMERVENDQTR">
-    <view name="RV_C_INVOICE_CUSTOMERVENDQTR"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.c_bpartner_id, po.c_bpartner_id AS vendor_id, TRUNC(il.dateinvoiced, 'Q') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt, 
+    <view name="RV_C_INVOICE_CUSTOMERVENDQTR"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.c_bpartner_id, po.c_bpartner_id AS vendor_id, TRUNC(il.dateinvoiced, 'Q') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt,
         CASE sum(il.linelistamt)
             WHEN 0 THEN 0
             ELSE round((sum(il.linelistamt) - sum(il.linenetamt)) / sum(il.linelistamt) * 100, 2)
-        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt, 
+        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt,
         CASE sum(il.linenetamt)
             WHEN 0 THEN 0
             ELSE 100 - round((sum(il.linenetamt) - sum(il.lineoverlimitamt)) / sum(il.linenetamt) * 100, 2)
--- a/database/model/views/RV_C_INVOICE_DAY.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICE_DAY.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICE_DAY">
-    <view name="RV_C_INVOICE_DAY"><![CDATA[SELECT rv_c_invoiceline.ad_client_id, rv_c_invoiceline.ad_org_id, rv_c_invoiceline.salesrep_id, TRUNC(rv_c_invoiceline.dateinvoiced, 'DD') AS dateinvoiced, sum(rv_c_invoiceline.linenetamt) AS linenetamt, sum(rv_c_invoiceline.linelistamt) AS linelistamt, sum(rv_c_invoiceline.linelimitamt) AS linelimitamt, sum(rv_c_invoiceline.linediscountamt) AS linediscountamt, 
+    <view name="RV_C_INVOICE_DAY"><![CDATA[SELECT rv_c_invoiceline.ad_client_id, rv_c_invoiceline.ad_org_id, rv_c_invoiceline.salesrep_id, TRUNC(rv_c_invoiceline.dateinvoiced, 'DD') AS dateinvoiced, sum(rv_c_invoiceline.linenetamt) AS linenetamt, sum(rv_c_invoiceline.linelistamt) AS linelistamt, sum(rv_c_invoiceline.linelimitamt) AS linelimitamt, sum(rv_c_invoiceline.linediscountamt) AS linediscountamt,
         CASE sum(rv_c_invoiceline.linelistamt)
             WHEN 0 THEN 0
             ELSE round((sum(rv_c_invoiceline.linelistamt) - sum(rv_c_invoiceline.linenetamt)) / sum(rv_c_invoiceline.linelistamt) * 100, 2)
-        END AS linediscount, sum(rv_c_invoiceline.lineoverlimitamt) AS lineoverlimitamt, 
+        END AS linediscount, sum(rv_c_invoiceline.lineoverlimitamt) AS lineoverlimitamt,
         CASE sum(rv_c_invoiceline.linenetamt)
             WHEN 0 THEN 0
             ELSE 100 - round((sum(rv_c_invoiceline.linenetamt) - sum(rv_c_invoiceline.lineoverlimitamt)) / sum(rv_c_invoiceline.linenetamt) * 100, 2)
--- a/database/model/views/RV_C_INVOICE_MONTH.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICE_MONTH.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICE_MONTH">
-    <view name="RV_C_INVOICE_MONTH"><![CDATA[SELECT rv_c_invoiceline.ad_client_id, rv_c_invoiceline.ad_org_id, rv_c_invoiceline.salesrep_id, TRUNC(rv_c_invoiceline.dateinvoiced, 'MM') AS dateinvoiced, sum(rv_c_invoiceline.linenetamt) AS linenetamt, sum(rv_c_invoiceline.linelistamt) AS linelistamt, sum(rv_c_invoiceline.linelimitamt) AS linelimitamt, sum(rv_c_invoiceline.linediscountamt) AS linediscountamt, 
+    <view name="RV_C_INVOICE_MONTH"><![CDATA[SELECT rv_c_invoiceline.ad_client_id, rv_c_invoiceline.ad_org_id, rv_c_invoiceline.salesrep_id, TRUNC(rv_c_invoiceline.dateinvoiced, 'MM') AS dateinvoiced, sum(rv_c_invoiceline.linenetamt) AS linenetamt, sum(rv_c_invoiceline.linelistamt) AS linelistamt, sum(rv_c_invoiceline.linelimitamt) AS linelimitamt, sum(rv_c_invoiceline.linediscountamt) AS linediscountamt,
         CASE sum(rv_c_invoiceline.linelistamt)
             WHEN 0 THEN 0
             ELSE round((sum(rv_c_invoiceline.linelistamt) - sum(rv_c_invoiceline.linenetamt)) / sum(rv_c_invoiceline.linelistamt) * 100, 2)
-        END AS linediscount, sum(rv_c_invoiceline.lineoverlimitamt) AS lineoverlimitamt, 
+        END AS linediscount, sum(rv_c_invoiceline.lineoverlimitamt) AS lineoverlimitamt,
         CASE sum(rv_c_invoiceline.linenetamt)
             WHEN 0 THEN 0
             ELSE 100 - round((sum(rv_c_invoiceline.linenetamt) - sum(rv_c_invoiceline.lineoverlimitamt)) / sum(rv_c_invoiceline.linenetamt) * 100, 2)
--- a/database/model/views/RV_C_INVOICE_PRODMONTH.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICE_PRODMONTH.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICE_PRODMONTH">
-    <view name="RV_C_INVOICE_PRODMONTH"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.m_product_category_id, TRUNC(il.dateinvoiced, 'MM') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt, 
+    <view name="RV_C_INVOICE_PRODMONTH"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.m_product_category_id, TRUNC(il.dateinvoiced, 'MM') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt,
         CASE sum(il.linelistamt)
             WHEN 0 THEN 0
             ELSE round((sum(il.linelistamt) - sum(il.linenetamt)) / sum(il.linelistamt) * 100, 2)
-        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt, 
+        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt,
         CASE sum(il.linenetamt)
             WHEN 0 THEN 0
             ELSE 100 - round((sum(il.linenetamt) - sum(il.lineoverlimitamt)) / sum(il.linenetamt) * 100, 2)
--- a/database/model/views/RV_C_INVOICE_PRODWEEK.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICE_PRODWEEK.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICE_PRODWEEK">
-    <view name="RV_C_INVOICE_PRODWEEK"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.m_product_category_id, TRUNC(il.dateinvoiced, 'DY') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt, 
+    <view name="RV_C_INVOICE_PRODWEEK"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, il.m_product_category_id, TRUNC(il.dateinvoiced, 'DY') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt,
         CASE sum(il.linelistamt)
             WHEN 0 THEN 0
             ELSE round((sum(il.linelistamt) - sum(il.linenetamt)) / sum(il.linelistamt) * 100, 2)
-        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt, 
+        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt,
         CASE sum(il.linenetamt)
             WHEN 0 THEN 0
             ELSE 100 - round((sum(il.linenetamt) - sum(il.lineoverlimitamt)) / sum(il.linenetamt) * 100, 2)
--- a/database/model/views/RV_C_INVOICE_VENDORMONTH.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICE_VENDORMONTH.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICE_VENDORMONTH">
-    <view name="RV_C_INVOICE_VENDORMONTH"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, po.c_bpartner_id, TRUNC(il.dateinvoiced, 'MM') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt, 
+    <view name="RV_C_INVOICE_VENDORMONTH"><![CDATA[SELECT il.ad_client_id, il.ad_org_id, po.c_bpartner_id, TRUNC(il.dateinvoiced, 'MM') AS dateinvoiced, sum(il.linenetamt) AS linenetamt, sum(il.linelistamt) AS linelistamt, sum(il.linelimitamt) AS linelimitamt, sum(il.linediscountamt) AS linediscountamt,
         CASE sum(il.linelistamt)
             WHEN 0 THEN 0
             ELSE round((sum(il.linelistamt) - sum(il.linenetamt)) / sum(il.linelistamt) * 100, 2)
-        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt, 
+        END AS linediscount, sum(il.lineoverlimitamt) AS lineoverlimitamt,
         CASE sum(il.linenetamt)
             WHEN 0 THEN 0
             ELSE 100 - round((sum(il.linenetamt) - sum(il.lineoverlimitamt)) / sum(il.linenetamt) * 100, 2)
--- a/database/model/views/RV_C_INVOICE_WEEK.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_C_INVOICE_WEEK.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,10 +1,10 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_C_INVOICE_WEEK">
-    <view name="RV_C_INVOICE_WEEK"><![CDATA[SELECT rv_c_invoiceline.ad_client_id, rv_c_invoiceline.ad_org_id, rv_c_invoiceline.salesrep_id, TRUNC(rv_c_invoiceline.dateinvoiced, 'DY') AS dateinvoiced, sum(rv_c_invoiceline.linenetamt) AS linenetamt, sum(rv_c_invoiceline.linelistamt) AS linelistamt, sum(rv_c_invoiceline.linelimitamt) AS linelimitamt, sum(rv_c_invoiceline.linediscountamt) AS linediscountamt, 
+    <view name="RV_C_INVOICE_WEEK"><![CDATA[SELECT rv_c_invoiceline.ad_client_id, rv_c_invoiceline.ad_org_id, rv_c_invoiceline.salesrep_id, TRUNC(rv_c_invoiceline.dateinvoiced, 'DY') AS dateinvoiced, sum(rv_c_invoiceline.linenetamt) AS linenetamt, sum(rv_c_invoiceline.linelistamt) AS linelistamt, sum(rv_c_invoiceline.linelimitamt) AS linelimitamt, sum(rv_c_invoiceline.linediscountamt) AS linediscountamt,
         CASE sum(rv_c_invoiceline.linelistamt)
             WHEN 0 THEN 0
             ELSE round((sum(rv_c_invoiceline.linelistamt) - sum(rv_c_invoiceline.linenetamt)) / sum(rv_c_invoiceline.linelistamt) * 100, 2)
-        END AS linediscount, sum(rv_c_invoiceline.lineoverlimitamt) AS lineoverlimitamt, 
+        END AS linediscount, sum(rv_c_invoiceline.lineoverlimitamt) AS lineoverlimitamt,
         CASE sum(rv_c_invoiceline.linenetamt)
             WHEN 0 THEN 0
             ELSE 100 - round((sum(rv_c_invoiceline.linenetamt) - sum(rv_c_invoiceline.lineoverlimitamt)) / sum(rv_c_invoiceline.linenetamt) * 100, 2)
--- a/database/model/views/RV_PRODUCT_COSTING.xml	Tue Apr 22 13:30:10 2008 +0000
+++ b/database/model/views/RV_PRODUCT_COSTING.xml	Tue Apr 22 13:47:26 2008 +0000
@@ -1,14 +1,14 @@
 <?xml version="1.0"?>
   <database name="VIEW RV_PRODUCT_COSTING">
-    <view name="RV_PRODUCT_COSTING"><![CDATA[SELECT pc.m_product_id, pc.c_acctschema_id, p.value, p.name, p.m_product_category_id, pc.ad_client_id, pc.ad_org_id, pc.isactive, pc.created, pc.createdby, pc.updated, pc.updatedby, pc.currentcostprice, pc.futurecostprice, pc.coststandard, pc.coststandardpoqty, pc.coststandardpoamt, 
+    <view name="RV_PRODUCT_COSTING"><![CDATA[SELECT pc.m_product_id, pc.c_acctschema_id, p.value, p.name, p.m_product_category_id, pc.ad_client_id, pc.ad_org_id, pc.isactive, pc.created, pc.createdby, pc.updated, pc.updatedby, pc.currentcostprice, pc.futurecostprice, pc.coststandard, pc.coststandardpoqty, pc.coststandardpoamt,
         CASE pc.coststandardpoqty
             WHEN 0 THEN 0
             ELSE pc.coststandardpoamt / pc.coststandardpoqty
-        END AS coststandardpodiff, pc.coststandardcumqty, pc.coststandardcumamt, 
+        END AS coststandardpodiff, pc.coststandardcumqty, pc.coststandardcumamt,
         CASE pc.coststandardcumqty
             WHEN 0 THEN 0
             ELSE pc.coststandardcumamt / pc.coststandardcumqty
-        END AS coststandardinvdiff, pc.costaverage, pc.costaveragecumqty, pc.costaveragecumamt, pc.totalinvqty, pc.totalinvamt, 
+        END AS coststandardinvdiff, pc.costaverage, pc.costaveragecumqty, pc.costaveragecumamt, pc.totalinvqty, pc.totalinvamt,
         CASE pc.totalinvqty
             WHEN 0 THEN 0
             ELSE pc.totalinvamt / pc.totalinvqty