<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Doctrine\ORM\Tools\Pagination\Paginator;
use App\Events;
use App\Entity\User;
use App\Entity\Note;
use App\Entity\ModeleBlanks;
use App\Entity\Resin;
use App\Entity\Fins;
use App\Entity\Fibre;
use App\Entity\Logo;
use App\Entity\Plug;
use App\Entity\FabricationPlanche;
use App\Entity\Commande;
use App\Entity\Planche;
use App\Repository\UserRepository;
use Symfony\Component\Security\Core\Security;
class DashboardController extends Controller
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
/**
* @Route("/online", name="homepage")
* Accueil Dashboard
*/
public function index()
{
$user = $this->security->getUser();
$role = $user->getRoles();
$brandsid = $user->getBrandsid();
$royalties = $user->getRoyalties();
//dump($brandsid);
if ($role[0] == "ROLE_ADMIN" && $brandsid == "0") {
$em = $this->getDoctrine()->getManager();
$statut = 'inProgress';
// Affichage des commandes en attente
$order = $em
->getRepository(FabricationPlanche::Class)
->findByStatut($statut);
// Mise a jour des statuts SANS ORDER STATUS et un PRODUCT STATUS Finished
// Affichage notes par demande d'achats
$note = $em
->getRepository(Note::Class)
->findBy(array('type' => 'DemandeAchat'));
// Affichage des commandes en attente
$day_one = new \DateTime;
$res_day_one = $day_one->format('Y-m-d');
$jour_ = date("l", strtotime("now"));
// LAMINATION
$Date_lundi_lamination = date("Y-m-d", strtotime("Monday this week"));
$Date_mardi_lamination = date("Y-m-d", strtotime("tuesday this week"));
$Date_mercredi_lamination = date("Y-m-d", strtotime("wednesday this week"));
$Date_jeudi_lamination = date("Y-m-d", strtotime("thursday this week"));
$Date_vendredi_lamination = date("Y-m-d", strtotime("friday this week"));
// SHAPE
$Date_lundi_shape = date("Y-m-d", strtotime("Monday next week"));
$Date_mardi_shape = date("Y-m-d", strtotime("tuesday next week"));
$Date_mercredi_shape = date("Y-m-d", strtotime("wednesday next week"));
$Date_jeudi_shape = date("Y-m-d", strtotime("thursday next week"));
$Date_vendredi_shape = date("Y-m-d", strtotime("friday next week"));
$Date_late = date("Y-m-d", strtotime("friday last week"));
$lundi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_lundi_lamination);
$mardi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_mardi_lamination);
$mercredi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_mercredi_lamination);
$jeudi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_jeudi_lamination);
$vendredi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_vendredi_lamination);
$lundi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_lundi_shape);
$mardi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_mardi_shape);
$mercredi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_mercredi_shape);
$jeudi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_jeudi_shape);
$vendredi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_vendredi_shape);
$late = $em
->getRepository(FabricationPlanche::Class)
->findDayLate($Date_late);
$modelsBlanks = $em
->getRepository(ModeleBlanks::Class)
->findStock();
$resin = $em
->getRepository(Resin::Class)
->findStock();
$fins = $em
->getRepository(Fins::Class)
->findStock();
$fibre = $em
->getRepository(Fibre::Class)
->findStock();
$logo = $em
->getRepository(Logo::Class)
->findStock();
$plug = $em
->getRepository(Plug::Class)
->findStock();
/*------------------------ STATS DES PLANCHES PAR THOMAS ---------*/
$statDay = $em
->getRepository(FabricationPlanche::Class)
->findNumDayPlanning();
$statWeek = $em
->getRepository(FabricationPlanche::Class)
->findNumWeekPlanning();
$statMonth = $em
->getRepository(FabricationPlanche::Class)
->findNumMonthPlanning();
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DE PLANCHE EN COMMANDE
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 1 YEAR AND NOW())
AND `status_fabrication` = 'inProgress'
AND `etat_avancement` = 'waiting'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardYearOrder = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DANS LES TUYAUX
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 4 YEAR AND NOW())
AND `status_fabrication` = 'InProgress' ";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardinProduct = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DANS LES TUYAUX Draft
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 2 YEAR AND NOW())
AND `etat_avancement` = 'Draft'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardinDraft = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DANS LES TUYAUX Standby
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 4 YEAR AND NOW())
AND `etat_avancement` = 'Standby'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardinStandby = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DANS LES TUYAUX Cave
$sql = "SELECT COUNT(etat_avancement) AS 'NUMBERS_BOARDS'
FROM `V_stats`
WHERE (date_maj BETWEEN NOW() - INTERVAL 2 YEAR AND NOW())
AND `etat_avancement` = 'cave'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardinCave = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DE PLANCHE DEPUIS LE DEBUT DE L'ANNEE
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE YEAR( `date_maj`) = YEAR(NOW())
AND `status_fabrication` LIKE '%ed'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardYearLeft = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DE PLANCHE PAR MOIS DEPUIS 3 ANS
/*$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS',
EXTRACT(YEAR_MONTH FROM `date_maj`) AS 'DATES'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 2 YEAR AND NOW())
AND `status_fabrication` LIKE '%ed'
GROUP BY DATES";*/
/* $sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS',
EXTRACT(YEAR_MONTH FROM `date_maj`) AS 'DATES'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN '2021-01-01' AND '2024-12-31')
AND `status_fabrication` LIKE '%ed'
GROUP BY DATES";*/
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS',
EXTRACT(YEAR_MONTH FROM `date_maj`) AS 'DATES' FROM `fabrication_planche`
WHERE (date_maj BETWEEN CONCAT(YEAR(CURDATE()) - 2, '-01-01') AND CONCAT(YEAR(CURDATE()), '-12-31'))
AND `status_fabrication` LIKE 'finished'
GROUP BY DATES";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
//
// dump($result);
//
// exit;
// CONTROLE SI IL Y A UN CHIFFRE ET SI EXISTE
for ($z = 0; $z < 36; $z++) {
if (!isset($result[$z]['NUMBERS_BOARDS'])) {
$result[$z]['NUMBERS_BOARDS'] = "0";
}
if ($result[$z]['NUMBERS_BOARDS'] == "") {
$result[$z]['NUMBERS_BOARDS'] = "0";
}
}
$statYear = "
{ year: 'Jan', value1: " . $result[0]['NUMBERS_BOARDS'] . ", value2: " . $result[12]['NUMBERS_BOARDS'] . ", value3: " . $result[24]['NUMBERS_BOARDS'] . " },
{ year: 'Feb', value1: " . $result[1]['NUMBERS_BOARDS'] . ", value2: " . $result[13]['NUMBERS_BOARDS'] . ", value3: " . $result[25]['NUMBERS_BOARDS'] . " },
{ year: 'Mar', value1: " . $result[2]['NUMBERS_BOARDS'] . ", value2: " . $result[14]['NUMBERS_BOARDS'] . ", value3: " . $result[26]['NUMBERS_BOARDS'] . " },
{ year: 'Apr', value1: " . $result[3]['NUMBERS_BOARDS'] . ", value2: " . $result[15]['NUMBERS_BOARDS'] . ", value3: " . $result[27]['NUMBERS_BOARDS'] . " },
{ year: 'May', value1: " . $result[4]['NUMBERS_BOARDS'] . ", value2: " . $result[16]['NUMBERS_BOARDS'] . ", value3: " . $result[28]['NUMBERS_BOARDS'] . " },
{ year: 'Jun', value1: " . $result[5]['NUMBERS_BOARDS'] . ", value2: " . $result[17]['NUMBERS_BOARDS'] . ", value3: " . $result[29]['NUMBERS_BOARDS'] . " },
{ year: 'Jul', value1: " . $result[6]['NUMBERS_BOARDS'] . ", value2: " . $result[18]['NUMBERS_BOARDS'] . ", value3: " . $result[30]['NUMBERS_BOARDS'] . " },
{ year: 'Aug', value1: " . $result[7]['NUMBERS_BOARDS'] . ", value2: " . $result[19]['NUMBERS_BOARDS'] . ", value3: " . $result[31]['NUMBERS_BOARDS'] . " },
{ year: 'Sep', value1: " . $result[8]['NUMBERS_BOARDS'] . ", value2: " . $result[20]['NUMBERS_BOARDS'] . ", value3: " . $result[32]['NUMBERS_BOARDS'] . " },
{ year: 'Oct', value1: " . $result[9]['NUMBERS_BOARDS'] . ", value2: " . $result[21]['NUMBERS_BOARDS'] . ", value3: " . $result[32]['NUMBERS_BOARDS'] . " },
{ year: 'Nov', value1: " . $result[10]['NUMBERS_BOARDS'] . ", value2: " . $result[22]['NUMBERS_BOARDS'] . ", value3: " . $result[34]['NUMBERS_BOARDS'] . " },
{ year: 'Dec', value1: " . $result[11]['NUMBERS_BOARDS'] . ", value2: " . $result[23]['NUMBERS_BOARDS'] . ", value3: " . $result[35]['NUMBERS_BOARDS'] . " }";
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DE PLANCHE FINIES DANS LA SEMAINE
$sql = "SELECT COUNT('id') AS 'NUMBERS_BOARDS',
DAYNAME(date_maj) AS 'DAYS'
FROM `V_stats`
WHERE WEEK(date_maj) = WEEK(NOW())
AND YEAR(date_maj) = YEAR(NOW())
AND `status_fabrication` LIKE '%ed'
GROUP BY DAYOFWEEK(date_maj)";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
// CONTROLE SI IL Y A UN CHIFFRE ET SI EXISTE
for ($z = 0; $z < 36; $z++) {
if (!isset($result[$z]['NUMBERS_BOARDS'])) {
$result[$z]['NUMBERS_BOARDS'] = "0";
}
if ($result[$z]['NUMBERS_BOARDS'] == "") {
$result[$z]['NUMBERS_BOARDS'] = "0";
}
}
$statDayWeek = "
{ day: 'Monday', value1: " . $result[0]['NUMBERS_BOARDS'] . ", value2: " . $result[12]['NUMBERS_BOARDS'] . ", value3: " . $result[24]['NUMBERS_BOARDS'] . " },
{ day: 'Tuesday', value1: " . $result[1]['NUMBERS_BOARDS'] . ", value2: " . $result[13]['NUMBERS_BOARDS'] . ", value3: " . $result[25]['NUMBERS_BOARDS'] . " },
{ day: 'Wednesday', value1: " . $result[2]['NUMBERS_BOARDS'] . ", value2: " . $result[14]['NUMBERS_BOARDS'] . ", value3: " . $result[26]['NUMBERS_BOARDS'] . " },
{ day: 'Thursday', value1: " . $result[3]['NUMBERS_BOARDS'] . ", value2: " . $result[15]['NUMBERS_BOARDS'] . ", value3: " . $result[27]['NUMBERS_BOARDS'] . " },
{ day: 'Friday', value1: " . $result[4]['NUMBERS_BOARDS'] . ", value2: " . $result[16]['NUMBERS_BOARDS'] . ", value3: " . $result[28]['NUMBERS_BOARDS'] . " },
{ day: 'Saturday', value1: " . $result[5]['NUMBERS_BOARDS'] . ", value2: " . $result[17]['NUMBERS_BOARDS'] . ", value3: " . $result[29]['NUMBERS_BOARDS'] . " },
{ day: 'Sunday', value1: " . $result[6]['NUMBERS_BOARDS'] . ", value2: " . $result[18]['NUMBERS_BOARDS'] . ", value3: " . $result[30]['NUMBERS_BOARDS'] . " }";
/*------------------------ FIN STATS DES PLANCHES ---------*/
return $this->render('newdashboard.html.twig', array('order' => $order, 'note' => $note, 'modelsBlanks' => $modelsBlanks, 'resin' => $resin, 'fins' => $fins, 'fibre' => $fibre, 'logo' => $logo, 'plug' => $plug,
'lundi' => $lundi_lam, 'mardi' => $mardi_lam, 'mercredi' => $mercredi_lam, 'jeudi' => $jeudi_lam, 'vendredi' => $vendredi_lam,
'lundiShape' => $lundi_shape, 'mardiShape' => $mardi_shape, 'mercrediShape' => $mercredi_shape, 'jeudiShape' => $jeudi_shape, 'vendrediShape' => $vendredi_shape,
'jour' => $jour_, 'late' => $late,
'statDay' => $statDay,
'statWeek' => $statWeek,
'statMonth' => $statMonth,
'statBoardinProduct' => $statBoardinProduct,
'statBoardinDraft' => $statBoardinDraft,
'statBoardinCave' => $statBoardinCave,
'statBoardinStandby' => $statBoardinStandby,
'statBoardYearOrder' => $statBoardYearOrder,
'statBoardYearLeft' => $statBoardYearLeft,
'statYear' => $statYear,
'statDayWeek' => $statDayWeek,
'brandsid' => $brandsid
));
} elseif ($brandsid != "0") {
$em = $this->getDoctrine()->getManager();
$bid = $em
->getRepository(\App\Entity\Marque::Class)
->findOneBy(['nom' => $brandsid]);
$statut = 'inProgress';
// Affichage des commandes en attente
$order = $em
->getRepository(FabricationPlanche::Class)
->findByStatut($statut);
// exit;
// Mise a jour des statuts SANS ORDER STATUS et un PRODUCT STATUS Finished
// Affichage notes par demande d'achats
$note = $em
->getRepository(Note::Class)
->findBy(array('type' => 'DemandeAchat'));
// Affichage des commandes en attente
$day_one = new \DateTime;
$res_day_one = $day_one->format('Y-m-d');
$jour_ = date("l", strtotime("now"));
// LAMINATION
$Date_lundi_lamination = date("Y-m-d", strtotime("Monday this week"));
$Date_mardi_lamination = date("Y-m-d", strtotime("tuesday this week"));
$Date_mercredi_lamination = date("Y-m-d", strtotime("wednesday this week"));
$Date_jeudi_lamination = date("Y-m-d", strtotime("thursday this week"));
$Date_vendredi_lamination = date("Y-m-d", strtotime("friday this week"));
// SHAPE
$Date_lundi_shape = date("Y-m-d", strtotime("Monday next week"));
$Date_mardi_shape = date("Y-m-d", strtotime("tuesday next week"));
$Date_mercredi_shape = date("Y-m-d", strtotime("wednesday next week"));
$Date_jeudi_shape = date("Y-m-d", strtotime("thursday next week"));
$Date_vendredi_shape = date("Y-m-d", strtotime("friday next week"));
$Date_late = date("Y-m-d", strtotime("friday last week"));
$lundi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_lundi_lamination);
$mardi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_mardi_lamination);
$mercredi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_mercredi_lamination);
$jeudi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_jeudi_lamination);
$vendredi_lam = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_vendredi_lamination);
$lundi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_lundi_shape);
$mardi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_mardi_shape);
$mercredi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_mercredi_shape);
$jeudi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_jeudi_shape);
$vendredi_shape = $em
->getRepository(FabricationPlanche::Class)
->findDay($Date_vendredi_shape);
$late = $em
->getRepository(FabricationPlanche::Class)
->findDayLate($Date_late);
$modelsBlanks = $em
->getRepository(ModeleBlanks::Class)
->findStock();
$resin = $em
->getRepository(Resin::Class)
->findStock();
$fins = $em
->getRepository(Fins::Class)
->findStock();
$fibre = $em
->getRepository(Fibre::Class)
->findStock();
$logo = $em
->getRepository(Logo::Class)
->findStock();
$plug = $em
->getRepository(Plug::Class)
->findStock();
/*------------------------ STATS DES PLANCHES PAR THOMAS ---------*/
$statDay = $em
->getRepository(FabricationPlanche::Class)
->findNumDayPlanning();
$statWeek = $em
->getRepository(FabricationPlanche::Class)
->findNumWeekPlanning();
$statMonth = $em
->getRepository(FabricationPlanche::Class)
->findNumMonthPlanning();
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DE PLANCHE EN COMMANDE
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 1 YEAR AND NOW())
AND `status_fabrication` = 'inProgress'
AND `etat_avancement` = 'waiting'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardYearOrder = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DANS LES TUYAUX
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 2 YEAR AND NOW())
AND `status_fabrication` = 'InProgress'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardinProduct = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DANS LES TUYAUX Draft
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 2 YEAR AND NOW())
AND `etat_avancement` = 'Draft'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardinDraft = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DANS LES TUYAUX Standby
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 2 YEAR AND NOW())
AND `etat_avancement` = 'Standby'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardinStandby = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DE PLANCHE DEPUIS LE DEBUT DE L'ANNEE
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS'
FROM `fabrication_planche`
WHERE YEAR( `date_maj`) = YEAR(NOW())
AND `status_fabrication` LIKE '%ed'";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$statBoardYearLeft = $result[0]['NUMBERS_BOARDS'];
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DE PLANCHE PAR MOIS DEPUIS 3 ANS
/*$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS',
EXTRACT(YEAR_MONTH FROM `date_maj`) AS 'DATES'
FROM `fabrication_planche`
WHERE (date_maj BETWEEN NOW() - INTERVAL 2 YEAR AND NOW())
AND `status_fabrication` LIKE '%ed'
GROUP BY DATES";*/
//
// $sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS',
// EXTRACT(YEAR_MONTH FROM `date_maj`) AS 'DATES'
// FROM `fabrication_planche`
// WHERE (date_maj BETWEEN '2018-01-01' AND '2020-12-31')
// AND `status_fabrication` LIKE '%ed'
// GROUP BY DATES";
$brid = $bid->getId();
//
$sql = "SELECT COUNT(fabrication_planche.id) AS 'NUMBERS_BOARDS',
EXTRACT(YEAR_MONTH FROM `date_maj`) AS 'DATES' FROM fabrication_planche
JOIN planche ON planche.id = fabrication_planche.planche_id
JOIN modele ON modele.id = planche.modele_id
JOIN marque ON marque.id = modele.marque_id
Where marque_id = '$brid'
AND (date_maj BETWEEN '2019-01-01' AND '2028-12-31') AND `status_fabrication` LIKE '%ed' GROUP BY DATES";
//
// dump($sql);
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
// dd($result);
// $sDay = $em
// ->getRepository(FabricationPlanche::Class)
// ->findNumDayPlanning();
//
//
// dump($sDay);
//
// exit;
// CONTROLE SI IL Y A UN CHIFFRE ET SI EXISTE
for ($z = 0; $z < 36; $z++) {
if (!isset($result[$z]['NUMBERS_BOARDS'])) {
$result[$z]['NUMBERS_BOARDS'] = "0";
}
if ($result[$z]['NUMBERS_BOARDS'] == "") {
$result[$z]['NUMBERS_BOARDS'] = "0";
}
}
$statYear = "
{ year: 'Jan', value1: " . $result[0]['NUMBERS_BOARDS'] . ", value2: " . $result[12]['NUMBERS_BOARDS'] . ", value3: " . $result[24]['NUMBERS_BOARDS'] . " },
{ year: 'Feb', value1: " . $result[1]['NUMBERS_BOARDS'] . ", value2: " . $result[13]['NUMBERS_BOARDS'] . ", value3: " . $result[25]['NUMBERS_BOARDS'] . " },
{ year: 'Mar', value1: " . $result[2]['NUMBERS_BOARDS'] . ", value2: " . $result[14]['NUMBERS_BOARDS'] . ", value3: " . $result[26]['NUMBERS_BOARDS'] . " },
{ year: 'Apr', value1: " . $result[3]['NUMBERS_BOARDS'] . ", value2: " . $result[15]['NUMBERS_BOARDS'] . ", value3: " . $result[27]['NUMBERS_BOARDS'] . " },
{ year: 'May', value1: " . $result[4]['NUMBERS_BOARDS'] . ", value2: " . $result[16]['NUMBERS_BOARDS'] . ", value3: " . $result[28]['NUMBERS_BOARDS'] . " },
{ year: 'Jun', value1: " . $result[5]['NUMBERS_BOARDS'] . ", value2: " . $result[17]['NUMBERS_BOARDS'] . ", value3: " . $result[29]['NUMBERS_BOARDS'] . " },
{ year: 'Jul', value1: " . $result[6]['NUMBERS_BOARDS'] . ", value2: " . $result[18]['NUMBERS_BOARDS'] . ", value3: " . $result[30]['NUMBERS_BOARDS'] . " },
{ year: 'Aug', value1: " . $result[7]['NUMBERS_BOARDS'] . ", value2: " . $result[19]['NUMBERS_BOARDS'] . ", value3: " . $result[31]['NUMBERS_BOARDS'] . " },
{ year: 'Sep', value1: " . $result[8]['NUMBERS_BOARDS'] . ", value2: " . $result[20]['NUMBERS_BOARDS'] . ", value3: " . $result[32]['NUMBERS_BOARDS'] . " },
{ year: 'Oct', value1: " . $result[9]['NUMBERS_BOARDS'] . ", value2: " . $result[21]['NUMBERS_BOARDS'] . ", value3: " . $result[32]['NUMBERS_BOARDS'] . " },
{ year: 'Nov', value1: " . $result[10]['NUMBERS_BOARDS'] . ", value2: " . $result[22]['NUMBERS_BOARDS'] . ", value3: " . $result[34]['NUMBERS_BOARDS'] . " },
{ year: 'Dec', value1: " . $result[11]['NUMBERS_BOARDS'] . ", value2: " . $result[23]['NUMBERS_BOARDS'] . ", value3: " . $result[35]['NUMBERS_BOARDS'] . " }";
//-----------------------------------------------------------------------
//-------------------------- NOMBRE DE PLANCHE FINIES DANS LA SEMAINE
$sql = "SELECT COUNT('id') AS 'NUMBERS_BOARDS',
DAYNAME(date_maj) AS 'DAYS'
FROM `V_stats`
WHERE WEEK(date_maj) = WEEK(NOW())
AND YEAR(date_maj) = YEAR(NOW())
AND `status_fabrication` LIKE '%ed'
GROUP BY DAYOFWEEK(date_maj)";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
// CONTROLE SI IL Y A UN CHIFFRE ET SI EXISTE
for ($z = 0; $z < 36; $z++) {
if (!isset($result[$z]['NUMBERS_BOARDS'])) {
$result[$z]['NUMBERS_BOARDS'] = "0";
}
if ($result[$z]['NUMBERS_BOARDS'] == "") {
$result[$z]['NUMBERS_BOARDS'] = "0";
}
}
$statDayWeek = "
{ day: 'Monday', value1: " . $result[0]['NUMBERS_BOARDS'] . ", value2: " . $result[12]['NUMBERS_BOARDS'] . ", value3: " . $result[24]['NUMBERS_BOARDS'] . " },
{ day: 'Tuesday', value1: " . $result[1]['NUMBERS_BOARDS'] . ", value2: " . $result[13]['NUMBERS_BOARDS'] . ", value3: " . $result[25]['NUMBERS_BOARDS'] . " },
{ day: 'Wednesday', value1: " . $result[2]['NUMBERS_BOARDS'] . ", value2: " . $result[14]['NUMBERS_BOARDS'] . ", value3: " . $result[26]['NUMBERS_BOARDS'] . " },
{ day: 'Thursday', value1: " . $result[3]['NUMBERS_BOARDS'] . ", value2: " . $result[15]['NUMBERS_BOARDS'] . ", value3: " . $result[27]['NUMBERS_BOARDS'] . " },
{ day: 'Friday', value1: " . $result[4]['NUMBERS_BOARDS'] . ", value2: " . $result[16]['NUMBERS_BOARDS'] . ", value3: " . $result[28]['NUMBERS_BOARDS'] . " },
{ day: 'Saturday', value1: " . $result[5]['NUMBERS_BOARDS'] . ", value2: " . $result[17]['NUMBERS_BOARDS'] . ", value3: " . $result[29]['NUMBERS_BOARDS'] . " },
{ day: 'Sunday', value1: " . $result[6]['NUMBERS_BOARDS'] . ", value2: " . $result[18]['NUMBERS_BOARDS'] . ", value3: " . $result[30]['NUMBERS_BOARDS'] . " }";
/*------------------------ FIN STATS DES PLANCHES ---------*/
return $this->render('newdashboardforbrand.html.twig', array('order' => $order, 'note' => $note, 'modelsBlanks' => $modelsBlanks, 'resin' => $resin, 'fins' => $fins, 'fibre' => $fibre, 'logo' => $logo, 'plug' => $plug,
'lundi' => $lundi_lam, 'mardi' => $mardi_lam, 'mercredi' => $mercredi_lam, 'jeudi' => $jeudi_lam, 'vendredi' => $vendredi_lam,
'lundiShape' => $lundi_shape, 'mardiShape' => $mardi_shape, 'mercrediShape' => $mercredi_shape, 'jeudiShape' => $jeudi_shape, 'vendrediShape' => $vendredi_shape,
'jour' => $jour_, 'late' => $late,
'statDay' => $statDay,
'statWeek' => $statWeek,
'statMonth' => $statMonth,
'statBoardinProduct' => $statBoardinProduct,
'statBoardinDraft' => $statBoardinDraft,
'statBoardinStandby' => $statBoardinStandby,
'statBoardYearOrder' => $statBoardYearOrder,
'statBoardYearLeft' => $statBoardYearLeft,
'statYear' => $statYear,
'statDayWeek' => $statDayWeek,
'brandsid' => $brandsid,
'royalties' => $royalties
));
} else {
return $this->redirectToRoute('homepage_customer');
}
}
/**
* @Route("online/pass", name="change_pass")
* Change Pass
*/
public function change_pass(Request $request, UserPasswordEncoderInterface $passwordEncoder, EventDispatcherInterface $eventDispatcher)
{
// Récupération de l'entité user dans le formulaire
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository(User::class)->find($this->getUser()->getId());
// Création d'un formulaire
$form = $this->createFormBuilder($user)
->add('password', RepeatedType::class, array(
'type' => PasswordType::class,
'invalid_message' => 'The password fields must match.',
'options' => array('attr' => array('class' => 'password-field')),
'required' => true,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
))
->getForm();
// Formulaire soumis à validation
$form->handleRequest($request);
// Apres validation du formulaire - redirection effectuée
if ($form->isSubmitted() && $form->isValid()) {
$em->flush();
//On déclenche l'event message
$event = new GenericEvent($user);
$eventDispatcher->dispatch(Events::USER_REGISTERED, $event);
// On enregistre cette fois-ci le mdp hashé
$password = $passwordEncoder->encodePassword($user, $user->getPassword());
$user->setPassword($password);
// Enregistrement dans la bdd
$em->flush();
//echo "<script>alert(\"The password has been changed\")</script>";
// Redirection vers la page admin
return $this->redirectToRoute('logout');
}
return $this->render('pass.html.twig', array('form' => $form->createView()));
}
/**
* @Route("/admin", name="admin_redirect")
* Redirection url
*/
public function admin_redirect()
{
return $this->redirectToRoute('admin');
}
/**
* @Route("/admin/voir/{page}", name="admin")
* Accueil AdminDashboard
*/
public function admin(Request $request, $page = 1, $max_results = 10)
{
// Formulaire de requetage
$search = NULL;
$formulaire = $this->createFormBuilder()
->add('search', TextType::class, array('attr' => array('placeholder' => 'Fullname')))
->add('send', SubmitType::class, array('label' => 'Search'))
->getForm();
$formulaire->handleRequest($request);
// Apres validation du formulaire - redirection effectuée
if ($formulaire->isSubmitted() && $formulaire->isValid()) {
$search = $formulaire['search']->getData();
return $this->redirectToRoute('admin_search', array('search' => $search));
}
// Recherche de tous les utilisateurs
$users = $this->getDoctrine()
->getRepository(User::Class)
->findAll_($page, $max_results);
// Pagination
$pg = array(
'page' => $page,
'route' => 'admin',
'pages_count' => ceil(count($users) / $max_results),
'route_params' => array()
);
// Passage en parametre TWIG des variables ('tableau des utilisateurs, pagination, formulaire et également du mode recherche inactive')
return $this->render('Admin/admin.html.twig', array('users' => $users, 'pg' => $pg, 'formulaire' => $formulaire->createView(), 'mode' => false));
}
/**
* @Route("/admin/req", name="admin_search_redirect")
*/
public function admin_search_redirect()
{
// Si l'utilisateur rentre req sans rien derrière dans l'URL, redirection vers la page admin accueil
return $this->redirectToRoute('admin');
}
/**
* @Route("/admin/req/{search}", name="admin_search")
*/
public function admin_search(Request $request, $search)
{
// Initialisation tableau user vide -
$users = array();
$repository = $this->getDoctrine()
->getManager()
->getRepository(User::Class);
// Requete recherche en fonction du nom - résultat
$user = $repository->findByFullname($search);
// Si on ne trouve pas de résultat, on retourne rien
if (null !== $user)
$users = $user;
// Formulaire de requetage
$search = NULL;
$formulaire = $this->createFormBuilder()
->add('search', TextType::class, array('attr' => array('placeholder' => 'Fullname')))
->add('send', SubmitType::class, array('label' => 'Search'))
->getForm();
$formulaire->handleRequest($request);
// Apres validation du formulaire - redirection effectuée sur la même page
if ($formulaire->isSubmitted() && $formulaire->isValid()) {
$search = $formulaire['search']->getData();
return $this->redirectToRoute('admin_search', array('search' => $search));
}
// Passage en parametre TWIG des variables ('tableau des utilisateurs, pagination, formulaire et également du mode recherche active')
return $this->render('Admin/admin.html.twig', array('users' => $users, 'pg' => '1', 'formulaire' => $formulaire->createView(), 'mode' => true));
}
/**
* @Route("/online/step/tab", name="step_modif")
*/
public function step_modif(Request $request)
{
if ($request->isXmlHttpRequest()) {
// recuperation des données
$step = $request->request->get('step');
$tab_val = $request->request->get('tab_val');
// entité manager
$em = $this->getDoctrine()->getManager();
foreach ($tab_val as $value) {
$q = $em
->getRepository(FabricationPlanche::Class)
->findOneBy(array('id' => $value));
$o = $em
->getRepository(Commande::Class)
->findOneBy(array('id' => $value));
if ($step == 'finished') {
$q->setEtatAvancement(' ');
$q->setStatusFab($step);
$q->setDateMaj(new \DateTime);
//-----------------------------------------------------------------------
//-------------------------- INFOS SUR LA PLANCHE NUMERO STATUT
$sql = "SELECT num_serie, modele, marque, statut, email
FROM `V_stats`
WHERE `id` = " . $value . "";
$manager = $this->getDoctrine()->getManager();
$conn = $manager->getConnection();
$result = $conn->query($sql)->fetchAll();
$INFOnum_serie = $result[0]['num_serie'];
$INFOnum_modele = $result[0]['modele'];
$INFOnum_marque = $result[0]['marque'];
$INFOstatut = $result[0]['statut'];
$INFOemail = $result[0]['email'];
//-----------------------------------------------------------------------
//-------------------------- FIN
// SendEmail - Création d'un e-mail type
$passage_ligne = "\r\n";
$body_txt = "Hello " . $o->getPersonne()->getFirstname() . " " . $o->getPersonne()->getLastname() . " ! \n\n ======================================== \n\n Your surfboard is ready. You can pick-up it at :\n\n ZAC des fourneaux, 3 Rue Albert Denis, 17690 Angoulins FRANCE \n\n OR if you 've selected the shipping option, please confirm by email your exact address.\n\n
UWL SHAPERS CLUB, \n\nHave a nice day !\n\n";
$body_html = "<html><head></head><body><p>Hello " . $o->getPersonne()->getFirstname() . " " . $o->getPersonne()->getLastname() . ",</p><p>Your surfboard is ready.</p><p> You can pickup it at :</p><p>ZAC des fourneaux, 3 Rue Albert Denis, 17690 Angoulins FRANCE</p><p>Tel.+33 5 46 27 00 27 // Email. contact@uwl-surfboards.com </p><p>OR if you 've selected the shipping option, please confirm by email your exact address.</p><p></p><p>
UWL SHAPER CLUB</p></i>
<p>Have a nice day !</p><p><b>www.uwl-intranet.com</b></p></body></html>";
$body_txt2 = "Hello the crew, the board of " . $o->getPersonne()->getFirstname() . " " . $o->getPersonne()->getLastname() . " is ready ! \n\n ======================================== \n\n STATUS : " . $INFOstatut . " \n\n BRAND : " . $INFOnum_marque . " \n\n MODEL : " . $INFOnum_modele . " \n\n SERIAL NUMBER : " . $INFOnum_serie . "\n\n
UWL SHAPERS CLUB, \n\nHave a nice day !\n\n";
$body_html2 = "<html><head></head><body><p>Hello the crew,</p><p>The board of " . $o->getPersonne()->getFirstname() . " " . $o->getPersonne()->getLastname() . " is ready.</p><p> STATUS : " . $INFOstatut . " </p><p> BRAND : " . $INFOnum_marque . " </p><p> MODEL : " . $INFOnum_modele . " </p><p> SERIAL NUMBER : " . $INFOnum_serie . "</p><p> LINK : <a href='http://www.uwl-intranet.com/online/order/view/" . $value . "'>http://www.uwl-intranet.com/online/order/view/" . $value . "</a></p><p>
UWL SHAPER CLUB</p></i>
<p>Have a nice day !</p><p><b>www.uwl-intranet.com</b></p></body></html>";
//=====Création de la boundary
$boundary = "-----=" . md5(rand());
//==========
//=====Définition du sujet.
$subject = "[UWL SHAPERS CLUB] Hello " . $o->getPersonne()->getFirstname() . " " . $o->getPersonne()->getLastname() . " | Your surfboard is ready.";
$subject2 = "[UWL SHAPERS CLUB] The board of " . $o->getPersonne()->getFirstname() . " " . $o->getPersonne()->getLastname() . " is done.";
//==========
//=====Création du header de l'e-mail.
$header = "From: \"uwl-intranet\" <contact@uwl-surfboards.com>" . $passage_ligne;
$header .= "Reply-to: \"uwl-intranet\" <contact@uwl-surfboards.com>" . $passage_ligne;
$header .= "MIME-Version: 1.0" . $passage_ligne;
$header .= "Content-Type: multipart/alternative;" . $passage_ligne . " boundary=\"$boundary\"" . $passage_ligne;
//==========
//=====Création du message.
$message = $passage_ligne . "--" . $boundary . $passage_ligne;
//=====Ajout du message au format texte.
$message .= "Content-Type: text/plain; charset=\"ISO-8859-1\"" . $passage_ligne;
$message .= "Content-Transfer-Encoding: 8bit" . $passage_ligne;
$message .= $passage_ligne . $body_txt . $passage_ligne;
//==========
$message .= $passage_ligne . "--" . $boundary . $passage_ligne;
//=====Ajout du message au format HTML
$message .= "Content-Type: text/html; charset=\"ISO-8859-1\"" . $passage_ligne;
$message .= "Content-Transfer-Encoding: 8bit" . $passage_ligne;
$message .= $passage_ligne . $body_html . $passage_ligne;
//==========
$message .= $passage_ligne . "--" . $boundary . "--" . $passage_ligne;
$message .= $passage_ligne . "--" . $boundary . "--" . $passage_ligne;
//==========
//== MESSAGE 2
//=====Création du message 2.
$message2 = $passage_ligne . "--" . $boundary . $passage_ligne;
//=====Ajout du message 2 au format texte.
$message2 .= "Content-Type: text/plain; charset=\"ISO-8859-1\"" . $passage_ligne;
$message2 .= "Content-Transfer-Encoding: 8bit" . $passage_ligne;
$message2 .= $passage_ligne . $body_txt2 . $passage_ligne;
//==========
$message2 .= $passage_ligne . "--" . $boundary . $passage_ligne;
//=====Ajout du message 2 au format HTML
$message2 .= "Content-Type: text/html; charset=\"ISO-8859-1\"" . $passage_ligne;
$message2 .= "Content-Transfer-Encoding: 8bit" . $passage_ligne;
$message2 .= $passage_ligne . $body_html2 . $passage_ligne;
//==========
$message2 .= $passage_ligne . "--" . $boundary . "--" . $passage_ligne;
$message2 .= $passage_ligne . "--" . $boundary . "--" . $passage_ligne;
//==========
$req_user = $em
->getRepository(User::Class)
->findOneBy(array('id' => $o->getPersonne()));
try {
//$to = $req_user->getUsername();
$to = $INFOemail;
$to2 = "contact@uwl-surfboards.com";
mail($to2, $subject2, $message2, $header);
if ($INFOstatut != "Surfshop" OR $INFOstatut != "Subcontractor") {
mail($to, $subject, $message, $header);
// ENVOIE DES SMS
$TelSms = $o->getPersonne()->getCellularnumber();
if (strlen($TelSms) <= 10) {
$TelSms = "0" . $TelSms;
}
$sms = "http://www.itooki-sms.com/http.php?email=thomas@uwl-surfboards.com&pass=D2CT7F4&numero=" . $TelSms . "&message=Hello%20your%20surfboards%20is%20ready.%20UWL%20SHAPERS%20CLUB";
$resultatsms = implode("", file($sms));
} // FIN SI C'EST UN SHOP
} catch (Exception $e) {
redirectToRoute('homepage');
}
} else if ($step == 'delivered') {
$q->setEtatAvancement(' ');
$q->setStatusFab($step);
} else {
$q->setEtatAvancement($step);
}
$em->persist($q);
$em->flush();
}
// retour reponse en json
return new JsonResponse($o);
}
return new Response("Erreur : Requete incorrecte", 400);
}
}