Vourcherify

This commit is contained in:
Dillon
2023-05-30 22:02:09 +08:00
parent 44deab4542
commit 20d6ca47dc
39 changed files with 1102 additions and 35 deletions
@@ -5,6 +5,7 @@ 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
{
@@ -15,15 +16,20 @@ class CalculationObject implements DataTransferObject
/** @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)
public function __construct(CurrencyConversionObject $conversionObject, CompanyServiceConfigurationsObject $configurations, ?ValidatedVoucherObject $voucherObject = null)
{
$this->conversionObject = $conversionObject;
$this->configurations = $configurations;
$this->voucherObject = $voucherObject;
}
/**
@@ -43,6 +49,15 @@ class CalculationObject implements DataTransferObject
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();
}
@@ -87,9 +102,31 @@ class CalculationObject implements DataTransferObject
return ($this->getSubTotal()/100) * $this->getConfigurations()->getTax();
}
public function getTotal(): float {
return $this->getSubTotal() + $this->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();
}
}
}