diff --git a/application/controllers/dashboard/DashboardController.php b/application/controllers/dashboard/DashboardController.php index baefb07..1fa1efc 100644 --- a/application/controllers/dashboard/DashboardController.php +++ b/application/controllers/dashboard/DashboardController.php @@ -42,12 +42,15 @@ class DashboardController extends MY_Controller { $available += $project['budgetAvailable']; } + $outstandings = $this->Invoices_model-> getTotalsOutstandingPerProject(); + $this->json( [ - 'totalOwp' => $totalOwp, - 'currentFinancialYear' => $currentFinancialYear, - 'owpNextyear' => $totalOwp - $currentFinancialYear, - 'revenuesNextyear' => $totalOwp / 0.4, - 'totalRevenues' => $totalRevenues + 'totalOwp' => round( $totalOwp, 0 ), + 'currentFinancialYear' => round( $currentFinancialYear ), + 'owpNextyear' => round( $totalOwp - $currentFinancialYear ), + 'revenuesNextyear' => round( $totalOwp / 0.4 ), + 'totalRevenues' => round( $totalRevenues ), + 'outstandings' => $outstandings ] ); } diff --git a/application/models/eloquent/Projectemployee.php b/application/models/eloquent/Projectemployee.php index 48b7372..15626df 100644 --- a/application/models/eloquent/Projectemployee.php +++ b/application/models/eloquent/Projectemployee.php @@ -8,113 +8,70 @@ class Projectemployee extends BaseModel { - public function project() - { - return $this->belongsTo( 'Project' ); - } + public function project() + { + return $this->belongsTo( 'Project' ); + } -<<<<<<< Updated upstream - public function user() - { - return $this->belongsTo( 'User' ); - } + public function user() + { + return $this->belongsTo( 'User' ); + } - public function projecthours() - { - return $this->hasMany( 'Projecthour' ); - } + public function projecthours() + { + return $this->hasMany( 'Projecthour' ); + } - public static function getAvailableEmployees( $projectID ) - { - $currentEmployees = Self::whereProjectId( $projectID ) - ->lists( 'user_id' ); + public static function getAvailableEmployees( $projectID ) + { + $currentEmployees = Self::whereProjectId( $projectID ) + ->lists( 'user_id' ); - $availableEmployees = User::selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) - ->whereNotIn( 'id', $currentEmployees ) - ->whereArchive( 'F' ) - ->get(); + $availableEmployees = User::selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) + ->whereNotIn( 'id', $currentEmployees ) + ->whereArchive( 'F' ) + ->get(); - return $availableEmployees; - } + return $availableEmployees; + } - public static function getUniqueProjectEmployees() - { - $projectemployees = Projectemployee::selectRaw( "USR.id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) - ->distinct() - ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) - ->get(); + public static function getUniqueProjectEmployees() + { + $projectemployees = Projectemployee::selectRaw( "USR.id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) + ->distinct() + ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) + ->get(); - return $projectemployees; - } + return $projectemployees; + } - public static function getProjectemployeeDetailsPerProject( $projectID ) - { - $details = Projectemployee::selectRaw( 'USR.id, budget, project_id, ROUND(SUM(hours), 0) AS hours, ROUND(SUM(hours * tarif), 0) AS revenues, projectemployees.id AS projectemployeeID' ) - ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) - ->join( 'projecthours AS PRH', 'PRH.projectemployee_id', '=', 'projectemployees.id' ) - ->where( 'projectemployees.project_id', '=', $projectID ) - ->where( 'PRH.hourtype_id', '=', 1 ) - ->groupBy( 'projectemployees.id' ) - ->get(); + public static function getUniqueEmployeesWithActivity( $archive = 'F' ) + { + $projectemployees = Projectemployee::selectRaw( "USR.id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ) + ->distinct() + ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) + ->join( 'projectemployees AS PRE', 'PRE.user_id', '=', 'USR.id' ) + ->join( 'projects AS PRJ', 'PRJ.id', '=', 'PRE.project_id' ); - return $details; - } + if ( $archive == 'F' ) $projectemployees = $projectemployees->where( 'PRJ.archive', '=', 'F' ); - public static function firstOrCreateProjectemployee( $userID, $projectID ) - { - $projectemployee = self::whereUserId($userID)->whereProjectId($projectID); + $projectemployees = $projectemployees->get(); - if( $projectemployee->count() > 0 ) return $projectemployee->first(); + return $projectemployees; + } - $user = User::find( $userID ); - - $tarif = $user ? $user->hourlyrate : 0; - - $projectemployee = Projectemployee::create( [ - 'project_id' => $projectID, - 'user_id' => $userID, - 'tarif' => $tarif - ] ); - - return $projectemployee; - } - - public static function createProjectEmployee( $projectID ) - { - $projectemployee = Projectemployee::create( [ - 'project_id' => $projectID - ] ); - - return $projectemployee->id; - } - - public static function saveProjectemployee( $projectemployeeID, $projectemployee ) - { - Projectemployee::whereId( $projectemployeeID ) - ->update( $projectemployee ); - } - - public static function removeProjectemployee( $projectemployeeID ) - { - Projectemployee::whereId( $projectemployeeID )->delete(); - } - -} -======= public static function getProjectemployeeDetailsPerProject( $projectID ) { $details = Projectemployee::selectRaw( ' USR.id, budget, project_id, ROUND(SUM(hours), 0) AS hours, ROUND(SUM(hours * tarif), 0) AS revenues, projectemployees.id AS projectemployeeID' ) ->join( 'users AS USR', 'USR.id', '=', 'projectemployees.user_id' ) ->join( 'projecthours AS PRH', 'PRH.projectemployee_id', '=', 'projectemployees.id' ) + ->where( 'projectemployees.project_id', '=', $projectID ) ->where( 'PRH.hourtype_id', '=', 1 ) // ->where( 'budget', '!=', 0 ) ->groupBy( 'projectemployees.id' ) ->havingRaw( 'ROUND(SUM(hours), 0) > 0' ); - - if( $projectID) - $details = $details->where( 'projectemployees.project_id', '=', $projectID ); - $details = $details->get(); return $details; @@ -160,4 +117,3 @@ class Projectemployee extends BaseModel { } } ->>>>>>> Stashed changes diff --git a/application/models/projects/Invoices_model.php b/application/models/projects/Invoices_model.php index 2bbdef1..3c28eff 100644 --- a/application/models/projects/Invoices_model.php +++ b/application/models/projects/Invoices_model.php @@ -54,4 +54,60 @@ class Invoices_model extends MY_Model { return $invoiceDetails; } -} \ No newline at end of file + + public function getTotalsOutstandingPerProject() + { + $this->sql = " + SELECT + PRJ.id, + projectnumber, + projectname, + SUM(invoiced) AS invoiced, + SUM(payment) AS payment, + revenues, + costs, + COALESCE(payedcosts, 0) AS payedcosts + FROM ( + SELECT + project_id, + ROUND(SUM(invoiceamount * (1 + (vatrate / 100))), 0) AS invoiced, + payment + FROM + invoices INV + JOIN vats VAT ON VAT.id = INV.vat_id + LEFT JOIN ( + SELECT + ROUND(COALESCE(SUM(paymentamount), 0), 0) AS payment, + invoice_id + FROM + payments + GROUP BY + invoice_id) AS Q1 ON INV.id = Q1.invoice_id + GROUP BY + INV.id) Q2 + JOIN projects PRJ ON PRJ.id = Q2.project_id + JOIN ( + SELECT + ROUND((own_revenue + other_revenue + costs) * (1 + (vatrate / 100)), 0) revenues, + ROUND(costs * (1 + (vatrate / 100)), 0) costs, + OFF.project_id + FROM + offers OFF + JOIN projects PRJ ON PRJ.id = OFF.project_id + JOIN vats VAT ON VAT.id = PRJ.vat_id) Q3 ON Q3.project_id = PRJ.id + LEFT JOIN ( + SELECT + SUM(costs) AS payedcosts, + project_id + FROM + projectcosts + GROUP BY + project_id) Q4 ON Q4.project_id = PRJ.id + GROUP BY + PRJ.id "; + + $outstandings = $this->get_query_result(); + + return $outstandings; + } +} diff --git a/application/views/main_view.php b/application/views/main_view.php index 7effca0..0026de9 100644 --- a/application/views/main_view.php +++ b/application/views/main_view.php @@ -5,6 +5,8 @@ + + ** De Beleidsonderzoeker ** @@ -12,7 +14,8 @@ load->view( 'partials/_css' ); ?> load->view( 'partials/_fonts' ); ?> - + + diff --git a/application/views/pages/dashboard_view.php b/application/views/pages/dashboard_view.php index 1aaead2..b8ec3eb 100644 --- a/application/views/pages/dashboard_view.php +++ b/application/views/pages/dashboard_view.php @@ -1,44 +1,90 @@
-
-
-
-

+
+
+
+

Onderhanden werkpositie

-
+

- Onderhanden werkpositie huidig jaar: - + Onderhanden werkpositie huidig jaar: +

- Onderhanden werkpositie volgend jaar: - + Onderhanden werkpositie volgend jaar: +

- Totaal: - + Totaal: +

-
-
-
-

+
+
+
+

Omzet

-
+

- Omzet komende jaar: - + Omzet komende jaar: +

- Omzet totaal gerealiseerd lopend jaar: - + Omzet totaal gerealiseerd lopend jaar: + +

+
+
+
+
+
+
+
+
+

+ Facturatie +

+
+
+
+

+ Openstaande facturen (incl btw): + +

+

+ Nog te factureren (incl btw): + +

+
+
+
+
+
+
+

+ Resultaat +

+
+
+
+

+ Kosten derden (excl btw): + +

+

+ Saldo inkomsten (excl btw): + +

+

+ Omzet lopend jaar (excl btw): +

diff --git a/application/views/pages/login/login_view.php b/application/views/pages/login/login_view.php index c1032ca..08e38c4 100644 --- a/application/views/pages/login/login_view.php +++ b/application/views/pages/login/login_view.php @@ -20,7 +20,6 @@ - @@ -102,42 +101,16 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/public/css/dashboard.css b/public/css/dashboard.css new file mode 100644 index 0000000..5cd8648 --- /dev/null +++ b/public/css/dashboard.css @@ -0,0 +1,51 @@ +/* @override + http://dbois.test/css/dashboard.css */ +#DASHBOARD { + font-family: 'Libre Franklin', sans-serif; +} +.db-panel { + float: left; + width: 50%; + padding: 5px; + /*border: 1px solid #333;*/ + color: #fff; +} +.db-panel-holder { + padding: 15px; + border-radius: 5px; + box-shadow: 5px 5px 10px #aaa; + height: 270px; +} +.db-panel-success { + background-color: #616236; +} +.db-panel-warning { + background-color: #db9c01; + /*color: #256;*/ +} +.db-panel-danger { + background-color: #930125; +} +.db-panel-info { + background-color: #202737; +} +.db-panel-holder h3 { + font-weight: bold; +} +.db-panel-holder h3, .db-panel-holder h4 { + padding: 0; + margin: 0; +} +.db-panel-label { + line-height: 2em; +} +.db-panel-body h4 { + margin-bottom: 15px; + border-bottom: 1px solid #fff; + padding-bottom: 10px; + /*text-align: right;*/ +} + .db-panel-data { + float: right; + margin-top: 10px; + } diff --git a/public/js/lib/modules/dashboard/dashboardModule.js b/public/js/lib/modules/dashboard/dashboardModule.js index aa99df7..8b5b8de 100644 --- a/public/js/lib/modules/dashboard/dashboardModule.js +++ b/public/js/lib/modules/dashboard/dashboardModule.js @@ -6,7 +6,7 @@ */ dbo.dashboardInit = function () { - console.log( dbo.dashboardModel ); + if ( dbo.dashboardModel !== undefined ) { dbo.dashboardModel.init(); @@ -15,21 +15,56 @@ dbo.dashboardInit = function () { dbo.dashboardModel = { - owpThisYear : ko.observable( null ), - owpNextYear : ko.observable( null ), - owpTotal : ko.observable( null ), - revenuesNextyear: ko.observable( null ), - totalRevenues : ko.observable( null ), + owpThisYear : ko.observable( null ), + owpNextYear : ko.observable( null ), + owpTotal : ko.observable( null ), + revenuesNextyear : ko.observable( null ), + totalRevenues : ko.observable( null ), + outstanding : ko.observable( null ), + toInvoice : ko.observable( null ), + openCosts : ko.observable( null ), + revenues : ko.observable( null ), + revenues : ko.observable( null ), + revenueCurrentYear: ko.observable( null ), init: function () { var self = dbo.dashboardModel; dbo.dashboardDataservice.getOwhp( function ( data ) { + var outstandings = self.getOutstandingTotal( data.outstandings ); + var revCurYear = Number( data.currentFinancialYear ) + Number( data.totalOwp ); + self.owpThisYear( dbo.helpers.thousandSeparator( data.currentFinancialYear ) ); self.owpNextYear( dbo.helpers.thousandSeparator( data.owpNextyear ) ); self.owpTotal( dbo.helpers.thousandSeparator( data.totalOwp ) ); self.revenuesNextyear( dbo.helpers.thousandSeparator( data.revenuesNextyear ) ); self.totalRevenues( dbo.helpers.thousandSeparator( data.totalRevenues ) ); + self.outstanding( dbo.helpers.thousandSeparator( outstandings.open ) ); + self.toInvoice( dbo.helpers.thousandSeparator( outstandings.toInvoice ) ); + self.openCosts( dbo.helpers.thousandSeparator( outstandings.openCosts ) ); + self.revenues( dbo.helpers.thousandSeparator( outstandings.revenues ) ); + self.revenueCurrentYear( dbo.helpers.thousandSeparator( revCurYear ) ); } ); + }, + + getOutstandingTotal: function ( data ) { + var open = 0; + var toInvoice = 0; + var costs = 0; + var openCosts = 0; + _.each( data, function ( p ) { + open += Number( p.invoiced ) - Number( p.payment ); + toInvoice += Number( p.revenues ) - Number( p.invoiced ); + costs += Number( p.costs ); + openCosts += Number( p.costs ) - Number( p.payedcosts ) + } ); + var revenues = (Number( open ) + Number( toInvoice ) - Number( openCosts )) / 1.21; + return { + open : open, + toInvoice: toInvoice, + costs : costs, + revenues : Math.round( revenues ), + openCosts: openCosts + }; } };