<?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>
			$(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 downloadExcel(){
				var url = "<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'/'.true; ?>";
				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>
            
                        </tr>
                    </thead>
                    <tbody class="tbPrint">
                        <?php
                        $i = 1;
                        $total = 0;
                        $nHeader = 0;
                        $firstTime = TRUE;
						$totalGroup = array();
						
						
						
						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 ($firstTime ==FALSE){
                                     echo "<tr><td colspan='2'></td><td class='tar'>Total : ".number_format($totalGroup[$group],2)."</td></tr>";
                               }  else {
                                    $firstTime = FALSE;
                               } 
                                $i =1;
                                $group = $row1->acctGroup;
                              
                              echo   "<tr><td colspan='3'>".$group."</td></tr>";
                            }
                               
                            
                             $tr ="<tr><td>".$i++."</td>";
                            $tr .= "<td>".$row1->desc."</td>";
                             $tr .= "<td class='tar'>".number_format($row1->amount,2)."</td>";	
                            $tr .= "</tr>";
                            echo $tr;
                        }
						echo "<tr><td colspan='2'></td><td class='tar'>Total : ".number_format($totalGroup[$group],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">
    	<style>
        	.table1 td{
				border:1px solid #dddddd;
				padding:5px;
			}
        </style>
    	<table class="table1" cellpadding="0" cellspacing="0" width="100%">
        	<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>           
                    
            <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="left" colspan="2" class="no-print">
                            <button title="Print" class="btn-icon btn-success-form Print" onclick="do_print()" type="button" name="Print"><i class="icon-print"></i></button> 
                            <!--button title="Download" class="btn-icon btn-warning-form EXCEL" onclick="downloadExcel()" type="button" name="EXCEL"><i class="icon-download"></i></button-->
                            <button title="Close" class="btn-icon btn-danger-form Close" onclick="javascript:window.close();" type="button" name="Close">
							<i class="icon-off"></i></button>       
						</td>
                    </tr>
                
                
            </tbody>
        </table>
   </body>
</html>