<?php
namespace App\Controller\Widget;
use App\Entity\FO\Cron;
use App\Entity\FO\TacheCron;
use App\Entity\GestionComerciale\Commande;
use App\Form\Clients\ClientType;
use App\Service\Articles\ArticleService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Process\Process;
use Symfony\Component\Routing\Annotation\Route;
class WidgetCumpController extends AbstractController
{
//lancerProcessCump
//git 2
/**
* @Route("/cump/{id}/pourcentage-traitement", name="dtc_calcul_cump_pourcentage_traitement")
*/
public function pourcentageTraitementAction(Request $request, Cron $cron, ArticleService $service)
{
$pourcentageTraitement = $service->pourcentageTraitementCalculCump($cron);
$response = new JsonResponse();
$response->setData([
'pourcentageTraitement' => $pourcentageTraitement,
]);
return $response;
}
/**
* @Route("", name="")
*/
public function widgetCumpAction(Request $request, $parametres = [], EntityManagerInterface $em)
{
$repo_commande = $em->getRepository(Commande::class);
$fin = new \Datetime();
$repo_cron = $em->getRepository(Cron::class);
$repo_tache_cron = $em->getRepository(TacheCron::class);
$tache = $repo_tache_cron->find(10);
$get = $request->query->all();
$derniersCron = $repo_cron->findBy(['tacheCron' => $tache], ['date' => 'DESC'], 1, 0);
//print_r($parametres);
$cron_lancer = false;
$cron_calcul_cump = false;
if (count($derniersCron) > 0) {
if (is_object($derniersCron[0]) && $derniersCron[0]->getDateFin() == null) {
$cron_calcul_cump = true;
} else {
}
}
if (array_key_exists('calculcump', $parametres) && $parametres["calculcump"] == "1") {
if ($cron_calcul_cump) {
/*
$this->addFlash(
'warning',
$translator->trans('Impossible de lancer le calcul du cump, un calcul est déja en cours')
);
*/
} else {
/*
$this->addFlash(
'notice',
$translator->trans('Demande de calcul de cump en cours')
);
*/
if (array_key_exists('tous', $parametres) && $parametres["tous"] == "1") {
$process = new Process(['php', 'bin/console', 'genererCpumpArticle', '0']);
} else {
$process = new Process(['php', 'bin/console', 'genererCpumpArticle']);
}
$process->setWorkingDirectory($this->getParameter('kernel.project_dir'));
$process->setOptions(['create_new_console' => true]);
$process->start();
$cron_calcul_cump = true;
$derniersCron = $repo_cron->findBy(['tacheCron' => $tache], ['date' => 'DESC'], 1, 0);
$cron_lancer = true;
}
//return $this->redirectToRoute('dtcfo_homepage',array());
}
return $this->render('Widget/Widget/cump.html.twig', [
"cron_calcul_cump" => $cron_calcul_cump,
"derniersCron" => $derniersCron,
"cron_lancer" => $cron_lancer,
]);
}
}