@if(isset($couriers[0]))
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title" data-toggle="collapse" data-parent="#accordion" href="#collapse10">
                <a>Couriers</a> <i class="la la-plus-circle" style="float: right;padding-right: 8px;padding-top: 5px;"></i>
            </h4>
        </div>
        <div id="collapse10" class="panel-collapse collapse in">
            @foreach($couriers as $courier)
                <div class="panel-body">
                    <?php if(isset($courier->received_by) && $courier->received_by > 0){ ?>
                    <div class="row col-md-5">
                        <div style="padding-bottom: 7px;"><b><i class="fa fa-file-o" style="padding-right: 10px;"></i>Courier Received Summary</b></div>
                        <table class="table">
                            <tbody>
                            <tr>
                                <td><i class="fa fa-user" style="padding-right: 10px;"></i>Courier Received By</td>
                                <td>{!! \App\User::find($courier->received_by)->name !!}</td>
                                <td><i class="fa fa-user" style="padding-right: 10px;"></i>Courier Sent By</td>
                                <td><?php echo ((\App\User::find($courier->user_id)) ? (\App\User::find($courier->user_id)->name) : ""); ?> </td>
                            </tr>
                            <tr>
                                <td><i class="fa fa-clock-o" style="padding-right: 10px;"></i>Courier Received at</td>
                                <td>{!! date('M d, Y', strtotime($courier->updated_at)) !!}</td>
                                <td><i class="fa fa-clock-o" style="padding-right: 10px;"></i>Courier Sent at</td>
                                <td>{!! date('M d, Y', strtotime($courier->created_at)) !!}</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <?php } ?>
                </div>
                <div class="col-md-12">
                    <?php $documents = json_decode($courier->documents, 1); ?>
                    <?php $received_document = (!empty($courier->received_document)) ? json_decode($courier->received_document, 1) : []; ?>
                    <table class="table col-md-12">
                        <thead>
                        <tr>
                            <th>Document Of</th>
                            <th>Name</th>
                            <th>Document</th>
                            <th>Document Quantity</th>
                            <th>Is Received</th>
                            <th>Received Quantity</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($documents as $key=>$document)
                            <tr>

                                <?php
                                $document_for_id = '';
                                $document_for = '';
                                switch ($document['document_for']){
                                    case 1:
                                        $document_for = 'Merchant';
                                        $merchant = \App\Merchant::find($document['document_for_id']);
                                        $document_for_id = isset($merchant->merchant_name) ? $merchant->merchant_name : '';
                                        break;
                                    case 2:
                                        $application = \App\ConsumerApplication::find($document['document_for_id']);
                                        $document_for_id = isset($application->name) ? $application->name : '';
                                        $document_for = 'Consumer';
                                        break;
                                    case 3:
                                        $document_for_id = $document['document_for_id'];
                                        $document_for = 'Other';
                                        break;
                                }

                                ?>

                                <td><?php echo $document_for; ?></td>
                                <td><?php echo $document_for_id; ?></td>
                                <td>{!! ucwords(str_replace('_',' ',$document['document'])) !!}</td>
                                <td>{!! $document['document_count'] !!}</td>
                                <td><label><input type="checkbox" data-id="{!! $document['document_id'] !!}" class="is_document_received" name="is_received[{!! $document['document_id'] !!}][]" <?php echo isset($received_document[$document['document_id']]) && isset($received_document[$document['document_id']]['is_received']) && $received_document[$document['document_id']]['is_received'] == 1 ? 'checked' : ''; ?> readonly disabled/></label></td>
                                <td><div>
                                        <input style="width: 54%" id="received_quantity_{!! $document['document_id'] !!}" type="number" min="0" max="{!! $document['document_count'] !!}" name="received_quantity[{!! $document['document_id'] !!}][]" value="<?php echo isset($received_document[$document['document_id']]) && isset($received_document[$document['document_id']]['document_count']) ? $received_document[$document['document_id']]['document_count'] : 0; ?>" readonly disabled class="form-control received_q_count" placeholder="Received Quantity" <?php echo isset($received_document[$document['document_id']]) ? 'readonly disabled' : ''; ?>/>
                                        <input type="hidden" name="document_id[]" value="{!! $document['document_id'] !!}"/>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    <?php if(isset($courier->id) && (is_null($courier->received_by))){ ?>
                    <div class="form-control btn btn-primary col-md-2"><a style="text-decoration: none;color:white;" href="/admin/courier/{!! $courier->id !!}">Courier Received</a></div>
                    <?php } ?>
                </div>
            @endforeach
        </div>
    </div>
@endif
