<?php
    $CI =& get_instance();
    $CI->load->model('company/company_info_model');
    $company = $CI->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Reporting</title>
      
        <link  rel="stylesheet" type="text/css"  href="<?php echo base_url() ?>css/bootstrap/bootstrap.min.css" />
        <?php echo put_headers(); ?>
        <style>
			@media print {     .no-print, 	.no-print *, #scrollUp {         display: none !important;     } }
            @media print {
                .td-print,.td-print*{display:none !important;}
				.printTbl hr{
					margin:0 !important;
				}
				.thPrint th{
					background:url(<?php echo base_url() ?>img/rptPaymentAdvice.png) !important;
                	-webkit-print-color-adjust: exact;
				}
            }
        </style>

        <script language="javascript" type="text/javascript">
			$(document).ready(function(){
				$('.image').height($('.thPrint').height());
				$('.image').width($('.thPrint').width());
			});
        
            function do_print() {
                window.print();
            }

//             function getExcelFile() {
                var url = '<?php echo base_url(); echo isset($myUrl) ? $myUrl:''; echo '/'; echo isset($id)?$id:''; ?>"';
                //var url = "<?php echo base_url() ?>ApTransactionReport/printPaymentAdviceRptExel/<?php echo isset($id)?$id:''; ?>";
//                         window.location.href = url;
//                     }
            function do_printexcel(){
				var url = "<?php echo base_url()?>zakatReport/zakatRptExcel/<?php echo $id ?>";
				window.location.href = url;
            }
        </script>

    </head>

    <body>
        <table  style="width:97%; margin-top:20px; margin:auto;" class="printTbl">
            <tbody>
                        <tr>
                            <td colspan="2" >
                                <p style="text-align: right; margin:0; padding-right: 10px; font-weight: 500; line-height: 2; padding-bottom: 0px; padding-top: 0px; color: black; font-size: 25px;">
                                    <?php if(isset($rptTitle)) echo $rptTitle; ?>
                                </p>
                                <?php
                                if (isset($company)) {
                                    foreach ($company as $rowC) {
                                        ?>
                                        <p style="text-align:center; font-size:16px;"> 
                                            <span style=" font-weight:800;"><?php echo $rowC->companyName; ?></span> <span style="font-size:10px;"><?php echo "(".$rowC->companyNo.")";?></span><br />
                                            <span style="font-size:10px;"><?php echo "GST Registration No : ".$rowC->gstRegisteredNo; ?></span><br />
                                        </p>
                                        <p style="text-align:center; font-size:10px; line-height:1.4; padding:0 0 5px; margin:0; border-bottom:1px solid #eeeeee;">

                                            <?php if(!empty($rowC->line1)): ?><span><?php echo $rowC->line1; ?></span><br /><?php endif; ?>
                                            <?php if(!empty($rowC->line2) || !empty($rowC->line3)): ?><span><?php echo $rowC->line2.", ".$rowC->line3; ?></span><br /><?php endif; ?>
                                            <?php if(!empty($rowC->companyPostCode) || !empty($rowC->city)): ?><span><?php echo $rowC->companyPostCode . '  ' . $rowC->city; ?> </span><br /><?php endif; ?>
                                            <?php if(!empty($rowC->fldname) || !empty($rowC->fldcountry)): ?><span><?php echo $rowC->fldname . '  ' . $rowC->fldcountry; ?> </span><br /><?php endif; ?>
                                            <?php if(!empty($rowC->phoneNo) || !empty($rowC->faxNo)): ?><span><?php echo 'Phone : ' . $rowC->phoneNo . '  Fax : ' . $rowC->faxNo; ?> </span><?php endif; ?>
                                        </p>
                                    <?php }
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <?php
                                if (isset($leftContentHeader)){
                                    echo "<p style='padding-left:10px; margin:0; font-size:11px; '>"
                                    . "<strong>".$leftContentHeader."</strong></p>";
                                }
                                 
                                 if (isset($leftContent)){
                                   echo '<p style="padding-left:10px; margin:0; line-height:1.4;">';
                                    foreach ($leftContent as $value) {
                                         echo $value != ''?"<span>".$value."</span><br />":'';
                                     }
                                  echo '</p>';
                                 }
                                
                                ?>
                            </td>
                                
                                <td style="float:right;" valign="top">
                                    <p style="line-height:1.4; text-align:left;">
                                        <?php
	                                        if (isset($rightContentHeader)){
	                                        	echo "<p style='padding-right:10px; margin:0; font-size:11px; '>"
	                                        			. "<strong>".$rightContentHeader."</strong></p>";
	                                        } 
                                            if (isset($rightContent)){
                                                 foreach ($rightContent as $value) {
                                                    echo $value != ''?"<span>".$value."</span><br />":'';
                                                }
                                            }
                                        ?>
                                    </p>
                                  </td>
                            </tr>
                
                <?php $tdNoFormat = isset($tdNoFormat)?$tdNoFormat:array(); ?>
<style>
	.table th,.table td{
		line-height:10px;
	}
</style>
     <?php if (!empty($rptDataDetail)) { ?>
                
	<?php if(isset($headerLeft)): ?>
    <tr>
    	<td colspan="2">
        	<?php 
				echo "<p style='padding-left:10px; margin:0; font-size:11px; '>"
								. "<strong>".$headerLeft."</strong></p>"
			?>
        </td>
    </tr>
    <?php endif; ?>
                
    <tr>
       <td colspan="2" style="position: relative">
       			<img class="image" style="position:absolute;left:0;top:0;z-index: -1000" alt="" src="<?php echo base_url() ?>img/rptPaymentAdvice.png" />
                <table class="table" style="z-index: 100" cellpadding="0" cellspacing="0" width="80%">
                   
                    <thead class="thPrint">
                        <tr> <?php /*style="background:url(<?php echo base_url() ?>img/rptPaymentAdvice.png)" */ ?>
                            <th>No.</th>
                            <th><?php echo $this->lang->line("description"); ?></th>
                            <th class="tar"><?php echo $this->lang->line("amount"); ?></th>
                            <th class="tar"></th>
                            <th class="tar"><?php echo $this->lang->line("adjustment"); ?></th>
            
                        </tr>
                    </thead>
                    <tbody class="tbPrint">
                        <?php
                        $i = 1;
                        $total = 0;
                        $nHeader = 0;
                        $firstTime = TRUE;
						$totalGroup = array();
						
						$totalCheckAbleAmountBefore = 0;
						$totalCheckAbleAmount = 0;
						$totalAdjustment = 0;
						
						$n = 1;
						$totalNet = 0;
						$firstGroup = 0;
						$secondGroup = 0;
						$totalNetCurrentAssetfirst = 0;
						$totalNetCurrentAsset = 0;
						
						if(!empty($rptDataDetail)){
                            //$group = $rptDataDetail[0]->acctGroup;
                      		 $group = '';
                        	foreach ($rptDataDetail as $row1) {
								if ($group!=$row1->acctGroup){
									$group = $row1->acctGroup;
									$totalGroup[$group] = $row1->amount;
								}
								else{
									$totalGroup[$row1->acctGroup] = $totalGroup[$row1->acctGroup] + $row1->amount;
								}
									//else{
										
								//$totalGroup[$group] = $totalGroup[$group] + $rptDataDetail[0]->amount;}
							}
	 					}
						
						/*if(!empty($rptDataDetail)){
                            //$group = $rptDataDetail[0]->acctGroup;
                      		 $group = '';
                        	foreach ($rptDataDetail as $row1){
								$totalGroup[$row1->acctGroup] = $totalGroup[$row1->acctGroup] + $row1->amount;
							}
	 					}*/
						
						//var_dump($totalGroup);
                         if (isset($tableHeader))
                              $nHeader =  sizeof($tableHeader);
							  $i = 1;
                        if(!empty($rptDataDetail)):
                            $group = "";
                      
                        foreach ($rptDataDetail as $row1) {
                             
                             $total = $total + $row1->amount;
							 if($group!=$row1->acctGroup){
								 if($n == 1){
							 		$firstGroup = $firstGroup + $row1->amount;
									$n = 2;
								 }
								 else if($n == 2){
									 $totalNetCurrentAssetfirst = $totalNetCurrentAsset;
									 $totalNetCurrentAsset = 0;
									 $secondGroup = $secondGroup + $row1->amount;
								 }
							 }
							 else if($group == $row1->acctGroup){
							 	$totalNetCurrentAsset = $totalNetCurrentAsset + $row1->amount;
							 }
							 
							 /*if(($n == 1) && ($group==$row1->acctGroup)){
							 	$totalNetCurrentAsset = $totalNetCurrentAsset + $row1->amount;
								$n ++;
							 }
							 else if(($n != 1) && ($group==$row1->acctGroup)){
							 	$totalNetCurrentAsset = $totalNetCurrentAsset + $row1->amount;
								$n ++;
							 }
							 else if(($n != 1) && ($group!=$row1->acctGroup)){
								 $totalNet = $totalNetCurrentAsset;
								 $totalNetCurrentAsset = 0;
								 $n = 1;
							 }*/
							 
							 if($row1->checkAble == 0){
								 $totalCheckAbleAmount = $totalCheckAbleAmount + $row1->amount;
							 }
                           
                            if ($group!=$row1->acctGroup){
                               if ($firstTime ==FALSE){
                                     echo "<tr>
									 		<td colspan='2'></td>
											<td class='tar'>Total : ".number_format($totalGroup[$group],2)."</td>
											<td></td>
											<td class='tar'>".number_format($totalCheckAbleAmount,2)."</td>
										</tr>";
									$totalCheckAbleAmountBefore = $totalCheckAbleAmount;
									$totalCheckAbleAmount = 0;
									
                               }  else {
                                    $firstTime = FALSE;
                               } 
                                $i =1;
                                $group = $row1->acctGroup;
                              
                              echo   "<tr><td colspan='5'>".$group."</td></tr>";
                            }
                               
                            
                             $tr ="<tr><td>".$i++."</td>";
                             $tr .= "<td>".$row1->desc."</td>";
                             $tr .= "<td class='tar'>".number_format($row1->amount,2)."</td>";
							 if($row1->checkAble == 1){
								 $tr .= "<td class='tar'><span class='i-checkmark-2'></td>"; 
							 	 $tr .= "<td class='tar'>".number_format(0,2)."</td>";
							 }
							 else{
								 $tr .= "<td class='tar'></td>";
								 $tr .= "<td class='tar'>".number_format($row1->amount,2)."</td>";
							 }
                            $tr .= "</tr>";
                            echo $tr;
                        }
						
						$totalAdjustment = $totalCheckAbleAmountBefore - $totalCheckAbleAmount;
						$a = $firstGroup + $totalNetCurrentAssetfirst;
						$b = $secondGroup + $totalNetCurrentAsset;
						$c = $a - $b;
						echo "<tr>
								<td colspan='2'></td>
								<td class='tar'>Total : ".number_format($totalGroup[$group],2)."</td>
								<td></td>
								<td class='tar'>".number_format($totalCheckAbleAmount,2)."</td>
							</tr>";
							
						echo "<tr>
								<td colspan='3' class='tar'>Net Current Asset (Current Asset - Current Liabilities) : ".number_format($c,2)."</td>
								<td></td>
								<td class='tar'>".number_format($totalAdjustment,2)."</td>
							</tr>";
						
                        endif;
                    ?>
                    	
                    
                        <?php 
                            if (isset($tableFooter)){
                                if (in_array("#",$tableHeader)) 
                                    echo " <tr><td style='text-align:right;' colspan='".sizeof($tableHeader)."'>";
                                else 
                                    echo " <tr><td style='text-align:right;' colspan='".(sizeof($tableHeader)+1)."'>";
                                
                                 foreach ($tableFooter as $value) {
                                    echo "<p>".$value."</p>";
                              }
                              echo "</td></tr>";
                            }
                        ?>
                </tbody>
            </table>
               <?php// $rptDataDetail[] = $rptDataDetail[0]; echo count((array)$rptDataDetail); echo "hsssssssdakjdnaldkmaldkmad"; ?>        
      </td>
</tr>
     <?php } ?>

                <tr>
	<!--<td valign="top" class="span8">
    	<?php //if(isset($ftrLeftContentHeader) || isset($ftrLeftContent)): ?>
        <div class="row-fluid span6" style="padding:0 20px 10px 0;margin:0 0 10px;">
        	<?php
				/*if (isset($ftrLeftContentHeader)){
					echo "<p class='span10' style='padding-right:10px; margin:0; font-size:11px; '>"
							. "<strong>".$ftrLeftContentHeader."</strong></p>";
				} 
				if (isset($ftrLeftContent)){
					 foreach ($ftrLeftContent as $value) {
						echo ($value != '')?"<span class='span10' style='margin-left:0px !important;text-align:justify;'>".$value."</span><br />":'';
					}
				}*/
			?>
        </div>
        <?php //endif; ?>
    </td>-->
    <!--<td valign="top" align="right" class="span6">-->
    <td valign="top" align="right">
    	<style>
        	.table1 td{
				border:1px solid #dddddd;
				padding:5px;
			}
        </style>
    	<table class="table1" cellpadding="0" cellspacing="0" width="80%">
        	<tbody>
				<?php 
                    /*if (isset($amountCount)){
                        foreach ($amountCount as $value) {
							$temp = explode(":",$value);
                        	echo "<tr><td valign='middle'>";
                            echo "<p style='line-height:10px; float:left;'><b>".$temp[0]."</b></p>";
							echo "</td><td valign='middle'>";
                            echo "<p style='line-height:10px; float:right;'><b>".$temp[1]."</b></p>";
							echo "</td></tr>";
                        }
                    }*/
                ?>
                <tr>
                	<td><b><?php echo $this->lang->line('zakatRate')." :" ?></b></td>
                    <td class="tar"><b><?php echo "2.50 %"; ?></b></td>
                    <td><b><?php echo $this->lang->line('netCurrentAsset')." :" ?></b></td>
                    <td class="tar"><b><?php echo $currency.' '.number_format((double) ( $master->netCurrentAsset), 2); ?></b></td>
                </tr>
                <tr>
                	<td><b><?php echo $this->lang->line('muslimOwnershipShare')." :" ?></b></td>
                    <td class="tar"><b><?php echo number_format((double) ($master->muslimOwnershipShare), 2)." %";; ?></b></td>
                    <td><b><?php echo $this->lang->line('adjustment')." :" ?></b></td>
                    <td class="tar"><b><?php echo $currency.' '.number_format((double) ($adjustment), 2); ?></b></td>
                </tr>
                <tr>
                	<td><b><?php echo $this->lang->line('nisab')." :" ?></b></td>
                    <td class="tar"><b><?php echo $currency.' '.number_format((double) ($master->nisab), 2); ?></b></td>
                    <td><b><?php echo $this->lang->line('adjustmentNetCurrentAsset')." :" ?></b></td>
                    <td class="tar"><b><?php echo $currency.' '.' '.number_format((double) ( $master->netCurrentAsset - $adjustment), 2); ?></b></td>
                </tr>
                <tr>
                	<td><b><?php echo $this->lang->line('monthlyZakat')." :" ?></b></td>
                    <td class="tar"><b><?php echo $currency.' '.number_format((double) ($master->monthlyZakatPayable), 2); ?></b></td>
                    <td><b><?php echo $this->lang->line('totalNetAssetDueForZak')." :" ?></b></td>
                    <td class="tar"><b><?php echo $currency.' '.number_format((double) ($master->totalDueForZakat), 2); ?></b></td>
                </tr>
                <tr>
                	<td class="tar"><b></td>
                    <td class="tar"></td>
                    <td><b><?php echo $this->lang->line('zakatForYear')." :" ?></b></td>
                    <td class="tar"><b><?php echo $currency.' '.number_format((double) ($master->zakatPayableForTheYear), 2); ?></b></td>
                </tr>
        	</tbody>
        </table>
    </td>
</tr>           
                    
            <tr>
                	<td colspan="2">
                     <br /> 
                    	 <p style="text-align: right; font-size:8px; font-weight:500;"> Prepared by &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        Aprproved By&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;       Receive By</p>
                         
                         <br />
                    	<p>
                            <p style="text-align: right; font-weight: 600; font-size: 8px;">SYSTEM GENERATED NO SIGNATURE REQUIRED</p>
                            <hr style="border: 1px solid #dddddd;" />
        <div class="row-fluid">
                          <div class="span4"><?php echo date("m/d/Y G:i:s"); ?></div>
                          <div class="span4">Private and Confidential</div>
                          <div class="span4"></div>
    </div>
                        </p>
                    </td>
                </tr>
                <tr>
                        <td align="center" colspan="2">
                        <br />
                            <div class="printButton" align="left">
                            <?php 
                            $js = 'onClick="do_print()" class="btn-icon btn-success-form Print" title="Print"';
                            echo form_button('Print','<span class="icon-print">',$js);?> <?php
                            $js = 'onClick="do_printexcel()" class="btn-icon btn-warning-form EXCEL" title="Download"';
                            echo form_button('EXCEL','<span class="icon-download">',$js);?> <?php
                            $js = 'onClick="javascript:window.close();" class="btn-icon btn-danger-form Close" title="Close"';
                            echo form_button('Close','<span class="icon-off">',$js);?>
                            </div>
                        </td>
                    </tr>
                
                
            </tbody>
        </table>
   </body>
</html>