invoiceninja/app/Services/Invoice/GetInvoicePdf.php
Benjamin Beganović 7dd6f814ac
Change 'Quote' & 'Invoice' service implementation (#3327)
* Change '__invoke' to 'run' for Invoice services

*  Change '__invoke' to 'run' for Quote services
2020-02-14 14:32:22 +11:00

49 lines
951 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 run($invoice, $contact = null)
{
if(!$contact)
$contact = $invoice->client->primary_contact()->first();
$path = $invoice->client->client_hash . '/invoices/';
$file_path = $path . $invoice->number . '.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);
}
}