<?php
$this->load->view ( $left );
$this->load->view ( $header );
?>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2>Purchase Bill List</h2>
    </div>
    <div class="col-sm-8">
        <div class="title-action">
            <a href="<?php echo site_url("purchase/newpurchase");?>" class="btn btn-primary addNewUser">
                <i class="fa fa-plus-square-o"></i>
                <span class="m-l-xs">Add Bill</span>
            </a>
        </div>
    </div>
</div>
<div class="wrapper wrapper-content">
    <div class="row text-center animated fadeInRightBig">
        <table class="table" id="myTable">
        	<thead>
        		<tr>
        			<th>Date</th>
        			<th>Invoice#</th>
                    <th>Order No.</th>
                    <th>Customer</th>
                    <th>Status</th>
                    <th>Due Date</th>
                    <th>Amount</th>
        			<th>Balance Due</th>
        		</tr>
        	</thead>
            <tbody>
                <?php 
                if (count($purchase_list) > 0) {
                    foreach ($purchase_list as $key_invoice => $value_bill) {
                        if (strtotime($value_bill->due_date) < strtotime(date('Y-m-d'))) {
                            if (($value_bill->total - $value_bill->payment) == 0) {
                                $status = "<span class='label label-success-light'>Paid</span>";
                            }else{
                                $status = "<span class='label label-danger-light'>Over Due</span>";
                            }
                        } else {
                            if (($value_bill->total - $value_bill->payment) == 0) {
                                $status = "<span class='label label-success-light'>Paid</span>";
                            }else{
                                $status = "<span class='label label-warning-light'>Due</span>";
                            }
                        }
                        ?>
                        <tr class="bill_edit" data-bill_id="<?php echo !empty($value_bill->purchase_bill_id) ? $value_bill->purchase_bill_id : '';?>">
                           <td><?php echo !empty($value_bill->bill_date) ? date('d/m/Y',strtotime(str_replace('-', '/', $value_bill->bill_date))) : '';?></td>
                           <td><?php echo !empty($value_bill->bill_no) ? $value_bill->bill_no : '';?></td>
                           <td><?php echo !empty($value_bill->order_no) ? $value_bill->order_no  : '';?></td>
                           <td><?php echo !empty($value_bill->name) ? $value_bill->name : '';?></td>
                           <td><?php echo $status;?></td>
                           <td><?php echo !empty($value_bill->due_date ) ? date('d/m/Y',strtotime(str_replace('-', '/', $value_bill->due_date))) : '';?></td>
                           <td><?php echo !empty($value_bill->total ) ? number_format((float)$value_bill->total, 2, '.', '') : '';?></td>
                           <td><?php echo (($value_bill->total - $value_bill->payment) > 0) ? number_format((float)($value_bill->total - $value_bill->payment), 2, '.', '') : '0.00';?></td>
                        </tr>
                <?php }
                }?>
            </tbody>
        </table>
    </div>
</div>
<?php $this->load->view($footer); ?>
<script type="text/javascript">
	$(document).ready(function(){
        //  $('#myTable').DataTable();

        $('.bill_edit').on('click',function(){
            var bill = $(this).data('bill_id');
            //window.location.href = '<?php //echo site_url("invoice/invoice_print/'+invoice+'");?>';
            window.open('<?php echo site_url("purchase/bill_print/'+bill+'");?>','_blank');
        });
	});
</script>

<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.12.4.js"></script>
    <script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
    <script src="//cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script> 	
	<script src="//cdn.datatables.net/buttons/1.5.1/js/buttons.flash.min.js"></script> 
	<script src="//cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script> 
	<script src="//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script> 
	<script src="//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
	<script src="//cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script> 
    <script src="//cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>

<script type="text/javascript">
	var jq = jQuery.noConflict();

	jq(document).ready(function() {
	jq('#myTable').DataTable( {
			dom: 'Bfrtip',
			buttons: [
				'copy', 'csv', 'excel', 'pdf', 'print'
			]
		} );
	} );

</script>	
