<commit_before><?php
/**
 * SingleController.php
 * Copyright (C) 2016 <EMAIL>
 *
 * This software may be modified and distributed under the terms of the
 * Creative Commons Attribution-ShareAlike 4.0 International License.
 *
 * See the LICENSE file for details.
 */

declare(strict_types=1);

namespace FireflyIII\Http\Controllers\Transaction;


use ExpandedForm;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\JournalFormRequest;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Log;
use Preferences;
use Session;
use Steam;
use View;

/**
 * Class SingleController
 *
 * @package FireflyIII\Http\Controllers\Transaction
 */
class SingleController extends Controller
{
    /** @var  AccountRepositoryInterface */
    private $accounts;

    /** @var AttachmentHelperInterface */
    private $attachments;

    /** @var  BudgetRepositoryInterface */
    private $budgets;
    /** @var  CurrencyRepositoryInterface */
    private $currency;
    /** @var  PiggyBankRepositoryInterface */
    private $piggyBanks;

    /**
     *
     */
    public function __construct()
    {
        parent::__construct();

        $maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
        $maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
        $uploadSize  = min($maxFileSize, $maxPostSize);
        View::share('uploadSize', $uploadSize);

        // some useful repositories:
        $this->middleware(
            function ($request, $next) {
                $this->accounts    = app(AccountRepositoryInterface::class);
                $this->budgets     = app(BudgetRepositoryInterface::class);
                $this->piggyBanks  = app(PiggyBankRepositoryInterface::class);
                $this->attachments = app(AttachmentHelperInterface::class);
                $this->currency    = app(CurrencyRepositoryInterface::class);

                View::share('title', trans('firefly.transactions'));
                View::share('mainTitleIcon', 'fa-repeat');

                return $next($request);
            }
        );

    }

    public function cloneTransaction(TransactionJournal $journal)
    {
        $source       = $journal->sourceAccountList()->first();
        $destination  = $journal->destinationAccountList()->first();
        $budget       = $journal->budgets()->first();
        $budgetId     = is_null($budget) ? 0 : $budget->id;
        $category     = $journal->categories()->first();
        $categoryName = is_null($category) ? '' : $category->name;
        $tags         = join(',', $journal->tags()->get()->pluck('tag')->toArray());


        $preFilled = [
            'description'              => $journal->description,
            'source_account_id'        => $source->id,
            'source_account_name'      => $source->name,
            'destination_account_id'   => $destination->id,
            'destination_account_name' => $destination->name,
            'amount'                   => $journal->amountPositive(),
            'date'                     => $journal->date->format('Y-m-d'),
            'budget_id'                => $budgetId,<commit_msg>Fix #672<commit_after><?php
/**
 * SingleController.php
 * Copyright (C) 2016 <EMAIL>
 *
 * This software may be modified and distributed under the terms of the
 * Creative Commons Attribution-ShareAlike 4.0 International License.
 *
 * See the LICENSE file for details.
 */

declare(strict_types=1);

namespace FireflyIII\Http\Controllers\Transaction;


use ExpandedForm;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\JournalFormRequest;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Log;
use Preferences;
use Session;
use Steam;
use View;

/**
 * Class SingleController
 *
 * @package FireflyIII\Http\Controllers\Transaction
 */
class SingleController extends Controller
{
    /** @var  AccountRepositoryInterface */
    private $accounts;

    /** @var AttachmentHelperInterface */
    private $attachments;

    /** @var  BudgetRepositoryInterface */
    private $budgets;
    /** @var  CurrencyRepositoryInterface */
    private $currency;
    /** @var  PiggyBankRepositoryInterface */
    private $piggyBanks;

    /**
     *
     */
    public function __construct()
    {
        parent::__construct();

        $maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
        $maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
        $uploadSize  = min($maxFileSize, $maxPostSize);
        View::share('uploadSize', $uploadSize);

        // some useful repositories:
        $this->middleware(
            function ($request, $next) {
                $this->accounts    = app(AccountRepositoryInterface::class);
                $this->budgets     = app(BudgetRepositoryInterface::class);
                $this->piggyBanks  = app(PiggyBankRepositoryInterface::class);
                $this->attachments = app(AttachmentHelperInterface::class);
                $this->currency    = app(CurrencyRepositoryInterface::class);

                View::share('title', trans('firefly.transactions'));
                View::share('mainTitleIcon', 'fa-repeat');

                return $next($request);
            }
        );

    }

    public function cloneTransaction(TransactionJournal $journal)
    {
        $source        = $journal->sourceAccountList()->first();
        $destination   = $journal->destinationAccountList()->first();
        $budget        = $journal->budgets()->first();
        $budgetId      = is_null($budget) ? 0 : $budget->id;
        $category      = $journal->categories()->first();
        $categoryName  = is_null($category) ? '' : $category->name;
        $tags          = join(',', $journal->tags()->get()->pluck('tag')->toArray());
        $transaction   = $journal->transactions()->first();
        $amount        = Steam::positive($transaction->amount);
        $foreignAmount = is_null($transaction->foreign_amount) ? null : Steam::positive($transaction->foreign_amount);

        $preFilled = [
            'description'              => $journal->description,
            'source_account_id'        => $source->id,
            'source_account_name'      => $source->name,
            'destination_account_id'   => $destination->id,
            'destination_account_name' => $destination->name,
            'amount'                   => $amount,
            'source_amount'            => $amount,
            'destination_amount'       => $foreignAmount,
            'foreign_amount'           => $foreignAmount,
            'date'                     => $journal->date->format('Y-m-d'),
            'budget_id'                => $budgetId,
{'fraction_non_alphanumeric': 0.1261910893638939, 'fraction_numerical': 0.0024465619366469227, 'mean_word_length': 2.8796203796203796, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6811241', 'n_tokens_mistral': 2130, 'n_tokens_neox': 2080, 'n_words': 362}