added pointer interfaces for jobs
This commit is contained in:
@ -3,37 +3,19 @@
|
||||
namespace App\Jobs\Banking;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Jobs\Banking\CreateTransaction;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Banking\Transfer;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class CreateTransfer extends Job
|
||||
class CreateTransfer extends Job implements HasOwner, ShouldCreate
|
||||
{
|
||||
use Currencies;
|
||||
|
||||
protected $transfer;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
$this->request->merge(['created_by' => user_id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Transfer
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): Transfer
|
||||
{
|
||||
\DB::transaction(function () {
|
||||
$expense_currency_code = $this->getCurrencyCode('from');
|
||||
@ -42,7 +24,7 @@ class CreateTransfer extends Job
|
||||
$expense_currency_rate = $this->getCurrencyRate('from');
|
||||
$income_currency_rate = $this->getCurrencyRate('to');
|
||||
|
||||
$expense_transaction = Transaction::create([
|
||||
$expense_transaction = $this->dispatch(new CreateTransaction([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'expense',
|
||||
'account_id' => $this->request->get('from_account_id'),
|
||||
@ -56,7 +38,7 @@ class CreateTransfer extends Job
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
'created_by' => $this->request->get('created_by'),
|
||||
]);
|
||||
]));
|
||||
|
||||
$amount = $this->request->get('amount');
|
||||
|
||||
@ -65,7 +47,7 @@ class CreateTransfer extends Job
|
||||
$amount = $this->convertBetween($amount, $expense_currency_code, $expense_currency_rate, $income_currency_code, $income_currency_rate);
|
||||
}
|
||||
|
||||
$income_transaction = Transaction::create([
|
||||
$income_transaction = $this->dispatch(new CreateTransaction([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'type' => 'income',
|
||||
'account_id' => $this->request->get('to_account_id'),
|
||||
@ -79,9 +61,9 @@ class CreateTransfer extends Job
|
||||
'payment_method' => $this->request->get('payment_method'),
|
||||
'reference' => $this->request->get('reference'),
|
||||
'created_by' => $this->request->get('created_by'),
|
||||
]);
|
||||
]));
|
||||
|
||||
$this->transfer = Transfer::create([
|
||||
$this->model = Transfer::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'expense_transaction_id' => $expense_transaction->id,
|
||||
'income_transaction_id' => $income_transaction->id,
|
||||
@ -93,12 +75,12 @@ class CreateTransfer extends Job
|
||||
foreach ($this->request->file('attachment') as $attachment) {
|
||||
$media = $this->getMedia($attachment, 'transfers');
|
||||
|
||||
$this->transfer->attachMedia($media, 'attachment');
|
||||
$this->model->attachMedia($media, 'attachment');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $this->transfer;
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
protected function getCurrencyCode($type)
|
||||
|
Reference in New Issue
Block a user