2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Banking;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
|
|
|
use App\Models\Banking\Transaction;
|
|
|
|
|
|
|
|
class UpdateTransaction extends Job
|
|
|
|
{
|
|
|
|
protected $transaction;
|
|
|
|
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param $transaction
|
|
|
|
* @param $request
|
|
|
|
*/
|
|
|
|
public function __construct($transaction, $request)
|
|
|
|
{
|
|
|
|
$this->transaction = $transaction;
|
|
|
|
$this->request = $this->getRequestInstance($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return Transaction
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2020-03-13 14:55:50 +03:00
|
|
|
$this->authorize();
|
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
|
|
|
$this->transaction->update($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')) {
|
2021-02-09 11:54:53 +03:00
|
|
|
$this->transaction->delete_attachment();
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2021-02-09 11:54:53 +03:00
|
|
|
foreach ($this->request->file('attachment') as $attachment) {
|
|
|
|
$media = $this->getMedia($attachment, 'transactions');
|
|
|
|
|
|
|
|
$this->transaction->attachMedia($media, 'attachment');
|
|
|
|
}
|
|
|
|
} elseif (!$this->request->file('attachment') && $this->transaction->attachment) {
|
|
|
|
$this->transaction->delete_attachment();
|
2020-06-26 13:40:19 +03:00
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
// Recurring
|
|
|
|
$this->transaction->updateRecurring();
|
|
|
|
});
|
2019-11-16 10:21:14 +03:00
|
|
|
|
|
|
|
return $this->transaction;
|
|
|
|
}
|
2020-03-13 14:55:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if this action is applicable.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
if ($this->transaction->reconciled) {
|
|
|
|
$message = trans('messages.warning.reconciled_tran');
|
|
|
|
|
|
|
|
throw new \Exception($message);
|
|
|
|
}
|
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|