mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Initial process form.
This commit is contained in:
parent
16374bce9b
commit
26c9b2c353
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Controllers;
|
namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
|
use Crypt;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Input;
|
use Input;
|
||||||
use League\Csv\Reader;
|
use League\Csv\Reader;
|
||||||
@ -42,7 +44,7 @@ class CsvController extends Controller
|
|||||||
$subTitle = trans('firefly.csv_import');
|
$subTitle = trans('firefly.csv_import');
|
||||||
|
|
||||||
// can actually upload?
|
// can actually upload?
|
||||||
$uploadPossible = !is_writable(storage_path('upload'));
|
$uploadPossible = is_writable(storage_path('upload'));
|
||||||
$path = storage_path('upload');
|
$path = storage_path('upload');
|
||||||
|
|
||||||
|
|
||||||
@ -54,6 +56,21 @@ class CsvController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function upload(Request $request)
|
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')) {
|
if (!$request->hasFile('csv')) {
|
||||||
Session::flash('warning', 'No file uploaded.');
|
Session::flash('warning', 'No file uploaded.');
|
||||||
|
|
||||||
@ -64,29 +81,31 @@ class CsvController extends Controller
|
|||||||
$reader = Reader::createFromPath($request->file('csv')->getRealPath());
|
$reader = Reader::createFromPath($request->file('csv')->getRealPath());
|
||||||
$data = $reader->query();
|
$data = $reader->query();
|
||||||
$data->next(); // go to first row:
|
$data->next(); // go to first row:
|
||||||
if ($hasHeaders) {
|
|
||||||
|
|
||||||
// first row = headers.
|
|
||||||
$headers = $data->current();
|
|
||||||
} else {
|
|
||||||
$count = count($data->current());
|
$count = count($data->current());
|
||||||
$headers = [];
|
$headers = [];
|
||||||
for ($i = 1; $i <= $count; $i++) {
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
$headers[] = trans('firefly.csv_row') . ' #' . $i;
|
$headers[] = trans('firefly.csv_row') . ' #' . $i;
|
||||||
}
|
}
|
||||||
|
if ($hasHeaders) {
|
||||||
|
$headers = $data->current();
|
||||||
}
|
}
|
||||||
|
|
||||||
// example data is always the second row:
|
// example data is always the second row:
|
||||||
$data->next();
|
$data->next();
|
||||||
$example = $data->current();
|
$example = $data->current();
|
||||||
|
// 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);
|
||||||
|
|
||||||
var_dump($headers);
|
$subTitle = trans('firefly.csv_process');
|
||||||
var_dump($example);
|
|
||||||
|
|
||||||
// store file somewhere temporary?
|
return view('csv.upload', compact('headers', 'example', 'roles', 'subTitle'));
|
||||||
|
|
||||||
|
|
||||||
exit;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
71
resources/twig/csv/upload.twig
Normal file
71
resources/twig/csv/upload.twig
Normal file
@ -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 %}
|
Loading…
Reference in New Issue
Block a user