import { Component, ElementRef, EventEmitter, HostListener, Input, NgZone, OnInit, Output, ViewChild } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { Router } from "@angular/router"; import { NgbCalendar, NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'; import { DataTableDirective } from 'angular-datatables'; import * as lodash from 'lodash'; import * as moment from 'moment'; import { Subject } from 'rxjs'; import { IArchiveContent, IArchiveOrders, ISingleArchiveOrders } from 'src/app/models/order-list/archive-content'; import { ArchivedOrder } from 'src/app/models/order-list/archive-order'; import { OrderList } from 'src/app/models/order-list/order'; import { DataTable } from 'src/app/models/shared/data-table/data-table'; import { CommonService } from 'src/app/services/common.service'; import { DashboardDataService } from 'src/app/services/dashboard/dashboard.service'; import { OrderListService } from 'src/app/services/order/order.service'; import { NgbDatepickerConfig } from '@ng-bootstrap/ng-bootstrap'; import { DatePipe } from '@angular/common'; import { NgSelectComponent } from '@ng-select/ng-select'; import { environment } from 'src/environments/environment'; import { CommonEnum } from 'src/app/models/common-enum'; @Component({ selector: 'datatable', templateUrl: './data-table.component.html', styleUrls: ['./data-table.component.css'] }) export class DataTableComponent implements OnInit { objectKeys = Object.keys; commonGridList: any; APIResponse: any; id: number = 0; pagingNo: number = 1; totalRecords: number = 0; lastPage: number = 0; pageLength: number = 25; sortOrder: boolean = true; stateSave: boolean = true; columnName: string = ''; searchText: string = ''; isLast: boolean = false; previousColName: string = ''; modelDataTable = new DataTable(); entries: string = 'Showing 0 to 0 of 0 entries'; totalpage: number = 0; page: number = 1; pageSize: number = 10; pageSizes = [10, 25, 50, 100]; selectedColumn: string = ''; displayIndex: string = ''; archiveSelectedMessage: string = ''; show: boolean = false; @Input() options; @Output() data: EventEmitter = new EventEmitter(); showModal: boolean = false; deleteModal; previewModal; dtOptions: any = {}; dtTrigger: Subject = new Subject(); @ViewChild(DataTableDirective) dtElement: DataTableDirective; @ViewChild('btnClose') btnClose: ElementRef; locationSearchData: String[] = []; markDisabled; currentDate: Date = new Date(); locationDataSource = []; @ViewChild('select1') select1Comp: NgSelectComponent; isbeingSearched: boolean = false; addressnumber: Array = sessionStorage.getItem('MapingCustomer').split(','); showPricingColumn: boolean = Number(sessionStorage.getItem(CommonEnum.ViewPricing)) == 0 ? false : true; constructor( public router: Router, private ngZone: NgZone, private common: CommonService, private service: OrderListService, private formBuilder: FormBuilder, private servicedata: DashboardDataService, private datePipe: DatePipe) { } state = { "data": null, gridData: null, "dateData": null } isListView = true; showDataRange = false; showOpenArchivedSelected: boolean = false; showUnArchivedSelected: boolean = false; isCheckedAll: boolean = false; select1: boolean = false; select2: boolean = false; select3: boolean = false; isCheckedAll1: boolean = false; IsSelect: boolean = false; checkeddata: any; isSelected: boolean = false; ArchiveOrdersinfo: IArchiveOrders[] = []; SingleArchiveinfos: ISingleArchiveOrders[] = []; ArchiveOrderForm: FormGroup; APIResponses: any; archivedOrder: IArchiveContent[]; CustomerNumber: string = ''; _paramId: number = 0; _paramPoId: string; getcustomernumber: string = sessionStorage.getItem('CustomerNumber'); getmapingcustomer: string = sessionStorage.getItem('MapingCustomer'); OpenOrderData: OrderList[]; getDashboard: string = sessionStorage.getItem('IsDashboard'); loggedInUserType: string = sessionStorage.getItem('UserType'); archiveorderList = new ArchivedOrder(); SingleArchiveinfo: ArchivedOrder[] = []; filterByShow = false; lstArchivedOrder: ArchivedOrder[] = []; index = new Array(); ResultData: any[]; UpdateDateAPIResponse: any; email: string = sessionStorage.getItem('Email'); foldername: string = '2021'; selectedFilterData: any = []; panelOpenState: boolean[] = []; model: NgbDateStruct; public isCollapsed = true; selectedDate: any; dates = [ { id: 1, name: 'This Week' }, { id: 2, name: 'Last 30 Days' }, { id: 3, name: 'Last 60 Days' }, { id: 4, name: 'Last 3 Months' }, { id: 5, name: 'LAst 6 Months' } ]; sortOrders: string[] = ["This Week", "Last 30 Days", "Last 60 Days", "Last 3 Months", "Last 6 Months"]; selectedSortOrder: string = "Date Range"; filterData = []; fromDate: any; toDate: any; isValidDate: number = 0; maxStartDate: any; maxEndDate: any; minStartDateasstring: any; maxEndDateasstring: any; minStartDate: any; toInputDate: any; ngOnInit(): void { sessionStorage.removeItem("filterSearchText"); sessionStorage.removeItem("filterSearchDate"); this.archiveSelectedMessage = "Are you sure you want to archive order(s)"; if (Boolean(Number(this.getDashboard))) { this.pagingNo = sessionStorage.getItem('DatatablePageNo') == 'null' || sessionStorage.getItem('DatatablePageNo') == null || Number(sessionStorage.getItem('DatatablePageNo')) == 0 ? 1 : Number(sessionStorage.getItem('DatatablePageNo')); this.sortOrder = sessionStorage.getItem('DatatableSortOrder') == 'null' || sessionStorage.getItem('DatatableSortOrder') == null ? true : Boolean(Number(sessionStorage.getItem('DatatableSortOrder'))); this.columnName = sessionStorage.getItem('DatatableColumnName') == 'null' || sessionStorage.getItem('DatatableColumnName') == null ? this.options.columnName : (sessionStorage.getItem('DatatableColumnName')); this.pageLength = sessionStorage.getItem('DatatablePagingNumber') == 'null' || sessionStorage.getItem('DatatablePagingNumber') == null || Number(sessionStorage.getItem('DatatablePagingNumber')) == 0 ? 25 : Number(sessionStorage.getItem('DatatablePagingNumber')); } else { this.pagingNo = sessionStorage.getItem('OrderDatatablePageNo') == 'null' || sessionStorage.getItem('OrderDatatablePageNo') == null || Number(sessionStorage.getItem('OrderDatatablePageNo')) == 0 ? 1 : Number(sessionStorage.getItem('OrderDatatablePageNo')); this.sortOrder = sessionStorage.getItem('OrderDatatableSortOrder') == 'null' || sessionStorage.getItem('OrderDatatableSortOrder') == null ? true : Boolean(Number(sessionStorage.getItem('OrderDatatableSortOrder'))); this.columnName = sessionStorage.getItem('OrderDatatableColumnName') == 'null' || sessionStorage.getItem('OrderDatatableColumnName') == null ? this.options.columnName : (sessionStorage.getItem('OrderDatatableColumnName')); this.pageLength = sessionStorage.getItem('OrderDatatablePagingNumber') == 'null' || sessionStorage.getItem('OrderDatatablePagingNumber') == null || Number(sessionStorage.getItem('OrderDatatablePagingNumber')) == 0 ? 25 : Number(sessionStorage.getItem('OrderDatatablePagingNumber')); } if (this.getDashboard == '1') { this.fillLastUpdateData(); } if (history.state.gridData == undefined) { this.fillGrid(); this.getFilterData(); } else { this.state = this.common.copy(history.state); this.filterData = this.common.copy(history.state.data); let locationDataCount = this.filterData.filter(d => { return d.group == "Location" && d.locationSearchData !== undefined && d.locationSearchData.length > 0; }) if (locationDataCount.length > 0) { this.locationSearchData = locationDataCount[0].locationSearchData; this.locationDataSource = locationDataCount[0].values; } this.changeFilter(); this.commonGridList = history.state.gridData; if (this.commonGridList != null && this.commonGridList?.length > 0) { if (this.options.page == 'GeoRegion') { this.commonGridList.map(i => i.toggleactive = false); } this.totalRecords = this.commonGridList[0].count; this.lastPage = Math.ceil(this.totalRecords / this.pageLength); this.getEntries(); this.dtTrigger.next(); } else { this.totalRecords = 0; this.entries = 'Showing 0 to 0 of 0 entries' } this.applyFilterGenerateQuery(); let obj = this.filterData.filter(d => { return d.group == "Brand"; }) if (obj.length > 0) { if (obj[0].values.length > 1) { if (this.router.url == '/dashboard/dashboard') { if (this.showPricingColumn) { this.common.options.columnHeader = { 'BRAND': 'Brand', 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'ORDERTOTAL': 'Order Total' } } else { this.common.options.columnHeader = { 'BRAND': 'Brand', 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items' } } } else { if (this.showPricingColumn) { this.common.options.columnHeader = { 'BRAND': 'Brand', 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'ORDERTOTAL': 'Order Total', 'SHIPTOADDRESS1': 'Delivery Address' } } else { this.common.options.columnHeader = { 'BRAND': 'Brand', 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'SHIPTOADDRESS1': 'Delivery Address' } } } } } else { if (this.router.url == '/dashboard/dashboard') { if (this.showPricingColumn) { this.common.options.columnHeader = { 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'ORDERTOTAL': 'Order Total' } } else { this.common.options.columnHeader = { 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items' } } } else { if (this.showPricingColumn) { this.common.options.columnHeader = { 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'ORDERTOTAL': 'Order Total', 'SHIPTOADDRESS1': 'Delivery Address' } } else { this.common.options.columnHeader = { 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'SHIPTOADDRESS1': 'Delivery Address' } } } } if ("dateData" in history.state && history.state.dateData !== null) { if (typeof history.state.dateData == "string") { this.selectedSortOrder = (history.state.dateData == "" ? "Date Range" : history.state.dateData); if (this.selectedSortOrder !== "" && this.selectedSortOrder !== "Date Range") { this.ChangeSortOrderGenerateQuery(history.state.dateData); } } else { this.selectedSortOrder = "Custom"; this.fromDate = history.state.dateData[0].fromDate; this.toDate = history.state.dateData[0].toDate; this.fromToDateGenerateQuery(); } } } const currentDate: Date = new Date(); this.minStartDateasstring = { year: currentDate.getFullYear() - 2, month: 1, day: 1 } this.minStartDate = { year: currentDate.getFullYear() - 2, month: 1, day: 1 }; this.maxStartDate = this.transformPickerDate(currentDate); this.maxEndDateasstring = this.transformPickerDate(currentDate); } transformPickerDate(_pickDate): { year: number; month: number; day: number; } { let _pickYear = 0; let _pickMonth = 0; let _pickDay = 0; if (_pickDate != undefined && _pickDate != "" && _pickDate != null) { _pickYear = Number(this.datePipe.transform(_pickDate, 'yyyy')); _pickMonth = Number(this.datePipe.transform(_pickDate, 'MM')); _pickDay = Number(this.datePipe.transform(_pickDate, 'dd')); return { year: _pickYear, month: _pickMonth, day: _pickDay } } else return null; } totalpages() { this.totalpage = Math.ceil(this.totalRecords / this.pageLength); } counter(i: number) { return new Array(i); } Pageselect(no: number) { this.pagingNo = no; if (sessionStorage.getItem("filterSearchText") !== null || sessionStorage.getItem("filterSearchDate") !== null) { this.fillFilteredGrid(); } else { this.fillGrid(); } } setPagingNo(page) { if (page == 'First') { this.pagingNo = 1 } else if (page == 'Previous') { this.pagingNo = this.pagingNo - 1; } else if (page == 'Next') { this.pagingNo = this.pagingNo + 1; } else { this.isLast = true; this.pagingNo = this.lastPage; } if (sessionStorage.getItem("filterSearchText") !== null || sessionStorage.getItem("filterSearchDate") !== null) { this.fillFilteredGrid(); } else { this.fillGrid(); } } fillGrid() { if (this.options.isHistory) { this.searchText = "AND " + this.options.historyFor; } this.modelBeforeSubmit(); this.common.GetGridList(this.modelDataTable, data => { this.APIResponse = data; this.commonGridList = this.APIResponse.objResponse.responseContent; if (this.commonGridList != null && this.commonGridList?.length > 0) { if (this.options.page == 'GeoRegion') { this.commonGridList.map(i => i.toggleactive = false); } this.totalRecords = this.commonGridList[0].count; this.lastPage = Math.ceil(this.totalRecords / this.pageLength); this.getEntries(); this.dtTrigger.next(); } else { this.totalRecords = 0; this.entries = 'Showing 0 to 0 of 0 entries' } }, (error) => { console.error('Error: ' + error); return error(error); }); } clear() { this.btnClose.nativeElement.click(); } handlePageChange(event) { this.page = Number(event); this.pagingNo = Number(event); this.fillGrid(); } fillLastUpdateData() { this.servicedata.getUpdateData(data => { this.UpdateDateAPIResponse = data; this.ResultData = this.UpdateDateAPIResponse.objResponse.responseContent; this.dtTrigger.next(); }, (error) => { console.error('Error: ' + error); return error(error); }); } getEntries() { if (this.totalRecords != 0) { let lastEntry = this.pagingNo * this.pageLength > this.totalRecords ? this.totalRecords : this.pageLength * this.pagingNo; let firstEntry = (lastEntry - this.pageLength + 1) < this.pagingNo * this.pageLength - this.pageLength + 1 ? this.pagingNo * this.pageLength - this.pageLength + 1 : (lastEntry - this.pageLength + 1); this.entries = "Showing " + firstEntry + " to " + lastEntry + " of " + this.totalRecords + " entries"; this.totalpages(); } else { this.entries = 'Showing 0 to 0 of 0 entries' } } modelBeforeSubmit() { this.modelDataTable.sortOrder = Boolean(this.sortOrder); this.modelDataTable.stateSave = true; this.modelDataTable.columnName = String(this.columnName); this.modelDataTable.isLast = Boolean(this.isLast); this.modelDataTable.pageLength = Number(this.pageLength); this.modelDataTable.pageNo = Number(this.pagingNo); this.modelDataTable.searchText = String(this.searchText); this.modelDataTable.tableName = String(this.options.tableName); this.modelDataTable.ROLEID = Number(sessionStorage.getItem('RoleID')); if (Boolean(Number(this.getDashboard))) { sessionStorage.setItem('DatatablePageNo', String(this.pagingNo)); sessionStorage.setItem('DatatableColumnName', String(this.columnName)); sessionStorage.setItem('DatatableSortOrder', this.sortOrder ? '1' : '0'); sessionStorage.setItem('DatatablePagingNumber', String(this.pageLength)); } else { sessionStorage.setItem('OrderDatatablePageNo', String(this.pagingNo)); sessionStorage.setItem('OrderDatatableColumnName', String(this.columnName)); sessionStorage.setItem('OrderDatatableSortOrder', this.sortOrder ? '1' : '0'); sessionStorage.setItem('OrderDatatablePagingNumber', String(this.pageLength)); } } editRecord(editId) { this.ngZone.run(() => this.navigateTo(this.options.path + editId)); } setId(recordId) { this.id = recordId; } pageLengthChange(pageLength) { this.pageLength = Number(pageLength); if ((this.pageLength * this.pagingNo) > this.totalRecords) { this.pagingNo = Math.ceil(this.totalRecords / pageLength); } this.page = Number(this.pagingNo); this.lstArchivedOrder = null; this.isSelected = false; this.showOpenArchivedSelected = false; /*this.stateSave = true;*/ if (sessionStorage.getItem("filterSearchText") !== null || sessionStorage.getItem("filterSearchDate") !== null) { this.fillFilteredGrid(); } else { this.fillGrid(); } } showDeleteModal(id) { this.showModal = true; this.deleteModal = { tableName: this.options.tableName, id: id } this.previewModal = ""; } showPreviewModal(data) { this.showModal = true; this.previewModal = { content: data.TableName, file: "", fileFormat: "" } this.deleteModal = ""; } actionAllSelected(event: any) { this.displayIndex = ''; if (event.checked) { this.showOpenArchivedSelected = true; this.isSelected = true; this.commonGridList.forEach((datas: any) => { let orderArchiveDetails: ArchivedOrder = { ARCHIVEID: 0, ORDERNAME: datas.ORDERNUMBER, ORDERNUMBER: datas.ORDERNUMBER, ORDERNUMBERS: null, ISARCHIVED: 1, ARCHIVEDDATE: '', CUSTOMERNUMBER: Number(datas.CUSTOMERNUMBER), JOB: 0, ORDERTYPE: datas.ORDERTYPE, ORDERDATE: datas.ORDERDATE, FOLDERNAME: '', PATH: '', ORDERARCHIVEFOLDERID: null, CUSTOMERPO: '', SHIPTOLOCATION: '', ITEMS: 0, ORDERTOTAL: '', SHIPTOADDRESS: '' }; this.index.push(datas.RNO); if (this.lstArchivedOrder == null || this.lstArchivedOrder == undefined) this.lstArchivedOrder = []; this.lstArchivedOrder.push(orderArchiveDetails); this.archiveSelectedMessage = "Are you sure you want to archive selected order(s) of current page"; this.displayIndex = this.displayIndex + (this.displayIndex == '' ? '' : ', ') + orderArchiveDetails.ORDERNUMBER; }); } else { this.archiveSelectedMessage = "Are you sure you want to archive order(s)"; this.lstArchivedOrder = null; this.isSelected = false; this.showOpenArchivedSelected = false; } } showArchived(event: any, orders: any) { this.displayIndex = ''; if (event.checked) { let orderArchiveDetails: ArchivedOrder = { ARCHIVEID: 0, ORDERNUMBER: orders.ORDERNUMBER, ORDERNAME: orders.ORDERNUMBER, ORDERNUMBERS: null, ISARCHIVED: 1, ARCHIVEDDATE: '', CUSTOMERNUMBER: Number(orders.CUSTOMERNUMBER), JOB: 0, ORDERTYPE: orders.ORDERTYPE, ORDERDATE: orders.TRANSACTIONDATE, PATH: '', FOLDERNAME: '', ORDERARCHIVEFOLDERID: null, CUSTOMERPO: '', SHIPTOLOCATION: '', ITEMS: 0, ORDERTOTAL: '', SHIPTOADDRESS: '' }; this.index.push(orders.RNO); if (this.lstArchivedOrder == null || this.lstArchivedOrder == undefined) this.lstArchivedOrder = []; this.lstArchivedOrder.push(orderArchiveDetails); this.showOpenArchivedSelected = true; } else { this.lstArchivedOrder = this.lstArchivedOrder.filter(x => x.ORDERNUMBER != orders.ORDERNUMBER); if (this.lstArchivedOrder?.length == 0) this.showOpenArchivedSelected = false; } this.lstArchivedOrder.forEach(ArchivedOrder => this.displayIndex = this.displayIndex + (this.displayIndex == '' ? '' : ', ') + ArchivedOrder.ORDERNUMBER); } setFormBuilder() { this.ArchiveOrderForm = this.formBuilder.group({ ARCHIVEID: [''], ORDERNUMBER: [''], ORDERNUMBERS: [''], ISARCHIVED: [''], ARCHIVEDDATE: [''], CUSTOMERNUMBER: [''], JOB: [''], ORDERTYPE: [''], ORDERDATE: [''], }); } setAddForm() { this.ArchiveOrderForm.setValue({ ARCHIVEID: 0, ORDERNUMBER: 0, ORDERNUMBERS: 0, ISARCHIVED: 0, ARCHIVEDDATE: '', CUSTOMERNUMBER: this.getcustomernumber, JOB: '', ORDERTYPE: '', ORDERDATE: '', }); } setCustNo(id, ids) { this.service.customernumber = id; sessionStorage.setItem('CustomerNo', String(this.service.customernumber)); this.service.customerpo = ids; sessionStorage.setItem('CustomerPo', String(this.service.customerpo)); } ArchiveOpenOrders() { this.service.SingleArchiveOrderList(this.lstArchivedOrder, this.email, this.foldername, data1 => { this.APIResponses = data1; if (this.APIResponses.objResponse.statusCode == "200") { this.common.showSuccess("The order was successfully archived.", "Success") this.isSelected = false; this.router.navigateByUrl('order/order-list', { skipLocationChange: true }).then(() => { this.router.navigate(['order/order-list']); }); this.ngOnInit(); this.index.sort(); for (let i = this.index?.length - 1; i >= 0; i--) { this.commonGridList.splice(this.index[i] - 1, 1); } } else { this.common.showError("The order was not successfully archived.", "Archivedorder Fail") } }, (error) => { console.error('Error: ' + error); return error(error); }); } setOrder(columnName) { if (columnName != null && columnName != '') { this.show ? this.show = false : this.show = true; this.selectedColumn = columnName; this.previousColName = columnName; this.sortOrder = this.previousColName != columnName ? true : !this.sortOrder; this.columnName = columnName; this.stateSave = true; if (sessionStorage.getItem("filterSearchText") !== null || sessionStorage.getItem("filterSearchDate") !== null) { this.fillFilteredGrid(); } else { this.fillGrid(); } } } toggleClass(item) { item.toggleactive = !item.toggleactive; } previewRecord(data) { this.data = data.TableName; } navigateTo(url) { this.router.navigate([url]); } ClearDatatableSession() { sessionStorage.setItem('DatatablePageNo', '1'); sessionStorage.setItem('DatatableColumnName', null); sessionStorage.setItem('DatatableSortOrder', '1'); sessionStorage.setItem('DatatablePagingNumber', '25'); } // Filter Functions starts @HostListener('document:click', ['$event']) onGlobalClick(event): void { var element = document.getElementById("outsideClickDiv"); var isClickInsideElement = element.contains(event.target) || event.target.title == 'MinusIcon' || event.target.title == 'AddIcon' || event.target.title == 'arrow_drop_down' || lodash.includes(event.target.classList, 'ng-value-icon') || event.target.id == 'location'; if (!isClickInsideElement || event.target.title == 'arrow_drop_up') { this.panelOpenState = []; this.filterByShow = false; } } // Setting Accordion and Binding Data getFilterData() { var ShipToAddress = this.addressnumber; if (sessionStorage.getItem('GlobalSearchCustomerID') != undefined && sessionStorage.getItem('GlobalSearchCustomerID') != 'null' && sessionStorage.getItem('GlobalSearchCustomerID') != null) { ShipToAddress = []; ShipToAddress.push(sessionStorage.getItem('GlobalSearchCustomerID')); } if (Number(sessionStorage.getItem('GlobalSearchCustomerID')) > 0) { this.common.GetFilterData(Number(sessionStorage.getItem('GlobalSearchCustomerID')), sessionStorage.getItem('Email'), this.loggedInUserType, data => { Object.entries(data.objResponse).forEach(([key, value], index) => { let obj: any = {}; obj.group = (key == "TypeOfOrder" ? "Type Of Order" : key); obj.expand = false; obj.values = []; let groupByDataWithStatus = lodash.groupBy(JSON.parse(JSON.stringify(value)), 'Status'); let groupByDataWithTypeOfOrder = lodash.groupBy(JSON.parse(JSON.stringify(value)), 'TypeOfOrder'); let groupByDataWithLocation = lodash.groupBy(JSON.parse(JSON.stringify(value)), 'Location'); if (value) { JSON.parse(JSON.stringify(value)).forEach((i, ind) => { let ids: string = ""; if (key == "Brand") { if (this.loggedInUserType !== 'Admin' && this.loggedInUserType !== "") { i.Brand = i.BRAND; ids = i.BrandID; } else { if (this.common.BrandData.length > 0) { this.common.BrandData.forEach((bData, index) => { if (index == ind) { i.Brand = bData.BRAND; ids = bData.BrandID; } }) } } } else if (key == 'Status') { ids = lodash.uniq(lodash.map(groupByDataWithStatus[i[obj.group]], 'LastStatusId')).join(","); } else if (key == 'Location') { ids = lodash.uniq(lodash.map(groupByDataWithLocation[i[key]], 'locationid')).join(","); } else { ids = lodash.uniq(lodash.map(groupByDataWithTypeOfOrder[i[key]], 'BranchId')).join(","); } if (ids !== '') { obj.values.push({ "label": key, "value": lodash.trim(i[key]), "selected": false, ids: ids }) } }) } obj.values = lodash.uniqBy(obj.values, 'value'); if (obj.group == "Brand") { if (obj.values.length > 1) { obj.showAccordion = true; this.filterData.push(obj); if (this.router.url == '/dashboard/dashboard') { if (this.showPricingColumn) { this.common.options.columnHeader = { 'BRAND': 'Brand', 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'ORDERTOTAL': 'Order Total' } } else { this.common.options.columnHeader = { 'BRAND': 'Brand', 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items' } } } else { if (this.showPricingColumn) { this.common.options.columnHeader = { 'BRAND': 'Brand', 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'ORDERTOTAL': 'Order Total', 'SHIPTOADDRESS1': 'Delivery Address' } } else { this.common.options.columnHeader = { 'BRAND': 'Brand', 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'SHIPTOADDRESS1': 'Delivery Address' } } } } else { if (this.router.url == '/dashboard/dashboard') { if (this.showPricingColumn) { this.common.options.columnHeader = { 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'ORDERTOTAL': 'Order Total' } } else { this.common.options.columnHeader = { 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items' } } } else { if (this.showPricingColumn) { this.common.options.columnHeader = { 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'ORDERTOTAL': 'Order Total', 'SHIPTOADDRESS1': 'Delivery Address' } } else { this.common.options.columnHeader = { 'BRANCHNAME': 'Type of Order', 'CUSTOMERPO': 'PO #', 'ORDERNUMBER': 'Order #', 'TRANSACTIONDATE': 'Order Date', 'LASTSTATUSNAME': 'Status', 'REQUESTED_SHIPDATE': 'Expected to Ship', 'ACTUALSHIPDATE': 'Date Shipped', 'SHIPTOLOCATION': 'Location', 'ITEMS': '# Items', 'SHIPTOADDRESS1': 'Delivery Address' } } } } } else if (obj.group == "Location") { if (obj.values.length > 1) { if (obj.values.length <= 10 && obj.values.length > 1) { obj.showAccordion = true; this.filterData.push(obj); } else { obj.showAccordion = false; this.filterData.push(obj); } } } else { obj.showAccordion = true; this.filterData.push(obj); } }) // Sequence - Status -> TypeOfOrder -> Location -> Brand if (this.filterData.length == 4) { var brandData = this.common.copy(this.filterData[2]); this.filterData[2] = this.filterData[3]; this.filterData[3] = brandData; } var location = this.filterData.filter(d => { return d.group == "Location"; }) if (location.length > 0) { this.locationDataSource = location[0].values; } }, (error) => { console.error('Error: ' + error); return error(error); }); } } // On tick check box, calculating count changeFilter() { this.selectedFilterData = []; this.filterData.map(d => d.values).forEach(d => { let selectedValue = d.filter(e => { return e.selected == true; }) if (selectedValue.length > 0) { selectedValue.forEach(c => { this.selectedFilterData.push(c); }) } }); // when location is in text format, need to add count if (this.locationSearchData.length > 0) { this.locationSearchData.forEach(d => { this.selectedFilterData.push({ label: "" }) }) } } // Accordion Filter Apply applyFilter() { this.filterByShow = false; if (this.selectedFilterData.length > 0 || this.locationSearchData.length > 0 || sessionStorage.getItem("filterSearchText") !== null) { this.panelOpenState = []; sessionStorage.removeItem("filterSearchText"); var searchText = ""; // Status let statusData = lodash.filter(this.selectedFilterData, d => { return d.label == "Status"; }); let statusDataIds = lodash.map(statusData, 'ids'); let statusNames = lodash.map(statusData, 'value'); if (statusDataIds.length > 0) { searchText += "(last_status in (" + statusDataIds.join() + ") AND TRIM(laststatusname) in (" + '\'' + statusNames.join('\',\'') + '\'' + "))"; } // Type Of Order let typeOFOrderData = lodash.filter(this.selectedFilterData, d => { return d.label == "TypeOfOrder"; }); let typeOFOrderDataIds = lodash.map(typeOFOrderData, 'ids'); if (typeOFOrderDataIds.length > 0) { if (searchText !== "") { searchText += " and (TRIM(branch) in (" + typeOFOrderDataIds.join() + "))"; } else { searchText += "(TRIM(branch) in (" + typeOFOrderDataIds.join() + "))"; } } // Location // Multiselect if (this.locationSearchData.length > 0) { let locationSearchData = this.locationSearchData.map(name => name.toUpperCase()); if (searchText !== "") { searchText += " and (UPPER(TRIM(shiptolocation)) in (" + '\'' + locationSearchData.join('\',\'') + '\'' + "))"; } else { searchText += "(UPPER(TRIM(shiptolocation)) in (" + '\'' + locationSearchData.join('\',\'') + '\'' + "))"; } } // Check Box else { let locationData = lodash.filter(this.selectedFilterData, d => { return d.label == "Location"; }); let locationDataIds = lodash.map(locationData, 'ids'); if (locationDataIds.length > 0) { if (searchText !== "") { searchText += " and (shiptoaddress in (" + locationDataIds.join() + "))"; } else { searchText += "(shiptoaddress in (" + locationDataIds.join() + "))"; } } } // Brand let brandData = lodash.filter(this.selectedFilterData, d => { return d.label == "Brand"; }); let brandNames = lodash.map(brandData, 'value'); if (brandNames.length > 0) { if (searchText !== "") { searchText += " and (TRIM(brand) in (" + '\'' + brandNames.join('\',\'') + '\'' + "))"; } else { searchText += "(TRIM(brand) in (" + '\'' + brandNames.join('\',\'') + '\'' + "))"; } } if (searchText !== "") { sessionStorage.setItem("filterSearchText", searchText); this.pagingNo = 1; } this.fillFilteredGrid(); } } // Generating Query when Moved from one page to another applyFilterGenerateQuery() { this.filterByShow = false; if (this.selectedFilterData.length > 0 || this.locationSearchData.length > 0 || sessionStorage.getItem("filterSearchText") !== null) { this.panelOpenState = []; sessionStorage.removeItem("filterSearchText"); var searchText = ""; // Status let statusData = lodash.filter(this.selectedFilterData, d => { return d.label == "Status"; }); let statusDataIds = lodash.map(statusData, 'ids'); let statusNames = lodash.map(statusData, 'value'); if (statusDataIds.length > 0) { searchText += "last_status in (" + statusDataIds.join() + ") and TRIM(laststatusname) in (" + '\'' + statusNames.join('\',\'') + '\'' + ")"; } // Type Of Order let typeOFOrderData = lodash.filter(this.selectedFilterData, d => { return d.label == "TypeOfOrder"; }); let typeOFOrderDataIds = lodash.map(typeOFOrderData, 'ids'); if (typeOFOrderDataIds.length > 0) { if (searchText !== "") { searchText += " and TRIM(branch) in (" + typeOFOrderDataIds.join() + ")"; } else { searchText += "TRIM(branch) in (" + typeOFOrderDataIds.join() + ")"; } } // Location // Multiselect if (this.locationSearchData.length > 0) { let locationSearchData = this.locationSearchData.map(name => name.toUpperCase()); if (searchText !== "") { searchText += " and UPPER(TRIM(shiptolocation)) in (" + '\'' + locationSearchData.join('\',\'') + '\'' + ")"; } else { searchText += "UPPER(TRIM(shiptolocation)) in (" + '\'' + locationSearchData.join('\',\'') + '\'' + ")"; } } // Check box else { let locationData = lodash.filter(this.selectedFilterData, d => { return d.label == "Location"; }); let locationDataIds = lodash.map(locationData, 'ids'); if (locationDataIds.length > 0) { if (searchText !== "") { searchText += " and shiptoaddress in (" + locationDataIds.join() + ")"; } else { searchText += "shiptoaddress in (" + locationDataIds.join() + ")"; } } } // Brand let brandData = lodash.filter(this.selectedFilterData, d => { return d.label == "Brand"; }); let brandNames = lodash.map(brandData, 'value'); if (brandNames.length > 0) { if (searchText !== "") { searchText += " and TRIM(brand) in (" + '\'' + brandNames.join('\',\'') + '\'' + ")"; } else { searchText += "TRIM(brand) in (" + '\'' + brandNames.join('\',\'') + '\'' + ")"; } } if (searchText !== "") { sessionStorage.setItem("filterSearchText", searchText); } } } // Generating Query For Date When moved from one page to another ChangeSortOrderGenerateQuery(value: string) { sessionStorage.removeItem("filterSearchDate"); this.selectedSortOrder = value; let previousDate: any; var searchText = ""; if (value == "This Week") { previousDate = moment().subtract(1, 'week').format("DD-MM-YY"); } else if (value == "Last 30 Days") { previousDate = moment().subtract(1, "month").format("DD-MM-YY"); } else if (value == "Last 60 Days") { previousDate = moment().subtract(2, "months").format("DD-MM-YY"); } else if (value == "Last 3 Months") { previousDate = moment().subtract(3, "months").format("DD-MM-YY"); } else if (value == "Last 6 Months") { previousDate = moment().subtract(6, "months").format("DD-MM-YY"); } if (sessionStorage.getItem("filterSearchDate") !== null) { searchText = sessionStorage.getItem("filterSearchDate"); searchText += " transactiondate BETWEEN TO_DATE ('" + previousDate + "','dd-mm-yy') AND TO_DATE ('" + moment().format("DD-MM-YY") + "','dd-mm-yy')" sessionStorage.setItem("filterSearchDate", searchText); } else if (this.searchText !== "") { searchText = ""; searchText += " transactiondate BETWEEN TO_DATE ('" + previousDate + "','dd-mm-yy') AND TO_DATE ('" + moment().format("DD-MM-YY") + "','dd-mm-yy')" sessionStorage.setItem("filterSearchDate", searchText); } else { searchText = ""; searchText += " transactiondate BETWEEN TO_DATE ('" + previousDate + "','dd-mm-yy') AND TO_DATE ('" + moment().format("DD-MM-YY") + "','dd-mm-yy')" sessionStorage.setItem("filterSearchDate", searchText); } this.fromToDateGenerateQuery(); } fromToDateGenerateQuery() { if (!lodash.isEmpty(this.fromDate) && !lodash.isEmpty(this.toDate)) { sessionStorage.removeItem("filterSearchDate"); let fromDate = moment(new Date(this.fromDate.year, this.fromDate.month - 1, this.fromDate.day)).format("DD-MM-YY"); let toDate = moment(new Date(this.toDate.year, this.toDate.month - 1, this.toDate.day)).format("DD-MM-YY"); var searchText = ""; searchText += " transactiondate BETWEEN TO_DATE ('" + fromDate + "','dd-mm-yy') AND TO_DATE ('" + toDate + "','dd-mm-yy')" sessionStorage.setItem("filterSearchDate", searchText); } } // Clearing Accordion Filter clearAll() { this.filterByShow = false; this.locationSearchData = []; this.state = { "data": null, gridData: null, "dateData": null }; if (sessionStorage.getItem("filterSearchText") !== null) { sessionStorage.removeItem("filterSearchText"); if (sessionStorage.getItem("filterSearchDate") !== null) { this.fillFilteredGrid(); } else { this.fillGrid(); } } this.filterData.forEach(f => { f.values.forEach(val => { val.selected = false; }) }) this.changeFilter(); this.isbeingSearched = false; } // On selecting Static Data of Date Range ChangeSortOrder(value: string) { this.fromDate = {}; this.toDate = {}; sessionStorage.removeItem("filterSearchDate"); this.selectedSortOrder = value; let previousDate: any; var searchText = ""; if (value == "This Week") { previousDate = moment().subtract(1, 'week').format("DD-MM-YY"); } else if (value == "Last 30 Days") { previousDate = moment().subtract(1, "month").format("DD-MM-YY"); } else if (value == "Last 60 Days") { previousDate = moment().subtract(2, "months").format("DD-MM-YY"); } else if (value == "Last 3 Months") { previousDate = moment().subtract(3, "months").format("DD-MM-YY"); } else if (value == "Last 6 Months") { previousDate = moment().subtract(6, "months").format("DD-MM-YY"); } if (sessionStorage.getItem("filterSearchDate") !== null) { searchText = sessionStorage.getItem("filterSearchDate"); searchText += " transactiondate BETWEEN TO_DATE ('" + previousDate + "','dd-mm-yy') AND TO_DATE ('" + moment().format("DD-MM-YY") + "','dd-mm-yy')" sessionStorage.setItem("filterSearchDate", searchText); } else if (this.searchText !== "") { searchText = ""; searchText += " transactiondate BETWEEN TO_DATE ('" + previousDate + "','dd-mm-yy') AND TO_DATE ('" + moment().format("DD-MM-YY") + "','dd-mm-yy')" sessionStorage.setItem("filterSearchDate", searchText); } else { searchText = ""; searchText += " transactiondate BETWEEN TO_DATE ('" + previousDate + "','dd-mm-yy') AND TO_DATE ('" + moment().format("DD-MM-YY") + "','dd-mm-yy')" sessionStorage.setItem("filterSearchDate", searchText); } this.applyDateFilterFromSelectedItem(); } applyDateFilterFromSelectedItem() { this.pagingNo = 1; if (!lodash.isEmpty(this.fromDate) && !lodash.isEmpty(this.toDate)) { sessionStorage.removeItem("filterSearchDate"); let fromDate = moment(new Date(this.fromDate.year, this.fromDate.month - 1, this.fromDate.day)).format("DD-MM-YY"); let toDate = moment(new Date(this.toDate.year, this.toDate.month - 1, this.toDate.day)).format("DD-MM-YY"); var searchText = ""; searchText += " transactiondate BETWEEN TO_DATE ('" + fromDate + "','dd-mm-yy') AND TO_DATE ('" + toDate + "','dd-mm-yy')" sessionStorage.setItem("filterSearchDate", searchText); this.fillFilteredGrid(); } else { this.fillFilteredGrid(); } } datecheck() { var parsedDate1 = this.fromDate; var parsedDate2 = this.toDate; if (parsedDate1 && typeof parsedDate1 === 'string') { const [month, day, year] = parsedDate1.split('/'); const obj = { month: parseInt(month), day: parseInt(day.split(' ')[0].trim()), year: parseInt(year) }; parsedDate1 = obj; } else { parsedDate1 = this.fromDate; } if (parsedDate2 && typeof parsedDate2 === 'string') { const [month, day, year] = parsedDate2.split('/'); const obj = { month: parseInt(month), day: parseInt(day.split(' ')[0].trim()), year: parseInt(year) }; parsedDate2 = obj; } else { parsedDate2 = this.toDate; } this.fromDate = parsedDate1; this.toDate = parsedDate2; this.selectedSortOrder = "Custom"; this.applyDateFilterFromSelectedItem(); } applyDateFilter() { const currentDates: Date = new Date(); this.toInputDate = this.transformPickerDate(currentDates); if (typeof this.fromDate === 'string') { const [month, day, year] = this.fromDate.split("/"); if ((month > environment.month)) { this.common.showWarning("Please input the valid month.", "Warning Alert!") } else if ((month > environment.month)) { this.common.showWarning("Please input the valid month.", "Warning Alert!") } else if ((day > environment.day)) { this.common.showWarning("Please input the valid day.", "Warning Alert!") } else if ((day > environment.day)) { this.common.showWarning("Please input the valid day.", "Warning Alert!") } else if ((year < environment.year)) { this.common.showWarning("Order data available from Jan-2020", "Warning Alert!") } else if ((year < environment.year)) { this.common.showWarning("Order data available from Jan-2020", "Warning Alert!") } //else if ((this.fromDate) > (this.toDate)){ // this.common.showError("Start date should be less than end date.", "Validation Alert!") //} //else if ((this.toDate) < (this.fromDate)) { // this.common.showError("To date should be greater than from date.", "Validation Alert!") //} else if ((this.fromDate == null || this.fromDate == undefined || this.fromDate == "") && (this.toDate == null || this.toDate == undefined || this.toDate == "")) { this.common.showError("FromDate and ToDate required.", "Validation Alert!") } else if (this.fromDate == null || this.fromDate == undefined || this.fromDate == "") { this.common.showError("FromDate required.", "Validation Alert!") } else if (this.toDate == null || this.toDate == undefined || this.toDate == "") { this.common.showError("ToDate required.", "Validation Alert!") } else { this.datecheck(); } } else if (typeof this.toDate === 'string') { /*const [month, day, year] = this.fromDate.split("/");*/ const [month1, day1, year1] = this.toDate.split("/"); /*console.log(month);*/ if ((month1 > environment.month)) { this.common.showWarning("Please input the valid month.", "Warning Alert!") } else if ((month1 > environment.month)) { this.common.showWarning("Please input the valid month.", "Warning Alert!") } else if ((day1 > environment.day)) { this.common.showWarning("Please input the valid day.", "Warning Alert!") } else if ((day1 > environment.day)) { this.common.showWarning("Please input the valid day.", "Warning Alert!") } else if ((year1 < environment.year)) { this.common.showWarning("Order data available from Jan-2020", "Warning Alert!") } else if ((year1 < environment.year)) { this.common.showWarning("Order data available from Jan-2020", "Warning Alert!") } //else if ((this.fromDate) > (this.toDate)){ // this.common.showError("Start date should be less than end date.", "Validation Alert!") //} //else if ((this.toDate) < (this.fromDate)) { // this.common.showError("To date should be greater than from date.", "Validation Alert!") //} else if ((this.fromDate == null || this.fromDate == undefined || this.fromDate == "") && (this.toDate == null || this.toDate == undefined || this.toDate == "")) { this.common.showError("FromDate and ToDate required.", "Validation Alert!") } else if (this.fromDate == null || this.fromDate == undefined || this.fromDate == "") { this.common.showError("FromDate required.", "Validation Alert!") } else if (this.toDate == null || this.toDate == undefined || this.toDate == "") { this.common.showError("ToDate required.", "Validation Alert!") } else { this.datecheck(); } } else if ((this.fromDate == null || this.fromDate == undefined || this.fromDate == "") && (this.toDate == null || this.toDate == undefined || this.toDate == "")) { this.common.showError("FromDate and ToDate required.", "Validation Alert!") } else if (this.fromDate == null || this.fromDate == undefined || this.fromDate == "") { this.common.showError("FromDate required.", "Validation Alert!") } else if (this.toDate == null || this.toDate == undefined || this.toDate == "") { this.common.showError("ToDate required.", "Validation Alert!") } else if ((this.fromDate.year < environment.year) || (this.toDate.year < environment.year)) { this.common.showWarning("Order data available from Jan-2020", "Warning Alert!") } else if ((this.fromDate.year < environment.year) || (this.toDate.year < environment.year)) { this.common.showWarning("Order data available from Jan-2020", "Warning Alert!") } else if (moment().set('year', this.fromDate.year).set('month', this.fromDate.month).set('date', this.fromDate.day) > moment().set('year', this.toInputDate.year).set('month', this.toInputDate.month).set('date', this.toInputDate.day)) { this.common.showWarning("Please input the valid FromDate", "Warning Alert!") } else if (moment().set('year', this.toDate.year).set('month', this.toDate.month).set('date', this.toDate.day) > moment().set('year', this.toInputDate.year).set('month', this.toInputDate.month).set('date', this.toInputDate.day)) { this.common.showWarning("Please input the valid ToDate", "Warning Alert!") } else if (moment().set('year', this.toDate.year).set('month', this.toDate.month - 1).set('date', this.toDate.day) < moment().set('year', this.fromDate.year).set('month', this.fromDate.month - 1).set('date', this.fromDate.day)) { this.common.showError("To date should be greater than from date.", "Validation Alert!") } else { this.datecheck(); } } clearDateFilterAll() { const currentDates: Date = new Date(); this.state = { "data": null, gridData: null, "dateData": null }; this.filterByShow = false; this.fromDate = ""; this.toDate = ""; this.minStartDateasstring = { year: currentDates.getFullYear() - 2, month: 1, day: 1 } this.minStartDate = { year: currentDates.getFullYear() - 2, month: 1, day: 1 } this.maxStartDate = { year: currentDates.getFullYear(), month: currentDates.getMonth() + 1, day: currentDates.getDate() } this.selectedSortOrder = "Date Range"; if (sessionStorage.getItem("filterSearchDate") !== null) { sessionStorage.removeItem("filterSearchDate"); if (sessionStorage.getItem("filterSearchText") !== null) { this.fillFilteredGrid(); } else { this.fillGrid(); } } } fillFilteredGrid() { let ifLocationDataExists = this.selectedFilterData.filter(d => { return d.label == 'Location'; }) if (ifLocationDataExists.length > 0) { this.searchText = ""; } else { if (this.options.isHistory) { this.searchText = "AND " + this.options.historyFor; } } this.searchText += (sessionStorage.getItem("filterSearchText") !== null ? " AND " + sessionStorage.getItem("filterSearchText") : ""); this.searchText += (sessionStorage.getItem("filterSearchDate") !== null ? " AND " + sessionStorage.getItem("filterSearchDate") : ""); this.modelBeforeSubmit(); this.common.GetGridList(this.modelDataTable, data => { this.APIResponse = data; this.commonGridList = this.APIResponse.objResponse.responseContent; let filteredDataCopy = this.common.copy(this.filterData); if (this.locationSearchData.length > 0) { filteredDataCopy.forEach(d => { if (d.group == "Location" && this.locationSearchData.length > 0) { d.locationSearchData = this.locationSearchData; } }) this.state = { "data": filteredDataCopy, "gridData": this.commonGridList, "dateData": (this.selectedSortOrder !== "Date Range" && this.selectedSortOrder !== "Custom" ? this.selectedSortOrder : (this.selectedSortOrder == "Custom" ? [{ fromDate: this.fromDate, toDate: this.toDate }] : "")) }; } else { this.state = { "data": filteredDataCopy, "gridData": this.commonGridList, "dateData": (this.selectedSortOrder !== "Date Range" && this.selectedSortOrder !== "Custom" ? this.selectedSortOrder : (this.selectedSortOrder == "Custom" ? [{ fromDate: this.fromDate, toDate: this.toDate }] : "")) }; } if (this.commonGridList != null && this.commonGridList?.length > 0) { if (this.options.page == 'GeoRegion') { this.commonGridList.map(i => i.toggleactive = false); } this.totalRecords = this.commonGridList[0].count; this.lastPage = Math.ceil(this.totalRecords / this.pageLength); this.getEntries(); this.dtTrigger.next(); } else { this.lastPage = this.totalRecords = 0; this.totalpages(); this.entries = 'Showing 0 to 0 of 0 entries' } }, (error) => { console.error('Error: ' + error); return error(error); }); } OnFromDateInput(event: any, valueobject: any) { this.validateDates(); } manualValidation(_sd) { /* console.log("value of input field: " + _sd._elRef.nativeElement.value)*/ var data = _sd._elRef.nativeElement.value if (data.length == 10) { if (data) { const [month, day, year] = data.split('/'); const obj = { month: parseInt(month), day: parseInt(day), year: parseInt(year) }; data = obj; } this.fromDate = data; data.toggle(); } } manualValidationend(_ed) { /* console.log("value of input field: " + _ed._elRef.nativeElement.value)*/ var data = _ed._elRef.nativeElement.value if (data.length == 10) { if (data) { const [month, day, year] = data.split('/'); const obj = { month: parseInt(month), day: parseInt(day), year: parseInt(year) }; data = obj; } this.toDate = data; data.toggle(); } } StartDate(data: any) { let from: any; let to: any; if (data) { const [month, day, year] = data._inputValue.split('/'); const obj = { month: parseInt(month), day: parseInt(day), year: parseInt(year) }; data._inputValue = obj; } this.fromDate = data._inputValue; data.toggle(); this.validateDates(); } EndDate(datae: any) { let to: any; if (datae) { const [month, day, year] = datae._inputValue.split('/'); const obj = { month: parseInt(month), day: parseInt(day), year: parseInt(year) }; datae._inputValue = obj; this.toDate = datae._inputValue; datae.toggle(); this.validateDates(); } } OnStartDateInput(event: any) { this.validateDates(); } OnEndDateInput(event: any) { this.validateDates(); } validateDates() { let sDate: Date; let eDate: Date; this.isValidDate = 0; const currentDate: Date = new Date(); if (this.fromDate) { sDate = new Date(this.fromDate.year, this.fromDate.month, this.fromDate.day); this.minStartDateasstring = { year: this.fromDate.year, month: this.fromDate.month, day: this.fromDate.day } this.maxEndDateasstring = this.transformPickerDate(currentDate); } if (this.toDate) { eDate = new Date(this.toDate.year, this.toDate.month, this.toDate.day); this.maxStartDate = { year: this.toDate.year, month: this.toDate.month, day: this.toDate.day } } if ((sDate != null && eDate != null) && (sDate) > (eDate)) { this.isValidDate = 1; this.common.showError("Start date should be less than end date.", "Validation Alert!") } else if ((sDate != null && eDate != null) && (eDate) < (sDate)) { this.isValidDate = 2; this.common.showError("End date should be grater than start date.", "Validation Alert!") } else { this.isValidDate = 0; } } OnOpen() { if (!this.isbeingSearched) { this.select1Comp.close(); } } OnSearch(e) { if (e.term.length >= 1) { let filteredData = lodash.sortBy(this.locationDataSource.filter(f => { return (!lodash.includes(this.locationSearchData, f.value)) && lodash.includes(lodash.toLower(f.value), lodash.toLower(e.term)) }), s => { return s.value }); this.select1Comp.itemsList.setItems(filteredData); this.isbeingSearched = true; this.select1Comp.open(); } else { this.clearLocationItems(); } } clearLocationItems() { this.isbeingSearched = false; this.select1Comp.close(); this.select1Comp.itemsList.setItems([]); } clickLocation() { this.select1Comp.placeholder = ""; } addplaceHolderToLocation() { this.select1Comp.placeholder = "Enter a Location"; } // Filter Functions Ends }