<?php $__env->startSection('main-body'); ?>
<div class="container-fluid">
    <div class="page-header">
        <div class="row">
            <div class="col-sm-12">
                <h3>Create Disbursement</h3>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="/">Dashboard</a></li>
                    <li class="breadcrumb-item"><a href="/disbursements">Disbursements</a></li>
                    <li class="breadcrumb-item active">Create</li>
                </ol>
            </div>
        </div>
    </div>
</div>
<div class="row gutters">
    <?php echo Form::open(['route' => 'disbursements.filter', 'method' => 'POST']); ?>

    <div class="col-sm-12 col-xl-12 box-col-12">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body mt-4">
                        <div class="row gutters">
                            <div class="col-xl-4 col-lg-4 col-md-4 col-sm-4 col-12">
                                <div class="form-group">
                                    <?php echo Form::label('professional_id', 'Professionals'); ?>

                                    <?php echo Form::select('professional_id', $professionals, $selectedProfessional, ['class' => 'form-control', 'id' => 'professionalId','placeholder'=>'Select Professional', 'onchange'=>"checkProfessional()"]); ?>

                                </div>
                            </div>
                            <div class="col-xl-4 col-lg-4 col-md-4 col-sm-4 col-12">
                                <div class="form-group">
                                    <?php echo Form::label('date', 'Date'); ?>

                                    <?php echo Form::text('date', $dateFilter, ['class' => 'form-control digits', 'required' => 'required', 'id' => 'reportrange']); ?>

                                </div>
                            </div>
                            <div class="col-xl-4 col-lg-4 col-md-4 col-sm-4 col-12">
                                <div class="form-group" style="margin-top: 25px;">
                                    <button style="margin-right:5px; margin-bottom: 10px;" class="btn btn-primary" type="submit" name="type" value="search" disabled id="searchBtn">
                                        <span class="icon-search1"></span> Search
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php echo Form::close(); ?>

</div>
<?php if(count($transactions) > 0): ?>
<div class="row gutters" id="transactions-body">
    <div class="row">
        <?php echo Form::open(['route' => 'disbursements.disburse', 'method' => 'POST', 'files' => 'true']); ?>

        <div class="col-sm-12 col-xl-12 box-col-12">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table custom-table">
                            <thead>
                                <tr>
                                    <th><input class="checkbox_animated check_all" id="check-all-transactions" type="checkbox" onchange="clickTransactions()"></th>
                                    <th>Invoice#</th>
                                    <th>Completion Date</th>
                                    <th>Professional Fee</th>
                                    <th>Desxpert Fee</th>
                                    <th>Net Pay</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td>
                                        <input class="checkbox_animated check_trans" id="transaction-<?php echo e($transaction->transaction_id); ?>"
                                             type="checkbox" name="transactions[]" value="<?php echo e($transaction->payment_id); ?>" onclick="computePayout(this)"
                                             data-value="<?php echo e($transaction->professional_fee); ?>"
                                        >
                                    </td>
                                    <td><?php echo $transaction->invoice; ?></td>
                                    <td><?php echo $transaction->completion_date; ?></td>
                                    <td><?php echo number_format($transaction->amount - $transaction->convenience_fee, 2); ?></td>
                                    <td><?php echo number_format($transaction->desxpert_fee, 2); ?></td>
                                    <td><?php echo number_format($transaction->professional_fee, 2); ?></td>
                                </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <?php endif; ?>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td>
                                        <h5>Total</h5>
                                    </td>
                                    <td style="color:green">
                                        <h5 id="totalPayout">0.00</h5>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-12 col-xl-12 box-col-12">
            <div class="card">
                <div class="card-body">
                    <div class="row">
                        <div class="col-lg-4">
                            <div class="form-group">
                                <?php echo Form::label('reference_no', 'Deposit Reference #'); ?>

                                <?php echo Form::text('reference_no', '', ['class' => 'form-control', 'required' => 'required', 'maxlength' => '255', 'id' => 'reference_no']); ?>

                            </div>
                        </div>
                        <div class="col-lg-4">
                            <div class="form-group">
                                <?php echo Form::label('mop', 'Mode of Payment'); ?>

                                <?php echo Form::text('mop', '', ['class' => 'form-control', 'required' => 'required', 'maxlength' => '255', 'id' => 'mop']); ?>

                            </div>
                        </div>
                        <div class="col-lg-4">
                            <div class="form-group">
                                <?php echo Form::label('account_no', 'Account No.'); ?>

                                <?php echo Form::text('account_no', '', ['class' => 'form-control', 'required' => 'required', 'maxlength' => '255', 'id' => 'account_no']); ?>

                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4">
                        <div class="form-group">
                            <?php echo Form::label('attachment', 'Attachment'); ?>

                            <?php echo Form::file('attachment', ['class' => 'form-control', 'required' => 'required', 'id' => 'attachment']); ?>

                        </div>
                    </div>
                    <div class="col-lg-12">
                        <div class="form-group">
                            <?php echo Form::hidden('total_payout', '0.00', ['id' => 'total_payout']); ?>

                            <?php echo Form::hidden('professional_id', '', ['id' => 'selectedProfessional']); ?>

                            <?php echo Form::hidden('date_period', '', ['id' => 'datePeriod']); ?>

                            <button class="btn btn-primary action-btn" id="submit-btn">Submit</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php echo Form::close(); ?>

    </div>
</div>
<!-- Container-fluid Ends-->
<?php else: ?>
<?php endif; ?>
<?php echo $__env->make('modals.confirmation', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('import-scripts'); ?>
<script src="/assets/js/field-validations.js"></script>
<script src="/assets/js/checkbox.js"></script>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('page-script'); ?>

initiateSearchBtn();

initiateFormValues();

checkIfThereIsTransaction();

function clickTransactions() {

    let checkAll = $('#check-all-transactions').prop('checked');
    $('.check_trans').prop('checked', checkAll);
    let payout = 0
    if (checkAll) {
        $('.check_trans').each(function() {
                payout += parseFloat($(this).data('value'));
        });
        $('#totalPayout').html(parseFloat(payout).toFixed(2))
    } else {
        $('#totalPayout').html(parseFloat(0).toFixed(2))
    }

    $('#total_payout').val(parseFloat(payout).toFixed(2))

    initiateFormValues();

    checkIfThereIsTransaction();
}

function computePayout(elem) {
    let isChecked = $('#'+elem.id).prop('checked');
    let transactionAmount =  parseFloat($('#'+elem.id).data('value'));
    let payout = parseFloat($('#totalPayout').html());

    let newTotal = isChecked ? payout + transactionAmount : payout - transactionAmount;

    $('#totalPayout').html(newTotal.toFixed(2))

    if ($('.check_trans:checked').length == $('.check_trans').length) {
        $('#check-all-transactions').prop('checked', true);
    } else {
        $('#check-all-transactions').prop('checked', false);
    }

    $('#total_payout').val(newTotal.toFixed(2))

    initiateFormValues();

    checkIfThereIsTransaction();
}

function initiateSearchBtn() {
    let professional = $('#professionalId').val()
    if (!professional) {
        $('#searchBtn').prop('disabled', true)
    } else {
        $('#searchBtn').prop('disabled', false)
    }
}

function initiateFormValues() {
    $('#selectedProfessional').val($('#professionalId').val())
    $('#datePeriod').val($('#reportrange').val())
}

function checkProfessional() {
    initiateSearchBtn();
    $('#transactions-body').html('')
}

function checkIfThereIsTransaction() {
    console.log($('.check_trans:checked').length)
    if ($('.check_trans:checked').length > 0) {
        $('#submit-btn').prop('disabled', false)
    } else {
        $('#submit-btn').prop('disabled', true)
    }
}

function cancelForm(elem) {
    window.location.replace('/disbursements')
}


<?php echo $__env->make('notifications.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/prod/desxpert-admin/resources/views/disbursements/create.blade.php ENDPATH**/ ?>