src/Controller/DefaultController.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AbsenceCounter;
  4. use App\Entity\AbsenceCounterTeam;
  5. use App\Entity\Client\Client;
  6. use App\Entity\Collaborator;
  7. use App\Entity\DeliveryAddress;
  8. use App\Entity\Inventory\InventoryOrder;
  9. use App\Entity\Inventory\InventoryStock;
  10. use App\Entity\Invoicing\Credit;
  11. use App\Entity\Invoicing\Invoice;
  12. use App\Entity\Opportunity\Activity;
  13. use App\Entity\Opportunity\Opportunity;
  14. use App\Entity\Project\Project;
  15. use App\Entity\Project\Task;
  16. use App\Entity\RH\Absence;
  17. use App\Entity\RH\Expense;
  18. use App\Entity\Supplier\SupplierCommand;
  19. use App\Manager\Inventory\InventoryOrderManager;
  20. use App\Manager\RH\ScoreManager;
  21. use App\Repository\Supplier\SupplierCommandRepository;
  22. use App\Repository\Supplier\SupplierShippingNotificationRepository;
  23. use App\Utils\ClassUtils;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  26. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  27. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  28. use Symfony\Component\Finder\Exception\AccessDeniedException;
  29. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  30. use Symfony\Component\HttpFoundation\Request;
  31. use Symfony\Component\HttpFoundation\Response;
  32. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  33. use Symfony\Component\Mailer\MailerInterface;
  34. use Symfony\Component\Mime\Address;
  35. use Symfony\Component\Mime\Email;
  36. use Symfony\Component\Routing\Annotation\Route;
  37. use Symfony\Component\Translation\Loader\XliffFileLoader;
  38. use Symfony\Component\Yaml\Yaml;
  39. use Translation\Bundle\Catalogue\CatalogueFetcher;
  40. use Translation\Bundle\Catalogue\CatalogueManager;
  41. use Translation\Bundle\Model\CatalogueMessage;
  42. use Translation\Bundle\Service\CacheClearer;
  43. use Translation\Bundle\Service\ConfigurationManager;
  44. class DefaultController extends AbstractController
  45. {
  46.     /**
  47.      * @Route("/", name="app_homepage")
  48.      */
  49.     public function index(ScoreManager $managerSupplierCommandRepository $supplierCommandRepositorySupplierShippingNotificationRepository $notifRepo): Response
  50.     {
  51.         $myCollab $this->getUser()->getCollaborator();
  52.         $total_collab         $manager->getRepository(Collaborator::class)->countEnabled();
  53.         $total_absence        $manager->getRepository(Absence::class)->countInFuture($myCollab);
  54.         $total_expense_report $manager->getRepository(Expense::class)->totalByYearAndCollab($myCollab);
  55.         $today_absences       $manager->getRepository(Absence::class)->getByCollaboratorAndDay(date('Ymd'), null, [Absence::VALID]);
  56.         $collab_to_deleg      $manager->getRepository(Collaborator::class)->getMyDelegationsForToday($myCollab);
  57.         $hasDelegation        $manager->getRepository(Collaborator::class)->hasDelegateForToday($myCollab);
  58.         $opportunities             $manager->getRepository(Opportunity::class)->findMyOpportunitiesNotClosed($myCollab);
  59.         $activities                $manager->getRepository(Activity::class)->findMyActivities($myCollab);
  60.         $commandsToReview $supplierCommandRepository->findBy(['reviewer' => $this->getUser()->getCollaborator(), 'status' => SupplierCommand::COMMAND_REVIEW]);
  61.         $demandsToReview  $supplierCommandRepository->findBy(['reviewer' => $this->getUser()->getCollaborator(), 'demandStatus' => SupplierCommand::DEMAND_REVIEW]);
  62.         $shippingNotifications $notifRepo->findBy(['collaborator' => $this->getUser()->getCollaborator(), 'hasBeenSeen' => false]);
  63.         $commandToValidate null;
  64.         if($this->isGranted('ROLE_ADMIN')) {
  65.             $commandToValidate $supplierCommandRepository->findBy(['status' => SupplierCommand::COMMAND_AWAIT_VALID]);
  66.             $commandToValidate count($commandToValidate) > $commandToValidate null;
  67.         }
  68.         return $this->render('default/index.html.twig', [
  69.             'total_collab'         => $total_collab,
  70.             'total_absence'        => $total_absence,
  71.             'total_expense_report' => $total_expense_report,
  72.             'today_absences'       => $today_absences,
  73.             'activities'                => $activities,
  74.             'collab_to_deleg'      => $collab_to_deleg,
  75.             'hasDelegation'        => $hasDelegation,
  76.             'opportunities'             => $opportunities,
  77.             'restToScored'         => $manager->getJaugeCollab(),
  78.             'holidays' => array_map(function ($date) {
  79.                 return $date->format('Ymd');
  80.             }, ClassUtils::getPublicHolidays(nullfalse)),
  81.             'commandsToReview'       => count($commandsToReview) > $commandsToReview null,
  82.             'demandsToReview'        => count($demandsToReview)  > $demandsToReview  null,
  83.             'commandToValidate'      => $commandToValidate,
  84.             'shippingNotifications'  => count($shippingNotifications) > $shippingNotifications  null,
  85.             'orders_to_prepare' => $manager->getRepository(InventoryOrder::class)->getToPrepare($this->getUser()->getCollaborator()),
  86.             'orders_blocked' => $manager->getRepository(InventoryOrder::class)->getBlocked($this->getUser()->getCollaborator()),
  87.             'orders_prepared' => $manager->getRepository(InventoryOrder::class)->getPrepared($this->getUser()->getCollaborator()),
  88.             'stocks_to_valid'=> $manager->getRepository(DeliveryAddress::class)->getStocksToValidate($this->getUser()->getCollaborator()),
  89.         ]);
  90.     }
  91.     /**
  92.      * @Route("/tableau-de-bord-ca", name="dashboard_ca")
  93.      */
  94.     public function dashboard_ca(EntityManagerInterface $em): Response
  95.     {
  96.         if(!$this->getUser()->getCollaborator()->getViewFinancialDashboard())
  97.         {
  98.             $this->addFlash('danger''Vous n\'avez pas les droits pour accéder à cette page');
  99.             return $this->redirectToRoute('app_homepage');
  100.         }
  101.         return $this->render('default/dashboard_ca.html.twig', [
  102.             'clients'=>$em->getRepository(Client::class)->findBy(['enabled'=>true])
  103.         ]);
  104.     }
  105.     /**
  106.      * @Route("/stat_ca", name="app_dashboard_stat_ca", options={"expose"=true})
  107.      */
  108.     public function statCaAction(Request $request,EntityManagerInterface $em)
  109.     {
  110.         $format_cas=[];
  111.         $total_ca=0;
  112.         //period1
  113.         list($start,$end)=explode(' - ',$request->request->get('period1'));
  114.         $start=\DateTime::createFromFormat('d/m/Y',$start);
  115.         $end=\DateTime::createFromFormat('d/m/Y',$end);
  116.         $cas=$em->getRepository(Invoice::class)->findCAByMonth($start,$end,$request->request->get('client'));
  117.         $cas=$em->getRepository(Credit::class)->findCAByMonth($start,$end,$cas,$request->request->get('client'));
  118.         foreach ($cas as $key=>$ca){
  119.             $total_ca+=$ca;
  120.             $month=new \DateTime($key.'01');
  121.             $format_cas[$month->format('m/Y')]=$ca;
  122.         }
  123.         return $this->render(
  124.             'default/stat_ca.html.twig',
  125.             [
  126.             'statsCa'=>json_encode($format_cas),
  127.             'total_ca'=>$total_ca,
  128.             /*'statsCa2'=>json_encode($format_cas2),
  129.             'total_ca2'=>$total_ca2,
  130.             'is_compare'=> $request->request->get('year_compare'),*/
  131.             ]
  132.         );
  133.     }
  134.     /**
  135.      * @Route("/comming_soon", name="to_do")
  136.      * @Route("/purchases/comming_soon", name="to_do_supplier")
  137.      */
  138.     public function toDo(): Response
  139.     {
  140.         return $this->render('default/to_do.html.twig', [
  141.             'controller_name' => 'DefaultController',
  142.         ]);
  143.     }
  144.     /**
  145.      * @Route("/clearTrad", name="admin_clear_trad", methods={"GET","POST"},options={"expose"=true})
  146.      * @IsGranted("ROLE_ADMIN")
  147.      */
  148.     public function clearTrad(Request $requestCacheClearer $cacheClearer)
  149.     {
  150.         $cacheClearer->clearAndWarmUp($request->getLocale());
  151.         return $this->redirect($request->headers->get('referer'));
  152.     }
  153.     /**
  154.      * @Route("/public/translation.js", name="translation_js")
  155.      */
  156.     public function translationJs(Request $request,$projectDir,  ConfigurationManager $configurationManager,CatalogueManager $catalogueManager,CatalogueFetcher $catalogueFetcher)
  157.     {
  158.         $config $configurationManager->getConfiguration();
  159.         // Get a catalogue manager and load it with all the catalogues
  160.         $catalogueManager->load($catalogueFetcher->getCatalogues($config));
  161.         $locale $request->getLocale();
  162.         /** @var CatalogueMessage[] $messages */
  163.         $messages $catalogueManager->getMessages($locale'messages');
  164.         \usort($messages, function (CatalogueMessage $aCatalogueMessage $b) {
  165.             return \strcmp($a->getKey(), $b->getKey());
  166.         });
  167.         $messages_format=[];
  168.         foreach ($messages as $message){
  169.             $messages_format[$message->getKey()]=$message->getMessage();
  170.         }
  171.         /*
  172.         $file   = $projectDir.'/translations/messages.'.$locale.'.xlf';
  173.         $parsed = XliffFileLoader::parse(file_get_contents($file));*/
  174.         $translations $this->renderView(
  175.             'translation/translation.js.twig',
  176.             array(
  177.                 'json' => json_encode($messages_format)
  178.             )
  179.         );
  180.         return new Response($translations200,
  181.             array('Content-Type' => 'text/javascript')
  182.         );
  183.     }
  184. //    /**
  185. //     * @Route("/", name="old_app_homepage")
  186. //     */
  187. //    public function old_index(): Response
  188. //    {
  189. //
  190. //        //$total_collab=$this->getDoctrine()->getRepository(Collaborator::class)->countEnabled();
  191. //        $total_absence=$this->getDoctrine()->getRepository(Absence::class)->countInFuture($this->getUser()->getCollaborator());
  192. //        $total_expense_report=$this->getDoctrine()->getRepository(Expense::class)->totalByYearAndCollab($this->getUser()->getCollaborator());
  193. //        $today_absences=$this->getDoctrine()->getRepository(Absence::class)->getByCollaboratorAndDay(date('Ymd'),null,[Absence::VALID,Absence::PENDING]);
  194. //        $tasks=$this->getDoctrine()->getRepository(Task::class)->findMyTasks($this->getUser()->getCollaborator());
  195. //
  196. //        $collab_to_deleg=$this->getDoctrine()->getRepository(Collaborator::class)->getMyDelegationsForToday($this->getUser()->getCollaborator());
  197. //        $hasDelegation=$this->getDoctrine()->getRepository(Collaborator::class)->hasDelegateForToday($this->getUser()->getCollaborator());
  198. //
  199. //        $absenceCounter=$this->getDoctrine()->getRepository(AbsenceCounter::class)->findOneBy(['name'=>'Jours de repos']);
  200. //
  201. //        /*$total_working_days=$this->getUser()->getCollaborator()->getWorkingDayCount();
  202. //        $holidays=ClassUtils::getWorkingDays();
  203. //        $total_working_days-=$holidays;*/
  204. //
  205. //        if ($absenceCounter){
  206. //
  207. //            $counterCollab=$this->getDoctrine()->getRepository(AbsenceCounterTeam::class)->getByPeriodAndCollabAndReason(date('Y'),$this->getUser()->getCollaborator(),null,$absenceCounter);
  208. //            if($counterCollab){
  209. //                $pris_today=$this->getDoctrine()->getRepository(Absence::class)->getSoldeCongesByCollaborator($counterCollab);
  210. //
  211. //                $planned=$this->getDoctrine()->getRepository(Absence::class)->getSoldeCongesByCollaborator($counterCollab,'planned');
  212. //                $planned+=$this->getDoctrine()->getRepository(Absence::class)->getSoldeCongesByCollaborator($counterCollab,'planned_a_cheval');
  213. //                $solde_today=$counterCollab->getDefaultValue()-$pris_today;
  214. //
  215. //                //$total_working_days+=$solde_today-$planned;
  216. //
  217. //            }
  218. //
  219. //        }
  220. //
  221. //        return $this->render('default/index.html.twig', [
  222. //            //'total_collab' => $total_collab,
  223. //            'total_absence' => $total_absence,
  224. //            'total_expense_report' => $total_expense_report,
  225. //            'today_absences'=>$today_absences,
  226. //            'tasks'=>$tasks,
  227. //            'collab_to_deleg'=>$collab_to_deleg,
  228. //            'hasDelegation'=>$hasDelegation,
  229. //            //"total_working_days"=>$total_working_days
  230. //        ]);
  231. //    }
  232.     /**
  233.      * @Route("/inventory/order/pdf/{publicToken}", name="inventory_order_preview_pdf", methods={"GET","POST"}, options={"expose"=true}, defaults={"id" = null})
  234.      */
  235.     public function previewPdf(InventoryOrderManager $managerstring $publicToken)
  236.     {
  237.         $inventoryOrder $manager->getEntityManager()->getRepository(InventoryOrder::class)->findOneBy(['publicToken' => $publicToken]);
  238.         if($inventoryOrder === null) {
  239.             throw new AccessDeniedException('The token is invalid.');
  240.         }
  241.         if($inventoryOrder->getNum() === null) {
  242.             $this->addFlash('danger','fichier inexistant ou pas encore généré en pdf');
  243.             return $this->redirectToRoute("inventory_order_index");
  244.         }
  245.         if ($this->isGranted('ROLE_COLLAB'))
  246.         {
  247.             $manager->generatePdf($inventoryOrder);
  248.         }
  249.         $file $manager->getPdfPath($inventoryOrder);
  250.         $response = new BinaryFileResponse($file);
  251.         return $response->setContentDisposition(
  252.             ResponseHeaderBag::DISPOSITION_INLINE,
  253.             $inventoryOrder->getNum().'.pdf'
  254.         );
  255.     }
  256. }