Reservations
This commit is contained in:
@@ -317,7 +317,7 @@ class ProjectsController extends MY_Controller {
|
||||
|
||||
if ( $removeReservation->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] );
|
||||
|
||||
Forecast::removeReservation( $reservationID );
|
||||
Reservation::removeReservation( $reservationID );
|
||||
|
||||
$this->json( ['result' => TRUE] );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 13/04/2018
|
||||
* Time: 13:54
|
||||
*/
|
||||
|
||||
class ReservationsController extends MY_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getReservations()
|
||||
{
|
||||
$sql = ReservationTotals::fire();
|
||||
|
||||
$query = $this->db->query( $sql );
|
||||
|
||||
$results = $query->result();
|
||||
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
if ( ! isset( $projects[ $result->projectID ] ) )
|
||||
{
|
||||
$projects[ $result->projectID ] = [
|
||||
'projectnumber' => $result->projectnumber,
|
||||
'reservation' => 0,
|
||||
'payed' => 0,
|
||||
'saldo' => 0,
|
||||
'customers' => []
|
||||
];
|
||||
}
|
||||
|
||||
$projects[ $result->projectID ]['reservation'] += $result->reservation;
|
||||
$projects[ $result->projectID ]['payed'] += $result->payed;
|
||||
$projects[ $result->projectID ]['saldo'] += $result->saldo;
|
||||
|
||||
$projects[ $result->projectID ]['externals'][] = [
|
||||
'external' => $result->contactperson,
|
||||
'reservation' => $result->reservation,
|
||||
'payed' => $result->payed,
|
||||
'saldo' => $result->saldo
|
||||
];
|
||||
}
|
||||
|
||||
$this->json( $projects );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,10 @@ class ReservationValidation extends BaseValidation {
|
||||
'validations' => 'required|integer',
|
||||
'fieldname' => 'project'
|
||||
],
|
||||
'external_id' =>[
|
||||
'validations' => 'required|integer',
|
||||
'fieldname' => 'onderaannemer'
|
||||
],
|
||||
'reservationamount' => [
|
||||
'validations' => 'number',
|
||||
'fieldname' => 'bedrag'
|
||||
|
||||
@@ -11,6 +11,11 @@ class External extends BaseModel {
|
||||
|
||||
protected $table = "externals";
|
||||
|
||||
public function reservations()
|
||||
{
|
||||
return $this->hasMany( 'Reservation' );
|
||||
}
|
||||
|
||||
public static function getAllExternals( $archive )
|
||||
{
|
||||
$externals = External::orderBy( 'name' );
|
||||
@@ -24,24 +29,24 @@ class External extends BaseModel {
|
||||
|
||||
public static function saveExternal( $externalID, $external )
|
||||
{
|
||||
$external = (array)$external;
|
||||
$external = (array) $external;
|
||||
|
||||
if( $externalID == 0)
|
||||
if ( $externalID == 0 )
|
||||
{
|
||||
$external = External::create($external);
|
||||
$external = External::create( $external );
|
||||
$externalID = $external['id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
External::whereId($externalID)->update($external);
|
||||
External::whereId( $externalID )->update( $external );
|
||||
}
|
||||
|
||||
return $externalID;
|
||||
}
|
||||
|
||||
public static function removeExternal($externalID)
|
||||
public static function removeExternal( $externalID )
|
||||
{
|
||||
External::whereId($externalID)->delete();
|
||||
External::whereId( $externalID )->delete();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ class Reservation extends BaseModel {
|
||||
return $this->belongsTo( 'Project' );
|
||||
}
|
||||
|
||||
public function external()
|
||||
{
|
||||
return $this->belongsTo( 'External' );
|
||||
}
|
||||
|
||||
public static function saveReservation( $reservationID, $reservation )
|
||||
{
|
||||
$reservation = (array) $reservation;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by Pensare Software.
|
||||
* User: Theo Weijmer
|
||||
* Date: 13/04/2018
|
||||
* Time: 14:27
|
||||
*/
|
||||
|
||||
class ReservationTotals {
|
||||
|
||||
public static function fire()
|
||||
{
|
||||
$sql = "SELECT projectID, externalID, reservation, payed, (reservation - payed) AS saldo, PRJ.projectnumber, EXT.contactperson
|
||||
FROM (
|
||||
SELECT COALESCE(RES.project_id, PRC.project_id) AS projectID,
|
||||
COALESCE(RES.external_id, PRC.external_id) AS externalID,
|
||||
SUM(COALESCE(reservationamount, 0)) AS reservation,
|
||||
SUM(COALESCE(payed, 0)) AS payed
|
||||
FROM reservations RES
|
||||
LEFT JOIN projectcosts PRC
|
||||
ON RES.project_id = PRC.project_id AND RES.external_id = PRC.external_id
|
||||
GROUP BY COALESCE(RES.project_id, PRC.project_id), COALESCE(PRC.external_id, PRC.external_id)
|
||||
UNION ALL
|
||||
SELECT COALESCE(RES.project_id, PRC.project_id) AS projectID,
|
||||
COALESCE(RES.external_id, PRC.external_id) AS externalID,
|
||||
SUM(COALESCE(reservationamount, 0)) AS reservation,
|
||||
SUM(COALESCE(payed, 0)) AS payed
|
||||
FROM reservations RES
|
||||
RIGHT JOIN projectcosts PRC
|
||||
ON RES.project_id = PRC.project_id AND RES.external_id = PRC.external_id
|
||||
WHERE RES.id IS NULL
|
||||
GROUP BY COALESCE(RES.project_id, PRC.project_id), COALESCE(RES.external_id, PRC.external_id)
|
||||
) Q3
|
||||
JOIN projects PRJ
|
||||
ON PRJ.id = Q3.projectID
|
||||
JOIN externals EXT
|
||||
ON EXT.id = Q3.externalID ";
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
<th class="table-cyanish-header align-right">
|
||||
te betalen
|
||||
</th>
|
||||
<th class="table-cyanish-header" width="40px">
|
||||
<th class="table-cyanish-header" width="50px">
|
||||
|
||||
</th>
|
||||
</thead>
|
||||
@@ -100,7 +100,7 @@
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
<td colspan="7">
|
||||
<button class="btn btn-primary btn-round btn-sm" data-bind="click:newProjectcost">
|
||||
nieuwe projectkosten
|
||||
</button>
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
<div class="panel-body panel-body-project">
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<th class="table-cyanish-header" width="40%">
|
||||
<th class="table-cyanish-header align-right" width="40%">
|
||||
bedrag
|
||||
</th>
|
||||
<th class="table-cyanish-header" width="40%">
|
||||
betaald
|
||||
klant
|
||||
</th>
|
||||
<th class="table-cyanish-header" width="20%"> </th>
|
||||
</thead>
|
||||
<tbody data-bind="foreach:reservations">
|
||||
<tr>
|
||||
<td class="align-right">
|
||||
<td class="align-right" data-bind="css:{'red-line':invalidReservation()}">
|
||||
<span data-bind="visible:!inEdit()">
|
||||
<i class="icon fa-euro"></i>
|
||||
<span data-bind="text:dbo.helpers.numberWithPoints(reservationamount())"></span>
|
||||
@@ -28,13 +28,20 @@
|
||||
data-bind="textInput:reservationamount, visible:inEdit,
|
||||
event:{change:$root.saveReservation,keyup:$root.validateNumber.bind($data, 'reservationamount')}"/>
|
||||
</td>
|
||||
<td>
|
||||
<i class="icon fa-square-o pointer" title="niet betaald"
|
||||
data-bind="click:$root.setPayment.bind($data, 'PAYED'), visible:payed()=='UNPAYED'"></i>
|
||||
<i class="icon fa-check pointer" title="betaald"
|
||||
data-bind="click:$root.setPayment.bind($data, 'UNPAYED'), visible: payed()=='PAYED'"></i>
|
||||
<td data-bind="css:{'red-line':invalidReservation()}">
|
||||
<span data-bind="text:dbo.helpers.findArrayElement('id', 'contactperson', external_id(), $root.externals()),
|
||||
visible:! inEdit()"></span>
|
||||
<select class="form-control"
|
||||
data-bind="
|
||||
options:$root.externals,
|
||||
optionsText:'contactperson',
|
||||
optionsValue:'id',
|
||||
value:external_id,
|
||||
optionsCaption:'selecteer...',
|
||||
visible: inEdit(),
|
||||
event:{change:$root.saveReservation}"
|
||||
</td>
|
||||
<td>
|
||||
<td data-bind="css:{'red-line':invalidReservation()}">
|
||||
<i class="icon fa-edit pointer" title="wijzig" data-bind="click:$root.editReservation"></i>
|
||||
<i class="icon fa-trash redish pointer" title="verwijder"
|
||||
data-bind="click:$root.removeReservation"></i>
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<div id="RESERVATIONS">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<table class="table table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="5px"> </th>
|
||||
<th>project</th>
|
||||
<th class="align-right">gereserveerd</th>
|
||||
<th class="align-right">betaald</th>
|
||||
<th class="align-right">saldo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<!-- ko foreach:projects -->
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
<i class="icon fa-chevron-right"
|
||||
data-bind="click:$root.toggleExternals, visible: ! showExternals()">
|
||||
</i>
|
||||
<i class="icon fa-chevron-down"
|
||||
data-bind="click:$root.toggleExternals, visible:showExternals()">
|
||||
</i>
|
||||
</th>
|
||||
<th>
|
||||
<span data-bind="text:projectnumber"></span>
|
||||
</th>
|
||||
<th class="align-right" data-bind="visible: ! showExternals()">
|
||||
<span data-bind="text:reservation"></span>
|
||||
</th>
|
||||
<th class="align-right" data-bind="visible: ! showExternals()">
|
||||
<span data-bind="text:payed"></span>
|
||||
</th>
|
||||
<th class="align-right" data-bind="visible: ! showExternals()">
|
||||
<span data-bind="text:saldo"></span>
|
||||
</th>
|
||||
</tr>
|
||||
<!-- ko if:showExternals() -->
|
||||
<!-- ko foreach: externals -->
|
||||
<tr>
|
||||
<td width="5px"> </td>
|
||||
<td>
|
||||
<span data-bind="text:externalName"></span>
|
||||
</td>
|
||||
<td class="align-right">
|
||||
<span data-bind="text:reservation"></span>
|
||||
</td>
|
||||
<td class="align-right">
|
||||
<span data-bind="text:payed"></span>
|
||||
</td>
|
||||
<td class="align-right">
|
||||
<span data-bind="text:saldo"></span>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- /ko -->
|
||||
<!-- /ko -->
|
||||
<!-- ko if:showExternals() -->
|
||||
<tr class="subtotal">
|
||||
<th colspan="2">Totaal</th>
|
||||
<th class="align-right">
|
||||
<span data-bind="text:reservation"></span>
|
||||
</th>
|
||||
<th class="align-right">
|
||||
<span data-bind="text:payed"></span>
|
||||
</th>
|
||||
<th class="align-right">
|
||||
<span data-bind="text:saldo"></span>
|
||||
</th>
|
||||
</tr>
|
||||
<!-- /ko -->
|
||||
</tbody>
|
||||
<!-- /ko -->
|
||||
<tfoot>
|
||||
<tr class="grandtotal">
|
||||
<th colspan="2">Grand totaal</th>
|
||||
<th class="align-right"><span data-bind="text:reservation"></span></th>
|
||||
<th class="align-right"><span data-bind="text:payed"></span></th>
|
||||
<th class="align-right"><span data-bind="text:saldo"></span></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -34,6 +34,7 @@
|
||||
<script src="js/lib/modules/reports/monthlyEmployeeHoursModule.js?version=<?= $this->version ?>"></script>
|
||||
<script src="js/lib/modules/reports/employeeHours.js?version=<?= $this->version ?>"></script>
|
||||
<script src="js/lib/modules/reports/outgoingInvoices.js?version=<?= $this->version ?>"></script>
|
||||
<script src="js/lib/modules/reports/reservations.js?version=<?= $this->version ?>"></script>
|
||||
|
||||
<!-- ***********MODALS************* -->
|
||||
|
||||
@@ -62,6 +63,7 @@
|
||||
<script src="js/lib/dataservices/employeehoursDataService.js"></script>
|
||||
<script src="js/lib/dataservices/reportsDataService.js"></script>
|
||||
<script src="js/lib/dataservices/invoiceDataService.js"></script>
|
||||
<script src="js/lib/dataservices/reservationsDataService.js"></script>
|
||||
|
||||
<script src="js/lib/services/chartService.js"></script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user