akaunting/app/Jobs/Setting/CreateCurrency.php

32 lines
834 B
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
namespace App\Jobs\Setting;
use App\Abstracts\Job;
2021-09-06 11:53:57 +03:00
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\ShouldCreate;
2019-11-16 10:21:14 +03:00
use App\Models\Setting\Currency;
2021-09-06 11:53:57 +03:00
class CreateCurrency extends Job implements HasOwner, ShouldCreate
2019-11-16 10:21:14 +03:00
{
2021-09-06 11:53:57 +03:00
public function handle(): Currency
2019-11-16 10:21:14 +03:00
{
// Force the rate to be 1 for default currency
if ($this->request->get('default_currency')) {
$this->request['rate'] = '1';
}
2020-06-26 13:40:19 +03:00
\DB::transaction(function () {
2021-09-06 11:53:57 +03:00
$this->model = Currency::create($this->request->all());
2019-11-16 10:21:14 +03:00
2020-06-26 13:40:19 +03:00
// Update default currency setting
if ($this->request->get('default_currency')) {
setting()->set('default.currency', $this->request->get('code'));
setting()->save();
}
});
2019-11-16 10:21:14 +03:00
2021-09-06 11:53:57 +03:00
return $this->model;
2019-11-16 10:21:14 +03:00
}
}