<?php
$this->load->view ( $left );
$this->load->view ( $header );
?>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-12">
        <h2>Customer Sales</h2>
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="row text-center animated fadeInRightBig">
        <div class="ibox float-e-margins">
            <div class="ibox-content" style="padding: 15px 20px 15px 20px;">
                <div class="row">
                    <div class="col-lg-4">
                        <label class="col-lg-4 m-t-xs">From</label>
                        <div class="date_calender col-lg-8">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" name="start_date" id="start_date" class="form-control" value="<?php echo (!empty($start_date) ? date('d/m/Y',strtotime(str_replace('/', '-', $start_date))) : date('d/m/Y'));?>">
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4">
                        <label class="col-lg-4 m-t-xs">To</label>
                        <div class="date_calender col-lg-8">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" name="end_date" id="end_date" class="form-control" value="<?php echo (!empty($end_date) ? date('d/m/Y',strtotime(str_replace('/', '-', $end_date))) : date('d/m/Y'));?>">
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4"><button type="button" class="btn btn-info generate_report"><i class="fa fa-search"></i> Search</button></div>
                </div>
            </div>
        </div>
        <div class="ibox float-e-margins">
            <div class="ibox-content" style="padding: 15px 20px 15px 20px;">
                <div class="row">
                    <table class="table" id="myTable">
                        <thead>
                            <tr>
                                <th>Item Name</th>
                                <th>Date added</th>
                                <th>Quantity</th>
                                <th>Manufacturing Cost /Unit</th>
                                <th>Rhodium Cost /Unit</th>
                                <th>Total Manufacturing</th>
                                <th>Total Rhodium</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                            if (count($expence) > 0) {
                                foreach ($expence as $key => $value) {?>
                                    <tr>
                                       <td><?php echo !empty($value->item_name) ? $value->item_name : '';?></td>
                                       <td><?php echo !empty($value->date_added) ? date('d/m/Y',strtotime(str_replace('-', '/', $value->date_added))) : '';?></td>
                                       <td><?php echo !empty($value->qty_purchase) ? $value->qty_purchase  : '0';?></td>
                                       <td><?php echo !empty($value->manufacturing_charge) ? number_format((float)$value->manufacturing_charge, 2, '.', '')  : '0.00';?></td>
                                       <td><?php echo !empty($value->rhodium_charge) ? number_format((float)$value->rhodium_charge, 2, '.', '') : '0.00';?></td>
                                       <td><?php echo !empty($value->tot_manufacturing_charge) ? number_format((float)$value->tot_manufacturing_charge, 2, '.', '') : '0.00';?></td>
                                       <td><?php echo !empty($value->tot_rhodium_charge) ? number_format((float)$value->tot_rhodium_charge, 2, '.', '') : '0.00';?></td>
                                    </tr>
                            <?php }
                             }?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view($footer); ?>
<script type="text/javascript">
    $(document).ready(function(){
        $('#myTable').DataTable();

        $('.date_calender .input-group.date').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            language: 'en',
            autoclose: true
        });

        $('.generate_report').on('click',function(){
            var start_date = chage_date_format($('#start_date').val());
            var end_date = chage_date_format($('#end_date').val());
            window.location.href = '<?php echo site_url("reports/production_expence/'+start_date+'/'+end_date+'");?>';
        });

        function chage_date_format(date_str){
            return date_str.replace('/','-').replace('/','-');
        }
    });
</script>