app.controller('FlightsCtrl', function($scope, $http, $location) { $scope.flight = []; $scope.airport_tax = []; $scope.allotmentOverview = null; $scope.flightOverview = { name: 'Vluchten', controller: 'flight', function: 'getForOverview', //Panel class panelClass: 'panel-trainingskampen', showFilters: true, getCSV: true, pageLimit: 10, fields: [ 'id', 'carrier_id', 'flight_number', 'departure_date', 'arrival_date', 'from', 'to', 'number_of_passengers', 'quantity', 'luggage_price', 'allotment', 'number_of_uploads', 'updated_at', 'sent', ], //pair the organizations table subQueries: { carrier: { lfield: 'carrier_id', ffield: 'id', controller: 'carrier', }, from_airport: { lfield: 'from', ffield: 'iata', controller: 'airport', function: 'getForSelect', }, to_airport: { lfield: 'to', ffield: 'iata', controller: 'airport', function: 'getForSelect', }, }, //get the name of organization fieldDetails: { id: { label: '#', hideEdit: true, }, carrier_id: { label: 'Maatschappij', changeTo: ['carrier.id', ' - ', 'carrier.name'], // autoChangeTo: , required: true, }, flight_number: { label: 'Vluchtnummer', required: true, }, from: { label: 'Van', required: true, type: 'combobox', changeTo: ['from_airport.iata', ' - ', 'from_airport.name'], }, to: { label: 'Naar', required: true, type: 'combobox', changeTo: ['to_airport.iata', ' - ', 'to_airport.name'], }, departure_date: { label: 'Vertrek', //hideList: true, required: true, }, arrival_date: { label: 'Aankomst', hideList: true, required: true, }, 'number_of_passengers': { 'label': 'Personen', 'hideEdit': true, }, 'quantity': { 'label': 'Ingekocht totaal', 'hideEdit': true, }, 'luggage_price': { 'label': 'Baggage prijs', }, 'allotment': { 'label': 'Ingekocht allotment', 'hideEdit': true, }, 'number_of_uploads': { 'label': 'Uploads', 'hideEdit': true, }, 'updated_at': { 'label': 'Laatste update', 'hideEdit': true, }, 'sent': { 'label': 'Verzonden', 'hideEdit': true, }, }, buttons: { 'C':{ 'id': 'c', 'name': 'Voeg vlucht toe' , 'confirmName': 'Insert', 'confirmClass': 'success', 'icon': 'fa-plus-square', 'header': true, 'action': 'create', }, 'putCSV':{ 'id': 'putCSV', 'name': 'Upload CSV data', 'confirmName': 'Upload data', 'confirmClass': 'success', 'icon': 'fa-table', 'header': true, 'inline': false, 'noFields': true, 'action': 'putCSV', }, 'R': { 'id': 'r', 'name': 'Bekijk vlucht', 'label': 'Bekijk', 'confirmName': 'View', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-arrow-right', 'action': 'toFlight', 'parentScope': true, }, 'U':{ 'id': 'u', 'name': 'Bewerk', 'label': 'Bewerk', 'confirmName': 'Update', 'confirmClass': 'success', 'inline':true, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder vlucht', 'label': 'Verwijder', 'confirmName': 'Verwijder', 'cancelName': 'Annuleer', 'confirmClass': 'success', 'icon': 'fa-trash', 'header': false, 'inline': true, 'action': 'delete', }, 'v':{ 'id': 'v', 'name': 'Overzicht inkoop vluchten', 'label': 'Overzicht inkoop vluchten', 'icon': 'fa-table', 'header': false, 'inline': true, 'parentScope': true, 'action': 'viewAllotments', }, } } //translate table $scope.tableReady = function (tableName) { if (tableName === 'Vluchten') { $scope.flightOverview.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...', }; } if(tableName == "Inkoop vluchten"){ $scope.allotmentOverview.fieldDetails.airport_tax.class = ['button-disabled']; $scope.allotmentOverview.fieldDetails.total.class = ['button-disabled']; } } $scope.toFlight = function(btn, row, blnSubmit) { $location.url('/page/flight/' + row['id']); } $scope.sbaCrudTableChange = function(tableName, fieldName, fieldValue, eventType){ if(tableName == "Inkoop vluchten"){ $scope.allotmentOverview.modal.data.airport_tax = 0; if ($scope.allotmentOverview.modal.data.is_airport_tax) { $scope.allotmentOverview.modal.data.airport_tax = $scope.airport_tax.amount; } let totalPrice = ($scope.allotmentOverview.modal.data.ticket_price ? $scope.allotmentOverview.modal.data.ticket_price : 0) + $scope.allotmentOverview.modal.data.airport_tax; $scope.allotmentOverview.modal.data.total = Math.round(totalPrice * 100) / 100; } } $scope.modalReady = function(tableName, row) { $scope.allotmentOverview.modal.data.airport_tax = 0; if ($scope.allotmentOverview.modal.data.is_airport_tax) { $scope.allotmentOverview.modal.data.airport_tax = $scope.airport_tax.amount; } let totalPrice = ($scope.allotmentOverview.modal.data.ticket_price ? $scope.allotmentOverview.modal.data.ticket_price : 0) + $scope.allotmentOverview.modal.data.airport_tax; $scope.allotmentOverview.modal.data.total = Math.round(totalPrice * 100) / 100; } $scope.viewAllotments = function(btn, row, blnSubmit) { $scope.flight = row; $("#participantConfirmationModal").modal('toggle'); $scope.allotmentOverview = { name: 'Inkoop vluchten', controller: 'flight_allotment', function: 'getbyflightid/' + row.id, //Panel class panelClass: 'panel-trainingskampen', getCSV: true, pageLimit: 10, fields: [ 'flight_id', 'ticket_price', 'user_id', 'is_airport_tax', 'airport_tax', 'total', 'quantity', 'is_allotment', 'created_at', ], //pair the organizations table subQueries: { 'user': { 'lfield': 'user_id', 'ffield': 'id', 'controller': 'user', } }, //get the name of organization fieldDetails: { 'flight_id': { 'label': 'Flight_id', 'hideEdit': true, 'hideList': true, 'type': 'string', 'default': row.id, }, 'ticket_price': { 'label': 'Ticket prijs', 'required': true, 'currency': '€' }, 'user_id': { 'label': 'Gebruiker', 'hideEdit': true, 'changeTo': ['user.name'], }, 'quantity': { 'label': 'Hoeveelheid', 'required': true, }, 'created_at': { 'label': 'Gemaakt op', 'required': false, 'hideEdit': true, }, 'is_allotment': { 'label': 'Allotment?', 'hideEdit': false, 'hideList': true, 'default': true, }, 'is_airport_tax': { 'label': 'Luchthavenbelasting toepassen', 'hideEdit': false, 'hideList': true, 'default': true, }, 'airport_tax': { 'label': 'Luchthavenbelasting', 'hideEdit': false, 'hideList': true, }, 'total': { 'label': 'Totaal', 'disabled' : true, 'type' : 'number', 'hideList': true, 'required': false, }, }, buttons: { 'C':{ 'id': 'c', 'name': 'Voeg inkoopvlucht toe' , 'confirmName': 'Insert', 'confirmClass': 'success', 'icon': 'fa-plus-square', 'header': true, 'action': 'create', }, 'R': { 'id': 'r', 'name': 'Bekijk inkoopvlucht', 'label': 'Bekijk', 'confirmName': 'View', 'confirmClass': 'info', 'inline': true, 'header': false, 'action': 'read', 'icon': 'fa-arrow-right', }, 'U':{ 'id': 'u', 'name': 'Bewerk', 'label': 'Bewerk', 'confirmName': 'Update', 'confirmClass': 'success', 'inline':true, 'icon':'fa-pencil', 'action': 'update', }, 'D':{ 'id': 'd', 'name': 'Verwijder inkoopvlucht', 'label': 'Verwijder', 'confirmName': 'Verwijder', 'cancelName': 'Annuleer', 'confirmClass': 'success', 'icon': 'fa-trash', 'header': false, 'inline': true, 'action': 'delete', }, } } //retrieve airport_tax for this flight let req = { method: 'GET', url: '/flight/getAirportTax/' + row.id, } $http(req).then(function(response) { if(response.status && response.data.status){ $scope.airport_tax = response.data.data; } }); } });