<?php
    $CI =& get_instance();
    $CI->load->model('company/company_info_model');
    $company = $CI->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
?>
<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" height="10%"></td>
    </tr>            
    <tr>
       <td colspan="2" style="position: relative">
                <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>
            
                        </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='2'></td>
								<td 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>
                      
      </td>
</tr>
	<tr>
		<td colspan="3">
        	<style>
        	.table1 td{
				border:1px solid #dddddd;
				padding:5px;
			}
        	</style>
        	<table class="table1" cellpadding="0" cellspacing="0" width="70%">
        	<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>";
                        }
                    }
                ?>
        	</tbody>
        </table>
        </td>
	</tr>
     <?php } ?>

                