/** * Clôture d'un decompte * * @param $marcheId * @param $decompteId * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function clotureAction($marcheId, $decompteId) { $this->verifyAccess(); $em = $this->getDoctrine()->getManager(); $decompte = $em->getRepository('LaisoArmBundle:Decompte')->find($decompteId); if (!$decompte) { throw new NotFoundHttpException('Unable to find Decompte entity'); } $allowed = true; if (count($decompte->getAttachements()) == 0) { $allowed = false; } for ($k = sizeof($decompte->getAttachements()) - 1; $k >= 0 && ($allowed = true); $k--) { if ($attachement = $decompte->getAttachements()[$k]->getValide() == false) { $allowed = false; } } if ($allowed) { $decompte->setFerme(true); $em->persist($decompte); $em->flush(); $delai = $decompte->getAvenant()->getDelai(); if ($decompte->getNumero() == ceil($delai)) { /** @var \Laiso\ArmBundle\Entity\Attachement $dernierAttachement */ $dernierAttachement = $decompte->getAttachements()[count($decompte->getAttachements()) - 1]; $restitution = new Attachement(); $restitution->setType('RESTITUTION'); $restitution->setDateAttachement($decompte->getDateDecompte()); $restitution->setNumero($dernierAttachement->getNumero() + 1); $restitution->setDecompte($decompte); $restitution->setValide(true); $retenues = array(); $montant = 0.0; $attachements = $this->getAllAttachement($decompte->getAvenant()->getMarche(), $decompte); /** @var \Laiso\ArmBundle\Entity\Attachement $attachement */ foreach ($attachements as $attachement) { if ($attachement->isRetenue()) { array_push($retenues, $attachement); $montant += $attachement->getMontantHTVA(); } } $restitution->setMontantHTVA($montant); /** @var \Laiso\ArmBundle\Entity\Attachement $retenue */ foreach ($retenues as $retenue) { $retenue->setAttachement($restitution); $em->persist($retenue); } $em->persist($restitution); $em->flush(); $this->addFlash('success', 'Attachement de restitution de retenues de garanties créé avec succès'); } } else { $this->addFlash('error', 'Veuillez valider tous les attachements du décompte n° ' . $decompte->getNumero() . ' avant de le clôturer.'); } $decompte = $decompte->selfUpdate(); $em->persist($decompte); $em->flush(); return $this->redirect($this->generateUrl('decompte_show', array('decompteId' => $decompteId, 'marcheId' => $marcheId))); }
/** * @param Attachement $attachement * @return Attachement */ private function handleRetenue($attachement) { $retenue = new Attachement(); $retenue->setNumero($attachement->getNumero() + 1); $retenue->setDateAttachement($attachement->getDateAttachement()); $retenue->setDecompte($attachement->getDecompte()); $retenue->setType('RETENUE'); $retenue->setValide(true); $montantPartiel = 0.0; $em = $this->getDoctrine()->getManager(); $em->persist($retenue); $attachement->setRetenue($retenue); /** @var \Laiso\ArmBundle\Entity\ConsistanceAttachement $consistance */ foreach ($attachement->getConsistances() as $consistance) { $consistanceAttachement = new ConsistanceAttachement(); $consistanceAttachement->setAttachement($retenue); $consistanceAttachement->setLibelle($consistance->getLibelle()); $consistanceAttachement->setType($consistance->getType()); $em->persist($consistanceAttachement); /** @var \laiso\ArmBundle\Entity\LigneAttachement $ligne */ foreach ($consistance->getLignes() as $ligne) { if ($ligne->getLigneDqe()->getPrix()->getSerie()->getCategorie()->getNumero() > 100) { $ligneAttachement = new LigneAttachement(); $ligneAttachement->setLigneDqe($ligne->getLigneDqe()); $ligneAttachement->setConsistance($consistanceAttachement); $ligneAttachement->setQuantite($ligne->getQuantite()); $ligneAttachement->setQuantiteAnterieure($ligne->getQuantiteAnterieure()); $m = $ligneAttachement->getQuantite() * $ligneAttachement->getLigneDqe()->getPrix()->getPrixUnitaire(); $montantPartiel += $m; $em->persist($ligneAttachement); } } } $retenue->setMontantHTVA($montantPartiel / 10.0); $this->addFlash('success', 'Retenue de garantie créée avec succès'); $em->flush(); return $retenue; }