src/AtechNet/CoreBundle/Entity/CustomerBillingoData.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use App\AtechNet\CoreBundle\Helper\Billingo;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping\Column;
  6. use Doctrine\ORM\Mapping\Entity;
  7. use Doctrine\ORM\Mapping\JoinColumn;
  8. use Doctrine\ORM\Mapping\ManyToOne;
  9. use Doctrine\ORM\Mapping\OneToMany;
  10. use Doctrine\ORM\Mapping\OrderBy;
  11. use Doctrine\ORM\Mapping\Table as Table;
  12. /**
  13.  * CustomerBillingoData
  14.  *
  15.  * @Table(name="customers__billingo_data")
  16.  * @Entity()
  17.  */
  18. class CustomerBillingoData extends AbstractSignedEntity
  19. {
  20.     /**
  21.      * @var Order
  22.      *
  23.      * @ManyToOne(targetEntity="Order", inversedBy="billingoDocuments")
  24.      * @JoinColumn(name="order_id", referencedColumnName="id")
  25.      */
  26.     private $order;
  27.     /**
  28.      * @var Customer
  29.      *
  30.      * @ManyToOne(targetEntity="Customer", inversedBy="billingoDocuments")
  31.      * @JoinColumn(name="customer_id", referencedColumnName="id")
  32.      */
  33.     private $customer;
  34.     /**
  35.      * @var StockMovement
  36.      *
  37.      * @ManyToOne(targetEntity="StockMovement", inversedBy="billingoDocuments")
  38.      * @JoinColumn(name="stock_movement_id", referencedColumnName="id")
  39.      */
  40.     private $stockMovement;
  41.     /**
  42.      * @var ArrayCollection
  43.      *
  44.      * @OneToMany(targetEntity="PaymentData", mappedBy="billingoDocument", orphanRemoval=true)
  45.      * @OrderBy({"created" = "DESC"})
  46.      **/
  47.     private $paymentDatas;
  48.     /**
  49.      * @var int
  50.      *
  51.      * @Column(name="type", type="integer")
  52.      */
  53.     private $type;
  54.     /**
  55.      * @var string
  56.      *
  57.      * @Column(name="invoice_id", type="string")
  58.      */
  59.     private $invoiceId;
  60.     /**
  61.      * @var string
  62.      *
  63.      * @Column(name="invoice_v3_id", type="string", nullable=true)
  64.      */
  65.     private $invoiceV3Id;
  66.     /**
  67.      * @var string
  68.      *
  69.      * @Column(name="invoice_code", type="string")
  70.      */
  71.     private $invoiceCode;
  72.     /**
  73.      * @var string
  74.      *
  75.      * @Column(name="prefix", type="string", nullable=true)
  76.      */
  77.     private $prefix;
  78.     /**
  79.      * @var string
  80.      *
  81.      * @Column(name="invoice_code_with_prefix", type="string", nullable=true)
  82.      */
  83.     private $invoiceCodeWithPrefix;
  84.     /**
  85.      * @var \DateTime
  86.      *
  87.      * @Column(name="fullfilment_date", type="datetime")
  88.      */
  89.     private $fullfilment_date;
  90.     /**
  91.      * @var \DateTime
  92.      *
  93.      * @Column(name="due_date", type="datetime")
  94.      */
  95.     private $due_date;
  96.     /**
  97.      * @var string
  98.      *
  99.      * @Column(name="comment", type="text", nullable=true)
  100.      */
  101.     private $comment;
  102.     /**
  103.      * @var ArrayCollection
  104.      *
  105.      * @OneToMany(targetEntity="BillingoComment", mappedBy="document", orphanRemoval=true)
  106.      * @OrderBy({"created" = "DESC"})
  107.      **/
  108.     private $comments;
  109.     /**
  110.      * @var float
  111.      *
  112.      * @Column(name="total_price", type="decimal", precision=18, scale=4)
  113.      */
  114.     private $totalPrice;
  115.     /**
  116.      * @var float
  117.      *
  118.      * @Column(name="total_vat_price", type="decimal", precision=18, scale=4)
  119.      */
  120.     private $totalVatPrice;
  121.     /**
  122.      * @var string
  123.      *
  124.      * @Column(name="currency", type="string", length=6)
  125.      */
  126.     private $currency;
  127.     /**
  128.      * @var string
  129.      *
  130.      * @Column(name="client_uid", type="string", length=32)
  131.      */
  132.     private $clientUid;
  133.     /**
  134.      * @var string
  135.      *
  136.      * @Column(name="block_uid", type="string", length=32)
  137.      */
  138.     private $blockUid;
  139.     /**
  140.      * @var string
  141.      *
  142.      * @Column(name="uid", type="string", length=32)
  143.      */
  144.     private $uid;
  145.     /**
  146.      * @var bool
  147.      *
  148.      * @Column(name="paid", type="boolean")
  149.      */
  150.     private $paid;
  151.     /**
  152.      * @var string
  153.      *
  154.      * @Column(name="total_paid", type="decimal", precision=18, scale=4)
  155.      */
  156.     private $totalPaid;
  157.     /**
  158.      * @var float
  159.      *
  160.      * @Column(name="vat", type="decimal", precision=10, scale=2)
  161.      */
  162.     private $vat;
  163.     /**
  164.      * @var int
  165.      *
  166.      * @Column(name="payment_method", type="integer")
  167.      */
  168.     private $paymentMethod;
  169.     /**
  170.      * @var bool
  171.      *
  172.      * @Column(name="canceled", type="boolean")
  173.      */
  174.     private $canceled;
  175.     /**
  176.      * @var string
  177.      *
  178.      * @Column(name="canceled_invoice_id", type="string", length=32, nullable=true)
  179.      */
  180.     private $canceledInvoiceId;
  181.     /**
  182.      * @var string
  183.      *
  184.      * @Column(name="canceled_invoice_v3_id", type="string", length=32, nullable=true)
  185.      */
  186.     private $canceledInvoiceV3Id;
  187.     /**
  188.      * @var string
  189.      *
  190.      * @Column(name="canceled_invoice_code", type="string", length=32, nullable=true)
  191.      */
  192.     private $canceledInvoiceCode;
  193.     /**
  194.      * @var string
  195.      *
  196.      * @Column(name="public_v3_invoice_link", type="string", length=256, nullable=true)
  197.      */
  198.     private $publicV3InvoiceLink;
  199.     /**
  200.      * @var string
  201.      *
  202.      * @Column(name="public_v3_cancel_invoice_link", type="string", length=256, nullable=true)
  203.      */
  204.     private $publicV3CancelInvoiceLink;
  205.     /**
  206.      * @var ArrayCollection
  207.      *
  208.      * @OneToMany(targetEntity="BillingoPayment", mappedBy="billingoData", orphanRemoval=true)
  209.      * @OrderBy({"created" = "DESC"})
  210.      **/
  211.     private $payments;
  212.     /**
  213.      * @return Order
  214.      */
  215.     public function getOrder()
  216.     {
  217.         return $this->order;
  218.     }
  219.     /**
  220.      * @param Order $order
  221.      */
  222.     public function setOrder($order)
  223.     {
  224.         $this->order = $order;
  225.     }
  226.     /**
  227.      * @return Customer
  228.      */
  229.     public function getCustomer()
  230.     {
  231.         return $this->customer;
  232.     }
  233.     /**
  234.      * @param Customer $customer
  235.      */
  236.     public function setCustomer($customer)
  237.     {
  238.         $this->customer = $customer;
  239.     }
  240.     /**
  241.      * @return int
  242.      */
  243.     public function getType()
  244.     {
  245.         return $this->type;
  246.     }
  247.     /**
  248.      * @param int $type
  249.      */
  250.     public function setType($type)
  251.     {
  252.         $this->type = $type;
  253.     }
  254.     /**
  255.      * @return string
  256.      */
  257.     public function getInvoiceId()
  258.     {
  259.         return $this->invoiceId;
  260.     }
  261.     /**
  262.      * @param string $invoiceId
  263.      */
  264.     public function setInvoiceId($invoiceId)
  265.     {
  266.         $this->invoiceId = $invoiceId;
  267.     }
  268.     /**
  269.      * @return string
  270.      */
  271.     public function getInvoiceCode()
  272.     {
  273.         return $this->invoiceCode;
  274.     }
  275.     /**
  276.      * @param string $invoiceCode
  277.      */
  278.     public function setInvoiceCode($invoiceCode)
  279.     {
  280.         $this->invoiceCode = $invoiceCode;
  281.     }
  282.     /**
  283.      * @return \DateTime
  284.      */
  285.     public function getFullfilmentDate()
  286.     {
  287.         return $this->fullfilment_date;
  288.     }
  289.     /**
  290.      * @param \DateTime $fullfilment_date
  291.      */
  292.     public function setFullfilmentDate($fullfilment_date)
  293.     {
  294.         $this->fullfilment_date = $fullfilment_date;
  295.     }
  296.     /**
  297.      * @return \DateTime
  298.      */
  299.     public function getDueDate()
  300.     {
  301.         return $this->due_date;
  302.     }
  303.     /**
  304.      * @param \DateTime $due_date
  305.      */
  306.     public function setDueDate($due_date)
  307.     {
  308.         $this->due_date = $due_date;
  309.     }
  310.     /**
  311.      * @return string
  312.      */
  313.     public function getComment()
  314.     {
  315.         return $this->comment;
  316.     }
  317.     /**
  318.      * @param string $comment
  319.      */
  320.     public function setComment($comment)
  321.     {
  322.         $this->comment = $comment;
  323.     }
  324.     /**
  325.      * @return ArrayCollection
  326.      */
  327.     public function getComments()
  328.     {
  329.         return $this->comments;
  330.     }
  331.     /**
  332.      * @return BillingoComment|null
  333.      */
  334.     public function getLatestComment(): ?BillingoComment
  335.     {
  336.         return $this->getComments()->count() > 0 ? $this->getComments()->first() : null;
  337.     }
  338.     /**
  339.      * @return float
  340.      */
  341.     public function getTotalPrice()
  342.     {
  343.         return $this->totalPrice;
  344.     }
  345.     /**
  346.      * @param float $totalPrice
  347.      */
  348.     public function setTotalPrice($totalPrice)
  349.     {
  350.         $this->totalPrice = $totalPrice;
  351.     }
  352.     /**
  353.      * @return float
  354.      */
  355.     public function getTotalVatPrice()
  356.     {
  357.         return $this->totalVatPrice;
  358.     }
  359.     /**
  360.      * @param float $totalVatPrice
  361.      */
  362.     public function setTotalVatPrice($totalVatPrice)
  363.     {
  364.         $this->totalVatPrice = $totalVatPrice;
  365.     }
  366.     /**
  367.      * @return string
  368.      */
  369.     public function getCurrency()
  370.     {
  371.         return $this->currency;
  372.     }
  373.     /**
  374.      * @param string $currency
  375.      */
  376.     public function setCurrency($currency)
  377.     {
  378.         $this->currency = $currency;
  379.     }
  380.     /**
  381.      * @return string
  382.      */
  383.     public function getClientUid()
  384.     {
  385.         return $this->clientUid;
  386.     }
  387.     /**
  388.      * @param string $clientUid
  389.      */
  390.     public function setClientUid($clientUid)
  391.     {
  392.         $this->clientUid = $clientUid;
  393.     }
  394.     /**
  395.      * @return string
  396.      */
  397.     public function getBlockUid()
  398.     {
  399.         return $this->blockUid;
  400.     }
  401.     /**
  402.      * @param string $blockUid
  403.      */
  404.     public function setBlockUid($blockUid)
  405.     {
  406.         $this->blockUid = $blockUid;
  407.     }
  408.     /**
  409.      * @return string
  410.      */
  411.     public function getUid()
  412.     {
  413.         return $this->uid;
  414.     }
  415.     /**
  416.      * @param string $uid
  417.      */
  418.     public function setUid($uid)
  419.     {
  420.         $this->uid = $uid;
  421.     }
  422.     /**
  423.      * @return boolean
  424.      */
  425.     public function isPaid()
  426.     {
  427.         return $this->paid;
  428.     }
  429.     /**
  430.      * @param boolean $paid
  431.      */
  432.     public function setPaid($paid)
  433.     {
  434.         $this->paid = $paid;
  435.     }
  436.     /**
  437.      * @return string
  438.      */
  439.     public function getTotalPaid()
  440.     {
  441.         return $this->totalPaid;
  442.     }
  443.     /**
  444.      * @param string $totalPaid
  445.      */
  446.     public function setTotalPaid($totalPaid)
  447.     {
  448.         $this->totalPaid = $totalPaid;
  449.     }
  450.     /**
  451.      * @return float
  452.      */
  453.     public function getVat()
  454.     {
  455.         return $this->vat;
  456.     }
  457.     /**
  458.      * @param float $vat
  459.      */
  460.     public function setVat($vat)
  461.     {
  462.         $this->vat = $vat;
  463.     }
  464.     /**
  465.      * @return int
  466.      */
  467.     public function getPaymentMethod()
  468.     {
  469.         return $this->paymentMethod;
  470.     }
  471.     /**
  472.      * @param int $paymentMethod
  473.      */
  474.     public function setPaymentMethod($paymentMethod)
  475.     {
  476.         $this->paymentMethod = $paymentMethod;
  477.     }
  478.     /**
  479.      * @return float
  480.      */
  481.     public function getPriceToPay()
  482.     {
  483.         return $this->getVat() == 0 ? $this->getTotalPrice() : $this->getTotalVatPrice();
  484.     }
  485.     /**
  486.      * @return boolean
  487.      */
  488.     public function isCanceled()
  489.     {
  490.         return $this->canceled;
  491.     }
  492.     /**
  493.      * @param boolean $canceled
  494.      */
  495.     public function setCanceled($canceled)
  496.     {
  497.         $this->canceled = $canceled;
  498.     }
  499.     /**
  500.      * @return bool
  501.      */
  502.     public function isLocked()
  503.     {
  504.         return $this->getFullfilmentDate()->format('Ym') < date('Ym') && date('d') > Document::LOCKED_AFTER_DAY_OF_MONTH;
  505.     }
  506.     /**
  507.      * @return StockMovement
  508.      */
  509.     public function getStockMovement()
  510.     {
  511.         return $this->stockMovement;
  512.     }
  513.     /**
  514.      * @param StockMovement $stockMovement
  515.      */
  516.     public function setStockMovement($stockMovement)
  517.     {
  518.         $this->stockMovement = $stockMovement;
  519.     }
  520.     /**
  521.      * @return bool
  522.      */
  523.     public function isReStockAvailable(): bool
  524.     {
  525.         foreach ($this->getOrder()->getStockMovements() as $stockMovement) {
  526.             if ($stockMovement->getType() == StockMovement::TYPE_IN) {
  527.                 return false;
  528.             }
  529.         }
  530.         if (!is_null($this->getStockMovement()) && $this->getStockMovement()->getType() == StockMovement::TYPE_OUT) {
  531.             return true;
  532.         }
  533.         return false;
  534.     }
  535.     /**
  536.      * @return  string
  537.      */
  538.     public function getCanceledInvoiceId()
  539.     {
  540.         return $this->canceledInvoiceId;
  541.     }
  542.     /**
  543.      * @param  string  $canceledInvoiceId
  544.      */
  545.     public function setCanceledInvoiceId($canceledInvoiceId)
  546.     {
  547.         return $this->canceledInvoiceId = $canceledInvoiceId;
  548.     }
  549.     /**
  550.      * @return  string
  551.      */
  552.     public function getCanceledInvoiceCode()
  553.     {
  554.         return $this->canceledInvoiceCode;
  555.     }
  556.     /**
  557.      * @param  string  $canceledInvoiceCode
  558.      */
  559.     public function setCanceledInvoiceCode($canceledInvoiceCode)
  560.     {
  561.         return $this->canceledInvoiceCode = $canceledInvoiceCode;
  562.     }
  563.     /**
  564.      * @return ArrayCollection
  565.      */
  566.     public function getPayments()
  567.     {
  568.         return $this->payments;
  569.     }
  570.     /**
  571.      * @param ArrayCollection $payments
  572.      */
  573.     public function setPayments($payments)
  574.     {
  575.         $this->payments = $payments;
  576.     }
  577.     /**
  578.      * @return ArrayCollection
  579.      */
  580.     public function getPaymentDatas()
  581.     {
  582.         return $this->paymentDatas;
  583.     }
  584.     /**
  585.      * @return string|void
  586.      */
  587.     public function getStatusTitle()
  588.     {
  589.         if ($this->getTotalVatPrice() > $this->getTotalPaid()) {
  590.             return 'Not paid';
  591.         } elseif ($this->getTotalVatPrice() == $this->getTotalPaid()) {
  592.             return 'Paid';
  593.         } elseif ($this->getTotalVatPrice() < $this->getTotalPaid()) {
  594.             return 'Overpaid';
  595.         }
  596.     }
  597.     /**
  598.      * @return string|null
  599.      */
  600.     public function getPrefix(): ?string
  601.     {
  602.         return $this->prefix;
  603.     }
  604.     /**
  605.      * @param string|null $prefix
  606.      */
  607.     public function setPrefix(?string $prefix): void
  608.     {
  609.         $this->prefix = $prefix;
  610.     }
  611.     /**
  612.      * @return string|null
  613.      */
  614.     public function getInvoiceCodeWithPrefix(): ?string
  615.     {
  616.         return $this->invoiceCodeWithPrefix;
  617.     }
  618.     /**
  619.      * @param string|null $invoiceCodeWithPrefix
  620.      */
  621.     public function setInvoiceCodeWithPrefix(?string $invoiceCodeWithPrefix): void
  622.     {
  623.         $this->invoiceCodeWithPrefix = $invoiceCodeWithPrefix;
  624.     }
  625.     /**
  626.      * @return string|null
  627.      */
  628.     public function getInvoiceV3Id(): ?string
  629.     {
  630.         return $this->invoiceV3Id;
  631.     }
  632.     /**
  633.      * @param string|null $invoiceV3Id
  634.      */
  635.     public function setInvoiceV3Id(?string $invoiceV3Id): void
  636.     {
  637.         $this->invoiceV3Id = $invoiceV3Id;
  638.     }
  639.     /**
  640.      * @return string|null
  641.      */
  642.     public function getCanceledInvoiceV3Id(): ?string
  643.     {
  644.         return $this->canceledInvoiceV3Id;
  645.     }
  646.     /**
  647.      * @param string|null $canceledInvoiceV3Id
  648.      */
  649.     public function setCanceledInvoiceV3Id(?string $canceledInvoiceV3Id): void
  650.     {
  651.         $this->canceledInvoiceV3Id = $canceledInvoiceV3Id;
  652.     }
  653.     /**
  654.      * @return string|null
  655.      */
  656.     public function getPublicV3InvoiceLink(): ?string
  657.     {
  658.         return Billingo::PUBLIC_URL_PREFIX . $this->publicV3InvoiceLink;
  659.     }
  660.     /**
  661.      * @param string|null $publicV3InvoiceLink
  662.      */
  663.     public function setPublicV3InvoiceLink(?string $publicV3InvoiceLink): void
  664.     {
  665.         $this->publicV3InvoiceLink = $publicV3InvoiceLink;
  666.     }
  667.     /**
  668.      * @return string|null
  669.      */
  670.     public function getPublicV3CancelInvoiceLink(): ?string
  671.     {
  672.         return Billingo::PUBLIC_URL_PREFIX . $this->publicV3CancelInvoiceLink;
  673.     }
  674.     /**
  675.      * @param string|null $publicV3CancelInvoiceLink
  676.      */
  677.     public function setPublicV3CancelInvoiceLink(?string $publicV3CancelInvoiceLink): void
  678.     {
  679.         $this->publicV3CancelInvoiceLink = $publicV3CancelInvoiceLink;
  680.     }
  681. }