125 lines
4.7 KiB
Plaintext
125 lines
4.7 KiB
Plaintext
<cfset msStartAt=getTickCount()/>
|
|
<cfparam name="dt_finish" type="date" default=#createDateTime(year(Now()),month(Now()),1,0,0,0)#/>
|
|
<cfparam name="dt_start" type="date" default=#dateAdd('m',-1,dt_finish)#/>
|
|
<cfset hours=dateDiff('h',dt_start,dt_finish)/>
|
|
<cfset tenant_wz_index=val(mid(request.auth.wz,3,5))/><!--- cut off WZ --->
|
|
|
|
|
|
|
|
<cfscript>
|
|
function gaussianRound(numeric number, numeric precision = 0) {
|
|
var factor = 10 ^ precision;
|
|
var scaledNumber = number * factor;
|
|
var absScaled = abs(scaledNumber);
|
|
var sign = sgn(scaledNumber);
|
|
var floored = int(absScaled);
|
|
|
|
// If it's not ending in exactly .5, use standard rounding or precision scaling
|
|
if (absScaled - floored != 0.5) {
|
|
return round(number * factor) / factor;
|
|
}
|
|
|
|
// If it is exactly .5, round towards the nearest even number
|
|
if (floored % 2 != 0) {
|
|
// Nearest even is UP
|
|
return (floored + 1) * sign / factor;
|
|
} else {
|
|
// Nearest even is DOWN
|
|
return floored * sign / factor;
|
|
}
|
|
}
|
|
</cfscript>
|
|
|
|
|
|
<cfmodule template="mod/compute_payg.cfm"
|
|
dt_finish=#dt_finish#
|
|
dt_start=#dt_start#
|
|
tenant_wz_index=#tenant_wz_index#
|
|
output="report"
|
|
debug=#isDefined("DEBUG")#
|
|
/>
|
|
|
|
<cfset temp.out=["dtStart"="#dateFormat(dt_start, "yyyy-mm-dd")#"
|
|
,"dtFinish"="#dateFormat(dt_finish, "yyyy-mm-dd")#"
|
|
,"hours"=#hours#
|
|
,"tenantWzIndex"="#tenant_wz_index#"
|
|
,"periods"=[]
|
|
]/><!--- using [] instead of {} for struct literals to obtain linked (ordered) structures: keys order preserved --->
|
|
<!--- beware nulls --->
|
|
<cfoutput query="report.qCharge" group="year">
|
|
<cfoutput group="month">
|
|
<cfset temp.period=[
|
|
"year"=#year#
|
|
,"month"=#month#
|
|
,"services"=[]
|
|
]/>
|
|
<cfset arrayAppend(temp.out.periods,temp.period)/>
|
|
|
|
<cfoutput group="svc">
|
|
<cfset var accum_cost_svc = 0/>
|
|
<!--- <cfset var accum_metric_component = 0/> --->
|
|
|
|
<cfset "temp.service"=["svc"="#svc#"
|
|
,"serviceCode"="#service_code#"
|
|
,"serviceCustomName"="#serviceCustomName#"
|
|
<!--- ,"note"="#(serviceHash EQ '')?'не найдено в договоре':''#" --->
|
|
,"hash"="#serviceHash#"
|
|
<!--- ,"metric"=#accum_metric_component# --->
|
|
,"components"=[]
|
|
]/>
|
|
|
|
<cfoutput group="code">
|
|
<cfoutput group="serviceStart">
|
|
<!--- <cfset accum_metric_component += isNumeric(metric) ? metric : 0/> --->
|
|
<cfset accum_metric_dimension_1 = 0/>
|
|
|
|
<cfset "temp.component"=["code"="#code#"
|
|
,"codeMetered"="#m_code#"
|
|
,"component"="#component#"
|
|
,"unit"="#unit#"
|
|
,"freeTier"="#free_tier#"
|
|
,"price"="#gaussianRound(discounted_price,2)#"
|
|
,"details"=[]
|
|
]/>
|
|
|
|
<cfoutput group="dimension_1">
|
|
<cfset accum_metric_dimension_1 += isNumeric(metric) ? metric : 0/>
|
|
|
|
<cfset temp.dimension=["dimension1name"="#dimension_1_name#"
|
|
,"dimension1value"="#dimension_1#"
|
|
,"dtBilledFrom"="#dateFormat(dt_billed_from,'YYYY-MM-DD')#"
|
|
,"dtBilledTo"="#dateFormat(dt_billed_to,'YYYY-MM-DD')#"
|
|
,"metric"=#(metric NEQ 0 AND isNumeric(metric))?round(metric,3):javaCast("null",0)#
|
|
,"unit"="#unit#"
|
|
<!--- ,"price"="#gaussianRound(discounted_price,2)#" --->
|
|
]/>
|
|
|
|
<cfset arrayAppend(temp.component.details, temp.dimension)/>
|
|
</cfoutput><!--- dimension_1 --->
|
|
|
|
<!--- считаем, что free_tier NOT NULL (вместо NULL 0) --->
|
|
<cfset var payable_metric_dimension_1 = (isNumeric(accum_metric_dimension_1))? max(ceiling(accum_metric_dimension_1) - free_tier, 0):javaCast("null",0)/>
|
|
<cfset var cost_dimension_1 = precisionEvaluate("gaussianRound(payable_metric_dimension_1*gaussianRound(discounted_price, 2), 2)")/>
|
|
<cfset accum_cost_svc = precisionEvaluate("accum_cost_svc + cost_dimension_1")/>
|
|
|
|
<cfset "temp.component.metric"=#(accum_metric_dimension_1 NEQ 0 AND isNumeric(accum_metric_dimension_1))? round(accum_metric_dimension_1,3):javaCast("null",0)#/>
|
|
<cfset "temp.component.metricPayable"=#payable_metric_dimension_1#/>
|
|
<cfset "temp.component.cost"=#cost_dimension_1#/>
|
|
|
|
<cfset arrayAppend(temp.service.components, temp.component)/>
|
|
</cfoutput><!--- serviceStart (component version in specification, that is svc version joined down to the component) --->
|
|
|
|
<cfset "temp.service.cost"=#accum_cost_svc#/>
|
|
</cfoutput><!--- code (component) --->
|
|
|
|
<cfset arrayAppend(temp.period.services, temp.service)/>
|
|
</cfoutput><!--- svc --->
|
|
</cfoutput><!--- month --->
|
|
</cfoutput><!--- year --->
|
|
<cfset "temp.out.durationMs"=(getTickCount()-request.startTickCount)/>
|
|
<cfcontent
|
|
type="application/json"
|
|
/><cfoutput>#serializeJSON(temp.out)#</cfoutput>
|
|
|
|
|