금융 거래 기록 흐름 공통화
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/db.php';
|
||||
require_once __DIR__ . '/account_service.php';
|
||||
require_once __DIR__ . '/card_billing_service.php';
|
||||
require_once __DIR__ . '/db.php';
|
||||
require_once __DIR__ . '/account_service.php';
|
||||
require_once __DIR__ . '/card_billing_service.php';
|
||||
require_once __DIR__ . '/transaction_record_service.php';
|
||||
|
||||
function split_amount_evenly(float $amount, int $months): array
|
||||
{
|
||||
@@ -547,43 +548,10 @@ function prepay_installment(
|
||||
|
||||
recalculate_installment_status($installmentId);
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO transactions
|
||||
(
|
||||
user_id,
|
||||
account_id,
|
||||
category_id,
|
||||
transaction_type,
|
||||
amount,
|
||||
is_installment,
|
||||
installment_months,
|
||||
installment_interest_rate,
|
||||
installment_interest_total,
|
||||
installment_total_billed,
|
||||
installment_prepay_amount,
|
||||
transaction_date,
|
||||
merchant_name,
|
||||
description,
|
||||
related_account_id,
|
||||
fingerprint
|
||||
)
|
||||
VALUES (?, ?, ?, 'expense', ?, 0, NULL, 0, 0, NULL, ?, ?, ?, ?, NULL, ?)
|
||||
");
|
||||
|
||||
$desc = $description ?: '할부 선결제/중도상환';
|
||||
|
||||
$fingerprint = hash('sha256', implode('|', [
|
||||
$userId,
|
||||
$paymentAccountId,
|
||||
'installment_prepay',
|
||||
$installmentId,
|
||||
$prepayDate,
|
||||
number_format($totalAmount, 2, '.', ''),
|
||||
$desc
|
||||
]));
|
||||
|
||||
$stmtCat = $pdo->prepare("
|
||||
SELECT id
|
||||
$desc = $description ?: '할부 선결제/중도상환';
|
||||
|
||||
$stmtCat = $pdo->prepare("
|
||||
SELECT id
|
||||
FROM categories
|
||||
WHERE user_id = ?
|
||||
AND category_type = 'expense'
|
||||
@@ -594,22 +562,23 @@ function prepay_installment(
|
||||
$category = $stmtCat->fetch();
|
||||
|
||||
if (!$category) {
|
||||
throw new RuntimeException('선결제 기록용 expense 카테고리(기타지출)를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
$stmt->execute([
|
||||
$userId,
|
||||
$paymentAccountId,
|
||||
(int)$category['id'],
|
||||
$totalAmount,
|
||||
$totalAmount,
|
||||
$prepayDate,
|
||||
$installment['merchant_name'],
|
||||
'[할부 선결제] ' . $desc,
|
||||
$fingerprint
|
||||
]);
|
||||
|
||||
$pdo->commit();
|
||||
throw new RuntimeException('선결제 기록용 expense 카테고리(기타지출)를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
insert_transaction_record([
|
||||
'user_id' => $userId,
|
||||
'account_id' => $paymentAccountId,
|
||||
'category_id' => (int)$category['id'],
|
||||
'transaction_type' => 'expense',
|
||||
'amount' => $totalAmount,
|
||||
'transaction_date' => $prepayDate,
|
||||
'merchant_name' => $installment['merchant_name'],
|
||||
'description' => '[할부 선결제] ' . $installmentId . ' / ' . $desc,
|
||||
'related_account_id' => null,
|
||||
'installment_prepay_amount' => $totalAmount,
|
||||
], true);
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
recalculate_account_balance($paymentAccountId);
|
||||
} catch (Throwable $e) {
|
||||
@@ -701,4 +670,4 @@ function rebuild_all_installments_for_user(int $userId): int
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user