<?php
/**
* Created by simpson <simpsonwork@gmail.com>
* Date: 2019-06-27
* Time: 11:00
*/
namespace App\Entity\Sales;
use App\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use Money\Currency;
use Money\Money;
#[ORM\Table(name: 'account_charges')]
#[ORM\Entity]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'charge_type', type: 'string', length: 12)]
#[ORM\DiscriminatorMap(['profile' => Profile\PlacementCharge::class, 'saloon' => Saloon\PlacementCharge::class, 'manual' => ManualAccountCharge::class])]
abstract class AccountCharge
{
#[ORM\Id]
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected int $id;
#[ORM\JoinColumn(name: 'account_id', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'charges')]
protected User $account;
#[ORM\Column(name: 'charged_amount', type: 'integer')]
protected string $chargedAmount;
#[ORM\Column(name: 'currency', type: 'string', length: 3)]
protected string $currency;
#[ORM\Column(name: 'date', type: 'datetimetz_immutable')]
protected \DateTimeImmutable $date;
#[ORM\JoinColumn(name: 'price_id', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: PaidPlacementPrice::class)]
protected ?PaidPlacementPrice $price;
#[ORM\OneToOne(targetEntity: AccountTransaction::class, mappedBy: 'charge', cascade: ['all'])]
protected AccountTransaction $transaction;
#[ORM\Column(name: 'placement_start', type: 'datetimetz_immutable', nullable: true)]
protected ?\DateTimeImmutable $placementStart;
#[ORM\Column(name: 'placement_end', type: 'datetimetz_immutable', nullable: true)]
protected ?\DateTimeImmutable $placementEnd;
public function __construct(User $account, Money $chargedMoney, \DateTimeImmutable $date, ?PaidPlacementPrice $price, ?\DateTimeImmutable $placementStart, ?\DateTimeImmutable $placementEnd)
{
$this->account = $account;
$this->chargedAmount = $chargedMoney->getAmount();
$this->currency = $chargedMoney->getCurrency()->getCode();
$this->date = $date;
$this->price = $price;
$this->transaction = AccountTransaction::fromCharge($this);
$this->placementStart = $placementStart;
$this->placementEnd = $placementEnd;
}
public function getId(): int
{
return $this->id;
}
public function getAccount(): User
{
return $this->account;
}
public function getChargedMoney(): Money
{
return new Money($this->chargedAmount, new Currency($this->currency));
}
public function getDate(): \DateTimeImmutable
{
return $this->date;
}
public function getPrice(): ?PaidPlacementPrice
{
return $this->price;
}
public function getTransaction(): AccountTransaction
{
return $this->transaction;
}
public function getPlacementStart(): ?\DateTimeImmutable
{
return $this->placementStart;
}
public function getPlacementEnd(): ?\DateTimeImmutable
{
return $this->placementEnd;
}
}