app.controller('BackOfficeCtrl', function($scope, $http, $location, Upload) { //set params $scope.selectedInvoiceId = null; $scope.selectedInvoice = {}; $scope.flightChanges = { name: 'Vluchtwijzigingen', controller: 'scenario', function: 'getForFlightChanges', //Panel class panelClass: 'panel-trainingskampen', showFilters: false, showRowCount: true, getCSV: true, getCSVurl: 'scenario/getBackofficeCSV', pageLimit: 10, style: { row: { 'row-hide-button': { 'airline_id': '==1', }, }, }, fields: [ 'id', 'camp_name', 'club', 'passenger', 'airline_id', 'airline', 'flight_date', 'flight_number', 'scenario_flight_passenger_id', 'processed_to_airline', ], fieldDetails: { 'id': { 'hideList': true, }, 'camp_name':{ 'label': 'Kampnaam' }, 'club':{ 'label': 'Team' }, 'airline_id':{ 'hideList': true }, 'airline':{ 'label': 'Airline' }, 'flight_date':{ 'label': 'Vertrekdatum' }, 'flight_number':{ 'label': 'Vluchtnr' }, 'passenger':{ 'label': 'Naam' }, 'processed_to_airline': { 'hideList': true }, 'scenario_flight_passenger_id': { 'hideList': true }, }, buttons:{ 'C': { 'id': 'c', 'header': false }, 'R': { 'id': 'r', 'inline': false }, 'U': { 'id': 'u', 'inline': false }, 'D': { 'id': 'd', 'inline':false }, 'PTA': { 'id': 'pta', //process to airline 'icon': 'fa-close', 'label': 'Nog te verwerken', 'inline': true, 'where': {'==' : '0'}, 'whereField': 'processed_to_airline', 'action': 'processedToAirline', 'parentScope': true, }, 'PTAD': { 'id': 'ptad', //processed to airline 'icon': 'fa-check', 'label': 'Verwerkt', 'inline': true, 'where': {'==' : '1'}, 'whereField': 'processed_to_airline', 'action': 'processedToAirline', 'parentScope': true, }, 'TS':{ 'id': 'ts', 'name': 'Naar Draaiboek' , 'label': 'Naar Draaiboek', 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline':true, 'icon':'fa-arrow-right', 'action': 'goToScenario', 'parentScope': true, } } } //transavia tab, facturen $scope.transaviaInvoices = { name: 'Facturen', controller: 'transavia_invoice', //function: '', //Panel class panelClass: 'panel-trainingskampen', showRowCount: true, pageLimit: 25, autoChangeTo: ['transavia_invoice_status_id'], fields: [ 'date', 'number', 'type', 'transavia_invoice_status_id', 'created_at', 'allow_excel_upload', ], fieldDetails: { 'date': { 'label': 'Factuurdatum' }, 'number': { 'label': 'Factuurnummer' }, 'type': { 'label': 'Type' }, 'transavia_invoice_status_id': { 'label': 'Status' }, 'created_at': { 'label': 'Upload datum/tijd', 'sortAsc': false, }, 'allow_excel_upload': { 'hideList': true, 'hideEdit': true, }, }, buttons:{ 'C': { 'id': 'c', 'header': true, 'name': 'Upload factuur' , 'label': 'Upload', 'cancelName': 'Annuleren', 'confirmName': 'Bevestigen', 'confirmClass': 'success', 'icon':'fa-upload', 'action': 'uploadInvoice', 'parentScope': true, }, 'R': { 'id': 'r', 'inline': false }, 'U': { 'id': 'u', 'inline': false }, 'D': { 'id': 'd', 'inline': true, 'name': 'Verwijder factuur' , 'label': 'Verwijder factuur', 'cancelName': 'Annuleren', 'confirmName': 'Bevestigen', 'confirmClass': 'success', 'icon':'fa-trash', 'action': 'delete', 'whereField': 'transavia_invoice_status_id', 'where': { '!=': 3, } }, 'UE':{ 'id': 'ue', 'inline': false, 'name': 'Upload Excel' , 'label': 'Upload excel', 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline':true, 'icon':'fa-upload', 'action': 'uploadSepcificationInvoice', 'parentScope': true, 'whereField': 'allow_excel_upload', 'where': { '==': true, } }, 'TIL':{ 'id': 'til', 'inline': false, 'name': 'To Invoice Lines' , 'label': 'Factuur Regels', 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline':true, 'icon':'fa-eye', 'action': 'showInvoiceLines', 'parentScope': true, }, 'TE':{ 'id': 'te', 'inline': false, 'name': 'To Exact' , 'label': 'Verstuur naar exact', 'confirmClass': 'success', 'inline':true, 'icon':'fa-arrow-right', 'action': 'sendToExact', 'parentScope': true, 'whereField': 'transavia_invoice_status_id', 'where': { '==': 2, } } } } //transavia tab, factuur regels, modal $scope.invoiceLinesPerInvoice = { name: 'Inkoopregels', controller: 'transavia_invoice_line', function: 'getByInvoice/0', //Panel class panelClass: 'panel-trainingskampen', showFilters: true, showRowCount: false, pageLimit: 10, showStatistics: true, fields: [ 'id', 'original_transavia_invoice_line_id', 'scenario_id', 'invoice_id', 'type', 'flight_number', 'flight_date', 'from_destination', 'to_destination', 'contract', 'quantity', 'unit_price', 'total_price', 'sales_price', 'total_sales_price', 'cost_center', 'cost_unit', 'gl_account', ], fieldDetails: { 'id': { 'label': 'ID', 'hideEdit': true, }, 'original_transavia_invoice_line_id':{ 'label': 'Org row', 'hideEdit': true, }, 'scenario_id':{ 'label': 'Draaiboek Nr.', 'hideEdit': true, }, 'invoice_id':{ 'hideList': true, 'hideEdit': true, 'default': $scope.selectedInvoice.id, }, 'type':{ 'label': 'Soort', 'hideEdit': true, }, 'flight_number':{ 'label': 'Vlucht nr.', 'hideEdit': true, }, 'flight_date':{ 'label': 'Vertrekdatum', 'type': 'date', }, 'from_destination':{ 'label': 'Startpunt', }, 'to_destination':{ 'label': 'Eindpunt', }, 'contract':{ 'label': 'Contract', }, 'quantity':{ 'label': 'Aantal' }, 'unit_price': { 'label': 'Prijs', 'type': 'number', 'currency': '€', }, 'total_price': { 'label': 'Totaal prijs', 'type': 'number', 'hideEdit': true, 'currency': '€', }, 'sales_price': { 'label': 'Verkoopprijs', 'type': 'number', 'currency': '€', }, 'total_sales_price': { 'label': 'Totaal verkoopprijs', 'type': 'number', 'hideEdit': true, 'currency': '€', }, 'cost_center': { 'label': 'Kostenplaats', }, 'cost_unit': { 'label': 'Kostendrager', 'type': 'enum', 'options': [{ id: 'B', // name: 'B - Nederland, België en Duitsland', name: 'B', },{ id: 'C', // name: 'C - Gran Canaria, Zwitserland en buiten Europa', name: 'C', },{ id: 'R', // name: 'R - Spanje, Portugal en overige Europese landen', name: 'R', },{ id: 'G', // Emboost name: 'G', }], }, 'gl_account': { 'label': 'Grootboek', 'type': 'enum', 'options': [{ id: '7000', // name: '7000 - Nederland, België en Duitsland', name: '7000', },{ id: '7100', // name: '7100 - Alleen vliegtickets', name: '7100', },{ id: '7200', // name: '7200 - Spanje, Portugal en overige Europese landen', name: '7200', },{ id: '7300', // name: '7300 - Canarische eilanden, Zwitserland en buiten Europa', name: '7300', },{ id: '7500', // Emboost name: '7500', }], }, }, buttons:{ 'C':{ 'id': 'c', 'name': 'Nieuwe factuurregel', 'confirmName': 'Insert', 'confirmClass': 'success', 'icon': 'fa-plus-square', 'header': true, 'action': 'create', }, 'R':{ 'id': 'r', 'name': 'Bekijk', 'label': 'Bekijk', 'confirmName': 'View', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-search', 'action': 'read', }, 'U':{ 'id': 'u', 'name': 'Bewerk', 'label': 'Bewerk', 'confirmName': 'Update', 'confirmClass': 'success', 'inline':true, 'icon':'fa-pencil', 'action': 'update', }, 'SP':{ 'id': 'sp', 'name': 'Splits', 'label': 'Splits', 'confirmName': 'Update', 'confirmClass': 'success', 'inline':true, 'icon':'fa-clone', 'action': 'splitRow', 'parentScope': true, }, 'D': { 'id': 'd', 'name': 'Verwijder', 'label': 'Verwijder', 'confirmName': 'Verwijder', 'confirmClass': 'success', 'inline':true, 'icon':'fa-trash', 'action': 'delete', 'inline':true }, } } $scope.getFormattedDate = function(date) { let formattedDate = new Date(date); return formattedDate.getDate() + '-' + (formattedDate.getMonth() + 1) + '-' + formattedDate.getFullYear(); } $scope.splitRow = function(btn, row) { let newRow = JSON.parse(JSON.stringify(row)); delete newRow.id; if (Math.abs(newRow.quantity) <= 1) { swal("Helaas!", "Het aantal is 1 of lager, hierdoor kan je de regel niet splitsen", "warning"); return; } //set split id in newRow newRow.id_from_split = row.id; //check for date and set in correct format if (newRow.flight_date != undefined) { newRow.flight_date = new Date(newRow.flight_date); } $scope.invoiceLinesPerInvoice.toggleButton(this.invoiceLinesPerInvoice.buttons['C'], newRow, false) } $scope.uploadInvoice = function() { $scope.selectedInvoiceId = null; $('#invoiceModal').modal('show'); } $scope.uploadSepcificationInvoice = function(btn, row) { $scope.selectedInvoiceId = row.id; $('#invoiceModal').modal('show'); } //predefined filter, lars $scope.showInvoiceLines = function(btn, row) { $scope.selectedInvoice = row; $scope.invoiceLinesPerInvoice.function = "getbyinvoice/" + row.id; $scope.invoiceLinesPerInvoice.call('initiate'); $('#showInvoiceLinesModal').modal('show'); } //predefined filter, lars $scope.sendToExact = function(btn, row) { //count total amount of all rows let currentInvoiceAmount = 0; if ($scope.invoiceLinesPerInvoice.data != undefined && $scope.invoiceLinesPerInvoice.data.rows != undefined && Array.isArray($scope.invoiceLinesPerInvoice.data.rows)) { $scope.invoiceLinesPerInvoice.data.rows.forEach(invoiceLine => { if (invoiceLine['total_price'] != undefined) { currentInvoiceAmount = currentInvoiceAmount + parseFloat(invoiceLine['total_price']); } }); } //check for amount swal({ title: "Weet je het zeker?", text: ($scope.selectedInvoice.total_amount != undefined && $scope.selectedInvoice.total_amount > currentInvoiceAmount ? ' Het bedrag van de orginele factuur is namelijk hoger dan het bedrag van de huidige factuur regels.': 'Weet je zeker dat je de factuur wil versturen naar exact?'), icon: "warning", buttons: { cancel: "Nee", confirm: "Ja" }, dangerMode: false, }).then((willSend) => { if (willSend) { var loader = document.createElement("i"); loader.classList.add("fa"); loader.classList.add("fa-spinner"); loader.classList.add("fa-5x"); loader.classList.add("fa-spin"); //show loading swal({ title: "Loading", content: loader, buttons: false, }); $('#showInvoiceLinesModal').modal('hide'); //send to exact var req = { method: 'GET', url: '/invoice/sendToExact/' + row.id } $http(req).then(function(response) { swal.close(); if (response.status && response.data.status) { swal("Gelukt!", "De factuur is verzonden naar exact.", "success"); $scope.transaviaInvoices.call('initiate'); } else { swal("Mislukt!", response.data.message, "error"); } }); } }); } $scope.modalClose = function(table) { if (table == "Inkoopregels") { $scope.invoiceLinesPerInvoice.call('initiate'); } } //upload invoice function $scope.uploadFiles = function(file) { $scope.fileInfo = { file: file } if ($scope.fileInfo.file) { $scope.fileInfo.loading = true; Upload.upload({ url: '/transavia_invoice/upload/' + $scope.selectedInvoiceId, data: { 'file': $scope.fileInfo.file, }, }).then(function (response) { if (response.status && response.data.status) { var loader = document.createElement("i"); loader.classList.add("fa"); loader.classList.add("fa-spinner"); loader.classList.add("fa-5x"); loader.classList.add("fa-spin"); //show loading swal({ title: "Loading", content: loader, buttons: false, }); $('#invoiceModal').modal('hide'); // return message to user swal( "Gelukt!", "De upload is successvol. Het document zal spoedig verwerkt worden.", "success" ); } else { swal("Helaas!", response.data.message, "error"); } $scope.files.call('initiate'); }, 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.processedToAirline = function(btn, row) { if (row.airline_id != 1) { if (row.processed_to_airline == 1) { row.processed_to_airline = 0; } else { row.processed_to_airline = 1; } var req = { method: 'POST', url: '/scenario_flight_passenger/update/' + row.scenario_flight_passenger_id, data: {processed_to_airline: row.processed_to_airline} } $http(req).then(function(response) { if (response.status && response.data.status) { } }); } } $scope.commingScenarios = { name: 'Komende trainingskampen', controller: 'scenario', function: 'getForBackOffice', //Panel class panelClass: 'panel-trainingskampen', showFilters: false, showRowCount: true, getCSV: true, getCSVurl: 'scenario/getBackofficeCSV/upcomming_scenarios', pageLimit: 10, fields: [ 'id', 'camp_name', 'club', 'attendees', 'last_change' ], fieldDetails: { 'id': { 'hideList': true, }, 'camp_name': { 'label': 'Kampnaam' }, 'club': { 'label': 'Team' }, 'attendees': { 'label': 'Deelnemers' }, 'last_change': { 'label': 'Laatste wijziging', } }, buttons:{ 'C': { 'id': 'c', 'header': false }, 'R': { 'id': 'r', 'inline': false }, 'U': { 'id': 'u', 'inline': false }, 'D': { 'id': 'd', 'inline':false }, 'TS':{ 'id': 'ts', 'name': 'Naar Draaiboek' , 'label': 'Naar Draaiboek', 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline':true, 'icon':'fa-arrow-right', 'action': 'goToScenario', 'parentScope': true, } } } $scope.goToScenario = function(btn, row) { $location.url('/page/draaiboek/' + row.id); } $scope.accessScenario = function(btn, row) { $location.url('/page/draaiboek/' + row.scenario_id); } function getAirport() { var req = { method: 'GET', url: '/airport/get/' } $http(req).then(function(response) { if (response.status && response.data.status) { $scope.airports = response.data.data; } }); } getAirport(); $scope.generateFlightList = function() { if ($scope.filter && $scope.filter.date && $scope.filter.airport) { let date = ''; if ($scope.filter.date) { date = $scope.convertDateObjToJS($scope.filter.date, 'date'); var req = { method: 'GET', url: '/airport/generateFlightList/check?airport=' + $scope.filter.airport + '&date=' + date } $http(req).then(function(response) { if (response.status && response.data.status) { window.open('/airport/generateFlightList/Vluchtlijst?airport=' + $scope.filter.airport + '&date=' + date, '_blank'); } else { swal('Mislukt', 'Geen vluchten gevonden voor deze luchthaven (' + $scope.filter.airport + ') op de geselecteerde datum (' + date + ')', 'error'); } }); } } }; $scope.convertDateObjToJS = function(objDate, type) { if (!objDate) { return objDate; } if (typeof objDate === 'string') { return objDate; } switch(type){ case 'date': if(typeof objDate.getFullYear !== 'function'){ return null; } return ([objDate.getFullYear(), objDate.getMonth()+1, objDate.getDate()].join('-')); break; case 'time': if(typeof objDate.getHours !== 'function'){ return null; } return ([('00' + objDate.getHours()).slice(-2), ('00' + objDate.getMinutes()).slice(-2)].join(':')); break; case 'datetime': if(typeof objDate.getFullYear !== 'function'){ return null; } return ([objDate.getFullYear(), objDate.getMonth()+1, objDate.getDate()].join('-')+' '+[('00' + objDate.getHours()).slice(-2), ('00' + objDate.getMinutes()).slice(-2)].join(':')); break; default: return objDate; break; } } });