diff --git a/hesabixCore/src/Controller/ApprovalController.php b/hesabixCore/src/Controller/ApprovalController.php index 22906d3..32a6e27 100644 --- a/hesabixCore/src/Controller/ApprovalController.php +++ b/hesabixCore/src/Controller/ApprovalController.php @@ -134,16 +134,6 @@ class ApprovalController extends AbstractController $entityManager->persist($payment); } - $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'doc' => $document - ]); - foreach ($rows as $row) { - $row->setIsPreview(false); - $row->setIsApproved(true); - $row->setApprovedBy($user); - $entityManager->persist($row); - } - $entityManager->persist($document); $entityManager->flush(); @@ -227,16 +217,6 @@ class ApprovalController extends AbstractController $entityManager->persist($payment); } - $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'doc' => $document - ]); - foreach ($rows as $row) { - $row->setIsPreview(false); - $row->setIsApproved(true); - $row->setApprovedBy($user); - $entityManager->persist($row); - } - $entityManager->persist($document); $entityManager->flush(); } @@ -313,16 +293,6 @@ class ApprovalController extends AbstractController $entityManager->persist($payment); } - $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'doc' => $document - ]); - foreach ($rows as $row) { - $row->setIsPreview(true); - $row->setIsApproved(false); - $row->setApprovedBy(null); - $entityManager->persist($row); - } - $entityManager->persist($document); $entityManager->flush(); diff --git a/hesabixCore/src/Controller/Plugins/TaxSettingsController.php b/hesabixCore/src/Controller/Plugins/TaxSettingsController.php index e533de7..62a094e 100644 --- a/hesabixCore/src/Controller/Plugins/TaxSettingsController.php +++ b/hesabixCore/src/Controller/Plugins/TaxSettingsController.php @@ -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,6 +35,45 @@ class TaxSettingsController extends AbstractController return $sandboxMode ? 'https://sandboxrc.tax.gov.ir/' : 'https://tp.tax.gov.ir/'; } + private function getTaxSettings(EntityManagerInterface $em, int $businessId, User $user): array + { + $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); + $entity = $repo->findOneBy(['business_id' => $businessId]); + + $settings = [ + 'taxMemoryId' => $entity ? $entity->getTaxMemoryId() : '', + 'economicCode' => $entity ? $entity->getEconomicCode() : '', + 'privateKey' => $entity ? $entity->getPrivateKey() : '', + ]; + } else { + if (!$perm || !$perm->isPlugTaxSettings()) { + return [ + '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 $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 { @@ -45,40 +85,7 @@ class TaxSettingsController extends AbstractController $businessId = is_object($acc['bid']) ? $acc['bid']->getId() : $acc['bid']; $user = $this->getUser(); - $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); - $entity = $repo->findOneBy(['business_id' => $businessId]); - - $settings = [ - 'taxMemoryId' => $entity ? $entity->getTaxMemoryId() : '', - 'economicCode' => $entity ? $entity->getEconomicCode() : '', - '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() : '', - ]; - } - + $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' => 'تنظیمات مالیاتی تکمیل نشده است. لطفاً ابتدا تنظیمات را تکمیل کنید.' diff --git a/hesabixCore/src/Controller/SellController.php b/hesabixCore/src/Controller/SellController.php index fb0dbd1..b14fecd 100644 --- a/hesabixCore/src/Controller/SellController.php +++ b/hesabixCore/src/Controller/SellController.php @@ -1137,15 +1137,6 @@ class SellController extends AbstractController $hesabdariRow->setBd(0); $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '61']); $hesabdariRow->setRef($ref); - if ($TwoStepApproval) { - $hesabdariRow->setIsPreview(true); - $hesabdariRow->setIsApproved(false); - $hesabdariRow->setApprovedBy(null); - } else { - $hesabdariRow->setIsPreview(false); - $hesabdariRow->setIsApproved(true); - $hesabdariRow->setApprovedBy($this->getUser()); - } $entityManager->persist($hesabdariRow); } @@ -1175,15 +1166,6 @@ class SellController extends AbstractController $hesabdariRow->setBd($totalDiscount); $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '104']); $hesabdariRow->setRef($ref); - if ($TwoStepApproval) { - $hesabdariRow->setIsPreview(true); - $hesabdariRow->setIsApproved(false); - $hesabdariRow->setApprovedBy(null); - } else { - $hesabdariRow->setIsPreview(false); - $hesabdariRow->setIsApproved(true); - $hesabdariRow->setApprovedBy($this->getUser()); - } $entityManager->persist($hesabdariRow); } @@ -1208,16 +1190,6 @@ class SellController extends AbstractController $hesabdariRow->setDiscountType($item['showPercentDiscount'] ? 'percent' : 'fixed'); $hesabdariRow->setDiscountPercent($item['discountPercent'] ?? 0); - if ($TwoStepApproval) { - $hesabdariRow->setIsPreview(true); - $hesabdariRow->setIsApproved(false); - $hesabdariRow->setApprovedBy(null); - } else { - $hesabdariRow->setIsPreview(false); - $hesabdariRow->setIsApproved(true); - $hesabdariRow->setApprovedBy($this->getUser()); - } - $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '53']); $hesabdariRow->setRef($ref); @@ -1251,15 +1223,6 @@ class SellController extends AbstractController $taxRow->setBd(0); $taxRef = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '33']); $taxRow->setRef($taxRef); - if ($TwoStepApproval) { - $taxRow->setIsPreview(true); - $taxRow->setIsApproved(false); - $taxRow->setApprovedBy(null); - } else { - $taxRow->setIsPreview(false); - $taxRow->setIsApproved(true); - $taxRow->setApprovedBy($this->getUser()); - } $entityManager->persist($taxRow); } @@ -1277,16 +1240,6 @@ class SellController extends AbstractController $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '3']); $hesabdariRow->setRef($ref); - if ($TwoStepApproval) { - $hesabdariRow->setIsPreview(true); - $hesabdariRow->setIsApproved(false); - $hesabdariRow->setApprovedBy(null); - } else { - $hesabdariRow->setIsPreview(false); - $hesabdariRow->setIsApproved(true); - $hesabdariRow->setApprovedBy($this->getUser()); - } - if (!isset($params['customer']) || $params['customer'] == '') { $person = $entityManager->getRepository(Person::class)->findOneBy([ 'bid' => $acc['bid'], @@ -1365,15 +1318,6 @@ class SellController extends AbstractController $bankRef = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '5']); $bankRow->setRef($bankRef); $bankRow->setBank($entityManager->getRepository(BankAccount::class)->find($payment['bank'])); - if ($TwoStepApproval) { - $bankRow->setIsPreview(true); - $bankRow->setIsApproved(false); - $bankRow->setApprovedBy(null); - } else { - $bankRow->setIsPreview(false); - $bankRow->setIsApproved(true); - $bankRow->setApprovedBy($this->getUser()); - } $entityManager->persist($bankRow); } elseif ($payment['type'] === 'cashdesk') { // دریافت از طریق صندوق @@ -1387,15 +1331,6 @@ class SellController extends AbstractController $cashdeskRef = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '121']); $cashdeskRow->setRef($cashdeskRef); $cashdeskRow->setCashdesk($entityManager->getRepository(Cashdesk::class)->find($payment['cashdesk'])); - if ($TwoStepApproval) { - $cashdeskRow->setIsPreview(true); - $cashdeskRow->setIsApproved(false); - $cashdeskRow->setApprovedBy(null); - } else { - $cashdeskRow->setIsPreview(false); - $cashdeskRow->setIsApproved(true); - $cashdeskRow->setApprovedBy($this->getUser()); - } $entityManager->persist($cashdeskRow); } elseif ($payment['type'] === 'salary') { // دریافت از طریق تنخواه گردان @@ -1409,15 +1344,6 @@ class SellController extends AbstractController $salaryRef = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '122']); $salaryRow->setRef($salaryRef); $salaryRow->setSalary($entityManager->getRepository(Salary::class)->find($payment['salary'])); - if ($TwoStepApproval) { - $salaryRow->setIsPreview(true); - $salaryRow->setIsApproved(false); - $salaryRow->setApprovedBy(null); - } else { - $salaryRow->setIsPreview(false); - $salaryRow->setIsApproved(true); - $salaryRow->setApprovedBy($this->getUser()); - } $entityManager->persist($salaryRow); } @@ -1432,15 +1358,7 @@ class SellController extends AbstractController $receiveRef = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '3']); $receiveRow->setRef($receiveRef); $receiveRow->setPerson($person); - if ($TwoStepApproval) { - $receiveRow->setIsPreview(true); - $receiveRow->setIsApproved(false); - $receiveRow->setApprovedBy(null); - } else { - $receiveRow->setIsPreview(false); - $receiveRow->setIsApproved(true); - $receiveRow->setApprovedBy($this->getUser()); - } + $entityManager->persist($receiveRow); $entityManager->persist($paymentDoc); diff --git a/hesabixCore/src/Controller/StoreroomController.php b/hesabixCore/src/Controller/StoreroomController.php index b980248..ebe968b 100644 --- a/hesabixCore/src/Controller/StoreroomController.php +++ b/hesabixCore/src/Controller/StoreroomController.php @@ -68,7 +68,7 @@ class StoreroomController extends AbstractController if (!$file) { return $this->json(['result'=>-1,'message'=>'فایل ارسال نشده است'], 400); } - // Store securely in var/storage + $stored = $storage->store($file, (string)$acc['bid']->getId(), 'storeroom_attachments'); $archive = new ArchiveFile(); diff --git a/hesabixCore/src/Entity/HesabdariRow.php b/hesabixCore/src/Entity/HesabdariRow.php index 3baca35..6e91683 100644 --- a/hesabixCore/src/Entity/HesabdariRow.php +++ b/hesabixCore/src/Entity/HesabdariRow.php @@ -368,48 +368,4 @@ class HesabdariRow return $this; } - - // Approval fields - #[ORM\Column(nullable: true)] - private ?bool $isPreview = null; - - #[ORM\Column(nullable: true)] - private ?bool $isApproved = null; - - #[ORM\ManyToOne] - #[ORM\JoinColumn(nullable: true)] - private ?User $approvedBy = null; - - public function isPreview(): ?bool - { - return $this->isPreview; - } - - public function setIsPreview(?bool $isPreview): static - { - $this->isPreview = $isPreview; - return $this; - } - - public function isApproved(): ?bool - { - return $this->isApproved; - } - - public function setIsApproved(?bool $isApproved): static - { - $this->isApproved = $isApproved; - return $this; - } - - public function getApprovedBy(): ?User - { - return $this->approvedBy; - } - - public function setApprovedBy(?User $approvedBy): static - { - $this->approvedBy = $approvedBy; - return $this; - } } \ No newline at end of file diff --git a/public_html/uploads/storeroom/st_6899dc09b4eb05.86469834_4837DCA8-0915-4C7B-9BE1-70C87FF4385A.jpeg b/public_html/uploads/storeroom/st_6899dc09b4eb05.86469834_4837DCA8-0915-4C7B-9BE1-70C87FF4385A.jpeg deleted file mode 100644 index ffe5a5e..0000000 Binary files a/public_html/uploads/storeroom/st_6899dc09b4eb05.86469834_4837DCA8-0915-4C7B-9BE1-70C87FF4385A.jpeg and /dev/null differ diff --git a/public_html/uploads/storeroom/st_68a1ad4e1bb6c5.93976672_Screenshot_2025-03-30_233821.png b/public_html/uploads/storeroom/st_68a1ad4e1bb6c5.93976672_Screenshot_2025-03-30_233821.png deleted file mode 100644 index 795a746..0000000 Binary files a/public_html/uploads/storeroom/st_68a1ad4e1bb6c5.93976672_Screenshot_2025-03-30_233821.png and /dev/null differ diff --git a/public_html/uploads/storeroom/st_68a1af08b47979.56036064_Screenshot_2025-03-30_233821.png b/public_html/uploads/storeroom/st_68a1af08b47979.56036064_Screenshot_2025-03-30_233821.png deleted file mode 100644 index 795a746..0000000 Binary files a/public_html/uploads/storeroom/st_68a1af08b47979.56036064_Screenshot_2025-03-30_233821.png and /dev/null differ diff --git a/public_html/uploads/storeroom/st_68a1b350a9b8c3.34236142_NDr4WkNHDI.pdf b/public_html/uploads/storeroom/st_68a1b350a9b8c3.34236142_NDr4WkNHDI.pdf deleted file mode 100644 index 6717a5f..0000000 Binary files a/public_html/uploads/storeroom/st_68a1b350a9b8c3.34236142_NDr4WkNHDI.pdf and /dev/null differ