src/Diplix/KMGBundle/Entity/Accounting/Document.php line 21

Open in your IDE?
  1. <?php
  2. namespace Diplix\KMGBundle\Entity\Accounting;
  3. use Cocur\Slugify\Slugify;
  4. use Diplix\KMGBundle\Entity\BasicEntity;
  5. use Diplix\KMGBundle\Entity\Customer;
  6. use Diplix\KMGBundle\Entity\File;
  7. use Diplix\KMGBundle\Entity\User;
  8. use Diplix\KMGBundle\Form\Accounting\CoopMemberForm;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11.  * @ORM\Table(name="acc_documents",
  12.  *              indexes={@ORM\Index(name="be_deleted",columns={"be_deleted"})},
  13.  *              uniqueConstraints={
  14.  *                  @ORM\UniqueConstraint(name="docnr_unqiue",columns={"document_type", "document_number"})
  15.  *              }
  16.  * )
  17.  * @ORM\Entity(repositoryClass="Diplix\KMGBundle\Repository\DocumentRepository")
  18.  */
  19. class Document extends BasicEntity
  20. {
  21.     const TYPE_RECHNUNG 'R';
  22.     const TYPE_GUTSCHRIFT 'G';
  23.     public static $typeMap = [
  24.         self::TYPE_GUTSCHRIFT => "Gutschrift",
  25.         self::TYPE_RECHNUNG => "Rechnung"
  26.     ];
  27.     const STATUS_ENTWURF         0;
  28.     const STATUS_OFFEN       1;
  29.     const STATUS_MAHNSTUFE1     11;
  30.     const STATUS_MAHNSTUFE2     12;
  31.     const STATUS_MAHNSTUFE3     13;
  32.     const STATUS_CLOSED_THRESHOLD 50;
  33.     const STATUS_BEZAHLT               50;
  34.     const STATUS_STORNIERT             60;
  35.     public static $statusMap = [
  36.         self::STATUS_ENTWURF => "Entwurf",
  37.         self::STATUS_OFFEN => "Offen",
  38.         self::STATUS_MAHNSTUFE1 => "Mahnstufe 1",
  39.         self::STATUS_MAHNSTUFE2 => "Mahnstufe 2",
  40.         self::STATUS_MAHNSTUFE3 => "Mahnstufe 3",
  41.         self::STATUS_BEZAHLT    => "Bezahlt",
  42.         self::STATUS_STORNIERT => "Storniert"
  43.     ];
  44.     /**
  45.      * @ORM\Column(type="integer",name="id")
  46.      * @ORM\Id()
  47.      * @ORM\GeneratedValue(strategy="AUTO")
  48.      */
  49.     protected $id;
  50.     /**
  51.      * @ORM\Column(name="document_type", type="string",length=1,options={"fixed":true})
  52.      */
  53.     protected $type;
  54.     /**
  55.      * @ORM\Column(name="document_number", type="string")
  56.      */
  57.     protected $number;
  58.     /**
  59.      * @ORM\Column(name="document_date", type="datetime")
  60.      */
  61.     protected $date;
  62.     /**
  63.      * @ORM\Column(type="text")
  64.      */
  65.     protected $receiverAddress;
  66.     /**
  67.      * @ORM\ManyToOne(targetEntity="Diplix\KMGBundle\Entity\Customer")
  68.      * @ORM\JoinColumn(nullable=true)
  69.      */
  70.     protected $customer;
  71.     /**
  72.      * @ORM\ManyToOne(targetEntity="Diplix\KMGBundle\Entity\Accounting\CoopMember")
  73.      * @ORM\JoinColumn(nullable=true)
  74.      */
  75.     protected $member;
  76.     /**
  77.      * @ORM\Column(type="integer")
  78.      */
  79.     protected $status self::STATUS_ENTWURF;
  80.     /**
  81.      * @ORM\Column(type="decimal", nullable=false, precision=12, scale=2,options={"unsigned":false})
  82.      */
  83.     protected $totalNet 0.0;
  84.     /**
  85.      * @ORM\ManyToOne(targetEntity="Diplix\KMGBundle\Entity\File", fetch="EAGER")
  86.      * @ORM\JoinColumn(referencedColumnName="id",nullable=true)
  87.      */
  88.     protected $pdfFile;
  89.     /**
  90.      * @ORM\OneToOne(targetEntity="Diplix\KMGBundle\Entity\Accounting\Billing", fetch="EAGER")
  91.      * @ORM\JoinColumn(name="billing_id", referencedColumnName="id")
  92.      */
  93.     protected $billing;
  94.     /**
  95.      * @ORM\ManyToOne(targetEntity="Diplix\KMGBundle\Entity\User",fetch="EXTRA_LAZY")
  96.      * @ORM\JoinColumn(nullable=true)
  97.      */
  98.     protected $treatedBy null;
  99.     /**
  100.      * @ORM\Column(type="integer")
  101.      */
  102.     protected $accountingMonth 0;
  103.     /**
  104.      * @ORM\Column(type="integer")
  105.      */
  106.     protected $accountingYear 0;
  107.     /**
  108.      * @ORM\Column(type="datetime", nullable=true);
  109.      */
  110.     protected $sentToReceiver null;
  111.     /**
  112.      * @ORM\Column(type="text")
  113.      */
  114.     protected $headerText '';
  115.     /**
  116.      * @ORM\Column(type="text")
  117.      */
  118.     protected $footerText '';
  119.     /**
  120.      * @ORM\ManyToOne(targetEntity="Diplix\KMGBundle\Entity\File", fetch="EAGER")
  121.      * @ORM\JoinColumn(referencedColumnName="id",nullable=true)
  122.      */
  123.     protected $reminderPdf;
  124.     /**
  125.      * @ORM\Column(type="datetime", nullable=true);
  126.      */
  127.     protected $reminderSentToReceiver null;
  128.     /**
  129.      * @ORM\ManyToOne(targetEntity="Diplix\KMGBundle\Entity\File", fetch="EAGER")
  130.      * @ORM\JoinColumn(referencedColumnName="id",nullable=true)
  131.      */
  132.     protected $monition1Pdf;
  133.     /**
  134.      * @ORM\Column(type="datetime", nullable=true);
  135.      */
  136.     protected $monition1SentToReceiver null;
  137.     /**
  138.      * @ORM\ManyToOne(targetEntity="Diplix\KMGBundle\Entity\File", fetch="EAGER")
  139.      * @ORM\JoinColumn(referencedColumnName="id",nullable=true)
  140.      */
  141.     protected $monition2Pdf;
  142.     /**
  143.      * @ORM\Column(type="datetime", nullable=true);
  144.      */
  145.     protected $monition2SentToReceiver null;
  146.     /**
  147.      * @ORM\Column(type="json")
  148.      */
  149.     protected $extraCalculationItems = [];
  150.     /**
  151.      * @ORM\ManyToOne(targetEntity="Diplix\KMGBundle\Entity\File", fetch="EAGER")
  152.      * @ORM\JoinColumn(referencedColumnName="id",nullable=true)
  153.      */
  154.     protected $extraPdf;
  155.     /**
  156.      * @ORM\Column(type="json")
  157.      */
  158.     protected $standByDispoData = [];
  159.     public function __clone()
  160.     {
  161.         $this->id null;
  162.         $this->status self::STATUS_ENTWURF;
  163.         $this->pdfFile null$this->sentToReceiver null;
  164.         $this->reminderPdf null$this->reminderSentToReceiver null;
  165.         $this->monition1Pdf null$this->monition1SentToReceiver null;
  166.         $this->monition2Pdf null$this->monition2SentToReceiver null;
  167.         $this->treatedBy null;
  168.         $this->billing null;
  169.     }
  170.     public function generateFilename()
  171.     {
  172.         $sl = new Slugify();
  173.         $kc '';
  174.         if ($this->getCustomer()!==null)
  175.         {
  176.             $kc.= 'K' $sl->slugify(sprintf('%s_,%s',$this->getCustomer()->getCustomerNo(),$this->getCustomer()->getName()));
  177.         }
  178.         if ($this->getMember()!==null)
  179.         {
  180.             $kc.= 'M' $sl->slugify(sprintf('%s_%s',$this->getMember()->getNumber(),$this->getMember()->getName()));
  181.         }
  182.         $s $this->getStatus();
  183.         $m = (($s>=self::STATUS_MAHNSTUFE1)&&($s<=self::STATUS_MAHNSTUFE3)) ? 'M'.$s.'_' '';
  184.         return sprintf('%s%s_%s_%s.pdf',$m,$this->getType(),$this->getNumber(),$kc);
  185.     }
  186.     public function recalculateExtraItems()
  187.     {
  188.         $it $this->getExtraCalculationItems();
  189.         $sum 0;
  190.         foreach ($it as $one)
  191.         {
  192.             $one->totalNet $one->amount*$one->quantity;
  193.             $sum += $one->totalNet;
  194.         }
  195.         return $sum;
  196.     }
  197.     /**
  198.      * @return mixed
  199.      */
  200.     public function getId()
  201.     {
  202.         return $this->id;
  203.     }
  204.     /**
  205.      * @return mixed
  206.      */
  207.     public function getType()
  208.     {
  209.         return $this->type;
  210.     }
  211.     /**
  212.      * @param mixed $type
  213.      */
  214.     public function setType($type)
  215.     {
  216.         $this->type $type;
  217.     }
  218.     /**
  219.      * @return mixed
  220.      */
  221.     public function getNumber()
  222.     {
  223.         return $this->number;
  224.     }
  225.     /**
  226.      * @param mixed $number
  227.      */
  228.     public function setNumber($number)
  229.     {
  230.         $this->number $number;
  231.     }
  232.     /**
  233.      * @return mixed
  234.      */
  235.     public function getReceiverAddress()
  236.     {
  237.         return $this->receiverAddress;
  238.     }
  239.     /**
  240.      * @param mixed $receiverAddress
  241.      */
  242.     public function setReceiverAddress($receiverAddress)
  243.     {
  244.         $this->receiverAddress $receiverAddress;
  245.     }
  246.     /**
  247.      * @return null|Customer
  248.      */
  249.     public function getCustomer()
  250.     {
  251.         return $this->customer;
  252.     }
  253.     /**
  254.      * @param mixed $customer
  255.      */
  256.     public function setCustomer($customer)
  257.     {
  258.         $this->customer $customer;
  259.     }
  260.     /**
  261.      * @return null|CoopMember
  262.      */
  263.     public function getMember()
  264.     {
  265.         return $this->member;
  266.     }
  267.     /**
  268.      * @param mixed $member
  269.      */
  270.     public function setMember($member)
  271.     {
  272.         $this->member $member;
  273.     }
  274.     /**
  275.      * @return mixed
  276.      */
  277.     public function getStatus()
  278.     {
  279.         return $this->status;
  280.     }
  281.     /**
  282.      * @param mixed $status
  283.      */
  284.     public function setStatus($status)
  285.     {
  286.         $this->status $status;
  287.     }
  288.     /**
  289.      * @return mixed
  290.      */
  291.     public function getTotalNet()
  292.     {
  293.         return $this->totalNet;
  294.     }
  295.     /**
  296.      * @param mixed $totalNet
  297.      */
  298.     public function setTotalNet($totalNet)
  299.     {
  300.         $this->totalNet $totalNet;
  301.     }
  302.     /**
  303.      * @return mixed
  304.      */
  305.     public function getDate()
  306.     {
  307.         return $this->date;
  308.     }
  309.     /**
  310.      * @param mixed $date
  311.      */
  312.     public function setDate($date)
  313.     {
  314.         $this->date $date;
  315.     }
  316.     /**
  317.      * @return Billing
  318.      */
  319.     public function getBilling()
  320.     {
  321.         return $this->billing;
  322.     }
  323.     /**
  324.      * @param mixed $billing
  325.      */
  326.     public function setBilling($billing)
  327.     {
  328.         $this->billing $billing;
  329.     }
  330.     /**
  331.      * @return File|null
  332.      */
  333.     public function getPdfFile()
  334.     {
  335.         return $this->pdfFile;
  336.     }
  337.     /**
  338.      * @param File|null $pdfFile
  339.      */
  340.     public function setPdfFile($pdfFile)
  341.     {
  342.         $this->pdfFile $pdfFile;
  343.     }
  344.     /**
  345.      * @return null|User
  346.      */
  347.     public function getTreatedBy()
  348.     {
  349.         return $this->treatedBy;
  350.     }
  351.     /**
  352.      * @param null|User $treatedBy
  353.      */
  354.     public function setTreatedBy($treatedBy)
  355.     {
  356.         $this->treatedBy $treatedBy;
  357.     }
  358.     /**
  359.      * @return int
  360.      */
  361.     public function getAccountingMonth()
  362.     {
  363.         return $this->accountingMonth;
  364.     }
  365.     /**
  366.      * @param int $accountingMonth
  367.      */
  368.     public function setAccountingMonth($accountingMonth)
  369.     {
  370.         $this->accountingMonth $accountingMonth;
  371.     }
  372.     /**
  373.      * @return int
  374.      */
  375.     public function getAccountingYear()
  376.     {
  377.         return $this->accountingYear;
  378.     }
  379.     /**
  380.      * @param int $accountingYear
  381.      */
  382.     public function setAccountingYear($accountingYear)
  383.     {
  384.         $this->accountingYear $accountingYear;
  385.     }
  386.     /**
  387.      * @return \DateTime|null
  388.      */
  389.     public function isSentToReceiver()
  390.     {
  391.         return $this->sentToReceiver;
  392.     }
  393.     /**
  394.      * @param  \DateTime|null $sentToReceiver
  395.      */
  396.     public function setSentToReceiver($sentToReceiver): void
  397.     {
  398.         $this->sentToReceiver $sentToReceiver;
  399.     }
  400.     /**
  401.      * @return string
  402.      */
  403.     public function getHeaderText(): string
  404.     {
  405.         return $this->headerText;
  406.     }
  407.     /**
  408.      * @param string $headerText
  409.      */
  410.     public function setHeaderText(string $headerText): void
  411.     {
  412.         $this->headerText $headerText;
  413.     }
  414.     /**
  415.      * @return string
  416.      */
  417.     public function getFooterText(): string
  418.     {
  419.         return $this->footerText;
  420.     }
  421.     /**
  422.      * @param string $footerText
  423.      */
  424.     public function setFooterText(string $footerText): void
  425.     {
  426.         $this->footerText $footerText;
  427.     }
  428.     /**
  429.      * @return mixed
  430.      */
  431.     public function getReminderPdf()
  432.     {
  433.         return $this->reminderPdf;
  434.     }
  435.     /**
  436.      * @param mixed $reminderPdf
  437.      */
  438.     public function setReminderPdf($reminderPdf): void
  439.     {
  440.         $this->reminderPdf $reminderPdf;
  441.     }
  442.     /**
  443.      * @return mixed
  444.      */
  445.     public function getMonition1Pdf()
  446.     {
  447.         return $this->monition1Pdf;
  448.     }
  449.     /**
  450.      * @param mixed $monition1Pdf
  451.      */
  452.     public function setMonition1Pdf($monition1Pdf): void
  453.     {
  454.         $this->monition1Pdf $monition1Pdf;
  455.     }
  456.     /**
  457.      * @return mixed
  458.      */
  459.     public function getMonition2Pdf()
  460.     {
  461.         return $this->monition2Pdf;
  462.     }
  463.     /**
  464.      * @param mixed $monition2Pdf
  465.      */
  466.     public function setMonition2Pdf($monition2Pdf): void
  467.     {
  468.         $this->monition2Pdf $monition2Pdf;
  469.     }
  470.     /**
  471.      * @return null
  472.      */
  473.     public function getReminderSentToReceiver()
  474.     {
  475.         return $this->reminderSentToReceiver;
  476.     }
  477.     /**
  478.      * @param null $reminderSentToReceiver
  479.      */
  480.     public function setReminderSentToReceiver($reminderSentToReceiver): void
  481.     {
  482.         $this->reminderSentToReceiver $reminderSentToReceiver;
  483.     }
  484.     /**
  485.      * @return null
  486.      */
  487.     public function getMonition1SentToReceiver()
  488.     {
  489.         return $this->monition1SentToReceiver;
  490.     }
  491.     /**
  492.      * @param null $monition1SentToReceiver
  493.      */
  494.     public function setMonition1SentToReceiver($monition1SentToReceiver): void
  495.     {
  496.         $this->monition1SentToReceiver $monition1SentToReceiver;
  497.     }
  498.     /**
  499.      * @return null
  500.      */
  501.     public function getMonition2SentToReceiver()
  502.     {
  503.         return $this->monition2SentToReceiver;
  504.     }
  505.     /**
  506.      * @param null $monition2SentToReceiver
  507.      */
  508.     public function setMonition2SentToReceiver($monition2SentToReceiver): void
  509.     {
  510.         $this->monition2SentToReceiver $monition2SentToReceiver;
  511.     }
  512.     /**
  513.      * @return array|JobCalcItem[]
  514.      */
  515.     public function getExtraCalculationItems()
  516.     {
  517.         $ex $this->extraCalculationItems;
  518.         if (($ex === null)||($ex==='')) $ex = [];
  519.         return Job::toJciArray($ex);
  520.     }
  521.     /**
  522.      * @param array $extaCalculationItems
  523.      */
  524.     public function setExtraCalculationItems($extaCalculationItems)
  525.     {
  526.         $this->extraCalculationItems Job::fromObjectArray($extaCalculationItems);
  527.     }
  528.     /**
  529.      * @return File|null
  530.      */
  531.     public function getExtraPdf()
  532.     {
  533.         return $this->extraPdf;
  534.     }
  535.     /**
  536.      * @param File|null $extraPdf
  537.      */
  538.     public function setExtraPdf($extraPdf): void
  539.     {
  540.         $this->extraPdf $extraPdf;
  541.     }
  542.     /**
  543.      * @return array
  544.      */
  545.     public function getStandByDispoData(): array
  546.     {
  547.         return $this->standByDispoData ?? [];
  548.     }
  549.     /**
  550.      * @param array $standByDispoData
  551.      */
  552.     public function setStandByDispoData(array $standByDispoData): void
  553.     {
  554.         $this->standByDispoData $standByDispoData;
  555.     }
  556. }