<table id="" class="table table-striped table-bordered dt-responsive nowrap" style="width:100%">
    <thead>
        <tr>
            <th>#</th>
            <th>Medicine</th>
            <th>Amount</th>
        </tr>
    </thead>
    
        <tbody>
            @php $i=1;@endphp
            @foreach($data as $result)
            <tr>
                <td width="10">
                    <label class="custom-control custom-checkbox">
                        <input type="checkbox" oninput="clickChk()" class="custom-control-input common_selector Proccedures" name="MedicineId[]" value="{{$result->id}}"  >
                        <span class="custom-control-label">&nbsp;</span>
                    </label>
                </td>
                <input type="hidden" name="ProcId[]" value="{{$result->id}}">
                <td>{{$result->Name}}</td>
                <td>&#8377;{{$result->Amount}}</td>
            </tr>
            @php $i++;@endphp
            @endforeach
            <tr>
           
        <td style="font-size: 20px;color: blue;" colspan="2">Total Amount</td>
        <td id="TotalAmount" style="font-size: 20px;color: blue;"></td>
      
        </tr>
        </tbody>
        <input type="hidden" id="TotAmt" value="">
        <input type="hidden" id="ProcId" name="ProcedureId[]" value="">
        <input type="hidden" id="actionsurg" value="Save">
        <input type="hidden" id="surgsaveid" value="">
</table>

<script type="text/javascript">
$(document).ready(function() {
    $('#example22').DataTable({
        scrollY: '200px',
        pageLength: '1000',
        paging: false
    });

    // function get_filter(class_name)
    // {
    //     var filter = [];
    //     $('.'+class_name+':checked').each(function(){
    //         filter.push($(this).val());
    //     });
    //     return filter;
    // }

    // $('.common_selector').click(function(){
    //     //filter_data();
    //     var ProccedureId = get_filter('Proccedures');
    //      if(ProccedureId == ''){
    //           $('#ProcId').val(0);
    //      }
    //      else{
    //     $('#ProcId').val(ProccedureId);
    //     getTotAmount();
    //      }
        
    // });

});

function get_filter(class_name)
    {
        var filter = [];
        $('.'+class_name+':checked').each(function(){
            filter.push($(this).val());
        });
        return filter;
    }
function clickChk(){

        var ProccedureId = get_filter('Proccedures');
         if(ProccedureId == ''){
              $('#ProcId').val(0);
         }
         else{
        $('#ProcId').val(ProccedureId);
        getTotAmount();
         }
    }
function getTotAmount(){
    var ProcId = $('#ProcId').val();
    $.ajax({
            url: "{{ url('getInvestigationAmount') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                ProcId:ProcId
            },
            success: function(data) {
                console.log(data);
                var res = JSON.parse(data);
                $('#TotAmt').val(res.Amount);
                $('#InvStAmount').val(res.Amount);
                $('#TotalAmount').html('&#8377;'+res.Amount);
                $('#InvStName').val(res.InvstName);
            }
        });
}

</script>