src/org/openbravo/erpCommon/ad_reports/ReportOrderNotInvoice_data.xsql
author Priya Muthukumar <priya.muthukumar@openbravo.com>
Thu, 09 Dec 2010 09:43:14 +0100
changeset 9072 79e55dfc8af0
parent 6701 690d2af86089
child 12996 bc639e86fe20
permissions -rw-r--r--
Change Openbravo Public License Version 1.0 to Openbravo Public License Version 1.1
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
priya@9072
     5
 * Version  1.1  (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. 
ggi@6701
    14
 * The Initial Developer of the Original Code is Openbravo SLU 
ggi@6701
    15
 * All portions are Copyright (C) 2001-2008 Openbravo SLU 
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[
rafael@1868
    31
      SELECT ORGNAME, C_BPARTNER_ID, BPARTNERNAME, C_ORDER_ID, DOCUMENTNO, DATEORDERED, GRANDTOTAL, CONVGRANDTOTAL, INVOICERULE,       
rafael@1868
    32
	  LINE, PRODUCT, PRICE, CONVPRICE, QTYORDERED, UOMSYMBOL, TAX, TAXBASE, CONVTAXBASE, LINENETAMT, CONVLINENETAMT,
rafael@1868
    33
	  ORDERCURRENCYSYM, TRANSCURRENCYIDORDER, TRANSDATEORDER, TRANSCLIENTIDORDER, TRANSORGIDORDER,
rafael@1868
    34
	  LINECURRENCYSYM, TRANSCURRENCYIDLINE, TRANSDATELINE, TRANSCLIENTIDLINE, TRANSORGIDLINE,
rafael@1868
    35
	  C_CURRENCY_SYMBOL(?, 0, 'Y') AS CONVSYM, C_CURRENCY_ISOSYM(?) AS CONVISOSYM
rafael@1868
    36
	  FROM (
rafael@1868
    37
	  SELECT AD_ORG.NAME AS ORGNAME, C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME AS BPARTNERNAME, C_ORDER.C_ORDER_ID, C_ORDER.DOCUMENTNO, C_ORDER.DATEORDERED, C_ORDER.GRANDTOTAL,
rafael@1868
    38
	  C_CURRENCY_CONVERT(C_ORDER.GRANDTOTAL, C_ORDER.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C_ORDER.DATEORDERED, NOW())), NULL, C_ORDER.AD_CLIENT_ID, C_ORDER.AD_ORG_ID) AS CONVGRANDTOTAL, 
rafael@1868
    39
	  (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,      
rafael@1868
    40
	  C_ORDERLINE.LINE AS LINE, COALESCE(M_PRODUCT.NAME, M_PRODUCT.DESCRIPTION) AS PRODUCT, C_ORDERLINE.PRICEACTUAL AS PRICE,
rafael@1868
    41
	  C_CURRENCY_CONVERT(C_ORDERLINE.PRICEACTUAL, COALESCE(C_ORDERLINE.C_CURRENCY_ID, C_ORDER.C_CURRENCY_ID), ?, TO_DATE(COALESCE(C_ORDERLINE.DATEORDERED, C_ORDER.DATEORDERED, NOW())), NULL, C_ORDERLINE.AD_CLIENT_ID, C_ORDERLINE.AD_ORG_ID) AS CONVPRICE,        
rafael@1868
    42
	  C_ORDERLINE.QTYORDERED, C_UOM.UOMSYMBOL, NULL AS TAX, NULL AS TAXBASE, NULL AS CONVTAXBASE, C_ORDERLINE.LINENETAMT,
rafael@1868
    43
	  C_CURRENCY_CONVERT(C_ORDERLINE.LINENETAMT, COALESCE(C_ORDERLINE.C_CURRENCY_ID, C_ORDER.C_CURRENCY_ID), ?, TO_DATE(COALESCE(C_ORDERLINE.DATEORDERED, C_ORDER.DATEORDERED, NOW())), NULL, C_ORDERLINE.AD_CLIENT_ID, C_ORDERLINE.AD_ORG_ID) AS CONVLINENETAMT,        
rafael@1868
    44
	  C_CURRENCY_SYMBOL(C_ORDER.C_CURRENCY_ID, 0, 'Y') AS ORDERCURRENCYSYM,
rafael@1868
    45
	  C_ORDER.C_CURRENCY_ID AS TRANSCURRENCYIDORDER,
rafael@1868
    46
	  C_ORDER.DATEORDERED AS TRANSDATEORDER,
rafael@1868
    47
	  C_ORDER.AD_CLIENT_ID AS TRANSCLIENTIDORDER,
rafael@1868
    48
	  C_ORDER.AD_ORG_ID AS TRANSORGIDORDER,
rafael@1868
    49
	  C_CURRENCY_SYMBOL(COALESCE(C_ORDERLINE.C_CURRENCY_ID, C_ORDER.C_CURRENCY_ID), 0, 'Y') AS LINECURRENCYSYM,
rafael@1868
    50
	  COALESCE(C_ORDERLINE.C_CURRENCY_ID, C_ORDER.C_CURRENCY_ID) AS TRANSCURRENCYIDLINE,
rafael@1868
    51
	  TO_DATE(COALESCE(C_ORDERLINE.DATEORDERED, C_ORDER.DATEORDERED, NOW())) AS TRANSDATELINE,
rafael@1868
    52
	  C_ORDERLINE.AD_CLIENT_ID AS TRANSCLIENTIDLINE,
rafael@1868
    53
	  C_ORDERLINE.AD_ORG_ID AS TRANSORGIDLINE 
carlos@0
    54
      FROM C_BPARTNER left join C_INVOICESCHEDULE on C_BPARTNER.C_INVOICESCHEDULE_ID = C_INVOICESCHEDULE.C_INVOICESCHEDULE_ID,
carlos@0
    55
           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
    56
                                                     and AD_REF_LIST_TRL.AD_LANGUAGE = ?,
carlos@0
    57
           C_ORDERLINE left join M_PRODUCT on C_ORDERLINE.M_PRODUCT_ID=M_PRODUCT.M_PRODUCT_ID,
carlos@0
    58
           C_ORDER, AD_ORG, C_UOM, C_CURRENCY
carlos@0
    59
      WHERE C_ORDER.C_ORDER_ID=C_ORDERLINE.C_ORDER_ID
carlos@0
    60
      AND C_ORDER.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
carlos@0
    61
      AND C_ORDER.INVOICERULE = AD_REF_LIST.VALUE
harikrishnan@5068
    62
      AND C_ORDER.INVOICERULE <> 'N'
carlos@0
    63
      AND C_ORDERLINE.C_UOM_ID = C_UOM.C_UOM_ID
carlos@0
    64
      AND C_ORDER.AD_ORG_ID = AD_ORG.AD_ORG_ID
carlos@0
    65
      AND C_ORDER.C_CURRENCY_ID = C_CURRENCY.C_CURRENCY_ID
juanpablo@1605
    66
      AND AD_REF_LIST.AD_REFERENCE_ID = '150'
carlos@0
    67
      AND C_ORDER.PROCESSED = 'Y'
carlos@0
    68
      AND C_ORDER.ISSOTRX = 'Y'
rafael@2585
    69
      AND C_ORDERLINE.QTYORDERED<>C_ORDERLINE.QTYINVOICED 
carlos@0
    70
      AND C_ORDER.AD_Client_ID IN ('1')
carlos@0
    71
      AND C_ORDER.AD_ORG_ID IN ('1')
carlos@0
    72
      AND 1=1
carlos@0
    73
      UNION ALL
rafael@1868
    74
      SELECT AD_ORG.NAME AS ORGNAME, C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME AS BPARTNERNAME, C.C_ORDER_ID, C.DOCUMENTNO, C.DATEORDERED, C.GRANDTOTAL,
rafael@1868
    75
	  C_CURRENCY_CONVERT(C.GRANDTOTAL, C.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C.DATEORDERED, NOW())), NULL, C.AD_CLIENT_ID, C.AD_ORG_ID) AS CONVGRANDTOTAL, 
rafael@1868
    76
	  (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,      
rafael@1868
    77
	  NULL AS LINE , C_TAX.NAME AS PRODUCT, NULL AS PRICE, NULL AS CONVPRICE, NULL AS QTYORDERED, NULL AS UOMSYMBOL, 
rafael@1868
    78
	  C_TAX.RATE AS TAX,  C_ORDERTAX.TAXBASEAMT AS TAXBASE,
rafael@1868
    79
	  C_CURRENCY_CONVERT(C_ORDERTAX.TAXBASEAMT, C.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C.DATEORDERED, NOW())), NULL, C_ORDERTAX.AD_CLIENT_ID, C_ORDERTAX.AD_ORG_ID) AS CONVTAXBASE,         
rafael@1868
    80
	  C_ORDERTAX.TAXAMT AS LINENETAMT,
rafael@1868
    81
	  C_CURRENCY_CONVERT(C_ORDERTAX.TAXAMT, C.C_CURRENCY_ID, ?, TO_DATE(COALESCE(C.DATEORDERED, NOW())), NULL, C_ORDERTAX.AD_CLIENT_ID, C_ORDERTAX.AD_ORG_ID) AS CONVLINENETAMT,        
rafael@1868
    82
	  C_CURRENCY_SYMBOL(C.C_CURRENCY_ID, 0, 'Y') AS ORDERCURRENCYSYM,
rafael@1868
    83
	  C.C_CURRENCY_ID AS TRANSCURRENCYIDORDER,
rafael@1868
    84
	  C.DATEORDERED AS TRANSDATEORDER,
rafael@1868
    85
	  C.AD_CLIENT_ID AS TRANSCLIENTIDORDER,
rafael@1868
    86
	  C.AD_ORG_ID AS TRANSORGIDORDER,
rafael@1868
    87
	  C_CURRENCY_SYMBOL(C.C_CURRENCY_ID, 0, 'Y') AS LINECURRENCYSYM,
rafael@1868
    88
	  C.C_CURRENCY_ID AS TRANSCURRENCYIDLINE,
rafael@1868
    89
	  TO_DATE(COALESCE(C.DATEORDERED, NOW())) AS TRANSDATELINE,
rafael@1868
    90
	  C_ORDERTAX.AD_CLIENT_ID AS TRANSCLIENTIDLINE,
rafael@1868
    91
	  C_ORDERTAX.AD_ORG_ID AS TRANSORGIDLINE
carlos@0
    92
      FROM C_BPARTNER left join C_INVOICESCHEDULE on C_BPARTNER.C_INVOICESCHEDULE_ID = C_INVOICESCHEDULE.C_INVOICESCHEDULE_ID,
carlos@0
    93
           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
    94
                                                 AND AD_REF_LIST_TRL.AD_LANGUAGE = ? ,
carlos@0
    95
      C_ORDER C ,C_ORDERTAX, AD_ORG,  C_TAX, C_CURRENCY      
carlos@0
    96
      WHERE C.C_ORDER_ID=C_ORDERTAX.C_ORDER_ID
carlos@0
    97
      AND C.C_BPARTNER_ID=C_BPARTNER.C_BPARTNER_ID
carlos@0
    98
      AND C.C_CURRENCY_ID = C_CURRENCY.C_CURRENCY_ID
carlos@0
    99
      AND C.INVOICERULE = AD_REF_LIST.VALUE
harikrishnan@5068
   100
      AND C.INVOICERULE <> 'N'
juanpablo@1605
   101
      AND AD_REF_LIST.AD_REFERENCE_ID = '150'
carlos@0
   102
      AND C_ORDERTAX.C_TAX_ID = C_TAX.C_TAX_ID
carlos@0
   103
      AND C.AD_ORG_ID = AD_ORG.AD_ORG_ID
carlos@0
   104
      AND C.PROCESSED = 'Y'
carlos@0
   105
      AND C.ISSOTRX = 'Y'
carlos@0
   106
      AND EXISTS (SELECT 1 FROM C_ORDER C2, C_ORDERLINE CL
carlos@0
   107
                 WHERE C2.c_order_id = C.c_order_id
carlos@0
   108
                 and c2.c_order_id=cl.c_order_id
carlos@0
   109
                 and cl.QTYORDERED<>cl.QTYINVOICED)
carlos@0
   110
      AND C.AD_Client_ID IN ('2')
carlos@0
   111
      AND C.AD_ORG_ID IN ('2')
carlos@0
   112
      AND 2=2
carlos@0
   113
      ) AAA
carlos@0
   114
      ORDER BY ORGNAME, BPARTNERNAME, DATEORDERED DESC, DOCUMENTNO, LINE
carlos@0
   115
      ]]></Sql>
rafael@1868
   116
    <Parameter name="cCurrencyConv"/>
rafael@1868
   117
	<Parameter name="cCurrencyConv"/>
rafael@1868
   118
	<Parameter name="cCurrencyConv"/>
rafael@1868
   119
	<Parameter name="cCurrencyConv"/>
rafael@1868
   120
	<Parameter name="cCurrencyConv"/>
carlos@0
   121
    <Parameter name="adLanguage"/>
carlos@0
   122
    <Parameter name="adUserClient" type="replace" optional="true" after="C_ORDER.AD_Client_ID IN (" text="'1'"/>
carlos@0
   123
    <Parameter name="adUserOrg" type="replace" optional="true" after="C_ORDER.AD_ORG_ID IN (" text="'1'"/>
juanpablo@1605
   124
    <Parameter name="cBpartnerId" optional="true" after="1=1">AND C_ORDER.C_BPARTNER_ID = ?</Parameter>
juanpablo@1605
   125
    <Parameter name="cOrgId" optional="true" after="1=1">AND C_ORDER.AD_ORG_ID = ?</Parameter>
carlos@0
   126
    <Parameter name="invoiceRule" optional="true" after="1=1">AND C_ORDER.INVOICERULE = ?</Parameter>
carlos@0
   127
    <Parameter name="dateFrom" optional="true" after="1=1"><![CDATA[ AND C_ORDER.DATEORDERED >= to_date(?) ]]></Parameter>
carlos@0
   128
    <Parameter name="dateTo" optional="true" after="1=1"><![CDATA[ AND C_ORDER.DATEORDERED < to_date(?) ]]></Parameter>
rafael@1868
   129
    <Parameter name="cCurrencyConv"/>
rafael@1868
   130
	<Parameter name="cCurrencyConv"/>
rafael@1868
   131
	<Parameter name="cCurrencyConv"/>
carlos@0
   132
    <Parameter name="adLanguage"/>
carlos@0
   133
    <Parameter name="adUserClient" type="replace" optional="true" after="C.AD_Client_ID IN (" text="'2'"/>
carlos@0
   134
    <Parameter name="adUserOrg" type="replace" optional="true" after="C.AD_ORG_ID IN (" text="'2'"/>
juanpablo@1605
   135
    <Parameter name="cBpartnerId" optional="true" after="2=2">AND C.C_BPARTNER_ID = ?</Parameter>
juanpablo@1605
   136
    <Parameter name="cOrgId" optional="true" after="2=2">AND C.AD_ORG_ID = ?</Parameter>
carlos@0
   137
    <Parameter name="invoiceRule" optional="true" after="2=2">AND C.INVOICERULE = ?</Parameter>
carlos@0
   138
    <Parameter name="dateFrom" optional="true" after="2=2"><![CDATA[ AND C.DATEORDERED >= to_date(?) ]]></Parameter>
carlos@0
   139
    <Parameter name="dateTo" optional="true" after="2=2"><![CDATA[ AND C.DATEORDERED < to_date(?) ]]></Parameter>
carlos@0
   140
  </SqlMethod>
carlos@0
   141
  <SqlMethod name="set" type="constant" return="multiple">
carlos@0
   142
      <SqlMethodComment></SqlMethodComment>
carlos@0
   143
      <Sql></Sql>
carlos@0
   144
  </SqlMethod>
carlos@0
   145
  <SqlMethod name="bPartnerDescription" type="preparedStatement" return="String" default="">
carlos@0
   146
    <SqlMethodComment></SqlMethodComment>
carlos@0
   147
    <Sql>
carlos@0
   148
    SELECT max(NAME) as name FROM C_BPARTNER 
juanpablo@1605
   149
    WHERE C_BPARTNER_ID = ?
carlos@0
   150
    </Sql>
carlos@0
   151
    <Parameter name="cBpartnerId"/>
carlos@0
   152
  </SqlMethod>
carlos@0
   153
</SqlClass>