mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fix for archived relationships
This commit is contained in:
parent
bb8c2f80f6
commit
31037d44d9
@ -82,9 +82,7 @@ class ExpenseController extends BaseController
|
|||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'url' => 'expenses',
|
'url' => 'expenses',
|
||||||
'title' => trans('texts.new_expense'),
|
'title' => trans('texts.new_expense'),
|
||||||
'vendors' => Vendor::scope()->with('vendor_contacts')->orderBy('name')->get(),
|
|
||||||
'vendor' => $vendor,
|
'vendor' => $vendor,
|
||||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
|
||||||
'clientPublicId' => $request->client_id,
|
'clientPublicId' => $request->client_id,
|
||||||
'categoryPublicId' => $request->category_id,
|
'categoryPublicId' => $request->category_id,
|
||||||
];
|
];
|
||||||
@ -160,14 +158,12 @@ class ExpenseController extends BaseController
|
|||||||
'url' => $url,
|
'url' => $url,
|
||||||
'title' => 'Edit Expense',
|
'title' => 'Edit Expense',
|
||||||
'actions' => $actions,
|
'actions' => $actions,
|
||||||
'vendors' => Vendor::scope()->with('vendor_contacts')->orderBy('name')->get(),
|
|
||||||
'vendorPublicId' => $expense->vendor ? $expense->vendor->public_id : null,
|
'vendorPublicId' => $expense->vendor ? $expense->vendor->public_id : null,
|
||||||
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
|
|
||||||
'clientPublicId' => $expense->client ? $expense->client->public_id : null,
|
'clientPublicId' => $expense->client ? $expense->client->public_id : null,
|
||||||
'categoryPublicId' => $expense->expense_category ? $expense->expense_category->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);
|
return View::make('expenses.edit', $data);
|
||||||
}
|
}
|
||||||
@ -287,12 +283,14 @@ class ExpenseController extends BaseController
|
|||||||
return $this->returnBulk($this->entityType, $action, $ids);
|
return $this->returnBulk($this->entityType, $action, $ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getViewModel()
|
private static function getViewModel($expense = false)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'data' => Input::old('data'),
|
'data' => Input::old('data'),
|
||||||
'account' => Auth::user()->account,
|
'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(),
|
'taxRates' => TaxRate::scope()->whereIsInclusive(false)->orderBy('name')->get(),
|
||||||
'isRecurring' => false,
|
'isRecurring' => false,
|
||||||
];
|
];
|
||||||
|
@ -82,13 +82,13 @@ class ProposalController extends BaseController
|
|||||||
{
|
{
|
||||||
$proposal = $request->entity();
|
$proposal = $request->entity();
|
||||||
|
|
||||||
$data = array_merge($this->getViewmodel(), [
|
$data = array_merge($this->getViewmodel($proposal), [
|
||||||
'proposal' => $proposal,
|
'proposal' => $proposal,
|
||||||
'entity' => $proposal,
|
'entity' => $proposal,
|
||||||
'method' => 'PUT',
|
'method' => 'PUT',
|
||||||
'url' => 'proposals/' . $proposal->public_id,
|
'url' => 'proposals/' . $proposal->public_id,
|
||||||
'title' => trans('texts.edit_proposal'),
|
'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,
|
'invoicePublicId' => $proposal->invoice ? $proposal->invoice->public_id : null,
|
||||||
'templatePublicId' => $proposal->proposal_template ? $proposal->proposal_template->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);
|
return View::make('proposals.edit', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getViewmodel()
|
private function getViewmodel($proposal = false)
|
||||||
{
|
{
|
||||||
$account = auth()->user()->account;
|
$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()) {
|
if (! $templates->count()) {
|
||||||
$templates = ProposalTemplate::whereNull('account_id')->orderBy('name')->get();
|
$templates = ProposalTemplate::whereNull('account_id')->orderBy('name')->get();
|
||||||
|
@ -84,7 +84,7 @@ class ProposalSnippetController extends BaseController
|
|||||||
'method' => 'PUT',
|
'method' => 'PUT',
|
||||||
'url' => 'proposals/snippets/' . $proposalSnippet->public_id,
|
'url' => 'proposals/snippets/' . $proposalSnippet->public_id,
|
||||||
'title' => trans('texts.edit_proposal_snippet'),
|
'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,
|
'categoryPublicId' => $proposalSnippet->proposal_category ? $proposalSnippet->proposal_category->public_id : null,
|
||||||
'icons' => $this->getIcons(),
|
'icons' => $this->getIcons(),
|
||||||
];
|
];
|
||||||
|
@ -189,7 +189,7 @@ class TaskController extends BaseController
|
|||||||
'datetimeFormat' => Auth::user()->account->getMomentDateTimeFormat(),
|
'datetimeFormat' => Auth::user()->account->getMomentDateTimeFormat(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$data = array_merge($data, self::getViewModel());
|
$data = array_merge($data, self::getViewModel($task));
|
||||||
|
|
||||||
return View::make('tasks.edit', $data);
|
return View::make('tasks.edit', $data);
|
||||||
}
|
}
|
||||||
@ -211,12 +211,12 @@ class TaskController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private static function getViewModel()
|
private static function getViewModel($task = false)
|
||||||
{
|
{
|
||||||
return [
|
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,
|
'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;
|
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
|
* @param $query
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user