We understand Your business.
The key to our joint success.
2 decades of our experience turned into your success story
Billions of transactions, Terabytes of data, Thousands of processes
made simple
...
our tools used,
enjoyed &
proven by people all over the world
...
across all timezones, almost all countries
protected function joinRegions(ActiveQuery $query){
if(empty($this->by_regions) && empty($this->regions)){
return;
}
$this->joinBusinessUnit($query);
$query->leftJoin('region fcRegion', 'fcRegion.id = businessUnit.region_id');
$query->leftJoin(
'(
(
SELECT
ao.erp_output_id AS erp_output_id,
r.id AS region_id,
r.acronym AS region_name,
r.order_idx AS order_idx,
fc.id AS fc_id
FROM
atlas_output ao
INNER JOIN region r ON r.id = ao.region_id
LEFT JOIN financial_component fc ON fc.erp_output_id = ao.erp_output_id
)
UNION
(
SELECT
fc.erp_output_id,
MIN(r.id) AS region_id,
MIN(r.acronym) AS region_name,
MIN(r.order_idx) AS order_idx,
fc.id AS fc_id
FROM
financial_component fc
LEFT JOIN atlas_output ao ON ao.erp_output_id = fc.erp_output_id
INNER JOIN country bu ON bu.id = fc.business_unit_id
INNER JOIN region r ON r.id = bu.region_id
WHERE ao.erp_output_id IS NULL
GROUP BY
fc.id
)
) outputRegion',
'fc.id = outputRegion.fc_id'
);
if($this->ouBreakDownActive()){
$query->leftJoin(
'(
SELECT
ou.code AS ou_code,
r.id AS region_id,
r.acronym AS region_name,
r.order_idx AS region_order_idx
FROM
operating_unit ou
INNER JOIN countries_operating_units cou ON cou.operating_unit_id = ou.id
INNER JOIN country c ON c.id = cou.country_id
INNER JOIN region r ON r.id = c.region_id
GROUP BY ou.code
) afi_region',
'afi_region.ou_code = budgets.operating_unit_code'
);
return;
}
$query->leftJoin(
'(
SELECT
d.base_code AS department_base_code,
r.id AS region_id, r.acronym AS region_name,
r.order_idx AS region_order_idx
FROM
department d
INNER JOIN countries_departments cd ON cd.department_id = d.id
INNER JOIN country c ON c.id = cd.country_id
INNER JOIN region r ON r.id = c.region_id
GROUP BY d.base_code
) afi_region',
'afi_region.department_base_code = budgets.department_base_code'
);
}