Invoices can be uploaded
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Enumerations\UserRole;
|
||||
|
||||
class AuthCheckProvider {
|
||||
public function checkLoggedIn() : bool {
|
||||
if (!auth()->check()) {
|
||||
@@ -14,8 +16,11 @@ class AuthCheckProvider {
|
||||
return $user->active;
|
||||
}
|
||||
|
||||
if ($user->user_role_main === UserRole::USER_ROLE_ADMIN) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $user->active && $tenant->slug === $user->tenant;
|
||||
return $user->active && $tenant->slug === $user->local_group;
|
||||
}
|
||||
|
||||
public function getUserRole() : ?string {
|
||||
|
||||
11
app/Providers/FlashMessageProvider.php
Normal file
11
app/Providers/FlashMessageProvider.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
class FlashMessageProvider {
|
||||
public function __construct(string $message, string $messageType) {
|
||||
session()->put('message',
|
||||
serialize(['messageType' => $messageType, 'message' => $message])
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Enumerations\InvoiceType;
|
||||
use App\Enumerations\UserRole;
|
||||
use App\Models\User;
|
||||
use App\Repositories\PageTextRepository;
|
||||
use App\Resources\UserResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GlobalDataProvider {
|
||||
private ?User $user;
|
||||
@@ -20,6 +24,57 @@ class GlobalDataProvider {
|
||||
]);
|
||||
}
|
||||
|
||||
public function getInvoiceTypes() : JsonResponse {
|
||||
$invoiceTypes = [];
|
||||
foreach (InvoiceType::all() as $invoiceType) {
|
||||
if (
|
||||
$invoiceType->slug === InvoiceType::INVOICE_TYPE_TRAVELLING ||
|
||||
$invoiceType->slug === InvoiceType::INVOICE_TYPE_OTHER
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$invoiceTypes[] = [
|
||||
'slug' => $invoiceType->slug,
|
||||
'name' => $invoiceType->name
|
||||
];
|
||||
}
|
||||
|
||||
$invoiceTypes[] = ['slug' => InvoiceType::INVOICE_TYPE_OTHER, 'name' => 'Sonstige Kosten'];
|
||||
|
||||
return response()->json([
|
||||
'invoiceTypes' => $invoiceTypes
|
||||
]);
|
||||
}
|
||||
|
||||
public function getMessages() : JsonResponse {
|
||||
$messageContainer = [
|
||||
'message' => '',
|
||||
'type' => ''
|
||||
];
|
||||
|
||||
$message = session()->get('message');
|
||||
|
||||
if (null !== $message) {
|
||||
$message = session()->get('message');
|
||||
session()->forget('message');
|
||||
|
||||
if('' !== $message ) {
|
||||
$messageContainer = unserialize($message);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($messageContainer);
|
||||
}
|
||||
|
||||
public function getTextResourceText(string $textResource) : JsonResponse {
|
||||
$pageTextRepository = new PageTextRepository();
|
||||
|
||||
return response()->json([
|
||||
'content' => $pageTextRepository->getPageText( $textResource)
|
||||
]);
|
||||
}
|
||||
|
||||
private function generateNavbar() : array {
|
||||
$navigation = [
|
||||
'personal' => [],
|
||||
@@ -42,7 +97,7 @@ class GlobalDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
$navigation['common'][] = ['url' => '/capture-invoice', 'display' => 'Neue Abrechnung'];
|
||||
$navigation['common'][] = ['url' => '/invoice/new', 'display' => 'Neue Abrechnung'];
|
||||
$navigation['common'][] = ['url' => '/available-events', 'display' => 'Verfügbare Veranstaltungen'];
|
||||
|
||||
return $navigation;
|
||||
|
||||
@@ -22,11 +22,6 @@ final class InertiaProvider
|
||||
}
|
||||
|
||||
public function render() : Response {
|
||||
if (null !== session()->get('message')) {
|
||||
$this->props['message'] = session()->get('message');
|
||||
session()->forget('message');
|
||||
}
|
||||
|
||||
$this->props['availableLocalGroups'] = Tenant::where(['is_active_local_group' => true])->get();
|
||||
|
||||
return Inertia::render(
|
||||
|
||||
52
app/Providers/UploadFileProvider.php
Normal file
52
app/Providers/UploadFileProvider.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\CostUnit;
|
||||
use App\ValueObjects\InvoiceFile;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UploadFileProvider {
|
||||
private UploadedFile $file;
|
||||
private CostUnit $costUnit;
|
||||
|
||||
public function __construct(UploadedFile $file, CostUnit $costUnit) {
|
||||
$this->file = $file;
|
||||
$this->costUnit = $costUnit;
|
||||
}
|
||||
|
||||
public function saveUploadedFile() : ?InvoiceFile {
|
||||
try {
|
||||
$directory = sprintf(
|
||||
'%1$s/invoices/%2$s',
|
||||
app('tenant')->slug,
|
||||
$this->costUnit->id
|
||||
);
|
||||
|
||||
$filename = $this->normalizeFilename($this->file->getClientOriginalName());
|
||||
|
||||
$path = $this->file->storeAs(
|
||||
$directory,
|
||||
$filename
|
||||
);
|
||||
|
||||
$invoiceFile = new InvoiceFile();
|
||||
$invoiceFile->filename = $filename;
|
||||
$invoiceFile->path = $path;
|
||||
return $invoiceFile;
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeFilename(string $filename) : string {
|
||||
return strtolower($filename)
|
||||
|> function (string $filename) : string { return str_replace(' ', '_', $filename); }
|
||||
|> function (string $filename) : string { return str_replace('ä', 'ae', $filename); }
|
||||
|> function (string $filename) : string { return str_replace('ö', 'oe', $filename); }
|
||||
|> function (string $filename) : string { return str_replace('ü', 'ue', $filename); }
|
||||
|> function (string $filename) : string { return str_replace('ß', 'ss', $filename); };
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user