1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Recurring Invoices query

This commit is contained in:
David Bomba 2021-08-29 20:34:53 +10:00
parent d3c4e1080a
commit a17227f2ca
3 changed files with 27 additions and 1 deletions

View File

@ -84,6 +84,7 @@ class BaseController extends Controller
'company.payments.documents',
'company.payment_terms.company',
'company.projects.documents',
'company.recurring_expenses',
'company.recurring_invoices',
'company.recurring_invoices.invitations.contact',
'company.recurring_invoices.invitations.company',
@ -304,6 +305,13 @@ class BaseController extends Controller
if(!$user->hasPermission('view_recurring_invoice'))
$query->where('recurring_invoices.user_id', $user->id)->orWhere('recurring_invoices.assigned_user_id', $user->id);
},
'company.recurring_expenses'=> function ($query) use ($updated_at, $user) {
$query->where('updated_at', '>=', $updated_at)->with('documents');
if(!$user->hasPermission('view_recurring_expense'))
$query->where('recurring_expenses.user_id', $user->id)->orWhere('recurring_expenses.assigned_user_id', $user->id);
},
'company.tasks'=> function ($query) use ($updated_at, $user) {
$query->where('updated_at', '>=', $updated_at)->with('documents');

View File

@ -259,6 +259,14 @@ class Company extends BaseModel
return $this->hasMany(RecurringInvoice::class)->withTrashed();
}
/**
* @return HasMany
*/
public function recurring_expenses()
{
return $this->hasMany(RecurringExpense::class)->withTrashed();
}
/**
* @return HasMany
*/

View File

@ -13,7 +13,6 @@ namespace App\Transformers;
use App\Models\Account;
use App\Models\Activity;
use App\Models\Subscription;
use App\Models\Client;
use App\Models\Company;
use App\Models\CompanyGateway;
@ -31,13 +30,16 @@ use App\Models\PaymentTerm;
use App\Models\Product;
use App\Models\Project;
use App\Models\Quote;
use App\Models\RecurringExpense;
use App\Models\RecurringInvoice;
use App\Models\Subscription;
use App\Models\SystemLog;
use App\Models\Task;
use App\Models\TaskStatus;
use App\Models\TaxRate;
use App\Models\User;
use App\Models\Webhook;
use App\Transformers\RecurringExpenseTransformer;
use App\Utils\Traits\MakesHash;
use stdClass;
@ -92,6 +94,7 @@ class CompanyTransformer extends EntityTransformer
'expense_categories',
'task_statuses',
'subscriptions',
'recurring_expenses',
];
/**
@ -295,6 +298,13 @@ class CompanyTransformer extends EntityTransformer
return $this->includeCollection($company->recurring_invoices, $transformer, RecurringInvoice::class);
}
public function includeRecurringExpenses(Company $company)
{
$transformer = new RecurringExpenseTransformer($this->serializer);
return $this->includeCollection($company->recurring_expenses, $transformer, RecurringExpense::class);
}
public function includeQuotes(Company $company)
{
$transformer = new QuoteTransformer($this->serializer);