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;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Models\ClientContact;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Services\AbstractService;
|
2020-02-12 01:41:17 +01:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
class GetInvoicePdf extends AbstractService
|
2020-02-12 01:41:17 +01:00
|
|
|
{
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
public function __construct(Invoice $invoice, ClientContact $contact = null)
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->invoice = $invoice;
|
|
|
|
|
|
|
|
$this->contact = $contact;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run()
|
2020-02-12 01:41:17 +01:00
|
|
|
{
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
if(!$this->contact)
|
|
|
|
$this->contact = $this->invoice->client->primary_contact()->first();
|
2020-02-12 10:18:56 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$path = $this->invoice->client->invoice_filepath();
|
2020-02-12 01:41:17 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$file_path = $path . $this->invoice->number . '.pdf';
|
2020-02-12 01:41:17 +01:00
|
|
|
|
|
|
|
$disk = config('filesystems.default');
|
|
|
|
|
|
|
|
$file = Storage::disk($disk)->exists($file_path);
|
|
|
|
|
|
|
|
if(!$file)
|
|
|
|
{
|
2020-02-14 04:32:22 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$file_path = CreateInvoicePdf::dispatchNow($this->invoice, $this->invoice->company, $this->contact);
|
2020-02-12 01:41:17 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//return $file_path;
|
|
|
|
|
|
|
|
return Storage::disk($disk)->path($file_path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|