createSaleCommand->execute($data); try { DB::beginTransaction(); //create transactions for the sale app(CreateRecordTransactionsAction::class)($record, $transactions); $accountIds = collect($transactions) ->pluck('account_id') ->filter() ->unique() ->values() ->all(); //sync accounts to sale app(SyncAccountsAction::class)($record, $accountIds); //increment current_series $this->createSeriesCommand->execute([ 'branch_id' => $record->branch_id, 'series' => $record->reference_number, ]); DB::commit(); } catch (\Exception $exception) { DB::rollBack(); throw new \Exception('Failed to save transactions : '.$exception->getMessage()); } return $record; } }