test invoices
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user