app.controller('ParticipantsCtrl', function($scope, $routeParams, $http, $timeout) { if ($routeParams.id != undefined) { $scope.scenarioId = $routeParams.id; } $scope.customCosts = 0; $scope.btn = {}; $scope.row = {}; $scope.blnSubmit = {}; $scope.DeleteCurrentAttendee = false; $scope.inland = [20,57,166]; $scope.$on('scenario_loaded', function(event) { $scope.initParticipants(); }); $scope.initParticipants = function() { if ($scope.participants !== undefined) { return; } $scope.participants = { name: 'Deelnemers', controller: 'contact', function: 'getPerScenario/' + $scope.scenarioId, //Make the rows selectable selectable: true, //Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 10, getCSV: true, getCSVurl: 'contact/getScenarioCSV/' + $scope.scenarioId, putCSVurl: 'contact/putScenarioCSV/' + $scope.scenarioId, fields: [ 'scenario_id', 'organization_id', 'attendee_type_id', 'passport_gender', 'passport_birthday', 'passport_name_first', 'passport_name_last', 'passport_expiry', 'passport_number', 'passport_country_id', 'confirmation', ], //pair the customer table subQueries: { 'country': { 'lfield': 'passport_country_id', 'ffield': 'id', 'controller': 'country', 'function': 'getForPassport', // get all including non camp countries }, 'attendee_type': { 'lfield': 'attendee_type_id', 'ffield': 'id', 'controller': 'attendee_type', }, }, fieldDetails: { 'scenario_id': { 'label': 'Scenario', 'type': 'number', 'hideList': true, 'hideEdit': true, 'default': $scope.scenarioId, }, 'confirmation': { 'label': 'Hierbij bevestig ik op de hoogte te zijn van de extra kosten', 'hideList': true, 'hideEdit': true, 'type': 'boolean', 'booleanOn': true, 'booleanOff': false, 'default': false, }, 'organization_id': { 'label': 'Organization', 'type': 'number', 'hideList': true, 'hideEdit': true, 'default': $scope.organizationId, }, 'attendee_type_id': { 'label': 'Type', 'changeTo': ['attendee_type.name'], 'required': true, }, 'passport_gender': { 'label': 'Geslacht', 'type': 'enum', 'options': [{ 'id': 'M', 'name': 'Man' }, { 'id': 'V', 'name': 'Vrouw', }, { 'id': 'O', 'name': 'Geen van beide', }], 'required': true, }, 'passport_birthday': { 'label': 'Geboortedatum', 'type': 'date', 'required': true, }, 'passport_name_first': { 'label': 'Voornaam paspoort / ID', 'required': true, 'sortAsc': true, }, 'passport_name_last': { 'label': 'Achternaam paspoort / ID', 'required': true, }, 'passport_expiry': { 'label': 'Vervaldatum van paspoort / ID', 'type': 'date', 'required': true, }, 'passport_number': { 'label': 'Paspoort / ID nummer', 'required': true, }, 'passport_country_id': { 'label': 'Nationaliteit van paspoort / ID', 'changeTo': ['country.dutch_name'], 'required': true, }, }, buttons: { 'putCSV':{ 'id': 'putCSV', 'name': 'Upload CSV data', 'label': 'Upload CSV data', 'confirmName': 'Upload data', 'confirmClass': 'success', 'icon': 'fa-table', 'header': true, 'inline': false, 'noFields': true, 'action': 'putCSV', }, 'tempCSV':{ 'id': 'tempCSV', 'name': 'Download template', 'label': 'Download template', 'confirmName': 'Download template', 'confirmClass': 'success', 'icon': 'fa-table', 'header': true, 'inline': false, 'action': 'downloadCSVTemplate', 'parentScope': true, }, 'C':{ 'id': 'c', 'name': 'Voeg deelnemer toe', 'label': 'Voeg deelnemer toe', 'cancelName': 'Annuleer', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': false, 'inline': false, 'icon': 'fa-plus-square', 'action': 'create', }, 'CC':{ 'id': 'cc', 'name': 'Voeg deelnemer toe', 'label': 'Voeg deelnemer toe', 'cancelName': 'Annuleer', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': true, 'inline': false, 'icon': 'fa-plus-square', 'action': 'checkBeforeInsert', 'parentScope': true, }, 'R':{ 'id': 'r', 'name': 'Bekijk deelnemer', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Wijzig deelnemer' , 'label': 'Wijzig', 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline': false, 'icon': 'fa-pencil', 'action': 'update', }, 'UC':{ 'id': 'uc', 'name': 'Wijzig deelnemer' , 'label': 'Wijzig' , 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline': true, 'icon': 'fa-pencil', 'action': 'checkBeforeUpdate', 'parentScope': true, }, 'D':{ 'id': 'd', 'name': 'Verwijder deelnemer', 'label': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline':true, 'icon':'fa-trash', 'action': 'deleteAttendee', 'parentScope': true, }, //Enable to delete multiple rows 'DA':{ 'id': 'da', 'name': 'Delete Selected Rows', 'confirmName': 'Delete Selected Rows', 'confirmClass': 'success', 'icon': 'fa-trash', 'header': true, 'inline': false, 'noFields': true, 'action': 'deleteManyAttendees', 'parentScope': true, }, } } } $scope.deleteAttendee = function(btn, row, blnSubmit) { $scope.DeleteCurrentAttendee = true; this.deleteAttendeeById(btn, row, blnSubmit); } $scope.downloadCSVTemplate = function() { window.open('/scenario_attendee/getCSVTemplate','_blank'); } $scope.deleteManyAttendees = function(btn, row, blnSubmit) { //object cntSelParticipants = $scope.participants.selectedItems.length; cntProParticipants = 0; cntDelParticipants = 0; //loop angular.forEach($scope.participants.selectedItems, function(selectedItem){ let req = { method: 'GET', url: '/scenario_attendee/deleteByContactId/' + selectedItem.id, } $http(req).then(function(response) { cntProParticipants++; if (response.status && response.data.status) { cntDelParticipants++; // Send the payment $scope.customCosts = 0; } if (cntProParticipants == cntSelParticipants) { //check if all processed if (cntSelParticipants == cntDelParticipants) { swal({title: 'Verwijderd!', text: 'Deelnemers succesvol van trainingskamp verwijderd.', icon: 'success'}); } else { swal({title: 'Verwijder actie', text: cntDelParticipants + ' van de ' + cntSelParticipants + ' deelnemers succesvol van trainingskamp verwijderd.', icon: 'success'}); } //initiate $scope.participants.call('initiate'); } }); }); } $scope.deleteAttendeeById = function(btn, row, blnSubmit) { $("#customCostsModal").modal('hide'); let req = { method: 'GET', url: '/scenario_attendee/deleteByContactId/' + row.id, } $http(req).then(function(response) { if (response.status && response.data.status) { // delete success swal({title: 'Verwijderd!', text: 'Deelnemer succesvol van trainingskamp verwijderd.', icon: 'success'}); // Send the payment $scope.customCosts = 0; } $scope.participants.call('initiate'); }); } $scope.checkBeforeInsert = function(btn, row, blnSubmit) { $scope.DeleteCurrentAttendee = false; $scope.participants.fieldDetails['confirmation']['default'] = false; $scope.participants.fieldDetails['confirmation'].hideEdit = true; $scope.participants.fieldDetails['confirmation'].required = false; if ($scope.scenarioId !== undefined) { this.hasCostPerScenario(btn, row, blnSubmit); } } $scope.hasCostPerScenario = function(btn, row, blnSubmit, TKCconfirmation = false) { $("#customCostsModal").modal('hide'); if ($scope.scenarioId !== undefined) { var req = { method: 'GET', url: '/contact/hasCostPerScenario/' + $scope.scenarioId + '/' + $scope.customCosts, } $http(req).then(function(response) { // if result = false if (response.status && response.data.status){ if (response.data.message == 'too.late.for.changes.10') { swal({ title: 'Let op!', text: 'Op dit moment is het niet meer mogelijk om kosteloos wijzigingen door te voeren, aangezien het systeem is vastgezet gezien jullie binnen 10 dagen vertrekken. \n Graag de gewenste wijziging(en) schriftelijk doorgeven aan backoffice@trainingskampen.nl (oude situatie – nieuwe situatie), Let op: Er wordt conform overeenkomst €130 per wijziging doorbelast.', icon: 'error', }) } else if (response.data.message == 'too.late.for.changes.3') { swal({ title: 'Let op!', text: 'U kunt geen deelnemers meer toevoegen of bewerken binnen 1 dag voor begin trainingskamp', icon: 'error', }) } else if (response.data.message == 'change.with.fee.25') { if($scope.user.organization_id == 2 || $scope.user.organization_id == 1){ if(!TKCconfirmation){ $scope.btn = btn; $scope.row = row; $scope.blnSubmit = blnSubmit; // set price ] $scope.customCosts = 25.00; // open modal $("#customCostsModal").modal('toggle'); }else{ $scope.participants.fieldDetails['confirmation']['default'] = true; if(btn['id'] == 'uc'){ btn = $scope.participants.buttons['U']; $scope.participants.toggleButton(btn, row); }else{ btn = $scope.participants.buttons['C']; $scope.participants.toggleButton(btn, row); } $scope.participants['modal']['data']['customCosts'] = $scope.customCosts; } } else { swal({ title: 'Let op!', text: 'Deze toevoeging/aanpassing kost €25, is dit akkoord?', icon: 'warning', buttons: { cancel: 'Annuleren', OK: 'Akkoord', } }).then((OK) => { if (OK) { $scope.participants.fieldDetails['confirmation']['default'] = true; if(btn['id'] == 'uc'){ btn = $scope.participants.buttons['U']; $scope.participants.toggleButton(btn, row); } else { btn = $scope.participants.buttons['C']; $scope.participants.toggleButton(btn, row); } } }); } } else if (response.data.message == 'change.with.fee.130') { if($scope.user.organization_id == 2 || $scope.user.organization_id == 1){ if(!TKCconfirmation){ $scope.btn = btn; $scope.row = row; $scope.blnSubmit = blnSubmit; // set price ] $scope.customCosts = 130.00; // open modal $("#customCostsModal").modal('toggle'); }else{ $scope.participants.fieldDetails['confirmation']['default'] = true; if(btn['id'] == 'uc'){ btn = $scope.participants.buttons['U']; $scope.participants.toggleButton(btn, row); } else{ btn = $scope.participants.buttons['C']; $scope.participants.toggleButton(btn, row); } $scope.participants['modal']['data']['customCosts'] = $scope.customCosts; } } else { swal({ title: 'Let op!', text: 'Deze toevoeging/aanpassing kost €130, is dit akkoord?', icon: 'warning', buttons: { cancel: 'Annuleren', OK: 'Akkoord', } }).then((OK) => { if (OK) { $scope.participants.fieldDetails['confirmation']['default'] = true; if(btn['id'] == 'uc'){ btn = $scope.participants.buttons['U']; $scope.participants.toggleButton(btn, row); } else { btn = $scope.participants.buttons['C']; $scope.participants.toggleButton(btn, row); } } }); } } else { swal({ title: 'Let op!', text: response.data.message, icon: 'warning', buttons: { cancel: 'Annuleren', OK: { text: 'OK', value: true, closeModal: false, }, } }).then((willConfirm) => { if (willConfirm) { $scope.participants.fieldDetails['confirmation'].hideEdit = true; btn = $scope.participants.buttons['C']; $scope.participants.toggleButton(btn, row); } $timeout(function() { swal.stopLoading(); swal.close(); }, 0); }); } } else { // if result = true if(btn['id'] == 'uc'){ btn = $scope.participants.buttons['U']; $scope.participants.toggleButton(btn, row); } else { btn = $scope.participants.buttons['C']; $scope.participants.toggleButton(btn, row); } $scope.customCosts = 0; } }); } } $scope.checkBeforeUpdate = function(btn, row, blnSubmit) { $scope.participants.fieldDetails['confirmation']['default'] = false; $scope.participants.fieldDetails['confirmation'].hideEdit = true; $scope.participants.fieldDetails['confirmation'].required = false; if (row['scenario_id'] !== undefined) { this.hasCostPerScenario(btn, row, blnSubmit); } } // Translate table $scope.tableReady = function (tableName) { if (tableName === 'Deelnemers') { $scope.participants.labels = { 'of': 'van', 'rows': 'rijen', 'lastUpdated': 'Laatste wijziging', 'showNotSelectedRows': 'Toon niet geselecteerde rijen', 'showSelectedRows': 'Toon geselecteerde rijen', 'selectAllRows': 'Selecteer alle rijen', 'deSelectAllRows': 'De-selecteer alle rijen', 'selectFilteredRows': 'Selecteer gefilterde rijen', 'deSelectFilteredRows': 'De-selecteer gefilterde rijen', 'false': 'Mislukt', 'true': 'Gelukt', 'statistics': 'Statistieken', 'deleteAllRowsMessage': 'Let op! Je staat op het punt alle geselecteerde rijen te verwijderen', 'ready' : 'Klaar', 'processSubFields' : 'Verwerk subvelden', 'alreadyLoaded' : 'al ingeladen in data.', 'errorInFetching' : 'Error in ophalen', 'dataAvailable' : 'Data al beschikbaar', 'loading' : 'Laden...', }; } } $scope.$on('getNumOfParticipants', function(e) { $scope.$emit('returnNumOfParticipants', $scope.participants.data.rows.length); }) $scope.getParticipantsToInsert = function() { if ($scope.pax && $scope.participants.data) { return $scope.pax - $scope.participants.data.rows.length } else { return null } } // This function checks whether the user is allowed to edit the participants // This is done by comparing the organization.id of the user and the organization.id of the scenario // If the id's match the user is allowed to edit the participants and the content is set accordingly function determineScenarioContent() { // Add these variables to your $scope $scope.editParticipantMessage = ''; $scope.isParticipantsReadOnly = false; // Define the request for checking user information const userCheckReq = { method: 'GET', url: '/user/check', }; // Define the request for getting scenario information const scenarioGetReq = { method: 'GET', url: '/scenario/get/' + $scope.scenarioId, }; // Execute both requests simultaneously using Promise.all Promise.all([ $http(userCheckReq), $http(scenarioGetReq) ]) .then(function([userResponse, scenarioResponse]) { // Check if both requests were successful if (userResponse.status && userResponse.data.status && scenarioResponse.status && scenarioResponse.data.status) { // Extract organization IDs from the responses const userOrganization = userResponse.data.data.organization.id; const scenarioOrganization = scenarioResponse.data.data.organization_id; // Compare user's organization with scenario's organization if (userOrganization === scenarioOrganization) { // If they don't match, set message about inability to make changes and provide contact information $scope.editParticipantMessage = ` Op dit moment is het niet meer mogelijk om kosteloos wijzigingen door te voeren, het systeem is vastgezet gezien jullie binnen 10 dagen vertrekken.
Graag de gewenste wijziging(en) schriftelijk doorgeven aan backoffice@trainingskampen.nl. `; // Disable editing of participant amount $scope.isParticipantsReadOnly = true; } else { // If they match, set message for entering modification costs $scope.editParticipantMessage = "De deadline voor het wijzigen van de deelnemerslijst is verstreken. Voer de wijzigingskosten in:"; } } }) .catch(function(error) { // Display error message if any request fails swal({ title: 'Let op!', text: 'Er is iets misgegaan, probeer het opnieuw', icon: 'error', }); }); } determineScenarioContent(); })