checkLevelModal(5);
// ============================
// Search filters (LEFT ONLY)
// ============================
$where = [];
if (!empty($kw_customer)) $where[] = "(iw_customer_name LIKE '%{$kw_customer}%' OR iw_address LIKE '%{$kw_customer}%' OR iw_accountno LIKE '%{$kw_customer}%' OR iw_city LIKE '%{$kw_customer}%')";
if (!empty($kw_work)) $where[] = "(iw_work_type = '{$kw_work}')";
if (!empty($_GET['kw_two_person'])) $where[] = "(iw_required_person_cnt IS NOT NULL AND iw_required_person_cnt > 0)";
$kw_categories = $_GET['kw_category'] ?? [];
if (!is_array($kw_categories)) $kw_categories = [$kw_categories];
$kw_categories = array_filter(array_map('intval', $kw_categories), function($v){
return $v >= 0 && $v <= 5;
});
if ($kw_categories) {
$hasZero = in_array(0, $kw_categories);
$cats = array_filter($kw_categories, fn($v) => $v > 0);
$cond = [];
if ($cats) $cond[] = "iw_category IN (" . implode(',', $cats) . ")";
if ($hasZero) $cond[] = "(iw_category = 0 OR iw_category IS NULL)";
$where[] = '(' . implode(' OR ', $cond) . ')';
}
$statusList = [];
if (!empty($_GET['kw_waiting'])) $statusList[] = "'WAITING'";
if (!empty($_GET['kw_draft'])) $statusList[] = "'DRAFT'";
if (!empty($_GET['kw_assigned'])) $statusList[] = "'ASSIGNED'";
// 기본
if (!$statusList) {
$statusList = ["'WAITING'", "'DRAFT'"];
}
$statusWhere = "iw_status IN (" . implode(',', $statusList) . ")";
if (!empty($where)) {
$add_where = ' AND ' . implode(' AND ', $where);
}
function db_escape($jdb, $str) {
return mysqli_real_escape_string($jdb->DBConn, $str);
}
$view_mode = ($_GET['view_mode'] ?? 'list') === 'map' ? 'map' : 'list';
// ============================
// Total count
// ============================
$sql_cnt = "
SELECT COUNT(*)
FROM tbl_install_waitlist
WHERE {$statusWhere}
$add_where
";
$total_count = $jdb->rQuery($sql_cnt, "Install wait list count error");
// ============================
// 1) Load waitlist
// ============================
$sql = "
SELECT iw.*, CONCAT(m.m_firstname, ' ', m.m_lastname) as iw_created_member, di.di_install_date
FROM tbl_install_waitlist iw
LEFT OUTER JOIN tbl_member m
ON iw.iw_created_by = m.m_uid
LEFT JOIN (
SELECT
di_wait_uid,
MAX(di_install_date) as di_install_date
FROM tbl_daily_install
WHERE di_status != 'X'
GROUP BY di_wait_uid
) di ON di.di_wait_uid = iw.iw_uid
WHERE {$statusWhere}
$add_where
ORDER BY iw_category, iw_requested_due_date ASC, iw_request_at ASC
";
$rs = $jdb->nQuery($sql, "Load waitlist error");
$rows = [];
$iw_uids = [];
$customer_uids = [];
while ($r = mysqli_fetch_assoc($rs)) {
$rows[] = $r;
$iw_uids[] = (int)$r['iw_uid'];
if (!empty($r['iw_customer_uid'])) {
$customer_uids[] = (int)$r['iw_customer_uid'];
}
}
$iw_uids = array_values(array_unique($iw_uids));
$customer_uids = array_values(array_unique($customer_uids));
/* ============================
* 2) Customer containers (cc_status='A')
* ============================ */
$customerContainerMap = []; // [customer_uid => [rows...]]
if ($customer_uids) {
$in = implode(',', $customer_uids);
$sql_cc = "
SELECT cc_customer_uid, cc_type, cc_owner_type, cc_is_used, cc_has_lock, cc_has_wheel, cc_has_woodframe
FROM tbl_customer_container
WHERE cc_status = 'A'
AND cc_customer_uid IN ($in)
ORDER BY cc_customer_uid, cc_type, cc_uid
";
$rc = $jdb->nQuery($sql_cc, "Load customer containers error");
while ($c = mysqli_fetch_assoc($rc)) {
$cu = (int)$c['cc_customer_uid'];
if (!isset($customerContainerMap[$cu])) $customerContainerMap[$cu] = [];
$customerContainerMap[$cu][] = $c;
}
}
/* ============================
* 3) Task containers (waitlist)
* ============================ */
$taskMap = []; // [iw_uid => rows]
if ($iw_uids) {
$in = implode(',', $iw_uids);
$sql_task = "
SELECT *
FROM tbl_install_waitlist_container
WHERE iwc_wait_uid IN ($in)
ORDER BY iwc_wait_uid, iwc_uid
";
$rt = $jdb->nQuery($sql_task, "Load task containers error");
while ($t = mysqli_fetch_assoc($rt)) {
$taskMap[$t['iwc_wait_uid']][] = $t;
}
}
/* ============================
* 4) Customer images (install_order)
* ============================ */
$imageMap = []; // [customer_uid => true]
if ($iw_uids) {
$in = implode(',', $iw_uids);
$sql_img = "
SELECT DISTINCT i_customeruid
FROM tbl_customer_image
WHERE i_status = 'A'
AND i_type = 'install_order'
AND i_sourceuid IN ($in)
";
$ri = $jdb->nQuery($sql_img, "Load customer images error");
while ($img = mysqli_fetch_assoc($ri)) {
$imageMap[(int)$img['i_customeruid']] = true;
}
}
// ============================
// 5) customer driver
// ============================
$customerDriverMap = []; // [customer_uid => driver_uid]
if ($customer_uids) {
$in = implode(',', $customer_uids);
$sql_cd = "
SELECT
c.c_uid,
d.dr_initial
FROM tbl_customer c
LEFT JOIN tbl_member m
ON c.c_regionuid = m.m_regionuid
LEFT JOIN tbl_driver d
ON m.m_defaultdriver = d.dr_uid
WHERE c.c_uid IN ($in)
AND d.dr_type = 'UCO'
";
$rc = $jdb->nQuery($sql_cd, "Load customer driver error");
while ($c = mysqli_fetch_assoc($rc)) {
$cu = (int)$c['c_uid'];
$customerDriverMap[$cu] = $c['dr_initial'] ?? '';
}
}
// ============================
// 6) install drivers
// ============================
$drivers = [];
$sql_install = "
SELECT dr_uid, dr_initial
FROM tbl_driver
WHERE dr_status = 'A'
AND dr_type = 'INSTALL'
ORDER BY dr_uid
";
$ris = $jdb->nQuery($sql_install, "Load install drivers error");
while ($r = mysqli_fetch_assoc($ris)) {
$drivers[] = $r;
}
// ============================
// 7) driver initials (modal)
// ============================
$driverInitialMap = []; // [dr_uid => dr_initial]
$sql_driver = "
SELECT dr_uid, dr_initial
FROM tbl_driver
WHERE dr_status = 'A'
";
$res = $jdb->nQuery($sql_driver, "Load driver map error");
while ($r = mysqli_fetch_assoc($res)) {
$driverInitialMap[(int)$r['dr_uid']] = $r['dr_initial'];
}
// ============================
// 전화번호
// ============================
function formatPhone($phone) {
$digits = preg_replace('/\D+/', '', (string)$phone);
// 10 digits => (xxx) xxx-xxxx
if (strlen($digits) === 10) {
return sprintf(
'(%s) %s - %s',
substr($digits, 0, 3),
substr($digits, 3, 3),
substr($digits, 6, 4)
);
}
return $phone;
}
function getWaitCategoryColor($cat) {
switch ((int)$cat) {
case 1: return '#ff4d4f'; // red
case 2: return '#1677ff'; // blue
case 3: return '#52c41a'; // green
case 4: return '#fa9614'; // orange
case 5: return '#9254de'; // purple
default: return 'transparent';
}
}
// 하드코딩
$categoryLabels = [
0 => 'No Category',
1 => 'To do list',
2 => 'Power Wash',
3 => 'Category 3',
4 => 'Category 4',
5 => 'Category 5'
];
?>
INSTALL WAIT LIST
- HOME
- PLANNING
- INSTALL WAIT LIST
No waiting items.
=$work?>
created by =$row['iw_created_member']?>
Draft
1): ?>
x=$row['iw_required_person_cnt']?>
=$row['iw_multi_person_reason']?>
0): ?>
Pickup
Every =$row['iw_scheduled_cycle']?> days
· Last = $row['iw_last_exchange_date'] ?>
Assigned: =$row['di_install_date']?>
=$row['iw_lock_date'] == 1 ? '' : '';?>
Due: =$row['iw_requested_due_date'] ?: '-'?>
=$row['iw_accountno']?>
=$row['iw_customer_name']?>
=$driverInitial?>
=$row['iw_address']?>, =$row['iw_city']?>, =$row['iw_postal']?> ·
=formatPhone($row['iw_phone'])?>
=$dueTypeLabel?>
Request
(by =$reqByDisplay?> =substr($row['iw_request_at'],0,10)?>)
=htmlspecialchars($row['iw_request_note'])?>
CS
=htmlspecialchars($row['iw_cs_note'])?>
Work
=htmlspecialchars($row['iw_work_note'])?>
Pickup
Install
=$action?>
';
if ($t['iwc_has_wheel'] === 'Y') $optIcons .= ' ';
if ($t['iwc_has_woodframe'] === 'Y') $optIcons .= ' ';
?>
=$usedLabel?>=$t['iwc_type']?>
=$optIcons?>
Customer";
$sql_driver = "
SELECT dr_uid, dr_initial
FROM tbl_driver
WHERE dr_status = 'A'
ORDER BY dr_initial
";
$rmem = $jdb->nQuery($sql_driver, "Load driver list error");
while ($row = mysqli_fetch_assoc($rmem)) {
$driveruid = $row['dr_uid'];
$ini = htmlspecialchars(trim($row['dr_initial']));
if ($ini === '') continue;
$iwRequestByOptions .= "";
}
?>