Service/Calc/Z/Helper/GetDownlinePlainPrev.php
private function getPrevTreeCalcId($dateOn)
    {
        /* get plain tree calc (PV_WRITE_OFF) for prev. period */
        $periodPrev = $this->hlpPeriod->getPeriodPrev($dateOn, HPeriod::TYPE_MONTH);
        $dsLast = $this->hlpPeriod->getPeriodLastDate($periodPrev);

        $query = $this->qGetCalcs->build();

        /* WHERE */
        $bndTypeForecast = 'forecast';
        $bndTypeWriteOff = 'writeOff';
        $bndEnd = 'end';
        $bndState = 'state';
        $byTypeForecast = QGetCalcs::AS_CALC_TYPE . '.' . ECalcType::A_CODE . "=:$bndTypeForecast";
        $byTypeWriteOff = QGetCalcs::AS_CALC_TYPE . '.' . ECalcType::A_CODE . "=:$bndTypeWriteOff";
        $byDateEnd = QGetCalcs::AS_PERIOD . '.' . EPeriod::A_DSTAMP_END . "=:$bndEnd";
        $byState = QGetCalcs::AS_CALC . '.' . ECalc::A_STATE . "=:$bndState";
        $where = "(($byTypeForecast) OR ($byTypeWriteOff)) AND ($byDateEnd) AND ($byState)";
        $query->where($where);

        /* ORDER BY */
        $byCalcIdDesc = QGetCalcs::AS_CALC . '.' . ECalc::A_ID . ' DESC';
        $query->order($byCalcIdDesc);

        /* EXEC QUERY */
        $bind = [
            $bndTypeForecast => Cfg::CODE_TYPE_CALC_FORECAST_PLAIN,
            $bndTypeWriteOff => Cfg::CODE_TYPE_CALC_PV_WRITE_OFF,
            $bndEnd => $dsLast,
            $bndState => Cfg::CALC_STATE_COMPLETE,
        ];
        $conn = $query->getConnection();
        $rs = $conn->fetchAll($query, $bind);
        $one = reset($rs);
        $result = $one[QGetCalcs::A_CALC_ID];

        return $result;
    }
private function getPrevTreeCalcId($dateOn)
    {
        /* get plain tree calc (PV_WRITE_OFF) for prev. period */
        $periodPrev = $this->hlpPeriod->getPeriodPrev($dateOn, HPeriod::TYPE_MONTH);
        $dsLast = $this->hlpPeriod->getPeriodLastDate($periodPrev);

        $query = $this->qGetCalcs->build();

        /* WHERE */
        $bndTypeForecast = 'forecast';
        $bndTypeWriteOff = 'writeOff';
        $bndEnd = 'end';
        $bndState = 'state';
        $byTypeForecast = QGetCalcs::AS_CALC_TYPE . '.' . ECalcType::A_CODE . "=:$bndTypeForecast";
        $byTypeWriteOff = QGetCalcs::AS_CALC_TYPE . '.' . ECalcType::A_CODE . "=:$bndTypeWriteOff";
        $byDateEnd = QGetCalcs::AS_PERIOD . '.' . EPeriod::A_DSTAMP_END . "=:$bndEnd";
        $byState = QGetCalcs::AS_CALC . '.' . ECalc::A_STATE . "=:$bndState";
        $where = "(($byTypeForecast) OR ($byTypeWriteOff)) AND ($byDateEnd) AND ($byState)";
        $query->where($where);

        /* ORDER BY */
        $byCalcIdDesc = QGetCalcs::AS_CALC . '.' . ECalc::A_ID . ' DESC';
        $query->order($byCalcIdDesc);

        /* EXEC QUERY */
        $bind = [
            $bndTypeForecast => Cfg::CODE_TYPE_CALC_FORECAST_PLAIN,
            $bndTypeWriteOff => Cfg::CODE_TYPE_CALC_PV_WRITE_OFF,
            $bndEnd => $dsLast,
            $bndState => Cfg::CALC_STATE_COMPLETE,
        ];
        $conn = $query->getConnection();
        $rs = $conn->fetchAll($query, $bind);
        $one = reset($rs);
        $result = $one[QGetCalcs::A_CALC_ID];

        return $result;
    }
Get calc ID (Forecast or PV Write Off) to load plain tree for previous period for $dateOn.

@param string $dateOn
@return int