mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 17:54:30 -04:00
Option to include expense documents with invoice #1442
This commit is contained in:
parent
81d9e4994c
commit
d1e77f877b
@ -651,7 +651,9 @@ class ClientPortalController extends BaseController
|
||||
$documents = $invoice->documents;
|
||||
|
||||
foreach ($invoice->expenses as $expense) {
|
||||
$documents = $documents->merge($expense->documents);
|
||||
if ($expense->invoice_documents) {
|
||||
$documents = $documents->merge($expense->documents);
|
||||
}
|
||||
}
|
||||
|
||||
$documents = $documents->sortBy('size');
|
||||
@ -740,7 +742,7 @@ class ClientPortalController extends BaseController
|
||||
$document = Document::scope($publicId, $invitation->account_id)->firstOrFail();
|
||||
|
||||
$authorized = false;
|
||||
if ($document->expense && $document->expense->client_id == $invitation->invoice->client_id) {
|
||||
if ($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;
|
||||
|
@ -50,6 +50,7 @@ class Expense extends EntityModel
|
||||
'payment_date',
|
||||
'payment_type_id',
|
||||
'transaction_reference',
|
||||
'invoice_documents',
|
||||
];
|
||||
|
||||
public static function getImportColumns()
|
||||
|
@ -1405,6 +1405,22 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
$taxes[$key]['paid'] += $paid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function countDocuments()
|
||||
{
|
||||
$count = count($this->documents);
|
||||
|
||||
foreach ($this->expenses as $expense) {
|
||||
if ($expense->invoice_documents) {
|
||||
$count += count($expense->documents);
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@ -1423,7 +1439,7 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
public function hasExpenseDocuments()
|
||||
{
|
||||
foreach ($this->expenses as $expense) {
|
||||
if (count($expense->documents)) {
|
||||
if ($expense->invoice_documents && count($expense->documents)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ class AddCustomContactFields extends Migration
|
||||
$table->date('payment_date')->nullable();
|
||||
$table->string('transaction_reference')->nullable();
|
||||
$table->foreign('payment_type_id')->references('id')->on('payment_types');
|
||||
$table->boolean('invoice_documents')->default(true);
|
||||
});
|
||||
|
||||
// remove duplicate annual frequency
|
||||
@ -76,6 +77,7 @@ class AddCustomContactFields extends Migration
|
||||
$table->dropColumn('payment_type_id');
|
||||
$table->dropColumn('payment_date');
|
||||
$table->dropColumn('transaction_reference');
|
||||
$table->dropColumn('invoice_documents');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -2481,7 +2481,7 @@ $LANG = array(
|
||||
'custom_contact_fields_help' => 'Add a field when creating a contact and display the label and value on the PDF.',
|
||||
'datatable_info' => 'Showing :start to :end of :total entries',
|
||||
'credit_total' => 'Credit Total',
|
||||
'mark_billable' => 'Mark Billable',
|
||||
'mark_billable' => 'Mark billable',
|
||||
'billed' => 'Billed',
|
||||
'company_variables' => 'Company Variables',
|
||||
'client_variables' => 'Client Variables',
|
||||
@ -2489,6 +2489,8 @@ $LANG = array(
|
||||
'navigation_variables' => 'Navigation Variables',
|
||||
'custom_variables' => 'Custom Variables',
|
||||
'invalid_file' => 'Invalid file type',
|
||||
'add_documents_to_invoice' => 'Add documents to invoice',
|
||||
'mark_expense_paid' => 'Mark paid',
|
||||
|
||||
);
|
||||
|
||||
|
@ -89,7 +89,7 @@
|
||||
@if (! $expense || ! $expense->isPaid())
|
||||
{!! Former::checkbox('mark_paid')
|
||||
->data_bind('checked: mark_paid')
|
||||
->text(trans('texts.mark_paid'))
|
||||
->text(trans('texts.mark_expense_paid'))
|
||||
->label(' ')
|
||||
->value(1) !!}
|
||||
@endif
|
||||
@ -181,6 +181,15 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($account->hasFeature(FEATURE_DOCUMENTS))
|
||||
{!! Former::checkbox('invoice_documents')
|
||||
->text(trans('texts.add_documents_to_invoice'))
|
||||
->onchange('onInvoiceDocumentsChange()')
|
||||
->data_bind('checked: invoice_documents')
|
||||
->label(' ')
|
||||
->value(1) !!}
|
||||
@endif
|
||||
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
|
||||
@ -452,6 +461,12 @@
|
||||
self.convert_currency = ko.observable({{ ($expense && $expense->isExchanged()) ? 'true' : 'false' }});
|
||||
self.apply_taxes = ko.observable({{ ($expense && ($expense->tax_name1 || $expense->tax_name2)) ? 'true' : 'false' }});
|
||||
|
||||
var invoiceDocuments = false;
|
||||
if (isStorageSupported()) {
|
||||
invoiceDocuments = localStorage.getItem('last:invoice_documents');
|
||||
}
|
||||
self.invoice_documents = ko.observable({{ $expense ? $expense->invoice_documents : 'invoiceDocuments' }});
|
||||
|
||||
self.mapping = {
|
||||
'documents': {
|
||||
create: function(options) {
|
||||
@ -611,6 +626,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
function onInvoiceDocumentsChange()
|
||||
{
|
||||
if (isStorageSupported()) {
|
||||
var checked = $('#invoice_documents').is(':checked');
|
||||
localStorage.setItem('last:invoice_documents', checked || '');
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@stop
|
||||
|
@ -346,8 +346,8 @@
|
||||
@if ($account->hasFeature(FEATURE_DOCUMENTS))
|
||||
<li role="presentation"><a href="#attached-documents" aria-controls="attached-documents" role="tab" data-toggle="tab">
|
||||
{{ trans("texts.invoice_documents") }}
|
||||
@if (count($invoice->documents))
|
||||
({{ count($invoice->documents) }})
|
||||
@if ($count = $invoice->countDocuments())
|
||||
({{ $count }})
|
||||
@endif
|
||||
</a></li>
|
||||
@endif
|
||||
@ -393,9 +393,11 @@
|
||||
@if ($invoice->hasExpenseDocuments())
|
||||
<h4>{{trans('texts.documents_from_expenses')}}</h4>
|
||||
@foreach($invoice->expenses as $expense)
|
||||
@foreach($expense->documents as $document)
|
||||
<div>{{$document->name}}</div>
|
||||
@endforeach
|
||||
@if ($expense->invoice_documents)
|
||||
@foreach($expense->documents as $document)
|
||||
<div>{{$document->name}}</div>
|
||||
@endforeach
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
|
@ -151,7 +151,9 @@
|
||||
@endforeach
|
||||
@foreach ($invoice->expenses as $expense)
|
||||
@foreach ($expense->documents as $document)
|
||||
<li><a target="_blank" href="{{ $document->getClientUrl($invitation) }}">{{$document->name}} ({{Form::human_filesize($document->size)}})</a></li>
|
||||
@if ($expense->invoice_documents)
|
||||
<li><a target="_blank" href="{{ $document->getClientUrl($invitation) }}">{{$document->name}} ({{Form::human_filesize($document->size)}})</a></li>
|
||||
@endif
|
||||
@endforeach
|
||||
@endforeach
|
||||
</ul>
|
||||
|
Loading…
x
Reference in New Issue
Block a user