<div id="content">                        
<div class="wrap">
<script type="text/javascript">
$(document).ready(function() {
    /* Build the DataTable with third column using our custom sort functions */
	$('select').select2();
	jQuery('.datepicker2').datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
			});
    var oTable = $("#test").dataTable( {
        "iDisplayLength": 10,
         "aLengthMenu": [5,10,25,50,100],
         "sPaginationType": "full_numbers", "aoColumns": [ { 
            "bSortable": false },   
            null, 
            null,
            null,
            null,
            null, { 
            "bSortable": false } ]});
	oTable.fnSort([[1,"asc"]]);
	
    $("table.editable").on("click",".remove",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_delete").dialog("open");
    });
    $("table.editable").on("click",".edit",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_edit").dialog("open");
    });
    $("table.editable").on("click",".shipto",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text();
        urls = "shiptolist/" + ID; 
            window.location.replace(urls);    
    });
    $("#row_edit").dialog({
        autoOpen: false,
        resizable: false,        
        modal: true,
        buttons: {
            "Continue...": function() {
                window.location.href = "<?php echo base_url()?>historicalinvoice/historicalSupplierInvoiceEdit?ID=" + ID;      
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });    
    function remove_row(row){
        row.remove();
        $.ajax({
            type: "POST",
            url: "<?php echo base_url()?>historicalinvoice/historicalCusInvoice_delete",
            data:"ID="+ID,
            success: function(){
                alert('Row has been deleted...');
				location.reload(); 
            },
        });       // Here your ajax action after delete confirmed
    }
    $("#row_delete").dialog({
        autoOpen: false,
        resizable: false,        
        modal: true,
        buttons: {
            "Delete": function() {
                remove_row(rRow);
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });    
}); 


function changeList(){
	var datefrom = $('#selDateFrom').val();
	var dateto = $('#selDateTo').val();
	var totalPay = $('#totalPayable').val();
	var urls = "<?php echo base_url();?>historicalinvoice/historicalCustomerInvoice/"+datefrom+"/"+dateto;
		window.location = urls;
}

function editHistoricalInvoice(me){
	//alert(me);
	window.location.href = "<?php echo base_url()?>historicalinvoice/historicalCustomerInvoiceEdit/"+me;
}
</script>
<div class="head">
    <div class="info">
                            <!--<h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
                                <?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>-->
            <ul class="breadcrumb">
                <li><a href="#"><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                <li><a href="#"><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                <li class="active"><?php echo $this->lang->line('cust') ?></li>
            </ul>
    </div>
    <div class="search">
        <form action="<?php echo base_url() ?>admin/search" method="post">
            <input name="search_text" type="text" placeholder="search..."/>                                
            <button type="submit"><span class="i-magnifier"></span></button>
        </form>
    </div>                        
</div><!-- head --> 
<div class="content">
<div class="wrap">                    
    <div class="row-fluid">
        <div class="span12">
            <div class="block">
            
            	<div class="head">
                    <h2><?php echo $this->lang->line('cust') ?></h2>
                </div><!-- head -->
				<div class="content np">    
                	<div class="controls-row"><!-- Row 4-->
						<div class="span5 tac">
                    	<div class="span2 tar"><?php echo form_label($this->lang->line('from'));?></div>
                        <div class="input-prepend">
						<span class="add-on"><i class="i-calendar"></i></span>
				                 <?php
										$data = array(
										'name' => 'selDateFrom',
										'id' => 'selDateFrom',
										'type' => 'text',
										'class' => 'datepicker2 financhk',);
										$js='';
										echo form_input($data, date("d-m-Y", strtotime($dateFrom)), $js);
										
									?>
                        </div>       
                        </div>
						<div class="span5 tac">
                    	<div class="span2 tar"><?php echo form_label($this->lang->line('to'));?></div>
						<div class="input-prepend">
						<span class="add-on"><i class="i-calendar"></i></span>
				                 <?php
										$data = array(
										'name' => 'selDateTo',
										'id' => 'selDateTo',
										'type' => 'text',
										'class' => 'datepicker2 financhk',);
										$js='';
										echo form_input($data, date("d-m-Y", strtotime($dateTo)), $js);
									?>
                        </div>       
                        </div>
                           
                 	</div><!-- End Row 4-->
				</div><!-- content -->
                <div class="footer">
                	<div class="side fr">
                    <?php 
						$data = array(
						'name'=>'mysubmit', 
						'class'=>'btn-form btn-success-form');
						$js="onClick='changeList()'";
						echo form_button($data,$this->lang->line('submit'),$js);
					?>
                    </div>
                </div>
            
                <div class="head">
                    <h2><?php echo $this->lang->line('titlelist') ?></h2>
                        
                        <div class="side fr">                               
                           <a href="<?php echo base_url()?>historicalInvoice/historicalCustomerInvoice_print/<?php echo date(("d-m-Y"), strtotime($dateFrom));?>/<?php echo date(("d-m-Y"), strtotime($dateTo));?>" class="btn-form btn-success-form" onclick="" target="_blank"><?php echo $this->lang->line('print') ?></a>
                           <a href="<?php echo base_url()?>historicalInvoice/historicalCustomerInvoiceNew" class="btn-form btn-small btn-warning-form" title="New"><span class="i-plus-2"></span></a>
                        </div>                                        
                </div>
                <div class="content np table-sorting">
                <table cellpadding="0" cellspacing="0" width="100%" id="test" class="editable">
                    <thead>
                    <tr>
                        <th style="display:none"></th>
                        <th>#</th>
                        <th><?php echo $this->lang->line('customerPoNo') ?></th>
                        <th><?php echo $this->lang->line('customerName') ?></th>
                        <!--<th><?php //echo $this->lang->line('formNo') ?></th>-->
                        <th><?php echo $this->lang->line('totalInvoice') ?></th>
                        <th><?php echo $this->lang->line('date') ?></th>
                        <th width="55" class="tac"><?php echo $this->lang->line('action') ?></th>
                    </tr>
                    </thead>
                     <tbody>
            <?php $bil = 0;
                if($datatbls){
                foreach($datatbls as $datatbl):
                $bil++?>
                <tr>
                    <td style="display:none" ><?php echo $datatbl->ID; ?></td>
                    <td><?php echo $bil; ?></td>
               		<?php 
						if($datatbl->gotPayment == 0){	
							echo "<td><a class='btn btn-mini btn-link' onclick='editHistoricalInvoice(".$datatbl->ID.")'>".$datatbl->customerPoNo."</a></td>";
						}
						else{
							echo "<td>&nbsp;&nbsp;".$datatbl->customerPoNo."</td>";
						}
					?>
                    <td><?php echo $datatbl->customerName; ?></td>
                    <!--<td><?php //echo $datatbl->historicalFormNo; ?></td>-->
                    <td><?php echo number_format($datatbl->totalAmount,2); ?></td>
                    <td><?php echo date("d-m-Y", strtotime($datatbl->salesInvoiceDate)); ?></td>
                    <?php
						//if(empty($datatbl->historicalinvoiceID) && (($datatbl->paymentDelete == 0) || ($datatbl->paymentDelete == NULL))){	
						//if(empty($datatbl->historicalinvoiceID) || (!empty($datatbl->historicalinvoiceID) && !isset($datatbl->paymentDelete)) ){	
						if($datatbl->gotPayment == 0){	
							$js = 'class="btn-icon btn-mini btn-danger-form remove" title="Delete"';
                            echo "<td class='tac'>".form_button('remove','<span class="i-trashcan">',$js)."</td>";
						}
						else{
							$js = 'class="btn-icon btn-mini btn-danger-form remove" title="Delete" disabled';
							echo "<td class='tac'>".form_button('remove','<span class="i-trashcan">',$js)."</td>";
						}
					?>
                </tr>
            <?php endforeach; }?>
                    </tbody>
            </table>                                         
            </div>
</div>                                
</div>
</div>                                
</div>
</div>                                
</div>
</div>
<div class="dialog" id="row_delete" style="display: none;" title="Are you sure to Delete?">
    <p><?php echo $this->lang->line('message1') ?></p>
</div>   
<div class="dialog" id="row_edit" style="display: none;" title="Are you sure to Edit ?">
    <p><?php echo $this->lang->line('message2') ?></p>
</div>


