review code pattern consistency

This commit is contained in:
Thanakorn S
2026-05-20 13:07:57 +07:00
parent 7396db6ffc
commit 91f8bb854f
20 changed files with 93 additions and 58 deletions
+14 -10
View File
@@ -8,7 +8,8 @@ $quotation_id = (int)($data['quotation_id'] ?? 0);
$convert_items = $data['convert_items'] ?? [];
if (!$quotation_id) {
exit(json_encode(['success' => 0, 'message' => 'Quotation ID required.']));
$answer['message'] = 'Quotation ID required.';
exit(json_encode($answer));
}
$qm = new QuotationManager($pdo2, $company_id);
@@ -16,16 +17,19 @@ $qm = new QuotationManager($pdo2, $company_id);
// Load quotation — must be Accepted
$q = $qm->getById($quotation_id);
if (!$q || (int)$q['status'] !== 2) {
exit(json_encode(['success' => 0, 'message' => 'Quotation not found or not in Accepted status.']));
$answer['message'] = 'Quotation not found or not in Accepted status.';
exit(json_encode($answer));
}
$qt_items = $q['items'];
if (empty($qt_items)) {
exit(json_encode(['success' => 0, 'message' => 'Quotation has no items.']));
$answer['message'] = 'Quotation has no items.';
exit(json_encode($answer));
}
if ((float)$q['total_remaining'] <= 0.000001) {
exit(json_encode(['success' => 0, 'message' => 'Quotation is already fully converted.']));
$answer['message'] = 'Quotation is already fully converted.';
exit(json_encode($answer));
}
// Index by item_id for validation
@@ -55,7 +59,8 @@ foreach ($convert_items as $ci) {
if ($qty <= 0) continue;
if (!isset($qt_by_id[$item_id])) {
exit(json_encode(['success' => 0, 'message' => "Item #{$item_id} not found in this quotation."]));
$answer['message'] = "Item #{$item_id} not found in this quotation.";
exit(json_encode($answer));
}
$qi = $qt_by_id[$item_id];
@@ -63,10 +68,8 @@ foreach ($convert_items as $ci) {
if ($qty - $remaining > 0.000001) {
$name = $qi['product_name'] ?: $qi['product_sku'];
exit(json_encode([
'success' => 0,
'message' => "Cannot convert {$qty} for \"{$name}\": only {$remaining} remaining.",
]));
$answer['message'] = "Cannot convert {$qty} for \"{$name}\": only {$remaining} remaining.";
exit(json_encode($answer));
}
$unit_price = (float)$qi['unit_price'];
@@ -89,7 +92,8 @@ foreach ($convert_items as $ci) {
}
if (empty($ord_items)) {
exit(json_encode(['success' => 0, 'message' => 'No valid items to convert.']));
$answer['message'] = 'No valid items to convert.';
exit(json_encode($answer));
}
$order_data = [