diff --git a/src/app/services/opCommercial/op-commercial.service.ts b/src/app/services/opCommercial/op-commercial.service.ts index e155097..fdde743 100644 --- a/src/app/services/opCommercial/op-commercial.service.ts +++ b/src/app/services/opCommercial/op-commercial.service.ts @@ -81,52 +81,109 @@ export class OpCommercialService { updateOpCommStatus() { const opComAll = this.getOpComs(); - opComAll.forEach(utilisateur => { - utilisateur.forEach(monOpCom => { - if(monOpCom !== undefined){ - var todayTemp = new Date(Date.now()); - var debutTemp = new Date(monOpCom.dateDebut); - var finTemp = new Date(monOpCom.dateFin); - if (monOpCom.status !== 'Bloqué') { - if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { - monOpCom.status = 'Active'; - } else { - monOpCom.status = 'Inactive'; - } - if (monOpCom.uid !== undefined){ - const carteStatusRef = firebase.database().ref().child('OperationCommercial').child(monOpCom.uid.toString()).child('status'); - carteStatusRef.set(monOpCom.status); + opComAll.subscribe(tabOpComs => { + if (tabOpComs.length > 0) { + for (let i = 0; i < tabOpComs.length ; ++i){ + console.log('tabOpComs[i].name' + tabOpComs[i].name); + if(tabOpComs[i].name !== ''){ + let monOpCom = tabOpComs[i]; + console.log('tabOpComs[i].name not vide' + tabOpComs[i].name); + + + + + if (monOpCom !== undefined){ + console.log(monOpCom); + var todayTemp = new Date(Date.now()); + var debutTemp = new Date(monOpCom.dateDebut); + var finTemp = new Date(monOpCom.dateFin); + if (monOpCom.status !== 'Bloqué') { + if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { + if (monOpCom.uid !== undefined && monOpCom.status !== undefined && monOpCom.name !== undefined + && monOpCom.uid !== '' && monOpCom.status !== '' && monOpCom.name !== '') { + console.log(monOpCom.uid); + console.log(monOpCom.status); + monOpCom.status = 'Active'; + } + } else { + if (monOpCom.uid !== undefined && monOpCom.status !== undefined && monOpCom.name !== undefined + && monOpCom.uid !== '' && monOpCom.status !== '' && monOpCom.name !== ''){ + console.log(monOpCom.uid); + console.log(monOpCom.status); + monOpCom.status = 'Inactive'; + } + } + if (monOpCom.uid !== undefined && monOpCom.status !== undefined && monOpCom.name !== undefined + && monOpCom.uid !== '' && monOpCom.status !== '' && monOpCom.name !== '') { + console.log('monOpCom.uid: ' + monOpCom.uid); + console.log('monOpCom.status: ' + monOpCom.status); + const carteStatusRef = firebase.database().ref().child('OperationCommercial').child(monOpCom.uid).child('status'); + carteStatusRef.set(monOpCom.status); + } + } } + } } + } + }); + opComAll.forEach(utilisateur => { + utilisateur.forEach(monOpCom => { + }); }); } updateCarteEtOpCom(){ - //this.updateOpCommStatus(); - //this.updateCarteStatus(); + this.updateOpCommStatus(); + this.updateCarteStatus(); } updateCarteStatus(){ const carteAll = this.getCartes(); + + carteAll.subscribe(tabCarte => { + if (tabCarte.length > 0) { + for (let i = 0; i < tabCarte.length ; ++i){ + console.log('tabCarte[i].parrainCarte.firstname' + tabCarte[i].parrainCarte.firstname); + if (tabCarte[i].parrainCarte.firstname !== '') { + let maCarte = tabCarte[i]; + + if(maCarte !== undefined) { + var todayTemp = new Date(Date.now()); + var debutTemp = new Date(maCarte.dateDebut); + var finTemp = new Date(maCarte.dateFin); + if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { + if(maCarte.status !== undefined && maCarte.uid !== undefined && maCarte.parrainCarte !== undefined + && maCarte.status !== '' && maCarte.uid !== '' && maCarte.parrainCarte.firstname !== '') { + console.log('maCarte.uid: ' + maCarte.uid); + console.log('maCarte.status: ' + maCarte.status); + maCarte.status = 'Active'; + } + } else { + if (maCarte.status !== undefined && maCarte.uid !== undefined && maCarte.parrainCarte !== undefined + && maCarte.status !== '' && maCarte.uid !== '' && maCarte.parrainCarte.firstname !== '') { + console.log('maCarte.uid: ' + maCarte.uid); + console.log('maCarte.status: ' + maCarte.status); + maCarte.status = 'Inactive'; + } + } + if (maCarte.status !== undefined && maCarte.uid !== undefined && maCarte.parrainCarte !== undefined + && maCarte.status !== '' && maCarte.uid !== '' && maCarte.parrainCarte.firstname !== '') { + console.log('maCarte.uid: ' + maCarte.uid); + console.log('maCarte.status: ' + maCarte.status); + const carteStatusRef = firebase.database().ref().child('CarteParrainage').child(maCarte.uid).child('status'); + carteStatusRef.set(maCarte.status); + } + + } + } + } + } + }); carteAll.forEach(utilisateur => { utilisateur.forEach(maCarte => { - if(maCarte !== undefined) { - var todayTemp = new Date(Date.now()); - var debutTemp = new Date(maCarte.dateDebut); - var finTemp = new Date(maCarte.dateFin); - if (todayTemp.getTime() >= debutTemp.getTime() && todayTemp.getTime() <= finTemp.getTime()) { - maCarte.status = 'Active'; - } else { - maCarte.status = 'Inactive'; - } - if (maCarte.uid !== undefined){ - const carteStatusRef = firebase.database().ref().child('CarteParrainage').child(maCarte.uid.toString()).child('status'); - carteStatusRef.set(maCarte.status); - } - } }); }); }