src/org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscount_data.xsql
author David Baz Fayos <david.baz@openbravo.com>
Tue, 27 May 2008 15:26:10 +0000
changeset 1044 8691bbc94032
parent 752 bc18bf2d37e1
child 1156 6aa22c3eac9a
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="ReportInvoiceDiscountData" 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 C_BPARTNER_ID as ID, NAME, PRODUCTNAME, QTY,UOM, ROUND(DIVIDE(TOTALLINE,QTY),3) AS PRICEACTUAL, TOTALLINE, ROUND(DIVIDE(TOTALLINEDISCOUNT,QTY),3) AS REALPRICE, TOTALLINEDISCOUNT,
carlos@0
    32
        (ROUND(DIVIDE((ROUND(DIVIDE(TOTALLINE,QTY),3)-ROUND(DIVIDE(TOTALLINEDISCOUNT,QTY),3)),ROUND(DIVIDE(TOTALLINE,QTY),3)),2))*100 AS DISCOUNT,
carlos@0
    33
        (CASE (ROUND(DIVIDE((ROUND(DIVIDE(TOTALLINE,QTY),3)-ROUND(DIVIDE(TOTALLINEDISCOUNT,QTY),3)),ROUND(DIVIDE(TOTALLINE,QTY),3)),2))*100 WHEN 0 THEN 'DerechaMedio' ELSE 'BordesRojoClaro' END)  AS CLASS_DESIGN,
carlos@0
    34
        WEIGHT
carlos@0
    35
        FROM (
carlos@0
    36
        SELECT C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME, M_PRODUCT.NAME AS PRODUCTNAME, C_UOM.UOMSYMBOL AS UOM, SUM(C_INVOICELINE.QTYINVOICED) AS QTY, ROUND(SUM(LINENETAMT),2) AS TOTALLINE, 
carlos@0
    37
        ROUND(SUM(LINENETAMT*(1-COALESCE(DISCOUNTPERUNIT,0))),2) AS TOTALLINEDISCOUNT, SUM(C_INVOICELINE.QTYINVOICED)*COALESCE(M_PRODUCT.WEIGHT,0) AS WEIGHT
carlos@0
    38
        FROM C_INVOICELINE left join
carlos@0
    39
          (SELECT C_INVOICE_ID, DISCOUNTLINES/(TOTALLINES+DISCOUNTLINES) AS DISCOUNTPERUNIT 
carlos@0
    40
          FROM (SELECT I.C_INVOICE_ID, I.TOTALLINES, -SUM(LINENETAMT) AS DISCOUNTLINES FROM C_INVOICE I, C_INVOICELINE IL 
carlos@0
    41
          WHERE I.C_INVOICE_ID = IL.C_INVOICE_ID 
carlos@0
    42
          AND IL.C_INVOICE_DISCOUNT_ID IS NOT NULL 
carlos@0
    43
          GROUP BY I.C_INVOICE_ID, I.TOTALLINES) BB) A on C_INVOICELINE.C_INVOICE_ID = A.C_INVOICE_ID
carlos@0
    44
          left join C_INVOICE on C_INVOICELINE.C_INVOICE_ID = C_INVOICE.C_INVOICE_ID,
carlos@0
    45
        M_PRODUCT, C_BPARTNER,  C_UOM
carlos@0
    46
        WHERE  C_INVOICELINE.C_INVOICE_DISCOUNT_ID IS NULL
carlos@0
    47
        AND C_INVOICELINE.M_PRODUCT_ID = M_PRODUCT.M_PRODUCT_ID
carlos@0
    48
        AND M_PRODUCT.C_UOM_ID = C_UOM.C_UOM_ID
carlos@0
    49
        AND C_INVOICE.C_BPARTNER_ID = C_BPARTNER.C_BPARTNER_ID
carlos@0
    50
        AND C_INVOICE.ISSOTRX='Y'
carlos@0
    51
        AND C_INVOICE.AD_CLIENT_ID IN ('1')
carlos@0
    52
        AND C_INVOICE.AD_ORG_ID IN ('1')
carlos@0
    53
        AND PRICEACTUAL<>0
carlos@0
    54
        AND C_INVOICE.DATEINVOICED >= to_date(?)
phillip@752
    55
        AND C_INVOICE.DATEINVOICED <= to_date(?)
carlos@0
    56
        AND 1=1
carlos@0
    57
        GROUP BY C_BPARTNER.C_BPARTNER_ID, C_BPARTNER.NAME, M_PRODUCT.NAME, C_UOM.UOMSYMBOL, M_PRODUCT.WEIGHT) AA
carlos@0
    58
        WHERE QTY<>0
carlos@0
    59
        AND 2=2
carlos@0
    60
        ORDER BY NAME
carlos@0
    61
      ]]></Sql>
carlos@0
    62
    <Parameter name="adUserClient" type="replace" optional="true" after="C_INVOICE.AD_CLIENT_ID IN (" text="'1'"/>
carlos@0
    63
    <Parameter name="adUserOrg" type="replace" optional="true" after="C_INVOICE.AD_ORG_ID IN (" text="'1'"/>
carlos@0
    64
    <Parameter name="datefrom"/>
carlos@0
    65
    <Parameter name="dateto"/>
carlos@0
    66
    <Parameter name="parBPartnerId" optional="true" type="argument" after="AND 1=1"><![CDATA[ AND C_BPARTNER.C_BPARTNER_ID IN]]></Parameter>
carlos@0
    67
    <Parameter name="discount" optional="true" type="none" after="AND 2=2"><![CDATA[ AND (ROUND((ROUND(TOTALLINE/QTY,3)-ROUND(TOTALLINEDISCOUNT/QTY,3))/ROUND(TOTALLINE/QTY,3),2))*100 <>0]]></Parameter>
carlos@0
    68
  </SqlMethod>
carlos@0
    69
  <SqlMethod name="set" type="constant" return="multiple">
carlos@0
    70
      <SqlMethodComment></SqlMethodComment>
carlos@0
    71
      <Sql></Sql>
carlos@0
    72
  </SqlMethod>
carlos@0
    73
   <SqlMethod name="selectBpartner" type="preparedStatement" return="multiple">
carlos@0
    74
    <SqlMethodComment></SqlMethodComment>
carlos@0
    75
    <Sql>
carlos@0
    76
    <![CDATA[
carlos@0
    77
      SELECT C_BPARTNER_ID AS ID, C_BPARTNER.NAME
carlos@0
    78
      FROM C_BPARTNER
carlos@0
    79
      WHERE AD_ORG_ID IN ('1') 
carlos@0
    80
      AND AD_CLIENT_ID IN ('1') 
carlos@0
    81
      AND (1=2 )
carlos@0
    82
     ]]></Sql>
carlos@0
    83
    <Parameter name="adOrgClient" type="replace" optional="true" after="AD_ORG_ID IN (" text="'1'"/>
carlos@0
    84
     <Parameter name="adUserClient" type="replace" optional="true" after="AND AD_CLIENT_ID IN (" text="'1'"/>
carlos@0
    85
     <Parameter name="cBpartnerId" optional="true" type="argument" after="(1=2" text=" OR C_BPARTNER_ID IN"/>
carlos@0
    86
  </SqlMethod>
carlos@0
    87
</SqlClass>