@extends('layouts.master')

@section('content')
<!-- Main content -->
<section class="content">
    <!-- Main row -->
    <div class="row">
        <div class="col-md-12">
            <section class="panel tasks-widget">
                <header class="panel-heading" style="height:40px;">
                    <div class="pull-left">
                        {{$title}}
                    </div>
                    <div>
                        <button class="btn btn-success btn-xs pull-right" data-toggle="modal" data-target=".add-modal">Add company</button>
                    </div>
                </header>
                <div class="table-responsive project-list" style="padding: 10px;">

                @if(Session::has('msg'))
                    {{Session::get('msg')}}
                @endif
                    <table class="table table-bordered" id="example" style="border: 1px solid #dee2e6" >
                        <caption class='text-left' style='padding-left:10px;'>
                        <br>
                        <form action="{{ url('admin/companies') }}" method="GET" class='form-inline'>
                            <input type="text" style='width:200px;' name="cname" id="cname" placeholder="Company Name" class="form-control" value="{{ $cname }}"> 
                            <button type="submit" class='btn btn-info'><i class="fa fa-search"></i></button>
                        </form>
                            <br>
                        </caption>
                        <thead>
                            <tr style="background: #f8f9fa;height: 40px">
                                <th width="15%">
                                    Company Name
                                </th>
                                <th width="25%">
                                    Contact Info
                                </th>
                                <th class="text-center" width="15%">
                                    To Do List
                                </th>
                                <th width="25%">
                                    Address &amp; Remarks
                                </th>
                                <th width="10%">
                                    Status
                                </th>
                                <th width="10%">
                                    Action
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                        @if (session('data'))
                            <div class="alert alert-success">
                                {{ session('data') }}
                            </div>
                        @endif
                        @if($all)
                            @foreach($all as $info)
                            <tr>
                                <td>{{$info->name}}</td>
                                <td>
                                    @if(!empty($info->web)) <b>Website: </b>{{$info->web}}<br> @endif
                                    <b>Mob#01: </b>{{$info->mob1}}<br>
                                    <b>Email#01: </b>{{$info->email1}}<br>
                                </td>
                                <?php 
                                    $ary_industry = [
                                                        1=>"Recreation",2=>"Food",3=>"Training",
                                                        4=>"Professionals",5=>"Industry",6=>"Agriculture",7=>"Germents",8=>"Health",9=>"Apperal",10=>"E-Commerce"
                                                    ];
                                    $ary_service = [
                                                    1=>"All", 2=>"Mobile App", 3=>"Website", 4=>"Software"
                                                    ];
                                    $ary_condition =[ 1=>"N/A", 2=>"Bad", 3=>"Excellent"];
                                ?>
                                <td class="text-center">
                                    @if(@$info->mtask['task_type']==1)
                                    <label class="label label-success text-center">New Task created</label>

                                    {{-- <b>{{$info->mtask['name']}} </b>-{!! $info->mtask['description'] !!} --}}
                                    @elseif(@$info->mtask['task_type']==2)
                                    <label class="label label-info text-center">Appointment created</label>
                                    @elseif(@$info->mtask['task_type']==3)
                                    <label class="label label-danger text-center">New Call</label>
                                    @elseif(@$info->mtask['task_type']==4)
                                    <label class="label label-primary text-center">email Sent</label>
                                    @endif
                                </td>
                                <td>
                                    <b>Details:</b>{{$info->details or 'NA'}}<br>
                                    <b>Address:</b>{{$info->address or 'NA'}}<br>
                                    <b>Remarks:</b>{{$info->remarks or 'NA'}}<br>
                                </td>
                                <td>
                                    <select name="status" data-company='{{ $info->id }}' class='ddl_status' id="status">
                                        <option {{ $info->status==0?'selected':'' }} value="0">Enlisted</option>
                                        <option {{ $info->status==1?'selected':'' }} value="1">Approached</option>
                                        <option {{ $info->status==2?'selected':'' }} value="2">Client</option>
                                    </select>
                                </td>
                                <td>
                                    <input type="hidden" id="proj_id" value="{{$info->id}}">

                                    <div class="btn-group">
                                      <button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                        Action <span class="caret"></span>
                                      </button>
                                      <ul class="dropdown-menu">
                                        <li>
                                         <a href='' title='Edit Company' data-toggle="modal" data-target=".edit-company">
                                            <i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit
                                        </a>
                                        </li>
                                        <li>
                                        <a href="{{url("admin/view_company/$info->id")}}" title='View Company' target="_blank">
                                            <i class="fa fa-eye" aria-hidden="true"></i> View
                                        </a>
                                        </li>
                                        <li>
                                            <a href="#" class='lnkAssignService' data-company_id='{{ $info->id }}' data-company_name='{{ $info->name }}' title='Add Service'>
                                                <i class="fa fa-plus-circle" aria-hidden="true"></i> Add Service
                                            </a>
                                        </li>
                                        <li role="separator" class="divider"></li>
                                        <li>
                                            <a onclick="return confirm ('want to delete?')" title='Delete Company' href="{{url("admin/companies/$info->id")}}">
                                                <i class="fa fa-times" aria-hidden="true"></i> Delete
                                            </a>
                                        </li>
                                      </ul>
                                    </div>
                                   
                                </td>
                            </tr>
                            @endforeach
                        @else
                        <tr>
                            <td colspan="6" class="text-center">No Data Found !!</td>
                        </tr>
                        @endif
                        </tbody>
                    </table>
                    <hr>
                    </hr>
                </div>
                <div class="panel-body">
                    <div class=" add-task-row">
                    </div>
                    <div class="table-foot">
                        {{ $all->appends(['cname'=>$cname])->links() }}
                    </div>
                </div>
            </section>
        </div>
    </div>
</section>
<!-- row end -->
<!-- /.content -->


<!-- Modal Add Company -->
<div class="modal fade add-modal" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
  <div class="modal-dialog" role="document">
    <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="gridSystemModalLabel">Add Company Info</h4>
      </div>
      <div class="modal-body">

        <form action="{{url('admin/companies')}}" method="POST">

            {{ csrf_field() }}
            <div class="form-group in-group">
                <label for="">Company name<span class="field_mendatory">*</span></label>
                <input type="text" name="name" required="" class="form-control" id="" placeholder="Company name" >
            </div>
            <div class="form-group in-group">
                <label for="">Industry<span class="field_mendatory">*</span></label>
                <select class="form-control" name="industry" id="industry">
                    <option value="1">Recreation</option>
                    <option value="2">Food</option>
                    <option value="3">Training</option>
                    <option value="4">Professionals</option>
                    <option value="5">Instutes</option>
                    <option value="6">Agriculture</option>
                    <option value="7">Germents</option>
                    <option value="8">Health</option>
                    <option value="9">Apperal</option>
                    <option value="10">E-Commerce</option>
                </select>
            </div>
            <div class="form-group in-group">
                <label for="">Service Required<span class="field_mendatory">*</span></label>
                <select class="form-control" name="service_required" id="service_required">
                    <option value="1">All</option>
                    <option value="2">Mobile App</option>
                    <option value="3">Website</option>
                    <option value="4">Software</option>
                </select>
            </div>
            <div class="form-group in-group">
                <label for="">Current Condition<span class="field_mendatory">*</span></label>
                <select class="form-control" name="current_condition" id="current_condition">
                    <option value="1">N\A</option>
                    <option value="2">Bad</option>
                    <option value="3">Excellent</option>
                </select>
            </div>
            <div class="form-group in-group">
                <label for="">Mobile no #01<span class="field_mendatory">*</span></label>
                <input type="text" name="mob1" required="" class="form-control" id="" placeholder="Mobile number" >
            </div>
            <div class="form-group in-group">
                <label for="">Mobile no #02</label>
                <input type="text" name="mob2" class="form-control" id="" placeholder="Optional mobile number" >
            </div>
            <div class="form-group in-group">
                <label for="">Email #01<span class="field_mendatory">*</span></label>
                <input type="email" name="email1" required="" class="form-control" id="" placeholder="Email address" >
            </div>
            <div class="form-group in-group">
                <label for="">Email #02</label>
                <input type="email" name="email2" class="form-control" id="" placeholder="Optional email address" >
            </div>
            <div class="form-group in-group">
                <label for="">Website</label>
                <input type="text" name="web" class="form-control" id="" placeholder="Company website" >
            </div>
            <div class="form-group in-group">
                <label for="">Details</label>
                <textarea type="text" name="details" class="form-control" id="" placeholder="Details" ></textarea>
            </div>
            <div class="form-group in-group">
                <label for="">Address</label>
                <textarea type="text" name="address" class="form-control" id="" placeholder="Company address" ></textarea>
            </div>
            <div class="form-group in-group">
                <label for="">Remarks</label>
                <textarea type="text" name="remarks" class="form-control" id="remarks" placeholder="Company remarks" ></textarea>
            </div>
            <div class="form-group in-group">
                <input type="checkbox" checked="checked" name="display" value="1"> Display company info.
            </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
      </form>  
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!-- Modal Edit Company -->
<div class="modal fade edit-company" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
  <div class="modal-dialog" role="document">
    <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="gridSystemModalLabel">Edit Company Info</h4>
      </div>
      <div class="modal-body">

        <form action="{{url('admin/update_company')}}" method="POST">

            {{ csrf_field() }}
            <input type="hidden" name="id" value="" id="id">

            <div class="form-group in-group">
                <label for="">Company name<span class="field_mendatory">*</span></label>
                <input type="text" name="name" required="" class="form-control" id="name" placeholder="Company name" >
            </div>
            <div class="form-group in-group">
                <label for="">Industry<span class="field_mendatory">*</span></label>
                <select class="form-control" name="industry" id="industry">
                    <option value="0">Select industry</option>
                    <option value="1">Recreation</option>
                    <option value="2">Food</option>
                    <option value="3">Training</option>
                    <option value="4">Professionals</option>
                    <option value="5">Instutes</option>
                    <option value="6">Agriculture</option>
                    <option value="7">Germents</option>
                    <option value="8">Health</option>
                    <option value="9">Apperal</option>
                    <option value="10">E-Commerce</option>
                </select>
            </div>
            <div class="form-group in-group">
                <label for="">Service Required<span class="field_mendatory">*</span></label>
                <select class="form-control" name="service_required" id="service_required">
                    <option value="1">All</option>
                    <option value="2">Mobile App</option>
                    <option value="3">Website</option>
                    <option value="4">Software</option>
                </select>
            </div>
            <div class="form-group in-group">
                <label for="">Current Condition<span class="field_mendatory">*</span></label>
                <select class="form-control" name="current_condition" id="current_condition">
                    <option value="1">N\A</option>
                    <option value="2">Bad</option>
                    <option value="3">Excellent</option>
                </select>
            </div>
            <div class="form-group in-group">
                <label for="">Mobile no #01<span class="field_mendatory">*</span></label>
                <input type="text" name="mob1" required="" class="form-control" id="mob1" placeholder="Mobile number" >
            </div>
            <div class="form-group in-group">
                <label for="">Mobile no #02</label>
                <input type="text" name="mob2" class="form-control" id="mob2" placeholder="Optional mobile number" >
            </div>
            <div class="form-group in-group">
                <label for="">Email #01<span class="field_mendatory">*</span></label>
                <input type="email" name="email1" required="" class="form-control" id="email1" placeholder="Email address" >
            </div>
            <div class="form-group in-group">
                <label for="">Email #02</label>
                <input type="email" name="email2" class="form-control" id="email2" placeholder="Optional email address" >
            </div>
            <div class="form-group in-group">
                <label for="">Website</label>
                <input type="text" name="web" class="form-control" id="web" placeholder="Company website" >
            </div>
            <div class="form-group in-group">
                <label for="">Details</label>
                <textarea type="text" name="details" class="form-control" id="details" placeholder="Details" ></textarea>
            </div>
            <div class="form-group in-group">
                <label for="">Address</label>
                <textarea type="text" name="address" class="form-control" id="address" placeholder="Company address" ></textarea>
            </div>
            <div class="form-group in-group">
                <label for="">Remarks</label>
                <textarea type="text" name="remarks" class="form-control" id="remarks" placeholder="Company remarks" ></textarea>
            </div>
            <div class="form-group in-group">
                <input type="checkbox" name="display" id="display" value="1"> Display company info.
            </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
      </form>  
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!-- service modal -->
@include('admin.company_info.service_modal')
<!-- end service modal -->
@endsection

@section('style')
<style>
    .table thead tr th{
        border: 1px solid #dee2e6 !important;
        color: #3e5569; 
    }
    .table tbody tr td{
        font-size:12px !important;
        font-family:sans-serif;
        font-weight: 400;
        line-height: 1.5;
    }
</style>
@stop


@section('script')

<script type="text/javascript">
$(document).ready(function() {
     $( ".date" ).datepicker({
          changeMonth: true,
          changeYear: true,
          dateFormat:"yy-mm-dd"
     });
    

    $('.ddl_status').change(function(){
        var conf=confirm('Are you sure to change the company status ??');
        if(conf)
        {
            var company_id=$(this).data('company');
            var status=$(this).val();
            var token='{{ csrf_token() }}';
            $.ajax({
                url: '{{ url('admin/change_status') }}',
                type: 'POST',
                data: {id:company_id,status:status,_token:token}
            })
            .done(function(res) {

                alert('status changed successfully !!');
              
            });
            
        }
    });

    $('.edit-btn').click(function(event) {
        
        var id = $(this).prev('input').val();
        
        $.ajax({
            url: "{{url("admin/companies")}}/"+id+"/edit",
            type: 'GET',
        })
        .done(function(data) {
            $('#id').val(data['id']);
            $('#name').val(data['name']);
            var industry = data['industry'];
            $("#industry option[value='"+industry+"']").prop('selected', true);
            var service_req = data['service_required'];
            $("#service_required option[value='"+service_req+"']").prop('selected', true);
            var current_con = data['current_condition'];
            $("#current_condition option[value='"+current_con+"']").prop('selected', true);
            $('#mob1').val(data['mob1']);
            $('#mob2').val(data['mob2']);
            $('#email1').val(data['email1']);
            $('#email2').val(data['email2']);
            $('#web').val(data['web']);
            $('#details').val(data['details']);
            $('#address').val(data['address']);
            $('#remarks').val(data['remarks']);
            
            if(data['display']==1){
                $('#display').prop('checked', true);
            }
            else{
                $('#display').prop('checked', false);
            }
        });
    });


    $('body').on('hidden.bs.modal', '.modal', function () {
      $(this).removeData('bs.modal');
    });



    $('.lnkAssignService').click(function(e){

        e.preventDefault();
        var com_id=$(this).data('company_id');
        var com_name=$(this).data('company_name');
        $('span#company_name').text(com_name);
        $('input[name="hdn_com_id"]').val(com_id);

        $('#modalService').modal('show');

    });

    $('#btn_assign_service').click(function(){
        var com_id=$('input[name="hdn_com_id"]').val();
        var service=$('#ddlService').val();
        var contact_person=$('#contact_person').val();
        var contact_number=$('#contact_number').val();
        var deployement_unit=$('#deployement_unit').val();
        var po_details=$('#po_details').val();
        var renewal_cycle=$('#renewal_cycle').val();
        var free_session=$('#free_session').val();
        var start_date=$('#start_date').val();
        var token='{{ csrf_token() }}';
        if(com_id.length==0 || service.length==0){
            $('#spn_msg').text('Service name must be selected !'); 
            return false;
        }

        $.ajax({
            url: '{{ url('admin/company/service/assign') }}',
            type: 'POST',
            dataType: 'json',
            data: {com_id:com_id,service:service,contact_person:contact_person,contact_number:contact_number,deployement_unit:deployement_unit,po_details:po_details,renewal_cycle:renewal_cycle,free_session:free_session,start_date:start_date,_token:token}
        })
        .done(function(res) {
            if(res.ok)
            {
                alert(res.msg);
                $('#modalService').modal('hide');

            }
        });
        
    });


});
   
</script>
@endsection
