src/Entity/Document.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DocumentRepository;
  4. use App\Tools\Fnc;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=DocumentRepository::class)
  10.  */
  11. class Document
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $type_document;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity=Projet::class, inversedBy="documents")
  25.      * @ORM\JoinColumn(nullable=false)
  26.      */
  27.     private $projet;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity=Societe::class, inversedBy="documents")
  30.      * @ORM\JoinColumn(nullable=false)
  31.      */
  32.     private $tiers;
  33.     /**
  34.      * @ORM\Column(type="string", length=255, nullable=true)
  35.      */
  36.     private $statut;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=true)
  39.      */
  40.     private $reference;
  41.     /**
  42.      * @ORM\Column(type="string", length=255, nullable=true)
  43.      */
  44.     private $num_piece;
  45.     /**
  46.      * @ORM\Column(type="datetime")
  47.      */
  48.     private $date_crea;
  49.     /**
  50.      * @ORM\Column(type="integer")
  51.      */
  52.     private $user_crea;
  53.     /**
  54.      * @ORM\Column(type="datetime", nullable=true)
  55.      */
  56.     private $date_modif;
  57.     /**
  58.      * @ORM\Column(type="integer", nullable=true)
  59.      */
  60.     private $user_modif;
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity=Adresse::class)
  63.      */
  64.     private $adresse;
  65.     /**
  66.      * @ORM\Column(type="float")
  67.      */
  68.     private $montant_ht;
  69.     /**
  70.      * @ORM\Column(type="float")
  71.      */
  72.     private $montant_tva;
  73.     /**
  74.      * @ORM\Column(type="datetime", nullable=true)
  75.      */
  76.     private $date_envoi;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity=DocumentLigne::class, mappedBy="document", cascade={"persist"})
  79.      */
  80.     private $documentLignes;
  81.     /**
  82.      * @ORM\Column(type="datetime", nullable=true)
  83.      */
  84.     private $date_paiement;
  85.     /**
  86.      * @ORM\Column(type="datetime", nullable=true)
  87.      */
  88.     private $date_echeance;
  89.     /**
  90.      * @ORM\Column(type="string", length=255, nullable=true)
  91.      */
  92.     private $contact;
  93.     /**
  94.      * @ORM\Column(type="integer", nullable=true)
  95.      */
  96.     private $id_doc_origine;
  97.     /**
  98.      * @ORM\Column(type="text", nullable=true)
  99.      */
  100.     private $commentaire;
  101.     /**
  102.      * @ORM\Column(type="date", nullable=true)
  103.      */
  104.     private $date_bdc;
  105.     /**
  106.      * @ORM\Column(type="string", length=255, nullable=true)
  107.      */
  108.     private $lib_projet;
  109.     /**
  110.      * @ORM\ManyToOne(targetEntity=Tiers::class, inversedBy="ndf")
  111.      */
  112.     private $salarie;
  113.     /**
  114.      * @ORM\Column(type="date", nullable=true)
  115.      */
  116.     private $date_ndf;
  117.     /**
  118.      * @ORM\Column(type="string", length=255, nullable=true)
  119.      */
  120.     private $libelle;
  121.     /**
  122.      * @ORM\Column(type="string", length=255, nullable=true)
  123.      */
  124.     private $condition_reglement;
  125.     public function __construct()
  126.     {
  127.         $this->documentLignes = new ArrayCollection();
  128.     }
  129.     public function getId(): ?int
  130.     {
  131.         return $this->id;
  132.     }
  133.     public function getTypeDocument(): ?string
  134.     {
  135.         return $this->type_document;
  136.     }
  137.     public function setTypeDocument(string $type_document): self
  138.     {
  139.         $this->type_document $type_document;
  140.         return $this;
  141.     }
  142.     public function getProjet(): ?Projet
  143.     {
  144.         return $this->projet;
  145.     }
  146.     public function setProjet(?Projet $projet): self
  147.     {
  148.         $this->projet $projet;
  149.         return $this;
  150.     }
  151.     public function getTiers(): ?Societe
  152.     {
  153.         return $this->tiers;
  154.     }
  155.     public function setTiers(?Societe $tiers): self
  156.     {
  157.         $this->tiers $tiers;
  158.         return $this;
  159.     }
  160.     public function getStatut(): ?string
  161.     {
  162.         return $this->statut;
  163.     }
  164.     public function setStatut(?string $statut): self
  165.     {
  166.         $this->statut $statut;
  167.         return $this;
  168.     }
  169.     public function getReference(): ?string
  170.     {
  171.         return $this->reference;
  172.     }
  173.     public function setReference(?string $reference): self
  174.     {
  175.         $this->reference $reference;
  176.         return $this;
  177.     }
  178.     public function getNumPiece(): ?string
  179.     {
  180.         return $this->num_piece;
  181.     }
  182.     public function setNumPiece(?string $num_piece): self
  183.     {
  184.         $this->num_piece $num_piece;
  185.         return $this;
  186.     }
  187.     public function getDateCrea(): ?\DateTimeInterface
  188.     {
  189.         return $this->date_crea;
  190.     }
  191.     public function setDateCrea(\DateTimeInterface $date_crea): self
  192.     {
  193.         $this->date_crea $date_crea;
  194.         return $this;
  195.     }
  196.     public function getUserCrea(): ?int
  197.     {
  198.         return $this->user_crea;
  199.     }
  200.     public function setUserCrea(int $user_crea): self
  201.     {
  202.         $this->user_crea $user_crea;
  203.         return $this;
  204.     }
  205.     public function getDateModif(): ?\DateTimeInterface
  206.     {
  207.         return $this->date_modif;
  208.     }
  209.     public function setDateModif(?\DateTimeInterface $date_modif): self
  210.     {
  211.         $this->date_modif $date_modif;
  212.         return $this;
  213.     }
  214.     public function getUserModif(): ?int
  215.     {
  216.         return $this->user_modif;
  217.     }
  218.     public function setUserModif(?int $user_modif): self
  219.     {
  220.         $this->user_modif $user_modif;
  221.         return $this;
  222.     }
  223.     public function getAdresse(): ?Adresse
  224.     {
  225.         return $this->adresse;
  226.     }
  227.     public function setAdresse(?Adresse $adresse): self
  228.     {
  229.         $this->adresse $adresse;
  230.         return $this;
  231.     }
  232.     public function getMontantHt(): ?float
  233.     {
  234.         return $this->montant_ht;
  235.     }
  236.     public function setMontantHt(float $montant_ht): self
  237.     {
  238.         $this->montant_ht $montant_ht;
  239.         return $this;
  240.     }
  241.     public function getMontantTva(): ?float
  242.     {
  243.         return $this->montant_tva;
  244.     }
  245.     public function setMontantTva(float $montant_tva): self
  246.     {
  247.         $this->montant_tva $montant_tva;
  248.         return $this;
  249.     }
  250.     public function getDateEnvoi(): ?\DateTimeInterface
  251.     {
  252.         return $this->date_envoi;
  253.     }
  254.     public function setDateEnvoi(?\DateTimeInterface $date_envoi): self
  255.     {
  256.         $this->date_envoi $date_envoi;
  257.         return $this;
  258.     }
  259.     /**
  260.      * @return Collection<int, DocumentLigne>
  261.      */
  262.     public function getDocumentLignes(): Collection
  263.     {
  264.         return $this->documentLignes;
  265.     }
  266.     public function addDocumentLigne(DocumentLigne $documentLigne): self
  267.     {
  268.         if (!$this->documentLignes->contains($documentLigne)) {
  269.             $this->documentLignes[] = $documentLigne;
  270.             $documentLigne->setDocument($this);
  271.         }
  272.         return $this;
  273.     }
  274.     public function removeDocumentLigne(DocumentLigne $documentLigne): self
  275.     {
  276.         if ($this->documentLignes->removeElement($documentLigne)) {
  277.             // set the owning side to null (unless already changed)
  278.             if ($documentLigne->getDocument() === $this) {
  279.                 $documentLigne->setDocument(null);
  280.             }
  281.         }
  282.         return $this;
  283.     }
  284.     public function orderDocLigneByTauxTva()
  285.     {
  286.         $this->documentLignes = new ArrayCollection(
  287.             Fnc::array_orderby($this->getDocumentLignes()->toArray(), 'getTauxTva()'SORT_ASC)
  288.         );
  289.     }
  290.     public function getLibelleFirstLigne(): string
  291.     {
  292.         if(0===$this->getDocumentLignes()->count()) return 'Aucune ligne dans le document';
  293.         return array_reduce(
  294.             $this->getDocumentLignes()->toArray(),
  295.             function ($lib$ligne){
  296.                 $libelle $ligne->getLibelle();
  297.                 if('Avance'!==$libelle) {
  298.                     $libelle .= ' - ';
  299.                     $libelle .= $ligne->getTauxTva() * 100;
  300.                     $libelle .= '%';
  301.                 } else {
  302.                     $libelle .= ' : ';
  303.                     $libelle .= $ligne->getPuht();
  304.                     $libelle .= '€';
  305.                 }
  306.                 if(empty($lib)) return $libelle;
  307.                 else return $lib'<br>' $libelle;
  308.             }
  309.         );
  310.     }
  311.     public function getDatePaiement(): ?\DateTimeInterface
  312.     {
  313.         return $this->date_paiement;
  314.     }
  315.     public function setDatePaiement(?\DateTimeInterface $date_paiement): self
  316.     {
  317.         $this->date_paiement $date_paiement;
  318.         return $this;
  319.     }
  320.     public function getDateEcheance(): ?\DateTimeInterface
  321.     {
  322.         return $this->date_echeance;
  323.     }
  324.     public function setDateEcheance(?\DateTimeInterface $date_echeance): self
  325.     {
  326.         $this->date_echeance $date_echeance;
  327.         return $this;
  328.     }
  329.     public function getContact(): ?string
  330.     {
  331.         return $this->contact;
  332.     }
  333.     public function setContact(?string $contact): self
  334.     {
  335.         $this->contact $contact;
  336.         return $this;
  337.     }
  338.     public function getVentilationTVA(): array
  339.     {
  340.         $ventilation = array();
  341.         $ligneList $this->getDocumentLignes()->toArray();
  342.         foreach ($ligneList as $ligne){
  343.             if('Avance'===$ligne->getLibelle()) continue;
  344.             $txTva $ligne->getTauxTva();
  345.             if(!isset($ventilation[$txTva])) $ventilation[$txTva] = (object) array(
  346.                 'taux_tva' => $txTva*100,
  347.                 'montant_tva' => 0,
  348.             );
  349.             $ventilation[$txTva]->montant_tva+= $ligne->getMontantTva();
  350.         }
  351.         ksort($ventilation);
  352.         return $ventilation;
  353.     }
  354.     public function performMontant(): self
  355.     {
  356.         $montantHT 0;
  357.         $montantTVA 0;
  358.         $ligneList $this->getDocumentLignes()->toArray();
  359.         foreach ($ligneList as $ligne){
  360.             $montantHT+= $ligne->getMontantHt();
  361.             $montantTVA+= $ligne->getMontantTva();
  362.         }
  363.         $this->setMontantHt($montantHT);
  364.         $this->setMontantTva($montantTVA);
  365.         return $this;
  366.     }
  367.     public function initDocVierge(Projet $projetstring $typeDoc): self
  368.     {
  369.         switch ($typeDoc){
  370.             case 'FACTURE PROFORMA':
  371.                 $adresseClient $projet->getSociete()->getAdresses()->last();
  372.                 $this->setNumPiece($projet->getNumProd() .'-xxxxxxx')
  373.                     ->setTiers$projet->getSociete() )
  374.                     ->setAdresse($adresseClient)
  375.                     ->setDateBdc($projet->getDateCrea())
  376.                 ;
  377.                 break;
  378.             case 'COMMANDE PRESTATAIRE':
  379.                 $societe = new Societe();
  380.                 $societe->setLibSociete('Nouvelle commande prestataire');
  381.                 $tiers = new Tiers();
  382.                 $tiers->addSociete($societe)
  383.                     ->setPrenomTiers('-')
  384.                     ->setEmailTiers('-')
  385.                     ->setTelFixeTiers('-')
  386.                     ->setTelPortableTiers('-')
  387.                 ;
  388.                 $this->setTiers($societe)
  389.                     ->setStatut('Non Payée')
  390.                 ;
  391.                 $ligne = new DocumentLigne();
  392.                 $ligne->setTauxTva(0.2);
  393.                 $this->addDocumentLigne($ligne);
  394.                 break;
  395.             case 'NDF':
  396.                 break;
  397.             default:
  398.                 break;
  399.         }
  400.         $this->setProjet($projet)
  401.             ->setDateCrea(new \DateTime())
  402.             ->setTypeDocument($typeDoc)
  403.             ->setMontantHt(0)
  404.         ;
  405.         return $this;
  406.     }
  407.     public function getIdDocOrigine(): ?int
  408.     {
  409.         return $this->id_doc_origine;
  410.     }
  411.     public function setIdDocOrigine(?int $id_doc_origine): self
  412.     {
  413.         $this->id_doc_origine $id_doc_origine;
  414.         return $this;
  415.     }
  416.     public function getCommentaire(): ?string
  417.     {
  418.         return $this->commentaire;
  419.     }
  420.     public function setCommentaire(?string $commentaire): self
  421.     {
  422.         $this->commentaire $commentaire;
  423.         return $this;
  424.     }
  425.     public function getDateBdc(): ?\DateTimeInterface
  426.     {
  427.         return $this->date_bdc;
  428.     }
  429.     public function setDateBdc(?\DateTimeInterface $date_bdc): self
  430.     {
  431.         $this->date_bdc $date_bdc;
  432.         return $this;
  433.     }
  434.     public function getLibProjet(): ?string
  435.     {
  436.         return $this->lib_projet;
  437.     }
  438.     public function setLibProjet(?string $lib_projet): self
  439.     {
  440.         $this->lib_projet $lib_projet;
  441.         return $this;
  442.     }
  443.     public function getSalarie(): ?Tiers
  444.     {
  445.         return $this->salarie;
  446.     }
  447.     public function setSalarie(?Tiers $salarie): self
  448.     {
  449.         $this->salarie $salarie;
  450.         return $this;
  451.     }
  452.     public function getDateNdf(): ?\DateTimeInterface
  453.     {
  454.         return $this->date_ndf;
  455.     }
  456.     public function setDateNdf(?\DateTimeInterface $date_ndf): self
  457.     {
  458.         $this->date_ndf $date_ndf;
  459.         return $this;
  460.     }
  461.     public function getLibelle(): ?string
  462.     {
  463.         return $this->libelle;
  464.     }
  465.     public function setLibelle(?string $libelle): self
  466.     {
  467.         $this->libelle $libelle;
  468.         return $this;
  469.     }
  470.     public function groupNdfBySalarie($ndfList): array
  471.     {
  472.         $salarieList = [];
  473.         /** @var Document $ndf */
  474.         foreach ($ndfList as $ndf){
  475.             $idSalarie $ndf->getSalarie()->getId();
  476.             if(!isset($salarieList[$idSalarie])){
  477.                 $salarieList[$idSalarie] = (object)[
  478.                     'id_projet' => $ndf->getProjet()->getId(),
  479.                     'id_salarie' => $idSalarie,
  480.                     'salarie' => $ndf->getSalarie(),
  481.                     'total_ht' => 0,
  482.                     'total_ttc' => 0,
  483.                     'select_option' => [],
  484.                     'ndf_list' => [],
  485.                 ];
  486.             }
  487.             $salarieList[$idSalarie]->total_ht+= $ndf->getMontantHt();
  488.             $salarieList[$idSalarie]->total_ttc+= $ndf->getMontantHt() + $ndf->getMontantTva();
  489.             $salarieList[$idSalarie]->ndf_list[]= $ndf;
  490.             $mois $ndf->getDateNdf()->format('Y-m');
  491.             if(!isset($salarieList[$idSalarie]->select_option[$mois])){
  492.                 $annee $ndf->getDateNdf()->format('Y');
  493.                 $libMois Fnc::getLibMois(
  494.                     $ndf->getDateNdf()->format('m')
  495.                 );
  496.                 $salarieList[$idSalarie]->select_option[$mois] = '<option value="'$mois .'">'$libMois .' '$annee.'</option>';
  497.                 $salarieList[$idSalarie]->select_option[$mois.'-en_GB'] = '<option value="'$mois .'&lang=en_GB">'$libMois .' '$annee.' en 🇬🇧</option>';
  498.             }
  499.             ksort($salarieList[$idSalarie]->select_option);
  500.         }
  501.         return $salarieList;
  502.     }
  503.     public function getConditionReglement(): ?string
  504.     {
  505.         return $this->condition_reglement;
  506.     }
  507.     public function setConditionReglement(?string $condition_reglement): self
  508.     {
  509.         $this->condition_reglement $condition_reglement;
  510.         return $this;
  511.     }
  512. }