- [ORDER] Note 삭제 로직 적용.
- [INSTALL ORDER] Note 삭제 로직 적용.
- [INSTALL ORDER] 작업 완료 후 Customer 의 install, exchange, removal date 로직 수정.
- [LOGIN] m_gid 를 활용해서 Plant 계정은 Install 전체 일정 볼 수 있게 수정.
- [EXPORT] 액셀 저장할 때 Container 정보를 Container 테이블에서 가져오도록 수정.
This commit is contained in:
Hyojin Ahn 2026-04-29 08:14:27 -04:00
parent be2a92d2db
commit e01e72c0ca
9 changed files with 196 additions and 103 deletions

View File

@ -448,7 +448,8 @@ class DailyService extends CONF {
$data['d_form_eu'] = $customer['c_form_eu'] ?? ''; $data['d_form_eu'] = $customer['c_form_eu'] ?? '';
$data['d_form_corsia'] = $customer['c_form_corsia'] ?? ''; $data['d_form_corsia'] = $customer['c_form_corsia'] ?? '';
$data['d_maincontainer'] = $customer['c_maincontainer'] ?? ''; $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_location'] = $customer['c_location'] ?? '';
$data['d_phone'] = $customer['c_phone'] ?? ''; $data['d_phone'] = $customer['c_phone'] ?? '';
$data['d_address'] = $customer['c_address'] ?? ''; $data['d_address'] = $customer['c_address'] ?? '';
@ -475,6 +476,34 @@ class DailyService extends CONF {
return $data; 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 private function getDailyColumns(): array
{ {
return [ return [
@ -780,13 +809,13 @@ class DailyService extends CONF {
if (empty($after['d_uid'])) return; if (empty($after['d_uid'])) return;
// note는 saveDaily payload에 포함되어 있어야 함 // note는 saveDaily payload에 포함되어 있어야 함
if (empty($after['d_pickupnote']) && empty($after['d_note'])) { // if (empty($after['d_pickupnote']) && empty($after['d_note'])) {
return; // return;
} // }
$noteText = trim($after['d_pickupnote'] ?? $after['d_note'] ?? ''); $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']); $dailyuid = mysqli_real_escape_string($connect, $after['d_uid']);
$customeruid = mysqli_real_escape_string($connect, $after['d_customeruid'] ?? ''); $customeruid = mysqli_real_escape_string($connect, $after['d_customeruid'] ?? '');
@ -795,6 +824,15 @@ class DailyService extends CONF {
$now14 = date('YmdHis'); $now14 = date('YmdHis');
$level = mysqli_real_escape_string($connect, $after['d_level'] ?? 9); $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 존재 여부 확인 // 기존 note 존재 여부 확인
$qr = mysqli_query($connect, " $qr = mysqli_query($connect, "
SELECT n_uid SELECT n_uid

View File

@ -1138,80 +1138,6 @@ trait InstallAPI {
qry($sql); 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]); 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'])); $this->apply_container_changes_for_di($di_uid, $install_note, intval($di['di_customer_uid']));
// 3-1) 컨테이너 반영 후 customer 의 main 볼륨이랑 main 컨테이너 변경 // 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 // 4) oil pickup → daily
@ -1339,6 +1265,19 @@ trait InstallAPI {
// file_put_contents(__DIR__.'/debug.log', "NOTE: ".$additional_note."\n", FILE_APPEND); // file_put_contents(__DIR__.'/debug.log', "NOTE: ".$additional_note."\n", FILE_APPEND);
$noteText = trim($additional_note); $noteText = trim($additional_note);
if (strlen($noteText) <= 1) { 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; return;
} }
@ -1891,19 +1830,23 @@ trait InstallAPI {
} }
} }
private function updateCustomerMainContainer($customer_uid) private function updateCustomerMainContainer($customer_uid, $install_date)
{ {
$customer_uid = intval($customer_uid); $customer_uid = intval($customer_uid);
$install_yyyymmdd = null;
if (!empty($install_date)) {
$install_yyyymmdd = str_replace('-', '', $install_date);
}
// =========================================
// 0) 수동 관리
// =========================================
$qr = qry(" $qr = qry("
SELECT SELECT
c_manualvolume, c_manualvolume,
c_fullcycleflag, c_fullcycleflag,
c_fullcycleforced, c_fullcycleforced,
c_mainvolume c_mainvolume,
c_installdate,
c_exchangedate,
c_removaldate
FROM tbl_customer FROM tbl_customer
WHERE c_uid = '{$customer_uid}' WHERE c_uid = '{$customer_uid}'
LIMIT 1 LIMIT 1
@ -1914,6 +1857,58 @@ trait InstallAPI {
throw new Exception('customer not found'); 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') { if ($cus['c_manualvolume'] === 'Y') {
// 아무것도 하지 않음 // 아무것도 하지 않음
return; return;
@ -1922,7 +1917,7 @@ trait InstallAPI {
$oldVolume = intval($cus['c_mainvolume'] ?? 0); $oldVolume = intval($cus['c_mainvolume'] ?? 0);
// ========================================= // =========================================
// 1) active container 조회 // 2) active container 조회
// ========================================= // =========================================
$rc = qry(" $rc = qry("
SELECT SELECT
@ -1940,7 +1935,7 @@ trait InstallAPI {
} }
// ========================================= // =========================================
// 2) 컨테이너 없으면 초기화 // 3) 컨테이너 없으면 초기화
// ========================================= // =========================================
if (!count($containers)) { if (!count($containers)) {
@ -1957,7 +1952,7 @@ trait InstallAPI {
} }
// ========================================= // =========================================
// 3) 타입 분류 (D / B) // 4) 타입 분류 (D / B)
// ========================================= // =========================================
$d_list = []; // D 계열 $d_list = []; // D 계열
$b_list = []; // B 계열 $b_list = []; // B 계열
@ -1989,7 +1984,7 @@ trait InstallAPI {
} }
// ========================================= // =========================================
// 4) B가 하나라도 있으면 → B 기준 처리 // 5) B가 하나라도 있으면 → B 기준 처리
// ========================================= // =========================================
if (count($b_list) > 0) { if (count($b_list) > 0) {
@ -2027,7 +2022,7 @@ trait InstallAPI {
} }
// ========================================= // =========================================
// 5) B 없고 D만 있는 경우 // 6) B 없고 D만 있는 경우
// ========================================= // =========================================
if (count($d_list) > 0) { if (count($d_list) > 0) {
@ -2057,7 +2052,7 @@ trait InstallAPI {
} }
// ========================================= // =========================================
// 6) fallback (이상 케이스) // 7) fallback (이상 케이스)
// ========================================= // =========================================
qry(" qry("
UPDATE tbl_customer UPDATE tbl_customer

View File

@ -96,6 +96,9 @@ if ($mode == "update") {
if ($c_removaldate != "N/A") $c_removaldateSTR = $func -> convertFormat ($c_removaldate, 3); if ($c_removaldate != "N/A") $c_removaldateSTR = $func -> convertFormat ($c_removaldate, 3);
else $c_removaldateSTR = "N/A"; 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) { function safeDate($val) {
@ -1494,11 +1497,21 @@ $(document).ready(function()
<input type="text" id="c_installdate" name="c_installdate" value="<?=$c_installdateSTR?>" placeholder="<?=date('Y-m-d')?>" readonly> <input type="text" id="c_installdate" name="c_installdate" value="<?=$c_installdateSTR?>" placeholder="<?=date('Y-m-d')?>" readonly>
</td> </td>
<td class="td-title-info">Last Removal Date</td> <td class="td-title-info">Removal Date</td>
<td class="td-text-info"> <td class="td-text-info">
<input type="text" id="c_removaldate" name="c_removaldate" value="<?=$c_removaldateSTR?>" placeholder="<?=date('Y-m-d')?>" readonly> <input type="text" id="c_removaldate" name="c_removaldate" value="<?=$c_removaldateSTR?>" placeholder="<?=date('Y-m-d')?>" readonly>
</td> </td>
</tr> </tr>
<tr>
<td class="td-title-info">Last Container Work Date</td>
<td class="td-text-info">
<input type="text" id="c_exchangedate" name="c_exchangedate" value="<?=$c_exchangedateSTR?>" placeholder="<?=date('Y-m-d')?>" readonly>
</td>
<td class="td-title-info"></td>
<td class="td-text-info">
</td>
</tr>
<tr> <tr>
<td class="td-title-info"><span style="margin-right:10px;">Container</span><div style="display: inline; float:right; padding-right: 30px;">Show Inactive <input type="checkbox" id="showInactive" name="showInactive" value="1"></div> <td class="td-title-info"><span style="margin-right:10px;">Container</span><div style="display: inline; float:right; padding-right: 30px;">Show Inactive <input type="checkbox" id="showInactive" name="showInactive" value="1"></div>
<td class="td-text-info" colspan="3"> <td class="td-text-info" colspan="3">

View File

@ -36,6 +36,28 @@ if ($actionStr == "CUSTOMER") {
} }
echo "</Row>\n"; echo "</Row>\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 // Customer list
$query = "SELECT * FROM tbl_customer WHERE c_uid != '' ORDER BY c_uid DESC"; $query = "SELECT * FROM tbl_customer WHERE c_uid != '' ORDER BY c_uid DESC";
$result = $jdb->nQuery($query, "list error"); $result = $jdb->nQuery($query, "list error");
@ -49,7 +71,32 @@ if ($actionStr == "CUSTOMER") {
foreach ($export_customer as $col) { 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 "<Cell><Data ss:Type=\"String\">" . $containerStr . "</Data></Cell>\n";
}
else if ($col == 'c_maincontainer') {
echo "<Cell><Data ss:Type=\"String\">" . $arrBin[$list[$col]] . "</Data></Cell>\n"; echo "<Cell><Data ss:Type=\"String\">" . $arrBin[$list[$col]] . "</Data></Cell>\n";
} }
@ -296,7 +343,7 @@ if ($actionStr == "CUSTOMER") {
/* -------- DATA QUERY -------- */ /* -------- DATA QUERY -------- */
$qry = " $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_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_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 , 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 FROM tbl_daily d
JOIN tbl_customer c JOIN tbl_customer c
ON d.d_customeruid = c.c_uid ON d.d_customeruid = c.c_uid
JOIN tbl_member m
ON d.d_driveruid = m.m_uid
WHERE d.d_status = 'F' WHERE d.d_status = 'F'
AND d.d_orderdate BETWEEN '$oil_period_fromTMP' AND '$oil_period_toTMP' AND d.d_orderdate BETWEEN '$oil_period_fromTMP' AND '$oil_period_toTMP'
ORDER BY d.d_orderdate, c.c_accountno ORDER BY d.d_orderdate, c.c_accountno

View File

@ -210,7 +210,7 @@ else $typeQRY = " AND (c_schedule = 'None') ";
if ($c_type_o == "O") $orderflagQRY = " AND c_orderflag = 0 "; if ($c_type_o == "O") $orderflagQRY = " AND c_orderflag = 0 ";
else $orderflagQRY = " ";; 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"); $rt_driver = $jdb->fQuery($qry_driver, "fetch query error");
// $query = "SELECT * FROM tbl_sampletypes // $query = "SELECT * FROM tbl_sampletypes

View File

@ -1,19 +1,20 @@
<?php <?php
$selectedDate = $_GET['date'] ?? date('Y-m-d'); $selectedDate = $_GET['date'] ?? date('Y-m-d');
$selectedDriver = $_GET['driver_uid'] ?? $_SESSION['ss_DRUID']; $canViewAllDrivers = ($_SESSION['ss_LEVEL'] <= 5 || $_SESSION['ss_GROUP'] == 1);
$selectedDriver = $_GET['driver_uid'] ?? ($canViewAllDrivers ? 0 : $_SESSION['ss_DRUID']);
$isAdmin = ($_SESSION['ss_LEVEL'] <= 5); $isAdmin = $canViewAllDrivers;
// driver filter // driver filter
$whereDriver = ""; $whereDriver = "";
if(!$isAdmin){ if(!$isAdmin){
$driver_uid = $_SESSION['ss_DRUID']; $driver_uid = $_SESSION['ss_DRUID'];
$whereDriver = " AND di_driver_uid = {$driver_uid}"; $whereDriver = " AND di_driver_uid = '{$driver_uid}'";
}else{ }else{
$driver_uid = (int)($_GET['driver_uid'] ?? 0); $driver_uid = (int)($_GET['driver_uid'] ?? 0);
if($driver_uid > 0){ if($driver_uid > 0){
$whereDriver = " AND di_driver_uid = {$driver_uid}"; $whereDriver = " AND di_driver_uid = '{$driver_uid}'";
} }
} }

View File

@ -376,7 +376,7 @@ while($lt_driver=mysqli_fetch_array($rt_driver, MYSQLI_ASSOC)) {
// Get Driver Info // 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"); $rt_dr = $jdb->nQuery($qry_dr, "list error");
while($lt_dr=mysqli_fetch_array($rt_dr, MYSQLI_ASSOC)) { while($lt_dr=mysqli_fetch_array($rt_dr, MYSQLI_ASSOC)) {

View File

@ -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' ); $arrNoteType = array ('B' => 'Accounting', 'S' => 'Staff', 'D' => 'Driver', 'A' => 'All' );
$arrPaidStatus = array ('P' => 'Paid', 'N' => 'UnPaid', 'G' => 'Paid (Grease Trap)'); $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'); $arrJobType = array ('UCO' => 'UCO', 'INSTALL' => 'INSTALL', 'EMERGENCY' => 'EMERGENCY');
//$arrClass = array ('M' => 'Math', 'P' => 'Physics', 'C' => 'Chemistry', 'B' => 'Biology', 'S' => 'Science', 'O' => 'Others' ); //$arrClass = array ('M' => 'Math', 'P' => 'Physics', 'C' => 'Chemistry', 'B' => 'Biology', 'S' => 'Science', 'O' => 'Others' );

View File

@ -107,6 +107,7 @@ if($action == "login") {
// Level : m_level : Admin : 1, Manager : 3, Staff : 5, Accounting : 6, Operator : 7, Driver : 9 // Level : m_level : Admin : 1, Manager : 3, Staff : 5, Accounting : 6, Operator : 7, Driver : 9
$_SESSION['ss_LEVEL'] = $result['m_level']; $_SESSION['ss_LEVEL'] = $result['m_level'];
$_SESSION['ss_GROUP'] = $result['m_gid'];
$today = $func -> PgetTime(0,0,4); $today = $func -> PgetTime(0,0,4);
$loginCnt = $result['m_loginnum']+1; $loginCnt = $result['m_loginnum']+1;