existing-report.component.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import { ToastrService } from 'ngx-toastr';
  2. import { AuthServiceService } from './../../../shared/auth-service.service';
  3. import { HttpClient } from '@angular/common/http';
  4. import { ActivatedRoute } from '@angular/router';
  5. import { Component, OnInit } from '@angular/core';
  6. import { NgxSpinnerService } from 'ngx-spinner';
  7. @Component({
  8. selector: 'app-existing-report',
  9. templateUrl: './existing-report.component.html',
  10. styleUrls: ['./existing-report.component.css']
  11. })
  12. export class ExistingReportComponent implements OnInit {
  13. constructor(private route: ActivatedRoute,
  14. private authSer: AuthServiceService,
  15. private toastr: ToastrService,
  16. private spinner: NgxSpinnerService,
  17. private http: HttpClient) { }
  18. vehicle_types: any[] =[];
  19. vehicle_models: any[]=[];
  20. vehiclesData: any[] = [];
  21. vehicleTypeId: number;
  22. vehicleModelId:number;
  23. showTableData:boolean = false;
  24. ngOnInit() {
  25. //init the values of permision boolean
  26. this.authSer.showAddBtn = false;
  27. this.authSer.showDeleteBtn = false;
  28. this.authSer.showEditBtn = false;
  29. //show / hide notification search in header
  30. this.authSer.notificationLogin = true;
  31. this.authSer.showSearchHeader = false;
  32. this.authSer.showHeaderLogin = false;
  33. this.authSer.showHeaderDashBoard = true;
  34. this.authSer.showDashboardHeader = true;
  35. this.authSer.internalHeader = false;
  36. localStorage.setItem('pageIdActive', '48');
  37. //get vehicles types
  38. this.http.get(this.authSer.pathApi + '/get_vehicle_types_list').subscribe(
  39. (response) => {
  40. console.log(response);
  41. this.vehicle_types = response['types'];
  42. },
  43. (error) => {
  44. console.log(error);
  45. });
  46. }
  47. //change type vehicle
  48. typeVehicle(event) {
  49. console.log(event.target.value);
  50. this.vehicleTypeId = event.target.value;
  51. this.http.get(this.authSer.pathApi + '/get_vehicle_models_by_type_id/' + this.vehicleTypeId).subscribe(
  52. (responce) => {
  53. console.log('models vehicle', responce);
  54. this.vehicle_models = responce['models'];
  55. if(this.vehicle_models.length == 0) {
  56. this.toastr.warning('لا يوجد موديلات لهذا النوع حاليا ');
  57. }
  58. },
  59. (error) => {
  60. console.log(error);
  61. }
  62. );
  63. };
  64. //get report when change model
  65. getReport(event) {
  66. this.spinner.show();
  67. console.log(event.target.value);
  68. this.vehicleModelId = event.target.value;
  69. this.http.get(this.authSer.pathApi + '/report_existing_vehicles/' + this.vehicleTypeId + '/' + this.vehicleModelId + '/all').subscribe(
  70. (responce) => {
  71. console.log('report data ', responce);
  72. this.vehiclesData = responce['vehicles'];
  73. if(this.vehiclesData.length > 0) {
  74. this.showTableData = true;
  75. } else {
  76. this.showTableData = false;
  77. }
  78. this.spinner.hide();
  79. },
  80. (error) => {
  81. console.log(error);
  82. }
  83. );
  84. }
  85. //fillter data
  86. getFillter(event) {
  87. console.log(event.target.value);
  88. this.spinner.show();
  89. this.http.get(this.authSer.pathApi
  90. + '/report_existing_vehicles/'
  91. + this.vehicleTypeId + '/'
  92. + this.vehicleModelId
  93. + '/' + event.target.value).subscribe(
  94. (responce) => {
  95. this.vehiclesData = [];
  96. console.log(responce);
  97. this.vehiclesData = responce['vehicles'];
  98. if(this.vehiclesData.length == 0) {
  99. this.toastr.warning('لا يوجد بيانات لعرضها حاليا');
  100. }
  101. if(this.vehiclesData.length > 0) {
  102. this.showTableData = true;
  103. } else {
  104. this.showTableData = false;
  105. }
  106. this.spinner.hide();
  107. },
  108. (error) => {
  109. console.log(error);
  110. }
  111. )
  112. }
  113. //print function
  114. onPrint(): void {
  115. let printContents, popupWin;
  116. printContents = document.getElementById('print-section').innerHTML;
  117. popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
  118. popupWin.document.open();
  119. popupWin.document.write(`
  120. <html>
  121. <head>
  122. <title>تقرير المركبات الموجوده</title>
  123. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> </link>
  124. <style>
  125. .row{
  126. display: flex;
  127. flex-wrap: wrap;
  128. margin-right: -15px;
  129. margin-left: -15px;
  130. }
  131. .col-6{
  132. float: right;
  133. flex: 0 0 50%;
  134. max-width: 50%
  135. }
  136. .col-12{
  137. flex-basis: 0;
  138. flex-grow: 1;
  139. max-width: 100%;
  140. }
  141. table {
  142. font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  143. border-collapse: collapse;
  144. width: 100%;
  145. direction: rtl;
  146. text-align: center;
  147. }
  148. table td, table th {
  149. border: 1px solid #ddd;
  150. padding: 8px;
  151. }
  152. table tr:nth-child(even){background-color: #f2f2f2;}
  153. table tr:hover {background-color: #ddd;}
  154. table th {
  155. padding-top: 12px;
  156. padding-bottom: 12px;
  157. text-align: center;
  158. background-color: #4CAF50;
  159. color: white;
  160. }
  161. </style>
  162. </head>
  163. <body onload="window.print();window.close()">
  164. <div class="row">
  165. <div class="col-6">
  166. <img class="logo1" src="../../assets/image/logo2.png">
  167. </div>
  168. <div class="col-6" style="float: right">
  169. <img class="logo2" src="../../assets/image/logo1.png">
  170. </div>
  171. </div>
  172. <div class="row">
  173. <div class="col-12" style="width:100%;text-align: center">
  174. <h1>تقرير المركبات الموجوده</h1>
  175. </div>
  176. </div>
  177. <div class="row">
  178. <div class="col-12">
  179. ${printContents}
  180. </div>
  181. </div>
  182. </body>
  183. </html>`
  184. );
  185. popupWin.document.close();
  186. }
  187. }