minor fixes

This commit is contained in:
2025-03-29 20:35:54 +01:00
parent b454bbe77b
commit ed1d991a84
11 changed files with 95 additions and 12 deletions
@@ -0,0 +1,3 @@
<?php // dev.API_FAKTUROWNIA.f73a67 on Fri, 01 Nov 2024 22:52:28 +0100
return "\xA9c\xD0\xC5\xD1\x3Aek\xE6\x24\x16\x15b\x3A\xDF\x83\x9B\xED\xE8n\x04_d\x5B\xAE8\x1B\xAC\x02\x2C\x9CA\xFB\x8Ee\x99\xFC3\xDE\xC34f\x28\x08\x26\xC8\x26o\x88\xF9\xF4z";
+1
View File
@@ -1,5 +1,6 @@
<?php
return [
'API_FAKTUROWNIA' => null,
'DATABASE_PASSWORD' => null,
];
+2 -1
View File
@@ -4,6 +4,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
FAKTUROWNIA_API: '%env(API_FAKTUROWNIA)%'
services:
# default configuration for services in *this* file
@@ -24,6 +25,6 @@ services:
resource: '../src/Services/'
arguments:
- '@doctrine.orm.entity_manager'
- 'Symfony\Contracts\HttpClient\HttpClientInterface'
- '@Symfony\Contracts\HttpClient\HttpClientInterface'
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
+7 -1
View File
@@ -31,9 +31,15 @@ class BaseController extends AbstractController
#[Route('/', name: 'index')]
public function index(): Response
{
if (!$this->isGranted('reportView')) {
if ($this->isGranted('reportView')) {
return $this->redirectToRoute('app_base');
}
if ($this->isGranted('scheduleView')) {
return $this->redirectToRoute('app_schedule');
}
if ($this->isGranted('clientView')) {
return $this->redirectToRoute('app_customers_list');
}
return $this->redirectToRoute('app_base');
}
#[Route('/reports/{monthId}/{clientId}', name: 'app_base')]
+6 -5
View File
@@ -54,11 +54,12 @@ class ReportsController extends AbstractController
$report->setDone(true);
}
}
if ($todo->getName() === ReportTodoEnum::INVOICE_SEND && !$todo->isDeleted()) {
$invoiceServices->setClients($report->getClient());
$invoiceServices->setReportDate($report->getDateStart());
$invoiceServices->send();
}
// if ($todo->getName() === ReportTodoEnum::INVOICE_SEND && !$todo->isDeleted()) {
// $invoiceServices->setApiKey($this->getParameter('FAKTUROWNIA_API'));
// $invoiceServices->setClients($report->getClient());
// $invoiceServices->setReportDate($report->getDateStart());
// $invoiceServices->send();
// }
$entityManager->persist($todo);
}
@@ -10,10 +10,12 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class ScheduleController extends AbstractController
{
#[Route('/schedule/{typeId}', name: 'app_schedule', defaults: ['typeId' => 1])]
#[IsGranted('scheduleView')]
public function index(EntityManagerInterface $entityManager, int $typeId = 1): Response
{
if ($typeId == 1) {
@@ -31,6 +33,7 @@ class ScheduleController extends AbstractController
}
#[Route('/schedule_status/{id}', name: 'app_schedule_status', methods: ['POST'])]
#[IsGranted('scheduleEdit')]
public function setDone(EntityManagerInterface $entityManager, Request $request, Schedule $schedule): Response
{
$token = $request->get("token");
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Security;
use App\Entity\User;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class SchedulesVoter extends Voter
{
const VIEW = "scheduleView";
const EDIT = "scheduleEdit";
public function __construct(readonly private Security $security)
{
}
protected function supports(string $attribute, mixed $subject): bool
{
if (!in_array($attribute, [self::VIEW, self::EDIT])) {
return false;
}
return true; }
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
return match ($attribute) {
self::VIEW => $this->canView(),
self::EDIT => $this->canEdit()
};
}
private function canView(): bool
{
if ($this->canAll()) {
return true;
}
return $this->security->isGranted('ROLE_SCHEDULE_VIEW');
}
private function canEdit(): bool
{
if ($this->canAll()) {
return true;
}
return $this->canView();
}
private function canAll(): bool
{
return $this->security->isGranted('ROLE_ACCESS_ALL');
}
}
+14 -3
View File
@@ -11,7 +11,10 @@ class InvoiceServices
{
private Clients $clients;
private \DateTimeInterface $reportDate;
public function __construct(private EntityManager $entityManager, private HttpClientInterface $curl){}
private string $apiKey;
public function __construct(
private readonly EntityManager $entityManager,
private readonly HttpClientInterface $curl){}
/**
* @param Clients $clients
@@ -21,6 +24,11 @@ class InvoiceServices
$this->clients = $clients;
}
public function setApiKey(string $api): void
{
$this->apiKey = $api;
}
/**
* @param \DateTimeInterface $reportDate
*/
@@ -61,7 +69,7 @@ class InvoiceServices
$monthStartPeriod = (clone $this->reportDate)->modify("-2 months")->format('m');
$periodStr = $monthStartPeriod . ' - ' . $this->reportDate->format('m') . '/' . $this->reportDate->format('Y');
$post = [
$invoice = [
'kinds' => ["vat","proforma"],
'number' => null,
'sell_date' => $todayStr,
@@ -93,6 +101,9 @@ class InvoiceServices
// {"name":"Produkt A2", "tax":0, "total_price_gross":50, "quantity":3}
// ]
return $post;
return [
'api_token' => $this->apiKey,
'invoice' => $invoice,
];
}
}
+1 -1
View File
@@ -49,7 +49,7 @@ class AppExtension extends AbstractExtension
public function getMailtoLink(Reports $reports): string
{
$subject = rawurlencode("Sprawozdanie z wykonania układu");
$subject = rawurlencode("Sprawozdanie z wykonania układu nr {$reports->getNumber()}");
$dateBase = (clone $reports->getDateStart())->modify("-1 month");
$template = "email/report.html.twig";
@@ -12,9 +12,11 @@
<a class="nav-link {{ is_route_active('app_base', route) }}" aria-current="page" href="{{ path('app_base') }}">Sprawozdania</a>
</li>
{% endif %}
{% if is_granted('scheduleView') %}
<li class="nav-item">
<a class="nav-link {{ is_route_active('app_schedule', route) }}" aria-current="page" href="{{ path('app_schedule') }}">Harmonogramy</a>
</li>
{% endif %}
{% if is_granted('clientView') %}
<li class="nav-item">
<a class="nav-link {{ is_route_active('app_customers_list', route) }}" aria-current="page" href="{{ path('app_customers_list') }}">Klienci</a>