<script>
$(document).ready(function(){
	$('select').select2();
   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",".edit",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_edit").dialog("open");
    });
   /* $("#row_edit").dialog({
        autoOpen: false,
        resizable: false,        
        modal: true,
        buttons: {
            "Continue...": function() {
				window.location.href = "<?php echo base_url(); ?>zakatsetup/summary/" + ID;		
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });    */
    $("table.editable").on("click",".remove",function(){
        rRow = $(this).parents("tr");
        fldid = $('td:first', $(this).parents('tr')).text(); 
        $("#row_delete").dialog("open");
    }); 
    
    
    function remove_row(row){
                year = $(row).find("td:eq(3)").text();
 		$.ajax({
  			type: "POST",
  			url: "<?php echo base_url() ?>zakatreport/deleteZakatSummary",
			data:"ID="+fldid+"&year=" +year,
  			success: function(data){
                            if(data>0){
			        row.remove();
					alert('Row has been deleted...');
                                    }else
                                        if(data=="year issue")
                                            alert("Delete fail : financial invalide");
                                           else
                                               alert('Action failed...');
			},
			failed: function(){
					alert('Action failed...');				
			},
		});       // 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 deleteRow(me){
  rRow = $(this).parents("tr");
        fldid = $('td:first', $(this).parents('tr')).text(); 
        $("#row_delete").dialog("open");
}

function confirmZktSummary(id) {
	if (confirm("Confirm ... ?")) {
    	$.ajax({
        	type: "POST",
            data: {
            	rowID: id,
            },
            url: "<?php echo base_url() ?>zakatReport/confirmZktSummary",
            success: function(data) {
            	location.reload(true);
            }
        });
    }
}
</script>
<div id="content">                        
<div class="wrap">
                  
<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 base_url()?>home"><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                <li><a href="zakat/home"><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                <li class="active"><?php echo $this->lang->line('title') ?></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="row-fluid">
		<div class="span12">
            	<div class="block">
                	<div class="head">
                    	<h2><?php echo $this->lang->line('titlelist') ?></h2>
                    	<div class="side fr">
                    		<a href="<?php echo base_url()?>zakatTransaction/Calculation" class="btn-icon btn-warning-form" title="Add New"><span class="i-plus-2"></span></a>
                            <a href="<?php echo base_url(); ?>zakatreport/summaryList_print" class="btn-form btn-success-form" name="updatePosting" onclick="" target="_blank"><?php echo $this->lang->line('print') ?></a>
                        </div>                                        
                    </div><!-- head -->
            	<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 class="tac">#</th>
                        <th><?php echo $this->lang->line('center') ?></th>
                        <th class="tac"><?php echo $this->lang->line('year') ?></th>
                        <th class="tar"><?php echo $this->lang->line('totalNetAssDueForZakat') ?></th>
                        <th class="tar"><?php echo $this->lang->line('zakatPay1') ?></th>
                        <th 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 class="tac"><?php echo $bil; ?></td>
                    <td><a href="<?php echo base_url() ?>zakatTransaction/Calculation"><strong><?php echo $datatbl->centerName ?></strong></a></td>
                	<td class="tac"><?php echo $datatbl->year;?></td>
                	<td class="tar"><?php echo number_format($datatbl->totalDueForZakat,2); ?></td>
                	<td class="tar"><?php echo number_format($datatbl->zakatPayableForTheYear,2); ?></td>
 					<td class="tac"><?php
							$js = 'class="btn-icon btn-mini btn-success-form " title="Confirm" onclick="confirmZktSummary('.$datatbl->ID.')"';
							echo form_button('confirm','<span class="i-checkmark-3">',$js)."&nbsp"; ?>
                            
                            <a href="<?php echo base_url() ?>zakatreport/printzakatRpt/<?php echo $datatbl->ID;?>" class="btn-icon btn-mini btn-success-form print" title="<?php echo $this->lang->line('print'); ?>" target="_blank"><span class="i-printer"></a>
                            
							<?php $js = 'class="btn-icon btn-mini btn-danger-form remove" title="'.$this->lang->line('delete').'"';
							echo "&nbsp".form_button('remove','<span class="i-trashcan">',$js);
						?>
                         
					</td>
               </tr>
            <?php endforeach; }?>
                     </tbody>
                     </table>
				</div><!-- content -->
				</div><!-- block -->
		</div>  <!-- span12 -->
	</div>  <!-- row-fluid -->
</div>  <!-- content -->
</div>  <!-- wrap -->
</div>  <!-- content -->
<div class="dialog" id="row_edit" style="display: none;" title="<?php echo $this->lang->line('edit');?> ?">
    <p><?php echo $this->lang->line('message1');?></p>
</div>  
<div class="dialog" id="row_delete" style="display: none;" title="<?php echo $this->lang->line('delete');?> ?">
    <p><?php echo $this->lang->line('message3');?></p>
</div>  
