update for Moadian plugin

This commit is contained in:
Gloomy 2025-08-19 13:50:11 +00:00
parent ac49a0229e
commit e775de8f77

View file

@ -7,6 +7,8 @@
namespace App\Controller\Plugins; namespace App\Controller\Plugins;
use App\Entity\Business;
use App\Entity\Permission;
use App\Service\Access; use App\Service\Access;
use App\Service\Extractor; use App\Service\Extractor;
use App\Service\Log; use App\Service\Log;
@ -42,16 +44,41 @@ class TaxSettingsController extends AbstractController
$businessId = is_object($acc['bid']) ? $acc['bid']->getId() : $acc['bid']; $businessId = is_object($acc['bid']) ? $acc['bid']->getId() : $acc['bid'];
$user = $this->getUser(); $user = $this->getUser();
$userId = $user instanceof \App\Entity\User ? $user->getId() : null;
$perm = $em->getRepository(Permission::class)->findOneBy([
'bid' => $businessId,
'user' => $user
]);
$business = $em->getRepository(Business::class)->find($businessId);
if ($business->getOwner() == $user) {
$repo = $em->getRepository(PluginTaxsettingsKey::class); $repo = $em->getRepository(PluginTaxsettingsKey::class);
$entity = $repo->findOneBy(['business_id' => $businessId, 'user_id' => $userId]); $entity = $repo->findOneBy(['business_id' => $businessId]);
$settings = [ $settings = [
'taxMemoryId' => $entity ? $entity->getTaxMemoryId() : '', 'taxMemoryId' => $entity ? $entity->getTaxMemoryId() : '',
'economicCode' => $entity ? $entity->getEconomicCode() : '', 'economicCode' => $entity ? $entity->getEconomicCode() : '',
'privateKey' => $entity ? $entity->getPrivateKey() : '', 'privateKey' => $entity ? $entity->getPrivateKey() : '',
]; ];
} else {
if (!$perm || !$perm->isPlugTaxSettings()) {
return $this->json([
'success' => false,
'message' => 'شما دسترسی لازم را ندارید.'
]);
}
$repo = $em->getRepository(PluginTaxsettingsKey::class);
$entity = $repo->findOneBy(['business_id' => $businessId]);
$settings = [
'taxMemoryId' => $entity ? $entity->getTaxMemoryId() : '',
'economicCode' => $entity ? $entity->getEconomicCode() : '',
'privateKey' => $entity ? $entity->getPrivateKey() : '',
];
}
return $this->json($settings); return $this->json($settings);
} }