Skip to content

Commit

Permalink
feat(invoice): support credit of invoice format
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAndersen committed Dec 12, 2024
1 parent db7e0cd commit 5b00be1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
19 changes: 17 additions & 2 deletions src/app/invoice/invoice-table/invoice-table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="col-auto">
<button
class="btn btn-sm btn-outline-primary"
(click)="exportToExcel(false)"
(click)="exportToExcel(false, false)"
>
<fa-icon icon="file-excel" class="mr-2"></fa-icon>
<fa-icon
Expand All @@ -62,7 +62,22 @@
<div class="col-auto">
<button
class="btn btn-sm btn-outline-primary"
(click)="exportToExcel(true)"
(click)="exportToExcel(false, true)"
>
<fa-icon icon="file-excel" class="mr-2"></fa-icon>
<fa-icon
icon="circle-notch"
[spin]="true"
*ngIf="printToExcelWait"
></fa-icon>
<span *ngIf="!printToExcelWait">Visma kredittnota-format</span>
</button>
</div>

<div class="col-auto">
<button
class="btn btn-sm btn-outline-primary"
(click)="exportToExcel(true, false)"
>
<fa-icon icon="file-excel" class="mr-2"></fa-icon>
<fa-icon
Expand Down
6 changes: 3 additions & 3 deletions src/app/invoice/invoice-table/invoice-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ export class InvoiceTableComponent implements OnInit, OnChanges {
}
}

public exportToExcel(ehf: boolean) {
let selectedInvoices = this.getSelected();
public exportToExcel(ehf: boolean, isCreditOfInvoice: boolean) {
const selectedInvoices = this.getSelected();
this.printToExcelWait = true;

this.invoiceVismaService
.printToVismaInvoices(selectedInvoices, ehf)
.printToVismaInvoices(selectedInvoices, ehf, isCreditOfInvoice)
.then(() => {
this.printToExcelWait = false;
})
Expand Down
45 changes: 39 additions & 6 deletions src/app/invoice/invoice-visma/invoice-visma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,32 @@ export class InvoiceVismaService {

public async printToVismaInvoices(
invoices: Invoice[],
ehf: boolean
ehf: boolean,
isCreditOfInvoice: boolean
): Promise<boolean> {
await this.addBranchNames(invoices);
const vismaRows = this.invoicesToVismaRows(invoices, ehf);
const vismaRows = this.invoicesToVismaRows(
invoices,
ehf,
isCreditOfInvoice
);
this.printService.printVismaRows(vismaRows);
return true;
}

public invoicesToVismaRows(invoices: Invoice[], ehf: boolean) {
public invoicesToVismaRows(
invoices: Invoice[],
ehf: boolean,
isCreditOfInvoice: boolean
) {
const vismaRows = [];

for (const invoice of invoices) {
for (const row of this.invoiceToVismaRows(invoice, ehf)) {
for (const row of this.invoiceToVismaRows(
invoice,
ehf,
isCreditOfInvoice
)) {
vismaRows.push(row);
}
}
Expand Down Expand Up @@ -356,10 +369,18 @@ export class InvoiceVismaService {
return epoch + counter; // return epoch + randomVal + counter;
}

private invoiceToVismaRows(invoice: Invoice, ehf: boolean): any[] {
private invoiceToVismaRows(
invoice: Invoice,
ehf: boolean,
isCreditOfInvoice: boolean
): any[] {
const rows = [];
let lineNum = 0;
rows.push(this.createVismaH1Field(lineNum, invoice, ehf));
if (isCreditOfInvoice) {
rows.push(this.createVismaH3Field(lineNum, invoice));
} else {
rows.push(this.createVismaH1Field(lineNum, invoice, ehf));
}

lineNum++;

Expand Down Expand Up @@ -476,6 +497,18 @@ export class InvoiceVismaService {
lineNumber++;
return rows;
}
private createVismaH3Field(lineNum: number, invoice: Invoice) {
const customerNumber = invoice.customerInfo.userDetail
? this.getInvoiceMiniID(invoice).toString()
: invoice.customerInfo.customerNumber;

return [
"H3", // 1 Record Type (M)
lineNum, // 2 Line number (M)
customerNumber, // 3 Customer no (M)
invoice.invoiceId, // 4 Invoice number (M)
];
}

private createVismaH1Field(
lineNum: number,
Expand Down

0 comments on commit 5b00be1

Please sign in to comment.