<style>

	#total{
        border-collapse: collapse;
    }
    #total td {
        border: 1px solid #000; 
    }
	 
	#lineheader td {
        border-top: 1px solid #000; 
    }
	
	#lastline td {
        border-bottom: 1px solid #000; 
    }
	
	#iniprint th {
		border-top: 1px solid #000;
		border-bottom: 1px solid #000;
	}

</style>

<?php $tdNoFormat = isset($tdNoFormat)?$tdNoFormat:array(); ?>

<?php if (!empty($rptDataDetail)) { ?>
    <tr id="lineheader">
    	<td colspan="2"><br />
        	<p style="font-size:24px; font-family:roboto"><b><?php echo $reportheader; ?></b></p><br />
        </td>
    </tr> 
    <tr>
    	<td colspan="2">
        	<table id="total" cellpadding="0" cellspacing="0" width="40%">
                <thead>
                	<tr>
                    	<td width="40%">&nbsp;&nbsp;&nbsp;<?php echo $this->lang->line('totalmember') ?></td>
                        <td>&nbsp;&nbsp;&nbsp;<b><?php echo $memberNo; ?></b></td>
                    </tr>
                    <tr>
                    	<td width="40%">&nbsp;&nbsp;&nbsp;<?php echo $this->lang->line('totalvote') ?></td>
                        <td><b>&nbsp;&nbsp;&nbsp;<?php echo $companyName; ?></b></td>
                    </tr>
                </thead>
            </table>
        </td>
    </tr>
    <tr>
    	<td colspan="2" align="right">
        	<?php 
				echo "<p style='padding-right:10px; margin:0; font-size:16px; '>" . "<b>".date('d-m-Y')." ".date("h:i:sa")."</b></p>"
			?>
        </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">-->
                <thead>
                    <tr id="iniprint">
                        <?php 
                            if (isset($tableHeader)){
	                            if (!in_array("#",$tableHeader))
	                                echo " <th>No.</th>"; 
									$p = 0;
									foreach ($tableHeader as $value) {
		                            	if (isset($tdAmount) && in_array($selectFields[$p++],$tdAmount)) {	
											echo " <th style='text-align:right;'>".$value."</th>";
										}else{
											echo " <th>".$value."</th>";
										}
									}
	                        }
	                    ?>
                    </tr>
                </thead>
                <tbody class="tbPrint">
                <?php
                    $i = 1;
					$positionID = 0;
					$count = 0;
					$elected = 0;
                    foreach ($rptDataDetail as $row1) {
						if($i == 1){
							
							$positionID = $row1->positionID;
							$elected = $row1->elected;
							$count ++;
							
							echo "<tr>";
							echo "<td>".$i."</td>";
							if($elected > 1){
								echo "<td>".$row1->positionName." ".$count."</td>";
							} else{
								echo "<td>".$row1->positionName."</td>";
							}
							echo "<td>".$row1->candidateName."</td>";
							echo "<td>".$row1->companyName."</td>";
							echo "<td>".$row1->countvote."</td>";
							echo "</tr>";
							
							$i++;
							
						} else if($row1->positionID == $positionID){
							
							$count ++;
							
							if($count <= $row1->elected){
								echo "<tr>";
								echo "<td>".$i."</td>";
								if($elected > 1){
									echo "<td>".$row1->positionName." ".$count."</td>";
								} else{
									echo "<td>".$row1->positionName."</td>";
								}
								echo "<td>".$row1->candidateName."</td>";
								echo "<td>".$row1->companyName."</td>";
								echo "<td>".$row1->countvote."</td>";
								echo "</tr>";
								$i++;
							}
							
						} else if($row1->positionID != $positionID){
						
							$positionID = $row1->positionID;
							$elected = $row1->elected;
							$count = 0;
							$count ++;
							
								echo "<tr>";
								echo "<td>".$i."</td>";
								if($elected > 1){
									echo "<td>".$row1->positionName." ".$count."</td>";
								} else{
									echo "<td>".$row1->positionName."</td>";
								}
								echo "<td>".$row1->candidateName."</td>";
								echo "<td>".$row1->companyName."</td>";
								echo "<td>".$row1->countvote."</td>";
								echo "</tr>";
								
							$i++;
						}
                    } ?>
	                <tr id="lastline">
	                	<td></td><td></td><td></td><td></td><td></td>
	                </tr>
	            </tbody>
	        </table><br/>
            
	        <?php for($i=0;$i<$countposition;$i++){ $j=1; ?>

	    		<p style="font-size:24px; font-family:roboto"><b><?php echo $position[$i]->positionName; ?></b></p>
	    		<table class="table" style="z-index: 100" cellpadding="0" cellspacing="0" width="80%">
	                <thead>
	                	<tr id="iniprint">
	                    	<th style="width: 10px;">No.</th>
	                        <th style="width: 100px;"><?php echo $this->lang->line('candidate') ?></th>
	                        <th style="width: 100px;"><?php echo $this->lang->line('entity') ?></th>
	                        <th style="width: 100px;"><?php echo $this->lang->line('totalvote') ?></th>
	                    </tr>
	                </thead>
	    			<?php 
	                    echo "<tbody class='tbPrint'>";
						foreach ($rptDataDetail as $row2) {
							if($position[$i]->positionID == $row2->positionID){
	                    	
								echo "<tr>
	                        			<td>".$j."</td>
	                            		<td>".$row2->candidateName."</td>
	                            		<td>".$row2->companyName."</td>
	                            		<td>".$row2->countvote."</td>
	                        	</tr>";
								$j++;
								
							}
						}
						
						echo"<tr id='lastline'>
	                		<td></td><td></td><td></td><td></td>
	                	</tr>";
						
	                    echo "</tbody>";
					?>
	            </table>

	        <?php } ?>  
      	</td>
    </tr>
<?php } ?>