1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Merge pull request #4495 from turbo124/v5-develop

Fixes for query filters
This commit is contained in:
David Bomba 2020-12-15 20:38:36 +11:00 committed by GitHub
commit 4cc3289cec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 317 additions and 92 deletions

View File

@ -26,7 +26,7 @@ BROADCAST_DRIVER=log
LOG_CHANNEL=stack
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=cookie
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1

View File

@ -104,11 +104,11 @@ abstract class QueryFilters
* @param string $value
* @return stdClass
*/
public function split($value) : stdClass
public function split($value) : \stdClass
{
$exploded_array = explode(':', $value);
$parts = new stdClass;
$parts = new \stdClass;
$parts->value = $exploded_array[0];
$parts->operator = $this->operatorConvertor($exploded_array[1]);

View File

@ -12,8 +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;
@ -90,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

@ -66,6 +66,10 @@ class UpdateExpenseRequest extends Request
$input['category_id'] = $this->decodePrimaryKey($input['category_id']);
}
if (! array_key_exists('currency_id', $input) || strlen($input['currency_id']) == 0) {
$input['currency_id'] = (string)auth()->user()->company()->settings->currency_id;
}
$this->replace($input);
}
}

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

@ -17,41 +17,59 @@ class InvoiceMap
public static function importable()
{
return [
0 => 'number',
1 => 'user_id',
2 => 'amount',
3 => 'balance',
4 => 'client_id',
5 => 'status_id',
6 => 'is_deleted',
7 => 'discount',
8 => 'po_number',
9 => 'date',
10 => 'due_date',
11 => 'terms',
12 => 'public_notes',
13 => 'private_notes',
14 => 'uses_inclusive_taxes',
15 => 'tax_name1',
16 => 'tax_rate1',
17 => 'tax_name2',
18 => 'tax_rate2',
19 => 'tax_name3',
20 => 'tax_rate3',
21 => 'is_amount_discount',
22 => 'footer',
23 => 'partial',
24 => 'partial_due_date',
25 => 'custom_value1',
26 => 'custom_value2',
27 => 'custom_value3',
28 => 'custom_value4',
29 => 'custom_surcharge1',
30 => 'custom_surcharge2',
31 => 'custom_surcharge3',
32 => 'custom_surcharge4',
33 => 'exchange_rate',
34 => 'line_items',
0 => 'invoice.number',
1 => 'invoice.user_id',
2 => 'invoice.amount',
3 => 'invoice.balance',
4 => 'invoice.client_id',
5 => 'invoice.discount',
6 => 'invoice.po_number',
7 => 'invoice.date',
8 => 'invoice.due_date',
9 => 'invoice.terms',
10 => 'invoice.public_notes',
11 => 'invoice.is_sent',
12 => 'invoice.private_notes',
13 => 'invoice.uses_inclusive_taxes',
14 => 'invoice.tax_name1',
15 => 'invoice.tax_rate1',
16 => 'invoice.tax_name2',
17 => 'invoice.tax_rate2',
18 => 'invoice.tax_name3',
19 => 'invoice.tax_rate3',
20 => 'invoice.is_amount_discount',
21 => 'invoice.footer',
22 => 'invoice.partial',
23 => 'invoice.partial_due_date',
24 => 'invoice.custom_value1',
25 => 'invoice.custom_value2',
26 => 'invoice.custom_value3',
27 => 'invoice.custom_value4',
28 => 'invoice.custom_surcharge1',
29 => 'invoice.custom_surcharge2',
30 => 'invoice.custom_surcharge3',
31 => 'invoice.custom_surcharge4',
32 => 'invoice.exchange_rate',
33 => 'payment.date',
34 => 'payment.amount',
35 => 'payment.transaction_reference',
36 => 'item.quantity',
37 => 'item.cost',
38 => 'item.product_key',
39 => 'item.notes',
40 => 'item.discount',
41 => 'item.is_amount_discount',
42 => 'item.tax_name1',
43 => 'item.tax_rate1',
44 => 'item.tax_name2',
45 => 'item.tax_rate2',
46 => 'item.tax_name3',
47 => 'item.tax_rate3',
48 => 'item.custom_value1',
49 => 'item.custom_value2',
50 => 'item.custom_value3',
51 => 'item.custom_value4',
52 => 'item.type_id',
];
}
@ -63,36 +81,54 @@ class InvoiceMap
2 => 'texts.amount',
3 => 'texts.balance',
4 => 'texts.client',
5 => 'texts.status',
6 => 'texts.deleted',
7 => 'texts.discount',
8 => 'texts.po_number',
9 => 'texts.date',
10 => 'texts.due_date',
11 => 'texts.terms',
12 => 'texts.public_notes',
13 => 'texts.private_notes',
14 => 'texts.uses_inclusive_taxes',
15 => 'texts.tax_name1',
16 => 'texts.tax_rate',
17 => 'texts.tax_name',
18 => 'texts.tax_rate',
19 => 'texts.tax_name',
20 => 'texts.tax_rate',
21 => 'texts.is_amount_discount',
22 => 'texts.footer',
23 => 'texts.partial',
24 => 'texts.partial_due_date',
25 => 'texts.custom_value1',
26 => 'texts.custom_value2',
27 => 'texts.custom_value3',
28 => 'texts.custom_value4',
5 => 'texts.discount',
6 => 'texts.po_number',
7 => 'texts.date',
8 => 'texts.due_date',
9 => 'texts.terms',
10 => 'texts.public_notes',
11 => 'texts.sent',
12 => 'texts.private_notes',
13 => 'texts.uses_inclusive_taxes',
14 => 'texts.tax_name',
15 => 'texts.tax_rate',
16 => 'texts.tax_name',
17 => 'texts.tax_rate',
18 => 'texts.tax_name',
19 => 'texts.tax_rate',
20 => 'texts.is_amount_discount',
21 => 'texts.footer',
22 => 'texts.partial',
23 => 'texts.partial_due_date',
24 => 'texts.custom_value1',
25 => 'texts.custom_value2',
26 => 'texts.custom_value3',
27 => 'texts.custom_value4',
28 => 'texts.surcharge',
29 => 'texts.surcharge',
30 => 'texts.surcharge',
31 => 'texts.surcharge',
32 => 'texts.surcharge',
33 => 'texts.exchange_rate',
34 => 'texts.items',
32 => 'texts.exchange_rate',
33 => 'texts.payment_date',
34 => 'texts.payment_amount',
35 => 'texts.transaction_reference',
36 => 'texts.quantity',
37 => 'texts.cost',
38 => 'texts.product_key',
39 => 'texts.notes',
40 => 'texts.discount',
41 => 'texts.is_amount_discount',
42 => 'texts.tax_name',
43 => 'texts.tax_rate',
44 => 'texts.tax_name',
45 => 'texts.tax_rate',
46 => 'texts.tax_name',
47 => 'texts.tax_rate',
48 => 'texts.custom_value',
49 => 'texts.custom_value',
50 => 'texts.custom_value',
51 => 'texts.custom_value',
52 => 'texts.type',
];
}
}

View File

@ -0,0 +1,74 @@
<?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\Jobs\Import;
use App\Libraries\MultiDB;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;
class CSVImport implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $invoice;
public $company;
public $hash;
public $entity_type;
public $skip_headers;
public function __construct(Request $request, Company $company)
{
$this->request = $request;
$this->company = $company;
$this->hash = $request->input('hash');
$this->entity_type = $request->input('entity_type');
$this->skip_headers = $request->input('skip_headers');
}
/**
* Execute the job.
*
*
* @return void
*/
public function handle()
{
MultiDB::setDb($this->company->db);
}
public function failed($exception)
{
}
private function getCsv()
{
$base64_encoded_csv = Cache::get($this->hash);
return base64_decode($base64_encoded_csv);
}
}

View File

@ -104,6 +104,7 @@ class Import implements ShouldQueue
* @var array
*/
private $available_imports = [
'account',
'company',
'users',
'payment_terms',
@ -225,6 +226,13 @@ class Import implements ShouldQueue
});
}
private function processAccount(array $data) :void
{
$account = $this->company->account;
$account->fill($data);
$account->save();
}
/**
* @param array $data
* @throws Exception

View File

@ -79,6 +79,7 @@ class Company extends BaseModel
'invoice_task_timelog',
'auto_start_tasks',
'is_disabled',
'default_task_is_date_based',
];
protected $hidden = [

View File

@ -38,6 +38,7 @@ class Task extends BaseModel
'invoice_documents',
'rate',
'number',
'is_date_based',
];
protected $touches = [];

View File

@ -146,6 +146,7 @@ class CompanyTransformer extends EntityTransformer
'invoice_task_documents' => (bool) $company->invoice_task_documents,
'show_tasks_table' => (bool) $company->show_tasks_table,
'use_credits_payment' => 'always', //todo remove
'default_task_is_date_based' => (bool)$company->default_task_is_date_based,
];
}

View File

@ -66,6 +66,7 @@ class TaskTransformer extends EntityTransformer
'custom_value4' => $task->custom_value4 ?: '',
'status_id' => $this->encodePrimaryKey($task->status_id) ?: '',
'status_sort_order' => (int) $task->status_sort_order,
'is_date_based' => (bool) $task->is_date_based,
];
}
}

View File

@ -63,6 +63,14 @@ trait ClientGroupSettingsSaver
$entity_settings->{$key} = $value;
}
//this pass will handle any null values that are in the translations
foreach ($settings->translations as $key => $value) {
if (is_null($settings->translations[$key]))
$settings->translations[$key] = '';
}
$entity_settings->translations = $settings->translations;
$entity->settings = $entity_settings;
$entity->save();

View File

@ -58,6 +58,14 @@ trait CompanySettingsSaver
}
}
//this pass will handle any null values that are in the translations
foreach ($settings->translations as $key => $value) {
if (is_null($settings->translations[$key]))
$settings->translations[$key] = '';
}
$company_settings->translations = $settings->translations;
$entity->settings = $company_settings;
$entity->save();

49
composer.lock generated
View File

@ -116,16 +116,16 @@
},
{
"name": "aws/aws-sdk-php",
"version": "3.168.3",
"version": "3.169.0",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "49ef1f905388c8185012c9651b80941b8f2a218d"
"reference": "d15a231355e4435fc33bab83df075ec31edd0a9b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/49ef1f905388c8185012c9651b80941b8f2a218d",
"reference": "49ef1f905388c8185012c9651b80941b8f2a218d",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/d15a231355e4435fc33bab83df075ec31edd0a9b",
"reference": "d15a231355e4435fc33bab83df075ec31edd0a9b",
"shasum": ""
},
"require": {
@ -200,9 +200,9 @@
"support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues",
"source": "https://github.com/aws/aws-sdk-php/tree/3.168.3"
"source": "https://github.com/aws/aws-sdk-php/tree/3.169.0"
},
"time": "2020-12-11T19:12:18+00:00"
"time": "2020-12-14T19:12:33+00:00"
},
{
"name": "brick/math",
@ -4019,16 +4019,16 @@
},
{
"name": "monolog/monolog",
"version": "2.1.1",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
"reference": "f9eee5cec93dfb313a38b6b288741e84e53f02d5"
"reference": "1cb1cde8e8dd0f70cc0fe51354a59acad9302084"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/f9eee5cec93dfb313a38b6b288741e84e53f02d5",
"reference": "f9eee5cec93dfb313a38b6b288741e84e53f02d5",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/1cb1cde8e8dd0f70cc0fe51354a59acad9302084",
"reference": "1cb1cde8e8dd0f70cc0fe51354a59acad9302084",
"shasum": ""
},
"require": {
@ -4041,16 +4041,17 @@
"require-dev": {
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
"doctrine/couchdb": "~1.0@dev",
"elasticsearch/elasticsearch": "^6.0",
"elasticsearch/elasticsearch": "^7",
"graylog2/gelf-php": "^1.4.2",
"mongodb/mongodb": "^1.8",
"php-amqplib/php-amqplib": "~2.4",
"php-console/php-console": "^3.1.3",
"php-parallel-lint/php-parallel-lint": "^1.0",
"phpspec/prophecy": "^1.6.1",
"phpstan/phpstan": "^0.12.59",
"phpunit/phpunit": "^8.5",
"predis/predis": "^1.1",
"rollbar/rollbar": "^1.3",
"ruflin/elastica": ">=0.90 <3.0",
"ruflin/elastica": ">=0.90 <7.0.1",
"swiftmailer/swiftmailer": "^5.3|^6.0"
},
"suggest": {
@ -4070,7 +4071,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
"dev-main": "2.x-dev"
}
},
"autoload": {
@ -4086,11 +4087,11 @@
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
"homepage": "https://seld.be"
}
],
"description": "Sends your logs to files, sockets, inboxes, databases and various web services",
"homepage": "http://github.com/Seldaek/monolog",
"homepage": "https://github.com/Seldaek/monolog",
"keywords": [
"log",
"logging",
@ -4098,7 +4099,7 @@
],
"support": {
"issues": "https://github.com/Seldaek/monolog/issues",
"source": "https://github.com/Seldaek/monolog/tree/2.1.1"
"source": "https://github.com/Seldaek/monolog/tree/2.2.0"
},
"funding": [
{
@ -4110,7 +4111,7 @@
"type": "tidelift"
}
],
"time": "2020-07-23T08:41:23+00:00"
"time": "2020-12-14T13:15:25+00:00"
},
{
"name": "mtdowling/jmespath.php",
@ -11469,16 +11470,16 @@
},
{
"name": "phar-io/version",
"version": "3.0.3",
"version": "3.0.4",
"source": {
"type": "git",
"url": "https://github.com/phar-io/version.git",
"reference": "726c026815142e4f8677b7cb7f2249c9ffb7ecae"
"reference": "e4782611070e50613683d2b9a57730e9a3ba5451"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phar-io/version/zipball/726c026815142e4f8677b7cb7f2249c9ffb7ecae",
"reference": "726c026815142e4f8677b7cb7f2249c9ffb7ecae",
"url": "https://api.github.com/repos/phar-io/version/zipball/e4782611070e50613683d2b9a57730e9a3ba5451",
"reference": "e4782611070e50613683d2b9a57730e9a3ba5451",
"shasum": ""
},
"require": {
@ -11514,9 +11515,9 @@
"description": "Library for handling version information and constraints",
"support": {
"issues": "https://github.com/phar-io/version/issues",
"source": "https://github.com/phar-io/version/tree/3.0.3"
"source": "https://github.com/phar-io/version/tree/3.0.4"
},
"time": "2020-11-30T09:21:21+00:00"
"time": "2020-12-13T23:18:30+00:00"
},
{
"name": "php-cs-fixer/diff",

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class TaskFields extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tasks', function (Blueprint $table) {
$table->boolean('is_date_based')->default(false);
});
Schema::table('companies', function (Blueprint $table) {
$table->boolean('default_task_is_date_based')->default(false);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -3325,5 +3325,5 @@ return [
'custom_value3' => 'Custom Value',
'custom_value4' => 'Custom Value',
'inclusive_taxes' => 'Include taxes',
'sort_order' => 'Sort Order',
];