prevent change/delete for reconciled records

This commit is contained in:
denisdulici
2020-03-13 14:55:50 +03:00
parent 88a3159d68
commit d46e6c44ac
6 changed files with 78 additions and 0 deletions

View File

@ -41,6 +41,12 @@ class DeleteTransaction extends Job
*/ */
public function authorize() public function authorize()
{ {
if ($this->transaction->reconciled) {
$message = trans('messages.warning.reconciled_tran');
throw new \Exception($message);
}
if ($this->transaction->category->id == Category::transfer()) { if ($this->transaction->category->id == Category::transfer()) {
throw new \Exception('Unauthorized'); throw new \Exception('Unauthorized');
} }

View File

@ -30,6 +30,8 @@ class UpdateTransaction extends Job
*/ */
public function handle() public function handle()
{ {
$this->authorize();
$this->transaction->update($this->request->all()); $this->transaction->update($this->request->all());
// Upload attachment // Upload attachment
@ -44,4 +46,18 @@ class UpdateTransaction extends Job
return $this->transaction; return $this->transaction;
} }
/**
* 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);
}
}
} }

View File

@ -27,6 +27,8 @@ class DeleteBill extends Job
*/ */
public function handle() public function handle()
{ {
$this->authorize();
Transaction::mute(); Transaction::mute();
$this->deleteRelationships($this->bill, [ $this->deleteRelationships($this->bill, [
@ -39,4 +41,18 @@ class DeleteBill extends Job
return true; return true;
} }
/**
* Determine if this action is applicable.
*
* @return void
*/
public function authorize()
{
if ($this->bill->transactions()->isReconciled()->count()) {
$message = trans('messages.warning.reconciled_doc', ['type' => trans_choice('general.bills', 1)]);
throw new \Exception($message);
}
}
} }

View File

@ -27,6 +27,8 @@ class DeleteInvoice extends Job
*/ */
public function handle() public function handle()
{ {
$this->authorize();
Transaction::mute(); Transaction::mute();
$this->deleteRelationships($this->invoice, [ $this->deleteRelationships($this->invoice, [
@ -39,4 +41,18 @@ class DeleteInvoice extends Job
return true; return true;
} }
/**
* Determine if this action is applicable.
*
* @return void
*/
public function authorize()
{
if ($this->invoice->transactions()->isReconciled()->count()) {
$message = trans('messages.warning.reconciled_doc', ['type' => trans_choice('general.invoices', 1)]);
throw new \Exception($message);
}
}
} }

View File

@ -174,6 +174,28 @@ class Transaction extends Model
return $query->sum('amount'); return $query->sum('amount');
} }
/**
* Get only reconciled.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIsReconciled($query)
{
return $query->where('reconciled', 1);
}
/**
* Get only not reconciled.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIsNotReconciled($query)
{
return $query->where('reconciled', 0);
}
/** /**
* Convert amount to double. * Convert amount to double.
* *

View File

@ -28,6 +28,8 @@ return [
'warning' => [ 'warning' => [
'deleted' => 'Warning: You are not allowed to delete <b>:name</b> because it has :text related.', 'deleted' => 'Warning: You are not allowed to delete <b>:name</b> because it has :text related.',
'disabled' => 'Warning: You are not allowed to disable <b>:name</b> because it has :text related.', 'disabled' => 'Warning: You are not allowed to disable <b>:name</b> because it has :text related.',
'reconciled_tran' => 'Warning: You are not allowed to change/delete transaction because it is reconciled!',
'reconciled_doc' => 'Warning: You are not allowed to change/delete :type because it has reconciled transactions!',
'disable_code' => 'Warning: You are not allowed to disable or change the currency of <b>:name</b> because it has :text related.', 'disable_code' => 'Warning: You are not allowed to disable or change the currency of <b>:name</b> because it has :text related.',
'payment_cancel' => 'Warning: You have cancelled your recent :method payment!', 'payment_cancel' => 'Warning: You have cancelled your recent :method payment!',
], ],