ctrlpanel/app/Models/PaypalProduct.php

85 lines
1.8 KiB
PHP
Raw Normal View History

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-11-07 17:39:20 +00:00
* @param mixed $value
* @param string $locale
2021-11-07 17:39:20 +00:00
* @return NumberFormatter
*/
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
*
* @return int
*/
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
}