Commit 78c636b9 authored by Karamel's avatar Karamel
Browse files

Restore TicketTax.

parent f001d5d2
......@@ -54,6 +54,12 @@ class Ticket extends DoctrineModel
'array' => true,
'embedded' => true
],
[
'name' => 'taxes',
'class' => '\Pasteque\Server\Model\TicketTax',
'array' => true,
'embedded' => true
],
[
'name' => 'payments',
'class' => '\Pasteque\Server\Model\TicketPayment',
......@@ -80,6 +86,7 @@ class Ticket extends DoctrineModel
public function __construct() {
$this->lines = new \Doctrine\Common\Collections\ArrayCollection();
$this->taxes = new \Doctrine\Common\Collections\ArrayCollection();
$this->payments = new \Doctrine\Common\Collections\ArrayCollection();
}
......@@ -169,6 +176,28 @@ class Ticket extends DoctrineModel
$line->setTicket($this);
}
/**
* Array of tax totals.
* @var \Pasteque\Ticket[]
* @SWG\Property()
* @OneToMany(targetEntity="\Pasteque\Server\Model\TicketTax", mappedBy="ticket", cascade={"persist"}, orphanRemoval=true)
*/
protected $taxes;
public function getTaxes() { return $this->taxes; }
public function setTaxes($taxes) {
$this->taxes->clear();
foreach ($taxes as $tax) {
$this->addTax($tax);
}
}
public function clearTaxes() {
$this->getTaxes()->clear();
}
public function addTax($tax) {
$this->taxes->add($tax);
$tax->setTicket($this);
}
/**
* Array of payment
* @var \Pasteque\Payment[]
......@@ -319,6 +348,13 @@ public function getPayments() { return $this->payments; }
unset($line['tax']);
$struct['lines'][$i] = $line;
}
for ($i = 0; $i < count($struct['taxes']); $i++) {
$tax = $struct['taxes'][$i];
unset($tax['id']);
unset($tax['ticket']);
unset($tax['tax']);
$struct['taxes'][$i] = $tax;
}
for ($i = 0; $i < count($struct['payments']); $i++) {
$payment = $struct['payments'][$i];
unset($payment['id']);
......
<?php
// Pastèque API
//
// Copyright (C)
// 2012 Scil (http://scil.coop)
// 2017 Karamel, Association Pastèque (karamel@creativekara.fr, https://pasteque.org)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque\Server\Model;
use \Pasteque\Server\System\DAO\DAO;
use \Pasteque\Server\System\DAO\DoctrineModel;
/**
* Class TicketTax. Sum of the taxes amount by tax.
* This class is for fast data analysis only.
* For declarations see FiscalTicket.
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @Table(name="tickettaxes")
*/
class TicketTax extends DoctrineModel // Embedded class
{
public function getDirectFieldNames() {
return ['base', 'taxRate', 'amount'];
}
public function getAssociationFields() {
return [
[
'name' => 'ticket',
'class' => '\Pasteque\Server\Model\Ticket',
'null' => true // because embedded
],
[
'name' => 'tax',
'class' => '\Pasteque\Server\Model\Tax',
]
];
}
public function getId() {
return array('ticket' => $this->getTicket()->getId(),
'tax' => $this->getTax()->getId());
}
/**
* @var integer
* @SWG\Property
* @ManyToOne(targetEntity="\Pasteque\Server\Model\Ticket", inversedBy="lines")
* @JoinColumn(name="ticket_id", referencedColumnName="id", nullable=false)
* @Id
*/
protected $ticket;
public function getTicket() { return $this->ticket; }
public function setTicket($ticket) { $this->ticket = $ticket; }
/**
* Id of the tax
* @var integer
* @SWG\Property()
* @ManyToOne(targetEntity="\Pasteque\Server\Model\Tax")
* @JoinColumn(name="tax_id", referencedColumnName="id", nullable=false)
* @Id
*/
protected $tax;
public function getTax() { return $this->tax; }
/** Set the tax. If taxRate is null, it will be set with
* the rate of the tax. */
public function setTax($tax) {
$this->tax = $tax;
if ($this->getTaxRate() == null) {
$this->setTaxRate($tax->getRate());
}
}
/**
* Rate of the tax at the time of the ticket
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected $taxRate;
public function getTaxRate() { return $this->taxRate; }
public function setTaxRate($taxRate) { $this->taxRate = $taxRate; }
/**
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected $base;
public function getBase() { return round($this->base, 5); }
public function setBase($base) {
$this->base = round($base, 5);
}
/**
* Total amount of tax.
* @var float
* @SWG\Property()
* @Column(type="float")
*/
protected $amount;
public function getAmount() { return round($this->amount, 5); }
public function setAmount($amount) {
$this->amount = round($amount, 5);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment