2026-01-16 14:32:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Controller\Dashboard;
|
|
|
|
|
|
2026-01-19 18:22:53 +01:00
|
|
|
use App\Entity\CustomerAddress;
|
2026-01-16 16:00:00 +01:00
|
|
|
use App\Entity\Devis;
|
2026-01-17 22:29:04 +01:00
|
|
|
use App\Entity\DevisLine;
|
2026-01-16 16:00:00 +01:00
|
|
|
use App\Form\NewDevisType;
|
2026-01-16 14:32:20 +01:00
|
|
|
use App\Logger\AppLogger;
|
|
|
|
|
use App\Repository\AccountRepository;
|
2026-01-19 18:22:53 +01:00
|
|
|
use App\Repository\CustomerAddressRepository;
|
2026-01-17 22:29:04 +01:00
|
|
|
use App\Repository\CustomerRepository;
|
2026-01-16 15:04:50 +01:00
|
|
|
use App\Repository\DevisRepository;
|
2026-01-19 17:56:57 +01:00
|
|
|
use App\Repository\ProductRepository;
|
2026-01-17 22:29:04 +01:00
|
|
|
use App\Service\Pdf\DevisPdfService;
|
2026-01-19 18:22:53 +01:00
|
|
|
use App\Service\Signature\Client;
|
2026-01-17 22:29:04 +01:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2026-01-16 15:04:50 +01:00
|
|
|
use Knp\Bundle\PaginatorBundle\KnpPaginatorBundle;
|
|
|
|
|
use Knp\Component\Pager\PaginatorInterface;
|
2026-01-16 14:32:20 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2026-01-19 18:22:53 +01:00
|
|
|
use Symfony\Component\HttpFoundation\File\File;
|
|
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
2026-01-16 15:04:50 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2026-01-16 14:32:20 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2026-01-17 22:29:04 +01:00
|
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
2026-01-16 14:32:20 +01:00
|
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
|
|
|
|
|
|
class DevisController extends AbstractController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Liste des administrateurs
|
|
|
|
|
*/
|
|
|
|
|
#[Route(path: '/crm/devis', name: 'app_crm_devis', options: ['sitemap' => false], methods: ['GET'])]
|
2026-01-19 18:22:53 +01:00
|
|
|
public function devis(Client $client,EntityManagerInterface $entityManager,KernelInterface $kernel,DevisRepository $devisRepository,AppLogger $appLogger,PaginatorInterface $paginator,Request $request): Response
|
2026-01-16 14:32:20 +01:00
|
|
|
{
|
|
|
|
|
$appLogger->record('VIEW', 'Consultation de la liste des devis');
|
|
|
|
|
return $this->render('dashboard/devis/list.twig',[
|
2026-01-16 15:04:50 +01:00
|
|
|
'quotes' => $paginator->paginate($devisRepository->findBy([],['createA'=>'asc']),$request->get('page', 1),20),
|
2026-01-16 14:32:20 +01:00
|
|
|
]);
|
|
|
|
|
}
|
2026-01-17 22:29:04 +01:00
|
|
|
#[Route(path: '/crm/devis/add', name: 'app_crm_devis_add', options: ['sitemap' => false], methods: ['GET','POST'])]
|
2026-01-19 18:22:53 +01:00
|
|
|
public function devisAdd(Client $client,KernelInterface $kernel,CustomerAddressRepository $customerAddress,ProductRepository $productRepository,EntityManagerInterface $entityManager,CustomerRepository $customerRepository,DevisRepository $devisRepository, AppLogger $appLogger,Request $request): Response
|
2026-01-16 15:04:50 +01:00
|
|
|
{
|
2026-01-16 16:00:00 +01:00
|
|
|
$devisNumber ="DEVIS-".sprintf('%05d',$devisRepository->count()+1);
|
|
|
|
|
$appLogger->record('VIEW', 'Consultation de la création d\'un devis');
|
2026-01-16 14:32:20 +01:00
|
|
|
|
2026-01-16 16:00:00 +01:00
|
|
|
$devis = new Devis();
|
|
|
|
|
$devis->setNum($devisNumber);
|
|
|
|
|
$devis->setState("draft");
|
|
|
|
|
$devis->setCreateA(new \DateTimeImmutable());
|
|
|
|
|
$devis->setUpdateAt(new \DateTimeImmutable());
|
|
|
|
|
|
|
|
|
|
$form = $this->createForm(NewDevisType::class,$devis);
|
2026-01-17 22:29:04 +01:00
|
|
|
if($request->isMethod('POST')){
|
2026-01-19 18:22:53 +01:00
|
|
|
$devis->setBillAddress($customerAddress->find($_POST['devis']['bill_address']));
|
|
|
|
|
$devis->setAddressShip($customerAddress->find($_POST['devis']['ship_address']));
|
2026-01-17 22:29:04 +01:00
|
|
|
$devis->setCustomer($customerRepository->find($_POST['new_devis']['customer']));
|
|
|
|
|
foreach ($_POST['lines'] as $cd=>$line) {
|
|
|
|
|
$rLine = new DevisLine();
|
|
|
|
|
$rLine->setDevi($devis);
|
|
|
|
|
$rLine->setPos($cd);
|
2026-01-19 17:56:57 +01:00
|
|
|
$rLine->setProduct($productRepository->find($line['product_id']));
|
|
|
|
|
$rLine->setDay($line['days']);
|
|
|
|
|
$rLine->setPriceHt(floatval($line['price_ht']));
|
|
|
|
|
$rLine->setPriceHtSup(floatval($line['price_sup_ht']));
|
|
|
|
|
$rLine->setStartAt(\DateTimeImmutable::createFromFormat('Y-m-d',$line['date_start']));
|
|
|
|
|
$rLine->setEndAt(\DateTimeImmutable::createFromFormat('Y-m-d',$line['date_end']));
|
2026-01-17 22:29:04 +01:00
|
|
|
$entityManager->persist($rLine);
|
|
|
|
|
}
|
|
|
|
|
$entityManager->persist($devis);
|
|
|
|
|
|
2026-01-19 18:22:53 +01:00
|
|
|
|
|
|
|
|
$docusealService = new DevisPdfService($kernel, $devis, true);
|
|
|
|
|
$contentDocuseal = $docusealService->generate();
|
|
|
|
|
|
|
|
|
|
$tmpPathDocuseal = sys_get_temp_dir() . '/docuseal_' . uniqid() . '.pdf';
|
|
|
|
|
file_put_contents($tmpPathDocuseal, $contentDocuseal);
|
|
|
|
|
|
|
|
|
|
$fileDocuseal = new UploadedFile($tmpPathDocuseal,'dc_'.$devis->getNum() . '.pdf','application/pdf',0,true);
|
|
|
|
|
$devis->setDevisDocuSealFile($fileDocuseal);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$devisService = new DevisPdfService($kernel, $devis, false);
|
|
|
|
|
$contentDevis = $devisService->generate();
|
|
|
|
|
|
|
|
|
|
$tmpPathDevis = sys_get_temp_dir() . '/devis_' . uniqid() . '.pdf';
|
|
|
|
|
file_put_contents($tmpPathDevis, $contentDevis);
|
|
|
|
|
|
|
|
|
|
$fileDevis = new UploadedFile($tmpPathDevis,'devis_'.$devis->getNum() . '.pdf','application/pdf',0,true);
|
|
|
|
|
$devis->setDevisFile($fileDevis);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$devis->setState("created_waitsign");
|
|
|
|
|
$devis->setUpdateAt(new \DateTimeImmutable());
|
|
|
|
|
$entityManager->flush();
|
|
|
|
|
$client->createSubmissionDevis($devis);
|
|
|
|
|
return $this->redirectToRoute('app_crm_devis');
|
2026-01-17 22:29:04 +01:00
|
|
|
}
|
2026-01-16 16:00:00 +01:00
|
|
|
return $this->render('dashboard/devis/add.twig',[
|
|
|
|
|
'form' => $form->createView(),
|
|
|
|
|
]);
|
2026-01-16 15:04:50 +01:00
|
|
|
}
|
2026-01-16 14:32:20 +01:00
|
|
|
|
|
|
|
|
}
|