Skip to content

Commit d2fd11f

Browse files
committed
fix: scanner options
1 parent 5293a63 commit d2fd11f

2 files changed

Lines changed: 30 additions & 20 deletions

File tree

src/app/afip/afip.component.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
<!--button mat-raised-button color="primary" class="w-100" (click)="test()">TEST</button-->
2121

22-
<div *ngIf="invoices.length > 0 && !loading" class="row">
22+
<div class="row text-center" *ngIf="loading">
23+
<mat-spinner class="mx-auto mt-2" diameter="30"></mat-spinner>
24+
</div>
25+
26+
<div *ngIf="invoices.length > 0" class="row">
2327
<div class="col-12">
2428
<table mat-table [dataSource]="invoices" class="mat-elevation-z8 w-100" multiTemplateDataRows>
2529

@@ -61,7 +65,4 @@ <h5 class="mb-1"><b>Receptor:</b> {{element.nameRec}}</h5>
6165

6266
</table>
6367
</div>
64-
</div>
65-
<div class="row text-center" *ngIf="loading">
66-
<mat-spinner class="mx-auto" diameter="40"></mat-spinner>
6768
</div>

src/app/afip/afip.component.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, ViewChild, Inject } from '@angular/core';
1+
import { Component, OnInit, DoCheck, ViewChild, Inject } from '@angular/core';
22
import {animate, state, style, transition, trigger} from '@angular/animations';
33
import { MatTable } from '@angular/material/table';
44
import { MatDialog, MAT_DIALOG_DATA } from '@angular/material/dialog';
@@ -55,42 +55,50 @@ export class AfipComponent implements OnInit {
5555
}
5656
}
5757

58+
ngDoCheck(): void {}
59+
5860
scanQR() {
59-
this.barcodeScanner.scan({formats: 'QR_CODE'})
61+
this.barcodeScanner.scan({
62+
formats: 'QR_CODE',
63+
prompt: 'Coloque un Código QR de AFIP en el Escaner.',
64+
resultDisplayDuration: 0
65+
})
6066
.then(barcodeData => {
61-
this.processQR(barcodeData.text);
67+
if (barcodeData.cancelled === false) {
68+
this.processQR(barcodeData.text);
69+
}
6270
}).catch(err => {
6371
alert(err);
6472
});
6573
}
6674

67-
test() {
75+
async test() {
6876
// FA-C
69-
const urlText = "https://www.afip.gob.ar/fe/qr/?p=eyJ2ZXIiOjEsImZlY2hhIjoiMjAyMi0wMS0yNSIsImN1aXQiOjIwMzY3MzYyNDczLCJwdG9WdGEiOjIsInRpcG9DbXAiOjExLCJucm9DbXAiOjg4LCJpbXBvcnRlIjoyMDAwLCJtb25lZGEiOiJQRVMiLCJjdHoiOjEsInRpcG9Eb2NSZWMiOjgwLCJucm9Eb2NSZWMiOjMwNzE2NzQzMjk5LCJ0aXBvQ29kQXV0IjoiRSIsImNvZEF1dCI6NzIwNDMzMjQ5NjcwOTl9";
77+
const urlText1 = "https://www.afip.gob.ar/fe/qr/?p=eyJ2ZXIiOjEsImZlY2hhIjoiMjAyMi0wMS0yNSIsImN1aXQiOjIwMzY3MzYyNDczLCJwdG9WdGEiOjIsInRpcG9DbXAiOjExLCJucm9DbXAiOjg4LCJpbXBvcnRlIjoyMDAwLCJtb25lZGEiOiJQRVMiLCJjdHoiOjEsInRpcG9Eb2NSZWMiOjgwLCJucm9Eb2NSZWMiOjMwNzE2NzQzMjk5LCJ0aXBvQ29kQXV0IjoiRSIsImNvZEF1dCI6NzIwNDMzMjQ5NjcwOTl9";
7078
// FA-A
71-
// const urlText = "https://www.afip.gob.ar/fe/qr/?p=eyJ2ZXIiOiAxLCAiZmVjaGEiOiAiMjAyMi0wMi0wMSIsICJjdWl0IjogMzA3MTY3MTg1MjksICJwdG9WdGEiOiAyLCAidGlwb0NtcCI6IDEsICJucm9DbXAiOiAxNjcsICJpbXBvcnRlIjogMTgxNTAuMCwgIm1vbmVkYSI6ICJQRVMiLCAiY3R6IjogMS4wLCAidGlwb0NvZEF1dCI6ICJFIiwgImNvZEF1dCI6IDcyMDU5MDA0NTQ5NTc1LCAibnJvRG9jUmVjIjogMjAzNzAzODYwNTcsICJ0aXBvRG9jUmVjIjogODB9";
79+
const urlText2 = "https://www.afip.gob.ar/fe/qr/?p=eyJ2ZXIiOiAxLCAiZmVjaGEiOiAiMjAyMi0wMi0wMSIsICJjdWl0IjogMzA3MTY3MTg1MjksICJwdG9WdGEiOiAyLCAidGlwb0NtcCI6IDEsICJucm9DbXAiOiAxNjcsICJpbXBvcnRlIjogMTgxNTAuMCwgIm1vbmVkYSI6ICJQRVMiLCAiY3R6IjogMS4wLCAidGlwb0NvZEF1dCI6ICJFIiwgImNvZEF1dCI6IDcyMDU5MDA0NTQ5NTc1LCAibnJvRG9jUmVjIjogMjAzNzAzODYwNTcsICJ0aXBvRG9jUmVjIjogODB9";
7280
// FA-B
73-
// const urlText = "https://www.afip.gob.ar/fe/qr/?p=eyJjb2RBdXQiOjcyMDQ2MTkwMDUyNDc3LCJjdHoiOjEsImN1aXQiOjMwNzEwMTE0MTc2LCJmZWNoYSI6IjIwMjItMDEtMjMiLCJpbXBvcnRlIjo2Mzk4LjAwLCJtb25lZGEiOiJQRVMiLCJucm9DbXAiOjEwMDk3OTksIm5yb0RvY1JlYyI6MCwicHRvVnRhIjozMSwidGlwb0NtcCI6NiwidGlwb0NvZEF1dCI6IkUiLCJ0aXBvRG9jUmVjIjo5NiwidmVyIjoxfQ=="
74-
this.processQR(urlText);
81+
const urlText3 = "https://www.afip.gob.ar/fe/qr/?p=eyJjb2RBdXQiOjcyMDQ2MTkwMDUyNDc3LCJjdHoiOjEsImN1aXQiOjMwNzEwMTE0MTc2LCJmZWNoYSI6IjIwMjItMDEtMjMiLCJpbXBvcnRlIjo2Mzk4LjAwLCJtb25lZGEiOiJQRVMiLCJucm9DbXAiOjEwMDk3OTksIm5yb0RvY1JlYyI6MCwicHRvVnRhIjozMSwidGlwb0NtcCI6NiwidGlwb0NvZEF1dCI6IkUiLCJ0aXBvRG9jUmVjIjo5NiwidmVyIjoxfQ=="
7582
}
7683

7784
removeInvoices(): void {
7885
this.invoices.length = 0;
7986
localStorage.setItem('invoices', JSON.stringify(this.invoices));
8087
}
8188

82-
async processQR(t: string) {
89+
async processQR(t: string, i: number = 0) {
8390
this.loading = true;
8491
const url = new URL(t);
8592
const p: any = url.searchParams.get('p');
8693
let encode = p.replace(/b\'(.*)\'/, '$1').replace(/\n/g, '');
8794
const decode = decodeURIComponent(escape(atob( encode ))).replace(/\'/g, '"');
8895
const obj = JSON.parse(decode);
8996
console.log(obj);
97+
9098
if (url.host === 'www.afip.gob.ar' || url.host === 'afip.gob.ar') {
9199
if (this.invoices.find(x => x.cae === obj.codAut) !== undefined) {
92-
this.loading = false;
93100
this.openDialog('¡Factura ya escaneada!');
101+
this.loading = false;
94102
} else {
95103
let newinvoice = await this.processQrFeAr(obj);
96104
this.http.get<any>('https://afip.tangofactura.com/Rest/GetContribuyenteFull?cuit=' + obj.cuit,{}).subscribe(dataE => {
@@ -102,32 +110,33 @@ export class AfipComponent implements OnInit {
102110
newinvoice.nameRec = dataR.Contribuyente.nombre;
103111
this.invoices.push(newinvoice);
104112
localStorage.setItem('invoices', JSON.stringify(this.invoices));
105-
this.loading = false;
106113
if (this.table) {
107114
this.table!.renderRows();
108115
}
109-
}
116+
this.loading = false;
117+
} else {}
110118
}, (err: any) => {
111-
this.loading = false;
112119
this.openDialog(err);
120+
this.loading = false;
113121
});
114122
} else {
115123
newinvoice.nameRec = 'Consumidor Final';
116124
this.invoices.push(newinvoice);
117125
localStorage.setItem('invoices', JSON.stringify(this.invoices));
118-
this.loading = false;
119126
if (this.table) {
120127
this.table!.renderRows();
121128
}
129+
this.loading = false;
122130
}
123-
}
131+
} else {}
124132
}, (err: any) => {
125-
this.loading = false;
126133
this.openDialog(err);
134+
this.loading = false;
127135
});
128136
}
129137
} else {
130138
this.openDialog('El QR escaneado no es de AFIP');
139+
this.loading = false;
131140
}
132141
}
133142

0 commit comments

Comments
 (0)