Invoice PAIN & CSV can be uploaded
This commit is contained in:
49
app/Providers/InvoiceCsvFileProvider.php
Normal file
49
app/Providers/InvoiceCsvFileProvider.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user