22 bug fix
This commit is contained in:
+32
-17
@@ -46,9 +46,9 @@ from (
|
||||
) as income_install
|
||||
,0 as income_recurring
|
||||
from
|
||||
(SELECT dd::date as dt FROM generate_series
|
||||
( '2023-01-01'::timestamp
|
||||
, '2029-12-31'::timestamp
|
||||
(SELECT dd::date as dt FROM generate_series (
|
||||
'#DAYSCALE_START#'::timestamp
|
||||
,'#DAYSCALE_FINISH#'::timestamp
|
||||
, '1 day'::interval) dd) dayscale
|
||||
join specification_item_version siv on (dayscale.dt=siv.dt_from)
|
||||
join specification_item si on (siv.specification_item_uid=si.specification_item_uid AND si.pricing_model_id in (1))
|
||||
@@ -81,14 +81,14 @@ from (
|
||||
select
|
||||
DATE_TRUNC('month', dayscale.dt)::date as m
|
||||
,0
|
||||
/*,sum(siv.price*siv.quantity*a.probability_perc/100/dayscale.days
|
||||
+ COALESCE(siv0.price*siv0.quantity*(100-a.probability_perc)/100/dayscale.days, 0)
|
||||
/*,sum(siv.price*siv.quantity*a.probability_perc/100/dayscale.monthdays
|
||||
+ COALESCE(siv0.price*siv0.quantity*(100-a.probability_perc)/100/dayscale.monthdays, 0)
|
||||
)*/
|
||||
,COALESCE(sum(
|
||||
<!--- ,COALESCE(sum(
|
||||
case when (siv.dt_to > dayscale.dt OR siv.dt_to IS NULL) then
|
||||
siv.price*siv.quantity*COALESCE(
|
||||
case when a.is_actual then 100 else a.probability_perc end
|
||||
,0)/100/dayscale.days
|
||||
,0)/100/dayscale.monthdays
|
||||
/*до окончания свежей сделки она суммируется с прошлой актуальной по правилу вероятностей, считая вероятность актуальной за сделки за 1*/
|
||||
else 0 /*по окончании свежей сделки она дает нулевой вклад*/
|
||||
end
|
||||
@@ -97,15 +97,30 @@ from (
|
||||
case when (siv0.dt_to > dayscale.dt OR siv0.dt_to IS NULL) then 0 else
|
||||
siv0.price*siv0.quantity*(100-COALESCE(
|
||||
case when a.is_actual then 100 else a.probability_perc end
|
||||
,0))/100/dayscale.days
|
||||
,0))/100/dayscale.monthdays
|
||||
/*по окончании свежей сделки*/
|
||||
end
|
||||
),0)
|
||||
),0) --->
|
||||
,sum(
|
||||
COALESCE(case when (siv.dt_to > dayscale.dt OR siv.dt_to IS NULL) then
|
||||
siv.price*siv.quantity*(
|
||||
case when a.is_actual then 100 else a.probability_perc end
|
||||
)/100/dayscale.monthdays
|
||||
else 0 /*по окончании рабочей сделки она дает нулевой вклад*/
|
||||
end,0)
|
||||
+
|
||||
COALESCE(case when (siv0.dt_to > dayscale.dt OR siv0.dt_to IS NULL) then
|
||||
siv0.price/dayscale.monthdays*siv0.quantity*(100- COALESCE(
|
||||
case when a.is_actual then 100 else a.probability_perc end
|
||||
,0))/100
|
||||
else 0 /*по окончании базовой сделки она дает нулевой вклад*/
|
||||
end,0)
|
||||
)
|
||||
from (SELECT dd::date as dt
|
||||
, DATE_PART('days', DATE_TRUNC('month', dd) + '1 MONTH'::INTERVAL - '1 DAY'::INTERVAL) days
|
||||
, DATE_PART('days', DATE_TRUNC('month', dd) + '1 MONTH'::INTERVAL - '1 DAY'::INTERVAL) monthdays
|
||||
FROM generate_series(
|
||||
'2023-01-01'::timestamp
|
||||
,'2029-12-31'::timestamp
|
||||
'#DAYSCALE_START#'::timestamp
|
||||
,'#DAYSCALE_FINISH#'::timestamp
|
||||
,'1 day'::interval) dd
|
||||
) dayscale
|
||||
left outer join specification_item_version siv on (dayscale.dt >= siv.dt_from /*AND (siv.dt_to > dayscale.dt OR siv.dt_to IS NULL)*/
|
||||
@@ -196,12 +211,12 @@ select count(*) as cnt from specification_item where 1=1
|
||||
<cfoutput query="qRead">
|
||||
<tr>
|
||||
<td class="c">#dateFormat(m,"MM.YYYY")#</td>
|
||||
<td class="r">#myNumFmt(income_install)#</td>
|
||||
<td class="r">#myNumFmt(income_recurring)#</td>
|
||||
<td class="r">#myNumFmt(income)#</td>
|
||||
<td class="r">#myNumFmt(safeNum(income) - income_old)#</td>
|
||||
<td class="r"><cfif income_install NEQ 0>#myNumFmt(income_install)#</cfif></td>
|
||||
<td class="r"><cfif income_recurring NEQ 0>#myNumFmt(income_recurring)#</cfif></td>
|
||||
<td class="r"><cfif income NEQ 0>#myNumFmt(income)#</cfif></td>
|
||||
<td class="r"><cfif safeNum(income) - income_old NEQ 0>#myNumFmt(safeNum(income) - income_old)#</cfif></td>
|
||||
<cfset income_old = safeNum(income)/>
|
||||
<td class="r">#myNumFmt(income_recurring-income_recurring_old)#</td>
|
||||
<td class="r"><cfif income_recurring-income_recurring_old NEQ 0>#myNumFmt(income_recurring-income_recurring_old)#</cfif></td>
|
||||
<cfset income_recurring_old = safeNum(income_recurring)/>
|
||||
</tr>
|
||||
</cfoutput>
|
||||
|
||||
Reference in New Issue
Block a user