<script>
    $(document).ready(function () {
        $('#type-list').select2();
        $('#category-list').select2();
        $('#currency-list').select2();

        $('#type-list').on('change', function (){
            let type = $(this).val();
            $('#type-label').addClass('error');
            $('#account-details-div').show();
            if(type != ""){
                
                $.ajax({
                    method: 'GET',
                    url: '<?php echo e(URL::to('company-account-type')); ?>',
                    data : {'id':type},
                    success: function (res){
                        if(res == "CB"){
                            $('#account-currency-div').show();
                        }else{
                            $('#account-currency-div').hide();
                        }
                    }
                });
                $('#account-details-div').show();
                $('#type-label').removeClass('error');
            }
        });


        $('#account-name').on('input paste', function (){
            let name = $(this).val();
            $('#name-label').addClass('error');
            if(name != ""){
                $('#name-label').removeClass('error');
            }
        });
        $('#account-number').on('input paste', function (){
            let number = $(this).val();
            $('#number-label').addClass('error');
            if(number != ""){
                $('#number-label').removeClass('error');
            }
        });

        $('#currency-list').on('change', function (){
            let currency = $(this).val();

            $('#currency-label').addClass('error');
            if(currency != ""){
                $('#currency-label').removeClass('error');
            }
        });


    });
</script>
<?php echo Form::open(['action'=>['CompanyChartsOfAccountController@store'], 'method'=>'POST', 'id'=>'add-company-chart-of-accounts']); ?>

<div class="error" style="text-align: center;">On this Window, You can Create a New Account</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">
        <?php echo Form::label('type', 'Select the Main Type of Account:', ['id'=>'type-label', 'class'=>'error']); ?>

        <span class="error">*</span>
    </div>
    <div class="guestDetails_input">
        <select name="type" id="type-list" style="width: 350px">
            <option value="">--Select Main Account Type--</option>
            <optgroup label="Balance Sheet Accounts"></optgroup>
            <?php $__currentLoopData = $mainAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php if($row->type == 'BS'): ?>
                    <option value="<?php echo e($row->id); ?>"><?php echo e(strtoupper($row->name)); ?></option>
                <?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <optgroup label="Profit & Loss Accounts"></optgroup>
            <?php $__currentLoopData = $mainAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php if($row->type == 'PL'): ?>
                    <option value="<?php echo e($row->id); ?>"><?php echo e(strtoupper($row->name)); ?></option>
                <?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
    </div>
</div>
<div class="guestDetails_input" id="account-currency-div" style="display: none">
    <div class="guestDetails_inputLabel" >
        <?php echo Form::label('currency', 'Currency', ['class'=>'error', 'id'=>'currency-label']); ?><span class="error">*</span></div>
    <div class="guestDetails_input">
        <select name="currency" id="currency-list" style="width: 150px">
            <?php if($currencies != null): ?>
                <option value="">--Select Currency--</option>
                <?php $__currentLoopData = $currencies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($row->id); ?>"><?php echo e($row->name."(".$row->abbr.")"); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php endif; ?>
        </select>
    </div>
</div>

<div id="account-details-div" style="display: none">
    <div class="guestDetails_inputDivider"></div>
    <div class="guestDetails_input">
        <div class="guestDetails_inputLabel">
            <?php echo Form::label('account-name', 'Enter the Account/Ledger Name:', ['id'=>'name-label', 'class'=>'error']); ?>

            <span class="error">*</span>
        </div>
        <div class="guestDetails_input">
            <?php echo Form::text('account-name', '', ['size'=>60, 'placeholder'=>'Enter Ledger/Account Name', 'id'=>'account-name', 'class'=>'input-text-height']); ?>

        </div>
    </div>
    <div class="guestDetails_input">
        <div class="guestDetails_inputLabel">
            <?php echo Form::label('account-number', 'Enter the Ledger Number:', ['id'=>'number-label', 'class'=>'error']); ?>

            <span class="error">*</span>
        </div>
        <div class="guestDetails_input">
            <?php echo Form::text('account-number', '', ['size'=>22, 'placeholder'=>'Enter Ledger Number', 'id'=>'account-number', 'class'=>'input-text-height']); ?>

        </div>
    </div>

</div>


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

<?php /**PATH /home/zedarroot/public_html/edwulp/resources/views/adds/add-company-chart-of-account.blade.php ENDPATH**/ ?>