app.controller('CustomerCtrl', function($scope, $http, $filter, $location, $routeParams, $rootScope, Upload) {
// fetch the account details
$scope.showUncheckedItems = '1';
$scope.customer = {};
$scope.customerAccounts = [];
$scope.scenarios = [];
$scope.employees = [];
$scope.createButton = {'id': 'c', 'action': 'create', 'cancelName': 'Annuleren', 'confirmName': 'Toevoegen', 'confirmClass': 'success', 'name': 'Agenda notitie toevoegen','label': 'Agenda notitie toevoegen',};
$scope.selectedNote = {
responsible: $scope.user.id,
date: new Date(),
};
$scope.showAccountDetails = function(account) {
swal({
title: "Weet je het zeker?",
text: "Het wachtwoord zal definitief gereset worden.",
icon: "warning",
buttons: true,
})
.then((willReset) => {
if (willReset) {
var req = {
url: '/customer/resetAccount/' + $scope.customer.id + '/' + account.id,
method: 'GET',
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
swal('Gelukt!', "Het wachtwoord van de gebruiker is veranderd naar: \n" + response.data.data.password, 'success');
}
});
}
});
}
$scope.toggleAccountActive = function(account) {
swal({
title: "Weet je het zeker?",
text: "Het account zal op " + (account.active == 1 ? "inactief" : "actief") + " worden gezet",
icon: (account.active == 1 ? "warning" : "info"),
dangerMode: (account.active == 1 ? true : false),
buttons: true,
})
.then((willToggle) => {
if (willToggle) {
var req = {
url: '/customer/updateAccount/' + $scope.customer.id + '/' + account.id,
method: 'POST',
data: {
active: (account.active == 1 ? 0 : 1),
}
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
swal('Gelukt!', "Het account is " + (account.active == 1 ? "inactief" : "actief") + " gezet.", 'success');
$scope.fetchAccounts();
}
});
}
});
}
$scope.deleteAccount = function(account) {
swal({
title: "Weet je het zeker?",
text: "Het account zal definitief verwijderd worden.",
icon: "warning",
dangerMode: true,
buttons: true,
})
.then((willDelete) => {
if (willDelete) {
var req = {
url: '/customer/deleteAccount/' + $scope.customer.id + '/' + account.id,
method: 'GET',
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
swal('Gelukt!', "Het account is definitief verwijderd.", 'success');
var index = $scope.customerAccounts.indexOf(account);
$scope.customerAccounts.splice(index, 1);
}
});
}
});
}
$scope.fetchAccounts = function() {
var req = {
url: '/customer/getAccounts/' + $scope.customer.id,
method: 'GET',
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
$scope.customerAccounts = response.data.data;
}
});
}
$scope.fetchScenarios = function() {
var req = {
url: '/scenario/getforcustomer/' + $scope.customer.id,
method: 'GET',
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
$scope.scenarios = response.data.data;
}
});
}
$scope.createOptionsForRights = function(scenario_rights) {
var strScenarioOptions = '';
angular.forEach($scope.scenarios, function(scenario) {
if (scenario_rights && scenario_rights.scenarios) {
if (scenario_rights.scenarios.indexOf(scenario.id) == -1) {
strScenarioOptions = strScenarioOptions + '
' + scenario.id + ' - ' + scenario.name + ' - ' + scenario.from + '
'
} else {
strScenarioOptions = strScenarioOptions + ' ' + scenario.id + ' - ' + scenario.name + ' - ' + scenario.from + '
'
}
} else {
strScenarioOptions = strScenarioOptions + ' ' + scenario.id + ' - ' + scenario.name + ' - ' + scenario.from + '
'
}
});
/* if scenarioOptions is empty */
if (strScenarioOptions == '') {
strScenarioOptions = 'No scenarios';
}
return strScenarioOptions;
}
toggleDisplay = function(elementId) {
var element = document.getElementById(elementId);
if (element.style.display === "none") {
element.style.display = "block";
} else {
element.style.display = "none";
}
}
$scope.processScenarioRights = function(account) {
if (typeof account.scenario_rights === 'string') {
account.scenario_rights = JSON.parse(account.scenario_rights);
}
strScenarioRights = "";
if (account.scenario_rights.rights && account.scenario_rights.rights == 'specific') {
strScenarioRights = 'Specifieke draaiboeken';
} else {
strScenarioRights = 'Volledige rechten';
}
return strScenarioRights;
}
checkScenarioRights = function(strRadio, account) {
if (account && account.scenario_rights && account.scenario_rights.rights) {
if (strRadio == account.scenario_rights.rights) {
return 'checked';
} else {
return '';
}
} else if (strRadio == 'all') {
return 'checked';
}
return '';
}
checkScenarioRightsStyle = function(strRadio, account) {
if (account && account.scenario_rights && account.scenario_rights.rights) {
if (strRadio == account.scenario_rights.rights) {
return '';
} else {
return 'style="display:none"';
}
} else if (strRadio == 'all') {
return '';
}
return 'style="display:none"';
}
function getRadioValue(theRadioGroup) {
var elements = document.getElementsByName(theRadioGroup);
for (var i = 0, l = elements.length; i < l; i++)
{
if (elements[i].checked)
{
return elements[i].value;
}
}
}
$scope.changeScenarioRights = function(account) {
var span = document.createElement("span");
span.innerHTML = 'Naam '
+ 'Functie '
+ 'Emailadres '
+ 'Telefoonnummer '
+ ' Rechten '
+ 'Selecteer de draaiboeken voor toegang
'
+ $scope.createOptionsForRights(account.scenario_rights)
+ '
';
swal({
title: 'Update rechten klant account',
text: 'U wilt een account updaten van klant ' + $scope.customer.club_name,
type: 'warning',
content: span,
buttons: {
cancel: 'Annuleren',
confirm: {
text: 'Updaten',
closeModal: false,
},
},
}).then((isConfirm) => {
if (isConfirm) {
var name = document.getElementById('swal_customer_account_name').value;
var accountFunction = document.getElementById('swal_customer_account_function').value;
var emailaddress = document.getElementById('swal_customer_account_email').value;
var phone_internal = document.getElementById('swal_customer_account_phone_internal').value;
var rights = getRadioValue('rights');
/*
Specific rights
*/
var arrScenarios = [];
if (rights == 'specific') {
var checkboxes = document.querySelectorAll('input[name=chkboxScenario]:checked');
for (var i = 0; i < checkboxes.length; i++) {
arrScenarios.push(checkboxes[i].value);
}
}
var scenario_rights = {
'rights': rights,
'scenarios': arrScenarios,
};
if (!name || !emailaddress) {
swal('Naam en emailadres zijn verplicht!', '', 'error');
return false;
}
var req = {
url: '/customer/createAccount/' + $scope.customer.id,
method: 'POST',
data: {
name: name,
function: accountFunction,
emailaddress: emailaddress,
phone_internal: phone_internal,
scenario_rights: scenario_rights,
}
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
$scope.fetchAccounts();
// response message to email failed
let icon = 'success';
var span = document.createElement("span");
span.innerHTML = 'Het klant account is geupdate';
swal({
title: 'Gelukt!',
content: span,
icon: icon,
});
} else {
let message = 'Het aanmaken van het nieuwe klant account is niet gelukt, controleer het emailadres en probeer het opnieuw!';
if (response.data.message == 'messages.organization.failed') {
message = 'De klant heeft geen verzonden offertes, hierdoor kan een account voor deze klant niet worden aangemaakt';
}
swal('Mislukt!', message, 'error');
}
}, function(error) {
swal('Mislukt!', 'Het aanmaken van het nieuwe klant account is niet gelukt, controleer het emailadres en probeer het opnieuw!', 'error');
});
}
});
}
$scope.addCustomerAccount = function() {
var span = document.createElement("span");
span.innerHTML = 'Naam '
+ 'Functie '
+ 'Emailadres '
+ 'Telefoonnummer '
+ ' Rechten '
+ 'Selecteer de draaiboeken voor toegang
'
+ $scope.createOptionsForRights()
+ '
';
swal({
title: 'Aanmaken nieuw klant account',
text: 'U wilt een nieuw account aanmaken voor klant ' + $scope.customer.club_name + '.\nWat is de naam, functie, emailadres en het telefoonnummer van de nieuwe gebruiker?',
type: 'warning',
content: span,
buttons: {
cancel: 'Annuleren',
confirm: {
text: 'Aanmaken',
closeModal: false,
},
},
}).then((isConfirm) => {
if (isConfirm) {
var name = document.getElementById('swal_customer_account_name').value;
var accountFunction = document.getElementById('swal_customer_account_function').value;
var emailaddress = document.getElementById('swal_customer_account_email').value;
var phone_internal = document.getElementById('swal_customer_account_phone_internal').value;
var rights = getRadioValue('rights');
/*
Specific rights
*/
var arrScenarios = [];
if (rights == 'specific') {
var checkboxes = document.querySelectorAll('input[name=chkboxScenario]:checked');
for (var i = 0; i < checkboxes.length; i++) {
arrScenarios.push(checkboxes[i].value);
}
}
var scenario_rights = {
'rights': rights,
'scenarios': arrScenarios,
};
if (!name || !emailaddress) {
swal('Naam en emailadres zijn verplicht!', '', 'error');
return false;
}
var req = {
url: '/customer/createAccount/' + $scope.customer.id,
method: 'POST',
data: {
name: name,
function: accountFunction,
emailaddress: emailaddress,
phone_internal: phone_internal,
scenario_rights: scenario_rights,
}
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
$scope.customerAccounts.push(response.data.data);
// response message to email failed
let icon = 'success';
let emailMsg = 'Een email is verstuurd naar de klant met zijn/haar gegevens';
if (response.data.message == 'messages.email.failed') {
icon = 'warning';
emailMsg = 'Let op! De email met de gegevens van het account is helaas niet succesvol verzonden ';
}
var span = document.createElement("span");
span.innerHTML = 'Het nieuwe klant account is aangemaakt voor ' + emailaddress + '! ' + emailMsg + ' Het wachtwoord is: \n' + response.data.data['password'] + ' Let op! Het wachtwoord is hierna niet meer te zien';
swal({
title: 'Gelukt!',
content: span,
icon: icon,
});
} else {
let message = 'Het aanmaken van het nieuwe klant account is niet gelukt, controleer het emailadres en probeer het opnieuw!';
if (response.data.message == 'messages.organization.failed') {
message = 'De klant heeft geen verzonden offertes, hierdoor kan een account voor deze klant niet worden aangemaakt';
}
swal('Mislukt!', message, 'error');
}
}, function(error) {
swal('Mislukt!', 'Het aanmaken van het nieuwe klant account is niet gelukt, controleer het emailadres en probeer het opnieuw!', 'error');
});
}
});
}
// Init data
$scope.init = function () {
// $scope.today = $scope.convertDateObjToJS(new Date(), true, 'date');
$scope.todayDate = new Date();
$scope.todayDate.setHours(0)
$scope.todayDate.setMinutes(0)
$scope.todayDate.setSeconds(0)
$scope.todayDate.setMilliseconds(0)
$scope.today = $scope.todayDate.toLocaleDateString()
// Agenda item frequencies
$scope.frequencies = [{
code: '-',
name: 'Eenmalig'
},{
code: 'D',
name: 'Dagelijks'
},{
code: 'W',
name: 'Wekelijks'
},{
code: 'M',
name: 'Maandelijks'
},{
code: 'Y',
name: 'Jaarlijks'
}];
$scope.getCustomer();
$scope.getEmployeesForAgenda();
}
$scope.getCustomer = function() {
var req = {
method: 'GET',
url: '/customer/getDetails/' + $routeParams.id,
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
if (response.data.data[0]) {
$scope.customer = response.data.data[0];
} else {
$scope.customer = response.data.data;
}
$scope.fetchAccounts();
$scope.fetchScenarios();
}
});
}
$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.toOverview = function() {
$location.url('/page/klanten');
}
$scope.afterChange = function(tableName, row, action) {
if (tableName == 'Customer') {
row['contactperson'] = row.contactperson_salutation + ' ' + row.contactperson_name;
}
}
// customer
$scope.customerCard = {
name: 'Customer',
controller: 'customer',
function: 'getdetails/' + $routeParams.id,
hideTable: true,
// Panel class
panelClass: 'panel-trainingskampen',
pageLimit: 5,
fields: [
'id',
'club_name',
'contactperson',
'contactperson_salutation',
'contactperson_name',
'address',
'address1',
'address2',
'postalcode',
'place',
'state',
'country',
'country_name',
'remarks',
'phone_number',
'mobile_number',
'email',
'coc_code',
'vat_code',
'password',
],
fieldDetails:{
'id': {
'hideEdit':true,
},
'club_name': {
'label': 'Clubnaam'
},
'contactperson_salutation': {
'label': 'Aanhef'
},
'contactperson_name': {
'label': 'Contactp. Naam'
},
'address': {
'label': 'Adres1'
},
'address1': {
'label': 'Adres2'
},
'address2': {
'label': 'Adres3'
},
'postalcode': {
'label': 'Postcode'
},
'place': {
'label': 'Plaats'
},
'state': {
'hideEdit': true,
},
'contactperson':{
'hideEdit': true,
},
'password': {
'type': 'password',
'hideEdit':true,
},
'country': {
'label': 'Land code',
},
'country_name': {
'label': 'Land naam'
},
'remarks': {
'label': 'Opmerkingen'
},
'phone_number': {
'label': 'Tel.Nr.'
},
'mobile_number': {
'label': 'Mob.Nr.'
},
'email': {
'label': 'E-Mailadres'
},
'coc_code': {
'label': 'KVK-Nummer'
},
'vat_code': {
'label': 'BTW-Nummer'
},
},
buttons: {
'C': {
'id': 'c',
'inline': false,
'header': false,
},
'R':{
'id': 'r',
'inline': false,
},
'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,
}
}
}
// agenda item that need follow up
$scope.personalContactOverview = {
name: 'Persoonlijk contact',
controller: 'customer_note',
function: 'getByCustomerId/' + $routeParams.id,
hideTable: true,
// Panel class
panelClass: 'panel-trainingskampen',
pageLimit: 5,
autoChangeTo: ['user_id'],
fields: [
'id',
'v_date',// date for view
'subject',
'date', // date for edit
'user_id',
'v_follow_up_date', // follow up date for view
'follow_up',
'follow_up_date', // follow up date for edit
'finished',
'customer_id',
'files',
'note',
'show',
'send_agenda_item',
'time',
'duration',
],
//pair the customer table
subQueries: {
'customer': {
'lfield': 'customer_id',
'ffield': 'id',
'controller': 'customer',
'function': 'getForOverview',
},
},
style:{
row:{
'danger':{
'v_status': '==danger',
},
'warning':{
'v_status': '==warning',
},
'success':{
'v_status': '==success',
},
},
},
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,
},
id: {
hideList: false,
hideEdit: true,
label: '#',
},
show: {
label: 'Tonen',
hideList: true,
hideEdit: true,
},
customer_id: {
hideEdit: true,
hideList: true,
label: 'Klant',
changeTo: ['customer.club_name'],
default: $routeParams.id,
required: true,
},
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,
},
follow_up_date: {
label: 'Opvolg datum',
sortAsc: true,
hideList: true,
hideEdit: false,
required: true,
},
finished: {
label: 'Afgerond',
hideList: false,
},
note: {
label: 'Beschrijving',
hideList: true,
},
date: {
label: 'Datum',
hideList: true,
default: new Date(),
required: true,
},
v_date: {
label: 'Datum',
hideList: false,
hideEdit: 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 item 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,
}
}
}
// customer quotations
$scope.customerQuotations = {
name: 'Klant offertes',
controller: 'quotation',
function: 'getByCustomerId/' + $routeParams.id,
pageLimit: 5,
fields: [
'id',
'quotation_number',
'managing_user_id',
'camp_name',
'amount',
'expire_date',
'status',
'payment_status_id',
'archived',
'updated_at',
],
style:{
row:{
'danger':{
'row': '==danger',
},
'warning':{
'row': '==warning',
},
},
},
subQueries: {
'manager':{
'lfield': 'managing_user_id',
'ffield': 'id',
'controller': 'user',
},
'payment_status':{
'lfield': 'payment_status_id',
'ffield': 'id',
'controller': 'payment_status',
},
},
fieldDetails: {
'id': {
'label': 'Id',
'hideEdit': 'true',
'type': 'number',
},
'quotation_number': {
'label': 'Offerte nummer',
'hideEdit': 'true',
'type': 'number',
},
'managing_user_id': {
'label': 'TK manager',
'changeTo': 'manager.name',
},
'camp_name': {
'label': 'Kampnaam',
},
'amount': {
'label': 'Bedrag',
},
'expire_date':{
'label': 'Verval datum',
},
'status':{
'label': 'Status',
},
'payment_status_id': {
'label': 'Aanbetaal status',
'changeTo': 'payment_status.name',
},
'archived': {
'label': 'Gearchiveerd',
'hideEdit': true,
'type': 'boolean',
'booleanOff': '0',
'booleanOn': '1',
},
'updated_at': {
'label': 'Laatst geüpdate',
'hideEdit': true,
'sortAsc': false,
}
},
buttons: {
'C': {
'id': 'c',
'header': false,
'inline': false,
},
'R':{
'id': 'r',
'name': 'Bekijk offerte',
'label': 'Bekijk',
'cancelName': 'Annuleren',
'confirmName': 'Bekijk',
'confirmClass': 'info',
'icon':'fa-arrow-right',
'action': 'toQuotation',
'parentScope': true,
'inline': true,
},
'U': {
'id': 'u',
'inline':false,
},
'V':{
'id': 'v',
'name': 'Bekijk de versies',
'label': 'Versies',
'cancelName': 'Annuleren',
'confirmName': 'Versies',
'confirmClass': 'info',
'icon': 'fa-align-justify',
'action':'showVersions',
'inline': $scope.user.role.id >= 4,
'parentScope': true,
},
'VV':{
'id': 'vv',
'name': 'Verleng vervaldatum',
'label': 'Verleng vervaldatum',
'icon': 'fa-repeat',
'action':'extendExpireDate',
'inline': $scope.user.rights != undefined && $scope.user.rights.quotation != undefined && $scope.user.rights.quotation.extendexpiredate != undefined && $scope.user.rights.quotation.extendexpiredate,
'parentScope': true,
'whereField': 'status',
'where': {
'==': 'Vervallen',
},
},
'S':{
'id': 's',
'name': 'Mail offerte',
'label': 'Verstuur',
'cancelName': 'Annuleren',
'confirmName': 'Stuur',
'confirmClass': 'send',
'icon': 'fa-envelope',
'action':'sendQuotation',
'inline': $scope.user.role.id >= 4,
'parentScope': true,
'whereField': 'showSend',
'where': {
'!=': false,
},
},
'PDF':{
'id': 'pdf',
'name': 'Zie offerte',
'label': 'PDF',
'cancelName': 'Annuleren',
'confirmName': 'Stuur',
'confirmClass': 'getPdf',
'icon': 'fa-file',
'action':'getPdf',
'inline': $scope.user.role.id >= 4,
'parentScope': true,
},
'DQ':{
'id': 'dq',
'name': 'Weiger offerte',
'label': 'Weiger',
'header': false,
'inline': true,
'icon': 'fa-times',
'action': 'showDeclineModal',
'parentScope': true,
'whereField': 'showDeny',
'where':{
'!=': false,
},
},
'DU': {
'id': 'du',
'name': 'Offerte dupliceren',
'label': 'Kopie',
'cancelName': 'Annuleren',
'confirmName': 'Dupliceren',
'confirmClass': 'duplicate',
'header': false,
'inline': $scope.user.role.id >= 4,
'icon': 'fa-copy',
'action': 'duplicate',
'parentScope': true,
},
'O': {
'id': 'o',
'name': 'Offline betaald en getekend',
'label': 'Offline betaald en getekend',
'cancelName': 'Annuleren',
'confirmName': 'Naar draaiboek',
'confirmClass': 'offline',
'header': false,
'inline': $scope.user.role.id >= 5,
'icon': 'fa-lock',
'action': 'toScenario',
'parentScope': true,
'whereField': 'status',
'where':{
'==': 'Concept',
},
},
'A':{
'id': 'a',
'name': 'Archiveer offerte',
'label': 'Archiveer',
'cancelName': 'Annuleren',
'confirmName': 'Archiveer',
'confirmClass': 'warning',
'header': false,
'inline': $scope.user.role.id >= 4,
'icon': 'fa-archive',
'action': 'toArchive',
'parentScope': true,
'whereField': 'archived',
'where':{
'==': 0,
},
},
'DEA':{
'id': 'dea',
'name': 'Dearchiveer offerte',
'label': 'Dearchiveer',
'cancelName': 'Annuleren',
'confirmName': 'Archiveer',
'confirmClass': 'warning',
'header': false,
'inline': $scope.user.role.id >= 4,
'icon': 'fa-archive',
'action': 'toArchive',
'parentScope': true,
'whereField': 'archived',
'where':{
'==': 1,
},
},
'D':{
'id': 'd',
'name': 'Verwijder offerte',
'label': 'Verwijder',
'cancelName': 'Annuleren',
'confirmName': 'Verwijder',
'confirmClass': 'warning',
'header': false,
'inline': $scope.user.role.id >= 4,
'icon': 'fa-trash',
'action': 'delete',
'whereField': 'status',
'where':{
'!=': 'Geaccepteerd',
},
},
}
}
if ($rootScope && $rootScope['user'] && $rootScope['user']['user_role_id'] && $rootScope['user']['user_role_id'] >= 4) {
//Draaiboeken OVERZICHT employees and higher
$scope.customerScenarios = {
name: 'Draaiboeken',
controller: 'scenario',
function: 'getByCustomerId/' + $routeParams.id,
showFilters: true,
pageLimit: 10,
fields: [
'name',
'customer_id',
'scenario_status_id',
'from',
'to',
'archived',
],
//pair the customer table
subQueries: {
'customer': {
'lfield': 'customer_id',
'ffield': 'id',
'controller': 'customer',
'function': 'getForOverview',
},
'scenario_status': {
'lfield': 'scenario_status_id',
'ffield': 'id',
'controller': 'scenario_status',
},
},
fieldDetails: {
'name': {
'label': 'Trainingskamp',
},
'customer_id': {
'label': 'Klant',
'changeTo': ['customer.company_name'],
},
'scenario_status_id': {
'label': 'Status',
'changeTo': ['scenario_status.name'],
},
'from': {
'label': 'Van datum',
'sortAsc': false,
},
'to':{
'label': 'Tot datum',
'sortAsc': false,
},
'archived':{
'label': 'Gearchiveerd',
'type': 'boolean',
'booleanOn': 1,
'booleanOff': 0,
}
},
buttons: {
'C':{
'id': 'c',
'header': false,
'inline': false,
},
'R': {
'id': 'r',
'name': 'Bekijk traingskamp',
'label': 'Bekijk',
'confirmName': 'View',
'confirmClass': 'info',
'inline': true,
'header': false,
'icon': 'fa-arrow-right',
'action': 'goToScenario',
'parentScope': true,
},
'P': {
'id': 'p',
'name': 'Bekijk pdf',
'label': 'PDF',
'confirmName': 'pdf',
'confirmClass': 'pdf',
'inline': true,
'header': false,
'icon': 'fa-file',
'action': 'toPdf',
'parentScope': true,
'whereField': 'scenario_status_id',
'where': {
'!=': '1',
},
},
'AR': {
'id': 'ar',
'name': 'Archiveer',
'label': 'Archiveer',
'confirmName': 'Archiveer',
'confirmClass': 'success',
'inline': true,
'header': false,
'icon': 'fa-archive',
'action': 'archiveScenario',
'parentScope': true,
'whereField': 'archived',
'where':{
'==': 0,
},
},
'DAR': {
'id': 'dar',
'name': 'Dearchiveer',
'label': 'Dearchiveer',
'confirmName': 'Archiveer',
'confirmClass': 'success',
'inline': true,
'header': false,
'icon': 'fa-archive',
'action': 'deArchiveScenario',
'parentScope': true,
'whereField': 'archived',
'where':{
'==': 1,
},
},
'U':{
'id': 'u',
'header': false,
'inline': false,
},
'D':{
'id': 'd',
'name': 'Verwijder',
'label': 'Verwijder',
'confirmName': 'Delete',
'confirmClass': 'warning',
'inline': ($scope.user.role && $scope.user.role.id && $scope.user.role.id > 4 ? true : false),
'icon':'fa-trash',
'action': 'delete',
}
}
}
} else {
//Draaiboeken OVERZICHT employees and higher
$scope.customerScenarios = {
name: 'Draaiboeken',
//Panel class
panelClass: 'panel-trainingskampen',
controller: 'scenario',
function: 'getByCustomerId/' + $routeParams.id,
showFilters: true,
pageLimit: 10,
fields: [
'name',
'customer_id',
'scenario_status_id',
'from',
'to',
],
//pair the customer table
subQueries: {
'customer': {
'lfield': 'customer_id',
'ffield': 'id',
'controller': 'customer',
'function': 'getForOverview',
},
'scenario_status': {
'lfield': 'scenario_status_id',
'ffield': 'id',
'controller': 'scenario_status',
},
},
fieldDetails: {
'name': {
'label': 'Trainingskamp',
},
'customer_id': {
'label': 'Klant',
'changeTo': ['customer.company_name'],
},
'scenario_status_id': {
'label': 'Status',
'changeTo': ['scenario_status.name'],
},
'from': {
'label': 'Van datum',
'sortAsc': false,
},
'to':{
'label': 'Tot datum',
'sortAsc': false,
}
},
buttons: {
'C':{
'id': 'c',
'header': false,
'inline': false,
},
'R': {
'id': 'r',
'name': 'Bekijk traingskamp',
'label': 'Bekijk',
'confirmName': 'View',
'confirmClass': 'info',
'inline': true,
'header': false,
'icon': 'fa-arrow-right',
'action': 'goToScenario',
'parentScope': true,
'whereField': 'scenario_status_id',
'where': {
'!=': '1',
},
},
'P': {
'id': 'p',
'name': 'Bekijk pdf',
'label': 'PDF',
'confirmName': 'pdf',
'confirmClass': 'pdf',
'inline': true,
'header': false,
'icon': 'fa-file',
'action': 'toPdf',
'parentScope': true,
'whereField': 'scenario_status_id',
'where': {
'!=': '1',
},
},
'U':{
'id': 'u',
'header': false,
'inline': false,
},
'D':{
'id': 'd',
'header': false,
'inline': false,
},
}
}
}
//ga naar draaiboek
$scope.goToScenario = function(btn, row, blnSubmit) {
$location.url('/page/draaiboek/' + row['id']);
}
//ga naar pdf
$scope.toPdf = function(btn, row, blnSubmit) {
window.open('/scenario/createPdf/' + row['id']);
}
//archive scenario
$scope.archiveScenario = function(btn, row, blnSubmit) {
//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.customerScenarios.call('initiate');
} else {
swal({
title: 'Let op!',
text: response.data.message,
icon: 'error',
})
}
})
}
//dearchive scenario
$scope.deArchiveScenario = function(btn, row, blnSubmit) {
//update scenario with archived 0
let req = {
method: 'POST',
url: '/scenario/update/' + row.id,
data: {archived: 0},
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
swal({
title: 'Gelukt!',
text: 'Het draaiboek is gedearchiveerd',
icon: 'success',
});
$scope.customerScenarios.call('initiate');
} else {
swal({
title: 'Let op!',
text: response.data.message,
icon: 'error',
})
}
})
}
$scope.toArchive = function(btn, row, blnSubmit) {
if (row.archived == 1){
updateData = {archived: false};
} else {
updateData = {archived: true};
}
var req = {
method: 'POST',
url: '/quotation/update/' + row.id,
data: updateData,
}
$http(req).then(function(response) {
if (response.data.status){
$scope.customerQuotations.call('initiate');
}
});
}
// 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;
}
}
$scope.toScenario = function(btn, row, blnSubmit) {
swal({
title: 'Let op!',
text: 'Weet u zeker dat het draaiboek voor offerte ' + row.quotation_number + ' aangemaakt kan worden?\nDe klant heeft voor offerte ' + row.quotation_number + ' offline getekend en de aanbetaling is ontvangen. \n',
icon: 'warning',
type: 'warning',
buttons: {
cancel: 'Annuleren',
confirm: {
text: 'Ja!',
closeModal: false,
},
},
}).then(confirm => {
if (confirm) {
// Make scenario for the quotation
var req = {
method: 'GET',
url: '/scenario/createFromQuotation/' + row.hash,
}
// Make backend request to create scenario
$http(req).then(function(response) {
if (response.status && response.data.status) {
// manually enable the scenario
var req = {
method: 'GET',
url: '/scenario/manualEnable/' + response.data.data.id,
}
// Make backend request to create scenario
$http(req).then(function(response) {
if (response.status && response.data.status) {
swal('Geslaagd', 'Het draaiboek is aangemaakt!', 'success');
} else {
swal('Fout', 'Het activeren van het draaiboek is mislukt', 'error');
}
$scope.customerQuotations.call('initiate');
});
swal('Geslaagd', 'Het draaiboek is aangemaakt!', 'success');
} else {
swal('Fout', 'Het aanmaken van het draaiboek is mislukt', 'error');
}
}).catch(function(err) {
swal('Fout', 'Er is een onbekende fout opgetreden', 'error');
});
}
});
}
// Duplicate the quotation
$scope.duplicate = function(btn, row, blnSubmit) {
swal({
title: 'Let op!',
text: 'U wilt offerte ' + row.quotation_number + ' dupliceren.\nWelke trainingskampnaam wenst u?',
type: 'warning',
content: 'input',
buttons: {
cancel: 'Terug',
confirm: {
text: 'OK',
closeModal: false,
},
},
}).then(name => {
if (!name) {
throw null;
}
// If the user confirms
if (name.length >= 3) {
// Duplicate the quotation
var req = {
method: 'POST',
url: '/quotation/duplicate/' + row.hash,
data: {
campname: name,
}
}
$http(req).then(function(response) {
swal.stopLoading();
if (response.status && response.data.status) {
// OK
$scope.customerQuotations.call('initiate');
swal('Geslaagd', 'De offerte is gedupliceerd.', 'success');
} else {
swal('Fout', 'Het dupliceren is mislukt', 'error');
}
}).catch(function(err) {
swal('Fout', 'Er is een onbekende fout opgetreden.', 'error');
});
} else {
// No valid camp name
swal({
title: 'Let op!',
text: 'Voer een geldige kampnaam in.', type: 'warning'
});
}
}).catch(err => {
if (err) {
swal('Fout', 'Er ging iets fout.', 'error')
} else {
swal.stopLoading();
swal.close();
}
});
}
$scope.showDeclineModal = function(btn, row, blnSubmit) {
$('#declineModal').modal('show');
$scope.hash = row['hash'];
}
$scope.showVersions = function(btn, row, blnSubmit) {
$location.url('/page/offerteversies/' + row.quotation_number);
}
$scope.getPdf = function(btn, row, blnSubmit) {
window.open('/quotation/createPdf/' + row.quotation_number);
}
$scope.sendQuotation = function(btn, row, blnSubmit) {
var req = {
method: 'POST',
url: '/quotation/email/' + row.hash,
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
// Refresh the overview
$scope.customerQuotations.call('initiate');
swal('Email verstuurd','De email is met succes verstuurd naar ' + response.data.data.email, 'success');
} else {
var msg = 'De e-mail kon helaas niet verzonden worden.'
if (response.data.message) {
msg += '\nFout: ' + response.data.message
}
swal('Foutmelding', msg, 'error');
}
}).catch(err => {
if (err) {
swal('Foutmelding', 'Er is een onbekende fout opgetreden!', 'error');
console.error(err)
} else {
swal.stopLoading();
swal.close();
}
})
}
$scope.toQuotation = function(btn, row, blnSubmit) {
if ($scope['user']['role']['id'] == 1) {
if (row['status'] == 'Geaccepteerd' || row['status'] == 'Vervallen') {
swal('Waarschuwing', 'Een offerte met status \'' + row['status'] + '\' kan u niet meer inkijken', 'warning');
return false;
}
window.open('/page/offertevalidatie/' + row['hash'], '_blank');
} else {
$location.url('/page/offerte/' + row['hash']);
}
}
//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;
$scope.sbaCrudTableChange(tableName, 'follow_up', followUpValue, 'CHANGE');
break;
}
}
$scope.undoData = function(){
if ($scope.selectedNote['original_responsible'] !== undefined) {
$scope.selectedNote['responsible'] = $scope.selectedNote['responsible_name'];
}
}
//translate table data groups
$scope.tableReady = function (tableName) {
switch (tableName) {
case 'Persoonlijk contact':
angular.forEach($scope.personalContactOverview.data.rows, function(row) {
row.created_at = $scope.convertDateObjToJS(row.created_at, false, 'date');
if (row.created_at) {
row.created_at = row.created_at.toLocaleDateString();
}
});
break;
}
}
$scope.getActualItems = function(key, value, showOlderNotes = false) {
return function(item) {
return showOlderNotes || item[key] >= value;
}
}
// Toggle: show/hide this note
$scope.toggleShowItem = function (row) {
var req = {
method: 'POST',
url: '/customer_note/add/' + row.id,
data: {
show: row.show,
}
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
// OK
} else {
// Error
swal({
title: 'Foutmelding',
text: response.data.message,
icon: 'warning',
});
}
});
}
$scope.customerDoBtn = function (btn, row) {
if (btn.parentScope && (typeof $scope[btn.action] !== undefined)) {
$scope[btn.action](btn, row);
} else {
$scope.customerCard.toggleButton(btn, row);
}
}
$scope.doBtn = function (btn, row) {
if (btn.parentScope && (typeof $scope[btn.action] !== undefined)) {
$scope[btn.action](btn, row);
} else {
$scope.personalContactOverview.toggleButton(btn, row);
}
}
$scope.doBtnAg = function (btn, row) {
if (btn.parentScope && (typeof $scope[btn.action] !== undefined)) {
$scope[btn.action](btn, row);
} else {
$scope.agendaOverview.toggleButton(btn, row);
}
}
$scope.toLabel = function(myTable, fieldName){
if (myTable.fieldDetails !== undefined && myTable.fieldDetails[fieldName] !== undefined && myTable.fieldDetails[fieldName].label !== undefined){
return myTable.fieldDetails[fieldName].label;
}else{
return fieldName.split("_").join(" ");
}
}
$scope.toggleNote = function (btn, row) {
if ($scope.showNoteId === row.id) {
$scope.showNoteId = 0;
// btn.icon = 'fa-caret-down';
} else {
$scope.showNoteId = row.id;
// btn.icon = 'fa-caret-up';
}
}
$scope.toggleAgendaItem = function (btn, row) {
if ($scope.showAgItemId === row.id) {
$scope.showAgItemId = 0;
// btn.icon = 'fa-caret-down';
} else {
$scope.showAgItemId = row.id;
// btn.icon = 'fa-caret-up';
}
}
// Save the note
$scope.saveNote = function() {
if ($scope.selectedNote['original_responsible'] !== undefined) {
$scope.selectedNote['responsible'] = $scope.selectedNote['original_responsible'];
}
if ($scope.selectedNote['original_customer_id'] !== undefined) {
$scope.selectedNote['customer_id'] = $scope.selectedNote['original_customer_id'];
}
if (!$scope.selectedNote.id) {
$scope.selectedNote.id = '';
// Set the customer id
$scope.selectedNote.customer_id = $routeParams.id;
}
var req = {
method: 'POST',
url: '/customer_note/add/' + $scope.selectedNote.id,
data: $scope.selectedNote,
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
// OK
$scope.personalContactOverview.call('initiate');
$('#noteModal').modal('hide');
swal({
title: 'Gelukt!',
text: 'Uw notitie is opgeslagen.',
icon: 'success',
});
} else {
// Error
swal({
title: 'Foutmelding',
text: response.data.message,
icon: 'warning',
});
}
});
}
$scope.showAgendaModal = function(btn, row) {
$scope.selectedAgItem = row;
$('#agendaModal').modal('show');
}
// Save the agenda item
$scope.saveAgItem = function() {
if (!$scope.selectedAgItem.id) {
$scope.selectedAgItem.id = '';
// Set the customer id
$scope.selectedAgItem.customer_id = $routeParams.id;
}
selectedAgItem = angular.copy($scope.selectedAgItem);
selectedAgItem.date = $scope.convertDateObjToJS(selectedAgItem.date, true, 'date')
var req = {
method: 'POST',
url: '/customer_agenda/add/' + $scope.selectedAgItem.id,
data: selectedAgItem,
}
$http(req).then(function(response) {
if (response.status && response.data.status) {
// OK
$scope.agendaOverview.call('initiate');
$('#agendaModal').modal('hide');
swal({
title: 'Gelukt!',
text: 'Uw agendapunt is opgeslagen.',
icon: 'success',
});
} else {
// Error
swal({
title: 'Foutmelding',
text: response.data.message,
icon: 'warning',
});
}
});
}
$scope.getImages = function( images = null, item = null) {
var req = {
method: 'POST',
url: '/filecontroller/getImages/customers/' + $routeParams.id,
data: {
images: images,
},
}
$http(req).then(function(response) {
// Success? Set the options
$scope.clubImage = response.data.data[0];
})
}
$scope.getImages();
// Image upload function
$scope.uploadImage = 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.clubImage !== undefined){
url += '/' + 0;
}
url += '?name=' + encodeURI(fileName);
Upload.upload({
url: url,
data: {
file: $scope.fileInfo.file,
},
}).then(function (response) {
$scope.currentImages = response.data.data;
$scope.uploadMsgType = 'success';
$scope.uploadImageMessage = 'Succesvol opgeslagen';
$scope.getImages();
}, 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.deleteImage = 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.getImages();
} else {
// Error
swal({
title: 'Error',
text: response.data.message,
icon: 'warning',
});
}
});
}
$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;
}
}
}
// Extend expire date of the quotation
$scope.extendExpireDate = function(btn, row, blnSubmit) {
swal({
title: 'Let op!',
text: 'U wilt de verval datum van offerte ' + row.quotation_number + ' verlengen.\nMet hoeveel dagen wilt u de de vervaldatum verlengen?',
type: 'warning',
content: 'input',
input: 'number',
buttons: {
cancel: 'Terug',
confirm: {
text: 'OK',
closeModal: false,
},
},
}).then(amountOfDays => {
// If the user confirms
if (amountOfDays && amountOfDays > 0) {
// Extend expire date of the quotation
var req = {
method: 'POST',
url: '/quotation/extendExpireDate/' + row.hash,
data: {
amount_of_days: amountOfDays,
}
}
$http(req).then(function(response) {
swal.stopLoading();
if (response.status && response.data.status) {
// OK
$scope.customerQuotations.call('initiate');
swal('Gelukt!', 'De vervaldatum van de offerte is verlengt met ' + amountOfDays + (amountOfDays == 1 ? ' dag': ' dagen') + '.', 'success');
} else {
swal('Fout', 'Het verlengen van de vervaldatum is mislukt', 'error');
}
}).catch(function(err) {
swal('Fout', 'Er is een onbekende fout opgetreden.', 'error');
});
} else {
// No valid amount of days
swal('Let op!', 'Voer een geldig aantal dagen in.', 'warning');
}
}).catch(err => {
if (err) {
swal('Fout', 'Er ging iets fout.', 'error')
} else {
swal.stopLoading();
swal.close();
}
});
}
// Init
$scope.init();
})