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

<?= $this->section('content') ?>
<div class="page-wrapper">
	<?php if (session()->get('msg')) : ?>
    <div class="alert alert-warning alert-dismissible fade show" role="alert">
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        <strong><?= session()->getFlashdata('msg'); ?></strong>
        </div>
    <?php endif; ?>
	<div class="container-fluid">
		<div class="row page-titles">
			<div class="col-md-5 align-self-center">
				<h4 class="text-themecolor">Transaction List</h4>
			</div>					
		</div>
		<div class="row">
			<div class="col-12">
				<div class="card">
					<div class="card-body">
						<form method='post' >
							<div class="accordion accordion-flush mb-3" id="accordionForm">
								<div class="accordion-item">
									<h2 class="accordion-header" id="headingForm">
									<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseForm" 
										aria-expanded="false" aria-controls="collapseForm" style='padding:5px;'>
										<span class="me-3"> Filter </span>
									</button>
									</h2>
									<div id="collapseForm" class="accordion-collapse collapse show bg-white" aria-labelledby="headingForm">
										<div class="accordion-body ps-0">	
											<div class="row mb-2">
												<div class="col">
													<div class="input-group input-group-sm">
														<span class="input-group-text d-flex align-items-center justify-content-center" style="width: 80px;">Date</span>
														<input class="form-control form-control-sm" type="date" name="date1" value="<?= $date1;?>" onfocus="this.showPicker()"/>
														<span class="input-group-text d-flex align-items-center justify-content-center">-</span>
														<input class="form-control form-control-sm" type="date" name="date2" value="<?= $date2;?>" onfocus="this.showPicker()"/>
													</div>
												</div>
											</div>											
											<button type="submit" class="btn btn-success btn-sm text-white float-end"> <i class="fa fa-check"></i> Submit</button>
										</div>
									</div>
								</div>
							</div>							
						</form>
					</div>
				</div>
			</div>
		</div>
		
		<?php if(isset($invtrans_itd) || isset($invtrans_act)) { ?>
		<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>
									<tr>
										<th>ID</th> <th></th>
									</tr>
								</thead>
								<tbody>
								<?php
								foreach($invtrans_itd as $data) {
									$itdid = $data['itdid'];
									$subject = $data['subject'];
									echo "<tr> <td>ITD [$itdid] $subject</td> <td>
											<button type='button' class='btn btn-success btn-sm openViewItd' data-itdid='$itdid'><i class='fas fa-eye'></i> View</button>
											<a class='btn btn-warning btn-sm' href='/invtrans/edit/$itdid' 
												onclick=\"window.open(this.href, 'Editor','width=900,height=800,toolbar=1,resizable=0'); return false;\">
												<i class='fas fa-pencil-alt'></i> Edit
											</a>
										</td></tr>";
								}
								?>
								<?php
								foreach($invtrans_act as $data) {
									$actid = $data['actid'];
									$subject = $data['subject'];
									echo "<tr> <td>AR [$actid] $subject</td> <td>
											<button type='button' class='btn btn-success btn-sm openViewAct' data-actid='$actid'><i class='fas fa-eye'></i> View</button>
											<a class='btn btn-warning btn-sm' href='/activities/edit/$actid'><i class='fas fa-pencil-alt'></i> Edit</a>
										</td></tr>";
								}
								?>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<div id="modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="tooltipmodel" aria-hidden="true">
			<div class="modal-dialog modal-dialog-centered modal-xl">
				<div class="modal-content">
				</div>
			</div>
		</div>
		<?php } ?>
	</div>
</div>
<?= $this->endSection() ?>

<?= $this->section('script') ?>
<script>
<!-- SCRIPT DATATABLES -->
$(function () {
	$('#myTable').DataTable();
});

$('.openViewItd').on('click',function(){
	const itdid = $(this).data('itdid');
	$('.modal-content').load('/invtrans/view/itd/'+itdid,function(){
		$('#modal').modal('show');
	});
});

$('.openViewAct').on('click',function(){
	const actid = $(this).data('actid');
	$('.modal-content').load('/invtrans/view/act/'+actid,function(){
		$('#modal').modal('show');
	});
});
</script>

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