- [INSTALL WAIT LIST] Assigned 된 작업도 수정 추가.
This commit is contained in:
Hyojin Ahn 2026-05-14 11:30:11 -04:00
parent 0695e5d1cd
commit ef26d34239
4 changed files with 220 additions and 45 deletions

View File

@ -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;
@ -443,16 +548,13 @@ trait InstallAPI {
$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_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 = $_POST['need_oil'] ?? 0; // 0 or 1
$need_oil = intval($_POST['need_oil'] ?? 0);
// Two-person OFF = NULL
if (!$person_cnt) {
@ -460,12 +562,16 @@ trait InstallAPI {
$person_reason = null;
}
// Recurring OFF = 0
// Recurring OFF
if (!$scheduled) {
$cycle = 0;
}
qry("
qry("START TRANSACTION");
try {
$sql = "
UPDATE tbl_install_waitlist
SET
iw_request_at = ".($request_at ? "'{$request_at}'" : "NOW()").",
@ -475,19 +581,75 @@ trait InstallAPI {
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 = 'WAITING'
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]);
}

View File

@ -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 = `
<td class="iw-drag-handle" style="cursor:grab;">
@ -1361,7 +1367,10 @@ $categoryLabels = [
<td><span class="badge ${getWorkTypeBadge(r.di_work_type)}" title="${r.di_work_type || ''}"> ${(r.di_work_type || '').substring(0, 2)}</span></td>
<td>${renderContainerSummary(r.pickup_d_cnt, r.pickup_b_cnt)}</td>
<td>${renderContainerSummary(r.install_d_cnt, r.install_b_cnt)}</td>
<td class="text-center">${r.is_trial ? '' : `<button class="btn btn-sm btn-outline-danger btn-unassign" title="Remove from schedule"> <i class="bi bi-dash-circle"></i></button>`}</td>
<td class="text-center">${r.is_trial ? '' : `
<button class="btn btn-sm btn-outline-secondary btn-edit-install-wait" data-iw-uid="${tr.dataset.iwUid || ''}" title="Edit assigned work"> <i class="bi bi-pencil-square"></i></button>
<button class="btn btn-sm btn-outline-danger btn-unassign" title="Remove from schedule"> <i class="bi bi-dash-circle"></i></button>
`}</td>
`;
const tooltipHtml = `

View File

@ -237,8 +237,8 @@ function bindStep2Next() {
STEP 3
============================ */
function initInstallWaitStep3() {
btnStep3Back.onclick = () => {
const backBtn = document.getElementById('btnStep3Back');
backBtn.onclick = () => {
// id 없으면 그냥 back
if (!InstallWait.iw_uid) {
goInstallWaitStep(2);
@ -321,8 +321,9 @@ function initInstallWaitStep3() {
if (!res || !res.ok) {
btnStep3Complete.disabled = false;
console.error(res);
//alert('Failed to complete install request');
showPopupMessage('Save failed', 'error', 1500);
showPopupMessage(res?.msg || JSON.stringify(res) || 'Save failed', 'error', 1500);
return;
}

View File

@ -22,7 +22,10 @@ WHERE di.di_install_date BETWEEN '{$startDate}' AND '{$endDate}'
ORDER BY di.di_install_date, di_driver_uid, di_order_seq ASC
";
$result = mysqli_query($connect, $sql);
$result = mysqli_query($conn, $sql);
if(!$result){
die(mysqli_error($conn));
}
$installData = [];
$sq = qry($sql);