src/Entity/Sales/AccountCharge.php line 20

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-06-27
  5.  * Time: 11:00
  6.  */
  7. namespace App\Entity\Sales;
  8. use App\Entity\User;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Money\Currency;
  11. use Money\Money;
  12. #[ORM\Table(name: 'account_charges')]
  13. #[ORM\Entity]
  14. #[ORM\InheritanceType('SINGLE_TABLE')]
  15. #[ORM\DiscriminatorColumn(name: 'charge_type', type: 'string', length: 12)]
  16. #[ORM\DiscriminatorMap(['profile' => Profile\PlacementCharge::class, 'saloon' => Saloon\PlacementCharge::class, 'manual' => ManualAccountCharge::class])]
  17. abstract class AccountCharge
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\Column(name: 'id', type: 'integer')]
  21.     #[ORM\GeneratedValue(strategy: 'AUTO')]
  22.     protected int $id;
  23.     #[ORM\JoinColumn(name: 'account_id', referencedColumnName: 'id')]
  24.     #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'charges')]
  25.     protected User $account;
  26.     #[ORM\Column(name: 'charged_amount', type: 'integer')]
  27.     protected string $chargedAmount;
  28.     #[ORM\Column(name: 'currency', type: 'string', length: 3)]
  29.     protected string $currency;
  30.     #[ORM\Column(name: 'date', type: 'datetimetz_immutable')]
  31.     protected \DateTimeImmutable $date;
  32.     #[ORM\JoinColumn(name: 'price_id', referencedColumnName: 'id')]
  33.     #[ORM\ManyToOne(targetEntity: PaidPlacementPrice::class)]
  34.     protected ?PaidPlacementPrice $price;
  35.     #[ORM\OneToOne(targetEntity: AccountTransaction::class, mappedBy: 'charge', cascade: ['all'])]
  36.     protected AccountTransaction $transaction;
  37.     #[ORM\Column(name: 'placement_start', type: 'datetimetz_immutable', nullable: true)]
  38.     protected ?\DateTimeImmutable $placementStart;
  39.     #[ORM\Column(name: 'placement_end', type: 'datetimetz_immutable', nullable: true)]
  40.     protected ?\DateTimeImmutable $placementEnd;
  41.     public function __construct(User $account, Money $chargedMoney, \DateTimeImmutable $date, ?PaidPlacementPrice $price, ?\DateTimeImmutable $placementStart, ?\DateTimeImmutable $placementEnd)
  42.     {
  43.         $this->account = $account;
  44.         $this->chargedAmount = $chargedMoney->getAmount();
  45.         $this->currency = $chargedMoney->getCurrency()->getCode();
  46.         $this->date = $date;
  47.         $this->price = $price;
  48.         $this->transaction = AccountTransaction::fromCharge($this);
  49.         $this->placementStart = $placementStart;
  50.         $this->placementEnd = $placementEnd;
  51.     }
  52.     public function getId(): int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getAccount(): User
  57.     {
  58.         return $this->account;
  59.     }
  60.     public function getChargedMoney(): Money
  61.     {
  62.         return new Money($this->chargedAmount, new Currency($this->currency));
  63.     }
  64.     public function getDate(): \DateTimeImmutable
  65.     {
  66.         return $this->date;
  67.     }
  68.     public function getPrice(): ?PaidPlacementPrice
  69.     {
  70.         return $this->price;
  71.     }
  72.     public function getTransaction(): AccountTransaction
  73.     {
  74.         return $this->transaction;
  75.     }
  76.     public function getPlacementStart(): ?\DateTimeImmutable
  77.     {
  78.         return $this->placementStart;
  79.     }
  80.     public function getPlacementEnd(): ?\DateTimeImmutable
  81.     {
  82.         return $this->placementEnd;
  83.     }
  84. }