update for Moadian plugin

This commit is contained in:
Gloomy 2025-08-19 16:37:49 +00:00
parent f3517d55d6
commit 758111de76

View file

@ -23,6 +23,7 @@ use App\Entity\HesabdariDoc;
use App\Entity\PluginTaxInvoice; use App\Entity\PluginTaxInvoice;
use App\Dto\TaxSettingsDto; use App\Dto\TaxSettingsDto;
use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Validator\Validator\ValidatorInterface;
use App\Entity\User;
use DateTime; use DateTime;
class TaxSettingsController extends AbstractController class TaxSettingsController extends AbstractController
@ -34,17 +35,8 @@ class TaxSettingsController extends AbstractController
return $sandboxMode ? 'https://sandboxrc.tax.gov.ir/' : 'https://tp.tax.gov.ir/'; return $sandboxMode ? 'https://sandboxrc.tax.gov.ir/' : 'https://tp.tax.gov.ir/';
} }
#[Route('/api/plugins/tax/settings/get', name: 'plugin_tax_settings_get', methods: ['GET'])] private function getTaxSettings(EntityManagerInterface $em, int $businessId, User $user): array
public function plugin_tax_settings_get(EntityManagerInterface $em, Access $access): JsonResponse
{ {
$acc = $access->hasRole('plugTaxSettings');
if (!$acc) {
throw $this->createAccessDeniedException('شما دسترسی لازم را ندارید.');
}
$businessId = is_object($acc['bid']) ? $acc['bid']->getId() : $acc['bid'];
$user = $this->getUser();
$perm = $em->getRepository(Permission::class)->findOneBy([ $perm = $em->getRepository(Permission::class)->findOneBy([
'bid' => $businessId, 'bid' => $businessId,
'user' => $user 'user' => $user
@ -63,10 +55,10 @@ class TaxSettingsController extends AbstractController
]; ];
} else { } else {
if (!$perm || !$perm->isPlugTaxSettings()) { if (!$perm || !$perm->isPlugTaxSettings()) {
return $this->json([ return [
'success' => false, 'success' => false,
'message' => 'شما دسترسی لازم را ندارید.' 'message' => 'شما دسترسی لازم را ندارید.'
]); ];
} }
$repo = $em->getRepository(PluginTaxsettingsKey::class); $repo = $em->getRepository(PluginTaxsettingsKey::class);
@ -79,6 +71,21 @@ class TaxSettingsController extends AbstractController
]; ];
} }
return $settings;
}
#[Route('/api/plugins/tax/settings/get', name: 'plugin_tax_settings_get', methods: ['GET'])]
public function plugin_tax_settings_get(EntityManagerInterface $em, Access $access): JsonResponse
{
$acc = $access->hasRole('plugTaxSettings');
if (!$acc) {
throw $this->createAccessDeniedException('شما دسترسی لازم را ندارید.');
}
$businessId = is_object($acc['bid']) ? $acc['bid']->getId() : $acc['bid'];
$user = $this->getUser();
$settings = $this->getTaxSettings($em, $businessId, $user);
return $this->json($settings); return $this->json($settings);
} }
@ -777,7 +784,6 @@ 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;
$taxInvoiceRepo = $em->getRepository(PluginTaxInvoice::class); $taxInvoiceRepo = $em->getRepository(PluginTaxInvoice::class);
$taxInvoice = $taxInvoiceRepo->findOneBy([ $taxInvoice = $taxInvoiceRepo->findOneBy([
@ -801,10 +807,9 @@ class TaxSettingsController extends AbstractController
]); ]);
} }
$repo = $em->getRepository(PluginTaxsettingsKey::class); $taxSettings = $this->getTaxSettings($em, $businessId, $user);
$taxSettings = $repo->findOneBy(['business_id' => $businessId, 'user_id' => $userId]);
if (!$taxSettings || !$taxSettings->getPrivateKey() || !$taxSettings->getTaxMemoryId()) { if (!$taxSettings['privateKey'] || !$taxSettings['taxMemoryId']) {
return $this->json([ return $this->json([
'success' => false, 'success' => false,
'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.' 'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.'
@ -812,8 +817,8 @@ class TaxSettingsController extends AbstractController
} }
try { try {
$username = $taxSettings->getTaxMemoryId(); $username = $taxSettings['taxMemoryId'];
$privateKey = $taxSettings->getPrivateKey(); $privateKey = $taxSettings['privateKey'];
if (!$username || !$privateKey) { if (!$username || !$privateKey) {
return $this->json([ return $this->json([
@ -872,7 +877,7 @@ class TaxSettingsController extends AbstractController
throw new \Exception($validationResult['message']); throw new \Exception($validationResult['message']);
} }
$invoiceDto = $this->buildInvoiceDto($invoice, $moadian, $taxSettings->getEconomicCode()); $invoiceDto = $this->buildInvoiceDto($invoice, $moadian, $taxSettings['economicCode']);
if (!$invoiceDto) { if (!$invoiceDto) {
throw new \Exception('خطا در آماده‌سازی فاکتور: خطا در ساخت DTO فاکتور'); throw new \Exception('خطا در آماده‌سازی فاکتور: خطا در ساخت DTO فاکتور');
} }
@ -1004,12 +1009,10 @@ 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;
$repo = $em->getRepository(PluginTaxsettingsKey::class); $taxSettings = $this->getTaxSettings($em, $businessId, $user);
$taxSettings = $repo->findOneBy(['business_id' => $businessId, 'user_id' => $userId]);
if (!$taxSettings || !$taxSettings->getPrivateKey() || !$taxSettings->getTaxMemoryId()) { if (!$taxSettings['privateKey'] || !$taxSettings['taxMemoryId']) {
return $this->json([ return $this->json([
'success' => false, 'success' => false,
'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.' 'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.'
@ -1017,8 +1020,8 @@ class TaxSettingsController extends AbstractController
} }
try { try {
$username = $taxSettings->getTaxMemoryId(); $username = $taxSettings['taxMemoryId'];
$privateKey = $taxSettings->getPrivateKey(); $privateKey = $taxSettings['privateKey'];
$taxOrgPublicKey = ''; $taxOrgPublicKey = '';
$taxOrgKeyId = ''; $taxOrgKeyId = '';
@ -1359,12 +1362,10 @@ 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;
$repo = $em->getRepository(PluginTaxsettingsKey::class); $taxSettings = $this->getTaxSettings($em, $businessId, $user);
$taxSettings = $repo->findOneBy(['business_id' => $businessId, 'user_id' => $userId]);
if (!$taxSettings || !$taxSettings->getPrivateKey() || !$taxSettings->getTaxMemoryId()) { if (!$taxSettings['privateKey'] || !$taxSettings['taxMemoryId']) {
return $this->json([ return $this->json([
'success' => false, 'success' => false,
'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.' 'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.'
@ -1372,8 +1373,8 @@ class TaxSettingsController extends AbstractController
} }
try { try {
$username = $taxSettings->getTaxMemoryId(); $username = $taxSettings['taxMemoryId'];
$privateKey = $taxSettings->getPrivateKey(); $privateKey = $taxSettings['privateKey'];
if (!$username || !$privateKey) { if (!$username || !$privateKey) {
return $this->json([ return $this->json([
@ -1482,7 +1483,7 @@ class TaxSettingsController extends AbstractController
continue; continue;
} }
$invoiceDto = $this->buildInvoiceDto($invoice, $moadian, $taxSettings->getEconomicCode()); $invoiceDto = $this->buildInvoiceDto($invoice, $moadian, $taxSettings['economicCode']);
if (!$invoiceDto) { if (!$invoiceDto) {
$results[] = [ $results[] = [
'id' => $id, 'id' => $id,
@ -1581,12 +1582,10 @@ 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;
$repo = $em->getRepository(PluginTaxsettingsKey::class); $taxSettings = $this->getTaxSettings($em, $businessId, $user);
$taxSettings = $repo->findOneBy(['business_id' => $businessId, 'user_id' => $userId]);
if (!$taxSettings || !$taxSettings->getPrivateKey() || !$taxSettings->getTaxMemoryId()) { if (!$taxSettings['privateKey'] || !$taxSettings['taxMemoryId']) {
return $this->json([ return $this->json([
'success' => false, 'success' => false,
'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.' 'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.'