<tr>
<th>Office Code</th>
<th>Document Date</th>
<th>Subject</th>
<th>Reference Number</th>
<th>Action Taken</th>
<th>Action Date</th>
<th>Status</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<?php 
    for ($i = 0; $i < $nm; $i++) {
        $row = $rs->fetch_assoc();
        $referenceNumber = calculateReferenceNumber($db, $row, adjustControlNumber($row['ref_id']));
        $sql2 = "select * from document_routing where reference_no='" . $row['ref_id'] . "' order by request_date desc";
        $rs2 = $db->query($sql2);
        $row2 = $rs2->fetch_assoc();
        $sql3 = "select * from routing_targets where routing_id='" . $row2["id"] . "'";
        $rs3 = $db->query($sql3);
        $row3 = $rs3->fetch_assoc();
        $action = getAction($db, $row3['action_id']);
        ?>
		<tr>
			<td><?php 
        echo $row['sending_office'];
        ?>
</td>
			<td><?php 
        echo $row['document_date'];
    ?>
</td>
					<td><?php 
    echo getOriginatingOffice($db, $searchRow['originating_office']);
    ?>
</td>
					<td><?php 
    echo $searchRow['document_date'];
    ?>
</td>
					<td><?php 
    echo $searchRow['receive_date'];
    ?>
</td>
					<td><?php 
    echo calculateReferenceNumber($db, $searchRow, adjustControlNumber($searchRow['ref_id']));
    ?>
</td>
				</tr>
			<?php 
}
?>
			</tbody>
			<tfoot>
				<tr>
				<th>Subject</th>
				<th>Originating Office</th>
				<th>Document Date</th>
				<th>Received Date</th>
				<th>Reference Number</th>
				</tr>			
<tr>
<th>Office Code</th>
<th>Document Date</th>

<th>Subject</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php 
    $routing_Option = "<select class='form-control' name='reference_number'>";
    for ($i = 0; $i < $nm; $i++) {
        $row = $rs->fetch_assoc();
        $document_type = getDocumentType($db, $row['document_type']);
        $docId = $row['ref_id'];
        $reference_number = calculateReferenceNumber($db, $row, adjustControlNumber($docId));
        ?>
<tr>
<td><?php 
        echo $row['sending_office'];
        ?>
</td>
<td><?php 
        echo date("Y-m-d", strtotime($row['document_date']));
        ?>
</td>
<td><a href='submit.php?reference_number=<?php 
        echo $reference_number;
        ?>
'><?php 
        echo $row['subject'];
<tr>
<th>Subject</th>
<th>Classification</th>
<th>Document Date</th>
<th>Originating Office</th>
<th>Information</th>
</tr>
</thead>

<tbody>
<?php 
    $routing_Option = "<select class='form-control' name='reference_number'>";
    for ($i = 0; $i < $nm; $i++) {
        $row = $rs->fetch_assoc();
        $row2 = getDocumentDetails($db, $row['reference_no']);
        $reference = calculateReferenceNumber($db2, $row2, adjustControlNumber($row['reference_no']));
        ?>
<tr>
<td><?php 
        echo $row2['subject'] . " " . $reference;
        ?>
 <a style="color:red" href='download.php?refId=<?php 
        echo $row2['ref_id'];
        ?>
' target='window'>[Link]</a></td>
<td>Office Order</td>
<td><?php 
        echo date("Y-m-d", strtotime($row2['document_date']));
        ?>
</td>
<td><?php 
			$rr[0]="a".$i;
			$rr[1]="b".$i;
			addContent($rr,$excel,getOriginatingOffice($db, $row['originating_office']),"true",$ExWs);
			setCellArea($rr,$excel,$ExWs,$excel);
		styleCellArea(setRange($rr[0],$rr[1]),"false","true",$ExWs,$excel);

			$rr[0]="c".$i;
			$rr[1]="d".$i;
			addContent($rr,$excel,$row['subject'],"true",$ExWs);
			setCellArea($rr,$excel,$ExWs,$excel);
		styleCellArea(setRange($rr[0],$rr[1]),"false","true",$ExWs,$excel);

			$rr[0]="e".$i;
			$rr[1]="f".$i;
			addContent($rr,$excel,calculateReferenceNumber($db,$row,adjustControlNumber($row['ref_id'])),"true",$ExWs);
			setCellArea($rr,$excel,$ExWs,$excel);
		styleCellArea(setRange($rr[0],$rr[1]),"false","true",$ExWs,$excel);

			$rr[0]="g".$i;
			$rr[1]="g".$i;
			addContent($rr,$excel,$row['document_type'],"true",$ExWs);
			setCellArea($rr,$excel,$ExWs,$excel);
		styleCellArea(setRange($rr[0],$rr[1]),"false","true",$ExWs,$excel);

			$rr[0]="h".$i;
			$rr[1]="i".$i;
			addContent($rr,$excel,date("Y-m-d", strtotime($row['document_date'])),"true",$ExWs);
			setCellArea($rr,$excel,$ExWs,$excel);
		styleCellArea(setRange($rr[0],$rr[1]),"false","true",$ExWs,$excel);