@extends('admin.layouts.master')

@section('title')
    Releases
@stop

@section('style')

@stop

@section('content')
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <span class="fa fa-table"></span> Commission Releases
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-table"></i> Admin Panel</a></li>
                <li class="active">Releases</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content" style=" padding-bottom: 100%;">
            <div class="page-header">
                <a href="{{route('releases.new')}}" class="btn btn-primary"><i class="fa fa-plus-circle"></i> New Release</a>
            </div>

            <table class="table table-hover" id="releases_table">
                <thead>
                <tr style="background: grey ;color:#fff; font-weight: bold">
                    <td>ID</td>
                    <td>Agent Name</td>
                    <td>Unit Manager</td>
                    <td>Referrer</td>
                    <td>Remarks</td>
                    <td>Created By</td>
                    <td>Released Date</td>
                    <td>Actions</td>
                </tr>
                </thead>
                @foreach($comms as $comm)
                    <tr >
                        <td>{{$comm->id}}</td>
                        <td>{{ isset($comm->agent->fullname) ? $comm->agent->fullname : '-' }}</td>
                        <td>{{ isset($comm->manager->fullname) ? $comm->manager->fullname : '-' }}</td>
                        <td>{{ isset($comm->referrer_id) ? $comm->referrer->fullname : '-' }}</td>
                        {{--<td>{{$comm->referrer->fullname}}</td>--}}
                        <td>{{$comm->remarks}}</td>
                        <td>{{$comm->user->full_name}}</td>
                        {{--<td style="text-align: right">{{number_format($comm->property->net_selling_price,2)}}</td>
                        <td style="text-align: right">{{number_format($comm->property->comm_rate,2)}}</td>
                        <td style="text-align: right">{{number_format($comm->property->rate_amount,2)}}</td>
                        <td style="text-align: right">{{number_format($comm->release_amount,2)}}</td>--}}
                        <td>{{$comm->created_at}}</td>

                        <td class="btn btn-default ">
                            <a href="#" data-toggle="modal" data-target="#e{{$comm->rcvd_id}}" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i></a>
                            {{--<a href="#" data-toggle="modal" data-target="#d{{$comm->rcvd_id}}" class="text-danger btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>--}}

                            <div class="modal fade" id="e{{$comm->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                <div class="modal-dialog" role="document">
                                    <form method="post" action="{{route('releases.edit')}}">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title" id="myModalLabel">Edit Release info for <b>"{{$comm->agent->fullname}}"</b></h4>
                                            </div>
                                            <div class="modal-body text-left">
                                                <input type="hidden" name="id" value="{{$comm->id}}">

                                                {{--@foreach($releases as $release)
                                                <div class="modal-body text-left">
                                                    <input type="hidden" id="gl_id" name="gl_id" value="{{$release->gr_id}}">
                                                    <input type="hidden" id="rcvd_id" name="rcvd_id" value="{{$release->rcvd_id}}">
                                                    <input type="hidden" id="comm_amount" name="comm_amount" value="{{$release->amount}}">
                                                <div class="col-md-12">
                                                    <div class="form-group has-feedback @if($errors->has('agent_id')) has-error @endif">
                                                        <label for="agent_id" class="control-label">Agent</label>
                                                        <select name="agent_id" id="agent_id" class="form-control">
                                                            <option value="">Select Agent</option>
                                                            @foreach($agents as $agent)
                                                                <option value="{{$agent->id}}">{{$agent->fullname}}</option>
                                                            @endforeach
                                                        </select>
                                                        <span class="fa fa-user form-control-feedback"></span>
                                                        @if($errors->has('agent_id')) <span class="help-block">{{$errors->first('agent_id')}}</span> @endif
                                                    </div>
                                                    {{--<div class="form-group has-feedback @if($errors->has('umanager_id')) has-error @endif">
                                                        <label for="umanager_id" class="control-label">Unit Manager</label>
                                                        <select name="umanager_id" id="umanager_id" class="form-control">
                                                            <option value="">Select Unit Manager</option>
                                                            @foreach($ums as $um)
                                                                <option value="{{$um->id}}">{{$um->fullname}}</option>
                                                            @endforeach
                                                        </select>
                                                        <span class="fa fa-user-md form-control-feedback"></span>
                                                        @if($errors->has('umanager_id')) <span class="help-block">{{$errors->first('umanager_id')}}</span> @endif
                                                    </div>
                                                    <div class="form-group has-feedback @if($errors->has('referrer_id')) has-error @endif">
                                                        <label for="referrer_id" class="control-label">Referrer</label>
                                                        <select name="referrer_id" id="referrer_id" class="form-control">
                                                            <option value="">Select Referrer</option>
                                                            @foreach($agents as $agent)
                                                                <option value="{{$agent->id}}">{{$agent->fullname}}</option>
                                                            @endforeach
                                                        </select>
                                                        <span class="fa fa-users form-control-feedback"></span>
                                                        @if($errors->has('referrer_id')) <span class="help-block">{{$errors->first('referrer_id')}}</span> @endif
                                                    </div>
                                                    <div class="form-group has-feedback @if($errors->has('referrer_id')) has-error @endif">
                                                        <label for="remarks" class="control-label">Remarks:</label>
                                                        <textarea class="form-control txt" rows="2" name="remarks" id="remarks" placeholder=""></textarea>
                                                        @if($errors->has('remarks')) <span class="help-block">{{$errors->first('remarks')}}</span> @endif
                                                    </div>

                                                    <hr>

                                                    @foreach ($share as $sh)
                                                        <div class="form-group">
                                                            <div class="editor-label">
                                                                <label for="agent_pcg_rate">Agent Share %</label>
                                                            </div>
                                                            <div class="editor-field">
                                                                <input type="number" name="agent_pcg_rate" id="agent_pcg_rate" value="{{$sh->shr_agent}}" class="form-control comm_rate"/>

                                                            </div>
                                                        </div>

                                                        <div class="form-group">
                                                            <div class="editor-label">
                                                                <label for="um_pcg_rate">Unit Manager Share %</label>
                                                            </div>
                                                            <div class="editor-field">
                                                                <input type="number" name="um_pcg_rate" id="um_pcg_rate" value="{{$sh->shr_um}}" class="form-control comm_rate" />
                                                            </div>
                                                        </div>

                                                        <div class="form-group">
                                                            <div class="editor-label">
                                                                <label for="broker_pcg_rate">Broker Share %</label>
                                                            </div>
                                                            <div class="editor-field">
                                                                <input type="number" name="broker_pcg_rate" id="broker_pcg_rate" value="{{$sh->shr_broker}}" class="form-control comm_rate" />
                                                            </div>
                                                        </div>

                                                        <div class="form-group">
                                                            <div class="editor-label">
                                                                <label for="referrer_pcg_rate">Referrer Share %</label>
                                                            </div>
                                                            <div class="editor-field">
                                                                <input type="number" name="referrer_pcg_rate" id="referrer_pcg_rate" value="{{$sh->shr_refer}}" class="form-control comm_rate" />
                                                            </div>
                                                        </div>
                                                    @endforeach

                                                    <div class="form-group ">
                                                        <div class="editor-label">
                                                            <label for="agent_pcg_rate">Cash Advance Payment</label>
                                                        </div>
                                                        <div class="editor-field">
                                                            <input type="number" name="ca_amount" id="ca_amount" value="0.00" class="form-control comm_rate"/>
                                                        </div>
                                                    </div>--}}

                                                {{--<div class="form-group has-feedback @if($errors->has('full_name')) has-error @endif">
                                                    <label for="full_name" class="control-label">Full Name</label>
                                                    <input value="{{$user->full_name}}" type="text" name="full_name" id="full_name" class="form-control">
                                                    <span class="glyphicon glyphicon-book form-control-feedback"></span>
                                                    @if($errors->has('full_name')) <span class="help-block">{{$errors->first('full_name')}}</span> @endif
                                                </div>
                                                <div class="form-group has-feedback @if($errors->has('name')) has-error @endif">
                                                    <label for="name" class="control-label">Username</label>
                                                    <input value="{{$user->name}}" type="text" name="name" id="name" class="form-control">
                                                    <span class="glyphicon glyphicon-user form-control-feedback"></span>
                                                    @if($errors->has('name')) <span class="help-block">{{$errors->first('name')}}</span> @endif
                                                </div>
                                                <div class="form-group has-feedback @if($errors->has('email')) has-error @endif">
                                                    <label for="email" class="control-label">Email Address</label>
                                                    <input value="{{$user->email}}" type="email" name="email" id="email" class="form-control">
                                                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                                                    @if($errors->has('email')) <span class="help-block">{{$errors->first('email')}}</span> @endif
                                                </div>
                                                <div class="form-group has-feedback @if($errors->has('role')) has-error @endif">
                                                    <label for="role" class="control-label">Roles</label>
                                                    <select name="role" id="role" class="form-control">
                                                        <option value="">Select Role</option>
                                                        @foreach($roles as $role)
                                                            <option @if($user->roles->first()->id == $role->id) selected  @endif>{{$role->name}}</option>
                                                        @endforeach
                                                    </select>
                                                    <span class="fa fa-user-md form-control-feedback"></span>
                                                    @if($errors->has('role')) <span class="help-block">{{$errors->first('role')}}</span> @endif
                                                </div>
                                                <div class="form-group has-feedback @if($errors->has('password')) has-error @endif">
                                                    <label for="password" class="control-label">Password</label>
                                                    <input type="password" name="password" id="password" class="form-control">
                                                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                                                    @if($errors->has('password')) <span class="help-block">{{$errors->first('password')}}</span> @endif
                                                </div>--}}
                                                {{--@endforeach--}}

                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                <button type="submit" class="btn btn-primary">Confirm</button>
                                            </div>

                                            </div>
                                        {{--</div>--}}
                                        {{csrf_field()}}
                                    </form>
                                </div>
                            </div>

                            <a href="#" data-toggle="modal" data-target="#d{{$comm->id}}" class="text-danger btn btn-danger btn-xs"><i class="fa fa-trash"></i></a>
                            <!-- Delete Modal -->
                            <div class="modal fade" id="d{{$comm->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                <div class="modal-dialog" role="document">
                                    <form method="post" action="{{route('user.delete')}}">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                            <h4 class="modal-title" id="myModalLabel"><i class="fa fa-warning"></i> confirm deletion</h4>
                                        </div>
                                        <div class="modal-body text-danger">
                                            <input type="hidden" name="id" value="{{$comm->id}}">
                                            Are you sure want to delete this Release entry
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                            <button type="submit" class="btn btn-primary">Confirm</button>
                                        </div>

                                    </div>
                                        {{csrf_field()}}
                                    </form>
                                </div>
                            </div>
                        </td>
                    </tr>
                    @endforeach
            </table>
            @if(Session('info'))
                <div class="row">
                    <div class="col-md-6 col-md-offset-3 text-center">
                        <div class="tem alert alert-success navbar-fixed-bottom"><span class="glyphicon glyphicon-ok-circle"></span> {{Session('info')}}</div>
                    </div>
                </div>
            @endif
        </section>

    </div>
@stop

@section('script')

<script>
    $('#releases_table').DataTable( {
        "bDestroy": true,
        /*searching: true,
        paging: true,
        "bInfo" : false,
        lengthChange: false,
        pageLength: 5,
        info: true,
        orderable: true*/
        "order": [[ 0, "desc" ]]
    });
</script>

@stop