2020-04-10 07:07:36 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-04-10 07:07:36 +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-04-10 07:07:36 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils\Traits;
|
|
|
|
|
|
|
|
use App\Jobs\Util\UploadFile;
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Company;
|
|
|
|
|
|
|
|
trait SavesDocuments
|
|
|
|
{
|
2020-11-09 11:17:20 +01:00
|
|
|
public function saveDocuments($document_array, $entity, $is_public = true)
|
2020-04-10 07:07:36 +02:00
|
|
|
{
|
2020-04-15 02:30:52 +02:00
|
|
|
if ($entity instanceof Company) {
|
|
|
|
$account = $entity->account;
|
|
|
|
$company = $entity;
|
2021-01-13 11:18:39 +01:00
|
|
|
$user = auth()->user();
|
2020-04-15 02:30:52 +02:00
|
|
|
} else {
|
|
|
|
$account = $entity->company->account;
|
|
|
|
$company = $entity->company;
|
2021-01-13 11:18:39 +01:00
|
|
|
$user = $entity->user;
|
2020-04-15 02:30:52 +02:00
|
|
|
}
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $account->hasFeature(Account::FEATURE_DOCUMENTS)) {
|
2020-04-15 02:30:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($document_array as $document) {
|
|
|
|
$document = UploadFile::dispatchNow(
|
|
|
|
$document,
|
|
|
|
UploadFile::DOCUMENT,
|
2021-01-13 11:18:39 +01:00
|
|
|
$user,
|
|
|
|
$company,
|
2020-08-18 16:12:46 +02:00
|
|
|
$entity,
|
|
|
|
null,
|
|
|
|
$is_public
|
2020-04-15 02:30:52 +02:00
|
|
|
);
|
|
|
|
}
|
2020-04-10 07:07:36 +02:00
|
|
|
}
|
2020-11-24 11:12:05 +01:00
|
|
|
|
|
|
|
public function saveDocument($document, $entity, $is_public = true)
|
|
|
|
{
|
|
|
|
if ($entity instanceof Company) {
|
|
|
|
$account = $entity->account;
|
|
|
|
$company = $entity;
|
2021-01-13 11:18:39 +01:00
|
|
|
$user = auth()->user();
|
2020-11-24 11:12:05 +01:00
|
|
|
} else {
|
|
|
|
$account = $entity->company->account;
|
|
|
|
$company = $entity->company;
|
2021-01-13 11:18:39 +01:00
|
|
|
$user = $entity->user;
|
2020-11-24 11:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $account->hasFeature(Account::FEATURE_DOCUMENTS)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$document = UploadFile::dispatchNow(
|
|
|
|
$document,
|
|
|
|
UploadFile::DOCUMENT,
|
2021-01-13 11:18:39 +01:00
|
|
|
$user,
|
|
|
|
$company,
|
2020-11-24 11:12:05 +01:00
|
|
|
$entity,
|
|
|
|
null,
|
|
|
|
$is_public
|
|
|
|
);
|
|
|
|
}
|
2020-04-10 07:07:36 +02:00
|
|
|
}
|