

<?php $__env->startSection('title'); ?>
    General Journal Entries
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
    <ol class="breadcrumb pull-right">
        <li><a href="<?php echo e(route('home')); ?>"><i class="fa fa-dashboard"></i> Home</a></li>

        <li class="active">General Journal Entries</li>
    </ol>
<?php $__env->stopSection(); ?>

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



    <link href="<?php echo e(asset('plugins/components/bootstrap-daterangepicker/daterangepicker.css')); ?>" rel="stylesheet">

    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />

    <style>
        .float {
            position: fixed;
            width: 160px;
            height: 40px;
            bottom: 40px;
            right: 40px;
            background-color: #003f5c;
            ;
            color: #FFF;
            border-radius: 50px;
            text-align: center;
            box-shadow: 2px 2px 3px #999;
            z-index: 999;
        }

        .my-float {
            margin-top: 22px;
        }

        .float:hover {
            color: #FFF;
            opacity: .8;
        }
    </style>
<?php $__env->stopSection(); ?>

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


    <div class="container-fluid">


        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('isSuperAdmin')): ?>
            <?php echo $__env->make('partial.multiproject_select', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <?php endif; ?>
        <?php if (\Illuminate\Support\Facades\Blade::check('permission', 'create-voucher')): ?>
            <a onclick="$('#voucher-form').submit()" href="#" class="float">
                <span style='line-height: 36px;'><i class="fa fa-money "></i> Make Voucher</span>
                
            </a>
        <?php endif; ?>



        <form id="voucher-form" method="post" action="<?php echo e(route('create-voucher')); ?>">
            <?php echo e(csrf_field()); ?>

            <input type="hidden" name="type" value="">
            <input type="hidden" name="id" value="">


        </form>


        <div id='updatecontent'>
            <div class="row" style="margin-top:25px;">

                <div class="col-md-12">
                    <div class="panel panel-info">
                        <div class="panel-heading">Customize Entries</div>
                        <div class="panel-wrapper collapse in" aria-expanded="true">
                            <div class="panel-body">
                                <form>
                                    <div class="form-body">
                                        <div class="row">

                                            <div class="col-md-4">

                                                <input type='hidden' name='multipro_id' value='all'
                                                    id='multipro_id_input'>

                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">By Account</label>
                                                    <div class="col-sm-8">
                                                        <div class="input-group">
                                                            <div class="input-group-addon">

                                                            </div>
                                                            <select class="form-control chosen-select" id="c_account">
                                                                <option value="0">None</option>
                                                                <?php $__currentLoopData = $accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ac): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <option value="<?php echo e($ac->id); ?>"><?php echo e($ac->number); ?>

                                                                        -
                                                                        <?php echo e($ac->name); ?></option>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>



                                            <div class="col-md-4">



                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">Date range</label>
                                                    <div class="col-sm-8">
                                                        <div class="input-group" id="date-div">
                                                            <div class="input-group-addon">
                                                                <i class="fa fa-calendar"></i>
                                                            </div>
                                                            <input type="text" class="form-control pull-right"
                                                                id="daterange-btn" name='date_range'>

                                                        </div>
                                                        <?php if($errors->has('date_range')): ?>
                                                            <span class="help-block">
                                                                <strong><?php echo e($errors->first('date_range')); ?></strong>
                                                            </span>
                                                        <?php endif; ?>
                                                    </div>
                                                    <!-- /.input group -->
                                                </div>
                                            </div>

                                            <div class="form-actions pull-right" style="margin-right: 30PX;">
                                                <button type="button" class="btn btn-success update-record"> <i
                                                        class="fa fa-check"></i> Update</button>
                                            </div>
                                        </div>

                                    </div>



                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--./row-->


            <div class="pull-right">


                <form class="form-inline" method="get" onsubmit="return getSearcableResult(this)"
                    style="position: relative;top: 50px; right: 2.2rem;z-index: 999;">
                    <div class="form-group mb-2">
                        <input type="search" name="search_voucher" id="search_voucher" class="form-control"
                            placeholder="Search By Type & Amount" style="width: 200px;">
                    </div>

                    <button type="submit" class="btn btn-success mb-2" style="padding: 8px;">Search</button>
                </form>


            </div>

            <!-- /row -->
            <div class="row" id="update-table">

                <div class="col-sm-12">
                    <div class="white-box">

                        <h3 class="box-title">List of General Journal Entries</h3>

                        <div class="table-responsive">

                            <table id="myTable" class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>Type</th>
                                        <th>Checked</th>
                                        <th>Posted</th>
                                        <th>Date</th>
                                        <th>Entry No.</th>
                                        <th>Cheque No.</th>
                                        <th>Receipt No.</th>
                                        <th>Account</th>
                                        <!-- <th>Narration</th> -->
                                        <!-- <th>Class</th> -->
                                        <th>Debit/Credit (+/-)</th>
                                        <th>Action</th>

                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $allEntries; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $entry): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr ondblclick="showEntry('<?php echo e($entry->entry_no); ?>')">

                                            <?php if($entry->voucher_type == \App\GeneralJournalEntry::CRV): ?>
                                                <td>CRV-<?php echo e($entry->voucher_no); ?></td>
                                            <?php elseif($entry->voucher_type == \App\GeneralJournalEntry::BRV): ?>
                                                <td>BRV-<?php echo e($entry->voucher_no); ?></td>
                                            <?php elseif($entry->voucher_type == \App\GeneralJournalEntry::CPV): ?>
                                                <td>CPV-<?php echo e($entry->voucher_no); ?></td>
                                            <?php elseif($entry->voucher_type == \App\GeneralJournalEntry::BPV): ?>
                                                <td>BPV-<?php echo e($entry->voucher_no); ?></td>
                                            <?php elseif($entry->voucher_type == \App\GeneralJournalEntry::JV): ?>
                                                <td>JV-<?php echo e($entry->voucher_no); ?></td>
                                            <?php else: ?>
                                                <td></td>
                                            <?php endif; ?>

                                            <td>
                                                <?php if($entry->is_check): ?>
                                                    <i class="fa fa-check" style="color:green"></i>
                                                <?php else: ?>
                                                    <i class="fa fa-close" style="color: red;"></i>
                                                <?php endif; ?>

                                            <td>
                                                <?php if($entry->is_post): ?>
                                                    <i class="fa fa-check" style="color:green"></i>
                                                <?php else: ?>
                                                    <i class="fa fa-close" style="color: red;"></i>
                                                <?php endif; ?>
                                            </td>

                                            <td><?php echo e(date('d/m/Y', strtotime($entry->date))); ?></td>
                                            <td class="text-right"><?php echo e($entry->entry_no); ?></td>
                                            <td>
                                                <?php echo e($entry->cheaque_no ? $entry->cheaque_no : ''); ?>

                                            </td>

                                            <td>
                                                <?php if($entry->dealer_package_voucher == 1): ?>
                                                    <?php if($entry->dealerReceipt): ?>
                                                        <a
                                                            href="<?php echo e(route('openfile.package.detailReceipt', [$entry->dealerReceipt->id])); ?>">
                                                            <?php echo e($entry->dealerReceipt->receipt_no); ?>

                                                        </a>
                                                    <?php endif; ?>
                                                <?php elseif($entry->customer_refund_unit == 1): ?>
                                                    <?php if($entry->customerUnitRefundReceipt): ?>
                                                        <a
                                                            href="<?php echo e(route('receipt.refund-openfile.detail', [$entry->customerUnitRefundReceipt->id])); ?>">
                                                            <?php echo e($entry->customerUnitRefundReceipt->receipt_no); ?>

                                                        </a>
                                                    <?php endif; ?>
                                                <?php elseif($entry->dealer_refund_openfile == 1): ?>
                                                    <?php if($entry->dealerOpenFileRefundReceipt): ?>
                                                        <a
                                                            href="<?php echo e(route('receipt.refund.detail', [$entry->dealerOpenFileRefundReceipt->id])); ?>">
                                                            <?php echo e($entry->dealerOpenFileRefundReceipt->receipt_no); ?>

                                                        </a>
                                                    <?php endif; ?>
                                                <?php elseif($entry->cancel_close_unit == 1): ?>
                                                    <?php if($entry->CustomerCancelUnitReceipt): ?>
                                                        <a
                                                            href="<?php echo e(route('receipt.cancel-closeunit.detail', [$entry->CustomerCancelUnitReceipt->id])); ?>">
                                                            <?php echo e($entry->CustomerCancelUnitReceipt->receipt_no); ?>

                                                        </a>
                                                    <?php endif; ?>
                                                    <?php elseif($entry->cancel_open_unit == 1): ?>
                                                    <?php if($entry->DealerOpenFileCancelReceipt): ?>
                                                        <a
                                                            href="<?php echo e(route('receipt.cancel-openunit.detail', [$entry->DealerOpenFileCancelReceipt->id])); ?>">
                                                            <?php echo e($entry->DealerOpenFileCancelReceipt->receipt_no); ?>

                                                        </a>
                                                    <?php endif; ?>
                                                <?php else: ?>
                                                    <?php if($entry->receipt): ?>
                                                        <a href="<?php echo e(route('receipt.detail', [$entry->receipt->id])); ?>">
                                                            <?php echo e($entry->receipt->receipt_no); ?>

                                                        </a>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            </td>

                                            <td><?php echo e($entry->account ? $entry->account->name : ''); ?></td>
                                            <!-- <td><?php echo e($entry->voucher ? $entry->voucher->narration : ''); ?></td> -->
                                            <!-- <td><?php echo e($entry->class ? $entry->class->name : ''); ?></td> -->
                                            <td class="text-right"><?php echo e(number_format($totalAmount[$entry->entry_no])); ?>

                                            </td>
                                            <td>
                                                <!-- <span onclick="showEntry('<?php echo e($entry->entry_no); ?>')" style="cursor: pointer;" class="btn btn-sm btn-primary"> Show</span> -->

                                                <?php if (\Illuminate\Support\Facades\Blade::check('permission', 'view-voucher')): ?>
                                                    <a href="<?php echo e(route('voucher-detail', ['id' => $entry->entry_no])); ?>"
                                                        class="btn btn-sm btn-default" style="background: #0282ca; color: white;">View</a>
                                                <?php endif; ?>

                                                <?php if(!$entry->is_post): ?>
                                                <?php if (\Illuminate\Support\Facades\Blade::check('permission', 'delete-voucher')): ?>
                                                    <a href="<?php echo e(route('voucher-delete', ['id' => $entry->entry_no])); ?>"
                                                        class="btn btn-sm btn-danger" data-toggle="confirmation"
                                                        data-placement="left" data-title="Are you sure to delete?">Delete</a>
                                                <?php endif; ?>
                                                <?php endif; ?>



                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                </tbody>
                            </table>
                            <?php echo e($allEntries->links()); ?>

                        </div>
                    </div>
                </div>
            </div>

        </div>
        <!-- /.row -->
    </div>
    <!-- /.container-fluid -->

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

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

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>

    <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>

    <script>
        function getSearcableResult(self) {
            $('.preloader').fadeIn();

            query = $(self).find('#search_voucher').val();

            var data = {
                'query': query
            };
            $.get('/general-journal-entries/update-query', data, function(data) {
                document.getElementById('update-table').innerHTML = data;

                $('#myTable').DataTable({
                    'paging': false,
                    'searching': false,
                    'info': true
                });
                $('.preloader').fadeOut();
            });


            return false;
        }



        function callFunction() {
            $(function() {
                $('#myTable').DataTable({
                    'pageLength': 50,
                    'paging': false,
                    'ordering': false,
                    'searching': false,
                    'info': false,
                });

            });
            const year = new Date().getFullYear();

            const this_fiscal_year_start_date = new Date(year + '-' + <?php echo e(\App\ChartOfAccount::FISCAL_YEAR_START); ?> +
            '-01');

            const this_fiscal_year_end_date = new Date((year + 1) + '-' + <?php echo e(\App\ChartOfAccount::FISCAL_YEAR_END); ?> +
                '-30');

            const last_fiscal_year_start_date = new Date((year - 1) + '-' + <?php echo e(\App\ChartOfAccount::FISCAL_YEAR_START); ?> +
                '-01');

            const last_fiscal_year_end_date = new Date(year + '-' + <?php echo e(\App\ChartOfAccount::FISCAL_YEAR_END); ?> + '-30');




            $('#daterange-btn').daterangepicker({
                    ranges: {
                        'Today': [moment(), moment()],
                        'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                        'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                        'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                        'This Month': [moment().startOf('month'), moment().endOf('month')],
                        'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month')
                            .endOf(
                                'month')
                        ],
                        'This Fiscal Year': [this_fiscal_year_start_date, this_fiscal_year_end_date],
                        'Last Fiscal Year': [last_fiscal_year_start_date, last_fiscal_year_end_date]
                    },
                    startDate: moment().subtract(29, 'days'),
                    endDate: moment()
                },
                function(start, end) {
                    $('#daterange-btn span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
                }
            );

            $('.update-record').on('click', function() {

                $('.preloader').fadeIn();

                date_range = $('#daterange-btn').val();
                account = $('#c_account').val();
                name = $('#c_name').val();
                multipro_id = $('#multipro_id_input').val();



                var data = {
                    'date_range': date_range,
                    'account': account,
                    'name': name,
                    'multipro_id': multipro_id
                };
                $.get('/general-journal-entries/update-entries', data, function(data) {
                    document.getElementById('update-table').innerHTML = data;

                    $('#myTable').DataTable({
                        'paging': false,
                        'searching': false,
                        'info': true
                    });
                    toastr.success("Report updated.");
                });

                $('.preloader').fadeOut();
            });
        }
        callFunction();

        function addDebit() {
            sum = 0;
            $('.debit').each(function() {
                if (this.innerHTML) {
                    sum += parseInt(this.innerHTML);
                }
            });
            document.getElementById('debit-total').innerHTML = sum;
            checkTotal();
        }

        function addCredit() {
            sum = 0;
            $('.credit').each(function() {
                if (this.innerHTML) {
                    sum += parseInt(this.innerHTML);
                }
            });
            document.getElementById('credit-total').innerHTML = sum;
            checkTotal();
        }

        function checkTotal() {

            debit = parseInt(document.getElementById('debit-total').innerHTML);
            credit = parseInt(document.getElementById('credit-total').innerHTML);
            if (debit == credit) {
                $("#search").prop("disabled", false);

                document.getElementById('debit-total').style.color = 'black';
                document.getElementById('credit-total').style.color = 'black';
                $("#update").prop("disabled", false);
            } else {
                $("#search").prop("disabled", true);

                document.getElementById('debit-total').style.color = 'red';
                document.getElementById('credit-total').style.color = 'red';
                $("#update").prop("disabled", false);
            }

        }

        $('#search').click(function() {

            date = $('#date').val();
            entry_no = $('#entry_no').val();
            adjusting_entry = 0;
            if ($('#adjusting_entry').prop("checked") == true) {
                adjusting_entry = 1;
            }
            account = [];
            $('select[name="account[]"]').each(function() {
                if ($(this).val() != 0)
                    account.push($(this).val());
            });
            name1 = [];
            $('select[name="name1[]"]').each(function() {
                name1.push($(this).val());
            });

            class_id = [];
            $('select[name="class_id[]"]').each(function() {
                class_id.push($(this).val());
            });

            debit = [];
            $('.debit').each(function() {
                if (this.innerHTML) {
                    debit.push(parseInt(this.innerHTML));
                }
            });

            credit = [];
            $('.credit').each(function() {
                if (this.innerHTML) {
                    credit.push(parseInt(this.innerHTML));
                }
            });

            memo = [];
            $('.memo').each(function() {
                if (this.innerHTML) {
                    memo.push(this.innerHTML);
                }
            });

            data = {
                'date': date,
                'entry_no': entry_no,
                'adjusting_entry': adjusting_entry,
                'account': account,
                'debit': debit,
                'credit': credit,
                'memo': memo,
                'name': name1,
                'class_id': class_id
            };

            $.get('/general-journal-entries/add', data, function(data) {

                toastr.success("Entry added successfully.");

                window.location.reload(1);
            });
        });

        function updateEntry() {

            date = $('#date').val();
            entry_no = $('#entry_no').val();
            adjusting_entry = 0;
            if ($('#adjusting_entry').prop("checked") == true) {
                adjusting_entry = 1;
            }
            account = [];
            $('select[name="account[]"]').each(function() {
                if ($(this).val() != 0)
                    account.push($(this).val());
            });
            name1 = [];
            $('select[name="name1[]"]').each(function() {
                name1.push($(this).val());
            });

            class_id = [];
            $('select[name="class_id[]"]').each(function() {
                class_id.push($(this).val());
            });

            debit = [];
            $('.debit').each(function() {
                if (this.innerHTML) {
                    debit.push(parseInt(this.innerHTML));
                }
            });

            credit = [];
            $('.credit').each(function() {
                if (this.innerHTML) {
                    credit.push(parseInt(this.innerHTML));
                }
            });

            memo = [];
            $('.memo').each(function() {
                if (this.innerHTML) {
                    memo.push(this.innerHTML);
                }
            });

            data = {
                'date': date,
                'entry_no': entry_no,
                'adjusting_entry': adjusting_entry,
                'account': account,
                'debit': debit,
                'credit': credit,
                'memo': memo,
                'name': name1,
                'class_id': class_id
            };

            $.get('/general-journal-entries/update', data, function(data) {

                toastr.success("Entry updated successfully.");

                window.location.reload(1);
            });
        }

        function approveEntry() {


            entry_no = $('#entry_no').val();


            data = {
                'entry_no': entry_no
            };

            $.get('/general-journal-entries/approve-entry', data, function(data) {

                toastr.success("Entry updated successfully.");

                window.location.reload(1);
            });
        }


        function showEntry(entry_no) {

            data = {
                'entry_no': entry_no
            };

            $.get('/general-journal-entries/show', data, function(data) {

                document.getElementById('form-div').innerHTML = data;

                $('.chosen-select').chosen - select();

                $(window).scrollTop(0);

            });


        }

        function approveEntryModal(entry_no) {

            data = {
                'entry_no': entry_no
            };

            $.get('/general-journal-entries/approve-modal', data, function(data) {

                document.getElementById('form-div').innerHTML = data;

                $('.chosen-select').chosen - select();

                $(window).scrollTop(0);

            });


        }

        function deleteEntry(entry_no) {

            $.confirm({
                title: 'Confirm!',
                content: 'You cannot revert this.Do you want to proceed!.',
                buttons: {
                    confirm: function() {
                        data = {
                            'entry_no': entry_no
                        };
                        $.get('/general-journal-entries/delete', data, function(data) {
                            toastr.success("Entry deleted successfully.");
                            window.location.reload(1);
                        });
                    },
                    cancel: function() {

                    }
                }
            });



        }


        function updateStatus(value) {
            $('.preloader').fadeIn();

            if (value === 'search') {

                $('.preloader').fadeOut();
                return false;
            }
            var data = {
                'multipro_id': value,
            };

            $.get('<?php echo e(route('entry.all')); ?>', data, function(data) {
                $('.preloader').fadeOut();
                $('#myTable tbody').empty();



                document.getElementById('updatecontent').innerHTML = data;




                $('#multipro_id_input').val(value);
                callFunction();
                toastr.success("Search updated.");


                $('.preloader').fadeOut();
            });

        }
    </script>

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

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\erpv7\resources\views/general-entry/index.blade.php ENDPATH**/ ?>