<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        
        <div class="row">
            <div class="col-sm-12">
                <div class="pull-right m-t-15">     
                    <?php if(isset($startdate)){?>
                    <form method="Post" action="<?php echo base_url()."adjustments";?>">
                        <div id="reportrange" name="reportrange" class="form-control" style="display:inline">
                           <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
                           <span></span>
                        </div>
                        <input type="hidden" name="startdate" id="startdate" value="<?php echo $startdate;?>"><input type="hidden" name="enddate" id="enddate" value="<?php echo $enddate;?>">
                        <button type="submit" class="btn btn-sm btn-pink btn-bordred waves-effect w-md waves-light m-l-5">Run</button>   
                    </form>
                     <?php }?>
                </div>
                <h4 class="page-title">Adjustment Notes:</h4>
            </div>
        </div>
       
        <div class="row">
            <div class="col-sm-12">
                <div class="card-box table-responsive">

                    <h4 class="header-title m-t-0 m-b-30">&nbsp;</h4>

                    <table id="tblreport" class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>ID</th>
                                
                                <th>Product ID</th>
                                <th>Brand</th>
                                <th>Product</th>
                                <th>ID / Batch</th>
                                <th>Store</th>
                                <th>By</th>
                                 <th>Adj. Date</th>
                                <th>Adj. Qty</th>
                                <th>Adj. Rate</th>
                                <th>Adj. Value</th>
                                <th>Adj. Remarks</th>
                            </tr>
                        </thead>

                         <tbody>
                            <?php $adj_value=0; $adj_qty=0; $adj_rate=0; foreach ($adjnotes as $an){?>
                            <tr>
                                <td><?php echo $an['id_adjustment_notes'];?></td>                                
                                <td><?php echo $an['id_business_products'];?></td>
                                <td><?php echo $an['business_brand_name'];?></td>
                                <td><?php echo $an['product'];?></td>
                                <td><?php echo $an['id_batch'].' / '.$an['batch_number'];?></td>
                                <td><?php echo $an['business_store'];?></td> 
                                <td><?php echo $an['by'];?></td> 
                                <td><?php echo $an['adj_date'];?></td> 
                                <td style="text-align: right;"><?php echo $an['adjustment_qty']; $adj_qty=$adj_qty+$an['adjustment_qty']; ?></td> 
                                <td style="text-align: right;"><?php echo $an['rate']; $adj_rate=$adj_rate+$an['rate'];?></td> 
                                <td style="text-align: right;"><?php echo $an['adj_value']; $adj_value=$adj_value+$an['adj_value'];?></td> 
                                <td><?php echo $an['adjustment_remarks'];?></td> 
                            </tr>
                            <?php } ?>
                        </tbody>
                        <tfoot>
                            <th>ID</th>
                                
                                <th>Product ID</th>
                                <th>Brand</th>
                                <th>Product</th>
                                <th>ID / Batch</th>
                                <th>Store</th>
                                <th>By</th>
                                 <th>Adj. Date</th>
                                <th>Adj. Qty</th>
                                <th>Adj. Rate</th>
                                <th><strong><?php echo $adj_value;?></strong></th>
                                <th>Adj. Remarks</th>
                        </tfoot>
                    </table>
                </div>
            </div><!-- end col -->
        </div>
        <!-- end row -->
        
    </div>
    <script>
        $(document).ready(function() {
            <?php if(isset($startdate)){?>
               var startdate = '<?php echo date('F j, Y', strtotime($startdate)); ?>';
                var enddate = '<?php echo date('F j, Y', strtotime($enddate)); ?>';
                $('#reportrange span').html(startdate + ' - ' + enddate);

                $('#reportrange').daterangepicker({
                    format: 'MM/DD/YYYY',
                    startDate: moment().subtract(15, 'days'),
                    endDate: moment(),
                    minDate: '01/01/2012',
                    maxDate: '12/31/2090',
        //                    dateLimit: {
        //                        days: 60
        //                    },
                    showDropdowns: true,
                    showWeekNumbers: true,
                    timePicker: false,
                    timePickerIncrement: 1,
                    timePicker12Hour: true,
                    ranges: {
                        'Today': [moment()],
                        'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                        'Last 7 Days': [moment().subtract(6, 'days'), moment().add(1, 'days')],
                        'Last 30 Days': [moment().subtract(29, 'days'), moment().add(1, 'days')],
                        'This Month': [moment().startOf('month'), moment().endOf('month')],
                        'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                    },
                    opens: 'left',
                    drops: 'down',
                    buttonClasses: ['btn', 'btn-sm'],
                    applyClass: 'btn-success',
                    cancelClass: 'btn-default',
                    separator: ' to ',
                    locale: {
                        applyLabel: 'Submit',
                        cancelLabel: 'Cancel',
                        fromLabel: 'From',
                        toLabel: 'To',
                        customRangeLabel: 'Custom',
                        daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
                        monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
                        firstDay: 1
                    }
                }, function(start, end, label) {
                    //console.log(start.toISOString(), end.toISOString(), label);
                    startdate = start;
                    enddate = end;
                    $("#startdate").val(startdate.format('YYYY-MM-DD'));
                    $("#enddate").val(enddate.format('YYYY-MM-DD'));
                    $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
                });
            <?php } ?>
            $('#tblreport').DataTable({
                    dom: "Bfrtlip",
                    buttons: [{extend: "copy", className: "btn-sm btn-custom btn-trans"}, {extend: "csv", className: "btn-sm btn-pink btn-trans"},
                        {extend: "excel", className: "btn-sm btn-warning btn-trans"}, {extend: "pdf", className: "btn-sm btn-purple btn-trans"}],
                    responsive: !0
                });
            });
        </script>