src/org/openbravo/erpCommon/ad_actionButton/CopyFromOrder_data.xsql
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 1173 3b528c8e84a7
child 1674 e6434eaacdad
permissions -rw-r--r--
Merge r2.5x intro trunk
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="CopyFromOrderData" package="org.openbravo.erpCommon.ad_actionButton">
carlos@0
    26
<SqlMethod name="select" type="preparedStatement" return="multiple">
carlos@0
    27
    <SqlMethodComment></SqlMethodComment>
carlos@0
    28
    <Sql>
carlos@0
    29
      <![CDATA[
carlos@0
    30
        SELECT M_PRODUCT_ID, PRODUCTNAME, M_ATTRIBUTESETINSTANCE_ID, DESCRIPTION, CLASS_OFFER,
hennadzi@1173
    31
        OFFER_NAME, PRICESTD, LASTPRICESO, C_TAX_ID, NAMETAX, C_UOM_ID, UOMSYMBOL, '0' AS QTY, '' AS PRICELIMIT, '' AS PRICELIST FROM (
hennadzi@1173
    32
        SELECT CL.M_PRODUCT_ID AS M_PRODUCT_ID, M.NAME AS PRODUCTNAME,
carlos@0
    33
        MA.M_ATTRIBUTESETINSTANCE_ID AS M_ATTRIBUTESETINSTANCE_ID, MA.DESCRIPTION AS DESCRIPTION,
juanpablo@1605
    34
        (CASE coalesce(M_GET_OFFER(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID),'-1') WHEN '-1' THEN '' ELSE '' END) AS CLASS_OFFER,
juanpablo@1605
    35
        (CASE coalesce(M_GET_OFFER(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID),'-1') WHEN '-1' THEN '' ELSE TO_CHAR(
juanpablo@1605
    36
        M_GET_OFFERS_NAME(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID)
carlos@0
    37
        ) END) AS OFFER_NAME,
juanpablo@1605
    38
        (CASE coalesce(M_GET_OFFER(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID),'-1') WHEN '-1' THEN '' ELSE M_GET_OFFER(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID) END) AS M_OFFER_ID,
juanpablo@1605
    39
        BOM_PRICESTD(CL.M_PRODUCT_ID, GET_PRICELIST_VERSION(?, TO_DATE(?))) AS PRICESTD,
juanpablo@1605
    40
        (CASE coalesce(M_GET_OFFER(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID),'-1') WHEN '-1' 
carlos@0
    41
                                                            THEN (SELECT MAX(PRICEACTUAL) 
carlos@0
    42
                                                                    FROM C_ORDER, C_ORDERLINE
carlos@0
    43
                                                                    WHERE C_ORDER.C_ORDER_ID = C_ORDERLINE.C_ORDER_ID
carlos@0
    44
                                                                    AND C_ORDER.DATEORDERED = (SELECT MAX(C_ORDER.DATEORDERED) FROM C_ORDER, C_ORDERLINE
carlos@0
    45
                                                                    WHERE C_ORDER.C_ORDER_ID = C_ORDERLINE.C_ORDER_ID
juanpablo@1605
    46
                                                                    AND C_ORDER.C_BPARTNER_ID = ?
carlos@0
    47
                                                                    AND C_ORDERLINE.M_PRODUCT_ID = M.M_PRODUCT_ID
carlos@0
    48
                                                                    AND C_ORDER.DOCSTATUS = 'CO')
juanpablo@1605
    49
                                                                    AND C_ORDER.C_BPARTNER_ID = ?
carlos@0
    50
                                                                    AND C_ORDERLINE.M_PRODUCT_ID = M.M_PRODUCT_ID
carlos@0
    51
                                                                    AND C_ORDER.DOCSTATUS = 'CO') 
juanpablo@1605
    52
                                                               ELSE M_GET_OFFERS_PRICE(TO_DATE(NOW()), ?, CL.M_PRODUCT_ID,BOM_PRICESTD(CL.M_PRODUCT_ID, GET_PRICELIST_VERSION(?, TO_DATE(?))), 1 /*CL.QTYORDERED what should be here*/, C.M_PRICELIST_ID) 
carlos@0
    53
                                                                END) AS LASTPRICESO,
carlos@0
    54
        C_TAX.C_TAX_ID, C_TAX.NAME AS NAMETAX, C_UOM.C_UOM_ID, C_UOM.UOMSYMBOL
carlos@0
    55
        FROM C_ORDER C, C_ORDERLINE CL LEFT JOIN (SELECT M_ATTRIBUTESETINSTANCE_ID , DESCRIPTION FROM M_ATTRIBUTESETINSTANCE) MA ON (CL.M_ATTRIBUTESETINSTANCE_ID = MA.M_ATTRIBUTESETINSTANCE_ID), M_PRODUCT M, C_UOM, C_TAX
carlos@0
    56
        WHERE C.C_ORDER_ID = CL.C_ORDER_ID
carlos@0
    57
        AND CL.M_PRODUCT_ID = M.M_PRODUCT_ID
carlos@0
    58
        AND CL.C_TAX_ID = C_TAX.C_TAX_ID
carlos@0
    59
        AND M.C_UOM_ID = C_UOM.C_UOM_ID
juanpablo@1605
    60
        AND C.C_BPARTNER_ID = ?
carlos@0
    61
        AND C.DOCSTATUS = 'CO'
carlos@0
    62
        AND M.ISACTIVE = 'Y'
carlos@0
    63
        AND C.ISSOTRX = ?
carlos@0
    64
        AND C.DATEORDERED >= NOW()-TO_NUMBER(?)
carlos@0
    65
        AND C.DATEORDERED <NOW()+1
carlos@0
    66
        GROUP BY CL.M_PRODUCT_ID, M.NAME, MA.M_ATTRIBUTESETINSTANCE_ID, 
carlos@0
    67
        MA.DESCRIPTION,M.M_PRODUCT_ID, C_TAX.C_TAX_ID, C_TAX.NAME, C_UOM.C_UOM_ID, C_UOM.UOMSYMBOL, C.M_PRICELIST_ID
carlos@0
    68
        )A
carlos@0
    69
       ORDER BY M_PRODUCT_ID
carlos@0
    70
      ]]>
carlos@0
    71
    </Sql>
carlos@0
    72
    <Field name="rownum" value="count"/>
carlos@0
    73
    <Parameter name="cBpartnerId"/>
carlos@0
    74
    <Parameter name="cBpartnerId"/>
carlos@0
    75
    <Parameter name="cBpartnerId"/>
carlos@0
    76
    <Parameter name="cBpartnerId"/>
carlos@0
    77
    <Parameter name="cBpartnerId"/>
carlos@0
    78
    <Parameter name="mPricelistId"/>
carlos@0
    79
    <Parameter name="dateOrdered"/>
carlos@0
    80
    <Parameter name="cBpartnerId"/>
carlos@0
    81
    <Parameter name="cBpartnerId"/>
carlos@0
    82
    <Parameter name="cBpartnerId"/>
carlos@0
    83
    <Parameter name="cBpartnerId"/>
carlos@0
    84
    <Parameter name="mPricelistId"/>
carlos@0
    85
    <Parameter name="dateOrdered"/>
carlos@0
    86
    <Parameter name="cBpartnerId"/>
carlos@0
    87
    <Parameter name="issotrx"/>
carlos@0
    88
    <Parameter name="lastDays"/>
carlos@0
    89
  </SqlMethod>
carlos@0
    90
  <SqlMethod name="set" type="constant" return="multiple">
carlos@0
    91
      <SqlMethodComment></SqlMethodComment>
carlos@0
    92
      <Sql></Sql>
carlos@0
    93
  </SqlMethod>
carlos@0
    94
  <SqlMethod name="selectPrices" type="preparedStatement" return="multiple">
carlos@0
    95
    <SqlMethodComment></SqlMethodComment>
carlos@0
    96
    <Sql>
carlos@0
    97
      <![CDATA[
carlos@0
    98
        SELECT BOM_PRICELIST(P.M_PRODUCT_ID,PV.M_PRICELIST_VERSION_ID) AS PRICELIST,
carlos@0
    99
        BOM_PRICELIMIT(P.M_PRODUCT_ID,PV.M_PRICELIST_VERSION_ID) AS PRICELIMIT
carlos@0
   100
        FROM M_PRODUCT P, M_PRODUCTPRICE PP, M_PRICELIST PL, M_PRICELIST_VERSION PV 
carlos@0
   101
        WHERE P.M_PRODUCT_ID=PP.M_PRODUCT_ID
carlos@0
   102
        AND PP.M_PRICELIST_VERSION_ID=PV.M_PRICELIST_VERSION_ID
carlos@0
   103
        AND PV.M_PRICELIST_ID=PL.M_PRICELIST_ID
carlos@0
   104
        AND PV.ISACTIVE='Y'
carlos@0
   105
        AND PV.VALIDFROM <= TO_DATE(?)
juanpablo@1605
   106
        AND P.M_PRODUCT_ID = ?
juanpablo@1605
   107
        AND PL.M_PRICELIST_ID = ?
carlos@0
   108
        ORDER BY PV.VALIDFROM DESC
carlos@0
   109
      ]]>
carlos@0
   110
    </Sql>
carlos@0
   111
    <Parameter name="dateordered"/>
carlos@0
   112
    <Parameter name="MProductID"/>
carlos@0
   113
    <Parameter name="MPriceListID"/>
carlos@0
   114
  </SqlMethod>
carlos@0
   115
  <SqlMethod name="insertCOrderline" type="preparedStatement" connection="true" return="rowCount">
carlos@0
   116
    <SqlMethodComment></SqlMethodComment>
carlos@0
   117
    <Sql>
carlos@0
   118
      <![CDATA[
carlos@0
   119
        INSERT INTO C_ORDERLINE (C_ORDERLINE_ID, AD_CLIENT_ID, AD_ORG_ID, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
carlos@0
   120
        C_ORDER_ID, LINE, C_BPARTNER_ID, C_BPARTNER_LOCATION_ID, DATEORDERED, DATEPROMISED, M_PRODUCT_ID, M_WAREHOUSE_ID, C_UOM_ID,
carlos@0
   121
        QTYORDERED, C_CURRENCY_ID, PRICELIST, PRICEACTUAL, PRICELIMIT, C_TAX_ID, M_ATTRIBUTESETINSTANCE_ID) 
juanpablo@1605
   122
        VALUES (?,?,?,NOW(),?,NOW(),?,
juanpablo@1605
   123
                ?,(SELECT (coalesce(Max(Line),0))+10 FROM C_OrderLine WHERE C_Order_id = ?),?,?,TO_DATE(?),TO_DATE(?),?,?,?,
juanpablo@1605
   124
                ?,?,?,?,?,?, ?)
carlos@0
   125
      ]]>
carlos@0
   126
    </Sql>
carlos@0
   127
    <Parameter name="cOrderlineId"/>
carlos@0
   128
    <Parameter name="adClientId"/>
carlos@0
   129
    <Parameter name="adOrgId"/>
carlos@0
   130
    <Parameter name="user"/>
carlos@0
   131
    <Parameter name="user"/>
carlos@0
   132
    <Parameter name="cOrderId"/>
carlos@0
   133
    <Parameter name="cOrderId"/>
carlos@0
   134
    <Parameter name="cBpartnerId"/>
carlos@0
   135
    <Parameter name="cBpartnerLocationId"/>
carlos@0
   136
    <Parameter name="dateordered"/>
carlos@0
   137
    <Parameter name="datepromised"/>
carlos@0
   138
    <Parameter name="mProductId"/>
carlos@0
   139
    <Parameter name="mWarehouseId"/>
carlos@0
   140
    <Parameter name="cUomId"/>
carlos@0
   141
    <Parameter name="qtyordered"/>
carlos@0
   142
    <Parameter name="cCurrencyId"/>
carlos@0
   143
    <Parameter name="pricelist"/>
carlos@0
   144
    <Parameter name="priceactual"/>
carlos@0
   145
    <Parameter name="pricelimit"/>
carlos@0
   146
    <Parameter name="cTaxId"/>
carlos@0
   147
    <Parameter name="mAttributesetinstanceId"/>
carlos@0
   148
  </SqlMethod>
carlos@0
   149
</SqlClass>