diff --git a/docker-compose.yml b/docker-compose.yml index fe24b38..ab24afb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: - internal - myadmin www: - image: registry.docker.rhost.ovh/sprawozdania:0.2.3 + image: registry.docker.rhost.ovh/sprawozdania:0.2.5 restart: on-failure platform: linux/x86_64 build: diff --git a/project/config/secrets/dev/dev.API_FAKTUROWNIA.f73a67.php b/project/config/secrets/dev/dev.API_FAKTUROWNIA.f73a67.php new file mode 100644 index 0000000..ef13813 --- /dev/null +++ b/project/config/secrets/dev/dev.API_FAKTUROWNIA.f73a67.php @@ -0,0 +1,3 @@ + null, 'DATABASE_PASSWORD' => null, ]; diff --git a/project/config/services.yaml b/project/config/services.yaml index 936b204..c0b3417 100644 --- a/project/config/services.yaml +++ b/project/config/services.yaml @@ -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 diff --git a/project/src/Controller/BaseController.php b/project/src/Controller/BaseController.php index 717d814..b759c82 100644 --- a/project/src/Controller/BaseController.php +++ b/project/src/Controller/BaseController.php @@ -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')] diff --git a/project/src/Controller/ReportsController.php b/project/src/Controller/ReportsController.php index 04d988f..fb1a55b 100644 --- a/project/src/Controller/ReportsController.php +++ b/project/src/Controller/ReportsController.php @@ -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); } diff --git a/project/src/Controller/ScheduleController.php b/project/src/Controller/ScheduleController.php index 63ea051..63c3036 100644 --- a/project/src/Controller/ScheduleController.php +++ b/project/src/Controller/ScheduleController.php @@ -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"); diff --git a/project/src/Security/SchedulesVoter.php b/project/src/Security/SchedulesVoter.php new file mode 100644 index 0000000..db77fa8 --- /dev/null +++ b/project/src/Security/SchedulesVoter.php @@ -0,0 +1,55 @@ +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'); + } +} \ No newline at end of file diff --git a/project/src/Services/InvoiceServices.php b/project/src/Services/InvoiceServices.php index 6264cdd..8a808fc 100644 --- a/project/src/Services/InvoiceServices.php +++ b/project/src/Services/InvoiceServices.php @@ -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, + ]; } } \ No newline at end of file diff --git a/project/src/Twig/AppExtension.php b/project/src/Twig/AppExtension.php index f0b135e..a029759 100644 --- a/project/src/Twig/AppExtension.php +++ b/project/src/Twig/AppExtension.php @@ -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"; diff --git a/project/templates/navigation/top.html.twig b/project/templates/navigation/top.html.twig index dc0eae1..d84d056 100644 --- a/project/templates/navigation/top.html.twig +++ b/project/templates/navigation/top.html.twig @@ -12,9 +12,11 @@ Sprawozdania {% endif %} + {% if is_granted('scheduleView') %}