Advertisement
Guest User

Untitled

a guest
Sep 10th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.74 KB | None | 0 0
  1. 'use strict';
  2.  
  3. /* Controllers - Quotation Controller */
  4.  
  5. angular.module('nsgsis').controller('QuotationController', ['$scope', 'NgTableParams', 'QuotationService','$translate', 'GeneralService','$mdDialog', '$location', '$timeout',
  6. function($scope, NgTableParams, QuotationService, $translate, GeneralService, $mdDialog, $location, $timeout) {
  7.  
  8. $scope.loader = false;
  9.  
  10. $scope.searchStringClientName = "";
  11. $scope.General = GeneralService;
  12.  
  13.  
  14. $scope.quotation = {};
  15. $scope.quotationId = null;
  16. $scope.quotationList = {};
  17. $scope.clientsList = {};
  18. $scope.co_ordinatorsList = {};
  19. $scope.clientContactsList = {};
  20. $scope.clientDetails = {};
  21. $scope.co_ordinatorsSelected = {};
  22. $scope.TypeList = [];
  23. $scope.courseDetails = {};
  24. $scope.clientSelectedContactsList = {};
  25. $scope.tariffList = {};
  26. $scope.tariffSelected = " ";
  27. $scope.courseItemsList = [];
  28. $scope.courseDeletedItemsList = [];
  29. $scope.costCentreItems= {};
  30. $scope.selectedCourseName = null;
  31. $scope.totalItems = 0;
  32. $scope.allItemsSaved = true;
  33. $scope.searchFilter = {};
  34. $scope.collapse = false;
  35. $scope.editMode = false;
  36. $scope.emptyDate = true;
  37. $scope.foundDelegatesList = [];
  38. $scope.quotationDelegatesList = [];
  39. $scope.addingDelegate = false;
  40. $scope.delegateDetails = {};
  41. $scope.copyCase = false;
  42. $scope.delegatesResultEnabled = false;
  43. $scope.racesList = [];
  44. $scope.qualificationsList = [];
  45. $scope.calendarList = [];
  46. $scope.calendarSelected = {};
  47.  
  48. $scope.userName = "user";
  49. $scope.pageSize = null;
  50. $scope.pageNumber = null;
  51.  
  52. $scope.username = "user";
  53. $scope.password = "password";
  54.  
  55.  
  56. // Restituisce la lista delle ultime 10 quotation dell'utente corrente
  57. $scope.getLastQuotations = function () {
  58. QuotationService.getUserToken($scope.username, $scope.password)
  59. .then(
  60. function(response) {
  61. $scope.loader = true;
  62. $scope.size = "10";
  63. QuotationService.getUserQuotations($scope.userName, $scope.size, $scope.searchFilter)
  64. .then(
  65. function(response) {
  66. $scope.quotationList = response;
  67. for (var i in response) {
  68. $scope.quotationList[i].quotationDate = new Date (response[i].quotationDate);
  69. $scope.quotationList[i].printStatus = getIconByStatus(String(response[i].status), String(response[i].subStatus));
  70. if($scope.quotationList[i].status == "20" && $scope.quotationList[i].subStatus == "0") {
  71. $scope.quotationList[i].classDeleted = "deleted";
  72. }
  73. }
  74. $scope.defaultConfigTableParams =
  75. new NgTableParams({
  76. page: 1,
  77. count: 10
  78. }, {
  79. counts: [],
  80. total: 1,
  81. dataset: $scope.quotationList
  82. });
  83. $scope.loader = false;
  84. },
  85. function(errResponse){
  86. $scope.quotationList = [];
  87. console.error("Error loading last quotations");
  88. $scope.loader = false;
  89. }
  90. );
  91. },
  92. function(errResponse){
  93. console.error("Error token");
  94. }
  95. );
  96. }
  97.  
  98.  
  99.  
  100. // Restituisce l'icona FA relativa allo stato della quotation
  101. function getIconByStatus(status, substatus) {
  102. var printStatus = {};
  103. $scope.ss = status + substatus;
  104. switch ($scope.ss) {
  105. case "30"://draft
  106. printStatus.iconName = "hourglass-start";
  107. printStatus.title = "NSG_SIS_QUOTATION.GENERATE";
  108. break;
  109. case "40"://submitted
  110. printStatus.iconName ="certificate";
  111. printStatus.title = "NSG_SIS_QUOTATION.AUTHORIZE";
  112. break;
  113. case "50"://authorized
  114. printStatus.iconName = "registered";
  115. printStatus.title = "NSG_SIS_QUOTATION.SUBMIT";
  116. break;
  117. case "60"://tentative booking (add calendar & delegates)
  118. printStatus.iconName = "calendar-alt";
  119. printStatus.title = "NSG_SIS_QUOTATION.TENTATIVE_BOOKING";
  120. break;
  121. case "61": case "62": case "63": case "64": case "65":
  122. printStatus.iconName = "money-bill-alt";
  123. break;
  124. case "70": case "71": case "72": case "73": case "74": case "75": case "76":
  125. printStatus.iconName = "clipboard-check";
  126. break;
  127. case "80": case "81": case "82":
  128. printStatus.iconName = "money-bill";
  129. case "90"://event completed
  130. printStatus.iconName = "calendar-check";
  131. break;
  132. case "91"://cancelled training
  133. printStatus.iconName = "ban";
  134. break;
  135. case "200"://cancelled quotation
  136. printStatus.iconName = "trash-alt";
  137. printStatus.title = "NSG_SIS_QUOTATION.DELETED";
  138. break;
  139. default://not found
  140. printStatus.iconName = null;
  141. break;
  142. }
  143. return printStatus;
  144. }
  145.  
  146. $scope.editQuotation = function(item) {
  147. $scope.editMode = true;
  148. $scope.info = {};
  149. $scope.info.clientInformation = false;
  150. $scope.info.contactDetails = false;
  151. $scope.info.pricesQuoted = false;
  152. $scope.getQualifications();
  153. $scope.getRaces();
  154. getQuotation(item.id);
  155. }
  156.  
  157. // Operazioni dopo la selezione del cliente
  158. $scope.selectedClientNameItemChanged = function (item) {
  159. if (item !== undefined && item.clientName !== undefined){
  160. $scope.selectedClientName = item.clientName;
  161. $scope.clientId = item.clientId;
  162. getClientDetails($scope.clientId);
  163. }
  164. // Clear fields
  165. if (item === undefined) {
  166. $scope.clientDetails = $scope.co_ordinatorsList = $scope.clientContactsList = {};
  167. $scope.postalress = $scope.streetAddress = "";
  168. $scope.clientSelectedContactsList = {};
  169. }
  170. }
  171.  
  172. $scope.selectedCourseNameItemChanged = function (item) {
  173. switch(item){
  174. case undefined:
  175. $scope.courseDetails = {};
  176. $scope.courseItemsList = [];
  177. $scope.selectedCourseName = null;
  178. $scope.allItemsSaved = true;
  179. $scope.emptyDate = true;
  180. break;
  181. default:
  182. if (item.courseNameFull !== undefined){
  183. $scope.selectedCourseName = item.courseNameFull;
  184. $scope.courseDetailsId = item.courseDetailsId;
  185. getCourseDetails($scope.courseDetailsId, null, false);
  186. }
  187. break;
  188. }
  189. }
  190.  
  191. // Restituisce il dettaglio del Client
  192. function getClientDetails(clientId,contactId) {
  193. $scope.loader = true;
  194. QuotationService.getClientDetails(clientId)
  195. .then(
  196. function(response) {
  197. $scope.clientDetails = response;
  198. loadClientType();
  199. $scope.co_ordinatorsList = response.clientContacts;
  200. $scope.clientContactsList = response.contacts;
  201. if ($scope.editMode) {
  202. $scope.co_ordinatorsSelected = String(contactId);
  203. $scope.insertCoordinator();
  204. $scope.calendarIdSelected = String($scope.quotation.calendarId);
  205. $scope.insertCalendar();
  206. }
  207. $scope.count = 0;
  208. $scope.postalAddress = "";
  209. $scope.streetAddress = "";
  210. $scope.clientDetails.typeName = "";
  211. if($scope.editMode)
  212. $scope.selectedClientName = $scope.clientDetails.clientName;
  213. for (var i in $scope.clientTypeList) {
  214. if ($scope.clientTypeList[i].typeId == $scope.clientDetails.type)
  215. $scope.clientDetails.typeName = $scope.clientTypeList[i].type;
  216. }
  217. for (var i in response.addresses) {
  218. $scope.count++;
  219. if($scope.count <= 5 && response.addresses[i] != null)
  220. $scope.postalAddress += response.addresses[i]+"\n";
  221. if($scope.count > 5 && response.addresses[i] != null)
  222. $scope.streetAddress += response.addresses[i]+"\n";
  223. }
  224. $scope.loader = false;
  225. },
  226. function(errResponse){
  227. $scope.loader = false;
  228. console.error("Error loading client details");
  229. }
  230. );
  231. }
  232.  
  233. function loadClientType() {
  234. GeneralService.loadClientType().then(
  235. function(response) {
  236. $scope.clientTypeList = response;
  237. }, function(errResponse) {
  238. console.error("Error loading client types");
  239. });
  240. }
  241.  
  242.  
  243. function getCalendar(courseId) {
  244. $scope.today = GeneralService.getTodayDate();
  245. QuotationService.getCalendar(courseId, $scope.today)
  246. .then(
  247. function(response) {
  248. $scope.calendarList = response;
  249. },
  250. function(errResponse){
  251. console.error("Error loading calendar details");
  252. }
  253. )
  254. }
  255.  
  256. // Valorizza i campi del co-ordinator selezionato
  257. $scope.insertCoordinator = function() {
  258. $scope.loader = true;
  259. for (var i in $scope.co_ordinatorsList) {
  260. if ($scope.co_ordinatorsList[i].id == $scope.co_ordinatorsSelected) {
  261. $scope.clientSelectedContactsList = $scope.co_ordinatorsList[i];
  262. if ($scope.co_ordinatorsList[i].designation == "1")
  263. $scope.clientSelectedContactsList.designationValue = "Departmental Coordinator";
  264. $scope.clientSelectedContactsList.postalAddress = "";
  265. $scope.clientSelectedContactsList.streetAddress = "";
  266. $scope.count = 0;
  267. for (var j in $scope.clientSelectedContactsList.addresses) {
  268. $scope.count++;
  269. if($scope.count <= 5 && $scope.clientSelectedContactsList.addresses[j] != null)
  270. $scope.clientSelectedContactsList.postalAddress += $scope.clientSelectedContactsList.addresses[j]+"\n";
  271. if($scope.count > 5 && $scope.clientSelectedContactsList.addresses[j] != null)
  272. $scope.clientSelectedContactsList.streetAddress += $scope.clientSelectedContactsList.addresses[j ]+"\n";
  273. }
  274. }
  275. }
  276. $scope.loader = false;
  277. }
  278.  
  279. // Valorizza i campi del calendar selezionato
  280. $scope.insertCalendar = function() {
  281. $scope.loader = true;
  282. for (var i in $scope.calendarList) {
  283. if ($scope.calendarList[i].calendarId == $scope.calendarIdSelected) {
  284. $scope.calendarSelected = $scope.calendarList[i];
  285. $scope.calendarSelected.fromDate = new Date ($scope.calendarSelected.fromDate);
  286. $scope.calendarSelected.toDate = new Date ($scope.calendarSelected.toDate);
  287. }
  288. }
  289. $scope.loader = false;
  290. }
  291.  
  292. //Restituisce il dettaglio del Course
  293. function getCourseDetails(courseId, quotationId, retrieveCourseList) {
  294. $scope.loader = true;
  295. QuotationService.getCourseDetails(courseId)
  296. .then(
  297. function(response) {
  298. $scope.courseDetails = response;
  299. if($scope.courseDetails.dateApproved!=null){
  300. $scope.emptyDate = false;
  301. $scope.courseDetails.dateApproved = new Date($scope.courseDetails.dateApproved);
  302. }else{
  303. $scope.emptyDate = true;
  304. }
  305.  
  306. if($scope.courseDetails.hasTariffGroup){
  307. QuotationService.getTariffGroups()
  308. .then(
  309. function(response) {
  310. $scope.tariffList= response;
  311. },
  312. function(errResponse){
  313. console.error("Error loading tariff details");
  314. }
  315. )
  316. }
  317.  
  318. if($scope.editMode)
  319. $scope.selectedCourseName = $scope.courseDetails.courseNameFull;
  320.  
  321. $scope.CourseItemConfigTableParams =
  322. new NgTableParams({
  323. page: 1,
  324. count: 10
  325. }, {
  326. counts: [],
  327. total: 1,
  328. dataset: $scope.courseItemsList
  329. });
  330. loadCostCentre();
  331. if($scope.editMode && retrieveCourseList){
  332. var index_list = 0;
  333. QuotationService.getQuotationCourseItemList(quotationId)
  334. .then(
  335. function(response) {
  336. $scope.courseItemsList= response;
  337. for(var i in $scope.courseItemsList){
  338. //Save max number of learners
  339. if($scope.courseItemsList[i].costCentreId==3){
  340. $scope.courseDetails.noOfTrainee = $scope.courseItemsList[i].noOfTrainee;
  341. $scope.courseItemsList[i].item = "course";
  342. }
  343. for(var j in $scope.costCentreItems){
  344. if($scope.courseItemsList[i].costCentreId==$scope.costCentreItems[j].costId){
  345. $scope.courseItemsList[i].item = $scope.costCentreItems[j].costCentre;
  346. }
  347. }
  348.  
  349. $scope.courseItemsList[i].saved = true;
  350. $scope.courseItemsList[i].item_old = $scope.courseItemsList[i].item;
  351. $scope.courseItemsList[i].coursePrice_old = $scope.courseItemsList[i].coursePrice;
  352. $scope.courseItemsList[i].total_old = $scope.courseItemsList[i].total;
  353. $scope.courseItemsList[i].noOfTrainee_old = $scope.courseItemsList[i].noOfTrainee;
  354. $scope.courseItemsList[i].index = index_list;
  355. $scope.courseItemsList[i].couresDetailsId = $scope.courseDetails.id;
  356. index_list++;
  357. $scope.courseItemsList[i].saved = true;
  358. }
  359. if($scope.courseItemsList.length > 0) {
  360. $scope.allItemsSaved = true;
  361. }
  362. else {
  363. $scope.allItemsSaved = false;
  364. $scope.courseItemsList=[{"item":"course", "noOfTrainee":"", "coursePrice":$scope.courseDetails.coursePrice, "total":"0", "saved":false, "index":0,
  365. "item_old":"course", "noOfTrainee_old":"", "total_old":0, "coursePrice_old":0}];
  366. }
  367. refreshTotal();
  368. },
  369. function(errResponse){
  370. console.error("Error loading course items list");
  371. }
  372. )
  373. }
  374. else {
  375. $scope.allItemsSaved = false;
  376. $scope.courseItemsList=[{"item":"course", "noOfTrainee":"", "coursePrice":$scope.courseDetails.coursePrice, "total":"0", "saved":false, "index":0,
  377. "item_old":"course", "noOfTrainee_old":"", "total_old":0, "coursePrice_old":0}];
  378. }
  379. $scope.loader = false;
  380. },
  381. function(errResponse){
  382. $scope.loader = false;
  383. console.error("Error loading course details");
  384. }
  385. );
  386. }
  387.  
  388. // Salva la quotation come bozza (stato 3-0)
  389. $scope.saveQuotation = function() {
  390. $scope.loader = true;
  391. $scope.quotation.clientId = $scope.clientDetails.id;
  392. $scope.quotation.clientContactId = $scope.clientSelectedContactsList.id;
  393. $scope.quotation.dataId = $scope.quotationId;
  394. $scope.quotation.courseDetailsId = $scope.courseDetails.id;
  395. $scope.quotation.courseQuotedList = $scope.courseItemsList;
  396. $scope.quotation.tariffId = parseInt($scope.tariffSelected);
  397. if($scope.courseDeletedItemsList.length > 0){
  398. for(var i in $scope.courseDeletedItemsList){
  399. QuotationService.deleteCourseItem($scope.courseDeletedItemsList[i]).then(
  400. function(response) {
  401. $scope.loader = false;
  402. }, function(errResponse) {
  403. $scope.loader = false;
  404. console.error("Error saving quotation");
  405. }
  406. );
  407. }
  408. }
  409.  
  410. for(var i in $scope.courseItemsList){
  411. if($scope.courseItemsList[i].costCentreId == 3) $scope.courseItemsList[i].coursePrice = null;
  412. }
  413.  
  414. QuotationService.saveQuotation($scope.quotation).then(
  415. function(response) {
  416. $scope.loader = false;
  417. dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_SUCCESS'));
  418. $location.path( "/nsgsisfe/cco/manage-quotations" );
  419. $scope.editMode = false;
  420. $scope.getUserQuotations();
  421. }, function(errResponse) {
  422. $scope.loader = false;
  423. console.error("Error saving quotation");
  424. dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_ERROR'));
  425. }
  426. );
  427. }
  428.  
  429. // Send della quotation (stato 3-0 to 4-0)
  430. $scope.submitQuotation = function() {
  431. console.log($scope.quotation);
  432. $scope.loader = true;
  433. $scope.quotation.clientId = $scope.clientDetails.id;
  434. $scope.quotation.clientContactId = $scope.clientSelectedContactsList.id;
  435. $scope.quotation.dataId = $scope.quotationId;
  436. $scope.quotation.courseDetailsId = $scope.courseDetails.id;
  437. $scope.quotation.courseQuotedList = $scope.courseItemsList;
  438.  
  439. for(var i in $scope.courseItemsList){
  440. if($scope.courseItemsList[i].costCentreId == 3) $scope.courseItemsList[i].coursePrice = null;
  441. }
  442.  
  443. QuotationService.submitQuotation($scope.quotation).then(
  444. function(response) {
  445. $scope.loader = false;
  446. dialogPop($translate.instant('NSG_SIS_QUOTATION.SUBMIT_SUCCESS'));
  447. $location.path( "/nsgsisfe/cco/manage-quotations" );
  448. $scope.editMode = false;
  449. $scope.getUserQuotations();
  450. }, function(errResponse) {
  451. $scope.loader = false;
  452. console.error("Error saving quotation");
  453. dialogPop($translate.instant('NSG_SIS_QUOTATION.SUBMIT_ERROR'));
  454. }
  455. );
  456. }
  457.  
  458. // Delete della quotation (stato 3-0 to 20-0)
  459.  
  460. $scope.selectedQuotationDelete = "";
  461.  
  462. $scope.deleteSelected = function (quotationId) {
  463. $scope.selectedQuotationDelete = quotationId;
  464. }
  465.  
  466. $scope.deleteQuotation = function(list) {
  467. $scope.loader = true;
  468. QuotationService.deleteQuotation($scope.selectedQuotationDelete).then(
  469. function(response) {
  470. $scope.loader = false;
  471. dialogPop($translate.instant('NSG_SIS_QUOTATION.DELETE_SUCCESS'));
  472. if(list == 'last')
  473. $scope.getLastQuotations();
  474. if(list == 'manage')
  475. $scope.getUserQuotations();
  476. }, function(errResponse) {
  477. $scope.loader = false;
  478. console.error("Error deleting quotation");
  479. dialogPop($translate.instant('NSG_SIS_QUOTATION.DELETE_ERROR'));
  480. }
  481. );
  482. }
  483.  
  484. function dialogPop(title, text) {
  485. $mdDialog.show(
  486. $mdDialog.alert()
  487. .parent(angular.element(document.querySelector('#popupContainer')))
  488. .clickOutsideToClose(true)
  489. .title(title)
  490. .textContent(text)
  491. .ok('OK')
  492. );
  493. }
  494.  
  495. $scope.refreshTariff = function() {
  496. QuotationService.getTariffedCourse($scope.courseDetails.id, $scope.tariffSelected)
  497. .then(
  498. function(response) {
  499. $scope.courseDetails.coursePrice = response.coursePrice;
  500. $scope.courseDetails.coursePrice = $scope.courseDetails.coursePrice.toFixed(2);
  501. $scope.courseDetails.pricePerpersonPerDay = response.coursePrice/response.courseDurationDays;
  502. $scope.courseDetails.courseDurationDays = response.courseDurationDays;
  503. $scope.courseDetails.dateApproved = response.dateApproved;
  504. },
  505. function(errResponse){
  506. console.error("Error loading Tariffed Course details");
  507. }
  508. );
  509. }
  510.  
  511. $scope.totalCourse = function(elem){
  512. elem.total=elem.noOfTrainee*elem.coursePrice;
  513. }
  514.  
  515. $scope.saveCourseItem = function(item) {
  516. if(item.coursePrice==undefined || item.coursePrice==null ||
  517. item.noOfTrainee=="" || item.noOfTrainee==null
  518. || item.item==undefined || item.item==""){
  519. return;
  520. }
  521.  
  522. if(item.coursePrice == undefined){
  523. item.coursePrice = 0;
  524. }
  525.  
  526. // Saving
  527. item.saved = true;
  528. $scope.allItemsSaved = true;
  529.  
  530. //Aggiornamento totale
  531. refreshTotal();
  532.  
  533. //shadow copy
  534. item.item_old=item.item;
  535. item.noOfTrainee_old=item.noOfTrainee;
  536. item.coursePrice_old=item.coursePrice;
  537.  
  538. // Aggiunta campi per save
  539. item.pricePerTrainee = item.coursePrice/item.noOfTrainee;
  540.  
  541. for (var i in $scope.costCentreItems){
  542. if($scope.costCentreItems[i].costCentre==item.item){
  543. item.costCentreId=$scope.costCentreItems[i].costId;
  544. }
  545. }
  546. item.couresDetailsId=$scope.courseDetails.id;
  547. item.fromDate=null;
  548. item.toDate=null;
  549. }
  550.  
  551. $scope.editCourseItem = function(item) {
  552. item.saved=false;
  553. $scope.allItemsSaved= false;
  554. }
  555.  
  556. $scope.deleteCourseItem = function(item) {
  557. if(item.item!='course'){
  558. $scope.courseItemsList.splice(item.index, 1);
  559. refreshTotal();
  560. }
  561. if(item.id!=null){
  562. $scope.courseDeletedItemsList.push(item.id);
  563. }
  564. }
  565.  
  566. $scope.newCostItem = function(){
  567. var allow=true;
  568. for(var i in $scope.courseItemsList){
  569. if ($scope.courseItemsList[i].saved == false) allow = false;
  570. }
  571. if(allow){
  572. $scope.allItemsSaved=false;
  573. $scope.courseItemsList.push({
  574. "item" : "",
  575. "learners" : "",
  576. "price": "",
  577. "total": "0",
  578. "saved": false,
  579. "index": $scope.courseItemsList.length,
  580. "item_old": "",
  581. "learners_old" : "",
  582. "price_old" : 0,
  583. "total_old" : 0
  584. });
  585. }
  586. else { // Altro item da salvare prima di crearne un altro
  587. dialogPop($translate.instant('NSG_SIS_QUOTATION.COURSE_COST_ITEMS.NEW_ERROR'));
  588. }
  589. }
  590.  
  591. //Prende gli items di Cost Centre
  592. function loadCostCentre() {
  593. QuotationService.getCostCentre()
  594. .then(
  595. function(response) {
  596. $scope.costCentreItems = response;
  597. },
  598. function(errResponse){
  599. console.error("Error loading cost centre items");
  600. }
  601. );
  602. }
  603.  
  604. // Annulla le modifiche di un oggetto di courseItemsList
  605. $scope.discardChanges= function(item){
  606. for (var i in $scope.courseItemsList){
  607. if($scope.courseItemsList[i].index==item.index){
  608. item.coursePrice=item.coursePrice_old;
  609. item.noOfTrainee=item.noOfTrainee_old;
  610. item.item=item.item_old;
  611. }
  612. }
  613. }
  614.  
  615. // Aggiorna il totale dei Course items (salvato in $scope.totalItems)
  616. function refreshTotal() {
  617. var count = 0;
  618. for (var i in $scope.courseItemsList){
  619. count += $scope.courseItemsList[i].total;
  620. }
  621. $scope.totalItems = count;
  622. }
  623.  
  624. // Restituisce la lista delle quotation dell'utente corrente
  625. $scope.getUserQuotations = function () {
  626. $scope.loader = true;
  627. $scope.size = null;
  628. QuotationService.getUserQuotations($scope.userName, $scope.size, $scope.searchFilter)
  629. .then(
  630. function(response) {
  631. $scope.quotationList = response;
  632. for (var i in response) {
  633. $scope.quotationList[i].quotationDate = new Date (response[i].quotationDate);
  634. $scope.quotationList[i].printStatus = getIconByStatus(String(response[i].status), String(response[i].subStatus));
  635.  
  636. if($scope.quotationList[i].status == "20" && $scope.quotationList[i].subStatus == "0") {
  637. $scope.quotationList[i].classDeleted = "deleted";
  638. }
  639. }
  640. $scope.defaultConfigTableParams =
  641. new NgTableParams({
  642. page: 1,
  643. count: 10
  644. }, {
  645. dataset: $scope.quotationList
  646. });
  647. $scope.loader = false;
  648. },
  649. function(errResponse){
  650. $scope.quotationList = [];
  651. console.error("Error loading quotations");
  652. $scope.loader = false;
  653. }
  654. );
  655. }
  656.  
  657.  
  658. function getQuotation(quotationId) {
  659. $scope.loader = true;
  660. $scope.quotationId = quotationId;
  661. QuotationService.getQuotation(quotationId)
  662. .then(
  663. function(response) {
  664. $scope.quotation = response;
  665. $scope.tariffSelected = String(response.tariffId);
  666. $scope.quotation.printStatus = getIconByStatus(String($scope.quotation.status), String($scope.quotation.subStatus));
  667. if($scope.quotation.clientId != null){
  668. getClientDetails($scope.quotation.clientId, $scope.quotation.clientContactId);
  669. }
  670. if($scope.quotation.courseDetailsId) {
  671. getCourseDetails($scope.quotation.courseDetailsId, $scope.quotationId, true);
  672. }
  673. if($scope.quotation.status>=6) {
  674. $scope.getQuotationDelegates($scope.quotation.id);
  675. getCalendar($scope.quotation.courseDetailsId);
  676. }
  677.  
  678.  
  679.  
  680. $scope.loader = false;
  681. },
  682. function(errResponse){
  683. console.error("Error loading last quotations");
  684. $scope.loader = false;
  685. }
  686. );
  687. }
  688.  
  689. $scope.declineQuotation = function () {
  690. $scope.loader = true;
  691. QuotationService.declineQuotation($scope.quotation.id, $scope.quotation.description, $scope.quotation.comments)
  692. .then(
  693. function(response) {
  694. dialogPop($translate.instant('NSG_SIS_QUOTATION.DECLINE_SUCCESS'));
  695. $scope.loader = false;
  696. $scope.getLastQuotations();
  697. $scope.editMode = false;
  698. },
  699. function(errResponse){
  700. dialogPop($translate.instant('NSG_SIS_QUOTATION.DECLINE_ERROR'));
  701. $scope.loader = false;
  702. }
  703. );
  704. }
  705.  
  706. $scope.approveQuotation = function () {
  707. $scope.loader = true;
  708. QuotationService.approveQuotation($scope.quotation.id, $scope.quotation.description, $scope.quotation.comments)
  709. .then(
  710. function(response) {
  711. $scope.loader = false;
  712. dialogPop($translate.instant('NSG_SIS_QUOTATION.APPROVE_SUCCESS'));
  713. $scope.getLastQuotations();
  714. $scope.editMode = false;
  715. },
  716. function(errResponse){
  717. dialogPop($translate.instant('NSG_SIS_QUOTATION.APPROVE_ERROR'));
  718. $scope.loader = false;
  719. }
  720. );
  721. }
  722.  
  723. $scope.submitQuotationToClient = function() {
  724. $scope.loader = true;
  725. QuotationService.submitQuotationToClient($scope.quotation.id, $scope.quotation.description, $scope.quotation.comments)
  726. .then(
  727. function(response) {
  728. $scope.loader = false;
  729. dialogPop($translate.instant('NSG_SIS_QUOTATION.SUBMIT_TO_CLIENT_SUCCESS'));
  730. $location.path( "/nsgsisfe/cco/manage-quotations" );
  731. $scope.editMode = false;
  732. $scope.getUserQuotations();
  733. }, function(errResponse) {
  734. $scope.loader = false;
  735. console.error("Error saving quotation");
  736. dialogPop($translate.instant('NSG_SIS_QUOTATION.SUBMIT_TO_CLIENT_ERROR'));
  737. }
  738. );
  739. }
  740.  
  741. $scope.reportQuotation = function (){
  742. $scope.loader = true;
  743. QuotationService.reportQuotation($scope.quotation.id)
  744. .then(
  745. function(response) {
  746. var a = document.createElement("a");
  747. document.body.appendChild(a);
  748. a.style = "display: none";
  749. var file = new Blob([response.data.data], {type: 'application/pdf'});
  750. var fileURL = window.URL.createObjectURL(file);
  751. a.href = fileURL;
  752. a.download = getFileNameFromHttpResponse(response);
  753. a.click();
  754. $scope.loader = false;
  755. },
  756. function(errResponse){
  757. $('#printModal').modal('hide');
  758. console.error("Error downloading document");
  759. dialogPop($translate.instant('NSG_SIS_REPORTS.DOWNLOAD_ERROR'));
  760. $scope.loader = false;
  761. }
  762. );
  763. }
  764.  
  765. $scope.reportBooking = function (){
  766. $scope.loader = true;
  767. QuotationService.reportBooking($scope.quotation.id)
  768. .then(
  769. function(response) {
  770. var a = document.createElement("a");
  771. document.body.appendChild(a);
  772. a.style = "display: none";
  773. var file = new Blob([response.data.data], {type: 'application/pdf'});
  774. var fileURL = window.URL.createObjectURL(file);
  775. a.href = fileURL;
  776. a.download = getFileNameFromHttpResponse(response);
  777. a.click();
  778. $scope.loader = false;
  779. },
  780. function(errResponse){
  781. $('#printModal').modal('hide');
  782. console.error("Error downloading document");
  783. dialogPop($translate.instant('NSG_SIS_REPORTS.DOWNLOAD_ERROR'));
  784. $scope.loader = false;
  785. }
  786. );
  787. }
  788.  
  789. $scope.getDelegatesList = function() {
  790. //if empty filter
  791. if(emptyDelegatesFilter($scope.searchFilter)){
  792. dialogPop($translate.instant('NSG_SIS_QUOTATION.EMPTY_SEARCH'));
  793. return;
  794. }
  795. $scope.delegatesResultEnabled = true;
  796. $scope.loader = true;
  797. $scope.copyCase = false;
  798. if(onlyCase($scope.searchFilter)) $scope.copyCase = true;
  799.  
  800. //Lista dei delegates appartenenti alla quotation
  801. $scope.quotationDelegatesConfigTableParams =
  802. new NgTableParams({
  803. page: 1,
  804. count: 10
  805. }, {
  806. dataset: $scope.quotationDelegatesList
  807. });
  808.  
  809. QuotationService.getDelegatesList($scope.searchFilter)
  810. .then(
  811. function(response) {
  812. $scope.foundDelegatesList = response;
  813. console.log(response);
  814. $scope.foundDelegatesConfigTableParams =
  815. new NgTableParams({
  816. page: 1,
  817. count: 10
  818. }, {
  819. dataset: $scope.foundDelegatesList
  820. });
  821. $scope.loader = false;
  822. $scope.foundDelegatesConfigTableParams.reload();
  823. }, function(errResponse) {
  824. $scope.foundDelegatesList = [];
  825. $scope.loader = false;
  826. }
  827. );
  828. }
  829.  
  830. function onlyCase(filter){
  831. if (filter.surname != undefined && filter.surname != null && filter.surname != "") {
  832. return false;
  833. }
  834.  
  835. if (filter.firstName != undefined && filter.firstName != null && filter.firstName != "") {
  836. return false;
  837. }
  838.  
  839. if (filter.persalNumber != undefined && filter.persalNumber != null && filter.persalNumber != "") {
  840. return false;
  841. }
  842.  
  843. if (filter.idNumber != undefined && filter.idNumber != null && filter.idNumber != "") {
  844. return false;
  845. }
  846.  
  847. if(filter.idcase != undefined && filter.idcase != null && filter.idcase != "")
  848. return true;
  849. else
  850. return false;
  851. }
  852.  
  853. function emptyDelegatesFilter(filter){
  854. if (filter.surname != undefined && filter.surname != null && filter.surname != "") {
  855. return false;
  856. }
  857.  
  858. if (filter.name != undefined && filter.name != null && filter.name != "") {
  859. return false;
  860. }
  861.  
  862. if (filter.persalNumber != undefined && filter.persalNumber != null && filter.persalNumber != "") {
  863. return false;
  864. }
  865.  
  866. if (filter.idNumber != undefined && filter.idNumber != null && filter.idNumber != "") {
  867. return false;
  868. }
  869.  
  870. if(filter.idcase != undefined && filter.idcase != null && filter.idcase != "")
  871. return false;
  872.  
  873. return true;
  874. }
  875.  
  876. $scope.addDelegate = function(elem, copy) {
  877.  
  878. if(elem.idNumber == null && elem.persalNumber == null && (!copy || copy==null)) {
  879. dialogPop($translate.instant('NSG_SIS_QUOTATION.DELEGATE.NULL_IDS'));
  880. }
  881.  
  882. if(elem.idNumber != null && !$scope.isValidIdNumber(elem.idNumber) && (!copy || copy==null)) {
  883. dialogPop($translate.instant('NSG_SIS_QUOTATION.DELEGATE.INVALID_ID'));
  884. return;
  885. }
  886.  
  887. if(copy && ($scope.quotationDelegatesList.length + $scope.foundDelegatesList.length > $scope.courseDetails.noOfTrainee)) {
  888. dialogPop($translate.instant('NSG_SIS_QUOTATION.LEARNERS_EXCEEDS'));
  889. return;
  890. }
  891. if((!copy || copy==null) && ($scope.quotationDelegatesList.length == $scope.courseDetails.noOfTrainee)){
  892. dialogPop($translate.instant('NSG_SIS_QUOTATION.LEARNERS_EXCEEDS'));
  893. return;
  894. }
  895.  
  896. if(delegateAlreadyPresent(elem) && (!copy || copy==null)){
  897. dialogPop($translate.instant('NSG_SIS_QUOTATION.DELEGATE.ALREADY_PRESENT'));
  898. return;
  899. }
  900.  
  901. //element filling
  902. elem.added = true;
  903. elem.delegateId = null;
  904. elem.deleted = false;
  905.  
  906. // adding to list
  907. $scope.quotationDelegatesList.push(angular.copy(elem));
  908. $scope.quotationDelegatesConfigTableParams =
  909. new NgTableParams({
  910. page: 1,
  911. count: 10
  912. }, {
  913. dataset: $scope.quotationDelegatesList
  914. });
  915. $scope.quotationDelegatesConfigTableParams.reload();
  916.  
  917. //Resetting form
  918. $scope.cancelDelegateCreation();
  919. }
  920.  
  921. $scope.removeDelegate = function(elem) {
  922. elem.deleted = true;
  923. }
  924.  
  925. $scope.createDelegate = function() {
  926. $scope.addingDelegate = true;
  927. }
  928.  
  929. $scope.getInitials = function(names){
  930. var names= names.split(' ');
  931. var initials="";
  932. for(var i=0;i<names.length;i++){
  933. names[i].replace(/\s+/g, '');
  934. initials = initials + names[i].substring(0,1).toUpperCase();
  935. }
  936. $scope.delegateDetails.initials = initials;
  937. }
  938.  
  939. $scope.cancelDelegateCreation = function(){
  940. $scope.addingDelegate = false;
  941. $scope.searchFilter = {};
  942. }
  943.  
  944. $scope.addFromCase = function() {
  945. if($scope.quotationDelegatesList.length + $scope.foundDelegatesList.length > $scope.courseDetails.noOfTrainee) {
  946. dialogPop($translate.instant('NSG_SIS_QUOTATION.LEARNERS_EXCEEDS'));
  947. } else{
  948. $scope.loader = true;
  949. //Copying list elements
  950. var terminated = false;
  951. var i = 0;
  952. for(i=0; i<$scope.foundDelegatesList.length; i++){
  953. if(i==$scope.foundDelegatesList.length -1 )
  954. //Stop loader
  955. $scope.addDelegate($scope.foundDelegatesList[i], true);
  956. else
  957. //Do not stop loader
  958. $scope.addDelegate($scope.foundDelegatesList[i], true);
  959. }
  960. }
  961. }
  962.  
  963. $scope.getRaces = function() {
  964. QuotationService.getRaces()
  965. .then(
  966. function(response) {
  967. $scope.racesList = response;
  968. $scope.loader = false;
  969. }, function(errResponse) {
  970. $scope.loader = false;
  971. }
  972. );
  973. }
  974.  
  975. $scope.getQualifications = function() {
  976. QuotationService.getQualifications()
  977. .then(
  978. function(response) {
  979. $scope.qualificationsList = response;
  980. $scope.loader = false;
  981. }, function(errResponse) {
  982. $scope.loader = false;
  983. }
  984. );
  985. }
  986.  
  987. $scope.getQuotationDelegates = function(quotationId) {
  988. var filter = {};
  989. filter.idcase = quotationId;
  990. QuotationService.getDelegatesList(filter)
  991. .then(
  992. function(response) {
  993. $scope.quotationDelegatesList = response;
  994. $scope.quotationDelegatesConfigTableParams =
  995. new NgTableParams({
  996. page: 1,
  997. count: 10
  998. }, {
  999. dataset: $scope.quotationDelegatesList
  1000. });
  1001. $scope.quotationDelegatesConfigTableParams.reload();
  1002. $scope.loader = false;
  1003. }, function(errResponse) {
  1004. $scope.foundDelegatesList = [];
  1005. $scope.loader = false;
  1006. }
  1007. );
  1008. }
  1009.  
  1010. $scope.showDelegateDetails = function(delegate) {
  1011.  
  1012. var message = "";
  1013. var name= "";
  1014. var surname = "";
  1015.  
  1016. if(delegate.firstName != null && delegate.firstName != ""){
  1017. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.NAME')+": "+delegate.firstName+"<br />";
  1018. name = delegate.firstName;
  1019. }
  1020. if(delegate.surname != null && delegate.surname != ""){
  1021. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.SURNAME')+": "+delegate.surname+"<br />";
  1022. surname = delegate.surname;
  1023. }
  1024. if(delegate.idNumber != null && delegate.idNumber != ""){
  1025. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.ID')+": "+delegate.idNumber+"<br />";
  1026. }
  1027. if(delegate.persalNumber != null && delegate.persalNumber != ""){
  1028. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.PERSAL')+": "+delegate.persalNumber+"<br />";
  1029. }
  1030. if(delegate.qualificationId != null && delegate.qualificationId != ""){
  1031. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.QUALIFICATION')+": "+getQualificationById(delegate.qualificationId)+"<br />";
  1032. }
  1033. if(delegate.rank != null && delegate.rank != ""){
  1034. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.RANK')+": "+delegate.rank+"<br />";
  1035. }
  1036. if(delegate.gender != null && delegate.gender != ""){
  1037. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.GENDER')+": "+getGenderById(delegate.gender)+"<br />";
  1038. }
  1039. if(delegate.raceId != null && delegate.raceId != ""){
  1040. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.RACE')+": "+getRaceById(delegate.raceId)+"<br />";
  1041. }
  1042. if(delegate.disability != null && delegate.disability != ""){
  1043. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.DISABILITY')+": "+delegate.disability+"<br />";
  1044. }
  1045. if(delegate.email != null && delegate.email != ""){
  1046. message = message + $translate.instant('NSG_SIS_QUOTATION.EMAIL')+": "+delegate.email+"<br />";
  1047. }
  1048. if(delegate.telephone != null && delegate.telephone != ""){
  1049. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.TELEPHONE_NUMBER')+": "+delegate.telephone+"<br />";
  1050. }
  1051. if(delegate.cellPhone != null && delegate.cellPhone != ""){
  1052. message = message + $translate.instant('NSG_SIS_QUOTATION.DELEGATE.CELLULAR_NUMBER')+": "+delegate.cellPhone+"<br />";
  1053. }
  1054.  
  1055. $mdDialog.show(
  1056. $mdDialog.alert()
  1057. .clickOutsideToClose(true)
  1058. .title(name+" "+surname)
  1059. .htmlContent(message)
  1060. .ariaLabel("Label")
  1061. .ok($translate.instant('NSG_SIS_OK'))
  1062. );
  1063. }
  1064.  
  1065. function getQualificationById(id){
  1066. for(var i in $scope.qualificationsList){
  1067. if($scope.qualificationsList[i].qualificationId == id) return $scope.qualificationsList[i].qualName;
  1068. }
  1069. return null;
  1070. }
  1071.  
  1072. function getRaceById(id) {
  1073. for(var i in $scope.racesList){
  1074. if($scope.racesList[i].raceId == id) return $scope.racesList[i].race;
  1075. }
  1076. return null;
  1077. }
  1078.  
  1079. function getGenderById(id){
  1080. if(id == 1) return "Male";
  1081. if(id == 2) return "Female";
  1082. }
  1083.  
  1084. function getFileNameFromHttpResponse(httpResponse) {
  1085. var contentDispositionHeader = httpResponse.headers('Content-Disposition');
  1086. var result = contentDispositionHeader.split(';')[1].trim().split('=')[1];
  1087. return result.replace(/"/g, '');
  1088. };
  1089.  
  1090. $scope.saveTentativeBooking = function() {
  1091. var calls = 0;
  1092. var i = 0;
  1093. $scope.loader = true;
  1094. $scope.errs = false;
  1095.  
  1096. for(i = 0; i<$scope.quotationDelegatesList.length; i++) {
  1097. $scope.quotationDelegatesList[i].dataId = $scope.quotation.id;
  1098. //se il delegate non era già in lista e non è stato cancellato, salva
  1099. if($scope.quotationDelegatesList[i].delegateId == null && $scope.quotationDelegatesList[i].deleted == false) {
  1100. console.log($scope.quotationDelegatesList[i]);
  1101. QuotationService.saveDelegate($scope.quotation.id, $scope.quotationDelegatesList[i])
  1102. .then(
  1103. function(response) {
  1104. }, function(errResponse) {
  1105. console.error("Risposta negativa");
  1106. $scope.errs = true;
  1107. }
  1108. );
  1109. }
  1110.  
  1111. //se il delegate era già in lista ed è stato cancellato, rimuovi
  1112. if($scope.quotationDelegatesList[i].delegateId != null && $scope.quotationDelegatesList[i].deleted == true){
  1113. console.log("Devo cancellare roba");
  1114. QuotationService.removeDelegate($scope.quotationDelegatesList[i].delegateId)
  1115. .then(function(response) {
  1116. $scope.quotationDelegatesList.splice(i, 1);
  1117. }, function(errResponse) {
  1118. $scope.errs = true;
  1119. }
  1120. );
  1121. }
  1122. }
  1123. $timeout($scope.saveTentativeBookingCall, 5000);
  1124. }
  1125.  
  1126. $scope.saveTentativeBookingCall = function () {
  1127. if(!$scope.errs) {
  1128. var data = {};
  1129. data.id = $scope.quotation.id;
  1130. data.calendarId = $scope.calendarIdSelected;
  1131. data.groupNo = $scope.quotation.groupNo;
  1132. data.bookingType = $scope.quotation.groupNo; //bookingType == groupNo
  1133. data.orderNumber = $scope.quotation.orderNumber;
  1134. data.comments = $scope.quotation.comments;
  1135. data.description = $scope.quotation.description;
  1136.  
  1137. // calls: numero di chiamate a saveDelegate (per sapere quando sono finite)
  1138.  
  1139. QuotationService.saveTentativeBooking(data)
  1140. .then(
  1141. function(response) {
  1142. dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_SUCCESS'));
  1143. $location.path( "/nsgsisfe/cco/manage-quotations" );
  1144. $scope.editMode = false;
  1145. $scope.getUserQuotations();
  1146. $scope.loader = false;
  1147. }, function(errResponse) {
  1148. dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_ERROR'));
  1149. $scope.loader = false;
  1150. }
  1151. );
  1152. }
  1153. else {
  1154. dialogPop($translate.instant('NSG_SIS_QUOTATION.SAVE_ERROR'));
  1155. $scope.loader = false;
  1156. }
  1157.  
  1158. }
  1159.  
  1160. $scope.submitTentativeBooking = function() {
  1161. $scope.loader = true;
  1162. var data = {};
  1163. data.id = $scope.quotation.id;
  1164. data.calendarId = $scope.calendarIdSelected;
  1165. data.groupNo = $scope.quotation.groupNo;
  1166. data.bookingType = $scope.quotation.groupNo; //bookingType == groupNo
  1167. data.orderNumber = $scope.quotation.orderNumber;
  1168. data.comments = $scope.quotation.comments;
  1169. data.description = $scope.quotation.description;
  1170. QuotationService.submitTentativeBooking(data)
  1171. .then(
  1172. function(response) {
  1173. $scope.loader = false;
  1174. dialogPop($translate.instant('NSG_SIS_QUOTATION.TENTATIVE_BOOKING_SUCCESS'));
  1175. $location.path( "/nsgsisfe/cco/manage-quotations" );
  1176. $scope.editMode = false;
  1177. $scope.getUserQuotations();
  1178. }, function(errResponse) {
  1179. dialogPop($translate.instant('NSG_SIS_QUOTATION.TENTATIVE_BOOKING_ERROR'));
  1180. $scope.loader = false;
  1181. }
  1182. );
  1183. }
  1184.  
  1185. $scope.isValidIdNumber = function(idNumber) {
  1186. 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}))/;
  1187. return ex.test(idNumber);
  1188. }
  1189.  
  1190. function delegateAlreadyPresent(elem) {
  1191. for(var i=0; i<$scope.quotationDelegatesList; i++){
  1192. if(elem.idNumber == $scope.quotationDelegatesList[i].idNumber ||
  1193. elem.persalNumber == $scope.quotationDelegatesList[i].persalNumber)
  1194. return true;
  1195. }
  1196. return false;
  1197. }
  1198.  
  1199. $scope.cancel = function() {
  1200. $scope.editMode = false;
  1201. $scope.loader = true;
  1202. $scope.getLastQuotations();
  1203. $scope.foundDelegatesList = [];
  1204. $scope.quotationDelegatesList = [];
  1205. $scope.searchFilter = {};
  1206. }
  1207. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement