Skip to content

Commit

Permalink
csv
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothauer committed Dec 5, 2024
1 parent 47cba43 commit 9dc4d15
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions plugins/Admin/src/Controller/FundingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ public function foerderantragPdf($fundingUid) {

public function bankExport() {

$this->disableAutoRender();
$fundingsTable = $this->getTableLocator()->get('Fundings');

$fundings = $fundingsTable->find('all',
conditions: $this->conditions,
conditions: [
$fundingsTable->aliasField('submit_date IS NOT NULL'),
],
contain: [
'OwnerUsers',
'Fundingsupporters',
Expand All @@ -53,28 +56,20 @@ public function bankExport() {

$validFundings = [];
foreach($fundings as $funding) {

if (!$funding->is_submitted) {
continue;
}

if ($funding->owner_user) {
$funding->owner_user->revertPrivatizeData();
}

$funding->owner_user->revertPrivatizeData();
$validFundings[] = $funding;

}

$writer = Writer::createFromString();
$writer->setDelimiter(';');

$writer->insertOne($this->getCsvHeader());
$records = [];
foreach($validFundings as $funding) {
$record = [];
$record = [
'EUR', // Währung
$funding->budgetplan_total_with_limit, // VorzBetrag
number_format($funding->budgetplan_total_with_limit, 2, ',', ''), // VorzBetrag
'Antrag-' . $funding->uid, // RechNr
date('d.m.Y'), // Belegdatum
'', // InterneRechNr
Expand All @@ -85,7 +80,7 @@ public function bankExport() {
'5010', // Konto
'', // Kontobezeichnung
'Reparaturförderung', // Ware/Leistung
date('Y.m.d'), // Fällig_am
date('d.m.Y'), // Fällig_am
'', // gezahlt_am
'', // UStSatz
'', // USt-IdNr.Kunde
Expand All @@ -97,24 +92,23 @@ public function bankExport() {
'', // Skonto
'', // Nachricht
'', // Skto_Fällig_am
'', // BankKonto
'', // BankBlz
$funding->fundingsupporter->bank_institute, // Bankname
$funding->fundingsupporter->iban, // BankKonto
$funding->fundingsupporter->bic, // BankBlz
$funding->fundingsupporter->iban, // BankIban
$funding->fundingsupporter->bic, // BankBic
'', // Skto_Proz
'', // Leistungsdatum
];
$records[] = $record;
}
$writer->insertAll($records);

$this->disableAutoRender();

pr($writer->toString());
exit;

$response = $this->response;
$response = $response->withStringBody($writer->toString());
$response = $response->withCharset('UTF-8');
$response = $response->withDownload('bankexport' . DateTime::now()->i18nFormat('yyyyMMdd_HHmmss') . '.csv');
$response = $response->withDownload('bankexport-' . DateTime::now()->i18nFormat('yyyyMMdd_HHmmss') . '.csv');
return $response;

}

Expand All @@ -135,7 +129,7 @@ private function getCsvHeader() {
'Fällig_am',
'gezahlt_am',
'UStSatz',
'USt-IdNr.Kunde',
'USt-IdNr.Lieferant',
'Kunden-Nr.',
'KOST1',
'KOST2',
Expand All @@ -150,6 +144,7 @@ private function getCsvHeader() {
'BankIban',
'BankBic',
'Skto_Proz',
'Leistungsdatum',
];
}

Expand Down

0 comments on commit 9dc4d15

Please sign in to comment.