src/Controller/WebController.php line 201

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Category;
  4. use App\Entity\ClientOrder;
  5. use App\Entity\Doctor;
  6. use App\Entity\Exam;
  7. use App\Entity\ExamParam;
  8. use App\Entity\ExamParamVariant;
  9. use App\Entity\ExamRequest;
  10. use App\Entity\ExamRequestItem;
  11. use App\Entity\ExamRequestItemParam;
  12. use App\Entity\ExamType;
  13. use App\Entity\InsuranceCompany;
  14. use App\Entity\MedicalPrescription;
  15. use App\Entity\Order;
  16. use App\Entity\Patient;
  17. use App\Entity\PaymentAdvance;
  18. use App\Entity\Product;
  19. use App\Entity\ProductCalendarExpiration;
  20. use App\Entity\ProductOutRequest;
  21. use App\Entity\ProductStore;
  22. use App\Entity\Provider;
  23. use App\Entity\Role;
  24. use App\Entity\Save;
  25. use App\Entity\Statut;
  26. use App\Entity\Store;
  27. use App\Entity\System;
  28. use App\Entity\User;
  29. use App\Entity\UserType;
  30. use App\Repository\ProductOutRepository;
  31. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  32. use Symfony\Component\HttpFoundation\Response;
  33. use Symfony\Component\HttpFoundation\Request;
  34. use Symfony\Component\DependencyInjection\ContainerInterface;
  35. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  36. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  37. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  38. use App\Twig\AppExtension;
  39. use Doctrine\ORM\EntityManagerInterface;
  40. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  41. use function Symfony\Component\String\b;
  42. class WebController extends AbstractController implements LogginInterfaceController
  43. {
  44.     private $mycontainer;
  45.     private $token;
  46.     private $locale;
  47.     private $tokenUser;
  48.     private $session;
  49.     private $extension;
  50.     private $currentUser;
  51.     private $currentUserRoles;
  52.     private $em;
  53.     /**
  54.      * WebController constructor.
  55.      * @param ContainerInterface $c
  56.      * @param SessionInterface $s
  57.      * @param EntityManagerInterface $em
  58.      */
  59.     public function __construct(ContainerInterface $c,SessionInterface $s,EntityManagerInterface $em)
  60.     {
  61.         $this->currentUser null;
  62.         $this->currentUserRoles = [];
  63.         $this->extension = new AppExtension($c);
  64.         $this->session $s;
  65.         $this->mycontainer $c;
  66.         $this->locale="fr";
  67.         $this->em=$em;
  68.         $this->mycontainer->get('translator')->setLocale($this->locale);
  69.         $lang $this->mycontainer->get("request_stack")->getCurrentRequest()->cookies->get("lang");
  70.         if(in_array($lang,["fr","en"])) {
  71.             $this->mycontainer->get('translator')->setLocale($lang);
  72.             $this->locale $lang;
  73.         }
  74.         $token $this->mycontainer->get("request_stack")->getCurrentRequest()->cookies->get("token");
  75.         if($token === null || $token === "null") {
  76.             $this->tokenUser null;
  77.         }
  78.         else{
  79.             $this->connected true;
  80.             $this->token =$token;
  81.             $tokenPayload=null;
  82.             if($this->token !== null)
  83.             {
  84.                 $tokenParts explode("."$this->token);
  85.                 //$tokenHeader = base64_decode($tokenParts[0]);
  86.                 $tokenPayload base64_decode($tokenParts[1]);
  87.                 $this->tokenUser=  json_decode($tokenPayload);
  88.             }
  89.         }
  90.         $tokenUser $this->mycontainer->get('security.token_storage')->getToken();
  91.         if($tokenUser === null){
  92.             $this->currentUser "anon.";
  93.         }
  94.         else{
  95.             $this->currentUser $tokenUser->getUser();
  96.         }
  97.         $tab=[];
  98.         if($this->currentUser !== "anon.")
  99.         {
  100.             if(in_array($this->currentUser->getRoles()[0],['SADMIN','ADMIN']))
  101.             {
  102.                 $roles $this->em->getRepository(Role::class)->findBy(array("isActive"=>true));
  103.                 foreach ($roles as $r)
  104.                 {
  105.                     $tab[]=$r->getCode();
  106.                 }
  107.             }
  108.             else
  109.             {
  110.                 $roles1=$this->currentUser->getUserRoles();
  111.                 foreach ($roles1 as $r)
  112.                 {
  113.                     if(!in_array($r->getCode(),$tab)) $tab[]=$r->getCode();
  114.                 }
  115.             }
  116.         }
  117.         $this->currentUserRoles $tab;
  118.         $res $this->mycontainer->get("user_manager")->getSystemInfo();
  119.         $this->mycontainer->get('session')->set('AppData',$res["data"]);
  120.         $this->mycontainer->get('session')->set('roles',$tab);
  121.         $stores $this->em->getRepository(Store::class)->findBy(['isActive'=>true]);
  122.         if(count($stores)==0){
  123.             $store = new Store();
  124.             $store->setTitle('DEFAULT');
  125.             $this->em->persist($store);
  126.             $this->em->flush();
  127.             $stores=[$store];
  128.         }
  129.         $sts = [];
  130.         foreach ($stores as $s){
  131.             $sts[]=['name'=>$s->getTitle(),'slug'=>$s->getSlug()];
  132.         }
  133.         $this->mycontainer->get('session')->set('stores',$sts);
  134.     }
  135.     private function testRole($role): bool
  136.     {
  137.         $test false;
  138.         $roles1=$this->currentUserRoles;
  139.         foreach ($roles1 as $r)
  140.         {
  141.             if($r == $role$test=true;
  142.         }
  143.         if(gettype($this->currentUser)==="object"){
  144.             if(in_array($this->currentUser->getRoles()[0],["SADMIN","ADMIN"]))$test=true;
  145.         }
  146.         return $test;
  147.     }
  148.     private  function ageCalculator(\DateTime $born){
  149.         //set current date
  150.         $now = new \DateTime;
  151.         //get differ between born date and current date
  152.         $diff $now->diff($born);
  153.         $total_days $diff->days;
  154.         $total_week = ($diff->days 7);
  155.         /*if($diff->days % 7 > 0){
  156.             $total_week = $total_week +1;
  157.         }*/
  158.         $total_months = ($diff->12) + $diff->m;
  159.         $total_years $diff->y;
  160.         return ['year'=>$total_years,'month'=>$total_months,'week'=>$total_week,'day'=>$total_days];
  161.     }
  162.     public function home(Request $request)
  163.     {
  164.         if($this->currentUser !== 'anon.') return $this->redirectToRoute('web_app_dashboard');
  165.         $res $this->mycontainer->get("user_manager")->getSystemInfo();
  166.         return $this->render('login.html.twig',["system"=>$res["data"]]);
  167.     }
  168.     public function dashboard(Request $request)
  169.     {
  170.         if($this->currentUser === 'anon.'){
  171.             return $this->redirectToRoute('web_logout');
  172.         }
  173.         $save $this->em->getRepository(Save::class)->findBy(array("isActive"=>true),array("id"=>"DESC"),1,0);
  174.         $date=$this->mycontainer->get('translator')->trans("no_save");
  175.         if(count($save)>0)
  176.         {
  177.             $date $save[0]->getDate()->format("d/m/Y h:i:s");
  178.         }
  179.         $simple=0;
  180.         $activeProduct $this->em->getRepository(Product::class)->getTotalActive();
  181.         $totalProduct =  $this->em->getRepository(Product::class)->getTotal();;
  182.         $ProductOutRequest $this->em->getRepository(ProductOutRequest::class)->totalNb();
  183.         $ProductStockExceed $this->em->getRepository(Product::class)->totalProductStockExceed();
  184.         $response $this->render('dashboard.html.twig',
  185.             ["dossiers"=>$simple,
  186.                 "active_product"=>$activeProduct[0]['nb'],
  187.                 "total_product"=>$totalProduct[0]['nb'],
  188.                 "product_out_request"=>$ProductOutRequest[0]['nb'],
  189.                 "product_stock_exceed"=>$ProductStockExceed[0]['nb']]);
  190.         return $response;
  191.     }
  192.     public function systeme(Request $request)
  193.     {
  194.         if($this->testRole('M_SYS')==false) return $this->redirectToRoute('web_app_dashboard');
  195.         $res $this->mycontainer->get("user_manager")->getSystemInfo();
  196.         return $this->render('systeme.html.twig',["system"=>$res["data"]]);
  197.     }
  198.     public function utilisateur(Request $request)
  199.     {
  200.         if($this->testRole('M_USER')==false) return $this->redirectToRoute('web_app_dashboard');
  201.         $userTypes $this->em->getRepository(UserType::class)->findExceptSuperAdmin();
  202.         $users $this->em->getRepository(User::class)->loadAllUsers(10000,0);
  203.         $roles $this->em->getRepository(Role::class)->findBy(array("isActive"=>true),array("id"=>"ASC"));
  204.         foreach ($roles as $r){
  205.             $r->setTranslatableLocale($this->locale);
  206.             $this->em->refresh($r);
  207.         }
  208.         foreach ($userTypes as $r){
  209.             $r->setTranslatableLocale($this->locale);
  210.             $this->em->refresh($r);
  211.         }
  212.         return $this->render('utilisateur.html.twig',["user_types"=>$userTypes,"users"=>$users,'roles'=>$roles]);
  213.     }
  214.     public function sauvegarde(Request $request)
  215.     {
  216.         if($this->testRole('AD_S1')==false) return $this->redirectToRoute('web_app_dashboard');
  217.         $all $this->em->getRepository(Save::class)->findBy(array("isActive"=>true),array("id"=>"DESC"));
  218.         $todaydb $this->em->getRepository(Save::class)->findForTodayDb();
  219.         $todayar $this->em->getRepository(Save::class)->findForTodayArchive();
  220.         $today=[];
  221.         foreach ($todaydb as $t)
  222.         {
  223.             $today[]=$t;
  224.         }
  225.         foreach ($todayar as $t)
  226.         {
  227.             $today[]=$t;
  228.         }
  229.         return $this->render('sauvegarde.html.twig',["all"=>$all,"today"=>$today]);
  230.     }
  231.     public function profile(Request $request)
  232.     {
  233.         // $this->addFlash('notice',$this->mycontainer->get('translator')->trans("eeeeee"));
  234.         return $this->render('profile.html.twig');
  235.     }
  236.     public function support(Request $request)
  237.     {
  238.         $news $this->em->getRepository(News::class)->findBy(array("isActive"=>true,"status"=>true));
  239.         return $this->render('support.html.twig',["faq"=>$news]);
  240.     }
  241.     public function upload(Request $request)
  242.     {
  243.         $file $request->files;
  244.         return new Response();
  245.     }
  246.     public function readFile(Request $request,$name)
  247.     {
  248.         if($this->currentUser === 'anon.') return $this->redirectToRoute('api_home');
  249.         $fu $this->mycontainer->get('upload_service');
  250.         $res $fu->getFileBinary($name);
  251.         if($res['error']==true) return new Response('file not found '.$name,401);
  252.         if(!in_array($name,['man.png''woman.png'])){
  253.             $original $this->mycontainer->get('upload_service')->getFile($name);
  254.             if($original !== null){
  255.                 $resp = new BinaryFileResponse($res["data"]);
  256.                 $resp->setContentDisposition(
  257.                     ResponseHeaderBag::DISPOSITION_ATTACHMENT,''
  258.                 );
  259.                 return $resp;
  260.             }
  261.         }
  262.         return new BinaryFileResponse($res["data"]);
  263.     }
  264.     public function readFileOld(Request $request,$name)
  265.     {
  266.         if($this->currentUser === 'anon.') return $this->redirectToRoute('api_home');
  267.         $fu $this->mycontainer->get('upload_service');
  268.         $res $fu->getFileBinary($name);
  269.         if($res['error']==true) return new Response('file not found '.$res['data'],401);
  270.         if(!in_array($name,['man.png''woman.png'])){
  271.             $original $this->mycontainer->get('user_manager')->getFile(['name'=>$name]);
  272.             if($original !== null && !in_array(explode('/',$original['type'])[0],['image','pdf'])){
  273.                 $resp = new BinaryFileResponse($res["data"]);
  274.                 $resp->setContentDisposition(
  275.                     ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  276.                     $original['nom']
  277.                 );
  278.                 return $resp;
  279.             }
  280.         }
  281.         // return new BinaryFileResponse($res["data"]);
  282.     }
  283.     public function showNotif(Request $request,$id)
  284.     {
  285.         $status $this->em->getRepository(Statut::class)->findOneBy(array('id' =>$id'user' =>$this->currentUser,'isActive'=>true));
  286.         if($status === null) return $this->redirectToRoute("web_app_dashboard");
  287.         if($status->getStatut()==0)
  288.         {
  289.             $status->setStatut(1);
  290.             $this->em->persist($status);
  291.             $this->em->flush();
  292.         }
  293.         /*if(in_array($status->getNotification()->getCode(),[30,31,33,35,36,37,38,39])){
  294.             return $this->redirectToRoute("web_my_mail");
  295.         }*/
  296.         switch ($status->getNotification()->getCode())
  297.         {
  298.             case 30:
  299.                 return $this->redirectToRoute("web_app_order");
  300.             case 40:
  301.                 return $this->redirectToRoute("web_app_product_store_request",['slug'=>$status->getNotification()->getProductOutRequest()->getStore()->getSlug()]);
  302.             case 50:
  303.                 return $this->redirectToRoute("web_app_exam_request_result");
  304.             case 60:
  305.                 return $this->redirectToRoute("web_app_product");
  306.             case 70:
  307.                 return $this->redirectToRoute("web_app_exam_item");
  308.             default:
  309.                 return $this->redirectToRoute("web_app_dashboard");
  310.         }
  311.     }
  312.     public function allUserExecptAdmin(Request $request)
  313.     {
  314.         //$data = $this->postData;
  315.         $res $this->container->get("user_manager")->allUserExecptAdmin([]);
  316.         if($res["statut"]==false)
  317.         {
  318.             $this->response->setStatut(401);
  319.             $this->response->setContent($res);
  320.             return $this->response->getResponse();
  321.         }
  322.         $this->response->setStatut(201);
  323.         $this->response->setContent($res);
  324.         return $this->response->getResponse();
  325.     }
  326.     public function readFileUserSignature(Request $request,$name)
  327.     {
  328.         if($this->currentUser === 'anon.') return $this->redirectToRoute('api_home');
  329.         $fu $this->mycontainer->get('upload_service');
  330.         $res $fu->getFileBinaryUserSignature($name);
  331.         if($res['error']==true) return new Response('file not found',404);
  332.         return new BinaryFileResponse($res["data"]);
  333.     }
  334.     /** NEW* **/
  335.     public function productCategory(Request $request)
  336.     {
  337.         if($this->testRole('M_PRODUCT_CAT')==false) return $this->redirectToRoute('web_app_dashboard');
  338.         $data $this->em->getRepository(Category::class)->findBy(['isActive'=>true],['title'=>'ASC']);
  339.         foreach ($data as $r){
  340.             $r->setTranslatableLocale($this->locale);
  341.             $this->em->refresh($r);
  342.         }
  343.         return $this->render('product_category.html.twig',["data_list"=>$data]);
  344.     }
  345.     public function wareHouse(Request $request)
  346.     {
  347.         if($this->testRole('M_WAREHOUSE')==false) return $this->redirectToRoute('web_app_dashboard');
  348.         $data $this->em->getRepository(Store::class)->findBy(['isActive'=>true],['title'=>'ASC']);
  349.         return $this->render('warehouse.html.twig',["data_list"=>$data]);
  350.     }
  351.     public function product(Request $request)
  352.     {
  353.         if($this->testRole('M_PRODUCT')==false) return $this->redirectToRoute('web_app_dashboard');
  354.         $data $this->em->getRepository(Product::class)->findBy(['isActive'=>true],['title'=>'ASC']);
  355.         $categories $this->em->getRepository(Category::class)->findBy(['isActive'=>true],['title'=>'ASC']);
  356.         $stores $this->em->getRepository(Store::class)->findBy(['isActive'=>true],['title'=>'ASC']);
  357.         $dateFrom = new \DateTime();
  358.         $dateTo = new \DateTime();
  359.         $sys $this->em->getRepository(System::class)->findOneBy([]);
  360.         if($sys !== null){
  361.             $dateTo->add(new \DateInterval('P'.$sys->getNbDayAlertProductExpiration().'D'));
  362.         }
  363.         $pE $this->em->getRepository(ProductCalendarExpiration::class)->findExpiredBeforeNbDay($dateFrom->format("Y-m-d")." 00:00:00",$dateTo->format("Y-m-d")." 23:59:59");
  364.         foreach ($categories as $r){
  365.             $r->setTranslatableLocale($this->locale);
  366.             $this->em->refresh($r);
  367.         }
  368.         foreach ($data as $r){
  369.             $r->setTranslatableLocale($this->locale);
  370.             $this->em->refresh($r);
  371.         }
  372.         return $this->render('product.html.twig',["data_list"=>$data,"data_list2"=>$pE,'categories'=>$categories,'stores'=>$stores,'code'=>$this->mycontainer->get('user_manager')->generateReference('PR')]);
  373.     }
  374.     public function provider(Request $request)
  375.     {
  376.         if($this->testRole('M_SUPPLIER')==false) return $this->redirectToRoute('web_app_dashboard');
  377.         $data $this->em->getRepository(Provider::class)->findBy(['isActive'=>true],['title'=>'ASC']);
  378.         return $this->render('provider.html.twig',["data_list"=>$data]);
  379.     }
  380.     public function patient(Request $request)
  381.     {
  382.         if($this->testRole('M_PAT')==false) return $this->redirectToRoute('web_app_dashboard');
  383.         $data $this->em->getRepository(Patient::class)->findBy(['isActive'=>true],['name'=>'ASC','surname'=>'ASC']);
  384.         return $this->render('patient.html.twig',["data_list"=>$data]);
  385.     }
  386.     public function patientProfile(Request $request$slug)
  387.     {
  388.         $referer $request->headers->get('referer');
  389.         $test1 $this->testRole('M_EXAM_REQUEST');
  390.         $test2 $this->testRole('M_EXAM_RESULT');
  391.         $test3 $this->testRole('M_PAT');
  392.         if($test1==false && $test2==false && $test3==false) return $this->redirectToRoute('web_app_dashboard');
  393.         $patient $this->em->getRepository(Patient::class)->findOneBy(['slug'=>$slug]);
  394.         if($patient === null){
  395.             $this->mycontainer->get('session')->getFlashBag()->add('notice','Patient '.$this->mycontainer->get('translator')->trans("not_found"));
  396.             return $this->redirect($referer ?? '/');
  397.         }
  398.         $oldExams $this->em->getRepository(ExamRequest::class)->findBy(['patient'=>$patient,'isActive'=>true]);
  399.         return $this->render('patient_profile.html.twig',["patient"=>$patient,"exam_requests"=>$oldExams]);
  400.     }
  401.     public function productOrder(Request $request)
  402.     {
  403.         if($this->testRole('M_ORDER')==false) return $this->redirectToRoute('web_app_dashboard');
  404.         $data $this->em->getRepository(Order::class)->findBy(['isActive'=>true],['dateOrder'=>'DESC']);
  405.         $products $this->em->getRepository(Product::class)->findBy(['isActive'=>true],['title'=>'DESC']);
  406.         $providers $this->em->getRepository(Provider::class)->findBy(['isActive'=>true],['title'=>'ASC']);
  407.         foreach ($products as $r){
  408.             $r->setTranslatableLocale($this->locale);
  409.             $this->em->refresh($r);
  410.         }
  411.         return $this->render('order.html.twig',["data_list"=>$data,'products'=>$products,'providers'=>$providers,'code'=>$this->mycontainer->get('user_manager')->generateReference('OR')]);
  412.     }
  413.     public function displayOrder(Request $request$slug){
  414.         $test2 $this->testRole('M_ORDER');
  415.         $test3 $this->testRole('M_BILL');
  416.         if($test2==false && $test3 ==false) return $this->redirectToRoute('web_app_dashboard');
  417.         $order $this->em->getRepository(Order::class)->findOneBy(['reference'=>$slug]);
  418.         if($order === null){
  419.             $this->mycontainer->get('session')->getFlashBag()->add('notice','Order '.$this->mycontainer->get('translator')->trans("not_found"));
  420.             return $this->redirectToRoute('web_app_order');
  421.         }
  422.         foreach ($order->getOrderItems() as $item){
  423.             $item->getProduct()->setTranslatableLocale($this->locale);
  424.             $this->em->refresh$item->getProduct());
  425.         }
  426.         $system $this->em->getRepository(System::class)->findOneBy([]);
  427.         return $this->render('display_order.html.twig',["order"=>$order,'system'=>$system]);
  428.     }
  429.     public function productRequest(Request $request$slug)
  430.     {
  431.         if($this->testRole('M_BORROW')==false) return $this->redirectToRoute('web_app_dashboard');
  432.         $store $this->em->getRepository(Store::class)->findOneBy(['slug'=>$slug]);
  433.         if($store === null){
  434.             $this->mycontainer->get('session')->getFlashBag()->add('notice','Store '.$this->mycontainer->get('translator')->trans("not_found"));
  435.             return $this->redirectToRoute('web_app_product_request_main');
  436.         }
  437.         $data $this->em->getRepository(ProductOutRequest::class)->findBy(['isActive'=>true,'store'=>$store],['dateRequest'=>'DESC']);
  438.         $products $this->em->getRepository(ProductStore::class)->findByStore($store->getId());
  439.         foreach ($products as $r){
  440.             $r->getProduct()->setTranslatableLocale($this->locale);
  441.             $this->em->refresh($r->getProduct());
  442.         }
  443.         return $this->render('product_request.html.twig',["data_list"=>$data,'products'=>$products,'store'=>$store,'code'=>$this->mycontainer->get('user_manager')->generateReference('PR_R')]);
  444.     }
  445.     public function productStoreList(Request $request,$slug)
  446.     {
  447.         if($this->testRole('M_WAREHOUSE')==false) return $this->redirectToRoute('web_app_dashboard');
  448.         $store $this->em->getRepository(Store::class)->findOneBy(['slug'=>$slug]);
  449.         if($store === null){
  450.             $this->mycontainer->get('session')->getFlashBag()->add('notice','Store '.$this->mycontainer->get('translator')->trans("not_found"));
  451.             return $this->redirectToRoute('web_app_warehouse');
  452.         }
  453.         $stores $this->em->getRepository(Store::class)->findExcept($store->getId());
  454.         $products $this->em->getRepository(ProductStore::class)->findBy(['isActive'=>true,'store'=>$store],['id'=>'ASC']);
  455.         foreach ($products as $p){
  456.             $p->getProduct()->setTranslatableLocale($this->locale);
  457.             $this->em->refresh($p->getProduct());
  458.         }
  459.         return $this->render('warehouse_product.html.twig',["data_list"=>$products,'store'=>$store,'stores'=>$stores]);
  460.     }
  461.     public function productRequestMain(Request $request){
  462.         if($this->testRole('M_BORROW')==false) return $this->redirectToRoute('web_app_dashboard');
  463.         $data $this->em->getRepository(Store::class)->findBy(['isActive'=>true],['title'=>'ASC']);
  464.         return $this->render('product_request_main.html.twig',["data_list"=>$data]);
  465.     }
  466.     public function displayRequest(Request $request$slug){
  467.         if($this->testRole('M_BORROW')==false) return $this->redirectToRoute('web_app_dashboard');
  468.         $order $this->em->getRepository(ProductOutRequest::class)->findOneBy(['slug'=>$slug]);
  469.         if($order === null){
  470.             $this->mycontainer->get('session')->getFlashBag()->add('notice','Request '.$this->mycontainer->get('translator')->trans("not_found"));
  471.             return $this->redirectToRoute('web_app_product_request_main');
  472.         }
  473.         foreach ($order->getProductOuts() as $item){
  474.             $item->getProductStore()->getProduct()->setTranslatableLocale($this->locale);
  475.             $this->em->refresh$item->getProductStore()->getProduct());
  476.         }
  477.         $system $this->em->getRepository(System::class)->findOneBy([]);
  478.         return $this->render('display_request.html.twig',["order"=>$order,'system'=>$system]);
  479.     }
  480.     public function bill(Request $request)
  481.     {
  482.         if($this->testRole('M_BILL')==false) return $this->redirectToRoute('web_app_dashboard');
  483.         $referer $request->headers->get('referer');
  484.         $params $request->query->all();
  485.         $tabKeys = ['start_date'=>'','end_date'=>'','patient'=>'','provider'=>'','type'=>''];
  486.         $test false;
  487.         foreach ($tabKeys as $k=>$val){
  488.             if(array_key_exists($k,$params)){
  489.                 $test=true;
  490.                 $tabKeys[$k]=$params[$k];
  491.             }
  492.         }
  493.         if($test === false){
  494.             $data $this->em->getRepository(ClientOrder::class)->findBy(['isActive'=>true],['dateOrder'=>'DESC']);
  495.             $data2 $this->em->getRepository(Order::class)->findBy(['isActive'=>true],['dateOrder'=>'DESC']);
  496.         }
  497.         else{
  498.             if(strlen($tabKeys['start_date'])>0){
  499.                 try {
  500.                     $start = \DateTime::createFromFormat('d/m/Y',$tabKeys["start_date"])->format("Y-m-d")." 00:00:00";
  501.                     $tabKeys['start_date']=$start;
  502.                 }
  503.                 catch (\Exception $e)
  504.                 {
  505.                     $this->mycontainer->get('session')->getFlashBag()->add('notice','incorrect date');
  506.                     return $this->redirect($referer ?? '/');
  507.                 }
  508.             }
  509.             if(strlen($tabKeys['end_date'])>0){
  510.                 try {
  511.                     $start = \DateTime::createFromFormat('d/m/Y',$tabKeys["end_date"])->format("Y-m-d")." 23:59:59";
  512.                     $tabKeys['end_date']=$start;
  513.                 }
  514.                 catch (\Exception $e)
  515.                 {
  516.                     $this->mycontainer->get('session')->getFlashBag()->add('notice','incorrect date');
  517.                     return $this->redirect($referer ?? '/');
  518.                 }
  519.             }
  520.             if($tabKeys['type']==0){
  521.                 $data $this->em->getRepository(ClientOrder::class)->findFilterBill($tabKeys);
  522.                 $data2=[];
  523.             }else{
  524.                 $data2 $this->em->getRepository(Order::class)->findFilterBill($tabKeys);
  525.                 $data=[];
  526.             }
  527.         }
  528.         $dateInt 2;
  529.         $sys $this->em->getRepository(System::class)->findOneBy([]);
  530.         if($sys !== null){
  531.             $dateInt $sys->getNbDayAlertBill();
  532.         }
  533.         return $this->render('bill.html.twig',["data_list"=>$data,'data_list2'=>$data2,'date_int'=>$dateInt]);
  534.     }
  535.     public function statistiques(Request $request)
  536.     {
  537.         if($this->testRole('M_STA')==false) return $this->redirectToRoute('web_app_dashboard');
  538.         return $this->render('statistiques.html.twig',['date'=>(new \DateTime())->format('d/m/Y')]);
  539.     }
  540.     public function journal(Request $request)
  541.     {
  542.         if($this->testRole('M_LOG')==false) return $this->redirectToRoute('web_app_dashboard');
  543.         //$this->mycontainer->get('session')->getFlashBag()->add('notice','hello');
  544.         return $this->render('journal.html.twig');
  545.     }
  546.     public function insurance(Request $request)
  547.     {
  548.         if($this->testRole('M_PAT')==false) return $this->redirectToRoute('web_app_dashboard');
  549.         $data $this->em->getRepository(InsuranceCompany::class)->findBy(['isActive'=>true],['name'=>'ASC']);
  550.         return $this->render('insurance.html.twig',["data_list"=>$data]);
  551.     }
  552.     public function medicalPrescription(Request $request)
  553.     {
  554.         if($this->testRole('M_PAT')==false) return $this->redirectToRoute('web_app_dashboard');
  555.         $data $this->em->getRepository(MedicalPrescription::class)->findBy(['isActive'=>true],['date'=>'DESC']);
  556.         return $this->render('medical_prescription.html.twig',["data_list"=>$data,'code'=>$this->mycontainer->get('user_manager')->generateReference('ORD')]);
  557.     }
  558.     public function clientOrder(Request $request$store_slug)
  559.     {
  560.         if($this->testRole('M_EXAM_REQUEST')==false) return $this->redirectToRoute('web_app_dashboard');
  561.         $store $this->em->getRepository(Store::class)->findOneBy(['slug'=>$store_slug]);
  562.         if($store === null) return $this->redirectToRoute('web_app_dashboard');
  563.         $data $this->em->getRepository(ClientOrder::class)->findBy(['isActive'=>true,'store'=>$store],['date'=>'DESC']);
  564.         $productsStore $this->em->getRepository(ProductStore::class)->findBy(['store'=>$store]);
  565.         $products = [];
  566.         foreach ($productsStore as $pr){
  567.             $p $pr->getProduct();
  568.             $p->setQuantity($pr->getQuantity());
  569.             $p->setProductStoreId($pr->getId());
  570.             $products[]=$p;
  571.         }
  572.         foreach ($products as $r){
  573.             $r->setTranslatableLocale($this->locale);
  574.             $this->em->refresh($r);
  575.         }
  576.         $toDayAmount $this->em->getRepository(ClientOrder::class)->findToDayUserPayment($this->currentUser->getId());
  577.         return $this->render('client_order.html.twig',['today_payment'=>$toDayAmount[0]['amount'],"store"=>$store"data_list"=>$data,'products'=>$products,'code'=>$this->mycontainer->get('user_manager')->generateReference('COR')]);
  578.     }
  579.     public function displayClientOrder(Request $request$slug){
  580.         $order $this->em->getRepository(ClientOrder::class)->findOneBy(['reference'=>$slug]);
  581.         if($order === null){
  582.             $this->mycontainer->get('session')->getFlashBag()->add('notice','Order '.$this->mycontainer->get('translator')->trans("not_found"));
  583.             return $this->redirectToRoute('web_app_dashboard');
  584.         }
  585.         foreach ($order->getSaleItems() as $item){
  586.             $item->getProduct()->setTranslatableLocale($this->locale);
  587.             $this->em->refresh$item->getProduct());
  588.         }
  589.         $system $this->em->getRepository(System::class)->findOneBy([]);
  590.         return $this->render('display_client_order.html.twig',["order"=>$order,'system'=>$system]);
  591.     }
  592. }