From 92a460f0fff2957a14d1bfd46044d6734cfe2660 Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Mon, 7 Oct 2019 19:45:42 +0200 Subject: [PATCH] reservations sdjusted --- .../reports/ReservationsController.php | 2 +- application/models/eloquent/Project.php | 15 +++++++++++-- .../eloquent/queries/ReservationTotals.php | 21 +++++++++++-------- .../views/modals/partials/_reservations.php | 2 +- application/views/pages/reservations_view.php | 2 +- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/application/controllers/reports/ReservationsController.php b/application/controllers/reports/ReservationsController.php index c2f8eaa..e2eaa6a 100644 --- a/application/controllers/reports/ReservationsController.php +++ b/application/controllers/reports/ReservationsController.php @@ -60,4 +60,4 @@ class ReservationsController extends MY_Controller { $this->json( $projects ); } -} \ No newline at end of file +} diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php index 7736d28..6e24fca 100644 --- a/application/models/eloquent/Project.php +++ b/application/models/eloquent/Project.php @@ -82,8 +82,8 @@ class Project extends BaseModel { { $project = Project::getBaseProject(); - $project = $project->whereArchive( 'F' ) - ->whereId( $projectID ) + $project = $project->whereId( $projectID ) +// ->whereArchive( 'F' ) ->first(); return $project; @@ -179,4 +179,15 @@ class Project extends BaseModel { self::whereId( $offer->project_id ) ->update( ['projectname' => $offer->offername] ); } + + public static function getProjectsWithExternalCosts( $projects ) + { + $projectCosts = self::selectRAW( 'projects.id, OFF.costs' ) + ->join( 'offers AS OFF', 'OFF.project_id', '=', 'projects.id' ) + ->whereNotIn( 'projects.id', $projects ) + ->where( 'OFF.costs', '>', 0 ) + ->get(); + + return $projectCosts; + } } diff --git a/application/models/eloquent/queries/ReservationTotals.php b/application/models/eloquent/queries/ReservationTotals.php index 3331003..44f7002 100644 --- a/application/models/eloquent/queries/ReservationTotals.php +++ b/application/models/eloquent/queries/ReservationTotals.php @@ -11,10 +11,11 @@ class ReservationTotals { public static function fire() { // UNION ALL wordt gebruikt voor een full outer join - $sql = "SELECT Q5.project_id AS projectID, external_id AS externalID, - fromreservation, - Q5.costs, reservation, payed, (reservation - fromreservation) AS saldo, - (Q5.costs - payed) AS saldoToPay, PRJ.projectnumber, EXT.contactperson, + $sql = " SELECT PRJ.id AS projectID, external_id AS externalID, + COALESCE(fromreservation, 0) AS fromreservation, + COALESCE(Q5.costs, 0) AS costs, COALESCE(reservation, 0) AS reservation, + COALESCE(payed, 0) AS payed, (COALESCE(reservation, 0) - COALESCE(fromreservation, 0)) AS saldo, + (COALESCE(Q5.costs, 0) - COALESCE(payed, 0)) AS saldoToPay, PRJ.projectnumber, EXT.contactperson, ROUND(( (OFF.costs * (100 + (SELECT vatrate FROM vats VTS JOIN projects P @@ -52,12 +53,14 @@ class ReservationTotals { ON Q3.external_id = Q4.external_id AND Q3.project_id = Q4.project_id WHERE Q4.id IS NULL ) Q5 - JOIN projects PRJ + RIGHT JOIN projects PRJ ON PRJ.id = Q5.project_id - JOIN externals EXT - ON EXT.id = Q5.external_id - JOIN offers OFF - ON PRJ.id = OFF.project_id "; + LEFT JOIN offers OFF + ON PRJ.id = OFF.project_id + LEFT JOIN externals EXT + ON EXT.id = Q5.external_id + WHERE OFF.costs > 0 + AND PRJ.archive = 'F'"; return $sql; } diff --git a/application/views/modals/partials/_reservations.php b/application/views/modals/partials/_reservations.php index a1a923c..2500a13 100644 --- a/application/views/modals/partials/_reservations.php +++ b/application/views/modals/partials/_reservations.php @@ -1,7 +1,7 @@

- budget onderaannemers (incl. btw) + budget gereserveerd (incl. btw)

diff --git a/application/views/pages/reservations_view.php b/application/views/pages/reservations_view.php index 17dcac5..57386ff 100644 --- a/application/views/pages/reservations_view.php +++ b/application/views/pages/reservations_view.php @@ -11,7 +11,7 @@ project Kosten derden factuur INK - budget onderaannemers + budget gereserveerd betaald saldo te
betalen betaald via
reserveringen