110 lines
2.4 KiB
PHP
110 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 31/10/2019
|
|
* Time: 14:53
|
|
*/
|
|
|
|
class DashboardController extends MY_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function getOwhp()
|
|
{
|
|
$recapprojects = new Recapprojects( 'F', FALSE, FALSE );
|
|
|
|
$projects = $recapprojects->getProjects();
|
|
|
|
$currentFinancialYear = 0;
|
|
$totalRevenues = 0;
|
|
$totalOwp = 0;
|
|
$ownRevenue = 0;
|
|
$available = 0;
|
|
foreach ( $projects as $project )
|
|
{
|
|
$revenues = 0;
|
|
foreach ( $project['employees'] as $employee )
|
|
{
|
|
$revenues += $employee['revenues'];
|
|
}
|
|
$currentFinancialYear += $project['current_financial_year'];
|
|
|
|
$owp = $project['own_revenue'] - $revenues;
|
|
$owp = $owp > 0 ? $owp : 0;
|
|
$totalOwp += $owp;
|
|
|
|
$ownRevenue += $project['own_revenue'];
|
|
$totalRevenues += $revenues;
|
|
$available += $project['budgetAvailable'];
|
|
}
|
|
|
|
$outstandings = $this->Invoices_model->getTotalsOutstandingPerProject(FALSE);
|
|
|
|
$this->json( [
|
|
'totalOwp' => round( $totalOwp, 0 ),
|
|
'revenuesThisYear' => $this->getRevenuesThisYear(),
|
|
'currentFinancialYear' => round( $currentFinancialYear ),
|
|
'owpNextyear' => round( $totalOwp - $currentFinancialYear ),
|
|
'revenuesNextyear' => round( $currentFinancialYear / 0.4 ),
|
|
'totalRevenues' => round( $totalRevenues ),
|
|
'outstandings' => $this->getInvoiceOverview(),
|
|
'costsToPay' => $this->reservations()
|
|
] );
|
|
}
|
|
|
|
private function getRevenuesThisYear()
|
|
{
|
|
$year = date('Y');
|
|
$sql = QEmployeeHours::fire( FALSE, $year );
|
|
|
|
$query = $this->db->query( $sql );
|
|
|
|
$result = $query->result();
|
|
|
|
$totalRevenue = 0;
|
|
foreach($result as $revenue)
|
|
{
|
|
$totalRevenue += $revenue->revenues;
|
|
}
|
|
|
|
return $totalRevenue;
|
|
}
|
|
|
|
private function getInvoiceOverview( )
|
|
{
|
|
$projects = Project::whereArchive('F')->get();
|
|
|
|
foreach($projects as $project)
|
|
{
|
|
$invoiceOverview = new InvoiceOverview( $project, date('Y') );
|
|
|
|
$invoiceOverviews[] = $invoiceOverview->getProjectDetails();
|
|
}
|
|
|
|
return $invoiceOverviews;
|
|
}
|
|
|
|
private function reservations()
|
|
{
|
|
$sql = ReservationTotals::fire();
|
|
|
|
$query = $this->db->query( $sql );
|
|
|
|
$results = $query->result();
|
|
|
|
$costsToPay = 0;
|
|
foreach($results as $result)
|
|
{
|
|
$toPay = $result->other_revenue - $result->costs + $result->saldoToPay;
|
|
$costsToPay += $toPay;
|
|
}
|
|
|
|
return $costsToPay;
|
|
}
|
|
|
|
}
|