d2d.emegrendeles.hu/app/Services/SupplierService.php
2026-04-26 05:37:07 +02:00

108 lines
3.3 KiB
PHP

<?php
namespace App\Services;
use App\Repositories\SupplierRepositoryInterface;
class SupplierService extends ServiceBase
{
public function __construct(SupplierRepositoryInterface $Repository)
{
parent::__construct();
$this->Repository = $Repository;
// $this->setRelation('contact','productGroup');
}
public function addProductGroup($supplierId, $productGroupIds = []): bool
{
return $this->Repository->addProductGroup($supplierId, $productGroupIds);
}
public function addContact($supplierId, $contactIds = []): bool
{
return $this->Repository->addContact($supplierId, $contactIds);
}
public function removeContact($supplierId, $contactIds = []): bool
{
return $this->Repository->removeContact($supplierId, $contactIds);
}
public function removeProductGroup($supplierId, $productGroupIds = []): bool
{
return $this->Repository->removeProductGroup($supplierId, $productGroupIds);
}
public function syncContact($supplierId, $contactIds = []): bool
{
return $this->Repository->syncContact($supplierId, $contactIds);
}
public function syncProductGroup($supplierId, $productGroupIds = []): bool
{
return $this->Repository->syncProductGroup($supplierId, $productGroupIds);
}
public function syncService($supplierId, $serviceId = []): bool
{
return $this->Repository->syncService($supplierId, $serviceId);
}
public function syncProfitCenter($supplierId, $profitCenterIds = []): bool
{
return $this->Repository->syncProfitCenter($supplierId, $profitCenterIds);
}
public function syncUsers($supplierId, $userIds = []): bool
{
return $this->Repository->syncUsers($supplierId, $userIds);
}
public function add($data): ?int
{
$contactIds = $data['contactId'];
$productGroupId = $data['productGroupId'];
$serviceId = $data['serviceId'];
$profitCenterId = $data['profitCenterId'];
$userIds = $data['userId'] ?? [];
unset($data['contactId'], $data['productGroupId'], $data['userId']);
if (! $supplierId = parent::add($data)) {
return false;
}
$this->addContact($supplierId, $contactIds);
$this->addProductGroup($supplierId, $productGroupId);
$this->syncService($supplierId, $serviceId);
$this->syncProfitCenter($supplierId, $profitCenterId);
$this->syncUsers($supplierId, $userIds);
return $supplierId;
}
/**
* Updates a post.
*
* @param int
* @param array
*/
public function update($id, array $data): bool
{
$contactIds = $data['contactId'];
$productGroupId = $data['productGroupId'];
$serviceId = $data['serviceId'];
$profitCenterId = $data['profitCenterId'];
$userIds = $data['userId'] ?? [];
unset($data['contactId'], $data['productGroupId'], $data['userId']);
if ($this->Repository->update($id, $data)) {
$this->syncContact($id, $contactIds);
$this->syncProductGroup($id, $productGroupId);
$this->syncService($id, $serviceId);
$this->syncProfitCenter($id, $profitCenterId);
$this->syncUsers($id, $userIds);
return true;
}
return false;
}
}