Reservations

This commit is contained in:
2018-04-13 17:05:13 +02:00
parent 49bd541cb8
commit dbe736d941
14 changed files with 368 additions and 26 deletions
@@ -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
View File
@@ -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">
&nbsp;
</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%">&nbsp;</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">&nbsp;</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">&nbsp;</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>
+2
View File
@@ -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>
+18
View File
@@ -1,3 +1,6 @@
/* @override
http://dbois.local/css/main.css?* */
.redish {
color: #F2353C;
}
@@ -341,3 +344,18 @@ th.focus-green{
top: 0;
opacity: 0;
}
/*************** RESERVATIONS *******************/
.grandtotal {
background-color: #444;
color: #fff;
}
.subtotal {
background-color: #888;
color: #fff;
}
@@ -0,0 +1,20 @@
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 13/04/2018
* Time: 13:35
*/
dbo.reservationsDataservice = {
getReservations: function ( callback ) {
$.getJSON( 'index.php/reports/reservationsController/getReservations', function ( data ) {
callback( data );
} );
}
}
+19 -8
View File
@@ -304,11 +304,12 @@ $( function () {
var vm = dbo.editProjectModal;
var reservation = {
id : 0,
project_id : vm.projectID,
reservationamount: 0,
payed : 'UNPAYED',
inEdit : true
id : 0,
project_id : vm.projectID,
reservationamount : 0,
external_id : null,
inEdit : true,
invalidReservation: true
};
vm.reservations.push( new vm.Reservation( reservation ) );
@@ -485,15 +486,23 @@ $( function () {
var vm = dbo.editProjectModal;
if ( !self ) self = this;
if ( !self.external_id ) {
self.invalidReservation(true);
return;
}
var submitDATA = {
id : self.id,
project_id : self.project_id,
payed : self.payed(),
external_id : self.external_id(),
reservationamount: self.reservationamount()
}
dbo.projectDataService.saveReservation( submitDATA, function ( data ) {
if ( data.success ) self.id = data.reservationID;
if ( data.success ) {
self.invalidReservation(false);
self.id = data.reservationID;
}
} );
},
@@ -878,11 +887,13 @@ $( function () {
},
Reservation: function ( data ) {
console.log( data );
this.id = data.id;
this.project_id = data.project_id;
this.reservationamount = ko.observable( data.reservationamount );
this.payed = ko.observable( data.payed );
this.external_id = ko.observable( data.external_id );
this.inEdit = ko.observable( data.inEdit || false );
this.invalidReservation = ko.observable( data.invalidReservation || false );
},
addDocument: function ( data, evt ) {
@@ -0,0 +1,92 @@
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 13/04/2018
* Time: 13:31
*/
dbo.reservationsInit = function () {
if ( dbo.reservationsModel !== undefined ) {
} else {
dbo.reservationsModel = {
projects : ko.observableArray( [] ),
reservation: ko.observable(),
payed : ko.observable(),
saldo : ko.observable(),
init: function () {
var vm = dbo.reservationsModel;
vm.refreshReservations();
},
refreshReservations: function () {
var vm = dbo.reservationsModel;
dbo.reservationsDataservice.getReservations( function ( data ) {
vm.projects.removeAll();
vm.reservation( 0 );
vm.payed( 0 );
vm.saldo( 0 );
_.each( data, function ( p ) {
vm.projects.push( new vm.Project( p ) );
} );
vm.reservation( dbo.helpers.numberWithPoints( vm.reservation() ) );
vm.payed( dbo.helpers.numberWithPoints( vm.payed() ) );
vm.saldo( dbo.helpers.numberWithPoints( vm.saldo() ) );
} );
},
toggleExternals: function () {
this.showExternals( !this.showExternals() );
},
Project: function ( data ) {
var vm = dbo.reservationsModel;
var self = this;
self.projectnumber = data.projectnumber;
self.reservation = dbo.helpers.numberWithPoints( data.reservation );
self.payed = dbo.helpers.numberWithPoints( data.payed );
self.saldo = dbo.helpers.numberWithPoints( data.saldo );
self.showExternals = ko.observable( false );
vm.reservation( Number( vm.reservation() ) + Number( data.reservation ) );
vm.payed( Number( vm.payed() ) + Number( data.payed ) );
vm.saldo( Number( vm.saldo() ) + Number( data.saldo ) );
self.externals = ko.observableArray( [] );
_.each( data.externals, function ( p ) {
self.externals.push( new vm.External( p ) );
} )
},
External: function ( data ) {
var self = this;
self.externalName = data.external;
self.reservation = dbo.helpers.numberWithPoints( data.reservation );
self.payed = dbo.helpers.numberWithPoints( data.payed );
self.saldo = dbo.helpers.numberWithPoints( data.saldo );
}
}
}
dbo.reservationsModel.init();
ko.applyBindings(
dbo.reservationsModel, document.getElementById( "RESERVATIONS" ) );
}