diff --git a/application/controllers/projects/ProjectsController.php b/application/controllers/projects/ProjectsController.php index c553f25..f441088 100644 --- a/application/controllers/projects/ProjectsController.php +++ b/application/controllers/projects/ProjectsController.php @@ -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] ); } diff --git a/application/controllers/reports/ReservationsController.php b/application/controllers/reports/ReservationsController.php new file mode 100644 index 0000000..eb96895 --- /dev/null +++ b/application/controllers/reports/ReservationsController.php @@ -0,0 +1,52 @@ +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 ); + } + +} \ No newline at end of file diff --git a/application/libraries/validation/inputValidations/ReservationValidation.php b/application/libraries/validation/inputValidations/ReservationValidation.php index 7b72c54..c029a43 100644 --- a/application/libraries/validation/inputValidations/ReservationValidation.php +++ b/application/libraries/validation/inputValidations/ReservationValidation.php @@ -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' diff --git a/application/models/eloquent/External.php b/application/models/eloquent/External.php index e35b75d..d5ed07e 100644 --- a/application/models/eloquent/External.php +++ b/application/models/eloquent/External.php @@ -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(); } diff --git a/application/models/eloquent/Reservation.php b/application/models/eloquent/Reservation.php index d3f6c49..9fa3481 100644 --- a/application/models/eloquent/Reservation.php +++ b/application/models/eloquent/Reservation.php @@ -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; diff --git a/application/models/eloquent/queries/ReservationTotals.php b/application/models/eloquent/queries/ReservationTotals.php new file mode 100644 index 0000000..05ea508 --- /dev/null +++ b/application/models/eloquent/queries/ReservationTotals.php @@ -0,0 +1,42 @@ + te betalen - +   @@ -100,7 +100,7 @@ - + diff --git a/application/views/modals/partials/_reservations.php b/application/views/modals/partials/_reservations.php index a8295ee..15fe9bd 100644 --- a/application/views/modals/partials/_reservations.php +++ b/application/views/modals/partials/_reservations.php @@ -7,17 +7,17 @@
- - -
+ bedrag - betaald + klant  
+ @@ -28,13 +28,20 @@ data-bind="textInput:reservationamount, visible:inEdit, event:{change:$root.saveReservation,keyup:$root.validateNumber.bind($data, 'reservationamount')}"/> - - + + + + diff --git a/application/views/pages/reservations_view.php b/application/views/pages/reservations_view.php new file mode 100644 index 0000000..2e4cb83 --- /dev/null +++ b/application/views/pages/reservations_view.php @@ -0,0 +1,84 @@ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 projectgereserveerdbetaaldsaldo
+ + + + + + + + + + + + +
  + + + + + + + +
Totaal + + + + + +
Grand totaal
+
+
+
\ No newline at end of file diff --git a/application/views/partials/_js.php b/application/views/partials/_js.php index ba64448..0304ff4 100644 --- a/application/views/partials/_js.php +++ b/application/views/partials/_js.php @@ -34,6 +34,7 @@ + @@ -62,6 +63,7 @@ + diff --git a/public/css/main.css b/public/css/main.css index cbba3df..1d0670b 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -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; +} + + + diff --git a/public/js/lib/dataservices/reservationsDataService.js b/public/js/lib/dataservices/reservationsDataService.js new file mode 100644 index 0000000..529ed43 --- /dev/null +++ b/public/js/lib/dataservices/reservationsDataService.js @@ -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 ); + } ); + } + + +} + + + diff --git a/public/js/lib/modals/projectModal.js b/public/js/lib/modals/projectModal.js index c8a78a3..c6ffbf8 100644 --- a/public/js/lib/modals/projectModal.js +++ b/public/js/lib/modals/projectModal.js @@ -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 ) { diff --git a/public/js/lib/modules/reports/reservations.js b/public/js/lib/modules/reports/reservations.js new file mode 100644 index 0000000..0ce35b0 --- /dev/null +++ b/public/js/lib/modules/reports/reservations.js @@ -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" ) ); + +} + + + +