<div id="content">                        
<div class="wrap">
<script>
$(document).ready(function(){
	$('select').select2();
	jQuery('.datepicker2').datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
			});
	
    $("table.editable").on("click",".edit",function(){
        var eRow   = $(this).parents('tr');
        var eState = $(this).attr('data-state');
        
        if(eState == null){
            //$(this).html('Save');
            eState = 1;
        }
        if(eState == 1) 
            $(this).attr('data-state','2');
        else{
            $(this).removeAttr('data-state');
            //$(this).html('Edit');
        }
    });

  	//Location transfer detail 
	$('.detail').live('click',function(){
		window.location = "<?php echo base_url() ?>locationtransfer/reportdetail/"+$(this).parents('tr').find('.ID').text();
	}); 
});
</script>

<script type="text/javascript">
$(document).ready(function() {
	//var oTable = $("#test").dataTable( {
    /* Build the DataTable with third column using our custom sort functions */
    var oTable = $("#test").dataTable( {
        "iDisplayLength": 10,
		 "aLengthMenu": [5,10,25,50,100],
		 "sPaginationType": "full_numbers", "aoColumns": [ { 
		 	"bSortable": false },   
			null, 
			null,
			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 = "CustomerNew?ID=" + ID;		
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });    
    function remove_row(row){
        row.remove();
 		$.ajax({
  			type: "POST",
  			url: "customermaster_delete",
			data:"ID="+ID,
  			success: function(){
				alert('Row has been deleted...');
			},
		});       // 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 selDateFrom = $('#selDateFrom').val();
	var selDateTo = $('#selDateTo').val();
	var suppID = $('#ID option:selected').val();
	var urls = "<?php echo base_url();?>SupplierStatement/supplierlist/"+selDateFrom+"/"+selDateTo+"/"+suppID;
		window.location = urls;
}

function supplierListPrint(){
	var selDateFrom = $('#selDateFrom').val();
	var selDateTo = $('#selDateTo').val();
	window.open("<?php echo base_url();?>SupplierStatement/supplierlist_print/"+selDateFrom+"/"+selDateTo);
}

</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('titlelist') ?></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('title') ?></h2>                         
                </div>
                <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('dateFrom'));?></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' => 'input-small datepicker2',);
											$js='onChange="changeList()"';
											echo form_input($data, date(element('dtFormat', $this->session->userdata('logged_in')), strtotime($dateFrom)), $js);
											
										?>       
                        	</div>
                        </div>
						<div class="span5 tac">
	                    	<div class="span2 tar"><?php echo form_label($this->lang->line('dateTo'));?></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' => 'input-small datepicker2',);
											$js='onChange="changeList()"';
											echo form_input($data, date(element('dtFormat', $this->session->userdata('logged_in')), strtotime($dateTo)), $js);
										?>       
	                        </div>
                        </div>
                 	</div><!-- End Row 4-->
				
					<div class="controls-row"> 
	                    	<div class="span2"><?php echo form_label($this->lang->line('supplierName'));?></div>
	                   		<div class="span4">
							<?php
								$preselsupplier = $ID;
								$options = '';
								$options[] = '--Please Select--';
								foreach($supplier as $row){
								$options[$row->ID] = $row->supplierName;
								}
								$js='onChange="changeList()" id="ID"';
								//$js='onChange="changeList(this)"';
								echo form_dropdown('ID', $options, $preselsupplier,$js);
							?>        
	                     </div> 
	                </div>
	            </div><!-- content -->
	        </div>  
            <div class="block">
            	<div class="head">
                	<h2><?php echo $this->lang->line('title') ?></h2>
                    <ul class="buttons">
                        <li><a href="<?php echo base_url();?>SupplierStatement/supplierlistprint/<?php echo date((element('dtFormat', $this->session->userdata('logged_in'))), strtotime($dateFrom));?>/<?php echo date((element('dtFormat', $this->session->userdata('logged_in'))), strtotime($dateTo));?>/<?php echo $ID;?>" target="_blank">Print</a></li>
                    </ul>                 
                </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('supplierName') ?></th>
		                        <th><?php echo $this->lang->line('transDate') ?></th>
		                        <th><?php echo $this->lang->line('refNo') ?></th>		                        
		                        <th class='tar'><?php echo $this->lang->line('debit') ?></th>
		                        <th class='tar'><?php echo $this->lang->line('credit') ?></th>
		                        <th class='tar'><?php echo $this->lang->line('balance') ?></th>
		                		<th width="55" class="tac"><?php echo $this->lang->line('action') ?></th>
		            		</tr>
		        		</thead>
			       		<tbody>
						<?php $bil = 0; 
							if(isset($datatbls) && !empty($datatbls)):
							$bal = isset($monthOpening)?$monthOpening:0;
							foreach($datatbls as $datatbl):
							$bil++;
							$bal += $datatbl->dr - $datatbl->cr;
							?>
			            	<tr>
			                	<td style="display:none" ><?php echo $datatbl->ID; ?></td>
			                	<td><?php echo $bil; ?></td>
			                    <td><?php echo $datatbl->supplierName; ?></td>
			                    <td><?php echo $datatbl->line1.'<br>'.$datatbl->line2; ?></td>
			                    <td><?php echo $datatbl->city; ?></td>
			                    <td class="tar"><?php echo number_format($datatbl->dr, 2, ".", ","); ?></td>
			                    <td class="tar"><?php echo number_format($datatbl->cr, 2, ".", ","); ?></td>        
			                    <td class="tar"><?php echo number_format($bal, 2, ".", ","); ?></td>
                                <!--supplierStatDetail/ -->
			                    <td class="tac"><a href="<?php echo base_url();?>supplierStatement/get_bySupplierID2/<?php echo date('d-m-Y', strtotime($dateFrom));?>/<?php echo date('d-m-Y', strtotime($dateTo));?>/<?php echo $datatbl->ID; ?>" class="btn btn-mini btn-primary edit; i-printer" target="_blank"></a></td>
			                </tr>
			            <?php endforeach; 
			            	endif;
			            ?>
						</tbody>
					</table>                                         
				</div>
				<div class="footer">
					<div class="fr" style="line-height:40px;margin-right:40px">
                    	<!--<?php //if(isset($bal)): ?><div class="tal">Balance: <?php //echo number_format($bal, 2, ".", ","); ?></div> <?php //endif; ?>-->
                	</div>
				</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>


