<script>
    $(document).ready(function() {
        $('select').select2();
        $.each($(".select2-container"), function(i, n) {
            $(n).next().show().fadeTo(0, 0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
            $(n).prepend($(n).next());
            $(n).delay(500).queue(function() {
                $(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
                $(this).dequeue();
            });
        });
        $("#calculateDetails").hide();
        $("#calculateHeader").hide();
		
		$('#select-all').click(function(event) {   
    		if(this.checked) {
        		// Iterate each checkbox
        		$(':checkbox').each(function() {
            		this.checked = true;                        
        		});
    		}
			else {
        		// Iterate each checkbox
        		$(':checkbox').each(function() {
            		this.checked = false;                        
        		});
    		}
		});
		
    });
	
//--------------------------------------------Last Edit By Fadhirul (20150820)--------------------------------------------------------	
    function Calculcate() {
		
        var centerID = $("#centerID option:selected").val();
        var methodID = $("#methodID option:selected").val();
        var nisabYear = $("#nisabYear option:selected").val();
        if ($("#formValidate").validationEngine('validate') && finanEngine('financhk')) {
            //if (methodID == 1) {
			if (methodID == 'Working Capital') {
                postData = {
                    methodID: methodID,
                    centerID: centerID,
                    nisabYear: nisabYear,
                };
                $.ajax({
                    type: "POST",
                    url: '<?php echo base_url(); ?>zakatTransaction/zakatCalculation',
                    dataType: "json",
                    data: postData,
                    async: false,
                    success: function(content) {
                        if (content.status == "success") {
                            var bill = 0;
                            var Header = '';
                            var Headertotal = 0;
							var Headertotal2 = 0;
							var a;
							var b;
							
							if(content.checkUpdateAble == 0){
								document.getElementById("finalSubmitBtn").disabled = true;
								//$('#finalSubmitBtn').attr('disabled', 'disabled');
							}
							else{
								document.getElementById("finalSubmitBtn").disabled = false;
							}
                            /*
                             for ( var i = 0; i < content.message.length; i++) {
                             bill++;
                             if(content.message[i].parentID != Header){
                             $("#oTable tbody").append(
                             "<tr><td colspan='3'>"+ content.message[i].topGroupName + "</td>" +
                             "</tr>"
                             );
                             Header = content.message[i].parentID;
                             }
                             
                             $("#oTable tbody").append(
                             "<tr><td style='display:none'>"+content.message[i].ID+"</td>" +
                             "<td class='tac'>"+bill+"</td>" +
                             "<td>"+content.message[i].acctName+"</td>" +
                             "<td class='tar'>"+accounting.formatNumber(content.message[i].totalAmount,2)+"</td>" +
                             "</tr>"
                             );
                             }
                             var totalNisab = 0;
                             
                             for ( var i = 0; i < content.details.length; i++) {
                             if(content.details[i].parentID == 1){
                             $("#totalAssets").val(accounting.formatNumber(content.details[i].totalAmount,2));
                             totalNisab = parseFloat(totalNisab) + parseFloat(content.details[i].totalAmount);
                             }else{
                             $("#totalLiability").val(accounting.formatNumber(content.details[i].totalAmount,2));
                             totalNisab = parseFloat(totalNisab)  + parseFloat(content.details[i].totalAmount);
                             }
                             } 
                             
                             
                             
                             */




                             var netCurrentAsset = content.CurrentAssets - content.CurrentLiabilities;
                            var totalNetAssetDueForZak  = netCurrentAsset - content.AdjustmentMinusCurrentAssets + content.AdjustmentAddCurrentLiability;
                            var zakatValue = 0;
                            if(content.mShare > 0){
                              zakatValue = totalNetAssetDueForZak*content.mShare /100;
                            }
                            
                            var yearZakat = 0;
                             if (zakatValue >= content.nisab){
                                  yearZakat = zakatValue *0.025;
                             }
                            var  monthlyZakat = yearZakat / 12;
                             
                             $("#netCurrentAsset").val(accounting.formatNumber(netCurrentAsset,2));
                             $("#adjustmentNetCurrentAsset").val(accounting.formatNumber(totalNetAssetDueForZak,2));
                             $("#totalNetAssetDueForZak").val(accounting.formatNumber(zakatValue,2));
							               //$("#totalNetAssetDueForZak").val(accounting.formatNumber(zakatValue,2));
                             $("#zakatForYear").val(accounting.formatNumber(yearZakat,2));
                             $("#monthlyZakat").val(accounting.formatNumber(monthlyZakat,2));
							               //$("#adjustmentNetCurrentAsset").val(accounting.formatNumber(totalNetAssetDueForZak,2));
                             
                             $("#muslimOwnershipShare").val(accounting.formatNumber(content.mShare,2));
                             $("#nisabTotal").val(accounting.formatNumber(content.nisab,2));

                           // var bill = 0;
                           // var Header = '';
                           // var Headertotal = 0;
                            var tbody = '';
                            var listHead = [];
							var fad = 0;
							var tt = 0;
							var currentAmountAssetAll = 0;
							var currentAmountLiabilitiesAll = 0;
							var currentAmountAssetCheck = 0;
							var currentAmountLiabilitiesCheck = 0;
							var count = 0;
							var amountToadd = 0;
							var ddddd = 0;
							var hhhhh = 0;
							//console.log(content.message.length+"<->"+content.checkAble.length);
							//return false;
                            for (var i = 0; i < content.message.length; i++) {


                                if (listHead.indexOf(content.message[i].topGroupName) < 0) {
                                    Headertotal = 0;
                                    tbody = tbody + "<tr><td colspan='5'>" + content.message[i].topGroupName + "</td>";
                                    listHead[i] = content.message[i].topGroupName;
                                    bill = 0;
                                    for (var j = i; j < content.message.length; j++) {
                                      // alert(content.message[j].topGroupName);
                                       
                                        if (listHead[i] == content.message[j].topGroupName) {
                                             
											 
											 //var totalAmount = accounting.formatNumber(content.message[j].total, 2);
											 //alert(totalAmount);
											 
											 if(content.message[j].acctGroupID == 3){
												a = (content.message[j].lastyeardebit - content.message[j].lastyearcredit) + (content.message[j].currentyeardebit - content.message[j].currentyearcredit);
											 	var totalAmount = accounting.formatNumber((content.message[j].lastyeardebit - content.message[j].lastyearcredit) + (content.message[j].currentyeardebit - content.message[j].currentyearcredit), 2);												
											 }
											 else{
												b = (content.message[j].lastyearcredit - content.message[j].lastyeardebit) + (content.message[j].currentyearcredit - content.message[j].currentyeardebit);
											 	var totalAmount = accounting.formatNumber((content.message[j].lastyearcredit - content.message[j].lastyeardebit) + (content.message[j].currentyearcredit - content.message[j].currentyeardebit), 2);										
											 }
											 
											 //Headertotal = Headertotal + accounting.unformat(content.message[j].totalAmount);
											
											if(totalAmount != 0){
												if(content.message[j].acctGroupID == 3){
													Headertotal = Headertotal + a;
												}
												else{
													Headertotal2 = Headertotal2 + b;
												}
												bill++;
												//if(content.checkZakatDetail != false){
													if(content.message[j].checkAble == 0){
														if(tt == 0){
															//currentAmountAssetCheck = currentAmountAssetCheck + accounting.unformat(content.message[j].totalAmount);
															currentAmountAssetCheck = currentAmountAssetCheck + a;
														}
														else{
															//currentAmountLiabilitiesCheck = currentAmountLiabilitiesCheck + accounting.unformat(content.message[j].totalAmount);
															currentAmountLiabilitiesCheck = currentAmountLiabilitiesCheck + b;
														}
														/*if(tt == 0){
															count = tt;
															currentAmount = currentAmount + accounting.unformat(content.message[j].totalAmount);
														}
														else if(count != tt){
															currentAmount=0;
															amountToadd = accounting.unformat(content.message[j].totalAmount);
															count += 1;
														}
														else{
															currentAmount = currentAmount + accounting.unformat(content.message[j].totalAmount) + amountToadd;
															amountToadd = 0;
														}*/
														
														tbody = tbody + 
															"<tr><td class='tac' style='display:none'>" + (tt+1) + "</td>" +
															"<td class='tac' style='display:none'>" + content.message[j].compAcctDetID + "</td>" +
															"<td class='tac'>" + bill + "</td>" +
															"<td>" + content.message[j].acctName + "</td>" +
															"<td class='tar' id='amountAdj'>" + totalAmount + "</td>" +
															"<td class='tac'>" + "<input id='checkbox1' name='checkbox1' type='checkbox' onchange='doit(this, "+ tt +")' />" + "</td>" +
															//"<td class='tac'>" + "<input id='checkbox1' name='checkbox1' type='checkbox' onchange='doit(this, \"" + totalAmount + "\")' data-count='1' />" + "</td>" +
															"<td class='tar'>" + totalAmount + "</td>" +
															"</tr>";
													}
													else{
														if(tt == 0){
															//currentAmountAssetAll = currentAmountAssetAll + accounting.unformat(content.message[j].totalAmount);
															currentAmountAssetAll = currentAmountAssetAll + a;
														}
														else{
															//currentAmountLiabilitiesAll = currentAmountLiabilitiesAll + accounting.unformat(content.message[j].totalAmount);
															currentAmountLiabilitiesAll = currentAmountLiabilitiesAll + b
														}
														
														tbody = tbody + 
															"<tr><td class='tac' style='display:none'>" + (tt+1) + "</td>" +
															"<td class='tac' style='display:none'>" + content.message[j].compAcctDetID + "</td>" +
															"<td class='tac'>" + bill + "</td>" +
															"<td>" + content.message[j].acctName + "</td>" +
															"<td class='tar'>" + totalAmount + "</td>" +
															"<td class='tac'>" + "<input id='checkbox1' name='checkbox1' type='checkbox' onchange='doit(this, "+ tt +")' checked = 'checked' />" + "</td>" +
															//"<td class='tac'>" + "<input id='checkbox1' name='checkbox1' type='checkbox' onchange='doit(this, \"" + totalAmount + "\")' data-count='1' />" + "</td>" +
															"<td class='tar'></td>" +
															"</tr>";
													}
												/*}
												else{
													
													if(tt == 0){
														//currentAmountAssetAll = currentAmountAssetAll + accounting.unformat(content.message[j].totalAmount);
														currentAmountAssetAll = currentAmountAssetAll + a;
													}
													else{
														//currentAmountLiabilitiesAll = currentAmountLiabilitiesAll + accounting.unformat(content.message[j].totalAmount);
														currentAmountLiabilitiesAll = currentAmountLiabilitiesAll + b;
													}
													
													tbody = tbody + 
														"<tr><td class='tac' style='display:none'>" + (tt+1) + "</td>" +
														"<td class='tac' style='display:none'>" + content.message[j].compAcctDetID + "</td>" +
														"<td class='tac'>" + bill + "</td>" +
														"<td>" + content.message[j].acctName + "</td>" +
														"<td class='tar'>" + totalAmount + "</td>" +
														"<td class='tac'>" + "<input id='checkbox1' name='checkbox1' type='checkbox' onchange='doit(this, "+ tt +")' checked = 'checked' />" + "</td>" +
														//"<td class='tac'>" + "<input id='checkbox1' name='checkbox1' type='checkbox' onchange='doit(this, \"" + totalAmount + "\")' data-count='1' />" + "</td>" +
														"<td class='tar'></td>" +
														"</tr>";
												}*/
												
											}
										
										}//end totalAmount != 0
                                    }
									tt = tt + 1;
                                    
									
									if(fad == 0){
										 //$('#netCurrentAsset').val(accounting.formatNumber(currentAmount, 2));
										 tbody = tbody + "<tr><td colspan='2'>.</td>" +
                                            "<td class='tar' id='totAsset'>" + accounting.formatNumber(Headertotal, 2) + "</td>" +
											"<td class='tar'></td>" +
											"<td class='tar' id='ll'>" + accounting.formatNumber(currentAmountAssetCheck, 2) + "</td>" +
                                            "</tr>";
										 ddddd = currentAmountAssetCheck;
									}
									else{
										 tbody = tbody + "<tr><td colspan='2'>.</td>" +
                                            "<td class='tar' id='totLiabilities'>" + accounting.formatNumber(Headertotal2, 2) + "</td>" +
											"<td class='tar'></td>" +
											"<td class='tar' id='pp'>" + accounting.formatNumber(currentAmountLiabilitiesCheck, 2) + "</td>" +
                                            "</tr>";
										 //$('#adjustmentNetCurrentAsset').val(accounting.formatNumber(currentAmount, 2));
										 hhhhh = currentAmountLiabilitiesCheck;
									}
									currentAmount = 0;
									fad = fad + 1;
									
									
								
								}

                            }
							
							var totCurrentAssetLiabilities = 0;
							
							totCurrentAssetLiabilities = (currentAmountAssetAll + currentAmountAssetCheck) - (currentAmountLiabilitiesAll + currentAmountLiabilitiesCheck);
							
							var totCurrentAssetLiabilitiesAdj = ddddd - hhhhh;
							
							tbody = tbody + "<tr><td colspan='2' class='tar'><?php echo $this->lang->line('currentAssetLiabilities'); ?></td>" +
                                            "<td class='tar' id='totCurrentAssetLiabilities'>" + accounting.formatNumber(totCurrentAssetLiabilities, 2) + "</td>" +
											"<td class='tar'></td>" +
											"<td class='tar' id='totCurrentAssetLiabilitiesAdj'>" + accounting.formatNumber(totCurrentAssetLiabilitiesAdj, 2) + "</td>" +
                                            "</tr>";
											
							$("#oTable tbody").empty();
                            $("#oTable tbody").append(tbody);
                            $("#calculateDetails").show();
                            $("#calculateHeader").show();
							
							var netCurrentAsset = $('#totCurrentAssetLiabilities').text();
							$('#netCurrentAsset').val(netCurrentAsset);
							
							var adjustmentNetCurrentAsset = $('#totCurrentAssetLiabilitiesAdj').text();
							$('#adjustmentNetCurrentAsset').val(adjustmentNetCurrentAsset);
							
							var a = accounting.unformat(netCurrentAsset);
							var b = accounting.unformat(adjustmentNetCurrentAsset);
							
							var beforeAfterAdjustmentNetCurrentAsset = a - b;
							$('#beforeAfterAdjustmentNetCurrentAsset').val(accounting.formatNumber(beforeAfterAdjustmentNetCurrentAsset,2));
							
                        	$('#totalNetAssetDueForZak').val(accounting.formatNumber(beforeAfterAdjustmentNetCurrentAsset * (content.mShare/100), 2));
						
							var totalNetAssetDueForZak = accounting.unformat($('#totalNetAssetDueForZak').val());
							var zakatAmount = $('#zakatRate').val();
						
							if( totalNetAssetDueForZak > content.nisab){
								var totalZakatNeedToPay = totalNetAssetDueForZak * (zakatAmount/100);
								$("#zakatForYear").val(accounting.formatNumber(totalZakatNeedToPay, 2));
							}
							else{
								$("#zakatForYear").val(accounting.formatNumber(0, 2));
							}
							
							 var zakatForYear = accounting.unformat($("#zakatForYear").val());
							 
							 $("#monthlyZakat").val(accounting.formatNumber(zakatForYear/12, 2));
							 
							 
							/*if(netCurrentAsset > content.nisab){	
								var mmmmm = netCurrentAsset * 0.025 * (content.mShare/100);
								$('#zakatForYear').val(accounting.formatNumber(mmmmm, 2));
							}
							else{
								$('#zakatForYear').val(accounting.formatNumber(0, 2));
							}*/
							
						/*  $("#zakatPay").val(accounting.formatNumber(content.zakatAmount, 2));
                            $("#zakatPerniagaan").val(accounting.formatNumber(totalNisab, 2));
                            $("#calculateDetails").show();
                            $("#calculateHeader").show(); */
                        }
                    }
                });
            }
        }
    }
   
    function saveData() {
        var n = 0;

        var nT = 0;//$("#oTable tbody tr").length;
		var count = 1;
        $("#oTable tbody tr").each(function(){
            if($(('td'),this).length >2){
                nT++;
            }
        });
		
		var kikiki = $("#nisabYear").val();
		
		
        postData = {
                'centerID': $("#centerID").val(),
                'calculationMethod': $("#methodID option:selected").text(),
                'year': $("#nisabYear").val(),
                'mshare':  accounting.unformat($("#muslimOwnershipShare").val()),
                'nisab' :  accounting.unformat($("#nisabTotal").val()),
                'netCurrentAsset' :  accounting.unformat($("#netCurrentAsset").val()),
                'totalNetAssetDueForTheYear' :  accounting.unformat($("#totalNetAssetDueForZak").val()),
                'zakatPayableForYear' :  accounting.unformat($("#zakatForYear").val()),
                'zakatPayableMonly' :  accounting.unformat($("#monthlyZakat").val()),
                'option' : 'master'
            };
        $.ajax({
            type: "POST",
            url: "<?php echo base_url() ?>zakatTransaction/zakat_save",
            data: postData,
            
            success: function(data) {
              console.log(data);
              /*if(data == 'false'){
                  alertbox("Zakat entry found !",3);
              }*/
                //if (data > 0) { 
                     var group ="";
                    
                    $("#oTable tbody tr").each(function(){

                      firstColumValue = $(this).find("td:eq(0)").text();
					  
                       if (firstColumValue > 0){
						   
						//$("#oTable").find(':checkbox').each(function () {
        				  if($('input',this).is(':checked')){
							
							var compAcctDetID = $(this).find("td:eq(1)").text();
                          		//alert('fad');
							$.ajax({
                              type: "POST",
                              url: "<?php echo base_url() ?>zakatTransaction/zakat_saveDetail",
                              data: {
                                  masterID : data,
                                  group : group,
                                  compAcctDetID : $(this).find("td:eq(1)").text(),
								  desc : $(this).find("td:eq(3)").text(),
                                  amount :  accounting.unformat($(this).find("td:eq(4)").text()), 
                                  option : 'detail',
                                  total : nT,
								  checkAble : 1,
								  year : kikiki
                              },
                              /*success: function(content) {
                                  if(content == false){
                                      alertbox("Zakat entry found !",3);
                                  }
                                  //window.location = "<?php echo base_url() ?>zakatreport/zakatSummaryList";    
                                  n++;
                                  console.log(nT+"<->"+n);
                                  if (nT==n){
                                      window.location = "<?php echo base_url() ?>zakatreport/zakatSummaryList";
                                  }
                              }*/
                            });
						  
						  }
						  else{
							  //alert('dasd');
							  $.ajax({
                              type: "POST",
                              url: "<?php echo base_url() ?>zakatTransaction/zakat_saveDetail",
                              data: {
                                  masterID : data,
                                  group : group,
								  compAcctDetID : $(this).find("td:eq(1)").text(),
                                  desc : $(this).find("td:eq(3)").text(),
                                  amount :  accounting.unformat($(this).find("td:eq(4)").text()), 
                                  option : 'detail',
                                  total : nT,
								  checkAble : 0,
								  year : kikiki
                              },
                              /*success: function(content) {
                                  if(content == false){
                                      alertbox("Zakat entry found !",3);
                                  }
                                  //window.location = "<?php echo base_url() ?>zakatreport/zakatSummaryList";    
                                  n++;
                                  console.log(nT+"<->"+n);
                                  if (nT==n){
                                      window.location = "<?php echo base_url() ?>zakatreport/zakatSummaryList";
                                  }
                              }*/
                          	});
							
						  }
						  
						//});
						   
                       }else
					   {
                           if(firstColumValue !=="" && firstColumValue!=="."){
                             group = firstColumValue;
                           }
                       }
                    });
					alert("<?php echo $this->lang->line('dataSaved') ?>");
                  //}
                  //else  window.location = "<?php echo base_url() ?>zakatreport/zakatSummaryList";
              }
          });
            
      
               
    }
	
	function doit(me, fad) {
		var tr = $(me).parent().parent();
		
		var totAsset = accounting.unformat($('#ll').text());
		var totLiabilities = accounting.unformat($('#pp').text());
		
		var total = 0;
		
		var count = 0;
		
		//alert(fad);
		
		var curAmount = accounting.unformat($(tr).find("td:eq(4)").text());
		//console.log(totAsset+"<->"+curAmount+"<->result:"+(totAsset-curAmount));
		
		if (me.checked == 1){
			$(tr).find("td:eq(6)").text('');
			
			if(fad == 0){
				$('#ll').text(accounting.formatNumber((totAsset-curAmount),2));
			}
			else{
				$('#pp').text(accounting.formatNumber((totLiabilities-curAmount),2));
			}
		}
		else{
			$(tr).find("td:eq(6)").text(accounting.formatNumber(curAmount,2));
			
			if(fad == 0){
				$('#ll').text(accounting.formatNumber((totAsset+curAmount),2));
			}
			else{
				$('#pp').text(accounting.formatNumber((totLiabilities+curAmount),2));
			}
		}
		
		var totCurrentAssetAdj = accounting.unformat($('#ll').text());
		var totCurrentLiabAdj = accounting.unformat($('#pp').text());
		
		$('#totCurrentAssetLiabilitiesAdj').text(accounting.formatNumber((totCurrentAssetAdj-totCurrentLiabAdj),2));
		/*if(totCurrentAssetAdj > 0){
			$('#totCurrentAssetLiabilitiesAdj').text(accounting.formatNumber((totCurrentAssetAdj-totCurrentLiabAdj),2));
		}
		else{
			$('#totCurrentAssetLiabilitiesAdj').text(accounting.formatNumber((totCurrentAssetAdj+totCurrentLiabAdj),2));
		}
		
		if(totCurrentLiabAdj > 0){
			$('#totCurrentAssetLiabilitiesAdj').text(accounting.formatNumber((totCurrentAssetAdj-totCurrentLiabAdj),2));
		}
		else{
			$('#totCurrentAssetLiabilitiesAdj').text(accounting.formatNumber((totCurrentAssetAdj+totCurrentLiabAdj),2));
		}*/
		
		if(me.checked == 1){
			var totCurrentAssetLiabilitiesAdj = $('#totCurrentAssetLiabilitiesAdj').text();
			$('#adjustmentNetCurrentAsset').val(totCurrentAssetLiabilitiesAdj);
			
			var netCurrentAsset = accounting.unformat($('#netCurrentAsset').val());
			var adjustmentNetCurrentAsset = accounting.unformat($('#adjustmentNetCurrentAsset').val());
			$('#beforeAfterAdjustmentNetCurrentAsset').val(accounting.formatNumber(netCurrentAsset - adjustmentNetCurrentAsset,2))
			
			var zakatAmount = $('#zakatRate').val();
			var nisab = accounting.unformat($('#nisabTotal').val());
			var muslimShare = accounting.unformat($('#muslimOwnershipShare').val());
			
			var beforeAfterAdjustmentNetCurrentAsset = accounting.unformat($('#beforeAfterAdjustmentNetCurrentAsset').val());
							
            $('#totalNetAssetDueForZak').val(accounting.formatNumber(beforeAfterAdjustmentNetCurrentAsset * (muslimShare/100), 2));
						
			var totalNetAssetDueForZak = accounting.unformat($('#totalNetAssetDueForZak').val());
						
			if( totalNetAssetDueForZak > nisab){
				var totalZakatNeedToPay = totalNetAssetDueForZak * (zakatAmount/100);
				$("#zakatForYear").val(accounting.formatNumber(totalZakatNeedToPay, 2));
			}
			else{
				$("#zakatForYear").val(accounting.formatNumber(0, 2));
			}
							
			var zakatForYear = accounting.unformat($("#zakatForYear").val());
							 
			$("#monthlyZakat").val(accounting.formatNumber(zakatForYear/12, 2));
			
		}
		else{
			var totCurrentAssetLiabilitiesAdj = $('#totCurrentAssetLiabilitiesAdj').text();
			$('#adjustmentNetCurrentAsset').val(totCurrentAssetLiabilitiesAdj);
			
			var netCurrentAsset = accounting.unformat($('#netCurrentAsset').val());
			var adjustmentNetCurrentAsset = accounting.unformat($('#adjustmentNetCurrentAsset').val());
			$('#beforeAfterAdjustmentNetCurrentAsset').val(accounting.formatNumber(netCurrentAsset - adjustmentNetCurrentAsset,2))
			
			var zakatAmount = $('#zakatRate').val();
			var nisab = accounting.unformat($('#nisabTotal').val());
			var muslimShare = accounting.unformat($('#muslimOwnershipShare').val());
			
			var beforeAfterAdjustmentNetCurrentAsset = accounting.unformat($('#beforeAfterAdjustmentNetCurrentAsset').val());
							
            $('#totalNetAssetDueForZak').val(accounting.formatNumber(beforeAfterAdjustmentNetCurrentAsset * (muslimShare/100), 2));
						
			var totalNetAssetDueForZak = accounting.unformat($('#totalNetAssetDueForZak').val());
						
			if( totalNetAssetDueForZak > nisab){
				var totalZakatNeedToPay = totalNetAssetDueForZak * (zakatAmount/100);
				$("#zakatForYear").val(accounting.formatNumber(totalZakatNeedToPay, 2));
			}
			else{
				$("#zakatForYear").val(accounting.formatNumber(0, 2));
			}
							
			var zakatForYear = accounting.unformat($("#zakatForYear").val());
							 
			$("#monthlyZakat").val(accounting.formatNumber(zakatForYear/12, 2));
			
		}
		//$('#netCurrentAsset').val(accounting.formatNumber(ggggg,2));
		//$('#totalNetAssetDueForZak').val(accounting.formatNumber(ggggg,2));
		//$('#zakatForYear').val(accounting.formatNumber(mmmmm, 2));
		
		
	}
	
	/*function saveZakat(me){
		//var oTable = $("#oTable").dataTable( );
        $(me).attr("disabled","disabled");
		$("#oTable").find(':checkbox').each(function () {
        	if($(this).is(':checked')){
				
				//var fldid = $('td:first', $(this).parents('tr')).text(); 
				var effdate = $('td:eq(3)', $(this).parents('tr')).text();
				alert(fldid);
				
			}
		});
	}*/
	
	function hideTable(){
		$("#calculateDetails").hide();
        $("#calculateHeader").hide();
	}
	
	function checkAll(me){
		var dd = 0;
		var count = 0;
		var totalAdj = 0;
		var firstTotal = 0;
		var secondTotal = 0;
		
		$("#oTable tbody tr").each(function(){
			
			var tt = $(this).find("td:eq(0)").text();
			
			var totalAmount = accounting.unformat($(this).find("td:eq(4)").text());
			
			if(me.checked == 1){
				var fad = $(this).find("td:eq(6)").text('');
				$('#ll').text(accounting.formatNumber(0,2));
				$('#pp').text(accounting.formatNumber(0,2));
				
				var adjustmentNetCurrentAsset = $('#totCurrentAssetLiabilitiesAdj').text();
				$('#adjustmentNetCurrentAsset').val('0.00');
				
				var netCurrentAsset = accounting.unformat($('#netCurrentAsset').val());
				var adjustmentNetCurrentAsset = accounting.unformat($('#adjustmentNetCurrentAsset').val());
				$('#beforeAfterAdjustmentNetCurrentAsset').val(accounting.formatNumber(netCurrentAsset - adjustmentNetCurrentAsset,2));
				
				var zakatAmount = $('#zakatRate').val();
				var nisab = accounting.unformat($('#nisabTotal').val());
				var muslimShare = accounting.unformat($('#muslimOwnershipShare').val());
			
				var beforeAfterAdjustmentNetCurrentAsset = accounting.unformat($('#beforeAfterAdjustmentNetCurrentAsset').val());
							
            	$('#totalNetAssetDueForZak').val(accounting.formatNumber(beforeAfterAdjustmentNetCurrentAsset * (muslimShare/100), 2));
						
				var totalNetAssetDueForZak = accounting.unformat($('#totalNetAssetDueForZak').val());
						
				if( totalNetAssetDueForZak > nisab){
					var totalZakatNeedToPay = totalNetAssetDueForZak * (zakatAmount/100);
					$("#zakatForYear").val(accounting.formatNumber(totalZakatNeedToPay, 2));
				}
				else{
					$("#zakatForYear").val(accounting.formatNumber(0, 2));
				}
							
				var zakatForYear = accounting.unformat($("#zakatForYear").val());
							 
				$("#monthlyZakat").val(accounting.formatNumber(zakatForYear/12, 2));
				
			}
			else{
				$(this).find("td:eq(6)").text(accounting.formatNumber(totalAmount,2));
				//$('#hihi'+fad).text(totalAmount);
				if(tt == 2 && count == 0){
					dd = 0;
					count = 1;
				}
				dd = dd + totalAmount;
				
				var adjustmentNetCurrentAsset = $('#totCurrentAssetLiabilitiesAdj').text();
				$('#adjustmentNetCurrentAsset').val(adjustmentNetCurrentAsset);
				
				var netCurrentAsset = accounting.unformat($('#netCurrentAsset').val());
				var adjustmentNetCurrentAsset = accounting.unformat($('#adjustmentNetCurrentAsset').val());
				$('#beforeAfterAdjustmentNetCurrentAsset').val(accounting.formatNumber(netCurrentAsset - adjustmentNetCurrentAsset,2));
				
				var zakatAmount = $('#zakatRate').val();
				var nisab = accounting.unformat($('#nisabTotal').val());
				var muslimShare = accounting.unformat($('#muslimOwnershipShare').val());
			
				var beforeAfterAdjustmentNetCurrentAsset = accounting.unformat($('#beforeAfterAdjustmentNetCurrentAsset').val());
							
            	$('#totalNetAssetDueForZak').val(accounting.formatNumber(beforeAfterAdjustmentNetCurrentAsset * (muslimShare/100), 2));
						
				var totalNetAssetDueForZak = accounting.unformat($('#totalNetAssetDueForZak').val());
						
				if( totalNetAssetDueForZak > nisab){
					var totalZakatNeedToPay = totalNetAssetDueForZak * (zakatAmount/100);
					$("#zakatForYear").val(accounting.formatNumber(totalZakatNeedToPay, 2));
				}
				else{
					$("#zakatForYear").val(accounting.formatNumber(0, 2));
				}
							
				var zakatForYear = accounting.unformat($("#zakatForYear").val());
							 
				$("#monthlyZakat").val(accounting.formatNumber(zakatForYear/12, 2));
				
			}
			
			if(tt == 1){
				$('#ll').text(accounting.formatNumber(dd,2));
				firstTotal = accounting.unformat(dd);
				//dd = 0;
			}
			else{
				$('#pp').text(accounting.formatNumber(dd,2));
				secondTotal = accounting.unformat(dd);
				
			}
			//alert(fad);
			if(me.checked == 1){
				$('#totCurrentAssetLiabilitiesAdj').text(accounting.formatNumber(0,2));
			}
			else{
				totalAdj = firstTotal - secondTotal;
				$('#totCurrentAssetLiabilitiesAdj').text(accounting.formatNumber(totalAdj,2));
			}
		});
		
		
	}
</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('title') ?></h2>
                        </div>
                        <div class="content np" id="">    
                            <form id="formValidate" action="#">
                                <div class="controls-row">
                                    <div class="span2"><?php echo $this->lang->line('center') ?></div>
                                    <div class="span4">
                                        <?php
                                        $options = '';
                                        $options[NULL] = $this->lang->line('pleaseSelect');
                                        if ($ZakatCenter != '') {
                                            foreach ($ZakatCenter as $row) {
                                                $options[$row->ID] = $row->name . " [" . $row->shortName . "]";
                                            }
                                        }
                                        $js = 'id="centerID" style="width: 250px;" class="validate[required]" onchange="hideTable()"';
                                        echo form_dropdown('centerID', $options, '', $js);
                                        ?>       
                                    </div>                
                                </div>
                                <div class="controls-row"> 
                                    <div class="span2"><?php echo $this->lang->line('method') ?></div>
                                    <div class="span4">
                                        <?php
                                        $options = '';
                                       // $options[NULL] = $this->lang->line('pleaseSelect');
                                       // $options[1] = $this->lang->line('workingCapital');
									   $options['Working Capital'] = $this->lang->line('workingCapital');
                                    //    $options[2] = $this->lang->line('extentionCapital');
                                        $js = 'id="methodID" style="width: 250px;" class="validate[required]" onchange="hideTable()"';
                                        echo form_dropdown('methodID', $options, '', $js);
                                        ?>       
                                    </div>                
                                </div>
                                <div class="controls-row">
                                    <div class="span2"><?php echo $this->lang->line('year'); ?></div>
                                    <div class="span4">
                                        <?php
                                        $preselyear = date("Y");
                                        $options = '';
                                        for ($i = -5; $i < 20; $i++) {
                                            $options[date('Y', strtotime($i . "  year"))] = date('Y', strtotime($i . "  year"));
                                        }
                                        $js = 'class="input-medium validate[required]" id="nisabYear" onchange="hideTable()"';
                                        echo form_dropdown('nisabYear', $options, $preselyear, $js);
                                        ?>       
                                    </div>
                                </div>
                            </form>
                            <div class="footer">
                                <div class="side fr">
                                    <div class="btn-group">
                                        <?php
                                        $data = array(
                                            'name' => 'mysubmit',
                                            'class' => 'btn-form btn-warning-form');
                                        $js = 'onclick="Calculcate()"';
                                        echo form_button($data, $this->lang->line('Calculate'), $js);
                                        ?>
                                    </div>
                                </div>
                            </div>                                    
                        </div>  
                    </div>  
                </div> 
            </div>  
            <div class="row-fluid" id="calculateHeader">
                <div class="span12">
                    <!-- div class="block">
                        <div class="head">
                            <h2><?php echo $this->lang->line('title1') ?></h2>
                        </div>
                        <div class="content">
                            <div class="controls-row">
                                <div class="span2"><?php echo $this->lang->line('totalAssets') ?></div>
                                <div class="span4">
                                    <?php
                                    $data = array(
                                        'name' => 'totalAssets',
                                        'id' => 'totalAssets',
                                        'disabled' => 'disabled',
                                        'class' => 'span12 tar',);
                                    echo form_input($data, set_value('totalAssets'));
                                    ?>                       
                                </div>                            
                                <div class="span2 tar"><?php echo $this->lang->line('totalLiability') ?></div>
                                <div class="span4">
                                    <?php
                                    $data = array(
                                        'name' => 'totalLiability',
                                        'id' => 'totalLiability',
                                        'disabled' => 'disabled',
                                        'class' => 'span12 tar',);
                                    echo form_input($data, set_value('totalLiability'));
                                    ?>                       
                                </div>                            
                            </div>    
                            <div class="controls-row">
                                <div class="span8"><?php echo $this->lang->line('zakatPerniagaan') ?></div>
                                <div class="span4 tar">
                                    <?php
                                    $data = array(
                                        'name' => 'zakatPerniagaan',
                                        'id' => 'zakatPerniagaan',
                                        'disabled' => 'disabled',
                                        'class' => 'span12 tar',);
                                    echo form_input($data, set_value('zakatPerniagaan'));
                                    ?>                       
                                </div>                            
                            </div>    
                            <div class="controls-row">
                                <div class="span8"><?php echo $this->lang->line('zakatPay') ?></div>
                                <div class="span4 tar">
                                    <?php
                                    $data = array(
                                        'name' => 'zakatPay',
                                        'id' => 'zakatPay',
                                        'disabled' => 'disabled',
                                        'class' => 'span12 tar',);
                                    echo form_input($data, set_value('zakatPay'));
                                    ?>                       
                                </div>                            
                            </div>    
                        </div> 
                        <div class="footer">
                            <div class="side fr">
                                <div class="btn-group">
                                    <?php
                                    $data = array(
                                        'name' => 'Submit',
                                        'class' => 'btn-form btn-success-form');
                                    $js = 'onclick="saveData()"';
                                    echo form_button($data, $this->lang->line('submit'), $js);
                                    ?>
                                </div>
                            </div>
                        </div>                                    
                    </div>  
                </div>  -->
                <div class="row-fluid" id="calculateDetails">
                    <div class="span12">
                        <div class="block">
                            <div class="head">
                                <h2><?php echo $this->lang->line('title2') ?></h2>
                                 <ul class="buttons">
                                    <li><a class="block_toggle collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                                            <span class="i-arrow-down-3"></span></a></li>
                                </ul>  
                            </div>
                            
                            <div class="content np table-sorting">
                                <table cellpadding="0" cellspacing="0" width="100%" id="oTable" class="editable">
                                    <thead>
                                        <tr>
                                            <th style="display:none"></th>
                                            <th class="span1 tac">#</th>
                                            <th><?php echo $this->lang->line('description') ?></th>
                                            <th class="tar"><?php echo $this->lang->line('amount') ?></th>
                                            <th class="tac"><input type='checkbox' name='select-all' id='select-all' checked='checked' onclick="checkAll(this)" /></th>
                                            <th class="tar"><?php echo $this->lang->line('adjustment') ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div><!-- content -->
                        </div>  <!-- block -->
                    </div>  <!-- span12 -->
                </div>  <!-- row-fluid -->
                <div class="row-fluid scRow ">  
                    <div class="block">
                        <div class="head">
                            <h2><?php echo $this->lang->line('title1') ?></h2>
                        </div>
                        <div class="content">
                            <div class="span6 scCol">
                                <div class="block" id="grid_block_1">
                                    <div class="content">
                                        
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('zakatRate') ?></div>
                                            <div class="span8">
                                                <input id="zakatRate" name="zakatRate" value="2.50" type="text" disabled="disabled" placeholder="0.00" class="span9 tar">   
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="%" class="span3 tac"> 
                                            </div>
                                        </div> <!-- row -->

                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('muslimOwnershipShare') ?></div>
                                            <div class="span8">
                                                <input id="muslimOwnershipShare" name="muslimOwnershipShare" type="text" disabled="disabled" placeholder="0.00" class="span9 tar">
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="%" class="span3 tac"> 
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('nisab') ?></div>
                                            <div class="span8">
                                                <input id="nisabTotal" name="nisabTotal" type="text" disabled="disabled" placeholder="0.00" class="span9 tar">  
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="<?php echo $companyCurrency; ?>" class="span3 tac"> 
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('monthlyZakat') ?></div>
                                            <div class="span8">
                                                <input id="monthlyZakat" name="monthlyZakat" type="text" disabled="disabled" placeholder="0.00" class="span9 tar">  
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="<?php echo $companyCurrency; ?>" class="span3 tac"> 
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                         <div class="controls-row">
                                            <div class="span4"></div>
                                            <div class="span8">
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                    </div><!-- grid block 1-->
                                </div>
                            </div><!-- scCol -->
                            <div class="span6 scCol">
                                <div class="block" id="grid_block_2">
                                    <div class="content">
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('netCurrentAsset') ?></div>
                                            <div class="span8">
                                                <input id="netCurrentAsset" name="netCurrentAsset" type="text" disabled="disabled" placeholder="0.00" class="span9 tar">  
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="<?php echo $companyCurrency; ?>" class="span3 tac"> 
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('adjustment'); ?></div>
                                            <div class="span8">
                                                <input id="adjustmentNetCurrentAsset" name="adjustmentNetCurrentAsset" type="text" disabled="disabled" placeholder="0.00" class="span9 tar">  
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="<?php echo $companyCurrency; ?>" class="span3 tac"> 
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                        
										<div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('adjustmentNetCurrentAsset'); ?></div>
                                            <div class="span8">
                                                <input id="beforeAfterAdjustmentNetCurrentAsset" name="beforeAfterAdjustmentNetCurrentAsset" type="text" disabled="disabled" placeholder="0.00" class="span9 tar">  
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="<?php echo $companyCurrency; ?>" class="span3 tac"> 
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                        
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('totalNetAssetDueForZak') ?></div>
                                            <div class="span8">
                                                <input id="totalNetAssetDueForZak" name="totalNetAssetDueForZak" type="text" disabled="disabled" placeholder="0.00" class="span9 tar"> 
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="<?php echo $companyCurrency; ?>" class="span3 tac"> 
                                            </div><!-- span -->
                                        </div><!-- control row -->

                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('zakatForYear') ?></div>
                                            <div class="span8">
                                                <input id="zakatForYear" name="zakatForYear" type="text" disabled="disabled" placeholder="0.00" class="span9 tar">  
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="<?php echo $companyCurrency; ?>" class="span3 tac"> 
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                        <!--div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('monthlyZakat') ?></div>
                                            <div class="span8">
                                                <input id="monthlyZakat" name="monthlyZakat" type="text" disabled="disabled" placeholder="0.00" class="span9 tar">  
                                                <input   type="text" disabled="disabled" placeholder="0.00" value="<?php echo $companyCurrency; ?>" class="span3 tac"> 
                                            </div><!-- span -->
                                        <!--/div><!-- control row -->
                                    </div>

                                </div><!-- grid block 1-->
                            </div><!-- scCol -->
                            <div class="footer">
                                <div class="side fr">
                                    <div class="btn-group">
                                        <?php
                                        $data = array(
                                            'name' => 'Submit',
											'id' => 'finalSubmitBtn',
											'type' => 'button',
                                            'class' => 'btn-form btn-success-form');
                                        $js = 'onclick="saveData()"';
                                        echo form_button($data, $this->lang->line('submit'), $js);
                                        ?>
                                        <!--<a href="#" id="finalSubmitBtn" onclick="saveData()" class="btn-form btn-success-form"><?php //echo $this->lang->line('submit') ?></a>-->
                                    </div>
                                </div>
                            </div> 
                        </div>
                    </div> 
                </div> 
            </div>  <!-- wrap -->
        </div>  <!-- content -->
        </div>
        </div>
        </div>
        </div>
