@extends('layouts.app')
@section('title', '決済トランザクション')

@section('content')
<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-lg-6">
                <h1 class="m-0 text-dark">決済トランザクション</h1>
            </div>
            <div class="col-lg-6">
                <ol class="breadcrumb float-sm-right text-sm">
                    <li class="breadcrumb-item"><a href="{{ route('home') }}">ホーム</a></li>
                    <li class="breadcrumb-item active">決済トランザクション</li>
                </ol>
            </div>
        </div>
    </div>
</div>

<section class="content">
    <!-- 絞り込みフィルター -->
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header"><h3 class="card-title">絞り込みフィルター</h3></div>
            <div class="card-body">
                <form action="{{ route('settlement_transactions') }}" method="POST" id="list-form">
                    @csrf
                    <input type="hidden" name="sort" value="{{ $sort ?? '' }}">
                    <input type="hidden" name="sort_type" value="{{ $sort_type ?? '' }}">

                    <div class="row">
                        <div class="form-group col-12">
                            <label>定期契約ID</label>
                            <input type="text" name="contract_id" class="form-control"
                                value="{{ old('contract_id', $contract_id ?? '') }}">
                        </div>
                    </div>

                    <div class="form-group col-12 text-left">
                        <button type="submit" name="action" value="filter" class="btn btn-default">絞り込み</button>
                        <button type="submit" name="action" value="unlink" class="btn btn-default">解除</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="container-fluid">
        <!-- ツールバー -->
        <div class="container-fluid mb20">
            <div class="d-flex justify-content-end">
                {{ $transactions->appends(['sort' => $sort ?? '', 'sort_type' => $sort_type ?? ''])->links('pagination') }}
            </div>
        </div>

        <!-- メッセージ表示 -->
        <div class="form col-lg-12">
            @if(Session::has('success'))
                <div class="alert alert-success alert-dismissible" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    {{ Session::get('success') }}
                </div>
            @elseif(Session::has('error'))
                <div class="alert alert-danger alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-ban"></i> {{ __('誤差') }}:</h4>
                    {!! Session::get('error') !!}
                </div>
            @elseif(isset($errorMsg))
                <div class="alert alert-danger alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-ban"></i> {{ __('誤差') }}:</h4>
                    {!! $errorMsg !!}
                </div>
            @endif
        </div>

        <!-- ▼ 単一テーブル構成 ----------------------------------------- -->
        <div class="col-lg-12 mb20">
            <div class="table-responsive">
                <form action="{{ route('settlement_transactions_delete') }}" method="POST" id="form_delete">
                    @csrf
                    <table class="table table-bordered dataTable text-nowrap">
                        <thead class="thead-light">
                        <tr>                            
                            <th class="sorting {{ ($sort=='settlement_transaction_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="settlement_transaction_id"><span>決済トランザクションID</span></th>
                            <th class="sorting {{ ($sort=='contract_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="contract_id"><span>定期契約ID</span></th>
                            <th class="sorting {{ ($sort=='status') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="status"><span>ステータス</span></th>
                            <th><span>支払いコード</span></th>
                            <th><span>受付番号</span></th>
                            <th class="sorting {{ ($sort=='corp_code') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="corp_code"><span>企業コード</span></th>
                            <th class="sorting {{ ($sort=='mms_date') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="mms_date"><span>MMS予約照会日時</span></th>
                            <th class="sorting {{ ($sort=='cvs_code') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="cvs_code"><span>CVS本部コード</span></th>
                            <th class="sorting {{ ($sort=='shop_code') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="shop_code"><span>店舗コード</span></th>
                            <th class="sorting {{ ($sort=='pay_date') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="pay_date"><span>入金日時</span></th>
                            <th><span>決済金額</span></th>
                            <th><span>印紙貼付フラグ</span></th>
                            <th><span>MD5ハッシュ値</span></th>
                        </tr>
                        </thead>
                        <tbody class="bg-white" >
                        @foreach($transactions as $item)
                            <tr>
                                <td class="sm-item text-left align-middle">{{ $item->settlement_transaction_id }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->contract_id }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->status }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->pay_code }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->contract_payment_number }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->corp_code }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->mms_date }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->cvs_code }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->shop_code }}</td>
                                <td class="sm-item text-left align-middle">{{ optional($item->pay_date)->format('Y-m-d H:i') }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->settlement_amount }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->stamp_flag }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->md5_string }}</td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <!-- ▲ 単一テーブル構成ここまで ----------------------------------------- -->
    </div>
</section>

@endsection
