From e01e72c0cadd05d21cdd69d39ac244b70364a661 Mon Sep 17 00:00:00 2001 From: Hyojin Ahn Date: Wed, 29 Apr 2026 08:14:27 -0400 Subject: [PATCH] =?UTF-8?q?v1.2.4=20-=20[ORDER]=20Note=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EC=A0=81=EC=9A=A9.=20-=20[INS?= =?UTF-8?q?TALL=20ORDER]=20Note=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9.=20-=20[INSTALL=20ORDER]=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=20=EC=99=84=EB=A3=8C=20=ED=9B=84=20Customer=20?= =?UTF-8?q?=EC=9D=98=20install,=20exchange,=20removal=20date=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95.=20-=20[LOGIN]=20m=5Fgid=20?= =?UTF-8?q?=EB=A5=BC=20=ED=99=9C=EC=9A=A9=ED=95=B4=EC=84=9C=20Plant=20?= =?UTF-8?q?=EA=B3=84=EC=A0=95=EC=9D=80=20Install=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20=EB=B3=BC=20=EC=88=98=20=EC=9E=88=EA=B2=8C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95.=20-=20[EXPORT]=20=EC=95=A1=EC=85=80=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=A0=20=EB=95=8C=20Container=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20Container=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public_html/assets/api/daily.php | 48 +++++++- public_html/assets/api/install.php | 167 ++++++++++++++-------------- public_html/doc/customer_detail.php | 15 ++- public_html/doc/export_process.php | 53 ++++++++- public_html/doc/forecast_list.php | 2 +- public_html/doc/install_order.php | 9 +- public_html/doc/order_driver.php | 2 +- public_html/include/arrayinfo.php | 2 +- public_html/lib/login_process.php | 1 + 9 files changed, 196 insertions(+), 103 deletions(-) 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() - Last Removal Date + Removal Date + + Last Container Work Date + + + + + + + + Container
Show Inactive
diff --git a/public_html/doc/export_process.php b/public_html/doc/export_process.php index 3c5ab55..9e07006 100644 --- a/public_html/doc/export_process.php +++ b/public_html/doc/export_process.php @@ -36,6 +36,28 @@ if ($actionStr == "CUSTOMER") { } echo "\n"; + // Active customer containers map + $customerContainerMap = []; + + $qry_cc = " + SELECT cc_customer_uid, cc_type + FROM tbl_customer_container + WHERE cc_status = 'A' + ORDER BY cc_customer_uid, cc_type, cc_uid + "; + + $rt_cc = $jdb->nQuery($qry_cc, "container load error"); + + while ($row_cc = mysqli_fetch_assoc($rt_cc)) { + $cu = (int)$row_cc['cc_customer_uid']; + + if (!isset($customerContainerMap[$cu])) { + $customerContainerMap[$cu] = []; + } + + $customerContainerMap[$cu][] = $row_cc; + } + // Customer list $query = "SELECT * FROM tbl_customer WHERE c_uid != '' ORDER BY c_uid DESC"; $result = $jdb->nQuery($query, "list error"); @@ -49,7 +71,32 @@ if ($actionStr == "CUSTOMER") { foreach ($export_customer as $col) { - if ($col == 'c_maincontainer') { + if ($col == 'c_container') { + $containers = $customerContainerMap[(int)$list['c_uid']] ?? []; + + $counts = []; + foreach ($containers as $containerRow) { + $type = trim($containerRow['cc_type']); + if ($type === '') continue; + + if (!isset($counts[$type])) { + $counts[$type] = 0; + } + + $counts[$type]++; + } + + $parts = []; + foreach ($counts as $type => $cnt) { + $parts[] = ($cnt > 1) ? "{$type}x{$cnt}" : $type; + } + + $containerStr = implode(', ', $parts); + + echo "" . $containerStr . "\n"; + } + + else if ($col == 'c_maincontainer') { echo "" . $arrBin[$list[$col]] . "\n"; } @@ -296,7 +343,7 @@ if ($actionStr == "CUSTOMER") { /* -------- DATA QUERY -------- */ $qry = " - SELECT d_accountno as c_accountno, c_status, d_name as c_name, m_region as c_driveruid, m.m_currentdriverinitial as m_currentdriverinitial + SELECT d_accountno as c_accountno, c_status, d_name as c_name, m_region as c_driveruid, d_drinitial as m_currentdriverinitial , d_address as c_address, d_city as c_city, d_postal as c_postal, d_area as c_area , d_phone as c_phone, c_phoneext, c_cell, d_rate as c_rate, d_paymenttype as c_paymenttype , d_maincontainer as c_maincontainer, d_container as c_container, d_location as c_location, c_schedule @@ -317,8 +364,6 @@ if ($actionStr == "CUSTOMER") { FROM tbl_daily d JOIN tbl_customer c ON d.d_customeruid = c.c_uid - JOIN tbl_member m - ON d.d_driveruid = m.m_uid WHERE d.d_status = 'F' AND d.d_orderdate BETWEEN '$oil_period_fromTMP' AND '$oil_period_toTMP' ORDER BY d.d_orderdate, c.c_accountno diff --git a/public_html/doc/forecast_list.php b/public_html/doc/forecast_list.php index 29332bc..bd21834 100644 --- a/public_html/doc/forecast_list.php +++ b/public_html/doc/forecast_list.php @@ -210,7 +210,7 @@ else $typeQRY = " AND (c_schedule = 'None') "; if ($c_type_o == "O") $orderflagQRY = " AND c_orderflag = 0 "; else $orderflagQRY = " ";; -$qry_driver = "SELECT m_initial, m_firstname, m_lastname FROM tbl_member WHERE m_uid = '$c_driveruid' "; +$qry_driver = "SELECT m_initial, m_firstname, m_lastname, m_currentdriver FROM tbl_member WHERE m_uid = '$c_driveruid' "; $rt_driver = $jdb->fQuery($qry_driver, "fetch query error"); // $query = "SELECT * FROM tbl_sampletypes diff --git a/public_html/doc/install_order.php b/public_html/doc/install_order.php index a5b65d0..cdb6d47 100644 --- a/public_html/doc/install_order.php +++ b/public_html/doc/install_order.php @@ -1,19 +1,20 @@ 0){ - $whereDriver = " AND di_driver_uid = {$driver_uid}"; + $whereDriver = " AND di_driver_uid = '{$driver_uid}'"; } } diff --git a/public_html/doc/order_driver.php b/public_html/doc/order_driver.php index 40f9e8e..19a578e 100644 --- a/public_html/doc/order_driver.php +++ b/public_html/doc/order_driver.php @@ -376,7 +376,7 @@ while($lt_driver=mysqli_fetch_array($rt_driver, MYSQLI_ASSOC)) { // Get Driver Info -$qry_dr = "SELECT * FROM tbl_driver WHERE dr_status = 'A' ORDER by dr_initial ASC "; +$qry_dr = "SELECT * FROM tbl_driver WHERE dr_status = 'A' and dr_type = 'UCO' ORDER by dr_initial ASC "; $rt_dr = $jdb->nQuery($qry_dr, "list error"); while($lt_dr=mysqli_fetch_array($rt_dr, MYSQLI_ASSOC)) { diff --git a/public_html/include/arrayinfo.php b/public_html/include/arrayinfo.php index 8bc848b..d64c929 100644 --- a/public_html/include/arrayinfo.php +++ b/public_html/include/arrayinfo.php @@ -18,7 +18,7 @@ $arrPaymentCycle = array ('A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'F' => $arrNoteType = array ('B' => 'Accounting', 'S' => 'Staff', 'D' => 'Driver', 'A' => 'All' ); $arrPaidStatus = array ('P' => 'Paid', 'N' => 'UnPaid', 'G' => 'Paid (Grease Trap)'); -$arrMemberLevel = array ('1' => 'Administrator', '5' => 'Staff', '6' => 'Accounting', '7' => 'Sales', '8' => 'Install Driver', '9' => 'UCO Driver', '10' => 'Sales Agent' ); +$arrMemberLevel = array ('1' => 'Administrator', '5' => 'Staff', '6' => 'Accounting', '7' => 'Sales', '8' => 'Plant/Install', '9' => 'UCO Driver', '10' => 'Sales Agent' ); $arrJobType = array ('UCO' => 'UCO', 'INSTALL' => 'INSTALL', 'EMERGENCY' => 'EMERGENCY'); //$arrClass = array ('M' => 'Math', 'P' => 'Physics', 'C' => 'Chemistry', 'B' => 'Biology', 'S' => 'Science', 'O' => 'Others' ); diff --git a/public_html/lib/login_process.php b/public_html/lib/login_process.php index 68410e6..54ba00c 100644 --- a/public_html/lib/login_process.php +++ b/public_html/lib/login_process.php @@ -107,6 +107,7 @@ if($action == "login") { // Level : m_level : Admin : 1, Manager : 3, Staff : 5, Accounting : 6, Operator : 7, Driver : 9 $_SESSION['ss_LEVEL'] = $result['m_level']; + $_SESSION['ss_GROUP'] = $result['m_gid']; $today = $func -> PgetTime(0,0,4); $loginCnt = $result['m_loginnum']+1;