src-db/database/model/functions/C_CREATE_PINVOICE_FROM_OUTS.xml
author Carlos Romero <carlos.romero@openbravo.com>
Tue, 17 Jun 2008 17:04:30 +0000
changeset 1259 aa36b7150211
parent 799 fef2c5e2feb7
child 1605 8a0fe0193bef
permissions -rw-r--r--
Fixed bug 4002: Review processes that create Invoices because of Tax Date
Functions and inserts modified in order to include TaxDate with the same value that DateAcct
* C_COMMISSIONRUN_PROCESS.xml
* C_CREATE_PINVOICE_FROM_OUTS.xml
* C_INVOICE_CREATE.xml
* C_INVOICE_POST.xml
* M_INOUT_CREATEINVOICE.xml
* M_RAPPEL_INVOICE_CREATE.xml
* C_INVOICE_TRG.xml
* ad_forms/InvoiceVendorMultiline_data.xsql
* ad_process/ExpenseAPInvoice_data.xsql
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION C_CREATE_PINVOICE_FROM_OUTS">
adrian@94
     3
    <function name="C_CREATE_PINVOICE_FROM_OUTS" type="NULL">
antonio@735
     4
      <parameter name="p_pinstance_id" type="NUMERIC" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
gorkaion@239
     7
      <body><![CDATA[/*************************************************************************
carlos@0
     8
* The contents of this file are subject to the Openbravo  Public  License
carlos@0
     9
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
carlos@0
    10
* Version 1.1  with a permitted attribution clause; you may not  use this
carlos@0
    11
* file except in compliance with the License. You  may  obtain  a copy of
carlos@0
    12
* the License at http://www.openbravo.com/legal/license.html
carlos@0
    13
* Software distributed under the License  is  distributed  on  an "AS IS"
carlos@0
    14
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
carlos@0
    15
* License for the specific  language  governing  rights  and  limitations
carlos@0
    16
* under the License.
carlos@0
    17
* The Original Code is Openbravo ERP.
carlos@0
    18
* The Initial Developer of the Original Code is Openbravo SL
carlos@1259
    19
* All portions are Copyright (C) 2001-2008 Openbravo SL
carlos@0
    20
* All Rights Reserved.
carlos@0
    21
* Contributor(s):  ______________________________________.
carlos@0
    22
************************************************************************/
carlos@0
    23
  /*************************************************************************
carlos@0
    24
  * Description:
carlos@0
    25
  * - Create purchase invoice from sales shipments and inventory movements
carlos@0
    26
  ************************************************************************/
carlos@0
    27
  -- Logistice
carlos@0
    28
  v_ResultStr VARCHAR2(2000):='';
carlos@0
    29
  v_Message VARCHAR2(2000):='';
carlos@0
    30
  -- Parameter
carlos@0
    31
  TYPE RECORD IS REF CURSOR;
carlos@0
    32
    Cur_Parameter RECORD;
carlos@0
    33
    v_DateFrom DATE;
carlos@0
    34
    v_DateTo DATE;
carlos@0
    35
    v_Warehouse_ID NUMBER(10) ;
carlos@0
    36
    v_BPartner_ID NUMBER(10) ;
carlos@0
    37
    v_ReferenceNo NVARCHAR2(40) ;
carlos@0
    38
    v_DateInvoiced DATE;
carlos@0
    39
    v_User_ID NUMBER(10) ;
carlos@0
    40
    --
carlos@0
    41
    v_Project_ID NUMBER(10):=0;
carlos@0
    42
    v_Doctype_ID NUMBER(10) ;
carlos@0
    43
    v_Invoice_ID NUMBER(10) ;
carlos@0
    44
    v_DocumentNo NVARCHAR2(60) ;
carlos@0
    45
    v_PaymentRule CHAR(1) ;
carlos@0
    46
    v_PaymentTerm_ID NUMBER(10) ;
carlos@0
    47
    v_Currency_ID NUMBER(10) ;
carlos@0
    48
    v_IsTaxIncluded CHAR(1) ;
carlos@0
    49
    v_NoRecords NUMBER:=0;
carlos@0
    50
    v_InvoiceLine_ID NUMBER(10) ;
carlos@0
    51
    v_auxQty NUMBER;
carlos@0
    52
    v_auxQtyTotal NUMBER;
carlos@0
    53
    v_line NUMBER;
carlos@0
    54
    v_priceList NUMBER;
carlos@0
    55
    v_priceActual NUMBER;
carlos@0
    56
    v_priceLimit NUMBER;
carlos@0
    57
    v_Tax_ID NUMBER(10) ;
carlos@0
    58
    v_BPLocation_ID NUMBER(10) ;
carlos@0
    59
    -- Outs: shipments and inventory movements
carlos@0
    60
    Cur_Outs RECORD;
carlos@0
    61
    -- Pend: orderlines-inoutlines not invoiced
carlos@0
    62
    Cur_Pend RECORD;
carlos@0
    63
  BEGIN
carlos@0
    64
    --  Update AD_PInstance
carlos@0
    65
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
carlos@0
    66
    v_ResultStr:='PInstanceNotFound';
antonio@735
    67
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    68
  BEGIN --BODY
carlos@0
    69
    -- Get Parameters
carlos@0
    70
    v_ResultStr:='ReadingParameters';
carlos@0
    71
    FOR Cur_Parameter IN
carlos@0
    72
      (SELECT i.Record_ID,
carlos@0
    73
        p.ParameterName,
carlos@0
    74
        p.P_String,
carlos@0
    75
        p.P_Number,
carlos@0
    76
        p.P_Date,
carlos@0
    77
        i.UpdatedBy
carlos@0
    78
      FROM AD_PINSTANCE i
carlos@0
    79
      LEFT JOIN AD_PINSTANCE_PARA p
carlos@0
    80
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    81
      WHERE i.AD_PInstance_ID=p_PInstance_ID
carlos@0
    82
      ORDER BY p.SeqNo
carlos@0
    83
      )
carlos@0
    84
    LOOP
carlos@0
    85
      v_User_ID:=Cur_Parameter.UpdatedBy;
carlos@0
    86
      IF(Cur_Parameter.ParameterName='DateFrom') THEN
carlos@0
    87
        v_DateFrom:=Cur_Parameter.P_Date;
carlos@0
    88
        DBMS_OUTPUT.PUT_LINE('  DateFrom=' || v_DateFrom) ;
carlos@0
    89
      ELSIF(Cur_Parameter.ParameterName='DateTo') THEN
carlos@0
    90
        v_DateTo:=Cur_Parameter.P_Date;
carlos@0
    91
        DBMS_OUTPUT.PUT_LINE('  DateTo=' || v_DateTo) ;
carlos@0
    92
      ELSIF(Cur_Parameter.ParameterName='M_Warehouse_ID') THEN
carlos@0
    93
        v_Warehouse_ID:=Cur_Parameter.P_Number;
carlos@0
    94
        DBMS_OUTPUT.PUT_LINE('  M_Warehouse_ID=' || v_Warehouse_ID) ;
carlos@0
    95
      ELSIF(Cur_Parameter.ParameterName='C_BPartner_ID') THEN
carlos@0
    96
        v_BPartner_ID:=Cur_Parameter.P_Number;
carlos@0
    97
        DBMS_OUTPUT.PUT_LINE('  C_BPartner_ID=' || v_BPartner_ID) ;
carlos@0
    98
      ELSIF(Cur_Parameter.ParameterName='ReferenceNo') THEN
carlos@0
    99
        v_ReferenceNo:=Cur_Parameter.P_String;
carlos@0
   100
        DBMS_OUTPUT.PUT_LINE('  ReferenceNo=' || v_ReferenceNo) ;
carlos@0
   101
      ELSIF(Cur_Parameter.ParameterName='DateInvoiced') THEN
carlos@0
   102
        v_DateInvoiced:=Cur_Parameter.P_Date;
carlos@0
   103
        DBMS_OUTPUT.PUT_LINE('  DateInvoiced=' || v_DateInvoiced) ;
carlos@0
   104
      ELSE
carlos@0
   105
        DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || Cur_Parameter.ParameterName) ;
carlos@0
   106
      END IF;
carlos@0
   107
    END LOOP; -- Get Parameter
carlos@0
   108
    FOR Cur_Outs IN
carlos@0
   109
      (SELECT s.AD_Client_ID,
carlos@0
   110
        s.AD_Org_ID,
carlos@0
   111
        p.C_Project_ID,
carlos@0
   112
        pv.M_PriceList_ID,
carlos@0
   113
        sl.M_Product_ID,
carlos@0
   114
        sl.MovementQty,
carlos@0
   115
        sl.C_UOM_ID,
carlos@0
   116
        sl.M_AttributeSetInstance_ID,
carlos@0
   117
        sl.quantityOrder,
carlos@0
   118
        sl.M_Product_UOM_ID
carlos@0
   119
      FROM M_INOUT s,
carlos@0
   120
        M_INOUTLINE sl,
carlos@0
   121
        C_PROJECT p,
carlos@0
   122
        C_PROJECT_VENDOR pv,
carlos@0
   123
        M_LOCATOR l
carlos@0
   124
      WHERE s.M_InOut_ID=sl.M_InOut_ID
carlos@0
   125
        AND s.C_Project_ID=p.C_Project_ID
carlos@0
   126
        AND p.C_Project_ID=pv.C_Project_ID
carlos@0
   127
        AND sl.M_Locator_ID=l.M_Locator_ID
carlos@0
   128
        AND s.IsSOTrx='Y'
gorkaion@239
   129
        AND s.MovementDate>=v_DateFrom
gorkaion@239
   130
        AND s.MovementDate<v_DateTo + 1
carlos@0
   131
        AND l.M_Warehouse_ID=v_Warehouse_ID
carlos@0
   132
        AND pv.C_BPartner_ID=v_BPartner_ID
gorkaion@239
   133
        AND sl.MovementQty<>0
carlos@0
   134
      UNION ALL
carlos@0
   135
      SELECT s.AD_Client_ID,
carlos@0
   136
        s.AD_Org_ID,
carlos@0
   137
        p.C_Project_ID,
carlos@0
   138
        pv.M_PriceList_ID,
carlos@0
   139
        sl.M_Product_ID,
carlos@0
   140
        sl.MovementQty,
carlos@0
   141
        sl.C_UOM_ID,
carlos@0
   142
        sl.M_AttributeSetInstance_ID,
carlos@0
   143
        sl.quantityOrder,
carlos@0
   144
        sl.M_Product_UOM_ID
carlos@0
   145
      FROM M_MOVEMENT s,
carlos@0
   146
        M_MOVEMENTLINE sl,
carlos@0
   147
        C_PROJECT p,
carlos@0
   148
        C_PROJECT_VENDOR pv,
carlos@0
   149
        M_LOCATOR l
carlos@0
   150
      WHERE s.M_Movement_ID=sl.M_Movement_ID
carlos@0
   151
        AND s.C_Project_ID=p.C_Project_ID
carlos@0
   152
        AND p.C_Project_ID=pv.C_Project_ID
carlos@0
   153
        AND sl.M_Locator_ID=l.M_Locator_ID
gorkaion@239
   154
        AND s.MovementDate>=v_DateFrom
gorkaion@239
   155
        AND s.MovementDate<v_DateTo + 1
carlos@0
   156
        AND l.M_Warehouse_ID=v_Warehouse_ID
carlos@0
   157
        AND pv.C_BPartner_ID=v_BPartner_ID
gorkaion@239
   158
        AND sl.MovementQty<>0
carlos@0
   159
      ORDER BY C_Project_ID,
carlos@0
   160
        M_Product_ID,
carlos@0
   161
        C_UOM_ID,
carlos@0
   162
        M_Product_UOM_ID
carlos@0
   163
      )
carlos@0
   164
    LOOP
carlos@0
   165
      v_BPLocation_ID:=C_Getbplocationid(v_BPartner_ID, 'B') ;
gorkaion@239
   166
      IF(v_Project_ID<>Cur_Outs.C_Project_ID) THEN
carlos@0
   167
        v_NoRecords:=v_NoRecords + 1;
carlos@0
   168
        v_Project_ID:=Cur_Outs.C_Project_ID;
carlos@0
   169
        v_line:=0;
carlos@0
   170
        v_DocType_ID:=Ad_Get_Doctype(Cur_Outs.AD_Client_ID, Cur_Outs.AD_Org_ID, 'API') ;
carlos@0
   171
        --
carlos@0
   172
        Ad_Sequence_Next('C_Invoice', Cur_Outs.AD_Client_ID, v_Invoice_ID) ;
carlos@0
   173
        Ad_Sequence_Doctype(v_DocType_ID, Cur_Outs.AD_Client_ID, 'Y', v_DocumentNo) ;
carlos@0
   174
        IF(v_DocumentNo IS NULL) THEN
carlos@0
   175
          Ad_Sequence_Doc('DocumentNo_C_Invoice', Cur_Outs.AD_Client_ID, 'Y', v_DocumentNo) ;
carlos@0
   176
        END IF;
carlos@0
   177
        SELECT PAYMENTRULEPO,
carlos@0
   178
          PO_PAYMENTTERM_ID
carlos@0
   179
        INTO v_PaymentRule,
carlos@0
   180
          v_PaymentTerm_ID
carlos@0
   181
        FROM C_BPARTNER
carlos@0
   182
        WHERE C_BPartner_ID=v_BPartner_ID;
carlos@0
   183
        SELECT C_Currency_ID,
carlos@0
   184
          IsTaxIncluded
carlos@0
   185
        INTO v_Currency_ID,
carlos@0
   186
          v_IsTaxIncluded
carlos@0
   187
        FROM M_PRICELIST
carlos@0
   188
        WHERE M_PriceList_ID=Cur_Outs.M_PriceList_ID;
carlos@0
   189
        --
carlos@0
   190
        DBMS_OUTPUT.PUT_LINE('  Invoice_ID=' || v_Invoice_ID || ' DocumentNo=' || v_DocumentNo) ;
carlos@0
   191
        v_ResultStr:='InsertInvoice ' || v_Invoice_ID;
carlos@0
   192
        INSERT
carlos@0
   193
        INTO C_INVOICE
carlos@0
   194
          (
carlos@0
   195
            C_INVOICE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
carlos@0
   196
            CREATED, CREATEDBY, UPDATED, UPDATEDBY,
carlos@0
   197
            ISSOTRX, DOCUMENTNO, DOCSTATUS, DOCACTION,
carlos@0
   198
            PROCESSING, PROCESSED, POSTED, C_DOCTYPE_ID,
asier@799
   199
            C_DOCTYPETARGET_ID, C_ORDER_ID, DESCRIPTION,
carlos@1259
   200
            ISPRINTED, SALESREP_ID, DATEINVOICED, TAXDATE,
carlos@0
   201
            DATEPRINTED, DATEACCT, C_BPARTNER_ID, C_BPARTNER_LOCATION_ID,
carlos@0
   202
            POREFERENCE, ISDISCOUNTPRINTED, DATEORDERED, C_CURRENCY_ID,
carlos@0
   203
            PAYMENTRULE, C_PAYMENTTERM_ID, C_CHARGE_ID, CHARGEAMT,
carlos@0
   204
            TOTALLINES, GRANDTOTAL, M_PRICELIST_ID, ISTAXINCLUDED,
asier@799
   205
            C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID,
asier@799
   206
            CREATEFROM, GENERATETO, AD_USER_ID,
carlos@0
   207
            COPYFROM, ISSELFSERVICE
carlos@0
   208
          )
carlos@0
   209
          VALUES
carlos@0
   210
          (
carlos@0
   211
            v_Invoice_ID, Cur_Outs.AD_Client_ID, Cur_Outs.AD_Org_ID, 'Y',
antonio@735
   212
            now(), v_User_ID, now(), v_User_ID,
carlos@0
   213
             'N', v_DocumentNo, 'DR', 'CO',
carlos@0
   214
             'N', 'N', 'N', 0,
asier@799
   215
            v_DocType_ID, NULL, NULL,
carlos@1259
   216
            'N', NULL, v_DateInvoiced, v_DateInvoiced,
carlos@0
   217
            NULL, v_DateInvoiced, v_BPartner_ID, v_BPLocation_ID,
carlos@0
   218
            v_ReferenceNo, 'Y', NULL, v_Currency_ID,
carlos@0
   219
            v_PaymentRule, v_PaymentTerm_ID, NULL, 0,
carlos@0
   220
            0, 0, Cur_Outs.M_PriceList_ID, v_IsTaxIncluded,
asier@799
   221
            NULL, v_Project_ID, NULL,
asier@799
   222
             'N', 'N', NULL,
carlos@0
   223
             'N', 'N'
carlos@0
   224
          )
carlos@0
   225
          ;
carlos@0
   226
      END IF;
carlos@0
   227
      v_auxQtyTotal:=0;
carlos@0
   228
      SELECT MAX(PRICELIST), MAX(PRICESTD),  MAX(PRICELIMIT)
carlos@0
   229
      INTO v_priceList, v_priceActual,  v_priceLimit
carlos@0
   230
      FROM M_PRODUCTPRICE
carlos@0
   231
      WHERE M_PriceList_Version_ID=
carlos@0
   232
        (SELECT MIN(M_PriceList_Version_ID)
carlos@0
   233
        FROM M_PRICELIST_VERSION
carlos@0
   234
        WHERE M_PriceList_ID=Cur_Outs.M_PriceList_ID
carlos@0
   235
        )
carlos@0
   236
        AND M_Product_ID=Cur_Outs.M_Product_ID;
carlos@0
   237
      v_Tax_ID:=C_Gettax(Cur_Outs.M_Product_ID, v_DateInvoiced, Cur_Outs.AD_Org_ID, v_Warehouse_ID, v_BPLocation_ID, v_BPLocation_ID, v_Project_ID, 'N') ;
carlos@0
   238
      FOR Cur_Pend IN
carlos@0
   239
        (SELECT dl.M_INOUTLINE_ID,
carlos@0
   240
          ol.C_ORDERLINE_ID,
carlos@0
   241
          (dl.MovementQty - COALESCE(A.QTY, 0)) AS qty
carlos@0
   242
        FROM M_INOUTLINE dl
carlos@0
   243
        LEFT JOIN C_ORDERLINE ol
carlos@0
   244
          ON dl.C_OrderLine_ID=ol.C_OrderLine_ID
carlos@0
   245
        LEFT JOIN C_ORDER o
carlos@0
   246
          ON ol.C_Order_ID=o.C_Order_ID
carlos@0
   247
        LEFT JOIN
carlos@0
   248
          (SELECT M_InOutLine_ID,
carlos@0
   249
            COALESCE(SUM(QTY), 0) AS QTY
carlos@0
   250
          FROM M_MATCHINV
carlos@0
   251
          WHERE C_InvoiceLine_ID IS NOT NULL
carlos@0
   252
          GROUP BY M_InOutLine_ID
carlos@0
   253
          )
carlos@0
   254
          A
carlos@0
   255
          ON dl.M_InOutLine_ID=A.M_InOutLine_ID,
carlos@0
   256
          M_INOUT d
carlos@0
   257
        WHERE d.M_InOut_ID=dl.M_InOut_ID
carlos@0
   258
          AND d.IsSOTrx='N'
gorkaion@239
   259
          AND dl.MovementQty<>COALESCE(A.QTY, 0)
carlos@0
   260
          AND d.C_BPartner_ID=v_BPartner_ID
carlos@0
   261
          AND dl.M_Product_ID=Cur_Outs.M_Product_ID
carlos@0
   262
          AND(dl.M_ATTRIBUTESETInstance_ID=Cur_Outs.M_AttributeSetInstance_ID
carlos@0
   263
          OR Cur_Outs.M_AttributeSetInstance_ID IS NULL)
carlos@0
   264
        ORDER BY d.MOVEMENTDATE,
carlos@0
   265
          d.M_InOut_ID
carlos@0
   266
        )
carlos@0
   267
      LOOP
carlos@0
   268
        v_auxQty:=LEAST(Cur_Outs.MovementQty-v_auxQtyTotal, Cur_Pend.qty) ;
carlos@0
   269
        v_auxQtyTotal:=v_auxQtyTotal + v_auxQty;
carlos@0
   270
        v_line:=v_line + 10;
carlos@0
   271
        Ad_Sequence_Next('C_InvoiceLine', Cur_Outs.AD_Client_ID, v_InvoiceLine_ID) ;
carlos@0
   272
        INSERT
carlos@0
   273
        INTO C_INVOICELINE
carlos@0
   274
          (
carlos@0
   275
            C_INVOICELINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
carlos@0
   276
            CREATED, CREATEDBY, UPDATED, UPDATEDBY,
carlos@0
   277
            C_INVOICE_ID, C_ORDERLINE_ID, M_INOUTLINE_ID, LINE,
carlos@0
   278
            DESCRIPTION, M_PRODUCT_ID, QTYINVOICED,
carlos@0
   279
   PRICELIST, PRICEACTUAL,
carlos@0
   280
   PRICELIMIT, LINENETAMT,
carlos@0
   281
   C_CHARGE_ID, CHARGEAMT, C_UOM_ID, C_TAX_ID, S_RESOURCEASSIGNMENT_ID,
asier@799
   282
            TAXAMT, M_ATTRIBUTESETINSTANCE_ID, ISDESCRIPTION,
carlos@0
   283
            QUANTITYORDER, M_PRODUCT_UOM_ID, PriceStd
carlos@0
   284
          )
carlos@0
   285
          VALUES
carlos@0
   286
          (
carlos@0
   287
            v_InvoiceLine_ID, Cur_Outs.AD_Client_ID, Cur_Outs.AD_Org_ID, 'Y',
antonio@735
   288
            now(), v_User_ID, now(), v_User_ID,
carlos@0
   289
            v_Invoice_ID, Cur_Pend.C_OrderLine_ID, Cur_Pend.M_InOutLine_ID,
carlos@0
   290
            v_line, NULL, Cur_Outs.M_Product_ID, v_auxQty,
carlos@0
   291
            v_priceList, M_Get_Offers_Price(v_DateInvoiced, v_BPartner_ID, Cur_Outs.M_Product_ID, v_priceActual, v_auxQty, Cur_Outs.M_PriceList_ID),
carlos@0
   292
   v_priceLimit, ROUND(M_Get_Offers_Price(v_DateInvoiced, v_BPartner_ID, Cur_Outs.M_Product_ID, v_priceActual, v_auxQty, Cur_Outs.M_PriceList_ID) *v_auxQty, 2),
carlos@0
   293
            NULL, 0, Cur_Outs.C_UOM_ID, v_Tax_ID, NULL,
asier@799
   294
            0, Cur_Outs.M_AttributeSetInstance_ID, 'N',
carlos@0
   295
            Cur_Outs.quantityOrder*(v_auxQty/Cur_Outs.MovementQty), Cur_Outs.M_Product_UOM_ID, v_priceActual
carlos@0
   296
          )
carlos@0
   297
          ;
gorkaion@239
   298
        IF(v_auxQtyTotal>=Cur_Outs.MovementQty) THEN
carlos@0
   299
          EXIT;
carlos@0
   300
        END IF;
carlos@0
   301
      END LOOP;
gorkaion@239
   302
      IF(v_auxQtyTotal<Cur_Outs.MovementQty) THEN
carlos@0
   303
        v_line:=v_line + 10;
carlos@0
   304
        v_auxQty:=Cur_Outs.MovementQty - v_auxQtyTotal;
carlos@0
   305
        Ad_Sequence_Next('C_InvoiceLine', Cur_Outs.AD_Client_ID, v_InvoiceLine_ID) ;
carlos@0
   306
        INSERT
carlos@0
   307
        INTO C_INVOICELINE
carlos@0
   308
          (
carlos@0
   309
            C_INVOICELINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
carlos@0
   310
            CREATED, CREATEDBY, UPDATED, UPDATEDBY,
carlos@0
   311
            C_INVOICE_ID, C_ORDERLINE_ID, M_INOUTLINE_ID, LINE,
carlos@0
   312
            DESCRIPTION, M_PRODUCT_ID, QTYINVOICED, PRICELIST,
carlos@0
   313
            PRICEACTUAL, PRICELIMIT,
carlos@0
   314
   LINENETAMT, C_CHARGE_ID,
carlos@0
   315
            CHARGEAMT, C_UOM_ID, C_TAX_ID, S_RESOURCEASSIGNMENT_ID,
asier@799
   316
            TAXAMT, M_ATTRIBUTESETINSTANCE_ID, ISDESCRIPTION,
carlos@0
   317
            QUANTITYORDER, M_PRODUCT_UOM_ID, PriceStd
carlos@0
   318
          )
carlos@0
   319
          VALUES
carlos@0
   320
          (
carlos@0
   321
            v_InvoiceLine_ID, Cur_Outs.AD_Client_ID, Cur_Outs.AD_Org_ID, 'Y',
antonio@735
   322
            now(), v_User_ID, now(), v_User_ID,
carlos@0
   323
            v_Invoice_ID, NULL, NULL, v_line,
carlos@0
   324
            NULL, Cur_Outs.M_Product_ID, v_auxQty, v_priceList,
carlos@0
   325
            M_Get_Offers_Price(v_DateInvoiced, v_BPartner_ID, Cur_Outs.M_Product_ID, v_priceActual, v_auxQty, Cur_Outs.M_PriceList_ID), v_priceLimit,
carlos@0
   326
   ROUND(M_Get_Offers_Price(v_DateInvoiced, v_BPartner_ID, Cur_Outs.M_Product_ID, v_priceActual, v_auxQty, Cur_Outs.M_PriceList_ID) *v_auxQty, 2), NULL,
carlos@0
   327
            0, Cur_Outs.C_UOM_ID, v_Tax_ID, NULL,
asier@799
   328
            0, Cur_Outs.M_AttributeSetInstance_ID, 'N',
carlos@0
   329
            Cur_Outs.quantityOrder*(v_auxQty/Cur_Outs.MovementQty), Cur_Outs.M_Product_UOM_ID, v_priceActual
carlos@0
   330
          )
carlos@0
   331
          ;
carlos@0
   332
      END IF;
carlos@0
   333
    END LOOP;
gorkaion@239
   334
    --<<FINISH_PROCESS>>
carlos@0
   335
    v_Message:=v_Message || '@Created@: ' || v_NoRecords;
carlos@0
   336
    --  Update AD_PInstance
carlos@0
   337
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
antonio@735
   338
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 1, v_Message) ;
carlos@0
   339
    RETURN;
carlos@0
   340
  END; --BODY
carlos@0
   341
EXCEPTION
carlos@0
   342
WHEN OTHERS THEN
carlos@0
   343
  v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
   344
  DBMS_OUTPUT.PUT_LINE(v_Message) ;
carlos@0
   345
  ROLLBACK;
antonio@735
   346
  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_Message) ;
antonio@735
   347
END C_CREATE_PINVOICE_FROM_OUTS
gorkaion@239
   348
]]></body>
adrian@94
   349
    </function>
adrian@94
   350
  </database>