Diversen debug

This commit is contained in:
2018-07-31 15:15:54 +02:00
parent c520c3386a
commit 26f16ee088
8 changed files with 71 additions and 43 deletions
@@ -12,7 +12,8 @@ class ReservationTotals {
{
// UNION ALL wordt gebruikt voor een full outer join
$sql = "SELECT Q5.project_id AS projectID, external_id AS externalID,
Q5.costs, reservation, payed, (reservation - payed) AS saldo,
fromreservation,
Q5.costs, reservation, payed, (reservation - fromreservation) AS saldo,
(Q5.costs - payed) AS saldoToPay, PRJ.projectnumber, EXT.contactperson,
ROUND(( (OFF.costs * (100 + (SELECT vatrate
FROM vats VTS
@@ -20,7 +21,8 @@ class ReservationTotals {
ON VTS.id = P.vat_id
WHERE P.id = PRJ.id LIMIT 1))) / 100 ), 0) other_revenue
FROM (
SELECT COALESCE(reservation, 0) AS reservation, costs, payed, Q2.external_id, Q2.project_id
SELECT COALESCE(reservation, 0) AS reservation, costs, payed, Q2.external_id, Q2.project_id,
IF(from_reservation = 'T', payed, 0) fromreservation
FROM (
SELECT SUM(reservationamount) AS reservation, external_id, project_id
FROM reservations
@@ -28,14 +30,14 @@ class ReservationTotals {
) Q1
RIGHT JOIN
(
SELECT SUM(costs) AS costs, SUM(payed) AS payed, external_id, project_id
SELECT SUM(costs) AS costs, SUM(payed) AS payed, external_id, project_id, from_reservation
FROM projectcosts
WHERE from_reservation = 'T'
GROUP BY external_id, project_id
) Q2
ON Q1.external_id = Q2.external_id AND Q1.project_id = Q2.project_id
UNION ALL
SELECT reservation, COALESCE(costs, 0), COALESCE(payed, 0), Q3.external_id, Q3.project_id
SELECT reservation, COALESCE(costs, 0), COALESCE(payed, 0), Q3.external_id, Q3.project_id,
IF(from_reservation = 'T', payed, 0) fromreservation
FROM (
SELECT SUM(reservationamount) AS reservation, external_id, project_id
FROM reservations
@@ -43,9 +45,8 @@ class ReservationTotals {
) Q3
LEFT JOIN
(
SELECT SUM(costs) AS costs, SUM(payed) AS payed, external_id, project_id, id
SELECT SUM(costs) AS costs, SUM(payed) AS payed, external_id, project_id, id, from_reservation
FROM projectcosts
WHERE from_reservation = 'T'
GROUP BY external_id, project_id
) Q4
ON Q3.external_id = Q4.external_id AND Q3.project_id = Q4.project_id