src/EventListener/JournalPaieListener.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\JournalBulletinLg;
  4. use App\Entity\JournalPaieDossier;
  5. use App\Entity\PBordereau;
  6. use App\Entity\PCompteComptable;
  7. use App\Entity\Prubrique;
  8. use App\Entity\PStatut;
  9. use App\Entity\TbulletinLg;
  10. use App\Entity\VMatrix;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Symfony\Component\HttpKernel\Event\TerminateEvent;
  13. class JournalPaieListener
  14. {
  15.     private $entityManager;
  16.     private $charge;
  17.     public function __construct(EntityManagerInterface  $entityManager)
  18.     {
  19.         $this->entityManager $entityManager;
  20.     }
  21.     public function onKernelTerminate(TerminateEvent $event)
  22.     {
  23.         $request $event->getRequest();
  24.         if (
  25.             $request->get('_route') === 'app_bulletin_employe_calcul' or
  26.             $request->get('_route') === 'app_bulletin_employe_calcul_all' or
  27.             $request->get('_route') === 'app_paie_indeminite_insert' or
  28.             $request->get('_route') === 'app_paie_honoraire_insert' or
  29.             $request->get('_route') === 'app_paie_remuneration_avance_insert' or
  30.             $request->get('_route') === 'app_paie_stc_insert' or
  31.             $request->get('_route') === 'app_tresorerie_bordereau_journal'
  32.         ) {
  33.             if ($request->request->get('bordoreauIds')) {
  34.                 $bordoreauIds json_decode($request->request->get('bordoreauIds'));
  35.                 foreach ($bordoreauIds as $key => $bordoreauId) {
  36.                     $bordoreau $this->entityManager->getRepository(PBordereau::class)->find($bordoreauId);
  37.                     $this->charge 0;
  38.                     $this->entityManager->refresh($bordoreau);
  39.                     foreach ($bordoreau->getActiveBulletins() as $key => $bulletin) {
  40.                         $this->journalBulletin($bulletin);
  41.                     }
  42.                     if (number_format($this->charge2) == 0) {
  43.                         $bordoreau->setStatut(
  44.                             $this->entityManager->getRepository(PStatut::class)->find(2)
  45.                         );
  46.                     } else {
  47.                         $bordoreau->setStatut(
  48.                             $this->entityManager->getRepository(PStatut::class)->find(5)
  49.                         );
  50.                     }
  51.                 }
  52.                 $this->entityManager->flush();
  53.             }
  54.         }
  55.         return;
  56.     }
  57.     public function journalBulletin($bulletin)
  58.     {
  59.         $cotisationsArray = [
  60.             "cnss" => [504753],
  61.             "cimr" => [48],
  62.             "ir" => [43],
  63.             // "netpaye" => "K10010','K10011"
  64.         ];
  65.         $bordoreau $bulletin->getBordereau();
  66.         $primes $this->entityManager->getRepository(Prubrique::class)->findBy(['id' => [467891093111624256076,94]]);
  67.         if (in_array($bordoreau->getNatureContract()->getType()->getId(), [26])) {
  68.             $primes = [];
  69.         } else {
  70.             $primes $this->entityManager->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin'active' => true'rubrique' => $primes]);
  71.         }
  72.         if ($bulletin->getDossier()->getGroupement() == 'FCZ') {
  73.             $prevelements $this->entityManager->getRepository(Prubrique::class)->findBy(['id' => [568303133343536373839858079787782834584]]);
  74.             $prevelementCabs $this->entityManager->getRepository(Prubrique::class)->findBy(['id' => [29324041444659]]); // if u change this ids please change also in TbulletinLgRepositry for regularisation
  75.             $prevelements $this->entityManager->getRepository(TbulletinLg::class)->findByGroup($bulletin,  $prevelements);
  76.             $prevelementCabs $this->entityManager->getRepository(TbulletinLg::class)->findByGroup($bulletin$prevelementCabs);
  77.         } else {
  78.             $prevelements $this->entityManager->getRepository(Prubrique::class)->findBy(['id' => [56830313334353637383985807978778283458429324041444659]]);
  79.             $prevelements $this->entityManager->getRepository(TbulletinLg::class)->findByGroup($bulletin$prevelements);
  80.             $prevelementCabs = [];
  81.         }
  82.         // disable if exist already to insert new lines
  83.         // $journalBulletinLgs = $bulletin->getJournalBulletinLgs();
  84.         $class JournalBulletinLg::class;
  85.         $query $this->entityManager->createQuery(
  86.             "UPDATE $class e SET e.active = :newValue WHERE e.bulletin = :someValue and e.active = 1"
  87.         );
  88.         $query->setParameters([
  89.             'newValue' => '0',
  90.             'someValue' => $bulletin,
  91.         ]);
  92.         $query->execute();
  93.         // foreach($journalBulletinLgs as $journalBulletinLg) {
  94.         //     $journalBulletinLg->setActive(false);
  95.         // }
  96.         if ($bordoreau->getNatureContract()->getType()->getId() == && $bordoreau->getType() == 'paie') {
  97.             $salaireBase $this->entityManager->getRepository(TbulletinLg::class)->findOneBy(['bulletin' => $bulletin'rubrique' => $this->entityManager->getRepository(Prubrique::class)->find(1), 'active' => true]);
  98.             $salaireAnciennte $this->entityManager->getRepository(TbulletinLg::class)->findOneBy(['bulletin' => $bulletin'rubrique' => $this->entityManager->getRepository(Prubrique::class)->find(2), 'active' => true]);
  99.             $montantSalaireBase $salaireBase->getMontant();
  100.             $montantSalaireBaseInitial $salaireBase->getMontant();
  101.             $montantSalaireAnciennte $salaireAnciennte $salaireAnciennte->getMontant() : 0;
  102.             $montantSalaireAnciennteInitital $salaireAnciennte $salaireAnciennte->getMontant() : 0;
  103.         } else {
  104.             // if($bordoreau->getType() == 'regularisation') {
  105.             //     $rubriques = $this->entityManager->getRepository(Prubrique::class)->findBy(['id' => [5]]);
  106.             //     $salaireBase = $this->entityManager->getRepository(TbulletinLg::class)->findOneBy(['bulletin' => $bulletin, 'rubrique' => $rubriques, 'active' => true]);
  107.             // } else {
  108.             $rubriques $this->entityManager->getRepository(Prubrique::class)->findBy(['id' => [3121314151718222627616364656667697088]]);
  109.             $salaireBase $this->entityManager->getRepository(TbulletinLg::class)->findOneBy(['bulletin' => $bulletin'rubrique' => $rubriques'active' => true]);
  110.             // }
  111.             $montantSalaireBase $salaireBase->getMontant();
  112.             $montantSalaireBaseDevise $salaireBase->getMontantDevise() ?? 0;
  113.             $montantSalaireBaseInitial $salaireBase->getMontant();
  114.             $montantSalaireAnciennte 0;
  115.             $montantSalaireAnciennteInitital 0;
  116.         }
  117.         if ($montantSalaireBase == 0) {
  118.             return;
  119.         }
  120.         foreach ($cotisationsArray as $key => $cotisationArray) {
  121.             $cotisations $this->entityManager->getRepository(TbulletinLg::class)->findByCotisation($bulletin$cotisationArray);
  122.             $montantTotalCotisations $this->entityManager->getRepository(TbulletinLg::class)->findByCotisationGroupBulletin($bulletin$cotisationArray);
  123.             if ($cotisations and $montantTotalCotisations) {
  124.                 $montantInitial round($montantTotalCotisations['montant'], 2);
  125.                 $halfMontant round(($montantTotalCotisations['montant'] / 2), 2);
  126.                 if ($halfMontant $halfMontant != $montantInitial) {
  127.                     $firstHalf $halfMontant;
  128.                     $secondHalf $montantInitial $halfMontant;
  129.                 } else {
  130.                     $firstHalf $secondHalf $halfMontant;
  131.                 }
  132.                 if ($firstHalf $montantSalaireAnciennte) {
  133.                     $minus round(($firstHalf $montantSalaireAnciennte), 2);
  134.                     $montantSalaireBase  round(($montantSalaireBase  - ($secondHalf $minus)), 2);
  135.                     $montantSalaireAnciennte 0;
  136.                 } else {
  137.                     $montantSalaireBase  round(($montantSalaireBase $secondHalf), 2);
  138.                     $montantSalaireAnciennte round(($montantSalaireAnciennte $firstHalf), 2);
  139.                 }
  140.                 foreach ($cotisations as $cotisation) {
  141.                     $pcompteComptable $this->entityManager->getRepository(PCompteComptable::class)->findOneBy(['rubrique' => $cotisation->getRubrique(), 'natureContract' => $bordoreau->getNatureContract()]);
  142.                     // $excute = self::det_element_insert($id_employe,$element['Eléments'],$element['ID_Eléments'],abs($element['Montant_App_HRM']),NULL,$period,$code_comptable,$element['ID_Bulletin'],$id_cotis,$qte,$type,$this->em);
  143.                     if (!$pcompteComptable) {
  144.                         echo $cotisation->getRubrique()->getId() . '/' $bordoreau->getNatureContract()->getId();
  145.                         die;
  146.                     }
  147.                     $journalBulletinLg = new JournalBulletinLg();
  148.                     $journalBulletinLg->setRubrique($cotisation->getRubrique());
  149.                     $journalBulletinLg->setBulletin($bulletin);
  150.                     $journalBulletinLg->setMontant($cotisation->getMontant());
  151.                     $journalBulletinLg->setQte($pcompteComptable->getQte());
  152.                     $journalBulletinLg->setCodeComptable($pcompteComptable->getCompteComptable());
  153.                     $journalBulletinLg->setType($key);
  154.                     $journalBulletinLg->setSens($pcompteComptable->getSens());
  155.                     $this->entityManager->persist($journalBulletinLg);
  156.                     $this->charge -= $journalBulletinLg->getMontant();
  157.                 }
  158.                 $pcompteComptable $this->entityManager->getRepository(PCompteComptable::class)->findOneBy(['rubrique' => $salaireBase->getRubrique(), 'natureContract' => $bordoreau->getNatureContract()]);
  159.                 // if($key == 'cimr') {
  160.                 //     echo $montantSalaireBaseInitial . '/' .$montantSalaireBase . '/' .$halfMontant;
  161.                 //     die;
  162.                 // }
  163.                 $journalBulletinLg = new JournalBulletinLg();
  164.                 $journalBulletinLg->setRubrique($salaireBase->getRubrique());
  165.                 $journalBulletinLg->setBulletin($bulletin);
  166.                 $journalBulletinLg->setMontant(round($montantSalaireBaseInitial $montantSalaireBase2));
  167.                 $journalBulletinLg->setQte($pcompteComptable->getQte());
  168.                 $journalBulletinLg->setCodeComptable($pcompteComptable->getCompteComptable());
  169.                 $journalBulletinLg->setType($key);
  170.                 $journalBulletinLg->setSens($pcompteComptable->getSens());
  171.                 $this->entityManager->persist($journalBulletinLg);
  172.                 $this->charge += $journalBulletinLg->getMontant();
  173.                 if ($bordoreau->getNatureContract()->getType()->getId() == 1   && $bordoreau->getType() == 'paie' && $salaireAnciennte) {
  174.                     $pcompteComptable $this->entityManager->getRepository(PCompteComptable::class)->findOneBy(['rubrique' => $salaireAnciennte->getRubrique(), 'natureContract' => $bordoreau->getNatureContract()]);
  175.                     $journalBulletinLg = new JournalBulletinLg();
  176.                     $journalBulletinLg->setRubrique($salaireAnciennte->getRubrique());
  177.                     $journalBulletinLg->setBulletin($bulletin);
  178.                     $journalBulletinLg->setMontant(round($montantSalaireAnciennteInitital $montantSalaireAnciennte2));
  179.                     $journalBulletinLg->setQte($pcompteComptable->getQte());
  180.                     $journalBulletinLg->setCodeComptable($pcompteComptable->getCompteComptable());
  181.                     $journalBulletinLg->setType($key);
  182.                     $journalBulletinLg->setSens($pcompteComptable->getSens());
  183.                     $this->entityManager->persist($journalBulletinLg);
  184.                     $this->charge += $journalBulletinLg->getMontant();
  185.                 }
  186.                 $montantSalaireBaseInitial $montantSalaireBase;
  187.                 $montantSalaireAnciennteInitital $montantSalaireAnciennte;
  188.             }
  189.         }
  190.         $type "netpaye";
  191.         $primesArrayInitital = [];
  192.         // initialize the montant for each prime 
  193.         foreach ($primes as $prime) {
  194.             array_push($primesArrayInitital, [
  195.                 'id' => $prime->getId(),
  196.                 'prime' => $prime,
  197.                 'montantInitial' => $prime->getMontant(),
  198.                 'montantFinal' => $prime->getMontant(),
  199.                 'montantMinus' => 0
  200.             ]);
  201.         }
  202.         usort($primesArrayInitital, fn ($a$b) => $a['montantInitial'] <=> $b['montantInitial']);
  203.         $halfMontantPretArray = [];
  204.         // calculate the montant for each prelevement 
  205.         $keyToRemove 'montantFinal';
  206.         // this array only for condition i keep the key to modify the montant thatt sould be removed in the original array primesArrayInitital
  207.         foreach ($prevelementCabs as $key => $prevelementCab) {
  208.             $filtredPrimesArrayInitital array_filter($primesArrayInitital, function ($subarray) use ($keyToRemove) {
  209.                 return $subarray[$keyToRemove] != 0;
  210.             });
  211.             if ($prevelementCab['montant'] > 0) {
  212.                 $nombrePrimes count($filtredPrimesArrayInitital);
  213.                 $details = [];
  214.                 if (count($filtredPrimesArrayInitital) > 0) {
  215.                     $halfMontantPret = (($prevelementCab['montant'] / count($filtredPrimesArrayInitital)));
  216.                     if ($this->hasMoreThanTwoDecimals($halfMontantPret)) {
  217.                         $halfMontantPret $this->roundUpToNDecimals($halfMontantPret2);
  218.                     }
  219.                     $reste 0;
  220.                     $montantMinusInitial 0;
  221.                     $montantDebit 0;
  222.                     foreach ($filtredPrimesArrayInitital as $key => $primeArray) {
  223.                         if ($primeArray['montantFinal'] == 0) {
  224.                             $nombrePrimes $nombrePrimes 1;
  225.                             $reste $halfMontantPret $primeArray['montantFinal'];
  226.                             if ($nombrePrimes == 0) {
  227.                                 $halfReste round(($reste 1), 2);
  228.                             } else {
  229.                                 $halfReste round(($reste $nombrePrimes), 2);
  230.                             }
  231.                             $halfMontantPret += $halfReste;
  232.                             $montant 0;
  233.                         } elseif ($primeArray['montantFinal'] < $halfMontantPret) {
  234.                             // echo $primeArray['montantFinal'] . '/'.$halfMontantPret;
  235.                             // die;
  236.                             $reste $halfMontantPret $primeArray['montantFinal'];
  237.                             $primesArrayInitital[$key]['montantMinus'] = $primeArray['montantFinal'];
  238.                             $montant $primeArray['montantFinal'];
  239.                             $primesArrayInitital[$key]['montantFinal'] = 0;
  240.                             $montantMinusInitial += $montant;
  241.                             $nombrePrimes $nombrePrimes 1;
  242.                             if ($nombrePrimes == 0) {
  243.                                 $halfReste round(($reste 1), 2);
  244.                             } else {
  245.                                 $halfReste = ($reste $nombrePrimes);
  246.                                 if ($this->hasMoreThanTwoDecimals($halfReste)) {
  247.                                     $halfReste $this->roundUpToNDecimals($halfReste2);
  248.                                 }
  249.                             }
  250.                             $halfMontantPret += $halfReste;
  251.                         } else {
  252.                             if ($prevelementCab['montant'] < $montantMinusInitial $halfMontantPret) {
  253.                                 $halfMontantPret round($prevelementCab['montant'] - $montantMinusInitial2);
  254.                             }
  255.                             $montant $halfMontantPret;
  256.                             $montantMinusInitial += $montant;
  257.                             $primesArrayInitital[$key]['montantMinus'] = round($primesArrayInitital[$key]['montantMinus'] + $halfMontantPret2);
  258.                             $primesArrayInitital[$key]['montantFinal'] = round($primesArrayInitital[$key]['montantFinal'] - $halfMontantPret2);
  259.                             $filtredPrimesArrayInitital[$key]['montantMinus'] = round($filtredPrimesArrayInitital[$key]['montantMinus'] + $halfMontantPret2);
  260.                             $filtredPrimesArrayInitital[$key]['montantFinal'] = round($filtredPrimesArrayInitital[$key]['montantFinal'] - $halfMontantPret2);
  261.                         }
  262.                         $montantDebit += $montant;
  263.                         array_push($details, [
  264.                             'prime' => $primeArray['prime'],
  265.                             'montant' => $montant
  266.                         ]);
  267.                     }
  268.                     // die;
  269.                     // check if prelevement not completed from primes then debit from base and anciennete
  270.                     $montantEcart $prevelementCab['montant'] - $montantDebit;
  271.                     if ($nombrePrimes == and $montantEcart  0) {
  272.                         $halfMontantPret round($montantEcart2);
  273.                         $halfMontant round(($montantEcart 2), 2);
  274.                         if ($halfMontant $halfMontant != $halfMontantPret) {
  275.                             $firstHalf $halfMontant;
  276.                             $secondHalf $halfMontantPret $halfMontant;
  277.                         } else {
  278.                             $firstHalf $secondHalf $halfMontant;
  279.                         }
  280.                         if ($firstHalf $montantSalaireAnciennte) {
  281.                             $minus round(($firstHalf $montantSalaireAnciennte), 2);
  282.                             $montantSalaireBaseMinus  round(($montantSalaireBase  - ($secondHalf $minus)), 2);
  283.                             $montantSalaireAnciennteMinus 0;
  284.                         } else {
  285.                             $montantSalaireBaseMinus  round(($montantSalaireBase $secondHalf), 2);
  286.                             $montantSalaireAnciennteMinus round(($montantSalaireAnciennte $firstHalf), 2);
  287.                         }
  288.                         array_push($details, [
  289.                             'prime' => $salaireBase,
  290.                             'montant' => round($montantSalaireBase $montantSalaireBaseMinus2)
  291.                         ]);
  292.                         if ($bordoreau->getNatureContract()->getType()->getId() == and $salaireAnciennte and $bordoreau->getType() == 'paie') {
  293.                             array_push($details, [
  294.                                 'prime' => $salaireAnciennte,
  295.                                 'montant' => round($montantSalaireAnciennte $montantSalaireAnciennteMinus2)
  296.                             ]);
  297.                         }
  298.                         $montantSalaireBase $montantSalaireBaseMinus;
  299.                         $montantSalaireAnciennte $montantSalaireAnciennteMinus;
  300.                     }
  301.                 } else {
  302.                     // $montantSalaireBase;
  303.                     // $montantSalaireAnciennteInitital;
  304.                     $halfMontantPret round($prevelementCab['montant'], 2);
  305.                     $halfMontant round(($prevelementCab['montant'] / 2), 2);
  306.                     if ($halfMontant $halfMontant != $halfMontantPret) {
  307.                         $firstHalf $halfMontant;
  308.                         $secondHalf $halfMontantPret $halfMontant;
  309.                     } else {
  310.                         $firstHalf $secondHalf $halfMontant;
  311.                     }
  312.                     if ($firstHalf $montantSalaireAnciennte) {
  313.                         $minus round(($firstHalf $montantSalaireAnciennte), 2);
  314.                         $montantSalaireBaseMinus  round(($montantSalaireBase  - ($secondHalf $minus)), 2);
  315.                         $montantSalaireAnciennteMinus 0;
  316.                     } else {
  317.                         $montantSalaireBaseMinus  round(($montantSalaireBase $secondHalf), 2);
  318.                         $montantSalaireAnciennteMinus round(($montantSalaireAnciennte $firstHalf), 2);
  319.                     }
  320.                     array_push($details, [
  321.                         'prime' => $salaireBase,
  322.                         'montant' => round($montantSalaireBase $montantSalaireBaseMinus2)
  323.                     ]);
  324.                     if ($bordoreau->getNatureContract()->getType()->getId() == and $salaireAnciennte and $bordoreau->getType() == 'paie') {
  325.                         array_push($details, [
  326.                             'prime' => $salaireAnciennte,
  327.                             'montant' => round($montantSalaireAnciennte $montantSalaireAnciennteMinus2)
  328.                         ]);
  329.                     }
  330.                     $montantSalaireBase $montantSalaireBaseMinus;
  331.                     $montantSalaireAnciennte $montantSalaireAnciennteMinus;
  332.                 }
  333.                 array_push($halfMontantPretArray, [
  334.                     'id' => $prevelementCab['id'],
  335.                     'prelevement' => $prevelementCab,
  336.                     'montant' => $halfMontantPret,
  337.                     'montantInitial' => $prevelementCab['montant'],
  338.                     'details' => $details
  339.                 ]);
  340.             }
  341.         }
  342.         // echo json_encode($halfMontantPretArray);
  343.         // die;
  344.         foreach ($primesArrayInitital as $primesArray) {
  345.             $pcompteComptable $this->entityManager->getRepository(PCompteComptable::class)->findOneBy(['rubrique' => $primesArray['prime']->getRubrique(), 'natureContract' => $bordoreau->getNatureContract()]);
  346.             $journalBulletinLg = new JournalBulletinLg();
  347.             $journalBulletinLg->setRubrique($primesArray['prime']->getRubrique());
  348.             $journalBulletinLg->setBulletin($bulletin);
  349.             if (count($halfMontantPretArray) == 0) {
  350.                 $journalBulletinLg->setMontant(round($primesArray['montantInitial'], 2));
  351.             } else {
  352.                 $journalBulletinLg->setMontant(round($primesArray['montantFinal'], 2));
  353.             }
  354.             $journalBulletinLg->setQte($pcompteComptable->getQte());
  355.             $journalBulletinLg->setCodeComptable($pcompteComptable->getCompteComptable());
  356.             $journalBulletinLg->setType($type);
  357.             $journalBulletinLg->setSens($pcompteComptable->getSens());
  358.             $this->entityManager->persist($journalBulletinLg);
  359.             $this->charge += $journalBulletinLg->getMontant();
  360.         }
  361.         // echo json_decode($prevelements);die;
  362.         foreach ($prevelements as $prevelement) {
  363.             // echo json_decode($prevelement['rubrique_id']);
  364.             // die;
  365.             $rubrique $this->entityManager->getRepository(Prubrique::class)->find($prevelement['rubrique_id']);
  366.             $pcompteComptable $this->entityManager->getRepository(PCompteComptable::class)->findOneBy(['rubrique' => $rubrique'natureContract' => $bordoreau->getNatureContract()]);
  367.             $journalBulletinLg = new JournalBulletinLg();
  368.             $journalBulletinLg->setRubrique($rubrique);
  369.             $journalBulletinLg->setBulletin($bulletin);
  370.             $journalBulletinLg->setMontant($prevelement['montant']);
  371.             $journalBulletinLg->setQte($pcompteComptable->getQte());
  372.             $journalBulletinLg->setCodeComptable($pcompteComptable->getCompteComptable());
  373.             $journalBulletinLg->setType($type);
  374.             $journalBulletinLg->setSens($pcompteComptable->getSens());
  375.             if ($bordoreau->getDevise() && $bordoreau->getDevise()->getId() != 1) {
  376.                 $journalBulletinLg->setMontantDevise($prevelement['montantDevise']);
  377.             }
  378.             $this->entityManager->persist($journalBulletinLg);
  379.             $this->charge -= $journalBulletinLg->getMontant();
  380.         }
  381.         $pcompteComptable $this->entityManager->getRepository(PCompteComptable::class)->findOneBy(['rubrique' => $salaireBase->getRubrique(), 'natureContract' => $bordoreau->getNatureContract()]);
  382.         $journalBulletinLg = new JournalBulletinLg();
  383.         $journalBulletinLg->setRubrique($salaireBase->getRubrique());
  384.         $journalBulletinLg->setBulletin($bulletin);
  385.         $journalBulletinLg->setMontant(round($montantSalaireBase2));
  386.         $journalBulletinLg->setQte($pcompteComptable->getQte());
  387.         $journalBulletinLg->setCodeComptable($pcompteComptable->getCompteComptable());
  388.         $journalBulletinLg->setType($type);
  389.         $journalBulletinLg->setSens($pcompteComptable->getSens());
  390.         if ($bordoreau->getDevise() && $bordoreau->getDevise()->getId() != 1) {
  391.             $journalBulletinLg->setMontantDevise($montantSalaireBaseDevise);
  392.         }
  393.         $this->entityManager->persist($journalBulletinLg);
  394.         $this->charge += $journalBulletinLg->getMontant();
  395.         if ($bordoreau->getNatureContract()->getType()->getId() == and $bordoreau->getType() == 'paie') {
  396.             if(!$salaireAnciennte) {
  397.                 dd($salaireAnciennte$bulletin);
  398.             }
  399.             $pcompteComptable $this->entityManager->getRepository(PCompteComptable::class)->findOneBy(['rubrique' => $salaireAnciennte->getRubrique(), 'natureContract' => $bordoreau->getNatureContract()]);
  400.             $journalBulletinLg = new JournalBulletinLg();
  401.             $journalBulletinLg->setRubrique($salaireAnciennte->getRubrique());
  402.             $journalBulletinLg->setBulletin($bulletin);
  403.             $journalBulletinLg->setMontant(round($montantSalaireAnciennte2));
  404.             $journalBulletinLg->setQte($pcompteComptable->getQte());
  405.             $journalBulletinLg->setCodeComptable($pcompteComptable->getCompteComptable());
  406.             $journalBulletinLg->setType($type);
  407.             $journalBulletinLg->setSens($pcompteComptable->getSens());
  408.             $this->entityManager->persist($journalBulletinLg);
  409.             $this->charge += $journalBulletinLg->getMontant();
  410.         }
  411.         foreach ($halfMontantPretArray as $halfMontantPret) {
  412.             $rubrique $this->entityManager->getRepository(Prubrique::class)->find($halfMontantPret['prelevement']['rubrique_id']);
  413.             $type $rubrique->getDesignation();
  414.             foreach ($halfMontantPret['details'] as $det) {
  415.                 $pcompteComptable $this->entityManager->getRepository(PCompteComptable::class)->findOneBy(['rubrique' => $det['prime']->getRubrique(), 'natureContract' => $bordoreau->getNatureContract()]);
  416.                 $journalBulletinLg = new JournalBulletinLg();
  417.                 $journalBulletinLg->setRubrique($det['prime']->getRubrique());
  418.                 $journalBulletinLg->setBulletin($bulletin);
  419.                 $journalBulletinLg->setMontant($det['montant']);
  420.                 $journalBulletinLg->setQte($pcompteComptable->getQte());
  421.                 $journalBulletinLg->setCodeComptable($pcompteComptable->getCompteComptable());
  422.                 $journalBulletinLg->setType($type);
  423.                 $journalBulletinLg->setSens($pcompteComptable->getSens());
  424.                 $this->entityManager->persist($journalBulletinLg);
  425.                 $this->charge += $journalBulletinLg->getMontant();
  426.             }
  427.             $pcompteComptable $this->entityManager->getRepository(PCompteComptable::class)->findOneBy(['rubrique' => $rubrique'natureContract' => $bordoreau->getNatureContract()]);
  428.             $journalBulletinLg = new JournalBulletinLg();
  429.             $journalBulletinLg->setRubrique($rubrique);
  430.             $journalBulletinLg->setBulletin($bulletin);
  431.             $journalBulletinLg->setMontant($halfMontantPret['montantInitial']);
  432.             $journalBulletinLg->setQte($pcompteComptable->getQte());
  433.             $journalBulletinLg->setCodeComptable($pcompteComptable->getCompteComptable());
  434.             $journalBulletinLg->setType($type);
  435.             $journalBulletinLg->setSens($pcompteComptable->getSens());
  436.             $this->entityManager->persist($journalBulletinLg);
  437.             $this->charge -= $journalBulletinLg->getMontant();
  438.         }
  439.     }
  440.     function hasMoreThanTwoDecimals($number)
  441.     {
  442.         // Convert the number to a string to handle both integers and floats
  443.         $numberStr strval($number);
  444.         // Use a regular expression to check if the number has more than two decimals
  445.         // The pattern matches a dot (decimal point), followed by at most two digits
  446.         return preg_match('/\.\d{3,}/'$numberStr) === 1;
  447.     }
  448.     function roundUpToNDecimals($number$decimals)
  449.     {
  450.         $multiplier pow(10$decimals);
  451.         return ceil($number $multiplier) / $multiplier;
  452.     }
  453. }