import { Component, Injector, OnInit, ViewChild, ViewEncapsulation, EventEmitter, Output, Input } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { ControllerRouteDetailServiceProxy, ShippingPackageServiceProxy, ControllerScheduleDetailDto, GetCompaniesListItemDto, OrderPackageListDto, OrderStatusAttachmentServiceProxy, UpdateOrderSorting, UpdateOrderSortingInput, UpdateRouteTemplateAddressSorting, RouteTemplateAddressServiceProxy, RemoveOrderInput, RemoveOrderList, OrderServiceProxy, LockedOrderInput, ControllerPrintRouteSheetServiceProxy, UpdateRouteInput, ControllerRouteServiceProxy, ControllerRouteSheetDto } 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'; declare var $: any; declare var jquery: any; import * as moment from 'moment-timezone'; @Component({ selector: 'route-sheet-laboratory', templateUrl: 'route-sheet-laboratory.component.html', styleUrls: ['./route-sheet-laboratory.css'], encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()], providers: [ControllerPrintRouteSheetServiceProxy] }) export class RouteSheetLaboratoryComponent extends AppComponentBase implements OnInit { routeId: number = null; packages: Array<{ id: number, name: string }> = new Array(); data: any; packageCount: Array<{ id: number, quantity: number }> = new Array(); filterText = ''; accountNoFilter: any; clinicFilter: any; advancedFiltersAreShown = false; now: Date; arrayNotes: Array = new Array(); dNote: string; resultCount: number; saving = false; newRemoveOrderInput: Array = []; sprintIds: Array<{}> = new Array(); sprintIdsList: any[]; checkAll: boolean; records: any; loadDate: Date; driverName: string = ""; routeCode: string = ""; route: UpdateRouteInput = new UpdateRouteInput(); vehicleName: string; locationName: string; routeSheet: ControllerRouteSheetDto[] = []; // data: Array []; @ViewChild("dataTable", { static: true }) dataTable: Table @ViewChild("paginator", { static: true }) paginator: Paginator newDto: ControllerScheduleDetailDto = new ControllerScheduleDetailDto(); newPackage: OrderPackageListDto = new OrderPackageListDto(); lockedEtaInput: LockedOrderInput = new LockedOrderInput(); packagesList: Array = new Array(); totalCount: any; flag = false; tbodyHolder: any; orderList: Array = []; routeTemplateAddressList: Array = []; timeId: any; localRouteIds = []; retrieving: boolean = false; public getRouteDetailFunction: Function; constructor( injector: Injector, private id: ActivatedRoute, private _controllerPrintRouteDetails: ControllerPrintRouteSheetServiceProxy, private _controllerRouteDetails: ControllerRouteDetailServiceProxy, private _controllerRoutePackages: ShippingPackageServiceProxy, 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); this.routeSheet.length = 1; } ngOnInit() { this.now = new Date(); 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}`); $('head').append(''); popupWin.document .write(``); popupWin.document.close(); } $('#btn').on('click', function () { printContent(); }); this.getLabPackages(); this.getRouteDetails(); } ngAfterViewInit() { } getLabPackages() { this.packages = []; this._controllerRoutePackages.getShippingPackage(undefined, undefined, undefined, undefined, undefined, undefined).subscribe(result => { result.items.forEach(element => { if (element.name !== 'Default') { this.packages.push(element); } }); }); } 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.getPrintRouteSheet(this.localRouteIds).subscribe(result => { for (let index = 0; index < result.length; index++) { if (result[index].orderList != undefined || result[index].orderList != null) { for (let index1 = 0; index1 < result[index].orderList.length && result[index].orderList.length != 0; index1++) { result[index].orderList[index1].eta = moment(result[index].orderList[index1].after).tz(localStorage.getItem('timeZoneId')).format('h:mm a'); result[index].orderList[index1].arriveTime = moment(result[index].orderList[index1].time).tz(localStorage.getItem('timeZoneId')).format('h:mm a'); } }else{ result[index].orderList = []; } if (result[index].willCallList != undefined || result[index].willCallList != null) { for (let index1 = 0; index1 < result[index].willCallList.length; index1++) { result[index].willCallList[index1].eta = moment(result[index].willCallList[index1].clinicAfter).tz(localStorage.getItem('timeZoneId')).format('h:mm a'); } } else { result[index].willCallList = []; } } if (result != null) { this.routeSheet = result; console.log(this.routeSheet); this.retrieving = true; this.spinnerService.hide(); } }); } onShown() { } ConvertToInt(val) { return parseInt(val); } goBack() { this._location.back(); } getDetails() { this._controllerRouteDetails.getControllerRouteDetail(this.routeId) .subscribe(result => { this.routeCode = result.routeTemplate.name; // if (result.vehicle) { // this.vehicleName = result.vehicle.user.name + " " + result.vehicle.user.surname; // } }); } }