@extends('layouts.master')

@section('style')
    <link href="{{URL::asset('assets/css/jquery.datetimepicker.css')}}" rel="stylesheet" type="text/css"/>
    

    <style type="text/css">
        .cls-overflow{
            height: 800px;
            overflow: scroll;
        }

        .cls-overflow-one{
            height: 200px;
            overflow: scroll;
        }
        .info-box {
            display: block;
            min-height: 90px;
            background: #fff;
            width: 100%;
            box-shadow: 0 1px 1px rgba(0,0,0,0.1);
            border-radius: 2px;
            margin-bottom: 15px;
        }
        .info-box-icon {
            border-top-left-radius: 2px;
            border-top-right-radius: 0;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 2px;
            display: block;
            float: left;
            height: 90px;
            width: 90px;
            text-align: center;
            font-size: 45px;
            line-height: 90px;
            background: rgba(0,0,0,0.2);
        }
        .info-box-content {
            padding: 5px 10px;
            margin-left: 90px;
        }
        .info-box-text {
            text-transform: uppercase;
        }
        .progress-description, .info-box-text {
            display: block;
            font-size: 14px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .info-box-number {
            display: block;
            font-weight: bold;
            font-size: 18px;
        }
        .bg-success{
            background-color: #00a65a !important;
            color: #fff;
        }
        .ng-red{
            background-color: #dd4b39 !important;
        }
    </style>
@endsection

@section('content')
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
<!-- Main content -->
<section class="content">
    <!-- Main row -->
    <div class="row">
        <div class="col-md-12">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
                <div class="info-box">
                    <span class="info-box-icon bg-aqua"><i class="fa fa-users"></i></span>
    
                    <div class="info-box-content">
                      <span class="info-box-text">Total Client</span>
                      <span class="info-box-number">{{ $clients }}</span>
                    </div>
                <!-- /.info-box-content -->
              </div>
            </div>
    
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
                <div class="info-box">
                    <span class="info-box-icon bg-success"><i class="fa fa-info"></i></span>
    
                    <div class="info-box-content">
                      <span class="info-box-text">Monthly Invoice</span>
                      <span class="info-box-number">{{ $ttl_invoice }}</span>
                    </div>
                <!-- /.info-box-content -->
              </div>
            </div>
    
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
                <div class="info-box">
                    <span class="info-box-icon bg-red"><i class="fa fa-info"></i></span>
    
                    <div class="info-box-content">
                      <span class="info-box-text">Monthly Overdue Invoice</span>
    
                      <span class="info-box-number"><a href="{{ url('invoice?code=&status=0&counsellor=&client=&overdue=true') }}" title='View All'>{{ $ttl_due_invoice }}</a></span>
                    </div>
                <!-- /.info-box-content -->
              </div>
            </div>
            </div>
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
                <div class="info-box">
                    <span class="info-box-icon bg-red"><i class="fa fa-money"></i></span>
    
                    <div class="info-box-content">
                      <span class="info-box-text">All Time Due</span>
                      <?php
                        $new_due=(float) $dues;
                      ?>
                      <span class="info-box-number">{{ number_format($new_due, 2) }}</span>
                    </div>
                <!-- /.info-box-content -->
              </div>
            </div>
    
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
                <div class="info-box">
                    <span class="info-box-icon bg-success"><i class="fa fa-money"></i></span>
                    <?php
                        $new_collection=(float) $monthly_collected;
                    ?>
                    <div class="info-box-content">
                      <span class="info-box-text">Received This Month</span>
                      <span class="info-box-number">{{ number_format($new_collection, 2) }}</span>
                    </div>
                <!-- /.info-box-content -->
              </div>
            </div>
    
            <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
                <div class="info-box">
                    <span class="info-box-icon bg-red"><i class="fa fa-money"></i></span>
    
                    <div class="info-box-content">
                      <span class="info-box-text">Invoiced This Month</span>
                      <?php
                        $new_month_due=(float) $all_month_due;
                      ?>
                      <span class="info-box-number">{{ number_format($new_month_due, 2) }}</span>
                    </div>
                <!-- /.info-box-content -->
              </div>
            </div>
            </div>
            
            <div class="row">
                <div class="col-md-8">
                    <div class="panel panel-default">
                      <div class="panel-heading">
                        <h3 class="panel-title">Income Expense Report</h3>
                      </div>
                      <div class="panel-body">
                          <div class="chart">
                           <canvas id="lineChart" style="height:250px"></canvas>
                          </div>
                      </div>
                  </div>
                </div>
                <div class="col-md-4">
                   <div class="panel panel-default">
                  <div class="panel-heading">
                    <h3 class="panel-title">Balance</h3>
                  </div>
                  <div class="panel-body">
                  @if($banks !='')
                      <table class="table table-striped">
                        <thead>
                          <tr>
                            <th class="text-center">Name</th>
                            <th class="text-center">Amount</th>
                          </tr>
                        </thead>
                        <tbody>
                    @foreach($banks as $bank)
                            <tr>
                                    <td>{{ $bank['bank_name'] }}</td>
                                    <td class="text-center">{{ number_format($bank['balance'], 2) }}</td>
                            </tr>
                    @endforeach
                        </tbody>
                      </table>
                      @else
                   <h2>{{ "No Records Found" }}</h2>
                      @endif
                  </div>
              </div>
                </div>
            </div>
            
            
            <style>
                #sortable { list-style-type: none; margin-top:2%; height: auto }
                #sortable .test {padding: 0.4em; padding-left: 1.5em;  height: auto;margin:2%;background:#fff }
                #sortable .test span { margin-left: -1.3em;margin-top:2%;
                text-transform: uppercase; }
                    #save{
                        cursor: pointer;
                    }
            </style>
            <?php
                /*
            ?>
            @foreach($all as $info)
            <div class="col-md-6" id="sortable">
                <section class="panel tasks-widget">
                    <header class="panel-heading text-center">
                        {{$info->name}}
                    </header>
                    <header class="panel-heading text-center" style="background:#d9534f;margin-top:2%;color:#fff">
                        Deadline Missed
                    </header>
                    <?php 
                        $missed = App\Models\Task::where('user_id',$info->id)->where('status','!=',6)->whereDay('dead_line', '<=', date('d'))->get();
                    ?>
                    @if(count($missed) > 0)
                        @foreach($missed as $p) 
                            <li class="test ui-state-default">
                                <span class="task-color">{{$p->name}}</span> 
                               (Assign: {{date("d-m-Y H:i", strtotime($p->assign_time))}} # Estimated: {{$p->estimated_time}} )
                            </li>
                        @endforeach
                    @endif
                    
                    <header class="panel-heading text-center" style="background:#f0ad4e;margin-top:2%;color:#fff">
                        Deadline Today
                    </header>
                    <?php 
                        $deadline_today = App\Models\Task::where('user_id',$info->id)->where('status','!=',6)->whereDate('dead_line', '=', date('Y-m-d'))->get();
                    ?>
                    @if(count($deadline_today) > 0)
                        @foreach($deadline_today as $p) 
                            <li class="test ui-state-default">
                                <span class="task-color">{{$p->name}}</span> 
                               (Assign: {{date("d-m-Y H:i", strtotime($p->assign_time))}} # Estimated: {{$p->estimated_time}} )
                            </li>
                        @endforeach
                    @endif
                    <header class="panel-heading text-center" style="background:#d9534f;margin-top:2%;color:#fff">
                        Pending Task
                    </header>
                    <?php 
                        $pen = App\Models\Task::where('user_id',$info->id)->where('status',1)->get();
                    ?>
                    @if(count($pen) > 0)
                        @foreach($pen as $p) 
                            <li class="test ui-state-default">
                                <span class="task-color">{{$p->name}}</span> 
                               (Assign: {{date("d-m-Y H:i", strtotime($p->assign_time))}} # Estimated: {{$p->estimated_time}} )
                            </li>
                        @endforeach
                    @endif
                    <header class="panel-heading text-center" style="background:#31b0d5;margin-top:2%;color: #fff">
                        In Progress
                    </header>
                    <?php 
                        $in_proecss = App\Models\Task::where('user_id',$info->id)->where('status',2)->get();
                    ?>
                    @if(count($in_proecss) > 0)
                        @foreach($in_proecss as $p)
                            <li class="test ui-state-default">
                                <span class="task-color">{{$p->name}}</span> 
                               (Assign: {{date("d-m-Y H:i", strtotime($p->assign_time))}} # Estimated: {{$p->estimated_time}} )
                            </li>
                        @endforeach
                    @endif
                    <header class="panel-heading text-center" style="background:#449d44;margin-top:2%;color: #fff">
                        Completed
                    </header>
                    <?php 
                        $completed = App\Models\Task::where('user_id',$info->id)
                            ->where('status',6)->whereDate('closing_time', '=', date('Y-m-d'))->get();
                    ?>
                    @if(count($completed) > 0)
                        @foreach($completed as $p)
                            <li class="test ui-state-default">
                                <span class="task-color">{{$p->name}}</span> 
                               (Assign: {{date("d-m-Y H:i", strtotime($p->assign_time))}} # Estimated: {{$p->estimated_time}} )
                            </li>
                        @endforeach
                    @endif
                    <header class="panel-heading text-center" style="background:#449d44;margin-top:2%;color: #fff">
                        Completed Yesterday
                    </header>
                    <?php 
                        $completed_yes = App\Models\Task::where('user_id',$info->id)
                            ->where('status',6)->whereDate('closing_time', '!=', date('Y-m-d'))->get();
                    ?>
                    @if(count($completed_yes) > 0)
                        @foreach($completed_yes as $p)
                            <li class="test ui-state-default">
                                <span class="task-color">{{$p->name}}</span> 
                               (Assign: {{date("d-m-Y H:i", strtotime($p->assign_time))}} # Estimated: {{$p->estimated_time}} )
                            </li>
                        @endforeach
                    @endif
                </section>
            </div>
            @endforeach
            <?php
                */
            ?>
        </div>
        
        <!--
        <?php 
            
        ?>
        <?php
            if(!empty($all1)){
        ?>
        <div class="col-md-12">
            <section class="panel tasks-widget">
                <header class="panel-heading text-center" style="background:#fff;margin-top:2%;color:#333">
                    Vendors's Work Today
                </header>
            </section>
            @foreach($all1 as $info1)
            <div class="col-md-6" id="sortable">
                <section class="panel tasks-widget">
                    <header class="panel-heading text-center">
                        {{$info1->name}}
                    </header>
                    <?php 
                        $pen1 = App\Models\Task::where('user_id',$info1->id)->where('status',1)->get();
                    ?>
                    @if(count($pen1) != 0)
                        <header class="panel-heading text-center" style="background:#d9534f;margin-top:2%;color:#fff">
                            Pending Task
                        </header>
                        @foreach($pen1 as $p1) 
                            <li class="test ui-state-default">
                                <span class="task-color">{{$p1->name}}</span> 
                               (Assign: {{date("d-m-Y H:i", strtotime($p1->assign_time))}} # Estimated: {{$p1->estimated_time}} )
                            </li>
                        @endforeach
                    @endif
                    <?php 
                        $in_proecss1 = App\Models\Task::where('user_id',$info1->id)->where('status',2)->get();
                    ?>
                    @if(count($in_proecss1) != 0)
                    <header class="panel-heading text-center" style="background:#31b0d5;margin-top:2%;color: #fff">
                        In Progress
                    </header>
                    
                        @foreach($in_proecss1 as $p1)
                            <li class="test ui-state-default">
                                <span class="task-color">{{$p1->name}}</span> 
                               (Assign: {{date("d-m-Y H:i", strtotime($p1->assign_time))}} # Estimated: {{$p1->estimated_time}} )
                            </li>
                        @endforeach
                    @endif
                    <?php 
                        $completed1 = App\Models\Task::where('user_id',$info1->id)
                            ->where('status',3)->whereDate('closing_time', '=', date('Y-m-d'))->get();
                    ?>
                    @if(count($completed1) != 0)
                        <header class="panel-heading text-center" style="background:#449d44;margin-top:2%;color: #fff">
                            Completed
                        </header>
                        @foreach($completed1 as $p1)
                            <li class="test ui-state-default">
                                <span class="task-color">{{$p1->name}}</span> 
                               (Assign: {{date("d-m-Y H:i", strtotime($p1->assign_time))}} # Estimated: {{$p1->estimated_time}} )
                            </li>
                        @endforeach
                    @endif
                </section>
            </div>
            @endforeach
        </div>
        <?php
            }
        ?>
    </div>
    
    <div class="row">
        <div class="col-md-6">
            <section class="panel tasks-widget">
                <header class="panel-heading">
                    In-Process Task
                </header>
                <div class="cls-overflow table-responsive project-list">
                    <table class="table table-striped">
                        
                        <tbody>
                            @if(!empty($in_process_task))
                                <?php $count=1; ?>
                                @foreach($in_process_task as $pt)
                                    <tr>
                                        <td>
                                            {{$count++ .") "}}
                                            <a style="color: #1ab394;" href="{{url("admin/project_details/$pt->proj_id")}}">
                                                {{$pt->name}} - 
                                            </a>
                                            <span style="color:green;">
                                                {{@$pt->proj_name->name}} - 
                                            </span>

                                            <span style="color:red;">
                                            @if(!empty($pt->user->name))
                                                {{$pt->user->name}}
                                            @else
                                                {{"Not assigned"}}
                                            @endif
                                            </span> - 
                                        
                                            {{date("d-m-Y H:i", strtotime($pt->start_time))}} # {{$pt->estimated_time}}
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                        </tbody>
                    </table>
                    <hr>
                    </hr>
                </div>
                <div class="panel-body">
                    <div class=" add-task-row">
                    </div>
                    <div class="table-foot">
                       
                    </div>
                </div>
            </section>
        </div>
        <div class="col-md-6">
            <section class="panel tasks-widget">
                <header class="panel-heading">
                   Completed Today
                </header>
                <div class="cls-overflow table-responsive project-list">
                    <table class="table table-striped">
                        
                        <tbody>
                            @if(!empty($pending_task))
                                <?php $count = 1; ?>
                                @foreach($pending_task as $pt)
                                    <tr>
                                        <td>
                                            {{$count++ .") "}}
                                            <a style="color: #1ab394;" href="{{url("admin/project_details/$pt->proj_id")}}">
                                            {{$pt->name}}
                                            </a> - 
                                            <span style="color: green;">
                                                {{$pt->proj_name?$pt->proj_name->name:''}} - 
                                            </span>
                                            <span style="color:red;">
                                            @if($pt->user)
                                            @if(!empty($pt->user->name))
                                                {{$pt->user->name}} - 
                                            @else
                                                <span style="color:#FF6000;">
                                                {{"Not assigned"}} - 
                                                </span>
                                            @endif
                                            @endif
                                            </span>
                                        
                                            {{date("d-m-Y H:i", strtotime($pt->closing_time))}}
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                        </tbody>
                    </table>
                    <hr>
                    </hr>
                </div>
                <div class="panel-body">
                    <div class=" add-task-row">
                    </div>
                    <div class="table-foot">
                       
                    </div>
                </div>
            </section>
        </div>
    </div>-->
    
</section>
<!-- row end -->
<!-- /.content -->


<!-- Add note modal -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
     <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 User</h4>
          </div>
          <div class="modal-body">

            <form role="form" action="{{url('admin/add_note')}}" method="POST">
                {!! csrf_field() !!}
                <div class="form-group">
                    <label for="Add new Project">
                        Note
                    </label>
                    <textarea name="note" rows="5" class="form-control" id="new-project" placeholder="Write down your important notes..." ></textarea>
                </div>
                <div class="form-group">
                    <label for="Add new Project">
                        Select Date Time
                    </label>
                    <input name="date_time" class="form-control" id="datetimepicker" type="text">
                </div>
                <div class="form-group">
                    <button class="btn btn-info" type="submit">
                    Submit
                    </button>
                </div>
            </form> 
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div> 
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<!-- Modal assign task -->
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg">
        <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">Assign Task</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                <script src="{{URL::asset('assets/ckeditor/ckeditor.js')}}"></script>
                    <div class="col-md-7">
                        <b>Assinged users:</b> 
                        <div class="assinged-users">
                            
                        </div>
                    </div>
                    <div class="col-md-5">
                    

                        <input type="hidden" name="id_task_id" id="id_task_id" value="">
                        
                        <div class="form-group">
                            <label for="Add new Project">
                                User
                            </label>
                            <select name="user_id" id="id_user_id" class="form-control cls-proj-user">
                                
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="Add new Project">
                                Estimated Time
                            </label>
                            <br>
                            <input type="text" id="id_estimated_time" name="estimated_time" class="form-control">
                            
                        </div>

                        <div class="form-group">
                            <button class="btn btn-primary assign-task-user">Assign</button>
                        </div>
                    
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div style="margin-bottom:10px;">
                            <b>Details:</b> <span class="cls-task-details"></span>
                        </div>
                        <textarea class="form-control" name="comment_txt" id="comment_txt" cols="" rows="2" placeholder="Post comment here"></textarea>
                        <button class="btn btn-success add-task-comment" style="margin-top:5px;">Post Comment</button>
                        <button class="btn btn-success add-task-comment-doc" style="margin-top:5px;" data-toggle="modal" data-target="#add_doc_task_modal">Attach Documnet</button>
                        <br><br>
                        <b>Comments:</b><br>
                        <div class="comments-cls"  style="height:400px;overflow:scroll;">
                            
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                    <br/>
                    <b>Activity Logs:</b><br>
                        <div class="show-logs" style="height:150px;overflow:scroll;">
                            
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <div class="row">
                    <div class="col-md-10">
                        Change status to: 
                        <button data-id='2' class="btn btn-primary cls-change-created btn-xs">In-process</button>
                        <span class="show-change-btn">
                            <button data-id='3' class="btn btn-primary cls-change-created btn-xs">Completed</button>
                            <button data-id='4' class="btn btn-primary cls-change-created btn-xs">Checking</button>
                            <button data-id='5' class="btn btn-primary cls-change-created btn-xs">Bug-fixing</button>
                            <button data-id='6' class="btn btn-primary cls-change-created btn-xs">Done</button>    
                        </span>
                    </div>
                    <div class="col-md-2">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Assign task finished -->

@endsection

@section('script')
    <script src="{{URL::asset('assets/js/jquery.datetimepicker.full.min.js')}}" type="text/javascript"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        //jQuery('#datetimepicker').datetimepicker();
    $('.bs-example-modal-lg').on('shown.bs.modal', function () {
            datePicker1();
        });
  
        function datePicker1(){
            $( "#id_estimated_time" ).datetimepicker({
            });
        }
        jQuery('#datetimepicker').datetimepicker({
          format:'Y-m-d H:i:s',
          lang:'ru'
        });

        $(document).ready(function() {
            var timeout = setTimeout("location.reload(true);",600000);
            function resetTimeout() {
                clearTimeout(timeout);
                timeout = setTimeout("location.reload(true);",600000);
            }
            $('.cls-assign').click(function(event)
        {
            var proj_id = $('.cls-project-id').val();
            var task_id = $(this).data('task_id');
            $('#id_task_id').val(task_id);
    
            $.ajax({
                    url: "{{url('admin/user_list_for_task_assign')}}",
                    type: 'POST',
                    data: {proj_id: proj_id, task_id: task_id},
                })
                .done(function(data) {
                    var status = data[4];
                    if(status > 1)
                    {
                        $('.show-change-btn').show();
                    }
                    else{
                        $('.show-change-btn').hide();
                    }
    
                    $('.cls-proj-user').html(data[0]);
                    $('.assinged-users').html(data[1]);
                    $('.show-logs').html(data[2]);
                    $('.comments-cls').html(data[3]);
                    $('.cls-task-details').html(data[5]);
                    $('#id_estimated_time').val(data[6]);
                });
                    
        });
    
        $('.assign-task-user').click(function(event)
        {
            //url('admin/task_assign_to_user')
            //var id_estimated_time = $('#id_estimated_time').val();
            var id_estimated_time = $('#id_estimated_time').val();
            //var min = $('#id_estimated_time_min').val();
            //var id_estimated_time = hours+":"+min+":00";
            
            var id_user_id = $('#id_user_id').val();
            var id_task_id = $('#id_task_id').val();
            
            if(id_estimated_time !=''){
                $.ajax({
                    url: "{{url('admin/task_assign_to_user')}}",
                    type: 'POST',
                    data: {id_estimated_time: id_estimated_time,id_user_id: id_user_id,id_task_id: id_task_id},
                })
                .done(function(data) {
                    $('.assinged-users').html(data);
                });
            }
            else{
                alert('Please define time estimate!');
            }
            
        });
    
    
        $('.assinged-users').on('click','.remove-task-assign-user',function(){
    
            var id = $(this).prev('input').val();
            var task_id = $('#id_task_id').val();
    
            $.ajax({
                url: "{{url('admin/remove_assign_task_user')}}",
                type: 'POST',
                data: {id: id,task_id: task_id},
            })
            .done(function(data) {
                $('.assinged-users').html(data);
            });
    
        });
    
        $('.add-task-comment').click(function(event) {
            
            var comment = $('#comment_txt').val();
            var task_id = $('#id_task_id').val();
    
            if(comment.length > 0){
                $.ajax({
                    url: "{{url('admin/add_task_comment')}}",
                    type: 'POST',
                    data: {comment: comment,task_id: task_id},
                })
                .done(function(data) {
                    
                    $('.comments-cls').html(data);
                });
            }
            else{
                alert('Please fill-up comment field.');
            }
            
        });
        $('.comments-cls').on('click','.edit_comment',function(){
        
            var id = $(this).data('id');
            
            $.ajax({
                url: '{{url('admin/edit_comment_form')}}',
                type: 'POST',
                data: {id: id},
            })
            .done(function(data) {
                $('.modal-edit').modal('show');
                $('.update-comment').val(data['comment']);
                $('.update-comment-id').val(data['id']);
            });
            
        });
    
        $('.comments-cls').on('click','.remove_comment',function(){
            
            var id = $(this).data('id');
            var task_id = $('#id_task_id').val();
    
            $.ajax({
                url: "{{url('admin/remove_comment')}}",
                type: 'POST',
                data: {id: id,task_id: task_id},
            })
            .done(function(data) {
                $('.comments-cls').html(data);
            }); 
        });
    
        $('.save-updated-comment').click(function(event) {
            
            var id = $('.update-comment-id').val();
            var comment = $('.update-comment').val();
            var task_id = $('#id_task_id').val();
    
            $.ajax({
                url: '{{url('admin/save_update_comment')}}',
                type: 'POST',
                data: {id: id,comment: comment,task_id: task_id},
            })
            .done(function(data) {
                $('.modal-edit').modal('hide');
                $('.comments-cls').html(data);
                $('.update-comment').val('');
                alert('Data updated successfully!');
            });
            
        });
    
        $('.cls-change-created').click(function(event)
        {
            if(confirm("Are you sure you want to change status ?")) 
            {
                var task_id = $('#id_task_id').val();
                var status = $(this).data('id');
                
                
                $.ajax({
                    url: "{{url('admin/change_to_process')}}",
                    type: 'POST',
                    data: {task_id: task_id, status: status},
                })
                .done(function(data) {
                    
                    if(data == 'Yes'){
                        alert('Status Changed !!');
                        location.reload();
                    }
                    else{
                        alert('Status Not Changed !!');
                    }
                });
                
            }
        });
    
        $('.upload-cls').click(function(event)
        {        
            var id = $('.cls-project-id').val();
            $('.cls-proj-id').val(id);
        });
    
        $('.cls-pm').click(function(event) {
            
            var id = $(this).val();
            var pm_status;
    
            if($(this).attr('checked')){
                pm_status = 1 ; //check
            }
            else{
                pm_status = 0 ; //uncheck
            }
    
            $.ajax({
                url: "{{url('admin/make_pm')}}",
                type: 'POST',
                data: {id: id,pm_status: pm_status},
            })
            .done(function(data) {
                alert(data);
            });
            
        });
    
        $('.add-task-comment-doc').click(function(event) {
            var task_id = $('#id_task_id').val();
            $('.cls-task-doc-id').val(task_id);
        });
    
        $('.attatch-close-btn').click(function(event) {
            
            location.reload();
        });
    
        $('.attatchment-doc-comment').click(function(event) {
            
            //this event only for fetch the comments after close 
            //attatchemnt dropzone.
            var comment = '';
            var task_id = $('#id_task_id').val();
    
            $.ajax({
                url: "{{url('admin/add_task_comment')}}",
                type: 'POST',
                data: {comment: comment,task_id: task_id},
            })
            .done(function(data){
                
                $('.comments-cls').html(data);
            });        
        });
        });
        $(document).ready(function() {
            var timeout = setTimeout("location.reload(true);",600000);
            function resetTimeout() {
                clearTimeout(timeout);
                timeout = setTimeout("location.reload(true);",600000);
            }


            new Chart(document.getElementById("lineChart"), {
                type: 'bar',
                data: {
                  labels: ["January", "February", "March", "April", "May", "June", "July","August","September","October","November","December"],
                  datasets: [
                    {
                      label: "Income",
                      backgroundColor: "#3e95cd",
                      data: {{ $revenue_amount }}
                    }, {
                      label: "Expense",
                      backgroundColor: "#8e5ea2",
                      data: {{ $exp_amount }}
                    }
                  ]
                },
                options: {
                  title: {
                    display: true,
                    text: 'Income Expense Report'
                  }
                }
            }); 
            
        });
    </script>
@endsection
