<?php $__env->startSection('css'); ?>
    <?php echo $__env->make('layouts.datatables_css', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>
<div class="row mb-3">
<form class="row gx-3 gy-2 align-items-center">
  <div class="col-sm-3">    
    <?php echo Form::select('unit', $unitItem, null, ['class' => 'form-control select2', 'data-placeholder' => 'Pilih Unit']); ?>    
  </div>
  <div class="col-sm-3">
    <?php echo Form::text('transaction_date','', ['class' => 'form-control datetime', 'placeholder' => 'Tanggal KU']); ?>    
  </div>  
  <div class="col-sm-3">    
    <?php echo Form::select('customer_code', $wilayahItem, null, ['class' => 'form-control select2', 'data-placeholder' => 'Pilih Teritori']); ?>    
  </div>
  
  <div class="col-auto">
    <?php echo Form::button('Cari',['class' => 'btn btn-primary', 'onclick' => 'searchKU(this)']); ?>    
  </div>
</form>
</div>
<?php echo $dataTable->table(['width' => '100%', 'class' => 'table table-striped table-bordered']); ?>


<?php $__env->startPush('scripts'); ?>
    <?php echo $__env->make('layouts.datatables_js', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <script>
      let dataTableObj
        function searchKU(elm){
          if(dataTableObj == undefined){
            dataTableObj = $('#dataTableBuilder').DataTable(<?php echo $dataTable->generateJson(); ?>)
          }
          
          dataTableObj.column(1).search(main.getValueDateSQL($('input[name=transaction_date]')))
          dataTableObj.column(2).search($('select[name=customer_code]').val())
          dataTableObj.column(6).search($('select[name=unit]').val())
          
          dataTableObj.draw()
        }

        function saveLhph(elm){
          const _row = $(elm).closest('tr')
          const _lhph = _row.find('input.lhph')
          const _customer = _row.find('select.customer')
          const _message = []
          if(_.isEmpty(_lhph.val())){
            _message.push('LHPH harus diisi')            
          }

          if(_.isEmpty(_customer.val())){
            _message.push('Pelanggan harus diisi')            
          }

          if(!_.isEmpty(_message)){
            main.alertDialog('Warning', _message.join('\n'))
            return
          }
          
          $.ajax({            
            url: $(elm).data('url'),
            beforeSend: function(){
              $(elm).html('<i class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></i>')            
            },
            type: 'PUT',
            dataType: 'json',
            data: {
              lhph_number: _lhph.val(),
              customer_code: _customer.val()
            },
            success: function(data){
              if(!data.status){
                main.alertDialog('Error', data.message)
                $(elm).html('<i class="fa fa-save" aria-hidden="true"></i>')
              }else{
                $(elm).html('<i class="fa fa-save" aria-hidden="true"></i> <i class="fa fa-check" aria-hidden="true"></i>')
              }
              
            }
          })
        }
    </script>
        
<?php $__env->stopPush(); ?>
<?php /**PATH /data/docker/wjc/portal/resources/views/transaction/receive_moneys_lhph/table.blade.php ENDPATH**/ ?>