Customer - total price

AS-IS 

  • the price is calulated by summing up "amout_total" on all the agreement where, payment_type = "per_year"  and status = 'I Kraft'

  • The price is not calculated if the response is paginated 

  • The following jsonpath can be used to calculate price for the response: 

    $.sum($.agreements[?(@.payment_type=='per_year' && @.status=='I Kraft')].price.amount_total)

TO-BE 

considerations

GET /customer/agreements?page=1&size=25

{
:
"page_price" : {
      "per_year" : 12000,
      "per_month" : 1000,
"one_time_amount" : 1700
  }
:
}
  • (A) calculate total price (with fee) for both "per_year" and "per_month" 

    • converte amounts specified in per_year to amounts per_month.

    • converte amounts specified in per_month to per_year.

  • (B) calculate total price without fee

    "per_year" : 12000,
    "per_month" : 1000,
    "per_year_without_fee" : 12000,
    "per_month_without_fee" : 1000,
  • (C) calculate total fee

    "fee" : 120,
  • (D) calculate total one_time_amount 

    "one_time_amount" : 1700,
  • (E) price for agreements activated in near future

    "soon_activated" : 500,
  • (F) price for agreements canceled in near future

    "soon_cancled" : 423,

Examples

The following two examples uses customer_no : "4604077613

Example 1: fethes data in one page

GET /customer/agreements?page=1&size=25&include_own=false

Example 2: fethes data in three pages

GET /customer/agreements?page=1&size=8&include_own=false
GET /customer/agreements?page=2&size=8&include_own=false
GET /customer/agreements?page=3&size=8&include_own=false

fethes data in one pages

GET /customer/agreements?page=1&size=25&include_own=false

The page price is returned in the response 

"price": 57140.14,

Can be calcualted via jsonpath

$.sum($.agreements[?(@.payment_type=='per_year' && @.status=='I Kraft')].price.amount_total)

by summing the following prices for payment_type=='per_year'

 $.agreements[?(@.payment_type=='per_year' && @.status=='I Kraft')].price.amount_total
[
  6831.33,
  3880.22,
  4968.49,
  2146.35,
  885.64,
  5815.46,
  1616.59,
  545.94,
  1044.36,
  412.49,
  412.49,
  8062.18,
  2387,
  2387,
  6867.57,
  2272,
  6605.03
]

The full list of agreement values used for price calculation is

$.agreements[*]['title','price']

[
   "Husforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 6831.33,
      "amount_total" : 6831.33,
      "fee" : 0
   },
   "Rejseforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 885.64,
      "amount_total" : 885.64,
      "fee" : 0
   },
   "Ulykkesforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 412.49,
      "amount_total" : 412.49,
      "fee" : 0
   },
   "Ulykkesforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 1044.36,
      "amount_total" : 1044.36,
      "fee" : 0
   },
   "Ulykkesforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 412.49,
      "amount_total" : 412.49,
      "fee" : 0
   },
   "Ulykkesforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 1616.59,
      "amount_total" : 1616.59,
      "fee" : 0
   },
   "Ulykkesforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 545.94,
      "amount_total" : 545.94,
      "fee" : 0
   },
   "Sælgeransvarsforsikring",
   {
      "payment_type" : "one_time_amount",
      "amount" : 1775,
      "amount_total" : 1775,
      "fee" : 0
   },
   "Indboforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 3880.22,
      "amount_total" : 3880.22,
      "fee" : 0
   },
   "Bilforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 4968.49,
      "amount_total" : 4968.49,
      "fee" : 0
   },
   "Bilforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 5815.46,
      "amount_total" : 5815.46,
      "fee" : 0
   },
   "Bilforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 8062.18,
      "amount_total" : 8062.18,
      "fee" : 0
   },
   "Bilforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 2387,
      "amount_total" : 2387,
      "fee" : 0
   },
   "Bilforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 2387,
      "amount_total" : 2387,
      "fee" : 0
   },
   "Bilforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 6867.57,
      "amount_total" : 6867.57,
      "fee" : 0
   },
   "Ulykkesforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 2146.35,
      "amount_total" : 2146.35,
      "fee" : 0
   },
   "Bilforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 2272,
      "amount_total" : 2272,
      "fee" : 0
   },
   "Bilforsikring",
   {
      "payment_type" : "per_year",
      "amount" : 6605.03,
      "amount_total" : 6605.03,
      "fee" : 0
   }
]

fethes data in three pages

(A) GET /customer/agreements?page=1&size=8&include_own=false
(B) GET /customer/agreements?page=2&size=8&include_own=false
(C) GET /customer/agreements?page=3&size=8&include_own=false

Calulate prices

$.sum($.agreements[?(@.payment_type=='per_year' && @.status=='I Kraft')].price.amount_total)

(A) 26144.079999999994
(B) 22119.03
(C) 8877.029999999999

value
$.agreements[?(?(@.payment_type=='per_year' && @.status=='I Kraft'))].price.amount_total
(a)
[
   3880.22,
   885.64,
   6831.33,
   1616.59,
   5815.46,
   4968.49,
   2146.35
]
(b)
[
   1044.36,
   412.49,
   412.49,
   545.94,
   2387,
   8062.18,
   2387,
   6867.57
]
(c)
[
   6605.03,
   2272
]

data
$.agreements[*]['title','price']
(A)
[
   {
      "title" : "Sælgeransvarsforsikring",
      "price" : {
         "payment_type" : "one_time_amount",
         "amount" : 1775,
         "amount_total" : 1775,
         "fee" : 0
      }
   },
   {
      "title" : "Indboforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 3880.22,
         "amount_total" : 3880.22,
         "fee" : 0
      }
   },
   {
      "title" : "Rejseforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 885.64,
         "amount_total" : 885.64,
         "fee" : 0
      }
   },
   {
      "title" : "Husforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 6831.33,
         "amount_total" : 6831.33,
         "fee" : 0
      }
   },
   {
      "title" : "Ulykkesforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 1616.59,
         "amount_total" : 1616.59,
         "fee" : 0
      }
   },
   {
      "title" : "Bilforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 5815.46,
         "amount_total" : 5815.46,
         "fee" : 0
      }
   },
   {
      "title" : "Bilforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 4968.49,
         "amount_total" : 4968.49,
         "fee" : 0
      }
   },
   {
      "title" : "Ulykkesforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 2146.35,
         "amount_total" : 2146.35,
         "fee" : 0
      }
   }
]
(B)
[
   {
      "title" : "Ulykkesforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 1044.36,
         "amount_total" : 1044.36,
         "fee" : 0
      }
   },
   {
      "title" : "Ulykkesforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 412.49,
         "amount_total" : 412.49,
         "fee" : 0
      }
   },
   {
      "title" : "Ulykkesforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 412.49,
         "amount_total" : 412.49,
         "fee" : 0
      }
   },
   {
      "title" : "Ulykkesforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 545.94,
         "amount_total" : 545.94,
         "fee" : 0
      }
   },
   {
      "title" : "Bilforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 2387,
         "amount_total" : 2387,
         "fee" : 0
      }
   },
   {
      "title" : "Bilforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 8062.18,
         "amount_total" : 8062.18,
         "fee" : 0
      }
   },
   {
      "title" : "Bilforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 2387,
         "amount_total" : 2387,
         "fee" : 0
      }
   },
   {
      "title" : "Bilforsikring",
      "price" : {
         "payment_type" : "per_year",
         "amount" : 6867.57,
         "amount_total" : 6867.57,
         "fee" : 0
      }
   }
]
(C)
[
   "Bilforsikring",
   {
     "payment_type": "per_year",
     "amount": 6605.03,
     "amount_total": 6605.03,
     "fee": 0
   },
   "Bilforsikring",
   {
     "payment_type": "per_year",
     "amount": 2272,
     "amount_total": 2272,
     "fee": 0
   }
]