2021-06-05 09:26:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Hidehalo\Nanoid\Client;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use NumberFormatter;
|
|
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
2021-11-05 16:38:05 +00:00
|
|
|
use App\Models\Configuration;
|
2021-06-05 09:26:32 +00:00
|
|
|
|
|
|
|
class PaypalProduct extends Model
|
|
|
|
{
|
|
|
|
use LogsActivity;
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $incrementing = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
|
|
|
"type",
|
|
|
|
"price",
|
|
|
|
"description",
|
|
|
|
"display",
|
|
|
|
"currency_code",
|
|
|
|
"quantity",
|
|
|
|
"disabled",
|
|
|
|
];
|
|
|
|
|
|
|
|
public static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
static::creating(function (PaypalProduct $paypalProduct) {
|
|
|
|
$client = new Client();
|
|
|
|
|
|
|
|
$paypalProduct->{$paypalProduct->getKeyName()} = $client->generateId($size = 21);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-23 09:28:57 +00:00
|
|
|
/**
|
2021-11-07 17:39:20 +00:00
|
|
|
* @param mixed $value
|
2021-06-23 09:28:57 +00:00
|
|
|
* @param string $locale
|
2021-11-07 17:43:38 +00:00
|
|
|
*
|
|
|
|
* @return float
|
2021-06-23 09:28:57 +00:00
|
|
|
*/
|
2021-11-07 17:02:53 +00:00
|
|
|
public function formatToCurrency($value,$locale = 'en_US')
|
2021-06-05 09:26:32 +00:00
|
|
|
{
|
|
|
|
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
|
2021-11-05 08:00:18 +00:00
|
|
|
return $formatter->formatCurrency($value, $this->currency_code);
|
2021-06-05 09:26:32 +00:00
|
|
|
}
|
2021-11-05 16:38:05 +00:00
|
|
|
|
2021-11-07 17:02:53 +00:00
|
|
|
/**
|
2021-11-07 17:39:20 +00:00
|
|
|
* @description Returns the tax in % taken from the Configuration
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2021-11-07 17:02:53 +00:00
|
|
|
public function getTaxPercent()
|
|
|
|
{
|
2021-11-05 16:38:05 +00:00
|
|
|
$tax = Configuration::getValueByKey("SALES_TAX");
|
2021-11-07 17:02:53 +00:00
|
|
|
return $tax < 0 ? 0 : $tax;
|
2021-11-05 16:38:05 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 17:02:53 +00:00
|
|
|
/**
|
2021-11-07 17:39:20 +00:00
|
|
|
* @description Returns the tax as Number
|
|
|
|
*
|
|
|
|
* @return float
|
|
|
|
*/
|
2021-11-07 17:02:53 +00:00
|
|
|
public function getTaxValue()
|
|
|
|
{
|
2021-11-05 16:38:05 +00:00
|
|
|
return $this->price*$this->getTaxPercent()/100;
|
|
|
|
}
|
|
|
|
|
2021-11-07 17:02:53 +00:00
|
|
|
/**
|
2021-11-07 17:39:20 +00:00
|
|
|
* @description Returns the full price of a Product including tax
|
|
|
|
*
|
2021-11-07 17:43:38 +00:00
|
|
|
* @return float
|
2021-11-07 17:39:20 +00:00
|
|
|
*/
|
2021-11-07 17:02:53 +00:00
|
|
|
public function getTotalPrice()
|
|
|
|
{
|
2021-11-05 16:38:05 +00:00
|
|
|
return $this->price+($this->getTaxValue());
|
|
|
|
}
|
2021-06-05 09:26:32 +00:00
|
|
|
}
|