<?php /*********Edited Sayem (11-8-2014)
<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');
        }
    });
        
});
</script>
*/ ?>
<script type="text/javascript">
$(document).ready(function() {
	jQuery('.datepicker2').datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
			});
    /* Build the DataTable with third column using our custom sort functions */
    var oTable = $("#test").dataTable( {
        "iDisplayLength": 10,
		 "aLengthMenu": [5,10,25,50,100],
		 "asSorting": [ "asc"], "aTargets": [ 1 ],});
    $("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()?>artransaction/editDirectSaleInvoice/"+ID;                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });    
 $("table.editable").on("click",".remove",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_delete").dialog("open");
    });
    function remove_row(row){
        row.remove();
 		$.ajax({
  			type: "POST",
  			url: "salesinv_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(obj){
	var df = $('#selDateFrom').val();
	var dt = $('#selDateTo').val();
	var urls = "<?php echo base_url();?>arReports/salesInvoiceList/"+df+"/"+dt;
		window.location = urls;
} 

function printTransSummlist(){
	var year = $('#add_year').val();
	window.open("<?php echo base_url();?>glreports/transactionSummaryList_print/"+year);
	//var urls = "<?php //echo base_url();?>glreports/transactionSummaryList_print/"+year;
	//window.location = urls;
	
}

function checkYear(obj){
	var add_year = obj.value;
	//var period = $("#period").val();*/
	//alert(add_year);
	var postData = {
			'add_year' : add_year,
		};
		
 		$.ajax({
  			type: "POST",
  			dataType: "json",
			url: "<?php echo base_url()?>glreports/checkYear",
			data: postData,
  			success: function(content){
				if(content.status == "success"){
					//alert('betul');
					$('#transactionSummary thead').empty();
					$('#transactionSummary tbody').empty();
					$("#printTransSumm").attr("disabled", false);
					$("#transactionSummary thead").append('<tr><th style="display:none"></th><th class="tac">' + 
						"#" + '</th><th class="tac">' +  
						"<?php echo $this->lang->line('_1');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_2');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_3');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_4');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_5');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_6');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_7');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_8');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_9');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_10');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_11');?>" + '</th><th class="tac">' + 
						"<?php echo $this->lang->line('_12');?>" + '</th><th class="tac">' + 
						"Total" + '</th></tr>');
						
						var n = content.message.length;
						var jan = 0;
						var month1 = 0;
						var month2 = 0;
						var month3 = 0;
						var month4 = 0;
						var month5 = 0;
						var month6 = 0;
						var month7 = 0;
						var month8 = 0;
						var month9 = 0;
						var month10 = 0;
						var month11 = 0;
						var month12 = 0;
						var rowTotal = 0;
						
						for (var i=0; i < n; i++){
						month1 += parseInt(content.message[i].Jan);
						month2 += parseInt(content.message[i].Feb);
						month3 += parseInt(content.message[i].Mar);
						month4 += parseInt(content.message[i].Apr);
						month5 += parseInt(content.message[i].may);
						month6 += parseInt(content.message[i].Jun);
						month7 += parseInt(content.message[i].Jul);
						month8 += parseInt(content.message[i].Aug);
						month9 += parseInt(content.message[i].Sept);
						month10 += parseInt(content.message[i].Oct);
						month11 += parseInt(content.message[i].Nov);
						month12 += parseInt(content.message[i].Dec);
						
						
						row = parseInt(content.message[i].Jan) + parseInt(content.message[i].Feb) + parseInt(content.message[i].Mar) + parseInt(content.message[i].Apr) + parseInt(content.message[i].may) + parseInt(content.message[i].Jun) + parseInt(content.message[i].Jul) + parseInt(content.message[i].Aug) + parseInt(content.message[i].Sept) + parseInt(content.message[i].Oct) + parseInt(content.message[i].Nov) + parseInt(content.message[i].Dec);
						
						rowTotal += row;
						
						$("#transactionSummary tbody").append('<tr><td style="display:none">' + 
						content.message[i].transID + '</td><td>' + content.message[i].transID + '</td><td class="tac">' + 
						content.message[i].Jan + '</td><td class="tac">' + 
						content.message[i].Feb + '</td><td class="tac">' + 
						content.message[i].Mar + '</td><td class="tac">' + 
						content.message[i].Apr + '</td><td class="tac">' + 
						content.message[i].may + '</td><td class="tac">' + 
						content.message[i].Jun + '</td><td class="tac">' + 
						content.message[i].Jul + '</td><td class="tac">' + 
						content.message[i].Aug + '</td><td class="tac">' + 
						content.message[i].Sept + '</td><td class="tac">' + 
						content.message[i].Oct+ '</td><td class="tac">' + 
						content.message[i].Nov + '</td><td class="tac">' + 
						content.message[i].Dec + '</td><td class="tac">' + 
						row + '</td></tr>');
						}
						
						$("#transactionSummary tbody").append('<tr><th style="display:none"></th><th class="tar">' + 
						"Total" + '</th><th class="tac">' +  
						month1 + '</th><th class="tac">' + 
						month2 + '</th><th class="tac">' + 
						month3 + '</th><th class="tac">' + 
						month4 + '</th><th class="tac">' + 
						month5 + '</th><th class="tac">' + 
						month6 + '</th><th class="tac">' + 
						month7 + '</th><th class="tac">' + 
						month8 + '</th><th class="tac">' + 
						month9 + '</th><th class="tac">' + 
						month10 + '</th><th class="tac">' + 
						month11 + '</th><th class="tac">' + 
						month12 + '</th><th class="tac">' + 
						rowTotal + '</th></tr>');
					
				}
				else{
					//alert('salah');
					$('#transactionSummary tbody').empty();
					$("#printTransSumm").attr("disabled", 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='<?php echo base_url()."GeneralLedger" ?>'><?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="wrap">                    
				<div class="row-fluid">
					<div class="span12">
						<div class="block">
							<div class="head">
								<h2><?php echo $this->lang->line('searchParam') ?></h2>
								<ul class="buttons">
									<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
								</ul>
							</div><!-- head -->
							<div class="content np">    
								<div class="controls-row"><!-- Row 1-->
									<div class="span5 tac">
									<div class="span2 tar"><?php echo $this->lang->line('year') ?></div>
									<?php
										/*$preselyear = '';               
										$options[] = '--Please Select--';
											foreach($year as $row){
										//var_dump($row);
										$options[$row->year] = $row->year;
										}
										$js='onChange="checkYear(this)"; class="input-medium"; id="add_year"';

										echo form_dropdown('add_year', $options, $preselyear, $js);*/
									?>
									<?php
										$preselyear = $this->lang->line('selectyear');
										$options = '';
										$options[] = $this->lang->line('selectyear');
										if(isset($yrs) && !empty($yrs)){	
											foreach($yrs as $row){
											$options[$row['financialYear']] = $row['financialYear'];
											}
										}
										$js='onchange="checkYear(this)" class="input-medium" id="add_year"';

										echo form_dropdown('add_year', $options, $preselyear, $js);
									?>
									</div>
								</div><!-- End Row 1-->
							</div><!-- content -->
							
							
							<div class="head">
								<h2><?php echo $this->lang->line('title');?></h2>
								<ul class="buttons">
									<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
								</ul>
								<div class="side fr">
									<button name="printTransSumm" id="printTransSumm" class="btn-form btn-success-form" onClick="printTransSummlist()" disabled="disabled">
									<?php echo $this->lang->line('print');?></button>
								</div>                                       
							</div>
							<div class="content np table-sorting">
								<table cellpadding="0" cellspacing="0" width="100%" id="transactionSummary" class="editable">
								<thead>
									<tr>
										<th style="display:none"></th>
										<th class="tac">#</th>
										<th class="tac"><?php echo $this->lang->line('_1');?></th>
										<th class="tac"><?php echo $this->lang->line('_2');?></th>
										<th class="tac"><?php echo $this->lang->line('_3');?></th>
										<th class="tac"><?php echo $this->lang->line('_4');?></th>                
										<th class="tac"><?php echo $this->lang->line('_5');?></th>
										<th class="tac"><?php echo $this->lang->line('_6');?></th>
										<th class="tac"><?php echo $this->lang->line('_7');?></th>
										<th class="tac"><?php echo $this->lang->line('_8');?></th>
										<th class="tac"><?php echo $this->lang->line('_9');?></th>
										<th class="tac"><?php echo $this->lang->line('_10');?></th>
										<th class="tac"><?php echo $this->lang->line('_11');?></th>
										<th class="tac"><?php echo $this->lang->line('_12');?></th>
										<th class="tac"><?php echo $this->lang->line('total');?></th>              
										<!--<th width="55" class="tac"><?php //echo $this->lang->line('action');?></th>-->
									</tr>
								</thead>
								<tbody>
									<tr style="display:none">
									<td></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									<td class="tac"></td>
									</tr>
								</tbody>
								</table>                                     
							</div>
				<div class="dialog" id="row_edit" style="display: none;" title=". <?php echo $this->lang->line("edit") ?> . ?">
					<p><?php echo $this->lang->line('message2');?></p>
				</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
