src/Entity/Reception.php line 20

Open in your IDE?
  1. <?php
  2. /**
  3.  * Reception.php
  4.  * Created by Stéphane Brun
  5.  * Date: 10/07/2018 at 08:28
  6.  */
  7. namespace App\Entity;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\ReceptionRepository")
  12.  * @ORM\Table(name="reception",
  13.  *    uniqueConstraints={
  14.  *        @ORM\UniqueConstraint(name="facture_unique", columns={"company_id", "fournisseur_id", "factureFournisseur"})
  15.  *    }
  16.  * )
  17.  */
  18. class Reception
  19. {
  20.     const HISTORY_WATCH = array(
  21.         'type' => 'Type',
  22.         'date' => 'Date',
  23.         'indicatif' => 'Indicatif',
  24.         'dateLimite' => 'Date limite',
  25.         'descriptif' => 'Descriptif',
  26.         'completee' => 'Complétée',
  27.     );
  28.     const FERME 1;
  29.     const DEPOT 2;
  30.     const MISE_EN_PLACE 3;
  31.     const OFFICE 4;
  32.     const SOLDE 4;
  33.     //Used in import void provider
  34.     const INDICATIF_DIFF_MONTH 4;
  35.     /**
  36.      * @ORM\Column(type="integer")
  37.      * @ORM\Id
  38.      * @ORM\GeneratedValue(strategy="AUTO")
  39.      */
  40.     protected $id;
  41.     /**
  42.      * @ORM\Column(name="date", type="datetime")
  43.      */
  44.     protected $date;
  45.     /**
  46.      * @ORM\Column(name="date_limite", type="datetime", nullable=true)
  47.      */
  48.     protected $dateLimite;
  49.     /**
  50.      * @ORM\Column(name="indicatif", type="datetime", nullable=true)
  51.      */
  52.     protected $indicatif;
  53.     /**
  54.      * Many Features have One Product.
  55.      * @ORM\ManyToOne(targetEntity="Commande", inversedBy="receptions")
  56.      * @ORM\JoinColumn(name="commandesVisees", referencedColumnName="id")
  57.      */
  58.     protected $commandeVisee;
  59.     /**
  60.      * @ORM\Column(name="completee", type="boolean")
  61.      */
  62.     protected $completee false;
  63.     /**
  64.      * @ORM\Column(name="original", type="string", length=100, nullable=true)
  65.      */
  66.     protected $original;
  67.     /**
  68.      * @ORM\Column(name="descriptif", type="string", length=150, nullable=true)
  69.      */
  70.     protected $descriptif;
  71.     /**
  72.      * @ORM\Column(name="factureFTP", type="boolean")
  73.      */
  74.     protected $factureFTP false;
  75.     /**
  76.      * @ORM\Column(name="signature", type="string", length=5, nullable=true)
  77.      */
  78.     protected $signature;
  79.     /**
  80.      * has one Company
  81.      *
  82.      * @ORM\ManyToOne(targetEntity="App\Entity\Company")
  83.      * @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=true)
  84.      */
  85.     protected $company;
  86.     /**
  87.      * has one Fournisseurs
  88.      *
  89.      * @ORM\ManyToOne(targetEntity="App\Entity\Fournisseurs")
  90.      * @ORM\JoinColumn(name="fournisseur_id", referencedColumnName="id")
  91.      */
  92.     protected $fournisseur;
  93.     /**
  94.      * @ORM\Column(name="factureFournisseur", type="string", length=50)
  95.      */
  96.     protected $factureFournisseur;
  97.     /**
  98.      * has many ReceptionDetail
  99.      *
  100.      * @ORM\OneToMany(targetEntity="App\Entity\ReceptionDetail", mappedBy="reception", cascade={"persist", "remove"}, orphanRemoval=true)
  101.      * @ORM\OrderBy({"produit" = "ASC"})
  102.      */
  103.     protected $details;
  104.     /**
  105.      * has one ReceptionType
  106.      *
  107.      * @ORM\ManyToOne(targetEntity="App\Entity\ReceptionType")
  108.      * @ORM\JoinColumn(name="type_id", referencedColumnName="id")
  109.      */
  110.     protected $type;
  111.     /**
  112.      * has one SysUser
  113.      *
  114.      * @ORM\ManyToOne(targetEntity="App\Entity\SysUsers")
  115.      * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  116.      */
  117.     protected $user;
  118.     /**
  119.      * @ORM\Column(name="ftp_total_receive", type="integer", length=200, nullable=true)
  120.      */
  121.     protected $ftpTotalReceive 0;
  122.     /**
  123.      * @ORM\Column(name="ftp_total_net", type="float", length=200, nullable=true)
  124.      */
  125.     protected $ftpTotalNetNoTaxeAndTransport 0;
  126.     /**
  127.      * @ORM\Column(name="ftp_total_tps", type="float", length=200, nullable=true)
  128.      */
  129.     protected $ftpTotalTps 0;
  130.     /**
  131.      * @ORM\Column(name="ftp_total_tvq", type="float", length=200, nullable=true)
  132.      */
  133.     protected $ftpTotalTvq 0;
  134.     /**
  135.      * @ORM\Column(name="ftp_total_invoice", type="float", length=200, nullable=true)
  136.      */
  137.     protected $ftpTotalInvoice 0;
  138.     public function __construct()
  139.     {
  140.         $this->details = new ArrayCollection();
  141.         $this->date = new \DateTime();
  142.     }
  143.     /**
  144.      * @return mixed
  145.      */
  146.     public function getId()
  147.     {
  148.         return $this->id;
  149.     }
  150.     /**
  151.      * @return mixed
  152.      */
  153.     public function getDate()
  154.     {
  155.         return $this->date;
  156.     }
  157.     /**
  158.      * @param mixed $date
  159.      * @return Reception
  160.      */
  161.     public function setDate($date)
  162.     {
  163.         if (is_string($date)) {
  164.             $this->date = new \DateTime($date);
  165.         } else {
  166.             $this->date $date;
  167.         }
  168.         return $this;
  169.     }
  170.     /**
  171.      * @return mixed
  172.      */
  173.     public function getDateLimite()
  174.     {
  175.         return $this->dateLimite;
  176.     }
  177.     /**
  178.      * @param mixed $dateLimite
  179.      * @return Reception
  180.      */
  181.     public function setDateLimite($dateLimite)
  182.     {
  183.         $this->dateLimite $dateLimite;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return mixed
  188.      */
  189.     public function getIndicatif()
  190.     {
  191.         return $this->indicatif;
  192.     }
  193.     /**
  194.      * @param mixed $indicatif
  195.      * @return Reception
  196.      */
  197.     public function setIndicatif($indicatif)
  198.     {
  199.         $this->indicatif $indicatif;
  200.         return $this;
  201.     }
  202.     /**
  203.      * @return mixed
  204.      */
  205.     public function getCommandeVisee()
  206.     {
  207.         return $this->commandeVisee;
  208.     }
  209.     /**
  210.      * @param mixed $commandeVisee
  211.      */
  212.     public function setCommandeVisee($commandeVisee)
  213.     {
  214.         $this->commandeVisee $commandeVisee;
  215.     }
  216.     /**
  217.      * @return mixed
  218.      */
  219.     public function getCompletee()
  220.     {
  221.         return $this->completee;
  222.     }
  223.     /**
  224.      * @return mixed
  225.      */
  226.     public function isCompletee()
  227.     {
  228.         return $this->completee;
  229.     }
  230.     /**
  231.      * @param mixed $completee
  232.      * @return Reception
  233.      */
  234.     public function setCompletee($completee)
  235.     {
  236.         $this->completee $completee;
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return mixed
  241.      */
  242.     public function getOriginal()
  243.     {
  244.         return $this->original;
  245.     }
  246.     /**
  247.      * @param mixed $original
  248.      * @return Reception
  249.      */
  250.     public function setOriginal($original)
  251.     {
  252.         $this->original $original;
  253.         return $this;
  254.     }
  255.     /**
  256.      * @return mixed
  257.      */
  258.     public function getDescriptif()
  259.     {
  260.         return $this->descriptif;
  261.     }
  262.     /**
  263.      * @param mixed $descriptif
  264.      * @return Reception
  265.      */
  266.     public function setDescriptif($descriptif)
  267.     {
  268.         $this->descriptif $descriptif;
  269.         return $this;
  270.     }
  271.     /**
  272.      * @return mixed
  273.      */
  274.     public function getFactureFTP()
  275.     {
  276.         return $this->factureFTP;
  277.     }
  278.     /**
  279.      * @return mixed
  280.      */
  281.     public function isFactureFtp()
  282.     {
  283.         return $this->getFactureFTP();
  284.     }
  285.     /**
  286.      * @param mixed $factureFTP
  287.      * @return Reception
  288.      */
  289.     public function setFactureFTP($factureFTP)
  290.     {
  291.         $this->factureFTP $factureFTP;
  292.         return $this;
  293.     }
  294.     /**
  295.      * @return mixed
  296.      */
  297.     public function getSignature()
  298.     {
  299.         return $this->signature;
  300.     }
  301.     /**
  302.      * @param mixed $signature
  303.      * @return Reception
  304.      */
  305.     public function setSignature($signature)
  306.     {
  307.         $this->signature $signature;
  308.         return $this;
  309.     }
  310.     /**
  311.      * @return Fournisseurs
  312.      */
  313.     public function getFournisseur()
  314.     {
  315.         return $this->fournisseur;
  316.     }
  317.     /**
  318.      * @param Fournisseurs $fournisseur
  319.      * @return Reception
  320.      */
  321.     public function setFournisseur(Fournisseurs $fournisseur)
  322.     {
  323.         $this->fournisseur $fournisseur;
  324.         return $this;
  325.     }
  326.     /**
  327.      * @return mixed
  328.      */
  329.     public function getFactureFournisseur()
  330.     {
  331.         return $this->factureFournisseur;
  332.     }
  333.     /**
  334.      * @param mixed $factureFournisseur
  335.      * @return Reception
  336.      */
  337.     public function setFactureFournisseur($factureFournisseur)
  338.     {
  339.         $this->factureFournisseur $factureFournisseur;
  340.         return $this;
  341.     }
  342.     /**
  343.      * @return ReceptionType
  344.      */
  345.     public function getType()
  346.     {
  347.         return $this->type;
  348.     }
  349.     /**
  350.      * @param ReceptionType $type
  351.      * @return Reception
  352.      */
  353.     public function setType(ReceptionType $type)
  354.     {
  355.         $this->type $type;
  356.         return $this;
  357.     }
  358.     /**
  359.      * @return Company
  360.      */
  361.     public function getCompany()
  362.     {
  363.         return $this->company;
  364.     }
  365.     /**
  366.      * @param Company $company
  367.      * @return Reception
  368.      */
  369.     public function setCompany(Company $company)
  370.     {
  371.         $this->company $company;
  372.         return $this;
  373.     }
  374.     /**
  375.      * @return mixed
  376.      */
  377.     public function getDetails()
  378.     {
  379.         return $this->details;
  380.     }
  381.     /**
  382.      * @param mixed $details
  383.      * @return Reception
  384.      */
  385.     public function setDetails($details)
  386.     {
  387.         $this->details $details;
  388.         return $this;
  389.     }
  390.     /**
  391.      * @param ReceptionDetail $detail
  392.      * @return Reception
  393.      */
  394.     public function addDetail(ReceptionDetail $detail)
  395.     {
  396.         if (!$this->details->contains($detail)) {
  397.             $this->details->add($detail);
  398.             $detail->setReception($this);
  399.         }
  400.         return $this;
  401.     }
  402.     /**
  403.      * @param ReceptionDetail $detail
  404.      * @return Reception
  405.      */
  406.     public function removeDetail(ReceptionDetail $detail)
  407.     {
  408.         if ($this->details->contains($detail)) {
  409.             $this->details->removeElement($detail);
  410. //            $detail->setReception(null);
  411.         }
  412.         return $this;
  413.     }
  414.     /**
  415.      * @return SysUsers
  416.      */
  417.     public function getUser()
  418.     {
  419.         return $this->user;
  420.     }
  421.     /**
  422.      * @param SysUsers $user
  423.      * @return Reception
  424.      */
  425.     public function setUser(SysUsers $user)
  426.     {
  427.         $this->user $user;
  428.         return $this;
  429.     }
  430.     /**
  431.      * @return mixed
  432.      */
  433.     public function getFtpTotalReceive()
  434.     {
  435.         return $this->ftpTotalReceive;
  436.     }
  437.     /**
  438.      * @param mixed $ftpTotalReceive
  439.      */
  440.     public function setFtpTotalReceive($ftpTotalReceive): void
  441.     {
  442.         $this->ftpTotalReceive $ftpTotalReceive;
  443.     }
  444.     /**
  445.      * @return mixed
  446.      */
  447.     public function getFtpTotalNetNoTaxeAndTransport()
  448.     {
  449.         return $this->ftpTotalNetNoTaxeAndTransport;
  450.     }
  451.     /**
  452.      * @param mixed $ftpTotalNetNoTaxeAndTransport
  453.      */
  454.     public function setFtpTotalNetNoTaxeAndTransport($ftpTotalNetNoTaxeAndTransport): void
  455.     {
  456.         $this->ftpTotalNetNoTaxeAndTransport $ftpTotalNetNoTaxeAndTransport;
  457.     }
  458.     /**
  459.      * @return mixed
  460.      */
  461.     public function getFtpTotalTps()
  462.     {
  463.         return $this->ftpTotalTps;
  464.     }
  465.     /**
  466.      * @param mixed $ftpTotalTps
  467.      */
  468.     public function setFtpTotalTps($ftpTotalTps): void
  469.     {
  470.         $this->ftpTotalTps $ftpTotalTps;
  471.     }
  472.     /**
  473.      * @return mixed
  474.      */
  475.     public function getFtpTotalTvq()
  476.     {
  477.         return $this->ftpTotalTvq;
  478.     }
  479.     /**
  480.      * @param mixed $ftpTotalTvq
  481.      */
  482.     public function setFtpTotalTvq($ftpTotalTvq): void
  483.     {
  484.         $this->ftpTotalTvq $ftpTotalTvq;
  485.     }
  486.     /**
  487.      * @return mixed
  488.      */
  489.     public function getFtpTotalInvoice()
  490.     {
  491.         return $this->ftpTotalInvoice;
  492.     }
  493.     /**
  494.      * @param mixed $ftpTotalInvoice
  495.      */
  496.     public function setFtpTotalInvoice($ftpTotalInvoice): void
  497.     {
  498.         $this->ftpTotalInvoice $ftpTotalInvoice;
  499.     }
  500.     /***
  501.      * @param Reception $reception
  502.      * @return Reception
  503.      * @throws \Exception
  504.      */
  505.     public static function calculDateLimit(Reception $reception) : Reception
  506.     {
  507.         if (empty($reception->getDate()) || empty($reception->getFournisseur())) {
  508.             return $reception;
  509.         }
  510.         $date $reception->getDate();
  511.         $dateLimit = clone($date);
  512.         return $reception->setDateLimite(
  513.             $dateLimit->add(
  514.                 new \DateInterval('P' $reception->getFournisseur()->getDureeOffice() . 'D')
  515.             )
  516.         );
  517.     }
  518.     /***
  519.      * @param Reception $reception
  520.      * @return Reception
  521.      * @throws \Exception
  522.      */
  523.     public function calculIndicatif(Reception $reception) : Reception
  524.     {
  525.         if (empty($reception->getDate())) {
  526.             return $reception;
  527.         }
  528.         $date $reception->getDate();
  529.         $dateIndicatif = clone($date);
  530.         return $reception->setIndicatif(
  531.             $dateIndicatif->add(
  532.                 new \DateInterval('P' $this::INDICATIF_DIFF_MONTH 'M')
  533.             )
  534.         );
  535.     }
  536. }