Calculate line price based on adjustments

Hi Guru's.
Could you please help me to prepare a query?
Selling price has to be calculated based on unit_list_price & adjustment details.
Two tables Order line & Adjustment data.
Pricing group sequence is the order of calculating adjustment at every step to arrive at the current price to adjust further.
Example Calculation :
25000     -- List price
5%     1250 -- First bucket -- 5%discount on list price
50     50 -- First bucket -- 50 discount on list price
23700     -- Price after first bucket adjustment
7%     1659 -- adjustment for second bucket - on top of 23700
22041     -- Price after second bucket adjustment
20     20 -- 20 on 22041
2%     440.82 -- 2% on 22041
21580.18     -- Price after third bucket adjustment
2%     431.6 -- 2% on 21580.18
21148.58     
select * from v$version
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE     11.2.0.3.0     Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
create table xx_line
(line_id number,
item varchar2(30),
unit_list_price number,
selling_price number);
insert into xx_line
(line_id,item,unit_list_price,selling_price)
values
(1234,'xxitem',25000,21148.58);
create table xx_price_adjustments
adjustment_id number primary key,
Line_id number,
pricing_group_sequence number,
operand number,
arithmetic_operator varchar2(4) check (arithmetic_operator  in ('%','AMT'))
insert into xx_price_adjustments
(adjustment_id,line_id,pricing_group_sequence,Operand,arithmetic_operator)
values
(10000,1234,1,5,'%');
insert into xx_price_adjustments
(adjustment_id,line_id,pricing_group_sequence,Operand,arithmetic_operator)
values
(10001,1234,1,50,'AMT');
insert into xx_price_adjustments
(adjustment_id,line_id,pricing_group_sequence,Operand,arithmetic_operator)
values
(10002,1234,2,7,'%');
insert into xx_price_adjustments
(adjustment_id,line_id,pricing_group_sequence,Operand,arithmetic_operator)
values
(10003,1234,3,2,'%');
insert into xx_price_adjustments
(adjustment_id,line_id,pricing_group_sequence,Operand,arithmetic_operator)
values
(10004,1234,3,20,'AMT');
insert into xx_price_adjustments
(adjustment_id,line_id,pricing_group_sequence,Operand,arithmetic_operator)
values
(10005,1234,4,2,'%');
select * from xx_line;
select * from xx_price_adjustments order by pricing_group_sequence;

seankim wrote:
below is sys_connect_by_path() version.Data magic. Your solution isn't working. It doesn't take buckets (pricing_group_sequence) into consideration. Just issue:
update xx_price_adjustments set arithmetic_operator = '%';Now calculations are:
25000 -- List price
5% 1250 -- First bucket -- 5%discount on list price
50% 12500 -- First bucket -- 50% discount on list price
11250 -- Price after first bucket adjustment
7% 787.5 -- adjustment for second bucket - on top of 10462.5
10462.5 -- Price after second bucket adjustment
20% 2092.5 -- 20% on 10462.5
2% 209.25 -- 2% on 10462.5
8160.75 -- Price after third bucket adjustment
2% 163.215 -- 2% on 8160.75
7997.535 - selling price.
And look what your solution returns:
SQL> select * from xx_price_adjustments;
ADJUSTMENT_ID    LINE_ID PRICING_GROUP_SEQUENCE    OPERAND ARIT
        10000       1234                      1          5 %
        10001       1234                      1         50 %
        10002       1234                      2          7 %
        10003       1234                      3          2 %
        10004       1234                      3         20 %
        10005       1234                      4          2 %
6 rows selected.
SQL> select a.line_id,
  2         a.item,
  3        a.unit_list_price,
  4        round(get_sell_prie(a.unit_list_price, b.op),2) sell_price
  5  from   xx_line a, (
  6                   select b.line_id, max(sys_connect_by_path(substr(b.arithmetic_operator,1,1)||b.operand,'/')) op
  7                   from  (
  8                          select b.adjustment_id,
  9                                     b.line_id,
10                                     b.pricing_group_sequence,
11                                     b.operand,
12                                     b.arithmetic_operator,
13                                     row_number() over (partition by line_id order by adjustment_id) rnum
14                          from   xx_price_adjustments b)  b
15                   start with rnum=1
16                   connect by prior rnum=rnum-1 and prior line_id=line_id
17                   group by b.line_id) b
18  where a.line_id=b.line_id;
   LINE_ID ITEM                           UNIT_LIST_PRICE SELL_PRICE
      1234 xxitem                                   25000    8485.13Why? It is always basing price on previous step selling price, not on bucket selling price:
25000 -- List price
5% of 25000 = 1250
Selling price 23750
50% of 23750 = 11875
Selling price 11875
7% of 11875 = 831.25
Selling price 11043.75
2% of 11043.75 = 220.875
Selling price 10822.875
20% of 10822.875 = 2164.575
Selling price 8658.3
2% of 8658.3 = 173.166
Selling price 8485.134 (or 8485.13 rounded)
My solution:
SQL> with a as (
  2             select  row_number() over(order by adjustment_id) adjustment_sequence,
  3                     count(*) over() adjustment_count,
  4                     line_id,
  5                     pricing_group_sequence,
  6                     operand,
  7                     arithmetic_operator
  8               from  xx_price_adjustments
  9            ),
10       r(
11         line_id,
12         item,
13         unit_list_price,
14         selling_price,
15         pricing_group_selling_price,
16         adjustment_sequence,
17         adjustment_count,
18         pricing_group_sequence
19        ) as (
20               select  line_id,
21                       item,
22                       unit_list_price,
23                       unit_list_price selling_price,
24                       unit_list_price pricing_group_selling_price,
25                       0 adjustment_sequence,
26                       1 adjustment_count,
27                       1 pricing_group_sequence
28                 from  xx_line
29              union all
30               select  r.line_id,
31                       r.item,
32                       r.unit_list_price,
33                       case r.pricing_group_sequence
34                         when a.pricing_group_sequence then r.selling_price - case a.arithmetic_operator
35                                                                                when '%' then r.pricing_group_selling_price / 100 * a.operand
36                                                                                when 'AMT' then a.operand
37                                                                              end
38                       else r.selling_price - case a.arithmetic_operator
39                                                when '%' then r.selling_price / 100 * a.operand
40                                                when 'AMT' then a.operand
41                                              end
42                       end selling_price,
43                       case r.pricing_group_sequence
44                         when a.pricing_group_sequence then r.pricing_group_selling_price
45                       else r.selling_price
46                       end pricing_group_selling_price,
47                       a.adjustment_sequence,
48                       a.adjustment_count,
49                       a.pricing_group_sequence
50                 from  r,
51                       a
52                 where a.line_id = r.line_id
53                   and a.adjustment_sequence = r.adjustment_sequence + 1
54             )
55  select  line_id,
56          item,
57          unit_list_price,
58          selling_price
59    from  r
60    where adjustment_sequence = adjustment_count
61  /
   LINE_ID ITEM                           UNIT_LIST_PRICE SELLING_PRICE
      1234 xxitem                                   25000      7997.535
SQL>SY.

Similar Messages

  • How to calculate net price based on customized formula

    Hi  all expert,
    I have a requirement in a rental process:
    The price of a rental is defined as daily rate (e.g. 100/day) and monthly rate (e.g. 2500/month).
    when I create a rental contract, I'd like SAP to calculate net price based on contract duration with both rate and use the lower one.
    e.g. rental 5 days. use daily rate = 500; monthly rate = 2500; So use 500.
    e.g. rental >=26 days. use daily rate >= 2600; monthly rate = 2500; So use monthly rate 2500.
    I was think to use price condition scales to set:
    1 - 25 days: 100/day
    >=26 days: 2500/month
    But the problem is there are 30day a month and 31 days a month. When the contract has to calculate partial month, daily rate has to be calculated as monthly rate/actual days in the month.
    How to handle it?
    Thank you in advance!    

    There might be more than one method to resolve the requirement.
    You can develop a routine in t.code VOFM and add it in the column  AltCTy. The logic in the routine can be if the netvalue exceeds 2500, then the net value should be 2500.
    The second option is you can try with using standard. In VK12, after maintaining the pricing as 100/day, go to details. Then in upper limit add value as 2500. Then create a test sales order for 25 days and more than 25 days, then check the values. I think this can help with your scenario.
    Regards,

  • How to calculate Total Price based on a sqm rate with different price points?

    Hi,
    I'm guessing this is a script solution but I've never done any scripting so though I'd ask you guys...
    I have a form where I'd like to calculate the total price of some carpet based on the price per sqm.
    - The user enters the carpet quanitity required.
    - There are different price points for 1-20, 21-60, 61+sqm (each with their own hidden fields containing the price value).
    - The Total Price field assesses the quantity ordered, and multiplis it by the relevant square metre rate.
    Is this achievable?
    I'm guessing any solutions are placed into the "Custom Calculation Script" field too?
    Thanks in advance!

    Yes. You can use something like this as the custom calculation of the total price field (you might need to adjust the field names):
    var sqm = Number(this.getField("SQM").value);
    var rate = 0;
    if (sqm>0 && sqm<=20) rate = Number(this.getField("Rate1").value);
    else if (sqm>20 && sqm<=60) rate = Number(this.getField("Rate2").value);
    else if (sqm>60) rate = Number(this.getField("Rate3").value);
    event.value = sqm * rate;

  • Completion and approval workflows in line item based SC approval scenario

    Hi SRM experts,
    We are on SRM 7 ECS , support pack SAPKIBKV08
    We are designing line item based SC approval workflow. We also have completion workflow. i.e after requester creates a shopping cart, it goes to buyer as per completion workflow( if the SC does not have price , vendor or has a free text)  , and then after the completion workflow, it goes to main SC approval workflow.
    My questions are :
    1. If a requester creates 2 line items in SC , and 1 line item does not have price/vendor/or material , whereas 2nd line item has price/vendor/ and material , can we send onlt the 1st line item  to completion workflow and not send the 2nd line item in the completion workflow but directly to SC approval workflow  ?  OR we have to send the entire cart to the completion workflow ?
    2. After the completion and the approval workflow , if line item 1 is approved, can it create a PO , whereas the 2nd line be still in approval . i.e  do all the cart items need to be approved before creating POs or as and when individual line items get approved , they can create thier own POs
    Rgds
    Sumendra

    Hi Sumedra,
    Which workflow are you using - application or process contrlled workflow?
    Assuming you are using process-controlled workflow - I will answer following questions -
    1. Can offline approval be used for item based shopping cart approval workflow?
    - Yes, it can be used !
    2. Can different line items be sent by mail to different mail boxes?
    Yes
    3. Will 1 manager see all the 10 line items OR only the 1 line item for which he is responsible?
    1 manager can 'see' all the items but he can only approve or reject the item that he is suppose to act on. All other item will be grayed out. However, this behaviour is configuarable !
    4. If he will get only line for which he is responsible , and once he clicks on approve , will this approval apply to his line item only , OR it will apply to all the 10 line items ?
    - see above
    Regards,
    Amit

  • Calculating Key Figures in Copa based as sales Rev / Cusomter Price Based

    Hello Gurus,
    I have a requirement in which i would like to calculate some key figures in COPA as sales revenue.
    I would like for e.g to calculate the following: Cusomter Price Based Discount but do not know what to take into consideration.
    Is there any document which can help me to build it?
    I have  created the generic datasource based on the table CE1XXXXX.
    Thank you

    Hi Anindya,
    thank you for replying.
    The steps in that document was already being done.
    I have all Key Figures comin from CE1xxx Table. We are using the cost based COPA.
    My problem now is to build some Key Figures as sales revenue (Sales View) like for e.g Cusomter Price Based Discount.
    I would like to know how to proceed to build them. Any sample?
    Is it possible to build them directly based only on the generated extractor? or should i have to take dta from Billing as well?
    Thank you.

  • Trying to find selling price based on most current date

    Need help on finding the selling price based on the most current date.  I'm able to get the current date but not the selling price for that date.  Any help will be appreciated.
    Thank you in advance.
    This is the pivot table I'm working with.  The price should be 5.81 but it's picking up the highest price and not the last price.
    Formula for current date is =LASTDATE('Product Cost'[EFFDATE])
    Formula for current price is  =LASTNONBLANK('Product Cost'[STDCOST],LASTDATE('Product Cost'[EFFDATE]))
    Row Labels
    Current Date
    Current Price
    1152
    09/29/2014
    6.01
    Should be 5.81
    1/1/2009
    01/01/2009
    5.5
    7/9/2009
    07/09/2009
    5.11
    1/4/2010
    01/04/2010
    5.15
    4/12/2010
    04/12/2010
    5.18
    7/12/2010
    07/12/2010
    5.18
    10/27/2010
    10/27/2010
    5.18
    12/21/2010
    12/21/2010
    5.48
    12/27/2010
    12/27/2010
    5.18
    1/5/2011
    01/05/2011
    5.48
    1/17/2011
    01/17/2011
    5.47
    4/4/2011
    04/04/2011
    5.56
    8/22/2011
    08/22/2011
    5.45
    1/2/2012
    01/02/2012
    5.9
    1/2/2013
    01/02/2013
    6.01
    1/6/2014
    01/06/2014
    5.84
    9/29/2014
    09/29/2014
    5.81

    Hi Mike,
    Something like this should give you the behaviour you're after:
    Current Price:=
    CALCULATE(
    MIN(Product Cost[STDCOST]),
    FILTER(
    ALL(Product Cost),
    Product Cost[EFFDATE] = MAX(Product Cost[EFFDATE])
    Regards,
    Michael Amadi
    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)
    Website: http://www.nimblelearn.com
    Blog: http://www.nimblelearn.com/blog
    Twitter: @nimblelearn

  • Looking for an API to get calculate the price

    Hi ,
    I am trying to find an API to calculate the Price of an item (Quote)
    This need to find the price considering the Modifier , and qualifiers.
    I have setup up qualifiers on Customer,Price List , Order levels.
    I have tried the below given script , but it is not considering modifiers
    DECLARE
    l_listprice     NUMBER;
    l_bestprice     NUMBER;
    l_status_code     VARCHAR2(2000);
    l_status_text     VARCHAR2(2000);
    l_user_id     NUMBER;
    l_responsibility_id NUMBER;
    l_application_id NUMBER;
    BEGIN
    fnd_client_info.set_org_context ('81');
    SELECT user_id
    INTO l_user_id
    FROM fnd_user
    WHERE user_name = 'USER';
    SELECT responsibility_id
    ,application_id
    INTO l_responsibility_id
    ,l_application_id
    FROM fnd_responsibility_tl
    WHERE responsibility_name = 'IBE_CUSTOMER';
    fnd_global.apps_initialize (l_user_id
    ,l_responsibility_id
    ,l_application_id);
    IBE_PRICE_PVT.GetPrice(
         p_price_list_id     =>          7007
         ,p_party_id => 222
         ,p_cust_account_id => 111
         ,p_model_id          => NULL
         ,p_organization_id     => 123
         ,p_currency_code     => 'USD'
    ,p_inventory_item_id     =>     1222321
    ,p_uom_code          => 'CS'
         --,p_calculate_flag     => 'Y'
         ,p_model_bundle_flag     => NULL
         ,p_request_type_code     => 'ASO'
         ,p_pricing_event     => 'LINE'
    ,x_listprice          => l_listprice
         ,x_bestprice          => l_bestprice
         ,x_status_code     => l_status_code
         ,x_status_text     => l_status_text
    DBMS_OUTPUT.PUT_LINE ( 'l_listprice = '|| l_listprice );
    DBMS_OUTPUT.PUT_LINE ( 'l_bestprice = '|| l_bestprice );
    DBMS_OUTPUT.PUT_LINE ( 'l_status_code = '|| l_status_code );
    DBMS_OUTPUT.PUT_LINE ( 'l_status_text = '|| l_status_text );
    END;
    Edited by: 797959 on 22-Feb-2011 10:08

    I'm not sure I completely follow you with the "privilege".
    To answer your question, yes, you may enhance behaviour of standard services such as CHECKIN_UNIVERSAL via so called "filters". Filters are Java pieces of code, that might be hooked to "filter events" such as validateCheckinData. When a service is being processed, the filter code is triggered on that event automatically.
    However, the checkin services already contain a security check (it calls a Java method from the standard code), and it will do checks like "can this user check in a document with such a security group?" or "does this folder exist?", no extra code needed. So, I'm not sure what your enhancement would do additional.

  • How do I use acrobat to calculate quantity/price as a form?

    Hello, I am trying to find out how to complete a form in acrobat pro using fields to calculate quantity/prices, ending in the field "TOTAL". This form is designed in illustrator. Here is a picture of the form: http://db.tt/gJsLWngT  Can anyone help me complete to process? If I am taking the wrong approach to this please let me know. I would greatly appreciate it, thank you.

    You need to place text fields as your Quantity and Total columns, 2 in each
    row.
    For example, in the first row you can create: Quantity1 and Total1
    Set up the quantity fields to accept only numbers (under Format).
    The total fields should be set to be read-only, and under Calculate you can
    use the Simple Field Notation to calculate their value.
    In the case of Total1, you can use something like this (for the retail
    price):
    Quantity1 * 35
    The value will be automatically updated whenever the value of Quantity1
    changes.
    For the last total field, use the first calculation option: Value is the
    (sum) of... and then select all the other total fields from the list.
    There are many more things that you can do...
    The tutorials on this website contains a lot of information about forms in
    PDF files:
    http://acrobatusers.com/tutorials

  • How to add new line item based on main item using crm_order_maintain

    Hi All,
    can you please provide a way to create a new line item based on main line item and save in crm transaction( in house repair order) by using crm_order_maintain(from SAP GUI).
    Thanks,
    vinod.

    Hi Vinod,
    The relationship with main item is stored with CRMD_ORDERADM_I- Parent.
    You need to pass the guid of main item to orderadm_i-parent. This will keep the relationship with main item.
    Thanks
    Ajay

  • Line item based approval

    Hi All,
    I have line item based approval workflow WS14500015. My shopping cart has multiple line items each awaiting approval from multiple approvers.
    Now my requirement is when any approver approves his line items , that particular line items should not be allowed for changes even though the shopping cart has status awaiting approval coz others line items are still awaiting approval .
    Is this possible i.e user should be able to make changes to unapproved line items abut not approved line items .
    Can i user badi BBP_WFL_SECURE_BADI for this ?? Please if anyone has already done this please share your inputs .
    Thanks in advance
    Iftekhar Alam

    Hi Alam,
    have you checked the APPROVAL_HISTORY_TABLE and ITEM_APPROVAL_HISTORY_TABLE? Here you will receive information on already approved items and the current approval process.
    Kind regards,
    Thomas

  • Calculate excise duties based on rates in J1IEX

    Hi,
    When i am trying to change the duty rates  in J1IEX transaction (in change mode)
    and put tick in check box( Calculate excise duties based on rates ),then the system calculating wrong duty values for SHEcess & Ecess.
    We are using TAXINN here.
    Pls provide me the solution where to do the settings for this issue.
    rgrds
    srini

    THE PROBLEM HAS BEEN RESOLVED. NOW CALCULATE EXCISE TAX CHECK BOX IS APPEARING. I HAVE RESOLVED IT

  • Calculate credit amount based on a sub service order?

    Hi Experts,
    How do I calculate credit amount based on a sub service order? Is that in the COEP table? If yes what is the logic to calculate it? suppose I have sub service order number 000006009972. Thanks!
    Best regards,
    - Anthony -

    Anthony
    It might help if you decribe the business process...
    PeteA

  • Sale Item Price Based On BP Customer Group

    Hi,
    We have SAP B1 2007A.
    We have different customer groups like : Member, Non Member, Distributors.
    I want to have a different price list for each Customer based on the customer group they belong to.
    In other words, the same ITEM has a different price based on the customer group.
    Any way to do that?
    Mike

    Mike,
    This is what you can do -
    1. Create a "BASIC PRICE LIST" for the item first.
    2. For each customer (since the relation of Price lists has to be defined at this level not customer group), you can create a new price list but link it to the "BASIC PRICE LIST" you created in step 1.
    So for ex - if CUSTOMER GRP A has to be sold at a discount of 10%, then in your customer price list definition, enter factor as 0.9 and link it to the "BASIC PRICE LIST".
    Since one customer can be defined only within one group at a time, you can have the same effect of having the price list defined on customer groups. Only that, if your group pricing changes, you will have to either modify the price list, or create a new price list and link it all your customers (of a particular group) once again.
    Hope this helps.
    Cheers

  • COPA Realignments for line item based reports

    Hi Guru
    I built two CO-PA  line item based reports in our environment. Now , there are some organizational changes in our environment and Now I have re-derive a characteristic from customer master data. Does those changes reflect in my line item based reports, If i run Re-Alignments (KEND)?
    Thanks in advance

    Line item reports (defined w/KE91) will reflect the realignment.  Line item display (KE24/KE25) will give you the choice of reading the original posting or the realigned data.

  • Get price based on Good Received Qty

    Hi Experts,
    Do possible to determine price based on Good Received Qty instead of PO Qty?
    Eg:
    PO Qty 500 pcs = $ 5,000
    1st GR - 150 pcs = price will determine $ 15 per pc
    2nd GR - 350 pcs = price will determine $ 10 per pc
    Thanks in advanced..

    Hi All,
    Thanks for ur feedback..
    Vijay: I had follow your steps.. but when create GR, the price still determine based on PO number.
    Gaito: Cannot accept same material posted in same PO.. price requested to determine based on GR qty.
    Piyush: Thanks for information but is not what i requested..
    Chakrapani: Then do you have any idea to determine price based on GR qty? User Exit?
    Thanks to all, still need your support..
    Lina

Maybe you are looking for

  • Data from BW to Oracle.

    Hi All, I am new into BW and i know how to get the data from my applications backend i.e ORACLE to BW system for reporting purpose. I have a scenario where user can edit this information through IP. I want this modified data to go back to ORACLE DB s

  • Messages (-1) error - can't send or receive messages

    Haven't been able to send or receive messages since last night. Error shown in link below. Really strange. Don't remember doing anything in particular that might have caused it. http://img217.imageshack.us/img217/6581/photogo.png

  • Imessage won't work/activate after 5.1

    I updated to 5.1 this morning, and now my imessage won't work. I try to turn it on, and I just get an activation error. "An error occurred during activation, try again".I've read in some other posts that my phone number should show by the imessage op

  • How to include manual config to TR?

    Hi Experts, I have a question about transportation. I assigned a new partner type to a partner function, when I tried to save it,  the system did not ask me to provide a TR number, instead the message popped up u2018Please process table entry transfe

  • Sporadic start up on my MacBook

    My late 2008 aluminum Mabook is suddenly not starting up all the time.  I've tried all the tricks (I.e. Battery removal, pram, etc.) but to no avail. The machine has died twice for a couple days and then started up fine. Is this a dying hard disc, or