import {Injectable} from '@angular/core'; import {ApiService} from '../../app.api.service'; import {HttpClient, HttpEvent, HttpRequest} from '@angular/common/http'; import { Observable } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class DataUploadService { baseUrl = ApiService.BASE_URL + '/HRBasic'; constructor(public apiService: ApiService, private http: HttpClient) { } getPrepareColumnDefinition(uploadId: number, itemid?: number) { const newItemid = this.apiService.getApiDefaultIntData(itemid); return this.apiService.httpGet('/dataUpload/prepareUpload/' + uploadId + '/' + newItemid); } public uploadFile(selectedFile: File, uploadID: number, payrolltypeid: number, userid: number, itemid?: number, itemidTwo?: number, selectedDate?: Date): Observable> { const date = selectedDate.getDate(); const month = selectedDate.getMonth(); const year = selectedDate.getFullYear(); // console.log(`${date}/${month}/${year}`); console.log(selectedDate.toDateString()); const formData: FormData = new FormData(); formData.append('excelfile', selectedFile); formData.append('uploadID', String(uploadID)); formData.append('itemID', String(itemid)); formData.append('itemIDTwo', String(itemidTwo)); formData.append('payrolltypeid', String(payrolltypeid)); formData.append('userid', String(userid)); formData.append('selectedDate', selectedDate.toDateString()); const req = new HttpRequest('POST', `${this.apiService.base_url + '/'}dataUpload/regularExcelInterface`, formData, { responseType: 'json' }); return this.http.request(req); } public uploadBonusFile(selectedFile: File, payrolltypeid: number): Observable> { const formData: FormData = new FormData(); formData.append('excelfile', selectedFile); formData.append('payrolltypeid', String(payrolltypeid)); const req = new HttpRequest('POST', `${this.apiService.base_url + '/'}dataUpload/uploadBonusFile`, formData, { reportProgress: true, responseType: 'json' }); return this.http.request(req); } public uploadRecruitmentFiles(formData: any) { return this.apiService.httpPostBlob('/filemanager/uploadFiles', formData); } getUploadDatatMessagen(data: any) { return this.apiService.httpPost('/dataUpload/uploadData/', data); // return this.apiService.httpGet('/dataUpload/uploadData/' + uploadId + '/' + test + '/' + path); } public removeFile(formData: any) { return this.apiService.httpPostBlob('/filemanager/removeExcelfile', formData); } }