
<?= $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>Database Finance Recap Report</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
            
              <li class="breadcrumb-item active">Database Finance Recap Report</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

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

      <!-- Default box -->
      <div class=" card card-primary ">
        <div class="bg-olive card-header">
          <h3 class="card-title">Database Finance Recap Report</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>Database Finance Recap 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">Status paid from client</label>
                    <div class="col-sm-4">
                    <select class="form-control" id="status_from">
                          <option value="">- ALL -</option>
                          <option value="1">Paid</option>
                          <option value="0">Not yet</option>
                       
                        </select>
                    </div>
                  </div>
                   <div class="form-group row">
                    <label for="names" class="col-sm-2 col-form-label">Status paid to talent</label>
                    <div class="col-sm-4">
                     <select class="form-control" id="status_to">
                          <option value="">- ALL -</option>
                          <option value="1">Paid</option>
                          <option value="0">Not yet</option>
                       
                        </select>
                    </div>
                  </div>
                

                  
                   <button type="button" class="btn btn-info search-data">Search</button>
            
                </div>

             <div class="col-12" style="overflow-x:scroll">
             <table id="table-data" style="width:1500px;" class="table table-bordered table-hover">
                  <thead>
                  <tr>
                   
                  
                    <th>Talent Name</th>
                    <th>Product</th>
                    <th>Deal Value</th>
                    <th>Status paid from client</th>
                   
                    <th>Management cut</th>
                    <th>Talent share</th>
                    <th>Status paid to client</th>
                   
                    <th>Detail status</th>
                 
                    
                  </tr>
                  </thead>
                  <tbody>
                 
                  
                  </tbody>
                  <tfoot>
                    <th colspan="2"></th>
                    <th class="total-deal"></th>
                    <th></th>
                   
                   <th class="total-management"></th>
                  <th class="total-talent"></th>
                    <th colspan="2"></th>
                  </tfoot>
                </table>
                 </div>
        </div>
        <!-- /.card-body -->
        <div class="card-footer">
            </div>
        <!-- /.card-footer-->
      </div>
      <!-- /.card -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  </div>



   <?= $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>
$(document).ready(function () {


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

          };


          $.ajax({
            type: "POST",
            url: "<?= site_url('report/search-recap')?>",
            data: $data,
           
            success: function (response) {
              $totaldeal = 0;
              $totalmanagement = 0;
              $totaltalent = 0;

            
          
             $.each(response.data, function (key, value) { 
              var paid_client, paid_talent;
              if(value['STAT_PAID_CLIENT'] == 1){
                paid_client = "<div class=\"bg-success  color-palette text-center\"><span>Paid</span></div>";
              }else{
                paid_client = "<div class=\"bg-secondary  color-palette text-center\"><span>Not yet</span></div>";
              }
              if(value['STAT_PAID_TALENT'] == 1){
                paid_talent = "<div class=\"bg-success  color-palette text-center\"><span>Paid</span></div>";
              }else{
                paid_talent = "<div class=\"bg-secondary  color-palette text-center\"><span>Not yet</span></div>";
              }

              $totaldeal = $totaldeal + parseFloat(value['DEAL_VAL']);
              $totalmanagement = $totalmanagement + parseFloat(value['managemen_cut']);
              $totaltalent = $totaltalent + parseFloat(value['talent_share']);
              
             
              var body = "<tr>";
              
              body += "<td>"+value['talent_name']+"</td>";
              body += "<td>"+value['brand_name']+"</td>";
              body += "<td>"+value['DEAL_VAL']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+paid_client+"</div></td>";
            
              body += "<td>"+value['managemen_cut']+"</td>";              
              body += "<td>"+value['talent_share']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+paid_talent+"</div></td>";
             
              body += "<td>"+value['DTL_STAT_TALENT']+"</td>";
              body += "</tr>";
              
              $("#table-data tbody").append(body);
               
             });
              $("#table-data").DataTable({
                dom: 'Bfrtip',
                buttons: [
                
                    'excelHtml5'
                   
                ]
            } );
              $(".total-deal").text($totaldeal);
              $(".total-management").text($totalmanagement);
              $(".total-talent").text($totaltalent);
            }
          
         
          });
         

      
    });


}); // end of document ready function

</script>

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