import {Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation, OnDestroy} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {FormBuilder, FormControl, FormGroup} from '@angular/forms'; import {ApiService} from '../app.api.service'; import {EmployeeServices} from '../_services/employee/employee.service'; import {SelectableSettings} from '@progress/kendo-angular-grid'; import {SearchEmployee, SearchManager} from '../_models/Employee/searchEmployee'; import {EnumExtension, EnumGender, EnumSearchFrom, EnumSearchObjDataType, EnumSearchParameter, EnumSQLOperator,EnumStatus,EnumAssetStatus} from '../_models/enums'; import {DynamicPicker, EnumDynamicpickerType} from './dynamic-picker/Dynamic-Picker'; import {BasicService} from '../_services/Basic/basic.service'; import {Subscription} from 'rxjs'; import {PickerDataTransferService} from '../data.transfer.service'; import {loadingPanelService} from '../hrm-loding panel/loding.panel.service'; import {RecruitmentRequisition} from '../_models/Requisition/recruitmentRequisition'; import {RecruitmentService} from '../_services/recruitment/recruitment.service'; import {InternalRecruitment} from '../_models/Requisition/InternalRecruitment'; import {Asset,AssetSerial,AssetCategory} from '../_models/ExitClearance/existClearance'; import {ExitClearanceService} from '../_services/payroll/exitClearance.service'; @Component({ selector: 'app-asset-serial-picker', templateUrl: './asset-serial-picker.component.html', //styleUrls: ['../../assets/kendo-grid/grid.css'], encapsulation: ViewEncapsulation.None, }) export class AssetSerialPickerComponent implements OnInit, OnDestroy { valueChangedSubscription: Subscription; genders: any = EnumExtension.getNamesAndValues(EnumGender); public active = false; public showPopUp = false; public checkboxOnly = false; public mode = 'multiple'; public assetid:number; public status:EnumAssetStatus; public selectableSettings: SelectableSettings; taggedSelection: number[] = []; assetList:Asset[]=[]; /*public searchItems: RecruitmentRequisition[];*/ public searchItems: AssetSerial[]; public selectedItems: AssetSerial[] = []; public selectedItem: AssetSerial; public selectedAssetSerial: AssetSerial; public searchAssetSerial: AssetSerial[]; requisitionName: string = 'Search Asset Serial'; assetCategoryPicker: DynamicPicker; searchIcon: string = 'Search'; ItemCount: number = 0; statusList: any = EnumExtension.getNamesAndValues(EnumAssetStatus); @Input() pickerFormGroup: FormGroup; @Output() ItemSelected: EventEmitter = new EventEmitter(); @Input() pickerformControlName: string = "itemselected"; @Input() public set setSelectedItem(inputedItem: AssetSerial) { if (inputedItem !== undefined) { this.selectedItem = inputedItem; this.taggedSelection = []; this.taggedSelection.push(this.selectedItem.id); // this.selectedItemText = this.selectedItem.serialNo; } else { this.selectedItem = new AssetSerial(); // this.selectedItemText = ''; } } private empCodeNameList: Array; private empCodeNameListSource: Array; public selectedItemText: string; public gridMultiSelect = false; @Input() public set MultiSelect(ismultiselect: boolean) { if (ismultiselect !== undefined) { /* this.gridMultiSelect = true;*/ this.gridMultiSelect = ismultiselect; this.setSelectableSettings(); } } @Input() public set isStatusActive(isActive: boolean) { debugger; this.active = isActive; } @Input() public set setStatus(Status: EnumAssetStatus) { debugger; this.status = Status; } /** role-permission-entry ctor */ constructor(public api: ApiService, public formBuilder: FormBuilder, public router: Router, public route: ActivatedRoute, public empSrvc: EmployeeServices, public basicService: BasicService, public pickerService: PickerDataTransferService, public loadingService: loadingPanelService, public recruitmentService: RecruitmentService, public exitClearanceService:ExitClearanceService, ) { if (this.pickerFormGroup === undefined) { this.pickerFormGroup = new FormGroup({}); } } ngOnInit() { debugger; this.assetCategoryPicker = new DynamicPicker(EnumDynamicpickerType.AssetCategory, true); // this.status = EnumAssetStatus.Free; this.setSelectableSettings(); this.getAssets(); this.valueChangedSubscription == this.pickerService.dataChanged.subscribe( x => { if (x) { //this.employeeCount = x; } } ); } public getAssets() { this.exitClearanceService.getAllAssets().subscribe( (x) => { this.assetList = x; }, (x) => { this.loadingService.ShowLoadingPanel = false; ///this.notificationService.showError(x); }, () => { this.loadingService.ShowLoadingPanel = false; //this.getAssetCategories(); }); } public clear() { // this.dynamicPickerView.selectedID = 0; // this.dynamicPickerView.selectedIDs = []; // this.dynamicPickerView.selecteditemText = ''; } setSelectableSettings(): void { debugger; if (this.gridMultiSelect === false) { this.selectableSettings = { checkboxOnly: true, mode: 'single', // this.mode }; } else { this.selectableSettings = { checkboxOnly: true, mode: 'multiple', // this.mode }; } } search() { let categoryid = this.assetCategoryPicker.selectedIDs[0] == undefined ? 0 : this.assetCategoryPicker.selectedIDs[0]; this.assetid = this.assetid == undefined ? 0 :this.assetid; this.status = (this.status == undefined || this.status==null) ? 0 :this.status; this.loadingService.ShowLoadingPanel = true; this.exitClearanceService.getAssetSerialPicker(this.assetid,categoryid,this.status).subscribe( (resp) => { this.searchItems = resp; }, (x) => { console.log(x); this.loadingService.ShowLoadingPanel = false; }, () => { this.loadingService.ShowLoadingPanel = false; }, ); } public onCancel(e): void { this.closeForm(); } public onSelect(e): void { debugger; this.searchAssetSerial = []; this.selectedAssetSerial = new AssetSerial(); if (this.taggedSelection.length > 0) { if (this.gridMultiSelect === true) { this.taggedSelection.forEach(positionid => { this.searchAssetSerial.push(this.searchItems.find(x => x.id === positionid)); }); } else { this.taggedSelection.forEach(positionid => { this.selectedAssetSerial = this.searchItems.find(x => x.id === positionid); }); } } if (this.gridMultiSelect === false) { // this.selectedAutoCmptEmp = this.selectedEmployee.employeeNo + '-' + this.selectedEmployee.name; this.ItemSelected.emit(this.selectedAssetSerial); this.requisitionName = this.selectedAssetSerial.serialNo; } else { this.ItemSelected.emit(this.searchAssetSerial); } this.showPopUp = false; } closeForm(): void { this.showPopUp = false; } OpenForm(): void { //this.selectedEmployees = []; //this.selectedEmployee = new SearchEmployee(); //this.taggedSelection = []; this.showPopUp = true; } ngOnDestroy() { this.loadingService.ShowLoadingPanel = false; } }