diff --git a/public_html/assets/api/install.php b/public_html/assets/api/install.php index 062c853..671d064 100644 --- a/public_html/assets/api/install.php +++ b/public_html/assets/api/install.php @@ -346,6 +346,24 @@ trait InstallAPI { } } + // assigned check + $rs = qry(" + SELECT di_uid + FROM tbl_daily_install + WHERE di_wait_uid = '{$iw_uid}' + LIMIT 1 + "); + $di = mysqli_fetch_assoc($rs); + + // assigned sync + if ($di && $di['di_uid']) { + $this->sync_daily_install_containers( + $iw_uid, + $di['di_uid'], + $requestAction + ); + } + qry("COMMIT"); } catch (Exception $e) { @@ -362,6 +380,92 @@ trait InstallAPI { echo $this->json(['ok' => 1]); } + private function sync_daily_install_containers($iw_uid, $di_uid, $action) + { + $iw_uid = intval($iw_uid); + $di_uid = intval($di_uid); + $action = addslashes(trim($action)); + + if (!$iw_uid) { + throw new Exception('invalid iw_uid'); + } + + if (!$di_uid) { + throw new Exception('invalid di_uid'); + } + + if (!$action) { + throw new Exception('invalid action'); + } + + // 기존 daily container 삭제 + $sqlDelete = " + DELETE FROM tbl_daily_install_container + WHERE + dic_di_uid = '{$di_uid}' + AND dic_action = '{$action}' + "; + + if (!qry($sqlDelete)) { + throw new Exception('daily container delete failed'); + } + + // waitlist container 조회 + $rs = qry(" + SELECT * + FROM tbl_install_waitlist_container + WHERE + iwc_wait_uid = '{$iw_uid}' + AND iwc_action = '{$action}' + ORDER BY iwc_uid ASC + "); + + if (!$rs) { + throw new Exception('wait container select failed'); + } + + // 재 insert + while ($r = mysqli_fetch_assoc($rs)) { + + $type = addslashes($r['iwc_type'] ?? ''); + + $capacity = isset($r['iwc_capacity']) + && $r['iwc_capacity'] !== null + ? intval($r['iwc_capacity']) + : 'NULL'; + + $is_used = addslashes($r['iwc_is_used'] ?? 'N'); + $owner_type = addslashes($r['iwc_owner_type'] ?? 'C'); + + $has_lock = addslashes($r['iwc_has_lock'] ?? 'N'); + $has_wheel = addslashes($r['iwc_has_wheel'] ?? 'N'); + $has_frame = addslashes($r['iwc_has_woodframe'] ?? 'N'); + + $sqlInsert = " + INSERT INTO tbl_daily_install_container + SET + dic_di_uid = '{$di_uid}', + dic_action = '{$action}', + + dic_type = '{$type}', + dic_capacity = {$capacity}, + + dic_is_used = '{$is_used}', + dic_owner_type = '{$owner_type}', + + dic_has_lock = '{$has_lock}', + dic_has_wheel = '{$has_wheel}', + dic_has_woodframe = '{$has_frame}' + "; + + if (!qry($sqlInsert)) { + throw new Exception('daily container insert failed'); + } + } + + return true; + } + public function get_customer_containers_active() { @@ -431,6 +535,7 @@ trait InstallAPI { public function install_wait_complete() { $iw_uid = intval($_POST['iw_uid'] ?? 0); + if (!$iw_uid) { echo $this->json(['ok' => 0, 'msg' => 'no iw_uid']); return; @@ -442,17 +547,14 @@ trait InstallAPI { $request_by = $_POST['request_by'] ?? null; $request_note = $_POST['request_note'] ?? null; $cs_note = $_POST['cs_note'] ?? null; - $work_note = $_POST['work_note'] ?? null; - - $person_cnt = $_POST['person_cnt'] ?? null; // null or 2 - $person_reason= $_POST['person_reason'] ?? null; - $category = intval($_POST['category'] ?? 0); - - $scheduled = intval($_POST['scheduled'] ?? 0); - $cycle = intval($_POST['scheduled_cycle'] ?? 0); - $lock_date = intval($_POST['lock_date'] ?? 0); - - $need_oil = $_POST['need_oil'] ?? 0; // 0 or 1 + $work_note = $_POST['work_note'] ?? null; + $person_cnt = $_POST['person_cnt'] ?? null; + $person_reason = $_POST['person_reason'] ?? null; + $category = intval($_POST['category'] ?? 0); + $scheduled = intval($_POST['scheduled'] ?? 0); + $cycle = intval($_POST['scheduled_cycle'] ?? 0); + $lock_date = intval($_POST['lock_date'] ?? 0); + $need_oil = intval($_POST['need_oil'] ?? 0); // Two-person OFF = NULL if (!$person_cnt) { @@ -460,33 +562,93 @@ trait InstallAPI { $person_reason = null; } - // Recurring OFF = 0 + // Recurring OFF if (!$scheduled) { $cycle = 0; } - qry(" - UPDATE tbl_install_waitlist - SET - iw_request_at = ".($request_at ? "'{$request_at}'" : "NOW()").", - iw_requested_due_date = ".($due_date ? "'{$due_date}'" : "NULL").", - iw_lock_date = '{$lock_date}', - iw_request_by = ".($request_by ? "'{$request_by}'" : "NULL").", - iw_request_note = ".($request_note ? "'".addslashes($request_note)."'" : "NULL").", - iw_cs_note = ".($cs_note ? "'".addslashes($cs_note)."'" : "NULL").", - iw_work_note = ".($work_note ? "'".addslashes($work_note)."'" : "NULL").", + qry("START TRANSACTION"); - iw_required_person_cnt = ".($person_cnt !== null ? intval($person_cnt) : "NULL").", - iw_multi_person_reason = ".($person_reason ? "'".addslashes($person_reason)."'" : "NULL").", - iw_scheduled = '{$scheduled}', - iw_scheduled_cycle = '{$cycle}', - iw_need_oil_pickup = '{$need_oil}', - iw_category = '{$category}', + try { - iw_status = 'WAITING' - WHERE iw_uid = '{$iw_uid}' - LIMIT 1 - "); + $sql = " + UPDATE tbl_install_waitlist + SET + iw_request_at = ".($request_at ? "'{$request_at}'" : "NOW()").", + iw_requested_due_date = ".($due_date ? "'{$due_date}'" : "NULL").", + iw_lock_date = '{$lock_date}', + iw_request_by = ".($request_by ? "'{$request_by}'" : "NULL").", + iw_request_note = ".($request_note ? "'".addslashes($request_note)."'" : "NULL").", + iw_cs_note = ".($cs_note ? "'".addslashes($cs_note)."'" : "NULL").", + iw_work_note = ".($work_note ? "'".addslashes($work_note)."'" : "NULL").", + iw_required_person_cnt = ".($person_cnt !== null ? intval($person_cnt) : "NULL").", + iw_multi_person_reason = ".($person_reason ? "'".addslashes($person_reason)."'" : "NULL").", + iw_scheduled = '{$scheduled}', + iw_scheduled_cycle = '{$cycle}', + iw_need_oil_pickup = '{$need_oil}', + iw_category = '{$category}', + iw_status = CASE + WHEN iw_status IN ('DRAFT') + THEN 'WAITING' + ELSE iw_status + END + WHERE iw_uid = '{$iw_uid}' + LIMIT 1 + "; + + if (!qry($sql)) { + throw new Exception('waitlist update failed'); + } + + // assigned check + $rs = qry(" + SELECT di_uid + FROM tbl_daily_install + WHERE di_wait_uid = '{$iw_uid}' + LIMIT 1 + "); + + if (!$rs) { + throw new Exception('daily install select failed'); + } + + $di = mysqli_fetch_assoc($rs); + + // assigned sync + if ($di && $di['di_uid']) { + + $di_uid = intval($di['di_uid']); + + $sql2 = " + UPDATE tbl_daily_install + SET + di_request_note = ".($request_note ? "'".addslashes($request_note)."'" : "NULL").", + di_cs_note = ".($cs_note ? "'".addslashes($cs_note)."'" : "NULL").", + di_work_note = ".($work_note ? "'".addslashes($work_note)."'" : "NULL").", + di_lock_date = '{$lock_date}', + di_oil_pickup = '{$need_oil}' + WHERE di_uid = '{$di_uid}' + LIMIT 1 + "; + + if (!qry($sql2)) { + throw new Exception('daily install update failed'); + } + } + + qry("COMMIT"); + + } catch (Exception $e) { + + qry("ROLLBACK"); + + echo $this->json([ + 'ok' => 0, + 'msg' => $e->getMessage() + ]); + + return; + } echo $this->json(['ok' => 1]); } diff --git a/public_html/doc/install_wait_list.php b/public_html/doc/install_wait_list.php index af1132a..2da936b 100644 --- a/public_html/doc/install_wait_list.php +++ b/public_html/doc/install_wait_list.php @@ -444,6 +444,15 @@ $categoryLabels = [ type: data.iw_work_type }; + InstallWait.status = (data.iw_status || ''); + const backBtn = document.getElementById('btnStep3Back'); + + if ((InstallWait.status || '').toUpperCase() === 'ASSIGNED') { + backBtn.classList.add('invisible'); + } else { + backBtn.classList.remove('invisible'); + } + // Step3 의 기본 필드 채우기 iwRequestDate.value = data.iw_request_at?.substring(0,10) || ''; iwScheduleDate.value = data.iw_requested_due_date || ''; @@ -1327,16 +1336,13 @@ $categoryLabels = [ tr.dataset.address = r.di_address || ''; tr.dataset.city = r.di_city || ''; tr.dataset.postal = r.di_postal || ''; + tr.dataset.isTrial = r.is_trial ? '1' : '0'; + tr.dataset.iwUid = r.is_trial ? (r.iw_uid || '') : (r.di_wait_uid || ''); + // assigned row 전용 + tr.dataset.diUid = r.di_uid || ''; + tr.dataset.orderSeq = r.di_order_seq || ''; if (r.is_trial) { - tr.dataset.isTrial = '1'; - tr.dataset.iwUid = r.iw_uid; // waitlist uid - tr.dataset.orderSeq = r.di_order_seq; tr.classList.add('table-warning'); - } else { - tr.dataset.isTrial = '0'; - tr.dataset.iwUid = ''; // 기존 daily_install row - tr.dataset.diUid = r.di_uid; - tr.dataset.orderSeq = r.di_order_seq; } tr.innerHTML = `