app.controller('ScenariosCtrl', function($scope, $location, $routeParams, $http, $parse, $filter, Upload, notify) { $scope.scenario = {}; $scope.scenarioId = $routeParams.id; $scope.organizationId = 0; $scope.attendeeBagage = ""; $scope.pnrNumber = ""; // update activity status $scope.updateActivityStatus = function() { //update scenario with activity status 1 let req = { method: 'POST', url: '/scenario/update/' + $scope.scenario.id, data: {activity_status_id: $scope.scenario.activity_status_id}, } $http(req).then(function(response) { if (response.status && response.data.status) { swal({ title: 'Gelukt!', text: 'De programma status van het scenario is aangepast.', icon: 'success', }); } else { swal({ title: 'Let op!', text: response.data.message, icon: 'error', }); } }); }; //show hide tabs $scope.checkShow = function(tabName){ if($scope.activeTab === undefined){ $scope.activeTab = 'informatie'; if($scope.user.role.id == 2) { $scope.activeTab = 'programma'; } } //set classes of div objClass = { 'in': tabName == $scope.activeTab, 'active': tabName == $scope.activeTab, 'hidden': !tabName == $scope.activeTab, }; return objClass; } $scope.notification = function(title, message, type, duration) { if (type == undefined) { type == 'success'; } if (duration == undefined) { duration = 5000; } notify({ message: message, messageTemplate: '
' + title + '

' + message + '

', classes: ["alert-" + type], duration: duration, position: "right", }) } // create invoice $scope.makeInvoice = function() { swal({ title: "Eindfactuur versturen?", text: "Weet je zeker dat je de eindfactuur van het draaiboek wilt versturen?", icon: "warning", buttons: { cancel: "Nee", confirm: { text: "Ja", value: true, closeModal: false, }, }, }).then((willSend) => { if (willSend) { createInvoice(0).then(function(response) { if (response.status && response.data.status) { $scope.notification("Succes", "Het versturen van de eindfactuur is gelukt!", "success"); $scope.getScenario(); } else { $scope.notification("Foutmelding", "Het versturen van de eindfactuur is niet gelukt met de volgende reden:\n" + response.data.message, "danger"); } swal.close(); }, function(error) { $scope.notification("Foutmelding", "Het versturen van de eindfactuur is niet gelukt, gelieve contact op te nemen met SBA", "danger"); swal.close(); }); } }); } //Inovices $scope.invoices = { name: 'Facturen', controller: 'invoice', function: 'getByScenario/' + $routeParams.id, //Panel class panelClass: 'panel-trainingskampen', showFilters: true, showRowCount: true, pageLimit: 20, readOnly: !($scope.user && $scope.user.role.id > 1), fields: [ 'date', 'payment_reference', 'total_amount', 'sent', 'last_sent_at' ], fieldDetails: { 'date': { 'label': 'Datum', 'sortAsc': false, }, 'payment_reference': { 'label': 'Referentie', }, 'total_amount': { 'label': 'Bedrag', 'currency': '€', 'type' : 'number', }, 'sent': { 'label': 'Verzonden', }, 'last_sent_at': { 'label': 'Laatste keer verzonden' } }, buttons: { 'C':{ 'id': 'c', 'header': false, 'inline': false, 'name': 'Factuur maken', 'label': 'Bekijk', 'cancelName': 'Annuleer', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'icon': 'fa-plus-square', 'action': 'createInvoice', 'parentScope':true }, 'R': { 'id': 'r', 'name': 'Factuur log', 'label': 'Log', 'cancelName': 'Annuleer', 'confirmName': 'Log', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-list', 'action': 'toInvoiceLog', 'parentScope': true, }, 'S': { 'id': 's', 'name': 'Verstuur factuur', 'label': 'Verzenden', 'cancelName': 'Annuleer', 'confirmName': 'Stuur', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-envelope', 'action': 'sendInvoice', 'parentScope': true, }, 'DL': { 'id': 'dl', 'name': 'Download factuur', 'label': 'Downloaden', 'cancelName': 'Annuleer', 'confirmName': 'Download', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-download', 'action': 'downloadInvoice', 'parentScope': true, }, 'U':{ 'id': 'u', 'header': false, 'inline': false, }, 'D':{ 'id': 'd', 'header': false, 'inline': false, }, } } //Inovices $scope.invoiceLogs = { name: 'Facturen log', controller: 'invoice_log', function: '', //Panel class panelClass: 'panel-trainingskampen', showFilters: true, showRowCount: true, pageLimit: 20, readOnly: true, fields: [ 'created_at', 'message', ], fieldDetails: { 'created_at': { 'label': 'Datum', 'sortAsc': false, }, 'message': { 'label': 'Bericht' } }, buttons: { 'C':{ 'id': 'c', 'header': false, 'inline': false, }, 'R': { 'id': 'r', 'inline': true, 'header': false, }, 'U':{ 'id': 'u', 'header': false, 'inline': false, }, 'D':{ 'id': 'd', 'header': false, 'inline': false, }, } } $scope.toInvoiceLog = function(btn, row, blnSubmit) { $scope.invoiceLogs.function = '/getByInvoice/' + row.id; $scope.invoiceLogs.call('initiate'); $('#logInvoiceModal').modal('show'); } //archive scenario $scope.archiveScenario = function(btn, row) { //update scenario with archived 1 let req = { method: 'POST', url: '/scenario/update/' + row.id, data: {archived: 1}, } $http(req).then(function(response) { if (response.status && response.data.status) { swal({ title: 'Gelukt!', text: 'Het draaiboek is gearchiveerd', icon: 'success', }); $scope.getScenario(); } else { swal({ title: 'Let op!', text: response.data.message, icon: 'error', }) } }) } $scope.generateAppCode = function() { var req = { method: 'GET', url: '/scenario/generateScenarioCode/' + $routeParams.id, } $http(req).then((response) => { if (response.data.status) { $scope.scenario.app_code = response.data.data.code; } }); } $scope.getTotalAmountForProgram = function(activities, sales = false) { var total = 0.00; activities.forEach(activity => { if (sales) { total += parseFloat(activity['price_sales']); } else { total += parseFloat(activity['price']); } }, this); return parseFloat(total).toFixed(2); } $scope.invoiceCreation = { loading: false } $scope.createScenarioInvoice = function() { $scope.invoiceCreation.loading = true; var req = { method: 'POST', url: '/invoice/createScenarioInvoice/' + $routeParams.id, data: $scope.newInvoice, } $http(req).then((response) => { if (response.data.status) { $('#createInvoiceModal').modal('hide'); $scope.invoices.call('initiate'); $scope.invoiceCreation.loading = false; } else { $scope.notification("Foutmelding", response.data.message, "danger"); $scope.invoiceCreation.loading = false; } }); } $scope.createInvoice = function() { $scope.newInvoice = { amount: 0.00, nameOption: "1", } $('#createInvoiceModal').modal('show'); } // create recalculation $scope.makeRecalculation = function() { swal({ title: "Nacalculatie versturen?", text: "Weet je zeker dat je de nacalculatie van het draaiboek wilt versturen?", icon: "warning", buttons: { cancel: "Nee", confirm: { text: "Ja", value: true, closeModal: false, }, }, }).then((willSend) => { if (willSend) { createInvoice(1).then(function(response) { if (response.status && response.data.status) { $scope.notification("Succes", "Het versturen van de nacalculatie is gelukt!", "success"); $scope.getScenario(); } else { $scope.notification("Foutmelding", "Het versturen van de nacalculatie is niet gelukt met de volgende reden:\n" + response.data.message, "danger"); } swal.close(); }, function(error) { $scope.notification("Foutmelding", "Het versturen van de nacalculatie is niet gelukt, gelieve contact op te nemen met SBA", "danger"); swal.close(); }); } }); } $scope.getFinalInvoiceDate = function() { let date = null; if ($scope.scenario.from != undefined) { //make date from date date = new Date($scope.scenario.from); //set from date minus 60 days date.setDate(date.getDate() - 60); } if ($scope.scenario.final_invoice_date != undefined) { //make date final invoice date date = new Date($scope.scenario.final_invoice_date); } //check for date if (date != undefined) { return date.getDate() + '-' + (date.getMonth() + 1) + '-' + date.getFullYear(); } return false; } $scope.getSecondInvoiceDate = function() { let date = null; if ($scope.scenario.from != undefined) { //make date from date date = new Date($scope.scenario.from); //set from date minus 90 days date.setDate(date.getDate() - 90); } if ($scope.scenario.second_invoice_date != undefined) { //make date final invoice date date = new Date($scope.scenario.second_invoice_date); } //check for date if (date != undefined) { return date.getDate() + '-' + (date.getMonth() + 1) + '-' + date.getFullYear(); } return false; } $scope.getInvoiceInfo = function(invoiceType = null, infoType = null) { //get final invoice let finalInvoice = {}; if ($scope.scenario != undefined && $scope.scenario.invoices != undefined) { $scope.scenario.invoices.forEach((invoice) => { //check for type if (invoice.type == invoiceType) { finalInvoice = invoice; } }); switch(infoType) { case 'number': if (finalInvoice != undefined && finalInvoice['invoice_number'] != undefined) { return finalInvoice['invoice_number']; } break; case 'amount': if (finalInvoice != undefined && finalInvoice['total_amount'] != undefined) { return finalInvoice['total_amount']; } break; case 'status': if (finalInvoice != undefined && finalInvoice['status_name'] != undefined) { return finalInvoice['status_name']; } break; } } return ""; } $scope.showExtraInvoiceModal = function() { let amount = $scope.getActivityCosts() - $scope.getInvoiceAmount(); $scope.extraInvoiceAmount = parseFloat(amount); $scope.extraInvoiceDescription = "Restfactuur " + ($scope.scenario != undefined && $scope.scenario.name != undefined ? $scope.scenario.name : ''); $('#extraInvoiceModal').modal('show'); } $scope.addExtraInvoice = function() { let minimalAmount = ($scope.getActivityCosts() - $scope.getInvoiceAmount()).toFixed(2); // convert string to float minimalAmount = parseFloat(minimalAmount); //check if selected amount is not lower than minimum if ($scope.extraInvoiceAmount && minimalAmount < 0 && $scope.extraInvoiceAmount < minimalAmount) { $scope.notification("Foutmelding", "Het ingevulde bedrag is lager dan het bedrag wat open staat. Het minimale bedrag is €" + minimalAmount, "danger"); return } $('#extraInvoiceModal').modal('hide'); var loader = document.createElement("i"); loader.classList.add("fa"); loader.classList.add("fa-spinner"); loader.classList.add("fa-5x"); loader.classList.add("fa-spin"); swal({ title: "Laden...", content: loader, buttons: false, backdrop:true, closeOnClickOutside: false, }); var req = { method: 'POST', url: '/scenario/sendExtraInvoice/' + $routeParams.id, data: {amount: $scope.extraInvoiceAmount, description: $scope.extraInvoiceDescription}, } $http(req).then((response) => { swal.close(); if (response.data.status) { $scope.getScenario(); } else { swal('Mislukt', 'De factuur kon niet worden aangemaakt, probeer het opnieuw', 'error'); } }); } $scope.changeSecondInvoiceDate = function() { swal({ title: 'Verander verzend datum', text: 'Geef hieronder een datum op waarop de eind factuur verstuurd moet worden. De huidige verzend datum staat nu op ' + $scope.getSecondInvoiceDate(), content: { element: "input", attributes: { type: "date", }, }, buttons: { cancel: "Annuleer", confirm: { text: "Opslaan", value: true, closeModal: false, }, }, }).then(date => { if (!date) throw null; return date; }).then(date => { //check for date if (date != undefined) { let formattedDate = new Date(date); //check if date is not yesterday or earlier if (formattedDate <= new Date(new Date().setDate(new Date().getDate()-1))) { swal('Mislukt', 'Je kan geen datum in het verleden kiezen', 'error'); return; } var req = { method: 'POST', url: '/scenario/changeSecondInvoiceDate/' + $routeParams.id, data: {second_invoice_date: formattedDate.getFullYear() + '-' + (formattedDate.getMonth() + 1) + '-' + formattedDate.getDate()}, } $http(req).then((response) => { if (response.data.status) { $scope.scenario.second_invoice_date = response.data.data.second_invoice_date; swal.close(); } else { swal('Mislukt', 'De datum kon niet worden aangepast, probeer het opnieuw', 'error'); } }); } else { swal('Mislukt', 'Geef een geldige datum op.', 'error'); } }) } $scope.changeFinalInvoiceDate = function() { swal({ title: 'Verander verzend datum', text: 'Geef hieronder een datum op waarop de eind factuur verstuurd moet worden. De huidige verzend datum staat nu op ' + $scope.getFinalInvoiceDate(), content: { element: "input", attributes: { type: "date", }, }, buttons: { cancel: "Annuleer", confirm: { text: "Opslaan", value: true, closeModal: false, }, }, }).then(date => { if (!date) throw null; return date; }).then(date => { //check for date if (date != undefined) { let formattedDate = new Date(date); //check if date is not yesterday or earlier if (formattedDate <= new Date(new Date().setDate(new Date().getDate()-1))) { swal('Mislukt', 'Je kan geen datum in het verleden kiezen', 'error'); return; } var req = { method: 'POST', url: '/scenario/changeFinalInvoiceDate/' + $routeParams.id, data: {final_invoice_date: formattedDate.getFullYear() + '-' + (formattedDate.getMonth() + 1) + '-' + formattedDate.getDate()}, } $http(req).then((response) => { if (response.data.status) { $scope.scenario.final_invoice_date = response.data.data.final_invoice_date; swal.close(); } else { swal('Mislukt', 'De datum kon niet worden aangepast, probeer het opnieuw', 'error'); } }); } else { swal('Mislukt', 'Geef een geldige datum op.', 'error'); } }) } function createInvoice(final) { var req = { method: 'GET', url: '/scenario/invoice/' + $routeParams.id + '/' + final, } return $http(req); } //refresh page $scope.reloadRoute = function() { $route.reload(); } //show hide tabs $scope.checkFlightShow = function(tabName){ if($scope.activeFlightTab === undefined){ $scope.activeFlightTab = 'overview'; } //set classes of div objClass = { 'in': tabName == $scope.activeFlightTab, 'active': tabName == $scope.activeFlightTab, 'hidden': !tabName == $scope.activeFlightTab, }; return objClass; } $scope.selectedFlight = null; $scope.setActiveFlightTab = function(tabName, flight){ $scope.activeFlightTab = tabName; $scope.selectedFlight = flight; $scope.flightAttendees.predefinedFilters['scenario_flight_id'] = tabName; $scope.baggageModalTable.predefinedFilters['scenario_flight_id'] = tabName; } $scope.hasFlights = function() { if ($scope.scenario.has_flights !== undefined && $scope.scenario.has_flights == '1') { return true; } // first make it visible if ($scope.scenario.flights === undefined) { return true; } // set it to non visible when no flights if (!$scope.scenario.flights.length) { return false; } return true; } $scope.openPassengerModal = function() { $scope.attendeeModalTable.function = 'getScenarioAttendees/' + $scope.scenarioId + '/' + $scope.selectedFlight.id; $scope.attendeeModalTable.call('initiate'); $("#passengerModal").modal('toggle'); } $scope.openBaggageModal = function() { $scope.baggageModalTable.call('initiate'); $("#baggageModal").modal('toggle'); } $scope.campPast = function() { let campIsInThePast = false; if ($scope.scenario.to != undefined) { let toDate = new Date($scope.scenario.to); let currentDate = new Date(); if (toDate < currentDate) { campIsInThePast = true; } } return campIsInThePast; } //get scenario $scope.getScenario = function(){ var req = { method: 'GET', url: '/scenario/getWith/' + $scope.scenarioId, } //response $http(req).then(function (response){ if (response.data.status) { $scope.scenario = response.data.data[0]; $scope.scenario.pax = parseInt($scope.scenario.pax); $scope.scenario.price = parseFloat($scope.scenario.price); $scope.organizationId = $scope.scenario['organization_id']; // calculate number of nights $scope.numOfNights = daysBetween(new Date($scope.scenario.from), new Date($scope.scenario.to)); // set room variables $scope.rooms = response.data.data[0].hotel.rooms; $scope.room_types = []; // add default room to the room_types $scope.room_types.push({ name: response.data.data[0].hotel['room_name'], amount_of_singles: parseInt(response.data.data[0].hotel['room_amount_of_singles']), amount_of_doubles: parseInt(response.data.data[0].hotel['room_amount_of_doubles']), }); //set pnr $scope.pnrNumber = response.data.data[0].pnr; //convert dates for edit $scope.scenario.from_date_js = new Date($scope.scenario.from); $scope.scenario.to_date_js = new Date($scope.scenario.to); //customer logos $scope.scenario.customer.logos = []; if ($scope.scenario.customer.images !== undefined) { try { $scope.scenario.customer.logos = JSON.parse($scope.scenario.customer.images); } catch (e) { $scope.scenario.customer.logos = []; } } // add other rooms to room_types if (response.data.data[0].hotel.room_types !== undefined && typeof response.data.data[0].hotel.room_types === 'string') { try { var roomTypes = JSON.parse(response.data.data[0].hotel.room_types); if (Array.isArray(roomTypes)) { roomTypes.forEach(function(roomType) { $scope.room_types.push(roomType); }); } } catch (e) { // failed to decode room_types $scope.room_types = []; } } //get cooperation partners for general information $scope.cooperationPartners = []; let req = { method: 'GET', url: '/scenario/getCooperationPartnersForGeneralInfo/' + $scope.scenarioId, } $http(req).then(function(response) { if (response.status && response.data.status) { $scope.cooperationPartners = response.data.data; } }); //check for quotation id if (response.data.data != undefined && response.data.data[0] != undefined && response.data.data[0]['quotation_id'] != undefined) { //get quotation for quotation information $scope.quotation = {}; let reqQuotation = { method: 'GET', url: '/quotation/get/' + response.data.data[0]['quotation_id'], } $http(reqQuotation).then(function(response) { if (response.status && response.data.status) { $scope.quotation = response.data.data; } }); } $scope.attendees = response.data.data[0].attendees; angular.forEach($scope.attendees, function(attendee){ attendee.id = parseInt(attendee.id); attendee.name = attendee.name_first + ' ' + attendee.name_middle + ' ' + attendee.name_last; attendee.type = attendee.attendee_type; }); $scope.getImages('scenario_hotels', $scope.scenario.hotel.id); //set information $scope.information = $scope.scenario.information; angular.forEach($scope.information, function(info){ info.order = parseInt(info.order); }); //Hotel $scope.hotel = response.data.data[0].hotel; //activities $scope.activities = response.data.data[0].activities; //set flight tabName if ($scope.activeFlightTab !== undefined) { $scope.setActiveFlightTab($scope.activeFlightTab, $scope.selectedFlight); } else if ($scope.scenario.flights[0] !== undefined) { $scope.setActiveFlightTab('overview'); } var arrDates = Array();                 for(var i = 0; i < response.data.data[0].activities.length; i++){ if(arrDates.indexOf(response.data.data[0].activities[i].date) == -1){ arrDates.push(response.data.data[0].activities[i].date); } } var arrActivitiPerDate = Array(); angular.forEach(arrDates, function(value, key){ arrActivitiPerDate[key] = $scope.activities.filter(function(activiti) { return activiti.date == value; }); }); //sprt arrActivitiPerDate.sort(function(a, b) { if ( Array.isArray(a) && Array.isArray(b) && a[0] !== undefined && b[0] !== undefined && typeof a[0] == 'object' && typeof b[0] == 'object' && a[0].date !== undefined && b[0].date !== undefined && a[0].date && b[0].date ) { return new Date(a[0].date) - new Date(b[0].date); } else { return 0; } }); angular.forEach(arrActivitiPerDate, function(arrActivitiesOneDay, key) { arrActivitiesOneDay.sort(function(a, b){ return a.from - b.from }); arrActivitiPerDate[key] = arrActivitiesOneDay; }); $scope.arrActivitiPerDate = arrActivitiPerDate $scope.calculateAvailableAttendees(); $scope.createMap(); $scope.$broadcast('scenario_loaded'); }else{ $location.url('/page/overzicht'); } }); } $scope.deletePartner = function(partner){ let req = { method: 'GET', url: '/scenario_cooperation_partner/removepartner/' + partner['scenario_id'] + '/' + partner['user_id'], } $http(req).then(function(response) { if(response.data.status) { $scope.notification("Succes!", "De samenwerkingspartner is succesvol verwijdered", "success"); var index = $scope.cooperationPartners.indexOf(partner); $scope.cooperationPartners.splice(index, 1); } else { $scope.notification("Foutmelding", "De samenwerkingspartner kon niet worden verwijdered", "danger"); } }); } function daysBetween(startDate, endDate) { if ((typeof startDate !== 'object') || (typeof endDate !== 'object')) { return null; } // The number of milliseconds in all UTC days (no DST) const ONE_DAY = 1000 * 60 * 60 * 24; // Convert both dates to milliseconds var start_ms = startDate.getTime(); var end_ms = endDate.getTime(); if (start_ms <= end_ms) { // Calculate the difference in milliseconds var difference_ms = Math.abs(start_ms - end_ms); // Convert back to days and return return Math.round(difference_ms/ONE_DAY); } else { // startDate > endDate return -1; } } $scope.getScenario(); //last changes table $scope.lastChanges = { name: 'Laatste wijzigingen', controller: 'scenario_log', function: 'getLastChanges/' + $scope.scenarioId, pageLimit: 15, //Panel class panelClass: 'panel-trainingskampen', //hideTable: true, fields: [ 'changes', 'updated_at', ], subQueries: { }, fieldDetails: { 'changes': { 'label': 'Wijziging', }, 'updated_at': { 'label': 'Gewijzigd op', 'sortAsc': false, }, }, buttons: { 'C':{ 'id': 'c', 'name': 'add', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': false, 'inline': false, 'icon': 'fa-plus-square', 'action': 'create', }, 'R':{ 'id': 'r', 'name': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': false, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Wijzig' , 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline':false, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline':false, 'icon':'fa-trash', 'action': 'delete', }, } } //hotel edit //last changes table $scope.table_scenario_hotel = { name: 'Hotel', controller: 'scenario_hotel', function: 'getPerScenario/' + $scope.scenarioId, pageLimit: 15, //Panel class panelClass: 'panel-trainingskampen', fields: [ 'name', 'address', 'postalcode', 'place', 'country', 'phone_number', ], fieldDetails: { 'name': { 'label': 'Naam', }, 'address': { 'label': 'Adres', }, 'postalcode': { 'label': 'Postcode', }, 'place': { 'label': 'Plaats', }, 'country': { 'label': 'Land', }, 'phone_number': { 'label': 'Telefoonnummer', }, }, buttons: { 'C':{ 'id': 'c', 'name': 'add', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': false, 'inline': false, 'icon': 'fa-plus-square', 'action': 'create', }, 'R':{ 'id': 'r', 'name': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': false, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Wijzig', 'label': 'Wijzig', 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline':true, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline':false, 'icon':'fa-trash', 'action': 'delete', }, } } // update flight passengers $scope.updateAllotment = function(){ let pnr = {reservation_nr: $scope.pnrNumber}; var req = { method: 'POST', url: '/flight_passenger/addfromscenario/' + $scope.scenarioId, data: pnr, } $http(req).then(function (response) { if(response.data.status) { $scope.notification("Succes!", "De allotments in dit draaiboek is succesvol gewijzigd", "success"); } else { switch (response.data.message) { case 'get.flight.failed': $scope.notification("Foutmelding", "De vlucht bestaat niet in de vluchtentabel", "danger"); break; case 'get.passengers.failed': $scope.notification("Foutmelding", "Er zijn geen passagiers opgegeven voor één of meerdere vluchten", "danger"); break; case 'get.scenario.flights.failed': $scope.notification("Foutmelding", "Er zijn geen vluchten binnen dit draaiboek", "danger"); break; case 'pnr.not.set': $scope.notification("Foutmelding", "Ongeldig reserveringsnummer", "danger"); break; default: $scope.notification("Foutmelding", "De allotments in dit draaiboek kon niet worden gewijzigd, probeer het opnieuw!", "danger"); } } }); } // update scenario flight passengers $scope.updateScenarioFlightPassengers = function(){ let scenarioFlightPassengers = {}; if ($scope.attendeeModalTable.selectedItems && $scope.selectedFlight) { scenarioFlightPassengers = { scenario_flight_id: $scope.selectedFlight.id, passengers: $scope.attendeeModalTable.selectedItems, reservation_nr: $scope.pnrNumber, passenger_baggage: $scope.attendeeBagage, }; } var req = { method: 'POST', url: '/scenario_flight_passenger/addfromscenario/' + $scope.scenarioId, data: scenarioFlightPassengers, } $http(req).then(function (response) { if(response.data.status) { $scope.notification("Succes!", "De passagiers zijn succesvol op de vlucht gezet", "success"); } else { switch (response.data.message) { case 'get.flight.failed': $scope.notification("Foutmelding", "De vlucht bestaat niet in de vluchtentabel", "danger"); break; case 'get.passengers.failed': $scope.notification("Foutmelding", "Er zijn geen passagiers opgegeven", "danger"); break; case 'get.scenario.flights.failed': $scope.notification("Foutmelding", "Er zijn geen vluchten binnen dit draaiboek", "danger"); break; case 'pnr.not.set': $scope.notification("Foutmelding", "Ongeldig reserveringsnummer", "danger"); break; default: $scope.notification("Foutmelding", "De passagiers van de vlucht konden niet worden gewijzigd, probeer het opnieuw!", "danger"); } } // reload flight attendees after update $scope.flightAttendees.call('initiate'); }); } // update scenario flight baggage $scope.updateScenarioFlightBaggage = function(){ let scenarioFlightPassengers = {}; if ($scope.baggageModalTable.selectedItems) { // only update rows for the current visible selected items in case all rows are selected let selectedItems = $scope.baggageModalTable.selectedItems.filter((row, index) => { return row.scenario_flight_id == $scope.activeFlightTab; }) scenarioFlightPassengers = { passengers: selectedItems, passenger_baggage: $scope.attendeeBagage, }; } var req = { method: 'POST', url: '/scenario_flight_passenger/addBaggageToPassengers/' + $scope.scenarioId, data: scenarioFlightPassengers, } $http(req).then(function (response) { if(response.data.status) { $scope.notification("Succes!", "De bagage is succesvol op de passagiers gezet", "success"); } else { switch (response.data.message) { case 'scenario_flight.no.passengers': $scope.notification("Foutmelding", "Er zijn geen vlucht deelnemers geselecteerd", "danger"); break; default: $scope.notification("Foutmelding", "De bagage van de vlucht deelnemers kon niet worden gewijzigd, probeer het opnieuw!", "danger"); break; } } // reload tables after update $scope.baggageModalTable.call('initiate'); $scope.flightAttendees.call('initiate'); }); } //flight functions $scope.savePNR = function() { if ($scope.scenario.pnr !== undefined && $scope.pnrNumber !== undefined) { if ($scope.pnrNumber !== null && $scope.pnrNumber.length > 0) { if ($scope.scenario.pnr == null || $scope.scenario.pnr.length == 0) { var req = { method: 'POST', url: '/scenario/update/' + $scope.scenarioId, data: {pnr: $scope.pnrNumber}, } //response $http(req).then(function (response){ if(response.data.status) { $scope.notification("Succes!", "De informatie van dit draaiboek is succesvol gewijzigd", "success"); } else { $scope.notification("Foutmelding", "De informatie van dit draaiboek kon niet worden gewijzigd, probeer het opnieuw!", "danger"); } }); } else { $scope.pnrNumber = $scope.scenario.pnr; $scope.notification("Foutmelding", "PNR is al ingesteld!", "danger"); } } else { $scope.notification("Foutmelding", "PNR heeft geen waarde!", "danger"); } } } //view the pax $scope.selectFlight = function (btn, row, blnSubmit) { if (row.flight_number != undefined) { $scope.setActiveFlightTab(row.flight_number, row); } } //check last week changes $scope.changesLastWeek = false; $scope.getLastWeekChanges = function(){ var req = { method: 'GET', url: '/scenario_log/getLastWeekChanges/' + $scope.scenarioId, } //response $http(req).then(function (response){ $scope.changesLastWeek = response.data.status; }); } $scope.getLastWeekChanges(); //get default scenarios $scope.getDefaultInformation = function(){ $scope.defaultInfo = []; var req = { method: 'GET', url: '/scenario_information_default/get', } //response $http(req).then(function (response){ if(response.data.status){ $scope.defaultInfo = response.data.data; } }); } $scope.getDefaultInformation(); $scope.saveInformation = function($state = null){ $scope.information['scenario'] = $scope.scenarioId; var req = { method: 'POST', url: '/scenario_information/insertOrUpdate/' + $scope.scenarioId, data: $scope.information, } //response $http(req).then(function (response){ if(response.data.status && $state == null) { $scope.information = response.data.data; $scope.notification("Succes!", "De informatie van dit draaiboek is succesvol gewijzigd", "success"); } else if ($state == null) { $scope.notification("Foutmelding", "De informatie van dit draaiboek kon niet worden gewijzigd, probeer het opnieuw!", "danger"); } }); } $scope.changeOrder = function($order, id, direction){ //get previous order and save a copy of current order data var prevOrder = parseInt($order) -1; var nextOrder = parseInt($order) +1; var currentInfoId = parseInt(id); //change order 1 up or down if (($order > 0 && direction == 'up') || ($order < $scope.information.length - 1 && direction == 'down')){ angular.forEach($scope.information, function(info){ if(direction == 'up'){ if(info.order == prevOrder){ info.order = $order; }if(info.id == currentInfoId){ info.order = prevOrder; } }else{ if(info.order == nextOrder){ info.order = $order; }if(info.id == currentInfoId){ info.order = nextOrder; } } }); } } $scope.addFieldToInformation = function(){ var newOrder = $scope.information.length; var pushArr = {'scenario_id': $scope.scenarioId,'order': newOrder,'name': '', 'title': '', 'description': ''}; $scope.information.push(pushArr); } $scope.deleteInformation = function(informationData){ index = $scope.information.indexOf(informationData); $scope.information.splice(index, 1); } $scope.setDefault = function(informationData, index){ if(informationData != undefined){ swal({ title: "Standaard tekst invoeren?", text: "Weet je zeker dat je de tekst met de standaard tekst wilt overschrijven? Er kunnen gegevens verloren gaan.", icon: "warning", buttons: { cancel: "Nee", confirm: "Ja" }, dangerMode: true, }).then((willDelete) => { if (willDelete) { informationData.description = $scope.defaultInfo[informationData.default].description; informationData.title = htmlDecode($scope.defaultInfo[informationData.default].title); delete informationData.default; $scope.information[index] = informationData; $scope.$apply(); } }); } } function htmlDecode(input) { var doc = new DOMParser().parseFromString(input, "text/html"); return doc.documentElement.textContent; } $scope.showAttendeePanel = false; $scope.setAddAttendee = function(attendee){ $scope.showAttendeePanel = true; if(attendee !== undefined){ $scope.attendee = attendee; $scope.headerTekst = "Paspoort/ID gegevens wijzigen"; }else{ $scope.attendee = {}; $scope.headerTekst = "Paspoort/ID gegevens toevoegen"; } } //Add attendee to flight $scope.addAttendee = function(){ // insert flight passengers var req = { method: 'POST', url: '/scenario_flight_passenger/insert', data: $scope.addAttendeeToFlight, } $http(req).then(function(response) { if (response.data.status) { $scope.getScenario(); $scope.addAttendeeToFlight = {}; } }); } $scope.createMap = function() { var name = 'Unknown hotel'; var LatLng = {lat: 52.3545653, lng: 4.7585435}; if ($scope.scenario.hotel.latitude !== undefined && parseFloat($scope.scenario.hotel.latitude) && $scope.scenario.hotel.longitude !== undefined && parseFloat($scope.scenario.hotel.longitude)) { var LatLng = {lat: parseFloat($scope.scenario.hotel.latitude), lng: parseFloat($scope.scenario.hotel.longitude)}; } if ($scope.scenario.hotel.name !== undefined) { name = $scope.scenario.hotel.name; } //init map var map = new google.maps.Map(document.getElementById('googleMap'), { zoom: 6, center: LatLng }); //place marker var marker = new google.maps.Marker({ position: LatLng, map: map, title: name, }); } $scope.addActivity = function(activityOneDay){ $scope.activitiesTable.toggleButton(btn, row); } $scope.changeActivity = function(activity, functionName){ switch(functionName) { case 'create': //create activity if (activity[0] !== undefined && activity[0]['date'] !== undefined && activity[0]['date']) { $scope.activitiesTable.fieldDetails['date']['default'] = activity[0].date; } row = {}; btn = $scope.activitiesTable.buttons['C']; break; case 'copy': case 'update': case 'delete': //update and delete activity var updateActivity = Object(); /* -----------------[set known data]----------------*/ if(activity.activity_type_id != undefined){ updateActivity['activity_type_id'] = activity.activity_type_id; } if(activity.country_id != undefined){ updateActivity['country_id'] = activity.country_id; } if(activity.from != undefined){ //set from time var fromTime = activity.from; var arrFromTime = fromTime.split(":"); newFromTime = new Date(0 , 0, 0, arrFromTime[0], arrFromTime[1], arrFromTime[2]); updateActivity['from'] = newFromTime; } if(activity.till != undefined){ //set till time var tillTime = activity.till; var arrTillTime = tillTime.split(":"); newTillTime = new Date(0 , 0, 0, arrTillTime[0], arrTillTime[1], arrTillTime[2]); updateActivity['till'] = newTillTime; } //create object for update and delete updateActivity['id'] = activity.id; //check for all variables if(activity.name != undefined){ //set name updateActivity['name'] = activity.name; } if(activity.address != undefined) { updateActivity['address'] = activity.address; } if(activity.postalcode != undefined) { updateActivity['postalcode'] = activity.postalcode; } if(activity.place != undefined) { updateActivity['place'] = activity.place; } if(activity.contactperson != undefined) { updateActivity['contactperson'] = activity.contactperson; } if(activity.description != undefined) { updateActivity['description'] = activity.description; } if(activity.date != undefined){ //set date updateActivity['date'] = new Date(activity.date); } if(activity.price != undefined && activity.price){ //set price updateActivity['price'] = parseFloat(activity.price); } if(activity.price_sales != undefined && activity.price_sales){ //set price_sales updateActivity['price_sales'] = parseFloat(activity.price_sales); } if(activity.hide_from_scenario != undefined){ //set hide_from_scenario updateActivity['hide_from_scenario'] = activity.hide_from_scenario; } /* set known match data is type is match */ if(activity.activity_type_id == 5) { if (parseInt(activity.football_match_id)) { var req = { method: 'GET', url: '/football_match/get/' + activity.football_match_id, } //response $http(req).then(function (response){ if(response.data.status){ activity.club = response.data.data.club; activity.field = response.data.data.field; activity.stadium = response.data.data.stadium; activity.referee = response.data.data.referee; //show match fields $scope.activitiesTable.fieldDetails['club'].hideEdit = false; $scope.activitiesTable.fieldDetails['field'].hideEdit = false; $scope.activitiesTable.fieldDetails['stadium'].hideEdit = false; $scope.activitiesTable.fieldDetails['referee'].hideEdit = false; //set match field data $scope.activitiesTable.modal.data['club'] = activity.club; $scope.activitiesTable.modal.data['field'] = activity.field; $scope.activitiesTable.modal.data['stadium'] = activity.stadium; $scope.activitiesTable.modal.data['referee'] = activity.referee; } }); }else{ //show match fields $scope.activitiesTable.fieldDetails['club'].hideEdit = false; $scope.activitiesTable.fieldDetails['field'].hideEdit = false; $scope.activitiesTable.fieldDetails['stadium'].hideEdit = false; $scope.activitiesTable.fieldDetails['referee'].hideEdit = false; } }else{ // hide match $scope.activitiesTable.fieldDetails['club'].hideEdit = true; $scope.activitiesTable.fieldDetails['field'].hideEdit = true; $scope.activitiesTable.fieldDetails['stadium'].hideEdit = true; $scope.activitiesTable.fieldDetails['referee'].hideEdit = true; } row = updateActivity; /*---------------[end set known data]----------------*/ if(functionName == 'update'){ btn = $scope.activitiesTable.buttons['U']; }else if(functionName == 'copy') { btn = $scope.activitiesTable.buttons['C']; //unset id delete row['id']; } else { btn = $scope.activitiesTable.buttons['D']; } break; } $scope.activitiesTable.toggleButton(btn, row); } $scope.deleteActivity = function(activity) { //set from time var fromTime = activity.from; var arrFromTime = fromTime.split(":"); newFromTime = new Date(0 ,0, 0, arrFromTime[0], arrFromTime[1], arrFromTime[2]); //set till time var tillTime = activity.till; var arrTillTime = fromTime.split(":"); newTillTime = new Date(0 ,0, 0, arrTillTime[0], arrTillTime[1], arrTillTime[2]); //create objuct for update var updateActivity = Object(); updateActivity['id'] = activity.id; updateActivity['name'] = activity.name; updateActivity['date'] = new Date(activity.date); updateActivity['from'] = newFromTime; updateActivity['till'] = newTillTime; row = updateActivity; btn = $scope.activitiesTable.buttons['D']; $scope.activitiesTable.toggleButton(btn, row); } $scope.contactPersons = { name: 'Contactpersonen', controller: 'scenario_contactperson', function: 'getForOverview/' + $scope.scenarioId, //Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 10, autoChangeTo: ['user_id'], fields: [ 'scenario_id', 'description', 'name', 'mobile', 'in_app', 'photo', 'user_id', 'photo_show', ], fieldDetails: { 'scenario_id': { 'label': 'Scenario', 'type': 'number', 'hideList': true, 'hideEdit': true, 'default': $scope.scenarioId, }, 'description': { 'label': 'Beschrijving', }, 'name': { 'label': 'Naam', }, 'mobile': { 'label': 'Telefoonnummer', }, 'in_app': { 'label': 'In app', }, 'photo': { 'label': 'Kies een foto of koppel een gebruiker', 'type': 'file', 'uploadFileUrl': 'scenario_contactperson/uploadImage', 'multiple': false, 'hideList': true, }, 'photo_show': { 'label': 'Foto', 'hideEdit': true }, 'user_id': { 'label': 'Koppel gebruiker', } }, buttons: { 'C':{ 'id': 'c', 'name': 'Voeg contactpersonen toe', 'label': 'Voeg contactpersonen toe', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': ($scope.user['rights']['scenario_contactperson']['insert'] ? true : false), 'inline': false, 'icon': 'fa-plus-square', 'action': 'create', }, 'R':{ 'id': 'r', 'name': 'Bekijk contactpersoon', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Wijzig contactpersoon', 'label': 'Wijzig', 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline': ($scope.user['rights']['scenario_contactperson']['update'] ? true : false), 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder contactpersoon', 'label': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline': ($scope.user['rights']['scenario_contactperson']['delete'] ? true : false), 'icon':'fa-trash', 'action': 'delete', }, } } $scope.flights = { name: 'Vluchten', controller: 'scenario_flight', function: 'getPerScenario/' + $scope.scenarioId, //Panel class panelClass: 'panel-trainingskampen', showCount: true, readOnly: !($scope.user && $scope.user.role.id > 1), //hideTable: true, fields: [ 'id', 'flight_id', 'scenario_id', 'flight_number', 'from', 'to', 'departure_date', 'arrival_date', 'pax', 'sequence', ], subQueries: { 'flight':{ 'lfield': 'flight_id', 'ffield': 'id', 'controller': 'flight', } }, fieldDetails: { 'id': { 'label': 'ID', 'hideList': true, 'hideEdit': true, }, 'flight_id': { 'label': 'Selecteer vlucht', 'hideList': true, 'changeTo': ['flight.from', ' - ', 'flight.to', ', ', 'flight.flight_number', ' (', 'flight.departure_date', ' - ', 'flight.arrival_date', ')'] }, 'scenario_id': { 'label': 'Scenario', 'hideList': true, 'hideEdit': true, }, 'flight_number': { 'label': 'Vluchtnummer', 'hideEdit': true, }, 'from': { 'label': 'Van', 'hideEdit': true, }, 'to': { 'label': 'Naar', 'hideEdit': true, }, 'departure_date': { 'label': 'Vertrek datum', 'sortAsc': true, 'hideEdit': true, }, 'arrival_date': { 'label': 'Aankomst datum', 'hideEdit': true, }, 'pax': { 'label': 'Pax', 'hideEdit': true, }, 'sequence': { 'label': 'Seq', 'hideEdit': true, }, }, buttons: { 'C':{ 'id': 'c', 'name': 'Vlucht toevoegen', 'label': 'Vlucht toevoegen', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': $scope.user.rights.scenario_flight && $scope.user.rights.scenario_flight.insert, 'inline': false, 'icon': 'fa-plus-square', 'action': 'create', }, 'R':{ 'id': 'r', 'name': 'Bekijk', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': false, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Wijzig' , 'label': 'Wijzig' , 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline':false, 'icon':'fa-pencil', 'action': 'update', }, 'P':{ 'id': 'p', 'name': 'Pax' , 'label': 'Pax' , 'cancelName': 'Annuleren', 'confirmName': 'Pax', 'confirmClass': 'success', 'inline': true, 'icon':'fa-eye', 'action': 'selectFlight', 'parentScope': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder vlucht', 'label': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline': false, 'icon':'fa-trash', 'action': 'delete', }, 'DD':{ 'id': 'dd', 'name': 'Verwijder vlucht', 'label': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline': $scope.user.rights.scenario_flight && $scope.user.rights.scenario_flight.delete, 'icon':'fa-trash', 'action': 'deleteScenarioFlight', 'parentScope': true, }, } } $scope.deleteScenarioFlight = function(btn, row, blnSubmit) { btn = $scope.flights.buttons['D']; // unset hide edit $scope.flights.fieldDetails.flight_id.hideEdit = true; $scope.flights.fieldDetails.flight_number.hideEdit = false; $scope.flights.toggleButton(btn, row); } $scope.modalClose = function(tableName) { if (tableName == $scope.flights.name) { // reset hide edit $scope.flights.fieldDetails.flight_id.hideEdit = false; $scope.flights.fieldDetails.flight_number.hideEdit = true; } else if (tableName == $scope.flightAttendees.name) { // reset hide edit $scope.flightAttendees.fieldDetails.ssr_baggage.hideEdit = false; $scope.flightAttendees.fieldDetails.scenario_attendee_id.hideEdit = true; } } $scope.attendeeTable = { name: 'Passagiers', controller: 'scenario_attendee', function: 'getPerScenarioForFlights/' + $scope.scenarioId, //Panel class panelClass: 'panel-trainingskampen', showCount: true, readOnly: !($scope.user && $scope.user.role.id > 1), showRowCount: true, //hideTable: true, fields: [ 'id', 'name', 'attendee_flight', ], fieldDetails: { 'id': { 'label': 'ID', 'hideList': true, }, 'name': { 'label': 'Passagier', }, 'attendee_flight': { 'label': 'Deelnemerslijst vs Vlucht', 'type': 'boolean', 'booleanOn': 1, 'booleanOff': 0, }, }, buttons: { 'C':{ 'id': 'c', 'name': 'Toevoegen', 'label': 'Toevoegen', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': false, 'inline': false, 'icon': 'fa-plus-square', 'action': 'create', }, 'R':{ 'id': 'r', 'name': 'Bekijk', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Wijzig' , 'label': 'Wijzig' , 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline': false, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder', 'label': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline': false, 'icon':'fa-trash', 'action': 'delete', }, } } $scope.flightAttendees = { name: 'Vlucht deelnemers', controller: 'scenario_flight_passenger', function: 'getPerScenario/' + $scope.scenarioId, //Panel class panelClass: 'panel-trainingskampen', showFilters: false, readOnly: !($scope.user && $scope.user.role.id > 1), showRowCount: true, fields: [ 'scenario_flight_id', 'scenario_attendee_id', 'ssr_baggage', ], predefinedFilters: { 'scenario_flight_id': $scope.activeFlightTab, }, subQueries: { 'flight': { 'lfield': 'scenario_flight_id', 'ffield': 'id', 'controller': 'scenario_flight', 'function': 'getPerScenario/' + $scope.scenarioId, }, 'scenario_attendee': { 'lfield': 'scenario_attendee_id', 'ffield': 'id', 'controller': 'scenario_attendee', 'function': 'getForContactInfo/' + $scope.scenarioId, }, }, fieldDetails: { 'scenario_flight_id': { 'label': 'Vlucht', 'changeTo': ['flight.id', ' - ', 'flight.flight_number'], 'hideEdit': true }, 'scenario_attendee_id': { 'label': 'Deelnemer', 'hideEdit': true, 'required': true, 'changeTo': [('scenario_attendee.passport_name_first' != undefined ? 'scenario_attendee.passport_name_first' : ''), ' ', ('scenario_attendee.passport_name_last' != undefined ? 'scenario_attendee.passport_name_last' : '')], 'disabled': true, }, 'ssr_baggage': { 'label': 'Bagage', 'type': 'enum', 'options': [{ 'id': '', 'name': 'Geen bagage', }, { 'id': '5B15', 'name': '15 kg', }, { 'id': '5B20', 'name': '20 kg', }, { 'id': '5B25', 'name': '25 kg', }, { 'id': '5B30', 'name': '30 kg', }, { 'id': '5B40', 'name': '40 kg', }, { 'id': '5B50', 'name': '50 kg', }], }, }, buttons: { 'C':{ 'id': 'c', 'name': 'Wijzig deelnemers', 'label': 'Wijzig deelnemers', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': $scope.user.role.id > 3, 'inline': false, 'icon': 'fa-users', 'action': 'openPassengerModal', 'parentScope': true, }, 'R':{ 'id': 'r', 'name': 'Bekijk vlucht deelnemer', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': false, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Wijzig vlucht deelnemer' , 'label': 'Wijzig' , 'cancelName': 'Annuleren', 'confirmName': 'Bewerk', 'confirmClass': 'success', 'inline':true, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder vlucht deelnemer', 'label': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline': false, 'icon':'fa-trash', 'action': 'delete', }, 'DD':{ 'id': 'dd', 'name': 'Verwijder vlucht', 'label': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline': true, 'icon':'fa-trash', 'action': 'deleteFlightAttendee', 'parentScope': true, }, 'CC':{ 'id': 'cc', 'name': 'Wijzig bagage', 'label': 'Wijzig bagage', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': $scope.user.role.id > 3, 'icon': 'fa-suitcase', 'action': 'openBaggageModal', 'parentScope': true, }, 'AE':{ 'id': 'ae', 'name': 'Lege rijen toevoegen', 'label': 'Lege rijen toevoegen', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'success', 'header': $scope.user.role.id > 3, 'inline': false, 'icon': 'fa-plus-square', 'action': 'addEmptyPassengers', 'parentScope': true, }, } } $scope.deleteFlightAttendee = function(btn, row, blnSubmit) { btn = $scope.flightAttendees.buttons['D']; // unset hide edit $scope.flightAttendees.fieldDetails.ssr_baggage.hideEdit = true; $scope.flightAttendees.fieldDetails.scenario_attendee_id.hideEdit = false; $scope.flightAttendees.toggleButton(btn, row); } $scope.attendeeModalTable = { name: 'Wijzig vlucht deelnemers', controller: 'scenario_flight_passenger', function: 'getScenarioAttendees/' + $scope.scenarioId, //Panel class panelClass: 'panel-trainingskampen', showFilters: false, showRowCount: true, selectable: true, fields: [ 'id', 'scenario_id', 'scenario_flight_id', 'contact_id', 'ssr_baggage', ], subQueries: { 'contact': { 'lfield': 'contact_id', 'ffield': 'id', 'controller': 'contact', 'function': 'getPerScenario/' + $scope.scenarioId, }, }, fieldDetails: { 'id': { 'hideList': true, 'hideEdit': true, }, 'scenario_id': { 'hideList': true, 'hideEdit': true, }, 'scenario_flight_id': { 'hideList': true, 'hideEdit': true, }, 'contact_id': { 'label': 'Naam', 'changeTo': ['contact.passport_name_first', ' ', 'contact.passport_name_last'], }, 'ssr_baggage': { 'hideList': true, 'hideEdit': true, }, }, buttons: { 'C':{ 'id': 'c', 'name': 'Wijzig passagiers', 'label': 'Wijzig passagiers', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'create', 'header': false, 'inline': false, 'icon': 'fa-plus-square', 'action': 'openPassengerModal', 'parentScope': true, }, 'R':{ 'id': 'r', 'name': 'Bekijk vlucht deelnemer', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': false, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Wijzig vlucht deelnemer' , 'label': 'Wijzig' , 'cancelName': 'Annuleren', 'confirmName': 'Bewerk', 'confirmClass': 'success', 'inline':false, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder vlucht deelnemer', 'label': 'Verwijder', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline':false, 'icon':'fa-trash', 'action': 'delete', }, } } $scope.baggageModalTable = { name: 'Wijzig baggage', controller: 'scenario_flight_passenger', function: 'getPerScenario/' + $scope.scenarioId, //Panel class panelClass: 'panel-trainingskampen', showFilters: false, showRowCount: true, selectable: true, fields: [ 'id', 'scenario_id', 'scenario_attendee_id', 'scenario_flight_id', 'ssr_baggage', ], predefinedFilters: { 'scenario_flight_id': $scope.activeFlightTab, }, subQueries: { 'flight': { 'lfield': 'scenario_flight_id', 'ffield': 'id', 'controller': 'scenario_flight', 'function': 'getPerScenario/' + $scope.scenarioId, }, 'scenario_attendee': { 'lfield': 'scenario_attendee_id', 'ffield': 'id', 'controller': 'scenario_attendee', 'function': 'getForContactInfo/' + $scope.scenarioId, }, }, fieldDetails: { 'scenario_flight_id': { 'label': 'Vlucht', 'changeTo': ['flight.id', ' - ', 'flight.flight_number'], 'hideList': true, 'hideEdit': true, }, 'scenario_attendee_id': { 'label': 'Naam', 'hideEdit': true, 'required': true, 'changeTo': [('scenario_attendee.passport_name_first' != undefined ? 'scenario_attendee.passport_name_first' : ''), ' ', ('scenario_attendee.passport_name_last' != undefined ? 'scenario_attendee.passport_name_last' : '')], 'disabled': true, }, 'id': { 'hideList': true, 'hideEdit': true, }, 'scenario_id': { 'hideList': true, 'hideEdit': true, }, 'ssr_baggage': { 'label': 'Bagage', 'type': 'enum', 'options': [{ 'id': '', 'name': 'Geen bagage', }, { 'id': '5B15', 'name': '15 kg', }, { 'id': '5B20', 'name': '20 kg', }, { 'id': '5B25', 'name': '25 kg', }, { 'id': '5B30', 'name': '30 kg', }, { 'id': '5B40', 'name': '40 kg', }, { 'id': '5B50', 'name': '50 kg', }], }, }, buttons: { 'C':{ 'id': 'c', 'header': false, }, 'R':{ 'id': 'r', 'inline': false, }, 'U':{ 'id': 'u', 'inline': false, }, 'D':{ 'id': 'd', 'inline':false, }, 'SU':{ 'id': 'su', 'name': 'Selecteer oneven rijen', 'header': true, 'icon': 'fa-plus-square', 'action': 'selectUnevenBaggageRows', 'function': 'read', 'parentScope': true, }, 'EA':{ 'id': 'ea', 'name': 'Uitvoeren TK bagage algoritme', 'header': true, 'icon': 'fa-plus-square', 'action': 'executeBaggageAlgoritm', 'function': 'read', 'parentScope': true, }, } } // $scope.$on('scenario_loaded', function(event) { $scope.initActivitiesTable(); }); // $scope.initActivitiesTable = function() { $scope.activitiesTable = { name: 'Activiteiten', controller: 'scenario_activity', function: 'getPerScenario/' + $scope.scenarioId, //Panel class panelClass: 'panel-trainingskampen', hideTable: true, fields: [ 'scenario_id', 'organization_id', 'activity_id', 'activity_type_id', 'country_id', 'football_match_id', 'name', 'address', 'postalcode', 'place', 'contactperson', 'date', 'from', 'till', 'description', 'price', 'price_sales', //match fields 'club', 'field', 'stadium', 'referee', // 'pay_per_camp', 'hide_from_scenario', ], subQueries: { 'activity': { 'lfield': 'actvity_id', 'ffield': 'id', 'controller': 'activity', }, 'activity_type': { 'lfield': 'activity_type_id', 'ffield': 'id', 'controller': 'activity_type', }, 'country': { 'lfield': 'country_id', 'ffield': 'id', 'controller': 'country', }, 'football_match': { 'lfield': 'football_match_id', 'ffield': 'id', 'controller': 'football_match', } }, fieldDetails: { 'scenario_id': { 'label': 'scenario', 'type': 'number', 'hideEdit': true, 'default': $scope.scenarioId, }, 'organization_id': { 'label': 'organisatie', 'type': 'number', 'hideEdit': true, 'default': $scope.organizationId, }, 'activity_type_id': { 'label': 'Activiteits type', 'changeTo': ['activity_type.name'], }, 'activity_id': { 'label': 'Activiteit', 'changeTo': ['activity.name'], }, 'country_id': { 'label': 'Land', 'changeTo': ['country.name'], }, 'football_match_id': { 'label': 'tegenstander', 'changeTo': ['football_match.club'], 'hideEdit': true, }, 'name': { 'label': 'Naam', 'required': true, }, 'date': { 'label': 'Datum', 'required': true, }, 'from': { 'label': 'Vanaf', 'required': true, 'type': 'time', }, 'till': { 'label': 'Tot', 'type': 'time', }, 'price': { 'label': 'Extra inkoopkosten', 'required': false, //'type': 'number', }, 'price_sales': { 'label': 'Extra verkoopkosten', 'required': false, //'type': 'number', }, //match fields 'club':{ 'label': 'Tegenstander', 'hideEdit': true, }, 'field':{ 'label': 'Veld', 'hideEdit': true, }, 'stadium':{ 'label': 'Stadion', 'hideEdit': true, }, 'referee':{ 'label': 'Scheidsrechter', 'hideEdit': true, }, 'address':{ 'label': 'Adres', }, 'postalcode':{ 'label': 'Postcode', }, 'place':{ 'label': 'Plaats', }, 'contactperson':{ 'label': 'Contactpersoon', }, 'description':{ 'label': 'Beschrijving', }, /* 'pay_per_camp': { 'label': 'Betaal eenmalig', }, */ 'hide_from_scenario': { 'label': 'Verberg in draaiboek', } }, buttons: { 'C':{ 'id': 'c', 'name': 'Voeg activiteit toe', 'label': 'Voeg activiteit toe', 'cancelName': 'Annuleren', 'confirmName': 'Voeg toe', 'confirmClass': 'success', 'icon': 'fa-plus-square', 'header': true, 'action': 'create', }, 'R':{ 'id': 'r', 'name': 'Bekijk activiteit', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Wijzig activiteit' , 'label': 'Wijzig' , 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline':true, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder activiteit', 'label': 'Verwijder activiteit', 'cancelName': 'Annuleren', 'confirmName': 'Verwijder', 'confirmClass': 'warning', 'inline':true, 'icon':'fa-trash', 'action': 'delete', }, } } // } $scope.selectUnevenBaggageRows = function(btn) { $scope.baggageModalTable.data.rows .filter((row, index) => { return row.scenario_flight_id == $scope.activeFlightTab; }) .forEach((row, index) => { if (index % 2 == 1) { row['sba_selected'] = row['sba_selected'] ? !row['sba_selected'] : true; } }); } $scope.executeBaggageAlgoritm = async function(btn) { let baggageUpdateStatus = false; let activeFlightRows = $scope.baggageModalTable.data.rows.filter((row, index) => row.scenario_flight_id == $scope.activeFlightTab); let totalPassengers = Object.keys(activeFlightRows).length; // show error swal if not enough passengers // need atleast 2 passengers since 10kg + 60kg = 70kg on 1 passenger while max is 50kg per passengers if (totalPassengers < 2) { return swal('Mislukt', 'Er zijn te weinig vlucht deelnemers om het bagage algoritme toe te passen', 'error'); } for (const [index, row] of Object.entries(activeFlightRows)) { // start with 0 (can be max 50) let baggage = 0; // every 3rd iteration add 30kg for 3 passengers (10kg each) if (index % 3 == 2) { baggage += 30; } // give last to second passenger sport baggage split 60kg when 50kg is standard on the last passenger if (index == totalPassengers - 2) { baggage = 50 - 10 * (3 - ((totalPassengers - 1) % 3)); } // set last passenger's baggage to 50kg & set second to last passenger's baggage to 50kg if was set to 20kg in calculation above if (index == totalPassengers - 1 || (index == totalPassengers - 2 && index % 3 == 2)) { baggage = 50; } row['ssr_baggage'] = baggage > 0 ? '5B' + baggage : ''; // update each row var req = { method: 'POST', url: '/scenario_flight_passenger/update/' + row.id, data: { ssr_baggage: row['ssr_baggage'] }, } var response = await $http(req); if (response.data.status) { baggageUpdateStatus = true; // update table rows with new baggage if ($scope.flightAttendees.data.rows.find(r => r.id == row.id) !== undefined && response.data?.data?.ssr_baggage !== undefined && response.data?.data?.ssr_baggage !== null) { $scope.flightAttendees.data.rows.find(r => r.id == row.id).ssr_baggage = response.data.data.ssr_baggage; } } else { // set status to false baggageUpdateStatus = false; } } // show response swal if (baggageUpdateStatus) { swal('Gelukt', 'De bagages van alle vlucht deelnemers zijn succesvol aangepast', 'success'); } else { swal('Mislukt', 'De bagages van één of meerdere vlucht deelnemers konden niet worden aangepast', 'error'); } } //get all existing activities $scope.getAllActivities = function(){ var req = { method: 'GET', url: '/activity/getWith', } //response $http(req).then(function (response){ if(response.data.status){ $scope.allActivities = response.data.data; } }); } $scope.getAllActivities(); $scope.sbaCrudTableChange = function(tableName, fieldName, fieldValue, eventType) { if (tableName == 'Vluchten') { $scope.flights.modal.data['scenario_id'] = $routeParams.id; } switch (fieldName) { case 'activity_id': var arrActivities = $scope.allActivities; var search = arrActivities.find(function(activity) { if(fieldValue) { return activity.id == fieldValue.id; } }); if (search) { activity = search; $scope.activitiesTable.setCombobox('activity_type_id', String(activity.activity_type_id)); $scope.activitiesTable.setCombobox('country_id', String(activity.country.id)); $scope.activitiesTable.modal.data['name'] = activity.name; $scope.activitiesTable.modal.data['address'] = activity.address; $scope.activitiesTable.modal.data['postalcode'] = activity.postalcode; $scope.activitiesTable.modal.data['place'] = activity.place; $scope.activitiesTable.modal.data['contactperson'] = activity.contactperson; $scope.activitiesTable.modal.data['from'] = new Date(activity.from); $scope.activitiesTable.modal.data['till'] = new Date(activity.till); $scope.activitiesTable.modal.data['description'] = activity.description; if(activity.activity_type_id == 5){ //show match fields $scope.activitiesTable.fieldDetails['club'].hideEdit = false; $scope.activitiesTable.modal.data['club'] = activity.football_match.club; $scope.activitiesTable.fieldDetails['field'].hideEdit = false; $scope.activitiesTable.modal.data['field'] = activity.football_match.field; $scope.activitiesTable.fieldDetails['stadium'].hideEdit = false; $scope.activitiesTable.modal.data['stadium'] = activity.football_match.stadium; $scope.activitiesTable.fieldDetails['referee'].hideEdit = false; $scope.activitiesTable.modal.data['referee'] = activity.football_match.referee; }else{ // hide match $scope.activitiesTable.fieldDetails['club'].hideEdit = true; $scope.activitiesTable.fieldDetails['field'].hideEdit = true; $scope.activitiesTable.fieldDetails['stadium'].hideEdit = true; $scope.activitiesTable.fieldDetails['referee'].hideEdit = true; } } else { $scope.activitiesTable.modal.data['activity_type_id'] = ''; $scope.activitiesTable.modal.data['country_id'] = ''; $scope.activitiesTable.modal.data['football_match_id'] = ''; $scope.activitiesTable.modal.data['name'] = ''; $scope.activitiesTable.modal.data['address'] = ''; $scope.activitiesTable.modal.data['postalcode'] = ''; $scope.activitiesTable.modal.data['place'] = ''; $scope.activitiesTable.modal.data['contactperson'] = ''; $scope.activitiesTable.modal.data['from'] = ''; $scope.activitiesTable.modal.data['till'] = ''; $scope.activitiesTable.modal.data['description'] = ''; } $scope.activitiesTable.call('checkRequired'); break; case 'activity_type_id': if(fieldValue && (fieldValue.id == 5)){ //show match fields $scope.activitiesTable.fieldDetails['club'].hideEdit = false; $scope.activitiesTable.fieldDetails['field'].hideEdit = false; $scope.activitiesTable.fieldDetails['stadium'].hideEdit = false; $scope.activitiesTable.fieldDetails['referee'].hideEdit = false; }else{ // hide match $scope.activitiesTable.fieldDetails['club'].hideEdit = true; $scope.activitiesTable.fieldDetails['field'].hideEdit = true; $scope.activitiesTable.fieldDetails['stadium'].hideEdit = true; $scope.activitiesTable.fieldDetails['referee'].hideEdit = true; } $scope.activitiesTable.call('checkRequired'); break; } } //add all participants to flights $scope.addAllParticpants = function(){ swal({ title: "Weet je zeker dat je alle deelnemers aan alle vluchten toe wilt voegen?", text: "De deelnemers die al in de lijst stonden zullen verloren gaan?", icon: "warning", buttons: { cancel: true, confirm: true, }, dangerMode: true, }) .then((result) => { if (result) { var req = { method: 'POST', url: '/scenario_flight_passenger/addAllParticipants/' + $scope.scenarioId, data: { 'bagage': $scope.attendeeBagage }, } //response $http(req).then(function (response){ if (response.status && response.data.status) { $scope.getScenario(); //$scope.flights.call('initiate'); } else { $scope.notification('Foutmelding', 'De passagiers konden niet worden toegevoegd aan de vlucht, probeer het opnieuw!', 'danger'); } }); } }); } /* KAMERLIJSTEN FUNCTIONS */ $scope.rooms = [ { 'id': 1, 'beds': [ { 'id': 1, 'amount_of_persons': 1, 'attendees': [], }, { 'id': 2, 'amount_of_persons': 1, 'attendees': [], }, ], }, { 'id': 2, 'beds': [ { 'id': 1, 'amount_of_persons': 1, 'attendees': [], }, { 'id': 2, 'amount_of_persons': 2, 'attendees': [], }, { 'id': 3, 'amount_of_persons': 1, 'attendees': [], }, ], }, ]; // Extra payment $scope.sendExtraPayment = function() { if ($scope.extraPaymentAmount) { if ($scope.extraPaymentAmount > ($scope.getActivityCosts() - $scope.getPayedAmount())) { swal({ title: 'Let op!', text: 'Het bedrag is hoger dan het openstaande bedrag!', type: 'warning', buttons: { cancel: true, confirm: true, }, }).then(ok => { if (!ok) throw null; $scope.sendPayment(); }); } else { $scope.sendPayment(); } } else { $scope.extraPyamentMessage = 'Voer een geldig bedrag in.'; } } $scope.sendPayment = function () { $scope.extraPyamentMessage = null; // Send the payment var req = { method: 'POST', url: '/payment/sendExtraPayment/' + $scope.scenarioId + '/' + $scope.extraPaymentAmount, data: { 'description': $scope.extraPaymentDescription } } $http(req).then(function(response) { if (response.status && response.data.status) { // Hide the modal $("#paymentModal").modal('toggle') // Refresh the overview $scope.getScenario(); // OK $scope.notification("Gelukt!", response.data.message, "success"); } else { // Error $scope.extraPaymentMessage = response.data.message; } }); } //array from numberOf $scope.getNumber = function(num) { return new Array(parseInt(num)); } $scope.getLabel = function(attendee){ return attendee.name + " (" + attendee.type + ")"; } $scope.availableAttendees = []; $scope.getAvailableAttendees = function(attendeeId){ if(!angular.isNumber(attendeeId)){ return $scope.availableAttendees; }else{ searchAttendee = $filter('filter')($scope.attendees, {'id': attendeeId}, true); return angular.extend(angular.copy($scope.availableAttendees), searchAttendee); } } $scope.calculateAvailableAttendees = function(currentBed){ $scope.availableAttendees = angular.copy($scope.attendees); if(currentBed === undefined){ angular.forEach($scope.rooms, function(room){ angular.forEach(room.beds, function(bed){ angular.forEach(bed.attendees, function(attendee){ if(angular.isNumber(attendee)){ searchAttendee = $filter('filter')($scope.availableAttendees, {'id': attendee}, true); if(searchAttendee && searchAttendee[0]){ $scope.availableAttendees.splice($scope.availableAttendees.indexOf(searchAttendee[0]), 1); } } }); }); }); }else{ angular.forEach(currentBed.attendees, function(attendee){ if(angular.isNumber(attendee)){ searchAttendee = $filter('filter')($scope.availableAttendees, {'id': attendee}, true); if(searchAttendee && searchAttendee[0]){ $scope.availableAttendees.splice($scope.availableAttendees.indexOf(searchAttendee[0]), 1); } } }); } } // Image upload function $scope.uploadImage = function(file, model, id, index, item = null) { $scope.fileInfo = { file: file } if ($scope.fileInfo.file) { $scope.fileInfo.loading = true; var fileName = $scope.fileInfo.file.name; fileName = fileName.replace('#', ''); fileName = fileName.replace('+', ''); fileName = fileName.replace(' ', '_'); url = '/filecontroller/uploadImage/' + model + '/' + id; if (index !== undefined) { url += '/' + index; } url += '?name=' + encodeURI(fileName); Upload.upload({ url: url, data: { file: $scope.fileInfo.file, }, }).then(function (response) { $scope.currentImages = response.data.data; $scope.gotUploadImages(model, id, index, item); $scope.uploadMsgType = 'success'; $scope.uploadImageMessage = 'Succesvol opgeslagen'; }, function (response) { if (response.status > 0) $scope.errorMsg = response.status + ': ' + response.data; }, function (evt) { $scope.fileInfo.file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); $scope.uploadMsgType = 'info'; $scope.uploadImageMessage = 'Het wordt opgeslagen: ' + $scope.fileInfo.file.progress; }); } } $scope.gotUploadImages = function (model, id, index, item) { if (index === undefined) { index = $scope.currentImages.length; } if (model === 'hotels' && item) { // Add the hotel image to the list item.images = angular.toJson($scope.currentImages); } } $scope.deleteImage = function(model, id, index, path, item = null) { // Delete the image var req = { method: 'POST', url: '/filecontroller/deleteImage', data: { index: index, id: id, model: model, path: path, } } $http(req).then(function(response) { // Success? Set the options if (response.status && response.data.status) { // OK $scope.getImages(model, id, item); } else { // Error $scope.notification('Foutmelding', 'De afbeelding kon niet worden verwijderd, probeer het opnieuw!', 'warning'); } }); } $scope.getImages = function(model, id, images = null, item = null) { var req = { method: 'POST', url: '/filecontroller/getImages/' + model + '/' + id, data: { images: images, }, } $http(req).then(function(response) { // Success? Set the options if (response.status && response.data.status) { // OK $scope.currentImages = response.data.data; if (item) { item.images = response.data.data; } } else { // Error $scope.notification('Foutmelding', 'De afbeeldingen konden niet worden geladen', 'warning'); } }) } $scope.getFrontImages = function( images = null, item = null) { var req = { method: 'POST', url: '/filecontroller/getImages/scenarios/' + $routeParams.id, data: { images: images, }, } $http(req).then(function(response) { // Success? Set the options $scope.frontPageImage = response.data.data[0]; }) } $scope.getFrontImages(); // Image upload function $scope.uploadFrontPageImage = function(file, model, id, item = null) { $scope.fileInfo = { file: file } if ($scope.fileInfo.file) { $scope.fileInfo.loading = true; var fileName = $scope.fileInfo.file.name; fileName = fileName.replace('#', ''); fileName = fileName.replace('+', ''); fileName = fileName.replace(' ', '_'); url = '/filecontroller/uploadImage/' + model + '/' + id; if($scope.frontPageImage !== undefined){ url += '/' + 0; } url += '?name=' + encodeURI(fileName); Upload.upload({ url: url, data: { file: $scope.fileInfo.file, }, }).then(function (response) { if (response.status && response.data.status) { $scope.currentImages = response.data.data; $scope.getFrontImages(); } else { $scope.notification('Foutmelding', 'De voorblad afbeelding kon niet worden geupload, probeer het opnieuw!', 'danger'); } }, function (response) { if (response.status > 0) $scope.errorMsg = response.status + ': ' + response.data; }, function (evt) { $scope.fileInfo.file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)); $scope.uploadMsgType = 'info'; $scope.uploadImageMessage = 'Het wordt opgeslagen: ' + $scope.fileInfo.file.progress; }); } } $scope.deleteFrontPageImage = function(model, id, path, item = null) { // Delete the image var req = { method: 'POST', url: '/filecontroller/deleteImage', data: { index: 0, id: id, model: model, path: path, } } $http(req).then(function(response) { // Success? Set the options if (response.status && response.data.status) { // OK $scope.getFrontImages(); } else { // Error $scope.notification('Foutmelding', 'De voorblad afbeelding kon niet worden verwijderd, probeer het opnieuw!', 'danger'); } }); } //afterChages $scope.afterChange = function(tableName, data, functionName){ //always reload last changes table $scope.lastChanges.call('initiate'); //only call get scenarios when not activiteit because not user friendly if (tableName == 'Activiteiten') { switch (functionName) { case 'CREATE': case 'UPDATE': // get activity from backend var req = { method: 'GET', url: '/scenario_activity/get/' + data.id, } $http(req).then(function (response){ if (response.data.status) { let newActivity = response.data.data; let foundedDate = false; angular.forEach($scope.arrActivitiPerDate, function(activitieOneDay, key){ angular.forEach(activitieOneDay, function(activity, activitieOneDayKey){ if (!foundedDate) { if (functionName == "CREATE") { if (activity.date == newActivity.date) { activitieOneDay.push(newActivity); foundedDate = true; } } else { if (activity.id == newActivity.id) { activitieOneDay[activitieOneDayKey] = newActivity; foundedDate = true; } } } }); }); //check foundedDate if (!foundedDate){ //new date $scope.arrActivitiPerDate.push([newActivity]); } //sprt $scope.arrActivitiPerDate.sort(function(a, b) { if ( Array.isArray(a) && Array.isArray(b) && a[0] !== undefined && b[0] !== undefined && typeof a[0] == 'object' && typeof b[0] == 'object' && a[0].date !== undefined && b[0].date !== undefined && a[0].date && b[0].date ) { return new Date(a[0].date) - new Date(b[0].date); } else { return 0; } }); angular.forEach($scope.arrActivitiPerDate, function(arrActivitiesOneDay, key) { arrActivitiesOneDay.sort(function(a, b){ return a.from - b.from }); $scope.arrActivitiPerDate[key] = arrActivitiesOneDay; }); } }); break; case 'DELETE': let foundedDate = false; angular.forEach($scope.arrActivitiPerDate, function(activitieOneDay, key){ angular.forEach(activitieOneDay, function(activity, activitieOneDayKey){ if (!foundedDate) { if (activity.id == data.id) { activitieOneDay.splice(activitieOneDayKey, 1); foundedDate = true; //check if empty if (activitieOneDay.length == 0) { $scope.arrActivitiPerDate.splice(key, 1); } } } }); }); break; } } else { $scope.getScenario(); } //reload tables with attendees if(tableName == 'Deelnemers'){ var arrTables = ['flights'] $scope.$broadcast('init'); angular.forEach(arrTables, function(table){ $scope[table].call('initiate'); }); } if (tableName == 'Contactpersonen'){ $scope.contactPersons.call('initiate'); } } //translate table $scope.tableReady = function (tableName) { if (tableName === 'Contactpersonen') { $scope.contactPersons.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...', }; }else if (tableName === 'Vluchten') { $scope.flights.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...', }; //check for flight data if ($scope.flights.data !== undefined && $scope.flights.data.rows != undefined && $scope.attendeeTable !== undefined && $scope.attendeeTable.fields != undefined) { angular.forEach($scope.flights.data.rows, function(flight) { if ($scope.attendeeTable.fields.indexOf(flight.flight_number) < 0) { $scope.attendeeTable.fields.push(flight.flight_number); $scope.attendeeTable.fieldDetails[flight.flight_number] = { 'label': flight.flight_number, 'type': 'boolean', 'booleanOn': 1, 'booleanOff': 0, }; } }); $scope.attendeeTable.call('initiate'); } } else if (tableName === 'Activiteiten') { $scope.activitiesTable.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...', }; } else if (tableName === $scope.attendeeModalTable.name) { // loop through attendee modal rows and set selected items based on the selected flight $scope.attendeeModalTable.data.rows.forEach((row) => { if ($scope.selectedFlight != undefined && $scope.selectedFlight.id != undefined && row.scenario_flight_id == $scope.selectedFlight.id) { row['sba_selected'] = true; } }); } } $scope.saveRoomingList = function() { var req = { method: 'POST', url: '/scenario/update/' + $scope.scenario['id'], data: { 'enable_rooming_list': $scope.scenario['enable_rooming_list'], } } $http(req).then(function(response) { if (response.status && response.data.status) { $scope.notification("Succes!", "De kamerlijst is " + ($scope.scenario['enable_rooming_list'] ? 'opengezet' : 'dichtgezet') + " voor de klant", "success"); $scope.getScenario(); } }); } function isValidDate(d) { return d instanceof Date && !isNaN(d); } //bekijk factuur $scope.toInvoice = function(btn, row, blnSubmit) { var loader = document.createElement("i"); loader.classList.add("fa"); loader.classList.add("fa-spinner"); loader.classList.add("fa-5x"); loader.classList.add("fa-spin"); swal({ title: "Loading", content: loader, buttons: false }); var req = { method: 'POST', url: '/invoice/getPdfInvoice/' + row['id'], } $http(req).then(function(response) { swal.close() if (response.status && response.data.status == undefined) { window.open('/invoice/getPdfInvoice/' + row['id'], '_blank'); }else if(response.data.message == 'invoice_number.not.recognized'){ swal('Mislukt', 'Het factuur nummer werd helaas niet herkend, probeer het opnieuw', 'error'); }else{ swal('Mislukt', 'De factuur kon helaas niet worden opgehaald, probeer het opnieuw', 'error'); } }, function(error) { swal('Mislukt', 'De factuur kon helaas niet worden opgehaald, gelieve contact op te nemen met SBA', 'error'); }); } //verstuur factuur $scope.sendInvoice = function(btn, row, blnSubmit) { var loader = document.createElement("i"); loader.classList.add("fa"); loader.classList.add("fa-spinner"); loader.classList.add("fa-5x"); loader.classList.add("fa-spin"); swal({ title: "Loading", content: loader, buttons: false }); var req = { method: 'POST', url: '/invoice/sendInvoice/' + row['id'], } $http(req).then(function(response) { swal.close(); if (response.status && response.data.status) { swal('E-mail verstuurd','De e-mail is met succes verstuurd naar ' + response.data.data.email, 'success'); if (response.data.data.sent == '1') { row['sent'] = 1; } $scope.invoices.call('initiate') } else { swal('E-mail niet verstuurd', 'De e-mail kon helaas niet worden verzonden, probeer het opnieuw', 'error') } }, function(error) { swal.close(); swal('E-mail niet verstuurd', 'De e-mail kon helaas niet worden verzonden, gelieve contact op te nemen met SBA', 'error'); }); // window.open('/invoice/sendInvoice/' + row['id'], '_blank'); } //check for full down payment $scope.checkForFullDownPayment = function() { let fullDownPayment = false; //check if invoices are set if ($scope.scenario != undefined && $scope.scenario.invoices != undefined && Array.isArray($scope.scenario.invoices)) { //find down payment invoice let downPaymentInvoice = $scope.scenario.invoices.find((invoice) => { return invoice.type == "DOWN_PAYMENT"}); //check for amount if (downPaymentInvoice != undefined && downPaymentInvoice.amount != undefined && $scope.quotation != undefined && $scope.quotation.amount != undefined && downPaymentInvoice.amount == $scope.quotation.amount) { fullDownPayment = true; } } return fullDownPayment; } //check for full down payment $scope.checkForSecondPayment = function() { //check if invoices are set let secondPaymentInvoice = false; if ($scope.scenario != undefined && $scope.scenario.invoices != undefined && Array.isArray($scope.scenario.invoices)) { let amount_paid = $scope.scenario.invoices[0].amount; let total = $scope.scenario.price_total; let percentage_paid = (amount_paid / total) * 100; //check for percentage if (percentage_paid < 70) { secondPaymentInvoice = true; } } return secondPaymentInvoice; } //download factuur $scope.downloadInvoice = function(btn, row, blnSubmit) { var loader = document.createElement("i"); loader.classList.add("fa"); loader.classList.add("fa-spinner"); loader.classList.add("fa-5x"); loader.classList.add("fa-spin"); swal({ title: "Loading", content: loader, buttons: false }); var req = { method: 'GET', url: '/invoice/checkExistence/' + row['id'], } $http(req).then(function(response) { swal.close(); if (response.status && response.data.status) { window.open('/invoice/downloadPdfInvoice/' + row['id'], '_blank'); } else if (response.data.message == 'fetch.exact.failed') { swal('Fout', 'De factuur bestaat niet in het administratie pakket.', 'error'); } else { swal('Fout', 'De factuur kon helaas niet worden gedownload', 'error'); } }, function(error) { swal('Fout', 'De factuur kon helaas niet worden gedownload, gelieve contact op te nemen met SBA', 'error'); }); } //pax change $scope.savePax = function(){ if($scope.attendees.length > $scope.scenario.pax){ $scope.notification("Error!", "Het aantal deelnemers is op dit moment al meer, corrigeer dit eerst.", "danger"); }else{ if(!isNaN($scope.scenario.pax) && isValidDate($scope.scenario.from_date_js) && isValidDate($scope.scenario.to_date_js)) { var req = { method: 'POST', url: '/scenario/update/' + $scope.scenario.id, data: { 'name': $scope.scenario.name, 'from': new Date($scope.scenario.from_date_js).toISOString().split('T')[0], 'to': new Date($scope.scenario.to_date_js).toISOString().split('T')[0], 'email_invoice': $scope.scenario.email_invoice, 'email_reminders': $scope.scenario.email_reminders, 'pax': parseInt($scope.scenario.pax), 'price': parseFloat($scope.scenario.price), 'price_total': parseInt($scope.scenario.pax) * parseFloat($scope.scenario.price), } } $http(req).then(function(response) { if (response.status && response.data.status) { $scope.notification("Succes!", "De informatie van het draaiboek is aangepast", "success"); $scope.getScenario(); } }); } else { $scope.notification("Error!", "De informatie van het draaiboek is ongeldig", "error"); } } } /*-----------[Kosten]----------*/ $scope.filterByAmountAndNoPayment = function(activity) { return (activity.price_sales != null && parseFloat(activity.price_sales) != 0 && activity.payment === false); } $scope.getActivityCosts = function(){ cost = parseFloat($scope.scenario.price_total); angular.forEach($scope.scenario.activities, function(activity){ if(activity.payment === false && activity.price_sales){ cost += parseFloat(activity.price_sales); } }); return cost; } $scope.getInvoicedAmount = function() { invoiced = 0.00; angular.forEach($scope.scenario.payments, function(payment){ if(payment.amount){ invoiced += parseFloat(payment.amount); } }); return invoiced; } $scope.getPayedAmount = function(){ paid = 0.00; angular.forEach($scope.scenario.payments, function(payment){ if(payment.status == 'paid'){ paid += parseFloat(payment.amount); } }); return paid; } $scope.getInvoiceAmount = function(){ amount = 0.00; angular.forEach($scope.scenario.invoices, function(invoice){ amount += parseFloat(invoice.amount); }); return amount; } $scope.getInvoiceOpenAmount = function(){ amount = 0.00; angular.forEach($scope.scenario.invoices, function(invoice){ amount += parseFloat(invoice.amount - invoice.paid_amount); }); return amount; } $scope.changeDataTime = function(strDate){ return strDate.substr(0,10); } /*-----------[Add participants]----------*/ $scope.addParticipants = function() { if (parseInt($scope.extraParticipants) > 0) { let req = { method: 'POST', url: '/scenario/update/' + $scope.scenario.id, data: { 'pax': parseInt($scope.scenario.pax) + parseInt($scope.extraParticipants), 'price': parseFloat($scope.scenario.price), 'price_total': (parseInt($scope.scenario.pax) + parseInt($scope.extraParticipants)) * parseFloat($scope.scenario.price), } } $http(req).then(function(response) { if (response.status && response.data.status) { $scope.notification("Succes!", "De informatie van het draaiboek is aangepast", "success"); $scope.getScenario(); $("#addParticipantModal").modal('toggle'); } }); } } /*-----------[Show add participants]----------*/ $scope.showAddParticipant = function() { $scope.fetchAccounts(); //prepare for add participant modal $scope.addParticipantForm = new Object(); $scope.addParticipantForm.extraCosts = 0; } /*-----------[Show delete participants]----------*/ $scope.showDeleteParticipant = function() { $scope.fetchAccounts(); //prepare for delete participant modal $scope.deleteParticipantForm = new Object(); $scope.deleteParticipantForm.price_per_person = -0; } /*-----------[Change extra costs]----------*/ $scope.changeExtraCosts = function(enabled, flight) { //check if price is defined if (flight.price_diff !== undefined && parseFloat(flight.price_diff)) { //check if checkbox is checked if (enabled) { //add costs $scope.addParticipantForm.extraCosts += parseFloat(flight.price_diff); } else { //remove costs $scope.addParticipantForm.extraCosts -= parseFloat(flight.price_diff); } //convert to 2 decimals $scope.addParticipantForm.extraCosts = Math.round($scope.addParticipantForm.extraCosts * 100) / 100; } } $scope.processAddParticipant = function() { let req = { method: 'POST', url: '/scenario/update/' + $scope.scenario.id, data: { 'pax': parseInt($scope.scenario.pax) + 1, 'price': parseFloat($scope.scenario.price), 'price_total': (parseInt($scope.scenario.pax) + 1) * parseFloat($scope.scenario.price), } } $http(req).then(function(response) { if (response.status && response.data.status) { //add extra costs if ($scope.addParticipantForm.extraCosts > 0) { let req = { method: 'POST', url: '/scenario_activity/insert', data: { 'scenario_id': $scope.scenario.id, 'name': 'Toevoegen deelnemer', 'hide_from_scenario': 1, 'price_sales': $scope.addParticipantForm.extraCosts, } } $http(req).then(function(response) { if (response.status && response.data.status) { //close add modal $("#addParticipantModal").modal('toggle'); //open cofirmation modal $scope.confirmationForm = new Object(); $scope.confirmationForm.action = "addParticipant"; $("#participantConfirmationModal").modal('toggle'); //reload scenario $scope.getScenario(); } }); } else { //close add modal $("#addParticipantModal").modal('toggle'); //open cofirmation modal $scope.confirmationForm = new Object(); $scope.confirmationForm.action = "addParticipant"; $("#participantConfirmationModal").modal('toggle'); //reload scenario $scope.getScenario(); } } }); } $scope.processDeleteParticipant = function() { //check if amount of users you want to remove is less than the amount of participants if (($scope.scenario.pax - $scope.deleteParticipantForm.amount) < $scope.scenario.attendees.length) { //cant remove that much $scope.notification("Let op!", "Er staan nog te veel deelenemers in de tabel om het aantal te verlagen, verwijder eerst de deelnemer van het deelnemers tabje.", "warning"); return; } let req = { method: 'POST', url: '/scenario/update/' + $scope.scenario.id, data: { 'pax': parseInt($scope.scenario.pax) - $scope.deleteParticipantForm.amount, 'price': parseFloat($scope.scenario.price), 'price_total': (parseInt($scope.scenario.pax) - $scope.deleteParticipantForm.amount) * parseFloat($scope.scenario.price), } } $http(req).then(function(response) { if (response.status && response.data.status) { //add extra costs if ($scope.deleteParticipantForm.price_per_person > 0) { let req = { method: 'POST', url: '/scenario_activity/insert', data: { 'scenario_id': $scope.scenario.id, 'name': 'Verwijderen van ' + $scope.deleteParticipantForm.amount + ' deelnemer(s)', 'hide_from_scenario': 1, 'price_sales': -$scope.deleteParticipantForm.price_per_person * $scope.deleteParticipantForm.amount, } } $http(req).then(function(response) { if (response.status && response.data.status) { //close add modal $("#removeParticipantsModal").modal('toggle'); //open cofirmation modal $scope.confirmationForm = new Object(); $scope.confirmationForm.action = "deleteParticipant"; $("#participantConfirmationModal").modal('toggle'); //reload scenario $scope.getScenario(); } }); } else { //close add modal $("#removeParticipantsModal").modal('toggle'); //open cofirmation modal $scope.confirmationForm = new Object(); $scope.confirmationForm.action = "deleteParticipant"; $("#participantConfirmationModal").modal('toggle'); //reload scenario $scope.getScenario(); } } }); } $scope.sendConfirmation = function() { let emails = new Array(); let costs = 0; //loop customer accounts to check if ($scope.customerAccounts != undefined) { $scope.customerAccounts.forEach((customer) => { if (customer.send_confirmation) { emails.push(customer.email); } }); } //check for other mail if ($scope.confirmationForm.email != undefined) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($scope.confirmationForm.email)) { emails.push($scope.confirmationForm.email); } else { $scope.notification("Let op!", "Het e-mailadres wat je bij anders hebt ingevuld is geen geldig e-mailadres", "warning"); return; } } if (emails.length <= 0) { $scope.notification("Let op!", "Je hebt geen e-mailadres opgegeven, vink er 1 aan of vul een e-mailadres bij anders", "warning"); return; } if ($scope.confirmationForm.action == "addParticipant") { costs = $scope.addParticipantForm.extraCosts; } if ($scope.confirmationForm.action == "deleteParticipant") { costs = $scope.deleteParticipantForm.price_per_person * $scope.deleteParticipantForm.amount; } let req = { method: 'POST', url: '/scenario/sendConfirmation', data: { 'emails': emails, 'type': $scope.confirmationForm.action, 'scenario_id': $scope.scenario.id, 'costs': costs, } } $http(req).then(function(response) { if (response.status && response.data.status) { $("#participantConfirmationModal").modal('toggle'); //reload scenario $scope.getScenario(); //show notification $scope.notification("Succes!", "De bevestiging is verstuurd", "success"); } }); } /*-----------[Fetch all customer accounts]----------*/ $scope.fetchAccounts = function() { //check for customer id if ($scope.scenario.customer_id != undefined) { var req = { url: '/customer/getAccounts/' + $scope.scenario.customer_id, method: 'GET', } $http(req).then(function(response) { if (response.status && response.data.status) { $scope.customerAccounts = response.data.data; } }); } } /*-----------[change RBR]----------*/ $scope.changeRBR = function() { let req = { method: 'POST', url: '/scenario/update/' + $scope.scenario.id, data: { 'is_rbr': $scope.scenario.is_rbr, } } $http(req).then(function(response) { if (response.status && response.data.status) { $scope.notification("Succes!", "Het draaiboek is aangepast", "success"); $scope.getScenario(); } }); } /*-----------[add empty passengers]----------*/ $scope.addEmptyPassengers = function() { swal({ title: 'Lege rijen toevoegen', text: 'Geef hieronder het aantal lege rijen op welke worden toegevoegd.', content: { element: "input", attributes: { type: "number", }, }, buttons: { cancel: "Annuleer", confirm: { text: "Opslaan", value: true, closeModal: false, }, }, }).then(quantity => { // handle cancel button if (quantity == null) throw null; return quantity }).then(quantity => { //check if quantity is valid if (quantity != undefined && !isNaN(parseFloat(quantity)) && isFinite(quantity)) { // check quantity under 100 for accidental user input if (quantity <= 100) { var req = { method: 'POST', url: '/scenario_flight_passenger/addEmptyPassengers/' + $scope.scenarioId, data: { scenario_flight_id: $scope.selectedFlight.id, quantity }, } $http(req).then((response) => { if (response.data.status) { swal.close(); // reload flight attendees after update $scope.flightAttendees.call('initiate'); } else { swal('Mislukt', 'De lege rij(en) konden niet worden toegevoegd, probeer het opnieuw', 'error'); } }); } else { swal('Mislukt', 'Geef maximaal 10 lege rijen per keer op.', 'error'); } } else { swal('Mislukt', 'Geef een geldig aantal op.', 'error'); } }) } });