From fb85ac565f0d24345674bb71b5d3a13024d299f2 Mon Sep 17 00:00:00 2001 From: Ryjek Date: Tue, 8 Oct 2024 23:47:04 +0200 Subject: [PATCH] test invoices --- docker-compose.yml | 1 + project/composer.json | 1 + project/composer.lock | 174 ++++++++++++++++++- project/config/services.yaml | 1 + project/src/Controller/ReportsController.php | 15 +- project/src/Services/InvoiceServices.php | 98 +++++++++++ 6 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 project/src/Services/InvoiceServices.php diff --git a/docker-compose.yml b/docker-compose.yml index 82f6c53..5f0cbe5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,7 @@ services: - internal - myadmin www: + platform: linux/x86_64 image: registry.docker.rhost.ovh/sprawozdania:0.2.2 restart: on-failure build: diff --git a/project/composer.json b/project/composer.json index b4cdc3c..f5f2bc6 100644 --- a/project/composer.json +++ b/project/composer.json @@ -17,6 +17,7 @@ "symfony/dotenv": "6.4.*", "symfony/form": "6.4.*", "symfony/framework-bundle": "6.4.*", + "symfony/http-client": "^7.1", "symfony/runtime": "6.4.*", "symfony/security-bundle": "6.4.*", "symfony/stimulus-bundle": "^2.18", diff --git a/project/composer.lock b/project/composer.lock index a6b685f..547e57b 100644 --- a/project/composer.lock +++ b/project/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "84b6eb8586cc5012ba63fa2692e0acd1", + "content-hash": "f61a92b404d4256be3343c63e0dd5b46", "packages": [ { "name": "dflydev/dot-access-data", @@ -3370,6 +3370,178 @@ ], "time": "2024-07-26T13:24:20+00:00" }, + { + "name": "symfony/http-client", + "version": "v7.1.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client.git", + "reference": "abca35865118edf35a23f2f24978a1784c831cb4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client/zipball/abca35865118edf35a23f2f24978a1784c831cb4", + "reference": "abca35865118edf35a23f2f24978a1784c831cb4", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "psr/log": "^1|^2|^3", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/http-client-contracts": "^3.4.1", + "symfony/service-contracts": "^2.5|^3" + }, + "conflict": { + "php-http/discovery": "<1.15", + "symfony/http-foundation": "<6.4" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "1.0", + "symfony/http-client-implementation": "3.0" + }, + "require-dev": { + "amphp/amp": "^2.5", + "amphp/http-client": "^4.2.1", + "amphp/http-tunnel": "^1.0", + "amphp/socket": "^1.1", + "guzzlehttp/promises": "^1.4|^2.0", + "nyholm/psr7": "^1.0", + "php-http/httplug": "^1.0|^2.0", + "psr/http-client": "^1.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/messenger": "^6.4|^7.0", + "symfony/process": "^6.4|^7.0", + "symfony/rate-limiter": "^6.4|^7.0", + "symfony/stopwatch": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", + "homepage": "https://symfony.com", + "keywords": [ + "http" + ], + "support": { + "source": "https://github.com/symfony/http-client/tree/v7.1.5" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-20T13:35:23+00:00" + }, + { + "name": "symfony/http-client-contracts", + "version": "v3.5.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client-contracts.git", + "reference": "20414d96f391677bf80078aa55baece78b82647d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/20414d96f391677bf80078aa55baece78b82647d", + "reference": "20414d96f391677bf80078aa55baece78b82647d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\HttpClient\\": "" + }, + "exclude-from-classmap": [ + "/Test/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to HTTP clients", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/http-client-contracts/tree/v3.5.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-04-18T09:32:20+00:00" + }, { "name": "symfony/http-foundation", "version": "v7.1.3", diff --git a/project/config/services.yaml b/project/config/services.yaml index da10f6f..936b204 100644 --- a/project/config/services.yaml +++ b/project/config/services.yaml @@ -24,5 +24,6 @@ services: resource: '../src/Services/' arguments: - '@doctrine.orm.entity_manager' + - '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/ReportsController.php b/project/src/Controller/ReportsController.php index 6e73089..04d988f 100644 --- a/project/src/Controller/ReportsController.php +++ b/project/src/Controller/ReportsController.php @@ -6,6 +6,7 @@ use App\Entity\Reports; use App\Entity\ReportsTodo; use App\Enum\ReportTodoEnum; use App\Services\AddReports; +use App\Services\InvoiceServices; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -17,7 +18,7 @@ class ReportsController extends AbstractController { #[Route('/set-status-todo/{id}', name: 'app_set_status_todo', methods: ['POST'])] #[IsGranted('reportEdit')] - public function setStatusTodo(EntityManagerInterface $entityManager, AddReports $reportsService, Request $request, Reports $report): Response + public function setStatusTodo(EntityManagerInterface $entityManager, AddReports $reportsService, InvoiceServices $invoiceServices, Request $request, Reports $report): Response { $token = $request->get("token"); if ($this->isCsrfTokenValid('report-status', $token)) { @@ -53,7 +54,13 @@ 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(); + } $entityManager->persist($todo); + } } $entityManager->persist($report); @@ -100,4 +107,10 @@ class ReportsController extends AbstractController } return $this->redirectToRoute('app_client', ['id'=>$clientId]); } + + #[Route('/testapi')] + public function test() + { + return new Response(var_export($_POST,true)); + } } \ No newline at end of file diff --git a/project/src/Services/InvoiceServices.php b/project/src/Services/InvoiceServices.php new file mode 100644 index 0000000..6264cdd --- /dev/null +++ b/project/src/Services/InvoiceServices.php @@ -0,0 +1,98 @@ +clients = $clients; + } + + /** + * @param \DateTimeInterface $reportDate + */ + public function setReportDate(\DateTimeInterface $reportDate): void + { + $this->reportDate = $reportDate->modify('-1 month'); + } + + public function send(): void + { + $this->curl->request( + 'POST', +// 'https://kancelariakolczynski.fakturownia.pl/invoices.json', + 'http://sprawozdania.docker/testapi', + [ + 'headers' => [ + 'Accept' => 'application/json', + ], + 'json' => $this->preparePost() + ] + ); + } + + private function postToJson(): string + { + return json_encode($this->preparePost()); + } + + private function preparePost() : array + { + if (!isset($this->clients) || !isset($this->reportDate)) { + return []; + } + $todayObj = new \DateTime("now"); + $todayStr = $todayObj->format('Y-m-d'); + $paymentToObj = new \DateTime("+7 days"); + $paymentToStr = $paymentToObj->format('Y-m-d'); + $monthStartPeriod = (clone $this->reportDate)->modify("-2 months")->format('m'); + $periodStr = $monthStartPeriod . ' - ' . $this->reportDate->format('m') . '/' . $this->reportDate->format('Y'); + + $post = [ + 'kinds' => ["vat","proforma"], + 'number' => null, + 'sell_date' => $todayStr, + 'issue_date' => $todayStr, + 'payment_to' => $paymentToStr, + 'buyer_name' => $this->clients->getStrName(), + 'buyer_email' => $this->clients->getStrEmail(), + 'buyer_tax_no' => $this->clients->getIntNIP(), + 'positions' => [ + [ + 'name' => "Przygotowanie sprawozdanie z wykonania układu za okres $periodStr", + 'tax' => 23, + 'total_price_gross' => 553.5 + ] + ] + ]; +// "kind":"vat", +// "number": null, +// "sell_date": "2013-01-16", +// "issue_date": "2013-01-16", +// "payment_to": "2013-01-23", +// "seller_name": "Wystawca Sp. z o.o.", +// "seller_tax_no": "6272616681", +// "buyer_name": "Klient1 Sp. z o.o.", +// "buyer_email": "buyer@testemail.pl", +// "buyer_tax_no": "6272616681", +// "positions":[ +// {"name":"Produkt A1", "tax":23, "total_price_gross":10.23, "quantity":1}, +// {"name":"Produkt A2", "tax":0, "total_price_gross":50, "quantity":3} +// ] + + return $post; + } +} \ No newline at end of file