creation et implementation de scanner carte
parent
092d642c2b
commit
64b83bed40
@ -0,0 +1,109 @@
|
||||
<!--
|
||||
|
||||
<ul>
|
||||
<li *ngFor="let fil of filleulExistList | async">
|
||||
Filleuls: {{fil.firstname}} {{fil.familyname}}
|
||||
</li>
|
||||
</ul>-->
|
||||
|
||||
|
||||
<div class="container" style="padding-top:10%">
|
||||
<div class="card">
|
||||
<div class="well">
|
||||
<p class="h5 text-center mb-4">Scanner Carte</p>
|
||||
<p class="text-center mb-4" style="padding-top: 2%;">Choisissez quelle type de fieulle voulez-vous scanner la carte</p>
|
||||
<form class="form-inline flex-center">
|
||||
<div class="md-form" style="padding-left: 2%;">
|
||||
<input name="group2" type="radio" class="with-gap" id="Newfilleul" value="Newfilleul" (click)="initFilSelect()" [(ngModel)]="radioFilleul">
|
||||
<label for="Newfilleul">Nouveau Filleul</label>
|
||||
</div>
|
||||
<div class="md-form" style="padding-left: 2%;">
|
||||
<input name="group2" type="radio" class="with-gap" id="FilleulExist" value ="FilleulExist" (click)="initFilSelect()" [(ngModel)]="radioFilleul">
|
||||
<label for="FilleulExist">Filleul Existant</label>
|
||||
</div>
|
||||
</form>
|
||||
<!-- Si cest un nouveau filleul -->
|
||||
<div *ngIf="radioFilleul === 'Newfilleul'">
|
||||
<div class="md-form">
|
||||
<i class="fa fa-user prefix grey-text"></i>
|
||||
<input type="text" id="orangeForm-Familyname" [(ngModel)]="filleul.idCard" placeholder="ID carte">
|
||||
</div>
|
||||
<div class="md-form">
|
||||
<i class="fa fa-user prefix grey-text"></i>
|
||||
<input type="text" id="orangeForm-Familyname" [(ngModel)]="filleul.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)]="filleul.firstname" placeholder="Firstname">
|
||||
</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)]="filleul.sex">
|
||||
<label for="homme">Homme</label>
|
||||
</div>
|
||||
<div class="md-form" style="padding-left: 2%;">
|
||||
<input name="group3" type="radio" class="with-gap" id="femme" value="Femme" [(ngModel)]="filleul.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)]="filleul.birthday" placeholder="Birthday">
|
||||
</div>
|
||||
<div class="md-form">
|
||||
<i class="fa fa-envelope prefix grey-text"></i>
|
||||
<input type="email" id="orangeForm-email" [(ngModel)]="filleul.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@filleul.fr</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-light-green waves-light" [disabled]="email.errors" (click)="registerNewFilleul()">Creer nouveau filleul & scanner carte</button>
|
||||
<button class="btn btn-cyan" (click)="goToOpComm()">Back</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Fin Si cest un nouveau filleul -->
|
||||
|
||||
<!-- Si cest un filleul existant -->
|
||||
<div *ngIf="radioFilleul === 'FilleulExist'">
|
||||
|
||||
<p>{{filleulSelect}}</p>
|
||||
<input
|
||||
#query
|
||||
(keyup)="filter(query.value)"
|
||||
type="text" class="form-control" placeholder="Cherchez Filleul Existants...">
|
||||
<div *ngFor="let filleul of filteredFilleulsTest">
|
||||
<a (click)="getIdFilleul(filleul.uid)">{{filleul.firstname}} {{filleul.familyname}}</a>
|
||||
<p>
|
||||
Carte ID:
|
||||
{{filleul?.idCard}}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-form" style="padding-top:2%;">
|
||||
<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-light-green waves-light" [disabled]="filleulSelect === ''" (click)="scanCarteFil()">Scanner Carte du filleul</button>
|
||||
<button class="btn btn-cyan" (click)="goToOpComm()">Back</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Fin Si cest un filleul existant -->
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,3 @@
|
||||
.card {
|
||||
padding: 5%;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ScannerCarteComponent } from './scanner-carte.component';
|
||||
|
||||
describe('ScannerCarteComponent', () => {
|
||||
let component: ScannerCarteComponent;
|
||||
let fixture: ComponentFixture<ScannerCarteComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ScannerCarteComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ScannerCarteComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,226 @@
|
||||
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 { Subject } from 'rxjs/Subject';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
import {forEach} from '@angular/router/src/utils/collection';
|
||||
import { AuthService } from '../../../services/auth/auth.service';
|
||||
import { Filleul } from '../../../../models/Filleul';
|
||||
import { Scan } from '../../../../models/Scan';
|
||||
|
||||
@Component({
|
||||
selector: 'app-scanner-carte',
|
||||
templateUrl: './scanner-carte.component.html',
|
||||
styleUrls: ['./scanner-carte.component.scss'],
|
||||
providers: [AuthService, OpCommercialService]
|
||||
})
|
||||
export class ScannerCarteComponent implements OnInit, OnDestroy {
|
||||
|
||||
filleulSelect: string;
|
||||
radioFilleul: string;
|
||||
user: Observable<firebase.User>;
|
||||
localUser: any;
|
||||
filleul: Filleul;
|
||||
scan: Scan;
|
||||
commercant: Commercant;
|
||||
opComm: OperationCommerciale;
|
||||
cartePar: CarteParrainage;
|
||||
|
||||
commList: FirebaseListObservable<any[]>;
|
||||
opCommList: FirebaseListObservable<any[]>;
|
||||
filleulExistList: FirebaseListObservable<any[]>;
|
||||
|
||||
databaseRef: any;
|
||||
|
||||
/////
|
||||
filleulTest: Filleul[];
|
||||
filteredFilleulsTest: any[];
|
||||
filleulListTemp = [];
|
||||
subscription: Subscription;
|
||||
//startAt = new Subject();
|
||||
//endAt = new Subject();
|
||||
/////
|
||||
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
|
||||
private router: Router, private authService: AuthService,
|
||||
private opComService: OpCommercialService, private route: ActivatedRoute) {
|
||||
|
||||
this.radioFilleul = '';
|
||||
this.filleulSelect = '';
|
||||
this.filleul = new Filleul();
|
||||
this.scan = new Scan();
|
||||
this.commercant = new Commercant();
|
||||
this.cartePar = new CarteParrainage();
|
||||
this.filleulExistList = null;
|
||||
this.user = afAuth.authState;
|
||||
this.databaseRef = firebase.database().ref();
|
||||
this.user.subscribe(
|
||||
(auth) => {
|
||||
if (auth) {
|
||||
this.commList = this.afDb.list('/Commercant/', {
|
||||
query: {
|
||||
orderByChild: 'uid',
|
||||
equalTo: auth.uid.toString()
|
||||
}
|
||||
}
|
||||
);
|
||||
this.commList.forEach(commerc => {
|
||||
commerc.forEach(elementCommerc => {
|
||||
this.commercant = elementCommerc;
|
||||
});
|
||||
});
|
||||
// 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;
|
||||
});
|
||||
});
|
||||
});
|
||||
// fin si parrain affilié
|
||||
// si parrain exist non affilié
|
||||
this.filleulExistList = this.afDb.list('/Filleul/', {
|
||||
query: {
|
||||
orderByChild: 'uid'
|
||||
}
|
||||
}
|
||||
);
|
||||
this.filleulExistList.forEach(fill => {
|
||||
fill.forEach(elementfillAf => {
|
||||
this.filleulListTemp.push(
|
||||
{
|
||||
uid: elementfillAf.uid,
|
||||
firstname: elementfillAf.firstname,
|
||||
familyname: elementfillAf.familyname
|
||||
});
|
||||
});
|
||||
});
|
||||
// fin si parrain exist non affilié
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
goToOpComm() {
|
||||
this.router.navigate(['/opCommercial']);
|
||||
}
|
||||
filter(query: string) {
|
||||
this.filteredFilleulsTest = (query) ?
|
||||
this.filleulTest.filter(f => (f.firstname.toLowerCase() + f.familyname.toLowerCase()).includes(query.toLowerCase())) :
|
||||
[];
|
||||
}
|
||||
registerNewFilleul(){
|
||||
console.log(this.filleul.familyname);
|
||||
console.log(this.filleul.firstname);
|
||||
console.log(this.filleul.familyname);
|
||||
|
||||
this.filleul.status = 'Filleul';
|
||||
this.filleul.uid = firebase.database().ref().child('Filleul').push().key;
|
||||
const userRef = this.databaseRef.child('Filleul').child(this.filleul.uid);
|
||||
userRef.set(this.filleul);
|
||||
this.scanCarteFil();
|
||||
}
|
||||
scanCarteFil(){
|
||||
this.scan.uid = firebase.database().ref().child('Scan').push().key;
|
||||
this.scan.carteParrainID = this.filleul.idCard;
|
||||
this.scan.carteFilleulID = this.filleul.idCard;
|
||||
console.log(Date.now());
|
||||
this.scan.valeurParrain = this.opComm.avantageParrain;
|
||||
this.scan.valeurFilleul = this.opComm.avantageFilleul;
|
||||
console.log(this.scan.uid);
|
||||
console.log(this.scan.carteParrainID);
|
||||
console.log(this.scan.carteFilleulID);
|
||||
console.log(this.scan.valeurParrain);
|
||||
console.log(this.scan.valeurFilleul);
|
||||
const userRef = this.databaseRef.child('Scan').child(this.scan.uid);
|
||||
userRef.set(this.scan);
|
||||
}
|
||||
|
||||
getIdFilleul(filUid) {
|
||||
this.filleulExistList.forEach(fill => {
|
||||
fill.forEach(elementfillAf => {
|
||||
if (elementfillAf.uid === filUid) {
|
||||
this.filleulSelect = 'Vous avez selectionner le filleul : '
|
||||
+ elementfillAf.familyname + ' '
|
||||
+ elementfillAf.firstname;
|
||||
this.filleul = elementfillAf;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
initFilSelect(){
|
||||
this.filleulSelect = '';
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.subscription = this.opComService.getFilleuls()
|
||||
.subscribe(filleuls => this.filleulTest = filleuls);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscription.unsubscribe();
|
||||
this.radioFilleul = '';
|
||||
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.filleul = {
|
||||
uid: '',
|
||||
email: '',
|
||||
familyname: '',
|
||||
firstname: '',
|
||||
sex: '',
|
||||
birthday: new Date(),
|
||||
idCard: '',
|
||||
status: ''
|
||||
};
|
||||
|
||||
this.scan = {
|
||||
uid: '',
|
||||
carteParrainID: '',
|
||||
carteFilleulID: '',
|
||||
dateCreation: new Date(),
|
||||
valeurParrain: '',
|
||||
valeurFilleul: '',
|
||||
type: ''
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
export class Filleul
|
||||
{
|
||||
uid: string;
|
||||
familyname: string;
|
||||
firstname: string;
|
||||
sex: string;
|
||||
birthday: Date;
|
||||
email: string;
|
||||
idCard: string;
|
||||
status: string;
|
||||
|
||||
constructor() {
|
||||
this.uid = '';
|
||||
this.familyname = '';
|
||||
this.firstname = '';
|
||||
this.sex = '';
|
||||
this.birthday = new Date();
|
||||
this.email = '';
|
||||
this.idCard = '';
|
||||
this.status = '';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue