creation Envoyer carte avec bug pour creer nouveau parrain
parent
81810062b2
commit
cbe2548344
@ -0,0 +1,3 @@
|
||||
.card {
|
||||
padding: 5%;
|
||||
}
|
@ -1,18 +1,239 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Router } from '@angular/router';
|
||||
import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';
|
||||
import * as firebase from 'firebase/app';
|
||||
import { AngularFireAuth } from 'angularfire2/auth';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { ProfilService } from '../../../services/profil/profil.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { User } from '../../../../models/User';
|
||||
import { Parrain } from '../../../../models/Parrain';
|
||||
import { Commercant } from '../../../../models/Commercant';
|
||||
import { Image } from '../../../../models/Image';
|
||||
import { OperationCommerciale } from '../../../../models/OperationCommerciale';
|
||||
import { CarteParrainage } from '../../../../models/CarteParrainage';
|
||||
|
||||
import { OpCommercialService } from '../../../services/opCommercial/op-commercial.service';
|
||||
|
||||
import {forEach} from '@angular/router/src/utils/collection';
|
||||
import { AuthService } from '../../../services/auth/auth.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-envoyer-carte',
|
||||
templateUrl: './envoyer-carte.component.html',
|
||||
styleUrls: ['./envoyer-carte.component.scss']
|
||||
styleUrls: ['./envoyer-carte.component.scss'],
|
||||
providers: [AuthService, OpCommercialService]
|
||||
})
|
||||
export class EnvoyerCarteComponent implements OnInit {
|
||||
export class EnvoyerCarteComponent implements OnInit, OnDestroy {
|
||||
|
||||
radioParrain: string;
|
||||
|
||||
user: Observable<firebase.User>;
|
||||
localUser: any;
|
||||
parrain: Parrain;
|
||||
commercant: Commercant;
|
||||
opComm: OperationCommerciale;
|
||||
cartePar: CarteParrainage;
|
||||
|
||||
opCommList: FirebaseListObservable<any[]>;
|
||||
parrainExistList: FirebaseListObservable<any[]>;
|
||||
parrainAffList: FirebaseListObservable<any[]>;
|
||||
carteParList: FirebaseListObservable<any[]>;
|
||||
parSelect: string;
|
||||
selectPar: boolean;
|
||||
parrainAffListTemp = [];
|
||||
|
||||
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
|
||||
private router: Router, private authService: AuthService,
|
||||
private opComService: OpCommercialService, private route: ActivatedRoute) {
|
||||
|
||||
|
||||
|
||||
this.radioParrain = '';
|
||||
|
||||
this.localUser = new User();
|
||||
this.parrain = new Parrain();
|
||||
this.commercant = new Commercant();
|
||||
this.cartePar = new CarteParrainage();
|
||||
this.parrainAffList = null;
|
||||
this.user = afAuth.authState;
|
||||
|
||||
this.user.subscribe(
|
||||
(auth) => {
|
||||
if (auth) {
|
||||
// initialisation carte
|
||||
this.route.params.subscribe(params => {
|
||||
// this.test = params['idOp'];
|
||||
this.opCommList = this.afDb.list('/OperationCommercial/', {
|
||||
query: {
|
||||
orderByChild: 'uid',
|
||||
equalTo: params['idOp']
|
||||
}
|
||||
}
|
||||
);
|
||||
this.opCommList.forEach(op => {
|
||||
op.forEach(element => {
|
||||
this.opComm = element;
|
||||
this.cartePar.commercantID = this.opComm.idCommercant;
|
||||
this.cartePar.operationCommercialID = this.opComm.uid;
|
||||
this.cartePar.dateDebut = this.opComm.dateDebut;
|
||||
this.cartePar.dateFin = this.opComm.dateFin;
|
||||
this.cartePar.carteTemplate = this.opComm.carteTemplate;
|
||||
});
|
||||
});
|
||||
// fin initialisation carte
|
||||
// si parrain affilié
|
||||
this.carteParList = this.afDb.list('/CarteParrainage/', {
|
||||
query: {
|
||||
orderByChild: 'operationCommercialID',
|
||||
equalTo: params['idOp']
|
||||
}
|
||||
}
|
||||
);
|
||||
console.log(params['idOp']);
|
||||
this.carteParList.forEach(carte => {
|
||||
|
||||
console.log('carte :' + carte.length);
|
||||
|
||||
carte.forEach(elementCarte => {
|
||||
console.log("elementCarte.parrainID : " + elementCarte.parrainID);
|
||||
this.parrainAffList = this.afDb.list('/Parrain/', {
|
||||
query: {
|
||||
orderByChild: 'uid',
|
||||
equalTo: elementCarte.parrainID
|
||||
}
|
||||
}
|
||||
);
|
||||
this.parrainAffList.forEach(parAf => {
|
||||
parAf.forEach(elementparAf => {
|
||||
this.parrainAffListTemp.push(
|
||||
{
|
||||
uid : elementparAf.uid,
|
||||
firstname : elementparAf.firstname,
|
||||
familyname: elementparAf.familyname
|
||||
});
|
||||
console.log("elementparAf.firstname" + elementparAf.firstname);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// fin si parrain affilié
|
||||
// si parrain exist non affilié
|
||||
this.parrainExistList = this.afDb.list('/Parrain/', {
|
||||
query: {
|
||||
orderByChild: 'uid'
|
||||
}
|
||||
}
|
||||
);
|
||||
// fin si parrain exist non affilié
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
registerNewParrain() {
|
||||
this.parrain.status = 'Parrain';
|
||||
this.parrain.secretCode = this.getRandomArbitrary(1111, 9999).toString();
|
||||
this.parrain.password = this.getRandomArbitrary(111111, 999999).toString();
|
||||
// this.authService.signUp(this.parrain);
|
||||
|
||||
firebase.auth().createUserWithEmailAndPassword(this.parrain.email, this.parrain.password).then(userCreate => {
|
||||
this.cartePar.parrainID = userCreate.uid;
|
||||
this.authService.setUserInfo(userCreate, this.parrain);
|
||||
});
|
||||
|
||||
}
|
||||
getRandomArbitrary(min, max) {
|
||||
return Math.trunc(Math.random() * (max - min) + min);
|
||||
}
|
||||
initParSelect(){
|
||||
this.parSelect = '';
|
||||
}
|
||||
|
||||
getIdParrain(parUid) {
|
||||
this.cartePar.parrainID = parUid;
|
||||
this.selectPar = true;
|
||||
|
||||
constructor(private router: Router) { }
|
||||
|
||||
|
||||
if (this.radioParrain === 'ParrainAffi'){
|
||||
for (let i = 0; i < this.parrainAffListTemp.length; i++) {
|
||||
if (this.parrainAffListTemp[i].uid === parUid) {
|
||||
this.parSelect = 'vous avez selectionner le parrain : '
|
||||
+ this.parrainAffListTemp[i].familyname + ' '
|
||||
+ this.parrainAffListTemp[i].firstname;
|
||||
}
|
||||
}
|
||||
} else if (this.radioParrain === 'ParrainExist'){
|
||||
this.parrainExistList.forEach(parEx => {
|
||||
parEx.forEach(elementparEx => {
|
||||
if (elementparEx.uid === parUid){
|
||||
this.parSelect = 'vous avez selectionner le parrain : '
|
||||
+ elementparEx.familyname + ' '
|
||||
+ elementparEx.firstname;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
console.log('this.cartePar.commercantID : ' + this.cartePar.commercantID);
|
||||
console.log('this.cartePar.parrainID : ' + this.cartePar.parrainID);
|
||||
console.log('this.cartePar.operationCommercialID : ' + this.cartePar.operationCommercialID);
|
||||
console.log('this.cartePar.dateDebut : ' + this.cartePar.dateDebut);
|
||||
console.log('this.cartePar.dateFin : ' + this.cartePar.dateFin);
|
||||
}
|
||||
|
||||
|
||||
creerCartePar() {
|
||||
this.opComService.creerCartePar(this.cartePar);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
|
||||
ngOnDestroy() {
|
||||
this.radioParrain = '';
|
||||
this.cartePar = {
|
||||
uid: '',
|
||||
parrainID: '',
|
||||
commercantID: '',
|
||||
operationCommercialID: '',
|
||||
dateDebut: new Date(),
|
||||
dateFin: new Date(),
|
||||
avantageCumule: '',
|
||||
avantageRecuperer: '',
|
||||
carteTemplate: new Image(),
|
||||
status: ''
|
||||
};
|
||||
this.localUser = {
|
||||
uid: '',
|
||||
image: new Image(),
|
||||
email: '',
|
||||
emailVerified: false,
|
||||
password: '',
|
||||
status: ''
|
||||
};
|
||||
this.parrain = {
|
||||
uid: '',
|
||||
image: new Image(),
|
||||
email: '',
|
||||
emailVerified: false,
|
||||
password: '',
|
||||
familyname: '',
|
||||
firstname: '',
|
||||
sex: '',
|
||||
birthday: new Date(),
|
||||
telephone: '',
|
||||
idCard: '',
|
||||
secretCode: '',
|
||||
status: ''
|
||||
};
|
||||
}
|
||||
goToOpComm() {
|
||||
this.router.navigate(['/opCommercial']);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue