src/EventListener/JournalPaieListener.php line 31

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