1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Services/Credit/GetCreditPdf.php
David Bomba 43e57d0117
Fixes for self-update (#3514)
* minor fix for payment notifications

* styleci

* Limit Self updating to self hosters only
:

* Fixes for designs

* Minor fixes for self-update
2020-03-21 16:37:30 +11:00

45 lines
1.1 KiB
PHP

<?php
namespace App\Services\Credit;
use App\Jobs\Credit\CreateCreditPdf;
use App\Jobs\Invoice\CreateInvoicePdf;
use App\Models\ClientContact;
use App\Models\Credit;
use App\Services\AbstractService;
use Illuminate\Support\Facades\Storage;
class GetCreditPdf extends AbstractService
{
private $credit;
private $contact;
public function __construct(Credit $credit, ClientContact $contact = null)
{
$this->credit = $credit;
$this->contact = $contact;
}
public function run()
{
if (!$this->contact) {
$this->contact = $this->credit->client->primary_contact()->first();
}
$path = $this->credit->client->credit_filepath();
$file_path = $path . $this->credit->number . '.pdf';
$disk = config('filesystems.default');
$file = Storage::disk($disk)->exists($file_path);
if (!$file) {
$file_path = CreateCreditPdf::dispatchNow($this->credit, $this->credit->company, $this->contact);
}
return Storage::disk($disk)->path($file_path);
}
}