1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Utils/Traits/SavesDocuments.php

80 lines
2.0 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
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)
{
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;
}
2023-02-16 02:36:09 +01:00
if (!is_array($document_array)) {
2022-09-06 09:36:56 +02:00
return;
2023-02-16 02:36:09 +01:00
}
2022-09-06 09:36:56 +02:00
foreach ($document_array as $document) {
$document = (new UploadFile(
$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
))->handle();
}
}
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 = (new UploadFile(
2020-11-24 11:12:05 +01:00
$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
))->handle();
2020-11-24 11:12:05 +01:00
}
}