Changed query which is used to obtain certain person target sets. Most joins are
now left joins, otherwise the query would drop all targets without assigned sub-bookings.
This commit is contained in:
@@ -200,15 +200,15 @@ class PersonTarget extends Model
|
|||||||
$selection = DB::select('
|
$selection = DB::select('
|
||||||
SELECT
|
SELECT
|
||||||
p_t.*,
|
p_t.*,
|
||||||
p_t.amount * i_o2.factor as target,
|
p_t.amount * i_o2.factor AS target,
|
||||||
sum(i_o1.factor * s_b.amount) as actual
|
IFNULL(SUM(i_o1.factor * s_b.amount), 0) AS actual
|
||||||
FROM sub_bookings s_b
|
FROM person_targets p_t
|
||||||
INNER JOIN account_types a_t ON a_t.id = s_b.account_type_id
|
|
||||||
INNER JOIN account_classes a_c ON a_c.id = a_t.account_class_id
|
|
||||||
INNER JOIN i_o_types i_o1 ON i_o1.id = a_c.io_type_id
|
|
||||||
INNER JOIN person_targets p_t ON p_t.id = s_b.person_target_id
|
|
||||||
INNER JOIN i_o_types i_o2 ON i_o2.id = p_t.io_type_id
|
INNER JOIN i_o_types i_o2 ON i_o2.id = p_t.io_type_id
|
||||||
GROUP BY s_b.person_target_id
|
LEFT JOIN sub_bookings s_b ON p_t.id = s_b.person_target_id
|
||||||
|
LEFT JOIN account_types a_t ON a_t.id = s_b.account_type_id
|
||||||
|
LEFT JOIN account_classes a_c ON a_c.id = a_t.account_class_id
|
||||||
|
LEFT JOIN i_o_types i_o1 ON i_o1.id = a_c.io_type_id
|
||||||
|
GROUP BY p_t.id
|
||||||
HAVING ' . $having . ';');
|
HAVING ' . $having . ';');
|
||||||
|
|
||||||
// Remove the unused columns 'target' and 'actual' from the query
|
// Remove the unused columns 'target' and 'actual' from the query
|
||||||
|
|||||||
Reference in New Issue
Block a user