<?= $this->extend('layouts/main.php') ?>

<?= $this->section('content') ?>
<?php
$startdate = date("Y-m-01");
$enddate = date("Y-m-d");
?>
<div class="page-wrapper">
	<div class="container-fluid">
        <div class="row page-titles">
			<div class="col-md-5 align-self-center">
				<h4 class="text-themecolor">Bugs Count</h4>
			</div>
		</div>
        <div class="row">
			<div class="col-12">
				<div class="card">
					<div class="card-body">
                        <form action="" method="post">
                            <div class="row mb-2">
                                <div class="col md-6">
                                    <div class="input-group input-group-sm">
                                        <span class="input-group-text d-flex align-items-center justify-content-center" style="width: 80px;">From</span>
                                            <input class="form-control form-control-sm" type="date" name="startdate" value="<?=$startdate;?>"/>
                                    </div>
                                </div>
                                <div class="col md-6">
                                    <div class="input-group input-group-sm">
                                        <span class="input-group-text d-flex align-items-center justify-content-center" style="width: 80px;">To</span>
                                            <input class="form-control form-control-sm" type="date" name="enddate" value="<?=$enddate;?>"/>
                                    </div>
                                </div>
                            </div>
                            <button type="submit" class="btn btn-success btn-sm text-white float-end"> <i class="fa fa-check"></i> Submit</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
		<?php
		if(isset($count)) {
		?>
        <div class="row mt-2">
      		<div class="col-12">
				<div class="card">
					<div class="card-body">
						<div class="table-responsive">
							<table id="myTable" class="table small display border">
								<thead class="table-info">
									<tr>
                                        <th style="width:40%;">Name</th>
                                        <th>Issued / Closed</th>
										<th>Solving</th>
										<th>Total comment</th>
									</tr>
								</thead>
								<tbody>
								<?php 
									foreach($count as $row) {
										$firstname = $row['firstname'];
										$lastname = $row['lastname'];
										$bugopen = $row['bugopen'];
										$bugclose = $row['bugclose'];
										$bugcloser = $row['bugcloser'];
										$bugcomment = $row['bugcomment'];
										if( $bugopen != 0 || $bugclose != 0 || $bugcloser != 0 || $bugcomment != 0) { 
											echo "<tr> <td>$firstname $lastname</td> <td>$bugopen / $bugclose</td> <td>$bugcloser</td> <td>$bugcomment</td> </tr>";
										}
									}
								?>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<?php 
		}
		?>
    </div>
</div>

<?= $this->endSection() ?>

<?= $this->section('script') ?>

<!-- SCRIPT EXPORT TABLE TO EXCEL -->
<script>
    function exportToExcel() {
        const data = document.getElementById("myTable"); //const data = $("#myTable")[0]; kalo pake jquery
        var ws = XLSX.utils.table_to_sheet(data);

        var wb = XLSX.utils.book_new();
        XLSX.utils.book_append_sheet(wb, ws, "Sheet 1");
        XLSX.writeFile(wb, "ActivityCount.xlsx");
      }
</script>

<?= $this->endSection() ?>