2020-06-22 00:34:02 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-06-22 00:34:02 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-06-22 00:34:02 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-06-22 00:34:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2024-07-19 02:51:52 +02:00
|
|
|
use App\Utils\Ninja;
|
2021-06-03 00:02:30 +02:00
|
|
|
use App\Models\Design;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
2020-06-22 00:34:02 +02:00
|
|
|
/**
|
2020-11-03 14:27:41 +01:00
|
|
|
* Class for DesignRepository .
|
2020-06-22 00:34:02 +02:00
|
|
|
*/
|
|
|
|
class DesignRepository extends BaseRepository
|
|
|
|
{
|
2024-01-14 05:05:00 +01:00
|
|
|
public function delete($design): Design
|
2021-06-03 00:02:30 +02:00
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
$design->name = $design->name.'_deleted_'.Str::random(5);
|
2021-06-03 00:02:30 +02:00
|
|
|
|
2023-04-29 13:01:02 +02:00
|
|
|
/** Make sure this design was not a default design - if it is, set the Clean template as the default */
|
|
|
|
|
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$company = $user->company();
|
|
|
|
$settings = $company->settings;
|
|
|
|
|
|
|
|
if ($settings->invoice_design_id == $design->hashed_id) {
|
|
|
|
$settings->invoice_design_id = 'Wpmbk5ezJn';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($settings->quote_design_id == $design->hashed_id) {
|
|
|
|
$settings->quote_design_id = 'Wpmbk5ezJn';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($settings->credit_design_id == $design->hashed_id) {
|
|
|
|
$settings->credit_design_id = 'Wpmbk5ezJn';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($settings->purchase_order_design_id == $design->hashed_id) {
|
|
|
|
$settings->purchase_order_design_id = 'Wpmbk5ezJn';
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-04-29 13:01:02 +02:00
|
|
|
$company->settings = $settings;
|
|
|
|
$company->save();
|
|
|
|
|
2021-06-03 00:02:30 +02:00
|
|
|
parent::delete($design);
|
|
|
|
|
|
|
|
return $design;
|
|
|
|
}
|
2024-07-19 02:51:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $entity
|
|
|
|
*/
|
|
|
|
public function restore($design)
|
|
|
|
{
|
|
|
|
|
|
|
|
$design->name = str_ireplace("_deleted_", "_restored_", $design->name);
|
|
|
|
|
|
|
|
parent::restore($design);
|
2024-08-22 08:45:06 +02:00
|
|
|
|
2024-07-19 02:51:52 +02:00
|
|
|
return $design;
|
2024-08-22 08:45:06 +02:00
|
|
|
|
2024-07-19 02:51:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-22 00:34:02 +02:00
|
|
|
}
|