refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s

This commit is contained in:
Kroonk
2026-05-22 16:19:55 +02:00
parent 38cc4c09ca
commit a213a1dba0
2215 changed files with 242567 additions and 6015 deletions

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Services\Account\Company;
use App\Models\User\User;
use App\Services\BaseService;
use function Safe\json_encode;
use App\Models\Account\Company;
use Safe\Exceptions\JsonException;
use App\Jobs\AuditLog\LogAccountAudit;
class CreateCompany extends BaseService
{
/**
* Get the validation rules that apply to the service.
*
* @return array
*/
public function rules()
{
return [
'account_id' => 'required|integer|exists:accounts,id',
'author_id' => 'required|integer|exists:users,id',
'name' => 'required|string|max:255',
'website' => 'nullable|string|max:255',
'number_of_employees' => 'nullable|integer',
];
}
/**
* Create a company.
*
* @param array $data
* @return Company
*/
public function execute(array $data): Company
{
$this->validate($data);
$this->log($data);
return Company::create([
'account_id' => $data['account_id'],
'name' => $data['name'],
'website' => $this->nullOrValue($data, 'website'),
'number_of_employees' => $this->nullOrValue($data, 'number_of_employees'),
]);
}
/**
* Add an audit log.
*
* @param array $data
* @return void
*
* @throws JsonException
*/
private function log(array $data): void
{
$author = User::find($data['author_id']);
LogAccountAudit::dispatch([
'action' => 'company_created',
'account_id' => $data['account_id'],
'about_contact_id' => null,
'author_id' => $author->id,
'author_name' => $author->name,
'audited_at' => now(),
'should_appear_on_dashboard' => true,
'objects' => json_encode([
'name' => $data['name'],
]),
]);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Services\Account\Company;
use App\Services\BaseService;
use App\Models\Account\Company;
class DestroyCompany extends BaseService
{
/**
* Get the validation rules that apply to the service.
*
* @return array
*/
public function rules()
{
return [
'account_id' => 'required|integer|exists:accounts,id',
'company_id' => 'required|integer|exists:companies,id',
];
}
/**
* Destroy a company.
*
* @param array $data
* @return bool
*/
public function execute(array $data): bool
{
$this->validate($data);
$company = Company::where('account_id', $data['account_id'])
->findOrFail($data['company_id']);
$company->delete();
return true;
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Services\Account\Company;
use App\Services\BaseService;
use App\Models\Account\Company;
class UpdateCompany extends BaseService
{
/**
* Get the validation rules that apply to the service.
*
* @return array
*/
public function rules()
{
return [
'account_id' => 'required|integer|exists:accounts,id',
'company_id' => 'required|integer|exists:companies,id',
'name' => 'required|string|max:255',
'website' => 'nullable|string|max:255',
'number_of_employees' => 'nullable|integer',
];
}
/**
* Update a company.
*
* @param array $data
* @return Company
*/
public function execute(array $data): Company
{
$this->validate($data);
/** @var Company */
$company = Company::where('account_id', $data['account_id'])
->findOrFail($data['company_id']);
$company->update([
'name' => $data['name'],
'website' => $this->nullOrValue($data, 'website'),
'number_of_employees' => $this->nullOrValue($data, 'number_of_employees'),
]);
return $company;
}
}