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