diff --git a/public_html/assets/api/daily.php b/public_html/assets/api/daily.php index 3019d4e..90d0cd2 100644 --- a/public_html/assets/api/daily.php +++ b/public_html/assets/api/daily.php @@ -448,7 +448,8 @@ class DailyService extends CONF { $data['d_form_eu'] = $customer['c_form_eu'] ?? ''; $data['d_form_corsia'] = $customer['c_form_corsia'] ?? ''; $data['d_maincontainer'] = $customer['c_maincontainer'] ?? ''; - $data['d_container'] = $customer['c_container'] ?? ''; + //$data['d_container'] = $customer['c_container'] ?? ''; + $data['d_container'] = $this->buildContainerString($customerUid, $connect); $data['d_location'] = $customer['c_location'] ?? ''; $data['d_phone'] = $customer['c_phone'] ?? ''; $data['d_address'] = $customer['c_address'] ?? ''; @@ -475,6 +476,34 @@ class DailyService extends CONF { return $data; } + function buildContainerString($c_uid, $connect) { + $sql = " + SELECT cc_type, COUNT(*) as cnt + FROM tbl_customer_container + WHERE cc_customer_uid = '{$c_uid}' + AND cc_status = 'A' + GROUP BY cc_type + ORDER BY cc_type + "; + + $res = mysqli_query($connect, $sql); + + $parts = []; + + while ($row = mysqli_fetch_assoc($res)) { + $type = $row['cc_type']; + $cnt = (int)$row['cnt']; + + if ($cnt > 1) { + $parts[] = "{$type}x{$cnt}"; + } else { + $parts[] = $type; + } + } + + return implode(', ', $parts); + } + private function getDailyColumns(): array { return [ @@ -780,13 +809,13 @@ class DailyService extends CONF { if (empty($after['d_uid'])) return; // note는 saveDaily payload에 포함되어 있어야 함 - if (empty($after['d_pickupnote']) && empty($after['d_note'])) { - return; - } + // if (empty($after['d_pickupnote']) && empty($after['d_note'])) { + // return; + // } $noteText = trim($after['d_pickupnote'] ?? $after['d_note'] ?? ''); - if (strlen($noteText) <= 1) return; + // if (strlen($noteText) <= 1) return; $dailyuid = mysqli_real_escape_string($connect, $after['d_uid']); $customeruid = mysqli_real_escape_string($connect, $after['d_customeruid'] ?? ''); @@ -795,6 +824,15 @@ class DailyService extends CONF { $now14 = date('YmdHis'); $level = mysqli_real_escape_string($connect, $after['d_level'] ?? 9); + if ($noteText === '') { + mysqli_query($connect, " + DELETE FROM tbl_note + WHERE n_dailyuid = '{$dailyuid}' + LIMIT 1 + "); + return; + } + // 기존 note 존재 여부 확인 $qr = mysqli_query($connect, " SELECT n_uid diff --git a/public_html/assets/api/install.php b/public_html/assets/api/install.php index a1e3972..805f54a 100644 --- a/public_html/assets/api/install.php +++ b/public_html/assets/api/install.php @@ -1138,80 +1138,6 @@ trait InstallAPI { qry($sql); } - // 최초 install - if ($install_date) { - - $install_yyyymmdd = str_replace('-', '', $install_date); - - // 현재 c_installdate 가져오기 - $r = qry("SELECT c_installdate FROM tbl_customer WHERE c_uid='{$c_uid}'"); - $row = mysqli_fetch_assoc($r); - $current = $row['c_installdate']; - - if (!$current || $current === 'N/A' || $install_yyyymmdd < $current) { - - qry(" - UPDATE tbl_customer - SET c_installdate='{$install_yyyymmdd}' - WHERE c_uid='{$c_uid}' - "); - } - } - - // c_exchangedate: 최신 install_date 또는 pickup_date - $exchangeDates = []; - - if ($install_date) { - $exchangeDates[] = str_replace('-', '', $install_date); - } - - if ($pickup_date) { - $exchangeDates[] = str_replace('-', '', $pickup_date); - } - - if (!empty($exchangeDates)) { - rsort($exchangeDates); - $latestExchangeDate = $exchangeDates[0]; - - qry(" - UPDATE tbl_customer - SET c_exchangedate = '{$latestExchangeDate}' - WHERE c_uid = '{$c_uid}' - "); - } - - // c_removaldate: 작업 후 active container가 하나도 없으면 최종 수거일 업데이트 - // 반대로 active container가 있으면 c_removaldate 초기화 - $r = qry(" - SELECT COUNT(*) AS active_cnt - FROM tbl_customer_container - WHERE cc_customer_uid = '{$c_uid}' - AND cc_status = 'A' - "); - - $row = mysqli_fetch_assoc($r); - $activeCnt = (int)($row['active_cnt'] ?? 0); - - if ($activeCnt === 0) { - if ($pickup_date) { - $pickup_yyyymmdd = str_replace('-', '', $pickup_date); - - qry(" - UPDATE tbl_customer - SET c_removaldate = '{$pickup_yyyymmdd}' - WHERE c_uid = '{$c_uid}' - "); - } - } else { - qry(" - UPDATE tbl_customer - SET c_removaldate = '' - WHERE c_uid = '{$c_uid}' - and c_removaldate <> '' - "); - } - - echo $this->json(['ok'=>1]); } @@ -1269,7 +1195,7 @@ trait InstallAPI { $this->apply_container_changes_for_di($di_uid, $install_note, intval($di['di_customer_uid'])); // 3-1) 컨테이너 반영 후 customer 의 main 볼륨이랑 main 컨테이너 변경 - $this->updateCustomerMainContainer(intval($di['di_customer_uid'])); + $this->updateCustomerMainContainer(intval($di['di_customer_uid']), $di['di_install_date']); } // 4) oil pickup → daily @@ -1339,6 +1265,19 @@ trait InstallAPI { // file_put_contents(__DIR__.'/debug.log', "NOTE: ".$additional_note."\n", FILE_APPEND); $noteText = trim($additional_note); if (strlen($noteText) <= 1) { + // 기존 note 삭제 + $di_uid = intval($di['di_uid'] ?? 0); + if ($di_uid > 0) { + + $noteDailyUid = 'i_' . $di_uid; + $n_dailyuid = mysqli_real_escape_string($connect, $noteDailyUid); + + mysqli_query($connect, " + DELETE FROM tbl_note + WHERE n_dailyuid = '{$n_dailyuid}' + "); + } + return; } @@ -1891,19 +1830,23 @@ trait InstallAPI { } } - private function updateCustomerMainContainer($customer_uid) + private function updateCustomerMainContainer($customer_uid, $install_date) { $customer_uid = intval($customer_uid); + $install_yyyymmdd = null; + if (!empty($install_date)) { + $install_yyyymmdd = str_replace('-', '', $install_date); + } - // ========================================= - // 0) 수동 관리 - // ========================================= $qr = qry(" SELECT c_manualvolume, c_fullcycleflag, c_fullcycleforced, - c_mainvolume + c_mainvolume, + c_installdate, + c_exchangedate, + c_removaldate FROM tbl_customer WHERE c_uid = '{$customer_uid}' LIMIT 1 @@ -1914,6 +1857,58 @@ trait InstallAPI { throw new Exception('customer not found'); } + if ($install_yyyymmdd) { + // first install + $current_installdate = $cus['c_installdate']; + if (!$current_installdate || $current_installdate === 'N/A' || $install_yyyymmdd < $current_installdate) { + + qry(" + UPDATE tbl_customer + SET c_installdate='{$install_yyyymmdd}' + WHERE c_uid='{$customer_uid}' + "); + } + + // exchange date (최근 install 작업) + $current_exchangedate = $cus['c_exchangedate']; + if ($current_exchangedate < $install_yyyymmdd) { + qry(" + UPDATE tbl_customer + SET c_exchangedate='{$install_yyyymmdd}' + WHERE c_uid='{$customer_uid}' + "); + } + + // removal date + $q_activeCount = qry(" + SELECT COUNT(*) AS active_cnt + FROM tbl_customer_container + WHERE cc_customer_uid = '{$customer_uid}' + AND cc_status = 'A' + "); + + $row_activeCount = mysqli_fetch_assoc($q_activeCount); + $activeCnt = (int)($row_activeCount['active_cnt'] ?? 0); + if ($activeCnt === 0) { + qry(" + UPDATE tbl_customer + SET c_removaldate = '{$install_yyyymmdd}' + WHERE c_uid = '{$customer_uid}' + "); + } else { + // 치웠다가 다시 설치 + qry(" + UPDATE tbl_customer + SET c_removaldate = '' + WHERE c_uid = '{$customer_uid}' + AND c_removaldate <> '' + "); + } + } + + // ========================================= + // 1) 수동 관리 + // ========================================= if ($cus['c_manualvolume'] === 'Y') { // 아무것도 하지 않음 return; @@ -1922,7 +1917,7 @@ trait InstallAPI { $oldVolume = intval($cus['c_mainvolume'] ?? 0); // ========================================= - // 1) active container 조회 + // 2) active container 조회 // ========================================= $rc = qry(" SELECT @@ -1940,7 +1935,7 @@ trait InstallAPI { } // ========================================= - // 2) 컨테이너 없으면 초기화 + // 3) 컨테이너 없으면 초기화 // ========================================= if (!count($containers)) { @@ -1957,7 +1952,7 @@ trait InstallAPI { } // ========================================= - // 3) 타입 분류 (D / B) + // 4) 타입 분류 (D / B) // ========================================= $d_list = []; // D 계열 $b_list = []; // B 계열 @@ -1989,7 +1984,7 @@ trait InstallAPI { } // ========================================= - // 4) B가 하나라도 있으면 → B 기준 처리 + // 5) B가 하나라도 있으면 → B 기준 처리 // ========================================= if (count($b_list) > 0) { @@ -2027,7 +2022,7 @@ trait InstallAPI { } // ========================================= - // 5) B 없고 D만 있는 경우 + // 6) B 없고 D만 있는 경우 // ========================================= if (count($d_list) > 0) { @@ -2057,7 +2052,7 @@ trait InstallAPI { } // ========================================= - // 6) fallback (이상 케이스) + // 7) fallback (이상 케이스) // ========================================= qry(" UPDATE tbl_customer diff --git a/public_html/doc/customer_detail.php b/public_html/doc/customer_detail.php index 4800b80..b97e8c2 100644 --- a/public_html/doc/customer_detail.php +++ b/public_html/doc/customer_detail.php @@ -96,6 +96,9 @@ if ($mode == "update") { if ($c_removaldate != "N/A") $c_removaldateSTR = $func -> convertFormat ($c_removaldate, 3); else $c_removaldateSTR = "N/A"; + + if ($c_exchangedate != "N/A") $c_exchangedateSTR = $func -> convertFormat ($c_exchangedate, 3); + else $c_exchangedateSTR = "N/A"; // function safeDate($val) { @@ -1494,11 +1497,21 @@ $(document).ready(function() -