connect_error) { die("연결 실패: " . $conn->connect_error); } // 선택한 날짜 가져오기 $date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d'); // 어제 날짜 계산 $yesterday = date('Y-m-d', strtotime($date . ' -1 day')); // SQL 쿼리 실행 $sql = "SELECT category_name, product_name, option_name, qty FROM product_quantities WHERE date = '$date'"; $result = $conn->query($sql); // 어제 데이터 가져오기 $sql_yesterday = "SELECT category_name, product_name, option_name, qty FROM product_quantities WHERE date = '$yesterday'"; $result_yesterday = $conn->query($sql_yesterday); // 데이터 초기화 $data = [ '홈페이지' => [ '1부' => [ 'R석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ], 'S석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ], 'A석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ] ], '2부' => [ 'R석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ], 'S석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ], 'A석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ] ] ], '큐패스' => [ '1부' => [ 'R석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ], 'S석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ], 'A석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ] ], '2부' => [ 'R석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ], 'S석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ], 'A석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ] ] ] ]; $y_data = [ '홈페이지' => [ '1부' => [ 'R석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ], 'S석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ], 'A석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ] ], '2부' => [ 'R석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ], 'S석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ], 'A석' => [ '대인' => 0, '소인' => 0, '36개월미만' => 0 ] ] ], '큐패스' => [ '1부' => [ 'R석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ], 'S석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ], 'A석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ] ], '2부' => [ 'R석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ], 'S석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ], 'A석' => [ '대인' => 0, '소인' => 0, '36개월 미만' => 0 ] ] ] ]; // 데이터를 변환하는 로직 if ($result->num_rows > 0) { // 각 행 데이터 처리 while ($row = $result->fetch_assoc()) { if (preg_match('/\[(.+?)\](.+?)\s(.+)/', $row['option_name'], $matches)) { $part = $matches[1]; // 예: '1부' $seat = $matches[2]; // 예: 'R석' $option = $matches[3]; // 예: '대인' } // $data[$row['category_name']][$row['product_name']][$part][$seat][$option] = $row['qty']; $data[$row['category_name']][$part][$seat][$option] = $row['qty']; } } if ($result_yesterday->num_rows > 0) { // 어제 각 행 데이터 처리 while ($row = $result_yesterday->fetch_assoc()) { if (preg_match('/\[(.+?)\](.+?)\s(.+)/', $row['option_name'], $matches)) { $part = $matches[1]; // 예: '1부' $seat = $matches[2]; // 예: 'R석' $option = $matches[3]; // 예: '대인' } // $y_data[$row['category_name']][$row['product_name']][$part][$seat][$option] = $row['qty']; $y_data[$row['category_name']][$part][$seat][$option] = $row['qty']; } } function totalView($data) { $result = sprintf("%+d", $data); return $result; } // 합계 초기화 $web_part1 = $web_part2 = $qpos_part1 = $qpos_part2 = 0; function catSum($is_web, $option, $data) { $sum = 0; if ( isset($data[$is_web][$option]) && is_array($data[$is_web][$option]) ) { foreach ($data[$is_web][$option] as $seat => $option) { foreach ($option as $row) { $sum += $row; } } return $sum; } else { return 0; } } // 합계 데이터 저장 $web_part1 = catSum('홈페이지', '1부', $data); $web_part2 = catSum('홈페이지', '2부', $data); $qpos_part1 = catSum('큐패스', '1부', $data); $qpos_part2 = catSum('큐패스', '2부', $data); $y_web_part1 = catSum('홈페이지', '1부', $y_data); $y_web_part2 = catSum('홈페이지', '2부', $y_data); $y_qpos_part1 = catSum('큐패스', '1부', $y_data); $y_qpos_part2 = catSum('큐패스', '2부', $y_data); $web_total = $web_part1 + $web_part2; $qpos_total = $qpos_part1 + $qpos_part2; $y_web_total = $y_web_part1 + $y_web_part2; $y_qpos_total = $y_qpos_part1 + $y_qpos_part2; $y_grand_total = $y_web_total + $y_qpos_total; $sub_total1 = $web_part1 + $qpos_part1; $sub_total2 = $web_part2 + $qpos_part2; $grand_total = $web_total + $qpos_total; $y_sub_total1 = $y_web_part1 + $y_qpos_part1; $y_sub_total2 = $y_web_part2 + $y_qpos_part2; $y_grand_total = $y_web_total + $y_qpos_total; // 최종 업데이트 시간 알려주기 // 현재 서버의 시간대를 설정 (+9 시간, 한국 표준시) date_default_timezone_set('Asia/Seoul'); // 현재 시각 가져오기 $currentDateTime = new DateTime(); // 현재 분을 확인하여 조정 if ((int)$currentDateTime->format('i') < 3) { // 현재 분이 3보다 작으면 1시간 전으로 이동 $currentDateTime->modify('-1 hour'); } // 03분으로 설정 $currentDateTime->setTime((int)$currentDateTime->format('H'), 3, 0); $data['w'] = [ 0 => ['today' => $data['홈페이지']['1부']['R석']['대인'] + $data['홈페이지']['2부']['R석']['대인'], 'yesterday' => $y_data['홈페이지']['1부']['R석']['대인'] + $y_data['홈페이지']['2부']['R석']['대인']], 1 => ['today' => $data['홈페이지']['1부']['R석']['소인'] + $data['홈페이지']['2부']['R석']['소인'], 'yesterday' => $y_data['홈페이지']['1부']['R석']['소인'] + $y_data['홈페이지']['2부']['R석']['소인']], 2 => ['today' => $data['홈페이지']['1부']['R석']['36개월미만'] + $data['홈페이지']['2부']['R석']['36개월미만'], 'yesterday' => $y_data['홈페이지']['1부']['R석']['36개월미만'] + $y_data['홈페이지']['2부']['R석']['36개월미만']], 3 => ['today' => $data['홈페이지']['1부']['S석']['대인'] + $data['홈페이지']['2부']['S석']['대인'], 'yesterday' => $y_data['홈페이지']['1부']['S석']['대인'] + $y_data['홈페이지']['2부']['S석']['대인']], 4 => ['today' => $data['홈페이지']['1부']['S석']['소인'] + $data['홈페이지']['2부']['S석']['소인'], 'yesterday' => $y_data['홈페이지']['1부']['S석']['소인'] + $y_data['홈페이지']['2부']['S석']['소인']], 5 => ['today' => $data['홈페이지']['1부']['S석']['36개월미만'] + $data['홈페이지']['2부']['S석']['36개월미만'], 'yesterday' => $y_data['홈페이지']['1부']['S석']['36개월미만'] + $y_data['홈페이지']['2부']['S석']['36개월미만']], 6 => ['today' => $data['홈페이지']['1부']['A석']['대인'] + $data['홈페이지']['2부']['A석']['대인'], 'yesterday' => $y_data['홈페이지']['1부']['A석']['대인'] + $y_data['홈페이지']['2부']['A석']['대인']], 7 => ['today' => $data['홈페이지']['1부']['A석']['소인'] + $data['홈페이지']['2부']['A석']['소인'], 'yesterday' => $y_data['홈페이지']['1부']['A석']['소인'] + $y_data['홈페이지']['2부']['A석']['소인']], 8 => ['today' => $data['홈페이지']['1부']['A석']['36개월미만'] + $data['홈페이지']['2부']['A석']['36개월미만'], 'yesterday' => $y_data['홈페이지']['1부']['A석']['36개월미만'] + $y_data['홈페이지']['2부']['A석']['36개월미만']] ]; $data['q'] = [ 0 => ['today' => $data['큐패스']['1부']['R석']['대인'] + $data['큐패스']['2부']['R석']['대인'], 'yesterday' => $y_data['큐패스']['1부']['R석']['대인'] + $y_data['큐패스']['2부']['R석']['대인']], 1 => ['today' => $data['큐패스']['1부']['R석']['소인'] + $data['큐패스']['2부']['R석']['소인'], 'yesterday' => $y_data['큐패스']['1부']['R석']['소인'] + $y_data['큐패스']['2부']['R석']['소인']], 2 => ['today' => $data['큐패스']['1부']['R석']['36개월 미만'] + $data['큐패스']['2부']['R석']['36개월 미만'], 'yesterday' => $y_data['큐패스']['1부']['R석']['36개월 미만'] + $y_data['큐패스']['2부']['R석']['36개월 미만']], 3 => ['today' => $data['큐패스']['1부']['S석']['대인'] + $data['큐패스']['2부']['S석']['대인'], 'yesterday' => $y_data['큐패스']['1부']['S석']['대인'] + $y_data['큐패스']['2부']['S석']['대인']], 4 => ['today' => $data['큐패스']['1부']['S석']['소인'] + $data['큐패스']['2부']['S석']['소인'], 'yesterday' => $y_data['큐패스']['1부']['S석']['소인'] + $y_data['큐패스']['2부']['S석']['소인']], 5 => ['today' => $data['큐패스']['1부']['S석']['36개월 미만'] + $data['큐패스']['2부']['S석']['36개월 미만'], 'yesterday' => $y_data['큐패스']['1부']['S석']['36개월 미만'] + $y_data['큐패스']['2부']['S석']['36개월 미만']], 6 => ['today' => $data['큐패스']['1부']['A석']['대인'] + $data['큐패스']['2부']['A석']['대인'], 'yesterday' => $y_data['큐패스']['1부']['A석']['대인'] + $y_data['큐패스']['2부']['A석']['대인']], 7 => ['today' => $data['큐패스']['1부']['A석']['소인'] + $data['큐패스']['2부']['A석']['소인'], 'yesterday' => $y_data['큐패스']['1부']['A석']['소인'] + $y_data['큐패스']['2부']['A석']['소인']], 8 => ['today' => $data['큐패스']['1부']['A석']['36개월 미만'] + $data['큐패스']['2부']['A석']['36개월 미만'], 'yesterday' => $y_data['큐패스']['1부']['A석']['36개월 미만'] + $y_data['큐패스']['2부']['A석']['36개월 미만']] ]; // 각 항목별 합계를 저장할 배열 초기화 $web_totals = []; $qpos_totals = []; // 홈페이지 합계 계산 foreach ($data['w'] as $key => $row) { $web_totals[$key]['today'] = $row['today']; $web_totals[$key]['yesterday'] = $row['yesterday']; } // 큐패스 합계 계산 foreach ($data['q'] as $key => $row) { $qpos_totals[$key]['today'] = $row['today']; $qpos_totals[$key]['yesterday'] = $row['yesterday']; } // 전체 합계 $grand_totals = []; foreach ($web_totals as $key => $value) { $grand_totals[$key]['today'] = $web_totals[$key]['today'] + $qpos_totals[$key]['today']; $grand_totals[$key]['yesterday'] = $web_totals[$key]['yesterday'] + $qpos_totals[$key]['yesterday']; } $web_total = array_sum(array_column($data['w'], 'today')); $y_web_total = array_sum(array_column($data['w'], 'yesterday')); $qpos_total = array_sum(array_column($data['q'], 'today')); $y_qpos_total = array_sum(array_column($data['q'], 'yesterday')); $grand_total = $web_total + $qpos_total; $y_grand_total = $y_web_total + $y_qpos_total; ?>
| 구분 | R석 | S석 | A석 | 합계 | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 대인 | 소인 | 유아 | 대인 | 소인 | 유아 | 대인 | 소인 | 유아 | ||
| 홈페이지 | =$row['today']?> (=totalView($row['today'] - $row['yesterday'])?>) | =$web_total?> (=totalView($web_total - $y_web_total)?>) | ||||||||
| 큐패스 | =$row['today']?> (=totalView($row['today'] - $row['yesterday'])?>) | =$qpos_total?> (=totalView($qpos_total - $y_qpos_total)?>) | ||||||||
| 합계 | =$totals['today']?> (=totalView($totals['today'] - $totals['yesterday'])?>) | =$grand_total?> (=totalView($grand_total - $y_grand_total)?>) | ||||||||
결과가 없습니다.
| 구분 | 홈페이지 | 큐패스 | 합계 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| R | S | A | 계 | R | S | A | 계 | ||
| =date('m/d', strtotime($date))?> | = $web_r === 0 ? '-' : $web_r ?> | = $web_s === 0 ? '-' : $web_s ?> | = $web_a === 0 ? '-' : $web_a ?> | = $web_tot === 0 ? '-' : $web_tot ?> | = $q_r === 0 ? '-' : $q_r ?> | = $q_s === 0 ? '-' : $q_s ?> | = $q_a === 0 ? '-' : $q_a ?> | = $q_tot === 0 ? '-' : $q_tot ?> | = $total === 0 ? '-' : $total ?> |