2020-02-12 01:41:17 +01:00
|
|
|
<?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)
|
|
|
|
{
|
|
|
|
|
2020-02-12 10:18:56 +01:00
|
|
|
if(!$contact)
|
|
|
|
$contact = $invoice->client->primary_contact()->first();
|
|
|
|
|
2020-02-12 01:41:17 +01:00
|
|
|
$path = $invoice->client->client_hash . '/invoices/';
|
|
|
|
|
2020-02-12 10:18:56 +01:00
|
|
|
$file_path = $path . $invoice->number . '-' . $contact->contact_key . '.pdf';
|
2020-02-12 01:41:17 +01:00
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|