<?php $__env->startSection('title', 'Payable Date Report'); ?>

<?php $__env->startPush('css'); ?>
<!-- bootstrap-datetimepicker -->
<!--<link rel="stylesheet" href="<?php echo e(asset('myfile/backend/assets/datepicker/zebra_datepicker.min.css')); ?>" type="text/css">
	<link rel="stylesheet" href="<?php echo e(asset('myfile/backend/assets/datepicker/examples.css')); ?>" type="text/css">-->
	<link rel="stylesheet" href="<?php echo e(asset('backend/plugins/select2.min.css')); ?>">
	<style>
		.search_btn{
			margin-top:24px;
		}
	</style>
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>
<div class="right_col" role="main">
    <div class="">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2 class="widget-title">Payable Date</h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li>
                                <a class="collapse-link" onclick="printDiv('printableArea')">
                                    <i class="fa fa-1x fa-print"></i>
                                </a>
                            </li>
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                                    aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                <ul class="dropdown-menu" role="menu">
                                    <li><a href="#">Settings 1</a></li>
                                    <li><a href="#">Settings 2</a></li>
                                </ul>
                            </li>
                            <li><a class="close-link"><i class="fa fa-close"></i></a></li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="row">
                        <div class="col-md-12 col-sm-12 col-xs-12">
                            <div class="x_content" id="printableArea">
                                <form id="demo-form2" action="<?php echo e(route('account.payable_dates')); ?>" method="Get" data-parsley-validate class="form" autocomplete="off" >
    								<div class="row">
    									<div class="col-sm-2"></div>
    									<div class="col-sm-2">
    										<div class="form-group">
    											<label>Record Period </label>
    											<select name="number_of_day" id="days" class="form-control select2">
    												<option value="1" <?php echo request()->number_of_day == 1 ? 'selected' : ''; ?> >Todays</option>
    												<option value="7" <?php echo request()->number_of_day == 7 ? 'selected' : ''; ?> >Last 7 Days</option>
    												<option value="15" <?php echo request()->number_of_day == 15 ? 'selected' : ''; ?> >Last 15 Days</option>
    												<option value="30" <?php echo request()->number_of_day == 30 ? 'selected' : ''; ?> >Last 30 Days</option>
    												<option value="60" <?php echo request()->number_of_day == 60 ? 'selected' : ''; ?> >Last 60 Days</option>
    												<option value="90" <?php echo request()->number_of_day == 90 ? 'selected' : ''; ?> >Last 90 Days</option>
    											</select>
    										</div>
    									</div>
    									<div class="col-sm-2">
    										<div class="form-group">
    											<label>Report Type</label>
    											<select class="form-control select2" name="report_type">
    												<option value="Payable" <?php echo request()->report_type == 'Payable' ? 'selected' : ''; ?> >Payable Customer</option>
    												<option value="No Payment" <?php echo request()->report_type == 'No Payment' ? 'selected' : ''; ?> >No Payment</option>
    											</select>
    										</div>
    									</div>
    									<div class="col-sm-1">
    										<div class="form-group">
    											<button class="btn btn-primary btn-xs search_btn" id="search_btn">
    												<i class="ace-icon fa fa-search fa-2x icon-only"></i>
    											</button>
    										</div>
    									</div>
    									<div class="col-sm-1">
    										<a href="#" id="search-btn" class="btn btn-primary btn-xs search_btn" onclick="printDiv('printableArea')">
    											<i class="ace-icon fa fa-print fa-2x icon-only"></i>
    										</a>
    									</div>
    									<div class="col-sm-4">
                                            <div class="input-group">
                                                <input type="text" id="myInput" class="form-control search_btn" placeholder="Filter Row" autocomplete="off">
                                                <span class="input-group-btn ">
                                                    <button type="button" class="btn btn-primary search_btn">
                                                    <span class="ace-icon fa fa-search icon-on-right bigger-110"></span></button>
                                                </span>
                                            </div>
                                        </div>
    								</div>
    							</form>
    							<hr/>
                                <div class="row">
                                    <div class="col-xs-1"></div>
                                    <div class="col-xs-1">
                                        <img src="<?php echo e(asset('storage/about/'.about()->logo)); ?>" class="img-responsive img-thumbnail" alt="logo" width="85px" height="75px">
                                    </div>
                                    <div class="col-xs-8">
                                        <div class="text-center">
                                            <h4><?php echo e(about()->english_name); ?></h4>
                                            <h5>
                                                <?php if(request()->report_type == 'Payable'): ?> 
                                                Todays
                                                <?php else: ?>
                                                Last <?php echo e(request()->number_of_day); ?> Days 
                                                <?php endif; ?>
                                                <?php echo e(request()->report_type); ?> Report
                                            </h5>
                                            <p>Date: <?php echo e(date('d-m-Y')); ?></p>
                                        </div>
                                    </div>
                                    <div class="col-xs-2"></div>
                                </div>
                                <div class="table-responsive">
                                    <?php if(!empty($reports)): ?>
                                    <table class="table table-bordered table-condensed">
                                        <thead>
                                            <tr>
                                                <th>SL</th>
                                                <th>Customer</th>
                                                <th>Phone</th>
                                                <th>Address</th>
                                                <th>Total Sale</th>
                                                <th>Payment</th>
                                                <th>Due</th>
                                                <th>N:Date</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php $__currentLoopData = $reports; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $l=>$rp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr id="<?php echo e($rp->customer_id); ?>" >
                                                <td><?php echo e($l+1); ?></td>
                                                <td><a href="<?php echo e(url('csrs').'?customer_id='.$rp->customer_id.'&report_type=Invoice'); ?>" target="_blank"><?php echo e($rp->customer_name); ?></a></td>
                                                <td><a href="<?php echo e(url('csrs').'?customer_id='.$rp->customer_id.'&report_type=Payment'); ?>" target="_blank"><?php echo e($rp->phone); ?></a></td>
                                                <td><a href="<?php echo e(url('csrs').'?customer_id='.$rp->customer_id.'&report_type=Record'); ?>" target="_blank"><?php echo e($rp->address); ?></a></td>
                                                <td><a href="<?php echo e(url('csrs').'?customer_id='.$rp->customer_id.'&report_type=Product'); ?>" target="_blank"><?php echo e($rp->total_amount); ?></a></td>
                                                <td><a href="<?php echo e(url('csrs').'?customer_id='.$rp->customer_id.'&report_type=Statement'); ?>" target="_blank"><?php echo e($rp->total_payment); ?></a></td>
                                                <td><a href="<?php echo e(url('csrs').'?customer_id='.$rp->customer_id.'&report_type=Sales_Due'); ?>" target="_blank"><?php echo e($rp->total_due); ?></a></td>
												<td>
												    <input type="date" class="dateField" id="date_<?php echo e($rp->customer_id); ?>" >
												    <input type="hidden" class="" id="due_<?php echo e($rp->customer_id); ?>" value="<?php echo e($rp->total_due); ?>"  >
												</td>
												<td>
												    <button class="updateBtn"  value="<?php echo e($rp->customer_id); ?>" >Update</button>
												</td>
                                            </tr>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
												<th colspan="4">Total:</th>
												<th><?php echo e($reports->sum('total_amount')); ?></th>
												<th><?php echo e($reports->sum('total_payment')); ?></th>
												<th><?php echo e($reports->sum('total_due')); ?></th>
												<th></th>
											</tr>
                                        </tbody>
                                    </table>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

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

<!-- Jquery Plugin For Date Calender-->
<!--<script type="text/javascript" src="<?php echo e(asset('myfile/backend/assets/datepicker/zebra_datepicker.src.js')); ?>"></script>
<script type="text/javascript" src="<?php echo e(asset('myfile/backend/assets/datepicker/examples.js')); ?>"></script>-->
<script type="text/javascript" src="<?php echo e(asset('myfile/backend/assets/js/bootstrap-notify.min.js')); ?>" ></script>
<script src="<?php echo e(asset('backend/plugins/select2.min.js')); ?>"></script>
<script>
    $(document).ready(function() {
        // select2 section
         $('.select2').select2();
        
        // Get all date input fields
        /*var dateInputs = document.querySelectorAll(".dateField");
        // Get the current date
        var today = new Date().toISOString().split('T')[0];
        // Set the minimum date for each input field
        dateInputs.forEach(function(input) {
            input.setAttribute("min", today);
        });*/
    
    });
    
    $(document).on('click','.updateBtn',function(){
        var id = $(this).val();
        var date = $("#date_"+id).val();
        var due = $("#due_"+id).val();
       // console.log(date);
        if(date != ''){
            var token = "<?php echo e(csrf_token()); ?>";
            $.ajax({
                url: "<?php echo e(route('account.date_update')); ?>",
                type: "Get",
                data: { cid: id,pdate:date,due:due,'_token': token },
                success: function(response){
                    // console.log(response);
                    $.notify({icon: 'glyphicon glyphicon-star',message: 'Next Payment Date Update Successfull',},{placement: {from: "bottom",align: "right"},type:'success',});
                },
                error: function(error){
                    console.log(error);
                    $.notify({icon: 'glyphicon glyphicon-star',message: 'Next Payment Date Update Fail',},{placement: {from: "bottom",align: "right"},type:'error',});
                }
            });
        }else{
            $.notify({icon: 'glyphicon glyphicon-star',message: 'Woops! Please select date first',},{placement: {from: "bottom",align: "right"},type:'error',});
        }
    });
    
    function printDiv(divName) {
        var printContents = document.getElementById(divName).innerHTML;
        var originalContents = document.body.innerHTML;
        document.body.innerHTML = printContents;
        window.print();
        document.body.innerHTML = originalContents;
    }
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('backend.layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>