
<?= $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>Deal Job & Payment</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
            <li class="breadcrumb-item">Transactional</li>
              <li class="breadcrumb-item active">Deal Job & Payment</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
 <input type="hidden" id="hdn_talentid">
  <input type="hidden" id="hdn_brandid">
      <!-- Default box -->
      <div class="card card-warning">
        <div class="card-header">
          <h3 class="card-title">Deal Job & Payment</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">
              <button type="submit" id="btn-add-form" class="btn btn-danger" data-toggle="modal" data-target="#form-add">Add Deal Job & Payment</button>
              <hr>
          <p> Deal Job & Payment report filter</p>
         
        
                <div class="card-body">
                    <div class="row">
                <div class="col-6">
              
                  <div class="form-group row">
                    <label for="names" class="col-sm-4 col-form-label">Year</label>
                    <div class="col-sm-8">
                      <input type="text" class="form-control" id="tahun" >
                    </div>
                  </div>
                    <div class="form-group row">
                    <label for="names" class="col-sm-4 col-form-label">Month</label>
                    <div class="col-sm-8">
                      <input type="text" class="form-control" id="bulan" >
                    </div>
                  </div>
                  <div class="form-group row">
                    <label for="names" class="col-sm-4 col-form-label">Talent name</label>
                    <div class="col-sm-8">
                      <input type="text" class="form-control" id="nama" >
                    </div>
                  </div>
                
                  
                     </div>
                        <div class="col-6">
              
                  <div class="form-group row">
                    <label for="names" class="col-sm-6 col-form-label">Status paid from client</label>
                    <div class="col-sm-6">
                       <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-6 col-form-label">Status paid to talent</label>
                    <div class="col-sm-6">
                       <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="submit" class="btn btn-info search-data">Search</button>
                 
                     </div>
</div>
             
              
                </div>
<hr>
             <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>Year</th>
                    <th>Month</th>
                    <th>Nama talent</th>
                    <th>Product</th>
                    <th>Deal by</th>
                    <th>Deal value</th>
                    <th>Deal value after tax</th>
                    <th>Status paid from client</th>
                    <th>Date of payment from client</th>
                    <th>Detail status</th>     
                    <th>Status paid to talent</th>   
                    <th>Date of payment to talent</th>
                    <th>Detail status</th>
                    <th>Status paid to manager</th>   
                    <th>Date of payment to manager</th>
                    <th>Invoice</th>
                    <th>Invoice number</th>
                    <th>Contract</th>
                    <th>Tax paid</th>  
                    <th>Faktur pajak</th>        
                    
                  </tr>
                  </thead>
                  <tbody>
                  
                  
                  </tbody>
              
                </table>
                 </div>
        </div>
        <!-- /.card-body -->
        <div class="card-footer">
          
        </div>
        <!-- /.card-footer-->
      </div>
      <!-- /.card -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  </div>
  <?php include('Jobpayment_add.php');?>
   <?php include('Jobpayment_edit.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 () {
    $( "#DTM_PAID_CLIENT" ).datepicker({ dateFormat: 'dd/mm/yy'});
    $( "#DTM_PAID_TALENT" ).datepicker({ dateFormat: 'dd/mm/yy'});

   
    $( "#eDTM_PAID_TALENT" ).datepicker({ dateFormat: 'dd/mm/yy'});
    $( "#eDTM_PAID_MANAGER" ).datepicker({ dateFormat: 'dd/mm/yy'});
    
 

    

  });
     $('.currency').simpleMoneyFormat();
    function numberOnly(selector) {
            selector.value = selector.value.replace(/[^0-9]/g, '');
         }

  
  

  function getsessionform(){
  var $sessionlevel = "<?php echo $_SESSION['USER_LEVEL'] ?>";
     if($sessionlevel == "TALENT_MANAGER" || $sessionlevel == "TALENT" )
            {
              managerform();
            }else if($sessionlevel == "STAFF_FINANCE")
            {
              financeform();
            }else if($sessionlevel == "STAFF_ADMIN")
            {
              adminform();
            }
          

       
  }


  function loaddeal(){
   
     $.ajax({
            type: "GET",
            url: "<?= site_url('tran/getdeal/fetch')?>",
        
            success: function (response) {
            //  console.log(response.data);
             $.each(response.data, function (key, value) { 
             
              var paid_client, paid_talent,tax,$INV,$CONTRACT,$FAKTUR_PAJAK,$STAT_PAID_MANAGER;
              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>";
              }

               if(value['STAT_TAX_PAID'] == 1){
                STAT_TAX_PAID = "<div class=\"bg-success  color-palette text-center\"><span>Yes</span></div>";
              }else{
                STAT_TAX_PAID = "<div class=\"bg-secondary  color-palette text-center\"><span>No</span></div>";
              }


              if(value['INV'] == "1"){
                $INV = "<div class=\"bg-success  color-palette text-center\"><span>Yes</span></div>";
              }else{
                $INV = "<div class=\"bg-secondary  color-palette text-center\"><span>No</span></div>";
              }

              if(value['CONTRACT'] == "1"){
                $CONTRACT = "<div class=\"bg-success  color-palette text-center\"><span>Yes</span></div>";
              }else{
                $CONTRACT = "<div class=\"bg-secondary  color-palette text-center\"><span>No</span></div>";
              }

              if(value['FAKTUR_PAJAK'] == "1"){
                $FAKTUR_PAJAK = "<div class=\"bg-success  color-palette text-center\"><span>Yes</span></div>";
              }else{
                $FAKTUR_PAJAK = "<div class=\"bg-secondary  color-palette text-center\"><span>No</span></div>";
              }

              if(value['STAT_PAID_MANAGER'] == "1"){
                $STAT_PAID_MANAGER = "<div class=\"bg-success  color-palette text-center\"><span>Paid</span></div>";
              }else{
                $STAT_PAID_MANAGER = "<div class=\"bg-secondary  color-palette text-center\"><span>Not yet</span></div>";
              }

              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['DEAL_ID']+"</td>";
              body += "<td >"+value['DEAL_YEAR']+"</td>";
              body += "<td>"+value['DEAL_MONTH']+"</td>";
              body += "<td>"+value['talent_name']+"</td>";
              body += "<td>"+value['brand_name']+"</td>";
              body += "<td>"+value['DEAL_BY']+"</td>";
              body += "<td>"+value['DEAL_VAL']+"</td>";
              body += "<td>"+value['DEAL_VAL_TAX']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+paid_client+"</div></td>";
              body += "<td>"+value['DTM_PAID_CLIENT']+"</td>";
              body += "<td>"+value['DTL_STAT_CLIENT']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+paid_talent+"</div></td>";
              body += "<td>"+value['DTM_PAID_TALENT']+"</td>";
              body += "<td>"+value['DTL_STAT_TALENT']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+$STAT_PAID_MANAGER+"</div></td>";
              body += "<td>"+value['DTM_PAID_MANAGER']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+$INV+"</div></td>";
              body += "<td>"+value['INV_NUMBER']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+$CONTRACT+"</div></td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+STAT_TAX_PAID+"</div></td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+$FAKTUR_PAJAK+"</div></td>";
              
              
             
              body += "</tr>";
              $("#table-data tbody").append(body);
               
             });

            var $sessionlevel = "<?php echo $_SESSION['USER_LEVEL'] ?>";
            if($sessionlevel == "TALENT_MANAGER" || $sessionlevel == "TALENT" )
            {
             // manager_table();
              $("#btn-add-form").show();
              
            }else if($sessionlevel == "STAFF_FINANCE")
            {
              // finance_table();
              
            }else if($sessionlevel == "STAFF_ADMIN")
            {
             // admin_table();
             
            }
          }
        });
      

       
  }

    $(document).ready(function () {
      loadtalent("new");
     
      loaddeal();
      $("#btn-add-form").hide();


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

          };
         

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

            
          
             $.each(response.data, function (key, value) { 
              var paid_client, paid_talent,tax,$INV,$CONTRACT,$FAKTUR_PAJAK,$STAT_PAID_MANAGER;
              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>";
              }

              if(value['STAT_TAX_PAID'] == 1){
                tax = "<div class=\"bg-success  color-palette text-center\"><span>Yes</span></div>";
              }else{
                tax = "<div class=\"bg-secondary  color-palette text-center\"><span>No</span></div>";
              }


              if(value['INV'] == "1"){
                $INV = "<div class=\"bg-success  color-palette text-center\"><span>Yes</span></div>";
              }else{
                $INV = "<div class=\"bg-secondary  color-palette text-center\"><span>No</span></div>";
              }

              if(value['CONTRACT'] == "1"){
                $CONTRACT = "<div class=\"bg-success  color-palette text-center\"><span>Yes</span></div>";
              }else{
                $CONTRACT = "<div class=\"bg-secondary  color-palette text-center\"><span>No</span></div>";
              }

              if(value['FAKTUR_PAJAK'] == "1"){
                $FAKTUR_PAJAK = "<div class=\"bg-success  color-palette text-center\"><span>Yes</span></div>";
              }else{
                $FAKTUR_PAJAK = "<div class=\"bg-secondary  color-palette text-center\"><span>No</span></div>";
              }

              if(value['STAT_PAID_MANAGER'] == "1"){
                $STAT_PAID_MANAGER = "<div class=\"bg-success  color-palette text-center\"><span>Yes</span></div>";
              }else{
                $STAT_PAID_MANAGER = "<div class=\"bg-secondary  color-palette text-center\"><span>No</span></div>";
              }

             
              
             
              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['DEAL_ID']+"</td>";
               body += "<td >"+value['DEAL_YEAR']+"</td>";
              body += "<td>"+value['DEAL_MONTH']+"</td>";
              body += "<td>"+value['talent_name']+"</td>";
              body += "<td>"+value['brand_name']+"</td>";
              
              body += "<td>"+value['DEAL_BY']+"</td>";
              body += "<td>"+value['DEAL_VAL']+"</td>";
              body += "<td>"+value['DEAL_VAL_TAX']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+paid_client+"</div></td>";
              body += "<td>"+value['DTM_PAID_CLIENT']+"</td>";
              body += "<td>"+value['DTL_STAT_CLIENT']+"</td>";
            
              body += "<td><div class=\"col-sm-4 col-md-10\">"+paid_talent+"</div></td>";
              body += "<td>"+value['DTM_PAID_TALENT']+"</td>";
              body += "<td>"+value['DTL_STAT_TALENT']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+$STAT_PAID_MANAGER+"</div></td>";
              body += "<td>"+value['DTM_PAID_MANAGER']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+$INV+"</div></td>";
              body += "<td>"+value['INV_NUMBER']+"</td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+$CONTRACT+"</div></td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+tax+"</div></td>";
              body += "<td><div class=\"col-sm-4 col-md-10\">"+$FAKTUR_PAJAK+"</div></td>";
              body += "</tr>";
              $("#table-data tbody").append(body);
               
             });
              $("#table-data").DataTable();
            
            
            }
          
         
          });
         

      
    });

    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']));
               
             });
              if($("#hdn_talentid").val() != "")
             {
              $("#eTALENT_ID").val($("#hdn_talentid").val());
             }
             
            }
          });

       
  }

 

      
   

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

         if($('#STAT_PAID_CLIENT').is(':checked') && $("#DTM_PAID_CLIENT").val() == "" ){
             toastr.error("Date paid to client cannot blank !")
              return false;
         }else if($('#STAT_PAID_TALENT').is(':checked') && $("#DTM_PAID_TALENT").val() == "" ){
             toastr.error("Date paid to talent cannot blank !")
              return false;
         }
         $STAT_PAID_CLIENT = 0;
         $STAT_PAID_TALENT = 0;
         if($('#STAT_PAID_CLIENT').is(':checked')){ $STAT_PAID_CLIENT = "1" }
         if($('#STAT_PAID_TALENT').is(':checked')){ $STAT_PAID_TALENT = "1" }

         
          var $data = {
            'DEAL_YEAR' : $("#DEAL_YEAR").val(),
            'DEAL_MONTH' : $("#DEAL_MONTH").val(),
            'TALENT_ID' : $("#TALENT_ID").val(),
            'BRAND_ID' : $("#BRAND_ID").val(),
            'DEAL_BY' : $("#DEAL_BY").val(),
            'DEAL_VAL' : $("#DEAL_VAL").val(),
            'STAT_PAID_CLIENT' : $STAT_PAID_CLIENT,
            'DTM_PAID_CLIENT' : $("#DTM_PAID_CLIENT").val(),
            'DTL_STAT_CLIENT' : $("#DTL_STAT_CLIENT").val(),
            'STAT_PAID_TALENT' : $STAT_PAID_TALENT,
            'DTM_PAID_TALENT' : $("#DTM_PAID_TALENT").val(),
            'DTL_STAT_TALENT' : $("#DTL_STAT_TALENT").val(),
            'INV' : $("#INV").val(),
            'INV_NUMBER' : $("#INV_NUMBER").val(),
            'STAT_TAX_PAID' : $("#STAT_TAX_PAID").val(),
            'FAKTUR_PAJAK' : $("#FAKTUR_PAJAK").val(),
            'CONTRACT' : $("#CONTRACT").val(),
            'DEAL_VAL_TAX' : $("#DEAL_VAL_TAX").val(),
        
            

          };
          $.ajax({
            type: "POST",
            url: "<?= site_url('tran/simpan/job-payment/manager')?>",
            data: $data,
           
            success: function (response) {
              $('#form-add').modal('hide');
              $('#form-add').find('input').val('');
               $("#table-data tbody").html("");
                loadtalent("new");
               
            
              toastr.success(response.status);
            
          
           
            }
          });
         

       }
    });

    $(document).on('click','.edit-data', function () {
       if( $("#eDEAL_YEAR").val() == "" || $("#eDEAL_MONTH").val() == "" || $("#eTALENT_ID").val() == "" || $("#eBRAND_ID").val() == "" || $("#eDEAL_BY").val() == "" || $("#eDEAL_VAL").val() == "" )
       {
        // Display an info toast with no title
          toastr.error("Mohon isi form dengan lengkap !")
          return false;
       }
       else
       { // jika sudah di isi semua.
      
         if($('#STAT_PAID_CLIENT').is(':checked') && $("#DTM_PAID_CLIENT").val() == "" ){
             toastr.error("Date paid to client cannot blank !")
              return false;
         }else if($('#STAT_PAID_TALENT').is(':checked') && $("#DTM_PAID_TALENT").val() == "" ){
             toastr.error("Date paid to talent cannot blank !")
              return false;
         }
         $STAT_PAID_CLIENT = 0;
         $STAT_PAID_TALENT = 0;
         $STAT_TAX_PAID  = 0;
         $eCONTRACT = 0;
         $eFAKTUR_PAJAK = 0;
         $eINV = 0;
         $eSTAT_PAID_MANAGER = 0;


         if($('#eSTAT_PAID_CLIENT').is(':checked')){ $STAT_PAID_CLIENT = "1" }
         if($('#eSTAT_PAID_TALENT').is(':checked')){ $STAT_PAID_TALENT = "1" }
         if($('#eSTAT_TAX_PAID').is(':checked')){ $STAT_TAX_PAID = "1" }


         if($('#eCONTRACT').is(':checked')){ $eCONTRACT = "1" }
         if($('#eFAKTUR_PAJAK').is(':checked')){ $eFAKTUR_PAJAK = "1" }
         if($('#eINV').is(':checked')){ $eINV = "1" }
         if($('#eSTAT_PAID_MANAGER').is(':checked')){ $eSTAT_PAID_MANAGER = "1" }
         

         
          var $data = {
            'DEAL_YEAR' : $("#eDEAL_YEAR").val(),
            'DEAL_MONTH' : $("#eDEAL_MONTH").val(),
            'TALENT_ID' : $("#eTALENT_ID").val(),
            'BRAND_ID' : $("#eBRAND_ID").val(),
            'DEAL_BY' : $("#eDEAL_BY").val(),
            'DEAL_VAL' : $("#eDEAL_VAL").val(),
            'DEAL_VAL_TAX' : $("#eDEAL_VAL_TAX").val(),
            'STAT_PAID_CLIENT' : $STAT_PAID_CLIENT,
            'DTM_PAID_CLIENT' : $("#eDTM_PAID_CLIENT").val(),
            'DTL_STAT_CLIENT' : $("#eDTL_STAT_CLIENT").val(),
            'STAT_PAID_TALENT' : $STAT_PAID_TALENT,
            'DTM_PAID_TALENT' : $("#eDTM_PAID_TALENT").val(),
            'DTL_STAT_TALENT' : $("#eDTL_STAT_TALENT").val(),
            'INV' : $eINV,
            'INV_NUMBER' : $("#eINV_NUMBER").val(),
            'STAT_TAX_PAID' : $STAT_TAX_PAID,
            'FAKTUR_PAJAK' : $eFAKTUR_PAJAK,
            'CONTRACT' : $eCONTRACT,
            'DEAL_ID' : $("#eDEAL_ID").val(),
            'STAT_PAID_MANAGER' : $eSTAT_PAID_MANAGER,
            'DTM_PAID_MANAGER' : $("#eDTM_PAID_MANAGER").val(),
        
            

          };
          $.ajax({
            type: "POST",
            url: "<?= site_url('tran/update/job-payment/internal')?>",
            data: $data,
           
            success: function (response) {
              $('#form-edit').modal('hide');
              $('#form-edit').find('input').val('');
               $("#table-data tbody").html("");
                loadtalent("edit");
               
                loaddeal();
            
              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/deal/edit')?>",
      data: {'id' : id},
    
      success: function (response) {
     
    
       $.each(response, function (key, value) { 
           var $eDTM_PAID_TALENT, $DTM_PAID_CLIENT,$INV,$eDTM_PAID_MANAGER;

        if(value['eDTM_PAID_TALENT'] != null){
          $eDTM_PAID_TALENT = moment(value['eDTM_PAID_TALENT']).format("DD/MM/YYYY");
        }
        if(value['DTM_PAID_CLIENT'] != null){
          $DTM_PAID_CLIENT = value['DTM_PAID_CLIENT'];
        }
         if(value['INV'] != null){
          $INV = moment(value['INV']).format("DD/MM/YYYY");
        }
        if(value['DTM_PAID_MANAGER'] != null){
          $eDTM_PAID_MANAGER = moment(value['DTM_PAID_MANAGER']).format("DD/MM/YYYY");
        }

       
          $('#form-edit').find('input').val('');
           $("#eDEAL_YEAR").val(value['DEAL_YEAR']);
           $("#eDEAL_MONTH").val(value['DEAL_MONTH']);
          
           $("#eDEAL_BY").val(value['DEAL_BY']);
           $("#eDEAL_VAL").val(value['DEAL_VAL']);
           if(value['STAT_PAID_CLIENT'] == 1 ){$('#eSTAT_PAID_CLIENT').prop('checked', true);} else {$('#eSTAT_PAID_CLIENT').prop('checked', false);}
           $("#eDTM_PAID_CLIENT").val($DTM_PAID_CLIENT);
           $("#eDTL_STAT_CLIENT").val(value['DTL_STAT_CLIENT']);
           if(value['STAT_PAID_TALENT'] == 1 ){$('#eSTAT_PAID_TALENT').prop('checked', true);} else {$('#eSTAT_PAID_TALENT').prop('checked', false);}
           $("#eDTM_PAID_TALENT").val($eDTM_PAID_TALENT);
           $("#eDTL_STAT_TALENT").val(value['DTL_STAT_TALENT']);
           if(value['INV'] == "1" ){$('#eINV').prop('checked', true);} else {$('#eINV').prop('checked', false);}
           $("#eINV_NUMBER").val(value['INV_NUMBER']);
           if(value['STAT_TAX_PAID'] == 1 ){$('#eSTAT_TAX_PAID').prop('checked', true);} else {$('#eSTAT_TAX_PAID').prop('checked', false);}
           if(value['FAKTUR_PAJAK'] == "1" ){$('#eFAKTUR_PAJAK').prop('checked', true);} else {$('#eFAKTUR_PAJAK').prop('checked', false);}
           if(value['CONTRACT'] == "1" ){$('#eCONTRACT').prop('checked', true);} else {$('#eCONTRACT').prop('checked', false);}
           if(value['STAT_PAID_MANAGER'] == "1" ){$('#eSTAT_PAID_MANAGER').prop('checked', true);} else {$('#eSTAT_PAID_MANAGER').prop('checked', false);}
           $("#eDTM_PAID_MANAGER").val($eDTM_PAID_MANAGER);
           $("#eDEAL_ID").val(id);
           $("#eTALENT_ID").val(value['TALENT_ID']);
           $("#eBRAND_ID").val(value['BRAND_ID']);
           $("#hdn_talentid").val(value['TALENT_ID']);
           $("#hdn_brandid").val(value['BRAND_ID']);
           $("#form-edit").modal("show");
           $("#eDEAL_VAL_TAX").val(value['DEAL_VAL_TAX']);

           
           
          
       });

       if($('#eSTAT_PAID_CLIENT').is(':checked'))
    { 
      $( "#eDTM_PAID_CLIENT" ).prop( "disabled", false );
      $( "#eDTL_STAT_CLIENT" ).prop( "disabled", false );
    }
    else
    {
      $( "#eDTM_PAID_CLIENT" ).prop( "disabled", true );
      $( "#eDTL_STAT_CLIENT" ).prop( "disabled", true );
    }

     if($('#eSTAT_PAID_TALENT').is(':checked'))
    { 
      $( "#eDTM_PAID_TALENT" ).prop( "disabled", false );
      $( "#eDTL_STAT_TALENT" ).prop( "disabled", false );
    }
    else
    {
      $( "#eDTM_PAID_TALENT" ).prop( "disabled", true );
      $( "#eDTL_STAT_TALENT" ).prop( "disabled", true );
    }

      getsessionform();
       

        
      }
   
    });
  });

    })


    $("#eSTAT_PAID_CLIENT").change( function () {
    if($('#eSTAT_PAID_CLIENT').is(':checked'))
    { 
      $( "#eDTM_PAID_CLIENT" ).prop( "disabled", false );
      $( "#eDTL_STAT_CLIENT" ).prop( "disabled", false );
    }
    else
    {
      $( "#eDTM_PAID_CLIENT" ).prop( "disabled", true );
      $( "#eDTL_STAT_CLIENT" ).prop( "disabled", true );
    }
    
  });


      $("#eSTAT_PAID_TALENT").change( function () {
    if($('#eSTAT_PAID_TALENT').is(':checked'))
    { 
      $( "#eDTM_PAID_TALENT" ).prop( "disabled", false );
      $( "#eDTL_STAT_TALENT" ).prop( "disabled", false );
    }
    else
    {
      $( "#eDTM_PAID_TALENT" ).prop( "disabled", true );
      $( "#eDTL_STAT_TALENT" ).prop( "disabled", true );
    }
    
  });

  function managerform(){
          $("#eDEAL_YEAR").prop( "disabled", false );
          $("#eDEAL_MONTH").prop( "disabled", false );
          $("#eTALENT_ID").prop( "disabled", false );
          $("#eBRAND_ID").prop( "disabled", false );
          $("#eDEAL_BY").prop( "disabled", false );
          $("#eDEAL_VAL").prop( "disabled", false );
          
          $("#eSTAT_PAID_CLIENT").prop( "disabled", true );
          $("#eSTAT_PAID_TALENT").prop( "disabled", true );
          $("#eDTM_PAID_CLIENT").prop( "disabled", true );
          $("#eDTL_STAT_CLIENT").prop( "disabled", true );
        
          $("#eDTM_PAID_TALENT").prop( "disabled", true );
          $("#eDTL_STAT_TALENT").prop( "disabled", true );
          $("#eINV").prop( "disabled", true );
          $("#eINV_NUMBER").prop( "disabled", true );
          $("#eSTAT_TAX_PAID").prop( "disabled", true );
          $("#eFAKTUR_PAJAK").prop( "disabled", true );
          $("#eCONTRACT").prop( "disabled", true );
          $("#eDEAL_ID").prop( "disabled", true );

          $("#eDTM_PAID_MANAGER").prop( "disabled", true );
          $("#eSTAT_PAID_MANAGER").prop( "disabled", true );
    
         
 

       
  }

   function financeform(){

        
        //  $("#eTALENT_ID").val($("#hdn_talentid").val()).change();
         // $("#eBRAND_ID").val($("#hdn_brandid").val()).change();

          $("#eDEAL_YEAR").prop( "disabled", true );
          $("#eDEAL_MONTH").prop( "disabled", true );
          $("#eDEAL_VAL_TAX").prop( "disabled", true );
          
          
         // $("#eTALENT_ID").prop( "disabled", true );
         // $("#eBRAND_ID").prop( "disabled", true );
          $("#eDEAL_BY").prop( "disabled", true );
          $("#eDEAL_VAL").prop( "disabled", true );
          $("#eSTAT_PAID_CLIENT").prop( "disabled", false );
          $("#eSTAT_PAID_TALENT").prop( "disabled", false );
          $("#eDTM_PAID_CLIENT").prop( "disabled", false );
          $("#eDTL_STAT_CLIENT").prop( "disabled", false );     
          $("#eDTM_PAID_TALENT").prop( "disabled", false );
          $("#eDTL_STAT_TALENT").prop( "disabled", false );
          $("#eDTM_PAID_MANAGER").prop( "disabled", false );
          $("#eSTAT_PAID_MANAGER").prop( "disabled", false );


          $("#eINV").prop( "disabled", true );
          $("#eINV_NUMBER").prop( "disabled", true );
          $("#eSTAT_TAX_PAID").prop( "disabled", true );
          $("#eFAKTUR_PAJAK").prop( "disabled", true );
          $("#eCONTRACT").prop( "disabled", true );
          $("#eDEAL_ID").prop( "disabled", true );  
  }


  function adminform(){
          $("#eDEAL_YEAR").prop( "disabled", true );
          $("#eDEAL_MONTH").prop( "disabled", true );
          $("#eTALENT_ID").prop( "disabled", true );
          $("#eBRAND_ID").prop( "disabled", true );
          $("#eDEAL_BY").prop( "disabled", true );
          $("#eDEAL_VAL").prop( "disabled", true );

          $("#eSTAT_PAID_CLIENT").prop( "disabled", true );
          $("#eSTAT_PAID_TALENT").prop( "disabled", true );
          $("#eDTM_PAID_CLIENT").prop( "disabled", true );
          $("#eDTL_STAT_CLIENT").prop( "disabled", true );     
          $("#eDTM_PAID_TALENT").prop( "disabled", true );
          $("#eDTL_STAT_TALENT").prop( "disabled", true );
          $("#eDTM_PAID_MANAGER").prop( "disabled", true );
          $("#eSTAT_PAID_MANAGER").prop( "disabled", true );

          $("#eINV").prop( "disabled", false );
          $("#eINV_NUMBER").prop( "disabled", false );
          $("#eSTAT_TAX_PAID").prop( "disabled", false );
          $("#eFAKTUR_PAJAK").prop( "disabled", false );
          $("#eCONTRACT").prop( "disabled", false );
          $("#eDEAL_ID").prop( "disabled", false );  
  }

  /*

  function manager_table(){
         
          $tabledata =  $("#table-data").DataTable();
          $tabledata.column(8).visible( false );
          $tabledata.column(9).visible( false );
          $tabledata.column(10).visible( false );
          $tabledata.column(11).visible( false );
          $tabledata.column(12).visible( false );
          $tabledata.column(13).visible( false );
          $tabledata.column(14).visible( false );
          $tabledata.column(15).visible( false );
          $tabledata.column(16).visible( false );
          $tabledata.column(17).visible( false );
          $tabledata.column(18).visible( false );
   
  }

    function finance_table(){
         
          $tabledata =  $("#table-data").DataTable();
         
          $tabledata.column(15).visible( false );
          $tabledata.column(16).visible( false );
          $tabledata.column(17).visible( false );
          $tabledata.column(18).visible( false );
   
  }


   function admin_table(){
         
          $tabledata =  $("#table-data").DataTable();
             $tabledata.column(2).visible( false );
          $tabledata.column(3).visible( false );
          $tabledata.column(4).visible( false );
          $tabledata.column(5).visible( false );
          $tabledata.column(6).visible( false );
           $tabledata.column(7).visible( false );
           $tabledata.column(8).visible( false );
          $tabledata.column(9).visible( false );
          $tabledata.column(10).visible( false );
          $tabledata.column(11).visible( false );
          $tabledata.column(12).visible( false );
          $tabledata.column(13).visible( false );
 
  }

*/


</script>

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