mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-06 03:02:34 +01:00
6a7079b0be
* Update phpunit.yml * Update phpunit.yml * Update .env.ci * Update phpunit.yml * Update .env.ci * Update phpunit.yml * Update phpunit.yml * Update phpunit.yml * Update phpunit.yml * Update .env.ci * Update phpunit.yml * Update phpunit.yml * Update phpunit.yml * Update phpunit.yml * Force /setup if system requirements are not met * Update .env.ci * Update phpunit.yml * Minor changes for github actions" * Fixes for github actions * Fixes for github actions * Fixes for github actions * Fixes for github actions * Fixes for github actions * Fixes for github actions * Fixes for github actions * Fixes for github actions * cs-fixer * cs-fixer * Fixes for github actions * db ports github actions * Refactor the template engine
85 lines
2.4 KiB
PHP
85 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://opensource.org/licenses/AAL
|
|
*/
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\Activity;
|
|
use App\Models\Backup;
|
|
use App\Models\Client;
|
|
use App\Models\Invoice;
|
|
use App\Models\User;
|
|
use App\Utils\Traits\MakesInvoiceHtml;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
/**
|
|
* Class for activity repository.
|
|
*/
|
|
class ActivityRepository extends BaseRepository
|
|
{
|
|
use MakesInvoiceHtml;
|
|
/**
|
|
* Save the Activity
|
|
*
|
|
* @param stdClass $fields The fields
|
|
* @param Collection $entity The entity that you wish to have backed up (typically Invoice, Quote etc etc rather than Payment)
|
|
*/
|
|
public function save($fields, $entity)
|
|
{
|
|
$activity = new Activity();
|
|
|
|
$activity->is_system = app()->runningInConsole();
|
|
$activity->ip = request()->getClientIp();
|
|
|
|
foreach ($fields as $key => $value) {
|
|
$activity->{$key} = $value;
|
|
}
|
|
|
|
$activity->save();
|
|
|
|
$this->createBackup($entity, $activity);
|
|
}
|
|
|
|
/**
|
|
* Creates a backup.
|
|
*
|
|
* @param Collection $entity The entity
|
|
* @param Collection $activity The activity
|
|
*/
|
|
public function createBackup($entity, $activity)
|
|
{
|
|
$backup = new Backup();
|
|
|
|
// if(get_class($entity) == Client::class)
|
|
// $settings = $entity->getMergedSettings();
|
|
// else
|
|
// $settings = $entity->client->getMergedSettings();
|
|
// $entity->clientMergedDettings = $settings;
|
|
|
|
if (get_class($entity) == Client::class) {
|
|
$entity->load('company');
|
|
} elseif (get_class($entity) == User::class) {
|
|
} else {
|
|
$entity->load('company', 'client');
|
|
}
|
|
|
|
|
|
if (get_class($entity) == Invoice::class && ($activity->activity_type_id == Activity::MARK_SENT_INVOICE || $activity->activity_type_id == Activity::PAID_INVOICE)) {
|
|
//$backup->html_backup = $this->generateInvoiceHtml($entity->design(), $entity);
|
|
$backup->html_backup = $this->generateEntityHtml($entity->getEntityDesigner(), $entity);
|
|
}
|
|
|
|
|
|
$backup->activity_id = $activity->id;
|
|
$backup->json_backup = $entity->toJson();
|
|
$backup->save();
|
|
}
|
|
}
|