<script>
    $(document).ready(function (){
        $('#credited-item').select2();
        $('#debited-item').select2();

        $('#credited-client').on('input paste', function (){
            var names = $(this).val();
            var clients = names.split("-");
            //alert(client);
            if(names != ""){
                $.ajax({
                    method: 'GET',
                    url: '/search-client-by-name-add-id-two/'+names,
                    data: names,
                    success: function (res){
                        if(res != ""){
                            $('#client-two-search-results').show().html(res);
                        }else{
                            $('#client-two-search-results').hide();
                        }
                    }
                });
                var clientIds = clients[0];
                $('#credited-item').empty();
                if($.isNumeric(clientIds)){
                    $.ajax({
                        method: 'GET',
                        url: '/client-debit-notes/'+clientIds,
                        data: clientIds,
                        success: function (res){
                            if(res != ""){
                                $('#credited-item').append(res);
                            }
                        }
                    });
                }

            }
        });

        $('#debited-client').on('input paste', function (){
            var name = $(this).val();
            var client = name.split("-");
            //alert(client);
            if(name != ""){
                $.ajax({
                    method: 'GET',
                    url: '/search-client-by-name-add-id/'+name,
                    data: name,
                    success: function (res){
                        if(res != ""){
                            $('#client-one-search-results').show().html(res);
                        }else{
                            $('#client-one-search-results').hide();
                        }
                    }
                });
                var clientId = client[0];
                $('#debited-item').empty();
                if($.isNumeric(clientId)){
                    $.ajax({
                        method: 'GET',
                        url: '/client-debit-notes/'+clientId,
                        data: clientId,
                        success: function (res){
                            if(res != ""){
                                $('#debited-item').append(res);
                            }
                        }
                    });
                }

            }
        });


        /**Selecting through the Debits, show Policy Balance**/
        $('#debited-item').change(function (){
            var debit = $(this).val();
            if(debit != ""){
                $.ajax({
                    method: 'GET',
                    url: '/client-debit-note-balance/'+debit,
                    data: debit,
                    success: function (res){
                        if(res != ""){
                            $('#debited-item-balance').text(res);
                        }
                    }
                });
            }
        });

        /**Selecting through the Debits, show Policy Balance**/
        $('#credited-item').change(function (){
            var debit = $(this).val();
            if(debit != ""){
                $.ajax({
                    method: 'GET',
                    url: '/client-debit-note-balance/'+debit,
                    data: debit,
                    success: function (res){
                        if(res != ""){
                            $('#credited-item-balance').text(res);
                        }
                    }
                });
            }
        });

        /**Confirm Details are okay**/
        $('#confirm-checkbox').click(function (){
            if($('#confirm-checkbox').is(':checked')){
                $('#jv-amount-div').show();
            }else{
                $('#jv-amount-div').hide();
            }
        });

    });
</script>

<?php echo Form::open(['action'=>['Finance\JvsController@storeClientToClientJv'], 'id'=>'add-client-client-jv', 'method'=>'POST']); ?>

<div class="error" style="text-align: center;">On this Window, You can Create a New Client-Client JV</div>
<div class="guestDetails_inputDivider"></div>
<button type="submit" disabled style="display: none" aria-hidden="true"></button>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Select Client Account to be Debited <span class="error">*</span>
    </div>
    <div>
        <input type="text" name="debited-client" list="clients-listing"  id="debited-client" style="width: 300px" class="input-text-height">
        <div id="client-one-search-results" style="display: none"></div>
    </div>
</div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Select Item to be Debited <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        <select name="debited-item" id="debited-item" style="width: 130px">
            <option value="">--Select Item--</option>
        </select>
    </div>
</div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Project Balance <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        <b id="debited-item-balance" class="error" style="font-size: 16px"></b>
    </div>
</div>
<div class="guestDetails_inputDivider1"></div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Select Client Account to be Credited <span class="error">*</span>
    </div>
    <div>
        <input type="text" name="credited-client" list="clients-listing-two"  id="credited-client" style="width: 300px" class="input-text-height">
        <div id="client-two-search-results" style="display: none"></div>
    </div>
</div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Select Item to be Credited <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        <select name="credited-item" id="credited-item" style="width: 130px">
            <option value="">--Select Item--</option>
        </select>
    </div>
</div>
<div class="guestDetails_input">
    <div class="guestDetails_inputLabel">
        Project Balance <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        <b id="credited-item-balance" class="error" style="font-size: 16px"></b>
    </div>
</div>
<div class="guestDetails_inputDivider"></div>
<div id="confirm-div" style="text-align: center">
    <div class="guestDetails_inputDividerNone"></div>
    <?php echo Form::checkbox('confirm', 'yes', false,['id'=>'confirm-checkbox']); ?>

    <b class="error">I confirm the above Items are Correct and I wish to proceed to Create a JV.</b>
</div><br>
<div  id="jv-amount-div" style="display: none">
    <div class="guestDetails_input">
        <div class="guestDetails_inputLabel">
            Journal Amount <span class="error">*</span>
        </div>
        <div class="guestDetails_input">
            <?php echo Form::number('jv-amount', '',['class'=>'input-text-height', 'style'=>'width:150px', 'min'=>0]); ?>

        </div>
    </div>
    <div class="guestDetails_input">
        <div class="guestDetails_inputLabel">
            Journal Date <span class="error">*</span>
        </div>
        <div class="guestDetails_input">
            <?php echo Form::date('jv-date', '',['class'=>'input-text-height', 'min'=>date('Y-m-d')]); ?>

        </div>
    </div>
    <div class="guestDetails_inputDividerNone"></div>
    <div class="guestDetails_inputDivider1"></div>
    <div class="guestDetails_input">
        <div class="guestDetails_inputLabel">
            <?php echo Form::label('narration', 'Narration'); ?> <span class="error">*</span>
        </div>
        <div class="guestDetails_input">
            <?php echo Form::textarea('narration', '',['style'=>'width:560px; height:60px']); ?>

        </div>
    </div>
</div>
<?php echo Form::close(); ?>

<?php /**PATH C:\xampp\htdocs\finewood\resources\views/finance/jvs/client-client-jv.blade.php ENDPATH**/ ?>