src-db/database/model/functions/GENERATEPOFROMPROJECT.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 1535 df3c4c5c3d0d
permissions -rw-r--r--
Merge r2.5x intro trunk
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION GENERATEPOFROMPROJECT">
adrian@94
     3
    <function name="GENERATEPOFROMPROJECT" type="NULL">
juanpablo@1605
     4
      <parameter name="p_pinstance_id" type="VARCHAR" 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
rafael@615
    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
  v_ResultStr VARCHAR2(2000):='';
carlos@0
    24
  v_Message VARCHAR2(2000):='';
carlos@0
    25
  v_Result NUMBER:=1; -- 0=failure
juanpablo@1605
    26
  v_Record_ID VARCHAR2(32);
juanpablo@1605
    27
  v_AD_User_ID VARCHAR2(32);
carlos@0
    28
  TYPE RECORD IS REF CURSOR;
carlos@0
    29
    Cur_Parameter RECORD;
juanpablo@1605
    30
    v_C_Order_ID VARCHAR2(32);
juanpablo@1605
    31
    v_C_OrderLine_ID VARCHAR2(32);
juanpablo@1605
    32
    v_C_DOCTYPE_ID VARCHAR2(32);
carlos@0
    33
    v_DocumentNo NVARCHAR2(30) ;
carlos@0
    34
  BEGIN
carlos@0
    35
    --  Update AD_PInstance
carlos@0
    36
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
carlos@0
    37
    v_ResultStr:='PInstanceNotFound';
carlos@0
    38
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
carlos@0
    39
  BEGIN --BODY
carlos@0
    40
    -- Get PARAMETERS
carlos@0
    41
    v_ResultStr:='ReadingParameters';
carlos@0
    42
    FOR Cur_Parameter IN
carlos@0
    43
      (SELECT i.Record_ID,
carlos@0
    44
        i.AD_User_ID,
carlos@0
    45
        i.AD_Client_ID,
carlos@0
    46
        i.AD_Org_ID,
carlos@0
    47
        p.ParameterName,
carlos@0
    48
        p.P_String,
carlos@0
    49
        p.P_Number,
carlos@0
    50
        p.P_Date,
carlos@0
    51
        p.P_Date_To
carlos@0
    52
      FROM AD_PInstance i
carlos@0
    53
      LEFT JOIN AD_PInstance_Para p
carlos@0
    54
        ON i.AD_PInstance_ID=p.AD_PInstance_ID
carlos@0
    55
      WHERE i.AD_PInstance_ID=p_PInstance_ID
carlos@0
    56
      ORDER BY p.SeqNo
carlos@0
    57
      )
carlos@0
    58
    LOOP
carlos@0
    59
      v_Record_ID:=Cur_Parameter.Record_ID;
carlos@0
    60
      v_AD_User_ID:=Cur_Parameter.AD_User_ID;
carlos@0
    61
    END LOOP; -- Get Parameter
carlos@0
    62
    DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID) ;
carlos@0
    63
    DECLARE
juanpablo@1605
    64
      v_BPartner_Location_ID VARCHAR2(32);
juanpablo@1605
    65
      v_BillTo_ID VARCHAR2(32);
rafael@615
    66
      v_Size NUMBER;
rafael@615
    67
      v_UOM NUMBER;
rafael@615
    68
      v_PriceStd NUMBER;
rafael@615
    69
      v_PriceList NUMBER;
rafael@615
    70
      v_PriceLimit NUMBER;
juanpablo@1605
    71
      v_C_UOM_ID VARCHAR2(32);
juanpablo@1605
    72
      v_C_Currency_ID VARCHAR2(32);
rafael@615
    73
      v_PriceActual NUMBER;
rafael@615
    74
      v_Discount NUMBER;
juanpablo@1605
    75
      v_Tax_ID VARCHAR2(32);
juanpablo@1605
    76
      v_M_PriceList_Version_ID VARCHAR2(32);
antonio@737
    77
carlos@0
    78
    TYPE RECORD IS REF CURSOR;
carlos@0
    79
      Cur_SO RECORD;
rafael@615
    80
      Cur_SOLINES RECORD;
carlos@0
    81
    BEGIN
carlos@0
    82
      v_ResultStr:='StartLoop';
carlos@0
    83
      FOR Cur_SO IN
carlos@0
    84
        (SELECT P.C_PROJECT_ID,
carlos@0
    85
          P.PROJECTSTATUS,
carlos@0
    86
          V.AD_CLIENT_ID,
carlos@0
    87
          V.AD_ORG_ID,
carlos@0
    88
          V.C_BPARTNER_ID,
carlos@0
    89
          V.C_INCOTERMS_ID,
carlos@0
    90
          V.C_PROJECT_VENDOR_ID,
carlos@0
    91
          V.INCOTERMS_DESCRIPTION,
carlos@0
    92
          V.M_PRICELIST_VERSION_ID,
carlos@0
    93
          V.M_PRICELIST_ID,
carlos@0
    94
          P.C_CAMPAIGN_ID,
carlos@0
    95
          PL.C_CURRENCY_ID,
rafael@1535
    96
	  	  P.C_CURRENCY_ID AS PROJCURRENCY,
carlos@0
    97
          BP.PAYMENTRULEPO AS PAYMENTRULE,
carlos@0
    98
          BP.PO_PAYMENTTERM_ID AS C_PAYMENTTERM_ID,
carlos@0
    99
          P.M_WAREHOUSE_ID,
carlos@0
   100
          P.POREFERENCE,
rafael@615
   101
          P.SALESREP_ID,
rafael@615
   102
          P.CREATETEMPPRICELIST,
rafael@615
   103
          P.DESCRIPTION
carlos@0
   104
        FROM C_PROJECT P,
carlos@0
   105
          C_PROJECT_VENDOR V,
carlos@0
   106
          C_BPARTNER BP,
carlos@0
   107
          M_PRICELIST PL
carlos@0
   108
        WHERE P.C_PROJECT_ID=V.C_PROJECT_ID
carlos@0
   109
          AND V.C_BPARTNER_ID=BP.C_BPARTNER_ID
carlos@0
   110
          AND V.M_PRICELIST_ID=PL.M_PRICELIST_ID
carlos@0
   111
          AND V.ISACTIVE='Y'
carlos@0
   112
          AND V.C_PROJECT_VENDOR_ID=v_Record_ID
carlos@0
   113
        )
carlos@0
   114
      LOOP
carlos@0
   115
        -- Check that we have some restrictions
carlos@0
   116
        v_ResultStr:='CheckRestriction';
gorkaion@239
   117
        IF(Cur_SO.PROJECTSTATUS IS NULL OR Cur_SO.PROJECTSTATUS<>'OR') THEN
rafael@615
   118
         RAISE_APPLICATION_ERROR(-20000, '@Invalidprojectstatus@'||'. '||' @ChangeToOrder@'||'.');
rafael@615
   119
        ELSIF Cur_SO.C_BPARTNER_ID IS NULL THEN
antonio@735
   120
          RAISE_APPLICATION_ERROR(-20000, '@NoprojectBusinesspartner@');
rafael@615
   121
        ELSIF Cur_SO.C_PAYMENTTERM_ID IS NULL THEN
rafael@615
   122
          RAISE_APPLICATION_ERROR(-20000, '@ThebusinessPartner@'||' '||' @PaymenttermNotdefined@'||'.');
rafael@615
   123
        ELSIF Cur_SO.M_PRICELIST_ID IS NULL THEN
rafael@615
   124
          RAISE_APPLICATION_ERROR(-20000, '@ThebusinessPartner@'||' '||' @PricelistNotdefined@'||'.');
rafael@615
   125
        ELSIF Cur_SO.C_CURRENCY_ID IS NULL THEN
rafael@615
   126
          RAISE_APPLICATION_ERROR(-20000, '@ProjectCurrencyNotFound@'||'.');
rafael@615
   127
        ELSIF Cur_SO.M_WAREHOUSE_ID IS NULL THEN
rafael@615
   128
          RAISE_APPLICATION_ERROR(-20000, '@ProjectWarehouseNotFound@'||'.');
rafael@615
   129
        ELSIF Cur_SO.SALESREP_ID IS NULL THEN
rafael@615
   130
          RAISE_APPLICATION_ERROR(-20000, '@ProjectSalesRepNotFound@'||'.');
carlos@0
   131
        END IF;
antonio@737
   132
carlos@0
   133
        v_C_DOCTYPE_ID:=Ad_Get_DocType(Cur_SO.AD_Client_ID, Cur_SO.AD_Org_ID, 'POO') ;
carlos@0
   134
        AD_Sequence_DocType(v_C_DOCTYPE_ID, Cur_SO.AD_Client_ID, 'Y', v_DocumentNo) ;
carlos@0
   135
        IF(v_DocumentNo IS NULL) THEN
carlos@0
   136
          AD_Sequence_Doc('DocumentNo_C_Order', Cur_SO.AD_Client_ID, 'Y', v_DocumentNo) ;
carlos@0
   137
        END IF;
antonio@737
   138
rafael@615
   139
        -- Get Business Partner Ship Location
rafael@615
   140
        v_BPartner_Location_ID := C_GetBPLocationID(Cur_SO.C_BPartner_ID, 'S') ;
rafael@615
   141
        IF (v_BPartner_Location_ID IS NULL) THEN
rafael@615
   142
          RAISE_APPLICATION_ERROR(-20000, '@ThebusinessPartner@'||' '||' @ShiptoNotdefined@'||'.');
rafael@615
   143
        END IF;
antonio@737
   144
rafael@615
   145
        -- Get Business Partner Bill Location
rafael@615
   146
        v_Billto_ID := C_GetBPLocationID(Cur_SO.C_BPartner_ID, 'B') ;
rafael@615
   147
        IF (v_Billto_ID IS NULL) THEN
rafael@615
   148
          RAISE_APPLICATION_ERROR(-20000, '@ThebusinessPartner@'||' '||' @BillToNotdefined@'||'.');
rafael@615
   149
        END IF;
antonio@737
   150
rafael@615
   151
        -- Get next C_Order_ID
rafael@615
   152
        Ad_Sequence_Next('C_Order', Cur_SO.AD_CLIENT_ID, v_C_Order_ID) ;
rafael@615
   153
        v_ResultStr:='C_ORDER_ID - ' || v_C_Order_ID;
antonio@737
   154
carlos@0
   155
        INSERT
carlos@0
   156
        INTO C_ORDER
carlos@0
   157
          (
carlos@0
   158
            C_ORDER_ID, AD_CLIENT_ID, AD_ORG_ID, CREATEDBY,
carlos@0
   159
            UPDATEDBY, ISSOTRX, DOCUMENTNO, DOCSTATUS,
carlos@0
   160
            DOCACTION, C_DOCTYPE_ID, C_DOCTYPETARGET_ID, DATEORDERED,
carlos@0
   161
            DATEACCT, C_BPARTNER_ID, C_BPARTNER_LOCATION_ID, ISDISCOUNTPRINTED,
carlos@0
   162
            C_CURRENCY_ID, PAYMENTRULE, C_PAYMENTTERM_ID, INVOICERULE,
carlos@0
   163
            DELIVERYRULE, FREIGHTCOSTRULE, DELIVERYVIARULE, PRIORITYRULE,
carlos@0
   164
            TOTALLINES, GRANDTOTAL, M_WAREHOUSE_ID, M_PRICELIST_ID,
carlos@0
   165
            ISTAXINCLUDED, POSTED, PROCESSING, SALESREP_ID,
carlos@0
   166
            BILLTO_ID, POREFERENCE, C_CAMPAIGN_ID, C_PROJECT_ID,
carlos@0
   167
            AD_USER_ID, COPYFROM, C_INCOTERMS_ID, INCOTERMSDESCRIPTION,
rafael@615
   168
            DATEPROMISED, DESCRIPTION
carlos@0
   169
          )
carlos@0
   170
          VALUES
carlos@0
   171
          (
carlos@0
   172
            v_C_Order_ID, Cur_SO.AD_CLIENT_ID, Cur_SO.AD_ORG_ID, v_AD_User_ID,
carlos@0
   173
            v_AD_User_ID, 'N', v_DocumentNo, 'DR',
juanpablo@1605
   174
             'CO', '0', v_C_DOCTYPE_ID, TRUNC(now(), 'DD'),
carlos@0
   175
            TRUNC(now(), 'DD'), Cur_SO.C_BPARTNER_ID, v_BPartner_Location_ID, 'N',
carlos@0
   176
            Cur_SO.C_CURRENCY_ID, COALESCE(Cur_SO.PAYMENTRULE, 'P'), Cur_SO.C_PAYMENTTERM_ID, 'D',
carlos@0
   177
             'A', 'I', 'D', '5',
carlos@0
   178
            0, 0, Cur_SO.M_WAREHOUSE_ID, Cur_SO.M_PRICELIST_ID,
carlos@0
   179
             'N', 'N', 'N', Cur_SO.SALESREP_ID,
carlos@0
   180
            v_BillTo_ID, Cur_SO.POREFERENCE, Cur_SO.C_CAMPAIGN_ID, Cur_SO.C_PROJECT_ID,
carlos@0
   181
            NULL, 'N', Cur_SO.C_INCOTERMS_ID, Cur_SO.INCOTERMS_DESCRIPTION,
rafael@615
   182
            TRUNC(now(), 'DD'), Cur_SO.DESCRIPTION
carlos@0
   183
          )
carlos@0
   184
          ;
antonio@737
   185
rafael@615
   186
        -- Select the price list version that a applies for the price list of the header
antonio@735
   187
        SELECT Get_Pricelist_Version(Cur_SO.M_PriceList_ID, TRUNC(now(), 'DD'))
rafael@615
   188
        INTO v_M_PriceList_Version_ID
antonio@737
   189
        FROM DUAL;
rafael@615
   190
        IF (v_M_PriceList_Version_ID IS NULL) THEN
rafael@615
   191
          RAISE_APPLICATION_ERROR(-20000, '@PriceListVersionNotFound@'||'.');
antonio@737
   192
        ELSE
rafael@615
   193
         -- Select products, quantities, sequence numbers, descriptions and unit prices of the project
rafael@615
   194
            -- In both cases, if no unit price has been defined for a product,
rafael@615
   195
            -- price is taken from the price list of the project.
rafael@615
   196
            -- And if no price is defined in the price list, price is set to 0.
rafael@615
   197
          FOR Cur_SOLINES IN
rafael@615
   198
            (
antonio@737
   199
            SELECT pl.LINE AS SEQNO, pl.PRODUCT_DESCRIPTION AS DESCRIPTION, pl.M_PRODUCT_ID,
rafael@615
   200
              pl.PLANNEDQTY AS QTY, pl.PLANNEDPOPRICE AS PRICEACTUAL, pl.C_TAX_ID
rafael@615
   201
            FROM C_PROJECTLINE pl, C_PROJECT_VENDOR  pv
rafael@615
   202
            WHERE pv.C_PROJECT_VENDOR_ID = v_Record_ID
rafael@615
   203
              AND pl.C_PROJECT_ID = pv.C_PROJECT_ID
rafael@615
   204
              AND pl.M_Product_ID IS NOT NULL
rafael@615
   205
              AND pl.IsActive = 'Y'
rafael@615
   206
            ORDER BY SEQNO ASC
rafael@615
   207
            )
antonio@737
   208
          LOOP
antonio@737
   209
rafael@615
   210
            -- Take StdPrice, PriceList and PriceLimit from Price List Version
rafael@615
   211
            SELECT COUNT(*)
rafael@615
   212
            INTO v_Size
rafael@615
   213
            FROM M_PRODUCT p,M_PRODUCTPRICE pp,M_PRICELIST_VERSION pv,M_PRICELIST pl
rafael@615
   214
            WHERE p.M_Product_ID=pp.M_Product_ID
rafael@615
   215
              AND pp.M_PriceList_Version_ID=pv.M_PriceList_Version_ID
rafael@615
   216
              AND pv.M_PriceList_ID=pl.M_PriceList_ID
rafael@615
   217
              AND pv.IsActive='Y'
rafael@615
   218
              AND p.M_Product_ID=Cur_SOLINES.M_PRODUCT_ID
rafael@615
   219
              AND pv.M_PriceList_Version_ID=v_M_PriceList_Version_ID
rafael@615
   220
              AND pl.C_Currency_ID=Cur_SO.C_CURRENCY_ID;
antonio@737
   221
            IF (v_Size>0) THEN
rafael@615
   222
              SELECT Bom_Pricestd(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceStd,
rafael@615
   223
                Bom_Pricelist(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceList,
rafael@615
   224
                Bom_Pricelimit(p.M_Product_ID, pv.M_PriceList_Version_ID) AS PriceLimit,
rafael@615
   225
                p.C_UOM_ID
rafael@615
   226
              INTO v_PriceStd,v_PriceList,
rafael@615
   227
                v_PriceLimit,v_C_UOM_ID
rafael@615
   228
              FROM M_PRODUCT p,M_PRODUCTPRICE pp,M_PRICELIST_VERSION pv,M_PRICELIST pl
rafael@615
   229
              WHERE p.M_Product_ID=pp.M_Product_ID
rafael@615
   230
                AND pp.M_PriceList_Version_ID=pv.M_PriceList_Version_ID
rafael@615
   231
                AND pv.M_PriceList_ID=pl.M_PriceList_ID
rafael@615
   232
                AND pv.IsActive='Y'
rafael@615
   233
                AND p.M_Product_ID=Cur_SOLINES.M_PRODUCT_ID
rafael@615
   234
                AND pv.M_PriceList_Version_ID=v_M_PriceList_Version_ID
rafael@615
   235
                AND pl.C_Currency_ID=Cur_SO.C_CURRENCY_ID;
rafael@615
   236
            ELSE
rafael@615
   237
              v_PriceStd := NULL;
rafael@615
   238
              v_PriceList := NULL;
rafael@615
   239
              v_PriceLimit := NULL;
rafael@615
   240
              v_C_UOM_ID := NULL;
rafael@615
   241
            END IF;
antonio@737
   242
rafael@615
   243
            -- Calculate Price Actual
rafael@615
   244
            IF (Cur_SOLINES.priceactual=0) THEN
rafael@615
   245
              Cur_SOLINES.priceactual:=NULL;
rafael@615
   246
            END IF;
antonio@737
   247
            v_PriceActual := COALESCE(Cur_SOLINES.priceactual,M_Get_Offers_Price(now(), Cur_SO.C_BPARTNER_ID, Cur_SOLINES.M_PRODUCT_ID, v_PriceStd, Cur_SOLINES.Qty, Cur_SO.M_PRICELIST_ID),0);
antonio@737
   248
rafael@615
   249
            IF (v_PriceStd IS NULL) THEN
rafael@615
   250
             v_PriceStd :=  v_PriceActual ;
rafael@615
   251
            END IF;
antonio@737
   252
rafael@615
   253
            IF (v_PriceList IS NULL) THEN
rafael@615
   254
              v_PriceList :=  v_PriceActual ;
rafael@615
   255
            END IF;
antonio@737
   256
rafael@615
   257
            IF (v_PriceLimit IS NULL) THEN
rafael@615
   258
              v_PriceLimit :=  v_PriceActual ;
rafael@615
   259
            END IF;
antonio@737
   260
rafael@1535
   261
	        -- Make currency conversion if project header's currency (hence, project lines currency) is different from supplier's price list currency
rafael@1535
   262
            IF (Cur_SO.C_CURRENCY_ID != Cur_SO.PROJCURRENCY) THEN
rafael@1535
   263
              v_PriceActual := COALESCE(C_Currency_Convert(v_PriceActual, Cur_SO.PROJCURRENCY, Cur_SO.C_CURRENCY_ID, now(), NULL, Cur_SO.AD_CLIENT_ID, Cur_SO.AD_ORG_ID),0);
rafael@1535
   264
	          v_PriceStd := COALESCE(C_Currency_Convert(v_PriceStd, Cur_SO.PROJCURRENCY, Cur_SO.C_CURRENCY_ID, now(), NULL, Cur_SO.AD_CLIENT_ID, Cur_SO.AD_ORG_ID),0);
rafael@1535
   265
              v_PriceList := COALESCE(C_Currency_Convert(v_PriceList, Cur_SO.PROJCURRENCY, Cur_SO.C_CURRENCY_ID, now(), NULL, Cur_SO.AD_CLIENT_ID, Cur_SO.AD_ORG_ID),0);
rafael@1535
   266
              v_PriceLimit := COALESCE(C_Currency_Convert(v_PriceLimit, Cur_SO.PROJCURRENCY, Cur_SO.C_CURRENCY_ID, now(), NULL, Cur_SO.AD_CLIENT_ID, Cur_SO.AD_ORG_ID),0);
rafael@1535
   267
	        END IF;
rafael@1535
   268
rafael@1535
   269
	        -- Calculating the discount
rafael@1535
   270
	        IF (v_PriceList = 0) THEN
rafael@615
   271
               v_Discount := 0 ;
rafael@615
   272
            ELSE
rafael@615
   273
              -- Calculate rounded discount
rafael@615
   274
              v_Discount :=ROUND((v_PriceList-v_PriceActual) / v_PriceList*100, 2);
rafael@615
   275
            END IF;
antonio@737
   276
rafael@615
   277
            IF (v_C_UOM_ID IS NULL) THEN
rafael@615
   278
              SELECT P.C_UOM_ID
rafael@615
   279
              INTO v_UOM
rafael@615
   280
              FROM M_PRODUCT P
rafael@615
   281
              WHERE P.M_PRODUCT_ID=Cur_SOLINES.M_PRODUCT_ID;
rafael@615
   282
            ELSE
rafael@615
   283
              v_UOM := v_C_UOM_ID;
rafael@615
   284
            END IF;
antonio@737
   285
rafael@615
   286
            IF (Cur_SOLINES.C_TAX_ID IS NULL) THEN
antonio@735
   287
              v_Tax_ID:= C_Gettax(Cur_SOLINES.M_PRODUCT_ID, TRUNC(now(), 'DD'), Cur_SO.AD_ORG_ID, Cur_SO.M_WAREHOUSE_ID, v_BPartner_Location_ID, v_BPartner_Location_ID, Cur_SO.C_PROJECT_ID, 'Y') ;
rafael@615
   288
            ELSE
rafael@615
   289
              v_Tax_ID:=Cur_SOLINES.C_TAX_ID;
rafael@615
   290
            END IF;
antonio@737
   291
rafael@615
   292
            -- Get next C_OrderLine_ID
rafael@615
   293
            Ad_Sequence_Next('C_OrderLine', Cur_SO.AD_CLIENT_ID, v_C_OrderLine_ID) ;
rafael@615
   294
            v_ResultStr:='C_OrderLine_ID - ' || v_C_OrderLine_ID;
antonio@737
   295
rafael@615
   296
            INSERT
rafael@615
   297
            INTO C_ORDERLINE
rafael@615
   298
              (
rafael@615
   299
                DateOrdered, M_Warehouse_ID, QtyOrdered, QtyDelivered,
asier@799
   300
                QtyReserved, M_Shipper_ID, QtyInvoiced,
rafael@615
   301
                C_Currency_ID, PriceList, DatePromised, DateDelivered,
rafael@615
   302
                DateInvoiced, Created, IsActive, Line,
rafael@615
   303
                C_OrderLine_ID, AD_Client_ID, C_Order_ID, Description,
rafael@615
   304
                M_Product_ID, C_UOM_ID, DirectShip, CreatedBy,
rafael@615
   305
                UpdatedBy, FreightAmt, C_Charge_ID, ChargeAmt,
rafael@615
   306
                Updated, AD_Org_ID, S_ResourceAssignment_ID, C_BPartner_ID,
rafael@615
   307
                PriceActual,
asier@799
   308
                C_Tax_ID, C_BPartner_Location_ID,
rafael@615
   309
                Discount, PriceLimit, Ref_OrderLine_ID, LineNetAmt,
rafael@615
   310
                M_AttributeSetInstance_ID, IsDescription, PriceStd
rafael@615
   311
              )
rafael@615
   312
              VALUES
rafael@615
   313
              (
antonio@735
   314
                TRUNC(now(), 'DD'), Cur_SO.M_WAREHOUSE_ID, Cur_SOLINES.Qty, 0,
asier@799
   315
                0, NULL, 0,
antonio@735
   316
                Cur_SO.C_CURRENCY_ID, v_PriceList, TRUNC(now(), 'DD'), NULL,
antonio@735
   317
                NULL, now(), 'Y', Cur_SOLINES.SEQNO,
rafael@615
   318
                v_C_OrderLine_ID, Cur_SO.AD_CLIENT_ID, v_C_Order_ID, Cur_SOLINES.DESCRIPTION,
rafael@615
   319
                Cur_SOLINES.M_PRODUCT_ID, v_UOM, 'N', v_AD_User_ID,
rafael@615
   320
                v_AD_User_ID, 0, NULL, 0,
antonio@735
   321
                now(), Cur_SO.AD_ORG_ID, NULL, Cur_SO.C_BPARTNER_ID,
rafael@615
   322
                v_PriceActual,
asier@799
   323
                v_Tax_ID, v_BPartner_Location_ID,
rafael@615
   324
                v_Discount, v_PriceLimit, NULL, v_PriceActual * Cur_SOLINES.Qty,
rafael@615
   325
                NULL, 'N', v_PriceStd
rafael@615
   326
              )
antonio@737
   327
              ;
rafael@615
   328
          END LOOP;
rafael@615
   329
        END IF;
antonio@737
   330
carlos@0
   331
        IF v_Message IS NOT NULL THEN
carlos@0
   332
          v_Message:=v_Message || ', ';
carlos@0
   333
        END IF;
carlos@0
   334
        v_Message:=v_Message || v_DocumentNo;
carlos@0
   335
      END LOOP;
carlos@0
   336
      v_Message:='@DocumentNo@: ' || v_Message;
carlos@0
   337
    END;
gorkaion@239
   338
    --<<FINISH_PROCESS>>
carlos@0
   339
    --  Update AD_PInstance
carlos@0
   340
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
carlos@0
   341
    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', v_Result, v_Message) ;
carlos@0
   342
    RETURN;
carlos@0
   343
  END; --BODY
carlos@0
   344
EXCEPTION
carlos@0
   345
WHEN OTHERS THEN
carlos@0
   346
  v_ResultStr:= '@ERROR=' || SQLERRM;
carlos@0
   347
  DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
carlos@0
   348
  ROLLBACK;
carlos@0
   349
  AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
carlos@0
   350
  RETURN;
antonio@735
   351
END GENERATEPOFROMPROJECT
gorkaion@239
   352
]]></body>
adrian@94
   353
    </function>
adrian@94
   354
  </database>