src/Controller/User/UserController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller\User;
  3. use App\Common\Tools;
  4. use App\Entity\Admin;
  5. use App\Entity\Adminevent;
  6. use App\Entity\Adminprev;
  7. use App\Entity\Adminprevrdv;
  8. use App\Entity\Client;
  9. use App\Entity\Clientvente;
  10. use App\Entity\Fournisseur;
  11. use App\Entity\Messages;
  12. use App\Entity\Moisvalide;
  13. use App\Form\User\ClientProspectType;
  14. use App\Form\User\ClientType;
  15. use App\Utils\Dates\MalysDates;
  16. use Doctrine\ORM\EntityManagerInterface;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. class UserController extends AbstractController
  21. {
  22. private $malysDates;
  23. /**
  24. * @required
  25. */
  26. public function setMalysDates(MalysDates $malysDates)
  27. {
  28. $this->malysDates = $malysDates;
  29. }
  30. /**
  31. * @Route("/", name="homepage")
  32. */
  33. public function indexAction(Request $request,EntityManagerInterface $em)
  34. {
  35. return $this->homeAction(date("Y"), date("m"), date("W"), $request,$em);
  36. }
  37. /**
  38. * @Route("/mobile/{filter}", name="malys_user_mobilehome", defaults={"filter"="nom"}, requirements={"filter"="nom|datefr"})
  39. */
  40. public function mobileAction($filter, Request $request, EntityManagerInterface $em)
  41. {
  42. // on cherche un user-agent apparenté à une plateforme mobile dans la variable
  43. $iphone = strpos($request->server->get('HTTP_USER_AGENT'), 'iPhone');
  44. $ipad = strpos($request->server->get('HTTP_USER_AGENT'), 'iPad');
  45. $android = strpos($request->server->get('HTTP_USER_AGENT'), 'Android');
  46. $blackberry = strpos($request->server->get('HTTP_USER_AGENT'), 'BlackBerry');
  47. // Si c'est un mobile
  48. if ($iphone || $ipad || $android || $blackberry > -1) {
  49. // On recupère les clients du USER
  50. $clients_user = $em->getRepository(Client::class)->findMyClientsAndProspects($this->getUser()->getId(), $filter);
  51. ($filter == "datefr") ? $clients_user = array_reverse($clients_user, true) : 0;
  52. ($filter == "nom") ? $filter = 'datefr' : $filter = 'nom';
  53. return $this->render('User/mobile.html.twig', array(
  54. "clients" => $clients_user,
  55. "nom_commercial" => $this->getUser()->getUser(),
  56. "filter" => $filter
  57. ));
  58. } else {
  59. return $this->redirect($this->generateUrl('homepage'));
  60. }
  61. }
  62. /**
  63. * @Route("/mobile/commande/{id}", name="malys_user_mobilecommande", defaults={"id"=0})
  64. */
  65. public function mobilecommandeAction($id, EntityManagerInterface $em)
  66. {
  67. $clientRepository = $em->getRepository(Client::class);
  68. $client_info = $clientRepository->find($id);
  69. $limit = 30;
  70. $orders = $em->getRepository(Clientvente::class)->getLastOrdersClient($id, $limit);
  71. return $this->render('User/mobilecommande.html.twig', array(
  72. "client" => $client_info,
  73. "orders" => $orders
  74. ));
  75. }
  76. /**
  77. * @Route("/mobile/location/{id}", name="malys_user_mobilelocation", defaults={"id"=0})
  78. */
  79. public function mobilelocationAction($id, EntityManagerInterface $em)
  80. {
  81. $client_info = $em->getRepository(Client::class)->find($id);
  82. $adresse = $client_info->getAdresse() . " " . $client_info->getCp() . " " . $client_info->getVille();
  83. return $this->render('User/mobilelocation.html.twig', array(
  84. "client" => $client_info,
  85. "adresse" => $adresse
  86. ));
  87. }
  88. /**
  89. * @Route("/mobile/chart/{id}", name="malys_user_mobilechart", defaults={"id"=0})
  90. */
  91. public function mobilechartAction($id, EntityManagerInterface $em)
  92. {
  93. /* RECUPERATION DU CLIENT EN BASE */
  94. $client = $em->getRepository(Client::class)->find($id);
  95. //RECUPERE LE MOIS VALIDE LE PLUS PROCHE
  96. $MonthValid = $em->getRepository(Moisvalide::class)->findLastMoisvalide(date("n"), date("Y"));
  97. $annee_valide = $MonthValid[0]['annee'];
  98. $mois_valide = $MonthValid[0]['mois'];
  99. /* RECUPERATION CA CLIENT */
  100. $cv = $em->getRepository(Clientvente::class)->findMyClientCa($id, 'all');
  101. /* tableau ca pour chart */
  102. $t_valeur_ca_chart = array();
  103. /* tableau frn */
  104. $t_fournisseur = array();
  105. /* Total Ca client */
  106. $total_ca = 0;
  107. /* tableau ca last month */
  108. $t_last_month_ca = array();
  109. foreach ($cv as $v) {
  110. $ca_genere = 0;
  111. $annee_vente = $v[0]->getDatefr()->format('Y');
  112. $mois_vente = $v[0]->getDatefr()->format('n');
  113. (isset($v['ca_genere']) && $annee_vente == $annee_valide) ? $ca_genere = $v['ca_genere'] : $ca_genere = 0;
  114. //TABLEAU MOIS PAR MOIS
  115. if (!isset($t_valeur_ca_chart[intval($v[0]->getDatefr()->format('Y'))][intval($v[0]->getDatefr()->format('m'))])) {
  116. $t_valeur_ca_chart[intval($v[0]->getDatefr()->format('Y'))][intval($v[0]->getDatefr()->format('n'))] = array(
  117. 'ca_genere' => 0,
  118. 'ca_commission' => 0,
  119. 'solde' => 0
  120. );
  121. }
  122. $t_valeur_ca_chart[intval($v[0]->getDatefr()->format('Y'))][intval($v[0]->getDatefr()->format('n'))]['ca_genere'] += number_format($v['ca_genere'], 2, '.', '');
  123. $t_valeur_ca_chart[intval($v[0]->getDatefr()->format('Y'))][intval($v[0]->getDatefr()->format('n'))]['ca_commission'] += ($v[0]->getIdadmin()->getId() == $this->getUser()->getId()) ? number_format($v['ca_commission'], 2, '.', '') : 0;
  124. $t_valeur_ca_chart[intval($v[0]->getDatefr()->format('Y'))][intval($v[0]->getDatefr()->format('n'))]['solde'] += number_format($v[0]->getSolde(), 2, '.', '');
  125. //TABLEAU LAST MONTHS CA
  126. $date_vente = Date("n/Y", mktime(0, 0, 0, $mois_vente, 1, $annee_vente));
  127. $mois_valide_past = Date("n/Y", mktime(0, 0, 0, $mois_valide, 1, $annee_valide));
  128. $mois_past1 = Date("n/Y", mktime(0, 0, 0, $mois_valide - 1, 1, $annee_valide));
  129. $mois_past2 = Date("n/Y", mktime(0, 0, 0, $mois_valide - 2, 1, $annee_valide));
  130. if (!isset($t_last_month_ca[$v[0]->getIdfournisseur()->getId()])) {
  131. $t_last_month_ca[$v[0]->getIdfournisseur()->getId()] = array(
  132. $mois_valide_past => 0,
  133. $mois_past1 => 0,
  134. $mois_past2 => 0
  135. );
  136. if ($date_vente == $mois_valide_past or $date_vente == $mois_past1 or $date_vente == $mois_past2) {
  137. $t_last_month_ca[$v[0]->getIdfournisseur()->getId()][$mois_valide_past] = $v['ca_genere'];
  138. }
  139. } else {
  140. if ($date_vente == $mois_valide_past or $date_vente == $mois_past1 or $date_vente == $mois_past2) {
  141. $t_last_month_ca[$v[0]->getIdfournisseur()->getId()][$date_vente] = $v['ca_genere'];
  142. }
  143. }
  144. //TABLEAU FOURNISSEUR
  145. $montant = 0;
  146. if (!isset($t_fournisseur[$v[0]->getIdfournisseur()->getId()])) {
  147. $montant = $v['ca_genere'];
  148. $t_fournisseur[$v[0]->getIdfournisseur()->getId()] = array(
  149. 'nom' => $v[0]->getIdfournisseur()->getNom(),
  150. 'total_ca' => $montant
  151. );
  152. } else {
  153. $montant += $v['ca_genere'];
  154. $t_fournisseur[$v[0]->getIdfournisseur()->getId()]['total_ca'] += $montant;
  155. }
  156. //TOTAL CA CLIENT
  157. $total_ca += $ca_genere;
  158. }
  159. //CREATE JSON FOR CHART CA
  160. $t_ca_chart = array();
  161. foreach ($t_valeur_ca_chart as $key => $item_ca) {
  162. $t_ca = array();
  163. for ($i = 1; $i <= 12; $i++) {
  164. (isset($item_ca[$i]['ca_genere']) && intval($item_ca[$i]['ca_genere']) != 0) ? array_push($t_ca, $item_ca[$i]['ca_genere']) : array_push($t_ca, null);
  165. }
  166. ($key == date("Y")) ? array_push($t_ca_chart, (object)array(
  167. 'name' => $key,
  168. 'data' => $t_ca
  169. )) : array_push($t_ca_chart, (object)array('name' => $key, 'visible' => false, 'data' => $t_ca));
  170. }
  171. $t_ca_chart_json = json_encode($t_ca_chart);
  172. return $this->render('User/mobilechart.html.twig', array(
  173. 'client' => $client,
  174. 'user' => $this->getUser()->getFamille(),
  175. 't_ca_chart_json' => $t_ca_chart_json,
  176. 't_frn_client' => $t_fournisseur,
  177. 'total_ca' => $total_ca,
  178. 't_last_month_ca' => $t_last_month_ca,
  179. 'month_valid' => Date("n/Y", mktime(0, 0, 0, $mois_valide, 1, $annee_valide)),
  180. 'month_valid_past' => Date("n/Y", mktime(0, 0, 0, $mois_valide - 1, 1, $annee_valide)),
  181. 'month_valid_pastpast' => Date("n/Y", mktime(0, 0, 0, $mois_valide - 2, 1, $annee_valide)),
  182. ));
  183. }
  184. /**
  185. * @Route("/mobile/show/{id}", name="malys_user_mobileshow", defaults={"id"=0})
  186. */
  187. public function mobileshowAction($id, EntityManagerInterface $em)
  188. {
  189. $tab_fonction = array(
  190. 0 => 'non renseigne',
  191. 1 => 'Chef',
  192. 2 => 'Patron',
  193. 3 => 'Resp Bar',
  194. 4 => 'Gerant',
  195. 5 => 'Autre'
  196. );
  197. $tab_typeaffaire = array(
  198. 0 => 'Restaurant traditionnel',
  199. 1 => 'VAE',
  200. 2 => 'Bistrot <100 couverts/j',
  201. 3 => 'Basserie',
  202. 4 => 'Bar pur',
  203. 5 => 'Hotel',
  204. 6 => 'Boite de nuit',
  205. 7 => 'Traiteur',
  206. 8 => 'Autre',
  207. );
  208. $tab_typecontrat = array(
  209. 0 => 'non renseigne',
  210. 1 => 'Pret',
  211. 2 => 'MaD',
  212. 3 => 'Avance sur remise'
  213. );
  214. // On recupère les infos client
  215. $client_info = $em->getRepository(Client::class)->find($id);
  216. return $this->render('User/mobileshow.html.twig', array(
  217. 'client' => $client_info,
  218. 'tab_fonction' => $tab_fonction,
  219. 'tab_typeaffaire' => $tab_typeaffaire,
  220. 'tab_typecontrat' => $tab_typecontrat,
  221. ));
  222. }
  223. /**
  224. * @Route("/mobile/modify/{id}", name="malys_user_mobilemodify", defaults={"id"=0})
  225. */
  226. public function mobilemodifyAction($id, Request $request, EntityManagerInterface $em)
  227. {
  228. //$currentRoute = $request->attributes->get('_route');
  229. /*if($currentRoute != 'malys_user_mobileshow')
  230. return $this->redirect($this->generateUrl('malys_user_mobileshow', array('id' => $id)));*/
  231. //if($this->get('request')->headers->get('referer')){ $toto = "redirect ";}
  232. $type = '';
  233. if (isset($id) and $id != 0) {
  234. $client = $em->getRepository(Client::class)->find($id);
  235. $type = "Modifier";
  236. } else {
  237. $client = new Client;
  238. $type = "Ajouter";
  239. }
  240. // On verifie si le user est un admin ou pas pour créer le formualaire correspondant
  241. if ($id && $this->isGranted('ROLE_ADMIN')) {
  242. $form = $this->createForm(new ClientType($client->getProspect(), true), $client);
  243. } else {
  244. $form = $this->createForm(new ClientType($client->getProspect()), $client);
  245. }
  246. //On Regarde si on a recu une requete POST => si oui c'est que le user nous transmet un ajout ou une modif.
  247. if ($request->getMethod() == 'POST') {
  248. $form->handleRequest($request);
  249. if ($form->isValid()) {
  250. //Si une aucune date client on met a jour
  251. if ($client->getDateclientfr() == null) {
  252. $client->setDateclientfr($client->getDatefr());
  253. }
  254. // si c'est un nouveau client, on lui associe le user en admin
  255. if ($client->getIdadmin() == null) {
  256. $client->setIdadmin($this->getUser());
  257. }
  258. $em->persist($client);
  259. $em->flush();
  260. $id_client_retour = $client->getId();
  261. return $this->redirect($this->generateUrl('malys_user_mobileshow', array('id' => $id_client_retour)));
  262. }
  263. }
  264. return $this->render('User/mobilemodify.html.twig', array(
  265. 'form' => $form->createView(),
  266. 'client' => $client,
  267. 'type' => $type
  268. ));
  269. }
  270. /**
  271. * @Route("/index/{annee}/{mois}/{semaine}", name="malys_user_homepage", defaults={"semaine"=0})
  272. */
  273. public function homeAction($annee, $mois, $semaine, Request $request, EntityManagerInterface $em)
  274. {
  275. $annee_cal = $annee;
  276. $mois_cal = $mois;
  277. $semaine_cal = $semaine;
  278. //$this->container->get('malys_user.charts');
  279. $tab_mois_fr = $this->malysDates->getTabMoisFr();
  280. $tab_jours_fr = $this->malysDates->getTabJoursFr();
  281. //echo " <pre>";print_r($tab_mois_fr); echo " </pre><pre> "; print_r($tab_jours_fr);echo " </pre>";
  282. // CA GENERE DU MOIS POUR UN COMMERCIAL
  283. /*$t_ListeCA = array();
  284. $ca = $em->getRepository(Clientvente::Class)->findCommercialCa($this->getUser()->getId(), $annee);
  285. foreach ($ca as $c)
  286. $t_ListeCA[intval($c['le_mois'])] = $c['ca_genere'];*/
  287. //RECUPERE LE MOIS VALIDE LE PLUS PROCHE
  288. //
  289. $MonthValid = $em->getRepository(Moisvalide::class)->findLastMoisvalide(date("n"), date("Y"));
  290. // debug here
  291. $annee = $MonthValid[0]['annee'];
  292. $mois_valide = $MonthValid[0]['mois'];
  293. /* GRAPH */
  294. /* $objChart = new \Chart(140, 100, "chart_bar_ca_mois_" . $this->getUser()->getId() . "_gd_small");
  295. $objChart->SetHeaderName("Evolution CA " . $annee);
  296. $objChart->SetY_Barchart_Show_Values(true);
  297. for ($i = 1; $i < 13; $i++)
  298. $objChart->AddValue((string) $i, (isset($t_ListeCA[$i])) ? intval($t_ListeCA[$i]) : 0);
  299. $objChart->SetImageDestination("images/graph/");
  300. $objChart->CreateChartImage(LINE_CHART);*/
  301. // FOURNISSEURS
  302. if ($this->getUser()->getFamille() == 'Commercial') {
  303. $fournisseurs = $em->getRepository(Fournisseur::class)->findMyClientsFournisseurs($this->getUser()->getId());
  304. } else {
  305. $fournisseurs = null;
  306. }
  307. //RECUPERATION DES MESSAGES NON LUS
  308. $mes = $em->getRepository(Messages::class)->findMyMessagesNonLus($this->getUser()->getId());
  309. //AFFICHAGE DES RDV DU JOUR ET DU LENDEMAIN
  310. $rdv = $em->getRepository(Adminevent::class)->findTodayAndTomorrowRdv($this->getUser()->getId());
  311. //RECUPERATION DES STATS CLIENTELE
  312. $t_ListePC = array();
  313. $stats = $em->getRepository(Client::class)->findMyClientsStats($this->getUser()->getId());
  314. foreach ($stats as $s) {
  315. if ($s[0]->getProspect() == 1) {
  316. $t_ListePC['prospect'][$s[0]->getNote()] = $s['nombre'];
  317. } else {
  318. $t_ListePC['client'][$s[0]->getActivite()] = $s['nombre'];
  319. }
  320. }
  321. //LISTE SIMULATION HEBDO
  322. $simu = $em->getRepository(Adminevent::class)->findCommercialSimulationHebdo($this->getUser()->getId(), $annee, $semaine);
  323. //RECUPERATION DES OBJECTIFS RDV
  324. $obj_rdv = $em->getRepository(Adminprevrdv::class)->findOneBy(array(
  325. 'idadmin' => $this->getUser()->getId(),
  326. 'annee' => $annee,
  327. 'semaine' => $semaine
  328. ));
  329. //LISTE PROSPECTION HEBDO
  330. $t_ListeProspect = array();
  331. $pro = $em->getRepository(Client::class)->findListeProspectionHebdo($this->getUser()->getId(), $annee, $semaine);
  332. foreach ($pro as $p) {
  333. $t_ListeProspect[$p[0]->getNote()] = $p['nbprospect'];
  334. }
  335. //LISTE RDV CLIENTS
  336. $rdvClient = $em->getRepository(Adminevent::class)->findMyClientRdvHebdo($this->getUser()->getId(), $annee, $semaine);
  337. //LISTE TRANSFOS CLIENTS
  338. $transfo = $em->getRepository(Client::class)->findMyTransfoClientHebdo($this->getUser()->getId(), $annee, $semaine);
  339. //OBJECTIF DE CA
  340. $caObj = $em->getRepository(Adminprev::class)->findCommercialPrevCaInMonth($this->getUser()->getId(), $annee, $mois);
  341. //ALL CA FRN BY MONTH/YEAR
  342. $getAllCaByMonth = $em->getRepository(Clientvente::class)->getAllCaByMonth(3, $this->getUser()->getId(), $this->getUser()->getFamille());
  343. //ALL OBJECTIF BY MONTH/YEAR
  344. $t_Objectifs = $em->getRepository(Adminprev::class)->getAllPrevCaByMonth($this->getUser()->getId(), $this->getUser()->getFamille(), $annee);
  345. $t_objectif = array();
  346. $obj_total = 0;
  347. foreach ($t_Objectifs as $key => $item) {
  348. (intval($item['objectif'] != 0)) ? array_push($t_objectif, intval($item['objectif'])) : array_push($t_objectif, null);
  349. $obj_total += intval($item['objectif']);
  350. }
  351. //création json pour chart CA
  352. $t_ca_chart = array();
  353. foreach ($getAllCaByMonth as $key => $item) {
  354. $t_ca = array();
  355. $i = 0;
  356. foreach ($item as $year => $ca) {
  357. if ($i != 0) {
  358. (intval($ca) != 0) ? array_push($t_ca, intval($ca)) : array_push($t_ca, null);
  359. }
  360. $i++;
  361. }
  362. ($item["Annee"] == $annee) ? array_push($t_ca_chart, (object)array(
  363. 'name' => $item["Annee"],
  364. 'data' => $t_ca
  365. )) : array_push($t_ca_chart, (object)array(
  366. 'name' => $item["Annee"],
  367. 'visible' => false,
  368. 'data' => $t_ca
  369. ));
  370. }
  371. array_push($t_ca_chart, (object)array('name' => "Objectifs", 'color' => '#a3dfd9', 'data' => $t_objectif));
  372. array_push($t_objectif, $obj_total);
  373. $t_ca_chart_json = json_encode($t_ca_chart);
  374. unset($t_ca_chart); //Free memoire
  375. unset($getAllCaByMonth);
  376. //ALL CA CLIENT BY MONTH/YEAR
  377. $t_allCaClientByMonth = $em->getRepository(Clientvente::class)->getAllClientsCaLight($annee, null, 'three year', $this->getUser()->getId(), $this->getUser()->getFamille());
  378. $t_listClientActif = array();
  379. $t_listClientNouveau = array();
  380. $t_listClientPerdu = array();
  381. $t_ListeCaClientForChart = array();
  382. $t_ListeCaFamilleForChart = array();
  383. $t_CaFamilleForChart = array();
  384. // Recuperation tab CAclient/mois et tab CaFamille/mois
  385. foreach ($t_allCaClientByMonth as $caClient => $item) {
  386. $yearfr = $item['datefr']->format('Y');
  387. $monthfr = $item['datefr']->format('n');
  388. // Recuperation des clients actifs du dernier mois valider
  389. if ($monthfr == $mois_valide && $yearfr == $annee) {
  390. if (!isset($t_listClientActif[$item['id']])) {
  391. $t_listClientActif[$item['id']] = $item['nom'];
  392. $t_listClientNouveau[$item['id']] = $item['nom'];
  393. }
  394. }
  395. // Recuperation des clients actifs du dernier mois valider-1
  396. if ($monthfr == $mois_valide - 1 && $yearfr == $annee) {
  397. if (!isset($t_listClientPerdu[$item['id']])) {
  398. $t_listClientPerdu[$item['id']] = $item['nom'];
  399. }
  400. }
  401. // Si l'année, le mois et le client n'existe pas dans le tableau d'arrivée, on l'ajoute au tableau
  402. if ($yearfr == $annee || $yearfr == $annee - 1) {
  403. if (!isset($t_ListeCaClientForChart[$yearfr][$monthfr][$item['id']])) {
  404. if ($item['ca_genere'] > 0) {
  405. $t_ListeCaClientForChart[$yearfr][$monthfr][$item['id']] = array();
  406. $t_ListeCaClientForChart[$yearfr][$monthfr][$item['id']]['ca_genere'] = number_format((float)$item['ca_genere'], 2, '.', '');
  407. }
  408. } else { // Si la case existe déjà
  409. if ($item['ca_genere'] > 0) {
  410. $t_ListeCaClientForChart[$yearfr][$monthfr][$item['id']]['ca_genere'] += number_format((float)$item['ca_genere'], 2, '.', '');
  411. }
  412. }
  413. }
  414. // Si l'année n'existe pas dans le tableau CAfamille d'arrivée, on ajoute la case avec la l'année
  415. if ($yearfr == $annee) {
  416. if (!isset($t_ListeCaFamilleForChart[$item['famille']])) {
  417. $t_ListeCaFamilleForChart[$item['famille']] = array();
  418. $t_ListeCaFamilleForChart[$item['famille']] = number_format((float)$item['ca_genere'], 2, '.', '');
  419. } else {
  420. $t_ListeCaFamilleForChart[$item['famille']] += number_format((float)$item['ca_genere'], 2, '.', '');
  421. }
  422. }
  423. }
  424. //ON RETIRE LES CLIENTS QUI ONT COMMANDES DE LA LISTE
  425. foreach ($t_listClientPerdu as $k => $value) {
  426. if (isset($t_listClientActif[$k])) {
  427. unset($t_listClientPerdu[$k]);
  428. }
  429. }
  430. foreach ($t_allCaClientByMonth as $caClient => $item) {
  431. $yearfr = $item['datefr']->format('Y');
  432. $monthfr = $item['datefr']->format('n');
  433. // Recuperation des clients Nouveau du dernier mois valider
  434. if ($yearfr == ($annee)) {
  435. if ($monthfr == ($mois_valide) - 1 ||
  436. $monthfr == ($mois_valide) - 2 ||
  437. $monthfr == ($mois_valide) - 3 ||
  438. $monthfr == ($mois_valide) - 4) {
  439. if (isset($t_listClientNouveau[$item['id']])) {
  440. unset($t_listClientNouveau[$item['id']]);
  441. }
  442. }
  443. }
  444. }
  445. unset($t_allCaClientByMonth); //Free memoire
  446. $t_ca_famille = array();
  447. foreach ($t_ListeCaFamilleForChart as $key => $value) {
  448. ($key != "") ? array_push($t_ca_famille, array(
  449. $key,
  450. intval($value)
  451. )) : array_push($t_ca_famille, array("AUTRE", intval($value)));
  452. }
  453. // Obtient une liste de colonnes
  454. foreach ($t_ca_famille as $key => $row) {
  455. $volume[$key] = $row[1];
  456. $edition[$key] = $row[0];
  457. }
  458. // Trie les données par volume décroissant, edition croissant
  459. // Ajoute $data en tant que dernier paramètre, pour trier par la clé commune
  460. if (isset($volume)) {
  461. array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $t_ca_famille);
  462. }
  463. array_push($t_CaFamilleForChart, (object)array(
  464. 'type' => 'pie',
  465. 'name' => 'Famille',
  466. 'data' => $t_ca_famille
  467. ));
  468. unset($t_ca_famille); // free Memory
  469. $t_CaFamilleForChart_json = json_encode($t_CaFamilleForChart);
  470. unset($t_CaFamilleForChart);
  471. unset($t_ListeCaFamilleForChart);
  472. $t_gp_val_chart = array();
  473. $t_gp_client_chart = array();
  474. $t_ListeGainsPertes = array(
  475. 0 => array('gain' => array(), 'perte' => array(), 'type' => 'ca'),
  476. 1 => array('gain' => array(), 'perte' => array(), 'type' => 'client')
  477. );
  478. if (isset($t_ListeCaClientForChart[$annee - 1][12])) {
  479. foreach ($t_ListeCaClientForChart[$annee - 1][12] as $id => $ca) {
  480. (!array_key_exists($id, $t_ListeCaClientForChart[$annee][1])) ? $t_ListeCaClientForChart[$annee][1][$id] = array('ca_genere' => 0.0) : null;
  481. }
  482. }
  483. foreach ($t_ListeCaClientForChart as $year => $item) {
  484. foreach ($item as $month => $val) {
  485. foreach ($val as $id => $ca) {
  486. for ($i = 1; $i < count($item); $i++) {
  487. if (isset($t_ListeCaClientForChart[$year][$i])) {
  488. (!array_key_exists($id, $t_ListeCaClientForChart[$year][$i])) ? $t_ListeCaClientForChart[$year][$i][$id] = array('ca_genere' => 0.0) : null;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. for ($i = 1; $i <= 12; $i++) {
  495. (!isset($t_ListeCaClientForChart[$annee][$i])) ? $t_ListeCaClientForChart[$annee][$i] = null : 1;
  496. }
  497. ksort($t_ListeCaClientForChart[$annee], SORT_ASC);
  498. //calcul et recuperation "pertes et gains" total en valeur et client/MOIS
  499. foreach ($t_ListeCaClientForChart as $year => $item) {
  500. $t_gains_valeur = array();
  501. $t_pertes_valeur = array();
  502. $t_gains_client = array();
  503. $t_pertes_client = array();
  504. if ($year == $annee) {
  505. foreach ($item as $month => $val) {
  506. $gainsValeur = 0;
  507. $pertesValeur = 0;
  508. $gainsClient = 0;
  509. $pertesClient = 0;
  510. if ($val != null) {
  511. foreach ($val as $client => $caClient) {
  512. $caMoisPrec = 0;
  513. if ($month != 1) { // Si C'est pas le mois de janvier
  514. if (isset($item[$month - 1][$client])) {
  515. $caMoisPrec = $item[$month - 1][$client]['ca_genere'];
  516. }
  517. } else { // si c'est janvier => IDEM avec décembre de l'année précédente
  518. if (isset($t_ListeCaClientForChart[$year - 1][12][$client])) {
  519. $caMoisPrec = $t_ListeCaClientForChart[$year - 1][12][$client]['ca_genere'];
  520. }
  521. }
  522. $diff = ($caClient['ca_genere']) - ($caMoisPrec); // ON calcul $diff => CA du mois - (Ca du mois-1) [exemple: CAmars - CAfevrier ]
  523. ($diff < 0) ? $pertesValeur += $diff : $gainsValeur += $diff; // On met a jour Gains et Pertes
  524. //On calcul $evoCa => (CA du mois - (Ca du mois-1)) / (Ca du mois-1) [exemple: (CAmars - CAfevrier)/CAfevrier ]
  525. if ($caMoisPrec != 0) {
  526. $evoCa = (($caClient['ca_genere']) - ($caMoisPrec)) / ($caMoisPrec);
  527. } else {
  528. $evoCa = 0;
  529. }
  530. // On met a jour Gains et Pertes Client
  531. if ($evoCa < 0) {
  532. $pertesClient--;
  533. }
  534. if ($evoCa > 0) {
  535. $gainsClient++;
  536. }
  537. }
  538. } else {
  539. $gainsClient = null;
  540. $pertesClient = null;
  541. $pertesValeur = null;
  542. $gainsValeur = null;
  543. }
  544. array_push($t_gains_valeur, $gainsValeur);
  545. array_push($t_pertes_valeur, $pertesValeur);
  546. array_push($t_gains_client, $gainsClient);
  547. array_push($t_pertes_client, $pertesClient);
  548. }
  549. }
  550. if ($year == $annee) {
  551. array_push($t_gp_val_chart, (object)array('name' => "Gains", 'data' => $t_gains_valeur)); //Valeur
  552. array_push($t_gp_val_chart, (object)array(
  553. 'name' => "Pertes",
  554. 'data' => $t_pertes_valeur
  555. )); //Valeur
  556. array_push($t_gp_client_chart, (object)array(
  557. 'name' => "Gains",
  558. 'data' => $t_gains_client
  559. )); //Client
  560. array_push($t_gp_client_chart, (object)array(
  561. 'name' => "Pertes",
  562. 'data' => $t_pertes_client
  563. )); //Client
  564. array_push($t_ListeGainsPertes[0]['gain'], $t_gains_valeur); //Valeur
  565. array_push($t_ListeGainsPertes[0]['perte'], $t_pertes_valeur); //Valeur
  566. array_push($t_ListeGainsPertes[1]['gain'], $t_gains_client); //Client
  567. array_push($t_ListeGainsPertes[1]['perte'], $t_pertes_client); //Client
  568. }
  569. }
  570. // COnstrcution JSON pour GAINS PERTES CHARTS
  571. $t_gp_val_chart_json = json_encode($t_gp_val_chart);
  572. $t_gp_client_chart_json = json_encode($t_gp_client_chart);
  573. unset($t_gp_val_chart);
  574. unset($t_gp_client_chart);
  575. //Tableau Gains Pertes
  576. $tab_moy = array('moyValP' => 0, 'moyCliP' => 0, 'moyValG' => 0, 'moyCliG' => 0);
  577. $next = 0;
  578. $nbmonth = 0;
  579. foreach ($t_ListeGainsPertes as $key => $val) {
  580. if ($val['gain'][0]) {
  581. foreach ($val['gain'][0] as $k => $value) {
  582. ($next == 0) ? $tab_moy['moyValG'] += $value : $tab_moy['moyCliG'] += $value;
  583. ($next == 0) ? $nbmonth++ : null;
  584. }
  585. }
  586. if ($val['perte'][0]) {
  587. foreach ($val['perte'][0] as $k => $value) {
  588. ($next == 0) ? $tab_moy['moyValP'] += $value : $tab_moy['moyCliP'] += $value;
  589. }
  590. }
  591. $next++;
  592. }
  593. if ($nbmonth != 0) {
  594. array_push($t_ListeGainsPertes[0]['gain'], $tab_moy['moyValG'] / $nbmonth);
  595. array_push($t_ListeGainsPertes[0]['perte'], $tab_moy['moyValP'] / $nbmonth);
  596. array_push($t_ListeGainsPertes[1]['gain'], $tab_moy['moyCliG'] / $nbmonth);
  597. array_push($t_ListeGainsPertes[1]['perte'], $tab_moy['moyCliP'] / $nbmonth);
  598. }
  599. unset($tab_moy);
  600. unset($t_gp_val_chart);
  601. unset($t_gp_client_chart);
  602. unset($t_gains_valeur);
  603. unset($t_pertes_valeur);
  604. unset($t_gains_client);
  605. unset($t_pertes_client);
  606. // Recuperation segClient/mois et segValeur/mois
  607. $t_seg_client_chart = array();
  608. $t_seg_valeur_chart = array();
  609. $t_seg_client = array(
  610. '0' => array(),
  611. '1' => array(),
  612. '2' => array(),
  613. '3' => array(),
  614. '4' => array(),
  615. '5' => array()
  616. );
  617. $t_seg_valeur = array(
  618. '0' => array(),
  619. '1' => array(),
  620. '2' => array(),
  621. '3' => array(),
  622. '4' => array(),
  623. '5' => array()
  624. );
  625. $t_seg = array(
  626. 0 => array("palier" => 500, "valeur" => 0, "client" => 0, "name" => '0-500'),
  627. 1 => array("palier" => 1500, "valeur" => 0, "client" => 0, "name" => '500-1500'),
  628. 2 => array("palier" => 3000, "valeur" => 0, "client" => 0, "name" => '1500-3000'),
  629. 3 => array("palier" => 9000, "valeur" => 0, "client" => 0, "name" => '3000-9000'),
  630. 4 => array("palier" => 20000, "valeur" => 0, "client" => 0, "name" => '9000-20000'),
  631. 5 => array("valeur" => 0, "client" => 0, "name" => '>20000'),
  632. );
  633. $Liste_client_groupe1 = array($year => array());
  634. // On recupere les valeurs de segmentation
  635. foreach ($t_ListeCaClientForChart as $year => $item) {
  636. if ($year == $annee) {
  637. foreach ($item as $month => $val) {
  638. for ($i = 0; $i < count($t_seg); $i++) {
  639. $t_seg[$i]["valeur"] = 0;
  640. $t_seg[$i]["client"] = 0;
  641. }
  642. (!isset($Liste_client_groupe1[$year][$month])) ? $Liste_client_groupe1[$year][$month] = array() : 1;
  643. if ($val != null) {
  644. foreach ($val as $client => $caClient) {
  645. //Récupération des valeurs de segementation
  646. if ($caClient['ca_genere'] > 1 && $caClient['ca_genere'] <= $t_seg[0]["palier"]) {
  647. $t_seg[0]["valeur"] += $caClient['ca_genere'];
  648. $t_seg[0]["client"] += 1;
  649. //TODO EXTRACT LIST OF CLIENT BY GROUPE AND BY MONTH
  650. array_push($Liste_client_groupe1[$year][$month], $client);
  651. } else if ($caClient['ca_genere'] > $t_seg[0]["palier"] && $caClient['ca_genere'] <= $t_seg[1]["palier"]) {
  652. $t_seg[1]["valeur"] += $caClient['ca_genere'];
  653. $t_seg[1]["client"] += 1;
  654. } else if ($caClient['ca_genere'] > $t_seg[1]["palier"] && $caClient['ca_genere'] <= $t_seg[2]["palier"]) {
  655. $t_seg[2]["valeur"] += $caClient['ca_genere'];
  656. $t_seg[2]["client"] += 1;
  657. } else if ($caClient['ca_genere'] > $t_seg[2]["palier"] && $caClient['ca_genere'] <= $t_seg[3]["palier"]) {
  658. $t_seg[3]["valeur"] += $caClient['ca_genere'];
  659. $t_seg[3]["client"] += 1;
  660. } else if ($caClient['ca_genere'] > $t_seg[3]["palier"] && $caClient['ca_genere'] <= $t_seg[4]["palier"]) {
  661. $t_seg[4]["valeur"] += $caClient['ca_genere'];
  662. $t_seg[4]["client"] += 1;
  663. } else if ($caClient['ca_genere'] > $t_seg[4]["palier"]) {
  664. $t_seg[5]["valeur"] += $caClient['ca_genere'];
  665. $t_seg[5]["client"] += 1;
  666. }
  667. }
  668. }
  669. foreach ($t_seg as $key => $value) {
  670. if ($year == $annee) {
  671. for ($i = 0; $i < 6; $i++) {
  672. if ($key == $i) {
  673. array_push($t_seg_client[$i], $value['client']);
  674. array_push($t_seg_valeur[$i], $value['valeur']);
  675. }
  676. }
  677. }
  678. }
  679. }
  680. }
  681. }
  682. $t_ListeSeg = array();
  683. array_push($t_ListeSeg, $t_seg_client);
  684. array_push($t_ListeSeg, $t_seg_valeur);
  685. foreach ($t_ListeSeg as $key => $val) {
  686. foreach ($val as $k => $value) {
  687. $total = 0;
  688. for ($i = 0; $i < count($value); $i++) {
  689. $total += $value[$i];
  690. }
  691. if ($key == 1) {
  692. $t_ListeSeg[$key][$k]['total_group'] = $total;
  693. } else {
  694. (count($value) != 0) ? $t_ListeSeg[$key][$k]['total_group'] = ($total / count($value)) : null;
  695. }
  696. for ($j = 0; $j < count($t_seg); $j++) {
  697. $t_ListeSeg[$key][$j]['nom'] = $t_seg[$j]['name'];
  698. }
  699. }
  700. }
  701. $t_listeNbCommande = array();
  702. $t_listeCaSeg = array();
  703. for ($j = 0; $j < 12; $j++) {
  704. $total_client = 0;
  705. $total_ca = 0;
  706. foreach ($t_ListeSeg[0] as $key => $val) {
  707. (isset($val[$j])) ? $total_client += $val[$j] : null;
  708. }
  709. array_push($t_listeNbCommande, $total_client);
  710. foreach ($t_ListeSeg[1] as $key => $val) {
  711. (isset($val[$j])) ? $total_ca += $val[$j] : null;
  712. }
  713. array_push($t_listeCaSeg, $total_ca);
  714. }
  715. for ($j = 5; $j > -1; $j--) {
  716. array_push($t_seg_client_chart, (object)array(
  717. 'type' => "column",
  718. 'name' => $t_seg[$j]['name'],
  719. 'data' => $t_seg_client[$j],
  720. 'id' => $t_seg[$j]['name'] . 'c',
  721. )
  722. );
  723. array_push($t_seg_valeur_chart, (object)array(
  724. 'type' => "column",
  725. 'name' => $t_seg[$j]['name'],
  726. 'data' => $t_seg_valeur[$j],
  727. 'id' => $t_seg[$j]['name'] . 'v',
  728. ));
  729. }
  730. for ($j = 5; $j > -1; $j--) {
  731. array_push($t_seg_client_chart, (object)array(
  732. 'name' => 'seg1->',
  733. 'id' => $t_seg[$j]['name'] . 'cc',
  734. 'showInLegend' => false,
  735. 'color' => 'red',
  736. 'lineWidth' => 1,
  737. 'marker' => (object)array(
  738. 'lineWidth' => 0.1,
  739. 'lineColor' => 'Highcharts.getOptions().colors[4]',
  740. 'fillColor' => "white",
  741. "radius" => 2,
  742. 'enabled' => true
  743. ),
  744. 'data' => $t_seg_client[$j]
  745. ));
  746. array_push($t_seg_valeur_chart, (object)array(
  747. 'name' => "seg1->",
  748. 'id' => $t_seg[$j]['name'] . 'vv',
  749. 'showInLegend' => false,
  750. 'color' => 'red',
  751. 'lineWidth' => 1,
  752. 'marker' => (object)array(
  753. 'lineWidth' => 0.1,
  754. 'lineColor' => 'Highcharts.getOptions().colors[4]',
  755. 'fillColor' => "white",
  756. "radius" => 2,
  757. 'enabled' => true
  758. ),
  759. 'data' => $t_seg_valeur[$j]
  760. ));
  761. }
  762. $t_seg_client_chart_json = json_encode($t_seg_client_chart);
  763. $t_seg_valeur_chart_json = json_encode($t_seg_valeur_chart);
  764. unset($t_seg);
  765. unset($t_seg_client_chart);
  766. unset($t_seg_client);
  767. unset($t_seg_valeur_chart);
  768. unset($t_seg_valeur);
  769. //vide memoire
  770. // Recupération informations pour tableau fournisseurs global
  771. // TRAITEMENT FORMULAIRE ET VALEURS PAR DEFAUT
  772. $year = $annee;
  773. $source = $request->get('source', null) == '' ? null : $request->get('source', null);
  774. $perf_ca = $request->get('perf_ca', null);
  775. $type = 'fournisseur';
  776. // GET CA
  777. $cv = $em->getRepository(Clientvente::class)->getAllFournisseursCa($year, $source, "three year", $this->getUser()->getId(), $this->getUser()->getFamille());
  778. $t_ListeCA_frn = array();
  779. $t_ListeMois = array();
  780. $t_ListeDetail = array();
  781. foreach ($cv as $c) {
  782. $mois = intval($c[0]['datefr']->format('m'));
  783. $yeartraitement = intval($c[0]['datefr']->format('Y'));
  784. $id = $c['id'];
  785. //TABLEAU ANNNEE TOTAUX
  786. if (!isset($t_ListeMois[$yeartraitement])) {
  787. $t_ListeMois[$yeartraitement] = array(
  788. 'cagenere_total' => 0,
  789. 'cacommission_total' => 0,
  790. 'solde_total' => 0
  791. );
  792. }
  793. //TABLEAU DETAILLE
  794. if (!isset($t_ListeCA_frn[$yeartraitement][$id])) {
  795. $t_ListeCA_frn[$yeartraitement][$id] = array(
  796. 'cagenere_total' => 0,
  797. 'cacommission_total' => 0,
  798. 'solde_total' => 0
  799. );
  800. }
  801. $t_ListeCA_frn[$yeartraitement][$id][$mois]['ca_genere'] = number_format($c['ca_genere'], 2, '.', '');
  802. $t_ListeCA_frn[$yeartraitement][$id][$mois]['ca_commission'] = number_format($c['ca_commission'], 2, '.', '');
  803. $t_ListeCA_frn[$yeartraitement][$id][$mois]['solde'] = number_format($c['ca_solde'], 2, '.', '');
  804. $t_ListeCA_frn[$yeartraitement][$id]['id' . $type] = $c['id'];
  805. $t_ListeCA_frn[$yeartraitement][$id]['nom'] = $c['nom'];
  806. $t_ListeCA_frn[$yeartraitement][$id]['cagenere_total'] += number_format($c['ca_genere'], 2, '.', '');
  807. $t_ListeCA_frn[$yeartraitement][$id]['cacommission_total'] += number_format($c['ca_commission'], 2, '.', '');
  808. $t_ListeCA_frn[$yeartraitement][$id]['solde_total'] += number_format($c['ca_solde'], 2, '.', '');
  809. $t_ListeCA_frn[$yeartraitement][$id]['source'] = $c['source'];
  810. //TABLEAU ANNEE MOIS PAR MOIS
  811. if (!isset($t_ListeMois[$yeartraitement][$mois])) {
  812. $t_ListeMois[$yeartraitement][$mois] = array(
  813. 'ca_genere' => 0,
  814. 'ca_commission' => 0,
  815. 'solde' => 0
  816. );
  817. }
  818. $t_ListeMois[$yeartraitement][$mois]['ca_genere'] += number_format($c['ca_genere'], 2, '.', '');
  819. $t_ListeMois[$yeartraitement][$mois]['ca_commission'] += number_format($c['ca_commission'], 2, '.', '');
  820. $t_ListeMois[$yeartraitement][$mois]['solde'] += number_format($c['ca_solde'], 2, '.', '');
  821. //TEABLEAU TOTAL
  822. $t_ListeMois[$yeartraitement]['cagenere_total'] += number_format($c['ca_genere'], 2, '.', '');
  823. $t_ListeMois[$yeartraitement]['cacommission_total'] += number_format($c['ca_commission'], 2, '.', '');
  824. $t_ListeMois[$yeartraitement]['solde_total'] += number_format($c['ca_solde'], 2, '.', '');
  825. //TABLEAU PAR TYPE DETAIL
  826. if (!isset($t_ListeDetail[$yeartraitement][$id])) {
  827. $t_ListeDetail[$yeartraitement][$id] = array(
  828. 'ca_genere' => 0,
  829. 'ca_commission' => 0,
  830. 'solde' => 0
  831. );
  832. }
  833. $t_ListeDetail[$yeartraitement][$id]['ca_genere'] += number_format($c['ca_genere'], 2, '.', '');
  834. $t_ListeDetail[$yeartraitement][$id]['ca_commission'] += number_format($c['ca_commission'], 2, '.', '');
  835. $t_ListeDetail[$yeartraitement][$id]['solde'] += number_format($c['ca_solde'], 2, '.', '');
  836. $t_ListeDetail[$yeartraitement][$id]['source'] = $c['source'];
  837. }
  838. if ($perf_ca != null) {
  839. uasort($t_ListeCA, "App\\Controller\\Marketing::cmpCa");
  840. }
  841. // GET POTENCIEL
  842. $potenciel = $em->getRepository(Client::class)->getPotentielCaClient(0, $this->getUser()->getId(), $this->getUser()->getFamille());
  843. $potentiel_json = array();
  844. $potenciel[0]['potentiel'] = 0;
  845. if (intval($potenciel[0]['potentiel']) - intval(number_format($t_ListeMois[$annee]["cagenere_total"], 2, '.', '')) > 0) {
  846. array_push($potentiel_json, (object)array(
  847. 'name' => "Potentiel",
  848. 'id' => '' + $potenciel[0]['potentiel'] + '',
  849. 'data' => array(intval($potenciel[0]['potentiel']) - intval(number_format($t_ListeMois[$annee]["cagenere_total"], 2, '.', ''))),
  850. ));
  851. array_push($potentiel_json, (object)array(
  852. 'name' => "CA realise",
  853. 'id' => '' + intval(number_format($t_ListeMois[$annee]["cagenere_total"], 2, '.', '')) + '',
  854. 'data' => array(intval(number_format($t_ListeMois[$annee]["cagenere_total"], 2, '.', ''))),
  855. ));
  856. } else {
  857. if ($potenciel[0]['potentiel'] != 0) {
  858. $ca = intval(number_format($t_ListeMois[$annee]["cagenere_total"], 2, '.', ''));
  859. $pot = $potenciel[0]['potentiel'];
  860. $percent_ca = $ca / $pot * 100;
  861. if ($percent_ca > 200) {
  862. $ca_enplus = $ca - $pot;
  863. $potenciel_maj = $pot - $ca_enplus;
  864. array_push($potentiel_json, (object)array(
  865. 'name' => "CA realise",
  866. 'id' => '' + $ca + '',
  867. 'data' => array($ca_enplus),
  868. ));
  869. } else {
  870. $ca_enplus = $ca - $pot;
  871. $potenciel_maj = $pot - $ca_enplus;
  872. echo $potenciel_maj;
  873. array_push($potentiel_json, (object)array(
  874. 'color' => 'green',
  875. 'name' => "CA realise",
  876. 'id' => '' + $ca + '',
  877. 'data' => array($ca_enplus),
  878. ));
  879. array_push($potentiel_json, (object)array(
  880. 'name' => "Potentiel",
  881. 'id' => '' + $pot + '',
  882. 'data' => array(intval(number_format($potenciel_maj, 2, '.', ''))),
  883. ));
  884. }
  885. } else {
  886. array_push($potentiel_json, (object)array(
  887. 'name' => "Potentiel",
  888. 'id' => 'Aucun Potentiel',
  889. 'data' => array(100),
  890. ));
  891. }
  892. }
  893. $t_potentiel_json = json_encode($potentiel_json);
  894. unset($potentiel_json);
  895. $mois_francais = array(
  896. 1 => 'Jan',
  897. 2 => 'Fev',
  898. 3 => 'Mars',
  899. 4 => 'Avr',
  900. 5 => 'Mai',
  901. 6 => 'Juin',
  902. 7 => 'Juil',
  903. 8 => 'Aout',
  904. 9 => 'Sept',
  905. 10 => 'Oct',
  906. 11 => 'Nov',
  907. 12 => 'Dec'
  908. );
  909. return $this->render('User/index.html.twig', array(
  910. 'Res_CA_obj' => (!empty($caObj)) ? $caObj[0]->getMontantht() : '0.00',
  911. 'ListeTransfos' => $transfo[0],
  912. 'ListeRDV' => $rdvClient[0],
  913. 'Obj_RDV' => $obj_rdv,
  914. 'ListeSimulation' => $simu[0],
  915. 't_ListeProspect' => $t_ListeProspect,
  916. 't_ListePC' => $t_ListePC,
  917. 'tab_mois_fr' => $tab_mois_fr,
  918. 'tab_jours_fr' => $tab_jours_fr,
  919. 'Rdv' => $rdv,
  920. 'Messages' => $mes,
  921. 'fournisseurs' => $fournisseurs,
  922. 'annee_cal' => $annee_cal,
  923. 'mois_cal' => $mois_cal,
  924. 'semaine_cal' => $semaine_cal,
  925. 'mois' => $mois,
  926. 'annee' => $annee,
  927. 'semaine' => $semaine,
  928. 't_potentiel_json' => $t_potentiel_json,
  929. 't_objectif' => $t_objectif,
  930. 't_ca_chart_json' => $t_ca_chart_json,
  931. 't_gp_val_chart_json' => $t_gp_val_chart_json,
  932. 't_gp_client_chart_json' => $t_gp_client_chart_json,
  933. 't_CaFamilleForChart_json' => $t_CaFamilleForChart_json,
  934. 't_seg_client_chart_json' => $t_seg_client_chart_json,
  935. 't_seg_valeur_chart_json' => $t_seg_valeur_chart_json,
  936. 'type' => 'fournisseur',
  937. 't_listeNbCommande' => $t_listeNbCommande,
  938. 't_listeCaSeg' => $t_listeCaSeg,
  939. 't_ListeSeg' => $t_ListeSeg,
  940. 't_ListeGainsPertes' => $t_ListeGainsPertes,
  941. 't_ListeDetail' => $t_ListeDetail,
  942. 't_ListeMois' => $t_ListeMois,
  943. 't_ListeCA' => $t_ListeCA_frn,
  944. 'user' => $this->getUser()->getFamille(),
  945. 'nb_actif' => count($t_listClientActif),
  946. 'nb_nouveau' => count($t_listClientNouveau),
  947. 'nb_perdu' => count($t_listClientPerdu),
  948. 'current_year' => $annee,
  949. 'current_month' => $mois_francais[$mois_valide],
  950. 'current_month_detail' => $MonthValid[0]['note']
  951. ));
  952. unset($t_listClientActif);
  953. unset($t_listClientNouveau);
  954. unset($t_listClientPerdu);
  955. unset($t_ListeSeg);
  956. unset($t_ListeGainsPertes);
  957. unset($t_ListeDetail);
  958. unset($t_ListeCA_frn);
  959. unset($t_ListeMois);
  960. unset($t_listClientPerdu);
  961. unset($t_seg_client_chart_json);
  962. unset($t_seg_valeur_chart_json);
  963. unset($t_CaFamilleForChart_json);
  964. unset($t_ca_chart_json);
  965. unset($t_gp_client_chart_json);
  966. unset($t_objectif);
  967. unset($t_potentiel_json);
  968. }
  969. /**
  970. * @Route("/menu", name="user_menu")
  971. */
  972. public function menuAction()
  973. {
  974. return $this->render('User/menu.html.twig');
  975. }
  976. /**
  977. * @Route("/select", name="select_client")
  978. */
  979. public function selectClientsAction($id, EntityManagerInterface $em)
  980. {
  981. if ($id != 0) {
  982. $clients = $em->getRepository(Client::class)->findMyClients($this->getUser()->getId());
  983. $prospects = $em->getRepository(Client::class)->findMyProsPects($this->getUser()->getId());
  984. } else {
  985. $clients = $em->getRepository(Client::class)->findAllClientsInArray();
  986. $prospects = $em->getRepository(Client::class)->findAllProspectInArray();
  987. }
  988. $form = $this->createForm(ClientProspectType::class);
  989. return $this->render('User/clientsSelectors.html.twig', array(
  990. 'clients' => $clients,
  991. 'prospects' => $prospects,
  992. 'form' => $form->createView(),
  993. ));
  994. }
  995. /* AFFICHAGE DES SELECTEURS UTILISATEURS */
  996. public function selectUtilisateursAction($id, $annee, $mois, $semaine, $route, EntityManagerInterface $em)
  997. {
  998. //RECUPERATION DES UTILISATEURS POUR LISTE DEROULANTE
  999. $utilisateurs = $em->getRepository(Admin::class)->findBy(array('valide' => 1), array('contact' => 'ASC'));
  1000. return $this->render('User/utilisateursSelectors.html.twig', array(
  1001. 'utilisateurs' => $utilisateurs,
  1002. 'id' => $id,
  1003. 'route' => $route,
  1004. 'annee' => $annee,
  1005. 'mois' => $mois,
  1006. 'semaine' => $semaine
  1007. ));
  1008. }
  1009. /* AFFICHAGE DES STATS GLOBALES D'UN UTILISATEUR */
  1010. /**
  1011. * @Route("/rapport_global/{date}/{id}", name="malys_user_globalreport", defaults={"date"=0, "id"=0})
  1012. */
  1013. public function globalReportAction($date, $id, EntityManagerInterface $em)
  1014. {
  1015. /* annee courante par défaut */
  1016. if ($date == 0) {
  1017. $date = date('Y');
  1018. }
  1019. if ($id == 0) {
  1020. $id = $this->getUser()->getId();
  1021. $currentUser = true;
  1022. } else {
  1023. $currentUser = false;
  1024. }
  1025. /* selecteur de date */
  1026. $begin = date("Y", time()) - 3;
  1027. $end = date("Y", time()) + 1;
  1028. /* mois du tableau et service de graph */
  1029. $tab_mois_fr = $this->malysDates->getTabMoisFr();
  1030. // $this->container->get('malys_user.charts');
  1031. // CA GENERE DU MOIS POUR UN COMMERCIAL
  1032. $t_ListeCA = array();
  1033. $ca = $em->getRepository(Clientvente::class)->findCommercialCa($id, $date);
  1034. foreach ($ca as $c) {
  1035. $t_ListeCA[intval($c['le_mois'])] = $c['ca_genere'];
  1036. }
  1037. // CA GENERE PREVISIONNEL
  1038. $t_ListePrev = array();
  1039. $prev = $em->getRepository(Adminprev::class)->findCommercialPrevCa($id, $date);
  1040. foreach ($prev as $p) {
  1041. $t_ListePrev[intval($p['le_mois'])] = $p['montantht'];
  1042. }
  1043. //LISTE PROSPECTION
  1044. $t_ListeProspect = array();
  1045. $pro = $em->getRepository(Client::class)->findListeProspection($id, $date);
  1046. foreach ($pro as $p) {
  1047. $t_ListeProspect[intval($p['le_mois'])][$p[0]->getNote()] = $p['nbprospect'];
  1048. }
  1049. //LISTE SIMULATION
  1050. $t_ListeSimulation = array();
  1051. $sim = $em->getRepository(Adminevent::class)->findCommercialSimulation($id, $date);
  1052. foreach ($sim as $s) {
  1053. $t_ListeSimulation[intval($s['le_mois'])] = $s['nbsimulation'];
  1054. }
  1055. //LISTE RDV CLIENTS
  1056. $t_ListeRDV = array();
  1057. $rdv = $em->getRepository(Adminevent::class)->findMyClientRdv($id, $date);
  1058. foreach ($rdv as $r) {
  1059. $t_ListeRDV[intval($r['le_mois'])] = $r['nbrdv'];
  1060. }
  1061. //LISTE TRANSFOS CLIENTS
  1062. $t_ListeTransfos = array();
  1063. $tra = $em->getRepository(Client::class)->findMyTransfoClient($id, $date);
  1064. foreach ($tra as $t) {
  1065. $t_ListeTransfos[intval($t['le_mois'])] = $t['nbtransfos'];
  1066. }
  1067. /* GRAPH */
  1068. // $objChart = new \Chart(500, 240, "chart_bar_ca_mois_" . $id . "_gd");
  1069. // $objChart->SetHeaderName("Evolution CA " . $date);
  1070. // $objChart->SetY_Barchart_Show_Values(true);
  1071. //
  1072. // for ($i = 1; $i < 13; $i++) {
  1073. // $objChart->AddValue((string)$i, (isset($t_ListeCA[$i])) ? intval($t_ListeCA[$i]) : 0);
  1074. // }
  1075. //
  1076. // $objChart->SetImageDestination("images/graph/");
  1077. // $objChart->CreateChartImage(BAR_CHART);
  1078. return $this->render('User/globalReport.html.twig', array(
  1079. 't_ListeTransfos' => $t_ListeTransfos,
  1080. 't_ListeRDV' => $t_ListeRDV,
  1081. 't_ListeSimulation' => $t_ListeSimulation,
  1082. 't_ListeProspect' => $t_ListeProspect,
  1083. 't_ListePrev' => $t_ListePrev,
  1084. 't_ListeCA' => $t_ListeCA,
  1085. 'tab_mois_fr' => $tab_mois_fr,
  1086. 'date' => $date,
  1087. 'begin' => $begin,
  1088. 'end' => $end,
  1089. 'id' => $id,
  1090. 'currentUser' => $currentUser
  1091. ));
  1092. }
  1093. /**
  1094. * @Route("/rapport_client/{date}", name="malys_user_clientreport", defaults={"date"=0})
  1095. */
  1096. public function clientReportAction($date, EntityManagerInterface $em)
  1097. {
  1098. /* annee courante par défaut */
  1099. if ($date == 0) {
  1100. $date = date('Y');
  1101. }
  1102. /* selecteur de date */
  1103. $begin = date("Y", time()) - 3;
  1104. $end = date("Y", time()) + 1;
  1105. $tab_mois_fr = $this->malysDates->getTabMoisFr();
  1106. $t_ListeCA = array();
  1107. $t_ListeMois = array();
  1108. $t_ListeDetail = array();
  1109. $totalCaGenere = 0;
  1110. $totalCaCommission = 0;
  1111. $ca = $em->getRepository(Clientvente::class)->findCommercialCaParClient($this->getUser()->getId(), $date);
  1112. foreach ($ca as $c) {
  1113. //TABLEAU DETAILLE
  1114. if (!isset($t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])])) {
  1115. $t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])] = array();
  1116. }
  1117. $t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])]['ca_genere'] = number_format($c['ca_genere'], 2, '.', '');
  1118. $t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])]['ca_commission'] = number_format($c['ca_commission'], 2, '.', '');
  1119. $t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])]['solde'] = number_format($c['ca_solde'], 2, '.', '');
  1120. //TABLEAU MOIS PAR MOIS
  1121. if (!isset($t_ListeMois[intval($c['le_mois'])])) {
  1122. $t_ListeMois[intval($c['le_mois'])] = array('ca_genere' => 0, 'ca_commission' => 0, 'solde' => 0);
  1123. }
  1124. $t_ListeMois[intval($c['le_mois'])]['ca_genere'] += number_format($c['ca_genere'], 2, '.', '');
  1125. $t_ListeMois[intval($c['le_mois'])]['ca_commission'] += number_format($c['ca_commission'], 2, '.', '');
  1126. $t_ListeMois[intval($c['le_mois'])]['solde'] += number_format($c['ca_solde'], 2, '.', '');
  1127. $totalCaGenere += number_format($c['ca_genere'], 2, '.', '');
  1128. $totalCaCommission += number_format($c['ca_commission'], 2, '.', '');
  1129. //TABLEAU PAR TYPE DETAIL
  1130. if (!isset($t_ListeDetail[$c[0]->getIdclient()->getNom()])) {
  1131. $t_ListeDetail[$c[0]->getIdclient()->getNom()] = array(
  1132. 'ca_genere' => 0,
  1133. 'ca_commission' => 0,
  1134. 'solde' => 0
  1135. );
  1136. }
  1137. $t_ListeDetail[$c[0]->getIdclient()->getNom()]['ca_genere'] += number_format($c['ca_genere'], 2, '.', '');
  1138. $t_ListeDetail[$c[0]->getIdclient()->getNom()]['ca_commission'] += number_format($c['ca_commission'], 2, '.', '');
  1139. $t_ListeDetail[$c[0]->getIdclient()->getNom()]['solde'] += number_format($c['ca_solde'], 2, '.', '');
  1140. }
  1141. return $this->render('user/clientReport.html.twig', array(
  1142. 'totalCaGenere' => $totalCaGenere,
  1143. 'totalCaCommission' => $totalCaCommission,
  1144. 'tab_mois_fr' => $tab_mois_fr,
  1145. 't_ListeCA' => $t_ListeCA,
  1146. 't_ListeMois' => $t_ListeMois,
  1147. 't_ListeDetail' => $t_ListeDetail,
  1148. 'date' => $date,
  1149. 'begin' => $begin,
  1150. 'end' => $end
  1151. )
  1152. );
  1153. }
  1154. /**
  1155. * @Route("/rapport_liste_clients/{date}/{id}", name="malys_user_commercialreport", defaults={"date"=0, "id"=0})
  1156. */
  1157. public function commercialReportAction($date, $id, Request $request, EntityManagerInterface $em)
  1158. {
  1159. /* AFFICHAGE DES STATS CLIENT D'UN UTILISATEUR */
  1160. /* annee courante par défaut */
  1161. if ($request->get('id')) {
  1162. $id = $request->get('id');
  1163. }
  1164. if ($request->get('vannee')) {
  1165. $date = $request->get('vannee');
  1166. }
  1167. if ($date == 0) {
  1168. $date = date('Y');
  1169. }
  1170. if ($id == 0) {
  1171. $id = $this->getUser()->getId();
  1172. }
  1173. $perf_ca = $request->get('perf_ca', null);
  1174. //echo $perf_ca;
  1175. /* selecteur de date */
  1176. $begin = date("Y", time()) - 3;
  1177. $end = date("Y", time()) + 1;
  1178. $tab_mois_fr = $this->malysDates->getTabMoisFr();
  1179. $t_ListeCA = array();
  1180. $t_ListeMois = array();
  1181. $t_ListeDetail = array();
  1182. $totalCaGenere = 0;
  1183. $totalCaCommission = 0;
  1184. $totalSolde = 0;
  1185. $ca = $em->getRepository(Clientvente::class)->findCommercialCaParClient($id, $date);
  1186. foreach ($ca as $c) {
  1187. //TABLEAU DETAILLE
  1188. if (!isset($t_ListeCA[$c[0]->getIdclient()->getNom()]['idclient'])) {
  1189. $t_ListeCA[$c[0]->getIdclient()->getNom()]['idclient'] = $c[0]->getIdclient()->getId();
  1190. }
  1191. if (!isset($t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])])) {
  1192. $t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])] = array();
  1193. }
  1194. $t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])]['ca_genere'] = number_format($c['ca_genere'], 2, '.', '');
  1195. $t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])]['ca_commission'] = number_format($c['ca_commission'], 2, '.', '');
  1196. $t_ListeCA[$c[0]->getIdclient()->getNom()][intval($c['le_mois'])]['solde'] = number_format($c['ca_solde'], 2, '.', '');
  1197. $t_ListeCA[$c[0]->getIdclient()->getNom()]['cagenere_total'] += number_format($c['ca_genere'], 2, '.', '');
  1198. //TABLEAU MOIS PAR MOIS
  1199. if (!isset($t_ListeMois[intval($c['le_mois'])])) {
  1200. $t_ListeMois[intval($c['le_mois'])] = array('ca_genere' => 0, 'ca_commission' => 0, 'solde' => 0);
  1201. }
  1202. $t_ListeMois[intval($c['le_mois'])]['ca_genere'] += number_format($c['ca_genere'], 2, '.', '');
  1203. $t_ListeMois[intval($c['le_mois'])]['ca_commission'] += number_format($c['ca_commission'], 2, '.', '');
  1204. $t_ListeMois[intval($c['le_mois'])]['solde'] += number_format($c['ca_solde'], 2, '.', '');
  1205. $totalCaGenere += number_format($c['ca_genere'], 2, '.', '');
  1206. $totalCaCommission += number_format($c['ca_commission'], 2, '.', '');
  1207. $totalSolde += number_format($c['ca_solde'], 2, '.', '');
  1208. //TABLEAU PAR TYPE DETAIL
  1209. if (!isset($t_ListeDetail[$c[0]->getIdclient()->getNom()])) {
  1210. $t_ListeDetail[$c[0]->getIdclient()->getNom()] = array(
  1211. 'ca_genere' => 0,
  1212. 'ca_commission' => 0,
  1213. 'solde' => 0
  1214. );
  1215. }
  1216. $t_ListeDetail[$c[0]->getIdclient()->getNom()]['ca_genere'] += number_format($c['ca_genere'], 2, '.', '');
  1217. $t_ListeDetail[$c[0]->getIdclient()->getNom()]['ca_commission'] += number_format($c['ca_commission'], 2, '.', '');
  1218. $t_ListeDetail[$c[0]->getIdclient()->getNom()]['solde'] += number_format($c['ca_solde'], 2, '.', '');
  1219. }
  1220. if ($perf_ca != null) {
  1221. uasort($t_ListeCA, "App\Controller\User\UserController::cmpCa");
  1222. }
  1223. /*echo "<pre>";
  1224. print_r($t_ListeCA);
  1225. echo "</pre>";*/
  1226. return $this->render('User/commercialReport.html.twig', array(
  1227. 'totalCaGenere' => $totalCaGenere,
  1228. 'totalCaCommission' => $totalCaCommission,
  1229. 'totalSolde' => $totalSolde,
  1230. 'tab_mois_fr' => $tab_mois_fr,
  1231. 't_ListeCA' => $t_ListeCA,
  1232. 't_ListeMois' => $t_ListeMois,
  1233. 't_ListeDetail' => $t_ListeDetail,
  1234. 'date' => $date,
  1235. 'begin' => $begin,
  1236. 'end' => $end,
  1237. 'id' => $id
  1238. )
  1239. );
  1240. }
  1241. private static function cmpCa($a, $b)
  1242. {
  1243. if ($a['cagenere_total'] < $b['cagenere_total']) {
  1244. return true;
  1245. }
  1246. return false;
  1247. }
  1248. /**
  1249. * @Route("/rapport_detaille/{annee}/{mois}/{semaine}/{id}", name="malys_user_detailreport", defaults={"semaine"=0, "id"=0})
  1250. */
  1251. public function detailReportAction($annee, $mois, $semaine, $id, Request $request, EntityManagerInterface $em)
  1252. {
  1253. $annee_cal = $annee;
  1254. $mois_cal = $mois;
  1255. $semaine_cal = $semaine;
  1256. if ($id == 0) {
  1257. $id = $this->getUser()->getId();
  1258. $currentUser = true;
  1259. } else {
  1260. $currentUser = false;
  1261. }
  1262. /* SEMAINE PAR DEFAUT */
  1263. if ($semaine == 0) {
  1264. if ($mois != date("n", time())) {
  1265. $semaine = date("W", mktime(0, 0, 0, $mois, 1, $annee));
  1266. } else {
  1267. $semaine = date("W", mktime(0, 0, 0, $mois, date('d'), $annee));
  1268. }
  1269. }
  1270. $tab_mois_fr = $this->malysDates->getTabMoisFr();
  1271. //CA GENERE DU MOIS POUR UN COMMERCIAL
  1272. $ca = $em->getRepository(Clientvente::class)->findCommercialCaInMonth($id, $annee, $mois);
  1273. //OBJECTIF DE CA
  1274. $caObj = $em->getRepository(Adminprev::class)->findCommercialPrevCaInMonth($id, $annee, $mois);
  1275. //RECUPERATION DES COMMISSIONS UTILISATEURS
  1276. $com = $em->getRepository(Clientvente::class)->findCommercialCommission($id, $annee, $mois);
  1277. /* TOTAL COMMISSION */
  1278. $totalCommission = 0;
  1279. foreach ($com as $c) {
  1280. $totalCommission += $c->getMontantht() * $c->getAdmincom() / 100;
  1281. }
  1282. //LISTE PROSPECTION HEBDO
  1283. $t_ListeProspect = array();
  1284. $totalProspect = 0;
  1285. $pro = $em->getRepository(Client::class)->findListeProspectionHebdo($id, $annee, $semaine);
  1286. foreach ($pro as $p) {
  1287. $t_ListeProspect[$p[0]->getNote()] = $p['nbprospect'];
  1288. $totalProspect += $p['nbprospect'];
  1289. }
  1290. //RECUPERATION DES OBJECTIFS RDV
  1291. $rdv = $em->getRepository(Adminprevrdv::class)->findOneBy(array(
  1292. 'idadmin' => $id,
  1293. 'annee' => $annee,
  1294. 'semaine' => $semaine
  1295. ));
  1296. //LISTE SIMULATION HEBDO
  1297. $simu = $em->getRepository(Adminevent::class)->findCommercialSimulationHebdo($id, $annee, $semaine);
  1298. //LISTE RDV CLIENTS
  1299. $rdvClient = $em->getRepository(Adminevent::class)->findMyClientRdvHebdo($id, $annee, $semaine);
  1300. //LISTE TRANSFOS CLIENTS
  1301. $transfo = $em->getRepository(Client::class)->findMyTransfoClientHebdo($id, $annee, $semaine);
  1302. //LISTE DETAILLEE PROSPECTION HEBDO
  1303. $dPro = $em->getRepository(Client::class)->findListeProspectHebdoDetail($id, $annee, $semaine);
  1304. //LISTE SIMULATION HEBDO DETAIL
  1305. $s = $em->getRepository(Adminevent::class)->findCommercialSimulationHebdoDetail($id, $annee, $semaine);
  1306. //LISTE DETAILLEE RDV CLIENTS
  1307. $rdvClientDetail = $em->getRepository(Adminevent::class)->findMyClientRdvHebdoDetail($id, $annee, $semaine);
  1308. //LISTE DETAILLEE TRANSFOS CLIENTS
  1309. $tansfoDet = $em->getRepository(Client::class)->findMyTransfoClientHebdoDetail($id, $annee, $semaine);
  1310. //RECUPERATION DES RELANCES PROSPECTS
  1311. $relances = $em->getRepository(Adminevent::class)->findProspectRelanceHebdo($id, $annee, $semaine);
  1312. //ALL CA FRN BY MONTH/YEAR OF COMMERCIAL
  1313. $getAllCaByMonth = $em->getRepository(Clientvente::class)->getAllCaByMonth(3, $id, "Commercial");
  1314. //RECUPERE LE MOIS VALIDE LE PLUS PROCHE
  1315. $MonthValid = $em->getRepository(Moisvalide::class)->findLastMoisvalide(date("n"), date("Y"));
  1316. $annee = $MonthValid[0]['annee'];
  1317. $mois_valide = $MonthValid[0]['mois'];
  1318. //ALL OBJECTIF BY MONTH/YEAR
  1319. $t_Objectifs = $em->getRepository(Adminprev::class)->getAllPrevCaByMonth($id, "Commercial", $annee);
  1320. $t_objectif = array();
  1321. $obj_total = 0;
  1322. foreach ($t_Objectifs as $key => $item) {
  1323. (intval($item['objectif'] != 0)) ? array_push($t_objectif, intval($item['objectif'])) : array_push($t_objectif, null);
  1324. $obj_total += intval($item['objectif']);
  1325. }
  1326. //création json pour chart CA
  1327. $t_ca_chart = array();
  1328. foreach ($getAllCaByMonth as $key => $item) {
  1329. $t_ca = array();
  1330. $i = 0;
  1331. foreach ($item as $year => $ca) {
  1332. if ($i != 0) {
  1333. (intval($ca) != 0) ? array_push($t_ca, intval($ca)) : array_push($t_ca, null);
  1334. }
  1335. $i++;
  1336. }
  1337. ($item["Annee"] == $annee) ? array_push($t_ca_chart, (object)array(
  1338. 'name' => $item["Annee"],
  1339. 'data' => $t_ca
  1340. )) : array_push($t_ca_chart, (object)array(
  1341. 'name' => $item["Annee"],
  1342. 'visible' => false,
  1343. 'data' => $t_ca
  1344. ));
  1345. }
  1346. array_push($t_ca_chart, (object)array('name' => "Objectifs", 'color' => '#a3dfd9', 'data' => $t_objectif));
  1347. array_push($t_objectif, $obj_total);
  1348. $t_ca_chart_json = json_encode($t_ca_chart);
  1349. unset($t_ca_chart); //Free memoire
  1350. //ALL CA CLIENT BY MONTH/YEAR
  1351. $t_allCaClientByMonth = $em->getRepository(Clientvente::class)->getAllClientsCaLight($annee, null, 'three year', $id, "commercial");
  1352. $t_ListeCaClientForChart = array();
  1353. $t_ListeCaFamilleForChart = array();
  1354. $t_CaFamilleForChart = array();
  1355. // Recuperation tab CAclient/mois et tab CaFamille/mois
  1356. foreach ($t_allCaClientByMonth as $caClient => $item) {
  1357. $yearfr = $item['datefr']->format('Y');
  1358. $monthfr = $item['datefr']->format('n');
  1359. // Si l'année, le mois et le client n'existe pas dans le tableau d'arrivée, on l'ajoute au tableau
  1360. if ($yearfr == date('Y') || $yearfr == date('Y') - 1) {
  1361. if (!isset($t_ListeCaClientForChart[$yearfr][$monthfr][$item['id']])) {
  1362. if ($item['ca_genere'] > 0) {
  1363. $t_ListeCaClientForChart[$yearfr][$monthfr][$item['id']] = array();
  1364. $t_ListeCaClientForChart[$yearfr][$monthfr][$item['id']]['ca_genere'] = number_format((float)$item['ca_genere'], 2, '.', '');
  1365. }
  1366. } else { // Si la case existe déjà
  1367. if ($item['ca_genere'] > 0) {
  1368. $t_ListeCaClientForChart[$yearfr][$monthfr][$item['id']]['ca_genere'] += number_format((float)$item['ca_genere'], 2, '.', '');
  1369. }
  1370. }
  1371. }
  1372. // Si l'année n'existe pas dans le tableau CAfamille d'arrivée, on ajoute la case avec la l'année
  1373. if ($yearfr == date('Y')) {
  1374. if (!isset($t_ListeCaFamilleForChart[$item['famille']])) {
  1375. $t_ListeCaFamilleForChart[$item['famille']] = array();
  1376. $t_ListeCaFamilleForChart[$item['famille']] = number_format((float)$item['ca_genere'], 2, '.', '');
  1377. } else {
  1378. $t_ListeCaFamilleForChart[$item['famille']] += number_format((float)$item['ca_genere'], 2, '.', '');
  1379. }
  1380. }
  1381. }
  1382. unset($t_allCaClientByMonth); //Free memoire
  1383. $t_ca_famille = array();
  1384. foreach ($t_ListeCaFamilleForChart as $key => $value) {
  1385. ($key != "") ? array_push($t_ca_famille, array(
  1386. $key,
  1387. intval($value)
  1388. )) : array_push($t_ca_famille, array("AUTRE", intval($value)));
  1389. }
  1390. // Obtient une liste de colonnes
  1391. $volume = array();
  1392. foreach ($t_ca_famille as $key => $row) {
  1393. $volume[$key] = $row[1];
  1394. $edition[$key] = $row[0];
  1395. }
  1396. // Trie les données par volume décroissant, edition croissant
  1397. // Ajoute $data en tant que dernier paramètre, pour trier par la clé commune
  1398. if ($volume) {
  1399. array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $t_ca_famille);
  1400. }
  1401. array_push($t_CaFamilleForChart, (object)array(
  1402. 'type' => 'pie',
  1403. 'name' => 'Famille',
  1404. 'data' => $t_ca_famille
  1405. ));
  1406. unset($t_ca_famille); // free Memory
  1407. $t_CaFamilleForChart_json = json_encode($t_CaFamilleForChart);
  1408. unset($t_CaFamilleForChart);
  1409. unset($t_ListeCaFamilleForChart);
  1410. $t_gp_val_chart = array();
  1411. $t_gp_client_chart = array();
  1412. $t_ListeGainsPertes = array(
  1413. 0 => array('gain' => array(), 'perte' => array(), 'type' => 'ca'),
  1414. 1 => array('gain' => array(), 'perte' => array(), 'type' => 'client')
  1415. );
  1416. if (isset($t_ListeCaClientForChart[$annee - 1][12])) {
  1417. foreach ($t_ListeCaClientForChart[$annee - 1][12] as $id_client => $ca) {
  1418. (!array_key_exists($id_client, $t_ListeCaClientForChart[$annee][1])) ? $t_ListeCaClientForChart[$annee][1][$id_client] = array('ca_genere' => 0.0) : null;
  1419. }
  1420. }
  1421. foreach ($t_ListeCaClientForChart as $year => $item) {
  1422. foreach ($item as $month => $val) {
  1423. foreach ($val as $id_client => $ca) {
  1424. for ($i = 1; $i < count($item); $i++) {
  1425. if (isset($t_ListeCaClientForChart[$year][$i])) {
  1426. (!array_key_exists($id_client, $t_ListeCaClientForChart[$year][$i])) ? $t_ListeCaClientForChart[$year][$i][$id_client] = array('ca_genere' => 0.0) : null;
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. for ($i = 1; $i <= 12; $i++) {
  1433. (!isset($t_ListeCaClientForChart[$annee][$i])) ? $t_ListeCaClientForChart[$annee][$i] = null : 1;
  1434. }
  1435. ksort($t_ListeCaClientForChart[$annee], SORT_ASC);
  1436. //calcul et recuperation "pertes et gains" total en valeur et client/MOIS
  1437. foreach ($t_ListeCaClientForChart as $year => $item) {
  1438. $t_gains_valeur = array();
  1439. $t_pertes_valeur = array();
  1440. $t_gains_client = array();
  1441. $t_pertes_client = array();
  1442. if ($year == $annee) {
  1443. foreach ($item as $month => $val) {
  1444. $gainsValeur = 0;
  1445. $pertesValeur = 0;
  1446. $gainsClient = 0;
  1447. $pertesClient = 0;
  1448. if ($val != null) {
  1449. foreach ($val as $client => $caClient) {
  1450. $caMoisPrec = 0;
  1451. if ($month != 1) { // Si C'est pas le mois de janvier
  1452. if (isset($item[$month - 1][$client])) {
  1453. $caMoisPrec = $item[$month - 1][$client]['ca_genere'];
  1454. }
  1455. } else { // si c'est janvier => IDEM avec décembre de l'année précédente
  1456. if (isset($t_ListeCaClientForChart[$year - 1][12][$client])) {
  1457. $caMoisPrec = $t_ListeCaClientForChart[$year - 1][12][$client]['ca_genere'];
  1458. }
  1459. }
  1460. $diff = ($caClient['ca_genere']) - ($caMoisPrec); // ON calcul $diff => CA du mois - (Ca du mois-1) [exemple: CAmars - CAfevrier ]
  1461. ($diff < 0) ? $pertesValeur += $diff : $gainsValeur += $diff; // On met a jour Gains et Pertes
  1462. //On calcul $evoCa => (CA du mois - (Ca du mois-1)) / (Ca du mois-1) [exemple: (CAmars - CAfevrier)/CAfevrier ]
  1463. if ($caMoisPrec != 0) {
  1464. $evoCa = (($caClient['ca_genere']) - ($caMoisPrec)) / ($caMoisPrec);
  1465. } else {
  1466. $evoCa = 0;
  1467. }
  1468. // On met a jour Gains et Pertes Client
  1469. if ($evoCa < 0) {
  1470. $pertesClient--;
  1471. }
  1472. if ($evoCa > 0) {
  1473. $gainsClient++;
  1474. }
  1475. }
  1476. } else {
  1477. $gainsClient = null;
  1478. $pertesClient = null;
  1479. $pertesValeur = null;
  1480. $gainsValeur = null;
  1481. }
  1482. array_push($t_gains_valeur, $gainsValeur);
  1483. array_push($t_pertes_valeur, $pertesValeur);
  1484. array_push($t_gains_client, $gainsClient);
  1485. array_push($t_pertes_client, $pertesClient);
  1486. }
  1487. }
  1488. if ($year == $annee) {
  1489. array_push($t_gp_val_chart, (object)array('name' => "Gains", 'data' => $t_gains_valeur)); //Valeur
  1490. array_push($t_gp_val_chart, (object)array(
  1491. 'name' => "Pertes",
  1492. 'data' => $t_pertes_valeur
  1493. )); //Valeur
  1494. array_push($t_gp_client_chart, (object)array(
  1495. 'name' => "Gains",
  1496. 'data' => $t_gains_client
  1497. )); //Client
  1498. array_push($t_gp_client_chart, (object)array(
  1499. 'name' => "Pertes",
  1500. 'data' => $t_pertes_client
  1501. )); //Client
  1502. array_push($t_ListeGainsPertes[0]['gain'], $t_gains_valeur); //Valeur
  1503. array_push($t_ListeGainsPertes[0]['perte'], $t_pertes_valeur); //Valeur
  1504. array_push($t_ListeGainsPertes[1]['gain'], $t_gains_client); //Client
  1505. array_push($t_ListeGainsPertes[1]['perte'], $t_pertes_client); //Client
  1506. }
  1507. }
  1508. $t_gp_val_chart_json = json_encode($t_gp_val_chart);
  1509. $t_gp_client_chart_json = json_encode($t_gp_client_chart);
  1510. /*TABLEAU GAINS PERTES */
  1511. $tab_moy = array('moyValP' => 0, 'moyCliP' => 0, 'moyValG' => 0, 'moyCliG' => 0);
  1512. $next = 0;
  1513. $nbmonth = 0;
  1514. foreach ($t_ListeGainsPertes as $key => $val) {
  1515. if ($val['gain'][0]) {
  1516. foreach ($val['gain'][0] as $k => $value) {
  1517. ($next == 0) ? $tab_moy['moyValG'] += $value : $tab_moy['moyCliG'] += $value;
  1518. ($next == 0) ? $nbmonth++ : null;
  1519. }
  1520. }
  1521. if ($val['perte'][0]) {
  1522. foreach ($val['perte'][0] as $k => $value) {
  1523. ($next == 0) ? $tab_moy['moyValP'] += $value : $tab_moy['moyCliP'] += $value;
  1524. }
  1525. }
  1526. $next++;
  1527. }
  1528. if ($nbmonth != 0) {
  1529. array_push($t_ListeGainsPertes[0]['gain'], $tab_moy['moyValG'] / $nbmonth);
  1530. array_push($t_ListeGainsPertes[0]['perte'], $tab_moy['moyValP'] / $nbmonth);
  1531. array_push($t_ListeGainsPertes[1]['gain'], $tab_moy['moyCliG'] / $nbmonth);
  1532. array_push($t_ListeGainsPertes[1]['perte'], $tab_moy['moyCliP'] / $nbmonth);
  1533. }
  1534. unset($t_gp_val_chart); //Free Memoire
  1535. unset($t_gp_client_chart);
  1536. unset($t_gains_valeur);
  1537. unset($t_pertes_valeur);
  1538. unset($t_gains_client);
  1539. unset($t_pertes_client);
  1540. // Recuperation segClient/mois et segValeur/mois
  1541. $t_seg_client_chart = array();
  1542. $t_seg_valeur_chart = array();
  1543. $t_seg_client = array(
  1544. '0' => array(),
  1545. '1' => array(),
  1546. '2' => array(),
  1547. '3' => array(),
  1548. '4' => array(),
  1549. '5' => array()
  1550. );
  1551. $t_seg_valeur = array(
  1552. '0' => array(),
  1553. '1' => array(),
  1554. '2' => array(),
  1555. '3' => array(),
  1556. '4' => array(),
  1557. '5' => array()
  1558. );
  1559. $t_seg = array(
  1560. 0 => array("palier" => 500, "valeur" => 0, "client" => 0, "name" => '0-500'),
  1561. 1 => array("palier" => 1500, "valeur" => 0, "client" => 0, "name" => '500-1500'),
  1562. 2 => array("palier" => 3000, "valeur" => 0, "client" => 0, "name" => '1500-3000'),
  1563. 3 => array("palier" => 9000, "valeur" => 0, "client" => 0, "name" => '3000-9000'),
  1564. 4 => array("palier" => 20000, "valeur" => 0, "client" => 0, "name" => '9000-20000'),
  1565. 5 => array("valeur" => 0, "client" => 0, "name" => '>20000'),
  1566. );
  1567. $Liste_client_groupe1 = array($year => array());
  1568. // On recupere les valeurs de segmentation
  1569. foreach ($t_ListeCaClientForChart as $year => $item) {
  1570. if ($year == $annee) {
  1571. foreach ($item as $month => $val) {
  1572. for ($i = 0; $i < count($t_seg); $i++) {
  1573. $t_seg[$i]["valeur"] = 0;
  1574. $t_seg[$i]["client"] = 0;
  1575. }
  1576. (!isset($Liste_client_groupe1[$year][$month])) ? $Liste_client_groupe1[$year][$month] = array() : 1;
  1577. if ($val != null) {
  1578. foreach ($val as $client => $caClient) {
  1579. //Récupération des valeurs de segementation
  1580. if ($caClient['ca_genere'] > 1 && $caClient['ca_genere'] <= $t_seg[0]["palier"]) {
  1581. $t_seg[0]["valeur"] += $caClient['ca_genere'];
  1582. $t_seg[0]["client"] += 1;
  1583. //TODO EXTRACT LIST OF CLIENT BY GROUPE AND BY MONTH
  1584. array_push($Liste_client_groupe1[$year][$month], $client);
  1585. } else if ($caClient['ca_genere'] > $t_seg[0]["palier"] && $caClient['ca_genere'] <= $t_seg[1]["palier"]) {
  1586. $t_seg[1]["valeur"] += $caClient['ca_genere'];
  1587. $t_seg[1]["client"] += 1;
  1588. } else if ($caClient['ca_genere'] > $t_seg[1]["palier"] && $caClient['ca_genere'] <= $t_seg[2]["palier"]) {
  1589. $t_seg[2]["valeur"] += $caClient['ca_genere'];
  1590. $t_seg[2]["client"] += 1;
  1591. } else if ($caClient['ca_genere'] > $t_seg[2]["palier"] && $caClient['ca_genere'] <= $t_seg[3]["palier"]) {
  1592. $t_seg[3]["valeur"] += $caClient['ca_genere'];
  1593. $t_seg[3]["client"] += 1;
  1594. } else if ($caClient['ca_genere'] > $t_seg[3]["palier"] && $caClient['ca_genere'] <= $t_seg[4]["palier"]) {
  1595. $t_seg[4]["valeur"] += $caClient['ca_genere'];
  1596. $t_seg[4]["client"] += 1;
  1597. } else if ($caClient['ca_genere'] > $t_seg[4]["palier"]) {
  1598. $t_seg[5]["valeur"] += $caClient['ca_genere'];
  1599. $t_seg[5]["client"] += 1;
  1600. }
  1601. }
  1602. }
  1603. foreach ($t_seg as $key => $value) {
  1604. if ($year == $annee) {
  1605. for ($i = 0; $i < 6; $i++) {
  1606. if ($key == $i) {
  1607. array_push($t_seg_client[$i], $value['client']);
  1608. array_push($t_seg_valeur[$i], $value['valeur']);
  1609. }
  1610. }
  1611. }
  1612. }
  1613. }
  1614. }
  1615. }
  1616. $t_ListeSeg = array();
  1617. array_push($t_ListeSeg, $t_seg_client);
  1618. array_push($t_ListeSeg, $t_seg_valeur);
  1619. foreach ($t_ListeSeg as $key => $val) {
  1620. foreach ($val as $k => $value) {
  1621. $total = 0;
  1622. for ($i = 0; $i < count($value); $i++) {
  1623. $total += $value[$i];
  1624. }
  1625. if ($key == 1) {
  1626. $t_ListeSeg[$key][$k]['total_group'] = $total;
  1627. } else {
  1628. (count($value) != 0) ? $t_ListeSeg[$key][$k]['total_group'] = ($total / count($value)) : null;
  1629. }
  1630. for ($j = 0; $j < count($t_seg); $j++) {
  1631. $t_ListeSeg[$key][$j]['nom'] = $t_seg[$j]['name'];
  1632. }
  1633. }
  1634. }
  1635. $t_listeNbCommande = array();
  1636. $t_listeCaSeg = array();
  1637. for ($j = 0; $j < 12; $j++) {
  1638. $total_client = 0;
  1639. $total_ca = 0;
  1640. foreach ($t_ListeSeg[0] as $key => $val) {
  1641. (isset($val[$j])) ? $total_client += $val[$j] : null;
  1642. }
  1643. array_push($t_listeNbCommande, $total_client);
  1644. foreach ($t_ListeSeg[1] as $key => $val) {
  1645. (isset($val[$j])) ? $total_ca += $val[$j] : null;
  1646. }
  1647. array_push($t_listeCaSeg, $total_ca);
  1648. }
  1649. for ($j = 5; $j > -1; $j--) {
  1650. array_push($t_seg_client_chart, (object)array(
  1651. 'type' => "column",
  1652. 'name' => $t_seg[$j]['name'],
  1653. 'data' => $t_seg_client[$j],
  1654. 'id' => $t_seg[$j]['name'] . 'c',
  1655. )
  1656. );
  1657. array_push($t_seg_valeur_chart, (object)array(
  1658. 'type' => "column",
  1659. 'name' => $t_seg[$j]['name'],
  1660. 'data' => $t_seg_valeur[$j],
  1661. 'id' => $t_seg[$j]['name'] . 'v',
  1662. ));
  1663. }
  1664. for ($j = 5; $j > -1; $j--) {
  1665. array_push($t_seg_client_chart, (object)array(
  1666. 'name' => 'seg1->',
  1667. 'id' => $t_seg[$j]['name'] . 'cc',
  1668. 'showInLegend' => false,
  1669. 'color' => 'red',
  1670. 'lineWidth' => 1,
  1671. 'marker' => (object)array(
  1672. 'lineWidth' => 0.1,
  1673. 'lineColor' => 'Highcharts.getOptions().colors[4]',
  1674. 'fillColor' => "white",
  1675. "radius" => 2,
  1676. 'enabled' => true
  1677. ),
  1678. 'data' => $t_seg_client[$j]
  1679. ));
  1680. array_push($t_seg_valeur_chart, (object)array(
  1681. 'name' => "seg1->",
  1682. 'id' => $t_seg[$j]['name'] . 'vv',
  1683. 'showInLegend' => false,
  1684. 'color' => 'red',
  1685. 'lineWidth' => 1,
  1686. 'marker' => (object)array(
  1687. 'lineWidth' => 0.1,
  1688. 'lineColor' => 'Highcharts.getOptions().colors[4]',
  1689. 'fillColor' => "white",
  1690. "radius" => 2,
  1691. 'enabled' => true
  1692. ),
  1693. 'data' => $t_seg_valeur[$j]
  1694. ));
  1695. }
  1696. $t_seg_client_chart_json = json_encode($t_seg_client_chart);
  1697. $t_seg_valeur_chart_json = json_encode($t_seg_valeur_chart);
  1698. unset($t_seg);
  1699. unset($t_seg_client_chart);
  1700. unset($t_seg_client); //free Memory
  1701. unset($t_seg_valeur_chart);
  1702. unset($t_seg_valeur); //free Memory
  1703. // Recupération informations pour tableau fournisseurs global
  1704. /* TRAITEMENT FORMULAIRE ET VALEURS PAR DEFAUT */
  1705. $year = $request->get('year', date('Y'));
  1706. $source = $request->get('source', null) == '' ? null : $request->get('source', null);
  1707. $perf_ca = $request->get('perf_ca', null);
  1708. $type = 'fournisseur';
  1709. /* GET CA */
  1710. $cv = $em->getRepository(Clientvente::class)->getAllFournisseursCa($year, $source, "three year", $id, "commercial");
  1711. $t_ListeCA_frn = array();
  1712. $t_ListeMois = array();
  1713. $t_ListeDetail = array();
  1714. foreach ($cv as $c) {
  1715. $mois = intval($c[0]['datefr']->format('m'));
  1716. $yeartraitement = intval($c[0]['datefr']->format('Y'));
  1717. $id_frn = $c['id'];
  1718. //TABLEAU ANNNEE TOTAUX
  1719. if (!isset($t_ListeMois[$yeartraitement])) {
  1720. $t_ListeMois[$yeartraitement] = array(
  1721. 'cagenere_total' => 0,
  1722. 'cacommission_total' => 0,
  1723. 'solde_total' => 0
  1724. );
  1725. }
  1726. //TABLEAU DETAILLE
  1727. if (!isset($t_ListeCA_frn[$yeartraitement][$id_frn])) {
  1728. $t_ListeCA_frn[$yeartraitement][$id_frn] = array(
  1729. 'cagenere_total' => 0,
  1730. 'cacommission_total' => 0,
  1731. 'solde_total' => 0
  1732. );
  1733. }
  1734. $t_ListeCA_frn[$yeartraitement][$id_frn][$mois]['ca_genere'] = number_format($c['ca_genere'], 2, '.', '');
  1735. $t_ListeCA_frn[$yeartraitement][$id_frn][$mois]['ca_commission'] = number_format($c['ca_commission'], 2, '.', '');
  1736. $t_ListeCA_frn[$yeartraitement][$id_frn][$mois]['solde'] = number_format($c['ca_solde'], 2, '.', '');
  1737. $t_ListeCA_frn[$yeartraitement][$id_frn]['id' . $type] = $c['id'];
  1738. $t_ListeCA_frn[$yeartraitement][$id_frn]['nom'] = $c['nom'];
  1739. $t_ListeCA_frn[$yeartraitement][$id_frn]['cagenere_total'] += number_format($c['ca_genere'], 2, '.', '');
  1740. $t_ListeCA_frn[$yeartraitement][$id_frn]['cacommission_total'] += number_format($c['ca_commission'], 2, '.', '');
  1741. $t_ListeCA_frn[$yeartraitement][$id_frn]['solde_total'] += number_format($c['ca_solde'], 2, '.', '');
  1742. $t_ListeCA_frn[$yeartraitement][$id_frn]['source'] = $c['source'];
  1743. //TABLEAU ANNEE MOIS PAR MOIS
  1744. if (!isset($t_ListeMois[$yeartraitement][$mois])) {
  1745. $t_ListeMois[$yeartraitement][$mois] = array(
  1746. 'ca_genere' => 0,
  1747. 'ca_commission' => 0,
  1748. 'solde' => 0
  1749. );
  1750. }
  1751. $t_ListeMois[$yeartraitement][$mois]['ca_genere'] += number_format($c['ca_genere'], 2, '.', '');
  1752. $t_ListeMois[$yeartraitement][$mois]['ca_commission'] += number_format($c['ca_commission'], 2, '.', '');
  1753. $t_ListeMois[$yeartraitement][$mois]['solde'] += number_format($c['ca_solde'], 2, '.', '');
  1754. //TEABLEAU TOTAL
  1755. $t_ListeMois[$yeartraitement]['cagenere_total'] += number_format($c['ca_genere'], 2, '.', '');
  1756. $t_ListeMois[$yeartraitement]['cacommission_total'] += number_format($c['ca_commission'], 2, '.', '');
  1757. $t_ListeMois[$yeartraitement]['solde_total'] += number_format($c['ca_solde'], 2, '.', '');
  1758. //TABLEAU PAR TYPE DETAIL
  1759. if (!isset($t_ListeDetail[$yeartraitement][$id_frn])) {
  1760. $t_ListeDetail[$yeartraitement][$id_frn] = array(
  1761. 'ca_genere' => 0,
  1762. 'ca_commission' => 0,
  1763. 'solde' => 0
  1764. );
  1765. }
  1766. $t_ListeDetail[$yeartraitement][$id_frn]['ca_genere'] += number_format($c['ca_genere'], 2, '.', '');
  1767. $t_ListeDetail[$yeartraitement][$id_frn]['ca_commission'] += number_format($c['ca_commission'], 2, '.', '');
  1768. $t_ListeDetail[$yeartraitement][$id_frn]['solde'] += number_format($c['ca_solde'], 2, '.', '');
  1769. $t_ListeDetail[$yeartraitement][$id_frn]['source'] = $c['source'];
  1770. }
  1771. if ($perf_ca != null) {
  1772. uasort($t_ListeCA, "App\\Controller\\Marketing::cmpCa");
  1773. }
  1774. return $this->render('User/detailReport.html.twig', array(
  1775. 'ListeRelance' => $relances[0],
  1776. 'ListeSimulationDet' => $s,
  1777. 't_prospect_note' => Tools::getNote(),
  1778. 'ListeDetProspect' => $dPro,
  1779. 'ListeDetTransfos' => $tansfoDet,
  1780. 'ListeTransfos' => $transfo[0],
  1781. 'ListeDetRDV' => $rdvClientDetail,
  1782. 'ListeRDV' => $rdvClient[0],
  1783. 'ListeSimulation' => $simu[0],
  1784. 'Obj_RDV' => $rdv,
  1785. 'Res_CA' => (!empty($ca) && isset($ca[0]['ca_genere'])) ? $ca[0]['ca_genere'] : '0.00',
  1786. 'Res_CA_obj' => (!empty($caObj)) ? $caObj[0]->getMontantht() : '0.00',
  1787. 'totalProspect' => $totalProspect,
  1788. 't_ListeProspect' => $t_ListeProspect,
  1789. 'Commissions' => $com,
  1790. 'totalCommission' => $totalCommission,
  1791. 'tab_mois_fr' => $tab_mois_fr,
  1792. 'mois_cal' => $mois_cal,
  1793. 'annee_cal' => $annee_cal,
  1794. 'semaine_cal' => $semaine_cal,
  1795. 'mois' => $mois,
  1796. 'annee' => $annee,
  1797. 'semaine' => $semaine,
  1798. 'id' => $id,
  1799. 'currentUser' => $currentUser,
  1800. 't_objectif' => $t_objectif,
  1801. 't_ca_chart_json' => $t_ca_chart_json,
  1802. 'user' => $this->getUser()->getFamille(),
  1803. 't_ListeSeg' => $t_ListeSeg,
  1804. 't_ListeGainsPertes' => $t_ListeGainsPertes,
  1805. 't_ListeDetail' => $t_ListeDetail,
  1806. 't_ListeMois' => $t_ListeMois,
  1807. 't_ListeCA' => $t_ListeCA_frn,
  1808. 't_ca_chart_json' => $t_ca_chart_json,
  1809. 't_gp_val_chart_json' => $t_gp_val_chart_json,
  1810. 't_gp_client_chart_json' => $t_gp_client_chart_json,
  1811. 't_CaFamilleForChart_json' => $t_CaFamilleForChart_json,
  1812. 't_seg_client_chart_json' => $t_seg_client_chart_json,
  1813. 't_seg_valeur_chart_json' => $t_seg_valeur_chart_json,
  1814. 'type' => 'fournisseur',
  1815. 't_listeNbCommande' => $t_listeNbCommande,
  1816. 't_listeCaSeg' => $t_listeCaSeg,
  1817. ));
  1818. }
  1819. public function calMonthAction($mois, $annee, $semaine, $route, $id = 0)
  1820. {
  1821. if ($id == 0) {
  1822. $currentUser = true;
  1823. } else {
  1824. $currentUser = false;
  1825. }
  1826. //valeurs par defaut pour le calendrier
  1827. $mois = $mois == "" ? date("n", mktime(0, 0, 0, date("m"), date("d"), $annee)) : $mois;
  1828. $annee = $annee == "" ? date("Y", mktime(0, 0, 0, date("m"), date("d"), $annee)) : $annee;
  1829. //initialisation txt fran�ais
  1830. $mois_nom = array(
  1831. "Janvier",
  1832. "Février",
  1833. "Mars",
  1834. "Avril",
  1835. "Mai",
  1836. "Juin",
  1837. "Juillet",
  1838. "Août",
  1839. "Septembre",
  1840. "Octobre",
  1841. "Novembre",
  1842. "Décembre"
  1843. );
  1844. //initialisation des dates
  1845. $premierj = date("w", mktime(0, 0, 0, $mois, 1, $annee));
  1846. $moisnj = date("t", mktime(0, 0, 0, $mois, 1, $annee));
  1847. //initialisation des donn�es tableau
  1848. if ($premierj == 0) {
  1849. $premierj = 7;
  1850. }
  1851. //nombre de case du calendrier
  1852. $nbcases = ($moisnj + $premierj - 1);
  1853. //nombre de lignes du calendrier
  1854. $nblignes = ceil($nbcases / 7);
  1855. //liens précédents & suivant
  1856. $mois_pre = $mois == 1 ? 12 : ($mois - 1);
  1857. $mois_suiv = $mois == 12 ? 1 : ($mois + 1);
  1858. $annee_prev = $mois == 1 ? $annee - 1 : $annee;
  1859. $annee_next = $mois == 12 ? $annee + 1 : $annee;
  1860. //CONSTRUCTION DU TABLEAU
  1861. $tab_html = "<table border='0' width='100%' cellspacing='0' cellpadding='0' align='center' class='Calendrier_fond'>";
  1862. //LIGNES DE LA NAVIGATION MOIS
  1863. $tab_html .= "<tr>";
  1864. $tab_html .= "<td>";
  1865. $tab_html .= "<table width='100%' border='0' cellspacing='0' cellpadding='3' class='Calendrier_titre'>";
  1866. $tab_html .= "<tr>";
  1867. if ($currentUser) {
  1868. $tab_html .= "<td width='30'><a href='" . $this->generateUrl($route, array(
  1869. 'annee' => $annee_prev,
  1870. 'mois' => $mois_pre
  1871. )) . "'>&lt;&lt;</a></td>";
  1872. } else {
  1873. $tab_html .= "<td width='30'><a href='" . $this->generateUrl($route, array(
  1874. 'annee' => $annee_prev,
  1875. 'mois' => $mois_pre,
  1876. 'id' => $id
  1877. )) . "'>&lt;&lt;</a></td>";
  1878. }
  1879. $tab_html .= "<td align='center'>" . $mois_nom[$mois - 1] . " " . $annee . "</td>";
  1880. if ($currentUser) {
  1881. $tab_html .= "<td width='30' align='right'><a href='" . $this->generateUrl($route, array(
  1882. 'annee' => $annee_next,
  1883. 'mois' => $mois_suiv
  1884. )) . "'>&gt;&gt;</a></td>";
  1885. } else {
  1886. $tab_html .= "<td width='30' align='right'><a href='" . $this->generateUrl($route, array(
  1887. 'annee' => $annee_next,
  1888. 'mois' => $mois_suiv,
  1889. 'id' => $id
  1890. )) . "'>&gt;&gt;</a></td>";
  1891. }
  1892. $tab_html .= "</tr>";
  1893. $tab_html .= "</table>";
  1894. $tab_html .= "</td>";
  1895. $tab_html .= "</tr>";
  1896. //LIGNES DU CALENDRIER
  1897. $tab_html .= "<tr>";
  1898. $tab_html .= "<td>";
  1899. $tab_html .= "<table width='100%' border='0' cellspacing='0' cellpadding='2' class='Calendrier_jours'>";
  1900. $tab_html .= "<tr>";
  1901. $tab_html .= "<td width='23'>&nbsp;</td>";
  1902. $tab_html .= "<td width='23'>L</td>";
  1903. $tab_html .= "<td width='23'>M</td>";
  1904. $tab_html .= "<td width='23'>M</td>";
  1905. $tab_html .= "<td width='23'>J</td>";
  1906. $tab_html .= "<td width='23'>V</td>";
  1907. $tab_html .= "<td width='23'>S</td>";
  1908. $tab_html .= "<td width='23'>D</td>";
  1909. $tab_html .= "</tr>";
  1910. //initialisation du compteur de case
  1911. $compteurj = 1;
  1912. //ecriture des cases
  1913. for ($i = 1; $i < ($nblignes + 1); $i++) {
  1914. $tab_html .= "<tr>";
  1915. //definition de la semaine
  1916. if ($i == 1) {
  1917. $numsemaine = intval(date("W", mktime(0, 0, 0, $mois, 1, $annee)));
  1918. } else {
  1919. $numsemaine = intval(date("W", mktime(0, 0, 0, $mois, $compteurj - $premierj + 1, $annee)));
  1920. }
  1921. if ($currentUser) {
  1922. $tab_html .= "<td width='23' " . (($semaine == $numsemaine) ? "class='Calendrier_LaSemaine'" : "") . "><a href='" . $this->generateUrl($route, array(
  1923. 'annee' => $annee,
  1924. 'mois' => $mois,
  1925. 'semaine' => $numsemaine
  1926. )) . "'>" . $numsemaine . "</a></td>";
  1927. } else {
  1928. $tab_html .= "<td width='23' " . (($semaine == $numsemaine) ? "class='Calendrier_LaSemaine'" : "") . "><a href='" . $this->generateUrl($route, array(
  1929. 'annee' => $annee,
  1930. 'mois' => $mois,
  1931. 'semaine' => $numsemaine,
  1932. 'id' => $id
  1933. )) . "'>" . $numsemaine . "</a></td>";
  1934. }
  1935. for ($j = 1; $j < 8; $j++) {
  1936. if (($compteurj >= $premierj) && ($compteurj <= ($moisnj + $premierj - 1))) {
  1937. $vclass = (($compteurj - $premierj + 1) . "/" . $mois . "/" . $annee == date("j/m/Y")) ? " class='Calendrier_LeJour'" : "";
  1938. $tab_html .= "<td " . $vclass . ">" . ($compteurj - $premierj + 1) . "</td>";
  1939. } else {
  1940. $tab_html .= "<td>&nbsp;</td>";
  1941. }
  1942. $compteurj++;
  1943. }
  1944. $tab_html .= "</tr>";
  1945. }
  1946. $tab_html .= "</table>";
  1947. $tab_html .= "</td>";
  1948. $tab_html .= "</tr>";
  1949. $tab_html .= "</table>";
  1950. //return response
  1951. $response = new \Symfony\Component\HttpFoundation\Response;
  1952. $response->setContent($tab_html);
  1953. return $response;
  1954. }
  1955. /**
  1956. * @Route("/planning/{annee}/{mois}/{semaine}", name="malys_user_planning", defaults={"semaine"=0})
  1957. */
  1958. public function planningAction($annee, $mois, $semaine, EntityManagerInterface $em)
  1959. {
  1960. if ($semaine == 0) {
  1961. $semaine = date('W', mktime(0, 0, 0, $mois, 1, $annee));
  1962. }
  1963. $tab_mois_fr = $this->malysDates->getTabMoisFr();
  1964. $tab_jours_fr = $this->malysDates->getTabJoursFr();
  1965. //AFFICHAGE DES RDV DE LA SEMAINE
  1966. $rdv = $em->getRepository(Adminevent::class)->findMyRdvHebdo($this->getUser()->getId(), $annee, $semaine);
  1967. return $this->render('User/planning.html.twig', array(
  1968. 'tab_mois_fr' => $tab_mois_fr,
  1969. 'tab_jours_fr' => $tab_jours_fr,
  1970. 'Rdv' => $rdv,
  1971. 'annee' => $annee,
  1972. 'mois' => $mois,
  1973. 'semaine' => $semaine,
  1974. ));
  1975. }
  1976. /**
  1977. * @Route("/messages", name="malys_user_messages")
  1978. */
  1979. public function messagesAction(EntityManagerInterface $em)
  1980. {
  1981. //RECUPERATION DE TOUS MES MESSAGES
  1982. $mes = $em->getRepository(Messages::class)->findMyMessages($this->getUser()->getId());
  1983. return $this->render('User/messages.html.twig', array('Messages' => $mes));
  1984. }
  1985. /**
  1986. * @Route("/message_lu/{id}", name="malys_user_readmessage")
  1987. */
  1988. public function readMessageAction($id, EntityManagerInterface $em)
  1989. {
  1990. $message = $em->getRepository(Messages::class)->find($id);
  1991. $message->setLu(1);
  1992. $message->setDatelufr(new \DateTime('now'));
  1993. $em->flush();
  1994. return $this->redirect($this->generateUrl('malys_user_messages'));
  1995. }
  1996. /**
  1997. * @Route("/rapport/{id}", name="malys_user_rapport", defaults={"id"=0})
  1998. */
  1999. public function rapportAction($id)
  2000. {
  2001. ($id == 0) ? ($id = '') : ($id);
  2002. return $this->render('User/rapport.html.twig', array('id' => $id));
  2003. }
  2004. }