50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Invoice;
|
|
use App\Resources\InvoiceResource;
|
|
|
|
class InvoiceCsvFileProvider {
|
|
|
|
/* @var Invoice[] */
|
|
private array $invoices;
|
|
|
|
public function __construct(array $invoices) {
|
|
$this->invoices = $invoices;
|
|
}
|
|
|
|
public function createCsvFileContent() : string
|
|
{
|
|
$csvArray[] = implode(
|
|
',', [
|
|
'"Rechnungsnummer"',
|
|
'"Zahlungsgrund"',
|
|
'"Name"',
|
|
'"IBAN"',
|
|
'"Kontoinhaber*in"',
|
|
'"Betrag"',
|
|
'"Spende"',
|
|
'"Beleg ohne Auszahlung"',
|
|
]);
|
|
|
|
foreach ($this->invoices as $invoice) {
|
|
$invoiceReadable = new InvoiceResource($invoice)->toArray();
|
|
$csvLine = implode(',', [
|
|
'"' . $invoiceReadable['invoiceNumber'] . '"',
|
|
'"' . $invoiceReadable['invoiceType'] . '"',
|
|
'"' . $invoiceReadable['contactName'] . '"',
|
|
'"' . $invoiceReadable['accountIban'] . '"',
|
|
'"' . $invoiceReadable['accountOwner'] . '"',
|
|
'"' . $invoiceReadable['amountPlain'] . '"',
|
|
'"' . $invoiceReadable['donation'] . '"',
|
|
'"' . $invoiceReadable['alreadyPaid'] . '"'
|
|
]);
|
|
|
|
$csvArray[] = $csvLine;
|
|
}
|
|
|
|
return implode(PHP_EOL, $csvArray);
|
|
}
|
|
}
|