5) { sleep(1); header("Location:" . $WebSite . "login/login_form.php"); exit; } ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php'; $title_message = '배차 차량 일지'; ?> <?=$title_message?> '1' OR devMode IS NULL) AND deliveryfeeList IS NOT NULL AND deliveryfeeList != '' AND deliveryfeeList != '[]' " . $orderby; $searchwhere = " WHERE is_deleted = '0' AND deliveryfeeList IS NOT NULL and (devMode <> '1' OR devMode IS NULL) AND deliveryfeeList != '' AND deliveryfeeList != '[]' AND searchtag LIKE '%$search%'" . $orderby; // 수정된 쿼리: COD이 존재하고 is_deleted가 0인 자료만 선택 if ($search == "") { $sql = "SELECT * FROM $DB.$tablename " . $where; } else { $sql = "SELECT * FROM $DB.$tablename " . $searchwhere; } // 현재일자 변수지정 $today = date("Y-m-d"); // SQL 실행 및 데이터 처리 // print $sql; ?>
    
500000, '조운물류' => 300000, ... ] $prepaidSum = 0; // 선불 합계 $collectSum = 0; // 착불 합계 $totalSum = 0; // 총합 (모든 합계) $resultRows = []; // 실제 목록 표시에 사용할 모든 레코드+deliveryfeeList 데이터를 담아둘 배열 try { $stmh = $pdo->query($sql); // PDOStatement $total_row = $stmh->rowCount(); while ($row = $stmh->fetch(PDO::FETCH_ASSOC)) { // deliveryfeeList를 JSON -> 배열 디코딩 $deliveryfeeListData = json_decode($row['deliveryfeeList'], true); if (!is_array($deliveryfeeListData) || count($deliveryfeeListData) === 0) { $deliveryfeeListData = [[]]; } // (B) 각 행을 순회하면서 합계 계산 foreach ($deliveryfeeListData as $feeRow) { // col1 : 물류업체명, col5 : 합계(숫자), col6 : 착불/선불 $company = $feeRow['col1'] ?? ''; // 예: '25시물류' $sumText = $feeRow['col5'] ?? ''; // 예: '12,345' (콤마가 있을 수도 있으므로) $payType = $feeRow['col6'] ?? ''; // 예: '착불' or '선불' // 숫자 변환 (콤마 제거 후 float/int 변환) $sumValue = floatval(str_replace(',', '', $sumText)); // 물류업체명별 합계 if (!isset($companySums[$company])) { $companySums[$company] = 0; } $companySums[$company] += $sumValue; // 착불/선불 합계 if ($payType === '선불') { $prepaidSum += $sumValue; } elseif ($payType === '착불') { $collectSum += $sumValue; } // 총합 $totalSum += $sumValue; } // (C) 화면에 출력할 수 있도록, 원본 $row + deliveryfeeListData를 저장 $resultRows[] = $row; } } catch (PDOException $Exception) { print "오류: " . $Exception->getMessage(); } // (D) 합계 테이블을 출력하기 전에, 물류업체명 배열을 정렬(필요 시) ksort($companySums); // 키(물류업체명)로 정렬 - 사용 여부는 선택 // echo '
';
// print_r($deliveryfeeListData);
// echo '
'; ?> $amount) { echo ""; } ?> $amount) { // 3자리 콤마 $formatted = number_format($amount); echo ""; } // 선불, 착불, 전체 합계 $formattedPrepaid = number_format($prepaidSum); $formattedCollect = number_format($collectSum); $formattedTotal = number_format($totalSum); echo ""; echo ""; echo ""; ?>
" . htmlspecialchars($companyName) . "선불 착불 합계
{$formatted}{$formattedPrepaid}{$formattedCollect}{$formattedTotal}
    ~    
 
 
query($sql); // 검색조건에 맞는글 stmh $total_row = $stmh->rowCount(); $start_num = 1; // 페이지당 표시되는 첫 번째 글 순번 while ($row = $stmh->fetch(PDO::FETCH_ASSOC)) { // (예) DB 필드에서 출고일, 현장명, 오늘 날짜 비교 등에 사용 $outdate = $row['outdate'] ?? ''; $outworkplace = $row['outworkplace'] ?? ''; $num = $row['num'] ?? ''; $tablename = $tablename ?? ''; // 오늘 날짜와 출고일 비교해 색상 지정 (선택 사항) $date_font = ($today == $outdate) ? "text-danger" : "text-dark"; // 요일 표기 if ($outdate !== "") { $week = ["(일)", "(월)", "(화)", "(수)", "(목)", "(금)", "(토)"]; $outdate .= $week[ date('w', strtotime($outdate)) ]; } // deliveryfeeList를 JSON -> 배열 디코딩 (여러 개 행이 있을 수 있음) $deliveryfeeListData = json_decode($row['deliveryfeeList'], true); // 만약 데이터가 없거나 파싱 실패하면, 1개짜리 빈 배열로 처리 (빈 화면 대신) if (!is_array($deliveryfeeListData) || count($deliveryfeeListData) === 0) { $deliveryfeeListData = [[]]; } // deliveryfeeList의 각 행마다 생성 foreach ($deliveryfeeListData as $index => $feeRow) { // 첫 번째 행($index===0)일 때만 번호/출고일/현장명 표시 // $tdNumber = ($index === 0) ? $start_num : ''; // $tdOutdate = ($index === 0) ? "{$outdate}" : ''; // $tdWork = ($index === 0) ? $outworkplace : ''; $tdNumber = $start_num ; $tdOutdate = "{$outdate}" ; $tdWork = $outworkplace ; // col1 ~ col11 $col1 = $feeRow['col1'] ?? ''; $col2 = $feeRow['col2'] ?? ''; $col3 = $feeRow['col3'] ?? ''; $col4 = $feeRow['col4'] ?? ''; $col5 = $feeRow['col5'] ?? ''; $col6 = $feeRow['col6'] ?? ''; // 체크할 컬럼 (선불/착불) $col7 = $feeRow['col7'] ?? ''; $col8 = $feeRow['col8'] ?? ''; $col9 = $feeRow['col9'] ?? ''; $col10 = $feeRow['col10'] ?? ''; $col11 = $feeRow['col11'] ?? ''; // col6이 비어있으면 blink 클래스 추가 (선불/착불) $blinkClass = ($col6 === '') ? 'blink-row' : ''; ?> 다음 레코드 } // while($row) } catch (PDOException $Exception) { print "오류: " . $Exception->getMessage(); } ?>
번호 출고일 현장명 하차업체명 상차지 물류업체명 차량톤수 금 액 부가세 합계 착/선불 차량번호 기사 연락처 비고