src/org/openbravo/erpCommon/ad_reports/ReportOrderNotInvoice_data.xsql
author Carlos Romero <carlos.romero@openbravo.com>
Tue, 06 Nov 2007 08:33:31 +0000
changeset 0 0247c26f10c6
child 423 ecf368072c48
permissions -rw-r--r--
Modified PostgreSQL post script in order to include C_DEBT_PAYMENT_GENERATE modification tules
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="ReportOrderNotInvoiceData" 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 ORGNAME, C_BPARTNER_ID, BPARTNERNAME, C_ORDER_ID, DOCUMENTNO, DATEORDERED, GRANDTOTAL, ISO_CODE, INVOICERULE, 
carlos@0
    32
      LINE, PRODUCT, PRICE, QTYORDERED, UOMSYMBOL, TAX, TAXBASE, LINENETAMT
carlos@0
    33
      FROM (
carlos@0
    34
      SELECT AD_ORG.NAME AS ORGNAME, C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME AS BPARTNERNAME, C_ORDER.C_ORDER_ID, C_ORDER.DOCUMENTNO,
carlos@0
    35
      C_ORDER.DATEORDERED, C_ORDER.GRANDTOTAL, C_CURRENCY.ISO_CODE, (CASE C_ORDER.INVOICERULE WHEN 'S' THEN COALESCE(AD_REF_LIST_TRL.NAME, AD_REF_LIST.NAME)||' ('||C_INVOICESCHEDULE.NAME||')' ELSE COALESCE(AD_REF_LIST_TRL.NAME, AD_REF_LIST.NAME) END) AS INVOICERULE,
carlos@0
    36
      C_ORDERLINE.LINE AS LINE, COALESCE(M_PRODUCT.NAME, M_PRODUCT.DESCRIPTION) AS PRODUCT, C_ORDERLINE.PRICEACTUAL AS PRICE, 
carlos@0
    37
      C_ORDERLINE.QTYORDERED, C_UOM.UOMSYMBOL, NULL AS TAX, NULL AS TAXBASE, C_ORDERLINE.LINENETAMT
carlos@0
    38
      FROM C_BPARTNER left join C_INVOICESCHEDULE on C_BPARTNER.C_INVOICESCHEDULE_ID = C_INVOICESCHEDULE.C_INVOICESCHEDULE_ID,
carlos@0
    39
           AD_REF_LIST left join AD_REF_LIST_TRL  on AD_REF_LIST.AD_REF_LIST_ID = AD_REF_LIST_TRL.AD_REF_LIST_ID  
carlos@0
    40
                                                     and AD_REF_LIST_TRL.AD_LANGUAGE = ?,
carlos@0
    41
           C_ORDERLINE left join M_PRODUCT on C_ORDERLINE.M_PRODUCT_ID=M_PRODUCT.M_PRODUCT_ID,
carlos@0
    42
           C_ORDER, AD_ORG, C_UOM, C_CURRENCY
carlos@0
    43
      WHERE C_ORDER.C_ORDER_ID=C_ORDERLINE.C_ORDER_ID
carlos@0
    44
      AND C_ORDER.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
carlos@0
    45
      AND C_ORDER.INVOICERULE = AD_REF_LIST.VALUE
carlos@0
    46
      AND C_ORDERLINE.C_UOM_ID = C_UOM.C_UOM_ID
carlos@0
    47
      AND C_ORDER.AD_ORG_ID = AD_ORG.AD_ORG_ID
carlos@0
    48
      AND C_ORDER.C_CURRENCY_ID = C_CURRENCY.C_CURRENCY_ID
carlos@0
    49
      AND AD_REF_LIST.AD_REFERENCE_ID = 150
carlos@0
    50
      AND C_ORDER.PROCESSED = 'Y'
carlos@0
    51
      AND C_ORDER.ISSOTRX = 'Y'
carlos@0
    52
      AND C_ORDERLINE.QTYORDERED<>C_ORDERLINE.QTYINVOICED
carlos@0
    53
      AND C_ORDER.AD_Client_ID IN ('1')
carlos@0
    54
      AND C_ORDER.AD_ORG_ID IN ('1')
carlos@0
    55
      AND 1=1
carlos@0
    56
      UNION ALL
carlos@0
    57
      SELECT AD_ORG.NAME AS ORGNAME, C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME AS BPARTNERNAME, C.C_ORDER_ID, C.DOCUMENTNO,
carlos@0
    58
      C.DATEORDERED, C.GRANDTOTAL, C_CURRENCY.ISO_CODE AS ISO_CODE, (CASE C.INVOICERULE WHEN 'S' THEN COALESCE(AD_REF_LIST_TRL.NAME, AD_REF_LIST.NAME)||' ('||C_INVOICESCHEDULE.NAME||')' ELSE COALESCE(AD_REF_LIST_TRL.NAME, AD_REF_LIST.NAME) END) AS INVOICERULE,
carlos@0
    59
      NULL AS LINE , C_TAX.NAME AS PRODUCT, NULL AS PRICE, 
carlos@0
    60
      NULL AS QTYORDERED, NULL AS UOMSYMBOL, C_TAX.RATE AS TAX, C_ORDERTAX.TAXBASEAMT AS TAXBASE, C_ORDERTAX.TAXAMT AS LINENETAMT
carlos@0
    61
      FROM C_BPARTNER left join C_INVOICESCHEDULE on C_BPARTNER.C_INVOICESCHEDULE_ID = C_INVOICESCHEDULE.C_INVOICESCHEDULE_ID,
carlos@0
    62
           AD_REF_LIST left join AD_REF_LIST_TRL on AD_REF_LIST.AD_REF_LIST_ID = AD_REF_LIST_TRL.AD_REF_LIST_ID 
carlos@0
    63
                                                 AND AD_REF_LIST_TRL.AD_LANGUAGE = ? ,
carlos@0
    64
      C_ORDER C ,C_ORDERTAX, AD_ORG,  C_TAX, C_CURRENCY      
carlos@0
    65
      WHERE C.C_ORDER_ID=C_ORDERTAX.C_ORDER_ID
carlos@0
    66
      AND C.C_BPARTNER_ID=C_BPARTNER.C_BPARTNER_ID
carlos@0
    67
      AND C.C_CURRENCY_ID = C_CURRENCY.C_CURRENCY_ID
carlos@0
    68
      AND C.INVOICERULE = AD_REF_LIST.VALUE
carlos@0
    69
      AND AD_REF_LIST.AD_REFERENCE_ID = 150
carlos@0
    70
      AND C_ORDERTAX.C_TAX_ID = C_TAX.C_TAX_ID
carlos@0
    71
      AND C.AD_ORG_ID = AD_ORG.AD_ORG_ID
carlos@0
    72
      AND C.PROCESSED = 'Y'
carlos@0
    73
      AND C.ISSOTRX = 'Y'
carlos@0
    74
      AND EXISTS (SELECT 1 FROM C_ORDER C2, C_ORDERLINE CL
carlos@0
    75
                 WHERE C2.c_order_id = C.c_order_id
carlos@0
    76
                 and c2.c_order_id=cl.c_order_id
carlos@0
    77
                 and cl.QTYORDERED<>cl.QTYINVOICED)
carlos@0
    78
      AND C.AD_Client_ID IN ('2')
carlos@0
    79
      AND C.AD_ORG_ID IN ('2')
carlos@0
    80
      AND 2=2
carlos@0
    81
      ) AAA
carlos@0
    82
      ORDER BY ORGNAME, BPARTNERNAME, DATEORDERED DESC, DOCUMENTNO, LINE
carlos@0
    83
      ]]></Sql>
carlos@0
    84
    <Parameter name="adLanguage"/>
carlos@0
    85
    <Parameter name="adUserClient" type="replace" optional="true" after="C_ORDER.AD_Client_ID IN (" text="'1'"/>
carlos@0
    86
    <Parameter name="adUserOrg" type="replace" optional="true" after="C_ORDER.AD_ORG_ID IN (" text="'1'"/>
carlos@0
    87
    <Parameter name="cBpartnerId" optional="true" after="1=1">AND C_ORDER.C_BPARTNER_ID = ?</Parameter>
carlos@0
    88
    <Parameter name="cOrgId" optional="true" after="1=1">AND C_ORDER.AD_ORG_ID = ?</Parameter>
carlos@0
    89
    <Parameter name="invoiceRule" optional="true" after="1=1">AND C_ORDER.INVOICERULE = ?</Parameter>
carlos@0
    90
    <Parameter name="dateFrom" optional="true" after="1=1"><![CDATA[ AND C_ORDER.DATEORDERED >= to_date(?) ]]></Parameter>
carlos@0
    91
    <Parameter name="dateTo" optional="true" after="1=1"><![CDATA[ AND C_ORDER.DATEORDERED < to_date(?) ]]></Parameter>
carlos@0
    92
    <Parameter name="adLanguage"/>
carlos@0
    93
    <Parameter name="adUserClient" type="replace" optional="true" after="C.AD_Client_ID IN (" text="'2'"/>
carlos@0
    94
    <Parameter name="adUserOrg" type="replace" optional="true" after="C.AD_ORG_ID IN (" text="'2'"/>
carlos@0
    95
    <Parameter name="cBpartnerId" optional="true" after="2=2">AND C.C_BPARTNER_ID = ?</Parameter>
carlos@0
    96
    <Parameter name="cOrgId" optional="true" after="2=2">AND C.AD_ORG_ID = ?</Parameter>
carlos@0
    97
    <Parameter name="invoiceRule" optional="true" after="2=2">AND C.INVOICERULE = ?</Parameter>
carlos@0
    98
    <Parameter name="dateFrom" optional="true" after="2=2"><![CDATA[ AND C.DATEORDERED >= to_date(?) ]]></Parameter>
carlos@0
    99
    <Parameter name="dateTo" optional="true" after="2=2"><![CDATA[ AND C.DATEORDERED < to_date(?) ]]></Parameter>
carlos@0
   100
  </SqlMethod>
carlos@0
   101
  <SqlMethod name="set" type="constant" return="multiple">
carlos@0
   102
      <SqlMethodComment></SqlMethodComment>
carlos@0
   103
      <Sql></Sql>
carlos@0
   104
  </SqlMethod>
carlos@0
   105
  <SqlMethod name="bPartnerDescription" type="preparedStatement" return="String" default="">
carlos@0
   106
    <SqlMethodComment></SqlMethodComment>
carlos@0
   107
    <Sql>
carlos@0
   108
    SELECT max(NAME) as name FROM C_BPARTNER 
carlos@0
   109
    WHERE C_BPARTNER_ID = ?
carlos@0
   110
    </Sql>
carlos@0
   111
    <Parameter name="cBpartnerId"/>
carlos@0
   112
  </SqlMethod>
carlos@0
   113
</SqlClass>