application-for-housing.component.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import { NgxSpinnerService } from 'ngx-spinner';
  2. import { ActivatedRoute, Params, Router } from '@angular/router';
  3. import { Component, OnInit, ViewChild } from '@angular/core';
  4. import { NgForm } from '@angular/forms';
  5. import { ToastrService } from 'ngx-toastr';
  6. import { Location, formatDate } from '@angular/common';
  7. import { UserService } from 'src/app/shared/user.service';
  8. import { DashboardService } from 'src/app/shared/dashboard.service';
  9. import { HttpClient } from '@angular/common/http';
  10. import { AuthServiceService } from 'src/app/shared/auth-service.service';
  11. @Component({
  12. selector: 'app-application-for-housing',
  13. templateUrl: './application-for-housing.component.html',
  14. styleUrls: ['./application-for-housing.component.css']
  15. })
  16. export class ApplicationForHousingComponent implements OnInit {
  17. departmentUserLoginId: any;
  18. userLoginId: any;
  19. constructor(
  20. private route: ActivatedRoute,
  21. private http: HttpClient,
  22. private toastr: ToastrService,
  23. private dashBoardSer: DashboardService,
  24. private spiner: NgxSpinnerService,
  25. private location: Location,
  26. public authService: AuthServiceService,
  27. private userService: UserService,
  28. private router: Router
  29. ) { }
  30. subLocationList = [];
  31. checkSaveClick: boolean = false;
  32. bindingDateSplitStart;
  33. checked : boolean = false;
  34. pageId: number;
  35. uploaded: boolean = false;
  36. disabledVal: boolean = true;
  37. serviceId: number;
  38. userId: number = 0;
  39. search: any;
  40. reportVal:boolean = false;
  41. saveTherequist: boolean = false;
  42. whosend = '';
  43. applyForOther : boolean = false;
  44. showdetails : boolean = false;
  45. applyForOtherSearch: boolean =false;
  46. showSearch: boolean = false;
  47. send: boolean = true;
  48. searchValue = null;
  49. applyForm = {
  50. employee_id: null,
  51. files:[]
  52. };
  53. dataForm = {
  54. id_number: '',
  55. name : '',
  56. phoneNum: '',
  57. functional_number:'',
  58. email:''
  59. };
  60. files = [{
  61. title : null,
  62. file: null,
  63. file_type: null,
  64. nameFile: null,
  65. }];
  66. ngOnInit() {
  67. //init the values of permision boolean
  68. this.authService.showAddBtn = false;
  69. this.authService.showDeleteBtn = false;
  70. this.authService.showEditBtn = false;
  71. //show / hide notification search in header
  72. this.authService.notificationLogin = true;
  73. this.authService.showSearchHeader = false;
  74. this.authService.showHeaderLogin = false;
  75. this.authService.showHeaderDashBoard = true;
  76. this.authService.showDashboardHeader = true;
  77. this.authService.internalHeader = false;
  78. this.route.params.subscribe(
  79. (parmas: Params) => {
  80. this.pageId = +parmas['reportId'];
  81. localStorage.setItem('pageIdActive', parmas['reportId']);
  82. this.whosend = parmas['comefrom'];
  83. }
  84. );
  85. this.route.parent.params.subscribe(
  86. (params:Params) => {
  87. this.serviceId = params['serviceID'];
  88. this.userId = params['userID'];
  89. }
  90. );
  91. this.route.parent.params.subscribe(
  92. (params:Params) => {
  93. this.userLoginId = params['userID'];
  94. this.serviceId = params['serviceID'];
  95. })
  96. if(this.whosend == 'new'){
  97. this.http.get(this.authService.pathApi + '/profile').subscribe(
  98. res => {
  99. this.dataForm.id_number = res['user'].identity_number;
  100. this.dataForm.name = res['user'].name;
  101. this.dataForm.phoneNum = res['user'].phone;
  102. this.applyForm.employee_id = res['user'].id;
  103. console.log(this.applyForm.employee_id);
  104. this.dataForm.functional_number = res['user'].functional_number;
  105. this.dataForm.email = res['user'].email;
  106. console.log('dsf',res)
  107. this.showdetails = true;
  108. this.applyForOther = false;
  109. this.send = false;
  110. },
  111. (error) => {console.log(error)},
  112. );
  113. }else{
  114. this.showSearch = true;
  115. }
  116. if(this.whosend == 'new'){
  117. this.http.get(this.authService.pathApi + '/get_employee_request_status/' + this.userId).subscribe(
  118. res => {
  119. console.log('ser' , res);
  120. const status = res['status']
  121. if(status == 'employee already has an un finished request'){
  122. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'viewRequestsForTenant/' + this.userLoginId])
  123. this.toastr.warning('لديك طلب بالفعل ');
  124. }else if(status == "employee free to make new request"){
  125. }
  126. },
  127. err => {
  128. if(err.error.error == 'employee already has an un finished request'){
  129. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'viewRequestsForTenant/' + this.userLoginId])
  130. this.toastr.warning('لديك طلب بالفعل');
  131. }else if(err.error.error == "employee free to make new request"){
  132. }
  133. }
  134. );
  135. }
  136. if(this.whosend == 'Ad547'){
  137. this.applyForOtherSearch = true;
  138. }
  139. }
  140. plusImage() {
  141. this.files.push({
  142. title: null,
  143. file: null,
  144. file_type: null,
  145. nameFile: null,
  146. });
  147. console.log('files after plus ', this.files);
  148. }
  149. //delete row from table
  150. onDeleteRow(index:number) {
  151. this.files.splice(index , 1);
  152. console.log('files after delete ',this.files);
  153. }
  154. //change file
  155. onFileChanges(event, index:number) {
  156. console.log(event);
  157. console.log(index);
  158. this.uploaded = true;
  159. this.files[index].nameFile = event[0].name.substring(0,20) + '....';
  160. this.files[index].file = event[0].base64;
  161. this.files[index].file_type = event[0].type.split('/')[1];
  162. console.log(this.files);
  163. console.log('files after change ',this.files);
  164. }
  165. SearchOnUser(){
  166. const key = this.searchValue
  167. console.log(key);
  168. console.log('here');
  169. this.http.get(this.authService.pathApi + '/find_user/' + key ).subscribe(
  170. res => {
  171. console.log('user',res);
  172. if(res['user'] == null){
  173. this.showdetails = false;
  174. }else{
  175. this.dataForm.id_number = res['user'].identity_number;
  176. this.dataForm.name = res['user'].name;
  177. this.dataForm.phoneNum = res['user'].phone;
  178. this.applyForm.employee_id = res['user'].id;
  179. this.dataForm.functional_number = res['user'].functional_number;
  180. this.dataForm.email = res['user'].email;
  181. this.applyForOther = true;
  182. this.showdetails = true;
  183. this.http.get(this.authService.pathApi + '/get_employee_request_status/' + this.applyForm.employee_id).subscribe(
  184. res => {
  185. console.log('ser' , res);
  186. const status = res['status']
  187. if(status == 'employee free to make new request'){
  188. this.toastr.warning('لديه طلب بالفعل');
  189. this.applyForOther = false;
  190. this.showdetails = false;
  191. }
  192. },
  193. err => {
  194. console.log(err);
  195. }
  196. );
  197. }
  198. },
  199. err => {
  200. console.log(err);
  201. this.showdetails = false;
  202. }
  203. );
  204. // }
  205. }
  206. onSubmitted(){
  207. for (let i = 0; i < this.files.length; i++) {
  208. if(this.files[i].file_type){
  209. this.files[i].file_type = this.files[i].file_type.toLowerCase();
  210. }
  211. if(!this.files[i].file){
  212. this.files.splice(i , 1);
  213. }
  214. else if(!this.files[i].title){
  215. this.toastr.warning('ادخل عنوان الملف رقم ' + (i+1) );
  216. return 0;
  217. } else {
  218. delete this.files[i].nameFile;
  219. this.applyForm.files.push(this.files[i]);
  220. }
  221. }
  222. console.log(this.applyForm);
  223. this.http.post(this.authService.pathApi + '/add_housing_request' , this.applyForm )
  224. .subscribe(
  225. res => {
  226. console.log(res);
  227. this.toastr.success('تم حفظ الطلب ');
  228. // this.router.navigate(['/service/' + this.userId + '/' + this.serviceId + '/followCommunicationList/58']);
  229. this.location.back();
  230. },
  231. err => {
  232. console.log(err)
  233. this.toastr.error('حدث خطأ في الاتصال ');
  234. }
  235. );
  236. }
  237. }