invoiceninja/app/Services/Invoice/GetInvoicePdf.php
David Bomba be3ade65f1
Download Invoice by Invitation (#3312)
* style cs

* Style CS

* Throw Record not found exception if invalid primary key hash is provided

* Improve error handling

* Create abstract implementation for designs

* working on custom designs

* Add Design Model

* invoice services

* Download Invoice by Invitation
2020-02-12 11:41:17 +11:00

53 lines
1005 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 __construct()
{
}
public function __invoke($invoice, $contact = null)
{
$path = $invoice->client->client_hash . '/invoices/';
$file_path = $path . $invoice->number . '.pdf';
$disk = config('filesystems.default');
$file = Storage::disk($disk)->exists($file_path);
if(!$contact)
$contact = $invoice->client->primary_contact()->first();
if(!$file)
{
$file_path = CreateInvoicePdf::dispatchNow($invoice, $invoice->company, $contact);
}
//return $file_path;
return Storage::disk($disk)->path($file_path);
}
}