diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 0c3031265a..7219dd2379 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -17,12 +17,15 @@ use App\Events\Invoice\InvoiceWasUpdated; use App\Helpers\Invoice\InvoiceSum; use App\Helpers\Invoice\InvoiceSumInclusive; use App\Jobs\Entity\CreateEntityPdf; +use App\Models\Expense; use App\Models\Presenters\InvoicePresenter; +use App\Models\Task; use App\Services\Invoice\InvoiceService; use App\Services\Ledger\LedgerService; use App\Utils\Ninja; use App\Utils\Traits\Invoice\ActionsInvoice; use App\Utils\Traits\MakesDates; +use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesInvoiceValues; use App\Utils\Traits\MakesReminders; use App\Utils\Traits\NumberFormatter; @@ -562,6 +565,60 @@ class Invoice extends BaseModel ]; } + public function expense_documents() + { + + $line_items = $this->line_items; + + $expense_ids = []; + + foreach($line_items as $item) + { + + if(property_exists($item, 'expense_id')) + { + $expense_ids[] = $item->expense_id; + } + + } + + nlog($line_items); + + return Expense::whereIn('id', $this->transformKeys($expense_ids)) + ->where('invoice_documents', 1) + ->where('company_id', $this->company_id) + ->cursor(); + + } + + public function task_documents() + { + + $line_items = $this->line_items; + + $task_ids = []; + + foreach($line_items as $item) + { + + if(property_exists($item, 'task_id')) + { + $task_ids[] = $item->task_id; + } + + } + + nlog($task_ids); + + return Task::whereIn('id', $this->transformKeys($task_ids)) + ->whereHas('company', function($query){ + $query->where('invoice_task_documents', 1); + }) + ->where('company_id', $this->company_id) + ->cursor(); + + } + public function translate_entity() { return ctrans('texts.invoice'); diff --git a/resources/views/portal/ninja2020/components/entity-documents.blade.php b/resources/views/portal/ninja2020/components/entity-documents.blade.php index 72fda48ec4..efe5e7415d 100644 --- a/resources/views/portal/ninja2020/components/entity-documents.blade.php +++ b/resources/views/portal/ninja2020/components/entity-documents.blade.php @@ -42,45 +42,49 @@ @endforeach - @if($entity->expense && $entity->expense->invoice_documents) - @foreach ($entity->expense->documents as $document) -