test invoices

This commit is contained in:
2024-10-08 23:47:04 +02:00
parent 598acfd77c
commit fb85ac565f
6 changed files with 288 additions and 2 deletions
+1
View File
@@ -14,6 +14,7 @@ services:
- internal - internal
- myadmin - myadmin
www: www:
platform: linux/x86_64
image: registry.docker.rhost.ovh/sprawozdania:0.2.2 image: registry.docker.rhost.ovh/sprawozdania:0.2.2
restart: on-failure restart: on-failure
build: build:
+1
View File
@@ -17,6 +17,7 @@
"symfony/dotenv": "6.4.*", "symfony/dotenv": "6.4.*",
"symfony/form": "6.4.*", "symfony/form": "6.4.*",
"symfony/framework-bundle": "6.4.*", "symfony/framework-bundle": "6.4.*",
"symfony/http-client": "^7.1",
"symfony/runtime": "6.4.*", "symfony/runtime": "6.4.*",
"symfony/security-bundle": "6.4.*", "symfony/security-bundle": "6.4.*",
"symfony/stimulus-bundle": "^2.18", "symfony/stimulus-bundle": "^2.18",
+173 -1
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "84b6eb8586cc5012ba63fa2692e0acd1", "content-hash": "f61a92b404d4256be3343c63e0dd5b46",
"packages": [ "packages": [
{ {
"name": "dflydev/dot-access-data", "name": "dflydev/dot-access-data",
@@ -3370,6 +3370,178 @@
], ],
"time": "2024-07-26T13:24:20+00:00" "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", "name": "symfony/http-foundation",
"version": "v7.1.3", "version": "v7.1.3",
+1
View File
@@ -24,5 +24,6 @@ services:
resource: '../src/Services/' resource: '../src/Services/'
arguments: arguments:
- '@doctrine.orm.entity_manager' - '@doctrine.orm.entity_manager'
- 'Symfony\Contracts\HttpClient\HttpClientInterface'
# add more service definitions when explicit configuration is needed # add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones # please note that last definitions always *replace* previous ones
+14 -1
View File
@@ -6,6 +6,7 @@ use App\Entity\Reports;
use App\Entity\ReportsTodo; use App\Entity\ReportsTodo;
use App\Enum\ReportTodoEnum; use App\Enum\ReportTodoEnum;
use App\Services\AddReports; use App\Services\AddReports;
use App\Services\InvoiceServices;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; 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'])] #[Route('/set-status-todo/{id}', name: 'app_set_status_todo', methods: ['POST'])]
#[IsGranted('reportEdit')] #[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"); $token = $request->get("token");
if ($this->isCsrfTokenValid('report-status', $token)) { if ($this->isCsrfTokenValid('report-status', $token)) {
@@ -53,7 +54,13 @@ class ReportsController extends AbstractController
$report->setDone(true); $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($todo);
} }
} }
$entityManager->persist($report); $entityManager->persist($report);
@@ -100,4 +107,10 @@ class ReportsController extends AbstractController
} }
return $this->redirectToRoute('app_client', ['id'=>$clientId]); return $this->redirectToRoute('app_client', ['id'=>$clientId]);
} }
#[Route('/testapi')]
public function test()
{
return new Response(var_export($_POST,true));
}
} }
+98
View File
@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace App\Services;
use App\Entity\Clients;
use Doctrine\ORM\EntityManager;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class InvoiceServices
{
private Clients $clients;
private \DateTimeInterface $reportDate;
public function __construct(private EntityManager $entityManager, private HttpClientInterface $curl){}
/**
* @param Clients $clients
*/
public function setClients(Clients $clients): void
{
$this->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;
}
}