1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-18 00:53:10 +01:00
invoiceninja/app/Services/Credit/GetCreditPdf.php

58 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2020-07-01 03:06:40 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2020-07-01 03:06:40 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-07-01 03:06:40 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Credit;
2020-10-26 05:06:58 +01:00
use App\Jobs\Entity\CreateEntityPdf;
use App\Services\AbstractService;
2021-04-06 14:36:50 +02:00
use App\Utils\TempFile;
use Illuminate\Support\Facades\Storage;
class GetCreditPdf extends AbstractService
{
2020-11-11 01:13:39 +01:00
public $credit;
2020-02-18 21:56:21 +01:00
2020-11-11 01:13:39 +01:00
public $contact;
2020-02-18 21:56:21 +01:00
2020-11-11 01:13:39 +01:00
public $invitation;
public function __construct($invitation)
{
2020-11-11 01:13:39 +01:00
$this->invitation = $invitation;
$this->credit = $invitation->credit;
$this->contact = $invitation->contact;
}
2020-02-18 21:56:21 +01:00
public function run()
{
if (! $this->contact) {
2020-02-18 21:56:21 +01:00
$this->contact = $this->credit->client->primary_contact()->first();
}
$path = $this->credit->client->credit_filepath();
$file_path = $path.$this->credit->numberFormatter().'.pdf';
$disk = config('filesystems.default');
$file = Storage::disk($disk)->exists($file_path);
if (! $file) {
2020-11-11 01:13:39 +01:00
$file_path = CreateEntityPdf::dispatchNow($this->invitation);
}
2021-04-06 14:36:50 +02:00
if(config('filesystems.default') == 's3')
return TempFile::path(Storage::disk($disk)->url($file_path));
return Storage::disk($disk)->path($file_path);
}
}