fixed reconciliation actions

This commit is contained in:
Denis Duliçi 2020-08-20 12:55:59 +03:00
parent 9b0d5604ba
commit 95f5c8cd73
6 changed files with 49 additions and 41 deletions

View File

@ -11,14 +11,14 @@ class Reconciliations extends BulkAction
public $model = Reconciliation::class; public $model = Reconciliation::class;
public $actions = [ public $actions = [
'enable' => [ 'reconcile' => [
'name' => 'general.enable', 'name' => 'reconciliations.reconcile',
'message' => 'bulk_actions.message.enable', 'message' => 'bulk_actions.message.reconcile',
'permission' => 'update-banking-reconciliations', 'permission' => 'update-banking-reconciliations',
], ],
'disable' => [ 'unreconcile' => [
'name' => 'general.disable', 'name' => 'reconciliations.unreconcile',
'message' => 'bulk_actions.message.disable', 'message' => 'bulk_actions.message.unreconcile',
'permission' => 'update-banking-reconciliations', 'permission' => 'update-banking-reconciliations',
], ],
'delete' => [ 'delete' => [
@ -28,37 +28,41 @@ class Reconciliations extends BulkAction
], ],
]; ];
public function enable($request) public function reconcile($request)
{ {
$reconciliations = $this->getSelectedRecords($request); $reconciliations = $this->getSelectedRecords($request);
foreach ($reconciliations as $reconciliation) { foreach ($reconciliations as $reconciliation) {
$reconciliation->enabled = 1; \DB::transaction(function () use ($reconciliation) {
$reconciliation->reconciled = 1;
$reconciliation->save(); $reconciliation->save();
Transaction::where('account_id', $reconciliation->account_id) Transaction::where('account_id', $reconciliation->account_id)
->reconciled() ->isNotReconciled()
->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) { ->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) {
$item->reconciled = 1; $item->reconciled = 1;
$item->save(); $item->save();
}); });
});
} }
} }
public function disable($request) public function unreconcile($request)
{ {
$reconciliations = $this->getSelectedRecords($request); $reconciliations = $this->getSelectedRecords($request);
foreach ($reconciliations as $reconciliation) { foreach ($reconciliations as $reconciliation) {
$reconciliation->enabled = 0; \DB::transaction(function () use ($reconciliation) {
$reconciliation->reconciled = 0;
$reconciliation->save(); $reconciliation->save();
Transaction::where('account_id', $reconciliation->account_id) Transaction::where('account_id', $reconciliation->account_id)
->reconciled() ->isReconciled()
->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) { ->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) {
$item->reconciled = 0; $item->reconciled = 0;
$item->save(); $item->save();
}); });
});
} }
} }
@ -67,14 +71,16 @@ class Reconciliations extends BulkAction
$reconciliations = $this->getSelectedRecords($request); $reconciliations = $this->getSelectedRecords($request);
foreach ($reconciliations as $reconciliation) { foreach ($reconciliations as $reconciliation) {
\DB::transaction(function () use ($reconciliation) {
$reconciliation->delete(); $reconciliation->delete();
Transaction::where('account_id', $reconciliation->account_id) Transaction::where('account_id', $reconciliation->account_id)
->reconciled() ->isReconciled()
->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) { ->whereBetween('paid_at', [$reconciliation->started_at, $reconciliation->ended_at])->each(function ($item) {
$item->reconciled = 0; $item->reconciled = 0;
$item->save(); $item->save();
}); });
});
} }
} }
} }

View File

@ -30,7 +30,7 @@ class DeleteReconciliation extends Job
$this->reconciliation->delete(); $this->reconciliation->delete();
Transaction::where('account_id', $this->reconciliation->account_id) Transaction::where('account_id', $this->reconciliation->account_id)
->reconciled() ->isReconciled()
->whereBetween('paid_at', [$this->reconciliation->started_at, $this->reconciliation->ended_at])->each(function ($transaction) { ->whereBetween('paid_at', [$this->reconciliation->started_at, $this->reconciliation->ended_at])->each(function ($transaction) {
$transaction->reconciled = 0; $transaction->reconciled = 0;
$transaction->save(); $transaction->save();

View File

@ -4,7 +4,6 @@ namespace App\Models\Banking;
use App\Abstracts\Model; use App\Abstracts\Model;
use App\Models\Setting\Category; use App\Models\Setting\Category;
use App\Models\Setting\Currency;
use App\Traits\Currencies; use App\Traits\Currencies;
use App\Traits\DateTime; use App\Traits\DateTime;
use App\Traits\Media; use App\Traits\Media;

View File

@ -16,6 +16,8 @@ return [
'sent' => 'Are you sure you want to mark selected invoice as <b>sent</b>?|Are you sure you want to mark selected invoices as <b>sent</b>?', 'sent' => 'Are you sure you want to mark selected invoice as <b>sent</b>?|Are you sure you want to mark selected invoices as <b>sent</b>?',
'received' => 'Are you sure you want to mark selected bill as <b>received</b>?|Are you sure you want to mark selected bills as <b>received</b>?', 'received' => 'Are you sure you want to mark selected bill as <b>received</b>?|Are you sure you want to mark selected bills as <b>received</b>?',
'cancelled' => 'Are you sure you want to <b>cancel</b> selected invoice/bill?|Are you sure you want to <b>cancel</b> selected invoices/bills?', 'cancelled' => 'Are you sure you want to <b>cancel</b> selected invoice/bill?|Are you sure you want to <b>cancel</b> selected invoices/bills?',
'reconcile' => 'Are you sure you want to <b>reconcile</b> selected record?|Are you sure you want to <b>reconcile</b> selected records?',
'unreconcile' => 'Are you sure you want to <b>unreconcile</b> selected record?|Are you sure you want to <b>unreconcile</b> selected records?',
], ],
]; ];

View File

@ -3,6 +3,7 @@
return [ return [
'reconcile' => 'Reconcile', 'reconcile' => 'Reconcile',
'unreconcile' => 'Unreconcile',
'reconciled' => 'Reconciled', 'reconciled' => 'Reconciled',
'opening_balance' => 'Opening Balance', 'opening_balance' => 'Opening Balance',
'closing_balance' => 'Closing Balance', 'closing_balance' => 'Closing Balance',

View File

@ -35,11 +35,11 @@
<tr class="row table-head-line"> <tr class="row table-head-line">
<th class="col-sm-2 col-md-1 col-lg-1 d-none d-sm-block">{{ Form::bulkActionAllGroup() }}</th> <th class="col-sm-2 col-md-1 col-lg-1 d-none d-sm-block">{{ Form::bulkActionAllGroup() }}</th>
<th class="col-sm-3 col-md-2 col-lg-2 d-none d-sm-block">@sortablelink('created_at', trans('general.created_date'), ['filter' => 'active, visible'], ['class' => 'col-aka', 'rel' => 'nofollow'])</th> <th class="col-sm-3 col-md-2 col-lg-2 d-none d-sm-block">@sortablelink('created_at', trans('general.created_date'), ['filter' => 'active, visible'], ['class' => 'col-aka', 'rel' => 'nofollow'])</th>
<th class="col-xs-4 col-sm-3 col-md-3 col-lg-3">@sortablelink('account_id', trans_choice('general.accounts', 1))</th> <th class="col-xs-3 col-sm-2 col-md-2 col-lg-2">@sortablelink('account_id', trans_choice('general.accounts', 1))</th>
<th class="col-lg-2 d-none d-lg-block">{{ trans('general.period') }}</th> <th class="col-md-2 col-lg-2 d-none d-lg-block">{{ trans('general.period') }}</th>
<th class="col-md-2 col-lg-2 d-none d-md-block text-right">@sortablelink('closing_balance', trans('reconciliations.closing_balance'))</th> <th class="col-md-2 col-lg-2 d-none d-md-block text-right">@sortablelink('closing_balance', trans('reconciliations.closing_balance'))</th>
<th class="col-xs-4 col-sm-2 col-md-2 col-lg-1">@sortablelink('status', trans_choice('general.statuses', 1))</th> <th class="col-xs-4 col-sm-2 col-md-2 col-lg-2">@sortablelink('status', trans_choice('general.statuses', 1))</th>
<th class="col-xs-4 col-sm-2 col-md-2 col-lg-1 text-center">{{ trans('general.actions') }}</th> <th class="col-xs-4 col-sm-2 col-md-1 col-lg-1 text-center">{{ trans('general.actions') }}</th>
</tr> </tr>
</thead> </thead>
@ -48,17 +48,17 @@
<tr class="row align-items-center border-top-1"> <tr class="row align-items-center border-top-1">
<td class="col-sm-2 col-md-1 col-lg-1 d-none d-sm-block">{{ Form::bulkActionGroup($item->id, $item->account->name) }}</td> <td class="col-sm-2 col-md-1 col-lg-1 d-none d-sm-block">{{ Form::bulkActionGroup($item->id, $item->account->name) }}</td>
<td class="col-sm-3 col-md-2 col-lg-2 d-none d-sm-block"><a class="col-aka" href="{{ route('reconciliations.edit', $item->id) }}">@date($item->created_at)</a></td> <td class="col-sm-3 col-md-2 col-lg-2 d-none d-sm-block"><a class="col-aka" href="{{ route('reconciliations.edit', $item->id) }}">@date($item->created_at)</a></td>
<td class="col-xs-4 col-sm-3 col-md-3 col-lg-3">{{ $item->account->name }}</td> <td class="col-xs-3 col-sm-2 col-md-2 col-lg-2">{{ $item->account->name }}</td>
<td class="col-lg-2 d-none d-lg-block border-0">@date($item->started_at) - @date($item->ended_at)</td> <td class="col-md-2 col-lg-2 d-none d-lg-block border-0">@date($item->started_at) - @date($item->ended_at)</td>
<td class="col-md-2 col-lg-2 d-none d-md-block text-right">@money($item->closing_balance, $item->account->currency_code, true)</td> <td class="col-md-2 col-lg-2 d-none d-md-block text-right">@money($item->closing_balance, $item->account->currency_code, true)</td>
<td class="col-xs-4 col-sm-2 col-md-2 col-lg-1"> <td class="col-xs-4 col-sm-2 col-md-2 col-lg-2">
@if ($item->reconciled) @if ($item->reconciled)
<span class="badge badge-pill badge-success">{{ trans('reconciliations.reconciled') }}</span> <span class="badge badge-pill badge-success">{{ trans('reconciliations.reconciled') }}</span>
@else @else
<span class="badge badge-pill badge-danger">{{ trans('reconciliations.unreconciled') }}</span> <span class="badge badge-pill badge-danger">{{ trans('reconciliations.unreconciled') }}</span>
@endif @endif
</td> </td>
<td class="col-xs-4 col-sm-2 col-md-2 col-lg-1 text-center"> <td class="col-xs-4 col-sm-2 col-md-1 col-lg-1 text-center">
<div class="dropdown"> <div class="dropdown">
<a class="btn btn-neutral btn-sm text-light items-align-center py-2" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <a class="btn btn-neutral btn-sm text-light items-align-center py-2" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-ellipsis-h text-muted"></i> <i class="fa fa-ellipsis-h text-muted"></i>