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
|
|
|
|
{
|
2020-03-11 22:16:52 +03:00
|
|
|
protected $transaction;
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
protected $request;
|
|
|
|
|
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));
|
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
|
|
|
$this->transaction = Transaction::create($this->request->all());
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
// Upload attachment
|
|
|
|
if ($this->request->file('attachment')) {
|
|
|
|
$media = $this->getMedia($this->request->file('attachment'), 'transactions');
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
$this->transaction->attachMedia($media, 'attachment');
|
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
// Recurring
|
|
|
|
$this->transaction->createRecurring();
|
|
|
|
});
|
2020-03-11 22:16:52 +03:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|