review code pattern consistency
This commit is contained in:
@@ -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 = [
|
||||
|
||||
@@ -7,11 +7,13 @@ $action = $data['action'] ?? '';
|
||||
$data['items'] = json_decode($data['items'] ?? '[]', true) ?: [];
|
||||
|
||||
if (!in_array($action, ['create', 'update'], true)) {
|
||||
exit(json_encode(['success' => 0, 'message' => 'Unknown action']));
|
||||
$answer['message'] = 'Unknown action';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if (empty($data['items'])) {
|
||||
exit(json_encode(['success' => 0, 'message' => 'At least one item is required']));
|
||||
$answer['message'] = 'At least one item is required';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -51,4 +53,3 @@ try {
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
?>
|
||||
|
||||
@@ -10,7 +10,8 @@ if ($id) {
|
||||
$row = $qm->getById($id);
|
||||
if (!$row) {
|
||||
http_response_code(404);
|
||||
exit(json_encode(['success' => 0, 'message' => 'Not found.']));
|
||||
$answer['message'] = 'Not found.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
$answer['output'] = $row;
|
||||
} else {
|
||||
|
||||
@@ -7,7 +7,8 @@ $id = (int)($data['id'] ?? 0);
|
||||
$action = $data['action_type'] ?? '';
|
||||
|
||||
if (!$id || !$action) {
|
||||
exit(json_encode(['success' => 0, 'message' => 'ID and action are required.']));
|
||||
$answer['message'] = 'ID and action are required.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
$qm = new QuotationManager($pdo2, $company_id);
|
||||
|
||||
Reference in New Issue
Block a user