'; // print_r($lastMonthEnd); // echo ''; // 이월잔액 계산 $salesBeforeSql = " SELECT SUM(COALESCE(e.ET_total, 0)) AS total_sales FROM " . $DB . ".output o LEFT JOIN " . $DB . ".output_extra e ON o.num = e.parent_num WHERE o.secondordnum = :secondordnum AND o.outdate <= :lastMonthEnd AND (o.is_deleted IS NULL OR o.is_deleted = 0) "; $paymentBeforeSql = " SELECT SUM(CAST(REPLACE(amount, ',', '') AS SIGNED)) AS total_payment FROM " . $DB . ".account WHERE secondordnum = :secondordnum AND registDate <= :lastMonthEnd AND (is_deleted IS NULL OR is_deleted = 0) AND content = '거래처 수금' "; $salesBeforeStmt = $pdo->prepare($salesBeforeSql); $salesBeforeStmt->execute([':secondordnum' => $secondordnum, ':lastMonthEnd' => $lastMonthEnd]); $salesBeforeData = $salesBeforeStmt->fetch(PDO::FETCH_ASSOC); $paymentBeforeStmt = $pdo->prepare($paymentBeforeSql); $paymentBeforeStmt->execute([':secondordnum' => $secondordnum, ':lastMonthEnd' => $lastMonthEnd]); $paymentBeforeData = $paymentBeforeStmt->fetch(PDO::FETCH_ASSOC); $initialSales = isset($salesBeforeData['total_sales']) ? (float)$salesBeforeData['total_sales'] : 0; $initialPayments = isset($paymentBeforeData['total_payment']) ? (float)$paymentBeforeData['total_payment'] : 0; // Calculate the initial balance $initialBalance = intval(round($initialSales, 2) - round($initialPayments)); // 마지막 자릿수가 1인지 확인 if (floatval($initialBalance) % 10 === 1) { // 마지막 자릿수를 제거 (정수로 처리) $initialBalance = floor($initialBalance / 10); } } catch (Exception $e) { echo "오류: " . $e->getMessage(); } ?>
| 사업자등록번호 | = $customer['vendor_code'] ?> | 대표자 | = $customer['representative_name'] ?> |
|---|---|---|---|
| 여신한도 | 0 | 전화 | = $customer['phone'] ?> (모바일: = $customer['mobile'] ?>) |
| = $customer['email'] ?> | Fax | = $customer['fax'] ?> | |
| 주소 | = $customer['address'] ?> | ||
| 적요 | |||
| 판매/수금내역 | ||||
|---|---|---|---|---|
| 일자 | 적요 | 판매 | 수금 | 잔액 |
| 이월잔액 | = number_format($initialBalance) ?> | |||
| {$payment_date} | 입금 | " . number_format($payment_amount) . " | " . number_format($total_balance) . " | |
| {$current_month} 계 | " . number_format($monthly_sales[$current_month]) . " | |||
| {$outdate} | {$workplacename} | " . number_format($amount) . " | " . number_format($total_balance) . " | |
| {$itemName} {$spec} | " . number_format($amountDetail) . " | |||
| 비인정 금액 | -" . number_format($row['ET_unapproved']) . " | |||
| {$current_month} 계 (VAT 포함) | " . number_format($monthly_sales[$current_month]) . " | |||
| 총 = $sale_count ?>건 누계 (VAT 포함) | = number_format($grand_total) ?> | = number_format($total_payment_sum) ?> | = number_format($total_balance) ?> | |