Skip to content

Commit f0643ad

Browse files
committed
fear: add comprobation on cae
1 parent a1b13bf commit f0643ad

2 files changed

Lines changed: 41 additions & 34 deletions

File tree

src/app/afip/afip.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</div>
1313
</div>
1414

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

1717
<div *ngIf="invoices.length > 0 && !loading" class="row">
1818
<div class="col-12">

src/app/afip/afip.component.ts

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { FileOpener } from '@ionic-native/file-opener/ngx';
1111
export interface InvoiceElement {
1212
docName: string;
1313
docNumber: string;
14+
cae: string;
1415
cuitEmi: string;
1516
cuitRec: string;
1617
nameEmi: string;
@@ -63,11 +64,11 @@ export class AfipComponent implements OnInit {
6364

6465
test() {
6566
// FA-C
66-
// const urlText = "https://www.afip.gob.ar/fe/qr/?p=eyJ2ZXIiOjEsImZlY2hhIjoiMjAyMi0wMS0yNSIsImN1aXQiOjIwMzY3MzYyNDczLCJwdG9WdGEiOjIsInRpcG9DbXAiOjExLCJucm9DbXAiOjg4LCJpbXBvcnRlIjoyMDAwLCJtb25lZGEiOiJQRVMiLCJjdHoiOjEsInRpcG9Eb2NSZWMiOjgwLCJucm9Eb2NSZWMiOjMwNzE2NzQzMjk5LCJ0aXBvQ29kQXV0IjoiRSIsImNvZEF1dCI6NzIwNDMzMjQ5NjcwOTl9";
67+
const urlText = "https://www.afip.gob.ar/fe/qr/?p=eyJ2ZXIiOjEsImZlY2hhIjoiMjAyMi0wMS0yNSIsImN1aXQiOjIwMzY3MzYyNDczLCJwdG9WdGEiOjIsInRpcG9DbXAiOjExLCJucm9DbXAiOjg4LCJpbXBvcnRlIjoyMDAwLCJtb25lZGEiOiJQRVMiLCJjdHoiOjEsInRpcG9Eb2NSZWMiOjgwLCJucm9Eb2NSZWMiOjMwNzE2NzQzMjk5LCJ0aXBvQ29kQXV0IjoiRSIsImNvZEF1dCI6NzIwNDMzMjQ5NjcwOTl9";
6768
// FA-A
6869
// const urlText = "https://www.afip.gob.ar/fe/qr/?p=eyJ2ZXIiOiAxLCAiZmVjaGEiOiAiMjAyMi0wMi0wMSIsICJjdWl0IjogMzA3MTY3MTg1MjksICJwdG9WdGEiOiAyLCAidGlwb0NtcCI6IDEsICJucm9DbXAiOiAxNjcsICJpbXBvcnRlIjogMTgxNTAuMCwgIm1vbmVkYSI6ICJQRVMiLCAiY3R6IjogMS4wLCAidGlwb0NvZEF1dCI6ICJFIiwgImNvZEF1dCI6IDcyMDU5MDA0NTQ5NTc1LCAibnJvRG9jUmVjIjogMjAzNzAzODYwNTcsICJ0aXBvRG9jUmVjIjogODB9";
6970
// FA-B
70-
const urlText = "https://www.afip.gob.ar/fe/qr/?p=eyJjb2RBdXQiOjcyMDQ2MTkwMDUyNDc3LCJjdHoiOjEsImN1aXQiOjMwNzEwMTE0MTc2LCJmZWNoYSI6IjIwMjItMDEtMjMiLCJpbXBvcnRlIjo2Mzk4LjAwLCJtb25lZGEiOiJQRVMiLCJucm9DbXAiOjEwMDk3OTksIm5yb0RvY1JlYyI6MCwicHRvVnRhIjozMSwidGlwb0NtcCI6NiwidGlwb0NvZEF1dCI6IkUiLCJ0aXBvRG9jUmVjIjo5NiwidmVyIjoxfQ=="
71+
// const urlText = "https://www.afip.gob.ar/fe/qr/?p=eyJjb2RBdXQiOjcyMDQ2MTkwMDUyNDc3LCJjdHoiOjEsImN1aXQiOjMwNzEwMTE0MTc2LCJmZWNoYSI6IjIwMjItMDEtMjMiLCJpbXBvcnRlIjo2Mzk4LjAwLCJtb25lZGEiOiJQRVMiLCJucm9DbXAiOjEwMDk3OTksIm5yb0RvY1JlYyI6MCwicHRvVnRhIjozMSwidGlwb0NtcCI6NiwidGlwb0NvZEF1dCI6IkUiLCJ0aXBvRG9jUmVjIjo5NiwidmVyIjoxfQ=="
7172
this.processQR(urlText);
7273
}
7374

@@ -85,39 +86,44 @@ export class AfipComponent implements OnInit {
8586
const obj = JSON.parse(decode);
8687
console.log(obj);
8788
if (url.host === 'www.afip.gob.ar' || url.host === 'afip.gob.ar') {
88-
let newinvoice = await this.processQrFeAr(obj);
89-
this.http.get<any>('https://afip.tangofactura.com/Rest/GetContribuyenteFull?cuit=' + obj.cuit,{}).subscribe(dataE => {
90-
if (dataE.Contribuyente) {
91-
newinvoice.nameEmi = dataE.Contribuyente.nombre;
92-
if (obj.nroDocRec !== 0) {
93-
this.http.get<any>('https://afip.tangofactura.com/Rest/GetContribuyenteFull?cuit=' + obj.nroDocRec,{}).subscribe(dataR => {
94-
if (dataR.Contribuyente) {
95-
newinvoice.nameRec = dataR.Contribuyente.nombre;
96-
this.invoices.push(newinvoice);
97-
localStorage.setItem('invoices', JSON.stringify(this.invoices));
98-
this.loading = false;
99-
if (this.table) {
100-
this.table!.renderRows();
89+
if (this.invoices.find(x => x.cae === obj.codAut) !== undefined) {
90+
this.loading = false;
91+
this.openDialog('¡Factura ya escaneada!');
92+
} else {
93+
let newinvoice = await this.processQrFeAr(obj);
94+
this.http.get<any>('https://afip.tangofactura.com/Rest/GetContribuyenteFull?cuit=' + obj.cuit,{}).subscribe(dataE => {
95+
if (dataE.Contribuyente) {
96+
newinvoice.nameEmi = dataE.Contribuyente.nombre;
97+
if (obj.nroDocRec !== 0) {
98+
this.http.get<any>('https://afip.tangofactura.com/Rest/GetContribuyenteFull?cuit=' + obj.nroDocRec,{}).subscribe(dataR => {
99+
if (dataR.Contribuyente) {
100+
newinvoice.nameRec = dataR.Contribuyente.nombre;
101+
this.invoices.push(newinvoice);
102+
localStorage.setItem('invoices', JSON.stringify(this.invoices));
103+
this.loading = false;
104+
if (this.table) {
105+
this.table!.renderRows();
106+
}
101107
}
102-
}
103-
}, (err: any) => {
108+
}, (err: any) => {
109+
this.loading = false;
110+
this.openDialog(err);
111+
});
112+
} else {
113+
newinvoice.nameRec = 'Consumidor Final';
114+
this.invoices.push(newinvoice);
115+
localStorage.setItem('invoices', JSON.stringify(this.invoices));
104116
this.loading = false;
105-
this.openDialog(err);
106-
});
107-
} else {
108-
newinvoice.nameRec = 'Consumidor Final';
109-
this.invoices.push(newinvoice);
110-
localStorage.setItem('invoices', JSON.stringify(this.invoices));
111-
this.loading = false;
112-
if (this.table) {
113-
this.table!.renderRows();
117+
if (this.table) {
118+
this.table!.renderRows();
119+
}
114120
}
115121
}
116-
}
117-
}, (err: any) => {
118-
this.loading = false;
119-
this.openDialog(err);
120-
})
122+
}, (err: any) => {
123+
this.loading = false;
124+
this.openDialog(err);
125+
});
126+
}
121127
} else {
122128
this.openDialog('El QR escaneado no es de AFIP');
123129
}
@@ -192,6 +198,7 @@ export class AfipComponent implements OnInit {
192198
return {
193199
docName: comp,
194200
docNumber: pdv + '-' + num,
201+
cae: obj.codAut,
195202
cuitEmi: obj.cuit,
196203
cuitRec: obj.nroDocRec,
197204
nameEmi: '',
@@ -205,10 +212,10 @@ export class AfipComponent implements OnInit {
205212

206213
async exportToCSV() {
207214
let csvContent = '';
208-
csvContent += 'Tipo,Nro,Emisor,Emisor CUIT,Receptor,Receptor CUIT,Fecha,Importe,Importe sin IVA 21,Moneda\r\n';
215+
csvContent += 'Tipo,Nro,CAE,Emisor,Emisor CUIT,Receptor,Receptor CUIT,Fecha,Importe,Importe sin IVA 21,Moneda\r\n';
209216

210217
this.invoices.forEach((row) => {
211-
csvContent += row.docName + ',' + row.docNumber + ',' + row.nameEmi + ',' + row.cuitEmi + ',' + row.nameRec + ',' + row.cuitRec + ',' + row.date + ',' + row.amount + ',' + Number(row.amount) / 1.21 + ',' + row.currency + '\r\n';
218+
csvContent += row.docName + ',' + row.docNumber + ',' + row.cae + ',' + row.nameEmi + ',' + row.cuitEmi + ',' + row.nameRec + ',' + row.cuitRec + ',' + row.date + ',' + row.amount + ',' + Number(row.amount) / 1.21 + ',' + row.currency + '\r\n';
212219
});
213220

214221
let date = new Date()

0 commit comments

Comments
 (0)