Files
2023-05-30 22:02:09 +08:00

133 lines
4.0 KiB
PHP

<?php
namespace App\Classes\Modules\Bookings\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyServiceConfigurationsObject;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidatedVoucherObject;
class CalculationObject implements DataTransferObject
{
/** @var CurrencyConversionObject */
private $conversionObject;
/** @var CompanyServiceConfigurationsObject */
private $configurations;
/** @var ValidatedVoucherObject */
private $voucherObject;
/**
* CalculationObject constructor.
* @param CurrencyConversionObject $conversionObject
* @param CompanyServiceConfigurationsObject $configurations
* @param ValidatedVoucherObject $voucherObject
*/
public function __construct(CurrencyConversionObject $conversionObject, CompanyServiceConfigurationsObject $configurations, ?ValidatedVoucherObject $voucherObject = null)
{
$this->conversionObject = $conversionObject;
$this->configurations = $configurations;
$this->voucherObject = $voucherObject;
}
/**
* @return CurrencyConversionObject
*/
public function getConversionObject(): CurrencyConversionObject
{
return $this->conversionObject;
}
/**
* @return CompanyServiceConfigurationsObject
*/
public function getConfigurations(): CompanyServiceConfigurationsObject
{
return $this->configurations;
}
/**
* @return ValidatedVoucherObject
*/
public function getValidatedVoucherObject(): ?ValidatedVoucherObject
{
return $this->voucherObject;
}
public function getConvertibleTotal(){
return $this->getConversionObject()->getType() === 1 ? $this->getConversionObject()->getAmount() : $this->getConversionTotal();
}
/**
* @return float
*/
public function getConversionTotal(): float {
$rate = $this->getConversionObject()->getType() === 1 ? (1/$this->getConfigurations()->getRate()) : $this->getConfigurations()->getRate();
return $this->getConversionObject()->getAmount() * $rate;
}
/**
* @return float
*/
public function getLocalTotal(){
return $this->getConversionObject()->getType() === 1 ? $this->getConversionTotal() : $this->getConversionObject()->getAmount();
}
/**
* @return float
*/
public function getForeignTotal(){
return $this->getConversionObject()->getType() === 1 ? $this->getConversionObject()->getAmount() : $this->getConversionTotal();
}
/**
* @return float
*/
public function getServiceCharge(): float {
return ($this->getLocalTotal()/100) * $this->getConfigurations()->getServiceCharge() < $this->getConfigurations()->getMinimumCharge() ? $this->getConfigurations()->getMinimumCharge() : ($this->getLocalTotal()/100) * $this->getConfigurations()->getServiceCharge();
}
public function getSubTotal(): float {
return $this->getLocalTotal() + $this->getServiceCharge();
}
/**
* @return float
*/
public function getTax(): float {
return ($this->getSubTotal()/100) * $this->getConfigurations()->getTax();
}
public function getVoucherDiscountAmount(): float {
if($this->getValidatedVoucherObject()){
return $this->getValidatedVoucherObject()->getTotalDiscountAmount();
}
else{
return 0.00;
}
}
public function getVoucherCode(): string {
if($this->getValidatedVoucherObject()){
return $this->getValidatedVoucherObject()->getCode();
}
else{
return "";
}
}
public function getTotal(): float {
if($this->getValidatedVoucherObject()){
return $this->getValidatedVoucherObject()->getTotalAmount() + $this->getTax();
}
else{
return $this->getSubTotal() + $this->getTax();
}
}
}