Conversie codeigniter 4
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Reports;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
|
||||
class ReservationsController extends BaseController
|
||||
{
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
||||
die('NO ACCESS');
|
||||
}
|
||||
}
|
||||
|
||||
public function getReservations(): ResponseInterface
|
||||
{
|
||||
$sql = \ReservationTotals::fire();
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$query = $db->query($sql);
|
||||
|
||||
$results = $query->getResult();
|
||||
|
||||
$projects = [];
|
||||
foreach ($results as $result) {
|
||||
if (!isset($projects[$result->projectID])) {
|
||||
$projects[$result->projectID] = [
|
||||
'projectnumber' => $result->projectnumber,
|
||||
'projectname' => $result->projectname,
|
||||
'costs' => 0,
|
||||
'reservation' => 0,
|
||||
'payed' => 0,
|
||||
'fromreservation' => 0,
|
||||
'saldo' => 0,
|
||||
'saldoToPay' => 0,
|
||||
'other_revenue' => 0,
|
||||
'customers' => [],
|
||||
'externals' => []
|
||||
];
|
||||
}
|
||||
|
||||
$projects[$result->projectID]['reservation'] += $result->reservation;
|
||||
$projects[$result->projectID]['costs'] += $result->costs;
|
||||
$projects[$result->projectID]['payed'] += $result->payed;
|
||||
$projects[$result->projectID]['fromreservation'] += $result->fromreservation;
|
||||
$projects[$result->projectID]['saldo'] += $result->saldo;
|
||||
$projects[$result->projectID]['saldoToPay'] += $result->saldoToPay;
|
||||
$projects[$result->projectID]['other_revenue'] = $result->other_revenue;
|
||||
|
||||
$projects[$result->projectID]['externals'][] = [
|
||||
'external' => $result->contactperson,
|
||||
'reservation' => $result->reservation,
|
||||
'costs' => $result->costs,
|
||||
'payed' => $result->payed,
|
||||
'saldo' => $result->saldo,
|
||||
'fromreservation' => $result->fromreservation,
|
||||
'saldoToPay' => $result->saldoToPay
|
||||
];
|
||||
}
|
||||
|
||||
return $this->json($projects);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user