creation Envoyer carte avec bug pour creer nouveau parrain

thierry
Tmadkaud 7 years ago
parent 81810062b2
commit cbe2548344

@ -15,5 +15,5 @@ export const AppRoutes = [
{path: 'opCommercial', component: OpCommercialComponent},
{path: 'creationOpCommercial', component: CreationOpComComponent},
{path: 'carteParrainageComponent', component: CarteParrainageComponent},
{path: 'EnvoyerCarte', component: EnvoyerCarteComponent},
{path: 'EnvoyerCarte/:idOp', component: EnvoyerCarteComponent},
];

@ -1,8 +1,12 @@
<p>
envoyer-carte works!
</p>
<button (click)="goToOpComm()">Back</button>
<ul>
<li *ngFor="let par of parrainExistList | async">
Parrains: {{par.firstname}} {{par.familyname}}
</li>
</ul>
@ -13,21 +17,21 @@
<label>
<form class="form-inline">
<div class="md-form">
<input name="group2" type="radio" class="with-gap" id="Newparrain" value="Newparrain">
<input name="group2" type="radio" class="with-gap" id="Newparrain" value="Newparrain" (click)="initParSelect()" [(ngModel)]="radioParrain">
<label for="Newparrain">Nouveau Parrain</label>
</div>
<div class="md-form">
<input name="group2" type="radio" class="with-gap" id="ParrainExist" value ="ParrainExist">
<input name="group2" type="radio" class="with-gap" id="ParrainExist" value ="ParrainExist" (click)="initParSelect()" [(ngModel)]="radioParrain">
<label for="ParrainExist">Parrain Existant</label>
</div>
<div class="md-form">
<input name="group2" type="radio" class="with-gap" id="ParrainExistAffi" value ="ParrainExistAffi">
<label for="ParrainExistAffi">Parrain Existant Affilier</label>
<input name="group2" type="radio" class="with-gap" id="ParrainAffi" value ="ParrainAffi" (click)="initParSelect()" [(ngModel)]="radioParrain">
<label for="ParrainAffi">Parrain Affilier</label>
</div>
</form>
</label>
<!--Si cest un parrain-->
<div *ngIf="false" class="alert alert-danger">
<!-- Si cest un nouveau parrain -->
<div *ngIf="radioParrain === 'Newparrain'" class="alert alert-danger">
<div class="md-form">
<i class="fa fa-user prefix grey-text"></i>
@ -65,32 +69,26 @@
données, y compris notre Utilisation des cookies.
</label>
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" [disabled]="email.errors">Creer nouveau parrain & envoyer carte</button>
<button class="btn btn-deep-orange" [disabled]="email.errors" (click)="registerNewParrain()">Creer nouveau parrain & envoyer carte</button>
<button class="btn btn-cyan" (click)="goToOpComm()">Back</button>
</div>
</div>
<!--Fin Si cest un parrain-->
<!--Si cest un commercant-->
<div *ngIf="true" class="alert alert-danger">
<!-- Fin Si cest un nouveau parrain -->
<!-- Si cest un parrain existant -->
<div *ngIf="radioParrain === 'ParrainExist'" class="alert alert-danger">
<p>{{parSelect}}</p>
<div class="dropdown" dropdown>
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle waves-light" mdbRippleRadius>
Dropdown
Parrains Existants
</button>
<div class="dropdown-menu">
<h6 class="dropdown-header">Parrains</h6>
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<h6 class="dropdown-header">Parrains Existants</h6>
<a class="dropdown-item" *ngFor="let par of parrainExistList | async" (click)="getIdParrain(par.uid)">{{par.firstname}} {{par.familyname}}</a>
</div>
</div>
<div class="md-form">
<i class="fa fa-birthday-cake prefix grey-text"></i>
<input type="date" id="orangeForm-Birthday" placeholder="Birthday">
@ -102,44 +100,41 @@
données, y compris notre Utilisation des cookies.
</label>
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" (click)="register()">S'inscrire</button>
<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>
<button class="btn btn-deep-orange" [disabled]="parSelect === ''" (click)="creerCartePar()">Envoyer Carte et affilié le parrain</button>
<button class="btn btn-cyan" (click)="goToOpComm()">Back</button>
</div>
</div>
<!--Fin Si cest un commercant-->
<!--Si cest un connu et affilié-->
<div *ngIf="false" class="alert alert-danger">
<!-- Fin Si cest un parrain existant -->
<!-- Si cest un parrain connu et affilié -->
<div *ngIf="radioParrain === 'ParrainAffi'" class="alert alert-danger">
<p>{{parSelect}}</p>
<div class="dropdown" dropdown>
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle waves-light" mdbRippleRadius>
Dropdown
Parrains Affilié
</button>
<div class="dropdown-menu">
<h6 class="dropdown-header">Parrains existant</h6>
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<h6 class="dropdown-header">Parrains Affilié</h6>
<a class="dropdown-item" *ngFor="let parAf of parrainAffListTemp" (click)="getIdParrain(parAf.uid)">{{parAf.firstname}}</a>
</div>
</div>
<div class="md-form">
<i class="fa fa-birthday-cake prefix grey-text"></i>
<input type="date" id="orangeForm-Birthday" placeholder="Birthday">
</div>
<div class="md-form">
<i class="fa fa-birthday-cake prefix grey-text"></i>
<input type="date" id="orangeForm-Birthday" placeholder="Birthday">
</div>
<label>
En cliquant sur Créer un compte, vous acceptez nos Conditions
et indiquez que vous aves lu notre Politique d'utilisation des
données, y compris notre Utilisation des cookies.
</label>
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" (click)="register()">S'inscrire</button>
<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>
<label>
En cliquant sur Créer un compte, vous acceptez nos Conditions
et indiquez que vous aves lu notre Politique d'utilisation des
données, y compris notre Utilisation des cookies.
</label>
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" [disabled]="parSelect === ''" (click)="register()">S'inscrire</button>
<button class="btn btn-cyan" (click)="goToOpComm()">Back</button>
</div>
</div>
<!-- Fin Si cest un parrain connu et affilié -->
</div>
<!--Fin Si cest un connu et affilié-->
</div>
</div>

@ -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']);
}
}

@ -15,7 +15,7 @@
<div class="btn-group">
<button (click)="goToCreaOpCom()">Nouvelle opération Commercial</button>
<button (click)="goToProfil()">Profil</button>
<button (click)="goToEnCart()">Envoyer carte</button>
</div>
<div class="list-group">
<div class="card mainCard" *ngFor="let op of opCommData | async">
@ -36,6 +36,7 @@
</div>
<div class="col-md-6 card subCard2">
<label>Operation Commerciale: {{op.name}}</label>
<button (click)="goToEnCart(op.uid)">Envoyer carte</button>
</div>
</div>
</div>

@ -62,14 +62,14 @@ export class OpCommercialComponent implements OnInit, OnDestroy {
);
}
goToCreaOpCom(){
goToCreaOpCom() {
this.router.navigate(['/creationOpCommercial']);
}
goToProfil(){
goToProfil() {
this.router.navigate(['/profil']);
}
goToEnCart(){
this.router.navigate(['/EnvoyerCarte']);
goToEnCart(idOp) {
this.router.navigate(['/EnvoyerCarte', idOp]);
}
ngOnInit() {
}

@ -17,77 +17,75 @@
<!--Si cest un parrain-->
<div *ngIf="currentUser.status === 'Parrain'" class="alert alert-danger">
<div class="md-form">
<i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Familyname" [(ngModel)]="parrain.familyname" placeholder="Family name">
</div>
<div class="md-form">
<i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Firstname" [(ngModel)]="parrain.firstname" placeholder="Firstname">
</div>
<div class="md-form">
<i class="fa fa-file-picture-o prefix grey-text"></i>
<input type="file" id="orangeForm-File" name="file">
</div>
<form class="form-inline">
<div class="md-form">
<i class="fa fa-venus-mars prefix grey-text"></i>
<input name="group3" type="radio" class="with-gap" id="homme" value="Homme" [(ngModel)]="parrain.sex">
<label for="homme">Homme</label>
<i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Familyname" [(ngModel)]="parrain.familyname" placeholder="Family name">
</div>
<div class="md-form">
<input name="group3" type="radio" class="with-gap" id="femme" value="Femme" [(ngModel)]="parrain.sex">
<label for="femme">Femme</label>
<i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Firstname" [(ngModel)]="parrain.firstname" placeholder="Firstname">
</div>
</form>
<div class="md-form">
<i class="fa fa-birthday-cake prefix grey-text"></i>
<input type="date" id="orangeForm-Birthday" [(ngModel)]="parrain.birthday" placeholder="Birthday">
</div>
<div class="md-form">
<i class="fa fa-tty prefix grey-text"></i>
<input type="text" id="orangeForm-Username" required minlength="10" [(ngModel)]="parrain.telephone" placeholder="Telephone" name="telephone" #telephone="ngModel">
<div *ngIf="telephone.errors && (telephone.dirty || telephone.touched)" class="alert alert-danger">
<strong>Telephone</strong> must have 10 numbers or more
<div class="md-form">
<i class="fa fa-file-picture-o prefix grey-text"></i>
<input type="file" id="orangeForm-File" name="file">
</div>
</div>
<div class="md-form">
<i class="fa fa-envelope prefix grey-text"></i>
<input type="email" id="orangeForm-email" [(ngModel)]="parrain.email" placeholder="Email" name="email" required pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" #email="ngModel">
<div *ngIf="email.errors && email.errors.pattern && (email.dirty || email.touched)" class="alert alert-danger">
Email is required and format should be <strong><i>john@parrain.fr</i></strong>.
<form class="form-inline">
<div class="md-form">
<i class="fa fa-venus-mars prefix grey-text"></i>
<input name="group3" type="radio" class="with-gap" id="homme" value="Homme" [(ngModel)]="parrain.sex">
<label for="homme">Homme</label>
</div>
<div class="md-form">
<input name="group3" type="radio" class="with-gap" id="femme" value="Femme" [(ngModel)]="parrain.sex">
<label for="femme">Femme</label>
</div>
</form>
<div class="md-form">
<i class="fa fa-birthday-cake prefix grey-text"></i>
<input type="date" id="orangeForm-Birthday" [(ngModel)]="parrain.birthday" placeholder="Birthday">
</div>
</div>
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-pass" type="password" [(ngModel)]="parrain.password" placeholder="Password" name="password" #password= "ngModel" required minlength="5">
<div *ngIf="password.errors && (password.dirty || password.touched)" class="alert alert-danger">
<strong>Password</strong> must have more than 5 caracteres
<div class="md-form">
<i class="fa fa-tty prefix grey-text"></i>
<input type="text" id="orangeForm-Username" required minlength="10" [(ngModel)]="parrain.telephone" placeholder="Telephone" name="telephone" #telephone="ngModel">
<div *ngIf="telephone.errors && (telephone.dirty || telephone.touched)" class="alert alert-danger">
<strong>Telephone</strong> must have 10 numbers or more
</div>
</div>
</div>
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-passC" type="password" [(ngModel)]="ConfirmPasswordParrain" placeholder="Confirm your password" name="confirmPassword" #confirmPassword="ngModel">
<div *ngIf="(parrain.password != ConfirmPasswordParrain) && (confirmPassword.touched)" class="alert alert-danger">
Please write the same of your <strong><i>password</i></strong>.
<div class="md-form">
<i class="fa fa-envelope prefix grey-text"></i>
<input type="email" id="orangeForm-email" [(ngModel)]="parrain.email" placeholder="Email" name="email" required pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" #email="ngModel">
<div *ngIf="email.errors && email.errors.pattern && (email.dirty || email.touched)" class="alert alert-danger">
Email is required and format should be <strong><i>john@parrain.fr</i></strong>.
</div>
</div>
</div>
<label>
En cliquant sur Créer un compte, vous acceptez nos Conditions
et indiquez que vous aves lu notre Politique d'utilisation des
données, y compris notre Utilisation des cookies.
</label>
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" [disabled]="email.errors || password.errors || (parrain.password != ConfirmPasswordParrain)" (click)="register()">Sign up</button>
<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>
</div>
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-pass" type="password" [(ngModel)]="parrain.password" placeholder="Password" name="password" #password= "ngModel" required minlength="5">
<div *ngIf="password.errors && (password.dirty || password.touched)" class="alert alert-danger">
<strong>Password</strong> must have more than 5 caracteres
</div>
</div>
<div class="md-form">
<i class="fa fa-lock prefix grey-text"></i>
<input id="orangeForm-passC" type="password" [(ngModel)]="ConfirmPasswordParrain" placeholder="Confirm your password" name="confirmPassword" #confirmPassword="ngModel">
<div *ngIf="(parrain.password != ConfirmPasswordParrain) && (confirmPassword.touched)" class="alert alert-danger">
Please write the same of your <strong><i>password</i></strong>.
</div>
</div>
<label>
En cliquant sur Créer un compte, vous acceptez nos Conditions
et indiquez que vous aves lu notre Politique d'utilisation des
données, y compris notre Utilisation des cookies.
</label>
<div class="text-center" style="margin-top:5%">
<button class="btn btn-deep-orange" [disabled]="email.errors || password.errors || (parrain.password != ConfirmPasswordParrain)" (click)="register()">Sign up</button>
<button class="btn btn-cyan" (click)="loadHomeComponent()">Back</button>
</div>
</div>
<!--Fin Si cest un parrain-->
<!--Si cest un commercant-->
<div *ngIf="currentUser.status === 'Commercant'" class="alert alert-danger">

@ -17,6 +17,7 @@ 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';
@Injectable()
export class OpCommercialService {
@ -37,6 +38,14 @@ export class OpCommercialService {
this.storageRef = firebase.storage().ref();
}
creerCartePar(infoCartePar: CarteParrainage) {
console.log('ba');
infoCartePar.uid = firebase.database().ref().child('CarteParrainage').push().key;
let updates = {};
updates['/CarteParrainage/' + infoCartePar.uid] = infoCartePar;
firebase.database().ref().update(updates);
}
saveOpComm(user: firebase.User, infoOpCom: OperationCommerciale) {
infoOpCom.uid = firebase.database().ref().child('OperationCommercial').push().key;

@ -1,26 +1,29 @@
//nouvelle operation commercial / nouvelle carte
import { Image } from './Image';
export class CarteParrainage
{
uid: string;
parrainID: string;
commercantID: string;
operationCommercialID: string;
dateDebut: Date;
dateFin: Date;
avantageCumule: string;
avantageRecuperer: string;
carteTemplate: string;
carteTemplate: Image;
status: string;
constructor() {
this.uid = '';
this.parrainID = '';
this.commercantID = '';
this.operationCommercialID = '';
this.dateDebut = new Date();
this.dateFin = new Date();
this.avantageCumule = '';
this.avantageRecuperer = '';
this.carteTemplate = '';
this.carteTemplate = new Image();
this.status = '';
}
/*

Loading…
Cancel
Save