1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-18 09:04:35 +01:00
invoiceninja/app/Utils/Traits/SavesDocuments.php

77 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @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)
{
2021-03-16 22:15:43 +01:00
if ($entity instanceof Company) {
$account = $entity->account;
$company = $entity;
2021-01-13 11:18:39 +01:00
$user = auth()->user();
} else {
$account = $entity->company->account;
$company = $entity->company;
2021-01-13 11:18:39 +01:00
$user = $entity->user;
}
if (! $account->hasFeature(Account::FEATURE_DOCUMENTS)) {
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-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
);
}
}