1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Services/Invoice/GetInvoicePdf.php
David Bomba 162580bcd3
Fixes for ClientContact CRUD (#3317)
* Fixes for downloading invoice PDF

* Fixes for client contact CRUD
2020-02-12 20:18:56 +11:00

49 lines
988 B
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Invoice;
use App\Jobs\Invoice\CreateInvoicePdf;
use Illuminate\Support\Facades\Storage;
class GetInvoicePdf
{
public function __invoke($invoice, $contact = null)
{
if(!$contact)
$contact = $invoice->client->primary_contact()->first();
$path = $invoice->client->client_hash . '/invoices/';
$file_path = $path . $invoice->number . '-' . $contact->contact_key . '.pdf';
$disk = config('filesystems.default');
$file = Storage::disk($disk)->exists($file_path);
if(!$file)
{
$file_path = CreateInvoicePdf::dispatchNow($invoice, $invoice->company, $contact);
}
//return $file_path;
return Storage::disk($disk)->path($file_path);
}
}