app.controller('DashboardCtrl', function($scope, $http, $filter, $location, $rootScope, $routeParams, $window) { $scope.selectedNote = { responsible: $scope.user.id, date: new Date(), }; $scope.employees = []; //Laatst gewijzigde trainingskampen $scope.changedTrainingsCamps = { name: 'Laatst gewijzigde trainingskampen', controller: 'scenario', function: 'getForDashboard', //Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 50, fields: [ 'name', 'customer_id', 'logs', 'updated_at', ], //pair the customer table subQueries: { 'customer': { 'lfield': 'customer_id', 'ffield': 'id', 'controller': 'customer', 'function': 'getForOverview', }, }, fieldDetails: { 'name': { 'label': 'Trainingskamp', }, 'logs': { 'label': 'Verandering', 'where': '!= true', }, 'customer_id': { 'label': 'Klant', 'changeTo': ['customer.company_name'], }, 'updated_at': { 'label': 'Datum/tijd', 'hideEdit': true, 'sortAsc': false, }, }, buttons: { 'C':{ 'id': 'c', 'header': false, 'inline': false, }, 'R': { 'id': 'r', 'name': 'Bekijk traingskamp', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-arrow-right', 'action': 'toScenario', 'parentScope': true, 'whereField': 'scenario_status_id', 'where': { '!=': '1', }, }, 'U':{ 'id': 'u', 'header': false, 'inline': false, }, 'D':{ 'id': 'd', 'header': false, 'inline': false, }, } } //Quotations $scope.quotations = { name: 'Offertes', controller: 'quotation', function: 'getForOverview', //Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 5, fields: [ 'quotation_number', 'managing_user_id', 'customer_id', 'expire_date', 'status', 'amount', ], style:{ row:{ 'danger':{ 'row': '==danger', }, 'warning':{ 'row': '==warning', }, }, }, //pair the organizations table subQueries: { 'managing_user': { 'lfield': 'managing_user_id', 'ffield': 'id', 'controller': 'user', }, 'customer': { 'lfield': 'customer_id', 'ffield': 'id', 'controller': 'customer', }, 'payment_status': { 'lfield': 'payment_status_id', 'ffield': 'id', 'controller': 'payment_status', }, }, //get the name of organization fieldDetails: { 'quotation_number': { 'label': 'Offerte nummer', 'type': 'number', }, 'managing_user_id': { 'label': 'TK manager', 'changeTo': ['managing_user.name'], }, 'customer_id': { 'label': 'Klant', 'changeTo': ['customer.company_name'], }, 'expire_date': { 'label': 'Verval datum', }, 'status': { 'label': 'Status', }, 'amount': { 'label': 'Bedrag', 'type': 'number', }, 'payment_status_id': { 'label': 'Betaal status', 'changeTo': ['payment_status.name'], }, }, buttons: { 'C':{ 'id': 'c', 'name': 'Offerte aanmaken', 'label': 'Offerte aanmaken', 'cancelName': 'Annuleren', 'confirmName': 'maak aan', 'confirmClass': 'success', 'icon': 'fa-plus-square', 'header': true, 'action': 'toWizard', 'parentScope': true, }, 'R': { 'id': 'r', 'name': 'Bekijk offerte', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-arrow-right', 'action': 'toQuotation', 'parentScope': true, }, 'U':{ 'id': 'u', 'header': false, 'inline': false, }, 'D':{ 'id': 'd', 'header': false, 'inline': false, }, } } // Agenda item that need follow up $scope.personalContactOverview = { name: 'Agendering met opvolging', controller: 'customer_note', function: 'getForDashboard', // Panel class panelClass: 'panel-trainingskampen', pageLimit: 5, autoChangeTo: ['user_id', 'customer_id'], fields: [ 'id', 'v_follow_up_date', // follow up date for view 'customer_id', 'subject', 'date', 'user_id', 'follow_up', 'follow_up_date', // follow up date for edit 'finished', 'note', 'show', 'files', 'send_agenda_item', 'time', 'duration', ], style:{ row:{ 'danger':{ 'v_status': '==danger', }, 'warning':{ 'v_status': '==warning', }, 'success':{ 'v_status': '==success', }, }, }, predefinedFilters: { user_id: $scope.user.name, finished: "false", }, fieldDetails: { files: { type: 'file', label: 'Bestanden', dropzoneDescription: 'Sleep of klik om een bestand toe te voegen!', uploadFileUrl: 'customer_note/upload/' + 0, fetchFileUrl: 'customer_note/fetch/' + 0, hideList: true, }, id: { hideList: false, hideEdit: true, label: '#', }, show: { label: 'Tonen', hideList: true, hideEdit: true, }, customer_id: { hideEdit: false, required: true, label: 'Klant', changeTo: ['customer.id', ' - ', 'customer.club_name'], }, subject: { label: 'Onderwerp', required: true, }, user_id: { label: 'Verantwoordelijke', default: $scope.user.id, }, follow_up: { label: 'Taak opvolgen', hideList: true, default: true, type: "boolean", booleanOn:"1", booleanOff:"0", }, v_follow_up_date: { label: 'Opvolg datum', hideEdit: true, sortAsc: true, }, follow_up_date: { label: 'Opvolg datum', sortAsc: true, hideList: true, hideEdit: false, required: true, }, finished: { label: 'Afgerond', hideList: true, type: "boolean", booleanOn:"1", booleanOff:"0", }, note: { label: 'Beschrijving', hideList: true, }, date: { label: 'Datum', hideList: true, required: true, default: new Date(), }, send_agenda_item: { label: 'Stuur herinneringsmail naar verantwoordelijke', type: 'boolean', booleanOn: '1', booleanOff: '0', hideList: true, }, time: { label: 'Tijd', hideList: true, hideEdit: true, required: true, }, duration: { label: 'Duur', hideList: true, hideEdit: true, required: true, }, }, buttons: { 'C':{ 'id': 'c', 'name': 'Agenda notitie toevoegen', 'label': 'Agenda notitie toevoegen', 'cancelName': 'Annuleren', 'confirmName': 'Toevoegen', 'confirmClass': 'success', 'icon':'fa-plus-square', 'header': true, 'inline': false, 'action': 'create', }, 'R':{ 'id': 'r', 'inline': true, 'cancelName': 'Sluiten', 'name': 'Bekijk', 'label': 'Bekijk', 'icon':'fa-search', 'action': 'read', }, 'U': { 'id': 'u', 'name': 'Bewerk', 'label': 'Bewerk', 'cancelName': 'Annuleren', 'confirmName': 'Wijzig', 'confirmClass': 'success', 'inline':true, 'icon':'fa-pencil', 'action': 'update', }, 'D': { 'id': 'd', 'inline': false, }, 'T': { 'id': 'taken', 'name': 'Taken', 'label': 'Laat alle taken zien', 'header': true, 'action': 'goToAgendaRing', 'parentScope': true, } } } $scope.goToAgendaRing = function(btn, row, blnSubmit) { $location.url('/page/taken/'); } // change field details on changes $scope.sbaCrudTableChange = function(tableName, fieldName, fieldValue, eventType){ switch (fieldName) { case 'follow_up': fieldSearch = $filter('filter')($scope.personalContactOverview.modal.fields, { 'name': 'follow_up_date' }); if (fieldValue) { //hide follow up date $scope.personalContactOverview.fieldDetails['follow_up_date'].hideEdit = false; if (fieldSearch[1] !== undefined) { fieldSearch[1]['required'] = true; } } else { //show follow up date $scope.personalContactOverview.fieldDetails['follow_up_date'].hideEdit = true; if (fieldSearch[1] !== undefined) { fieldSearch[1]['required'] = false; } } break; case 'send_agenda_item': if (fieldValue === true) { $scope.personalContactOverview.fieldDetails['time']['hideEdit'] = false; $scope.personalContactOverview.fieldDetails['duration']['hideEdit'] = false; } else if (fieldValue === false) { $scope.personalContactOverview.fieldDetails['time']['hideEdit'] = true; $scope.personalContactOverview.fieldDetails['duration']['hideEdit'] = true; } break; } } //parent function $scope.modalReady = function(tableName) { switch (tableName) { case $scope.personalContactOverview.name: let followUpValue = $scope.personalContactOverview.modal.data.follow_up !== undefined ? $scope.personalContactOverview.modal.data.follow_up : true; let sendAgendaValue = $scope.personalContactOverview.modal.data.send_agenda_item !== undefined ? $scope.personalContactOverview.modal.data.send_agenda_item : true; $scope.sbaCrudTableChange(tableName, 'follow_up', followUpValue, 'CHANGE'); $scope.sbaCrudTableChange(tableName, 'send_agenda_item', sendAgendaValue, 'CHANGE'); break; } } $scope.getEmployeesForAgenda = function() { var req = { method: 'GET', url: '/customer/getEmployeesForAgenda', } $http(req).then(function(response) { if (response.status && response.data.status) { $scope.employees = response.data.data; } }); } $scope.undoData = function(){ if ($scope.selectedNote['original_responsible'] !== undefined) { $scope.selectedNote['responsible'] = $scope.selectedNote['responsible_name']; } } $scope.convertDateObjToJS = function(objDate, reverse, type) { if (!objDate) { return objDate; } if(!reverse){ if (typeof objDate == 'object') { return objDate; } tempTime = objDate.split(/[- :T.]/); switch(type){ case 'date': tempNewTime = new Date(tempTime[0], tempTime[1]-1, tempTime[2], 0, 0, 0); break; case 'time': if(!tempTime[2]){ tempTime[2] = 0; } tempNewTime = new Date(0 ,0, 0, tempTime[0], tempTime[1], 0); break; case 'datetime': if (tempTime[5]) { sec = tempTime[5]; } else { sec = 0; } tempNewTime = new Date(tempTime[0], tempTime[1]-1, tempTime[2], tempTime[3], tempTime[4], sec); break; } return tempNewTime; }else{ 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; } } } $scope.toQuotation = function(btn, row, blnSubmit) { $location.url('/page/wizard/' + row['hash']); } $scope.init = function () { // load employees for agenda item add $scope.getEmployeesForAgenda(); } //Invoices $scope.invoices = { name: 'Openstaande facturen', controller: 'invoice', function: 'getForDashboard', //Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 5, fields: [ 'invoice_number', 'scenario_name', 'customer_name', 'date', 'amount', 'status_name', ], fieldDetails: { 'invoice_number': { 'label': 'Factuur nummer', 'type': 'number', }, 'scenario_name': { 'label': 'Traingingskamp', }, 'customer_name': { 'label': 'Klant', }, 'scenario_id': { 'label': 'Traingingskamp', }, 'date': { 'label': 'Datum', }, 'status': { 'label': 'Status', }, 'amount': { 'label': 'Bedrag', 'type': 'number', }, 'status_name': { 'label': 'Status', }, }, buttons: { 'C':{ 'id': 'c', 'header': false, 'inline': false, }, 'R': { 'id': 'r', 'name': 'Bekijk factuur', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-arrow-right', 'action': 'toInvoice', 'parentScope': true, }, 'U':{ 'id': 'u', 'header': false, 'inline': false, }, 'D':{ 'id': 'd', 'header': false, 'inline': false, }, } } /* //EIGEN VEANTWOODELIJKE TRAINGSKAMPEN $scope.trainingsCampsPerTKManager = { name: 'Mijn trainingskampen', controller: 'scenario', function: 'getForOverview', //Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 5, fields: [ 'name', 'customer_id', 'managing_user_id', 'managing_user_name', 'place', 'from', 'to', 'status_name', ], //pair the customer table subQueries: { 'customer': { 'lfield': 'customer_id', 'ffield': 'id', 'controller': 'customer', }, }, fieldDetails: { 'name': { 'label': 'Trainingskamp', }, 'managing_user_name': { 'label': 'TK manager', }, 'managing_user_id': { 'label': 'TK manager id', 'hideList': true, 'hideEdit': true, 'where': { '==': $rootScope.user.id ? $rootScope.user.id : 0, }, }, 'customer_id': { 'label': 'Klant', 'changeTo': ['customer.company_name'], }, 'place': { 'label': 'Plaats', }, 'from': { 'label': 'Van datum', }, 'to': { 'label': 'Tot datum', }, 'status_name': { 'label': 'Status', }, }, buttons: { 'C':{ 'id': 'c', 'header': false, 'inline': false, }, 'R': { 'id': 'r', 'name': 'Bekijk traingskamp', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-arrow-right', 'action': 'toScenario', 'parentScope': true, }, 'U':{ 'id': 'u', 'header': false, 'inline': false, }, 'D':{ 'id': 'd', 'header': false, 'inline': false, }, } } */ //Customer $scope.activeTrainingsCamps = { name: 'Mijn trainingskampen', controller: 'scenario', function: 'getForOverview', //Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 5, fields: [ 'name', 'customer_id', 'from', 'to', 'country', 'managing_user', 'status', ], //pair the customer table subQueries: { 'customer': { 'lfield': 'customer_id', 'ffield': 'id', 'controller': 'customer', }, }, fieldDetails: { 'name': { 'label': 'Trainingskamp', }, 'managing_user': { 'label': 'TK manager', }, 'from': { 'label': 'Vanaf datum', }, 'to': { 'label': 'Tot datum', }, 'country': { 'label': 'Plaats', }, 'status': { 'label': 'Status', }, 'customer_id': { 'label': 'Klant', 'hideList': true, 'hideEdit': true, }, }, buttons: { 'C':{ 'id': 'c', 'header': false, 'inline': false, }, 'R': { 'id': 'r', 'name': 'Bekijk traingskamp', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-arrow-right', 'action': 'toScenario', 'parentScope': true, }, 'U':{ 'id': 'u', 'header': false, 'inline': false, }, 'D':{ 'id': 'd', 'header': false, 'inline': false, }, } } /* //INVOICES CUSTOMERS $scope.invoicesCustomer = { name: 'Openstaande facturen', controller: 'invoice', function: 'getforoverview', //Panel class panelClass: 'panel-trainingskampen', showFilters: true, pageLimit: 5, fields: [ 'invoice_number', 'scenario_name', 'customer_id', 'date', 'amount', ], //pair the organizations table subQueries: { }, //get the name of organization fieldDetails: { 'invoice_number': { 'label': 'Factuur nummer', }, 'scenario_name': { 'label': 'Trainingskamp', }, 'customer_id': { 'label': 'Klant', 'changeTo': ['customer.name'], 'hideList': true, 'HideEdit': true, 'where': { '==': $rootScope.user.organization.id ? $rootScope.user.organization.id : 0, }, }, 'date': { 'label': 'Datum', }, 'amount': { 'label': 'Bedrag', }, }, buttons: { 'C':{ 'id': 'c', 'header': false, 'inline': false, }, 'B': { 'id': 'b', 'name': 'Betaal nu', 'label': 'Betaal', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-credit-card', 'action': 'payNow', 'parentScope': true, }, 'R': { 'id': 'r', 'name': 'Bekijk factuur', 'label': 'Bekijk', 'cancelName': 'Annuleren', 'confirmName': 'Bekijk', 'confirmClass': 'info', 'inline': true, 'header': false, 'icon': 'fa-arrow-right', 'action': 'toInvoice', 'parentScope': true, }, 'U':{ 'id': 'u', 'header': false, 'inline': false, }, 'D':{ 'id': 'd', 'header': false, 'inline': false, }, } } */ $scope.tableReady = function (tableName) { if (tableName === 'Laatst gewijzigde trainingskampen' || tableName === 'Offertes' || tableName === 'Openstaande facturen' || tableName === 'Mijn trainingskampen') { var arrTables = ['changedTrainingsCamps', 'quotations', 'invoices', 'activeTrainingsCamps']; //set trainslation for each table angular.forEach(arrTables, function(table) { $scope[table].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...', }; }); }; switch (tableName) { case 'Agendering met opvolging': angular.forEach($scope.personalContactOverview.data.rows, function(row) { row.created_at = $scope.convertDateObjToJS(row.created_at, false, 'date') if (row.created_at !== undefined) { row.created_at = row.created_at.toLocaleDateString() } }) break; } } //ga naar draaiboek $scope.toScenario = function(btn, row, blnSubmit) { $location.url('/page/draaiboek/' + row['id']); } //bekijk factuur $scope.toInvoice = function(btn, row, blnSubmit) { var req = { method: 'POST', url: '/invoice/getPdfInvoice/' + row['id'], } $http(req).then(function(response) { 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', 'Controleer het factuur nummer', 'error'); }else{ swal('Mislukt', 'Probeer opnieuw', 'error'); } }); } //betaal nu functie $scope.payNow = function(btn, row, blnSubmit) { //$location.url('/page/camps/' + row['id']); } $scope.toWizard = function(btn, row, blnSubmit) { $location.url('/page/wizard'); } var checkIfpaymentSucceded = function () { if($routeParams['p'] !== undefined){ if($routeParams['p'].includes("true")){ swal('Succes', 'Bedankt voor je betaling', 'success').then((confirm) => { var req = { method: 'GET', url: '/user/logout', } //response $http(req) .then(function (response){ $scope.logout = response.data; //delete all data form user delete $scope.user; //send to login page $window.location.reload(); //give succes alert }); }); $location.url('/page/overzicht'); } } }; checkIfpaymentSucceded(); // Init $scope.init(); });