1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Default documents

This commit is contained in:
Hillel Coren 2017-07-21 14:01:48 +03:00
parent 48dbf0f287
commit e0c080947b
5 changed files with 23 additions and 25 deletions

View File

@ -745,7 +745,9 @@ class ClientPortalController extends BaseController
$document = Document::scope($publicId, $invitation->account_id)->firstOrFail();
$authorized = false;
if ($document->expense && $document->expense->invoice_documents && $document->expense->client_id == $invitation->invoice->client_id) {
if ($document->is_default) {
$authorized = true;
} elseif ($document->expense && $document->expense->invoice_documents && $document->expense->client_id == $invitation->invoice->client_id) {
$authorized = true;
} elseif ($document->invoice && $document->invoice->client_id == $invitation->invoice->client_id) {
$authorized = true;

View File

@ -305,6 +305,23 @@ class Invoice extends EntityModel implements BalanceAffecting
return $this->hasMany('App\Models\Document')->orderBy('id');
}
/**
* @return mixed
*/
public function allDocuments()
{
$documents = $this->documents;
$documents = $documents->merge($this->account->defaultDocuments);
foreach ($this->expenses as $expense) {
if ($expense->invoice_documents) {
$documents = $documents->merge($expense->documents);
}
}
return $documents;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/

View File

@ -68,14 +68,7 @@ class ContactMailer extends Mailer
$documentStrings = [];
if ($account->document_email_attachment && $invoice->hasDocuments()) {
$documents = $invoice->documents;
foreach ($invoice->expenses as $expense) {
if ($expense->invoice_documents) {
$documents = $documents->merge($expense->documents);
}
}
$documents = $invoice->allDocuments();
$documents = $documents->sortBy('size');
$size = 0;

View File

@ -34,16 +34,9 @@ class TemplateService
if ($account->hasFeature(FEATURE_DOCUMENTS) && $invoice->hasDocuments()) {
$documentsHTML .= trans('texts.email_documents_header').'<ul>';
foreach ($invoice->documents as $document) {
foreach ($invoice->allDocuments() as $document) {
$documentsHTML .= '<li><a href="'.HTML::entities($document->getClientUrl($invitation)).'">'.HTML::entities($document->name).'</a></li>';
}
foreach ($invoice->expenses as $expense) {
if ($expense->invoice_documents) {
foreach ($expense->documents as $document) {
$documentsHTML .= '<li><a href="'.HTML::entities($document->getClientUrl($invitation)).'">'.HTML::entities($document->name).'</a></li>';
}
}
}
$documentsHTML .= '</ul>';
}

View File

@ -151,16 +151,9 @@
<div class="invoice-documents">
<h3>{{ trans('texts.documents_header') }}</h3>
<ul>
@foreach ($invoice->documents as $document)
@foreach ($invoice->allDocuments() as $document)
<li><a target="_blank" href="{{ $document->getClientUrl($invitation) }}">{{$document->name}} ({{Form::human_filesize($document->size)}})</a></li>
@endforeach
@foreach ($invoice->expenses as $expense)
@if ($expense->invoice_documents)
@foreach ($expense->documents as $document)
<li><a target="_blank" href="{{ $document->getClientUrl($invitation) }}">{{$document->name}} ({{Form::human_filesize($document->size)}})</a></li>
@endforeach
@endif
@endforeach
</ul>
</div>
@endif