import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, EventEmitter, Output, Input, ElementRef } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ControllerPrintRouteSheetServiceProxy } from '@shared/service-proxies/service-proxies'; import { AppSessionService } from '@shared/common/session/app-session.service'; import { Table } from "primeng/table"; import { LazyLoadEvent } from "primeng/primeng"; import { Paginator } from 'primeng/components/paginator/paginator'; import { finalize, repeat } from 'rxjs/operators'; import { Location } from '@angular/common'; import * as _ from 'lodash'; import * as jsPDF from 'jspdf' import html2canvas from 'html2canvas'; declare var $: any; declare var jquery: any; import * as moment from 'moment-timezone'; @Component({ selector: 'route-report', templateUrl: 'route-report.component.html', styleUrls: ['./route-sheet-laboratory.css'], encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], providers: [ControllerPrintRouteSheetServiceProxy] }) export class RouteReportComponent extends AppComponentBase implements OnInit { routeId: number = null; data: any; // data: Array []; @ViewChild("dataTable", { static: true }) dataTable: Table @ViewChild("paginator", { static: true }) paginator: Paginator @ViewChild('content', {static: false}) content: ElementRef localRouteIds = []; routeDate: Date routeDriver: string; routeName: string retrieving: boolean = false; timeId: any; constructor( injector: Injector, private id: ActivatedRoute, private _controllerPrintRouteDetails: ControllerPrintRouteSheetServiceProxy, private _location: Location, ) { super(injector); this.localRouteIds = JSON.parse(localStorage.getItem('routeIds')); if (this.localRouteIds.length == 0) { window.close(); } this.timeId = localStorage.getItem('timeZoneId'); moment.tz.setDefault(this.timeId); } ngOnInit() { this.getRouteDetails(); /*function printContent() { let popupWin = window.open('', '_blank', 'width=1080,height=595'); let printContents = document.getElementById("container-print").innerHTML; popupWin.document .write(` ${$('head').clone().html()}`); popupWin.document .write(`${printContents}`); popupWin.document .write(``); popupWin.document.close(); }*/ } printContent() { //let that = this; //this.spinnerService.show(); /* var data = document.getElementById('container-print'); var date = new Date();*/ /*const filename = 'ThisIsYourPDFFilename.pdf'; html2canvas(document.querySelector('#container-print')).then(canvas => { let pdf = new jsPDF('p', 'mm', 'a4'); let image_height = (211 / canvas.width) * canvas.height; pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0, 211, image_height); //pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0, 211, 298); pdf.save(filename); });*/ /*const filename = 'ThisIsYourPDFFilename.pdf'; html2canvas(data).then(canvas => { var imgWidth = 210; var pageHeight = 295; var imgHeight = (211 / canvas.width) * canvas.height; var heightLeft = imgHeight; //enter code here const imgData = canvas.toDataURL('image/png') var doc = new jsPDF('p', 'mm'); var position = 0; doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight+15); heightLeft -= pageHeight; while (heightLeft >= 0) { position = heightLeft - imgHeight; doc.addPage(); doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight + 15); heightLeft -= pageHeight; } doc.save(filename); this.spinnerService.hide(); });*/ /* const doc = new jsPDF(); const specialElementHandlers = { '#content': function (element, renderer) { return true; } }; const content = this.content.nativeElement; //console.log(this.content) doc.fromHTML(content.innerHTML, 15, 15, { width: 190, 'elementHandlers': specialElementHandlers }); doc.save('test.pdf');*/ let popupWin = window.open('', '_blank', 'width=1080,height=595'); let printContents = document.getElementById("content").innerHTML; popupWin.document .write(` ${$('head').clone().html()}`); popupWin.document .write(`${printContents}`); popupWin.document .write(``); popupWin.document.close(); } ngAfterViewInit() { } getTotal(array) { var data = array.map(i => i.quantity); data.reduce((a, b) => a + b, 0); return data; } getRouteDetails(event?: LazyLoadEvent) { let maxcount = 700 this.spinnerService.show(); this.retrieving = false; this._controllerPrintRouteDetails.getPrintRoute(this.localRouteIds).subscribe(result => { this.data = result; this.routeDate = new Date(result[0]['routeList'][0]['loadDate'].toString()); this.routeName = result[0]['routeList'][0]['routeCode'] this.routeId = result[0].routeId; this.retrieving = true; }); } onShown() { } ConvertToInt(val) { return parseInt(val); } goBack() { this._location.back(); } isOdd(num) { let value = num % 2; if(value == 0) { return false; } else { return true; } } }