1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Import CSV

This commit is contained in:
David Bomba 2020-12-15 09:59:41 +11:00
parent 864892a7d2
commit 57ee54032f
4 changed files with 56 additions and 3 deletions

View File

@ -12,9 +12,11 @@
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Http\Requests\Import\ImportRequest;
use App\Http\Requests\Import\PreImportRequest;
use App\Import\Definitions\Import\ImportMap;
use App\Import\Definitions\InvoiceMap;
use App\Jobs\Import\CSVImport;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
@ -91,6 +93,12 @@ class ImportController extends Controller
return response()->json($data);
}
public function import(ImportRequest $request)
{
CSVImport::dispatch($request, auth()->user()->company());
return response()->json(['message' => 'Importing data, email will be sent on completion'], 200);
}
private function getCsvData($csvfile)
{

View File

@ -0,0 +1,37 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Import;
use App\Http\Requests\Request;
class ImportRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
public function rules()
{
return [
'hash' => 'required',
'entity_type' => 'required',
];
}
}

View File

@ -12,7 +12,6 @@
namespace App\Http\Requests\Import;
use App\Http\Requests\Request;
use App\Models\GroupSetting;
class PreImportRequest extends Request
{
@ -30,7 +29,8 @@ class PreImportRequest extends Request
{
return [
'file' => 'required|file|mimes:csv,txt'
'file' => 'required|file|mimes:csv,txt',
'entity_type' => 'required',
];
}

View File

@ -54,6 +54,9 @@ class InvoiceMap
34 => 'invoice.line_items',
35 => 'client.name',
36 => 'client.email',
37 => 'payment.date',
38 => 'payment.amount',
39 => 'payment.transaction_reference',
];
}
@ -75,7 +78,7 @@ class InvoiceMap
12 => 'texts.public_notes',
13 => 'texts.private_notes',
14 => 'texts.uses_inclusive_taxes',
15 => 'texts.tax_name1',
15 => 'texts.tax_name',
16 => 'texts.tax_rate',
17 => 'texts.tax_name',
18 => 'texts.tax_rate',
@ -95,6 +98,11 @@ class InvoiceMap
32 => 'texts.surcharge',
33 => 'texts.exchange_rate',
34 => 'texts.items',
35 => 'texts.client_name',
36 => 'texts.email',
37 => 'texts.payment_date',
38 => 'texts.payment_amount',
39 => 'texts.transaction_reference',
];
}
}