<?php $__env->startSection('title'); ?>
    <title>Application Users</title>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('banner'); ?>
    <?php echo $__env->make('backend.partials.banner', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('menu'); ?>
    <div class="col-md-10 col-md-offset-1" style="background-color: #7ebb7b">
        <div class="breadcrumbs">
            <div class="container">
                <div class="row">
                    <div class="col-sm-8">
                        <ul>
                            <li><a href="<?php echo url('admin.home'); ?>">Home</a></li>
                            <li class="active">Delivery</li>
                        </ul><!-- end breadcrumb -->
                    </div><!-- end col -->
                </div><!-- end row -->
            </div><!-- end container -->
        </div><!-- end breadcrumbs -->
    </div>
<?php $__env->stopSection(); ?>

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


    <meta name="csrf-token" content="<?php echo e(csrf_token()); ?>">

    <?php echo $__env->make('backend.messages.flashmessage', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

    <div>

        <div class="container spark-screen">
            <div class="row">
                <div class="col-md-6 col-md-offset-2">
                    <br/>
                    <div><h3>Delivery Sales : <?php echo $invoiceno; ?></h3></div>
                    <div style="background-color: #ff0000;height: 2px">&nbsp;</div>
                    <br/>


                    <div class="search" id="search">
                        <br/>
                        <?php echo Form::open(['url'=>'delivery.invoice.index', 'method' => 'GET']); ?>


                        <table width="50%" class="table table-responsive table-hover" >

                            <tr>
                                <td width="5%"><label for="type" class="control-label">Invoice No</label></td>
                                <td width="10%"><?php echo Form::select('invoiceno',(['' => 'Please Select'] + $sales), null , array('id' => 'invoiceno', 'class' => 'form-control')); ?></td>
                                <td width="10%"><button name="submittype" type="submit" value="print" class="btn btn-primary btn-approve pull-right">Submit</button></td>
                            </tr>

                        </table>

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


                    </div>
                </div>

                <div style="width: 5px"></div>
            </div>
        </div>
    </div>
    <?php $item_row = 0; ?>
    <?php if(!empty($data)): ?>
        <?php echo Form::open(['url'=>'delivery.invoice.create']); ?>

        <?php echo e(csrf_field()); ?>

        <?php echo Form::hidden('invoiceno',$invoiceno); ?>

        <div class="form-group col-md-12" style="background-color: rgba(177, 245, 174, 0.33)">
            <?php echo Form::label('items', 'Items', ['class' => 'control-label']); ?>

            <div class="table-responsive">
                <table class="table table-bordered" id="items">
                    <thead>
                    <tr style="background-color: #f9f9f9;">
                        <th width="40%" class="text-left">Product</th>
                        <th width="20%" class="text-left">Invoice Qty</th>
                        <th width="20%" class="text-right">Delivery Qty</th>
                        <th width="20%" class="text-right">Return</th>
                    </tr>
                    </thead>
                    <tbody>

                    <?php $__currentLoopData = $data->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                        <tr id="item-row-<?php echo e($item_row); ?>">
                            <td>
                                <span><?php echo $row->item->name; ?></span>
                                <input value="<?php echo $row->product_id; ?>" name="item[<?php echo e($item_row); ?>][item_id]" type="hidden" id="item-id-<?php echo e($item_row); ?>">
                                <input value="<?php echo $row->id; ?>" name="item[<?php echo e($item_row); ?>][tr_id]" type="hidden" id="item-trid-<?php echo e($item_row); ?>">
                                <input name="item[<?php echo e($item_row); ?>][quantity]" type="hidden" id="item-quantity-<?php echo e($item_row); ?>" value="<?php echo $row->quantity; ?>">
                                <input name="item[<?php echo e($item_row); ?>][price]" type="hidden" id="item-price-<?php echo e($item_row); ?>" value="<?php echo $row->unit_price; ?>">
                                <input name="item[<?php echo e($item_row); ?>][tax_id]" type="hidden" id="item-tax_id-<?php echo e($item_row); ?>" value="<?php echo $row->tax_id; ?>">

                            </td>
                            <td>
                                <span><?php echo $row->quantity; ?> <?php echo $row->item->unit_name; ?></span>
                            </td>
                            <td>
                                <input class="form-control receive text-right" required="required" name="item[<?php echo e($i); ?>][receive]" type="text" id="item-receive-<?php echo e($item_row); ?>" value="<?php echo $row->quantity; ?>">
                            </td>

                            <td>
                                <input class="form-control text-right" required="required" name="item[<?php echo e($item_row); ?>][return]" type="text" id="item-return-<?php echo e($item_row); ?>"value="<?php echo 0; ?>" readonly>
                            </td>

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


                    </tbody>
                </table>
            </div>

            <div class="col-md-6">
                <?php echo Form::submit('SUBMIT',['class'=>'btn btn-primary button-control']); ?>

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


            <?php echo Form::open(['url'=>'admin.home', 'method' => 'GET']); ?>


            <div class="col-md-6">
                <?php echo Form::submit('EXIT',['class'=>'btn btn-primary button-control pull-right']); ?>

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


        </div>

    <?php endif; ?>

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

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

<script type="text/javascript">

    var item_row = '<?php echo e($item_row); ?>';

    $(document).ready(function(){
        //Date picker
        var minday = new Date();

        $('#pdate').datepicker({
            numberOfMonths: 1,
            showButtonPanel: true,
            minDate: minday,
            dateFormat: 'dd/mm/yy',
            maxDate: minday
        });

        $(document).on('keyup', '#items tbody .form-control', function(){
            returned();
        });
    });

    function returned() {

        for(i=0; i< item_row; i++)
        {
            document.getElementById('item-return-'+ i).value = document.getElementById('item-quantity-'+ i).value - document.getElementById('item-receive-'+ i).value
        }

    }

    $(function (){
        $(document).on("focus", "input:text", function() {
            $(this).select();
        });
    });

</script>

<?php $__env->stopPush(); ?>
<?php echo $__env->make('backend.layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>