diff --git a/app/BulkActions/Banking/Reconciliations.php b/app/BulkActions/Banking/Reconciliations.php index 024614715..b8d3916bd 100644 --- a/app/BulkActions/Banking/Reconciliations.php +++ b/app/BulkActions/Banking/Reconciliations.php @@ -11,14 +11,14 @@ class Reconciliations extends BulkAction public $model = Reconciliation::class; public $actions = [ - 'enable' => [ - 'name' => 'general.enable', - 'message' => 'bulk_actions.message.enable', + 'reconcile' => [ + 'name' => 'reconciliations.reconcile', + 'message' => 'bulk_actions.message.reconcile', 'permission' => 'update-banking-reconciliations', ], - 'disable' => [ - 'name' => 'general.disable', - 'message' => 'bulk_actions.message.disable', + 'unreconcile' => [ + 'name' => 'reconciliations.unreconcile', + 'message' => 'bulk_actions.message.unreconcile', 'permission' => 'update-banking-reconciliations', ], 'delete' => [ @@ -28,37 +28,41 @@ class Reconciliations extends BulkAction ], ]; - public function enable($request) + public function reconcile($request) { $reconciliations = $this->getSelectedRecords($request); foreach ($reconciliations as $reconciliation) { - $reconciliation->enabled = 1; - $reconciliation->save(); + \DB::transaction(function () use ($reconciliation) { + $reconciliation->reconciled = 1; + $reconciliation->save(); - Transaction::where('account_id', $reconciliation->account_id) - ->reconciled() - ->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) { - $item->reconciled = 1; - $item->save(); - }); + Transaction::where('account_id', $reconciliation->account_id) + ->isNotReconciled() + ->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) { + $item->reconciled = 1; + $item->save(); + }); + }); } } - public function disable($request) + public function unreconcile($request) { $reconciliations = $this->getSelectedRecords($request); foreach ($reconciliations as $reconciliation) { - $reconciliation->enabled = 0; - $reconciliation->save(); + \DB::transaction(function () use ($reconciliation) { + $reconciliation->reconciled = 0; + $reconciliation->save(); - Transaction::where('account_id', $reconciliation->account_id) - ->reconciled() - ->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) { - $item->reconciled = 0; - $item->save(); - }); + Transaction::where('account_id', $reconciliation->account_id) + ->isReconciled() + ->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) { + $item->reconciled = 0; + $item->save(); + }); + }); } } @@ -67,14 +71,16 @@ class Reconciliations extends BulkAction $reconciliations = $this->getSelectedRecords($request); foreach ($reconciliations as $reconciliation) { - $reconciliation->delete(); + \DB::transaction(function () use ($reconciliation) { + $reconciliation->delete(); - Transaction::where('account_id', $reconciliation->account_id) - ->reconciled() - ->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) { - $item->reconciled = 0; - $item->save(); - }); + Transaction::where('account_id', $reconciliation->account_id) + ->isReconciled() + ->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) { + $item->reconciled = 0; + $item->save(); + }); + }); } } } diff --git a/app/Jobs/Banking/DeleteReconciliation.php b/app/Jobs/Banking/DeleteReconciliation.php index ca5ae50e0..98de26b5c 100644 --- a/app/Jobs/Banking/DeleteReconciliation.php +++ b/app/Jobs/Banking/DeleteReconciliation.php @@ -30,7 +30,7 @@ class DeleteReconciliation extends Job $this->reconciliation->delete(); Transaction::where('account_id', $this->reconciliation->account_id) - ->reconciled() + ->isReconciled() ->whereBetween('paid_at', [$this->reconciliation->started_at, $this->reconciliation->ended_at])->each(function ($transaction) { $transaction->reconciled = 0; $transaction->save(); diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index 7680e291c..40002fb37 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -4,7 +4,6 @@ namespace App\Models\Banking; use App\Abstracts\Model; use App\Models\Setting\Category; -use App\Models\Setting\Currency; use App\Traits\Currencies; use App\Traits\DateTime; use App\Traits\Media; diff --git a/resources/lang/en-GB/bulk_actions.php b/resources/lang/en-GB/bulk_actions.php index 4c420c141..3706b8f20 100644 --- a/resources/lang/en-GB/bulk_actions.php +++ b/resources/lang/en-GB/bulk_actions.php @@ -16,6 +16,8 @@ return [ 'sent' => 'Are you sure you want to mark selected invoice as sent?|Are you sure you want to mark selected invoices as sent?', 'received' => 'Are you sure you want to mark selected bill as received?|Are you sure you want to mark selected bills as received?', 'cancelled' => 'Are you sure you want to cancel selected invoice/bill?|Are you sure you want to cancel selected invoices/bills?', + 'reconcile' => 'Are you sure you want to reconcile selected record?|Are you sure you want to reconcile selected records?', + 'unreconcile' => 'Are you sure you want to unreconcile selected record?|Are you sure you want to unreconcile selected records?', ], ]; diff --git a/resources/lang/en-GB/reconciliations.php b/resources/lang/en-GB/reconciliations.php index 967621945..04dede8ec 100644 --- a/resources/lang/en-GB/reconciliations.php +++ b/resources/lang/en-GB/reconciliations.php @@ -3,6 +3,7 @@ return [ 'reconcile' => 'Reconcile', + 'unreconcile' => 'Unreconcile', 'reconciled' => 'Reconciled', 'opening_balance' => 'Opening Balance', 'closing_balance' => 'Closing Balance', diff --git a/resources/views/banking/reconciliations/index.blade.php b/resources/views/banking/reconciliations/index.blade.php index 08cf8ec26..edc0cb5f1 100644 --- a/resources/views/banking/reconciliations/index.blade.php +++ b/resources/views/banking/reconciliations/index.blade.php @@ -35,11 +35,11 @@ {{ Form::bulkActionAllGroup() }} @sortablelink('created_at', trans('general.created_date'), ['filter' => 'active, visible'], ['class' => 'col-aka', 'rel' => 'nofollow']) - @sortablelink('account_id', trans_choice('general.accounts', 1)) - {{ trans('general.period') }} + @sortablelink('account_id', trans_choice('general.accounts', 1)) + {{ trans('general.period') }} @sortablelink('closing_balance', trans('reconciliations.closing_balance')) - @sortablelink('status', trans_choice('general.statuses', 1)) - {{ trans('general.actions') }} + @sortablelink('status', trans_choice('general.statuses', 1)) + {{ trans('general.actions') }} @@ -48,17 +48,17 @@ {{ Form::bulkActionGroup($item->id, $item->account->name) }} @date($item->created_at) - {{ $item->account->name }} - @date($item->started_at) - @date($item->ended_at) + {{ $item->account->name }} + @date($item->started_at) - @date($item->ended_at) @money($item->closing_balance, $item->account->currency_code, true) - + @if ($item->reconciled) {{ trans('reconciliations.reconciled') }} @else {{ trans('reconciliations.unreconciled') }} @endif - +