update for Moadian plugin
This commit is contained in:
parent
f3517d55d6
commit
758111de76
|
@ -23,6 +23,7 @@ use App\Entity\HesabdariDoc;
|
|||
use App\Entity\PluginTaxInvoice;
|
||||
use App\Dto\TaxSettingsDto;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use App\Entity\User;
|
||||
use DateTime;
|
||||
|
||||
class TaxSettingsController extends AbstractController
|
||||
|
@ -34,17 +35,8 @@ class TaxSettingsController extends AbstractController
|
|||
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'])]
|
||||
public function plugin_tax_settings_get(EntityManagerInterface $em, Access $access): JsonResponse
|
||||
private function getTaxSettings(EntityManagerInterface $em, int $businessId, User $user): array
|
||||
{
|
||||
$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([
|
||||
'bid' => $businessId,
|
||||
'user' => $user
|
||||
|
@ -63,10 +55,10 @@ class TaxSettingsController extends AbstractController
|
|||
];
|
||||
} else {
|
||||
if (!$perm || !$perm->isPlugTaxSettings()) {
|
||||
return $this->json([
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'شما دسترسی لازم را ندارید.'
|
||||
]);
|
||||
];
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
@ -777,7 +784,6 @@ class TaxSettingsController extends AbstractController
|
|||
|
||||
$businessId = is_object($acc['bid']) ? $acc['bid']->getId() : $acc['bid'];
|
||||
$user = $this->getUser();
|
||||
$userId = $user instanceof \App\Entity\User ? $user->getId() : null;
|
||||
|
||||
$taxInvoiceRepo = $em->getRepository(PluginTaxInvoice::class);
|
||||
$taxInvoice = $taxInvoiceRepo->findOneBy([
|
||||
|
@ -801,10 +807,9 @@ class TaxSettingsController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
$repo = $em->getRepository(PluginTaxsettingsKey::class);
|
||||
$taxSettings = $repo->findOneBy(['business_id' => $businessId, 'user_id' => $userId]);
|
||||
$taxSettings = $this->getTaxSettings($em, $businessId, $user);
|
||||
|
||||
if (!$taxSettings || !$taxSettings->getPrivateKey() || !$taxSettings->getTaxMemoryId()) {
|
||||
if (!$taxSettings['privateKey'] || !$taxSettings['taxMemoryId']) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.'
|
||||
|
@ -812,8 +817,8 @@ class TaxSettingsController extends AbstractController
|
|||
}
|
||||
|
||||
try {
|
||||
$username = $taxSettings->getTaxMemoryId();
|
||||
$privateKey = $taxSettings->getPrivateKey();
|
||||
$username = $taxSettings['taxMemoryId'];
|
||||
$privateKey = $taxSettings['privateKey'];
|
||||
|
||||
if (!$username || !$privateKey) {
|
||||
return $this->json([
|
||||
|
@ -872,7 +877,7 @@ class TaxSettingsController extends AbstractController
|
|||
throw new \Exception($validationResult['message']);
|
||||
}
|
||||
|
||||
$invoiceDto = $this->buildInvoiceDto($invoice, $moadian, $taxSettings->getEconomicCode());
|
||||
$invoiceDto = $this->buildInvoiceDto($invoice, $moadian, $taxSettings['economicCode']);
|
||||
if (!$invoiceDto) {
|
||||
throw new \Exception('خطا در آمادهسازی فاکتور: خطا در ساخت DTO فاکتور');
|
||||
}
|
||||
|
@ -1004,12 +1009,10 @@ class TaxSettingsController extends AbstractController
|
|||
|
||||
$businessId = is_object($acc['bid']) ? $acc['bid']->getId() : $acc['bid'];
|
||||
$user = $this->getUser();
|
||||
$userId = $user instanceof \App\Entity\User ? $user->getId() : null;
|
||||
|
||||
$repo = $em->getRepository(PluginTaxsettingsKey::class);
|
||||
$taxSettings = $repo->findOneBy(['business_id' => $businessId, 'user_id' => $userId]);
|
||||
$taxSettings = $this->getTaxSettings($em, $businessId, $user);
|
||||
|
||||
if (!$taxSettings || !$taxSettings->getPrivateKey() || !$taxSettings->getTaxMemoryId()) {
|
||||
if (!$taxSettings['privateKey'] || !$taxSettings['taxMemoryId']) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.'
|
||||
|
@ -1017,8 +1020,8 @@ class TaxSettingsController extends AbstractController
|
|||
}
|
||||
|
||||
try {
|
||||
$username = $taxSettings->getTaxMemoryId();
|
||||
$privateKey = $taxSettings->getPrivateKey();
|
||||
$username = $taxSettings['taxMemoryId'];
|
||||
$privateKey = $taxSettings['privateKey'];
|
||||
$taxOrgPublicKey = '';
|
||||
$taxOrgKeyId = '';
|
||||
|
||||
|
@ -1359,12 +1362,10 @@ class TaxSettingsController extends AbstractController
|
|||
|
||||
$businessId = is_object($acc['bid']) ? $acc['bid']->getId() : $acc['bid'];
|
||||
$user = $this->getUser();
|
||||
$userId = $user instanceof \App\Entity\User ? $user->getId() : null;
|
||||
|
||||
$repo = $em->getRepository(PluginTaxsettingsKey::class);
|
||||
$taxSettings = $repo->findOneBy(['business_id' => $businessId, 'user_id' => $userId]);
|
||||
$taxSettings = $this->getTaxSettings($em, $businessId, $user);
|
||||
|
||||
if (!$taxSettings || !$taxSettings->getPrivateKey() || !$taxSettings->getTaxMemoryId()) {
|
||||
if (!$taxSettings['privateKey'] || !$taxSettings['taxMemoryId']) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.'
|
||||
|
@ -1372,8 +1373,8 @@ class TaxSettingsController extends AbstractController
|
|||
}
|
||||
|
||||
try {
|
||||
$username = $taxSettings->getTaxMemoryId();
|
||||
$privateKey = $taxSettings->getPrivateKey();
|
||||
$username = $taxSettings['taxMemoryId'];
|
||||
$privateKey = $taxSettings['privateKey'];
|
||||
|
||||
if (!$username || !$privateKey) {
|
||||
return $this->json([
|
||||
|
@ -1482,7 +1483,7 @@ class TaxSettingsController extends AbstractController
|
|||
continue;
|
||||
}
|
||||
|
||||
$invoiceDto = $this->buildInvoiceDto($invoice, $moadian, $taxSettings->getEconomicCode());
|
||||
$invoiceDto = $this->buildInvoiceDto($invoice, $moadian, $taxSettings['economicCode']);
|
||||
if (!$invoiceDto) {
|
||||
$results[] = [
|
||||
'id' => $id,
|
||||
|
@ -1581,12 +1582,10 @@ class TaxSettingsController extends AbstractController
|
|||
|
||||
$businessId = is_object($acc['bid']) ? $acc['bid']->getId() : $acc['bid'];
|
||||
$user = $this->getUser();
|
||||
$userId = $user instanceof \App\Entity\User ? $user->getId() : null;
|
||||
|
||||
$repo = $em->getRepository(PluginTaxsettingsKey::class);
|
||||
$taxSettings = $repo->findOneBy(['business_id' => $businessId, 'user_id' => $userId]);
|
||||
$taxSettings = $this->getTaxSettings($em, $businessId, $user);
|
||||
|
||||
if (!$taxSettings || !$taxSettings->getPrivateKey() || !$taxSettings->getTaxMemoryId()) {
|
||||
if (!$taxSettings['privateKey'] || !$taxSettings['taxMemoryId']) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'message' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.'
|
||||
|
|
Loading…
Reference in a new issue