success($this->configRepo->getAll()); } #[Route('/api/v1/admin/settings', methods: ['PATCH'])] public function patch(Request $request, #[\Symfony\Component\Security\Http\Attribute\CurrentUser] \App\Auth\Entity\User $admin): JsonResponse { $data = json_decode($request->getContent(), true) ?? []; // مقادیر فعلی مالیات برای تشخیص تغییر و ثبت تاریخچه. $prevTaxPercent = $this->configRepo->get('tax_percent'); $prevTaxEnabled = $this->configRepo->get('tax_enabled'); foreach ($data as $key => $value) { if (!in_array($key, self::ALLOWED_KEYS, true)) { continue; } $this->configRepo->set($key, $value === null ? null : (string) $value); } $this->em->flush(); $newTaxPercent = $this->configRepo->get('tax_percent'); $newTaxEnabled = $this->configRepo->get('tax_enabled'); if ($newTaxPercent !== $prevTaxPercent || $newTaxEnabled !== $prevTaxEnabled) { $this->taxHistoryRepo->save(new \App\Config\Entity\TaxRateHistory( (string) $newTaxPercent, $newTaxEnabled === '1', $admin, )); } return $this->success($this->configRepo->getAll()); } #[Route('/api/v1/admin/settings/tax-history', methods: ['GET'])] public function taxHistory(): JsonResponse { $rows = $this->taxHistoryRepo->findBy([], ['changedAt' => 'DESC'], 50); return $this->success(array_map( fn(\App\Config\Entity\TaxRateHistory $h) => $h->toArray(), $rows, )); } }