@extends('layouts.app')

@section('content')
<?php use App\Http\Controllers\ConfigController; ?>
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
		<div class="panel" id="form_style">
			<div id="header">
		<h3>Add Payroll Agreement</h3>
	</div>
                <div class="panel-body">
                
                    <form class="form-horizontal" method="POST" action="{{url('user.payroll.agreement.save')}}" id="userPayroll">
                        {{ csrf_field() }}

                    <div class="form-group well" id="data-id">
                        
                        @include('users.agreements_data')
                        
                    </div>


                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-3">
                                <button type="submit" class="btn btn-primary col-md-12" id="submit">
                                    Update
                                </button>

                            </div>
                        </div>


                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

        function show(id)
        {
           if(document.getElementById('checkbox'+id).checked)
           {
                document.getElementById('productCheckbox'+id).value = 'yes';
                
                $('#div-percentage'+id).fadeIn('slow');
           }
           else
           {
                document.getElementById('productCheckbox'+id).value = 'no';
                $('#div-percentage'+id).fadeOut('slow');
           }
        }
 

     function refresh()
     {
        $.ajax({
            type:'get',
            url:"{{url('user.agreement.payroll')}}.{{$user_id}}",
            data: '',
            success:function(data){
                
                $('#data-id').html(data.html);
            },
            error:function(data){
                alert('error');
            }
        });
     }     


     $('#userPayroll').submit(function(e){
        e.preventDefault();


        var url, formData;
        url = $(this).attr('action');
        formData = $('#userPayroll').serialize();

        $.ajax({
            type: 'POST',
            url: url,
            data: formData,
            success:function(data){
                if(data.success)
                {
                        swal({
                            title: 'Success',
                            text: data.success,
                            type: 'success',
                            animation:true
                        });
                }

                if(data.error)
                {
                    swal({
                        title: 'Oops',
                        text: data.error,
                        type: 'error',
                        animation:true
                    });
                }
                refresh();
            },
            error:function(data){

            }
        });

        // refresh();

     })  

</script>
@endsection