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
|
|
|
/**
|
|
|
|
* @param string $locale
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-11-05 08:00:18 +00:00
|
|
|
public function formatToCurrency($value,$locale = 'de_DE')
|
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
|
|
|
|
|
|
|
public function getTaxPercent(){
|
|
|
|
$tax = Configuration::getValueByKey("SALES_TAX");
|
|
|
|
if ( $tax < 0 ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return $tax;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTaxValue(){
|
|
|
|
return $this->price*$this->getTaxPercent()/100;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTotalPrice(){
|
|
|
|
return $this->price+($this->getTaxValue());
|
|
|
|
}
|
2021-06-05 09:26:32 +00:00
|
|
|
}
|