144 lines
3.2 KiB
PHP
144 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 31/10/2019
|
|
* Time: 14:53
|
|
*/
|
|
|
|
class DashboardController extends MY_Controller {
|
|
|
|
private $invoiceOverviews = [];
|
|
|
|
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->setInvoiceOverview();
|
|
|
|
$this->json( [
|
|
'totalOwp' => round( $totalOwp, 0 ),
|
|
'revenuesThisYear' => $this->getRevenuesThisYear(),
|
|
'currentFinancialYear' => round( $currentFinancialYear ),
|
|
'owpNextyear' => round( $totalOwp - $currentFinancialYear ),
|
|
'revenuesNextyear' => round( $totalOwp / 0.4 ),
|
|
'totalRevenues' => round( $totalRevenues ),
|
|
'outstandings' => $this->invoiceOverviews,
|
|
'costsToPay' => $this->reservations(),
|
|
'invoiced' => $this->getInvoiced(),
|
|
'totalChance' => $this->getChanceRevenues(),
|
|
'totalPayment' => round( Payment::getPaymentInYear( date( 'Y' )))
|
|
] );
|
|
}
|
|
|
|
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 setInvoiceOverview()
|
|
{
|
|
$projects = Project::whereArchive( 'F' )->get();
|
|
|
|
foreach ( $projects as $project )
|
|
{
|
|
$invoiceOverview = new InvoiceOverview( $project, date( 'Y' ) );
|
|
|
|
$this->invoiceOverviews[] = $invoiceOverview->getProjectDetails();
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
private function getInvoiced()
|
|
{
|
|
$invoiced = Invoice::getInvoiced( date( 'Y' ) );
|
|
|
|
$totalInvoiced = 0;
|
|
foreach ( $invoiced as $invoice )
|
|
{
|
|
$totalInvoiced += ROUND( ( $invoice->invoiceamount * 1.21 ), 0 );
|
|
}
|
|
|
|
return $totalInvoiced;
|
|
}
|
|
|
|
private function getChanceRevenues()
|
|
{
|
|
$offers = Offer::getAllOffers( FALSE, 'F', '', 'id', 'desc' );
|
|
|
|
$totalChance = 0;
|
|
foreach ( $offers as $offer )
|
|
{
|
|
$totalChance +=
|
|
ROUND(
|
|
( $offer->own_revenue + $offer->other_revenue ) *
|
|
( $offer->acceptance_chance / 100 ), 0 );
|
|
}
|
|
|
|
return $totalChance;
|
|
}
|
|
|
|
}
|