src-db/database/model/functions/M_EXPLODEBOMNOTSTOCK.xml
changeset 22852 8403924dc79d
parent 21926 8d694f6a34a3
child 25697 11a4bc84965f
equal deleted inserted replaced
22851:bf51ff460dc8 22852:8403924dc79d
    17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    18 * License for the specific  language  governing  rights  and  limitations
    18 * License for the specific  language  governing  rights  and  limitations
    19 * under the License.
    19 * under the License.
    20 * The Original Code is Openbravo ERP.
    20 * The Original Code is Openbravo ERP.
    21 * The Initial Developer of the Original Code is Openbravo SLU
    21 * The Initial Developer of the Original Code is Openbravo SLU
    22 * All portions are Copyright (C) 2013 Openbravo SLU
    22 * All portions are Copyright (C) 2013-2014 Openbravo SLU
    23 * All Rights Reserved.
    23 * All Rights Reserved.
    24 * Contributor(s):  ______________________________________.
    24 * Contributor(s):  ______________________________________.
    25 ************************************************************************/
    25 ************************************************************************/
    26   -- Logistice
    26   -- Logistice
    27   v_explode CHAR(1);
    27   v_explode CHAR(1);
    37   CUR_BOM_Line RECORD;
    37   CUR_BOM_Line RECORD;
    38   CUR_BOM RECORD;
    38   CUR_BOM RECORD;
    39   v_Line NUMBER:=0;
    39   v_Line NUMBER:=0;
    40   v_ResultStr VARCHAR2(2000):='';
    40   v_ResultStr VARCHAR2(2000):='';
    41   v_result NUMBER:= 1;  
    41   v_result NUMBER:= 1;  
       
    42   v_Precision NUMBER;
       
    43   v_gross_unit_price NUMBER;
       
    44   v_line_gross_amount NUMBER;
       
    45   v_price_actual NUMBER;
       
    46   v_gross_price_list NUMBER;
       
    47   v_line_net_amt NUMBER;
       
    48   v_istaxincluded CHAR(1);
       
    49   
    42   BEGIN
    50   BEGIN
    43   IF (p_PInstance_ID IS NOT NULL) THEN
    51   IF (p_PInstance_ID IS NOT NULL) THEN
    44       --  Update AD_PInstance
    52       --  Update AD_PInstance
    45       DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    53       DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
    46       v_ResultStr:='PInstanceNotFound';
    54       v_ResultStr:='PInstanceNotFound';
    77     
    85     
    78     v_ResultStr:='Exploding';
    86     v_ResultStr:='Exploding';
    79 
    87 
    80     -- Get Price List Version
    88     -- Get Price List Version
    81     FOR Cur_MPriceListVersion IN
    89     FOR Cur_MPriceListVersion IN
    82       (SELECT v.M_PriceList_Version_ID AS PriceList_Version_ID, o.M_PriceList_ID
    90       (SELECT v.M_PriceList_Version_ID AS PriceList_Version_ID, o.M_PriceList_ID,
    83        FROM M_PRICELIST_VERSION v, C_ORDER o
    91       p.IsTaxIncluded
       
    92        FROM M_PRICELIST_VERSION v, C_ORDER o, M_PriceList p
    84        WHERE v.M_PriceList_ID=o.M_PriceList_ID
    93        WHERE v.M_PriceList_ID=o.M_PriceList_ID
       
    94          AND v.M_PriceList_ID = p.M_PriceList_ID
    85          AND v.ValidFrom<=o.DateOrdered
    95          AND v.ValidFrom<=o.DateOrdered
    86          AND v.IsActive='Y'
    96          AND v.IsActive='Y'
    87          AND o.C_Order_ID=v_orderID
    97          AND o.C_Order_ID=v_orderID
    88        ORDER BY v.ValidFrom DESC
    98        ORDER BY v.ValidFrom DESC
    89       )
    99       )
    90     LOOP
   100     LOOP
    91       v_PriceList_Version_ID:=Cur_MPriceListVersion.PriceList_Version_ID;
   101       v_PriceList_Version_ID:=Cur_MPriceListVersion.PriceList_Version_ID;
       
   102       v_IsTaxIncluded:=Cur_MPriceListVersion.IsTaxIncluded;
    92       EXIT;
   103       EXIT;
    93     END LOOP;
   104     END LOOP;
    94     -- Replace Lines
   105     -- Replace Lines
    95     v_ResultStr:='Inserting lines';
   106     v_ResultStr:='Inserting lines';
    96     For Cur_Bom_Line In
   107     For Cur_Bom_Line In
   122       LOOP
   133       LOOP
   123         V_C_Tax_Id:=C_Gettax(Cur_Bom.M_Productbom_Id, Cur_Bom_Line.Dateordered, 
   134         V_C_Tax_Id:=C_Gettax(Cur_Bom.M_Productbom_Id, Cur_Bom_Line.Dateordered, 
   124         Cur_Bom_Line.Ad_Org_Id, Cur_Bom_Line.Ord_M_Warehouse_Id, Cur_Bom_Line.Ord_C_Bpartner_Location_Id, 
   135         Cur_Bom_Line.Ad_Org_Id, Cur_Bom_Line.Ord_M_Warehouse_Id, Cur_Bom_Line.Ord_C_Bpartner_Location_Id, 
   125         CUR_BOM_Line.ord_C_BPartner_Location_ID, null, CUR_BOM_Line.issotrx) ;
   136         CUR_BOM_Line.ord_C_BPartner_Location_ID, null, CUR_BOM_Line.issotrx) ;
   126 
   137 
       
   138         SELECT PricePrecision INTO v_Precision FROM C_Currency WHERE
       
   139         C_Currency_ID = CUR_BOM_Line.C_Currency_ID;
       
   140 
       
   141         IF(v_IsTaxIncluded='Y') THEN
       
   142 					v_gross_unit_price:=M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID);
       
   143 					v_gross_price_list:=M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceList(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID);
       
   144 					v_line_gross_amount:=ROUND(CUR_BOM_Line.QtyOrdered*CUR_BOM.BOMQty*v_gross_unit_price, v_Precision);
       
   145 					v_price_actual:=ROUND(C_GET_NET_PRICE_FROM_GROSS(V_C_Tax_Id,  M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID), 0, v_Precision, 1),v_Precision);
       
   146 					v_line_net_amt:=ROUND(CUR_BOM_Line.QtyOrdered*CUR_BOM.BOMQty*v_price_actual, v_Precision);
       
   147 				ELSE
       
   148 					v_gross_unit_price:=0;
       
   149 					v_line_gross_amount:=0;
       
   150 					v_gross_price_list:=0;
       
   151 					v_price_actual:=M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID);
       
   152 					v_line_net_amt:=ROUND(CUR_BOM_Line.QtyOrdered*CUR_BOM.BOMQty*v_gross_unit_price, v_Precision);
       
   153 				END IF;
       
   154 
   127         v_Line:=v_Line + 1;
   155         v_Line:=v_Line + 1;
   128         INSERT
   156         INSERT
   129         INTO C_ORDERLINE
   157         INTO C_ORDERLINE
   130           (
   158           (
   131             C_OrderLine_ID, AD_Client_ID, AD_Org_ID, IsActive,
   159             C_OrderLine_ID, AD_Client_ID, AD_Org_ID, IsActive,
   138             PriceList,
   166             PriceList,
   139             PriceActual, PriceLimit, LineNetAmt, Discount,
   167             PriceActual, PriceLimit, LineNetAmt, Discount,
   140             FreightAmt, C_Charge_ID, ChargeAmt, C_Tax_ID,
   168             FreightAmt, C_Charge_ID, ChargeAmt, C_Tax_ID,
   141             QuantityOrder, M_Product_Uom_ID, PriceStd,
   169             QuantityOrder, M_Product_Uom_ID, PriceStd,
   142             c_project_id, a_asset_id, c_costcenter_id,
   170             c_project_id, a_asset_id, c_costcenter_id,
   143             user1_id, user2_id, bom_parent_id
   171             user1_id, user2_id, bom_parent_id,
       
   172             gross_unit_price, grosspricelist, line_gross_amount
   144           )
   173           )
   145         VALUES
   174         VALUES
   146           (
   175           (
   147             get_uuid(), CUR_BOM_Line.AD_Client_ID, CUR_BOM_Line.AD_Org_ID, CUR_BOM_Line.IsActive,
   176             get_uuid(), CUR_BOM_Line.AD_Client_ID, CUR_BOM_Line.AD_Org_ID, CUR_BOM_Line.IsActive,
   148             now(), '0', now(), '0',
   177             now(), '0', now(), '0',
   150             CUR_BOM_Line.DateOrdered, CUR_BOM_Line.DatePromised, CUR_BOM_Line.DateDelivered, CUR_BOM_Line.DateInvoiced,
   179             CUR_BOM_Line.DateOrdered, CUR_BOM_Line.DatePromised, CUR_BOM_Line.DateDelivered, CUR_BOM_Line.DateInvoiced,
   151             CUR_BOM.Description, CUR_BOM.M_ProductBOM_ID, CUR_BOM_Line.M_Warehouse_ID, CUR_BOM_Line.DirectShip,
   180             CUR_BOM.Description, CUR_BOM.M_ProductBOM_ID, CUR_BOM_Line.M_Warehouse_ID, CUR_BOM_Line.DirectShip,
   152             CUR_BOM.C_UOM_ID, CUR_BOM_Line.QtyOrdered*CUR_BOM.BOMQty, CUR_BOM_Line.QtyReserved*CUR_BOM.BOMQty, CUR_BOM_Line.QtyDelivered*CUR_BOM.BOMQty,
   181             CUR_BOM.C_UOM_ID, CUR_BOM_Line.QtyOrdered*CUR_BOM.BOMQty, CUR_BOM_Line.QtyReserved*CUR_BOM.BOMQty, CUR_BOM_Line.QtyDelivered*CUR_BOM.BOMQty,
   153             CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, CUR_BOM_Line.M_Shipper_ID, CUR_BOM_Line.C_Currency_ID,
   182             CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, CUR_BOM_Line.M_Shipper_ID, CUR_BOM_Line.C_Currency_ID,
   154             M_BOM_PriceList(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID),
   183             M_BOM_PriceList(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID),
   155             M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID), M_BOM_PriceLimit(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID),
   184             v_price_actual, M_BOM_PriceLimit(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID),
   156             M_Get_Offers_Price(CUR_BOM_Line.DateOrdered, v_CBPartner_ID, CUR_BOM.M_ProductBOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID), CUR_BOM_Line.QtyInvoiced*CUR_BOM.BOMQty, v_PriceList_ID) * CUR_BOM_Line.QtyOrdered*CUR_BOM.BOMQty, CUR_BOM_Line.Discount,
   185             v_line_net_amt, CUR_BOM_Line.Discount,
   157             CUR_BOM_Line.FreightAmt, CUR_BOM_Line.C_Charge_ID, CUR_BOM_Line.ChargeAmt, coalesce(v_C_Tax_ID,CUR_BOM_Line.c_tax_id),
   186             CUR_BOM_Line.FreightAmt, CUR_BOM_Line.C_Charge_ID, CUR_BOM_Line.ChargeAmt, coalesce(v_C_Tax_ID,CUR_BOM_Line.c_tax_id),
   158             CUR_BOM_Line.QuantityOrder, CUR_BOM_Line.M_Product_UOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID),
   187             CUR_BOM_Line.QuantityOrder, CUR_BOM_Line.M_Product_UOM_ID, M_BOM_PriceStd(CUR_BOM.M_ProductBOM_ID, v_PriceList_Version_ID),
   159             CUR_BOM_Line.c_project_id, CUR_BOM_Line.a_asset_id, CUR_BOM_Line.c_costcenter_id,
   188             CUR_BOM_Line.c_project_id, CUR_BOM_Line.a_asset_id, CUR_BOM_Line.c_costcenter_id,
   160             CUR_BOM_Line.user1_id, CUR_BOM_Line.user2_id, v_Record_ID
   189             CUR_BOM_Line.user1_id, CUR_BOM_Line.user2_id, v_Record_ID,
       
   190             v_gross_unit_price, v_gross_price_list, v_line_gross_amount
   161           );
   191           );
   162       END LOOP; -- Create New Lines
   192       END LOOP; -- Create New Lines
   163     END LOOP; -- Replace Lines
   193     END LOOP; -- Replace Lines
   164     UPDATE c_orderline set explode='Y' where c_orderline_id = v_Record_ID;
   194     UPDATE c_orderline set explode='Y' where c_orderline_id = v_Record_ID;
   165     
   195