mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Fix for archived relationships
This commit is contained in:
parent
bb8c2f80f6
commit
31037d44d9
@ -82,9 +82,7 @@ class ExpenseController extends BaseController
|
||||
'method' => 'POST',
|
||||
'url' => 'expenses',
|
||||
'title' => trans('texts.new_expense'),
|
||||
'vendors' => Vendor::scope()->with('vendor_contacts')->orderBy('name')->get(),
|
||||
'vendor' => $vendor,
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
||||
'clientPublicId' => $request->client_id,
|
||||
'categoryPublicId' => $request->category_id,
|
||||
];
|
||||
@ -160,14 +158,12 @@ class ExpenseController extends BaseController
|
||||
'url' => $url,
|
||||
'title' => 'Edit Expense',
|
||||
'actions' => $actions,
|
||||
'vendors' => Vendor::scope()->with('vendor_contacts')->orderBy('name')->get(),
|
||||
'vendorPublicId' => $expense->vendor ? $expense->vendor->public_id : null,
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
||||
'clientPublicId' => $expense->client ? $expense->client->public_id : null,
|
||||
'categoryPublicId' => $expense->expense_category ? $expense->expense_category->public_id : null,
|
||||
];
|
||||
|
||||
$data = array_merge($data, self::getViewModel());
|
||||
$data = array_merge($data, self::getViewModel($expense));
|
||||
|
||||
return View::make('expenses.edit', $data);
|
||||
}
|
||||
@ -287,12 +283,14 @@ class ExpenseController extends BaseController
|
||||
return $this->returnBulk($this->entityType, $action, $ids);
|
||||
}
|
||||
|
||||
private static function getViewModel()
|
||||
private static function getViewModel($expense = false)
|
||||
{
|
||||
return [
|
||||
'data' => Input::old('data'),
|
||||
'account' => Auth::user()->account,
|
||||
'categories' => ExpenseCategory::whereAccountId(Auth::user()->account_id)->withArchived()->orderBy('name')->get(),
|
||||
'vendors' => Vendor::scope()->withActiveOrSelected($expense ? $expense->vendor_id : false)->with('vendor_contacts')->orderBy('name')->get(),
|
||||
'clients' => Client::scope()->withActiveOrSelected($expense ? $expense->client_id : false)->with('contacts')->orderBy('name')->get(),
|
||||
'categories' => ExpenseCategory::whereAccountId(Auth::user()->account_id)->withActiveOrSelected($expense ? $expense->expense_category_id : false)->orderBy('name')->get(),
|
||||
'taxRates' => TaxRate::scope()->whereIsInclusive(false)->orderBy('name')->get(),
|
||||
'isRecurring' => false,
|
||||
];
|
||||
|
@ -82,13 +82,13 @@ class ProposalController extends BaseController
|
||||
{
|
||||
$proposal = $request->entity();
|
||||
|
||||
$data = array_merge($this->getViewmodel(), [
|
||||
$data = array_merge($this->getViewmodel($proposal), [
|
||||
'proposal' => $proposal,
|
||||
'entity' => $proposal,
|
||||
'method' => 'PUT',
|
||||
'url' => 'proposals/' . $proposal->public_id,
|
||||
'title' => trans('texts.edit_proposal'),
|
||||
'invoices' => Invoice::scope()->with('client.contacts', 'client.country')->unapprovedQuotes($proposal->invoice_id)->orderBy('id')->get(),
|
||||
'invoices' => Invoice::scope()->with('client.contacts', 'client.country')->withActiveOrSelected($proposal->invoice_id)->unapprovedQuotes($proposal->invoice_id)->orderBy('id')->get(),
|
||||
'invoicePublicId' => $proposal->invoice ? $proposal->invoice->public_id : null,
|
||||
'templatePublicId' => $proposal->proposal_template ? $proposal->proposal_template->public_id : null,
|
||||
]);
|
||||
@ -96,10 +96,10 @@ class ProposalController extends BaseController
|
||||
return View::make('proposals.edit', $data);
|
||||
}
|
||||
|
||||
private function getViewmodel()
|
||||
private function getViewmodel($proposal = false)
|
||||
{
|
||||
$account = auth()->user()->account;
|
||||
$templates = ProposalTemplate::whereAccountId($account->id)->orderBy('name')->get();
|
||||
$templates = ProposalTemplate::whereAccountId($account->id)->withActiveOrSelected($proposal ? $proposal->proposal_template_id : false)->orderBy('name')->get();
|
||||
|
||||
if (! $templates->count()) {
|
||||
$templates = ProposalTemplate::whereNull('account_id')->orderBy('name')->get();
|
||||
|
@ -84,7 +84,7 @@ class ProposalSnippetController extends BaseController
|
||||
'method' => 'PUT',
|
||||
'url' => 'proposals/snippets/' . $proposalSnippet->public_id,
|
||||
'title' => trans('texts.edit_proposal_snippet'),
|
||||
'categories' => ProposalCategory::scope()->orderBy('name')->get(),
|
||||
'categories' => ProposalCategory::scope()->withActiveOrSelected($proposalSnippet->proposal_category_id)->orderBy('name')->get(),
|
||||
'categoryPublicId' => $proposalSnippet->proposal_category ? $proposalSnippet->proposal_category->public_id : null,
|
||||
'icons' => $this->getIcons(),
|
||||
];
|
||||
|
@ -189,7 +189,7 @@ class TaskController extends BaseController
|
||||
'datetimeFormat' => Auth::user()->account->getMomentDateTimeFormat(),
|
||||
];
|
||||
|
||||
$data = array_merge($data, self::getViewModel());
|
||||
$data = array_merge($data, self::getViewModel($task));
|
||||
|
||||
return View::make('tasks.edit', $data);
|
||||
}
|
||||
@ -211,12 +211,12 @@ class TaskController extends BaseController
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private static function getViewModel()
|
||||
private static function getViewModel($task = false)
|
||||
{
|
||||
return [
|
||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
||||
'clients' => Client::scope()->withActiveOrSelected($task ? $task->client_id : false)->with('contacts')->orderBy('name')->get(),
|
||||
'account' => Auth::user()->account,
|
||||
'projects' => Project::scope()->with('client.contacts')->orderBy('name')->get(),
|
||||
'projects' => Project::scope()->withActiveOrSelected($task ? $task->project_id : false)->with('client.contacts')->orderBy('name')->get(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -182,6 +182,15 @@ class EntityModel extends Eloquent
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function scopeWithActiveOrSelected($query, $id = false)
|
||||
{
|
||||
return $query->withTrashed()
|
||||
->where(function ($query) use ($id) {
|
||||
$query->whereNull('deleted_at')
|
||||
->orWhere('id', '=', $id);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $query
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user