<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Traits\FinancialTrait;
use App\Http\Controllers\Controller;

class ExchangeController extends Controller
{
    use FinancialTrait;

    /*
     * 환율 정보
     */
    public function index(Request $request)
    {
        $data = [
            'subject' => '도매 관리 - 환율 정보'
        ];

        $searchDate = $request->get("search_date", date('Y-m-d', time()));
        $exchangeList = $this->exchangeList($searchDate);

        if ($exchangeList) {
            foreach ($exchangeList as $idx => $exchange) {
                if (in_array($exchange['cur_unit'], ["USD", "EUR"])) {
                    array_unshift($exchangeList, $exchange);
                    unset($exchangeList[$idx + 1]);
                }
            }
        }

        $data['searchDate'] = $searchDate;
        $data['exchangeList'] = $exchangeList;
        $data['exchangeRows'] = count($exchangeList);

        return view('admin.exchange', $data);
    }
}
