1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| <?php
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\Prestation;
use App\Entity\Facture;
use App\Form\Type\FactureType;
class FactureController extends Controller
{
/**
* @Route("/facture", name="facture")
*/
public function index(Request $request, FileUploader $fileUploader)
{
$facture = new Facture();
$form = $this->createForm(FactureType::class, $facture);
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
if($form->isSubmitted() && $form->isValid()){
$em->persist($facture);
$em->flush();
$this->addFlash('success', 'Votre facture à bien été enregistrée.');
return $this->redirect($this->generateUrl('app_facture_list'));
}
return $this->render('facture/index.html.twig', [
'form'=>$form->createView(),'mainNavRegistration' => true, 'title' => 'Créer une facture'
]);
}
/**
* @return string
*/
private function generateUniqueFileName()
{
// md5() reduces the similarity of the file names generated by
// uniqid(), which is based on timestamps
return md5(uniqid());
}
/**
*@Route("facture/{id}", name="onefacture", requirements={"id"="\d+"})
*/
public function show($id)
{
$facture=$this->getDoctrine()
->getRepository(Facture::class)
->find($id);
if(!$facture){
throw $this->createNotFoundException('Aucune facture à l\'id '.$id);
}
return $this->render('facture/show.html.twig', ['facture' => $facture,
'mainNavRegistration' => true, 'title' => 'Afficher une facture'
]);
}
/**
*@Route("allfactures", name="allfactures")
*/
public function showAll()
{
$factures=$this->getDoctrine()
->getRepository(Facture::class)
->findAll();
if(!$factures){
throw $this->createNotFoundException('Aucune facture à l\'id');
}
return $this->render('facture/showAll.html.twig', ['factures' => $factures]);
}
} |
Partager