Skip to content

Commit 665e97c

Browse files
committed
feat: add name data of cuits
1 parent 66683d6 commit 665e97c

3 files changed

Lines changed: 37 additions & 14 deletions

File tree

src/app/afip/afip.component.html

Lines changed: 3 additions & 3 deletions
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" class="row">
1818
<div class="col-12">
@@ -39,8 +39,8 @@ <h3 class="mb-0">{{element.amount | currency:'ARS':'symbol':'':'es-AR'}}</h3>
3939
</div>
4040
<div class="p-1 w-50">
4141
<h5 class="mb-1">{{element.docName}} {{element.docNumber}}</h5>
42-
<h5 class="mb-1"><b>Emisor:</b> {{element.cuitEmi}}</h5>
43-
<h5 class="mb-1"><b>Receptor:</b> {{element.cuitRec}}</h5>
42+
<h5 class="mb-1"><b>Emisor:</b> {{element.nameEmi}}</h5>
43+
<h5 class="mb-1"><b>Receptor:</b> {{element.nameRec}}</h5>
4444
</div>
4545
</div>
4646
</td>

src/app/afip/afip.component.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ 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
import { BarcodeScanner } from '@awesome-cordova-plugins/barcode-scanner/ngx';
6+
import { HttpClient } from '@angular/common/http';
67

78
export interface InvoiceElement {
89
docName: string;
910
docNumber: string;
1011
cuitEmi: string;
1112
cuitRec: string;
13+
nameEmi: string;
14+
nameRec: string;
1215
date: string;
1316
amount: number;
1417
currency: string;
@@ -33,7 +36,7 @@ export class AfipComponent implements OnInit {
3336
expandedElement: InvoiceElement | null | undefined;
3437
@ViewChild(MatTable) table: MatTable<InvoiceElement> | undefined;
3538

36-
constructor(private barcodeScanner: BarcodeScanner, public dialog: MatDialog) { }
39+
constructor(private barcodeScanner: BarcodeScanner, public dialog: MatDialog, private http: HttpClient) { }
3740

3841
ngOnInit(): void {
3942
let inv = localStorage.getItem('invoices');
@@ -66,20 +69,34 @@ export class AfipComponent implements OnInit {
6669
localStorage.setItem('invoices', JSON.stringify(this.invoices));
6770
}
6871

69-
processQR(t: string) {
72+
async processQR(t: string) {
7073
const url = new URL(t);
7174
const p: any = url.searchParams.get('p');
7275
let encode = p.replace(/b\'(.*)\'/, '$1').replace(/\n/g, '');
7376
const decode = decodeURIComponent(escape(atob( encode ))).replace(/\'/g, '"');
7477
const obj = JSON.parse(decode);
7578
console.log(obj);
7679
if (url.host === 'www.afip.gob.ar' || url.host === 'afip.gob.ar') {
77-
this.invoices.push(this.processQrFeAr(obj));
78-
localStorage.setItem('invoices', JSON.stringify(this.invoices));
79-
console.log(this.invoices);
80-
if (this.table) {
81-
this.table!.renderRows();
82-
}
80+
let newinvoice = await this.processQrFeAr(obj);
81+
this.http.get<any>('https://afip.tangofactura.com/Rest/GetContribuyenteFull?cuit=' + obj.cuit,{}).subscribe(dataE => {
82+
if (dataE.Contribuyente) {
83+
newinvoice.nameEmi = dataE.Contribuyente.nombre;
84+
this.http.get<any>('https://afip.tangofactura.com/Rest/GetContribuyenteFull?cuit=' + obj.nroDocRec,{}).subscribe(dataR => {
85+
if (dataR.Contribuyente) {
86+
newinvoice.nameRec = dataR.Contribuyente.nombre;
87+
this.invoices.push(newinvoice);
88+
localStorage.setItem('invoices', JSON.stringify(this.invoices));
89+
if (this.table) {
90+
this.table!.renderRows();
91+
}
92+
}
93+
}, (err: any) => {
94+
this.openDialog(err);
95+
});
96+
}
97+
}, (err: any) => {
98+
this.openDialog(err);
99+
})
83100
} else {
84101
this.openDialog('El QR escaneado no es de AFIP');
85102
}
@@ -148,12 +165,16 @@ export class AfipComponent implements OnInit {
148165

149166
let pdv = obj.ptoVta.toLocaleString('es-AR', {minimumIntegerDigits: 5,useGrouping: false});
150167
let num = obj.nroCmp.toLocaleString('es-AR', {minimumIntegerDigits: 8,useGrouping: false});
168+
let nameEmi = '';
169+
let nameRec = '';
151170

152171
return {
153172
docName: comp,
154173
docNumber: pdv + '-' + num,
155174
cuitEmi: obj.cuit,
156175
cuitRec: obj.nroDocRec,
176+
nameEmi: '',
177+
nameRec: '',
157178
date: obj.fecha,
158179
amount: obj.importe,
159180
currency: obj.moneda
@@ -163,10 +184,10 @@ export class AfipComponent implements OnInit {
163184

164185
exportToCSV(): void {
165186
let csvContent = 'data:text/csv;charset=utf-8,';
166-
csvContent += 'Tipo,Nro,Emisor,Receptor,Fecha,Importe,Moneda\r\n';
187+
csvContent += 'Tipo,Nro,Emisor,Emisor CUIT,Receptor,Receptor CUIT,Fecha,Importe,Importe sin IVA 21,Moneda\r\n';
167188

168189
this.invoices.forEach((row) => {
169-
csvContent += row.docName + ',' + row.docNumber + ',' + row.cuitEmi + ',' + row.cuitRec + ',' + row.date + ',' + row.amount + ',' + row.currency + '\r\n';
190+
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';
170191
});
171192

172193
let date = new Date()
@@ -177,7 +198,7 @@ export class AfipComponent implements OnInit {
177198
const encodedUri = encodeURI(csvContent);
178199
const link = document.createElement('a');
179200
link.setAttribute('href', encodedUri);
180-
link.setAttribute('download', 'invoices_afip_' + `${day}${month}${year}` + '.csv');
201+
link.setAttribute('download', 'invoices_afip_' + `${year}${month}${day}` + '.csv');
181202
document.body.appendChild(link);
182203
link.click();
183204
}

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
33
import { Routes, RouterModule } from '@angular/router';
4+
import { HttpClientModule } from '@angular/common/http';
45

56
import { registerLocaleData } from '@angular/common';
67
import locale from '@angular/common/locales/es-AR';
@@ -40,6 +41,7 @@ const routes: Routes = [
4041
BrowserModule,
4142
BrowserAnimationsModule,
4243
RouterModule.forRoot(routes),
44+
HttpClientModule,
4345
MatToolbarModule,
4446
MatButtonModule,
4547
MatTableModule,

0 commit comments

Comments
 (0)