diff --git a/VERSION.txt b/VERSION.txt index 3113d499b22c..ef0ff164084a 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.7.8 \ No newline at end of file +5.7.9 \ No newline at end of file diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 3dac3bb6163f..7c5a3f21bb42 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -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()) { diff --git a/app/Filters/InvoiceFilters.php b/app/Filters/InvoiceFilters.php index 8ade4be3a6a1..91e426192fde 100644 --- a/app/Filters/InvoiceFilters.php +++ b/app/Filters/InvoiceFilters.php @@ -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. diff --git a/app/Filters/PaymentFilters.php b/app/Filters/PaymentFilters.php index b6c82430baad..af094202aaed 100644 --- a/app/Filters/PaymentFilters.php +++ b/app/Filters/PaymentFilters.php @@ -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. * diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index f46e35133b4d..f6ae18029457 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -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; } diff --git a/config/ninja.php b/config/ninja.php index a530a2dd26d4..cac415703b6c 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -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', ''), diff --git a/public/storage/.htaccess b/public/storage/.htaccess new file mode 100644 index 000000000000..377516b7230a --- /dev/null +++ b/public/storage/.htaccess @@ -0,0 +1,4 @@ + +Order deny,Allow +Deny from all + diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore old mode 100755 new mode 100644 diff --git a/tests/Feature/InvoiceTest.php b/tests/Feature/InvoiceTest.php index 8730566b12b0..e0530f5b2056 100644 --- a/tests/Feature/InvoiceTest.php +++ b/tests/Feature/InvoiceTest.php @@ -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([ diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 7a69e0b0a3ab..25cd22f894b2 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -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'),