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.                     $activeRib =  $contract->getLribs()->filter(function ($rib) {
  103.                            return $rib->isActive();
  104.                        })->first();
  105.                     $bulletin->setRIB($activeRib $activeRib->getCode() : null);
  106.                     
  107.                     $this->em->persist($bulletin);
  108.         
  109.                     
  110.                     $bulletinDet = new TbulletinLg();
  111.                     $bulletinDet->setBulletin($bulletin);
  112.                     $bulletinDet->setRubrique($netAPayer);
  113.                     $bulletinDet->setSens(1);
  114.                     $bulletinDet->setMontant($stc->montant);
  115.         
  116.                     $this->em->persist($bulletinDet);
  117.                     
  118.                     $bulletinDet = new TbulletinLg();
  119.                     $bulletinDet->setBulletin($bulletin);
  120.                     $bulletinDet->setRubrique($this->em->getRepository(Prubrique::class)->find(64));
  121.                     $bulletinDet->setSens(1);
  122.                     $bulletinDet->setMontant($stc->montant);
  123.                     
  124.                     $this->em->persist($bulletinDet);
  125.         
  126.                     $contract->getEmploye()->setStc(true);
  127.                 }
  128.                 $this->em->flush();
  129.                 array_push($bordoreauIds$bordoreau->getId());
  130.             }
  131.         }
  132.         
  133.         
  134.         $bordoreauIds array_unique($bordoreauIds);
  135.         if(count($bordoreauIds) > 0) {
  136.             $request->request->add(['bordoreauIds' => json_encode($bordoreauIds)]);
  137.         }
  138.         return new JsonResponse('Bien Enregistrer!');
  139.     }
  140.     #[Route('/app_paie_stc_list'name'app_paie_stc_list'options: ['expose' => true])]
  141.     public function app_paie_stc_list(Request $request,): Response
  142.     {
  143.        
  144.         // $date = new \DateTime($periode);
  145.         
  146.         $draw $request->query->get('draw');
  147.         $start $request->query->get('start') ?? 0;
  148.         $length $request->query->get('length') ?? 10;
  149.         $search $request->query->all('search')["value"];
  150.         $orderColumnIndex $request->query->all('order')[0]['column'];
  151.         $orderColumn $request->query->all("columns")[$orderColumnIndex]['name'];
  152.         $orderDir $request->query->all('order')[0]['dir'] ?? 'asc';
  153.         $queryBuilder $this->em->createQueryBuilder()
  154.         ->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')
  155.         ->from(LContract::class, 'contract')
  156.         ->innerJoin('contract.employe''p')
  157.         ->innerJoin('contract.bulletins''b')
  158.         ->innerJoin('b.piece''piece')
  159.         ->innerJoin('contract.dossier''dossier')
  160.         ->innerJoin('b.periode''periode')
  161.         ->andWhere('piece.id = 13')
  162.         ->andWhere('b.active = 1')
  163.         ;
  164.         if (!empty($search)) {
  165.             $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)')
  166.                 ->setParameter('search'"%$search%");
  167.         }
  168.         if (!empty($orderColumn)) {
  169.             $queryBuilder->orderBy("$orderColumn"$orderDir);
  170.         }
  171.         $filteredRecords count($queryBuilder->getQuery()->getResult());
  172.         
  173.         // Paginate results
  174.         $queryBuilder->setFirstResult($start)
  175.             ->setMaxResults($length)
  176.             ->orderBy('b.id''DESC');
  177.         $results $queryBuilder->getQuery()->getResult();
  178.         // dd($results);
  179.         foreach ($results as $key => $contract) {
  180.             $results[$key]['DT_RowId'] = $contract['id'];
  181.             $results[$key]['nombreJourTravails'] = "-";
  182.             $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>';
  183.             $results[$key]['problemes'] = '<i class="fa-solid fa-circle-check text-success"></i>';
  184.         }
  185.         
  186.         // dd($results);
  187.         $totalRecords $this->em->createQueryBuilder()
  188.         ->select('COUNT(d.id)')
  189.         ->from(LContract::class, 'd')
  190.         ->innerJoin('d.bulletins''bulletins')
  191.         ->innerJoin('bulletins.piece''piece')
  192.         ->Where('d.active = 1')
  193.         ->andWhere('piece.id = 13')
  194.         ->getQuery()
  195.         ->getSingleScalarResult();
  196.         return new JsonResponse([
  197.             'draw' => $draw,
  198.             'recordsTotal' => $totalRecords,
  199.             'recordsFiltered' => $filteredRecords,
  200.             'data' => $results,
  201.         ]);
  202.     }
  203.     #[Route('/app_stc_employe'name'app_stc_employe'options: ['expose' => true])]
  204.     public function app_stc_employe(Request $request,): Response
  205.     {
  206.        
  207.         $employes $this->em->getRepository(Pemploye::class)->findEmployeesWithLastContract($request->query->get("search"));
  208.         // dd($employes);
  209.         
  210.         return new JsonResponse($employes);
  211.     }
  212. }