Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Initial process form.
James Cole26c9b2c3531b
diff --git a/app/Http/Controllers/CsvController.php b/app/Http/Controllers/CsvController.phpindex 3f2504a7a4..4e40bbeed7 100644--- a/app/Http/Controllers/CsvController.php+++ b/app/Http/Controllers/CsvController.php@@ -8,6 +8,8 @@namespace FireflyIII\Http\Controllers;+use Auth;+use Crypt;use Illuminate\Http\Request;use Input;use League\Csv\Reader;@@ -42,7 +44,7 @@ class CsvController extends Controller$subTitle = trans('firefly.csv_import');// can actually upload?- $uploadPossible = !is_writable(storage_path('upload'));+ $uploadPossible = is_writable(storage_path('upload'));$path = storage_path('upload');@@ -54,6 +56,21 @@ class CsvController extends Controller*/public function upload(Request $request){+ // possible column roles:+ $roles = [+ '(ignore this column)',+ 'Asset account name',+ 'Expense or revenue account name',+ 'Amount',+ 'Date',+ 'Currency',+ 'Description',+ 'Category',+ 'Budget',++ ];++if (!$request->hasFile('csv')) {Session::flash('warning', 'No file uploaded.');@@ -64,29 +81,31 @@ class CsvController extends Controller$reader = Reader::createFromPath($request->file('csv')->getRealPath());$data = $reader->query();$data->next(); // go to first row:- if ($hasHeaders) {- // first row = headers.+ $count = count($data->current());+ $headers = [];+ for ($i = 1; $i <= $count; $i++) {+ $headers[] = trans('firefly.csv_row') . ' #' . $i;+ }+ if ($hasHeaders) {$headers = $data->current();- } else {- $count = count($data->current());- $headers = [];- for ($i = 1; $i <= $count; $i++) {- $headers[] = trans('firefly.csv_row') . ' #' . $i;- }}// example data is always the second row:$data->next();$example = $data->current();-- var_dump($headers);- var_dump($example);-- // store file somewhere temporary?--- exit;+ // store file somewhere temporary (encrypted)?+ $time = str_replace(' ', '-', microtime());+ $fileName = 'csv-upload-' . Auth::user()->id . '-' . $time . '.csv.encrypted';+ $fullPath = storage_path('upload') . DIRECTORY_SEPARATOR . $fileName;+ $content = file_get_contents($request->file('csv')->getRealPath());+ $content = Crypt::encrypt($content);+ file_put_contents($fullPath, $content);+ Session::put('latestCSVUpload', $fullPath);++ $subTitle = trans('firefly.csv_process');++ return view('csv.upload', compact('headers', 'example', 'roles', 'subTitle'));}}\ No newline at end of filediff --git a/resources/twig/csv/upload.twig b/resources/twig/csv/upload.twignew file mode 100644index 0000000000..4b0b34cd07--- /dev/null+++ b/resources/twig/csv/upload.twig@@ -0,0 +1,71 @@+{% extends "./layout/default.twig" %}++{% block breadcrumbs %}+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }}+{% endblock %}++{% block content %}+++<div class="row">+ <div class="col-lg-12">+ <div class="box">+ <div class="box-header with-border">+ <h3 class="box-title">{{ 'csv_process'|_ }}</h3>++ <!-- ACTIONS MENU -->+ <div class="box-tools pull-right">+ <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>+ </div>++ </div>+ <div class="box-body">+ {{ 'csv_process_text'|_ }}+ </div>+ </div>++ </div>+</div>+ <div class="row">+ <div class="col-lg-12">+ <div class="box">+ <div class="box-header with-border">+ <h3 class="box-title">{{ 'csv_process_form'|_ }}</h3>++ <!-- ACTIONS MENU -->+ <div class="box-tools pull-right">+ <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>+ </div>++ </div>+ <div class="box-body">++ <table class="table">+ <thead>+ <th>{{ 'cvs_column_name'|_ }}</th>+ <th>{{ 'cvs_column_example'|_ }}</th>+ <th>{{ 'cvs_column_role'|_ }}</th>+ <th>{{ 'do_map_value'|_ }}</th>+ </thead>+ {% for index,header in headers %}+ <tr>+ <td>{{ header }}</td>+ <td>{{ example[index] }}</td>+ <td>+ {{ Form.select(('role_'~index), roles) }}+ </td>+ <td>+ {{ Form.checkbox(('map_'~index),false) }}+ </td>++ </tr>+ {% endfor %}+ </table>+++ </div>+ </div>+ </div>+ </div>++{% endblock %}