Funds.php 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\FundsSummaryService;
  6. use Exception;
  7. use Illuminate\Validation\ValidationException;
  8. class Funds extends Controller
  9. {
  10. public function summary()
  11. {
  12. try {
  13. $params = request()->validate([
  14. 'start_date' => ['nullable', 'date_format:Y-m-d', 'required_with:end_date'],
  15. 'end_date' => ['nullable', 'date_format:Y-m-d', 'required_with:start_date', 'after_or_equal:start_date'],
  16. ]);
  17. $today = date('Y-m-d');
  18. $startDate = $params['start_date'] ?? $today;
  19. $endDate = $params['end_date'] ?? $today;
  20. return $this->success(FundsSummaryService::summary($startDate, $endDate));
  21. } catch (ValidationException $e) {
  22. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  23. } catch (Exception $e) {
  24. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  25. }
  26. }
  27. }