Skip to content

Instantly share code, notes, and snippets.

@Bakhshi-Faisal
Created April 24, 2019 08:55
Show Gist options
  • Save Bakhshi-Faisal/bd459aab6ef0e8566c5fceb0789655af to your computer and use it in GitHub Desktop.
Save Bakhshi-Faisal/bd459aab6ef0e8566c5fceb0789655af to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Etat
*
* @ORM\Table(name="etat")
* @ORM\Entity(repositoryClass="AppBundle\Repository\EtatRepository")
*/
class Etat
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="libelle", type="string", length=255)
*/
private $libelle;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set libelle
*
* @param string $libelle
*
* @return Etat
*/
public function setLibelle($libelle)
{
$this->libelle = $libelle;
return $this;
}
/**
* Get libelle
*
* @return string
*/
public function getLibelle()
{
return $this->libelle;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints\Date;
/**
* FicheFrais
*
* @ORM\Table(name="fiche_frais")
* @ORM\Entity(repositoryClass="AppBundle\Repository\FicheFraisRepository")
*/
class FicheFrais
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\SequenceGenerator(sequenceName="id", initialValue=250000)
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var User
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User",cascade={"remove"})
* @ORM\JoinColumn(name="idUtilisateur",referencedColumnName="id",nullable=true,onDelete="CASCADE")
*/
private $idUtilisateur;
/**
* @var string
*
* @ORM\Column(name="moisAnne", type="string", length=255,nullable=true)
*
*/
private $moisAnne;
/**
* @var int
* @ORM\Column(name="nbJustificatif",type="integer",length=255)
*/
private $nbJustificatif;
/**
* @var float
* @ORM\Column(name="montantValide",type="float",length=255)
*/
private $montantValide;
/**
* @var DateTime
* @ORM\Column(name="dateModif",type="date",length=255)
*/
private $dateModif;
/**
* @var Etat
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Etat",cascade={"remove"})
* @ORM\JoinColumn(name="id_etat",referencedColumnName="id",nullable=true,onDelete="CASCADE")
*/
private $id_etat;
///exp correspend à ligne frais hors forfait
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\LigneFraisHorsForfait", mappedBy="project", cascade={"persist"},orphanRemoval=true)
*/
private $exp;
private $mois;
private $anne;
private $libelleFrais;
public function __construct()
{
$this->exp = new ArrayCollection();
$this->setDateModif(true);
$this->dateModif = new \DateTime("now");
}
/**
* Add exp
*
* @param LigneFraisHorsForfait $exp
*
* @return FicheFrais
*/
public function addExp($exp)
{
$this->exp[] = $exp;
$exp->setProject($this);
return $this;
}
/**
* Remove exp
*
* @param LigneFraisHorsForfait $exp
*/
public function removeExp($exp)
{
$this->exp->removeElement($exp);
}
/**
* Get exp
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getExp()
{
return $this->exp;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param User $idUtilisateur
*/
public function setIdUtilisateur($idUtilisateur)
{
$this->idUtilisateur = $idUtilisateur;
}
/**
* @return User
*/
public function getIdUtilisateur()
{
return $this->idUtilisateur;
}
/**
* @return mixed
*/
public function getMoisAnne()
{
return $this->moisAnne;
}
/**
* @param mixed $moisAnne
*/
public function setMoisAnne($moisAnne)
{
$this->moisAnne = $moisAnne;
}
/**
* @return int
*/
public function getNbJustificatif()
{
return $this->nbJustificatif;
}
/**
* @param int $nbJustificatif
*/
public function setNbJustificatif($nbJustificatif)
{
$this->nbJustificatif = $nbJustificatif;
}
/**
* @return float
*/
public function getMontantValide()
{
return $this->montantValide;
}
/**
* @param float $montantValide
*/
public function setMontantValide($montantValide)
{
$this->montantValide = $montantValide;
}
/**
* @return Date
*/
public function getDateModif()
{
return $this->dateModif;
}
/**
* @param Date $dateModif
*/
public function setDateModif($dateModif)
{
$this->dateModif = $dateModif;
}
/**
* @return Etat
*/
public function getIdEtat()
{
return $this->id_etat;
}
/**
* @param User $id_etat
*/
public function setIdEtat($id_etat)
{
$this->id_etat = $id_etat;
}
//spilte form
//these objects are uesed but never saved in DataBase
/**
* @return mixed
*/
public function getMois()
{
return $this->mois;
}
/**
* @param mixed $mois
*/
public function setMois($mois)
{
$this->mois = $mois;
}
/**
* @return mixed
*/
public function getAnne()
{
return $this->anne;
}
/**
* @param mixed $anne
*/
public function setAnne($anne)
{
$this->anne = $anne;
}
/**
* @return mixed
*/
public function getLibelleFrais()
{
return $this->libelleFrais;
}
/**
* @param mixed $libelleFrais
*/
public function setLibelleFrais($libelleFrais)
{
$this->libelleFrais = $libelleFrais;
}
//Méthodes
public function __toString()
{
return Project::class;
}
}
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Etat;
use AppBundle\Entity\FicheFrais;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\Date;
/**
* Fichefrai controller.
*
* @Route("fichefrais")
*/
class FicheFraisController extends Controller
{
/**
* Lists all ficheFrai entities.
*
* @Route("/", name="fichefrais_index")
* @Method("GET")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$ficheFrais = $em->getRepository('AppBundle:FicheFrais')->findAll();
return $this->render('fichefrais/index.html.twig', array(
'ficheFrais' => $ficheFrais,
));
}
/**
* Creates a new ficheFrai entity.
*
* @Route("/new", name="fichefrais_new")
* @Method({"GET", "POST"})
*/
public function newAction(Request $request)
{
$ficheFrai = new FicheFrais();
$etat = new Etat();
$form = $this->createForm('AppBundle\Form\FicheFraisType', $ficheFrai);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//set month and year for new fiche
date_default_timezone_set('Europe/Paris');
$date = date('m/d/Y', time());
$array=explode("/",$date);
$month=$array[0];
$year=$array[2];
$ficheFrai->setMoisAnne($month."/".$year);
//set id_etat
$ficheFrai->setIdEtat(1);
//getting id user
$user = $this->get('security.token_storage')->getToken()->getUser();
$user->getUsername();
//set user id
$ficheFrai->setIdUtilisateur($user);
$em = $this->getDoctrine()->getManager();
$em->persist($ficheFrai);
$em->flush();
return $this->redirectToRoute('fichefrais_show', array('id' => $ficheFrai->getId()));
}
return $this->render('fichefrais/new.html.twig', array(
'ficheFrai' => $ficheFrai,
'form' => $form->createView(),
));
}
/**
* Finds and displays a ficheFrai entity.
*
* @Route("/{id}", name="fichefrais_show")
* @Method("GET")
*/
public function showAction(FicheFrais $ficheFrai)
{
$deleteForm = $this->createDeleteForm($ficheFrai);
return $this->render('fichefrais/show.html.twig', array(
'ficheFrai' => $ficheFrai,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing ficheFrai entity.
*
* @Route("/{id}/edit", name="fichefrais_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, FicheFrais $ficheFrai)
{
$deleteForm = $this->createDeleteForm($ficheFrai);
$editForm = $this->createForm('AppBundle\Form\FicheFraisType', $ficheFrai);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('fichefrais_edit', array('id' => $ficheFrai->getId()));
}
return $this->render('fichefrais/edit.html.twig', array(
'ficheFrai' => $ficheFrai,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a ficheFrai entity.
*
* @Route("/{id}", name="fichefrais_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, FicheFrais $ficheFrai)
{
$form = $this->createDeleteForm($ficheFrai);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($ficheFrai);
$em->flush();
}
return $this->redirectToRoute('fichefrais_index');
}
/**
* Creates a form to delete a ficheFrai entity.
*
* @param FicheFrais $ficheFrai The ficheFrai entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(FicheFrais $ficheFrai)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('fichefrais_delete', array('id' => $ficheFrai->getId())))
->setMethod('DELETE')
->getForm()
;
}
}
<?php
namespace AppBundle\Form;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class FicheFraisType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('mois',TextType::class,array('attr'=> [ 'readonly' => true ]))
->add('anne',TextType::class,array('attr'=> [ 'readonly' => true ]))
->add('nbJustificatif',TextType::class,array('label'=>false))
->add('montantValide')
->add('exp', CollectionType::class, [
'required'=>false,
'data_class'=>null,
'entry_type' => LigneFraisHorsForfaitType::class,
'entry_options' => [
'label' => false,
],
'by_reference' => false,
'allow_add' => true,
'allow_delete' => true,
'data_class'=> null,
'label'=>true
])
->add('libelleFrais', EntityType::class,array(
'label'=> false,
'class'=>'AppBundle\Entity\FraisForfait',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('r')
->orderBy('r.montant')
->orderBy('r.libelle', 'ASC');
},
"choice_label" => "libelle",
))
;
}/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\FicheFrais'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'appbundle_fichefrais';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment