
<?= $this->extend('Page_layout') ?>
<?= $this->section('content') ?>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Lookats talent performance</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
            
              <li class="breadcrumb-item active">Lookats talent performance</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">

      <!-- Default box -->
      <div class="card card-warning">
        <div class="card-header">
          <h3 class="card-title">Lookats talent performance</h3>

          <div class="card-tools">
            <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
              <i class="fas fa-minus"></i>
            </button>
            <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
              <i class="fas fa-times"></i>
            </button>
          </div>
        </div>
        <div class="card-body">
          <p> Lookats talent performance filter</p>
         
                <div class="card-body">
                  <div class="form-group row">
                    <label for="names" class="col-sm-2 col-form-label">Talent name</label>
                    <div class="col-sm-4">
                      <input type="text" class="form-control" id="nama" placeholder="Input Name">
                    </div>
                  </div>
                  <div class="form-group row">
                    <label for="names" class="col-sm-2 col-form-label">Year</label>
                    <div class="col-sm-4">
                      <input type="number" class="form-control" id="tahun" placeholder="Input Year">
                    </div>
                  </div>
                
                   <button type="submit" class="btn btn-info search-data">Search</button>
            
                </div>

             <div class="col-12" style="overflow-x:scroll">
             <table id="table-data" style="width:2500px;" class="table table-bordered table-hover">
                  <thead>
                  <tr>
                    <th>Action</th>
                    <th>ID</th>
                    <th>Talent Name</th>
                    <th>Year </th>
                    <th>Month</th>
                    <th>Follower IG</th>
                    <th>Monthly Progress</th>
                    <th>Follower Tiktok</th>
                    <th>Monthly Progress</th>
                    <th>Follower Twitter</th>
                    <th>Monthly Progress</th>
                    <th>Subs Youtube</th>
                    <th>Monthly Progress</th>
                    <th>ER IG %</th>
                    <th>Monthly Progrss</th>
                    <th>ER Tiktok % </th>
                    <th>Monthly. Progress</th>
                    <th>ER Twitter %</th>
                    <th>Monthly Progress</th>
                    <th>ER youtube %</th>
                    <th>Monthly Progress</th>

                 
                    
                  </tr>
                  </thead>
                  <tbody>
                  
                  </tbody>
                 
                </table>
                 </div>
        </div>
        <!-- /.card-body -->
        <div class="card-footer">
           <button type="submit" class="btn btn-danger" data-toggle="modal" data-target="#form-add">Add new</button>
        </div>
        <!-- /.card-footer-->
      </div>
      <!-- /.card -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  </div>
  <?php include('Add_talent_performance.php');?>
  <?php include('edit_talent_performance.php');?>

   <?= $this->endSection() ?> 

  <?=$this->section("scripts")?>
<script src="<?=base_url('public/plugins/jquery-ui/jquery-ui.js')?>"></script>  
<script src="<?=base_url('public/plugins/datatables/jquery.dataTables.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-responsive/js/dataTables.responsive.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-responsive/js/responsive.bootstrap4.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/dataTables.buttons.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/buttons.bootstrap4.min.js')?>"></script>
<script src="<?=base_url('public/plugins/jszip/jszip.min.js')?>"></script>
<script src="<?=base_url('public/plugins/pdfmake/pdfmake.min.js')?>"></script>
<script src="<?=base_url('public/plugins/pdfmake/vfs_fonts.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/buttons.html5.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/buttons.print.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/buttons.colVis.min.js')?>"></script>
<script src="<?=base_url('public/plugins/money-format/simple.money.format.js')?>"></script>
<script src="<?=base_url('public/plugins/moment/moment.min.js')?>"></script>

<script>
  $(function () {

      $(document).on('click','.search-data', function () {
          $("#table-data tbody").html("");
          var $data = {
            'nama' : $("#nama").val(),
            'tahun' : $("#tahun").val()
           
          };
       
         


          $.ajax({
            type: "POST",
            url: "<?= site_url('report/search-performance')?>",
            data: $data,
           
            success: function (response) {
              
             $.each(response.data, function (key, value) { 
             
            
                var body = "<tr>";
              body += "<td><div class=\"btn-group\"><a  class=\"btn btn-info btn-sm edit-btn\">Edit</a>";
              
              body += "<td class=\"data-id\">"+value['PERFORM_ID']+"</td>";
              
              body += "<td>"+value['talent_name']+"</td>";
              body += "<td>"+value['PERFORM_YEAR']+"</td>";
              body += "<td>"+value['PERFORM_MONTH']+"</td>";
              body += "<td>"+value['FW_IG']+"</td>";
              body += "<td>"+value['PROG_IG']+"</td>";
              body += "<td>"+value['FW_TIKTOK']+"</td>";
              body += "<td>"+value['PROG_TIKTOK']+"</td>";
              body += "<td>"+value['FW_TWITTER']+"</td>";
              body += "<td>"+value['PROG_TWITTER']+"</td>";
              body += "<td>"+value['FW_YOUTUBE']+"</td>";
              body += "<td>"+value['PROG_YOUTUBE']+"</td>";
              body += "<td>"+value['ER_IG']+"</td>";
              body += "<td>"+value['ER_PROG_IG']+"</td>";
              body += "<td>"+value['ER_TIKTOK']+"</td>";
              body += "<td>"+value['ER_PROG_TIKTOK']+"</td>";
              body += "<td>"+value['ER_TWITTER']+"</td>";
              body += "<td>"+value['ER_PROG_TWITTER']+"</td>";
              body += "<td>"+value['ER_YOUTUBE']+"</td>";
              body += "<td>"+value['ER_PROG_YOUTUBE']+"</td>";
             
              body += "</tr>";
              $("#table-data tbody").append(body);
               
             });
              $("#table-data").DataTable();
             
          
            
            }
         
         
          });

          

  
         

      
    });
   
  

  });
  



   function loadperformance(){
   
     $.ajax({
            type: "GET",
            url: "<?= site_url('tran/getperformance/fetch')?>",
        
            success: function (response) {
            //  console.log(response.data);
             $.each(response.data, function (key, value) { 
            

              var body = "<tr>";
              body += "<td><div class=\"btn-group\"><a  class=\"btn btn-info btn-sm edit-btn\">Edit</a>";
              
              body += "<td class=\"data-id\">"+value['PERFORM_ID']+"</td>";
              body += "<td>"+value['talent_name']+"</td>";
              body += "<td>"+value['PERFORM_YEAR']+"</td>";
              body += "<td>"+value['PERFORM_MONTH']+"</td>";
              body += "<td>"+value['FW_IG']+"</td>";
              body += "<td>"+value['PROG_IG']+"</td>";
              body += "<td>"+value['FW_TIKTOK']+"</td>";
              body += "<td>"+value['PROG_TIKTOK']+"</td>";
              body += "<td>"+value['FW_TWITTER']+"</td>";
              body += "<td>"+value['PROG_TWITTER']+"</td>";
              body += "<td>"+value['FW_YOUTUBE']+"</td>";
              body += "<td>"+value['PROG_YOUTUBE']+"</td>";
              body += "<td>"+value['ER_IG']+"</td>";
              body += "<td>"+value['ER_PROG_IG']+"</td>";
              body += "<td>"+value['ER_TIKTOK']+"</td>";
              body += "<td>"+value['ER_PROG_TIKTOK']+"</td>";
              body += "<td>"+value['ER_TWITTER']+"</td>";
              body += "<td>"+value['ER_PROG_TWITTER']+"</td>";
              body += "<td>"+value['ER_YOUTUBE']+"</td>";
              body += "<td>"+value['ER_PROG_YOUTUBE']+"</td>";
             
              body += "</tr>";
              $("#table-data tbody").append(body);
               
             });

          }
        });
      

       
  }

   function loadtalent(param){
  
    
      if(param == "new")
      {
        var ddl_username = $("#TALENT_ID");
     
      }else
      {
        var ddl_username = $("#eTALENT_ID");  
       
      }
        
     $.ajax({
            type: "GET",
            url: "<?= site_url('tran/get/talent')?>",
          
        
            success: function (response) {
             ddl_username.empty().append('<option selected="selected" value="">Please select</option>');
          
             $.each(response.data, function (key, value) { 
               ddl_username.append($("<option></option>").val(value['TALENT_ID']).html(value['XNAME']));
               
             });
             
            }
          });

       
  }

   $(document).ready(function () {
    loadtalent("new");
    loadperformance();


    $(document).on('click','.save-data', function () {
       if( $("#TALENT_ID").val() == "" || $("#PERFORM_YEAR").val() == "" || $("#PERFORM_MONTH").val() == "")
       {
        // Display an info toast with no title
          toastr.error("Mohon isi form dengan lengkap !")
          return false;
       }
       else
       { // jika sudah di isi semua.

       
         
          var $data = {
            'TALENT_ID' : $("#TALENT_ID").val(),
            'PERFORM_YEAR' : $("#PERFORM_YEAR").val(),
            'PERFORM_MONTH' : $("#PERFORM_MONTH").val(),
            'FW_IG' : $("#FW_IG").val(),
            'PROG_IG' : $("#PROG_IG").val(),
            'FW_TIKTOK' : $("#FW_TIKTOK").val(),
            'PROG_TIKTOK' : $("#PROG_TIKTOK").val(),
            'FW_TWITTER' : $("#FW_TWITTER").val(),
            'PROG_TWITTER' : $("#PROG_TWITTER").val(),
            'FW_YOUTUBE' : $("#FW_YOUTUBE").val(),
            'PROG_YOUTUBE' : $("#PROG_YOUTUBE").val(),
            'ER_IG' : $("#ER_IG").val(),
            'ER_PROG_IG' : $("#ER_PROG_IG").val(),
            'ER_TIKTOK' : $("#ER_TIKTOK").val(),
            'ER_PROG_TIKTOK' : $("#ER_PROG_TIKTOK").val(),
            'ER_TWITTER' : $("#ER_TWITTER").val(),
            'ER_PROG_TWITTER' : $("#ER_PROG_TWITTER").val(),
            'ER_YOUTUBE' : $("#ER_YOUTUBE").val(),
            'ER_PROG_YOUTUBE' : $("#ER_PROG_YOUTUBE").val()
          
          };
          $.ajax({
            type: "POST",
            url: "<?= site_url('tran/simpan/performance/save')?>",
            data: $data,
           
            success: function (response) {
              $('#form-add').modal('hide');
              $('#form-add').find('input').val('');
               $("#table-data tbody").html("");
            
            
              toastr.success(response.status);
            
          
           
            }
          });
         

       }
    });

     $(document).on('click','.edit-data', function () {
     if( $("#eTALENT_ID").val() == "" || $("#ePERFORM_YEAR").val() == "" || $("#ePERFORM_MONTH").val() == "")
       {
        // Display an info toast with no title
          toastr.error("Mohon isi form dengan lengkap !")
          return false;
       }
       else
       { // jika sudah di isi semua.

          var $data = {
            'TALENT_ID' : $("#eTALENT_ID").val(),
            'PERFORM_YEAR' : $("#ePERFORM_YEAR").val(),
            'PERFORM_MONTH' : $("#ePERFORM_MONTH").val(),
            'FW_IG' : $("#eFW_IG").val(),
            'PROG_IG' : $("#ePROG_IG").val(),
            'FW_TIKTOK' : $("#eFW_TIKTOK").val(),
            'PROG_TIKTOK' : $("#ePROG_TIKTOK").val(),
            'FW_TWITTER' : $("#eFW_TWITTER").val(),
            'PROG_TWITTER' : $("#ePROG_TWITTER").val(),
            'FW_YOUTUBE' : $("#eFW_YOUTUBE").val(),
            'PROG_YOUTUBE' : $("#ePROG_YOUTUBE").val(),
            'ER_IG' : $("#eER_IG").val(),
            'ER_PROG_IG' : $("#eER_PROG_IG").val(),
            'ER_TIKTOK' : $("#eER_TIKTOK").val(),
            'ER_PROG_TIKTOK' : $("#eER_PROG_TIKTOK").val(),
            'ER_TWITTER' : $("#eER_TWITTER").val(),
            'ER_PROG_TWITTER' : $("#eER_PROG_TWITTER").val(),
            'ER_YOUTUBE' : $("#eER_YOUTUBE").val(),
            'ER_PROG_YOUTUBE' : $("#eER_PROG_YOUTUBE").val(),
            'PERFORM_ID' : $("#performid").val(),
          
          };
          $.ajax({
            type: "POST",
            url: "<?= site_url('tran/update/performance')?>",
            data: $data,
           
            success: function (response) {
              $('#form-edit').modal('hide');
              $('#form-edit').find('input').val('');
               $("#table-data tbody").html("");
              
              loadperformance();
            
              toastr.success(response.status);
            
          
           
            }
          });
         

       }
    });


    
    $(document).on('click','.edit-btn', function () {
      var id = $(this).closest('tr').find('.data-id').text();
     
        loadtalent("edit");
  
     
    $.ajax({
      type: "POST",
      url: "<?= site_url('tran/performance/edit')?>",
      data: {'id' : id},
    
      success: function (response) {
    
       $.each(response, function (key, value) { 
       
          $('#form-edit').find('input').val('');
       
          $("#eTALENT_ID").val(value['TALENT_ID']).change();
          $("#ePERFORM_YEAR").val(value['PERFORM_YEAR']);
          $("#ePERFORM_MONTH").val(value['PERFORM_MONTH']);
          $("#eFW_IG").val(value['FW_IG']);
          $("#ePROG_IG").val(value['PROG_IG']);
          $("#eFW_TIKTOK").val(value['FW_TIKTOK']);
          $("#ePROG_TIKTOK").val(value['PROG_TIKTOK']);
          $("#eFW_TWITTER").val(value['FW_TWITTER']);
          $("#ePROG_TWITTER").val(value['PROG_TWITTER']);
          $("#eFW_YOUTUBE").val(value['FW_YOUTUBE']);
          $("#ePROG_YOUTUBE").val(value['PROG_YOUTUBE']);
          $("#eER_IG").val(value['ER_IG']);
          $("#eER_PROG_IG").val(value['ER_PROG_IG']);
          $("#eER_TIKTOK").val(value['ER_TIKTOK']);
          $("#eER_PROG_TIKTOK").val(value['ER_PROG_TIKTOK']);
          $("#eER_TWITTER").val(value['ER_TWITTER']);
          $("#eER_PROG_TWITTER").val(value['ER_PROG_TWITTER']);
          $("#eER_YOUTUBE").val(value['ER_YOUTUBE']);
          $("#eER_PROG_YOUTUBE").val(value['ER_PROG_YOUTUBE']);

           $("#performid").val(id);
           $("#form-edit").modal("show");
          
       });

      

      getsessionform();

        
      }
    });
  });

   }); // end of document ready

</script>



<?=$this->endSection()?>
