diff --git a/app/Http/Controllers/Admin/TahesabController.php b/app/Http/Controllers/Admin/TahesabController.php index a59a563..53917fa 100644 --- a/app/Http/Controllers/Admin/TahesabController.php +++ b/app/Http/Controllers/Admin/TahesabController.php @@ -22,6 +22,21 @@ class TahesabController extends Controller return app(TahesabSyncService::class); } + private function lastPriceData(): array + { + $response = app(ReportController::class)->lastPrice(request()); + + if (is_array($response)) { + return $response; + } + + if (is_object($response) && method_exists($response, 'getData')) { + return (array) $response->getData(true); + } + + return (array) $response; + } + public function table(Request $request) { $query = Tahesab::with('customer')->orderByDesc('id'); @@ -478,8 +493,7 @@ class TahesabController extends Controller "data" => json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), ]); - $pricesResponse = app(ReportController::class)->lastPrice(request()); - $prices = method_exists($pricesResponse, 'getData') ? (array) $pricesResponse->getData(true) : (array) $pricesResponse; + $prices = $this->lastPriceData(); $mazaneh = $isDeposit ? (int) ($prices['buy'] ?? 0) : (int) ($prices['sell'] ?? 0); $mablaghKol = (int) round($mazaneh * $amount);