89 lines
2.1 KiB
PHP
Raw Normal View History

2020-12-24 01:28:38 +03:00
<?php
namespace App\View\Components\Documents;
2022-06-01 10:15:55 +03:00
use App\Abstracts\View\Component;
2020-12-24 01:28:38 +03:00
use App\Models\Setting\Currency;
use App\Models\Setting\Tax;
2022-06-01 10:15:55 +03:00
use App\Traits\ViewComponents;
2020-12-24 01:28:38 +03:00
class Script extends Component
{
2022-06-01 10:15:55 +03:00
use ViewComponents;
2020-12-24 01:28:38 +03:00
2022-06-01 10:15:55 +03:00
public const OBJECT_TYPE = 'document';
public const DEFAULT_TYPE = 'invoice';
public const DEFAULT_PLURAL_TYPE = 'invoices';
2020-12-24 01:28:38 +03:00
/** @var string */
2022-06-01 10:15:55 +03:00
public $type;
public $document;
2020-12-24 01:28:38 +03:00
public $items;
public $currencies;
public $currency_code;
2020-12-24 01:28:38 +03:00
public $taxes;
2022-06-01 10:15:55 +03:00
/** @var string */
public $alias;
/** @var string */
public $folder;
/** @var string */
public $file;
2020-12-24 01:28:38 +03:00
/**
* Create a new component instance.
*
* @return void
*/
2022-06-01 10:15:55 +03:00
public function __construct(
string $type = '', $document = false, $items = [], $currencies = [], $taxes = [],
string $alias = '', string $folder = '', string $file = ''
) {
2020-12-24 01:28:38 +03:00
$this->type = $type;
$this->document = $document;
2020-12-24 01:28:38 +03:00
$this->items = $items;
$this->currencies = $this->getCurrencies($currencies);
$this->currency_code = ($document) ? $document->currency_code : default_currency();
2020-12-24 01:28:38 +03:00
$this->taxes = $this->getTaxes($taxes);
2022-06-01 10:15:55 +03:00
$this->alias = $this->getAlias($type, $alias);
$this->folder = $this->getScriptFolder($type, $folder);
$this->file = $this->getScriptFile($type, $file);
2020-12-24 01:28:38 +03:00
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|string
*/
public function render()
{
return view('components.documents.script');
}
protected function getCurrencies($currencies)
{
if (!empty($currencies)) {
return $currencies;
}
return Currency::enabled()->orderBy('name')->get()->makeHidden(['id', 'company_id', 'created_at', 'updated_at', 'deleted_at']);
}
protected function getTaxes($taxes)
{
if (!empty($taxes)) {
return $taxes;
}
return Tax::enabled()->orderBy('name')->get()->makeHidden(['company_id', 'created_at', 'updated_at', 'deleted_at']);
}
}