✨ feat(search): Indexe les options et contrats, ajuste la durée du devis.
This commit is contained in:
@@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Account;
|
||||
use App\Entity\Contrats;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Options;
|
||||
use App\Entity\Product;
|
||||
use App\Service\Search\Client;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -74,6 +76,29 @@ class SearchCommand extends Command
|
||||
|
||||
$this->client->indexDocuments($datas, 'product');
|
||||
}
|
||||
$options = $this->entityManager->getRepository(Options::class)->findAll();
|
||||
|
||||
foreach ($options as $option) {
|
||||
|
||||
$datas = [
|
||||
'id' => $option->getId(),
|
||||
'name' => $option->getName(),
|
||||
];
|
||||
|
||||
$this->client->indexDocuments($datas, 'options');
|
||||
}
|
||||
|
||||
$options = $this->entityManager->getRepository(Contrats::class)->findAll();
|
||||
|
||||
foreach ($options as $option) {
|
||||
|
||||
$datas = [
|
||||
'id' => $option->getId(),
|
||||
'num' => $option->getNumReservation(),
|
||||
];
|
||||
|
||||
$this->client->indexDocuments($datas, 'contrat');
|
||||
}
|
||||
$output->writeln('Indexation terminée (hors ROOT).');
|
||||
|
||||
return Command::SUCCESS;
|
||||
|
||||
@@ -135,6 +135,9 @@ class DevisController extends AbstractController
|
||||
|
||||
$devis->setStartAt(new DateTimeImmutable($_POST['new_devis']['startAt']));
|
||||
$devis->setEndAt(new DateTimeImmutable($_POST['new_devis']['endAt']));
|
||||
|
||||
$interval = $devis->getStartAt()->diff($devis->getEndAt());
|
||||
$day = $interval->days;
|
||||
$devis->setBillAddress($customerAddress->find($_POST['devis']['bill_address']));
|
||||
$devis->setAddressShip($customerAddress->find($_POST['devis']['ship_address']));
|
||||
$devis->setCustomer($customerRepository->find($_POST['new_devis']['customer']));
|
||||
@@ -143,7 +146,7 @@ class DevisController extends AbstractController
|
||||
$rLine->setDevi($devis);
|
||||
$rLine->setPos($cd);
|
||||
$rLine->setProduct($productRepository->find($line['product_id']));
|
||||
$rLine->setDay($line['days']);
|
||||
$rLine->setDay($day);
|
||||
$rLine->setPriceHt(floatval($line['price_ht']));
|
||||
$rLine->setPriceHtSup(floatval($line['price_sup_ht']));
|
||||
$entityManager->persist($rLine);
|
||||
|
||||
@@ -8,7 +8,9 @@ use App\Entity\AccountResetPasswordRequest;
|
||||
use App\Form\RequestPasswordConfirmType;
|
||||
use App\Form\RequestPasswordRequestType;
|
||||
use App\Repository\AccountRepository;
|
||||
use App\Repository\ContratsRepository;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\OptionsRepository;
|
||||
use App\Repository\ProductRepository;
|
||||
use App\Service\ResetPassword\Event\ResetPasswordConfirmEvent;
|
||||
use App\Service\ResetPassword\Event\ResetPasswordEvent;
|
||||
@@ -31,6 +33,8 @@ class SearchController extends AbstractController
|
||||
AccountRepository $accountRepository,
|
||||
ProductRepository $productRepository,
|
||||
CustomerRepository $customerRepository,
|
||||
ContratsRepository $contratsRepository,
|
||||
OptionsRepository $optionsRepository,
|
||||
Client $client,
|
||||
Request $request
|
||||
): Response {
|
||||
@@ -41,6 +45,20 @@ class SearchController extends AbstractController
|
||||
$response = $client->searchGlobal($query, 20);
|
||||
|
||||
foreach ($response['results'] as $resultGroup) {
|
||||
if (str_contains($resultGroup['indexUid'], 'intranet_ludikevent_options')) {
|
||||
$ids = array_map(fn($h) => $h['id'], $resultGroup['hits']);
|
||||
$accounts = $optionsRepository->findBy(['id' => $ids]);
|
||||
foreach ($accounts as $account) {
|
||||
$unifiedResults[] = [
|
||||
'title' => $account->getName(),
|
||||
'subtitle' => '',
|
||||
'link' => $this->generateUrl('app_crm_product_options_edit', ['id' => $account->getId()]),
|
||||
'type' => 'Options',
|
||||
'id' => $account->getId(),
|
||||
'initials' => strtoupper(substr($account->getName(), 0, 2) )
|
||||
];
|
||||
}
|
||||
}
|
||||
if (str_contains($resultGroup['indexUid'], 'intranet_ludikevent_customer')) {
|
||||
// Extraction des IDs pour éviter les requêtes en boucle
|
||||
$ids = array_map(fn($h) => $h['id'], $resultGroup['hits']);
|
||||
@@ -57,6 +75,22 @@ class SearchController extends AbstractController
|
||||
];
|
||||
}
|
||||
}
|
||||
if (str_contains($resultGroup['indexUid'], 'intranet_ludikevent_contrat')) {
|
||||
// Extraction des IDs pour éviter les requêtes en boucle
|
||||
$ids = array_map(fn($h) => $h['id'], $resultGroup['hits']);
|
||||
$accounts = $contratsRepository->findBy(['id' => $ids]);
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$unifiedResults[] = [
|
||||
'title' => $account->getNumReservation(),
|
||||
'subtitle' => '',
|
||||
'link' => $this->generateUrl('app_crm_contrats_view', ['id' => $account->getId()]),
|
||||
'type' => 'Contrat de location',
|
||||
'id' => $account->getId(),
|
||||
'initials' => '',
|
||||
];
|
||||
}
|
||||
}
|
||||
// On vérifie si l'index correspond aux administrateurs
|
||||
if (str_contains($resultGroup['indexUid'], 'intranet_ludikevent_admin')) {
|
||||
|
||||
@@ -95,6 +129,7 @@ class SearchController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->render('dashboard/search.twig', [
|
||||
'results' => $unifiedResults,
|
||||
'query' => $query
|
||||
|
||||
@@ -31,6 +31,8 @@ class Client
|
||||
"intranet_ludikevent_admin" => [],
|
||||
"intranet_ludikevent_customer" => [],
|
||||
"intranet_ludikevent_product" => [],
|
||||
"intranet_ludikevent_options" => [],
|
||||
"intranet_ludikevent_contrat" => [],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@@ -125,20 +125,14 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{# 2. DURÉE #}
|
||||
<div class="lg:col-span-2">
|
||||
<label class="{{ label_class }}">Jours</label>
|
||||
<input type="number" name="lines[{{ key }}][days]" min="1" placeholder="1" class="{{ input_class }} [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none" required value="{{ line.days }}" />
|
||||
</div>
|
||||
|
||||
{# 3. PRIX HT J1 #}
|
||||
<div class="lg:col-span-2">
|
||||
<div class="lg:col-span-3">
|
||||
<label class="{{ label_class }}">HT J1 (€)</label>
|
||||
<input type="number" step="0.01" name="lines[{{ key }}][price_ht]" placeholder="0.00" class="{{ input_class }} text-right font-mono" required value="{{ line.price_ht }}" />
|
||||
</div>
|
||||
|
||||
{# 4. PRIX HT SUP #}
|
||||
<div class="lg:col-span-2">
|
||||
<div class="lg:col-span-3">
|
||||
<label class="{{ label_class }}">HT Sup</label>
|
||||
<input type="number" step="0.01" name="lines[{{ key }}][price_sup_ht]" placeholder="0.00" class="{{ input_class }} text-right font-mono" required value="{{ line.price_sup_ht }}" />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user