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 = '일일 일보'; ?>
| 내용 | 등록일 | 만기일 | 배서일자 | 금액 | 수입/지출 | 계산타입 | 계산금액 | '; // echo '
|---|---|---|---|---|---|---|---|
| ' . htmlspecialchars($row['content_detail']) . ' | '; // echo '' . $row['registDate'] . ' | '; // echo '' . $row['dueDate'] . ' | '; // echo '' . $row['endorsementDate'] . ' | '; // echo '' . $row['amount'] . ' | '; // echo '' . $row['inoutsep'] . ' | '; // echo '' . $row['calculated_type'] . ' | '; // echo '' . $row['calculated_amount'] . ' | '; // echo '
'; // print_r($notesReceivable); // echo ''; // 5. 날짜별로 모든 데이터 계산 후 배열에 저장 (메모리에서 처리) $reportData = []; $current = strtotime($fromdate); $end = strtotime($todate); while ($current <= $end) { $currentDateStr = date('Y-m-d', $current); $dailyTransactions = $dataByDate[$currentDateStr] ?? []; // 거래가 있는 날만 리포트 데이터 생성 if (!empty($dailyTransactions)) { $dailySummaries = []; foreach ($accountNames as $bankbookName) { $prevBalance = $runningBalances[$bankbookName]; $dailyIncome = 0; $dailyExpense = 0; foreach ($dailyTransactions as $tx) { if ($tx['bankbook'] === $bankbookName) { $amount = floatval(str_replace(',', '', $tx['amount'])); if ($tx['inoutsep'] === '지출') { $dailyExpense += $amount; } else { $dailyIncome += $amount; } } } $endOfDayBalance = $prevBalance + $dailyIncome - $dailyExpense; $dailySummaries[$bankbookName] = [ 'prev' => $prevBalance, 'income' => $dailyIncome, 'expense' => $dailyExpense, 'balance' => $endOfDayBalance ]; } $reportData[$currentDateStr] = [ 'summaries' => $dailySummaries, 'transactions' => $dailyTransactions ]; } // 전일이월액 업데이트는 거래가 없는 날도 매일 수행해야 함 foreach ($accountNames as $bankbookName) { $dailyIncome = 0; $dailyExpense = 0; $currentDayTx = $dataByDate[$currentDateStr] ?? []; foreach ($currentDayTx as $tx) { if ($tx['bankbook'] === $bankbookName) { $amount = floatval(str_replace(',', '', $tx['amount'])); if ($tx['inoutsep'] === '지출') $dailyExpense += $amount; else $dailyIncome += $amount; } } $runningBalances[$bankbookName] += ($dailyIncome - $dailyExpense); } $current = strtotime('+1 day', $current); } // 날짜 역순으로 출력하기 위해 배열 뒤집기 $reportData = array_reverse($reportData, true); // echo '
'; // print_r($reportData); // echo ''; ?>