src/org/openbravo/erpCommon/ad_reports/ReportOrderNotInvoice_data.xsql
changeset 0 0247c26f10c6
child 423 ecf368072c48
equal deleted inserted replaced
-1:000000000000 0:0247c26f10c6
       
     1 <?xml version="1.0" encoding="UTF-8" ?>
       
     2 <!--
       
     3  *************************************************************************
       
     4  * The contents of this file are subject to the Openbravo  Public  License
       
     5  * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
       
     6  * Version 1.1  with a permitted attribution clause; you may not  use this
       
     7  * file except in compliance with the License. You  may  obtain  a copy of
       
     8  * the License at http://www.openbravo.com/legal/license.html 
       
     9  * Software distributed under the License  is  distributed  on  an "AS IS"
       
    10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
       
    11  * License for the specific  language  governing  rights  and  limitations
       
    12  * under the License. 
       
    13  * The Original Code is Openbravo ERP. 
       
    14  * The Initial Developer of the Original Code is Openbravo SL 
       
    15  * All portions are Copyright (C) 2001-2006 Openbravo SL 
       
    16  * All Rights Reserved. 
       
    17  * Contributor(s):  ______________________________________.
       
    18  ************************************************************************
       
    19 -->
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 <SqlClass name="ReportOrderNotInvoiceData" package="org.openbravo.erpCommon.ad_reports">
       
    26   <SqlClassComment></SqlClassComment>
       
    27   <SqlMethod name="select" type="preparedStatement" return="multiple">
       
    28     <SqlMethodComment></SqlMethodComment>
       
    29     <Sql>
       
    30     <![CDATA[
       
    31       SELECT ORGNAME, C_BPARTNER_ID, BPARTNERNAME, C_ORDER_ID, DOCUMENTNO, DATEORDERED, GRANDTOTAL, ISO_CODE, INVOICERULE, 
       
    32       LINE, PRODUCT, PRICE, QTYORDERED, UOMSYMBOL, TAX, TAXBASE, LINENETAMT
       
    33       FROM (
       
    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,
       
    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,
       
    36       C_ORDERLINE.LINE AS LINE, COALESCE(M_PRODUCT.NAME, M_PRODUCT.DESCRIPTION) AS PRODUCT, C_ORDERLINE.PRICEACTUAL AS PRICE, 
       
    37       C_ORDERLINE.QTYORDERED, C_UOM.UOMSYMBOL, NULL AS TAX, NULL AS TAXBASE, C_ORDERLINE.LINENETAMT
       
    38       FROM C_BPARTNER left join C_INVOICESCHEDULE on C_BPARTNER.C_INVOICESCHEDULE_ID = C_INVOICESCHEDULE.C_INVOICESCHEDULE_ID,
       
    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  
       
    40                                                      and AD_REF_LIST_TRL.AD_LANGUAGE = ?,
       
    41            C_ORDERLINE left join M_PRODUCT on C_ORDERLINE.M_PRODUCT_ID=M_PRODUCT.M_PRODUCT_ID,
       
    42            C_ORDER, AD_ORG, C_UOM, C_CURRENCY
       
    43       WHERE C_ORDER.C_ORDER_ID=C_ORDERLINE.C_ORDER_ID
       
    44       AND C_ORDER.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
       
    45       AND C_ORDER.INVOICERULE = AD_REF_LIST.VALUE
       
    46       AND C_ORDERLINE.C_UOM_ID = C_UOM.C_UOM_ID
       
    47       AND C_ORDER.AD_ORG_ID = AD_ORG.AD_ORG_ID
       
    48       AND C_ORDER.C_CURRENCY_ID = C_CURRENCY.C_CURRENCY_ID
       
    49       AND AD_REF_LIST.AD_REFERENCE_ID = 150
       
    50       AND C_ORDER.PROCESSED = 'Y'
       
    51       AND C_ORDER.ISSOTRX = 'Y'
       
    52       AND C_ORDERLINE.QTYORDERED<>C_ORDERLINE.QTYINVOICED
       
    53       AND C_ORDER.AD_Client_ID IN ('1')
       
    54       AND C_ORDER.AD_ORG_ID IN ('1')
       
    55       AND 1=1
       
    56       UNION ALL
       
    57       SELECT AD_ORG.NAME AS ORGNAME, C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME AS BPARTNERNAME, C.C_ORDER_ID, C.DOCUMENTNO,
       
    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,
       
    59       NULL AS LINE , C_TAX.NAME AS PRODUCT, NULL AS PRICE, 
       
    60       NULL AS QTYORDERED, NULL AS UOMSYMBOL, C_TAX.RATE AS TAX, C_ORDERTAX.TAXBASEAMT AS TAXBASE, C_ORDERTAX.TAXAMT AS LINENETAMT
       
    61       FROM C_BPARTNER left join C_INVOICESCHEDULE on C_BPARTNER.C_INVOICESCHEDULE_ID = C_INVOICESCHEDULE.C_INVOICESCHEDULE_ID,
       
    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 
       
    63                                                  AND AD_REF_LIST_TRL.AD_LANGUAGE = ? ,
       
    64       C_ORDER C ,C_ORDERTAX, AD_ORG,  C_TAX, C_CURRENCY      
       
    65       WHERE C.C_ORDER_ID=C_ORDERTAX.C_ORDER_ID
       
    66       AND C.C_BPARTNER_ID=C_BPARTNER.C_BPARTNER_ID
       
    67       AND C.C_CURRENCY_ID = C_CURRENCY.C_CURRENCY_ID
       
    68       AND C.INVOICERULE = AD_REF_LIST.VALUE
       
    69       AND AD_REF_LIST.AD_REFERENCE_ID = 150
       
    70       AND C_ORDERTAX.C_TAX_ID = C_TAX.C_TAX_ID
       
    71       AND C.AD_ORG_ID = AD_ORG.AD_ORG_ID
       
    72       AND C.PROCESSED = 'Y'
       
    73       AND C.ISSOTRX = 'Y'
       
    74       AND EXISTS (SELECT 1 FROM C_ORDER C2, C_ORDERLINE CL
       
    75                  WHERE C2.c_order_id = C.c_order_id
       
    76                  and c2.c_order_id=cl.c_order_id
       
    77                  and cl.QTYORDERED<>cl.QTYINVOICED)
       
    78       AND C.AD_Client_ID IN ('2')
       
    79       AND C.AD_ORG_ID IN ('2')
       
    80       AND 2=2
       
    81       ) AAA
       
    82       ORDER BY ORGNAME, BPARTNERNAME, DATEORDERED DESC, DOCUMENTNO, LINE
       
    83       ]]></Sql>
       
    84     <Parameter name="adLanguage"/>
       
    85     <Parameter name="adUserClient" type="replace" optional="true" after="C_ORDER.AD_Client_ID IN (" text="'1'"/>
       
    86     <Parameter name="adUserOrg" type="replace" optional="true" after="C_ORDER.AD_ORG_ID IN (" text="'1'"/>
       
    87     <Parameter name="cBpartnerId" optional="true" after="1=1">AND C_ORDER.C_BPARTNER_ID = ?</Parameter>
       
    88     <Parameter name="cOrgId" optional="true" after="1=1">AND C_ORDER.AD_ORG_ID = ?</Parameter>
       
    89     <Parameter name="invoiceRule" optional="true" after="1=1">AND C_ORDER.INVOICERULE = ?</Parameter>
       
    90     <Parameter name="dateFrom" optional="true" after="1=1"><![CDATA[ AND C_ORDER.DATEORDERED >= to_date(?) ]]></Parameter>
       
    91     <Parameter name="dateTo" optional="true" after="1=1"><![CDATA[ AND C_ORDER.DATEORDERED < to_date(?) ]]></Parameter>
       
    92     <Parameter name="adLanguage"/>
       
    93     <Parameter name="adUserClient" type="replace" optional="true" after="C.AD_Client_ID IN (" text="'2'"/>
       
    94     <Parameter name="adUserOrg" type="replace" optional="true" after="C.AD_ORG_ID IN (" text="'2'"/>
       
    95     <Parameter name="cBpartnerId" optional="true" after="2=2">AND C.C_BPARTNER_ID = ?</Parameter>
       
    96     <Parameter name="cOrgId" optional="true" after="2=2">AND C.AD_ORG_ID = ?</Parameter>
       
    97     <Parameter name="invoiceRule" optional="true" after="2=2">AND C.INVOICERULE = ?</Parameter>
       
    98     <Parameter name="dateFrom" optional="true" after="2=2"><![CDATA[ AND C.DATEORDERED >= to_date(?) ]]></Parameter>
       
    99     <Parameter name="dateTo" optional="true" after="2=2"><![CDATA[ AND C.DATEORDERED < to_date(?) ]]></Parameter>
       
   100   </SqlMethod>
       
   101   <SqlMethod name="set" type="constant" return="multiple">
       
   102       <SqlMethodComment></SqlMethodComment>
       
   103       <Sql></Sql>
       
   104   </SqlMethod>
       
   105   <SqlMethod name="bPartnerDescription" type="preparedStatement" return="String" default="">
       
   106     <SqlMethodComment></SqlMethodComment>
       
   107     <Sql>
       
   108     SELECT max(NAME) as name FROM C_BPARTNER 
       
   109     WHERE C_BPARTNER_ID = ?
       
   110     </Sql>
       
   111     <Parameter name="cBpartnerId"/>
       
   112   </SqlMethod>
       
   113 </SqlClass>