akaunting/app/Jobs/Banking/CreateTransaction.php

52 lines
1.1 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
namespace App\Jobs\Banking;
use App\Abstracts\Job;
2020-03-11 22:16:52 +03:00
use App\Events\Banking\TransactionCreated;
use App\Events\Banking\TransactionCreating;
2020-03-12 14:29:21 +03:00
use App\Models\Banking\Transaction;
2019-11-16 10:21:14 +03:00
class CreateTransaction extends Job
{
protected $request;
2020-03-12 14:29:21 +03:00
2020-03-11 22:16:52 +03:00
protected $transaction;
2019-11-16 10:21:14 +03:00
/**
* Create a new job instance.
*
* @param $request
*/
public function __construct($request)
{
$this->request = $this->getRequestInstance($request);
}
/**
* Execute the job.
*
* @return Transaction
*/
public function handle()
{
2020-03-11 22:16:52 +03:00
event(new TransactionCreating($this->request));
$this->transaction = Transaction::create($this->request->all());
2019-11-16 10:21:14 +03:00
// Upload attachment
if ($this->request->file('attachment')) {
$media = $this->getMedia($this->request->file('attachment'), 'transactions');
2020-03-11 22:16:52 +03:00
$this->transaction->attachMedia($media, 'attachment');
2019-11-16 10:21:14 +03:00
}
// Recurring
2020-03-11 22:16:52 +03:00
$this->transaction->createRecurring();
event(new TransactionCreated($this->transaction));
2019-11-16 10:21:14 +03:00
2020-03-11 22:16:52 +03:00
return $this->transaction;
2019-11-16 10:21:14 +03:00
}
}