mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-17 15:24:38 -04:00
Merge branch 'v5-develop' of https://github.com/turbo124/invoiceninja into v5-develop
This commit is contained in:
commit
15dc54a719
@ -20,11 +20,6 @@ use Illuminate\Database\Eloquent\Builder;
|
|||||||
class DocumentFilters extends QueryFilters
|
class DocumentFilters extends QueryFilters
|
||||||
{
|
{
|
||||||
|
|
||||||
// public function client_id(int $client_id) :Builder
|
|
||||||
// {
|
|
||||||
// return $this->builder->where('client_id', $client_id);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter based on search text.
|
* Filter based on search text.
|
||||||
*
|
*
|
||||||
@ -41,6 +36,14 @@ class DocumentFilters extends QueryFilters
|
|||||||
return $this->builder;
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If client ID passed to this entity, simply return */
|
||||||
|
public function client_id(string $client_id = '') :Builder
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->builder;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the list based on $sort.
|
* Sorts the list based on $sort.
|
||||||
*
|
*
|
||||||
@ -64,6 +67,7 @@ class DocumentFilters extends QueryFilters
|
|||||||
*/
|
*/
|
||||||
public function baseQuery(int $company_id, User $user) : Builder
|
public function baseQuery(int $company_id, User $user) : Builder
|
||||||
{
|
{
|
||||||
|
return $this->builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
118
app/Filters/PaymentTermFilters.php
Normal file
118
app/Filters/PaymentTermFilters.php
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Filters;
|
||||||
|
|
||||||
|
use App\Models\Design;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PaymentTermFilters.
|
||||||
|
*/
|
||||||
|
class PaymentTermFilters extends QueryFilters
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Filter based on search text.
|
||||||
|
*
|
||||||
|
* @param string query filter
|
||||||
|
* @return Builder
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function filter(string $filter = '') : Builder
|
||||||
|
{
|
||||||
|
if (strlen($filter) == 0) {
|
||||||
|
return $this->builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->builder->where(function ($query) use ($filter) {
|
||||||
|
$query->where('payment_terms.name', 'like', '%'.$filter.'%');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the list based on the status
|
||||||
|
* archived, active, deleted.
|
||||||
|
*
|
||||||
|
* @param string filter
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public function status(string $filter = '') : Builder
|
||||||
|
{
|
||||||
|
if (strlen($filter) == 0) {
|
||||||
|
return $this->builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
$table = 'payment_terms';
|
||||||
|
$filters = explode(',', $filter);
|
||||||
|
|
||||||
|
return $this->builder->where(function ($query) use ($filters, $table) {
|
||||||
|
$query->whereNull($table.'.id');
|
||||||
|
|
||||||
|
if (in_array(parent::STATUS_ACTIVE, $filters)) {
|
||||||
|
$query->orWhereNull($table.'.deleted_at');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array(parent::STATUS_ARCHIVED, $filters)) {
|
||||||
|
$query->orWhere(function ($query) use ($table) {
|
||||||
|
$query->whereNotNull($table.'.deleted_at');
|
||||||
|
|
||||||
|
if (! in_array($table, ['users'])) {
|
||||||
|
$query->where($table.'.is_deleted', '=', 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array(parent::STATUS_DELETED, $filters)) {
|
||||||
|
$query->orWhere($table.'.is_deleted', '=', 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts the list based on $sort.
|
||||||
|
*
|
||||||
|
* @param string sort formatted as column|asc
|
||||||
|
* @return Builder
|
||||||
|
*/
|
||||||
|
public function sort(string $sort) : Builder
|
||||||
|
{
|
||||||
|
$sort_col = explode('|', $sort);
|
||||||
|
|
||||||
|
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the base query.
|
||||||
|
*
|
||||||
|
* @param int company_id
|
||||||
|
* @param User $user
|
||||||
|
* @return Builder
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function baseQuery(int $company_id, User $user) : Builder
|
||||||
|
{
|
||||||
|
return $this->builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the query by the users company ID.
|
||||||
|
*
|
||||||
|
* @return Illuminate\Database\Query\Builder
|
||||||
|
*/
|
||||||
|
public function entityFilter()
|
||||||
|
{
|
||||||
|
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||||
|
return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ use App\Transformers\PaymentTermTransformer;
|
|||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
use App\Filters\PaymentTermFilters;
|
||||||
|
|
||||||
class PaymentTermController extends BaseController
|
class PaymentTermController extends BaseController
|
||||||
{
|
{
|
||||||
@ -73,9 +74,9 @@ class PaymentTermController extends BaseController
|
|||||||
* ),
|
* ),
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index(PaymentTermFilters $filters)
|
||||||
{
|
{
|
||||||
$payment_terms = PaymentTerm::whereCompanyId(auth()->user()->company()->id)->orWhere('company_id', null);
|
$payment_terms = PaymentTerm::filter($filters);
|
||||||
|
|
||||||
return $this->listResponse($payment_terms);
|
return $this->listResponse($payment_terms);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Filterable;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,6 +20,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||||||
class PaymentTerm extends BaseModel
|
class PaymentTerm extends BaseModel
|
||||||
{
|
{
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
use Filterable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
|
@ -33,19 +33,6 @@ class NinjaTranslationServiceProvider extends TranslationServiceProvider
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// $this->app->bind('translator', function($app) {
|
|
||||||
|
|
||||||
// $loader = $app['translation.loader'];
|
|
||||||
// $locale = $app['config']['app.locale'];
|
|
||||||
|
|
||||||
// $trans = new NinjaTranslator($loader, $locale);
|
|
||||||
|
|
||||||
// $trans->setFallback($app['config']['app.fallback_locale']);
|
|
||||||
|
|
||||||
// return $trans;
|
|
||||||
|
|
||||||
// });
|
|
||||||
|
|
||||||
$this->app->singleton('translator', function ($app) {
|
$this->app->singleton('translator', function ($app) {
|
||||||
|
|
||||||
$loader = $app['translation.loader'];
|
$loader = $app['translation.loader'];
|
||||||
|
@ -299,7 +299,10 @@ class InvoiceService
|
|||||||
if($this->invoice->status_id == Invoice::STATUS_DRAFT)
|
if($this->invoice->status_id == Invoice::STATUS_DRAFT)
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
if ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
|
if($this->invoice->balance == 0){
|
||||||
|
$this->setStatus(Invoice::STATUS_PAID);
|
||||||
|
}
|
||||||
|
elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
|
||||||
$this->setStatus(Invoice::STATUS_PARTIAL);
|
$this->setStatus(Invoice::STATUS_PARTIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<env name="SESSION_DRIVER" value="array"/>
|
<env name="SESSION_DRIVER" value="array"/>
|
||||||
<env name="QUEUE_CONNECTION" value="sync"/>
|
<env name="QUEUE_CONNECTION" value="sync"/>
|
||||||
<env name="MAIL_MAILER" value="array"/>
|
<env name="MAIL_MAILER" value="array"/>
|
||||||
<env name="DB_CONNECTION" value="mysql"/>
|
<env name="DB_CONNECTION" value="sqlite"/>
|
||||||
<env name="DB_DATABASE" value=":memory:"/>
|
<env name="DB_DATABASE" value=":memory:"/>
|
||||||
</php>
|
</php>
|
||||||
<logging/>
|
<logging/>
|
||||||
|
@ -60,7 +60,6 @@
|
|||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
document.querySelector('div[data-ref="required-fields-container"]').classList.add('hidden');
|
document.querySelector('div[data-ref="required-fields-container"]').classList.add('hidden');
|
||||||
|
|
||||||
document.querySelector('div[data-ref="gateway-container"]').classList.remove('opacity-25');
|
document.querySelector('div[data-ref="gateway-container"]').classList.remove('opacity-25');
|
||||||
document.querySelector('div[data-ref="gateway-container"]').classList.remove('pointer-events-none');
|
document.querySelector('div[data-ref="gateway-container"]').classList.remove('pointer-events-none');
|
||||||
});
|
});
|
||||||
|
@ -57,6 +57,37 @@ class PaymentTermsApiTest extends TestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testPaymentTermsGetStatusActive()
|
||||||
|
{
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->get('/api/v1/payment_terms?status=active');
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaymentTermsGetStatusArchived()
|
||||||
|
{
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->get('/api/v1/payment_terms?status=archived');
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPaymentTermsGetStatusDeleted()
|
||||||
|
{
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->get('/api/v1/payment_terms?status=deleted');
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
public function testPostPaymentTerm()
|
public function testPostPaymentTerm()
|
||||||
{
|
{
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user