recreate project
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container my-4">
|
||||
<h3 class="mb-3">Adjust Stock — <?= esc($item['name']) ?></h3>
|
||||
<?= view('partials/flash_messages') ?>
|
||||
|
||||
<form method="post" action="<?= site_url('inventory/adjust/'.$item['id']) ?>">
|
||||
<?= csrf_field() ?>
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Mode</label>
|
||||
<select class="form-select" name="mode" required>
|
||||
<option value="in">Add to Stock</option>
|
||||
<option value="out">Deduct from Stock</option>
|
||||
<option value="adjust">Adjust (signed)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Quantity</label>
|
||||
<input type="number" min="1" class="form-control" name="quantity" required>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Reason</label>
|
||||
<input class="form-control" name="reason" placeholder="Purchase, Donation, Correction, etc.">
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label">Note (optional)</label>
|
||||
<textarea class="form-control" rows="3" name="note"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 d-flex gap-2">
|
||||
<button class="btn btn-primary">Save</button>
|
||||
<a class="btn btn-outline-secondary" href="<?= site_url('inventory/summary/'.$item['type']) ?>">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,174 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container my-4">
|
||||
<?php $isEdit = !empty($item); ?>
|
||||
<h3 class="mb-3"><?= $isEdit ? 'Edit' : 'Add' ?> Book</h3>
|
||||
|
||||
<?= view('partials/flash_messages') ?>
|
||||
<?php
|
||||
$isEdit = isset($isEdit) && $isEdit;
|
||||
$itemId = $item['id'] ?? null;
|
||||
$action = $isEdit ? site_url('inventory/update/'.$itemId) : site_url('inventory/store');
|
||||
|
||||
// Build a label function for categories with grade range
|
||||
$catLabel = function(array $c): string {
|
||||
$name = $c['name'] ?? '';
|
||||
$gmin = $c['grade_min'] ?? null;
|
||||
$gmax = $c['grade_max'] ?? null;
|
||||
if ($gmin !== null || $gmax !== null) {
|
||||
// Render compact: (Gmin–Gmax) supports one-sided ranges too
|
||||
if ($gmin !== null && $gmax !== null) $name .= " (G{$gmin}–G{$gmax})";
|
||||
elseif ($gmin !== null) $name .= " (G{$gmin}+)";
|
||||
elseif ($gmax !== null) $name .= " (≤G{$gmax})";
|
||||
}
|
||||
return $name;
|
||||
};
|
||||
|
||||
// ---- Classes preselection (supports array, CSV, or JSON) ----
|
||||
$selectedClasses = [];
|
||||
$rawClasses = $item['classes'] ?? $item['class_list'] ?? $item['class_ids'] ?? null;
|
||||
|
||||
if (is_array($rawClasses)) {
|
||||
$selectedClasses = array_map('intval', $rawClasses);
|
||||
} elseif (is_string($rawClasses) && $rawClasses !== '') {
|
||||
$decoded = json_decode($rawClasses, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
||||
$selectedClasses = array_map('intval', $decoded);
|
||||
} else {
|
||||
$parts = preg_split('/[,\s]+/', $rawClasses);
|
||||
$selectedClasses = array_map('intval', array_filter($parts, static fn($v) => $v !== ''));
|
||||
}
|
||||
}
|
||||
// Keep only values 1..13
|
||||
$selectedClasses = array_values(array_intersect(range(1,13), $selectedClasses));
|
||||
?>
|
||||
<form method="post" action="<?= $action ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="type" value="book">
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Title</label>
|
||||
<input class="form-control" name="name" required value="<?= esc($item['name'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Category</label>
|
||||
<select class="form-select" name="category_id" id="bookCategorySelect">
|
||||
<option value="">— None —</option>
|
||||
<?php foreach ($categories as $c): ?>
|
||||
<?php
|
||||
$cid = (int)($c['id'] ?? 0);
|
||||
$sel = isset($item['category_id']) && (int)$item['category_id'] === $cid ? 'selected' : '';
|
||||
$gmin = $c['grade_min'] ?? '';
|
||||
$gmax = $c['grade_max'] ?? '';
|
||||
?>
|
||||
<option value="<?= esc($cid) ?>"
|
||||
data-gmin="<?= esc($gmin) ?>"
|
||||
data-gmax="<?= esc($gmax) ?>"
|
||||
<?= $sel ?>>
|
||||
<?= esc($catLabel($c)) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<div class="form-text">
|
||||
Grade Range:
|
||||
<span id="catGradeRange">—</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== Classes (1–13) ===== -->
|
||||
<div class="col-12">
|
||||
<label class="form-label d-flex align-items-center gap-2">
|
||||
Classes (1–13)
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" id="btnSelectAllClasses">Select All</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" id="btnClearClasses">Clear</button>
|
||||
</label>
|
||||
<div class="row g-2" id="classesGrid">
|
||||
<?php for ($i = 1; $i <= 13; $i++): ?>
|
||||
<?php $checked = in_array($i, $selectedClasses, true) ? 'checked' : ''; ?>
|
||||
<div class="col-6 col-sm-4 col-md-3 col-lg-2">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input class-checkbox" type="checkbox"
|
||||
id="class<?= $i ?>" name="classes[]" value="<?= $i ?>" <?= $checked ?>>
|
||||
<label class="form-check-label" for="class<?= $i ?>">Class <?= $i ?></label>
|
||||
</div>
|
||||
</div>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<div class="form-text">Choose all class numbers that use this book.</div>
|
||||
</div>
|
||||
<!-- ========================== -->
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Author</label>
|
||||
<input class="form-control" name="author" value="<?= esc($item['author'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">ISBN</label>
|
||||
<input class="form-control" name="isbn" value="<?= esc($item['isbn'] ?? '') ?>">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Edition</label>
|
||||
<input class="form-control" name="edition" value="<?= esc($item['edition'] ?? '') ?>">
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Quantity</label>
|
||||
<input type="number" min="0" class="form-control" name="quantity" value="<?= esc($item['quantity'] ?? 0) ?>">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Unit</label>
|
||||
<input class="form-control" name="unit" placeholder="pcs, set" value="<?= esc($item['unit'] ?? '') ?>">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">SKU</label>
|
||||
<input class="form-control" name="sku" value="<?= esc($item['sku'] ?? '') ?>">
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label">Description / Notes</label>
|
||||
<textarea class="form-control" rows="3" name="description"><?= esc($item['description'] ?? '') ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 d-flex gap-2">
|
||||
<button class="btn btn-primary"><?= $isEdit ? 'Update' : 'Save' ?></button>
|
||||
<a class="btn btn-outline-secondary" href="<?= site_url('inventory/book') ?>">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
// Category grade range helper
|
||||
const sel = document.getElementById('bookCategorySelect');
|
||||
const out = document.getElementById('catGradeRange');
|
||||
function label(opt) {
|
||||
if (!opt) { out.textContent = '—'; return; }
|
||||
const gmin = opt.getAttribute('data-gmin');
|
||||
const gmax = opt.getAttribute('data-gmax');
|
||||
if ((gmin && gmin !== '') && (gmax && gmax !== '')) out.textContent = `G${gmin}–G${gmax}`;
|
||||
else if (gmin && gmin !== '') out.textContent = `G${gmin}+`;
|
||||
else if (gmax && gmax !== '') out.textContent = `≤G${gmax}`;
|
||||
else out.textContent = '—';
|
||||
}
|
||||
sel?.addEventListener('change', () => label(sel.options[sel.selectedIndex]));
|
||||
if (sel) label(sel.options[sel.selectedIndex]); // init on load
|
||||
|
||||
// Classes select all / clear
|
||||
const selectAllBtn = document.getElementById('btnSelectAllClasses');
|
||||
const clearBtn = document.getElementById('btnClearClasses');
|
||||
const checkboxes = document.querySelectorAll('.class-checkbox');
|
||||
|
||||
selectAllBtn?.addEventListener('click', () => {
|
||||
checkboxes.forEach(cb => cb.checked = true);
|
||||
});
|
||||
clearBtn?.addEventListener('click', () => {
|
||||
checkboxes.forEach(cb => cb.checked = false);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,139 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container-fluid px-0 mt-3">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3 px-3">
|
||||
<h3 class="mb-0">Books</h3>
|
||||
<div class="btn-group">
|
||||
<a class="btn btn-primary" href="<?= site_url('inventory/create/book') ?>">Add Book</a>
|
||||
<button class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#addCategoryModal">Add Category</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= view('partials/flash_messages') ?>
|
||||
<div class="px-3 mb-2"><?= $this->include('partials/academic_filter') ?></div>
|
||||
|
||||
<?php
|
||||
// Helper to render a compact grade label from a category row
|
||||
$gradeLabel = function (?array $cat): string {
|
||||
if (!$cat) return '—';
|
||||
$gmin = $cat['grade_min'] ?? null;
|
||||
$gmax = $cat['grade_max'] ?? null;
|
||||
if ($gmin === null && $gmax === null) return '—';
|
||||
if ($gmin !== null && $gmax !== null) return 'G' . (int)$gmin . '–G' . (int)$gmax;
|
||||
if ($gmin !== null) return 'G' . (int)$gmin . '+';
|
||||
return '≤G' . (int)$gmax;
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span>Books</span>
|
||||
<select class="form-select form-select-sm" id="categoryFilter" style="min-width:260px">
|
||||
<option value="">All Categories</option>
|
||||
<?php foreach ($categories as $c): ?>
|
||||
<?php
|
||||
$label = $c['name'] ?? '';
|
||||
$gl = $gradeLabel($c);
|
||||
if ($gl !== '—') $label .= ' (' . $gl . ')';
|
||||
?>
|
||||
<option value="<?= esc($c['id']) ?>"><?= esc($label) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="card-body table-responsive">
|
||||
<table class="table table-striped align-middle" id="inventoryTable" data-no-mgmt-sticky="1">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th><th>ISBN</th><th>Edition</th>
|
||||
<th>Category</th>
|
||||
<th>Grade Range</th> <!-- NEW -->
|
||||
<th>Qty</th><th>Unit</th>
|
||||
<th>Updated By</th><th>Updated Date</th>
|
||||
<th>SKU</th><th style="width:110px">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($items as $i): ?>
|
||||
<?php
|
||||
$cat = array_values(array_filter($categories, fn($c)=>($c['id']??null)==($i['category_id']??null)))[0] ?? null;
|
||||
$catName = $cat['name'] ?? '—';
|
||||
$catGrades = $gradeLabel($cat);
|
||||
?>
|
||||
<tr data-category="<?= esc($i['category_id'] ?? '') ?>">
|
||||
<td><?= esc($i['name']) ?></td>
|
||||
<td><?= esc($i['isbn']) ?></td>
|
||||
<td><?= esc($i['edition']) ?></td>
|
||||
<td><?= esc($catName) ?></td>
|
||||
<td><?= esc($catGrades) ?></td> <!-- NEW -->
|
||||
<td><?= esc($i['quantity']) ?></td>
|
||||
<td><?= esc($i['unit']) ?></td>
|
||||
<td><?= esc($userNames[(int)($i['updated_by'] ?? 0)] ?? '—') ?></td>
|
||||
<td><?= esc($i['updated_at'] ? local_datetime($i['updated_at'], 'm-d-Y H:i') : '—') ?></td>
|
||||
<td><?= esc($i['sku']) ?></td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-outline-primary" href="<?= site_url('inventory/edit/'.$i['id']) ?>">Edit</a>
|
||||
<form action="<?= site_url('inventory/delete/'.$i['id']) ?>" method="post" class="d-inline">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="return confirm('Delete this item?')">Del</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Category Modal -->
|
||||
<div class="modal fade" id="addCategoryModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<form class="modal-content" method="post" action="<?= site_url('inventory/category/save') ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="type" value="book">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Add Category (Books)</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name</label>
|
||||
<input type="text" name="name" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<!-- NEW: Grade range -->
|
||||
<div class="row g-2 mb-3">
|
||||
<div class="col-6">
|
||||
<label class="form-label">Grade Min</label>
|
||||
<input type="number" name="grade_min" class="form-control" min="0" max="13" placeholder="e.g., 1">
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label class="form-label">Grade Max</label>
|
||||
<input type="number" name="grade_max" class="form-control" min="0" max="13" placeholder="e.g., 3">
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<small class="text-muted">Optional. Only used for Book categories.</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-0">
|
||||
<label class="form-label">Description (optional)</label>
|
||||
<textarea name="description" class="form-control" rows="2"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer"><button class="btn btn-primary">Save Category</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('categoryFilter')?.addEventListener('change', function() {
|
||||
const val = this.value;
|
||||
document.querySelectorAll('#inventoryTable tbody tr').forEach(tr => {
|
||||
tr.style.display = (!val || tr.getAttribute('data-category') === val) ? '' : 'none';
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container my-4">
|
||||
<h3 class="mb-3">Audit — <?= esc($item['name']) ?></h3>
|
||||
<?= view('partials/flash_messages') ?>
|
||||
|
||||
<div class="alert alert-info">
|
||||
<strong>Current On Hand:</strong> <?= (int)$item['quantity'] ?> pcs
|
||||
</div>
|
||||
|
||||
<form method="post" action="<?= site_url('inventory/classroom/audit/'.$item['id']) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<div class="row g-3">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Needs Repair</label>
|
||||
<input type="number" min="0" class="form-control" name="needs_repair_qty"
|
||||
value="<?= (int)$item['needs_repair_qty'] ?>">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Total Loss (Need Replace)</label>
|
||||
<input type="number" min="0" class="form-control" name="need_replace_qty"
|
||||
value="<?= (int)$item['need_replace_qty'] ?>">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Cannot Find</label>
|
||||
<input type="number" min="0" class="form-control" name="cannot_find_qty"
|
||||
value="<?= (int)$item['cannot_find_qty'] ?>">
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Derived Good (read-only)</label>
|
||||
<input type="number" class="form-control" value="<?= max(0, (int)$item['quantity'] - (int)$item['needs_repair_qty']) ?>" readonly>
|
||||
<div class="form-text">Good = On Hand − Needs Repair</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 d-flex gap-2">
|
||||
<button class="btn btn-primary">Save Audit</button>
|
||||
<a class="btn btn-outline-secondary" href="<?= site_url('inventory/classroom') ?>">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,189 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<?php
|
||||
// Safe defaults so "create" doesn't blow up
|
||||
$item = isset($item) && is_array($item) ? $item : [];
|
||||
$isEdit = !empty($item['id']);
|
||||
$itemId = $isEdit ? (int)$item['id'] : null;
|
||||
$action = $isEdit ? site_url('inventory/update/'.$itemId) : site_url('inventory/store');
|
||||
|
||||
// Buckets / on-hand (robust defaults)
|
||||
$onHand = (int)($item['quantity'] ?? 0);
|
||||
$needsRepairQty = (int)($item['needs_repair_qty'] ?? 0);
|
||||
$lossQty = (int)($item['need_replace_qty'] ?? 0);
|
||||
$missingQty = (int)($item['cannot_find_qty'] ?? 0);
|
||||
$goodCalc = max(0, $onHand - $needsRepairQty);
|
||||
|
||||
// Lists
|
||||
$categories = isset($categories) && is_array($categories) ? $categories : [];
|
||||
$conditionOptions = isset($conditionOptions) && is_array($conditionOptions) ? $conditionOptions : [
|
||||
'good' => 'Good condition',
|
||||
'needs_repair' => 'Needs repair',
|
||||
'need_replace' => 'Need replace',
|
||||
'cannot_find' => 'Cannot find',
|
||||
];
|
||||
?>
|
||||
|
||||
<div class="container my-4">
|
||||
<!-- Top bar: Items / Adjust / Audit -->
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h3 class="mb-0"><?= $isEdit ? 'Edit' : 'Add' ?> Classroom Item</h3>
|
||||
<div class="btn-group">
|
||||
<a class="btn btn-sm btn-outline-secondary" href="<?= site_url('inventory/classroom') ?>">Items</a>
|
||||
<?php if ($isEdit): ?>
|
||||
<a class="btn btn-sm btn-outline-secondary" href="<?= site_url('inventory/adjust/'.$itemId) ?>">Adjust Stock</a>
|
||||
<a class="btn btn-sm btn-outline-secondary" href="<?= site_url('inventory/classroom/audit/'.$itemId) ?>">Audit</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= view('partials/flash_messages') ?>
|
||||
|
||||
<form method="post" action="<?= $action ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="type" value="classroom">
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Name</label>
|
||||
<input class="form-control" name="name" required value="<?= esc($item['name'] ?? '') ?>">
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Category</label>
|
||||
<select class="form-select" name="category_id">
|
||||
<option value="">— None —</option>
|
||||
<?php foreach ($categories as $c): ?>
|
||||
<option value="<?= esc($c['id'] ?? '') ?>"
|
||||
<?= isset($item['category_id']) && (int)$item['category_id'] === (int)($c['id'] ?? 0) ? 'selected' : '' ?>>
|
||||
<?= esc($c['name'] ?? '') ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Condition (overall)</label>
|
||||
<select class="form-select" name="condition">
|
||||
<option value="">— Select —</option>
|
||||
<?php foreach ($conditionOptions as $val => $label): ?>
|
||||
<option value="<?= esc($val) ?>"
|
||||
<?= (isset($item['condition']) && $item['condition'] === $val) ? 'selected' : '' ?>>
|
||||
<?= esc($label) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<div class="form-text">Quick overall tag. Detailed states shown below.</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Quantity</label>
|
||||
<input type="number" min="0" class="form-control" name="quantity"
|
||||
value="<?= esc($onHand) ?>" <?= $isEdit ? 'readonly' : '' ?>>
|
||||
<?php if ($isEdit): ?>
|
||||
<div class="form-text">
|
||||
Change on-hand via <a href="<?= site_url('inventory/adjust/'.$itemId) ?>">Adjust Stock</a>.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Unit</label>
|
||||
<input class="form-control" name="unit" placeholder="pcs, set, box" value="<?= esc($item['unit'] ?? '') ?>">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">SKU</label>
|
||||
<input class="form-control" name="sku" value="<?= esc($item['sku'] ?? '') ?>">
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<label class="form-label">Description / Notes</label>
|
||||
<textarea class="form-control" rows="3" name="description"><?= esc($item['description'] ?? '') ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Item State table -->
|
||||
<div class="card mt-4">
|
||||
<div class="card-header">Item State</div>
|
||||
<div class="card-body table-responsive">
|
||||
<table class="table table-sm align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>State</th>
|
||||
<th class="text-end">Count</th>
|
||||
<th>Included in On-Hand?</th>
|
||||
<th>Notes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>On Hand (now)</strong></td>
|
||||
<td class="text-end"><strong><?= $onHand ?></strong></td>
|
||||
<td>—</td>
|
||||
<td>Sum of movements; authoritative stock.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Good</td>
|
||||
<td class="text-end"><?= $goodCalc ?></td>
|
||||
<td>Yes</td>
|
||||
<td>Available to use (derived = On Hand − Needs Repair).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Needs Repair</td>
|
||||
<td class="text-end"><?= $needsRepairQty ?></td>
|
||||
<td>Yes</td>
|
||||
<td>Unavailable until fixed.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Total Loss</td>
|
||||
<td class="text-end"><?= $lossQty ?></td>
|
||||
<td>No</td>
|
||||
<td>Deducted via audit (Out).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Cannot Find</td>
|
||||
<td class="text-end"><?= $missingQty ?></td>
|
||||
<td>No</td>
|
||||
<td>Deducted via audit (Out).</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr class="table-light">
|
||||
<th>Available to Use</th>
|
||||
<th class="text-end"><?= $goodCalc ?></th>
|
||||
<th colspan="2"></th>
|
||||
</tr>
|
||||
<tr class="table-light">
|
||||
<th>Unavailable but On-Hand (Repair)</th>
|
||||
<th class="text-end"><?= $needsRepairQty ?></th>
|
||||
<th colspan="2"></th>
|
||||
</tr>
|
||||
<tr class="table-light">
|
||||
<th>Removed (Loss + Missing)</th>
|
||||
<th class="text-end"><?= $lossQty + $missingQty ?></th>
|
||||
<th colspan="2"></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div class="small text-muted">
|
||||
Update states via <strong>Audit</strong>; stock movements are created automatically.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 d-flex gap-2">
|
||||
<button class="btn btn-primary"><?= $isEdit ? 'Update' : 'Save' ?></button>
|
||||
<a class="btn btn-outline-secondary" href="<?= site_url('inventory/classroom') ?>">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php if ($isEdit && !empty($item['updated_at'])): ?>
|
||||
<div class="text-muted mt-3">
|
||||
<small>Updated Date: <?= esc(local_datetime($item['updated_at'], 'm-d-Y H:i')) ?></small>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,111 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container-fluid px-0 mt-3">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3 px-3">
|
||||
<h3 class="mb-0">Classroom Equipment</h3>
|
||||
<div class="btn-group">
|
||||
<a class="btn btn-primary" href="<?= site_url('inventory/create/classroom') ?>">Add Item</a>
|
||||
<button class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#addCategoryModal">Add Category</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= view('partials/flash_messages') ?>
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span>Items</span>
|
||||
<select class="form-select form-select-sm" id="categoryFilter" style="min-width:220px">
|
||||
<option value="">All Categories</option>
|
||||
<?php foreach ($categories as $c): ?>
|
||||
<option value="<?= esc($c['id']) ?>"><?= esc($c['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="card-body table-responsive">
|
||||
<table class="table table-striped align-middle" id="inventoryTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Condition</th>
|
||||
<th>Category</th>
|
||||
<th>Qty</th>
|
||||
<th>Unit</th>
|
||||
<th>Updated By</th>
|
||||
<th>Updated Date</th>
|
||||
<th>SKU</th>
|
||||
<th style="width:110px">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($items as $i): ?>
|
||||
<tr data-category="<?= esc($i['category_id'] ?? '') ?>">
|
||||
<td><?= esc($i['name']) ?></td>
|
||||
<td>
|
||||
<span class="badge bg-<?php
|
||||
$map=['good'=>'success','needs_repair'=>'warning','need_replace'=>'danger','cannot_find'=>'secondary'];
|
||||
echo $map[$i['condition'] ?? ''] ?? 'light';
|
||||
?>">
|
||||
<?= esc(ucwords(str_replace('_',' ', $i['condition'] ?? ''))) ?>
|
||||
</span>
|
||||
</td>
|
||||
<td><?php
|
||||
$cat = array_values(array_filter($categories, fn($c)=> ($c['id']??null) == ($i['category_id']??null)))[0] ?? null;
|
||||
echo esc($cat['name'] ?? '—');
|
||||
?></td>
|
||||
<td><?= esc($i['quantity']) ?></td>
|
||||
<td><?= esc($i['unit']) ?></td>
|
||||
<td><?= esc($userNames[(int)($i['updated_by'] ?? 0)] ?? '—') ?></td>
|
||||
|
||||
<td><?= esc($i['updated_at'] ? local_datetime($i['updated_at'], 'm-d-Y H:i') : '—') ?></td>
|
||||
<td><?= esc($i['sku']) ?></td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-outline-primary" href="<?= site_url('inventory/edit/'.$i['id']) ?>">Edit</a>
|
||||
<form action="<?= site_url('inventory/delete/'.$i['id']) ?>" method="post" class="d-inline">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="return confirm('Delete this item?')">Del</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Category Modal -->
|
||||
<div class="modal fade" id="addCategoryModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<form class="modal-content" method="post" action="<?= site_url('inventory/category/save') ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="type" value="classroom">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Add Category (Classroom)</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Name</label>
|
||||
<input type="text" name="name" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-0">
|
||||
<label class="form-label">Description (optional)</label>
|
||||
<textarea name="description" class="form-control" rows="2"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer"><button class="btn btn-primary">Save Category</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('categoryFilter')?.addEventListener('change', function() {
|
||||
const val = this.value;
|
||||
document.querySelectorAll('#inventoryTable tbody tr').forEach(tr => {
|
||||
tr.style.display = (!val || tr.getAttribute('data-category') === val) ? '' : 'none';
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container my-4">
|
||||
<?php $isEdit = !empty($item); ?>
|
||||
<h3 class="mb-3"><?= $isEdit ? 'Edit' : 'Add' ?> Kitchen Supply</h3>
|
||||
|
||||
<?= view('partials/flash_messages') ?>
|
||||
<?php
|
||||
$isEdit = isset($isEdit) && $isEdit; // passed from controller on edit
|
||||
$itemId = $item['id'] ?? null;
|
||||
$action = $isEdit
|
||||
? site_url('inventory/update/'.$itemId)
|
||||
: site_url('inventory/store');
|
||||
?>
|
||||
<form method="post" action="<?= $isEdit ? site_url('inventory/update/'.$item['id']) : site_url('inventory/store') ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="type" value="kitchen">
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6"><label class="form-label">Name</label><input class="form-control" name="name" required value="<?= esc($item['name'] ?? '') ?>"></div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Category</label>
|
||||
<select class="form-select" name="category_id">
|
||||
<option value="">— None —</option>
|
||||
<?php foreach ($categories as $c): ?>
|
||||
<option value="<?= esc($c['id']) ?>" <?= isset($item['category_id']) && (int)$item['category_id']===(int)$c['id'] ? 'selected' : '' ?>><?= esc($c['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2"><label class="form-label">Quantity</label><input type="number" min="0" class="form-control" name="quantity" value="<?= esc($item['quantity'] ?? 0) ?>"></div>
|
||||
<div class="col-md-2"><label class="form-label">Unit</label><input class="form-control" name="unit" value="<?= esc($item['unit'] ?? '') ?>"></div>
|
||||
<div class="col-md-4"><label class="form-label">SKU</label><input class="form-control" name="sku" value="<?= esc($item['sku'] ?? '') ?>"></div>
|
||||
<div class="col-12"><label class="form-label">Description / Notes</label><textarea class="form-control" rows="3" name="description"><?= esc($item['description'] ?? '') ?></textarea></div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 d-flex gap-2">
|
||||
<button class="btn btn-primary"><?= $isEdit ? 'Update' : 'Save' ?></button>
|
||||
<a class="btn btn-outline-secondary" href="<?= site_url('inventory/kitchen') ?>">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container-fluid px-0 mt-3">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3 px-3">
|
||||
<h3 class="mb-0">Kitchen Supplies</h3>
|
||||
<div class="btn-group">
|
||||
<a class="btn btn-primary" href="<?= site_url('inventory/create/kitchen') ?>">Add Item</a>
|
||||
<button class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#addCategoryModal">Add Category</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= view('partials/flash_messages') ?>
|
||||
<div class="px-3 mb-2"><?= $this->include('partials/academic_filter') ?></div>
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span>Items</span>
|
||||
<select class="form-select form-select-sm" id="categoryFilter" style="min-width:220px">
|
||||
<option value="">All Categories</option>
|
||||
<?php foreach ($categories as $c): ?>
|
||||
<option value="<?= esc($c['id']) ?>"><?= esc($c['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="card-body table-responsive">
|
||||
<table class="table table-striped align-middle" id="inventoryTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th><th>Category</th><th>Qty</th><th>Unit</th>
|
||||
<th>Updated By</th><th>Updated Date</th>
|
||||
<th>SKU</th><th style="width:110px">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($items as $i): ?>
|
||||
<tr data-category="<?= esc($i['category_id'] ?? '') ?>">
|
||||
<td><?= esc($i['name']) ?></td>
|
||||
<td><?php $cat=array_values(array_filter($categories, fn($c)=>($c['id']??null)==($i['category_id']??null)))[0] ?? null; echo esc($cat['name'] ?? '—'); ?></td>
|
||||
<td><?= esc($i['quantity']) ?></td>
|
||||
<td><?= esc($i['unit']) ?></td>
|
||||
<td><?= esc($userNames[(int)($i['updated_by'] ?? 0)] ?? '—') ?></td>
|
||||
|
||||
<td><?= esc($i['updated_at'] ? local_datetime($i['updated_at'], 'm-d-Y H:i') : '—') ?></td>
|
||||
<td><?= esc($i['sku']) ?></td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-outline-primary" href="<?= site_url('inventory/edit/'.$i['id']) ?>">Edit</a>
|
||||
<form action="<?= site_url('inventory/delete/'.$i['id']) ?>" method="post" class="d-inline">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="return confirm('Delete this item?')">Del</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Category Modal -->
|
||||
<div class="modal fade" id="addCategoryModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<form class="modal-content" method="post" action="<?= site_url('inventory/category/save') ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="type" value="kitchen">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Add Category (Kitchen)</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3"><label class="form-label">Name</label><input type="text" name="name" class="form-control" required></div>
|
||||
<div class="mb-0"><label class="form-label">Description (optional)</label><textarea name="description" class="form-control" rows="2"></textarea></div>
|
||||
</div>
|
||||
<div class="modal-footer"><button class="btn btn-primary">Save Category</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('categoryFilter')?.addEventListener('change', function() {
|
||||
const val = this.value;
|
||||
document.querySelectorAll('#inventoryTable tbody tr').forEach(tr => {
|
||||
tr.style.display = (!val || tr.getAttribute('data-category') === val) ? '' : 'none';
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<div class="container my-4">
|
||||
<h3>Edit Inventory Movement</h3>
|
||||
|
||||
<form action="<?= site_url('inventory/movements/update/'.$movement['id']) ?>" method="post">
|
||||
<?= csrf_field() ?>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Item</label>
|
||||
<input type="text" class="form-control" value="<?= esc($movement['item_name'] ?? $movement['item_id']) ?>" disabled>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Quantity Change</label>
|
||||
<input type="number" name="qty_change" class="form-control" value="<?= esc($movement['qty_change']) ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Movement Type</label>
|
||||
<select name="movement_type" class="form-select" required>
|
||||
<?php foreach (['initial','in','out','adjust','distribution'] as $type): ?>
|
||||
<option value="<?= $type ?>" <?= $movement['movement_type']===$type ? 'selected' : '' ?>>
|
||||
<?= ucfirst($type) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Reason</label>
|
||||
<input type="text" name="reason" class="form-control" maxlength="120" value="<?= esc($movement['reason']) ?>">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Note</label>
|
||||
<textarea name="note" class="form-control"><?= esc($movement['note']) ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Semester</label>
|
||||
<select name="semester" class="form-select">
|
||||
<option value="">-- None --</option>
|
||||
<option value="Spring" <?= $movement['semester']==='Spring'?'selected':'' ?>>Spring</option>
|
||||
<option value="Fall" <?= $movement['semester']==='Fall'?'selected':'' ?>>Fall</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">School Year</label>
|
||||
<input type="text" name="school_year" class="form-control" value="<?= esc($movement['school_year']) ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||
<a href="<?= site_url('inventory/movements') ?>" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,213 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container my-4">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h3 class="mb-0"><?= esc($title ?? ($isCreate ? 'Create Inventory Movement' : 'Edit Inventory Movement')) ?></h3>
|
||||
<a href="<?= site_url('inventory/movements') ?>" class="btn btn-outline-secondary">Back to List</a>
|
||||
</div>
|
||||
|
||||
<?php if (session()->getFlashdata('status')): ?>
|
||||
<div class="alert alert-<?= session('status') === 'success' ? 'success' : 'danger' ?>">
|
||||
<?= esc(session('message')) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($validation) && $validation->getErrors()): ?>
|
||||
<div class="alert alert-danger">
|
||||
<ul class="mb-0">
|
||||
<?php foreach ($validation->getErrors() as $e): ?>
|
||||
<li><?= esc($e) ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="<?= esc($action) ?>" method="post" class="card shadow-sm">
|
||||
<?= csrf_field() ?>
|
||||
<div class="card-body">
|
||||
<!-- =============== Item =============== -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Item <span class="text-danger">*</span></label>
|
||||
|
||||
<?php if (!empty($isCreate)): ?>
|
||||
<select name="item_id" class="form-select" required>
|
||||
<option value="">-- Select Item --</option>
|
||||
<?php
|
||||
$oldItem = old('item_id', $movement['item_id'] ?? '');
|
||||
foreach ($items as $it):
|
||||
$selected = (string)$oldItem === (string)$it['id'] ? 'selected' : '';
|
||||
?>
|
||||
<option value="<?= esc($it['id']) ?>" <?= $selected ?>>
|
||||
<?= esc($it['name']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php else: ?>
|
||||
<!-- Lock item on edit (history integrity). Keep hidden field to submit original value -->
|
||||
<input type="hidden" name="item_id" value="<?= esc($movement['item_id']) ?>">
|
||||
<input type="text" class="form-control" value="<?= esc($movement['item_name'] ?? $movement['item_id']) ?>" disabled>
|
||||
<div class="form-text">Item cannot be changed after creation.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- =============== Qty Change & Type =============== -->
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Quantity Change <span class="text-danger">*</span></label>
|
||||
<input
|
||||
type="number"
|
||||
name="qty_change"
|
||||
required
|
||||
class="form-control"
|
||||
value="<?= esc(old('qty_change', $movement['qty_change'] ?? 0)) ?>"
|
||||
>
|
||||
<div class="form-text">
|
||||
Use negative values for outbound movements if type is <code>out</code> (or set type accordingly).
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Movement Type <span class="text-danger">*</span></label>
|
||||
<select name="movement_type" class="form-select" required>
|
||||
<?php
|
||||
$oldType = old('movement_type', $movement['movement_type'] ?? 'adjust');
|
||||
foreach ($movementTypes as $t):
|
||||
$sel = $oldType === $t ? 'selected' : '';
|
||||
?>
|
||||
<option value="<?= esc($t) ?>" <?= $sel ?>><?= ucfirst($t) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- =============== Reason & Note =============== -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Reason</label>
|
||||
<input
|
||||
type="text"
|
||||
name="reason"
|
||||
maxlength="120"
|
||||
class="form-control"
|
||||
value="<?= esc(old('reason', $movement['reason'] ?? '')) ?>"
|
||||
placeholder="Short reason (max 120 chars)"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Note</label>
|
||||
<textarea
|
||||
name="note"
|
||||
class="form-control"
|
||||
rows="3"
|
||||
placeholder="Any additional details about this movement..."
|
||||
><?= esc(old('note', $movement['note'] ?? '')) ?></textarea>
|
||||
</div>
|
||||
|
||||
<!-- =============== Semester & School Year =============== -->
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Semester</label>
|
||||
<select name="semester" class="form-select">
|
||||
<option value="">-- None --</option>
|
||||
<?php
|
||||
$oldSem = old('semester', $movement['semester'] ?? '');
|
||||
foreach ($semesters as $sem):
|
||||
$sel = $oldSem === $sem ? 'selected' : '';
|
||||
?>
|
||||
<option value="<?= esc($sem) ?>" <?= $sel ?>><?= esc($sem) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">School Year</label>
|
||||
<input
|
||||
type="text"
|
||||
name="school_year"
|
||||
class="form-control"
|
||||
value="<?= esc(old('school_year', $movement['school_year'] ?? '')) ?>"
|
||||
placeholder="e.g., 2025-2026"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- =============== Optional Relations =============== -->
|
||||
<div class="row">
|
||||
<!-- Teachers / TAs from TeacherModel::getTeachersAndTAs() -->
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Teacher (optional)</label>
|
||||
<select name="teacher_id" class="form-select">
|
||||
<option value="">-- None --</option>
|
||||
<?php
|
||||
$oldTeacher = (string) old('teacher_id', (string) ($movement['teacher_id'] ?? ''));
|
||||
foreach ($teachers as $t):
|
||||
$sel = $oldTeacher === (string)$t['id'] ? 'selected' : '';
|
||||
?>
|
||||
<option value="<?= esc($t['id']) ?>" <?= $sel ?>>
|
||||
<?= esc($t['fullname']) ?> (<?= esc(ucfirst($t['role'])) ?>)
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Students (expects id + fullname; adjust if your array key is different) -->
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Student (optional)</label>
|
||||
<select name="student_id" class="form-select">
|
||||
<option value="">-- None --</option>
|
||||
<?php
|
||||
$oldStudent = (string) old('student_id', (string) ($movement['student_id'] ?? ''));
|
||||
foreach ($students as $s):
|
||||
$sel = $oldStudent !== '' && $oldStudent === (string)$s['id'] ? 'selected' : '';
|
||||
?>
|
||||
<option value="<?= esc($s['id']) ?>" <?= $sel ?>><?= esc($s['fullname']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Class Section (optional)</label>
|
||||
<select name="class_section_id" class="form-select">
|
||||
<option value="">-- None --</option>
|
||||
<?php
|
||||
$oldSection = (string) old('class_section_id', (string) ($movement['class_section_id'] ?? ''));
|
||||
foreach ($classSections as $cs):
|
||||
$value = (string)$cs['class_section_id']; // using CODE per your schema
|
||||
$sel = $oldSection !== '' && $oldSection === $value ? 'selected' : '';
|
||||
?>
|
||||
<option value="<?= esc($value) ?>" <?= $sel ?>><?= esc($cs['class_section_name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<div class="form-text">Uses the <strong>class_section_id</strong> code (not PK).</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!$isCreate): ?>
|
||||
<hr>
|
||||
<div class="row g-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Performed By</label>
|
||||
<input type="text" class="form-control"
|
||||
value="<?= esc($movement['performed_by_name'] ?? $movement['performed_by'] ?? '—') ?>" disabled>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Created At</label>
|
||||
<input type="text" class="form-control" value="<?= esc(!empty($movement['created_at']) ? local_datetime($movement['created_at'], 'm-d-Y H:i') : '—') ?>" disabled>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">Last Updated</label>
|
||||
<input type="text" class="form-control" value="<?= esc(!empty($movement['updated_at']) ? local_datetime($movement['updated_at'], 'm-d-Y H:i') : '—') ?>" disabled>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="card-footer d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary"><?= $isCreate ? 'Create Movement' : 'Save Changes' ?></button>
|
||||
<a href="<?= site_url('inventory/movements') ?>" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,275 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
<div class="container-fluid">
|
||||
<div class="d-flex justify-content-between align-items-center my-3">
|
||||
<h2 class="mb-0">Inventory Movements</h2>
|
||||
<div class="d-flex gap-2">
|
||||
<!-- Top bulk delete submits the master form by id -->
|
||||
<button id="bulkDeleteBtnTop" type="submit" form="bulkDeleteForm" class="btn btn-danger" disabled>
|
||||
<i class="bi bi-trash"></i> Delete Selected
|
||||
</button>
|
||||
<a href="<?= site_url('inventory/movements/create') ?>" class="btn btn-success">
|
||||
<i class="bi bi-plus-circle"></i> New Movement
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-2"><?= $this->include('partials/academic_filter') ?></div>
|
||||
|
||||
<?php if (session()->getFlashdata('status')): ?>
|
||||
<div class="alert alert-<?= session('status') === 'success' ? 'success' : 'danger' ?>">
|
||||
<?= esc(session('message')) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="table-responsive">
|
||||
<!-- Single master form holds the selected ids[] for bulk delete -->
|
||||
<form id="bulkDeleteForm" action="<?= site_url('inventory/movements/bulk-delete') ?>" method="post">
|
||||
<?= csrf_field() ?>
|
||||
|
||||
<table id="movementsTable" class="table table-striped table-hover align-middle" data-no-mgmt-sticky="1">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th style="width:36px">
|
||||
<input type="checkbox" id="checkAll" title="Select all on this page">
|
||||
</th>
|
||||
<th>ID</th>
|
||||
<th>Item</th>
|
||||
<th>Qty Change</th>
|
||||
<th>Movement Type</th>
|
||||
<th>Reason</th>
|
||||
<th>Semester</th>
|
||||
<th>School Year</th>
|
||||
<th>Teacher</th>
|
||||
<th>Student</th>
|
||||
<th>Class Section</th>
|
||||
<th>Performed By</th>
|
||||
<th>Created At</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (!empty($movements)): ?>
|
||||
<?php foreach ($movements as $m): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" class="row-check" name="ids[]" value="<?= esc($m['id']) ?>">
|
||||
</td>
|
||||
<td><?= esc($m['id']) ?></td>
|
||||
<td><?= esc($m['item_name'] ?? $m['item_id']) ?></td>
|
||||
<td><?= esc($m['qty_change']) ?></td>
|
||||
<td><span class="badge bg-info"><?= esc($m['movement_type']) ?></span></td>
|
||||
<td><?= esc($m['reason']) ?></td>
|
||||
<td><?= esc($m['semester']) ?></td>
|
||||
<td><?= esc($m['school_year']) ?></td>
|
||||
<td><?= esc($m['teacher_name'] ?? $m['teacher_id']) ?></td>
|
||||
<td><?= esc($m['student_name'] ?? $m['student_id']) ?></td>
|
||||
<td><?= esc($m['class_section_name'] ?? $m['class_section_id']) ?></td>
|
||||
<td><?= esc($m['performed_by_name'] ?? $m['performed_by']) ?></td>
|
||||
<td><?= esc(!empty($m['created_at']) ? local_datetime($m['created_at'], 'm-d-Y H:i') : '') ?></td>
|
||||
<td class="text-nowrap">
|
||||
<a href="<?= site_url('inventory/movements/edit/'.$m['id']) ?>" class="btn btn-sm btn-primary">
|
||||
<i class="bi bi-pencil"></i> Edit
|
||||
</a>
|
||||
|
||||
<!-- Single delete button (no nested form). JS will create & submit a POST form with CSRF -->
|
||||
<button type="button"
|
||||
class="btn btn-sm btn-danger btn-delete-one"
|
||||
data-action="<?= site_url('inventory/movements/delete/'.$m['id']) ?>">
|
||||
<i class="bi bi-trash"></i> Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="mt-2">
|
||||
<button id="bulkDeleteBtnBottom" type="submit" class="btn btn-danger" disabled>
|
||||
<i class="bi bi-trash"></i> Delete Selected
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(function(){
|
||||
const table = $('#movementsTable').DataTable({
|
||||
pageLength: 100,
|
||||
order: [[1, 'desc']], // 0=checkbox, 1=ID
|
||||
columnDefs: [
|
||||
{ orderable: false, targets: [0, 13] } // checkbox + actions
|
||||
]
|
||||
});
|
||||
|
||||
const $checkAll = $('#checkAll');
|
||||
const $bulkTop = $('#bulkDeleteBtnTop');
|
||||
const $bulkBot = $('#bulkDeleteBtnBottom');
|
||||
|
||||
function selectionCount() { return $('#movementsTable tbody .row-check:checked').length; }
|
||||
function syncBulkButtons() {
|
||||
const n = selectionCount();
|
||||
$bulkTop.prop('disabled', n === 0);
|
||||
$bulkBot.prop('disabled', n === 0);
|
||||
}
|
||||
|
||||
// Individual row checks
|
||||
$(document).on('change', '.row-check', syncBulkButtons);
|
||||
|
||||
// Header "select all" (only visible rows on current page)
|
||||
$checkAll.on('change', function() {
|
||||
const checked = this.checked;
|
||||
$('#movementsTable tbody input.row-check').prop('checked', checked);
|
||||
syncBulkButtons();
|
||||
});
|
||||
|
||||
// Keep header checkbox in sync after redraws
|
||||
table.on('draw', function(){
|
||||
const $visible = $('#movementsTable tbody input.row-check');
|
||||
const allChecked = $visible.length && $visible.filter(':checked').length === $visible.length;
|
||||
$checkAll.prop('checked', allChecked && $visible.length > 0);
|
||||
syncBulkButtons();
|
||||
});
|
||||
|
||||
// Confirm for bulk delete (both top and bottom submit the same #bulkDeleteForm)
|
||||
$('#bulkDeleteForm').on('submit', function(e){
|
||||
const n = selectionCount();
|
||||
if (n === 0) { e.preventDefault(); return false; }
|
||||
if (!confirm(`Delete ${n} selected movement(s)?`)) { e.preventDefault(); return false; }
|
||||
});
|
||||
|
||||
// ---- Single delete (avoid nested forms) ----
|
||||
const csrfName = '<?= esc(csrf_token()) ?>';
|
||||
const CSRF_COOKIE_NAME = <?= json_encode(config('Security')->csrfCookieName ?? (config('Security')->cookieName ?? 'csrf_cookie_name')) ?>;
|
||||
function getCookie(name){
|
||||
return document.cookie.split(';').map(v=>v.trim()).find(v=>v.startsWith(name+'='))?.split('=')[1] || '';
|
||||
}
|
||||
|
||||
$(document).on('click', '.btn-delete-one', async function(e){
|
||||
e.preventDefault();
|
||||
const url = $(this).data('action');
|
||||
if (!url) return;
|
||||
|
||||
if (!confirm('Delete this movement?')) return;
|
||||
|
||||
const token = decodeURIComponent(getCookie(CSRF_COOKIE_NAME) || '<?= esc(csrf_hash()) ?>');
|
||||
// Try fast path: POST via fetch, then reload regardless of redirect
|
||||
try {
|
||||
const body = new URLSearchParams();
|
||||
body.append(csrfName, token);
|
||||
const resp = await fetch(url, {
|
||||
method: 'POST',
|
||||
body,
|
||||
credentials: 'same-origin',
|
||||
headers: { 'Accept': 'text/html,application/json', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest' }
|
||||
});
|
||||
// If the server responded (200/302/etc), just reload to reflect changes
|
||||
if (resp.ok || resp.status === 302 || resp.status === 303 || resp.status === 301) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
} catch (_) {
|
||||
// fall through to form submit
|
||||
}
|
||||
|
||||
// Fallback: create a one-off form and submit (POST with latest CSRF)
|
||||
const form = document.createElement('form');
|
||||
form.method = 'post';
|
||||
form.action = url;
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = csrfName;
|
||||
input.value = token;
|
||||
form.appendChild(input);
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
});
|
||||
|
||||
// Keep bulk delete form's CSRF fresh just before submit
|
||||
$('#bulkDeleteForm').on('submit', function(){
|
||||
try {
|
||||
const fresh = decodeURIComponent(getCookie(CSRF_COOKIE_NAME) || '');
|
||||
if (fresh) {
|
||||
const $hidden = $(this).find('input[name="' + csrfName + '"]');
|
||||
if ($hidden.length) $hidden.val(fresh);
|
||||
}
|
||||
} catch(_) {}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// jQuery-free fallback: enables bulk delete buttons and single delete
|
||||
(function(){
|
||||
if (window.jQuery) return; // jQuery path already binds everything
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
function qsa(sel, root){ return Array.prototype.slice.call((root||document).querySelectorAll(sel)); }
|
||||
function selCount(){ return qsa('#movementsTable tbody .row-check:checked').length; }
|
||||
function sync(){
|
||||
var n = selCount();
|
||||
var top = document.getElementById('bulkDeleteBtnTop');
|
||||
var bot = document.getElementById('bulkDeleteBtnBottom');
|
||||
if (top) top.disabled = (n === 0);
|
||||
if (bot) bot.disabled = (n === 0);
|
||||
}
|
||||
|
||||
// Individual row checks
|
||||
document.addEventListener('change', function(e){
|
||||
if (e.target && e.target.classList && e.target.classList.contains('row-check')) sync();
|
||||
});
|
||||
// Header select all
|
||||
var checkAll = document.getElementById('checkAll');
|
||||
if (checkAll) {
|
||||
checkAll.addEventListener('change', function(){
|
||||
var on = !!this.checked;
|
||||
qsa('#movementsTable tbody input.row-check').forEach(function(el){ el.checked = on; });
|
||||
sync();
|
||||
});
|
||||
}
|
||||
|
||||
// Confirm bulk delete
|
||||
var bulkForm = document.getElementById('bulkDeleteForm');
|
||||
if (bulkForm) {
|
||||
bulkForm.addEventListener('submit', function(e){
|
||||
var n = selCount();
|
||||
if (n === 0) { e.preventDefault(); return; }
|
||||
if (!confirm('Delete ' + n + ' selected movement(s)?')) { e.preventDefault(); }
|
||||
});
|
||||
}
|
||||
|
||||
// Single delete via fetch fallback
|
||||
(function(){
|
||||
var TOKEN_NAME = '<?= esc(csrf_token()) ?>';
|
||||
var COOKIE_NAME = <?= json_encode(config('Security')->csrfCookieName ?? (config('Security')->cookieName ?? 'csrf_cookie_name')) ?>;
|
||||
function getCookie(n){
|
||||
try { return document.cookie.split(';').map(function(v){return v.trim();}).find(function(v){return v.indexOf(n+'=')===0;})?.split('=')[1] || ''; } catch(_) { return ''; }
|
||||
}
|
||||
document.addEventListener('click', function(e){
|
||||
var btn = e.target && e.target.closest ? e.target.closest('.btn-delete-one') : null;
|
||||
if (!btn) return;
|
||||
e.preventDefault();
|
||||
var url = btn.getAttribute('data-action');
|
||||
if (!url) return;
|
||||
if (!confirm('Delete this movement?')) return;
|
||||
var token = decodeURIComponent(getCookie(COOKIE_NAME) || '<?= esc(csrf_hash()) ?>');
|
||||
var body = new URLSearchParams();
|
||||
body.append(TOKEN_NAME, token);
|
||||
fetch(url, { method:'POST', body, credentials:'same-origin', headers:{ 'Accept':'text/html,application/json', 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With':'XMLHttpRequest' } })
|
||||
.then(function(){ location.reload(); })
|
||||
.catch(function(){
|
||||
var form = document.createElement('form');
|
||||
form.method = 'post'; form.action = url;
|
||||
var inp = document.createElement('input');
|
||||
inp.type = 'hidden'; inp.name = TOKEN_NAME; inp.value = token;
|
||||
form.appendChild(inp); document.body.appendChild(form); form.submit();
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
// Initial state
|
||||
sync();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container my-4">
|
||||
<?php $isEdit = !empty($item); ?>
|
||||
<h3 class="mb-3"><?= $isEdit ? 'Edit' : 'Add' ?> Office Supply</h3>
|
||||
|
||||
<?= view('partials/flash_messages') ?>
|
||||
<?php
|
||||
$isEdit = isset($isEdit) && $isEdit; // passed from controller on edit
|
||||
$itemId = $item['id'] ?? null;
|
||||
$action = $isEdit
|
||||
? site_url('inventory/update/'.$itemId)
|
||||
: site_url('inventory/store');
|
||||
?>
|
||||
<form method="post" action="<?= $isEdit ? site_url('inventory/update/'.$item['id']) : site_url('inventory/store') ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="type" value="office">
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6"><label class="form-label">Name</label><input class="form-control" name="name" required value="<?= esc($item['name'] ?? '') ?>"></div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Category</label>
|
||||
<select class="form-select" name="category_id">
|
||||
<option value="">— None —</option>
|
||||
<?php foreach ($categories as $c): ?>
|
||||
<option value="<?= esc($c['id']) ?>" <?= isset($item['category_id']) && (int)$item['category_id']===(int)$c['id'] ? 'selected' : '' ?>><?= esc($c['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2"><label class="form-label">Quantity</label><input type="number" min="0" class="form-control" name="quantity" value="<?= esc($item['quantity'] ?? 0) ?>"></div>
|
||||
<div class="col-md-2"><label class="form-label">Unit</label><input class="form-control" name="unit" value="<?= esc($item['unit'] ?? '') ?>"></div>
|
||||
<div class="col-md-4"><label class="form-label">SKU</label><input class="form-control" name="sku" value="<?= esc($item['sku'] ?? '') ?>"></div>
|
||||
<div class="col-12"><label class="form-label">Description / Notes</label><textarea class="form-control" rows="3" name="description"><?= esc($item['description'] ?? '') ?></textarea></div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 d-flex gap-2">
|
||||
<button class="btn btn-primary"><?= $isEdit ? 'Update' : 'Save' ?></button>
|
||||
<a class="btn btn-outline-secondary" href="<?= site_url('inventory/office') ?>">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container-fluid px-0 mt-3">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3 px-3">
|
||||
<h3 class="mb-0">Office Supplies</h3>
|
||||
<div class="btn-group">
|
||||
<a class="btn btn-primary" href="<?= site_url('inventory/create/office') ?>">Add Item</a>
|
||||
<button class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#addCategoryModal">Add Category</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= view('partials/flash_messages') ?>
|
||||
<div class="px-3 mb-2"><?= $this->include('partials/academic_filter') ?></div>
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span>Items</span>
|
||||
<select class="form-select form-select-sm" id="categoryFilter" style="min-width:220px">
|
||||
<option value="">All Categories</option>
|
||||
<?php foreach ($categories as $c): ?>
|
||||
<option value="<?= esc($c['id']) ?>"><?= esc($c['name']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="card-body table-responsive">
|
||||
<table class="table table-striped align-middle" id="inventoryTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th><th>Category</th><th>Qty</th><th>Unit</th>
|
||||
<th>Updated By</th><th>Updated Date</th>
|
||||
<th>SKU</th><th style="width:110px">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($items as $i): ?>
|
||||
<tr data-category="<?= esc($i['category_id'] ?? '') ?>">
|
||||
<td><?= esc($i['name']) ?></td>
|
||||
<td><?php $cat=array_values(array_filter($categories, fn($c)=>($c['id']??null)==($i['category_id']??null)))[0] ?? null; echo esc($cat['name'] ?? '—'); ?></td>
|
||||
<td><?= esc($i['quantity']) ?></td>
|
||||
<td><?= esc($i['unit']) ?></td>
|
||||
<td><?= esc($userNames[(int)($i['updated_by'] ?? 0)] ?? '—') ?></td>
|
||||
|
||||
<td><?= esc($i['updated_at'] ? local_datetime($i['updated_at'], 'm-d-Y H:i') : '—') ?></td>
|
||||
<td><?= esc($i['sku']) ?></td>
|
||||
<td>
|
||||
<a class="btn btn-sm btn-outline-primary" href="<?= site_url('inventory/edit/'.$i['id']) ?>">Edit</a>
|
||||
<form action="<?= site_url('inventory/delete/'.$i['id']) ?>" method="post" class="d-inline">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn btn-sm btn-outline-danger" onclick="return confirm('Delete this item?')">Del</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Category Modal -->
|
||||
<div class="modal fade" id="addCategoryModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<form class="modal-content" method="post" action="<?= site_url('inventory/category/save') ?>">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="type" value="office">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Add Category (Office)</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3"><label class="form-label">Name</label><input type="text" name="name" class="form-control" required></div>
|
||||
<div class="mb-0"><label class="form-label">Description (optional)</label><textarea name="description" class="form-control" rows="2"></textarea></div>
|
||||
</div>
|
||||
<div class="modal-footer"><button class="btn btn-primary">Save Category</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('categoryFilter')?.addEventListener('change', function() {
|
||||
const val = this.value;
|
||||
document.querySelectorAll('#inventoryTable tbody tr').forEach(tr => {
|
||||
tr.style.display = (!val || tr.getAttribute('data-category') === val) ? '' : 'none';
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,127 @@
|
||||
<?= $this->extend('layout/management_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<?php
|
||||
// Safe fallbacks
|
||||
$selectedYear = $selectedYear ?? ($currentYear ?? '');
|
||||
$currentYear = $currentYear ?? '';
|
||||
$schoolYears = $schoolYears ?? [];
|
||||
$rows = $rows ?? [];
|
||||
$totals = array_merge([
|
||||
'opening'=>0,'received'=>0,'distributed'=>0,'other_out'=>0,'adjust_net'=>0,'ending'=>0,'onhand'=>0,'variance'=>0
|
||||
], $totals ?? []);
|
||||
?>
|
||||
|
||||
<div class="container-fluid px-0 mt-3">
|
||||
<div class="px-3 mb-2"><?= $this->include('partials/academic_filter') ?></div>
|
||||
<div class="d-flex justify-content-between align-items-center mb-3 px-3">
|
||||
<h3 class="mb-0">
|
||||
Inventory Summary — <?= esc(strtolower((string)$selectedYear)==='all' ? 'All Years' : $selectedYear) ?>
|
||||
</h3>
|
||||
<div><a class="btn btn-outline-secondary" href="<?= site_url('inventory/book') ?>">Back to Items</a></div>
|
||||
</div>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex gap-2 flex-wrap align-items-center justify-content-between">
|
||||
<div>Filter</div>
|
||||
<div class="d-flex gap-2">
|
||||
<select id="yearFilter" class="form-select form-select-sm" style="min-width:220px">
|
||||
<option value="__current__" <?= (strtolower((string)$selectedYear)!=='all' && $selectedYear===$currentYear)?'selected':'' ?>>
|
||||
Current (<?= esc($currentYear) ?>)
|
||||
</option>
|
||||
<option value="all" <?= strtolower((string)$selectedYear)==='all'?'selected':'' ?>>All Years</option>
|
||||
<?php foreach ($schoolYears as $y): ?>
|
||||
<?php if ($y !== $currentYear): // avoid duplicate of "Current" ?>
|
||||
<option value="<?= esc($y) ?>" <?= ($selectedYear===$y)?'selected':'' ?>><?= esc($y) ?></option>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body table-responsive">
|
||||
<table class="table table-striped align-middle" id="summaryTable" data-no-mgmt-sticky="1">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Type</th>
|
||||
<th>Category</th>
|
||||
<th>Name</th>
|
||||
<th class="text-end">Opening</th>
|
||||
<th class="text-end">Received</th>
|
||||
<th class="text-end">Distributed</th>
|
||||
<th class="text-end">Other Out</th>
|
||||
<th class="text-end">Adjust ±</th>
|
||||
<th class="text-end">Ending</th>
|
||||
<th class="text-end">On Hand (Now)</th>
|
||||
<th class="text-end">Variance</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($rows)): ?>
|
||||
<tr>
|
||||
<td colspan="11" class="text-center text-muted py-4">
|
||||
No data to display for <?= esc(strtolower((string)$selectedYear)==='all' ? 'All Years' : $selectedYear) ?>.
|
||||
</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($rows as $r): ?>
|
||||
<?php
|
||||
$opening = (int)($r['opening'] ?? 0);
|
||||
$received = (int)($r['received'] ?? 0);
|
||||
$distributed = (int)($r['distributed'] ?? 0);
|
||||
$otherOut = (int)($r['other_out'] ?? 0);
|
||||
$adjustNet = (int)($r['adjust_net'] ?? 0);
|
||||
$ending = (int)($r['ending'] ?? 0);
|
||||
$onhand = (int)($r['onhand'] ?? 0);
|
||||
$variance = (int)($r['variance'] ?? 0);
|
||||
?>
|
||||
<tr>
|
||||
<td><?= esc($r['type'] ?? '') ?></td>
|
||||
<td><?= esc($r['category'] ?? '') ?></td>
|
||||
<td><?= esc($r['name'] ?? '') ?></td>
|
||||
<td class="text-end"><?= number_format($opening) ?></td>
|
||||
<td class="text-end"><?= number_format($received) ?></td>
|
||||
<td class="text-end"><?= number_format($distributed) ?></td>
|
||||
<td class="text-end"><?= number_format($otherOut) ?></td>
|
||||
<td class="text-end"><?= number_format($adjustNet) ?></td>
|
||||
<td class="text-end fw-semibold"><?= number_format($ending) ?></td>
|
||||
<td class="text-end"><?= number_format($onhand) ?></td>
|
||||
<td class="text-end">
|
||||
<?php if ($variance === 0): ?>
|
||||
<span class="text-success"><?= number_format($variance) ?></span>
|
||||
<?php else: ?>
|
||||
<span class="text-danger fw-semibold"><?= number_format($variance) ?></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr class="table-light">
|
||||
<th colspan="3" class="text-end">Totals</th>
|
||||
<th class="text-end"><?= number_format((int)$totals['opening']) ?></th>
|
||||
<th class="text-end"><?= number_format((int)$totals['received']) ?></th>
|
||||
<th class="text-end"><?= number_format((int)$totals['distributed']) ?></th>
|
||||
<th class="text-end"><?= number_format((int)$totals['other_out']) ?></th>
|
||||
<th class="text-end"><?= number_format((int)$totals['adjust_net']) ?></th>
|
||||
<th class="text-end"><?= number_format((int)$totals['ending']) ?></th>
|
||||
<th class="text-end"><?= number_format((int)$totals['onhand']) ?></th>
|
||||
<th class="text-end"><?= number_format((int)$totals['variance']) ?></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('yearFilter')?.addEventListener('change', function() {
|
||||
const v = this.value, url = new URL(window.location.href);
|
||||
if (v === '__current__') url.searchParams.delete('school_year');
|
||||
else url.searchParams.set('school_year', v);
|
||||
window.location.href = url.toString();
|
||||
});
|
||||
</script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
@@ -0,0 +1,165 @@
|
||||
<?= $this->extend('layout/main_layout') ?>
|
||||
<?= $this->section('content') ?>
|
||||
|
||||
<div class="container my-4">
|
||||
<h4 class="text-dark mb-3" style="font-family: Arial, sans-serif;">Distribute Books to Students</h4>
|
||||
<?= view('partials/flash_messages') ?>
|
||||
|
||||
<!-- Filter bar (GET) — no class section shown -->
|
||||
<form id="filterForm" class="row g-3 mb-3" method="get" action="<?= site_url('inventory/books/distribute') ?>">
|
||||
<!-- Keep class section hidden; controller sets $class_section_id -->
|
||||
<input type="hidden" name="class_section_id" value="<?= esc($class_section_id) ?>">
|
||||
|
||||
<div class="col-md-5">
|
||||
<label class="form-label">Book</label>
|
||||
<select class="form-select" name="item_id" id="bookSelect" required>
|
||||
<option value="">— Select a book —</option>
|
||||
<?php foreach (($booksGrouped ?? []) as $group): ?>
|
||||
<optgroup label="<?= esc($group['label']) ?>">
|
||||
<?php foreach ($group['items'] as $b): ?>
|
||||
<option value="<?= esc($b['id']) ?>" <?= ((int)$b['id'] === (int)$item_id) ? 'selected' : '' ?>>
|
||||
<?= esc($b['display']) ?> (On Hand: <?= (int)$b['quantity'] ?>)
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</optgroup>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2 d-flex align-items-end">
|
||||
<button class="btn btn-secondary w-100">Load</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php if ($item_id && !empty($students)): ?>
|
||||
<div class="alert alert-info py-2">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<strong>School Year:</strong> <?= esc($schoolYear) ?>,
|
||||
<strong>Semester:</strong> <?= esc($semester) ?>
|
||||
</div>
|
||||
<div><strong>On Hand:</strong> <?= (int)$onHand ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Submission form (POST) -->
|
||||
<form method="post" action="<?= site_url('inventory/books/distribute') ?>">
|
||||
<?= csrf_field() ?>
|
||||
<!-- Keep class section hidden -->
|
||||
<input type="hidden" name="class_section_id" value="<?= esc($class_section_id) ?>">
|
||||
<input type="hidden" name="item_id" value="<?= esc($item_id) ?>">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span>Students</span>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-sm btn-info" id="checkAllBtn">Check All</button>
|
||||
<button type="button" class="btn btn-sm btn-secondary" id="uncheckAllBtn">Uncheck All</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body table-responsive">
|
||||
<table class="table table-bordered table-striped align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width:48px; text-align:center;">#</th>
|
||||
<th style="width:56px; text-align:center;">Give</th>
|
||||
<th>School ID</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
<th style="text-align:center;">Age</th>
|
||||
<th style="text-align:center;">Semester</th>
|
||||
<th style="text-align:center;">School Year</th>
|
||||
<th style="text-align:center;">History</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $order = 1;
|
||||
foreach ($students as $student):
|
||||
$sid = $student['student_id'] ?? ($student['id'] ?? ($student['user_id'] ?? null));
|
||||
if (!$sid) continue;
|
||||
$given = (int)($already[$sid] ?? 0) > 0;
|
||||
?>
|
||||
<tr>
|
||||
<td style="text-align:center;"><?= $order++ ?></td>
|
||||
<td style="text-align:center;">
|
||||
<input type="checkbox"
|
||||
class="form-check-input student-box"
|
||||
name="student_ids[]"
|
||||
value="<?= esc($sid) ?>"
|
||||
<?= $given ? 'checked' : '' ?>>
|
||||
</td>
|
||||
<td><?= esc($student['school_id'] ?? '-') ?></td>
|
||||
<td><?= esc($student['firstname'] ?? '') ?></td>
|
||||
<td><?= esc($student['lastname'] ?? '') ?></td>
|
||||
<td style="text-align:center;"><?= esc($student['age'] ?? '-') ?></td>
|
||||
<td style="text-align:center;"><?= esc($student['semester'] ?? $semester) ?></td>
|
||||
<td style="text-align:center;"><?= esc($student['school_year'] ?? $schoolYear) ?></td>
|
||||
<td style="text-align:center;">
|
||||
<?php if ($given): ?>
|
||||
<span class="badge bg-success">Given</span>
|
||||
<?php else: ?>
|
||||
<span class="text-muted">—</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="card-footer">
|
||||
<div class="mb-2">
|
||||
<label class="form-label">Note (optional)</label>
|
||||
<textarea class="form-control" rows="2" name="note" placeholder="e.g., Distributed in class today"></textarea>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-success">Deduct & Save</button>
|
||||
<button type="button" class="btn btn-secondary" id="clearSelectionBtn">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<?php elseif ($item_id): ?>
|
||||
<div class="alert alert-warning">No students found for this class.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
<?= $this->section('scripts') ?>
|
||||
<script>
|
||||
// Auto-submit filter when book changes
|
||||
document.getElementById('bookSelect')?.addEventListener('change', () => {
|
||||
document.getElementById('filterForm').submit();
|
||||
});
|
||||
|
||||
document.getElementById('checkAllBtn')?.addEventListener('click', () => {
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = true);
|
||||
});
|
||||
document.getElementById('uncheckAllBtn')?.addEventListener('click', () => {
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = false);
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// Auto-submit filter when book changes
|
||||
document.getElementById('bookSelect')?.addEventListener('change', () => {
|
||||
document.getElementById('filterForm').submit();
|
||||
});
|
||||
|
||||
document.getElementById('checkAllBtn')?.addEventListener('click', () => {
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = true);
|
||||
});
|
||||
|
||||
document.getElementById('uncheckAllBtn')?.addEventListener('click', () => {
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = false);
|
||||
});
|
||||
|
||||
// Cancel button clears all checkboxes
|
||||
document.getElementById('clearSelectionBtn')?.addEventListener('click', () => {
|
||||
document.querySelectorAll('.student-box').forEach(cb => cb.checked = false);
|
||||
});
|
||||
</script>
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
Reference in New Issue
Block a user