```
✨ feat(ReserverController): Génère un devis PDF provisoire basé sur la session. 🎨 style(flow_confirmed.twig): Ajoute un lien pour télécharger le devis provisoire. ```
This commit is contained in:
@@ -24,11 +24,15 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use App\Service\Pdf\DevisPdfService;
|
||||
use App\Entity\Devis;
|
||||
use App\Entity\DevisLine;
|
||||
use App\Entity\CustomerAddress;
|
||||
|
||||
class ReserverController extends AbstractController
|
||||
{
|
||||
@@ -40,6 +44,88 @@ class ReserverController extends AbstractController
|
||||
$this->kernel = $kernel;
|
||||
}
|
||||
|
||||
#[Route('/flow/{sessionId}/devis', name: 'reservation_generate_devis', methods: ['GET'])]
|
||||
public function generateDevis(
|
||||
string $sessionId,
|
||||
OrderSessionRepository $repository,
|
||||
ProductRepository $productRepository,
|
||||
KernelInterface $kernel
|
||||
): Response {
|
||||
$session = $repository->findOneBy(['uuid' => $sessionId]);
|
||||
if (!$session) {
|
||||
return $this->redirectToRoute('reservation');
|
||||
}
|
||||
|
||||
$sessionData = $session->getProducts();
|
||||
$ids = $sessionData['ids'] ?? [];
|
||||
$startStr = $sessionData['start'] ?? null;
|
||||
$endStr = $sessionData['end'] ?? null;
|
||||
|
||||
// Calcul de la durée
|
||||
$duration = 1;
|
||||
$start = null;
|
||||
$end = null;
|
||||
if ($startStr && $endStr) {
|
||||
try {
|
||||
$start = new \DateTimeImmutable($startStr);
|
||||
$end = new \DateTimeImmutable($endStr);
|
||||
if ($end >= $start) {
|
||||
$duration = $start->diff($end)->days + 1;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$duration = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Création des objets temporaires pour le PDF
|
||||
$customer = new Customer();
|
||||
$customer->setName($session->getCustomer() ? $session->getCustomer()->getName() : 'Client');
|
||||
$customer->setSurname($session->getCustomer() ? $session->getCustomer()->getSurname() : 'Temporaire');
|
||||
$customer->setEmail($session->getCustomer() ? $session->getCustomer()->getEmail() : '');
|
||||
$customer->setPhone($session->getCustomer() ? $session->getCustomer()->getPhone() : '');
|
||||
|
||||
// Adresse de facturation
|
||||
$billAddress = new CustomerAddress();
|
||||
$billAddress->setAddress($session->getBillingAddress() ?? '');
|
||||
$billAddress->setZipcode($session->getBillingZipCode() ?? '');
|
||||
$billAddress->setCity($session->getBillingTown() ?? '');
|
||||
|
||||
// Adresse de prestation
|
||||
$shipAddress = new CustomerAddress();
|
||||
$shipAddress->setAddress($session->getAdressEvent() ?? '');
|
||||
$shipAddress->setAddress2($session->getAdress2Event() ?? '');
|
||||
$shipAddress->setZipcode($session->getZipCodeEvent() ?? '');
|
||||
$shipAddress->setCity($session->getTownEvent() ?? '');
|
||||
|
||||
$devis = new Devis();
|
||||
$devis->setCustomer($customer);
|
||||
$devis->setBillAddress($billAddress);
|
||||
$devis->setAddressShip($shipAddress);
|
||||
$devis->setNum('PROVISOIRE');
|
||||
$devis->setStartAt($start);
|
||||
$devis->setEndAt($end);
|
||||
|
||||
if (!empty($ids)) {
|
||||
$products = $productRepository->findBy(['id' => $ids]);
|
||||
foreach ($products as $product) {
|
||||
$line = new DevisLine();
|
||||
$line->setProduct($product->getName());
|
||||
$line->setPriceHt($product->getPriceDay());
|
||||
$line->setPriceHtSup($product->getPriceSup());
|
||||
$line->setDay($duration);
|
||||
$devis->addDevisLine($line);
|
||||
}
|
||||
}
|
||||
|
||||
$pdfService = new DevisPdfService($kernel, $devis, $productRepository);
|
||||
$content = $pdfService->generate();
|
||||
|
||||
return new Response($content, 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'attachment; filename="devis_provisoire.pdf"'
|
||||
]);
|
||||
}
|
||||
|
||||
private function loadSimplifiedCommunes(): array
|
||||
{
|
||||
if ($this->simplifiedCommunes !== null) {
|
||||
|
||||
Reference in New Issue
Block a user