|
|
|
|
@ -17,6 +17,7 @@ import { Device } from '@ionic-native/device/ngx';
|
|
|
|
|
import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx';
|
|
|
|
|
import { Platform } from '@ionic/angular';
|
|
|
|
|
import { ModalController } from '@ionic/angular';
|
|
|
|
|
import { FirebaseX } from '@ionic-native/firebase-x/ngx';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
@ -32,6 +33,7 @@ export class AttendScanService {
|
|
|
|
|
userData: any = {};
|
|
|
|
|
public isFakeLocationUsed = false;
|
|
|
|
|
public isGpsRequired = false;
|
|
|
|
|
public collection = 'CS';
|
|
|
|
|
|
|
|
|
|
constructor(private device: Device,
|
|
|
|
|
private zbar: ZBar,
|
|
|
|
|
@ -46,9 +48,11 @@ export class AttendScanService {
|
|
|
|
|
public ts: TranslatorService,
|
|
|
|
|
public backgroundGeolocation: BackgroundGeolocation,
|
|
|
|
|
public platform: Platform,
|
|
|
|
|
public modalController: ModalController
|
|
|
|
|
public modalController: ModalController,
|
|
|
|
|
public firebasex: FirebaseX
|
|
|
|
|
) {
|
|
|
|
|
this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false);
|
|
|
|
|
console.log(this.userData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDeviceLocation() {
|
|
|
|
|
@ -132,6 +136,29 @@ export class AttendScanService {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async checkFirestoreDocument(userID : string) {
|
|
|
|
|
let result = {};
|
|
|
|
|
await this.firebasex.fetchDocumentInFirestoreCollection(userID, this.collection, (document: any) => {
|
|
|
|
|
console.log("Successfully Fetched the document with id =");
|
|
|
|
|
result = {
|
|
|
|
|
isDocumentAvailable: true,
|
|
|
|
|
document: document
|
|
|
|
|
};
|
|
|
|
|
this.common.sharedService.setSharedData(result, 'firebase-document');
|
|
|
|
|
this.common.stopLoading();
|
|
|
|
|
}, (error: any) => {
|
|
|
|
|
console.log(error);
|
|
|
|
|
result = {
|
|
|
|
|
isDocumentAvailable: false,
|
|
|
|
|
document: null
|
|
|
|
|
};
|
|
|
|
|
this.common.sharedService.setSharedData(result, 'firebase-document');
|
|
|
|
|
this.common.stopLoading();
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fakeSwipeAttendance() {
|
|
|
|
|
const request: any = {};
|
|
|
|
|
request.Latitude = this.lat;
|
|
|
|
|
@ -149,6 +176,54 @@ export class AttendScanService {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public updateFirebaseDocument(resultObject: any) {
|
|
|
|
|
let currentFirebaseDocument = this.common.sharedService.getSharedData('firebase-document');
|
|
|
|
|
let currentSwipeArray = currentFirebaseDocument.document.swipeData;
|
|
|
|
|
currentSwipeArray.push(resultObject);
|
|
|
|
|
const updatedDocument = {
|
|
|
|
|
swipeData: currentSwipeArray
|
|
|
|
|
};
|
|
|
|
|
console.log(updatedDocument);
|
|
|
|
|
this.firebasex.updateDocumentInFirestoreCollection(this.userData.EMPLOYEE_NUMBER, updatedDocument, this.collection, () => {
|
|
|
|
|
console.log("Successfully added document with id=" + this.userData.EMPLOYEE_NUMBER);
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.error("Error adding document: " + error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public processFirebaseDocument(mode: string, result: any, isDocumentAvailable: boolean) {
|
|
|
|
|
console.log(mode);
|
|
|
|
|
console.log(result);
|
|
|
|
|
console.log(isDocumentAvailable);
|
|
|
|
|
this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false);
|
|
|
|
|
console.log(this.userData);
|
|
|
|
|
const resultObject = {
|
|
|
|
|
modeOfAttendance: mode,
|
|
|
|
|
messageStatus: result.MessageStatus,
|
|
|
|
|
transactionID: result.SWP_AuthenticateAndSwipeUserModel.TransactionID,
|
|
|
|
|
userID: result.SWP_AuthenticateAndSwipeUserModel.UserID,
|
|
|
|
|
pointID: result.SWP_AuthenticateAndSwipeUserModel.PointID,
|
|
|
|
|
branchDescription: result.SWP_AuthenticateAndSwipeUserModel.BranchDescription
|
|
|
|
|
}
|
|
|
|
|
if (isDocumentAvailable) {
|
|
|
|
|
this.updateFirebaseDocument(resultObject);
|
|
|
|
|
} else {
|
|
|
|
|
this.createNewDocument(resultObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public createNewDocument(resultObject: any) {
|
|
|
|
|
let swipeData = [];
|
|
|
|
|
swipeData.push(resultObject);
|
|
|
|
|
const newDocument = {
|
|
|
|
|
swipeData: swipeData
|
|
|
|
|
};
|
|
|
|
|
this.firebasex.setDocumentInFirestoreCollection(this.userData.EMPLOYEE_NUMBER, newDocument, this.collection, () => {
|
|
|
|
|
console.log("Successfully added document");
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.error("Error adding document: "+error);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public swipeAttendance() {
|
|
|
|
|
const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest();
|
|
|
|
|
|