src/org/openbravo/erpCommon/ad_reports/ReportTrialBalance_data.xsql
author David Baz Fayos <david.baz@openbravo.com>
Tue, 27 May 2008 15:26:10 +0000
changeset 1044 8691bbc94032
parent 832 2090f49a85a0
child 1276 8c52bdadbab9
permissions -rw-r--r--
Removed old frame parameter of windowTableId
carlos@0
     1
<?xml version="1.0" encoding="UTF-8" ?>
carlos@0
     2
<!--
carlos@0
     3
 *************************************************************************
carlos@0
     4
 * The contents of this file are subject to the Openbravo  Public  License
carlos@0
     5
 * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
carlos@0
     6
 * Version 1.1  with a permitted attribution clause; you may not  use this
carlos@0
     7
 * file except in compliance with the License. You  may  obtain  a copy of
carlos@0
     8
 * the License at http://www.openbravo.com/legal/license.html 
carlos@0
     9
 * Software distributed under the License  is  distributed  on  an "AS IS"
carlos@0
    10
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
carlos@0
    11
 * License for the specific  language  governing  rights  and  limitations
carlos@0
    12
 * under the License. 
carlos@0
    13
 * The Original Code is Openbravo ERP. 
carlos@0
    14
 * The Initial Developer of the Original Code is Openbravo SL 
carlos@0
    15
 * All portions are Copyright (C) 2001-2006 Openbravo SL 
carlos@0
    16
 * All Rights Reserved. 
carlos@0
    17
 * Contributor(s):  ______________________________________.
carlos@0
    18
 ************************************************************************
carlos@0
    19
-->
carlos@0
    20
carlos@0
    21
carlos@0
    22
carlos@0
    23
carlos@0
    24
carlos@0
    25
<SqlClass name="ReportTrialBalanceData" package="org.openbravo.erpCommon.ad_reports">
carlos@0
    26
  <SqlClassComment></SqlClassComment>
carlos@0
    27
  <SqlMethod name="select" type="preparedStatement" return="multiple">
carlos@0
    28
    <SqlMethodComment></SqlMethodComment>
carlos@0
    29
    <Sql>
carlos@0
    30
    <![CDATA[
carlos@0
    31
      SELECT SUM(PARENT_ID) AS PARENT_ID, ID, NAME, ACCOUNT_ID, ELEMENTLEVEL, SUM(AMTACCTDR) AS AMTACCTDR, 
carlos@0
    32
      SUM(AMTACCTCR) AS AMTACCTCR, SUM(SALDO_INICIAL) AS SALDO_INICIAL,0 AS TOTALAMTACCTDR, 0 AS TOTALAMTACCTCR,
carlos@0
    33
      SUM(SALDO_INICIAL+AMTACCTDR-AMTACCTCR) AS SALDO_FINAL, TO_DATE(?) AS DATE_FROM, TO_DATE(?) AS DATE_TO, ? AS AD_ORG_ID,
carlos@520
    34
      '' AS BP, '' AS PADRE
carlos@0
    35
      FROM
carlos@0
    36
      (SELECT AD_TREENODE.PARENT_ID, C_ELEMENTVALUE.C_ELEMENTVALUE_ID AS ID, C_ELEMENTVALUE.ELEMENTLEVEL, 
carlos@0
    37
      C_ELEMENTVALUE.NAME AS NAME, C_ELEMENTVALUE.VALUE AS ACCOUNT_ID, 0 AS SALDO_INICIAL, 0 AS AMTACCTDR, 
carlos@0
    38
      0 AS AMTACCTCR
carlos@0
    39
      FROM AD_TREENODE, C_ELEMENTVALUE
carlos@0
    40
      WHERE AD_TREENODE.NODE_ID = C_ELEMENTVALUE.C_ELEMENTVALUE_ID
carlos@423
    41
      AND AD_TREENODE.AD_TREE_ID = TO_NUMBER(?)
carlos@0
    42
      AND AD_TREENODE.ISACTIVE = 'Y'
carlos@0
    43
      AND C_ELEMENTVALUE.ISACTIVE = 'Y'
eduardo@445
    44
      AND (select max(c_element_id) from c_acctschema_element where c_acctschema_id = ? and ELEMENTTYPE = 'AC') = C_ELEMENTVALUE.C_ELEMENT_ID
carlos@0
    45
      UNION		
carlos@0
    46
      SELECT 0 AS PARENT_ID, F.ACCOUNT_ID AS ID, EV.ELEMENTLEVEL, EV.NAME AS NAME, EV.VALUE AS ACCOUNT_ID, 
carlos@0
    47
      SUM((CASE f.FACTACCTTYPE WHEN 'O' THEN F.AMTACCTDR-F.AMTACCTCR ELSE 0 END)) AS SALDO_INICIAL, 
carlos@0
    48
      SUM((CASE f.FACTACCTTYPE WHEN 'O' THEN 0 ELSE F.AMTACCTDR END)) AS AMTACCTDR, 
carlos@0
    49
      SUM((CASE f.FACTACCTTYPE WHEN 'O' THEN 0 ELSE f.AMTACCTCR END)) AS AMTACCTCR 
carlos@0
    50
      FROM FACT_ACCT F, C_ELEMENTVALUE EV
carlos@0
    51
      WHERE F.ACCOUNT_ID = EV.C_ELEMENTVALUE_ID
carlos@0
    52
      AND f.AD_ORG_ID IN('2')
carlos@0
    53
      AND F.AD_CLIENT_ID IN ('1')
carlos@0
    54
      AND F.AD_ORG_ID IN('1')
carlos@0
    55
      AND 1=1
carlos@0
    56
      AND F.FACTACCTTYPE <> 'R'
carlos@0
    57
      AND F.FACTACCTTYPE <> 'C'
carlos@0
    58
      AND F.ISACTIVE = 'Y'
carlos@0
    59
      GROUP BY ACCOUNT_ID,EV.NAME, EV.VALUE, EV.ELEMENTLEVEL) A
carlos@0
    60
      GROUP BY ID, NAME, ACCOUNT_ID, ELEMENTLEVEL
carlos@0
    61
      ORDER BY PARENT_ID, ID, NAME, ACCOUNT_ID, ELEMENTLEVEL
carlos@0
    62
      ]]></Sql>
carlos@0
    63
    <Field name="rownum" value="count"/>
carlos@0
    64
    <Parameter name="dateFrom"/>
carlos@0
    65
    <Parameter name="dateTo"/>
carlos@0
    66
    <Parameter name="org"/>
carlos@0
    67
    <Parameter name="treeAcct"/>
eduardo@445
    68
    <Parameter name="acctSchema"/>    
carlos@0
    69
    <Parameter name="orgFamily" type="replace" optional="true" after="f.AD_ORG_ID IN(" text="'2'"/>
carlos@0
    70
    <Parameter name="adUserClient" type="replace" optional="true" after="F.AD_CLIENT_ID IN (" text="'1'"/>
carlos@0
    71
    <Parameter name="adUserOrg" type="replace" optional="true" after="F.AD_ORG_ID IN(" text="'1'"/>
carlos@0
    72
    <Parameter name="parDateFrom" optional="true" after="AND 1=1"><![CDATA[AND F.DATEACCT >= TO_DATE(?)]]></Parameter>
carlos@0
    73
    <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[AND F.DATEACCT < TO_DATE(?)]]></Parameter>
carlos@832
    74
    <Parameter name="accountFrom" optional="true" after="AND 1=1"><![CDATA[AND TO_NUMBER(EV.VALUE) >= TO_NUMBER(?)]]></Parameter>
carlos@832
    75
    <Parameter name="accountTo" optional="true" after="AND 1=1"><![CDATA[AND TO_NUMBER(EV.VALUE) <= TO_NUMBER(?)]]></Parameter>
eduardo@445
    76
    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[ AND F.C_ACCTSCHEMA_ID = to_number(?)]]></Parameter>    
carlos@0
    77
  </SqlMethod>
carlos@0
    78
  
carlos@0
    79
  
carlos@0
    80
  <SqlMethod name="selectBP" type="preparedStatement" return="multiple">
carlos@0
    81
    <SqlMethodComment></SqlMethodComment>
carlos@0
    82
    <Sql>
carlos@0
    83
    <![CDATA[
carlos@0
    84
      SELECT 0 AS PARENT_ID, bp, ID, NAME, ACCOUNT_ID, ELEMENTLEVEL, SUM(AMTACCTDR) AS AMTACCTDR, 
carlos@0
    85
      SUM(AMTACCTCR) AS AMTACCTCR, SUM(SALDO_INICIAL) AS SALDO_INICIAL,0 AS TOTALAMTACCTDR, 0 AS TOTALAMTACCTCR,
carlos@0
    86
      SUM(SALDO_INICIAL+AMTACCTDR-AMTACCTCR) AS SALDO_FINAL, TO_DATE(?) AS DATE_FROM, TO_DATE(?) AS DATE_TO, ? AS AD_ORG_ID
carlos@0
    87
      FROM
carlos@0
    88
      (SELECT f.c_bpartner_id, bp.name as bp, 0 AS PARENT_ID, F.ACCOUNT_ID AS ID, EV.ELEMENTLEVEL, EV.NAME AS NAME, EV.VALUE AS ACCOUNT_ID, 
carlos@0
    89
      SUM((CASE f.FACTACCTTYPE WHEN 'O' THEN F.AMTACCTDR-F.AMTACCTCR ELSE 0 END)) AS SALDO_INICIAL, 
carlos@0
    90
      SUM((CASE f.FACTACCTTYPE WHEN 'O' THEN 0 ELSE F.AMTACCTDR END)) AS AMTACCTDR, 
carlos@0
    91
      SUM((CASE f.FACTACCTTYPE WHEN 'O' THEN 0 ELSE f.AMTACCTCR END)) AS AMTACCTCR 
carlos@0
    92
      FROM C_ELEMENTVALUE EV, 
carlos@0
    93
           FACT_ACCT F left join c_bpartner bp on bp.c_bpartner_id = f.c_bpartner_id
carlos@0
    94
      WHERE F.ACCOUNT_ID = EV.C_ELEMENTVALUE_ID
carlos@0
    95
      AND f.AD_ORG_ID IN('2')
carlos@0
    96
      AND F.AD_CLIENT_ID IN ('1')
carlos@0
    97
      AND F.AD_ORG_ID IN('1')
carlos@0
    98
      AND 1=1
carlos@0
    99
      AND F.FACTACCTTYPE <> 'R'
carlos@0
   100
      AND F.FACTACCTTYPE <> 'C'
carlos@0
   101
      AND F.ISACTIVE = 'Y'
carlos@0
   102
      GROUP BY f.c_bpartner_id, bp.name, ACCOUNT_ID,EV.NAME, EV.VALUE, EV.ELEMENTLEVEL) A
carlos@0
   103
      GROUP BY bp, ID, NAME, ACCOUNT_ID, ELEMENTLEVEL
carlos@0
   104
      ORDER BY bp, ID, ACCOUNT_ID
carlos@0
   105
      ]]></Sql>
carlos@0
   106
    <Field name="rownum" value="count"/>
carlos@0
   107
    <Parameter name="dateFrom"/>
carlos@0
   108
    <Parameter name="dateTo"/>
carlos@0
   109
    <Parameter name="org"/>
carlos@0
   110
    <Parameter name="orgFamily" type="replace" optional="true" after="f.AD_ORG_ID IN(" text="'2'"/>
carlos@0
   111
    <Parameter name="adUserClient" type="replace" optional="true" after="F.AD_CLIENT_ID IN (" text="'1'"/>
carlos@0
   112
    <Parameter name="adUserOrg" type="replace" optional="true" after="F.AD_ORG_ID IN(" text="'1'"/>
carlos@0
   113
    <Parameter name="parDateFrom" optional="true" after="AND 1=1"><![CDATA[AND F.DATEACCT >= TO_DATE(?)]]></Parameter>
carlos@0
   114
    <Parameter name="parDateTo" optional="true" after="AND 1=1"><![CDATA[AND F.DATEACCT < TO_DATE(?)]]></Parameter>
carlos@832
   115
    <Parameter name="accountFrom" optional="true" after="AND 1=1"><![CDATA[AND TO_NUMBER(EV.VALUE) >= TO_NUMBER(?)]]></Parameter>
carlos@832
   116
    <Parameter name="accountTo" optional="true" after="AND 1=1"><![CDATA[AND TO_NUMBER(EV.VALUE) <= TO_NUMBER(?)]]></Parameter>
carlos@0
   117
    <Parameter name="cBpartnerId" optional="true" type="argument" after="AND 1=1"><![CDATA[ AND F.C_BPARTNER_ID IN]]></Parameter>
eduardo@445
   118
    <Parameter name="acctSchema" optional="true" after="AND 1=1"><![CDATA[ AND F.C_ACCTSCHEMA_ID = to_number(?)]]></Parameter>        
carlos@0
   119
  </SqlMethod>
carlos@0
   120
  
carlos@0
   121
  <SqlMethod name="set" type="constant" return="multiple">
carlos@0
   122
      <SqlMethodComment></SqlMethodComment>
carlos@0
   123
      <Sql></Sql>
carlos@0
   124
  </SqlMethod>
carlos@0
   125
  <SqlMethod name="treeOrg" type="preparedStatement" return="string">
carlos@0
   126
    <SqlMethodComment></SqlMethodComment>
carlos@0
   127
    <Sql>
carlos@0
   128
        SELECT AD_TREE_ORG_ID FROM AD_CLIENTINFO
carlos@423
   129
        WHERE AD_CLIENT_ID = TO_NUMBER(?)
carlos@0
   130
    </Sql>
carlos@0
   131
    <Parameter name="client"/>
carlos@0
   132
  </SqlMethod>
carlos@0
   133
  <SqlMethod name="treeAccount" type="preparedStatement" return="string">
carlos@0
   134
    <SqlMethodComment></SqlMethodComment>
carlos@0
   135
    <Sql>
carlos@0
   136
        SELECT AD_TREE_ID FROM AD_TREE
carlos@423
   137
        WHERE AD_CLIENT_ID = TO_NUMBER(?)
carlos@0
   138
        AND TREETYPE = 'EV'
carlos@0
   139
        
carlos@0
   140
    </Sql>
carlos@0
   141
    <Parameter name="client"/>
carlos@0
   142
  </SqlMethod>
carlos@0
   143
  <SqlMethod name="selectCompany" type="preparedStatement" return="string">
carlos@0
   144
    <SqlMethodComment></SqlMethodComment>
carlos@0
   145
    <Sql>
carlos@0
   146
        SELECT NAME
carlos@0
   147
        FROM AD_CLIENT
carlos@423
   148
        WHERE AD_CLIENT_ID = TO_NUMBER(?)
carlos@0
   149
    </Sql>
carlos@0
   150
    <Parameter name="client"/>
carlos@0
   151
  </SqlMethod>
carlos@0
   152
  <SqlMethod name="selectAccount" type="preparedStatement" return="multiple">
carlos@0
   153
    <SqlMethodComment></SqlMethodComment>
carlos@0
   154
    <Sql><![CDATA[
carlos@0
   155
        SELECT C_ElementValue.value as id, 
carlos@0
   156
        ((CASE C_ElementValue.isActive WHEN 'N' THEN '**' ELSE '' END) || C_ElementValue.value || ' - ' || C_ElementValue.Name) as name 
carlos@0
   157
        FROM C_ElementValue
carlos@0
   158
        WHERE C_ElementValue.AD_Org_ID IN('1') 
carlos@0
   159
        AND C_ElementValue.AD_Client_ID IN('1')  
carlos@0
   160
        AND C_ElementValue.IsSummary='N' 
carlos@423
   161
        AND (C_ElementValue.isActive = 'Y' OR C_ElementValue.C_ElementValue_ID = TO_NUMBER(?) ) 
eduardo@445
   162
        AND 1=1
carlos@0
   163
        ORDER BY C_ElementValue.Value
carlos@0
   164
    ]]></Sql>
carlos@0
   165
  <Parameter name="adOrgClient" type="replace" optional="true" after="C_ElementValue.AD_Org_ID IN(" text="'1'"/>
carlos@0
   166
  <Parameter name="adUserClient" type="replace" optional="true" after="C_ElementValue.AD_Client_ID IN(" text="'1'"/>
carlos@0
   167
  <Parameter name="cElementvalueId"/>
eduardo@445
   168
  <Parameter name="schema" optional="true" after="AND 1=1"><![CDATA[ AND (select max(c_element_id) from c_acctschema_element where c_acctschema_id = ? and ELEMENTTYPE = 'AC') = C_ElementValue.c_element_id ]]></Parameter>  
carlos@0
   169
  </SqlMethod>
carlos@520
   170
  <SqlMethod name="selectAccountDouble" type="preparedStatement" return="multiple">
carlos@520
   171
    <SqlMethodComment></SqlMethodComment>
carlos@520
   172
    <Sql><![CDATA[
carlos@520
   173
        SELECT c_acctschema_element.c_acctschema_id AS PADRE, C_ElementValue.value as id, 
carlos@520
   174
        ((CASE C_ElementValue.isActive WHEN 'N' THEN '**' ELSE '' END) || C_ElementValue.value || ' - ' || C_ElementValue.Name) as name 
carlos@520
   175
        FROM C_ElementValue, c_acctschema_element
carlos@520
   176
        WHERE C_ElementValue.AD_Org_ID IN('1') 
carlos@520
   177
        AND C_ElementValue.AD_Client_ID IN('1')  
carlos@520
   178
        AND C_ElementValue.IsSummary='N' 
carlos@520
   179
        AND (C_ElementValue.isActive = 'Y' OR C_ElementValue.C_ElementValue_ID = TO_NUMBER(?) ) 
carlos@520
   180
        AND 1=1
carlos@520
   181
        AND c_acctschema_element.ELEMENTTYPE = 'AC'
carlos@520
   182
        and c_acctschema_element.c_acctschema_id = C_ElementValue.c_element_id         
carlos@520
   183
        ORDER BY C_ElementValue.Value
carlos@520
   184
    ]]></Sql>
carlos@520
   185
  <Parameter name="adOrgClient" type="replace" optional="true" after="C_ElementValue.AD_Org_ID IN(" text="'1'"/>
carlos@520
   186
  <Parameter name="adUserClient" type="replace" optional="true" after="C_ElementValue.AD_Client_ID IN(" text="'1'"/>
carlos@520
   187
  <Parameter name="cElementvalueId"/>  
carlos@520
   188
  </SqlMethod>  
carlos@0
   189
carlos@0
   190
  <SqlMethod name="selectAccountingName" type="preparedStatement" return="string">
carlos@0
   191
    <SqlMethodComment></SqlMethodComment>
carlos@0
   192
    <Sql><![CDATA[
carlos@0
   193
        SELECT C_ELEMENTVALUE.VALUE||'-'||C_ELEMENTVALUE.NAME
carlos@0
   194
        FROM C_ELEMENTVALUE
carlos@0
   195
        WHERE C_ELEMENTVALUE.VALUE = ?
carlos@0
   196
        AND C_ELEMENTVALUE.ISACTIVE = 'Y'
carlos@0
   197
    ]]></Sql>
carlos@0
   198
  <Parameter name="cElementvalueId"/>
carlos@0
   199
  </SqlMethod>
carlos@0
   200
  <SqlMethod name="selectLastAccount" type="preparedStatement" return="string" default="">
carlos@0
   201
    <SqlMethodComment></SqlMethodComment>
carlos@0
   202
    <Sql><![CDATA[
carlos@0
   203
	    SELECT MAX(C_ELEMENTVALUE.VALUE) AS ID 
carlos@0
   204
        FROM C_ELEMENTVALUE
carlos@0
   205
        WHERE C_ELEMENTVALUE.AD_Org_ID IN('1') 
carlos@0
   206
       AND C_ELEMENTVALUE.AD_Client_ID IN('1')  
carlos@0
   207
       AND C_ELEMENTVALUE.IsSummary='N'
carlos@0
   208
    ]]></Sql>
carlos@0
   209
  <Parameter name="adOrgClient" type="replace" optional="true" after="C_ELEMENTVALUE.AD_Org_ID IN(" text="'1'"/>
carlos@0
   210
  <Parameter name="adUserClient" type="replace" optional="true" after="C_ELEMENTVALUE.AD_Client_ID IN(" text="'1'"/>
carlos@0
   211
  </SqlMethod>
carlos@0
   212
</SqlClass>