fix enrollment, invoice, payment and financila aid
This commit is contained in:
@@ -145,6 +145,10 @@ class InventoryController extends BaseController
|
||||
}
|
||||
if (($item['type'] ?? '') === 'book') {
|
||||
$this->saveBookClassAssignments($id);
|
||||
$gradeError = $this->syncBookCategoryGradeRange($data['category_id'] ?? null);
|
||||
if ($gradeError !== null) {
|
||||
return redirect()->back()->withInput()->with('error', $gradeError);
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->to(site_url('inventory/' . $item['type']))->with('success', 'Item updated.');
|
||||
@@ -161,6 +165,10 @@ class InventoryController extends BaseController
|
||||
$initialQty = (int) ($itemData['quantity'] ?? 0);
|
||||
if (($itemData['type'] ?? '') === 'book') {
|
||||
$this->saveBookClassAssignments((int) $itemId);
|
||||
$gradeError = $this->syncBookCategoryGradeRange($itemData['category_id'] ?? null);
|
||||
if ($gradeError !== null) {
|
||||
return redirect()->back()->withInput()->with('error', $gradeError);
|
||||
}
|
||||
if ($initialQty !== 0) {
|
||||
$this->recordMovement($itemId, $initialQty, 'initial', 'Initial stock');
|
||||
} else {
|
||||
@@ -229,20 +237,12 @@ class InventoryController extends BaseController
|
||||
|
||||
// Only books have grade range
|
||||
if ($data['type'] === 'book') {
|
||||
$gmin = $this->request->getPost('grade_min');
|
||||
$gmax = $this->request->getPost('grade_max');
|
||||
|
||||
$gmin = ($gmin === '' || $gmin === null) ? null : max(0, (int)$gmin);
|
||||
$gmax = ($gmax === '' || $gmax === null) ? null : max(0, (int)$gmax);
|
||||
|
||||
if ($gmin !== null && $gmax !== null && $gmin > $gmax) {
|
||||
return redirect()->back()->withInput()->with('error', 'Grade Min cannot be greater than Grade Max.');
|
||||
$normalized = $this->normalizeGradeRangePost();
|
||||
if (is_string($normalized)) {
|
||||
return redirect()->back()->withInput()->with('error', $normalized);
|
||||
}
|
||||
if ($gmin !== null && $gmin > 13) $gmin = 13;
|
||||
if ($gmax !== null && $gmax > 13) $gmax = 13;
|
||||
|
||||
$data['grade_min'] = $gmin;
|
||||
$data['grade_max'] = $gmax;
|
||||
$data['grade_min'] = $normalized['grade_min'];
|
||||
$data['grade_max'] = $normalized['grade_max'];
|
||||
} else {
|
||||
$data['grade_min'] = null;
|
||||
$data['grade_max'] = null;
|
||||
@@ -264,7 +264,14 @@ class InventoryController extends BaseController
|
||||
'A category with this Type & Name already exists. Please choose a different name or edit the existing one.'
|
||||
);
|
||||
}
|
||||
$ok = $this->catModel->update((int)$id, $data);
|
||||
$current = $this->db->table('inventory_categories')->where('id', (int) $id)->get()->getRowArray();
|
||||
if (!$current) {
|
||||
return redirect()->back()->withInput()->with('error', 'Category not found.');
|
||||
}
|
||||
if (!empty($current['school_year'])) {
|
||||
$data['school_year'] = $current['school_year'];
|
||||
}
|
||||
$ok = $this->writeCategoryRow((int) $id, $data);
|
||||
} else {
|
||||
// Creating: block if already exists
|
||||
if ($existing) {
|
||||
@@ -295,7 +302,9 @@ class InventoryController extends BaseController
|
||||
}
|
||||
|
||||
if (!$ok) {
|
||||
return redirect()->back()->withInput()->with('error', 'Failed to save category.');
|
||||
$errors = $this->catModel->errors();
|
||||
$message = $errors !== [] ? implode(', ', $errors) : 'Failed to save category.';
|
||||
return redirect()->back()->withInput()->with('error', $message);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', 'Category saved.');
|
||||
@@ -531,6 +540,85 @@ class InventoryController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist grade_min/grade_max onto the selected book category.
|
||||
* Returns an error message string on failure, or null on success/no-op.
|
||||
*/
|
||||
private function syncBookCategoryGradeRange($categoryId): ?string
|
||||
{
|
||||
$categoryId = (int) ($categoryId ?? 0);
|
||||
if ($categoryId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Disabled inputs are omitted from POST; do not wipe an existing category range.
|
||||
$post = $this->request->getPost();
|
||||
if (! is_array($post)
|
||||
|| (! array_key_exists('grade_min', $post) && ! array_key_exists('grade_max', $post))
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$normalized = $this->normalizeGradeRangePost();
|
||||
if (is_string($normalized)) {
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
$category = $this->db->table('inventory_categories')->where('id', $categoryId)->get()->getRowArray();
|
||||
if (!$category || ($category['type'] ?? '') !== 'book') {
|
||||
return 'Selected category was not found or is not a book category.';
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'grade_min' => $normalized['grade_min'],
|
||||
'grade_max' => $normalized['grade_max'],
|
||||
];
|
||||
if (!empty($category['school_year'])) {
|
||||
$payload['school_year'] = $category['school_year'];
|
||||
}
|
||||
|
||||
if (!$this->writeCategoryRow($categoryId, $payload)) {
|
||||
return 'Failed to update category grade range.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function writeCategoryRow(int $id, array $data): bool
|
||||
{
|
||||
$data['updated_at'] = date('Y-m-d H:i:s');
|
||||
|
||||
return (bool) $this->db->table('inventory_categories')->where('id', $id)->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{grade_min: ?int, grade_max: ?int}|string
|
||||
*/
|
||||
private function normalizeGradeRangePost()
|
||||
{
|
||||
$gmin = $this->request->getPost('grade_min');
|
||||
$gmax = $this->request->getPost('grade_max');
|
||||
|
||||
$gmin = ($gmin === '' || $gmin === null) ? null : max(0, (int) $gmin);
|
||||
$gmax = ($gmax === '' || $gmax === null) ? null : max(0, (int) $gmax);
|
||||
|
||||
if ($gmin !== null && $gmin > 13) {
|
||||
$gmin = 13;
|
||||
}
|
||||
if ($gmax !== null && $gmax > 13) {
|
||||
$gmax = 13;
|
||||
}
|
||||
|
||||
if ($gmin !== null && $gmax !== null && $gmin > $gmax) {
|
||||
return 'Grade Min cannot be greater than Grade Max.';
|
||||
}
|
||||
|
||||
return [
|
||||
'grade_min' => $gmin,
|
||||
'grade_max' => $gmax,
|
||||
];
|
||||
}
|
||||
|
||||
private function moneyValueToCents($value): int
|
||||
{
|
||||
$raw = trim((string) $value);
|
||||
|
||||
Reference in New Issue
Block a user