Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- /* Controllers - Quotation Controller */
- angular.module('nsgsis').controller('QuotationController', ['$scope', 'NgTableParams', 'QuotationService','$translate', 'GeneralService','$mdDialog', '$location', '$timeout',
- function($scope, NgTableParams, QuotationService, $translate, GeneralService, $mdDialog, $location, $timeout) {
- $scope.loader = false;
- $scope.searchStringClientName = "";
- $scope.General = GeneralService;
- $scope.quotation = {};
- $scope.quotationId = null;
- $scope.quotationList = {};
- $scope.clientsList = {};
- $scope.co_ordinatorsList = {};
- $scope.clientContactsList = {};
- $scope.clientDetails = {};
- $scope.co_ordinatorsSelected = {};
- $scope.TypeList = [];
- $scope.courseDetails = {};
- $scope.clientSelectedContactsList = {};
- $scope.tariffList = {};
- $scope.tariffSelected = " ";
- $scope.courseItemsList = [];
- $scope.courseDeletedItemsList = [];
- $scope.costCentreItems= {};
- $scope.selectedCourseName = null;
- $scope.totalItems = 0;
- $scope.allItemsSaved = true;
- $scope.searchFilter = {};
- $scope.collapse = false;
- $scope.editMode = false;
- $scope.emptyDate = true;
- $scope.foundDelegatesList = [];
- $scope.quotationDelegatesList = [];
- $scope.addingDelegate = false;
- $scope.delegateDetails = {};
- $scope.copyCase = false;
- $scope.delegatesResultEnabled = false;
- $scope.racesList = [];
- $scope.qualificationsList = [];
- $scope.calendarList = [];
- $scope.calendarSelected = {};
- $scope.userName = "user";
- $scope.pageSize = null;
- $scope.pageNumber = null;
- $scope.username = "user";
- $scope.password = "password";
- // Restituisce la lista delle ultime 10 quotation dell'utente corrente
- $scope.getLastQuotations = function () {
- QuotationService.getUserToken($scope.username, $scope.password)
- .then(
- function(response) {
- $scope.loader = true;
- $scope.size = "10";
- QuotationService.getUserQuotations($scope.userName, $scope.size, $scope.searchFilter)
- .then(
- function(response) {
- $scope.quotationList = response;
- for (var i in response) {
- $scope.quotationList[i].quotationDate = new Date (response[i].quotationDate);
- $scope.quotationList[i].printStatus = getIconByStatus(String(response[i].status), String(response[i].subStatus));
- if($scope.quotationList[i].status == "20" && $scope.quotationList[i].subStatus == "0") {
- $scope.quotationList[i].classDeleted = "deleted";
- }
- }
- $scope.defaultConfigTableParams =
- new NgTableParams({
- page: 1,
- count: 10
- }, {
- counts: [],
- total: 1,
- dataset: $scope.quotationList
- });
- $scope.loader = false;
- },
- function(errResponse){
- $scope.quotationList = [];
- console.error("Error loading last quotations");
- $scope.loader = false;
- }
- );
- },
- function(errResponse){
- console.error("Error token");
- }
- );
- }
- // Restituisce l'icona FA relativa allo stato della quotation
- function getIconByStatus(status, substatus) {
- var printStatus = {};
- $scope.ss = status + substatus;
- switch ($scope.ss) {
- case "30"://draft
- printStatus.iconName = "hourglass-start";
- printStatus.title = "NSG_SIS_QUOTATION.GENERATE";
- break;
- case "40"://submitted
- printStatus.iconName ="certificate";
- printStatus.title = "NSG_SIS_QUOTATION.AUTHORIZE";
- break;
- case "50"://authorized
- printStatus.iconName = "registered";
- printStatus.title = "NSG_SIS_QUOTATION.SUBMIT";
- break;
- case "60"://tentative booking (add calendar & delegates)
- printStatus.iconName = "calendar-alt";
- printStatus.title = "NSG_SIS_QUOTATION.TENTATIVE_BOOKING";
- break;
- case "61": case "62": case "63": case "64": case "65":
- printStatus.iconName = "money-bill-alt";
- break;
- case "70": case "71": case "72": case "73": case "74": case "75": case "76":
- printStatus.iconName = "clipboard-check";
- break;
- case "80": case "81": case "82":
- printStatus.iconName = "money-bill";
- case "90"://event completed
- printStatus.iconName = "calendar-check";
- break;
- case "91"://cancelled training
- printStatus.iconName = "ban";
- break;
- case "200"://cancelled quotation
- printStatus.iconName = "trash-alt";
- printStatus.title = "NSG_SIS_QUOTATION.DELETED";
- break;
- default://not found
- printStatus.iconName = null;
- break;
- }
- return printStatus;
- }
- $scope.editQuotation = function(item) {
- $scope.editMode = true;
- $scope.info = {};
- $scope.info.clientInformation = false;
- $scope.info.contactDetails = false;
- $scope.info.pricesQuoted = false;
- $scope.getQualifications();
- $scope.getRaces();
- getQuotation(item.id);
- }
- // Operazioni dopo la selezione del cliente
- $scope.selectedClientNameItemChanged = function (item) {
- if (item !== undefined && item.clientName !== undefined){
- $scope.selectedClientName = item.clientName;
- $scope.clientId = item.clientId;
- getClientDetails($scope.clientId);
- }
- // Clear fields
- if (item === undefined) {
- $scope.clientDetails = $scope.co_ordinatorsList = $scope.clientContactsList = {};
- $scope.postalress = $scope.streetAddress = "";
- $scope.clientSelectedContactsList = {};
- }
- }
- $scope.selectedCourseNameItemChanged = function (item) {
- switch(item){
- case undefined:
- $scope.courseDetails = {};
- $scope.courseItemsList = [];
- $scope.selectedCourseName = null;
- $scope.allItemsSaved = true;
- $scope.emptyDate = true;
- break;
- default:
- if (item.courseNameFull !== undefined){
- $scope.selectedCourseName = item.courseNameFull;
- $scope.courseDetailsId = item.courseDetailsId;
- getCourseDetails($scope.courseDetailsId, null, false);
- }
- break;
- }
- }
- // Restituisce il dettaglio del Client
- function getClientDetails(clientId,contactId) {
- $scope.loader = true;
- QuotationService.getClientDetails(clientId)
- .then(
- function(response) {
- $scope.clientDetails = response;
- loadClientType();
- $scope.co_ordinatorsList = response.clientContacts;
- $scope.clientContactsList = response.contacts;
- if ($scope.editMode) {
- $scope.co_ordinatorsSelected = String(contactId);
- $scope.insertCoordinator();
- $scope.calendarIdSelected = String($scope.quotation.calendarId);
- $scope.insertCalendar();
- }
- $scope.count = 0;
- $scope.postalAddress = "";
- $scope.streetAddress = "";
- $scope.clientDetails.typeName = "";
- if($scope.editMode)
- $scope.selectedClientName = $scope.clientDetails.clientName;
- for (var i in $scope.clientTypeList) {
- if ($scope.clientTypeList[i].typeId == $scope.clientDetails.type)
- $scope.clientDetails.typeName = $scope.clientTypeList[i].type;
- }
- for (var i in response.addresses) {
- $scope.count++;
- if($scope.count <= 5 && response.addresses[i] != null)
- $scope.postalAddress += response.addresses[i]+"\n";
- if($scope.count > 5 && response.addresses[i] != null)
- $scope.streetAddress += response.addresses[i]+"\n";
- }
- $scope.loader = false;
- },
- function(errResponse){
- $scope.loader = false;
- console.error("Error loading client details");
- }
- );
- }
- function loadClientType() {
- GeneralService.loadClientType().then(
- function(response) {
- $scope.clientTypeList = response;
- }, function(errResponse) {
- console.error("Error loading client types");
- });
- }
- function getCalendar(courseId) {
- $scope.today = GeneralService.getTodayDate();
- QuotationService.getCalendar(courseId, $scope.today)
- .then(
- function(response) {
- $scope.calendarList = response;
- },
- function(errResponse){
- console.error("Error loading calendar details");
- }
- )
- }
- // Valorizza i campi del co-ordinator selezionato
- $scope.insertCoordinator = function() {
- $scope.loader = true;
- for (var i in $scope.co_ordinatorsList) {
- if ($scope.co_ordinatorsList[i].id == $scope.co_ordinatorsSelected) {
- $scope.clientSelectedContactsList = $scope.co_ordinatorsList[i];
- if ($scope.co_ordinatorsList[i].designation == "1")
- $scope.clientSelectedContactsList.designationValue = "Departmental Coordinator";
- $scope.clientSelectedContactsList.postalAddress = "";
- $scope.clientSelectedContactsList.streetAddress = "";
- $scope.count = 0;
- for (var j in $scope.clientSelectedContactsList.addresses) {
- $scope.count++;
- if($scope.count <= 5 && $scope.clientSelectedContactsList.addresses[j] != null)
- $scope.clientSelectedContactsList.postalAddress += $scope.clientSelectedContactsList.addresses[j]+"\n";
- if($scope.count > 5 && $scope.clientSelectedContactsList.addresses[j] != null)
- $scope.clientSelectedContactsList.streetAddress += $scope.clientSelectedContactsList.addresses[j ]+"\n";
- }
- }
- }
- $scope.loader = false;
- }
- // Valorizza i campi del calendar selezionato
- $scope.insertCalendar = function() {
- $scope.loader = true;
- for (var i in $scope.calendarList) {
- if ($scope.calendarList[i].calendarId == $scope.calendarIdSelected) {
- $scope.calendarSelected = $scope.calendarList[i];
- $scope.calendarSelected.fromDate = new Date ($scope.calendarSelected.fromDate);
- $scope.calendarSelected.toDate = new Date ($scope.calendarSelected.toDate);
- }
- }
- $scope.loader = false;
- }
- //Restituisce il dettaglio del Course
- function getCourseDetails(courseId, quotationId, retrieveCourseList) {
- $scope.loader = true;
- QuotationService.getCourseDetails(courseId)
- .then(
- function(response) {
- $scope.courseDetails = response;
- if($scope.courseDetails.dateApproved!=null){
- $scope.emptyDate = false;
- $scope.courseDetails.dateApproved = new Date($scope.courseDetails.dateApproved);
- }else{
- $scope.emptyDate = true;
- }
- if($scope.courseDetails.hasTariffGroup){
- QuotationService.getTariffGroups()
- .then(
- function(response) {
- $scope.tariffList= response;
- },
- function(errResponse){
- console.error("Error loading tariff details");
- }
- )
- }
- if($scope.editMode)
- $scope.selectedCourseName = $scope.courseDetails.courseNameFull;
- $scope.CourseItemConfigTableParams =
- new NgTableParams({
- page: 1,
- count: 10
- }, {
- counts: [],
- total: 1,
- dataset: $scope.courseItemsList
- });
- loadCostCentre();
- if($scope.editMode && retrieveCourseList){
- var index_list = 0;
- QuotationService.getQuotationCourseItemList(quotationId)
- .then(
- function(response) {
- $scope.courseItemsList= response;
- for(var i in $scope.courseItemsList){
- //Save max number of learners
- if($scope.courseItemsList[i].costCentreId==3){
- $scope.courseDetails.noOfTrainee = $scope.courseItemsList[i].noOfTrainee;
- $scope.courseItemsList[i].item = "course";
- }
- for(var j in $scope.costCentreItems){
- if($scope.courseItemsList[i].costCentreId==$scope.costCentreItems[j].costId){
- $scope.courseItemsList[i].item = $scope.costCentreItems[j].costCentre;
- }
- }
- $scope.courseItemsList[i].saved = true;
- $scope.courseItemsList[i].item_old = $scope.courseItemsList[i].item;
- $scope.courseItemsList[i].coursePrice_old = $scope.courseItemsList[i].coursePrice;
- $scope.courseItemsList[i].total_old = $scope.courseItemsList[i].total;
- $scope.courseItemsList[i].noOfTrainee_old = $scope.courseItemsList[i].noOfTrainee;
- $scope.courseItemsList[i].index = index_list;
- $scope.courseItemsList[i].couresDetailsId = $scope.courseDetails.id;
- index_list++;
- $scope.courseItemsList[i].saved = true;
- }
- if($scope.courseItemsList.length > 0) {
- $scope.allItemsSaved = true;
- }
- else {
- $scope.allItemsSaved = false;
- $scope.courseItemsList=[{"item":"course", "noOfTrainee":"", "coursePrice":$scope.courseDetails.coursePrice, "total":"0", "saved":false, "index":0,
- "item_old":"course", "noOfTrainee_old":"", "total_old":0, "coursePrice_old":0}];
- }
- refreshTotal();
- },
- function(errResponse){
- console.error("Error loading course items list");
- }
- )
- }
- else {
- $scope.allItemsSaved = false;
- $scope.courseItemsList=[{"item":"course", "noOfTrainee":"", "coursePrice":$scope.courseDetails.coursePrice, "total":"0", "saved":false, "index":0,
- "item_old":"course", "noOfTrainee_old":"", "total_old":0, "coursePrice_old":0}];
- }
- $scope.loader = false;
- },
- function(errResponse){
- $scope.loader = false;
- console.error("Error loading course details");
- }
- );
- }
- // Salva la quotation come bozza (stato 3-0)
- $scope.saveQuotation = function() {
- $scope.loader = true;
- $scope.quotation.clientId = $scope.clientDetails.id;
- $scope.quotation.clientContactId = $scope.clientSelectedContactsList.id;
- $scope.quotation.dataId = $scope.quotationId;
- $scope.quotation.courseDetailsId = $scope.courseDetails.id;
- $scope.quotation.courseQuotedList = $scope.courseItemsList;
- $scope.quotation.tariffId = parseInt($scope.tariffSelected);
- if($scope.courseDeletedItemsList.length > 0){
- for(var i in $scope.courseDeletedItemsList){
- QuotationService.deleteCourseItem($scope.courseDeletedItemsList[i]).then(
- function(response) {
- $scope.loader = false;
- }, function(errResponse) {
- $scope.loader = false;
- console.error("Error saving quotation");
- }
- );
- }
- }
- for(var i in $scope.courseItemsList){
- if($scope.courseItemsList[i].costCentreId == 3) $scope.courseItemsList[i].coursePrice = null;
- }
- QuotationService.saveQuotation($scope.quotation).then(
- function(response) {
- $scope.loader = false;
- dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_SUCCESS'));
- $location.path( "/nsgsisfe/cco/manage-quotations" );
- $scope.editMode = false;
- $scope.getUserQuotations();
- }, function(errResponse) {
- $scope.loader = false;
- console.error("Error saving quotation");
- dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_ERROR'));
- }
- );
- }
- // Send della quotation (stato 3-0 to 4-0)
- $scope.submitQuotation = function() {
- console.log($scope.quotation);
- $scope.loader = true;
- $scope.quotation.clientId = $scope.clientDetails.id;
- $scope.quotation.clientContactId = $scope.clientSelectedContactsList.id;
- $scope.quotation.dataId = $scope.quotationId;
- $scope.quotation.courseDetailsId = $scope.courseDetails.id;
- $scope.quotation.courseQuotedList = $scope.courseItemsList;
- for(var i in $scope.courseItemsList){
- if($scope.courseItemsList[i].costCentreId == 3) $scope.courseItemsList[i].coursePrice = null;
- }
- QuotationService.submitQuotation($scope.quotation).then(
- function(response) {
- $scope.loader = false;
- dialogPop($translate.instant('NSG_SIS_QUOTATION.SUBMIT_SUCCESS'));
- $location.path( "/nsgsisfe/cco/manage-quotations" );
- $scope.editMode = false;
- $scope.getUserQuotations();
- }, function(errResponse) {
- $scope.loader = false;
- console.error("Error saving quotation");
- dialogPop($translate.instant('NSG_SIS_QUOTATION.SUBMIT_ERROR'));
- }
- );
- }
- // Delete della quotation (stato 3-0 to 20-0)
- $scope.selectedQuotationDelete = "";
- $scope.deleteSelected = function (quotationId) {
- $scope.selectedQuotationDelete = quotationId;
- }
- $scope.deleteQuotation = function(list) {
- $scope.loader = true;
- QuotationService.deleteQuotation($scope.selectedQuotationDelete).then(
- function(response) {
- $scope.loader = false;
- dialogPop($translate.instant('NSG_SIS_QUOTATION.DELETE_SUCCESS'));
- if(list == 'last')
- $scope.getLastQuotations();
- if(list == 'manage')
- $scope.getUserQuotations();
- }, function(errResponse) {
- $scope.loader = false;
- console.error("Error deleting quotation");
- dialogPop($translate.instant('NSG_SIS_QUOTATION.DELETE_ERROR'));
- }
- );
- }
- function dialogPop(title, text) {
- $mdDialog.show(
- $mdDialog.alert()
- .parent(angular.element(document.querySelector('#popupContainer')))
- .clickOutsideToClose(true)
- .title(title)
- .textContent(text)
- .ok('OK')
- );
- }
- $scope.refreshTariff = function() {
- QuotationService.getTariffedCourse($scope.courseDetails.id, $scope.tariffSelected)
- .then(
- function(response) {
- $scope.courseDetails.coursePrice = response.coursePrice;
- $scope.courseDetails.coursePrice = $scope.courseDetails.coursePrice.toFixed(2);
- $scope.courseDetails.pricePerpersonPerDay = response.coursePrice/response.courseDurationDays;
- $scope.courseDetails.courseDurationDays = response.courseDurationDays;
- $scope.courseDetails.dateApproved = response.dateApproved;
- },
- function(errResponse){
- console.error("Error loading Tariffed Course details");
- }
- );
- }
- $scope.totalCourse = function(elem){
- elem.total=elem.noOfTrainee*elem.coursePrice;
- }
- $scope.saveCourseItem = function(item) {
- if(item.coursePrice==undefined || item.coursePrice==null ||
- item.noOfTrainee=="" || item.noOfTrainee==null
- || item.item==undefined || item.item==""){
- return;
- }
- if(item.coursePrice == undefined){
- item.coursePrice = 0;
- }
- // Saving
- item.saved = true;
- $scope.allItemsSaved = true;
- //Aggiornamento totale
- refreshTotal();
- //shadow copy
- item.item_old=item.item;
- item.noOfTrainee_old=item.noOfTrainee;
- item.coursePrice_old=item.coursePrice;
- // Aggiunta campi per save
- item.pricePerTrainee = item.coursePrice/item.noOfTrainee;
- for (var i in $scope.costCentreItems){
- if($scope.costCentreItems[i].costCentre==item.item){
- item.costCentreId=$scope.costCentreItems[i].costId;
- }
- }
- item.couresDetailsId=$scope.courseDetails.id;
- item.fromDate=null;
- item.toDate=null;
- }
- $scope.editCourseItem = function(item) {
- item.saved=false;
- $scope.allItemsSaved= false;
- }
- $scope.deleteCourseItem = function(item) {
- if(item.item!='course'){
- $scope.courseItemsList.splice(item.index, 1);
- refreshTotal();
- }
- if(item.id!=null){
- $scope.courseDeletedItemsList.push(item.id);
- }
- }
- $scope.newCostItem = function(){
- var allow=true;
- for(var i in $scope.courseItemsList){
- if ($scope.courseItemsList[i].saved == false) allow = false;
- }
- if(allow){
- $scope.allItemsSaved=false;
- $scope.courseItemsList.push({
- "item" : "",
- "learners" : "",
- "price": "",
- "total": "0",
- "saved": false,
- "index": $scope.courseItemsList.length,
- "item_old": "",
- "learners_old" : "",
- "price_old" : 0,
- "total_old" : 0
- });
- }
- else { // Altro item da salvare prima di crearne un altro
- dialogPop($translate.instant('NSG_SIS_QUOTATION.COURSE_COST_ITEMS.NEW_ERROR'));
- }
- }
- //Prende gli items di Cost Centre
- function loadCostCentre() {
- QuotationService.getCostCentre()
- .then(
- function(response) {
- $scope.costCentreItems = response;
- },
- function(errResponse){
- console.error("Error loading cost centre items");
- }
- );
- }
- // Annulla le modifiche di un oggetto di courseItemsList
- $scope.discardChanges= function(item){
- for (var i in $scope.courseItemsList){
- if($scope.courseItemsList[i].index==item.index){
- item.coursePrice=item.coursePrice_old;
- item.noOfTrainee=item.noOfTrainee_old;
- item.item=item.item_old;
- }
- }
- }
- // Aggiorna il totale dei Course items (salvato in $scope.totalItems)
- function refreshTotal() {
- var count = 0;
- for (var i in $scope.courseItemsList){
- count += $scope.courseItemsList[i].total;
- }
- $scope.totalItems = count;
- }
- // Restituisce la lista delle quotation dell'utente corrente
- $scope.getUserQuotations = function () {
- $scope.loader = true;
- $scope.size = null;
- QuotationService.getUserQuotations($scope.userName, $scope.size, $scope.searchFilter)
- .then(
- function(response) {
- $scope.quotationList = response;
- for (var i in response) {
- $scope.quotationList[i].quotationDate = new Date (response[i].quotationDate);
- $scope.quotationList[i].printStatus = getIconByStatus(String(response[i].status), String(response[i].subStatus));
- if($scope.quotationList[i].status == "20" && $scope.quotationList[i].subStatus == "0") {
- $scope.quotationList[i].classDeleted = "deleted";
- }
- }
- $scope.defaultConfigTableParams =
- new NgTableParams({
- page: 1,
- count: 10
- }, {
- dataset: $scope.quotationList
- });
- $scope.loader = false;
- },
- function(errResponse){
- $scope.quotationList = [];
- console.error("Error loading quotations");
- $scope.loader = false;
- }
- );
- }
- function getQuotation(quotationId) {
- $scope.loader = true;
- $scope.quotationId = quotationId;
- QuotationService.getQuotation(quotationId)
- .then(
- function(response) {
- $scope.quotation = response;
- $scope.tariffSelected = String(response.tariffId);
- $scope.quotation.printStatus = getIconByStatus(String($scope.quotation.status), String($scope.quotation.subStatus));
- if($scope.quotation.clientId != null){
- getClientDetails($scope.quotation.clientId, $scope.quotation.clientContactId);
- }
- if($scope.quotation.courseDetailsId) {
- getCourseDetails($scope.quotation.courseDetailsId, $scope.quotationId, true);
- }
- if($scope.quotation.status>=6) {
- $scope.getQuotationDelegates($scope.quotation.id);
- getCalendar($scope.quotation.courseDetailsId);
- }
- $scope.loader = false;
- },
- function(errResponse){
- console.error("Error loading last quotations");
- $scope.loader = false;
- }
- );
- }
- $scope.declineQuotation = function () {
- $scope.loader = true;
- QuotationService.declineQuotation($scope.quotation.id, $scope.quotation.description, $scope.quotation.comments)
- .then(
- function(response) {
- dialogPop($translate.instant('NSG_SIS_QUOTATION.DECLINE_SUCCESS'));
- $scope.loader = false;
- $scope.getLastQuotations();
- $scope.editMode = false;
- },
- function(errResponse){
- dialogPop($translate.instant('NSG_SIS_QUOTATION.DECLINE_ERROR'));
- $scope.loader = false;
- }
- );
- }
- $scope.approveQuotation = function () {
- $scope.loader = true;
- QuotationService.approveQuotation($scope.quotation.id, $scope.quotation.description, $scope.quotation.comments)
- .then(
- function(response) {
- $scope.loader = false;
- dialogPop($translate.instant('NSG_SIS_QUOTATION.APPROVE_SUCCESS'));
- $scope.getLastQuotations();
- $scope.editMode = false;
- },
- function(errResponse){
- dialogPop($translate.instant('NSG_SIS_QUOTATION.APPROVE_ERROR'));
- $scope.loader = false;
- }
- );
- }
- $scope.submitQuotationToClient = function() {
- $scope.loader = true;
- QuotationService.submitQuotationToClient($scope.quotation.id, $scope.quotation.description, $scope.quotation.comments)
- .then(
- function(response) {
- $scope.loader = false;
- dialogPop($translate.instant('NSG_SIS_QUOTATION.SUBMIT_TO_CLIENT_SUCCESS'));
- $location.path( "/nsgsisfe/cco/manage-quotations" );
- $scope.editMode = false;
- $scope.getUserQuotations();
- }, function(errResponse) {
- $scope.loader = false;
- console.error("Error saving quotation");
- dialogPop($translate.instant('NSG_SIS_QUOTATION.SUBMIT_TO_CLIENT_ERROR'));
- }
- );
- }
- $scope.reportQuotation = function (){
- $scope.loader = true;
- QuotationService.reportQuotation($scope.quotation.id)
- .then(
- function(response) {
- var a = document.createElement("a");
- document.body.appendChild(a);
- a.style = "display: none";
- var file = new Blob([response.data.data], {type: 'application/pdf'});
- var fileURL = window.URL.createObjectURL(file);
- a.href = fileURL;
- a.download = getFileNameFromHttpResponse(response);
- a.click();
- $scope.loader = false;
- },
- function(errResponse){
- $('#printModal').modal('hide');
- console.error("Error downloading document");
- dialogPop($translate.instant('NSG_SIS_REPORTS.DOWNLOAD_ERROR'));
- $scope.loader = false;
- }
- );
- }
- $scope.reportBooking = function (){
- $scope.loader = true;
- QuotationService.reportBooking($scope.quotation.id)
- .then(
- function(response) {
- var a = document.createElement("a");
- document.body.appendChild(a);
- a.style = "display: none";
- var file = new Blob([response.data.data], {type: 'application/pdf'});
- var fileURL = window.URL.createObjectURL(file);
- a.href = fileURL;
- a.download = getFileNameFromHttpResponse(response);
- a.click();
- $scope.loader = false;
- },
- function(errResponse){
- $('#printModal').modal('hide');
- console.error("Error downloading document");
- dialogPop($translate.instant('NSG_SIS_REPORTS.DOWNLOAD_ERROR'));
- $scope.loader = false;
- }
- );
- }
- $scope.getDelegatesList = function() {
- //if empty filter
- if(emptyDelegatesFilter($scope.searchFilter)){
- dialogPop($translate.instant('NSG_SIS_QUOTATION.EMPTY_SEARCH'));
- return;
- }
- $scope.delegatesResultEnabled = true;
- $scope.loader = true;
- $scope.copyCase = false;
- if(onlyCase($scope.searchFilter)) $scope.copyCase = true;
- //Lista dei delegates appartenenti alla quotation
- $scope.quotationDelegatesConfigTableParams =
- new NgTableParams({
- page: 1,
- count: 10
- }, {
- dataset: $scope.quotationDelegatesList
- });
- QuotationService.getDelegatesList($scope.searchFilter)
- .then(
- function(response) {
- $scope.foundDelegatesList = response;
- console.log(response);
- $scope.foundDelegatesConfigTableParams =
- new NgTableParams({
- page: 1,
- count: 10
- }, {
- dataset: $scope.foundDelegatesList
- });
- $scope.loader = false;
- $scope.foundDelegatesConfigTableParams.reload();
- }, function(errResponse) {
- $scope.foundDelegatesList = [];
- $scope.loader = false;
- }
- );
- }
- function onlyCase(filter){
- if (filter.surname != undefined && filter.surname != null && filter.surname != "") {
- return false;
- }
- if (filter.firstName != undefined && filter.firstName != null && filter.firstName != "") {
- return false;
- }
- if (filter.persalNumber != undefined && filter.persalNumber != null && filter.persalNumber != "") {
- return false;
- }
- if (filter.idNumber != undefined && filter.idNumber != null && filter.idNumber != "") {
- return false;
- }
- if(filter.idcase != undefined && filter.idcase != null && filter.idcase != "")
- return true;
- else
- return false;
- }
- function emptyDelegatesFilter(filter){
- if (filter.surname != undefined && filter.surname != null && filter.surname != "") {
- return false;
- }
- if (filter.name != undefined && filter.name != null && filter.name != "") {
- return false;
- }
- if (filter.persalNumber != undefined && filter.persalNumber != null && filter.persalNumber != "") {
- return false;
- }
- if (filter.idNumber != undefined && filter.idNumber != null && filter.idNumber != "") {
- return false;
- }
- if(filter.idcase != undefined && filter.idcase != null && filter.idcase != "")
- return false;
- return true;
- }
- $scope.addDelegate = function(elem, copy) {
- if(elem.idNumber == null && elem.persalNumber == null && (!copy || copy==null)) {
- dialogPop($translate.instant('NSG_SIS_QUOTATION.DELEGATE.NULL_IDS'));
- }
- if(elem.idNumber != null && !$scope.isValidIdNumber(elem.idNumber) && (!copy || copy==null)) {
- dialogPop($translate.instant('NSG_SIS_QUOTATION.DELEGATE.INVALID_ID'));
- return;
- }
- if(copy && ($scope.quotationDelegatesList.length + $scope.foundDelegatesList.length > $scope.courseDetails.noOfTrainee)) {
- dialogPop($translate.instant('NSG_SIS_QUOTATION.LEARNERS_EXCEEDS'));
- return;
- }
- if((!copy || copy==null) && ($scope.quotationDelegatesList.length == $scope.courseDetails.noOfTrainee)){
- dialogPop($translate.instant('NSG_SIS_QUOTATION.LEARNERS_EXCEEDS'));
- return;
- }
- if(delegateAlreadyPresent(elem) && (!copy || copy==null)){
- dialogPop($translate.instant('NSG_SIS_QUOTATION.DELEGATE.ALREADY_PRESENT'));
- return;
- }
- //element filling
- elem.added = true;
- elem.delegateId = null;
- elem.deleted = false;
- // adding to list
- $scope.quotationDelegatesList.push(angular.copy(elem));
- $scope.quotationDelegatesConfigTableParams =
- new NgTableParams({
- page: 1,
- count: 10
- }, {
- dataset: $scope.quotationDelegatesList
- });
- $scope.quotationDelegatesConfigTableParams.reload();
- //Resetting form
- $scope.cancelDelegateCreation();
- }
- $scope.removeDelegate = function(elem) {
- elem.deleted = true;
- }
- $scope.createDelegate = function() {
- $scope.addingDelegate = true;
- }
- $scope.getInitials = function(names){
- var names= names.split(' ');
- var initials="";
- for(var i=0;i<names.length;i++){
- names[i].replace(/\s+/g, '');
- initials = initials + names[i].substring(0,1).toUpperCase();
- }
- $scope.delegateDetails.initials = initials;
- }
- $scope.cancelDelegateCreation = function(){
- $scope.addingDelegate = false;
- $scope.searchFilter = {};
- }
- $scope.addFromCase = function() {
- if($scope.quotationDelegatesList.length + $scope.foundDelegatesList.length > $scope.courseDetails.noOfTrainee) {
- dialogPop($translate.instant('NSG_SIS_QUOTATION.LEARNERS_EXCEEDS'));
- } else{
- $scope.loader = true;
- //Copying list elements
- var terminated = false;
- var i = 0;
- for(i=0; i<$scope.foundDelegatesList.length; i++){
- if(i==$scope.foundDelegatesList.length -1 )
- //Stop loader
- $scope.addDelegate($scope.foundDelegatesList[i], true);
- else
- //Do not stop loader
- $scope.addDelegate($scope.foundDelegatesList[i], true);
- }
- }
- }
- $scope.getRaces = function() {
- QuotationService.getRaces()
- .then(
- function(response) {
- $scope.racesList = response;
- $scope.loader = false;
- }, function(errResponse) {
- $scope.loader = false;
- }
- );
- }
- $scope.getQualifications = function() {
- QuotationService.getQualifications()
- .then(
- function(response) {
- $scope.qualificationsList = response;
- $scope.loader = false;
- }, function(errResponse) {
- $scope.loader = false;
- }
- );
- }
- $scope.getQuotationDelegates = function(quotationId) {
- var filter = {};
- filter.idcase = quotationId;
- QuotationService.getDelegatesList(filter)
- .then(
- function(response) {
- $scope.quotationDelegatesList = response;
- $scope.quotationDelegatesConfigTableParams =
- new NgTableParams({
- page: 1,
- count: 10
- }, {
- dataset: $scope.quotationDelegatesList
- });
- $scope.quotationDelegatesConfigTableParams.reload();
- $scope.loader = false;
- }, function(errResponse) {
- $scope.foundDelegatesList = [];
- $scope.loader = false;
- }
- );
- }
- $scope.showDelegateDetails = function(delegate) {
- var message = "";
- var name= "";
- var surname = "";
- if(delegate.firstName != null && delegate.firstName != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.NAME')+": "+delegate.firstName+"<br />";
- name = delegate.firstName;
- }
- if(delegate.surname != null && delegate.surname != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.SURNAME')+": "+delegate.surname+"<br />";
- surname = delegate.surname;
- }
- if(delegate.idNumber != null && delegate.idNumber != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.ID')+": "+delegate.idNumber+"<br />";
- }
- if(delegate.persalNumber != null && delegate.persalNumber != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.PERSAL')+": "+delegate.persalNumber+"<br />";
- }
- if(delegate.qualificationId != null && delegate.qualificationId != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.QUALIFICATION')+": "+getQualificationById(delegate.qualificationId)+"<br />";
- }
- if(delegate.rank != null && delegate.rank != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.RANK')+": "+delegate.rank+"<br />";
- }
- if(delegate.gender != null && delegate.gender != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.GENDER')+": "+getGenderById(delegate.gender)+"<br />";
- }
- if(delegate.raceId != null && delegate.raceId != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.RACE')+": "+getRaceById(delegate.raceId)+"<br />";
- }
- if(delegate.disability != null && delegate.disability != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.DISABILITY')+": "+delegate.disability+"<br />";
- }
- if(delegate.email != null && delegate.email != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.EMAIL')+": "+delegate.email+"<br />";
- }
- if(delegate.telephone != null && delegate.telephone != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.TELEPHONE_NUMBER')+": "+delegate.telephone+"<br />";
- }
- if(delegate.cellPhone != null && delegate.cellPhone != ""){
- message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.CELLULAR_NUMBER')+": "+delegate.cellPhone+"<br />";
- }
- $mdDialog.show(
- $mdDialog.alert()
- .clickOutsideToClose(true)
- .title(name+" "+surname)
- .htmlContent(message)
- .ariaLabel("Label")
- .ok($translate.instant('NSG_SIS_OK'))
- );
- }
- function getQualificationById(id){
- for(var i in $scope.qualificationsList){
- if($scope.qualificationsList[i].qualificationId == id) return $scope.qualificationsList[i].qualName;
- }
- return null;
- }
- function getRaceById(id) {
- for(var i in $scope.racesList){
- if($scope.racesList[i].raceId == id) return $scope.racesList[i].race;
- }
- return null;
- }
- function getGenderById(id){
- if(id == 1) return "Male";
- if(id == 2) return "Female";
- }
- function getFileNameFromHttpResponse(httpResponse) {
- var contentDispositionHeader = httpResponse.headers('Content-Disposition');
- var result = contentDispositionHeader.split(';')[1].trim().split('=')[1];
- return result.replace(/"/g, '');
- };
- $scope.saveTentativeBooking = function() {
- var calls = 0;
- var i = 0;
- $scope.loader = true;
- $scope.errs = false;
- for(i = 0; i<$scope.quotationDelegatesList.length; i++) {
- $scope.quotationDelegatesList[i].dataId = $scope.quotation.id;
- //se il delegate non era già in lista e non è stato cancellato, salva
- if($scope.quotationDelegatesList[i].delegateId == null && $scope.quotationDelegatesList[i].deleted == false) {
- console.log($scope.quotationDelegatesList[i]);
- QuotationService.saveDelegate($scope.quotation.id, $scope.quotationDelegatesList[i])
- .then(
- function(response) {
- }, function(errResponse) {
- console.error("Risposta negativa");
- $scope.errs = true;
- }
- );
- }
- //se il delegate era già in lista ed è stato cancellato, rimuovi
- if($scope.quotationDelegatesList[i].delegateId != null && $scope.quotationDelegatesList[i].deleted == true){
- console.log("Devo cancellare roba");
- QuotationService.removeDelegate($scope.quotationDelegatesList[i].delegateId)
- .then(function(response) {
- $scope.quotationDelegatesList.splice(i, 1);
- }, function(errResponse) {
- $scope.errs = true;
- }
- );
- }
- }
- $timeout($scope.saveTentativeBookingCall, 5000);
- }
- $scope.saveTentativeBookingCall = function () {
- if(!$scope.errs) {
- var data = {};
- data.id = $scope.quotation.id;
- data.calendarId = $scope.calendarIdSelected;
- data.groupNo = $scope.quotation.groupNo;
- data.bookingType = $scope.quotation.groupNo; //bookingType == groupNo
- data.orderNumber = $scope.quotation.orderNumber;
- data.comments = $scope.quotation.comments;
- data.description = $scope.quotation.description;
- // calls: numero di chiamate a saveDelegate (per sapere quando sono finite)
- QuotationService.saveTentativeBooking(data)
- .then(
- function(response) {
- dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_SUCCESS'));
- $location.path( "/nsgsisfe/cco/manage-quotations" );
- $scope.editMode = false;
- $scope.getUserQuotations();
- $scope.loader = false;
- }, function(errResponse) {
- dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_ERROR'));
- $scope.loader = false;
- }
- );
- }
- else {
- dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_ERROR'));
- $scope.loader = false;
- }
- }
- $scope.submitTentativeBooking = function() {
- $scope.loader = true;
- var data = {};
- data.id = $scope.quotation.id;
- data.calendarId = $scope.calendarIdSelected;
- data.groupNo = $scope.quotation.groupNo;
- data.bookingType = $scope.quotation.groupNo; //bookingType == groupNo
- data.orderNumber = $scope.quotation.orderNumber;
- data.comments = $scope.quotation.comments;
- data.description = $scope.quotation.description;
- QuotationService.submitTentativeBooking(data)
- .then(
- function(response) {
- $scope.loader = false;
- dialogPop($translate.instant('NSG_SIS_QUOTATION.TENTATIVE_BOOKING_SUCCESS'));
- $location.path( "/nsgsisfe/cco/manage-quotations" );
- $scope.editMode = false;
- $scope.getUserQuotations();
- }, function(errResponse) {
- dialogPop($translate.instant('NSG_SIS_QUOTATION.TENTATIVE_BOOKING_ERROR'));
- $scope.loader = false;
- }
- );
- }
- $scope.isValidIdNumber = function(idNumber) {
- var ex = /^(((\d{2}((0[13578]|1[02])(0[1-9]|[12]\d|3[01])|(0[13456789]|1[012])(0[1-9]|[12]\d|30)|02(0[1-9]|1\d|2[0-8])))|([02468][048]|[13579][26])0229))(( |-)(\d{4})( |-)(\d{3})|(\d{7}))/;
- return ex.test(idNumber);
- }
- function delegateAlreadyPresent(elem) {
- for(var i=0; i<$scope.quotationDelegatesList; i++){
- if(elem.idNumber == $scope.quotationDelegatesList[i].idNumber ||
- elem.persalNumber == $scope.quotationDelegatesList[i].persalNumber)
- return true;
- }
- return false;
- }
- $scope.cancel = function() {
- $scope.editMode = false;
- $scope.loader = true;
- $scope.getLastQuotations();
- $scope.foundDelegatesList = [];
- $scope.quotationDelegatesList = [];
- $scope.searchFilter = {};
- }
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement