Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 157 fundings 4 #168

Merged
merged 13 commits into from
Dec 9, 2024
15 changes: 15 additions & 0 deletions config/Migrations/20241203155342_Fundings6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

use Migrations\AbstractMigration;

class Fundings6 extends AbstractMigration
{
public function change(): void
{
$sql = "ALTER TABLE `fundings`
ADD `zuwendungsbestaetigung_status` int(10) DEFAULT 10 AFTER `freistellungsbescheid_comment`,
ADD `zuwendungsbestaetigung_comment` text AFTER `zuwendungsbestaetigung_status`";
$this->execute($sql);
}
}
1 change: 1 addition & 0 deletions config/app_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
define('ZIP_REGEX', '/^[0-9]{4,5}$/');
define('ZIP_REGEX_DE', '/^[0-9]{5}$/');
define('BIC_REGEX', '/^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/');
define('UUID_REGEX', '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[0-5][a-fA-F0-9]{3}-[089aAbB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}'); // see Validate::uuid()

return [
'Email' => [
Expand Down
28 changes: 8 additions & 20 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,19 @@

if (Configure::read('AppConfig.fundingsEnabled')) {
$routes->connect('/mein-foerderantrag', ['controller'=>'fundings', 'action'=>'index']);
$routes->connect('/mein-foerderantrag/{action}/{workshopUid}', [
'controller'=>'fundings',
'action'=>'{action}'
],
)->setPatterns([
'action' => 'edit',
'workshopUid' => '[0-9]+'
]);

$routes->connect('/mein-foerderantrag/delete/{fundingUid}', [
'controller'=>'fundings',
'action'=>'delete'
])->setPatterns(['fundingUid' => '[0-9]+']);

$routes->connect('/mein-foerderantrag/download/{type}/{fundingUid}', [
$routes->connect('/mein-foerderantrag/download/{type}/{uid}', [
'controller'=>'fundings',
'action'=>'download'
])->setPatterns([
'type' => 'foerderantrag|foerderbewilligung',
'fundingUid' => '[0-9]+'
'uid' => '[0-9]+'
]);

$routes->connect('/mein-foerderantrag/uploadDetail/{fundinguploadId}', [
'controller'=>'fundings',
'action'=>'uploadDetail'
$routes->connect('/mein-foerderantrag/{action}/{uid}', [
'controller' => 'fundings',
'action'=> '{action}'
])->setPatterns([
'action' => 'uploadDetail|uploadZuwendungsbestaetigung|edit|delete',
'uid' => '[0-9]+|(' . UUID_REGEX . ')',
]);
}

Expand Down
4 changes: 4 additions & 0 deletions plugins/Admin/src/Controller/AdminAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ protected function generateSearchConditions($searchFieldKey)
]
];
break;
case 'custom':
$this->conditions[] = $searchOption['conditions'][$queryParams['val-' . $searchFieldKey]];
break;

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/Admin/src/Controller/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function index()

$objects = $this->paginate($query, [
'order' => [
'Events.updated' => 'DESC'
'Events.uid' => 'DESC'
]
]);
foreach($objects as $object) {
Expand Down
26 changes: 25 additions & 1 deletion plugins/Admin/src/Controller/FundingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,29 @@
use Cake\I18n\DateTime;
use App\Services\PdfWriter\FoerderantragPdfWriterService;
use League\Csv\Writer;
use App\Model\Entity\Funding;

class FundingsController extends AdminAppController
{

public $searchName = false;
public $searchText = false;
public $searchUid = false;

public $searchStatus = false;

public function beforeFilter(EventInterface $event) {
$this->addSearchOptions([
'Workshops.name' => [
'name' => 'Workshops.name',
'searchType' => 'search'
],
'FundingStatus' => [
'searchType' => 'custom',
'conditions' => Funding::ADMIN_FILTER_CONDITIONS,
'extraDropdown' => true
],
]);
$this->generateSearchConditions('opt-1');
parent::beforeFilter($event);
}

Expand Down Expand Up @@ -173,6 +180,9 @@ public function edit($uid)
'FundinguploadsFreistellungsbescheids' => function($q) {
return $q->order(['FundinguploadsFreistellungsbescheids.created' => 'DESC']);
},
'FundinguploadsZuwendungsbestaetigungs' => function($q) {
return $q->order(['FundinguploadsZuwendungsbestaetigungs.created' => 'DESC']);
},
])->first();

if ($funding->owner_user) {
Expand Down Expand Up @@ -232,6 +242,18 @@ private function sendEmails($funding) {
]);
$email->addToQueue();
}

if ($funding->isDirty('zuwendungsbestaetigung_status')) {
$email->viewBuilder()->setTemplate('fundings/zuwendungsbestaetigung_status_changed');
$email->setSubject('Der Status deiner Zuwendungsbestätigung wurde geändert')
->setTo($funding->owner_user->email)
->setViewVars([
'funding' => $funding,
'data' => $funding->owner_user,
]);
$email->addToQueue();
}

}

public function index()
Expand All @@ -249,6 +271,7 @@ public function index()
'Fundingsupporters',
'FundinguploadsActivityProofs',
'FundinguploadsFreistellungsbescheids',
'FundinguploadsZuwendungsbestaetigungs',
'Fundingbudgetplans',
]);

Expand All @@ -267,6 +290,7 @@ public function index()
}

$this->set('objects', $objects);
$this->set('fundingStatus', Funding::ADMIN_FILTER_OPTIONS);

}

Expand Down
2 changes: 1 addition & 1 deletion plugins/Admin/src/Controller/WorkshopsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function index()

$objects = $this->paginate($query, [
'order' => [
'Workshops.name' => 'ASC'
'Workshops.created' => 'DESC'
],
]);

Expand Down
21 changes: 19 additions & 2 deletions plugins/Admin/templates/Fundings/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
if ($funding->workshop->funding_activity_proof_required) {
echo $this->element('funding/fundingUploadsForm', [
'fundinguploads' => $funding->fundinguploads_activity_proofs,
'uploadType' => Fundingupload::TYPE_MAP[Fundingupload::TYPE_ACTIVITY_PROOF],
'uploadType' => Fundingupload::TYPE_MAP_STEP_1[Fundingupload::TYPE_ACTIVITY_PROOF],
'legend' => 'Uploads Aktivitätsnachweis',
]);

Expand All @@ -49,7 +49,7 @@

echo $this->element('funding/fundingUploadsForm', [
'fundinguploads' => $funding->fundinguploads_freistellungsbescheids,
'uploadType' => Fundingupload::TYPE_MAP[Fundingupload::TYPE_FREISTELLUNGSBESCHEID],
'uploadType' => Fundingupload::TYPE_MAP_STEP_1[Fundingupload::TYPE_FREISTELLUNGSBESCHEID],
'legend' => 'Upload Freistellungsbescheid',
]);

Expand Down Expand Up @@ -110,6 +110,23 @@

echo $this->element('funding/blocks/blockCheckboxes', ['funding' => $funding, 'disabled' => true]);


if ($funding->is_submitted) {
echo $this->element('funding/fundingUploadsForm', [
'fundinguploads' => $funding->fundinguploads_zuwendungsbestaetigungs,
'uploadType' => Fundingupload::TYPE_MAP_STEP_2[Fundingupload::TYPE_ZUWENDUNGSBESTAETIGUNG],
'legend' => 'Upload Zuwendungsbestätigung',
]);

echo '<fieldset>';
echo '<legend>Status Zuwendungsbestätigung</legend>';
echo $this->element('funding/status/zuwendungsbestaetigungStatus', ['funding' => $funding, 'additionalTextBefore' => '']);
echo $this->Form->control('Fundings.zuwendungsbestaetigung_status', ['label' => 'Status', 'options' => Funding::STATUS_MAPPING_UPLOADS, 'disabled' => !$funding->is_submitted, 'class' => 'no-verify']);
echo $this->Form->control('Fundings.zuwendungsbestaetigung_comment', ['label' => 'Kommentar', 'disabled' => !$funding->is_submitted, 'class' => 'no-verify']);
echo '</fieldset>';
}


echo '</div>';

echo $this->element('cancelAndSaveButton', ['saveLabel' => 'Speichern']);
Expand Down
6 changes: 5 additions & 1 deletion plugins/Admin/templates/Fundings/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
'heading' => 'Förderanträge',
'editMethod' => ['url' => 'urlFundingsAdminEdit'],
'deleteMethod' => '/admin/intern/ajaxDeleteFunding',
'fields' => [
'optionalSearchForms' => [
['options' => $fundingStatus, 'value' => 'FundingStatus', 'label' => 'Status'],
],
'fields' => [
['name' => 'uid', 'label' => 'UID'],
['name' => 'workshop.name', 'label' => 'Initiative', 'sortable' => false],
['label' => 'AN', 'template' => 'list/fundings/activityProof'],
Expand All @@ -15,6 +18,7 @@
['name' => 'fundingsupporter.name', 'label' => 'Träger', 'sortable' => false],
['label' => 'Summe', 'template' => 'list/fundings/budgetplan', 'sortable' => false],
['label' => 'eingereicht', 'template' => 'list/fundings/submitInfo'],
['label' => 'ZB', 'template' => 'list/fundings/zuwendungsbestaetigung'],
['name' => 'created', 'type' => 'datetime', 'label' => 'erstellt'],
['name' => 'modified', 'type' => 'datetime', 'label' => 'geändert'],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
if (!$object->is_submitted) {
return;
}
echo '<div style="padding:5px;" class="'. $object->zuwendungsbestaetigung_status_css_class .'">';
echo $object->zuwendungsbestaetigungs_count . 'x';
echo '</div>';
95 changes: 66 additions & 29 deletions src/Controller/FundingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function createdByOtherOwnerCheck($workshopUid) {

public function edit() {

$workshopUid = (int) $this->getRequest()->getParam('workshopUid');
$workshopUid = (int) $this->getRequest()->getParam('uid');

$createdByOtherOwnerCheckMessage = $this->createdByOtherOwnerCheck($workshopUid);
if ($createdByOtherOwnerCheckMessage != '') {
Expand Down Expand Up @@ -153,8 +153,8 @@ public function edit() {
$patchedEntity = $this->patchFunding($funding, $associations);
$errors = $patchedEntity->getErrors();

$newFundinguploads = $this->handleNewFundinguploads($funding, $associations, $patchedEntity);
$this->handleDeleteFundinguploads($funding, $associations, $patchedEntity, $newFundinguploads);
$newFundinguploads = $this->handleNewFundinguploads($funding, $associations, $patchedEntity, Fundingupload::TYPE_MAP_STEP_1);
$this->handleDeleteFundinguploads($funding, $associations, $patchedEntity, $newFundinguploads, Fundingupload::TYPE_MAP_STEP_1);

if (!empty($errors)) {
$patchedEntity = $this->getPatchedFundingForValidFields($errors, $workshopUid, $associationsWithoutValidation);
Expand All @@ -173,25 +173,7 @@ public function edit() {
$fundingsTable->save($patchedEntity, ['associated' => $associationsWithoutValidation]);
$this->AppFlash->setFlashMessage('Der Förderantrag wurde erfolgreich zwischengespeichert.');

foreach(Fundingupload::TYPE_MAP as $uploadTypeId => $uploadType) {
if (!empty($this->request->getData('Fundings.fundinguploads_' . $uploadType))) {
// patch id for new fundinguploads
$fundinguploadsFromDatabase = $this->getTableLocator()->get('Fundinguploads')->find()->where([
'Fundinguploads.funding_uid' => $funding->uid,
])->toArray();
$updatedFundinguploads = [];
foreach($this->request->getData('Fundings.fundinguploads_' . $uploadType) as $fundingupload) {
foreach($fundinguploadsFromDatabase as $fundinguploadFromDatabaseEntity) {
if ($fundingupload['filename'] == $fundinguploadFromDatabaseEntity->filename) {
$fundingupload['id'] = $fundinguploadFromDatabaseEntity->id;
$updatedFundinguploads[] = $fundingupload;
}
}
}
$this->request = $this->request->withData('Fundings.fundinguploads_' . $uploadType ?? [], $updatedFundinguploads);
$patchedEntity = $this->patchFunding($funding, $associations);
}
}
$patchedEntity = $this->handleUpdateNewFundinguploadsWithIds($funding, $associations, $patchedEntity, Fundingupload::TYPE_MAP_STEP_1);

if (!$patchedEntity->hasErrors() && $funding->is_submittable && !empty($this->request->getData('submit_funding'))) {
$this->submitFunding($funding);
Expand Down Expand Up @@ -260,9 +242,32 @@ private function submitFunding($funding) {

}

private function handleDeleteFundinguploads($funding, $associations, $patchedEntity, $newFundinguploads) {
private function handleUpdateNewFundinguploadsWithIds($funding, $associations, $patchedEntity, $uploadTypes) {
foreach($uploadTypes as $uploadTypeId => $uploadType) {
if (!empty($this->request->getData('Fundings.fundinguploads_' . $uploadType))) {
// patch id for new fundinguploads
$fundinguploadsFromDatabase = $this->getTableLocator()->get('Fundinguploads')->find()->where([
'Fundinguploads.funding_uid' => $funding->uid,
])->toArray();
$updatedFundinguploads = [];
foreach($this->request->getData('Fundings.fundinguploads_' . $uploadType) as $fundingupload) {
foreach($fundinguploadsFromDatabase as $fundinguploadFromDatabaseEntity) {
if ($fundingupload['filename'] == $fundinguploadFromDatabaseEntity->filename) {
$fundingupload['id'] = $fundinguploadFromDatabaseEntity->id;
$updatedFundinguploads[] = $fundingupload;
}
}
}
$this->request = $this->request->withData('Fundings.fundinguploads_' . $uploadType ?? [], $updatedFundinguploads);
$patchedEntity = $this->patchFunding($funding, $associations);
}
}
return $patchedEntity;
}

private function handleDeleteFundinguploads($funding, $associations, $patchedEntity, $newFundinguploads, $uploadTypes) {

foreach(Fundingupload::TYPE_MAP as $uploadTypeId => $uploadType) {
foreach($uploadTypes as $uploadTypeId => $uploadType) {
$deleteFundinguploads = $this->request->getData('Fundings.delete_fundinguploads_' . $uploadType);
if (!empty($deleteFundinguploads)) {
$remainingFundinguploads = $this->request->getData('Fundings.fundinguploads_' . $uploadType) ?? [];
Expand Down Expand Up @@ -298,9 +303,9 @@ private function handleDeleteFundinguploads($funding, $associations, $patchedEnt

}

private function handleNewFundinguploads($funding, $associations, $patchedEntity) {
private function handleNewFundinguploads($funding, $associations, $patchedEntity, $uploadTypes) {
$newFundinguploads = [];
foreach(Fundingupload::TYPE_MAP as $uploadTypeId => $uploadType) {
foreach($uploadTypes as $uploadTypeId => $uploadType) {
$filesFundinguploadsErrors = $patchedEntity->getError('files_fundinguploads_' . $uploadType);
if (!empty($filesFundinguploadsErrors)) {
$patchedEntity->setError('files_fundinguploads_' . $uploadType . '[]', $filesFundinguploadsErrors);
Expand Down Expand Up @@ -374,7 +379,7 @@ private function updateCoordinates($entity, $index, $addressString) {

public function delete()
{
$fundingUid = (int) $this->request->getParam('fundingUid');
$fundingUid = (int) $this->request->getParam('uid');
$fundingsTable = $this->getTableLocator()->get('Fundings');
$fundingsTable->deleteCustom($fundingUid);
$this->AppFlash->setFlashMessage('Der Förderantrag wurde erfolgreich gelöscht.');
Expand Down Expand Up @@ -424,9 +429,41 @@ private function removeValidationFromAssociations($associations) {

}

public function uploadZuwendungsbestaetigung() {

$fundingsTable = $this->getTableLocator()->get('Fundings');
$fundingUid = $this->getRequest()->getParam('uid');
$funding = $fundingsTable->getUnprivatizedFundingWithAllAssociations($fundingUid);

if (!$funding->is_submitted) {
throw new NotFoundException('Förderantrag (UID: '.$fundingUid.') wurde noch nicht eingereicht.');
}

$this->setReferer();

if (!empty($this->request->getData())) {
$associations = ['FundinguploadsZuwendungsbestaetigungs'];
$patchedEntity = $this->patchFunding($funding, $associations);
$newFundinguploads = $this->handleNewFundinguploads($funding, $associations, $patchedEntity, Fundingupload::TYPE_MAP_STEP_2);
$this->handleDeleteFundinguploads($funding, $associations, $patchedEntity, $newFundinguploads, Fundingupload::TYPE_MAP_STEP_2);

$patchedEntity->modified = DateTime::now();
$fundingsTable->save($patchedEntity);
$this->AppFlash->setFlashMessage('Die Zuwendungsbestägigung wurde erfolgreich gespeichert.');
$patchedEntity = $this->handleUpdateNewFundinguploadsWithIds($funding, $associations, $patchedEntity, Fundingupload::TYPE_MAP_STEP_2);

}

$this->set('metaTags', [
'title' => 'Upload Zuwendungsbestätigung zu Förderantrag UID: ' . $funding->uid . ')',
]);
$this->set('funding', $funding);

}

public function download() {

$fundingUid = $this->getRequest()->getParam('fundingUid');
$fundingUid = $this->getRequest()->getParam('uid');
$type = $this->getRequest()->getParam('type');

$fundingsTable = $this->getTableLocator()->get('Fundings');
Expand Down Expand Up @@ -461,7 +498,7 @@ public function download() {

public function uploadDetail() {

$fundinguploadUid = $this->getRequest()->getParam('fundinguploadId');
$fundinguploadUid = $this->getRequest()->getParam('uid');
$fundinguploadsTable = $this->getTableLocator()->get('Fundinguploads');
$fundingupload = $fundinguploadsTable->find('all',
conditions: [
Expand Down
Loading