Merge branch 'v5-develop' of https://github.com/turbo124/invoiceninja into v5-develop

This commit is contained in:
David Bomba 2023-09-06 14:41:23 +10:00
commit 3541324d1a
10 changed files with 209 additions and 14 deletions

View File

@ -1 +1 @@
5.7.8
5.7.9

View File

@ -862,7 +862,7 @@ class CheckData extends Command
}
$records = DB::table($table)
->join($tableName, "{$tableName}.id", '=', "{$table}.{$field}_id")
->where("{$table}.{$company_id}", '!=', "{$tableName}.company_id")
->whereRaw("{$table}.{$company_id} != {$tableName}.company_id")
->get(["{$table}.id"]);
if ($records->count()) {

View File

@ -229,6 +229,32 @@ class InvoiceFilters extends QueryFilters
return $this->builder->where('due_date', '>=', $date);
}
public function date_range(string $date_range = ''): Builder
{
$parts = explode(",", $date_range);
if (count($parts) != 3) {
return $this->builder;
}
if(!in_array($parts[0], ['date','due_date'])) {
return $this->builder;
}
try{
$start_date = Carbon::parse($parts[1]);
$end_date = Carbon::parse($parts[2]);
return $this->builder->whereBetween($parts[0], [$start_date, $end_date]);
}
catch(\Exception $e){
return $this->builder;
}
return $this->builder;
}
/**
* Sorts the list based on $sort.

View File

@ -12,8 +12,9 @@
namespace App\Filters;
use App\Models\Payment;
use Illuminate\Contracts\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Database\Eloquent\Builder as EloquentBuilder;
/**
* PaymentFilters.
@ -177,6 +178,33 @@ class PaymentFilters extends QueryFilters
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
}
public function date_range(string $date_range = ''): Builder
{
$parts = explode(",", $date_range);
if (count($parts) != 3) {
return $this->builder;
}
if(!in_array($parts[0], ['date'])) {
return $this->builder;
}
try{
$start_date = Carbon::parse($parts[1]);
$end_date = Carbon::parse($parts[2]);
return $this->builder->whereBetween($parts[0], [$start_date, $end_date]);
}
catch(\Exception $e){
return $this->builder;
}
return $this->builder;
}
/**
* Filters the query by the users company ID.
*

View File

@ -123,6 +123,7 @@ class ImportController extends Controller
$hit = false;
$unsetKey = false;
// array_multisort(array_column($translated_keys, 'label'), SORT_ASC, $translated_keys);
foreach($translated_keys as $tkey => $tvalue)
{
@ -131,10 +132,10 @@ class ImportController extends Controller
$hit = $available_keys[$tvalue['key']];
$unsetKey = $tkey;
}
elseif($this->testMatch($value, $tvalue['index'])) {
$hit = $available_keys[$tvalue['key']];
$unsetKey = $tkey;
}
// elseif($this->testMatch($value, $tvalue['index'])) {
// $hit = $available_keys[$tvalue['key']];
// $unsetKey = $tkey;
// }
}
@ -148,13 +149,13 @@ class ImportController extends Controller
}
nlog($translated_keys);
return $hints;
}
private function testMatch($haystack, $needle): bool
{ nlog("needle = {$needle}");
nlog("haystack = {$haystack}");
{
return stripos($haystack, $needle) !== false;
}

View File

@ -15,8 +15,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => env('APP_VERSION','5.7.8'),
'app_tag' => env('APP_TAG','5.7.8'),
'app_version' => env('APP_VERSION','5.7.9'),
'app_tag' => env('APP_TAG','5.7.9'),
'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', ''),

4
public/storage/.htaccess Normal file
View File

@ -0,0 +1,4 @@
<Files *.php>
Order deny,Allow
Deny from all
</Files>

0
storage/app/public/.gitignore vendored Executable file → Normal file
View File

View File

@ -48,6 +48,70 @@ class InvoiceTest extends TestCase
$this->makeTestData();
}
public function testInvoiceGetDatesBetween()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/invoices?date_range=date,2023-01-01,2023-01-01', )
->assertStatus(200);
}
public function testInvoiceGetDatesBetween2()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/invoices?date_range=date', )
->assertStatus(200);
}
public function testInvoiceGetDatesBetween3()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/invoices?date_range=x', )
->assertStatus(200);
}
public function testInvoiceGetDatesBetween4()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/invoices?date_range=date,2023223123,312312321', )
->assertStatus(200);
}
public function testInvoiceGetDatesBetween5()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/invoices?date_range=date,x,23423', )
->assertStatus(200);
}
public function testInvoiceGetDatesBetween6()
{
Invoice::factory()->count(10)->create([
'company_id' => $this->company->id,
'user_id' => $this->user->id,
'client_id' => $this->client->id,
'date' => '1971-01-02',
]);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/invoices?date_range=date,1971-01-01,1971-01-03', )
->assertStatus(200);
$arr = $response->json();
$this->assertCount(10, $arr['data']);
}
public function testInvoiceGetPaidReversedInvoice()
{
@ -66,7 +130,6 @@ class InvoiceTest extends TestCase
$this->assertCount(1, $arr['data']);
}
public function testInvoiceGetPaidInvoices()
{
$response = $this->withHeaders([

View File

@ -60,7 +60,80 @@ class PaymentTest extends TestCase
);
}
public function testPatymentGetClientStatus()
public function testPaymentGetBetweenQuery1()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/payments?date_range=date,2023-01-01,2023-02-01');
$response->assertStatus(200);
}
public function testPaymentGetBetweenQuery2()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/payments?date_range=');
$response->assertStatus(200);
}
public function testPaymentGetBetweenQuery3()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/payments?date_range=1,1,1,1,1');
$response->assertStatus(200);
}
public function testPaymentGetBetweenQuery4()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/payments?date_range=date,34343,34343434343');
$response->assertStatus(200);
}
public function testPaymentGetBetweenQuery5()
{
Payment::factory()->count(10)->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'client_id' => $this->client->id,
'date' => '2023-01-02',
]);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/payments?date_range=date,2023-01-01,2023-01-03');
$response->assertStatus(200);
$arr = $response->json();
$this->assertCount(10, $arr['data']);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->get('/api/v1/payments?date_range=date,2053-10-01,2053-10-03');
$response->assertStatus(200);
$arr = $response->json();
$this->assertCount(0, $arr['data']);
}
public function testPaymentGetClientStatus()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),