prevent change/delete for reconciled records
This commit is contained in:
@@ -41,6 +41,12 @@ class DeleteTransaction extends Job
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if ($this->transaction->reconciled) {
|
||||
$message = trans('messages.warning.reconciled_tran');
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
if ($this->transaction->category->id == Category::transfer()) {
|
||||
throw new \Exception('Unauthorized');
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class UpdateTransaction extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
$this->transaction->update($this->request->all());
|
||||
|
||||
// Upload attachment
|
||||
@@ -44,4 +46,18 @@ class UpdateTransaction extends Job
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ class DeleteBill extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
Transaction::mute();
|
||||
|
||||
$this->deleteRelationships($this->bill, [
|
||||
@@ -39,4 +41,18 @@ class DeleteBill extends Job
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ class DeleteInvoice extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
Transaction::mute();
|
||||
|
||||
$this->deleteRelationships($this->invoice, [
|
||||
@@ -39,4 +41,18 @@ class DeleteInvoice extends Job
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +174,28 @@ class Transaction extends Model
|
||||
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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user