fixed reconciliation actions
This commit is contained in:
		@@ -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();
 | 
			
		||||
                    });
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user