import { Component, OnInit, ViewChild } from '@angular/core'; import { CommonService } from '../../../services/common.service'; import { from, Subject } from 'rxjs'; import { DataTableDirective } from 'angular-datatables'; import { ActivatedRoute, Router } from "@angular/router"; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { OrderListService } from '../../../services/order/order.service'; import { OrderList } from '../../../models/order-list/order'; import { ArchivedOrder } from '../../../models/order-list/archive-order'; import { IArchiveContent, IArchiveOrders } from '../../../models/order-list/archive-content'; import { DataTable } from '../../../models/shared/data-table/data-table' import { formatAsDateString } from '../../../views/shared/helpers/date.helpers'; //import { // selectdRow, // expandedtree, // expandAllTree, // collapseAllTree, //} from 'tabletreedragtest' import { DomSanitizer } from '@angular/platform-browser'; import { Input } from '@angular/core'; import { Output } from '@angular/core'; import { EventEmitter } from '@angular/core'; @Component({ selector: 'app-order-list', templateUrl: './order-list.component.html', styleUrls: ['./order-list.component.css'] }) export class OrderListComponent implements OnInit { dtOptions: any = {}; OrderlistAPIResponse: any; //documentTree: any; //OpenOrderData: any[]; OpenOrderData: OrderList[]; ArchiveOrderData: ArchivedOrder[]; formData: FormData = new FormData(); dtTrigger: Subject = new Subject(); UserId: number = 1; @ViewChild(DataTableDirective) dtElement: DataTableDirective; customtree: any = []; customtreejson: any; ArchivedOrderAPIResponse: any; data: any; fileUrl; count = 0; counter: number; @Input() OrderListModal; @Output() datas: EventEmitter = new EventEmitter(); constructor(private common: CommonService, private service: OrderListService, private sanitizer: DomSanitizer, private formBuilder: FormBuilder, private router: Router, private route: ActivatedRoute) { } 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[] = []; archivedOrder: IArchiveContent[]; customernumber: number = 1404456; CustomerNumber: string = ""; getcustomerno: string = sessionStorage.getItem('CustomerNo'); getcustomernumber: string = sessionStorage.getItem('CustomerNumber'); getmapingcustomer: string = sessionStorage.getItem('MapingCustomer'); loggedInUserType: string = sessionStorage.getItem('UserType'); GlobalSearchShipToAddressID:string = ''; searchdatamodel: any; customerOrderPO: string = ""; showTree: boolean = false; isRefersh = false; archivedOrderlist: any; sidingArchiveOrderList: any; @Output() property = new EventEmitter(); //archivedOrderlists: StructureFolder[] = []; //lstFolderDocument: FolderDocument[]; isOrderRefersh = false; commonGridList = []; searchData: any; options; IsShowOrderData: boolean = false; ngOnInit(): void { this.router.routeReuseStrategy.shouldReuseRoute = () => false; sessionStorage.setItem('IsDashboard', '0'); if (this.getcustomernumber != "" && this.getcustomernumber != null && this.getcustomernumber != undefined) { this.CustomerNumber = this.getcustomernumber; } if (this.getmapingcustomer != "" && this.getmapingcustomer != null && this.getmapingcustomer != undefined) { if (this.CustomerNumber != "") { this.CustomerNumber = this.CustomerNumber + ',' + this.getmapingcustomer; } else { this.CustomerNumber = this.getmapingcustomer; } } let querystring = ""; var searchData = sessionStorage.getItem('searchData') == undefined || sessionStorage.getItem('searchData') == null ? '' : sessionStorage.getItem('searchData'); this.searchData = searchData; this.GlobalSearchShipToAddressID = sessionStorage.getItem('GlobalSearchShipToAddressID') == undefined || sessionStorage.getItem('GlobalSearchShipToAddressID') == 'null' || sessionStorage.getItem('GlobalSearchShipToAddressID') == null ? '' : sessionStorage.getItem('GlobalSearchShipToAddressID'); var ShipToAddressSearchQuery =''; if(this.GlobalSearchShipToAddressID != ''){ ShipToAddressSearchQuery = 'shiptoaddress IN (' + this.GlobalSearchShipToAddressID + ') ' } else{ ShipToAddressSearchQuery = 'shiptoaddress IN (' + this.getmapingcustomer + ') ' } if ((sessionStorage.getItem('GlobalSearchShipToAddressID') == undefined || sessionStorage.getItem('GlobalSearchShipToAddressID') == '' || sessionStorage.getItem('GlobalSearchShipToAddressID') == null) && sessionStorage.getItem('UserType') != "External") { this.IsShowOrderData = false; } else { this.IsShowOrderData = true; } if (searchData) { this.searchdatamodel = JSON.parse(searchData); this.customerOrderPO = this.searchdatamodel.search.trim(); if (this.searchdatamodel.type == 'rdOrderNo') { querystring = 'ordernumber=to_number(' + this.customerOrderPO + ') AND ordernumber NOT IN(SELECT ordernumber FROM sidingpilot_archive_order WHERE isarchived = 1 AND ordernumber = to_number(' + this.customerOrderPO + ')) '; querystring += 'AND ordernumber=to_number(' + this.customerOrderPO + ') ' // querystring += 'AND shiptoaddress IN (' + this.getmapingcustomer + ') ' querystring += ShipToAddressSearchQuery; querystring += 'AND ordernumber NOT IN(SELECT ordernumber FROM sidingpilot_archive_order WHERE isarchived = 1 AND ordernumber = to_number(' + this.customerOrderPO + ')) ' } else { //querystring = ' rtrim(customerpo)=\'' + this.customerOrderPO + '\' AND ordernumber NOT IN ( SELECT ordernumber FROM sidingpilot_archive_order WHERE isarchived=1 AND ordernumber=(SELECT DISTINCT ordernumber FROM CBB_PORTAL_APPS.cbb_siding_orders_dw WHERE rtrim(customerpo)=\'' + this.customerOrderPO + '\'))'; querystring = 'UPPER(rtrim(customerpo)) like UPPER(\'' + '%' + this.customerOrderPO + '%' + '\') ' querystring += ShipToAddressSearchQuery; //querystring += ' AND shiptoaddress IN (' + this.getmapingcustomer + ')' } sessionStorage.setItem('searchData', ''); this.common.options = this.options = { path: '', columnHeader : {}, // 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' }, isDelete: false, isEdit: false, isPreview: false, isAction: false, tableName: 'SIDINGPILOT_ORDERS_LIST', columnName: 'TRANSACTIONDATE', isHistory: true, searching: false, stateSave: true, historyFor: querystring } let modelDataTable = new DataTable(); modelDataTable.columnName = this.options.columnName; modelDataTable.sortOrder = Boolean(true); modelDataTable.stateSave = true; modelDataTable.isLast = Boolean(false); modelDataTable.pageLength = Number(10); modelDataTable.pageNo = Number(1); modelDataTable.searchText = String("AND " + this.options.historyFor); modelDataTable.tableName = String(this.options.tableName); this.common.GetGridList(modelDataTable, data => { let APIResponse = data; this.commonGridList = APIResponse.objResponse.responseContent; if (this.commonGridList?.length == 0) { this.showTree = true; this.getCustomerArchiveContents(); } }, (error) => { console.error('Error: ' + error); return error(error); }); } else { if (this.OrderListModal != "") { this.common.options = this.options = { path: '', columnHeader: {}, // 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' }, isDelete: false, isEdit: false, isPreview: false, isAction: false, tableName: 'SIDINGPILOT_ORDERS_LIST', columnName: 'TRANSACTIONDATE', isHistory: true, searching: false, stateSave: true, // historyFor: 'ordernumber NOT IN ( SELECT ordernumber FROM sidingpilot_archive_order WHERE customernumber IN(' + this.getmapingcustomer + ') AND isarchived=1) ' + ShipToAddressSearchQuery historyFor: ShipToAddressSearchQuery //historyFor: 'soldtoaddress= ' + this.getmapingcustomer + '' //historyFor: 'customernumber IN(' + this.CustomerNumber + ') AND ordernumber NOT IN ( SELECT ordernumber FROM sidingpilot_archive_order WHERE customernumber IN(' + this.CustomerNumber + ') AND isarchived=1) ' } } } } onClickOpenOrder() { this.router.navigate(['/order/order-list']); } refershItemFlag() { this.isOrderRefersh = true; } refreshAfterArchived() { if (this.isOrderRefersh) this.getOpenOrder(); this.isOrderRefersh = false; } getOpenOrder() { throw new Error('Method not implemented.'); } getCustomerArchiveContents() { if (this.customtree == null || this.customtree == undefined || this.customtree?.length == 0 || this.isRefersh) { this.service.getCustomerArchiveContents(this.getmapingcustomer, data => { this.ArchivedOrderAPIResponse = data; this.archivedOrderlist = this.ArchivedOrderAPIResponse.objResponse.responseContent.ArchivedOrderTree; this.sidingArchiveOrderList = this.ArchivedOrderAPIResponse.objResponse.responseContent.FilterOrder; if (this.commonGridList?.length == 0 && this.customerOrderPO != null && this.customerOrderPO != '') { this.archivedOrderlist = this.archivedOrderlist.filter(x => x.Jobid == this.customerOrderPO); this.service.FilderOrderlist = this.archivedOrderlist; } if (this.archivedOrderlist != null && this.archivedOrderlist != undefined) { //mapping Archived Tree this.customtree = this.archivedOrderlist.map((data) => { return { id: data.Id, parentid: data.Parentid, IsFolder: data.IsFolder, Jobid: data.Jobid, Type: data.Type, Ordername: data.Ordername, CustomerArchiveFolderGuid: data.CustomerArchiveFolderGuid, OrderArchiveFolderGuid: data.OrderArchiveFolderGuid, ParentCustomerArchiveFolderGuid: data.ParentCustomerArchiveFolderGuid, Orderdate: data.Orderdate ? formatAsDateString(data.Orderdate) : null, Archivdate: data.Archivdate ? formatAsDateString(data.Archivdate) : null, CUSTOMERNUMBER: data.CUSTOMERNUMBER }; } ); this.isRefersh = false; } this.showTree = true }, (error) => { console.error('Error: ' + error); return error(error); } ); } } sendData() { this.property.emit(this.archivedOrderlist); } ngOnDestroy(): void { // Do not forget to unsubscribe the event this.dtTrigger.unsubscribe(); } UpdateTree() { } Download() { const data = 'some text'; const blob = new Blob([data], { type: 'application/octet-stream' }); this.fileUrl = this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob)); } actionAllSelected(event: any) { if (event.checked) { //this.ArchiveOrdersinfo = null; this.showOpenArchivedSelected = true; this.isSelected = true; this.OpenOrderData.forEach((data: any) => { let orderArchiveDetails: IArchiveOrders = { OrderId: { oeOrderId: data.id, year: data.Year, type: data.Type, key: data.Key, }, CustomerArchiveFolderGuid: null, Date: null, }; if (this.ArchiveOrdersinfo == null || this.ArchiveOrdersinfo == undefined) this.ArchiveOrdersinfo = []; this.ArchiveOrdersinfo.push(orderArchiveDetails); }); } else { this.ArchiveOrdersinfo = null; this.isSelected = false; this.showOpenArchivedSelected = false; } } showArchived(event: any, orders: any) { if (event.checked) { let orderArchiveDetails: IArchiveOrders = { OrderId: { oeOrderId: orders.id, year: orders.Year, type: orders.Type, key: orders.Key, }, CustomerArchiveFolderGuid: null, Date: null, }; if (this.ArchiveOrdersinfo == null || this.ArchiveOrdersinfo == undefined) this.ArchiveOrdersinfo = []; this.ArchiveOrdersinfo.push(orderArchiveDetails); this.showOpenArchivedSelected = true; } else { // get index of object with id:37 var removeIndex = this.ArchiveOrdersinfo.map(function (item) { return item.OrderId.oeOrderId; }).indexOf(orders.id); // remove object this.ArchiveOrdersinfo.splice(removeIndex, 1); if (this.ArchiveOrdersinfo?.length == 0) this.showOpenArchivedSelected = false; } } actionAllSelectedEvent(event: any) { if (event.checked) { //this.ArchiveOrdersinfo = null; this.showUnArchivedSelected = true; this.isSelected = true; this.OpenOrderData.forEach((data: any) => { let orderArchiveDetails: IArchiveOrders = { OrderId: { oeOrderId: data.id, year: data.Year, type: data.Type, key: data.Key, }, CustomerArchiveFolderGuid: null, Date: null, }; if (this.ArchiveOrdersinfo == null || this.ArchiveOrdersinfo == undefined) this.ArchiveOrdersinfo = []; this.ArchiveOrdersinfo.push(orderArchiveDetails); }); } else { this.ArchiveOrdersinfo = null; this.isSelected = false; this.showUnArchivedSelected = false; } } showUnArchived(event: any, orders: any) { if (event.checked) { let orderArchiveDetails: IArchiveOrders = { OrderId: { oeOrderId: orders.id, year: orders.Year, type: orders.Type, key: orders.Key, }, CustomerArchiveFolderGuid: null, Date: null, }; if (this.ArchiveOrdersinfo == null || this.ArchiveOrdersinfo == undefined) this.ArchiveOrdersinfo = []; this.ArchiveOrdersinfo.push(orderArchiveDetails); this.showUnArchivedSelected = true; } else { // get index of object with id:37 var removeIndex = this.ArchiveOrdersinfo.map(function (item) { return item.OrderId.oeOrderId; }).indexOf(orders.id); // remove object this.ArchiveOrdersinfo.splice(removeIndex, 1); if (this.ArchiveOrdersinfo?.length == 0) this.showUnArchivedSelected = false; } } }