계약 관리 화면에서 더욱 간결하고 직관적으로 테넌트와 계약을 관리

This commit is contained in:
2026-01-04 17:39:59 +09:00
parent c029440396
commit bed13dc633
2 changed files with 149 additions and 38 deletions

View File

@@ -478,6 +478,7 @@ try {
$stmt->execute([$manager_val, $tenant_id]);
echo json_encode(['success' => true, 'message' => $manager_val ? '담당 매니저가 지정되었습니다.' : '담당 매니저 지정이 취소되었습니다.']);
} elseif ($action === 'update_product') {
$product_id = $data['id'] ?? null;
if (!$product_id) throw new Exception("ID가 누락되었습니다.");
@@ -492,6 +493,10 @@ try {
if ($p['operator_confirmed'] == 1) throw new Exception("이미 승인된 계약은 수정할 수 없습니다.");
$product_name = $data['product_name'] ?? '';
$contract_amount = $data['contract_amount'] ?? 0;
$commission_rate = $data['commission_rate'] ?? 0;
$contract_date = $data['contract_date'] ?? date('Y-m-d');
$sub_models = isset($data['sub_models']) ? json_encode($data['sub_models']) : null;
$commission_amount = ($contract_amount * $commission_rate) / 100;
@@ -499,6 +504,37 @@ try {
$stmt->execute([$product_name, $contract_amount, $commission_rate, $commission_amount, $contract_date, $sub_models, $product_id]);
echo json_encode(['success' => true, 'message' => '계약 정보가 수정되었습니다.']);
} elseif ($action === 'update_tenant') {
$tenant_id = $data['id'] ?? null;
if (!checkTenantPermission($pdo, $tenant_id, $currentUser)) throw new Exception("권한이 없습니다.");
$tenant_name = $data['tenant_name'] ?? '';
$representative = $data['representative'] ?? '';
$business_no = $data['business_no'] ?? '';
$contact_phone = $data['contact_phone'] ?? '';
$email = $data['email'] ?? '';
$address = $data['address'] ?? '';
$sales_manager_id = $data['sales_manager_id'] ?? null;
if (!$tenant_name) throw new Exception("업체명은 필수입니다.");
$stmt = $pdo->prepare("UPDATE sales_tenants SET tenant_name = ?, representative = ?, business_no = ?, contact_phone = ?, email = ?, address = ?, sales_manager_id = ? WHERE id = ?");
$stmt->execute([$tenant_name, $representative, $business_no, $contact_phone, $email, $address, $sales_manager_id, $tenant_id]);
echo json_encode(['success' => true, 'message' => '테넌트 정보가 수정되었습니다.']);
} elseif ($action === 'delete_tenant') {
$tenant_id = $data['id'] ?? null;
if (!checkTenantPermission($pdo, $tenant_id, $currentUser)) throw new Exception("권한이 없습니다.");
// 관련 데이터 삭제 (계약, 시나리오, 상담기록)
$pdo->prepare("DELETE FROM sales_tenant_products WHERE tenant_id = ?")->execute([$tenant_id]);
$pdo->prepare("DELETE FROM sales_tenant_scenarios WHERE tenant_id = ?")->execute([$tenant_id]);
$pdo->prepare("DELETE FROM sales_tenant_consultations WHERE tenant_id = ?")->execute([$tenant_id]);
$pdo->prepare("DELETE FROM sales_tenants WHERE id = ?")->execute([$tenant_id]);
echo json_encode(['success' => true, 'message' => '테넌트가 삭제되었습니다.']);
}
break;
}