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:
Lukas Halbritter
2018-10-23 23:34:16 +02:00
parent cda399a9f2
commit c8b08da62a
+8 -8
View File
@@ -200,15 +200,15 @@ class PersonTarget extends Model
$selection = DB::select('
SELECT
p_t.*,
p_t.amount * i_o2.factor as target,
sum(i_o1.factor * s_b.amount) as actual
FROM sub_bookings s_b
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
p_t.amount * i_o2.factor AS target,
IFNULL(SUM(i_o1.factor * s_b.amount), 0) AS actual
FROM person_targets p_t
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 . ';');
// Remove the unused columns 'target' and 'actual' from the query