src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql
author Rafa Roda Palacios <rafael.roda@openbravo.com>
Sun, 17 Jan 2010 15:23:28 +0100
changeset 5919 520829d243f7
parent 5407 7b6d1c51cb38
child 6416 1ef24cfd4caa
permissions -rw-r--r--
Fixes issue 11512 \"Create Lines From\" in Invoice window now rounds correctly when selecting a Shipment.
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 
rafael@5919
    15
 * All portions are Copyright (C) 2001-2010 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="CreateFromInvoiceData" package="org.openbravo.erpCommon.ad_actionButton">
carlos@0
    26
  <SqlMethod name="selectFromPO" type="preparedStatement" return="multiple">
carlos@0
    27
    <SqlMethodComment></SqlMethodComment>
carlos@0
    28
    <Sql>
carlos@0
    29
      <![CDATA[
carlos@0
    30
        SELECT o.C_ORDER_ID as ID, Ad_Column_Identifier(to_char('C_Order'), to_char(o.c_order_id), to_char(?)) AS NAME, o.DocumentNo AS NAMEORDER,
david@3296
    31
        '' AS NAMESHIPMENT,
carlos@0
    32
        l.QtyOrdered-SUM(COALESCE(m.Qty,0)) AS QTY, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,p.NAME AS RELATION_NAME, 
carlos@0
    33
        l.C_OrderLine_ID,l.Line, l.ad_org_id, '' as STDPRECISION, 
carlos@0
    34
        '' as M_InOutLine_ID, '' AS PriceActual, '' AS PriceList, '' AS PriceLimit, '' AS Description, '' as PriceStd,
rafael@5919
    35
        '' AS QUANTITYORDER, '' AS M_Product_UOM_ID, '' AS M_ATTRIBUTESETINSTANCE_ID, '' AS M_Offer_ID, '' AS PricePrecision
carlos@0
    36
        FROM C_ORDERLINE l left join M_MATCHPO m on  l.C_OrderLine_ID=m.C_OrderLine_ID
carlos@0
    37
                                                 AND m.C_InvoiceLine_ID IS NOT NULL, 
carlos@0
    38
        C_ORDER o, C_UOM uom,  M_PRODUCT p
carlos@0
    39
        WHERE o.C_ORDER_ID = l.C_ORDER_ID 
carlos@0
    40
        AND o.IsSOTrx='N' 
carlos@0
    41
        AND o.DocStatus IN ('CL','CO') 
carlos@0
    42
        AND o.AD_Client_ID IN ('1') 
carlos@0
    43
        AND o.AD_Org_ID IN ('1') 
carlos@0
    44
        AND l.C_UOM_ID=uom.C_UOM_ID
carlos@0
    45
        AND l.M_Product_ID=p.M_Product_ID
juanpablo@1605
    46
        AND l.C_Order_ID = ? 
carlos@0
    47
        GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.C_UOM_ID,
carlos@0
    48
        uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.ad_org_id
carlos@0
    49
        HAVING (l.QtyOrdered-SUM(COALESCE(m.Qty,0))) <> 0
carlos@0
    50
        ORDER BY NAME, l.Line
carlos@0
    51
      ]]>
carlos@0
    52
    </Sql>
carlos@0
    53
    <Field name="rownum" value="count"/>
carlos@0
    54
    <Parameter name="language"/>
carlos@0
    55
    <Parameter name="adUserClient" type="replace" optional="true" after="o.AD_Client_ID IN (" text="'1'"/>
carlos@0
    56
    <Parameter name="adOrgClient" type="replace" optional="true" after="o.AD_Org_ID IN (" text="'1'"/>
carlos@0
    57
    <Parameter name="poId"/>
carlos@0
    58
  </SqlMethod>
carlos@0
    59
  <SqlMethod name="selectFromPOCombo" type="preparedStatement" return="multiple">
carlos@0
    60
    <SqlMethodComment></SqlMethodComment>
carlos@0
    61
    <Sql>
carlos@0
    62
      <![CDATA[
carlos@0
    63
        SELECT o.C_ORDER_ID as ID, Ad_Column_Identifier(to_char('C_Order'), to_char(o.c_order_id), to_char(?)) AS NAME 
carlos@0
    64
        FROM C_ORDER o 
carlos@0
    65
        WHERE o.IsSOTrx='N' 
carlos@0
    66
        AND o.DocStatus IN ('CL','CO') 
carlos@0
    67
        AND o.AD_Client_ID IN ('1') 
carlos@0
    68
        AND o.AD_Org_ID IN ('1')
juanpablo@1605
    69
        AND o.C_BPartner_ID = ?
carlos@0
    70
        AND EXISTS (SELECT 1 
carlos@0
    71
                     FROM C_ORDERLINE l left join M_MATCHPO m on  l.C_OrderLine_ID=m.C_OrderLine_ID
carlos@0
    72
                                                              and m.C_InvoiceLine_ID IS NOT NULL  
carlos@0
    73
                    WHERE l.C_ORDER_ID = o.C_ORDER_ID  
carlos@0
    74
                    GROUP BY l.QtyOrdered,l.C_OrderLine_ID 
carlos@0
    75
                    HAVING (l.QtyOrdered-SUM(COALESCE(m.Qty,0))) <> 0)
carlos@0
    76
        ORDER BY NAME
carlos@0
    77
      ]]>
carlos@0
    78
    </Sql>
carlos@0
    79
    <Parameter name="language"/>
carlos@0
    80
    <Parameter name="adUserClient" type="replace" optional="true" after="o.AD_Client_ID IN (" text="'1'"/>
carlos@0
    81
    <Parameter name="adOrgClient" type="replace" optional="true" after="o.AD_Org_ID IN (" text="'1'"/>
carlos@0
    82
    <Parameter name="cBpartnerId"/>
carlos@0
    83
  </SqlMethod>
carlos@0
    84
  <SqlMethod name="selectFromPOSOTrx" type="preparedStatement" return="multiple">
carlos@0
    85
    <SqlMethodComment></SqlMethodComment>
carlos@0
    86
    <Sql>
carlos@0
    87
      <![CDATA[
carlos@0
    88
        SELECT o.C_ORDER_ID as ID, Ad_Column_Identifier(to_char('C_Order'), to_char(o.c_order_id), to_char(?)) AS NAME,o.DocumentNo AS NAMEORDER,
carlos@0
    89
        l.QtyOrdered-COALESCE(l.QTYINVOICED,0) AS QTY, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,p.NAME AS RELATION_NAME, 
carlos@0
    90
        l.C_OrderLine_ID,l.Line, l.ad_Org_id
carlos@0
    91
        FROM C_INVOICE_CANDIDATE_V ic, C_UOM uom, C_ORDER o, C_ORDERLINE l, M_PRODUCT p 
carlos@0
    92
        WHERE l.C_UOM_ID=uom.C_UOM_ID
carlos@0
    93
        AND o.C_ORDER_ID = ic.C_ORDER_ID 
carlos@0
    94
        AND o.C_ORDER_ID=l.C_ORDER_ID 
carlos@0
    95
        AND ic.AD_Client_ID IN ('1') 
carlos@0
    96
        AND ic.AD_Org_ID IN ('1') 
carlos@0
    97
        AND l.M_Product_ID=p.M_Product_ID 
juanpablo@1605
    98
        AND ic.C_Order_ID = ? 
carlos@0
    99
        GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,
carlos@0
   100
        l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.QTYINVOICED, l.ad_org_id
carlos@0
   101
        ORDER BY NAME, l.Line
carlos@0
   102
      ]]>
carlos@0
   103
    </Sql>
carlos@0
   104
    <Field name="rownum" value="count"/>
carlos@0
   105
    <Parameter name="language"/>
carlos@0
   106
    <Parameter name="adUserClient" type="replace" optional="true" after="ic.AD_Client_ID IN (" text="'1'"/>
carlos@0
   107
    <Parameter name="adOrgClient" type="replace" optional="true" after="ic.AD_Org_ID IN (" text="'1'"/>
carlos@0
   108
    <Parameter name="poId"/>
carlos@0
   109
  </SqlMethod>
carlos@0
   110
  <SqlMethod name="selectFromPOSOTrxCombo" type="preparedStatement" return="multiple">
carlos@0
   111
    <SqlMethodComment></SqlMethodComment>
carlos@0
   112
    <Sql>
carlos@0
   113
      <![CDATA[
carlos@0
   114
        SELECT o.C_ORDER_ID as ID, Ad_Column_Identifier(to_char('C_Order'), to_char(o.c_order_id), to_char(?)) AS NAME 
carlos@0
   115
        FROM C_INVOICE_CANDIDATE_V ic, C_ORDER o 
carlos@0
   116
        WHERE o.C_ORDER_ID = ic.C_ORDER_ID 
carlos@0
   117
        AND ic.AD_Client_ID IN ('1') 
carlos@0
   118
        AND ic.AD_Org_ID IN ('1') 
juanpablo@1605
   119
        AND ic.C_BPartner_ID = ? 
harikrishnan@5407
   120
        AND ((ic.term = 'D' AND ic.qtydelivered >0) OR (ic.term = 'I') OR (ic.term <> 'N' AND (ic.term IN ('O','S') AND (ic.qtyordered = ic.qtydelivered) )) )
carlos@0
   121
        GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal 
carlos@0
   122
        ORDER BY NAME
carlos@0
   123
      ]]>
carlos@0
   124
    </Sql>
carlos@0
   125
    <Parameter name="language"/>
carlos@0
   126
    <Parameter name="adUserClient" type="replace" optional="true" after="ic.AD_Client_ID IN (" text="'1'"/>
carlos@0
   127
    <Parameter name="adOrgClient" type="replace" optional="true" after="ic.AD_Org_ID IN (" text="'1'"/>
carlos@0
   128
    <Parameter name="cBpartnerId"/>
carlos@0
   129
  </SqlMethod>
carlos@0
   130
  <SqlMethod name="selectFromPOTrl" type="preparedStatement" return="multiple">
carlos@0
   131
    <SqlMethodComment></SqlMethodComment>
carlos@0
   132
    <Sql>
carlos@0
   133
      <![CDATA[
carlos@0
   134
        SELECT o.C_ORDER_ID as ID, Ad_Column_Identifier(to_char('C_Order'), to_char(o.c_order_id), to_char(?)) AS NAME, o.DocumentNo AS NAMEORDER,
carlos@0
   135
        l.QtyOrdered-SUM(COALESCE(m.Qty,0)) AS QTY, l.C_UOM_ID, COALESCE(uomt.UOMSYMBOL, uom.UOMSymbol) AS UOMSymbol, 
carlos@0
   136
        l.M_Product_ID,p.NAME AS RELATION_NAME, l.C_OrderLine_ID,l.Line 
carlos@0
   137
        FROM C_UOM uom left join  C_UOM_TRL uomt on uom.C_UOM_ID = uomt.C_UOM_ID
carlos@0
   138
                                                and uomt.AD_Language = ?,
carlos@0
   139
             C_ORDERLINE l left join M_MATCHPO m on l.C_OrderLine_ID=m.C_OrderLine_ID
carlos@0
   140
                                                and m.C_InvoiceLine_ID IS NOT NULL,
carlos@0
   141
        C_ORDER o, M_PRODUCT p
carlos@0
   142
        WHERE o.C_ORDER_ID = l.C_ORDER_ID 
carlos@0
   143
        AND o.IsSOTrx='N' 
carlos@0
   144
        AND o.DocStatus IN ('CL','CO') 
carlos@0
   145
        AND o.AD_Client_ID IN ('1') 
carlos@0
   146
        AND o.AD_Org_ID IN ('1') 
carlos@0
   147
        AND l.C_UOM_ID=uom.C_UOM_ID 
carlos@0
   148
        AND l.M_Product_ID=p.M_Product_ID  
juanpablo@1605
   149
        AND l.C_Order_ID = ? 
carlos@0
   150
        GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,l.C_UOM_ID,
carlos@0
   151
        uom.UOMSymbol, uomt.UOMSYMBOL,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID 
carlos@0
   152
        HAVING (l.QtyOrdered-SUM(COALESCE(m.Qty,0))) <> 0
carlos@0
   153
        ORDER BY NAME, l.Line
carlos@0
   154
      ]]>
carlos@0
   155
    </Sql>
carlos@0
   156
    <Field name="rownum" value="count"/>
carlos@0
   157
    <Parameter name="adLanguage"/>
carlos@0
   158
    <Parameter name="adUserClient" type="replace" optional="true" after="o.AD_Client_ID IN (" text="'1'"/>
carlos@0
   159
    <Parameter name="adOrgClient" type="replace" optional="true" after="o.AD_Org_ID IN (" text="'1'"/>
carlos@0
   160
    <Parameter name="adLanguage"/>
carlos@0
   161
    <Parameter name="poId"/>
carlos@0
   162
  </SqlMethod>
carlos@0
   163
  <SqlMethod name="selectFromPOTrlSOTrx" type="preparedStatement" return="multiple">
carlos@0
   164
    <SqlMethodComment></SqlMethodComment>
carlos@0
   165
    <Sql>
carlos@0
   166
      <![CDATA[
carlos@0
   167
        SELECT o.C_ORDER_ID as ID, Ad_Column_Identifier(to_char('C_Order'), to_char(o.c_order_id), to_char(?) ) AS NAME,o.DocumentNo AS NAMEORDER,
carlos@0
   168
        l.QtyOrdered-COALESCE(l.QTYINVOICED,0) AS QTY, l.C_UOM_ID, COALESCE(uomt.UOMSymbol, uom.UOMSymbol) AS UOMSymbol, 
carlos@0
   169
        l.M_Product_ID,p.NAME AS RELATION_NAME, l.C_OrderLine_ID,l.Line
carlos@0
   170
        FROM C_UOM uom left join C_UOM_TRL uomt on uom.C_UOM_ID = uomt.C_UOM_ID
carlos@0
   171
                                               and  uomt.AD_Language = ?, 
carlos@0
   172
        C_INVOICE_CANDIDATE_V ic,   C_ORDER o, C_ORDERLINE l, M_PRODUCT p 
carlos@0
   173
        WHERE l.C_UOM_ID=uom.C_UOM_ID
carlos@0
   174
        AND o.C_ORDER_ID = ic.C_ORDER_ID 
carlos@0
   175
        AND o.C_ORDER_ID=l.C_ORDER_ID 
carlos@0
   176
        AND ic.AD_Client_ID IN ('1') 
carlos@0
   177
        AND ic.AD_Org_ID IN ('1') 
carlos@0
   178
        AND l.M_Product_ID=p.M_Product_ID
juanpablo@1605
   179
        AND ic.C_Order_ID = ? 
carlos@0
   180
        GROUP BY o.C_ORDER_ID, o.DocumentNo, o.DateOrdered, o.GrandTotal, l.QtyOrdered,
carlos@0
   181
        l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, l.QTYINVOICED 
carlos@0
   182
        ORDER BY NAME, l.Line
carlos@0
   183
      ]]>
carlos@0
   184
    </Sql>
carlos@0
   185
    <Field name="rownum" value="count"/>
carlos@0
   186
    <Parameter name="adLanguage"/>
carlos@0
   187
    <Parameter name="adUserClient" type="replace" optional="true" after="ic.AD_Client_ID IN (" text="'1'"/>
carlos@0
   188
    <Parameter name="adOrgClient" type="replace" optional="true" after="ic.AD_Org_ID IN (" text="'1'"/>
carlos@0
   189
    <Parameter name="adLanguage"/>
carlos@0
   190
    <Parameter name="poId"/>
carlos@0
   191
  </SqlMethod>
carlos@0
   192
  
carlos@0
   193
  <SqlMethod name="selectFromPOUpdate" type="preparedStatement" connection="true" return="multiple">
carlos@0
   194
    <SqlMethodComment></SqlMethodComment>
carlos@0
   195
    <Sql>
carlos@0
   196
      <![CDATA[
carlos@0
   197
      SELECT (CASE WHEN B.M_InOutLine_ID IS NULL THEN A.QTY ELSE B.QTY END) AS ID, 
rafael@5919
   198
      A.C_UOM_ID,uom.UOMSymbol, A.M_Product_ID,p.NAME, A.C_OrderLine_ID,A.Line, uom.stdprecision AS stdprecision, cur.priceprecision, 
carlos@0
   199
      B.M_InOutLine_ID, A.Description, (CASE WHEN B.M_InOutLine_ID IS NULL THEN A.quantityOrder ELSE B.quantityOrder END) AS quantityOrder, 
carlos@0
   200
      (CASE WHEN B.M_InOutLine_ID IS NULL THEN A.M_Product_UOM_ID ELSE B.M_Product_UOM_ID END) AS M_Product_UOM_ID, A.M_ATTRIBUTESETINSTANCE_ID, A.ad_org_id
harikrishnan@4494
   201
      FROM c_currency cur,C_UOM uom, M_PRODUCT p, 
harikrishnan@4494
   202
      (SELECT l.ad_org_id,l.C_CURRENCY_ID,l.C_UOM_ID, l.M_Product_ID, l.Line, l.Description, l.C_OrderLine_ID, (l.QtyOrdered-SUM(COALESCE(mp.Qty,0))) AS QTY,
gorkaion@1787
   203
      l.quantityOrder*C_DIVIDE((l.QtyOrdered-SUM(COALESCE(mp.Qty,0))),l.QtyOrdered) as quantityOrder, l.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID
carlos@0
   204
        FROM C_ORDERLINE l left join M_MATCHPO mp on l.C_OrderLine_ID=mp.C_OrderLine_ID
carlos@0
   205
                                                  and mp.C_InvoiceLine_ID IS NOT NULL
harikrishnan@4494
   206
        GROUP BY l.ad_org_id,l.C_CURRENCY_ID,l.C_UOM_ID, l.M_Product_ID, l.Line, l.Description, l.C_OrderLine_ID, l.QtyOrdered, l.quantityOrder, l.M_Product_UOM_ID,
carlos@0
   207
        l.M_ATTRIBUTESETINSTANCE_ID) A left join 
carlos@0
   208
      (SELECT il.M_InOutLine_ID, il.C_OrderLine_ID, (il.MovementQty-SUM(COALESCE(mi.Qty,0))) AS QTY,
gorkaion@1787
   209
      il.quantityOrder*C_DIVIDE((il.MovementQty-SUM(COALESCE(mi.Qty,0))),(il.MovementQty)) as quantityOrder, il.M_Product_UOM_ID
gorkaion@158
   210
        FROM M_INOUTLINE il left join M_MATCHINV mi on il.M_InOutLine_ID=mi.M_InOutLine_ID,
gorkaion@158
   211
             M_INOUT io
carlos@0
   212
        WHERE il.C_OrderLine_ID IS NOT NULL
gorkaion@158
   213
        AND io.M_InOut_ID = il.M_InOut_ID
gorkaion@158
   214
        AND io.Processed = 'Y'
carlos@0
   215
        GROUP BY il.M_InOutLine_ID, il.C_OrderLine_ID, il.MovementQty, il.quantityOrder, il.M_Product_UOM_ID
carlos@0
   216
        HAVING (il.MovementQty-SUM(COALESCE(mi.Qty,0))) <> 0) B on A.C_OrderLine_ID=B.C_OrderLine_ID
carlos@0
   217
      WHERE A.C_UOM_ID=uom.C_UOM_ID
harikrishnan@4494
   218
      AND cur.C_CURRENCY_ID=A.C_CURRENCY_ID
carlos@0
   219
      AND A.M_Product_ID=p.M_Product_ID
carlos@0
   220
      ORDER BY A.Line
carlos@0
   221
      ]]>
carlos@0
   222
    </Sql>
carlos@0
   223
    <Parameter name="cOrderlineId" optional="true" type="argument" after="AND A.M_Product_ID=p.M_Product_ID" text=" AND A.C_OrderLine_ID IN "/>
carlos@0
   224
  </SqlMethod>
carlos@0
   225
  <SqlMethod name="selectFromPOUpdateSOTrx" type="preparedStatement" connection="true" return="multiple">
carlos@0
   226
    <SqlMethodComment></SqlMethodComment>
carlos@0
   227
    <Sql>
carlos@0
   228
      <![CDATA[
carlos@0
   229
        SELECT (CASE WHEN il.M_INOUTLINE_ID IS NULL THEN (l.QtyOrdered-COALESCE(l.QTYINVOICED ,0)) ELSE il.MOVEMENTQTY END) AS ID, 
carlos@0
   230
        l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,p.NAME, 
rafael@5919
   231
        l.C_OrderLine_ID,l.Line, max(uom.stdprecision) AS stdprecision, cur.priceprecision, il.M_InOutLine_ID as M_InOutLine_ID, l.Description,
gorkaion@1787
   232
        (CASE WHEN il.M_INOUTLINE_ID IS NULL THEN l.quantityOrder*C_DIVIDE((l.QtyOrdered-COALESCE(l.QTYINVOICED ,0)),(l.QtyOrdered)) ELSE il.quantityOrder END) AS quantityOrder, 
carlos@0
   233
        (CASE WHEN il.M_INOUTLINE_ID IS NULL THEN l.M_Product_UOM_ID ELSE il.M_Product_UOM_ID END) AS M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id
gorkaion@158
   234
        FROM C_ORDERLINE l left join (SELECT M_InOutLine.* FROM M_InOutLine, M_InOut
gorkaion@158
   235
                                      WHERE M_InOut.M_InOut_ID = M_InOutLine.M_InOut_ID
gorkaion@158
   236
                                      AND M_InOutLine.IsInvoiced = 'N'
gorkaion@158
   237
                                      AND M_InOut.Processed='Y') il  on l.C_OrderLine_ID = il.C_OrderLine_ID,
harikrishnan@4494
   238
        C_UOM uom,  M_PRODUCT p  ,c_currency cur
harikrishnan@4494
   239
        WHERE cur.C_CURRENCY_ID=l.C_CURRENCY_ID AND l.C_UOM_ID=uom.C_UOM_ID
carlos@0
   240
        AND l.M_Product_ID=p.M_Product_ID 
carlos@0
   241
        GROUP BY l.QtyOrdered,l.qtydelivered,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME,l.Line,l.C_OrderLine_ID, 
carlos@0
   242
        l.QTYINVOICED, il.M_InOutLine_ID, il.MovementQty, l.Description, l.quantityOrder, il.quantityOrder, 
rafael@5919
   243
        l.M_Product_UOM_ID, il.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID,l.ad_org_id, cur.priceprecision
carlos@0
   244
        HAVING (l.QtyOrdered-COALESCE(l.QTYINVOICED ,0)) <> 0 
carlos@0
   245
        ORDER BY l.Line
carlos@0
   246
      ]]>
carlos@0
   247
    </Sql>
carlos@0
   248
    <Field name="rownum" value="count"/>
carlos@0
   249
    <Parameter name="cOrderlineId" optional="true" type="argument" after=" AND l.M_Product_ID=p.M_Product_ID " text=" AND l.C_OrderLine_ID IN "/>
carlos@0
   250
  </SqlMethod>
carlos@0
   251
  <SqlMethod name="selectFromShipment" type="preparedStatement" return="multiple">
carlos@0
   252
    <SqlMethodComment></SqlMethodComment>
carlos@0
   253
    <Sql>
carlos@0
   254
      <![CDATA[
carlos@0
   255
        SELECT s.M_InOut_ID AS ID, Ad_Column_Identifier(to_char('M_InOut'), to_char(s.M_InOut_ID), to_char(?)) AS NAME, 
carlos@0
   256
        s.DocumentNo AS NAMESHIPMENT, 
ainhoa@3030
   257
        (l.MovementQty-SUM(COALESCE(mi.Qty,0))) AS QTY, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,p.NAME||' '||(CASE WHEN ma.serno IS NOT NULL THEN TO_CHAR('('||' '||ma.serno||' '||')') ELSE TO_CHAR('')  END) AS RELATION_NAME, 
carlos@0
   258
        l.M_InOutLine_ID,l.Line, l.M_InOutLine_ID as C_OrderLine_ID 
carlos@0
   259
        FROM M_INOUTLINE l left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID
carlos@0
   260
                           left join M_MATCHINV mi             on l.M_InOutLine_ID=mi.M_InOutLine_ID,
carlos@0
   261
        M_INOUT s, C_UOM uom,  M_PRODUCT p
carlos@0
   262
        WHERE s.M_INOUT_ID = l.M_INOUT_ID 
carlos@0
   263
        AND s.IsSOTrx='N' 
carlos@0
   264
        AND s.DocStatus IN ('CL','CO') 
carlos@0
   265
        AND s.AD_Client_ID IN ('1') 
carlos@0
   266
        AND s.AD_Org_ID IN ('1') 
carlos@0
   267
        AND l.C_UOM_ID=uom.C_UOM_ID 
carlos@0
   268
        AND l.M_Product_ID=p.M_Product_ID 
juanpablo@1605
   269
        AND l.M_InOut_ID=? 
carlos@0
   270
        GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,
carlos@0
   271
        l.M_Product_ID,ma.serno,p.NAME, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID 
carlos@0
   272
        HAVING  (l.MovementQty-SUM(COALESCE(mi.Qty,0))) <> 0
carlos@0
   273
        ORDER BY NAME, l.Line
carlos@0
   274
      ]]>
carlos@0
   275
    </Sql>
carlos@0
   276
    <Field name="rownum" value="count"/>
carlos@0
   277
    <Parameter name="adLanguage"/>
carlos@0
   278
    <Parameter name="adUserClient" type="replace" optional="true" after="s.AD_Client_ID IN (" text="'1'"/>
carlos@0
   279
    <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
carlos@0
   280
    <Parameter name="mInoutId"/>
carlos@0
   281
  </SqlMethod>
carlos@0
   282
  <SqlMethod name="selectFromShipmentCombo" type="preparedStatement" return="multiple">
carlos@0
   283
    <SqlMethodComment></SqlMethodComment>
carlos@0
   284
    <Sql>
carlos@0
   285
      <![CDATA[
carlos@0
   286
        SELECT s.M_InOut_ID AS ID, Ad_Column_Identifier(to_char('M_InOut'), to_char(s.M_InOut_ID), to_char(?)) AS NAME 
carlos@0
   287
        FROM M_INOUT s 
carlos@0
   288
        WHERE s.IsSOTrx='N' 
carlos@0
   289
        AND s.DocStatus IN ('CL','CO') 
david@1686
   290
        AND s.ISLOGISTIC <> 'Y'
carlos@0
   291
        AND s.AD_Client_ID IN ('1') 
carlos@0
   292
        AND s.AD_Org_ID IN ('1') 
juanpablo@1605
   293
        AND s.C_BPartner_ID = ? 
carlos@0
   294
        AND EXISTS (SELECT 1 
carlos@0
   295
                     FROM M_INOUTLINE l left join M_MATCHINV mi on l.M_InOutLine_ID=mi.M_InOutLine_ID
carlos@0
   296
                      WHERE l.M_INOUT_ID = s.M_INOUT_ID 
carlos@0
   297
                      GROUP BY l.MovementQty, l.M_InOutLine_ID 
carlos@0
   298
                      HAVING  (l.MovementQty-SUM(COALESCE(mi.Qty,0))) <> 0)
carlos@0
   299
        ORDER BY NAME
carlos@0
   300
      ]]>
carlos@0
   301
    </Sql>
carlos@0
   302
    <Field name="rownum" value="count"/>
carlos@0
   303
    <Parameter name="adLanguage"/>
carlos@0
   304
    <Parameter name="adUserClient" type="replace" optional="true" after="s.AD_Client_ID IN (" text="'1'"/>
carlos@0
   305
    <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
carlos@0
   306
    <Parameter name="cBpartnerId"/>
carlos@0
   307
  </SqlMethod>
carlos@0
   308
  <SqlMethod name="selectFromShipmentSOTrx" type="preparedStatement" return="multiple">
carlos@0
   309
    <SqlMethodComment></SqlMethodComment>
carlos@0
   310
    <Sql>
carlos@0
   311
      <![CDATA[
carlos@0
   312
        SELECT s.M_InOut_ID AS ID, Ad_Column_Identifier(to_char('M_InOut'), to_char(s.M_InOut_ID), to_char(?)) AS NAME,
carlos@0
   313
        s.DocumentNo AS NAMESHIPMENT,
ainhoa@3030
   314
        l.MovementQty AS QTY, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,p.NAME||' '||(CASE WHEN ma.serno IS NOT NULL THEN TO_CHAR('('||' '||ma.serno||' '||')') ELSE TO_CHAR('') END) AS RELATION_NAME, l.M_InOutLine_ID,l.Line,
carlos@0
   315
        l.M_InOutLine_ID as C_OrderLine_ID 
carlos@0
   316
        FROM M_INOUTLINE l left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID,
carlos@0
   317
        M_INOUT s, C_UOM uom, M_PRODUCT p 
carlos@0
   318
        WHERE s.M_INOUT_ID = l.M_INOUT_ID
carlos@0
   319
        AND s.IsSOTrx='Y' 
carlos@0
   320
        AND s.DocStatus IN ('CL','CO') 
carlos@0
   321
        AND s.AD_Client_ID IN ('1') 
carlos@0
   322
        AND s.AD_Org_ID IN ('1') 
carlos@0
   323
        AND l.C_UOM_ID=uom.C_UOM_ID 
carlos@0
   324
        AND l.M_Product_ID=p.M_Product_ID 
carlos@0
   325
        AND l.isinvoiced = 'N' 
juanpablo@1605
   326
        AND l.M_InOut_ID=?
carlos@0
   327
        GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,
carlos@0
   328
        l.M_Product_ID,p.NAME, ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID
carlos@0
   329
        ORDER BY NAME, l.Line
carlos@0
   330
      ]]>
carlos@0
   331
    </Sql>
carlos@0
   332
    <Field name="rownum" value="count"/>
carlos@0
   333
    <Parameter name="adLanguage"/>
carlos@0
   334
    <Parameter name="adUserClient" type="replace" optional="true" after="s.AD_Client_ID IN (" text="'1'"/>
carlos@0
   335
    <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
carlos@0
   336
    <Parameter name="mInoutId"/>
carlos@0
   337
  </SqlMethod>
carlos@0
   338
  <SqlMethod name="selectFromShipmentSOTrxCombo" type="preparedStatement" return="multiple">
carlos@0
   339
    <SqlMethodComment></SqlMethodComment>
carlos@0
   340
    <Sql>
carlos@0
   341
      <![CDATA[
carlos@0
   342
        SELECT s.M_InOut_ID AS ID, Ad_Column_Identifier(to_char('M_InOut'), to_char(s.M_InOut_ID), to_char(?)) AS NAME 
carlos@0
   343
        FROM M_INOUT s 
carlos@0
   344
        WHERE s.IsSOTrx='Y' 
david@1686
   345
        AND s.ISLOGISTIC <> 'Y'
carlos@0
   346
        AND s.DocStatus IN ('CL','CO') 
carlos@0
   347
        AND s.AD_Client_ID IN ('1') 
carlos@0
   348
        AND s.AD_Org_ID IN ('1')
juanpablo@1605
   349
        AND s.C_BPartner_ID = ?  
carlos@0
   350
        AND EXISTS (SELECT 1 FROM M_INOUTLINE l 
carlos@0
   351
        WHERE l.M_INOUT_ID = s.M_INOUT_ID 
carlos@0
   352
        AND l.isinvoiced = 'N') 
carlos@0
   353
        ORDER BY NAME
carlos@0
   354
      ]]>
carlos@0
   355
    </Sql>
carlos@0
   356
    <Parameter name="adLanguage"/>
carlos@0
   357
    <Parameter name="adUserClient" type="replace" optional="true" after="s.AD_Client_ID IN (" text="'1'"/>
carlos@0
   358
    <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
carlos@0
   359
    <Parameter name="cBpartnerId"/>
carlos@0
   360
  </SqlMethod>
carlos@0
   361
  <SqlMethod name="selectFromShipmentTrl" type="preparedStatement" return="multiple">
carlos@0
   362
    <SqlMethodComment></SqlMethodComment>
carlos@0
   363
    <Sql>
carlos@0
   364
      <![CDATA[
carlos@0
   365
      SELECT s.M_InOut_ID AS ID, Ad_Column_Identifier(to_char('M_InOut'), to_char(s.M_InOut_ID), to_char(?)) AS NAME,
carlos@0
   366
      s.DocumentNo AS NAMESHIPMENT,
carlos@0
   367
        (l.MovementQty-SUM(COALESCE(mi.Qty,0))) AS QTY, l.C_UOM_ID, COALESCE(uomt.UOMSymbol, uom.UOMSymbol) AS UOMSymbol, 
ainhoa@3030
   368
        l.M_Product_ID,p.NAME||' '||(CASE WHEN ma.serno IS NOT NULL THEN TO_CHAR('('||' '||ma.serno||' '||')') ELSE TO_CHAR('')  END) AS RELATION_NAME, l.M_InOutLine_ID,l.Line, l.M_InOutLine_ID as C_OrderLine_ID 
carlos@0
   369
        FROM M_INOUTLINE l left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID
carlos@0
   370
                           left join M_MATCHINV mi             on l.M_InOutLine_ID=mi.M_InOutLine_ID,
carlos@0
   371
             C_UOM uom     left join C_UOM_TRL uomt            on uom.C_UOM_ID = uomt.C_UOM_ID
carlos@0
   372
                                                              and uomt.AD_Language = ?,
carlos@0
   373
        M_INOUT s,   M_PRODUCT p
carlos@0
   374
        WHERE s.M_INOUT_ID = l.M_INOUT_ID 
carlos@0
   375
        AND s.IsSOTrx='N' 
carlos@0
   376
        AND s.DocStatus IN ('CL','CO') 
carlos@0
   377
        AND s.AD_Client_ID IN ('1') 
carlos@0
   378
        AND s.AD_Org_ID IN ('1') 
carlos@0
   379
        AND l.C_UOM_ID=uom.C_UOM_ID 
carlos@0
   380
        AND l.M_Product_ID=p.M_Product_ID 
juanpablo@1605
   381
        AND l.M_InOut_ID=? 
carlos@0
   382
        GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,
carlos@0
   383
        l.M_Product_ID,p.NAME, ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID 
carlos@0
   384
        HAVING  (l.MovementQty-SUM(COALESCE(mi.Qty,0))) <> 0
carlos@0
   385
        ORDER BY NAME, l.Line
carlos@0
   386
      ]]>
carlos@0
   387
    </Sql>
carlos@0
   388
    <Field name="rownum" value="count"/>
carlos@0
   389
    <Parameter name="adLanguage"/>
carlos@0
   390
    <Parameter name="adUserClient" type="replace" optional="true" after="s.AD_Client_ID IN (" text="'1'"/>
carlos@0
   391
    <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
carlos@0
   392
    <Parameter name="adLanguage"/>
carlos@0
   393
    <Parameter name="mInoutId"/>
carlos@0
   394
  </SqlMethod>
carlos@0
   395
  <SqlMethod name="selectFromShipmentTrlSOTrx" type="preparedStatement" return="multiple">
carlos@0
   396
    <SqlMethodComment></SqlMethodComment>
carlos@0
   397
    <Sql>
carlos@0
   398
      <![CDATA[
carlos@0
   399
        SELECT s.M_InOut_ID AS ID, Ad_Column_Identifier(to_char('M_InOut'), to_char(s.M_InOut_ID), to_char(?)) AS NAME,
carlos@0
   400
        s.DocumentNo AS NAMESHIPMENT, 
carlos@0
   401
        l.MovementQty AS QTY, l.C_UOM_ID,COALESCE(uomt.UOMSymbol, uom.UOMSymbol) AS UOMSymbol, 
ainhoa@3030
   402
        l.M_Product_ID,p.NAME||' '|| (CASE WHEN ma.serno IS NOT NULL THEN TO_CHAR('('||' '||ma.serno||' '||')') ELSE TO_CHAR('')  END) AS RELATION_NAME, l.M_InOutLine_ID,l.Line, l.M_InOutLine_ID as C_OrderLine_ID 
carlos@0
   403
        FROM M_INOUTLINE l left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID,
carlos@0
   404
             C_UOM uom     left join C_UOM_TRL uomt            on uom.C_UOM_ID = uomt.C_UOM_ID
carlos@0
   405
                                                              and uomt.AD_Language = ? ,
carlos@0
   406
        M_INOUT s,    M_PRODUCT p 
carlos@0
   407
        WHERE s.M_INOUT_ID = l.M_INOUT_ID
carlos@0
   408
        AND s.IsSOTrx='Y' 
carlos@0
   409
        AND s.DocStatus IN ('CL','CO') 
carlos@0
   410
        AND s.AD_Client_ID IN ('1') 
carlos@0
   411
        AND s.AD_Org_ID IN ('1') 
carlos@0
   412
        AND l.C_UOM_ID=uom.C_UOM_ID 
carlos@0
   413
        AND l.M_Product_ID=p.M_Product_ID 
carlos@0
   414
        AND l.isinvoiced = 'N' 
juanpablo@1605
   415
        AND l.M_InOut_ID=? 
carlos@0
   416
        GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,
carlos@0
   417
        l.M_Product_ID,p.NAME,ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID
carlos@0
   418
        ORDER BY NAME, l.Line
carlos@0
   419
      ]]>
carlos@0
   420
    </Sql>
carlos@0
   421
    <Field name="rownum" value="count"/>
carlos@0
   422
    <Parameter name="adLanguage"/>
carlos@0
   423
    <Parameter name="adUserClient" type="replace" optional="true" after="s.AD_Client_ID IN (" text="'1'"/>
carlos@0
   424
    <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
carlos@0
   425
    <Parameter name="adLanguage"/>
carlos@0
   426
    <Parameter name="mInoutId"/>
carlos@0
   427
  </SqlMethod>
carlos@0
   428
  <SqlMethod name="selectFromShipmentUpdate" type="preparedStatement" connection="true" return="multiple">
carlos@0
   429
    <SqlMethodComment></SqlMethodComment>
carlos@0
   430
    <Sql>
carlos@0
   431
      <![CDATA[
carlos@0
   432
      SELECT (l.MovementQty-SUM(COALESCE(mi.Qty,0))) AS ID, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,p.NAME, l.M_InOutLine_ID,l.Line,
gorkaion@1787
   433
      l.C_OrderLine_ID, max(uom.STDPRECISION) as stdprecision, l.Description, l.quantityOrder*C_DIVIDE((l.MovementQty-SUM(COALESCE(mi.Qty,0))),l.MovementQty) as quantityOrder, 
carlos@0
   434
      l.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id
carlos@0
   435
      FROM M_INOUTLINE l left join M_MATCHINV mi on l.M_InOutLine_ID=mi.M_InOutLine_ID,
carlos@0
   436
      C_UOM uom,  M_PRODUCT p
carlos@0
   437
      WHERE l.C_UOM_ID=uom.C_UOM_ID
carlos@0
   438
      AND l.M_Product_ID=p.M_Product_ID
carlos@0
   439
      GROUP BY l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID, l.Description,l.quantityOrder, l.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id
carlos@0
   440
      ORDER BY l.Line
carlos@0
   441
      ]]>
carlos@0
   442
    </Sql>
carlos@0
   443
    <Parameter name="cOrderlineId" optional="true" type="argument" after="AND l.M_Product_ID=p.M_Product_ID" text=" AND l.M_InOutLine_ID IN "/>
carlos@0
   444
  </SqlMethod>
carlos@0
   445
  <SqlMethod name="selectFromShipmentUpdateSOTrx" type="preparedStatement" connection="true" return="multiple">
carlos@0
   446
    <SqlMethodComment></SqlMethodComment>
carlos@0
   447
    <Sql>
carlos@0
   448
      <![CDATA[
carlos@0
   449
        SELECT l.MovementQty AS ID, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,p.NAME, l.M_InOutLine_ID,l.Line,
carlos@0
   450
        l.C_OrderLine_ID, max(uom.STDPRECISION) as stdprecision, l.Description,l.quantityOrder, l.M_Product_UOM_ID,
carlos@0
   451
        l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id
carlos@0
   452
        FROM C_UOM uom, M_INOUTLINE l, M_PRODUCT p 
carlos@0
   453
        WHERE l.C_UOM_ID=uom.C_UOM_ID
carlos@0
   454
        AND l.M_Product_ID=p.M_Product_ID 
carlos@0
   455
        AND l.isinvoiced = 'N' 
carlos@0
   456
        GROUP BY l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID, l.Description, l.quantityOrder, l.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id
carlos@0
   457
        ORDER BY l.Line
carlos@0
   458
      ]]>
carlos@0
   459
    </Sql>
carlos@0
   460
    <Field name="rownum" value="count"/>
carlos@0
   461
    <Parameter name="cOrderlineId" optional="true" type="argument" after="AND l.isinvoiced = 'N' " text=" AND l.M_InOutLine_ID IN "/>
carlos@0
   462
  </SqlMethod>
carlos@0
   463
  <SqlMethod name="set" type="constant" return="multiple">
carlos@0
   464
      <SqlMethodComment></SqlMethodComment>
carlos@0
   465
      <Sql></Sql>
carlos@0
   466
  </SqlMethod>
carlos@0
   467
  <SqlMethod name="selectPriceList" type="preparedStatement" connection="true" return="multiple">
carlos@0
   468
    <SqlMethodComment></SqlMethodComment>
carlos@0
   469
    <Sql>
carlos@0
   470
      <![CDATA[
rafael@5919
   471
      SELECT plv.M_PriceList_Version_ID AS ID, cur.Priceprecision
rafael@5919
   472
      FROM M_PRICELIST pl, M_PRICELIST_VERSION plv, C_CURRENCY cur
rafael@5919
   473
      WHERE pl.M_PriceList_ID = plv.M_PriceList_ID 
rafael@5919
   474
      AND pl.C_Currency_ID = cur.C_Currency_ID
rafael@5919
   475
      AND plv.IsActive='Y'
juanpablo@1605
   476
      AND plv.ValidFrom <= TO_DATE(?) AND pl.M_PriceList_ID=? 
carlos@0
   477
      ORDER BY plv.ValidFrom DESC
carlos@0
   478
      ]]>
carlos@0
   479
    </Sql>
carlos@0
   480
    <Parameter name="validfrom"/>
carlos@0
   481
    <Parameter name="mPricelistId"/>
carlos@0
   482
  </SqlMethod>
carlos@0
   483
carlos@0
   484
  <SqlMethod name="selectPrices" type="preparedStatement" connection="true" return="multiple">
carlos@0
   485
    <SqlMethodComment></SqlMethodComment>
carlos@0
   486
    <Sql>
carlos@0
   487
      <![CDATA[
carlos@0
   488
      SELECT PriceActual,PriceList,PriceLimit,Description, '' AS C_ORDERLINE_ID, PriceStd
carlos@0
   489
      FROM C_OrderLine 
juanpablo@1605
   490
      WHERE C_OrderLine_ID=?
carlos@0
   491
      ]]>
carlos@0
   492
    </Sql>
carlos@0
   493
    <Parameter name="cOrderlineId"/>
carlos@0
   494
  </SqlMethod>
carlos@0
   495
  <SqlMethod name="selectBOM" type="preparedStatement" connection="true" return="multiple">
carlos@0
   496
    <SqlMethodComment></SqlMethodComment>
carlos@0
   497
    <Sql>
carlos@0
   498
      <![CDATA[
gorkaion@1787
   499
      SELECT M_BOM_PriceStd(pp.M_Product_ID,pp.M_PriceList_Version_ID) AS PriceStd,
gorkaion@1787
   500
      M_BOM_PriceList(pp.M_Product_ID,pp.M_PriceList_Version_ID) AS PriceList,
gorkaion@1787
   501
      M_BOM_PriceLimit(pp.M_Product_ID,pp.M_PriceList_Version_ID) AS PriceLimit, 
gorkaion@1787
   502
      M_GET_OFFER_PRICE(M_GET_OFFER(to_date(?), ?, pp.M_Product_ID), M_BOM_PriceStd(pp.M_Product_ID,pp.M_PriceList_Version_ID)) AS PriceActual, 
juanpablo@1605
   503
      M_GET_OFFER(to_date(?), ?, pp.M_Product_ID) AS M_Offer_ID
carlos@0
   504
      FROM M_PRODUCTPRICE pp 
juanpablo@1605
   505
      WHERE pp.M_Product_ID=? 
juanpablo@1605
   506
      AND pp.M_PriceList_Version_ID=? 
carlos@0
   507
      ]]>
carlos@0
   508
    </Sql>
carlos@0
   509
    <Parameter name="dateinvoiced"/>
carlos@0
   510
    <Parameter name="cBpartnerId"/>
carlos@0
   511
    <Parameter name="dateinvoiced"/>
carlos@0
   512
    <Parameter name="cBpartnerId"/>
carlos@0
   513
    <Parameter name="mProductId"/>
carlos@0
   514
    <Parameter name="mPricelistVersionId"/>
carlos@0
   515
  </SqlMethod>
carlos@0
   516
  <SqlMethod name="insert" type="preparedStatement" connection="true" return="rowCount">
carlos@0
   517
    <SqlMethodComment></SqlMethodComment>
carlos@0
   518
    <Sql>
juanpablo@1605
   519
      INSERT INTO C_INVOICELINE 
juanpablo@1605
   520
        (C_InvoiceLine_ID,C_Invoice_ID, AD_Client_ID,AD_Org_ID,IsActive,
juanpablo@1605
   521
        Created,CreatedBy,Updated,UpdatedBy, 
juanpablo@1605
   522
        C_OrderLine_ID,M_InOutLine_ID, Line,Description, M_Product_ID,
juanpablo@1605
   523
        C_UOM_ID,QtyInvoiced, PriceList,
juanpablo@1605
   524
        PriceActual,PriceLimit, LineNetAmt,
juanpablo@1605
   525
        ChargeAmt,C_Tax_ID, QuantityOrder, M_Product_UOM_ID,
juanpablo@1605
   526
        M_Attributesetinstance_ID, PriceStd)
juanpablo@1605
   527
      VALUES 
juanpablo@1605
   528
        (?, ?, ?, ?, 'Y', 
juanpablo@1605
   529
         now(), ?, now(), ?, 
juanpablo@1605
   530
         ?, ?, (SELECT (COALESCE(Max(Line),0))+10 FROM C_InvoiceLine WHERE C_Invoice_ID=?), ?, ?, 
juanpablo@1605
   531
         ?, TO_NUMBER(?), TO_NUMBER(?), 
juanpablo@1605
   532
         TO_NUMBER(?), TO_NUMBER(?), TO_NUMBER(?), 
juanpablo@1605
   533
         0, ?, TO_NUMBER(?), ?, 
juanpablo@1605
   534
         ?, TO_NUMBER(?))
carlos@0
   535
    </Sql>
carlos@0
   536
    <Parameter name="cInvoicelineId"/>
carlos@0
   537
    <Parameter name="cInvoiceId"/>
carlos@0
   538
    <Parameter name="adClientId"/>
carlos@0
   539
    <Parameter name="adOrgId"/>
carlos@0
   540
    <Parameter name="adUserId"/>
carlos@0
   541
    <Parameter name="adUserId"/>
carlos@0
   542
    <Parameter name="cOrderlineId"/>
carlos@0
   543
    <Parameter name="mInoutlineId"/>
carlos@0
   544
    <Parameter name="cInvoiceId"/>
carlos@0
   545
    <Parameter name="description"/>
carlos@0
   546
    <Parameter name="mProductId"/>
carlos@0
   547
    <Parameter name="cUomId"/>
carlos@0
   548
    <Parameter name="qtyinvoiced"/>
carlos@0
   549
    <Parameter name="pricelist"/>
carlos@0
   550
    <Parameter name="priceactual"/>
carlos@0
   551
    <Parameter name="pricelimit"/>
carlos@0
   552
    <Parameter name="linenetamt"/>
carlos@0
   553
    <Parameter name="cTaxId"/>
carlos@0
   554
    <Parameter name="quantityOrder"/>
carlos@0
   555
    <Parameter name="mProductUomId"/>
carlos@0
   556
    <Parameter name="mAttributesetinstanceId"/>
carlos@0
   557
    <Parameter name="pricestd"/>
carlos@0
   558
  </SqlMethod>
carlos@0
   559
  <SqlMethod name="updateC_Order_ID" type="preparedStatement" connection="true" return="rowCount">
carlos@0
   560
    <SqlMethodComment></SqlMethodComment>
carlos@0
   561
    <Sql><![CDATA[
juanpablo@1605
   562
      UPDATE C_Invoice SET C_Order_id = ?
juanpablo@1605
   563
      WHERE C_Invoice_ID = ?
carlos@0
   564
    ]]></Sql>
carlos@0
   565
    <Parameter name="cOrderId"/>
carlos@0
   566
    <Parameter name="cInvoiceId"/>
carlos@0
   567
  </SqlMethod>
carlos@0
   568
  <SqlMethod name="deleteC_Order_ID" type="preparedStatement" connection="true" return="rowCount">
carlos@0
   569
    <SqlMethodComment></SqlMethodComment>
carlos@0
   570
    <Sql> <![CDATA[
carlos@0
   571
      UPDATE C_INVOICE SET C_Order_ID=NULL
juanpablo@1605
   572
      WHERE C_Invoice_ID=?
juanpablo@1605
   573
      AND C_Order_ID IS NOT NULL AND C_Order_ID <> ?
carlos@0
   574
    ]]></Sql>
carlos@0
   575
    <Parameter name="cInvoiceId"/>
carlos@0
   576
    <Parameter name="cOrderId"/>
carlos@0
   577
  </SqlMethod>
carlos@0
   578
  <SqlMethod name="selectProject" type="preparedStatement" return="String" default="">
carlos@0
   579
    <SqlMethodComment></SqlMethodComment>
carlos@0
   580
    <Sql><![CDATA[
carlos@0
   581
      SELECT C_Project_ID
carlos@0
   582
      FROM C_INVOICE
juanpablo@1605
   583
      WHERE C_INVOICE_ID = ? 
carlos@0
   584
    ]]></Sql>
carlos@0
   585
    <Parameter name="cInvoiceId"/>
carlos@0
   586
  </SqlMethod>
carlos@0
   587
  <SqlMethod name="getTax" type="preparedStatement" return="String" default="">
carlos@0
   588
    <SqlMethodComment></SqlMethodComment>
carlos@0
   589
    <Sql><![CDATA[
carlos@0
   590
      SELECT C_Tax_ID
carlos@0
   591
      FROM C_ORDERLINE
juanpablo@1605
   592
      WHERE C_ORDERLINE_ID = ? 
carlos@0
   593
    ]]></Sql>
carlos@0
   594
    <Parameter name="cOrderLineId"/>
carlos@0
   595
  </SqlMethod>
carlos@0
   596
</SqlClass>