Skip to content

Commit

Permalink
fixed reconciliation actions
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Aug 20, 2020
1 parent 9b0d560 commit 95f5c8c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 41 deletions.
68 changes: 37 additions & 31 deletions app/BulkActions/Banking/Reconciliations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand All @@ -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();
});
});
}
}

Expand All @@ -67,14 +71,16 @@ public function destroy($request)
$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();
});
});
}
}
}
2 changes: 1 addition & 1 deletion app/Jobs/Banking/DeleteReconciliation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function handle()
$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();
Expand Down
1 change: 0 additions & 1 deletion app/Models/Banking/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

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;
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en-GB/bulk_actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
'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>?',
'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?',
],

];
1 change: 1 addition & 0 deletions resources/lang/en-GB/reconciliations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
return [

'reconcile' => 'Reconcile',
'unreconcile' => 'Unreconcile',
'reconciled' => 'Reconciled',
'opening_balance' => 'Opening Balance',
'closing_balance' => 'Closing Balance',
Expand Down
16 changes: 8 additions & 8 deletions resources/views/banking/reconciliations/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
<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-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-lg-2 d-none d-lg-block">{{ trans('general.period') }}</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-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-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-1 text-center">{{ trans('general.actions') }}</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-1 col-lg-1 text-center">{{ trans('general.actions') }}</th>
</tr>
</thead>

Expand All @@ -48,17 +48,17 @@
<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-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-lg-2 d-none d-lg-block border-0">@date($item->started_at) - @date($item->ended_at)</td>
<td class="col-xs-3 col-sm-2 col-md-2 col-lg-2">{{ $item->account->name }}</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-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)
<span class="badge badge-pill badge-success">{{ trans('reconciliations.reconciled') }}</span>
@else
<span class="badge badge-pill badge-danger">{{ trans('reconciliations.unreconciled') }}</span>
@endif
</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">
<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>
Expand Down

0 comments on commit 95f5c8c

Please sign in to comment.