diff --git a/Application.cfc b/Application.cfc index d90da96..ac01463 100644 --- a/Application.cfc +++ b/Application.cfc @@ -89,7 +89,7 @@ - + diff --git a/payg.cfm b/payg.cfm index 0ba9ed6..5a8afa1 100644 --- a/payg.cfm +++ b/payg.cfm @@ -81,7 +81,8 @@ siv.hash as line_key ,siv.date_nop as serviceStart, siv.date_end as serviceEnd, - siv.discount as service_discount, siv.cnt as service_quantity + siv.discount as service_discount, + siv.cnt as service_quantity /*,p.__name as line_key*/, p.ed_izm, p.name as component, p.type, p.cnt*coalesce(siv.cnt,1) as component_quantity, aa.__name as additional_agreement, aa.__id::text as additional_agreement_uid --, aa.is_actual @@ -91,6 +92,7 @@ --,ft.free_tier ,s.probability_pc ,siv.__id::text as siv_uid + ,coalesce(siv.cnt*(100.-siv.discount)/100.*p.price*(100.-p.discount)/100., 0.) as discounted_price from elma.deals d JOIN STATUS s ON (d.__status_status = s.status_id) join elma.deals_services siv on (d.__id=ANY(siv.deal)) @@ -544,9 +546,10 @@ WITH max(component_quantity) as component_quantity, max(service_quantity) as service_quantity, max(service_discount) as service_discount, + max(discounted_price) as discounted_price, max(type) as type, max(ed_izm) as ed_izm, - max(coalesce(service_quantity*(100.-service_discount)/100.*price*(100.-component_discount)/100., 0.)) as discounted_price, + --max(coalesce(service_quantity*(100.-service_discount)/100.*price*(100.-component_discount)/100., 0.)) as discounted_price, max(serviceStart) as serviceStart, max(serviceEnd) as serviceEnd, max(line_key) as line_key, @@ -579,15 +582,25 @@ SELECT s.sku_code as sku_code s.component_quantity s.service_quantity - s.service_discount + s.type s.ed_izm - coalesce(s.service_quantity*(100.-s.service_discount)/100.*s.price*(100.-s.component_discount)/100., 0.) as discounted_price + + CASE + -- Isolate the 3rd decimal place using MOD instead of % + WHEN ABS(MOD(TRUNCATE(s.discounted_price * 1000, 0), 10)) = 5 + AND ABS(MOD(TRUNCATE(s.discounted_price * 100, 0), 2)) = 0 + -- If it's a perfect .xx5 tie and the 2nd digit is EVEN, shave off the 5 + THEN TRUNCATE(s.discounted_price, 2) + -- In all other cases, standard mathematical rounding applies safely + ELSE ROUND(s.discounted_price, 2) + END as discounted_price + s.serviceStart s.serviceEnd s.line_key - s.price - s.component_discount + + s.contract s.contract_uid s.additional_agreement @@ -604,7 +617,7 @@ SELECT m.dimension1 m.unit m.raw_metric - m.metric + round(m.metric,3) as metric coalesce(ft.free_tier,0) as free_tier @@ -726,7 +739,7 @@ S3 операции и трафик: Кол-во метр. Free Tier. Опл. объем - Ед.изм. + Ед.изм. Цена ₽ со скид., с НДС Стоимость ₽ с НДС @@ -749,9 +762,9 @@ S3 операции и трафик: Цена ₽ до ск. с НДС Цена ₽ co ск. с НДС без окр. Кол-во сервиса - Скидка на сервис + Кол-во комп-та - Скидка на комп-т % + @@ -816,11 +829,12 @@ S3 операции и трафик: #m_code# #dimension1# - #request.roundSafe(metric,3)# + #metric# - #unit# [#ed_izm#] - #gaussianRound(discounted_price,2)# + #unit# [#ed_izm#] + + #discounted_price# #deal# @@ -836,16 +850,16 @@ S3 операции и трафик: #dateFormat(serviceEnd,'YYYY-MM-DD')# - #request.roundSafe(raw_metric,3)# - #request.roundSafe(metric,3)# + #raw_metric# + #metric# - #price# + #discounted_price# #service_quantity# - #service_discount# + #component_quantity# - #component_discount# + @@ -866,7 +880,7 @@ S3 операции и трафик: #unit# [#ed_izm#] #current_price# #gaussianRoundSafe(cost_dimension_1,2)# - + #request.roundSafe(accum_metric_dimension_1_all,3)#