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

<?= $this->section('content') ?>
<?php
$catalogid = '';
$unitgroupid = '';
$unitgroupcode = '';
$unit = '';
$quantity = '';
$baseunit = '';
if(isset($unitgroup[0])) { $data = $unitgroup[0]; }
if(isset($new_value)) { $data = $new_value; }
if(isset($data)) {
	if(isset($data['unitgroupid'])) { $unitgroupid = $data['unitgroupid']; }
	$catalogid = $data['catalogid'];
	$unitgroupcode = $data['unitgroupcode'];
	$unit = $data['unit'];
	$quantity = $data['quantity'];
	$baseunit = $data['baseunit'];
}
?>
<div class="form-body">
	<h3 class="card-title">Unit Group Editor</h3>
	<hr>
	<?php 
	if(isset($validation)) {
	?>
		<div class='alert alert-danger alert-dismissible'>
			<?= $validation->listErrors(); ?>
			<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"> <span aria-hidden="true"></span> </button>
		</div>
	<?php
	}
	?>
	<form method='post'>
		<input type='hidden' name='catalogid' value='<?=$unitgroupid;?>'/>
		<div class="form-group row">
			<label class="col-3 col-form-label">Product</label>
			<div class="col-9">
				<select class="form-control select2" name='catalogid' >
					<option value=''>-</option>
					<?php
					foreach ($productcatalog as $data) {
						$qcatalogid = $data['catalogid'];
						$qproductname = $data['productname'];
						$qcatalognumber = $data['catalognumber'];
						if ($qcatalogid == $catalogid) { echo "<option value='$qcatalogid' selected>$qcatalognumber - $qproductname</option>"; }
						else { echo "<option value='$qcatalogid'>$qcatalognumber - $qproductname</option>"; }
					}
					?>
				</select>
			</div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">Unit Group Code</label>
			<div class="col-9"><input class="form-control" type="text" name='unitgroupcode' value="<?=$unitgroupcode;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">Unit</label>
			<div class="col-9"><input class="form-control" type="text" name='unit' value="<?=$unit;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">Quantity</label>
			<div class="col-9"><input class="form-control" type="text" name='quantity' value="<?=$quantity;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">Base Unit</label>
			<div class="col-9"><input class="form-control" type="text" name='baseunit' value="<?=$baseunit;?>"></div>
		</div>
		<button type="button" class="btn btn-dark float-start" onclick="window.close()">Cancel</button>
		<button type="submit" class="btn btn-success text-white float-end"> <i class="fa fa-check"></i> Submit</button>
	</form>
</div>
<?= $this->endSection() ?>