logique mathematique v1

thierry
Tmadkaud 7 years ago
parent a72b86db52
commit 077c3f51e7

@ -9,35 +9,6 @@
"**/.*",
"**/node_modules/**"
],
"headers": [
{
"source": "**/*",
"headers": [
{
"key": "Access-Control-Allow-Origin",
"value": "*"
}
]
},
{
"source": "**/*.@(jpg|jpeg|gif|png)",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=7200"
}
]
},
{
"source": "404.html",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=300"
}
]
}
],
"rewrites": [
{
"source": "**",

@ -49,7 +49,7 @@ export class CreationOpComComponent implements OnInit, OnDestroy {
this.user.subscribe(
(auth) => {
if (auth) {
this.opCommData = this.afDb.list('/' + auth.displayName + '/', {
this.opCommData = this.afDb.list('/Commercant/', {
query: {
orderByChild: 'uid',
equalTo: auth.uid.toString()
@ -58,12 +58,15 @@ export class CreationOpComComponent implements OnInit, OnDestroy {
);
this.opCommData.forEach(utilisateur => {
utilisateur.forEach(element => {
console.log('element.uid: ' + element.uid);
console.log('element.uid: ' + element.raisonSociale);
this.opComm.commercantOpCom = element;
this.opComm.status = 'Non active';
// let file = this.selectedFiles.item(0);
// this.opComm.carteTemplate = file;
// this.upload();
this.opComm.nbScan = '';
this.opComm.nbEnvoie = '';
this.opComm.nbDebiter = '';
console.log('element.uid: ' + element.uid);
this.opComService.saveOpComm(element, this.opComm);
});
@ -119,7 +122,10 @@ export class CreationOpComComponent implements OnInit, OnDestroy {
avantageFilleul : '',
deviseAvantageFilleul : '',
tarifXJCFilleul : '',
status : ''
status : '',
nbScan : '',
nbEnvoie : '',
nbDebiter : ''
};
}
}

@ -17,12 +17,15 @@
<!-- Si cest un filleul existant -->
<div class="md-form">
<i class="fa fa-address-card prefix grey-text"></i>
<input type="text" id="orangeForm-Familyname" placeholder="ID carte" ><!--[(ngModel)]="filleul.idCard"-->
<input
#query
(keyup)="filterCarte(query.value)"
type="text" class="form-control" placeholder="ID carte">
<!--<input type="text" id="orangeForm-Familyname" placeholder="ID carte" [(ngModel)]="carteIDTemp">[(ngModel)]="filleul.idCard"-->
</div>
<div class="md-form">
<i class="fa fa-euro prefix grey-text"></i>
<input type="text" id="orangeForm-Familyname" placeholder="Combien le parrain souhaite utiliser ?" ><!--[(ngModel)]="filleul.idCard"-->
<input type="text" id="orangeForm-Familyname" [(ngModel)]="valeurRecup" placeholder="Combien le parrain souhaite utiliser ?" ><!--[(ngModel)]="filleul.idCard"-->
</div>
<!--
<div class="md-form">
@ -39,7 +42,10 @@
-->
<div class="md-form">
<i class="fa fa-user prefix grey-text"></i>
<input type="text" id="orangeForm-Familyname" placeholder="Code confidentiel du parrain" ><!--[(ngModel)]="filleul.idCard"-->
<input type="text" id="orangeForm-Familyname" [(ngModel)]="codeTemp" placeholder="Code confidentiel du parrain" name="codeT" #codeT="ngModel"><!--[(ngModel)]="filleul.idCard"-->
<div *ngIf="(codeTemp !== cartePar.parrainCarte.secretCode) && (codeT.dirty || codeT.touched)" class="alert alert-danger">
Code is required and it should be the same of <strong><i>{{cartePar.parrainCarte.firstname}} {{cartePar.parrainCarte.familyname}}</i></strong>.
</div>
</div>
<label>
@ -48,7 +54,7 @@
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" (click)="debiterCarte()">Débiter Carte</button>
<button class="btn btn-light-green waves-light" [disabled]="codeTemp !== cartePar.parrainCarte.secretCode" (click)="debiterCarte()">Débiter Carte</button>
<button class="btn btn-cyan" (click)="goToOpComm()">Back</button>
</div>

@ -50,6 +50,13 @@ export class DebiterCarteComponent implements OnInit, OnDestroy {
parrainsTest: Parrain[];
filteredParrainsTest: any[];
subscription: Subscription;
carteTest: Filleul[];
codeTemp: string;
valeurRecup: string;
filteredCartesTest: any[];
subscriptionCarte: Subscription;
//startAt = new Subject();
//endAt = new Subject();
/////
@ -57,7 +64,6 @@ export class DebiterCarteComponent implements OnInit, OnDestroy {
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();
@ -65,21 +71,69 @@ export class DebiterCarteComponent implements OnInit, OnDestroy {
this.parrainAffList = null;
this.user = afAuth.authState;
this.databaseRef = firebase.database().ref();
}
debiterCarte(){}
getIdParrain(parUid) {
this.parrainExistList.forEach(parEx => {
parEx.forEach(elementparEx => {
if (elementparEx.uid === parUid){
this.parSelect = 'Vous avez selectionner le parrain : '
+ elementparEx.familyname + ' '
+ elementparEx.firstname;
this.user.subscribe(
(auth) => {
if (auth) {
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;
});
});
});
}
});
});
}
filterCarte(query: string) {
this.filteredCartesTest = (query) ?
this.carteTest.filter(c => (c.uid).includes(query)) :
[];
if (this.filteredCartesTest !== []){
for(let i = 0; i < this.filteredCartesTest.length;i++){
if (this.filteredCartesTest[i].uid === query) {
console.log('succes id carte est: ' + this.filteredCartesTest[i].uid);
console.log('succes parrain carte est: ' + this.filteredCartesTest[i].parrainCarte.firstname);
console.log('succes code secret parrain carte est: ' + this.filteredCartesTest[i].parrainCarte.secretCode);
this.cartePar = this.filteredCartesTest[i];
}else{
console.log('echec de la carte ! ');
}
}
}
}
debiterCarte() {
console.log('+this.cartePar.avantageCumule : ' + (+this.cartePar.avantageCumule));
console.log('+this.cartePar.avantageRecuperer : ' + (+this.cartePar.avantageRecuperer));
this.cartePar.avantageCumule = ((+this.cartePar.avantageCumule) - (+this.valeurRecup)).toString();
this.cartePar.avantageRecuperer = ((+this.cartePar.avantageRecuperer) + (+this.valeurRecup)).toString();
console.log('+this.cartePar.avantageCumule : ' + this.cartePar.avantageCumule);
console.log('+this.cartePar.avantageRecuperer : ' + this.cartePar.avantageRecuperer);
console.log('carte iiiiid: ' + this.cartePar.uid);
const carteCumuRef = this.databaseRef.child('CarteParrainage').child(this.cartePar.uid.toString()).child('avantageCumule');
carteCumuRef.set(this.cartePar.avantageCumule);
const carteRecuRef = this.databaseRef.child('CarteParrainage').child(this.cartePar.uid.toString()).child('avantageRecuperer');
carteRecuRef.set(this.cartePar.avantageRecuperer);
console.log(this.opComm.nbDebiter);
this.opComm.nbDebiter = ((+this.opComm.nbDebiter) + 1).toString();
console.log(this.opComm.nbDebiter);
const opEnvRef = this.databaseRef.child('OperationCommercial').child(this.opComm.uid.toString()).child('nbDebiter');
opEnvRef.set(this.opComm.nbDebiter);
}
filter(query: string) {
this.filteredParrainsTest = (query) ?
this.parrainsTest.filter(p => (p.firstname.toLowerCase() + p.familyname.toLowerCase()).includes(query.toLowerCase())) :
@ -93,11 +147,14 @@ export class DebiterCarteComponent implements OnInit, OnDestroy {
ngOnInit() {
this.subscription = this.opComService.getParrains()
.subscribe(parrains => this.parrainsTest = parrains);
this.subscriptionCarte = this.opComService.getCartes()
.subscribe(cartes => this.carteTest = cartes);
}
//////
ngOnDestroy() {
this.subscription.unsubscribe();
this.subscriptionCarte.unsubscribe();
this.cartePar = {
uid: '',
name: '',

@ -77,7 +77,7 @@
<!-- Si cest un parrain existant -->
<div *ngIf="radioParrain === 'ParrainExist'">
<p>{{parSelect}}</p>
<!--
<div class="dropdown" dropdown>
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle waves-light" mdbRippleRadius>
@ -119,7 +119,7 @@
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]="(parSelect === '') || (birthdayTemp !== parrain.birthday)" (click)="creerCartePar()">Envoyer Carte et affilié le parrain</button>
<button class="btn btn-light-green waves-light" [disabled]="(parSelect === '') || (birthdayTemp !== parrain.birthday)" (click)="creerCartePar()">Envoyer Carte {{parSelect}}</button>
<button class="btn btn-cyan" (click)="goToOpComm()">Back</button>
</div>
</div>

@ -102,11 +102,11 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
this.opComm = element;
this.cartePar.uid = firebase.database().ref().child('CarteParrainage').push().key;
this.cartePar.name = this.opComm.name;
this.cartePar.commercantCarte.uid = this.opComm.commercantOpCom.uid;
this.cartePar.commercantCarte = this.opComm.commercantOpCom;
this.cartePar.operationCommercialID = this.opComm.uid;
this.cartePar.dateDebut = this.opComm.dateDebut;
this.cartePar.dateFin = this.opComm.dateFin;
console.log('this.opComm.dateFin: '+ this.opComm.dateFin);
console.log('this.opComm.dateFin: ' + this.opComm.dateFin);
/*
var dateTest = this.opComm.dateFin.toString().split(/[- :]/);
this.cartePar.dateFin = new Date(Number(dateTest[0]), Number(dateTest[1]) - 1,
@ -124,11 +124,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
}
}
);
console.log(params['idOp']);
this.carteParList.forEach(carte => {
console.log('carte :' + carte.length);
carte.forEach(elementCarte => {
console.log("elementCarte..parrainCarte.uid : " + elementCarte.parrainCarte.uid);
this.parrainAffList = this.afDb.list('/Parrain/', {
@ -178,6 +174,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
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);
@ -193,14 +190,14 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
emailVerified: true
});
this.cartePar.parrainCarte.uid = userCreate.uid;
this.cartePar.parrainCarte = userCreate;
this.parrain.uid = userCreate.uid;
this.parrain.emailVerified = userCreate.emailVerified;
userRef.set(this.parrain);
this.creerCartePar();
firebase.auth().sendPasswordResetEmail(this.parrain.email);
userCreate.sendEmailVerification()
userCreate.sendEmailVerification();
firebase.auth().signOut();
firebase.auth().signInWithEmailAndPassword(this.commercant.email, this.commercant.password);
});
@ -214,8 +211,19 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
}
getIdParrain(parUid) {
var parlistTemp = this.afDb.list('/Parrain/', {
query: {
orderByChild: 'uid',
equalTo: parUid
}
}
);
this.cartePar.parrainCarte.uid = parUid;
parlistTemp.forEach(par => {
par.forEach(elementParTemp => {
this.cartePar.parrainCarte = elementParTemp;
});
});
this.selectPar = true;
@ -223,7 +231,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
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.parSelect = ' à : '
+ this.parrainAffListTemp[i].familyname + ' '
+ this.parrainAffListTemp[i].firstname;
}
@ -232,7 +240,7 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
this.parrainExistList.forEach(parEx => {
parEx.forEach(elementparEx => {
if (elementparEx.uid === parUid){
this.parSelect = 'Vous avez selectionner le parrain : '
this.parSelect = ' à : '
+ elementparEx.familyname + ' '
+ elementparEx.firstname;
}
@ -262,10 +270,16 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
creerCartePar() {
// this.opComService.creerCartePar(this.cartePar);
// this.opComService.creerCartePar(this.cartePar); inutile
this.sectionToImage(this.cartePar);
// console.log('iiiiiiiii :' + this.opComService.saveImg(this.cartePar));
console.log(this.opComm.nbEnvoie);
this.opComm.nbEnvoie = ((+this.opComm.nbEnvoie) + 1).toString();
console.log(this.opComm.nbEnvoie);
const opEnvRef = this.databaseRef.child('OperationCommercial').child(this.opComm.uid.toString()).child('nbEnvoie');
opEnvRef.set(this.opComm.nbEnvoie);
}
sectionToImage(maCarteP: CarteParrainage) {
@ -297,8 +311,6 @@ export class EnvoyerCarteComponent implements OnInit, OnDestroy {
nouvelleImg.src = blob;
storageRef.child('CarteParrainage/' + maCarteP.uid + '/carteTemplate').put(blob).then((snapshot) => {
// console.log('Uploaded a blob or file! Now storing the reference at', `/${this.folder}/images/`);
// this.afDb.list(`/${folder}/`).push({ path: path, filename: selectedFile.name });
let updates = {};
maCarteP.carteTemplate.path = 'CarteParrainage/' + maCarteP.uid + '/carteTemplate';
maCarteP.carteTemplate.filename = maCarteP.name;

@ -41,21 +41,19 @@
<label>Operation Commerciale: {{op.name}}</label>
</div>
<div id="opAvantages">
<label>Avantage parrain:</label>
<label>Avantage filleul:</label>
<label>Avantage parrain: {{op.avantageParrain}}</label>
<label>Avantage filleul: {{op.avantageFilleul}}</label>
</div>
<div id="opLogs">
<label>Carte(s) envoyée(s):</label>
<label>Carte(s) scannée(s):</label>
<label>Carte(s) débitée(s):</label>
<label>Carte(s) envoyée(s): {{op.nbEnvoie}}</label>
<label>Carte(s) scannée(s): {{op.nbScan}}</label>
<label>Carte(s) débitée(s): {{op.nbDebiter}}</label>
</div>
</div>
<div class="col-md-2" id="subCard2Part2">
<button class="btn btn-outline-primary btn-rounded" (click)="goToEnCart(op.uid)">Envoyer</button>
<button class="btn btn-outline-default btn-rounded" (click)="goToScanCart(op.uid)">Scanner</button>
<button class="btn btn-outline-info btn-rounded" (click)="goToDebiterCart(op.uid)">Débiter</button>
<!--<button class="btn btn-outline-info btn-rounded" (click)="sectionToImage(op.carteTemplate.downloadURL, commercant.image.downloadURL)">screenShot</button>-->
</div>
</div>
<div class="card-block col-md-12" id="subCard2Part3">

@ -28,7 +28,7 @@ import { Commercant } from '../../../../models/Commercant';
var $ = require('jquery')(window);
});*/
//import { Image } from '../../../../models/Image';
// import { Image } from '../../../../models/Image';
@Component({
selector: 'app-op-commercial',
templateUrl: './op-commercial.component.html',
@ -93,370 +93,9 @@ export class OpCommercialComponent implements OnInit, OnDestroy {
goToDebiterCart(idOp) {
this.router.navigate(['/debiterCarte', idOp]);
}
goToCarteEnvoyer() {
this.router.navigate(['/historiqueCarte']);
}
sectionToImage(monURL: string) {
/**
* covert canvas to image
* and save the image file
*/
var Canvas2Image = function () {
// check if support sth.
var $support = function () {
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d');
return {
canvas: !!ctx,
imageData: !!ctx.getImageData,
dataURL: !!canvas.toDataURL,
btoa: !!window.btoa
};
}();
var downloadMime = 'image/png';
function scaleCanvas (canvas, width, height) {
var w = canvas.width,
h = canvas.height;
if (width == undefined) {
width = w;
}
if (height == undefined) {
height = h;
}
var retCanvas = document.createElement('canvas');
var retCtx = retCanvas.getContext('2d');
retCanvas.width = width;
retCanvas.height = height;
retCtx.drawImage(canvas, 0, 0, w, h, 0, 0, width, height);
return retCanvas;
}
function getDataURL (canvas, type, width, height) {
canvas = scaleCanvas(canvas, width, height);
return canvas.toDataURL(type);
}
function saveFile (strData) {
document.location.href = strData;
}
function genImage(strData) {
var img = document.createElement('img');
img.src = strData;
return img;
}
function fixType (type) {
type = type.toLowerCase().replace(/jpg/i, 'jpeg');
var r = type.match(/png|jpeg|bmp|gif/)[0];
return 'image/' + r;
}
function encodeData (data) {
if (!window.btoa) { throw 'btoa undefined' }
var str = '';
if (typeof data == 'string') {
str = data;
} else {
for (var i = 0; i < data.length; i ++) {
str += String.fromCharCode(data[i]);
}
}
return btoa(str);
}
function getImageData (canvas) {
var w = canvas.width,
h = canvas.height;
return canvas.getContext('2d').getImageData(0, 0, w, h);
}
function makeURI (strData, type) {
return 'data:' + type + ';base64,' + strData;
}
/**
* create bitmap image
*
*/
var genBitmapImage = function (oData) {
//
// BITMAPFILEHEADER: http://msdn.microsoft.com/en-us/library/windows/desktop/dd183374(v=vs.85).aspx
// BITMAPINFOHEADER: http://msdn.microsoft.com/en-us/library/dd183376.aspx
//
var biWidth = oData.width;
var biHeight = oData.height;
var biSizeImage = biWidth * biHeight * 3;
var bfSize = biSizeImage + 54; // total header size = 54 bytes
//
// typedef struct tagBITMAPFILEHEADER {
// WORD bfType;
// DWORD bfSize;
// WORD bfReserved1;
// WORD bfReserved2;
// DWORD bfOffBits;
// } BITMAPFILEHEADER;
//
var BITMAPFILEHEADER = [
// WORD bfType -- The file type signature; must be "BM"
0x42, 0x4D,
// DWORD bfSize -- The size, in bytes, of the bitmap file
bfSize & 0xff, bfSize >> 8 & 0xff, bfSize >> 16 & 0xff, bfSize >> 24 & 0xff,
// WORD bfReserved1 -- Reserved; must be zero
0, 0,
// WORD bfReserved2 -- Reserved; must be zero
0, 0,
// DWORD bfOffBits -- The offset, in bytes, from the beginning of the BITMAPFILEHEADER structure to the bitmap bits.
54, 0, 0, 0
];
//
// typedef struct tagBITMAPINFOHEADER {
// DWORD biSize;
// LONG biWidth;
// LONG biHeight;
// WORD biPlanes;
// WORD biBitCount;
// DWORD biCompression;
// DWORD biSizeImage;
// LONG biXPelsPerMeter;
// LONG biYPelsPerMeter;
// DWORD biClrUsed;
// DWORD biClrImportant;
// } BITMAPINFOHEADER, *PBITMAPINFOHEADER;
//
var BITMAPINFOHEADER = [
// DWORD biSize -- The number of bytes required by the structure
40, 0, 0, 0,
// LONG biWidth -- The width of the bitmap, in pixels
biWidth & 0xff, biWidth >> 8 & 0xff, biWidth >> 16 & 0xff, biWidth >> 24 & 0xff,
// LONG biHeight -- The height of the bitmap, in pixels
biHeight & 0xff, biHeight >> 8 & 0xff, biHeight >> 16 & 0xff, biHeight >> 24 & 0xff,
// WORD biPlanes -- The number of planes for the target device. This value must be set to 1
1, 0,
// WORD biBitCount -- The number of bits-per-pixel, 24 bits-per-pixel -- the bitmap
// has a maximum of 2^24 colors (16777216, Truecolor)
24, 0,
// DWORD biCompression -- The type of compression, BI_RGB (code 0) -- uncompressed
0, 0, 0, 0,
// DWORD biSizeImage -- The size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps
biSizeImage & 0xff, biSizeImage >> 8 & 0xff, biSizeImage >> 16 & 0xff, biSizeImage >> 24 & 0xff,
// LONG biXPelsPerMeter, unused
0,0,0,0,
// LONG biYPelsPerMeter, unused
0,0,0,0,
// DWORD biClrUsed, the number of color indexes of palette, unused
0,0,0,0,
// DWORD biClrImportant, unused
0,0,0,0
];
var iPadding = (4 - ((biWidth * 3) % 4)) % 4;
var aImgData = oData.data;
var strPixelData = '';
var biWidth4 = biWidth<<2;
var y = biHeight;
var fromCharCode = String.fromCharCode;
do {
var iOffsetY = biWidth4*(y-1);
var strPixelRow = '';
for (var x = 0; x < biWidth; x++) {
var iOffsetX = x<<2;
strPixelRow += fromCharCode(aImgData[iOffsetY+iOffsetX+2]) +
fromCharCode(aImgData[iOffsetY+iOffsetX+1]) +
fromCharCode(aImgData[iOffsetY+iOffsetX]);
}
for (var c = 0; c < iPadding; c++) {
strPixelRow += String.fromCharCode(0);
}
strPixelData += strPixelRow;
} while (--y);
var strEncoded = encodeData(BITMAPFILEHEADER.concat(BITMAPINFOHEADER)) + encodeData(strPixelData);
return strEncoded;
};
/**
* saveAsImage
* @param canvasElement
* @param {String} image type
* @param {Number} [optional] png width
* @param {Number} [optional] png height
*/
var saveAsImage = function (canvas, width, height, type) {
if ($support.canvas && $support.dataURL) {
if (typeof canvas == "string") { canvas = document.getElementById(canvas); }
if (type == undefined) { type = 'png'; }
type = fixType(type);
if (/bmp/.test(type)) {
var data = getImageData(scaleCanvas(canvas, width, height));
var strData = '';
strData = genBitmapImage(data);
saveFile(makeURI(strData, downloadMime));
} else {
var strData = '';
strData = getDataURL(canvas, type, width, height);
saveFile(strData.replace(type, downloadMime));
}
}
};
var convertToImage = function (canvas, width, height, type) {
if ($support.canvas && $support.dataURL) {
if (typeof canvas == "string") { canvas = document.getElementById(canvas); }
if (type == undefined) { type = 'png'; }
type = fixType(type);
if (/bmp/.test(type)) {
var data = getImageData(scaleCanvas(canvas, width, height));
var strData = '';
strData = genBitmapImage(data);
return genImage(makeURI(strData, 'image/bmp'));
} else {
var strData = '';
strData = getDataURL(canvas, type, width, height);
return genImage(strData);
}
}
};
return {
saveAsImage: saveAsImage,
saveAsPNG: function (canvas, width, height) {
return saveAsImage(canvas, width, height, 'png');
},
saveAsJPEG: function (canvas, width, height) {
return saveAsImage(canvas, width, height, 'jpeg');
},
saveAsGIF: function (canvas, width, height) {
return saveAsImage(canvas, width, height, 'gif');
},
saveAsBMP: function (canvas, width, height) {
return saveAsImage(canvas, width, height, 'bmp');
},
convertToImage: convertToImage,
convertToPNG: function (canvas, width, height) {
return convertToImage(canvas, width, height, 'png');
},
convertToJPEG: function (canvas, width, height) {
return convertToImage(canvas, width, height, 'jpeg');
},
convertToGIF: function (canvas, width, height) {
return convertToImage(canvas, width, height, 'gif');
},
convertToBMP: function (canvas, width, height) {
return convertToImage(canvas, width, height, 'bmp');
}
};
}();
/*
html2canvas(document.body).then(canvas => {
var imgData = canvas.toDataURL("image/png");
var context = canvas.getContext('2d');
console.log(imgData);
window.open(imgData);
// this.AddImagesResource(imgData);
// document.body.appendChild(canvas);
});*/
html2canvas(document.getElementById('subCard1'), {
allowTaint: true,
useCORS: true,
logging: true,
onrendered: function(canvas) {
var context = canvas.getContext('2d');
var img = new Image();
var offsets = document.getElementById('subCard1').getBoundingClientRect();
var imgTop = offsets.top;
var imgLeft = offsets.left;
//var offsetsContainer = document.getElementById('subCard1').getBoundingClientRect();
//var imageLeft = imgLeft - offsetsContainer.left;
//var imageTop = imgTop - offsetsContainer.top;
img.src = monURL; // document.getElementById('myimage').getAttribute('src');
img.onload = function() {
context.drawImage(img, imgLeft, imgTop);
};
document.body.appendChild(canvas);
Canvas2Image.saveAsPNG(canvas, 50, 1000);
// window.open(canvas.toDataURL('image/png'));
}
});
/*
$(function() {
$('#btnSave').click(function() {
html2canvas($('#widget'), {
onrendered: function(canvas) {
var context = canvas.getContext('2d'); // returns the 2d context object
var img = new Image(); // creates a variable for a new image
var offsets = document.getElementById('myimage').getBoundingClientRect();
var imgTop = offsets.top;
var imgLeft = offsets.left;
// Find actual position with parent cotainer
var offsetsContainer = document.getElementById('widget').getBoundingClientRect();
var imageLeft = imgLeft - offsetsContainer.left;
var imageTop = imgTop - offsetsContainer.top;
img.src = 'http://www.vulgaris-medical.com/sites/default/files/styles/big-lightbox/public/field/image' +
'/actualites/2016/02/12/le-chat-source-de-bienfaits-pour-votre-sante.jpg'; // specifies the location of the image
img.onload = function() {
context.drawImage(img, imageLeft, imageTop); // draws the image at the specified x and y location
};
// Convert and download as image
var theCanvas = canvas;
document.body.appendChild(canvas);
// Convert and download as image
Canvas2Image.saveAsPNG(canvas);
$('#img-out').append(canvas);
}
});
});
});
*/
/*
html2canvas(document.getElementsByClassName('subCard1'), {
// allowTaint:true,
logging:true,
onrendered: function(canvas) {
var img = new Image();
var testt : string;
img.setAttribute('crossOrigin', 'anonymous');
img = canvas.toDataURL('image/png');
testt = img.toString();
window.open(testt);
}
});
*/
}
ngOnInit() {
}
ngOnDestroy() {}

@ -77,8 +77,8 @@
<div class="md-form">
<i class="fa fa-user prefix grey-text"></i>
<input
#query
(keyup)="filter(query.value)"
#queryF
(keyup)="filter(queryF.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>
@ -91,7 +91,11 @@
<div class="md-form">
<i class="fa fa-address-card prefix grey-text"></i>
<input type="text" id="orangeForm-Familyname" placeholder="ID carte" ><!--[(ngModel)]="filleul.idCard"-->
<input
#query
(keyup)="filterCarte(query.value)"
type="text" class="form-control" placeholder="ID carte">
<!--<input type="text" id="orangeForm-Familyname" placeholder="ID carte" [(ngModel)]="carteIDTemp">[(ngModel)]="filleul.idCard"-->
</div>
<label>

@ -34,10 +34,13 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
localUser: any;
filleul: Filleul;
scan: Scan;
parrain: Parrain;
commercant: Commercant;
opComm: OperationCommerciale;
cartePar: CarteParrainage;
carteIDTemp: string;
commList: FirebaseListObservable<any[]>;
opCommList: FirebaseListObservable<any[]>;
filleulExistList: FirebaseListObservable<any[]>;
@ -46,9 +49,12 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
/////
filleulTest: Filleul[];
carteTest: Filleul[];
filteredFilleulsTest: any[];
filteredCartesTest: any[];
filleulListTemp = [];
subscription: Subscription;
subscriptionCarte: Subscription;
/////
constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
private router: Router, private authService: AuthService,
@ -58,6 +64,7 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
this.filleulSelect = '';
this.filleul = new Filleul();
this.scan = new Scan();
this.parrain = new Parrain();
this.commercant = new Commercant();
this.cartePar = new CarteParrainage();
this.filleulExistList = null;
@ -121,9 +128,26 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
goToOpComm() {
this.router.navigate(['/opCommercial']);
}
filter(query: string) {
this.filteredFilleulsTest = (query) ?
this.filleulTest.filter(f => (f.firstname.toLowerCase() + f.familyname.toLowerCase()).includes(query.toLowerCase())) :
filterCarte(query: string) {
this.filteredCartesTest = (query) ?
this.carteTest.filter(c => (c.uid).includes(query)) :
[];
if (this.filteredCartesTest !== []){
for(let i = 0; i < this.filteredCartesTest.length;i++){
if (this.filteredCartesTest[i].uid === query) {
console.log('succes id carte est: ' + this.filteredCartesTest[i].uid);
console.log('succes le parrain de la carte est: ' + this.filteredCartesTest[i].parrainCarte.firstname);
this.cartePar = this.filteredCartesTest[i];
this.parrain = this.filteredCartesTest[i].parrainCarte;
}else{
console.log('echec de la carte ! ');
}
}
}
}
filter(queryF: string) {
this.filteredFilleulsTest = (queryF) ?
this.filleulTest.filter(f => (f.firstname.toLowerCase() + f.familyname.toLowerCase()).includes(queryF.toLowerCase())) :
[];
}
registerNewFilleul(){
@ -137,8 +161,10 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
userRef.set(this.filleul);
this.scanCarteFil();
}
scanCarteFil(){
scanCarteFil() {
this.scan.uid = firebase.database().ref().child('Scan').push().key;
this.scan.dateCreation = new Date (Date.now());
this.scan.carteParrainID = this.filleul.idCard;
this.scan.carteFilleulID = this.filleul.idCard;
console.log(Date.now());
@ -151,6 +177,25 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
console.log(this.scan.valeurFilleul);
const userRef = this.databaseRef.child('Scan').child(this.scan.uid);
userRef.set(this.scan);
this.updateCarte();
}
updateCarte() {
console.log(+this.cartePar.avantageCumule);
this.cartePar.avantageCumule = ((+this.cartePar.avantageCumule) + (+this.opComm.avantageParrain)).toString();
console.log(this.cartePar.avantageCumule);
console.log('carte iiiiid: ' + this.cartePar.uid);
const carteRef = this.databaseRef.child('CarteParrainage').child(this.cartePar.uid.toString()).child('avantageCumule');
carteRef.set(this.cartePar.avantageCumule);
this.opComm.nbScan = ((+this.opComm.nbScan) + 1).toString();
console.log(this.opComm.nbScan);
const opEnvRef = this.databaseRef.child('OperationCommercial').child(this.opComm.uid.toString()).child('nbScan');
opEnvRef.set(this.opComm.nbScan);
}
getIdFilleul(filUid) {
@ -172,10 +217,13 @@ export class ScannerCarteComponent implements OnInit, OnDestroy {
ngOnInit() {
this.subscription = this.opComService.getParrains()
.subscribe(parrains => this.filleulTest = parrains);
this.subscriptionCarte = this.opComService.getCartes()
.subscribe(cartes => this.carteTest = cartes);
}
ngOnDestroy() {
this.subscription.unsubscribe();
this.subscriptionCarte.unsubscribe();
this.radioFilleul = '';
this.cartePar = {
uid: '',

@ -39,6 +39,7 @@ export class RegisterComponent implements OnInit, OnDestroy {
this.test = true;
}else if (this.currentUser.status === 'Commercant') {
this.commercant.status = this.currentUser.status;
this.commercant.dateInscription = new Date (Date.now());
this.authService.signUp(this.commercant);
this.test = true;
}else if (this.test) {

@ -47,6 +47,15 @@ export class OpCommercialService {
);
}
getCartes(): FirebaseListObservable<any> {
return this.afDb.list('/CarteParrainage/', {
query: {
orderByChild: 'uid'
}
}
);
}
getFilleuls(): FirebaseListObservable<any> {
return this.afDb.list('/Filleul/', {
query: {

@ -15,6 +15,9 @@ export class OperationCommerciale
deviseAvantageFilleul: string;
tarifXJCFilleul: string;
status: string;
nbScan: string;
nbEnvoie: string;
nbDebiter: string;
constructor() {
this.uid = '';
@ -30,6 +33,9 @@ export class OperationCommerciale
this.deviseAvantageFilleul = '';
this.tarifXJCFilleul = '';
this.status = '';
this.nbScan = '0';
this.nbEnvoie = '0';
this.nbDebiter = '0';
}
/*
addParrain(addStatus, addEmail, addFamilyname, addFirstname) {

Loading…
Cancel
Save