src/Controller/Paie/StcController.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Paie;
  3. use App\Entity\PPiece;
  4. use App\Entity\PDevise;
  5. use App\Entity\PStatut;
  6. use App\Entity\PDossier;
  7. use App\Entity\Pemploye;
  8. use App\Entity\LContract;
  9. use App\Entity\PPaiement;
  10. use App\Entity\Prubrique;
  11. use App\Entity\Tbulletin;
  12. use App\Entity\PBordereau;
  13. use App\Entity\TbulletinLg;
  14. use App\Entity\PnatureContract;
  15. use App\Controller\ApiController;
  16. use App\Service\CalculPaieService;
  17. use Doctrine\Persistence\ManagerRegistry;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  23. #[Route('/paie/stc')]
  24. class StcController extends AbstractController
  25. {
  26.     private $em;
  27.     private $calculPaieService;
  28.     private $api;
  29.     public function __construct(ManagerRegistry $doctrineCalculPaieService $calculPaieServiceApiController $api)
  30.     {
  31.         $this->em $doctrine->getManager();
  32.         $this->calculPaieService $calculPaieService
  33.         $this->api $api
  34.     }
  35.     #[Route('/'name'app_paie_stc')]
  36.     public function index(Request $request): Response
  37.     {
  38.         $operations $this->api->check($this->getUser(), 'app_paie_stc'$this->em$request);
  39.         if(!is_array($operations)) {
  40.             return $this->redirectToRoute('app_site');  
  41.         }elseif(count($operations) == 0) {
  42.             return $this->render('includes/404.html.twig');
  43.         }
  44.         $paiements $this->em->getRepository(PPaiement::class)->findBy(['active' => true]);
  45.         // dd($employes);
  46.         return $this->render('paie/stc/index.html.twig', [
  47.             'operations' => $operations,
  48.             'paiements' => $paiements,
  49.         ]);
  50.     }
  51.     #[Route('/app_paie_stc_insert'name'app_paie_stc_insert'options: ['expose' => true])]
  52.     public function app_paie_stc_insert(Request $request): Response
  53.     {
  54.         $devise $this->em->getRepository(PDevise::class)->find(1);
  55.         // $paiement = $this->em->getRepository(PPaiement::class)->find(2);
  56.         $paiement $this->em->getRepository(PPaiement::class)->find($request->get('paiement'));
  57.         $periode $this->calculPaieService->getPeriode();
  58.         $observation $request->get('observation');
  59.         // dd($paiement,$request->get('paiement'));
  60.         
  61.         if($periode->IsValider()) {
  62.             return new JsonResponse('Periode est valider !'500, [], JSON_UNESCAPED_UNICODE);
  63.         }
  64.         
  65.         $stcs json_decode($request->get('stcs'));
  66.         // dd($stcs);
  67.         $netAPayer $this->em->getRepository(Prubrique::class)->find(5);
  68.         $bordoreauIds = [];
  69.         
  70.         foreach($stcs as $key => $dossierKey) {
  71.             $dossier $this->em->getRepository(PDossier::class)->find($key);
  72.             foreach ($dossierKey as $key => $natureKey) {
  73.                 $bordoreau = new PBordereau;
  74.                 $bordoreau->setPiece($this->em->getRepository(PPiece::class)->find(14));
  75.                 $bordoreau->setNatureContract($this->em->getRepository(PnatureContract::class)->find($key));
  76.                 $bordoreau->setStatut(
  77.                     $this->em->getRepository(PStatut::class)->find(1)
  78.                 );
  79.                 $bordoreau->setPeriode($periode);
  80.                 $bordoreau->setType('stc');
  81.                 $bordoreau->setPaiement($paiement);
  82.                 $bordoreau->setDevise($devise);
  83.                 $bordoreau->setUserCreated($this->getUser());
  84.                 $bordoreau->setObservation($observation);
  85.                 $bordoreau->setDossier($dossier);
  86.                 $this->em->persist($bordoreau);
  87.                 foreach($natureKey as $key => $stc) {
  88.             
  89.                     $contract $this->em->getRepository(LContract::class)->find($stc->contract);
  90.         
  91.                     $bulletin = new Tbulletin();
  92.                     $bulletin->setDossier($dossier);
  93.                     $bulletin->setDevise($devise);
  94.                     $bulletin->setPaiement($paiement);
  95.                     $bulletin->setObservation($observation);
  96.                     $bulletin->setBordereau($bordoreau);
  97.                     $bulletin->setContract($contract);
  98.                     $bulletin->setPeriode($periode);
  99.                     $bulletin->setPPiece(
  100.                         $this->em->getRepository(PPiece::class)->find(13)
  101.                     );
  102.                     $this->em->persist($bulletin);
  103.         
  104.                     
  105.                     $bulletinDet = new TbulletinLg();
  106.                     $bulletinDet->setBulletin($bulletin);
  107.                     $bulletinDet->setRubrique($netAPayer);
  108.                     $bulletinDet->setSens(1);
  109.                     $bulletinDet->setMontant($stc->montant);
  110.         
  111.                     $this->em->persist($bulletinDet);
  112.                     
  113.                     $bulletinDet = new TbulletinLg();
  114.                     $bulletinDet->setBulletin($bulletin);
  115.                     $bulletinDet->setRubrique($this->em->getRepository(Prubrique::class)->find(64));
  116.                     $bulletinDet->setSens(1);
  117.                     $bulletinDet->setMontant($stc->montant);
  118.                     
  119.                     $this->em->persist($bulletinDet);
  120.         
  121.                     $contract->getEmploye()->setStc(true);
  122.                 }
  123.                 $this->em->flush();
  124.                 array_push($bordoreauIds$bordoreau->getId());
  125.             }
  126.         }
  127.         
  128.         
  129.         $bordoreauIds array_unique($bordoreauIds);
  130.         if(count($bordoreauIds) > 0) {
  131.             $request->request->add(['bordoreauIds' => json_encode($bordoreauIds)]);
  132.         }
  133.         return new JsonResponse('Bien Enregistrer!');
  134.     }
  135.     #[Route('/app_paie_stc_list'name'app_paie_stc_list'options: ['expose' => true])]
  136.     public function app_paie_stc_list(Request $request,): Response
  137.     {
  138.        
  139.         // $date = new \DateTime($periode);
  140.         
  141.         $draw $request->query->get('draw');
  142.         $start $request->query->get('start') ?? 0;
  143.         $length $request->query->get('length') ?? 10;
  144.         $search $request->query->all('search')["value"];
  145.         $orderColumnIndex $request->query->all('order')[0]['column'];
  146.         $orderColumn $request->query->all("columns")[$orderColumnIndex]['name'];
  147.         $orderDir $request->query->all('order')[0]['dir'] ?? 'asc';
  148.         $queryBuilder $this->em->createQueryBuilder()
  149.         ->select('b.code as bulletin, b.id as bulletin_id, periode.code as periode_code,dossier.abreviation as dossier_abreviation, contract.id as id, contract.code as contract_code, p.nom as nom, contract.id as matricule , p.prenom')
  150.         ->from(LContract::class, 'contract')
  151.         ->innerJoin('contract.employe''p')
  152.         ->innerJoin('contract.bulletins''b')
  153.         ->innerJoin('b.piece''piece')
  154.         ->innerJoin('contract.dossier''dossier')
  155.         ->innerJoin('b.periode''periode')
  156.         ->andWhere('piece.id = 13')
  157.         ->andWhere('b.active = 1')
  158.         ;
  159.         if (!empty($search)) {
  160.             $queryBuilder->andWhere('(dossier.abreviation LIKE :search OR periode.code LIKE :search OR contract.code LIKE :search OR b.code LIKE :search OR p.matricule LIKE :search OR  p.nom LIKE :search OR p.prenom LIKE :search)')
  161.                 ->setParameter('search'"%$search%");
  162.         }
  163.         if (!empty($orderColumn)) {
  164.             $queryBuilder->orderBy("$orderColumn"$orderDir);
  165.         }
  166.         $filteredRecords count($queryBuilder->getQuery()->getResult());
  167.         
  168.         // Paginate results
  169.         $queryBuilder->setFirstResult($start)
  170.             ->setMaxResults($length)
  171.             ->orderBy('b.id''DESC');
  172.         $results $queryBuilder->getQuery()->getResult();
  173.         // dd($results);
  174.         foreach ($results as $key => $contract) {
  175.             $results[$key]['DT_RowId'] = $contract['id'];
  176.             $results[$key]['nombreJourTravails'] = "-";
  177.             $results[$key]['salaire'] = '<p style="text-align: right !important; margin:0 !important">'.number_format($this->em->getRepository(Tbulletin::class)->getNetAPaye($contract['bulletin_id']), 2',' ' ').'</p>';
  178.             $results[$key]['problemes'] = '<i class="fa-solid fa-circle-check text-success"></i>';
  179.         }
  180.         
  181.         // dd($results);
  182.         $totalRecords $this->em->createQueryBuilder()
  183.         ->select('COUNT(d.id)')
  184.         ->from(LContract::class, 'd')
  185.         ->innerJoin('d.bulletins''bulletins')
  186.         ->innerJoin('bulletins.piece''piece')
  187.         ->Where('d.active = 1')
  188.         ->andWhere('piece.id = 13')
  189.         ->getQuery()
  190.         ->getSingleScalarResult();
  191.         return new JsonResponse([
  192.             'draw' => $draw,
  193.             'recordsTotal' => $totalRecords,
  194.             'recordsFiltered' => $filteredRecords,
  195.             'data' => $results,
  196.         ]);
  197.     }
  198.     #[Route('/app_stc_employe'name'app_stc_employe'options: ['expose' => true])]
  199.     public function app_stc_employe(Request $request,): Response
  200.     {
  201.        
  202.         $employes $this->em->getRepository(Pemploye::class)->findEmployeesWithLastContract($request->query->get("search"));
  203.         // dd($employes);
  204.         
  205.         return new JsonResponse($employes);
  206.     }
  207. }